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 | |
48e3b985 | 5 | * Copyright (C) 2012-2013 LSI Corporation |
f92363d1 SR |
6 | * (mailto:DL-MPTFusionLinux@lsi.com) |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License | |
10 | * as published by the Free Software Foundation; either version 2 | |
11 | * of the License, or (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * NO WARRANTY | |
19 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | |
20 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | |
21 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | |
22 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | |
23 | * solely responsible for determining the appropriateness of using and | |
24 | * distributing the Program and assumes all risks associated with its | |
25 | * exercise of rights under this Agreement, including but not limited to | |
26 | * the risks and costs of program errors, damage to or loss of data, | |
27 | * programs or equipment, and unavailability or interruption of operations. | |
28 | ||
29 | * DISCLAIMER OF LIABILITY | |
30 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | |
31 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
32 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | |
33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
35 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
36 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | |
37 | ||
38 | * You should have received a copy of the GNU General Public License | |
39 | * along with this program; if not, write to the Free Software | |
40 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
41 | * USA. | |
42 | */ | |
43 | ||
f92363d1 SR |
44 | #include <linux/module.h> |
45 | #include <linux/kernel.h> | |
46 | #include <linux/init.h> | |
47 | #include <linux/errno.h> | |
48 | #include <linux/blkdev.h> | |
49 | #include <linux/sched.h> | |
50 | #include <linux/workqueue.h> | |
51 | #include <linux/delay.h> | |
52 | #include <linux/pci.h> | |
53 | #include <linux/interrupt.h> | |
54 | #include <linux/aer.h> | |
55 | #include <linux/raid_class.h> | |
56 | ||
57 | #include "mpt3sas_base.h" | |
58 | ||
59 | MODULE_AUTHOR(MPT3SAS_AUTHOR); | |
60 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); | |
61 | MODULE_LICENSE("GPL"); | |
62 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); | |
63 | ||
64 | #define RAID_CHANNEL 1 | |
65 | /* forward proto's */ | |
66 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
67 | struct _sas_node *sas_expander); | |
68 | static void _firmware_event_work(struct work_struct *work); | |
69 | ||
70 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
71 | struct _sas_device *sas_device); | |
72 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
73 | u8 retry_count, u8 is_pd); | |
74 | ||
75 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); | |
76 | ||
77 | static void _scsih_scan_start(struct Scsi_Host *shost); | |
78 | static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time); | |
79 | ||
80 | /* global parameters */ | |
81 | LIST_HEAD(mpt3sas_ioc_list); | |
82 | ||
83 | /* local parameters */ | |
84 | static u8 scsi_io_cb_idx = -1; | |
85 | static u8 tm_cb_idx = -1; | |
86 | static u8 ctl_cb_idx = -1; | |
87 | static u8 base_cb_idx = -1; | |
88 | static u8 port_enable_cb_idx = -1; | |
89 | static u8 transport_cb_idx = -1; | |
90 | static u8 scsih_cb_idx = -1; | |
91 | static u8 config_cb_idx = -1; | |
92 | static int mpt_ids; | |
93 | ||
94 | static u8 tm_tr_cb_idx = -1 ; | |
95 | static u8 tm_tr_volume_cb_idx = -1 ; | |
96 | static u8 tm_sas_control_cb_idx = -1; | |
97 | ||
98 | /* command line options */ | |
99 | static u32 logging_level; | |
100 | MODULE_PARM_DESC(logging_level, | |
101 | " bits for enabling additional logging info (default=0)"); | |
102 | ||
103 | ||
104 | static ushort max_sectors = 0xFFFF; | |
105 | module_param(max_sectors, ushort, 0); | |
106 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); | |
107 | ||
108 | ||
109 | static int missing_delay[2] = {-1, -1}; | |
110 | module_param_array(missing_delay, int, NULL, 0); | |
111 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | |
112 | ||
113 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | |
114 | #define MPT3SAS_MAX_LUN (16895) | |
1abf635d HR |
115 | static u64 max_lun = MPT3SAS_MAX_LUN; |
116 | module_param(max_lun, ullong, 0); | |
f92363d1 SR |
117 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
118 | ||
119 | ||
120 | ||
121 | ||
122 | /* diag_buffer_enable is bitwise | |
123 | * bit 0 set = TRACE | |
124 | * bit 1 set = SNAPSHOT | |
125 | * bit 2 set = EXTENDED | |
126 | * | |
127 | * Either bit can be set, or both | |
128 | */ | |
129 | static int diag_buffer_enable = -1; | |
130 | module_param(diag_buffer_enable, int, 0); | |
131 | MODULE_PARM_DESC(diag_buffer_enable, | |
132 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | |
133 | static int disable_discovery = -1; | |
134 | module_param(disable_discovery, int, 0); | |
135 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | |
136 | ||
137 | ||
138 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | |
139 | static int prot_mask = -1; | |
140 | module_param(prot_mask, int, 0); | |
141 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | |
142 | ||
143 | ||
144 | /* raid transport support */ | |
145 | ||
146 | static struct raid_template *mpt3sas_raid_template; | |
147 | ||
148 | ||
149 | /** | |
150 | * struct sense_info - common structure for obtaining sense keys | |
151 | * @skey: sense key | |
152 | * @asc: additional sense code | |
153 | * @ascq: additional sense code qualifier | |
154 | */ | |
155 | struct sense_info { | |
156 | u8 skey; | |
157 | u8 asc; | |
158 | u8 ascq; | |
159 | }; | |
160 | ||
161 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) | |
162 | #define MPT3SAS_TURN_ON_FAULT_LED (0xFFFC) | |
163 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) | |
164 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) | |
165 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | |
166 | /** | |
167 | * struct fw_event_work - firmware event struct | |
168 | * @list: link list framework | |
169 | * @work: work object (ioc->fault_reset_work_q) | |
170 | * @cancel_pending_work: flag set during reset handling | |
171 | * @ioc: per adapter object | |
172 | * @device_handle: device handle | |
173 | * @VF_ID: virtual function id | |
174 | * @VP_ID: virtual port id | |
175 | * @ignore: flag meaning this event has been marked to ignore | |
176 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h | |
177 | * @event_data: reply event data payload follows | |
178 | * | |
179 | * This object stored on ioc->fw_event_list. | |
180 | */ | |
181 | struct fw_event_work { | |
182 | struct list_head list; | |
183 | struct work_struct work; | |
184 | u8 cancel_pending_work; | |
185 | struct delayed_work delayed_work; | |
186 | ||
187 | struct MPT3SAS_ADAPTER *ioc; | |
188 | u16 device_handle; | |
189 | u8 VF_ID; | |
190 | u8 VP_ID; | |
191 | u8 ignore; | |
192 | u16 event; | |
35b62362 | 193 | char event_data[0] __aligned(4); |
f92363d1 SR |
194 | }; |
195 | ||
196 | /* raid transport support */ | |
197 | static struct raid_template *mpt3sas_raid_template; | |
198 | ||
199 | /** | |
200 | * struct _scsi_io_transfer - scsi io transfer | |
201 | * @handle: sas device handle (assigned by firmware) | |
202 | * @is_raid: flag set for hidden raid components | |
203 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | |
204 | * @data_length: data transfer length | |
205 | * @data_dma: dma pointer to data | |
206 | * @sense: sense data | |
207 | * @lun: lun number | |
208 | * @cdb_length: cdb length | |
209 | * @cdb: cdb contents | |
210 | * @timeout: timeout for this command | |
211 | * @VF_ID: virtual function id | |
212 | * @VP_ID: virtual port id | |
213 | * @valid_reply: flag set for reply message | |
214 | * @sense_length: sense length | |
215 | * @ioc_status: ioc status | |
216 | * @scsi_state: scsi state | |
217 | * @scsi_status: scsi staus | |
218 | * @log_info: log information | |
219 | * @transfer_length: data length transfer when there is a reply message | |
220 | * | |
221 | * Used for sending internal scsi commands to devices within this module. | |
222 | * Refer to _scsi_send_scsi_io(). | |
223 | */ | |
224 | struct _scsi_io_transfer { | |
225 | u16 handle; | |
226 | u8 is_raid; | |
227 | enum dma_data_direction dir; | |
228 | u32 data_length; | |
229 | dma_addr_t data_dma; | |
230 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | |
231 | u32 lun; | |
232 | u8 cdb_length; | |
233 | u8 cdb[32]; | |
234 | u8 timeout; | |
235 | u8 VF_ID; | |
236 | u8 VP_ID; | |
237 | u8 valid_reply; | |
238 | /* the following bits are only valid when 'valid_reply = 1' */ | |
239 | u32 sense_length; | |
240 | u16 ioc_status; | |
241 | u8 scsi_state; | |
242 | u8 scsi_status; | |
243 | u32 log_info; | |
244 | u32 transfer_length; | |
245 | }; | |
246 | ||
247 | /* | |
248 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | |
249 | */ | |
9baa3c34 | 250 | static const struct pci_device_id scsih_pci_table[] = { |
f92363d1 SR |
251 | /* Fury ~ 3004 and 3008 */ |
252 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, | |
253 | PCI_ANY_ID, PCI_ANY_ID }, | |
254 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, | |
255 | PCI_ANY_ID, PCI_ANY_ID }, | |
256 | /* Invader ~ 3108 */ | |
257 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, | |
258 | PCI_ANY_ID, PCI_ANY_ID }, | |
259 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, | |
260 | PCI_ANY_ID, PCI_ANY_ID }, | |
261 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, | |
262 | PCI_ANY_ID, PCI_ANY_ID }, | |
263 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, | |
264 | PCI_ANY_ID, PCI_ANY_ID }, | |
265 | {0} /* Terminating entry */ | |
266 | }; | |
267 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); | |
268 | ||
269 | /** | |
270 | * _scsih_set_debug_level - global setting of ioc->logging_level. | |
271 | * | |
272 | * Note: The logging levels are defined in mpt3sas_debug.h. | |
273 | */ | |
274 | static int | |
275 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) | |
276 | { | |
277 | int ret = param_set_int(val, kp); | |
278 | struct MPT3SAS_ADAPTER *ioc; | |
279 | ||
280 | if (ret) | |
281 | return ret; | |
282 | ||
283 | pr_info("setting logging_level(0x%08x)\n", logging_level); | |
284 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) | |
285 | ioc->logging_level = logging_level; | |
286 | return 0; | |
287 | } | |
288 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | |
289 | &logging_level, 0644); | |
290 | ||
291 | /** | |
292 | * _scsih_srch_boot_sas_address - search based on sas_address | |
293 | * @sas_address: sas address | |
294 | * @boot_device: boot device object from bios page 2 | |
295 | * | |
296 | * Returns 1 when there's a match, 0 means no match. | |
297 | */ | |
298 | static inline int | |
299 | _scsih_srch_boot_sas_address(u64 sas_address, | |
300 | Mpi2BootDeviceSasWwid_t *boot_device) | |
301 | { | |
302 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | |
303 | } | |
304 | ||
305 | /** | |
306 | * _scsih_srch_boot_device_name - search based on device name | |
307 | * @device_name: device name specified in INDENTIFY fram | |
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_device_name(u64 device_name, | |
314 | Mpi2BootDeviceDeviceName_t *boot_device) | |
315 | { | |
316 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | |
317 | } | |
318 | ||
319 | /** | |
320 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | |
321 | * @enclosure_logical_id: enclosure logical id | |
322 | * @slot_number: slot number | |
323 | * @boot_device: boot device object from bios page 2 | |
324 | * | |
325 | * Returns 1 when there's a match, 0 means no match. | |
326 | */ | |
327 | static inline int | |
328 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | |
329 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | |
330 | { | |
331 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | |
332 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | |
333 | SlotNumber)) ? 1 : 0; | |
334 | } | |
335 | ||
336 | /** | |
337 | * _scsih_is_boot_device - search for matching boot device. | |
338 | * @sas_address: sas address | |
339 | * @device_name: device name specified in INDENTIFY fram | |
340 | * @enclosure_logical_id: enclosure logical id | |
341 | * @slot_number: slot number | |
342 | * @form: specifies boot device form | |
343 | * @boot_device: boot device object from bios page 2 | |
344 | * | |
345 | * Returns 1 when there's a match, 0 means no match. | |
346 | */ | |
347 | static int | |
348 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | |
349 | u64 enclosure_logical_id, u16 slot, u8 form, | |
350 | Mpi2BiosPage2BootDevice_t *boot_device) | |
351 | { | |
352 | int rc = 0; | |
353 | ||
354 | switch (form) { | |
355 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | |
356 | if (!sas_address) | |
357 | break; | |
358 | rc = _scsih_srch_boot_sas_address( | |
359 | sas_address, &boot_device->SasWwid); | |
360 | break; | |
361 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | |
362 | if (!enclosure_logical_id) | |
363 | break; | |
364 | rc = _scsih_srch_boot_encl_slot( | |
365 | enclosure_logical_id, | |
366 | slot, &boot_device->EnclosureSlot); | |
367 | break; | |
368 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | |
369 | if (!device_name) | |
370 | break; | |
371 | rc = _scsih_srch_boot_device_name( | |
372 | device_name, &boot_device->DeviceName); | |
373 | break; | |
374 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | |
375 | break; | |
376 | } | |
377 | ||
378 | return rc; | |
379 | } | |
380 | ||
381 | /** | |
382 | * _scsih_get_sas_address - set the sas_address for given device handle | |
383 | * @handle: device handle | |
384 | * @sas_address: sas address | |
385 | * | |
386 | * Returns 0 success, non-zero when failure | |
387 | */ | |
388 | static int | |
389 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, | |
390 | u64 *sas_address) | |
391 | { | |
392 | Mpi2SasDevicePage0_t sas_device_pg0; | |
393 | Mpi2ConfigReply_t mpi_reply; | |
394 | u32 ioc_status; | |
395 | ||
396 | *sas_address = 0; | |
397 | ||
398 | if (handle <= ioc->sas_hba.num_phys) { | |
399 | *sas_address = ioc->sas_hba.sas_address; | |
400 | return 0; | |
401 | } | |
402 | ||
403 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
404 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
405 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
406 | __FILE__, __LINE__, __func__); | |
407 | return -ENXIO; | |
408 | } | |
409 | ||
410 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
411 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | |
412 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
413 | return 0; | |
414 | } | |
415 | ||
416 | /* we hit this becuase the given parent handle doesn't exist */ | |
417 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) | |
418 | return -ENXIO; | |
419 | ||
420 | /* else error case */ | |
421 | pr_err(MPT3SAS_FMT | |
422 | "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", | |
423 | ioc->name, handle, ioc_status, | |
424 | __FILE__, __LINE__, __func__); | |
425 | return -EIO; | |
426 | } | |
427 | ||
428 | /** | |
429 | * _scsih_determine_boot_device - determine boot device. | |
430 | * @ioc: per adapter object | |
431 | * @device: either sas_device or raid_device object | |
432 | * @is_raid: [flag] 1 = raid object, 0 = sas object | |
433 | * | |
434 | * Determines whether this device should be first reported device to | |
435 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | |
436 | * There are primary, alternate, and current entries in bios page 2. The order | |
437 | * priority is primary, alternate, then current. This routine saves | |
438 | * the corresponding device object and is_raid flag in the ioc object. | |
439 | * The saved data to be used later in _scsih_probe_boot_devices(). | |
440 | */ | |
441 | static void | |
442 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, | |
443 | void *device, u8 is_raid) | |
444 | { | |
445 | struct _sas_device *sas_device; | |
446 | struct _raid_device *raid_device; | |
447 | u64 sas_address; | |
448 | u64 device_name; | |
449 | u64 enclosure_logical_id; | |
450 | u16 slot; | |
451 | ||
452 | /* only process this function when driver loads */ | |
453 | if (!ioc->is_driver_loading) | |
454 | return; | |
455 | ||
456 | /* no Bios, return immediately */ | |
457 | if (!ioc->bios_pg3.BiosVersion) | |
458 | return; | |
459 | ||
460 | if (!is_raid) { | |
461 | sas_device = device; | |
462 | sas_address = sas_device->sas_address; | |
463 | device_name = sas_device->device_name; | |
464 | enclosure_logical_id = sas_device->enclosure_logical_id; | |
465 | slot = sas_device->slot; | |
466 | } else { | |
467 | raid_device = device; | |
468 | sas_address = raid_device->wwid; | |
469 | device_name = 0; | |
470 | enclosure_logical_id = 0; | |
471 | slot = 0; | |
472 | } | |
473 | ||
474 | if (!ioc->req_boot_device.device) { | |
475 | if (_scsih_is_boot_device(sas_address, device_name, | |
476 | enclosure_logical_id, slot, | |
477 | (ioc->bios_pg2.ReqBootDeviceForm & | |
478 | MPI2_BIOSPAGE2_FORM_MASK), | |
479 | &ioc->bios_pg2.RequestedBootDevice)) { | |
480 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
481 | "%s: req_boot_device(0x%016llx)\n", | |
482 | ioc->name, __func__, | |
483 | (unsigned long long)sas_address)); | |
484 | ioc->req_boot_device.device = device; | |
485 | ioc->req_boot_device.is_raid = is_raid; | |
486 | } | |
487 | } | |
488 | ||
489 | if (!ioc->req_alt_boot_device.device) { | |
490 | if (_scsih_is_boot_device(sas_address, device_name, | |
491 | enclosure_logical_id, slot, | |
492 | (ioc->bios_pg2.ReqAltBootDeviceForm & | |
493 | MPI2_BIOSPAGE2_FORM_MASK), | |
494 | &ioc->bios_pg2.RequestedAltBootDevice)) { | |
495 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
496 | "%s: req_alt_boot_device(0x%016llx)\n", | |
497 | ioc->name, __func__, | |
498 | (unsigned long long)sas_address)); | |
499 | ioc->req_alt_boot_device.device = device; | |
500 | ioc->req_alt_boot_device.is_raid = is_raid; | |
501 | } | |
502 | } | |
503 | ||
504 | if (!ioc->current_boot_device.device) { | |
505 | if (_scsih_is_boot_device(sas_address, device_name, | |
506 | enclosure_logical_id, slot, | |
507 | (ioc->bios_pg2.CurrentBootDeviceForm & | |
508 | MPI2_BIOSPAGE2_FORM_MASK), | |
509 | &ioc->bios_pg2.CurrentBootDevice)) { | |
510 | dinitprintk(ioc, pr_info(MPT3SAS_FMT | |
511 | "%s: current_boot_device(0x%016llx)\n", | |
512 | ioc->name, __func__, | |
513 | (unsigned long long)sas_address)); | |
514 | ioc->current_boot_device.device = device; | |
515 | ioc->current_boot_device.is_raid = is_raid; | |
516 | } | |
517 | } | |
518 | } | |
519 | ||
520 | /** | |
521 | * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search | |
522 | * @ioc: per adapter object | |
523 | * @sas_address: sas address | |
524 | * Context: Calling function should acquire ioc->sas_device_lock | |
525 | * | |
526 | * This searches for sas_device based on sas_address, then return sas_device | |
527 | * object. | |
528 | */ | |
529 | struct _sas_device * | |
530 | mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
531 | u64 sas_address) | |
532 | { | |
533 | struct _sas_device *sas_device; | |
534 | ||
535 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
536 | if (sas_device->sas_address == sas_address) | |
537 | return sas_device; | |
538 | ||
539 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
540 | if (sas_device->sas_address == sas_address) | |
541 | return sas_device; | |
542 | ||
543 | return NULL; | |
544 | } | |
545 | ||
546 | /** | |
547 | * _scsih_sas_device_find_by_handle - sas device search | |
548 | * @ioc: per adapter object | |
549 | * @handle: sas device handle (assigned by firmware) | |
550 | * Context: Calling function should acquire ioc->sas_device_lock | |
551 | * | |
552 | * This searches for sas_device based on sas_address, then return sas_device | |
553 | * object. | |
554 | */ | |
555 | static struct _sas_device * | |
556 | _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
557 | { | |
558 | struct _sas_device *sas_device; | |
559 | ||
560 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | |
561 | if (sas_device->handle == handle) | |
562 | return sas_device; | |
563 | ||
564 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | |
565 | if (sas_device->handle == handle) | |
566 | return sas_device; | |
567 | ||
568 | return NULL; | |
569 | } | |
570 | ||
571 | /** | |
572 | * _scsih_sas_device_remove - remove sas_device from list. | |
573 | * @ioc: per adapter object | |
574 | * @sas_device: the sas_device object | |
575 | * Context: This function will acquire ioc->sas_device_lock. | |
576 | * | |
577 | * Removing object and freeing associated memory from the ioc->sas_device_list. | |
578 | */ | |
579 | static void | |
580 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
581 | struct _sas_device *sas_device) | |
582 | { | |
583 | unsigned long flags; | |
584 | ||
585 | if (!sas_device) | |
586 | return; | |
587 | ||
588 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
589 | list_del(&sas_device->list); | |
590 | kfree(sas_device); | |
591 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
592 | } | |
593 | ||
594 | /** | |
595 | * _scsih_device_remove_by_handle - removing device object by handle | |
596 | * @ioc: per adapter object | |
597 | * @handle: device handle | |
598 | * | |
599 | * Return nothing. | |
600 | */ | |
601 | static void | |
602 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
603 | { | |
604 | struct _sas_device *sas_device; | |
605 | unsigned long flags; | |
606 | ||
607 | if (ioc->shost_recovery) | |
608 | return; | |
609 | ||
610 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
611 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
612 | if (sas_device) | |
613 | list_del(&sas_device->list); | |
614 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
615 | if (sas_device) | |
616 | _scsih_remove_device(ioc, sas_device); | |
617 | } | |
618 | ||
619 | /** | |
620 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address | |
621 | * @ioc: per adapter object | |
622 | * @sas_address: device sas_address | |
623 | * | |
624 | * Return nothing. | |
625 | */ | |
626 | void | |
627 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
628 | u64 sas_address) | |
629 | { | |
630 | struct _sas_device *sas_device; | |
631 | unsigned long flags; | |
632 | ||
633 | if (ioc->shost_recovery) | |
634 | return; | |
635 | ||
636 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
637 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
638 | sas_address); | |
639 | if (sas_device) | |
640 | list_del(&sas_device->list); | |
641 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
642 | if (sas_device) | |
643 | _scsih_remove_device(ioc, sas_device); | |
644 | } | |
645 | ||
646 | /** | |
647 | * _scsih_sas_device_add - insert sas_device to the list. | |
648 | * @ioc: per adapter object | |
649 | * @sas_device: the sas_device object | |
650 | * Context: This function will acquire ioc->sas_device_lock. | |
651 | * | |
652 | * Adding new object to the ioc->sas_device_list. | |
653 | */ | |
654 | static void | |
655 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, | |
656 | struct _sas_device *sas_device) | |
657 | { | |
658 | unsigned long flags; | |
659 | ||
660 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
661 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", | |
662 | ioc->name, __func__, sas_device->handle, | |
663 | (unsigned long long)sas_device->sas_address)); | |
664 | ||
665 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
666 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | |
667 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
668 | ||
669 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, | |
670 | sas_device->sas_address_parent)) { | |
671 | _scsih_sas_device_remove(ioc, sas_device); | |
672 | } else if (!sas_device->starget) { | |
673 | /* | |
674 | * When asyn scanning is enabled, its not possible to remove | |
675 | * devices while scanning is turned on due to an oops in | |
676 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | |
677 | */ | |
f5edbe77 | 678 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
679 | mpt3sas_transport_port_remove(ioc, |
680 | sas_device->sas_address, | |
681 | sas_device->sas_address_parent); | |
f5edbe77 SR |
682 | _scsih_sas_device_remove(ioc, sas_device); |
683 | } | |
f92363d1 SR |
684 | } |
685 | } | |
686 | ||
687 | /** | |
688 | * _scsih_sas_device_init_add - insert sas_device to the list. | |
689 | * @ioc: per adapter object | |
690 | * @sas_device: the sas_device object | |
691 | * Context: This function will acquire ioc->sas_device_lock. | |
692 | * | |
693 | * Adding new object at driver load time to the ioc->sas_device_init_list. | |
694 | */ | |
695 | static void | |
696 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, | |
697 | struct _sas_device *sas_device) | |
698 | { | |
699 | unsigned long flags; | |
700 | ||
701 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
702 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
703 | __func__, sas_device->handle, | |
704 | (unsigned long long)sas_device->sas_address)); | |
705 | ||
706 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
707 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); | |
708 | _scsih_determine_boot_device(ioc, sas_device, 0); | |
709 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
710 | } | |
711 | ||
712 | /** | |
713 | * _scsih_raid_device_find_by_id - raid device search | |
714 | * @ioc: per adapter object | |
715 | * @id: sas device target id | |
716 | * @channel: sas device channel | |
717 | * Context: Calling function should acquire ioc->raid_device_lock | |
718 | * | |
719 | * This searches for raid_device based on target id, then return raid_device | |
720 | * object. | |
721 | */ | |
722 | static struct _raid_device * | |
723 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) | |
724 | { | |
725 | struct _raid_device *raid_device, *r; | |
726 | ||
727 | r = NULL; | |
728 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
729 | if (raid_device->id == id && raid_device->channel == channel) { | |
730 | r = raid_device; | |
731 | goto out; | |
732 | } | |
733 | } | |
734 | ||
735 | out: | |
736 | return r; | |
737 | } | |
738 | ||
739 | /** | |
740 | * _scsih_raid_device_find_by_handle - raid device search | |
741 | * @ioc: per adapter object | |
742 | * @handle: sas device handle (assigned by firmware) | |
743 | * Context: Calling function should acquire ioc->raid_device_lock | |
744 | * | |
745 | * This searches for raid_device based on handle, then return raid_device | |
746 | * object. | |
747 | */ | |
748 | static struct _raid_device * | |
749 | _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
750 | { | |
751 | struct _raid_device *raid_device, *r; | |
752 | ||
753 | r = NULL; | |
754 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
755 | if (raid_device->handle != handle) | |
756 | continue; | |
757 | r = raid_device; | |
758 | goto out; | |
759 | } | |
760 | ||
761 | out: | |
762 | return r; | |
763 | } | |
764 | ||
765 | /** | |
766 | * _scsih_raid_device_find_by_wwid - raid device search | |
767 | * @ioc: per adapter object | |
768 | * @handle: sas device handle (assigned by firmware) | |
769 | * Context: Calling function should acquire ioc->raid_device_lock | |
770 | * | |
771 | * This searches for raid_device based on wwid, then return raid_device | |
772 | * object. | |
773 | */ | |
774 | static struct _raid_device * | |
775 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) | |
776 | { | |
777 | struct _raid_device *raid_device, *r; | |
778 | ||
779 | r = NULL; | |
780 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
781 | if (raid_device->wwid != wwid) | |
782 | continue; | |
783 | r = raid_device; | |
784 | goto out; | |
785 | } | |
786 | ||
787 | out: | |
788 | return r; | |
789 | } | |
790 | ||
791 | /** | |
792 | * _scsih_raid_device_add - add raid_device object | |
793 | * @ioc: per adapter object | |
794 | * @raid_device: raid_device object | |
795 | * | |
796 | * This is added to the raid_device_list link list. | |
797 | */ | |
798 | static void | |
799 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, | |
800 | struct _raid_device *raid_device) | |
801 | { | |
802 | unsigned long flags; | |
803 | ||
804 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
805 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | |
806 | raid_device->handle, (unsigned long long)raid_device->wwid)); | |
807 | ||
808 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
809 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | |
810 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
811 | } | |
812 | ||
813 | /** | |
814 | * _scsih_raid_device_remove - delete raid_device object | |
815 | * @ioc: per adapter object | |
816 | * @raid_device: raid_device object | |
817 | * | |
818 | */ | |
819 | static void | |
820 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, | |
821 | struct _raid_device *raid_device) | |
822 | { | |
823 | unsigned long flags; | |
824 | ||
825 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
826 | list_del(&raid_device->list); | |
827 | kfree(raid_device); | |
828 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
829 | } | |
830 | ||
831 | /** | |
832 | * mpt3sas_scsih_expander_find_by_handle - expander device search | |
833 | * @ioc: per adapter object | |
834 | * @handle: expander handle (assigned by firmware) | |
835 | * Context: Calling function should acquire ioc->sas_device_lock | |
836 | * | |
837 | * This searches for expander device based on handle, then returns the | |
838 | * sas_node object. | |
839 | */ | |
840 | struct _sas_node * | |
841 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
842 | { | |
843 | struct _sas_node *sas_expander, *r; | |
844 | ||
845 | r = NULL; | |
846 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
847 | if (sas_expander->handle != handle) | |
848 | continue; | |
849 | r = sas_expander; | |
850 | goto out; | |
851 | } | |
852 | out: | |
853 | return r; | |
854 | } | |
855 | ||
856 | /** | |
857 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search | |
858 | * @ioc: per adapter object | |
859 | * @sas_address: sas address | |
860 | * Context: Calling function should acquire ioc->sas_node_lock. | |
861 | * | |
862 | * This searches for expander device based on sas_address, then returns the | |
863 | * sas_node object. | |
864 | */ | |
865 | struct _sas_node * | |
866 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, | |
867 | u64 sas_address) | |
868 | { | |
869 | struct _sas_node *sas_expander, *r; | |
870 | ||
871 | r = NULL; | |
872 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
873 | if (sas_expander->sas_address != sas_address) | |
874 | continue; | |
875 | r = sas_expander; | |
876 | goto out; | |
877 | } | |
878 | out: | |
879 | return r; | |
880 | } | |
881 | ||
882 | /** | |
883 | * _scsih_expander_node_add - insert expander device to the list. | |
884 | * @ioc: per adapter object | |
885 | * @sas_expander: the sas_device object | |
886 | * Context: This function will acquire ioc->sas_node_lock. | |
887 | * | |
888 | * Adding new object to the ioc->sas_expander_list. | |
889 | * | |
890 | * Return nothing. | |
891 | */ | |
892 | static void | |
893 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, | |
894 | struct _sas_node *sas_expander) | |
895 | { | |
896 | unsigned long flags; | |
897 | ||
898 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
899 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | |
900 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
901 | } | |
902 | ||
903 | /** | |
904 | * _scsih_is_end_device - determines if device is an end device | |
905 | * @device_info: bitfield providing information about the device. | |
906 | * Context: none | |
907 | * | |
908 | * Returns 1 if end device. | |
909 | */ | |
910 | static int | |
911 | _scsih_is_end_device(u32 device_info) | |
912 | { | |
913 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | |
914 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | |
915 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | |
916 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | |
917 | return 1; | |
918 | else | |
919 | return 0; | |
920 | } | |
921 | ||
922 | /** | |
923 | * _scsih_scsi_lookup_get - returns scmd entry | |
924 | * @ioc: per adapter object | |
925 | * @smid: system request message index | |
926 | * | |
927 | * Returns the smid stored scmd pointer. | |
928 | */ | |
929 | static struct scsi_cmnd * | |
930 | _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
931 | { | |
932 | return ioc->scsi_lookup[smid - 1].scmd; | |
933 | } | |
934 | ||
935 | /** | |
936 | * _scsih_scsi_lookup_get_clear - returns scmd entry | |
937 | * @ioc: per adapter object | |
938 | * @smid: system request message index | |
939 | * | |
940 | * Returns the smid stored scmd pointer. | |
941 | * Then will derefrence the stored scmd pointer. | |
942 | */ | |
943 | static inline struct scsi_cmnd * | |
944 | _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
945 | { | |
946 | unsigned long flags; | |
947 | struct scsi_cmnd *scmd; | |
948 | ||
949 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
950 | scmd = ioc->scsi_lookup[smid - 1].scmd; | |
951 | ioc->scsi_lookup[smid - 1].scmd = NULL; | |
952 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
953 | ||
954 | return scmd; | |
955 | } | |
956 | ||
957 | /** | |
958 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup | |
959 | * @ioc: per adapter object | |
960 | * @smid: system request message index | |
961 | * @scmd: pointer to scsi command object | |
962 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
963 | * | |
964 | * This will search for a scmd pointer in the scsi_lookup array, | |
965 | * returning the revelent smid. A returned value of zero means invalid. | |
966 | */ | |
967 | static u16 | |
968 | _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd | |
969 | *scmd) | |
970 | { | |
971 | u16 smid; | |
972 | unsigned long flags; | |
973 | int i; | |
974 | ||
975 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
976 | smid = 0; | |
977 | for (i = 0; i < ioc->scsiio_depth; i++) { | |
978 | if (ioc->scsi_lookup[i].scmd == scmd) { | |
979 | smid = ioc->scsi_lookup[i].smid; | |
980 | goto out; | |
981 | } | |
982 | } | |
983 | out: | |
984 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
985 | return smid; | |
986 | } | |
987 | ||
988 | /** | |
989 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id | |
990 | * @ioc: per adapter object | |
991 | * @id: target id | |
992 | * @channel: channel | |
993 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
994 | * | |
995 | * This will search for a matching channel:id in the scsi_lookup array, | |
996 | * returning 1 if found. | |
997 | */ | |
998 | static u8 | |
999 | _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id, | |
1000 | int channel) | |
1001 | { | |
1002 | u8 found; | |
1003 | unsigned long flags; | |
1004 | int i; | |
1005 | ||
1006 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1007 | found = 0; | |
1008 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1009 | if (ioc->scsi_lookup[i].scmd && | |
1010 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1011 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { | |
1012 | found = 1; | |
1013 | goto out; | |
1014 | } | |
1015 | } | |
1016 | out: | |
1017 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1018 | return found; | |
1019 | } | |
1020 | ||
1021 | /** | |
1022 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun | |
1023 | * @ioc: per adapter object | |
1024 | * @id: target id | |
1025 | * @lun: lun number | |
1026 | * @channel: channel | |
1027 | * Context: This function will acquire ioc->scsi_lookup_lock. | |
1028 | * | |
1029 | * This will search for a matching channel:id:lun in the scsi_lookup array, | |
1030 | * returning 1 if found. | |
1031 | */ | |
1032 | static u8 | |
1033 | _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id, | |
1034 | unsigned int lun, int channel) | |
1035 | { | |
1036 | u8 found; | |
1037 | unsigned long flags; | |
1038 | int i; | |
1039 | ||
1040 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
1041 | found = 0; | |
1042 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | |
1043 | if (ioc->scsi_lookup[i].scmd && | |
1044 | (ioc->scsi_lookup[i].scmd->device->id == id && | |
1045 | ioc->scsi_lookup[i].scmd->device->channel == channel && | |
1046 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { | |
1047 | found = 1; | |
1048 | goto out; | |
1049 | } | |
1050 | } | |
1051 | out: | |
1052 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
1053 | return found; | |
1054 | } | |
1055 | ||
1056 | ||
1057 | static void | |
1058 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) | |
1059 | { | |
1060 | struct Scsi_Host *shost = sdev->host; | |
1061 | int max_depth; | |
1062 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1063 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1064 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1065 | struct _sas_device *sas_device; | |
1066 | unsigned long flags; | |
1067 | ||
1068 | max_depth = shost->can_queue; | |
1069 | ||
1070 | /* limit max device queue for SATA to 32 */ | |
1071 | sas_device_priv_data = sdev->hostdata; | |
1072 | if (!sas_device_priv_data) | |
1073 | goto not_sata; | |
1074 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1075 | if (!sas_target_priv_data) | |
1076 | goto not_sata; | |
1077 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | |
1078 | goto not_sata; | |
1079 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1080 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1081 | sas_device_priv_data->sas_target->sas_address); | |
1082 | if (sas_device && sas_device->device_info & | |
1083 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1084 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1085 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1086 | ||
1087 | not_sata: | |
1088 | ||
1089 | if (!sdev->tagged_supported) | |
1090 | max_depth = 1; | |
1091 | if (qdepth > max_depth) | |
1092 | qdepth = max_depth; | |
1093 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | |
1094 | } | |
1095 | ||
1096 | /** | |
1097 | * _scsih_change_queue_depth - setting device queue depth | |
1098 | * @sdev: scsi device struct | |
1099 | * @qdepth: requested queue depth | |
1100 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP | |
1101 | * (see include/scsi/scsi_host.h for definition) | |
1102 | * | |
1103 | * Returns queue depth. | |
1104 | */ | |
1105 | static int | |
1106 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) | |
1107 | { | |
1108 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) | |
1109 | _scsih_adjust_queue_depth(sdev, qdepth); | |
1110 | else if (reason == SCSI_QDEPTH_QFULL) | |
1111 | scsi_track_queue_full(sdev, qdepth); | |
1112 | else | |
1113 | return -EOPNOTSUPP; | |
1114 | ||
1115 | if (sdev->inquiry_len > 7) | |
1116 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \ | |
1117 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", | |
1118 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, | |
1119 | sdev->ordered_tags, sdev->scsi_level, | |
1120 | (sdev->inquiry[7] & 2) >> 1); | |
1121 | ||
1122 | return sdev->queue_depth; | |
1123 | } | |
1124 | ||
1125 | /** | |
1126 | * _scsih_change_queue_type - changing device queue tag type | |
1127 | * @sdev: scsi device struct | |
1128 | * @tag_type: requested tag type | |
1129 | * | |
1130 | * Returns queue tag type. | |
1131 | */ | |
1132 | static int | |
1133 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) | |
1134 | { | |
1135 | if (sdev->tagged_supported) { | |
1136 | scsi_set_tag_type(sdev, tag_type); | |
1137 | if (tag_type) | |
1138 | scsi_activate_tcq(sdev, sdev->queue_depth); | |
1139 | else | |
1140 | scsi_deactivate_tcq(sdev, sdev->queue_depth); | |
1141 | } else | |
1142 | tag_type = 0; | |
1143 | ||
1144 | return tag_type; | |
1145 | } | |
1146 | ||
1147 | ||
1148 | /** | |
1149 | * _scsih_target_alloc - target add routine | |
1150 | * @starget: scsi target struct | |
1151 | * | |
1152 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1153 | * the device is ignored. | |
1154 | */ | |
1155 | static int | |
1156 | _scsih_target_alloc(struct scsi_target *starget) | |
1157 | { | |
1158 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1159 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1160 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1161 | struct _sas_device *sas_device; | |
1162 | struct _raid_device *raid_device; | |
1163 | unsigned long flags; | |
1164 | struct sas_rphy *rphy; | |
1165 | ||
62c4da44 JL |
1166 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
1167 | GFP_KERNEL); | |
f92363d1 SR |
1168 | if (!sas_target_priv_data) |
1169 | return -ENOMEM; | |
1170 | ||
1171 | starget->hostdata = sas_target_priv_data; | |
1172 | sas_target_priv_data->starget = starget; | |
1173 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
1174 | ||
1175 | /* RAID volumes */ | |
1176 | if (starget->channel == RAID_CHANNEL) { | |
1177 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1178 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1179 | starget->channel); | |
1180 | if (raid_device) { | |
1181 | sas_target_priv_data->handle = raid_device->handle; | |
1182 | sas_target_priv_data->sas_address = raid_device->wwid; | |
1183 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | |
1184 | raid_device->starget = starget; | |
1185 | } | |
1186 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1187 | return 0; | |
1188 | } | |
1189 | ||
1190 | /* sas/sata devices */ | |
1191 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1192 | rphy = dev_to_rphy(starget->dev.parent); | |
1193 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1194 | rphy->identify.sas_address); | |
1195 | ||
1196 | if (sas_device) { | |
1197 | sas_target_priv_data->handle = sas_device->handle; | |
1198 | sas_target_priv_data->sas_address = sas_device->sas_address; | |
1199 | sas_device->starget = starget; | |
1200 | sas_device->id = starget->id; | |
1201 | sas_device->channel = starget->channel; | |
1202 | if (test_bit(sas_device->handle, ioc->pd_handles)) | |
1203 | sas_target_priv_data->flags |= | |
1204 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
1205 | if (sas_device->fast_path) | |
1206 | sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO; | |
1207 | } | |
1208 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1209 | ||
1210 | return 0; | |
1211 | } | |
1212 | ||
1213 | /** | |
1214 | * _scsih_target_destroy - target destroy routine | |
1215 | * @starget: scsi target struct | |
1216 | * | |
1217 | * Returns nothing. | |
1218 | */ | |
1219 | static void | |
1220 | _scsih_target_destroy(struct scsi_target *starget) | |
1221 | { | |
1222 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | |
1223 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1224 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1225 | struct _sas_device *sas_device; | |
1226 | struct _raid_device *raid_device; | |
1227 | unsigned long flags; | |
1228 | struct sas_rphy *rphy; | |
1229 | ||
1230 | sas_target_priv_data = starget->hostdata; | |
1231 | if (!sas_target_priv_data) | |
1232 | return; | |
1233 | ||
1234 | if (starget->channel == RAID_CHANNEL) { | |
1235 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1236 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | |
1237 | starget->channel); | |
1238 | if (raid_device) { | |
1239 | raid_device->starget = NULL; | |
1240 | raid_device->sdev = NULL; | |
1241 | } | |
1242 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1243 | goto out; | |
1244 | } | |
1245 | ||
1246 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1247 | rphy = dev_to_rphy(starget->dev.parent); | |
1248 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1249 | rphy->identify.sas_address); | |
1250 | if (sas_device && (sas_device->starget == starget) && | |
1251 | (sas_device->id == starget->id) && | |
1252 | (sas_device->channel == starget->channel)) | |
1253 | sas_device->starget = NULL; | |
1254 | ||
1255 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1256 | ||
1257 | out: | |
1258 | kfree(sas_target_priv_data); | |
1259 | starget->hostdata = NULL; | |
1260 | } | |
1261 | ||
1262 | /** | |
1263 | * _scsih_slave_alloc - device add routine | |
1264 | * @sdev: scsi device struct | |
1265 | * | |
1266 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1267 | * the device is ignored. | |
1268 | */ | |
1269 | static int | |
1270 | _scsih_slave_alloc(struct scsi_device *sdev) | |
1271 | { | |
1272 | struct Scsi_Host *shost; | |
1273 | struct MPT3SAS_ADAPTER *ioc; | |
1274 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1275 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1276 | struct scsi_target *starget; | |
1277 | struct _raid_device *raid_device; | |
b65cfedf | 1278 | struct _sas_device *sas_device; |
f92363d1 SR |
1279 | unsigned long flags; |
1280 | ||
62c4da44 JL |
1281 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
1282 | GFP_KERNEL); | |
f92363d1 SR |
1283 | if (!sas_device_priv_data) |
1284 | return -ENOMEM; | |
1285 | ||
1286 | sas_device_priv_data->lun = sdev->lun; | |
1287 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | |
1288 | ||
1289 | starget = scsi_target(sdev); | |
1290 | sas_target_priv_data = starget->hostdata; | |
1291 | sas_target_priv_data->num_luns++; | |
1292 | sas_device_priv_data->sas_target = sas_target_priv_data; | |
1293 | sdev->hostdata = sas_device_priv_data; | |
1294 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | |
1295 | sdev->no_uld_attach = 1; | |
1296 | ||
1297 | shost = dev_to_shost(&starget->dev); | |
1298 | ioc = shost_priv(shost); | |
1299 | if (starget->channel == RAID_CHANNEL) { | |
1300 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1301 | raid_device = _scsih_raid_device_find_by_id(ioc, | |
1302 | starget->id, starget->channel); | |
1303 | if (raid_device) | |
1304 | raid_device->sdev = sdev; /* raid is single lun */ | |
1305 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1306 | } | |
1307 | ||
b65cfedf SR |
1308 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
1309 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1310 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1311 | sas_target_priv_data->sas_address); | |
1312 | if (sas_device && (sas_device->starget == NULL)) { | |
1313 | sdev_printk(KERN_INFO, sdev, | |
1314 | "%s : sas_device->starget set to starget @ %d\n", | |
1315 | __func__, __LINE__); | |
1316 | sas_device->starget = starget; | |
1317 | } | |
1318 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1319 | } | |
1320 | ||
f92363d1 SR |
1321 | return 0; |
1322 | } | |
1323 | ||
1324 | /** | |
1325 | * _scsih_slave_destroy - device destroy routine | |
1326 | * @sdev: scsi device struct | |
1327 | * | |
1328 | * Returns nothing. | |
1329 | */ | |
1330 | static void | |
1331 | _scsih_slave_destroy(struct scsi_device *sdev) | |
1332 | { | |
1333 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1334 | struct scsi_target *starget; | |
1335 | struct Scsi_Host *shost; | |
1336 | struct MPT3SAS_ADAPTER *ioc; | |
1337 | struct _sas_device *sas_device; | |
1338 | unsigned long flags; | |
1339 | ||
1340 | if (!sdev->hostdata) | |
1341 | return; | |
1342 | ||
1343 | starget = scsi_target(sdev); | |
1344 | sas_target_priv_data = starget->hostdata; | |
1345 | sas_target_priv_data->num_luns--; | |
1346 | ||
1347 | shost = dev_to_shost(&starget->dev); | |
1348 | ioc = shost_priv(shost); | |
1349 | ||
1350 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | |
1351 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1352 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1353 | sas_target_priv_data->sas_address); | |
1354 | if (sas_device && !sas_target_priv_data->num_luns) | |
1355 | sas_device->starget = NULL; | |
1356 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1357 | } | |
1358 | ||
1359 | kfree(sdev->hostdata); | |
1360 | sdev->hostdata = NULL; | |
1361 | } | |
1362 | ||
1363 | /** | |
1364 | * _scsih_display_sata_capabilities - sata capabilities | |
1365 | * @ioc: per adapter object | |
1366 | * @handle: device handle | |
1367 | * @sdev: scsi device struct | |
1368 | */ | |
1369 | static void | |
1370 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1371 | u16 handle, struct scsi_device *sdev) | |
1372 | { | |
1373 | Mpi2ConfigReply_t mpi_reply; | |
1374 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1375 | u32 ioc_status; | |
1376 | u16 flags; | |
1377 | u32 device_info; | |
1378 | ||
1379 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
1380 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
1381 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1382 | ioc->name, __FILE__, __LINE__, __func__); | |
1383 | return; | |
1384 | } | |
1385 | ||
1386 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
1387 | MPI2_IOCSTATUS_MASK; | |
1388 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
1389 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1390 | ioc->name, __FILE__, __LINE__, __func__); | |
1391 | return; | |
1392 | } | |
1393 | ||
1394 | flags = le16_to_cpu(sas_device_pg0.Flags); | |
1395 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1396 | ||
1397 | sdev_printk(KERN_INFO, sdev, | |
1398 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | |
1399 | "sw_preserve(%s)\n", | |
1400 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | |
1401 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | |
1402 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | |
1403 | "n", | |
1404 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | |
1405 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | |
1406 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | |
1407 | } | |
1408 | ||
1409 | /* | |
1410 | * raid transport support - | |
1411 | * Enabled for SLES11 and newer, in older kernels the driver will panic when | |
1412 | * unloading the driver followed by a load - I beleive that the subroutine | |
1413 | * raid_class_release() is not cleaning up properly. | |
1414 | */ | |
1415 | ||
1416 | /** | |
1417 | * _scsih_is_raid - return boolean indicating device is raid volume | |
1418 | * @dev the device struct object | |
1419 | */ | |
1420 | static int | |
1421 | _scsih_is_raid(struct device *dev) | |
1422 | { | |
1423 | struct scsi_device *sdev = to_scsi_device(dev); | |
1424 | ||
1425 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; | |
1426 | } | |
1427 | ||
1428 | /** | |
1429 | * _scsih_get_resync - get raid volume resync percent complete | |
1430 | * @dev the device struct object | |
1431 | */ | |
1432 | static void | |
1433 | _scsih_get_resync(struct device *dev) | |
1434 | { | |
1435 | struct scsi_device *sdev = to_scsi_device(dev); | |
1436 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1437 | static struct _raid_device *raid_device; | |
1438 | unsigned long flags; | |
1439 | Mpi2RaidVolPage0_t vol_pg0; | |
1440 | Mpi2ConfigReply_t mpi_reply; | |
1441 | u32 volume_status_flags; | |
1442 | u8 percent_complete; | |
1443 | u16 handle; | |
1444 | ||
1445 | percent_complete = 0; | |
1446 | handle = 0; | |
1447 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1448 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1449 | sdev->channel); | |
1450 | if (raid_device) { | |
1451 | handle = raid_device->handle; | |
1452 | percent_complete = raid_device->percent_complete; | |
1453 | } | |
1454 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1455 | ||
1456 | if (!handle) | |
1457 | goto out; | |
1458 | ||
1459 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1460 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1461 | sizeof(Mpi2RaidVolPage0_t))) { | |
1462 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1463 | ioc->name, __FILE__, __LINE__, __func__); | |
1464 | percent_complete = 0; | |
1465 | goto out; | |
1466 | } | |
1467 | ||
1468 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1469 | if (!(volume_status_flags & | |
1470 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | |
1471 | percent_complete = 0; | |
1472 | ||
1473 | out: | |
1474 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); | |
1475 | } | |
1476 | ||
1477 | /** | |
1478 | * _scsih_get_state - get raid volume level | |
1479 | * @dev the device struct object | |
1480 | */ | |
1481 | static void | |
1482 | _scsih_get_state(struct device *dev) | |
1483 | { | |
1484 | struct scsi_device *sdev = to_scsi_device(dev); | |
1485 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); | |
1486 | static struct _raid_device *raid_device; | |
1487 | unsigned long flags; | |
1488 | Mpi2RaidVolPage0_t vol_pg0; | |
1489 | Mpi2ConfigReply_t mpi_reply; | |
1490 | u32 volstate; | |
1491 | enum raid_state state = RAID_STATE_UNKNOWN; | |
1492 | u16 handle = 0; | |
1493 | ||
1494 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1495 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | |
1496 | sdev->channel); | |
1497 | if (raid_device) | |
1498 | handle = raid_device->handle; | |
1499 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1500 | ||
1501 | if (!raid_device) | |
1502 | goto out; | |
1503 | ||
1504 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | |
1505 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
1506 | sizeof(Mpi2RaidVolPage0_t))) { | |
1507 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
1508 | ioc->name, __FILE__, __LINE__, __func__); | |
1509 | goto out; | |
1510 | } | |
1511 | ||
1512 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | |
1513 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | |
1514 | state = RAID_STATE_RESYNCING; | |
1515 | goto out; | |
1516 | } | |
1517 | ||
1518 | switch (vol_pg0.VolumeState) { | |
1519 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
1520 | case MPI2_RAID_VOL_STATE_ONLINE: | |
1521 | state = RAID_STATE_ACTIVE; | |
1522 | break; | |
1523 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
1524 | state = RAID_STATE_DEGRADED; | |
1525 | break; | |
1526 | case MPI2_RAID_VOL_STATE_FAILED: | |
1527 | case MPI2_RAID_VOL_STATE_MISSING: | |
1528 | state = RAID_STATE_OFFLINE; | |
1529 | break; | |
1530 | } | |
1531 | out: | |
1532 | raid_set_state(mpt3sas_raid_template, dev, state); | |
1533 | } | |
1534 | ||
1535 | /** | |
1536 | * _scsih_set_level - set raid level | |
1537 | * @sdev: scsi device struct | |
1538 | * @volume_type: volume type | |
1539 | */ | |
1540 | static void | |
1541 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) | |
1542 | { | |
1543 | enum raid_level level = RAID_LEVEL_UNKNOWN; | |
1544 | ||
1545 | switch (volume_type) { | |
1546 | case MPI2_RAID_VOL_TYPE_RAID0: | |
1547 | level = RAID_LEVEL_0; | |
1548 | break; | |
1549 | case MPI2_RAID_VOL_TYPE_RAID10: | |
1550 | level = RAID_LEVEL_10; | |
1551 | break; | |
1552 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
1553 | level = RAID_LEVEL_1E; | |
1554 | break; | |
1555 | case MPI2_RAID_VOL_TYPE_RAID1: | |
1556 | level = RAID_LEVEL_1; | |
1557 | break; | |
1558 | } | |
1559 | ||
1560 | raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level); | |
1561 | } | |
1562 | ||
1563 | ||
1564 | /** | |
1565 | * _scsih_get_volume_capabilities - volume capabilities | |
1566 | * @ioc: per adapter object | |
1567 | * @sas_device: the raid_device object | |
1568 | * | |
1569 | * Returns 0 for success, else 1 | |
1570 | */ | |
1571 | static int | |
1572 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, | |
1573 | struct _raid_device *raid_device) | |
1574 | { | |
1575 | Mpi2RaidVolPage0_t *vol_pg0; | |
1576 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
1577 | Mpi2SasDevicePage0_t sas_device_pg0; | |
1578 | Mpi2ConfigReply_t mpi_reply; | |
1579 | u16 sz; | |
1580 | u8 num_pds; | |
1581 | ||
1582 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, | |
1583 | &num_pds)) || !num_pds) { | |
1584 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1585 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1586 | __func__)); | |
1587 | return 1; | |
1588 | } | |
1589 | ||
1590 | raid_device->num_pds = num_pds; | |
1591 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | |
1592 | sizeof(Mpi2RaidVol0PhysDisk_t)); | |
1593 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | |
1594 | if (!vol_pg0) { | |
1595 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1596 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1597 | __func__)); | |
1598 | return 1; | |
1599 | } | |
1600 | ||
1601 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | |
1602 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | |
1603 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1604 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1605 | __func__)); | |
1606 | kfree(vol_pg0); | |
1607 | return 1; | |
1608 | } | |
1609 | ||
1610 | raid_device->volume_type = vol_pg0->VolumeType; | |
1611 | ||
1612 | /* figure out what the underlying devices are by | |
1613 | * obtaining the device_info bits for the 1st device | |
1614 | */ | |
1615 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
1616 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | |
1617 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | |
1618 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
1619 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
1620 | le16_to_cpu(pd_pg0.DevHandle)))) { | |
1621 | raid_device->device_info = | |
1622 | le32_to_cpu(sas_device_pg0.DeviceInfo); | |
1623 | } | |
1624 | } | |
1625 | ||
1626 | kfree(vol_pg0); | |
1627 | return 0; | |
1628 | } | |
1629 | ||
1630 | ||
1631 | ||
1632 | /** | |
1633 | * _scsih_enable_tlr - setting TLR flags | |
1634 | * @ioc: per adapter object | |
1635 | * @sdev: scsi device struct | |
1636 | * | |
1637 | * Enabling Transaction Layer Retries for tape devices when | |
1638 | * vpd page 0x90 is present | |
1639 | * | |
1640 | */ | |
1641 | static void | |
1642 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) | |
1643 | { | |
1644 | ||
1645 | /* only for TAPE */ | |
1646 | if (sdev->type != TYPE_TAPE) | |
1647 | return; | |
1648 | ||
1649 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | |
1650 | return; | |
1651 | ||
1652 | sas_enable_tlr(sdev); | |
1653 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | |
1654 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | |
1655 | return; | |
1656 | ||
1657 | } | |
1658 | ||
1659 | /** | |
1660 | * _scsih_slave_configure - device configure routine. | |
1661 | * @sdev: scsi device struct | |
1662 | * | |
1663 | * Returns 0 if ok. Any other return is assumed to be an error and | |
1664 | * the device is ignored. | |
1665 | */ | |
1666 | static int | |
1667 | _scsih_slave_configure(struct scsi_device *sdev) | |
1668 | { | |
1669 | struct Scsi_Host *shost = sdev->host; | |
1670 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
1671 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1672 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
1673 | struct _sas_device *sas_device; | |
1674 | struct _raid_device *raid_device; | |
1675 | unsigned long flags; | |
1676 | int qdepth; | |
1677 | u8 ssp_target = 0; | |
1678 | char *ds = ""; | |
1679 | char *r_level = ""; | |
1680 | u16 handle, volume_handle = 0; | |
1681 | u64 volume_wwid = 0; | |
1682 | ||
1683 | qdepth = 1; | |
1684 | sas_device_priv_data = sdev->hostdata; | |
1685 | sas_device_priv_data->configured_lun = 1; | |
1686 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | |
1687 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
1688 | handle = sas_target_priv_data->handle; | |
1689 | ||
1690 | /* raid volume handling */ | |
1691 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | |
1692 | ||
1693 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
1694 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
1695 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
1696 | if (!raid_device) { | |
1697 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1698 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
1699 | __LINE__, __func__)); | |
1700 | return 1; | |
1701 | } | |
1702 | ||
1703 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | |
1704 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1705 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | |
1706 | __LINE__, __func__)); | |
1707 | return 1; | |
1708 | } | |
1709 | ||
1710 | ||
1711 | /* RAID Queue Depth Support | |
1712 | * IS volume = underlying qdepth of drive type, either | |
1713 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH | |
1714 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) | |
1715 | */ | |
1716 | if (raid_device->device_info & | |
1717 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
1718 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
1719 | ds = "SSP"; | |
1720 | } else { | |
1721 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1722 | if (raid_device->device_info & | |
1723 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1724 | ds = "SATA"; | |
1725 | else | |
1726 | ds = "STP"; | |
1727 | } | |
1728 | ||
1729 | switch (raid_device->volume_type) { | |
1730 | case MPI2_RAID_VOL_TYPE_RAID0: | |
1731 | r_level = "RAID0"; | |
1732 | break; | |
1733 | case MPI2_RAID_VOL_TYPE_RAID1E: | |
1734 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1735 | if (ioc->manu_pg10.OEMIdentifier && | |
1736 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | |
1737 | MFG10_GF0_R10_DISPLAY) && | |
1738 | !(raid_device->num_pds % 2)) | |
1739 | r_level = "RAID10"; | |
1740 | else | |
1741 | r_level = "RAID1E"; | |
1742 | break; | |
1743 | case MPI2_RAID_VOL_TYPE_RAID1: | |
1744 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1745 | r_level = "RAID1"; | |
1746 | break; | |
1747 | case MPI2_RAID_VOL_TYPE_RAID10: | |
1748 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1749 | r_level = "RAID10"; | |
1750 | break; | |
1751 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | |
1752 | default: | |
1753 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; | |
1754 | r_level = "RAIDX"; | |
1755 | break; | |
1756 | } | |
1757 | ||
1758 | sdev_printk(KERN_INFO, sdev, | |
1759 | "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n", | |
1760 | r_level, raid_device->handle, | |
1761 | (unsigned long long)raid_device->wwid, | |
1762 | raid_device->num_pds, ds); | |
1763 | ||
1764 | ||
1765 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); | |
1766 | ||
1767 | /* raid transport support */ | |
1768 | _scsih_set_level(sdev, raid_device->volume_type); | |
1769 | return 0; | |
1770 | } | |
1771 | ||
1772 | /* non-raid handling */ | |
1773 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
1774 | if (mpt3sas_config_get_volume_handle(ioc, handle, | |
1775 | &volume_handle)) { | |
1776 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1777 | "failure at %s:%d/%s()!\n", ioc->name, | |
1778 | __FILE__, __LINE__, __func__)); | |
1779 | return 1; | |
1780 | } | |
1781 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, | |
1782 | volume_handle, &volume_wwid)) { | |
1783 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1784 | "failure at %s:%d/%s()!\n", ioc->name, | |
1785 | __FILE__, __LINE__, __func__)); | |
1786 | return 1; | |
1787 | } | |
1788 | } | |
1789 | ||
1790 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
1791 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
1792 | sas_device_priv_data->sas_target->sas_address); | |
1793 | if (!sas_device) { | |
1794 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1795 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT | |
1796 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | |
1797 | __func__)); | |
1798 | return 1; | |
1799 | } | |
1800 | ||
1801 | sas_device->volume_handle = volume_handle; | |
1802 | sas_device->volume_wwid = volume_wwid; | |
1803 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | |
1804 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; | |
1805 | ssp_target = 1; | |
1806 | ds = "SSP"; | |
1807 | } else { | |
1808 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; | |
1809 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
1810 | ds = "STP"; | |
1811 | else if (sas_device->device_info & | |
1812 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | |
1813 | ds = "SATA"; | |
1814 | } | |
1815 | ||
1816 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ | |
1817 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | |
1818 | ds, handle, (unsigned long long)sas_device->sas_address, | |
1819 | sas_device->phy, (unsigned long long)sas_device->device_name); | |
1820 | sdev_printk(KERN_INFO, sdev, | |
1821 | "%s: enclosure_logical_id(0x%016llx), slot(%d)\n", | |
1822 | ds, (unsigned long long) | |
1823 | sas_device->enclosure_logical_id, sas_device->slot); | |
1824 | ||
1825 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
1826 | ||
1827 | if (!ssp_target) | |
1828 | _scsih_display_sata_capabilities(ioc, handle, sdev); | |
1829 | ||
1830 | ||
1831 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); | |
1832 | ||
1833 | if (ssp_target) { | |
1834 | sas_read_port_mode_page(sdev); | |
1835 | _scsih_enable_tlr(ioc, sdev); | |
1836 | } | |
1837 | ||
1838 | return 0; | |
1839 | } | |
1840 | ||
1841 | /** | |
1842 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk | |
1843 | * @sdev: scsi device struct | |
1844 | * @bdev: pointer to block device context | |
1845 | * @capacity: device size (in 512 byte sectors) | |
1846 | * @params: three element array to place output: | |
1847 | * params[0] number of heads (max 255) | |
1848 | * params[1] number of sectors (max 63) | |
1849 | * params[2] number of cylinders | |
1850 | * | |
1851 | * Return nothing. | |
1852 | */ | |
1853 | static int | |
1854 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, | |
1855 | sector_t capacity, int params[]) | |
1856 | { | |
1857 | int heads; | |
1858 | int sectors; | |
1859 | sector_t cylinders; | |
1860 | ulong dummy; | |
1861 | ||
1862 | heads = 64; | |
1863 | sectors = 32; | |
1864 | ||
1865 | dummy = heads * sectors; | |
1866 | cylinders = capacity; | |
1867 | sector_div(cylinders, dummy); | |
1868 | ||
1869 | /* | |
1870 | * Handle extended translation size for logical drives | |
1871 | * > 1Gb | |
1872 | */ | |
1873 | if ((ulong)capacity >= 0x200000) { | |
1874 | heads = 255; | |
1875 | sectors = 63; | |
1876 | dummy = heads * sectors; | |
1877 | cylinders = capacity; | |
1878 | sector_div(cylinders, dummy); | |
1879 | } | |
1880 | ||
1881 | /* return result */ | |
1882 | params[0] = heads; | |
1883 | params[1] = sectors; | |
1884 | params[2] = cylinders; | |
1885 | ||
1886 | return 0; | |
1887 | } | |
1888 | ||
1889 | /** | |
1890 | * _scsih_response_code - translation of device response code | |
1891 | * @ioc: per adapter object | |
1892 | * @response_code: response code returned by the device | |
1893 | * | |
1894 | * Return nothing. | |
1895 | */ | |
1896 | static void | |
1897 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) | |
1898 | { | |
1899 | char *desc; | |
1900 | ||
1901 | switch (response_code) { | |
1902 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | |
1903 | desc = "task management request completed"; | |
1904 | break; | |
1905 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | |
1906 | desc = "invalid frame"; | |
1907 | break; | |
1908 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | |
1909 | desc = "task management request not supported"; | |
1910 | break; | |
1911 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | |
1912 | desc = "task management request failed"; | |
1913 | break; | |
1914 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | |
1915 | desc = "task management request succeeded"; | |
1916 | break; | |
1917 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | |
1918 | desc = "invalid lun"; | |
1919 | break; | |
1920 | case 0xA: | |
1921 | desc = "overlapped tag attempted"; | |
1922 | break; | |
1923 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | |
1924 | desc = "task queued, however not sent to target"; | |
1925 | break; | |
1926 | default: | |
1927 | desc = "unknown"; | |
1928 | break; | |
1929 | } | |
1930 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", | |
1931 | ioc->name, response_code, desc); | |
1932 | } | |
1933 | ||
1934 | /** | |
1935 | * _scsih_tm_done - tm completion routine | |
1936 | * @ioc: per adapter object | |
1937 | * @smid: system request message index | |
1938 | * @msix_index: MSIX table index supplied by the OS | |
1939 | * @reply: reply message frame(lower 32bit addr) | |
1940 | * Context: none. | |
1941 | * | |
1942 | * The callback handler when using scsih_issue_tm. | |
1943 | * | |
1944 | * Return 1 meaning mf should be freed from _base_interrupt | |
1945 | * 0 means the mf is freed from this function. | |
1946 | */ | |
1947 | static u8 | |
1948 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
1949 | { | |
1950 | MPI2DefaultReply_t *mpi_reply; | |
1951 | ||
1952 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) | |
1953 | return 1; | |
1954 | if (ioc->tm_cmds.smid != smid) | |
1955 | return 1; | |
1956 | mpt3sas_base_flush_reply_queues(ioc); | |
1957 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; | |
1958 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
1959 | if (mpi_reply) { | |
1960 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | |
1961 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; | |
1962 | } | |
1963 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; | |
1964 | complete(&ioc->tm_cmds.done); | |
1965 | return 1; | |
1966 | } | |
1967 | ||
1968 | /** | |
1969 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy | |
1970 | * @ioc: per adapter object | |
1971 | * @handle: device handle | |
1972 | * | |
1973 | * During taskmangement request, we need to freeze the device queue. | |
1974 | */ | |
1975 | void | |
1976 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
1977 | { | |
1978 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
1979 | struct scsi_device *sdev; | |
1980 | u8 skip = 0; | |
1981 | ||
1982 | shost_for_each_device(sdev, ioc->shost) { | |
1983 | if (skip) | |
1984 | continue; | |
1985 | sas_device_priv_data = sdev->hostdata; | |
1986 | if (!sas_device_priv_data) | |
1987 | continue; | |
1988 | if (sas_device_priv_data->sas_target->handle == handle) { | |
1989 | sas_device_priv_data->sas_target->tm_busy = 1; | |
1990 | skip = 1; | |
1991 | ioc->ignore_loginfos = 1; | |
1992 | } | |
1993 | } | |
1994 | } | |
1995 | ||
1996 | /** | |
1997 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy | |
1998 | * @ioc: per adapter object | |
1999 | * @handle: device handle | |
2000 | * | |
2001 | * During taskmangement request, we need to freeze the device queue. | |
2002 | */ | |
2003 | void | |
2004 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2005 | { | |
2006 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2007 | struct scsi_device *sdev; | |
2008 | u8 skip = 0; | |
2009 | ||
2010 | shost_for_each_device(sdev, ioc->shost) { | |
2011 | if (skip) | |
2012 | continue; | |
2013 | sas_device_priv_data = sdev->hostdata; | |
2014 | if (!sas_device_priv_data) | |
2015 | continue; | |
2016 | if (sas_device_priv_data->sas_target->handle == handle) { | |
2017 | sas_device_priv_data->sas_target->tm_busy = 0; | |
2018 | skip = 1; | |
2019 | ioc->ignore_loginfos = 0; | |
2020 | } | |
2021 | } | |
2022 | } | |
2023 | ||
2024 | /** | |
2025 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests | |
2026 | * @ioc: per adapter struct | |
2027 | * @device_handle: device handle | |
2028 | * @channel: the channel assigned by the OS | |
2029 | * @id: the id assigned by the OS | |
2030 | * @lun: lun number | |
2031 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | |
2032 | * @smid_task: smid assigned to the task | |
2033 | * @timeout: timeout in seconds | |
f92363d1 SR |
2034 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
2035 | * Context: user | |
2036 | * | |
2037 | * A generic API for sending task management requests to firmware. | |
2038 | * | |
2039 | * The callback index is set inside `ioc->tm_cb_idx`. | |
2040 | * | |
2041 | * Return SUCCESS or FAILED. | |
2042 | */ | |
2043 | int | |
2044 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, | |
2045 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, | |
c62e46de | 2046 | enum mutex_type m_type) |
f92363d1 SR |
2047 | { |
2048 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2049 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
2050 | u16 smid = 0; | |
2051 | u32 ioc_state; | |
2052 | unsigned long timeleft; | |
2053 | struct scsiio_tracker *scsi_lookup = NULL; | |
2054 | int rc; | |
2055 | ||
2056 | if (m_type == TM_MUTEX_ON) | |
2057 | mutex_lock(&ioc->tm_cmds.mutex); | |
2058 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { | |
2059 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", | |
2060 | __func__, ioc->name); | |
2061 | rc = FAILED; | |
2062 | goto err_out; | |
2063 | } | |
2064 | ||
2065 | if (ioc->shost_recovery || ioc->remove_host || | |
2066 | ioc->pci_error_recovery) { | |
2067 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", | |
2068 | __func__, ioc->name); | |
2069 | rc = FAILED; | |
2070 | goto err_out; | |
2071 | } | |
2072 | ||
2073 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); | |
2074 | if (ioc_state & MPI2_DOORBELL_USED) { | |
2075 | dhsprintk(ioc, pr_info(MPT3SAS_FMT | |
2076 | "unexpected doorbell active!\n", ioc->name)); | |
2077 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2078 | FORCE_BIG_HAMMER); | |
2079 | rc = (!rc) ? SUCCESS : FAILED; | |
2080 | goto err_out; | |
2081 | } | |
2082 | ||
2083 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | |
2084 | mpt3sas_base_fault_info(ioc, ioc_state & | |
2085 | MPI2_DOORBELL_DATA_MASK); | |
2086 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2087 | FORCE_BIG_HAMMER); | |
2088 | rc = (!rc) ? SUCCESS : FAILED; | |
2089 | goto err_out; | |
2090 | } | |
2091 | ||
2092 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | |
2093 | if (!smid) { | |
2094 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2095 | ioc->name, __func__); | |
2096 | rc = FAILED; | |
2097 | goto err_out; | |
2098 | } | |
2099 | ||
2100 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | |
2101 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; | |
2102 | ||
2103 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
2104 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", | |
2105 | ioc->name, handle, type, smid_task)); | |
2106 | ioc->tm_cmds.status = MPT3_CMD_PENDING; | |
2107 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2108 | ioc->tm_cmds.smid = smid; | |
2109 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2110 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | |
2111 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2112 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2113 | mpi_request->TaskType = type; | |
2114 | mpi_request->TaskMID = cpu_to_le16(smid_task); | |
2115 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | |
2116 | mpt3sas_scsih_set_tm_flag(ioc, handle); | |
2117 | init_completion(&ioc->tm_cmds.done); | |
2118 | mpt3sas_base_put_smid_hi_priority(ioc, smid); | |
2119 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); | |
2120 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { | |
2121 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
2122 | ioc->name, __func__); | |
2123 | _debug_dump_mf(mpi_request, | |
2124 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2125 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { | |
2126 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2127 | FORCE_BIG_HAMMER); | |
2128 | rc = (!rc) ? SUCCESS : FAILED; | |
2129 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
2130 | mpt3sas_scsih_clear_tm_flag(ioc, handle); | |
2131 | goto err_out; | |
2132 | } | |
2133 | } | |
2134 | ||
2135 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { | |
2136 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2137 | mpi_reply = ioc->tm_cmds.reply; | |
2138 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ | |
2139 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | |
2140 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
2141 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2142 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2143 | if (ioc->logging_level & MPT_DEBUG_TM) { | |
2144 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | |
2145 | if (mpi_reply->IOCStatus) | |
2146 | _debug_dump_mf(mpi_request, | |
2147 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | |
2148 | } | |
2149 | } | |
2150 | ||
2151 | switch (type) { | |
2152 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | |
2153 | rc = SUCCESS; | |
2154 | if (scsi_lookup->scmd == NULL) | |
2155 | break; | |
2156 | rc = FAILED; | |
2157 | break; | |
2158 | ||
2159 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | |
2160 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) | |
2161 | rc = FAILED; | |
2162 | else | |
2163 | rc = SUCCESS; | |
2164 | break; | |
2165 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | |
2166 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: | |
2167 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) | |
2168 | rc = FAILED; | |
2169 | else | |
2170 | rc = SUCCESS; | |
2171 | break; | |
2172 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | |
2173 | rc = SUCCESS; | |
2174 | break; | |
2175 | default: | |
2176 | rc = FAILED; | |
2177 | break; | |
2178 | } | |
2179 | ||
2180 | mpt3sas_scsih_clear_tm_flag(ioc, handle); | |
2181 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; | |
2182 | if (m_type == TM_MUTEX_ON) | |
2183 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2184 | ||
2185 | return rc; | |
2186 | ||
2187 | err_out: | |
2188 | if (m_type == TM_MUTEX_ON) | |
2189 | mutex_unlock(&ioc->tm_cmds.mutex); | |
2190 | return rc; | |
2191 | } | |
2192 | ||
2193 | /** | |
2194 | * _scsih_tm_display_info - displays info about the device | |
2195 | * @ioc: per adapter struct | |
2196 | * @scmd: pointer to scsi command object | |
2197 | * | |
2198 | * Called by task management callback handlers. | |
2199 | */ | |
2200 | static void | |
2201 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | |
2202 | { | |
2203 | struct scsi_target *starget = scmd->device->sdev_target; | |
2204 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
2205 | struct _sas_device *sas_device = NULL; | |
2206 | unsigned long flags; | |
2207 | char *device_str = NULL; | |
2208 | ||
2209 | if (!priv_target) | |
2210 | return; | |
2211 | device_str = "volume"; | |
2212 | ||
2213 | scsi_print_command(scmd); | |
2214 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2215 | starget_printk(KERN_INFO, starget, | |
2216 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", | |
2217 | device_str, priv_target->handle, | |
2218 | device_str, (unsigned long long)priv_target->sas_address); | |
2219 | } else { | |
2220 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2221 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
2222 | priv_target->sas_address); | |
2223 | if (sas_device) { | |
2224 | if (priv_target->flags & | |
2225 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2226 | starget_printk(KERN_INFO, starget, | |
2227 | "volume handle(0x%04x), " | |
2228 | "volume wwid(0x%016llx)\n", | |
2229 | sas_device->volume_handle, | |
2230 | (unsigned long long)sas_device->volume_wwid); | |
2231 | } | |
2232 | starget_printk(KERN_INFO, starget, | |
2233 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | |
2234 | sas_device->handle, | |
2235 | (unsigned long long)sas_device->sas_address, | |
2236 | sas_device->phy); | |
2237 | starget_printk(KERN_INFO, starget, | |
2238 | "enclosure_logical_id(0x%016llx), slot(%d)\n", | |
2239 | (unsigned long long)sas_device->enclosure_logical_id, | |
2240 | sas_device->slot); | |
2241 | } | |
2242 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2243 | } | |
2244 | } | |
2245 | ||
2246 | /** | |
2247 | * _scsih_abort - eh threads main abort routine | |
2248 | * @scmd: pointer to scsi command object | |
2249 | * | |
2250 | * Returns SUCCESS if command aborted else FAILED | |
2251 | */ | |
2252 | static int | |
2253 | _scsih_abort(struct scsi_cmnd *scmd) | |
2254 | { | |
2255 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2256 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2257 | u16 smid; | |
2258 | u16 handle; | |
2259 | int r; | |
2260 | ||
2261 | sdev_printk(KERN_INFO, scmd->device, | |
2262 | "attempting task abort! scmd(%p)\n", scmd); | |
2263 | _scsih_tm_display_info(ioc, scmd); | |
2264 | ||
2265 | sas_device_priv_data = scmd->device->hostdata; | |
2266 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2267 | sdev_printk(KERN_INFO, scmd->device, | |
2268 | "device been deleted! scmd(%p)\n", scmd); | |
2269 | scmd->result = DID_NO_CONNECT << 16; | |
2270 | scmd->scsi_done(scmd); | |
2271 | r = SUCCESS; | |
2272 | goto out; | |
2273 | } | |
2274 | ||
2275 | /* search for the command */ | |
2276 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); | |
2277 | if (!smid) { | |
2278 | scmd->result = DID_RESET << 16; | |
2279 | r = SUCCESS; | |
2280 | goto out; | |
2281 | } | |
2282 | ||
2283 | /* for hidden raid components and volumes this is not supported */ | |
2284 | if (sas_device_priv_data->sas_target->flags & | |
2285 | MPT_TARGET_FLAGS_RAID_COMPONENT || | |
2286 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
2287 | scmd->result = DID_RESET << 16; | |
2288 | r = FAILED; | |
2289 | goto out; | |
2290 | } | |
2291 | ||
2292 | mpt3sas_halt_firmware(ioc); | |
2293 | ||
2294 | handle = sas_device_priv_data->sas_target->handle; | |
2295 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | |
2296 | scmd->device->id, scmd->device->lun, | |
c62e46de | 2297 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON); |
f92363d1 SR |
2298 | |
2299 | out: | |
2300 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | |
2301 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2302 | return r; | |
2303 | } | |
2304 | ||
2305 | /** | |
2306 | * _scsih_dev_reset - eh threads main device reset routine | |
2307 | * @scmd: pointer to scsi command object | |
2308 | * | |
2309 | * Returns SUCCESS if command aborted else FAILED | |
2310 | */ | |
2311 | static int | |
2312 | _scsih_dev_reset(struct scsi_cmnd *scmd) | |
2313 | { | |
2314 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2315 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2316 | struct _sas_device *sas_device; | |
2317 | unsigned long flags; | |
2318 | u16 handle; | |
2319 | int r; | |
2320 | ||
2321 | sdev_printk(KERN_INFO, scmd->device, | |
2322 | "attempting device reset! scmd(%p)\n", scmd); | |
2323 | _scsih_tm_display_info(ioc, scmd); | |
2324 | ||
2325 | sas_device_priv_data = scmd->device->hostdata; | |
2326 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2327 | sdev_printk(KERN_INFO, scmd->device, | |
2328 | "device been deleted! scmd(%p)\n", scmd); | |
2329 | scmd->result = DID_NO_CONNECT << 16; | |
2330 | scmd->scsi_done(scmd); | |
2331 | r = SUCCESS; | |
2332 | goto out; | |
2333 | } | |
2334 | ||
2335 | /* for hidden raid components obtain the volume_handle */ | |
2336 | handle = 0; | |
2337 | if (sas_device_priv_data->sas_target->flags & | |
2338 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2339 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2340 | sas_device = _scsih_sas_device_find_by_handle(ioc, | |
2341 | sas_device_priv_data->sas_target->handle); | |
2342 | if (sas_device) | |
2343 | handle = sas_device->volume_handle; | |
2344 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2345 | } else | |
2346 | handle = sas_device_priv_data->sas_target->handle; | |
2347 | ||
2348 | if (!handle) { | |
2349 | scmd->result = DID_RESET << 16; | |
2350 | r = FAILED; | |
2351 | goto out; | |
2352 | } | |
2353 | ||
2354 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | |
2355 | scmd->device->id, scmd->device->lun, | |
c62e46de | 2356 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON); |
f92363d1 SR |
2357 | |
2358 | out: | |
2359 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | |
2360 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2361 | return r; | |
2362 | } | |
2363 | ||
2364 | /** | |
2365 | * _scsih_target_reset - eh threads main target reset routine | |
2366 | * @scmd: pointer to scsi command object | |
2367 | * | |
2368 | * Returns SUCCESS if command aborted else FAILED | |
2369 | */ | |
2370 | static int | |
2371 | _scsih_target_reset(struct scsi_cmnd *scmd) | |
2372 | { | |
2373 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2374 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2375 | struct _sas_device *sas_device; | |
2376 | unsigned long flags; | |
2377 | u16 handle; | |
2378 | int r; | |
2379 | struct scsi_target *starget = scmd->device->sdev_target; | |
2380 | ||
2381 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", | |
2382 | scmd); | |
2383 | _scsih_tm_display_info(ioc, scmd); | |
2384 | ||
2385 | sas_device_priv_data = scmd->device->hostdata; | |
2386 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
2387 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", | |
2388 | scmd); | |
2389 | scmd->result = DID_NO_CONNECT << 16; | |
2390 | scmd->scsi_done(scmd); | |
2391 | r = SUCCESS; | |
2392 | goto out; | |
2393 | } | |
2394 | ||
2395 | /* for hidden raid components obtain the volume_handle */ | |
2396 | handle = 0; | |
2397 | if (sas_device_priv_data->sas_target->flags & | |
2398 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | |
2399 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2400 | sas_device = _scsih_sas_device_find_by_handle(ioc, | |
2401 | sas_device_priv_data->sas_target->handle); | |
2402 | if (sas_device) | |
2403 | handle = sas_device->volume_handle; | |
2404 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2405 | } else | |
2406 | handle = sas_device_priv_data->sas_target->handle; | |
2407 | ||
2408 | if (!handle) { | |
2409 | scmd->result = DID_RESET << 16; | |
2410 | r = FAILED; | |
2411 | goto out; | |
2412 | } | |
2413 | ||
2414 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | |
2415 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, | |
c62e46de | 2416 | 30, TM_MUTEX_ON); |
f92363d1 SR |
2417 | |
2418 | out: | |
2419 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | |
2420 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2421 | return r; | |
2422 | } | |
2423 | ||
2424 | ||
2425 | /** | |
2426 | * _scsih_host_reset - eh threads main host reset routine | |
2427 | * @scmd: pointer to scsi command object | |
2428 | * | |
2429 | * Returns SUCCESS if command aborted else FAILED | |
2430 | */ | |
2431 | static int | |
2432 | _scsih_host_reset(struct scsi_cmnd *scmd) | |
2433 | { | |
2434 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | |
2435 | int r, retval; | |
2436 | ||
2437 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", | |
2438 | ioc->name, scmd); | |
2439 | scsi_print_command(scmd); | |
2440 | ||
2441 | retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
2442 | FORCE_BIG_HAMMER); | |
2443 | r = (retval < 0) ? FAILED : SUCCESS; | |
2444 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", | |
2445 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | |
2446 | ||
2447 | return r; | |
2448 | } | |
2449 | ||
2450 | /** | |
2451 | * _scsih_fw_event_add - insert and queue up fw_event | |
2452 | * @ioc: per adapter object | |
2453 | * @fw_event: object describing the event | |
2454 | * Context: This function will acquire ioc->fw_event_lock. | |
2455 | * | |
2456 | * This adds the firmware event object into link list, then queues it up to | |
2457 | * be processed from user context. | |
2458 | * | |
2459 | * Return nothing. | |
2460 | */ | |
2461 | static void | |
2462 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
2463 | { | |
2464 | unsigned long flags; | |
2465 | ||
2466 | if (ioc->firmware_event_thread == NULL) | |
2467 | return; | |
2468 | ||
2469 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
2470 | INIT_LIST_HEAD(&fw_event->list); | |
2471 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | |
2472 | INIT_WORK(&fw_event->work, _firmware_event_work); | |
2473 | queue_work(ioc->firmware_event_thread, &fw_event->work); | |
2474 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
2475 | } | |
2476 | ||
2477 | /** | |
2478 | * _scsih_fw_event_free - delete fw_event | |
2479 | * @ioc: per adapter object | |
2480 | * @fw_event: object describing the event | |
2481 | * Context: This function will acquire ioc->fw_event_lock. | |
2482 | * | |
2483 | * This removes firmware event object from link list, frees associated memory. | |
2484 | * | |
2485 | * Return nothing. | |
2486 | */ | |
2487 | static void | |
2488 | _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work | |
2489 | *fw_event) | |
2490 | { | |
2491 | unsigned long flags; | |
2492 | ||
2493 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
2494 | list_del(&fw_event->list); | |
f92363d1 SR |
2495 | kfree(fw_event); |
2496 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
2497 | } | |
2498 | ||
2499 | ||
2500 | /** | |
2501 | * mpt3sas_send_trigger_data_event - send event for processing trigger data | |
2502 | * @ioc: per adapter object | |
2503 | * @event_data: trigger event data | |
2504 | * | |
2505 | * Return nothing. | |
2506 | */ | |
2507 | void | |
2508 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, | |
2509 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) | |
2510 | { | |
2511 | struct fw_event_work *fw_event; | |
2512 | ||
2513 | if (ioc->is_driver_loading) | |
2514 | return; | |
35b62362 JL |
2515 | fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data), |
2516 | GFP_ATOMIC); | |
f92363d1 SR |
2517 | if (!fw_event) |
2518 | return; | |
f92363d1 SR |
2519 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
2520 | fw_event->ioc = ioc; | |
2521 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); | |
2522 | _scsih_fw_event_add(ioc, fw_event); | |
2523 | } | |
2524 | ||
2525 | /** | |
2526 | * _scsih_error_recovery_delete_devices - remove devices not responding | |
2527 | * @ioc: per adapter object | |
2528 | * | |
2529 | * Return nothing. | |
2530 | */ | |
2531 | static void | |
2532 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) | |
2533 | { | |
2534 | struct fw_event_work *fw_event; | |
2535 | ||
2536 | if (ioc->is_driver_loading) | |
2537 | return; | |
2538 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); | |
2539 | if (!fw_event) | |
2540 | return; | |
2541 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; | |
2542 | fw_event->ioc = ioc; | |
2543 | _scsih_fw_event_add(ioc, fw_event); | |
2544 | } | |
2545 | ||
2546 | /** | |
2547 | * mpt3sas_port_enable_complete - port enable completed (fake event) | |
2548 | * @ioc: per adapter object | |
2549 | * | |
2550 | * Return nothing. | |
2551 | */ | |
2552 | void | |
2553 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) | |
2554 | { | |
2555 | struct fw_event_work *fw_event; | |
2556 | ||
2557 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); | |
2558 | if (!fw_event) | |
2559 | return; | |
2560 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; | |
2561 | fw_event->ioc = ioc; | |
2562 | _scsih_fw_event_add(ioc, fw_event); | |
2563 | } | |
2564 | ||
2565 | /** | |
2566 | * _scsih_fw_event_cleanup_queue - cleanup event queue | |
2567 | * @ioc: per adapter object | |
2568 | * | |
2569 | * Walk the firmware event queue, either killing timers, or waiting | |
2570 | * for outstanding events to complete | |
2571 | * | |
2572 | * Return nothing. | |
2573 | */ | |
2574 | static void | |
2575 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) | |
2576 | { | |
2577 | struct fw_event_work *fw_event, *next; | |
2578 | ||
2579 | if (list_empty(&ioc->fw_event_list) || | |
2580 | !ioc->firmware_event_thread || in_interrupt()) | |
2581 | return; | |
2582 | ||
2583 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { | |
4dc06fd8 | 2584 | if (cancel_delayed_work_sync(&fw_event->delayed_work)) { |
f92363d1 SR |
2585 | _scsih_fw_event_free(ioc, fw_event); |
2586 | continue; | |
2587 | } | |
f92363d1 SR |
2588 | } |
2589 | } | |
2590 | ||
2591 | /** | |
2592 | * _scsih_ublock_io_all_device - unblock every device | |
2593 | * @ioc: per adapter object | |
2594 | * | |
2595 | * change the device state from block to running | |
2596 | */ | |
2597 | static void | |
2598 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
2599 | { | |
2600 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2601 | struct scsi_device *sdev; | |
2602 | ||
2603 | shost_for_each_device(sdev, ioc->shost) { | |
2604 | sas_device_priv_data = sdev->hostdata; | |
2605 | if (!sas_device_priv_data) | |
2606 | continue; | |
2607 | if (!sas_device_priv_data->block) | |
2608 | continue; | |
2609 | ||
2610 | sas_device_priv_data->block = 0; | |
2611 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, | |
2612 | "device_running, handle(0x%04x)\n", | |
2613 | sas_device_priv_data->sas_target->handle)); | |
2614 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); | |
2615 | } | |
2616 | } | |
2617 | ||
2618 | ||
2619 | /** | |
2620 | * _scsih_ublock_io_device - prepare device to be deleted | |
2621 | * @ioc: per adapter object | |
2622 | * @sas_addr: sas address | |
2623 | * | |
2624 | * unblock then put device in offline state | |
2625 | */ | |
2626 | static void | |
2627 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
2628 | { | |
2629 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2630 | struct scsi_device *sdev; | |
2631 | ||
2632 | shost_for_each_device(sdev, ioc->shost) { | |
2633 | sas_device_priv_data = sdev->hostdata; | |
2634 | if (!sas_device_priv_data) | |
2635 | continue; | |
2636 | if (sas_device_priv_data->sas_target->sas_address | |
2637 | != sas_address) | |
2638 | continue; | |
2639 | if (sas_device_priv_data->block) { | |
2640 | sas_device_priv_data->block = 0; | |
2641 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); | |
2642 | } | |
2643 | } | |
2644 | } | |
2645 | ||
2646 | /** | |
2647 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | |
2648 | * @ioc: per adapter object | |
2649 | * @handle: device handle | |
2650 | * | |
2651 | * During device pull we need to appropiately set the sdev state. | |
2652 | */ | |
2653 | static void | |
2654 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) | |
2655 | { | |
2656 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2657 | struct scsi_device *sdev; | |
2658 | ||
2659 | shost_for_each_device(sdev, ioc->shost) { | |
2660 | sas_device_priv_data = sdev->hostdata; | |
2661 | if (!sas_device_priv_data) | |
2662 | continue; | |
2663 | if (sas_device_priv_data->block) | |
2664 | continue; | |
2665 | sas_device_priv_data->block = 1; | |
2666 | scsi_internal_device_block(sdev); | |
2667 | sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n", | |
2668 | sas_device_priv_data->sas_target->handle); | |
2669 | } | |
2670 | } | |
2671 | ||
2672 | /** | |
2673 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | |
2674 | * @ioc: per adapter object | |
2675 | * @handle: device handle | |
2676 | * | |
2677 | * During device pull we need to appropiately set the sdev state. | |
2678 | */ | |
2679 | static void | |
2680 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2681 | { | |
2682 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
2683 | struct scsi_device *sdev; | |
2684 | ||
2685 | shost_for_each_device(sdev, ioc->shost) { | |
2686 | sas_device_priv_data = sdev->hostdata; | |
2687 | if (!sas_device_priv_data) | |
2688 | continue; | |
2689 | if (sas_device_priv_data->sas_target->handle != handle) | |
2690 | continue; | |
2691 | if (sas_device_priv_data->block) | |
2692 | continue; | |
2693 | sas_device_priv_data->block = 1; | |
2694 | scsi_internal_device_block(sdev); | |
2695 | sdev_printk(KERN_INFO, sdev, | |
2696 | "device_blocked, handle(0x%04x)\n", handle); | |
2697 | } | |
2698 | } | |
2699 | ||
2700 | /** | |
2701 | * _scsih_block_io_to_children_attached_to_ex | |
2702 | * @ioc: per adapter object | |
2703 | * @sas_expander: the sas_device object | |
2704 | * | |
2705 | * This routine set sdev state to SDEV_BLOCK for all devices | |
2706 | * attached to this expander. This function called when expander is | |
2707 | * pulled. | |
2708 | */ | |
2709 | static void | |
2710 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, | |
2711 | struct _sas_node *sas_expander) | |
2712 | { | |
2713 | struct _sas_port *mpt3sas_port; | |
2714 | struct _sas_device *sas_device; | |
2715 | struct _sas_node *expander_sibling; | |
2716 | unsigned long flags; | |
2717 | ||
2718 | if (!sas_expander) | |
2719 | return; | |
2720 | ||
2721 | list_for_each_entry(mpt3sas_port, | |
2722 | &sas_expander->sas_port_list, port_list) { | |
2723 | if (mpt3sas_port->remote_identify.device_type == | |
2724 | SAS_END_DEVICE) { | |
2725 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2726 | sas_device = | |
2727 | mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
2728 | mpt3sas_port->remote_identify.sas_address); | |
2729 | if (sas_device) | |
2730 | set_bit(sas_device->handle, | |
2731 | ioc->blocking_handles); | |
2732 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2733 | } | |
2734 | } | |
2735 | ||
2736 | list_for_each_entry(mpt3sas_port, | |
2737 | &sas_expander->sas_port_list, port_list) { | |
2738 | ||
2739 | if (mpt3sas_port->remote_identify.device_type == | |
2740 | SAS_EDGE_EXPANDER_DEVICE || | |
2741 | mpt3sas_port->remote_identify.device_type == | |
2742 | SAS_FANOUT_EXPANDER_DEVICE) { | |
2743 | expander_sibling = | |
2744 | mpt3sas_scsih_expander_find_by_sas_address( | |
2745 | ioc, mpt3sas_port->remote_identify.sas_address); | |
2746 | _scsih_block_io_to_children_attached_to_ex(ioc, | |
2747 | expander_sibling); | |
2748 | } | |
2749 | } | |
2750 | } | |
2751 | ||
2752 | /** | |
2753 | * _scsih_block_io_to_children_attached_directly | |
2754 | * @ioc: per adapter object | |
2755 | * @event_data: topology change event data | |
2756 | * | |
2757 | * This routine set sdev state to SDEV_BLOCK for all devices | |
2758 | * direct attached during device pull. | |
2759 | */ | |
2760 | static void | |
2761 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, | |
2762 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
2763 | { | |
2764 | int i; | |
2765 | u16 handle; | |
2766 | u16 reason_code; | |
f92363d1 SR |
2767 | |
2768 | for (i = 0; i < event_data->NumEntries; i++) { | |
2769 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
2770 | if (!handle) | |
2771 | continue; | |
f92363d1 SR |
2772 | reason_code = event_data->PHY[i].PhyStatus & |
2773 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
2774 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | |
2775 | _scsih_block_io_device(ioc, handle); | |
2776 | } | |
2777 | } | |
2778 | ||
2779 | /** | |
2780 | * _scsih_tm_tr_send - send task management request | |
2781 | * @ioc: per adapter object | |
2782 | * @handle: device handle | |
2783 | * Context: interrupt time. | |
2784 | * | |
2785 | * This code is to initiate the device removal handshake protocol | |
2786 | * with controller firmware. This function will issue target reset | |
2787 | * using high priority request queue. It will send a sas iounit | |
2788 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | |
2789 | * | |
2790 | * This is designed to send muliple task management request at the same | |
2791 | * time to the fifo. If the fifo is full, we will append the request, | |
2792 | * and process it in a future completion. | |
2793 | */ | |
2794 | static void | |
2795 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
2796 | { | |
2797 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
2798 | u16 smid; | |
2799 | struct _sas_device *sas_device; | |
2800 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
2801 | u64 sas_address = 0; | |
2802 | unsigned long flags; | |
2803 | struct _tr_list *delayed_tr; | |
2804 | u32 ioc_state; | |
2805 | ||
2806 | if (ioc->remove_host) { | |
2807 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2808 | "%s: host has been removed: handle(0x%04x)\n", | |
2809 | __func__, ioc->name, handle)); | |
2810 | return; | |
2811 | } else if (ioc->pci_error_recovery) { | |
2812 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2813 | "%s: host in pci error recovery: handle(0x%04x)\n", | |
2814 | __func__, ioc->name, | |
2815 | handle)); | |
2816 | return; | |
2817 | } | |
2818 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
2819 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
2820 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2821 | "%s: host is not operational: handle(0x%04x)\n", | |
2822 | __func__, ioc->name, | |
2823 | handle)); | |
2824 | return; | |
2825 | } | |
2826 | ||
2827 | /* if PD, then return */ | |
2828 | if (test_bit(handle, ioc->pd_handles)) | |
2829 | return; | |
2830 | ||
2831 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
2832 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
2833 | if (sas_device && sas_device->starget && | |
2834 | sas_device->starget->hostdata) { | |
2835 | sas_target_priv_data = sas_device->starget->hostdata; | |
2836 | sas_target_priv_data->deleted = 1; | |
2837 | sas_address = sas_device->sas_address; | |
2838 | } | |
2839 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
2840 | ||
2841 | if (sas_target_priv_data) { | |
2842 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2843 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", | |
2844 | ioc->name, handle, | |
2845 | (unsigned long long)sas_address)); | |
2846 | _scsih_ublock_io_device(ioc, sas_address); | |
2847 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; | |
2848 | } | |
2849 | ||
2850 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | |
2851 | if (!smid) { | |
2852 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
2853 | if (!delayed_tr) | |
2854 | return; | |
2855 | INIT_LIST_HEAD(&delayed_tr->list); | |
2856 | delayed_tr->handle = handle; | |
2857 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
2858 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2859 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
2860 | ioc->name, handle)); | |
2861 | return; | |
2862 | } | |
2863 | ||
2864 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2865 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
2866 | ioc->name, handle, smid, | |
2867 | ioc->tm_tr_cb_idx)); | |
2868 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
2869 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
2870 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
2871 | mpi_request->DevHandle = cpu_to_le16(handle); | |
2872 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
2873 | mpt3sas_base_put_smid_hi_priority(ioc, smid); | |
2874 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); | |
2875 | } | |
2876 | ||
2877 | /** | |
2878 | * _scsih_tm_tr_complete - | |
2879 | * @ioc: per adapter object | |
2880 | * @smid: system request message index | |
2881 | * @msix_index: MSIX table index supplied by the OS | |
2882 | * @reply: reply message frame(lower 32bit addr) | |
2883 | * Context: interrupt time. | |
2884 | * | |
2885 | * This is the target reset completion routine. | |
2886 | * This code is part of the code to initiate the device removal | |
2887 | * handshake protocol with controller firmware. | |
2888 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | |
2889 | * | |
2890 | * Return 1 meaning mf should be freed from _base_interrupt | |
2891 | * 0 means the mf is freed from this function. | |
2892 | */ | |
2893 | static u8 | |
2894 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | |
2895 | u32 reply) | |
2896 | { | |
2897 | u16 handle; | |
2898 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
2899 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
2900 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2901 | Mpi2SasIoUnitControlRequest_t *mpi_request; | |
2902 | u16 smid_sas_ctrl; | |
2903 | u32 ioc_state; | |
2904 | ||
2905 | if (ioc->remove_host) { | |
2906 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2907 | "%s: host has been removed\n", __func__, ioc->name)); | |
2908 | return 1; | |
2909 | } else if (ioc->pci_error_recovery) { | |
2910 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2911 | "%s: host in pci error recovery\n", __func__, | |
2912 | ioc->name)); | |
2913 | return 1; | |
2914 | } | |
2915 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); | |
2916 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | |
2917 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2918 | "%s: host is not operational\n", __func__, ioc->name)); | |
2919 | return 1; | |
2920 | } | |
2921 | if (unlikely(!mpi_reply)) { | |
2922 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
2923 | ioc->name, __FILE__, __LINE__, __func__); | |
2924 | return 1; | |
2925 | } | |
2926 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
2927 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
2928 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
2929 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
2930 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
2931 | ioc->name, handle, | |
2932 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
2933 | return 0; | |
2934 | } | |
2935 | ||
2936 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); | |
2937 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2938 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
2939 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
2940 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
2941 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
2942 | le32_to_cpu(mpi_reply->TerminationCount))); | |
2943 | ||
2944 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | |
2945 | if (!smid_sas_ctrl) { | |
2946 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
2947 | ioc->name, __func__); | |
2948 | return 1; | |
2949 | } | |
2950 | ||
2951 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2952 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
2953 | ioc->name, handle, smid_sas_ctrl, | |
2954 | ioc->tm_sas_control_cb_idx)); | |
2955 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); | |
2956 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | |
2957 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | |
2958 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | |
2959 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | |
2960 | mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl); | |
2961 | ||
2962 | return _scsih_check_for_pending_tm(ioc, smid); | |
2963 | } | |
2964 | ||
2965 | ||
2966 | /** | |
2967 | * _scsih_sas_control_complete - completion routine | |
2968 | * @ioc: per adapter object | |
2969 | * @smid: system request message index | |
2970 | * @msix_index: MSIX table index supplied by the OS | |
2971 | * @reply: reply message frame(lower 32bit addr) | |
2972 | * Context: interrupt time. | |
2973 | * | |
2974 | * This is the sas iounit control completion routine. | |
2975 | * This code is part of the code to initiate the device removal | |
2976 | * handshake protocol with controller firmware. | |
2977 | * | |
2978 | * Return 1 meaning mf should be freed from _base_interrupt | |
2979 | * 0 means the mf is freed from this function. | |
2980 | */ | |
2981 | static u8 | |
2982 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
2983 | u8 msix_index, u32 reply) | |
2984 | { | |
2985 | Mpi2SasIoUnitControlReply_t *mpi_reply = | |
2986 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
2987 | ||
2988 | if (likely(mpi_reply)) { | |
2989 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
2990 | "sc_complete:handle(0x%04x), (open) " | |
2991 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | |
2992 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | |
2993 | le16_to_cpu(mpi_reply->IOCStatus), | |
2994 | le32_to_cpu(mpi_reply->IOCLogInfo))); | |
2995 | } else { | |
2996 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
2997 | ioc->name, __FILE__, __LINE__, __func__); | |
2998 | } | |
2999 | return 1; | |
3000 | } | |
3001 | ||
3002 | /** | |
3003 | * _scsih_tm_tr_volume_send - send target reset request for volumes | |
3004 | * @ioc: per adapter object | |
3005 | * @handle: device handle | |
3006 | * Context: interrupt time. | |
3007 | * | |
3008 | * This is designed to send muliple task management request at the same | |
3009 | * time to the fifo. If the fifo is full, we will append the request, | |
3010 | * and process it in a future completion. | |
3011 | */ | |
3012 | static void | |
3013 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3014 | { | |
3015 | Mpi2SCSITaskManagementRequest_t *mpi_request; | |
3016 | u16 smid; | |
3017 | struct _tr_list *delayed_tr; | |
3018 | ||
3019 | if (ioc->shost_recovery || ioc->remove_host || | |
3020 | ioc->pci_error_recovery) { | |
3021 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3022 | "%s: host reset in progress!\n", | |
3023 | __func__, ioc->name)); | |
3024 | return; | |
3025 | } | |
3026 | ||
3027 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | |
3028 | if (!smid) { | |
3029 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3030 | if (!delayed_tr) | |
3031 | return; | |
3032 | INIT_LIST_HEAD(&delayed_tr->list); | |
3033 | delayed_tr->handle = handle; | |
3034 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | |
3035 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3036 | "DELAYED:tr:handle(0x%04x), (open)\n", | |
3037 | ioc->name, handle)); | |
3038 | return; | |
3039 | } | |
3040 | ||
3041 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3042 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", | |
3043 | ioc->name, handle, smid, | |
3044 | ioc->tm_tr_volume_cb_idx)); | |
3045 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3046 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | |
3047 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | |
3048 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3049 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | |
3050 | mpt3sas_base_put_smid_hi_priority(ioc, smid); | |
3051 | } | |
3052 | ||
3053 | /** | |
3054 | * _scsih_tm_volume_tr_complete - target reset completion | |
3055 | * @ioc: per adapter object | |
3056 | * @smid: system request message index | |
3057 | * @msix_index: MSIX table index supplied by the OS | |
3058 | * @reply: reply message frame(lower 32bit addr) | |
3059 | * Context: interrupt time. | |
3060 | * | |
3061 | * Return 1 meaning mf should be freed from _base_interrupt | |
3062 | * 0 means the mf is freed from this function. | |
3063 | */ | |
3064 | static u8 | |
3065 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, | |
3066 | u8 msix_index, u32 reply) | |
3067 | { | |
3068 | u16 handle; | |
3069 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | |
3070 | Mpi2SCSITaskManagementReply_t *mpi_reply = | |
3071 | mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
3072 | ||
3073 | if (ioc->shost_recovery || ioc->remove_host || | |
3074 | ioc->pci_error_recovery) { | |
3075 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3076 | "%s: host reset in progress!\n", | |
3077 | __func__, ioc->name)); | |
3078 | return 1; | |
3079 | } | |
3080 | if (unlikely(!mpi_reply)) { | |
3081 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
3082 | ioc->name, __FILE__, __LINE__, __func__); | |
3083 | return 1; | |
3084 | } | |
3085 | ||
3086 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); | |
3087 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | |
3088 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | |
3089 | dewtprintk(ioc, pr_err(MPT3SAS_FMT | |
3090 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", | |
3091 | ioc->name, handle, | |
3092 | le16_to_cpu(mpi_reply->DevHandle), smid)); | |
3093 | return 0; | |
3094 | } | |
3095 | ||
3096 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3097 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | |
3098 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | |
3099 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | |
3100 | le32_to_cpu(mpi_reply->IOCLogInfo), | |
3101 | le32_to_cpu(mpi_reply->TerminationCount))); | |
3102 | ||
3103 | return _scsih_check_for_pending_tm(ioc, smid); | |
3104 | } | |
3105 | ||
3106 | ||
3107 | /** | |
3108 | * _scsih_check_for_pending_tm - check for pending task management | |
3109 | * @ioc: per adapter object | |
3110 | * @smid: system request message index | |
3111 | * | |
3112 | * This will check delayed target reset list, and feed the | |
3113 | * next reqeust. | |
3114 | * | |
3115 | * Return 1 meaning mf should be freed from _base_interrupt | |
3116 | * 0 means the mf is freed from this function. | |
3117 | */ | |
3118 | static u8 | |
3119 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) | |
3120 | { | |
3121 | struct _tr_list *delayed_tr; | |
3122 | ||
3123 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | |
3124 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | |
3125 | struct _tr_list, list); | |
3126 | mpt3sas_base_free_smid(ioc, smid); | |
3127 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | |
3128 | list_del(&delayed_tr->list); | |
3129 | kfree(delayed_tr); | |
3130 | return 0; | |
3131 | } | |
3132 | ||
3133 | if (!list_empty(&ioc->delayed_tr_list)) { | |
3134 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | |
3135 | struct _tr_list, list); | |
3136 | mpt3sas_base_free_smid(ioc, smid); | |
3137 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | |
3138 | list_del(&delayed_tr->list); | |
3139 | kfree(delayed_tr); | |
3140 | return 0; | |
3141 | } | |
3142 | ||
3143 | return 1; | |
3144 | } | |
3145 | ||
3146 | /** | |
3147 | * _scsih_check_topo_delete_events - sanity check on topo events | |
3148 | * @ioc: per adapter object | |
3149 | * @event_data: the event data payload | |
3150 | * | |
3151 | * This routine added to better handle cable breaker. | |
3152 | * | |
3153 | * This handles the case where driver receives multiple expander | |
3154 | * add and delete events in a single shot. When there is a delete event | |
3155 | * the routine will void any pending add events waiting in the event queue. | |
3156 | * | |
3157 | * Return nothing. | |
3158 | */ | |
3159 | static void | |
3160 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
3161 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
3162 | { | |
3163 | struct fw_event_work *fw_event; | |
3164 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | |
3165 | u16 expander_handle; | |
3166 | struct _sas_node *sas_expander; | |
3167 | unsigned long flags; | |
3168 | int i, reason_code; | |
3169 | u16 handle; | |
3170 | ||
3171 | for (i = 0 ; i < event_data->NumEntries; i++) { | |
3172 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
3173 | if (!handle) | |
3174 | continue; | |
3175 | reason_code = event_data->PHY[i].PhyStatus & | |
3176 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
3177 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | |
3178 | _scsih_tm_tr_send(ioc, handle); | |
3179 | } | |
3180 | ||
3181 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
3182 | if (expander_handle < ioc->sas_hba.num_phys) { | |
3183 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
3184 | return; | |
3185 | } | |
3186 | if (event_data->ExpStatus == | |
3187 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | |
3188 | /* put expander attached devices into blocking state */ | |
3189 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
3190 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
3191 | expander_handle); | |
3192 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | |
3193 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
3194 | do { | |
3195 | handle = find_first_bit(ioc->blocking_handles, | |
3196 | ioc->facts.MaxDevHandle); | |
3197 | if (handle < ioc->facts.MaxDevHandle) | |
3198 | _scsih_block_io_device(ioc, handle); | |
3199 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | |
3200 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | |
3201 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | |
3202 | ||
3203 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | |
3204 | return; | |
3205 | ||
3206 | /* mark ignore flag for pending events */ | |
3207 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
3208 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | |
3209 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | |
3210 | fw_event->ignore) | |
3211 | continue; | |
35b62362 JL |
3212 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
3213 | fw_event->event_data; | |
f92363d1 SR |
3214 | if (local_event_data->ExpStatus == |
3215 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | |
3216 | local_event_data->ExpStatus == | |
3217 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | |
3218 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | |
3219 | expander_handle) { | |
3220 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3221 | "setting ignoring flag\n", ioc->name)); | |
3222 | fw_event->ignore = 1; | |
3223 | } | |
3224 | } | |
3225 | } | |
3226 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
3227 | } | |
3228 | ||
3229 | /** | |
3230 | * _scsih_set_volume_delete_flag - setting volume delete flag | |
3231 | * @ioc: per adapter object | |
3232 | * @handle: device handle | |
3233 | * | |
3234 | * This returns nothing. | |
3235 | */ | |
3236 | static void | |
3237 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3238 | { | |
3239 | struct _raid_device *raid_device; | |
3240 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3241 | unsigned long flags; | |
3242 | ||
3243 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
3244 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
3245 | if (raid_device && raid_device->starget && | |
3246 | raid_device->starget->hostdata) { | |
3247 | sas_target_priv_data = | |
3248 | raid_device->starget->hostdata; | |
3249 | sas_target_priv_data->deleted = 1; | |
3250 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3251 | "setting delete flag: handle(0x%04x), " | |
3252 | "wwid(0x%016llx)\n", ioc->name, handle, | |
3253 | (unsigned long long) raid_device->wwid)); | |
3254 | } | |
3255 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
3256 | } | |
3257 | ||
3258 | /** | |
3259 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | |
3260 | * @handle: input handle | |
3261 | * @a: handle for volume a | |
3262 | * @b: handle for volume b | |
3263 | * | |
3264 | * IR firmware only supports two raid volumes. The purpose of this | |
3265 | * routine is to set the volume handle in either a or b. When the given | |
3266 | * input handle is non-zero, or when a and b have not been set before. | |
3267 | */ | |
3268 | static void | |
3269 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | |
3270 | { | |
3271 | if (!handle || handle == *a || handle == *b) | |
3272 | return; | |
3273 | if (!*a) | |
3274 | *a = handle; | |
3275 | else if (!*b) | |
3276 | *b = handle; | |
3277 | } | |
3278 | ||
3279 | /** | |
3280 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | |
3281 | * @ioc: per adapter object | |
3282 | * @event_data: the event data payload | |
3283 | * Context: interrupt time. | |
3284 | * | |
3285 | * This routine will send target reset to volume, followed by target | |
3286 | * resets to the PDs. This is called when a PD has been removed, or | |
3287 | * volume has been deleted or removed. When the target reset is sent | |
3288 | * to volume, the PD target resets need to be queued to start upon | |
3289 | * completion of the volume target reset. | |
3290 | * | |
3291 | * Return nothing. | |
3292 | */ | |
3293 | static void | |
3294 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, | |
3295 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
3296 | { | |
3297 | Mpi2EventIrConfigElement_t *element; | |
3298 | int i; | |
3299 | u16 handle, volume_handle, a, b; | |
3300 | struct _tr_list *delayed_tr; | |
3301 | ||
3302 | a = 0; | |
3303 | b = 0; | |
3304 | ||
3305 | /* Volume Resets for Deleted or Removed */ | |
3306 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
3307 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
3308 | if (le32_to_cpu(event_data->Flags) & | |
3309 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
3310 | continue; | |
3311 | if (element->ReasonCode == | |
3312 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | |
3313 | element->ReasonCode == | |
3314 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | |
3315 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
3316 | _scsih_set_volume_delete_flag(ioc, volume_handle); | |
3317 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
3318 | } | |
3319 | } | |
3320 | ||
3321 | /* Volume Resets for UNHIDE events */ | |
3322 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
3323 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
3324 | if (le32_to_cpu(event_data->Flags) & | |
3325 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | |
3326 | continue; | |
3327 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | |
3328 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
3329 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | |
3330 | } | |
3331 | } | |
3332 | ||
3333 | if (a) | |
3334 | _scsih_tm_tr_volume_send(ioc, a); | |
3335 | if (b) | |
3336 | _scsih_tm_tr_volume_send(ioc, b); | |
3337 | ||
3338 | /* PD target resets */ | |
3339 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
3340 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
3341 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | |
3342 | continue; | |
3343 | handle = le16_to_cpu(element->PhysDiskDevHandle); | |
3344 | volume_handle = le16_to_cpu(element->VolDevHandle); | |
3345 | clear_bit(handle, ioc->pd_handles); | |
3346 | if (!volume_handle) | |
3347 | _scsih_tm_tr_send(ioc, handle); | |
3348 | else if (volume_handle == a || volume_handle == b) { | |
3349 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | |
3350 | BUG_ON(!delayed_tr); | |
3351 | INIT_LIST_HEAD(&delayed_tr->list); | |
3352 | delayed_tr->handle = handle; | |
3353 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | |
3354 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3355 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | |
3356 | handle)); | |
3357 | } else | |
3358 | _scsih_tm_tr_send(ioc, handle); | |
3359 | } | |
3360 | } | |
3361 | ||
3362 | ||
3363 | /** | |
3364 | * _scsih_check_volume_delete_events - set delete flag for volumes | |
3365 | * @ioc: per adapter object | |
3366 | * @event_data: the event data payload | |
3367 | * Context: interrupt time. | |
3368 | * | |
3369 | * This will handle the case when the cable connected to entire volume is | |
3370 | * pulled. We will take care of setting the deleted flag so normal IO will | |
3371 | * not be sent. | |
3372 | * | |
3373 | * Return nothing. | |
3374 | */ | |
3375 | static void | |
3376 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, | |
3377 | Mpi2EventDataIrVolume_t *event_data) | |
3378 | { | |
3379 | u32 state; | |
3380 | ||
3381 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
3382 | return; | |
3383 | state = le32_to_cpu(event_data->NewValue); | |
3384 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | |
3385 | MPI2_RAID_VOL_STATE_FAILED) | |
3386 | _scsih_set_volume_delete_flag(ioc, | |
3387 | le16_to_cpu(event_data->VolDevHandle)); | |
3388 | } | |
3389 | ||
3390 | /** | |
3391 | * _scsih_flush_running_cmds - completing outstanding commands. | |
3392 | * @ioc: per adapter object | |
3393 | * | |
3394 | * The flushing out of all pending scmd commands following host reset, | |
3395 | * where all IO is dropped to the floor. | |
3396 | * | |
3397 | * Return nothing. | |
3398 | */ | |
3399 | static void | |
3400 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) | |
3401 | { | |
3402 | struct scsi_cmnd *scmd; | |
3403 | u16 smid; | |
3404 | u16 count = 0; | |
3405 | ||
3406 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
3407 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
3408 | if (!scmd) | |
3409 | continue; | |
3410 | count++; | |
3411 | mpt3sas_base_free_smid(ioc, smid); | |
3412 | scsi_dma_unmap(scmd); | |
3413 | if (ioc->pci_error_recovery) | |
3414 | scmd->result = DID_NO_CONNECT << 16; | |
3415 | else | |
3416 | scmd->result = DID_RESET << 16; | |
3417 | scmd->scsi_done(scmd); | |
3418 | } | |
3419 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", | |
3420 | ioc->name, count)); | |
3421 | } | |
3422 | ||
3423 | /** | |
3424 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | |
3425 | * @ioc: per adapter object | |
3426 | * @scmd: pointer to scsi command object | |
3427 | * @mpi_request: pointer to the SCSI_IO reqest message frame | |
3428 | * | |
3429 | * Supporting protection 1 and 3. | |
3430 | * | |
3431 | * Returns nothing | |
3432 | */ | |
3433 | static void | |
3434 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
3435 | Mpi2SCSIIORequest_t *mpi_request) | |
3436 | { | |
3437 | u16 eedp_flags; | |
3438 | unsigned char prot_op = scsi_get_prot_op(scmd); | |
3439 | unsigned char prot_type = scsi_get_prot_type(scmd); | |
3440 | Mpi25SCSIIORequest_t *mpi_request_3v = | |
3441 | (Mpi25SCSIIORequest_t *)mpi_request; | |
3442 | ||
3443 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | |
3444 | return; | |
3445 | ||
3446 | if (prot_op == SCSI_PROT_READ_STRIP) | |
3447 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | |
3448 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
3449 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | |
3450 | else | |
3451 | return; | |
3452 | ||
3453 | switch (prot_type) { | |
3454 | case SCSI_PROT_DIF_TYPE1: | |
3455 | case SCSI_PROT_DIF_TYPE2: | |
3456 | ||
3457 | /* | |
3458 | * enable ref/guard checking | |
3459 | * auto increment ref tag | |
3460 | */ | |
3461 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | |
3462 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | |
3463 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
3464 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | |
3465 | cpu_to_be32(scsi_get_lba(scmd)); | |
3466 | break; | |
3467 | ||
3468 | case SCSI_PROT_DIF_TYPE3: | |
3469 | ||
3470 | /* | |
3471 | * enable guard checking | |
3472 | */ | |
3473 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | |
3474 | ||
3475 | break; | |
3476 | } | |
3477 | ||
3478 | mpi_request_3v->EEDPBlockSize = | |
3479 | cpu_to_le16(scmd->device->sector_size); | |
3480 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); | |
3481 | } | |
3482 | ||
3483 | /** | |
3484 | * _scsih_eedp_error_handling - return sense code for EEDP errors | |
3485 | * @scmd: pointer to scsi command object | |
3486 | * @ioc_status: ioc status | |
3487 | * | |
3488 | * Returns nothing | |
3489 | */ | |
3490 | static void | |
3491 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | |
3492 | { | |
3493 | u8 ascq; | |
3494 | ||
3495 | switch (ioc_status) { | |
3496 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
3497 | ascq = 0x01; | |
3498 | break; | |
3499 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
3500 | ascq = 0x02; | |
3501 | break; | |
3502 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
3503 | ascq = 0x03; | |
3504 | break; | |
3505 | default: | |
3506 | ascq = 0x00; | |
3507 | break; | |
3508 | } | |
3509 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, | |
3510 | ascq); | |
3511 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | |
3512 | SAM_STAT_CHECK_CONDITION; | |
3513 | } | |
3514 | ||
3515 | ||
3516 | /** | |
d8bfbd8d | 3517 | * _scsih_qcmd - main scsi request entry point |
f92363d1 SR |
3518 | * @scmd: pointer to scsi command object |
3519 | * @done: function pointer to be invoked on completion | |
3520 | * | |
3521 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | |
3522 | * | |
3523 | * Returns 0 on success. If there's a failure, return either: | |
3524 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | |
3525 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | |
3526 | */ | |
3527 | static int | |
d8bfbd8d | 3528 | _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
f92363d1 | 3529 | { |
d8bfbd8d | 3530 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
f92363d1 SR |
3531 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
3532 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3533 | Mpi2SCSIIORequest_t *mpi_request; | |
3534 | u32 mpi_control; | |
3535 | u16 smid; | |
3536 | u16 handle; | |
3537 | ||
3538 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
3539 | if (ioc->logging_level & MPT_DEBUG_SCSI) | |
3540 | scsi_print_command(scmd); | |
3541 | #endif | |
3542 | ||
f92363d1 SR |
3543 | sas_device_priv_data = scmd->device->hostdata; |
3544 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | |
3545 | scmd->result = DID_NO_CONNECT << 16; | |
3546 | scmd->scsi_done(scmd); | |
3547 | return 0; | |
3548 | } | |
3549 | ||
3550 | if (ioc->pci_error_recovery || ioc->remove_host) { | |
3551 | scmd->result = DID_NO_CONNECT << 16; | |
3552 | scmd->scsi_done(scmd); | |
3553 | return 0; | |
3554 | } | |
3555 | ||
3556 | sas_target_priv_data = sas_device_priv_data->sas_target; | |
3557 | ||
3558 | /* invalid device handle */ | |
3559 | handle = sas_target_priv_data->handle; | |
3560 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { | |
3561 | scmd->result = DID_NO_CONNECT << 16; | |
3562 | scmd->scsi_done(scmd); | |
3563 | return 0; | |
3564 | } | |
3565 | ||
3566 | ||
3567 | /* host recovery or link resets sent via IOCTLs */ | |
3568 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | |
3569 | return SCSI_MLQUEUE_HOST_BUSY; | |
3570 | ||
3571 | /* device has been deleted */ | |
3572 | else if (sas_target_priv_data->deleted) { | |
3573 | scmd->result = DID_NO_CONNECT << 16; | |
3574 | scmd->scsi_done(scmd); | |
3575 | return 0; | |
3576 | /* device busy with task managment */ | |
3577 | } else if (sas_target_priv_data->tm_busy || | |
3578 | sas_device_priv_data->block) | |
3579 | return SCSI_MLQUEUE_DEVICE_BUSY; | |
3580 | ||
3581 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) | |
3582 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | |
3583 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | |
3584 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | |
3585 | else | |
3586 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | |
3587 | ||
3588 | /* set tags */ | |
3589 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { | |
3590 | if (scmd->device->tagged_supported) { | |
3591 | if (scmd->device->ordered_tags) | |
3592 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; | |
3593 | else | |
3594 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; | |
3595 | } else | |
3596 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; | |
3597 | } else | |
3598 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; | |
3599 | ||
3600 | if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && | |
3601 | scmd->cmd_len != 32) | |
3602 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; | |
3603 | ||
3604 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | |
3605 | if (!smid) { | |
3606 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
3607 | ioc->name, __func__); | |
3608 | goto out; | |
3609 | } | |
3610 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
3611 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); | |
3612 | _scsih_setup_eedp(ioc, scmd, mpi_request); | |
3613 | ||
3614 | if (scmd->cmd_len == 32) | |
3615 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | |
3616 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
3617 | if (sas_device_priv_data->sas_target->flags & | |
3618 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
3619 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | |
3620 | else | |
3621 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | |
3622 | mpi_request->DevHandle = cpu_to_le16(handle); | |
3623 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | |
3624 | mpi_request->Control = cpu_to_le32(mpi_control); | |
3625 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | |
3626 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | |
3627 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | |
3628 | mpi_request->SenseBufferLowAddress = | |
3629 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); | |
3630 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; | |
3631 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) | |
3632 | mpi_request->LUN); | |
3633 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | |
3634 | ||
3635 | if (mpi_request->DataLength) { | |
3636 | if (ioc->build_sg_scmd(ioc, scmd, smid)) { | |
3637 | mpt3sas_base_free_smid(ioc, smid); | |
3638 | goto out; | |
3639 | } | |
3640 | } else | |
3641 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); | |
3642 | ||
3643 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { | |
3644 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { | |
3645 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | | |
3646 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); | |
3647 | mpt3sas_base_put_smid_fast_path(ioc, smid, handle); | |
3648 | } else | |
3649 | mpt3sas_base_put_smid_scsi_io(ioc, smid, handle); | |
3650 | } else | |
3651 | mpt3sas_base_put_smid_default(ioc, smid); | |
3652 | return 0; | |
3653 | ||
3654 | out: | |
3655 | return SCSI_MLQUEUE_HOST_BUSY; | |
3656 | } | |
f92363d1 SR |
3657 | |
3658 | /** | |
3659 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | |
3660 | * @sense_buffer: sense data returned by target | |
3661 | * @data: normalized skey/asc/ascq | |
3662 | * | |
3663 | * Return nothing. | |
3664 | */ | |
3665 | static void | |
3666 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | |
3667 | { | |
3668 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | |
3669 | /* descriptor format */ | |
3670 | data->skey = sense_buffer[1] & 0x0F; | |
3671 | data->asc = sense_buffer[2]; | |
3672 | data->ascq = sense_buffer[3]; | |
3673 | } else { | |
3674 | /* fixed format */ | |
3675 | data->skey = sense_buffer[2] & 0x0F; | |
3676 | data->asc = sense_buffer[12]; | |
3677 | data->ascq = sense_buffer[13]; | |
3678 | } | |
3679 | } | |
3680 | ||
3681 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
3682 | /** | |
3683 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request | |
3684 | * @ioc: per adapter object | |
3685 | * @scmd: pointer to scsi command object | |
3686 | * @mpi_reply: reply mf payload returned from firmware | |
3687 | * | |
3688 | * scsi_status - SCSI Status code returned from target device | |
3689 | * scsi_state - state info associated with SCSI_IO determined by ioc | |
3690 | * ioc_status - ioc supplied status info | |
3691 | * | |
3692 | * Return nothing. | |
3693 | */ | |
3694 | static void | |
3695 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | |
3696 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | |
3697 | { | |
3698 | u32 response_info; | |
3699 | u8 *response_bytes; | |
3700 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | |
3701 | MPI2_IOCSTATUS_MASK; | |
3702 | u8 scsi_state = mpi_reply->SCSIState; | |
3703 | u8 scsi_status = mpi_reply->SCSIStatus; | |
3704 | char *desc_ioc_state = NULL; | |
3705 | char *desc_scsi_status = NULL; | |
3706 | char *desc_scsi_state = ioc->tmp_string; | |
3707 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
3708 | struct _sas_device *sas_device = NULL; | |
3709 | unsigned long flags; | |
3710 | struct scsi_target *starget = scmd->device->sdev_target; | |
3711 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; | |
3712 | char *device_str = NULL; | |
3713 | ||
3714 | if (!priv_target) | |
3715 | return; | |
3716 | device_str = "volume"; | |
3717 | ||
3718 | if (log_info == 0x31170000) | |
3719 | return; | |
3720 | ||
3721 | switch (ioc_status) { | |
3722 | case MPI2_IOCSTATUS_SUCCESS: | |
3723 | desc_ioc_state = "success"; | |
3724 | break; | |
3725 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
3726 | desc_ioc_state = "invalid function"; | |
3727 | break; | |
3728 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
3729 | desc_ioc_state = "scsi recovered error"; | |
3730 | break; | |
3731 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | |
3732 | desc_ioc_state = "scsi invalid dev handle"; | |
3733 | break; | |
3734 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
3735 | desc_ioc_state = "scsi device not there"; | |
3736 | break; | |
3737 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
3738 | desc_ioc_state = "scsi data overrun"; | |
3739 | break; | |
3740 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
3741 | desc_ioc_state = "scsi data underrun"; | |
3742 | break; | |
3743 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
3744 | desc_ioc_state = "scsi io data error"; | |
3745 | break; | |
3746 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
3747 | desc_ioc_state = "scsi protocol error"; | |
3748 | break; | |
3749 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
3750 | desc_ioc_state = "scsi task terminated"; | |
3751 | break; | |
3752 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
3753 | desc_ioc_state = "scsi residual mismatch"; | |
3754 | break; | |
3755 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
3756 | desc_ioc_state = "scsi task mgmt failed"; | |
3757 | break; | |
3758 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
3759 | desc_ioc_state = "scsi ioc terminated"; | |
3760 | break; | |
3761 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
3762 | desc_ioc_state = "scsi ext terminated"; | |
3763 | break; | |
3764 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
3765 | desc_ioc_state = "eedp guard error"; | |
3766 | break; | |
3767 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
3768 | desc_ioc_state = "eedp ref tag error"; | |
3769 | break; | |
3770 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
3771 | desc_ioc_state = "eedp app tag error"; | |
3772 | break; | |
3773 | default: | |
3774 | desc_ioc_state = "unknown"; | |
3775 | break; | |
3776 | } | |
3777 | ||
3778 | switch (scsi_status) { | |
3779 | case MPI2_SCSI_STATUS_GOOD: | |
3780 | desc_scsi_status = "good"; | |
3781 | break; | |
3782 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | |
3783 | desc_scsi_status = "check condition"; | |
3784 | break; | |
3785 | case MPI2_SCSI_STATUS_CONDITION_MET: | |
3786 | desc_scsi_status = "condition met"; | |
3787 | break; | |
3788 | case MPI2_SCSI_STATUS_BUSY: | |
3789 | desc_scsi_status = "busy"; | |
3790 | break; | |
3791 | case MPI2_SCSI_STATUS_INTERMEDIATE: | |
3792 | desc_scsi_status = "intermediate"; | |
3793 | break; | |
3794 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | |
3795 | desc_scsi_status = "intermediate condmet"; | |
3796 | break; | |
3797 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | |
3798 | desc_scsi_status = "reservation conflict"; | |
3799 | break; | |
3800 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | |
3801 | desc_scsi_status = "command terminated"; | |
3802 | break; | |
3803 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | |
3804 | desc_scsi_status = "task set full"; | |
3805 | break; | |
3806 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | |
3807 | desc_scsi_status = "aca active"; | |
3808 | break; | |
3809 | case MPI2_SCSI_STATUS_TASK_ABORTED: | |
3810 | desc_scsi_status = "task aborted"; | |
3811 | break; | |
3812 | default: | |
3813 | desc_scsi_status = "unknown"; | |
3814 | break; | |
3815 | } | |
3816 | ||
3817 | desc_scsi_state[0] = '\0'; | |
3818 | if (!scsi_state) | |
3819 | desc_scsi_state = " "; | |
3820 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
3821 | strcat(desc_scsi_state, "response info "); | |
3822 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
3823 | strcat(desc_scsi_state, "state terminated "); | |
3824 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | |
3825 | strcat(desc_scsi_state, "no status "); | |
3826 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | |
3827 | strcat(desc_scsi_state, "autosense failed "); | |
3828 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | |
3829 | strcat(desc_scsi_state, "autosense valid "); | |
3830 | ||
3831 | scsi_print_command(scmd); | |
3832 | ||
3833 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | |
3834 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | |
3835 | device_str, (unsigned long long)priv_target->sas_address); | |
3836 | } else { | |
3837 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
3838 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
3839 | priv_target->sas_address); | |
3840 | if (sas_device) { | |
3841 | pr_warn(MPT3SAS_FMT | |
3842 | "\tsas_address(0x%016llx), phy(%d)\n", | |
3843 | ioc->name, (unsigned long long) | |
3844 | sas_device->sas_address, sas_device->phy); | |
3845 | pr_warn(MPT3SAS_FMT | |
3846 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", | |
3847 | ioc->name, (unsigned long long) | |
3848 | sas_device->enclosure_logical_id, sas_device->slot); | |
3849 | } | |
3850 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3851 | } | |
3852 | ||
3853 | pr_warn(MPT3SAS_FMT | |
3854 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", | |
3855 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), | |
3856 | desc_ioc_state, ioc_status, smid); | |
3857 | pr_warn(MPT3SAS_FMT | |
3858 | "\trequest_len(%d), underflow(%d), resid(%d)\n", | |
3859 | ioc->name, scsi_bufflen(scmd), scmd->underflow, | |
3860 | scsi_get_resid(scmd)); | |
3861 | pr_warn(MPT3SAS_FMT | |
3862 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", | |
3863 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), | |
3864 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | |
3865 | pr_warn(MPT3SAS_FMT | |
3866 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", | |
3867 | ioc->name, desc_scsi_status, | |
3868 | scsi_status, desc_scsi_state, scsi_state); | |
3869 | ||
3870 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
3871 | struct sense_info data; | |
3872 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
3873 | pr_warn(MPT3SAS_FMT | |
3874 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", | |
3875 | ioc->name, data.skey, | |
3876 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | |
3877 | } | |
3878 | ||
3879 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { | |
3880 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | |
3881 | response_bytes = (u8 *)&response_info; | |
3882 | _scsih_response_code(ioc, response_bytes[0]); | |
3883 | } | |
3884 | } | |
3885 | #endif | |
3886 | ||
3887 | /** | |
3888 | * _scsih_turn_on_fault_led - illuminate Fault LED | |
3889 | * @ioc: per adapter object | |
3890 | * @handle: device handle | |
3891 | * Context: process | |
3892 | * | |
3893 | * Return nothing. | |
3894 | */ | |
3895 | static void | |
3896 | _scsih_turn_on_fault_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3897 | { | |
3898 | Mpi2SepReply_t mpi_reply; | |
3899 | Mpi2SepRequest_t mpi_request; | |
3900 | ||
3901 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | |
3902 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | |
3903 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | |
3904 | mpi_request.SlotStatus = | |
3905 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | |
3906 | mpi_request.DevHandle = cpu_to_le16(handle); | |
3907 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | |
3908 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | |
3909 | &mpi_request)) != 0) { | |
3910 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, | |
3911 | __FILE__, __LINE__, __func__); | |
3912 | return; | |
3913 | } | |
3914 | ||
3915 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | |
3916 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
3917 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | |
3918 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | |
3919 | le32_to_cpu(mpi_reply.IOCLogInfo))); | |
3920 | return; | |
3921 | } | |
3922 | } | |
3923 | ||
3924 | /** | |
3925 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event | |
3926 | * @ioc: per adapter object | |
3927 | * @handle: device handle | |
3928 | * Context: interrupt. | |
3929 | * | |
3930 | * Return nothing. | |
3931 | */ | |
3932 | static void | |
3933 | _scsih_send_event_to_turn_on_fault_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3934 | { | |
3935 | struct fw_event_work *fw_event; | |
3936 | ||
3937 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); | |
3938 | if (!fw_event) | |
3939 | return; | |
3940 | fw_event->event = MPT3SAS_TURN_ON_FAULT_LED; | |
3941 | fw_event->device_handle = handle; | |
3942 | fw_event->ioc = ioc; | |
3943 | _scsih_fw_event_add(ioc, fw_event); | |
3944 | } | |
3945 | ||
3946 | /** | |
3947 | * _scsih_smart_predicted_fault - process smart errors | |
3948 | * @ioc: per adapter object | |
3949 | * @handle: device handle | |
3950 | * Context: interrupt. | |
3951 | * | |
3952 | * Return nothing. | |
3953 | */ | |
3954 | static void | |
3955 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
3956 | { | |
3957 | struct scsi_target *starget; | |
3958 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
3959 | Mpi2EventNotificationReply_t *event_reply; | |
3960 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | |
3961 | struct _sas_device *sas_device; | |
3962 | ssize_t sz; | |
3963 | unsigned long flags; | |
3964 | ||
3965 | /* only handle non-raid devices */ | |
3966 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
3967 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
3968 | if (!sas_device) { | |
3969 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3970 | return; | |
3971 | } | |
3972 | starget = sas_device->starget; | |
3973 | sas_target_priv_data = starget->hostdata; | |
3974 | ||
3975 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | |
3976 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { | |
3977 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3978 | return; | |
3979 | } | |
3980 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); | |
3981 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
3982 | ||
3983 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | |
3984 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); | |
3985 | ||
3986 | /* insert into event log */ | |
3987 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | |
3988 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | |
3989 | event_reply = kzalloc(sz, GFP_KERNEL); | |
3990 | if (!event_reply) { | |
3991 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
3992 | ioc->name, __FILE__, __LINE__, __func__); | |
3993 | return; | |
3994 | } | |
3995 | ||
3996 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | |
3997 | event_reply->Event = | |
3998 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | |
3999 | event_reply->MsgLength = sz/4; | |
4000 | event_reply->EventDataLength = | |
4001 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | |
4002 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | |
4003 | event_reply->EventData; | |
4004 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | |
4005 | event_data->ASC = 0x5D; | |
4006 | event_data->DevHandle = cpu_to_le16(handle); | |
4007 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | |
4008 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); | |
4009 | kfree(event_reply); | |
4010 | } | |
4011 | ||
4012 | /** | |
4013 | * _scsih_io_done - scsi request callback | |
4014 | * @ioc: per adapter object | |
4015 | * @smid: system request message index | |
4016 | * @msix_index: MSIX table index supplied by the OS | |
4017 | * @reply: reply message frame(lower 32bit addr) | |
4018 | * | |
4019 | * Callback handler when using _scsih_qcmd. | |
4020 | * | |
4021 | * Return 1 meaning mf should be freed from _base_interrupt | |
4022 | * 0 means the mf is freed from this function. | |
4023 | */ | |
4024 | static u8 | |
4025 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
4026 | { | |
4027 | Mpi2SCSIIORequest_t *mpi_request; | |
4028 | Mpi2SCSIIOReply_t *mpi_reply; | |
4029 | struct scsi_cmnd *scmd; | |
4030 | u16 ioc_status; | |
4031 | u32 xfer_cnt; | |
4032 | u8 scsi_state; | |
4033 | u8 scsi_status; | |
4034 | u32 log_info; | |
4035 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
4036 | u32 response_code = 0; | |
4037 | ||
4038 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
4039 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | |
4040 | if (scmd == NULL) | |
4041 | return 1; | |
4042 | ||
4043 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
4044 | ||
4045 | if (mpi_reply == NULL) { | |
4046 | scmd->result = DID_OK << 16; | |
4047 | goto out; | |
4048 | } | |
4049 | ||
4050 | sas_device_priv_data = scmd->device->hostdata; | |
4051 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | |
4052 | sas_device_priv_data->sas_target->deleted) { | |
4053 | scmd->result = DID_NO_CONNECT << 16; | |
4054 | goto out; | |
4055 | } | |
4056 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
4057 | ||
4058 | /* turning off TLR */ | |
4059 | scsi_state = mpi_reply->SCSIState; | |
4060 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | |
4061 | response_code = | |
4062 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | |
4063 | if (!sas_device_priv_data->tlr_snoop_check) { | |
4064 | sas_device_priv_data->tlr_snoop_check++; | |
4065 | if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && | |
4066 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) | |
4067 | sas_device_priv_data->flags &= | |
4068 | ~MPT_DEVICE_TLR_ON; | |
4069 | } | |
4070 | ||
4071 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | |
4072 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | |
4073 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
4074 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
4075 | else | |
4076 | log_info = 0; | |
4077 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
4078 | scsi_status = mpi_reply->SCSIStatus; | |
4079 | ||
4080 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | |
4081 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | |
4082 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | |
4083 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | |
4084 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | |
4085 | } | |
4086 | ||
4087 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | |
4088 | struct sense_info data; | |
4089 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, | |
4090 | smid); | |
4091 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | |
4092 | le32_to_cpu(mpi_reply->SenseCount)); | |
4093 | memcpy(scmd->sense_buffer, sense_data, sz); | |
4094 | _scsih_normalize_sense(scmd->sense_buffer, &data); | |
4095 | /* failure prediction threshold exceeded */ | |
4096 | if (data.asc == 0x5D) | |
4097 | _scsih_smart_predicted_fault(ioc, | |
4098 | le16_to_cpu(mpi_reply->DevHandle)); | |
4099 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); | |
4100 | } | |
4101 | ||
4102 | switch (ioc_status) { | |
4103 | case MPI2_IOCSTATUS_BUSY: | |
4104 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | |
4105 | scmd->result = SAM_STAT_BUSY; | |
4106 | break; | |
4107 | ||
4108 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | |
4109 | scmd->result = DID_NO_CONNECT << 16; | |
4110 | break; | |
4111 | ||
4112 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | |
4113 | if (sas_device_priv_data->block) { | |
4114 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | |
4115 | goto out; | |
4116 | } | |
4117 | if (log_info == 0x31110630) { | |
4118 | if (scmd->retries > 2) { | |
4119 | scmd->result = DID_NO_CONNECT << 16; | |
4120 | scsi_device_set_state(scmd->device, | |
4121 | SDEV_OFFLINE); | |
4122 | } else { | |
4123 | scmd->result = DID_SOFT_ERROR << 16; | |
4124 | scmd->device->expecting_cc_ua = 1; | |
4125 | } | |
4126 | break; | |
4127 | } | |
4128 | scmd->result = DID_SOFT_ERROR << 16; | |
4129 | break; | |
4130 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | |
4131 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | |
4132 | scmd->result = DID_RESET << 16; | |
4133 | break; | |
4134 | ||
4135 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | |
4136 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | |
4137 | scmd->result = DID_SOFT_ERROR << 16; | |
4138 | else | |
4139 | scmd->result = (DID_OK << 16) | scsi_status; | |
4140 | break; | |
4141 | ||
4142 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | |
4143 | scmd->result = (DID_OK << 16) | scsi_status; | |
4144 | ||
4145 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | |
4146 | break; | |
4147 | ||
4148 | if (xfer_cnt < scmd->underflow) { | |
4149 | if (scsi_status == SAM_STAT_BUSY) | |
4150 | scmd->result = SAM_STAT_BUSY; | |
4151 | else | |
4152 | scmd->result = DID_SOFT_ERROR << 16; | |
4153 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
4154 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | |
4155 | scmd->result = DID_SOFT_ERROR << 16; | |
4156 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4157 | scmd->result = DID_RESET << 16; | |
4158 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | |
4159 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | |
4160 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | |
4161 | scmd->result = (DRIVER_SENSE << 24) | | |
4162 | SAM_STAT_CHECK_CONDITION; | |
4163 | scmd->sense_buffer[0] = 0x70; | |
4164 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | |
4165 | scmd->sense_buffer[12] = 0x20; | |
4166 | scmd->sense_buffer[13] = 0; | |
4167 | } | |
4168 | break; | |
4169 | ||
4170 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | |
4171 | scsi_set_resid(scmd, 0); | |
4172 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | |
4173 | case MPI2_IOCSTATUS_SUCCESS: | |
4174 | scmd->result = (DID_OK << 16) | scsi_status; | |
4175 | if (response_code == | |
4176 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | |
4177 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | |
4178 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | |
4179 | scmd->result = DID_SOFT_ERROR << 16; | |
4180 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | |
4181 | scmd->result = DID_RESET << 16; | |
4182 | break; | |
4183 | ||
4184 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | |
4185 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | |
4186 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | |
4187 | _scsih_eedp_error_handling(scmd, ioc_status); | |
4188 | break; | |
4189 | ||
4190 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | |
4191 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | |
4192 | case MPI2_IOCSTATUS_INVALID_SGL: | |
4193 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | |
4194 | case MPI2_IOCSTATUS_INVALID_FIELD: | |
4195 | case MPI2_IOCSTATUS_INVALID_STATE: | |
4196 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | |
4197 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | |
4198 | default: | |
4199 | scmd->result = DID_SOFT_ERROR << 16; | |
4200 | break; | |
4201 | ||
4202 | } | |
4203 | ||
4204 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
4205 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) | |
4206 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | |
4207 | #endif | |
4208 | ||
4209 | out: | |
4210 | ||
4211 | scsi_dma_unmap(scmd); | |
4212 | ||
4213 | scmd->scsi_done(scmd); | |
4214 | return 1; | |
4215 | } | |
4216 | ||
4217 | /** | |
4218 | * _scsih_sas_host_refresh - refreshing sas host object contents | |
4219 | * @ioc: per adapter object | |
4220 | * Context: user | |
4221 | * | |
4222 | * During port enable, fw will send topology events for every device. Its | |
4223 | * possible that the handles may change from the previous setting, so this | |
4224 | * code keeping handles updating if changed. | |
4225 | * | |
4226 | * Return nothing. | |
4227 | */ | |
4228 | static void | |
4229 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) | |
4230 | { | |
4231 | u16 sz; | |
4232 | u16 ioc_status; | |
4233 | int i; | |
4234 | Mpi2ConfigReply_t mpi_reply; | |
4235 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
4236 | u16 attached_handle; | |
4237 | u8 link_rate; | |
4238 | ||
4239 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
4240 | "updating handles for sas_host(0x%016llx)\n", | |
4241 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | |
4242 | ||
4243 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | |
4244 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | |
4245 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
4246 | if (!sas_iounit_pg0) { | |
4247 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4248 | ioc->name, __FILE__, __LINE__, __func__); | |
4249 | return; | |
4250 | } | |
4251 | ||
4252 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
4253 | sas_iounit_pg0, sz)) != 0) | |
4254 | goto out; | |
4255 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
4256 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
4257 | goto out; | |
4258 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
4259 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | |
4260 | if (i == 0) | |
4261 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
4262 | PhyData[0].ControllerDevHandle); | |
4263 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
4264 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | |
4265 | AttachedDevHandle); | |
4266 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
4267 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | |
4268 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | |
4269 | attached_handle, i, link_rate); | |
4270 | } | |
4271 | out: | |
4272 | kfree(sas_iounit_pg0); | |
4273 | } | |
4274 | ||
4275 | /** | |
4276 | * _scsih_sas_host_add - create sas host object | |
4277 | * @ioc: per adapter object | |
4278 | * | |
4279 | * Creating host side data object, stored in ioc->sas_hba | |
4280 | * | |
4281 | * Return nothing. | |
4282 | */ | |
4283 | static void | |
4284 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) | |
4285 | { | |
4286 | int i; | |
4287 | Mpi2ConfigReply_t mpi_reply; | |
4288 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | |
4289 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | |
4290 | Mpi2SasPhyPage0_t phy_pg0; | |
4291 | Mpi2SasDevicePage0_t sas_device_pg0; | |
4292 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
4293 | u16 ioc_status; | |
4294 | u16 sz; | |
4295 | u8 device_missing_delay; | |
4296 | ||
4297 | mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); | |
4298 | if (!ioc->sas_hba.num_phys) { | |
4299 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4300 | ioc->name, __FILE__, __LINE__, __func__); | |
4301 | return; | |
4302 | } | |
4303 | ||
4304 | /* sas_iounit page 0 */ | |
4305 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | |
4306 | sizeof(Mpi2SasIOUnit0PhyData_t)); | |
4307 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | |
4308 | if (!sas_iounit_pg0) { | |
4309 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4310 | ioc->name, __FILE__, __LINE__, __func__); | |
4311 | return; | |
4312 | } | |
4313 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | |
4314 | sas_iounit_pg0, sz))) { | |
4315 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4316 | ioc->name, __FILE__, __LINE__, __func__); | |
4317 | goto out; | |
4318 | } | |
4319 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4320 | MPI2_IOCSTATUS_MASK; | |
4321 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4322 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4323 | ioc->name, __FILE__, __LINE__, __func__); | |
4324 | goto out; | |
4325 | } | |
4326 | ||
4327 | /* sas_iounit page 1 */ | |
4328 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | |
4329 | sizeof(Mpi2SasIOUnit1PhyData_t)); | |
4330 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | |
4331 | if (!sas_iounit_pg1) { | |
4332 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4333 | ioc->name, __FILE__, __LINE__, __func__); | |
4334 | goto out; | |
4335 | } | |
4336 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | |
4337 | sas_iounit_pg1, sz))) { | |
4338 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4339 | ioc->name, __FILE__, __LINE__, __func__); | |
4340 | goto out; | |
4341 | } | |
4342 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4343 | MPI2_IOCSTATUS_MASK; | |
4344 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4345 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4346 | ioc->name, __FILE__, __LINE__, __func__); | |
4347 | goto out; | |
4348 | } | |
4349 | ||
4350 | ioc->io_missing_delay = | |
4351 | sas_iounit_pg1->IODeviceMissingDelay; | |
4352 | device_missing_delay = | |
4353 | sas_iounit_pg1->ReportDeviceMissingDelay; | |
4354 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | |
4355 | ioc->device_missing_delay = (device_missing_delay & | |
4356 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | |
4357 | else | |
4358 | ioc->device_missing_delay = device_missing_delay & | |
4359 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | |
4360 | ||
4361 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | |
4362 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, | |
4363 | sizeof(struct _sas_phy), GFP_KERNEL); | |
4364 | if (!ioc->sas_hba.phy) { | |
4365 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4366 | ioc->name, __FILE__, __LINE__, __func__); | |
4367 | goto out; | |
4368 | } | |
4369 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | |
4370 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | |
4371 | i))) { | |
4372 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4373 | ioc->name, __FILE__, __LINE__, __func__); | |
4374 | goto out; | |
4375 | } | |
4376 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4377 | MPI2_IOCSTATUS_MASK; | |
4378 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4379 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4380 | ioc->name, __FILE__, __LINE__, __func__); | |
4381 | goto out; | |
4382 | } | |
4383 | ||
4384 | if (i == 0) | |
4385 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | |
4386 | PhyData[0].ControllerDevHandle); | |
4387 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | |
4388 | ioc->sas_hba.phy[i].phy_id = i; | |
4389 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | |
4390 | phy_pg0, ioc->sas_hba.parent_dev); | |
4391 | } | |
4392 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
4393 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | |
4394 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4395 | ioc->name, __FILE__, __LINE__, __func__); | |
4396 | goto out; | |
4397 | } | |
4398 | ioc->sas_hba.enclosure_handle = | |
4399 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
4400 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
4401 | pr_info(MPT3SAS_FMT | |
4402 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", | |
4403 | ioc->name, ioc->sas_hba.handle, | |
4404 | (unsigned long long) ioc->sas_hba.sas_address, | |
4405 | ioc->sas_hba.num_phys) ; | |
4406 | ||
4407 | if (ioc->sas_hba.enclosure_handle) { | |
4408 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
4409 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
4410 | ioc->sas_hba.enclosure_handle))) | |
4411 | ioc->sas_hba.enclosure_logical_id = | |
4412 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
4413 | } | |
4414 | ||
4415 | out: | |
4416 | kfree(sas_iounit_pg1); | |
4417 | kfree(sas_iounit_pg0); | |
4418 | } | |
4419 | ||
4420 | /** | |
4421 | * _scsih_expander_add - creating expander object | |
4422 | * @ioc: per adapter object | |
4423 | * @handle: expander handle | |
4424 | * | |
4425 | * Creating expander object, stored in ioc->sas_expander_list. | |
4426 | * | |
4427 | * Return 0 for success, else error. | |
4428 | */ | |
4429 | static int | |
4430 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
4431 | { | |
4432 | struct _sas_node *sas_expander; | |
4433 | Mpi2ConfigReply_t mpi_reply; | |
4434 | Mpi2ExpanderPage0_t expander_pg0; | |
4435 | Mpi2ExpanderPage1_t expander_pg1; | |
4436 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
4437 | u32 ioc_status; | |
4438 | u16 parent_handle; | |
4439 | u64 sas_address, sas_address_parent = 0; | |
4440 | int i; | |
4441 | unsigned long flags; | |
4442 | struct _sas_port *mpt3sas_port = NULL; | |
4443 | ||
4444 | int rc = 0; | |
4445 | ||
4446 | if (!handle) | |
4447 | return -1; | |
4448 | ||
4449 | if (ioc->shost_recovery || ioc->pci_error_recovery) | |
4450 | return -1; | |
4451 | ||
4452 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
4453 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | |
4454 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4455 | ioc->name, __FILE__, __LINE__, __func__); | |
4456 | return -1; | |
4457 | } | |
4458 | ||
4459 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4460 | MPI2_IOCSTATUS_MASK; | |
4461 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4462 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4463 | ioc->name, __FILE__, __LINE__, __func__); | |
4464 | return -1; | |
4465 | } | |
4466 | ||
4467 | /* handle out of order topology events */ | |
4468 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | |
4469 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | |
4470 | != 0) { | |
4471 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4472 | ioc->name, __FILE__, __LINE__, __func__); | |
4473 | return -1; | |
4474 | } | |
4475 | if (sas_address_parent != ioc->sas_hba.sas_address) { | |
4476 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4477 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
4478 | sas_address_parent); | |
4479 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4480 | if (!sas_expander) { | |
4481 | rc = _scsih_expander_add(ioc, parent_handle); | |
4482 | if (rc != 0) | |
4483 | return rc; | |
4484 | } | |
4485 | } | |
4486 | ||
4487 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4488 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
4489 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
4490 | sas_address); | |
4491 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4492 | ||
4493 | if (sas_expander) | |
4494 | return 0; | |
4495 | ||
4496 | sas_expander = kzalloc(sizeof(struct _sas_node), | |
4497 | GFP_KERNEL); | |
4498 | if (!sas_expander) { | |
4499 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4500 | ioc->name, __FILE__, __LINE__, __func__); | |
4501 | return -1; | |
4502 | } | |
4503 | ||
4504 | sas_expander->handle = handle; | |
4505 | sas_expander->num_phys = expander_pg0.NumPhys; | |
4506 | sas_expander->sas_address_parent = sas_address_parent; | |
4507 | sas_expander->sas_address = sas_address; | |
4508 | ||
4509 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ | |
4510 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | |
4511 | handle, parent_handle, (unsigned long long) | |
4512 | sas_expander->sas_address, sas_expander->num_phys); | |
4513 | ||
4514 | if (!sas_expander->num_phys) | |
4515 | goto out_fail; | |
4516 | sas_expander->phy = kcalloc(sas_expander->num_phys, | |
4517 | sizeof(struct _sas_phy), GFP_KERNEL); | |
4518 | if (!sas_expander->phy) { | |
4519 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4520 | ioc->name, __FILE__, __LINE__, __func__); | |
4521 | rc = -1; | |
4522 | goto out_fail; | |
4523 | } | |
4524 | ||
4525 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | |
4526 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, | |
4527 | sas_address_parent); | |
4528 | if (!mpt3sas_port) { | |
4529 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4530 | ioc->name, __FILE__, __LINE__, __func__); | |
4531 | rc = -1; | |
4532 | goto out_fail; | |
4533 | } | |
4534 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; | |
4535 | ||
4536 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
4537 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
4538 | &expander_pg1, i, handle))) { | |
4539 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4540 | ioc->name, __FILE__, __LINE__, __func__); | |
4541 | rc = -1; | |
4542 | goto out_fail; | |
4543 | } | |
4544 | sas_expander->phy[i].handle = handle; | |
4545 | sas_expander->phy[i].phy_id = i; | |
4546 | ||
4547 | if ((mpt3sas_transport_add_expander_phy(ioc, | |
4548 | &sas_expander->phy[i], expander_pg1, | |
4549 | sas_expander->parent_dev))) { | |
4550 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4551 | ioc->name, __FILE__, __LINE__, __func__); | |
4552 | rc = -1; | |
4553 | goto out_fail; | |
4554 | } | |
4555 | } | |
4556 | ||
4557 | if (sas_expander->enclosure_handle) { | |
4558 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, | |
4559 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
4560 | sas_expander->enclosure_handle))) | |
4561 | sas_expander->enclosure_logical_id = | |
4562 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
4563 | } | |
4564 | ||
4565 | _scsih_expander_node_add(ioc, sas_expander); | |
4566 | return 0; | |
4567 | ||
4568 | out_fail: | |
4569 | ||
4570 | if (mpt3sas_port) | |
4571 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
4572 | sas_address_parent); | |
4573 | kfree(sas_expander); | |
4574 | return rc; | |
4575 | } | |
4576 | ||
4577 | /** | |
4578 | * mpt3sas_expander_remove - removing expander object | |
4579 | * @ioc: per adapter object | |
4580 | * @sas_address: expander sas_address | |
4581 | * | |
4582 | * Return nothing. | |
4583 | */ | |
4584 | void | |
4585 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) | |
4586 | { | |
4587 | struct _sas_node *sas_expander; | |
4588 | unsigned long flags; | |
4589 | ||
4590 | if (ioc->shost_recovery) | |
4591 | return; | |
4592 | ||
4593 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
4594 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, | |
4595 | sas_address); | |
4596 | if (sas_expander) | |
4597 | list_del(&sas_expander->list); | |
4598 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
4599 | if (sas_expander) | |
4600 | _scsih_expander_node_remove(ioc, sas_expander); | |
4601 | } | |
4602 | ||
4603 | /** | |
4604 | * _scsih_done - internal SCSI_IO callback handler. | |
4605 | * @ioc: per adapter object | |
4606 | * @smid: system request message index | |
4607 | * @msix_index: MSIX table index supplied by the OS | |
4608 | * @reply: reply message frame(lower 32bit addr) | |
4609 | * | |
4610 | * Callback handler when sending internal generated SCSI_IO. | |
4611 | * The callback index passed is `ioc->scsih_cb_idx` | |
4612 | * | |
4613 | * Return 1 meaning mf should be freed from _base_interrupt | |
4614 | * 0 means the mf is freed from this function. | |
4615 | */ | |
4616 | static u8 | |
4617 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | |
4618 | { | |
4619 | MPI2DefaultReply_t *mpi_reply; | |
4620 | ||
4621 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
4622 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) | |
4623 | return 1; | |
4624 | if (ioc->scsih_cmds.smid != smid) | |
4625 | return 1; | |
4626 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; | |
4627 | if (mpi_reply) { | |
4628 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | |
4629 | mpi_reply->MsgLength*4); | |
4630 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; | |
4631 | } | |
4632 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; | |
4633 | complete(&ioc->scsih_cmds.done); | |
4634 | return 1; | |
4635 | } | |
4636 | ||
4637 | ||
4638 | ||
4639 | ||
4640 | #define MPT3_MAX_LUNS (255) | |
4641 | ||
4642 | ||
4643 | /** | |
4644 | * _scsih_check_access_status - check access flags | |
4645 | * @ioc: per adapter object | |
4646 | * @sas_address: sas address | |
4647 | * @handle: sas device handle | |
4648 | * @access_flags: errors returned during discovery of the device | |
4649 | * | |
4650 | * Return 0 for success, else failure | |
4651 | */ | |
4652 | static u8 | |
4653 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
4654 | u16 handle, u8 access_status) | |
4655 | { | |
4656 | u8 rc = 1; | |
4657 | char *desc = NULL; | |
4658 | ||
4659 | switch (access_status) { | |
4660 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | |
4661 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | |
4662 | rc = 0; | |
4663 | break; | |
4664 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | |
4665 | desc = "sata capability failed"; | |
4666 | break; | |
4667 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | |
4668 | desc = "sata affiliation conflict"; | |
4669 | break; | |
4670 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | |
4671 | desc = "route not addressable"; | |
4672 | break; | |
4673 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | |
4674 | desc = "smp error not addressable"; | |
4675 | break; | |
4676 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | |
4677 | desc = "device blocked"; | |
4678 | break; | |
4679 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | |
4680 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | |
4681 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | |
4682 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | |
4683 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | |
4684 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | |
4685 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | |
4686 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | |
4687 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | |
4688 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | |
4689 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | |
4690 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | |
4691 | desc = "sata initialization failed"; | |
4692 | break; | |
4693 | default: | |
4694 | desc = "unknown"; | |
4695 | break; | |
4696 | } | |
4697 | ||
4698 | if (!rc) | |
4699 | return 0; | |
4700 | ||
4701 | pr_err(MPT3SAS_FMT | |
4702 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", | |
4703 | ioc->name, desc, (unsigned long long)sas_address, handle); | |
4704 | return rc; | |
4705 | } | |
4706 | ||
4707 | /** | |
4708 | * _scsih_check_device - checking device responsiveness | |
4709 | * @ioc: per adapter object | |
4710 | * @parent_sas_address: sas address of parent expander or sas host | |
4711 | * @handle: attached device handle | |
4712 | * @phy_numberv: phy number | |
4713 | * @link_rate: new link rate | |
4714 | * | |
4715 | * Returns nothing. | |
4716 | */ | |
4717 | static void | |
4718 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, | |
4719 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) | |
4720 | { | |
4721 | Mpi2ConfigReply_t mpi_reply; | |
4722 | Mpi2SasDevicePage0_t sas_device_pg0; | |
4723 | struct _sas_device *sas_device; | |
4724 | u32 ioc_status; | |
4725 | unsigned long flags; | |
4726 | u64 sas_address; | |
4727 | struct scsi_target *starget; | |
4728 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4729 | u32 device_info; | |
4730 | ||
4731 | ||
4732 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
4733 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | |
4734 | return; | |
4735 | ||
4736 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | |
4737 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | |
4738 | return; | |
4739 | ||
4740 | /* wide port handling ~ we need only handle device once for the phy that | |
4741 | * is matched in sas device page zero | |
4742 | */ | |
4743 | if (phy_number != sas_device_pg0.PhyNum) | |
4744 | return; | |
4745 | ||
4746 | /* check if this is end device */ | |
4747 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
4748 | if (!(_scsih_is_end_device(device_info))) | |
4749 | return; | |
4750 | ||
4751 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
4752 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
4753 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
4754 | sas_address); | |
4755 | ||
4756 | if (!sas_device) { | |
4757 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4758 | return; | |
4759 | } | |
4760 | ||
4761 | if (unlikely(sas_device->handle != handle)) { | |
4762 | starget = sas_device->starget; | |
4763 | sas_target_priv_data = starget->hostdata; | |
4764 | starget_printk(KERN_INFO, starget, | |
4765 | "handle changed from(0x%04x) to (0x%04x)!!!\n", | |
4766 | sas_device->handle, handle); | |
4767 | sas_target_priv_data->handle = handle; | |
4768 | sas_device->handle = handle; | |
4769 | } | |
4770 | ||
4771 | /* check if device is present */ | |
4772 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
4773 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
4774 | pr_err(MPT3SAS_FMT | |
4775 | "device is not present handle(0x%04x), flags!!!\n", | |
4776 | ioc->name, handle); | |
4777 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4778 | return; | |
4779 | } | |
4780 | ||
4781 | /* check if there were any issues with discovery */ | |
4782 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
4783 | sas_device_pg0.AccessStatus)) { | |
4784 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4785 | return; | |
4786 | } | |
4787 | ||
4788 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4789 | _scsih_ublock_io_device(ioc, sas_address); | |
4790 | ||
4791 | } | |
4792 | ||
4793 | /** | |
4794 | * _scsih_add_device - creating sas device object | |
4795 | * @ioc: per adapter object | |
4796 | * @handle: sas device handle | |
4797 | * @phy_num: phy number end device attached to | |
4798 | * @is_pd: is this hidden raid component | |
4799 | * | |
4800 | * Creating end device object, stored in ioc->sas_device_list. | |
4801 | * | |
4802 | * Returns 0 for success, non-zero for failure. | |
4803 | */ | |
4804 | static int | |
4805 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, | |
4806 | u8 is_pd) | |
4807 | { | |
4808 | Mpi2ConfigReply_t mpi_reply; | |
4809 | Mpi2SasDevicePage0_t sas_device_pg0; | |
4810 | Mpi2SasEnclosurePage0_t enclosure_pg0; | |
4811 | struct _sas_device *sas_device; | |
4812 | u32 ioc_status; | |
4813 | u64 sas_address; | |
4814 | u32 device_info; | |
4815 | unsigned long flags; | |
4816 | ||
4817 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
4818 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
4819 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4820 | ioc->name, __FILE__, __LINE__, __func__); | |
4821 | return -1; | |
4822 | } | |
4823 | ||
4824 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
4825 | MPI2_IOCSTATUS_MASK; | |
4826 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
4827 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4828 | ioc->name, __FILE__, __LINE__, __func__); | |
4829 | return -1; | |
4830 | } | |
4831 | ||
4832 | /* check if this is end device */ | |
4833 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
4834 | if (!(_scsih_is_end_device(device_info))) | |
4835 | return -1; | |
4836 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | |
4837 | ||
4838 | /* check if device is present */ | |
4839 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | |
4840 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | |
4841 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", | |
4842 | ioc->name, handle); | |
4843 | return -1; | |
4844 | } | |
4845 | ||
4846 | /* check if there were any issues with discovery */ | |
4847 | if (_scsih_check_access_status(ioc, sas_address, handle, | |
4848 | sas_device_pg0.AccessStatus)) | |
4849 | return -1; | |
4850 | ||
4851 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
4852 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
4853 | sas_address); | |
4854 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
4855 | ||
4856 | if (sas_device) | |
4857 | return -1; | |
4858 | ||
4859 | sas_device = kzalloc(sizeof(struct _sas_device), | |
4860 | GFP_KERNEL); | |
4861 | if (!sas_device) { | |
4862 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4863 | ioc->name, __FILE__, __LINE__, __func__); | |
4864 | return 0; | |
4865 | } | |
4866 | ||
4867 | sas_device->handle = handle; | |
4868 | if (_scsih_get_sas_address(ioc, | |
4869 | le16_to_cpu(sas_device_pg0.ParentDevHandle), | |
4870 | &sas_device->sas_address_parent) != 0) | |
4871 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
4872 | ioc->name, __FILE__, __LINE__, __func__); | |
4873 | sas_device->enclosure_handle = | |
4874 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | |
4875 | sas_device->slot = | |
4876 | le16_to_cpu(sas_device_pg0.Slot); | |
4877 | sas_device->device_info = device_info; | |
4878 | sas_device->sas_address = sas_address; | |
4879 | sas_device->phy = sas_device_pg0.PhyNum; | |
4880 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & | |
4881 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; | |
4882 | ||
4883 | /* get enclosure_logical_id */ | |
4884 | if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0( | |
4885 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | |
4886 | sas_device->enclosure_handle))) | |
4887 | sas_device->enclosure_logical_id = | |
4888 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | |
4889 | ||
4890 | /* get device name */ | |
4891 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | |
4892 | ||
4893 | if (ioc->wait_for_discovery_to_complete) | |
4894 | _scsih_sas_device_init_add(ioc, sas_device); | |
4895 | else | |
4896 | _scsih_sas_device_add(ioc, sas_device); | |
4897 | ||
4898 | return 0; | |
4899 | } | |
4900 | ||
4901 | /** | |
4902 | * _scsih_remove_device - removing sas device object | |
4903 | * @ioc: per adapter object | |
4904 | * @sas_device_delete: the sas_device object | |
4905 | * | |
4906 | * Return nothing. | |
4907 | */ | |
4908 | static void | |
4909 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, | |
4910 | struct _sas_device *sas_device) | |
4911 | { | |
4912 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
4913 | ||
4914 | ||
4915 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4916 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", | |
4917 | ioc->name, __func__, | |
4918 | sas_device->handle, (unsigned long long) | |
4919 | sas_device->sas_address)); | |
4920 | ||
4921 | if (sas_device->starget && sas_device->starget->hostdata) { | |
4922 | sas_target_priv_data = sas_device->starget->hostdata; | |
4923 | sas_target_priv_data->deleted = 1; | |
4924 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | |
4925 | sas_target_priv_data->handle = | |
4926 | MPT3SAS_INVALID_DEVICE_HANDLE; | |
4927 | } | |
4928 | mpt3sas_transport_port_remove(ioc, | |
4929 | sas_device->sas_address, | |
4930 | sas_device->sas_address_parent); | |
4931 | ||
4932 | pr_info(MPT3SAS_FMT | |
4933 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", | |
4934 | ioc->name, sas_device->handle, | |
4935 | (unsigned long long) sas_device->sas_address); | |
4936 | ||
4937 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
4938 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", | |
4939 | ioc->name, __func__, | |
4940 | sas_device->handle, (unsigned long long) | |
4941 | sas_device->sas_address)); | |
4942 | ||
4943 | kfree(sas_device); | |
4944 | } | |
4945 | ||
4946 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
4947 | /** | |
4948 | * _scsih_sas_topology_change_event_debug - debug for topology event | |
4949 | * @ioc: per adapter object | |
4950 | * @event_data: event data payload | |
4951 | * Context: user. | |
4952 | */ | |
4953 | static void | |
4954 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
4955 | Mpi2EventDataSasTopologyChangeList_t *event_data) | |
4956 | { | |
4957 | int i; | |
4958 | u16 handle; | |
4959 | u16 reason_code; | |
4960 | u8 phy_number; | |
4961 | char *status_str = NULL; | |
4962 | u8 link_rate, prev_link_rate; | |
4963 | ||
4964 | switch (event_data->ExpStatus) { | |
4965 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | |
4966 | status_str = "add"; | |
4967 | break; | |
4968 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | |
4969 | status_str = "remove"; | |
4970 | break; | |
4971 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | |
4972 | case 0: | |
4973 | status_str = "responding"; | |
4974 | break; | |
4975 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | |
4976 | status_str = "remove delay"; | |
4977 | break; | |
4978 | default: | |
4979 | status_str = "unknown status"; | |
4980 | break; | |
4981 | } | |
4982 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", | |
4983 | ioc->name, status_str); | |
4984 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ | |
4985 | "start_phy(%02d), count(%d)\n", | |
4986 | le16_to_cpu(event_data->ExpanderDevHandle), | |
4987 | le16_to_cpu(event_data->EnclosureHandle), | |
4988 | event_data->StartPhyNum, event_data->NumEntries); | |
4989 | for (i = 0; i < event_data->NumEntries; i++) { | |
4990 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
4991 | if (!handle) | |
4992 | continue; | |
4993 | phy_number = event_data->StartPhyNum + i; | |
4994 | reason_code = event_data->PHY[i].PhyStatus & | |
4995 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
4996 | switch (reason_code) { | |
4997 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
4998 | status_str = "target add"; | |
4999 | break; | |
5000 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
5001 | status_str = "target remove"; | |
5002 | break; | |
5003 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | |
5004 | status_str = "delay target remove"; | |
5005 | break; | |
5006 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
5007 | status_str = "link rate change"; | |
5008 | break; | |
5009 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | |
5010 | status_str = "target responding"; | |
5011 | break; | |
5012 | default: | |
5013 | status_str = "unknown"; | |
5014 | break; | |
5015 | } | |
5016 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
5017 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
5018 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ | |
5019 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | |
5020 | handle, status_str, link_rate, prev_link_rate); | |
5021 | ||
5022 | } | |
5023 | } | |
5024 | #endif | |
5025 | ||
5026 | /** | |
5027 | * _scsih_sas_topology_change_event - handle topology changes | |
5028 | * @ioc: per adapter object | |
5029 | * @fw_event: The fw_event_work object | |
5030 | * Context: user. | |
5031 | * | |
5032 | */ | |
5033 | static int | |
5034 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, | |
5035 | struct fw_event_work *fw_event) | |
5036 | { | |
5037 | int i; | |
5038 | u16 parent_handle, handle; | |
5039 | u16 reason_code; | |
5040 | u8 phy_number, max_phys; | |
5041 | struct _sas_node *sas_expander; | |
5042 | u64 sas_address; | |
5043 | unsigned long flags; | |
5044 | u8 link_rate, prev_link_rate; | |
35b62362 JL |
5045 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
5046 | (Mpi2EventDataSasTopologyChangeList_t *) | |
5047 | fw_event->event_data; | |
f92363d1 SR |
5048 | |
5049 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5050 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
5051 | _scsih_sas_topology_change_event_debug(ioc, event_data); | |
5052 | #endif | |
5053 | ||
5054 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) | |
5055 | return 0; | |
5056 | ||
5057 | if (!ioc->sas_hba.num_phys) | |
5058 | _scsih_sas_host_add(ioc); | |
5059 | else | |
5060 | _scsih_sas_host_refresh(ioc); | |
5061 | ||
5062 | if (fw_event->ignore) { | |
5063 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5064 | "ignoring expander event\n", ioc->name)); | |
5065 | return 0; | |
5066 | } | |
5067 | ||
5068 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | |
5069 | ||
5070 | /* handle expander add */ | |
5071 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | |
5072 | if (_scsih_expander_add(ioc, parent_handle) != 0) | |
5073 | return 0; | |
5074 | ||
5075 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
5076 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, | |
5077 | parent_handle); | |
5078 | if (sas_expander) { | |
5079 | sas_address = sas_expander->sas_address; | |
5080 | max_phys = sas_expander->num_phys; | |
5081 | } else if (parent_handle < ioc->sas_hba.num_phys) { | |
5082 | sas_address = ioc->sas_hba.sas_address; | |
5083 | max_phys = ioc->sas_hba.num_phys; | |
5084 | } else { | |
5085 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5086 | return 0; | |
5087 | } | |
5088 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
5089 | ||
5090 | /* handle siblings events */ | |
5091 | for (i = 0; i < event_data->NumEntries; i++) { | |
5092 | if (fw_event->ignore) { | |
5093 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5094 | "ignoring expander event\n", ioc->name)); | |
5095 | return 0; | |
5096 | } | |
5097 | if (ioc->remove_host || ioc->pci_error_recovery) | |
5098 | return 0; | |
5099 | phy_number = event_data->StartPhyNum + i; | |
5100 | if (phy_number >= max_phys) | |
5101 | continue; | |
5102 | reason_code = event_data->PHY[i].PhyStatus & | |
5103 | MPI2_EVENT_SAS_TOPO_RC_MASK; | |
5104 | if ((event_data->PHY[i].PhyStatus & | |
5105 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | |
5106 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | |
5107 | continue; | |
5108 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | |
5109 | if (!handle) | |
5110 | continue; | |
5111 | link_rate = event_data->PHY[i].LinkRate >> 4; | |
5112 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | |
5113 | switch (reason_code) { | |
5114 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | |
5115 | ||
5116 | if (ioc->shost_recovery) | |
5117 | break; | |
5118 | ||
5119 | if (link_rate == prev_link_rate) | |
5120 | break; | |
5121 | ||
5122 | mpt3sas_transport_update_links(ioc, sas_address, | |
5123 | handle, phy_number, link_rate); | |
5124 | ||
5125 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | |
5126 | break; | |
5127 | ||
5128 | _scsih_check_device(ioc, sas_address, handle, | |
5129 | phy_number, link_rate); | |
5130 | ||
5131 | ||
5132 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | |
5133 | ||
5134 | if (ioc->shost_recovery) | |
5135 | break; | |
5136 | ||
5137 | mpt3sas_transport_update_links(ioc, sas_address, | |
5138 | handle, phy_number, link_rate); | |
5139 | ||
5140 | _scsih_add_device(ioc, handle, phy_number, 0); | |
5141 | ||
5142 | break; | |
5143 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | |
5144 | ||
5145 | _scsih_device_remove_by_handle(ioc, handle); | |
5146 | break; | |
5147 | } | |
5148 | } | |
5149 | ||
5150 | /* handle expander removal */ | |
5151 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | |
5152 | sas_expander) | |
5153 | mpt3sas_expander_remove(ioc, sas_address); | |
5154 | ||
5155 | return 0; | |
5156 | } | |
5157 | ||
5158 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5159 | /** | |
5160 | * _scsih_sas_device_status_change_event_debug - debug for device event | |
5161 | * @event_data: event data payload | |
5162 | * Context: user. | |
5163 | * | |
5164 | * Return nothing. | |
5165 | */ | |
5166 | static void | |
5167 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
5168 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | |
5169 | { | |
5170 | char *reason_str = NULL; | |
5171 | ||
5172 | switch (event_data->ReasonCode) { | |
5173 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | |
5174 | reason_str = "smart data"; | |
5175 | break; | |
5176 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | |
5177 | reason_str = "unsupported device discovered"; | |
5178 | break; | |
5179 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | |
5180 | reason_str = "internal device reset"; | |
5181 | break; | |
5182 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | |
5183 | reason_str = "internal task abort"; | |
5184 | break; | |
5185 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | |
5186 | reason_str = "internal task abort set"; | |
5187 | break; | |
5188 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | |
5189 | reason_str = "internal clear task set"; | |
5190 | break; | |
5191 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | |
5192 | reason_str = "internal query task"; | |
5193 | break; | |
5194 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | |
5195 | reason_str = "sata init failure"; | |
5196 | break; | |
5197 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | |
5198 | reason_str = "internal device reset complete"; | |
5199 | break; | |
5200 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | |
5201 | reason_str = "internal task abort complete"; | |
5202 | break; | |
5203 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | |
5204 | reason_str = "internal async notification"; | |
5205 | break; | |
5206 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | |
5207 | reason_str = "expander reduced functionality"; | |
5208 | break; | |
5209 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | |
5210 | reason_str = "expander reduced functionality complete"; | |
5211 | break; | |
5212 | default: | |
5213 | reason_str = "unknown reason"; | |
5214 | break; | |
5215 | } | |
5216 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" | |
5217 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | |
5218 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | |
5219 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | |
5220 | le16_to_cpu(event_data->TaskTag)); | |
5221 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | |
5222 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | |
5223 | event_data->ASC, event_data->ASCQ); | |
5224 | pr_info("\n"); | |
5225 | } | |
5226 | #endif | |
5227 | ||
5228 | /** | |
5229 | * _scsih_sas_device_status_change_event - handle device status change | |
5230 | * @ioc: per adapter object | |
5231 | * @fw_event: The fw_event_work object | |
5232 | * Context: user. | |
5233 | * | |
5234 | * Return nothing. | |
5235 | */ | |
5236 | static void | |
5237 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
5238 | struct fw_event_work *fw_event) | |
5239 | { | |
5240 | struct MPT3SAS_TARGET *target_priv_data; | |
5241 | struct _sas_device *sas_device; | |
5242 | u64 sas_address; | |
5243 | unsigned long flags; | |
5244 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | |
35b62362 JL |
5245 | (Mpi2EventDataSasDeviceStatusChange_t *) |
5246 | fw_event->event_data; | |
f92363d1 SR |
5247 | |
5248 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5249 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
5250 | _scsih_sas_device_status_change_event_debug(ioc, | |
5251 | event_data); | |
5252 | #endif | |
5253 | ||
5254 | /* In MPI Revision K (0xC), the internal device reset complete was | |
5255 | * implemented, so avoid setting tm_busy flag for older firmware. | |
5256 | */ | |
5257 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | |
5258 | return; | |
5259 | ||
5260 | if (event_data->ReasonCode != | |
5261 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | |
5262 | event_data->ReasonCode != | |
5263 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | |
5264 | return; | |
5265 | ||
5266 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5267 | sas_address = le64_to_cpu(event_data->SASAddress); | |
5268 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
5269 | sas_address); | |
5270 | ||
5271 | if (!sas_device || !sas_device->starget) { | |
5272 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5273 | return; | |
5274 | } | |
5275 | ||
5276 | target_priv_data = sas_device->starget->hostdata; | |
5277 | if (!target_priv_data) { | |
5278 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5279 | return; | |
5280 | } | |
5281 | ||
5282 | if (event_data->ReasonCode == | |
5283 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | |
5284 | target_priv_data->tm_busy = 1; | |
5285 | else | |
5286 | target_priv_data->tm_busy = 0; | |
5287 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5288 | } | |
5289 | ||
5290 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5291 | /** | |
5292 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure | |
5293 | * event | |
5294 | * @ioc: per adapter object | |
5295 | * @event_data: event data payload | |
5296 | * Context: user. | |
5297 | * | |
5298 | * Return nothing. | |
5299 | */ | |
5300 | static void | |
5301 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
5302 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | |
5303 | { | |
5304 | char *reason_str = NULL; | |
5305 | ||
5306 | switch (event_data->ReasonCode) { | |
5307 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | |
5308 | reason_str = "enclosure add"; | |
5309 | break; | |
5310 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | |
5311 | reason_str = "enclosure remove"; | |
5312 | break; | |
5313 | default: | |
5314 | reason_str = "unknown reason"; | |
5315 | break; | |
5316 | } | |
5317 | ||
5318 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" | |
5319 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | |
5320 | " number slots(%d)\n", ioc->name, reason_str, | |
5321 | le16_to_cpu(event_data->EnclosureHandle), | |
5322 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | |
5323 | le16_to_cpu(event_data->StartSlot)); | |
5324 | } | |
5325 | #endif | |
5326 | ||
5327 | /** | |
5328 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | |
5329 | * @ioc: per adapter object | |
5330 | * @fw_event: The fw_event_work object | |
5331 | * Context: user. | |
5332 | * | |
5333 | * Return nothing. | |
5334 | */ | |
5335 | static void | |
5336 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, | |
5337 | struct fw_event_work *fw_event) | |
5338 | { | |
5339 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5340 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
5341 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | |
35b62362 | 5342 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
f92363d1 SR |
5343 | fw_event->event_data); |
5344 | #endif | |
5345 | } | |
5346 | ||
5347 | /** | |
5348 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | |
5349 | * @ioc: per adapter object | |
5350 | * @fw_event: The fw_event_work object | |
5351 | * Context: user. | |
5352 | * | |
5353 | * Return nothing. | |
5354 | */ | |
5355 | static void | |
5356 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, | |
5357 | struct fw_event_work *fw_event) | |
5358 | { | |
5359 | struct scsi_cmnd *scmd; | |
5360 | struct scsi_device *sdev; | |
5361 | u16 smid, handle; | |
5362 | u32 lun; | |
5363 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
5364 | u32 termination_count; | |
5365 | u32 query_count; | |
5366 | Mpi2SCSITaskManagementReply_t *mpi_reply; | |
35b62362 JL |
5367 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
5368 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
5369 | fw_event->event_data; | |
f92363d1 SR |
5370 | u16 ioc_status; |
5371 | unsigned long flags; | |
5372 | int r; | |
5373 | u8 max_retries = 0; | |
5374 | u8 task_abort_retries; | |
5375 | ||
5376 | mutex_lock(&ioc->tm_cmds.mutex); | |
5377 | pr_info(MPT3SAS_FMT | |
5378 | "%s: enter: phy number(%d), width(%d)\n", | |
5379 | ioc->name, __func__, event_data->PhyNum, | |
5380 | event_data->PortWidth); | |
5381 | ||
5382 | _scsih_block_io_all_device(ioc); | |
5383 | ||
5384 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5385 | mpi_reply = ioc->tm_cmds.reply; | |
5386 | broadcast_aen_retry: | |
5387 | ||
5388 | /* sanity checks for retrying this loop */ | |
5389 | if (max_retries++ == 5) { | |
5390 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", | |
5391 | ioc->name, __func__)); | |
5392 | goto out; | |
5393 | } else if (max_retries > 1) | |
5394 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", | |
5395 | ioc->name, __func__, max_retries - 1)); | |
5396 | ||
5397 | termination_count = 0; | |
5398 | query_count = 0; | |
5399 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | |
5400 | if (ioc->shost_recovery) | |
5401 | goto out; | |
5402 | scmd = _scsih_scsi_lookup_get(ioc, smid); | |
5403 | if (!scmd) | |
5404 | continue; | |
5405 | sdev = scmd->device; | |
5406 | sas_device_priv_data = sdev->hostdata; | |
5407 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | |
5408 | continue; | |
5409 | /* skip hidden raid components */ | |
5410 | if (sas_device_priv_data->sas_target->flags & | |
5411 | MPT_TARGET_FLAGS_RAID_COMPONENT) | |
5412 | continue; | |
5413 | /* skip volumes */ | |
5414 | if (sas_device_priv_data->sas_target->flags & | |
5415 | MPT_TARGET_FLAGS_VOLUME) | |
5416 | continue; | |
5417 | ||
5418 | handle = sas_device_priv_data->sas_target->handle; | |
5419 | lun = sas_device_priv_data->lun; | |
5420 | query_count++; | |
5421 | ||
5422 | if (ioc->shost_recovery) | |
5423 | goto out; | |
5424 | ||
5425 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
5426 | r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun, | |
c62e46de | 5427 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, |
f92363d1 SR |
5428 | TM_MUTEX_OFF); |
5429 | if (r == FAILED) { | |
5430 | sdev_printk(KERN_WARNING, sdev, | |
5431 | "mpt3sas_scsih_issue_tm: FAILED when sending " | |
5432 | "QUERY_TASK: scmd(%p)\n", scmd); | |
5433 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5434 | goto broadcast_aen_retry; | |
5435 | } | |
5436 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | |
5437 | & MPI2_IOCSTATUS_MASK; | |
5438 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5439 | sdev_printk(KERN_WARNING, sdev, | |
5440 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", | |
5441 | ioc_status, scmd); | |
5442 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5443 | goto broadcast_aen_retry; | |
5444 | } | |
5445 | ||
5446 | /* see if IO is still owned by IOC and target */ | |
5447 | if (mpi_reply->ResponseCode == | |
5448 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | |
5449 | mpi_reply->ResponseCode == | |
5450 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | |
5451 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5452 | continue; | |
5453 | } | |
5454 | task_abort_retries = 0; | |
5455 | tm_retry: | |
5456 | if (task_abort_retries++ == 60) { | |
5457 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5458 | "%s: ABORT_TASK: giving up\n", ioc->name, | |
5459 | __func__)); | |
5460 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5461 | goto broadcast_aen_retry; | |
5462 | } | |
5463 | ||
5464 | if (ioc->shost_recovery) | |
5465 | goto out_no_lock; | |
5466 | ||
5467 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, | |
5468 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, | |
c62e46de | 5469 | TM_MUTEX_OFF); |
f92363d1 SR |
5470 | if (r == FAILED) { |
5471 | sdev_printk(KERN_WARNING, sdev, | |
5472 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " | |
5473 | "scmd(%p)\n", scmd); | |
5474 | goto tm_retry; | |
5475 | } | |
5476 | ||
5477 | if (task_abort_retries > 1) | |
5478 | sdev_printk(KERN_WARNING, sdev, | |
5479 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | |
5480 | " scmd(%p)\n", | |
5481 | task_abort_retries - 1, scmd); | |
5482 | ||
5483 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | |
5484 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | |
5485 | } | |
5486 | ||
5487 | if (ioc->broadcast_aen_pending) { | |
5488 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5489 | "%s: loop back due to pending AEN\n", | |
5490 | ioc->name, __func__)); | |
5491 | ioc->broadcast_aen_pending = 0; | |
5492 | goto broadcast_aen_retry; | |
5493 | } | |
5494 | ||
5495 | out: | |
5496 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | |
5497 | out_no_lock: | |
5498 | ||
5499 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5500 | "%s - exit, query_count = %d termination_count = %d\n", | |
5501 | ioc->name, __func__, query_count, termination_count)); | |
5502 | ||
5503 | ioc->broadcast_aen_busy = 0; | |
5504 | if (!ioc->shost_recovery) | |
5505 | _scsih_ublock_io_all_device(ioc); | |
5506 | mutex_unlock(&ioc->tm_cmds.mutex); | |
5507 | } | |
5508 | ||
5509 | /** | |
5510 | * _scsih_sas_discovery_event - handle discovery events | |
5511 | * @ioc: per adapter object | |
5512 | * @fw_event: The fw_event_work object | |
5513 | * Context: user. | |
5514 | * | |
5515 | * Return nothing. | |
5516 | */ | |
5517 | static void | |
5518 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, | |
5519 | struct fw_event_work *fw_event) | |
5520 | { | |
35b62362 JL |
5521 | Mpi2EventDataSasDiscovery_t *event_data = |
5522 | (Mpi2EventDataSasDiscovery_t *) fw_event->event_data; | |
f92363d1 SR |
5523 | |
5524 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5525 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { | |
5526 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, | |
5527 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | |
5528 | "start" : "stop"); | |
5529 | if (event_data->DiscoveryStatus) | |
5530 | pr_info("discovery_status(0x%08x)", | |
5531 | le32_to_cpu(event_data->DiscoveryStatus)); | |
5532 | pr_info("\n"); | |
5533 | } | |
5534 | #endif | |
5535 | ||
5536 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | |
5537 | !ioc->sas_hba.num_phys) { | |
5538 | if (disable_discovery > 0 && ioc->shost_recovery) { | |
5539 | /* Wait for the reset to complete */ | |
5540 | while (ioc->shost_recovery) | |
5541 | ssleep(1); | |
5542 | } | |
5543 | _scsih_sas_host_add(ioc); | |
5544 | } | |
5545 | } | |
5546 | ||
5547 | /** | |
5548 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk | |
5549 | * @ioc: per adapter object | |
5550 | * @handle: device handle for physical disk | |
5551 | * @phys_disk_num: physical disk number | |
5552 | * | |
5553 | * Return 0 for success, else failure. | |
5554 | */ | |
5555 | static int | |
5556 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) | |
5557 | { | |
5558 | Mpi2RaidActionRequest_t *mpi_request; | |
5559 | Mpi2RaidActionReply_t *mpi_reply; | |
5560 | u16 smid; | |
5561 | u8 issue_reset = 0; | |
5562 | int rc = 0; | |
5563 | u16 ioc_status; | |
5564 | u32 log_info; | |
5565 | ||
5566 | ||
5567 | mutex_lock(&ioc->scsih_cmds.mutex); | |
5568 | ||
5569 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
5570 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
5571 | ioc->name, __func__); | |
5572 | rc = -EAGAIN; | |
5573 | goto out; | |
5574 | } | |
5575 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
5576 | ||
5577 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
5578 | if (!smid) { | |
5579 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
5580 | ioc->name, __func__); | |
5581 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
5582 | rc = -EAGAIN; | |
5583 | goto out; | |
5584 | } | |
5585 | ||
5586 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
5587 | ioc->scsih_cmds.smid = smid; | |
5588 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
5589 | ||
5590 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
5591 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; | |
5592 | mpi_request->PhysDiskNum = phys_disk_num; | |
5593 | ||
5594 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ | |
5595 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, | |
5596 | handle, phys_disk_num)); | |
5597 | ||
5598 | init_completion(&ioc->scsih_cmds.done); | |
5599 | mpt3sas_base_put_smid_default(ioc, smid); | |
5600 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); | |
5601 | ||
5602 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
5603 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
5604 | ioc->name, __func__); | |
5605 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) | |
5606 | issue_reset = 1; | |
5607 | rc = -EFAULT; | |
5608 | goto out; | |
5609 | } | |
5610 | ||
5611 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
5612 | ||
5613 | mpi_reply = ioc->scsih_cmds.reply; | |
5614 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | |
5615 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | |
5616 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | |
5617 | else | |
5618 | log_info = 0; | |
5619 | ioc_status &= MPI2_IOCSTATUS_MASK; | |
5620 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5621 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5622 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " | |
5623 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, | |
5624 | log_info)); | |
5625 | rc = -EFAULT; | |
5626 | } else | |
5627 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
5628 | "IR RAID_ACTION: completed successfully\n", | |
5629 | ioc->name)); | |
5630 | } | |
5631 | ||
5632 | out: | |
5633 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
5634 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
5635 | ||
5636 | if (issue_reset) | |
5637 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
5638 | FORCE_BIG_HAMMER); | |
5639 | return rc; | |
5640 | } | |
5641 | ||
5642 | /** | |
5643 | * _scsih_reprobe_lun - reprobing lun | |
5644 | * @sdev: scsi device struct | |
5645 | * @no_uld_attach: sdev->no_uld_attach flag setting | |
5646 | * | |
5647 | **/ | |
5648 | static void | |
5649 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | |
5650 | { | |
5651 | int rc; | |
5652 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; | |
5653 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | |
5654 | sdev->no_uld_attach ? "hidding" : "exposing"); | |
5655 | rc = scsi_device_reprobe(sdev); | |
5656 | } | |
5657 | ||
5658 | /** | |
5659 | * _scsih_sas_volume_add - add new volume | |
5660 | * @ioc: per adapter object | |
5661 | * @element: IR config element data | |
5662 | * Context: user. | |
5663 | * | |
5664 | * Return nothing. | |
5665 | */ | |
5666 | static void | |
5667 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, | |
5668 | Mpi2EventIrConfigElement_t *element) | |
5669 | { | |
5670 | struct _raid_device *raid_device; | |
5671 | unsigned long flags; | |
5672 | u64 wwid; | |
5673 | u16 handle = le16_to_cpu(element->VolDevHandle); | |
5674 | int rc; | |
5675 | ||
5676 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
5677 | if (!wwid) { | |
5678 | pr_err(MPT3SAS_FMT | |
5679 | "failure at %s:%d/%s()!\n", ioc->name, | |
5680 | __FILE__, __LINE__, __func__); | |
5681 | return; | |
5682 | } | |
5683 | ||
5684 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
5685 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | |
5686 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
5687 | ||
5688 | if (raid_device) | |
5689 | return; | |
5690 | ||
5691 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
5692 | if (!raid_device) { | |
5693 | pr_err(MPT3SAS_FMT | |
5694 | "failure at %s:%d/%s()!\n", ioc->name, | |
5695 | __FILE__, __LINE__, __func__); | |
5696 | return; | |
5697 | } | |
5698 | ||
5699 | raid_device->id = ioc->sas_id++; | |
5700 | raid_device->channel = RAID_CHANNEL; | |
5701 | raid_device->handle = handle; | |
5702 | raid_device->wwid = wwid; | |
5703 | _scsih_raid_device_add(ioc, raid_device); | |
5704 | if (!ioc->wait_for_discovery_to_complete) { | |
5705 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
5706 | raid_device->id, 0); | |
5707 | if (rc) | |
5708 | _scsih_raid_device_remove(ioc, raid_device); | |
5709 | } else { | |
5710 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
5711 | _scsih_determine_boot_device(ioc, raid_device, 1); | |
5712 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
5713 | } | |
5714 | } | |
5715 | ||
5716 | /** | |
5717 | * _scsih_sas_volume_delete - delete volume | |
5718 | * @ioc: per adapter object | |
5719 | * @handle: volume device handle | |
5720 | * Context: user. | |
5721 | * | |
5722 | * Return nothing. | |
5723 | */ | |
5724 | static void | |
5725 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) | |
5726 | { | |
5727 | struct _raid_device *raid_device; | |
5728 | unsigned long flags; | |
5729 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5730 | struct scsi_target *starget = NULL; | |
5731 | ||
5732 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
5733 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
5734 | if (raid_device) { | |
5735 | if (raid_device->starget) { | |
5736 | starget = raid_device->starget; | |
5737 | sas_target_priv_data = starget->hostdata; | |
5738 | sas_target_priv_data->deleted = 1; | |
5739 | } | |
5740 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
5741 | ioc->name, raid_device->handle, | |
5742 | (unsigned long long) raid_device->wwid); | |
5743 | list_del(&raid_device->list); | |
5744 | kfree(raid_device); | |
5745 | } | |
5746 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
5747 | if (starget) | |
5748 | scsi_remove_target(&starget->dev); | |
5749 | } | |
5750 | ||
5751 | /** | |
5752 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | |
5753 | * @ioc: per adapter object | |
5754 | * @element: IR config element data | |
5755 | * Context: user. | |
5756 | * | |
5757 | * Return nothing. | |
5758 | */ | |
5759 | static void | |
5760 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, | |
5761 | Mpi2EventIrConfigElement_t *element) | |
5762 | { | |
5763 | struct _sas_device *sas_device; | |
5764 | struct scsi_target *starget = NULL; | |
5765 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5766 | unsigned long flags; | |
5767 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
5768 | ||
5769 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5770 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
5771 | if (sas_device) { | |
5772 | sas_device->volume_handle = 0; | |
5773 | sas_device->volume_wwid = 0; | |
5774 | clear_bit(handle, ioc->pd_handles); | |
5775 | if (sas_device->starget && sas_device->starget->hostdata) { | |
5776 | starget = sas_device->starget; | |
5777 | sas_target_priv_data = starget->hostdata; | |
5778 | sas_target_priv_data->flags &= | |
5779 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | |
5780 | } | |
5781 | } | |
5782 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5783 | if (!sas_device) | |
5784 | return; | |
5785 | ||
5786 | /* exposing raid component */ | |
5787 | if (starget) | |
5788 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | |
5789 | } | |
5790 | ||
5791 | /** | |
5792 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | |
5793 | * @ioc: per adapter object | |
5794 | * @element: IR config element data | |
5795 | * Context: user. | |
5796 | * | |
5797 | * Return nothing. | |
5798 | */ | |
5799 | static void | |
5800 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, | |
5801 | Mpi2EventIrConfigElement_t *element) | |
5802 | { | |
5803 | struct _sas_device *sas_device; | |
5804 | struct scsi_target *starget = NULL; | |
5805 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
5806 | unsigned long flags; | |
5807 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
5808 | u16 volume_handle = 0; | |
5809 | u64 volume_wwid = 0; | |
5810 | ||
5811 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); | |
5812 | if (volume_handle) | |
5813 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, | |
5814 | &volume_wwid); | |
5815 | ||
5816 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5817 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
5818 | if (sas_device) { | |
5819 | set_bit(handle, ioc->pd_handles); | |
5820 | if (sas_device->starget && sas_device->starget->hostdata) { | |
5821 | starget = sas_device->starget; | |
5822 | sas_target_priv_data = starget->hostdata; | |
5823 | sas_target_priv_data->flags |= | |
5824 | MPT_TARGET_FLAGS_RAID_COMPONENT; | |
5825 | sas_device->volume_handle = volume_handle; | |
5826 | sas_device->volume_wwid = volume_wwid; | |
5827 | } | |
5828 | } | |
5829 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5830 | if (!sas_device) | |
5831 | return; | |
5832 | ||
5833 | /* hiding raid component */ | |
5834 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
5835 | if (starget) | |
5836 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | |
5837 | } | |
5838 | ||
5839 | /** | |
5840 | * _scsih_sas_pd_delete - delete pd component | |
5841 | * @ioc: per adapter object | |
5842 | * @element: IR config element data | |
5843 | * Context: user. | |
5844 | * | |
5845 | * Return nothing. | |
5846 | */ | |
5847 | static void | |
5848 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, | |
5849 | Mpi2EventIrConfigElement_t *element) | |
5850 | { | |
5851 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
5852 | ||
5853 | _scsih_device_remove_by_handle(ioc, handle); | |
5854 | } | |
5855 | ||
5856 | /** | |
5857 | * _scsih_sas_pd_add - remove pd component | |
5858 | * @ioc: per adapter object | |
5859 | * @element: IR config element data | |
5860 | * Context: user. | |
5861 | * | |
5862 | * Return nothing. | |
5863 | */ | |
5864 | static void | |
5865 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, | |
5866 | Mpi2EventIrConfigElement_t *element) | |
5867 | { | |
5868 | struct _sas_device *sas_device; | |
5869 | unsigned long flags; | |
5870 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | |
5871 | Mpi2ConfigReply_t mpi_reply; | |
5872 | Mpi2SasDevicePage0_t sas_device_pg0; | |
5873 | u32 ioc_status; | |
5874 | u64 sas_address; | |
5875 | u16 parent_handle; | |
5876 | ||
5877 | set_bit(handle, ioc->pd_handles); | |
5878 | ||
5879 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
5880 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
5881 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
5882 | if (sas_device) { | |
5883 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
5884 | return; | |
5885 | } | |
5886 | ||
5887 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | |
5888 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | |
5889 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5890 | ioc->name, __FILE__, __LINE__, __func__); | |
5891 | return; | |
5892 | } | |
5893 | ||
5894 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
5895 | MPI2_IOCSTATUS_MASK; | |
5896 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
5897 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
5898 | ioc->name, __FILE__, __LINE__, __func__); | |
5899 | return; | |
5900 | } | |
5901 | ||
5902 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
5903 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
5904 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
5905 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
5906 | ||
5907 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); | |
5908 | _scsih_add_device(ioc, handle, 0, 1); | |
5909 | } | |
5910 | ||
5911 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
5912 | /** | |
5913 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | |
5914 | * @ioc: per adapter object | |
5915 | * @event_data: event data payload | |
5916 | * Context: user. | |
5917 | * | |
5918 | * Return nothing. | |
5919 | */ | |
5920 | static void | |
5921 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
5922 | Mpi2EventDataIrConfigChangeList_t *event_data) | |
5923 | { | |
5924 | Mpi2EventIrConfigElement_t *element; | |
5925 | u8 element_type; | |
5926 | int i; | |
5927 | char *reason_str = NULL, *element_str = NULL; | |
5928 | ||
5929 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
5930 | ||
5931 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", | |
5932 | ioc->name, (le32_to_cpu(event_data->Flags) & | |
5933 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | |
5934 | "foreign" : "native", event_data->NumElements); | |
5935 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
5936 | switch (element->ReasonCode) { | |
5937 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
5938 | reason_str = "add"; | |
5939 | break; | |
5940 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
5941 | reason_str = "remove"; | |
5942 | break; | |
5943 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | |
5944 | reason_str = "no change"; | |
5945 | break; | |
5946 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
5947 | reason_str = "hide"; | |
5948 | break; | |
5949 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
5950 | reason_str = "unhide"; | |
5951 | break; | |
5952 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
5953 | reason_str = "volume_created"; | |
5954 | break; | |
5955 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
5956 | reason_str = "volume_deleted"; | |
5957 | break; | |
5958 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
5959 | reason_str = "pd_created"; | |
5960 | break; | |
5961 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
5962 | reason_str = "pd_deleted"; | |
5963 | break; | |
5964 | default: | |
5965 | reason_str = "unknown reason"; | |
5966 | break; | |
5967 | } | |
5968 | element_type = le16_to_cpu(element->ElementFlags) & | |
5969 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | |
5970 | switch (element_type) { | |
5971 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | |
5972 | element_str = "volume"; | |
5973 | break; | |
5974 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | |
5975 | element_str = "phys disk"; | |
5976 | break; | |
5977 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | |
5978 | element_str = "hot spare"; | |
5979 | break; | |
5980 | default: | |
5981 | element_str = "unknown element"; | |
5982 | break; | |
5983 | } | |
5984 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ | |
5985 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | |
5986 | reason_str, le16_to_cpu(element->VolDevHandle), | |
5987 | le16_to_cpu(element->PhysDiskDevHandle), | |
5988 | element->PhysDiskNum); | |
5989 | } | |
5990 | } | |
5991 | #endif | |
5992 | ||
5993 | /** | |
5994 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | |
5995 | * @ioc: per adapter object | |
5996 | * @fw_event: The fw_event_work object | |
5997 | * Context: user. | |
5998 | * | |
5999 | * Return nothing. | |
6000 | */ | |
6001 | static void | |
6002 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, | |
6003 | struct fw_event_work *fw_event) | |
6004 | { | |
6005 | Mpi2EventIrConfigElement_t *element; | |
6006 | int i; | |
6007 | u8 foreign_config; | |
35b62362 JL |
6008 | Mpi2EventDataIrConfigChangeList_t *event_data = |
6009 | (Mpi2EventDataIrConfigChangeList_t *) | |
6010 | fw_event->event_data; | |
f92363d1 SR |
6011 | |
6012 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
6013 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
6014 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); | |
6015 | ||
6016 | #endif | |
6017 | ||
6018 | foreign_config = (le32_to_cpu(event_data->Flags) & | |
6019 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | |
6020 | ||
6021 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | |
6022 | if (ioc->shost_recovery) { | |
6023 | ||
6024 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
6025 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) | |
6026 | _scsih_ir_fastpath(ioc, | |
6027 | le16_to_cpu(element->PhysDiskDevHandle), | |
6028 | element->PhysDiskNum); | |
6029 | } | |
6030 | return; | |
6031 | } | |
6032 | for (i = 0; i < event_data->NumElements; i++, element++) { | |
6033 | ||
6034 | switch (element->ReasonCode) { | |
6035 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | |
6036 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | |
6037 | if (!foreign_config) | |
6038 | _scsih_sas_volume_add(ioc, element); | |
6039 | break; | |
6040 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | |
6041 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | |
6042 | if (!foreign_config) | |
6043 | _scsih_sas_volume_delete(ioc, | |
6044 | le16_to_cpu(element->VolDevHandle)); | |
6045 | break; | |
6046 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | |
6047 | _scsih_sas_pd_hide(ioc, element); | |
6048 | break; | |
6049 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | |
6050 | _scsih_sas_pd_expose(ioc, element); | |
6051 | break; | |
6052 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | |
6053 | _scsih_sas_pd_add(ioc, element); | |
6054 | break; | |
6055 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | |
6056 | _scsih_sas_pd_delete(ioc, element); | |
6057 | break; | |
6058 | } | |
6059 | } | |
6060 | } | |
6061 | ||
6062 | /** | |
6063 | * _scsih_sas_ir_volume_event - IR volume event | |
6064 | * @ioc: per adapter object | |
6065 | * @fw_event: The fw_event_work object | |
6066 | * Context: user. | |
6067 | * | |
6068 | * Return nothing. | |
6069 | */ | |
6070 | static void | |
6071 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, | |
6072 | struct fw_event_work *fw_event) | |
6073 | { | |
6074 | u64 wwid; | |
6075 | unsigned long flags; | |
6076 | struct _raid_device *raid_device; | |
6077 | u16 handle; | |
6078 | u32 state; | |
6079 | int rc; | |
35b62362 JL |
6080 | Mpi2EventDataIrVolume_t *event_data = |
6081 | (Mpi2EventDataIrVolume_t *) fw_event->event_data; | |
f92363d1 SR |
6082 | |
6083 | if (ioc->shost_recovery) | |
6084 | return; | |
6085 | ||
6086 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | |
6087 | return; | |
6088 | ||
6089 | handle = le16_to_cpu(event_data->VolDevHandle); | |
6090 | state = le32_to_cpu(event_data->NewValue); | |
6091 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6092 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
6093 | ioc->name, __func__, handle, | |
6094 | le32_to_cpu(event_data->PreviousValue), state)); | |
6095 | switch (state) { | |
6096 | case MPI2_RAID_VOL_STATE_MISSING: | |
6097 | case MPI2_RAID_VOL_STATE_FAILED: | |
6098 | _scsih_sas_volume_delete(ioc, handle); | |
6099 | break; | |
6100 | ||
6101 | case MPI2_RAID_VOL_STATE_ONLINE: | |
6102 | case MPI2_RAID_VOL_STATE_DEGRADED: | |
6103 | case MPI2_RAID_VOL_STATE_OPTIMAL: | |
6104 | ||
6105 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6106 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
6107 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6108 | ||
6109 | if (raid_device) | |
6110 | break; | |
6111 | ||
6112 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); | |
6113 | if (!wwid) { | |
6114 | pr_err(MPT3SAS_FMT | |
6115 | "failure at %s:%d/%s()!\n", ioc->name, | |
6116 | __FILE__, __LINE__, __func__); | |
6117 | break; | |
6118 | } | |
6119 | ||
6120 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | |
6121 | if (!raid_device) { | |
6122 | pr_err(MPT3SAS_FMT | |
6123 | "failure at %s:%d/%s()!\n", ioc->name, | |
6124 | __FILE__, __LINE__, __func__); | |
6125 | break; | |
6126 | } | |
6127 | ||
6128 | raid_device->id = ioc->sas_id++; | |
6129 | raid_device->channel = RAID_CHANNEL; | |
6130 | raid_device->handle = handle; | |
6131 | raid_device->wwid = wwid; | |
6132 | _scsih_raid_device_add(ioc, raid_device); | |
6133 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
6134 | raid_device->id, 0); | |
6135 | if (rc) | |
6136 | _scsih_raid_device_remove(ioc, raid_device); | |
6137 | break; | |
6138 | ||
6139 | case MPI2_RAID_VOL_STATE_INITIALIZING: | |
6140 | default: | |
6141 | break; | |
6142 | } | |
6143 | } | |
6144 | ||
6145 | /** | |
6146 | * _scsih_sas_ir_physical_disk_event - PD event | |
6147 | * @ioc: per adapter object | |
6148 | * @fw_event: The fw_event_work object | |
6149 | * Context: user. | |
6150 | * | |
6151 | * Return nothing. | |
6152 | */ | |
6153 | static void | |
6154 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, | |
6155 | struct fw_event_work *fw_event) | |
6156 | { | |
6157 | u16 handle, parent_handle; | |
6158 | u32 state; | |
6159 | struct _sas_device *sas_device; | |
6160 | unsigned long flags; | |
6161 | Mpi2ConfigReply_t mpi_reply; | |
6162 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6163 | u32 ioc_status; | |
35b62362 JL |
6164 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
6165 | (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data; | |
f92363d1 SR |
6166 | u64 sas_address; |
6167 | ||
6168 | if (ioc->shost_recovery) | |
6169 | return; | |
6170 | ||
6171 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | |
6172 | return; | |
6173 | ||
6174 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | |
6175 | state = le32_to_cpu(event_data->NewValue); | |
6176 | ||
6177 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
6178 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", | |
6179 | ioc->name, __func__, handle, | |
6180 | le32_to_cpu(event_data->PreviousValue), state)); | |
6181 | switch (state) { | |
6182 | case MPI2_RAID_PD_STATE_ONLINE: | |
6183 | case MPI2_RAID_PD_STATE_DEGRADED: | |
6184 | case MPI2_RAID_PD_STATE_REBUILDING: | |
6185 | case MPI2_RAID_PD_STATE_OPTIMAL: | |
6186 | case MPI2_RAID_PD_STATE_HOT_SPARE: | |
6187 | ||
6188 | set_bit(handle, ioc->pd_handles); | |
6189 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6190 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
6191 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6192 | ||
6193 | if (sas_device) | |
6194 | return; | |
6195 | ||
6196 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
6197 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
6198 | handle))) { | |
6199 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6200 | ioc->name, __FILE__, __LINE__, __func__); | |
6201 | return; | |
6202 | } | |
6203 | ||
6204 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6205 | MPI2_IOCSTATUS_MASK; | |
6206 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6207 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6208 | ioc->name, __FILE__, __LINE__, __func__); | |
6209 | return; | |
6210 | } | |
6211 | ||
6212 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
6213 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | |
6214 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
6215 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
6216 | ||
6217 | _scsih_add_device(ioc, handle, 0, 1); | |
6218 | ||
6219 | break; | |
6220 | ||
6221 | case MPI2_RAID_PD_STATE_OFFLINE: | |
6222 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | |
6223 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | |
6224 | default: | |
6225 | break; | |
6226 | } | |
6227 | } | |
6228 | ||
6229 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
6230 | /** | |
6231 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | |
6232 | * @ioc: per adapter object | |
6233 | * @event_data: event data payload | |
6234 | * Context: user. | |
6235 | * | |
6236 | * Return nothing. | |
6237 | */ | |
6238 | static void | |
6239 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, | |
6240 | Mpi2EventDataIrOperationStatus_t *event_data) | |
6241 | { | |
6242 | char *reason_str = NULL; | |
6243 | ||
6244 | switch (event_data->RAIDOperation) { | |
6245 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | |
6246 | reason_str = "resync"; | |
6247 | break; | |
6248 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | |
6249 | reason_str = "online capacity expansion"; | |
6250 | break; | |
6251 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | |
6252 | reason_str = "consistency check"; | |
6253 | break; | |
6254 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | |
6255 | reason_str = "background init"; | |
6256 | break; | |
6257 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | |
6258 | reason_str = "make data consistent"; | |
6259 | break; | |
6260 | } | |
6261 | ||
6262 | if (!reason_str) | |
6263 | return; | |
6264 | ||
6265 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ | |
6266 | "\thandle(0x%04x), percent complete(%d)\n", | |
6267 | ioc->name, reason_str, | |
6268 | le16_to_cpu(event_data->VolDevHandle), | |
6269 | event_data->PercentComplete); | |
6270 | } | |
6271 | #endif | |
6272 | ||
6273 | /** | |
6274 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | |
6275 | * @ioc: per adapter object | |
6276 | * @fw_event: The fw_event_work object | |
6277 | * Context: user. | |
6278 | * | |
6279 | * Return nothing. | |
6280 | */ | |
6281 | static void | |
6282 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, | |
6283 | struct fw_event_work *fw_event) | |
6284 | { | |
35b62362 JL |
6285 | Mpi2EventDataIrOperationStatus_t *event_data = |
6286 | (Mpi2EventDataIrOperationStatus_t *) | |
6287 | fw_event->event_data; | |
f92363d1 SR |
6288 | static struct _raid_device *raid_device; |
6289 | unsigned long flags; | |
6290 | u16 handle; | |
6291 | ||
6292 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING | |
6293 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | |
6294 | _scsih_sas_ir_operation_status_event_debug(ioc, | |
6295 | event_data); | |
6296 | #endif | |
6297 | ||
6298 | /* code added for raid transport support */ | |
6299 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | |
6300 | ||
6301 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6302 | handle = le16_to_cpu(event_data->VolDevHandle); | |
6303 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | |
6304 | if (raid_device) | |
6305 | raid_device->percent_complete = | |
6306 | event_data->PercentComplete; | |
6307 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6308 | } | |
6309 | } | |
6310 | ||
6311 | /** | |
6312 | * _scsih_prep_device_scan - initialize parameters prior to device scan | |
6313 | * @ioc: per adapter object | |
6314 | * | |
6315 | * Set the deleted flag prior to device scan. If the device is found during | |
6316 | * the scan, then we clear the deleted flag. | |
6317 | */ | |
6318 | static void | |
6319 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) | |
6320 | { | |
6321 | struct MPT3SAS_DEVICE *sas_device_priv_data; | |
6322 | struct scsi_device *sdev; | |
6323 | ||
6324 | shost_for_each_device(sdev, ioc->shost) { | |
6325 | sas_device_priv_data = sdev->hostdata; | |
6326 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | |
6327 | sas_device_priv_data->sas_target->deleted = 1; | |
6328 | } | |
6329 | } | |
6330 | ||
6331 | /** | |
6332 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | |
6333 | * @ioc: per adapter object | |
6334 | * @sas_address: sas address | |
6335 | * @slot: enclosure slot id | |
6336 | * @handle: device handle | |
6337 | * | |
6338 | * After host reset, find out whether devices are still responding. | |
6339 | * Used in _scsih_remove_unresponsive_sas_devices. | |
6340 | * | |
6341 | * Return nothing. | |
6342 | */ | |
6343 | static void | |
6344 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
6345 | u16 slot, u16 handle) | |
6346 | { | |
6347 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; | |
6348 | struct scsi_target *starget; | |
6349 | struct _sas_device *sas_device; | |
6350 | unsigned long flags; | |
6351 | ||
6352 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6353 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | |
6354 | if (sas_device->sas_address == sas_address && | |
6355 | sas_device->slot == slot) { | |
6356 | sas_device->responding = 1; | |
6357 | starget = sas_device->starget; | |
6358 | if (starget && starget->hostdata) { | |
6359 | sas_target_priv_data = starget->hostdata; | |
6360 | sas_target_priv_data->tm_busy = 0; | |
6361 | sas_target_priv_data->deleted = 0; | |
6362 | } else | |
6363 | sas_target_priv_data = NULL; | |
6364 | if (starget) | |
6365 | starget_printk(KERN_INFO, starget, | |
6366 | "handle(0x%04x), sas_addr(0x%016llx), " | |
6367 | "enclosure logical id(0x%016llx), " | |
6368 | "slot(%d)\n", handle, | |
6369 | (unsigned long long)sas_device->sas_address, | |
6370 | (unsigned long long) | |
6371 | sas_device->enclosure_logical_id, | |
6372 | sas_device->slot); | |
6373 | if (sas_device->handle == handle) | |
6374 | goto out; | |
6375 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
6376 | sas_device->handle); | |
6377 | sas_device->handle = handle; | |
6378 | if (sas_target_priv_data) | |
6379 | sas_target_priv_data->handle = handle; | |
6380 | goto out; | |
6381 | } | |
6382 | } | |
6383 | out: | |
6384 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6385 | } | |
6386 | ||
6387 | /** | |
6388 | * _scsih_search_responding_sas_devices - | |
6389 | * @ioc: per adapter object | |
6390 | * | |
6391 | * After host reset, find out whether devices are still responding. | |
6392 | * If not remove. | |
6393 | * | |
6394 | * Return nothing. | |
6395 | */ | |
6396 | static void | |
6397 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
6398 | { | |
6399 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6400 | Mpi2ConfigReply_t mpi_reply; | |
6401 | u16 ioc_status; | |
6402 | u16 handle; | |
6403 | u32 device_info; | |
6404 | ||
6405 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); | |
6406 | ||
6407 | if (list_empty(&ioc->sas_device_list)) | |
6408 | goto out; | |
6409 | ||
6410 | handle = 0xFFFF; | |
6411 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
6412 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
6413 | handle))) { | |
6414 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6415 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6416 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6417 | break; |
6418 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
6419 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | |
6420 | if (!(_scsih_is_end_device(device_info))) | |
6421 | continue; | |
6422 | _scsih_mark_responding_sas_device(ioc, | |
6423 | le64_to_cpu(sas_device_pg0.SASAddress), | |
6424 | le16_to_cpu(sas_device_pg0.Slot), handle); | |
6425 | } | |
6426 | ||
6427 | out: | |
6428 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", | |
6429 | ioc->name); | |
6430 | } | |
6431 | ||
6432 | /** | |
6433 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | |
6434 | * @ioc: per adapter object | |
6435 | * @wwid: world wide identifier for raid volume | |
6436 | * @handle: device handle | |
6437 | * | |
6438 | * After host reset, find out whether devices are still responding. | |
6439 | * Used in _scsih_remove_unresponsive_raid_devices. | |
6440 | * | |
6441 | * Return nothing. | |
6442 | */ | |
6443 | static void | |
6444 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, | |
6445 | u16 handle) | |
6446 | { | |
6447 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
6448 | struct scsi_target *starget; | |
6449 | struct _raid_device *raid_device; | |
6450 | unsigned long flags; | |
6451 | ||
6452 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6453 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | |
6454 | if (raid_device->wwid == wwid && raid_device->starget) { | |
6455 | starget = raid_device->starget; | |
6456 | if (starget && starget->hostdata) { | |
6457 | sas_target_priv_data = starget->hostdata; | |
6458 | sas_target_priv_data->deleted = 0; | |
6459 | } else | |
6460 | sas_target_priv_data = NULL; | |
6461 | raid_device->responding = 1; | |
6462 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6463 | starget_printk(KERN_INFO, raid_device->starget, | |
6464 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | |
6465 | (unsigned long long)raid_device->wwid); | |
6466 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6467 | if (raid_device->handle == handle) { | |
6468 | spin_unlock_irqrestore(&ioc->raid_device_lock, | |
6469 | flags); | |
6470 | return; | |
6471 | } | |
6472 | pr_info("\thandle changed from(0x%04x)!!!\n", | |
6473 | raid_device->handle); | |
6474 | raid_device->handle = handle; | |
6475 | if (sas_target_priv_data) | |
6476 | sas_target_priv_data->handle = handle; | |
6477 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6478 | return; | |
6479 | } | |
6480 | } | |
6481 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6482 | } | |
6483 | ||
6484 | /** | |
6485 | * _scsih_search_responding_raid_devices - | |
6486 | * @ioc: per adapter object | |
6487 | * | |
6488 | * After host reset, find out whether devices are still responding. | |
6489 | * If not remove. | |
6490 | * | |
6491 | * Return nothing. | |
6492 | */ | |
6493 | static void | |
6494 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) | |
6495 | { | |
6496 | Mpi2RaidVolPage1_t volume_pg1; | |
6497 | Mpi2RaidVolPage0_t volume_pg0; | |
6498 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
6499 | Mpi2ConfigReply_t mpi_reply; | |
6500 | u16 ioc_status; | |
6501 | u16 handle; | |
6502 | u8 phys_disk_num; | |
6503 | ||
6504 | if (!ioc->ir_firmware) | |
6505 | return; | |
6506 | ||
6507 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", | |
6508 | ioc->name); | |
6509 | ||
6510 | if (list_empty(&ioc->raid_device_list)) | |
6511 | goto out; | |
6512 | ||
6513 | handle = 0xFFFF; | |
6514 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
6515 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
6516 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6517 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6518 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6519 | break; |
6520 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
6521 | ||
6522 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
6523 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
6524 | sizeof(Mpi2RaidVolPage0_t))) | |
6525 | continue; | |
6526 | ||
6527 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
6528 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
6529 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | |
6530 | _scsih_mark_responding_raid_device(ioc, | |
6531 | le64_to_cpu(volume_pg1.WWID), handle); | |
6532 | } | |
6533 | ||
6534 | /* refresh the pd_handles */ | |
6535 | phys_disk_num = 0xFF; | |
6536 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | |
6537 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
6538 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
6539 | phys_disk_num))) { | |
6540 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6541 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6542 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6543 | break; |
6544 | phys_disk_num = pd_pg0.PhysDiskNum; | |
6545 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
6546 | set_bit(handle, ioc->pd_handles); | |
6547 | } | |
6548 | out: | |
6549 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", | |
6550 | ioc->name); | |
6551 | } | |
6552 | ||
6553 | /** | |
6554 | * _scsih_mark_responding_expander - mark a expander as responding | |
6555 | * @ioc: per adapter object | |
6556 | * @sas_address: sas address | |
6557 | * @handle: | |
6558 | * | |
6559 | * After host reset, find out whether devices are still responding. | |
6560 | * Used in _scsih_remove_unresponsive_expanders. | |
6561 | * | |
6562 | * Return nothing. | |
6563 | */ | |
6564 | static void | |
6565 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, | |
6566 | u16 handle) | |
6567 | { | |
6568 | struct _sas_node *sas_expander; | |
6569 | unsigned long flags; | |
6570 | int i; | |
6571 | ||
6572 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6573 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | |
6574 | if (sas_expander->sas_address != sas_address) | |
6575 | continue; | |
6576 | sas_expander->responding = 1; | |
6577 | if (sas_expander->handle == handle) | |
6578 | goto out; | |
6579 | pr_info("\texpander(0x%016llx): handle changed" \ | |
6580 | " from(0x%04x) to (0x%04x)!!!\n", | |
6581 | (unsigned long long)sas_expander->sas_address, | |
6582 | sas_expander->handle, handle); | |
6583 | sas_expander->handle = handle; | |
6584 | for (i = 0 ; i < sas_expander->num_phys ; i++) | |
6585 | sas_expander->phy[i].handle = handle; | |
6586 | goto out; | |
6587 | } | |
6588 | out: | |
6589 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6590 | } | |
6591 | ||
6592 | /** | |
6593 | * _scsih_search_responding_expanders - | |
6594 | * @ioc: per adapter object | |
6595 | * | |
6596 | * After host reset, find out whether devices are still responding. | |
6597 | * If not remove. | |
6598 | * | |
6599 | * Return nothing. | |
6600 | */ | |
6601 | static void | |
6602 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) | |
6603 | { | |
6604 | Mpi2ExpanderPage0_t expander_pg0; | |
6605 | Mpi2ConfigReply_t mpi_reply; | |
6606 | u16 ioc_status; | |
6607 | u64 sas_address; | |
6608 | u16 handle; | |
6609 | ||
6610 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); | |
6611 | ||
6612 | if (list_empty(&ioc->sas_expander_list)) | |
6613 | goto out; | |
6614 | ||
6615 | handle = 0xFFFF; | |
6616 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
6617 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
6618 | ||
6619 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6620 | MPI2_IOCSTATUS_MASK; | |
14be49ac | 6621 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
f92363d1 SR |
6622 | break; |
6623 | ||
6624 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
6625 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | |
6626 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", | |
6627 | handle, | |
6628 | (unsigned long long)sas_address); | |
6629 | _scsih_mark_responding_expander(ioc, sas_address, handle); | |
6630 | } | |
6631 | ||
6632 | out: | |
6633 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); | |
6634 | } | |
6635 | ||
6636 | /** | |
6637 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices | |
6638 | * @ioc: per adapter object | |
6639 | * | |
6640 | * Return nothing. | |
6641 | */ | |
6642 | static void | |
6643 | _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc) | |
6644 | { | |
6645 | struct _sas_device *sas_device, *sas_device_next; | |
6646 | struct _sas_node *sas_expander, *sas_expander_next; | |
6647 | struct _raid_device *raid_device, *raid_device_next; | |
6648 | struct list_head tmp_list; | |
6649 | unsigned long flags; | |
6650 | ||
6651 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", | |
6652 | ioc->name); | |
6653 | ||
6654 | /* removing unresponding end devices */ | |
6655 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", | |
6656 | ioc->name); | |
6657 | list_for_each_entry_safe(sas_device, sas_device_next, | |
6658 | &ioc->sas_device_list, list) { | |
6659 | if (!sas_device->responding) | |
6660 | mpt3sas_device_remove_by_sas_address(ioc, | |
6661 | sas_device->sas_address); | |
6662 | else | |
6663 | sas_device->responding = 0; | |
6664 | } | |
6665 | ||
6666 | /* removing unresponding volumes */ | |
6667 | if (ioc->ir_firmware) { | |
6668 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", | |
6669 | ioc->name); | |
6670 | list_for_each_entry_safe(raid_device, raid_device_next, | |
6671 | &ioc->raid_device_list, list) { | |
6672 | if (!raid_device->responding) | |
6673 | _scsih_sas_volume_delete(ioc, | |
6674 | raid_device->handle); | |
6675 | else | |
6676 | raid_device->responding = 0; | |
6677 | } | |
6678 | } | |
6679 | ||
6680 | /* removing unresponding expanders */ | |
6681 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", | |
6682 | ioc->name); | |
6683 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6684 | INIT_LIST_HEAD(&tmp_list); | |
6685 | list_for_each_entry_safe(sas_expander, sas_expander_next, | |
6686 | &ioc->sas_expander_list, list) { | |
6687 | if (!sas_expander->responding) | |
6688 | list_move_tail(&sas_expander->list, &tmp_list); | |
6689 | else | |
6690 | sas_expander->responding = 0; | |
6691 | } | |
6692 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6693 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | |
6694 | list) { | |
6695 | list_del(&sas_expander->list); | |
6696 | _scsih_expander_node_remove(ioc, sas_expander); | |
6697 | } | |
6698 | ||
6699 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", | |
6700 | ioc->name); | |
6701 | ||
6702 | /* unblock devices */ | |
6703 | _scsih_ublock_io_all_device(ioc); | |
6704 | } | |
6705 | ||
6706 | static void | |
6707 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, | |
6708 | struct _sas_node *sas_expander, u16 handle) | |
6709 | { | |
6710 | Mpi2ExpanderPage1_t expander_pg1; | |
6711 | Mpi2ConfigReply_t mpi_reply; | |
6712 | int i; | |
6713 | ||
6714 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | |
6715 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, | |
6716 | &expander_pg1, i, handle))) { | |
6717 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
6718 | ioc->name, __FILE__, __LINE__, __func__); | |
6719 | return; | |
6720 | } | |
6721 | ||
6722 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, | |
6723 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | |
6724 | expander_pg1.NegotiatedLinkRate >> 4); | |
6725 | } | |
6726 | } | |
6727 | ||
6728 | /** | |
6729 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | |
6730 | * @ioc: per adapter object | |
6731 | * | |
6732 | * Return nothing. | |
6733 | */ | |
6734 | static void | |
6735 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) | |
6736 | { | |
6737 | Mpi2ExpanderPage0_t expander_pg0; | |
6738 | Mpi2SasDevicePage0_t sas_device_pg0; | |
6739 | Mpi2RaidVolPage1_t volume_pg1; | |
6740 | Mpi2RaidVolPage0_t volume_pg0; | |
6741 | Mpi2RaidPhysDiskPage0_t pd_pg0; | |
6742 | Mpi2EventIrConfigElement_t element; | |
6743 | Mpi2ConfigReply_t mpi_reply; | |
6744 | u8 phys_disk_num; | |
6745 | u16 ioc_status; | |
6746 | u16 handle, parent_handle; | |
6747 | u64 sas_address; | |
6748 | struct _sas_device *sas_device; | |
6749 | struct _sas_node *expander_device; | |
6750 | static struct _raid_device *raid_device; | |
6751 | u8 retry_count; | |
6752 | unsigned long flags; | |
6753 | ||
6754 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); | |
6755 | ||
6756 | _scsih_sas_host_refresh(ioc); | |
6757 | ||
6758 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); | |
6759 | ||
6760 | /* expanders */ | |
6761 | handle = 0xFFFF; | |
6762 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | |
6763 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | |
6764 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6765 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
6766 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
6767 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ | |
6768 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
6769 | ioc->name, ioc_status, | |
6770 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
6771 | break; | |
6772 | } | |
6773 | handle = le16_to_cpu(expander_pg0.DevHandle); | |
6774 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | |
6775 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( | |
6776 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | |
6777 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | |
6778 | if (expander_device) | |
6779 | _scsih_refresh_expander_links(ioc, expander_device, | |
6780 | handle); | |
6781 | else { | |
6782 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ | |
6783 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
6784 | handle, (unsigned long long) | |
6785 | le64_to_cpu(expander_pg0.SASAddress)); | |
6786 | _scsih_expander_add(ioc, handle); | |
6787 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ | |
6788 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
6789 | handle, (unsigned long long) | |
6790 | le64_to_cpu(expander_pg0.SASAddress)); | |
6791 | } | |
6792 | } | |
6793 | ||
6794 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", | |
6795 | ioc->name); | |
6796 | ||
6797 | if (!ioc->ir_firmware) | |
6798 | goto skip_to_sas; | |
6799 | ||
6800 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); | |
6801 | ||
6802 | /* phys disk */ | |
6803 | phys_disk_num = 0xFF; | |
6804 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | |
6805 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | |
6806 | phys_disk_num))) { | |
6807 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6808 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
6809 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
6810 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ | |
6811 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
6812 | ioc->name, ioc_status, | |
6813 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
6814 | break; | |
6815 | } | |
6816 | phys_disk_num = pd_pg0.PhysDiskNum; | |
6817 | handle = le16_to_cpu(pd_pg0.DevHandle); | |
6818 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6819 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); | |
6820 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6821 | if (sas_device) | |
6822 | continue; | |
6823 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
6824 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | |
6825 | handle) != 0) | |
6826 | continue; | |
6827 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6828 | MPI2_IOCSTATUS_MASK; | |
6829 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6830 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ | |
6831 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
6832 | ioc->name, ioc_status, | |
6833 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
6834 | break; | |
6835 | } | |
6836 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
6837 | if (!_scsih_get_sas_address(ioc, parent_handle, | |
6838 | &sas_address)) { | |
6839 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ | |
6840 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
6841 | ioc->name, handle, (unsigned long long) | |
6842 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
6843 | mpt3sas_transport_update_links(ioc, sas_address, | |
6844 | handle, sas_device_pg0.PhyNum, | |
6845 | MPI2_SAS_NEG_LINK_RATE_1_5); | |
6846 | set_bit(handle, ioc->pd_handles); | |
6847 | retry_count = 0; | |
6848 | /* This will retry adding the end device. | |
6849 | * _scsih_add_device() will decide on retries and | |
6850 | * return "1" when it should be retried | |
6851 | */ | |
6852 | while (_scsih_add_device(ioc, handle, retry_count++, | |
6853 | 1)) { | |
6854 | ssleep(1); | |
6855 | } | |
6856 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ | |
6857 | " handle (0x%04x), sas_addr(0x%016llx)\n", | |
6858 | ioc->name, handle, (unsigned long long) | |
6859 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
6860 | } | |
6861 | } | |
6862 | ||
6863 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", | |
6864 | ioc->name); | |
6865 | ||
6866 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); | |
6867 | ||
6868 | /* volumes */ | |
6869 | handle = 0xFFFF; | |
6870 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | |
6871 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | |
6872 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6873 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
6874 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
6875 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
6876 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
6877 | ioc->name, ioc_status, | |
6878 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
6879 | break; | |
6880 | } | |
6881 | handle = le16_to_cpu(volume_pg1.DevHandle); | |
6882 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | |
6883 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | |
6884 | le64_to_cpu(volume_pg1.WWID)); | |
6885 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | |
6886 | if (raid_device) | |
6887 | continue; | |
6888 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | |
6889 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | |
6890 | sizeof(Mpi2RaidVolPage0_t))) | |
6891 | continue; | |
6892 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6893 | MPI2_IOCSTATUS_MASK; | |
6894 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | |
6895 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ | |
6896 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | |
6897 | ioc->name, ioc_status, | |
6898 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
6899 | break; | |
6900 | } | |
6901 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | |
6902 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | |
6903 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | |
6904 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | |
6905 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | |
6906 | element.VolDevHandle = volume_pg1.DevHandle; | |
6907 | pr_info(MPT3SAS_FMT | |
6908 | "\tBEFORE adding volume: handle (0x%04x)\n", | |
6909 | ioc->name, volume_pg1.DevHandle); | |
6910 | _scsih_sas_volume_add(ioc, &element); | |
6911 | pr_info(MPT3SAS_FMT | |
6912 | "\tAFTER adding volume: handle (0x%04x)\n", | |
6913 | ioc->name, volume_pg1.DevHandle); | |
6914 | } | |
6915 | } | |
6916 | ||
6917 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", | |
6918 | ioc->name); | |
6919 | ||
6920 | skip_to_sas: | |
6921 | ||
6922 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", | |
6923 | ioc->name); | |
6924 | ||
6925 | /* sas devices */ | |
6926 | handle = 0xFFFF; | |
6927 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, | |
6928 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | |
6929 | handle))) { | |
6930 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | |
6931 | MPI2_IOCSTATUS_MASK; | |
f92363d1 SR |
6932 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
6933 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ | |
6934 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | |
6935 | ioc->name, ioc_status, | |
6936 | le32_to_cpu(mpi_reply.IOCLogInfo)); | |
6937 | break; | |
6938 | } | |
6939 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | |
6940 | if (!(_scsih_is_end_device( | |
6941 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | |
6942 | continue; | |
6943 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
6944 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, | |
6945 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
6946 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
6947 | if (sas_device) | |
6948 | continue; | |
6949 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | |
6950 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | |
6951 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ | |
6952 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
6953 | handle, (unsigned long long) | |
6954 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
6955 | mpt3sas_transport_update_links(ioc, sas_address, handle, | |
6956 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | |
6957 | retry_count = 0; | |
6958 | /* This will retry adding the end device. | |
6959 | * _scsih_add_device() will decide on retries and | |
6960 | * return "1" when it should be retried | |
6961 | */ | |
6962 | while (_scsih_add_device(ioc, handle, retry_count++, | |
6963 | 0)) { | |
6964 | ssleep(1); | |
6965 | } | |
6966 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ | |
6967 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, | |
6968 | handle, (unsigned long long) | |
6969 | le64_to_cpu(sas_device_pg0.SASAddress)); | |
6970 | } | |
6971 | } | |
6972 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", | |
6973 | ioc->name); | |
6974 | ||
6975 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); | |
6976 | } | |
6977 | /** | |
6978 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) | |
6979 | * @ioc: per adapter object | |
6980 | * @reset_phase: phase | |
6981 | * | |
6982 | * The handler for doing any required cleanup or initialization. | |
6983 | * | |
6984 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, | |
6985 | * MPT3_IOC_DONE_RESET | |
6986 | * | |
6987 | * Return nothing. | |
6988 | */ | |
6989 | void | |
6990 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) | |
6991 | { | |
6992 | switch (reset_phase) { | |
6993 | case MPT3_IOC_PRE_RESET: | |
6994 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
6995 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); | |
6996 | break; | |
6997 | case MPT3_IOC_AFTER_RESET: | |
6998 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
6999 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); | |
7000 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { | |
7001 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; | |
7002 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | |
7003 | complete(&ioc->scsih_cmds.done); | |
7004 | } | |
7005 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { | |
7006 | ioc->tm_cmds.status |= MPT3_CMD_RESET; | |
7007 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); | |
7008 | complete(&ioc->tm_cmds.done); | |
7009 | } | |
7010 | ||
7011 | _scsih_fw_event_cleanup_queue(ioc); | |
7012 | _scsih_flush_running_cmds(ioc); | |
7013 | break; | |
7014 | case MPT3_IOC_DONE_RESET: | |
7015 | dtmprintk(ioc, pr_info(MPT3SAS_FMT | |
7016 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); | |
7017 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | |
7018 | !ioc->sas_hba.num_phys)) { | |
7019 | _scsih_prep_device_scan(ioc); | |
7020 | _scsih_search_responding_sas_devices(ioc); | |
7021 | _scsih_search_responding_raid_devices(ioc); | |
7022 | _scsih_search_responding_expanders(ioc); | |
7023 | _scsih_error_recovery_delete_devices(ioc); | |
7024 | } | |
7025 | break; | |
7026 | } | |
7027 | } | |
7028 | ||
7029 | /** | |
7030 | * _mpt3sas_fw_work - delayed task for processing firmware events | |
7031 | * @ioc: per adapter object | |
7032 | * @fw_event: The fw_event_work object | |
7033 | * Context: user. | |
7034 | * | |
7035 | * Return nothing. | |
7036 | */ | |
7037 | static void | |
7038 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | |
7039 | { | |
7040 | /* the queue is being flushed so ignore this event */ | |
4dc06fd8 | 7041 | if (ioc->remove_host || |
f92363d1 SR |
7042 | ioc->pci_error_recovery) { |
7043 | _scsih_fw_event_free(ioc, fw_event); | |
7044 | return; | |
7045 | } | |
7046 | ||
7047 | switch (fw_event->event) { | |
7048 | case MPT3SAS_PROCESS_TRIGGER_DIAG: | |
35b62362 JL |
7049 | mpt3sas_process_trigger_data(ioc, |
7050 | (struct SL_WH_TRIGGERS_EVENT_DATA_T *) | |
7051 | fw_event->event_data); | |
f92363d1 SR |
7052 | break; |
7053 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: | |
7054 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) | |
7055 | ssleep(1); | |
7056 | _scsih_remove_unresponding_sas_devices(ioc); | |
7057 | _scsih_scan_for_devices_after_reset(ioc); | |
7058 | break; | |
7059 | case MPT3SAS_PORT_ENABLE_COMPLETE: | |
7060 | ioc->start_scan = 0; | |
7061 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | |
7062 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], | |
7063 | missing_delay[1]); | |
7064 | dewtprintk(ioc, pr_info(MPT3SAS_FMT | |
7065 | "port enable: complete from worker thread\n", | |
7066 | ioc->name)); | |
7067 | break; | |
7068 | case MPT3SAS_TURN_ON_FAULT_LED: | |
7069 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); | |
7070 | break; | |
7071 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
7072 | _scsih_sas_topology_change_event(ioc, fw_event); | |
7073 | break; | |
7074 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
7075 | _scsih_sas_device_status_change_event(ioc, fw_event); | |
7076 | break; | |
7077 | case MPI2_EVENT_SAS_DISCOVERY: | |
7078 | _scsih_sas_discovery_event(ioc, fw_event); | |
7079 | break; | |
7080 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
7081 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); | |
7082 | break; | |
7083 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
7084 | _scsih_sas_enclosure_dev_status_change_event(ioc, | |
7085 | fw_event); | |
7086 | break; | |
7087 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
7088 | _scsih_sas_ir_config_change_event(ioc, fw_event); | |
7089 | break; | |
7090 | case MPI2_EVENT_IR_VOLUME: | |
7091 | _scsih_sas_ir_volume_event(ioc, fw_event); | |
7092 | break; | |
7093 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
7094 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | |
7095 | break; | |
7096 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
7097 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | |
7098 | break; | |
7099 | } | |
7100 | _scsih_fw_event_free(ioc, fw_event); | |
7101 | } | |
7102 | ||
7103 | /** | |
7104 | * _firmware_event_work | |
7105 | * @ioc: per adapter object | |
7106 | * @work: The fw_event_work object | |
7107 | * Context: user. | |
7108 | * | |
7109 | * wrappers for the work thread handling firmware events | |
7110 | * | |
7111 | * Return nothing. | |
7112 | */ | |
7113 | ||
7114 | static void | |
7115 | _firmware_event_work(struct work_struct *work) | |
7116 | { | |
7117 | struct fw_event_work *fw_event = container_of(work, | |
7118 | struct fw_event_work, work); | |
7119 | ||
7120 | _mpt3sas_fw_work(fw_event->ioc, fw_event); | |
7121 | } | |
7122 | ||
7123 | /** | |
7124 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) | |
7125 | * @ioc: per adapter object | |
7126 | * @msix_index: MSIX table index supplied by the OS | |
7127 | * @reply: reply message frame(lower 32bit addr) | |
7128 | * Context: interrupt. | |
7129 | * | |
7130 | * This function merely adds a new work task into ioc->firmware_event_thread. | |
7131 | * The tasks are worked from _firmware_event_work in user context. | |
7132 | * | |
7133 | * Return 1 meaning mf should be freed from _base_interrupt | |
7134 | * 0 means the mf is freed from this function. | |
7135 | */ | |
7136 | u8 | |
7137 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, | |
7138 | u32 reply) | |
7139 | { | |
7140 | struct fw_event_work *fw_event; | |
7141 | Mpi2EventNotificationReply_t *mpi_reply; | |
7142 | u16 event; | |
7143 | u16 sz; | |
7144 | ||
7145 | /* events turned off due to host reset or driver unloading */ | |
7146 | if (ioc->remove_host || ioc->pci_error_recovery) | |
7147 | return 1; | |
7148 | ||
7149 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); | |
7150 | ||
7151 | if (unlikely(!mpi_reply)) { | |
7152 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", | |
7153 | ioc->name, __FILE__, __LINE__, __func__); | |
7154 | return 1; | |
7155 | } | |
7156 | ||
7157 | event = le16_to_cpu(mpi_reply->Event); | |
7158 | ||
7159 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) | |
7160 | mpt3sas_trigger_event(ioc, event, 0); | |
7161 | ||
7162 | switch (event) { | |
7163 | /* handle these */ | |
7164 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | |
7165 | { | |
7166 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | |
7167 | (Mpi2EventDataSasBroadcastPrimitive_t *) | |
7168 | mpi_reply->EventData; | |
7169 | ||
7170 | if (baen_data->Primitive != | |
7171 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | |
7172 | return 1; | |
7173 | ||
7174 | if (ioc->broadcast_aen_busy) { | |
7175 | ioc->broadcast_aen_pending++; | |
7176 | return 1; | |
7177 | } else | |
7178 | ioc->broadcast_aen_busy = 1; | |
7179 | break; | |
7180 | } | |
7181 | ||
7182 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | |
7183 | _scsih_check_topo_delete_events(ioc, | |
7184 | (Mpi2EventDataSasTopologyChangeList_t *) | |
7185 | mpi_reply->EventData); | |
7186 | break; | |
7187 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | |
7188 | _scsih_check_ir_config_unhide_events(ioc, | |
7189 | (Mpi2EventDataIrConfigChangeList_t *) | |
7190 | mpi_reply->EventData); | |
7191 | break; | |
7192 | case MPI2_EVENT_IR_VOLUME: | |
7193 | _scsih_check_volume_delete_events(ioc, | |
7194 | (Mpi2EventDataIrVolume_t *) | |
7195 | mpi_reply->EventData); | |
7196 | break; | |
7197 | ||
7198 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | |
7199 | case MPI2_EVENT_IR_OPERATION_STATUS: | |
7200 | case MPI2_EVENT_SAS_DISCOVERY: | |
7201 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | |
7202 | case MPI2_EVENT_IR_PHYSICAL_DISK: | |
7203 | break; | |
7204 | ||
7205 | default: /* ignore the rest */ | |
7206 | return 1; | |
7207 | } | |
7208 | ||
f92363d1 | 7209 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
35b62362 JL |
7210 | fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC); |
7211 | if (!fw_event) { | |
f92363d1 SR |
7212 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
7213 | ioc->name, __FILE__, __LINE__, __func__); | |
f92363d1 SR |
7214 | return 1; |
7215 | } | |
7216 | ||
7217 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | |
7218 | fw_event->ioc = ioc; | |
7219 | fw_event->VF_ID = mpi_reply->VF_ID; | |
7220 | fw_event->VP_ID = mpi_reply->VP_ID; | |
7221 | fw_event->event = event; | |
7222 | _scsih_fw_event_add(ioc, fw_event); | |
7223 | return 1; | |
7224 | } | |
7225 | ||
7226 | /* shost template */ | |
7227 | static struct scsi_host_template scsih_driver_template = { | |
7228 | .module = THIS_MODULE, | |
7229 | .name = "Fusion MPT SAS Host", | |
7230 | .proc_name = MPT3SAS_DRIVER_NAME, | |
7231 | .queuecommand = _scsih_qcmd, | |
7232 | .target_alloc = _scsih_target_alloc, | |
7233 | .slave_alloc = _scsih_slave_alloc, | |
7234 | .slave_configure = _scsih_slave_configure, | |
7235 | .target_destroy = _scsih_target_destroy, | |
7236 | .slave_destroy = _scsih_slave_destroy, | |
7237 | .scan_finished = _scsih_scan_finished, | |
7238 | .scan_start = _scsih_scan_start, | |
7239 | .change_queue_depth = _scsih_change_queue_depth, | |
7240 | .change_queue_type = _scsih_change_queue_type, | |
7241 | .eh_abort_handler = _scsih_abort, | |
7242 | .eh_device_reset_handler = _scsih_dev_reset, | |
7243 | .eh_target_reset_handler = _scsih_target_reset, | |
7244 | .eh_host_reset_handler = _scsih_host_reset, | |
7245 | .bios_param = _scsih_bios_param, | |
7246 | .can_queue = 1, | |
7247 | .this_id = -1, | |
7248 | .sg_tablesize = MPT3SAS_SG_DEPTH, | |
7249 | .max_sectors = 32767, | |
7250 | .cmd_per_lun = 7, | |
7251 | .use_clustering = ENABLE_CLUSTERING, | |
7252 | .shost_attrs = mpt3sas_host_attrs, | |
7253 | .sdev_attrs = mpt3sas_dev_attrs, | |
7254 | }; | |
7255 | ||
7256 | /** | |
7257 | * _scsih_expander_node_remove - removing expander device from list. | |
7258 | * @ioc: per adapter object | |
7259 | * @sas_expander: the sas_device object | |
7260 | * Context: Calling function should acquire ioc->sas_node_lock. | |
7261 | * | |
7262 | * Removing object and freeing associated memory from the | |
7263 | * ioc->sas_expander_list. | |
7264 | * | |
7265 | * Return nothing. | |
7266 | */ | |
7267 | static void | |
7268 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, | |
7269 | struct _sas_node *sas_expander) | |
7270 | { | |
7271 | struct _sas_port *mpt3sas_port, *next; | |
7272 | ||
7273 | /* remove sibling ports attached to this expander */ | |
7274 | list_for_each_entry_safe(mpt3sas_port, next, | |
7275 | &sas_expander->sas_port_list, port_list) { | |
7276 | if (ioc->shost_recovery) | |
7277 | return; | |
7278 | if (mpt3sas_port->remote_identify.device_type == | |
7279 | SAS_END_DEVICE) | |
7280 | mpt3sas_device_remove_by_sas_address(ioc, | |
7281 | mpt3sas_port->remote_identify.sas_address); | |
7282 | else if (mpt3sas_port->remote_identify.device_type == | |
7283 | SAS_EDGE_EXPANDER_DEVICE || | |
7284 | mpt3sas_port->remote_identify.device_type == | |
7285 | SAS_FANOUT_EXPANDER_DEVICE) | |
7286 | mpt3sas_expander_remove(ioc, | |
7287 | mpt3sas_port->remote_identify.sas_address); | |
7288 | } | |
7289 | ||
7290 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, | |
7291 | sas_expander->sas_address_parent); | |
7292 | ||
7293 | pr_info(MPT3SAS_FMT | |
7294 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", | |
7295 | ioc->name, | |
7296 | sas_expander->handle, (unsigned long long) | |
7297 | sas_expander->sas_address); | |
7298 | ||
7299 | kfree(sas_expander->phy); | |
7300 | kfree(sas_expander); | |
7301 | } | |
7302 | ||
7303 | /** | |
7304 | * _scsih_ir_shutdown - IR shutdown notification | |
7305 | * @ioc: per adapter object | |
7306 | * | |
7307 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | |
7308 | * the host system is shutting down. | |
7309 | * | |
7310 | * Return nothing. | |
7311 | */ | |
7312 | static void | |
7313 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) | |
7314 | { | |
7315 | Mpi2RaidActionRequest_t *mpi_request; | |
7316 | Mpi2RaidActionReply_t *mpi_reply; | |
7317 | u16 smid; | |
7318 | ||
7319 | /* is IR firmware build loaded ? */ | |
7320 | if (!ioc->ir_firmware) | |
7321 | return; | |
7322 | ||
7323 | /* are there any volumes ? */ | |
7324 | if (list_empty(&ioc->raid_device_list)) | |
7325 | return; | |
7326 | ||
7327 | mutex_lock(&ioc->scsih_cmds.mutex); | |
7328 | ||
7329 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { | |
7330 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", | |
7331 | ioc->name, __func__); | |
7332 | goto out; | |
7333 | } | |
7334 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; | |
7335 | ||
7336 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); | |
7337 | if (!smid) { | |
7338 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", | |
7339 | ioc->name, __func__); | |
7340 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7341 | goto out; | |
7342 | } | |
7343 | ||
7344 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); | |
7345 | ioc->scsih_cmds.smid = smid; | |
7346 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | |
7347 | ||
7348 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | |
7349 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | |
7350 | ||
7351 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); | |
7352 | init_completion(&ioc->scsih_cmds.done); | |
7353 | mpt3sas_base_put_smid_default(ioc, smid); | |
7354 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); | |
7355 | ||
7356 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { | |
7357 | pr_err(MPT3SAS_FMT "%s: timeout\n", | |
7358 | ioc->name, __func__); | |
7359 | goto out; | |
7360 | } | |
7361 | ||
7362 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { | |
7363 | mpi_reply = ioc->scsih_cmds.reply; | |
7364 | pr_info(MPT3SAS_FMT | |
7365 | "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n", | |
7366 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | |
7367 | le32_to_cpu(mpi_reply->IOCLogInfo)); | |
7368 | } | |
7369 | ||
7370 | out: | |
7371 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; | |
7372 | mutex_unlock(&ioc->scsih_cmds.mutex); | |
7373 | } | |
7374 | ||
7375 | /** | |
7376 | * _scsih_remove - detach and remove add host | |
7377 | * @pdev: PCI device struct | |
7378 | * | |
7379 | * Routine called when unloading the driver. | |
7380 | * Return nothing. | |
7381 | */ | |
6f039790 | 7382 | static void _scsih_remove(struct pci_dev *pdev) |
f92363d1 SR |
7383 | { |
7384 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7385 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7386 | struct _sas_port *mpt3sas_port, *next_port; | |
7387 | struct _raid_device *raid_device, *next; | |
7388 | struct MPT3SAS_TARGET *sas_target_priv_data; | |
7389 | struct workqueue_struct *wq; | |
7390 | unsigned long flags; | |
7391 | ||
7392 | ioc->remove_host = 1; | |
7393 | _scsih_fw_event_cleanup_queue(ioc); | |
7394 | ||
7395 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
7396 | wq = ioc->firmware_event_thread; | |
7397 | ioc->firmware_event_thread = NULL; | |
7398 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
7399 | if (wq) | |
7400 | destroy_workqueue(wq); | |
7401 | ||
7402 | /* release all the volumes */ | |
7403 | _scsih_ir_shutdown(ioc); | |
7404 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | |
7405 | list) { | |
7406 | if (raid_device->starget) { | |
7407 | sas_target_priv_data = | |
7408 | raid_device->starget->hostdata; | |
7409 | sas_target_priv_data->deleted = 1; | |
7410 | scsi_remove_target(&raid_device->starget->dev); | |
7411 | } | |
7412 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", | |
7413 | ioc->name, raid_device->handle, | |
7414 | (unsigned long long) raid_device->wwid); | |
7415 | _scsih_raid_device_remove(ioc, raid_device); | |
7416 | } | |
7417 | ||
7418 | /* free ports attached to the sas_host */ | |
7419 | list_for_each_entry_safe(mpt3sas_port, next_port, | |
7420 | &ioc->sas_hba.sas_port_list, port_list) { | |
7421 | if (mpt3sas_port->remote_identify.device_type == | |
7422 | SAS_END_DEVICE) | |
7423 | mpt3sas_device_remove_by_sas_address(ioc, | |
7424 | mpt3sas_port->remote_identify.sas_address); | |
7425 | else if (mpt3sas_port->remote_identify.device_type == | |
7426 | SAS_EDGE_EXPANDER_DEVICE || | |
7427 | mpt3sas_port->remote_identify.device_type == | |
7428 | SAS_FANOUT_EXPANDER_DEVICE) | |
7429 | mpt3sas_expander_remove(ioc, | |
7430 | mpt3sas_port->remote_identify.sas_address); | |
7431 | } | |
7432 | ||
7433 | /* free phys attached to the sas_host */ | |
7434 | if (ioc->sas_hba.num_phys) { | |
7435 | kfree(ioc->sas_hba.phy); | |
7436 | ioc->sas_hba.phy = NULL; | |
7437 | ioc->sas_hba.num_phys = 0; | |
7438 | } | |
7439 | ||
7440 | sas_remove_host(shost); | |
4dc06fd8 | 7441 | scsi_remove_host(shost); |
f92363d1 SR |
7442 | mpt3sas_base_detach(ioc); |
7443 | list_del(&ioc->list); | |
f92363d1 SR |
7444 | scsi_host_put(shost); |
7445 | } | |
7446 | ||
7447 | /** | |
7448 | * _scsih_shutdown - routine call during system shutdown | |
7449 | * @pdev: PCI device struct | |
7450 | * | |
7451 | * Return nothing. | |
7452 | */ | |
7453 | static void | |
7454 | _scsih_shutdown(struct pci_dev *pdev) | |
7455 | { | |
7456 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7457 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7458 | struct workqueue_struct *wq; | |
7459 | unsigned long flags; | |
7460 | ||
7461 | ioc->remove_host = 1; | |
7462 | _scsih_fw_event_cleanup_queue(ioc); | |
7463 | ||
7464 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | |
7465 | wq = ioc->firmware_event_thread; | |
7466 | ioc->firmware_event_thread = NULL; | |
7467 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | |
7468 | if (wq) | |
7469 | destroy_workqueue(wq); | |
7470 | ||
7471 | _scsih_ir_shutdown(ioc); | |
7472 | mpt3sas_base_detach(ioc); | |
7473 | } | |
7474 | ||
7475 | ||
7476 | /** | |
7477 | * _scsih_probe_boot_devices - reports 1st device | |
7478 | * @ioc: per adapter object | |
7479 | * | |
7480 | * If specified in bios page 2, this routine reports the 1st | |
7481 | * device scsi-ml or sas transport for persistent boot device | |
7482 | * purposes. Please refer to function _scsih_determine_boot_device() | |
7483 | */ | |
7484 | static void | |
7485 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) | |
7486 | { | |
7487 | u8 is_raid; | |
7488 | void *device; | |
7489 | struct _sas_device *sas_device; | |
7490 | struct _raid_device *raid_device; | |
7491 | u16 handle; | |
7492 | u64 sas_address_parent; | |
7493 | u64 sas_address; | |
7494 | unsigned long flags; | |
7495 | int rc; | |
7496 | ||
7497 | /* no Bios, return immediately */ | |
7498 | if (!ioc->bios_pg3.BiosVersion) | |
7499 | return; | |
7500 | ||
7501 | device = NULL; | |
7502 | is_raid = 0; | |
7503 | if (ioc->req_boot_device.device) { | |
7504 | device = ioc->req_boot_device.device; | |
7505 | is_raid = ioc->req_boot_device.is_raid; | |
7506 | } else if (ioc->req_alt_boot_device.device) { | |
7507 | device = ioc->req_alt_boot_device.device; | |
7508 | is_raid = ioc->req_alt_boot_device.is_raid; | |
7509 | } else if (ioc->current_boot_device.device) { | |
7510 | device = ioc->current_boot_device.device; | |
7511 | is_raid = ioc->current_boot_device.is_raid; | |
7512 | } | |
7513 | ||
7514 | if (!device) | |
7515 | return; | |
7516 | ||
7517 | if (is_raid) { | |
7518 | raid_device = device; | |
7519 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7520 | raid_device->id, 0); | |
7521 | if (rc) | |
7522 | _scsih_raid_device_remove(ioc, raid_device); | |
7523 | } else { | |
7524 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7525 | sas_device = device; | |
7526 | handle = sas_device->handle; | |
7527 | sas_address_parent = sas_device->sas_address_parent; | |
7528 | sas_address = sas_device->sas_address; | |
7529 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
7530 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7531 | ||
7532 | if (!mpt3sas_transport_port_add(ioc, handle, | |
7533 | sas_address_parent)) { | |
7534 | _scsih_sas_device_remove(ioc, sas_device); | |
7535 | } else if (!sas_device->starget) { | |
f5edbe77 SR |
7536 | if (!ioc->is_driver_loading) { |
7537 | mpt3sas_transport_port_remove(ioc, | |
7538 | sas_address, | |
f92363d1 | 7539 | sas_address_parent); |
f5edbe77 SR |
7540 | _scsih_sas_device_remove(ioc, sas_device); |
7541 | } | |
f92363d1 SR |
7542 | } |
7543 | } | |
7544 | } | |
7545 | ||
7546 | /** | |
7547 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | |
7548 | * @ioc: per adapter object | |
7549 | * | |
7550 | * Called during initial loading of the driver. | |
7551 | */ | |
7552 | static void | |
7553 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) | |
7554 | { | |
7555 | struct _raid_device *raid_device, *raid_next; | |
7556 | int rc; | |
7557 | ||
7558 | list_for_each_entry_safe(raid_device, raid_next, | |
7559 | &ioc->raid_device_list, list) { | |
7560 | if (raid_device->starget) | |
7561 | continue; | |
7562 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | |
7563 | raid_device->id, 0); | |
7564 | if (rc) | |
7565 | _scsih_raid_device_remove(ioc, raid_device); | |
7566 | } | |
7567 | } | |
7568 | ||
7569 | /** | |
7570 | * _scsih_probe_sas - reporting sas devices to sas transport | |
7571 | * @ioc: per adapter object | |
7572 | * | |
7573 | * Called during initial loading of the driver. | |
7574 | */ | |
7575 | static void | |
7576 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) | |
7577 | { | |
7578 | struct _sas_device *sas_device, *next; | |
7579 | unsigned long flags; | |
7580 | ||
7581 | /* SAS Device List */ | |
7582 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, | |
7583 | list) { | |
7584 | ||
7585 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, | |
7586 | sas_device->sas_address_parent)) { | |
7587 | list_del(&sas_device->list); | |
7588 | kfree(sas_device); | |
7589 | continue; | |
7590 | } else if (!sas_device->starget) { | |
7591 | /* | |
7592 | * When asyn scanning is enabled, its not possible to | |
7593 | * remove devices while scanning is turned on due to an | |
7594 | * oops in scsi_sysfs_add_sdev()->add_device()-> | |
7595 | * sysfs_addrm_start() | |
7596 | */ | |
f5edbe77 | 7597 | if (!ioc->is_driver_loading) { |
f92363d1 SR |
7598 | mpt3sas_transport_port_remove(ioc, |
7599 | sas_device->sas_address, | |
7600 | sas_device->sas_address_parent); | |
f5edbe77 SR |
7601 | list_del(&sas_device->list); |
7602 | kfree(sas_device); | |
7603 | continue; | |
7604 | } | |
f92363d1 SR |
7605 | } |
7606 | ||
7607 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | |
7608 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | |
7609 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | |
7610 | } | |
7611 | } | |
7612 | ||
7613 | /** | |
7614 | * _scsih_probe_devices - probing for devices | |
7615 | * @ioc: per adapter object | |
7616 | * | |
7617 | * Called during initial loading of the driver. | |
7618 | */ | |
7619 | static void | |
7620 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) | |
7621 | { | |
7622 | u16 volume_mapping_flags; | |
7623 | ||
7624 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | |
7625 | return; /* return when IOC doesn't support initiator mode */ | |
7626 | ||
7627 | _scsih_probe_boot_devices(ioc); | |
7628 | ||
7629 | if (ioc->ir_firmware) { | |
7630 | volume_mapping_flags = | |
7631 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | |
7632 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | |
7633 | if (volume_mapping_flags == | |
7634 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | |
7635 | _scsih_probe_raid(ioc); | |
7636 | _scsih_probe_sas(ioc); | |
7637 | } else { | |
7638 | _scsih_probe_sas(ioc); | |
7639 | _scsih_probe_raid(ioc); | |
7640 | } | |
7641 | } else | |
7642 | _scsih_probe_sas(ioc); | |
7643 | } | |
7644 | ||
7645 | /** | |
7646 | * _scsih_scan_start - scsi lld callback for .scan_start | |
7647 | * @shost: SCSI host pointer | |
7648 | * | |
7649 | * The shost has the ability to discover targets on its own instead | |
7650 | * of scanning the entire bus. In our implemention, we will kick off | |
7651 | * firmware discovery. | |
7652 | */ | |
7653 | static void | |
7654 | _scsih_scan_start(struct Scsi_Host *shost) | |
7655 | { | |
7656 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7657 | int rc; | |
7658 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | |
7659 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); | |
7660 | ||
7661 | if (disable_discovery > 0) | |
7662 | return; | |
7663 | ||
7664 | ioc->start_scan = 1; | |
7665 | rc = mpt3sas_port_enable(ioc); | |
7666 | ||
7667 | if (rc != 0) | |
7668 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); | |
7669 | } | |
7670 | ||
7671 | /** | |
7672 | * _scsih_scan_finished - scsi lld callback for .scan_finished | |
7673 | * @shost: SCSI host pointer | |
7674 | * @time: elapsed time of the scan in jiffies | |
7675 | * | |
7676 | * This function will be called periodicallyn until it returns 1 with the | |
7677 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | |
7678 | * we wait for firmware discovery to complete, then return 1. | |
7679 | */ | |
7680 | static int | |
7681 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
7682 | { | |
7683 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7684 | ||
7685 | if (disable_discovery > 0) { | |
7686 | ioc->is_driver_loading = 0; | |
7687 | ioc->wait_for_discovery_to_complete = 0; | |
7688 | return 1; | |
7689 | } | |
7690 | ||
7691 | if (time >= (300 * HZ)) { | |
7692 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
7693 | pr_info(MPT3SAS_FMT | |
7694 | "port enable: FAILED with timeout (timeout=300s)\n", | |
7695 | ioc->name); | |
7696 | ioc->is_driver_loading = 0; | |
7697 | return 1; | |
7698 | } | |
7699 | ||
7700 | if (ioc->start_scan) | |
7701 | return 0; | |
7702 | ||
7703 | if (ioc->start_scan_failed) { | |
7704 | pr_info(MPT3SAS_FMT | |
7705 | "port enable: FAILED with (ioc_status=0x%08x)\n", | |
7706 | ioc->name, ioc->start_scan_failed); | |
7707 | ioc->is_driver_loading = 0; | |
7708 | ioc->wait_for_discovery_to_complete = 0; | |
7709 | ioc->remove_host = 1; | |
7710 | return 1; | |
7711 | } | |
7712 | ||
7713 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); | |
7714 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; | |
7715 | ||
7716 | if (ioc->wait_for_discovery_to_complete) { | |
7717 | ioc->wait_for_discovery_to_complete = 0; | |
7718 | _scsih_probe_devices(ioc); | |
7719 | } | |
7720 | mpt3sas_base_start_watchdog(ioc); | |
7721 | ioc->is_driver_loading = 0; | |
7722 | return 1; | |
7723 | } | |
7724 | ||
7725 | /** | |
7726 | * _scsih_probe - attach and add scsi host | |
7727 | * @pdev: PCI device struct | |
7728 | * @id: pci device id | |
7729 | * | |
7730 | * Returns 0 success, anything else error. | |
7731 | */ | |
7732 | static int | |
7733 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |
7734 | { | |
7735 | struct MPT3SAS_ADAPTER *ioc; | |
7736 | struct Scsi_Host *shost; | |
7737 | ||
7738 | shost = scsi_host_alloc(&scsih_driver_template, | |
7739 | sizeof(struct MPT3SAS_ADAPTER)); | |
7740 | if (!shost) | |
7741 | return -ENODEV; | |
7742 | ||
7743 | /* init local params */ | |
7744 | ioc = shost_priv(shost); | |
7745 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); | |
7746 | INIT_LIST_HEAD(&ioc->list); | |
7747 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); | |
7748 | ioc->shost = shost; | |
7749 | ioc->id = mpt_ids++; | |
7750 | sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id); | |
7751 | ioc->pdev = pdev; | |
7752 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | |
7753 | ioc->tm_cb_idx = tm_cb_idx; | |
7754 | ioc->ctl_cb_idx = ctl_cb_idx; | |
7755 | ioc->base_cb_idx = base_cb_idx; | |
7756 | ioc->port_enable_cb_idx = port_enable_cb_idx; | |
7757 | ioc->transport_cb_idx = transport_cb_idx; | |
7758 | ioc->scsih_cb_idx = scsih_cb_idx; | |
7759 | ioc->config_cb_idx = config_cb_idx; | |
7760 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | |
7761 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | |
7762 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | |
7763 | ioc->logging_level = logging_level; | |
7764 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | |
7765 | /* misc semaphores and spin locks */ | |
7766 | mutex_init(&ioc->reset_in_progress_mutex); | |
7767 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); | |
7768 | spin_lock_init(&ioc->scsi_lookup_lock); | |
7769 | spin_lock_init(&ioc->sas_device_lock); | |
7770 | spin_lock_init(&ioc->sas_node_lock); | |
7771 | spin_lock_init(&ioc->fw_event_lock); | |
7772 | spin_lock_init(&ioc->raid_device_lock); | |
7773 | spin_lock_init(&ioc->diag_trigger_lock); | |
7774 | ||
7775 | INIT_LIST_HEAD(&ioc->sas_device_list); | |
7776 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | |
7777 | INIT_LIST_HEAD(&ioc->sas_expander_list); | |
7778 | INIT_LIST_HEAD(&ioc->fw_event_list); | |
7779 | INIT_LIST_HEAD(&ioc->raid_device_list); | |
7780 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | |
7781 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | |
7782 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); | |
cf9bd21a | 7783 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
f92363d1 SR |
7784 | |
7785 | /* init shost parameters */ | |
7786 | shost->max_cmd_len = 32; | |
7787 | shost->max_lun = max_lun; | |
7788 | shost->transportt = mpt3sas_transport_template; | |
7789 | shost->unique_id = ioc->id; | |
7790 | ||
7791 | if (max_sectors != 0xFFFF) { | |
7792 | if (max_sectors < 64) { | |
7793 | shost->max_sectors = 64; | |
7794 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
7795 | "for max_sectors, range is 64 to 32767. Assigning " | |
7796 | "value of 64.\n", ioc->name, max_sectors); | |
7797 | } else if (max_sectors > 32767) { | |
7798 | shost->max_sectors = 32767; | |
7799 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ | |
7800 | "for max_sectors, range is 64 to 32767. Assigning " | |
7801 | "default value of 32767.\n", ioc->name, | |
7802 | max_sectors); | |
7803 | } else { | |
7804 | shost->max_sectors = max_sectors & 0xFFFE; | |
7805 | pr_info(MPT3SAS_FMT | |
7806 | "The max_sectors value is set to %d\n", | |
7807 | ioc->name, shost->max_sectors); | |
7808 | } | |
7809 | } | |
7810 | ||
f92363d1 SR |
7811 | /* register EEDP capabilities with SCSI layer */ |
7812 | if (prot_mask > 0) | |
7813 | scsi_host_set_prot(shost, prot_mask); | |
7814 | else | |
7815 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | |
7816 | | SHOST_DIF_TYPE2_PROTECTION | |
7817 | | SHOST_DIF_TYPE3_PROTECTION); | |
7818 | ||
7819 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | |
7820 | ||
7821 | /* event thread */ | |
7822 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | |
7823 | "fw_event%d", ioc->id); | |
7824 | ioc->firmware_event_thread = create_singlethread_workqueue( | |
7825 | ioc->firmware_event_name); | |
7826 | if (!ioc->firmware_event_thread) { | |
7827 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7828 | ioc->name, __FILE__, __LINE__, __func__); | |
7829 | goto out_thread_fail; | |
7830 | } | |
7831 | ||
7832 | ioc->is_driver_loading = 1; | |
7833 | if ((mpt3sas_base_attach(ioc))) { | |
7834 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7835 | ioc->name, __FILE__, __LINE__, __func__); | |
7836 | goto out_attach_fail; | |
7837 | } | |
4dc06fd8 RS |
7838 | if ((scsi_add_host(shost, &pdev->dev))) { |
7839 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", | |
7840 | ioc->name, __FILE__, __LINE__, __func__); | |
7841 | list_del(&ioc->list); | |
7842 | goto out_add_shost_fail; | |
7843 | } | |
7844 | ||
f92363d1 SR |
7845 | scsi_scan_host(shost); |
7846 | return 0; | |
4dc06fd8 RS |
7847 | out_add_shost_fail: |
7848 | mpt3sas_base_detach(ioc); | |
f92363d1 SR |
7849 | out_attach_fail: |
7850 | destroy_workqueue(ioc->firmware_event_thread); | |
7851 | out_thread_fail: | |
7852 | list_del(&ioc->list); | |
f92363d1 SR |
7853 | scsi_host_put(shost); |
7854 | return -ENODEV; | |
7855 | } | |
7856 | ||
7857 | #ifdef CONFIG_PM | |
7858 | /** | |
7859 | * _scsih_suspend - power management suspend main entry point | |
7860 | * @pdev: PCI device struct | |
7861 | * @state: PM state change to (usually PCI_D3) | |
7862 | * | |
7863 | * Returns 0 success, anything else error. | |
7864 | */ | |
7865 | static int | |
7866 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) | |
7867 | { | |
7868 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7869 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7870 | pci_power_t device_state; | |
7871 | ||
7872 | mpt3sas_base_stop_watchdog(ioc); | |
7873 | flush_scheduled_work(); | |
7874 | scsi_block_requests(shost); | |
7875 | device_state = pci_choose_state(pdev, state); | |
7876 | pr_info(MPT3SAS_FMT | |
7877 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", | |
7878 | ioc->name, pdev, pci_name(pdev), device_state); | |
7879 | ||
7880 | pci_save_state(pdev); | |
7881 | mpt3sas_base_free_resources(ioc); | |
7882 | pci_set_power_state(pdev, device_state); | |
7883 | return 0; | |
7884 | } | |
7885 | ||
7886 | /** | |
7887 | * _scsih_resume - power management resume main entry point | |
7888 | * @pdev: PCI device struct | |
7889 | * | |
7890 | * Returns 0 success, anything else error. | |
7891 | */ | |
7892 | static int | |
7893 | _scsih_resume(struct pci_dev *pdev) | |
7894 | { | |
7895 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7896 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7897 | pci_power_t device_state = pdev->current_state; | |
7898 | int r; | |
7899 | ||
7900 | pr_info(MPT3SAS_FMT | |
7901 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", | |
7902 | ioc->name, pdev, pci_name(pdev), device_state); | |
7903 | ||
7904 | pci_set_power_state(pdev, PCI_D0); | |
7905 | pci_enable_wake(pdev, PCI_D0, 0); | |
7906 | pci_restore_state(pdev); | |
7907 | ioc->pdev = pdev; | |
7908 | r = mpt3sas_base_map_resources(ioc); | |
7909 | if (r) | |
7910 | return r; | |
7911 | ||
7912 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); | |
7913 | scsi_unblock_requests(shost); | |
7914 | mpt3sas_base_start_watchdog(ioc); | |
7915 | return 0; | |
7916 | } | |
7917 | #endif /* CONFIG_PM */ | |
7918 | ||
7919 | /** | |
7920 | * _scsih_pci_error_detected - Called when a PCI error is detected. | |
7921 | * @pdev: PCI device struct | |
7922 | * @state: PCI channel state | |
7923 | * | |
7924 | * Description: Called when a PCI error is detected. | |
7925 | * | |
7926 | * Return value: | |
7927 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | |
7928 | */ | |
7929 | static pci_ers_result_t | |
7930 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
7931 | { | |
7932 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7933 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7934 | ||
7935 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", | |
7936 | ioc->name, state); | |
7937 | ||
7938 | switch (state) { | |
7939 | case pci_channel_io_normal: | |
7940 | return PCI_ERS_RESULT_CAN_RECOVER; | |
7941 | case pci_channel_io_frozen: | |
7942 | /* Fatal error, prepare for slot reset */ | |
7943 | ioc->pci_error_recovery = 1; | |
7944 | scsi_block_requests(ioc->shost); | |
7945 | mpt3sas_base_stop_watchdog(ioc); | |
7946 | mpt3sas_base_free_resources(ioc); | |
7947 | return PCI_ERS_RESULT_NEED_RESET; | |
7948 | case pci_channel_io_perm_failure: | |
7949 | /* Permanent error, prepare for device removal */ | |
7950 | ioc->pci_error_recovery = 1; | |
7951 | mpt3sas_base_stop_watchdog(ioc); | |
7952 | _scsih_flush_running_cmds(ioc); | |
7953 | return PCI_ERS_RESULT_DISCONNECT; | |
7954 | } | |
7955 | return PCI_ERS_RESULT_NEED_RESET; | |
7956 | } | |
7957 | ||
7958 | /** | |
7959 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. | |
7960 | * @pdev: PCI device struct | |
7961 | * | |
7962 | * Description: This routine is called by the pci error recovery | |
7963 | * code after the PCI slot has been reset, just before we | |
7964 | * should resume normal operations. | |
7965 | */ | |
7966 | static pci_ers_result_t | |
7967 | _scsih_pci_slot_reset(struct pci_dev *pdev) | |
7968 | { | |
7969 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7970 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
7971 | int rc; | |
7972 | ||
7973 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", | |
7974 | ioc->name); | |
7975 | ||
7976 | ioc->pci_error_recovery = 0; | |
7977 | ioc->pdev = pdev; | |
7978 | pci_restore_state(pdev); | |
7979 | rc = mpt3sas_base_map_resources(ioc); | |
7980 | if (rc) | |
7981 | return PCI_ERS_RESULT_DISCONNECT; | |
7982 | ||
7983 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, | |
7984 | FORCE_BIG_HAMMER); | |
7985 | ||
7986 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, | |
7987 | (rc == 0) ? "success" : "failed"); | |
7988 | ||
7989 | if (!rc) | |
7990 | return PCI_ERS_RESULT_RECOVERED; | |
7991 | else | |
7992 | return PCI_ERS_RESULT_DISCONNECT; | |
7993 | } | |
7994 | ||
7995 | /** | |
7996 | * _scsih_pci_resume() - resume normal ops after PCI reset | |
7997 | * @pdev: pointer to PCI device | |
7998 | * | |
7999 | * Called when the error recovery driver tells us that its | |
8000 | * OK to resume normal operation. Use completion to allow | |
8001 | * halted scsi ops to resume. | |
8002 | */ | |
8003 | static void | |
8004 | _scsih_pci_resume(struct pci_dev *pdev) | |
8005 | { | |
8006 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8007 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8008 | ||
8009 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); | |
8010 | ||
8011 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8012 | mpt3sas_base_start_watchdog(ioc); | |
8013 | scsi_unblock_requests(ioc->shost); | |
8014 | } | |
8015 | ||
8016 | /** | |
8017 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers | |
8018 | * @pdev: pointer to PCI device | |
8019 | */ | |
8020 | static pci_ers_result_t | |
8021 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) | |
8022 | { | |
8023 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8024 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); | |
8025 | ||
8026 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", | |
8027 | ioc->name); | |
8028 | ||
8029 | /* TODO - dump whatever for debugging purposes */ | |
8030 | ||
8031 | /* Request a slot reset. */ | |
8032 | return PCI_ERS_RESULT_NEED_RESET; | |
8033 | } | |
8034 | ||
8035 | /* raid transport support */ | |
8036 | static struct raid_function_template mpt3sas_raid_functions = { | |
8037 | .cookie = &scsih_driver_template, | |
8038 | .is_raid = _scsih_is_raid, | |
8039 | .get_resync = _scsih_get_resync, | |
8040 | .get_state = _scsih_get_state, | |
8041 | }; | |
8042 | ||
8043 | static struct pci_error_handlers _scsih_err_handler = { | |
8044 | .error_detected = _scsih_pci_error_detected, | |
8045 | .mmio_enabled = _scsih_pci_mmio_enabled, | |
8046 | .slot_reset = _scsih_pci_slot_reset, | |
8047 | .resume = _scsih_pci_resume, | |
8048 | }; | |
8049 | ||
8050 | static struct pci_driver scsih_driver = { | |
8051 | .name = MPT3SAS_DRIVER_NAME, | |
8052 | .id_table = scsih_pci_table, | |
8053 | .probe = _scsih_probe, | |
6f039790 | 8054 | .remove = _scsih_remove, |
f92363d1 SR |
8055 | .shutdown = _scsih_shutdown, |
8056 | .err_handler = &_scsih_err_handler, | |
8057 | #ifdef CONFIG_PM | |
8058 | .suspend = _scsih_suspend, | |
8059 | .resume = _scsih_resume, | |
8060 | #endif | |
8061 | }; | |
8062 | ||
8063 | ||
8064 | /** | |
8065 | * _scsih_init - main entry point for this driver. | |
8066 | * | |
8067 | * Returns 0 success, anything else error. | |
8068 | */ | |
8069 | static int __init | |
8070 | _scsih_init(void) | |
8071 | { | |
8072 | int error; | |
8073 | ||
8074 | mpt_ids = 0; | |
8075 | ||
8076 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, | |
8077 | MPT3SAS_DRIVER_VERSION); | |
8078 | ||
8079 | mpt3sas_transport_template = | |
8080 | sas_attach_transport(&mpt3sas_transport_functions); | |
8081 | if (!mpt3sas_transport_template) | |
8082 | return -ENODEV; | |
8083 | ||
8084 | /* raid transport support */ | |
8085 | mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions); | |
8086 | if (!mpt3sas_raid_template) { | |
8087 | sas_release_transport(mpt3sas_transport_template); | |
8088 | return -ENODEV; | |
8089 | } | |
8090 | ||
8091 | mpt3sas_base_initialize_callback_handler(); | |
8092 | ||
8093 | /* queuecommand callback hander */ | |
8094 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); | |
8095 | ||
8096 | /* task managment callback handler */ | |
8097 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); | |
8098 | ||
8099 | /* base internal commands callback handler */ | |
8100 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); | |
8101 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( | |
8102 | mpt3sas_port_enable_done); | |
8103 | ||
8104 | /* transport internal commands callback handler */ | |
8105 | transport_cb_idx = mpt3sas_base_register_callback_handler( | |
8106 | mpt3sas_transport_done); | |
8107 | ||
8108 | /* scsih internal commands callback handler */ | |
8109 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); | |
8110 | ||
8111 | /* configuration page API internal commands callback handler */ | |
8112 | config_cb_idx = mpt3sas_base_register_callback_handler( | |
8113 | mpt3sas_config_done); | |
8114 | ||
8115 | /* ctl module callback handler */ | |
8116 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); | |
8117 | ||
8118 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( | |
8119 | _scsih_tm_tr_complete); | |
8120 | ||
8121 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( | |
8122 | _scsih_tm_volume_tr_complete); | |
8123 | ||
8124 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( | |
8125 | _scsih_sas_control_complete); | |
8126 | ||
8127 | mpt3sas_ctl_init(); | |
8128 | ||
8129 | error = pci_register_driver(&scsih_driver); | |
8130 | if (error) { | |
8131 | /* raid transport support */ | |
8132 | raid_class_release(mpt3sas_raid_template); | |
8133 | sas_release_transport(mpt3sas_transport_template); | |
8134 | } | |
8135 | ||
8136 | return error; | |
8137 | } | |
8138 | ||
8139 | /** | |
8140 | * _scsih_exit - exit point for this driver (when it is a module). | |
8141 | * | |
8142 | * Returns 0 success, anything else error. | |
8143 | */ | |
8144 | static void __exit | |
8145 | _scsih_exit(void) | |
8146 | { | |
8147 | pr_info("mpt3sas version %s unloading\n", | |
8148 | MPT3SAS_DRIVER_VERSION); | |
8149 | ||
8150 | mpt3sas_ctl_exit(); | |
8151 | ||
8152 | pci_unregister_driver(&scsih_driver); | |
8153 | ||
8154 | ||
8155 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); | |
8156 | mpt3sas_base_release_callback_handler(tm_cb_idx); | |
8157 | mpt3sas_base_release_callback_handler(base_cb_idx); | |
8158 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); | |
8159 | mpt3sas_base_release_callback_handler(transport_cb_idx); | |
8160 | mpt3sas_base_release_callback_handler(scsih_cb_idx); | |
8161 | mpt3sas_base_release_callback_handler(config_cb_idx); | |
8162 | mpt3sas_base_release_callback_handler(ctl_cb_idx); | |
8163 | ||
8164 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); | |
8165 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); | |
8166 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); | |
8167 | ||
8168 | /* raid transport support */ | |
8169 | raid_class_release(mpt3sas_raid_template); | |
8170 | sas_release_transport(mpt3sas_transport_template); | |
8171 | } | |
8172 | ||
8173 | module_init(_scsih_init); | |
8174 | module_exit(_scsih_exit); |