]>
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 | ||
cd5897ed SPS |
2051 | static int |
2052 | scsih_is_nvme(struct device *dev) | |
2053 | { | |
2054 | struct scsi_device *sdev = to_scsi_device(dev); | |
2055 | ||
2056 | return (sdev->channel == PCIE_CHANNEL) ? 1 : 0; | |
2057 | } | |
2058 | ||
f92363d1 | 2059 | /** |
8a7e4c24 | 2060 | * scsih_get_resync - get raid volume resync percent complete |
f92363d1 SR |
2061 | * @dev the device struct object |
2062 | */ | |
8bbb1cf6 | 2063 | static void |
8a7e4c24 | 2064 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
2065 | { |
2066 | struct scsi_device *sdev = to_scsi_device(dev); | |
2067 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2068 | static struct _raid_device *raid_device; | |
2069 | unsigned long flags; | |
2070 | Mpi2RaidVolPage0_t vol_pg0; | |
2071 | Mpi2ConfigReply_t mpi_reply; | |
2072 | u32 volume_status_flags; | |
2073 | u8 percent_complete; | |
2074 | u16 handle; | |
2075 | ||
2076 | percent_complete = 0; | |
2077 | handle = 0; | |
7786ab6a SR |
2078 | if (ioc->is_warpdrive) |
2079 | goto out; | |
2080 | ||
f92363d1 SR |
2081 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
2082 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2083 | sdev->channel); | |
2084 | if (raid_device) { | |
2085 | handle = raid_device->handle; | |
2086 | percent_complete = raid_device->percent_complete; | |
2087 | } | |
2088 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2089 | ||
2090 | if (!handle) | |
2091 | goto out; | |
2092 | ||
2093 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2094 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2095 | sizeof(Mpi2RaidVolPage0_t))) { | |
2096 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2097 | ioc->name, __FILE__, __LINE__, __func__); | |
2098 | percent_complete = 0; | |
2099 | goto out; | |
2100 | } | |
2101 | ||
2102 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2103 | if (!(volume_status_flags & | |
2104 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
2105 | percent_complete = 0; | |
2106 | ||
2107 | out: | |
b130b0d5 SS |
2108 | |
2109 | switch (ioc->hba_mpi_version_belonged) { | |
2110 | case MPI2_VERSION: | |
c84b06a4 | 2111 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2112 | break; |
2113 | case MPI25_VERSION: | |
2114 | case MPI26_VERSION: | |
c84b06a4 | 2115 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
2116 | break; |
2117 | } | |
f92363d1 SR |
2118 | } |
2119 | ||
2120 | /** | |
8a7e4c24 | 2121 | * scsih_get_state - get raid volume level |
f92363d1 SR |
2122 | * @dev the device struct object |
2123 | */ | |
8bbb1cf6 | 2124 | static void |
8a7e4c24 | 2125 | scsih_get_state(struct device *dev) |
f92363d1 SR |
2126 | { |
2127 | struct scsi_device *sdev = to_scsi_device(dev); | |
2128 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
2129 | static struct _raid_device *raid_device; | |
2130 | unsigned long flags; | |
2131 | Mpi2RaidVolPage0_t vol_pg0; | |
2132 | Mpi2ConfigReply_t mpi_reply; | |
2133 | u32 volstate; | |
2134 | enum raid_state state = RAID_STATE_UNKNOWN; | |
2135 | u16 handle = 0; | |
2136 | ||
2137 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
2138 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
2139 | sdev->channel); | |
2140 | if (raid_device) | |
2141 | handle = raid_device->handle; | |
2142 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
2143 | ||
2144 | if (!raid_device) | |
2145 | goto out; | |
2146 | ||
2147 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
2148 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
2149 | sizeof(Mpi2RaidVolPage0_t))) { | |
2150 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
2151 | ioc->name, __FILE__, __LINE__, __func__); | |
2152 | goto out; | |
2153 | } | |
2154 | ||
2155 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
2156 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
2157 | state = RAID_STATE_RESYNCING; | |
2158 | goto out; | |
2159 | } | |
2160 | ||
2161 | switch (vol_pg0.VolumeState) { | |
2162 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
2163 | case MPI2_RAID_VOL_STATE_ONLINE: | |
2164 | state = RAID_STATE_ACTIVE; | |
2165 | break; | |
2166 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
2167 | state = RAID_STATE_DEGRADED; | |
2168 | break; | |
2169 | case MPI2_RAID_VOL_STATE_FAILED: | |
2170 | case MPI2_RAID_VOL_STATE_MISSING: | |
2171 | state = RAID_STATE_OFFLINE; | |
2172 | break; | |
2173 | } | |
2174 | out: | |
b130b0d5 SS |
2175 | switch (ioc->hba_mpi_version_belonged) { |
2176 | case MPI2_VERSION: | |
c84b06a4 | 2177 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
2178 | break; |
2179 | case MPI25_VERSION: | |
2180 | case MPI26_VERSION: | |
c84b06a4 | 2181 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
2182 | break; |
2183 | } | |
f92363d1 SR |
2184 | } |
2185 | ||
2186 | /** | |
2187 | * _scsih_set_level - set raid level | |
2188 | * @sdev: scsi device struct | |
2189 | * @volume_type: volume type | |
2190 | */ | |
2191 | static void | |
c84b06a4 SR |
2192 | _scsih_set_level(struct MPT3SAS_ADAPTER *ioc, |
2193 | struct scsi_device *sdev, u8 volume_type) | |
f92363d1 SR |
2194 | { |
2195 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
2196 | ||
2197 | switch (volume_type) { | |
2198 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2199 | level = RAID_LEVEL_0; | |
2200 | break; | |
2201 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2202 | level = RAID_LEVEL_10; | |
2203 | break; | |
2204 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2205 | level = RAID_LEVEL_1E; | |
2206 | break; | |
2207 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2208 | level = RAID_LEVEL_1; | |
2209 | break; | |
2210 | } | |
2211 | ||
b130b0d5 SS |
2212 | switch (ioc->hba_mpi_version_belonged) { |
2213 | case MPI2_VERSION: | |
c84b06a4 | 2214 | raid_set_level(mpt2sas_raid_template, |
b130b0d5 SS |
2215 | &sdev->sdev_gendev, level); |
2216 | break; | |
2217 | case MPI25_VERSION: | |
2218 | case MPI26_VERSION: | |
c84b06a4 | 2219 | raid_set_level(mpt3sas_raid_template, |
b130b0d5 SS |
2220 | &sdev->sdev_gendev, level); |
2221 | break; | |
2222 | } | |
f92363d1 SR |
2223 | } |
2224 | ||
2225 | ||
2226 | /** | |
2227 | * _scsih_get_volume_capabilities - volume capabilities | |
2228 | * @ioc: per adapter object | |
2229 | * @sas_device: the raid_device object | |
2230 | * | |
2231 | * Returns 0 for success, else 1 | |
2232 | */ | |
2233 | static int | |
2234 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
2235 | struct _raid_device *raid_device) | |
2236 | { | |
2237 | Mpi2RaidVolPage0_t *vol_pg0; | |
2238 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
2239 | Mpi2SasDevicePage0_t sas_device_pg0; | |
2240 | Mpi2ConfigReply_t mpi_reply; | |
2241 | u16 sz; | |
2242 | u8 num_pds; | |
2243 | ||
2244 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
2245 | &num_pds)) || !num_pds) { | |
2246 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2247 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2248 | __func__)); | |
2249 | return 1; | |
2250 | } | |
2251 | ||
2252 | raid_device->num_pds = num_pds; | |
2253 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
2254 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
2255 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
2256 | if (!vol_pg0) { | |
2257 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2258 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2259 | __func__)); | |
2260 | return 1; | |
2261 | } | |
2262 | ||
2263 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
2264 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
2265 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2266 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2267 | __func__)); | |
2268 | kfree(vol_pg0); | |
2269 | return 1; | |
2270 | } | |
2271 | ||
2272 | raid_device->volume_type = vol_pg0->VolumeType; | |
2273 | ||
2274 | /* figure out what the underlying devices are by | |
2275 | * obtaining the device_info bits for the 1st device | |
2276 | */ | |
2277 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
2278 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
2279 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
2280 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
2281 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
2282 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
2283 | raid_device->device_info = | |
2284 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2285 | } | |
2286 | } | |
2287 | ||
2288 | kfree(vol_pg0); | |
2289 | return 0; | |
2290 | } | |
2291 | ||
f92363d1 SR |
2292 | /** |
2293 | * _scsih_enable_tlr - setting TLR flags | |
2294 | * @ioc: per adapter object | |
2295 | * @sdev: scsi device struct | |
2296 | * | |
2297 | * Enabling Transaction Layer Retries for tape devices when | |
2298 | * vpd page 0x90 is present | |
2299 | * | |
2300 | */ | |
2301 | static void | |
2302 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
2303 | { | |
2304 | ||
2305 | /* only for TAPE */ | |
2306 | if (sdev->type != TYPE_TAPE) | |
2307 | return; | |
2308 | ||
2309 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
2310 | return; | |
2311 | ||
2312 | sas_enable_tlr(sdev); | |
2313 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
2314 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
2315 | return; | |
2316 | ||
2317 | } | |
2318 | ||
2319 | /** | |
8a7e4c24 | 2320 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
2321 | * @sdev: scsi device struct |
2322 | * | |
2323 | * Returns 0 if ok. Any other return is assumed to be an error and | |
2324 | * the device is ignored. | |
2325 | */ | |
8bbb1cf6 | 2326 | static int |
8a7e4c24 | 2327 | scsih_slave_configure(struct scsi_device *sdev) |
f92363d1 SR |
2328 | { |
2329 | struct Scsi_Host *shost = sdev->host; | |
2330 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
2331 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2332 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
2333 | struct _sas_device *sas_device; | |
d1b01d14 | 2334 | struct _pcie_device *pcie_device; |
f92363d1 SR |
2335 | struct _raid_device *raid_device; |
2336 | unsigned long flags; | |
2337 | int qdepth; | |
2338 | u8 ssp_target = 0; | |
2339 | char *ds = ""; | |
2340 | char *r_level = ""; | |
2341 | u16 handle, volume_handle = 0; | |
2342 | u64 volume_wwid = 0; | |
2343 | ||
2344 | qdepth = 1; | |
2345 | sas_device_priv_data = sdev->hostdata; | |
2346 | sas_device_priv_data->configured_lun = 1; | |
2347 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
2348 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
2349 | handle = sas_target_priv_data->handle; | |
2350 | ||
2351 | /* raid volume handling */ | |
2352 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2353 | ||
2354 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 2355 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
2356 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
2357 | if (!raid_device) { | |
2358 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2359 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2360 | __LINE__, __func__)); | |
2361 | return 1; | |
2362 | } | |
2363 | ||
2364 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
2365 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2366 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2367 | __LINE__, __func__)); | |
2368 | return 1; | |
2369 | } | |
2370 | ||
7786ab6a SR |
2371 | /* |
2372 | * WARPDRIVE: Initialize the required data for Direct IO | |
2373 | */ | |
c84b06a4 | 2374 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
2375 | |
2376 | /* RAID Queue Depth Support | |
2377 | * IS volume = underlying qdepth of drive type, either | |
2378 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
2379 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
2380 | */ | |
2381 | if (raid_device->device_info & | |
2382 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2383 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2384 | ds = "SSP"; | |
2385 | } else { | |
2386 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2387 | if (raid_device->device_info & | |
2388 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2389 | ds = "SATA"; | |
2390 | else | |
2391 | ds = "STP"; | |
2392 | } | |
2393 | ||
2394 | switch (raid_device->volume_type) { | |
2395 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2396 | r_level = "RAID0"; | |
2397 | break; | |
2398 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2399 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2400 | if (ioc->manu_pg10.OEMIdentifier && | |
2401 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
2402 | MFG10_GF0_R10_DISPLAY) && | |
2403 | !(raid_device->num_pds % 2)) | |
2404 | r_level = "RAID10"; | |
2405 | else | |
2406 | r_level = "RAID1E"; | |
2407 | break; | |
2408 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2409 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2410 | r_level = "RAID1"; | |
2411 | break; | |
2412 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2413 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2414 | r_level = "RAID10"; | |
2415 | break; | |
2416 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
2417 | default: | |
2418 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2419 | r_level = "RAIDX"; | |
2420 | break; | |
2421 | } | |
2422 | ||
7786ab6a SR |
2423 | if (!ioc->hide_ir_msg) |
2424 | sdev_printk(KERN_INFO, sdev, | |
2425 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
2426 | " pd_count(%d), type(%s)\n", | |
2427 | r_level, raid_device->handle, | |
2428 | (unsigned long long)raid_device->wwid, | |
2429 | raid_device->num_pds, ds); | |
f92363d1 | 2430 | |
6c197093 C |
2431 | if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) { |
2432 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2433 | MPT3SAS_RAID_MAX_SECTORS); | |
2434 | sdev_printk(KERN_INFO, sdev, | |
2435 | "Set queue's max_sector to: %u\n", | |
2436 | MPT3SAS_RAID_MAX_SECTORS); | |
2437 | } | |
2438 | ||
8a7e4c24 | 2439 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 2440 | |
7786ab6a SR |
2441 | /* raid transport support */ |
2442 | if (!ioc->is_warpdrive) | |
c84b06a4 | 2443 | _scsih_set_level(ioc, sdev, raid_device->volume_type); |
f92363d1 SR |
2444 | return 0; |
2445 | } | |
2446 | ||
2447 | /* non-raid handling */ | |
2448 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2449 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
2450 | &volume_handle)) { | |
2451 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2452 | "failure at %s:%d/%s()!\n", ioc->name, | |
2453 | __FILE__, __LINE__, __func__)); | |
2454 | return 1; | |
2455 | } | |
2456 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2457 | volume_handle, &volume_wwid)) { | |
2458 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2459 | "failure at %s:%d/%s()!\n", ioc->name, | |
2460 | __FILE__, __LINE__, __func__)); | |
2461 | return 1; | |
2462 | } | |
2463 | } | |
2464 | ||
d1b01d14 SPS |
2465 | /* PCIe handling */ |
2466 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2467 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2468 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
2469 | sas_device_priv_data->sas_target->sas_address); | |
2470 | if (!pcie_device) { | |
2471 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2472 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2473 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2474 | __LINE__, __func__)); | |
2475 | return 1; | |
2476 | } | |
2477 | ||
2478 | qdepth = MPT3SAS_NVME_QUEUE_DEPTH; | |
2479 | ds = "NVMe"; | |
2480 | sdev_printk(KERN_INFO, sdev, | |
2481 | "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2482 | ds, handle, (unsigned long long)pcie_device->wwid, | |
2483 | pcie_device->port_num); | |
2484 | if (pcie_device->enclosure_handle != 0) | |
2485 | sdev_printk(KERN_INFO, sdev, | |
2486 | "%s: enclosure logical id(0x%016llx), slot(%d)\n", | |
2487 | ds, | |
2488 | (unsigned long long)pcie_device->enclosure_logical_id, | |
2489 | pcie_device->slot); | |
2490 | if (pcie_device->connector_name[0] != '\0') | |
2491 | sdev_printk(KERN_INFO, sdev, | |
2492 | "%s: enclosure level(0x%04x)," | |
2493 | "connector name( %s)\n", ds, | |
2494 | pcie_device->enclosure_level, | |
2495 | pcie_device->connector_name); | |
2496 | pcie_device_put(pcie_device); | |
2497 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2498 | scsih_change_queue_depth(sdev, qdepth); | |
2499 | ||
2500 | if (pcie_device->nvme_mdts) | |
2501 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2502 | pcie_device->nvme_mdts/512); | |
2503 | /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be | |
2504 | ** merged and can eliminate holes created during merging | |
2505 | ** operation. | |
2506 | **/ | |
2507 | queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, | |
2508 | sdev->request_queue); | |
2509 | blk_queue_virt_boundary(sdev->request_queue, | |
2510 | ioc->page_size - 1); | |
2511 | return 0; | |
2512 | } | |
2513 | ||
f92363d1 | 2514 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 2515 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
2516 | sas_device_priv_data->sas_target->sas_address); |
2517 | if (!sas_device) { | |
2518 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2519 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2520 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2521 | __func__)); | |
2522 | return 1; | |
2523 | } | |
2524 | ||
2525 | sas_device->volume_handle = volume_handle; | |
2526 | sas_device->volume_wwid = volume_wwid; | |
2527 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2528 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2529 | ssp_target = 1; | |
30158dc9 SS |
2530 | if (sas_device->device_info & |
2531 | MPI2_SAS_DEVICE_INFO_SEP) { | |
2532 | sdev_printk(KERN_WARNING, sdev, | |
2533 | "set ignore_delay_remove for handle(0x%04x)\n", | |
2534 | sas_device_priv_data->sas_target->handle); | |
2535 | sas_device_priv_data->ignore_delay_remove = 1; | |
2536 | ds = "SES"; | |
2537 | } else | |
2538 | ds = "SSP"; | |
f92363d1 SR |
2539 | } else { |
2540 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2541 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
2542 | ds = "STP"; | |
2543 | else if (sas_device->device_info & | |
2544 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2545 | ds = "SATA"; | |
2546 | } | |
2547 | ||
2548 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
2549 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
2550 | ds, handle, (unsigned long long)sas_device->sas_address, | |
2551 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
75888956 SR |
2552 | |
2553 | _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL); | |
f92363d1 | 2554 | |
d1cb5e49 | 2555 | sas_device_put(sas_device); |
f92363d1 SR |
2556 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
2557 | ||
2558 | if (!ssp_target) | |
2559 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
2560 | ||
2561 | ||
8a7e4c24 | 2562 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
2563 | |
2564 | if (ssp_target) { | |
2565 | sas_read_port_mode_page(sdev); | |
2566 | _scsih_enable_tlr(ioc, sdev); | |
2567 | } | |
2568 | ||
2569 | return 0; | |
2570 | } | |
2571 | ||
2572 | /** | |
8a7e4c24 | 2573 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
2574 | * @sdev: scsi device struct |
2575 | * @bdev: pointer to block device context | |
2576 | * @capacity: device size (in 512 byte sectors) | |
2577 | * @params: three element array to place output: | |
2578 | * params[0] number of heads (max 255) | |
2579 | * params[1] number of sectors (max 63) | |
2580 | * params[2] number of cylinders | |
2581 | * | |
2582 | * Return nothing. | |
2583 | */ | |
8bbb1cf6 | 2584 | static int |
8a7e4c24 | 2585 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2586 | sector_t capacity, int params[]) |
2587 | { | |
2588 | int heads; | |
2589 | int sectors; | |
2590 | sector_t cylinders; | |
2591 | ulong dummy; | |
2592 | ||
2593 | heads = 64; | |
2594 | sectors = 32; | |
2595 | ||
2596 | dummy = heads * sectors; | |
2597 | cylinders = capacity; | |
2598 | sector_div(cylinders, dummy); | |
2599 | ||
2600 | /* | |
2601 | * Handle extended translation size for logical drives | |
2602 | * > 1Gb | |
2603 | */ | |
2604 | if ((ulong)capacity >= 0x200000) { | |
2605 | heads = 255; | |
2606 | sectors = 63; | |
2607 | dummy = heads * sectors; | |
2608 | cylinders = capacity; | |
2609 | sector_div(cylinders, dummy); | |
2610 | } | |
2611 | ||
2612 | /* return result */ | |
2613 | params[0] = heads; | |
2614 | params[1] = sectors; | |
2615 | params[2] = cylinders; | |
2616 | ||
2617 | return 0; | |
2618 | } | |
2619 | ||
2620 | /** | |
2621 | * _scsih_response_code - translation of device response code | |
2622 | * @ioc: per adapter object | |
2623 | * @response_code: response code returned by the device | |
2624 | * | |
2625 | * Return nothing. | |
2626 | */ | |
2627 | static void | |
2628 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2629 | { | |
2630 | char *desc; | |
2631 | ||
2632 | switch (response_code) { | |
2633 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2634 | desc = "task management request completed"; | |
2635 | break; | |
2636 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2637 | desc = "invalid frame"; | |
2638 | break; | |
2639 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2640 | desc = "task management request not supported"; | |
2641 | break; | |
2642 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2643 | desc = "task management request failed"; | |
2644 | break; | |
2645 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2646 | desc = "task management request succeeded"; | |
2647 | break; | |
2648 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2649 | desc = "invalid lun"; | |
2650 | break; | |
2651 | case 0xA: | |
2652 | desc = "overlapped tag attempted"; | |
2653 | break; | |
2654 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2655 | desc = "task queued, however not sent to target"; | |
2656 | break; | |
2657 | default: | |
2658 | desc = "unknown"; | |
2659 | break; | |
2660 | } | |
2661 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
2662 | ioc->name, response_code, desc); | |
2663 | } | |
2664 | ||
2665 | /** | |
2666 | * _scsih_tm_done - tm completion routine | |
2667 | * @ioc: per adapter object | |
2668 | * @smid: system request message index | |
2669 | * @msix_index: MSIX table index supplied by the OS | |
2670 | * @reply: reply message frame(lower 32bit addr) | |
2671 | * Context: none. | |
2672 | * | |
2673 | * The callback handler when using scsih_issue_tm. | |
2674 | * | |
2675 | * Return 1 meaning mf should be freed from _base_interrupt | |
2676 | * 0 means the mf is freed from this function. | |
2677 | */ | |
2678 | static u8 | |
2679 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2680 | { | |
2681 | MPI2DefaultReply_t *mpi_reply; | |
2682 | ||
2683 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2684 | return 1; | |
2685 | if (ioc->tm_cmds.smid != smid) | |
2686 | return 1; | |
f92363d1 SR |
2687 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2688 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2689 | if (mpi_reply) { | |
2690 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2691 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2692 | } | |
2693 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2694 | complete(&ioc->tm_cmds.done); | |
2695 | return 1; | |
2696 | } | |
2697 | ||
2698 | /** | |
2699 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2700 | * @ioc: per adapter object | |
2701 | * @handle: device handle | |
2702 | * | |
2703 | * During taskmangement request, we need to freeze the device queue. | |
2704 | */ | |
2705 | void | |
2706 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2707 | { | |
2708 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2709 | struct scsi_device *sdev; | |
2710 | u8 skip = 0; | |
2711 | ||
2712 | shost_for_each_device(sdev, ioc->shost) { | |
2713 | if (skip) | |
2714 | continue; | |
2715 | sas_device_priv_data = sdev->hostdata; | |
2716 | if (!sas_device_priv_data) | |
2717 | continue; | |
2718 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2719 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2720 | skip = 1; | |
2721 | ioc->ignore_loginfos = 1; | |
2722 | } | |
2723 | } | |
2724 | } | |
2725 | ||
2726 | /** | |
2727 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2728 | * @ioc: per adapter object | |
2729 | * @handle: device handle | |
2730 | * | |
2731 | * During taskmangement request, we need to freeze the device queue. | |
2732 | */ | |
2733 | void | |
2734 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2735 | { | |
2736 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2737 | struct scsi_device *sdev; | |
2738 | u8 skip = 0; | |
2739 | ||
2740 | shost_for_each_device(sdev, ioc->shost) { | |
2741 | if (skip) | |
2742 | continue; | |
2743 | sas_device_priv_data = sdev->hostdata; | |
2744 | if (!sas_device_priv_data) | |
2745 | continue; | |
2746 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2747 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2748 | skip = 1; | |
2749 | ioc->ignore_loginfos = 0; | |
2750 | } | |
2751 | } | |
2752 | } | |
2753 | ||
2754 | /** | |
2755 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2756 | * @ioc: per adapter struct | |
2757 | * @device_handle: device handle | |
2758 | * @channel: the channel assigned by the OS | |
2759 | * @id: the id assigned by the OS | |
2760 | * @lun: lun number | |
2761 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2762 | * @smid_task: smid assigned to the task | |
2763 | * @timeout: timeout in seconds | |
f92363d1 SR |
2764 | * Context: user |
2765 | * | |
2766 | * A generic API for sending task management requests to firmware. | |
2767 | * | |
2768 | * The callback index is set inside `ioc->tm_cb_idx`. | |
2769 | * | |
2770 | * Return SUCCESS or FAILED. | |
2771 | */ | |
2772 | int | |
2773 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, | |
96902835 | 2774 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout) |
f92363d1 SR |
2775 | { |
2776 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2777 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2778 | u16 smid = 0; | |
2779 | u32 ioc_state; | |
f92363d1 SR |
2780 | struct scsiio_tracker *scsi_lookup = NULL; |
2781 | int rc; | |
03d1fb3a | 2782 | u16 msix_task = 0; |
f92363d1 | 2783 | |
96902835 CO |
2784 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2785 | ||
f92363d1 SR |
2786 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
2787 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2788 | __func__, ioc->name); | |
96902835 | 2789 | return FAILED; |
f92363d1 SR |
2790 | } |
2791 | ||
2792 | if (ioc->shost_recovery || ioc->remove_host || | |
2793 | ioc->pci_error_recovery) { | |
2794 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2795 | __func__, ioc->name); | |
96902835 | 2796 | return FAILED; |
f92363d1 SR |
2797 | } |
2798 | ||
2799 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2800 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2801 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2802 | "unexpected doorbell active!\n", ioc->name)); | |
98c56ad3 | 2803 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2804 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2805 | } |
2806 | ||
2807 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2808 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2809 | MPI2_DOORBELL_DATA_MASK); | |
98c56ad3 | 2810 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2811 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2812 | } |
2813 | ||
2814 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2815 | if (!smid) { | |
2816 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2817 | ioc->name, __func__); | |
96902835 | 2818 | return FAILED; |
f92363d1 SR |
2819 | } |
2820 | ||
2821 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | |
2822 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; | |
2823 | ||
2824 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
2825 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", | |
2826 | ioc->name, handle, type, smid_task)); | |
2827 | ioc->tm_cmds.status = MPT3_CMD_PENDING; | |
2828 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2829 | ioc->tm_cmds.smid = smid; | |
2830 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2831 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2832 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2833 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2834 | mpi_request->TaskType = type; | |
2835 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
2836 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2837 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2838 | init_completion(&ioc->tm_cmds.done); | |
03d1fb3a SS |
2839 | if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) && |
2840 | (scsi_lookup->msix_io < ioc->reply_queue_count)) | |
2841 | msix_task = scsi_lookup->msix_io; | |
2842 | else | |
2843 | msix_task = 0; | |
81c16f83 | 2844 | ioc->put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2845 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 SR |
2846 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
2847 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
2848 | ioc->name, __func__); | |
2849 | _debug_dump_mf(mpi_request, | |
2850 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2851 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { | |
98c56ad3 CO |
2852 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2853 | FORCE_BIG_HAMMER); | |
f92363d1 | 2854 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2855 | goto out; |
f92363d1 SR |
2856 | } |
2857 | } | |
2858 | ||
5f0dfb7a C |
2859 | /* sync IRQs in case those were busy during flush. */ |
2860 | mpt3sas_base_sync_reply_irqs(ioc); | |
2861 | ||
f92363d1 SR |
2862 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2863 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2864 | mpi_reply = ioc->tm_cmds.reply; | |
2865 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2866 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2867 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2868 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2869 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2870 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2871 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2872 | if (mpi_reply->IOCStatus) | |
2873 | _debug_dump_mf(mpi_request, | |
2874 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2875 | } | |
2876 | } | |
2877 | ||
2878 | switch (type) { | |
2879 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | |
2880 | rc = SUCCESS; | |
2881 | if (scsi_lookup->scmd == NULL) | |
2882 | break; | |
2883 | rc = FAILED; | |
2884 | break; | |
2885 | ||
2886 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | |
2887 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) | |
2888 | rc = FAILED; | |
2889 | else | |
2890 | rc = SUCCESS; | |
2891 | break; | |
2892 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | |
2893 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: | |
2894 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) | |
2895 | rc = FAILED; | |
2896 | else | |
2897 | rc = SUCCESS; | |
2898 | break; | |
2899 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | |
2900 | rc = SUCCESS; | |
2901 | break; | |
2902 | default: | |
2903 | rc = FAILED; | |
2904 | break; | |
2905 | } | |
2906 | ||
96902835 | 2907 | out: |
f92363d1 SR |
2908 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2909 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2910 | return rc; |
96902835 | 2911 | } |
f92363d1 | 2912 | |
96902835 CO |
2913 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
2914 | uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout) | |
2915 | { | |
2916 | int ret; | |
2917 | ||
2918 | mutex_lock(&ioc->tm_cmds.mutex); | |
2919 | ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type, | |
2920 | smid_task, timeout); | |
2921 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2922 | ||
2923 | return ret; | |
f92363d1 SR |
2924 | } |
2925 | ||
2926 | /** | |
2927 | * _scsih_tm_display_info - displays info about the device | |
2928 | * @ioc: per adapter struct | |
2929 | * @scmd: pointer to scsi command object | |
2930 | * | |
2931 | * Called by task management callback handlers. | |
2932 | */ | |
2933 | static void | |
2934 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2935 | { | |
2936 | struct scsi_target *starget = scmd->device->sdev_target; | |
2937 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2938 | struct _sas_device *sas_device = NULL; | |
6ce2f1d1 | 2939 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
2940 | unsigned long flags; |
2941 | char *device_str = NULL; | |
2942 | ||
2943 | if (!priv_target) | |
2944 | return; | |
7786ab6a SR |
2945 | if (ioc->hide_ir_msg) |
2946 | device_str = "WarpDrive"; | |
2947 | else | |
2948 | device_str = "volume"; | |
f92363d1 SR |
2949 | |
2950 | scsi_print_command(scmd); | |
2951 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2952 | starget_printk(KERN_INFO, starget, | |
2953 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2954 | device_str, priv_target->handle, | |
2955 | device_str, (unsigned long long)priv_target->sas_address); | |
6ce2f1d1 SPS |
2956 | |
2957 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { | |
2958 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
2959 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target); | |
2960 | if (pcie_device) { | |
2961 | starget_printk(KERN_INFO, starget, | |
2962 | "handle(0x%04x), wwid(0x%016llx), port(%d)\n", | |
2963 | pcie_device->handle, | |
2964 | (unsigned long long)pcie_device->wwid, | |
2965 | pcie_device->port_num); | |
2966 | if (pcie_device->enclosure_handle != 0) | |
2967 | starget_printk(KERN_INFO, starget, | |
2968 | "enclosure logical id(0x%016llx), slot(%d)\n", | |
2969 | (unsigned long long) | |
2970 | pcie_device->enclosure_logical_id, | |
2971 | pcie_device->slot); | |
2972 | if (pcie_device->connector_name[0] != '\0') | |
2973 | starget_printk(KERN_INFO, starget, | |
2974 | "enclosure level(0x%04x), connector name( %s)\n", | |
2975 | pcie_device->enclosure_level, | |
2976 | pcie_device->connector_name); | |
2977 | pcie_device_put(pcie_device); | |
2978 | } | |
2979 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
2980 | ||
f92363d1 SR |
2981 | } else { |
2982 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2983 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2984 | if (sas_device) { |
2985 | if (priv_target->flags & | |
2986 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2987 | starget_printk(KERN_INFO, starget, | |
2988 | "volume handle(0x%04x), " | |
2989 | "volume wwid(0x%016llx)\n", | |
2990 | sas_device->volume_handle, | |
2991 | (unsigned long long)sas_device->volume_wwid); | |
2992 | } | |
2993 | starget_printk(KERN_INFO, starget, | |
2994 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2995 | sas_device->handle, | |
2996 | (unsigned long long)sas_device->sas_address, | |
2997 | sas_device->phy); | |
75888956 SR |
2998 | |
2999 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
3000 | NULL, starget); | |
d1cb5e49 SR |
3001 | |
3002 | sas_device_put(sas_device); | |
f92363d1 SR |
3003 | } |
3004 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3005 | } | |
3006 | } | |
3007 | ||
3008 | /** | |
8a7e4c24 | 3009 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
3010 | * @scmd: pointer to scsi command object |
3011 | * | |
3012 | * Returns SUCCESS if command aborted else FAILED | |
3013 | */ | |
8bbb1cf6 | 3014 | static int |
8a7e4c24 | 3015 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
3016 | { |
3017 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3018 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3019 | u16 smid; | |
3020 | u16 handle; | |
3021 | int r; | |
3022 | ||
3023 | sdev_printk(KERN_INFO, scmd->device, | |
3024 | "attempting task abort! scmd(%p)\n", scmd); | |
3025 | _scsih_tm_display_info(ioc, scmd); | |
3026 | ||
3027 | sas_device_priv_data = scmd->device->hostdata; | |
3028 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3029 | sdev_printk(KERN_INFO, scmd->device, | |
3030 | "device been deleted! scmd(%p)\n", scmd); | |
3031 | scmd->result = DID_NO_CONNECT << 16; | |
3032 | scmd->scsi_done(scmd); | |
3033 | r = SUCCESS; | |
3034 | goto out; | |
3035 | } | |
3036 | ||
3037 | /* search for the command */ | |
3038 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); | |
3039 | if (!smid) { | |
3040 | scmd->result = DID_RESET << 16; | |
3041 | r = SUCCESS; | |
3042 | goto out; | |
3043 | } | |
3044 | ||
3045 | /* for hidden raid components and volumes this is not supported */ | |
3046 | if (sas_device_priv_data->sas_target->flags & | |
3047 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
3048 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
3049 | scmd->result = DID_RESET << 16; | |
3050 | r = FAILED; | |
3051 | goto out; | |
3052 | } | |
3053 | ||
3054 | mpt3sas_halt_firmware(ioc); | |
3055 | ||
3056 | handle = sas_device_priv_data->sas_target->handle; | |
96902835 | 3057 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 3058 | scmd->device->id, scmd->device->lun, |
96902835 | 3059 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30); |
f92363d1 SR |
3060 | |
3061 | out: | |
3062 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
3063 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
3064 | return r; | |
3065 | } | |
3066 | ||
3067 | /** | |
8a7e4c24 | 3068 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
3069 | * @scmd: pointer to scsi command object |
3070 | * | |
3071 | * Returns SUCCESS if command aborted else FAILED | |
3072 | */ | |
8bbb1cf6 | 3073 | static int |
8a7e4c24 | 3074 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3075 | { |
3076 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3077 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 3078 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
3079 | u16 handle; |
3080 | int r; | |
3081 | ||
d1cb5e49 SR |
3082 | struct scsi_target *starget = scmd->device->sdev_target; |
3083 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
3084 | ||
f92363d1 SR |
3085 | sdev_printk(KERN_INFO, scmd->device, |
3086 | "attempting device reset! scmd(%p)\n", scmd); | |
3087 | _scsih_tm_display_info(ioc, scmd); | |
3088 | ||
3089 | sas_device_priv_data = scmd->device->hostdata; | |
3090 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3091 | sdev_printk(KERN_INFO, scmd->device, | |
3092 | "device been deleted! scmd(%p)\n", scmd); | |
3093 | scmd->result = DID_NO_CONNECT << 16; | |
3094 | scmd->scsi_done(scmd); | |
3095 | r = SUCCESS; | |
3096 | goto out; | |
3097 | } | |
3098 | ||
3099 | /* for hidden raid components obtain the volume_handle */ | |
3100 | handle = 0; | |
3101 | if (sas_device_priv_data->sas_target->flags & | |
3102 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3103 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3104 | target_priv_data); | |
f92363d1 SR |
3105 | if (sas_device) |
3106 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3107 | } else |
3108 | handle = sas_device_priv_data->sas_target->handle; | |
3109 | ||
3110 | if (!handle) { | |
3111 | scmd->result = DID_RESET << 16; | |
3112 | r = FAILED; | |
3113 | goto out; | |
3114 | } | |
3115 | ||
96902835 | 3116 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 3117 | scmd->device->id, scmd->device->lun, |
96902835 | 3118 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30); |
f92363d1 SR |
3119 | |
3120 | out: | |
3121 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
3122 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3123 | |
3124 | if (sas_device) | |
3125 | sas_device_put(sas_device); | |
3126 | ||
f92363d1 SR |
3127 | return r; |
3128 | } | |
3129 | ||
3130 | /** | |
8a7e4c24 | 3131 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
3132 | * @scmd: pointer to scsi command object |
3133 | * | |
3134 | * Returns SUCCESS if command aborted else FAILED | |
3135 | */ | |
8bbb1cf6 | 3136 | static int |
8a7e4c24 | 3137 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3138 | { |
3139 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3140 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 3141 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
3142 | u16 handle; |
3143 | int r; | |
3144 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 3145 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 SR |
3146 | |
3147 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
3148 | scmd); | |
3149 | _scsih_tm_display_info(ioc, scmd); | |
3150 | ||
3151 | sas_device_priv_data = scmd->device->hostdata; | |
3152 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3153 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", | |
3154 | scmd); | |
3155 | scmd->result = DID_NO_CONNECT << 16; | |
3156 | scmd->scsi_done(scmd); | |
3157 | r = SUCCESS; | |
3158 | goto out; | |
3159 | } | |
3160 | ||
3161 | /* for hidden raid components obtain the volume_handle */ | |
3162 | handle = 0; | |
3163 | if (sas_device_priv_data->sas_target->flags & | |
3164 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
3165 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
3166 | target_priv_data); | |
f92363d1 SR |
3167 | if (sas_device) |
3168 | handle = sas_device->volume_handle; | |
f92363d1 SR |
3169 | } else |
3170 | handle = sas_device_priv_data->sas_target->handle; | |
3171 | ||
3172 | if (!handle) { | |
3173 | scmd->result = DID_RESET << 16; | |
3174 | r = FAILED; | |
3175 | goto out; | |
3176 | } | |
3177 | ||
96902835 | 3178 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 3179 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
96902835 | 3180 | 30); |
f92363d1 SR |
3181 | |
3182 | out: | |
3183 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
3184 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
3185 | |
3186 | if (sas_device) | |
3187 | sas_device_put(sas_device); | |
3188 | ||
f92363d1 SR |
3189 | return r; |
3190 | } | |
3191 | ||
3192 | ||
3193 | /** | |
8a7e4c24 | 3194 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
3195 | * @scmd: pointer to scsi command object |
3196 | * | |
3197 | * Returns SUCCESS if command aborted else FAILED | |
3198 | */ | |
8bbb1cf6 | 3199 | static int |
8a7e4c24 | 3200 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
3201 | { |
3202 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
3203 | int r, retval; | |
3204 | ||
3205 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
3206 | ioc->name, scmd); | |
3207 | scsi_print_command(scmd); | |
3208 | ||
ddb588be SR |
3209 | if (ioc->is_driver_loading) { |
3210 | pr_info(MPT3SAS_FMT "Blocking the host reset\n", | |
3211 | ioc->name); | |
3212 | r = FAILED; | |
3213 | goto out; | |
3214 | } | |
3215 | ||
98c56ad3 | 3216 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 3217 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 3218 | out: |
f92363d1 SR |
3219 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
3220 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
3221 | ||
3222 | return r; | |
3223 | } | |
3224 | ||
3225 | /** | |
3226 | * _scsih_fw_event_add - insert and queue up fw_event | |
3227 | * @ioc: per adapter object | |
3228 | * @fw_event: object describing the event | |
3229 | * Context: This function will acquire ioc->fw_event_lock. | |
3230 | * | |
3231 | * This adds the firmware event object into link list, then queues it up to | |
3232 | * be processed from user context. | |
3233 | * | |
3234 | * Return nothing. | |
3235 | */ | |
3236 | static void | |
3237 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
3238 | { | |
3239 | unsigned long flags; | |
3240 | ||
3241 | if (ioc->firmware_event_thread == NULL) | |
3242 | return; | |
3243 | ||
3244 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 3245 | fw_event_work_get(fw_event); |
f92363d1 SR |
3246 | INIT_LIST_HEAD(&fw_event->list); |
3247 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
3248 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 3249 | fw_event_work_get(fw_event); |
f92363d1 SR |
3250 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
3251 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3252 | } | |
3253 | ||
3254 | /** | |
146b16c8 | 3255 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
3256 | * @ioc: per adapter object |
3257 | * @fw_event: object describing the event | |
3258 | * Context: This function will acquire ioc->fw_event_lock. | |
3259 | * | |
146b16c8 | 3260 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
3261 | * |
3262 | * Return nothing. | |
3263 | */ | |
3264 | static void | |
146b16c8 | 3265 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
3266 | *fw_event) |
3267 | { | |
3268 | unsigned long flags; | |
3269 | ||
3270 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3271 | if (!list_empty(&fw_event->list)) { |
3272 | list_del_init(&fw_event->list); | |
3273 | fw_event_work_put(fw_event); | |
3274 | } | |
f92363d1 SR |
3275 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3276 | } | |
3277 | ||
3278 | ||
3279 | /** | |
3280 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3281 | * @ioc: per adapter object | |
3282 | * @event_data: trigger event data | |
3283 | * | |
3284 | * Return nothing. | |
3285 | */ | |
3286 | void | |
3287 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3288 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3289 | { | |
3290 | struct fw_event_work *fw_event; | |
146b16c8 | 3291 | u16 sz; |
f92363d1 SR |
3292 | |
3293 | if (ioc->is_driver_loading) | |
3294 | return; | |
146b16c8 SR |
3295 | sz = sizeof(*event_data); |
3296 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3297 | if (!fw_event) |
3298 | return; | |
f92363d1 SR |
3299 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3300 | fw_event->ioc = ioc; | |
3301 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3302 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3303 | fw_event_work_put(fw_event); |
f92363d1 SR |
3304 | } |
3305 | ||
3306 | /** | |
3307 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3308 | * @ioc: per adapter object | |
3309 | * | |
3310 | * Return nothing. | |
3311 | */ | |
3312 | static void | |
3313 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3314 | { | |
3315 | struct fw_event_work *fw_event; | |
3316 | ||
3317 | if (ioc->is_driver_loading) | |
3318 | return; | |
146b16c8 | 3319 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3320 | if (!fw_event) |
3321 | return; | |
3322 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3323 | fw_event->ioc = ioc; | |
3324 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3325 | fw_event_work_put(fw_event); |
f92363d1 SR |
3326 | } |
3327 | ||
3328 | /** | |
3329 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3330 | * @ioc: per adapter object | |
3331 | * | |
3332 | * Return nothing. | |
3333 | */ | |
3334 | void | |
3335 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3336 | { | |
3337 | struct fw_event_work *fw_event; | |
3338 | ||
146b16c8 | 3339 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3340 | if (!fw_event) |
3341 | return; | |
3342 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3343 | fw_event->ioc = ioc; | |
3344 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3345 | fw_event_work_put(fw_event); |
3346 | } | |
3347 | ||
3348 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3349 | { | |
3350 | unsigned long flags; | |
3351 | struct fw_event_work *fw_event = NULL; | |
3352 | ||
3353 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3354 | if (!list_empty(&ioc->fw_event_list)) { | |
3355 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3356 | struct fw_event_work, list); | |
3357 | list_del_init(&fw_event->list); | |
3358 | } | |
3359 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3360 | ||
3361 | return fw_event; | |
f92363d1 SR |
3362 | } |
3363 | ||
3364 | /** | |
3365 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3366 | * @ioc: per adapter object | |
3367 | * | |
3368 | * Walk the firmware event queue, either killing timers, or waiting | |
3369 | * for outstanding events to complete | |
3370 | * | |
3371 | * Return nothing. | |
3372 | */ | |
3373 | static void | |
3374 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3375 | { | |
146b16c8 | 3376 | struct fw_event_work *fw_event; |
f92363d1 SR |
3377 | |
3378 | if (list_empty(&ioc->fw_event_list) || | |
3379 | !ioc->firmware_event_thread || in_interrupt()) | |
3380 | return; | |
3381 | ||
146b16c8 SR |
3382 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3383 | /* | |
3384 | * Wait on the fw_event to complete. If this returns 1, then | |
3385 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3386 | * reference the work had on the fw_event. |
146b16c8 SR |
3387 | * |
3388 | * If it did execute, we wait for it to finish, and the put will | |
3389 | * happen from _firmware_event_work() | |
3390 | */ | |
b8ac0cc7 | 3391 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3392 | fw_event_work_put(fw_event); |
3393 | ||
3394 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3395 | } |
3396 | } | |
3397 | ||
df838f92 SR |
3398 | /** |
3399 | * _scsih_internal_device_block - block the sdev device | |
3400 | * @sdev: per device object | |
3401 | * @sas_device_priv_data : per device driver private data | |
3402 | * | |
3403 | * make sure device is blocked without error, if not | |
3404 | * print an error | |
3405 | */ | |
3406 | static void | |
3407 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3408 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3409 | { | |
3410 | int r = 0; | |
3411 | ||
3412 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3413 | sas_device_priv_data->sas_target->handle); | |
3414 | sas_device_priv_data->block = 1; | |
3415 | ||
551eb598 | 3416 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3417 | if (r == -EINVAL) |
3418 | sdev_printk(KERN_WARNING, sdev, | |
3419 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3420 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3421 | } |
3422 | ||
3423 | /** | |
3424 | * _scsih_internal_device_unblock - unblock the sdev device | |
3425 | * @sdev: per device object | |
3426 | * @sas_device_priv_data : per device driver private data | |
3427 | * make sure device is unblocked without error, if not retry | |
3428 | * by blocking and then unblocking | |
3429 | */ | |
3430 | ||
3431 | static void | |
3432 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3433 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3434 | { | |
3435 | int r = 0; | |
3436 | ||
3437 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3438 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3439 | sas_device_priv_data->block = 0; | |
43f7571b | 3440 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3441 | if (r == -EINVAL) { |
3442 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3443 | * device addition but the request queue is still stopped by | |
3444 | * our earlier block call. We need to perform a block again | |
3445 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3446 | ||
3447 | sdev_printk(KERN_WARNING, sdev, | |
3448 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3449 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3450 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3451 | sas_device_priv_data->block = 1; |
551eb598 | 3452 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3453 | if (r) |
3454 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3455 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3456 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3457 | |
3458 | sas_device_priv_data->block = 0; | |
43f7571b | 3459 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3460 | if (r) |
3461 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3462 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3463 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3464 | } |
3465 | } | |
3466 | ||
f92363d1 SR |
3467 | /** |
3468 | * _scsih_ublock_io_all_device - unblock every device | |
3469 | * @ioc: per adapter object | |
3470 | * | |
3471 | * change the device state from block to running | |
3472 | */ | |
3473 | static void | |
3474 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3475 | { | |
3476 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3477 | struct scsi_device *sdev; | |
3478 | ||
3479 | shost_for_each_device(sdev, ioc->shost) { | |
3480 | sas_device_priv_data = sdev->hostdata; | |
3481 | if (!sas_device_priv_data) | |
3482 | continue; | |
3483 | if (!sas_device_priv_data->block) | |
3484 | continue; | |
3485 | ||
f92363d1 SR |
3486 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3487 | "device_running, handle(0x%04x)\n", | |
3488 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3489 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3490 | } |
3491 | } | |
3492 | ||
3493 | ||
3494 | /** | |
3495 | * _scsih_ublock_io_device - prepare device to be deleted | |
3496 | * @ioc: per adapter object | |
3497 | * @sas_addr: sas address | |
3498 | * | |
3499 | * unblock then put device in offline state | |
3500 | */ | |
3501 | static void | |
3502 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3503 | { | |
3504 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3505 | struct scsi_device *sdev; | |
3506 | ||
3507 | shost_for_each_device(sdev, ioc->shost) { | |
3508 | sas_device_priv_data = sdev->hostdata; | |
3509 | if (!sas_device_priv_data) | |
3510 | continue; | |
3511 | if (sas_device_priv_data->sas_target->sas_address | |
3512 | != sas_address) | |
3513 | continue; | |
df838f92 SR |
3514 | if (sas_device_priv_data->block) |
3515 | _scsih_internal_device_unblock(sdev, | |
3516 | sas_device_priv_data); | |
f92363d1 SR |
3517 | } |
3518 | } | |
3519 | ||
3520 | /** | |
3521 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3522 | * @ioc: per adapter object | |
3523 | * @handle: device handle | |
3524 | * | |
6c7abffc | 3525 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3526 | */ |
3527 | static void | |
3528 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3529 | { | |
3530 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3531 | struct scsi_device *sdev; | |
3532 | ||
3533 | shost_for_each_device(sdev, ioc->shost) { | |
3534 | sas_device_priv_data = sdev->hostdata; | |
3535 | if (!sas_device_priv_data) | |
3536 | continue; | |
3537 | if (sas_device_priv_data->block) | |
3538 | continue; | |
30158dc9 SS |
3539 | if (sas_device_priv_data->ignore_delay_remove) { |
3540 | sdev_printk(KERN_INFO, sdev, | |
3541 | "%s skip device_block for SES handle(0x%04x)\n", | |
3542 | __func__, sas_device_priv_data->sas_target->handle); | |
3543 | continue; | |
3544 | } | |
df838f92 | 3545 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3546 | } |
3547 | } | |
3548 | ||
3549 | /** | |
3550 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3551 | * @ioc: per adapter object | |
3552 | * @handle: device handle | |
3553 | * | |
6c7abffc | 3554 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3555 | */ |
3556 | static void | |
3557 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3558 | { | |
3559 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3560 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3561 | struct _sas_device *sas_device; |
3562 | ||
d1cb5e49 | 3563 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3564 | |
3565 | shost_for_each_device(sdev, ioc->shost) { | |
3566 | sas_device_priv_data = sdev->hostdata; | |
3567 | if (!sas_device_priv_data) | |
3568 | continue; | |
3569 | if (sas_device_priv_data->sas_target->handle != handle) | |
3570 | continue; | |
3571 | if (sas_device_priv_data->block) | |
3572 | continue; | |
4318c734 | 3573 | if (sas_device && sas_device->pend_sas_rphy_add) |
e4bc7f5c | 3574 | continue; |
30158dc9 SS |
3575 | if (sas_device_priv_data->ignore_delay_remove) { |
3576 | sdev_printk(KERN_INFO, sdev, | |
3577 | "%s skip device_block for SES handle(0x%04x)\n", | |
3578 | __func__, sas_device_priv_data->sas_target->handle); | |
3579 | continue; | |
3580 | } | |
df838f92 | 3581 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3582 | } |
d1cb5e49 | 3583 | |
4318c734 SPS |
3584 | if (sas_device) |
3585 | sas_device_put(sas_device); | |
f92363d1 SR |
3586 | } |
3587 | ||
3588 | /** | |
3589 | * _scsih_block_io_to_children_attached_to_ex | |
3590 | * @ioc: per adapter object | |
3591 | * @sas_expander: the sas_device object | |
3592 | * | |
3593 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3594 | * attached to this expander. This function called when expander is | |
3595 | * pulled. | |
3596 | */ | |
3597 | static void | |
3598 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3599 | struct _sas_node *sas_expander) | |
3600 | { | |
3601 | struct _sas_port *mpt3sas_port; | |
3602 | struct _sas_device *sas_device; | |
3603 | struct _sas_node *expander_sibling; | |
3604 | unsigned long flags; | |
3605 | ||
3606 | if (!sas_expander) | |
3607 | return; | |
3608 | ||
3609 | list_for_each_entry(mpt3sas_port, | |
3610 | &sas_expander->sas_port_list, port_list) { | |
3611 | if (mpt3sas_port->remote_identify.device_type == | |
3612 | SAS_END_DEVICE) { | |
3613 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3614 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3615 | mpt3sas_port->remote_identify.sas_address); | |
3616 | if (sas_device) { | |
f92363d1 | 3617 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3618 | ioc->blocking_handles); |
3619 | sas_device_put(sas_device); | |
3620 | } | |
f92363d1 SR |
3621 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3622 | } | |
3623 | } | |
3624 | ||
3625 | list_for_each_entry(mpt3sas_port, | |
3626 | &sas_expander->sas_port_list, port_list) { | |
3627 | ||
3628 | if (mpt3sas_port->remote_identify.device_type == | |
3629 | SAS_EDGE_EXPANDER_DEVICE || | |
3630 | mpt3sas_port->remote_identify.device_type == | |
3631 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3632 | expander_sibling = | |
3633 | mpt3sas_scsih_expander_find_by_sas_address( | |
3634 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3635 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3636 | expander_sibling); | |
3637 | } | |
3638 | } | |
3639 | } | |
3640 | ||
3641 | /** | |
3642 | * _scsih_block_io_to_children_attached_directly | |
3643 | * @ioc: per adapter object | |
3644 | * @event_data: topology change event data | |
3645 | * | |
3646 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3647 | * direct attached during device pull. | |
3648 | */ | |
3649 | static void | |
3650 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3651 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3652 | { | |
3653 | int i; | |
3654 | u16 handle; | |
3655 | u16 reason_code; | |
f92363d1 SR |
3656 | |
3657 | for (i = 0; i < event_data->NumEntries; i++) { | |
3658 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3659 | if (!handle) | |
3660 | continue; | |
f92363d1 SR |
3661 | reason_code = event_data->PHY[i].PhyStatus & |
3662 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3663 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3664 | _scsih_block_io_device(ioc, handle); | |
3665 | } | |
3666 | } | |
3667 | ||
4318c734 SPS |
3668 | /** |
3669 | * _scsih_block_io_to_pcie_children_attached_directly | |
3670 | * @ioc: per adapter object | |
3671 | * @event_data: topology change event data | |
3672 | * | |
3673 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3674 | * direct attached during device pull/reconnect. | |
3675 | */ | |
3676 | static void | |
3677 | _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3678 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
3679 | { | |
3680 | int i; | |
3681 | u16 handle; | |
3682 | u16 reason_code; | |
3683 | ||
3684 | for (i = 0; i < event_data->NumEntries; i++) { | |
3685 | handle = | |
3686 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
3687 | if (!handle) | |
3688 | continue; | |
3689 | reason_code = event_data->PortEntry[i].PortStatus; | |
3690 | if (reason_code == | |
3691 | MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING) | |
3692 | _scsih_block_io_device(ioc, handle); | |
3693 | } | |
3694 | } | |
f92363d1 SR |
3695 | /** |
3696 | * _scsih_tm_tr_send - send task management request | |
3697 | * @ioc: per adapter object | |
3698 | * @handle: device handle | |
3699 | * Context: interrupt time. | |
3700 | * | |
3701 | * This code is to initiate the device removal handshake protocol | |
3702 | * with controller firmware. This function will issue target reset | |
3703 | * using high priority request queue. It will send a sas iounit | |
3704 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3705 | * | |
3706 | * This is designed to send muliple task management request at the same | |
3707 | * time to the fifo. If the fifo is full, we will append the request, | |
3708 | * and process it in a future completion. | |
3709 | */ | |
3710 | static void | |
3711 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3712 | { | |
3713 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3714 | u16 smid; | |
d1cb5e49 | 3715 | struct _sas_device *sas_device = NULL; |
6ce2f1d1 | 3716 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
3717 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3718 | u64 sas_address = 0; | |
3719 | unsigned long flags; | |
3720 | struct _tr_list *delayed_tr; | |
3721 | u32 ioc_state; | |
3722 | ||
6ce2f1d1 | 3723 | if (ioc->pci_error_recovery) { |
f92363d1 SR |
3724 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
3725 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
3726 | __func__, ioc->name, | |
3727 | handle)); | |
3728 | return; | |
3729 | } | |
3730 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3731 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3732 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3733 | "%s: host is not operational: handle(0x%04x)\n", | |
3734 | __func__, ioc->name, | |
3735 | handle)); | |
3736 | return; | |
3737 | } | |
3738 | ||
3739 | /* if PD, then return */ | |
3740 | if (test_bit(handle, ioc->pd_handles)) | |
3741 | return; | |
3742 | ||
c696f7b8 SPS |
3743 | clear_bit(handle, ioc->pend_os_device_add); |
3744 | ||
f92363d1 | 3745 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3746 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3747 | if (sas_device && sas_device->starget && |
3748 | sas_device->starget->hostdata) { | |
3749 | sas_target_priv_data = sas_device->starget->hostdata; | |
3750 | sas_target_priv_data->deleted = 1; | |
3751 | sas_address = sas_device->sas_address; | |
3752 | } | |
3753 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6ce2f1d1 SPS |
3754 | if (!sas_device) { |
3755 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
3756 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
3757 | if (pcie_device && pcie_device->starget && | |
3758 | pcie_device->starget->hostdata) { | |
3759 | sas_target_priv_data = pcie_device->starget->hostdata; | |
3760 | sas_target_priv_data->deleted = 1; | |
3761 | sas_address = pcie_device->wwid; | |
3762 | } | |
3763 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
3764 | } | |
f92363d1 SR |
3765 | if (sas_target_priv_data) { |
3766 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3767 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3768 | ioc->name, handle, | |
3769 | (unsigned long long)sas_address)); | |
6ce2f1d1 SPS |
3770 | if (sas_device) { |
3771 | if (sas_device->enclosure_handle != 0) | |
3772 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3773 | "setting delete flag:enclosure logical " | |
3774 | "id(0x%016llx), slot(%d)\n", ioc->name, | |
3775 | (unsigned long long) | |
3776 | sas_device->enclosure_logical_id, | |
3777 | sas_device->slot)); | |
3778 | if (sas_device->connector_name[0] != '\0') | |
3779 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3780 | "setting delete flag: enclosure " | |
3781 | "level(0x%04x), connector name( %s)\n", | |
3782 | ioc->name, sas_device->enclosure_level, | |
3783 | sas_device->connector_name)); | |
3784 | } else if (pcie_device) { | |
3785 | if (pcie_device->enclosure_handle != 0) | |
3786 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3787 | "setting delete flag: logical " | |
3788 | "id(0x%016llx), slot(%d)\n", ioc->name, | |
3789 | (unsigned long long) | |
3790 | pcie_device->enclosure_logical_id, | |
3791 | pcie_device->slot)); | |
3792 | if (pcie_device->connector_name[0] != '\0') | |
3793 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3794 | "setting delete flag:, enclosure " | |
3795 | "level(0x%04x), " | |
3796 | "connector name( %s)\n", ioc->name, | |
3797 | pcie_device->enclosure_level, | |
3798 | pcie_device->connector_name)); | |
3799 | } | |
f92363d1 SR |
3800 | _scsih_ublock_io_device(ioc, sas_address); |
3801 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3802 | } | |
3803 | ||
3804 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3805 | if (!smid) { | |
3806 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3807 | if (!delayed_tr) | |
d1cb5e49 | 3808 | goto out; |
f92363d1 SR |
3809 | INIT_LIST_HEAD(&delayed_tr->list); |
3810 | delayed_tr->handle = handle; | |
3811 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3812 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3813 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3814 | ioc->name, handle)); | |
d1cb5e49 | 3815 | goto out; |
f92363d1 SR |
3816 | } |
3817 | ||
3818 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3819 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3820 | ioc->name, handle, smid, | |
3821 | ioc->tm_tr_cb_idx)); | |
3822 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3823 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3824 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3825 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3826 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c696f7b8 | 3827 | set_bit(handle, ioc->device_remove_in_progress); |
81c16f83 | 3828 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3829 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3830 | |
3831 | out: | |
3832 | if (sas_device) | |
3833 | sas_device_put(sas_device); | |
6ce2f1d1 SPS |
3834 | if (pcie_device) |
3835 | pcie_device_put(pcie_device); | |
f92363d1 SR |
3836 | } |
3837 | ||
3838 | /** | |
3839 | * _scsih_tm_tr_complete - | |
3840 | * @ioc: per adapter object | |
3841 | * @smid: system request message index | |
3842 | * @msix_index: MSIX table index supplied by the OS | |
3843 | * @reply: reply message frame(lower 32bit addr) | |
3844 | * Context: interrupt time. | |
3845 | * | |
3846 | * This is the target reset completion routine. | |
3847 | * This code is part of the code to initiate the device removal | |
3848 | * handshake protocol with controller firmware. | |
3849 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3850 | * | |
3851 | * Return 1 meaning mf should be freed from _base_interrupt | |
3852 | * 0 means the mf is freed from this function. | |
3853 | */ | |
3854 | static u8 | |
3855 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3856 | u32 reply) | |
3857 | { | |
3858 | u16 handle; | |
3859 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3860 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3861 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3862 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3863 | u16 smid_sas_ctrl; | |
3864 | u32 ioc_state; | |
fd0331b3 | 3865 | struct _sc_list *delayed_sc; |
f92363d1 SR |
3866 | |
3867 | if (ioc->remove_host) { | |
3868 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3869 | "%s: host has been removed\n", __func__, ioc->name)); | |
3870 | return 1; | |
3871 | } else if (ioc->pci_error_recovery) { | |
3872 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3873 | "%s: host in pci error recovery\n", __func__, | |
3874 | ioc->name)); | |
3875 | return 1; | |
3876 | } | |
3877 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3878 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3879 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3880 | "%s: host is not operational\n", __func__, ioc->name)); | |
3881 | return 1; | |
3882 | } | |
3883 | if (unlikely(!mpi_reply)) { | |
3884 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3885 | ioc->name, __FILE__, __LINE__, __func__); | |
3886 | return 1; | |
3887 | } | |
3888 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3889 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3890 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3891 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3892 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3893 | ioc->name, handle, | |
3894 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3895 | return 0; | |
3896 | } | |
3897 | ||
3898 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
3899 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3900 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3901 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3902 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3903 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3904 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3905 | ||
3906 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3907 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3908 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3909 | if (!delayed_sc) | |
3910 | return _scsih_check_for_pending_tm(ioc, smid); | |
3911 | INIT_LIST_HEAD(&delayed_sc->list); | |
3912 | delayed_sc->handle = mpi_request_tm->DevHandle; | |
3913 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); | |
3914 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3915 | "DELAYED:sc:handle(0x%04x), (open)\n", | |
3916 | ioc->name, handle)); | |
3917 | return _scsih_check_for_pending_tm(ioc, smid); | |
f92363d1 SR |
3918 | } |
3919 | ||
3920 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3921 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3922 | ioc->name, handle, smid_sas_ctrl, | |
3923 | ioc->tm_sas_control_cb_idx)); | |
3924 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
3925 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3926 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3927 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3928 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
81c16f83 | 3929 | ioc->put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3930 | |
3931 | return _scsih_check_for_pending_tm(ioc, smid); | |
3932 | } | |
3933 | ||
3934 | ||
3935 | /** | |
3936 | * _scsih_sas_control_complete - completion routine | |
3937 | * @ioc: per adapter object | |
3938 | * @smid: system request message index | |
3939 | * @msix_index: MSIX table index supplied by the OS | |
3940 | * @reply: reply message frame(lower 32bit addr) | |
3941 | * Context: interrupt time. | |
3942 | * | |
3943 | * This is the sas iounit control completion routine. | |
3944 | * This code is part of the code to initiate the device removal | |
3945 | * handshake protocol with controller firmware. | |
3946 | * | |
3947 | * Return 1 meaning mf should be freed from _base_interrupt | |
3948 | * 0 means the mf is freed from this function. | |
3949 | */ | |
3950 | static u8 | |
3951 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3952 | u8 msix_index, u32 reply) | |
3953 | { | |
3954 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3955 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3956 | ||
3957 | if (likely(mpi_reply)) { | |
3958 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3959 | "sc_complete:handle(0x%04x), (open) " | |
3960 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3961 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
3962 | le16_to_cpu(mpi_reply->IOCStatus), | |
3963 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3964 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3965 | MPI2_IOCSTATUS_SUCCESS) { | |
3966 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3967 | ioc->device_remove_in_progress); | |
3968 | } | |
f92363d1 SR |
3969 | } else { |
3970 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3971 | ioc->name, __FILE__, __LINE__, __func__); | |
3972 | } | |
fd0331b3 | 3973 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3974 | } |
3975 | ||
3976 | /** | |
3977 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3978 | * @ioc: per adapter object | |
3979 | * @handle: device handle | |
3980 | * Context: interrupt time. | |
3981 | * | |
3982 | * This is designed to send muliple task management request at the same | |
3983 | * time to the fifo. If the fifo is full, we will append the request, | |
3984 | * and process it in a future completion. | |
3985 | */ | |
3986 | static void | |
3987 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3988 | { | |
3989 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3990 | u16 smid; | |
3991 | struct _tr_list *delayed_tr; | |
3992 | ||
3993 | if (ioc->shost_recovery || ioc->remove_host || | |
3994 | ioc->pci_error_recovery) { | |
3995 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3996 | "%s: host reset in progress!\n", | |
3997 | __func__, ioc->name)); | |
3998 | return; | |
3999 | } | |
4000 | ||
4001 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
4002 | if (!smid) { | |
4003 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4004 | if (!delayed_tr) | |
4005 | return; | |
4006 | INIT_LIST_HEAD(&delayed_tr->list); | |
4007 | delayed_tr->handle = handle; | |
4008 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
4009 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4010 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
4011 | ioc->name, handle)); | |
4012 | return; | |
4013 | } | |
4014 | ||
4015 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4016 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4017 | ioc->name, handle, smid, | |
4018 | ioc->tm_tr_volume_cb_idx)); | |
4019 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4020 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
4021 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
4022 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4023 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
81c16f83 | 4024 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
4025 | } |
4026 | ||
4027 | /** | |
4028 | * _scsih_tm_volume_tr_complete - target reset completion | |
4029 | * @ioc: per adapter object | |
4030 | * @smid: system request message index | |
4031 | * @msix_index: MSIX table index supplied by the OS | |
4032 | * @reply: reply message frame(lower 32bit addr) | |
4033 | * Context: interrupt time. | |
4034 | * | |
4035 | * Return 1 meaning mf should be freed from _base_interrupt | |
4036 | * 0 means the mf is freed from this function. | |
4037 | */ | |
4038 | static u8 | |
4039 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
4040 | u8 msix_index, u32 reply) | |
4041 | { | |
4042 | u16 handle; | |
4043 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
4044 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
4045 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
4046 | ||
4047 | if (ioc->shost_recovery || ioc->remove_host || | |
4048 | ioc->pci_error_recovery) { | |
4049 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4050 | "%s: host reset in progress!\n", | |
4051 | __func__, ioc->name)); | |
4052 | return 1; | |
4053 | } | |
4054 | if (unlikely(!mpi_reply)) { | |
4055 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
4056 | ioc->name, __FILE__, __LINE__, __func__); | |
4057 | return 1; | |
4058 | } | |
4059 | ||
4060 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
4061 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
4062 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
4063 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
4064 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
4065 | ioc->name, handle, | |
4066 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
4067 | return 0; | |
4068 | } | |
4069 | ||
4070 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4071 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
4072 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
4073 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
4074 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
4075 | le32_to_cpu(mpi_reply->TerminationCount))); | |
4076 | ||
4077 | return _scsih_check_for_pending_tm(ioc, smid); | |
4078 | } | |
4079 | ||
fd0331b3 SS |
4080 | /** |
4081 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
4082 | * @ioc: per adapter object | |
4083 | * @smid: system request message index | |
4084 | * @event: Event ID | |
4085 | * @event_context: used to track events uniquely | |
4086 | * | |
4087 | * Context - processed in interrupt context. | |
4088 | */ | |
8bbb1cf6 | 4089 | static void |
fd0331b3 SS |
4090 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event, |
4091 | u32 event_context) | |
4092 | { | |
4093 | Mpi2EventAckRequest_t *ack_request; | |
4094 | int i = smid - ioc->internal_smid; | |
4095 | unsigned long flags; | |
4096 | ||
4097 | /* Without releasing the smid just update the | |
4098 | * call back index and reuse the same smid for | |
4099 | * processing this delayed request | |
4100 | */ | |
4101 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4102 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
4103 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4104 | ||
4105 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4106 | "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
4107 | ioc->name, le16_to_cpu(event), smid, | |
4108 | ioc->base_cb_idx)); | |
4109 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4110 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | |
4111 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | |
4112 | ack_request->Event = event; | |
4113 | ack_request->EventContext = event_context; | |
4114 | ack_request->VF_ID = 0; /* TODO */ | |
4115 | ack_request->VP_ID = 0; | |
81c16f83 | 4116 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4117 | } |
4118 | ||
4119 | /** | |
4120 | * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed | |
4121 | * sas_io_unit_ctrl messages | |
4122 | * @ioc: per adapter object | |
4123 | * @smid: system request message index | |
4124 | * @handle: device handle | |
4125 | * | |
4126 | * Context - processed in interrupt context. | |
4127 | */ | |
8bbb1cf6 | 4128 | static void |
fd0331b3 SS |
4129 | _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc, |
4130 | u16 smid, u16 handle) | |
4131 | { | |
4132 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
4133 | u32 ioc_state; | |
4134 | int i = smid - ioc->internal_smid; | |
4135 | unsigned long flags; | |
4136 | ||
4137 | if (ioc->remove_host) { | |
4138 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4139 | "%s: host has been removed\n", | |
4140 | __func__, ioc->name)); | |
4141 | return; | |
4142 | } else if (ioc->pci_error_recovery) { | |
4143 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4144 | "%s: host in pci error recovery\n", | |
4145 | __func__, ioc->name)); | |
4146 | return; | |
4147 | } | |
4148 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
4149 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
4150 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4151 | "%s: host is not operational\n", | |
4152 | __func__, ioc->name)); | |
4153 | return; | |
4154 | } | |
4155 | ||
4156 | /* Without releasing the smid just update the | |
4157 | * call back index and reuse the same smid for | |
4158 | * processing this delayed request | |
4159 | */ | |
4160 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4161 | ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx; | |
4162 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
4163 | ||
4164 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4165 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
4166 | ioc->name, le16_to_cpu(handle), smid, | |
4167 | ioc->tm_sas_control_cb_idx)); | |
4168 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4169 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
4170 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
4171 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
4172 | mpi_request->DevHandle = handle; | |
81c16f83 | 4173 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
4174 | } |
4175 | ||
4176 | /** | |
4177 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
4178 | * @ioc: per adapter object | |
4179 | * @smid: system request message index | |
4180 | * | |
4181 | * Context: Executed in interrupt context | |
4182 | * | |
4183 | * This will check delayed internal messages list, and process the | |
4184 | * next request. | |
4185 | * | |
4186 | * Return 1 meaning mf should be freed from _base_interrupt | |
4187 | * 0 means the mf is freed from this function. | |
4188 | */ | |
4189 | u8 | |
4190 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4191 | { | |
4192 | struct _sc_list *delayed_sc; | |
4193 | struct _event_ack_list *delayed_event_ack; | |
4194 | ||
4195 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
4196 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
4197 | struct _event_ack_list, list); | |
4198 | _scsih_issue_delayed_event_ack(ioc, smid, | |
4199 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
4200 | list_del(&delayed_event_ack->list); | |
4201 | kfree(delayed_event_ack); | |
4202 | return 0; | |
4203 | } | |
4204 | ||
4205 | if (!list_empty(&ioc->delayed_sc_list)) { | |
4206 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
4207 | struct _sc_list, list); | |
4208 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
4209 | delayed_sc->handle); | |
4210 | list_del(&delayed_sc->list); | |
4211 | kfree(delayed_sc); | |
4212 | return 0; | |
4213 | } | |
4214 | return 1; | |
4215 | } | |
f92363d1 SR |
4216 | |
4217 | /** | |
4218 | * _scsih_check_for_pending_tm - check for pending task management | |
4219 | * @ioc: per adapter object | |
4220 | * @smid: system request message index | |
4221 | * | |
4222 | * This will check delayed target reset list, and feed the | |
4223 | * next reqeust. | |
4224 | * | |
4225 | * Return 1 meaning mf should be freed from _base_interrupt | |
4226 | * 0 means the mf is freed from this function. | |
4227 | */ | |
4228 | static u8 | |
4229 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
4230 | { | |
4231 | struct _tr_list *delayed_tr; | |
4232 | ||
4233 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
4234 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
4235 | struct _tr_list, list); | |
4236 | mpt3sas_base_free_smid(ioc, smid); | |
4237 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
4238 | list_del(&delayed_tr->list); | |
4239 | kfree(delayed_tr); | |
4240 | return 0; | |
4241 | } | |
4242 | ||
4243 | if (!list_empty(&ioc->delayed_tr_list)) { | |
4244 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
4245 | struct _tr_list, list); | |
4246 | mpt3sas_base_free_smid(ioc, smid); | |
4247 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
4248 | list_del(&delayed_tr->list); | |
4249 | kfree(delayed_tr); | |
4250 | return 0; | |
4251 | } | |
4252 | ||
4253 | return 1; | |
4254 | } | |
4255 | ||
4256 | /** | |
4257 | * _scsih_check_topo_delete_events - sanity check on topo events | |
4258 | * @ioc: per adapter object | |
4259 | * @event_data: the event data payload | |
4260 | * | |
4261 | * This routine added to better handle cable breaker. | |
4262 | * | |
4263 | * This handles the case where driver receives multiple expander | |
4264 | * add and delete events in a single shot. When there is a delete event | |
4265 | * the routine will void any pending add events waiting in the event queue. | |
4266 | * | |
4267 | * Return nothing. | |
4268 | */ | |
4269 | static void | |
4270 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4271 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4272 | { | |
4273 | struct fw_event_work *fw_event; | |
4274 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
4275 | u16 expander_handle; | |
4276 | struct _sas_node *sas_expander; | |
4277 | unsigned long flags; | |
4278 | int i, reason_code; | |
4279 | u16 handle; | |
4280 | ||
4281 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
4282 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4283 | if (!handle) | |
4284 | continue; | |
4285 | reason_code = event_data->PHY[i].PhyStatus & | |
4286 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4287 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
4288 | _scsih_tm_tr_send(ioc, handle); | |
4289 | } | |
4290 | ||
4291 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
4292 | if (expander_handle < ioc->sas_hba.num_phys) { | |
4293 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4294 | return; | |
4295 | } | |
4296 | if (event_data->ExpStatus == | |
4297 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
4298 | /* put expander attached devices into blocking state */ | |
4299 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4300 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
4301 | expander_handle); | |
4302 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
4303 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4304 | do { | |
4305 | handle = find_first_bit(ioc->blocking_handles, | |
4306 | ioc->facts.MaxDevHandle); | |
4307 | if (handle < ioc->facts.MaxDevHandle) | |
4308 | _scsih_block_io_device(ioc, handle); | |
4309 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
4310 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
4311 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
4312 | ||
4313 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4314 | return; | |
4315 | ||
4316 | /* mark ignore flag for pending events */ | |
4317 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4318 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4319 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
4320 | fw_event->ignore) | |
4321 | continue; | |
35b62362 JL |
4322 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
4323 | fw_event->event_data; | |
f92363d1 SR |
4324 | if (local_event_data->ExpStatus == |
4325 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4326 | local_event_data->ExpStatus == | |
4327 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4328 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
4329 | expander_handle) { | |
4330 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4331 | "setting ignoring flag\n", ioc->name)); | |
4332 | fw_event->ignore = 1; | |
4333 | } | |
4334 | } | |
4335 | } | |
4336 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4337 | } | |
4338 | ||
4318c734 SPS |
4339 | /** |
4340 | * _scsih_check_pcie_topo_remove_events - sanity check on topo | |
4341 | * events | |
4342 | * @ioc: per adapter object | |
4343 | * @event_data: the event data payload | |
4344 | * | |
4345 | * This handles the case where driver receives multiple switch | |
4346 | * or device add and delete events in a single shot. When there | |
4347 | * is a delete event the routine will void any pending add | |
4348 | * events waiting in the event queue. | |
4349 | * | |
4350 | * Return nothing. | |
4351 | */ | |
4352 | static void | |
4353 | _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc, | |
4354 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
4355 | { | |
4356 | struct fw_event_work *fw_event; | |
4357 | Mpi26EventDataPCIeTopologyChangeList_t *local_event_data; | |
4358 | unsigned long flags; | |
4359 | int i, reason_code; | |
4360 | u16 handle, switch_handle; | |
4361 | ||
4362 | for (i = 0; i < event_data->NumEntries; i++) { | |
4363 | handle = | |
4364 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
4365 | if (!handle) | |
4366 | continue; | |
4367 | reason_code = event_data->PortEntry[i].PortStatus; | |
4368 | if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING) | |
4369 | _scsih_tm_tr_send(ioc, handle); | |
4370 | } | |
4371 | ||
4372 | switch_handle = le16_to_cpu(event_data->SwitchDevHandle); | |
4373 | if (!switch_handle) { | |
4374 | _scsih_block_io_to_pcie_children_attached_directly( | |
4375 | ioc, event_data); | |
4376 | return; | |
4377 | } | |
4378 | /* TODO We are not supporting cascaded PCIe Switch removal yet*/ | |
4379 | if ((event_data->SwitchStatus | |
4380 | == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) || | |
4381 | (event_data->SwitchStatus == | |
4382 | MPI26_EVENT_PCIE_TOPO_SS_RESPONDING)) | |
4383 | _scsih_block_io_to_pcie_children_attached_directly( | |
4384 | ioc, event_data); | |
4385 | ||
4386 | if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
4387 | return; | |
4388 | ||
4389 | /* mark ignore flag for pending events */ | |
4390 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
4391 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
4392 | if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST || | |
4393 | fw_event->ignore) | |
4394 | continue; | |
4395 | local_event_data = | |
4396 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
4397 | fw_event->event_data; | |
4398 | if (local_event_data->SwitchStatus == | |
4399 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
4400 | local_event_data->SwitchStatus == | |
4401 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
4402 | if (le16_to_cpu(local_event_data->SwitchDevHandle) == | |
4403 | switch_handle) { | |
4404 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4405 | "setting ignoring flag for switch event\n", | |
4406 | ioc->name)); | |
4407 | fw_event->ignore = 1; | |
4408 | } | |
4409 | } | |
4410 | } | |
4411 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4412 | } | |
4413 | ||
f92363d1 SR |
4414 | /** |
4415 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4416 | * @ioc: per adapter object | |
4417 | * @handle: device handle | |
4418 | * | |
4419 | * This returns nothing. | |
4420 | */ | |
4421 | static void | |
4422 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4423 | { | |
4424 | struct _raid_device *raid_device; | |
4425 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4426 | unsigned long flags; | |
4427 | ||
4428 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4429 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4430 | if (raid_device && raid_device->starget && |
4431 | raid_device->starget->hostdata) { | |
4432 | sas_target_priv_data = | |
4433 | raid_device->starget->hostdata; | |
4434 | sas_target_priv_data->deleted = 1; | |
4435 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4436 | "setting delete flag: handle(0x%04x), " | |
4437 | "wwid(0x%016llx)\n", ioc->name, handle, | |
4438 | (unsigned long long) raid_device->wwid)); | |
4439 | } | |
4440 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4441 | } | |
4442 | ||
4443 | /** | |
4444 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4445 | * @handle: input handle | |
4446 | * @a: handle for volume a | |
4447 | * @b: handle for volume b | |
4448 | * | |
4449 | * IR firmware only supports two raid volumes. The purpose of this | |
4450 | * routine is to set the volume handle in either a or b. When the given | |
4451 | * input handle is non-zero, or when a and b have not been set before. | |
4452 | */ | |
4453 | static void | |
4454 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4455 | { | |
4456 | if (!handle || handle == *a || handle == *b) | |
4457 | return; | |
4458 | if (!*a) | |
4459 | *a = handle; | |
4460 | else if (!*b) | |
4461 | *b = handle; | |
4462 | } | |
4463 | ||
4464 | /** | |
4465 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4466 | * @ioc: per adapter object | |
4467 | * @event_data: the event data payload | |
4468 | * Context: interrupt time. | |
4469 | * | |
4470 | * This routine will send target reset to volume, followed by target | |
4471 | * resets to the PDs. This is called when a PD has been removed, or | |
4472 | * volume has been deleted or removed. When the target reset is sent | |
4473 | * to volume, the PD target resets need to be queued to start upon | |
4474 | * completion of the volume target reset. | |
4475 | * | |
4476 | * Return nothing. | |
4477 | */ | |
4478 | static void | |
4479 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4480 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4481 | { | |
4482 | Mpi2EventIrConfigElement_t *element; | |
4483 | int i; | |
4484 | u16 handle, volume_handle, a, b; | |
4485 | struct _tr_list *delayed_tr; | |
4486 | ||
4487 | a = 0; | |
4488 | b = 0; | |
4489 | ||
7786ab6a SR |
4490 | if (ioc->is_warpdrive) |
4491 | return; | |
4492 | ||
f92363d1 SR |
4493 | /* Volume Resets for Deleted or Removed */ |
4494 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4495 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4496 | if (le32_to_cpu(event_data->Flags) & | |
4497 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4498 | continue; | |
4499 | if (element->ReasonCode == | |
4500 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4501 | element->ReasonCode == | |
4502 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4503 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4504 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4505 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4506 | } | |
4507 | } | |
4508 | ||
4509 | /* Volume Resets for UNHIDE events */ | |
4510 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4511 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4512 | if (le32_to_cpu(event_data->Flags) & | |
4513 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4514 | continue; | |
4515 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4516 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4517 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4518 | } | |
4519 | } | |
4520 | ||
4521 | if (a) | |
4522 | _scsih_tm_tr_volume_send(ioc, a); | |
4523 | if (b) | |
4524 | _scsih_tm_tr_volume_send(ioc, b); | |
4525 | ||
4526 | /* PD target resets */ | |
4527 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4528 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4529 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4530 | continue; | |
4531 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4532 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4533 | clear_bit(handle, ioc->pd_handles); | |
4534 | if (!volume_handle) | |
4535 | _scsih_tm_tr_send(ioc, handle); | |
4536 | else if (volume_handle == a || volume_handle == b) { | |
4537 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4538 | BUG_ON(!delayed_tr); | |
4539 | INIT_LIST_HEAD(&delayed_tr->list); | |
4540 | delayed_tr->handle = handle; | |
4541 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
4542 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4543 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
4544 | handle)); | |
4545 | } else | |
4546 | _scsih_tm_tr_send(ioc, handle); | |
4547 | } | |
4548 | } | |
4549 | ||
4550 | ||
4551 | /** | |
4552 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4553 | * @ioc: per adapter object | |
4554 | * @event_data: the event data payload | |
4555 | * Context: interrupt time. | |
4556 | * | |
4557 | * This will handle the case when the cable connected to entire volume is | |
4558 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4559 | * not be sent. | |
4560 | * | |
4561 | * Return nothing. | |
4562 | */ | |
4563 | static void | |
4564 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4565 | Mpi2EventDataIrVolume_t *event_data) | |
4566 | { | |
4567 | u32 state; | |
4568 | ||
4569 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4570 | return; | |
4571 | state = le32_to_cpu(event_data->NewValue); | |
4572 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4573 | MPI2_RAID_VOL_STATE_FAILED) | |
4574 | _scsih_set_volume_delete_flag(ioc, | |
4575 | le16_to_cpu(event_data->VolDevHandle)); | |
4576 | } | |
4577 | ||
2d8ce8c9 SR |
4578 | /** |
4579 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4580 | * @ioc: per adapter object | |
4581 | * @event_data: the temp threshold event data | |
4582 | * Context: interrupt time. | |
4583 | * | |
4584 | * Return nothing. | |
4585 | */ | |
4586 | static void | |
4587 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4588 | Mpi2EventDataTemperature_t *event_data) | |
4589 | { | |
4590 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
4591 | pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s" | |
4592 | " exceeded for Sensor: %d !!!\n", ioc->name, | |
4593 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | |
4594 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | |
4595 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | |
4596 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | |
4597 | event_data->SensorNum); | |
4598 | pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n", | |
4599 | ioc->name, event_data->CurrentTemperature); | |
4600 | } | |
4601 | } | |
4602 | ||
ffb58456 | 4603 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4604 | { |
ffb58456 JB |
4605 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4606 | ||
4607 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4608 | return 0; | |
4609 | ||
4610 | if (pending) | |
4611 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4612 | ||
4613 | clear_bit(0, &priv->ata_command_pending); | |
4614 | return 0; | |
7ff723ad SP |
4615 | } |
4616 | ||
f92363d1 SR |
4617 | /** |
4618 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4619 | * @ioc: per adapter object | |
4620 | * | |
4621 | * The flushing out of all pending scmd commands following host reset, | |
4622 | * where all IO is dropped to the floor. | |
4623 | * | |
4624 | * Return nothing. | |
4625 | */ | |
4626 | static void | |
4627 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4628 | { | |
4629 | struct scsi_cmnd *scmd; | |
4630 | u16 smid; | |
4631 | u16 count = 0; | |
4632 | ||
4633 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
4634 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4635 | if (!scmd) | |
4636 | continue; | |
4637 | count++; | |
ffb58456 | 4638 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4639 | mpt3sas_base_free_smid(ioc, smid); |
4640 | scsi_dma_unmap(scmd); | |
4641 | if (ioc->pci_error_recovery) | |
4642 | scmd->result = DID_NO_CONNECT << 16; | |
4643 | else | |
4644 | scmd->result = DID_RESET << 16; | |
4645 | scmd->scsi_done(scmd); | |
4646 | } | |
4647 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
4648 | ioc->name, count)); | |
4649 | } | |
4650 | ||
4651 | /** | |
4652 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4653 | * @ioc: per adapter object | |
4654 | * @scmd: pointer to scsi command object | |
6c7abffc | 4655 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4656 | * |
4657 | * Supporting protection 1 and 3. | |
4658 | * | |
4659 | * Returns nothing | |
4660 | */ | |
4661 | static void | |
4662 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4663 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4664 | { |
4665 | u16 eedp_flags; | |
4666 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4667 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4668 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4669 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4670 | ||
4671 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4672 | return; | |
4673 | ||
4674 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4675 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4676 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4677 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4678 | else | |
4679 | return; | |
4680 | ||
4681 | switch (prot_type) { | |
4682 | case SCSI_PROT_DIF_TYPE1: | |
4683 | case SCSI_PROT_DIF_TYPE2: | |
4684 | ||
4685 | /* | |
4686 | * enable ref/guard checking | |
4687 | * auto increment ref tag | |
4688 | */ | |
4689 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4690 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4691 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4692 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
648512cc | 4693 | cpu_to_be32(scsi_prot_ref_tag(scmd)); |
f92363d1 SR |
4694 | break; |
4695 | ||
4696 | case SCSI_PROT_DIF_TYPE3: | |
4697 | ||
4698 | /* | |
4699 | * enable guard checking | |
4700 | */ | |
4701 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4702 | ||
4703 | break; | |
4704 | } | |
4705 | ||
4706 | mpi_request_3v->EEDPBlockSize = | |
4707 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4708 | |
4709 | if (ioc->is_gen35_ioc) | |
4710 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4711 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4712 | } | |
4713 | ||
4714 | /** | |
4715 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4716 | * @scmd: pointer to scsi command object | |
4717 | * @ioc_status: ioc status | |
4718 | * | |
4719 | * Returns nothing | |
4720 | */ | |
4721 | static void | |
4722 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4723 | { | |
4724 | u8 ascq; | |
4725 | ||
4726 | switch (ioc_status) { | |
4727 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4728 | ascq = 0x01; | |
4729 | break; | |
4730 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4731 | ascq = 0x02; | |
4732 | break; | |
4733 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4734 | ascq = 0x03; | |
4735 | break; | |
4736 | default: | |
4737 | ascq = 0x00; | |
4738 | break; | |
4739 | } | |
4740 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4741 | ascq); | |
4742 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4743 | SAM_STAT_CHECK_CONDITION; | |
4744 | } | |
4745 | ||
f92363d1 | 4746 | /** |
8a7e4c24 | 4747 | * scsih_qcmd - main scsi request entry point |
f92363d1 SR |
4748 | * @scmd: pointer to scsi command object |
4749 | * @done: function pointer to be invoked on completion | |
4750 | * | |
4751 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4752 | * | |
4753 | * Returns 0 on success. If there's a failure, return either: | |
4754 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
4755 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4756 | */ | |
8bbb1cf6 | 4757 | static int |
8a7e4c24 | 4758 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4759 | { |
d8bfbd8d | 4760 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4761 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4762 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4763 | struct _raid_device *raid_device; |
307d9075 AM |
4764 | struct request *rq = scmd->request; |
4765 | int class; | |
016d5c35 SPS |
4766 | Mpi25SCSIIORequest_t *mpi_request; |
4767 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4768 | u32 mpi_control; |
4769 | u16 smid; | |
4770 | u16 handle; | |
4771 | ||
f92363d1 SR |
4772 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4773 | scsi_print_command(scmd); | |
f92363d1 | 4774 | |
f92363d1 SR |
4775 | sas_device_priv_data = scmd->device->hostdata; |
4776 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4777 | scmd->result = DID_NO_CONNECT << 16; | |
4778 | scmd->scsi_done(scmd); | |
4779 | return 0; | |
4780 | } | |
4781 | ||
4782 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
4783 | scmd->result = DID_NO_CONNECT << 16; | |
4784 | scmd->scsi_done(scmd); | |
4785 | return 0; | |
4786 | } | |
4787 | ||
ffb58456 JB |
4788 | /* |
4789 | * Bug work around for firmware SATL handling. The loop | |
4790 | * is based on atomic operations and ensures consistency | |
4791 | * since we're lockless at this point | |
4792 | */ | |
4793 | do { | |
4794 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { | |
4795 | scmd->result = SAM_STAT_BUSY; | |
4796 | scmd->scsi_done(scmd); | |
4797 | return 0; | |
4798 | } | |
4799 | } while (_scsih_set_satl_pending(scmd, true)); | |
4800 | ||
f92363d1 SR |
4801 | sas_target_priv_data = sas_device_priv_data->sas_target; |
4802 | ||
4803 | /* invalid device handle */ | |
4804 | handle = sas_target_priv_data->handle; | |
4805 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4806 | scmd->result = DID_NO_CONNECT << 16; | |
4807 | scmd->scsi_done(scmd); | |
4808 | return 0; | |
4809 | } | |
4810 | ||
4811 | ||
4812 | /* host recovery or link resets sent via IOCTLs */ | |
4813 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | |
4814 | return SCSI_MLQUEUE_HOST_BUSY; | |
4815 | ||
4816 | /* device has been deleted */ | |
4817 | else if (sas_target_priv_data->deleted) { | |
4818 | scmd->result = DID_NO_CONNECT << 16; | |
4819 | scmd->scsi_done(scmd); | |
4820 | return 0; | |
6c7abffc | 4821 | /* device busy with task management */ |
f92363d1 SR |
4822 | } else if (sas_target_priv_data->tm_busy || |
4823 | sas_device_priv_data->block) | |
4824 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
4825 | ||
4826 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) | |
4827 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4828 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4829 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4830 | else | |
4831 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4832 | ||
4833 | /* set tags */ | |
609aa22f | 4834 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4835 | /* NCQ Prio supported, make sure control indicated high priority */ |
4836 | if (sas_device_priv_data->ncq_prio_enable) { | |
4837 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4838 | if (class == IOPRIO_CLASS_RT) | |
4839 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4840 | } | |
7786ab6a SR |
4841 | /* Make sure Device is not raid volume. |
4842 | * We do not expose raid functionality to upper layer for warpdrive. | |
4843 | */ | |
cd5897ed SPS |
4844 | if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)) |
4845 | && !scsih_is_nvme(&scmd->device->sdev_gendev)) | |
4846 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) | |
f92363d1 SR |
4847 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4848 | ||
4849 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4850 | if (!smid) { | |
4851 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
4852 | ioc->name, __func__); | |
4853 | goto out; | |
4854 | } | |
4855 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4856 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4857 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4858 | ||
4859 | if (scmd->cmd_len == 32) | |
4860 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4861 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4862 | if (sas_device_priv_data->sas_target->flags & | |
4863 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4864 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4865 | else | |
4866 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4867 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4868 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4869 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4870 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4871 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4872 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4873 | mpi_request->SenseBufferLowAddress = | |
4874 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4875 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4876 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4877 | mpi_request->LUN); | |
4878 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4879 | ||
4880 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4881 | pcie_device = sas_target_priv_data->pcie_dev; |
4882 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 SR |
4883 | mpt3sas_base_free_smid(ioc, smid); |
4884 | goto out; | |
4885 | } | |
4886 | } else | |
4887 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4888 | ||
7786ab6a SR |
4889 | raid_device = sas_target_priv_data->raid_device; |
4890 | if (raid_device && raid_device->direct_io_enabled) | |
cd5897ed SPS |
4891 | mpt3sas_setup_direct_io(ioc, scmd, |
4892 | raid_device, mpi_request, smid); | |
7786ab6a | 4893 | |
f92363d1 SR |
4894 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4895 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4896 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4897 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
81c16f83 | 4898 | ioc->put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4899 | } else |
81c16f83 | 4900 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4901 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4902 | } else |
81c16f83 | 4903 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
4904 | return 0; |
4905 | ||
4906 | out: | |
4907 | return SCSI_MLQUEUE_HOST_BUSY; | |
4908 | } | |
f92363d1 SR |
4909 | |
4910 | /** | |
4911 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4912 | * @sense_buffer: sense data returned by target | |
4913 | * @data: normalized skey/asc/ascq | |
4914 | * | |
4915 | * Return nothing. | |
4916 | */ | |
4917 | static void | |
4918 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4919 | { | |
4920 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4921 | /* descriptor format */ | |
4922 | data->skey = sense_buffer[1] & 0x0F; | |
4923 | data->asc = sense_buffer[2]; | |
4924 | data->ascq = sense_buffer[3]; | |
4925 | } else { | |
4926 | /* fixed format */ | |
4927 | data->skey = sense_buffer[2] & 0x0F; | |
4928 | data->asc = sense_buffer[12]; | |
4929 | data->ascq = sense_buffer[13]; | |
4930 | } | |
4931 | } | |
4932 | ||
f92363d1 SR |
4933 | /** |
4934 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4935 | * @ioc: per adapter object | |
4936 | * @scmd: pointer to scsi command object | |
4937 | * @mpi_reply: reply mf payload returned from firmware | |
4938 | * | |
4939 | * scsi_status - SCSI Status code returned from target device | |
4940 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4941 | * ioc_status - ioc supplied status info | |
4942 | * | |
4943 | * Return nothing. | |
4944 | */ | |
4945 | static void | |
4946 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4947 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4948 | { | |
4949 | u32 response_info; | |
4950 | u8 *response_bytes; | |
4951 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4952 | MPI2_IOCSTATUS_MASK; | |
4953 | u8 scsi_state = mpi_reply->SCSIState; | |
4954 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4955 | char *desc_ioc_state = NULL; | |
4956 | char *desc_scsi_status = NULL; | |
4957 | char *desc_scsi_state = ioc->tmp_string; | |
4958 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4959 | struct _sas_device *sas_device = NULL; | |
ec051e5a | 4960 | struct _pcie_device *pcie_device = NULL; |
f92363d1 SR |
4961 | struct scsi_target *starget = scmd->device->sdev_target; |
4962 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4963 | char *device_str = NULL; | |
4964 | ||
4965 | if (!priv_target) | |
4966 | return; | |
7786ab6a SR |
4967 | if (ioc->hide_ir_msg) |
4968 | device_str = "WarpDrive"; | |
4969 | else | |
4970 | device_str = "volume"; | |
f92363d1 SR |
4971 | |
4972 | if (log_info == 0x31170000) | |
4973 | return; | |
4974 | ||
4975 | switch (ioc_status) { | |
4976 | case MPI2_IOCSTATUS_SUCCESS: | |
4977 | desc_ioc_state = "success"; | |
4978 | break; | |
4979 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4980 | desc_ioc_state = "invalid function"; | |
4981 | break; | |
4982 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4983 | desc_ioc_state = "scsi recovered error"; | |
4984 | break; | |
4985 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4986 | desc_ioc_state = "scsi invalid dev handle"; | |
4987 | break; | |
4988 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4989 | desc_ioc_state = "scsi device not there"; | |
4990 | break; | |
4991 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4992 | desc_ioc_state = "scsi data overrun"; | |
4993 | break; | |
4994 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4995 | desc_ioc_state = "scsi data underrun"; | |
4996 | break; | |
4997 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4998 | desc_ioc_state = "scsi io data error"; | |
4999 | break; | |
5000 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5001 | desc_ioc_state = "scsi protocol error"; | |
5002 | break; | |
5003 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5004 | desc_ioc_state = "scsi task terminated"; | |
5005 | break; | |
5006 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5007 | desc_ioc_state = "scsi residual mismatch"; | |
5008 | break; | |
5009 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
5010 | desc_ioc_state = "scsi task mgmt failed"; | |
5011 | break; | |
5012 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5013 | desc_ioc_state = "scsi ioc terminated"; | |
5014 | break; | |
5015 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5016 | desc_ioc_state = "scsi ext terminated"; | |
5017 | break; | |
5018 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5019 | desc_ioc_state = "eedp guard error"; | |
5020 | break; | |
5021 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5022 | desc_ioc_state = "eedp ref tag error"; | |
5023 | break; | |
5024 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5025 | desc_ioc_state = "eedp app tag error"; | |
5026 | break; | |
b130b0d5 SS |
5027 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
5028 | desc_ioc_state = "insufficient power"; | |
5029 | break; | |
f92363d1 SR |
5030 | default: |
5031 | desc_ioc_state = "unknown"; | |
5032 | break; | |
5033 | } | |
5034 | ||
5035 | switch (scsi_status) { | |
5036 | case MPI2_SCSI_STATUS_GOOD: | |
5037 | desc_scsi_status = "good"; | |
5038 | break; | |
5039 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
5040 | desc_scsi_status = "check condition"; | |
5041 | break; | |
5042 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
5043 | desc_scsi_status = "condition met"; | |
5044 | break; | |
5045 | case MPI2_SCSI_STATUS_BUSY: | |
5046 | desc_scsi_status = "busy"; | |
5047 | break; | |
5048 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
5049 | desc_scsi_status = "intermediate"; | |
5050 | break; | |
5051 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
5052 | desc_scsi_status = "intermediate condmet"; | |
5053 | break; | |
5054 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
5055 | desc_scsi_status = "reservation conflict"; | |
5056 | break; | |
5057 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
5058 | desc_scsi_status = "command terminated"; | |
5059 | break; | |
5060 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
5061 | desc_scsi_status = "task set full"; | |
5062 | break; | |
5063 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
5064 | desc_scsi_status = "aca active"; | |
5065 | break; | |
5066 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
5067 | desc_scsi_status = "task aborted"; | |
5068 | break; | |
5069 | default: | |
5070 | desc_scsi_status = "unknown"; | |
5071 | break; | |
5072 | } | |
5073 | ||
5074 | desc_scsi_state[0] = '\0'; | |
5075 | if (!scsi_state) | |
5076 | desc_scsi_state = " "; | |
5077 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5078 | strcat(desc_scsi_state, "response info "); | |
5079 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5080 | strcat(desc_scsi_state, "state terminated "); | |
5081 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
5082 | strcat(desc_scsi_state, "no status "); | |
5083 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
5084 | strcat(desc_scsi_state, "autosense failed "); | |
5085 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
5086 | strcat(desc_scsi_state, "autosense valid "); | |
5087 | ||
5088 | scsi_print_command(scmd); | |
5089 | ||
5090 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
5091 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
5092 | device_str, (unsigned long long)priv_target->sas_address); | |
ec051e5a SPS |
5093 | } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
5094 | pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target); | |
5095 | if (pcie_device) { | |
5096 | pr_info(MPT3SAS_FMT "\twwid(0x%016llx), port(%d)\n", | |
5097 | ioc->name, | |
5098 | (unsigned long long)pcie_device->wwid, | |
5099 | pcie_device->port_num); | |
5100 | if (pcie_device->enclosure_handle != 0) | |
5101 | pr_info(MPT3SAS_FMT | |
5102 | "\tenclosure logical id(0x%016llx), " | |
5103 | "slot(%d)\n", ioc->name, | |
5104 | (unsigned long long) | |
5105 | pcie_device->enclosure_logical_id, | |
5106 | pcie_device->slot); | |
5107 | if (pcie_device->connector_name[0]) | |
5108 | pr_info(MPT3SAS_FMT | |
5109 | "\tenclosure level(0x%04x)," | |
5110 | "connector name( %s)\n", | |
5111 | ioc->name, pcie_device->enclosure_level, | |
5112 | pcie_device->connector_name); | |
5113 | pcie_device_put(pcie_device); | |
5114 | } | |
f92363d1 | 5115 | } else { |
d1cb5e49 | 5116 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
5117 | if (sas_device) { |
5118 | pr_warn(MPT3SAS_FMT | |
5119 | "\tsas_address(0x%016llx), phy(%d)\n", | |
5120 | ioc->name, (unsigned long long) | |
5121 | sas_device->sas_address, sas_device->phy); | |
75888956 SR |
5122 | |
5123 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
5124 | NULL, NULL); | |
d1cb5e49 SR |
5125 | |
5126 | sas_device_put(sas_device); | |
f92363d1 | 5127 | } |
f92363d1 SR |
5128 | } |
5129 | ||
5130 | pr_warn(MPT3SAS_FMT | |
5131 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
5132 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
5133 | desc_ioc_state, ioc_status, smid); | |
5134 | pr_warn(MPT3SAS_FMT | |
5135 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
5136 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
5137 | scsi_get_resid(scmd)); | |
5138 | pr_warn(MPT3SAS_FMT | |
5139 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
5140 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
5141 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
5142 | pr_warn(MPT3SAS_FMT | |
5143 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
5144 | ioc->name, desc_scsi_status, | |
5145 | scsi_status, desc_scsi_state, scsi_state); | |
5146 | ||
5147 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5148 | struct sense_info data; | |
5149 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5150 | pr_warn(MPT3SAS_FMT | |
ec051e5a SPS |
5151 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", |
5152 | ioc->name, data.skey, | |
5153 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
f92363d1 | 5154 | } |
f92363d1 SR |
5155 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
5156 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
5157 | response_bytes = (u8 *)&response_info; | |
5158 | _scsih_response_code(ioc, response_bytes[0]); | |
5159 | } | |
5160 | } | |
f92363d1 SR |
5161 | |
5162 | /** | |
0f624c39 | 5163 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
5164 | * @ioc: per adapter object |
5165 | * @handle: device handle | |
5166 | * Context: process | |
5167 | * | |
5168 | * Return nothing. | |
5169 | */ | |
5170 | static void | |
0f624c39 | 5171 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5172 | { |
5173 | Mpi2SepReply_t mpi_reply; | |
5174 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
5175 | struct _sas_device *sas_device; |
5176 | ||
d1cb5e49 | 5177 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
5178 | if (!sas_device) |
5179 | return; | |
f92363d1 SR |
5180 | |
5181 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
5182 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5183 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5184 | mpi_request.SlotStatus = | |
5185 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
5186 | mpi_request.DevHandle = cpu_to_le16(handle); | |
5187 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
5188 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5189 | &mpi_request)) != 0) { | |
5190 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5191 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5192 | goto out; |
f92363d1 | 5193 | } |
0f624c39 | 5194 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
5195 | |
5196 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5197 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5198 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5199 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5200 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 5201 | goto out; |
f92363d1 | 5202 | } |
d1cb5e49 SR |
5203 | out: |
5204 | sas_device_put(sas_device); | |
f92363d1 | 5205 | } |
d1cb5e49 | 5206 | |
0f624c39 SR |
5207 | /** |
5208 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
5209 | * @ioc: per adapter object | |
5210 | * @sas_device: sas device whose PFA LED has to turned off | |
5211 | * Context: process | |
5212 | * | |
5213 | * Return nothing. | |
5214 | */ | |
5215 | static void | |
5216 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
5217 | struct _sas_device *sas_device) | |
5218 | { | |
5219 | Mpi2SepReply_t mpi_reply; | |
5220 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 5221 | |
0f624c39 SR |
5222 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
5223 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
5224 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
5225 | mpi_request.SlotStatus = 0; | |
5226 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
5227 | mpi_request.DevHandle = 0; | |
5228 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
5229 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
5230 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
5231 | &mpi_request)) != 0) { | |
5232 | printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
5233 | __FILE__, __LINE__, __func__); | |
5234 | return; | |
5235 | } | |
5236 | ||
5237 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
5238 | dewtprintk(ioc, printk(MPT3SAS_FMT | |
5239 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
5240 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
5241 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
5242 | return; | |
5243 | } | |
5244 | } | |
d1cb5e49 | 5245 | |
f92363d1 | 5246 | /** |
0f624c39 | 5247 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
5248 | * @ioc: per adapter object |
5249 | * @handle: device handle | |
5250 | * Context: interrupt. | |
5251 | * | |
5252 | * Return nothing. | |
5253 | */ | |
5254 | static void | |
0f624c39 | 5255 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
5256 | { |
5257 | struct fw_event_work *fw_event; | |
5258 | ||
146b16c8 | 5259 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
5260 | if (!fw_event) |
5261 | return; | |
0f624c39 | 5262 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
5263 | fw_event->device_handle = handle; |
5264 | fw_event->ioc = ioc; | |
5265 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 5266 | fw_event_work_put(fw_event); |
f92363d1 SR |
5267 | } |
5268 | ||
5269 | /** | |
5270 | * _scsih_smart_predicted_fault - process smart errors | |
5271 | * @ioc: per adapter object | |
5272 | * @handle: device handle | |
5273 | * Context: interrupt. | |
5274 | * | |
5275 | * Return nothing. | |
5276 | */ | |
5277 | static void | |
5278 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5279 | { | |
5280 | struct scsi_target *starget; | |
5281 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5282 | Mpi2EventNotificationReply_t *event_reply; | |
5283 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
5284 | struct _sas_device *sas_device; | |
5285 | ssize_t sz; | |
5286 | unsigned long flags; | |
5287 | ||
5288 | /* only handle non-raid devices */ | |
5289 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
5290 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
5291 | if (!sas_device) | |
5292 | goto out_unlock; | |
5293 | ||
f92363d1 SR |
5294 | starget = sas_device->starget; |
5295 | sas_target_priv_data = starget->hostdata; | |
5296 | ||
5297 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
5298 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
5299 | goto out_unlock; | |
5300 | ||
75888956 SR |
5301 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
5302 | ||
f92363d1 SR |
5303 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
5304 | ||
5305 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 5306 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
5307 | |
5308 | /* insert into event log */ | |
5309 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
5310 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
5311 | event_reply = kzalloc(sz, GFP_KERNEL); | |
5312 | if (!event_reply) { | |
5313 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5314 | ioc->name, __FILE__, __LINE__, __func__); | |
d1cb5e49 | 5315 | goto out; |
f92363d1 SR |
5316 | } |
5317 | ||
5318 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
5319 | event_reply->Event = | |
5320 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
5321 | event_reply->MsgLength = sz/4; | |
5322 | event_reply->EventDataLength = | |
5323 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
5324 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
5325 | event_reply->EventData; | |
5326 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
5327 | event_data->ASC = 0x5D; | |
5328 | event_data->DevHandle = cpu_to_le16(handle); | |
5329 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
5330 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
5331 | kfree(event_reply); | |
d1cb5e49 SR |
5332 | out: |
5333 | if (sas_device) | |
5334 | sas_device_put(sas_device); | |
5335 | return; | |
5336 | ||
5337 | out_unlock: | |
5338 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5339 | goto out; | |
f92363d1 SR |
5340 | } |
5341 | ||
5342 | /** | |
5343 | * _scsih_io_done - scsi request callback | |
5344 | * @ioc: per adapter object | |
5345 | * @smid: system request message index | |
5346 | * @msix_index: MSIX table index supplied by the OS | |
5347 | * @reply: reply message frame(lower 32bit addr) | |
5348 | * | |
5349 | * Callback handler when using _scsih_qcmd. | |
5350 | * | |
5351 | * Return 1 meaning mf should be freed from _base_interrupt | |
5352 | * 0 means the mf is freed from this function. | |
5353 | */ | |
5354 | static u8 | |
5355 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5356 | { | |
016d5c35 | 5357 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
5358 | Mpi2SCSIIOReply_t *mpi_reply; |
5359 | struct scsi_cmnd *scmd; | |
5360 | u16 ioc_status; | |
5361 | u32 xfer_cnt; | |
5362 | u8 scsi_state; | |
5363 | u8 scsi_status; | |
5364 | u32 log_info; | |
5365 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5366 | u32 response_code = 0; | |
7786ab6a | 5367 | unsigned long flags; |
f92363d1 SR |
5368 | |
5369 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 C |
5370 | |
5371 | if (ioc->broadcast_aen_busy || ioc->pci_error_recovery || | |
5372 | ioc->got_task_abort_from_ioctl) | |
5373 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
5374 | else | |
5375 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); | |
5376 | ||
f92363d1 SR |
5377 | if (scmd == NULL) |
5378 | return 1; | |
5379 | ||
ffb58456 | 5380 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 5381 | |
f92363d1 SR |
5382 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
5383 | ||
5384 | if (mpi_reply == NULL) { | |
5385 | scmd->result = DID_OK << 16; | |
5386 | goto out; | |
5387 | } | |
5388 | ||
5389 | sas_device_priv_data = scmd->device->hostdata; | |
5390 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
5391 | sas_device_priv_data->sas_target->deleted) { | |
5392 | scmd->result = DID_NO_CONNECT << 16; | |
5393 | goto out; | |
5394 | } | |
5395 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5396 | ||
7786ab6a SR |
5397 | /* |
5398 | * WARPDRIVE: If direct_io is set then it is directIO, | |
5399 | * the failed direct I/O should be redirected to volume | |
5400 | */ | |
c84b06a4 | 5401 | if (mpt3sas_scsi_direct_io_get(ioc, smid) && |
7786ab6a SR |
5402 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
5403 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
5404 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5405 | ioc->scsi_lookup[smid - 1].scmd = scmd; | |
5406 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
c84b06a4 | 5407 | mpt3sas_scsi_direct_io_set(ioc, smid, 0); |
7786ab6a SR |
5408 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
5409 | mpi_request->DevHandle = | |
5410 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 5411 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
5412 | sas_device_priv_data->sas_target->handle); |
5413 | return 0; | |
5414 | } | |
f92363d1 SR |
5415 | /* turning off TLR */ |
5416 | scsi_state = mpi_reply->SCSIState; | |
5417 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
5418 | response_code = | |
5419 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
5420 | if (!sas_device_priv_data->tlr_snoop_check) { | |
5421 | sas_device_priv_data->tlr_snoop_check++; | |
cd5897ed | 5422 | if ((!ioc->is_warpdrive && |
7786ab6a | 5423 | !scsih_is_raid(&scmd->device->sdev_gendev) && |
cd5897ed SPS |
5424 | !scsih_is_nvme(&scmd->device->sdev_gendev)) |
5425 | && sas_is_tlr_enabled(scmd->device) && | |
c84b06a4 SR |
5426 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
5427 | sas_disable_tlr(scmd->device); | |
5428 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5429 | } | |
f92363d1 SR |
5430 | } |
5431 | ||
5432 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5433 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5434 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5435 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5436 | else | |
5437 | log_info = 0; | |
5438 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5439 | scsi_status = mpi_reply->SCSIStatus; | |
5440 | ||
5441 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5442 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5443 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5444 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5445 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5446 | } | |
5447 | ||
5448 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5449 | struct sense_info data; | |
5450 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5451 | smid); | |
5452 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5453 | le32_to_cpu(mpi_reply->SenseCount)); | |
5454 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5455 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5456 | /* failure prediction threshold exceeded */ | |
5457 | if (data.asc == 0x5D) | |
5458 | _scsih_smart_predicted_fault(ioc, | |
5459 | le16_to_cpu(mpi_reply->DevHandle)); | |
5460 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5461 | |
0d667f72 | 5462 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5463 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5464 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5465 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5466 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5467 | } |
f92363d1 SR |
5468 | switch (ioc_status) { |
5469 | case MPI2_IOCSTATUS_BUSY: | |
5470 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5471 | scmd->result = SAM_STAT_BUSY; | |
5472 | break; | |
5473 | ||
5474 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5475 | scmd->result = DID_NO_CONNECT << 16; | |
5476 | break; | |
5477 | ||
5478 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5479 | if (sas_device_priv_data->block) { | |
5480 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5481 | goto out; | |
5482 | } | |
5483 | if (log_info == 0x31110630) { | |
5484 | if (scmd->retries > 2) { | |
5485 | scmd->result = DID_NO_CONNECT << 16; | |
5486 | scsi_device_set_state(scmd->device, | |
5487 | SDEV_OFFLINE); | |
5488 | } else { | |
5489 | scmd->result = DID_SOFT_ERROR << 16; | |
5490 | scmd->device->expecting_cc_ua = 1; | |
5491 | } | |
5492 | break; | |
3898f08e SR |
5493 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5494 | scmd->result = DID_RESET << 16; | |
5495 | break; | |
2ce9a364 SR |
5496 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5497 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5498 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5499 | scmd->result = DID_RESET << 16; | |
5500 | break; | |
f92363d1 SR |
5501 | } |
5502 | scmd->result = DID_SOFT_ERROR << 16; | |
5503 | break; | |
5504 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5505 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5506 | scmd->result = DID_RESET << 16; | |
5507 | break; | |
5508 | ||
5509 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5510 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5511 | scmd->result = DID_SOFT_ERROR << 16; | |
5512 | else | |
5513 | scmd->result = (DID_OK << 16) | scsi_status; | |
5514 | break; | |
5515 | ||
5516 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5517 | scmd->result = (DID_OK << 16) | scsi_status; | |
5518 | ||
5519 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5520 | break; | |
5521 | ||
5522 | if (xfer_cnt < scmd->underflow) { | |
5523 | if (scsi_status == SAM_STAT_BUSY) | |
5524 | scmd->result = SAM_STAT_BUSY; | |
5525 | else | |
5526 | scmd->result = DID_SOFT_ERROR << 16; | |
5527 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5528 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5529 | scmd->result = DID_SOFT_ERROR << 16; | |
5530 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5531 | scmd->result = DID_RESET << 16; | |
5532 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5533 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5534 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5535 | scmd->result = (DRIVER_SENSE << 24) | | |
5536 | SAM_STAT_CHECK_CONDITION; | |
5537 | scmd->sense_buffer[0] = 0x70; | |
5538 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5539 | scmd->sense_buffer[12] = 0x20; | |
5540 | scmd->sense_buffer[13] = 0; | |
5541 | } | |
5542 | break; | |
5543 | ||
5544 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5545 | scsi_set_resid(scmd, 0); | |
5546 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
5547 | case MPI2_IOCSTATUS_SUCCESS: | |
5548 | scmd->result = (DID_OK << 16) | scsi_status; | |
5549 | if (response_code == | |
5550 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5551 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5552 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5553 | scmd->result = DID_SOFT_ERROR << 16; | |
5554 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5555 | scmd->result = DID_RESET << 16; | |
5556 | break; | |
5557 | ||
5558 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5559 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5560 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5561 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5562 | break; | |
5563 | ||
5564 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5565 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5566 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5567 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5568 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5569 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5570 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5571 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5572 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5573 | default: |
5574 | scmd->result = DID_SOFT_ERROR << 16; | |
5575 | break; | |
5576 | ||
5577 | } | |
5578 | ||
f92363d1 SR |
5579 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5580 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5581 | |
5582 | out: | |
5583 | ||
5584 | scsi_dma_unmap(scmd); | |
5585 | ||
5586 | scmd->scsi_done(scmd); | |
5587 | return 1; | |
5588 | } | |
5589 | ||
5590 | /** | |
5591 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5592 | * @ioc: per adapter object | |
5593 | * Context: user | |
5594 | * | |
5595 | * During port enable, fw will send topology events for every device. Its | |
5596 | * possible that the handles may change from the previous setting, so this | |
5597 | * code keeping handles updating if changed. | |
5598 | * | |
5599 | * Return nothing. | |
5600 | */ | |
5601 | static void | |
5602 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5603 | { | |
5604 | u16 sz; | |
5605 | u16 ioc_status; | |
5606 | int i; | |
5607 | Mpi2ConfigReply_t mpi_reply; | |
5608 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5609 | u16 attached_handle; | |
5610 | u8 link_rate; | |
5611 | ||
5612 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
5613 | "updating handles for sas_host(0x%016llx)\n", | |
5614 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
5615 | ||
5616 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5617 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5618 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5619 | if (!sas_iounit_pg0) { | |
5620 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5621 | ioc->name, __FILE__, __LINE__, __func__); | |
5622 | return; | |
5623 | } | |
5624 | ||
5625 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5626 | sas_iounit_pg0, sz)) != 0) | |
5627 | goto out; | |
5628 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5629 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5630 | goto out; | |
5631 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5632 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5633 | if (i == 0) | |
5634 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5635 | PhyData[0].ControllerDevHandle); | |
5636 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5637 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5638 | AttachedDevHandle); | |
5639 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5640 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
5641 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
5642 | attached_handle, i, link_rate); | |
5643 | } | |
5644 | out: | |
5645 | kfree(sas_iounit_pg0); | |
5646 | } | |
5647 | ||
5648 | /** | |
5649 | * _scsih_sas_host_add - create sas host object | |
5650 | * @ioc: per adapter object | |
5651 | * | |
5652 | * Creating host side data object, stored in ioc->sas_hba | |
5653 | * | |
5654 | * Return nothing. | |
5655 | */ | |
5656 | static void | |
5657 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5658 | { | |
5659 | int i; | |
5660 | Mpi2ConfigReply_t mpi_reply; | |
5661 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5662 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5663 | Mpi2SasPhyPage0_t phy_pg0; | |
5664 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5665 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5666 | u16 ioc_status; | |
5667 | u16 sz; | |
5668 | u8 device_missing_delay; | |
87aa95d4 | 5669 | u8 num_phys; |
f92363d1 | 5670 | |
87aa95d4 JL |
5671 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5672 | if (!num_phys) { | |
f92363d1 SR |
5673 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
5674 | ioc->name, __FILE__, __LINE__, __func__); | |
5675 | return; | |
5676 | } | |
87aa95d4 JL |
5677 | ioc->sas_hba.phy = kcalloc(num_phys, |
5678 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5679 | if (!ioc->sas_hba.phy) { | |
5680 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5681 | ioc->name, __FILE__, __LINE__, __func__); | |
5682 | goto out; | |
5683 | } | |
5684 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5685 | |
5686 | /* sas_iounit page 0 */ | |
5687 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5688 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5689 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5690 | if (!sas_iounit_pg0) { | |
5691 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5692 | ioc->name, __FILE__, __LINE__, __func__); | |
5693 | return; | |
5694 | } | |
5695 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5696 | sas_iounit_pg0, sz))) { | |
5697 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5698 | ioc->name, __FILE__, __LINE__, __func__); | |
5699 | goto out; | |
5700 | } | |
5701 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5702 | MPI2_IOCSTATUS_MASK; | |
5703 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5704 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5705 | ioc->name, __FILE__, __LINE__, __func__); | |
5706 | goto out; | |
5707 | } | |
5708 | ||
5709 | /* sas_iounit page 1 */ | |
5710 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5711 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5712 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5713 | if (!sas_iounit_pg1) { | |
5714 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5715 | ioc->name, __FILE__, __LINE__, __func__); | |
5716 | goto out; | |
5717 | } | |
5718 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5719 | sas_iounit_pg1, sz))) { | |
5720 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5721 | ioc->name, __FILE__, __LINE__, __func__); | |
5722 | goto out; | |
5723 | } | |
5724 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5725 | MPI2_IOCSTATUS_MASK; | |
5726 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5727 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5728 | ioc->name, __FILE__, __LINE__, __func__); | |
5729 | goto out; | |
5730 | } | |
5731 | ||
5732 | ioc->io_missing_delay = | |
5733 | sas_iounit_pg1->IODeviceMissingDelay; | |
5734 | device_missing_delay = | |
5735 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5736 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5737 | ioc->device_missing_delay = (device_missing_delay & | |
5738 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5739 | else | |
5740 | ioc->device_missing_delay = device_missing_delay & | |
5741 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5742 | ||
5743 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5744 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5745 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5746 | i))) { | |
5747 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5748 | ioc->name, __FILE__, __LINE__, __func__); | |
5749 | goto out; | |
5750 | } | |
5751 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5752 | MPI2_IOCSTATUS_MASK; | |
5753 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5754 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5755 | ioc->name, __FILE__, __LINE__, __func__); | |
5756 | goto out; | |
5757 | } | |
5758 | ||
5759 | if (i == 0) | |
5760 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5761 | PhyData[0].ControllerDevHandle); | |
5762 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5763 | ioc->sas_hba.phy[i].phy_id = i; | |
5764 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
5765 | phy_pg0, ioc->sas_hba.parent_dev); | |
5766 | } | |
5767 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5768 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
5769 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5770 | ioc->name, __FILE__, __LINE__, __func__); | |
5771 | goto out; | |
5772 | } | |
5773 | ioc->sas_hba.enclosure_handle = | |
5774 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5775 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
5776 | pr_info(MPT3SAS_FMT | |
5777 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
5778 | ioc->name, ioc->sas_hba.handle, | |
5779 | (unsigned long long) ioc->sas_hba.sas_address, | |
5780 | ioc->sas_hba.num_phys) ; | |
5781 | ||
5782 | if (ioc->sas_hba.enclosure_handle) { | |
5783 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5784 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5785 | ioc->sas_hba.enclosure_handle))) | |
5786 | ioc->sas_hba.enclosure_logical_id = | |
5787 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5788 | } | |
5789 | ||
5790 | out: | |
5791 | kfree(sas_iounit_pg1); | |
5792 | kfree(sas_iounit_pg0); | |
5793 | } | |
5794 | ||
5795 | /** | |
5796 | * _scsih_expander_add - creating expander object | |
5797 | * @ioc: per adapter object | |
5798 | * @handle: expander handle | |
5799 | * | |
5800 | * Creating expander object, stored in ioc->sas_expander_list. | |
5801 | * | |
5802 | * Return 0 for success, else error. | |
5803 | */ | |
5804 | static int | |
5805 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5806 | { | |
5807 | struct _sas_node *sas_expander; | |
5808 | Mpi2ConfigReply_t mpi_reply; | |
5809 | Mpi2ExpanderPage0_t expander_pg0; | |
5810 | Mpi2ExpanderPage1_t expander_pg1; | |
5811 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5812 | u32 ioc_status; | |
5813 | u16 parent_handle; | |
5814 | u64 sas_address, sas_address_parent = 0; | |
5815 | int i; | |
5816 | unsigned long flags; | |
5817 | struct _sas_port *mpt3sas_port = NULL; | |
5818 | ||
5819 | int rc = 0; | |
5820 | ||
5821 | if (!handle) | |
5822 | return -1; | |
5823 | ||
5824 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5825 | return -1; | |
5826 | ||
5827 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5828 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
5829 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5830 | ioc->name, __FILE__, __LINE__, __func__); | |
5831 | return -1; | |
5832 | } | |
5833 | ||
5834 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5835 | MPI2_IOCSTATUS_MASK; | |
5836 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5837 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5838 | ioc->name, __FILE__, __LINE__, __func__); | |
5839 | return -1; | |
5840 | } | |
5841 | ||
5842 | /* handle out of order topology events */ | |
5843 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5844 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5845 | != 0) { | |
5846 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5847 | ioc->name, __FILE__, __LINE__, __func__); | |
5848 | return -1; | |
5849 | } | |
5850 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5851 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5852 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5853 | sas_address_parent); | |
5854 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5855 | if (!sas_expander) { | |
5856 | rc = _scsih_expander_add(ioc, parent_handle); | |
5857 | if (rc != 0) | |
5858 | return rc; | |
5859 | } | |
5860 | } | |
5861 | ||
5862 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5863 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5864 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5865 | sas_address); | |
5866 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5867 | ||
5868 | if (sas_expander) | |
5869 | return 0; | |
5870 | ||
5871 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5872 | GFP_KERNEL); | |
5873 | if (!sas_expander) { | |
5874 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5875 | ioc->name, __FILE__, __LINE__, __func__); | |
5876 | return -1; | |
5877 | } | |
5878 | ||
5879 | sas_expander->handle = handle; | |
5880 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5881 | sas_expander->sas_address_parent = sas_address_parent; | |
5882 | sas_expander->sas_address = sas_address; | |
5883 | ||
5884 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
5885 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
5886 | handle, parent_handle, (unsigned long long) | |
5887 | sas_expander->sas_address, sas_expander->num_phys); | |
5888 | ||
5889 | if (!sas_expander->num_phys) | |
5890 | goto out_fail; | |
5891 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5892 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5893 | if (!sas_expander->phy) { | |
5894 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5895 | ioc->name, __FILE__, __LINE__, __func__); | |
5896 | rc = -1; | |
5897 | goto out_fail; | |
5898 | } | |
5899 | ||
5900 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5901 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5902 | sas_address_parent); | |
5903 | if (!mpt3sas_port) { | |
5904 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5905 | ioc->name, __FILE__, __LINE__, __func__); | |
5906 | rc = -1; | |
5907 | goto out_fail; | |
5908 | } | |
5909 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5910 | ||
5911 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5912 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5913 | &expander_pg1, i, handle))) { | |
5914 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5915 | ioc->name, __FILE__, __LINE__, __func__); | |
5916 | rc = -1; | |
5917 | goto out_fail; | |
5918 | } | |
5919 | sas_expander->phy[i].handle = handle; | |
5920 | sas_expander->phy[i].phy_id = i; | |
5921 | ||
5922 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5923 | &sas_expander->phy[i], expander_pg1, | |
5924 | sas_expander->parent_dev))) { | |
5925 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5926 | ioc->name, __FILE__, __LINE__, __func__); | |
5927 | rc = -1; | |
5928 | goto out_fail; | |
5929 | } | |
5930 | } | |
5931 | ||
5932 | if (sas_expander->enclosure_handle) { | |
5933 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5934 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5935 | sas_expander->enclosure_handle))) | |
5936 | sas_expander->enclosure_logical_id = | |
5937 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5938 | } | |
5939 | ||
5940 | _scsih_expander_node_add(ioc, sas_expander); | |
5941 | return 0; | |
5942 | ||
5943 | out_fail: | |
5944 | ||
5945 | if (mpt3sas_port) | |
5946 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5947 | sas_address_parent); | |
5948 | kfree(sas_expander); | |
5949 | return rc; | |
5950 | } | |
5951 | ||
5952 | /** | |
5953 | * mpt3sas_expander_remove - removing expander object | |
5954 | * @ioc: per adapter object | |
5955 | * @sas_address: expander sas_address | |
5956 | * | |
5957 | * Return nothing. | |
5958 | */ | |
5959 | void | |
5960 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5961 | { | |
5962 | struct _sas_node *sas_expander; | |
5963 | unsigned long flags; | |
5964 | ||
5965 | if (ioc->shost_recovery) | |
5966 | return; | |
5967 | ||
5968 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5969 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5970 | sas_address); | |
f92363d1 SR |
5971 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5972 | if (sas_expander) | |
5973 | _scsih_expander_node_remove(ioc, sas_expander); | |
5974 | } | |
5975 | ||
5976 | /** | |
5977 | * _scsih_done - internal SCSI_IO callback handler. | |
5978 | * @ioc: per adapter object | |
5979 | * @smid: system request message index | |
5980 | * @msix_index: MSIX table index supplied by the OS | |
5981 | * @reply: reply message frame(lower 32bit addr) | |
5982 | * | |
5983 | * Callback handler when sending internal generated SCSI_IO. | |
5984 | * The callback index passed is `ioc->scsih_cb_idx` | |
5985 | * | |
5986 | * Return 1 meaning mf should be freed from _base_interrupt | |
5987 | * 0 means the mf is freed from this function. | |
5988 | */ | |
5989 | static u8 | |
5990 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5991 | { | |
5992 | MPI2DefaultReply_t *mpi_reply; | |
5993 | ||
5994 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5995 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5996 | return 1; | |
5997 | if (ioc->scsih_cmds.smid != smid) | |
5998 | return 1; | |
5999 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
6000 | if (mpi_reply) { | |
6001 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
6002 | mpi_reply->MsgLength*4); | |
6003 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
6004 | } | |
6005 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
6006 | complete(&ioc->scsih_cmds.done); | |
6007 | return 1; | |
6008 | } | |
6009 | ||
6010 | ||
6011 | ||
6012 | ||
6013 | #define MPT3_MAX_LUNS (255) | |
6014 | ||
6015 | ||
6016 | /** | |
6017 | * _scsih_check_access_status - check access flags | |
6018 | * @ioc: per adapter object | |
6019 | * @sas_address: sas address | |
6020 | * @handle: sas device handle | |
6021 | * @access_flags: errors returned during discovery of the device | |
6022 | * | |
6023 | * Return 0 for success, else failure | |
6024 | */ | |
6025 | static u8 | |
6026 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
6027 | u16 handle, u8 access_status) | |
6028 | { | |
6029 | u8 rc = 1; | |
6030 | char *desc = NULL; | |
6031 | ||
6032 | switch (access_status) { | |
6033 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
6034 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
6035 | rc = 0; | |
6036 | break; | |
6037 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
6038 | desc = "sata capability failed"; | |
6039 | break; | |
6040 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
6041 | desc = "sata affiliation conflict"; | |
6042 | break; | |
6043 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
6044 | desc = "route not addressable"; | |
6045 | break; | |
6046 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
6047 | desc = "smp error not addressable"; | |
6048 | break; | |
6049 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
6050 | desc = "device blocked"; | |
6051 | break; | |
6052 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
6053 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
6054 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
6055 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
6056 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
6057 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
6058 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
6059 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
6060 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
6061 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
6062 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
6063 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
6064 | desc = "sata initialization failed"; | |
6065 | break; | |
6066 | default: | |
6067 | desc = "unknown"; | |
6068 | break; | |
6069 | } | |
6070 | ||
6071 | if (!rc) | |
6072 | return 0; | |
6073 | ||
6074 | pr_err(MPT3SAS_FMT | |
6075 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
6076 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
6077 | return rc; | |
6078 | } | |
6079 | ||
aba5a85c SR |
6080 | /** |
6081 | * _scsih_get_enclosure_logicalid_chassis_slot - get device's | |
6082 | * EnclosureLogicalID and ChassisSlot information. | |
6083 | * @ioc: per adapter object | |
6084 | * @sas_device_pg0: SAS device page0 | |
6085 | * @sas_device: per sas device object | |
6086 | * | |
6087 | * Returns nothing. | |
6088 | */ | |
6089 | static void | |
6090 | _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER *ioc, | |
6091 | Mpi2SasDevicePage0_t *sas_device_pg0, struct _sas_device *sas_device) | |
6092 | { | |
6093 | Mpi2ConfigReply_t mpi_reply; | |
6094 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6095 | ||
6096 | if (!sas_device_pg0 || !sas_device) | |
6097 | return; | |
6098 | ||
6099 | sas_device->enclosure_handle = | |
6100 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
6101 | sas_device->is_chassis_slot_valid = 0; | |
6102 | ||
6103 | if (!le16_to_cpu(sas_device_pg0->EnclosureHandle)) | |
6104 | return; | |
6105 | ||
6106 | if (mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
6107 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
6108 | le16_to_cpu(sas_device_pg0->EnclosureHandle))) { | |
6109 | pr_err(MPT3SAS_FMT | |
6110 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
6111 | ioc->name, le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
6112 | return; | |
6113 | } | |
6114 | ||
6115 | sas_device->enclosure_logical_id = | |
6116 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
6117 | ||
6118 | if (le16_to_cpu(enclosure_pg0.Flags) & | |
6119 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6120 | sas_device->is_chassis_slot_valid = 1; | |
6121 | sas_device->chassis_slot = enclosure_pg0.ChassisSlot; | |
6122 | } | |
6123 | } | |
6124 | ||
6125 | ||
f92363d1 SR |
6126 | /** |
6127 | * _scsih_check_device - checking device responsiveness | |
6128 | * @ioc: per adapter object | |
6129 | * @parent_sas_address: sas address of parent expander or sas host | |
6130 | * @handle: attached device handle | |
6131 | * @phy_numberv: phy number | |
6132 | * @link_rate: new link rate | |
6133 | * | |
6134 | * Returns nothing. | |
6135 | */ | |
6136 | static void | |
6137 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
6138 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
6139 | { | |
6140 | Mpi2ConfigReply_t mpi_reply; | |
6141 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6142 | struct _sas_device *sas_device; | |
6143 | u32 ioc_status; | |
6144 | unsigned long flags; | |
6145 | u64 sas_address; | |
6146 | struct scsi_target *starget; | |
6147 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6148 | u32 device_info; | |
6149 | ||
f92363d1 SR |
6150 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
6151 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6152 | return; | |
6153 | ||
6154 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6155 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6156 | return; | |
6157 | ||
6158 | /* wide port handling ~ we need only handle device once for the phy that | |
6159 | * is matched in sas device page zero | |
6160 | */ | |
6161 | if (phy_number != sas_device_pg0.PhyNum) | |
6162 | return; | |
6163 | ||
6164 | /* check if this is end device */ | |
6165 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6166 | if (!(_scsih_is_end_device(device_info))) | |
6167 | return; | |
6168 | ||
6169 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6170 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 6171 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6172 | sas_address); |
6173 | ||
d1cb5e49 SR |
6174 | if (!sas_device) |
6175 | goto out_unlock; | |
f92363d1 SR |
6176 | |
6177 | if (unlikely(sas_device->handle != handle)) { | |
6178 | starget = sas_device->starget; | |
6179 | sas_target_priv_data = starget->hostdata; | |
6180 | starget_printk(KERN_INFO, starget, | |
6181 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6182 | sas_device->handle, handle); | |
6183 | sas_target_priv_data->handle = handle; | |
6184 | sas_device->handle = handle; | |
aa53bb89 | 6185 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
6186 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
6187 | sas_device->enclosure_level = | |
aa53bb89 | 6188 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6189 | memcpy(sas_device->connector_name, |
6190 | sas_device_pg0.ConnectorName, 4); | |
6191 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6192 | } else { |
6193 | sas_device->enclosure_level = 0; | |
6194 | sas_device->connector_name[0] = '\0'; | |
6195 | } | |
aba5a85c SR |
6196 | |
6197 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, | |
6198 | &sas_device_pg0, sas_device); | |
f92363d1 SR |
6199 | } |
6200 | ||
6201 | /* check if device is present */ | |
6202 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6203 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6204 | pr_err(MPT3SAS_FMT | |
6205 | "device is not present handle(0x%04x), flags!!!\n", | |
6206 | ioc->name, handle); | |
d1cb5e49 | 6207 | goto out_unlock; |
f92363d1 SR |
6208 | } |
6209 | ||
6210 | /* check if there were any issues with discovery */ | |
6211 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
6212 | sas_device_pg0.AccessStatus)) |
6213 | goto out_unlock; | |
f92363d1 SR |
6214 | |
6215 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6216 | _scsih_ublock_io_device(ioc, sas_address); | |
6217 | ||
d1cb5e49 SR |
6218 | if (sas_device) |
6219 | sas_device_put(sas_device); | |
6220 | return; | |
6221 | ||
6222 | out_unlock: | |
6223 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6224 | if (sas_device) | |
6225 | sas_device_put(sas_device); | |
f92363d1 SR |
6226 | } |
6227 | ||
6228 | /** | |
6229 | * _scsih_add_device - creating sas device object | |
6230 | * @ioc: per adapter object | |
6231 | * @handle: sas device handle | |
6232 | * @phy_num: phy number end device attached to | |
6233 | * @is_pd: is this hidden raid component | |
6234 | * | |
6235 | * Creating end device object, stored in ioc->sas_device_list. | |
6236 | * | |
6237 | * Returns 0 for success, non-zero for failure. | |
6238 | */ | |
6239 | static int | |
6240 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
6241 | u8 is_pd) | |
6242 | { | |
6243 | Mpi2ConfigReply_t mpi_reply; | |
6244 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6245 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
6246 | struct _sas_device *sas_device; | |
6247 | u32 ioc_status; | |
6248 | u64 sas_address; | |
6249 | u32 device_info; | |
75888956 | 6250 | int encl_pg0_rc = -1; |
f92363d1 SR |
6251 | |
6252 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6253 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6254 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6255 | ioc->name, __FILE__, __LINE__, __func__); | |
6256 | return -1; | |
6257 | } | |
6258 | ||
6259 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6260 | MPI2_IOCSTATUS_MASK; | |
6261 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6262 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6263 | ioc->name, __FILE__, __LINE__, __func__); | |
6264 | return -1; | |
6265 | } | |
6266 | ||
6267 | /* check if this is end device */ | |
6268 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6269 | if (!(_scsih_is_end_device(device_info))) | |
6270 | return -1; | |
c696f7b8 | 6271 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
6272 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
6273 | ||
6274 | /* check if device is present */ | |
6275 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
6276 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
6277 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
6278 | ioc->name, handle); | |
6279 | return -1; | |
6280 | } | |
6281 | ||
6282 | /* check if there were any issues with discovery */ | |
6283 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
6284 | sas_device_pg0.AccessStatus)) | |
6285 | return -1; | |
6286 | ||
d1cb5e49 SR |
6287 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
6288 | sas_address); | |
6289 | if (sas_device) { | |
c696f7b8 | 6290 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 6291 | sas_device_put(sas_device); |
f92363d1 | 6292 | return -1; |
d1cb5e49 | 6293 | } |
f92363d1 | 6294 | |
75888956 SR |
6295 | if (sas_device_pg0.EnclosureHandle) { |
6296 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
6297 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
6298 | sas_device_pg0.EnclosureHandle); | |
6299 | if (encl_pg0_rc) | |
6300 | pr_info(MPT3SAS_FMT | |
6301 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
6302 | ioc->name, sas_device_pg0.EnclosureHandle); | |
6303 | } | |
6304 | ||
f92363d1 SR |
6305 | sas_device = kzalloc(sizeof(struct _sas_device), |
6306 | GFP_KERNEL); | |
6307 | if (!sas_device) { | |
6308 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6309 | ioc->name, __FILE__, __LINE__, __func__); | |
6310 | return 0; | |
6311 | } | |
6312 | ||
d1cb5e49 | 6313 | kref_init(&sas_device->refcount); |
f92363d1 SR |
6314 | sas_device->handle = handle; |
6315 | if (_scsih_get_sas_address(ioc, | |
6316 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
6317 | &sas_device->sas_address_parent) != 0) | |
6318 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6319 | ioc->name, __FILE__, __LINE__, __func__); | |
6320 | sas_device->enclosure_handle = | |
6321 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
6322 | if (sas_device->enclosure_handle != 0) |
6323 | sas_device->slot = | |
6324 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
6325 | sas_device->device_info = device_info; |
6326 | sas_device->sas_address = sas_address; | |
6327 | sas_device->phy = sas_device_pg0.PhyNum; | |
6328 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
6329 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
6330 | ||
aa53bb89 SPS |
6331 | if (le16_to_cpu(sas_device_pg0.Flags) |
6332 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 6333 | sas_device->enclosure_level = |
aa53bb89 | 6334 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
6335 | memcpy(sas_device->connector_name, |
6336 | sas_device_pg0.ConnectorName, 4); | |
6337 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
6338 | } else { |
6339 | sas_device->enclosure_level = 0; | |
6340 | sas_device->connector_name[0] = '\0'; | |
6341 | } | |
75888956 SR |
6342 | |
6343 | /* get enclosure_logical_id & chassis_slot */ | |
6344 | sas_device->is_chassis_slot_valid = 0; | |
6345 | if (encl_pg0_rc == 0) { | |
f92363d1 SR |
6346 | sas_device->enclosure_logical_id = |
6347 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
6348 | ||
75888956 SR |
6349 | if (le16_to_cpu(enclosure_pg0.Flags) & |
6350 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
6351 | sas_device->is_chassis_slot_valid = 1; | |
6352 | sas_device->chassis_slot = | |
6353 | enclosure_pg0.ChassisSlot; | |
6354 | } | |
6355 | } | |
6356 | ||
f92363d1 SR |
6357 | /* get device name */ |
6358 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
6359 | ||
6360 | if (ioc->wait_for_discovery_to_complete) | |
6361 | _scsih_sas_device_init_add(ioc, sas_device); | |
6362 | else | |
6363 | _scsih_sas_device_add(ioc, sas_device); | |
6364 | ||
d1cb5e49 | 6365 | sas_device_put(sas_device); |
f92363d1 SR |
6366 | return 0; |
6367 | } | |
6368 | ||
6369 | /** | |
6370 | * _scsih_remove_device - removing sas device object | |
6371 | * @ioc: per adapter object | |
6372 | * @sas_device_delete: the sas_device object | |
6373 | * | |
6374 | * Return nothing. | |
6375 | */ | |
6376 | static void | |
6377 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
6378 | struct _sas_device *sas_device) | |
6379 | { | |
6380 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6381 | ||
0f624c39 SR |
6382 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
6383 | (sas_device->pfa_led_on)) { | |
6384 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
6385 | sas_device->pfa_led_on = 0; | |
6386 | } | |
75888956 | 6387 | |
f92363d1 SR |
6388 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
6389 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6390 | ioc->name, __func__, | |
6391 | sas_device->handle, (unsigned long long) | |
6392 | sas_device->sas_address)); | |
75888956 SR |
6393 | |
6394 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
6395 | NULL, NULL)); | |
f92363d1 SR |
6396 | |
6397 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6398 | sas_target_priv_data = sas_device->starget->hostdata; | |
6399 | sas_target_priv_data->deleted = 1; | |
6400 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
6401 | sas_target_priv_data->handle = | |
6402 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
6403 | } | |
7786ab6a SR |
6404 | |
6405 | if (!ioc->hide_drives) | |
6406 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
6407 | sas_device->sas_address, |
6408 | sas_device->sas_address_parent); | |
6409 | ||
6410 | pr_info(MPT3SAS_FMT | |
6411 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
6412 | ioc->name, sas_device->handle, | |
6413 | (unsigned long long) sas_device->sas_address); | |
75888956 SR |
6414 | |
6415 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 SR |
6416 | |
6417 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6418 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6419 | ioc->name, __func__, | |
e6d45e3e SR |
6420 | sas_device->handle, (unsigned long long) |
6421 | sas_device->sas_address)); | |
75888956 SR |
6422 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
6423 | NULL, NULL)); | |
f92363d1 SR |
6424 | } |
6425 | ||
f92363d1 SR |
6426 | /** |
6427 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
6428 | * @ioc: per adapter object | |
6429 | * @event_data: event data payload | |
6430 | * Context: user. | |
6431 | */ | |
6432 | static void | |
6433 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6434 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6435 | { | |
6436 | int i; | |
6437 | u16 handle; | |
6438 | u16 reason_code; | |
6439 | u8 phy_number; | |
6440 | char *status_str = NULL; | |
6441 | u8 link_rate, prev_link_rate; | |
6442 | ||
6443 | switch (event_data->ExpStatus) { | |
6444 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6445 | status_str = "add"; | |
6446 | break; | |
6447 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6448 | status_str = "remove"; | |
6449 | break; | |
6450 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6451 | case 0: | |
6452 | status_str = "responding"; | |
6453 | break; | |
6454 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6455 | status_str = "remove delay"; | |
6456 | break; | |
6457 | default: | |
6458 | status_str = "unknown status"; | |
6459 | break; | |
6460 | } | |
6461 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
6462 | ioc->name, status_str); | |
6463 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
6464 | "start_phy(%02d), count(%d)\n", | |
6465 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6466 | le16_to_cpu(event_data->EnclosureHandle), | |
6467 | event_data->StartPhyNum, event_data->NumEntries); | |
6468 | for (i = 0; i < event_data->NumEntries; i++) { | |
6469 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6470 | if (!handle) | |
6471 | continue; | |
6472 | phy_number = event_data->StartPhyNum + i; | |
6473 | reason_code = event_data->PHY[i].PhyStatus & | |
6474 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6475 | switch (reason_code) { | |
6476 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6477 | status_str = "target add"; | |
6478 | break; | |
6479 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6480 | status_str = "target remove"; | |
6481 | break; | |
6482 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6483 | status_str = "delay target remove"; | |
6484 | break; | |
6485 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6486 | status_str = "link rate change"; | |
6487 | break; | |
6488 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6489 | status_str = "target responding"; | |
6490 | break; | |
6491 | default: | |
6492 | status_str = "unknown"; | |
6493 | break; | |
6494 | } | |
6495 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6496 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6497 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6498 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6499 | handle, status_str, link_rate, prev_link_rate); | |
6500 | ||
6501 | } | |
6502 | } | |
f92363d1 SR |
6503 | |
6504 | /** | |
6505 | * _scsih_sas_topology_change_event - handle topology changes | |
6506 | * @ioc: per adapter object | |
6507 | * @fw_event: The fw_event_work object | |
6508 | * Context: user. | |
6509 | * | |
6510 | */ | |
6511 | static int | |
6512 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6513 | struct fw_event_work *fw_event) | |
6514 | { | |
6515 | int i; | |
6516 | u16 parent_handle, handle; | |
6517 | u16 reason_code; | |
6518 | u8 phy_number, max_phys; | |
6519 | struct _sas_node *sas_expander; | |
6520 | u64 sas_address; | |
6521 | unsigned long flags; | |
6522 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6523 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6524 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6525 | fw_event->event_data; | |
f92363d1 | 6526 | |
f92363d1 SR |
6527 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6528 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6529 | |
6530 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6531 | return 0; | |
6532 | ||
6533 | if (!ioc->sas_hba.num_phys) | |
6534 | _scsih_sas_host_add(ioc); | |
6535 | else | |
6536 | _scsih_sas_host_refresh(ioc); | |
6537 | ||
6538 | if (fw_event->ignore) { | |
6539 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6540 | "ignoring expander event\n", ioc->name)); | |
6541 | return 0; | |
6542 | } | |
6543 | ||
6544 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6545 | ||
6546 | /* handle expander add */ | |
6547 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6548 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6549 | return 0; | |
6550 | ||
6551 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6552 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6553 | parent_handle); | |
6554 | if (sas_expander) { | |
6555 | sas_address = sas_expander->sas_address; | |
6556 | max_phys = sas_expander->num_phys; | |
6557 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6558 | sas_address = ioc->sas_hba.sas_address; | |
6559 | max_phys = ioc->sas_hba.num_phys; | |
6560 | } else { | |
6561 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6562 | return 0; | |
6563 | } | |
6564 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6565 | ||
6566 | /* handle siblings events */ | |
6567 | for (i = 0; i < event_data->NumEntries; i++) { | |
6568 | if (fw_event->ignore) { | |
6569 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6570 | "ignoring expander event\n", ioc->name)); | |
6571 | return 0; | |
6572 | } | |
6573 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6574 | return 0; | |
6575 | phy_number = event_data->StartPhyNum + i; | |
6576 | if (phy_number >= max_phys) | |
6577 | continue; | |
6578 | reason_code = event_data->PHY[i].PhyStatus & | |
6579 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6580 | if ((event_data->PHY[i].PhyStatus & | |
6581 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6582 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6583 | continue; | |
6584 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6585 | if (!handle) | |
6586 | continue; | |
6587 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6588 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6589 | switch (reason_code) { | |
6590 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6591 | ||
6592 | if (ioc->shost_recovery) | |
6593 | break; | |
6594 | ||
6595 | if (link_rate == prev_link_rate) | |
6596 | break; | |
6597 | ||
6598 | mpt3sas_transport_update_links(ioc, sas_address, | |
6599 | handle, phy_number, link_rate); | |
6600 | ||
6601 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6602 | break; | |
6603 | ||
6604 | _scsih_check_device(ioc, sas_address, handle, | |
6605 | phy_number, link_rate); | |
6606 | ||
c696f7b8 SPS |
6607 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6608 | break; | |
6609 | ||
f92363d1 SR |
6610 | |
6611 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6612 | ||
6613 | if (ioc->shost_recovery) | |
6614 | break; | |
6615 | ||
6616 | mpt3sas_transport_update_links(ioc, sas_address, | |
6617 | handle, phy_number, link_rate); | |
6618 | ||
6619 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6620 | ||
6621 | break; | |
6622 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6623 | ||
6624 | _scsih_device_remove_by_handle(ioc, handle); | |
6625 | break; | |
6626 | } | |
6627 | } | |
6628 | ||
6629 | /* handle expander removal */ | |
6630 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6631 | sas_expander) | |
6632 | mpt3sas_expander_remove(ioc, sas_address); | |
6633 | ||
6634 | return 0; | |
6635 | } | |
6636 | ||
f92363d1 SR |
6637 | /** |
6638 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
6639 | * @event_data: event data payload | |
6640 | * Context: user. | |
6641 | * | |
6642 | * Return nothing. | |
6643 | */ | |
6644 | static void | |
6645 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6646 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6647 | { | |
6648 | char *reason_str = NULL; | |
6649 | ||
6650 | switch (event_data->ReasonCode) { | |
6651 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6652 | reason_str = "smart data"; | |
6653 | break; | |
6654 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6655 | reason_str = "unsupported device discovered"; | |
6656 | break; | |
6657 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6658 | reason_str = "internal device reset"; | |
6659 | break; | |
6660 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6661 | reason_str = "internal task abort"; | |
6662 | break; | |
6663 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6664 | reason_str = "internal task abort set"; | |
6665 | break; | |
6666 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6667 | reason_str = "internal clear task set"; | |
6668 | break; | |
6669 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6670 | reason_str = "internal query task"; | |
6671 | break; | |
6672 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6673 | reason_str = "sata init failure"; | |
6674 | break; | |
6675 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6676 | reason_str = "internal device reset complete"; | |
6677 | break; | |
6678 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6679 | reason_str = "internal task abort complete"; | |
6680 | break; | |
6681 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6682 | reason_str = "internal async notification"; | |
6683 | break; | |
6684 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6685 | reason_str = "expander reduced functionality"; | |
6686 | break; | |
6687 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6688 | reason_str = "expander reduced functionality complete"; | |
6689 | break; | |
6690 | default: | |
6691 | reason_str = "unknown reason"; | |
6692 | break; | |
6693 | } | |
6694 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
6695 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
6696 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
6697 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
6698 | le16_to_cpu(event_data->TaskTag)); | |
6699 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
6700 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
6701 | event_data->ASC, event_data->ASCQ); | |
6702 | pr_info("\n"); | |
6703 | } | |
f92363d1 SR |
6704 | |
6705 | /** | |
6706 | * _scsih_sas_device_status_change_event - handle device status change | |
6707 | * @ioc: per adapter object | |
6708 | * @fw_event: The fw_event_work object | |
6709 | * Context: user. | |
6710 | * | |
6711 | * Return nothing. | |
6712 | */ | |
6713 | static void | |
6714 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6715 | struct fw_event_work *fw_event) | |
6716 | { | |
6717 | struct MPT3SAS_TARGET *target_priv_data; | |
6718 | struct _sas_device *sas_device; | |
6719 | u64 sas_address; | |
6720 | unsigned long flags; | |
6721 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
6722 | (Mpi2EventDataSasDeviceStatusChange_t *) |
6723 | fw_event->event_data; | |
f92363d1 | 6724 | |
f92363d1 SR |
6725 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6726 | _scsih_sas_device_status_change_event_debug(ioc, | |
6727 | event_data); | |
f92363d1 SR |
6728 | |
6729 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6730 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6731 | */ | |
6732 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6733 | return; | |
6734 | ||
6735 | if (event_data->ReasonCode != | |
6736 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6737 | event_data->ReasonCode != | |
6738 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6739 | return; | |
6740 | ||
6741 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6742 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6743 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6744 | sas_address); |
6745 | ||
d1cb5e49 SR |
6746 | if (!sas_device || !sas_device->starget) |
6747 | goto out; | |
f92363d1 SR |
6748 | |
6749 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6750 | if (!target_priv_data) |
6751 | goto out; | |
f92363d1 SR |
6752 | |
6753 | if (event_data->ReasonCode == | |
6754 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6755 | target_priv_data->tm_busy = 1; | |
6756 | else | |
6757 | target_priv_data->tm_busy = 0; | |
d1cb5e49 SR |
6758 | |
6759 | out: | |
6760 | if (sas_device) | |
6761 | sas_device_put(sas_device); | |
6762 | ||
f92363d1 SR |
6763 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
6764 | } | |
6765 | ||
4318c734 | 6766 | |
c102e00c SPS |
6767 | /** |
6768 | * _scsih_check_pcie_access_status - check access flags | |
6769 | * @ioc: per adapter object | |
6770 | * @wwid: wwid | |
6771 | * @handle: sas device handle | |
6772 | * @access_flags: errors returned during discovery of the device | |
6773 | * | |
6774 | * Return 0 for success, else failure | |
6775 | */ | |
6776 | static u8 | |
6777 | _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6778 | u16 handle, u8 access_status) | |
6779 | { | |
6780 | u8 rc = 1; | |
6781 | char *desc = NULL; | |
6782 | ||
6783 | switch (access_status) { | |
6784 | case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS: | |
6785 | case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION: | |
6786 | rc = 0; | |
6787 | break; | |
6788 | case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED: | |
6789 | desc = "PCIe device capability failed"; | |
6790 | break; | |
6791 | case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED: | |
6792 | desc = "PCIe device blocked"; | |
6793 | break; | |
6794 | case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED: | |
6795 | desc = "PCIe device mem space access failed"; | |
6796 | break; | |
6797 | case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE: | |
6798 | desc = "PCIe device unsupported"; | |
6799 | break; | |
6800 | case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED: | |
6801 | desc = "PCIe device MSIx Required"; | |
6802 | break; | |
6803 | case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX: | |
6804 | desc = "PCIe device init fail max"; | |
6805 | break; | |
6806 | case MPI26_PCIEDEV0_ASTATUS_UNKNOWN: | |
6807 | desc = "PCIe device status unknown"; | |
6808 | break; | |
6809 | case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT: | |
6810 | desc = "nvme ready timeout"; | |
6811 | break; | |
6812 | case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED: | |
6813 | desc = "nvme device configuration unsupported"; | |
6814 | break; | |
6815 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED: | |
6816 | desc = "nvme identify failed"; | |
6817 | break; | |
6818 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED: | |
6819 | desc = "nvme qconfig failed"; | |
6820 | break; | |
6821 | case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED: | |
6822 | desc = "nvme qcreation failed"; | |
6823 | break; | |
6824 | case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED: | |
6825 | desc = "nvme eventcfg failed"; | |
6826 | break; | |
6827 | case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED: | |
6828 | desc = "nvme get feature stat failed"; | |
6829 | break; | |
6830 | case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT: | |
6831 | desc = "nvme idle timeout"; | |
6832 | break; | |
6833 | case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS: | |
6834 | desc = "nvme failure status"; | |
6835 | break; | |
6836 | default: | |
6837 | pr_err(MPT3SAS_FMT | |
6838 | " NVMe discovery error(0x%02x): wwid(0x%016llx)," | |
6839 | "handle(0x%04x)\n", ioc->name, access_status, | |
6840 | (unsigned long long)wwid, handle); | |
6841 | return rc; | |
6842 | } | |
6843 | ||
6844 | if (!rc) | |
6845 | return rc; | |
6846 | ||
6847 | pr_info(MPT3SAS_FMT | |
6848 | "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n", | |
6849 | ioc->name, desc, | |
6850 | (unsigned long long)wwid, handle); | |
6851 | return rc; | |
6852 | } | |
3075ac49 SPS |
6853 | |
6854 | /** | |
6855 | * _scsih_pcie_device_remove_from_sml - removing pcie device | |
6856 | * from SML and free up associated memory | |
6857 | * @ioc: per adapter object | |
6858 | * @pcie_device: the pcie_device object | |
6859 | * | |
6860 | * Return nothing. | |
6861 | */ | |
6862 | static void | |
6863 | _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc, | |
6864 | struct _pcie_device *pcie_device) | |
6865 | { | |
6866 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6867 | ||
6868 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6869 | "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6870 | pcie_device->handle, (unsigned long long) | |
6871 | pcie_device->wwid)); | |
6872 | if (pcie_device->enclosure_handle != 0) | |
6873 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6874 | "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n", | |
6875 | ioc->name, __func__, | |
6876 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6877 | pcie_device->slot)); | |
6878 | if (pcie_device->connector_name[0] != '\0') | |
6879 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6880 | "%s: enter: enclosure level(0x%04x), connector name( %s)\n", | |
6881 | ioc->name, __func__, | |
6882 | pcie_device->enclosure_level, | |
6883 | pcie_device->connector_name)); | |
6884 | ||
6885 | if (pcie_device->starget && pcie_device->starget->hostdata) { | |
6886 | sas_target_priv_data = pcie_device->starget->hostdata; | |
6887 | sas_target_priv_data->deleted = 1; | |
6888 | _scsih_ublock_io_device(ioc, pcie_device->wwid); | |
6889 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
6890 | } | |
6891 | ||
6892 | pr_info(MPT3SAS_FMT | |
6893 | "removing handle(0x%04x), wwid (0x%016llx)\n", | |
6894 | ioc->name, pcie_device->handle, | |
6895 | (unsigned long long) pcie_device->wwid); | |
6896 | if (pcie_device->enclosure_handle != 0) | |
6897 | pr_info(MPT3SAS_FMT | |
6898 | "removing : enclosure logical id(0x%016llx), slot(%d)\n", | |
6899 | ioc->name, | |
6900 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6901 | pcie_device->slot); | |
6902 | if (pcie_device->connector_name[0] != '\0') | |
6903 | pr_info(MPT3SAS_FMT | |
6904 | "removing: enclosure level(0x%04x), connector name( %s)\n", | |
6905 | ioc->name, pcie_device->enclosure_level, | |
6906 | pcie_device->connector_name); | |
6907 | ||
6908 | if (pcie_device->starget) | |
6909 | scsi_remove_target(&pcie_device->starget->dev); | |
6910 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6911 | "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
6912 | pcie_device->handle, (unsigned long long) | |
6913 | pcie_device->wwid)); | |
6914 | if (pcie_device->enclosure_handle != 0) | |
6915 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6916 | "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n", | |
6917 | ioc->name, __func__, | |
6918 | (unsigned long long)pcie_device->enclosure_logical_id, | |
6919 | pcie_device->slot)); | |
6920 | if (pcie_device->connector_name[0] != '\0') | |
6921 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6922 | "%s: exit: enclosure level(0x%04x), connector name( %s)\n", | |
6923 | ioc->name, __func__, pcie_device->enclosure_level, | |
6924 | pcie_device->connector_name)); | |
6925 | ||
6926 | kfree(pcie_device->serial_number); | |
6927 | } | |
6928 | ||
6929 | ||
c102e00c SPS |
6930 | /** |
6931 | * _scsih_pcie_check_device - checking device responsiveness | |
6932 | * @ioc: per adapter object | |
6933 | * @handle: attached device handle | |
6934 | * | |
6935 | * Returns nothing. | |
6936 | */ | |
6937 | static void | |
6938 | _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6939 | { | |
6940 | Mpi2ConfigReply_t mpi_reply; | |
6941 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
6942 | u32 ioc_status; | |
6943 | struct _pcie_device *pcie_device; | |
6944 | u64 wwid; | |
6945 | unsigned long flags; | |
6946 | struct scsi_target *starget; | |
6947 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6948 | u32 device_info; | |
6949 | ||
6950 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
6951 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) | |
6952 | return; | |
6953 | ||
6954 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
6955 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
6956 | return; | |
6957 | ||
6958 | /* check if this is end device */ | |
6959 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
6960 | if (!(_scsih_is_nvme_device(device_info))) | |
6961 | return; | |
6962 | ||
6963 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
6964 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
6965 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
6966 | ||
6967 | if (!pcie_device) { | |
6968 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
6969 | return; | |
6970 | } | |
6971 | ||
6972 | if (unlikely(pcie_device->handle != handle)) { | |
6973 | starget = pcie_device->starget; | |
6974 | sas_target_priv_data = starget->hostdata; | |
6975 | starget_printk(KERN_INFO, starget, | |
6976 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
6977 | pcie_device->handle, handle); | |
6978 | sas_target_priv_data->handle = handle; | |
6979 | pcie_device->handle = handle; | |
6980 | ||
6981 | if (le32_to_cpu(pcie_device_pg0.Flags) & | |
6982 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
6983 | pcie_device->enclosure_level = | |
6984 | pcie_device_pg0.EnclosureLevel; | |
6985 | memcpy(&pcie_device->connector_name[0], | |
6986 | &pcie_device_pg0.ConnectorName[0], 4); | |
6987 | } else { | |
6988 | pcie_device->enclosure_level = 0; | |
6989 | pcie_device->connector_name[0] = '\0'; | |
6990 | } | |
6991 | } | |
6992 | ||
6993 | /* check if device is present */ | |
6994 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
6995 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
6996 | pr_info(MPT3SAS_FMT | |
6997 | "device is not present handle(0x%04x), flags!!!\n", | |
6998 | ioc->name, handle); | |
6999 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7000 | pcie_device_put(pcie_device); | |
7001 | return; | |
7002 | } | |
7003 | ||
7004 | /* check if there were any issues with discovery */ | |
7005 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
7006 | pcie_device_pg0.AccessStatus)) { | |
7007 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7008 | pcie_device_put(pcie_device); | |
7009 | return; | |
7010 | } | |
7011 | ||
7012 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7013 | pcie_device_put(pcie_device); | |
7014 | ||
7015 | _scsih_ublock_io_device(ioc, wwid); | |
7016 | ||
7017 | return; | |
7018 | } | |
7019 | ||
7020 | /** | |
7021 | * _scsih_pcie_add_device - creating pcie device object | |
7022 | * @ioc: per adapter object | |
7023 | * @handle: pcie device handle | |
7024 | * | |
7025 | * Creating end device object, stored in ioc->pcie_device_list. | |
7026 | * | |
7027 | * Return 1 means queue the event later, 0 means complete the event | |
7028 | */ | |
7029 | static int | |
7030 | _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7031 | { | |
7032 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
7033 | Mpi26PCIeDevicePage2_t pcie_device_pg2; | |
7034 | Mpi2ConfigReply_t mpi_reply; | |
7035 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
7036 | struct _pcie_device *pcie_device; | |
7037 | u32 pcie_device_type; | |
7038 | u32 ioc_status; | |
7039 | u64 wwid; | |
7040 | ||
7041 | if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
7042 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
7043 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7044 | ioc->name, __FILE__, __LINE__, __func__); | |
7045 | return 0; | |
7046 | } | |
7047 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7048 | MPI2_IOCSTATUS_MASK; | |
7049 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7050 | pr_err(MPT3SAS_FMT | |
7051 | "failure at %s:%d/%s()!\n", | |
7052 | ioc->name, __FILE__, __LINE__, __func__); | |
7053 | return 0; | |
7054 | } | |
7055 | ||
7056 | set_bit(handle, ioc->pend_os_device_add); | |
7057 | wwid = le64_to_cpu(pcie_device_pg0.WWID); | |
7058 | ||
7059 | /* check if device is present */ | |
7060 | if (!(le32_to_cpu(pcie_device_pg0.Flags) & | |
7061 | MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) { | |
7062 | pr_err(MPT3SAS_FMT | |
7063 | "device is not present handle(0x04%x)!!!\n", | |
7064 | ioc->name, handle); | |
7065 | return 0; | |
7066 | } | |
7067 | ||
7068 | /* check if there were any issues with discovery */ | |
7069 | if (_scsih_check_pcie_access_status(ioc, wwid, handle, | |
7070 | pcie_device_pg0.AccessStatus)) | |
7071 | return 0; | |
7072 | ||
7073 | if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
7074 | return 0; | |
7075 | ||
7076 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7077 | if (pcie_device) { | |
7078 | clear_bit(handle, ioc->pend_os_device_add); | |
7079 | pcie_device_put(pcie_device); | |
7080 | return 0; | |
7081 | } | |
7082 | ||
7083 | pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL); | |
7084 | if (!pcie_device) { | |
7085 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7086 | ioc->name, __FILE__, __LINE__, __func__); | |
7087 | return 0; | |
7088 | } | |
7089 | ||
7090 | kref_init(&pcie_device->refcount); | |
7091 | pcie_device->id = ioc->pcie_target_id++; | |
7092 | pcie_device->channel = PCIE_CHANNEL; | |
7093 | pcie_device->handle = handle; | |
7094 | pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
7095 | pcie_device->wwid = wwid; | |
7096 | pcie_device->port_num = pcie_device_pg0.PortNum; | |
7097 | pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) & | |
7098 | MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
7099 | pcie_device_type = pcie_device->device_info & | |
7100 | MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE; | |
7101 | ||
7102 | pcie_device->enclosure_handle = | |
7103 | le16_to_cpu(pcie_device_pg0.EnclosureHandle); | |
7104 | if (pcie_device->enclosure_handle != 0) | |
7105 | pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot); | |
7106 | ||
7107 | if (le16_to_cpu(pcie_device_pg0.Flags) & | |
7108 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) { | |
7109 | pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel; | |
7110 | memcpy(&pcie_device->connector_name[0], | |
7111 | &pcie_device_pg0.ConnectorName[0], 4); | |
7112 | } else { | |
7113 | pcie_device->enclosure_level = 0; | |
7114 | pcie_device->connector_name[0] = '\0'; | |
7115 | } | |
7116 | ||
7117 | /* get enclosure_logical_id */ | |
7118 | if (pcie_device->enclosure_handle && | |
7119 | !(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
7120 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
7121 | pcie_device->enclosure_handle))) | |
7122 | pcie_device->enclosure_logical_id = | |
7123 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
7124 | ||
7125 | /* TODO -- Add device name once FW supports it */ | |
7126 | if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply, | |
7127 | &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) { | |
7128 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7129 | ioc->name, __FILE__, __LINE__, __func__); | |
7130 | kfree(pcie_device); | |
7131 | return 0; | |
7132 | } | |
7133 | ||
7134 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
7135 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7136 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7137 | ioc->name, __FILE__, __LINE__, __func__); | |
7138 | kfree(pcie_device); | |
7139 | return 0; | |
7140 | } | |
7141 | pcie_device->nvme_mdts = | |
7142 | le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize); | |
7143 | ||
7144 | if (ioc->wait_for_discovery_to_complete) | |
7145 | _scsih_pcie_device_init_add(ioc, pcie_device); | |
7146 | else | |
7147 | _scsih_pcie_device_add(ioc, pcie_device); | |
7148 | ||
7149 | pcie_device_put(pcie_device); | |
7150 | return 0; | |
7151 | } | |
4318c734 SPS |
7152 | |
7153 | /** | |
7154 | * _scsih_pcie_topology_change_event_debug - debug for topology | |
7155 | * event | |
7156 | * @ioc: per adapter object | |
7157 | * @event_data: event data payload | |
7158 | * Context: user. | |
7159 | */ | |
7160 | static void | |
7161 | _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7162 | Mpi26EventDataPCIeTopologyChangeList_t *event_data) | |
7163 | { | |
7164 | int i; | |
7165 | u16 handle; | |
7166 | u16 reason_code; | |
7167 | u8 port_number; | |
7168 | char *status_str = NULL; | |
7169 | u8 link_rate, prev_link_rate; | |
7170 | ||
7171 | switch (event_data->SwitchStatus) { | |
7172 | case MPI26_EVENT_PCIE_TOPO_SS_ADDED: | |
7173 | status_str = "add"; | |
7174 | break; | |
7175 | case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING: | |
7176 | status_str = "remove"; | |
7177 | break; | |
7178 | case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING: | |
7179 | case 0: | |
7180 | status_str = "responding"; | |
7181 | break; | |
7182 | case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING: | |
7183 | status_str = "remove delay"; | |
7184 | break; | |
7185 | default: | |
7186 | status_str = "unknown status"; | |
7187 | break; | |
7188 | } | |
7189 | pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n", | |
7190 | ioc->name, status_str); | |
7191 | pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)" | |
7192 | "start_port(%02d), count(%d)\n", | |
7193 | le16_to_cpu(event_data->SwitchDevHandle), | |
7194 | le16_to_cpu(event_data->EnclosureHandle), | |
7195 | event_data->StartPortNum, event_data->NumEntries); | |
7196 | for (i = 0; i < event_data->NumEntries; i++) { | |
7197 | handle = | |
7198 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7199 | if (!handle) | |
7200 | continue; | |
7201 | port_number = event_data->StartPortNum + i; | |
7202 | reason_code = event_data->PortEntry[i].PortStatus; | |
7203 | switch (reason_code) { | |
7204 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7205 | status_str = "target add"; | |
7206 | break; | |
7207 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7208 | status_str = "target remove"; | |
7209 | break; | |
7210 | case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING: | |
7211 | status_str = "delay target remove"; | |
7212 | break; | |
7213 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7214 | status_str = "link rate change"; | |
7215 | break; | |
7216 | case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE: | |
7217 | status_str = "target responding"; | |
7218 | break; | |
7219 | default: | |
7220 | status_str = "unknown"; | |
7221 | break; | |
7222 | } | |
7223 | link_rate = event_data->PortEntry[i].CurrentPortInfo & | |
7224 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7225 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo & | |
7226 | MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7227 | pr_info("\tport(%02d), attached_handle(0x%04x): %s:" | |
7228 | " link rate: new(0x%02x), old(0x%02x)\n", port_number, | |
7229 | handle, status_str, link_rate, prev_link_rate); | |
7230 | } | |
7231 | } | |
7232 | ||
7233 | /** | |
7234 | * _scsih_pcie_topology_change_event - handle PCIe topology | |
7235 | * changes | |
7236 | * @ioc: per adapter object | |
7237 | * @fw_event: The fw_event_work object | |
7238 | * Context: user. | |
7239 | * | |
7240 | */ | |
7241 | static int | |
7242 | _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7243 | struct fw_event_work *fw_event) | |
7244 | { | |
7245 | int i; | |
7246 | u16 handle; | |
7247 | u16 reason_code; | |
7248 | u8 link_rate, prev_link_rate; | |
7249 | unsigned long flags; | |
7250 | int rc; | |
7251 | int requeue_event; | |
7252 | Mpi26EventDataPCIeTopologyChangeList_t *event_data = | |
7253 | (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data; | |
7254 | struct _pcie_device *pcie_device; | |
7255 | ||
7256 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7257 | _scsih_pcie_topology_change_event_debug(ioc, event_data); | |
7258 | ||
7259 | if (ioc->shost_recovery || ioc->remove_host || | |
7260 | ioc->pci_error_recovery) | |
7261 | return 0; | |
7262 | ||
7263 | if (fw_event->ignore) { | |
7264 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n", | |
7265 | ioc->name)); | |
7266 | return 0; | |
7267 | } | |
7268 | ||
7269 | /* handle siblings events */ | |
7270 | for (i = 0; i < event_data->NumEntries; i++) { | |
7271 | if (fw_event->ignore) { | |
7272 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7273 | "ignoring switch event\n", ioc->name)); | |
7274 | return 0; | |
7275 | } | |
7276 | if (ioc->remove_host || ioc->pci_error_recovery) | |
7277 | return 0; | |
7278 | reason_code = event_data->PortEntry[i].PortStatus; | |
7279 | handle = | |
7280 | le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle); | |
7281 | if (!handle) | |
7282 | continue; | |
7283 | ||
7284 | link_rate = event_data->PortEntry[i].CurrentPortInfo | |
7285 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7286 | prev_link_rate = event_data->PortEntry[i].PreviousPortInfo | |
7287 | & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK; | |
7288 | ||
7289 | switch (reason_code) { | |
7290 | case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED: | |
7291 | if (ioc->shost_recovery) | |
7292 | break; | |
7293 | if (link_rate == prev_link_rate) | |
7294 | break; | |
7295 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7296 | break; | |
7297 | ||
7298 | _scsih_pcie_check_device(ioc, handle); | |
7299 | ||
7300 | /* This code after this point handles the test case | |
7301 | * where a device has been added, however its returning | |
7302 | * BUSY for sometime. Then before the Device Missing | |
7303 | * Delay expires and the device becomes READY, the | |
7304 | * device is removed and added back. | |
7305 | */ | |
7306 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7307 | pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle); | |
7308 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7309 | ||
7310 | if (pcie_device) { | |
7311 | pcie_device_put(pcie_device); | |
7312 | break; | |
7313 | } | |
7314 | ||
7315 | if (!test_bit(handle, ioc->pend_os_device_add)) | |
7316 | break; | |
7317 | ||
7318 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7319 | "handle(0x%04x) device not found: convert " | |
7320 | "event to a device add\n", ioc->name, handle)); | |
7321 | event_data->PortEntry[i].PortStatus &= 0xF0; | |
7322 | event_data->PortEntry[i].PortStatus |= | |
7323 | MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED; | |
7324 | case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED: | |
7325 | if (ioc->shost_recovery) | |
7326 | break; | |
7327 | if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5) | |
7328 | break; | |
7329 | ||
7330 | rc = _scsih_pcie_add_device(ioc, handle); | |
7331 | if (!rc) { | |
7332 | /* mark entry vacant */ | |
7333 | /* TODO This needs to be reviewed and fixed, | |
7334 | * we dont have an entry | |
7335 | * to make an event void like vacant | |
7336 | */ | |
7337 | event_data->PortEntry[i].PortStatus |= | |
7338 | MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE; | |
7339 | } | |
7340 | break; | |
7341 | case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING: | |
7342 | _scsih_pcie_device_remove_by_handle(ioc, handle); | |
7343 | break; | |
7344 | } | |
7345 | } | |
7346 | return requeue_event; | |
7347 | } | |
7348 | ||
7349 | /** | |
7350 | * _scsih_pcie_device_status_change_event_debug - debug for | |
7351 | * device event | |
7352 | * @event_data: event data payload | |
7353 | * Context: user. | |
7354 | * | |
7355 | * Return nothing. | |
7356 | */ | |
7357 | static void | |
7358 | _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7359 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data) | |
7360 | { | |
7361 | char *reason_str = NULL; | |
7362 | ||
7363 | switch (event_data->ReasonCode) { | |
7364 | case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA: | |
7365 | reason_str = "smart data"; | |
7366 | break; | |
7367 | case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED: | |
7368 | reason_str = "unsupported device discovered"; | |
7369 | break; | |
7370 | case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
7371 | reason_str = "internal device reset"; | |
7372 | break; | |
7373 | case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL: | |
7374 | reason_str = "internal task abort"; | |
7375 | break; | |
7376 | case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
7377 | reason_str = "internal task abort set"; | |
7378 | break; | |
7379 | case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
7380 | reason_str = "internal clear task set"; | |
7381 | break; | |
7382 | case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL: | |
7383 | reason_str = "internal query task"; | |
7384 | break; | |
7385 | case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE: | |
7386 | reason_str = "device init failure"; | |
7387 | break; | |
7388 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
7389 | reason_str = "internal device reset complete"; | |
7390 | break; | |
7391 | case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
7392 | reason_str = "internal task abort complete"; | |
7393 | break; | |
7394 | case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION: | |
7395 | reason_str = "internal async notification"; | |
7396 | break; | |
7397 | default: | |
7398 | reason_str = "unknown reason"; | |
7399 | break; | |
7400 | } | |
7401 | ||
7402 | pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n" | |
7403 | "\thandle(0x%04x), WWID(0x%016llx), tag(%d)", | |
7404 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
7405 | (unsigned long long)le64_to_cpu(event_data->WWID), | |
7406 | le16_to_cpu(event_data->TaskTag)); | |
7407 | if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA) | |
7408 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
7409 | event_data->ASC, event_data->ASCQ); | |
7410 | pr_info("\n"); | |
7411 | } | |
7412 | ||
7413 | /** | |
7414 | * _scsih_pcie_device_status_change_event - handle device status | |
7415 | * change | |
7416 | * @ioc: per adapter object | |
7417 | * @fw_event: The fw_event_work object | |
7418 | * Context: user. | |
7419 | * | |
7420 | * Return nothing. | |
7421 | */ | |
7422 | static void | |
7423 | _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7424 | struct fw_event_work *fw_event) | |
7425 | { | |
7426 | struct MPT3SAS_TARGET *target_priv_data; | |
7427 | struct _pcie_device *pcie_device; | |
7428 | u64 wwid; | |
7429 | unsigned long flags; | |
7430 | Mpi26EventDataPCIeDeviceStatusChange_t *event_data = | |
7431 | (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data; | |
7432 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
7433 | _scsih_pcie_device_status_change_event_debug(ioc, | |
7434 | event_data); | |
7435 | ||
7436 | if (event_data->ReasonCode != | |
7437 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
7438 | event_data->ReasonCode != | |
7439 | MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
7440 | return; | |
7441 | ||
7442 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
7443 | wwid = le64_to_cpu(event_data->WWID); | |
7444 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
7445 | ||
7446 | if (!pcie_device || !pcie_device->starget) | |
7447 | goto out; | |
7448 | ||
7449 | target_priv_data = pcie_device->starget->hostdata; | |
7450 | if (!target_priv_data) | |
7451 | goto out; | |
7452 | ||
7453 | if (event_data->ReasonCode == | |
7454 | MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
7455 | target_priv_data->tm_busy = 1; | |
7456 | else | |
7457 | target_priv_data->tm_busy = 0; | |
7458 | out: | |
7459 | if (pcie_device) | |
7460 | pcie_device_put(pcie_device); | |
7461 | ||
7462 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
7463 | } | |
7464 | ||
f92363d1 SR |
7465 | /** |
7466 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
7467 | * event | |
7468 | * @ioc: per adapter object | |
7469 | * @event_data: event data payload | |
7470 | * Context: user. | |
7471 | * | |
7472 | * Return nothing. | |
7473 | */ | |
7474 | static void | |
7475 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7476 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
7477 | { | |
7478 | char *reason_str = NULL; | |
7479 | ||
7480 | switch (event_data->ReasonCode) { | |
7481 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
7482 | reason_str = "enclosure add"; | |
7483 | break; | |
7484 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
7485 | reason_str = "enclosure remove"; | |
7486 | break; | |
7487 | default: | |
7488 | reason_str = "unknown reason"; | |
7489 | break; | |
7490 | } | |
7491 | ||
7492 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
7493 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
7494 | " number slots(%d)\n", ioc->name, reason_str, | |
7495 | le16_to_cpu(event_data->EnclosureHandle), | |
7496 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
7497 | le16_to_cpu(event_data->StartSlot)); | |
7498 | } | |
f92363d1 SR |
7499 | |
7500 | /** | |
7501 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
7502 | * @ioc: per adapter object | |
7503 | * @fw_event: The fw_event_work object | |
7504 | * Context: user. | |
7505 | * | |
7506 | * Return nothing. | |
7507 | */ | |
7508 | static void | |
7509 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7510 | struct fw_event_work *fw_event) | |
7511 | { | |
f92363d1 SR |
7512 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
7513 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 7514 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 7515 | fw_event->event_data); |
f92363d1 SR |
7516 | } |
7517 | ||
7518 | /** | |
7519 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
7520 | * @ioc: per adapter object | |
7521 | * @fw_event: The fw_event_work object | |
7522 | * Context: user. | |
7523 | * | |
7524 | * Return nothing. | |
7525 | */ | |
7526 | static void | |
7527 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
7528 | struct fw_event_work *fw_event) | |
7529 | { | |
7530 | struct scsi_cmnd *scmd; | |
7531 | struct scsi_device *sdev; | |
7532 | u16 smid, handle; | |
7533 | u32 lun; | |
7534 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7535 | u32 termination_count; | |
7536 | u32 query_count; | |
7537 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
7538 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
7539 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7540 | fw_event->event_data; | |
f92363d1 SR |
7541 | u16 ioc_status; |
7542 | unsigned long flags; | |
7543 | int r; | |
7544 | u8 max_retries = 0; | |
7545 | u8 task_abort_retries; | |
7546 | ||
7547 | mutex_lock(&ioc->tm_cmds.mutex); | |
7548 | pr_info(MPT3SAS_FMT | |
7549 | "%s: enter: phy number(%d), width(%d)\n", | |
7550 | ioc->name, __func__, event_data->PhyNum, | |
7551 | event_data->PortWidth); | |
7552 | ||
7553 | _scsih_block_io_all_device(ioc); | |
7554 | ||
7555 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7556 | mpi_reply = ioc->tm_cmds.reply; | |
7557 | broadcast_aen_retry: | |
7558 | ||
7559 | /* sanity checks for retrying this loop */ | |
7560 | if (max_retries++ == 5) { | |
7561 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
7562 | ioc->name, __func__)); | |
7563 | goto out; | |
7564 | } else if (max_retries > 1) | |
7565 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
7566 | ioc->name, __func__, max_retries - 1)); | |
7567 | ||
7568 | termination_count = 0; | |
7569 | query_count = 0; | |
7570 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
7571 | if (ioc->shost_recovery) | |
7572 | goto out; | |
7573 | scmd = _scsih_scsi_lookup_get(ioc, smid); | |
7574 | if (!scmd) | |
7575 | continue; | |
7576 | sdev = scmd->device; | |
7577 | sas_device_priv_data = sdev->hostdata; | |
7578 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
7579 | continue; | |
7580 | /* skip hidden raid components */ | |
7581 | if (sas_device_priv_data->sas_target->flags & | |
7582 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
7583 | continue; | |
7584 | /* skip volumes */ | |
7585 | if (sas_device_priv_data->sas_target->flags & | |
7586 | MPT_TARGET_FLAGS_VOLUME) | |
7587 | continue; | |
7588 | ||
7589 | handle = sas_device_priv_data->sas_target->handle; | |
7590 | lun = sas_device_priv_data->lun; | |
7591 | query_count++; | |
7592 | ||
7593 | if (ioc->shost_recovery) | |
7594 | goto out; | |
7595 | ||
7596 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7597 | r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun, | |
96902835 | 7598 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30); |
f92363d1 SR |
7599 | if (r == FAILED) { |
7600 | sdev_printk(KERN_WARNING, sdev, | |
7601 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
7602 | "QUERY_TASK: scmd(%p)\n", scmd); | |
7603 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7604 | goto broadcast_aen_retry; | |
7605 | } | |
7606 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
7607 | & MPI2_IOCSTATUS_MASK; | |
7608 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7609 | sdev_printk(KERN_WARNING, sdev, | |
7610 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
7611 | ioc_status, scmd); | |
7612 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7613 | goto broadcast_aen_retry; | |
7614 | } | |
7615 | ||
7616 | /* see if IO is still owned by IOC and target */ | |
7617 | if (mpi_reply->ResponseCode == | |
7618 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
7619 | mpi_reply->ResponseCode == | |
7620 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
7621 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7622 | continue; | |
7623 | } | |
7624 | task_abort_retries = 0; | |
7625 | tm_retry: | |
7626 | if (task_abort_retries++ == 60) { | |
7627 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7628 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
7629 | __func__)); | |
7630 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7631 | goto broadcast_aen_retry; | |
7632 | } | |
7633 | ||
7634 | if (ioc->shost_recovery) | |
7635 | goto out_no_lock; | |
7636 | ||
7637 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, | |
96902835 CO |
7638 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, |
7639 | 30); | |
f92363d1 SR |
7640 | if (r == FAILED) { |
7641 | sdev_printk(KERN_WARNING, sdev, | |
7642 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
7643 | "scmd(%p)\n", scmd); | |
7644 | goto tm_retry; | |
7645 | } | |
7646 | ||
7647 | if (task_abort_retries > 1) | |
7648 | sdev_printk(KERN_WARNING, sdev, | |
7649 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
7650 | " scmd(%p)\n", | |
7651 | task_abort_retries - 1, scmd); | |
7652 | ||
7653 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
7654 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
7655 | } | |
7656 | ||
7657 | if (ioc->broadcast_aen_pending) { | |
7658 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7659 | "%s: loop back due to pending AEN\n", | |
7660 | ioc->name, __func__)); | |
7661 | ioc->broadcast_aen_pending = 0; | |
7662 | goto broadcast_aen_retry; | |
7663 | } | |
7664 | ||
7665 | out: | |
7666 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
7667 | out_no_lock: | |
7668 | ||
7669 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7670 | "%s - exit, query_count = %d termination_count = %d\n", | |
7671 | ioc->name, __func__, query_count, termination_count)); | |
7672 | ||
7673 | ioc->broadcast_aen_busy = 0; | |
7674 | if (!ioc->shost_recovery) | |
7675 | _scsih_ublock_io_all_device(ioc); | |
7676 | mutex_unlock(&ioc->tm_cmds.mutex); | |
7677 | } | |
7678 | ||
7679 | /** | |
7680 | * _scsih_sas_discovery_event - handle discovery events | |
7681 | * @ioc: per adapter object | |
7682 | * @fw_event: The fw_event_work object | |
7683 | * Context: user. | |
7684 | * | |
7685 | * Return nothing. | |
7686 | */ | |
7687 | static void | |
7688 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
7689 | struct fw_event_work *fw_event) | |
7690 | { | |
35b62362 JL |
7691 | Mpi2EventDataSasDiscovery_t *event_data = |
7692 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 7693 | |
f92363d1 SR |
7694 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
7695 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
7696 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
7697 | "start" : "stop"); | |
af009411 SR |
7698 | if (event_data->DiscoveryStatus) |
7699 | pr_info("discovery_status(0x%08x)", | |
7700 | le32_to_cpu(event_data->DiscoveryStatus)); | |
7701 | pr_info("\n"); | |
f92363d1 | 7702 | } |
f92363d1 SR |
7703 | |
7704 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
7705 | !ioc->sas_hba.num_phys) { | |
7706 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
7707 | /* Wait for the reset to complete */ | |
7708 | while (ioc->shost_recovery) | |
7709 | ssleep(1); | |
7710 | } | |
7711 | _scsih_sas_host_add(ioc); | |
7712 | } | |
7713 | } | |
7714 | ||
4318c734 SPS |
7715 | /** |
7716 | * _scsih_pcie_enumeration_event - handle enumeration events | |
7717 | * @ioc: per adapter object | |
7718 | * @fw_event: The fw_event_work object | |
7719 | * Context: user. | |
7720 | * | |
7721 | * Return nothing. | |
7722 | */ | |
7723 | static void | |
7724 | _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc, | |
7725 | struct fw_event_work *fw_event) | |
7726 | { | |
7727 | Mpi26EventDataPCIeEnumeration_t *event_data = | |
7728 | (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data; | |
7729 | ||
7730 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { | |
7731 | pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x", | |
7732 | ioc->name, | |
7733 | ((event_data->ReasonCode == | |
7734 | MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? | |
7735 | "started" : "completed"), event_data->Flags); | |
7736 | if (event_data->EnumerationStatus) | |
7737 | pr_info("enumeration_status(0x%08x)", | |
7738 | le32_to_cpu(event_data->EnumerationStatus)); | |
7739 | pr_info("\n"); | |
7740 | } | |
7741 | } | |
7742 | ||
f92363d1 SR |
7743 | /** |
7744 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
7745 | * @ioc: per adapter object | |
7746 | * @handle: device handle for physical disk | |
7747 | * @phys_disk_num: physical disk number | |
7748 | * | |
7749 | * Return 0 for success, else failure. | |
7750 | */ | |
7751 | static int | |
7752 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
7753 | { | |
7754 | Mpi2RaidActionRequest_t *mpi_request; | |
7755 | Mpi2RaidActionReply_t *mpi_reply; | |
7756 | u16 smid; | |
7757 | u8 issue_reset = 0; | |
7758 | int rc = 0; | |
7759 | u16 ioc_status; | |
7760 | u32 log_info; | |
7761 | ||
c84b06a4 SR |
7762 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
7763 | return rc; | |
7764 | ||
f92363d1 SR |
7765 | mutex_lock(&ioc->scsih_cmds.mutex); |
7766 | ||
7767 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
7768 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
7769 | ioc->name, __func__); | |
7770 | rc = -EAGAIN; | |
7771 | goto out; | |
7772 | } | |
7773 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7774 | ||
7775 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7776 | if (!smid) { | |
7777 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
7778 | ioc->name, __func__); | |
7779 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7780 | rc = -EAGAIN; | |
7781 | goto out; | |
7782 | } | |
7783 | ||
7784 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7785 | ioc->scsih_cmds.smid = smid; | |
7786 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7787 | ||
7788 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7789 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
7790 | mpi_request->PhysDiskNum = phys_disk_num; | |
7791 | ||
7792 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
7793 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
7794 | handle, phys_disk_num)); | |
7795 | ||
7796 | init_completion(&ioc->scsih_cmds.done); | |
81c16f83 | 7797 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
7798 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
7799 | ||
7800 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
7801 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
7802 | ioc->name, __func__); | |
7803 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) | |
7804 | issue_reset = 1; | |
7805 | rc = -EFAULT; | |
7806 | goto out; | |
7807 | } | |
7808 | ||
7809 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7810 | ||
7811 | mpi_reply = ioc->scsih_cmds.reply; | |
7812 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
7813 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
7814 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
7815 | else | |
7816 | log_info = 0; | |
7817 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
7818 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7819 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7820 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
7821 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
7822 | log_info)); | |
7823 | rc = -EFAULT; | |
7824 | } else | |
7825 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7826 | "IR RAID_ACTION: completed successfully\n", | |
7827 | ioc->name)); | |
7828 | } | |
7829 | ||
7830 | out: | |
7831 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7832 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7833 | ||
7834 | if (issue_reset) | |
98c56ad3 | 7835 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
7836 | return rc; |
7837 | } | |
7838 | ||
7839 | /** | |
7840 | * _scsih_reprobe_lun - reprobing lun | |
7841 | * @sdev: scsi device struct | |
7842 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
7843 | * | |
7844 | **/ | |
7845 | static void | |
7846 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
7847 | { | |
f92363d1 SR |
7848 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
7849 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 7850 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 7851 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
7852 | } |
7853 | ||
7854 | /** | |
7855 | * _scsih_sas_volume_add - add new volume | |
7856 | * @ioc: per adapter object | |
7857 | * @element: IR config element data | |
7858 | * Context: user. | |
7859 | * | |
7860 | * Return nothing. | |
7861 | */ | |
7862 | static void | |
7863 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
7864 | Mpi2EventIrConfigElement_t *element) | |
7865 | { | |
7866 | struct _raid_device *raid_device; | |
7867 | unsigned long flags; | |
7868 | u64 wwid; | |
7869 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
7870 | int rc; | |
7871 | ||
7872 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7873 | if (!wwid) { | |
7874 | pr_err(MPT3SAS_FMT | |
7875 | "failure at %s:%d/%s()!\n", ioc->name, | |
7876 | __FILE__, __LINE__, __func__); | |
7877 | return; | |
7878 | } | |
7879 | ||
7880 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7881 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
7882 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7883 | ||
7884 | if (raid_device) | |
7885 | return; | |
7886 | ||
7887 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7888 | if (!raid_device) { | |
7889 | pr_err(MPT3SAS_FMT | |
7890 | "failure at %s:%d/%s()!\n", ioc->name, | |
7891 | __FILE__, __LINE__, __func__); | |
7892 | return; | |
7893 | } | |
7894 | ||
7895 | raid_device->id = ioc->sas_id++; | |
7896 | raid_device->channel = RAID_CHANNEL; | |
7897 | raid_device->handle = handle; | |
7898 | raid_device->wwid = wwid; | |
7899 | _scsih_raid_device_add(ioc, raid_device); | |
7900 | if (!ioc->wait_for_discovery_to_complete) { | |
7901 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7902 | raid_device->id, 0); | |
7903 | if (rc) | |
7904 | _scsih_raid_device_remove(ioc, raid_device); | |
7905 | } else { | |
7906 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7907 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
7908 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7909 | } | |
7910 | } | |
7911 | ||
7912 | /** | |
7913 | * _scsih_sas_volume_delete - delete volume | |
7914 | * @ioc: per adapter object | |
7915 | * @handle: volume device handle | |
7916 | * Context: user. | |
7917 | * | |
7918 | * Return nothing. | |
7919 | */ | |
7920 | static void | |
7921 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
7922 | { | |
7923 | struct _raid_device *raid_device; | |
7924 | unsigned long flags; | |
7925 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7926 | struct scsi_target *starget = NULL; | |
7927 | ||
7928 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7929 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7930 | if (raid_device) { |
7931 | if (raid_device->starget) { | |
7932 | starget = raid_device->starget; | |
7933 | sas_target_priv_data = starget->hostdata; | |
7934 | sas_target_priv_data->deleted = 1; | |
7935 | } | |
7936 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
7937 | ioc->name, raid_device->handle, | |
7938 | (unsigned long long) raid_device->wwid); | |
7939 | list_del(&raid_device->list); | |
7940 | kfree(raid_device); | |
7941 | } | |
7942 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7943 | if (starget) | |
7944 | scsi_remove_target(&starget->dev); | |
7945 | } | |
7946 | ||
7947 | /** | |
7948 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
7949 | * @ioc: per adapter object | |
7950 | * @element: IR config element data | |
7951 | * Context: user. | |
7952 | * | |
7953 | * Return nothing. | |
7954 | */ | |
7955 | static void | |
7956 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
7957 | Mpi2EventIrConfigElement_t *element) | |
7958 | { | |
7959 | struct _sas_device *sas_device; | |
7960 | struct scsi_target *starget = NULL; | |
7961 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7962 | unsigned long flags; | |
7963 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
7964 | ||
7965 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 7966 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
7967 | if (sas_device) { |
7968 | sas_device->volume_handle = 0; | |
7969 | sas_device->volume_wwid = 0; | |
7970 | clear_bit(handle, ioc->pd_handles); | |
7971 | if (sas_device->starget && sas_device->starget->hostdata) { | |
7972 | starget = sas_device->starget; | |
7973 | sas_target_priv_data = starget->hostdata; | |
7974 | sas_target_priv_data->flags &= | |
7975 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
7976 | } | |
7977 | } | |
7978 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7979 | if (!sas_device) | |
7980 | return; | |
7981 | ||
7982 | /* exposing raid component */ | |
7983 | if (starget) | |
7984 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
7985 | |
7986 | sas_device_put(sas_device); | |
f92363d1 SR |
7987 | } |
7988 | ||
7989 | /** | |
7990 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
7991 | * @ioc: per adapter object | |
7992 | * @element: IR config element data | |
7993 | * Context: user. | |
7994 | * | |
7995 | * Return nothing. | |
7996 | */ | |
7997 | static void | |
7998 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
7999 | Mpi2EventIrConfigElement_t *element) | |
8000 | { | |
8001 | struct _sas_device *sas_device; | |
8002 | struct scsi_target *starget = NULL; | |
8003 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
8004 | unsigned long flags; | |
8005 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
8006 | u16 volume_handle = 0; | |
8007 | u64 volume_wwid = 0; | |
8008 | ||
8009 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
8010 | if (volume_handle) | |
8011 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
8012 | &volume_wwid); | |
8013 | ||
8014 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 8015 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
8016 | if (sas_device) { |
8017 | set_bit(handle, ioc->pd_handles); | |
8018 | if (sas_device->starget && sas_device->starget->hostdata) { | |
8019 | starget = sas_device->starget; | |
8020 | sas_target_priv_data = starget->hostdata; | |
8021 | sas_target_priv_data->flags |= | |
8022 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
8023 | sas_device->volume_handle = volume_handle; | |
8024 | sas_device->volume_wwid = volume_wwid; | |
8025 | } | |
8026 | } | |
8027 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8028 | if (!sas_device) | |
8029 | return; | |
8030 | ||
8031 | /* hiding raid component */ | |
8032 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 8033 | |
f92363d1 SR |
8034 | if (starget) |
8035 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
8036 | |
8037 | sas_device_put(sas_device); | |
f92363d1 SR |
8038 | } |
8039 | ||
8040 | /** | |
8041 | * _scsih_sas_pd_delete - delete pd component | |
8042 | * @ioc: per adapter object | |
8043 | * @element: IR config element data | |
8044 | * Context: user. | |
8045 | * | |
8046 | * Return nothing. | |
8047 | */ | |
8048 | static void | |
8049 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
8050 | Mpi2EventIrConfigElement_t *element) | |
8051 | { | |
8052 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
8053 | ||
8054 | _scsih_device_remove_by_handle(ioc, handle); | |
8055 | } | |
8056 | ||
8057 | /** | |
8058 | * _scsih_sas_pd_add - remove pd component | |
8059 | * @ioc: per adapter object | |
8060 | * @element: IR config element data | |
8061 | * Context: user. | |
8062 | * | |
8063 | * Return nothing. | |
8064 | */ | |
8065 | static void | |
8066 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
8067 | Mpi2EventIrConfigElement_t *element) | |
8068 | { | |
8069 | struct _sas_device *sas_device; | |
f92363d1 SR |
8070 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
8071 | Mpi2ConfigReply_t mpi_reply; | |
8072 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8073 | u32 ioc_status; | |
8074 | u64 sas_address; | |
8075 | u16 parent_handle; | |
8076 | ||
8077 | set_bit(handle, ioc->pd_handles); | |
8078 | ||
d1cb5e49 | 8079 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
8080 | if (sas_device) { |
8081 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 8082 | sas_device_put(sas_device); |
f92363d1 SR |
8083 | return; |
8084 | } | |
8085 | ||
8086 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
8087 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
8088 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8089 | ioc->name, __FILE__, __LINE__, __func__); | |
8090 | return; | |
8091 | } | |
8092 | ||
8093 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8094 | MPI2_IOCSTATUS_MASK; | |
8095 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8096 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8097 | ioc->name, __FILE__, __LINE__, __func__); | |
8098 | return; | |
8099 | } | |
8100 | ||
8101 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8102 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8103 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8104 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8105 | ||
8106 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
8107 | _scsih_add_device(ioc, handle, 0, 1); | |
8108 | } | |
8109 | ||
f92363d1 SR |
8110 | /** |
8111 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
8112 | * @ioc: per adapter object | |
8113 | * @event_data: event data payload | |
8114 | * Context: user. | |
8115 | * | |
8116 | * Return nothing. | |
8117 | */ | |
8118 | static void | |
8119 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8120 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
8121 | { | |
8122 | Mpi2EventIrConfigElement_t *element; | |
8123 | u8 element_type; | |
8124 | int i; | |
8125 | char *reason_str = NULL, *element_str = NULL; | |
8126 | ||
8127 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
8128 | ||
8129 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
8130 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
8131 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
8132 | "foreign" : "native", event_data->NumElements); | |
8133 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
8134 | switch (element->ReasonCode) { | |
8135 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8136 | reason_str = "add"; | |
8137 | break; | |
8138 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8139 | reason_str = "remove"; | |
8140 | break; | |
8141 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
8142 | reason_str = "no change"; | |
8143 | break; | |
8144 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
8145 | reason_str = "hide"; | |
8146 | break; | |
8147 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
8148 | reason_str = "unhide"; | |
8149 | break; | |
8150 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8151 | reason_str = "volume_created"; | |
8152 | break; | |
8153 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8154 | reason_str = "volume_deleted"; | |
8155 | break; | |
8156 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
8157 | reason_str = "pd_created"; | |
8158 | break; | |
8159 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
8160 | reason_str = "pd_deleted"; | |
8161 | break; | |
8162 | default: | |
8163 | reason_str = "unknown reason"; | |
8164 | break; | |
8165 | } | |
8166 | element_type = le16_to_cpu(element->ElementFlags) & | |
8167 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
8168 | switch (element_type) { | |
8169 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
8170 | element_str = "volume"; | |
8171 | break; | |
8172 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
8173 | element_str = "phys disk"; | |
8174 | break; | |
8175 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
8176 | element_str = "hot spare"; | |
8177 | break; | |
8178 | default: | |
8179 | element_str = "unknown element"; | |
8180 | break; | |
8181 | } | |
8182 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
8183 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
8184 | reason_str, le16_to_cpu(element->VolDevHandle), | |
8185 | le16_to_cpu(element->PhysDiskDevHandle), | |
8186 | element->PhysDiskNum); | |
8187 | } | |
8188 | } | |
f92363d1 SR |
8189 | |
8190 | /** | |
8191 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
8192 | * @ioc: per adapter object | |
8193 | * @fw_event: The fw_event_work object | |
8194 | * Context: user. | |
8195 | * | |
8196 | * Return nothing. | |
8197 | */ | |
8198 | static void | |
8199 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
8200 | struct fw_event_work *fw_event) | |
8201 | { | |
8202 | Mpi2EventIrConfigElement_t *element; | |
8203 | int i; | |
8204 | u8 foreign_config; | |
35b62362 JL |
8205 | Mpi2EventDataIrConfigChangeList_t *event_data = |
8206 | (Mpi2EventDataIrConfigChangeList_t *) | |
8207 | fw_event->event_data; | |
f92363d1 | 8208 | |
7786ab6a SR |
8209 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8210 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8211 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
8212 | ||
f92363d1 SR |
8213 | foreign_config = (le32_to_cpu(event_data->Flags) & |
8214 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
8215 | ||
8216 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
8217 | if (ioc->shost_recovery && |
8218 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
8219 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8220 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
8221 | _scsih_ir_fastpath(ioc, | |
8222 | le16_to_cpu(element->PhysDiskDevHandle), | |
8223 | element->PhysDiskNum); | |
8224 | } | |
8225 | return; | |
8226 | } | |
7786ab6a | 8227 | |
f92363d1 SR |
8228 | for (i = 0; i < event_data->NumElements; i++, element++) { |
8229 | ||
8230 | switch (element->ReasonCode) { | |
8231 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
8232 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
8233 | if (!foreign_config) | |
8234 | _scsih_sas_volume_add(ioc, element); | |
8235 | break; | |
8236 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
8237 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
8238 | if (!foreign_config) | |
8239 | _scsih_sas_volume_delete(ioc, | |
8240 | le16_to_cpu(element->VolDevHandle)); | |
8241 | break; | |
8242 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
8243 | if (!ioc->is_warpdrive) |
8244 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
8245 | break; |
8246 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
8247 | if (!ioc->is_warpdrive) |
8248 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
8249 | break; |
8250 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
8251 | if (!ioc->is_warpdrive) |
8252 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
8253 | break; |
8254 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
8255 | if (!ioc->is_warpdrive) |
8256 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
8257 | break; |
8258 | } | |
8259 | } | |
8260 | } | |
8261 | ||
8262 | /** | |
8263 | * _scsih_sas_ir_volume_event - IR volume event | |
8264 | * @ioc: per adapter object | |
8265 | * @fw_event: The fw_event_work object | |
8266 | * Context: user. | |
8267 | * | |
8268 | * Return nothing. | |
8269 | */ | |
8270 | static void | |
8271 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
8272 | struct fw_event_work *fw_event) | |
8273 | { | |
8274 | u64 wwid; | |
8275 | unsigned long flags; | |
8276 | struct _raid_device *raid_device; | |
8277 | u16 handle; | |
8278 | u32 state; | |
8279 | int rc; | |
35b62362 JL |
8280 | Mpi2EventDataIrVolume_t *event_data = |
8281 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
8282 | |
8283 | if (ioc->shost_recovery) | |
8284 | return; | |
8285 | ||
8286 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
8287 | return; | |
8288 | ||
8289 | handle = le16_to_cpu(event_data->VolDevHandle); | |
8290 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a SR |
8291 | if (!ioc->hide_ir_msg) |
8292 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8293 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8294 | ioc->name, __func__, handle, | |
8295 | le32_to_cpu(event_data->PreviousValue), state)); | |
f92363d1 SR |
8296 | switch (state) { |
8297 | case MPI2_RAID_VOL_STATE_MISSING: | |
8298 | case MPI2_RAID_VOL_STATE_FAILED: | |
8299 | _scsih_sas_volume_delete(ioc, handle); | |
8300 | break; | |
8301 | ||
8302 | case MPI2_RAID_VOL_STATE_ONLINE: | |
8303 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
8304 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
8305 | ||
8306 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 8307 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8308 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
8309 | ||
8310 | if (raid_device) | |
8311 | break; | |
8312 | ||
8313 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
8314 | if (!wwid) { | |
8315 | pr_err(MPT3SAS_FMT | |
8316 | "failure at %s:%d/%s()!\n", ioc->name, | |
8317 | __FILE__, __LINE__, __func__); | |
8318 | break; | |
8319 | } | |
8320 | ||
8321 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
8322 | if (!raid_device) { | |
8323 | pr_err(MPT3SAS_FMT | |
8324 | "failure at %s:%d/%s()!\n", ioc->name, | |
8325 | __FILE__, __LINE__, __func__); | |
8326 | break; | |
8327 | } | |
8328 | ||
8329 | raid_device->id = ioc->sas_id++; | |
8330 | raid_device->channel = RAID_CHANNEL; | |
8331 | raid_device->handle = handle; | |
8332 | raid_device->wwid = wwid; | |
8333 | _scsih_raid_device_add(ioc, raid_device); | |
8334 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8335 | raid_device->id, 0); | |
8336 | if (rc) | |
8337 | _scsih_raid_device_remove(ioc, raid_device); | |
8338 | break; | |
8339 | ||
8340 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
8341 | default: | |
8342 | break; | |
8343 | } | |
8344 | } | |
8345 | ||
8346 | /** | |
8347 | * _scsih_sas_ir_physical_disk_event - PD event | |
8348 | * @ioc: per adapter object | |
8349 | * @fw_event: The fw_event_work object | |
8350 | * Context: user. | |
8351 | * | |
8352 | * Return nothing. | |
8353 | */ | |
8354 | static void | |
8355 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
8356 | struct fw_event_work *fw_event) | |
8357 | { | |
8358 | u16 handle, parent_handle; | |
8359 | u32 state; | |
8360 | struct _sas_device *sas_device; | |
f92363d1 SR |
8361 | Mpi2ConfigReply_t mpi_reply; |
8362 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8363 | u32 ioc_status; | |
35b62362 JL |
8364 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
8365 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
8366 | u64 sas_address; |
8367 | ||
8368 | if (ioc->shost_recovery) | |
8369 | return; | |
8370 | ||
8371 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
8372 | return; | |
8373 | ||
8374 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
8375 | state = le32_to_cpu(event_data->NewValue); | |
8376 | ||
7786ab6a SR |
8377 | if (!ioc->hide_ir_msg) |
8378 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8379 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
8380 | ioc->name, __func__, handle, | |
f92363d1 | 8381 | le32_to_cpu(event_data->PreviousValue), state)); |
7786ab6a | 8382 | |
f92363d1 SR |
8383 | switch (state) { |
8384 | case MPI2_RAID_PD_STATE_ONLINE: | |
8385 | case MPI2_RAID_PD_STATE_DEGRADED: | |
8386 | case MPI2_RAID_PD_STATE_REBUILDING: | |
8387 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
8388 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
8389 | ||
7786ab6a SR |
8390 | if (!ioc->is_warpdrive) |
8391 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 8392 | |
d1cb5e49 SR |
8393 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
8394 | if (sas_device) { | |
8395 | sas_device_put(sas_device); | |
f92363d1 | 8396 | return; |
d1cb5e49 | 8397 | } |
f92363d1 SR |
8398 | |
8399 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8400 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
8401 | handle))) { | |
8402 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8403 | ioc->name, __FILE__, __LINE__, __func__); | |
8404 | return; | |
8405 | } | |
8406 | ||
8407 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8408 | MPI2_IOCSTATUS_MASK; | |
8409 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8410 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
8411 | ioc->name, __FILE__, __LINE__, __func__); | |
8412 | return; | |
8413 | } | |
8414 | ||
8415 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
8416 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
8417 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8418 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8419 | ||
8420 | _scsih_add_device(ioc, handle, 0, 1); | |
8421 | ||
8422 | break; | |
8423 | ||
8424 | case MPI2_RAID_PD_STATE_OFFLINE: | |
8425 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
8426 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
8427 | default: | |
8428 | break; | |
8429 | } | |
8430 | } | |
8431 | ||
f92363d1 SR |
8432 | /** |
8433 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
8434 | * @ioc: per adapter object | |
8435 | * @event_data: event data payload | |
8436 | * Context: user. | |
8437 | * | |
8438 | * Return nothing. | |
8439 | */ | |
8440 | static void | |
8441 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
8442 | Mpi2EventDataIrOperationStatus_t *event_data) | |
8443 | { | |
8444 | char *reason_str = NULL; | |
8445 | ||
8446 | switch (event_data->RAIDOperation) { | |
8447 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
8448 | reason_str = "resync"; | |
8449 | break; | |
8450 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
8451 | reason_str = "online capacity expansion"; | |
8452 | break; | |
8453 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
8454 | reason_str = "consistency check"; | |
8455 | break; | |
8456 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
8457 | reason_str = "background init"; | |
8458 | break; | |
8459 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
8460 | reason_str = "make data consistent"; | |
8461 | break; | |
8462 | } | |
8463 | ||
8464 | if (!reason_str) | |
8465 | return; | |
8466 | ||
8467 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
8468 | "\thandle(0x%04x), percent complete(%d)\n", | |
8469 | ioc->name, reason_str, | |
8470 | le16_to_cpu(event_data->VolDevHandle), | |
8471 | event_data->PercentComplete); | |
8472 | } | |
f92363d1 SR |
8473 | |
8474 | /** | |
8475 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
8476 | * @ioc: per adapter object | |
8477 | * @fw_event: The fw_event_work object | |
8478 | * Context: user. | |
8479 | * | |
8480 | * Return nothing. | |
8481 | */ | |
8482 | static void | |
8483 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
8484 | struct fw_event_work *fw_event) | |
8485 | { | |
35b62362 JL |
8486 | Mpi2EventDataIrOperationStatus_t *event_data = |
8487 | (Mpi2EventDataIrOperationStatus_t *) | |
8488 | fw_event->event_data; | |
f92363d1 SR |
8489 | static struct _raid_device *raid_device; |
8490 | unsigned long flags; | |
8491 | u16 handle; | |
8492 | ||
7786ab6a SR |
8493 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
8494 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
8495 | _scsih_sas_ir_operation_status_event_debug(ioc, |
8496 | event_data); | |
f92363d1 SR |
8497 | |
8498 | /* code added for raid transport support */ | |
8499 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
8500 | ||
8501 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8502 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 8503 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
8504 | if (raid_device) |
8505 | raid_device->percent_complete = | |
8506 | event_data->PercentComplete; | |
8507 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8508 | } | |
8509 | } | |
8510 | ||
8511 | /** | |
8512 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
8513 | * @ioc: per adapter object | |
8514 | * | |
8515 | * Set the deleted flag prior to device scan. If the device is found during | |
8516 | * the scan, then we clear the deleted flag. | |
8517 | */ | |
8518 | static void | |
8519 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
8520 | { | |
8521 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
8522 | struct scsi_device *sdev; | |
8523 | ||
8524 | shost_for_each_device(sdev, ioc->shost) { | |
8525 | sas_device_priv_data = sdev->hostdata; | |
8526 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
8527 | sas_device_priv_data->sas_target->deleted = 1; | |
8528 | } | |
8529 | } | |
8530 | ||
8531 | /** | |
8532 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
8533 | * @ioc: per adapter object | |
e6d45e3e | 8534 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
8535 | * |
8536 | * After host reset, find out whether devices are still responding. | |
8537 | * Used in _scsih_remove_unresponsive_sas_devices. | |
8538 | * | |
8539 | * Return nothing. | |
8540 | */ | |
8541 | static void | |
e6d45e3e SR |
8542 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
8543 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
8544 | { |
8545 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8546 | struct scsi_target *starget; | |
aba5a85c | 8547 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
8548 | unsigned long flags; |
8549 | ||
8550 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
8551 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
e6d45e3e SR |
8552 | if ((sas_device->sas_address == sas_device_pg0->SASAddress) && |
8553 | (sas_device->slot == sas_device_pg0->Slot)) { | |
f92363d1 SR |
8554 | sas_device->responding = 1; |
8555 | starget = sas_device->starget; | |
8556 | if (starget && starget->hostdata) { | |
8557 | sas_target_priv_data = starget->hostdata; | |
8558 | sas_target_priv_data->tm_busy = 0; | |
8559 | sas_target_priv_data->deleted = 0; | |
8560 | } else | |
8561 | sas_target_priv_data = NULL; | |
e6d45e3e | 8562 | if (starget) { |
f92363d1 | 8563 | starget_printk(KERN_INFO, starget, |
e6d45e3e SR |
8564 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
8565 | sas_device_pg0->DevHandle, | |
f92363d1 | 8566 | (unsigned long long) |
e6d45e3e SR |
8567 | sas_device->sas_address); |
8568 | ||
8569 | if (sas_device->enclosure_handle != 0) | |
8570 | starget_printk(KERN_INFO, starget, | |
8571 | "enclosure logical id(0x%016llx)," | |
8572 | " slot(%d)\n", | |
8573 | (unsigned long long) | |
8574 | sas_device->enclosure_logical_id, | |
8575 | sas_device->slot); | |
8576 | } | |
8577 | if (sas_device_pg0->Flags & | |
8578 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
8579 | sas_device->enclosure_level = | |
aa53bb89 | 8580 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
8581 | memcpy(&sas_device->connector_name[0], |
8582 | &sas_device_pg0->ConnectorName[0], 4); | |
8583 | } else { | |
8584 | sas_device->enclosure_level = 0; | |
8585 | sas_device->connector_name[0] = '\0'; | |
8586 | } | |
8587 | ||
aba5a85c SR |
8588 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, |
8589 | sas_device_pg0, sas_device); | |
75888956 | 8590 | |
e6d45e3e | 8591 | if (sas_device->handle == sas_device_pg0->DevHandle) |
f92363d1 SR |
8592 | goto out; |
8593 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8594 | sas_device->handle); | |
e6d45e3e | 8595 | sas_device->handle = sas_device_pg0->DevHandle; |
f92363d1 | 8596 | if (sas_target_priv_data) |
e6d45e3e SR |
8597 | sas_target_priv_data->handle = |
8598 | sas_device_pg0->DevHandle; | |
f92363d1 SR |
8599 | goto out; |
8600 | } | |
8601 | } | |
8602 | out: | |
8603 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8604 | } | |
8605 | ||
8606 | /** | |
8607 | * _scsih_search_responding_sas_devices - | |
8608 | * @ioc: per adapter object | |
8609 | * | |
8610 | * After host reset, find out whether devices are still responding. | |
8611 | * If not remove. | |
8612 | * | |
8613 | * Return nothing. | |
8614 | */ | |
8615 | static void | |
8616 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
8617 | { | |
8618 | Mpi2SasDevicePage0_t sas_device_pg0; | |
8619 | Mpi2ConfigReply_t mpi_reply; | |
8620 | u16 ioc_status; | |
8621 | u16 handle; | |
8622 | u32 device_info; | |
8623 | ||
8624 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8625 | ||
8626 | if (list_empty(&ioc->sas_device_list)) | |
8627 | goto out; | |
8628 | ||
8629 | handle = 0xFFFF; | |
8630 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8631 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8632 | handle))) { | |
8633 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8634 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8635 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 8636 | break; |
e6d45e3e SR |
8637 | handle = sas_device_pg0.DevHandle = |
8638 | le16_to_cpu(sas_device_pg0.DevHandle); | |
f92363d1 SR |
8639 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
8640 | if (!(_scsih_is_end_device(device_info))) | |
8641 | continue; | |
e6d45e3e SR |
8642 | sas_device_pg0.SASAddress = |
8643 | le64_to_cpu(sas_device_pg0.SASAddress); | |
8644 | sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot); | |
aa53bb89 | 8645 | sas_device_pg0.Flags = le16_to_cpu(sas_device_pg0.Flags); |
e6d45e3e | 8646 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
8647 | } |
8648 | ||
8649 | out: | |
8650 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
8651 | ioc->name); | |
8652 | } | |
8653 | ||
ec051e5a SPS |
8654 | /** |
8655 | * _scsih_mark_responding_pcie_device - mark a pcie_device as responding | |
8656 | * @ioc: per adapter object | |
8657 | * @pcie_device_pg0: PCIe Device page 0 | |
8658 | * | |
8659 | * After host reset, find out whether devices are still responding. | |
8660 | * Used in _scsih_remove_unresponding_devices. | |
8661 | * | |
8662 | * Return nothing. | |
8663 | */ | |
8664 | static void | |
8665 | _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc, | |
8666 | Mpi26PCIeDevicePage0_t *pcie_device_pg0) | |
8667 | { | |
8668 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
8669 | struct scsi_target *starget; | |
8670 | struct _pcie_device *pcie_device; | |
8671 | unsigned long flags; | |
8672 | ||
8673 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8674 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { | |
8675 | if ((pcie_device->wwid == pcie_device_pg0->WWID) && | |
8676 | (pcie_device->slot == pcie_device_pg0->Slot)) { | |
8677 | pcie_device->responding = 1; | |
8678 | starget = pcie_device->starget; | |
8679 | if (starget && starget->hostdata) { | |
8680 | sas_target_priv_data = starget->hostdata; | |
8681 | sas_target_priv_data->tm_busy = 0; | |
8682 | sas_target_priv_data->deleted = 0; | |
8683 | } else | |
8684 | sas_target_priv_data = NULL; | |
8685 | if (starget) { | |
8686 | starget_printk(KERN_INFO, starget, | |
8687 | "handle(0x%04x), wwid(0x%016llx) ", | |
8688 | pcie_device->handle, | |
8689 | (unsigned long long)pcie_device->wwid); | |
8690 | if (pcie_device->enclosure_handle != 0) | |
8691 | starget_printk(KERN_INFO, starget, | |
8692 | "enclosure logical id(0x%016llx), " | |
8693 | "slot(%d)\n", | |
8694 | (unsigned long long) | |
8695 | pcie_device->enclosure_logical_id, | |
8696 | pcie_device->slot); | |
8697 | } | |
8698 | ||
8699 | if (((le32_to_cpu(pcie_device_pg0->Flags)) & | |
8700 | MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) && | |
8701 | (ioc->hba_mpi_version_belonged != MPI2_VERSION)) { | |
8702 | pcie_device->enclosure_level = | |
8703 | pcie_device_pg0->EnclosureLevel; | |
8704 | memcpy(&pcie_device->connector_name[0], | |
8705 | &pcie_device_pg0->ConnectorName[0], 4); | |
8706 | } else { | |
8707 | pcie_device->enclosure_level = 0; | |
8708 | pcie_device->connector_name[0] = '\0'; | |
8709 | } | |
8710 | ||
8711 | if (pcie_device->handle == pcie_device_pg0->DevHandle) | |
8712 | goto out; | |
8713 | pr_info(KERN_INFO "\thandle changed from(0x%04x)!!!\n", | |
8714 | pcie_device->handle); | |
8715 | pcie_device->handle = pcie_device_pg0->DevHandle; | |
8716 | if (sas_target_priv_data) | |
8717 | sas_target_priv_data->handle = | |
8718 | pcie_device_pg0->DevHandle; | |
8719 | goto out; | |
8720 | } | |
8721 | } | |
8722 | ||
8723 | out: | |
8724 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8725 | } | |
8726 | ||
8727 | /** | |
8728 | * _scsih_search_responding_pcie_devices - | |
8729 | * @ioc: per adapter object | |
8730 | * | |
8731 | * After host reset, find out whether devices are still responding. | |
8732 | * If not remove. | |
8733 | * | |
8734 | * Return nothing. | |
8735 | */ | |
8736 | static void | |
8737 | _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc) | |
8738 | { | |
8739 | Mpi26PCIeDevicePage0_t pcie_device_pg0; | |
8740 | Mpi2ConfigReply_t mpi_reply; | |
8741 | u16 ioc_status; | |
8742 | u16 handle; | |
8743 | u32 device_info; | |
8744 | ||
8745 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
8746 | ||
8747 | if (list_empty(&ioc->pcie_device_list)) | |
8748 | goto out; | |
8749 | ||
8750 | handle = 0xFFFF; | |
8751 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
8752 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8753 | handle))) { | |
8754 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8755 | MPI2_IOCSTATUS_MASK; | |
8756 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8757 | pr_info(MPT3SAS_FMT "\tbreak from %s: " | |
8758 | "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc->name, | |
8759 | __func__, ioc_status, | |
8760 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
8761 | break; | |
8762 | } | |
8763 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
8764 | device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo); | |
8765 | if (!(_scsih_is_nvme_device(device_info))) | |
8766 | continue; | |
8767 | pcie_device_pg0.WWID = le64_to_cpu(pcie_device_pg0.WWID), | |
8768 | pcie_device_pg0.Slot = le16_to_cpu(pcie_device_pg0.Slot); | |
8769 | pcie_device_pg0.Flags = le32_to_cpu(pcie_device_pg0.Flags); | |
8770 | pcie_device_pg0.DevHandle = handle; | |
8771 | _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0); | |
8772 | } | |
8773 | out: | |
8774 | pr_info(MPT3SAS_FMT "search for PCIe end-devices: complete\n", | |
8775 | ioc->name); | |
8776 | } | |
8777 | ||
f92363d1 SR |
8778 | /** |
8779 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
8780 | * @ioc: per adapter object | |
8781 | * @wwid: world wide identifier for raid volume | |
8782 | * @handle: device handle | |
8783 | * | |
8784 | * After host reset, find out whether devices are still responding. | |
8785 | * Used in _scsih_remove_unresponsive_raid_devices. | |
8786 | * | |
8787 | * Return nothing. | |
8788 | */ | |
8789 | static void | |
8790 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
8791 | u16 handle) | |
8792 | { | |
7786ab6a | 8793 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
8794 | struct scsi_target *starget; |
8795 | struct _raid_device *raid_device; | |
8796 | unsigned long flags; | |
8797 | ||
8798 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
8799 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
8800 | if (raid_device->wwid == wwid && raid_device->starget) { | |
8801 | starget = raid_device->starget; | |
8802 | if (starget && starget->hostdata) { | |
8803 | sas_target_priv_data = starget->hostdata; | |
8804 | sas_target_priv_data->deleted = 0; | |
8805 | } else | |
8806 | sas_target_priv_data = NULL; | |
8807 | raid_device->responding = 1; | |
8808 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8809 | starget_printk(KERN_INFO, raid_device->starget, | |
8810 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
8811 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 8812 | |
7786ab6a SR |
8813 | /* |
8814 | * WARPDRIVE: The handles of the PDs might have changed | |
8815 | * across the host reset so re-initialize the | |
8816 | * required data for Direct IO | |
8817 | */ | |
c84b06a4 | 8818 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
8819 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
8820 | if (raid_device->handle == handle) { | |
8821 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
8822 | flags); | |
8823 | return; | |
8824 | } | |
8825 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
8826 | raid_device->handle); | |
8827 | raid_device->handle = handle; | |
8828 | if (sas_target_priv_data) | |
8829 | sas_target_priv_data->handle = handle; | |
8830 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8831 | return; | |
8832 | } | |
8833 | } | |
8834 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
8835 | } | |
8836 | ||
8837 | /** | |
8838 | * _scsih_search_responding_raid_devices - | |
8839 | * @ioc: per adapter object | |
8840 | * | |
8841 | * After host reset, find out whether devices are still responding. | |
8842 | * If not remove. | |
8843 | * | |
8844 | * Return nothing. | |
8845 | */ | |
8846 | static void | |
8847 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
8848 | { | |
8849 | Mpi2RaidVolPage1_t volume_pg1; | |
8850 | Mpi2RaidVolPage0_t volume_pg0; | |
8851 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
8852 | Mpi2ConfigReply_t mpi_reply; | |
8853 | u16 ioc_status; | |
8854 | u16 handle; | |
8855 | u8 phys_disk_num; | |
8856 | ||
8857 | if (!ioc->ir_firmware) | |
8858 | return; | |
8859 | ||
8860 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
8861 | ioc->name); | |
8862 | ||
8863 | if (list_empty(&ioc->raid_device_list)) | |
8864 | goto out; | |
8865 | ||
8866 | handle = 0xFFFF; | |
8867 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
8868 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
8869 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8870 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8871 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8872 | break; |
8873 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
8874 | ||
8875 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8876 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8877 | sizeof(Mpi2RaidVolPage0_t))) | |
8878 | continue; | |
8879 | ||
8880 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8881 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8882 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
8883 | _scsih_mark_responding_raid_device(ioc, | |
8884 | le64_to_cpu(volume_pg1.WWID), handle); | |
8885 | } | |
8886 | ||
8887 | /* refresh the pd_handles */ | |
7786ab6a | 8888 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
8889 | phys_disk_num = 0xFF; |
8890 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
8891 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
8892 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
8893 | phys_disk_num))) { | |
8894 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8895 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8896 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8897 | break; |
8898 | phys_disk_num = pd_pg0.PhysDiskNum; | |
8899 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
8900 | set_bit(handle, ioc->pd_handles); | |
8901 | } | |
7786ab6a | 8902 | } |
f92363d1 SR |
8903 | out: |
8904 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
8905 | ioc->name); | |
8906 | } | |
8907 | ||
8908 | /** | |
8909 | * _scsih_mark_responding_expander - mark a expander as responding | |
8910 | * @ioc: per adapter object | |
aba5a85c | 8911 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
8912 | * |
8913 | * After host reset, find out whether devices are still responding. | |
8914 | * Used in _scsih_remove_unresponsive_expanders. | |
8915 | * | |
8916 | * Return nothing. | |
8917 | */ | |
8918 | static void | |
aba5a85c SR |
8919 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
8920 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 8921 | { |
aba5a85c | 8922 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 8923 | unsigned long flags; |
aba5a85c SR |
8924 | int i, encl_pg0_rc = -1; |
8925 | Mpi2ConfigReply_t mpi_reply; | |
8926 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
8927 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); | |
8928 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); | |
8929 | ||
8930 | if (le16_to_cpu(expander_pg0->EnclosureHandle)) { | |
8931 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
8932 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
8933 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
8934 | if (encl_pg0_rc) | |
8935 | pr_info(MPT3SAS_FMT | |
8936 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
8937 | ioc->name, | |
8938 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
8939 | } | |
f92363d1 SR |
8940 | |
8941 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
8942 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
8943 | if (sas_expander->sas_address != sas_address) | |
8944 | continue; | |
8945 | sas_expander->responding = 1; | |
aba5a85c SR |
8946 | |
8947 | if (!encl_pg0_rc) | |
8948 | sas_expander->enclosure_logical_id = | |
8949 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
8950 | ||
8951 | sas_expander->enclosure_handle = | |
8952 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
8953 | ||
f92363d1 SR |
8954 | if (sas_expander->handle == handle) |
8955 | goto out; | |
8956 | pr_info("\texpander(0x%016llx): handle changed" \ | |
8957 | " from(0x%04x) to (0x%04x)!!!\n", | |
8958 | (unsigned long long)sas_expander->sas_address, | |
8959 | sas_expander->handle, handle); | |
8960 | sas_expander->handle = handle; | |
8961 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
8962 | sas_expander->phy[i].handle = handle; | |
8963 | goto out; | |
8964 | } | |
8965 | out: | |
8966 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8967 | } | |
8968 | ||
8969 | /** | |
8970 | * _scsih_search_responding_expanders - | |
8971 | * @ioc: per adapter object | |
8972 | * | |
8973 | * After host reset, find out whether devices are still responding. | |
8974 | * If not remove. | |
8975 | * | |
8976 | * Return nothing. | |
8977 | */ | |
8978 | static void | |
8979 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
8980 | { | |
8981 | Mpi2ExpanderPage0_t expander_pg0; | |
8982 | Mpi2ConfigReply_t mpi_reply; | |
8983 | u16 ioc_status; | |
8984 | u64 sas_address; | |
8985 | u16 handle; | |
8986 | ||
8987 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
8988 | ||
8989 | if (list_empty(&ioc->sas_expander_list)) | |
8990 | goto out; | |
8991 | ||
8992 | handle = 0xFFFF; | |
8993 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
8994 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
8995 | ||
8996 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8997 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 8998 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
8999 | break; |
9000 | ||
9001 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9002 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
9003 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
9004 | handle, | |
9005 | (unsigned long long)sas_address); | |
aba5a85c | 9006 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
9007 | } |
9008 | ||
9009 | out: | |
9010 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
9011 | } | |
9012 | ||
9013 | /** | |
3075ac49 | 9014 | * _scsih_remove_unresponding_devices - removing unresponding devices |
f92363d1 SR |
9015 | * @ioc: per adapter object |
9016 | * | |
9017 | * Return nothing. | |
9018 | */ | |
9019 | static void | |
3075ac49 | 9020 | _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc) |
f92363d1 SR |
9021 | { |
9022 | struct _sas_device *sas_device, *sas_device_next; | |
9023 | struct _sas_node *sas_expander, *sas_expander_next; | |
9024 | struct _raid_device *raid_device, *raid_device_next; | |
3075ac49 | 9025 | struct _pcie_device *pcie_device, *pcie_device_next; |
f92363d1 SR |
9026 | struct list_head tmp_list; |
9027 | unsigned long flags; | |
d1cb5e49 | 9028 | LIST_HEAD(head); |
f92363d1 SR |
9029 | |
9030 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
9031 | ioc->name); | |
9032 | ||
9033 | /* removing unresponding end devices */ | |
9034 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
9035 | ioc->name); | |
d1cb5e49 SR |
9036 | /* |
9037 | * Iterate, pulling off devices marked as non-responding. We become the | |
9038 | * owner for the reference the list had on any object we prune. | |
9039 | */ | |
9040 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
9041 | list_for_each_entry_safe(sas_device, sas_device_next, |
9042 | &ioc->sas_device_list, list) { | |
9043 | if (!sas_device->responding) | |
d1cb5e49 | 9044 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
9045 | else |
9046 | sas_device->responding = 0; | |
9047 | } | |
d1cb5e49 SR |
9048 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
9049 | ||
9050 | /* | |
9051 | * Now, uninitialize and remove the unresponding devices we pruned. | |
9052 | */ | |
9053 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
9054 | _scsih_remove_device(ioc, sas_device); | |
9055 | list_del_init(&sas_device->list); | |
9056 | sas_device_put(sas_device); | |
9057 | } | |
f92363d1 | 9058 | |
3075ac49 SPS |
9059 | pr_info(MPT3SAS_FMT |
9060 | " Removing unresponding devices: pcie end-devices\n" | |
9061 | , ioc->name); | |
9062 | INIT_LIST_HEAD(&head); | |
9063 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
9064 | list_for_each_entry_safe(pcie_device, pcie_device_next, | |
9065 | &ioc->pcie_device_list, list) { | |
9066 | if (!pcie_device->responding) | |
9067 | list_move_tail(&pcie_device->list, &head); | |
9068 | else | |
9069 | pcie_device->responding = 0; | |
9070 | } | |
9071 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
9072 | ||
9073 | list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) { | |
9074 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9075 | list_del_init(&pcie_device->list); | |
9076 | pcie_device_put(pcie_device); | |
9077 | } | |
9078 | ||
f92363d1 SR |
9079 | /* removing unresponding volumes */ |
9080 | if (ioc->ir_firmware) { | |
9081 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
9082 | ioc->name); | |
9083 | list_for_each_entry_safe(raid_device, raid_device_next, | |
9084 | &ioc->raid_device_list, list) { | |
9085 | if (!raid_device->responding) | |
9086 | _scsih_sas_volume_delete(ioc, | |
9087 | raid_device->handle); | |
9088 | else | |
9089 | raid_device->responding = 0; | |
9090 | } | |
9091 | } | |
9092 | ||
9093 | /* removing unresponding expanders */ | |
9094 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
9095 | ioc->name); | |
9096 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9097 | INIT_LIST_HEAD(&tmp_list); | |
9098 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
9099 | &ioc->sas_expander_list, list) { | |
9100 | if (!sas_expander->responding) | |
9101 | list_move_tail(&sas_expander->list, &tmp_list); | |
9102 | else | |
9103 | sas_expander->responding = 0; | |
9104 | } | |
9105 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9106 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
9107 | list) { | |
f92363d1 SR |
9108 | _scsih_expander_node_remove(ioc, sas_expander); |
9109 | } | |
9110 | ||
9111 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
9112 | ioc->name); | |
9113 | ||
9114 | /* unblock devices */ | |
9115 | _scsih_ublock_io_all_device(ioc); | |
9116 | } | |
9117 | ||
9118 | static void | |
9119 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
9120 | struct _sas_node *sas_expander, u16 handle) | |
9121 | { | |
9122 | Mpi2ExpanderPage1_t expander_pg1; | |
9123 | Mpi2ConfigReply_t mpi_reply; | |
9124 | int i; | |
9125 | ||
9126 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
9127 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
9128 | &expander_pg1, i, handle))) { | |
9129 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
9130 | ioc->name, __FILE__, __LINE__, __func__); | |
9131 | return; | |
9132 | } | |
9133 | ||
9134 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
9135 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
9136 | expander_pg1.NegotiatedLinkRate >> 4); | |
9137 | } | |
9138 | } | |
9139 | ||
9140 | /** | |
9141 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
9142 | * @ioc: per adapter object | |
9143 | * | |
9144 | * Return nothing. | |
9145 | */ | |
9146 | static void | |
9147 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
9148 | { | |
9149 | Mpi2ExpanderPage0_t expander_pg0; | |
9150 | Mpi2SasDevicePage0_t sas_device_pg0; | |
ec051e5a | 9151 | Mpi26PCIeDevicePage0_t pcie_device_pg0; |
f92363d1 SR |
9152 | Mpi2RaidVolPage1_t volume_pg1; |
9153 | Mpi2RaidVolPage0_t volume_pg0; | |
9154 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
9155 | Mpi2EventIrConfigElement_t element; | |
9156 | Mpi2ConfigReply_t mpi_reply; | |
9157 | u8 phys_disk_num; | |
9158 | u16 ioc_status; | |
9159 | u16 handle, parent_handle; | |
9160 | u64 sas_address; | |
9161 | struct _sas_device *sas_device; | |
ec051e5a | 9162 | struct _pcie_device *pcie_device; |
f92363d1 SR |
9163 | struct _sas_node *expander_device; |
9164 | static struct _raid_device *raid_device; | |
9165 | u8 retry_count; | |
9166 | unsigned long flags; | |
9167 | ||
9168 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
9169 | ||
9170 | _scsih_sas_host_refresh(ioc); | |
9171 | ||
9172 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
9173 | ||
9174 | /* expanders */ | |
9175 | handle = 0xFFFF; | |
9176 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
9177 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
9178 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9179 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9180 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9181 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
9182 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9183 | ioc->name, ioc_status, | |
9184 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9185 | break; | |
9186 | } | |
9187 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
9188 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
9189 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
9190 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
9191 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9192 | if (expander_device) | |
9193 | _scsih_refresh_expander_links(ioc, expander_device, | |
9194 | handle); | |
9195 | else { | |
9196 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
9197 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9198 | handle, (unsigned long long) | |
9199 | le64_to_cpu(expander_pg0.SASAddress)); | |
9200 | _scsih_expander_add(ioc, handle); | |
9201 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
9202 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9203 | handle, (unsigned long long) | |
9204 | le64_to_cpu(expander_pg0.SASAddress)); | |
9205 | } | |
9206 | } | |
9207 | ||
9208 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
9209 | ioc->name); | |
9210 | ||
9211 | if (!ioc->ir_firmware) | |
9212 | goto skip_to_sas; | |
9213 | ||
9214 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
9215 | ||
9216 | /* phys disk */ | |
9217 | phys_disk_num = 0xFF; | |
9218 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
9219 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
9220 | phys_disk_num))) { | |
9221 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9222 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9223 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9224 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
9225 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9226 | ioc->name, ioc_status, | |
9227 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9228 | break; | |
9229 | } | |
9230 | phys_disk_num = pd_pg0.PhysDiskNum; | |
9231 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
9232 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
9233 | if (sas_device) { | |
9234 | sas_device_put(sas_device); | |
f92363d1 | 9235 | continue; |
d1cb5e49 | 9236 | } |
f92363d1 SR |
9237 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
9238 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
9239 | handle) != 0) | |
9240 | continue; | |
9241 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9242 | MPI2_IOCSTATUS_MASK; | |
9243 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9244 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
9245 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9246 | ioc->name, ioc_status, | |
9247 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9248 | break; | |
9249 | } | |
9250 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
9251 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
9252 | &sas_address)) { | |
9253 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
9254 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9255 | ioc->name, handle, (unsigned long long) | |
9256 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9257 | mpt3sas_transport_update_links(ioc, sas_address, | |
9258 | handle, sas_device_pg0.PhyNum, | |
9259 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
9260 | set_bit(handle, ioc->pd_handles); | |
9261 | retry_count = 0; | |
9262 | /* This will retry adding the end device. | |
9263 | * _scsih_add_device() will decide on retries and | |
9264 | * return "1" when it should be retried | |
9265 | */ | |
9266 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9267 | 1)) { | |
9268 | ssleep(1); | |
9269 | } | |
9270 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
9271 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
9272 | ioc->name, handle, (unsigned long long) | |
9273 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9274 | } | |
9275 | } | |
9276 | ||
9277 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
9278 | ioc->name); | |
9279 | ||
9280 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
9281 | ||
9282 | /* volumes */ | |
9283 | handle = 0xFFFF; | |
9284 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
9285 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
9286 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9287 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9288 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9289 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9290 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9291 | ioc->name, ioc_status, | |
9292 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9293 | break; | |
9294 | } | |
9295 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
9296 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
9297 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
9298 | le64_to_cpu(volume_pg1.WWID)); | |
9299 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
9300 | if (raid_device) | |
9301 | continue; | |
9302 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
9303 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
9304 | sizeof(Mpi2RaidVolPage0_t))) | |
9305 | continue; | |
9306 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9307 | MPI2_IOCSTATUS_MASK; | |
9308 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9309 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
9310 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9311 | ioc->name, ioc_status, | |
9312 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9313 | break; | |
9314 | } | |
9315 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
9316 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
9317 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
9318 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
9319 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
9320 | element.VolDevHandle = volume_pg1.DevHandle; | |
9321 | pr_info(MPT3SAS_FMT | |
9322 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
9323 | ioc->name, volume_pg1.DevHandle); | |
9324 | _scsih_sas_volume_add(ioc, &element); | |
9325 | pr_info(MPT3SAS_FMT | |
9326 | "\tAFTER adding volume: handle (0x%04x)\n", | |
9327 | ioc->name, volume_pg1.DevHandle); | |
9328 | } | |
9329 | } | |
9330 | ||
9331 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
9332 | ioc->name); | |
9333 | ||
9334 | skip_to_sas: | |
9335 | ||
9336 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
9337 | ioc->name); | |
9338 | ||
9339 | /* sas devices */ | |
9340 | handle = 0xFFFF; | |
9341 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
9342 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9343 | handle))) { | |
9344 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
9345 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
9346 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
9347 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
9348 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9349 | ioc->name, ioc_status, | |
9350 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9351 | break; | |
9352 | } | |
9353 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
9354 | if (!(_scsih_is_end_device( | |
9355 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
9356 | continue; | |
d1cb5e49 | 9357 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 9358 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
9359 | if (sas_device) { |
9360 | sas_device_put(sas_device); | |
f92363d1 | 9361 | continue; |
d1cb5e49 | 9362 | } |
f92363d1 SR |
9363 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
9364 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
9365 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
9366 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9367 | handle, (unsigned long long) | |
9368 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9369 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
9370 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
9371 | retry_count = 0; | |
9372 | /* This will retry adding the end device. | |
9373 | * _scsih_add_device() will decide on retries and | |
9374 | * return "1" when it should be retried | |
9375 | */ | |
9376 | while (_scsih_add_device(ioc, handle, retry_count++, | |
9377 | 0)) { | |
9378 | ssleep(1); | |
9379 | } | |
9380 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
9381 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
9382 | handle, (unsigned long long) | |
9383 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
9384 | } | |
9385 | } | |
9386 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
9387 | ioc->name); | |
ec051e5a SPS |
9388 | pr_info(MPT3SAS_FMT "\tscan devices: pcie end devices start\n", |
9389 | ioc->name); | |
9390 | ||
9391 | /* pcie devices */ | |
9392 | handle = 0xFFFF; | |
9393 | while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply, | |
9394 | &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
9395 | handle))) { | |
9396 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) | |
9397 | & MPI2_IOCSTATUS_MASK; | |
9398 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
9399 | pr_info(MPT3SAS_FMT "\tbreak from pcie end device" | |
9400 | " scan: ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9401 | ioc->name, ioc_status, | |
9402 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
9403 | break; | |
9404 | } | |
9405 | handle = le16_to_cpu(pcie_device_pg0.DevHandle); | |
9406 | if (!(_scsih_is_nvme_device( | |
9407 | le32_to_cpu(pcie_device_pg0.DeviceInfo)))) | |
9408 | continue; | |
9409 | pcie_device = mpt3sas_get_pdev_by_wwid(ioc, | |
9410 | le64_to_cpu(pcie_device_pg0.WWID)); | |
9411 | if (pcie_device) { | |
9412 | pcie_device_put(pcie_device); | |
9413 | continue; | |
9414 | } | |
9415 | retry_count = 0; | |
9416 | parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle); | |
9417 | _scsih_pcie_add_device(ioc, handle); | |
f92363d1 | 9418 | |
ec051e5a SPS |
9419 | pr_info(MPT3SAS_FMT "\tAFTER adding pcie end device: " |
9420 | "handle (0x%04x), wwid(0x%016llx)\n", ioc->name, | |
9421 | handle, | |
9422 | (unsigned long long) le64_to_cpu(pcie_device_pg0.WWID)); | |
9423 | } | |
9424 | pr_info(MPT3SAS_FMT "\tpcie devices: pcie end devices complete\n", | |
9425 | ioc->name); | |
f92363d1 SR |
9426 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); |
9427 | } | |
9428 | /** | |
9429 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
9430 | * @ioc: per adapter object | |
9431 | * @reset_phase: phase | |
9432 | * | |
9433 | * The handler for doing any required cleanup or initialization. | |
9434 | * | |
9435 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
9436 | * MPT3_IOC_DONE_RESET | |
9437 | * | |
9438 | * Return nothing. | |
9439 | */ | |
9440 | void | |
9441 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
9442 | { | |
9443 | switch (reset_phase) { | |
9444 | case MPT3_IOC_PRE_RESET: | |
9445 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9446 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
9447 | break; | |
9448 | case MPT3_IOC_AFTER_RESET: | |
9449 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9450 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
9451 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
9452 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
9453 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
9454 | complete(&ioc->scsih_cmds.done); | |
9455 | } | |
9456 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
9457 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
9458 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
9459 | complete(&ioc->tm_cmds.done); | |
9460 | } | |
9461 | ||
c696f7b8 SPS |
9462 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
9463 | memset(ioc->device_remove_in_progress, 0, | |
9464 | ioc->device_remove_in_progress_sz); | |
f92363d1 SR |
9465 | _scsih_fw_event_cleanup_queue(ioc); |
9466 | _scsih_flush_running_cmds(ioc); | |
9467 | break; | |
9468 | case MPT3_IOC_DONE_RESET: | |
9469 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
9470 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
9471 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
9472 | !ioc->sas_hba.num_phys)) { | |
9473 | _scsih_prep_device_scan(ioc); | |
9474 | _scsih_search_responding_sas_devices(ioc); | |
ec051e5a | 9475 | _scsih_search_responding_pcie_devices(ioc); |
f92363d1 SR |
9476 | _scsih_search_responding_raid_devices(ioc); |
9477 | _scsih_search_responding_expanders(ioc); | |
9478 | _scsih_error_recovery_delete_devices(ioc); | |
9479 | } | |
9480 | break; | |
9481 | } | |
9482 | } | |
9483 | ||
9484 | /** | |
9485 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
9486 | * @ioc: per adapter object | |
9487 | * @fw_event: The fw_event_work object | |
9488 | * Context: user. | |
9489 | * | |
9490 | * Return nothing. | |
9491 | */ | |
9492 | static void | |
9493 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
9494 | { | |
146b16c8 SR |
9495 | _scsih_fw_event_del_from_list(ioc, fw_event); |
9496 | ||
f92363d1 | 9497 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
9498 | if (ioc->remove_host || ioc->pci_error_recovery) { |
9499 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9500 | return; |
9501 | } | |
9502 | ||
9503 | switch (fw_event->event) { | |
9504 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
9505 | mpt3sas_process_trigger_data(ioc, |
9506 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
9507 | fw_event->event_data); | |
f92363d1 SR |
9508 | break; |
9509 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
9510 | while (scsi_host_in_recovery(ioc->shost) || |
9511 | ioc->shost_recovery) { | |
9512 | /* | |
9513 | * If we're unloading, bail. Otherwise, this can become | |
9514 | * an infinite loop. | |
9515 | */ | |
9516 | if (ioc->remove_host) | |
9517 | goto out; | |
f92363d1 | 9518 | ssleep(1); |
146b16c8 | 9519 | } |
3075ac49 | 9520 | _scsih_remove_unresponding_devices(ioc); |
f92363d1 SR |
9521 | _scsih_scan_for_devices_after_reset(ioc); |
9522 | break; | |
9523 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
9524 | ioc->start_scan = 0; | |
9525 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | |
9526 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], | |
9527 | missing_delay[1]); | |
9528 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
9529 | "port enable: complete from worker thread\n", | |
9530 | ioc->name)); | |
9531 | break; | |
0f624c39 SR |
9532 | case MPT3SAS_TURN_ON_PFA_LED: |
9533 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
9534 | break; |
9535 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9536 | _scsih_sas_topology_change_event(ioc, fw_event); | |
9537 | break; | |
9538 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
9539 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
9540 | break; | |
9541 | case MPI2_EVENT_SAS_DISCOVERY: | |
9542 | _scsih_sas_discovery_event(ioc, fw_event); | |
9543 | break; | |
9544 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9545 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
9546 | break; | |
9547 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9548 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
9549 | fw_event); | |
9550 | break; | |
9551 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
9552 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
9553 | break; | |
9554 | case MPI2_EVENT_IR_VOLUME: | |
9555 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
9556 | break; | |
9557 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
9558 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
9559 | break; | |
9560 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9561 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
9562 | break; | |
4318c734 SPS |
9563 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
9564 | _scsih_pcie_device_status_change_event(ioc, fw_event); | |
9565 | break; | |
9566 | case MPI2_EVENT_PCIE_ENUMERATION: | |
9567 | _scsih_pcie_enumeration_event(ioc, fw_event); | |
9568 | break; | |
9569 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: | |
9570 | _scsih_pcie_topology_change_event(ioc, fw_event); | |
9571 | return; | |
9572 | break; | |
f92363d1 | 9573 | } |
146b16c8 SR |
9574 | out: |
9575 | fw_event_work_put(fw_event); | |
f92363d1 SR |
9576 | } |
9577 | ||
9578 | /** | |
9579 | * _firmware_event_work | |
9580 | * @ioc: per adapter object | |
9581 | * @work: The fw_event_work object | |
9582 | * Context: user. | |
9583 | * | |
9584 | * wrappers for the work thread handling firmware events | |
9585 | * | |
9586 | * Return nothing. | |
9587 | */ | |
9588 | ||
9589 | static void | |
9590 | _firmware_event_work(struct work_struct *work) | |
9591 | { | |
9592 | struct fw_event_work *fw_event = container_of(work, | |
9593 | struct fw_event_work, work); | |
9594 | ||
9595 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
9596 | } | |
9597 | ||
9598 | /** | |
9599 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
9600 | * @ioc: per adapter object | |
9601 | * @msix_index: MSIX table index supplied by the OS | |
9602 | * @reply: reply message frame(lower 32bit addr) | |
9603 | * Context: interrupt. | |
9604 | * | |
9605 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
9606 | * The tasks are worked from _firmware_event_work in user context. | |
9607 | * | |
9608 | * Return 1 meaning mf should be freed from _base_interrupt | |
9609 | * 0 means the mf is freed from this function. | |
9610 | */ | |
9611 | u8 | |
9612 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
9613 | u32 reply) | |
9614 | { | |
9615 | struct fw_event_work *fw_event; | |
9616 | Mpi2EventNotificationReply_t *mpi_reply; | |
9617 | u16 event; | |
9618 | u16 sz; | |
a470a51c | 9619 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 SR |
9620 | |
9621 | /* events turned off due to host reset or driver unloading */ | |
9622 | if (ioc->remove_host || ioc->pci_error_recovery) | |
9623 | return 1; | |
9624 | ||
9625 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
9626 | ||
9627 | if (unlikely(!mpi_reply)) { | |
9628 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
9629 | ioc->name, __FILE__, __LINE__, __func__); | |
9630 | return 1; | |
9631 | } | |
9632 | ||
9633 | event = le16_to_cpu(mpi_reply->Event); | |
9634 | ||
9635 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
9636 | mpt3sas_trigger_event(ioc, event, 0); | |
9637 | ||
9638 | switch (event) { | |
9639 | /* handle these */ | |
9640 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
9641 | { | |
9642 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
9643 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
9644 | mpi_reply->EventData; | |
9645 | ||
9646 | if (baen_data->Primitive != | |
9647 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
9648 | return 1; | |
9649 | ||
9650 | if (ioc->broadcast_aen_busy) { | |
9651 | ioc->broadcast_aen_pending++; | |
9652 | return 1; | |
9653 | } else | |
9654 | ioc->broadcast_aen_busy = 1; | |
9655 | break; | |
9656 | } | |
9657 | ||
9658 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
9659 | _scsih_check_topo_delete_events(ioc, | |
9660 | (Mpi2EventDataSasTopologyChangeList_t *) | |
9661 | mpi_reply->EventData); | |
9662 | break; | |
4318c734 SPS |
9663 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
9664 | _scsih_check_pcie_topo_remove_events(ioc, | |
9665 | (Mpi26EventDataPCIeTopologyChangeList_t *) | |
9666 | mpi_reply->EventData); | |
9667 | break; | |
f92363d1 SR |
9668 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
9669 | _scsih_check_ir_config_unhide_events(ioc, | |
9670 | (Mpi2EventDataIrConfigChangeList_t *) | |
9671 | mpi_reply->EventData); | |
9672 | break; | |
9673 | case MPI2_EVENT_IR_VOLUME: | |
9674 | _scsih_check_volume_delete_events(ioc, | |
9675 | (Mpi2EventDataIrVolume_t *) | |
9676 | mpi_reply->EventData); | |
9677 | break; | |
7786ab6a SR |
9678 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
9679 | { | |
9680 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
9681 | u32 *log_code; | |
9682 | ||
9683 | if (!ioc->is_warpdrive) | |
9684 | break; | |
9685 | ||
9686 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
9687 | mpi_reply->EventData; | |
9688 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 9689 | |
7786ab6a SR |
9690 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
9691 | != MPT2_WARPDRIVE_LOGENTRY) | |
9692 | break; | |
9693 | ||
9694 | switch (le32_to_cpu(*log_code)) { | |
9695 | case MPT2_WARPDRIVE_LC_SSDT: | |
9696 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9697 | "IO Throttling has occurred in the WarpDrive " | |
9698 | "subsystem. Check WarpDrive documentation for " | |
9699 | "additional details.\n", ioc->name); | |
9700 | break; | |
9701 | case MPT2_WARPDRIVE_LC_SSDLW: | |
9702 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
9703 | "Program/Erase Cycles for the WarpDrive subsystem " | |
9704 | "in degraded range. Check WarpDrive documentation " | |
9705 | "for additional details.\n", ioc->name); | |
9706 | break; | |
9707 | case MPT2_WARPDRIVE_LC_SSDLF: | |
9708 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9709 | "There are no Program/Erase Cycles for the " | |
9710 | "WarpDrive subsystem. The storage device will be " | |
9711 | "in read-only mode. Check WarpDrive documentation " | |
9712 | "for additional details.\n", ioc->name); | |
9713 | break; | |
9714 | case MPT2_WARPDRIVE_LC_BRMF: | |
9715 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
9716 | "The Backup Rail Monitor has failed on the " | |
9717 | "WarpDrive subsystem. Check WarpDrive " | |
9718 | "documentation for additional details.\n", | |
9719 | ioc->name); | |
9720 | break; | |
9721 | } | |
9722 | ||
9723 | break; | |
9724 | } | |
f92363d1 SR |
9725 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
9726 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
9727 | case MPI2_EVENT_SAS_DISCOVERY: | |
9728 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
9729 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
4318c734 SPS |
9730 | case MPI2_EVENT_PCIE_ENUMERATION: |
9731 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: | |
f92363d1 SR |
9732 | break; |
9733 | ||
2d8ce8c9 SR |
9734 | case MPI2_EVENT_TEMP_THRESHOLD: |
9735 | _scsih_temp_threshold_events(ioc, | |
9736 | (Mpi2EventDataTemperature_t *) | |
9737 | mpi_reply->EventData); | |
9738 | break; | |
a470a51c C |
9739 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
9740 | ActiveCableEventData = | |
9741 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
9742 | switch (ActiveCableEventData->ReasonCode) { |
9743 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
b99b1993 SR |
9744 | pr_notice(MPT3SAS_FMT |
9745 | "Currently an active cable with ReceptacleID %d\n", | |
9746 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9747 | pr_notice("cannot be powered and devices connected\n"); | |
9748 | pr_notice("to this active cable will not be seen\n"); | |
9749 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 9750 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
9751 | break; |
9752 | ||
9753 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
b99b1993 SR |
9754 | pr_notice(MPT3SAS_FMT |
9755 | "Currently a cable with ReceptacleID %d\n", | |
9756 | ioc->name, ActiveCableEventData->ReceptacleID); | |
9757 | pr_notice( | |
9758 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 9759 | break; |
7ebd67e0 | 9760 | } |
6c44c0fe | 9761 | |
a470a51c | 9762 | break; |
2d8ce8c9 | 9763 | |
f92363d1 SR |
9764 | default: /* ignore the rest */ |
9765 | return 1; | |
9766 | } | |
9767 | ||
f92363d1 | 9768 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 9769 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 9770 | if (!fw_event) { |
f92363d1 SR |
9771 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
9772 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
9773 | return 1; |
9774 | } | |
9775 | ||
9776 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
9777 | fw_event->ioc = ioc; | |
9778 | fw_event->VF_ID = mpi_reply->VF_ID; | |
9779 | fw_event->VP_ID = mpi_reply->VP_ID; | |
9780 | fw_event->event = event; | |
9781 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 9782 | fw_event_work_put(fw_event); |
f92363d1 SR |
9783 | return 1; |
9784 | } | |
9785 | ||
f92363d1 SR |
9786 | /** |
9787 | * _scsih_expander_node_remove - removing expander device from list. | |
9788 | * @ioc: per adapter object | |
9789 | * @sas_expander: the sas_device object | |
f92363d1 SR |
9790 | * |
9791 | * Removing object and freeing associated memory from the | |
9792 | * ioc->sas_expander_list. | |
9793 | * | |
9794 | * Return nothing. | |
9795 | */ | |
9796 | static void | |
9797 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
9798 | struct _sas_node *sas_expander) | |
9799 | { | |
9800 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 9801 | unsigned long flags; |
f92363d1 SR |
9802 | |
9803 | /* remove sibling ports attached to this expander */ | |
9804 | list_for_each_entry_safe(mpt3sas_port, next, | |
9805 | &sas_expander->sas_port_list, port_list) { | |
9806 | if (ioc->shost_recovery) | |
9807 | return; | |
9808 | if (mpt3sas_port->remote_identify.device_type == | |
9809 | SAS_END_DEVICE) | |
9810 | mpt3sas_device_remove_by_sas_address(ioc, | |
9811 | mpt3sas_port->remote_identify.sas_address); | |
9812 | else if (mpt3sas_port->remote_identify.device_type == | |
9813 | SAS_EDGE_EXPANDER_DEVICE || | |
9814 | mpt3sas_port->remote_identify.device_type == | |
9815 | SAS_FANOUT_EXPANDER_DEVICE) | |
9816 | mpt3sas_expander_remove(ioc, | |
9817 | mpt3sas_port->remote_identify.sas_address); | |
9818 | } | |
9819 | ||
9820 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
9821 | sas_expander->sas_address_parent); | |
9822 | ||
9823 | pr_info(MPT3SAS_FMT | |
9824 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
9825 | ioc->name, | |
9826 | sas_expander->handle, (unsigned long long) | |
9827 | sas_expander->sas_address); | |
9828 | ||
bbe3def3 SR |
9829 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
9830 | list_del(&sas_expander->list); | |
9831 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
9832 | ||
f92363d1 SR |
9833 | kfree(sas_expander->phy); |
9834 | kfree(sas_expander); | |
9835 | } | |
9836 | ||
9837 | /** | |
9838 | * _scsih_ir_shutdown - IR shutdown notification | |
9839 | * @ioc: per adapter object | |
9840 | * | |
9841 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
9842 | * the host system is shutting down. | |
9843 | * | |
9844 | * Return nothing. | |
9845 | */ | |
9846 | static void | |
9847 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
9848 | { | |
9849 | Mpi2RaidActionRequest_t *mpi_request; | |
9850 | Mpi2RaidActionReply_t *mpi_reply; | |
9851 | u16 smid; | |
9852 | ||
9853 | /* is IR firmware build loaded ? */ | |
9854 | if (!ioc->ir_firmware) | |
9855 | return; | |
9856 | ||
9857 | /* are there any volumes ? */ | |
9858 | if (list_empty(&ioc->raid_device_list)) | |
9859 | return; | |
9860 | ||
9861 | mutex_lock(&ioc->scsih_cmds.mutex); | |
9862 | ||
9863 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
9864 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
9865 | ioc->name, __func__); | |
9866 | goto out; | |
9867 | } | |
9868 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
9869 | ||
9870 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
9871 | if (!smid) { | |
9872 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
9873 | ioc->name, __func__); | |
9874 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9875 | goto out; | |
9876 | } | |
9877 | ||
9878 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
9879 | ioc->scsih_cmds.smid = smid; | |
9880 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
9881 | ||
9882 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
9883 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
9884 | ||
7786ab6a SR |
9885 | if (!ioc->hide_ir_msg) |
9886 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
f92363d1 | 9887 | init_completion(&ioc->scsih_cmds.done); |
81c16f83 | 9888 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
9889 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
9890 | ||
9891 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
9892 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
9893 | ioc->name, __func__); | |
9894 | goto out; | |
9895 | } | |
9896 | ||
9897 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
9898 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a SR |
9899 | if (!ioc->hide_ir_msg) |
9900 | pr_info(MPT3SAS_FMT "IR shutdown " | |
9901 | "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
9902 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
9903 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
9904 | } |
9905 | ||
9906 | out: | |
9907 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
9908 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
9909 | } | |
9910 | ||
9911 | /** | |
8a7e4c24 | 9912 | * scsih_remove - detach and remove add host |
f92363d1 SR |
9913 | * @pdev: PCI device struct |
9914 | * | |
9915 | * Routine called when unloading the driver. | |
9916 | * Return nothing. | |
9917 | */ | |
8bbb1cf6 | 9918 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
9919 | { |
9920 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9921 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9922 | struct _sas_port *mpt3sas_port, *next_port; | |
9923 | struct _raid_device *raid_device, *next; | |
9924 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3075ac49 | 9925 | struct _pcie_device *pcie_device, *pcienext; |
f92363d1 SR |
9926 | struct workqueue_struct *wq; |
9927 | unsigned long flags; | |
9928 | ||
9929 | ioc->remove_host = 1; | |
9930 | _scsih_fw_event_cleanup_queue(ioc); | |
9931 | ||
9932 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
9933 | wq = ioc->firmware_event_thread; | |
9934 | ioc->firmware_event_thread = NULL; | |
9935 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
9936 | if (wq) | |
9937 | destroy_workqueue(wq); | |
9938 | ||
9939 | /* release all the volumes */ | |
9940 | _scsih_ir_shutdown(ioc); | |
9941 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
9942 | list) { | |
9943 | if (raid_device->starget) { | |
9944 | sas_target_priv_data = | |
9945 | raid_device->starget->hostdata; | |
9946 | sas_target_priv_data->deleted = 1; | |
9947 | scsi_remove_target(&raid_device->starget->dev); | |
9948 | } | |
9949 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
9950 | ioc->name, raid_device->handle, | |
9951 | (unsigned long long) raid_device->wwid); | |
9952 | _scsih_raid_device_remove(ioc, raid_device); | |
9953 | } | |
3075ac49 SPS |
9954 | list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list, |
9955 | list) { | |
9956 | _scsih_pcie_device_remove_from_sml(ioc, pcie_device); | |
9957 | list_del_init(&pcie_device->list); | |
9958 | pcie_device_put(pcie_device); | |
9959 | } | |
f92363d1 SR |
9960 | |
9961 | /* free ports attached to the sas_host */ | |
9962 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
9963 | &ioc->sas_hba.sas_port_list, port_list) { | |
9964 | if (mpt3sas_port->remote_identify.device_type == | |
9965 | SAS_END_DEVICE) | |
9966 | mpt3sas_device_remove_by_sas_address(ioc, | |
9967 | mpt3sas_port->remote_identify.sas_address); | |
9968 | else if (mpt3sas_port->remote_identify.device_type == | |
9969 | SAS_EDGE_EXPANDER_DEVICE || | |
9970 | mpt3sas_port->remote_identify.device_type == | |
9971 | SAS_FANOUT_EXPANDER_DEVICE) | |
9972 | mpt3sas_expander_remove(ioc, | |
9973 | mpt3sas_port->remote_identify.sas_address); | |
9974 | } | |
9975 | ||
9976 | /* free phys attached to the sas_host */ | |
9977 | if (ioc->sas_hba.num_phys) { | |
9978 | kfree(ioc->sas_hba.phy); | |
9979 | ioc->sas_hba.phy = NULL; | |
9980 | ioc->sas_hba.num_phys = 0; | |
9981 | } | |
9982 | ||
9983 | sas_remove_host(shost); | |
9984 | mpt3sas_base_detach(ioc); | |
08c4d550 | 9985 | spin_lock(&gioc_lock); |
f92363d1 | 9986 | list_del(&ioc->list); |
08c4d550 | 9987 | spin_unlock(&gioc_lock); |
f92363d1 SR |
9988 | scsi_host_put(shost); |
9989 | } | |
9990 | ||
9991 | /** | |
8a7e4c24 | 9992 | * scsih_shutdown - routine call during system shutdown |
f92363d1 SR |
9993 | * @pdev: PCI device struct |
9994 | * | |
9995 | * Return nothing. | |
9996 | */ | |
8bbb1cf6 | 9997 | static void |
8a7e4c24 | 9998 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
9999 | { |
10000 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10001 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10002 | struct workqueue_struct *wq; | |
10003 | unsigned long flags; | |
10004 | ||
10005 | ioc->remove_host = 1; | |
10006 | _scsih_fw_event_cleanup_queue(ioc); | |
10007 | ||
10008 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
10009 | wq = ioc->firmware_event_thread; | |
10010 | ioc->firmware_event_thread = NULL; | |
10011 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
10012 | if (wq) | |
10013 | destroy_workqueue(wq); | |
10014 | ||
10015 | _scsih_ir_shutdown(ioc); | |
10016 | mpt3sas_base_detach(ioc); | |
10017 | } | |
10018 | ||
10019 | ||
10020 | /** | |
10021 | * _scsih_probe_boot_devices - reports 1st device | |
10022 | * @ioc: per adapter object | |
10023 | * | |
10024 | * If specified in bios page 2, this routine reports the 1st | |
10025 | * device scsi-ml or sas transport for persistent boot device | |
10026 | * purposes. Please refer to function _scsih_determine_boot_device() | |
10027 | */ | |
10028 | static void | |
10029 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
10030 | { | |
d88e1eab | 10031 | u32 channel; |
f92363d1 SR |
10032 | void *device; |
10033 | struct _sas_device *sas_device; | |
10034 | struct _raid_device *raid_device; | |
d88e1eab | 10035 | struct _pcie_device *pcie_device; |
f92363d1 SR |
10036 | u16 handle; |
10037 | u64 sas_address_parent; | |
10038 | u64 sas_address; | |
10039 | unsigned long flags; | |
10040 | int rc; | |
d88e1eab | 10041 | int tid; |
f92363d1 SR |
10042 | |
10043 | /* no Bios, return immediately */ | |
10044 | if (!ioc->bios_pg3.BiosVersion) | |
10045 | return; | |
10046 | ||
10047 | device = NULL; | |
f92363d1 SR |
10048 | if (ioc->req_boot_device.device) { |
10049 | device = ioc->req_boot_device.device; | |
d88e1eab | 10050 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
10051 | } else if (ioc->req_alt_boot_device.device) { |
10052 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 10053 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
10054 | } else if (ioc->current_boot_device.device) { |
10055 | device = ioc->current_boot_device.device; | |
d88e1eab | 10056 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
10057 | } |
10058 | ||
10059 | if (!device) | |
10060 | return; | |
10061 | ||
d88e1eab | 10062 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
10063 | raid_device = device; |
10064 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
10065 | raid_device->id, 0); | |
10066 | if (rc) | |
10067 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
10068 | } else if (channel == PCIE_CHANNEL) { |
10069 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10070 | pcie_device = device; | |
10071 | tid = pcie_device->id; | |
10072 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10073 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10074 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
10075 | if (rc) | |
10076 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
10077 | } else { |
10078 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10079 | sas_device = device; | |
10080 | handle = sas_device->handle; | |
10081 | sas_address_parent = sas_device->sas_address_parent; | |
10082 | sas_address = sas_device->sas_address; | |
10083 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
10084 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10085 | ||
7786ab6a SR |
10086 | if (ioc->hide_drives) |
10087 | return; | |
f92363d1 SR |
10088 | if (!mpt3sas_transport_port_add(ioc, handle, |
10089 | sas_address_parent)) { | |
10090 | _scsih_sas_device_remove(ioc, sas_device); | |
10091 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
10092 | if (!ioc->is_driver_loading) { |
10093 | mpt3sas_transport_port_remove(ioc, | |
10094 | sas_address, | |
f92363d1 | 10095 | sas_address_parent); |
f5edbe77 SR |
10096 | _scsih_sas_device_remove(ioc, sas_device); |
10097 | } | |
f92363d1 SR |
10098 | } |
10099 | } | |
10100 | } | |
10101 | ||
10102 | /** | |
10103 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
10104 | * @ioc: per adapter object | |
10105 | * | |
10106 | * Called during initial loading of the driver. | |
10107 | */ | |
10108 | static void | |
10109 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
10110 | { | |
10111 | struct _raid_device *raid_device, *raid_next; | |
10112 | int rc; | |
10113 | ||
10114 | list_for_each_entry_safe(raid_device, raid_next, | |
10115 | &ioc->raid_device_list, list) { | |
10116 | if (raid_device->starget) | |
10117 | continue; | |
10118 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
10119 | raid_device->id, 0); | |
10120 | if (rc) | |
10121 | _scsih_raid_device_remove(ioc, raid_device); | |
10122 | } | |
10123 | } | |
10124 | ||
d1cb5e49 SR |
10125 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
10126 | { | |
10127 | struct _sas_device *sas_device = NULL; | |
10128 | unsigned long flags; | |
10129 | ||
10130 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10131 | if (!list_empty(&ioc->sas_device_init_list)) { | |
10132 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
10133 | struct _sas_device, list); | |
10134 | sas_device_get(sas_device); | |
10135 | } | |
10136 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10137 | ||
10138 | return sas_device; | |
10139 | } | |
10140 | ||
10141 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10142 | struct _sas_device *sas_device) | |
10143 | { | |
10144 | unsigned long flags; | |
10145 | ||
10146 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
10147 | ||
10148 | /* | |
10149 | * Since we dropped the lock during the call to port_add(), we need to | |
10150 | * be careful here that somebody else didn't move or delete this item | |
10151 | * while we were busy with other things. | |
10152 | * | |
10153 | * If it was on the list, we need a put() for the reference the list | |
10154 | * had. Either way, we need a get() for the destination list. | |
10155 | */ | |
10156 | if (!list_empty(&sas_device->list)) { | |
10157 | list_del_init(&sas_device->list); | |
10158 | sas_device_put(sas_device); | |
10159 | } | |
10160 | ||
10161 | sas_device_get(sas_device); | |
10162 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
10163 | ||
10164 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
10165 | } | |
10166 | ||
f92363d1 SR |
10167 | /** |
10168 | * _scsih_probe_sas - reporting sas devices to sas transport | |
10169 | * @ioc: per adapter object | |
10170 | * | |
10171 | * Called during initial loading of the driver. | |
10172 | */ | |
10173 | static void | |
10174 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
10175 | { | |
d1cb5e49 | 10176 | struct _sas_device *sas_device; |
f92363d1 | 10177 | |
d1cb5e49 SR |
10178 | if (ioc->hide_drives) |
10179 | return; | |
7786ab6a | 10180 | |
d1cb5e49 | 10181 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
10182 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
10183 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
10184 | _scsih_sas_device_remove(ioc, sas_device); |
10185 | sas_device_put(sas_device); | |
f92363d1 SR |
10186 | continue; |
10187 | } else if (!sas_device->starget) { | |
10188 | /* | |
10189 | * When asyn scanning is enabled, its not possible to | |
10190 | * remove devices while scanning is turned on due to an | |
10191 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10192 | * sysfs_addrm_start() | |
10193 | */ | |
f5edbe77 | 10194 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
10195 | mpt3sas_transport_port_remove(ioc, |
10196 | sas_device->sas_address, | |
10197 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
10198 | _scsih_sas_device_remove(ioc, sas_device); |
10199 | sas_device_put(sas_device); | |
f5edbe77 SR |
10200 | continue; |
10201 | } | |
f92363d1 | 10202 | } |
d1cb5e49 SR |
10203 | sas_device_make_active(ioc, sas_device); |
10204 | sas_device_put(sas_device); | |
f92363d1 SR |
10205 | } |
10206 | } | |
10207 | ||
d88e1eab SPS |
10208 | /** |
10209 | * get_next_pcie_device - Get the next pcie device | |
10210 | * @ioc: per adapter object | |
10211 | * | |
10212 | * Get the next pcie device from pcie_device_init_list list. | |
10213 | * | |
10214 | * Returns pcie device structure if pcie_device_init_list list is not empty | |
10215 | * otherwise returns NULL | |
10216 | */ | |
10217 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
10218 | { | |
10219 | struct _pcie_device *pcie_device = NULL; | |
10220 | unsigned long flags; | |
10221 | ||
10222 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10223 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
10224 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
10225 | struct _pcie_device, list); | |
10226 | pcie_device_get(pcie_device); | |
10227 | } | |
10228 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10229 | ||
10230 | return pcie_device; | |
10231 | } | |
10232 | ||
10233 | /** | |
10234 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
10235 | * @ioc: per adapter object | |
10236 | * @pcie_device: pcie device object | |
10237 | * | |
10238 | * Add the pcie device which has registered with SCSI Transport Later to | |
10239 | * pcie_device_list list | |
10240 | */ | |
10241 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
10242 | struct _pcie_device *pcie_device) | |
10243 | { | |
10244 | unsigned long flags; | |
10245 | ||
10246 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
10247 | ||
10248 | if (!list_empty(&pcie_device->list)) { | |
10249 | list_del_init(&pcie_device->list); | |
10250 | pcie_device_put(pcie_device); | |
10251 | } | |
10252 | pcie_device_get(pcie_device); | |
10253 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
10254 | ||
10255 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
10256 | } | |
10257 | ||
10258 | /** | |
10259 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
10260 | * @ioc: per adapter object | |
10261 | * | |
10262 | * Called during initial loading of the driver. | |
10263 | */ | |
10264 | static void | |
10265 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
10266 | { | |
10267 | struct _pcie_device *pcie_device; | |
10268 | int rc; | |
10269 | ||
10270 | /* PCIe Device List */ | |
10271 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
10272 | if (pcie_device->starget) { | |
10273 | pcie_device_put(pcie_device); | |
10274 | continue; | |
10275 | } | |
10276 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, | |
10277 | pcie_device->id, 0); | |
10278 | if (rc) { | |
10279 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10280 | pcie_device_put(pcie_device); | |
10281 | continue; | |
10282 | } else if (!pcie_device->starget) { | |
10283 | /* | |
10284 | * When async scanning is enabled, its not possible to | |
10285 | * remove devices while scanning is turned on due to an | |
10286 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
10287 | * sysfs_addrm_start() | |
10288 | */ | |
10289 | if (!ioc->is_driver_loading) { | |
10290 | /* TODO-- Need to find out whether this condition will | |
10291 | * occur or not | |
10292 | */ | |
10293 | _scsih_pcie_device_remove(ioc, pcie_device); | |
10294 | pcie_device_put(pcie_device); | |
10295 | continue; | |
10296 | } | |
10297 | } | |
10298 | pcie_device_make_active(ioc, pcie_device); | |
10299 | pcie_device_put(pcie_device); | |
10300 | } | |
10301 | } | |
10302 | ||
f92363d1 SR |
10303 | /** |
10304 | * _scsih_probe_devices - probing for devices | |
10305 | * @ioc: per adapter object | |
10306 | * | |
10307 | * Called during initial loading of the driver. | |
10308 | */ | |
10309 | static void | |
10310 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
10311 | { | |
10312 | u16 volume_mapping_flags; | |
10313 | ||
10314 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
10315 | return; /* return when IOC doesn't support initiator mode */ | |
10316 | ||
10317 | _scsih_probe_boot_devices(ioc); | |
10318 | ||
10319 | if (ioc->ir_firmware) { | |
10320 | volume_mapping_flags = | |
10321 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
10322 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
10323 | if (volume_mapping_flags == | |
10324 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
10325 | _scsih_probe_raid(ioc); | |
10326 | _scsih_probe_sas(ioc); | |
10327 | } else { | |
10328 | _scsih_probe_sas(ioc); | |
10329 | _scsih_probe_raid(ioc); | |
10330 | } | |
d88e1eab | 10331 | } else { |
f92363d1 | 10332 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
10333 | _scsih_probe_pcie(ioc); |
10334 | } | |
f92363d1 SR |
10335 | } |
10336 | ||
10337 | /** | |
8a7e4c24 | 10338 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
10339 | * @shost: SCSI host pointer |
10340 | * | |
10341 | * The shost has the ability to discover targets on its own instead | |
10342 | * of scanning the entire bus. In our implemention, we will kick off | |
10343 | * firmware discovery. | |
10344 | */ | |
8bbb1cf6 | 10345 | static void |
8a7e4c24 | 10346 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
10347 | { |
10348 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10349 | int rc; | |
10350 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
10351 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
10352 | ||
10353 | if (disable_discovery > 0) | |
10354 | return; | |
10355 | ||
10356 | ioc->start_scan = 1; | |
10357 | rc = mpt3sas_port_enable(ioc); | |
10358 | ||
10359 | if (rc != 0) | |
10360 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
10361 | } | |
10362 | ||
10363 | /** | |
8a7e4c24 | 10364 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
10365 | * @shost: SCSI host pointer |
10366 | * @time: elapsed time of the scan in jiffies | |
10367 | * | |
10368 | * This function will be called periodicallyn until it returns 1 with the | |
10369 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
10370 | * we wait for firmware discovery to complete, then return 1. | |
10371 | */ | |
8bbb1cf6 | 10372 | static int |
8a7e4c24 | 10373 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
10374 | { |
10375 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10376 | ||
10377 | if (disable_discovery > 0) { | |
10378 | ioc->is_driver_loading = 0; | |
10379 | ioc->wait_for_discovery_to_complete = 0; | |
10380 | return 1; | |
10381 | } | |
10382 | ||
10383 | if (time >= (300 * HZ)) { | |
10384 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
10385 | pr_info(MPT3SAS_FMT | |
10386 | "port enable: FAILED with timeout (timeout=300s)\n", | |
10387 | ioc->name); | |
10388 | ioc->is_driver_loading = 0; | |
10389 | return 1; | |
10390 | } | |
10391 | ||
10392 | if (ioc->start_scan) | |
10393 | return 0; | |
10394 | ||
10395 | if (ioc->start_scan_failed) { | |
10396 | pr_info(MPT3SAS_FMT | |
10397 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
10398 | ioc->name, ioc->start_scan_failed); | |
10399 | ioc->is_driver_loading = 0; | |
10400 | ioc->wait_for_discovery_to_complete = 0; | |
10401 | ioc->remove_host = 1; | |
10402 | return 1; | |
10403 | } | |
10404 | ||
10405 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
10406 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
10407 | ||
10408 | if (ioc->wait_for_discovery_to_complete) { | |
10409 | ioc->wait_for_discovery_to_complete = 0; | |
10410 | _scsih_probe_devices(ioc); | |
10411 | } | |
10412 | mpt3sas_base_start_watchdog(ioc); | |
10413 | ioc->is_driver_loading = 0; | |
10414 | return 1; | |
10415 | } | |
10416 | ||
c84b06a4 SR |
10417 | /* shost template for SAS 2.0 HBA devices */ |
10418 | static struct scsi_host_template mpt2sas_driver_template = { | |
10419 | .module = THIS_MODULE, | |
10420 | .name = "Fusion MPT SAS Host", | |
10421 | .proc_name = MPT2SAS_DRIVER_NAME, | |
10422 | .queuecommand = scsih_qcmd, | |
10423 | .target_alloc = scsih_target_alloc, | |
10424 | .slave_alloc = scsih_slave_alloc, | |
10425 | .slave_configure = scsih_slave_configure, | |
10426 | .target_destroy = scsih_target_destroy, | |
10427 | .slave_destroy = scsih_slave_destroy, | |
10428 | .scan_finished = scsih_scan_finished, | |
10429 | .scan_start = scsih_scan_start, | |
10430 | .change_queue_depth = scsih_change_queue_depth, | |
10431 | .eh_abort_handler = scsih_abort, | |
10432 | .eh_device_reset_handler = scsih_dev_reset, | |
10433 | .eh_target_reset_handler = scsih_target_reset, | |
10434 | .eh_host_reset_handler = scsih_host_reset, | |
10435 | .bios_param = scsih_bios_param, | |
10436 | .can_queue = 1, | |
10437 | .this_id = -1, | |
10438 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
10439 | .max_sectors = 32767, | |
10440 | .cmd_per_lun = 7, | |
10441 | .use_clustering = ENABLE_CLUSTERING, | |
10442 | .shost_attrs = mpt3sas_host_attrs, | |
10443 | .sdev_attrs = mpt3sas_dev_attrs, | |
10444 | .track_queue_depth = 1, | |
10445 | }; | |
10446 | ||
10447 | /* raid transport support for SAS 2.0 HBA devices */ | |
10448 | static struct raid_function_template mpt2sas_raid_functions = { | |
10449 | .cookie = &mpt2sas_driver_template, | |
10450 | .is_raid = scsih_is_raid, | |
10451 | .get_resync = scsih_get_resync, | |
10452 | .get_state = scsih_get_state, | |
10453 | }; | |
d357e84d | 10454 | |
c84b06a4 SR |
10455 | /* shost template for SAS 3.0 HBA devices */ |
10456 | static struct scsi_host_template mpt3sas_driver_template = { | |
10457 | .module = THIS_MODULE, | |
10458 | .name = "Fusion MPT SAS Host", | |
10459 | .proc_name = MPT3SAS_DRIVER_NAME, | |
10460 | .queuecommand = scsih_qcmd, | |
10461 | .target_alloc = scsih_target_alloc, | |
10462 | .slave_alloc = scsih_slave_alloc, | |
10463 | .slave_configure = scsih_slave_configure, | |
10464 | .target_destroy = scsih_target_destroy, | |
10465 | .slave_destroy = scsih_slave_destroy, | |
10466 | .scan_finished = scsih_scan_finished, | |
10467 | .scan_start = scsih_scan_start, | |
10468 | .change_queue_depth = scsih_change_queue_depth, | |
10469 | .eh_abort_handler = scsih_abort, | |
10470 | .eh_device_reset_handler = scsih_dev_reset, | |
10471 | .eh_target_reset_handler = scsih_target_reset, | |
10472 | .eh_host_reset_handler = scsih_host_reset, | |
10473 | .bios_param = scsih_bios_param, | |
10474 | .can_queue = 1, | |
10475 | .this_id = -1, | |
10476 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
10477 | .max_sectors = 32767, | |
10478 | .cmd_per_lun = 7, | |
10479 | .use_clustering = ENABLE_CLUSTERING, | |
10480 | .shost_attrs = mpt3sas_host_attrs, | |
10481 | .sdev_attrs = mpt3sas_dev_attrs, | |
10482 | .track_queue_depth = 1, | |
10483 | }; | |
10484 | ||
10485 | /* raid transport support for SAS 3.0 HBA devices */ | |
10486 | static struct raid_function_template mpt3sas_raid_functions = { | |
10487 | .cookie = &mpt3sas_driver_template, | |
10488 | .is_raid = scsih_is_raid, | |
10489 | .get_resync = scsih_get_resync, | |
10490 | .get_state = scsih_get_state, | |
10491 | }; | |
10492 | ||
10493 | /** | |
10494 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
10495 | * this device belongs to. | |
10496 | * @pdev: PCI device struct | |
10497 | * | |
10498 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
10499 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
10500 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 10501 | */ |
8bbb1cf6 | 10502 | static u16 |
c84b06a4 SR |
10503 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
10504 | { | |
10505 | ||
10506 | switch (pdev->device) { | |
7786ab6a | 10507 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
10508 | case MPI2_MFGPAGE_DEVID_SAS2004: |
10509 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
10510 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
10511 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
10512 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
10513 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
10514 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
10515 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
10516 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
10517 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
10518 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
10519 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
10520 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
10521 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
10522 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
10523 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
c84b06a4 | 10524 | return MPI2_VERSION; |
d357e84d SR |
10525 | case MPI25_MFGPAGE_DEVID_SAS3004: |
10526 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
10527 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
10528 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
10529 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
10530 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 10531 | return MPI25_VERSION; |
b130b0d5 SS |
10532 | case MPI26_MFGPAGE_DEVID_SAS3216: |
10533 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
10534 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
10535 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
10536 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
10537 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
10538 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
10539 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
10540 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
10541 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
10542 | case MPI26_MFGPAGE_DEVID_SAS3508: |
10543 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10544 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10545 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10546 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10547 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10548 | case MPI26_MFGPAGE_DEVID_SAS3616: |
b130b0d5 | 10549 | return MPI26_VERSION; |
d357e84d | 10550 | } |
c84b06a4 | 10551 | return 0; |
d357e84d SR |
10552 | } |
10553 | ||
f92363d1 | 10554 | /** |
c84b06a4 | 10555 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
10556 | * @pdev: PCI device struct |
10557 | * @id: pci device id | |
10558 | * | |
10559 | * Returns 0 success, anything else error. | |
10560 | */ | |
8bbb1cf6 | 10561 | static int |
c84b06a4 | 10562 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
10563 | { |
10564 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 10565 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 10566 | int rv; |
c84b06a4 SR |
10567 | u16 hba_mpi_version; |
10568 | ||
10569 | /* Determine in which MPI version class this pci device belongs */ | |
10570 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
10571 | if (hba_mpi_version == 0) | |
10572 | return -ENODEV; | |
10573 | ||
10574 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
10575 | * for other generation HBA's return with -ENODEV | |
10576 | */ | |
10577 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
10578 | return -ENODEV; | |
10579 | ||
10580 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
10581 | * for other generation HBA's return with -ENODEV | |
10582 | */ | |
b130b0d5 SS |
10583 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
10584 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
10585 | return -ENODEV; |
10586 | ||
10587 | switch (hba_mpi_version) { | |
10588 | case MPI2_VERSION: | |
ffdadd68 | 10589 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
10590 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
10591 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
10592 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
10593 | sizeof(struct MPT3SAS_ADAPTER)); | |
10594 | if (!shost) | |
10595 | return -ENODEV; | |
10596 | ioc = shost_priv(shost); | |
10597 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10598 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10599 | ioc->id = mpt2_ids++; | |
10600 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
10601 | if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) { | |
10602 | ioc->is_warpdrive = 1; | |
10603 | ioc->hide_ir_msg = 1; | |
10604 | } else | |
10605 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; | |
10606 | break; | |
10607 | case MPI25_VERSION: | |
b130b0d5 | 10608 | case MPI26_VERSION: |
c84b06a4 SR |
10609 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
10610 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
10611 | sizeof(struct MPT3SAS_ADAPTER)); | |
10612 | if (!shost) | |
10613 | return -ENODEV; | |
10614 | ioc = shost_priv(shost); | |
10615 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
10616 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
10617 | ioc->id = mpt3_ids++; | |
10618 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
10619 | switch (pdev->device) { |
10620 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
10621 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
10622 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
10623 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
10624 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
10625 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 10626 | case MPI26_MFGPAGE_DEVID_SAS3616: |
998f26ae SPS |
10627 | ioc->is_gen35_ioc = 1; |
10628 | break; | |
10629 | default: | |
10630 | ioc->is_gen35_ioc = 0; | |
10631 | } | |
b130b0d5 SS |
10632 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
10633 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
10634 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
10635 | ioc->combined_reply_queue = 1; | |
10636 | if (ioc->is_gen35_ioc) | |
10637 | ioc->combined_reply_index_count = | |
10638 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
10639 | else | |
10640 | ioc->combined_reply_index_count = | |
10641 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
10642 | } | |
c84b06a4 SR |
10643 | break; |
10644 | default: | |
10645 | return -ENODEV; | |
10646 | } | |
f92363d1 | 10647 | |
f92363d1 | 10648 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 10649 | spin_lock(&gioc_lock); |
f92363d1 | 10650 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 10651 | spin_unlock(&gioc_lock); |
f92363d1 | 10652 | ioc->shost = shost; |
f92363d1 SR |
10653 | ioc->pdev = pdev; |
10654 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
10655 | ioc->tm_cb_idx = tm_cb_idx; | |
10656 | ioc->ctl_cb_idx = ctl_cb_idx; | |
10657 | ioc->base_cb_idx = base_cb_idx; | |
10658 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
10659 | ioc->transport_cb_idx = transport_cb_idx; | |
10660 | ioc->scsih_cb_idx = scsih_cb_idx; | |
10661 | ioc->config_cb_idx = config_cb_idx; | |
10662 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
10663 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
10664 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
10665 | ioc->logging_level = logging_level; | |
10666 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
10667 | /* misc semaphores and spin locks */ | |
10668 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
10669 | /* initializing pci_access_mutex lock */ |
10670 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
10671 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
10672 | spin_lock_init(&ioc->scsi_lookup_lock); | |
10673 | spin_lock_init(&ioc->sas_device_lock); | |
10674 | spin_lock_init(&ioc->sas_node_lock); | |
10675 | spin_lock_init(&ioc->fw_event_lock); | |
10676 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 10677 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
10678 | spin_lock_init(&ioc->diag_trigger_lock); |
10679 | ||
10680 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
10681 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
10682 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
d88e1eab SPS |
10683 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
10684 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
10685 | INIT_LIST_HEAD(&ioc->fw_event_list); |
10686 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
10687 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
10688 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
10689 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
10690 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 10691 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 10692 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 10693 | |
c84b06a4 | 10694 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 10695 | |
f92363d1 SR |
10696 | /* init shost parameters */ |
10697 | shost->max_cmd_len = 32; | |
10698 | shost->max_lun = max_lun; | |
10699 | shost->transportt = mpt3sas_transport_template; | |
10700 | shost->unique_id = ioc->id; | |
10701 | ||
10702 | if (max_sectors != 0xFFFF) { | |
10703 | if (max_sectors < 64) { | |
10704 | shost->max_sectors = 64; | |
10705 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10706 | "for max_sectors, range is 64 to 32767. Assigning " | |
10707 | "value of 64.\n", ioc->name, max_sectors); | |
10708 | } else if (max_sectors > 32767) { | |
10709 | shost->max_sectors = 32767; | |
10710 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
10711 | "for max_sectors, range is 64 to 32767. Assigning " | |
10712 | "default value of 32767.\n", ioc->name, | |
10713 | max_sectors); | |
10714 | } else { | |
10715 | shost->max_sectors = max_sectors & 0xFFFE; | |
10716 | pr_info(MPT3SAS_FMT | |
10717 | "The max_sectors value is set to %d\n", | |
10718 | ioc->name, shost->max_sectors); | |
10719 | } | |
10720 | } | |
10721 | ||
f92363d1 SR |
10722 | /* register EEDP capabilities with SCSI layer */ |
10723 | if (prot_mask > 0) | |
10724 | scsi_host_set_prot(shost, prot_mask); | |
10725 | else | |
10726 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
10727 | | SHOST_DIF_TYPE2_PROTECTION | |
10728 | | SHOST_DIF_TYPE3_PROTECTION); | |
10729 | ||
10730 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
10731 | ||
10732 | /* event thread */ | |
10733 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 10734 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e SR |
10735 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
10736 | ioc->firmware_event_name, WQ_MEM_RECLAIM); | |
f92363d1 SR |
10737 | if (!ioc->firmware_event_thread) { |
10738 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10739 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10740 | rv = -ENODEV; |
f92363d1 SR |
10741 | goto out_thread_fail; |
10742 | } | |
10743 | ||
10744 | ioc->is_driver_loading = 1; | |
10745 | if ((mpt3sas_base_attach(ioc))) { | |
10746 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
10747 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 10748 | rv = -ENODEV; |
f92363d1 SR |
10749 | goto out_attach_fail; |
10750 | } | |
7786ab6a | 10751 | |
7786ab6a SR |
10752 | if (ioc->is_warpdrive) { |
10753 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
10754 | ioc->hide_drives = 0; | |
10755 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
10756 | ioc->hide_drives = 1; | |
10757 | else { | |
c84b06a4 | 10758 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
10759 | ioc->hide_drives = 1; |
10760 | else | |
10761 | ioc->hide_drives = 0; | |
10762 | } | |
10763 | } else | |
10764 | ioc->hide_drives = 0; | |
7786ab6a | 10765 | |
b65f1d4d SR |
10766 | rv = scsi_add_host(shost, &pdev->dev); |
10767 | if (rv) { | |
4dc06fd8 RS |
10768 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
10769 | ioc->name, __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
10770 | goto out_add_shost_fail; |
10771 | } | |
10772 | ||
f92363d1 SR |
10773 | scsi_scan_host(shost); |
10774 | return 0; | |
4dc06fd8 RS |
10775 | out_add_shost_fail: |
10776 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
10777 | out_attach_fail: |
10778 | destroy_workqueue(ioc->firmware_event_thread); | |
10779 | out_thread_fail: | |
08c4d550 | 10780 | spin_lock(&gioc_lock); |
f92363d1 | 10781 | list_del(&ioc->list); |
08c4d550 | 10782 | spin_unlock(&gioc_lock); |
f92363d1 | 10783 | scsi_host_put(shost); |
b65f1d4d | 10784 | return rv; |
f92363d1 SR |
10785 | } |
10786 | ||
10787 | #ifdef CONFIG_PM | |
10788 | /** | |
8a7e4c24 | 10789 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
10790 | * @pdev: PCI device struct |
10791 | * @state: PM state change to (usually PCI_D3) | |
10792 | * | |
10793 | * Returns 0 success, anything else error. | |
10794 | */ | |
8bbb1cf6 | 10795 | static int |
8a7e4c24 | 10796 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
10797 | { |
10798 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10799 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10800 | pci_power_t device_state; | |
10801 | ||
10802 | mpt3sas_base_stop_watchdog(ioc); | |
10803 | flush_scheduled_work(); | |
10804 | scsi_block_requests(shost); | |
10805 | device_state = pci_choose_state(pdev, state); | |
10806 | pr_info(MPT3SAS_FMT | |
10807 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
10808 | ioc->name, pdev, pci_name(pdev), device_state); | |
10809 | ||
10810 | pci_save_state(pdev); | |
10811 | mpt3sas_base_free_resources(ioc); | |
10812 | pci_set_power_state(pdev, device_state); | |
10813 | return 0; | |
10814 | } | |
10815 | ||
10816 | /** | |
8a7e4c24 | 10817 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
10818 | * @pdev: PCI device struct |
10819 | * | |
10820 | * Returns 0 success, anything else error. | |
10821 | */ | |
8bbb1cf6 | 10822 | static int |
8a7e4c24 | 10823 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
10824 | { |
10825 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10826 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10827 | pci_power_t device_state = pdev->current_state; | |
10828 | int r; | |
10829 | ||
10830 | pr_info(MPT3SAS_FMT | |
10831 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
10832 | ioc->name, pdev, pci_name(pdev), device_state); | |
10833 | ||
10834 | pci_set_power_state(pdev, PCI_D0); | |
10835 | pci_enable_wake(pdev, PCI_D0, 0); | |
10836 | pci_restore_state(pdev); | |
10837 | ioc->pdev = pdev; | |
10838 | r = mpt3sas_base_map_resources(ioc); | |
10839 | if (r) | |
10840 | return r; | |
10841 | ||
98c56ad3 | 10842 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
10843 | scsi_unblock_requests(shost); |
10844 | mpt3sas_base_start_watchdog(ioc); | |
10845 | return 0; | |
10846 | } | |
10847 | #endif /* CONFIG_PM */ | |
10848 | ||
10849 | /** | |
8a7e4c24 | 10850 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
10851 | * @pdev: PCI device struct |
10852 | * @state: PCI channel state | |
10853 | * | |
10854 | * Description: Called when a PCI error is detected. | |
10855 | * | |
10856 | * Return value: | |
10857 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
10858 | */ | |
8bbb1cf6 | 10859 | static pci_ers_result_t |
8a7e4c24 | 10860 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
10861 | { |
10862 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10863 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10864 | ||
10865 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
10866 | ioc->name, state); | |
10867 | ||
10868 | switch (state) { | |
10869 | case pci_channel_io_normal: | |
10870 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10871 | case pci_channel_io_frozen: | |
10872 | /* Fatal error, prepare for slot reset */ | |
10873 | ioc->pci_error_recovery = 1; | |
10874 | scsi_block_requests(ioc->shost); | |
10875 | mpt3sas_base_stop_watchdog(ioc); | |
10876 | mpt3sas_base_free_resources(ioc); | |
10877 | return PCI_ERS_RESULT_NEED_RESET; | |
10878 | case pci_channel_io_perm_failure: | |
10879 | /* Permanent error, prepare for device removal */ | |
10880 | ioc->pci_error_recovery = 1; | |
10881 | mpt3sas_base_stop_watchdog(ioc); | |
10882 | _scsih_flush_running_cmds(ioc); | |
10883 | return PCI_ERS_RESULT_DISCONNECT; | |
10884 | } | |
10885 | return PCI_ERS_RESULT_NEED_RESET; | |
10886 | } | |
10887 | ||
10888 | /** | |
8a7e4c24 | 10889 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
10890 | * @pdev: PCI device struct |
10891 | * | |
10892 | * Description: This routine is called by the pci error recovery | |
10893 | * code after the PCI slot has been reset, just before we | |
10894 | * should resume normal operations. | |
10895 | */ | |
8bbb1cf6 | 10896 | static pci_ers_result_t |
8a7e4c24 | 10897 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
10898 | { |
10899 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10900 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10901 | int rc; | |
10902 | ||
10903 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
10904 | ioc->name); | |
10905 | ||
10906 | ioc->pci_error_recovery = 0; | |
10907 | ioc->pdev = pdev; | |
10908 | pci_restore_state(pdev); | |
10909 | rc = mpt3sas_base_map_resources(ioc); | |
10910 | if (rc) | |
10911 | return PCI_ERS_RESULT_DISCONNECT; | |
10912 | ||
98c56ad3 | 10913 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
10914 | |
10915 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
10916 | (rc == 0) ? "success" : "failed"); | |
10917 | ||
10918 | if (!rc) | |
10919 | return PCI_ERS_RESULT_RECOVERED; | |
10920 | else | |
10921 | return PCI_ERS_RESULT_DISCONNECT; | |
10922 | } | |
10923 | ||
10924 | /** | |
8a7e4c24 | 10925 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
10926 | * @pdev: pointer to PCI device |
10927 | * | |
10928 | * Called when the error recovery driver tells us that its | |
10929 | * OK to resume normal operation. Use completion to allow | |
10930 | * halted scsi ops to resume. | |
10931 | */ | |
8bbb1cf6 | 10932 | static void |
8a7e4c24 | 10933 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
10934 | { |
10935 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10936 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10937 | ||
10938 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
10939 | ||
10940 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
10941 | mpt3sas_base_start_watchdog(ioc); | |
10942 | scsi_unblock_requests(ioc->shost); | |
10943 | } | |
10944 | ||
10945 | /** | |
8a7e4c24 | 10946 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
10947 | * @pdev: pointer to PCI device |
10948 | */ | |
8bbb1cf6 | 10949 | static pci_ers_result_t |
8a7e4c24 | 10950 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
10951 | { |
10952 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10953 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
10954 | ||
10955 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
10956 | ioc->name); | |
10957 | ||
10958 | /* TODO - dump whatever for debugging purposes */ | |
10959 | ||
83c3d340 KW |
10960 | /* This called only if scsih_pci_error_detected returns |
10961 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
10962 | * works, no need to reset slot. | |
10963 | */ | |
10964 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
10965 | } |
10966 | ||
307d9075 AM |
10967 | /** |
10968 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
10969 | * @sdev: scsi device struct | |
10970 | * | |
10971 | * This is called when a user indicates they would like to enable | |
10972 | * ncq command priorities. This works only on SATA devices. | |
10973 | */ | |
10974 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
10975 | { | |
10976 | unsigned char *buf; | |
10977 | bool ncq_prio_supp = false; | |
10978 | ||
10979 | if (!scsi_device_supports_vpd(sdev)) | |
10980 | return ncq_prio_supp; | |
10981 | ||
10982 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
10983 | if (!buf) | |
10984 | return ncq_prio_supp; | |
10985 | ||
10986 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
10987 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
10988 | ||
10989 | kfree(buf); | |
10990 | return ncq_prio_supp; | |
10991 | } | |
c84b06a4 SR |
10992 | /* |
10993 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
10994 | */ | |
10995 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
10996 | /* Spitfire ~ 2004 */ | |
10997 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
10998 | PCI_ANY_ID, PCI_ANY_ID }, | |
10999 | /* Falcon ~ 2008 */ | |
11000 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
11001 | PCI_ANY_ID, PCI_ANY_ID }, | |
11002 | /* Liberator ~ 2108 */ | |
11003 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
11004 | PCI_ANY_ID, PCI_ANY_ID }, | |
11005 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
11006 | PCI_ANY_ID, PCI_ANY_ID }, | |
11007 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
11008 | PCI_ANY_ID, PCI_ANY_ID }, | |
11009 | /* Meteor ~ 2116 */ | |
11010 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
11011 | PCI_ANY_ID, PCI_ANY_ID }, | |
11012 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
11013 | PCI_ANY_ID, PCI_ANY_ID }, | |
11014 | /* Thunderbolt ~ 2208 */ | |
11015 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
11016 | PCI_ANY_ID, PCI_ANY_ID }, | |
11017 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
11018 | PCI_ANY_ID, PCI_ANY_ID }, | |
11019 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
11020 | PCI_ANY_ID, PCI_ANY_ID }, | |
11021 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
11022 | PCI_ANY_ID, PCI_ANY_ID }, | |
11023 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
11024 | PCI_ANY_ID, PCI_ANY_ID }, | |
11025 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
11026 | PCI_ANY_ID, PCI_ANY_ID }, | |
11027 | /* Mustang ~ 2308 */ | |
11028 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
11029 | PCI_ANY_ID, PCI_ANY_ID }, | |
11030 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
11031 | PCI_ANY_ID, PCI_ANY_ID }, | |
11032 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
11033 | PCI_ANY_ID, PCI_ANY_ID }, | |
11034 | /* SSS6200 */ | |
11035 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
11036 | PCI_ANY_ID, PCI_ANY_ID }, | |
11037 | /* Fury ~ 3004 and 3008 */ | |
11038 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
11039 | PCI_ANY_ID, PCI_ANY_ID }, | |
11040 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
11041 | PCI_ANY_ID, PCI_ANY_ID }, | |
11042 | /* Invader ~ 3108 */ | |
11043 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
11044 | PCI_ANY_ID, PCI_ANY_ID }, | |
11045 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
11046 | PCI_ANY_ID, PCI_ANY_ID }, | |
11047 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
11048 | PCI_ANY_ID, PCI_ANY_ID }, | |
11049 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
11050 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
11051 | /* Cutlass ~ 3216 and 3224 */ |
11052 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
11053 | PCI_ANY_ID, PCI_ANY_ID }, | |
11054 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
11055 | PCI_ANY_ID, PCI_ANY_ID }, | |
11056 | /* Intruder ~ 3316 and 3324 */ | |
11057 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
11058 | PCI_ANY_ID, PCI_ANY_ID }, | |
11059 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
11060 | PCI_ANY_ID, PCI_ANY_ID }, | |
11061 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
11062 | PCI_ANY_ID, PCI_ANY_ID }, | |
11063 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
11064 | PCI_ANY_ID, PCI_ANY_ID }, | |
11065 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
11066 | PCI_ANY_ID, PCI_ANY_ID }, | |
11067 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
11068 | PCI_ANY_ID, PCI_ANY_ID }, | |
11069 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
11070 | PCI_ANY_ID, PCI_ANY_ID }, | |
11071 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
11072 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
11073 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
11074 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
11075 | PCI_ANY_ID, PCI_ANY_ID }, | |
11076 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
11077 | PCI_ANY_ID, PCI_ANY_ID }, | |
11078 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
11079 | PCI_ANY_ID, PCI_ANY_ID }, | |
11080 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
11081 | PCI_ANY_ID, PCI_ANY_ID }, | |
11082 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
11083 | PCI_ANY_ID, PCI_ANY_ID }, | |
11084 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
11085 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
11086 | /* Mercator ~ 3616*/ |
11087 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
11088 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
11089 | {0} /* Terminating entry */ |
11090 | }; | |
11091 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
11092 | ||
11093 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
11094 | .error_detected = scsih_pci_error_detected, | |
11095 | .mmio_enabled = scsih_pci_mmio_enabled, | |
11096 | .slot_reset = scsih_pci_slot_reset, | |
11097 | .resume = scsih_pci_resume, | |
11098 | }; | |
11099 | ||
11100 | static struct pci_driver mpt3sas_driver = { | |
11101 | .name = MPT3SAS_DRIVER_NAME, | |
11102 | .id_table = mpt3sas_pci_table, | |
11103 | .probe = _scsih_probe, | |
11104 | .remove = scsih_remove, | |
11105 | .shutdown = scsih_shutdown, | |
11106 | .err_handler = &_mpt3sas_err_handler, | |
11107 | #ifdef CONFIG_PM | |
11108 | .suspend = scsih_suspend, | |
11109 | .resume = scsih_resume, | |
11110 | #endif | |
11111 | }; | |
11112 | ||
f92363d1 | 11113 | /** |
8a7e4c24 | 11114 | * scsih_init - main entry point for this driver. |
f92363d1 SR |
11115 | * |
11116 | * Returns 0 success, anything else error. | |
11117 | */ | |
8bbb1cf6 | 11118 | static int |
8a7e4c24 | 11119 | scsih_init(void) |
f92363d1 | 11120 | { |
c84b06a4 SR |
11121 | mpt2_ids = 0; |
11122 | mpt3_ids = 0; | |
f92363d1 | 11123 | |
f92363d1 SR |
11124 | mpt3sas_base_initialize_callback_handler(); |
11125 | ||
11126 | /* queuecommand callback hander */ | |
11127 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
11128 | ||
6c7abffc | 11129 | /* task management callback handler */ |
f92363d1 SR |
11130 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
11131 | ||
11132 | /* base internal commands callback handler */ | |
11133 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
11134 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
11135 | mpt3sas_port_enable_done); | |
11136 | ||
11137 | /* transport internal commands callback handler */ | |
11138 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
11139 | mpt3sas_transport_done); | |
11140 | ||
11141 | /* scsih internal commands callback handler */ | |
11142 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
11143 | ||
11144 | /* configuration page API internal commands callback handler */ | |
11145 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
11146 | mpt3sas_config_done); | |
11147 | ||
11148 | /* ctl module callback handler */ | |
11149 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
11150 | ||
11151 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
11152 | _scsih_tm_tr_complete); | |
11153 | ||
11154 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
11155 | _scsih_tm_volume_tr_complete); | |
11156 | ||
11157 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
11158 | _scsih_sas_control_complete); | |
11159 | ||
7497392a | 11160 | return 0; |
f92363d1 SR |
11161 | } |
11162 | ||
11163 | /** | |
7497392a | 11164 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 SR |
11165 | * |
11166 | * Returns 0 success, anything else error. | |
11167 | */ | |
8bbb1cf6 | 11168 | static void |
8a7e4c24 | 11169 | scsih_exit(void) |
f92363d1 | 11170 | { |
f92363d1 SR |
11171 | |
11172 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
11173 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
11174 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
11175 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
11176 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
11177 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
11178 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
11179 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
11180 | ||
11181 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
11182 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
11183 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
11184 | ||
11185 | /* raid transport support */ | |
c84b06a4 SR |
11186 | if (hbas_to_enumerate != 1) |
11187 | raid_class_release(mpt3sas_raid_template); | |
11188 | if (hbas_to_enumerate != 2) | |
11189 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
11190 | sas_release_transport(mpt3sas_transport_template); |
11191 | } | |
7786ab6a | 11192 | |
c84b06a4 SR |
11193 | /** |
11194 | * _mpt3sas_init - main entry point for this driver. | |
11195 | * | |
11196 | * Returns 0 success, anything else error. | |
11197 | */ | |
11198 | static int __init | |
11199 | _mpt3sas_init(void) | |
11200 | { | |
11201 | int error; | |
11202 | ||
11203 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
11204 | MPT3SAS_DRIVER_VERSION); | |
11205 | ||
11206 | mpt3sas_transport_template = | |
11207 | sas_attach_transport(&mpt3sas_transport_functions); | |
11208 | if (!mpt3sas_transport_template) | |
11209 | return -ENODEV; | |
11210 | ||
11211 | /* No need attach mpt3sas raid functions template | |
11212 | * if hbas_to_enumarate value is one. | |
11213 | */ | |
11214 | if (hbas_to_enumerate != 1) { | |
11215 | mpt3sas_raid_template = | |
11216 | raid_class_attach(&mpt3sas_raid_functions); | |
11217 | if (!mpt3sas_raid_template) { | |
11218 | sas_release_transport(mpt3sas_transport_template); | |
11219 | return -ENODEV; | |
11220 | } | |
11221 | } | |
11222 | ||
11223 | /* No need to attach mpt2sas raid functions template | |
11224 | * if hbas_to_enumarate value is two | |
11225 | */ | |
11226 | if (hbas_to_enumerate != 2) { | |
11227 | mpt2sas_raid_template = | |
11228 | raid_class_attach(&mpt2sas_raid_functions); | |
11229 | if (!mpt2sas_raid_template) { | |
11230 | sas_release_transport(mpt3sas_transport_template); | |
11231 | return -ENODEV; | |
11232 | } | |
11233 | } | |
11234 | ||
11235 | error = scsih_init(); | |
11236 | if (error) { | |
11237 | scsih_exit(); | |
11238 | return error; | |
11239 | } | |
11240 | ||
11241 | mpt3sas_ctl_init(hbas_to_enumerate); | |
11242 | ||
11243 | error = pci_register_driver(&mpt3sas_driver); | |
11244 | if (error) | |
11245 | scsih_exit(); | |
11246 | ||
11247 | return error; | |
11248 | } | |
11249 | ||
11250 | /** | |
11251 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
11252 | * | |
11253 | */ | |
11254 | static void __exit | |
11255 | _mpt3sas_exit(void) | |
11256 | { | |
11257 | pr_info("mpt3sas version %s unloading\n", | |
11258 | MPT3SAS_DRIVER_VERSION); | |
11259 | ||
11260 | pci_unregister_driver(&mpt3sas_driver); | |
11261 | ||
11262 | mpt3sas_ctl_exit(hbas_to_enumerate); | |
11263 | ||
11264 | scsih_exit(); | |
11265 | } | |
11266 | ||
11267 | module_init(_mpt3sas_init); | |
11268 | module_exit(_mpt3sas_exit); |