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); | |
75 | ||
76 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); | |
77 | ||
f92363d1 SR |
78 | /* global parameters */ |
79 | LIST_HEAD(mpt3sas_ioc_list); | |
08c4d550 SR |
80 | /* global ioc lock for list operations */ |
81 | DEFINE_SPINLOCK(gioc_lock); | |
f92363d1 | 82 | |
c84b06a4 SR |
83 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
84 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
85 | MODULE_LICENSE("GPL"); | |
86 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
87 | MODULE_ALIAS("mpt2sas"); | |
88 | ||
f92363d1 SR |
89 | /* local parameters */ |
90 | static u8 scsi_io_cb_idx = -1; | |
91 | static u8 tm_cb_idx = -1; | |
92 | static u8 ctl_cb_idx = -1; | |
93 | static u8 base_cb_idx = -1; | |
94 | static u8 port_enable_cb_idx = -1; | |
95 | static u8 transport_cb_idx = -1; | |
96 | static u8 scsih_cb_idx = -1; | |
97 | static u8 config_cb_idx = -1; | |
c84b06a4 SR |
98 | static int mpt2_ids; |
99 | static int mpt3_ids; | |
f92363d1 SR |
100 | |
101 | static u8 tm_tr_cb_idx = -1 ; | |
102 | static u8 tm_tr_volume_cb_idx = -1 ; | |
103 | static u8 tm_sas_control_cb_idx = -1; | |
104 | ||
105 | /* command line options */ | |
106 | static u32 logging_level; | |
107 | MODULE_PARM_DESC(logging_level, | |
108 | " bits for enabling additional logging info (default=0)"); | |
109 | ||
110 | ||
111 | static ushort max_sectors = 0xFFFF; | |
112 | module_param(max_sectors, ushort, 0); | |
113 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); | |
114 | ||
115 | ||
116 | static int missing_delay[2] = {-1, -1}; | |
117 | module_param_array(missing_delay, int, NULL, 0); | |
118 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | |
119 | ||
120 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
121 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d HR |
122 | static u64 max_lun = MPT3SAS_MAX_LUN; |
123 | module_param(max_lun, ullong, 0); | |
f92363d1 SR |
124 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
125 | ||
c84b06a4 SR |
126 | static ushort hbas_to_enumerate; |
127 | module_param(hbas_to_enumerate, ushort, 0); | |
128 | MODULE_PARM_DESC(hbas_to_enumerate, | |
129 | " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \ | |
130 | 1 - enumerates only SAS 2.0 generation HBAs\n \ | |
131 | 2 - enumerates only SAS 3.0 generation HBAs (default=0)"); | |
f92363d1 SR |
132 | |
133 | /* diag_buffer_enable is bitwise | |
134 | * bit 0 set = TRACE | |
135 | * bit 1 set = SNAPSHOT | |
136 | * bit 2 set = EXTENDED | |
137 | * | |
138 | * Either bit can be set, or both | |
139 | */ | |
140 | static int diag_buffer_enable = -1; | |
141 | module_param(diag_buffer_enable, int, 0); | |
142 | MODULE_PARM_DESC(diag_buffer_enable, | |
143 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
144 | static int disable_discovery = -1; | |
145 | module_param(disable_discovery, int, 0); | |
146 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | |
147 | ||
148 | ||
149 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
150 | static int prot_mask = -1; | |
151 | module_param(prot_mask, int, 0); | |
152 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | |
153 | ||
154 | ||
155 | /* raid transport support */ | |
7497392a | 156 | struct raid_template *mpt3sas_raid_template; |
c84b06a4 | 157 | struct raid_template *mpt2sas_raid_template; |
f92363d1 SR |
158 | |
159 | ||
160 | /** | |
161 | * struct sense_info - common structure for obtaining sense keys | |
162 | * @skey: sense key | |
163 | * @asc: additional sense code | |
164 | * @ascq: additional sense code qualifier | |
165 | */ | |
166 | struct sense_info { | |
167 | u8 skey; | |
168 | u8 asc; | |
169 | u8 ascq; | |
170 | }; | |
171 | ||
172 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
0f624c39 | 173 | #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC) |
f92363d1 SR |
174 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
175 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
176 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
177 | /** | |
178 | * struct fw_event_work - firmware event struct | |
179 | * @list: link list framework | |
180 | * @work: work object (ioc->fault_reset_work_q) | |
f92363d1 SR |
181 | * @ioc: per adapter object |
182 | * @device_handle: device handle | |
183 | * @VF_ID: virtual function id | |
184 | * @VP_ID: virtual port id | |
185 | * @ignore: flag meaning this event has been marked to ignore | |
b8ac0cc7 JL |
186 | * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h |
187 | * @refcount: kref for this event | |
f92363d1 SR |
188 | * @event_data: reply event data payload follows |
189 | * | |
190 | * This object stored on ioc->fw_event_list. | |
191 | */ | |
192 | struct fw_event_work { | |
193 | struct list_head list; | |
194 | struct work_struct work; | |
f92363d1 SR |
195 | |
196 | struct MPT3SAS_ADAPTER *ioc; | |
197 | u16 device_handle; | |
198 | u8 VF_ID; | |
199 | u8 VP_ID; | |
200 | u8 ignore; | |
201 | u16 event; | |
146b16c8 | 202 | struct kref refcount; |
35b62362 | 203 | char event_data[0] __aligned(4); |
f92363d1 SR |
204 | }; |
205 | ||
146b16c8 SR |
206 | static void fw_event_work_free(struct kref *r) |
207 | { | |
208 | kfree(container_of(r, struct fw_event_work, refcount)); | |
209 | } | |
210 | ||
211 | static void fw_event_work_get(struct fw_event_work *fw_work) | |
212 | { | |
213 | kref_get(&fw_work->refcount); | |
214 | } | |
215 | ||
216 | static void fw_event_work_put(struct fw_event_work *fw_work) | |
217 | { | |
218 | kref_put(&fw_work->refcount, fw_event_work_free); | |
219 | } | |
220 | ||
221 | static struct fw_event_work *alloc_fw_event_work(int len) | |
222 | { | |
223 | struct fw_event_work *fw_event; | |
224 | ||
225 | fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC); | |
226 | if (!fw_event) | |
227 | return NULL; | |
228 | ||
229 | kref_init(&fw_event->refcount); | |
230 | return fw_event; | |
231 | } | |
232 | ||
f92363d1 SR |
233 | /** |
234 | * struct _scsi_io_transfer - scsi io transfer | |
235 | * @handle: sas device handle (assigned by firmware) | |
236 | * @is_raid: flag set for hidden raid components | |
237 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
238 | * @data_length: data transfer length | |
239 | * @data_dma: dma pointer to data | |
240 | * @sense: sense data | |
241 | * @lun: lun number | |
242 | * @cdb_length: cdb length | |
243 | * @cdb: cdb contents | |
244 | * @timeout: timeout for this command | |
245 | * @VF_ID: virtual function id | |
246 | * @VP_ID: virtual port id | |
247 | * @valid_reply: flag set for reply message | |
248 | * @sense_length: sense length | |
249 | * @ioc_status: ioc status | |
250 | * @scsi_state: scsi state | |
251 | * @scsi_status: scsi staus | |
252 | * @log_info: log information | |
253 | * @transfer_length: data length transfer when there is a reply message | |
254 | * | |
255 | * Used for sending internal scsi commands to devices within this module. | |
256 | * Refer to _scsi_send_scsi_io(). | |
257 | */ | |
258 | struct _scsi_io_transfer { | |
259 | u16 handle; | |
260 | u8 is_raid; | |
261 | enum dma_data_direction dir; | |
262 | u32 data_length; | |
263 | dma_addr_t data_dma; | |
264 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
265 | u32 lun; | |
266 | u8 cdb_length; | |
267 | u8 cdb[32]; | |
268 | u8 timeout; | |
269 | u8 VF_ID; | |
270 | u8 VP_ID; | |
271 | u8 valid_reply; | |
272 | /* the following bits are only valid when 'valid_reply = 1' */ | |
273 | u32 sense_length; | |
274 | u16 ioc_status; | |
275 | u8 scsi_state; | |
276 | u8 scsi_status; | |
277 | u32 log_info; | |
278 | u32 transfer_length; | |
279 | }; | |
280 | ||
f92363d1 SR |
281 | /** |
282 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
283 | * | |
284 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
285 | */ | |
286 | static int | |
287 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) | |
288 | { | |
289 | int ret = param_set_int(val, kp); | |
290 | struct MPT3SAS_ADAPTER *ioc; | |
291 | ||
292 | if (ret) | |
293 | return ret; | |
294 | ||
295 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
08c4d550 | 296 | spin_lock(&gioc_lock); |
f92363d1 SR |
297 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
298 | ioc->logging_level = logging_level; | |
08c4d550 | 299 | spin_unlock(&gioc_lock); |
f92363d1 SR |
300 | return 0; |
301 | } | |
302 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
303 | &logging_level, 0644); | |
304 | ||
305 | /** | |
306 | * _scsih_srch_boot_sas_address - search based on sas_address | |
307 | * @sas_address: sas address | |
308 | * @boot_device: boot device object from bios page 2 | |
309 | * | |
310 | * Returns 1 when there's a match, 0 means no match. | |
311 | */ | |
312 | static inline int | |
313 | _scsih_srch_boot_sas_address(u64 sas_address, | |
314 | Mpi2BootDeviceSasWwid_t *boot_device) | |
315 | { | |
316 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
317 | } | |
318 | ||
319 | /** | |
320 | * _scsih_srch_boot_device_name - search based on device name | |
321 | * @device_name: device name specified in INDENTIFY fram | |
322 | * @boot_device: boot device object from bios page 2 | |
323 | * | |
324 | * Returns 1 when there's a match, 0 means no match. | |
325 | */ | |
326 | static inline int | |
327 | _scsih_srch_boot_device_name(u64 device_name, | |
328 | Mpi2BootDeviceDeviceName_t *boot_device) | |
329 | { | |
330 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
331 | } | |
332 | ||
333 | /** | |
334 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
335 | * @enclosure_logical_id: enclosure logical id | |
336 | * @slot_number: slot number | |
337 | * @boot_device: boot device object from bios page 2 | |
338 | * | |
339 | * Returns 1 when there's a match, 0 means no match. | |
340 | */ | |
341 | static inline int | |
342 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
343 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
344 | { | |
345 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
346 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
347 | SlotNumber)) ? 1 : 0; | |
348 | } | |
349 | ||
350 | /** | |
351 | * _scsih_is_boot_device - search for matching boot device. | |
352 | * @sas_address: sas address | |
353 | * @device_name: device name specified in INDENTIFY fram | |
354 | * @enclosure_logical_id: enclosure logical id | |
355 | * @slot_number: slot number | |
356 | * @form: specifies boot device form | |
357 | * @boot_device: boot device object from bios page 2 | |
358 | * | |
359 | * Returns 1 when there's a match, 0 means no match. | |
360 | */ | |
361 | static int | |
362 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
363 | u64 enclosure_logical_id, u16 slot, u8 form, | |
364 | Mpi2BiosPage2BootDevice_t *boot_device) | |
365 | { | |
366 | int rc = 0; | |
367 | ||
368 | switch (form) { | |
369 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
370 | if (!sas_address) | |
371 | break; | |
372 | rc = _scsih_srch_boot_sas_address( | |
373 | sas_address, &boot_device->SasWwid); | |
374 | break; | |
375 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
376 | if (!enclosure_logical_id) | |
377 | break; | |
378 | rc = _scsih_srch_boot_encl_slot( | |
379 | enclosure_logical_id, | |
380 | slot, &boot_device->EnclosureSlot); | |
381 | break; | |
382 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
383 | if (!device_name) | |
384 | break; | |
385 | rc = _scsih_srch_boot_device_name( | |
386 | device_name, &boot_device->DeviceName); | |
387 | break; | |
388 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
389 | break; | |
390 | } | |
391 | ||
392 | return rc; | |
393 | } | |
394 | ||
395 | /** | |
396 | * _scsih_get_sas_address - set the sas_address for given device handle | |
397 | * @handle: device handle | |
398 | * @sas_address: sas address | |
399 | * | |
400 | * Returns 0 success, non-zero when failure | |
401 | */ | |
402 | static int | |
403 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
404 | u64 *sas_address) | |
405 | { | |
406 | Mpi2SasDevicePage0_t sas_device_pg0; | |
407 | Mpi2ConfigReply_t mpi_reply; | |
408 | u32 ioc_status; | |
409 | ||
410 | *sas_address = 0; | |
411 | ||
f92363d1 SR |
412 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
413 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
414 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
415 | __FILE__, __LINE__, __func__); | |
416 | return -ENXIO; | |
417 | } | |
418 | ||
419 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
420 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
758f8139 SR |
421 | /* For HBA, vSES doesn't return HBA SAS address. Instead return |
422 | * vSES's sas address. | |
423 | */ | |
424 | if ((handle <= ioc->sas_hba.num_phys) && | |
425 | (!(le32_to_cpu(sas_device_pg0.DeviceInfo) & | |
426 | MPI2_SAS_DEVICE_INFO_SEP))) | |
427 | *sas_address = ioc->sas_hba.sas_address; | |
428 | else | |
429 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
f92363d1 SR |
430 | return 0; |
431 | } | |
432 | ||
6c7abffc | 433 | /* we hit this because the given parent handle doesn't exist */ |
f92363d1 SR |
434 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
435 | return -ENXIO; | |
436 | ||
437 | /* else error case */ | |
438 | pr_err(MPT3SAS_FMT | |
439 | "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", | |
440 | ioc->name, handle, ioc_status, | |
441 | __FILE__, __LINE__, __func__); | |
442 | return -EIO; | |
443 | } | |
444 | ||
445 | /** | |
446 | * _scsih_determine_boot_device - determine boot device. | |
447 | * @ioc: per adapter object | |
d88e1eab SPS |
448 | * @device: sas_device or pcie_device object |
449 | * @channel: SAS or PCIe channel | |
f92363d1 SR |
450 | * |
451 | * Determines whether this device should be first reported device to | |
452 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
453 | * There are primary, alternate, and current entries in bios page 2. The order | |
454 | * priority is primary, alternate, then current. This routine saves | |
d88e1eab | 455 | * the corresponding device object. |
f92363d1 SR |
456 | * The saved data to be used later in _scsih_probe_boot_devices(). |
457 | */ | |
458 | static void | |
d88e1eab SPS |
459 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device, |
460 | u32 channel) | |
f92363d1 SR |
461 | { |
462 | struct _sas_device *sas_device; | |
d88e1eab | 463 | struct _pcie_device *pcie_device; |
f92363d1 SR |
464 | struct _raid_device *raid_device; |
465 | u64 sas_address; | |
466 | u64 device_name; | |
467 | u64 enclosure_logical_id; | |
468 | u16 slot; | |
469 | ||
470 | /* only process this function when driver loads */ | |
471 | if (!ioc->is_driver_loading) | |
472 | return; | |
473 | ||
474 | /* no Bios, return immediately */ | |
475 | if (!ioc->bios_pg3.BiosVersion) | |
476 | return; | |
477 | ||
d88e1eab | 478 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
479 | raid_device = device; |
480 | sas_address = raid_device->wwid; | |
481 | device_name = 0; | |
482 | enclosure_logical_id = 0; | |
483 | slot = 0; | |
d88e1eab SPS |
484 | } else if (channel == PCIE_CHANNEL) { |
485 | pcie_device = device; | |
486 | sas_address = pcie_device->wwid; | |
487 | device_name = 0; | |
488 | enclosure_logical_id = 0; | |
489 | slot = 0; | |
490 | } else { | |
491 | sas_device = device; | |
492 | sas_address = sas_device->sas_address; | |
493 | device_name = sas_device->device_name; | |
494 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
495 | slot = sas_device->slot; | |
f92363d1 SR |
496 | } |
497 | ||
498 | if (!ioc->req_boot_device.device) { | |
499 | if (_scsih_is_boot_device(sas_address, device_name, | |
500 | enclosure_logical_id, slot, | |
501 | (ioc->bios_pg2.ReqBootDeviceForm & | |
502 | MPI2_BIOSPAGE2_FORM_MASK), | |
503 | &ioc->bios_pg2.RequestedBootDevice)) { | |
504 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
505 | "%s: req_boot_device(0x%016llx)\n", | |
506 | ioc->name, __func__, | |
507 | (unsigned long long)sas_address)); | |
508 | ioc->req_boot_device.device = device; | |
d88e1eab | 509 | ioc->req_boot_device.channel = channel; |
f92363d1 SR |
510 | } |
511 | } | |
512 | ||
513 | if (!ioc->req_alt_boot_device.device) { | |
514 | if (_scsih_is_boot_device(sas_address, device_name, | |
515 | enclosure_logical_id, slot, | |
516 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
517 | MPI2_BIOSPAGE2_FORM_MASK), | |
518 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
519 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
520 | "%s: req_alt_boot_device(0x%016llx)\n", | |
521 | ioc->name, __func__, | |
522 | (unsigned long long)sas_address)); | |
523 | ioc->req_alt_boot_device.device = device; | |
d88e1eab | 524 | ioc->req_alt_boot_device.channel = channel; |
f92363d1 SR |
525 | } |
526 | } | |
527 | ||
528 | if (!ioc->current_boot_device.device) { | |
529 | if (_scsih_is_boot_device(sas_address, device_name, | |
530 | enclosure_logical_id, slot, | |
531 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
532 | MPI2_BIOSPAGE2_FORM_MASK), | |
533 | &ioc->bios_pg2.CurrentBootDevice)) { | |
534 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
535 | "%s: current_boot_device(0x%016llx)\n", | |
536 | ioc->name, __func__, | |
537 | (unsigned long long)sas_address)); | |
538 | ioc->current_boot_device.device = device; | |
d88e1eab | 539 | ioc->current_boot_device.channel = channel; |
f92363d1 SR |
540 | } |
541 | } | |
542 | } | |
543 | ||
d1cb5e49 SR |
544 | static struct _sas_device * |
545 | __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
546 | struct MPT3SAS_TARGET *tgt_priv) | |
547 | { | |
548 | struct _sas_device *ret; | |
549 | ||
550 | assert_spin_locked(&ioc->sas_device_lock); | |
551 | ||
d88e1eab | 552 | ret = tgt_priv->sas_dev; |
d1cb5e49 SR |
553 | if (ret) |
554 | sas_device_get(ret); | |
555 | ||
556 | return ret; | |
557 | } | |
558 | ||
559 | static struct _sas_device * | |
560 | mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
561 | struct MPT3SAS_TARGET *tgt_priv) | |
562 | { | |
563 | struct _sas_device *ret; | |
564 | unsigned long flags; | |
565 | ||
566 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
567 | ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv); | |
568 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
569 | ||
570 | return ret; | |
571 | } | |
572 | ||
d88e1eab SPS |
573 | static struct _pcie_device * |
574 | __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
575 | struct MPT3SAS_TARGET *tgt_priv) | |
576 | { | |
577 | struct _pcie_device *ret; | |
578 | ||
579 | assert_spin_locked(&ioc->pcie_device_lock); | |
580 | ||
581 | ret = tgt_priv->pcie_dev; | |
582 | if (ret) | |
583 | pcie_device_get(ret); | |
584 | ||
585 | return ret; | |
586 | } | |
587 | ||
588 | /** | |
589 | * mpt3sas_get_pdev_from_target - pcie device search | |
590 | * @ioc: per adapter object | |
591 | * @tgt_priv: starget private object | |
592 | * | |
593 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
594 | * before returning the pcie_device object. | |
595 | * | |
596 | * This searches for pcie_device from target, then return pcie_device object. | |
597 | */ | |
598 | struct _pcie_device * | |
599 | mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, | |
600 | struct MPT3SAS_TARGET *tgt_priv) | |
601 | { | |
602 | struct _pcie_device *ret; | |
603 | unsigned long flags; | |
604 | ||
605 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
606 | ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv); | |
607 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
608 | ||
609 | return ret; | |
610 | } | |
d1cb5e49 SR |
611 | |
612 | struct _sas_device * | |
613 | __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, | |
614 | u64 sas_address) | |
615 | { | |
616 | struct _sas_device *sas_device; | |
617 | ||
618 | assert_spin_locked(&ioc->sas_device_lock); | |
619 | ||
620 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
621 | if (sas_device->sas_address == sas_address) | |
622 | goto found_device; | |
623 | ||
624 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
625 | if (sas_device->sas_address == sas_address) | |
626 | goto found_device; | |
627 | ||
628 | return NULL; | |
629 | ||
630 | found_device: | |
631 | sas_device_get(sas_device); | |
632 | return sas_device; | |
633 | } | |
634 | ||
f92363d1 | 635 | /** |
d1cb5e49 | 636 | * mpt3sas_get_sdev_by_addr - sas device search |
f92363d1 SR |
637 | * @ioc: per adapter object |
638 | * @sas_address: sas address | |
639 | * Context: Calling function should acquire ioc->sas_device_lock | |
640 | * | |
641 | * This searches for sas_device based on sas_address, then return sas_device | |
642 | * object. | |
643 | */ | |
644 | struct _sas_device * | |
d1cb5e49 | 645 | mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc, |
f92363d1 SR |
646 | u64 sas_address) |
647 | { | |
648 | struct _sas_device *sas_device; | |
d1cb5e49 SR |
649 | unsigned long flags; |
650 | ||
651 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
652 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, | |
653 | sas_address); | |
654 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
655 | ||
656 | return sas_device; | |
657 | } | |
658 | ||
659 | static struct _sas_device * | |
660 | __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
661 | { | |
662 | struct _sas_device *sas_device; | |
663 | ||
664 | assert_spin_locked(&ioc->sas_device_lock); | |
f92363d1 SR |
665 | |
666 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
d1cb5e49 SR |
667 | if (sas_device->handle == handle) |
668 | goto found_device; | |
f92363d1 SR |
669 | |
670 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
d1cb5e49 SR |
671 | if (sas_device->handle == handle) |
672 | goto found_device; | |
f92363d1 SR |
673 | |
674 | return NULL; | |
d1cb5e49 SR |
675 | |
676 | found_device: | |
677 | sas_device_get(sas_device); | |
678 | return sas_device; | |
f92363d1 SR |
679 | } |
680 | ||
681 | /** | |
d1cb5e49 | 682 | * mpt3sas_get_sdev_by_handle - sas device search |
f92363d1 SR |
683 | * @ioc: per adapter object |
684 | * @handle: sas device handle (assigned by firmware) | |
685 | * Context: Calling function should acquire ioc->sas_device_lock | |
686 | * | |
687 | * This searches for sas_device based on sas_address, then return sas_device | |
688 | * object. | |
689 | */ | |
690 | static struct _sas_device * | |
d1cb5e49 | 691 | mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
692 | { |
693 | struct _sas_device *sas_device; | |
d1cb5e49 | 694 | unsigned long flags; |
f92363d1 | 695 | |
d1cb5e49 SR |
696 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
697 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); | |
698 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
f92363d1 | 699 | |
d1cb5e49 | 700 | return sas_device; |
f92363d1 SR |
701 | } |
702 | ||
75888956 SR |
703 | /** |
704 | * _scsih_display_enclosure_chassis_info - display device location info | |
705 | * @ioc: per adapter object | |
706 | * @sas_device: per sas device object | |
707 | * @sdev: scsi device struct | |
708 | * @starget: scsi target struct | |
709 | * | |
710 | * Returns nothing. | |
711 | */ | |
712 | static void | |
713 | _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc, | |
714 | struct _sas_device *sas_device, struct scsi_device *sdev, | |
715 | struct scsi_target *starget) | |
716 | { | |
717 | if (sdev) { | |
718 | if (sas_device->enclosure_handle != 0) | |
719 | sdev_printk(KERN_INFO, sdev, | |
720 | "enclosure logical id (0x%016llx), slot(%d) \n", | |
721 | (unsigned long long) | |
722 | sas_device->enclosure_logical_id, | |
723 | sas_device->slot); | |
724 | if (sas_device->connector_name[0] != '\0') | |
725 | sdev_printk(KERN_INFO, sdev, | |
726 | "enclosure level(0x%04x), connector name( %s)\n", | |
727 | sas_device->enclosure_level, | |
728 | sas_device->connector_name); | |
729 | if (sas_device->is_chassis_slot_valid) | |
730 | sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n", | |
731 | sas_device->chassis_slot); | |
732 | } else if (starget) { | |
733 | if (sas_device->enclosure_handle != 0) | |
734 | starget_printk(KERN_INFO, starget, | |
735 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
736 | (unsigned long long) | |
737 | sas_device->enclosure_logical_id, | |
738 | sas_device->slot); | |
739 | if (sas_device->connector_name[0] != '\0') | |
740 | starget_printk(KERN_INFO, starget, | |
741 | "enclosure level(0x%04x), connector name( %s)\n", | |
742 | sas_device->enclosure_level, | |
743 | sas_device->connector_name); | |
744 | if (sas_device->is_chassis_slot_valid) | |
745 | starget_printk(KERN_INFO, starget, | |
746 | "chassis slot(0x%04x)\n", | |
747 | sas_device->chassis_slot); | |
748 | } else { | |
749 | if (sas_device->enclosure_handle != 0) | |
750 | pr_info(MPT3SAS_FMT | |
751 | "enclosure logical id(0x%016llx), slot(%d) \n", | |
752 | ioc->name, (unsigned long long) | |
753 | sas_device->enclosure_logical_id, | |
754 | sas_device->slot); | |
755 | if (sas_device->connector_name[0] != '\0') | |
756 | pr_info(MPT3SAS_FMT | |
757 | "enclosure level(0x%04x), connector name( %s)\n", | |
758 | ioc->name, sas_device->enclosure_level, | |
759 | sas_device->connector_name); | |
760 | if (sas_device->is_chassis_slot_valid) | |
761 | pr_info(MPT3SAS_FMT "chassis slot(0x%04x)\n", | |
762 | ioc->name, sas_device->chassis_slot); | |
763 | } | |
764 | } | |
765 | ||
f92363d1 SR |
766 | /** |
767 | * _scsih_sas_device_remove - remove sas_device from list. | |
768 | * @ioc: per adapter object | |
769 | * @sas_device: the sas_device object | |
770 | * Context: This function will acquire ioc->sas_device_lock. | |
771 | * | |
d1cb5e49 | 772 | * If sas_device is on the list, remove it and decrement its reference count. |
f92363d1 SR |
773 | */ |
774 | static void | |
775 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
776 | struct _sas_device *sas_device) | |
777 | { | |
778 | unsigned long flags; | |
779 | ||
780 | if (!sas_device) | |
781 | return; | |
e6d45e3e SR |
782 | pr_info(MPT3SAS_FMT |
783 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
784 | ioc->name, sas_device->handle, | |
785 | (unsigned long long) sas_device->sas_address); | |
786 | ||
75888956 | 787 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); |
f92363d1 | 788 | |
d1cb5e49 SR |
789 | /* |
790 | * The lock serializes access to the list, but we still need to verify | |
791 | * that nobody removed the entry while we were waiting on the lock. | |
792 | */ | |
f92363d1 | 793 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
794 | if (!list_empty(&sas_device->list)) { |
795 | list_del_init(&sas_device->list); | |
796 | sas_device_put(sas_device); | |
797 | } | |
f92363d1 SR |
798 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
799 | } | |
800 | ||
801 | /** | |
802 | * _scsih_device_remove_by_handle - removing device object by handle | |
803 | * @ioc: per adapter object | |
804 | * @handle: device handle | |
805 | * | |
806 | * Return nothing. | |
807 | */ | |
808 | static void | |
809 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
810 | { | |
811 | struct _sas_device *sas_device; | |
812 | unsigned long flags; | |
813 | ||
814 | if (ioc->shost_recovery) | |
815 | return; | |
816 | ||
817 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
818 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
819 | if (sas_device) { | |
820 | list_del_init(&sas_device->list); | |
821 | sas_device_put(sas_device); | |
822 | } | |
f92363d1 | 823 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 824 | if (sas_device) { |
f92363d1 | 825 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
826 | sas_device_put(sas_device); |
827 | } | |
f92363d1 SR |
828 | } |
829 | ||
830 | /** | |
831 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
832 | * @ioc: per adapter object | |
833 | * @sas_address: device sas_address | |
834 | * | |
835 | * Return nothing. | |
836 | */ | |
837 | void | |
838 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
839 | u64 sas_address) | |
840 | { | |
841 | struct _sas_device *sas_device; | |
842 | unsigned long flags; | |
843 | ||
844 | if (ioc->shost_recovery) | |
845 | return; | |
846 | ||
847 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
848 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address); |
849 | if (sas_device) { | |
850 | list_del_init(&sas_device->list); | |
851 | sas_device_put(sas_device); | |
852 | } | |
f92363d1 | 853 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 854 | if (sas_device) { |
f92363d1 | 855 | _scsih_remove_device(ioc, sas_device); |
d1cb5e49 SR |
856 | sas_device_put(sas_device); |
857 | } | |
f92363d1 SR |
858 | } |
859 | ||
860 | /** | |
861 | * _scsih_sas_device_add - insert sas_device to the list. | |
862 | * @ioc: per adapter object | |
863 | * @sas_device: the sas_device object | |
864 | * Context: This function will acquire ioc->sas_device_lock. | |
865 | * | |
866 | * Adding new object to the ioc->sas_device_list. | |
867 | */ | |
868 | static void | |
869 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
870 | struct _sas_device *sas_device) | |
871 | { | |
872 | unsigned long flags; | |
873 | ||
874 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
875 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
876 | ioc->name, __func__, sas_device->handle, | |
877 | (unsigned long long)sas_device->sas_address)); | |
878 | ||
75888956 SR |
879 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
880 | NULL, NULL)); | |
e6d45e3e | 881 | |
f92363d1 | 882 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 883 | sas_device_get(sas_device); |
f92363d1 SR |
884 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
885 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
886 | ||
c696f7b8 SPS |
887 | if (ioc->hide_drives) { |
888 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
889 | return; | |
890 | } | |
891 | ||
f92363d1 SR |
892 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
893 | sas_device->sas_address_parent)) { | |
894 | _scsih_sas_device_remove(ioc, sas_device); | |
895 | } else if (!sas_device->starget) { | |
896 | /* | |
897 | * When asyn scanning is enabled, its not possible to remove | |
898 | * devices while scanning is turned on due to an oops in | |
899 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
900 | */ | |
f5edbe77 | 901 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
902 | mpt3sas_transport_port_remove(ioc, |
903 | sas_device->sas_address, | |
904 | sas_device->sas_address_parent); | |
f5edbe77 SR |
905 | _scsih_sas_device_remove(ioc, sas_device); |
906 | } | |
c696f7b8 SPS |
907 | } else |
908 | clear_bit(sas_device->handle, ioc->pend_os_device_add); | |
f92363d1 SR |
909 | } |
910 | ||
911 | /** | |
912 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
913 | * @ioc: per adapter object | |
914 | * @sas_device: the sas_device object | |
915 | * Context: This function will acquire ioc->sas_device_lock. | |
916 | * | |
917 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
918 | */ | |
919 | static void | |
920 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
921 | struct _sas_device *sas_device) | |
922 | { | |
923 | unsigned long flags; | |
924 | ||
925 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
926 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
927 | __func__, sas_device->handle, | |
928 | (unsigned long long)sas_device->sas_address)); | |
929 | ||
75888956 SR |
930 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
931 | NULL, NULL)); | |
e6d45e3e | 932 | |
f92363d1 | 933 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 934 | sas_device_get(sas_device); |
f92363d1 SR |
935 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
936 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
937 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
938 | } | |
939 | ||
d88e1eab SPS |
940 | |
941 | struct _pcie_device * | |
942 | __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
943 | { | |
944 | struct _pcie_device *pcie_device; | |
945 | ||
946 | assert_spin_locked(&ioc->pcie_device_lock); | |
947 | ||
948 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
949 | if (pcie_device->wwid == wwid) | |
950 | goto found_device; | |
951 | ||
952 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
953 | if (pcie_device->wwid == wwid) | |
954 | goto found_device; | |
955 | ||
956 | return NULL; | |
957 | ||
958 | found_device: | |
959 | pcie_device_get(pcie_device); | |
960 | return pcie_device; | |
961 | } | |
962 | ||
963 | ||
964 | /** | |
965 | * mpt3sas_get_pdev_by_wwid - pcie device search | |
966 | * @ioc: per adapter object | |
967 | * @wwid: wwid | |
968 | * | |
969 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
970 | * before returning the pcie_device object. | |
971 | * | |
972 | * This searches for pcie_device based on wwid, then return pcie_device object. | |
973 | */ | |
974 | struct _pcie_device * | |
975 | mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
976 | { | |
977 | struct _pcie_device *pcie_device; | |
978 | unsigned long flags; | |
979 | ||
980 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
981 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid); | |
982 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
983 | ||
984 | return pcie_device; | |
985 | } | |
986 | ||
987 | ||
988 | struct _pcie_device * | |
989 | __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, | |
990 | int channel) | |
991 | { | |
992 | struct _pcie_device *pcie_device; | |
993 | ||
994 | assert_spin_locked(&ioc->pcie_device_lock); | |
995 | ||
996 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) | |
997 | if (pcie_device->id == id && pcie_device->channel == channel) | |
998 | goto found_device; | |
999 | ||
1000 | list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list) | |
1001 | if (pcie_device->id == id && pcie_device->channel == channel) | |
1002 | goto found_device; | |
1003 | ||
1004 | return NULL; | |
1005 | ||
1006 | found_device: | |
1007 | pcie_device_get(pcie_device); | |
1008 | return pcie_device; | |
1009 | } | |
1010 | ||
1011 | ||
1012 | /** | |
1013 | * mpt3sas_get_pdev_by_idchannel - pcie device search | |
1014 | * @ioc: per adapter object | |
1015 | * @id: Target ID | |
1016 | * @channel: Channel ID | |
1017 | * | |
1018 | * Context: This function will acquire ioc->pcie_device_lock and will release | |
1019 | * before returning the pcie_device object. | |
1020 | * | |
1021 | * This searches for pcie_device based on id and channel, then return | |
1022 | * pcie_device object. | |
1023 | */ | |
1024 | struct _pcie_device * | |
1025 | mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1026 | { | |
1027 | struct _pcie_device *pcie_device; | |
1028 | unsigned long flags; | |
1029 | ||
1030 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1031 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, id, channel); | |
1032 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1033 | ||
1034 | return pcie_device; | |
1035 | } | |
1036 | /** | |
1037 | * _scsih_pcie_device_remove - remove pcie_device from list. | |
1038 | * @ioc: per adapter object | |
1039 | * @pcie_device: the pcie_device object | |
1040 | * Context: This function will acquire ioc->pcie_device_lock. | |
1041 | * | |
1042 | * If pcie_device is on the list, remove it and decrement its reference count. | |
1043 | */ | |
1044 | static void | |
1045 | _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1046 | struct _pcie_device *pcie_device) | |
1047 | { | |
1048 | unsigned long flags; | |
1049 | int was_on_pcie_device_list = 0; | |
1050 | ||
1051 | if (!pcie_device) | |
1052 | return; | |
1053 | pr_info(MPT3SAS_FMT | |
1054 | "removing handle(0x%04x), wwid(0x%016llx)\n", | |
1055 | ioc->name, pcie_device->handle, | |
1056 | (unsigned long long) pcie_device->wwid); | |
1057 | if (pcie_device->enclosure_handle != 0) | |
1058 | pr_info(MPT3SAS_FMT | |
1059 | "removing enclosure logical id(0x%016llx), slot(%d)\n", | |
1060 | ioc->name, | |
1061 | (unsigned long long)pcie_device->enclosure_logical_id, | |
1062 | pcie_device->slot); | |
1063 | if (pcie_device->connector_name[0] != '\0') | |
1064 | pr_info(MPT3SAS_FMT | |
1065 | "removing enclosure level(0x%04x), connector name( %s)\n", | |
1066 | ioc->name, pcie_device->enclosure_level, | |
1067 | pcie_device->connector_name); | |
1068 | ||
1069 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1070 | if (!list_empty(&pcie_device->list)) { | |
1071 | list_del_init(&pcie_device->list); | |
1072 | was_on_pcie_device_list = 1; | |
1073 | } | |
1074 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1075 | if (was_on_pcie_device_list) { | |
1076 | kfree(pcie_device->serial_number); | |
1077 | pcie_device_put(pcie_device); | |
1078 | } | |
1079 | } | |
f92363d1 SR |
1080 | /** |
1081 | * _scsih_raid_device_find_by_id - raid device search | |
1082 | * @ioc: per adapter object | |
1083 | * @id: sas device target id | |
1084 | * @channel: sas device channel | |
1085 | * Context: Calling function should acquire ioc->raid_device_lock | |
1086 | * | |
1087 | * This searches for raid_device based on target id, then return raid_device | |
1088 | * object. | |
1089 | */ | |
1090 | static struct _raid_device * | |
1091 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
1092 | { | |
1093 | struct _raid_device *raid_device, *r; | |
1094 | ||
1095 | r = NULL; | |
1096 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1097 | if (raid_device->id == id && raid_device->channel == channel) { | |
1098 | r = raid_device; | |
1099 | goto out; | |
1100 | } | |
1101 | } | |
1102 | ||
1103 | out: | |
1104 | return r; | |
1105 | } | |
1106 | ||
1107 | /** | |
c84b06a4 | 1108 | * mpt3sas_raid_device_find_by_handle - raid device search |
f92363d1 SR |
1109 | * @ioc: per adapter object |
1110 | * @handle: sas device handle (assigned by firmware) | |
1111 | * Context: Calling function should acquire ioc->raid_device_lock | |
1112 | * | |
1113 | * This searches for raid_device based on handle, then return raid_device | |
1114 | * object. | |
1115 | */ | |
c84b06a4 SR |
1116 | struct _raid_device * |
1117 | mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
f92363d1 SR |
1118 | { |
1119 | struct _raid_device *raid_device, *r; | |
1120 | ||
1121 | r = NULL; | |
1122 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1123 | if (raid_device->handle != handle) | |
1124 | continue; | |
1125 | r = raid_device; | |
1126 | goto out; | |
1127 | } | |
1128 | ||
1129 | out: | |
1130 | return r; | |
1131 | } | |
1132 | ||
1133 | /** | |
1134 | * _scsih_raid_device_find_by_wwid - raid device search | |
1135 | * @ioc: per adapter object | |
1136 | * @handle: sas device handle (assigned by firmware) | |
1137 | * Context: Calling function should acquire ioc->raid_device_lock | |
1138 | * | |
1139 | * This searches for raid_device based on wwid, then return raid_device | |
1140 | * object. | |
1141 | */ | |
1142 | static struct _raid_device * | |
1143 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
1144 | { | |
1145 | struct _raid_device *raid_device, *r; | |
1146 | ||
1147 | r = NULL; | |
1148 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
1149 | if (raid_device->wwid != wwid) | |
1150 | continue; | |
1151 | r = raid_device; | |
1152 | goto out; | |
1153 | } | |
1154 | ||
1155 | out: | |
1156 | return r; | |
1157 | } | |
1158 | ||
1159 | /** | |
1160 | * _scsih_raid_device_add - add raid_device object | |
1161 | * @ioc: per adapter object | |
1162 | * @raid_device: raid_device object | |
1163 | * | |
1164 | * This is added to the raid_device_list link list. | |
1165 | */ | |
1166 | static void | |
1167 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
1168 | struct _raid_device *raid_device) | |
1169 | { | |
1170 | unsigned long flags; | |
1171 | ||
1172 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
1173 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
1174 | raid_device->handle, (unsigned long long)raid_device->wwid)); | |
1175 | ||
1176 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1177 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
1178 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1179 | } | |
1180 | ||
1181 | /** | |
1182 | * _scsih_raid_device_remove - delete raid_device object | |
1183 | * @ioc: per adapter object | |
1184 | * @raid_device: raid_device object | |
1185 | * | |
1186 | */ | |
1187 | static void | |
1188 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
1189 | struct _raid_device *raid_device) | |
1190 | { | |
1191 | unsigned long flags; | |
1192 | ||
1193 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1194 | list_del(&raid_device->list); | |
1195 | kfree(raid_device); | |
1196 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1197 | } | |
1198 | ||
1199 | /** | |
1200 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
1201 | * @ioc: per adapter object | |
1202 | * @handle: expander handle (assigned by firmware) | |
1203 | * Context: Calling function should acquire ioc->sas_device_lock | |
1204 | * | |
1205 | * This searches for expander device based on handle, then returns the | |
1206 | * sas_node object. | |
1207 | */ | |
1208 | struct _sas_node * | |
1209 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1210 | { | |
1211 | struct _sas_node *sas_expander, *r; | |
1212 | ||
1213 | r = NULL; | |
1214 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1215 | if (sas_expander->handle != handle) | |
1216 | continue; | |
1217 | r = sas_expander; | |
1218 | goto out; | |
1219 | } | |
1220 | out: | |
1221 | return r; | |
1222 | } | |
1223 | ||
1224 | /** | |
1225 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
1226 | * @ioc: per adapter object | |
1227 | * @sas_address: sas address | |
1228 | * Context: Calling function should acquire ioc->sas_node_lock. | |
1229 | * | |
1230 | * This searches for expander device based on sas_address, then returns the | |
1231 | * sas_node object. | |
1232 | */ | |
1233 | struct _sas_node * | |
1234 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
1235 | u64 sas_address) | |
1236 | { | |
1237 | struct _sas_node *sas_expander, *r; | |
1238 | ||
1239 | r = NULL; | |
1240 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
1241 | if (sas_expander->sas_address != sas_address) | |
1242 | continue; | |
1243 | r = sas_expander; | |
1244 | goto out; | |
1245 | } | |
1246 | out: | |
1247 | return r; | |
1248 | } | |
1249 | ||
1250 | /** | |
1251 | * _scsih_expander_node_add - insert expander device to the list. | |
1252 | * @ioc: per adapter object | |
1253 | * @sas_expander: the sas_device object | |
1254 | * Context: This function will acquire ioc->sas_node_lock. | |
1255 | * | |
1256 | * Adding new object to the ioc->sas_expander_list. | |
1257 | * | |
1258 | * Return nothing. | |
1259 | */ | |
1260 | static void | |
1261 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
1262 | struct _sas_node *sas_expander) | |
1263 | { | |
1264 | unsigned long flags; | |
1265 | ||
1266 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
1267 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
1268 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
1269 | } | |
1270 | ||
1271 | /** | |
1272 | * _scsih_is_end_device - determines if device is an end device | |
1273 | * @device_info: bitfield providing information about the device. | |
1274 | * Context: none | |
1275 | * | |
1276 | * Returns 1 if end device. | |
1277 | */ | |
1278 | static int | |
1279 | _scsih_is_end_device(u32 device_info) | |
1280 | { | |
1281 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
1282 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
1283 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
1284 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
1285 | return 1; | |
1286 | else | |
1287 | return 0; | |
1288 | } | |
1289 | ||
1290 | /** | |
1291 | * _scsih_scsi_lookup_get - returns scmd entry | |
1292 | * @ioc: per adapter object | |
1293 | * @smid: system request message index | |
1294 | * | |
1295 | * Returns the smid stored scmd pointer. | |
1296 | */ | |
1297 | static struct scsi_cmnd * | |
1298 | _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
1299 | { | |
1300 | return ioc->scsi_lookup[smid - 1].scmd; | |
1301 | } | |
1302 | ||
459325c4 C |
1303 | /** |
1304 | * __scsih_scsi_lookup_get_clear - returns scmd entry without | |
1305 | * holding any lock. | |
1306 | * @ioc: per adapter object | |
1307 | * @smid: system request message index | |
1308 | * | |
1309 | * Returns the smid stored scmd pointer. | |
1310 | * Then will dereference the stored scmd pointer. | |
1311 | */ | |
1312 | static inline struct scsi_cmnd * | |
1313 | __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, | |
1314 | u16 smid) | |
1315 | { | |
1316 | struct scsi_cmnd *scmd = NULL; | |
1317 | ||
1318 | swap(scmd, ioc->scsi_lookup[smid - 1].scmd); | |
1319 | ||
1320 | return scmd; | |
1321 | } | |
1322 | ||
f92363d1 SR |
1323 | /** |
1324 | * _scsih_scsi_lookup_get_clear - returns scmd entry | |
1325 | * @ioc: per adapter object | |
1326 | * @smid: system request message index | |
1327 | * | |
1328 | * Returns the smid stored scmd pointer. | |
1329 | * Then will derefrence the stored scmd pointer. | |
1330 | */ | |
1331 | static inline struct scsi_cmnd * | |
1332 | _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
1333 | { | |
1334 | unsigned long flags; | |
1335 | struct scsi_cmnd *scmd; | |
1336 | ||
1337 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
459325c4 | 1338 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); |
f92363d1 SR |
1339 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
1340 | ||
1341 | return scmd; | |
1342 | } | |
1343 | ||
1344 | /** | |
1345 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup | |
1346 | * @ioc: per adapter object | |
1347 | * @smid: system request message index | |
1348 | * @scmd: pointer to scsi command object | |
1349 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1350 | * | |
1351 | * This will search for a scmd pointer in the scsi_lookup array, | |
1352 | * returning the revelent smid. A returned value of zero means invalid. | |
1353 | */ | |
1354 | static u16 | |
1355 | _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd | |
1356 | *scmd) | |
1357 | { | |
1358 | u16 smid; | |
1359 | unsigned long flags; | |
1360 | int i; | |
1361 | ||
1362 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1363 | smid = 0; | |
1364 | for (i = 0; i < ioc->scsiio_depth; i++) { | |
1365 | if (ioc->scsi_lookup[i].scmd == scmd) { | |
1366 | smid = ioc->scsi_lookup[i].smid; | |
1367 | goto out; | |
1368 | } | |
1369 | } | |
1370 | out: | |
1371 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1372 | return smid; | |
1373 | } | |
1374 | ||
1375 | /** | |
1376 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id | |
1377 | * @ioc: per adapter object | |
1378 | * @id: target id | |
1379 | * @channel: channel | |
1380 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1381 | * | |
1382 | * This will search for a matching channel:id in the scsi_lookup array, | |
1383 | * returning 1 if found. | |
1384 | */ | |
1385 | static u8 | |
1386 | _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id, | |
1387 | int channel) | |
1388 | { | |
1389 | u8 found; | |
1390 | unsigned long flags; | |
1391 | int i; | |
1392 | ||
1393 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1394 | found = 0; | |
1395 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1396 | if (ioc->scsi_lookup[i].scmd && | |
1397 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1398 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { | |
1399 | found = 1; | |
1400 | goto out; | |
1401 | } | |
1402 | } | |
1403 | out: | |
1404 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1405 | return found; | |
1406 | } | |
1407 | ||
1408 | /** | |
1409 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun | |
1410 | * @ioc: per adapter object | |
1411 | * @id: target id | |
1412 | * @lun: lun number | |
1413 | * @channel: channel | |
1414 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1415 | * | |
1416 | * This will search for a matching channel:id:lun in the scsi_lookup array, | |
1417 | * returning 1 if found. | |
1418 | */ | |
1419 | static u8 | |
1420 | _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id, | |
1421 | unsigned int lun, int channel) | |
1422 | { | |
1423 | u8 found; | |
1424 | unsigned long flags; | |
1425 | int i; | |
1426 | ||
1427 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1428 | found = 0; | |
1429 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1430 | if (ioc->scsi_lookup[i].scmd && | |
1431 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1432 | ioc->scsi_lookup[i].scmd->device->channel == channel && | |
1433 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { | |
1434 | found = 1; | |
1435 | goto out; | |
1436 | } | |
1437 | } | |
1438 | out: | |
1439 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1440 | return found; | |
1441 | } | |
1442 | ||
cf75d5d6 | 1443 | /** |
8a7e4c24 | 1444 | * scsih_change_queue_depth - setting device queue depth |
cf75d5d6 CH |
1445 | * @sdev: scsi device struct |
1446 | * @qdepth: requested queue depth | |
1447 | * | |
1448 | * Returns queue depth. | |
1449 | */ | |
8bbb1cf6 | 1450 | static int |
8a7e4c24 | 1451 | scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
f92363d1 SR |
1452 | { |
1453 | struct Scsi_Host *shost = sdev->host; | |
1454 | int max_depth; | |
1455 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1456 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1457 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1458 | struct _sas_device *sas_device; | |
1459 | unsigned long flags; | |
1460 | ||
1461 | max_depth = shost->can_queue; | |
1462 | ||
1463 | /* limit max device queue for SATA to 32 */ | |
1464 | sas_device_priv_data = sdev->hostdata; | |
1465 | if (!sas_device_priv_data) | |
1466 | goto not_sata; | |
1467 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1468 | if (!sas_target_priv_data) | |
1469 | goto not_sata; | |
1470 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1471 | goto not_sata; | |
d1cb5e49 | 1472 | |
f92363d1 | 1473 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1474 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
1475 | if (sas_device) { | |
1476 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1477 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1478 | ||
1479 | sas_device_put(sas_device); | |
1480 | } | |
f92363d1 SR |
1481 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1482 | ||
1483 | not_sata: | |
1484 | ||
1485 | if (!sdev->tagged_supported) | |
1486 | max_depth = 1; | |
1487 | if (qdepth > max_depth) | |
1488 | qdepth = max_depth; | |
cf75d5d6 | 1489 | return scsi_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
1490 | } |
1491 | ||
f92363d1 | 1492 | /** |
8a7e4c24 | 1493 | * scsih_target_alloc - target add routine |
f92363d1 SR |
1494 | * @starget: scsi target struct |
1495 | * | |
1496 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1497 | * the device is ignored. | |
1498 | */ | |
8bbb1cf6 | 1499 | static int |
8a7e4c24 | 1500 | scsih_target_alloc(struct scsi_target *starget) |
f92363d1 SR |
1501 | { |
1502 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1503 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1504 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1505 | struct _sas_device *sas_device; | |
1506 | struct _raid_device *raid_device; | |
d88e1eab | 1507 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1508 | unsigned long flags; |
1509 | struct sas_rphy *rphy; | |
1510 | ||
62c4da44 JL |
1511 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1512 | GFP_KERNEL); | |
f92363d1 SR |
1513 | if (!sas_target_priv_data) |
1514 | return -ENOMEM; | |
1515 | ||
1516 | starget->hostdata = sas_target_priv_data; | |
1517 | sas_target_priv_data->starget = starget; | |
1518 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1519 | ||
1520 | /* RAID volumes */ | |
1521 | if (starget->channel == RAID_CHANNEL) { | |
1522 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1523 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1524 | starget->channel); | |
1525 | if (raid_device) { | |
1526 | sas_target_priv_data->handle = raid_device->handle; | |
1527 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1528 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
7786ab6a | 1529 | if (ioc->is_warpdrive) |
6d3a56ed SR |
1530 | sas_target_priv_data->raid_device = raid_device; |
1531 | raid_device->starget = starget; | |
f92363d1 SR |
1532 | } |
1533 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1534 | return 0; | |
1535 | } | |
1536 | ||
d88e1eab SPS |
1537 | /* PCIe devices */ |
1538 | if (starget->channel == PCIE_CHANNEL) { | |
1539 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1540 | pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id, | |
1541 | starget->channel); | |
1542 | if (pcie_device) { | |
1543 | sas_target_priv_data->handle = pcie_device->handle; | |
1544 | sas_target_priv_data->sas_address = pcie_device->wwid; | |
1545 | sas_target_priv_data->pcie_dev = pcie_device; | |
1546 | pcie_device->starget = starget; | |
1547 | pcie_device->id = starget->id; | |
1548 | pcie_device->channel = starget->channel; | |
1549 | sas_target_priv_data->flags |= | |
1550 | MPT_TARGET_FLAGS_PCIE_DEVICE; | |
1551 | if (pcie_device->fast_path) | |
1552 | sas_target_priv_data->flags |= | |
1553 | MPT_TARGET_FASTPATH_IO; | |
1554 | } | |
1555 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1556 | return 0; | |
1557 | } | |
1558 | ||
f92363d1 SR |
1559 | /* sas/sata devices */ |
1560 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1561 | rphy = dev_to_rphy(starget->dev.parent); | |
d1cb5e49 | 1562 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
1563 | rphy->identify.sas_address); |
1564 | ||
1565 | if (sas_device) { | |
1566 | sas_target_priv_data->handle = sas_device->handle; | |
1567 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
d88e1eab | 1568 | sas_target_priv_data->sas_dev = sas_device; |
f92363d1 SR |
1569 | sas_device->starget = starget; |
1570 | sas_device->id = starget->id; | |
1571 | sas_device->channel = starget->channel; | |
1572 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1573 | sas_target_priv_data->flags |= | |
1574 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1575 | if (sas_device->fast_path) | |
d88e1eab SPS |
1576 | sas_target_priv_data->flags |= |
1577 | MPT_TARGET_FASTPATH_IO; | |
f92363d1 SR |
1578 | } |
1579 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1580 | ||
1581 | return 0; | |
1582 | } | |
1583 | ||
1584 | /** | |
8a7e4c24 | 1585 | * scsih_target_destroy - target destroy routine |
f92363d1 SR |
1586 | * @starget: scsi target struct |
1587 | * | |
1588 | * Returns nothing. | |
1589 | */ | |
8bbb1cf6 | 1590 | static void |
8a7e4c24 | 1591 | scsih_target_destroy(struct scsi_target *starget) |
f92363d1 SR |
1592 | { |
1593 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1594 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1595 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1596 | struct _sas_device *sas_device; | |
1597 | struct _raid_device *raid_device; | |
d88e1eab | 1598 | struct _pcie_device *pcie_device; |
f92363d1 | 1599 | unsigned long flags; |
d88e1eab | 1600 | struct sas_rphy *rphy; |
f92363d1 SR |
1601 | |
1602 | sas_target_priv_data = starget->hostdata; | |
1603 | if (!sas_target_priv_data) | |
1604 | return; | |
1605 | ||
1606 | if (starget->channel == RAID_CHANNEL) { | |
1607 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1608 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1609 | starget->channel); | |
1610 | if (raid_device) { | |
1611 | raid_device->starget = NULL; | |
1612 | raid_device->sdev = NULL; | |
1613 | } | |
1614 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1615 | goto out; | |
1616 | } | |
1617 | ||
d88e1eab SPS |
1618 | if (starget->channel == PCIE_CHANNEL) { |
1619 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1620 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1621 | sas_target_priv_data); | |
1622 | if (pcie_device && (pcie_device->starget == starget) && | |
1623 | (pcie_device->id == starget->id) && | |
1624 | (pcie_device->channel == starget->channel)) | |
1625 | pcie_device->starget = NULL; | |
1626 | ||
1627 | if (pcie_device) { | |
1628 | /* | |
1629 | * Corresponding get() is in _scsih_target_alloc() | |
1630 | */ | |
1631 | sas_target_priv_data->pcie_dev = NULL; | |
1632 | pcie_device_put(pcie_device); | |
1633 | pcie_device_put(pcie_device); | |
1634 | } | |
1635 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1636 | goto out; | |
1637 | } | |
1638 | ||
f92363d1 | 1639 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d88e1eab | 1640 | rphy = dev_to_rphy(starget->dev.parent); |
d1cb5e49 | 1641 | sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data); |
f92363d1 SR |
1642 | if (sas_device && (sas_device->starget == starget) && |
1643 | (sas_device->id == starget->id) && | |
1644 | (sas_device->channel == starget->channel)) | |
1645 | sas_device->starget = NULL; | |
1646 | ||
d1cb5e49 SR |
1647 | if (sas_device) { |
1648 | /* | |
1649 | * Corresponding get() is in _scsih_target_alloc() | |
1650 | */ | |
d88e1eab | 1651 | sas_target_priv_data->sas_dev = NULL; |
d1cb5e49 SR |
1652 | sas_device_put(sas_device); |
1653 | ||
1654 | sas_device_put(sas_device); | |
1655 | } | |
f92363d1 SR |
1656 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1657 | ||
1658 | out: | |
1659 | kfree(sas_target_priv_data); | |
1660 | starget->hostdata = NULL; | |
1661 | } | |
1662 | ||
1663 | /** | |
8a7e4c24 | 1664 | * scsih_slave_alloc - device add routine |
f92363d1 SR |
1665 | * @sdev: scsi device struct |
1666 | * | |
1667 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1668 | * the device is ignored. | |
1669 | */ | |
8bbb1cf6 | 1670 | static int |
8a7e4c24 | 1671 | scsih_slave_alloc(struct scsi_device *sdev) |
f92363d1 SR |
1672 | { |
1673 | struct Scsi_Host *shost; | |
1674 | struct MPT3SAS_ADAPTER *ioc; | |
1675 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1676 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1677 | struct scsi_target *starget; | |
1678 | struct _raid_device *raid_device; | |
b65cfedf | 1679 | struct _sas_device *sas_device; |
d88e1eab | 1680 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1681 | unsigned long flags; |
1682 | ||
62c4da44 JL |
1683 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1684 | GFP_KERNEL); | |
f92363d1 SR |
1685 | if (!sas_device_priv_data) |
1686 | return -ENOMEM; | |
1687 | ||
1688 | sas_device_priv_data->lun = sdev->lun; | |
1689 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1690 | ||
1691 | starget = scsi_target(sdev); | |
1692 | sas_target_priv_data = starget->hostdata; | |
1693 | sas_target_priv_data->num_luns++; | |
1694 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1695 | sdev->hostdata = sas_device_priv_data; | |
1696 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1697 | sdev->no_uld_attach = 1; | |
1698 | ||
1699 | shost = dev_to_shost(&starget->dev); | |
1700 | ioc = shost_priv(shost); | |
1701 | if (starget->channel == RAID_CHANNEL) { | |
1702 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1703 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1704 | starget->id, starget->channel); | |
1705 | if (raid_device) | |
1706 | raid_device->sdev = sdev; /* raid is single lun */ | |
1707 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1708 | } | |
d88e1eab SPS |
1709 | if (starget->channel == PCIE_CHANNEL) { |
1710 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1711 | pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, | |
1712 | sas_target_priv_data->sas_address); | |
1713 | if (pcie_device && (pcie_device->starget == NULL)) { | |
1714 | sdev_printk(KERN_INFO, sdev, | |
1715 | "%s : pcie_device->starget set to starget @ %d\n", | |
1716 | __func__, __LINE__); | |
1717 | pcie_device->starget = starget; | |
1718 | } | |
1719 | ||
1720 | if (pcie_device) | |
1721 | pcie_device_put(pcie_device); | |
1722 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
f92363d1 | 1723 | |
d88e1eab | 1724 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
b65cfedf | 1725 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 1726 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
b65cfedf SR |
1727 | sas_target_priv_data->sas_address); |
1728 | if (sas_device && (sas_device->starget == NULL)) { | |
1729 | sdev_printk(KERN_INFO, sdev, | |
1730 | "%s : sas_device->starget set to starget @ %d\n", | |
d1cb5e49 | 1731 | __func__, __LINE__); |
b65cfedf SR |
1732 | sas_device->starget = starget; |
1733 | } | |
d1cb5e49 SR |
1734 | |
1735 | if (sas_device) | |
1736 | sas_device_put(sas_device); | |
1737 | ||
b65cfedf SR |
1738 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1739 | } | |
1740 | ||
f92363d1 SR |
1741 | return 0; |
1742 | } | |
1743 | ||
1744 | /** | |
8a7e4c24 | 1745 | * scsih_slave_destroy - device destroy routine |
f92363d1 SR |
1746 | * @sdev: scsi device struct |
1747 | * | |
1748 | * Returns nothing. | |
1749 | */ | |
8bbb1cf6 | 1750 | static void |
8a7e4c24 | 1751 | scsih_slave_destroy(struct scsi_device *sdev) |
f92363d1 SR |
1752 | { |
1753 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1754 | struct scsi_target *starget; | |
1755 | struct Scsi_Host *shost; | |
1756 | struct MPT3SAS_ADAPTER *ioc; | |
1757 | struct _sas_device *sas_device; | |
d88e1eab | 1758 | struct _pcie_device *pcie_device; |
f92363d1 SR |
1759 | unsigned long flags; |
1760 | ||
1761 | if (!sdev->hostdata) | |
1762 | return; | |
1763 | ||
1764 | starget = scsi_target(sdev); | |
1765 | sas_target_priv_data = starget->hostdata; | |
1766 | sas_target_priv_data->num_luns--; | |
1767 | ||
1768 | shost = dev_to_shost(&starget->dev); | |
1769 | ioc = shost_priv(shost); | |
1770 | ||
d88e1eab SPS |
1771 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) { |
1772 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
1773 | pcie_device = __mpt3sas_get_pdev_from_target(ioc, | |
1774 | sas_target_priv_data); | |
1775 | if (pcie_device && !sas_target_priv_data->num_luns) | |
1776 | pcie_device->starget = NULL; | |
1777 | ||
1778 | if (pcie_device) | |
1779 | pcie_device_put(pcie_device); | |
1780 | ||
1781 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
1782 | ||
1783 | } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
f92363d1 | 1784 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 SR |
1785 | sas_device = __mpt3sas_get_sdev_from_target(ioc, |
1786 | sas_target_priv_data); | |
f92363d1 SR |
1787 | if (sas_device && !sas_target_priv_data->num_luns) |
1788 | sas_device->starget = NULL; | |
d1cb5e49 SR |
1789 | |
1790 | if (sas_device) | |
1791 | sas_device_put(sas_device); | |
f92363d1 SR |
1792 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
1793 | } | |
1794 | ||
1795 | kfree(sdev->hostdata); | |
1796 | sdev->hostdata = NULL; | |
1797 | } | |
1798 | ||
1799 | /** | |
1800 | * _scsih_display_sata_capabilities - sata capabilities | |
1801 | * @ioc: per adapter object | |
1802 | * @handle: device handle | |
1803 | * @sdev: scsi device struct | |
1804 | */ | |
1805 | static void | |
1806 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1807 | u16 handle, struct scsi_device *sdev) | |
1808 | { | |
1809 | Mpi2ConfigReply_t mpi_reply; | |
1810 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1811 | u32 ioc_status; | |
1812 | u16 flags; | |
1813 | u32 device_info; | |
1814 | ||
1815 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1816 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
1817 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1818 | ioc->name, __FILE__, __LINE__, __func__); | |
1819 | return; | |
1820 | } | |
1821 | ||
1822 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1823 | MPI2_IOCSTATUS_MASK; | |
1824 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
1825 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1826 | ioc->name, __FILE__, __LINE__, __func__); | |
1827 | return; | |
1828 | } | |
1829 | ||
1830 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1831 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1832 | ||
1833 | sdev_printk(KERN_INFO, sdev, | |
1834 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1835 | "sw_preserve(%s)\n", | |
1836 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1837 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1838 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1839 | "n", | |
1840 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
1841 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
1842 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
1843 | } | |
1844 | ||
1845 | /* | |
1846 | * raid transport support - | |
1847 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
6c7abffc | 1848 | * unloading the driver followed by a load - I believe that the subroutine |
f92363d1 SR |
1849 | * raid_class_release() is not cleaning up properly. |
1850 | */ | |
1851 | ||
1852 | /** | |
8a7e4c24 | 1853 | * scsih_is_raid - return boolean indicating device is raid volume |
f92363d1 SR |
1854 | * @dev the device struct object |
1855 | */ | |
8bbb1cf6 | 1856 | static int |
8a7e4c24 | 1857 | scsih_is_raid(struct device *dev) |
f92363d1 SR |
1858 | { |
1859 | struct scsi_device *sdev = to_scsi_device(dev); | |
7786ab6a | 1860 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
f92363d1 | 1861 | |
7786ab6a SR |
1862 | if (ioc->is_warpdrive) |
1863 | return 0; | |
f92363d1 SR |
1864 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
1865 | } | |
1866 | ||
1867 | /** | |
8a7e4c24 | 1868 | * scsih_get_resync - get raid volume resync percent complete |
f92363d1 SR |
1869 | * @dev the device struct object |
1870 | */ | |
8bbb1cf6 | 1871 | static void |
8a7e4c24 | 1872 | scsih_get_resync(struct device *dev) |
f92363d1 SR |
1873 | { |
1874 | struct scsi_device *sdev = to_scsi_device(dev); | |
1875 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1876 | static struct _raid_device *raid_device; | |
1877 | unsigned long flags; | |
1878 | Mpi2RaidVolPage0_t vol_pg0; | |
1879 | Mpi2ConfigReply_t mpi_reply; | |
1880 | u32 volume_status_flags; | |
1881 | u8 percent_complete; | |
1882 | u16 handle; | |
1883 | ||
1884 | percent_complete = 0; | |
1885 | handle = 0; | |
7786ab6a SR |
1886 | if (ioc->is_warpdrive) |
1887 | goto out; | |
1888 | ||
f92363d1 SR |
1889 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
1890 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1891 | sdev->channel); | |
1892 | if (raid_device) { | |
1893 | handle = raid_device->handle; | |
1894 | percent_complete = raid_device->percent_complete; | |
1895 | } | |
1896 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1897 | ||
1898 | if (!handle) | |
1899 | goto out; | |
1900 | ||
1901 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1902 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1903 | sizeof(Mpi2RaidVolPage0_t))) { | |
1904 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1905 | ioc->name, __FILE__, __LINE__, __func__); | |
1906 | percent_complete = 0; | |
1907 | goto out; | |
1908 | } | |
1909 | ||
1910 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1911 | if (!(volume_status_flags & | |
1912 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
1913 | percent_complete = 0; | |
1914 | ||
1915 | out: | |
b130b0d5 SS |
1916 | |
1917 | switch (ioc->hba_mpi_version_belonged) { | |
1918 | case MPI2_VERSION: | |
c84b06a4 | 1919 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
1920 | break; |
1921 | case MPI25_VERSION: | |
1922 | case MPI26_VERSION: | |
c84b06a4 | 1923 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
b130b0d5 SS |
1924 | break; |
1925 | } | |
f92363d1 SR |
1926 | } |
1927 | ||
1928 | /** | |
8a7e4c24 | 1929 | * scsih_get_state - get raid volume level |
f92363d1 SR |
1930 | * @dev the device struct object |
1931 | */ | |
8bbb1cf6 | 1932 | static void |
8a7e4c24 | 1933 | scsih_get_state(struct device *dev) |
f92363d1 SR |
1934 | { |
1935 | struct scsi_device *sdev = to_scsi_device(dev); | |
1936 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1937 | static struct _raid_device *raid_device; | |
1938 | unsigned long flags; | |
1939 | Mpi2RaidVolPage0_t vol_pg0; | |
1940 | Mpi2ConfigReply_t mpi_reply; | |
1941 | u32 volstate; | |
1942 | enum raid_state state = RAID_STATE_UNKNOWN; | |
1943 | u16 handle = 0; | |
1944 | ||
1945 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1946 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1947 | sdev->channel); | |
1948 | if (raid_device) | |
1949 | handle = raid_device->handle; | |
1950 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1951 | ||
1952 | if (!raid_device) | |
1953 | goto out; | |
1954 | ||
1955 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1956 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1957 | sizeof(Mpi2RaidVolPage0_t))) { | |
1958 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1959 | ioc->name, __FILE__, __LINE__, __func__); | |
1960 | goto out; | |
1961 | } | |
1962 | ||
1963 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1964 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
1965 | state = RAID_STATE_RESYNCING; | |
1966 | goto out; | |
1967 | } | |
1968 | ||
1969 | switch (vol_pg0.VolumeState) { | |
1970 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
1971 | case MPI2_RAID_VOL_STATE_ONLINE: | |
1972 | state = RAID_STATE_ACTIVE; | |
1973 | break; | |
1974 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
1975 | state = RAID_STATE_DEGRADED; | |
1976 | break; | |
1977 | case MPI2_RAID_VOL_STATE_FAILED: | |
1978 | case MPI2_RAID_VOL_STATE_MISSING: | |
1979 | state = RAID_STATE_OFFLINE; | |
1980 | break; | |
1981 | } | |
1982 | out: | |
b130b0d5 SS |
1983 | switch (ioc->hba_mpi_version_belonged) { |
1984 | case MPI2_VERSION: | |
c84b06a4 | 1985 | raid_set_state(mpt2sas_raid_template, dev, state); |
b130b0d5 SS |
1986 | break; |
1987 | case MPI25_VERSION: | |
1988 | case MPI26_VERSION: | |
c84b06a4 | 1989 | raid_set_state(mpt3sas_raid_template, dev, state); |
b130b0d5 SS |
1990 | break; |
1991 | } | |
f92363d1 SR |
1992 | } |
1993 | ||
1994 | /** | |
1995 | * _scsih_set_level - set raid level | |
1996 | * @sdev: scsi device struct | |
1997 | * @volume_type: volume type | |
1998 | */ | |
1999 | static void | |
c84b06a4 SR |
2000 | _scsih_set_level(struct MPT3SAS_ADAPTER *ioc, |
2001 | struct scsi_device *sdev, u8 volume_type) | |
f92363d1 SR |
2002 | { |
2003 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
2004 | ||
2005 | switch (volume_type) { | |
2006 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2007 | level = RAID_LEVEL_0; | |
2008 | break; | |
2009 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2010 | level = RAID_LEVEL_10; | |
2011 | break; | |
2012 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2013 | level = RAID_LEVEL_1E; | |
2014 | break; | |
2015 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2016 | level = RAID_LEVEL_1; | |
2017 | break; | |
2018 | } | |
2019 | ||
b130b0d5 SS |
2020 | switch (ioc->hba_mpi_version_belonged) { |
2021 | case MPI2_VERSION: | |
c84b06a4 | 2022 | raid_set_level(mpt2sas_raid_template, |
b130b0d5 SS |
2023 | &sdev->sdev_gendev, level); |
2024 | break; | |
2025 | case MPI25_VERSION: | |
2026 | case MPI26_VERSION: | |
c84b06a4 | 2027 | raid_set_level(mpt3sas_raid_template, |
b130b0d5 SS |
2028 | &sdev->sdev_gendev, level); |
2029 | break; | |
2030 | } | |
f92363d1 SR |
2031 | } |
2032 | ||
2033 | ||
2034 | /** | |
2035 | * _scsih_get_volume_capabilities - volume capabilities | |
2036 | * @ioc: per adapter object | |
2037 | * @sas_device: the raid_device object | |
2038 | * | |
2039 | * Returns 0 for success, else 1 | |
2040 | */ | |
2041 | static int | |
2042 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
2043 | struct _raid_device *raid_device) | |
2044 | { | |
2045 | Mpi2RaidVolPage0_t *vol_pg0; | |
2046 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
2047 | Mpi2SasDevicePage0_t sas_device_pg0; | |
2048 | Mpi2ConfigReply_t mpi_reply; | |
2049 | u16 sz; | |
2050 | u8 num_pds; | |
2051 | ||
2052 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
2053 | &num_pds)) || !num_pds) { | |
2054 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2055 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2056 | __func__)); | |
2057 | return 1; | |
2058 | } | |
2059 | ||
2060 | raid_device->num_pds = num_pds; | |
2061 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
2062 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
2063 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
2064 | if (!vol_pg0) { | |
2065 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2066 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2067 | __func__)); | |
2068 | return 1; | |
2069 | } | |
2070 | ||
2071 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
2072 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
2073 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2074 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2075 | __func__)); | |
2076 | kfree(vol_pg0); | |
2077 | return 1; | |
2078 | } | |
2079 | ||
2080 | raid_device->volume_type = vol_pg0->VolumeType; | |
2081 | ||
2082 | /* figure out what the underlying devices are by | |
2083 | * obtaining the device_info bits for the 1st device | |
2084 | */ | |
2085 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
2086 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
2087 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
2088 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
2089 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
2090 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
2091 | raid_device->device_info = | |
2092 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
2093 | } | |
2094 | } | |
2095 | ||
2096 | kfree(vol_pg0); | |
2097 | return 0; | |
2098 | } | |
2099 | ||
f92363d1 SR |
2100 | /** |
2101 | * _scsih_enable_tlr - setting TLR flags | |
2102 | * @ioc: per adapter object | |
2103 | * @sdev: scsi device struct | |
2104 | * | |
2105 | * Enabling Transaction Layer Retries for tape devices when | |
2106 | * vpd page 0x90 is present | |
2107 | * | |
2108 | */ | |
2109 | static void | |
2110 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
2111 | { | |
2112 | ||
2113 | /* only for TAPE */ | |
2114 | if (sdev->type != TYPE_TAPE) | |
2115 | return; | |
2116 | ||
2117 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
2118 | return; | |
2119 | ||
2120 | sas_enable_tlr(sdev); | |
2121 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
2122 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
2123 | return; | |
2124 | ||
2125 | } | |
2126 | ||
2127 | /** | |
8a7e4c24 | 2128 | * scsih_slave_configure - device configure routine. |
f92363d1 SR |
2129 | * @sdev: scsi device struct |
2130 | * | |
2131 | * Returns 0 if ok. Any other return is assumed to be an error and | |
2132 | * the device is ignored. | |
2133 | */ | |
8bbb1cf6 | 2134 | static int |
8a7e4c24 | 2135 | scsih_slave_configure(struct scsi_device *sdev) |
f92363d1 SR |
2136 | { |
2137 | struct Scsi_Host *shost = sdev->host; | |
2138 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
2139 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2140 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
2141 | struct _sas_device *sas_device; | |
2142 | struct _raid_device *raid_device; | |
2143 | unsigned long flags; | |
2144 | int qdepth; | |
2145 | u8 ssp_target = 0; | |
2146 | char *ds = ""; | |
2147 | char *r_level = ""; | |
2148 | u16 handle, volume_handle = 0; | |
2149 | u64 volume_wwid = 0; | |
2150 | ||
2151 | qdepth = 1; | |
2152 | sas_device_priv_data = sdev->hostdata; | |
2153 | sas_device_priv_data->configured_lun = 1; | |
2154 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
2155 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
2156 | handle = sas_target_priv_data->handle; | |
2157 | ||
2158 | /* raid volume handling */ | |
2159 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2160 | ||
2161 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 2162 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
2163 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
2164 | if (!raid_device) { | |
2165 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2166 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2167 | __LINE__, __func__)); | |
2168 | return 1; | |
2169 | } | |
2170 | ||
2171 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
2172 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2173 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
2174 | __LINE__, __func__)); | |
2175 | return 1; | |
2176 | } | |
2177 | ||
7786ab6a SR |
2178 | /* |
2179 | * WARPDRIVE: Initialize the required data for Direct IO | |
2180 | */ | |
c84b06a4 | 2181 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
2182 | |
2183 | /* RAID Queue Depth Support | |
2184 | * IS volume = underlying qdepth of drive type, either | |
2185 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
2186 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
2187 | */ | |
2188 | if (raid_device->device_info & | |
2189 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2190 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2191 | ds = "SSP"; | |
2192 | } else { | |
2193 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2194 | if (raid_device->device_info & | |
2195 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2196 | ds = "SATA"; | |
2197 | else | |
2198 | ds = "STP"; | |
2199 | } | |
2200 | ||
2201 | switch (raid_device->volume_type) { | |
2202 | case MPI2_RAID_VOL_TYPE_RAID0: | |
2203 | r_level = "RAID0"; | |
2204 | break; | |
2205 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
2206 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2207 | if (ioc->manu_pg10.OEMIdentifier && | |
2208 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
2209 | MFG10_GF0_R10_DISPLAY) && | |
2210 | !(raid_device->num_pds % 2)) | |
2211 | r_level = "RAID10"; | |
2212 | else | |
2213 | r_level = "RAID1E"; | |
2214 | break; | |
2215 | case MPI2_RAID_VOL_TYPE_RAID1: | |
2216 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2217 | r_level = "RAID1"; | |
2218 | break; | |
2219 | case MPI2_RAID_VOL_TYPE_RAID10: | |
2220 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2221 | r_level = "RAID10"; | |
2222 | break; | |
2223 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
2224 | default: | |
2225 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
2226 | r_level = "RAIDX"; | |
2227 | break; | |
2228 | } | |
2229 | ||
7786ab6a SR |
2230 | if (!ioc->hide_ir_msg) |
2231 | sdev_printk(KERN_INFO, sdev, | |
2232 | "%s: handle(0x%04x), wwid(0x%016llx)," | |
2233 | " pd_count(%d), type(%s)\n", | |
2234 | r_level, raid_device->handle, | |
2235 | (unsigned long long)raid_device->wwid, | |
2236 | raid_device->num_pds, ds); | |
f92363d1 | 2237 | |
6c197093 C |
2238 | if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) { |
2239 | blk_queue_max_hw_sectors(sdev->request_queue, | |
2240 | MPT3SAS_RAID_MAX_SECTORS); | |
2241 | sdev_printk(KERN_INFO, sdev, | |
2242 | "Set queue's max_sector to: %u\n", | |
2243 | MPT3SAS_RAID_MAX_SECTORS); | |
2244 | } | |
2245 | ||
8a7e4c24 | 2246 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 | 2247 | |
7786ab6a SR |
2248 | /* raid transport support */ |
2249 | if (!ioc->is_warpdrive) | |
c84b06a4 | 2250 | _scsih_set_level(ioc, sdev, raid_device->volume_type); |
f92363d1 SR |
2251 | return 0; |
2252 | } | |
2253 | ||
2254 | /* non-raid handling */ | |
2255 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2256 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
2257 | &volume_handle)) { | |
2258 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2259 | "failure at %s:%d/%s()!\n", ioc->name, | |
2260 | __FILE__, __LINE__, __func__)); | |
2261 | return 1; | |
2262 | } | |
2263 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
2264 | volume_handle, &volume_wwid)) { | |
2265 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2266 | "failure at %s:%d/%s()!\n", ioc->name, | |
2267 | __FILE__, __LINE__, __func__)); | |
2268 | return 1; | |
2269 | } | |
2270 | } | |
2271 | ||
2272 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2273 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
2274 | sas_device_priv_data->sas_target->sas_address); |
2275 | if (!sas_device) { | |
2276 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2277 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
2278 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
2279 | __func__)); | |
2280 | return 1; | |
2281 | } | |
2282 | ||
2283 | sas_device->volume_handle = volume_handle; | |
2284 | sas_device->volume_wwid = volume_wwid; | |
2285 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
2286 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
2287 | ssp_target = 1; | |
30158dc9 SS |
2288 | if (sas_device->device_info & |
2289 | MPI2_SAS_DEVICE_INFO_SEP) { | |
2290 | sdev_printk(KERN_WARNING, sdev, | |
2291 | "set ignore_delay_remove for handle(0x%04x)\n", | |
2292 | sas_device_priv_data->sas_target->handle); | |
2293 | sas_device_priv_data->ignore_delay_remove = 1; | |
2294 | ds = "SES"; | |
2295 | } else | |
2296 | ds = "SSP"; | |
f92363d1 SR |
2297 | } else { |
2298 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
2299 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
2300 | ds = "STP"; | |
2301 | else if (sas_device->device_info & | |
2302 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
2303 | ds = "SATA"; | |
2304 | } | |
2305 | ||
2306 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
2307 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
2308 | ds, handle, (unsigned long long)sas_device->sas_address, | |
2309 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
75888956 SR |
2310 | |
2311 | _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL); | |
f92363d1 | 2312 | |
d1cb5e49 | 2313 | sas_device_put(sas_device); |
f92363d1 SR |
2314 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
2315 | ||
2316 | if (!ssp_target) | |
2317 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
2318 | ||
2319 | ||
8a7e4c24 | 2320 | scsih_change_queue_depth(sdev, qdepth); |
f92363d1 SR |
2321 | |
2322 | if (ssp_target) { | |
2323 | sas_read_port_mode_page(sdev); | |
2324 | _scsih_enable_tlr(ioc, sdev); | |
2325 | } | |
2326 | ||
2327 | return 0; | |
2328 | } | |
2329 | ||
2330 | /** | |
8a7e4c24 | 2331 | * scsih_bios_param - fetch head, sector, cylinder info for a disk |
f92363d1 SR |
2332 | * @sdev: scsi device struct |
2333 | * @bdev: pointer to block device context | |
2334 | * @capacity: device size (in 512 byte sectors) | |
2335 | * @params: three element array to place output: | |
2336 | * params[0] number of heads (max 255) | |
2337 | * params[1] number of sectors (max 63) | |
2338 | * params[2] number of cylinders | |
2339 | * | |
2340 | * Return nothing. | |
2341 | */ | |
8bbb1cf6 | 2342 | static int |
8a7e4c24 | 2343 | scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
f92363d1 SR |
2344 | sector_t capacity, int params[]) |
2345 | { | |
2346 | int heads; | |
2347 | int sectors; | |
2348 | sector_t cylinders; | |
2349 | ulong dummy; | |
2350 | ||
2351 | heads = 64; | |
2352 | sectors = 32; | |
2353 | ||
2354 | dummy = heads * sectors; | |
2355 | cylinders = capacity; | |
2356 | sector_div(cylinders, dummy); | |
2357 | ||
2358 | /* | |
2359 | * Handle extended translation size for logical drives | |
2360 | * > 1Gb | |
2361 | */ | |
2362 | if ((ulong)capacity >= 0x200000) { | |
2363 | heads = 255; | |
2364 | sectors = 63; | |
2365 | dummy = heads * sectors; | |
2366 | cylinders = capacity; | |
2367 | sector_div(cylinders, dummy); | |
2368 | } | |
2369 | ||
2370 | /* return result */ | |
2371 | params[0] = heads; | |
2372 | params[1] = sectors; | |
2373 | params[2] = cylinders; | |
2374 | ||
2375 | return 0; | |
2376 | } | |
2377 | ||
2378 | /** | |
2379 | * _scsih_response_code - translation of device response code | |
2380 | * @ioc: per adapter object | |
2381 | * @response_code: response code returned by the device | |
2382 | * | |
2383 | * Return nothing. | |
2384 | */ | |
2385 | static void | |
2386 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
2387 | { | |
2388 | char *desc; | |
2389 | ||
2390 | switch (response_code) { | |
2391 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
2392 | desc = "task management request completed"; | |
2393 | break; | |
2394 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
2395 | desc = "invalid frame"; | |
2396 | break; | |
2397 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
2398 | desc = "task management request not supported"; | |
2399 | break; | |
2400 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
2401 | desc = "task management request failed"; | |
2402 | break; | |
2403 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
2404 | desc = "task management request succeeded"; | |
2405 | break; | |
2406 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
2407 | desc = "invalid lun"; | |
2408 | break; | |
2409 | case 0xA: | |
2410 | desc = "overlapped tag attempted"; | |
2411 | break; | |
2412 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
2413 | desc = "task queued, however not sent to target"; | |
2414 | break; | |
2415 | default: | |
2416 | desc = "unknown"; | |
2417 | break; | |
2418 | } | |
2419 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
2420 | ioc->name, response_code, desc); | |
2421 | } | |
2422 | ||
2423 | /** | |
2424 | * _scsih_tm_done - tm completion routine | |
2425 | * @ioc: per adapter object | |
2426 | * @smid: system request message index | |
2427 | * @msix_index: MSIX table index supplied by the OS | |
2428 | * @reply: reply message frame(lower 32bit addr) | |
2429 | * Context: none. | |
2430 | * | |
2431 | * The callback handler when using scsih_issue_tm. | |
2432 | * | |
2433 | * Return 1 meaning mf should be freed from _base_interrupt | |
2434 | * 0 means the mf is freed from this function. | |
2435 | */ | |
2436 | static u8 | |
2437 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
2438 | { | |
2439 | MPI2DefaultReply_t *mpi_reply; | |
2440 | ||
2441 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
2442 | return 1; | |
2443 | if (ioc->tm_cmds.smid != smid) | |
2444 | return 1; | |
f92363d1 SR |
2445 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
2446 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2447 | if (mpi_reply) { | |
2448 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
2449 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
2450 | } | |
2451 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
2452 | complete(&ioc->tm_cmds.done); | |
2453 | return 1; | |
2454 | } | |
2455 | ||
2456 | /** | |
2457 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
2458 | * @ioc: per adapter object | |
2459 | * @handle: device handle | |
2460 | * | |
2461 | * During taskmangement request, we need to freeze the device queue. | |
2462 | */ | |
2463 | void | |
2464 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2465 | { | |
2466 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2467 | struct scsi_device *sdev; | |
2468 | u8 skip = 0; | |
2469 | ||
2470 | shost_for_each_device(sdev, ioc->shost) { | |
2471 | if (skip) | |
2472 | continue; | |
2473 | sas_device_priv_data = sdev->hostdata; | |
2474 | if (!sas_device_priv_data) | |
2475 | continue; | |
2476 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2477 | sas_device_priv_data->sas_target->tm_busy = 1; | |
2478 | skip = 1; | |
2479 | ioc->ignore_loginfos = 1; | |
2480 | } | |
2481 | } | |
2482 | } | |
2483 | ||
2484 | /** | |
2485 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
2486 | * @ioc: per adapter object | |
2487 | * @handle: device handle | |
2488 | * | |
2489 | * During taskmangement request, we need to freeze the device queue. | |
2490 | */ | |
2491 | void | |
2492 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2493 | { | |
2494 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2495 | struct scsi_device *sdev; | |
2496 | u8 skip = 0; | |
2497 | ||
2498 | shost_for_each_device(sdev, ioc->shost) { | |
2499 | if (skip) | |
2500 | continue; | |
2501 | sas_device_priv_data = sdev->hostdata; | |
2502 | if (!sas_device_priv_data) | |
2503 | continue; | |
2504 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2505 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2506 | skip = 1; | |
2507 | ioc->ignore_loginfos = 0; | |
2508 | } | |
2509 | } | |
2510 | } | |
2511 | ||
2512 | /** | |
2513 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2514 | * @ioc: per adapter struct | |
2515 | * @device_handle: device handle | |
2516 | * @channel: the channel assigned by the OS | |
2517 | * @id: the id assigned by the OS | |
2518 | * @lun: lun number | |
2519 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2520 | * @smid_task: smid assigned to the task | |
2521 | * @timeout: timeout in seconds | |
f92363d1 SR |
2522 | * Context: user |
2523 | * | |
2524 | * A generic API for sending task management requests to firmware. | |
2525 | * | |
2526 | * The callback index is set inside `ioc->tm_cb_idx`. | |
2527 | * | |
2528 | * Return SUCCESS or FAILED. | |
2529 | */ | |
2530 | int | |
2531 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, | |
96902835 | 2532 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout) |
f92363d1 SR |
2533 | { |
2534 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2535 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2536 | u16 smid = 0; | |
2537 | u32 ioc_state; | |
f92363d1 SR |
2538 | struct scsiio_tracker *scsi_lookup = NULL; |
2539 | int rc; | |
03d1fb3a | 2540 | u16 msix_task = 0; |
f92363d1 | 2541 | |
96902835 CO |
2542 | lockdep_assert_held(&ioc->tm_cmds.mutex); |
2543 | ||
f92363d1 SR |
2544 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
2545 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2546 | __func__, ioc->name); | |
96902835 | 2547 | return FAILED; |
f92363d1 SR |
2548 | } |
2549 | ||
2550 | if (ioc->shost_recovery || ioc->remove_host || | |
2551 | ioc->pci_error_recovery) { | |
2552 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2553 | __func__, ioc->name); | |
96902835 | 2554 | return FAILED; |
f92363d1 SR |
2555 | } |
2556 | ||
2557 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2558 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2559 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2560 | "unexpected doorbell active!\n", ioc->name)); | |
98c56ad3 | 2561 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2562 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2563 | } |
2564 | ||
2565 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2566 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2567 | MPI2_DOORBELL_DATA_MASK); | |
98c56ad3 | 2568 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
96902835 | 2569 | return (!rc) ? SUCCESS : FAILED; |
f92363d1 SR |
2570 | } |
2571 | ||
2572 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2573 | if (!smid) { | |
2574 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2575 | ioc->name, __func__); | |
96902835 | 2576 | return FAILED; |
f92363d1 SR |
2577 | } |
2578 | ||
2579 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | |
2580 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; | |
2581 | ||
2582 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
2583 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", | |
2584 | ioc->name, handle, type, smid_task)); | |
2585 | ioc->tm_cmds.status = MPT3_CMD_PENDING; | |
2586 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2587 | ioc->tm_cmds.smid = smid; | |
2588 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2589 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2590 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2591 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2592 | mpi_request->TaskType = type; | |
2593 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
2594 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2595 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2596 | init_completion(&ioc->tm_cmds.done); | |
03d1fb3a SS |
2597 | if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) && |
2598 | (scsi_lookup->msix_io < ioc->reply_queue_count)) | |
2599 | msix_task = scsi_lookup->msix_io; | |
2600 | else | |
2601 | msix_task = 0; | |
81c16f83 | 2602 | ioc->put_smid_hi_priority(ioc, smid, msix_task); |
8bbb1cf6 | 2603 | wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
f92363d1 SR |
2604 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
2605 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
2606 | ioc->name, __func__); | |
2607 | _debug_dump_mf(mpi_request, | |
2608 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2609 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { | |
98c56ad3 CO |
2610 | rc = mpt3sas_base_hard_reset_handler(ioc, |
2611 | FORCE_BIG_HAMMER); | |
f92363d1 | 2612 | rc = (!rc) ? SUCCESS : FAILED; |
96902835 | 2613 | goto out; |
f92363d1 SR |
2614 | } |
2615 | } | |
2616 | ||
5f0dfb7a C |
2617 | /* sync IRQs in case those were busy during flush. */ |
2618 | mpt3sas_base_sync_reply_irqs(ioc); | |
2619 | ||
f92363d1 SR |
2620 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
2621 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2622 | mpi_reply = ioc->tm_cmds.reply; | |
2623 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2624 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2625 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2626 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2627 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2628 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2629 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2630 | if (mpi_reply->IOCStatus) | |
2631 | _debug_dump_mf(mpi_request, | |
2632 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2633 | } | |
2634 | } | |
2635 | ||
2636 | switch (type) { | |
2637 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | |
2638 | rc = SUCCESS; | |
2639 | if (scsi_lookup->scmd == NULL) | |
2640 | break; | |
2641 | rc = FAILED; | |
2642 | break; | |
2643 | ||
2644 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | |
2645 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) | |
2646 | rc = FAILED; | |
2647 | else | |
2648 | rc = SUCCESS; | |
2649 | break; | |
2650 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | |
2651 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: | |
2652 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) | |
2653 | rc = FAILED; | |
2654 | else | |
2655 | rc = SUCCESS; | |
2656 | break; | |
2657 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | |
2658 | rc = SUCCESS; | |
2659 | break; | |
2660 | default: | |
2661 | rc = FAILED; | |
2662 | break; | |
2663 | } | |
2664 | ||
96902835 | 2665 | out: |
f92363d1 SR |
2666 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
2667 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
f92363d1 | 2668 | return rc; |
96902835 | 2669 | } |
f92363d1 | 2670 | |
96902835 CO |
2671 | int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
2672 | uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout) | |
2673 | { | |
2674 | int ret; | |
2675 | ||
2676 | mutex_lock(&ioc->tm_cmds.mutex); | |
2677 | ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type, | |
2678 | smid_task, timeout); | |
2679 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2680 | ||
2681 | return ret; | |
f92363d1 SR |
2682 | } |
2683 | ||
2684 | /** | |
2685 | * _scsih_tm_display_info - displays info about the device | |
2686 | * @ioc: per adapter struct | |
2687 | * @scmd: pointer to scsi command object | |
2688 | * | |
2689 | * Called by task management callback handlers. | |
2690 | */ | |
2691 | static void | |
2692 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2693 | { | |
2694 | struct scsi_target *starget = scmd->device->sdev_target; | |
2695 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2696 | struct _sas_device *sas_device = NULL; | |
2697 | unsigned long flags; | |
2698 | char *device_str = NULL; | |
2699 | ||
2700 | if (!priv_target) | |
2701 | return; | |
7786ab6a SR |
2702 | if (ioc->hide_ir_msg) |
2703 | device_str = "WarpDrive"; | |
2704 | else | |
2705 | device_str = "volume"; | |
f92363d1 SR |
2706 | |
2707 | scsi_print_command(scmd); | |
2708 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2709 | starget_printk(KERN_INFO, starget, | |
2710 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2711 | device_str, priv_target->handle, | |
2712 | device_str, (unsigned long long)priv_target->sas_address); | |
2713 | } else { | |
2714 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 2715 | sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
2716 | if (sas_device) { |
2717 | if (priv_target->flags & | |
2718 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2719 | starget_printk(KERN_INFO, starget, | |
2720 | "volume handle(0x%04x), " | |
2721 | "volume wwid(0x%016llx)\n", | |
2722 | sas_device->volume_handle, | |
2723 | (unsigned long long)sas_device->volume_wwid); | |
2724 | } | |
2725 | starget_printk(KERN_INFO, starget, | |
2726 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2727 | sas_device->handle, | |
2728 | (unsigned long long)sas_device->sas_address, | |
2729 | sas_device->phy); | |
75888956 SR |
2730 | |
2731 | _scsih_display_enclosure_chassis_info(NULL, sas_device, | |
2732 | NULL, starget); | |
d1cb5e49 SR |
2733 | |
2734 | sas_device_put(sas_device); | |
f92363d1 SR |
2735 | } |
2736 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2737 | } | |
2738 | } | |
2739 | ||
2740 | /** | |
8a7e4c24 | 2741 | * scsih_abort - eh threads main abort routine |
f92363d1 SR |
2742 | * @scmd: pointer to scsi command object |
2743 | * | |
2744 | * Returns SUCCESS if command aborted else FAILED | |
2745 | */ | |
8bbb1cf6 | 2746 | static int |
8a7e4c24 | 2747 | scsih_abort(struct scsi_cmnd *scmd) |
f92363d1 SR |
2748 | { |
2749 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2750 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2751 | u16 smid; | |
2752 | u16 handle; | |
2753 | int r; | |
2754 | ||
2755 | sdev_printk(KERN_INFO, scmd->device, | |
2756 | "attempting task abort! scmd(%p)\n", scmd); | |
2757 | _scsih_tm_display_info(ioc, scmd); | |
2758 | ||
2759 | sas_device_priv_data = scmd->device->hostdata; | |
2760 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2761 | sdev_printk(KERN_INFO, scmd->device, | |
2762 | "device been deleted! scmd(%p)\n", scmd); | |
2763 | scmd->result = DID_NO_CONNECT << 16; | |
2764 | scmd->scsi_done(scmd); | |
2765 | r = SUCCESS; | |
2766 | goto out; | |
2767 | } | |
2768 | ||
2769 | /* search for the command */ | |
2770 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); | |
2771 | if (!smid) { | |
2772 | scmd->result = DID_RESET << 16; | |
2773 | r = SUCCESS; | |
2774 | goto out; | |
2775 | } | |
2776 | ||
2777 | /* for hidden raid components and volumes this is not supported */ | |
2778 | if (sas_device_priv_data->sas_target->flags & | |
2779 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2780 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2781 | scmd->result = DID_RESET << 16; | |
2782 | r = FAILED; | |
2783 | goto out; | |
2784 | } | |
2785 | ||
2786 | mpt3sas_halt_firmware(ioc); | |
2787 | ||
2788 | handle = sas_device_priv_data->sas_target->handle; | |
96902835 | 2789 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 2790 | scmd->device->id, scmd->device->lun, |
96902835 | 2791 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30); |
f92363d1 SR |
2792 | |
2793 | out: | |
2794 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
2795 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2796 | return r; | |
2797 | } | |
2798 | ||
2799 | /** | |
8a7e4c24 | 2800 | * scsih_dev_reset - eh threads main device reset routine |
f92363d1 SR |
2801 | * @scmd: pointer to scsi command object |
2802 | * | |
2803 | * Returns SUCCESS if command aborted else FAILED | |
2804 | */ | |
8bbb1cf6 | 2805 | static int |
8a7e4c24 | 2806 | scsih_dev_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2807 | { |
2808 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2809 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2810 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
2811 | u16 handle; |
2812 | int r; | |
2813 | ||
d1cb5e49 SR |
2814 | struct scsi_target *starget = scmd->device->sdev_target; |
2815 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; | |
2816 | ||
f92363d1 SR |
2817 | sdev_printk(KERN_INFO, scmd->device, |
2818 | "attempting device reset! scmd(%p)\n", scmd); | |
2819 | _scsih_tm_display_info(ioc, scmd); | |
2820 | ||
2821 | sas_device_priv_data = scmd->device->hostdata; | |
2822 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2823 | sdev_printk(KERN_INFO, scmd->device, | |
2824 | "device been deleted! scmd(%p)\n", scmd); | |
2825 | scmd->result = DID_NO_CONNECT << 16; | |
2826 | scmd->scsi_done(scmd); | |
2827 | r = SUCCESS; | |
2828 | goto out; | |
2829 | } | |
2830 | ||
2831 | /* for hidden raid components obtain the volume_handle */ | |
2832 | handle = 0; | |
2833 | if (sas_device_priv_data->sas_target->flags & | |
2834 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
2835 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
2836 | target_priv_data); | |
f92363d1 SR |
2837 | if (sas_device) |
2838 | handle = sas_device->volume_handle; | |
f92363d1 SR |
2839 | } else |
2840 | handle = sas_device_priv_data->sas_target->handle; | |
2841 | ||
2842 | if (!handle) { | |
2843 | scmd->result = DID_RESET << 16; | |
2844 | r = FAILED; | |
2845 | goto out; | |
2846 | } | |
2847 | ||
96902835 | 2848 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 2849 | scmd->device->id, scmd->device->lun, |
96902835 | 2850 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30); |
f92363d1 SR |
2851 | |
2852 | out: | |
2853 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
2854 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
2855 | |
2856 | if (sas_device) | |
2857 | sas_device_put(sas_device); | |
2858 | ||
f92363d1 SR |
2859 | return r; |
2860 | } | |
2861 | ||
2862 | /** | |
8a7e4c24 | 2863 | * scsih_target_reset - eh threads main target reset routine |
f92363d1 SR |
2864 | * @scmd: pointer to scsi command object |
2865 | * | |
2866 | * Returns SUCCESS if command aborted else FAILED | |
2867 | */ | |
8bbb1cf6 | 2868 | static int |
8a7e4c24 | 2869 | scsih_target_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2870 | { |
2871 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2872 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
d1cb5e49 | 2873 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
2874 | u16 handle; |
2875 | int r; | |
2876 | struct scsi_target *starget = scmd->device->sdev_target; | |
d1cb5e49 | 2877 | struct MPT3SAS_TARGET *target_priv_data = starget->hostdata; |
f92363d1 SR |
2878 | |
2879 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
2880 | scmd); | |
2881 | _scsih_tm_display_info(ioc, scmd); | |
2882 | ||
2883 | sas_device_priv_data = scmd->device->hostdata; | |
2884 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2885 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", | |
2886 | scmd); | |
2887 | scmd->result = DID_NO_CONNECT << 16; | |
2888 | scmd->scsi_done(scmd); | |
2889 | r = SUCCESS; | |
2890 | goto out; | |
2891 | } | |
2892 | ||
2893 | /* for hidden raid components obtain the volume_handle */ | |
2894 | handle = 0; | |
2895 | if (sas_device_priv_data->sas_target->flags & | |
2896 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
d1cb5e49 SR |
2897 | sas_device = mpt3sas_get_sdev_from_target(ioc, |
2898 | target_priv_data); | |
f92363d1 SR |
2899 | if (sas_device) |
2900 | handle = sas_device->volume_handle; | |
f92363d1 SR |
2901 | } else |
2902 | handle = sas_device_priv_data->sas_target->handle; | |
2903 | ||
2904 | if (!handle) { | |
2905 | scmd->result = DID_RESET << 16; | |
2906 | r = FAILED; | |
2907 | goto out; | |
2908 | } | |
2909 | ||
96902835 | 2910 | r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, |
f92363d1 | 2911 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
96902835 | 2912 | 30); |
f92363d1 SR |
2913 | |
2914 | out: | |
2915 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
2916 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
d1cb5e49 SR |
2917 | |
2918 | if (sas_device) | |
2919 | sas_device_put(sas_device); | |
2920 | ||
f92363d1 SR |
2921 | return r; |
2922 | } | |
2923 | ||
2924 | ||
2925 | /** | |
8a7e4c24 | 2926 | * scsih_host_reset - eh threads main host reset routine |
f92363d1 SR |
2927 | * @scmd: pointer to scsi command object |
2928 | * | |
2929 | * Returns SUCCESS if command aborted else FAILED | |
2930 | */ | |
8bbb1cf6 | 2931 | static int |
8a7e4c24 | 2932 | scsih_host_reset(struct scsi_cmnd *scmd) |
f92363d1 SR |
2933 | { |
2934 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2935 | int r, retval; | |
2936 | ||
2937 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
2938 | ioc->name, scmd); | |
2939 | scsi_print_command(scmd); | |
2940 | ||
ddb588be SR |
2941 | if (ioc->is_driver_loading) { |
2942 | pr_info(MPT3SAS_FMT "Blocking the host reset\n", | |
2943 | ioc->name); | |
2944 | r = FAILED; | |
2945 | goto out; | |
2946 | } | |
2947 | ||
98c56ad3 | 2948 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 | 2949 | r = (retval < 0) ? FAILED : SUCCESS; |
ddb588be | 2950 | out: |
f92363d1 SR |
2951 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
2952 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2953 | ||
2954 | return r; | |
2955 | } | |
2956 | ||
2957 | /** | |
2958 | * _scsih_fw_event_add - insert and queue up fw_event | |
2959 | * @ioc: per adapter object | |
2960 | * @fw_event: object describing the event | |
2961 | * Context: This function will acquire ioc->fw_event_lock. | |
2962 | * | |
2963 | * This adds the firmware event object into link list, then queues it up to | |
2964 | * be processed from user context. | |
2965 | * | |
2966 | * Return nothing. | |
2967 | */ | |
2968 | static void | |
2969 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
2970 | { | |
2971 | unsigned long flags; | |
2972 | ||
2973 | if (ioc->firmware_event_thread == NULL) | |
2974 | return; | |
2975 | ||
2976 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 | 2977 | fw_event_work_get(fw_event); |
f92363d1 SR |
2978 | INIT_LIST_HEAD(&fw_event->list); |
2979 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
2980 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
146b16c8 | 2981 | fw_event_work_get(fw_event); |
f92363d1 SR |
2982 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
2983 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
2984 | } | |
2985 | ||
2986 | /** | |
146b16c8 | 2987 | * _scsih_fw_event_del_from_list - delete fw_event from the list |
f92363d1 SR |
2988 | * @ioc: per adapter object |
2989 | * @fw_event: object describing the event | |
2990 | * Context: This function will acquire ioc->fw_event_lock. | |
2991 | * | |
146b16c8 | 2992 | * If the fw_event is on the fw_event_list, remove it and do a put. |
f92363d1 SR |
2993 | * |
2994 | * Return nothing. | |
2995 | */ | |
2996 | static void | |
146b16c8 | 2997 | _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
f92363d1 SR |
2998 | *fw_event) |
2999 | { | |
3000 | unsigned long flags; | |
3001 | ||
3002 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
146b16c8 SR |
3003 | if (!list_empty(&fw_event->list)) { |
3004 | list_del_init(&fw_event->list); | |
3005 | fw_event_work_put(fw_event); | |
3006 | } | |
f92363d1 SR |
3007 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
3008 | } | |
3009 | ||
3010 | ||
3011 | /** | |
3012 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
3013 | * @ioc: per adapter object | |
3014 | * @event_data: trigger event data | |
3015 | * | |
3016 | * Return nothing. | |
3017 | */ | |
3018 | void | |
3019 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
3020 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
3021 | { | |
3022 | struct fw_event_work *fw_event; | |
146b16c8 | 3023 | u16 sz; |
f92363d1 SR |
3024 | |
3025 | if (ioc->is_driver_loading) | |
3026 | return; | |
146b16c8 SR |
3027 | sz = sizeof(*event_data); |
3028 | fw_event = alloc_fw_event_work(sz); | |
f92363d1 SR |
3029 | if (!fw_event) |
3030 | return; | |
f92363d1 SR |
3031 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
3032 | fw_event->ioc = ioc; | |
3033 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
3034 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3035 | fw_event_work_put(fw_event); |
f92363d1 SR |
3036 | } |
3037 | ||
3038 | /** | |
3039 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
3040 | * @ioc: per adapter object | |
3041 | * | |
3042 | * Return nothing. | |
3043 | */ | |
3044 | static void | |
3045 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
3046 | { | |
3047 | struct fw_event_work *fw_event; | |
3048 | ||
3049 | if (ioc->is_driver_loading) | |
3050 | return; | |
146b16c8 | 3051 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3052 | if (!fw_event) |
3053 | return; | |
3054 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
3055 | fw_event->ioc = ioc; | |
3056 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 3057 | fw_event_work_put(fw_event); |
f92363d1 SR |
3058 | } |
3059 | ||
3060 | /** | |
3061 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
3062 | * @ioc: per adapter object | |
3063 | * | |
3064 | * Return nothing. | |
3065 | */ | |
3066 | void | |
3067 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
3068 | { | |
3069 | struct fw_event_work *fw_event; | |
3070 | ||
146b16c8 | 3071 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
3072 | if (!fw_event) |
3073 | return; | |
3074 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
3075 | fw_event->ioc = ioc; | |
3076 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 SR |
3077 | fw_event_work_put(fw_event); |
3078 | } | |
3079 | ||
3080 | static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc) | |
3081 | { | |
3082 | unsigned long flags; | |
3083 | struct fw_event_work *fw_event = NULL; | |
3084 | ||
3085 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3086 | if (!list_empty(&ioc->fw_event_list)) { | |
3087 | fw_event = list_first_entry(&ioc->fw_event_list, | |
3088 | struct fw_event_work, list); | |
3089 | list_del_init(&fw_event->list); | |
3090 | } | |
3091 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3092 | ||
3093 | return fw_event; | |
f92363d1 SR |
3094 | } |
3095 | ||
3096 | /** | |
3097 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
3098 | * @ioc: per adapter object | |
3099 | * | |
3100 | * Walk the firmware event queue, either killing timers, or waiting | |
3101 | * for outstanding events to complete | |
3102 | * | |
3103 | * Return nothing. | |
3104 | */ | |
3105 | static void | |
3106 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
3107 | { | |
146b16c8 | 3108 | struct fw_event_work *fw_event; |
f92363d1 SR |
3109 | |
3110 | if (list_empty(&ioc->fw_event_list) || | |
3111 | !ioc->firmware_event_thread || in_interrupt()) | |
3112 | return; | |
3113 | ||
146b16c8 SR |
3114 | while ((fw_event = dequeue_next_fw_event(ioc))) { |
3115 | /* | |
3116 | * Wait on the fw_event to complete. If this returns 1, then | |
3117 | * the event was never executed, and we need a put for the | |
b8ac0cc7 | 3118 | * reference the work had on the fw_event. |
146b16c8 SR |
3119 | * |
3120 | * If it did execute, we wait for it to finish, and the put will | |
3121 | * happen from _firmware_event_work() | |
3122 | */ | |
b8ac0cc7 | 3123 | if (cancel_work_sync(&fw_event->work)) |
146b16c8 SR |
3124 | fw_event_work_put(fw_event); |
3125 | ||
3126 | fw_event_work_put(fw_event); | |
f92363d1 SR |
3127 | } |
3128 | } | |
3129 | ||
df838f92 SR |
3130 | /** |
3131 | * _scsih_internal_device_block - block the sdev device | |
3132 | * @sdev: per device object | |
3133 | * @sas_device_priv_data : per device driver private data | |
3134 | * | |
3135 | * make sure device is blocked without error, if not | |
3136 | * print an error | |
3137 | */ | |
3138 | static void | |
3139 | _scsih_internal_device_block(struct scsi_device *sdev, | |
3140 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3141 | { | |
3142 | int r = 0; | |
3143 | ||
3144 | sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n", | |
3145 | sas_device_priv_data->sas_target->handle); | |
3146 | sas_device_priv_data->block = 1; | |
3147 | ||
551eb598 | 3148 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3149 | if (r == -EINVAL) |
3150 | sdev_printk(KERN_WARNING, sdev, | |
3151 | "device_block failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3152 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3153 | } |
3154 | ||
3155 | /** | |
3156 | * _scsih_internal_device_unblock - unblock the sdev device | |
3157 | * @sdev: per device object | |
3158 | * @sas_device_priv_data : per device driver private data | |
3159 | * make sure device is unblocked without error, if not retry | |
3160 | * by blocking and then unblocking | |
3161 | */ | |
3162 | ||
3163 | static void | |
3164 | _scsih_internal_device_unblock(struct scsi_device *sdev, | |
3165 | struct MPT3SAS_DEVICE *sas_device_priv_data) | |
3166 | { | |
3167 | int r = 0; | |
3168 | ||
3169 | sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, " | |
3170 | "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle); | |
3171 | sas_device_priv_data->block = 0; | |
43f7571b | 3172 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3173 | if (r == -EINVAL) { |
3174 | /* The device has been set to SDEV_RUNNING by SD layer during | |
3175 | * device addition but the request queue is still stopped by | |
3176 | * our earlier block call. We need to perform a block again | |
3177 | * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */ | |
3178 | ||
3179 | sdev_printk(KERN_WARNING, sdev, | |
3180 | "device_unblock failed with return(%d) for handle(0x%04x) " | |
3181 | "performing a block followed by an unblock\n", | |
b2fe6be7 | 3182 | r, sas_device_priv_data->sas_target->handle); |
df838f92 | 3183 | sas_device_priv_data->block = 1; |
551eb598 | 3184 | r = scsi_internal_device_block_nowait(sdev); |
df838f92 SR |
3185 | if (r) |
3186 | sdev_printk(KERN_WARNING, sdev, "retried device_block " | |
3187 | "failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3188 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3189 | |
3190 | sas_device_priv_data->block = 0; | |
43f7571b | 3191 | r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING); |
df838f92 SR |
3192 | if (r) |
3193 | sdev_printk(KERN_WARNING, sdev, "retried device_unblock" | |
3194 | " failed with return(%d) for handle(0x%04x)\n", | |
b2fe6be7 | 3195 | r, sas_device_priv_data->sas_target->handle); |
df838f92 SR |
3196 | } |
3197 | } | |
3198 | ||
f92363d1 SR |
3199 | /** |
3200 | * _scsih_ublock_io_all_device - unblock every device | |
3201 | * @ioc: per adapter object | |
3202 | * | |
3203 | * change the device state from block to running | |
3204 | */ | |
3205 | static void | |
3206 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3207 | { | |
3208 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3209 | struct scsi_device *sdev; | |
3210 | ||
3211 | shost_for_each_device(sdev, ioc->shost) { | |
3212 | sas_device_priv_data = sdev->hostdata; | |
3213 | if (!sas_device_priv_data) | |
3214 | continue; | |
3215 | if (!sas_device_priv_data->block) | |
3216 | continue; | |
3217 | ||
f92363d1 SR |
3218 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
3219 | "device_running, handle(0x%04x)\n", | |
3220 | sas_device_priv_data->sas_target->handle)); | |
df838f92 | 3221 | _scsih_internal_device_unblock(sdev, sas_device_priv_data); |
f92363d1 SR |
3222 | } |
3223 | } | |
3224 | ||
3225 | ||
3226 | /** | |
3227 | * _scsih_ublock_io_device - prepare device to be deleted | |
3228 | * @ioc: per adapter object | |
3229 | * @sas_addr: sas address | |
3230 | * | |
3231 | * unblock then put device in offline state | |
3232 | */ | |
3233 | static void | |
3234 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
3235 | { | |
3236 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3237 | struct scsi_device *sdev; | |
3238 | ||
3239 | shost_for_each_device(sdev, ioc->shost) { | |
3240 | sas_device_priv_data = sdev->hostdata; | |
3241 | if (!sas_device_priv_data) | |
3242 | continue; | |
3243 | if (sas_device_priv_data->sas_target->sas_address | |
3244 | != sas_address) | |
3245 | continue; | |
df838f92 SR |
3246 | if (sas_device_priv_data->block) |
3247 | _scsih_internal_device_unblock(sdev, | |
3248 | sas_device_priv_data); | |
f92363d1 SR |
3249 | } |
3250 | } | |
3251 | ||
3252 | /** | |
3253 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
3254 | * @ioc: per adapter object | |
3255 | * @handle: device handle | |
3256 | * | |
6c7abffc | 3257 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3258 | */ |
3259 | static void | |
3260 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
3261 | { | |
3262 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3263 | struct scsi_device *sdev; | |
3264 | ||
3265 | shost_for_each_device(sdev, ioc->shost) { | |
3266 | sas_device_priv_data = sdev->hostdata; | |
3267 | if (!sas_device_priv_data) | |
3268 | continue; | |
3269 | if (sas_device_priv_data->block) | |
3270 | continue; | |
30158dc9 SS |
3271 | if (sas_device_priv_data->ignore_delay_remove) { |
3272 | sdev_printk(KERN_INFO, sdev, | |
3273 | "%s skip device_block for SES handle(0x%04x)\n", | |
3274 | __func__, sas_device_priv_data->sas_target->handle); | |
3275 | continue; | |
3276 | } | |
df838f92 | 3277 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 SR |
3278 | } |
3279 | } | |
3280 | ||
3281 | /** | |
3282 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
3283 | * @ioc: per adapter object | |
3284 | * @handle: device handle | |
3285 | * | |
6c7abffc | 3286 | * During device pull we need to appropriately set the sdev state. |
f92363d1 SR |
3287 | */ |
3288 | static void | |
3289 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3290 | { | |
3291 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
3292 | struct scsi_device *sdev; | |
e4bc7f5c SR |
3293 | struct _sas_device *sas_device; |
3294 | ||
d1cb5e49 | 3295 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
e4bc7f5c SR |
3296 | if (!sas_device) |
3297 | return; | |
f92363d1 SR |
3298 | |
3299 | shost_for_each_device(sdev, ioc->shost) { | |
3300 | sas_device_priv_data = sdev->hostdata; | |
3301 | if (!sas_device_priv_data) | |
3302 | continue; | |
3303 | if (sas_device_priv_data->sas_target->handle != handle) | |
3304 | continue; | |
3305 | if (sas_device_priv_data->block) | |
3306 | continue; | |
e4bc7f5c SR |
3307 | if (sas_device->pend_sas_rphy_add) |
3308 | continue; | |
30158dc9 SS |
3309 | if (sas_device_priv_data->ignore_delay_remove) { |
3310 | sdev_printk(KERN_INFO, sdev, | |
3311 | "%s skip device_block for SES handle(0x%04x)\n", | |
3312 | __func__, sas_device_priv_data->sas_target->handle); | |
3313 | continue; | |
3314 | } | |
df838f92 | 3315 | _scsih_internal_device_block(sdev, sas_device_priv_data); |
f92363d1 | 3316 | } |
d1cb5e49 SR |
3317 | |
3318 | sas_device_put(sas_device); | |
f92363d1 SR |
3319 | } |
3320 | ||
3321 | /** | |
3322 | * _scsih_block_io_to_children_attached_to_ex | |
3323 | * @ioc: per adapter object | |
3324 | * @sas_expander: the sas_device object | |
3325 | * | |
3326 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3327 | * attached to this expander. This function called when expander is | |
3328 | * pulled. | |
3329 | */ | |
3330 | static void | |
3331 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
3332 | struct _sas_node *sas_expander) | |
3333 | { | |
3334 | struct _sas_port *mpt3sas_port; | |
3335 | struct _sas_device *sas_device; | |
3336 | struct _sas_node *expander_sibling; | |
3337 | unsigned long flags; | |
3338 | ||
3339 | if (!sas_expander) | |
3340 | return; | |
3341 | ||
3342 | list_for_each_entry(mpt3sas_port, | |
3343 | &sas_expander->sas_port_list, port_list) { | |
3344 | if (mpt3sas_port->remote_identify.device_type == | |
3345 | SAS_END_DEVICE) { | |
3346 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
3347 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
3348 | mpt3sas_port->remote_identify.sas_address); | |
3349 | if (sas_device) { | |
f92363d1 | 3350 | set_bit(sas_device->handle, |
d1cb5e49 SR |
3351 | ioc->blocking_handles); |
3352 | sas_device_put(sas_device); | |
3353 | } | |
f92363d1 SR |
3354 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
3355 | } | |
3356 | } | |
3357 | ||
3358 | list_for_each_entry(mpt3sas_port, | |
3359 | &sas_expander->sas_port_list, port_list) { | |
3360 | ||
3361 | if (mpt3sas_port->remote_identify.device_type == | |
3362 | SAS_EDGE_EXPANDER_DEVICE || | |
3363 | mpt3sas_port->remote_identify.device_type == | |
3364 | SAS_FANOUT_EXPANDER_DEVICE) { | |
3365 | expander_sibling = | |
3366 | mpt3sas_scsih_expander_find_by_sas_address( | |
3367 | ioc, mpt3sas_port->remote_identify.sas_address); | |
3368 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
3369 | expander_sibling); | |
3370 | } | |
3371 | } | |
3372 | } | |
3373 | ||
3374 | /** | |
3375 | * _scsih_block_io_to_children_attached_directly | |
3376 | * @ioc: per adapter object | |
3377 | * @event_data: topology change event data | |
3378 | * | |
3379 | * This routine set sdev state to SDEV_BLOCK for all devices | |
3380 | * direct attached during device pull. | |
3381 | */ | |
3382 | static void | |
3383 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
3384 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3385 | { | |
3386 | int i; | |
3387 | u16 handle; | |
3388 | u16 reason_code; | |
f92363d1 SR |
3389 | |
3390 | for (i = 0; i < event_data->NumEntries; i++) { | |
3391 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3392 | if (!handle) | |
3393 | continue; | |
f92363d1 SR |
3394 | reason_code = event_data->PHY[i].PhyStatus & |
3395 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3396 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
3397 | _scsih_block_io_device(ioc, handle); | |
3398 | } | |
3399 | } | |
3400 | ||
3401 | /** | |
3402 | * _scsih_tm_tr_send - send task management request | |
3403 | * @ioc: per adapter object | |
3404 | * @handle: device handle | |
3405 | * Context: interrupt time. | |
3406 | * | |
3407 | * This code is to initiate the device removal handshake protocol | |
3408 | * with controller firmware. This function will issue target reset | |
3409 | * using high priority request queue. It will send a sas iounit | |
3410 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
3411 | * | |
3412 | * This is designed to send muliple task management request at the same | |
3413 | * time to the fifo. If the fifo is full, we will append the request, | |
3414 | * and process it in a future completion. | |
3415 | */ | |
3416 | static void | |
3417 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3418 | { | |
3419 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3420 | u16 smid; | |
d1cb5e49 | 3421 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
3422 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
3423 | u64 sas_address = 0; | |
3424 | unsigned long flags; | |
3425 | struct _tr_list *delayed_tr; | |
3426 | u32 ioc_state; | |
3427 | ||
3428 | if (ioc->remove_host) { | |
3429 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3430 | "%s: host has been removed: handle(0x%04x)\n", | |
3431 | __func__, ioc->name, handle)); | |
3432 | return; | |
3433 | } else if (ioc->pci_error_recovery) { | |
3434 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3435 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
3436 | __func__, ioc->name, | |
3437 | handle)); | |
3438 | return; | |
3439 | } | |
3440 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3441 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3442 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3443 | "%s: host is not operational: handle(0x%04x)\n", | |
3444 | __func__, ioc->name, | |
3445 | handle)); | |
3446 | return; | |
3447 | } | |
3448 | ||
3449 | /* if PD, then return */ | |
3450 | if (test_bit(handle, ioc->pd_handles)) | |
3451 | return; | |
3452 | ||
c696f7b8 SPS |
3453 | clear_bit(handle, ioc->pend_os_device_add); |
3454 | ||
f92363d1 | 3455 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
d1cb5e49 | 3456 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
3457 | if (sas_device && sas_device->starget && |
3458 | sas_device->starget->hostdata) { | |
3459 | sas_target_priv_data = sas_device->starget->hostdata; | |
3460 | sas_target_priv_data->deleted = 1; | |
3461 | sas_address = sas_device->sas_address; | |
3462 | } | |
3463 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3464 | ||
3465 | if (sas_target_priv_data) { | |
3466 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3467 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
3468 | ioc->name, handle, | |
3469 | (unsigned long long)sas_address)); | |
75888956 SR |
3470 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, |
3471 | sas_device, NULL, NULL)); | |
f92363d1 SR |
3472 | _scsih_ublock_io_device(ioc, sas_address); |
3473 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
3474 | } | |
3475 | ||
3476 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
3477 | if (!smid) { | |
3478 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3479 | if (!delayed_tr) | |
d1cb5e49 | 3480 | goto out; |
f92363d1 SR |
3481 | INIT_LIST_HEAD(&delayed_tr->list); |
3482 | delayed_tr->handle = handle; | |
3483 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3484 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3485 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3486 | ioc->name, handle)); | |
d1cb5e49 | 3487 | goto out; |
f92363d1 SR |
3488 | } |
3489 | ||
3490 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3491 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3492 | ioc->name, handle, smid, | |
3493 | ioc->tm_tr_cb_idx)); | |
3494 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3495 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3496 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3497 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3498 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
c696f7b8 | 3499 | set_bit(handle, ioc->device_remove_in_progress); |
81c16f83 | 3500 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 | 3501 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
d1cb5e49 SR |
3502 | |
3503 | out: | |
3504 | if (sas_device) | |
3505 | sas_device_put(sas_device); | |
f92363d1 SR |
3506 | } |
3507 | ||
3508 | /** | |
3509 | * _scsih_tm_tr_complete - | |
3510 | * @ioc: per adapter object | |
3511 | * @smid: system request message index | |
3512 | * @msix_index: MSIX table index supplied by the OS | |
3513 | * @reply: reply message frame(lower 32bit addr) | |
3514 | * Context: interrupt time. | |
3515 | * | |
3516 | * This is the target reset completion routine. | |
3517 | * This code is part of the code to initiate the device removal | |
3518 | * handshake protocol with controller firmware. | |
3519 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
3520 | * | |
3521 | * Return 1 meaning mf should be freed from _base_interrupt | |
3522 | * 0 means the mf is freed from this function. | |
3523 | */ | |
3524 | static u8 | |
3525 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
3526 | u32 reply) | |
3527 | { | |
3528 | u16 handle; | |
3529 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3530 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3531 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3532 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3533 | u16 smid_sas_ctrl; | |
3534 | u32 ioc_state; | |
fd0331b3 | 3535 | struct _sc_list *delayed_sc; |
f92363d1 SR |
3536 | |
3537 | if (ioc->remove_host) { | |
3538 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3539 | "%s: host has been removed\n", __func__, ioc->name)); | |
3540 | return 1; | |
3541 | } else if (ioc->pci_error_recovery) { | |
3542 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3543 | "%s: host in pci error recovery\n", __func__, | |
3544 | ioc->name)); | |
3545 | return 1; | |
3546 | } | |
3547 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3548 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3549 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3550 | "%s: host is not operational\n", __func__, ioc->name)); | |
3551 | return 1; | |
3552 | } | |
3553 | if (unlikely(!mpi_reply)) { | |
3554 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3555 | ioc->name, __FILE__, __LINE__, __func__); | |
3556 | return 1; | |
3557 | } | |
3558 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3559 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3560 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3561 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3562 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3563 | ioc->name, handle, | |
3564 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3565 | return 0; | |
3566 | } | |
3567 | ||
3568 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
3569 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3570 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3571 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3572 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3573 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3574 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3575 | ||
3576 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
3577 | if (!smid_sas_ctrl) { | |
fd0331b3 SS |
3578 | delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC); |
3579 | if (!delayed_sc) | |
3580 | return _scsih_check_for_pending_tm(ioc, smid); | |
3581 | INIT_LIST_HEAD(&delayed_sc->list); | |
3582 | delayed_sc->handle = mpi_request_tm->DevHandle; | |
3583 | list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list); | |
3584 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3585 | "DELAYED:sc:handle(0x%04x), (open)\n", | |
3586 | ioc->name, handle)); | |
3587 | return _scsih_check_for_pending_tm(ioc, smid); | |
f92363d1 SR |
3588 | } |
3589 | ||
3590 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3591 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3592 | ioc->name, handle, smid_sas_ctrl, | |
3593 | ioc->tm_sas_control_cb_idx)); | |
3594 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
3595 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3596 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3597 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3598 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
81c16f83 | 3599 | ioc->put_smid_default(ioc, smid_sas_ctrl); |
f92363d1 SR |
3600 | |
3601 | return _scsih_check_for_pending_tm(ioc, smid); | |
3602 | } | |
3603 | ||
3604 | ||
3605 | /** | |
3606 | * _scsih_sas_control_complete - completion routine | |
3607 | * @ioc: per adapter object | |
3608 | * @smid: system request message index | |
3609 | * @msix_index: MSIX table index supplied by the OS | |
3610 | * @reply: reply message frame(lower 32bit addr) | |
3611 | * Context: interrupt time. | |
3612 | * | |
3613 | * This is the sas iounit control completion routine. | |
3614 | * This code is part of the code to initiate the device removal | |
3615 | * handshake protocol with controller firmware. | |
3616 | * | |
3617 | * Return 1 meaning mf should be freed from _base_interrupt | |
3618 | * 0 means the mf is freed from this function. | |
3619 | */ | |
3620 | static u8 | |
3621 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3622 | u8 msix_index, u32 reply) | |
3623 | { | |
3624 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
3625 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3626 | ||
3627 | if (likely(mpi_reply)) { | |
3628 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3629 | "sc_complete:handle(0x%04x), (open) " | |
3630 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
3631 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
3632 | le16_to_cpu(mpi_reply->IOCStatus), | |
3633 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
c696f7b8 SPS |
3634 | if (le16_to_cpu(mpi_reply->IOCStatus) == |
3635 | MPI2_IOCSTATUS_SUCCESS) { | |
3636 | clear_bit(le16_to_cpu(mpi_reply->DevHandle), | |
3637 | ioc->device_remove_in_progress); | |
3638 | } | |
f92363d1 SR |
3639 | } else { |
3640 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3641 | ioc->name, __FILE__, __LINE__, __func__); | |
3642 | } | |
fd0331b3 | 3643 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
f92363d1 SR |
3644 | } |
3645 | ||
3646 | /** | |
3647 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3648 | * @ioc: per adapter object | |
3649 | * @handle: device handle | |
3650 | * Context: interrupt time. | |
3651 | * | |
3652 | * This is designed to send muliple task management request at the same | |
3653 | * time to the fifo. If the fifo is full, we will append the request, | |
3654 | * and process it in a future completion. | |
3655 | */ | |
3656 | static void | |
3657 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3658 | { | |
3659 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3660 | u16 smid; | |
3661 | struct _tr_list *delayed_tr; | |
3662 | ||
3663 | if (ioc->shost_recovery || ioc->remove_host || | |
3664 | ioc->pci_error_recovery) { | |
3665 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3666 | "%s: host reset in progress!\n", | |
3667 | __func__, ioc->name)); | |
3668 | return; | |
3669 | } | |
3670 | ||
3671 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3672 | if (!smid) { | |
3673 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3674 | if (!delayed_tr) | |
3675 | return; | |
3676 | INIT_LIST_HEAD(&delayed_tr->list); | |
3677 | delayed_tr->handle = handle; | |
3678 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
3679 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3680 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3681 | ioc->name, handle)); | |
3682 | return; | |
3683 | } | |
3684 | ||
3685 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3686 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3687 | ioc->name, handle, smid, | |
3688 | ioc->tm_tr_volume_cb_idx)); | |
3689 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3690 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3691 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3692 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3693 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
81c16f83 | 3694 | ioc->put_smid_hi_priority(ioc, smid, 0); |
f92363d1 SR |
3695 | } |
3696 | ||
3697 | /** | |
3698 | * _scsih_tm_volume_tr_complete - target reset completion | |
3699 | * @ioc: per adapter object | |
3700 | * @smid: system request message index | |
3701 | * @msix_index: MSIX table index supplied by the OS | |
3702 | * @reply: reply message frame(lower 32bit addr) | |
3703 | * Context: interrupt time. | |
3704 | * | |
3705 | * Return 1 meaning mf should be freed from _base_interrupt | |
3706 | * 0 means the mf is freed from this function. | |
3707 | */ | |
3708 | static u8 | |
3709 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3710 | u8 msix_index, u32 reply) | |
3711 | { | |
3712 | u16 handle; | |
3713 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3714 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3715 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3716 | ||
3717 | if (ioc->shost_recovery || ioc->remove_host || | |
3718 | ioc->pci_error_recovery) { | |
3719 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3720 | "%s: host reset in progress!\n", | |
3721 | __func__, ioc->name)); | |
3722 | return 1; | |
3723 | } | |
3724 | if (unlikely(!mpi_reply)) { | |
3725 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3726 | ioc->name, __FILE__, __LINE__, __func__); | |
3727 | return 1; | |
3728 | } | |
3729 | ||
3730 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3731 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3732 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3733 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3734 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3735 | ioc->name, handle, | |
3736 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3737 | return 0; | |
3738 | } | |
3739 | ||
3740 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3741 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3742 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3743 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3744 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3745 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3746 | ||
3747 | return _scsih_check_for_pending_tm(ioc, smid); | |
3748 | } | |
3749 | ||
fd0331b3 SS |
3750 | /** |
3751 | * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages | |
3752 | * @ioc: per adapter object | |
3753 | * @smid: system request message index | |
3754 | * @event: Event ID | |
3755 | * @event_context: used to track events uniquely | |
3756 | * | |
3757 | * Context - processed in interrupt context. | |
3758 | */ | |
8bbb1cf6 | 3759 | static void |
fd0331b3 SS |
3760 | _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event, |
3761 | u32 event_context) | |
3762 | { | |
3763 | Mpi2EventAckRequest_t *ack_request; | |
3764 | int i = smid - ioc->internal_smid; | |
3765 | unsigned long flags; | |
3766 | ||
3767 | /* Without releasing the smid just update the | |
3768 | * call back index and reuse the same smid for | |
3769 | * processing this delayed request | |
3770 | */ | |
3771 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
3772 | ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx; | |
3773 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
3774 | ||
3775 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3776 | "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n", | |
3777 | ioc->name, le16_to_cpu(event), smid, | |
3778 | ioc->base_cb_idx)); | |
3779 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3780 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | |
3781 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | |
3782 | ack_request->Event = event; | |
3783 | ack_request->EventContext = event_context; | |
3784 | ack_request->VF_ID = 0; /* TODO */ | |
3785 | ack_request->VP_ID = 0; | |
81c16f83 | 3786 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
3787 | } |
3788 | ||
3789 | /** | |
3790 | * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed | |
3791 | * sas_io_unit_ctrl messages | |
3792 | * @ioc: per adapter object | |
3793 | * @smid: system request message index | |
3794 | * @handle: device handle | |
3795 | * | |
3796 | * Context - processed in interrupt context. | |
3797 | */ | |
8bbb1cf6 | 3798 | static void |
fd0331b3 SS |
3799 | _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc, |
3800 | u16 smid, u16 handle) | |
3801 | { | |
3802 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
3803 | u32 ioc_state; | |
3804 | int i = smid - ioc->internal_smid; | |
3805 | unsigned long flags; | |
3806 | ||
3807 | if (ioc->remove_host) { | |
3808 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3809 | "%s: host has been removed\n", | |
3810 | __func__, ioc->name)); | |
3811 | return; | |
3812 | } else if (ioc->pci_error_recovery) { | |
3813 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3814 | "%s: host in pci error recovery\n", | |
3815 | __func__, ioc->name)); | |
3816 | return; | |
3817 | } | |
3818 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
3819 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
3820 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3821 | "%s: host is not operational\n", | |
3822 | __func__, ioc->name)); | |
3823 | return; | |
3824 | } | |
3825 | ||
3826 | /* Without releasing the smid just update the | |
3827 | * call back index and reuse the same smid for | |
3828 | * processing this delayed request | |
3829 | */ | |
3830 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
3831 | ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx; | |
3832 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
3833 | ||
3834 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3835 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3836 | ioc->name, le16_to_cpu(handle), smid, | |
3837 | ioc->tm_sas_control_cb_idx)); | |
3838 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3839 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
3840 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
3841 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
3842 | mpi_request->DevHandle = handle; | |
81c16f83 | 3843 | ioc->put_smid_default(ioc, smid); |
fd0331b3 SS |
3844 | } |
3845 | ||
3846 | /** | |
3847 | * _scsih_check_for_pending_internal_cmds - check for pending internal messages | |
3848 | * @ioc: per adapter object | |
3849 | * @smid: system request message index | |
3850 | * | |
3851 | * Context: Executed in interrupt context | |
3852 | * | |
3853 | * This will check delayed internal messages list, and process the | |
3854 | * next request. | |
3855 | * | |
3856 | * Return 1 meaning mf should be freed from _base_interrupt | |
3857 | * 0 means the mf is freed from this function. | |
3858 | */ | |
3859 | u8 | |
3860 | mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
3861 | { | |
3862 | struct _sc_list *delayed_sc; | |
3863 | struct _event_ack_list *delayed_event_ack; | |
3864 | ||
3865 | if (!list_empty(&ioc->delayed_event_ack_list)) { | |
3866 | delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next, | |
3867 | struct _event_ack_list, list); | |
3868 | _scsih_issue_delayed_event_ack(ioc, smid, | |
3869 | delayed_event_ack->Event, delayed_event_ack->EventContext); | |
3870 | list_del(&delayed_event_ack->list); | |
3871 | kfree(delayed_event_ack); | |
3872 | return 0; | |
3873 | } | |
3874 | ||
3875 | if (!list_empty(&ioc->delayed_sc_list)) { | |
3876 | delayed_sc = list_entry(ioc->delayed_sc_list.next, | |
3877 | struct _sc_list, list); | |
3878 | _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid, | |
3879 | delayed_sc->handle); | |
3880 | list_del(&delayed_sc->list); | |
3881 | kfree(delayed_sc); | |
3882 | return 0; | |
3883 | } | |
3884 | return 1; | |
3885 | } | |
f92363d1 SR |
3886 | |
3887 | /** | |
3888 | * _scsih_check_for_pending_tm - check for pending task management | |
3889 | * @ioc: per adapter object | |
3890 | * @smid: system request message index | |
3891 | * | |
3892 | * This will check delayed target reset list, and feed the | |
3893 | * next reqeust. | |
3894 | * | |
3895 | * Return 1 meaning mf should be freed from _base_interrupt | |
3896 | * 0 means the mf is freed from this function. | |
3897 | */ | |
3898 | static u8 | |
3899 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
3900 | { | |
3901 | struct _tr_list *delayed_tr; | |
3902 | ||
3903 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
3904 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
3905 | struct _tr_list, list); | |
3906 | mpt3sas_base_free_smid(ioc, smid); | |
3907 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
3908 | list_del(&delayed_tr->list); | |
3909 | kfree(delayed_tr); | |
3910 | return 0; | |
3911 | } | |
3912 | ||
3913 | if (!list_empty(&ioc->delayed_tr_list)) { | |
3914 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
3915 | struct _tr_list, list); | |
3916 | mpt3sas_base_free_smid(ioc, smid); | |
3917 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
3918 | list_del(&delayed_tr->list); | |
3919 | kfree(delayed_tr); | |
3920 | return 0; | |
3921 | } | |
3922 | ||
3923 | return 1; | |
3924 | } | |
3925 | ||
3926 | /** | |
3927 | * _scsih_check_topo_delete_events - sanity check on topo events | |
3928 | * @ioc: per adapter object | |
3929 | * @event_data: the event data payload | |
3930 | * | |
3931 | * This routine added to better handle cable breaker. | |
3932 | * | |
3933 | * This handles the case where driver receives multiple expander | |
3934 | * add and delete events in a single shot. When there is a delete event | |
3935 | * the routine will void any pending add events waiting in the event queue. | |
3936 | * | |
3937 | * Return nothing. | |
3938 | */ | |
3939 | static void | |
3940 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
3941 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3942 | { | |
3943 | struct fw_event_work *fw_event; | |
3944 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
3945 | u16 expander_handle; | |
3946 | struct _sas_node *sas_expander; | |
3947 | unsigned long flags; | |
3948 | int i, reason_code; | |
3949 | u16 handle; | |
3950 | ||
3951 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
3952 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3953 | if (!handle) | |
3954 | continue; | |
3955 | reason_code = event_data->PHY[i].PhyStatus & | |
3956 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3957 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
3958 | _scsih_tm_tr_send(ioc, handle); | |
3959 | } | |
3960 | ||
3961 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
3962 | if (expander_handle < ioc->sas_hba.num_phys) { | |
3963 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
3964 | return; | |
3965 | } | |
3966 | if (event_data->ExpStatus == | |
3967 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
3968 | /* put expander attached devices into blocking state */ | |
3969 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
3970 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
3971 | expander_handle); | |
3972 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
3973 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
3974 | do { | |
3975 | handle = find_first_bit(ioc->blocking_handles, | |
3976 | ioc->facts.MaxDevHandle); | |
3977 | if (handle < ioc->facts.MaxDevHandle) | |
3978 | _scsih_block_io_device(ioc, handle); | |
3979 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
3980 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
3981 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
3982 | ||
3983 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
3984 | return; | |
3985 | ||
3986 | /* mark ignore flag for pending events */ | |
3987 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3988 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
3989 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
3990 | fw_event->ignore) | |
3991 | continue; | |
35b62362 JL |
3992 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
3993 | fw_event->event_data; | |
f92363d1 SR |
3994 | if (local_event_data->ExpStatus == |
3995 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
3996 | local_event_data->ExpStatus == | |
3997 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
3998 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
3999 | expander_handle) { | |
4000 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4001 | "setting ignoring flag\n", ioc->name)); | |
4002 | fw_event->ignore = 1; | |
4003 | } | |
4004 | } | |
4005 | } | |
4006 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
4007 | } | |
4008 | ||
4009 | /** | |
4010 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
4011 | * @ioc: per adapter object | |
4012 | * @handle: device handle | |
4013 | * | |
4014 | * This returns nothing. | |
4015 | */ | |
4016 | static void | |
4017 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4018 | { | |
4019 | struct _raid_device *raid_device; | |
4020 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4021 | unsigned long flags; | |
4022 | ||
4023 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 4024 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
4025 | if (raid_device && raid_device->starget && |
4026 | raid_device->starget->hostdata) { | |
4027 | sas_target_priv_data = | |
4028 | raid_device->starget->hostdata; | |
4029 | sas_target_priv_data->deleted = 1; | |
4030 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4031 | "setting delete flag: handle(0x%04x), " | |
4032 | "wwid(0x%016llx)\n", ioc->name, handle, | |
4033 | (unsigned long long) raid_device->wwid)); | |
4034 | } | |
4035 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
4036 | } | |
4037 | ||
4038 | /** | |
4039 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
4040 | * @handle: input handle | |
4041 | * @a: handle for volume a | |
4042 | * @b: handle for volume b | |
4043 | * | |
4044 | * IR firmware only supports two raid volumes. The purpose of this | |
4045 | * routine is to set the volume handle in either a or b. When the given | |
4046 | * input handle is non-zero, or when a and b have not been set before. | |
4047 | */ | |
4048 | static void | |
4049 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
4050 | { | |
4051 | if (!handle || handle == *a || handle == *b) | |
4052 | return; | |
4053 | if (!*a) | |
4054 | *a = handle; | |
4055 | else if (!*b) | |
4056 | *b = handle; | |
4057 | } | |
4058 | ||
4059 | /** | |
4060 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
4061 | * @ioc: per adapter object | |
4062 | * @event_data: the event data payload | |
4063 | * Context: interrupt time. | |
4064 | * | |
4065 | * This routine will send target reset to volume, followed by target | |
4066 | * resets to the PDs. This is called when a PD has been removed, or | |
4067 | * volume has been deleted or removed. When the target reset is sent | |
4068 | * to volume, the PD target resets need to be queued to start upon | |
4069 | * completion of the volume target reset. | |
4070 | * | |
4071 | * Return nothing. | |
4072 | */ | |
4073 | static void | |
4074 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
4075 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
4076 | { | |
4077 | Mpi2EventIrConfigElement_t *element; | |
4078 | int i; | |
4079 | u16 handle, volume_handle, a, b; | |
4080 | struct _tr_list *delayed_tr; | |
4081 | ||
4082 | a = 0; | |
4083 | b = 0; | |
4084 | ||
7786ab6a SR |
4085 | if (ioc->is_warpdrive) |
4086 | return; | |
4087 | ||
f92363d1 SR |
4088 | /* Volume Resets for Deleted or Removed */ |
4089 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4090 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4091 | if (le32_to_cpu(event_data->Flags) & | |
4092 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4093 | continue; | |
4094 | if (element->ReasonCode == | |
4095 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
4096 | element->ReasonCode == | |
4097 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
4098 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4099 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
4100 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4101 | } | |
4102 | } | |
4103 | ||
4104 | /* Volume Resets for UNHIDE events */ | |
4105 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4106 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4107 | if (le32_to_cpu(event_data->Flags) & | |
4108 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
4109 | continue; | |
4110 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
4111 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4112 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
4113 | } | |
4114 | } | |
4115 | ||
4116 | if (a) | |
4117 | _scsih_tm_tr_volume_send(ioc, a); | |
4118 | if (b) | |
4119 | _scsih_tm_tr_volume_send(ioc, b); | |
4120 | ||
4121 | /* PD target resets */ | |
4122 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
4123 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
4124 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
4125 | continue; | |
4126 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
4127 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
4128 | clear_bit(handle, ioc->pd_handles); | |
4129 | if (!volume_handle) | |
4130 | _scsih_tm_tr_send(ioc, handle); | |
4131 | else if (volume_handle == a || volume_handle == b) { | |
4132 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
4133 | BUG_ON(!delayed_tr); | |
4134 | INIT_LIST_HEAD(&delayed_tr->list); | |
4135 | delayed_tr->handle = handle; | |
4136 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
4137 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4138 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
4139 | handle)); | |
4140 | } else | |
4141 | _scsih_tm_tr_send(ioc, handle); | |
4142 | } | |
4143 | } | |
4144 | ||
4145 | ||
4146 | /** | |
4147 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
4148 | * @ioc: per adapter object | |
4149 | * @event_data: the event data payload | |
4150 | * Context: interrupt time. | |
4151 | * | |
4152 | * This will handle the case when the cable connected to entire volume is | |
4153 | * pulled. We will take care of setting the deleted flag so normal IO will | |
4154 | * not be sent. | |
4155 | * | |
4156 | * Return nothing. | |
4157 | */ | |
4158 | static void | |
4159 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
4160 | Mpi2EventDataIrVolume_t *event_data) | |
4161 | { | |
4162 | u32 state; | |
4163 | ||
4164 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
4165 | return; | |
4166 | state = le32_to_cpu(event_data->NewValue); | |
4167 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
4168 | MPI2_RAID_VOL_STATE_FAILED) | |
4169 | _scsih_set_volume_delete_flag(ioc, | |
4170 | le16_to_cpu(event_data->VolDevHandle)); | |
4171 | } | |
4172 | ||
2d8ce8c9 SR |
4173 | /** |
4174 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | |
4175 | * @ioc: per adapter object | |
4176 | * @event_data: the temp threshold event data | |
4177 | * Context: interrupt time. | |
4178 | * | |
4179 | * Return nothing. | |
4180 | */ | |
4181 | static void | |
4182 | _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc, | |
4183 | Mpi2EventDataTemperature_t *event_data) | |
4184 | { | |
4185 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | |
4186 | pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s" | |
4187 | " exceeded for Sensor: %d !!!\n", ioc->name, | |
4188 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | |
4189 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | |
4190 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | |
4191 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | |
4192 | event_data->SensorNum); | |
4193 | pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n", | |
4194 | ioc->name, event_data->CurrentTemperature); | |
4195 | } | |
4196 | } | |
4197 | ||
ffb58456 | 4198 | static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending) |
7ff723ad | 4199 | { |
ffb58456 JB |
4200 | struct MPT3SAS_DEVICE *priv = scmd->device->hostdata; |
4201 | ||
4202 | if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16) | |
4203 | return 0; | |
4204 | ||
4205 | if (pending) | |
4206 | return test_and_set_bit(0, &priv->ata_command_pending); | |
4207 | ||
4208 | clear_bit(0, &priv->ata_command_pending); | |
4209 | return 0; | |
7ff723ad SP |
4210 | } |
4211 | ||
f92363d1 SR |
4212 | /** |
4213 | * _scsih_flush_running_cmds - completing outstanding commands. | |
4214 | * @ioc: per adapter object | |
4215 | * | |
4216 | * The flushing out of all pending scmd commands following host reset, | |
4217 | * where all IO is dropped to the floor. | |
4218 | * | |
4219 | * Return nothing. | |
4220 | */ | |
4221 | static void | |
4222 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
4223 | { | |
4224 | struct scsi_cmnd *scmd; | |
4225 | u16 smid; | |
4226 | u16 count = 0; | |
4227 | ||
4228 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
4229 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4230 | if (!scmd) | |
4231 | continue; | |
4232 | count++; | |
ffb58456 | 4233 | _scsih_set_satl_pending(scmd, false); |
f92363d1 SR |
4234 | mpt3sas_base_free_smid(ioc, smid); |
4235 | scsi_dma_unmap(scmd); | |
4236 | if (ioc->pci_error_recovery) | |
4237 | scmd->result = DID_NO_CONNECT << 16; | |
4238 | else | |
4239 | scmd->result = DID_RESET << 16; | |
4240 | scmd->scsi_done(scmd); | |
4241 | } | |
4242 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
4243 | ioc->name, count)); | |
4244 | } | |
4245 | ||
4246 | /** | |
4247 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
4248 | * @ioc: per adapter object | |
4249 | * @scmd: pointer to scsi command object | |
6c7abffc | 4250 | * @mpi_request: pointer to the SCSI_IO request message frame |
f92363d1 SR |
4251 | * |
4252 | * Supporting protection 1 and 3. | |
4253 | * | |
4254 | * Returns nothing | |
4255 | */ | |
4256 | static void | |
4257 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
016d5c35 | 4258 | Mpi25SCSIIORequest_t *mpi_request) |
f92363d1 SR |
4259 | { |
4260 | u16 eedp_flags; | |
4261 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
4262 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
4263 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
4264 | (Mpi25SCSIIORequest_t *)mpi_request; | |
4265 | ||
4266 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
4267 | return; | |
4268 | ||
4269 | if (prot_op == SCSI_PROT_READ_STRIP) | |
4270 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
4271 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
4272 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
4273 | else | |
4274 | return; | |
4275 | ||
4276 | switch (prot_type) { | |
4277 | case SCSI_PROT_DIF_TYPE1: | |
4278 | case SCSI_PROT_DIF_TYPE2: | |
4279 | ||
4280 | /* | |
4281 | * enable ref/guard checking | |
4282 | * auto increment ref tag | |
4283 | */ | |
4284 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
4285 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
4286 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4287 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
648512cc | 4288 | cpu_to_be32(scsi_prot_ref_tag(scmd)); |
f92363d1 SR |
4289 | break; |
4290 | ||
4291 | case SCSI_PROT_DIF_TYPE3: | |
4292 | ||
4293 | /* | |
4294 | * enable guard checking | |
4295 | */ | |
4296 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
4297 | ||
4298 | break; | |
4299 | } | |
4300 | ||
4301 | mpi_request_3v->EEDPBlockSize = | |
4302 | cpu_to_le16(scmd->device->sector_size); | |
186a18e5 SPS |
4303 | |
4304 | if (ioc->is_gen35_ioc) | |
4305 | eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE; | |
f92363d1 SR |
4306 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
4307 | } | |
4308 | ||
4309 | /** | |
4310 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
4311 | * @scmd: pointer to scsi command object | |
4312 | * @ioc_status: ioc status | |
4313 | * | |
4314 | * Returns nothing | |
4315 | */ | |
4316 | static void | |
4317 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
4318 | { | |
4319 | u8 ascq; | |
4320 | ||
4321 | switch (ioc_status) { | |
4322 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4323 | ascq = 0x01; | |
4324 | break; | |
4325 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4326 | ascq = 0x02; | |
4327 | break; | |
4328 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4329 | ascq = 0x03; | |
4330 | break; | |
4331 | default: | |
4332 | ascq = 0x00; | |
4333 | break; | |
4334 | } | |
4335 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
4336 | ascq); | |
4337 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
4338 | SAM_STAT_CHECK_CONDITION; | |
4339 | } | |
4340 | ||
f92363d1 | 4341 | /** |
8a7e4c24 | 4342 | * scsih_qcmd - main scsi request entry point |
f92363d1 SR |
4343 | * @scmd: pointer to scsi command object |
4344 | * @done: function pointer to be invoked on completion | |
4345 | * | |
4346 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
4347 | * | |
4348 | * Returns 0 on success. If there's a failure, return either: | |
4349 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
4350 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
4351 | */ | |
8bbb1cf6 | 4352 | static int |
8a7e4c24 | 4353 | scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 4354 | { |
d8bfbd8d | 4355 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
4356 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
4357 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7786ab6a | 4358 | struct _raid_device *raid_device; |
307d9075 AM |
4359 | struct request *rq = scmd->request; |
4360 | int class; | |
016d5c35 SPS |
4361 | Mpi25SCSIIORequest_t *mpi_request; |
4362 | struct _pcie_device *pcie_device = NULL; | |
f92363d1 SR |
4363 | u32 mpi_control; |
4364 | u16 smid; | |
4365 | u16 handle; | |
4366 | ||
f92363d1 SR |
4367 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
4368 | scsi_print_command(scmd); | |
f92363d1 | 4369 | |
f92363d1 SR |
4370 | sas_device_priv_data = scmd->device->hostdata; |
4371 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
4372 | scmd->result = DID_NO_CONNECT << 16; | |
4373 | scmd->scsi_done(scmd); | |
4374 | return 0; | |
4375 | } | |
4376 | ||
4377 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
4378 | scmd->result = DID_NO_CONNECT << 16; | |
4379 | scmd->scsi_done(scmd); | |
4380 | return 0; | |
4381 | } | |
4382 | ||
ffb58456 JB |
4383 | /* |
4384 | * Bug work around for firmware SATL handling. The loop | |
4385 | * is based on atomic operations and ensures consistency | |
4386 | * since we're lockless at this point | |
4387 | */ | |
4388 | do { | |
4389 | if (test_bit(0, &sas_device_priv_data->ata_command_pending)) { | |
4390 | scmd->result = SAM_STAT_BUSY; | |
4391 | scmd->scsi_done(scmd); | |
4392 | return 0; | |
4393 | } | |
4394 | } while (_scsih_set_satl_pending(scmd, true)); | |
4395 | ||
f92363d1 SR |
4396 | sas_target_priv_data = sas_device_priv_data->sas_target; |
4397 | ||
4398 | /* invalid device handle */ | |
4399 | handle = sas_target_priv_data->handle; | |
4400 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
4401 | scmd->result = DID_NO_CONNECT << 16; | |
4402 | scmd->scsi_done(scmd); | |
4403 | return 0; | |
4404 | } | |
4405 | ||
4406 | ||
4407 | /* host recovery or link resets sent via IOCTLs */ | |
4408 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | |
4409 | return SCSI_MLQUEUE_HOST_BUSY; | |
4410 | ||
4411 | /* device has been deleted */ | |
4412 | else if (sas_target_priv_data->deleted) { | |
4413 | scmd->result = DID_NO_CONNECT << 16; | |
4414 | scmd->scsi_done(scmd); | |
4415 | return 0; | |
6c7abffc | 4416 | /* device busy with task management */ |
f92363d1 SR |
4417 | } else if (sas_target_priv_data->tm_busy || |
4418 | sas_device_priv_data->block) | |
4419 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
4420 | ||
4421 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) | |
4422 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
4423 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
4424 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
4425 | else | |
4426 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
4427 | ||
4428 | /* set tags */ | |
609aa22f | 4429 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
307d9075 AM |
4430 | /* NCQ Prio supported, make sure control indicated high priority */ |
4431 | if (sas_device_priv_data->ncq_prio_enable) { | |
4432 | class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); | |
4433 | if (class == IOPRIO_CLASS_RT) | |
4434 | mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT; | |
4435 | } | |
7786ab6a SR |
4436 | /* Make sure Device is not raid volume. |
4437 | * We do not expose raid functionality to upper layer for warpdrive. | |
4438 | */ | |
4439 | if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev) | |
15de0de2 | 4440 | && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
f92363d1 SR |
4441 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
4442 | ||
4443 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
4444 | if (!smid) { | |
4445 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
4446 | ioc->name, __func__); | |
4447 | goto out; | |
4448 | } | |
4449 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
016d5c35 | 4450 | memset(mpi_request, 0, ioc->request_sz); |
f92363d1 SR |
4451 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
4452 | ||
4453 | if (scmd->cmd_len == 32) | |
4454 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
4455 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4456 | if (sas_device_priv_data->sas_target->flags & | |
4457 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
4458 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
4459 | else | |
4460 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
4461 | mpi_request->DevHandle = cpu_to_le16(handle); | |
4462 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
4463 | mpi_request->Control = cpu_to_le32(mpi_control); | |
4464 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
4465 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
4466 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
4467 | mpi_request->SenseBufferLowAddress = | |
4468 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
016d5c35 | 4469 | mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4; |
f92363d1 SR |
4470 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
4471 | mpi_request->LUN); | |
4472 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
4473 | ||
4474 | if (mpi_request->DataLength) { | |
016d5c35 SPS |
4475 | pcie_device = sas_target_priv_data->pcie_dev; |
4476 | if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) { | |
f92363d1 SR |
4477 | mpt3sas_base_free_smid(ioc, smid); |
4478 | goto out; | |
4479 | } | |
4480 | } else | |
4481 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
4482 | ||
7786ab6a SR |
4483 | raid_device = sas_target_priv_data->raid_device; |
4484 | if (raid_device && raid_device->direct_io_enabled) | |
c84b06a4 | 4485 | mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
7786ab6a | 4486 | smid); |
7786ab6a | 4487 | |
f92363d1 SR |
4488 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
4489 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
4490 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
4491 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
81c16f83 | 4492 | ioc->put_smid_fast_path(ioc, smid, handle); |
f92363d1 | 4493 | } else |
81c16f83 | 4494 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a | 4495 | le16_to_cpu(mpi_request->DevHandle)); |
f92363d1 | 4496 | } else |
81c16f83 | 4497 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
4498 | return 0; |
4499 | ||
4500 | out: | |
4501 | return SCSI_MLQUEUE_HOST_BUSY; | |
4502 | } | |
f92363d1 SR |
4503 | |
4504 | /** | |
4505 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
4506 | * @sense_buffer: sense data returned by target | |
4507 | * @data: normalized skey/asc/ascq | |
4508 | * | |
4509 | * Return nothing. | |
4510 | */ | |
4511 | static void | |
4512 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
4513 | { | |
4514 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
4515 | /* descriptor format */ | |
4516 | data->skey = sense_buffer[1] & 0x0F; | |
4517 | data->asc = sense_buffer[2]; | |
4518 | data->ascq = sense_buffer[3]; | |
4519 | } else { | |
4520 | /* fixed format */ | |
4521 | data->skey = sense_buffer[2] & 0x0F; | |
4522 | data->asc = sense_buffer[12]; | |
4523 | data->ascq = sense_buffer[13]; | |
4524 | } | |
4525 | } | |
4526 | ||
f92363d1 SR |
4527 | /** |
4528 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
4529 | * @ioc: per adapter object | |
4530 | * @scmd: pointer to scsi command object | |
4531 | * @mpi_reply: reply mf payload returned from firmware | |
4532 | * | |
4533 | * scsi_status - SCSI Status code returned from target device | |
4534 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
4535 | * ioc_status - ioc supplied status info | |
4536 | * | |
4537 | * Return nothing. | |
4538 | */ | |
4539 | static void | |
4540 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
4541 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
4542 | { | |
4543 | u32 response_info; | |
4544 | u8 *response_bytes; | |
4545 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
4546 | MPI2_IOCSTATUS_MASK; | |
4547 | u8 scsi_state = mpi_reply->SCSIState; | |
4548 | u8 scsi_status = mpi_reply->SCSIStatus; | |
4549 | char *desc_ioc_state = NULL; | |
4550 | char *desc_scsi_status = NULL; | |
4551 | char *desc_scsi_state = ioc->tmp_string; | |
4552 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4553 | struct _sas_device *sas_device = NULL; | |
f92363d1 SR |
4554 | struct scsi_target *starget = scmd->device->sdev_target; |
4555 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
4556 | char *device_str = NULL; | |
4557 | ||
4558 | if (!priv_target) | |
4559 | return; | |
7786ab6a SR |
4560 | if (ioc->hide_ir_msg) |
4561 | device_str = "WarpDrive"; | |
4562 | else | |
4563 | device_str = "volume"; | |
f92363d1 SR |
4564 | |
4565 | if (log_info == 0x31170000) | |
4566 | return; | |
4567 | ||
4568 | switch (ioc_status) { | |
4569 | case MPI2_IOCSTATUS_SUCCESS: | |
4570 | desc_ioc_state = "success"; | |
4571 | break; | |
4572 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4573 | desc_ioc_state = "invalid function"; | |
4574 | break; | |
4575 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4576 | desc_ioc_state = "scsi recovered error"; | |
4577 | break; | |
4578 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
4579 | desc_ioc_state = "scsi invalid dev handle"; | |
4580 | break; | |
4581 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4582 | desc_ioc_state = "scsi device not there"; | |
4583 | break; | |
4584 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4585 | desc_ioc_state = "scsi data overrun"; | |
4586 | break; | |
4587 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4588 | desc_ioc_state = "scsi data underrun"; | |
4589 | break; | |
4590 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4591 | desc_ioc_state = "scsi io data error"; | |
4592 | break; | |
4593 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4594 | desc_ioc_state = "scsi protocol error"; | |
4595 | break; | |
4596 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4597 | desc_ioc_state = "scsi task terminated"; | |
4598 | break; | |
4599 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4600 | desc_ioc_state = "scsi residual mismatch"; | |
4601 | break; | |
4602 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4603 | desc_ioc_state = "scsi task mgmt failed"; | |
4604 | break; | |
4605 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4606 | desc_ioc_state = "scsi ioc terminated"; | |
4607 | break; | |
4608 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4609 | desc_ioc_state = "scsi ext terminated"; | |
4610 | break; | |
4611 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4612 | desc_ioc_state = "eedp guard error"; | |
4613 | break; | |
4614 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4615 | desc_ioc_state = "eedp ref tag error"; | |
4616 | break; | |
4617 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4618 | desc_ioc_state = "eedp app tag error"; | |
4619 | break; | |
b130b0d5 SS |
4620 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
4621 | desc_ioc_state = "insufficient power"; | |
4622 | break; | |
f92363d1 SR |
4623 | default: |
4624 | desc_ioc_state = "unknown"; | |
4625 | break; | |
4626 | } | |
4627 | ||
4628 | switch (scsi_status) { | |
4629 | case MPI2_SCSI_STATUS_GOOD: | |
4630 | desc_scsi_status = "good"; | |
4631 | break; | |
4632 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
4633 | desc_scsi_status = "check condition"; | |
4634 | break; | |
4635 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
4636 | desc_scsi_status = "condition met"; | |
4637 | break; | |
4638 | case MPI2_SCSI_STATUS_BUSY: | |
4639 | desc_scsi_status = "busy"; | |
4640 | break; | |
4641 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
4642 | desc_scsi_status = "intermediate"; | |
4643 | break; | |
4644 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
4645 | desc_scsi_status = "intermediate condmet"; | |
4646 | break; | |
4647 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
4648 | desc_scsi_status = "reservation conflict"; | |
4649 | break; | |
4650 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
4651 | desc_scsi_status = "command terminated"; | |
4652 | break; | |
4653 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
4654 | desc_scsi_status = "task set full"; | |
4655 | break; | |
4656 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
4657 | desc_scsi_status = "aca active"; | |
4658 | break; | |
4659 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
4660 | desc_scsi_status = "task aborted"; | |
4661 | break; | |
4662 | default: | |
4663 | desc_scsi_status = "unknown"; | |
4664 | break; | |
4665 | } | |
4666 | ||
4667 | desc_scsi_state[0] = '\0'; | |
4668 | if (!scsi_state) | |
4669 | desc_scsi_state = " "; | |
4670 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4671 | strcat(desc_scsi_state, "response info "); | |
4672 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4673 | strcat(desc_scsi_state, "state terminated "); | |
4674 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
4675 | strcat(desc_scsi_state, "no status "); | |
4676 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
4677 | strcat(desc_scsi_state, "autosense failed "); | |
4678 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
4679 | strcat(desc_scsi_state, "autosense valid "); | |
4680 | ||
4681 | scsi_print_command(scmd); | |
4682 | ||
4683 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
4684 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
4685 | device_str, (unsigned long long)priv_target->sas_address); | |
4686 | } else { | |
d1cb5e49 | 4687 | sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target); |
f92363d1 SR |
4688 | if (sas_device) { |
4689 | pr_warn(MPT3SAS_FMT | |
4690 | "\tsas_address(0x%016llx), phy(%d)\n", | |
4691 | ioc->name, (unsigned long long) | |
4692 | sas_device->sas_address, sas_device->phy); | |
75888956 SR |
4693 | |
4694 | _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
4695 | NULL, NULL); | |
d1cb5e49 SR |
4696 | |
4697 | sas_device_put(sas_device); | |
f92363d1 | 4698 | } |
f92363d1 SR |
4699 | } |
4700 | ||
4701 | pr_warn(MPT3SAS_FMT | |
4702 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
4703 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
4704 | desc_ioc_state, ioc_status, smid); | |
4705 | pr_warn(MPT3SAS_FMT | |
4706 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
4707 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
4708 | scsi_get_resid(scmd)); | |
4709 | pr_warn(MPT3SAS_FMT | |
4710 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
4711 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
4712 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
4713 | pr_warn(MPT3SAS_FMT | |
4714 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
4715 | ioc->name, desc_scsi_status, | |
4716 | scsi_status, desc_scsi_state, scsi_state); | |
4717 | ||
4718 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
4719 | struct sense_info data; | |
4720 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
4721 | pr_warn(MPT3SAS_FMT | |
4722 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", | |
4723 | ioc->name, data.skey, | |
4724 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
4725 | } | |
4726 | ||
4727 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { | |
4728 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
4729 | response_bytes = (u8 *)&response_info; | |
4730 | _scsih_response_code(ioc, response_bytes[0]); | |
4731 | } | |
4732 | } | |
f92363d1 SR |
4733 | |
4734 | /** | |
0f624c39 | 4735 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
f92363d1 SR |
4736 | * @ioc: per adapter object |
4737 | * @handle: device handle | |
4738 | * Context: process | |
4739 | * | |
4740 | * Return nothing. | |
4741 | */ | |
4742 | static void | |
0f624c39 | 4743 | _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
4744 | { |
4745 | Mpi2SepReply_t mpi_reply; | |
4746 | Mpi2SepRequest_t mpi_request; | |
0f624c39 SR |
4747 | struct _sas_device *sas_device; |
4748 | ||
d1cb5e49 | 4749 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
0f624c39 SR |
4750 | if (!sas_device) |
4751 | return; | |
f92363d1 SR |
4752 | |
4753 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
4754 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
4755 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
4756 | mpi_request.SlotStatus = | |
4757 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
4758 | mpi_request.DevHandle = cpu_to_le16(handle); | |
4759 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
4760 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
4761 | &mpi_request)) != 0) { | |
4762 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
4763 | __FILE__, __LINE__, __func__); | |
d1cb5e49 | 4764 | goto out; |
f92363d1 | 4765 | } |
0f624c39 | 4766 | sas_device->pfa_led_on = 1; |
f92363d1 SR |
4767 | |
4768 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
4769 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4770 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
4771 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
4772 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
d1cb5e49 | 4773 | goto out; |
f92363d1 | 4774 | } |
d1cb5e49 SR |
4775 | out: |
4776 | sas_device_put(sas_device); | |
f92363d1 | 4777 | } |
d1cb5e49 | 4778 | |
0f624c39 SR |
4779 | /** |
4780 | * _scsih_turn_off_pfa_led - turn off Fault LED | |
4781 | * @ioc: per adapter object | |
4782 | * @sas_device: sas device whose PFA LED has to turned off | |
4783 | * Context: process | |
4784 | * | |
4785 | * Return nothing. | |
4786 | */ | |
4787 | static void | |
4788 | _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc, | |
4789 | struct _sas_device *sas_device) | |
4790 | { | |
4791 | Mpi2SepReply_t mpi_reply; | |
4792 | Mpi2SepRequest_t mpi_request; | |
f92363d1 | 4793 | |
0f624c39 SR |
4794 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
4795 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
4796 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
4797 | mpi_request.SlotStatus = 0; | |
4798 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | |
4799 | mpi_request.DevHandle = 0; | |
4800 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | |
4801 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | |
4802 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
4803 | &mpi_request)) != 0) { | |
4804 | printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
4805 | __FILE__, __LINE__, __func__); | |
4806 | return; | |
4807 | } | |
4808 | ||
4809 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
4810 | dewtprintk(ioc, printk(MPT3SAS_FMT | |
4811 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
4812 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
4813 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
4814 | return; | |
4815 | } | |
4816 | } | |
d1cb5e49 | 4817 | |
f92363d1 | 4818 | /** |
0f624c39 | 4819 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
f92363d1 SR |
4820 | * @ioc: per adapter object |
4821 | * @handle: device handle | |
4822 | * Context: interrupt. | |
4823 | * | |
4824 | * Return nothing. | |
4825 | */ | |
4826 | static void | |
0f624c39 | 4827 | _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
f92363d1 SR |
4828 | { |
4829 | struct fw_event_work *fw_event; | |
4830 | ||
146b16c8 | 4831 | fw_event = alloc_fw_event_work(0); |
f92363d1 SR |
4832 | if (!fw_event) |
4833 | return; | |
0f624c39 | 4834 | fw_event->event = MPT3SAS_TURN_ON_PFA_LED; |
f92363d1 SR |
4835 | fw_event->device_handle = handle; |
4836 | fw_event->ioc = ioc; | |
4837 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 4838 | fw_event_work_put(fw_event); |
f92363d1 SR |
4839 | } |
4840 | ||
4841 | /** | |
4842 | * _scsih_smart_predicted_fault - process smart errors | |
4843 | * @ioc: per adapter object | |
4844 | * @handle: device handle | |
4845 | * Context: interrupt. | |
4846 | * | |
4847 | * Return nothing. | |
4848 | */ | |
4849 | static void | |
4850 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4851 | { | |
4852 | struct scsi_target *starget; | |
4853 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4854 | Mpi2EventNotificationReply_t *event_reply; | |
4855 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
4856 | struct _sas_device *sas_device; | |
4857 | ssize_t sz; | |
4858 | unsigned long flags; | |
4859 | ||
4860 | /* only handle non-raid devices */ | |
4861 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 SR |
4862 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
4863 | if (!sas_device) | |
4864 | goto out_unlock; | |
4865 | ||
f92363d1 SR |
4866 | starget = sas_device->starget; |
4867 | sas_target_priv_data = starget->hostdata; | |
4868 | ||
4869 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
d1cb5e49 SR |
4870 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) |
4871 | goto out_unlock; | |
4872 | ||
75888956 SR |
4873 | _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget); |
4874 | ||
f92363d1 SR |
4875 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
4876 | ||
4877 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
0f624c39 | 4878 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
f92363d1 SR |
4879 | |
4880 | /* insert into event log */ | |
4881 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
4882 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
4883 | event_reply = kzalloc(sz, GFP_KERNEL); | |
4884 | if (!event_reply) { | |
4885 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4886 | ioc->name, __FILE__, __LINE__, __func__); | |
d1cb5e49 | 4887 | goto out; |
f92363d1 SR |
4888 | } |
4889 | ||
4890 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
4891 | event_reply->Event = | |
4892 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
4893 | event_reply->MsgLength = sz/4; | |
4894 | event_reply->EventDataLength = | |
4895 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
4896 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
4897 | event_reply->EventData; | |
4898 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
4899 | event_data->ASC = 0x5D; | |
4900 | event_data->DevHandle = cpu_to_le16(handle); | |
4901 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
4902 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
4903 | kfree(event_reply); | |
d1cb5e49 SR |
4904 | out: |
4905 | if (sas_device) | |
4906 | sas_device_put(sas_device); | |
4907 | return; | |
4908 | ||
4909 | out_unlock: | |
4910 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4911 | goto out; | |
f92363d1 SR |
4912 | } |
4913 | ||
4914 | /** | |
4915 | * _scsih_io_done - scsi request callback | |
4916 | * @ioc: per adapter object | |
4917 | * @smid: system request message index | |
4918 | * @msix_index: MSIX table index supplied by the OS | |
4919 | * @reply: reply message frame(lower 32bit addr) | |
4920 | * | |
4921 | * Callback handler when using _scsih_qcmd. | |
4922 | * | |
4923 | * Return 1 meaning mf should be freed from _base_interrupt | |
4924 | * 0 means the mf is freed from this function. | |
4925 | */ | |
4926 | static u8 | |
4927 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
4928 | { | |
016d5c35 | 4929 | Mpi25SCSIIORequest_t *mpi_request; |
f92363d1 SR |
4930 | Mpi2SCSIIOReply_t *mpi_reply; |
4931 | struct scsi_cmnd *scmd; | |
4932 | u16 ioc_status; | |
4933 | u32 xfer_cnt; | |
4934 | u8 scsi_state; | |
4935 | u8 scsi_status; | |
4936 | u32 log_info; | |
4937 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
4938 | u32 response_code = 0; | |
7786ab6a | 4939 | unsigned long flags; |
f92363d1 SR |
4940 | |
4941 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
459325c4 C |
4942 | |
4943 | if (ioc->broadcast_aen_busy || ioc->pci_error_recovery || | |
4944 | ioc->got_task_abort_from_ioctl) | |
4945 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4946 | else | |
4947 | scmd = __scsih_scsi_lookup_get_clear(ioc, smid); | |
4948 | ||
f92363d1 SR |
4949 | if (scmd == NULL) |
4950 | return 1; | |
4951 | ||
ffb58456 | 4952 | _scsih_set_satl_pending(scmd, false); |
18f6084a | 4953 | |
f92363d1 SR |
4954 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
4955 | ||
4956 | if (mpi_reply == NULL) { | |
4957 | scmd->result = DID_OK << 16; | |
4958 | goto out; | |
4959 | } | |
4960 | ||
4961 | sas_device_priv_data = scmd->device->hostdata; | |
4962 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
4963 | sas_device_priv_data->sas_target->deleted) { | |
4964 | scmd->result = DID_NO_CONNECT << 16; | |
4965 | goto out; | |
4966 | } | |
4967 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
4968 | ||
7786ab6a SR |
4969 | /* |
4970 | * WARPDRIVE: If direct_io is set then it is directIO, | |
4971 | * the failed direct I/O should be redirected to volume | |
4972 | */ | |
c84b06a4 | 4973 | if (mpt3sas_scsi_direct_io_get(ioc, smid) && |
7786ab6a SR |
4974 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
4975 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | |
4976 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
4977 | ioc->scsi_lookup[smid - 1].scmd = scmd; | |
4978 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
c84b06a4 | 4979 | mpt3sas_scsi_direct_io_set(ioc, smid, 0); |
7786ab6a SR |
4980 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
4981 | mpi_request->DevHandle = | |
4982 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | |
81c16f83 | 4983 | ioc->put_smid_scsi_io(ioc, smid, |
7786ab6a SR |
4984 | sas_device_priv_data->sas_target->handle); |
4985 | return 0; | |
4986 | } | |
f92363d1 SR |
4987 | /* turning off TLR */ |
4988 | scsi_state = mpi_reply->SCSIState; | |
4989 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4990 | response_code = | |
4991 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
4992 | if (!sas_device_priv_data->tlr_snoop_check) { | |
4993 | sas_device_priv_data->tlr_snoop_check++; | |
7786ab6a SR |
4994 | if (!ioc->is_warpdrive && |
4995 | !scsih_is_raid(&scmd->device->sdev_gendev) && | |
c84b06a4 SR |
4996 | sas_is_tlr_enabled(scmd->device) && |
4997 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { | |
4998 | sas_disable_tlr(scmd->device); | |
4999 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | |
5000 | } | |
f92363d1 SR |
5001 | } |
5002 | ||
5003 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
5004 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
5005 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5006 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5007 | else | |
5008 | log_info = 0; | |
5009 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5010 | scsi_status = mpi_reply->SCSIStatus; | |
5011 | ||
5012 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
5013 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
5014 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
5015 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
5016 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
5017 | } | |
5018 | ||
5019 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
5020 | struct sense_info data; | |
5021 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
5022 | smid); | |
5023 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
5024 | le32_to_cpu(mpi_reply->SenseCount)); | |
5025 | memcpy(scmd->sense_buffer, sense_data, sz); | |
5026 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
5027 | /* failure prediction threshold exceeded */ | |
5028 | if (data.asc == 0x5D) | |
5029 | _scsih_smart_predicted_fault(ioc, | |
5030 | le16_to_cpu(mpi_reply->DevHandle)); | |
5031 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
f92363d1 | 5032 | |
0d667f72 | 5033 | if ((ioc->logging_level & MPT_DEBUG_REPLY) && |
e6d45e3e SR |
5034 | ((scmd->sense_buffer[2] == UNIT_ATTENTION) || |
5035 | (scmd->sense_buffer[2] == MEDIUM_ERROR) || | |
5036 | (scmd->sense_buffer[2] == HARDWARE_ERROR))) | |
5037 | _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid); | |
e6d45e3e | 5038 | } |
f92363d1 SR |
5039 | switch (ioc_status) { |
5040 | case MPI2_IOCSTATUS_BUSY: | |
5041 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
5042 | scmd->result = SAM_STAT_BUSY; | |
5043 | break; | |
5044 | ||
5045 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
5046 | scmd->result = DID_NO_CONNECT << 16; | |
5047 | break; | |
5048 | ||
5049 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
5050 | if (sas_device_priv_data->block) { | |
5051 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
5052 | goto out; | |
5053 | } | |
5054 | if (log_info == 0x31110630) { | |
5055 | if (scmd->retries > 2) { | |
5056 | scmd->result = DID_NO_CONNECT << 16; | |
5057 | scsi_device_set_state(scmd->device, | |
5058 | SDEV_OFFLINE); | |
5059 | } else { | |
5060 | scmd->result = DID_SOFT_ERROR << 16; | |
5061 | scmd->device->expecting_cc_ua = 1; | |
5062 | } | |
5063 | break; | |
3898f08e SR |
5064 | } else if (log_info == VIRTUAL_IO_FAILED_RETRY) { |
5065 | scmd->result = DID_RESET << 16; | |
5066 | break; | |
2ce9a364 SR |
5067 | } else if ((scmd->device->channel == RAID_CHANNEL) && |
5068 | (scsi_state == (MPI2_SCSI_STATE_TERMINATED | | |
5069 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) { | |
5070 | scmd->result = DID_RESET << 16; | |
5071 | break; | |
f92363d1 SR |
5072 | } |
5073 | scmd->result = DID_SOFT_ERROR << 16; | |
5074 | break; | |
5075 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
5076 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
5077 | scmd->result = DID_RESET << 16; | |
5078 | break; | |
5079 | ||
5080 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
5081 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
5082 | scmd->result = DID_SOFT_ERROR << 16; | |
5083 | else | |
5084 | scmd->result = (DID_OK << 16) | scsi_status; | |
5085 | break; | |
5086 | ||
5087 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
5088 | scmd->result = (DID_OK << 16) | scsi_status; | |
5089 | ||
5090 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
5091 | break; | |
5092 | ||
5093 | if (xfer_cnt < scmd->underflow) { | |
5094 | if (scsi_status == SAM_STAT_BUSY) | |
5095 | scmd->result = SAM_STAT_BUSY; | |
5096 | else | |
5097 | scmd->result = DID_SOFT_ERROR << 16; | |
5098 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5099 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
5100 | scmd->result = DID_SOFT_ERROR << 16; | |
5101 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5102 | scmd->result = DID_RESET << 16; | |
5103 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
5104 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
5105 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
5106 | scmd->result = (DRIVER_SENSE << 24) | | |
5107 | SAM_STAT_CHECK_CONDITION; | |
5108 | scmd->sense_buffer[0] = 0x70; | |
5109 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
5110 | scmd->sense_buffer[12] = 0x20; | |
5111 | scmd->sense_buffer[13] = 0; | |
5112 | } | |
5113 | break; | |
5114 | ||
5115 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
5116 | scsi_set_resid(scmd, 0); | |
5117 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
5118 | case MPI2_IOCSTATUS_SUCCESS: | |
5119 | scmd->result = (DID_OK << 16) | scsi_status; | |
5120 | if (response_code == | |
5121 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
5122 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
5123 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
5124 | scmd->result = DID_SOFT_ERROR << 16; | |
5125 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
5126 | scmd->result = DID_RESET << 16; | |
5127 | break; | |
5128 | ||
5129 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
5130 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
5131 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
5132 | _scsih_eedp_error_handling(scmd, ioc_status); | |
5133 | break; | |
5134 | ||
5135 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
5136 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
5137 | case MPI2_IOCSTATUS_INVALID_SGL: | |
5138 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
5139 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
5140 | case MPI2_IOCSTATUS_INVALID_STATE: | |
5141 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
5142 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
b130b0d5 | 5143 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
f92363d1 SR |
5144 | default: |
5145 | scmd->result = DID_SOFT_ERROR << 16; | |
5146 | break; | |
5147 | ||
5148 | } | |
5149 | ||
f92363d1 SR |
5150 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
5151 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
f92363d1 SR |
5152 | |
5153 | out: | |
5154 | ||
5155 | scsi_dma_unmap(scmd); | |
5156 | ||
5157 | scmd->scsi_done(scmd); | |
5158 | return 1; | |
5159 | } | |
5160 | ||
5161 | /** | |
5162 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
5163 | * @ioc: per adapter object | |
5164 | * Context: user | |
5165 | * | |
5166 | * During port enable, fw will send topology events for every device. Its | |
5167 | * possible that the handles may change from the previous setting, so this | |
5168 | * code keeping handles updating if changed. | |
5169 | * | |
5170 | * Return nothing. | |
5171 | */ | |
5172 | static void | |
5173 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
5174 | { | |
5175 | u16 sz; | |
5176 | u16 ioc_status; | |
5177 | int i; | |
5178 | Mpi2ConfigReply_t mpi_reply; | |
5179 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5180 | u16 attached_handle; | |
5181 | u8 link_rate; | |
5182 | ||
5183 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
5184 | "updating handles for sas_host(0x%016llx)\n", | |
5185 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
5186 | ||
5187 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
5188 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5189 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5190 | if (!sas_iounit_pg0) { | |
5191 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5192 | ioc->name, __FILE__, __LINE__, __func__); | |
5193 | return; | |
5194 | } | |
5195 | ||
5196 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5197 | sas_iounit_pg0, sz)) != 0) | |
5198 | goto out; | |
5199 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5200 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5201 | goto out; | |
5202 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
5203 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
5204 | if (i == 0) | |
5205 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5206 | PhyData[0].ControllerDevHandle); | |
5207 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5208 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
5209 | AttachedDevHandle); | |
5210 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5211 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
5212 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
5213 | attached_handle, i, link_rate); | |
5214 | } | |
5215 | out: | |
5216 | kfree(sas_iounit_pg0); | |
5217 | } | |
5218 | ||
5219 | /** | |
5220 | * _scsih_sas_host_add - create sas host object | |
5221 | * @ioc: per adapter object | |
5222 | * | |
5223 | * Creating host side data object, stored in ioc->sas_hba | |
5224 | * | |
5225 | * Return nothing. | |
5226 | */ | |
5227 | static void | |
5228 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
5229 | { | |
5230 | int i; | |
5231 | Mpi2ConfigReply_t mpi_reply; | |
5232 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
5233 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
5234 | Mpi2SasPhyPage0_t phy_pg0; | |
5235 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5236 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5237 | u16 ioc_status; | |
5238 | u16 sz; | |
5239 | u8 device_missing_delay; | |
87aa95d4 | 5240 | u8 num_phys; |
f92363d1 | 5241 | |
87aa95d4 JL |
5242 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
5243 | if (!num_phys) { | |
f92363d1 SR |
5244 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
5245 | ioc->name, __FILE__, __LINE__, __func__); | |
5246 | return; | |
5247 | } | |
87aa95d4 JL |
5248 | ioc->sas_hba.phy = kcalloc(num_phys, |
5249 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5250 | if (!ioc->sas_hba.phy) { | |
5251 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5252 | ioc->name, __FILE__, __LINE__, __func__); | |
5253 | goto out; | |
5254 | } | |
5255 | ioc->sas_hba.num_phys = num_phys; | |
f92363d1 SR |
5256 | |
5257 | /* sas_iounit page 0 */ | |
5258 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
5259 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
5260 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
5261 | if (!sas_iounit_pg0) { | |
5262 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5263 | ioc->name, __FILE__, __LINE__, __func__); | |
5264 | return; | |
5265 | } | |
5266 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
5267 | sas_iounit_pg0, sz))) { | |
5268 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5269 | ioc->name, __FILE__, __LINE__, __func__); | |
5270 | goto out; | |
5271 | } | |
5272 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5273 | MPI2_IOCSTATUS_MASK; | |
5274 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5275 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5276 | ioc->name, __FILE__, __LINE__, __func__); | |
5277 | goto out; | |
5278 | } | |
5279 | ||
5280 | /* sas_iounit page 1 */ | |
5281 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
5282 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
5283 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
5284 | if (!sas_iounit_pg1) { | |
5285 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5286 | ioc->name, __FILE__, __LINE__, __func__); | |
5287 | goto out; | |
5288 | } | |
5289 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
5290 | sas_iounit_pg1, sz))) { | |
5291 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5292 | ioc->name, __FILE__, __LINE__, __func__); | |
5293 | goto out; | |
5294 | } | |
5295 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5296 | MPI2_IOCSTATUS_MASK; | |
5297 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5298 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5299 | ioc->name, __FILE__, __LINE__, __func__); | |
5300 | goto out; | |
5301 | } | |
5302 | ||
5303 | ioc->io_missing_delay = | |
5304 | sas_iounit_pg1->IODeviceMissingDelay; | |
5305 | device_missing_delay = | |
5306 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
5307 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
5308 | ioc->device_missing_delay = (device_missing_delay & | |
5309 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
5310 | else | |
5311 | ioc->device_missing_delay = device_missing_delay & | |
5312 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
5313 | ||
5314 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
f92363d1 SR |
5315 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
5316 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
5317 | i))) { | |
5318 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5319 | ioc->name, __FILE__, __LINE__, __func__); | |
5320 | goto out; | |
5321 | } | |
5322 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5323 | MPI2_IOCSTATUS_MASK; | |
5324 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5325 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5326 | ioc->name, __FILE__, __LINE__, __func__); | |
5327 | goto out; | |
5328 | } | |
5329 | ||
5330 | if (i == 0) | |
5331 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
5332 | PhyData[0].ControllerDevHandle); | |
5333 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
5334 | ioc->sas_hba.phy[i].phy_id = i; | |
5335 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
5336 | phy_pg0, ioc->sas_hba.parent_dev); | |
5337 | } | |
5338 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5339 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
5340 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5341 | ioc->name, __FILE__, __LINE__, __func__); | |
5342 | goto out; | |
5343 | } | |
5344 | ioc->sas_hba.enclosure_handle = | |
5345 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
5346 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
5347 | pr_info(MPT3SAS_FMT | |
5348 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
5349 | ioc->name, ioc->sas_hba.handle, | |
5350 | (unsigned long long) ioc->sas_hba.sas_address, | |
5351 | ioc->sas_hba.num_phys) ; | |
5352 | ||
5353 | if (ioc->sas_hba.enclosure_handle) { | |
5354 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5355 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5356 | ioc->sas_hba.enclosure_handle))) | |
5357 | ioc->sas_hba.enclosure_logical_id = | |
5358 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5359 | } | |
5360 | ||
5361 | out: | |
5362 | kfree(sas_iounit_pg1); | |
5363 | kfree(sas_iounit_pg0); | |
5364 | } | |
5365 | ||
5366 | /** | |
5367 | * _scsih_expander_add - creating expander object | |
5368 | * @ioc: per adapter object | |
5369 | * @handle: expander handle | |
5370 | * | |
5371 | * Creating expander object, stored in ioc->sas_expander_list. | |
5372 | * | |
5373 | * Return 0 for success, else error. | |
5374 | */ | |
5375 | static int | |
5376 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5377 | { | |
5378 | struct _sas_node *sas_expander; | |
5379 | Mpi2ConfigReply_t mpi_reply; | |
5380 | Mpi2ExpanderPage0_t expander_pg0; | |
5381 | Mpi2ExpanderPage1_t expander_pg1; | |
5382 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5383 | u32 ioc_status; | |
5384 | u16 parent_handle; | |
5385 | u64 sas_address, sas_address_parent = 0; | |
5386 | int i; | |
5387 | unsigned long flags; | |
5388 | struct _sas_port *mpt3sas_port = NULL; | |
5389 | ||
5390 | int rc = 0; | |
5391 | ||
5392 | if (!handle) | |
5393 | return -1; | |
5394 | ||
5395 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
5396 | return -1; | |
5397 | ||
5398 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
5399 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
5400 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5401 | ioc->name, __FILE__, __LINE__, __func__); | |
5402 | return -1; | |
5403 | } | |
5404 | ||
5405 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5406 | MPI2_IOCSTATUS_MASK; | |
5407 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5408 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5409 | ioc->name, __FILE__, __LINE__, __func__); | |
5410 | return -1; | |
5411 | } | |
5412 | ||
5413 | /* handle out of order topology events */ | |
5414 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
5415 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
5416 | != 0) { | |
5417 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5418 | ioc->name, __FILE__, __LINE__, __func__); | |
5419 | return -1; | |
5420 | } | |
5421 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
5422 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5423 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5424 | sas_address_parent); | |
5425 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5426 | if (!sas_expander) { | |
5427 | rc = _scsih_expander_add(ioc, parent_handle); | |
5428 | if (rc != 0) | |
5429 | return rc; | |
5430 | } | |
5431 | } | |
5432 | ||
5433 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5434 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
5435 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5436 | sas_address); | |
5437 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5438 | ||
5439 | if (sas_expander) | |
5440 | return 0; | |
5441 | ||
5442 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
5443 | GFP_KERNEL); | |
5444 | if (!sas_expander) { | |
5445 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5446 | ioc->name, __FILE__, __LINE__, __func__); | |
5447 | return -1; | |
5448 | } | |
5449 | ||
5450 | sas_expander->handle = handle; | |
5451 | sas_expander->num_phys = expander_pg0.NumPhys; | |
5452 | sas_expander->sas_address_parent = sas_address_parent; | |
5453 | sas_expander->sas_address = sas_address; | |
5454 | ||
5455 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
5456 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
5457 | handle, parent_handle, (unsigned long long) | |
5458 | sas_expander->sas_address, sas_expander->num_phys); | |
5459 | ||
5460 | if (!sas_expander->num_phys) | |
5461 | goto out_fail; | |
5462 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
5463 | sizeof(struct _sas_phy), GFP_KERNEL); | |
5464 | if (!sas_expander->phy) { | |
5465 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5466 | ioc->name, __FILE__, __LINE__, __func__); | |
5467 | rc = -1; | |
5468 | goto out_fail; | |
5469 | } | |
5470 | ||
5471 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
5472 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
5473 | sas_address_parent); | |
5474 | if (!mpt3sas_port) { | |
5475 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5476 | ioc->name, __FILE__, __LINE__, __func__); | |
5477 | rc = -1; | |
5478 | goto out_fail; | |
5479 | } | |
5480 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
5481 | ||
5482 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
5483 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
5484 | &expander_pg1, i, handle))) { | |
5485 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5486 | ioc->name, __FILE__, __LINE__, __func__); | |
5487 | rc = -1; | |
5488 | goto out_fail; | |
5489 | } | |
5490 | sas_expander->phy[i].handle = handle; | |
5491 | sas_expander->phy[i].phy_id = i; | |
5492 | ||
5493 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
5494 | &sas_expander->phy[i], expander_pg1, | |
5495 | sas_expander->parent_dev))) { | |
5496 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5497 | ioc->name, __FILE__, __LINE__, __func__); | |
5498 | rc = -1; | |
5499 | goto out_fail; | |
5500 | } | |
5501 | } | |
5502 | ||
5503 | if (sas_expander->enclosure_handle) { | |
5504 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5505 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5506 | sas_expander->enclosure_handle))) | |
5507 | sas_expander->enclosure_logical_id = | |
5508 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5509 | } | |
5510 | ||
5511 | _scsih_expander_node_add(ioc, sas_expander); | |
5512 | return 0; | |
5513 | ||
5514 | out_fail: | |
5515 | ||
5516 | if (mpt3sas_port) | |
5517 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
5518 | sas_address_parent); | |
5519 | kfree(sas_expander); | |
5520 | return rc; | |
5521 | } | |
5522 | ||
5523 | /** | |
5524 | * mpt3sas_expander_remove - removing expander object | |
5525 | * @ioc: per adapter object | |
5526 | * @sas_address: expander sas_address | |
5527 | * | |
5528 | * Return nothing. | |
5529 | */ | |
5530 | void | |
5531 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
5532 | { | |
5533 | struct _sas_node *sas_expander; | |
5534 | unsigned long flags; | |
5535 | ||
5536 | if (ioc->shost_recovery) | |
5537 | return; | |
5538 | ||
5539 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5540 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
5541 | sas_address); | |
f92363d1 SR |
5542 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
5543 | if (sas_expander) | |
5544 | _scsih_expander_node_remove(ioc, sas_expander); | |
5545 | } | |
5546 | ||
5547 | /** | |
5548 | * _scsih_done - internal SCSI_IO callback handler. | |
5549 | * @ioc: per adapter object | |
5550 | * @smid: system request message index | |
5551 | * @msix_index: MSIX table index supplied by the OS | |
5552 | * @reply: reply message frame(lower 32bit addr) | |
5553 | * | |
5554 | * Callback handler when sending internal generated SCSI_IO. | |
5555 | * The callback index passed is `ioc->scsih_cb_idx` | |
5556 | * | |
5557 | * Return 1 meaning mf should be freed from _base_interrupt | |
5558 | * 0 means the mf is freed from this function. | |
5559 | */ | |
5560 | static u8 | |
5561 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
5562 | { | |
5563 | MPI2DefaultReply_t *mpi_reply; | |
5564 | ||
5565 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
5566 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
5567 | return 1; | |
5568 | if (ioc->scsih_cmds.smid != smid) | |
5569 | return 1; | |
5570 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
5571 | if (mpi_reply) { | |
5572 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
5573 | mpi_reply->MsgLength*4); | |
5574 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
5575 | } | |
5576 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
5577 | complete(&ioc->scsih_cmds.done); | |
5578 | return 1; | |
5579 | } | |
5580 | ||
5581 | ||
5582 | ||
5583 | ||
5584 | #define MPT3_MAX_LUNS (255) | |
5585 | ||
5586 | ||
5587 | /** | |
5588 | * _scsih_check_access_status - check access flags | |
5589 | * @ioc: per adapter object | |
5590 | * @sas_address: sas address | |
5591 | * @handle: sas device handle | |
5592 | * @access_flags: errors returned during discovery of the device | |
5593 | * | |
5594 | * Return 0 for success, else failure | |
5595 | */ | |
5596 | static u8 | |
5597 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
5598 | u16 handle, u8 access_status) | |
5599 | { | |
5600 | u8 rc = 1; | |
5601 | char *desc = NULL; | |
5602 | ||
5603 | switch (access_status) { | |
5604 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
5605 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
5606 | rc = 0; | |
5607 | break; | |
5608 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
5609 | desc = "sata capability failed"; | |
5610 | break; | |
5611 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
5612 | desc = "sata affiliation conflict"; | |
5613 | break; | |
5614 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
5615 | desc = "route not addressable"; | |
5616 | break; | |
5617 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
5618 | desc = "smp error not addressable"; | |
5619 | break; | |
5620 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
5621 | desc = "device blocked"; | |
5622 | break; | |
5623 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
5624 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
5625 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
5626 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
5627 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
5628 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
5629 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
5630 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
5631 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
5632 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
5633 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
5634 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
5635 | desc = "sata initialization failed"; | |
5636 | break; | |
5637 | default: | |
5638 | desc = "unknown"; | |
5639 | break; | |
5640 | } | |
5641 | ||
5642 | if (!rc) | |
5643 | return 0; | |
5644 | ||
5645 | pr_err(MPT3SAS_FMT | |
5646 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
5647 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
5648 | return rc; | |
5649 | } | |
5650 | ||
aba5a85c SR |
5651 | /** |
5652 | * _scsih_get_enclosure_logicalid_chassis_slot - get device's | |
5653 | * EnclosureLogicalID and ChassisSlot information. | |
5654 | * @ioc: per adapter object | |
5655 | * @sas_device_pg0: SAS device page0 | |
5656 | * @sas_device: per sas device object | |
5657 | * | |
5658 | * Returns nothing. | |
5659 | */ | |
5660 | static void | |
5661 | _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER *ioc, | |
5662 | Mpi2SasDevicePage0_t *sas_device_pg0, struct _sas_device *sas_device) | |
5663 | { | |
5664 | Mpi2ConfigReply_t mpi_reply; | |
5665 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5666 | ||
5667 | if (!sas_device_pg0 || !sas_device) | |
5668 | return; | |
5669 | ||
5670 | sas_device->enclosure_handle = | |
5671 | le16_to_cpu(sas_device_pg0->EnclosureHandle); | |
5672 | sas_device->is_chassis_slot_valid = 0; | |
5673 | ||
5674 | if (!le16_to_cpu(sas_device_pg0->EnclosureHandle)) | |
5675 | return; | |
5676 | ||
5677 | if (mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5678 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5679 | le16_to_cpu(sas_device_pg0->EnclosureHandle))) { | |
5680 | pr_err(MPT3SAS_FMT | |
5681 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
5682 | ioc->name, le16_to_cpu(sas_device_pg0->EnclosureHandle)); | |
5683 | return; | |
5684 | } | |
5685 | ||
5686 | sas_device->enclosure_logical_id = | |
5687 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5688 | ||
5689 | if (le16_to_cpu(enclosure_pg0.Flags) & | |
5690 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
5691 | sas_device->is_chassis_slot_valid = 1; | |
5692 | sas_device->chassis_slot = enclosure_pg0.ChassisSlot; | |
5693 | } | |
5694 | } | |
5695 | ||
5696 | ||
f92363d1 SR |
5697 | /** |
5698 | * _scsih_check_device - checking device responsiveness | |
5699 | * @ioc: per adapter object | |
5700 | * @parent_sas_address: sas address of parent expander or sas host | |
5701 | * @handle: attached device handle | |
5702 | * @phy_numberv: phy number | |
5703 | * @link_rate: new link rate | |
5704 | * | |
5705 | * Returns nothing. | |
5706 | */ | |
5707 | static void | |
5708 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
5709 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
5710 | { | |
5711 | Mpi2ConfigReply_t mpi_reply; | |
5712 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5713 | struct _sas_device *sas_device; | |
5714 | u32 ioc_status; | |
5715 | unsigned long flags; | |
5716 | u64 sas_address; | |
5717 | struct scsi_target *starget; | |
5718 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5719 | u32 device_info; | |
5720 | ||
f92363d1 SR |
5721 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
5722 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
5723 | return; | |
5724 | ||
5725 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
5726 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
5727 | return; | |
5728 | ||
5729 | /* wide port handling ~ we need only handle device once for the phy that | |
5730 | * is matched in sas device page zero | |
5731 | */ | |
5732 | if (phy_number != sas_device_pg0.PhyNum) | |
5733 | return; | |
5734 | ||
5735 | /* check if this is end device */ | |
5736 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
5737 | if (!(_scsih_is_end_device(device_info))) | |
5738 | return; | |
5739 | ||
5740 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5741 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
d1cb5e49 | 5742 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
5743 | sas_address); |
5744 | ||
d1cb5e49 SR |
5745 | if (!sas_device) |
5746 | goto out_unlock; | |
f92363d1 SR |
5747 | |
5748 | if (unlikely(sas_device->handle != handle)) { | |
5749 | starget = sas_device->starget; | |
5750 | sas_target_priv_data = starget->hostdata; | |
5751 | starget_printk(KERN_INFO, starget, | |
5752 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
5753 | sas_device->handle, handle); | |
5754 | sas_target_priv_data->handle = handle; | |
5755 | sas_device->handle = handle; | |
aa53bb89 | 5756 | if (le16_to_cpu(sas_device_pg0.Flags) & |
e6d45e3e SR |
5757 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { |
5758 | sas_device->enclosure_level = | |
aa53bb89 | 5759 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
5760 | memcpy(sas_device->connector_name, |
5761 | sas_device_pg0.ConnectorName, 4); | |
5762 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
5763 | } else { |
5764 | sas_device->enclosure_level = 0; | |
5765 | sas_device->connector_name[0] = '\0'; | |
5766 | } | |
aba5a85c SR |
5767 | |
5768 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, | |
5769 | &sas_device_pg0, sas_device); | |
f92363d1 SR |
5770 | } |
5771 | ||
5772 | /* check if device is present */ | |
5773 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
5774 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
5775 | pr_err(MPT3SAS_FMT | |
5776 | "device is not present handle(0x%04x), flags!!!\n", | |
5777 | ioc->name, handle); | |
d1cb5e49 | 5778 | goto out_unlock; |
f92363d1 SR |
5779 | } |
5780 | ||
5781 | /* check if there were any issues with discovery */ | |
5782 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
d1cb5e49 SR |
5783 | sas_device_pg0.AccessStatus)) |
5784 | goto out_unlock; | |
f92363d1 SR |
5785 | |
5786 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5787 | _scsih_ublock_io_device(ioc, sas_address); | |
5788 | ||
d1cb5e49 SR |
5789 | if (sas_device) |
5790 | sas_device_put(sas_device); | |
5791 | return; | |
5792 | ||
5793 | out_unlock: | |
5794 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5795 | if (sas_device) | |
5796 | sas_device_put(sas_device); | |
f92363d1 SR |
5797 | } |
5798 | ||
5799 | /** | |
5800 | * _scsih_add_device - creating sas device object | |
5801 | * @ioc: per adapter object | |
5802 | * @handle: sas device handle | |
5803 | * @phy_num: phy number end device attached to | |
5804 | * @is_pd: is this hidden raid component | |
5805 | * | |
5806 | * Creating end device object, stored in ioc->sas_device_list. | |
5807 | * | |
5808 | * Returns 0 for success, non-zero for failure. | |
5809 | */ | |
5810 | static int | |
5811 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
5812 | u8 is_pd) | |
5813 | { | |
5814 | Mpi2ConfigReply_t mpi_reply; | |
5815 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5816 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
5817 | struct _sas_device *sas_device; | |
5818 | u32 ioc_status; | |
5819 | u64 sas_address; | |
5820 | u32 device_info; | |
75888956 | 5821 | int encl_pg0_rc = -1; |
f92363d1 SR |
5822 | |
5823 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5824 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
5825 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5826 | ioc->name, __FILE__, __LINE__, __func__); | |
5827 | return -1; | |
5828 | } | |
5829 | ||
5830 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5831 | MPI2_IOCSTATUS_MASK; | |
5832 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5833 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5834 | ioc->name, __FILE__, __LINE__, __func__); | |
5835 | return -1; | |
5836 | } | |
5837 | ||
5838 | /* check if this is end device */ | |
5839 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
5840 | if (!(_scsih_is_end_device(device_info))) | |
5841 | return -1; | |
c696f7b8 | 5842 | set_bit(handle, ioc->pend_os_device_add); |
f92363d1 SR |
5843 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
5844 | ||
5845 | /* check if device is present */ | |
5846 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
5847 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
5848 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
5849 | ioc->name, handle); | |
5850 | return -1; | |
5851 | } | |
5852 | ||
5853 | /* check if there were any issues with discovery */ | |
5854 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
5855 | sas_device_pg0.AccessStatus)) | |
5856 | return -1; | |
5857 | ||
d1cb5e49 SR |
5858 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
5859 | sas_address); | |
5860 | if (sas_device) { | |
c696f7b8 | 5861 | clear_bit(handle, ioc->pend_os_device_add); |
d1cb5e49 | 5862 | sas_device_put(sas_device); |
f92363d1 | 5863 | return -1; |
d1cb5e49 | 5864 | } |
f92363d1 | 5865 | |
75888956 SR |
5866 | if (sas_device_pg0.EnclosureHandle) { |
5867 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
5868 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
5869 | sas_device_pg0.EnclosureHandle); | |
5870 | if (encl_pg0_rc) | |
5871 | pr_info(MPT3SAS_FMT | |
5872 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
5873 | ioc->name, sas_device_pg0.EnclosureHandle); | |
5874 | } | |
5875 | ||
f92363d1 SR |
5876 | sas_device = kzalloc(sizeof(struct _sas_device), |
5877 | GFP_KERNEL); | |
5878 | if (!sas_device) { | |
5879 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5880 | ioc->name, __FILE__, __LINE__, __func__); | |
5881 | return 0; | |
5882 | } | |
5883 | ||
d1cb5e49 | 5884 | kref_init(&sas_device->refcount); |
f92363d1 SR |
5885 | sas_device->handle = handle; |
5886 | if (_scsih_get_sas_address(ioc, | |
5887 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
5888 | &sas_device->sas_address_parent) != 0) | |
5889 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5890 | ioc->name, __FILE__, __LINE__, __func__); | |
5891 | sas_device->enclosure_handle = | |
5892 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
e6d45e3e SR |
5893 | if (sas_device->enclosure_handle != 0) |
5894 | sas_device->slot = | |
5895 | le16_to_cpu(sas_device_pg0.Slot); | |
f92363d1 SR |
5896 | sas_device->device_info = device_info; |
5897 | sas_device->sas_address = sas_address; | |
5898 | sas_device->phy = sas_device_pg0.PhyNum; | |
5899 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
5900 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
5901 | ||
aa53bb89 SPS |
5902 | if (le16_to_cpu(sas_device_pg0.Flags) |
5903 | & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
e6d45e3e | 5904 | sas_device->enclosure_level = |
aa53bb89 | 5905 | sas_device_pg0.EnclosureLevel; |
310c8e40 CO |
5906 | memcpy(sas_device->connector_name, |
5907 | sas_device_pg0.ConnectorName, 4); | |
5908 | sas_device->connector_name[4] = '\0'; | |
e6d45e3e SR |
5909 | } else { |
5910 | sas_device->enclosure_level = 0; | |
5911 | sas_device->connector_name[0] = '\0'; | |
5912 | } | |
75888956 SR |
5913 | |
5914 | /* get enclosure_logical_id & chassis_slot */ | |
5915 | sas_device->is_chassis_slot_valid = 0; | |
5916 | if (encl_pg0_rc == 0) { | |
f92363d1 SR |
5917 | sas_device->enclosure_logical_id = |
5918 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
5919 | ||
75888956 SR |
5920 | if (le16_to_cpu(enclosure_pg0.Flags) & |
5921 | MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { | |
5922 | sas_device->is_chassis_slot_valid = 1; | |
5923 | sas_device->chassis_slot = | |
5924 | enclosure_pg0.ChassisSlot; | |
5925 | } | |
5926 | } | |
5927 | ||
f92363d1 SR |
5928 | /* get device name */ |
5929 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
5930 | ||
5931 | if (ioc->wait_for_discovery_to_complete) | |
5932 | _scsih_sas_device_init_add(ioc, sas_device); | |
5933 | else | |
5934 | _scsih_sas_device_add(ioc, sas_device); | |
5935 | ||
d1cb5e49 | 5936 | sas_device_put(sas_device); |
f92363d1 SR |
5937 | return 0; |
5938 | } | |
5939 | ||
5940 | /** | |
5941 | * _scsih_remove_device - removing sas device object | |
5942 | * @ioc: per adapter object | |
5943 | * @sas_device_delete: the sas_device object | |
5944 | * | |
5945 | * Return nothing. | |
5946 | */ | |
5947 | static void | |
5948 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
5949 | struct _sas_device *sas_device) | |
5950 | { | |
5951 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5952 | ||
0f624c39 SR |
5953 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
5954 | (sas_device->pfa_led_on)) { | |
5955 | _scsih_turn_off_pfa_led(ioc, sas_device); | |
5956 | sas_device->pfa_led_on = 0; | |
5957 | } | |
75888956 | 5958 | |
f92363d1 SR |
5959 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
5960 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
5961 | ioc->name, __func__, | |
5962 | sas_device->handle, (unsigned long long) | |
5963 | sas_device->sas_address)); | |
75888956 SR |
5964 | |
5965 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, | |
5966 | NULL, NULL)); | |
f92363d1 SR |
5967 | |
5968 | if (sas_device->starget && sas_device->starget->hostdata) { | |
5969 | sas_target_priv_data = sas_device->starget->hostdata; | |
5970 | sas_target_priv_data->deleted = 1; | |
5971 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
5972 | sas_target_priv_data->handle = | |
5973 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
5974 | } | |
7786ab6a SR |
5975 | |
5976 | if (!ioc->hide_drives) | |
5977 | mpt3sas_transport_port_remove(ioc, | |
f92363d1 SR |
5978 | sas_device->sas_address, |
5979 | sas_device->sas_address_parent); | |
5980 | ||
5981 | pr_info(MPT3SAS_FMT | |
5982 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
5983 | ioc->name, sas_device->handle, | |
5984 | (unsigned long long) sas_device->sas_address); | |
75888956 SR |
5985 | |
5986 | _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL); | |
f92363d1 SR |
5987 | |
5988 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5989 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
5990 | ioc->name, __func__, | |
e6d45e3e SR |
5991 | sas_device->handle, (unsigned long long) |
5992 | sas_device->sas_address)); | |
75888956 SR |
5993 | dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device, |
5994 | NULL, NULL)); | |
f92363d1 SR |
5995 | } |
5996 | ||
f92363d1 SR |
5997 | /** |
5998 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
5999 | * @ioc: per adapter object | |
6000 | * @event_data: event data payload | |
6001 | * Context: user. | |
6002 | */ | |
6003 | static void | |
6004 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6005 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
6006 | { | |
6007 | int i; | |
6008 | u16 handle; | |
6009 | u16 reason_code; | |
6010 | u8 phy_number; | |
6011 | char *status_str = NULL; | |
6012 | u8 link_rate, prev_link_rate; | |
6013 | ||
6014 | switch (event_data->ExpStatus) { | |
6015 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
6016 | status_str = "add"; | |
6017 | break; | |
6018 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
6019 | status_str = "remove"; | |
6020 | break; | |
6021 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
6022 | case 0: | |
6023 | status_str = "responding"; | |
6024 | break; | |
6025 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
6026 | status_str = "remove delay"; | |
6027 | break; | |
6028 | default: | |
6029 | status_str = "unknown status"; | |
6030 | break; | |
6031 | } | |
6032 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
6033 | ioc->name, status_str); | |
6034 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
6035 | "start_phy(%02d), count(%d)\n", | |
6036 | le16_to_cpu(event_data->ExpanderDevHandle), | |
6037 | le16_to_cpu(event_data->EnclosureHandle), | |
6038 | event_data->StartPhyNum, event_data->NumEntries); | |
6039 | for (i = 0; i < event_data->NumEntries; i++) { | |
6040 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6041 | if (!handle) | |
6042 | continue; | |
6043 | phy_number = event_data->StartPhyNum + i; | |
6044 | reason_code = event_data->PHY[i].PhyStatus & | |
6045 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6046 | switch (reason_code) { | |
6047 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6048 | status_str = "target add"; | |
6049 | break; | |
6050 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6051 | status_str = "target remove"; | |
6052 | break; | |
6053 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
6054 | status_str = "delay target remove"; | |
6055 | break; | |
6056 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6057 | status_str = "link rate change"; | |
6058 | break; | |
6059 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
6060 | status_str = "target responding"; | |
6061 | break; | |
6062 | default: | |
6063 | status_str = "unknown"; | |
6064 | break; | |
6065 | } | |
6066 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6067 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6068 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
6069 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
6070 | handle, status_str, link_rate, prev_link_rate); | |
6071 | ||
6072 | } | |
6073 | } | |
f92363d1 SR |
6074 | |
6075 | /** | |
6076 | * _scsih_sas_topology_change_event - handle topology changes | |
6077 | * @ioc: per adapter object | |
6078 | * @fw_event: The fw_event_work object | |
6079 | * Context: user. | |
6080 | * | |
6081 | */ | |
6082 | static int | |
6083 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6084 | struct fw_event_work *fw_event) | |
6085 | { | |
6086 | int i; | |
6087 | u16 parent_handle, handle; | |
6088 | u16 reason_code; | |
6089 | u8 phy_number, max_phys; | |
6090 | struct _sas_node *sas_expander; | |
6091 | u64 sas_address; | |
6092 | unsigned long flags; | |
6093 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
6094 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
6095 | (Mpi2EventDataSasTopologyChangeList_t *) | |
6096 | fw_event->event_data; | |
f92363d1 | 6097 | |
f92363d1 SR |
6098 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6099 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
f92363d1 SR |
6100 | |
6101 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
6102 | return 0; | |
6103 | ||
6104 | if (!ioc->sas_hba.num_phys) | |
6105 | _scsih_sas_host_add(ioc); | |
6106 | else | |
6107 | _scsih_sas_host_refresh(ioc); | |
6108 | ||
6109 | if (fw_event->ignore) { | |
6110 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6111 | "ignoring expander event\n", ioc->name)); | |
6112 | return 0; | |
6113 | } | |
6114 | ||
6115 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
6116 | ||
6117 | /* handle expander add */ | |
6118 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
6119 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
6120 | return 0; | |
6121 | ||
6122 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6123 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
6124 | parent_handle); | |
6125 | if (sas_expander) { | |
6126 | sas_address = sas_expander->sas_address; | |
6127 | max_phys = sas_expander->num_phys; | |
6128 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
6129 | sas_address = ioc->sas_hba.sas_address; | |
6130 | max_phys = ioc->sas_hba.num_phys; | |
6131 | } else { | |
6132 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6133 | return 0; | |
6134 | } | |
6135 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6136 | ||
6137 | /* handle siblings events */ | |
6138 | for (i = 0; i < event_data->NumEntries; i++) { | |
6139 | if (fw_event->ignore) { | |
6140 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6141 | "ignoring expander event\n", ioc->name)); | |
6142 | return 0; | |
6143 | } | |
6144 | if (ioc->remove_host || ioc->pci_error_recovery) | |
6145 | return 0; | |
6146 | phy_number = event_data->StartPhyNum + i; | |
6147 | if (phy_number >= max_phys) | |
6148 | continue; | |
6149 | reason_code = event_data->PHY[i].PhyStatus & | |
6150 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
6151 | if ((event_data->PHY[i].PhyStatus & | |
6152 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
6153 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
6154 | continue; | |
6155 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
6156 | if (!handle) | |
6157 | continue; | |
6158 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
6159 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
6160 | switch (reason_code) { | |
6161 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
6162 | ||
6163 | if (ioc->shost_recovery) | |
6164 | break; | |
6165 | ||
6166 | if (link_rate == prev_link_rate) | |
6167 | break; | |
6168 | ||
6169 | mpt3sas_transport_update_links(ioc, sas_address, | |
6170 | handle, phy_number, link_rate); | |
6171 | ||
6172 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
6173 | break; | |
6174 | ||
6175 | _scsih_check_device(ioc, sas_address, handle, | |
6176 | phy_number, link_rate); | |
6177 | ||
c696f7b8 SPS |
6178 | if (!test_bit(handle, ioc->pend_os_device_add)) |
6179 | break; | |
6180 | ||
f92363d1 SR |
6181 | |
6182 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
6183 | ||
6184 | if (ioc->shost_recovery) | |
6185 | break; | |
6186 | ||
6187 | mpt3sas_transport_update_links(ioc, sas_address, | |
6188 | handle, phy_number, link_rate); | |
6189 | ||
6190 | _scsih_add_device(ioc, handle, phy_number, 0); | |
6191 | ||
6192 | break; | |
6193 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
6194 | ||
6195 | _scsih_device_remove_by_handle(ioc, handle); | |
6196 | break; | |
6197 | } | |
6198 | } | |
6199 | ||
6200 | /* handle expander removal */ | |
6201 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
6202 | sas_expander) | |
6203 | mpt3sas_expander_remove(ioc, sas_address); | |
6204 | ||
6205 | return 0; | |
6206 | } | |
6207 | ||
f92363d1 SR |
6208 | /** |
6209 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
6210 | * @event_data: event data payload | |
6211 | * Context: user. | |
6212 | * | |
6213 | * Return nothing. | |
6214 | */ | |
6215 | static void | |
6216 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6217 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
6218 | { | |
6219 | char *reason_str = NULL; | |
6220 | ||
6221 | switch (event_data->ReasonCode) { | |
6222 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
6223 | reason_str = "smart data"; | |
6224 | break; | |
6225 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
6226 | reason_str = "unsupported device discovered"; | |
6227 | break; | |
6228 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
6229 | reason_str = "internal device reset"; | |
6230 | break; | |
6231 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
6232 | reason_str = "internal task abort"; | |
6233 | break; | |
6234 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
6235 | reason_str = "internal task abort set"; | |
6236 | break; | |
6237 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
6238 | reason_str = "internal clear task set"; | |
6239 | break; | |
6240 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
6241 | reason_str = "internal query task"; | |
6242 | break; | |
6243 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
6244 | reason_str = "sata init failure"; | |
6245 | break; | |
6246 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
6247 | reason_str = "internal device reset complete"; | |
6248 | break; | |
6249 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
6250 | reason_str = "internal task abort complete"; | |
6251 | break; | |
6252 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
6253 | reason_str = "internal async notification"; | |
6254 | break; | |
6255 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
6256 | reason_str = "expander reduced functionality"; | |
6257 | break; | |
6258 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
6259 | reason_str = "expander reduced functionality complete"; | |
6260 | break; | |
6261 | default: | |
6262 | reason_str = "unknown reason"; | |
6263 | break; | |
6264 | } | |
6265 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
6266 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
6267 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
6268 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
6269 | le16_to_cpu(event_data->TaskTag)); | |
6270 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
6271 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
6272 | event_data->ASC, event_data->ASCQ); | |
6273 | pr_info("\n"); | |
6274 | } | |
f92363d1 SR |
6275 | |
6276 | /** | |
6277 | * _scsih_sas_device_status_change_event - handle device status change | |
6278 | * @ioc: per adapter object | |
6279 | * @fw_event: The fw_event_work object | |
6280 | * Context: user. | |
6281 | * | |
6282 | * Return nothing. | |
6283 | */ | |
6284 | static void | |
6285 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6286 | struct fw_event_work *fw_event) | |
6287 | { | |
6288 | struct MPT3SAS_TARGET *target_priv_data; | |
6289 | struct _sas_device *sas_device; | |
6290 | u64 sas_address; | |
6291 | unsigned long flags; | |
6292 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
6293 | (Mpi2EventDataSasDeviceStatusChange_t *) |
6294 | fw_event->event_data; | |
f92363d1 | 6295 | |
f92363d1 SR |
6296 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6297 | _scsih_sas_device_status_change_event_debug(ioc, | |
6298 | event_data); | |
f92363d1 SR |
6299 | |
6300 | /* In MPI Revision K (0xC), the internal device reset complete was | |
6301 | * implemented, so avoid setting tm_busy flag for older firmware. | |
6302 | */ | |
6303 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
6304 | return; | |
6305 | ||
6306 | if (event_data->ReasonCode != | |
6307 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
6308 | event_data->ReasonCode != | |
6309 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
6310 | return; | |
6311 | ||
6312 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6313 | sas_address = le64_to_cpu(event_data->SASAddress); | |
d1cb5e49 | 6314 | sas_device = __mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 SR |
6315 | sas_address); |
6316 | ||
d1cb5e49 SR |
6317 | if (!sas_device || !sas_device->starget) |
6318 | goto out; | |
f92363d1 SR |
6319 | |
6320 | target_priv_data = sas_device->starget->hostdata; | |
d1cb5e49 SR |
6321 | if (!target_priv_data) |
6322 | goto out; | |
f92363d1 SR |
6323 | |
6324 | if (event_data->ReasonCode == | |
6325 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
6326 | target_priv_data->tm_busy = 1; | |
6327 | else | |
6328 | target_priv_data->tm_busy = 0; | |
d1cb5e49 SR |
6329 | |
6330 | out: | |
6331 | if (sas_device) | |
6332 | sas_device_put(sas_device); | |
6333 | ||
f92363d1 | 6334 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
d1cb5e49 | 6335 | |
f92363d1 SR |
6336 | } |
6337 | ||
f92363d1 SR |
6338 | /** |
6339 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
6340 | * event | |
6341 | * @ioc: per adapter object | |
6342 | * @event_data: event data payload | |
6343 | * Context: user. | |
6344 | * | |
6345 | * Return nothing. | |
6346 | */ | |
6347 | static void | |
6348 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6349 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
6350 | { | |
6351 | char *reason_str = NULL; | |
6352 | ||
6353 | switch (event_data->ReasonCode) { | |
6354 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
6355 | reason_str = "enclosure add"; | |
6356 | break; | |
6357 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
6358 | reason_str = "enclosure remove"; | |
6359 | break; | |
6360 | default: | |
6361 | reason_str = "unknown reason"; | |
6362 | break; | |
6363 | } | |
6364 | ||
6365 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
6366 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
6367 | " number slots(%d)\n", ioc->name, reason_str, | |
6368 | le16_to_cpu(event_data->EnclosureHandle), | |
6369 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
6370 | le16_to_cpu(event_data->StartSlot)); | |
6371 | } | |
f92363d1 SR |
6372 | |
6373 | /** | |
6374 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
6375 | * @ioc: per adapter object | |
6376 | * @fw_event: The fw_event_work object | |
6377 | * Context: user. | |
6378 | * | |
6379 | * Return nothing. | |
6380 | */ | |
6381 | static void | |
6382 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6383 | struct fw_event_work *fw_event) | |
6384 | { | |
f92363d1 SR |
6385 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
6386 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 6387 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 | 6388 | fw_event->event_data); |
f92363d1 SR |
6389 | } |
6390 | ||
6391 | /** | |
6392 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
6393 | * @ioc: per adapter object | |
6394 | * @fw_event: The fw_event_work object | |
6395 | * Context: user. | |
6396 | * | |
6397 | * Return nothing. | |
6398 | */ | |
6399 | static void | |
6400 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
6401 | struct fw_event_work *fw_event) | |
6402 | { | |
6403 | struct scsi_cmnd *scmd; | |
6404 | struct scsi_device *sdev; | |
6405 | u16 smid, handle; | |
6406 | u32 lun; | |
6407 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
6408 | u32 termination_count; | |
6409 | u32 query_count; | |
6410 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
6411 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
6412 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
6413 | fw_event->event_data; | |
f92363d1 SR |
6414 | u16 ioc_status; |
6415 | unsigned long flags; | |
6416 | int r; | |
6417 | u8 max_retries = 0; | |
6418 | u8 task_abort_retries; | |
6419 | ||
6420 | mutex_lock(&ioc->tm_cmds.mutex); | |
6421 | pr_info(MPT3SAS_FMT | |
6422 | "%s: enter: phy number(%d), width(%d)\n", | |
6423 | ioc->name, __func__, event_data->PhyNum, | |
6424 | event_data->PortWidth); | |
6425 | ||
6426 | _scsih_block_io_all_device(ioc); | |
6427 | ||
6428 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
6429 | mpi_reply = ioc->tm_cmds.reply; | |
6430 | broadcast_aen_retry: | |
6431 | ||
6432 | /* sanity checks for retrying this loop */ | |
6433 | if (max_retries++ == 5) { | |
6434 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
6435 | ioc->name, __func__)); | |
6436 | goto out; | |
6437 | } else if (max_retries > 1) | |
6438 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
6439 | ioc->name, __func__, max_retries - 1)); | |
6440 | ||
6441 | termination_count = 0; | |
6442 | query_count = 0; | |
6443 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
6444 | if (ioc->shost_recovery) | |
6445 | goto out; | |
6446 | scmd = _scsih_scsi_lookup_get(ioc, smid); | |
6447 | if (!scmd) | |
6448 | continue; | |
6449 | sdev = scmd->device; | |
6450 | sas_device_priv_data = sdev->hostdata; | |
6451 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
6452 | continue; | |
6453 | /* skip hidden raid components */ | |
6454 | if (sas_device_priv_data->sas_target->flags & | |
6455 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
6456 | continue; | |
6457 | /* skip volumes */ | |
6458 | if (sas_device_priv_data->sas_target->flags & | |
6459 | MPT_TARGET_FLAGS_VOLUME) | |
6460 | continue; | |
6461 | ||
6462 | handle = sas_device_priv_data->sas_target->handle; | |
6463 | lun = sas_device_priv_data->lun; | |
6464 | query_count++; | |
6465 | ||
6466 | if (ioc->shost_recovery) | |
6467 | goto out; | |
6468 | ||
6469 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6470 | r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun, | |
96902835 | 6471 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30); |
f92363d1 SR |
6472 | if (r == FAILED) { |
6473 | sdev_printk(KERN_WARNING, sdev, | |
6474 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
6475 | "QUERY_TASK: scmd(%p)\n", scmd); | |
6476 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
6477 | goto broadcast_aen_retry; | |
6478 | } | |
6479 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
6480 | & MPI2_IOCSTATUS_MASK; | |
6481 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6482 | sdev_printk(KERN_WARNING, sdev, | |
6483 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
6484 | ioc_status, scmd); | |
6485 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
6486 | goto broadcast_aen_retry; | |
6487 | } | |
6488 | ||
6489 | /* see if IO is still owned by IOC and target */ | |
6490 | if (mpi_reply->ResponseCode == | |
6491 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
6492 | mpi_reply->ResponseCode == | |
6493 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
6494 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
6495 | continue; | |
6496 | } | |
6497 | task_abort_retries = 0; | |
6498 | tm_retry: | |
6499 | if (task_abort_retries++ == 60) { | |
6500 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6501 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
6502 | __func__)); | |
6503 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
6504 | goto broadcast_aen_retry; | |
6505 | } | |
6506 | ||
6507 | if (ioc->shost_recovery) | |
6508 | goto out_no_lock; | |
6509 | ||
6510 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, | |
96902835 CO |
6511 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, |
6512 | 30); | |
f92363d1 SR |
6513 | if (r == FAILED) { |
6514 | sdev_printk(KERN_WARNING, sdev, | |
6515 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
6516 | "scmd(%p)\n", scmd); | |
6517 | goto tm_retry; | |
6518 | } | |
6519 | ||
6520 | if (task_abort_retries > 1) | |
6521 | sdev_printk(KERN_WARNING, sdev, | |
6522 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
6523 | " scmd(%p)\n", | |
6524 | task_abort_retries - 1, scmd); | |
6525 | ||
6526 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
6527 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
6528 | } | |
6529 | ||
6530 | if (ioc->broadcast_aen_pending) { | |
6531 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6532 | "%s: loop back due to pending AEN\n", | |
6533 | ioc->name, __func__)); | |
6534 | ioc->broadcast_aen_pending = 0; | |
6535 | goto broadcast_aen_retry; | |
6536 | } | |
6537 | ||
6538 | out: | |
6539 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
6540 | out_no_lock: | |
6541 | ||
6542 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6543 | "%s - exit, query_count = %d termination_count = %d\n", | |
6544 | ioc->name, __func__, query_count, termination_count)); | |
6545 | ||
6546 | ioc->broadcast_aen_busy = 0; | |
6547 | if (!ioc->shost_recovery) | |
6548 | _scsih_ublock_io_all_device(ioc); | |
6549 | mutex_unlock(&ioc->tm_cmds.mutex); | |
6550 | } | |
6551 | ||
6552 | /** | |
6553 | * _scsih_sas_discovery_event - handle discovery events | |
6554 | * @ioc: per adapter object | |
6555 | * @fw_event: The fw_event_work object | |
6556 | * Context: user. | |
6557 | * | |
6558 | * Return nothing. | |
6559 | */ | |
6560 | static void | |
6561 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
6562 | struct fw_event_work *fw_event) | |
6563 | { | |
35b62362 JL |
6564 | Mpi2EventDataSasDiscovery_t *event_data = |
6565 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 | 6566 | |
f92363d1 SR |
6567 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
6568 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
6569 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
6570 | "start" : "stop"); | |
af009411 SR |
6571 | if (event_data->DiscoveryStatus) |
6572 | pr_info("discovery_status(0x%08x)", | |
6573 | le32_to_cpu(event_data->DiscoveryStatus)); | |
6574 | pr_info("\n"); | |
f92363d1 | 6575 | } |
f92363d1 SR |
6576 | |
6577 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
6578 | !ioc->sas_hba.num_phys) { | |
6579 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
6580 | /* Wait for the reset to complete */ | |
6581 | while (ioc->shost_recovery) | |
6582 | ssleep(1); | |
6583 | } | |
6584 | _scsih_sas_host_add(ioc); | |
6585 | } | |
6586 | } | |
6587 | ||
6588 | /** | |
6589 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
6590 | * @ioc: per adapter object | |
6591 | * @handle: device handle for physical disk | |
6592 | * @phys_disk_num: physical disk number | |
6593 | * | |
6594 | * Return 0 for success, else failure. | |
6595 | */ | |
6596 | static int | |
6597 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
6598 | { | |
6599 | Mpi2RaidActionRequest_t *mpi_request; | |
6600 | Mpi2RaidActionReply_t *mpi_reply; | |
6601 | u16 smid; | |
6602 | u8 issue_reset = 0; | |
6603 | int rc = 0; | |
6604 | u16 ioc_status; | |
6605 | u32 log_info; | |
6606 | ||
c84b06a4 SR |
6607 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
6608 | return rc; | |
6609 | ||
f92363d1 SR |
6610 | mutex_lock(&ioc->scsih_cmds.mutex); |
6611 | ||
6612 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
6613 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
6614 | ioc->name, __func__); | |
6615 | rc = -EAGAIN; | |
6616 | goto out; | |
6617 | } | |
6618 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
6619 | ||
6620 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
6621 | if (!smid) { | |
6622 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
6623 | ioc->name, __func__); | |
6624 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
6625 | rc = -EAGAIN; | |
6626 | goto out; | |
6627 | } | |
6628 | ||
6629 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
6630 | ioc->scsih_cmds.smid = smid; | |
6631 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
6632 | ||
6633 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
6634 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
6635 | mpi_request->PhysDiskNum = phys_disk_num; | |
6636 | ||
6637 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
6638 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
6639 | handle, phys_disk_num)); | |
6640 | ||
6641 | init_completion(&ioc->scsih_cmds.done); | |
81c16f83 | 6642 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
6643 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
6644 | ||
6645 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
6646 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
6647 | ioc->name, __func__); | |
6648 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) | |
6649 | issue_reset = 1; | |
6650 | rc = -EFAULT; | |
6651 | goto out; | |
6652 | } | |
6653 | ||
6654 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
6655 | ||
6656 | mpi_reply = ioc->scsih_cmds.reply; | |
6657 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
6658 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
6659 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
6660 | else | |
6661 | log_info = 0; | |
6662 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
6663 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6664 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6665 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
6666 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
6667 | log_info)); | |
6668 | rc = -EFAULT; | |
6669 | } else | |
6670 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6671 | "IR RAID_ACTION: completed successfully\n", | |
6672 | ioc->name)); | |
6673 | } | |
6674 | ||
6675 | out: | |
6676 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
6677 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
6678 | ||
6679 | if (issue_reset) | |
98c56ad3 | 6680 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
6681 | return rc; |
6682 | } | |
6683 | ||
6684 | /** | |
6685 | * _scsih_reprobe_lun - reprobing lun | |
6686 | * @sdev: scsi device struct | |
6687 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
6688 | * | |
6689 | **/ | |
6690 | static void | |
6691 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
6692 | { | |
f92363d1 SR |
6693 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
6694 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
6c7abffc | 6695 | sdev->no_uld_attach ? "hiding" : "exposing"); |
8bbb1cf6 | 6696 | WARN_ON(scsi_device_reprobe(sdev)); |
f92363d1 SR |
6697 | } |
6698 | ||
6699 | /** | |
6700 | * _scsih_sas_volume_add - add new volume | |
6701 | * @ioc: per adapter object | |
6702 | * @element: IR config element data | |
6703 | * Context: user. | |
6704 | * | |
6705 | * Return nothing. | |
6706 | */ | |
6707 | static void | |
6708 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
6709 | Mpi2EventIrConfigElement_t *element) | |
6710 | { | |
6711 | struct _raid_device *raid_device; | |
6712 | unsigned long flags; | |
6713 | u64 wwid; | |
6714 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
6715 | int rc; | |
6716 | ||
6717 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
6718 | if (!wwid) { | |
6719 | pr_err(MPT3SAS_FMT | |
6720 | "failure at %s:%d/%s()!\n", ioc->name, | |
6721 | __FILE__, __LINE__, __func__); | |
6722 | return; | |
6723 | } | |
6724 | ||
6725 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6726 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
6727 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6728 | ||
6729 | if (raid_device) | |
6730 | return; | |
6731 | ||
6732 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
6733 | if (!raid_device) { | |
6734 | pr_err(MPT3SAS_FMT | |
6735 | "failure at %s:%d/%s()!\n", ioc->name, | |
6736 | __FILE__, __LINE__, __func__); | |
6737 | return; | |
6738 | } | |
6739 | ||
6740 | raid_device->id = ioc->sas_id++; | |
6741 | raid_device->channel = RAID_CHANNEL; | |
6742 | raid_device->handle = handle; | |
6743 | raid_device->wwid = wwid; | |
6744 | _scsih_raid_device_add(ioc, raid_device); | |
6745 | if (!ioc->wait_for_discovery_to_complete) { | |
6746 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
6747 | raid_device->id, 0); | |
6748 | if (rc) | |
6749 | _scsih_raid_device_remove(ioc, raid_device); | |
6750 | } else { | |
6751 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6752 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
6753 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6754 | } | |
6755 | } | |
6756 | ||
6757 | /** | |
6758 | * _scsih_sas_volume_delete - delete volume | |
6759 | * @ioc: per adapter object | |
6760 | * @handle: volume device handle | |
6761 | * Context: user. | |
6762 | * | |
6763 | * Return nothing. | |
6764 | */ | |
6765 | static void | |
6766 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
6767 | { | |
6768 | struct _raid_device *raid_device; | |
6769 | unsigned long flags; | |
6770 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6771 | struct scsi_target *starget = NULL; | |
6772 | ||
6773 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 6774 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
6775 | if (raid_device) { |
6776 | if (raid_device->starget) { | |
6777 | starget = raid_device->starget; | |
6778 | sas_target_priv_data = starget->hostdata; | |
6779 | sas_target_priv_data->deleted = 1; | |
6780 | } | |
6781 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
6782 | ioc->name, raid_device->handle, | |
6783 | (unsigned long long) raid_device->wwid); | |
6784 | list_del(&raid_device->list); | |
6785 | kfree(raid_device); | |
6786 | } | |
6787 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6788 | if (starget) | |
6789 | scsi_remove_target(&starget->dev); | |
6790 | } | |
6791 | ||
6792 | /** | |
6793 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
6794 | * @ioc: per adapter object | |
6795 | * @element: IR config element data | |
6796 | * Context: user. | |
6797 | * | |
6798 | * Return nothing. | |
6799 | */ | |
6800 | static void | |
6801 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
6802 | Mpi2EventIrConfigElement_t *element) | |
6803 | { | |
6804 | struct _sas_device *sas_device; | |
6805 | struct scsi_target *starget = NULL; | |
6806 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6807 | unsigned long flags; | |
6808 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6809 | ||
6810 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 6811 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
6812 | if (sas_device) { |
6813 | sas_device->volume_handle = 0; | |
6814 | sas_device->volume_wwid = 0; | |
6815 | clear_bit(handle, ioc->pd_handles); | |
6816 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6817 | starget = sas_device->starget; | |
6818 | sas_target_priv_data = starget->hostdata; | |
6819 | sas_target_priv_data->flags &= | |
6820 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
6821 | } | |
6822 | } | |
6823 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6824 | if (!sas_device) | |
6825 | return; | |
6826 | ||
6827 | /* exposing raid component */ | |
6828 | if (starget) | |
6829 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
d1cb5e49 SR |
6830 | |
6831 | sas_device_put(sas_device); | |
f92363d1 SR |
6832 | } |
6833 | ||
6834 | /** | |
6835 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
6836 | * @ioc: per adapter object | |
6837 | * @element: IR config element data | |
6838 | * Context: user. | |
6839 | * | |
6840 | * Return nothing. | |
6841 | */ | |
6842 | static void | |
6843 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
6844 | Mpi2EventIrConfigElement_t *element) | |
6845 | { | |
6846 | struct _sas_device *sas_device; | |
6847 | struct scsi_target *starget = NULL; | |
6848 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6849 | unsigned long flags; | |
6850 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6851 | u16 volume_handle = 0; | |
6852 | u64 volume_wwid = 0; | |
6853 | ||
6854 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
6855 | if (volume_handle) | |
6856 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
6857 | &volume_wwid); | |
6858 | ||
6859 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
d1cb5e49 | 6860 | sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
6861 | if (sas_device) { |
6862 | set_bit(handle, ioc->pd_handles); | |
6863 | if (sas_device->starget && sas_device->starget->hostdata) { | |
6864 | starget = sas_device->starget; | |
6865 | sas_target_priv_data = starget->hostdata; | |
6866 | sas_target_priv_data->flags |= | |
6867 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
6868 | sas_device->volume_handle = volume_handle; | |
6869 | sas_device->volume_wwid = volume_wwid; | |
6870 | } | |
6871 | } | |
6872 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6873 | if (!sas_device) | |
6874 | return; | |
6875 | ||
6876 | /* hiding raid component */ | |
6877 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
c84b06a4 | 6878 | |
f92363d1 SR |
6879 | if (starget) |
6880 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
d1cb5e49 SR |
6881 | |
6882 | sas_device_put(sas_device); | |
f92363d1 SR |
6883 | } |
6884 | ||
6885 | /** | |
6886 | * _scsih_sas_pd_delete - delete pd component | |
6887 | * @ioc: per adapter object | |
6888 | * @element: IR config element data | |
6889 | * Context: user. | |
6890 | * | |
6891 | * Return nothing. | |
6892 | */ | |
6893 | static void | |
6894 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
6895 | Mpi2EventIrConfigElement_t *element) | |
6896 | { | |
6897 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
6898 | ||
6899 | _scsih_device_remove_by_handle(ioc, handle); | |
6900 | } | |
6901 | ||
6902 | /** | |
6903 | * _scsih_sas_pd_add - remove pd component | |
6904 | * @ioc: per adapter object | |
6905 | * @element: IR config element data | |
6906 | * Context: user. | |
6907 | * | |
6908 | * Return nothing. | |
6909 | */ | |
6910 | static void | |
6911 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
6912 | Mpi2EventIrConfigElement_t *element) | |
6913 | { | |
6914 | struct _sas_device *sas_device; | |
f92363d1 SR |
6915 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
6916 | Mpi2ConfigReply_t mpi_reply; | |
6917 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6918 | u32 ioc_status; | |
6919 | u64 sas_address; | |
6920 | u16 parent_handle; | |
6921 | ||
6922 | set_bit(handle, ioc->pd_handles); | |
6923 | ||
d1cb5e49 | 6924 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
f92363d1 SR |
6925 | if (sas_device) { |
6926 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
d1cb5e49 | 6927 | sas_device_put(sas_device); |
f92363d1 SR |
6928 | return; |
6929 | } | |
6930 | ||
6931 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
6932 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
6933 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6934 | ioc->name, __FILE__, __LINE__, __func__); | |
6935 | return; | |
6936 | } | |
6937 | ||
6938 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6939 | MPI2_IOCSTATUS_MASK; | |
6940 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6941 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6942 | ioc->name, __FILE__, __LINE__, __func__); | |
6943 | return; | |
6944 | } | |
6945 | ||
6946 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
6947 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
6948 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
6949 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
6950 | ||
6951 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
6952 | _scsih_add_device(ioc, handle, 0, 1); | |
6953 | } | |
6954 | ||
f92363d1 SR |
6955 | /** |
6956 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
6957 | * @ioc: per adapter object | |
6958 | * @event_data: event data payload | |
6959 | * Context: user. | |
6960 | * | |
6961 | * Return nothing. | |
6962 | */ | |
6963 | static void | |
6964 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6965 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
6966 | { | |
6967 | Mpi2EventIrConfigElement_t *element; | |
6968 | u8 element_type; | |
6969 | int i; | |
6970 | char *reason_str = NULL, *element_str = NULL; | |
6971 | ||
6972 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
6973 | ||
6974 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
6975 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
6976 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
6977 | "foreign" : "native", event_data->NumElements); | |
6978 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
6979 | switch (element->ReasonCode) { | |
6980 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
6981 | reason_str = "add"; | |
6982 | break; | |
6983 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
6984 | reason_str = "remove"; | |
6985 | break; | |
6986 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
6987 | reason_str = "no change"; | |
6988 | break; | |
6989 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
6990 | reason_str = "hide"; | |
6991 | break; | |
6992 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
6993 | reason_str = "unhide"; | |
6994 | break; | |
6995 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
6996 | reason_str = "volume_created"; | |
6997 | break; | |
6998 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
6999 | reason_str = "volume_deleted"; | |
7000 | break; | |
7001 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7002 | reason_str = "pd_created"; | |
7003 | break; | |
7004 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7005 | reason_str = "pd_deleted"; | |
7006 | break; | |
7007 | default: | |
7008 | reason_str = "unknown reason"; | |
7009 | break; | |
7010 | } | |
7011 | element_type = le16_to_cpu(element->ElementFlags) & | |
7012 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
7013 | switch (element_type) { | |
7014 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
7015 | element_str = "volume"; | |
7016 | break; | |
7017 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
7018 | element_str = "phys disk"; | |
7019 | break; | |
7020 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
7021 | element_str = "hot spare"; | |
7022 | break; | |
7023 | default: | |
7024 | element_str = "unknown element"; | |
7025 | break; | |
7026 | } | |
7027 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
7028 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
7029 | reason_str, le16_to_cpu(element->VolDevHandle), | |
7030 | le16_to_cpu(element->PhysDiskDevHandle), | |
7031 | element->PhysDiskNum); | |
7032 | } | |
7033 | } | |
f92363d1 SR |
7034 | |
7035 | /** | |
7036 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
7037 | * @ioc: per adapter object | |
7038 | * @fw_event: The fw_event_work object | |
7039 | * Context: user. | |
7040 | * | |
7041 | * Return nothing. | |
7042 | */ | |
7043 | static void | |
7044 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
7045 | struct fw_event_work *fw_event) | |
7046 | { | |
7047 | Mpi2EventIrConfigElement_t *element; | |
7048 | int i; | |
7049 | u8 foreign_config; | |
35b62362 JL |
7050 | Mpi2EventDataIrConfigChangeList_t *event_data = |
7051 | (Mpi2EventDataIrConfigChangeList_t *) | |
7052 | fw_event->event_data; | |
f92363d1 | 7053 | |
7786ab6a SR |
7054 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
7055 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
7056 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
7057 | ||
f92363d1 SR |
7058 | foreign_config = (le32_to_cpu(event_data->Flags) & |
7059 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
7060 | ||
7061 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
c84b06a4 SR |
7062 | if (ioc->shost_recovery && |
7063 | ioc->hba_mpi_version_belonged != MPI2_VERSION) { | |
f92363d1 SR |
7064 | for (i = 0; i < event_data->NumElements; i++, element++) { |
7065 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
7066 | _scsih_ir_fastpath(ioc, | |
7067 | le16_to_cpu(element->PhysDiskDevHandle), | |
7068 | element->PhysDiskNum); | |
7069 | } | |
7070 | return; | |
7071 | } | |
7786ab6a | 7072 | |
f92363d1 SR |
7073 | for (i = 0; i < event_data->NumElements; i++, element++) { |
7074 | ||
7075 | switch (element->ReasonCode) { | |
7076 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
7077 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
7078 | if (!foreign_config) | |
7079 | _scsih_sas_volume_add(ioc, element); | |
7080 | break; | |
7081 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
7082 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
7083 | if (!foreign_config) | |
7084 | _scsih_sas_volume_delete(ioc, | |
7085 | le16_to_cpu(element->VolDevHandle)); | |
7086 | break; | |
7087 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
7786ab6a SR |
7088 | if (!ioc->is_warpdrive) |
7089 | _scsih_sas_pd_hide(ioc, element); | |
f92363d1 SR |
7090 | break; |
7091 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
7786ab6a SR |
7092 | if (!ioc->is_warpdrive) |
7093 | _scsih_sas_pd_expose(ioc, element); | |
f92363d1 SR |
7094 | break; |
7095 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
7786ab6a SR |
7096 | if (!ioc->is_warpdrive) |
7097 | _scsih_sas_pd_add(ioc, element); | |
f92363d1 SR |
7098 | break; |
7099 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
7786ab6a SR |
7100 | if (!ioc->is_warpdrive) |
7101 | _scsih_sas_pd_delete(ioc, element); | |
f92363d1 SR |
7102 | break; |
7103 | } | |
7104 | } | |
7105 | } | |
7106 | ||
7107 | /** | |
7108 | * _scsih_sas_ir_volume_event - IR volume event | |
7109 | * @ioc: per adapter object | |
7110 | * @fw_event: The fw_event_work object | |
7111 | * Context: user. | |
7112 | * | |
7113 | * Return nothing. | |
7114 | */ | |
7115 | static void | |
7116 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
7117 | struct fw_event_work *fw_event) | |
7118 | { | |
7119 | u64 wwid; | |
7120 | unsigned long flags; | |
7121 | struct _raid_device *raid_device; | |
7122 | u16 handle; | |
7123 | u32 state; | |
7124 | int rc; | |
35b62362 JL |
7125 | Mpi2EventDataIrVolume_t *event_data = |
7126 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
7127 | |
7128 | if (ioc->shost_recovery) | |
7129 | return; | |
7130 | ||
7131 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
7132 | return; | |
7133 | ||
7134 | handle = le16_to_cpu(event_data->VolDevHandle); | |
7135 | state = le32_to_cpu(event_data->NewValue); | |
7786ab6a SR |
7136 | if (!ioc->hide_ir_msg) |
7137 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7138 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
7139 | ioc->name, __func__, handle, | |
7140 | le32_to_cpu(event_data->PreviousValue), state)); | |
f92363d1 SR |
7141 | switch (state) { |
7142 | case MPI2_RAID_VOL_STATE_MISSING: | |
7143 | case MPI2_RAID_VOL_STATE_FAILED: | |
7144 | _scsih_sas_volume_delete(ioc, handle); | |
7145 | break; | |
7146 | ||
7147 | case MPI2_RAID_VOL_STATE_ONLINE: | |
7148 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
7149 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
7150 | ||
7151 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
c84b06a4 | 7152 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7153 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
7154 | ||
7155 | if (raid_device) | |
7156 | break; | |
7157 | ||
7158 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
7159 | if (!wwid) { | |
7160 | pr_err(MPT3SAS_FMT | |
7161 | "failure at %s:%d/%s()!\n", ioc->name, | |
7162 | __FILE__, __LINE__, __func__); | |
7163 | break; | |
7164 | } | |
7165 | ||
7166 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
7167 | if (!raid_device) { | |
7168 | pr_err(MPT3SAS_FMT | |
7169 | "failure at %s:%d/%s()!\n", ioc->name, | |
7170 | __FILE__, __LINE__, __func__); | |
7171 | break; | |
7172 | } | |
7173 | ||
7174 | raid_device->id = ioc->sas_id++; | |
7175 | raid_device->channel = RAID_CHANNEL; | |
7176 | raid_device->handle = handle; | |
7177 | raid_device->wwid = wwid; | |
7178 | _scsih_raid_device_add(ioc, raid_device); | |
7179 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7180 | raid_device->id, 0); | |
7181 | if (rc) | |
7182 | _scsih_raid_device_remove(ioc, raid_device); | |
7183 | break; | |
7184 | ||
7185 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
7186 | default: | |
7187 | break; | |
7188 | } | |
7189 | } | |
7190 | ||
7191 | /** | |
7192 | * _scsih_sas_ir_physical_disk_event - PD event | |
7193 | * @ioc: per adapter object | |
7194 | * @fw_event: The fw_event_work object | |
7195 | * Context: user. | |
7196 | * | |
7197 | * Return nothing. | |
7198 | */ | |
7199 | static void | |
7200 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
7201 | struct fw_event_work *fw_event) | |
7202 | { | |
7203 | u16 handle, parent_handle; | |
7204 | u32 state; | |
7205 | struct _sas_device *sas_device; | |
f92363d1 SR |
7206 | Mpi2ConfigReply_t mpi_reply; |
7207 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7208 | u32 ioc_status; | |
35b62362 JL |
7209 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
7210 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
7211 | u64 sas_address; |
7212 | ||
7213 | if (ioc->shost_recovery) | |
7214 | return; | |
7215 | ||
7216 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
7217 | return; | |
7218 | ||
7219 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
7220 | state = le32_to_cpu(event_data->NewValue); | |
7221 | ||
7786ab6a SR |
7222 | if (!ioc->hide_ir_msg) |
7223 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7224 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
7225 | ioc->name, __func__, handle, | |
f92363d1 | 7226 | le32_to_cpu(event_data->PreviousValue), state)); |
7786ab6a | 7227 | |
f92363d1 SR |
7228 | switch (state) { |
7229 | case MPI2_RAID_PD_STATE_ONLINE: | |
7230 | case MPI2_RAID_PD_STATE_DEGRADED: | |
7231 | case MPI2_RAID_PD_STATE_REBUILDING: | |
7232 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
7233 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
7234 | ||
7786ab6a SR |
7235 | if (!ioc->is_warpdrive) |
7236 | set_bit(handle, ioc->pd_handles); | |
f92363d1 | 7237 | |
d1cb5e49 SR |
7238 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
7239 | if (sas_device) { | |
7240 | sas_device_put(sas_device); | |
f92363d1 | 7241 | return; |
d1cb5e49 | 7242 | } |
f92363d1 SR |
7243 | |
7244 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
7245 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
7246 | handle))) { | |
7247 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7248 | ioc->name, __FILE__, __LINE__, __func__); | |
7249 | return; | |
7250 | } | |
7251 | ||
7252 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7253 | MPI2_IOCSTATUS_MASK; | |
7254 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7255 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7256 | ioc->name, __FILE__, __LINE__, __func__); | |
7257 | return; | |
7258 | } | |
7259 | ||
7260 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
7261 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
7262 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
7263 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
7264 | ||
7265 | _scsih_add_device(ioc, handle, 0, 1); | |
7266 | ||
7267 | break; | |
7268 | ||
7269 | case MPI2_RAID_PD_STATE_OFFLINE: | |
7270 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
7271 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
7272 | default: | |
7273 | break; | |
7274 | } | |
7275 | } | |
7276 | ||
f92363d1 SR |
7277 | /** |
7278 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
7279 | * @ioc: per adapter object | |
7280 | * @event_data: event data payload | |
7281 | * Context: user. | |
7282 | * | |
7283 | * Return nothing. | |
7284 | */ | |
7285 | static void | |
7286 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
7287 | Mpi2EventDataIrOperationStatus_t *event_data) | |
7288 | { | |
7289 | char *reason_str = NULL; | |
7290 | ||
7291 | switch (event_data->RAIDOperation) { | |
7292 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
7293 | reason_str = "resync"; | |
7294 | break; | |
7295 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
7296 | reason_str = "online capacity expansion"; | |
7297 | break; | |
7298 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
7299 | reason_str = "consistency check"; | |
7300 | break; | |
7301 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
7302 | reason_str = "background init"; | |
7303 | break; | |
7304 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
7305 | reason_str = "make data consistent"; | |
7306 | break; | |
7307 | } | |
7308 | ||
7309 | if (!reason_str) | |
7310 | return; | |
7311 | ||
7312 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
7313 | "\thandle(0x%04x), percent complete(%d)\n", | |
7314 | ioc->name, reason_str, | |
7315 | le16_to_cpu(event_data->VolDevHandle), | |
7316 | event_data->PercentComplete); | |
7317 | } | |
f92363d1 SR |
7318 | |
7319 | /** | |
7320 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
7321 | * @ioc: per adapter object | |
7322 | * @fw_event: The fw_event_work object | |
7323 | * Context: user. | |
7324 | * | |
7325 | * Return nothing. | |
7326 | */ | |
7327 | static void | |
7328 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
7329 | struct fw_event_work *fw_event) | |
7330 | { | |
35b62362 JL |
7331 | Mpi2EventDataIrOperationStatus_t *event_data = |
7332 | (Mpi2EventDataIrOperationStatus_t *) | |
7333 | fw_event->event_data; | |
f92363d1 SR |
7334 | static struct _raid_device *raid_device; |
7335 | unsigned long flags; | |
7336 | u16 handle; | |
7337 | ||
7786ab6a SR |
7338 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) && |
7339 | (!ioc->hide_ir_msg)) | |
f92363d1 SR |
7340 | _scsih_sas_ir_operation_status_event_debug(ioc, |
7341 | event_data); | |
f92363d1 SR |
7342 | |
7343 | /* code added for raid transport support */ | |
7344 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
7345 | ||
7346 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7347 | handle = le16_to_cpu(event_data->VolDevHandle); | |
c84b06a4 | 7348 | raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle); |
f92363d1 SR |
7349 | if (raid_device) |
7350 | raid_device->percent_complete = | |
7351 | event_data->PercentComplete; | |
7352 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7353 | } | |
7354 | } | |
7355 | ||
7356 | /** | |
7357 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
7358 | * @ioc: per adapter object | |
7359 | * | |
7360 | * Set the deleted flag prior to device scan. If the device is found during | |
7361 | * the scan, then we clear the deleted flag. | |
7362 | */ | |
7363 | static void | |
7364 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
7365 | { | |
7366 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
7367 | struct scsi_device *sdev; | |
7368 | ||
7369 | shost_for_each_device(sdev, ioc->shost) { | |
7370 | sas_device_priv_data = sdev->hostdata; | |
7371 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
7372 | sas_device_priv_data->sas_target->deleted = 1; | |
7373 | } | |
7374 | } | |
7375 | ||
7376 | /** | |
7377 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
7378 | * @ioc: per adapter object | |
e6d45e3e | 7379 | * @sas_device_pg0: SAS Device page 0 |
f92363d1 SR |
7380 | * |
7381 | * After host reset, find out whether devices are still responding. | |
7382 | * Used in _scsih_remove_unresponsive_sas_devices. | |
7383 | * | |
7384 | * Return nothing. | |
7385 | */ | |
7386 | static void | |
e6d45e3e SR |
7387 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, |
7388 | Mpi2SasDevicePage0_t *sas_device_pg0) | |
f92363d1 SR |
7389 | { |
7390 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
7391 | struct scsi_target *starget; | |
aba5a85c | 7392 | struct _sas_device *sas_device = NULL; |
f92363d1 SR |
7393 | unsigned long flags; |
7394 | ||
7395 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7396 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
e6d45e3e SR |
7397 | if ((sas_device->sas_address == sas_device_pg0->SASAddress) && |
7398 | (sas_device->slot == sas_device_pg0->Slot)) { | |
f92363d1 SR |
7399 | sas_device->responding = 1; |
7400 | starget = sas_device->starget; | |
7401 | if (starget && starget->hostdata) { | |
7402 | sas_target_priv_data = starget->hostdata; | |
7403 | sas_target_priv_data->tm_busy = 0; | |
7404 | sas_target_priv_data->deleted = 0; | |
7405 | } else | |
7406 | sas_target_priv_data = NULL; | |
e6d45e3e | 7407 | if (starget) { |
f92363d1 | 7408 | starget_printk(KERN_INFO, starget, |
e6d45e3e SR |
7409 | "handle(0x%04x), sas_addr(0x%016llx)\n", |
7410 | sas_device_pg0->DevHandle, | |
f92363d1 | 7411 | (unsigned long long) |
e6d45e3e SR |
7412 | sas_device->sas_address); |
7413 | ||
7414 | if (sas_device->enclosure_handle != 0) | |
7415 | starget_printk(KERN_INFO, starget, | |
7416 | "enclosure logical id(0x%016llx)," | |
7417 | " slot(%d)\n", | |
7418 | (unsigned long long) | |
7419 | sas_device->enclosure_logical_id, | |
7420 | sas_device->slot); | |
7421 | } | |
7422 | if (sas_device_pg0->Flags & | |
7423 | MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) { | |
7424 | sas_device->enclosure_level = | |
aa53bb89 | 7425 | sas_device_pg0->EnclosureLevel; |
e6d45e3e SR |
7426 | memcpy(&sas_device->connector_name[0], |
7427 | &sas_device_pg0->ConnectorName[0], 4); | |
7428 | } else { | |
7429 | sas_device->enclosure_level = 0; | |
7430 | sas_device->connector_name[0] = '\0'; | |
7431 | } | |
7432 | ||
aba5a85c SR |
7433 | _scsih_get_enclosure_logicalid_chassis_slot(ioc, |
7434 | sas_device_pg0, sas_device); | |
75888956 | 7435 | |
e6d45e3e | 7436 | if (sas_device->handle == sas_device_pg0->DevHandle) |
f92363d1 SR |
7437 | goto out; |
7438 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
7439 | sas_device->handle); | |
e6d45e3e | 7440 | sas_device->handle = sas_device_pg0->DevHandle; |
f92363d1 | 7441 | if (sas_target_priv_data) |
e6d45e3e SR |
7442 | sas_target_priv_data->handle = |
7443 | sas_device_pg0->DevHandle; | |
f92363d1 SR |
7444 | goto out; |
7445 | } | |
7446 | } | |
7447 | out: | |
7448 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7449 | } | |
7450 | ||
7451 | /** | |
7452 | * _scsih_search_responding_sas_devices - | |
7453 | * @ioc: per adapter object | |
7454 | * | |
7455 | * After host reset, find out whether devices are still responding. | |
7456 | * If not remove. | |
7457 | * | |
7458 | * Return nothing. | |
7459 | */ | |
7460 | static void | |
7461 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
7462 | { | |
7463 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7464 | Mpi2ConfigReply_t mpi_reply; | |
7465 | u16 ioc_status; | |
7466 | u16 handle; | |
7467 | u32 device_info; | |
7468 | ||
7469 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
7470 | ||
7471 | if (list_empty(&ioc->sas_device_list)) | |
7472 | goto out; | |
7473 | ||
7474 | handle = 0xFFFF; | |
7475 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
7476 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
7477 | handle))) { | |
7478 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7479 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 7480 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 | 7481 | break; |
e6d45e3e SR |
7482 | handle = sas_device_pg0.DevHandle = |
7483 | le16_to_cpu(sas_device_pg0.DevHandle); | |
f92363d1 SR |
7484 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
7485 | if (!(_scsih_is_end_device(device_info))) | |
7486 | continue; | |
e6d45e3e SR |
7487 | sas_device_pg0.SASAddress = |
7488 | le64_to_cpu(sas_device_pg0.SASAddress); | |
7489 | sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot); | |
aa53bb89 | 7490 | sas_device_pg0.Flags = le16_to_cpu(sas_device_pg0.Flags); |
e6d45e3e | 7491 | _scsih_mark_responding_sas_device(ioc, &sas_device_pg0); |
f92363d1 SR |
7492 | } |
7493 | ||
7494 | out: | |
7495 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
7496 | ioc->name); | |
7497 | } | |
7498 | ||
7499 | /** | |
7500 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
7501 | * @ioc: per adapter object | |
7502 | * @wwid: world wide identifier for raid volume | |
7503 | * @handle: device handle | |
7504 | * | |
7505 | * After host reset, find out whether devices are still responding. | |
7506 | * Used in _scsih_remove_unresponsive_raid_devices. | |
7507 | * | |
7508 | * Return nothing. | |
7509 | */ | |
7510 | static void | |
7511 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
7512 | u16 handle) | |
7513 | { | |
7786ab6a | 7514 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
f92363d1 SR |
7515 | struct scsi_target *starget; |
7516 | struct _raid_device *raid_device; | |
7517 | unsigned long flags; | |
7518 | ||
7519 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7520 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
7521 | if (raid_device->wwid == wwid && raid_device->starget) { | |
7522 | starget = raid_device->starget; | |
7523 | if (starget && starget->hostdata) { | |
7524 | sas_target_priv_data = starget->hostdata; | |
7525 | sas_target_priv_data->deleted = 0; | |
7526 | } else | |
7527 | sas_target_priv_data = NULL; | |
7528 | raid_device->responding = 1; | |
7529 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7530 | starget_printk(KERN_INFO, raid_device->starget, | |
7531 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
7532 | (unsigned long long)raid_device->wwid); | |
7786ab6a | 7533 | |
7786ab6a SR |
7534 | /* |
7535 | * WARPDRIVE: The handles of the PDs might have changed | |
7536 | * across the host reset so re-initialize the | |
7537 | * required data for Direct IO | |
7538 | */ | |
c84b06a4 | 7539 | mpt3sas_init_warpdrive_properties(ioc, raid_device); |
f92363d1 SR |
7540 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
7541 | if (raid_device->handle == handle) { | |
7542 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
7543 | flags); | |
7544 | return; | |
7545 | } | |
7546 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
7547 | raid_device->handle); | |
7548 | raid_device->handle = handle; | |
7549 | if (sas_target_priv_data) | |
7550 | sas_target_priv_data->handle = handle; | |
7551 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7552 | return; | |
7553 | } | |
7554 | } | |
7555 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7556 | } | |
7557 | ||
7558 | /** | |
7559 | * _scsih_search_responding_raid_devices - | |
7560 | * @ioc: per adapter object | |
7561 | * | |
7562 | * After host reset, find out whether devices are still responding. | |
7563 | * If not remove. | |
7564 | * | |
7565 | * Return nothing. | |
7566 | */ | |
7567 | static void | |
7568 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
7569 | { | |
7570 | Mpi2RaidVolPage1_t volume_pg1; | |
7571 | Mpi2RaidVolPage0_t volume_pg0; | |
7572 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
7573 | Mpi2ConfigReply_t mpi_reply; | |
7574 | u16 ioc_status; | |
7575 | u16 handle; | |
7576 | u8 phys_disk_num; | |
7577 | ||
7578 | if (!ioc->ir_firmware) | |
7579 | return; | |
7580 | ||
7581 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
7582 | ioc->name); | |
7583 | ||
7584 | if (list_empty(&ioc->raid_device_list)) | |
7585 | goto out; | |
7586 | ||
7587 | handle = 0xFFFF; | |
7588 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
7589 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
7590 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7591 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 7592 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
7593 | break; |
7594 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
7595 | ||
7596 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
7597 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
7598 | sizeof(Mpi2RaidVolPage0_t))) | |
7599 | continue; | |
7600 | ||
7601 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
7602 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
7603 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
7604 | _scsih_mark_responding_raid_device(ioc, | |
7605 | le64_to_cpu(volume_pg1.WWID), handle); | |
7606 | } | |
7607 | ||
7608 | /* refresh the pd_handles */ | |
7786ab6a | 7609 | if (!ioc->is_warpdrive) { |
f92363d1 SR |
7610 | phys_disk_num = 0xFF; |
7611 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
7612 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
7613 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
7614 | phys_disk_num))) { | |
7615 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7616 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 7617 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
7618 | break; |
7619 | phys_disk_num = pd_pg0.PhysDiskNum; | |
7620 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
7621 | set_bit(handle, ioc->pd_handles); | |
7622 | } | |
7786ab6a | 7623 | } |
f92363d1 SR |
7624 | out: |
7625 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
7626 | ioc->name); | |
7627 | } | |
7628 | ||
7629 | /** | |
7630 | * _scsih_mark_responding_expander - mark a expander as responding | |
7631 | * @ioc: per adapter object | |
aba5a85c | 7632 | * @expander_pg0:SAS Expander Config Page0 |
f92363d1 SR |
7633 | * |
7634 | * After host reset, find out whether devices are still responding. | |
7635 | * Used in _scsih_remove_unresponsive_expanders. | |
7636 | * | |
7637 | * Return nothing. | |
7638 | */ | |
7639 | static void | |
aba5a85c SR |
7640 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, |
7641 | Mpi2ExpanderPage0_t *expander_pg0) | |
f92363d1 | 7642 | { |
aba5a85c | 7643 | struct _sas_node *sas_expander = NULL; |
f92363d1 | 7644 | unsigned long flags; |
aba5a85c SR |
7645 | int i, encl_pg0_rc = -1; |
7646 | Mpi2ConfigReply_t mpi_reply; | |
7647 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
7648 | u16 handle = le16_to_cpu(expander_pg0->DevHandle); | |
7649 | u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); | |
7650 | ||
7651 | if (le16_to_cpu(expander_pg0->EnclosureHandle)) { | |
7652 | encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
7653 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
7654 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
7655 | if (encl_pg0_rc) | |
7656 | pr_info(MPT3SAS_FMT | |
7657 | "Enclosure Pg0 read failed for handle(0x%04x)\n", | |
7658 | ioc->name, | |
7659 | le16_to_cpu(expander_pg0->EnclosureHandle)); | |
7660 | } | |
f92363d1 SR |
7661 | |
7662 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
7663 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
7664 | if (sas_expander->sas_address != sas_address) | |
7665 | continue; | |
7666 | sas_expander->responding = 1; | |
aba5a85c SR |
7667 | |
7668 | if (!encl_pg0_rc) | |
7669 | sas_expander->enclosure_logical_id = | |
7670 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
7671 | ||
7672 | sas_expander->enclosure_handle = | |
7673 | le16_to_cpu(expander_pg0->EnclosureHandle); | |
7674 | ||
f92363d1 SR |
7675 | if (sas_expander->handle == handle) |
7676 | goto out; | |
7677 | pr_info("\texpander(0x%016llx): handle changed" \ | |
7678 | " from(0x%04x) to (0x%04x)!!!\n", | |
7679 | (unsigned long long)sas_expander->sas_address, | |
7680 | sas_expander->handle, handle); | |
7681 | sas_expander->handle = handle; | |
7682 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
7683 | sas_expander->phy[i].handle = handle; | |
7684 | goto out; | |
7685 | } | |
7686 | out: | |
7687 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
7688 | } | |
7689 | ||
7690 | /** | |
7691 | * _scsih_search_responding_expanders - | |
7692 | * @ioc: per adapter object | |
7693 | * | |
7694 | * After host reset, find out whether devices are still responding. | |
7695 | * If not remove. | |
7696 | * | |
7697 | * Return nothing. | |
7698 | */ | |
7699 | static void | |
7700 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
7701 | { | |
7702 | Mpi2ExpanderPage0_t expander_pg0; | |
7703 | Mpi2ConfigReply_t mpi_reply; | |
7704 | u16 ioc_status; | |
7705 | u64 sas_address; | |
7706 | u16 handle; | |
7707 | ||
7708 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
7709 | ||
7710 | if (list_empty(&ioc->sas_expander_list)) | |
7711 | goto out; | |
7712 | ||
7713 | handle = 0xFFFF; | |
7714 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
7715 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
7716 | ||
7717 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7718 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 7719 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
7720 | break; |
7721 | ||
7722 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
7723 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
7724 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
7725 | handle, | |
7726 | (unsigned long long)sas_address); | |
aba5a85c | 7727 | _scsih_mark_responding_expander(ioc, &expander_pg0); |
f92363d1 SR |
7728 | } |
7729 | ||
7730 | out: | |
7731 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
7732 | } | |
7733 | ||
7734 | /** | |
7735 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices | |
7736 | * @ioc: per adapter object | |
7737 | * | |
7738 | * Return nothing. | |
7739 | */ | |
7740 | static void | |
7741 | _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
7742 | { | |
7743 | struct _sas_device *sas_device, *sas_device_next; | |
7744 | struct _sas_node *sas_expander, *sas_expander_next; | |
7745 | struct _raid_device *raid_device, *raid_device_next; | |
7746 | struct list_head tmp_list; | |
7747 | unsigned long flags; | |
d1cb5e49 | 7748 | LIST_HEAD(head); |
f92363d1 SR |
7749 | |
7750 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
7751 | ioc->name); | |
7752 | ||
7753 | /* removing unresponding end devices */ | |
7754 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
7755 | ioc->name); | |
d1cb5e49 SR |
7756 | /* |
7757 | * Iterate, pulling off devices marked as non-responding. We become the | |
7758 | * owner for the reference the list had on any object we prune. | |
7759 | */ | |
7760 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
f92363d1 SR |
7761 | list_for_each_entry_safe(sas_device, sas_device_next, |
7762 | &ioc->sas_device_list, list) { | |
7763 | if (!sas_device->responding) | |
d1cb5e49 | 7764 | list_move_tail(&sas_device->list, &head); |
f92363d1 SR |
7765 | else |
7766 | sas_device->responding = 0; | |
7767 | } | |
d1cb5e49 SR |
7768 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
7769 | ||
7770 | /* | |
7771 | * Now, uninitialize and remove the unresponding devices we pruned. | |
7772 | */ | |
7773 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | |
7774 | _scsih_remove_device(ioc, sas_device); | |
7775 | list_del_init(&sas_device->list); | |
7776 | sas_device_put(sas_device); | |
7777 | } | |
f92363d1 SR |
7778 | |
7779 | /* removing unresponding volumes */ | |
7780 | if (ioc->ir_firmware) { | |
7781 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
7782 | ioc->name); | |
7783 | list_for_each_entry_safe(raid_device, raid_device_next, | |
7784 | &ioc->raid_device_list, list) { | |
7785 | if (!raid_device->responding) | |
7786 | _scsih_sas_volume_delete(ioc, | |
7787 | raid_device->handle); | |
7788 | else | |
7789 | raid_device->responding = 0; | |
7790 | } | |
7791 | } | |
7792 | ||
7793 | /* removing unresponding expanders */ | |
7794 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
7795 | ioc->name); | |
7796 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
7797 | INIT_LIST_HEAD(&tmp_list); | |
7798 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
7799 | &ioc->sas_expander_list, list) { | |
7800 | if (!sas_expander->responding) | |
7801 | list_move_tail(&sas_expander->list, &tmp_list); | |
7802 | else | |
7803 | sas_expander->responding = 0; | |
7804 | } | |
7805 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
7806 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
7807 | list) { | |
f92363d1 SR |
7808 | _scsih_expander_node_remove(ioc, sas_expander); |
7809 | } | |
7810 | ||
7811 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
7812 | ioc->name); | |
7813 | ||
7814 | /* unblock devices */ | |
7815 | _scsih_ublock_io_all_device(ioc); | |
7816 | } | |
7817 | ||
7818 | static void | |
7819 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
7820 | struct _sas_node *sas_expander, u16 handle) | |
7821 | { | |
7822 | Mpi2ExpanderPage1_t expander_pg1; | |
7823 | Mpi2ConfigReply_t mpi_reply; | |
7824 | int i; | |
7825 | ||
7826 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
7827 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
7828 | &expander_pg1, i, handle))) { | |
7829 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7830 | ioc->name, __FILE__, __LINE__, __func__); | |
7831 | return; | |
7832 | } | |
7833 | ||
7834 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
7835 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
7836 | expander_pg1.NegotiatedLinkRate >> 4); | |
7837 | } | |
7838 | } | |
7839 | ||
7840 | /** | |
7841 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
7842 | * @ioc: per adapter object | |
7843 | * | |
7844 | * Return nothing. | |
7845 | */ | |
7846 | static void | |
7847 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
7848 | { | |
7849 | Mpi2ExpanderPage0_t expander_pg0; | |
7850 | Mpi2SasDevicePage0_t sas_device_pg0; | |
7851 | Mpi2RaidVolPage1_t volume_pg1; | |
7852 | Mpi2RaidVolPage0_t volume_pg0; | |
7853 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
7854 | Mpi2EventIrConfigElement_t element; | |
7855 | Mpi2ConfigReply_t mpi_reply; | |
7856 | u8 phys_disk_num; | |
7857 | u16 ioc_status; | |
7858 | u16 handle, parent_handle; | |
7859 | u64 sas_address; | |
7860 | struct _sas_device *sas_device; | |
7861 | struct _sas_node *expander_device; | |
7862 | static struct _raid_device *raid_device; | |
7863 | u8 retry_count; | |
7864 | unsigned long flags; | |
7865 | ||
7866 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
7867 | ||
7868 | _scsih_sas_host_refresh(ioc); | |
7869 | ||
7870 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
7871 | ||
7872 | /* expanders */ | |
7873 | handle = 0xFFFF; | |
7874 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
7875 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
7876 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7877 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7878 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7879 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
7880 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7881 | ioc->name, ioc_status, | |
7882 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7883 | break; | |
7884 | } | |
7885 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
7886 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
7887 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
7888 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
7889 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
7890 | if (expander_device) | |
7891 | _scsih_refresh_expander_links(ioc, expander_device, | |
7892 | handle); | |
7893 | else { | |
7894 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
7895 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
7896 | handle, (unsigned long long) | |
7897 | le64_to_cpu(expander_pg0.SASAddress)); | |
7898 | _scsih_expander_add(ioc, handle); | |
7899 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
7900 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
7901 | handle, (unsigned long long) | |
7902 | le64_to_cpu(expander_pg0.SASAddress)); | |
7903 | } | |
7904 | } | |
7905 | ||
7906 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
7907 | ioc->name); | |
7908 | ||
7909 | if (!ioc->ir_firmware) | |
7910 | goto skip_to_sas; | |
7911 | ||
7912 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
7913 | ||
7914 | /* phys disk */ | |
7915 | phys_disk_num = 0xFF; | |
7916 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
7917 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
7918 | phys_disk_num))) { | |
7919 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7920 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7921 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7922 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
7923 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7924 | ioc->name, ioc_status, | |
7925 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7926 | break; | |
7927 | } | |
7928 | phys_disk_num = pd_pg0.PhysDiskNum; | |
7929 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
d1cb5e49 SR |
7930 | sas_device = mpt3sas_get_sdev_by_handle(ioc, handle); |
7931 | if (sas_device) { | |
7932 | sas_device_put(sas_device); | |
f92363d1 | 7933 | continue; |
d1cb5e49 | 7934 | } |
f92363d1 SR |
7935 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
7936 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
7937 | handle) != 0) | |
7938 | continue; | |
7939 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7940 | MPI2_IOCSTATUS_MASK; | |
7941 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
7942 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
7943 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7944 | ioc->name, ioc_status, | |
7945 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7946 | break; | |
7947 | } | |
7948 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
7949 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
7950 | &sas_address)) { | |
7951 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
7952 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
7953 | ioc->name, handle, (unsigned long long) | |
7954 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7955 | mpt3sas_transport_update_links(ioc, sas_address, | |
7956 | handle, sas_device_pg0.PhyNum, | |
7957 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
7958 | set_bit(handle, ioc->pd_handles); | |
7959 | retry_count = 0; | |
7960 | /* This will retry adding the end device. | |
7961 | * _scsih_add_device() will decide on retries and | |
7962 | * return "1" when it should be retried | |
7963 | */ | |
7964 | while (_scsih_add_device(ioc, handle, retry_count++, | |
7965 | 1)) { | |
7966 | ssleep(1); | |
7967 | } | |
7968 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
7969 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
7970 | ioc->name, handle, (unsigned long long) | |
7971 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
7972 | } | |
7973 | } | |
7974 | ||
7975 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
7976 | ioc->name); | |
7977 | ||
7978 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
7979 | ||
7980 | /* volumes */ | |
7981 | handle = 0xFFFF; | |
7982 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
7983 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
7984 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
7985 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
7986 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
7987 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
7988 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7989 | ioc->name, ioc_status, | |
7990 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
7991 | break; | |
7992 | } | |
7993 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
7994 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
7995 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
7996 | le64_to_cpu(volume_pg1.WWID)); | |
7997 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
7998 | if (raid_device) | |
7999 | continue; | |
8000 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
8001 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
8002 | sizeof(Mpi2RaidVolPage0_t))) | |
8003 | continue; | |
8004 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8005 | MPI2_IOCSTATUS_MASK; | |
8006 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
8007 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
8008 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
8009 | ioc->name, ioc_status, | |
8010 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
8011 | break; | |
8012 | } | |
8013 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
8014 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
8015 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
8016 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
8017 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
8018 | element.VolDevHandle = volume_pg1.DevHandle; | |
8019 | pr_info(MPT3SAS_FMT | |
8020 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
8021 | ioc->name, volume_pg1.DevHandle); | |
8022 | _scsih_sas_volume_add(ioc, &element); | |
8023 | pr_info(MPT3SAS_FMT | |
8024 | "\tAFTER adding volume: handle (0x%04x)\n", | |
8025 | ioc->name, volume_pg1.DevHandle); | |
8026 | } | |
8027 | } | |
8028 | ||
8029 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
8030 | ioc->name); | |
8031 | ||
8032 | skip_to_sas: | |
8033 | ||
8034 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
8035 | ioc->name); | |
8036 | ||
8037 | /* sas devices */ | |
8038 | handle = 0xFFFF; | |
8039 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
8040 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
8041 | handle))) { | |
8042 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
8043 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
8044 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
8045 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
8046 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
8047 | ioc->name, ioc_status, | |
8048 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
8049 | break; | |
8050 | } | |
8051 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
8052 | if (!(_scsih_is_end_device( | |
8053 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
8054 | continue; | |
d1cb5e49 | 8055 | sas_device = mpt3sas_get_sdev_by_addr(ioc, |
f92363d1 | 8056 | le64_to_cpu(sas_device_pg0.SASAddress)); |
d1cb5e49 SR |
8057 | if (sas_device) { |
8058 | sas_device_put(sas_device); | |
f92363d1 | 8059 | continue; |
d1cb5e49 | 8060 | } |
f92363d1 SR |
8061 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
8062 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
8063 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
8064 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
8065 | handle, (unsigned long long) | |
8066 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
8067 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
8068 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
8069 | retry_count = 0; | |
8070 | /* This will retry adding the end device. | |
8071 | * _scsih_add_device() will decide on retries and | |
8072 | * return "1" when it should be retried | |
8073 | */ | |
8074 | while (_scsih_add_device(ioc, handle, retry_count++, | |
8075 | 0)) { | |
8076 | ssleep(1); | |
8077 | } | |
8078 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
8079 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
8080 | handle, (unsigned long long) | |
8081 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
8082 | } | |
8083 | } | |
8084 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
8085 | ioc->name); | |
8086 | ||
8087 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); | |
8088 | } | |
8089 | /** | |
8090 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
8091 | * @ioc: per adapter object | |
8092 | * @reset_phase: phase | |
8093 | * | |
8094 | * The handler for doing any required cleanup or initialization. | |
8095 | * | |
8096 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
8097 | * MPT3_IOC_DONE_RESET | |
8098 | * | |
8099 | * Return nothing. | |
8100 | */ | |
8101 | void | |
8102 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
8103 | { | |
8104 | switch (reset_phase) { | |
8105 | case MPT3_IOC_PRE_RESET: | |
8106 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
8107 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
8108 | break; | |
8109 | case MPT3_IOC_AFTER_RESET: | |
8110 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
8111 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
8112 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
8113 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
8114 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
8115 | complete(&ioc->scsih_cmds.done); | |
8116 | } | |
8117 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
8118 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
8119 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
8120 | complete(&ioc->tm_cmds.done); | |
8121 | } | |
8122 | ||
c696f7b8 SPS |
8123 | memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz); |
8124 | memset(ioc->device_remove_in_progress, 0, | |
8125 | ioc->device_remove_in_progress_sz); | |
f92363d1 SR |
8126 | _scsih_fw_event_cleanup_queue(ioc); |
8127 | _scsih_flush_running_cmds(ioc); | |
8128 | break; | |
8129 | case MPT3_IOC_DONE_RESET: | |
8130 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
8131 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
8132 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
8133 | !ioc->sas_hba.num_phys)) { | |
8134 | _scsih_prep_device_scan(ioc); | |
8135 | _scsih_search_responding_sas_devices(ioc); | |
8136 | _scsih_search_responding_raid_devices(ioc); | |
8137 | _scsih_search_responding_expanders(ioc); | |
8138 | _scsih_error_recovery_delete_devices(ioc); | |
8139 | } | |
8140 | break; | |
8141 | } | |
8142 | } | |
8143 | ||
8144 | /** | |
8145 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
8146 | * @ioc: per adapter object | |
8147 | * @fw_event: The fw_event_work object | |
8148 | * Context: user. | |
8149 | * | |
8150 | * Return nothing. | |
8151 | */ | |
8152 | static void | |
8153 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
8154 | { | |
146b16c8 SR |
8155 | _scsih_fw_event_del_from_list(ioc, fw_event); |
8156 | ||
f92363d1 | 8157 | /* the queue is being flushed so ignore this event */ |
146b16c8 SR |
8158 | if (ioc->remove_host || ioc->pci_error_recovery) { |
8159 | fw_event_work_put(fw_event); | |
f92363d1 SR |
8160 | return; |
8161 | } | |
8162 | ||
8163 | switch (fw_event->event) { | |
8164 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
8165 | mpt3sas_process_trigger_data(ioc, |
8166 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
8167 | fw_event->event_data); | |
f92363d1 SR |
8168 | break; |
8169 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
146b16c8 SR |
8170 | while (scsi_host_in_recovery(ioc->shost) || |
8171 | ioc->shost_recovery) { | |
8172 | /* | |
8173 | * If we're unloading, bail. Otherwise, this can become | |
8174 | * an infinite loop. | |
8175 | */ | |
8176 | if (ioc->remove_host) | |
8177 | goto out; | |
f92363d1 | 8178 | ssleep(1); |
146b16c8 | 8179 | } |
f92363d1 SR |
8180 | _scsih_remove_unresponding_sas_devices(ioc); |
8181 | _scsih_scan_for_devices_after_reset(ioc); | |
8182 | break; | |
8183 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
8184 | ioc->start_scan = 0; | |
8185 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | |
8186 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], | |
8187 | missing_delay[1]); | |
8188 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
8189 | "port enable: complete from worker thread\n", | |
8190 | ioc->name)); | |
8191 | break; | |
0f624c39 SR |
8192 | case MPT3SAS_TURN_ON_PFA_LED: |
8193 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | |
f92363d1 SR |
8194 | break; |
8195 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
8196 | _scsih_sas_topology_change_event(ioc, fw_event); | |
8197 | break; | |
8198 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
8199 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
8200 | break; | |
8201 | case MPI2_EVENT_SAS_DISCOVERY: | |
8202 | _scsih_sas_discovery_event(ioc, fw_event); | |
8203 | break; | |
8204 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
8205 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
8206 | break; | |
8207 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
8208 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
8209 | fw_event); | |
8210 | break; | |
8211 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
8212 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
8213 | break; | |
8214 | case MPI2_EVENT_IR_VOLUME: | |
8215 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
8216 | break; | |
8217 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
8218 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
8219 | break; | |
8220 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
8221 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
8222 | break; | |
8223 | } | |
146b16c8 SR |
8224 | out: |
8225 | fw_event_work_put(fw_event); | |
f92363d1 SR |
8226 | } |
8227 | ||
8228 | /** | |
8229 | * _firmware_event_work | |
8230 | * @ioc: per adapter object | |
8231 | * @work: The fw_event_work object | |
8232 | * Context: user. | |
8233 | * | |
8234 | * wrappers for the work thread handling firmware events | |
8235 | * | |
8236 | * Return nothing. | |
8237 | */ | |
8238 | ||
8239 | static void | |
8240 | _firmware_event_work(struct work_struct *work) | |
8241 | { | |
8242 | struct fw_event_work *fw_event = container_of(work, | |
8243 | struct fw_event_work, work); | |
8244 | ||
8245 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
8246 | } | |
8247 | ||
8248 | /** | |
8249 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
8250 | * @ioc: per adapter object | |
8251 | * @msix_index: MSIX table index supplied by the OS | |
8252 | * @reply: reply message frame(lower 32bit addr) | |
8253 | * Context: interrupt. | |
8254 | * | |
8255 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
8256 | * The tasks are worked from _firmware_event_work in user context. | |
8257 | * | |
8258 | * Return 1 meaning mf should be freed from _base_interrupt | |
8259 | * 0 means the mf is freed from this function. | |
8260 | */ | |
8261 | u8 | |
8262 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
8263 | u32 reply) | |
8264 | { | |
8265 | struct fw_event_work *fw_event; | |
8266 | Mpi2EventNotificationReply_t *mpi_reply; | |
8267 | u16 event; | |
8268 | u16 sz; | |
a470a51c | 8269 | Mpi26EventDataActiveCableExcept_t *ActiveCableEventData; |
f92363d1 SR |
8270 | |
8271 | /* events turned off due to host reset or driver unloading */ | |
8272 | if (ioc->remove_host || ioc->pci_error_recovery) | |
8273 | return 1; | |
8274 | ||
8275 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
8276 | ||
8277 | if (unlikely(!mpi_reply)) { | |
8278 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
8279 | ioc->name, __FILE__, __LINE__, __func__); | |
8280 | return 1; | |
8281 | } | |
8282 | ||
8283 | event = le16_to_cpu(mpi_reply->Event); | |
8284 | ||
8285 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
8286 | mpt3sas_trigger_event(ioc, event, 0); | |
8287 | ||
8288 | switch (event) { | |
8289 | /* handle these */ | |
8290 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
8291 | { | |
8292 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
8293 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
8294 | mpi_reply->EventData; | |
8295 | ||
8296 | if (baen_data->Primitive != | |
8297 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
8298 | return 1; | |
8299 | ||
8300 | if (ioc->broadcast_aen_busy) { | |
8301 | ioc->broadcast_aen_pending++; | |
8302 | return 1; | |
8303 | } else | |
8304 | ioc->broadcast_aen_busy = 1; | |
8305 | break; | |
8306 | } | |
8307 | ||
8308 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
8309 | _scsih_check_topo_delete_events(ioc, | |
8310 | (Mpi2EventDataSasTopologyChangeList_t *) | |
8311 | mpi_reply->EventData); | |
8312 | break; | |
8313 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
8314 | _scsih_check_ir_config_unhide_events(ioc, | |
8315 | (Mpi2EventDataIrConfigChangeList_t *) | |
8316 | mpi_reply->EventData); | |
8317 | break; | |
8318 | case MPI2_EVENT_IR_VOLUME: | |
8319 | _scsih_check_volume_delete_events(ioc, | |
8320 | (Mpi2EventDataIrVolume_t *) | |
8321 | mpi_reply->EventData); | |
8322 | break; | |
7786ab6a SR |
8323 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
8324 | { | |
8325 | Mpi2EventDataLogEntryAdded_t *log_entry; | |
8326 | u32 *log_code; | |
8327 | ||
8328 | if (!ioc->is_warpdrive) | |
8329 | break; | |
8330 | ||
8331 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | |
8332 | mpi_reply->EventData; | |
8333 | log_code = (u32 *)log_entry->LogData; | |
f92363d1 | 8334 | |
7786ab6a SR |
8335 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
8336 | != MPT2_WARPDRIVE_LOGENTRY) | |
8337 | break; | |
8338 | ||
8339 | switch (le32_to_cpu(*log_code)) { | |
8340 | case MPT2_WARPDRIVE_LC_SSDT: | |
8341 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
8342 | "IO Throttling has occurred in the WarpDrive " | |
8343 | "subsystem. Check WarpDrive documentation for " | |
8344 | "additional details.\n", ioc->name); | |
8345 | break; | |
8346 | case MPT2_WARPDRIVE_LC_SSDLW: | |
8347 | pr_warn(MPT3SAS_FMT "WarpDrive Warning: " | |
8348 | "Program/Erase Cycles for the WarpDrive subsystem " | |
8349 | "in degraded range. Check WarpDrive documentation " | |
8350 | "for additional details.\n", ioc->name); | |
8351 | break; | |
8352 | case MPT2_WARPDRIVE_LC_SSDLF: | |
8353 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
8354 | "There are no Program/Erase Cycles for the " | |
8355 | "WarpDrive subsystem. The storage device will be " | |
8356 | "in read-only mode. Check WarpDrive documentation " | |
8357 | "for additional details.\n", ioc->name); | |
8358 | break; | |
8359 | case MPT2_WARPDRIVE_LC_BRMF: | |
8360 | pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: " | |
8361 | "The Backup Rail Monitor has failed on the " | |
8362 | "WarpDrive subsystem. Check WarpDrive " | |
8363 | "documentation for additional details.\n", | |
8364 | ioc->name); | |
8365 | break; | |
8366 | } | |
8367 | ||
8368 | break; | |
8369 | } | |
f92363d1 SR |
8370 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
8371 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
8372 | case MPI2_EVENT_SAS_DISCOVERY: | |
8373 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
8374 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
8375 | break; | |
8376 | ||
2d8ce8c9 SR |
8377 | case MPI2_EVENT_TEMP_THRESHOLD: |
8378 | _scsih_temp_threshold_events(ioc, | |
8379 | (Mpi2EventDataTemperature_t *) | |
8380 | mpi_reply->EventData); | |
8381 | break; | |
a470a51c C |
8382 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
8383 | ActiveCableEventData = | |
8384 | (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData; | |
6c44c0fe C |
8385 | switch (ActiveCableEventData->ReasonCode) { |
8386 | case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER: | |
b99b1993 SR |
8387 | pr_notice(MPT3SAS_FMT |
8388 | "Currently an active cable with ReceptacleID %d\n", | |
8389 | ioc->name, ActiveCableEventData->ReceptacleID); | |
8390 | pr_notice("cannot be powered and devices connected\n"); | |
8391 | pr_notice("to this active cable will not be seen\n"); | |
8392 | pr_notice("This active cable requires %d mW of power\n", | |
6c44c0fe | 8393 | ActiveCableEventData->ActiveCablePowerRequirement); |
6c44c0fe C |
8394 | break; |
8395 | ||
8396 | case MPI26_EVENT_ACTIVE_CABLE_DEGRADED: | |
b99b1993 SR |
8397 | pr_notice(MPT3SAS_FMT |
8398 | "Currently a cable with ReceptacleID %d\n", | |
8399 | ioc->name, ActiveCableEventData->ReceptacleID); | |
8400 | pr_notice( | |
8401 | "is not running at optimal speed(12 Gb/s rate)\n"); | |
6c44c0fe | 8402 | break; |
7ebd67e0 | 8403 | } |
6c44c0fe | 8404 | |
a470a51c | 8405 | break; |
2d8ce8c9 | 8406 | |
f92363d1 SR |
8407 | default: /* ignore the rest */ |
8408 | return 1; | |
8409 | } | |
8410 | ||
f92363d1 | 8411 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
146b16c8 | 8412 | fw_event = alloc_fw_event_work(sz); |
35b62362 | 8413 | if (!fw_event) { |
f92363d1 SR |
8414 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
8415 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
8416 | return 1; |
8417 | } | |
8418 | ||
8419 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
8420 | fw_event->ioc = ioc; | |
8421 | fw_event->VF_ID = mpi_reply->VF_ID; | |
8422 | fw_event->VP_ID = mpi_reply->VP_ID; | |
8423 | fw_event->event = event; | |
8424 | _scsih_fw_event_add(ioc, fw_event); | |
146b16c8 | 8425 | fw_event_work_put(fw_event); |
f92363d1 SR |
8426 | return 1; |
8427 | } | |
8428 | ||
f92363d1 SR |
8429 | /** |
8430 | * _scsih_expander_node_remove - removing expander device from list. | |
8431 | * @ioc: per adapter object | |
8432 | * @sas_expander: the sas_device object | |
f92363d1 SR |
8433 | * |
8434 | * Removing object and freeing associated memory from the | |
8435 | * ioc->sas_expander_list. | |
8436 | * | |
8437 | * Return nothing. | |
8438 | */ | |
8439 | static void | |
8440 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
8441 | struct _sas_node *sas_expander) | |
8442 | { | |
8443 | struct _sas_port *mpt3sas_port, *next; | |
bbe3def3 | 8444 | unsigned long flags; |
f92363d1 SR |
8445 | |
8446 | /* remove sibling ports attached to this expander */ | |
8447 | list_for_each_entry_safe(mpt3sas_port, next, | |
8448 | &sas_expander->sas_port_list, port_list) { | |
8449 | if (ioc->shost_recovery) | |
8450 | return; | |
8451 | if (mpt3sas_port->remote_identify.device_type == | |
8452 | SAS_END_DEVICE) | |
8453 | mpt3sas_device_remove_by_sas_address(ioc, | |
8454 | mpt3sas_port->remote_identify.sas_address); | |
8455 | else if (mpt3sas_port->remote_identify.device_type == | |
8456 | SAS_EDGE_EXPANDER_DEVICE || | |
8457 | mpt3sas_port->remote_identify.device_type == | |
8458 | SAS_FANOUT_EXPANDER_DEVICE) | |
8459 | mpt3sas_expander_remove(ioc, | |
8460 | mpt3sas_port->remote_identify.sas_address); | |
8461 | } | |
8462 | ||
8463 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
8464 | sas_expander->sas_address_parent); | |
8465 | ||
8466 | pr_info(MPT3SAS_FMT | |
8467 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
8468 | ioc->name, | |
8469 | sas_expander->handle, (unsigned long long) | |
8470 | sas_expander->sas_address); | |
8471 | ||
bbe3def3 SR |
8472 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
8473 | list_del(&sas_expander->list); | |
8474 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
8475 | ||
f92363d1 SR |
8476 | kfree(sas_expander->phy); |
8477 | kfree(sas_expander); | |
8478 | } | |
8479 | ||
8480 | /** | |
8481 | * _scsih_ir_shutdown - IR shutdown notification | |
8482 | * @ioc: per adapter object | |
8483 | * | |
8484 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
8485 | * the host system is shutting down. | |
8486 | * | |
8487 | * Return nothing. | |
8488 | */ | |
8489 | static void | |
8490 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
8491 | { | |
8492 | Mpi2RaidActionRequest_t *mpi_request; | |
8493 | Mpi2RaidActionReply_t *mpi_reply; | |
8494 | u16 smid; | |
8495 | ||
8496 | /* is IR firmware build loaded ? */ | |
8497 | if (!ioc->ir_firmware) | |
8498 | return; | |
8499 | ||
8500 | /* are there any volumes ? */ | |
8501 | if (list_empty(&ioc->raid_device_list)) | |
8502 | return; | |
8503 | ||
8504 | mutex_lock(&ioc->scsih_cmds.mutex); | |
8505 | ||
8506 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
8507 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
8508 | ioc->name, __func__); | |
8509 | goto out; | |
8510 | } | |
8511 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
8512 | ||
8513 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
8514 | if (!smid) { | |
8515 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
8516 | ioc->name, __func__); | |
8517 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
8518 | goto out; | |
8519 | } | |
8520 | ||
8521 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
8522 | ioc->scsih_cmds.smid = smid; | |
8523 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
8524 | ||
8525 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
8526 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
8527 | ||
7786ab6a SR |
8528 | if (!ioc->hide_ir_msg) |
8529 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
f92363d1 | 8530 | init_completion(&ioc->scsih_cmds.done); |
81c16f83 | 8531 | ioc->put_smid_default(ioc, smid); |
f92363d1 SR |
8532 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
8533 | ||
8534 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
8535 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
8536 | ioc->name, __func__); | |
8537 | goto out; | |
8538 | } | |
8539 | ||
8540 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
8541 | mpi_reply = ioc->scsih_cmds.reply; | |
7786ab6a SR |
8542 | if (!ioc->hide_ir_msg) |
8543 | pr_info(MPT3SAS_FMT "IR shutdown " | |
8544 | "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
8545 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
8546 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
f92363d1 SR |
8547 | } |
8548 | ||
8549 | out: | |
8550 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
8551 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
8552 | } | |
8553 | ||
8554 | /** | |
8a7e4c24 | 8555 | * scsih_remove - detach and remove add host |
f92363d1 SR |
8556 | * @pdev: PCI device struct |
8557 | * | |
8558 | * Routine called when unloading the driver. | |
8559 | * Return nothing. | |
8560 | */ | |
8bbb1cf6 | 8561 | static void scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
8562 | { |
8563 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8564 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8565 | struct _sas_port *mpt3sas_port, *next_port; | |
8566 | struct _raid_device *raid_device, *next; | |
8567 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
8568 | struct workqueue_struct *wq; | |
8569 | unsigned long flags; | |
8570 | ||
8571 | ioc->remove_host = 1; | |
8572 | _scsih_fw_event_cleanup_queue(ioc); | |
8573 | ||
8574 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
8575 | wq = ioc->firmware_event_thread; | |
8576 | ioc->firmware_event_thread = NULL; | |
8577 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
8578 | if (wq) | |
8579 | destroy_workqueue(wq); | |
8580 | ||
8581 | /* release all the volumes */ | |
8582 | _scsih_ir_shutdown(ioc); | |
8583 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
8584 | list) { | |
8585 | if (raid_device->starget) { | |
8586 | sas_target_priv_data = | |
8587 | raid_device->starget->hostdata; | |
8588 | sas_target_priv_data->deleted = 1; | |
8589 | scsi_remove_target(&raid_device->starget->dev); | |
8590 | } | |
8591 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
8592 | ioc->name, raid_device->handle, | |
8593 | (unsigned long long) raid_device->wwid); | |
8594 | _scsih_raid_device_remove(ioc, raid_device); | |
8595 | } | |
8596 | ||
8597 | /* free ports attached to the sas_host */ | |
8598 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
8599 | &ioc->sas_hba.sas_port_list, port_list) { | |
8600 | if (mpt3sas_port->remote_identify.device_type == | |
8601 | SAS_END_DEVICE) | |
8602 | mpt3sas_device_remove_by_sas_address(ioc, | |
8603 | mpt3sas_port->remote_identify.sas_address); | |
8604 | else if (mpt3sas_port->remote_identify.device_type == | |
8605 | SAS_EDGE_EXPANDER_DEVICE || | |
8606 | mpt3sas_port->remote_identify.device_type == | |
8607 | SAS_FANOUT_EXPANDER_DEVICE) | |
8608 | mpt3sas_expander_remove(ioc, | |
8609 | mpt3sas_port->remote_identify.sas_address); | |
8610 | } | |
8611 | ||
8612 | /* free phys attached to the sas_host */ | |
8613 | if (ioc->sas_hba.num_phys) { | |
8614 | kfree(ioc->sas_hba.phy); | |
8615 | ioc->sas_hba.phy = NULL; | |
8616 | ioc->sas_hba.num_phys = 0; | |
8617 | } | |
8618 | ||
8619 | sas_remove_host(shost); | |
8620 | mpt3sas_base_detach(ioc); | |
08c4d550 | 8621 | spin_lock(&gioc_lock); |
f92363d1 | 8622 | list_del(&ioc->list); |
08c4d550 | 8623 | spin_unlock(&gioc_lock); |
f92363d1 SR |
8624 | scsi_host_put(shost); |
8625 | } | |
8626 | ||
8627 | /** | |
8a7e4c24 | 8628 | * scsih_shutdown - routine call during system shutdown |
f92363d1 SR |
8629 | * @pdev: PCI device struct |
8630 | * | |
8631 | * Return nothing. | |
8632 | */ | |
8bbb1cf6 | 8633 | static void |
8a7e4c24 | 8634 | scsih_shutdown(struct pci_dev *pdev) |
f92363d1 SR |
8635 | { |
8636 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8637 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8638 | struct workqueue_struct *wq; | |
8639 | unsigned long flags; | |
8640 | ||
8641 | ioc->remove_host = 1; | |
8642 | _scsih_fw_event_cleanup_queue(ioc); | |
8643 | ||
8644 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
8645 | wq = ioc->firmware_event_thread; | |
8646 | ioc->firmware_event_thread = NULL; | |
8647 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
8648 | if (wq) | |
8649 | destroy_workqueue(wq); | |
8650 | ||
8651 | _scsih_ir_shutdown(ioc); | |
8652 | mpt3sas_base_detach(ioc); | |
8653 | } | |
8654 | ||
8655 | ||
8656 | /** | |
8657 | * _scsih_probe_boot_devices - reports 1st device | |
8658 | * @ioc: per adapter object | |
8659 | * | |
8660 | * If specified in bios page 2, this routine reports the 1st | |
8661 | * device scsi-ml or sas transport for persistent boot device | |
8662 | * purposes. Please refer to function _scsih_determine_boot_device() | |
8663 | */ | |
8664 | static void | |
8665 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
8666 | { | |
d88e1eab | 8667 | u32 channel; |
f92363d1 SR |
8668 | void *device; |
8669 | struct _sas_device *sas_device; | |
8670 | struct _raid_device *raid_device; | |
d88e1eab | 8671 | struct _pcie_device *pcie_device; |
f92363d1 SR |
8672 | u16 handle; |
8673 | u64 sas_address_parent; | |
8674 | u64 sas_address; | |
8675 | unsigned long flags; | |
8676 | int rc; | |
d88e1eab | 8677 | int tid; |
f92363d1 SR |
8678 | |
8679 | /* no Bios, return immediately */ | |
8680 | if (!ioc->bios_pg3.BiosVersion) | |
8681 | return; | |
8682 | ||
8683 | device = NULL; | |
f92363d1 SR |
8684 | if (ioc->req_boot_device.device) { |
8685 | device = ioc->req_boot_device.device; | |
d88e1eab | 8686 | channel = ioc->req_boot_device.channel; |
f92363d1 SR |
8687 | } else if (ioc->req_alt_boot_device.device) { |
8688 | device = ioc->req_alt_boot_device.device; | |
d88e1eab | 8689 | channel = ioc->req_alt_boot_device.channel; |
f92363d1 SR |
8690 | } else if (ioc->current_boot_device.device) { |
8691 | device = ioc->current_boot_device.device; | |
d88e1eab | 8692 | channel = ioc->current_boot_device.channel; |
f92363d1 SR |
8693 | } |
8694 | ||
8695 | if (!device) | |
8696 | return; | |
8697 | ||
d88e1eab | 8698 | if (channel == RAID_CHANNEL) { |
f92363d1 SR |
8699 | raid_device = device; |
8700 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8701 | raid_device->id, 0); | |
8702 | if (rc) | |
8703 | _scsih_raid_device_remove(ioc, raid_device); | |
d88e1eab SPS |
8704 | } else if (channel == PCIE_CHANNEL) { |
8705 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8706 | pcie_device = device; | |
8707 | tid = pcie_device->id; | |
8708 | list_move_tail(&pcie_device->list, &ioc->pcie_device_list); | |
8709 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8710 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0); | |
8711 | if (rc) | |
8712 | _scsih_pcie_device_remove(ioc, pcie_device); | |
f92363d1 SR |
8713 | } else { |
8714 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
8715 | sas_device = device; | |
8716 | handle = sas_device->handle; | |
8717 | sas_address_parent = sas_device->sas_address_parent; | |
8718 | sas_address = sas_device->sas_address; | |
8719 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
8720 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8721 | ||
7786ab6a SR |
8722 | if (ioc->hide_drives) |
8723 | return; | |
f92363d1 SR |
8724 | if (!mpt3sas_transport_port_add(ioc, handle, |
8725 | sas_address_parent)) { | |
8726 | _scsih_sas_device_remove(ioc, sas_device); | |
8727 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
8728 | if (!ioc->is_driver_loading) { |
8729 | mpt3sas_transport_port_remove(ioc, | |
8730 | sas_address, | |
f92363d1 | 8731 | sas_address_parent); |
f5edbe77 SR |
8732 | _scsih_sas_device_remove(ioc, sas_device); |
8733 | } | |
f92363d1 SR |
8734 | } |
8735 | } | |
8736 | } | |
8737 | ||
8738 | /** | |
8739 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
8740 | * @ioc: per adapter object | |
8741 | * | |
8742 | * Called during initial loading of the driver. | |
8743 | */ | |
8744 | static void | |
8745 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
8746 | { | |
8747 | struct _raid_device *raid_device, *raid_next; | |
8748 | int rc; | |
8749 | ||
8750 | list_for_each_entry_safe(raid_device, raid_next, | |
8751 | &ioc->raid_device_list, list) { | |
8752 | if (raid_device->starget) | |
8753 | continue; | |
8754 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
8755 | raid_device->id, 0); | |
8756 | if (rc) | |
8757 | _scsih_raid_device_remove(ioc, raid_device); | |
8758 | } | |
8759 | } | |
8760 | ||
d1cb5e49 SR |
8761 | static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc) |
8762 | { | |
8763 | struct _sas_device *sas_device = NULL; | |
8764 | unsigned long flags; | |
8765 | ||
8766 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
8767 | if (!list_empty(&ioc->sas_device_init_list)) { | |
8768 | sas_device = list_first_entry(&ioc->sas_device_init_list, | |
8769 | struct _sas_device, list); | |
8770 | sas_device_get(sas_device); | |
8771 | } | |
8772 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8773 | ||
8774 | return sas_device; | |
8775 | } | |
8776 | ||
8777 | static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
8778 | struct _sas_device *sas_device) | |
8779 | { | |
8780 | unsigned long flags; | |
8781 | ||
8782 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
8783 | ||
8784 | /* | |
8785 | * Since we dropped the lock during the call to port_add(), we need to | |
8786 | * be careful here that somebody else didn't move or delete this item | |
8787 | * while we were busy with other things. | |
8788 | * | |
8789 | * If it was on the list, we need a put() for the reference the list | |
8790 | * had. Either way, we need a get() for the destination list. | |
8791 | */ | |
8792 | if (!list_empty(&sas_device->list)) { | |
8793 | list_del_init(&sas_device->list); | |
8794 | sas_device_put(sas_device); | |
8795 | } | |
8796 | ||
8797 | sas_device_get(sas_device); | |
8798 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
8799 | ||
8800 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
8801 | } | |
8802 | ||
f92363d1 SR |
8803 | /** |
8804 | * _scsih_probe_sas - reporting sas devices to sas transport | |
8805 | * @ioc: per adapter object | |
8806 | * | |
8807 | * Called during initial loading of the driver. | |
8808 | */ | |
8809 | static void | |
8810 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
8811 | { | |
d1cb5e49 | 8812 | struct _sas_device *sas_device; |
f92363d1 | 8813 | |
d1cb5e49 SR |
8814 | if (ioc->hide_drives) |
8815 | return; | |
7786ab6a | 8816 | |
d1cb5e49 | 8817 | while ((sas_device = get_next_sas_device(ioc))) { |
f92363d1 SR |
8818 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
8819 | sas_device->sas_address_parent)) { | |
d1cb5e49 SR |
8820 | _scsih_sas_device_remove(ioc, sas_device); |
8821 | sas_device_put(sas_device); | |
f92363d1 SR |
8822 | continue; |
8823 | } else if (!sas_device->starget) { | |
8824 | /* | |
8825 | * When asyn scanning is enabled, its not possible to | |
8826 | * remove devices while scanning is turned on due to an | |
8827 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
8828 | * sysfs_addrm_start() | |
8829 | */ | |
f5edbe77 | 8830 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
8831 | mpt3sas_transport_port_remove(ioc, |
8832 | sas_device->sas_address, | |
8833 | sas_device->sas_address_parent); | |
d1cb5e49 SR |
8834 | _scsih_sas_device_remove(ioc, sas_device); |
8835 | sas_device_put(sas_device); | |
f5edbe77 SR |
8836 | continue; |
8837 | } | |
f92363d1 | 8838 | } |
d1cb5e49 SR |
8839 | sas_device_make_active(ioc, sas_device); |
8840 | sas_device_put(sas_device); | |
f92363d1 SR |
8841 | } |
8842 | } | |
8843 | ||
d88e1eab SPS |
8844 | /** |
8845 | * get_next_pcie_device - Get the next pcie device | |
8846 | * @ioc: per adapter object | |
8847 | * | |
8848 | * Get the next pcie device from pcie_device_init_list list. | |
8849 | * | |
8850 | * Returns pcie device structure if pcie_device_init_list list is not empty | |
8851 | * otherwise returns NULL | |
8852 | */ | |
8853 | static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc) | |
8854 | { | |
8855 | struct _pcie_device *pcie_device = NULL; | |
8856 | unsigned long flags; | |
8857 | ||
8858 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8859 | if (!list_empty(&ioc->pcie_device_init_list)) { | |
8860 | pcie_device = list_first_entry(&ioc->pcie_device_init_list, | |
8861 | struct _pcie_device, list); | |
8862 | pcie_device_get(pcie_device); | |
8863 | } | |
8864 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8865 | ||
8866 | return pcie_device; | |
8867 | } | |
8868 | ||
8869 | /** | |
8870 | * pcie_device_make_active - Add pcie device to pcie_device_list list | |
8871 | * @ioc: per adapter object | |
8872 | * @pcie_device: pcie device object | |
8873 | * | |
8874 | * Add the pcie device which has registered with SCSI Transport Later to | |
8875 | * pcie_device_list list | |
8876 | */ | |
8877 | static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, | |
8878 | struct _pcie_device *pcie_device) | |
8879 | { | |
8880 | unsigned long flags; | |
8881 | ||
8882 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); | |
8883 | ||
8884 | if (!list_empty(&pcie_device->list)) { | |
8885 | list_del_init(&pcie_device->list); | |
8886 | pcie_device_put(pcie_device); | |
8887 | } | |
8888 | pcie_device_get(pcie_device); | |
8889 | list_add_tail(&pcie_device->list, &ioc->pcie_device_list); | |
8890 | ||
8891 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); | |
8892 | } | |
8893 | ||
8894 | /** | |
8895 | * _scsih_probe_pcie - reporting PCIe devices to scsi-ml | |
8896 | * @ioc: per adapter object | |
8897 | * | |
8898 | * Called during initial loading of the driver. | |
8899 | */ | |
8900 | static void | |
8901 | _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc) | |
8902 | { | |
8903 | struct _pcie_device *pcie_device; | |
8904 | int rc; | |
8905 | ||
8906 | /* PCIe Device List */ | |
8907 | while ((pcie_device = get_next_pcie_device(ioc))) { | |
8908 | if (pcie_device->starget) { | |
8909 | pcie_device_put(pcie_device); | |
8910 | continue; | |
8911 | } | |
8912 | rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, | |
8913 | pcie_device->id, 0); | |
8914 | if (rc) { | |
8915 | _scsih_pcie_device_remove(ioc, pcie_device); | |
8916 | pcie_device_put(pcie_device); | |
8917 | continue; | |
8918 | } else if (!pcie_device->starget) { | |
8919 | /* | |
8920 | * When async scanning is enabled, its not possible to | |
8921 | * remove devices while scanning is turned on due to an | |
8922 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
8923 | * sysfs_addrm_start() | |
8924 | */ | |
8925 | if (!ioc->is_driver_loading) { | |
8926 | /* TODO-- Need to find out whether this condition will | |
8927 | * occur or not | |
8928 | */ | |
8929 | _scsih_pcie_device_remove(ioc, pcie_device); | |
8930 | pcie_device_put(pcie_device); | |
8931 | continue; | |
8932 | } | |
8933 | } | |
8934 | pcie_device_make_active(ioc, pcie_device); | |
8935 | pcie_device_put(pcie_device); | |
8936 | } | |
8937 | } | |
8938 | ||
f92363d1 SR |
8939 | /** |
8940 | * _scsih_probe_devices - probing for devices | |
8941 | * @ioc: per adapter object | |
8942 | * | |
8943 | * Called during initial loading of the driver. | |
8944 | */ | |
8945 | static void | |
8946 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
8947 | { | |
8948 | u16 volume_mapping_flags; | |
8949 | ||
8950 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
8951 | return; /* return when IOC doesn't support initiator mode */ | |
8952 | ||
8953 | _scsih_probe_boot_devices(ioc); | |
8954 | ||
8955 | if (ioc->ir_firmware) { | |
8956 | volume_mapping_flags = | |
8957 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
8958 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
8959 | if (volume_mapping_flags == | |
8960 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
8961 | _scsih_probe_raid(ioc); | |
8962 | _scsih_probe_sas(ioc); | |
8963 | } else { | |
8964 | _scsih_probe_sas(ioc); | |
8965 | _scsih_probe_raid(ioc); | |
8966 | } | |
d88e1eab | 8967 | } else { |
f92363d1 | 8968 | _scsih_probe_sas(ioc); |
d88e1eab SPS |
8969 | _scsih_probe_pcie(ioc); |
8970 | } | |
f92363d1 SR |
8971 | } |
8972 | ||
8973 | /** | |
8a7e4c24 | 8974 | * scsih_scan_start - scsi lld callback for .scan_start |
f92363d1 SR |
8975 | * @shost: SCSI host pointer |
8976 | * | |
8977 | * The shost has the ability to discover targets on its own instead | |
8978 | * of scanning the entire bus. In our implemention, we will kick off | |
8979 | * firmware discovery. | |
8980 | */ | |
8bbb1cf6 | 8981 | static void |
8a7e4c24 | 8982 | scsih_scan_start(struct Scsi_Host *shost) |
f92363d1 SR |
8983 | { |
8984 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8985 | int rc; | |
8986 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
8987 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
8988 | ||
8989 | if (disable_discovery > 0) | |
8990 | return; | |
8991 | ||
8992 | ioc->start_scan = 1; | |
8993 | rc = mpt3sas_port_enable(ioc); | |
8994 | ||
8995 | if (rc != 0) | |
8996 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
8997 | } | |
8998 | ||
8999 | /** | |
8a7e4c24 | 9000 | * scsih_scan_finished - scsi lld callback for .scan_finished |
f92363d1 SR |
9001 | * @shost: SCSI host pointer |
9002 | * @time: elapsed time of the scan in jiffies | |
9003 | * | |
9004 | * This function will be called periodicallyn until it returns 1 with the | |
9005 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
9006 | * we wait for firmware discovery to complete, then return 1. | |
9007 | */ | |
8bbb1cf6 | 9008 | static int |
8a7e4c24 | 9009 | scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
f92363d1 SR |
9010 | { |
9011 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9012 | ||
9013 | if (disable_discovery > 0) { | |
9014 | ioc->is_driver_loading = 0; | |
9015 | ioc->wait_for_discovery_to_complete = 0; | |
9016 | return 1; | |
9017 | } | |
9018 | ||
9019 | if (time >= (300 * HZ)) { | |
9020 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
9021 | pr_info(MPT3SAS_FMT | |
9022 | "port enable: FAILED with timeout (timeout=300s)\n", | |
9023 | ioc->name); | |
9024 | ioc->is_driver_loading = 0; | |
9025 | return 1; | |
9026 | } | |
9027 | ||
9028 | if (ioc->start_scan) | |
9029 | return 0; | |
9030 | ||
9031 | if (ioc->start_scan_failed) { | |
9032 | pr_info(MPT3SAS_FMT | |
9033 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
9034 | ioc->name, ioc->start_scan_failed); | |
9035 | ioc->is_driver_loading = 0; | |
9036 | ioc->wait_for_discovery_to_complete = 0; | |
9037 | ioc->remove_host = 1; | |
9038 | return 1; | |
9039 | } | |
9040 | ||
9041 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
9042 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
9043 | ||
9044 | if (ioc->wait_for_discovery_to_complete) { | |
9045 | ioc->wait_for_discovery_to_complete = 0; | |
9046 | _scsih_probe_devices(ioc); | |
9047 | } | |
9048 | mpt3sas_base_start_watchdog(ioc); | |
9049 | ioc->is_driver_loading = 0; | |
9050 | return 1; | |
9051 | } | |
9052 | ||
c84b06a4 SR |
9053 | /* shost template for SAS 2.0 HBA devices */ |
9054 | static struct scsi_host_template mpt2sas_driver_template = { | |
9055 | .module = THIS_MODULE, | |
9056 | .name = "Fusion MPT SAS Host", | |
9057 | .proc_name = MPT2SAS_DRIVER_NAME, | |
9058 | .queuecommand = scsih_qcmd, | |
9059 | .target_alloc = scsih_target_alloc, | |
9060 | .slave_alloc = scsih_slave_alloc, | |
9061 | .slave_configure = scsih_slave_configure, | |
9062 | .target_destroy = scsih_target_destroy, | |
9063 | .slave_destroy = scsih_slave_destroy, | |
9064 | .scan_finished = scsih_scan_finished, | |
9065 | .scan_start = scsih_scan_start, | |
9066 | .change_queue_depth = scsih_change_queue_depth, | |
9067 | .eh_abort_handler = scsih_abort, | |
9068 | .eh_device_reset_handler = scsih_dev_reset, | |
9069 | .eh_target_reset_handler = scsih_target_reset, | |
9070 | .eh_host_reset_handler = scsih_host_reset, | |
9071 | .bios_param = scsih_bios_param, | |
9072 | .can_queue = 1, | |
9073 | .this_id = -1, | |
9074 | .sg_tablesize = MPT2SAS_SG_DEPTH, | |
9075 | .max_sectors = 32767, | |
9076 | .cmd_per_lun = 7, | |
9077 | .use_clustering = ENABLE_CLUSTERING, | |
9078 | .shost_attrs = mpt3sas_host_attrs, | |
9079 | .sdev_attrs = mpt3sas_dev_attrs, | |
9080 | .track_queue_depth = 1, | |
9081 | }; | |
9082 | ||
9083 | /* raid transport support for SAS 2.0 HBA devices */ | |
9084 | static struct raid_function_template mpt2sas_raid_functions = { | |
9085 | .cookie = &mpt2sas_driver_template, | |
9086 | .is_raid = scsih_is_raid, | |
9087 | .get_resync = scsih_get_resync, | |
9088 | .get_state = scsih_get_state, | |
9089 | }; | |
d357e84d | 9090 | |
c84b06a4 SR |
9091 | /* shost template for SAS 3.0 HBA devices */ |
9092 | static struct scsi_host_template mpt3sas_driver_template = { | |
9093 | .module = THIS_MODULE, | |
9094 | .name = "Fusion MPT SAS Host", | |
9095 | .proc_name = MPT3SAS_DRIVER_NAME, | |
9096 | .queuecommand = scsih_qcmd, | |
9097 | .target_alloc = scsih_target_alloc, | |
9098 | .slave_alloc = scsih_slave_alloc, | |
9099 | .slave_configure = scsih_slave_configure, | |
9100 | .target_destroy = scsih_target_destroy, | |
9101 | .slave_destroy = scsih_slave_destroy, | |
9102 | .scan_finished = scsih_scan_finished, | |
9103 | .scan_start = scsih_scan_start, | |
9104 | .change_queue_depth = scsih_change_queue_depth, | |
9105 | .eh_abort_handler = scsih_abort, | |
9106 | .eh_device_reset_handler = scsih_dev_reset, | |
9107 | .eh_target_reset_handler = scsih_target_reset, | |
9108 | .eh_host_reset_handler = scsih_host_reset, | |
9109 | .bios_param = scsih_bios_param, | |
9110 | .can_queue = 1, | |
9111 | .this_id = -1, | |
9112 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
9113 | .max_sectors = 32767, | |
9114 | .cmd_per_lun = 7, | |
9115 | .use_clustering = ENABLE_CLUSTERING, | |
9116 | .shost_attrs = mpt3sas_host_attrs, | |
9117 | .sdev_attrs = mpt3sas_dev_attrs, | |
9118 | .track_queue_depth = 1, | |
9119 | }; | |
9120 | ||
9121 | /* raid transport support for SAS 3.0 HBA devices */ | |
9122 | static struct raid_function_template mpt3sas_raid_functions = { | |
9123 | .cookie = &mpt3sas_driver_template, | |
9124 | .is_raid = scsih_is_raid, | |
9125 | .get_resync = scsih_get_resync, | |
9126 | .get_state = scsih_get_state, | |
9127 | }; | |
9128 | ||
9129 | /** | |
9130 | * _scsih_determine_hba_mpi_version - determine in which MPI version class | |
9131 | * this device belongs to. | |
9132 | * @pdev: PCI device struct | |
9133 | * | |
9134 | * return MPI2_VERSION for SAS 2.0 HBA devices, | |
b130b0d5 SS |
9135 | * MPI25_VERSION for SAS 3.0 HBA devices, and |
9136 | * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices | |
c84b06a4 | 9137 | */ |
8bbb1cf6 | 9138 | static u16 |
c84b06a4 SR |
9139 | _scsih_determine_hba_mpi_version(struct pci_dev *pdev) |
9140 | { | |
9141 | ||
9142 | switch (pdev->device) { | |
7786ab6a | 9143 | case MPI2_MFGPAGE_DEVID_SSS6200: |
d357e84d SR |
9144 | case MPI2_MFGPAGE_DEVID_SAS2004: |
9145 | case MPI2_MFGPAGE_DEVID_SAS2008: | |
9146 | case MPI2_MFGPAGE_DEVID_SAS2108_1: | |
9147 | case MPI2_MFGPAGE_DEVID_SAS2108_2: | |
9148 | case MPI2_MFGPAGE_DEVID_SAS2108_3: | |
9149 | case MPI2_MFGPAGE_DEVID_SAS2116_1: | |
9150 | case MPI2_MFGPAGE_DEVID_SAS2116_2: | |
9151 | case MPI2_MFGPAGE_DEVID_SAS2208_1: | |
9152 | case MPI2_MFGPAGE_DEVID_SAS2208_2: | |
9153 | case MPI2_MFGPAGE_DEVID_SAS2208_3: | |
9154 | case MPI2_MFGPAGE_DEVID_SAS2208_4: | |
9155 | case MPI2_MFGPAGE_DEVID_SAS2208_5: | |
9156 | case MPI2_MFGPAGE_DEVID_SAS2208_6: | |
9157 | case MPI2_MFGPAGE_DEVID_SAS2308_1: | |
9158 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | |
9159 | case MPI2_MFGPAGE_DEVID_SAS2308_3: | |
c84b06a4 | 9160 | return MPI2_VERSION; |
d357e84d SR |
9161 | case MPI25_MFGPAGE_DEVID_SAS3004: |
9162 | case MPI25_MFGPAGE_DEVID_SAS3008: | |
9163 | case MPI25_MFGPAGE_DEVID_SAS3108_1: | |
9164 | case MPI25_MFGPAGE_DEVID_SAS3108_2: | |
9165 | case MPI25_MFGPAGE_DEVID_SAS3108_5: | |
9166 | case MPI25_MFGPAGE_DEVID_SAS3108_6: | |
c84b06a4 | 9167 | return MPI25_VERSION; |
b130b0d5 SS |
9168 | case MPI26_MFGPAGE_DEVID_SAS3216: |
9169 | case MPI26_MFGPAGE_DEVID_SAS3224: | |
9170 | case MPI26_MFGPAGE_DEVID_SAS3316_1: | |
9171 | case MPI26_MFGPAGE_DEVID_SAS3316_2: | |
9172 | case MPI26_MFGPAGE_DEVID_SAS3316_3: | |
9173 | case MPI26_MFGPAGE_DEVID_SAS3316_4: | |
9174 | case MPI26_MFGPAGE_DEVID_SAS3324_1: | |
9175 | case MPI26_MFGPAGE_DEVID_SAS3324_2: | |
9176 | case MPI26_MFGPAGE_DEVID_SAS3324_3: | |
9177 | case MPI26_MFGPAGE_DEVID_SAS3324_4: | |
998f26ae SPS |
9178 | case MPI26_MFGPAGE_DEVID_SAS3508: |
9179 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
9180 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
9181 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
9182 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
9183 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 9184 | case MPI26_MFGPAGE_DEVID_SAS3616: |
b130b0d5 | 9185 | return MPI26_VERSION; |
d357e84d | 9186 | } |
c84b06a4 | 9187 | return 0; |
d357e84d SR |
9188 | } |
9189 | ||
f92363d1 | 9190 | /** |
c84b06a4 | 9191 | * _scsih_probe - attach and add scsi host |
f92363d1 SR |
9192 | * @pdev: PCI device struct |
9193 | * @id: pci device id | |
9194 | * | |
9195 | * Returns 0 success, anything else error. | |
9196 | */ | |
8bbb1cf6 | 9197 | static int |
c84b06a4 | 9198 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
f92363d1 SR |
9199 | { |
9200 | struct MPT3SAS_ADAPTER *ioc; | |
c84b06a4 | 9201 | struct Scsi_Host *shost = NULL; |
b65f1d4d | 9202 | int rv; |
c84b06a4 SR |
9203 | u16 hba_mpi_version; |
9204 | ||
9205 | /* Determine in which MPI version class this pci device belongs */ | |
9206 | hba_mpi_version = _scsih_determine_hba_mpi_version(pdev); | |
9207 | if (hba_mpi_version == 0) | |
9208 | return -ENODEV; | |
9209 | ||
9210 | /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one, | |
9211 | * for other generation HBA's return with -ENODEV | |
9212 | */ | |
9213 | if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION)) | |
9214 | return -ENODEV; | |
9215 | ||
9216 | /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two, | |
9217 | * for other generation HBA's return with -ENODEV | |
9218 | */ | |
b130b0d5 SS |
9219 | if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION |
9220 | || hba_mpi_version == MPI26_VERSION))) | |
c84b06a4 SR |
9221 | return -ENODEV; |
9222 | ||
9223 | switch (hba_mpi_version) { | |
9224 | case MPI2_VERSION: | |
ffdadd68 | 9225 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
9226 | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); | |
c84b06a4 SR |
9227 | /* Use mpt2sas driver host template for SAS 2.0 HBA's */ |
9228 | shost = scsi_host_alloc(&mpt2sas_driver_template, | |
9229 | sizeof(struct MPT3SAS_ADAPTER)); | |
9230 | if (!shost) | |
9231 | return -ENODEV; | |
9232 | ioc = shost_priv(shost); | |
9233 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
9234 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
9235 | ioc->id = mpt2_ids++; | |
9236 | sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME); | |
9237 | if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) { | |
9238 | ioc->is_warpdrive = 1; | |
9239 | ioc->hide_ir_msg = 1; | |
9240 | } else | |
9241 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; | |
9242 | break; | |
9243 | case MPI25_VERSION: | |
b130b0d5 | 9244 | case MPI26_VERSION: |
c84b06a4 SR |
9245 | /* Use mpt3sas driver host template for SAS 3.0 HBA's */ |
9246 | shost = scsi_host_alloc(&mpt3sas_driver_template, | |
9247 | sizeof(struct MPT3SAS_ADAPTER)); | |
9248 | if (!shost) | |
9249 | return -ENODEV; | |
9250 | ioc = shost_priv(shost); | |
9251 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
9252 | ioc->hba_mpi_version_belonged = hba_mpi_version; | |
9253 | ioc->id = mpt3_ids++; | |
9254 | sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME); | |
998f26ae SPS |
9255 | switch (pdev->device) { |
9256 | case MPI26_MFGPAGE_DEVID_SAS3508: | |
9257 | case MPI26_MFGPAGE_DEVID_SAS3508_1: | |
9258 | case MPI26_MFGPAGE_DEVID_SAS3408: | |
9259 | case MPI26_MFGPAGE_DEVID_SAS3516: | |
9260 | case MPI26_MFGPAGE_DEVID_SAS3516_1: | |
9261 | case MPI26_MFGPAGE_DEVID_SAS3416: | |
15fd7c74 | 9262 | case MPI26_MFGPAGE_DEVID_SAS3616: |
998f26ae SPS |
9263 | ioc->is_gen35_ioc = 1; |
9264 | break; | |
9265 | default: | |
9266 | ioc->is_gen35_ioc = 0; | |
9267 | } | |
b130b0d5 SS |
9268 | if ((ioc->hba_mpi_version_belonged == MPI25_VERSION && |
9269 | pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) || | |
0bb337c9 SPS |
9270 | (ioc->hba_mpi_version_belonged == MPI26_VERSION)) { |
9271 | ioc->combined_reply_queue = 1; | |
9272 | if (ioc->is_gen35_ioc) | |
9273 | ioc->combined_reply_index_count = | |
9274 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35; | |
9275 | else | |
9276 | ioc->combined_reply_index_count = | |
9277 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3; | |
9278 | } | |
c84b06a4 SR |
9279 | break; |
9280 | default: | |
9281 | return -ENODEV; | |
9282 | } | |
f92363d1 | 9283 | |
f92363d1 | 9284 | INIT_LIST_HEAD(&ioc->list); |
08c4d550 | 9285 | spin_lock(&gioc_lock); |
f92363d1 | 9286 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
08c4d550 | 9287 | spin_unlock(&gioc_lock); |
f92363d1 | 9288 | ioc->shost = shost; |
f92363d1 SR |
9289 | ioc->pdev = pdev; |
9290 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
9291 | ioc->tm_cb_idx = tm_cb_idx; | |
9292 | ioc->ctl_cb_idx = ctl_cb_idx; | |
9293 | ioc->base_cb_idx = base_cb_idx; | |
9294 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
9295 | ioc->transport_cb_idx = transport_cb_idx; | |
9296 | ioc->scsih_cb_idx = scsih_cb_idx; | |
9297 | ioc->config_cb_idx = config_cb_idx; | |
9298 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
9299 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
9300 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
9301 | ioc->logging_level = logging_level; | |
9302 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
9303 | /* misc semaphores and spin locks */ | |
9304 | mutex_init(&ioc->reset_in_progress_mutex); | |
08c4d550 SR |
9305 | /* initializing pci_access_mutex lock */ |
9306 | mutex_init(&ioc->pci_access_mutex); | |
f92363d1 SR |
9307 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
9308 | spin_lock_init(&ioc->scsi_lookup_lock); | |
9309 | spin_lock_init(&ioc->sas_device_lock); | |
9310 | spin_lock_init(&ioc->sas_node_lock); | |
9311 | spin_lock_init(&ioc->fw_event_lock); | |
9312 | spin_lock_init(&ioc->raid_device_lock); | |
d88e1eab | 9313 | spin_lock_init(&ioc->pcie_device_lock); |
f92363d1 SR |
9314 | spin_lock_init(&ioc->diag_trigger_lock); |
9315 | ||
9316 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
9317 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
9318 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
d88e1eab SPS |
9319 | INIT_LIST_HEAD(&ioc->pcie_device_list); |
9320 | INIT_LIST_HEAD(&ioc->pcie_device_init_list); | |
f92363d1 SR |
9321 | INIT_LIST_HEAD(&ioc->fw_event_list); |
9322 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
9323 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
9324 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
fd0331b3 SS |
9325 | INIT_LIST_HEAD(&ioc->delayed_sc_list); |
9326 | INIT_LIST_HEAD(&ioc->delayed_event_ack_list); | |
f92363d1 | 9327 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
cf9bd21a | 9328 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 | 9329 | |
c84b06a4 | 9330 | sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id); |
d357e84d | 9331 | |
f92363d1 SR |
9332 | /* init shost parameters */ |
9333 | shost->max_cmd_len = 32; | |
9334 | shost->max_lun = max_lun; | |
9335 | shost->transportt = mpt3sas_transport_template; | |
9336 | shost->unique_id = ioc->id; | |
9337 | ||
9338 | if (max_sectors != 0xFFFF) { | |
9339 | if (max_sectors < 64) { | |
9340 | shost->max_sectors = 64; | |
9341 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
9342 | "for max_sectors, range is 64 to 32767. Assigning " | |
9343 | "value of 64.\n", ioc->name, max_sectors); | |
9344 | } else if (max_sectors > 32767) { | |
9345 | shost->max_sectors = 32767; | |
9346 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
9347 | "for max_sectors, range is 64 to 32767. Assigning " | |
9348 | "default value of 32767.\n", ioc->name, | |
9349 | max_sectors); | |
9350 | } else { | |
9351 | shost->max_sectors = max_sectors & 0xFFFE; | |
9352 | pr_info(MPT3SAS_FMT | |
9353 | "The max_sectors value is set to %d\n", | |
9354 | ioc->name, shost->max_sectors); | |
9355 | } | |
9356 | } | |
9357 | ||
f92363d1 SR |
9358 | /* register EEDP capabilities with SCSI layer */ |
9359 | if (prot_mask > 0) | |
9360 | scsi_host_set_prot(shost, prot_mask); | |
9361 | else | |
9362 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
9363 | | SHOST_DIF_TYPE2_PROTECTION | |
9364 | | SHOST_DIF_TYPE3_PROTECTION); | |
9365 | ||
9366 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
9367 | ||
9368 | /* event thread */ | |
9369 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
c84b06a4 | 9370 | "fw_event_%s%d", ioc->driver_name, ioc->id); |
bdff785e SR |
9371 | ioc->firmware_event_thread = alloc_ordered_workqueue( |
9372 | ioc->firmware_event_name, WQ_MEM_RECLAIM); | |
f92363d1 SR |
9373 | if (!ioc->firmware_event_thread) { |
9374 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
9375 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 9376 | rv = -ENODEV; |
f92363d1 SR |
9377 | goto out_thread_fail; |
9378 | } | |
9379 | ||
9380 | ioc->is_driver_loading = 1; | |
9381 | if ((mpt3sas_base_attach(ioc))) { | |
9382 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
9383 | ioc->name, __FILE__, __LINE__, __func__); | |
b65f1d4d | 9384 | rv = -ENODEV; |
f92363d1 SR |
9385 | goto out_attach_fail; |
9386 | } | |
7786ab6a | 9387 | |
7786ab6a SR |
9388 | if (ioc->is_warpdrive) { |
9389 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | |
9390 | ioc->hide_drives = 0; | |
9391 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | |
9392 | ioc->hide_drives = 1; | |
9393 | else { | |
c84b06a4 | 9394 | if (mpt3sas_get_num_volumes(ioc)) |
7786ab6a SR |
9395 | ioc->hide_drives = 1; |
9396 | else | |
9397 | ioc->hide_drives = 0; | |
9398 | } | |
9399 | } else | |
9400 | ioc->hide_drives = 0; | |
7786ab6a | 9401 | |
b65f1d4d SR |
9402 | rv = scsi_add_host(shost, &pdev->dev); |
9403 | if (rv) { | |
4dc06fd8 RS |
9404 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
9405 | ioc->name, __FILE__, __LINE__, __func__); | |
4dc06fd8 RS |
9406 | goto out_add_shost_fail; |
9407 | } | |
9408 | ||
f92363d1 SR |
9409 | scsi_scan_host(shost); |
9410 | return 0; | |
4dc06fd8 RS |
9411 | out_add_shost_fail: |
9412 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
9413 | out_attach_fail: |
9414 | destroy_workqueue(ioc->firmware_event_thread); | |
9415 | out_thread_fail: | |
08c4d550 | 9416 | spin_lock(&gioc_lock); |
f92363d1 | 9417 | list_del(&ioc->list); |
08c4d550 | 9418 | spin_unlock(&gioc_lock); |
f92363d1 | 9419 | scsi_host_put(shost); |
b65f1d4d | 9420 | return rv; |
f92363d1 SR |
9421 | } |
9422 | ||
9423 | #ifdef CONFIG_PM | |
9424 | /** | |
8a7e4c24 | 9425 | * scsih_suspend - power management suspend main entry point |
f92363d1 SR |
9426 | * @pdev: PCI device struct |
9427 | * @state: PM state change to (usually PCI_D3) | |
9428 | * | |
9429 | * Returns 0 success, anything else error. | |
9430 | */ | |
8bbb1cf6 | 9431 | static int |
8a7e4c24 | 9432 | scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
f92363d1 SR |
9433 | { |
9434 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9435 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9436 | pci_power_t device_state; | |
9437 | ||
9438 | mpt3sas_base_stop_watchdog(ioc); | |
9439 | flush_scheduled_work(); | |
9440 | scsi_block_requests(shost); | |
9441 | device_state = pci_choose_state(pdev, state); | |
9442 | pr_info(MPT3SAS_FMT | |
9443 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
9444 | ioc->name, pdev, pci_name(pdev), device_state); | |
9445 | ||
9446 | pci_save_state(pdev); | |
9447 | mpt3sas_base_free_resources(ioc); | |
9448 | pci_set_power_state(pdev, device_state); | |
9449 | return 0; | |
9450 | } | |
9451 | ||
9452 | /** | |
8a7e4c24 | 9453 | * scsih_resume - power management resume main entry point |
f92363d1 SR |
9454 | * @pdev: PCI device struct |
9455 | * | |
9456 | * Returns 0 success, anything else error. | |
9457 | */ | |
8bbb1cf6 | 9458 | static int |
8a7e4c24 | 9459 | scsih_resume(struct pci_dev *pdev) |
f92363d1 SR |
9460 | { |
9461 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9462 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9463 | pci_power_t device_state = pdev->current_state; | |
9464 | int r; | |
9465 | ||
9466 | pr_info(MPT3SAS_FMT | |
9467 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
9468 | ioc->name, pdev, pci_name(pdev), device_state); | |
9469 | ||
9470 | pci_set_power_state(pdev, PCI_D0); | |
9471 | pci_enable_wake(pdev, PCI_D0, 0); | |
9472 | pci_restore_state(pdev); | |
9473 | ioc->pdev = pdev; | |
9474 | r = mpt3sas_base_map_resources(ioc); | |
9475 | if (r) | |
9476 | return r; | |
9477 | ||
98c56ad3 | 9478 | mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); |
f92363d1 SR |
9479 | scsi_unblock_requests(shost); |
9480 | mpt3sas_base_start_watchdog(ioc); | |
9481 | return 0; | |
9482 | } | |
9483 | #endif /* CONFIG_PM */ | |
9484 | ||
9485 | /** | |
8a7e4c24 | 9486 | * scsih_pci_error_detected - Called when a PCI error is detected. |
f92363d1 SR |
9487 | * @pdev: PCI device struct |
9488 | * @state: PCI channel state | |
9489 | * | |
9490 | * Description: Called when a PCI error is detected. | |
9491 | * | |
9492 | * Return value: | |
9493 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
9494 | */ | |
8bbb1cf6 | 9495 | static pci_ers_result_t |
8a7e4c24 | 9496 | scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
f92363d1 SR |
9497 | { |
9498 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9499 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9500 | ||
9501 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
9502 | ioc->name, state); | |
9503 | ||
9504 | switch (state) { | |
9505 | case pci_channel_io_normal: | |
9506 | return PCI_ERS_RESULT_CAN_RECOVER; | |
9507 | case pci_channel_io_frozen: | |
9508 | /* Fatal error, prepare for slot reset */ | |
9509 | ioc->pci_error_recovery = 1; | |
9510 | scsi_block_requests(ioc->shost); | |
9511 | mpt3sas_base_stop_watchdog(ioc); | |
9512 | mpt3sas_base_free_resources(ioc); | |
9513 | return PCI_ERS_RESULT_NEED_RESET; | |
9514 | case pci_channel_io_perm_failure: | |
9515 | /* Permanent error, prepare for device removal */ | |
9516 | ioc->pci_error_recovery = 1; | |
9517 | mpt3sas_base_stop_watchdog(ioc); | |
9518 | _scsih_flush_running_cmds(ioc); | |
9519 | return PCI_ERS_RESULT_DISCONNECT; | |
9520 | } | |
9521 | return PCI_ERS_RESULT_NEED_RESET; | |
9522 | } | |
9523 | ||
9524 | /** | |
8a7e4c24 | 9525 | * scsih_pci_slot_reset - Called when PCI slot has been reset. |
f92363d1 SR |
9526 | * @pdev: PCI device struct |
9527 | * | |
9528 | * Description: This routine is called by the pci error recovery | |
9529 | * code after the PCI slot has been reset, just before we | |
9530 | * should resume normal operations. | |
9531 | */ | |
8bbb1cf6 | 9532 | static pci_ers_result_t |
8a7e4c24 | 9533 | scsih_pci_slot_reset(struct pci_dev *pdev) |
f92363d1 SR |
9534 | { |
9535 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9536 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9537 | int rc; | |
9538 | ||
9539 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
9540 | ioc->name); | |
9541 | ||
9542 | ioc->pci_error_recovery = 0; | |
9543 | ioc->pdev = pdev; | |
9544 | pci_restore_state(pdev); | |
9545 | rc = mpt3sas_base_map_resources(ioc); | |
9546 | if (rc) | |
9547 | return PCI_ERS_RESULT_DISCONNECT; | |
9548 | ||
98c56ad3 | 9549 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
f92363d1 SR |
9550 | |
9551 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
9552 | (rc == 0) ? "success" : "failed"); | |
9553 | ||
9554 | if (!rc) | |
9555 | return PCI_ERS_RESULT_RECOVERED; | |
9556 | else | |
9557 | return PCI_ERS_RESULT_DISCONNECT; | |
9558 | } | |
9559 | ||
9560 | /** | |
8a7e4c24 | 9561 | * scsih_pci_resume() - resume normal ops after PCI reset |
f92363d1 SR |
9562 | * @pdev: pointer to PCI device |
9563 | * | |
9564 | * Called when the error recovery driver tells us that its | |
9565 | * OK to resume normal operation. Use completion to allow | |
9566 | * halted scsi ops to resume. | |
9567 | */ | |
8bbb1cf6 | 9568 | static void |
8a7e4c24 | 9569 | scsih_pci_resume(struct pci_dev *pdev) |
f92363d1 SR |
9570 | { |
9571 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9572 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9573 | ||
9574 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
9575 | ||
9576 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
9577 | mpt3sas_base_start_watchdog(ioc); | |
9578 | scsi_unblock_requests(ioc->shost); | |
9579 | } | |
9580 | ||
9581 | /** | |
8a7e4c24 | 9582 | * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
f92363d1 SR |
9583 | * @pdev: pointer to PCI device |
9584 | */ | |
8bbb1cf6 | 9585 | static pci_ers_result_t |
8a7e4c24 | 9586 | scsih_pci_mmio_enabled(struct pci_dev *pdev) |
f92363d1 SR |
9587 | { |
9588 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9589 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
9590 | ||
9591 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
9592 | ioc->name); | |
9593 | ||
9594 | /* TODO - dump whatever for debugging purposes */ | |
9595 | ||
83c3d340 KW |
9596 | /* This called only if scsih_pci_error_detected returns |
9597 | * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still | |
9598 | * works, no need to reset slot. | |
9599 | */ | |
9600 | return PCI_ERS_RESULT_RECOVERED; | |
f92363d1 SR |
9601 | } |
9602 | ||
307d9075 AM |
9603 | /** |
9604 | * scsih__ncq_prio_supp - Check for NCQ command priority support | |
9605 | * @sdev: scsi device struct | |
9606 | * | |
9607 | * This is called when a user indicates they would like to enable | |
9608 | * ncq command priorities. This works only on SATA devices. | |
9609 | */ | |
9610 | bool scsih_ncq_prio_supp(struct scsi_device *sdev) | |
9611 | { | |
9612 | unsigned char *buf; | |
9613 | bool ncq_prio_supp = false; | |
9614 | ||
9615 | if (!scsi_device_supports_vpd(sdev)) | |
9616 | return ncq_prio_supp; | |
9617 | ||
9618 | buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL); | |
9619 | if (!buf) | |
9620 | return ncq_prio_supp; | |
9621 | ||
9622 | if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN)) | |
9623 | ncq_prio_supp = (buf[213] >> 4) & 1; | |
9624 | ||
9625 | kfree(buf); | |
9626 | return ncq_prio_supp; | |
9627 | } | |
c84b06a4 SR |
9628 | /* |
9629 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
9630 | */ | |
9631 | static const struct pci_device_id mpt3sas_pci_table[] = { | |
9632 | /* Spitfire ~ 2004 */ | |
9633 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | |
9634 | PCI_ANY_ID, PCI_ANY_ID }, | |
9635 | /* Falcon ~ 2008 */ | |
9636 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | |
9637 | PCI_ANY_ID, PCI_ANY_ID }, | |
9638 | /* Liberator ~ 2108 */ | |
9639 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | |
9640 | PCI_ANY_ID, PCI_ANY_ID }, | |
9641 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | |
9642 | PCI_ANY_ID, PCI_ANY_ID }, | |
9643 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | |
9644 | PCI_ANY_ID, PCI_ANY_ID }, | |
9645 | /* Meteor ~ 2116 */ | |
9646 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | |
9647 | PCI_ANY_ID, PCI_ANY_ID }, | |
9648 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | |
9649 | PCI_ANY_ID, PCI_ANY_ID }, | |
9650 | /* Thunderbolt ~ 2208 */ | |
9651 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | |
9652 | PCI_ANY_ID, PCI_ANY_ID }, | |
9653 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | |
9654 | PCI_ANY_ID, PCI_ANY_ID }, | |
9655 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | |
9656 | PCI_ANY_ID, PCI_ANY_ID }, | |
9657 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | |
9658 | PCI_ANY_ID, PCI_ANY_ID }, | |
9659 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | |
9660 | PCI_ANY_ID, PCI_ANY_ID }, | |
9661 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | |
9662 | PCI_ANY_ID, PCI_ANY_ID }, | |
9663 | /* Mustang ~ 2308 */ | |
9664 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | |
9665 | PCI_ANY_ID, PCI_ANY_ID }, | |
9666 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | |
9667 | PCI_ANY_ID, PCI_ANY_ID }, | |
9668 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | |
9669 | PCI_ANY_ID, PCI_ANY_ID }, | |
9670 | /* SSS6200 */ | |
9671 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | |
9672 | PCI_ANY_ID, PCI_ANY_ID }, | |
9673 | /* Fury ~ 3004 and 3008 */ | |
9674 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
9675 | PCI_ANY_ID, PCI_ANY_ID }, | |
9676 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
9677 | PCI_ANY_ID, PCI_ANY_ID }, | |
9678 | /* Invader ~ 3108 */ | |
9679 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
9680 | PCI_ANY_ID, PCI_ANY_ID }, | |
9681 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
9682 | PCI_ANY_ID, PCI_ANY_ID }, | |
9683 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
9684 | PCI_ANY_ID, PCI_ANY_ID }, | |
9685 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
9686 | PCI_ANY_ID, PCI_ANY_ID }, | |
b130b0d5 SS |
9687 | /* Cutlass ~ 3216 and 3224 */ |
9688 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216, | |
9689 | PCI_ANY_ID, PCI_ANY_ID }, | |
9690 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224, | |
9691 | PCI_ANY_ID, PCI_ANY_ID }, | |
9692 | /* Intruder ~ 3316 and 3324 */ | |
9693 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1, | |
9694 | PCI_ANY_ID, PCI_ANY_ID }, | |
9695 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2, | |
9696 | PCI_ANY_ID, PCI_ANY_ID }, | |
9697 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3, | |
9698 | PCI_ANY_ID, PCI_ANY_ID }, | |
9699 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4, | |
9700 | PCI_ANY_ID, PCI_ANY_ID }, | |
9701 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1, | |
9702 | PCI_ANY_ID, PCI_ANY_ID }, | |
9703 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2, | |
9704 | PCI_ANY_ID, PCI_ANY_ID }, | |
9705 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3, | |
9706 | PCI_ANY_ID, PCI_ANY_ID }, | |
9707 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4, | |
9708 | PCI_ANY_ID, PCI_ANY_ID }, | |
998f26ae SPS |
9709 | /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/ |
9710 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508, | |
9711 | PCI_ANY_ID, PCI_ANY_ID }, | |
9712 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1, | |
9713 | PCI_ANY_ID, PCI_ANY_ID }, | |
9714 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408, | |
9715 | PCI_ANY_ID, PCI_ANY_ID }, | |
9716 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516, | |
9717 | PCI_ANY_ID, PCI_ANY_ID }, | |
9718 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1, | |
9719 | PCI_ANY_ID, PCI_ANY_ID }, | |
9720 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416, | |
9721 | PCI_ANY_ID, PCI_ANY_ID }, | |
15fd7c74 SR |
9722 | /* Mercator ~ 3616*/ |
9723 | { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616, | |
9724 | PCI_ANY_ID, PCI_ANY_ID }, | |
c84b06a4 SR |
9725 | {0} /* Terminating entry */ |
9726 | }; | |
9727 | MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table); | |
9728 | ||
9729 | static struct pci_error_handlers _mpt3sas_err_handler = { | |
9730 | .error_detected = scsih_pci_error_detected, | |
9731 | .mmio_enabled = scsih_pci_mmio_enabled, | |
9732 | .slot_reset = scsih_pci_slot_reset, | |
9733 | .resume = scsih_pci_resume, | |
9734 | }; | |
9735 | ||
9736 | static struct pci_driver mpt3sas_driver = { | |
9737 | .name = MPT3SAS_DRIVER_NAME, | |
9738 | .id_table = mpt3sas_pci_table, | |
9739 | .probe = _scsih_probe, | |
9740 | .remove = scsih_remove, | |
9741 | .shutdown = scsih_shutdown, | |
9742 | .err_handler = &_mpt3sas_err_handler, | |
9743 | #ifdef CONFIG_PM | |
9744 | .suspend = scsih_suspend, | |
9745 | .resume = scsih_resume, | |
9746 | #endif | |
9747 | }; | |
9748 | ||
f92363d1 | 9749 | /** |
8a7e4c24 | 9750 | * scsih_init - main entry point for this driver. |
f92363d1 SR |
9751 | * |
9752 | * Returns 0 success, anything else error. | |
9753 | */ | |
8bbb1cf6 | 9754 | static int |
8a7e4c24 | 9755 | scsih_init(void) |
f92363d1 | 9756 | { |
c84b06a4 SR |
9757 | mpt2_ids = 0; |
9758 | mpt3_ids = 0; | |
f92363d1 | 9759 | |
f92363d1 SR |
9760 | mpt3sas_base_initialize_callback_handler(); |
9761 | ||
9762 | /* queuecommand callback hander */ | |
9763 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
9764 | ||
6c7abffc | 9765 | /* task management callback handler */ |
f92363d1 SR |
9766 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
9767 | ||
9768 | /* base internal commands callback handler */ | |
9769 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
9770 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
9771 | mpt3sas_port_enable_done); | |
9772 | ||
9773 | /* transport internal commands callback handler */ | |
9774 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
9775 | mpt3sas_transport_done); | |
9776 | ||
9777 | /* scsih internal commands callback handler */ | |
9778 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
9779 | ||
9780 | /* configuration page API internal commands callback handler */ | |
9781 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
9782 | mpt3sas_config_done); | |
9783 | ||
9784 | /* ctl module callback handler */ | |
9785 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
9786 | ||
9787 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
9788 | _scsih_tm_tr_complete); | |
9789 | ||
9790 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
9791 | _scsih_tm_volume_tr_complete); | |
9792 | ||
9793 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
9794 | _scsih_sas_control_complete); | |
9795 | ||
7497392a | 9796 | return 0; |
f92363d1 SR |
9797 | } |
9798 | ||
9799 | /** | |
7497392a | 9800 | * scsih_exit - exit point for this driver (when it is a module). |
f92363d1 SR |
9801 | * |
9802 | * Returns 0 success, anything else error. | |
9803 | */ | |
8bbb1cf6 | 9804 | static void |
8a7e4c24 | 9805 | scsih_exit(void) |
f92363d1 | 9806 | { |
f92363d1 SR |
9807 | |
9808 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
9809 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
9810 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
9811 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
9812 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
9813 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
9814 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
9815 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
9816 | ||
9817 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
9818 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
9819 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
9820 | ||
9821 | /* raid transport support */ | |
c84b06a4 SR |
9822 | if (hbas_to_enumerate != 1) |
9823 | raid_class_release(mpt3sas_raid_template); | |
9824 | if (hbas_to_enumerate != 2) | |
9825 | raid_class_release(mpt2sas_raid_template); | |
f92363d1 SR |
9826 | sas_release_transport(mpt3sas_transport_template); |
9827 | } | |
7786ab6a | 9828 | |
c84b06a4 SR |
9829 | /** |
9830 | * _mpt3sas_init - main entry point for this driver. | |
9831 | * | |
9832 | * Returns 0 success, anything else error. | |
9833 | */ | |
9834 | static int __init | |
9835 | _mpt3sas_init(void) | |
9836 | { | |
9837 | int error; | |
9838 | ||
9839 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
9840 | MPT3SAS_DRIVER_VERSION); | |
9841 | ||
9842 | mpt3sas_transport_template = | |
9843 | sas_attach_transport(&mpt3sas_transport_functions); | |
9844 | if (!mpt3sas_transport_template) | |
9845 | return -ENODEV; | |
9846 | ||
9847 | /* No need attach mpt3sas raid functions template | |
9848 | * if hbas_to_enumarate value is one. | |
9849 | */ | |
9850 | if (hbas_to_enumerate != 1) { | |
9851 | mpt3sas_raid_template = | |
9852 | raid_class_attach(&mpt3sas_raid_functions); | |
9853 | if (!mpt3sas_raid_template) { | |
9854 | sas_release_transport(mpt3sas_transport_template); | |
9855 | return -ENODEV; | |
9856 | } | |
9857 | } | |
9858 | ||
9859 | /* No need to attach mpt2sas raid functions template | |
9860 | * if hbas_to_enumarate value is two | |
9861 | */ | |
9862 | if (hbas_to_enumerate != 2) { | |
9863 | mpt2sas_raid_template = | |
9864 | raid_class_attach(&mpt2sas_raid_functions); | |
9865 | if (!mpt2sas_raid_template) { | |
9866 | sas_release_transport(mpt3sas_transport_template); | |
9867 | return -ENODEV; | |
9868 | } | |
9869 | } | |
9870 | ||
9871 | error = scsih_init(); | |
9872 | if (error) { | |
9873 | scsih_exit(); | |
9874 | return error; | |
9875 | } | |
9876 | ||
9877 | mpt3sas_ctl_init(hbas_to_enumerate); | |
9878 | ||
9879 | error = pci_register_driver(&mpt3sas_driver); | |
9880 | if (error) | |
9881 | scsih_exit(); | |
9882 | ||
9883 | return error; | |
9884 | } | |
9885 | ||
9886 | /** | |
9887 | * _mpt3sas_exit - exit point for this driver (when it is a module). | |
9888 | * | |
9889 | */ | |
9890 | static void __exit | |
9891 | _mpt3sas_exit(void) | |
9892 | { | |
9893 | pr_info("mpt3sas version %s unloading\n", | |
9894 | MPT3SAS_DRIVER_VERSION); | |
9895 | ||
9896 | pci_unregister_driver(&mpt3sas_driver); | |
9897 | ||
9898 | mpt3sas_ctl_exit(hbas_to_enumerate); | |
9899 | ||
9900 | scsih_exit(); | |
9901 | } | |
9902 | ||
9903 | module_init(_mpt3sas_init); | |
9904 | module_exit(_mpt3sas_exit); |