diff options
author | Sreekanth Reddy <sreekanth.reddy@avagotech.com> | 2015-11-11 07:00:21 -0500 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2015-11-11 18:27:24 -0500 |
commit | 09ec55ed74ebb8a61859609011d28ab0bcb15e08 (patch) | |
tree | b5878777ace8a6b5a57ed8fb47412d70dbca2bc0 | |
parent | 78f97c8f612d0e7d7d08d741549e89e8c951920a (diff) |
mpt2sas: Remove .c and .h files from mpt2sas driver
Remove .c and .h files which are no longer needed from mpt2sas
driver. We are reusing this code from mpt3sas.
Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_base.c | 4899 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_base.h | 1235 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_config.c | 1527 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_ctl.c | 3101 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_ctl.h | 419 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_debug.h | 182 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_scsih.c | 8855 | ||||
-rw-r--r-- | drivers/scsi/mpt2sas/mpt2sas_transport.c | 2173 |
8 files changed, 0 insertions, 22391 deletions
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c deleted file mode 100644 index c167911221e9..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_base.c +++ /dev/null | |||
@@ -1,4899 +0,0 @@ | |||
1 | /* | ||
2 | * This is the Fusion MPT base driver providing common API layer interface | ||
3 | * for access to MPT (Message Passing Technology) firmware. | ||
4 | * | ||
5 | * This code is based on drivers/scsi/mpt2sas/mpt2_base.c | ||
6 | * Copyright (C) 2007-2014 LSI Corporation | ||
7 | * Copyright (C) 20013-2014 Avago Technologies | ||
8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version 2 | ||
13 | * of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * NO WARRANTY | ||
21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
25 | * solely responsible for determining the appropriateness of using and | ||
26 | * distributing the Program and assumes all risks associated with its | ||
27 | * exercise of rights under this Agreement, including but not limited to | ||
28 | * the risks and costs of program errors, damage to or loss of data, | ||
29 | * programs or equipment, and unavailability or interruption of operations. | ||
30 | |||
31 | * DISCLAIMER OF LIABILITY | ||
32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
39 | |||
40 | * You should have received a copy of the GNU General Public License | ||
41 | * along with this program; if not, write to the Free Software | ||
42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
43 | * USA. | ||
44 | */ | ||
45 | |||
46 | #include <linux/kernel.h> | ||
47 | #include <linux/module.h> | ||
48 | #include <linux/errno.h> | ||
49 | #include <linux/init.h> | ||
50 | #include <linux/slab.h> | ||
51 | #include <linux/types.h> | ||
52 | #include <linux/pci.h> | ||
53 | #include <linux/kdev_t.h> | ||
54 | #include <linux/blkdev.h> | ||
55 | #include <linux/delay.h> | ||
56 | #include <linux/interrupt.h> | ||
57 | #include <linux/dma-mapping.h> | ||
58 | #include <linux/sort.h> | ||
59 | #include <linux/io.h> | ||
60 | #include <linux/time.h> | ||
61 | #include <linux/kthread.h> | ||
62 | #include <linux/aer.h> | ||
63 | |||
64 | #include "mpt2sas_base.h" | ||
65 | |||
66 | static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS]; | ||
67 | |||
68 | #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */ | ||
69 | |||
70 | #define MAX_HBA_QUEUE_DEPTH 30000 | ||
71 | #define MAX_CHAIN_DEPTH 100000 | ||
72 | static int max_queue_depth = -1; | ||
73 | module_param(max_queue_depth, int, 0); | ||
74 | MODULE_PARM_DESC(max_queue_depth, " max controller queue depth "); | ||
75 | |||
76 | static int max_sgl_entries = -1; | ||
77 | module_param(max_sgl_entries, int, 0); | ||
78 | MODULE_PARM_DESC(max_sgl_entries, " max sg entries "); | ||
79 | |||
80 | static int msix_disable = -1; | ||
81 | module_param(msix_disable, int, 0); | ||
82 | MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)"); | ||
83 | |||
84 | static int max_msix_vectors = -1; | ||
85 | module_param(max_msix_vectors, int, 0); | ||
86 | MODULE_PARM_DESC(max_msix_vectors, " max msix vectors "); | ||
87 | |||
88 | static int mpt2sas_fwfault_debug; | ||
89 | MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault " | ||
90 | "and halt firmware - (default=0)"); | ||
91 | |||
92 | static int disable_discovery = -1; | ||
93 | module_param(disable_discovery, int, 0); | ||
94 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | ||
95 | |||
96 | static int | ||
97 | _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag); | ||
98 | |||
99 | static int | ||
100 | _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag); | ||
101 | |||
102 | /** | ||
103 | * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug. | ||
104 | * | ||
105 | */ | ||
106 | static int | ||
107 | _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp) | ||
108 | { | ||
109 | int ret = param_set_int(val, kp); | ||
110 | struct MPT2SAS_ADAPTER *ioc; | ||
111 | |||
112 | if (ret) | ||
113 | return ret; | ||
114 | |||
115 | /* global ioc spinlock to protect controller list on list operations */ | ||
116 | printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug); | ||
117 | spin_lock(&gioc_lock); | ||
118 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) | ||
119 | ioc->fwfault_debug = mpt2sas_fwfault_debug; | ||
120 | spin_unlock(&gioc_lock); | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug, | ||
125 | param_get_int, &mpt2sas_fwfault_debug, 0644); | ||
126 | |||
127 | /** | ||
128 | * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc | ||
129 | * @arg: input argument, used to derive ioc | ||
130 | * | ||
131 | * Return 0 if controller is removed from pci subsystem. | ||
132 | * Return -1 for other case. | ||
133 | */ | ||
134 | static int mpt2sas_remove_dead_ioc_func(void *arg) | ||
135 | { | ||
136 | struct MPT2SAS_ADAPTER *ioc = (struct MPT2SAS_ADAPTER *)arg; | ||
137 | struct pci_dev *pdev; | ||
138 | |||
139 | if ((ioc == NULL)) | ||
140 | return -1; | ||
141 | |||
142 | pdev = ioc->pdev; | ||
143 | if ((pdev == NULL)) | ||
144 | return -1; | ||
145 | pci_stop_and_remove_bus_device_locked(pdev); | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | |||
150 | /** | ||
151 | * _base_fault_reset_work - workq handling ioc fault conditions | ||
152 | * @work: input argument, used to derive ioc | ||
153 | * Context: sleep. | ||
154 | * | ||
155 | * Return nothing. | ||
156 | */ | ||
157 | static void | ||
158 | _base_fault_reset_work(struct work_struct *work) | ||
159 | { | ||
160 | struct MPT2SAS_ADAPTER *ioc = | ||
161 | container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work); | ||
162 | unsigned long flags; | ||
163 | u32 doorbell; | ||
164 | int rc; | ||
165 | struct task_struct *p; | ||
166 | |||
167 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); | ||
168 | if (ioc->shost_recovery || ioc->pci_error_recovery) | ||
169 | goto rearm_timer; | ||
170 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); | ||
171 | |||
172 | doorbell = mpt2sas_base_get_iocstate(ioc, 0); | ||
173 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) { | ||
174 | printk(MPT2SAS_INFO_FMT "%s : SAS host is non-operational !!!!\n", | ||
175 | ioc->name, __func__); | ||
176 | |||
177 | /* It may be possible that EEH recovery can resolve some of | ||
178 | * pci bus failure issues rather removing the dead ioc function | ||
179 | * by considering controller is in a non-operational state. So | ||
180 | * here priority is given to the EEH recovery. If it doesn't | ||
181 | * not resolve this issue, mpt2sas driver will consider this | ||
182 | * controller to non-operational state and remove the dead ioc | ||
183 | * function. | ||
184 | */ | ||
185 | if (ioc->non_operational_loop++ < 5) { | ||
186 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, | ||
187 | flags); | ||
188 | goto rearm_timer; | ||
189 | } | ||
190 | |||
191 | /* | ||
192 | * Call _scsih_flush_pending_cmds callback so that we flush all | ||
193 | * pending commands back to OS. This call is required to aovid | ||
194 | * deadlock at block layer. Dead IOC will fail to do diag reset, | ||
195 | * and this call is safe since dead ioc will never return any | ||
196 | * command back from HW. | ||
197 | */ | ||
198 | ioc->schedule_dead_ioc_flush_running_cmds(ioc); | ||
199 | /* | ||
200 | * Set remove_host flag early since kernel thread will | ||
201 | * take some time to execute. | ||
202 | */ | ||
203 | ioc->remove_host = 1; | ||
204 | /*Remove the Dead Host */ | ||
205 | p = kthread_run(mpt2sas_remove_dead_ioc_func, ioc, | ||
206 | "mpt2sas_dead_ioc_%d", ioc->id); | ||
207 | if (IS_ERR(p)) { | ||
208 | printk(MPT2SAS_ERR_FMT | ||
209 | "%s: Running mpt2sas_dead_ioc thread failed !!!!\n", | ||
210 | ioc->name, __func__); | ||
211 | } else { | ||
212 | printk(MPT2SAS_ERR_FMT | ||
213 | "%s: Running mpt2sas_dead_ioc thread success !!!!\n", | ||
214 | ioc->name, __func__); | ||
215 | } | ||
216 | |||
217 | return; /* don't rearm timer */ | ||
218 | } | ||
219 | |||
220 | ioc->non_operational_loop = 0; | ||
221 | |||
222 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | ||
223 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
224 | FORCE_BIG_HAMMER); | ||
225 | printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name, | ||
226 | __func__, (rc == 0) ? "success" : "failed"); | ||
227 | doorbell = mpt2sas_base_get_iocstate(ioc, 0); | ||
228 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) | ||
229 | mpt2sas_base_fault_info(ioc, doorbell & | ||
230 | MPI2_DOORBELL_DATA_MASK); | ||
231 | } | ||
232 | |||
233 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); | ||
234 | rearm_timer: | ||
235 | if (ioc->fault_reset_work_q) | ||
236 | queue_delayed_work(ioc->fault_reset_work_q, | ||
237 | &ioc->fault_reset_work, | ||
238 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); | ||
239 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * mpt2sas_base_start_watchdog - start the fault_reset_work_q | ||
244 | * @ioc: per adapter object | ||
245 | * Context: sleep. | ||
246 | * | ||
247 | * Return nothing. | ||
248 | */ | ||
249 | void | ||
250 | mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc) | ||
251 | { | ||
252 | unsigned long flags; | ||
253 | |||
254 | if (ioc->fault_reset_work_q) | ||
255 | return; | ||
256 | |||
257 | /* initialize fault polling */ | ||
258 | INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work); | ||
259 | snprintf(ioc->fault_reset_work_q_name, | ||
260 | sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id); | ||
261 | ioc->fault_reset_work_q = | ||
262 | create_singlethread_workqueue(ioc->fault_reset_work_q_name); | ||
263 | if (!ioc->fault_reset_work_q) { | ||
264 | printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n", | ||
265 | ioc->name, __func__, __LINE__); | ||
266 | return; | ||
267 | } | ||
268 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); | ||
269 | if (ioc->fault_reset_work_q) | ||
270 | queue_delayed_work(ioc->fault_reset_work_q, | ||
271 | &ioc->fault_reset_work, | ||
272 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); | ||
273 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); | ||
274 | } | ||
275 | |||
276 | /** | ||
277 | * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q | ||
278 | * @ioc: per adapter object | ||
279 | * Context: sleep. | ||
280 | * | ||
281 | * Return nothing. | ||
282 | */ | ||
283 | void | ||
284 | mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc) | ||
285 | { | ||
286 | unsigned long flags; | ||
287 | struct workqueue_struct *wq; | ||
288 | |||
289 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); | ||
290 | wq = ioc->fault_reset_work_q; | ||
291 | ioc->fault_reset_work_q = NULL; | ||
292 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); | ||
293 | if (wq) { | ||
294 | if (!cancel_delayed_work_sync(&ioc->fault_reset_work)) | ||
295 | flush_workqueue(wq); | ||
296 | destroy_workqueue(wq); | ||
297 | } | ||
298 | } | ||
299 | |||
300 | /** | ||
301 | * mpt2sas_base_fault_info - verbose translation of firmware FAULT code | ||
302 | * @ioc: per adapter object | ||
303 | * @fault_code: fault code | ||
304 | * | ||
305 | * Return nothing. | ||
306 | */ | ||
307 | void | ||
308 | mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code) | ||
309 | { | ||
310 | printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n", | ||
311 | ioc->name, fault_code); | ||
312 | } | ||
313 | |||
314 | /** | ||
315 | * mpt2sas_halt_firmware - halt's mpt controller firmware | ||
316 | * @ioc: per adapter object | ||
317 | * | ||
318 | * For debugging timeout related issues. Writing 0xCOFFEE00 | ||
319 | * to the doorbell register will halt controller firmware. With | ||
320 | * the purpose to stop both driver and firmware, the enduser can | ||
321 | * obtain a ring buffer from controller UART. | ||
322 | */ | ||
323 | void | ||
324 | mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc) | ||
325 | { | ||
326 | u32 doorbell; | ||
327 | |||
328 | if (!ioc->fwfault_debug) | ||
329 | return; | ||
330 | |||
331 | dump_stack(); | ||
332 | |||
333 | doorbell = readl(&ioc->chip->Doorbell); | ||
334 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) | ||
335 | mpt2sas_base_fault_info(ioc , doorbell); | ||
336 | else { | ||
337 | writel(0xC0FFEE00, &ioc->chip->Doorbell); | ||
338 | printk(MPT2SAS_ERR_FMT "Firmware is halted due to command " | ||
339 | "timeout\n", ioc->name); | ||
340 | } | ||
341 | |||
342 | panic("panic in %s\n", __func__); | ||
343 | } | ||
344 | |||
345 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
346 | /** | ||
347 | * _base_sas_ioc_info - verbose translation of the ioc status | ||
348 | * @ioc: per adapter object | ||
349 | * @mpi_reply: reply mf payload returned from firmware | ||
350 | * @request_hdr: request mf | ||
351 | * | ||
352 | * Return nothing. | ||
353 | */ | ||
354 | static void | ||
355 | _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply, | ||
356 | MPI2RequestHeader_t *request_hdr) | ||
357 | { | ||
358 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | ||
359 | MPI2_IOCSTATUS_MASK; | ||
360 | char *desc = NULL; | ||
361 | u16 frame_sz; | ||
362 | char *func_str = NULL; | ||
363 | |||
364 | /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */ | ||
365 | if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || | ||
366 | request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || | ||
367 | request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION) | ||
368 | return; | ||
369 | |||
370 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) | ||
371 | return; | ||
372 | |||
373 | switch (ioc_status) { | ||
374 | |||
375 | /**************************************************************************** | ||
376 | * Common IOCStatus values for all replies | ||
377 | ****************************************************************************/ | ||
378 | |||
379 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | ||
380 | desc = "invalid function"; | ||
381 | break; | ||
382 | case MPI2_IOCSTATUS_BUSY: | ||
383 | desc = "busy"; | ||
384 | break; | ||
385 | case MPI2_IOCSTATUS_INVALID_SGL: | ||
386 | desc = "invalid sgl"; | ||
387 | break; | ||
388 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | ||
389 | desc = "internal error"; | ||
390 | break; | ||
391 | case MPI2_IOCSTATUS_INVALID_VPID: | ||
392 | desc = "invalid vpid"; | ||
393 | break; | ||
394 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | ||
395 | desc = "insufficient resources"; | ||
396 | break; | ||
397 | case MPI2_IOCSTATUS_INVALID_FIELD: | ||
398 | desc = "invalid field"; | ||
399 | break; | ||
400 | case MPI2_IOCSTATUS_INVALID_STATE: | ||
401 | desc = "invalid state"; | ||
402 | break; | ||
403 | case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED: | ||
404 | desc = "op state not supported"; | ||
405 | break; | ||
406 | |||
407 | /**************************************************************************** | ||
408 | * Config IOCStatus values | ||
409 | ****************************************************************************/ | ||
410 | |||
411 | case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION: | ||
412 | desc = "config invalid action"; | ||
413 | break; | ||
414 | case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE: | ||
415 | desc = "config invalid type"; | ||
416 | break; | ||
417 | case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE: | ||
418 | desc = "config invalid page"; | ||
419 | break; | ||
420 | case MPI2_IOCSTATUS_CONFIG_INVALID_DATA: | ||
421 | desc = "config invalid data"; | ||
422 | break; | ||
423 | case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS: | ||
424 | desc = "config no defaults"; | ||
425 | break; | ||
426 | case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT: | ||
427 | desc = "config cant commit"; | ||
428 | break; | ||
429 | |||
430 | /**************************************************************************** | ||
431 | * SCSI IO Reply | ||
432 | ****************************************************************************/ | ||
433 | |||
434 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | ||
435 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | ||
436 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | ||
437 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | ||
438 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | ||
439 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | ||
440 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | ||
441 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | ||
442 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | ||
443 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | ||
444 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | ||
445 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | ||
446 | break; | ||
447 | |||
448 | /**************************************************************************** | ||
449 | * For use by SCSI Initiator and SCSI Target end-to-end data protection | ||
450 | ****************************************************************************/ | ||
451 | |||
452 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | ||
453 | desc = "eedp guard error"; | ||
454 | break; | ||
455 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | ||
456 | desc = "eedp ref tag error"; | ||
457 | break; | ||
458 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | ||
459 | desc = "eedp app tag error"; | ||
460 | break; | ||
461 | |||
462 | /**************************************************************************** | ||
463 | * SCSI Target values | ||
464 | ****************************************************************************/ | ||
465 | |||
466 | case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX: | ||
467 | desc = "target invalid io index"; | ||
468 | break; | ||
469 | case MPI2_IOCSTATUS_TARGET_ABORTED: | ||
470 | desc = "target aborted"; | ||
471 | break; | ||
472 | case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: | ||
473 | desc = "target no conn retryable"; | ||
474 | break; | ||
475 | case MPI2_IOCSTATUS_TARGET_NO_CONNECTION: | ||
476 | desc = "target no connection"; | ||
477 | break; | ||
478 | case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: | ||
479 | desc = "target xfer count mismatch"; | ||
480 | break; | ||
481 | case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: | ||
482 | desc = "target data offset error"; | ||
483 | break; | ||
484 | case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: | ||
485 | desc = "target too much write data"; | ||
486 | break; | ||
487 | case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT: | ||
488 | desc = "target iu too short"; | ||
489 | break; | ||
490 | case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: | ||
491 | desc = "target ack nak timeout"; | ||
492 | break; | ||
493 | case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED: | ||
494 | desc = "target nak received"; | ||
495 | break; | ||
496 | |||
497 | /**************************************************************************** | ||
498 | * Serial Attached SCSI values | ||
499 | ****************************************************************************/ | ||
500 | |||
501 | case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED: | ||
502 | desc = "smp request failed"; | ||
503 | break; | ||
504 | case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN: | ||
505 | desc = "smp data overrun"; | ||
506 | break; | ||
507 | |||
508 | /**************************************************************************** | ||
509 | * Diagnostic Buffer Post / Diagnostic Release values | ||
510 | ****************************************************************************/ | ||
511 | |||
512 | case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED: | ||
513 | desc = "diagnostic released"; | ||
514 | break; | ||
515 | default: | ||
516 | break; | ||
517 | } | ||
518 | |||
519 | if (!desc) | ||
520 | return; | ||
521 | |||
522 | switch (request_hdr->Function) { | ||
523 | case MPI2_FUNCTION_CONFIG: | ||
524 | frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size; | ||
525 | func_str = "config_page"; | ||
526 | break; | ||
527 | case MPI2_FUNCTION_SCSI_TASK_MGMT: | ||
528 | frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t); | ||
529 | func_str = "task_mgmt"; | ||
530 | break; | ||
531 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: | ||
532 | frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t); | ||
533 | func_str = "sas_iounit_ctl"; | ||
534 | break; | ||
535 | case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR: | ||
536 | frame_sz = sizeof(Mpi2SepRequest_t); | ||
537 | func_str = "enclosure"; | ||
538 | break; | ||
539 | case MPI2_FUNCTION_IOC_INIT: | ||
540 | frame_sz = sizeof(Mpi2IOCInitRequest_t); | ||
541 | func_str = "ioc_init"; | ||
542 | break; | ||
543 | case MPI2_FUNCTION_PORT_ENABLE: | ||
544 | frame_sz = sizeof(Mpi2PortEnableRequest_t); | ||
545 | func_str = "port_enable"; | ||
546 | break; | ||
547 | case MPI2_FUNCTION_SMP_PASSTHROUGH: | ||
548 | frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size; | ||
549 | func_str = "smp_passthru"; | ||
550 | break; | ||
551 | default: | ||
552 | frame_sz = 32; | ||
553 | func_str = "unknown"; | ||
554 | break; | ||
555 | } | ||
556 | |||
557 | printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p)," | ||
558 | " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str); | ||
559 | |||
560 | _debug_dump_mf(request_hdr, frame_sz/4); | ||
561 | } | ||
562 | |||
563 | /** | ||
564 | * _base_display_event_data - verbose translation of firmware asyn events | ||
565 | * @ioc: per adapter object | ||
566 | * @mpi_reply: reply mf payload returned from firmware | ||
567 | * | ||
568 | * Return nothing. | ||
569 | */ | ||
570 | static void | ||
571 | _base_display_event_data(struct MPT2SAS_ADAPTER *ioc, | ||
572 | Mpi2EventNotificationReply_t *mpi_reply) | ||
573 | { | ||
574 | char *desc = NULL; | ||
575 | u16 event; | ||
576 | |||
577 | if (!(ioc->logging_level & MPT_DEBUG_EVENTS)) | ||
578 | return; | ||
579 | |||
580 | event = le16_to_cpu(mpi_reply->Event); | ||
581 | |||
582 | switch (event) { | ||
583 | case MPI2_EVENT_LOG_DATA: | ||
584 | desc = "Log Data"; | ||
585 | break; | ||
586 | case MPI2_EVENT_STATE_CHANGE: | ||
587 | desc = "Status Change"; | ||
588 | break; | ||
589 | case MPI2_EVENT_HARD_RESET_RECEIVED: | ||
590 | desc = "Hard Reset Received"; | ||
591 | break; | ||
592 | case MPI2_EVENT_EVENT_CHANGE: | ||
593 | desc = "Event Change"; | ||
594 | break; | ||
595 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | ||
596 | desc = "Device Status Change"; | ||
597 | break; | ||
598 | case MPI2_EVENT_IR_OPERATION_STATUS: | ||
599 | if (!ioc->hide_ir_msg) | ||
600 | desc = "IR Operation Status"; | ||
601 | break; | ||
602 | case MPI2_EVENT_SAS_DISCOVERY: | ||
603 | { | ||
604 | Mpi2EventDataSasDiscovery_t *event_data = | ||
605 | (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData; | ||
606 | printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name, | ||
607 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | ||
608 | "start" : "stop"); | ||
609 | if (event_data->DiscoveryStatus) | ||
610 | printk("discovery_status(0x%08x)", | ||
611 | le32_to_cpu(event_data->DiscoveryStatus)); | ||
612 | printk("\n"); | ||
613 | return; | ||
614 | } | ||
615 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | ||
616 | desc = "SAS Broadcast Primitive"; | ||
617 | break; | ||
618 | case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE: | ||
619 | desc = "SAS Init Device Status Change"; | ||
620 | break; | ||
621 | case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW: | ||
622 | desc = "SAS Init Table Overflow"; | ||
623 | break; | ||
624 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | ||
625 | desc = "SAS Topology Change List"; | ||
626 | break; | ||
627 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | ||
628 | desc = "SAS Enclosure Device Status Change"; | ||
629 | break; | ||
630 | case MPI2_EVENT_IR_VOLUME: | ||
631 | if (!ioc->hide_ir_msg) | ||
632 | desc = "IR Volume"; | ||
633 | break; | ||
634 | case MPI2_EVENT_IR_PHYSICAL_DISK: | ||
635 | if (!ioc->hide_ir_msg) | ||
636 | desc = "IR Physical Disk"; | ||
637 | break; | ||
638 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | ||
639 | if (!ioc->hide_ir_msg) | ||
640 | desc = "IR Configuration Change List"; | ||
641 | break; | ||
642 | case MPI2_EVENT_LOG_ENTRY_ADDED: | ||
643 | if (!ioc->hide_ir_msg) | ||
644 | desc = "Log Entry Added"; | ||
645 | break; | ||
646 | case MPI2_EVENT_TEMP_THRESHOLD: | ||
647 | desc = "Temperature Threshold"; | ||
648 | break; | ||
649 | } | ||
650 | |||
651 | if (!desc) | ||
652 | return; | ||
653 | |||
654 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc); | ||
655 | } | ||
656 | #endif | ||
657 | |||
658 | /** | ||
659 | * _base_sas_log_info - verbose translation of firmware log info | ||
660 | * @ioc: per adapter object | ||
661 | * @log_info: log info | ||
662 | * | ||
663 | * Return nothing. | ||
664 | */ | ||
665 | static void | ||
666 | _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info) | ||
667 | { | ||
668 | union loginfo_type { | ||
669 | u32 loginfo; | ||
670 | struct { | ||
671 | u32 subcode:16; | ||
672 | u32 code:8; | ||
673 | u32 originator:4; | ||
674 | u32 bus_type:4; | ||
675 | } dw; | ||
676 | }; | ||
677 | union loginfo_type sas_loginfo; | ||
678 | char *originator_str = NULL; | ||
679 | |||
680 | sas_loginfo.loginfo = log_info; | ||
681 | if (sas_loginfo.dw.bus_type != 3 /*SAS*/) | ||
682 | return; | ||
683 | |||
684 | /* each nexus loss loginfo */ | ||
685 | if (log_info == 0x31170000) | ||
686 | return; | ||
687 | |||
688 | /* eat the loginfos associated with task aborts */ | ||
689 | if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info == | ||
690 | 0x31140000 || log_info == 0x31130000)) | ||
691 | return; | ||
692 | |||
693 | switch (sas_loginfo.dw.originator) { | ||
694 | case 0: | ||
695 | originator_str = "IOP"; | ||
696 | break; | ||
697 | case 1: | ||
698 | originator_str = "PL"; | ||
699 | break; | ||
700 | case 2: | ||
701 | if (!ioc->hide_ir_msg) | ||
702 | originator_str = "IR"; | ||
703 | else | ||
704 | originator_str = "WarpDrive"; | ||
705 | break; | ||
706 | } | ||
707 | |||
708 | printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), " | ||
709 | "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info, | ||
710 | originator_str, sas_loginfo.dw.code, | ||
711 | sas_loginfo.dw.subcode); | ||
712 | } | ||
713 | |||
714 | /** | ||
715 | * _base_display_reply_info - | ||
716 | * @ioc: per adapter object | ||
717 | * @smid: system request message index | ||
718 | * @msix_index: MSIX table index supplied by the OS | ||
719 | * @reply: reply message frame(lower 32bit addr) | ||
720 | * | ||
721 | * Return nothing. | ||
722 | */ | ||
723 | static void | ||
724 | _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
725 | u32 reply) | ||
726 | { | ||
727 | MPI2DefaultReply_t *mpi_reply; | ||
728 | u16 ioc_status; | ||
729 | |||
730 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
731 | if (unlikely(!mpi_reply)) { | ||
732 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", | ||
733 | ioc->name, __FILE__, __LINE__, __func__); | ||
734 | return; | ||
735 | } | ||
736 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | ||
737 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
738 | if ((ioc_status & MPI2_IOCSTATUS_MASK) && | ||
739 | (ioc->logging_level & MPT_DEBUG_REPLY)) { | ||
740 | _base_sas_ioc_info(ioc , mpi_reply, | ||
741 | mpt2sas_base_get_msg_frame(ioc, smid)); | ||
742 | } | ||
743 | #endif | ||
744 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | ||
745 | _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
746 | } | ||
747 | |||
748 | /** | ||
749 | * mpt2sas_base_done - base internal command completion routine | ||
750 | * @ioc: per adapter object | ||
751 | * @smid: system request message index | ||
752 | * @msix_index: MSIX table index supplied by the OS | ||
753 | * @reply: reply message frame(lower 32bit addr) | ||
754 | * | ||
755 | * Return 1 meaning mf should be freed from _base_interrupt | ||
756 | * 0 means the mf is freed from this function. | ||
757 | */ | ||
758 | u8 | ||
759 | mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
760 | u32 reply) | ||
761 | { | ||
762 | MPI2DefaultReply_t *mpi_reply; | ||
763 | |||
764 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
765 | if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK) | ||
766 | return 1; | ||
767 | |||
768 | if (ioc->base_cmds.status == MPT2_CMD_NOT_USED) | ||
769 | return 1; | ||
770 | |||
771 | ioc->base_cmds.status |= MPT2_CMD_COMPLETE; | ||
772 | if (mpi_reply) { | ||
773 | ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
774 | memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | ||
775 | } | ||
776 | ioc->base_cmds.status &= ~MPT2_CMD_PENDING; | ||
777 | |||
778 | complete(&ioc->base_cmds.done); | ||
779 | return 1; | ||
780 | } | ||
781 | |||
782 | /** | ||
783 | * _base_async_event - main callback handler for firmware asyn events | ||
784 | * @ioc: per adapter object | ||
785 | * @msix_index: MSIX table index supplied by the OS | ||
786 | * @reply: reply message frame(lower 32bit addr) | ||
787 | * | ||
788 | * Returns void. | ||
789 | */ | ||
790 | static void | ||
791 | _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply) | ||
792 | { | ||
793 | Mpi2EventNotificationReply_t *mpi_reply; | ||
794 | Mpi2EventAckRequest_t *ack_request; | ||
795 | u16 smid; | ||
796 | |||
797 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
798 | if (!mpi_reply) | ||
799 | return; | ||
800 | if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION) | ||
801 | return; | ||
802 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
803 | _base_display_event_data(ioc, mpi_reply); | ||
804 | #endif | ||
805 | if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED)) | ||
806 | goto out; | ||
807 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); | ||
808 | if (!smid) { | ||
809 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
810 | ioc->name, __func__); | ||
811 | goto out; | ||
812 | } | ||
813 | |||
814 | ack_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
815 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); | ||
816 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; | ||
817 | ack_request->Event = mpi_reply->Event; | ||
818 | ack_request->EventContext = mpi_reply->EventContext; | ||
819 | ack_request->VF_ID = 0; /* TODO */ | ||
820 | ack_request->VP_ID = 0; | ||
821 | mpt2sas_base_put_smid_default(ioc, smid); | ||
822 | |||
823 | out: | ||
824 | |||
825 | /* scsih callback handler */ | ||
826 | mpt2sas_scsih_event_callback(ioc, msix_index, reply); | ||
827 | |||
828 | /* ctl callback handler */ | ||
829 | mpt2sas_ctl_event_callback(ioc, msix_index, reply); | ||
830 | |||
831 | return; | ||
832 | } | ||
833 | |||
834 | /** | ||
835 | * _base_get_cb_idx - obtain the callback index | ||
836 | * @ioc: per adapter object | ||
837 | * @smid: system request message index | ||
838 | * | ||
839 | * Return callback index. | ||
840 | */ | ||
841 | static u8 | ||
842 | _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
843 | { | ||
844 | int i; | ||
845 | u8 cb_idx; | ||
846 | |||
847 | if (smid < ioc->hi_priority_smid) { | ||
848 | i = smid - 1; | ||
849 | cb_idx = ioc->scsi_lookup[i].cb_idx; | ||
850 | } else if (smid < ioc->internal_smid) { | ||
851 | i = smid - ioc->hi_priority_smid; | ||
852 | cb_idx = ioc->hpr_lookup[i].cb_idx; | ||
853 | } else if (smid <= ioc->hba_queue_depth) { | ||
854 | i = smid - ioc->internal_smid; | ||
855 | cb_idx = ioc->internal_lookup[i].cb_idx; | ||
856 | } else | ||
857 | cb_idx = 0xFF; | ||
858 | return cb_idx; | ||
859 | } | ||
860 | |||
861 | /** | ||
862 | * _base_mask_interrupts - disable interrupts | ||
863 | * @ioc: per adapter object | ||
864 | * | ||
865 | * Disabling ResetIRQ, Reply and Doorbell Interrupts | ||
866 | * | ||
867 | * Return nothing. | ||
868 | */ | ||
869 | static void | ||
870 | _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc) | ||
871 | { | ||
872 | u32 him_register; | ||
873 | |||
874 | ioc->mask_interrupts = 1; | ||
875 | him_register = readl(&ioc->chip->HostInterruptMask); | ||
876 | him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK; | ||
877 | writel(him_register, &ioc->chip->HostInterruptMask); | ||
878 | readl(&ioc->chip->HostInterruptMask); | ||
879 | } | ||
880 | |||
881 | /** | ||
882 | * _base_unmask_interrupts - enable interrupts | ||
883 | * @ioc: per adapter object | ||
884 | * | ||
885 | * Enabling only Reply Interrupts | ||
886 | * | ||
887 | * Return nothing. | ||
888 | */ | ||
889 | static void | ||
890 | _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc) | ||
891 | { | ||
892 | u32 him_register; | ||
893 | |||
894 | him_register = readl(&ioc->chip->HostInterruptMask); | ||
895 | him_register &= ~MPI2_HIM_RIM; | ||
896 | writel(him_register, &ioc->chip->HostInterruptMask); | ||
897 | ioc->mask_interrupts = 0; | ||
898 | } | ||
899 | |||
900 | union reply_descriptor { | ||
901 | u64 word; | ||
902 | struct { | ||
903 | u32 low; | ||
904 | u32 high; | ||
905 | } u; | ||
906 | }; | ||
907 | |||
908 | /** | ||
909 | * _base_interrupt - MPT adapter (IOC) specific interrupt handler. | ||
910 | * @irq: irq number (not used) | ||
911 | * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure | ||
912 | * @r: pt_regs pointer (not used) | ||
913 | * | ||
914 | * Return IRQ_HANDLE if processed, else IRQ_NONE. | ||
915 | */ | ||
916 | static irqreturn_t | ||
917 | _base_interrupt(int irq, void *bus_id) | ||
918 | { | ||
919 | struct adapter_reply_queue *reply_q = bus_id; | ||
920 | union reply_descriptor rd; | ||
921 | u32 completed_cmds; | ||
922 | u8 request_desript_type; | ||
923 | u16 smid; | ||
924 | u8 cb_idx; | ||
925 | u32 reply; | ||
926 | u8 msix_index = reply_q->msix_index; | ||
927 | struct MPT2SAS_ADAPTER *ioc = reply_q->ioc; | ||
928 | Mpi2ReplyDescriptorsUnion_t *rpf; | ||
929 | u8 rc; | ||
930 | |||
931 | if (ioc->mask_interrupts) | ||
932 | return IRQ_NONE; | ||
933 | |||
934 | if (!atomic_add_unless(&reply_q->busy, 1, 1)) | ||
935 | return IRQ_NONE; | ||
936 | |||
937 | rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index]; | ||
938 | request_desript_type = rpf->Default.ReplyFlags | ||
939 | & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; | ||
940 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) { | ||
941 | atomic_dec(&reply_q->busy); | ||
942 | return IRQ_NONE; | ||
943 | } | ||
944 | |||
945 | completed_cmds = 0; | ||
946 | cb_idx = 0xFF; | ||
947 | do { | ||
948 | rd.word = le64_to_cpu(rpf->Words); | ||
949 | if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX) | ||
950 | goto out; | ||
951 | reply = 0; | ||
952 | smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1); | ||
953 | if (request_desript_type == | ||
954 | MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) { | ||
955 | reply = le32_to_cpu | ||
956 | (rpf->AddressReply.ReplyFrameAddress); | ||
957 | if (reply > ioc->reply_dma_max_address || | ||
958 | reply < ioc->reply_dma_min_address) | ||
959 | reply = 0; | ||
960 | } else if (request_desript_type == | ||
961 | MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER) | ||
962 | goto next; | ||
963 | else if (request_desript_type == | ||
964 | MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS) | ||
965 | goto next; | ||
966 | if (smid) { | ||
967 | cb_idx = _base_get_cb_idx(ioc, smid); | ||
968 | if ((likely(cb_idx < MPT_MAX_CALLBACKS)) | ||
969 | && (likely(mpt_callbacks[cb_idx] != NULL))) { | ||
970 | rc = mpt_callbacks[cb_idx](ioc, smid, | ||
971 | msix_index, reply); | ||
972 | if (reply) | ||
973 | _base_display_reply_info(ioc, smid, | ||
974 | msix_index, reply); | ||
975 | if (rc) | ||
976 | mpt2sas_base_free_smid(ioc, smid); | ||
977 | } | ||
978 | } | ||
979 | if (!smid) | ||
980 | _base_async_event(ioc, msix_index, reply); | ||
981 | |||
982 | /* reply free queue handling */ | ||
983 | if (reply) { | ||
984 | ioc->reply_free_host_index = | ||
985 | (ioc->reply_free_host_index == | ||
986 | (ioc->reply_free_queue_depth - 1)) ? | ||
987 | 0 : ioc->reply_free_host_index + 1; | ||
988 | ioc->reply_free[ioc->reply_free_host_index] = | ||
989 | cpu_to_le32(reply); | ||
990 | wmb(); | ||
991 | writel(ioc->reply_free_host_index, | ||
992 | &ioc->chip->ReplyFreeHostIndex); | ||
993 | } | ||
994 | |||
995 | next: | ||
996 | |||
997 | rpf->Words = cpu_to_le64(ULLONG_MAX); | ||
998 | reply_q->reply_post_host_index = | ||
999 | (reply_q->reply_post_host_index == | ||
1000 | (ioc->reply_post_queue_depth - 1)) ? 0 : | ||
1001 | reply_q->reply_post_host_index + 1; | ||
1002 | request_desript_type = | ||
1003 | reply_q->reply_post_free[reply_q->reply_post_host_index]. | ||
1004 | Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; | ||
1005 | completed_cmds++; | ||
1006 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) | ||
1007 | goto out; | ||
1008 | if (!reply_q->reply_post_host_index) | ||
1009 | rpf = reply_q->reply_post_free; | ||
1010 | else | ||
1011 | rpf++; | ||
1012 | } while (1); | ||
1013 | |||
1014 | out: | ||
1015 | |||
1016 | if (!completed_cmds) { | ||
1017 | atomic_dec(&reply_q->busy); | ||
1018 | return IRQ_NONE; | ||
1019 | } | ||
1020 | wmb(); | ||
1021 | if (ioc->is_warpdrive) { | ||
1022 | writel(reply_q->reply_post_host_index, | ||
1023 | ioc->reply_post_host_index[msix_index]); | ||
1024 | atomic_dec(&reply_q->busy); | ||
1025 | return IRQ_HANDLED; | ||
1026 | } | ||
1027 | writel(reply_q->reply_post_host_index | (msix_index << | ||
1028 | MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex); | ||
1029 | atomic_dec(&reply_q->busy); | ||
1030 | return IRQ_HANDLED; | ||
1031 | } | ||
1032 | |||
1033 | /** | ||
1034 | * _base_is_controller_msix_enabled - is controller support muli-reply queues | ||
1035 | * @ioc: per adapter object | ||
1036 | * | ||
1037 | */ | ||
1038 | static inline int | ||
1039 | _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc) | ||
1040 | { | ||
1041 | return (ioc->facts.IOCCapabilities & | ||
1042 | MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable; | ||
1043 | } | ||
1044 | |||
1045 | /** | ||
1046 | * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues | ||
1047 | * @ioc: per adapter object | ||
1048 | * Context: ISR conext | ||
1049 | * | ||
1050 | * Called when a Task Management request has completed. We want | ||
1051 | * to flush the other reply queues so all the outstanding IO has been | ||
1052 | * completed back to OS before we process the TM completetion. | ||
1053 | * | ||
1054 | * Return nothing. | ||
1055 | */ | ||
1056 | void | ||
1057 | mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc) | ||
1058 | { | ||
1059 | struct adapter_reply_queue *reply_q; | ||
1060 | |||
1061 | /* If MSIX capability is turned off | ||
1062 | * then multi-queues are not enabled | ||
1063 | */ | ||
1064 | if (!_base_is_controller_msix_enabled(ioc)) | ||
1065 | return; | ||
1066 | |||
1067 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { | ||
1068 | if (ioc->shost_recovery) | ||
1069 | return; | ||
1070 | /* TMs are on msix_index == 0 */ | ||
1071 | if (reply_q->msix_index == 0) | ||
1072 | continue; | ||
1073 | _base_interrupt(reply_q->vector, (void *)reply_q); | ||
1074 | } | ||
1075 | } | ||
1076 | |||
1077 | /** | ||
1078 | * mpt2sas_base_release_callback_handler - clear interrupt callback handler | ||
1079 | * @cb_idx: callback index | ||
1080 | * | ||
1081 | * Return nothing. | ||
1082 | */ | ||
1083 | void | ||
1084 | mpt2sas_base_release_callback_handler(u8 cb_idx) | ||
1085 | { | ||
1086 | mpt_callbacks[cb_idx] = NULL; | ||
1087 | } | ||
1088 | |||
1089 | /** | ||
1090 | * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler | ||
1091 | * @cb_func: callback function | ||
1092 | * | ||
1093 | * Returns cb_func. | ||
1094 | */ | ||
1095 | u8 | ||
1096 | mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func) | ||
1097 | { | ||
1098 | u8 cb_idx; | ||
1099 | |||
1100 | for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--) | ||
1101 | if (mpt_callbacks[cb_idx] == NULL) | ||
1102 | break; | ||
1103 | |||
1104 | mpt_callbacks[cb_idx] = cb_func; | ||
1105 | return cb_idx; | ||
1106 | } | ||
1107 | |||
1108 | /** | ||
1109 | * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler | ||
1110 | * | ||
1111 | * Return nothing. | ||
1112 | */ | ||
1113 | void | ||
1114 | mpt2sas_base_initialize_callback_handler(void) | ||
1115 | { | ||
1116 | u8 cb_idx; | ||
1117 | |||
1118 | for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++) | ||
1119 | mpt2sas_base_release_callback_handler(cb_idx); | ||
1120 | } | ||
1121 | |||
1122 | /** | ||
1123 | * mpt2sas_base_build_zero_len_sge - build zero length sg entry | ||
1124 | * @ioc: per adapter object | ||
1125 | * @paddr: virtual address for SGE | ||
1126 | * | ||
1127 | * Create a zero length scatter gather entry to insure the IOCs hardware has | ||
1128 | * something to use if the target device goes brain dead and tries | ||
1129 | * to send data even when none is asked for. | ||
1130 | * | ||
1131 | * Return nothing. | ||
1132 | */ | ||
1133 | void | ||
1134 | mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr) | ||
1135 | { | ||
1136 | u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT | | ||
1137 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST | | ||
1138 | MPI2_SGE_FLAGS_SIMPLE_ELEMENT) << | ||
1139 | MPI2_SGE_FLAGS_SHIFT); | ||
1140 | ioc->base_add_sg_single(paddr, flags_length, -1); | ||
1141 | } | ||
1142 | |||
1143 | /** | ||
1144 | * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr. | ||
1145 | * @paddr: virtual address for SGE | ||
1146 | * @flags_length: SGE flags and data transfer length | ||
1147 | * @dma_addr: Physical address | ||
1148 | * | ||
1149 | * Return nothing. | ||
1150 | */ | ||
1151 | static void | ||
1152 | _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr) | ||
1153 | { | ||
1154 | Mpi2SGESimple32_t *sgel = paddr; | ||
1155 | |||
1156 | flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING | | ||
1157 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; | ||
1158 | sgel->FlagsLength = cpu_to_le32(flags_length); | ||
1159 | sgel->Address = cpu_to_le32(dma_addr); | ||
1160 | } | ||
1161 | |||
1162 | |||
1163 | /** | ||
1164 | * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr. | ||
1165 | * @paddr: virtual address for SGE | ||
1166 | * @flags_length: SGE flags and data transfer length | ||
1167 | * @dma_addr: Physical address | ||
1168 | * | ||
1169 | * Return nothing. | ||
1170 | */ | ||
1171 | static void | ||
1172 | _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr) | ||
1173 | { | ||
1174 | Mpi2SGESimple64_t *sgel = paddr; | ||
1175 | |||
1176 | flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING | | ||
1177 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; | ||
1178 | sgel->FlagsLength = cpu_to_le32(flags_length); | ||
1179 | sgel->Address = cpu_to_le64(dma_addr); | ||
1180 | } | ||
1181 | |||
1182 | #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10)) | ||
1183 | |||
1184 | /** | ||
1185 | * _base_config_dma_addressing - set dma addressing | ||
1186 | * @ioc: per adapter object | ||
1187 | * @pdev: PCI device struct | ||
1188 | * | ||
1189 | * Returns 0 for success, non-zero for failure. | ||
1190 | */ | ||
1191 | static int | ||
1192 | _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev) | ||
1193 | { | ||
1194 | struct sysinfo s; | ||
1195 | u64 consistent_dma_mask; | ||
1196 | |||
1197 | if (ioc->dma_mask) | ||
1198 | consistent_dma_mask = DMA_BIT_MASK(64); | ||
1199 | else | ||
1200 | consistent_dma_mask = DMA_BIT_MASK(32); | ||
1201 | |||
1202 | if (sizeof(dma_addr_t) > 4) { | ||
1203 | const uint64_t required_mask = | ||
1204 | dma_get_required_mask(&pdev->dev); | ||
1205 | if ((required_mask > DMA_BIT_MASK(32)) && | ||
1206 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && | ||
1207 | !pci_set_consistent_dma_mask(pdev, consistent_dma_mask)) { | ||
1208 | ioc->base_add_sg_single = &_base_add_sg_single_64; | ||
1209 | ioc->sge_size = sizeof(Mpi2SGESimple64_t); | ||
1210 | ioc->dma_mask = 64; | ||
1211 | goto out; | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1215 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) | ||
1216 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { | ||
1217 | ioc->base_add_sg_single = &_base_add_sg_single_32; | ||
1218 | ioc->sge_size = sizeof(Mpi2SGESimple32_t); | ||
1219 | ioc->dma_mask = 32; | ||
1220 | } else | ||
1221 | return -ENODEV; | ||
1222 | |||
1223 | out: | ||
1224 | si_meminfo(&s); | ||
1225 | printk(MPT2SAS_INFO_FMT | ||
1226 | "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n", | ||
1227 | ioc->name, ioc->dma_mask, convert_to_kb(s.totalram)); | ||
1228 | |||
1229 | return 0; | ||
1230 | } | ||
1231 | |||
1232 | static int | ||
1233 | _base_change_consistent_dma_mask(struct MPT2SAS_ADAPTER *ioc, | ||
1234 | struct pci_dev *pdev) | ||
1235 | { | ||
1236 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { | ||
1237 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) | ||
1238 | return -ENODEV; | ||
1239 | } | ||
1240 | return 0; | ||
1241 | } | ||
1242 | /** | ||
1243 | * _base_check_enable_msix - checks MSIX capabable. | ||
1244 | * @ioc: per adapter object | ||
1245 | * | ||
1246 | * Check to see if card is capable of MSIX, and set number | ||
1247 | * of available msix vectors | ||
1248 | */ | ||
1249 | static int | ||
1250 | _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc) | ||
1251 | { | ||
1252 | int base; | ||
1253 | u16 message_control; | ||
1254 | |||
1255 | |||
1256 | /* Check whether controller SAS2008 B0 controller, | ||
1257 | if it is SAS2008 B0 controller use IO-APIC instead of MSIX */ | ||
1258 | if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 && | ||
1259 | ioc->pdev->revision == 0x01) { | ||
1260 | return -EINVAL; | ||
1261 | } | ||
1262 | |||
1263 | base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); | ||
1264 | if (!base) { | ||
1265 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not " | ||
1266 | "supported\n", ioc->name)); | ||
1267 | return -EINVAL; | ||
1268 | } | ||
1269 | |||
1270 | /* get msix vector count */ | ||
1271 | /* NUMA_IO not supported for older controllers */ | ||
1272 | if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 || | ||
1273 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 || | ||
1274 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 || | ||
1275 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 || | ||
1276 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 || | ||
1277 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 || | ||
1278 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2) | ||
1279 | ioc->msix_vector_count = 1; | ||
1280 | else { | ||
1281 | pci_read_config_word(ioc->pdev, base + 2, &message_control); | ||
1282 | ioc->msix_vector_count = (message_control & 0x3FF) + 1; | ||
1283 | } | ||
1284 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, " | ||
1285 | "vector_count(%d)\n", ioc->name, ioc->msix_vector_count)); | ||
1286 | |||
1287 | return 0; | ||
1288 | } | ||
1289 | |||
1290 | /** | ||
1291 | * _base_free_irq - free irq | ||
1292 | * @ioc: per adapter object | ||
1293 | * | ||
1294 | * Freeing respective reply_queue from the list. | ||
1295 | */ | ||
1296 | static void | ||
1297 | _base_free_irq(struct MPT2SAS_ADAPTER *ioc) | ||
1298 | { | ||
1299 | struct adapter_reply_queue *reply_q, *next; | ||
1300 | |||
1301 | if (list_empty(&ioc->reply_queue_list)) | ||
1302 | return; | ||
1303 | |||
1304 | list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) { | ||
1305 | list_del(&reply_q->list); | ||
1306 | irq_set_affinity_hint(reply_q->vector, NULL); | ||
1307 | free_cpumask_var(reply_q->affinity_hint); | ||
1308 | synchronize_irq(reply_q->vector); | ||
1309 | free_irq(reply_q->vector, reply_q); | ||
1310 | kfree(reply_q); | ||
1311 | } | ||
1312 | } | ||
1313 | |||
1314 | /** | ||
1315 | * _base_request_irq - request irq | ||
1316 | * @ioc: per adapter object | ||
1317 | * @index: msix index into vector table | ||
1318 | * @vector: irq vector | ||
1319 | * | ||
1320 | * Inserting respective reply_queue into the list. | ||
1321 | */ | ||
1322 | static int | ||
1323 | _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector) | ||
1324 | { | ||
1325 | struct adapter_reply_queue *reply_q; | ||
1326 | int r; | ||
1327 | |||
1328 | reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL); | ||
1329 | if (!reply_q) { | ||
1330 | printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n", | ||
1331 | ioc->name, (int)sizeof(struct adapter_reply_queue)); | ||
1332 | return -ENOMEM; | ||
1333 | } | ||
1334 | reply_q->ioc = ioc; | ||
1335 | reply_q->msix_index = index; | ||
1336 | reply_q->vector = vector; | ||
1337 | |||
1338 | if (!alloc_cpumask_var(&reply_q->affinity_hint, GFP_KERNEL)) | ||
1339 | return -ENOMEM; | ||
1340 | cpumask_clear(reply_q->affinity_hint); | ||
1341 | |||
1342 | atomic_set(&reply_q->busy, 0); | ||
1343 | if (ioc->msix_enable) | ||
1344 | snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d", | ||
1345 | MPT2SAS_DRIVER_NAME, ioc->id, index); | ||
1346 | else | ||
1347 | snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d", | ||
1348 | MPT2SAS_DRIVER_NAME, ioc->id); | ||
1349 | r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name, | ||
1350 | reply_q); | ||
1351 | if (r) { | ||
1352 | printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n", | ||
1353 | reply_q->name, vector); | ||
1354 | kfree(reply_q); | ||
1355 | return -EBUSY; | ||
1356 | } | ||
1357 | |||
1358 | INIT_LIST_HEAD(&reply_q->list); | ||
1359 | list_add_tail(&reply_q->list, &ioc->reply_queue_list); | ||
1360 | return 0; | ||
1361 | } | ||
1362 | |||
1363 | /** | ||
1364 | * _base_assign_reply_queues - assigning msix index for each cpu | ||
1365 | * @ioc: per adapter object | ||
1366 | * | ||
1367 | * The enduser would need to set the affinity via /proc/irq/#/smp_affinity | ||
1368 | * | ||
1369 | * It would nice if we could call irq_set_affinity, however it is not | ||
1370 | * an exported symbol | ||
1371 | */ | ||
1372 | static void | ||
1373 | _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc) | ||
1374 | { | ||
1375 | unsigned int cpu, nr_cpus, nr_msix, index = 0; | ||
1376 | struct adapter_reply_queue *reply_q; | ||
1377 | |||
1378 | if (!_base_is_controller_msix_enabled(ioc)) | ||
1379 | return; | ||
1380 | |||
1381 | memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz); | ||
1382 | |||
1383 | nr_cpus = num_online_cpus(); | ||
1384 | nr_msix = ioc->reply_queue_count = min(ioc->reply_queue_count, | ||
1385 | ioc->facts.MaxMSIxVectors); | ||
1386 | if (!nr_msix) | ||
1387 | return; | ||
1388 | |||
1389 | cpu = cpumask_first(cpu_online_mask); | ||
1390 | |||
1391 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { | ||
1392 | |||
1393 | unsigned int i, group = nr_cpus / nr_msix; | ||
1394 | |||
1395 | if (cpu >= nr_cpus) | ||
1396 | break; | ||
1397 | |||
1398 | if (index < nr_cpus % nr_msix) | ||
1399 | group++; | ||
1400 | |||
1401 | for (i = 0 ; i < group ; i++) { | ||
1402 | ioc->cpu_msix_table[cpu] = index; | ||
1403 | cpumask_or(reply_q->affinity_hint, | ||
1404 | reply_q->affinity_hint, get_cpu_mask(cpu)); | ||
1405 | cpu = cpumask_next(cpu, cpu_online_mask); | ||
1406 | } | ||
1407 | |||
1408 | if (irq_set_affinity_hint(reply_q->vector, | ||
1409 | reply_q->affinity_hint)) | ||
1410 | dinitprintk(ioc, pr_info(MPT2SAS_FMT | ||
1411 | "error setting affinity hint for irq vector %d\n", | ||
1412 | ioc->name, reply_q->vector)); | ||
1413 | index++; | ||
1414 | } | ||
1415 | } | ||
1416 | |||
1417 | /** | ||
1418 | * _base_disable_msix - disables msix | ||
1419 | * @ioc: per adapter object | ||
1420 | * | ||
1421 | */ | ||
1422 | static void | ||
1423 | _base_disable_msix(struct MPT2SAS_ADAPTER *ioc) | ||
1424 | { | ||
1425 | if (ioc->msix_enable) { | ||
1426 | pci_disable_msix(ioc->pdev); | ||
1427 | ioc->msix_enable = 0; | ||
1428 | } | ||
1429 | } | ||
1430 | |||
1431 | /** | ||
1432 | * _base_enable_msix - enables msix, failback to io_apic | ||
1433 | * @ioc: per adapter object | ||
1434 | * | ||
1435 | */ | ||
1436 | static int | ||
1437 | _base_enable_msix(struct MPT2SAS_ADAPTER *ioc) | ||
1438 | { | ||
1439 | struct msix_entry *entries, *a; | ||
1440 | int r; | ||
1441 | int i; | ||
1442 | u8 try_msix = 0; | ||
1443 | |||
1444 | if (msix_disable == -1 || msix_disable == 0) | ||
1445 | try_msix = 1; | ||
1446 | |||
1447 | if (!try_msix) | ||
1448 | goto try_ioapic; | ||
1449 | |||
1450 | if (_base_check_enable_msix(ioc) != 0) | ||
1451 | goto try_ioapic; | ||
1452 | |||
1453 | ioc->reply_queue_count = min_t(int, ioc->cpu_count, | ||
1454 | ioc->msix_vector_count); | ||
1455 | |||
1456 | if (!ioc->rdpq_array_enable && max_msix_vectors == -1) | ||
1457 | max_msix_vectors = 8; | ||
1458 | |||
1459 | if (max_msix_vectors > 0) { | ||
1460 | ioc->reply_queue_count = min_t(int, max_msix_vectors, | ||
1461 | ioc->reply_queue_count); | ||
1462 | ioc->msix_vector_count = ioc->reply_queue_count; | ||
1463 | } else if (max_msix_vectors == 0) | ||
1464 | goto try_ioapic; | ||
1465 | |||
1466 | printk(MPT2SAS_INFO_FMT | ||
1467 | "MSI-X vectors supported: %d, no of cores: %d, max_msix_vectors: %d\n", | ||
1468 | ioc->name, ioc->msix_vector_count, ioc->cpu_count, max_msix_vectors); | ||
1469 | |||
1470 | entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry), | ||
1471 | GFP_KERNEL); | ||
1472 | if (!entries) { | ||
1473 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc " | ||
1474 | "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__, | ||
1475 | __LINE__, __func__)); | ||
1476 | goto try_ioapic; | ||
1477 | } | ||
1478 | |||
1479 | for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) | ||
1480 | a->entry = i; | ||
1481 | |||
1482 | r = pci_enable_msix_exact(ioc->pdev, entries, ioc->reply_queue_count); | ||
1483 | if (r) { | ||
1484 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1485 | "pci_enable_msix_exact failed (r=%d) !!!\n", ioc->name, r)); | ||
1486 | kfree(entries); | ||
1487 | goto try_ioapic; | ||
1488 | } | ||
1489 | |||
1490 | ioc->msix_enable = 1; | ||
1491 | for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) { | ||
1492 | r = _base_request_irq(ioc, i, a->vector); | ||
1493 | if (r) { | ||
1494 | _base_free_irq(ioc); | ||
1495 | _base_disable_msix(ioc); | ||
1496 | kfree(entries); | ||
1497 | goto try_ioapic; | ||
1498 | } | ||
1499 | } | ||
1500 | |||
1501 | kfree(entries); | ||
1502 | return 0; | ||
1503 | |||
1504 | /* failback to io_apic interrupt routing */ | ||
1505 | try_ioapic: | ||
1506 | |||
1507 | ioc->reply_queue_count = 1; | ||
1508 | r = _base_request_irq(ioc, 0, ioc->pdev->irq); | ||
1509 | |||
1510 | return r; | ||
1511 | } | ||
1512 | |||
1513 | /** | ||
1514 | * mpt2sas_base_map_resources - map in controller resources (io/irq/memap) | ||
1515 | * @ioc: per adapter object | ||
1516 | * | ||
1517 | * Returns 0 for success, non-zero for failure. | ||
1518 | */ | ||
1519 | int | ||
1520 | mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc) | ||
1521 | { | ||
1522 | struct pci_dev *pdev = ioc->pdev; | ||
1523 | u32 memap_sz; | ||
1524 | u32 pio_sz; | ||
1525 | int i, r = 0; | ||
1526 | u64 pio_chip = 0; | ||
1527 | u64 chip_phys = 0; | ||
1528 | struct adapter_reply_queue *reply_q; | ||
1529 | |||
1530 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", | ||
1531 | ioc->name, __func__)); | ||
1532 | |||
1533 | ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
1534 | if (pci_enable_device_mem(pdev)) { | ||
1535 | printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: " | ||
1536 | "failed\n", ioc->name); | ||
1537 | ioc->bars = 0; | ||
1538 | return -ENODEV; | ||
1539 | } | ||
1540 | |||
1541 | |||
1542 | if (pci_request_selected_regions(pdev, ioc->bars, | ||
1543 | MPT2SAS_DRIVER_NAME)) { | ||
1544 | printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: " | ||
1545 | "failed\n", ioc->name); | ||
1546 | ioc->bars = 0; | ||
1547 | r = -ENODEV; | ||
1548 | goto out_fail; | ||
1549 | } | ||
1550 | |||
1551 | /* AER (Advanced Error Reporting) hooks */ | ||
1552 | pci_enable_pcie_error_reporting(pdev); | ||
1553 | |||
1554 | pci_set_master(pdev); | ||
1555 | |||
1556 | if (_base_config_dma_addressing(ioc, pdev) != 0) { | ||
1557 | printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n", | ||
1558 | ioc->name, pci_name(pdev)); | ||
1559 | r = -ENODEV; | ||
1560 | goto out_fail; | ||
1561 | } | ||
1562 | |||
1563 | for (i = 0, memap_sz = 0, pio_sz = 0; (i < DEVICE_COUNT_RESOURCE) && | ||
1564 | (!memap_sz || !pio_sz); i++) { | ||
1565 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { | ||
1566 | if (pio_sz) | ||
1567 | continue; | ||
1568 | pio_chip = (u64)pci_resource_start(pdev, i); | ||
1569 | pio_sz = pci_resource_len(pdev, i); | ||
1570 | } else { | ||
1571 | if (memap_sz) | ||
1572 | continue; | ||
1573 | /* verify memory resource is valid before using */ | ||
1574 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { | ||
1575 | ioc->chip_phys = pci_resource_start(pdev, i); | ||
1576 | chip_phys = (u64)ioc->chip_phys; | ||
1577 | memap_sz = pci_resource_len(pdev, i); | ||
1578 | ioc->chip = ioremap(ioc->chip_phys, memap_sz); | ||
1579 | } | ||
1580 | } | ||
1581 | } | ||
1582 | |||
1583 | if (ioc->chip == NULL) { | ||
1584 | printk(MPT2SAS_ERR_FMT "unable to map adapter memory! " | ||
1585 | "or resource not found\n", ioc->name); | ||
1586 | r = -EINVAL; | ||
1587 | goto out_fail; | ||
1588 | } | ||
1589 | |||
1590 | _base_mask_interrupts(ioc); | ||
1591 | |||
1592 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); | ||
1593 | if (r) | ||
1594 | goto out_fail; | ||
1595 | |||
1596 | if (!ioc->rdpq_array_enable_assigned) { | ||
1597 | ioc->rdpq_array_enable = ioc->rdpq_array_capable; | ||
1598 | ioc->rdpq_array_enable_assigned = 1; | ||
1599 | } | ||
1600 | |||
1601 | r = _base_enable_msix(ioc); | ||
1602 | if (r) | ||
1603 | goto out_fail; | ||
1604 | |||
1605 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) | ||
1606 | printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n", | ||
1607 | reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : | ||
1608 | "IO-APIC enabled"), reply_q->vector); | ||
1609 | |||
1610 | printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n", | ||
1611 | ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz); | ||
1612 | printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n", | ||
1613 | ioc->name, (unsigned long long)pio_chip, pio_sz); | ||
1614 | |||
1615 | /* Save PCI configuration state for recovery from PCI AER/EEH errors */ | ||
1616 | pci_save_state(pdev); | ||
1617 | |||
1618 | return 0; | ||
1619 | |||
1620 | out_fail: | ||
1621 | if (ioc->chip_phys) | ||
1622 | iounmap(ioc->chip); | ||
1623 | ioc->chip_phys = 0; | ||
1624 | pci_release_selected_regions(ioc->pdev, ioc->bars); | ||
1625 | pci_disable_pcie_error_reporting(pdev); | ||
1626 | pci_disable_device(pdev); | ||
1627 | return r; | ||
1628 | } | ||
1629 | |||
1630 | /** | ||
1631 | * mpt2sas_base_get_msg_frame - obtain request mf pointer | ||
1632 | * @ioc: per adapter object | ||
1633 | * @smid: system request message index(smid zero is invalid) | ||
1634 | * | ||
1635 | * Returns virt pointer to message frame. | ||
1636 | */ | ||
1637 | void * | ||
1638 | mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1639 | { | ||
1640 | return (void *)(ioc->request + (smid * ioc->request_sz)); | ||
1641 | } | ||
1642 | |||
1643 | /** | ||
1644 | * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request | ||
1645 | * @ioc: per adapter object | ||
1646 | * @smid: system request message index | ||
1647 | * | ||
1648 | * Returns virt pointer to sense buffer. | ||
1649 | */ | ||
1650 | void * | ||
1651 | mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1652 | { | ||
1653 | return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); | ||
1654 | } | ||
1655 | |||
1656 | /** | ||
1657 | * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request | ||
1658 | * @ioc: per adapter object | ||
1659 | * @smid: system request message index | ||
1660 | * | ||
1661 | * Returns phys pointer to the low 32bit address of the sense buffer. | ||
1662 | */ | ||
1663 | __le32 | ||
1664 | mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1665 | { | ||
1666 | return cpu_to_le32(ioc->sense_dma + | ||
1667 | ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); | ||
1668 | } | ||
1669 | |||
1670 | /** | ||
1671 | * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address | ||
1672 | * @ioc: per adapter object | ||
1673 | * @phys_addr: lower 32 physical addr of the reply | ||
1674 | * | ||
1675 | * Converts 32bit lower physical addr into a virt address. | ||
1676 | */ | ||
1677 | void * | ||
1678 | mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr) | ||
1679 | { | ||
1680 | if (!phys_addr) | ||
1681 | return NULL; | ||
1682 | return ioc->reply + (phys_addr - (u32)ioc->reply_dma); | ||
1683 | } | ||
1684 | |||
1685 | /** | ||
1686 | * mpt2sas_base_get_smid - obtain a free smid from internal queue | ||
1687 | * @ioc: per adapter object | ||
1688 | * @cb_idx: callback index | ||
1689 | * | ||
1690 | * Returns smid (zero is invalid) | ||
1691 | */ | ||
1692 | u16 | ||
1693 | mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx) | ||
1694 | { | ||
1695 | unsigned long flags; | ||
1696 | struct request_tracker *request; | ||
1697 | u16 smid; | ||
1698 | |||
1699 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1700 | if (list_empty(&ioc->internal_free_list)) { | ||
1701 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1702 | printk(MPT2SAS_ERR_FMT "%s: smid not available\n", | ||
1703 | ioc->name, __func__); | ||
1704 | return 0; | ||
1705 | } | ||
1706 | |||
1707 | request = list_entry(ioc->internal_free_list.next, | ||
1708 | struct request_tracker, tracker_list); | ||
1709 | request->cb_idx = cb_idx; | ||
1710 | smid = request->smid; | ||
1711 | list_del(&request->tracker_list); | ||
1712 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1713 | return smid; | ||
1714 | } | ||
1715 | |||
1716 | /** | ||
1717 | * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue | ||
1718 | * @ioc: per adapter object | ||
1719 | * @cb_idx: callback index | ||
1720 | * @scmd: pointer to scsi command object | ||
1721 | * | ||
1722 | * Returns smid (zero is invalid) | ||
1723 | */ | ||
1724 | u16 | ||
1725 | mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx, | ||
1726 | struct scsi_cmnd *scmd) | ||
1727 | { | ||
1728 | unsigned long flags; | ||
1729 | struct scsiio_tracker *request; | ||
1730 | u16 smid; | ||
1731 | |||
1732 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1733 | if (list_empty(&ioc->free_list)) { | ||
1734 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1735 | printk(MPT2SAS_ERR_FMT "%s: smid not available\n", | ||
1736 | ioc->name, __func__); | ||
1737 | return 0; | ||
1738 | } | ||
1739 | |||
1740 | request = list_entry(ioc->free_list.next, | ||
1741 | struct scsiio_tracker, tracker_list); | ||
1742 | request->scmd = scmd; | ||
1743 | request->cb_idx = cb_idx; | ||
1744 | smid = request->smid; | ||
1745 | list_del(&request->tracker_list); | ||
1746 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1747 | return smid; | ||
1748 | } | ||
1749 | |||
1750 | /** | ||
1751 | * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue | ||
1752 | * @ioc: per adapter object | ||
1753 | * @cb_idx: callback index | ||
1754 | * | ||
1755 | * Returns smid (zero is invalid) | ||
1756 | */ | ||
1757 | u16 | ||
1758 | mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx) | ||
1759 | { | ||
1760 | unsigned long flags; | ||
1761 | struct request_tracker *request; | ||
1762 | u16 smid; | ||
1763 | |||
1764 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1765 | if (list_empty(&ioc->hpr_free_list)) { | ||
1766 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1767 | return 0; | ||
1768 | } | ||
1769 | |||
1770 | request = list_entry(ioc->hpr_free_list.next, | ||
1771 | struct request_tracker, tracker_list); | ||
1772 | request->cb_idx = cb_idx; | ||
1773 | smid = request->smid; | ||
1774 | list_del(&request->tracker_list); | ||
1775 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1776 | return smid; | ||
1777 | } | ||
1778 | |||
1779 | |||
1780 | /** | ||
1781 | * mpt2sas_base_free_smid - put smid back on free_list | ||
1782 | * @ioc: per adapter object | ||
1783 | * @smid: system request message index | ||
1784 | * | ||
1785 | * Return nothing. | ||
1786 | */ | ||
1787 | void | ||
1788 | mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1789 | { | ||
1790 | unsigned long flags; | ||
1791 | int i; | ||
1792 | struct chain_tracker *chain_req, *next; | ||
1793 | |||
1794 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1795 | if (smid < ioc->hi_priority_smid) { | ||
1796 | /* scsiio queue */ | ||
1797 | i = smid - 1; | ||
1798 | if (!list_empty(&ioc->scsi_lookup[i].chain_list)) { | ||
1799 | list_for_each_entry_safe(chain_req, next, | ||
1800 | &ioc->scsi_lookup[i].chain_list, tracker_list) { | ||
1801 | list_del_init(&chain_req->tracker_list); | ||
1802 | list_add(&chain_req->tracker_list, | ||
1803 | &ioc->free_chain_list); | ||
1804 | } | ||
1805 | } | ||
1806 | ioc->scsi_lookup[i].cb_idx = 0xFF; | ||
1807 | ioc->scsi_lookup[i].scmd = NULL; | ||
1808 | ioc->scsi_lookup[i].direct_io = 0; | ||
1809 | list_add(&ioc->scsi_lookup[i].tracker_list, | ||
1810 | &ioc->free_list); | ||
1811 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1812 | |||
1813 | /* | ||
1814 | * See _wait_for_commands_to_complete() call with regards | ||
1815 | * to this code. | ||
1816 | */ | ||
1817 | if (ioc->shost_recovery && ioc->pending_io_count) { | ||
1818 | if (ioc->pending_io_count == 1) | ||
1819 | wake_up(&ioc->reset_wq); | ||
1820 | ioc->pending_io_count--; | ||
1821 | } | ||
1822 | return; | ||
1823 | } else if (smid < ioc->internal_smid) { | ||
1824 | /* hi-priority */ | ||
1825 | i = smid - ioc->hi_priority_smid; | ||
1826 | ioc->hpr_lookup[i].cb_idx = 0xFF; | ||
1827 | list_add(&ioc->hpr_lookup[i].tracker_list, | ||
1828 | &ioc->hpr_free_list); | ||
1829 | } else if (smid <= ioc->hba_queue_depth) { | ||
1830 | /* internal queue */ | ||
1831 | i = smid - ioc->internal_smid; | ||
1832 | ioc->internal_lookup[i].cb_idx = 0xFF; | ||
1833 | list_add(&ioc->internal_lookup[i].tracker_list, | ||
1834 | &ioc->internal_free_list); | ||
1835 | } | ||
1836 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1837 | } | ||
1838 | |||
1839 | /** | ||
1840 | * _base_writeq - 64 bit write to MMIO | ||
1841 | * @ioc: per adapter object | ||
1842 | * @b: data payload | ||
1843 | * @addr: address in MMIO space | ||
1844 | * @writeq_lock: spin lock | ||
1845 | * | ||
1846 | * Glue for handling an atomic 64 bit word to MMIO. This special handling takes | ||
1847 | * care of 32 bit environment where its not quarenteed to send the entire word | ||
1848 | * in one transfer. | ||
1849 | */ | ||
1850 | #ifndef writeq | ||
1851 | static inline void _base_writeq(__u64 b, volatile void __iomem *addr, | ||
1852 | spinlock_t *writeq_lock) | ||
1853 | { | ||
1854 | unsigned long flags; | ||
1855 | __u64 data_out = cpu_to_le64(b); | ||
1856 | |||
1857 | spin_lock_irqsave(writeq_lock, flags); | ||
1858 | writel((u32)(data_out), addr); | ||
1859 | writel((u32)(data_out >> 32), (addr + 4)); | ||
1860 | spin_unlock_irqrestore(writeq_lock, flags); | ||
1861 | } | ||
1862 | #else | ||
1863 | static inline void _base_writeq(__u64 b, volatile void __iomem *addr, | ||
1864 | spinlock_t *writeq_lock) | ||
1865 | { | ||
1866 | writeq(cpu_to_le64(b), addr); | ||
1867 | } | ||
1868 | #endif | ||
1869 | |||
1870 | static inline u8 | ||
1871 | _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc) | ||
1872 | { | ||
1873 | return ioc->cpu_msix_table[raw_smp_processor_id()]; | ||
1874 | } | ||
1875 | |||
1876 | /** | ||
1877 | * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware | ||
1878 | * @ioc: per adapter object | ||
1879 | * @smid: system request message index | ||
1880 | * @handle: device handle | ||
1881 | * | ||
1882 | * Return nothing. | ||
1883 | */ | ||
1884 | void | ||
1885 | mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle) | ||
1886 | { | ||
1887 | Mpi2RequestDescriptorUnion_t descriptor; | ||
1888 | u64 *request = (u64 *)&descriptor; | ||
1889 | |||
1890 | |||
1891 | descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; | ||
1892 | descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc); | ||
1893 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); | ||
1894 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); | ||
1895 | descriptor.SCSIIO.LMID = 0; | ||
1896 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, | ||
1897 | &ioc->scsi_lookup_lock); | ||
1898 | } | ||
1899 | |||
1900 | |||
1901 | /** | ||
1902 | * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware | ||
1903 | * @ioc: per adapter object | ||
1904 | * @smid: system request message index | ||
1905 | * | ||
1906 | * Return nothing. | ||
1907 | */ | ||
1908 | void | ||
1909 | mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1910 | { | ||
1911 | Mpi2RequestDescriptorUnion_t descriptor; | ||
1912 | u64 *request = (u64 *)&descriptor; | ||
1913 | |||
1914 | descriptor.HighPriority.RequestFlags = | ||
1915 | MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY; | ||
1916 | descriptor.HighPriority.MSIxIndex = 0; | ||
1917 | descriptor.HighPriority.SMID = cpu_to_le16(smid); | ||
1918 | descriptor.HighPriority.LMID = 0; | ||
1919 | descriptor.HighPriority.Reserved1 = 0; | ||
1920 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, | ||
1921 | &ioc->scsi_lookup_lock); | ||
1922 | } | ||
1923 | |||
1924 | /** | ||
1925 | * mpt2sas_base_put_smid_default - Default, primarily used for config pages | ||
1926 | * @ioc: per adapter object | ||
1927 | * @smid: system request message index | ||
1928 | * | ||
1929 | * Return nothing. | ||
1930 | */ | ||
1931 | void | ||
1932 | mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1933 | { | ||
1934 | Mpi2RequestDescriptorUnion_t descriptor; | ||
1935 | u64 *request = (u64 *)&descriptor; | ||
1936 | |||
1937 | descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; | ||
1938 | descriptor.Default.MSIxIndex = _base_get_msix_index(ioc); | ||
1939 | descriptor.Default.SMID = cpu_to_le16(smid); | ||
1940 | descriptor.Default.LMID = 0; | ||
1941 | descriptor.Default.DescriptorTypeDependent = 0; | ||
1942 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, | ||
1943 | &ioc->scsi_lookup_lock); | ||
1944 | } | ||
1945 | |||
1946 | /** | ||
1947 | * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware | ||
1948 | * @ioc: per adapter object | ||
1949 | * @smid: system request message index | ||
1950 | * @io_index: value used to track the IO | ||
1951 | * | ||
1952 | * Return nothing. | ||
1953 | */ | ||
1954 | void | ||
1955 | mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
1956 | u16 io_index) | ||
1957 | { | ||
1958 | Mpi2RequestDescriptorUnion_t descriptor; | ||
1959 | u64 *request = (u64 *)&descriptor; | ||
1960 | |||
1961 | descriptor.SCSITarget.RequestFlags = | ||
1962 | MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET; | ||
1963 | descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc); | ||
1964 | descriptor.SCSITarget.SMID = cpu_to_le16(smid); | ||
1965 | descriptor.SCSITarget.LMID = 0; | ||
1966 | descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index); | ||
1967 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, | ||
1968 | &ioc->scsi_lookup_lock); | ||
1969 | } | ||
1970 | |||
1971 | /** | ||
1972 | * _base_display_dell_branding - Disply branding string | ||
1973 | * @ioc: per adapter object | ||
1974 | * | ||
1975 | * Return nothing. | ||
1976 | */ | ||
1977 | static void | ||
1978 | _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc) | ||
1979 | { | ||
1980 | char dell_branding[MPT2SAS_DELL_BRANDING_SIZE]; | ||
1981 | |||
1982 | if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL) | ||
1983 | return; | ||
1984 | |||
1985 | memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE); | ||
1986 | switch (ioc->pdev->subsystem_device) { | ||
1987 | case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID: | ||
1988 | strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING, | ||
1989 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
1990 | break; | ||
1991 | case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID: | ||
1992 | strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING, | ||
1993 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
1994 | break; | ||
1995 | case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID: | ||
1996 | strncpy(dell_branding, | ||
1997 | MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING, | ||
1998 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
1999 | break; | ||
2000 | case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID: | ||
2001 | strncpy(dell_branding, | ||
2002 | MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING, | ||
2003 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
2004 | break; | ||
2005 | case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID: | ||
2006 | strncpy(dell_branding, | ||
2007 | MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING, | ||
2008 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
2009 | break; | ||
2010 | case MPT2SAS_DELL_PERC_H200_SSDID: | ||
2011 | strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING, | ||
2012 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
2013 | break; | ||
2014 | case MPT2SAS_DELL_6GBPS_SAS_SSDID: | ||
2015 | strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING, | ||
2016 | MPT2SAS_DELL_BRANDING_SIZE - 1); | ||
2017 | break; | ||
2018 | default: | ||
2019 | sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device); | ||
2020 | break; | ||
2021 | } | ||
2022 | |||
2023 | printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X)," | ||
2024 | " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding, | ||
2025 | ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor, | ||
2026 | ioc->pdev->subsystem_device); | ||
2027 | } | ||
2028 | |||
2029 | /** | ||
2030 | * _base_display_intel_branding - Display branding string | ||
2031 | * @ioc: per adapter object | ||
2032 | * | ||
2033 | * Return nothing. | ||
2034 | */ | ||
2035 | static void | ||
2036 | _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc) | ||
2037 | { | ||
2038 | if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) | ||
2039 | return; | ||
2040 | |||
2041 | switch (ioc->pdev->device) { | ||
2042 | case MPI2_MFGPAGE_DEVID_SAS2008: | ||
2043 | switch (ioc->pdev->subsystem_device) { | ||
2044 | case MPT2SAS_INTEL_RMS2LL080_SSDID: | ||
2045 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2046 | MPT2SAS_INTEL_RMS2LL080_BRANDING); | ||
2047 | break; | ||
2048 | case MPT2SAS_INTEL_RMS2LL040_SSDID: | ||
2049 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2050 | MPT2SAS_INTEL_RMS2LL040_BRANDING); | ||
2051 | break; | ||
2052 | case MPT2SAS_INTEL_SSD910_SSDID: | ||
2053 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2054 | MPT2SAS_INTEL_SSD910_BRANDING); | ||
2055 | break; | ||
2056 | default: | ||
2057 | break; | ||
2058 | } | ||
2059 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | ||
2060 | switch (ioc->pdev->subsystem_device) { | ||
2061 | case MPT2SAS_INTEL_RS25GB008_SSDID: | ||
2062 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2063 | MPT2SAS_INTEL_RS25GB008_BRANDING); | ||
2064 | break; | ||
2065 | case MPT2SAS_INTEL_RMS25JB080_SSDID: | ||
2066 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2067 | MPT2SAS_INTEL_RMS25JB080_BRANDING); | ||
2068 | break; | ||
2069 | case MPT2SAS_INTEL_RMS25JB040_SSDID: | ||
2070 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2071 | MPT2SAS_INTEL_RMS25JB040_BRANDING); | ||
2072 | break; | ||
2073 | case MPT2SAS_INTEL_RMS25KB080_SSDID: | ||
2074 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2075 | MPT2SAS_INTEL_RMS25KB080_BRANDING); | ||
2076 | break; | ||
2077 | case MPT2SAS_INTEL_RMS25KB040_SSDID: | ||
2078 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2079 | MPT2SAS_INTEL_RMS25KB040_BRANDING); | ||
2080 | break; | ||
2081 | case MPT2SAS_INTEL_RMS25LB040_SSDID: | ||
2082 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2083 | MPT2SAS_INTEL_RMS25LB040_BRANDING); | ||
2084 | break; | ||
2085 | case MPT2SAS_INTEL_RMS25LB080_SSDID: | ||
2086 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2087 | MPT2SAS_INTEL_RMS25LB080_BRANDING); | ||
2088 | break; | ||
2089 | default: | ||
2090 | break; | ||
2091 | } | ||
2092 | default: | ||
2093 | break; | ||
2094 | } | ||
2095 | } | ||
2096 | |||
2097 | /** | ||
2098 | * _base_display_hp_branding - Display branding string | ||
2099 | * @ioc: per adapter object | ||
2100 | * | ||
2101 | * Return nothing. | ||
2102 | */ | ||
2103 | static void | ||
2104 | _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc) | ||
2105 | { | ||
2106 | if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID) | ||
2107 | return; | ||
2108 | |||
2109 | switch (ioc->pdev->device) { | ||
2110 | case MPI2_MFGPAGE_DEVID_SAS2004: | ||
2111 | switch (ioc->pdev->subsystem_device) { | ||
2112 | case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID: | ||
2113 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2114 | MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING); | ||
2115 | break; | ||
2116 | default: | ||
2117 | break; | ||
2118 | } | ||
2119 | case MPI2_MFGPAGE_DEVID_SAS2308_2: | ||
2120 | switch (ioc->pdev->subsystem_device) { | ||
2121 | case MPT2SAS_HP_2_4_INTERNAL_SSDID: | ||
2122 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2123 | MPT2SAS_HP_2_4_INTERNAL_BRANDING); | ||
2124 | break; | ||
2125 | case MPT2SAS_HP_2_4_EXTERNAL_SSDID: | ||
2126 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2127 | MPT2SAS_HP_2_4_EXTERNAL_BRANDING); | ||
2128 | break; | ||
2129 | case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID: | ||
2130 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2131 | MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING); | ||
2132 | break; | ||
2133 | case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID: | ||
2134 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2135 | MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING); | ||
2136 | break; | ||
2137 | default: | ||
2138 | break; | ||
2139 | } | ||
2140 | default: | ||
2141 | break; | ||
2142 | } | ||
2143 | } | ||
2144 | |||
2145 | /** | ||
2146 | * _base_display_ioc_capabilities - Disply IOC's capabilities. | ||
2147 | * @ioc: per adapter object | ||
2148 | * | ||
2149 | * Return nothing. | ||
2150 | */ | ||
2151 | static void | ||
2152 | _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc) | ||
2153 | { | ||
2154 | int i = 0; | ||
2155 | char desc[16]; | ||
2156 | u32 iounit_pg1_flags; | ||
2157 | u32 bios_version; | ||
2158 | |||
2159 | bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); | ||
2160 | strncpy(desc, ioc->manu_pg0.ChipName, 16); | ||
2161 | printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), " | ||
2162 | "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n", | ||
2163 | ioc->name, desc, | ||
2164 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, | ||
2165 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, | ||
2166 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, | ||
2167 | ioc->facts.FWVersion.Word & 0x000000FF, | ||
2168 | ioc->pdev->revision, | ||
2169 | (bios_version & 0xFF000000) >> 24, | ||
2170 | (bios_version & 0x00FF0000) >> 16, | ||
2171 | (bios_version & 0x0000FF00) >> 8, | ||
2172 | bios_version & 0x000000FF); | ||
2173 | |||
2174 | _base_display_dell_branding(ioc); | ||
2175 | _base_display_intel_branding(ioc); | ||
2176 | _base_display_hp_branding(ioc); | ||
2177 | |||
2178 | printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name); | ||
2179 | |||
2180 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) { | ||
2181 | printk("Initiator"); | ||
2182 | i++; | ||
2183 | } | ||
2184 | |||
2185 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) { | ||
2186 | printk("%sTarget", i ? "," : ""); | ||
2187 | i++; | ||
2188 | } | ||
2189 | |||
2190 | i = 0; | ||
2191 | printk("), "); | ||
2192 | printk("Capabilities=("); | ||
2193 | |||
2194 | if (!ioc->hide_ir_msg) { | ||
2195 | if (ioc->facts.IOCCapabilities & | ||
2196 | MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) { | ||
2197 | printk("Raid"); | ||
2198 | i++; | ||
2199 | } | ||
2200 | } | ||
2201 | |||
2202 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) { | ||
2203 | printk("%sTLR", i ? "," : ""); | ||
2204 | i++; | ||
2205 | } | ||
2206 | |||
2207 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) { | ||
2208 | printk("%sMulticast", i ? "," : ""); | ||
2209 | i++; | ||
2210 | } | ||
2211 | |||
2212 | if (ioc->facts.IOCCapabilities & | ||
2213 | MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) { | ||
2214 | printk("%sBIDI Target", i ? "," : ""); | ||
2215 | i++; | ||
2216 | } | ||
2217 | |||
2218 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) { | ||
2219 | printk("%sEEDP", i ? "," : ""); | ||
2220 | i++; | ||
2221 | } | ||
2222 | |||
2223 | if (ioc->facts.IOCCapabilities & | ||
2224 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) { | ||
2225 | printk("%sSnapshot Buffer", i ? "," : ""); | ||
2226 | i++; | ||
2227 | } | ||
2228 | |||
2229 | if (ioc->facts.IOCCapabilities & | ||
2230 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) { | ||
2231 | printk("%sDiag Trace Buffer", i ? "," : ""); | ||
2232 | i++; | ||
2233 | } | ||
2234 | |||
2235 | if (ioc->facts.IOCCapabilities & | ||
2236 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) { | ||
2237 | printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : ""); | ||
2238 | i++; | ||
2239 | } | ||
2240 | |||
2241 | if (ioc->facts.IOCCapabilities & | ||
2242 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) { | ||
2243 | printk("%sTask Set Full", i ? "," : ""); | ||
2244 | i++; | ||
2245 | } | ||
2246 | |||
2247 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); | ||
2248 | if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) { | ||
2249 | printk("%sNCQ", i ? "," : ""); | ||
2250 | i++; | ||
2251 | } | ||
2252 | |||
2253 | printk(")\n"); | ||
2254 | } | ||
2255 | |||
2256 | /** | ||
2257 | * mpt2sas_base_update_missing_delay - change the missing delay timers | ||
2258 | * @ioc: per adapter object | ||
2259 | * @device_missing_delay: amount of time till device is reported missing | ||
2260 | * @io_missing_delay: interval IO is returned when there is a missing device | ||
2261 | * | ||
2262 | * Return nothing. | ||
2263 | * | ||
2264 | * Passed on the command line, this function will modify the device missing | ||
2265 | * delay, as well as the io missing delay. This should be called at driver | ||
2266 | * load time. | ||
2267 | */ | ||
2268 | void | ||
2269 | mpt2sas_base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc, | ||
2270 | u16 device_missing_delay, u8 io_missing_delay) | ||
2271 | { | ||
2272 | u16 dmd, dmd_new, dmd_orignal; | ||
2273 | u8 io_missing_delay_original; | ||
2274 | u16 sz; | ||
2275 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | ||
2276 | Mpi2ConfigReply_t mpi_reply; | ||
2277 | u8 num_phys = 0; | ||
2278 | u16 ioc_status; | ||
2279 | |||
2280 | mpt2sas_config_get_number_hba_phys(ioc, &num_phys); | ||
2281 | if (!num_phys) | ||
2282 | return; | ||
2283 | |||
2284 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys * | ||
2285 | sizeof(Mpi2SasIOUnit1PhyData_t)); | ||
2286 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | ||
2287 | if (!sas_iounit_pg1) { | ||
2288 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
2289 | ioc->name, __FILE__, __LINE__, __func__); | ||
2290 | goto out; | ||
2291 | } | ||
2292 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | ||
2293 | sas_iounit_pg1, sz))) { | ||
2294 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
2295 | ioc->name, __FILE__, __LINE__, __func__); | ||
2296 | goto out; | ||
2297 | } | ||
2298 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
2299 | MPI2_IOCSTATUS_MASK; | ||
2300 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
2301 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
2302 | ioc->name, __FILE__, __LINE__, __func__); | ||
2303 | goto out; | ||
2304 | } | ||
2305 | |||
2306 | /* device missing delay */ | ||
2307 | dmd = sas_iounit_pg1->ReportDeviceMissingDelay; | ||
2308 | if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | ||
2309 | dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | ||
2310 | else | ||
2311 | dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | ||
2312 | dmd_orignal = dmd; | ||
2313 | if (device_missing_delay > 0x7F) { | ||
2314 | dmd = (device_missing_delay > 0x7F0) ? 0x7F0 : | ||
2315 | device_missing_delay; | ||
2316 | dmd = dmd / 16; | ||
2317 | dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16; | ||
2318 | } else | ||
2319 | dmd = device_missing_delay; | ||
2320 | sas_iounit_pg1->ReportDeviceMissingDelay = dmd; | ||
2321 | |||
2322 | /* io missing delay */ | ||
2323 | io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay; | ||
2324 | sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay; | ||
2325 | |||
2326 | if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, | ||
2327 | sz)) { | ||
2328 | if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | ||
2329 | dmd_new = (dmd & | ||
2330 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | ||
2331 | else | ||
2332 | dmd_new = | ||
2333 | dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | ||
2334 | printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), " | ||
2335 | "new(%d)\n", ioc->name, dmd_orignal, dmd_new); | ||
2336 | printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), " | ||
2337 | "new(%d)\n", ioc->name, io_missing_delay_original, | ||
2338 | io_missing_delay); | ||
2339 | ioc->device_missing_delay = dmd_new; | ||
2340 | ioc->io_missing_delay = io_missing_delay; | ||
2341 | } | ||
2342 | |||
2343 | out: | ||
2344 | kfree(sas_iounit_pg1); | ||
2345 | } | ||
2346 | |||
2347 | /** | ||
2348 | * _base_static_config_pages - static start of day config pages | ||
2349 | * @ioc: per adapter object | ||
2350 | * | ||
2351 | * Return nothing. | ||
2352 | */ | ||
2353 | static void | ||
2354 | _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc) | ||
2355 | { | ||
2356 | Mpi2ConfigReply_t mpi_reply; | ||
2357 | u32 iounit_pg1_flags; | ||
2358 | |||
2359 | mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0); | ||
2360 | if (ioc->ir_firmware) | ||
2361 | mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply, | ||
2362 | &ioc->manu_pg10); | ||
2363 | mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2); | ||
2364 | mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3); | ||
2365 | mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8); | ||
2366 | mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0); | ||
2367 | mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); | ||
2368 | mpt2sas_config_get_iounit_pg8(ioc, &mpi_reply, &ioc->iounit_pg8); | ||
2369 | _base_display_ioc_capabilities(ioc); | ||
2370 | |||
2371 | /* | ||
2372 | * Enable task_set_full handling in iounit_pg1 when the | ||
2373 | * facts capabilities indicate that its supported. | ||
2374 | */ | ||
2375 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); | ||
2376 | if ((ioc->facts.IOCCapabilities & | ||
2377 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING)) | ||
2378 | iounit_pg1_flags &= | ||
2379 | ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; | ||
2380 | else | ||
2381 | iounit_pg1_flags |= | ||
2382 | MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; | ||
2383 | ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags); | ||
2384 | mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); | ||
2385 | |||
2386 | if (ioc->iounit_pg8.NumSensors) | ||
2387 | ioc->temp_sensors_count = ioc->iounit_pg8.NumSensors; | ||
2388 | } | ||
2389 | |||
2390 | /** | ||
2391 | * _base_release_memory_pools - release memory | ||
2392 | * @ioc: per adapter object | ||
2393 | * | ||
2394 | * Free memory allocated from _base_allocate_memory_pools. | ||
2395 | * | ||
2396 | * Return nothing. | ||
2397 | */ | ||
2398 | static void | ||
2399 | _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc) | ||
2400 | { | ||
2401 | int i = 0; | ||
2402 | struct reply_post_struct *rps; | ||
2403 | |||
2404 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2405 | __func__)); | ||
2406 | |||
2407 | if (ioc->request) { | ||
2408 | pci_free_consistent(ioc->pdev, ioc->request_dma_sz, | ||
2409 | ioc->request, ioc->request_dma); | ||
2410 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)" | ||
2411 | ": free\n", ioc->name, ioc->request)); | ||
2412 | ioc->request = NULL; | ||
2413 | } | ||
2414 | |||
2415 | if (ioc->sense) { | ||
2416 | pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma); | ||
2417 | if (ioc->sense_dma_pool) | ||
2418 | pci_pool_destroy(ioc->sense_dma_pool); | ||
2419 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)" | ||
2420 | ": free\n", ioc->name, ioc->sense)); | ||
2421 | ioc->sense = NULL; | ||
2422 | } | ||
2423 | |||
2424 | if (ioc->reply) { | ||
2425 | pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma); | ||
2426 | if (ioc->reply_dma_pool) | ||
2427 | pci_pool_destroy(ioc->reply_dma_pool); | ||
2428 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)" | ||
2429 | ": free\n", ioc->name, ioc->reply)); | ||
2430 | ioc->reply = NULL; | ||
2431 | } | ||
2432 | |||
2433 | if (ioc->reply_free) { | ||
2434 | pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free, | ||
2435 | ioc->reply_free_dma); | ||
2436 | if (ioc->reply_free_dma_pool) | ||
2437 | pci_pool_destroy(ioc->reply_free_dma_pool); | ||
2438 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool" | ||
2439 | "(0x%p): free\n", ioc->name, ioc->reply_free)); | ||
2440 | ioc->reply_free = NULL; | ||
2441 | } | ||
2442 | |||
2443 | if (ioc->reply_post) { | ||
2444 | do { | ||
2445 | rps = &ioc->reply_post[i]; | ||
2446 | if (rps->reply_post_free) { | ||
2447 | pci_pool_free( | ||
2448 | ioc->reply_post_free_dma_pool, | ||
2449 | rps->reply_post_free, | ||
2450 | rps->reply_post_free_dma); | ||
2451 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2452 | "reply_post_free_pool(0x%p): free\n", | ||
2453 | ioc->name, rps->reply_post_free)); | ||
2454 | rps->reply_post_free = NULL; | ||
2455 | } | ||
2456 | } while (ioc->rdpq_array_enable && | ||
2457 | (++i < ioc->reply_queue_count)); | ||
2458 | |||
2459 | if (ioc->reply_post_free_dma_pool) | ||
2460 | pci_pool_destroy(ioc->reply_post_free_dma_pool); | ||
2461 | kfree(ioc->reply_post); | ||
2462 | } | ||
2463 | |||
2464 | if (ioc->config_page) { | ||
2465 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2466 | "config_page(0x%p): free\n", ioc->name, | ||
2467 | ioc->config_page)); | ||
2468 | pci_free_consistent(ioc->pdev, ioc->config_page_sz, | ||
2469 | ioc->config_page, ioc->config_page_dma); | ||
2470 | } | ||
2471 | |||
2472 | if (ioc->scsi_lookup) { | ||
2473 | free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages); | ||
2474 | ioc->scsi_lookup = NULL; | ||
2475 | } | ||
2476 | kfree(ioc->hpr_lookup); | ||
2477 | kfree(ioc->internal_lookup); | ||
2478 | if (ioc->chain_lookup) { | ||
2479 | for (i = 0; i < ioc->chain_depth; i++) { | ||
2480 | if (ioc->chain_lookup[i].chain_buffer) | ||
2481 | pci_pool_free(ioc->chain_dma_pool, | ||
2482 | ioc->chain_lookup[i].chain_buffer, | ||
2483 | ioc->chain_lookup[i].chain_buffer_dma); | ||
2484 | } | ||
2485 | if (ioc->chain_dma_pool) | ||
2486 | pci_pool_destroy(ioc->chain_dma_pool); | ||
2487 | free_pages((ulong)ioc->chain_lookup, ioc->chain_pages); | ||
2488 | ioc->chain_lookup = NULL; | ||
2489 | } | ||
2490 | } | ||
2491 | |||
2492 | |||
2493 | /** | ||
2494 | * _base_allocate_memory_pools - allocate start of day memory pools | ||
2495 | * @ioc: per adapter object | ||
2496 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
2497 | * | ||
2498 | * Returns 0 success, anything else error | ||
2499 | */ | ||
2500 | static int | ||
2501 | _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
2502 | { | ||
2503 | struct mpt2sas_facts *facts; | ||
2504 | u16 max_sge_elements; | ||
2505 | u16 chains_needed_per_io; | ||
2506 | u32 sz, total_sz, reply_post_free_sz; | ||
2507 | u32 retry_sz; | ||
2508 | u16 max_request_credit; | ||
2509 | int i; | ||
2510 | |||
2511 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
2512 | __func__)); | ||
2513 | |||
2514 | retry_sz = 0; | ||
2515 | facts = &ioc->facts; | ||
2516 | |||
2517 | /* command line tunables for max sgl entries */ | ||
2518 | if (max_sgl_entries != -1) { | ||
2519 | ioc->shost->sg_tablesize = min_t(unsigned short, | ||
2520 | max_sgl_entries, SCSI_MAX_SG_CHAIN_SEGMENTS); | ||
2521 | if (ioc->shost->sg_tablesize > MPT2SAS_SG_DEPTH) | ||
2522 | printk(MPT2SAS_WARN_FMT | ||
2523 | "sg_tablesize(%u) is bigger than kernel defined" | ||
2524 | " SCSI_MAX_SG_SEGMENTS(%u)\n", ioc->name, | ||
2525 | ioc->shost->sg_tablesize, MPT2SAS_SG_DEPTH); | ||
2526 | } else { | ||
2527 | ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH; | ||
2528 | } | ||
2529 | |||
2530 | /* command line tunables for max controller queue depth */ | ||
2531 | if (max_queue_depth != -1 && max_queue_depth != 0) { | ||
2532 | max_request_credit = min_t(u16, max_queue_depth + | ||
2533 | ioc->hi_priority_depth + ioc->internal_depth, | ||
2534 | facts->RequestCredit); | ||
2535 | if (max_request_credit > MAX_HBA_QUEUE_DEPTH) | ||
2536 | max_request_credit = MAX_HBA_QUEUE_DEPTH; | ||
2537 | } else | ||
2538 | max_request_credit = min_t(u16, facts->RequestCredit, | ||
2539 | MAX_HBA_QUEUE_DEPTH); | ||
2540 | |||
2541 | ioc->hba_queue_depth = max_request_credit; | ||
2542 | ioc->hi_priority_depth = facts->HighPriorityCredit; | ||
2543 | ioc->internal_depth = ioc->hi_priority_depth + 5; | ||
2544 | |||
2545 | /* request frame size */ | ||
2546 | ioc->request_sz = facts->IOCRequestFrameSize * 4; | ||
2547 | |||
2548 | /* reply frame size */ | ||
2549 | ioc->reply_sz = facts->ReplyFrameSize * 4; | ||
2550 | |||
2551 | retry_allocation: | ||
2552 | total_sz = 0; | ||
2553 | /* calculate number of sg elements left over in the 1st frame */ | ||
2554 | max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) - | ||
2555 | sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size); | ||
2556 | ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size; | ||
2557 | |||
2558 | /* now do the same for a chain buffer */ | ||
2559 | max_sge_elements = ioc->request_sz - ioc->sge_size; | ||
2560 | ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size; | ||
2561 | |||
2562 | ioc->chain_offset_value_for_main_message = | ||
2563 | ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) + | ||
2564 | (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4; | ||
2565 | |||
2566 | /* | ||
2567 | * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE | ||
2568 | */ | ||
2569 | chains_needed_per_io = ((ioc->shost->sg_tablesize - | ||
2570 | ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message) | ||
2571 | + 1; | ||
2572 | if (chains_needed_per_io > facts->MaxChainDepth) { | ||
2573 | chains_needed_per_io = facts->MaxChainDepth; | ||
2574 | ioc->shost->sg_tablesize = min_t(u16, | ||
2575 | ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message | ||
2576 | * chains_needed_per_io), ioc->shost->sg_tablesize); | ||
2577 | } | ||
2578 | ioc->chains_needed_per_io = chains_needed_per_io; | ||
2579 | |||
2580 | /* reply free queue sizing - taking into account for 64 FW events */ | ||
2581 | ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; | ||
2582 | |||
2583 | /* calculate reply descriptor post queue depth */ | ||
2584 | ioc->reply_post_queue_depth = ioc->hba_queue_depth + | ||
2585 | ioc->reply_free_queue_depth + 1; | ||
2586 | /* align the reply post queue on the next 16 count boundary */ | ||
2587 | if (ioc->reply_post_queue_depth % 16) | ||
2588 | ioc->reply_post_queue_depth += 16 - | ||
2589 | (ioc->reply_post_queue_depth % 16); | ||
2590 | |||
2591 | |||
2592 | if (ioc->reply_post_queue_depth > | ||
2593 | facts->MaxReplyDescriptorPostQueueDepth) { | ||
2594 | ioc->reply_post_queue_depth = | ||
2595 | facts->MaxReplyDescriptorPostQueueDepth - | ||
2596 | (facts->MaxReplyDescriptorPostQueueDepth % 16); | ||
2597 | ioc->hba_queue_depth = | ||
2598 | ((ioc->reply_post_queue_depth - 64) / 2) - 1; | ||
2599 | ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; | ||
2600 | } | ||
2601 | |||
2602 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: " | ||
2603 | "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), " | ||
2604 | "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message, | ||
2605 | ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize, | ||
2606 | ioc->chains_needed_per_io)); | ||
2607 | |||
2608 | /* reply post queue, 16 byte align */ | ||
2609 | reply_post_free_sz = ioc->reply_post_queue_depth * | ||
2610 | sizeof(Mpi2DefaultReplyDescriptor_t); | ||
2611 | |||
2612 | sz = reply_post_free_sz; | ||
2613 | if (_base_is_controller_msix_enabled(ioc) && !ioc->rdpq_array_enable) | ||
2614 | sz *= ioc->reply_queue_count; | ||
2615 | |||
2616 | ioc->reply_post = kcalloc((ioc->rdpq_array_enable) ? | ||
2617 | (ioc->reply_queue_count):1, | ||
2618 | sizeof(struct reply_post_struct), GFP_KERNEL); | ||
2619 | |||
2620 | if (!ioc->reply_post) { | ||
2621 | printk(MPT2SAS_ERR_FMT "reply_post_free pool: kcalloc failed\n", | ||
2622 | ioc->name); | ||
2623 | goto out; | ||
2624 | } | ||
2625 | ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool", | ||
2626 | ioc->pdev, sz, 16, 0); | ||
2627 | if (!ioc->reply_post_free_dma_pool) { | ||
2628 | printk(MPT2SAS_ERR_FMT | ||
2629 | "reply_post_free pool: pci_pool_create failed\n", | ||
2630 | ioc->name); | ||
2631 | goto out; | ||
2632 | } | ||
2633 | i = 0; | ||
2634 | do { | ||
2635 | ioc->reply_post[i].reply_post_free = | ||
2636 | pci_pool_alloc(ioc->reply_post_free_dma_pool, | ||
2637 | GFP_KERNEL, | ||
2638 | &ioc->reply_post[i].reply_post_free_dma); | ||
2639 | if (!ioc->reply_post[i].reply_post_free) { | ||
2640 | printk(MPT2SAS_ERR_FMT | ||
2641 | "reply_post_free pool: pci_pool_alloc failed\n", | ||
2642 | ioc->name); | ||
2643 | goto out; | ||
2644 | } | ||
2645 | memset(ioc->reply_post[i].reply_post_free, 0, sz); | ||
2646 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2647 | "reply post free pool (0x%p): depth(%d)," | ||
2648 | "element_size(%d), pool_size(%d kB)\n", ioc->name, | ||
2649 | ioc->reply_post[i].reply_post_free, | ||
2650 | ioc->reply_post_queue_depth, 8, sz/1024)); | ||
2651 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2652 | "reply_post_free_dma = (0x%llx)\n", ioc->name, | ||
2653 | (unsigned long long) | ||
2654 | ioc->reply_post[i].reply_post_free_dma)); | ||
2655 | total_sz += sz; | ||
2656 | } while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count)); | ||
2657 | |||
2658 | if (ioc->dma_mask == 64) { | ||
2659 | if (_base_change_consistent_dma_mask(ioc, ioc->pdev) != 0) { | ||
2660 | printk(MPT2SAS_WARN_FMT | ||
2661 | "no suitable consistent DMA mask for %s\n", | ||
2662 | ioc->name, pci_name(ioc->pdev)); | ||
2663 | goto out; | ||
2664 | } | ||
2665 | } | ||
2666 | |||
2667 | ioc->scsiio_depth = ioc->hba_queue_depth - | ||
2668 | ioc->hi_priority_depth - ioc->internal_depth; | ||
2669 | |||
2670 | /* set the scsi host can_queue depth | ||
2671 | * with some internal commands that could be outstanding | ||
2672 | */ | ||
2673 | ioc->shost->can_queue = ioc->scsiio_depth; | ||
2674 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: " | ||
2675 | "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue)); | ||
2676 | |||
2677 | /* contiguous pool for request and chains, 16 byte align, one extra " | ||
2678 | * "frame for smid=0 | ||
2679 | */ | ||
2680 | ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth; | ||
2681 | sz = ((ioc->scsiio_depth + 1) * ioc->request_sz); | ||
2682 | |||
2683 | /* hi-priority queue */ | ||
2684 | sz += (ioc->hi_priority_depth * ioc->request_sz); | ||
2685 | |||
2686 | /* internal queue */ | ||
2687 | sz += (ioc->internal_depth * ioc->request_sz); | ||
2688 | |||
2689 | ioc->request_dma_sz = sz; | ||
2690 | ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma); | ||
2691 | if (!ioc->request) { | ||
2692 | printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent " | ||
2693 | "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " | ||
2694 | "total(%d kB)\n", ioc->name, ioc->hba_queue_depth, | ||
2695 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); | ||
2696 | if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH) | ||
2697 | goto out; | ||
2698 | retry_sz += 64; | ||
2699 | ioc->hba_queue_depth = max_request_credit - retry_sz; | ||
2700 | goto retry_allocation; | ||
2701 | } | ||
2702 | |||
2703 | if (retry_sz) | ||
2704 | printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent " | ||
2705 | "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " | ||
2706 | "total(%d kb)\n", ioc->name, ioc->hba_queue_depth, | ||
2707 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); | ||
2708 | |||
2709 | |||
2710 | /* hi-priority queue */ | ||
2711 | ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) * | ||
2712 | ioc->request_sz); | ||
2713 | ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) * | ||
2714 | ioc->request_sz); | ||
2715 | |||
2716 | /* internal queue */ | ||
2717 | ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth * | ||
2718 | ioc->request_sz); | ||
2719 | ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth * | ||
2720 | ioc->request_sz); | ||
2721 | |||
2722 | |||
2723 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): " | ||
2724 | "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, | ||
2725 | ioc->request, ioc->hba_queue_depth, ioc->request_sz, | ||
2726 | (ioc->hba_queue_depth * ioc->request_sz)/1024)); | ||
2727 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n", | ||
2728 | ioc->name, (unsigned long long) ioc->request_dma)); | ||
2729 | total_sz += sz; | ||
2730 | |||
2731 | sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker); | ||
2732 | ioc->scsi_lookup_pages = get_order(sz); | ||
2733 | ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages( | ||
2734 | GFP_KERNEL, ioc->scsi_lookup_pages); | ||
2735 | if (!ioc->scsi_lookup) { | ||
2736 | printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, " | ||
2737 | "sz(%d)\n", ioc->name, (int)sz); | ||
2738 | goto out; | ||
2739 | } | ||
2740 | |||
2741 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): " | ||
2742 | "depth(%d)\n", ioc->name, ioc->request, | ||
2743 | ioc->scsiio_depth)); | ||
2744 | |||
2745 | ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH); | ||
2746 | sz = ioc->chain_depth * sizeof(struct chain_tracker); | ||
2747 | ioc->chain_pages = get_order(sz); | ||
2748 | |||
2749 | ioc->chain_lookup = (struct chain_tracker *)__get_free_pages( | ||
2750 | GFP_KERNEL, ioc->chain_pages); | ||
2751 | if (!ioc->chain_lookup) { | ||
2752 | printk(MPT2SAS_ERR_FMT "chain_lookup: get_free_pages failed, " | ||
2753 | "sz(%d)\n", ioc->name, (int)sz); | ||
2754 | goto out; | ||
2755 | } | ||
2756 | ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev, | ||
2757 | ioc->request_sz, 16, 0); | ||
2758 | if (!ioc->chain_dma_pool) { | ||
2759 | printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create " | ||
2760 | "failed\n", ioc->name); | ||
2761 | goto out; | ||
2762 | } | ||
2763 | for (i = 0; i < ioc->chain_depth; i++) { | ||
2764 | ioc->chain_lookup[i].chain_buffer = pci_pool_alloc( | ||
2765 | ioc->chain_dma_pool , GFP_KERNEL, | ||
2766 | &ioc->chain_lookup[i].chain_buffer_dma); | ||
2767 | if (!ioc->chain_lookup[i].chain_buffer) { | ||
2768 | ioc->chain_depth = i; | ||
2769 | goto chain_done; | ||
2770 | } | ||
2771 | total_sz += ioc->request_sz; | ||
2772 | } | ||
2773 | chain_done: | ||
2774 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth" | ||
2775 | "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, | ||
2776 | ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth * | ||
2777 | ioc->request_sz))/1024)); | ||
2778 | |||
2779 | /* initialize hi-priority queue smid's */ | ||
2780 | ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth, | ||
2781 | sizeof(struct request_tracker), GFP_KERNEL); | ||
2782 | if (!ioc->hpr_lookup) { | ||
2783 | printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n", | ||
2784 | ioc->name); | ||
2785 | goto out; | ||
2786 | } | ||
2787 | ioc->hi_priority_smid = ioc->scsiio_depth + 1; | ||
2788 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): " | ||
2789 | "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority, | ||
2790 | ioc->hi_priority_depth, ioc->hi_priority_smid)); | ||
2791 | |||
2792 | /* initialize internal queue smid's */ | ||
2793 | ioc->internal_lookup = kcalloc(ioc->internal_depth, | ||
2794 | sizeof(struct request_tracker), GFP_KERNEL); | ||
2795 | if (!ioc->internal_lookup) { | ||
2796 | printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n", | ||
2797 | ioc->name); | ||
2798 | goto out; | ||
2799 | } | ||
2800 | ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth; | ||
2801 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): " | ||
2802 | "depth(%d), start smid(%d)\n", ioc->name, ioc->internal, | ||
2803 | ioc->internal_depth, ioc->internal_smid)); | ||
2804 | |||
2805 | /* sense buffers, 4 byte align */ | ||
2806 | sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE; | ||
2807 | ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4, | ||
2808 | 0); | ||
2809 | if (!ioc->sense_dma_pool) { | ||
2810 | printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n", | ||
2811 | ioc->name); | ||
2812 | goto out; | ||
2813 | } | ||
2814 | ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL, | ||
2815 | &ioc->sense_dma); | ||
2816 | if (!ioc->sense) { | ||
2817 | printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n", | ||
2818 | ioc->name); | ||
2819 | goto out; | ||
2820 | } | ||
2821 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2822 | "sense pool(0x%p): depth(%d), element_size(%d), pool_size" | ||
2823 | "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth, | ||
2824 | SCSI_SENSE_BUFFERSIZE, sz/1024)); | ||
2825 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n", | ||
2826 | ioc->name, (unsigned long long)ioc->sense_dma)); | ||
2827 | total_sz += sz; | ||
2828 | |||
2829 | /* reply pool, 4 byte align */ | ||
2830 | sz = ioc->reply_free_queue_depth * ioc->reply_sz; | ||
2831 | ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4, | ||
2832 | 0); | ||
2833 | if (!ioc->reply_dma_pool) { | ||
2834 | printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n", | ||
2835 | ioc->name); | ||
2836 | goto out; | ||
2837 | } | ||
2838 | ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL, | ||
2839 | &ioc->reply_dma); | ||
2840 | if (!ioc->reply) { | ||
2841 | printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n", | ||
2842 | ioc->name); | ||
2843 | goto out; | ||
2844 | } | ||
2845 | ioc->reply_dma_min_address = (u32)(ioc->reply_dma); | ||
2846 | ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz; | ||
2847 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth" | ||
2848 | "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply, | ||
2849 | ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024)); | ||
2850 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n", | ||
2851 | ioc->name, (unsigned long long)ioc->reply_dma)); | ||
2852 | total_sz += sz; | ||
2853 | |||
2854 | /* reply free queue, 16 byte align */ | ||
2855 | sz = ioc->reply_free_queue_depth * 4; | ||
2856 | ioc->reply_free_dma_pool = pci_pool_create("reply_free pool", | ||
2857 | ioc->pdev, sz, 16, 0); | ||
2858 | if (!ioc->reply_free_dma_pool) { | ||
2859 | printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create " | ||
2860 | "failed\n", ioc->name); | ||
2861 | goto out; | ||
2862 | } | ||
2863 | ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL, | ||
2864 | &ioc->reply_free_dma); | ||
2865 | if (!ioc->reply_free) { | ||
2866 | printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc " | ||
2867 | "failed\n", ioc->name); | ||
2868 | goto out; | ||
2869 | } | ||
2870 | memset(ioc->reply_free, 0, sz); | ||
2871 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): " | ||
2872 | "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name, | ||
2873 | ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024)); | ||
2874 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma" | ||
2875 | "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma)); | ||
2876 | total_sz += sz; | ||
2877 | |||
2878 | ioc->config_page_sz = 512; | ||
2879 | ioc->config_page = pci_alloc_consistent(ioc->pdev, | ||
2880 | ioc->config_page_sz, &ioc->config_page_dma); | ||
2881 | if (!ioc->config_page) { | ||
2882 | printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc " | ||
2883 | "failed\n", ioc->name); | ||
2884 | goto out; | ||
2885 | } | ||
2886 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size" | ||
2887 | "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz)); | ||
2888 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma" | ||
2889 | "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma)); | ||
2890 | total_sz += ioc->config_page_sz; | ||
2891 | |||
2892 | printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n", | ||
2893 | ioc->name, total_sz/1024); | ||
2894 | printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), " | ||
2895 | "Max Controller Queue Depth(%d)\n", | ||
2896 | ioc->name, ioc->shost->can_queue, facts->RequestCredit); | ||
2897 | printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n", | ||
2898 | ioc->name, ioc->shost->sg_tablesize); | ||
2899 | return 0; | ||
2900 | |||
2901 | out: | ||
2902 | return -ENOMEM; | ||
2903 | } | ||
2904 | |||
2905 | |||
2906 | /** | ||
2907 | * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter. | ||
2908 | * @ioc: Pointer to MPT_ADAPTER structure | ||
2909 | * @cooked: Request raw or cooked IOC state | ||
2910 | * | ||
2911 | * Returns all IOC Doorbell register bits if cooked==0, else just the | ||
2912 | * Doorbell bits in MPI_IOC_STATE_MASK. | ||
2913 | */ | ||
2914 | u32 | ||
2915 | mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked) | ||
2916 | { | ||
2917 | u32 s, sc; | ||
2918 | |||
2919 | s = readl(&ioc->chip->Doorbell); | ||
2920 | sc = s & MPI2_IOC_STATE_MASK; | ||
2921 | return cooked ? sc : s; | ||
2922 | } | ||
2923 | |||
2924 | /** | ||
2925 | * _base_wait_on_iocstate - waiting on a particular ioc state | ||
2926 | * @ioc_state: controller state { READY, OPERATIONAL, or RESET } | ||
2927 | * @timeout: timeout in second | ||
2928 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
2929 | * | ||
2930 | * Returns 0 for success, non-zero for failure. | ||
2931 | */ | ||
2932 | static int | ||
2933 | _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout, | ||
2934 | int sleep_flag) | ||
2935 | { | ||
2936 | u32 count, cntdn; | ||
2937 | u32 current_state; | ||
2938 | |||
2939 | count = 0; | ||
2940 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; | ||
2941 | do { | ||
2942 | current_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
2943 | if (current_state == ioc_state) | ||
2944 | return 0; | ||
2945 | if (count && current_state == MPI2_IOC_STATE_FAULT) | ||
2946 | break; | ||
2947 | if (sleep_flag == CAN_SLEEP) | ||
2948 | msleep(1); | ||
2949 | else | ||
2950 | udelay(500); | ||
2951 | count++; | ||
2952 | } while (--cntdn); | ||
2953 | |||
2954 | return current_state; | ||
2955 | } | ||
2956 | |||
2957 | /** | ||
2958 | * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by | ||
2959 | * a write to the doorbell) | ||
2960 | * @ioc: per adapter object | ||
2961 | * @timeout: timeout in second | ||
2962 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
2963 | * | ||
2964 | * Returns 0 for success, non-zero for failure. | ||
2965 | * | ||
2966 | * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell. | ||
2967 | */ | ||
2968 | static int | ||
2969 | _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout, | ||
2970 | int sleep_flag) | ||
2971 | { | ||
2972 | u32 cntdn, count; | ||
2973 | u32 int_status; | ||
2974 | |||
2975 | count = 0; | ||
2976 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; | ||
2977 | do { | ||
2978 | int_status = readl(&ioc->chip->HostInterruptStatus); | ||
2979 | if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { | ||
2980 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
2981 | "successful count(%d), timeout(%d)\n", ioc->name, | ||
2982 | __func__, count, timeout)); | ||
2983 | return 0; | ||
2984 | } | ||
2985 | if (sleep_flag == CAN_SLEEP) | ||
2986 | msleep(1); | ||
2987 | else | ||
2988 | udelay(500); | ||
2989 | count++; | ||
2990 | } while (--cntdn); | ||
2991 | |||
2992 | printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), " | ||
2993 | "int_status(%x)!\n", ioc->name, __func__, count, int_status); | ||
2994 | return -EFAULT; | ||
2995 | } | ||
2996 | |||
2997 | /** | ||
2998 | * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell. | ||
2999 | * @ioc: per adapter object | ||
3000 | * @timeout: timeout in second | ||
3001 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3002 | * | ||
3003 | * Returns 0 for success, non-zero for failure. | ||
3004 | * | ||
3005 | * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to | ||
3006 | * doorbell. | ||
3007 | */ | ||
3008 | static int | ||
3009 | _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout, | ||
3010 | int sleep_flag) | ||
3011 | { | ||
3012 | u32 cntdn, count; | ||
3013 | u32 int_status; | ||
3014 | u32 doorbell; | ||
3015 | |||
3016 | count = 0; | ||
3017 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; | ||
3018 | do { | ||
3019 | int_status = readl(&ioc->chip->HostInterruptStatus); | ||
3020 | if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) { | ||
3021 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
3022 | "successful count(%d), timeout(%d)\n", ioc->name, | ||
3023 | __func__, count, timeout)); | ||
3024 | return 0; | ||
3025 | } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { | ||
3026 | doorbell = readl(&ioc->chip->Doorbell); | ||
3027 | if ((doorbell & MPI2_IOC_STATE_MASK) == | ||
3028 | MPI2_IOC_STATE_FAULT) { | ||
3029 | mpt2sas_base_fault_info(ioc , doorbell); | ||
3030 | return -EFAULT; | ||
3031 | } | ||
3032 | } else if (int_status == 0xFFFFFFFF) | ||
3033 | goto out; | ||
3034 | |||
3035 | if (sleep_flag == CAN_SLEEP) | ||
3036 | msleep(1); | ||
3037 | else | ||
3038 | udelay(500); | ||
3039 | count++; | ||
3040 | } while (--cntdn); | ||
3041 | |||
3042 | out: | ||
3043 | printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), " | ||
3044 | "int_status(%x)!\n", ioc->name, __func__, count, int_status); | ||
3045 | return -EFAULT; | ||
3046 | } | ||
3047 | |||
3048 | /** | ||
3049 | * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use | ||
3050 | * @ioc: per adapter object | ||
3051 | * @timeout: timeout in second | ||
3052 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3053 | * | ||
3054 | * Returns 0 for success, non-zero for failure. | ||
3055 | * | ||
3056 | */ | ||
3057 | static int | ||
3058 | _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout, | ||
3059 | int sleep_flag) | ||
3060 | { | ||
3061 | u32 cntdn, count; | ||
3062 | u32 doorbell_reg; | ||
3063 | |||
3064 | count = 0; | ||
3065 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; | ||
3066 | do { | ||
3067 | doorbell_reg = readl(&ioc->chip->Doorbell); | ||
3068 | if (!(doorbell_reg & MPI2_DOORBELL_USED)) { | ||
3069 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
3070 | "successful count(%d), timeout(%d)\n", ioc->name, | ||
3071 | __func__, count, timeout)); | ||
3072 | return 0; | ||
3073 | } | ||
3074 | if (sleep_flag == CAN_SLEEP) | ||
3075 | msleep(1); | ||
3076 | else | ||
3077 | udelay(500); | ||
3078 | count++; | ||
3079 | } while (--cntdn); | ||
3080 | |||
3081 | printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), " | ||
3082 | "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg); | ||
3083 | return -EFAULT; | ||
3084 | } | ||
3085 | |||
3086 | /** | ||
3087 | * _base_send_ioc_reset - send doorbell reset | ||
3088 | * @ioc: per adapter object | ||
3089 | * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET | ||
3090 | * @timeout: timeout in second | ||
3091 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3092 | * | ||
3093 | * Returns 0 for success, non-zero for failure. | ||
3094 | */ | ||
3095 | static int | ||
3096 | _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout, | ||
3097 | int sleep_flag) | ||
3098 | { | ||
3099 | u32 ioc_state; | ||
3100 | int r = 0; | ||
3101 | |||
3102 | if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) { | ||
3103 | printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n", | ||
3104 | ioc->name, __func__); | ||
3105 | return -EFAULT; | ||
3106 | } | ||
3107 | |||
3108 | if (!(ioc->facts.IOCCapabilities & | ||
3109 | MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY)) | ||
3110 | return -EFAULT; | ||
3111 | |||
3112 | printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name); | ||
3113 | |||
3114 | writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT, | ||
3115 | &ioc->chip->Doorbell); | ||
3116 | if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) { | ||
3117 | r = -EFAULT; | ||
3118 | goto out; | ||
3119 | } | ||
3120 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, | ||
3121 | timeout, sleep_flag); | ||
3122 | if (ioc_state) { | ||
3123 | printk(MPT2SAS_ERR_FMT "%s: failed going to ready state " | ||
3124 | " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state); | ||
3125 | r = -EFAULT; | ||
3126 | goto out; | ||
3127 | } | ||
3128 | out: | ||
3129 | printk(MPT2SAS_INFO_FMT "message unit reset: %s\n", | ||
3130 | ioc->name, ((r == 0) ? "SUCCESS" : "FAILED")); | ||
3131 | return r; | ||
3132 | } | ||
3133 | |||
3134 | /** | ||
3135 | * _base_handshake_req_reply_wait - send request thru doorbell interface | ||
3136 | * @ioc: per adapter object | ||
3137 | * @request_bytes: request length | ||
3138 | * @request: pointer having request payload | ||
3139 | * @reply_bytes: reply length | ||
3140 | * @reply: pointer to reply payload | ||
3141 | * @timeout: timeout in second | ||
3142 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3143 | * | ||
3144 | * Returns 0 for success, non-zero for failure. | ||
3145 | */ | ||
3146 | static int | ||
3147 | _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes, | ||
3148 | u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag) | ||
3149 | { | ||
3150 | MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply; | ||
3151 | int i; | ||
3152 | u8 failed; | ||
3153 | u16 dummy; | ||
3154 | __le32 *mfp; | ||
3155 | |||
3156 | /* make sure doorbell is not in use */ | ||
3157 | if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) { | ||
3158 | printk(MPT2SAS_ERR_FMT "doorbell is in use " | ||
3159 | " (line=%d)\n", ioc->name, __LINE__); | ||
3160 | return -EFAULT; | ||
3161 | } | ||
3162 | |||
3163 | /* clear pending doorbell interrupts from previous state changes */ | ||
3164 | if (readl(&ioc->chip->HostInterruptStatus) & | ||
3165 | MPI2_HIS_IOC2SYS_DB_STATUS) | ||
3166 | writel(0, &ioc->chip->HostInterruptStatus); | ||
3167 | |||
3168 | /* send message to ioc */ | ||
3169 | writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) | | ||
3170 | ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)), | ||
3171 | &ioc->chip->Doorbell); | ||
3172 | |||
3173 | if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) { | ||
3174 | printk(MPT2SAS_ERR_FMT "doorbell handshake " | ||
3175 | "int failed (line=%d)\n", ioc->name, __LINE__); | ||
3176 | return -EFAULT; | ||
3177 | } | ||
3178 | writel(0, &ioc->chip->HostInterruptStatus); | ||
3179 | |||
3180 | if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) { | ||
3181 | printk(MPT2SAS_ERR_FMT "doorbell handshake " | ||
3182 | "ack failed (line=%d)\n", ioc->name, __LINE__); | ||
3183 | return -EFAULT; | ||
3184 | } | ||
3185 | |||
3186 | /* send message 32-bits at a time */ | ||
3187 | for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) { | ||
3188 | writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell); | ||
3189 | if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) | ||
3190 | failed = 1; | ||
3191 | } | ||
3192 | |||
3193 | if (failed) { | ||
3194 | printk(MPT2SAS_ERR_FMT "doorbell handshake " | ||
3195 | "sending request failed (line=%d)\n", ioc->name, __LINE__); | ||
3196 | return -EFAULT; | ||
3197 | } | ||
3198 | |||
3199 | /* now wait for the reply */ | ||
3200 | if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) { | ||
3201 | printk(MPT2SAS_ERR_FMT "doorbell handshake " | ||
3202 | "int failed (line=%d)\n", ioc->name, __LINE__); | ||
3203 | return -EFAULT; | ||
3204 | } | ||
3205 | |||
3206 | /* read the first two 16-bits, it gives the total length of the reply */ | ||
3207 | reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell) | ||
3208 | & MPI2_DOORBELL_DATA_MASK); | ||
3209 | writel(0, &ioc->chip->HostInterruptStatus); | ||
3210 | if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) { | ||
3211 | printk(MPT2SAS_ERR_FMT "doorbell handshake " | ||
3212 | "int failed (line=%d)\n", ioc->name, __LINE__); | ||
3213 | return -EFAULT; | ||
3214 | } | ||
3215 | reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell) | ||
3216 | & MPI2_DOORBELL_DATA_MASK); | ||
3217 | writel(0, &ioc->chip->HostInterruptStatus); | ||
3218 | |||
3219 | for (i = 2; i < default_reply->MsgLength * 2; i++) { | ||
3220 | if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) { | ||
3221 | printk(MPT2SAS_ERR_FMT "doorbell " | ||
3222 | "handshake int failed (line=%d)\n", ioc->name, | ||
3223 | __LINE__); | ||
3224 | return -EFAULT; | ||
3225 | } | ||
3226 | if (i >= reply_bytes/2) /* overflow case */ | ||
3227 | dummy = readl(&ioc->chip->Doorbell); | ||
3228 | else | ||
3229 | reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell) | ||
3230 | & MPI2_DOORBELL_DATA_MASK); | ||
3231 | writel(0, &ioc->chip->HostInterruptStatus); | ||
3232 | } | ||
3233 | |||
3234 | _base_wait_for_doorbell_int(ioc, 5, sleep_flag); | ||
3235 | if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) { | ||
3236 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use " | ||
3237 | " (line=%d)\n", ioc->name, __LINE__)); | ||
3238 | } | ||
3239 | writel(0, &ioc->chip->HostInterruptStatus); | ||
3240 | |||
3241 | if (ioc->logging_level & MPT_DEBUG_INIT) { | ||
3242 | mfp = (__le32 *)reply; | ||
3243 | printk(KERN_INFO "\toffset:data\n"); | ||
3244 | for (i = 0; i < reply_bytes/4; i++) | ||
3245 | printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4, | ||
3246 | le32_to_cpu(mfp[i])); | ||
3247 | } | ||
3248 | return 0; | ||
3249 | } | ||
3250 | |||
3251 | /** | ||
3252 | * mpt2sas_base_sas_iounit_control - send sas iounit control to FW | ||
3253 | * @ioc: per adapter object | ||
3254 | * @mpi_reply: the reply payload from FW | ||
3255 | * @mpi_request: the request payload sent to FW | ||
3256 | * | ||
3257 | * The SAS IO Unit Control Request message allows the host to perform low-level | ||
3258 | * operations, such as resets on the PHYs of the IO Unit, also allows the host | ||
3259 | * to obtain the IOC assigned device handles for a device if it has other | ||
3260 | * identifying information about the device, in addition allows the host to | ||
3261 | * remove IOC resources associated with the device. | ||
3262 | * | ||
3263 | * Returns 0 for success, non-zero for failure. | ||
3264 | */ | ||
3265 | int | ||
3266 | mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc, | ||
3267 | Mpi2SasIoUnitControlReply_t *mpi_reply, | ||
3268 | Mpi2SasIoUnitControlRequest_t *mpi_request) | ||
3269 | { | ||
3270 | u16 smid; | ||
3271 | u32 ioc_state; | ||
3272 | unsigned long timeleft; | ||
3273 | bool issue_reset = false; | ||
3274 | int rc; | ||
3275 | void *request; | ||
3276 | u16 wait_state_count; | ||
3277 | |||
3278 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
3279 | __func__)); | ||
3280 | |||
3281 | mutex_lock(&ioc->base_cmds.mutex); | ||
3282 | |||
3283 | if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) { | ||
3284 | printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n", | ||
3285 | ioc->name, __func__); | ||
3286 | rc = -EAGAIN; | ||
3287 | goto out; | ||
3288 | } | ||
3289 | |||
3290 | wait_state_count = 0; | ||
3291 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
3292 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
3293 | if (wait_state_count++ == 10) { | ||
3294 | printk(MPT2SAS_ERR_FMT | ||
3295 | "%s: failed due to ioc not operational\n", | ||
3296 | ioc->name, __func__); | ||
3297 | rc = -EFAULT; | ||
3298 | goto out; | ||
3299 | } | ||
3300 | ssleep(1); | ||
3301 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
3302 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
3303 | "operational state(count=%d)\n", ioc->name, | ||
3304 | __func__, wait_state_count); | ||
3305 | } | ||
3306 | |||
3307 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); | ||
3308 | if (!smid) { | ||
3309 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
3310 | ioc->name, __func__); | ||
3311 | rc = -EAGAIN; | ||
3312 | goto out; | ||
3313 | } | ||
3314 | |||
3315 | rc = 0; | ||
3316 | ioc->base_cmds.status = MPT2_CMD_PENDING; | ||
3317 | request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3318 | ioc->base_cmds.smid = smid; | ||
3319 | memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)); | ||
3320 | if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || | ||
3321 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) | ||
3322 | ioc->ioc_link_reset_in_progress = 1; | ||
3323 | init_completion(&ioc->base_cmds.done); | ||
3324 | mpt2sas_base_put_smid_default(ioc, smid); | ||
3325 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, | ||
3326 | msecs_to_jiffies(10000)); | ||
3327 | if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || | ||
3328 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) && | ||
3329 | ioc->ioc_link_reset_in_progress) | ||
3330 | ioc->ioc_link_reset_in_progress = 0; | ||
3331 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { | ||
3332 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
3333 | ioc->name, __func__); | ||
3334 | _debug_dump_mf(mpi_request, | ||
3335 | sizeof(Mpi2SasIoUnitControlRequest_t)/4); | ||
3336 | if (!(ioc->base_cmds.status & MPT2_CMD_RESET)) | ||
3337 | issue_reset = true; | ||
3338 | goto issue_host_reset; | ||
3339 | } | ||
3340 | if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID) | ||
3341 | memcpy(mpi_reply, ioc->base_cmds.reply, | ||
3342 | sizeof(Mpi2SasIoUnitControlReply_t)); | ||
3343 | else | ||
3344 | memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t)); | ||
3345 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
3346 | goto out; | ||
3347 | |||
3348 | issue_host_reset: | ||
3349 | if (issue_reset) | ||
3350 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
3351 | FORCE_BIG_HAMMER); | ||
3352 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
3353 | rc = -EFAULT; | ||
3354 | out: | ||
3355 | mutex_unlock(&ioc->base_cmds.mutex); | ||
3356 | return rc; | ||
3357 | } | ||
3358 | |||
3359 | |||
3360 | /** | ||
3361 | * mpt2sas_base_scsi_enclosure_processor - sending request to sep device | ||
3362 | * @ioc: per adapter object | ||
3363 | * @mpi_reply: the reply payload from FW | ||
3364 | * @mpi_request: the request payload sent to FW | ||
3365 | * | ||
3366 | * The SCSI Enclosure Processor request message causes the IOC to | ||
3367 | * communicate with SES devices to control LED status signals. | ||
3368 | * | ||
3369 | * Returns 0 for success, non-zero for failure. | ||
3370 | */ | ||
3371 | int | ||
3372 | mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc, | ||
3373 | Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request) | ||
3374 | { | ||
3375 | u16 smid; | ||
3376 | u32 ioc_state; | ||
3377 | unsigned long timeleft; | ||
3378 | bool issue_reset = false; | ||
3379 | int rc; | ||
3380 | void *request; | ||
3381 | u16 wait_state_count; | ||
3382 | |||
3383 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
3384 | __func__)); | ||
3385 | |||
3386 | mutex_lock(&ioc->base_cmds.mutex); | ||
3387 | |||
3388 | if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) { | ||
3389 | printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n", | ||
3390 | ioc->name, __func__); | ||
3391 | rc = -EAGAIN; | ||
3392 | goto out; | ||
3393 | } | ||
3394 | |||
3395 | wait_state_count = 0; | ||
3396 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
3397 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
3398 | if (wait_state_count++ == 10) { | ||
3399 | printk(MPT2SAS_ERR_FMT | ||
3400 | "%s: failed due to ioc not operational\n", | ||
3401 | ioc->name, __func__); | ||
3402 | rc = -EFAULT; | ||
3403 | goto out; | ||
3404 | } | ||
3405 | ssleep(1); | ||
3406 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
3407 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
3408 | "operational state(count=%d)\n", ioc->name, | ||
3409 | __func__, wait_state_count); | ||
3410 | } | ||
3411 | |||
3412 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); | ||
3413 | if (!smid) { | ||
3414 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
3415 | ioc->name, __func__); | ||
3416 | rc = -EAGAIN; | ||
3417 | goto out; | ||
3418 | } | ||
3419 | |||
3420 | rc = 0; | ||
3421 | ioc->base_cmds.status = MPT2_CMD_PENDING; | ||
3422 | request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3423 | ioc->base_cmds.smid = smid; | ||
3424 | memcpy(request, mpi_request, sizeof(Mpi2SepReply_t)); | ||
3425 | init_completion(&ioc->base_cmds.done); | ||
3426 | mpt2sas_base_put_smid_default(ioc, smid); | ||
3427 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, | ||
3428 | msecs_to_jiffies(10000)); | ||
3429 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { | ||
3430 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
3431 | ioc->name, __func__); | ||
3432 | _debug_dump_mf(mpi_request, | ||
3433 | sizeof(Mpi2SepRequest_t)/4); | ||
3434 | if (!(ioc->base_cmds.status & MPT2_CMD_RESET)) | ||
3435 | issue_reset = true; | ||
3436 | goto issue_host_reset; | ||
3437 | } | ||
3438 | if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID) | ||
3439 | memcpy(mpi_reply, ioc->base_cmds.reply, | ||
3440 | sizeof(Mpi2SepReply_t)); | ||
3441 | else | ||
3442 | memset(mpi_reply, 0, sizeof(Mpi2SepReply_t)); | ||
3443 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
3444 | goto out; | ||
3445 | |||
3446 | issue_host_reset: | ||
3447 | if (issue_reset) | ||
3448 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
3449 | FORCE_BIG_HAMMER); | ||
3450 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
3451 | rc = -EFAULT; | ||
3452 | out: | ||
3453 | mutex_unlock(&ioc->base_cmds.mutex); | ||
3454 | return rc; | ||
3455 | } | ||
3456 | |||
3457 | /** | ||
3458 | * _base_get_port_facts - obtain port facts reply and save in ioc | ||
3459 | * @ioc: per adapter object | ||
3460 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3461 | * | ||
3462 | * Returns 0 for success, non-zero for failure. | ||
3463 | */ | ||
3464 | static int | ||
3465 | _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag) | ||
3466 | { | ||
3467 | Mpi2PortFactsRequest_t mpi_request; | ||
3468 | Mpi2PortFactsReply_t mpi_reply; | ||
3469 | struct mpt2sas_port_facts *pfacts; | ||
3470 | int mpi_reply_sz, mpi_request_sz, r; | ||
3471 | |||
3472 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
3473 | __func__)); | ||
3474 | |||
3475 | mpi_reply_sz = sizeof(Mpi2PortFactsReply_t); | ||
3476 | mpi_request_sz = sizeof(Mpi2PortFactsRequest_t); | ||
3477 | memset(&mpi_request, 0, mpi_request_sz); | ||
3478 | mpi_request.Function = MPI2_FUNCTION_PORT_FACTS; | ||
3479 | mpi_request.PortNumber = port; | ||
3480 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, | ||
3481 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP); | ||
3482 | |||
3483 | if (r != 0) { | ||
3484 | printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n", | ||
3485 | ioc->name, __func__, r); | ||
3486 | return r; | ||
3487 | } | ||
3488 | |||
3489 | pfacts = &ioc->pfacts[port]; | ||
3490 | memset(pfacts, 0, sizeof(struct mpt2sas_port_facts)); | ||
3491 | pfacts->PortNumber = mpi_reply.PortNumber; | ||
3492 | pfacts->VP_ID = mpi_reply.VP_ID; | ||
3493 | pfacts->VF_ID = mpi_reply.VF_ID; | ||
3494 | pfacts->MaxPostedCmdBuffers = | ||
3495 | le16_to_cpu(mpi_reply.MaxPostedCmdBuffers); | ||
3496 | |||
3497 | return 0; | ||
3498 | } | ||
3499 | |||
3500 | /** | ||
3501 | * _base_wait_for_iocstate - Wait until the card is in READY or OPERATIONAL | ||
3502 | * @ioc: per adapter object | ||
3503 | * @timeout: | ||
3504 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3505 | * | ||
3506 | * Returns 0 for success, non-zero for failure. | ||
3507 | */ | ||
3508 | static int | ||
3509 | _base_wait_for_iocstate(struct MPT2SAS_ADAPTER *ioc, int timeout, | ||
3510 | int sleep_flag) | ||
3511 | { | ||
3512 | u32 ioc_state, doorbell; | ||
3513 | int rc; | ||
3514 | |||
3515 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
3516 | __func__)); | ||
3517 | |||
3518 | if (ioc->pci_error_recovery) | ||
3519 | return 0; | ||
3520 | |||
3521 | doorbell = mpt2sas_base_get_iocstate(ioc, 0); | ||
3522 | ioc_state = doorbell & MPI2_IOC_STATE_MASK; | ||
3523 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n", | ||
3524 | ioc->name, __func__, ioc_state)); | ||
3525 | |||
3526 | switch (ioc_state) { | ||
3527 | case MPI2_IOC_STATE_READY: | ||
3528 | case MPI2_IOC_STATE_OPERATIONAL: | ||
3529 | return 0; | ||
3530 | } | ||
3531 | |||
3532 | if (doorbell & MPI2_DOORBELL_USED) { | ||
3533 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3534 | "unexpected doorbell activ!e\n", ioc->name)); | ||
3535 | goto issue_diag_reset; | ||
3536 | } | ||
3537 | |||
3538 | if (ioc_state == MPI2_IOC_STATE_FAULT) { | ||
3539 | mpt2sas_base_fault_info(ioc, doorbell & | ||
3540 | MPI2_DOORBELL_DATA_MASK); | ||
3541 | goto issue_diag_reset; | ||
3542 | } | ||
3543 | |||
3544 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, | ||
3545 | timeout, sleep_flag); | ||
3546 | if (ioc_state) { | ||
3547 | printk(MPT2SAS_ERR_FMT | ||
3548 | "%s: failed going to ready state (ioc_state=0x%x)\n", | ||
3549 | ioc->name, __func__, ioc_state); | ||
3550 | return -EFAULT; | ||
3551 | } | ||
3552 | |||
3553 | issue_diag_reset: | ||
3554 | rc = _base_diag_reset(ioc, sleep_flag); | ||
3555 | return rc; | ||
3556 | } | ||
3557 | |||
3558 | /** | ||
3559 | * _base_get_ioc_facts - obtain ioc facts reply and save in ioc | ||
3560 | * @ioc: per adapter object | ||
3561 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3562 | * | ||
3563 | * Returns 0 for success, non-zero for failure. | ||
3564 | */ | ||
3565 | static int | ||
3566 | _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
3567 | { | ||
3568 | Mpi2IOCFactsRequest_t mpi_request; | ||
3569 | Mpi2IOCFactsReply_t mpi_reply; | ||
3570 | struct mpt2sas_facts *facts; | ||
3571 | int mpi_reply_sz, mpi_request_sz, r; | ||
3572 | |||
3573 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
3574 | __func__)); | ||
3575 | |||
3576 | r = _base_wait_for_iocstate(ioc, 10, sleep_flag); | ||
3577 | if (r) { | ||
3578 | printk(MPT2SAS_ERR_FMT "%s: failed getting to correct state\n", | ||
3579 | ioc->name, __func__); | ||
3580 | return r; | ||
3581 | } | ||
3582 | |||
3583 | mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t); | ||
3584 | mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t); | ||
3585 | memset(&mpi_request, 0, mpi_request_sz); | ||
3586 | mpi_request.Function = MPI2_FUNCTION_IOC_FACTS; | ||
3587 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, | ||
3588 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP); | ||
3589 | |||
3590 | if (r != 0) { | ||
3591 | printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n", | ||
3592 | ioc->name, __func__, r); | ||
3593 | return r; | ||
3594 | } | ||
3595 | |||
3596 | facts = &ioc->facts; | ||
3597 | memset(facts, 0, sizeof(struct mpt2sas_facts)); | ||
3598 | facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion); | ||
3599 | facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion); | ||
3600 | facts->VP_ID = mpi_reply.VP_ID; | ||
3601 | facts->VF_ID = mpi_reply.VF_ID; | ||
3602 | facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions); | ||
3603 | facts->MaxChainDepth = mpi_reply.MaxChainDepth; | ||
3604 | facts->WhoInit = mpi_reply.WhoInit; | ||
3605 | facts->NumberOfPorts = mpi_reply.NumberOfPorts; | ||
3606 | facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors; | ||
3607 | facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit); | ||
3608 | facts->MaxReplyDescriptorPostQueueDepth = | ||
3609 | le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth); | ||
3610 | facts->ProductID = le16_to_cpu(mpi_reply.ProductID); | ||
3611 | facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities); | ||
3612 | if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)) | ||
3613 | ioc->ir_firmware = 1; | ||
3614 | if ((facts->IOCCapabilities & | ||
3615 | MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE)) | ||
3616 | ioc->rdpq_array_capable = 1; | ||
3617 | facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word); | ||
3618 | facts->IOCRequestFrameSize = | ||
3619 | le16_to_cpu(mpi_reply.IOCRequestFrameSize); | ||
3620 | facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators); | ||
3621 | facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets); | ||
3622 | ioc->shost->max_id = -1; | ||
3623 | facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders); | ||
3624 | facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures); | ||
3625 | facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags); | ||
3626 | facts->HighPriorityCredit = | ||
3627 | le16_to_cpu(mpi_reply.HighPriorityCredit); | ||
3628 | facts->ReplyFrameSize = mpi_reply.ReplyFrameSize; | ||
3629 | facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle); | ||
3630 | |||
3631 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), " | ||
3632 | "max chains per io(%d)\n", ioc->name, facts->RequestCredit, | ||
3633 | facts->MaxChainDepth)); | ||
3634 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), " | ||
3635 | "reply frame size(%d)\n", ioc->name, | ||
3636 | facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4)); | ||
3637 | return 0; | ||
3638 | } | ||
3639 | |||
3640 | /** | ||
3641 | * _base_send_ioc_init - send ioc_init to firmware | ||
3642 | * @ioc: per adapter object | ||
3643 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3644 | * | ||
3645 | * Returns 0 for success, non-zero for failure. | ||
3646 | */ | ||
3647 | static int | ||
3648 | _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
3649 | { | ||
3650 | Mpi2IOCInitRequest_t mpi_request; | ||
3651 | Mpi2IOCInitReply_t mpi_reply; | ||
3652 | int i, r = 0; | ||
3653 | struct timeval current_time; | ||
3654 | u16 ioc_status; | ||
3655 | u32 reply_post_free_array_sz = 0; | ||
3656 | Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL; | ||
3657 | dma_addr_t reply_post_free_array_dma; | ||
3658 | |||
3659 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
3660 | __func__)); | ||
3661 | |||
3662 | memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t)); | ||
3663 | mpi_request.Function = MPI2_FUNCTION_IOC_INIT; | ||
3664 | mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER; | ||
3665 | mpi_request.VF_ID = 0; /* TODO */ | ||
3666 | mpi_request.VP_ID = 0; | ||
3667 | mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION); | ||
3668 | mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); | ||
3669 | |||
3670 | if (_base_is_controller_msix_enabled(ioc)) | ||
3671 | mpi_request.HostMSIxVectors = ioc->reply_queue_count; | ||
3672 | mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4); | ||
3673 | mpi_request.ReplyDescriptorPostQueueDepth = | ||
3674 | cpu_to_le16(ioc->reply_post_queue_depth); | ||
3675 | mpi_request.ReplyFreeQueueDepth = | ||
3676 | cpu_to_le16(ioc->reply_free_queue_depth); | ||
3677 | |||
3678 | mpi_request.SenseBufferAddressHigh = | ||
3679 | cpu_to_le32((u64)ioc->sense_dma >> 32); | ||
3680 | mpi_request.SystemReplyAddressHigh = | ||
3681 | cpu_to_le32((u64)ioc->reply_dma >> 32); | ||
3682 | mpi_request.SystemRequestFrameBaseAddress = | ||
3683 | cpu_to_le64((u64)ioc->request_dma); | ||
3684 | mpi_request.ReplyFreeQueueAddress = | ||
3685 | cpu_to_le64((u64)ioc->reply_free_dma); | ||
3686 | |||
3687 | if (ioc->rdpq_array_enable) { | ||
3688 | reply_post_free_array_sz = ioc->reply_queue_count * | ||
3689 | sizeof(Mpi2IOCInitRDPQArrayEntry); | ||
3690 | reply_post_free_array = pci_alloc_consistent(ioc->pdev, | ||
3691 | reply_post_free_array_sz, &reply_post_free_array_dma); | ||
3692 | if (!reply_post_free_array) { | ||
3693 | printk(MPT2SAS_ERR_FMT | ||
3694 | "reply_post_free_array: pci_alloc_consistent failed\n", | ||
3695 | ioc->name); | ||
3696 | r = -ENOMEM; | ||
3697 | goto out; | ||
3698 | } | ||
3699 | memset(reply_post_free_array, 0, reply_post_free_array_sz); | ||
3700 | for (i = 0; i < ioc->reply_queue_count; i++) | ||
3701 | reply_post_free_array[i].RDPQBaseAddress = | ||
3702 | cpu_to_le64( | ||
3703 | (u64)ioc->reply_post[i].reply_post_free_dma); | ||
3704 | mpi_request.MsgFlags = MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE; | ||
3705 | mpi_request.ReplyDescriptorPostQueueAddress = | ||
3706 | cpu_to_le64((u64)reply_post_free_array_dma); | ||
3707 | } else { | ||
3708 | mpi_request.ReplyDescriptorPostQueueAddress = | ||
3709 | cpu_to_le64((u64)ioc->reply_post[0].reply_post_free_dma); | ||
3710 | } | ||
3711 | |||
3712 | /* This time stamp specifies number of milliseconds | ||
3713 | * since epoch ~ midnight January 1, 1970. | ||
3714 | */ | ||
3715 | do_gettimeofday(¤t_time); | ||
3716 | mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 + | ||
3717 | (current_time.tv_usec / 1000)); | ||
3718 | |||
3719 | if (ioc->logging_level & MPT_DEBUG_INIT) { | ||
3720 | __le32 *mfp; | ||
3721 | int i; | ||
3722 | |||
3723 | mfp = (__le32 *)&mpi_request; | ||
3724 | printk(KERN_INFO "\toffset:data\n"); | ||
3725 | for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++) | ||
3726 | printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4, | ||
3727 | le32_to_cpu(mfp[i])); | ||
3728 | } | ||
3729 | |||
3730 | r = _base_handshake_req_reply_wait(ioc, | ||
3731 | sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request, | ||
3732 | sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10, | ||
3733 | sleep_flag); | ||
3734 | |||
3735 | if (r != 0) { | ||
3736 | printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n", | ||
3737 | ioc->name, __func__, r); | ||
3738 | goto out; | ||
3739 | } | ||
3740 | |||
3741 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
3742 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS || | ||
3743 | mpi_reply.IOCLogInfo) { | ||
3744 | printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__); | ||
3745 | r = -EIO; | ||
3746 | } | ||
3747 | |||
3748 | out: | ||
3749 | if (reply_post_free_array) | ||
3750 | pci_free_consistent(ioc->pdev, reply_post_free_array_sz, | ||
3751 | reply_post_free_array, | ||
3752 | reply_post_free_array_dma); | ||
3753 | return r; | ||
3754 | } | ||
3755 | |||
3756 | /** | ||
3757 | * mpt2sas_port_enable_done - command completion routine for port enable | ||
3758 | * @ioc: per adapter object | ||
3759 | * @smid: system request message index | ||
3760 | * @msix_index: MSIX table index supplied by the OS | ||
3761 | * @reply: reply message frame(lower 32bit addr) | ||
3762 | * | ||
3763 | * Return 1 meaning mf should be freed from _base_interrupt | ||
3764 | * 0 means the mf is freed from this function. | ||
3765 | */ | ||
3766 | u8 | ||
3767 | mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
3768 | u32 reply) | ||
3769 | { | ||
3770 | MPI2DefaultReply_t *mpi_reply; | ||
3771 | u16 ioc_status; | ||
3772 | |||
3773 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
3774 | if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK) | ||
3775 | return 1; | ||
3776 | |||
3777 | if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED) | ||
3778 | return 1; | ||
3779 | |||
3780 | ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE; | ||
3781 | if (mpi_reply) { | ||
3782 | ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
3783 | memcpy(ioc->port_enable_cmds.reply, mpi_reply, | ||
3784 | mpi_reply->MsgLength*4); | ||
3785 | } | ||
3786 | ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING; | ||
3787 | |||
3788 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
3789 | |||
3790 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
3791 | ioc->port_enable_failed = 1; | ||
3792 | |||
3793 | if (ioc->is_driver_loading) { | ||
3794 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | ||
3795 | mpt2sas_port_enable_complete(ioc); | ||
3796 | return 1; | ||
3797 | } else { | ||
3798 | ioc->start_scan_failed = ioc_status; | ||
3799 | ioc->start_scan = 0; | ||
3800 | return 1; | ||
3801 | } | ||
3802 | } | ||
3803 | complete(&ioc->port_enable_cmds.done); | ||
3804 | return 1; | ||
3805 | } | ||
3806 | |||
3807 | |||
3808 | /** | ||
3809 | * _base_send_port_enable - send port_enable(discovery stuff) to firmware | ||
3810 | * @ioc: per adapter object | ||
3811 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3812 | * | ||
3813 | * Returns 0 for success, non-zero for failure. | ||
3814 | */ | ||
3815 | static int | ||
3816 | _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
3817 | { | ||
3818 | Mpi2PortEnableRequest_t *mpi_request; | ||
3819 | Mpi2PortEnableReply_t *mpi_reply; | ||
3820 | unsigned long timeleft; | ||
3821 | int r = 0; | ||
3822 | u16 smid; | ||
3823 | u16 ioc_status; | ||
3824 | |||
3825 | printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name); | ||
3826 | |||
3827 | if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) { | ||
3828 | printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n", | ||
3829 | ioc->name, __func__); | ||
3830 | return -EAGAIN; | ||
3831 | } | ||
3832 | |||
3833 | smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx); | ||
3834 | if (!smid) { | ||
3835 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
3836 | ioc->name, __func__); | ||
3837 | return -EAGAIN; | ||
3838 | } | ||
3839 | |||
3840 | ioc->port_enable_cmds.status = MPT2_CMD_PENDING; | ||
3841 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3842 | ioc->port_enable_cmds.smid = smid; | ||
3843 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); | ||
3844 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; | ||
3845 | |||
3846 | init_completion(&ioc->port_enable_cmds.done); | ||
3847 | mpt2sas_base_put_smid_default(ioc, smid); | ||
3848 | timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done, | ||
3849 | 300*HZ); | ||
3850 | if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) { | ||
3851 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
3852 | ioc->name, __func__); | ||
3853 | _debug_dump_mf(mpi_request, | ||
3854 | sizeof(Mpi2PortEnableRequest_t)/4); | ||
3855 | if (ioc->port_enable_cmds.status & MPT2_CMD_RESET) | ||
3856 | r = -EFAULT; | ||
3857 | else | ||
3858 | r = -ETIME; | ||
3859 | goto out; | ||
3860 | } | ||
3861 | mpi_reply = ioc->port_enable_cmds.reply; | ||
3862 | |||
3863 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
3864 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
3865 | printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n", | ||
3866 | ioc->name, __func__, ioc_status); | ||
3867 | r = -EFAULT; | ||
3868 | goto out; | ||
3869 | } | ||
3870 | out: | ||
3871 | ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED; | ||
3872 | printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ? | ||
3873 | "SUCCESS" : "FAILED")); | ||
3874 | return r; | ||
3875 | } | ||
3876 | |||
3877 | /** | ||
3878 | * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply) | ||
3879 | * @ioc: per adapter object | ||
3880 | * | ||
3881 | * Returns 0 for success, non-zero for failure. | ||
3882 | */ | ||
3883 | int | ||
3884 | mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc) | ||
3885 | { | ||
3886 | Mpi2PortEnableRequest_t *mpi_request; | ||
3887 | u16 smid; | ||
3888 | |||
3889 | printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name); | ||
3890 | |||
3891 | if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) { | ||
3892 | printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n", | ||
3893 | ioc->name, __func__); | ||
3894 | return -EAGAIN; | ||
3895 | } | ||
3896 | |||
3897 | smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx); | ||
3898 | if (!smid) { | ||
3899 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
3900 | ioc->name, __func__); | ||
3901 | return -EAGAIN; | ||
3902 | } | ||
3903 | |||
3904 | ioc->port_enable_cmds.status = MPT2_CMD_PENDING; | ||
3905 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3906 | ioc->port_enable_cmds.smid = smid; | ||
3907 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); | ||
3908 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; | ||
3909 | |||
3910 | mpt2sas_base_put_smid_default(ioc, smid); | ||
3911 | return 0; | ||
3912 | } | ||
3913 | |||
3914 | /** | ||
3915 | * _base_determine_wait_on_discovery - desposition | ||
3916 | * @ioc: per adapter object | ||
3917 | * | ||
3918 | * Decide whether to wait on discovery to complete. Used to either | ||
3919 | * locate boot device, or report volumes ahead of physical devices. | ||
3920 | * | ||
3921 | * Returns 1 for wait, 0 for don't wait | ||
3922 | */ | ||
3923 | static int | ||
3924 | _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc) | ||
3925 | { | ||
3926 | /* We wait for discovery to complete if IR firmware is loaded. | ||
3927 | * The sas topology events arrive before PD events, so we need time to | ||
3928 | * turn on the bit in ioc->pd_handles to indicate PD | ||
3929 | * Also, it maybe required to report Volumes ahead of physical | ||
3930 | * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set. | ||
3931 | */ | ||
3932 | if (ioc->ir_firmware) | ||
3933 | return 1; | ||
3934 | |||
3935 | /* if no Bios, then we don't need to wait */ | ||
3936 | if (!ioc->bios_pg3.BiosVersion) | ||
3937 | return 0; | ||
3938 | |||
3939 | /* Bios is present, then we drop down here. | ||
3940 | * | ||
3941 | * If there any entries in the Bios Page 2, then we wait | ||
3942 | * for discovery to complete. | ||
3943 | */ | ||
3944 | |||
3945 | /* Current Boot Device */ | ||
3946 | if ((ioc->bios_pg2.CurrentBootDeviceForm & | ||
3947 | MPI2_BIOSPAGE2_FORM_MASK) == | ||
3948 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && | ||
3949 | /* Request Boot Device */ | ||
3950 | (ioc->bios_pg2.ReqBootDeviceForm & | ||
3951 | MPI2_BIOSPAGE2_FORM_MASK) == | ||
3952 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && | ||
3953 | /* Alternate Request Boot Device */ | ||
3954 | (ioc->bios_pg2.ReqAltBootDeviceForm & | ||
3955 | MPI2_BIOSPAGE2_FORM_MASK) == | ||
3956 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED) | ||
3957 | return 0; | ||
3958 | |||
3959 | return 1; | ||
3960 | } | ||
3961 | |||
3962 | |||
3963 | /** | ||
3964 | * _base_unmask_events - turn on notification for this event | ||
3965 | * @ioc: per adapter object | ||
3966 | * @event: firmware event | ||
3967 | * | ||
3968 | * The mask is stored in ioc->event_masks. | ||
3969 | */ | ||
3970 | static void | ||
3971 | _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event) | ||
3972 | { | ||
3973 | u32 desired_event; | ||
3974 | |||
3975 | if (event >= 128) | ||
3976 | return; | ||
3977 | |||
3978 | desired_event = (1 << (event % 32)); | ||
3979 | |||
3980 | if (event < 32) | ||
3981 | ioc->event_masks[0] &= ~desired_event; | ||
3982 | else if (event < 64) | ||
3983 | ioc->event_masks[1] &= ~desired_event; | ||
3984 | else if (event < 96) | ||
3985 | ioc->event_masks[2] &= ~desired_event; | ||
3986 | else if (event < 128) | ||
3987 | ioc->event_masks[3] &= ~desired_event; | ||
3988 | } | ||
3989 | |||
3990 | /** | ||
3991 | * _base_event_notification - send event notification | ||
3992 | * @ioc: per adapter object | ||
3993 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
3994 | * | ||
3995 | * Returns 0 for success, non-zero for failure. | ||
3996 | */ | ||
3997 | static int | ||
3998 | _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
3999 | { | ||
4000 | Mpi2EventNotificationRequest_t *mpi_request; | ||
4001 | unsigned long timeleft; | ||
4002 | u16 smid; | ||
4003 | int r = 0; | ||
4004 | int i; | ||
4005 | |||
4006 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
4007 | __func__)); | ||
4008 | |||
4009 | if (ioc->base_cmds.status & MPT2_CMD_PENDING) { | ||
4010 | printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n", | ||
4011 | ioc->name, __func__); | ||
4012 | return -EAGAIN; | ||
4013 | } | ||
4014 | |||
4015 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); | ||
4016 | if (!smid) { | ||
4017 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
4018 | ioc->name, __func__); | ||
4019 | return -EAGAIN; | ||
4020 | } | ||
4021 | ioc->base_cmds.status = MPT2_CMD_PENDING; | ||
4022 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
4023 | ioc->base_cmds.smid = smid; | ||
4024 | memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t)); | ||
4025 | mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | ||
4026 | mpi_request->VF_ID = 0; /* TODO */ | ||
4027 | mpi_request->VP_ID = 0; | ||
4028 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) | ||
4029 | mpi_request->EventMasks[i] = | ||
4030 | cpu_to_le32(ioc->event_masks[i]); | ||
4031 | init_completion(&ioc->base_cmds.done); | ||
4032 | mpt2sas_base_put_smid_default(ioc, smid); | ||
4033 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ); | ||
4034 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { | ||
4035 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
4036 | ioc->name, __func__); | ||
4037 | _debug_dump_mf(mpi_request, | ||
4038 | sizeof(Mpi2EventNotificationRequest_t)/4); | ||
4039 | if (ioc->base_cmds.status & MPT2_CMD_RESET) | ||
4040 | r = -EFAULT; | ||
4041 | else | ||
4042 | r = -ETIME; | ||
4043 | } else | ||
4044 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n", | ||
4045 | ioc->name, __func__)); | ||
4046 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
4047 | return r; | ||
4048 | } | ||
4049 | |||
4050 | /** | ||
4051 | * mpt2sas_base_validate_event_type - validating event types | ||
4052 | * @ioc: per adapter object | ||
4053 | * @event: firmware event | ||
4054 | * | ||
4055 | * This will turn on firmware event notification when application | ||
4056 | * ask for that event. We don't mask events that are already enabled. | ||
4057 | */ | ||
4058 | void | ||
4059 | mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type) | ||
4060 | { | ||
4061 | int i, j; | ||
4062 | u32 event_mask, desired_event; | ||
4063 | u8 send_update_to_fw; | ||
4064 | |||
4065 | for (i = 0, send_update_to_fw = 0; i < | ||
4066 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) { | ||
4067 | event_mask = ~event_type[i]; | ||
4068 | desired_event = 1; | ||
4069 | for (j = 0; j < 32; j++) { | ||
4070 | if (!(event_mask & desired_event) && | ||
4071 | (ioc->event_masks[i] & desired_event)) { | ||
4072 | ioc->event_masks[i] &= ~desired_event; | ||
4073 | send_update_to_fw = 1; | ||
4074 | } | ||
4075 | desired_event = (desired_event << 1); | ||
4076 | } | ||
4077 | } | ||
4078 | |||
4079 | if (!send_update_to_fw) | ||
4080 | return; | ||
4081 | |||
4082 | mutex_lock(&ioc->base_cmds.mutex); | ||
4083 | _base_event_notification(ioc, CAN_SLEEP); | ||
4084 | mutex_unlock(&ioc->base_cmds.mutex); | ||
4085 | } | ||
4086 | |||
4087 | /** | ||
4088 | * _base_diag_reset - the "big hammer" start of day reset | ||
4089 | * @ioc: per adapter object | ||
4090 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
4091 | * | ||
4092 | * Returns 0 for success, non-zero for failure. | ||
4093 | */ | ||
4094 | static int | ||
4095 | _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
4096 | { | ||
4097 | u32 host_diagnostic; | ||
4098 | u32 ioc_state; | ||
4099 | u32 count; | ||
4100 | u32 hcb_size; | ||
4101 | |||
4102 | printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name); | ||
4103 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n", | ||
4104 | ioc->name)); | ||
4105 | |||
4106 | count = 0; | ||
4107 | do { | ||
4108 | /* Write magic sequence to WriteSequence register | ||
4109 | * Loop until in diagnostic mode | ||
4110 | */ | ||
4111 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic " | ||
4112 | "sequence\n", ioc->name)); | ||
4113 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4114 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4115 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4116 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4117 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4118 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4119 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4120 | |||
4121 | /* wait 100 msec */ | ||
4122 | if (sleep_flag == CAN_SLEEP) | ||
4123 | msleep(100); | ||
4124 | else | ||
4125 | mdelay(100); | ||
4126 | |||
4127 | if (count++ > 20) | ||
4128 | goto out; | ||
4129 | |||
4130 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); | ||
4131 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic " | ||
4132 | "sequence: count(%d), host_diagnostic(0x%08x)\n", | ||
4133 | ioc->name, count, host_diagnostic)); | ||
4134 | |||
4135 | } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0); | ||
4136 | |||
4137 | hcb_size = readl(&ioc->chip->HCBSize); | ||
4138 | |||
4139 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n", | ||
4140 | ioc->name)); | ||
4141 | writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER, | ||
4142 | &ioc->chip->HostDiagnostic); | ||
4143 | |||
4144 | /* This delay allows the chip PCIe hardware time to finish reset tasks*/ | ||
4145 | if (sleep_flag == CAN_SLEEP) | ||
4146 | msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000); | ||
4147 | else | ||
4148 | mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000); | ||
4149 | |||
4150 | /* Approximately 300 second max wait */ | ||
4151 | for (count = 0; count < (300000000 / | ||
4152 | MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC); count++) { | ||
4153 | |||
4154 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); | ||
4155 | |||
4156 | if (host_diagnostic == 0xFFFFFFFF) | ||
4157 | goto out; | ||
4158 | if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER)) | ||
4159 | break; | ||
4160 | |||
4161 | /* Wait to pass the second read delay window */ | ||
4162 | if (sleep_flag == CAN_SLEEP) | ||
4163 | msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC | ||
4164 | /1000); | ||
4165 | else | ||
4166 | mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC | ||
4167 | /1000); | ||
4168 | } | ||
4169 | |||
4170 | if (host_diagnostic & MPI2_DIAG_HCB_MODE) { | ||
4171 | |||
4172 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter " | ||
4173 | "assuming the HCB Address points to good F/W\n", | ||
4174 | ioc->name)); | ||
4175 | host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK; | ||
4176 | host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW; | ||
4177 | writel(host_diagnostic, &ioc->chip->HostDiagnostic); | ||
4178 | |||
4179 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
4180 | "re-enable the HCDW\n", ioc->name)); | ||
4181 | writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE, | ||
4182 | &ioc->chip->HCBSize); | ||
4183 | } | ||
4184 | |||
4185 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n", | ||
4186 | ioc->name)); | ||
4187 | writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET, | ||
4188 | &ioc->chip->HostDiagnostic); | ||
4189 | |||
4190 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the " | ||
4191 | "diagnostic register\n", ioc->name)); | ||
4192 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); | ||
4193 | |||
4194 | drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the " | ||
4195 | "READY state\n", ioc->name)); | ||
4196 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20, | ||
4197 | sleep_flag); | ||
4198 | if (ioc_state) { | ||
4199 | printk(MPT2SAS_ERR_FMT "%s: failed going to ready state " | ||
4200 | " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state); | ||
4201 | goto out; | ||
4202 | } | ||
4203 | |||
4204 | printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name); | ||
4205 | return 0; | ||
4206 | |||
4207 | out: | ||
4208 | printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name); | ||
4209 | return -EFAULT; | ||
4210 | } | ||
4211 | |||
4212 | /** | ||
4213 | * _base_make_ioc_ready - put controller in READY state | ||
4214 | * @ioc: per adapter object | ||
4215 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
4216 | * @type: FORCE_BIG_HAMMER or SOFT_RESET | ||
4217 | * | ||
4218 | * Returns 0 for success, non-zero for failure. | ||
4219 | */ | ||
4220 | static int | ||
4221 | _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag, | ||
4222 | enum reset_type type) | ||
4223 | { | ||
4224 | u32 ioc_state; | ||
4225 | int rc; | ||
4226 | |||
4227 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
4228 | __func__)); | ||
4229 | |||
4230 | if (ioc->pci_error_recovery) | ||
4231 | return 0; | ||
4232 | |||
4233 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); | ||
4234 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n", | ||
4235 | ioc->name, __func__, ioc_state)); | ||
4236 | |||
4237 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) | ||
4238 | return 0; | ||
4239 | |||
4240 | if (ioc_state & MPI2_DOORBELL_USED) { | ||
4241 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " | ||
4242 | "active!\n", ioc->name)); | ||
4243 | goto issue_diag_reset; | ||
4244 | } | ||
4245 | |||
4246 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | ||
4247 | mpt2sas_base_fault_info(ioc, ioc_state & | ||
4248 | MPI2_DOORBELL_DATA_MASK); | ||
4249 | goto issue_diag_reset; | ||
4250 | } | ||
4251 | |||
4252 | if (type == FORCE_BIG_HAMMER) | ||
4253 | goto issue_diag_reset; | ||
4254 | |||
4255 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) | ||
4256 | if (!(_base_send_ioc_reset(ioc, | ||
4257 | MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) { | ||
4258 | ioc->ioc_reset_count++; | ||
4259 | return 0; | ||
4260 | } | ||
4261 | |||
4262 | issue_diag_reset: | ||
4263 | rc = _base_diag_reset(ioc, CAN_SLEEP); | ||
4264 | ioc->ioc_reset_count++; | ||
4265 | return rc; | ||
4266 | } | ||
4267 | |||
4268 | /** | ||
4269 | * _base_make_ioc_operational - put controller in OPERATIONAL state | ||
4270 | * @ioc: per adapter object | ||
4271 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
4272 | * | ||
4273 | * Returns 0 for success, non-zero for failure. | ||
4274 | */ | ||
4275 | static int | ||
4276 | _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
4277 | { | ||
4278 | int r, i; | ||
4279 | unsigned long flags; | ||
4280 | u32 reply_address; | ||
4281 | u16 smid; | ||
4282 | struct _tr_list *delayed_tr, *delayed_tr_next; | ||
4283 | u8 hide_flag; | ||
4284 | struct adapter_reply_queue *reply_q; | ||
4285 | long reply_post_free; | ||
4286 | u32 reply_post_free_sz, index = 0; | ||
4287 | |||
4288 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
4289 | __func__)); | ||
4290 | |||
4291 | /* clean the delayed target reset list */ | ||
4292 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, | ||
4293 | &ioc->delayed_tr_list, list) { | ||
4294 | list_del(&delayed_tr->list); | ||
4295 | kfree(delayed_tr); | ||
4296 | } | ||
4297 | |||
4298 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, | ||
4299 | &ioc->delayed_tr_volume_list, list) { | ||
4300 | list_del(&delayed_tr->list); | ||
4301 | kfree(delayed_tr); | ||
4302 | } | ||
4303 | |||
4304 | /* initialize the scsi lookup free list */ | ||
4305 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
4306 | INIT_LIST_HEAD(&ioc->free_list); | ||
4307 | smid = 1; | ||
4308 | for (i = 0; i < ioc->scsiio_depth; i++, smid++) { | ||
4309 | INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list); | ||
4310 | ioc->scsi_lookup[i].cb_idx = 0xFF; | ||
4311 | ioc->scsi_lookup[i].smid = smid; | ||
4312 | ioc->scsi_lookup[i].scmd = NULL; | ||
4313 | ioc->scsi_lookup[i].direct_io = 0; | ||
4314 | list_add_tail(&ioc->scsi_lookup[i].tracker_list, | ||
4315 | &ioc->free_list); | ||
4316 | } | ||
4317 | |||
4318 | /* hi-priority queue */ | ||
4319 | INIT_LIST_HEAD(&ioc->hpr_free_list); | ||
4320 | smid = ioc->hi_priority_smid; | ||
4321 | for (i = 0; i < ioc->hi_priority_depth; i++, smid++) { | ||
4322 | ioc->hpr_lookup[i].cb_idx = 0xFF; | ||
4323 | ioc->hpr_lookup[i].smid = smid; | ||
4324 | list_add_tail(&ioc->hpr_lookup[i].tracker_list, | ||
4325 | &ioc->hpr_free_list); | ||
4326 | } | ||
4327 | |||
4328 | /* internal queue */ | ||
4329 | INIT_LIST_HEAD(&ioc->internal_free_list); | ||
4330 | smid = ioc->internal_smid; | ||
4331 | for (i = 0; i < ioc->internal_depth; i++, smid++) { | ||
4332 | ioc->internal_lookup[i].cb_idx = 0xFF; | ||
4333 | ioc->internal_lookup[i].smid = smid; | ||
4334 | list_add_tail(&ioc->internal_lookup[i].tracker_list, | ||
4335 | &ioc->internal_free_list); | ||
4336 | } | ||
4337 | |||
4338 | /* chain pool */ | ||
4339 | INIT_LIST_HEAD(&ioc->free_chain_list); | ||
4340 | for (i = 0; i < ioc->chain_depth; i++) | ||
4341 | list_add_tail(&ioc->chain_lookup[i].tracker_list, | ||
4342 | &ioc->free_chain_list); | ||
4343 | |||
4344 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
4345 | |||
4346 | /* initialize Reply Free Queue */ | ||
4347 | for (i = 0, reply_address = (u32)ioc->reply_dma ; | ||
4348 | i < ioc->reply_free_queue_depth ; i++, reply_address += | ||
4349 | ioc->reply_sz) | ||
4350 | ioc->reply_free[i] = cpu_to_le32(reply_address); | ||
4351 | |||
4352 | /* initialize reply queues */ | ||
4353 | if (ioc->is_driver_loading) | ||
4354 | _base_assign_reply_queues(ioc); | ||
4355 | |||
4356 | /* initialize Reply Post Free Queue */ | ||
4357 | reply_post_free_sz = ioc->reply_post_queue_depth * | ||
4358 | sizeof(Mpi2DefaultReplyDescriptor_t); | ||
4359 | reply_post_free = (long)ioc->reply_post[index].reply_post_free; | ||
4360 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { | ||
4361 | reply_q->reply_post_host_index = 0; | ||
4362 | reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *) | ||
4363 | reply_post_free; | ||
4364 | for (i = 0; i < ioc->reply_post_queue_depth; i++) | ||
4365 | reply_q->reply_post_free[i].Words = | ||
4366 | cpu_to_le64(ULLONG_MAX); | ||
4367 | if (!_base_is_controller_msix_enabled(ioc)) | ||
4368 | goto skip_init_reply_post_free_queue; | ||
4369 | /* | ||
4370 | * If RDPQ is enabled, switch to the next allocation. | ||
4371 | * Otherwise advance within the contiguous region. | ||
4372 | */ | ||
4373 | if (ioc->rdpq_array_enable) | ||
4374 | reply_post_free = (long) | ||
4375 | ioc->reply_post[++index].reply_post_free; | ||
4376 | else | ||
4377 | reply_post_free += reply_post_free_sz; | ||
4378 | } | ||
4379 | skip_init_reply_post_free_queue: | ||
4380 | |||
4381 | r = _base_send_ioc_init(ioc, sleep_flag); | ||
4382 | if (r) | ||
4383 | return r; | ||
4384 | |||
4385 | /* initialize reply free host index */ | ||
4386 | ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1; | ||
4387 | writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex); | ||
4388 | |||
4389 | /* initialize reply post host index */ | ||
4390 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { | ||
4391 | writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT, | ||
4392 | &ioc->chip->ReplyPostHostIndex); | ||
4393 | if (!_base_is_controller_msix_enabled(ioc)) | ||
4394 | goto skip_init_reply_post_host_index; | ||
4395 | } | ||
4396 | |||
4397 | skip_init_reply_post_host_index: | ||
4398 | |||
4399 | _base_unmask_interrupts(ioc); | ||
4400 | |||
4401 | r = _base_event_notification(ioc, sleep_flag); | ||
4402 | if (r) | ||
4403 | return r; | ||
4404 | |||
4405 | if (sleep_flag == CAN_SLEEP) | ||
4406 | _base_static_config_pages(ioc); | ||
4407 | |||
4408 | |||
4409 | if (ioc->is_driver_loading) { | ||
4410 | if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier | ||
4411 | == 0x80) { | ||
4412 | hide_flag = (u8) ( | ||
4413 | le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) & | ||
4414 | MFG_PAGE10_HIDE_SSDS_MASK); | ||
4415 | if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK) | ||
4416 | ioc->mfg_pg10_hide_flag = hide_flag; | ||
4417 | } | ||
4418 | ioc->wait_for_discovery_to_complete = | ||
4419 | _base_determine_wait_on_discovery(ioc); | ||
4420 | return r; /* scan_start and scan_finished support */ | ||
4421 | } | ||
4422 | r = _base_send_port_enable(ioc, sleep_flag); | ||
4423 | if (r) | ||
4424 | return r; | ||
4425 | |||
4426 | return r; | ||
4427 | } | ||
4428 | |||
4429 | /** | ||
4430 | * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap) | ||
4431 | * @ioc: per adapter object | ||
4432 | * | ||
4433 | * Return nothing. | ||
4434 | */ | ||
4435 | void | ||
4436 | mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc) | ||
4437 | { | ||
4438 | struct pci_dev *pdev = ioc->pdev; | ||
4439 | |||
4440 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
4441 | __func__)); | ||
4442 | |||
4443 | /* synchronizing freeing resource with pci_access_mutex lock */ | ||
4444 | mutex_lock(&ioc->pci_access_mutex); | ||
4445 | if (ioc->chip_phys && ioc->chip) { | ||
4446 | _base_mask_interrupts(ioc); | ||
4447 | ioc->shost_recovery = 1; | ||
4448 | _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET); | ||
4449 | ioc->shost_recovery = 0; | ||
4450 | } | ||
4451 | |||
4452 | _base_free_irq(ioc); | ||
4453 | _base_disable_msix(ioc); | ||
4454 | |||
4455 | if (ioc->chip_phys && ioc->chip) | ||
4456 | iounmap(ioc->chip); | ||
4457 | ioc->chip_phys = 0; | ||
4458 | |||
4459 | if (pci_is_enabled(pdev)) { | ||
4460 | pci_release_selected_regions(ioc->pdev, ioc->bars); | ||
4461 | pci_disable_pcie_error_reporting(pdev); | ||
4462 | pci_disable_device(pdev); | ||
4463 | } | ||
4464 | mutex_unlock(&ioc->pci_access_mutex); | ||
4465 | return; | ||
4466 | } | ||
4467 | |||
4468 | /** | ||
4469 | * mpt2sas_base_attach - attach controller instance | ||
4470 | * @ioc: per adapter object | ||
4471 | * | ||
4472 | * Returns 0 for success, non-zero for failure. | ||
4473 | */ | ||
4474 | int | ||
4475 | mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc) | ||
4476 | { | ||
4477 | int r, i; | ||
4478 | int cpu_id, last_cpu_id = 0; | ||
4479 | |||
4480 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
4481 | __func__)); | ||
4482 | |||
4483 | /* setup cpu_msix_table */ | ||
4484 | ioc->cpu_count = num_online_cpus(); | ||
4485 | for_each_online_cpu(cpu_id) | ||
4486 | last_cpu_id = cpu_id; | ||
4487 | ioc->cpu_msix_table_sz = last_cpu_id + 1; | ||
4488 | ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL); | ||
4489 | ioc->reply_queue_count = 1; | ||
4490 | if (!ioc->cpu_msix_table) { | ||
4491 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for " | ||
4492 | "cpu_msix_table failed!!!\n", ioc->name)); | ||
4493 | r = -ENOMEM; | ||
4494 | goto out_free_resources; | ||
4495 | } | ||
4496 | |||
4497 | if (ioc->is_warpdrive) { | ||
4498 | ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz, | ||
4499 | sizeof(resource_size_t *), GFP_KERNEL); | ||
4500 | if (!ioc->reply_post_host_index) { | ||
4501 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation " | ||
4502 | "for cpu_msix_table failed!!!\n", ioc->name)); | ||
4503 | r = -ENOMEM; | ||
4504 | goto out_free_resources; | ||
4505 | } | ||
4506 | } | ||
4507 | |||
4508 | ioc->rdpq_array_enable_assigned = 0; | ||
4509 | ioc->dma_mask = 0; | ||
4510 | r = mpt2sas_base_map_resources(ioc); | ||
4511 | if (r) | ||
4512 | goto out_free_resources; | ||
4513 | |||
4514 | if (ioc->is_warpdrive) { | ||
4515 | ioc->reply_post_host_index[0] = (resource_size_t __iomem *) | ||
4516 | &ioc->chip->ReplyPostHostIndex; | ||
4517 | |||
4518 | for (i = 1; i < ioc->cpu_msix_table_sz; i++) | ||
4519 | ioc->reply_post_host_index[i] = | ||
4520 | (resource_size_t __iomem *) | ||
4521 | ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1) | ||
4522 | * 4))); | ||
4523 | } | ||
4524 | |||
4525 | pci_set_drvdata(ioc->pdev, ioc->shost); | ||
4526 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); | ||
4527 | if (r) | ||
4528 | goto out_free_resources; | ||
4529 | |||
4530 | r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET); | ||
4531 | if (r) | ||
4532 | goto out_free_resources; | ||
4533 | |||
4534 | ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts, | ||
4535 | sizeof(struct mpt2sas_port_facts), GFP_KERNEL); | ||
4536 | if (!ioc->pfacts) { | ||
4537 | r = -ENOMEM; | ||
4538 | goto out_free_resources; | ||
4539 | } | ||
4540 | |||
4541 | for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) { | ||
4542 | r = _base_get_port_facts(ioc, i, CAN_SLEEP); | ||
4543 | if (r) | ||
4544 | goto out_free_resources; | ||
4545 | } | ||
4546 | |||
4547 | r = _base_allocate_memory_pools(ioc, CAN_SLEEP); | ||
4548 | if (r) | ||
4549 | goto out_free_resources; | ||
4550 | |||
4551 | init_waitqueue_head(&ioc->reset_wq); | ||
4552 | /* allocate memory pd handle bitmask list */ | ||
4553 | ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8); | ||
4554 | if (ioc->facts.MaxDevHandle % 8) | ||
4555 | ioc->pd_handles_sz++; | ||
4556 | ioc->pd_handles = kzalloc(ioc->pd_handles_sz, | ||
4557 | GFP_KERNEL); | ||
4558 | if (!ioc->pd_handles) { | ||
4559 | r = -ENOMEM; | ||
4560 | goto out_free_resources; | ||
4561 | } | ||
4562 | ioc->blocking_handles = kzalloc(ioc->pd_handles_sz, | ||
4563 | GFP_KERNEL); | ||
4564 | if (!ioc->blocking_handles) { | ||
4565 | r = -ENOMEM; | ||
4566 | goto out_free_resources; | ||
4567 | } | ||
4568 | ioc->fwfault_debug = mpt2sas_fwfault_debug; | ||
4569 | |||
4570 | /* base internal command bits */ | ||
4571 | mutex_init(&ioc->base_cmds.mutex); | ||
4572 | ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4573 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
4574 | |||
4575 | /* port_enable command bits */ | ||
4576 | ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4577 | ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED; | ||
4578 | |||
4579 | /* transport internal command bits */ | ||
4580 | ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4581 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; | ||
4582 | mutex_init(&ioc->transport_cmds.mutex); | ||
4583 | |||
4584 | /* scsih internal command bits */ | ||
4585 | ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4586 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; | ||
4587 | mutex_init(&ioc->scsih_cmds.mutex); | ||
4588 | |||
4589 | /* task management internal command bits */ | ||
4590 | ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4591 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; | ||
4592 | mutex_init(&ioc->tm_cmds.mutex); | ||
4593 | |||
4594 | /* config page internal command bits */ | ||
4595 | ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4596 | ioc->config_cmds.status = MPT2_CMD_NOT_USED; | ||
4597 | mutex_init(&ioc->config_cmds.mutex); | ||
4598 | |||
4599 | /* ctl module internal command bits */ | ||
4600 | ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); | ||
4601 | ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); | ||
4602 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; | ||
4603 | mutex_init(&ioc->ctl_cmds.mutex); | ||
4604 | |||
4605 | if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply || | ||
4606 | !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply || | ||
4607 | !ioc->config_cmds.reply || !ioc->ctl_cmds.reply || | ||
4608 | !ioc->ctl_cmds.sense) { | ||
4609 | r = -ENOMEM; | ||
4610 | goto out_free_resources; | ||
4611 | } | ||
4612 | |||
4613 | if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply || | ||
4614 | !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply || | ||
4615 | !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) { | ||
4616 | r = -ENOMEM; | ||
4617 | goto out_free_resources; | ||
4618 | } | ||
4619 | |||
4620 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) | ||
4621 | ioc->event_masks[i] = -1; | ||
4622 | |||
4623 | /* here we enable the events we care about */ | ||
4624 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY); | ||
4625 | _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE); | ||
4626 | _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST); | ||
4627 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | ||
4628 | _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE); | ||
4629 | _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST); | ||
4630 | _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME); | ||
4631 | _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK); | ||
4632 | _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS); | ||
4633 | _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED); | ||
4634 | _base_unmask_events(ioc, MPI2_EVENT_TEMP_THRESHOLD); | ||
4635 | r = _base_make_ioc_operational(ioc, CAN_SLEEP); | ||
4636 | if (r) | ||
4637 | goto out_free_resources; | ||
4638 | |||
4639 | ioc->non_operational_loop = 0; | ||
4640 | |||
4641 | return 0; | ||
4642 | |||
4643 | out_free_resources: | ||
4644 | |||
4645 | ioc->remove_host = 1; | ||
4646 | mpt2sas_base_free_resources(ioc); | ||
4647 | _base_release_memory_pools(ioc); | ||
4648 | pci_set_drvdata(ioc->pdev, NULL); | ||
4649 | kfree(ioc->cpu_msix_table); | ||
4650 | if (ioc->is_warpdrive) | ||
4651 | kfree(ioc->reply_post_host_index); | ||
4652 | kfree(ioc->pd_handles); | ||
4653 | kfree(ioc->blocking_handles); | ||
4654 | kfree(ioc->tm_cmds.reply); | ||
4655 | kfree(ioc->transport_cmds.reply); | ||
4656 | kfree(ioc->scsih_cmds.reply); | ||
4657 | kfree(ioc->config_cmds.reply); | ||
4658 | kfree(ioc->base_cmds.reply); | ||
4659 | kfree(ioc->port_enable_cmds.reply); | ||
4660 | kfree(ioc->ctl_cmds.reply); | ||
4661 | kfree(ioc->ctl_cmds.sense); | ||
4662 | kfree(ioc->pfacts); | ||
4663 | ioc->ctl_cmds.reply = NULL; | ||
4664 | ioc->base_cmds.reply = NULL; | ||
4665 | ioc->tm_cmds.reply = NULL; | ||
4666 | ioc->scsih_cmds.reply = NULL; | ||
4667 | ioc->transport_cmds.reply = NULL; | ||
4668 | ioc->config_cmds.reply = NULL; | ||
4669 | ioc->pfacts = NULL; | ||
4670 | return r; | ||
4671 | } | ||
4672 | |||
4673 | |||
4674 | /** | ||
4675 | * mpt2sas_base_detach - remove controller instance | ||
4676 | * @ioc: per adapter object | ||
4677 | * | ||
4678 | * Return nothing. | ||
4679 | */ | ||
4680 | void | ||
4681 | mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc) | ||
4682 | { | ||
4683 | |||
4684 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
4685 | __func__)); | ||
4686 | |||
4687 | mpt2sas_base_stop_watchdog(ioc); | ||
4688 | mpt2sas_base_free_resources(ioc); | ||
4689 | _base_release_memory_pools(ioc); | ||
4690 | pci_set_drvdata(ioc->pdev, NULL); | ||
4691 | kfree(ioc->cpu_msix_table); | ||
4692 | if (ioc->is_warpdrive) | ||
4693 | kfree(ioc->reply_post_host_index); | ||
4694 | kfree(ioc->pd_handles); | ||
4695 | kfree(ioc->blocking_handles); | ||
4696 | kfree(ioc->pfacts); | ||
4697 | kfree(ioc->ctl_cmds.reply); | ||
4698 | kfree(ioc->ctl_cmds.sense); | ||
4699 | kfree(ioc->base_cmds.reply); | ||
4700 | kfree(ioc->port_enable_cmds.reply); | ||
4701 | kfree(ioc->tm_cmds.reply); | ||
4702 | kfree(ioc->transport_cmds.reply); | ||
4703 | kfree(ioc->scsih_cmds.reply); | ||
4704 | kfree(ioc->config_cmds.reply); | ||
4705 | } | ||
4706 | |||
4707 | /** | ||
4708 | * _base_reset_handler - reset callback handler (for base) | ||
4709 | * @ioc: per adapter object | ||
4710 | * @reset_phase: phase | ||
4711 | * | ||
4712 | * The handler for doing any required cleanup or initialization. | ||
4713 | * | ||
4714 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, | ||
4715 | * MPT2_IOC_DONE_RESET | ||
4716 | * | ||
4717 | * Return nothing. | ||
4718 | */ | ||
4719 | static void | ||
4720 | _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) | ||
4721 | { | ||
4722 | mpt2sas_scsih_reset_handler(ioc, reset_phase); | ||
4723 | mpt2sas_ctl_reset_handler(ioc, reset_phase); | ||
4724 | switch (reset_phase) { | ||
4725 | case MPT2_IOC_PRE_RESET: | ||
4726 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
4727 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); | ||
4728 | break; | ||
4729 | case MPT2_IOC_AFTER_RESET: | ||
4730 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
4731 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); | ||
4732 | if (ioc->transport_cmds.status & MPT2_CMD_PENDING) { | ||
4733 | ioc->transport_cmds.status |= MPT2_CMD_RESET; | ||
4734 | mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid); | ||
4735 | complete(&ioc->transport_cmds.done); | ||
4736 | } | ||
4737 | if (ioc->base_cmds.status & MPT2_CMD_PENDING) { | ||
4738 | ioc->base_cmds.status |= MPT2_CMD_RESET; | ||
4739 | mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid); | ||
4740 | complete(&ioc->base_cmds.done); | ||
4741 | } | ||
4742 | if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) { | ||
4743 | ioc->port_enable_failed = 1; | ||
4744 | ioc->port_enable_cmds.status |= MPT2_CMD_RESET; | ||
4745 | mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid); | ||
4746 | if (ioc->is_driver_loading) { | ||
4747 | ioc->start_scan_failed = | ||
4748 | MPI2_IOCSTATUS_INTERNAL_ERROR; | ||
4749 | ioc->start_scan = 0; | ||
4750 | ioc->port_enable_cmds.status = | ||
4751 | MPT2_CMD_NOT_USED; | ||
4752 | } else | ||
4753 | complete(&ioc->port_enable_cmds.done); | ||
4754 | |||
4755 | } | ||
4756 | if (ioc->config_cmds.status & MPT2_CMD_PENDING) { | ||
4757 | ioc->config_cmds.status |= MPT2_CMD_RESET; | ||
4758 | mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid); | ||
4759 | ioc->config_cmds.smid = USHRT_MAX; | ||
4760 | complete(&ioc->config_cmds.done); | ||
4761 | } | ||
4762 | break; | ||
4763 | case MPT2_IOC_DONE_RESET: | ||
4764 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
4765 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); | ||
4766 | break; | ||
4767 | } | ||
4768 | } | ||
4769 | |||
4770 | /** | ||
4771 | * _wait_for_commands_to_complete - reset controller | ||
4772 | * @ioc: Pointer to MPT_ADAPTER structure | ||
4773 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
4774 | * | ||
4775 | * This function waiting(3s) for all pending commands to complete | ||
4776 | * prior to putting controller in reset. | ||
4777 | */ | ||
4778 | static void | ||
4779 | _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) | ||
4780 | { | ||
4781 | u32 ioc_state; | ||
4782 | unsigned long flags; | ||
4783 | u16 i; | ||
4784 | |||
4785 | ioc->pending_io_count = 0; | ||
4786 | if (sleep_flag != CAN_SLEEP) | ||
4787 | return; | ||
4788 | |||
4789 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); | ||
4790 | if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) | ||
4791 | return; | ||
4792 | |||
4793 | /* pending command count */ | ||
4794 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
4795 | for (i = 0; i < ioc->scsiio_depth; i++) | ||
4796 | if (ioc->scsi_lookup[i].cb_idx != 0xFF) | ||
4797 | ioc->pending_io_count++; | ||
4798 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
4799 | |||
4800 | if (!ioc->pending_io_count) | ||
4801 | return; | ||
4802 | |||
4803 | /* wait for pending commands to complete */ | ||
4804 | wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ); | ||
4805 | } | ||
4806 | |||
4807 | /** | ||
4808 | * mpt2sas_base_hard_reset_handler - reset controller | ||
4809 | * @ioc: Pointer to MPT_ADAPTER structure | ||
4810 | * @sleep_flag: CAN_SLEEP or NO_SLEEP | ||
4811 | * @type: FORCE_BIG_HAMMER or SOFT_RESET | ||
4812 | * | ||
4813 | * Returns 0 for success, non-zero for failure. | ||
4814 | */ | ||
4815 | int | ||
4816 | mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag, | ||
4817 | enum reset_type type) | ||
4818 | { | ||
4819 | int r; | ||
4820 | unsigned long flags; | ||
4821 | |||
4822 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, | ||
4823 | __func__)); | ||
4824 | |||
4825 | if (ioc->pci_error_recovery) { | ||
4826 | printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n", | ||
4827 | ioc->name, __func__); | ||
4828 | r = 0; | ||
4829 | goto out_unlocked; | ||
4830 | } | ||
4831 | |||
4832 | if (mpt2sas_fwfault_debug) | ||
4833 | mpt2sas_halt_firmware(ioc); | ||
4834 | |||
4835 | /* TODO - What we really should be doing is pulling | ||
4836 | * out all the code associated with NO_SLEEP; its never used. | ||
4837 | * That is legacy code from mpt fusion driver, ported over. | ||
4838 | * I will leave this BUG_ON here for now till its been resolved. | ||
4839 | */ | ||
4840 | BUG_ON(sleep_flag == NO_SLEEP); | ||
4841 | |||
4842 | /* wait for an active reset in progress to complete */ | ||
4843 | if (!mutex_trylock(&ioc->reset_in_progress_mutex)) { | ||
4844 | do { | ||
4845 | ssleep(1); | ||
4846 | } while (ioc->shost_recovery == 1); | ||
4847 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name, | ||
4848 | __func__)); | ||
4849 | return ioc->ioc_reset_in_progress_status; | ||
4850 | } | ||
4851 | |||
4852 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); | ||
4853 | ioc->shost_recovery = 1; | ||
4854 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); | ||
4855 | |||
4856 | _base_reset_handler(ioc, MPT2_IOC_PRE_RESET); | ||
4857 | _wait_for_commands_to_complete(ioc, sleep_flag); | ||
4858 | _base_mask_interrupts(ioc); | ||
4859 | r = _base_make_ioc_ready(ioc, sleep_flag, type); | ||
4860 | if (r) | ||
4861 | goto out; | ||
4862 | _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET); | ||
4863 | |||
4864 | /* If this hard reset is called while port enable is active, then | ||
4865 | * there is no reason to call make_ioc_operational | ||
4866 | */ | ||
4867 | if (ioc->is_driver_loading && ioc->port_enable_failed) { | ||
4868 | ioc->remove_host = 1; | ||
4869 | r = -EFAULT; | ||
4870 | goto out; | ||
4871 | } | ||
4872 | |||
4873 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); | ||
4874 | if (r) | ||
4875 | goto out; | ||
4876 | |||
4877 | if (ioc->rdpq_array_enable && !ioc->rdpq_array_capable) | ||
4878 | panic("%s: Issue occurred with flashing controller firmware." | ||
4879 | "Please reboot the system and ensure that the correct" | ||
4880 | " firmware version is running\n", ioc->name); | ||
4881 | |||
4882 | r = _base_make_ioc_operational(ioc, sleep_flag); | ||
4883 | if (!r) | ||
4884 | _base_reset_handler(ioc, MPT2_IOC_DONE_RESET); | ||
4885 | out: | ||
4886 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n", | ||
4887 | ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED"))); | ||
4888 | |||
4889 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); | ||
4890 | ioc->ioc_reset_in_progress_status = r; | ||
4891 | ioc->shost_recovery = 0; | ||
4892 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); | ||
4893 | mutex_unlock(&ioc->reset_in_progress_mutex); | ||
4894 | |||
4895 | out_unlocked: | ||
4896 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name, | ||
4897 | __func__)); | ||
4898 | return r; | ||
4899 | } | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h deleted file mode 100644 index 65e1046efd87..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_base.h +++ /dev/null | |||
@@ -1,1235 +0,0 @@ | |||
1 | /* | ||
2 | * This is the Fusion MPT base driver providing common API layer interface | ||
3 | * for access to MPT (Message Passing Technology) firmware. | ||
4 | * | ||
5 | * This code is based on drivers/scsi/mpt2sas/mpt2_base.h | ||
6 | * Copyright (C) 2007-2014 LSI Corporation | ||
7 | * Copyright (C) 20013-2014 Avago Technologies | ||
8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version 2 | ||
13 | * of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * NO WARRANTY | ||
21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
25 | * solely responsible for determining the appropriateness of using and | ||
26 | * distributing the Program and assumes all risks associated with its | ||
27 | * exercise of rights under this Agreement, including but not limited to | ||
28 | * the risks and costs of program errors, damage to or loss of data, | ||
29 | * programs or equipment, and unavailability or interruption of operations. | ||
30 | |||
31 | * DISCLAIMER OF LIABILITY | ||
32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
39 | |||
40 | * You should have received a copy of the GNU General Public License | ||
41 | * along with this program; if not, write to the Free Software | ||
42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
43 | * USA. | ||
44 | */ | ||
45 | |||
46 | #ifndef MPT2SAS_BASE_H_INCLUDED | ||
47 | #define MPT2SAS_BASE_H_INCLUDED | ||
48 | |||
49 | #include "mpi/mpi2_type.h" | ||
50 | #include "mpi/mpi2.h" | ||
51 | #include "mpi/mpi2_ioc.h" | ||
52 | #include "mpi/mpi2_cnfg.h" | ||
53 | #include "mpi/mpi2_init.h" | ||
54 | #include "mpi/mpi2_raid.h" | ||
55 | #include "mpi/mpi2_tool.h" | ||
56 | #include "mpi/mpi2_sas.h" | ||
57 | |||
58 | #include <scsi/scsi.h> | ||
59 | #include <scsi/scsi_cmnd.h> | ||
60 | #include <scsi/scsi_device.h> | ||
61 | #include <scsi/scsi_host.h> | ||
62 | #include <scsi/scsi_tcq.h> | ||
63 | #include <scsi/scsi_transport_sas.h> | ||
64 | #include <scsi/scsi_dbg.h> | ||
65 | #include <scsi/scsi_eh.h> | ||
66 | |||
67 | #include "mpt2sas_debug.h" | ||
68 | |||
69 | /* driver versioning info */ | ||
70 | #define MPT2SAS_DRIVER_NAME "mpt2sas" | ||
71 | #define MPT2SAS_AUTHOR "Avago Technologies <MPT-FusionLinux.pdl@avagotech.com>" | ||
72 | #define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" | ||
73 | #define MPT2SAS_DRIVER_VERSION "20.100.00.00" | ||
74 | #define MPT2SAS_MAJOR_VERSION 20 | ||
75 | #define MPT2SAS_MINOR_VERSION 100 | ||
76 | #define MPT2SAS_BUILD_VERSION 00 | ||
77 | #define MPT2SAS_RELEASE_VERSION 00 | ||
78 | |||
79 | /* | ||
80 | * Set MPT2SAS_SG_DEPTH value based on user input. | ||
81 | */ | ||
82 | #ifdef CONFIG_SCSI_MPT2SAS_MAX_SGE | ||
83 | #if CONFIG_SCSI_MPT2SAS_MAX_SGE < 16 | ||
84 | #define MPT2SAS_SG_DEPTH 16 | ||
85 | #elif CONFIG_SCSI_MPT2SAS_MAX_SGE > 128 | ||
86 | #define MPT2SAS_SG_DEPTH 128 | ||
87 | #else | ||
88 | #define MPT2SAS_SG_DEPTH CONFIG_SCSI_MPT2SAS_MAX_SGE | ||
89 | #endif | ||
90 | #else | ||
91 | #define MPT2SAS_SG_DEPTH 128 /* MAX_HW_SEGMENTS */ | ||
92 | #endif | ||
93 | |||
94 | |||
95 | /* | ||
96 | * Generic Defines | ||
97 | */ | ||
98 | #define MPT2SAS_SATA_QUEUE_DEPTH 32 | ||
99 | #define MPT2SAS_SAS_QUEUE_DEPTH 254 | ||
100 | #define MPT2SAS_RAID_QUEUE_DEPTH 128 | ||
101 | |||
102 | #define MPT_NAME_LENGTH 32 /* generic length of strings */ | ||
103 | #define MPT_STRING_LENGTH 64 | ||
104 | |||
105 | #define MPT_MAX_CALLBACKS 16 | ||
106 | |||
107 | |||
108 | #define CAN_SLEEP 1 | ||
109 | #define NO_SLEEP 0 | ||
110 | |||
111 | #define INTERNAL_CMDS_COUNT 10 /* reserved cmds */ | ||
112 | |||
113 | #define MPI2_HIM_MASK 0xFFFFFFFF /* mask every bit*/ | ||
114 | |||
115 | #define MPT2SAS_INVALID_DEVICE_HANDLE 0xFFFF | ||
116 | |||
117 | |||
118 | /* | ||
119 | * reset phases | ||
120 | */ | ||
121 | #define MPT2_IOC_PRE_RESET 1 /* prior to host reset */ | ||
122 | #define MPT2_IOC_AFTER_RESET 2 /* just after host reset */ | ||
123 | #define MPT2_IOC_DONE_RESET 3 /* links re-initialized */ | ||
124 | |||
125 | /* | ||
126 | * logging format | ||
127 | */ | ||
128 | #define MPT2SAS_FMT "%s: " | ||
129 | #define MPT2SAS_INFO_FMT KERN_INFO MPT2SAS_FMT | ||
130 | #define MPT2SAS_NOTE_FMT KERN_NOTICE MPT2SAS_FMT | ||
131 | #define MPT2SAS_WARN_FMT KERN_WARNING MPT2SAS_FMT | ||
132 | #define MPT2SAS_ERR_FMT KERN_ERR MPT2SAS_FMT | ||
133 | |||
134 | /* | ||
135 | * Dell HBA branding | ||
136 | */ | ||
137 | #define MPT2SAS_DELL_BRANDING_SIZE 32 | ||
138 | |||
139 | #define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING "Dell 6Gbps SAS HBA" | ||
140 | #define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING "Dell PERC H200 Adapter" | ||
141 | #define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated" | ||
142 | #define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING "Dell PERC H200 Modular" | ||
143 | #define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING "Dell PERC H200 Embedded" | ||
144 | #define MPT2SAS_DELL_PERC_H200_BRANDING "Dell PERC H200" | ||
145 | #define MPT2SAS_DELL_6GBPS_SAS_BRANDING "Dell 6Gbps SAS" | ||
146 | |||
147 | /* | ||
148 | * Dell HBA SSDIDs | ||
149 | */ | ||
150 | #define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID 0x1F1C | ||
151 | #define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID 0x1F1D | ||
152 | #define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID 0x1F1E | ||
153 | #define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID 0x1F1F | ||
154 | #define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID 0x1F20 | ||
155 | #define MPT2SAS_DELL_PERC_H200_SSDID 0x1F21 | ||
156 | #define MPT2SAS_DELL_6GBPS_SAS_SSDID 0x1F22 | ||
157 | |||
158 | /* | ||
159 | * Intel HBA branding | ||
160 | */ | ||
161 | #define MPT2SAS_INTEL_RMS25JB080_BRANDING \ | ||
162 | "Intel(R) Integrated RAID Module RMS25JB080" | ||
163 | #define MPT2SAS_INTEL_RMS25JB040_BRANDING \ | ||
164 | "Intel(R) Integrated RAID Module RMS25JB040" | ||
165 | #define MPT2SAS_INTEL_RMS25KB080_BRANDING \ | ||
166 | "Intel(R) Integrated RAID Module RMS25KB080" | ||
167 | #define MPT2SAS_INTEL_RMS25KB040_BRANDING \ | ||
168 | "Intel(R) Integrated RAID Module RMS25KB040" | ||
169 | #define MPT2SAS_INTEL_RMS25LB040_BRANDING \ | ||
170 | "Intel(R) Integrated RAID Module RMS25LB040" | ||
171 | #define MPT2SAS_INTEL_RMS25LB080_BRANDING \ | ||
172 | "Intel(R) Integrated RAID Module RMS25LB080" | ||
173 | #define MPT2SAS_INTEL_RMS2LL080_BRANDING \ | ||
174 | "Intel Integrated RAID Module RMS2LL080" | ||
175 | #define MPT2SAS_INTEL_RMS2LL040_BRANDING \ | ||
176 | "Intel Integrated RAID Module RMS2LL040" | ||
177 | #define MPT2SAS_INTEL_RS25GB008_BRANDING \ | ||
178 | "Intel(R) RAID Controller RS25GB008" | ||
179 | #define MPT2SAS_INTEL_SSD910_BRANDING \ | ||
180 | "Intel(R) SSD 910 Series" | ||
181 | /* | ||
182 | * Intel HBA SSDIDs | ||
183 | */ | ||
184 | #define MPT2SAS_INTEL_RMS25JB080_SSDID 0x3516 | ||
185 | #define MPT2SAS_INTEL_RMS25JB040_SSDID 0x3517 | ||
186 | #define MPT2SAS_INTEL_RMS25KB080_SSDID 0x3518 | ||
187 | #define MPT2SAS_INTEL_RMS25KB040_SSDID 0x3519 | ||
188 | #define MPT2SAS_INTEL_RMS25LB040_SSDID 0x351A | ||
189 | #define MPT2SAS_INTEL_RMS25LB080_SSDID 0x351B | ||
190 | #define MPT2SAS_INTEL_RMS2LL080_SSDID 0x350E | ||
191 | #define MPT2SAS_INTEL_RMS2LL040_SSDID 0x350F | ||
192 | #define MPT2SAS_INTEL_RS25GB008_SSDID 0x3000 | ||
193 | #define MPT2SAS_INTEL_SSD910_SSDID 0x3700 | ||
194 | |||
195 | /* | ||
196 | * HP HBA branding | ||
197 | */ | ||
198 | #define MPT2SAS_HP_3PAR_SSVID 0x1590 | ||
199 | #define MPT2SAS_HP_2_4_INTERNAL_BRANDING "HP H220 Host Bus Adapter" | ||
200 | #define MPT2SAS_HP_2_4_EXTERNAL_BRANDING "HP H221 Host Bus Adapter" | ||
201 | #define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING "HP H222 Host Bus Adapter" | ||
202 | #define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING "HP H220i Host Bus Adapter" | ||
203 | #define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING "HP H210i Host Bus Adapter" | ||
204 | |||
205 | /* | ||
206 | * HO HBA SSDIDs | ||
207 | */ | ||
208 | #define MPT2SAS_HP_2_4_INTERNAL_SSDID 0x0041 | ||
209 | #define MPT2SAS_HP_2_4_EXTERNAL_SSDID 0x0042 | ||
210 | #define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID 0x0043 | ||
211 | #define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID 0x0044 | ||
212 | #define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID 0x0046 | ||
213 | |||
214 | /* | ||
215 | * WarpDrive Specific Log codes | ||
216 | */ | ||
217 | |||
218 | #define MPT2_WARPDRIVE_LOGENTRY (0x8002) | ||
219 | #define MPT2_WARPDRIVE_LC_SSDT (0x41) | ||
220 | #define MPT2_WARPDRIVE_LC_SSDLW (0x43) | ||
221 | #define MPT2_WARPDRIVE_LC_SSDLF (0x44) | ||
222 | #define MPT2_WARPDRIVE_LC_BRMF (0x4D) | ||
223 | |||
224 | /* | ||
225 | * per target private data | ||
226 | */ | ||
227 | #define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01 | ||
228 | #define MPT_TARGET_FLAGS_VOLUME 0x02 | ||
229 | #define MPT_TARGET_FLAGS_DELETED 0x04 | ||
230 | |||
231 | /** | ||
232 | * struct MPT2SAS_TARGET - starget private hostdata | ||
233 | * @starget: starget object | ||
234 | * @sas_address: target sas address | ||
235 | * @raid_device: raid_device pointer to access volume data | ||
236 | * @handle: device handle | ||
237 | * @num_luns: number luns | ||
238 | * @flags: MPT_TARGET_FLAGS_XXX flags | ||
239 | * @deleted: target flaged for deletion | ||
240 | * @tm_busy: target is busy with TM request. | ||
241 | * @sdev: The sas_device associated with this target | ||
242 | */ | ||
243 | struct MPT2SAS_TARGET { | ||
244 | struct scsi_target *starget; | ||
245 | u64 sas_address; | ||
246 | struct _raid_device *raid_device; | ||
247 | u16 handle; | ||
248 | int num_luns; | ||
249 | u32 flags; | ||
250 | u8 deleted; | ||
251 | u8 tm_busy; | ||
252 | struct _sas_device *sdev; | ||
253 | }; | ||
254 | |||
255 | |||
256 | /* | ||
257 | * per device private data | ||
258 | */ | ||
259 | #define MPT_DEVICE_FLAGS_INIT 0x01 | ||
260 | #define MPT_DEVICE_TLR_ON 0x02 | ||
261 | |||
262 | /** | ||
263 | * struct MPT2SAS_DEVICE - sdev private hostdata | ||
264 | * @sas_target: starget private hostdata | ||
265 | * @lun: lun number | ||
266 | * @flags: MPT_DEVICE_XXX flags | ||
267 | * @configured_lun: lun is configured | ||
268 | * @block: device is in SDEV_BLOCK state | ||
269 | * @tlr_snoop_check: flag used in determining whether to disable TLR | ||
270 | */ | ||
271 | |||
272 | /* OEM Identifiers */ | ||
273 | #define MFG10_OEM_ID_INVALID (0x00000000) | ||
274 | #define MFG10_OEM_ID_DELL (0x00000001) | ||
275 | #define MFG10_OEM_ID_FSC (0x00000002) | ||
276 | #define MFG10_OEM_ID_SUN (0x00000003) | ||
277 | #define MFG10_OEM_ID_IBM (0x00000004) | ||
278 | |||
279 | /* GENERIC Flags 0*/ | ||
280 | #define MFG10_GF0_OCE_DISABLED (0x00000001) | ||
281 | #define MFG10_GF0_R1E_DRIVE_COUNT (0x00000002) | ||
282 | #define MFG10_GF0_R10_DISPLAY (0x00000004) | ||
283 | #define MFG10_GF0_SSD_DATA_SCRUB_DISABLE (0x00000008) | ||
284 | #define MFG10_GF0_SINGLE_DRIVE_R0 (0x00000010) | ||
285 | |||
286 | /* OEM Specific Flags will come from OEM specific header files */ | ||
287 | typedef struct _MPI2_CONFIG_PAGE_MAN_10 { | ||
288 | MPI2_CONFIG_PAGE_HEADER Header; /* 00h */ | ||
289 | U8 OEMIdentifier; /* 04h */ | ||
290 | U8 Reserved1; /* 05h */ | ||
291 | U16 Reserved2; /* 08h */ | ||
292 | U32 Reserved3; /* 0Ch */ | ||
293 | U32 GenericFlags0; /* 10h */ | ||
294 | U32 GenericFlags1; /* 14h */ | ||
295 | U32 Reserved4; /* 18h */ | ||
296 | U32 OEMSpecificFlags0; /* 1Ch */ | ||
297 | U32 OEMSpecificFlags1; /* 20h */ | ||
298 | U32 Reserved5[18]; /* 24h-60h*/ | ||
299 | } MPI2_CONFIG_PAGE_MAN_10, | ||
300 | *PTR_MPI2_CONFIG_PAGE_MAN_10, | ||
301 | Mpi2ManufacturingPage10_t, *pMpi2ManufacturingPage10_t; | ||
302 | |||
303 | #define MFG_PAGE10_HIDE_SSDS_MASK (0x00000003) | ||
304 | #define MFG_PAGE10_HIDE_ALL_DISKS (0x00) | ||
305 | #define MFG_PAGE10_EXPOSE_ALL_DISKS (0x01) | ||
306 | #define MFG_PAGE10_HIDE_IF_VOL_PRESENT (0x02) | ||
307 | |||
308 | |||
309 | struct MPT2SAS_DEVICE { | ||
310 | struct MPT2SAS_TARGET *sas_target; | ||
311 | unsigned int lun; | ||
312 | u32 flags; | ||
313 | u8 configured_lun; | ||
314 | u8 block; | ||
315 | u8 tlr_snoop_check; | ||
316 | }; | ||
317 | |||
318 | #define MPT2_CMD_NOT_USED 0x8000 /* free */ | ||
319 | #define MPT2_CMD_COMPLETE 0x0001 /* completed */ | ||
320 | #define MPT2_CMD_PENDING 0x0002 /* pending */ | ||
321 | #define MPT2_CMD_REPLY_VALID 0x0004 /* reply is valid */ | ||
322 | #define MPT2_CMD_RESET 0x0008 /* host reset dropped the command */ | ||
323 | |||
324 | /** | ||
325 | * struct _internal_cmd - internal commands struct | ||
326 | * @mutex: mutex | ||
327 | * @done: completion | ||
328 | * @reply: reply message pointer | ||
329 | * @sense: sense data | ||
330 | * @status: MPT2_CMD_XXX status | ||
331 | * @smid: system message id | ||
332 | */ | ||
333 | struct _internal_cmd { | ||
334 | struct mutex mutex; | ||
335 | struct completion done; | ||
336 | void *reply; | ||
337 | void *sense; | ||
338 | u16 status; | ||
339 | u16 smid; | ||
340 | }; | ||
341 | |||
342 | |||
343 | /** | ||
344 | * struct _sas_device - attached device information | ||
345 | * @list: sas device list | ||
346 | * @starget: starget object | ||
347 | * @sas_address: device sas address | ||
348 | * @device_name: retrieved from the SAS IDENTIFY frame. | ||
349 | * @handle: device handle | ||
350 | * @sas_address_parent: sas address of parent expander or sas host | ||
351 | * @enclosure_handle: enclosure handle | ||
352 | * @enclosure_logical_id: enclosure logical identifier | ||
353 | * @volume_handle: volume handle (valid when hidden raid member) | ||
354 | * @volume_wwid: volume unique identifier | ||
355 | * @device_info: bitfield provides detailed info about the device | ||
356 | * @id: target id | ||
357 | * @channel: target channel | ||
358 | * @slot: number number | ||
359 | * @phy: phy identifier provided in sas device page 0 | ||
360 | * @responding: used in _scsih_sas_device_mark_responding | ||
361 | * @pfa_led_on: flag for PFA LED status | ||
362 | */ | ||
363 | struct _sas_device { | ||
364 | struct list_head list; | ||
365 | struct scsi_target *starget; | ||
366 | u64 sas_address; | ||
367 | u64 device_name; | ||
368 | u16 handle; | ||
369 | u64 sas_address_parent; | ||
370 | u16 enclosure_handle; | ||
371 | u64 enclosure_logical_id; | ||
372 | u16 volume_handle; | ||
373 | u64 volume_wwid; | ||
374 | u32 device_info; | ||
375 | int id; | ||
376 | int channel; | ||
377 | u16 slot; | ||
378 | u8 phy; | ||
379 | u8 responding; | ||
380 | u8 pfa_led_on; | ||
381 | struct kref refcount; | ||
382 | }; | ||
383 | |||
384 | static inline void sas_device_get(struct _sas_device *s) | ||
385 | { | ||
386 | kref_get(&s->refcount); | ||
387 | } | ||
388 | |||
389 | static inline void sas_device_free(struct kref *r) | ||
390 | { | ||
391 | kfree(container_of(r, struct _sas_device, refcount)); | ||
392 | } | ||
393 | |||
394 | static inline void sas_device_put(struct _sas_device *s) | ||
395 | { | ||
396 | kref_put(&s->refcount, sas_device_free); | ||
397 | } | ||
398 | |||
399 | /** | ||
400 | * struct _raid_device - raid volume link list | ||
401 | * @list: sas device list | ||
402 | * @starget: starget object | ||
403 | * @sdev: scsi device struct (volumes are single lun) | ||
404 | * @wwid: unique identifier for the volume | ||
405 | * @handle: device handle | ||
406 | * @block_size: Block size of the volume | ||
407 | * @id: target id | ||
408 | * @channel: target channel | ||
409 | * @volume_type: the raid level | ||
410 | * @device_info: bitfield provides detailed info about the hidden components | ||
411 | * @num_pds: number of hidden raid components | ||
412 | * @responding: used in _scsih_raid_device_mark_responding | ||
413 | * @percent_complete: resync percent complete | ||
414 | * @direct_io_enabled: Whether direct io to PDs are allowed or not | ||
415 | * @stripe_exponent: X where 2powX is the stripe sz in blocks | ||
416 | * @block_exponent: X where 2powX is the block sz in bytes | ||
417 | * @max_lba: Maximum number of LBA in the volume | ||
418 | * @stripe_sz: Stripe Size of the volume | ||
419 | * @device_info: Device info of the volume member disk | ||
420 | * @pd_handle: Array of handles of the physical drives for direct I/O in le16 | ||
421 | */ | ||
422 | #define MPT_MAX_WARPDRIVE_PDS 8 | ||
423 | struct _raid_device { | ||
424 | struct list_head list; | ||
425 | struct scsi_target *starget; | ||
426 | struct scsi_device *sdev; | ||
427 | u64 wwid; | ||
428 | u16 handle; | ||
429 | u16 block_sz; | ||
430 | int id; | ||
431 | int channel; | ||
432 | u8 volume_type; | ||
433 | u8 num_pds; | ||
434 | u8 responding; | ||
435 | u8 percent_complete; | ||
436 | u8 direct_io_enabled; | ||
437 | u8 stripe_exponent; | ||
438 | u8 block_exponent; | ||
439 | u64 max_lba; | ||
440 | u32 stripe_sz; | ||
441 | u32 device_info; | ||
442 | u16 pd_handle[MPT_MAX_WARPDRIVE_PDS]; | ||
443 | }; | ||
444 | |||
445 | /** | ||
446 | * struct _boot_device - boot device info | ||
447 | * @is_raid: flag to indicate whether this is volume | ||
448 | * @device: holds pointer for either struct _sas_device or | ||
449 | * struct _raid_device | ||
450 | */ | ||
451 | struct _boot_device { | ||
452 | u8 is_raid; | ||
453 | void *device; | ||
454 | }; | ||
455 | |||
456 | /** | ||
457 | * struct _sas_port - wide/narrow sas port information | ||
458 | * @port_list: list of ports belonging to expander | ||
459 | * @num_phys: number of phys belonging to this port | ||
460 | * @remote_identify: attached device identification | ||
461 | * @rphy: sas transport rphy object | ||
462 | * @port: sas transport wide/narrow port object | ||
463 | * @phy_list: _sas_phy list objects belonging to this port | ||
464 | */ | ||
465 | struct _sas_port { | ||
466 | struct list_head port_list; | ||
467 | u8 num_phys; | ||
468 | struct sas_identify remote_identify; | ||
469 | struct sas_rphy *rphy; | ||
470 | struct sas_port *port; | ||
471 | struct list_head phy_list; | ||
472 | }; | ||
473 | |||
474 | /** | ||
475 | * struct _sas_phy - phy information | ||
476 | * @port_siblings: list of phys belonging to a port | ||
477 | * @identify: phy identification | ||
478 | * @remote_identify: attached device identification | ||
479 | * @phy: sas transport phy object | ||
480 | * @phy_id: unique phy id | ||
481 | * @handle: device handle for this phy | ||
482 | * @attached_handle: device handle for attached device | ||
483 | * @phy_belongs_to_port: port has been created for this phy | ||
484 | */ | ||
485 | struct _sas_phy { | ||
486 | struct list_head port_siblings; | ||
487 | struct sas_identify identify; | ||
488 | struct sas_identify remote_identify; | ||
489 | struct sas_phy *phy; | ||
490 | u8 phy_id; | ||
491 | u16 handle; | ||
492 | u16 attached_handle; | ||
493 | u8 phy_belongs_to_port; | ||
494 | }; | ||
495 | |||
496 | /** | ||
497 | * struct _sas_node - sas_host/expander information | ||
498 | * @list: list of expanders | ||
499 | * @parent_dev: parent device class | ||
500 | * @num_phys: number phys belonging to this sas_host/expander | ||
501 | * @sas_address: sas address of this sas_host/expander | ||
502 | * @handle: handle for this sas_host/expander | ||
503 | * @sas_address_parent: sas address of parent expander or sas host | ||
504 | * @enclosure_handle: handle for this a member of an enclosure | ||
505 | * @device_info: bitwise defining capabilities of this sas_host/expander | ||
506 | * @responding: used in _scsih_expander_device_mark_responding | ||
507 | * @phy: a list of phys that make up this sas_host/expander | ||
508 | * @sas_port_list: list of ports attached to this sas_host/expander | ||
509 | */ | ||
510 | struct _sas_node { | ||
511 | struct list_head list; | ||
512 | struct device *parent_dev; | ||
513 | u8 num_phys; | ||
514 | u64 sas_address; | ||
515 | u16 handle; | ||
516 | u64 sas_address_parent; | ||
517 | u16 enclosure_handle; | ||
518 | u64 enclosure_logical_id; | ||
519 | u8 responding; | ||
520 | struct _sas_phy *phy; | ||
521 | struct list_head sas_port_list; | ||
522 | }; | ||
523 | |||
524 | /** | ||
525 | * enum reset_type - reset state | ||
526 | * @FORCE_BIG_HAMMER: issue diagnostic reset | ||
527 | * @SOFT_RESET: issue message_unit_reset, if fails to to big hammer | ||
528 | */ | ||
529 | enum reset_type { | ||
530 | FORCE_BIG_HAMMER, | ||
531 | SOFT_RESET, | ||
532 | }; | ||
533 | |||
534 | /** | ||
535 | * struct chain_tracker - firmware chain tracker | ||
536 | * @chain_buffer: chain buffer | ||
537 | * @chain_buffer_dma: physical address | ||
538 | * @tracker_list: list of free request (ioc->free_chain_list) | ||
539 | */ | ||
540 | struct chain_tracker { | ||
541 | void *chain_buffer; | ||
542 | dma_addr_t chain_buffer_dma; | ||
543 | struct list_head tracker_list; | ||
544 | }; | ||
545 | |||
546 | /** | ||
547 | * struct scsiio_tracker - scsi mf request tracker | ||
548 | * @smid: system message id | ||
549 | * @scmd: scsi request pointer | ||
550 | * @cb_idx: callback index | ||
551 | * @direct_io: To indicate whether I/O is direct (WARPDRIVE) | ||
552 | * @chain_list: list of chains associated to this IO | ||
553 | * @tracker_list: list of free request (ioc->free_list) | ||
554 | */ | ||
555 | struct scsiio_tracker { | ||
556 | u16 smid; | ||
557 | struct scsi_cmnd *scmd; | ||
558 | u8 cb_idx; | ||
559 | u8 direct_io; | ||
560 | struct list_head chain_list; | ||
561 | struct list_head tracker_list; | ||
562 | }; | ||
563 | |||
564 | /** | ||
565 | * struct request_tracker - firmware request tracker | ||
566 | * @smid: system message id | ||
567 | * @cb_idx: callback index | ||
568 | * @tracker_list: list of free request (ioc->free_list) | ||
569 | */ | ||
570 | struct request_tracker { | ||
571 | u16 smid; | ||
572 | u8 cb_idx; | ||
573 | struct list_head tracker_list; | ||
574 | }; | ||
575 | |||
576 | /** | ||
577 | * struct _tr_list - target reset list | ||
578 | * @handle: device handle | ||
579 | * @state: state machine | ||
580 | */ | ||
581 | struct _tr_list { | ||
582 | struct list_head list; | ||
583 | u16 handle; | ||
584 | u16 state; | ||
585 | }; | ||
586 | |||
587 | typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr); | ||
588 | |||
589 | /** | ||
590 | * struct adapter_reply_queue - the reply queue struct | ||
591 | * @ioc: per adapter object | ||
592 | * @msix_index: msix index into vector table | ||
593 | * @vector: irq vector | ||
594 | * @reply_post_host_index: head index in the pool where FW completes IO | ||
595 | * @reply_post_free: reply post base virt address | ||
596 | * @name: the name registered to request_irq() | ||
597 | * @busy: isr is actively processing replies on another cpu | ||
598 | * @list: this list | ||
599 | */ | ||
600 | struct adapter_reply_queue { | ||
601 | struct MPT2SAS_ADAPTER *ioc; | ||
602 | u8 msix_index; | ||
603 | unsigned int vector; | ||
604 | u32 reply_post_host_index; | ||
605 | Mpi2ReplyDescriptorsUnion_t *reply_post_free; | ||
606 | char name[MPT_NAME_LENGTH]; | ||
607 | atomic_t busy; | ||
608 | cpumask_var_t affinity_hint; | ||
609 | struct list_head list; | ||
610 | }; | ||
611 | |||
612 | /* IOC Facts and Port Facts converted from little endian to cpu */ | ||
613 | union mpi2_version_union { | ||
614 | MPI2_VERSION_STRUCT Struct; | ||
615 | u32 Word; | ||
616 | }; | ||
617 | |||
618 | struct mpt2sas_facts { | ||
619 | u16 MsgVersion; | ||
620 | u16 HeaderVersion; | ||
621 | u8 IOCNumber; | ||
622 | u8 VP_ID; | ||
623 | u8 VF_ID; | ||
624 | u16 IOCExceptions; | ||
625 | u16 IOCStatus; | ||
626 | u32 IOCLogInfo; | ||
627 | u8 MaxChainDepth; | ||
628 | u8 WhoInit; | ||
629 | u8 NumberOfPorts; | ||
630 | u8 MaxMSIxVectors; | ||
631 | u16 RequestCredit; | ||
632 | u16 ProductID; | ||
633 | u32 IOCCapabilities; | ||
634 | union mpi2_version_union FWVersion; | ||
635 | u16 IOCRequestFrameSize; | ||
636 | u16 Reserved3; | ||
637 | u16 MaxInitiators; | ||
638 | u16 MaxTargets; | ||
639 | u16 MaxSasExpanders; | ||
640 | u16 MaxEnclosures; | ||
641 | u16 ProtocolFlags; | ||
642 | u16 HighPriorityCredit; | ||
643 | u16 MaxReplyDescriptorPostQueueDepth; | ||
644 | u8 ReplyFrameSize; | ||
645 | u8 MaxVolumes; | ||
646 | u16 MaxDevHandle; | ||
647 | u16 MaxPersistentEntries; | ||
648 | u16 MinDevHandle; | ||
649 | }; | ||
650 | |||
651 | struct mpt2sas_port_facts { | ||
652 | u8 PortNumber; | ||
653 | u8 VP_ID; | ||
654 | u8 VF_ID; | ||
655 | u8 PortType; | ||
656 | u16 MaxPostedCmdBuffers; | ||
657 | }; | ||
658 | |||
659 | struct reply_post_struct { | ||
660 | Mpi2ReplyDescriptorsUnion_t *reply_post_free; | ||
661 | dma_addr_t reply_post_free_dma; | ||
662 | }; | ||
663 | |||
664 | /** | ||
665 | * enum mutex_type - task management mutex type | ||
666 | * @TM_MUTEX_OFF: mutex is not required becuase calling function is acquiring it | ||
667 | * @TM_MUTEX_ON: mutex is required | ||
668 | */ | ||
669 | enum mutex_type { | ||
670 | TM_MUTEX_OFF = 0, | ||
671 | TM_MUTEX_ON = 1, | ||
672 | }; | ||
673 | |||
674 | typedef void (*MPT2SAS_FLUSH_RUNNING_CMDS)(struct MPT2SAS_ADAPTER *ioc); | ||
675 | /** | ||
676 | * struct MPT2SAS_ADAPTER - per adapter struct | ||
677 | * @list: ioc_list | ||
678 | * @shost: shost object | ||
679 | * @id: unique adapter id | ||
680 | * @cpu_count: number online cpus | ||
681 | * @name: generic ioc string | ||
682 | * @tmp_string: tmp string used for logging | ||
683 | * @pdev: pci pdev object | ||
684 | * @chip: memory mapped register space | ||
685 | * @chip_phys: physical addrss prior to mapping | ||
686 | * @logging_level: see mpt2sas_debug.h | ||
687 | * @fwfault_debug: debuging FW timeouts | ||
688 | * @ir_firmware: IR firmware present | ||
689 | * @bars: bitmask of BAR's that must be configured | ||
690 | * @mask_interrupts: ignore interrupt | ||
691 | * @dma_mask: used to set the consistent dma mask | ||
692 | * @fault_reset_work_q_name: fw fault work queue | ||
693 | * @fault_reset_work_q: "" | ||
694 | * @fault_reset_work: "" | ||
695 | * @firmware_event_name: fw event work queue | ||
696 | * @firmware_event_thread: "" | ||
697 | * @fw_events_off: flag to turn off fw event handling | ||
698 | * @fw_event_lock: | ||
699 | * @fw_event_list: list of fw events | ||
700 | * @aen_event_read_flag: event log was read | ||
701 | * @broadcast_aen_busy: broadcast aen waiting to be serviced | ||
702 | * @shost_recovery: host reset in progress | ||
703 | * @ioc_reset_in_progress_lock: | ||
704 | * @ioc_link_reset_in_progress: phy/hard reset in progress | ||
705 | * @ignore_loginfos: ignore loginfos during task management | ||
706 | * @remove_host: flag for when driver unloads, to avoid sending dev resets | ||
707 | * @pci_error_recovery: flag to prevent ioc access until slot reset completes | ||
708 | * @wait_for_discovery_to_complete: flag set at driver load time when | ||
709 | * waiting on reporting devices | ||
710 | * @is_driver_loading: flag set at driver load time | ||
711 | * @port_enable_failed: flag set when port enable has failed | ||
712 | * @start_scan: flag set from scan_start callback, cleared from _mpt2sas_fw_work | ||
713 | * @start_scan_failed: means port enable failed, return's the ioc_status | ||
714 | * @msix_enable: flag indicating msix is enabled | ||
715 | * @msix_vector_count: number msix vectors | ||
716 | * @cpu_msix_table: table for mapping cpus to msix index | ||
717 | * @cpu_msix_table_sz: table size | ||
718 | * @schedule_dead_ioc_flush_running_cmds: callback to flush pending commands | ||
719 | * @scsi_io_cb_idx: shost generated commands | ||
720 | * @tm_cb_idx: task management commands | ||
721 | * @scsih_cb_idx: scsih internal commands | ||
722 | * @transport_cb_idx: transport internal commands | ||
723 | * @ctl_cb_idx: clt internal commands | ||
724 | * @base_cb_idx: base internal commands | ||
725 | * @config_cb_idx: base internal commands | ||
726 | * @tm_tr_cb_idx : device removal target reset handshake | ||
727 | * @tm_tr_volume_cb_idx : volume removal target reset | ||
728 | * @base_cmds: | ||
729 | * @transport_cmds: | ||
730 | * @scsih_cmds: | ||
731 | * @tm_cmds: | ||
732 | * @ctl_cmds: | ||
733 | * @config_cmds: | ||
734 | * @base_add_sg_single: handler for either 32/64 bit sgl's | ||
735 | * @event_type: bits indicating which events to log | ||
736 | * @event_context: unique id for each logged event | ||
737 | * @event_log: event log pointer | ||
738 | * @event_masks: events that are masked | ||
739 | * @facts: static facts data | ||
740 | * @pfacts: static port facts data | ||
741 | * @manu_pg0: static manufacturing page 0 | ||
742 | * @manu_pg10: static manufacturing page 10 | ||
743 | * @bios_pg2: static bios page 2 | ||
744 | * @bios_pg3: static bios page 3 | ||
745 | * @ioc_pg8: static ioc page 8 | ||
746 | * @iounit_pg0: static iounit page 0 | ||
747 | * @iounit_pg1: static iounit page 1 | ||
748 | * @iounit_pg8: static iounit page 8 | ||
749 | * @sas_hba: sas host object | ||
750 | * @sas_expander_list: expander object list | ||
751 | * @sas_node_lock: | ||
752 | * @sas_device_list: sas device object list | ||
753 | * @sas_device_init_list: sas device object list (used only at init time) | ||
754 | * @sas_device_lock: | ||
755 | * @io_missing_delay: time for IO completed by fw when PDR enabled | ||
756 | * @device_missing_delay: time for device missing by fw when PDR enabled | ||
757 | * @sas_id : used for setting volume target IDs | ||
758 | * @blocking_handles: bitmask used to identify which devices need blocking | ||
759 | * @pd_handles : bitmask for PD handles | ||
760 | * @pd_handles_sz : size of pd_handle bitmask | ||
761 | * @config_page_sz: config page size | ||
762 | * @config_page: reserve memory for config page payload | ||
763 | * @config_page_dma: | ||
764 | * @hba_queue_depth: hba request queue depth | ||
765 | * @sge_size: sg element size for either 32/64 bit | ||
766 | * @scsiio_depth: SCSI_IO queue depth | ||
767 | * @request_sz: per request frame size | ||
768 | * @request: pool of request frames | ||
769 | * @request_dma: | ||
770 | * @request_dma_sz: | ||
771 | * @scsi_lookup: firmware request tracker list | ||
772 | * @scsi_lookup_lock: | ||
773 | * @free_list: free list of request | ||
774 | * @chain: pool of chains | ||
775 | * @pending_io_count: | ||
776 | * @reset_wq: | ||
777 | * @chain_dma: | ||
778 | * @max_sges_in_main_message: number sg elements in main message | ||
779 | * @max_sges_in_chain_message: number sg elements per chain | ||
780 | * @chains_needed_per_io: max chains per io | ||
781 | * @chain_offset_value_for_main_message: location 1st sg in main | ||
782 | * @chain_depth: total chains allocated | ||
783 | * @hi_priority_smid: | ||
784 | * @hi_priority: | ||
785 | * @hi_priority_dma: | ||
786 | * @hi_priority_depth: | ||
787 | * @hpr_lookup: | ||
788 | * @hpr_free_list: | ||
789 | * @internal_smid: | ||
790 | * @internal: | ||
791 | * @internal_dma: | ||
792 | * @internal_depth: | ||
793 | * @internal_lookup: | ||
794 | * @internal_free_list: | ||
795 | * @sense: pool of sense | ||
796 | * @sense_dma: | ||
797 | * @sense_dma_pool: | ||
798 | * @reply_depth: hba reply queue depth: | ||
799 | * @reply_sz: per reply frame size: | ||
800 | * @reply: pool of replys: | ||
801 | * @reply_dma: | ||
802 | * @reply_dma_pool: | ||
803 | * @reply_free_queue_depth: reply free depth | ||
804 | * @reply_free: pool for reply free queue (32 bit addr) | ||
805 | * @reply_free_dma: | ||
806 | * @reply_free_dma_pool: | ||
807 | * @reply_free_host_index: tail index in pool to insert free replys | ||
808 | * @reply_post_queue_depth: reply post queue depth | ||
809 | * @reply_post_struct: struct for reply_post_free physical & virt address | ||
810 | * @rdpq_array_capable: FW supports multiple reply queue addresses in ioc_init | ||
811 | * @rdpq_array_enable: rdpq_array support is enabled in the driver | ||
812 | * @rdpq_array_enable_assigned: this ensures that rdpq_array_enable flag | ||
813 | * is assigned only ones | ||
814 | * @reply_queue_count: number of reply queue's | ||
815 | * @reply_queue_list: link list contaning the reply queue info | ||
816 | * @reply_post_host_index: head index in the pool where FW completes IO | ||
817 | * @delayed_tr_list: target reset link list | ||
818 | * @delayed_tr_volume_list: volume target reset link list | ||
819 | * @@temp_sensors_count: flag to carry the number of temperature sensors | ||
820 | * @pci_access_mutex: Mutex to synchronize ioctl,sysfs show path and | ||
821 | * pci resource handling. PCI resource freeing will lead to free | ||
822 | * vital hardware/memory resource, which might be in use by cli/sysfs | ||
823 | * path functions resulting in Null pointer reference followed by kernel | ||
824 | * crash. To avoid the above race condition we use mutex syncrhonization | ||
825 | * which ensures the syncrhonization between cli/sysfs_show path | ||
826 | */ | ||
827 | struct MPT2SAS_ADAPTER { | ||
828 | struct list_head list; | ||
829 | struct Scsi_Host *shost; | ||
830 | u8 id; | ||
831 | int cpu_count; | ||
832 | char name[MPT_NAME_LENGTH]; | ||
833 | char tmp_string[MPT_STRING_LENGTH]; | ||
834 | struct pci_dev *pdev; | ||
835 | Mpi2SystemInterfaceRegs_t __iomem *chip; | ||
836 | resource_size_t chip_phys; | ||
837 | int logging_level; | ||
838 | int fwfault_debug; | ||
839 | u8 ir_firmware; | ||
840 | int bars; | ||
841 | u8 mask_interrupts; | ||
842 | int dma_mask; | ||
843 | |||
844 | /* fw fault handler */ | ||
845 | char fault_reset_work_q_name[20]; | ||
846 | struct workqueue_struct *fault_reset_work_q; | ||
847 | struct delayed_work fault_reset_work; | ||
848 | |||
849 | /* fw event handler */ | ||
850 | char firmware_event_name[20]; | ||
851 | struct workqueue_struct *firmware_event_thread; | ||
852 | spinlock_t fw_event_lock; | ||
853 | struct list_head fw_event_list; | ||
854 | |||
855 | /* misc flags */ | ||
856 | int aen_event_read_flag; | ||
857 | u8 broadcast_aen_busy; | ||
858 | u16 broadcast_aen_pending; | ||
859 | u8 shost_recovery; | ||
860 | |||
861 | struct mutex reset_in_progress_mutex; | ||
862 | spinlock_t ioc_reset_in_progress_lock; | ||
863 | u8 ioc_link_reset_in_progress; | ||
864 | u8 ioc_reset_in_progress_status; | ||
865 | |||
866 | u8 ignore_loginfos; | ||
867 | u8 remove_host; | ||
868 | u8 pci_error_recovery; | ||
869 | u8 wait_for_discovery_to_complete; | ||
870 | struct completion port_enable_done; | ||
871 | u8 is_driver_loading; | ||
872 | u8 port_enable_failed; | ||
873 | |||
874 | u8 start_scan; | ||
875 | u16 start_scan_failed; | ||
876 | |||
877 | u8 msix_enable; | ||
878 | u16 msix_vector_count; | ||
879 | u8 *cpu_msix_table; | ||
880 | resource_size_t __iomem **reply_post_host_index; | ||
881 | u16 cpu_msix_table_sz; | ||
882 | u32 ioc_reset_count; | ||
883 | MPT2SAS_FLUSH_RUNNING_CMDS schedule_dead_ioc_flush_running_cmds; | ||
884 | u32 non_operational_loop; | ||
885 | |||
886 | /* internal commands, callback index */ | ||
887 | u8 scsi_io_cb_idx; | ||
888 | u8 tm_cb_idx; | ||
889 | u8 transport_cb_idx; | ||
890 | u8 scsih_cb_idx; | ||
891 | u8 ctl_cb_idx; | ||
892 | u8 base_cb_idx; | ||
893 | u8 port_enable_cb_idx; | ||
894 | u8 config_cb_idx; | ||
895 | u8 tm_tr_cb_idx; | ||
896 | u8 tm_tr_volume_cb_idx; | ||
897 | u8 tm_sas_control_cb_idx; | ||
898 | struct _internal_cmd base_cmds; | ||
899 | struct _internal_cmd port_enable_cmds; | ||
900 | struct _internal_cmd transport_cmds; | ||
901 | struct _internal_cmd scsih_cmds; | ||
902 | struct _internal_cmd tm_cmds; | ||
903 | struct _internal_cmd ctl_cmds; | ||
904 | struct _internal_cmd config_cmds; | ||
905 | |||
906 | MPT_ADD_SGE base_add_sg_single; | ||
907 | |||
908 | /* event log */ | ||
909 | u32 event_type[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS]; | ||
910 | u32 event_context; | ||
911 | void *event_log; | ||
912 | u32 event_masks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS]; | ||
913 | |||
914 | /* static config pages */ | ||
915 | struct mpt2sas_facts facts; | ||
916 | struct mpt2sas_port_facts *pfacts; | ||
917 | Mpi2ManufacturingPage0_t manu_pg0; | ||
918 | Mpi2BiosPage2_t bios_pg2; | ||
919 | Mpi2BiosPage3_t bios_pg3; | ||
920 | Mpi2IOCPage8_t ioc_pg8; | ||
921 | Mpi2IOUnitPage0_t iounit_pg0; | ||
922 | Mpi2IOUnitPage1_t iounit_pg1; | ||
923 | Mpi2IOUnitPage8_t iounit_pg8; | ||
924 | |||
925 | struct _boot_device req_boot_device; | ||
926 | struct _boot_device req_alt_boot_device; | ||
927 | struct _boot_device current_boot_device; | ||
928 | |||
929 | /* sas hba, expander, and device list */ | ||
930 | struct _sas_node sas_hba; | ||
931 | struct list_head sas_expander_list; | ||
932 | spinlock_t sas_node_lock; | ||
933 | struct list_head sas_device_list; | ||
934 | struct list_head sas_device_init_list; | ||
935 | spinlock_t sas_device_lock; | ||
936 | struct list_head raid_device_list; | ||
937 | spinlock_t raid_device_lock; | ||
938 | u8 io_missing_delay; | ||
939 | u16 device_missing_delay; | ||
940 | int sas_id; | ||
941 | void *blocking_handles; | ||
942 | void *pd_handles; | ||
943 | u16 pd_handles_sz; | ||
944 | |||
945 | /* config page */ | ||
946 | u16 config_page_sz; | ||
947 | void *config_page; | ||
948 | dma_addr_t config_page_dma; | ||
949 | |||
950 | /* scsiio request */ | ||
951 | u16 hba_queue_depth; | ||
952 | u16 sge_size; | ||
953 | u16 scsiio_depth; | ||
954 | u16 request_sz; | ||
955 | u8 *request; | ||
956 | dma_addr_t request_dma; | ||
957 | u32 request_dma_sz; | ||
958 | struct scsiio_tracker *scsi_lookup; | ||
959 | ulong scsi_lookup_pages; | ||
960 | spinlock_t scsi_lookup_lock; | ||
961 | struct list_head free_list; | ||
962 | int pending_io_count; | ||
963 | wait_queue_head_t reset_wq; | ||
964 | |||
965 | /* chain */ | ||
966 | struct chain_tracker *chain_lookup; | ||
967 | struct list_head free_chain_list; | ||
968 | struct dma_pool *chain_dma_pool; | ||
969 | ulong chain_pages; | ||
970 | u16 max_sges_in_main_message; | ||
971 | u16 max_sges_in_chain_message; | ||
972 | u16 chains_needed_per_io; | ||
973 | u16 chain_offset_value_for_main_message; | ||
974 | u32 chain_depth; | ||
975 | |||
976 | /* hi-priority queue */ | ||
977 | u16 hi_priority_smid; | ||
978 | u8 *hi_priority; | ||
979 | dma_addr_t hi_priority_dma; | ||
980 | u16 hi_priority_depth; | ||
981 | struct request_tracker *hpr_lookup; | ||
982 | struct list_head hpr_free_list; | ||
983 | |||
984 | /* internal queue */ | ||
985 | u16 internal_smid; | ||
986 | u8 *internal; | ||
987 | dma_addr_t internal_dma; | ||
988 | u16 internal_depth; | ||
989 | struct request_tracker *internal_lookup; | ||
990 | struct list_head internal_free_list; | ||
991 | |||
992 | /* sense */ | ||
993 | u8 *sense; | ||
994 | dma_addr_t sense_dma; | ||
995 | struct dma_pool *sense_dma_pool; | ||
996 | |||
997 | /* reply */ | ||
998 | u16 reply_sz; | ||
999 | u8 *reply; | ||
1000 | dma_addr_t reply_dma; | ||
1001 | u32 reply_dma_max_address; | ||
1002 | u32 reply_dma_min_address; | ||
1003 | struct dma_pool *reply_dma_pool; | ||
1004 | |||
1005 | /* reply free queue */ | ||
1006 | u16 reply_free_queue_depth; | ||
1007 | __le32 *reply_free; | ||
1008 | dma_addr_t reply_free_dma; | ||
1009 | struct dma_pool *reply_free_dma_pool; | ||
1010 | u32 reply_free_host_index; | ||
1011 | |||
1012 | /* reply post queue */ | ||
1013 | u16 reply_post_queue_depth; | ||
1014 | struct reply_post_struct *reply_post; | ||
1015 | u8 rdpq_array_capable; | ||
1016 | u8 rdpq_array_enable; | ||
1017 | u8 rdpq_array_enable_assigned; | ||
1018 | struct dma_pool *reply_post_free_dma_pool; | ||
1019 | u8 reply_queue_count; | ||
1020 | struct list_head reply_queue_list; | ||
1021 | |||
1022 | struct list_head delayed_tr_list; | ||
1023 | struct list_head delayed_tr_volume_list; | ||
1024 | u8 temp_sensors_count; | ||
1025 | |||
1026 | /* diag buffer support */ | ||
1027 | u8 *diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT]; | ||
1028 | u32 diag_buffer_sz[MPI2_DIAG_BUF_TYPE_COUNT]; | ||
1029 | dma_addr_t diag_buffer_dma[MPI2_DIAG_BUF_TYPE_COUNT]; | ||
1030 | u8 diag_buffer_status[MPI2_DIAG_BUF_TYPE_COUNT]; | ||
1031 | u32 unique_id[MPI2_DIAG_BUF_TYPE_COUNT]; | ||
1032 | Mpi2ManufacturingPage10_t manu_pg10; | ||
1033 | u32 product_specific[MPI2_DIAG_BUF_TYPE_COUNT][23]; | ||
1034 | u32 diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT]; | ||
1035 | u32 ring_buffer_offset; | ||
1036 | u32 ring_buffer_sz; | ||
1037 | u8 is_warpdrive; | ||
1038 | u8 hide_ir_msg; | ||
1039 | u8 mfg_pg10_hide_flag; | ||
1040 | u8 hide_drives; | ||
1041 | |||
1042 | struct mutex pci_access_mutex; | ||
1043 | }; | ||
1044 | |||
1045 | typedef u8 (*MPT_CALLBACK)(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
1046 | u32 reply); | ||
1047 | |||
1048 | |||
1049 | /* base shared API */ | ||
1050 | extern struct list_head mpt2sas_ioc_list; | ||
1051 | /* spinlock on list operations over IOCs | ||
1052 | * Case: when multiple warpdrive cards(IOCs) are in use | ||
1053 | * Each IOC will added to the ioc list stucture on initialization. | ||
1054 | * Watchdog threads run at regular intervals to check IOC for any | ||
1055 | * fault conditions which will trigger the dead_ioc thread to | ||
1056 | * deallocate pci resource, resulting deleting the IOC netry from list, | ||
1057 | * this deletion need to protected by spinlock to enusre that | ||
1058 | * ioc removal is syncrhonized, if not synchronized it might lead to | ||
1059 | * list_del corruption as the ioc list is traversed in cli path | ||
1060 | */ | ||
1061 | extern spinlock_t gioc_lock; | ||
1062 | void mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc); | ||
1063 | void mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc); | ||
1064 | |||
1065 | int mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc); | ||
1066 | void mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc); | ||
1067 | int mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc); | ||
1068 | void mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc); | ||
1069 | int mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag, | ||
1070 | enum reset_type type); | ||
1071 | |||
1072 | void *mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid); | ||
1073 | void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid); | ||
1074 | void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr); | ||
1075 | __le32 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, | ||
1076 | u16 smid); | ||
1077 | void mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc); | ||
1078 | |||
1079 | /* hi-priority queue */ | ||
1080 | u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx); | ||
1081 | u16 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx, | ||
1082 | struct scsi_cmnd *scmd); | ||
1083 | |||
1084 | u16 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx); | ||
1085 | void mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid); | ||
1086 | void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
1087 | u16 handle); | ||
1088 | void mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid); | ||
1089 | void mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
1090 | u16 io_index); | ||
1091 | void mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid); | ||
1092 | void mpt2sas_base_initialize_callback_handler(void); | ||
1093 | u8 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func); | ||
1094 | void mpt2sas_base_release_callback_handler(u8 cb_idx); | ||
1095 | |||
1096 | u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
1097 | u32 reply); | ||
1098 | u8 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
1099 | u8 msix_index, u32 reply); | ||
1100 | void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr); | ||
1101 | |||
1102 | u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked); | ||
1103 | |||
1104 | void mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code); | ||
1105 | int mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc, | ||
1106 | Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t | ||
1107 | *mpi_request); | ||
1108 | int mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc, | ||
1109 | Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request); | ||
1110 | void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type); | ||
1111 | |||
1112 | void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc); | ||
1113 | |||
1114 | void mpt2sas_base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc, | ||
1115 | u16 device_missing_delay, u8 io_missing_delay); | ||
1116 | |||
1117 | int mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc); | ||
1118 | |||
1119 | /* scsih shared API */ | ||
1120 | void mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, | ||
1121 | u32 reply); | ||
1122 | int mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, | ||
1123 | uint channel, uint id, uint lun, u8 type, u16 smid_task, | ||
1124 | ulong timeout, enum mutex_type m_type); | ||
1125 | void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle); | ||
1126 | void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle); | ||
1127 | void mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address); | ||
1128 | void mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, | ||
1129 | u64 sas_address); | ||
1130 | struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, | ||
1131 | u16 handle); | ||
1132 | struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER | ||
1133 | *ioc, u64 sas_address); | ||
1134 | struct _sas_device *mpt2sas_get_sdev_by_addr( | ||
1135 | struct MPT2SAS_ADAPTER *ioc, u64 sas_address); | ||
1136 | struct _sas_device *__mpt2sas_get_sdev_by_addr( | ||
1137 | struct MPT2SAS_ADAPTER *ioc, u64 sas_address); | ||
1138 | |||
1139 | void mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc); | ||
1140 | void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase); | ||
1141 | |||
1142 | /* config shared API */ | ||
1143 | u8 mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
1144 | u32 reply); | ||
1145 | int mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys); | ||
1146 | int mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc, | ||
1147 | Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page); | ||
1148 | int mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc, | ||
1149 | Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page); | ||
1150 | int mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1151 | *mpi_reply, Mpi2BiosPage2_t *config_page); | ||
1152 | int mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1153 | *mpi_reply, Mpi2BiosPage3_t *config_page); | ||
1154 | int mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1155 | *mpi_reply, Mpi2IOUnitPage0_t *config_page); | ||
1156 | int mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1157 | *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle); | ||
1158 | int mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1159 | *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle); | ||
1160 | int mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1161 | *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz); | ||
1162 | int mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1163 | *mpi_reply, Mpi2IOUnitPage1_t *config_page); | ||
1164 | int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1165 | *mpi_reply, Mpi2IOUnitPage1_t *config_page); | ||
1166 | int mpt2sas_config_get_iounit_pg8(struct MPT2SAS_ADAPTER *ioc, | ||
1167 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage8_t *config_page); | ||
1168 | int mpt2sas_config_get_iounit_pg3(struct MPT2SAS_ADAPTER *ioc, | ||
1169 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz); | ||
1170 | int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1171 | *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz); | ||
1172 | int mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, | ||
1173 | Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz); | ||
1174 | int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1175 | *mpi_reply, Mpi2IOCPage8_t *config_page); | ||
1176 | int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1177 | *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle); | ||
1178 | int mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1179 | *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle); | ||
1180 | int mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1181 | *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle); | ||
1182 | int mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1183 | *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number); | ||
1184 | int mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1185 | *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number); | ||
1186 | int mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1187 | *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle); | ||
1188 | int mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 *num_pds); | ||
1189 | int mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1190 | *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz); | ||
1191 | int mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1192 | *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form, | ||
1193 | u32 form_specific); | ||
1194 | int mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle, | ||
1195 | u16 *volume_handle); | ||
1196 | int mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle, | ||
1197 | u64 *wwid); | ||
1198 | /* ctl shared API */ | ||
1199 | extern struct device_attribute *mpt2sas_host_attrs[]; | ||
1200 | extern struct device_attribute *mpt2sas_dev_attrs[]; | ||
1201 | void mpt2sas_ctl_init(void); | ||
1202 | void mpt2sas_ctl_exit(void); | ||
1203 | u8 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
1204 | u32 reply); | ||
1205 | void mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase); | ||
1206 | void mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, | ||
1207 | u32 reply); | ||
1208 | void mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc, | ||
1209 | Mpi2EventNotificationReply_t *mpi_reply); | ||
1210 | |||
1211 | void mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc, | ||
1212 | u8 bits_to_regsiter); | ||
1213 | |||
1214 | /* transport shared API */ | ||
1215 | u8 mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
1216 | u32 reply); | ||
1217 | struct _sas_port *mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, | ||
1218 | u16 handle, u64 sas_address); | ||
1219 | void mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, | ||
1220 | u64 sas_address_parent); | ||
1221 | int mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy | ||
1222 | *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev); | ||
1223 | int mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy | ||
1224 | *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev); | ||
1225 | void mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc, | ||
1226 | u64 sas_address, u16 handle, u8 phy_number, u8 link_rate); | ||
1227 | extern struct sas_function_template mpt2sas_transport_functions; | ||
1228 | extern struct scsi_transport_template *mpt2sas_transport_template; | ||
1229 | extern int scsi_internal_device_block(struct scsi_device *sdev); | ||
1230 | extern u8 mpt2sas_stm_zero_smid_handler(struct MPT2SAS_ADAPTER *ioc, | ||
1231 | u8 msix_index, u32 reply); | ||
1232 | extern int scsi_internal_device_unblock(struct scsi_device *sdev, | ||
1233 | enum scsi_device_state new_state); | ||
1234 | |||
1235 | #endif /* MPT2SAS_BASE_H_INCLUDED */ | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_config.c b/drivers/scsi/mpt2sas/mpt2sas_config.c deleted file mode 100644 index c43815b1a485..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_config.c +++ /dev/null | |||
@@ -1,1527 +0,0 @@ | |||
1 | /* | ||
2 | * This module provides common API for accessing firmware configuration pages | ||
3 | * | ||
4 | * This code is based on drivers/scsi/mpt2sas/mpt2_base.c | ||
5 | * Copyright (C) 2007-2014 LSI Corporation | ||
6 | * Copyright (C) 20013-2014 Avago Technologies | ||
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version 2 | ||
12 | * of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * NO WARRANTY | ||
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
24 | * solely responsible for determining the appropriateness of using and | ||
25 | * distributing the Program and assumes all risks associated with its | ||
26 | * exercise of rights under this Agreement, including but not limited to | ||
27 | * the risks and costs of program errors, damage to or loss of data, | ||
28 | * programs or equipment, and unavailability or interruption of operations. | ||
29 | |||
30 | * DISCLAIMER OF LIABILITY | ||
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
38 | |||
39 | * You should have received a copy of the GNU General Public License | ||
40 | * along with this program; if not, write to the Free Software | ||
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
42 | * USA. | ||
43 | */ | ||
44 | |||
45 | #include <linux/module.h> | ||
46 | #include <linux/kernel.h> | ||
47 | #include <linux/init.h> | ||
48 | #include <linux/errno.h> | ||
49 | #include <linux/blkdev.h> | ||
50 | #include <linux/sched.h> | ||
51 | #include <linux/workqueue.h> | ||
52 | #include <linux/delay.h> | ||
53 | #include <linux/pci.h> | ||
54 | #include <linux/slab.h> | ||
55 | |||
56 | #include "mpt2sas_base.h" | ||
57 | |||
58 | /* local definitions */ | ||
59 | |||
60 | /* Timeout for config page request (in seconds) */ | ||
61 | #define MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT 15 | ||
62 | |||
63 | /* Common sgl flags for READING a config page. */ | ||
64 | #define MPT2_CONFIG_COMMON_SGLFLAGS ((MPI2_SGE_FLAGS_SIMPLE_ELEMENT | \ | ||
65 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER \ | ||
66 | | MPI2_SGE_FLAGS_END_OF_LIST) << MPI2_SGE_FLAGS_SHIFT) | ||
67 | |||
68 | /* Common sgl flags for WRITING a config page. */ | ||
69 | #define MPT2_CONFIG_COMMON_WRITE_SGLFLAGS ((MPI2_SGE_FLAGS_SIMPLE_ELEMENT | \ | ||
70 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER \ | ||
71 | | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC) \ | ||
72 | << MPI2_SGE_FLAGS_SHIFT) | ||
73 | |||
74 | /** | ||
75 | * struct config_request - obtain dma memory via routine | ||
76 | * @sz: size | ||
77 | * @page: virt pointer | ||
78 | * @page_dma: phys pointer | ||
79 | * | ||
80 | */ | ||
81 | struct config_request{ | ||
82 | u16 sz; | ||
83 | void *page; | ||
84 | dma_addr_t page_dma; | ||
85 | }; | ||
86 | |||
87 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
88 | /** | ||
89 | * _config_display_some_debug - debug routine | ||
90 | * @ioc: per adapter object | ||
91 | * @smid: system request message index | ||
92 | * @calling_function_name: string pass from calling function | ||
93 | * @mpi_reply: reply message frame | ||
94 | * Context: none. | ||
95 | * | ||
96 | * Function for displaying debug info helpful when debugging issues | ||
97 | * in this module. | ||
98 | */ | ||
99 | static void | ||
100 | _config_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
101 | char *calling_function_name, MPI2DefaultReply_t *mpi_reply) | ||
102 | { | ||
103 | Mpi2ConfigRequest_t *mpi_request; | ||
104 | char *desc = NULL; | ||
105 | |||
106 | if (!(ioc->logging_level & MPT_DEBUG_CONFIG)) | ||
107 | return; | ||
108 | |||
109 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
110 | switch (mpi_request->Header.PageType & MPI2_CONFIG_PAGETYPE_MASK) { | ||
111 | case MPI2_CONFIG_PAGETYPE_IO_UNIT: | ||
112 | desc = "io_unit"; | ||
113 | break; | ||
114 | case MPI2_CONFIG_PAGETYPE_IOC: | ||
115 | desc = "ioc"; | ||
116 | break; | ||
117 | case MPI2_CONFIG_PAGETYPE_BIOS: | ||
118 | desc = "bios"; | ||
119 | break; | ||
120 | case MPI2_CONFIG_PAGETYPE_RAID_VOLUME: | ||
121 | desc = "raid_volume"; | ||
122 | break; | ||
123 | case MPI2_CONFIG_PAGETYPE_MANUFACTURING: | ||
124 | desc = "manufaucturing"; | ||
125 | break; | ||
126 | case MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK: | ||
127 | desc = "physdisk"; | ||
128 | break; | ||
129 | case MPI2_CONFIG_PAGETYPE_EXTENDED: | ||
130 | switch (mpi_request->ExtPageType) { | ||
131 | case MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT: | ||
132 | desc = "sas_io_unit"; | ||
133 | break; | ||
134 | case MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER: | ||
135 | desc = "sas_expander"; | ||
136 | break; | ||
137 | case MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE: | ||
138 | desc = "sas_device"; | ||
139 | break; | ||
140 | case MPI2_CONFIG_EXTPAGETYPE_SAS_PHY: | ||
141 | desc = "sas_phy"; | ||
142 | break; | ||
143 | case MPI2_CONFIG_EXTPAGETYPE_LOG: | ||
144 | desc = "log"; | ||
145 | break; | ||
146 | case MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE: | ||
147 | desc = "enclosure"; | ||
148 | break; | ||
149 | case MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG: | ||
150 | desc = "raid_config"; | ||
151 | break; | ||
152 | case MPI2_CONFIG_EXTPAGETYPE_DRIVER_MAPPING: | ||
153 | desc = "driver_mapping"; | ||
154 | break; | ||
155 | } | ||
156 | break; | ||
157 | } | ||
158 | |||
159 | if (!desc) | ||
160 | return; | ||
161 | |||
162 | printk(MPT2SAS_INFO_FMT "%s: %s(%d), action(%d), form(0x%08x), " | ||
163 | "smid(%d)\n", ioc->name, calling_function_name, desc, | ||
164 | mpi_request->Header.PageNumber, mpi_request->Action, | ||
165 | le32_to_cpu(mpi_request->PageAddress), smid); | ||
166 | |||
167 | if (!mpi_reply) | ||
168 | return; | ||
169 | |||
170 | if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo) | ||
171 | printk(MPT2SAS_INFO_FMT | ||
172 | "\tiocstatus(0x%04x), loginfo(0x%08x)\n", | ||
173 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | ||
174 | le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
175 | } | ||
176 | #endif | ||
177 | |||
178 | /** | ||
179 | * _config_alloc_config_dma_memory - obtain physical memory | ||
180 | * @ioc: per adapter object | ||
181 | * @mem: struct config_request | ||
182 | * | ||
183 | * A wrapper for obtaining dma-able memory for config page request. | ||
184 | * | ||
185 | * Returns 0 for success, non-zero for failure. | ||
186 | */ | ||
187 | static int | ||
188 | _config_alloc_config_dma_memory(struct MPT2SAS_ADAPTER *ioc, | ||
189 | struct config_request *mem) | ||
190 | { | ||
191 | int r = 0; | ||
192 | |||
193 | if (mem->sz > ioc->config_page_sz) { | ||
194 | mem->page = dma_alloc_coherent(&ioc->pdev->dev, mem->sz, | ||
195 | &mem->page_dma, GFP_KERNEL); | ||
196 | if (!mem->page) { | ||
197 | printk(MPT2SAS_ERR_FMT "%s: dma_alloc_coherent" | ||
198 | " failed asking for (%d) bytes!!\n", | ||
199 | ioc->name, __func__, mem->sz); | ||
200 | r = -ENOMEM; | ||
201 | } | ||
202 | } else { /* use tmp buffer if less than 512 bytes */ | ||
203 | mem->page = ioc->config_page; | ||
204 | mem->page_dma = ioc->config_page_dma; | ||
205 | } | ||
206 | return r; | ||
207 | } | ||
208 | |||
209 | /** | ||
210 | * _config_free_config_dma_memory - wrapper to free the memory | ||
211 | * @ioc: per adapter object | ||
212 | * @mem: struct config_request | ||
213 | * | ||
214 | * A wrapper to free dma-able memory when using _config_alloc_config_dma_memory. | ||
215 | * | ||
216 | * Returns 0 for success, non-zero for failure. | ||
217 | */ | ||
218 | static void | ||
219 | _config_free_config_dma_memory(struct MPT2SAS_ADAPTER *ioc, | ||
220 | struct config_request *mem) | ||
221 | { | ||
222 | if (mem->sz > ioc->config_page_sz) | ||
223 | dma_free_coherent(&ioc->pdev->dev, mem->sz, mem->page, | ||
224 | mem->page_dma); | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * mpt2sas_config_done - config page completion routine | ||
229 | * @ioc: per adapter object | ||
230 | * @smid: system request message index | ||
231 | * @msix_index: MSIX table index supplied by the OS | ||
232 | * @reply: reply message frame(lower 32bit addr) | ||
233 | * Context: none. | ||
234 | * | ||
235 | * The callback handler when using _config_request. | ||
236 | * | ||
237 | * Return 1 meaning mf should be freed from _base_interrupt | ||
238 | * 0 means the mf is freed from this function. | ||
239 | */ | ||
240 | u8 | ||
241 | mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
242 | u32 reply) | ||
243 | { | ||
244 | MPI2DefaultReply_t *mpi_reply; | ||
245 | |||
246 | if (ioc->config_cmds.status == MPT2_CMD_NOT_USED) | ||
247 | return 1; | ||
248 | if (ioc->config_cmds.smid != smid) | ||
249 | return 1; | ||
250 | ioc->config_cmds.status |= MPT2_CMD_COMPLETE; | ||
251 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
252 | if (mpi_reply) { | ||
253 | ioc->config_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
254 | memcpy(ioc->config_cmds.reply, mpi_reply, | ||
255 | mpi_reply->MsgLength*4); | ||
256 | } | ||
257 | ioc->config_cmds.status &= ~MPT2_CMD_PENDING; | ||
258 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
259 | _config_display_some_debug(ioc, smid, "config_done", mpi_reply); | ||
260 | #endif | ||
261 | ioc->config_cmds.smid = USHRT_MAX; | ||
262 | complete(&ioc->config_cmds.done); | ||
263 | return 1; | ||
264 | } | ||
265 | |||
266 | /** | ||
267 | * _config_request - main routine for sending config page requests | ||
268 | * @ioc: per adapter object | ||
269 | * @mpi_request: request message frame | ||
270 | * @mpi_reply: reply mf payload returned from firmware | ||
271 | * @timeout: timeout in seconds | ||
272 | * @config_page: contents of the config page | ||
273 | * @config_page_sz: size of config page | ||
274 | * Context: sleep | ||
275 | * | ||
276 | * A generic API for config page requests to firmware. | ||
277 | * | ||
278 | * The ioc->config_cmds.status flag should be MPT2_CMD_NOT_USED before calling | ||
279 | * this API. | ||
280 | * | ||
281 | * The callback index is set inside `ioc->config_cb_idx. | ||
282 | * | ||
283 | * Returns 0 for success, non-zero for failure. | ||
284 | */ | ||
285 | static int | ||
286 | _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t | ||
287 | *mpi_request, Mpi2ConfigReply_t *mpi_reply, int timeout, | ||
288 | void *config_page, u16 config_page_sz) | ||
289 | { | ||
290 | u16 smid; | ||
291 | u32 ioc_state; | ||
292 | unsigned long timeleft; | ||
293 | Mpi2ConfigRequest_t *config_request; | ||
294 | int r; | ||
295 | u8 retry_count, issue_host_reset = 0; | ||
296 | u16 wait_state_count; | ||
297 | struct config_request mem; | ||
298 | |||
299 | mutex_lock(&ioc->config_cmds.mutex); | ||
300 | if (ioc->config_cmds.status != MPT2_CMD_NOT_USED) { | ||
301 | printk(MPT2SAS_ERR_FMT "%s: config_cmd in use\n", | ||
302 | ioc->name, __func__); | ||
303 | mutex_unlock(&ioc->config_cmds.mutex); | ||
304 | return -EAGAIN; | ||
305 | } | ||
306 | |||
307 | retry_count = 0; | ||
308 | memset(&mem, 0, sizeof(struct config_request)); | ||
309 | |||
310 | mpi_request->VF_ID = 0; /* TODO */ | ||
311 | mpi_request->VP_ID = 0; | ||
312 | |||
313 | if (config_page) { | ||
314 | mpi_request->Header.PageVersion = mpi_reply->Header.PageVersion; | ||
315 | mpi_request->Header.PageNumber = mpi_reply->Header.PageNumber; | ||
316 | mpi_request->Header.PageType = mpi_reply->Header.PageType; | ||
317 | mpi_request->Header.PageLength = mpi_reply->Header.PageLength; | ||
318 | mpi_request->ExtPageLength = mpi_reply->ExtPageLength; | ||
319 | mpi_request->ExtPageType = mpi_reply->ExtPageType; | ||
320 | if (mpi_request->Header.PageLength) | ||
321 | mem.sz = mpi_request->Header.PageLength * 4; | ||
322 | else | ||
323 | mem.sz = le16_to_cpu(mpi_reply->ExtPageLength) * 4; | ||
324 | r = _config_alloc_config_dma_memory(ioc, &mem); | ||
325 | if (r != 0) | ||
326 | goto out; | ||
327 | if (mpi_request->Action == | ||
328 | MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT || | ||
329 | mpi_request->Action == | ||
330 | MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM) { | ||
331 | ioc->base_add_sg_single(&mpi_request->PageBufferSGE, | ||
332 | MPT2_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz, | ||
333 | mem.page_dma); | ||
334 | memcpy(mem.page, config_page, min_t(u16, mem.sz, | ||
335 | config_page_sz)); | ||
336 | } else { | ||
337 | memset(config_page, 0, config_page_sz); | ||
338 | ioc->base_add_sg_single(&mpi_request->PageBufferSGE, | ||
339 | MPT2_CONFIG_COMMON_SGLFLAGS | mem.sz, mem.page_dma); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | retry_config: | ||
344 | if (retry_count) { | ||
345 | if (retry_count > 2) { /* attempt only 2 retries */ | ||
346 | r = -EFAULT; | ||
347 | goto free_mem; | ||
348 | } | ||
349 | printk(MPT2SAS_INFO_FMT "%s: attempting retry (%d)\n", | ||
350 | ioc->name, __func__, retry_count); | ||
351 | } | ||
352 | wait_state_count = 0; | ||
353 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
354 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
355 | if (wait_state_count++ == MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT) { | ||
356 | printk(MPT2SAS_ERR_FMT | ||
357 | "%s: failed due to ioc not operational\n", | ||
358 | ioc->name, __func__); | ||
359 | ioc->config_cmds.status = MPT2_CMD_NOT_USED; | ||
360 | r = -EFAULT; | ||
361 | goto free_mem; | ||
362 | } | ||
363 | ssleep(1); | ||
364 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
365 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
366 | "operational state(count=%d)\n", ioc->name, | ||
367 | __func__, wait_state_count); | ||
368 | } | ||
369 | if (wait_state_count) | ||
370 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", | ||
371 | ioc->name, __func__); | ||
372 | |||
373 | smid = mpt2sas_base_get_smid(ioc, ioc->config_cb_idx); | ||
374 | if (!smid) { | ||
375 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
376 | ioc->name, __func__); | ||
377 | ioc->config_cmds.status = MPT2_CMD_NOT_USED; | ||
378 | r = -EAGAIN; | ||
379 | goto free_mem; | ||
380 | } | ||
381 | |||
382 | r = 0; | ||
383 | memset(mpi_reply, 0, sizeof(Mpi2ConfigReply_t)); | ||
384 | ioc->config_cmds.status = MPT2_CMD_PENDING; | ||
385 | config_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
386 | ioc->config_cmds.smid = smid; | ||
387 | memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t)); | ||
388 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
389 | _config_display_some_debug(ioc, smid, "config_request", NULL); | ||
390 | #endif | ||
391 | init_completion(&ioc->config_cmds.done); | ||
392 | mpt2sas_base_put_smid_default(ioc, smid); | ||
393 | timeleft = wait_for_completion_timeout(&ioc->config_cmds.done, | ||
394 | timeout*HZ); | ||
395 | if (!(ioc->config_cmds.status & MPT2_CMD_COMPLETE)) { | ||
396 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
397 | ioc->name, __func__); | ||
398 | _debug_dump_mf(mpi_request, | ||
399 | sizeof(Mpi2ConfigRequest_t)/4); | ||
400 | retry_count++; | ||
401 | if (ioc->config_cmds.smid == smid) | ||
402 | mpt2sas_base_free_smid(ioc, smid); | ||
403 | if ((ioc->shost_recovery) || (ioc->config_cmds.status & | ||
404 | MPT2_CMD_RESET) || ioc->pci_error_recovery) | ||
405 | goto retry_config; | ||
406 | issue_host_reset = 1; | ||
407 | r = -EFAULT; | ||
408 | goto free_mem; | ||
409 | } | ||
410 | |||
411 | if (ioc->config_cmds.status & MPT2_CMD_REPLY_VALID) | ||
412 | memcpy(mpi_reply, ioc->config_cmds.reply, | ||
413 | sizeof(Mpi2ConfigReply_t)); | ||
414 | if (retry_count) | ||
415 | printk(MPT2SAS_INFO_FMT "%s: retry (%d) completed!!\n", | ||
416 | ioc->name, __func__, retry_count); | ||
417 | if (config_page && mpi_request->Action == | ||
418 | MPI2_CONFIG_ACTION_PAGE_READ_CURRENT) | ||
419 | memcpy(config_page, mem.page, min_t(u16, mem.sz, | ||
420 | config_page_sz)); | ||
421 | free_mem: | ||
422 | if (config_page) | ||
423 | _config_free_config_dma_memory(ioc, &mem); | ||
424 | out: | ||
425 | ioc->config_cmds.status = MPT2_CMD_NOT_USED; | ||
426 | mutex_unlock(&ioc->config_cmds.mutex); | ||
427 | |||
428 | if (issue_host_reset) | ||
429 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
430 | FORCE_BIG_HAMMER); | ||
431 | return r; | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * mpt2sas_config_get_manufacturing_pg0 - obtain manufacturing page 0 | ||
436 | * @ioc: per adapter object | ||
437 | * @mpi_reply: reply mf payload returned from firmware | ||
438 | * @config_page: contents of the config page | ||
439 | * Context: sleep. | ||
440 | * | ||
441 | * Returns 0 for success, non-zero for failure. | ||
442 | */ | ||
443 | int | ||
444 | mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc, | ||
445 | Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page) | ||
446 | { | ||
447 | Mpi2ConfigRequest_t mpi_request; | ||
448 | int r; | ||
449 | |||
450 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
451 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
452 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
453 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; | ||
454 | mpi_request.Header.PageNumber = 0; | ||
455 | mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; | ||
456 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
457 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
458 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
459 | if (r) | ||
460 | goto out; | ||
461 | |||
462 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
463 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
464 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
465 | sizeof(*config_page)); | ||
466 | out: | ||
467 | return r; | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * mpt2sas_config_get_manufacturing_pg10 - obtain manufacturing page 10 | ||
472 | * @ioc: per adapter object | ||
473 | * @mpi_reply: reply mf payload returned from firmware | ||
474 | * @config_page: contents of the config page | ||
475 | * Context: sleep. | ||
476 | * | ||
477 | * Returns 0 for success, non-zero for failure. | ||
478 | */ | ||
479 | int | ||
480 | mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc, | ||
481 | Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page) | ||
482 | { | ||
483 | Mpi2ConfigRequest_t mpi_request; | ||
484 | int r; | ||
485 | |||
486 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
487 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
488 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
489 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_MANUFACTURING; | ||
490 | mpi_request.Header.PageNumber = 10; | ||
491 | mpi_request.Header.PageVersion = MPI2_MANUFACTURING0_PAGEVERSION; | ||
492 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
493 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
494 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
495 | if (r) | ||
496 | goto out; | ||
497 | |||
498 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
499 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
500 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
501 | sizeof(*config_page)); | ||
502 | out: | ||
503 | return r; | ||
504 | } | ||
505 | |||
506 | /** | ||
507 | * mpt2sas_config_get_bios_pg2 - obtain bios page 2 | ||
508 | * @ioc: per adapter object | ||
509 | * @mpi_reply: reply mf payload returned from firmware | ||
510 | * @config_page: contents of the config page | ||
511 | * Context: sleep. | ||
512 | * | ||
513 | * Returns 0 for success, non-zero for failure. | ||
514 | */ | ||
515 | int | ||
516 | mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, | ||
517 | Mpi2ConfigReply_t *mpi_reply, Mpi2BiosPage2_t *config_page) | ||
518 | { | ||
519 | Mpi2ConfigRequest_t mpi_request; | ||
520 | int r; | ||
521 | |||
522 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
523 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
524 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
525 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS; | ||
526 | mpi_request.Header.PageNumber = 2; | ||
527 | mpi_request.Header.PageVersion = MPI2_BIOSPAGE2_PAGEVERSION; | ||
528 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
529 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
530 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
531 | if (r) | ||
532 | goto out; | ||
533 | |||
534 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
535 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
536 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
537 | sizeof(*config_page)); | ||
538 | out: | ||
539 | return r; | ||
540 | } | ||
541 | |||
542 | /** | ||
543 | * mpt2sas_config_get_bios_pg3 - obtain bios page 3 | ||
544 | * @ioc: per adapter object | ||
545 | * @mpi_reply: reply mf payload returned from firmware | ||
546 | * @config_page: contents of the config page | ||
547 | * Context: sleep. | ||
548 | * | ||
549 | * Returns 0 for success, non-zero for failure. | ||
550 | */ | ||
551 | int | ||
552 | mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
553 | *mpi_reply, Mpi2BiosPage3_t *config_page) | ||
554 | { | ||
555 | Mpi2ConfigRequest_t mpi_request; | ||
556 | int r; | ||
557 | |||
558 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
559 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
560 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
561 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_BIOS; | ||
562 | mpi_request.Header.PageNumber = 3; | ||
563 | mpi_request.Header.PageVersion = MPI2_BIOSPAGE3_PAGEVERSION; | ||
564 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
565 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
566 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
567 | if (r) | ||
568 | goto out; | ||
569 | |||
570 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
571 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
572 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
573 | sizeof(*config_page)); | ||
574 | out: | ||
575 | return r; | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * mpt2sas_config_get_iounit_pg0 - obtain iounit page 0 | ||
580 | * @ioc: per adapter object | ||
581 | * @mpi_reply: reply mf payload returned from firmware | ||
582 | * @config_page: contents of the config page | ||
583 | * Context: sleep. | ||
584 | * | ||
585 | * Returns 0 for success, non-zero for failure. | ||
586 | */ | ||
587 | int | ||
588 | mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, | ||
589 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage0_t *config_page) | ||
590 | { | ||
591 | Mpi2ConfigRequest_t mpi_request; | ||
592 | int r; | ||
593 | |||
594 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
595 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
596 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
597 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; | ||
598 | mpi_request.Header.PageNumber = 0; | ||
599 | mpi_request.Header.PageVersion = MPI2_IOUNITPAGE0_PAGEVERSION; | ||
600 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
601 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
602 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
603 | if (r) | ||
604 | goto out; | ||
605 | |||
606 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
607 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
608 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
609 | sizeof(*config_page)); | ||
610 | out: | ||
611 | return r; | ||
612 | } | ||
613 | |||
614 | /** | ||
615 | * mpt2sas_config_get_iounit_pg1 - obtain iounit page 1 | ||
616 | * @ioc: per adapter object | ||
617 | * @mpi_reply: reply mf payload returned from firmware | ||
618 | * @config_page: contents of the config page | ||
619 | * Context: sleep. | ||
620 | * | ||
621 | * Returns 0 for success, non-zero for failure. | ||
622 | */ | ||
623 | int | ||
624 | mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, | ||
625 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page) | ||
626 | { | ||
627 | Mpi2ConfigRequest_t mpi_request; | ||
628 | int r; | ||
629 | |||
630 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
631 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
632 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
633 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; | ||
634 | mpi_request.Header.PageNumber = 1; | ||
635 | mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION; | ||
636 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
637 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
638 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
639 | if (r) | ||
640 | goto out; | ||
641 | |||
642 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
643 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
644 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
645 | sizeof(*config_page)); | ||
646 | out: | ||
647 | return r; | ||
648 | } | ||
649 | |||
650 | /** | ||
651 | * mpt2sas_config_set_iounit_pg1 - set iounit page 1 | ||
652 | * @ioc: per adapter object | ||
653 | * @mpi_reply: reply mf payload returned from firmware | ||
654 | * @config_page: contents of the config page | ||
655 | * Context: sleep. | ||
656 | * | ||
657 | * Returns 0 for success, non-zero for failure. | ||
658 | */ | ||
659 | int | ||
660 | mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, | ||
661 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage1_t *config_page) | ||
662 | { | ||
663 | Mpi2ConfigRequest_t mpi_request; | ||
664 | int r; | ||
665 | |||
666 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
667 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
668 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
669 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; | ||
670 | mpi_request.Header.PageNumber = 1; | ||
671 | mpi_request.Header.PageVersion = MPI2_IOUNITPAGE1_PAGEVERSION; | ||
672 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
673 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
674 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
675 | if (r) | ||
676 | goto out; | ||
677 | |||
678 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; | ||
679 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
680 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
681 | sizeof(*config_page)); | ||
682 | out: | ||
683 | return r; | ||
684 | } | ||
685 | |||
686 | /** | ||
687 | * mpt2sas_config_get_iounit_pg3 - obtain iounit page 3 | ||
688 | * @ioc: per adapter object | ||
689 | * @mpi_reply: reply mf payload returned from firmware | ||
690 | * @config_page: contents of the config page | ||
691 | * @sz: size of buffer passed in config_page | ||
692 | * Context: sleep. | ||
693 | * | ||
694 | * Returns 0 for success, non-zero for failure. | ||
695 | */ | ||
696 | int | ||
697 | mpt2sas_config_get_iounit_pg3(struct MPT2SAS_ADAPTER *ioc, | ||
698 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz) | ||
699 | { | ||
700 | Mpi2ConfigRequest_t mpi_request; | ||
701 | int r; | ||
702 | |||
703 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
704 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
705 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
706 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; | ||
707 | mpi_request.Header.PageNumber = 3; | ||
708 | mpi_request.Header.PageVersion = MPI2_IOUNITPAGE3_PAGEVERSION; | ||
709 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
710 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
711 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
712 | if (r) | ||
713 | goto out; | ||
714 | |||
715 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
716 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
717 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); | ||
718 | out: | ||
719 | return r; | ||
720 | } | ||
721 | |||
722 | /** | ||
723 | * mpt2sas_config_get_iounit_pg8 - obtain iounit page 8 | ||
724 | * @ioc: per adapter object | ||
725 | * @mpi_reply: reply mf payload returned from firmware | ||
726 | * @config_page: contents of the config page | ||
727 | * Context: sleep. | ||
728 | * | ||
729 | * Returns 0 for success, non-zero for failure. | ||
730 | */ | ||
731 | int | ||
732 | mpt2sas_config_get_iounit_pg8(struct MPT2SAS_ADAPTER *ioc, | ||
733 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage8_t *config_page) | ||
734 | { | ||
735 | Mpi2ConfigRequest_t mpi_request; | ||
736 | int r; | ||
737 | |||
738 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
739 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
740 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
741 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IO_UNIT; | ||
742 | mpi_request.Header.PageNumber = 8; | ||
743 | mpi_request.Header.PageVersion = MPI2_IOUNITPAGE8_PAGEVERSION; | ||
744 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
745 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
746 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
747 | if (r) | ||
748 | goto out; | ||
749 | |||
750 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
751 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
752 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
753 | sizeof(*config_page)); | ||
754 | out: | ||
755 | return r; | ||
756 | } | ||
757 | |||
758 | /** | ||
759 | * mpt2sas_config_get_ioc_pg8 - obtain ioc page 8 | ||
760 | * @ioc: per adapter object | ||
761 | * @mpi_reply: reply mf payload returned from firmware | ||
762 | * @config_page: contents of the config page | ||
763 | * Context: sleep. | ||
764 | * | ||
765 | * Returns 0 for success, non-zero for failure. | ||
766 | */ | ||
767 | int | ||
768 | mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, | ||
769 | Mpi2ConfigReply_t *mpi_reply, Mpi2IOCPage8_t *config_page) | ||
770 | { | ||
771 | Mpi2ConfigRequest_t mpi_request; | ||
772 | int r; | ||
773 | |||
774 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
775 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
776 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
777 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IOC; | ||
778 | mpi_request.Header.PageNumber = 8; | ||
779 | mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION; | ||
780 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
781 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
782 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
783 | if (r) | ||
784 | goto out; | ||
785 | |||
786 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
787 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
788 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
789 | sizeof(*config_page)); | ||
790 | out: | ||
791 | return r; | ||
792 | } | ||
793 | |||
794 | /** | ||
795 | * mpt2sas_config_get_sas_device_pg0 - obtain sas device page 0 | ||
796 | * @ioc: per adapter object | ||
797 | * @mpi_reply: reply mf payload returned from firmware | ||
798 | * @config_page: contents of the config page | ||
799 | * @form: GET_NEXT_HANDLE or HANDLE | ||
800 | * @handle: device handle | ||
801 | * Context: sleep. | ||
802 | * | ||
803 | * Returns 0 for success, non-zero for failure. | ||
804 | */ | ||
805 | int | ||
806 | mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
807 | *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle) | ||
808 | { | ||
809 | Mpi2ConfigRequest_t mpi_request; | ||
810 | int r; | ||
811 | |||
812 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
813 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
814 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
815 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
816 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE; | ||
817 | mpi_request.Header.PageVersion = MPI2_SASDEVICE0_PAGEVERSION; | ||
818 | mpi_request.Header.PageNumber = 0; | ||
819 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
820 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
821 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
822 | if (r) | ||
823 | goto out; | ||
824 | |||
825 | mpi_request.PageAddress = cpu_to_le32(form | handle); | ||
826 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
827 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
828 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
829 | sizeof(*config_page)); | ||
830 | out: | ||
831 | return r; | ||
832 | } | ||
833 | |||
834 | /** | ||
835 | * mpt2sas_config_get_sas_device_pg1 - obtain sas device page 1 | ||
836 | * @ioc: per adapter object | ||
837 | * @mpi_reply: reply mf payload returned from firmware | ||
838 | * @config_page: contents of the config page | ||
839 | * @form: GET_NEXT_HANDLE or HANDLE | ||
840 | * @handle: device handle | ||
841 | * Context: sleep. | ||
842 | * | ||
843 | * Returns 0 for success, non-zero for failure. | ||
844 | */ | ||
845 | int | ||
846 | mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
847 | *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle) | ||
848 | { | ||
849 | Mpi2ConfigRequest_t mpi_request; | ||
850 | int r; | ||
851 | |||
852 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
853 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
854 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
855 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
856 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE; | ||
857 | mpi_request.Header.PageVersion = MPI2_SASDEVICE1_PAGEVERSION; | ||
858 | mpi_request.Header.PageNumber = 1; | ||
859 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
860 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
861 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
862 | if (r) | ||
863 | goto out; | ||
864 | |||
865 | mpi_request.PageAddress = cpu_to_le32(form | handle); | ||
866 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
867 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
868 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
869 | sizeof(*config_page)); | ||
870 | out: | ||
871 | return r; | ||
872 | } | ||
873 | |||
874 | /** | ||
875 | * mpt2sas_config_get_number_hba_phys - obtain number of phys on the host | ||
876 | * @ioc: per adapter object | ||
877 | * @num_phys: pointer returned with the number of phys | ||
878 | * Context: sleep. | ||
879 | * | ||
880 | * Returns 0 for success, non-zero for failure. | ||
881 | */ | ||
882 | int | ||
883 | mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys) | ||
884 | { | ||
885 | Mpi2ConfigRequest_t mpi_request; | ||
886 | int r; | ||
887 | u16 ioc_status; | ||
888 | Mpi2ConfigReply_t mpi_reply; | ||
889 | Mpi2SasIOUnitPage0_t config_page; | ||
890 | |||
891 | *num_phys = 0; | ||
892 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
893 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
894 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
895 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
896 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; | ||
897 | mpi_request.Header.PageNumber = 0; | ||
898 | mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; | ||
899 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
900 | r = _config_request(ioc, &mpi_request, &mpi_reply, | ||
901 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
902 | if (r) | ||
903 | goto out; | ||
904 | |||
905 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
906 | r = _config_request(ioc, &mpi_request, &mpi_reply, | ||
907 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page, | ||
908 | sizeof(Mpi2SasIOUnitPage0_t)); | ||
909 | if (!r) { | ||
910 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
911 | MPI2_IOCSTATUS_MASK; | ||
912 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) | ||
913 | *num_phys = config_page.NumPhys; | ||
914 | } | ||
915 | out: | ||
916 | return r; | ||
917 | } | ||
918 | |||
919 | /** | ||
920 | * mpt2sas_config_get_sas_iounit_pg0 - obtain sas iounit page 0 | ||
921 | * @ioc: per adapter object | ||
922 | * @mpi_reply: reply mf payload returned from firmware | ||
923 | * @config_page: contents of the config page | ||
924 | * @sz: size of buffer passed in config_page | ||
925 | * Context: sleep. | ||
926 | * | ||
927 | * Calling function should call config_get_number_hba_phys prior to | ||
928 | * this function, so enough memory is allocated for config_page. | ||
929 | * | ||
930 | * Returns 0 for success, non-zero for failure. | ||
931 | */ | ||
932 | int | ||
933 | mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
934 | *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz) | ||
935 | { | ||
936 | Mpi2ConfigRequest_t mpi_request; | ||
937 | int r; | ||
938 | |||
939 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
940 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
941 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
942 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
943 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; | ||
944 | mpi_request.Header.PageNumber = 0; | ||
945 | mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; | ||
946 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
947 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
948 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
949 | if (r) | ||
950 | goto out; | ||
951 | |||
952 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
953 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
954 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); | ||
955 | out: | ||
956 | return r; | ||
957 | } | ||
958 | |||
959 | /** | ||
960 | * mpt2sas_config_get_sas_iounit_pg1 - obtain sas iounit page 1 | ||
961 | * @ioc: per adapter object | ||
962 | * @mpi_reply: reply mf payload returned from firmware | ||
963 | * @config_page: contents of the config page | ||
964 | * @sz: size of buffer passed in config_page | ||
965 | * Context: sleep. | ||
966 | * | ||
967 | * Calling function should call config_get_number_hba_phys prior to | ||
968 | * this function, so enough memory is allocated for config_page. | ||
969 | * | ||
970 | * Returns 0 for success, non-zero for failure. | ||
971 | */ | ||
972 | int | ||
973 | mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
974 | *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz) | ||
975 | { | ||
976 | Mpi2ConfigRequest_t mpi_request; | ||
977 | int r; | ||
978 | |||
979 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
980 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
981 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
982 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
983 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; | ||
984 | mpi_request.Header.PageNumber = 1; | ||
985 | mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION; | ||
986 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
987 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
988 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
989 | if (r) | ||
990 | goto out; | ||
991 | |||
992 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
993 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
994 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); | ||
995 | out: | ||
996 | return r; | ||
997 | } | ||
998 | |||
999 | /** | ||
1000 | * mpt2sas_config_set_sas_iounit_pg1 - send sas iounit page 1 | ||
1001 | * @ioc: per adapter object | ||
1002 | * @mpi_reply: reply mf payload returned from firmware | ||
1003 | * @config_page: contents of the config page | ||
1004 | * @sz: size of buffer passed in config_page | ||
1005 | * Context: sleep. | ||
1006 | * | ||
1007 | * Calling function should call config_get_number_hba_phys prior to | ||
1008 | * this function, so enough memory is allocated for config_page. | ||
1009 | * | ||
1010 | * Returns 0 for success, non-zero for failure. | ||
1011 | */ | ||
1012 | int | ||
1013 | mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1014 | *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz) | ||
1015 | { | ||
1016 | Mpi2ConfigRequest_t mpi_request; | ||
1017 | int r; | ||
1018 | |||
1019 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1020 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1021 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1022 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1023 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; | ||
1024 | mpi_request.Header.PageNumber = 1; | ||
1025 | mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION; | ||
1026 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1027 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1028 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1029 | if (r) | ||
1030 | goto out; | ||
1031 | |||
1032 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; | ||
1033 | _config_request(ioc, &mpi_request, mpi_reply, | ||
1034 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); | ||
1035 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM; | ||
1036 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1037 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); | ||
1038 | out: | ||
1039 | return r; | ||
1040 | } | ||
1041 | |||
1042 | /** | ||
1043 | * mpt2sas_config_get_expander_pg0 - obtain expander page 0 | ||
1044 | * @ioc: per adapter object | ||
1045 | * @mpi_reply: reply mf payload returned from firmware | ||
1046 | * @config_page: contents of the config page | ||
1047 | * @form: GET_NEXT_HANDLE or HANDLE | ||
1048 | * @handle: expander handle | ||
1049 | * Context: sleep. | ||
1050 | * | ||
1051 | * Returns 0 for success, non-zero for failure. | ||
1052 | */ | ||
1053 | int | ||
1054 | mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1055 | *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle) | ||
1056 | { | ||
1057 | Mpi2ConfigRequest_t mpi_request; | ||
1058 | int r; | ||
1059 | |||
1060 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1061 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1062 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1063 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1064 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER; | ||
1065 | mpi_request.Header.PageNumber = 0; | ||
1066 | mpi_request.Header.PageVersion = MPI2_SASEXPANDER0_PAGEVERSION; | ||
1067 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1068 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1069 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1070 | if (r) | ||
1071 | goto out; | ||
1072 | |||
1073 | mpi_request.PageAddress = cpu_to_le32(form | handle); | ||
1074 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1075 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1076 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1077 | sizeof(*config_page)); | ||
1078 | out: | ||
1079 | return r; | ||
1080 | } | ||
1081 | |||
1082 | /** | ||
1083 | * mpt2sas_config_get_expander_pg1 - obtain expander page 1 | ||
1084 | * @ioc: per adapter object | ||
1085 | * @mpi_reply: reply mf payload returned from firmware | ||
1086 | * @config_page: contents of the config page | ||
1087 | * @phy_number: phy number | ||
1088 | * @handle: expander handle | ||
1089 | * Context: sleep. | ||
1090 | * | ||
1091 | * Returns 0 for success, non-zero for failure. | ||
1092 | */ | ||
1093 | int | ||
1094 | mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1095 | *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, | ||
1096 | u16 handle) | ||
1097 | { | ||
1098 | Mpi2ConfigRequest_t mpi_request; | ||
1099 | int r; | ||
1100 | |||
1101 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1102 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1103 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1104 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1105 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER; | ||
1106 | mpi_request.Header.PageNumber = 1; | ||
1107 | mpi_request.Header.PageVersion = MPI2_SASEXPANDER1_PAGEVERSION; | ||
1108 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1109 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1110 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1111 | if (r) | ||
1112 | goto out; | ||
1113 | |||
1114 | mpi_request.PageAddress = | ||
1115 | cpu_to_le32(MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM | | ||
1116 | (phy_number << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | handle); | ||
1117 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1118 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1119 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1120 | sizeof(*config_page)); | ||
1121 | out: | ||
1122 | return r; | ||
1123 | } | ||
1124 | |||
1125 | /** | ||
1126 | * mpt2sas_config_get_enclosure_pg0 - obtain enclosure page 0 | ||
1127 | * @ioc: per adapter object | ||
1128 | * @mpi_reply: reply mf payload returned from firmware | ||
1129 | * @config_page: contents of the config page | ||
1130 | * @form: GET_NEXT_HANDLE or HANDLE | ||
1131 | * @handle: expander handle | ||
1132 | * Context: sleep. | ||
1133 | * | ||
1134 | * Returns 0 for success, non-zero for failure. | ||
1135 | */ | ||
1136 | int | ||
1137 | mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1138 | *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle) | ||
1139 | { | ||
1140 | Mpi2ConfigRequest_t mpi_request; | ||
1141 | int r; | ||
1142 | |||
1143 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1144 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1145 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1146 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1147 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE; | ||
1148 | mpi_request.Header.PageNumber = 0; | ||
1149 | mpi_request.Header.PageVersion = MPI2_SASENCLOSURE0_PAGEVERSION; | ||
1150 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1151 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1152 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1153 | if (r) | ||
1154 | goto out; | ||
1155 | |||
1156 | mpi_request.PageAddress = cpu_to_le32(form | handle); | ||
1157 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1158 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1159 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1160 | sizeof(*config_page)); | ||
1161 | out: | ||
1162 | return r; | ||
1163 | } | ||
1164 | |||
1165 | /** | ||
1166 | * mpt2sas_config_get_phy_pg0 - obtain phy page 0 | ||
1167 | * @ioc: per adapter object | ||
1168 | * @mpi_reply: reply mf payload returned from firmware | ||
1169 | * @config_page: contents of the config page | ||
1170 | * @phy_number: phy number | ||
1171 | * Context: sleep. | ||
1172 | * | ||
1173 | * Returns 0 for success, non-zero for failure. | ||
1174 | */ | ||
1175 | int | ||
1176 | mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1177 | *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number) | ||
1178 | { | ||
1179 | Mpi2ConfigRequest_t mpi_request; | ||
1180 | int r; | ||
1181 | |||
1182 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1183 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1184 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1185 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1186 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY; | ||
1187 | mpi_request.Header.PageNumber = 0; | ||
1188 | mpi_request.Header.PageVersion = MPI2_SASPHY0_PAGEVERSION; | ||
1189 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1190 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1191 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1192 | if (r) | ||
1193 | goto out; | ||
1194 | |||
1195 | mpi_request.PageAddress = | ||
1196 | cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number); | ||
1197 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1198 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1199 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1200 | sizeof(*config_page)); | ||
1201 | out: | ||
1202 | return r; | ||
1203 | } | ||
1204 | |||
1205 | /** | ||
1206 | * mpt2sas_config_get_phy_pg1 - obtain phy page 1 | ||
1207 | * @ioc: per adapter object | ||
1208 | * @mpi_reply: reply mf payload returned from firmware | ||
1209 | * @config_page: contents of the config page | ||
1210 | * @phy_number: phy number | ||
1211 | * Context: sleep. | ||
1212 | * | ||
1213 | * Returns 0 for success, non-zero for failure. | ||
1214 | */ | ||
1215 | int | ||
1216 | mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1217 | *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number) | ||
1218 | { | ||
1219 | Mpi2ConfigRequest_t mpi_request; | ||
1220 | int r; | ||
1221 | |||
1222 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1223 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1224 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1225 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1226 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_PHY; | ||
1227 | mpi_request.Header.PageNumber = 1; | ||
1228 | mpi_request.Header.PageVersion = MPI2_SASPHY1_PAGEVERSION; | ||
1229 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1230 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1231 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1232 | if (r) | ||
1233 | goto out; | ||
1234 | |||
1235 | mpi_request.PageAddress = | ||
1236 | cpu_to_le32(MPI2_SAS_PHY_PGAD_FORM_PHY_NUMBER | phy_number); | ||
1237 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1238 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1239 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1240 | sizeof(*config_page)); | ||
1241 | out: | ||
1242 | return r; | ||
1243 | } | ||
1244 | |||
1245 | /** | ||
1246 | * mpt2sas_config_get_raid_volume_pg1 - obtain raid volume page 1 | ||
1247 | * @ioc: per adapter object | ||
1248 | * @mpi_reply: reply mf payload returned from firmware | ||
1249 | * @config_page: contents of the config page | ||
1250 | * @form: GET_NEXT_HANDLE or HANDLE | ||
1251 | * @handle: volume handle | ||
1252 | * Context: sleep. | ||
1253 | * | ||
1254 | * Returns 0 for success, non-zero for failure. | ||
1255 | */ | ||
1256 | int | ||
1257 | mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, | ||
1258 | Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, | ||
1259 | u32 handle) | ||
1260 | { | ||
1261 | Mpi2ConfigRequest_t mpi_request; | ||
1262 | int r; | ||
1263 | |||
1264 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1265 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1266 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1267 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; | ||
1268 | mpi_request.Header.PageNumber = 1; | ||
1269 | mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE1_PAGEVERSION; | ||
1270 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1271 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1272 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1273 | if (r) | ||
1274 | goto out; | ||
1275 | |||
1276 | mpi_request.PageAddress = cpu_to_le32(form | handle); | ||
1277 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1278 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1279 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1280 | sizeof(*config_page)); | ||
1281 | out: | ||
1282 | return r; | ||
1283 | } | ||
1284 | |||
1285 | /** | ||
1286 | * mpt2sas_config_get_number_pds - obtain number of phys disk assigned to volume | ||
1287 | * @ioc: per adapter object | ||
1288 | * @handle: volume handle | ||
1289 | * @num_pds: returns pds count | ||
1290 | * Context: sleep. | ||
1291 | * | ||
1292 | * Returns 0 for success, non-zero for failure. | ||
1293 | */ | ||
1294 | int | ||
1295 | mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, | ||
1296 | u8 *num_pds) | ||
1297 | { | ||
1298 | Mpi2ConfigRequest_t mpi_request; | ||
1299 | Mpi2RaidVolPage0_t config_page; | ||
1300 | Mpi2ConfigReply_t mpi_reply; | ||
1301 | int r; | ||
1302 | u16 ioc_status; | ||
1303 | |||
1304 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1305 | *num_pds = 0; | ||
1306 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1307 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1308 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; | ||
1309 | mpi_request.Header.PageNumber = 0; | ||
1310 | mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION; | ||
1311 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1312 | r = _config_request(ioc, &mpi_request, &mpi_reply, | ||
1313 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1314 | if (r) | ||
1315 | goto out; | ||
1316 | |||
1317 | mpi_request.PageAddress = | ||
1318 | cpu_to_le32(MPI2_RAID_VOLUME_PGAD_FORM_HANDLE | handle); | ||
1319 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1320 | r = _config_request(ioc, &mpi_request, &mpi_reply, | ||
1321 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, &config_page, | ||
1322 | sizeof(Mpi2RaidVolPage0_t)); | ||
1323 | if (!r) { | ||
1324 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1325 | MPI2_IOCSTATUS_MASK; | ||
1326 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) | ||
1327 | *num_pds = config_page.NumPhysDisks; | ||
1328 | } | ||
1329 | |||
1330 | out: | ||
1331 | return r; | ||
1332 | } | ||
1333 | |||
1334 | /** | ||
1335 | * mpt2sas_config_get_raid_volume_pg0 - obtain raid volume page 0 | ||
1336 | * @ioc: per adapter object | ||
1337 | * @mpi_reply: reply mf payload returned from firmware | ||
1338 | * @config_page: contents of the config page | ||
1339 | * @form: GET_NEXT_HANDLE or HANDLE | ||
1340 | * @handle: volume handle | ||
1341 | * @sz: size of buffer passed in config_page | ||
1342 | * Context: sleep. | ||
1343 | * | ||
1344 | * Returns 0 for success, non-zero for failure. | ||
1345 | */ | ||
1346 | int | ||
1347 | mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, | ||
1348 | Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, | ||
1349 | u32 handle, u16 sz) | ||
1350 | { | ||
1351 | Mpi2ConfigRequest_t mpi_request; | ||
1352 | int r; | ||
1353 | |||
1354 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1355 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1356 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1357 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_VOLUME; | ||
1358 | mpi_request.Header.PageNumber = 0; | ||
1359 | mpi_request.Header.PageVersion = MPI2_RAIDVOLPAGE0_PAGEVERSION; | ||
1360 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1361 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1362 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1363 | if (r) | ||
1364 | goto out; | ||
1365 | |||
1366 | mpi_request.PageAddress = cpu_to_le32(form | handle); | ||
1367 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1368 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1369 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz); | ||
1370 | out: | ||
1371 | return r; | ||
1372 | } | ||
1373 | |||
1374 | /** | ||
1375 | * mpt2sas_config_get_phys_disk_pg0 - obtain phys disk page 0 | ||
1376 | * @ioc: per adapter object | ||
1377 | * @mpi_reply: reply mf payload returned from firmware | ||
1378 | * @config_page: contents of the config page | ||
1379 | * @form: GET_NEXT_PHYSDISKNUM, PHYSDISKNUM, DEVHANDLE | ||
1380 | * @form_specific: specific to the form | ||
1381 | * Context: sleep. | ||
1382 | * | ||
1383 | * Returns 0 for success, non-zero for failure. | ||
1384 | */ | ||
1385 | int | ||
1386 | mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t | ||
1387 | *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form, | ||
1388 | u32 form_specific) | ||
1389 | { | ||
1390 | Mpi2ConfigRequest_t mpi_request; | ||
1391 | int r; | ||
1392 | |||
1393 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1394 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1395 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1396 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK; | ||
1397 | mpi_request.Header.PageNumber = 0; | ||
1398 | mpi_request.Header.PageVersion = MPI2_RAIDPHYSDISKPAGE0_PAGEVERSION; | ||
1399 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1400 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1401 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1402 | if (r) | ||
1403 | goto out; | ||
1404 | |||
1405 | mpi_request.PageAddress = cpu_to_le32(form | form_specific); | ||
1406 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1407 | r = _config_request(ioc, &mpi_request, mpi_reply, | ||
1408 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1409 | sizeof(*config_page)); | ||
1410 | out: | ||
1411 | return r; | ||
1412 | } | ||
1413 | |||
1414 | /** | ||
1415 | * mpt2sas_config_get_volume_handle - returns volume handle for give hidden raid components | ||
1416 | * @ioc: per adapter object | ||
1417 | * @pd_handle: phys disk handle | ||
1418 | * @volume_handle: volume handle | ||
1419 | * Context: sleep. | ||
1420 | * | ||
1421 | * Returns 0 for success, non-zero for failure. | ||
1422 | */ | ||
1423 | int | ||
1424 | mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle, | ||
1425 | u16 *volume_handle) | ||
1426 | { | ||
1427 | Mpi2RaidConfigurationPage0_t *config_page = NULL; | ||
1428 | Mpi2ConfigRequest_t mpi_request; | ||
1429 | Mpi2ConfigReply_t mpi_reply; | ||
1430 | int r, i, config_page_sz; | ||
1431 | u16 ioc_status; | ||
1432 | int config_num; | ||
1433 | u16 element_type; | ||
1434 | u16 phys_disk_dev_handle; | ||
1435 | |||
1436 | *volume_handle = 0; | ||
1437 | memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); | ||
1438 | mpi_request.Function = MPI2_FUNCTION_CONFIG; | ||
1439 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER; | ||
1440 | mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; | ||
1441 | mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_RAID_CONFIG; | ||
1442 | mpi_request.Header.PageVersion = MPI2_RAIDCONFIG0_PAGEVERSION; | ||
1443 | mpi_request.Header.PageNumber = 0; | ||
1444 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); | ||
1445 | r = _config_request(ioc, &mpi_request, &mpi_reply, | ||
1446 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); | ||
1447 | if (r) | ||
1448 | goto out; | ||
1449 | |||
1450 | mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; | ||
1451 | config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4); | ||
1452 | config_page = kmalloc(config_page_sz, GFP_KERNEL); | ||
1453 | if (!config_page) { | ||
1454 | r = -1; | ||
1455 | goto out; | ||
1456 | } | ||
1457 | config_num = 0xff; | ||
1458 | while (1) { | ||
1459 | mpi_request.PageAddress = cpu_to_le32(config_num + | ||
1460 | MPI2_RAID_PGAD_FORM_GET_NEXT_CONFIGNUM); | ||
1461 | r = _config_request(ioc, &mpi_request, &mpi_reply, | ||
1462 | MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, | ||
1463 | config_page_sz); | ||
1464 | if (r) | ||
1465 | goto out; | ||
1466 | r = -1; | ||
1467 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1468 | MPI2_IOCSTATUS_MASK; | ||
1469 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
1470 | goto out; | ||
1471 | for (i = 0; i < config_page->NumElements; i++) { | ||
1472 | element_type = le16_to_cpu(config_page-> | ||
1473 | ConfigElement[i].ElementFlags) & | ||
1474 | MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE; | ||
1475 | if (element_type == | ||
1476 | MPI2_RAIDCONFIG0_EFLAGS_VOL_PHYS_DISK_ELEMENT || | ||
1477 | element_type == | ||
1478 | MPI2_RAIDCONFIG0_EFLAGS_OCE_ELEMENT) { | ||
1479 | phys_disk_dev_handle = | ||
1480 | le16_to_cpu(config_page->ConfigElement[i]. | ||
1481 | PhysDiskDevHandle); | ||
1482 | if (phys_disk_dev_handle == pd_handle) { | ||
1483 | *volume_handle = | ||
1484 | le16_to_cpu(config_page-> | ||
1485 | ConfigElement[i].VolDevHandle); | ||
1486 | r = 0; | ||
1487 | goto out; | ||
1488 | } | ||
1489 | } else if (element_type == | ||
1490 | MPI2_RAIDCONFIG0_EFLAGS_HOT_SPARE_ELEMENT) { | ||
1491 | *volume_handle = 0; | ||
1492 | r = 0; | ||
1493 | goto out; | ||
1494 | } | ||
1495 | } | ||
1496 | config_num = config_page->ConfigNum; | ||
1497 | } | ||
1498 | out: | ||
1499 | kfree(config_page); | ||
1500 | return r; | ||
1501 | } | ||
1502 | |||
1503 | /** | ||
1504 | * mpt2sas_config_get_volume_wwid - returns wwid given the volume handle | ||
1505 | * @ioc: per adapter object | ||
1506 | * @volume_handle: volume handle | ||
1507 | * @wwid: volume wwid | ||
1508 | * Context: sleep. | ||
1509 | * | ||
1510 | * Returns 0 for success, non-zero for failure. | ||
1511 | */ | ||
1512 | int | ||
1513 | mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle, | ||
1514 | u64 *wwid) | ||
1515 | { | ||
1516 | Mpi2ConfigReply_t mpi_reply; | ||
1517 | Mpi2RaidVolPage1_t raid_vol_pg1; | ||
1518 | |||
1519 | *wwid = 0; | ||
1520 | if (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | ||
1521 | &raid_vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, | ||
1522 | volume_handle))) { | ||
1523 | *wwid = le64_to_cpu(raid_vol_pg1.WWID); | ||
1524 | return 0; | ||
1525 | } else | ||
1526 | return -1; | ||
1527 | } | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c deleted file mode 100644 index 3694b63bd993..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c +++ /dev/null | |||
@@ -1,3101 +0,0 @@ | |||
1 | /* | ||
2 | * Management Module Support for MPT (Message Passing Technology) based | ||
3 | * controllers | ||
4 | * | ||
5 | * This code is based on drivers/scsi/mpt2sas/mpt2_ctl.c | ||
6 | * Copyright (C) 2007-2014 LSI Corporation | ||
7 | * Copyright (C) 20013-2014 Avago Technologies | ||
8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version 2 | ||
13 | * of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * NO WARRANTY | ||
21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
25 | * solely responsible for determining the appropriateness of using and | ||
26 | * distributing the Program and assumes all risks associated with its | ||
27 | * exercise of rights under this Agreement, including but not limited to | ||
28 | * the risks and costs of program errors, damage to or loss of data, | ||
29 | * programs or equipment, and unavailability or interruption of operations. | ||
30 | |||
31 | * DISCLAIMER OF LIABILITY | ||
32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
39 | |||
40 | * You should have received a copy of the GNU General Public License | ||
41 | * along with this program; if not, write to the Free Software | ||
42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
43 | * USA. | ||
44 | */ | ||
45 | |||
46 | #include <linux/kernel.h> | ||
47 | #include <linux/module.h> | ||
48 | #include <linux/errno.h> | ||
49 | #include <linux/init.h> | ||
50 | #include <linux/slab.h> | ||
51 | #include <linux/types.h> | ||
52 | #include <linux/pci.h> | ||
53 | #include <linux/delay.h> | ||
54 | #include <linux/mutex.h> | ||
55 | #include <linux/compat.h> | ||
56 | #include <linux/poll.h> | ||
57 | |||
58 | #include <linux/io.h> | ||
59 | #include <linux/uaccess.h> | ||
60 | |||
61 | #include "mpt2sas_base.h" | ||
62 | #include "mpt2sas_ctl.h" | ||
63 | |||
64 | static DEFINE_MUTEX(_ctl_mutex); | ||
65 | static struct fasync_struct *async_queue; | ||
66 | static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); | ||
67 | |||
68 | static int _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, | ||
69 | u8 *issue_reset); | ||
70 | |||
71 | /** | ||
72 | * enum block_state - blocking state | ||
73 | * @NON_BLOCKING: non blocking | ||
74 | * @BLOCKING: blocking | ||
75 | * | ||
76 | * These states are for ioctls that need to wait for a response | ||
77 | * from firmware, so they probably require sleep. | ||
78 | */ | ||
79 | enum block_state { | ||
80 | NON_BLOCKING, | ||
81 | BLOCKING, | ||
82 | }; | ||
83 | |||
84 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
85 | /** | ||
86 | * _ctl_sas_device_find_by_handle - sas device search | ||
87 | * @ioc: per adapter object | ||
88 | * @handle: sas device handle (assigned by firmware) | ||
89 | * Context: Calling function should acquire ioc->sas_device_lock | ||
90 | * | ||
91 | * This searches for sas_device based on sas_address, then return sas_device | ||
92 | * object. | ||
93 | */ | ||
94 | static struct _sas_device * | ||
95 | _ctl_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
96 | { | ||
97 | struct _sas_device *sas_device, *r; | ||
98 | |||
99 | r = NULL; | ||
100 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | ||
101 | if (sas_device->handle != handle) | ||
102 | continue; | ||
103 | r = sas_device; | ||
104 | goto out; | ||
105 | } | ||
106 | |||
107 | out: | ||
108 | return r; | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * _ctl_display_some_debug - debug routine | ||
113 | * @ioc: per adapter object | ||
114 | * @smid: system request message index | ||
115 | * @calling_function_name: string pass from calling function | ||
116 | * @mpi_reply: reply message frame | ||
117 | * Context: none. | ||
118 | * | ||
119 | * Function for displaying debug info helpful when debugging issues | ||
120 | * in this module. | ||
121 | */ | ||
122 | static void | ||
123 | _ctl_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
124 | char *calling_function_name, MPI2DefaultReply_t *mpi_reply) | ||
125 | { | ||
126 | Mpi2ConfigRequest_t *mpi_request; | ||
127 | char *desc = NULL; | ||
128 | |||
129 | if (!(ioc->logging_level & MPT_DEBUG_IOCTL)) | ||
130 | return; | ||
131 | |||
132 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
133 | switch (mpi_request->Function) { | ||
134 | case MPI2_FUNCTION_SCSI_IO_REQUEST: | ||
135 | { | ||
136 | Mpi2SCSIIORequest_t *scsi_request = | ||
137 | (Mpi2SCSIIORequest_t *)mpi_request; | ||
138 | |||
139 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, | ||
140 | "scsi_io, cmd(0x%02x), cdb_len(%d)", | ||
141 | scsi_request->CDB.CDB32[0], | ||
142 | le16_to_cpu(scsi_request->IoFlags) & 0xF); | ||
143 | desc = ioc->tmp_string; | ||
144 | break; | ||
145 | } | ||
146 | case MPI2_FUNCTION_SCSI_TASK_MGMT: | ||
147 | desc = "task_mgmt"; | ||
148 | break; | ||
149 | case MPI2_FUNCTION_IOC_INIT: | ||
150 | desc = "ioc_init"; | ||
151 | break; | ||
152 | case MPI2_FUNCTION_IOC_FACTS: | ||
153 | desc = "ioc_facts"; | ||
154 | break; | ||
155 | case MPI2_FUNCTION_CONFIG: | ||
156 | { | ||
157 | Mpi2ConfigRequest_t *config_request = | ||
158 | (Mpi2ConfigRequest_t *)mpi_request; | ||
159 | |||
160 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, | ||
161 | "config, type(0x%02x), ext_type(0x%02x), number(%d)", | ||
162 | (config_request->Header.PageType & | ||
163 | MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType, | ||
164 | config_request->Header.PageNumber); | ||
165 | desc = ioc->tmp_string; | ||
166 | break; | ||
167 | } | ||
168 | case MPI2_FUNCTION_PORT_FACTS: | ||
169 | desc = "port_facts"; | ||
170 | break; | ||
171 | case MPI2_FUNCTION_PORT_ENABLE: | ||
172 | desc = "port_enable"; | ||
173 | break; | ||
174 | case MPI2_FUNCTION_EVENT_NOTIFICATION: | ||
175 | desc = "event_notification"; | ||
176 | break; | ||
177 | case MPI2_FUNCTION_FW_DOWNLOAD: | ||
178 | desc = "fw_download"; | ||
179 | break; | ||
180 | case MPI2_FUNCTION_FW_UPLOAD: | ||
181 | desc = "fw_upload"; | ||
182 | break; | ||
183 | case MPI2_FUNCTION_RAID_ACTION: | ||
184 | desc = "raid_action"; | ||
185 | break; | ||
186 | case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: | ||
187 | { | ||
188 | Mpi2SCSIIORequest_t *scsi_request = | ||
189 | (Mpi2SCSIIORequest_t *)mpi_request; | ||
190 | |||
191 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, | ||
192 | "raid_pass, cmd(0x%02x), cdb_len(%d)", | ||
193 | scsi_request->CDB.CDB32[0], | ||
194 | le16_to_cpu(scsi_request->IoFlags) & 0xF); | ||
195 | desc = ioc->tmp_string; | ||
196 | break; | ||
197 | } | ||
198 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: | ||
199 | desc = "sas_iounit_cntl"; | ||
200 | break; | ||
201 | case MPI2_FUNCTION_SATA_PASSTHROUGH: | ||
202 | desc = "sata_pass"; | ||
203 | break; | ||
204 | case MPI2_FUNCTION_DIAG_BUFFER_POST: | ||
205 | desc = "diag_buffer_post"; | ||
206 | break; | ||
207 | case MPI2_FUNCTION_DIAG_RELEASE: | ||
208 | desc = "diag_release"; | ||
209 | break; | ||
210 | case MPI2_FUNCTION_SMP_PASSTHROUGH: | ||
211 | desc = "smp_passthrough"; | ||
212 | break; | ||
213 | } | ||
214 | |||
215 | if (!desc) | ||
216 | return; | ||
217 | |||
218 | printk(MPT2SAS_INFO_FMT "%s: %s, smid(%d)\n", | ||
219 | ioc->name, calling_function_name, desc, smid); | ||
220 | |||
221 | if (!mpi_reply) | ||
222 | return; | ||
223 | |||
224 | if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo) | ||
225 | printk(MPT2SAS_INFO_FMT | ||
226 | "\tiocstatus(0x%04x), loginfo(0x%08x)\n", | ||
227 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | ||
228 | le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
229 | |||
230 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || | ||
231 | mpi_request->Function == | ||
232 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { | ||
233 | Mpi2SCSIIOReply_t *scsi_reply = | ||
234 | (Mpi2SCSIIOReply_t *)mpi_reply; | ||
235 | struct _sas_device *sas_device = NULL; | ||
236 | unsigned long flags; | ||
237 | |||
238 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
239 | sas_device = _ctl_sas_device_find_by_handle(ioc, | ||
240 | le16_to_cpu(scsi_reply->DevHandle)); | ||
241 | if (sas_device) { | ||
242 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " | ||
243 | "phy(%d)\n", ioc->name, (unsigned long long) | ||
244 | sas_device->sas_address, sas_device->phy); | ||
245 | printk(MPT2SAS_WARN_FMT | ||
246 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", | ||
247 | ioc->name, sas_device->enclosure_logical_id, | ||
248 | sas_device->slot); | ||
249 | } | ||
250 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
251 | if (scsi_reply->SCSIState || scsi_reply->SCSIStatus) | ||
252 | printk(MPT2SAS_INFO_FMT | ||
253 | "\tscsi_state(0x%02x), scsi_status" | ||
254 | "(0x%02x)\n", ioc->name, | ||
255 | scsi_reply->SCSIState, | ||
256 | scsi_reply->SCSIStatus); | ||
257 | } | ||
258 | } | ||
259 | #endif | ||
260 | |||
261 | /** | ||
262 | * mpt2sas_ctl_done - ctl module completion routine | ||
263 | * @ioc: per adapter object | ||
264 | * @smid: system request message index | ||
265 | * @msix_index: MSIX table index supplied by the OS | ||
266 | * @reply: reply message frame(lower 32bit addr) | ||
267 | * Context: none. | ||
268 | * | ||
269 | * The callback handler when using ioc->ctl_cb_idx. | ||
270 | * | ||
271 | * Return 1 meaning mf should be freed from _base_interrupt | ||
272 | * 0 means the mf is freed from this function. | ||
273 | */ | ||
274 | u8 | ||
275 | mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
276 | u32 reply) | ||
277 | { | ||
278 | MPI2DefaultReply_t *mpi_reply; | ||
279 | Mpi2SCSIIOReply_t *scsiio_reply; | ||
280 | const void *sense_data; | ||
281 | u32 sz; | ||
282 | |||
283 | if (ioc->ctl_cmds.status == MPT2_CMD_NOT_USED) | ||
284 | return 1; | ||
285 | if (ioc->ctl_cmds.smid != smid) | ||
286 | return 1; | ||
287 | ioc->ctl_cmds.status |= MPT2_CMD_COMPLETE; | ||
288 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
289 | if (mpi_reply) { | ||
290 | memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | ||
291 | ioc->ctl_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
292 | /* get sense data */ | ||
293 | if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || | ||
294 | mpi_reply->Function == | ||
295 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { | ||
296 | scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply; | ||
297 | if (scsiio_reply->SCSIState & | ||
298 | MPI2_SCSI_STATE_AUTOSENSE_VALID) { | ||
299 | sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | ||
300 | le32_to_cpu(scsiio_reply->SenseCount)); | ||
301 | sense_data = mpt2sas_base_get_sense_buffer(ioc, | ||
302 | smid); | ||
303 | memcpy(ioc->ctl_cmds.sense, sense_data, sz); | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
308 | _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply); | ||
309 | #endif | ||
310 | ioc->ctl_cmds.status &= ~MPT2_CMD_PENDING; | ||
311 | complete(&ioc->ctl_cmds.done); | ||
312 | return 1; | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * _ctl_check_event_type - determines when an event needs logging | ||
317 | * @ioc: per adapter object | ||
318 | * @event: firmware event | ||
319 | * | ||
320 | * The bitmask in ioc->event_type[] indicates which events should be | ||
321 | * be saved in the driver event_log. This bitmask is set by application. | ||
322 | * | ||
323 | * Returns 1 when event should be captured, or zero means no match. | ||
324 | */ | ||
325 | static int | ||
326 | _ctl_check_event_type(struct MPT2SAS_ADAPTER *ioc, u16 event) | ||
327 | { | ||
328 | u16 i; | ||
329 | u32 desired_event; | ||
330 | |||
331 | if (event >= 128 || !event || !ioc->event_log) | ||
332 | return 0; | ||
333 | |||
334 | desired_event = (1 << (event % 32)); | ||
335 | if (!desired_event) | ||
336 | desired_event = 1; | ||
337 | i = event / 32; | ||
338 | return desired_event & ioc->event_type[i]; | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * mpt2sas_ctl_add_to_event_log - add event | ||
343 | * @ioc: per adapter object | ||
344 | * @mpi_reply: reply message frame | ||
345 | * | ||
346 | * Return nothing. | ||
347 | */ | ||
348 | void | ||
349 | mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc, | ||
350 | Mpi2EventNotificationReply_t *mpi_reply) | ||
351 | { | ||
352 | struct MPT2_IOCTL_EVENTS *event_log; | ||
353 | u16 event; | ||
354 | int i; | ||
355 | u32 sz, event_data_sz; | ||
356 | u8 send_aen = 0; | ||
357 | |||
358 | if (!ioc->event_log) | ||
359 | return; | ||
360 | |||
361 | event = le16_to_cpu(mpi_reply->Event); | ||
362 | |||
363 | if (_ctl_check_event_type(ioc, event)) { | ||
364 | |||
365 | /* insert entry into circular event_log */ | ||
366 | i = ioc->event_context % MPT2SAS_CTL_EVENT_LOG_SIZE; | ||
367 | event_log = ioc->event_log; | ||
368 | event_log[i].event = event; | ||
369 | event_log[i].context = ioc->event_context++; | ||
370 | |||
371 | event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4; | ||
372 | sz = min_t(u32, event_data_sz, MPT2_EVENT_DATA_SIZE); | ||
373 | memset(event_log[i].data, 0, MPT2_EVENT_DATA_SIZE); | ||
374 | memcpy(event_log[i].data, mpi_reply->EventData, sz); | ||
375 | send_aen = 1; | ||
376 | } | ||
377 | |||
378 | /* This aen_event_read_flag flag is set until the | ||
379 | * application has read the event log. | ||
380 | * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify. | ||
381 | */ | ||
382 | if (event == MPI2_EVENT_LOG_ENTRY_ADDED || | ||
383 | (send_aen && !ioc->aen_event_read_flag)) { | ||
384 | ioc->aen_event_read_flag = 1; | ||
385 | wake_up_interruptible(&ctl_poll_wait); | ||
386 | if (async_queue) | ||
387 | kill_fasync(&async_queue, SIGIO, POLL_IN); | ||
388 | } | ||
389 | } | ||
390 | |||
391 | /** | ||
392 | * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time) | ||
393 | * @ioc: per adapter object | ||
394 | * @msix_index: MSIX table index supplied by the OS | ||
395 | * @reply: reply message frame(lower 32bit addr) | ||
396 | * Context: interrupt. | ||
397 | * | ||
398 | * This function merely adds a new work task into ioc->firmware_event_thread. | ||
399 | * The tasks are worked from _firmware_event_work in user context. | ||
400 | * | ||
401 | * Returns void. | ||
402 | */ | ||
403 | void | ||
404 | mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, | ||
405 | u32 reply) | ||
406 | { | ||
407 | Mpi2EventNotificationReply_t *mpi_reply; | ||
408 | |||
409 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
410 | if (unlikely(!mpi_reply)) { | ||
411 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", | ||
412 | ioc->name, __FILE__, __LINE__, __func__); | ||
413 | return; | ||
414 | } | ||
415 | mpt2sas_ctl_add_to_event_log(ioc, mpi_reply); | ||
416 | return; | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * _ctl_verify_adapter - validates ioc_number passed from application | ||
421 | * @ioc: per adapter object | ||
422 | * @iocpp: The ioc pointer is returned in this. | ||
423 | * | ||
424 | * Return (-1) means error, else ioc_number. | ||
425 | */ | ||
426 | static int | ||
427 | _ctl_verify_adapter(int ioc_number, struct MPT2SAS_ADAPTER **iocpp) | ||
428 | { | ||
429 | struct MPT2SAS_ADAPTER *ioc; | ||
430 | /* global ioc lock to protect controller on list operations */ | ||
431 | spin_lock(&gioc_lock); | ||
432 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) { | ||
433 | if (ioc->id != ioc_number) | ||
434 | continue; | ||
435 | spin_unlock(&gioc_lock); | ||
436 | *iocpp = ioc; | ||
437 | return ioc_number; | ||
438 | } | ||
439 | spin_unlock(&gioc_lock); | ||
440 | *iocpp = NULL; | ||
441 | return -1; | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * mpt2sas_ctl_reset_handler - reset callback handler (for ctl) | ||
446 | * @ioc: per adapter object | ||
447 | * @reset_phase: phase | ||
448 | * | ||
449 | * The handler for doing any required cleanup or initialization. | ||
450 | * | ||
451 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, | ||
452 | * MPT2_IOC_DONE_RESET | ||
453 | */ | ||
454 | void | ||
455 | mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) | ||
456 | { | ||
457 | int i; | ||
458 | u8 issue_reset; | ||
459 | |||
460 | switch (reset_phase) { | ||
461 | case MPT2_IOC_PRE_RESET: | ||
462 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
463 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); | ||
464 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { | ||
465 | if (!(ioc->diag_buffer_status[i] & | ||
466 | MPT2_DIAG_BUFFER_IS_REGISTERED)) | ||
467 | continue; | ||
468 | if ((ioc->diag_buffer_status[i] & | ||
469 | MPT2_DIAG_BUFFER_IS_RELEASED)) | ||
470 | continue; | ||
471 | _ctl_send_release(ioc, i, &issue_reset); | ||
472 | } | ||
473 | break; | ||
474 | case MPT2_IOC_AFTER_RESET: | ||
475 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
476 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); | ||
477 | if (ioc->ctl_cmds.status & MPT2_CMD_PENDING) { | ||
478 | ioc->ctl_cmds.status |= MPT2_CMD_RESET; | ||
479 | mpt2sas_base_free_smid(ioc, ioc->ctl_cmds.smid); | ||
480 | complete(&ioc->ctl_cmds.done); | ||
481 | } | ||
482 | break; | ||
483 | case MPT2_IOC_DONE_RESET: | ||
484 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
485 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); | ||
486 | |||
487 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { | ||
488 | if (!(ioc->diag_buffer_status[i] & | ||
489 | MPT2_DIAG_BUFFER_IS_REGISTERED)) | ||
490 | continue; | ||
491 | if ((ioc->diag_buffer_status[i] & | ||
492 | MPT2_DIAG_BUFFER_IS_RELEASED)) | ||
493 | continue; | ||
494 | ioc->diag_buffer_status[i] |= | ||
495 | MPT2_DIAG_BUFFER_IS_DIAG_RESET; | ||
496 | } | ||
497 | break; | ||
498 | } | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * _ctl_fasync - | ||
503 | * @fd - | ||
504 | * @filep - | ||
505 | * @mode - | ||
506 | * | ||
507 | * Called when application request fasyn callback handler. | ||
508 | */ | ||
509 | static int | ||
510 | _ctl_fasync(int fd, struct file *filep, int mode) | ||
511 | { | ||
512 | return fasync_helper(fd, filep, mode, &async_queue); | ||
513 | } | ||
514 | |||
515 | /** | ||
516 | * _ctl_poll - | ||
517 | * @file - | ||
518 | * @wait - | ||
519 | * | ||
520 | */ | ||
521 | static unsigned int | ||
522 | _ctl_poll(struct file *filep, poll_table *wait) | ||
523 | { | ||
524 | struct MPT2SAS_ADAPTER *ioc; | ||
525 | |||
526 | poll_wait(filep, &ctl_poll_wait, wait); | ||
527 | |||
528 | /* global ioc lock to protect controller on list operations */ | ||
529 | spin_lock(&gioc_lock); | ||
530 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) { | ||
531 | if (ioc->aen_event_read_flag) { | ||
532 | spin_unlock(&gioc_lock); | ||
533 | return POLLIN | POLLRDNORM; | ||
534 | } | ||
535 | } | ||
536 | spin_unlock(&gioc_lock); | ||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | /** | ||
541 | * _ctl_set_task_mid - assign an active smid to tm request | ||
542 | * @ioc: per adapter object | ||
543 | * @karg - (struct mpt2_ioctl_command) | ||
544 | * @tm_request - pointer to mf from user space | ||
545 | * | ||
546 | * Returns 0 when an smid if found, else fail. | ||
547 | * during failure, the reply frame is filled. | ||
548 | */ | ||
549 | static int | ||
550 | _ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg, | ||
551 | Mpi2SCSITaskManagementRequest_t *tm_request) | ||
552 | { | ||
553 | u8 found = 0; | ||
554 | u16 i; | ||
555 | u16 handle; | ||
556 | struct scsi_cmnd *scmd; | ||
557 | struct MPT2SAS_DEVICE *priv_data; | ||
558 | unsigned long flags; | ||
559 | Mpi2SCSITaskManagementReply_t *tm_reply; | ||
560 | u32 sz; | ||
561 | u32 lun; | ||
562 | char *desc = NULL; | ||
563 | |||
564 | if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | ||
565 | desc = "abort_task"; | ||
566 | else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) | ||
567 | desc = "query_task"; | ||
568 | else | ||
569 | return 0; | ||
570 | |||
571 | lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN); | ||
572 | |||
573 | handle = le16_to_cpu(tm_request->DevHandle); | ||
574 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
575 | for (i = ioc->scsiio_depth; i && !found; i--) { | ||
576 | scmd = ioc->scsi_lookup[i - 1].scmd; | ||
577 | if (scmd == NULL || scmd->device == NULL || | ||
578 | scmd->device->hostdata == NULL) | ||
579 | continue; | ||
580 | if (lun != scmd->device->lun) | ||
581 | continue; | ||
582 | priv_data = scmd->device->hostdata; | ||
583 | if (priv_data->sas_target == NULL) | ||
584 | continue; | ||
585 | if (priv_data->sas_target->handle != handle) | ||
586 | continue; | ||
587 | tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid); | ||
588 | found = 1; | ||
589 | } | ||
590 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
591 | |||
592 | if (!found) { | ||
593 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
594 | "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name, | ||
595 | desc, le16_to_cpu(tm_request->DevHandle), lun)); | ||
596 | tm_reply = ioc->ctl_cmds.reply; | ||
597 | tm_reply->DevHandle = tm_request->DevHandle; | ||
598 | tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | ||
599 | tm_reply->TaskType = tm_request->TaskType; | ||
600 | tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4; | ||
601 | tm_reply->VP_ID = tm_request->VP_ID; | ||
602 | tm_reply->VF_ID = tm_request->VF_ID; | ||
603 | sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz); | ||
604 | if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply, | ||
605 | sz)) | ||
606 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
607 | __LINE__, __func__); | ||
608 | return 1; | ||
609 | } | ||
610 | |||
611 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
612 | "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name, | ||
613 | desc, le16_to_cpu(tm_request->DevHandle), lun, | ||
614 | le16_to_cpu(tm_request->TaskMID))); | ||
615 | return 0; | ||
616 | } | ||
617 | |||
618 | /** | ||
619 | * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode | ||
620 | * @ioc: per adapter object | ||
621 | * @karg - (struct mpt2_ioctl_command) | ||
622 | * @mf - pointer to mf in user space | ||
623 | */ | ||
624 | static long | ||
625 | _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command karg, | ||
626 | void __user *mf) | ||
627 | { | ||
628 | MPI2RequestHeader_t *mpi_request = NULL, *request; | ||
629 | MPI2DefaultReply_t *mpi_reply; | ||
630 | u32 ioc_state; | ||
631 | u16 ioc_status; | ||
632 | u16 smid; | ||
633 | unsigned long timeout, timeleft; | ||
634 | u8 issue_reset; | ||
635 | u32 sz; | ||
636 | void *psge; | ||
637 | void *data_out = NULL; | ||
638 | dma_addr_t data_out_dma; | ||
639 | size_t data_out_sz = 0; | ||
640 | void *data_in = NULL; | ||
641 | dma_addr_t data_in_dma; | ||
642 | size_t data_in_sz = 0; | ||
643 | u32 sgl_flags; | ||
644 | long ret; | ||
645 | u16 wait_state_count; | ||
646 | |||
647 | issue_reset = 0; | ||
648 | |||
649 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { | ||
650 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", | ||
651 | ioc->name, __func__); | ||
652 | ret = -EAGAIN; | ||
653 | goto out; | ||
654 | } | ||
655 | |||
656 | wait_state_count = 0; | ||
657 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
658 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
659 | if (wait_state_count++ == 10) { | ||
660 | printk(MPT2SAS_ERR_FMT | ||
661 | "%s: failed due to ioc not operational\n", | ||
662 | ioc->name, __func__); | ||
663 | ret = -EFAULT; | ||
664 | goto out; | ||
665 | } | ||
666 | ssleep(1); | ||
667 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
668 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
669 | "operational state(count=%d)\n", ioc->name, | ||
670 | __func__, wait_state_count); | ||
671 | } | ||
672 | if (wait_state_count) | ||
673 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", | ||
674 | ioc->name, __func__); | ||
675 | |||
676 | mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL); | ||
677 | if (!mpi_request) { | ||
678 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a memory for " | ||
679 | "mpi_request\n", ioc->name, __func__); | ||
680 | ret = -ENOMEM; | ||
681 | goto out; | ||
682 | } | ||
683 | |||
684 | /* Check for overflow and wraparound */ | ||
685 | if (karg.data_sge_offset * 4 > ioc->request_sz || | ||
686 | karg.data_sge_offset > (UINT_MAX / 4)) { | ||
687 | ret = -EINVAL; | ||
688 | goto out; | ||
689 | } | ||
690 | |||
691 | /* copy in request message frame from user */ | ||
692 | if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) { | ||
693 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__, | ||
694 | __func__); | ||
695 | ret = -EFAULT; | ||
696 | goto out; | ||
697 | } | ||
698 | |||
699 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) { | ||
700 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx); | ||
701 | if (!smid) { | ||
702 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
703 | ioc->name, __func__); | ||
704 | ret = -EAGAIN; | ||
705 | goto out; | ||
706 | } | ||
707 | } else { | ||
708 | |||
709 | smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL); | ||
710 | if (!smid) { | ||
711 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
712 | ioc->name, __func__); | ||
713 | ret = -EAGAIN; | ||
714 | goto out; | ||
715 | } | ||
716 | } | ||
717 | |||
718 | ret = 0; | ||
719 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; | ||
720 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); | ||
721 | request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
722 | memcpy(request, mpi_request, karg.data_sge_offset*4); | ||
723 | ioc->ctl_cmds.smid = smid; | ||
724 | data_out_sz = karg.data_out_size; | ||
725 | data_in_sz = karg.data_in_size; | ||
726 | |||
727 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || | ||
728 | mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { | ||
729 | if (!le16_to_cpu(mpi_request->FunctionDependent1) || | ||
730 | le16_to_cpu(mpi_request->FunctionDependent1) > | ||
731 | ioc->facts.MaxDevHandle) { | ||
732 | ret = -EINVAL; | ||
733 | mpt2sas_base_free_smid(ioc, smid); | ||
734 | goto out; | ||
735 | } | ||
736 | } | ||
737 | |||
738 | /* obtain dma-able memory for data transfer */ | ||
739 | if (data_out_sz) /* WRITE */ { | ||
740 | data_out = pci_alloc_consistent(ioc->pdev, data_out_sz, | ||
741 | &data_out_dma); | ||
742 | if (!data_out) { | ||
743 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
744 | __LINE__, __func__); | ||
745 | ret = -ENOMEM; | ||
746 | mpt2sas_base_free_smid(ioc, smid); | ||
747 | goto out; | ||
748 | } | ||
749 | if (copy_from_user(data_out, karg.data_out_buf_ptr, | ||
750 | data_out_sz)) { | ||
751 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
752 | __LINE__, __func__); | ||
753 | ret = -EFAULT; | ||
754 | mpt2sas_base_free_smid(ioc, smid); | ||
755 | goto out; | ||
756 | } | ||
757 | } | ||
758 | |||
759 | if (data_in_sz) /* READ */ { | ||
760 | data_in = pci_alloc_consistent(ioc->pdev, data_in_sz, | ||
761 | &data_in_dma); | ||
762 | if (!data_in) { | ||
763 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
764 | __LINE__, __func__); | ||
765 | ret = -ENOMEM; | ||
766 | mpt2sas_base_free_smid(ioc, smid); | ||
767 | goto out; | ||
768 | } | ||
769 | } | ||
770 | |||
771 | /* add scatter gather elements */ | ||
772 | psge = (void *)request + (karg.data_sge_offset*4); | ||
773 | |||
774 | if (!data_out_sz && !data_in_sz) { | ||
775 | mpt2sas_base_build_zero_len_sge(ioc, psge); | ||
776 | } else if (data_out_sz && data_in_sz) { | ||
777 | /* WRITE sgel first */ | ||
778 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
779 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); | ||
780 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
781 | ioc->base_add_sg_single(psge, sgl_flags | | ||
782 | data_out_sz, data_out_dma); | ||
783 | |||
784 | /* incr sgel */ | ||
785 | psge += ioc->sge_size; | ||
786 | |||
787 | /* READ sgel last */ | ||
788 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
789 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
790 | MPI2_SGE_FLAGS_END_OF_LIST); | ||
791 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
792 | ioc->base_add_sg_single(psge, sgl_flags | | ||
793 | data_in_sz, data_in_dma); | ||
794 | } else if (data_out_sz) /* WRITE */ { | ||
795 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
796 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
797 | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC); | ||
798 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
799 | ioc->base_add_sg_single(psge, sgl_flags | | ||
800 | data_out_sz, data_out_dma); | ||
801 | } else if (data_in_sz) /* READ */ { | ||
802 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
803 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
804 | MPI2_SGE_FLAGS_END_OF_LIST); | ||
805 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
806 | ioc->base_add_sg_single(psge, sgl_flags | | ||
807 | data_in_sz, data_in_dma); | ||
808 | } | ||
809 | |||
810 | /* send command to firmware */ | ||
811 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
812 | _ctl_display_some_debug(ioc, smid, "ctl_request", NULL); | ||
813 | #endif | ||
814 | |||
815 | init_completion(&ioc->ctl_cmds.done); | ||
816 | switch (mpi_request->Function) { | ||
817 | case MPI2_FUNCTION_SCSI_IO_REQUEST: | ||
818 | case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: | ||
819 | { | ||
820 | Mpi2SCSIIORequest_t *scsiio_request = | ||
821 | (Mpi2SCSIIORequest_t *)request; | ||
822 | scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | ||
823 | scsiio_request->SenseBufferLowAddress = | ||
824 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); | ||
825 | memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE); | ||
826 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST) | ||
827 | mpt2sas_base_put_smid_scsi_io(ioc, smid, | ||
828 | le16_to_cpu(mpi_request->FunctionDependent1)); | ||
829 | else | ||
830 | mpt2sas_base_put_smid_default(ioc, smid); | ||
831 | break; | ||
832 | } | ||
833 | case MPI2_FUNCTION_SCSI_TASK_MGMT: | ||
834 | { | ||
835 | Mpi2SCSITaskManagementRequest_t *tm_request = | ||
836 | (Mpi2SCSITaskManagementRequest_t *)request; | ||
837 | |||
838 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "TASK_MGMT: " | ||
839 | "handle(0x%04x), task_type(0x%02x)\n", ioc->name, | ||
840 | le16_to_cpu(tm_request->DevHandle), tm_request->TaskType)); | ||
841 | |||
842 | if (tm_request->TaskType == | ||
843 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK || | ||
844 | tm_request->TaskType == | ||
845 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) { | ||
846 | if (_ctl_set_task_mid(ioc, &karg, tm_request)) { | ||
847 | mpt2sas_base_free_smid(ioc, smid); | ||
848 | goto out; | ||
849 | } | ||
850 | } | ||
851 | |||
852 | mpt2sas_scsih_set_tm_flag(ioc, le16_to_cpu( | ||
853 | tm_request->DevHandle)); | ||
854 | mpt2sas_base_put_smid_hi_priority(ioc, smid); | ||
855 | break; | ||
856 | } | ||
857 | case MPI2_FUNCTION_SMP_PASSTHROUGH: | ||
858 | { | ||
859 | Mpi2SmpPassthroughRequest_t *smp_request = | ||
860 | (Mpi2SmpPassthroughRequest_t *)mpi_request; | ||
861 | u8 *data; | ||
862 | |||
863 | /* ioc determines which port to use */ | ||
864 | smp_request->PhysicalPort = 0xFF; | ||
865 | if (smp_request->PassthroughFlags & | ||
866 | MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE) | ||
867 | data = (u8 *)&smp_request->SGL; | ||
868 | else { | ||
869 | if (unlikely(data_out == NULL)) { | ||
870 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
871 | __FILE__, __LINE__, __func__); | ||
872 | mpt2sas_base_free_smid(ioc, smid); | ||
873 | ret = -EINVAL; | ||
874 | goto out; | ||
875 | } | ||
876 | data = data_out; | ||
877 | } | ||
878 | |||
879 | if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) { | ||
880 | ioc->ioc_link_reset_in_progress = 1; | ||
881 | ioc->ignore_loginfos = 1; | ||
882 | } | ||
883 | mpt2sas_base_put_smid_default(ioc, smid); | ||
884 | break; | ||
885 | } | ||
886 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: | ||
887 | { | ||
888 | Mpi2SasIoUnitControlRequest_t *sasiounit_request = | ||
889 | (Mpi2SasIoUnitControlRequest_t *)mpi_request; | ||
890 | |||
891 | if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET | ||
892 | || sasiounit_request->Operation == | ||
893 | MPI2_SAS_OP_PHY_LINK_RESET) { | ||
894 | ioc->ioc_link_reset_in_progress = 1; | ||
895 | ioc->ignore_loginfos = 1; | ||
896 | } | ||
897 | mpt2sas_base_put_smid_default(ioc, smid); | ||
898 | break; | ||
899 | } | ||
900 | default: | ||
901 | mpt2sas_base_put_smid_default(ioc, smid); | ||
902 | break; | ||
903 | } | ||
904 | |||
905 | if (karg.timeout < MPT2_IOCTL_DEFAULT_TIMEOUT) | ||
906 | timeout = MPT2_IOCTL_DEFAULT_TIMEOUT; | ||
907 | else | ||
908 | timeout = karg.timeout; | ||
909 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, | ||
910 | timeout*HZ); | ||
911 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) { | ||
912 | Mpi2SCSITaskManagementRequest_t *tm_request = | ||
913 | (Mpi2SCSITaskManagementRequest_t *)mpi_request; | ||
914 | mpt2sas_scsih_clear_tm_flag(ioc, le16_to_cpu( | ||
915 | tm_request->DevHandle)); | ||
916 | } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH || | ||
917 | mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) && | ||
918 | ioc->ioc_link_reset_in_progress) { | ||
919 | ioc->ioc_link_reset_in_progress = 0; | ||
920 | ioc->ignore_loginfos = 0; | ||
921 | } | ||
922 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { | ||
923 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, | ||
924 | __func__); | ||
925 | _debug_dump_mf(mpi_request, karg.data_sge_offset); | ||
926 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) | ||
927 | issue_reset = 1; | ||
928 | goto issue_host_reset; | ||
929 | } | ||
930 | |||
931 | mpi_reply = ioc->ctl_cmds.reply; | ||
932 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
933 | |||
934 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
935 | if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT && | ||
936 | (ioc->logging_level & MPT_DEBUG_TM)) { | ||
937 | Mpi2SCSITaskManagementReply_t *tm_reply = | ||
938 | (Mpi2SCSITaskManagementReply_t *)mpi_reply; | ||
939 | |||
940 | printk(MPT2SAS_INFO_FMT "TASK_MGMT: " | ||
941 | "IOCStatus(0x%04x), IOCLogInfo(0x%08x), " | ||
942 | "TerminationCount(0x%08x)\n", ioc->name, | ||
943 | le16_to_cpu(tm_reply->IOCStatus), | ||
944 | le32_to_cpu(tm_reply->IOCLogInfo), | ||
945 | le32_to_cpu(tm_reply->TerminationCount)); | ||
946 | } | ||
947 | #endif | ||
948 | /* copy out xdata to user */ | ||
949 | if (data_in_sz) { | ||
950 | if (copy_to_user(karg.data_in_buf_ptr, data_in, | ||
951 | data_in_sz)) { | ||
952 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
953 | __LINE__, __func__); | ||
954 | ret = -ENODATA; | ||
955 | goto out; | ||
956 | } | ||
957 | } | ||
958 | |||
959 | /* copy out reply message frame to user */ | ||
960 | if (karg.max_reply_bytes) { | ||
961 | sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz); | ||
962 | if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply, | ||
963 | sz)) { | ||
964 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
965 | __LINE__, __func__); | ||
966 | ret = -ENODATA; | ||
967 | goto out; | ||
968 | } | ||
969 | } | ||
970 | |||
971 | /* copy out sense to user */ | ||
972 | if (karg.max_sense_bytes && (mpi_request->Function == | ||
973 | MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function == | ||
974 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { | ||
975 | sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE); | ||
976 | if (copy_to_user(karg.sense_data_ptr, | ||
977 | ioc->ctl_cmds.sense, sz)) { | ||
978 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
979 | __LINE__, __func__); | ||
980 | ret = -ENODATA; | ||
981 | goto out; | ||
982 | } | ||
983 | } | ||
984 | |||
985 | issue_host_reset: | ||
986 | if (issue_reset) { | ||
987 | ret = -ENODATA; | ||
988 | if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || | ||
989 | mpi_request->Function == | ||
990 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || | ||
991 | mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) { | ||
992 | printk(MPT2SAS_INFO_FMT "issue target reset: handle " | ||
993 | "= (0x%04x)\n", ioc->name, | ||
994 | le16_to_cpu(mpi_request->FunctionDependent1)); | ||
995 | mpt2sas_halt_firmware(ioc); | ||
996 | mpt2sas_scsih_issue_tm(ioc, | ||
997 | le16_to_cpu(mpi_request->FunctionDependent1), 0, 0, | ||
998 | 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10, | ||
999 | TM_MUTEX_ON); | ||
1000 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; | ||
1001 | } else | ||
1002 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
1003 | FORCE_BIG_HAMMER); | ||
1004 | } | ||
1005 | |||
1006 | out: | ||
1007 | |||
1008 | /* free memory associated with sg buffers */ | ||
1009 | if (data_in) | ||
1010 | pci_free_consistent(ioc->pdev, data_in_sz, data_in, | ||
1011 | data_in_dma); | ||
1012 | |||
1013 | if (data_out) | ||
1014 | pci_free_consistent(ioc->pdev, data_out_sz, data_out, | ||
1015 | data_out_dma); | ||
1016 | |||
1017 | kfree(mpi_request); | ||
1018 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; | ||
1019 | return ret; | ||
1020 | } | ||
1021 | |||
1022 | /** | ||
1023 | * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode | ||
1024 | * @ioc: per adapter object | ||
1025 | * @arg - user space buffer containing ioctl content | ||
1026 | */ | ||
1027 | static long | ||
1028 | _ctl_getiocinfo(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1029 | { | ||
1030 | struct mpt2_ioctl_iocinfo karg; | ||
1031 | |||
1032 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1033 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1034 | __FILE__, __LINE__, __func__); | ||
1035 | return -EFAULT; | ||
1036 | } | ||
1037 | |||
1038 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, | ||
1039 | __func__)); | ||
1040 | |||
1041 | memset(&karg, 0 , sizeof(karg)); | ||
1042 | if (ioc->is_warpdrive) | ||
1043 | karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2_SSS6200; | ||
1044 | else | ||
1045 | karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2; | ||
1046 | if (ioc->pfacts) | ||
1047 | karg.port_number = ioc->pfacts[0].PortNumber; | ||
1048 | karg.hw_rev = ioc->pdev->revision; | ||
1049 | karg.pci_id = ioc->pdev->device; | ||
1050 | karg.subsystem_device = ioc->pdev->subsystem_device; | ||
1051 | karg.subsystem_vendor = ioc->pdev->subsystem_vendor; | ||
1052 | karg.pci_information.u.bits.bus = ioc->pdev->bus->number; | ||
1053 | karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn); | ||
1054 | karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn); | ||
1055 | karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus); | ||
1056 | karg.firmware_version = ioc->facts.FWVersion.Word; | ||
1057 | strcpy(karg.driver_version, MPT2SAS_DRIVER_NAME); | ||
1058 | strcat(karg.driver_version, "-"); | ||
1059 | strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION); | ||
1060 | karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); | ||
1061 | |||
1062 | if (copy_to_user(arg, &karg, sizeof(karg))) { | ||
1063 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1064 | __FILE__, __LINE__, __func__); | ||
1065 | return -EFAULT; | ||
1066 | } | ||
1067 | return 0; | ||
1068 | } | ||
1069 | |||
1070 | /** | ||
1071 | * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode | ||
1072 | * @ioc: per adapter object | ||
1073 | * @arg - user space buffer containing ioctl content | ||
1074 | */ | ||
1075 | static long | ||
1076 | _ctl_eventquery(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1077 | { | ||
1078 | struct mpt2_ioctl_eventquery karg; | ||
1079 | |||
1080 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1081 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1082 | __FILE__, __LINE__, __func__); | ||
1083 | return -EFAULT; | ||
1084 | } | ||
1085 | |||
1086 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, | ||
1087 | __func__)); | ||
1088 | |||
1089 | karg.event_entries = MPT2SAS_CTL_EVENT_LOG_SIZE; | ||
1090 | memcpy(karg.event_types, ioc->event_type, | ||
1091 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32)); | ||
1092 | |||
1093 | if (copy_to_user(arg, &karg, sizeof(karg))) { | ||
1094 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1095 | __FILE__, __LINE__, __func__); | ||
1096 | return -EFAULT; | ||
1097 | } | ||
1098 | return 0; | ||
1099 | } | ||
1100 | |||
1101 | /** | ||
1102 | * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode | ||
1103 | * @ioc: per adapter object | ||
1104 | * @arg - user space buffer containing ioctl content | ||
1105 | */ | ||
1106 | static long | ||
1107 | _ctl_eventenable(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1108 | { | ||
1109 | struct mpt2_ioctl_eventenable karg; | ||
1110 | |||
1111 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1112 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1113 | __FILE__, __LINE__, __func__); | ||
1114 | return -EFAULT; | ||
1115 | } | ||
1116 | |||
1117 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, | ||
1118 | __func__)); | ||
1119 | |||
1120 | if (ioc->event_log) | ||
1121 | return 0; | ||
1122 | memcpy(ioc->event_type, karg.event_types, | ||
1123 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32)); | ||
1124 | mpt2sas_base_validate_event_type(ioc, ioc->event_type); | ||
1125 | |||
1126 | /* initialize event_log */ | ||
1127 | ioc->event_context = 0; | ||
1128 | ioc->aen_event_read_flag = 0; | ||
1129 | ioc->event_log = kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE, | ||
1130 | sizeof(struct MPT2_IOCTL_EVENTS), GFP_KERNEL); | ||
1131 | if (!ioc->event_log) { | ||
1132 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1133 | __FILE__, __LINE__, __func__); | ||
1134 | return -ENOMEM; | ||
1135 | } | ||
1136 | return 0; | ||
1137 | } | ||
1138 | |||
1139 | /** | ||
1140 | * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode | ||
1141 | * @ioc: per adapter object | ||
1142 | * @arg - user space buffer containing ioctl content | ||
1143 | */ | ||
1144 | static long | ||
1145 | _ctl_eventreport(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1146 | { | ||
1147 | struct mpt2_ioctl_eventreport karg; | ||
1148 | u32 number_bytes, max_events, max; | ||
1149 | struct mpt2_ioctl_eventreport __user *uarg = arg; | ||
1150 | |||
1151 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1152 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1153 | __FILE__, __LINE__, __func__); | ||
1154 | return -EFAULT; | ||
1155 | } | ||
1156 | |||
1157 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, | ||
1158 | __func__)); | ||
1159 | |||
1160 | number_bytes = karg.hdr.max_data_size - | ||
1161 | sizeof(struct mpt2_ioctl_header); | ||
1162 | max_events = number_bytes/sizeof(struct MPT2_IOCTL_EVENTS); | ||
1163 | max = min_t(u32, MPT2SAS_CTL_EVENT_LOG_SIZE, max_events); | ||
1164 | |||
1165 | /* If fewer than 1 event is requested, there must have | ||
1166 | * been some type of error. | ||
1167 | */ | ||
1168 | if (!max || !ioc->event_log) | ||
1169 | return -ENODATA; | ||
1170 | |||
1171 | number_bytes = max * sizeof(struct MPT2_IOCTL_EVENTS); | ||
1172 | if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) { | ||
1173 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1174 | __FILE__, __LINE__, __func__); | ||
1175 | return -EFAULT; | ||
1176 | } | ||
1177 | |||
1178 | /* reset flag so SIGIO can restart */ | ||
1179 | ioc->aen_event_read_flag = 0; | ||
1180 | return 0; | ||
1181 | } | ||
1182 | |||
1183 | /** | ||
1184 | * _ctl_do_reset - main handler for MPT2HARDRESET opcode | ||
1185 | * @ioc: per adapter object | ||
1186 | * @arg - user space buffer containing ioctl content | ||
1187 | */ | ||
1188 | static long | ||
1189 | _ctl_do_reset(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1190 | { | ||
1191 | struct mpt2_ioctl_diag_reset karg; | ||
1192 | int retval; | ||
1193 | |||
1194 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1195 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1196 | __FILE__, __LINE__, __func__); | ||
1197 | return -EFAULT; | ||
1198 | } | ||
1199 | |||
1200 | if (ioc->shost_recovery || ioc->pci_error_recovery || | ||
1201 | ioc->is_driver_loading) | ||
1202 | return -EAGAIN; | ||
1203 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, | ||
1204 | __func__)); | ||
1205 | |||
1206 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
1207 | FORCE_BIG_HAMMER); | ||
1208 | printk(MPT2SAS_INFO_FMT "host reset: %s\n", | ||
1209 | ioc->name, ((!retval) ? "SUCCESS" : "FAILED")); | ||
1210 | return 0; | ||
1211 | } | ||
1212 | |||
1213 | /** | ||
1214 | * _ctl_btdh_search_sas_device - searching for sas device | ||
1215 | * @ioc: per adapter object | ||
1216 | * @btdh: btdh ioctl payload | ||
1217 | */ | ||
1218 | static int | ||
1219 | _ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER *ioc, | ||
1220 | struct mpt2_ioctl_btdh_mapping *btdh) | ||
1221 | { | ||
1222 | struct _sas_device *sas_device; | ||
1223 | unsigned long flags; | ||
1224 | int rc = 0; | ||
1225 | |||
1226 | if (list_empty(&ioc->sas_device_list)) | ||
1227 | return rc; | ||
1228 | |||
1229 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1230 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | ||
1231 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && | ||
1232 | btdh->handle == sas_device->handle) { | ||
1233 | btdh->bus = sas_device->channel; | ||
1234 | btdh->id = sas_device->id; | ||
1235 | rc = 1; | ||
1236 | goto out; | ||
1237 | } else if (btdh->bus == sas_device->channel && btdh->id == | ||
1238 | sas_device->id && btdh->handle == 0xFFFF) { | ||
1239 | btdh->handle = sas_device->handle; | ||
1240 | rc = 1; | ||
1241 | goto out; | ||
1242 | } | ||
1243 | } | ||
1244 | out: | ||
1245 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1246 | return rc; | ||
1247 | } | ||
1248 | |||
1249 | /** | ||
1250 | * _ctl_btdh_search_raid_device - searching for raid device | ||
1251 | * @ioc: per adapter object | ||
1252 | * @btdh: btdh ioctl payload | ||
1253 | */ | ||
1254 | static int | ||
1255 | _ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER *ioc, | ||
1256 | struct mpt2_ioctl_btdh_mapping *btdh) | ||
1257 | { | ||
1258 | struct _raid_device *raid_device; | ||
1259 | unsigned long flags; | ||
1260 | int rc = 0; | ||
1261 | |||
1262 | if (list_empty(&ioc->raid_device_list)) | ||
1263 | return rc; | ||
1264 | |||
1265 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1266 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | ||
1267 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && | ||
1268 | btdh->handle == raid_device->handle) { | ||
1269 | btdh->bus = raid_device->channel; | ||
1270 | btdh->id = raid_device->id; | ||
1271 | rc = 1; | ||
1272 | goto out; | ||
1273 | } else if (btdh->bus == raid_device->channel && btdh->id == | ||
1274 | raid_device->id && btdh->handle == 0xFFFF) { | ||
1275 | btdh->handle = raid_device->handle; | ||
1276 | rc = 1; | ||
1277 | goto out; | ||
1278 | } | ||
1279 | } | ||
1280 | out: | ||
1281 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1282 | return rc; | ||
1283 | } | ||
1284 | |||
1285 | /** | ||
1286 | * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode | ||
1287 | * @ioc: per adapter object | ||
1288 | * @arg - user space buffer containing ioctl content | ||
1289 | */ | ||
1290 | static long | ||
1291 | _ctl_btdh_mapping(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1292 | { | ||
1293 | struct mpt2_ioctl_btdh_mapping karg; | ||
1294 | int rc; | ||
1295 | |||
1296 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1297 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1298 | __FILE__, __LINE__, __func__); | ||
1299 | return -EFAULT; | ||
1300 | } | ||
1301 | |||
1302 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1303 | __func__)); | ||
1304 | |||
1305 | rc = _ctl_btdh_search_sas_device(ioc, &karg); | ||
1306 | if (!rc) | ||
1307 | _ctl_btdh_search_raid_device(ioc, &karg); | ||
1308 | |||
1309 | if (copy_to_user(arg, &karg, sizeof(karg))) { | ||
1310 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1311 | __FILE__, __LINE__, __func__); | ||
1312 | return -EFAULT; | ||
1313 | } | ||
1314 | return 0; | ||
1315 | } | ||
1316 | |||
1317 | /** | ||
1318 | * _ctl_diag_capability - return diag buffer capability | ||
1319 | * @ioc: per adapter object | ||
1320 | * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED | ||
1321 | * | ||
1322 | * returns 1 when diag buffer support is enabled in firmware | ||
1323 | */ | ||
1324 | static u8 | ||
1325 | _ctl_diag_capability(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type) | ||
1326 | { | ||
1327 | u8 rc = 0; | ||
1328 | |||
1329 | switch (buffer_type) { | ||
1330 | case MPI2_DIAG_BUF_TYPE_TRACE: | ||
1331 | if (ioc->facts.IOCCapabilities & | ||
1332 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) | ||
1333 | rc = 1; | ||
1334 | break; | ||
1335 | case MPI2_DIAG_BUF_TYPE_SNAPSHOT: | ||
1336 | if (ioc->facts.IOCCapabilities & | ||
1337 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) | ||
1338 | rc = 1; | ||
1339 | break; | ||
1340 | case MPI2_DIAG_BUF_TYPE_EXTENDED: | ||
1341 | if (ioc->facts.IOCCapabilities & | ||
1342 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) | ||
1343 | rc = 1; | ||
1344 | } | ||
1345 | |||
1346 | return rc; | ||
1347 | } | ||
1348 | |||
1349 | /** | ||
1350 | * _ctl_diag_register_2 - wrapper for registering diag buffer support | ||
1351 | * @ioc: per adapter object | ||
1352 | * @diag_register: the diag_register struct passed in from user space | ||
1353 | * | ||
1354 | */ | ||
1355 | static long | ||
1356 | _ctl_diag_register_2(struct MPT2SAS_ADAPTER *ioc, | ||
1357 | struct mpt2_diag_register *diag_register) | ||
1358 | { | ||
1359 | int rc, i; | ||
1360 | void *request_data = NULL; | ||
1361 | dma_addr_t request_data_dma; | ||
1362 | u32 request_data_sz = 0; | ||
1363 | Mpi2DiagBufferPostRequest_t *mpi_request; | ||
1364 | Mpi2DiagBufferPostReply_t *mpi_reply; | ||
1365 | u8 buffer_type; | ||
1366 | unsigned long timeleft; | ||
1367 | u16 smid; | ||
1368 | u16 ioc_status; | ||
1369 | u8 issue_reset = 0; | ||
1370 | |||
1371 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1372 | __func__)); | ||
1373 | |||
1374 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { | ||
1375 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", | ||
1376 | ioc->name, __func__); | ||
1377 | rc = -EAGAIN; | ||
1378 | goto out; | ||
1379 | } | ||
1380 | |||
1381 | buffer_type = diag_register->buffer_type; | ||
1382 | if (!_ctl_diag_capability(ioc, buffer_type)) { | ||
1383 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " | ||
1384 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1385 | return -EPERM; | ||
1386 | } | ||
1387 | |||
1388 | if (ioc->diag_buffer_status[buffer_type] & | ||
1389 | MPT2_DIAG_BUFFER_IS_REGISTERED) { | ||
1390 | printk(MPT2SAS_ERR_FMT "%s: already has a registered " | ||
1391 | "buffer for buffer_type(0x%02x)\n", ioc->name, __func__, | ||
1392 | buffer_type); | ||
1393 | return -EINVAL; | ||
1394 | } | ||
1395 | |||
1396 | if (diag_register->requested_buffer_size % 4) { | ||
1397 | printk(MPT2SAS_ERR_FMT "%s: the requested_buffer_size " | ||
1398 | "is not 4 byte aligned\n", ioc->name, __func__); | ||
1399 | return -EINVAL; | ||
1400 | } | ||
1401 | |||
1402 | smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx); | ||
1403 | if (!smid) { | ||
1404 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
1405 | ioc->name, __func__); | ||
1406 | rc = -EAGAIN; | ||
1407 | goto out; | ||
1408 | } | ||
1409 | |||
1410 | rc = 0; | ||
1411 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; | ||
1412 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); | ||
1413 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
1414 | ioc->ctl_cmds.smid = smid; | ||
1415 | |||
1416 | request_data = ioc->diag_buffer[buffer_type]; | ||
1417 | request_data_sz = diag_register->requested_buffer_size; | ||
1418 | ioc->unique_id[buffer_type] = diag_register->unique_id; | ||
1419 | ioc->diag_buffer_status[buffer_type] = 0; | ||
1420 | memcpy(ioc->product_specific[buffer_type], | ||
1421 | diag_register->product_specific, MPT2_PRODUCT_SPECIFIC_DWORDS); | ||
1422 | ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags; | ||
1423 | |||
1424 | if (request_data) { | ||
1425 | request_data_dma = ioc->diag_buffer_dma[buffer_type]; | ||
1426 | if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) { | ||
1427 | pci_free_consistent(ioc->pdev, | ||
1428 | ioc->diag_buffer_sz[buffer_type], | ||
1429 | request_data, request_data_dma); | ||
1430 | request_data = NULL; | ||
1431 | } | ||
1432 | } | ||
1433 | |||
1434 | if (request_data == NULL) { | ||
1435 | ioc->diag_buffer_sz[buffer_type] = 0; | ||
1436 | ioc->diag_buffer_dma[buffer_type] = 0; | ||
1437 | request_data = pci_alloc_consistent( | ||
1438 | ioc->pdev, request_data_sz, &request_data_dma); | ||
1439 | if (request_data == NULL) { | ||
1440 | printk(MPT2SAS_ERR_FMT "%s: failed allocating memory" | ||
1441 | " for diag buffers, requested size(%d)\n", | ||
1442 | ioc->name, __func__, request_data_sz); | ||
1443 | mpt2sas_base_free_smid(ioc, smid); | ||
1444 | return -ENOMEM; | ||
1445 | } | ||
1446 | ioc->diag_buffer[buffer_type] = request_data; | ||
1447 | ioc->diag_buffer_sz[buffer_type] = request_data_sz; | ||
1448 | ioc->diag_buffer_dma[buffer_type] = request_data_dma; | ||
1449 | } | ||
1450 | |||
1451 | mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST; | ||
1452 | mpi_request->BufferType = diag_register->buffer_type; | ||
1453 | mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags); | ||
1454 | mpi_request->BufferAddress = cpu_to_le64(request_data_dma); | ||
1455 | mpi_request->BufferLength = cpu_to_le32(request_data_sz); | ||
1456 | mpi_request->VF_ID = 0; /* TODO */ | ||
1457 | mpi_request->VP_ID = 0; | ||
1458 | |||
1459 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: diag_buffer(0x%p), " | ||
1460 | "dma(0x%llx), sz(%d)\n", ioc->name, __func__, request_data, | ||
1461 | (unsigned long long)request_data_dma, | ||
1462 | le32_to_cpu(mpi_request->BufferLength))); | ||
1463 | |||
1464 | for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++) | ||
1465 | mpi_request->ProductSpecific[i] = | ||
1466 | cpu_to_le32(ioc->product_specific[buffer_type][i]); | ||
1467 | |||
1468 | init_completion(&ioc->ctl_cmds.done); | ||
1469 | mpt2sas_base_put_smid_default(ioc, smid); | ||
1470 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, | ||
1471 | MPT2_IOCTL_DEFAULT_TIMEOUT*HZ); | ||
1472 | |||
1473 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { | ||
1474 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, | ||
1475 | __func__); | ||
1476 | _debug_dump_mf(mpi_request, | ||
1477 | sizeof(Mpi2DiagBufferPostRequest_t)/4); | ||
1478 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) | ||
1479 | issue_reset = 1; | ||
1480 | goto issue_host_reset; | ||
1481 | } | ||
1482 | |||
1483 | /* process the completed Reply Message Frame */ | ||
1484 | if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) { | ||
1485 | printk(MPT2SAS_ERR_FMT "%s: no reply message\n", | ||
1486 | ioc->name, __func__); | ||
1487 | rc = -EFAULT; | ||
1488 | goto out; | ||
1489 | } | ||
1490 | |||
1491 | mpi_reply = ioc->ctl_cmds.reply; | ||
1492 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
1493 | |||
1494 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | ||
1495 | ioc->diag_buffer_status[buffer_type] |= | ||
1496 | MPT2_DIAG_BUFFER_IS_REGISTERED; | ||
1497 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: success\n", | ||
1498 | ioc->name, __func__)); | ||
1499 | } else { | ||
1500 | printk(MPT2SAS_INFO_FMT "%s: ioc_status(0x%04x) " | ||
1501 | "log_info(0x%08x)\n", ioc->name, __func__, | ||
1502 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
1503 | rc = -EFAULT; | ||
1504 | } | ||
1505 | |||
1506 | issue_host_reset: | ||
1507 | if (issue_reset) | ||
1508 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
1509 | FORCE_BIG_HAMMER); | ||
1510 | |||
1511 | out: | ||
1512 | |||
1513 | if (rc && request_data) | ||
1514 | pci_free_consistent(ioc->pdev, request_data_sz, | ||
1515 | request_data, request_data_dma); | ||
1516 | |||
1517 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; | ||
1518 | return rc; | ||
1519 | } | ||
1520 | |||
1521 | /** | ||
1522 | * mpt2sas_enable_diag_buffer - enabling diag_buffers support driver load time | ||
1523 | * @ioc: per adapter object | ||
1524 | * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1 | ||
1525 | * | ||
1526 | * This is called when command line option diag_buffer_enable is enabled | ||
1527 | * at driver load time. | ||
1528 | */ | ||
1529 | void | ||
1530 | mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc, u8 bits_to_register) | ||
1531 | { | ||
1532 | struct mpt2_diag_register diag_register; | ||
1533 | |||
1534 | memset(&diag_register, 0, sizeof(struct mpt2_diag_register)); | ||
1535 | |||
1536 | if (bits_to_register & 1) { | ||
1537 | printk(MPT2SAS_INFO_FMT "registering trace buffer support\n", | ||
1538 | ioc->name); | ||
1539 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE; | ||
1540 | /* register for 1MB buffers */ | ||
1541 | diag_register.requested_buffer_size = (1024 * 1024); | ||
1542 | diag_register.unique_id = 0x7075900; | ||
1543 | _ctl_diag_register_2(ioc, &diag_register); | ||
1544 | } | ||
1545 | |||
1546 | if (bits_to_register & 2) { | ||
1547 | printk(MPT2SAS_INFO_FMT "registering snapshot buffer support\n", | ||
1548 | ioc->name); | ||
1549 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT; | ||
1550 | /* register for 2MB buffers */ | ||
1551 | diag_register.requested_buffer_size = 2 * (1024 * 1024); | ||
1552 | diag_register.unique_id = 0x7075901; | ||
1553 | _ctl_diag_register_2(ioc, &diag_register); | ||
1554 | } | ||
1555 | |||
1556 | if (bits_to_register & 4) { | ||
1557 | printk(MPT2SAS_INFO_FMT "registering extended buffer support\n", | ||
1558 | ioc->name); | ||
1559 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED; | ||
1560 | /* register for 2MB buffers */ | ||
1561 | diag_register.requested_buffer_size = 2 * (1024 * 1024); | ||
1562 | diag_register.unique_id = 0x7075901; | ||
1563 | _ctl_diag_register_2(ioc, &diag_register); | ||
1564 | } | ||
1565 | } | ||
1566 | |||
1567 | /** | ||
1568 | * _ctl_diag_register - application register with driver | ||
1569 | * @ioc: per adapter object | ||
1570 | * @arg - user space buffer containing ioctl content | ||
1571 | * | ||
1572 | * This will allow the driver to setup any required buffers that will be | ||
1573 | * needed by firmware to communicate with the driver. | ||
1574 | */ | ||
1575 | static long | ||
1576 | _ctl_diag_register(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1577 | { | ||
1578 | struct mpt2_diag_register karg; | ||
1579 | long rc; | ||
1580 | |||
1581 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1582 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1583 | __FILE__, __LINE__, __func__); | ||
1584 | return -EFAULT; | ||
1585 | } | ||
1586 | |||
1587 | rc = _ctl_diag_register_2(ioc, &karg); | ||
1588 | return rc; | ||
1589 | } | ||
1590 | |||
1591 | /** | ||
1592 | * _ctl_diag_unregister - application unregister with driver | ||
1593 | * @ioc: per adapter object | ||
1594 | * @arg - user space buffer containing ioctl content | ||
1595 | * | ||
1596 | * This will allow the driver to cleanup any memory allocated for diag | ||
1597 | * messages and to free up any resources. | ||
1598 | */ | ||
1599 | static long | ||
1600 | _ctl_diag_unregister(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1601 | { | ||
1602 | struct mpt2_diag_unregister karg; | ||
1603 | void *request_data; | ||
1604 | dma_addr_t request_data_dma; | ||
1605 | u32 request_data_sz; | ||
1606 | u8 buffer_type; | ||
1607 | |||
1608 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1609 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1610 | __FILE__, __LINE__, __func__); | ||
1611 | return -EFAULT; | ||
1612 | } | ||
1613 | |||
1614 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1615 | __func__)); | ||
1616 | |||
1617 | buffer_type = karg.unique_id & 0x000000ff; | ||
1618 | if (!_ctl_diag_capability(ioc, buffer_type)) { | ||
1619 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " | ||
1620 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1621 | return -EPERM; | ||
1622 | } | ||
1623 | |||
1624 | if ((ioc->diag_buffer_status[buffer_type] & | ||
1625 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { | ||
1626 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not " | ||
1627 | "registered\n", ioc->name, __func__, buffer_type); | ||
1628 | return -EINVAL; | ||
1629 | } | ||
1630 | if ((ioc->diag_buffer_status[buffer_type] & | ||
1631 | MPT2_DIAG_BUFFER_IS_RELEASED) == 0) { | ||
1632 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) has not been " | ||
1633 | "released\n", ioc->name, __func__, buffer_type); | ||
1634 | return -EINVAL; | ||
1635 | } | ||
1636 | |||
1637 | if (karg.unique_id != ioc->unique_id[buffer_type]) { | ||
1638 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " | ||
1639 | "registered\n", ioc->name, __func__, karg.unique_id); | ||
1640 | return -EINVAL; | ||
1641 | } | ||
1642 | |||
1643 | request_data = ioc->diag_buffer[buffer_type]; | ||
1644 | if (!request_data) { | ||
1645 | printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for " | ||
1646 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1647 | return -ENOMEM; | ||
1648 | } | ||
1649 | |||
1650 | request_data_sz = ioc->diag_buffer_sz[buffer_type]; | ||
1651 | request_data_dma = ioc->diag_buffer_dma[buffer_type]; | ||
1652 | pci_free_consistent(ioc->pdev, request_data_sz, | ||
1653 | request_data, request_data_dma); | ||
1654 | ioc->diag_buffer[buffer_type] = NULL; | ||
1655 | ioc->diag_buffer_status[buffer_type] = 0; | ||
1656 | return 0; | ||
1657 | } | ||
1658 | |||
1659 | /** | ||
1660 | * _ctl_diag_query - query relevant info associated with diag buffers | ||
1661 | * @ioc: per adapter object | ||
1662 | * @arg - user space buffer containing ioctl content | ||
1663 | * | ||
1664 | * The application will send only buffer_type and unique_id. Driver will | ||
1665 | * inspect unique_id first, if valid, fill in all the info. If unique_id is | ||
1666 | * 0x00, the driver will return info specified by Buffer Type. | ||
1667 | */ | ||
1668 | static long | ||
1669 | _ctl_diag_query(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1670 | { | ||
1671 | struct mpt2_diag_query karg; | ||
1672 | void *request_data; | ||
1673 | int i; | ||
1674 | u8 buffer_type; | ||
1675 | |||
1676 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1677 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1678 | __FILE__, __LINE__, __func__); | ||
1679 | return -EFAULT; | ||
1680 | } | ||
1681 | |||
1682 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1683 | __func__)); | ||
1684 | |||
1685 | karg.application_flags = 0; | ||
1686 | buffer_type = karg.buffer_type; | ||
1687 | |||
1688 | if (!_ctl_diag_capability(ioc, buffer_type)) { | ||
1689 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " | ||
1690 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1691 | return -EPERM; | ||
1692 | } | ||
1693 | |||
1694 | if ((ioc->diag_buffer_status[buffer_type] & | ||
1695 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { | ||
1696 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not " | ||
1697 | "registered\n", ioc->name, __func__, buffer_type); | ||
1698 | return -EINVAL; | ||
1699 | } | ||
1700 | |||
1701 | if (karg.unique_id & 0xffffff00) { | ||
1702 | if (karg.unique_id != ioc->unique_id[buffer_type]) { | ||
1703 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " | ||
1704 | "registered\n", ioc->name, __func__, | ||
1705 | karg.unique_id); | ||
1706 | return -EINVAL; | ||
1707 | } | ||
1708 | } | ||
1709 | |||
1710 | request_data = ioc->diag_buffer[buffer_type]; | ||
1711 | if (!request_data) { | ||
1712 | printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for " | ||
1713 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1714 | return -ENOMEM; | ||
1715 | } | ||
1716 | |||
1717 | if (ioc->diag_buffer_status[buffer_type] & MPT2_DIAG_BUFFER_IS_RELEASED) | ||
1718 | karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED | | ||
1719 | MPT2_APP_FLAGS_BUFFER_VALID); | ||
1720 | else | ||
1721 | karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED | | ||
1722 | MPT2_APP_FLAGS_BUFFER_VALID | | ||
1723 | MPT2_APP_FLAGS_FW_BUFFER_ACCESS); | ||
1724 | |||
1725 | for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++) | ||
1726 | karg.product_specific[i] = | ||
1727 | ioc->product_specific[buffer_type][i]; | ||
1728 | |||
1729 | karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type]; | ||
1730 | karg.driver_added_buffer_size = 0; | ||
1731 | karg.unique_id = ioc->unique_id[buffer_type]; | ||
1732 | karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type]; | ||
1733 | |||
1734 | if (copy_to_user(arg, &karg, sizeof(struct mpt2_diag_query))) { | ||
1735 | printk(MPT2SAS_ERR_FMT "%s: unable to write mpt2_diag_query " | ||
1736 | "data @ %p\n", ioc->name, __func__, arg); | ||
1737 | return -EFAULT; | ||
1738 | } | ||
1739 | return 0; | ||
1740 | } | ||
1741 | |||
1742 | /** | ||
1743 | * _ctl_send_release - Diag Release Message | ||
1744 | * @ioc: per adapter object | ||
1745 | * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED | ||
1746 | * @issue_reset - specifies whether host reset is required. | ||
1747 | * | ||
1748 | */ | ||
1749 | static int | ||
1750 | _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, u8 *issue_reset) | ||
1751 | { | ||
1752 | Mpi2DiagReleaseRequest_t *mpi_request; | ||
1753 | Mpi2DiagReleaseReply_t *mpi_reply; | ||
1754 | u16 smid; | ||
1755 | u16 ioc_status; | ||
1756 | u32 ioc_state; | ||
1757 | int rc; | ||
1758 | unsigned long timeleft; | ||
1759 | |||
1760 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1761 | __func__)); | ||
1762 | |||
1763 | rc = 0; | ||
1764 | *issue_reset = 0; | ||
1765 | |||
1766 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
1767 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
1768 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
1769 | "skipping due to FAULT state\n", ioc->name, | ||
1770 | __func__)); | ||
1771 | rc = -EAGAIN; | ||
1772 | goto out; | ||
1773 | } | ||
1774 | |||
1775 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { | ||
1776 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", | ||
1777 | ioc->name, __func__); | ||
1778 | rc = -EAGAIN; | ||
1779 | goto out; | ||
1780 | } | ||
1781 | |||
1782 | smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx); | ||
1783 | if (!smid) { | ||
1784 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
1785 | ioc->name, __func__); | ||
1786 | rc = -EAGAIN; | ||
1787 | goto out; | ||
1788 | } | ||
1789 | |||
1790 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; | ||
1791 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); | ||
1792 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
1793 | ioc->ctl_cmds.smid = smid; | ||
1794 | |||
1795 | mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE; | ||
1796 | mpi_request->BufferType = buffer_type; | ||
1797 | mpi_request->VF_ID = 0; /* TODO */ | ||
1798 | mpi_request->VP_ID = 0; | ||
1799 | |||
1800 | init_completion(&ioc->ctl_cmds.done); | ||
1801 | mpt2sas_base_put_smid_default(ioc, smid); | ||
1802 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, | ||
1803 | MPT2_IOCTL_DEFAULT_TIMEOUT*HZ); | ||
1804 | |||
1805 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { | ||
1806 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, | ||
1807 | __func__); | ||
1808 | _debug_dump_mf(mpi_request, | ||
1809 | sizeof(Mpi2DiagReleaseRequest_t)/4); | ||
1810 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) | ||
1811 | *issue_reset = 1; | ||
1812 | rc = -EFAULT; | ||
1813 | goto out; | ||
1814 | } | ||
1815 | |||
1816 | /* process the completed Reply Message Frame */ | ||
1817 | if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) { | ||
1818 | printk(MPT2SAS_ERR_FMT "%s: no reply message\n", | ||
1819 | ioc->name, __func__); | ||
1820 | rc = -EFAULT; | ||
1821 | goto out; | ||
1822 | } | ||
1823 | |||
1824 | mpi_reply = ioc->ctl_cmds.reply; | ||
1825 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
1826 | |||
1827 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | ||
1828 | ioc->diag_buffer_status[buffer_type] |= | ||
1829 | MPT2_DIAG_BUFFER_IS_RELEASED; | ||
1830 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: success\n", | ||
1831 | ioc->name, __func__)); | ||
1832 | } else { | ||
1833 | printk(MPT2SAS_INFO_FMT "%s: ioc_status(0x%04x) " | ||
1834 | "log_info(0x%08x)\n", ioc->name, __func__, | ||
1835 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
1836 | rc = -EFAULT; | ||
1837 | } | ||
1838 | |||
1839 | out: | ||
1840 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; | ||
1841 | return rc; | ||
1842 | } | ||
1843 | |||
1844 | /** | ||
1845 | * _ctl_diag_release - request to send Diag Release Message to firmware | ||
1846 | * @arg - user space buffer containing ioctl content | ||
1847 | * | ||
1848 | * This allows ownership of the specified buffer to returned to the driver, | ||
1849 | * allowing an application to read the buffer without fear that firmware is | ||
1850 | * overwritting information in the buffer. | ||
1851 | */ | ||
1852 | static long | ||
1853 | _ctl_diag_release(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1854 | { | ||
1855 | struct mpt2_diag_release karg; | ||
1856 | void *request_data; | ||
1857 | int rc; | ||
1858 | u8 buffer_type; | ||
1859 | u8 issue_reset = 0; | ||
1860 | |||
1861 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1862 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1863 | __FILE__, __LINE__, __func__); | ||
1864 | return -EFAULT; | ||
1865 | } | ||
1866 | |||
1867 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1868 | __func__)); | ||
1869 | |||
1870 | buffer_type = karg.unique_id & 0x000000ff; | ||
1871 | if (!_ctl_diag_capability(ioc, buffer_type)) { | ||
1872 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " | ||
1873 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1874 | return -EPERM; | ||
1875 | } | ||
1876 | |||
1877 | if ((ioc->diag_buffer_status[buffer_type] & | ||
1878 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { | ||
1879 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not " | ||
1880 | "registered\n", ioc->name, __func__, buffer_type); | ||
1881 | return -EINVAL; | ||
1882 | } | ||
1883 | |||
1884 | if (karg.unique_id != ioc->unique_id[buffer_type]) { | ||
1885 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " | ||
1886 | "registered\n", ioc->name, __func__, karg.unique_id); | ||
1887 | return -EINVAL; | ||
1888 | } | ||
1889 | |||
1890 | if (ioc->diag_buffer_status[buffer_type] & | ||
1891 | MPT2_DIAG_BUFFER_IS_RELEASED) { | ||
1892 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) " | ||
1893 | "is already released\n", ioc->name, __func__, | ||
1894 | buffer_type); | ||
1895 | return 0; | ||
1896 | } | ||
1897 | |||
1898 | request_data = ioc->diag_buffer[buffer_type]; | ||
1899 | |||
1900 | if (!request_data) { | ||
1901 | printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for " | ||
1902 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1903 | return -ENOMEM; | ||
1904 | } | ||
1905 | |||
1906 | /* buffers were released by due to host reset */ | ||
1907 | if ((ioc->diag_buffer_status[buffer_type] & | ||
1908 | MPT2_DIAG_BUFFER_IS_DIAG_RESET)) { | ||
1909 | ioc->diag_buffer_status[buffer_type] |= | ||
1910 | MPT2_DIAG_BUFFER_IS_RELEASED; | ||
1911 | ioc->diag_buffer_status[buffer_type] &= | ||
1912 | ~MPT2_DIAG_BUFFER_IS_DIAG_RESET; | ||
1913 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) " | ||
1914 | "was released due to host reset\n", ioc->name, __func__, | ||
1915 | buffer_type); | ||
1916 | return 0; | ||
1917 | } | ||
1918 | |||
1919 | rc = _ctl_send_release(ioc, buffer_type, &issue_reset); | ||
1920 | |||
1921 | if (issue_reset) | ||
1922 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
1923 | FORCE_BIG_HAMMER); | ||
1924 | |||
1925 | return rc; | ||
1926 | } | ||
1927 | |||
1928 | /** | ||
1929 | * _ctl_diag_read_buffer - request for copy of the diag buffer | ||
1930 | * @ioc: per adapter object | ||
1931 | * @arg - user space buffer containing ioctl content | ||
1932 | */ | ||
1933 | static long | ||
1934 | _ctl_diag_read_buffer(struct MPT2SAS_ADAPTER *ioc, void __user *arg) | ||
1935 | { | ||
1936 | struct mpt2_diag_read_buffer karg; | ||
1937 | struct mpt2_diag_read_buffer __user *uarg = arg; | ||
1938 | void *request_data, *diag_data; | ||
1939 | Mpi2DiagBufferPostRequest_t *mpi_request; | ||
1940 | Mpi2DiagBufferPostReply_t *mpi_reply; | ||
1941 | int rc, i; | ||
1942 | u8 buffer_type; | ||
1943 | unsigned long timeleft, request_size, copy_size; | ||
1944 | u16 smid; | ||
1945 | u16 ioc_status; | ||
1946 | u8 issue_reset = 0; | ||
1947 | |||
1948 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
1949 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
1950 | __FILE__, __LINE__, __func__); | ||
1951 | return -EFAULT; | ||
1952 | } | ||
1953 | |||
1954 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, | ||
1955 | __func__)); | ||
1956 | |||
1957 | buffer_type = karg.unique_id & 0x000000ff; | ||
1958 | if (!_ctl_diag_capability(ioc, buffer_type)) { | ||
1959 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " | ||
1960 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1961 | return -EPERM; | ||
1962 | } | ||
1963 | |||
1964 | if (karg.unique_id != ioc->unique_id[buffer_type]) { | ||
1965 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " | ||
1966 | "registered\n", ioc->name, __func__, karg.unique_id); | ||
1967 | return -EINVAL; | ||
1968 | } | ||
1969 | |||
1970 | request_data = ioc->diag_buffer[buffer_type]; | ||
1971 | if (!request_data) { | ||
1972 | printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for " | ||
1973 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); | ||
1974 | return -ENOMEM; | ||
1975 | } | ||
1976 | |||
1977 | request_size = ioc->diag_buffer_sz[buffer_type]; | ||
1978 | |||
1979 | if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) { | ||
1980 | printk(MPT2SAS_ERR_FMT "%s: either the starting_offset " | ||
1981 | "or bytes_to_read are not 4 byte aligned\n", ioc->name, | ||
1982 | __func__); | ||
1983 | return -EINVAL; | ||
1984 | } | ||
1985 | |||
1986 | if (karg.starting_offset > request_size) | ||
1987 | return -EINVAL; | ||
1988 | |||
1989 | diag_data = (void *)(request_data + karg.starting_offset); | ||
1990 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: diag_buffer(%p), " | ||
1991 | "offset(%d), sz(%d)\n", ioc->name, __func__, | ||
1992 | diag_data, karg.starting_offset, karg.bytes_to_read)); | ||
1993 | |||
1994 | /* Truncate data on requests that are too large */ | ||
1995 | if ((diag_data + karg.bytes_to_read < diag_data) || | ||
1996 | (diag_data + karg.bytes_to_read > request_data + request_size)) | ||
1997 | copy_size = request_size - karg.starting_offset; | ||
1998 | else | ||
1999 | copy_size = karg.bytes_to_read; | ||
2000 | |||
2001 | if (copy_to_user((void __user *)uarg->diagnostic_data, | ||
2002 | diag_data, copy_size)) { | ||
2003 | printk(MPT2SAS_ERR_FMT "%s: Unable to write " | ||
2004 | "mpt_diag_read_buffer_t data @ %p\n", ioc->name, | ||
2005 | __func__, diag_data); | ||
2006 | return -EFAULT; | ||
2007 | } | ||
2008 | |||
2009 | if ((karg.flags & MPT2_FLAGS_REREGISTER) == 0) | ||
2010 | return 0; | ||
2011 | |||
2012 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: Reregister " | ||
2013 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type)); | ||
2014 | if ((ioc->diag_buffer_status[buffer_type] & | ||
2015 | MPT2_DIAG_BUFFER_IS_RELEASED) == 0) { | ||
2016 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
2017 | "buffer_type(0x%02x) is still registered\n", ioc->name, | ||
2018 | __func__, buffer_type)); | ||
2019 | return 0; | ||
2020 | } | ||
2021 | /* Get a free request frame and save the message context. | ||
2022 | */ | ||
2023 | |||
2024 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { | ||
2025 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", | ||
2026 | ioc->name, __func__); | ||
2027 | rc = -EAGAIN; | ||
2028 | goto out; | ||
2029 | } | ||
2030 | |||
2031 | smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx); | ||
2032 | if (!smid) { | ||
2033 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
2034 | ioc->name, __func__); | ||
2035 | rc = -EAGAIN; | ||
2036 | goto out; | ||
2037 | } | ||
2038 | |||
2039 | rc = 0; | ||
2040 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; | ||
2041 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); | ||
2042 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
2043 | ioc->ctl_cmds.smid = smid; | ||
2044 | |||
2045 | mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST; | ||
2046 | mpi_request->BufferType = buffer_type; | ||
2047 | mpi_request->BufferLength = | ||
2048 | cpu_to_le32(ioc->diag_buffer_sz[buffer_type]); | ||
2049 | mpi_request->BufferAddress = | ||
2050 | cpu_to_le64(ioc->diag_buffer_dma[buffer_type]); | ||
2051 | for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++) | ||
2052 | mpi_request->ProductSpecific[i] = | ||
2053 | cpu_to_le32(ioc->product_specific[buffer_type][i]); | ||
2054 | mpi_request->VF_ID = 0; /* TODO */ | ||
2055 | mpi_request->VP_ID = 0; | ||
2056 | |||
2057 | init_completion(&ioc->ctl_cmds.done); | ||
2058 | mpt2sas_base_put_smid_default(ioc, smid); | ||
2059 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, | ||
2060 | MPT2_IOCTL_DEFAULT_TIMEOUT*HZ); | ||
2061 | |||
2062 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { | ||
2063 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, | ||
2064 | __func__); | ||
2065 | _debug_dump_mf(mpi_request, | ||
2066 | sizeof(Mpi2DiagBufferPostRequest_t)/4); | ||
2067 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) | ||
2068 | issue_reset = 1; | ||
2069 | goto issue_host_reset; | ||
2070 | } | ||
2071 | |||
2072 | /* process the completed Reply Message Frame */ | ||
2073 | if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) { | ||
2074 | printk(MPT2SAS_ERR_FMT "%s: no reply message\n", | ||
2075 | ioc->name, __func__); | ||
2076 | rc = -EFAULT; | ||
2077 | goto out; | ||
2078 | } | ||
2079 | |||
2080 | mpi_reply = ioc->ctl_cmds.reply; | ||
2081 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
2082 | |||
2083 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | ||
2084 | ioc->diag_buffer_status[buffer_type] |= | ||
2085 | MPT2_DIAG_BUFFER_IS_REGISTERED; | ||
2086 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: success\n", | ||
2087 | ioc->name, __func__)); | ||
2088 | } else { | ||
2089 | printk(MPT2SAS_INFO_FMT "%s: ioc_status(0x%04x) " | ||
2090 | "log_info(0x%08x)\n", ioc->name, __func__, | ||
2091 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
2092 | rc = -EFAULT; | ||
2093 | } | ||
2094 | |||
2095 | issue_host_reset: | ||
2096 | if (issue_reset) | ||
2097 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
2098 | FORCE_BIG_HAMMER); | ||
2099 | |||
2100 | out: | ||
2101 | |||
2102 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; | ||
2103 | return rc; | ||
2104 | } | ||
2105 | |||
2106 | |||
2107 | #ifdef CONFIG_COMPAT | ||
2108 | /** | ||
2109 | * _ctl_compat_mpt_command - convert 32bit pointers to 64bit. | ||
2110 | * @ioc: per adapter object | ||
2111 | * @cmd - ioctl opcode | ||
2112 | * @arg - (struct mpt2_ioctl_command32) | ||
2113 | * | ||
2114 | * MPT2COMMAND32 - Handle 32bit applications running on 64bit os. | ||
2115 | */ | ||
2116 | static long | ||
2117 | _ctl_compat_mpt_command(struct MPT2SAS_ADAPTER *ioc, unsigned cmd, | ||
2118 | void __user *arg) | ||
2119 | { | ||
2120 | struct mpt2_ioctl_command32 karg32; | ||
2121 | struct mpt2_ioctl_command32 __user *uarg; | ||
2122 | struct mpt2_ioctl_command karg; | ||
2123 | |||
2124 | if (_IOC_SIZE(cmd) != sizeof(struct mpt2_ioctl_command32)) | ||
2125 | return -EINVAL; | ||
2126 | |||
2127 | uarg = (struct mpt2_ioctl_command32 __user *) arg; | ||
2128 | |||
2129 | if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) { | ||
2130 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
2131 | __FILE__, __LINE__, __func__); | ||
2132 | return -EFAULT; | ||
2133 | } | ||
2134 | |||
2135 | memset(&karg, 0, sizeof(struct mpt2_ioctl_command)); | ||
2136 | karg.hdr.ioc_number = karg32.hdr.ioc_number; | ||
2137 | karg.hdr.port_number = karg32.hdr.port_number; | ||
2138 | karg.hdr.max_data_size = karg32.hdr.max_data_size; | ||
2139 | karg.timeout = karg32.timeout; | ||
2140 | karg.max_reply_bytes = karg32.max_reply_bytes; | ||
2141 | karg.data_in_size = karg32.data_in_size; | ||
2142 | karg.data_out_size = karg32.data_out_size; | ||
2143 | karg.max_sense_bytes = karg32.max_sense_bytes; | ||
2144 | karg.data_sge_offset = karg32.data_sge_offset; | ||
2145 | karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr); | ||
2146 | karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr); | ||
2147 | karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr); | ||
2148 | karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr); | ||
2149 | return _ctl_do_mpt_command(ioc, karg, &uarg->mf); | ||
2150 | } | ||
2151 | #endif | ||
2152 | |||
2153 | /** | ||
2154 | * _ctl_ioctl_main - main ioctl entry point | ||
2155 | * @file - (struct file) | ||
2156 | * @cmd - ioctl opcode | ||
2157 | * @arg - | ||
2158 | * compat - handles 32 bit applications in 64bit os | ||
2159 | */ | ||
2160 | static long | ||
2161 | _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg, | ||
2162 | u8 compat) | ||
2163 | { | ||
2164 | struct MPT2SAS_ADAPTER *ioc; | ||
2165 | struct mpt2_ioctl_header ioctl_header; | ||
2166 | enum block_state state; | ||
2167 | long ret = -EINVAL; | ||
2168 | |||
2169 | /* get IOCTL header */ | ||
2170 | if (copy_from_user(&ioctl_header, (char __user *)arg, | ||
2171 | sizeof(struct mpt2_ioctl_header))) { | ||
2172 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
2173 | __FILE__, __LINE__, __func__); | ||
2174 | return -EFAULT; | ||
2175 | } | ||
2176 | |||
2177 | if (_ctl_verify_adapter(ioctl_header.ioc_number, &ioc) == -1 || !ioc) | ||
2178 | return -ENODEV; | ||
2179 | /* pci_access_mutex lock acquired by ioctl path */ | ||
2180 | mutex_lock(&ioc->pci_access_mutex); | ||
2181 | if (ioc->shost_recovery || ioc->pci_error_recovery || | ||
2182 | ioc->is_driver_loading || ioc->remove_host) { | ||
2183 | ret = -EAGAIN; | ||
2184 | goto out_unlock_pciaccess; | ||
2185 | } | ||
2186 | |||
2187 | state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; | ||
2188 | if (state == NON_BLOCKING) { | ||
2189 | if (!mutex_trylock(&ioc->ctl_cmds.mutex)) { | ||
2190 | ret = -EAGAIN; | ||
2191 | goto out_unlock_pciaccess; | ||
2192 | } | ||
2193 | } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) { | ||
2194 | ret = -ERESTARTSYS; | ||
2195 | goto out_unlock_pciaccess; | ||
2196 | } | ||
2197 | |||
2198 | switch (cmd) { | ||
2199 | case MPT2IOCINFO: | ||
2200 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo)) | ||
2201 | ret = _ctl_getiocinfo(ioc, arg); | ||
2202 | break; | ||
2203 | #ifdef CONFIG_COMPAT | ||
2204 | case MPT2COMMAND32: | ||
2205 | #endif | ||
2206 | case MPT2COMMAND: | ||
2207 | { | ||
2208 | struct mpt2_ioctl_command __user *uarg; | ||
2209 | struct mpt2_ioctl_command karg; | ||
2210 | #ifdef CONFIG_COMPAT | ||
2211 | if (compat) { | ||
2212 | ret = _ctl_compat_mpt_command(ioc, cmd, arg); | ||
2213 | break; | ||
2214 | } | ||
2215 | #endif | ||
2216 | if (copy_from_user(&karg, arg, sizeof(karg))) { | ||
2217 | printk(KERN_ERR "failure at %s:%d/%s()!\n", | ||
2218 | __FILE__, __LINE__, __func__); | ||
2219 | ret = -EFAULT; | ||
2220 | break; | ||
2221 | } | ||
2222 | |||
2223 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) { | ||
2224 | uarg = arg; | ||
2225 | ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf); | ||
2226 | } | ||
2227 | break; | ||
2228 | } | ||
2229 | case MPT2EVENTQUERY: | ||
2230 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery)) | ||
2231 | ret = _ctl_eventquery(ioc, arg); | ||
2232 | break; | ||
2233 | case MPT2EVENTENABLE: | ||
2234 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable)) | ||
2235 | ret = _ctl_eventenable(ioc, arg); | ||
2236 | break; | ||
2237 | case MPT2EVENTREPORT: | ||
2238 | ret = _ctl_eventreport(ioc, arg); | ||
2239 | break; | ||
2240 | case MPT2HARDRESET: | ||
2241 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset)) | ||
2242 | ret = _ctl_do_reset(ioc, arg); | ||
2243 | break; | ||
2244 | case MPT2BTDHMAPPING: | ||
2245 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping)) | ||
2246 | ret = _ctl_btdh_mapping(ioc, arg); | ||
2247 | break; | ||
2248 | case MPT2DIAGREGISTER: | ||
2249 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register)) | ||
2250 | ret = _ctl_diag_register(ioc, arg); | ||
2251 | break; | ||
2252 | case MPT2DIAGUNREGISTER: | ||
2253 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister)) | ||
2254 | ret = _ctl_diag_unregister(ioc, arg); | ||
2255 | break; | ||
2256 | case MPT2DIAGQUERY: | ||
2257 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query)) | ||
2258 | ret = _ctl_diag_query(ioc, arg); | ||
2259 | break; | ||
2260 | case MPT2DIAGRELEASE: | ||
2261 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release)) | ||
2262 | ret = _ctl_diag_release(ioc, arg); | ||
2263 | break; | ||
2264 | case MPT2DIAGREADBUFFER: | ||
2265 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer)) | ||
2266 | ret = _ctl_diag_read_buffer(ioc, arg); | ||
2267 | break; | ||
2268 | default: | ||
2269 | |||
2270 | dctlprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2271 | "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd)); | ||
2272 | break; | ||
2273 | } | ||
2274 | |||
2275 | mutex_unlock(&ioc->ctl_cmds.mutex); | ||
2276 | out_unlock_pciaccess: | ||
2277 | mutex_unlock(&ioc->pci_access_mutex); | ||
2278 | return ret; | ||
2279 | } | ||
2280 | |||
2281 | /** | ||
2282 | * _ctl_ioctl - main ioctl entry point (unlocked) | ||
2283 | * @file - (struct file) | ||
2284 | * @cmd - ioctl opcode | ||
2285 | * @arg - | ||
2286 | */ | ||
2287 | static long | ||
2288 | _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
2289 | { | ||
2290 | long ret; | ||
2291 | |||
2292 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0); | ||
2293 | return ret; | ||
2294 | } | ||
2295 | #ifdef CONFIG_COMPAT | ||
2296 | /** | ||
2297 | * _ctl_ioctl_compat - main ioctl entry point (compat) | ||
2298 | * @file - | ||
2299 | * @cmd - | ||
2300 | * @arg - | ||
2301 | * | ||
2302 | * This routine handles 32 bit applications in 64bit os. | ||
2303 | */ | ||
2304 | static long | ||
2305 | _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg) | ||
2306 | { | ||
2307 | long ret; | ||
2308 | |||
2309 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1); | ||
2310 | return ret; | ||
2311 | } | ||
2312 | #endif | ||
2313 | |||
2314 | /* scsi host attributes */ | ||
2315 | |||
2316 | /** | ||
2317 | * _ctl_version_fw_show - firmware version | ||
2318 | * @cdev - pointer to embedded class device | ||
2319 | * @buf - the buffer returned | ||
2320 | * | ||
2321 | * A sysfs 'read-only' shost attribute. | ||
2322 | */ | ||
2323 | static ssize_t | ||
2324 | _ctl_version_fw_show(struct device *cdev, struct device_attribute *attr, | ||
2325 | char *buf) | ||
2326 | { | ||
2327 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2328 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2329 | |||
2330 | return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", | ||
2331 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, | ||
2332 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, | ||
2333 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, | ||
2334 | ioc->facts.FWVersion.Word & 0x000000FF); | ||
2335 | } | ||
2336 | static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL); | ||
2337 | |||
2338 | /** | ||
2339 | * _ctl_version_bios_show - bios version | ||
2340 | * @cdev - pointer to embedded class device | ||
2341 | * @buf - the buffer returned | ||
2342 | * | ||
2343 | * A sysfs 'read-only' shost attribute. | ||
2344 | */ | ||
2345 | static ssize_t | ||
2346 | _ctl_version_bios_show(struct device *cdev, struct device_attribute *attr, | ||
2347 | char *buf) | ||
2348 | { | ||
2349 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2350 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2351 | |||
2352 | u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion); | ||
2353 | |||
2354 | return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", | ||
2355 | (version & 0xFF000000) >> 24, | ||
2356 | (version & 0x00FF0000) >> 16, | ||
2357 | (version & 0x0000FF00) >> 8, | ||
2358 | version & 0x000000FF); | ||
2359 | } | ||
2360 | static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL); | ||
2361 | |||
2362 | /** | ||
2363 | * _ctl_version_mpi_show - MPI (message passing interface) version | ||
2364 | * @cdev - pointer to embedded class device | ||
2365 | * @buf - the buffer returned | ||
2366 | * | ||
2367 | * A sysfs 'read-only' shost attribute. | ||
2368 | */ | ||
2369 | static ssize_t | ||
2370 | _ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr, | ||
2371 | char *buf) | ||
2372 | { | ||
2373 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2374 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2375 | |||
2376 | return snprintf(buf, PAGE_SIZE, "%03x.%02x\n", | ||
2377 | ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8); | ||
2378 | } | ||
2379 | static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL); | ||
2380 | |||
2381 | /** | ||
2382 | * _ctl_version_product_show - product name | ||
2383 | * @cdev - pointer to embedded class device | ||
2384 | * @buf - the buffer returned | ||
2385 | * | ||
2386 | * A sysfs 'read-only' shost attribute. | ||
2387 | */ | ||
2388 | static ssize_t | ||
2389 | _ctl_version_product_show(struct device *cdev, struct device_attribute *attr, | ||
2390 | char *buf) | ||
2391 | { | ||
2392 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2393 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2394 | |||
2395 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName); | ||
2396 | } | ||
2397 | static DEVICE_ATTR(version_product, S_IRUGO, | ||
2398 | _ctl_version_product_show, NULL); | ||
2399 | |||
2400 | /** | ||
2401 | * _ctl_version_nvdata_persistent_show - ndvata persistent version | ||
2402 | * @cdev - pointer to embedded class device | ||
2403 | * @buf - the buffer returned | ||
2404 | * | ||
2405 | * A sysfs 'read-only' shost attribute. | ||
2406 | */ | ||
2407 | static ssize_t | ||
2408 | _ctl_version_nvdata_persistent_show(struct device *cdev, | ||
2409 | struct device_attribute *attr, char *buf) | ||
2410 | { | ||
2411 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2412 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2413 | |||
2414 | return snprintf(buf, PAGE_SIZE, "%08xh\n", | ||
2415 | le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word)); | ||
2416 | } | ||
2417 | static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO, | ||
2418 | _ctl_version_nvdata_persistent_show, NULL); | ||
2419 | |||
2420 | /** | ||
2421 | * _ctl_version_nvdata_default_show - nvdata default version | ||
2422 | * @cdev - pointer to embedded class device | ||
2423 | * @buf - the buffer returned | ||
2424 | * | ||
2425 | * A sysfs 'read-only' shost attribute. | ||
2426 | */ | ||
2427 | static ssize_t | ||
2428 | _ctl_version_nvdata_default_show(struct device *cdev, | ||
2429 | struct device_attribute *attr, char *buf) | ||
2430 | { | ||
2431 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2432 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2433 | |||
2434 | return snprintf(buf, PAGE_SIZE, "%08xh\n", | ||
2435 | le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word)); | ||
2436 | } | ||
2437 | static DEVICE_ATTR(version_nvdata_default, S_IRUGO, | ||
2438 | _ctl_version_nvdata_default_show, NULL); | ||
2439 | |||
2440 | /** | ||
2441 | * _ctl_board_name_show - board name | ||
2442 | * @cdev - pointer to embedded class device | ||
2443 | * @buf - the buffer returned | ||
2444 | * | ||
2445 | * A sysfs 'read-only' shost attribute. | ||
2446 | */ | ||
2447 | static ssize_t | ||
2448 | _ctl_board_name_show(struct device *cdev, struct device_attribute *attr, | ||
2449 | char *buf) | ||
2450 | { | ||
2451 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2452 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2453 | |||
2454 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName); | ||
2455 | } | ||
2456 | static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL); | ||
2457 | |||
2458 | /** | ||
2459 | * _ctl_board_assembly_show - board assembly name | ||
2460 | * @cdev - pointer to embedded class device | ||
2461 | * @buf - the buffer returned | ||
2462 | * | ||
2463 | * A sysfs 'read-only' shost attribute. | ||
2464 | */ | ||
2465 | static ssize_t | ||
2466 | _ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr, | ||
2467 | char *buf) | ||
2468 | { | ||
2469 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2470 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2471 | |||
2472 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly); | ||
2473 | } | ||
2474 | static DEVICE_ATTR(board_assembly, S_IRUGO, | ||
2475 | _ctl_board_assembly_show, NULL); | ||
2476 | |||
2477 | /** | ||
2478 | * _ctl_board_tracer_show - board tracer number | ||
2479 | * @cdev - pointer to embedded class device | ||
2480 | * @buf - the buffer returned | ||
2481 | * | ||
2482 | * A sysfs 'read-only' shost attribute. | ||
2483 | */ | ||
2484 | static ssize_t | ||
2485 | _ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr, | ||
2486 | char *buf) | ||
2487 | { | ||
2488 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2489 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2490 | |||
2491 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber); | ||
2492 | } | ||
2493 | static DEVICE_ATTR(board_tracer, S_IRUGO, | ||
2494 | _ctl_board_tracer_show, NULL); | ||
2495 | |||
2496 | /** | ||
2497 | * _ctl_io_delay_show - io missing delay | ||
2498 | * @cdev - pointer to embedded class device | ||
2499 | * @buf - the buffer returned | ||
2500 | * | ||
2501 | * This is for firmware implemention for deboucing device | ||
2502 | * removal events. | ||
2503 | * | ||
2504 | * A sysfs 'read-only' shost attribute. | ||
2505 | */ | ||
2506 | static ssize_t | ||
2507 | _ctl_io_delay_show(struct device *cdev, struct device_attribute *attr, | ||
2508 | char *buf) | ||
2509 | { | ||
2510 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2511 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2512 | |||
2513 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay); | ||
2514 | } | ||
2515 | static DEVICE_ATTR(io_delay, S_IRUGO, | ||
2516 | _ctl_io_delay_show, NULL); | ||
2517 | |||
2518 | /** | ||
2519 | * _ctl_device_delay_show - device missing delay | ||
2520 | * @cdev - pointer to embedded class device | ||
2521 | * @buf - the buffer returned | ||
2522 | * | ||
2523 | * This is for firmware implemention for deboucing device | ||
2524 | * removal events. | ||
2525 | * | ||
2526 | * A sysfs 'read-only' shost attribute. | ||
2527 | */ | ||
2528 | static ssize_t | ||
2529 | _ctl_device_delay_show(struct device *cdev, struct device_attribute *attr, | ||
2530 | char *buf) | ||
2531 | { | ||
2532 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2533 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2534 | |||
2535 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay); | ||
2536 | } | ||
2537 | static DEVICE_ATTR(device_delay, S_IRUGO, | ||
2538 | _ctl_device_delay_show, NULL); | ||
2539 | |||
2540 | /** | ||
2541 | * _ctl_fw_queue_depth_show - global credits | ||
2542 | * @cdev - pointer to embedded class device | ||
2543 | * @buf - the buffer returned | ||
2544 | * | ||
2545 | * This is firmware queue depth limit | ||
2546 | * | ||
2547 | * A sysfs 'read-only' shost attribute. | ||
2548 | */ | ||
2549 | static ssize_t | ||
2550 | _ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr, | ||
2551 | char *buf) | ||
2552 | { | ||
2553 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2554 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2555 | |||
2556 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit); | ||
2557 | } | ||
2558 | static DEVICE_ATTR(fw_queue_depth, S_IRUGO, | ||
2559 | _ctl_fw_queue_depth_show, NULL); | ||
2560 | |||
2561 | /** | ||
2562 | * _ctl_sas_address_show - sas address | ||
2563 | * @cdev - pointer to embedded class device | ||
2564 | * @buf - the buffer returned | ||
2565 | * | ||
2566 | * This is the controller sas address | ||
2567 | * | ||
2568 | * A sysfs 'read-only' shost attribute. | ||
2569 | */ | ||
2570 | static ssize_t | ||
2571 | _ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr, | ||
2572 | char *buf) | ||
2573 | { | ||
2574 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2575 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2576 | |||
2577 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", | ||
2578 | (unsigned long long)ioc->sas_hba.sas_address); | ||
2579 | } | ||
2580 | static DEVICE_ATTR(host_sas_address, S_IRUGO, | ||
2581 | _ctl_host_sas_address_show, NULL); | ||
2582 | |||
2583 | /** | ||
2584 | * _ctl_logging_level_show - logging level | ||
2585 | * @cdev - pointer to embedded class device | ||
2586 | * @buf - the buffer returned | ||
2587 | * | ||
2588 | * A sysfs 'read/write' shost attribute. | ||
2589 | */ | ||
2590 | static ssize_t | ||
2591 | _ctl_logging_level_show(struct device *cdev, struct device_attribute *attr, | ||
2592 | char *buf) | ||
2593 | { | ||
2594 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2595 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2596 | |||
2597 | return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level); | ||
2598 | } | ||
2599 | static ssize_t | ||
2600 | _ctl_logging_level_store(struct device *cdev, struct device_attribute *attr, | ||
2601 | const char *buf, size_t count) | ||
2602 | { | ||
2603 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2604 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2605 | int val = 0; | ||
2606 | |||
2607 | if (sscanf(buf, "%x", &val) != 1) | ||
2608 | return -EINVAL; | ||
2609 | |||
2610 | ioc->logging_level = val; | ||
2611 | printk(MPT2SAS_INFO_FMT "logging_level=%08xh\n", ioc->name, | ||
2612 | ioc->logging_level); | ||
2613 | return strlen(buf); | ||
2614 | } | ||
2615 | static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR, | ||
2616 | _ctl_logging_level_show, _ctl_logging_level_store); | ||
2617 | |||
2618 | /* device attributes */ | ||
2619 | /* | ||
2620 | * _ctl_fwfault_debug_show - show/store fwfault_debug | ||
2621 | * @cdev - pointer to embedded class device | ||
2622 | * @buf - the buffer returned | ||
2623 | * | ||
2624 | * mpt2sas_fwfault_debug is command line option | ||
2625 | * A sysfs 'read/write' shost attribute. | ||
2626 | */ | ||
2627 | static ssize_t | ||
2628 | _ctl_fwfault_debug_show(struct device *cdev, | ||
2629 | struct device_attribute *attr, char *buf) | ||
2630 | { | ||
2631 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2632 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2633 | |||
2634 | return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug); | ||
2635 | } | ||
2636 | static ssize_t | ||
2637 | _ctl_fwfault_debug_store(struct device *cdev, | ||
2638 | struct device_attribute *attr, const char *buf, size_t count) | ||
2639 | { | ||
2640 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2641 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2642 | int val = 0; | ||
2643 | |||
2644 | if (sscanf(buf, "%d", &val) != 1) | ||
2645 | return -EINVAL; | ||
2646 | |||
2647 | ioc->fwfault_debug = val; | ||
2648 | printk(MPT2SAS_INFO_FMT "fwfault_debug=%d\n", ioc->name, | ||
2649 | ioc->fwfault_debug); | ||
2650 | return strlen(buf); | ||
2651 | } | ||
2652 | static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR, | ||
2653 | _ctl_fwfault_debug_show, _ctl_fwfault_debug_store); | ||
2654 | |||
2655 | |||
2656 | /** | ||
2657 | * _ctl_ioc_reset_count_show - ioc reset count | ||
2658 | * @cdev - pointer to embedded class device | ||
2659 | * @buf - the buffer returned | ||
2660 | * | ||
2661 | * This is firmware queue depth limit | ||
2662 | * | ||
2663 | * A sysfs 'read-only' shost attribute. | ||
2664 | */ | ||
2665 | static ssize_t | ||
2666 | _ctl_ioc_reset_count_show(struct device *cdev, struct device_attribute *attr, | ||
2667 | char *buf) | ||
2668 | { | ||
2669 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2670 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2671 | |||
2672 | return snprintf(buf, PAGE_SIZE, "%08d\n", ioc->ioc_reset_count); | ||
2673 | } | ||
2674 | static DEVICE_ATTR(ioc_reset_count, S_IRUGO, | ||
2675 | _ctl_ioc_reset_count_show, NULL); | ||
2676 | |||
2677 | /** | ||
2678 | * _ctl_ioc_reply_queue_count_show - number of reply queues | ||
2679 | * @cdev - pointer to embedded class device | ||
2680 | * @buf - the buffer returned | ||
2681 | * | ||
2682 | * This is number of reply queues | ||
2683 | * | ||
2684 | * A sysfs 'read-only' shost attribute. | ||
2685 | */ | ||
2686 | static ssize_t | ||
2687 | _ctl_ioc_reply_queue_count_show(struct device *cdev, | ||
2688 | struct device_attribute *attr, char *buf) | ||
2689 | { | ||
2690 | u8 reply_queue_count; | ||
2691 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2692 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2693 | |||
2694 | if ((ioc->facts.IOCCapabilities & | ||
2695 | MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable) | ||
2696 | reply_queue_count = ioc->reply_queue_count; | ||
2697 | else | ||
2698 | reply_queue_count = 1; | ||
2699 | return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count); | ||
2700 | } | ||
2701 | static DEVICE_ATTR(reply_queue_count, S_IRUGO, | ||
2702 | _ctl_ioc_reply_queue_count_show, NULL); | ||
2703 | |||
2704 | /** | ||
2705 | * _ctl_BRM_status_show - Backup Rail Monitor Status | ||
2706 | * @cdev - pointer to embedded class device | ||
2707 | * @buf - the buffer returned | ||
2708 | * | ||
2709 | * This is number of reply queues | ||
2710 | * | ||
2711 | * A sysfs 'read-only' shost attribute. | ||
2712 | */ | ||
2713 | static ssize_t | ||
2714 | _ctl_BRM_status_show(struct device *cdev, struct device_attribute *attr, | ||
2715 | char *buf) | ||
2716 | { | ||
2717 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2718 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2719 | Mpi2IOUnitPage3_t *io_unit_pg3 = NULL; | ||
2720 | Mpi2ConfigReply_t mpi_reply; | ||
2721 | u16 backup_rail_monitor_status = 0; | ||
2722 | u16 ioc_status; | ||
2723 | int sz; | ||
2724 | ssize_t rc = 0; | ||
2725 | |||
2726 | if (!ioc->is_warpdrive) { | ||
2727 | printk(MPT2SAS_ERR_FMT "%s: BRM attribute is only for"\ | ||
2728 | "warpdrive\n", ioc->name, __func__); | ||
2729 | goto out; | ||
2730 | } | ||
2731 | /* pci_access_mutex lock acquired by sysfs show path */ | ||
2732 | mutex_lock(&ioc->pci_access_mutex); | ||
2733 | if (ioc->pci_error_recovery || ioc->remove_host) { | ||
2734 | mutex_unlock(&ioc->pci_access_mutex); | ||
2735 | return 0; | ||
2736 | } | ||
2737 | |||
2738 | /* allocate upto GPIOVal 36 entries */ | ||
2739 | sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36); | ||
2740 | io_unit_pg3 = kzalloc(sz, GFP_KERNEL); | ||
2741 | if (!io_unit_pg3) { | ||
2742 | printk(MPT2SAS_ERR_FMT "%s: failed allocating memory"\ | ||
2743 | "for iounit_pg3: (%d) bytes\n", ioc->name, __func__, sz); | ||
2744 | goto out; | ||
2745 | } | ||
2746 | |||
2747 | if (mpt2sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) != | ||
2748 | 0) { | ||
2749 | printk(MPT2SAS_ERR_FMT | ||
2750 | "%s: failed reading iounit_pg3\n", ioc->name, | ||
2751 | __func__); | ||
2752 | goto out; | ||
2753 | } | ||
2754 | |||
2755 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
2756 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
2757 | printk(MPT2SAS_ERR_FMT "%s: iounit_pg3 failed with"\ | ||
2758 | "ioc_status(0x%04x)\n", ioc->name, __func__, ioc_status); | ||
2759 | goto out; | ||
2760 | } | ||
2761 | |||
2762 | if (io_unit_pg3->GPIOCount < 25) { | ||
2763 | printk(MPT2SAS_ERR_FMT "%s: iounit_pg3->GPIOCount less than"\ | ||
2764 | "25 entries, detected (%d) entries\n", ioc->name, __func__, | ||
2765 | io_unit_pg3->GPIOCount); | ||
2766 | goto out; | ||
2767 | } | ||
2768 | |||
2769 | /* BRM status is in bit zero of GPIOVal[24] */ | ||
2770 | backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]); | ||
2771 | rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1)); | ||
2772 | |||
2773 | out: | ||
2774 | kfree(io_unit_pg3); | ||
2775 | mutex_unlock(&ioc->pci_access_mutex); | ||
2776 | return rc; | ||
2777 | } | ||
2778 | static DEVICE_ATTR(BRM_status, S_IRUGO, _ctl_BRM_status_show, NULL); | ||
2779 | |||
2780 | struct DIAG_BUFFER_START { | ||
2781 | __le32 Size; | ||
2782 | __le32 DiagVersion; | ||
2783 | u8 BufferType; | ||
2784 | u8 Reserved[3]; | ||
2785 | __le32 Reserved1; | ||
2786 | __le32 Reserved2; | ||
2787 | __le32 Reserved3; | ||
2788 | }; | ||
2789 | /** | ||
2790 | * _ctl_host_trace_buffer_size_show - host buffer size (trace only) | ||
2791 | * @cdev - pointer to embedded class device | ||
2792 | * @buf - the buffer returned | ||
2793 | * | ||
2794 | * A sysfs 'read-only' shost attribute. | ||
2795 | */ | ||
2796 | static ssize_t | ||
2797 | _ctl_host_trace_buffer_size_show(struct device *cdev, | ||
2798 | struct device_attribute *attr, char *buf) | ||
2799 | { | ||
2800 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2801 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2802 | u32 size = 0; | ||
2803 | struct DIAG_BUFFER_START *request_data; | ||
2804 | |||
2805 | if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) { | ||
2806 | printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not " | ||
2807 | "registered\n", ioc->name, __func__); | ||
2808 | return 0; | ||
2809 | } | ||
2810 | |||
2811 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2812 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { | ||
2813 | printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not " | ||
2814 | "registered\n", ioc->name, __func__); | ||
2815 | return 0; | ||
2816 | } | ||
2817 | |||
2818 | request_data = (struct DIAG_BUFFER_START *) | ||
2819 | ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]; | ||
2820 | if ((le32_to_cpu(request_data->DiagVersion) == 0x00000000 || | ||
2821 | le32_to_cpu(request_data->DiagVersion) == 0x01000000) && | ||
2822 | le32_to_cpu(request_data->Reserved3) == 0x4742444c) | ||
2823 | size = le32_to_cpu(request_data->Size); | ||
2824 | |||
2825 | ioc->ring_buffer_sz = size; | ||
2826 | return snprintf(buf, PAGE_SIZE, "%d\n", size); | ||
2827 | } | ||
2828 | static DEVICE_ATTR(host_trace_buffer_size, S_IRUGO, | ||
2829 | _ctl_host_trace_buffer_size_show, NULL); | ||
2830 | |||
2831 | /** | ||
2832 | * _ctl_host_trace_buffer_show - firmware ring buffer (trace only) | ||
2833 | * @cdev - pointer to embedded class device | ||
2834 | * @buf - the buffer returned | ||
2835 | * | ||
2836 | * A sysfs 'read/write' shost attribute. | ||
2837 | * | ||
2838 | * You will only be able to read 4k bytes of ring buffer at a time. | ||
2839 | * In order to read beyond 4k bytes, you will have to write out the | ||
2840 | * offset to the same attribute, it will move the pointer. | ||
2841 | */ | ||
2842 | static ssize_t | ||
2843 | _ctl_host_trace_buffer_show(struct device *cdev, struct device_attribute *attr, | ||
2844 | char *buf) | ||
2845 | { | ||
2846 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2847 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2848 | void *request_data; | ||
2849 | u32 size; | ||
2850 | |||
2851 | if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) { | ||
2852 | printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not " | ||
2853 | "registered\n", ioc->name, __func__); | ||
2854 | return 0; | ||
2855 | } | ||
2856 | |||
2857 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2858 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { | ||
2859 | printk(MPT2SAS_ERR_FMT "%s: host_trace_buffer is not " | ||
2860 | "registered\n", ioc->name, __func__); | ||
2861 | return 0; | ||
2862 | } | ||
2863 | |||
2864 | if (ioc->ring_buffer_offset > ioc->ring_buffer_sz) | ||
2865 | return 0; | ||
2866 | |||
2867 | size = ioc->ring_buffer_sz - ioc->ring_buffer_offset; | ||
2868 | size = (size > PAGE_SIZE) ? PAGE_SIZE : size; | ||
2869 | request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset; | ||
2870 | memcpy(buf, request_data, size); | ||
2871 | return size; | ||
2872 | } | ||
2873 | |||
2874 | static ssize_t | ||
2875 | _ctl_host_trace_buffer_store(struct device *cdev, struct device_attribute *attr, | ||
2876 | const char *buf, size_t count) | ||
2877 | { | ||
2878 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2879 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2880 | int val = 0; | ||
2881 | |||
2882 | if (sscanf(buf, "%d", &val) != 1) | ||
2883 | return -EINVAL; | ||
2884 | |||
2885 | ioc->ring_buffer_offset = val; | ||
2886 | return strlen(buf); | ||
2887 | } | ||
2888 | static DEVICE_ATTR(host_trace_buffer, S_IRUGO | S_IWUSR, | ||
2889 | _ctl_host_trace_buffer_show, _ctl_host_trace_buffer_store); | ||
2890 | |||
2891 | /*****************************************/ | ||
2892 | |||
2893 | /** | ||
2894 | * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only) | ||
2895 | * @cdev - pointer to embedded class device | ||
2896 | * @buf - the buffer returned | ||
2897 | * | ||
2898 | * A sysfs 'read/write' shost attribute. | ||
2899 | * | ||
2900 | * This is a mechnism to post/release host_trace_buffers | ||
2901 | */ | ||
2902 | static ssize_t | ||
2903 | _ctl_host_trace_buffer_enable_show(struct device *cdev, | ||
2904 | struct device_attribute *attr, char *buf) | ||
2905 | { | ||
2906 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2907 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2908 | |||
2909 | if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) || | ||
2910 | ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2911 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0)) | ||
2912 | return snprintf(buf, PAGE_SIZE, "off\n"); | ||
2913 | else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2914 | MPT2_DIAG_BUFFER_IS_RELEASED)) | ||
2915 | return snprintf(buf, PAGE_SIZE, "release\n"); | ||
2916 | else | ||
2917 | return snprintf(buf, PAGE_SIZE, "post\n"); | ||
2918 | } | ||
2919 | |||
2920 | static ssize_t | ||
2921 | _ctl_host_trace_buffer_enable_store(struct device *cdev, | ||
2922 | struct device_attribute *attr, const char *buf, size_t count) | ||
2923 | { | ||
2924 | struct Scsi_Host *shost = class_to_shost(cdev); | ||
2925 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2926 | char str[10] = ""; | ||
2927 | struct mpt2_diag_register diag_register; | ||
2928 | u8 issue_reset = 0; | ||
2929 | |||
2930 | if (sscanf(buf, "%9s", str) != 1) | ||
2931 | return -EINVAL; | ||
2932 | |||
2933 | if (!strcmp(str, "post")) { | ||
2934 | /* exit out if host buffers are already posted */ | ||
2935 | if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) && | ||
2936 | (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2937 | MPT2_DIAG_BUFFER_IS_REGISTERED) && | ||
2938 | ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2939 | MPT2_DIAG_BUFFER_IS_RELEASED) == 0)) | ||
2940 | goto out; | ||
2941 | memset(&diag_register, 0, sizeof(struct mpt2_diag_register)); | ||
2942 | printk(MPT2SAS_INFO_FMT "posting host trace buffers\n", | ||
2943 | ioc->name); | ||
2944 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE; | ||
2945 | diag_register.requested_buffer_size = (1024 * 1024); | ||
2946 | diag_register.unique_id = 0x7075900; | ||
2947 | ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0; | ||
2948 | _ctl_diag_register_2(ioc, &diag_register); | ||
2949 | } else if (!strcmp(str, "release")) { | ||
2950 | /* exit out if host buffers are already released */ | ||
2951 | if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) | ||
2952 | goto out; | ||
2953 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2954 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) | ||
2955 | goto out; | ||
2956 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & | ||
2957 | MPT2_DIAG_BUFFER_IS_RELEASED)) | ||
2958 | goto out; | ||
2959 | printk(MPT2SAS_INFO_FMT "releasing host trace buffer\n", | ||
2960 | ioc->name); | ||
2961 | _ctl_send_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE, &issue_reset); | ||
2962 | } | ||
2963 | |||
2964 | out: | ||
2965 | return strlen(buf); | ||
2966 | } | ||
2967 | static DEVICE_ATTR(host_trace_buffer_enable, S_IRUGO | S_IWUSR, | ||
2968 | _ctl_host_trace_buffer_enable_show, _ctl_host_trace_buffer_enable_store); | ||
2969 | |||
2970 | struct device_attribute *mpt2sas_host_attrs[] = { | ||
2971 | &dev_attr_version_fw, | ||
2972 | &dev_attr_version_bios, | ||
2973 | &dev_attr_version_mpi, | ||
2974 | &dev_attr_version_product, | ||
2975 | &dev_attr_version_nvdata_persistent, | ||
2976 | &dev_attr_version_nvdata_default, | ||
2977 | &dev_attr_board_name, | ||
2978 | &dev_attr_board_assembly, | ||
2979 | &dev_attr_board_tracer, | ||
2980 | &dev_attr_io_delay, | ||
2981 | &dev_attr_device_delay, | ||
2982 | &dev_attr_logging_level, | ||
2983 | &dev_attr_fwfault_debug, | ||
2984 | &dev_attr_fw_queue_depth, | ||
2985 | &dev_attr_host_sas_address, | ||
2986 | &dev_attr_ioc_reset_count, | ||
2987 | &dev_attr_host_trace_buffer_size, | ||
2988 | &dev_attr_host_trace_buffer, | ||
2989 | &dev_attr_host_trace_buffer_enable, | ||
2990 | &dev_attr_reply_queue_count, | ||
2991 | &dev_attr_BRM_status, | ||
2992 | NULL, | ||
2993 | }; | ||
2994 | |||
2995 | /** | ||
2996 | * _ctl_device_sas_address_show - sas address | ||
2997 | * @cdev - pointer to embedded class device | ||
2998 | * @buf - the buffer returned | ||
2999 | * | ||
3000 | * This is the sas address for the target | ||
3001 | * | ||
3002 | * A sysfs 'read-only' shost attribute. | ||
3003 | */ | ||
3004 | static ssize_t | ||
3005 | _ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr, | ||
3006 | char *buf) | ||
3007 | { | ||
3008 | struct scsi_device *sdev = to_scsi_device(dev); | ||
3009 | struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata; | ||
3010 | |||
3011 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", | ||
3012 | (unsigned long long)sas_device_priv_data->sas_target->sas_address); | ||
3013 | } | ||
3014 | static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL); | ||
3015 | |||
3016 | /** | ||
3017 | * _ctl_device_handle_show - device handle | ||
3018 | * @cdev - pointer to embedded class device | ||
3019 | * @buf - the buffer returned | ||
3020 | * | ||
3021 | * This is the firmware assigned device handle | ||
3022 | * | ||
3023 | * A sysfs 'read-only' shost attribute. | ||
3024 | */ | ||
3025 | static ssize_t | ||
3026 | _ctl_device_handle_show(struct device *dev, struct device_attribute *attr, | ||
3027 | char *buf) | ||
3028 | { | ||
3029 | struct scsi_device *sdev = to_scsi_device(dev); | ||
3030 | struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata; | ||
3031 | |||
3032 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", | ||
3033 | sas_device_priv_data->sas_target->handle); | ||
3034 | } | ||
3035 | static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL); | ||
3036 | |||
3037 | struct device_attribute *mpt2sas_dev_attrs[] = { | ||
3038 | &dev_attr_sas_address, | ||
3039 | &dev_attr_sas_device_handle, | ||
3040 | NULL, | ||
3041 | }; | ||
3042 | |||
3043 | static const struct file_operations ctl_fops = { | ||
3044 | .owner = THIS_MODULE, | ||
3045 | .unlocked_ioctl = _ctl_ioctl, | ||
3046 | .poll = _ctl_poll, | ||
3047 | .fasync = _ctl_fasync, | ||
3048 | #ifdef CONFIG_COMPAT | ||
3049 | .compat_ioctl = _ctl_ioctl_compat, | ||
3050 | #endif | ||
3051 | .llseek = noop_llseek, | ||
3052 | }; | ||
3053 | |||
3054 | static struct miscdevice ctl_dev = { | ||
3055 | .minor = MPT2SAS_MINOR, | ||
3056 | .name = MPT2SAS_DEV_NAME, | ||
3057 | .fops = &ctl_fops, | ||
3058 | }; | ||
3059 | |||
3060 | /** | ||
3061 | * mpt2sas_ctl_init - main entry point for ctl. | ||
3062 | * | ||
3063 | */ | ||
3064 | void | ||
3065 | mpt2sas_ctl_init(void) | ||
3066 | { | ||
3067 | async_queue = NULL; | ||
3068 | if (misc_register(&ctl_dev) < 0) | ||
3069 | printk(KERN_ERR "%s can't register misc device [minor=%d]\n", | ||
3070 | MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR); | ||
3071 | |||
3072 | init_waitqueue_head(&ctl_poll_wait); | ||
3073 | } | ||
3074 | |||
3075 | /** | ||
3076 | * mpt2sas_ctl_exit - exit point for ctl | ||
3077 | * | ||
3078 | */ | ||
3079 | void | ||
3080 | mpt2sas_ctl_exit(void) | ||
3081 | { | ||
3082 | struct MPT2SAS_ADAPTER *ioc; | ||
3083 | int i; | ||
3084 | |||
3085 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) { | ||
3086 | |||
3087 | /* free memory associated to diag buffers */ | ||
3088 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { | ||
3089 | if (!ioc->diag_buffer[i]) | ||
3090 | continue; | ||
3091 | pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i], | ||
3092 | ioc->diag_buffer[i], ioc->diag_buffer_dma[i]); | ||
3093 | ioc->diag_buffer[i] = NULL; | ||
3094 | ioc->diag_buffer_status[i] = 0; | ||
3095 | } | ||
3096 | |||
3097 | kfree(ioc->event_log); | ||
3098 | } | ||
3099 | misc_deregister(&ctl_dev); | ||
3100 | } | ||
3101 | |||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.h b/drivers/scsi/mpt2sas/mpt2sas_ctl.h deleted file mode 100644 index 46b2fc5b74af..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_ctl.h +++ /dev/null | |||
@@ -1,419 +0,0 @@ | |||
1 | /* | ||
2 | * Management Module Support for MPT (Message Passing Technology) based | ||
3 | * controllers | ||
4 | * | ||
5 | * This code is based on drivers/scsi/mpt2sas/mpt2_ctl.h | ||
6 | * Copyright (C) 2007-2014 LSI Corporation | ||
7 | * Copyright (C) 20013-2014 Avago Technologies | ||
8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version 2 | ||
13 | * of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * NO WARRANTY | ||
21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
25 | * solely responsible for determining the appropriateness of using and | ||
26 | * distributing the Program and assumes all risks associated with its | ||
27 | * exercise of rights under this Agreement, including but not limited to | ||
28 | * the risks and costs of program errors, damage to or loss of data, | ||
29 | * programs or equipment, and unavailability or interruption of operations. | ||
30 | |||
31 | * DISCLAIMER OF LIABILITY | ||
32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
39 | |||
40 | * You should have received a copy of the GNU General Public License | ||
41 | * along with this program; if not, write to the Free Software | ||
42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
43 | * USA. | ||
44 | */ | ||
45 | |||
46 | #ifndef MPT2SAS_CTL_H_INCLUDED | ||
47 | #define MPT2SAS_CTL_H_INCLUDED | ||
48 | |||
49 | #ifdef __KERNEL__ | ||
50 | #include <linux/miscdevice.h> | ||
51 | #endif | ||
52 | |||
53 | #define MPT2SAS_DEV_NAME "mpt2ctl" | ||
54 | #define MPT2_MAGIC_NUMBER 'L' | ||
55 | #define MPT2_IOCTL_DEFAULT_TIMEOUT (10) /* in seconds */ | ||
56 | |||
57 | /** | ||
58 | * IOCTL opcodes | ||
59 | */ | ||
60 | #define MPT2IOCINFO _IOWR(MPT2_MAGIC_NUMBER, 17, \ | ||
61 | struct mpt2_ioctl_iocinfo) | ||
62 | #define MPT2COMMAND _IOWR(MPT2_MAGIC_NUMBER, 20, \ | ||
63 | struct mpt2_ioctl_command) | ||
64 | #ifdef CONFIG_COMPAT | ||
65 | #define MPT2COMMAND32 _IOWR(MPT2_MAGIC_NUMBER, 20, \ | ||
66 | struct mpt2_ioctl_command32) | ||
67 | #endif | ||
68 | #define MPT2EVENTQUERY _IOWR(MPT2_MAGIC_NUMBER, 21, \ | ||
69 | struct mpt2_ioctl_eventquery) | ||
70 | #define MPT2EVENTENABLE _IOWR(MPT2_MAGIC_NUMBER, 22, \ | ||
71 | struct mpt2_ioctl_eventenable) | ||
72 | #define MPT2EVENTREPORT _IOWR(MPT2_MAGIC_NUMBER, 23, \ | ||
73 | struct mpt2_ioctl_eventreport) | ||
74 | #define MPT2HARDRESET _IOWR(MPT2_MAGIC_NUMBER, 24, \ | ||
75 | struct mpt2_ioctl_diag_reset) | ||
76 | #define MPT2BTDHMAPPING _IOWR(MPT2_MAGIC_NUMBER, 31, \ | ||
77 | struct mpt2_ioctl_btdh_mapping) | ||
78 | |||
79 | /* diag buffer support */ | ||
80 | #define MPT2DIAGREGISTER _IOWR(MPT2_MAGIC_NUMBER, 26, \ | ||
81 | struct mpt2_diag_register) | ||
82 | #define MPT2DIAGRELEASE _IOWR(MPT2_MAGIC_NUMBER, 27, \ | ||
83 | struct mpt2_diag_release) | ||
84 | #define MPT2DIAGUNREGISTER _IOWR(MPT2_MAGIC_NUMBER, 28, \ | ||
85 | struct mpt2_diag_unregister) | ||
86 | #define MPT2DIAGQUERY _IOWR(MPT2_MAGIC_NUMBER, 29, \ | ||
87 | struct mpt2_diag_query) | ||
88 | #define MPT2DIAGREADBUFFER _IOWR(MPT2_MAGIC_NUMBER, 30, \ | ||
89 | struct mpt2_diag_read_buffer) | ||
90 | |||
91 | /** | ||
92 | * struct mpt2_ioctl_header - main header structure | ||
93 | * @ioc_number - IOC unit number | ||
94 | * @port_number - IOC port number | ||
95 | * @max_data_size - maximum number bytes to transfer on read | ||
96 | */ | ||
97 | struct mpt2_ioctl_header { | ||
98 | uint32_t ioc_number; | ||
99 | uint32_t port_number; | ||
100 | uint32_t max_data_size; | ||
101 | }; | ||
102 | |||
103 | /** | ||
104 | * struct mpt2_ioctl_diag_reset - diagnostic reset | ||
105 | * @hdr - generic header | ||
106 | */ | ||
107 | struct mpt2_ioctl_diag_reset { | ||
108 | struct mpt2_ioctl_header hdr; | ||
109 | }; | ||
110 | |||
111 | |||
112 | /** | ||
113 | * struct mpt2_ioctl_pci_info - pci device info | ||
114 | * @device - pci device id | ||
115 | * @function - pci function id | ||
116 | * @bus - pci bus id | ||
117 | * @segment_id - pci segment id | ||
118 | */ | ||
119 | struct mpt2_ioctl_pci_info { | ||
120 | union { | ||
121 | struct { | ||
122 | uint32_t device:5; | ||
123 | uint32_t function:3; | ||
124 | uint32_t bus:24; | ||
125 | } bits; | ||
126 | uint32_t word; | ||
127 | } u; | ||
128 | uint32_t segment_id; | ||
129 | }; | ||
130 | |||
131 | |||
132 | #define MPT2_IOCTL_INTERFACE_SCSI (0x00) | ||
133 | #define MPT2_IOCTL_INTERFACE_FC (0x01) | ||
134 | #define MPT2_IOCTL_INTERFACE_FC_IP (0x02) | ||
135 | #define MPT2_IOCTL_INTERFACE_SAS (0x03) | ||
136 | #define MPT2_IOCTL_INTERFACE_SAS2 (0x04) | ||
137 | #define MPT2_IOCTL_INTERFACE_SAS2_SSS6200 (0x05) | ||
138 | #define MPT2_IOCTL_VERSION_LENGTH (32) | ||
139 | |||
140 | /** | ||
141 | * struct mpt2_ioctl_iocinfo - generic controller info | ||
142 | * @hdr - generic header | ||
143 | * @adapter_type - type of adapter (spi, fc, sas) | ||
144 | * @port_number - port number | ||
145 | * @pci_id - PCI Id | ||
146 | * @hw_rev - hardware revision | ||
147 | * @sub_system_device - PCI subsystem Device ID | ||
148 | * @sub_system_vendor - PCI subsystem Vendor ID | ||
149 | * @rsvd0 - reserved | ||
150 | * @firmware_version - firmware version | ||
151 | * @bios_version - BIOS version | ||
152 | * @driver_version - driver version - 32 ASCII characters | ||
153 | * @rsvd1 - reserved | ||
154 | * @scsi_id - scsi id of adapter 0 | ||
155 | * @rsvd2 - reserved | ||
156 | * @pci_information - pci info (2nd revision) | ||
157 | */ | ||
158 | struct mpt2_ioctl_iocinfo { | ||
159 | struct mpt2_ioctl_header hdr; | ||
160 | uint32_t adapter_type; | ||
161 | uint32_t port_number; | ||
162 | uint32_t pci_id; | ||
163 | uint32_t hw_rev; | ||
164 | uint32_t subsystem_device; | ||
165 | uint32_t subsystem_vendor; | ||
166 | uint32_t rsvd0; | ||
167 | uint32_t firmware_version; | ||
168 | uint32_t bios_version; | ||
169 | uint8_t driver_version[MPT2_IOCTL_VERSION_LENGTH]; | ||
170 | uint8_t rsvd1; | ||
171 | uint8_t scsi_id; | ||
172 | uint16_t rsvd2; | ||
173 | struct mpt2_ioctl_pci_info pci_information; | ||
174 | }; | ||
175 | |||
176 | |||
177 | /* number of event log entries */ | ||
178 | #define MPT2SAS_CTL_EVENT_LOG_SIZE (50) | ||
179 | |||
180 | /** | ||
181 | * struct mpt2_ioctl_eventquery - query event count and type | ||
182 | * @hdr - generic header | ||
183 | * @event_entries - number of events returned by get_event_report | ||
184 | * @rsvd - reserved | ||
185 | * @event_types - type of events currently being captured | ||
186 | */ | ||
187 | struct mpt2_ioctl_eventquery { | ||
188 | struct mpt2_ioctl_header hdr; | ||
189 | uint16_t event_entries; | ||
190 | uint16_t rsvd; | ||
191 | uint32_t event_types[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS]; | ||
192 | }; | ||
193 | |||
194 | /** | ||
195 | * struct mpt2_ioctl_eventenable - enable/disable event capturing | ||
196 | * @hdr - generic header | ||
197 | * @event_types - toggle off/on type of events to be captured | ||
198 | */ | ||
199 | struct mpt2_ioctl_eventenable { | ||
200 | struct mpt2_ioctl_header hdr; | ||
201 | uint32_t event_types[4]; | ||
202 | }; | ||
203 | |||
204 | #define MPT2_EVENT_DATA_SIZE (192) | ||
205 | /** | ||
206 | * struct MPT2_IOCTL_EVENTS - | ||
207 | * @event - the event that was reported | ||
208 | * @context - unique value for each event assigned by driver | ||
209 | * @data - event data returned in fw reply message | ||
210 | */ | ||
211 | struct MPT2_IOCTL_EVENTS { | ||
212 | uint32_t event; | ||
213 | uint32_t context; | ||
214 | uint8_t data[MPT2_EVENT_DATA_SIZE]; | ||
215 | }; | ||
216 | |||
217 | /** | ||
218 | * struct mpt2_ioctl_eventreport - returing event log | ||
219 | * @hdr - generic header | ||
220 | * @event_data - (see struct MPT2_IOCTL_EVENTS) | ||
221 | */ | ||
222 | struct mpt2_ioctl_eventreport { | ||
223 | struct mpt2_ioctl_header hdr; | ||
224 | struct MPT2_IOCTL_EVENTS event_data[1]; | ||
225 | }; | ||
226 | |||
227 | /** | ||
228 | * struct mpt2_ioctl_command - generic mpt firmware passthru ioctl | ||
229 | * @hdr - generic header | ||
230 | * @timeout - command timeout in seconds. (if zero then use driver default | ||
231 | * value). | ||
232 | * @reply_frame_buf_ptr - reply location | ||
233 | * @data_in_buf_ptr - destination for read | ||
234 | * @data_out_buf_ptr - data source for write | ||
235 | * @sense_data_ptr - sense data location | ||
236 | * @max_reply_bytes - maximum number of reply bytes to be sent to app. | ||
237 | * @data_in_size - number bytes for data transfer in (read) | ||
238 | * @data_out_size - number bytes for data transfer out (write) | ||
239 | * @max_sense_bytes - maximum number of bytes for auto sense buffers | ||
240 | * @data_sge_offset - offset in words from the start of the request message to | ||
241 | * the first SGL | ||
242 | * @mf[1]; | ||
243 | */ | ||
244 | struct mpt2_ioctl_command { | ||
245 | struct mpt2_ioctl_header hdr; | ||
246 | uint32_t timeout; | ||
247 | void __user *reply_frame_buf_ptr; | ||
248 | void __user *data_in_buf_ptr; | ||
249 | void __user *data_out_buf_ptr; | ||
250 | void __user *sense_data_ptr; | ||
251 | uint32_t max_reply_bytes; | ||
252 | uint32_t data_in_size; | ||
253 | uint32_t data_out_size; | ||
254 | uint32_t max_sense_bytes; | ||
255 | uint32_t data_sge_offset; | ||
256 | uint8_t mf[1]; | ||
257 | }; | ||
258 | |||
259 | #ifdef CONFIG_COMPAT | ||
260 | struct mpt2_ioctl_command32 { | ||
261 | struct mpt2_ioctl_header hdr; | ||
262 | uint32_t timeout; | ||
263 | uint32_t reply_frame_buf_ptr; | ||
264 | uint32_t data_in_buf_ptr; | ||
265 | uint32_t data_out_buf_ptr; | ||
266 | uint32_t sense_data_ptr; | ||
267 | uint32_t max_reply_bytes; | ||
268 | uint32_t data_in_size; | ||
269 | uint32_t data_out_size; | ||
270 | uint32_t max_sense_bytes; | ||
271 | uint32_t data_sge_offset; | ||
272 | uint8_t mf[1]; | ||
273 | }; | ||
274 | #endif | ||
275 | |||
276 | /** | ||
277 | * struct mpt2_ioctl_btdh_mapping - mapping info | ||
278 | * @hdr - generic header | ||
279 | * @id - target device identification number | ||
280 | * @bus - SCSI bus number that the target device exists on | ||
281 | * @handle - device handle for the target device | ||
282 | * @rsvd - reserved | ||
283 | * | ||
284 | * To obtain a bus/id the application sets | ||
285 | * handle to valid handle, and bus/id to 0xFFFF. | ||
286 | * | ||
287 | * To obtain the device handle the application sets | ||
288 | * bus/id valid value, and the handle to 0xFFFF. | ||
289 | */ | ||
290 | struct mpt2_ioctl_btdh_mapping { | ||
291 | struct mpt2_ioctl_header hdr; | ||
292 | uint32_t id; | ||
293 | uint32_t bus; | ||
294 | uint16_t handle; | ||
295 | uint16_t rsvd; | ||
296 | }; | ||
297 | |||
298 | |||
299 | /* status bits for ioc->diag_buffer_status */ | ||
300 | #define MPT2_DIAG_BUFFER_IS_REGISTERED (0x01) | ||
301 | #define MPT2_DIAG_BUFFER_IS_RELEASED (0x02) | ||
302 | #define MPT2_DIAG_BUFFER_IS_DIAG_RESET (0x04) | ||
303 | |||
304 | /* application flags for mpt2_diag_register, mpt2_diag_query */ | ||
305 | #define MPT2_APP_FLAGS_APP_OWNED (0x0001) | ||
306 | #define MPT2_APP_FLAGS_BUFFER_VALID (0x0002) | ||
307 | #define MPT2_APP_FLAGS_FW_BUFFER_ACCESS (0x0004) | ||
308 | |||
309 | /* flags for mpt2_diag_read_buffer */ | ||
310 | #define MPT2_FLAGS_REREGISTER (0x0001) | ||
311 | |||
312 | #define MPT2_PRODUCT_SPECIFIC_DWORDS 23 | ||
313 | |||
314 | /** | ||
315 | * struct mpt2_diag_register - application register with driver | ||
316 | * @hdr - generic header | ||
317 | * @reserved - | ||
318 | * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED | ||
319 | * @application_flags - misc flags | ||
320 | * @diagnostic_flags - specifies flags affecting command processing | ||
321 | * @product_specific - product specific information | ||
322 | * @requested_buffer_size - buffers size in bytes | ||
323 | * @unique_id - tag specified by application that is used to signal ownership | ||
324 | * of the buffer. | ||
325 | * | ||
326 | * This will allow the driver to setup any required buffers that will be | ||
327 | * needed by firmware to communicate with the driver. | ||
328 | */ | ||
329 | struct mpt2_diag_register { | ||
330 | struct mpt2_ioctl_header hdr; | ||
331 | uint8_t reserved; | ||
332 | uint8_t buffer_type; | ||
333 | uint16_t application_flags; | ||
334 | uint32_t diagnostic_flags; | ||
335 | uint32_t product_specific[MPT2_PRODUCT_SPECIFIC_DWORDS]; | ||
336 | uint32_t requested_buffer_size; | ||
337 | uint32_t unique_id; | ||
338 | }; | ||
339 | |||
340 | /** | ||
341 | * struct mpt2_diag_unregister - application unregister with driver | ||
342 | * @hdr - generic header | ||
343 | * @unique_id - tag uniquely identifies the buffer to be unregistered | ||
344 | * | ||
345 | * This will allow the driver to cleanup any memory allocated for diag | ||
346 | * messages and to free up any resources. | ||
347 | */ | ||
348 | struct mpt2_diag_unregister { | ||
349 | struct mpt2_ioctl_header hdr; | ||
350 | uint32_t unique_id; | ||
351 | }; | ||
352 | |||
353 | /** | ||
354 | * struct mpt2_diag_query - query relevant info associated with diag buffers | ||
355 | * @hdr - generic header | ||
356 | * @reserved - | ||
357 | * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED | ||
358 | * @application_flags - misc flags | ||
359 | * @diagnostic_flags - specifies flags affecting command processing | ||
360 | * @product_specific - product specific information | ||
361 | * @total_buffer_size - diag buffer size in bytes | ||
362 | * @driver_added_buffer_size - size of extra space appended to end of buffer | ||
363 | * @unique_id - unique id associated with this buffer. | ||
364 | * | ||
365 | * The application will send only buffer_type and unique_id. Driver will | ||
366 | * inspect unique_id first, if valid, fill in all the info. If unique_id is | ||
367 | * 0x00, the driver will return info specified by Buffer Type. | ||
368 | */ | ||
369 | struct mpt2_diag_query { | ||
370 | struct mpt2_ioctl_header hdr; | ||
371 | uint8_t reserved; | ||
372 | uint8_t buffer_type; | ||
373 | uint16_t application_flags; | ||
374 | uint32_t diagnostic_flags; | ||
375 | uint32_t product_specific[MPT2_PRODUCT_SPECIFIC_DWORDS]; | ||
376 | uint32_t total_buffer_size; | ||
377 | uint32_t driver_added_buffer_size; | ||
378 | uint32_t unique_id; | ||
379 | }; | ||
380 | |||
381 | /** | ||
382 | * struct mpt2_diag_release - request to send Diag Release Message to firmware | ||
383 | * @hdr - generic header | ||
384 | * @unique_id - tag uniquely identifies the buffer to be released | ||
385 | * | ||
386 | * This allows ownership of the specified buffer to returned to the driver, | ||
387 | * allowing an application to read the buffer without fear that firmware is | ||
388 | * overwritting information in the buffer. | ||
389 | */ | ||
390 | struct mpt2_diag_release { | ||
391 | struct mpt2_ioctl_header hdr; | ||
392 | uint32_t unique_id; | ||
393 | }; | ||
394 | |||
395 | /** | ||
396 | * struct mpt2_diag_read_buffer - request for copy of the diag buffer | ||
397 | * @hdr - generic header | ||
398 | * @status - | ||
399 | * @reserved - | ||
400 | * @flags - misc flags | ||
401 | * @starting_offset - starting offset within drivers buffer where to start | ||
402 | * reading data at into the specified application buffer | ||
403 | * @bytes_to_read - number of bytes to copy from the drivers buffer into the | ||
404 | * application buffer starting at starting_offset. | ||
405 | * @unique_id - unique id associated with this buffer. | ||
406 | * @diagnostic_data - data payload | ||
407 | */ | ||
408 | struct mpt2_diag_read_buffer { | ||
409 | struct mpt2_ioctl_header hdr; | ||
410 | uint8_t status; | ||
411 | uint8_t reserved; | ||
412 | uint16_t flags; | ||
413 | uint32_t starting_offset; | ||
414 | uint32_t bytes_to_read; | ||
415 | uint32_t unique_id; | ||
416 | uint32_t diagnostic_data[1]; | ||
417 | }; | ||
418 | |||
419 | #endif /* MPT2SAS_CTL_H_INCLUDED */ | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_debug.h b/drivers/scsi/mpt2sas/mpt2sas_debug.h deleted file mode 100644 index 277120d45648..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_debug.h +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | /* | ||
2 | * Logging Support for MPT (Message Passing Technology) based controllers | ||
3 | * | ||
4 | * This code is based on drivers/scsi/mpt2sas/mpt2_debug.c | ||
5 | * Copyright (C) 2007-2014 LSI Corporation | ||
6 | * Copyright (C) 20013-2014 Avago Technologies | ||
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version 2 | ||
12 | * of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * NO WARRANTY | ||
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
24 | * solely responsible for determining the appropriateness of using and | ||
25 | * distributing the Program and assumes all risks associated with its | ||
26 | * exercise of rights under this Agreement, including but not limited to | ||
27 | * the risks and costs of program errors, damage to or loss of data, | ||
28 | * programs or equipment, and unavailability or interruption of operations. | ||
29 | |||
30 | * DISCLAIMER OF LIABILITY | ||
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
38 | |||
39 | * You should have received a copy of the GNU General Public License | ||
40 | * along with this program; if not, write to the Free Software | ||
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
42 | * USA. | ||
43 | */ | ||
44 | |||
45 | #ifndef MPT2SAS_DEBUG_H_INCLUDED | ||
46 | #define MPT2SAS_DEBUG_H_INCLUDED | ||
47 | |||
48 | #define MPT_DEBUG 0x00000001 | ||
49 | #define MPT_DEBUG_MSG_FRAME 0x00000002 | ||
50 | #define MPT_DEBUG_SG 0x00000004 | ||
51 | #define MPT_DEBUG_EVENTS 0x00000008 | ||
52 | #define MPT_DEBUG_EVENT_WORK_TASK 0x00000010 | ||
53 | #define MPT_DEBUG_INIT 0x00000020 | ||
54 | #define MPT_DEBUG_EXIT 0x00000040 | ||
55 | #define MPT_DEBUG_FAIL 0x00000080 | ||
56 | #define MPT_DEBUG_TM 0x00000100 | ||
57 | #define MPT_DEBUG_REPLY 0x00000200 | ||
58 | #define MPT_DEBUG_HANDSHAKE 0x00000400 | ||
59 | #define MPT_DEBUG_CONFIG 0x00000800 | ||
60 | #define MPT_DEBUG_DL 0x00001000 | ||
61 | #define MPT_DEBUG_RESET 0x00002000 | ||
62 | #define MPT_DEBUG_SCSI 0x00004000 | ||
63 | #define MPT_DEBUG_IOCTL 0x00008000 | ||
64 | #define MPT_DEBUG_CSMISAS 0x00010000 | ||
65 | #define MPT_DEBUG_SAS 0x00020000 | ||
66 | #define MPT_DEBUG_TRANSPORT 0x00040000 | ||
67 | #define MPT_DEBUG_TASK_SET_FULL 0x00080000 | ||
68 | |||
69 | #define MPT_DEBUG_TARGET_MODE 0x00100000 | ||
70 | |||
71 | |||
72 | /* | ||
73 | * CONFIG_SCSI_MPT2SAS_LOGGING - enabled in Kconfig | ||
74 | */ | ||
75 | |||
76 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
77 | #define MPT_CHECK_LOGGING(IOC, CMD, BITS) \ | ||
78 | { \ | ||
79 | if (IOC->logging_level & BITS) \ | ||
80 | CMD; \ | ||
81 | } | ||
82 | #else | ||
83 | #define MPT_CHECK_LOGGING(IOC, CMD, BITS) | ||
84 | #endif /* CONFIG_SCSI_MPT2SAS_LOGGING */ | ||
85 | |||
86 | |||
87 | /* | ||
88 | * debug macros | ||
89 | */ | ||
90 | |||
91 | #define dprintk(IOC, CMD) \ | ||
92 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG) | ||
93 | |||
94 | #define dsgprintk(IOC, CMD) \ | ||
95 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SG) | ||
96 | |||
97 | #define devtprintk(IOC, CMD) \ | ||
98 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_EVENTS) | ||
99 | |||
100 | #define dewtprintk(IOC, CMD) \ | ||
101 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_EVENT_WORK_TASK) | ||
102 | |||
103 | #define dinitprintk(IOC, CMD) \ | ||
104 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_INIT) | ||
105 | |||
106 | #define dexitprintk(IOC, CMD) \ | ||
107 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_EXIT) | ||
108 | |||
109 | #define dfailprintk(IOC, CMD) \ | ||
110 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_FAIL) | ||
111 | |||
112 | #define dtmprintk(IOC, CMD) \ | ||
113 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_TM) | ||
114 | |||
115 | #define dreplyprintk(IOC, CMD) \ | ||
116 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_REPLY) | ||
117 | |||
118 | #define dhsprintk(IOC, CMD) \ | ||
119 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_HANDSHAKE) | ||
120 | |||
121 | #define dcprintk(IOC, CMD) \ | ||
122 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_CONFIG) | ||
123 | |||
124 | #define ddlprintk(IOC, CMD) \ | ||
125 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_DL) | ||
126 | |||
127 | #define drsprintk(IOC, CMD) \ | ||
128 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_RESET) | ||
129 | |||
130 | #define dsprintk(IOC, CMD) \ | ||
131 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SCSI) | ||
132 | |||
133 | #define dctlprintk(IOC, CMD) \ | ||
134 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_IOCTL) | ||
135 | |||
136 | #define dcsmisasprintk(IOC, CMD) \ | ||
137 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_CSMISAS) | ||
138 | |||
139 | #define dsasprintk(IOC, CMD) \ | ||
140 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SAS) | ||
141 | |||
142 | #define dsastransport(IOC, CMD) \ | ||
143 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SAS_WIDE) | ||
144 | |||
145 | #define dmfprintk(IOC, CMD) \ | ||
146 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_MSG_FRAME) | ||
147 | |||
148 | #define dtsfprintk(IOC, CMD) \ | ||
149 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_TASK_SET_FULL) | ||
150 | |||
151 | #define dtransportprintk(IOC, CMD) \ | ||
152 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_TRANSPORT) | ||
153 | |||
154 | #define dTMprintk(IOC, CMD) \ | ||
155 | MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_TARGET_MODE) | ||
156 | |||
157 | /* inline functions for dumping debug data*/ | ||
158 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
159 | /** | ||
160 | * _debug_dump_mf - print message frame contents | ||
161 | * @mpi_request: pointer to message frame | ||
162 | * @sz: number of dwords | ||
163 | */ | ||
164 | static inline void | ||
165 | _debug_dump_mf(void *mpi_request, int sz) | ||
166 | { | ||
167 | int i; | ||
168 | __le32 *mfp = (__le32 *)mpi_request; | ||
169 | |||
170 | printk(KERN_INFO "mf:\n\t"); | ||
171 | for (i = 0; i < sz; i++) { | ||
172 | if (i && ((i % 8) == 0)) | ||
173 | printk("\n\t"); | ||
174 | printk("%08x ", le32_to_cpu(mfp[i])); | ||
175 | } | ||
176 | printk("\n"); | ||
177 | } | ||
178 | #else | ||
179 | #define _debug_dump_mf(mpi_request, sz) | ||
180 | #endif /* CONFIG_SCSI_MPT2SAS_LOGGING */ | ||
181 | |||
182 | #endif /* MPT2SAS_DEBUG_H_INCLUDED */ | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c deleted file mode 100644 index 0ad09b2bff9c..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c +++ /dev/null | |||
@@ -1,8855 +0,0 @@ | |||
1 | /* | ||
2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers | ||
3 | * | ||
4 | * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c | ||
5 | * Copyright (C) 2007-2014 LSI Corporation | ||
6 | * Copyright (C) 20013-2014 Avago Technologies | ||
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version 2 | ||
12 | * of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * NO WARRANTY | ||
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
24 | * solely responsible for determining the appropriateness of using and | ||
25 | * distributing the Program and assumes all risks associated with its | ||
26 | * exercise of rights under this Agreement, including but not limited to | ||
27 | * the risks and costs of program errors, damage to or loss of data, | ||
28 | * programs or equipment, and unavailability or interruption of operations. | ||
29 | |||
30 | * DISCLAIMER OF LIABILITY | ||
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
38 | |||
39 | * You should have received a copy of the GNU General Public License | ||
40 | * along with this program; if not, write to the Free Software | ||
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
42 | * USA. | ||
43 | */ | ||
44 | |||
45 | #include <linux/module.h> | ||
46 | #include <linux/kernel.h> | ||
47 | #include <linux/init.h> | ||
48 | #include <linux/errno.h> | ||
49 | #include <linux/blkdev.h> | ||
50 | #include <linux/sched.h> | ||
51 | #include <linux/workqueue.h> | ||
52 | #include <linux/delay.h> | ||
53 | #include <linux/pci.h> | ||
54 | #include <linux/interrupt.h> | ||
55 | #include <linux/aer.h> | ||
56 | #include <linux/raid_class.h> | ||
57 | #include <linux/slab.h> | ||
58 | |||
59 | #include <asm/unaligned.h> | ||
60 | |||
61 | #include "mpt2sas_base.h" | ||
62 | |||
63 | MODULE_AUTHOR(MPT2SAS_AUTHOR); | ||
64 | MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION); | ||
65 | MODULE_LICENSE("GPL"); | ||
66 | MODULE_VERSION(MPT2SAS_DRIVER_VERSION); | ||
67 | |||
68 | #define RAID_CHANNEL 1 | ||
69 | |||
70 | /* forward proto's */ | ||
71 | static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, | ||
72 | struct _sas_node *sas_expander); | ||
73 | static void _firmware_event_work(struct work_struct *work); | ||
74 | |||
75 | static u8 _scsih_check_for_pending_tm(struct MPT2SAS_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(mpt2sas_ioc_list); | ||
82 | /* global ioc lock for list operations */ | ||
83 | DEFINE_SPINLOCK(gioc_lock); | ||
84 | /* local parameters */ | ||
85 | static u8 scsi_io_cb_idx = -1; | ||
86 | static u8 tm_cb_idx = -1; | ||
87 | static u8 ctl_cb_idx = -1; | ||
88 | static u8 base_cb_idx = -1; | ||
89 | static u8 port_enable_cb_idx = -1; | ||
90 | static u8 transport_cb_idx = -1; | ||
91 | static u8 scsih_cb_idx = -1; | ||
92 | static u8 config_cb_idx = -1; | ||
93 | static int mpt_ids; | ||
94 | |||
95 | static u8 tm_tr_cb_idx = -1 ; | ||
96 | static u8 tm_tr_volume_cb_idx = -1 ; | ||
97 | static u8 tm_sas_control_cb_idx = -1; | ||
98 | |||
99 | /* command line options */ | ||
100 | static u32 logging_level; | ||
101 | MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info " | ||
102 | "(default=0)"); | ||
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 | static int missing_delay[2] = {-1, -1}; | ||
109 | module_param_array(missing_delay, int, NULL, 0); | ||
110 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); | ||
111 | |||
112 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | ||
113 | #define MPT2SAS_MAX_LUN (16895) | ||
114 | static int max_lun = MPT2SAS_MAX_LUN; | ||
115 | module_param(max_lun, int, 0); | ||
116 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); | ||
117 | |||
118 | /* diag_buffer_enable is bitwise | ||
119 | * bit 0 set = TRACE | ||
120 | * bit 1 set = SNAPSHOT | ||
121 | * bit 2 set = EXTENDED | ||
122 | * | ||
123 | * Either bit can be set, or both | ||
124 | */ | ||
125 | static int diag_buffer_enable = -1; | ||
126 | module_param(diag_buffer_enable, int, 0); | ||
127 | MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers " | ||
128 | "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); | ||
129 | |||
130 | static int disable_discovery = -1; | ||
131 | module_param(disable_discovery, int, 0); | ||
132 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); | ||
133 | |||
134 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ | ||
135 | static int prot_mask = 0; | ||
136 | module_param(prot_mask, int, 0); | ||
137 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); | ||
138 | |||
139 | /** | ||
140 | * struct sense_info - common structure for obtaining sense keys | ||
141 | * @skey: sense key | ||
142 | * @asc: additional sense code | ||
143 | * @ascq: additional sense code qualifier | ||
144 | */ | ||
145 | struct sense_info { | ||
146 | u8 skey; | ||
147 | u8 asc; | ||
148 | u8 ascq; | ||
149 | }; | ||
150 | |||
151 | |||
152 | #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC) | ||
153 | #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD) | ||
154 | #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) | ||
155 | /** | ||
156 | * struct fw_event_work - firmware event struct | ||
157 | * @list: link list framework | ||
158 | * @work: work object (ioc->fault_reset_work_q) | ||
159 | * @cancel_pending_work: flag set during reset handling | ||
160 | * @ioc: per adapter object | ||
161 | * @device_handle: device handle | ||
162 | * @VF_ID: virtual function id | ||
163 | * @VP_ID: virtual port id | ||
164 | * @ignore: flag meaning this event has been marked to ignore | ||
165 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h | ||
166 | * @event_data: reply event data payload follows | ||
167 | * | ||
168 | * This object stored on ioc->fw_event_list. | ||
169 | */ | ||
170 | struct fw_event_work { | ||
171 | struct list_head list; | ||
172 | u8 cancel_pending_work; | ||
173 | struct delayed_work delayed_work; | ||
174 | struct MPT2SAS_ADAPTER *ioc; | ||
175 | u16 device_handle; | ||
176 | u8 VF_ID; | ||
177 | u8 VP_ID; | ||
178 | u8 ignore; | ||
179 | u16 event; | ||
180 | struct kref refcount; | ||
181 | char event_data[0] __aligned(4); | ||
182 | }; | ||
183 | |||
184 | static void fw_event_work_free(struct kref *r) | ||
185 | { | ||
186 | kfree(container_of(r, struct fw_event_work, refcount)); | ||
187 | } | ||
188 | |||
189 | static void fw_event_work_get(struct fw_event_work *fw_work) | ||
190 | { | ||
191 | kref_get(&fw_work->refcount); | ||
192 | } | ||
193 | |||
194 | static void fw_event_work_put(struct fw_event_work *fw_work) | ||
195 | { | ||
196 | kref_put(&fw_work->refcount, fw_event_work_free); | ||
197 | } | ||
198 | |||
199 | static struct fw_event_work *alloc_fw_event_work(int len) | ||
200 | { | ||
201 | struct fw_event_work *fw_event; | ||
202 | |||
203 | fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC); | ||
204 | if (!fw_event) | ||
205 | return NULL; | ||
206 | |||
207 | kref_init(&fw_event->refcount); | ||
208 | return fw_event; | ||
209 | } | ||
210 | |||
211 | /* raid transport support */ | ||
212 | static struct raid_template *mpt2sas_raid_template; | ||
213 | |||
214 | /** | ||
215 | * struct _scsi_io_transfer - scsi io transfer | ||
216 | * @handle: sas device handle (assigned by firmware) | ||
217 | * @is_raid: flag set for hidden raid components | ||
218 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, | ||
219 | * @data_length: data transfer length | ||
220 | * @data_dma: dma pointer to data | ||
221 | * @sense: sense data | ||
222 | * @lun: lun number | ||
223 | * @cdb_length: cdb length | ||
224 | * @cdb: cdb contents | ||
225 | * @timeout: timeout for this command | ||
226 | * @VF_ID: virtual function id | ||
227 | * @VP_ID: virtual port id | ||
228 | * @valid_reply: flag set for reply message | ||
229 | * @sense_length: sense length | ||
230 | * @ioc_status: ioc status | ||
231 | * @scsi_state: scsi state | ||
232 | * @scsi_status: scsi staus | ||
233 | * @log_info: log information | ||
234 | * @transfer_length: data length transfer when there is a reply message | ||
235 | * | ||
236 | * Used for sending internal scsi commands to devices within this module. | ||
237 | * Refer to _scsi_send_scsi_io(). | ||
238 | */ | ||
239 | struct _scsi_io_transfer { | ||
240 | u16 handle; | ||
241 | u8 is_raid; | ||
242 | enum dma_data_direction dir; | ||
243 | u32 data_length; | ||
244 | dma_addr_t data_dma; | ||
245 | u8 sense[SCSI_SENSE_BUFFERSIZE]; | ||
246 | u32 lun; | ||
247 | u8 cdb_length; | ||
248 | u8 cdb[32]; | ||
249 | u8 timeout; | ||
250 | u8 VF_ID; | ||
251 | u8 VP_ID; | ||
252 | u8 valid_reply; | ||
253 | /* the following bits are only valid when 'valid_reply = 1' */ | ||
254 | u32 sense_length; | ||
255 | u16 ioc_status; | ||
256 | u8 scsi_state; | ||
257 | u8 scsi_status; | ||
258 | u32 log_info; | ||
259 | u32 transfer_length; | ||
260 | }; | ||
261 | |||
262 | /* | ||
263 | * The pci device ids are defined in mpi/mpi2_cnfg.h. | ||
264 | */ | ||
265 | static struct pci_device_id scsih_pci_table[] = { | ||
266 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, | ||
267 | PCI_ANY_ID, PCI_ANY_ID }, | ||
268 | /* Falcon ~ 2008*/ | ||
269 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, | ||
270 | PCI_ANY_ID, PCI_ANY_ID }, | ||
271 | /* Liberator ~ 2108 */ | ||
272 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, | ||
273 | PCI_ANY_ID, PCI_ANY_ID }, | ||
274 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, | ||
275 | PCI_ANY_ID, PCI_ANY_ID }, | ||
276 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, | ||
277 | PCI_ANY_ID, PCI_ANY_ID }, | ||
278 | /* Meteor ~ 2116 */ | ||
279 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, | ||
280 | PCI_ANY_ID, PCI_ANY_ID }, | ||
281 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, | ||
282 | PCI_ANY_ID, PCI_ANY_ID }, | ||
283 | /* Thunderbolt ~ 2208 */ | ||
284 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, | ||
285 | PCI_ANY_ID, PCI_ANY_ID }, | ||
286 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, | ||
287 | PCI_ANY_ID, PCI_ANY_ID }, | ||
288 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, | ||
289 | PCI_ANY_ID, PCI_ANY_ID }, | ||
290 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, | ||
291 | PCI_ANY_ID, PCI_ANY_ID }, | ||
292 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, | ||
293 | PCI_ANY_ID, PCI_ANY_ID }, | ||
294 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, | ||
295 | PCI_ANY_ID, PCI_ANY_ID }, | ||
296 | /* Mustang ~ 2308 */ | ||
297 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, | ||
298 | PCI_ANY_ID, PCI_ANY_ID }, | ||
299 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, | ||
300 | PCI_ANY_ID, PCI_ANY_ID }, | ||
301 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, | ||
302 | PCI_ANY_ID, PCI_ANY_ID }, | ||
303 | /* SSS6200 */ | ||
304 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, | ||
305 | PCI_ANY_ID, PCI_ANY_ID }, | ||
306 | {0} /* Terminating entry */ | ||
307 | }; | ||
308 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); | ||
309 | |||
310 | /** | ||
311 | * _scsih_set_debug_level - global setting of ioc->logging_level. | ||
312 | * | ||
313 | * Note: The logging levels are defined in mpt2sas_debug.h. | ||
314 | */ | ||
315 | static int | ||
316 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) | ||
317 | { | ||
318 | int ret = param_set_int(val, kp); | ||
319 | struct MPT2SAS_ADAPTER *ioc; | ||
320 | |||
321 | if (ret) | ||
322 | return ret; | ||
323 | |||
324 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); | ||
325 | spin_lock(&gioc_lock); | ||
326 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) | ||
327 | ioc->logging_level = logging_level; | ||
328 | spin_unlock(&gioc_lock); | ||
329 | return 0; | ||
330 | } | ||
331 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, | ||
332 | &logging_level, 0644); | ||
333 | |||
334 | /** | ||
335 | * _scsih_srch_boot_sas_address - search based on sas_address | ||
336 | * @sas_address: sas address | ||
337 | * @boot_device: boot device object from bios page 2 | ||
338 | * | ||
339 | * Returns 1 when there's a match, 0 means no match. | ||
340 | */ | ||
341 | static inline int | ||
342 | _scsih_srch_boot_sas_address(u64 sas_address, | ||
343 | Mpi2BootDeviceSasWwid_t *boot_device) | ||
344 | { | ||
345 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | * _scsih_srch_boot_device_name - search based on device name | ||
350 | * @device_name: device name specified in INDENTIFY fram | ||
351 | * @boot_device: boot device object from bios page 2 | ||
352 | * | ||
353 | * Returns 1 when there's a match, 0 means no match. | ||
354 | */ | ||
355 | static inline int | ||
356 | _scsih_srch_boot_device_name(u64 device_name, | ||
357 | Mpi2BootDeviceDeviceName_t *boot_device) | ||
358 | { | ||
359 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot | ||
364 | * @enclosure_logical_id: enclosure logical id | ||
365 | * @slot_number: slot number | ||
366 | * @boot_device: boot device object from bios page 2 | ||
367 | * | ||
368 | * Returns 1 when there's a match, 0 means no match. | ||
369 | */ | ||
370 | static inline int | ||
371 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, | ||
372 | Mpi2BootDeviceEnclosureSlot_t *boot_device) | ||
373 | { | ||
374 | return (enclosure_logical_id == le64_to_cpu(boot_device-> | ||
375 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> | ||
376 | SlotNumber)) ? 1 : 0; | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | * _scsih_is_boot_device - search for matching boot device. | ||
381 | * @sas_address: sas address | ||
382 | * @device_name: device name specified in INDENTIFY fram | ||
383 | * @enclosure_logical_id: enclosure logical id | ||
384 | * @slot_number: slot number | ||
385 | * @form: specifies boot device form | ||
386 | * @boot_device: boot device object from bios page 2 | ||
387 | * | ||
388 | * Returns 1 when there's a match, 0 means no match. | ||
389 | */ | ||
390 | static int | ||
391 | _scsih_is_boot_device(u64 sas_address, u64 device_name, | ||
392 | u64 enclosure_logical_id, u16 slot, u8 form, | ||
393 | Mpi2BiosPage2BootDevice_t *boot_device) | ||
394 | { | ||
395 | int rc = 0; | ||
396 | |||
397 | switch (form) { | ||
398 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: | ||
399 | if (!sas_address) | ||
400 | break; | ||
401 | rc = _scsih_srch_boot_sas_address( | ||
402 | sas_address, &boot_device->SasWwid); | ||
403 | break; | ||
404 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: | ||
405 | if (!enclosure_logical_id) | ||
406 | break; | ||
407 | rc = _scsih_srch_boot_encl_slot( | ||
408 | enclosure_logical_id, | ||
409 | slot, &boot_device->EnclosureSlot); | ||
410 | break; | ||
411 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: | ||
412 | if (!device_name) | ||
413 | break; | ||
414 | rc = _scsih_srch_boot_device_name( | ||
415 | device_name, &boot_device->DeviceName); | ||
416 | break; | ||
417 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: | ||
418 | break; | ||
419 | } | ||
420 | |||
421 | return rc; | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * _scsih_get_sas_address - set the sas_address for given device handle | ||
426 | * @handle: device handle | ||
427 | * @sas_address: sas address | ||
428 | * | ||
429 | * Returns 0 success, non-zero when failure | ||
430 | */ | ||
431 | static int | ||
432 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, | ||
433 | u64 *sas_address) | ||
434 | { | ||
435 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
436 | Mpi2ConfigReply_t mpi_reply; | ||
437 | u32 ioc_status; | ||
438 | *sas_address = 0; | ||
439 | |||
440 | if (handle <= ioc->sas_hba.num_phys) { | ||
441 | *sas_address = ioc->sas_hba.sas_address; | ||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
446 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | ||
447 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, | ||
448 | __FILE__, __LINE__, __func__); | ||
449 | return -ENXIO; | ||
450 | } | ||
451 | |||
452 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
453 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { | ||
454 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | /* we hit this becuase the given parent handle doesn't exist */ | ||
459 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) | ||
460 | return -ENXIO; | ||
461 | /* else error case */ | ||
462 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), " | ||
463 | "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, | ||
464 | __FILE__, __LINE__, __func__); | ||
465 | return -EIO; | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * _scsih_determine_boot_device - determine boot device. | ||
470 | * @ioc: per adapter object | ||
471 | * @device: either sas_device or raid_device object | ||
472 | * @is_raid: [flag] 1 = raid object, 0 = sas object | ||
473 | * | ||
474 | * Determines whether this device should be first reported device to | ||
475 | * to scsi-ml or sas transport, this purpose is for persistent boot device. | ||
476 | * There are primary, alternate, and current entries in bios page 2. The order | ||
477 | * priority is primary, alternate, then current. This routine saves | ||
478 | * the corresponding device object and is_raid flag in the ioc object. | ||
479 | * The saved data to be used later in _scsih_probe_boot_devices(). | ||
480 | */ | ||
481 | static void | ||
482 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, | ||
483 | void *device, u8 is_raid) | ||
484 | { | ||
485 | struct _sas_device *sas_device; | ||
486 | struct _raid_device *raid_device; | ||
487 | u64 sas_address; | ||
488 | u64 device_name; | ||
489 | u64 enclosure_logical_id; | ||
490 | u16 slot; | ||
491 | |||
492 | /* only process this function when driver loads */ | ||
493 | if (!ioc->is_driver_loading) | ||
494 | return; | ||
495 | |||
496 | /* no Bios, return immediately */ | ||
497 | if (!ioc->bios_pg3.BiosVersion) | ||
498 | return; | ||
499 | |||
500 | if (!is_raid) { | ||
501 | sas_device = device; | ||
502 | sas_address = sas_device->sas_address; | ||
503 | device_name = sas_device->device_name; | ||
504 | enclosure_logical_id = sas_device->enclosure_logical_id; | ||
505 | slot = sas_device->slot; | ||
506 | } else { | ||
507 | raid_device = device; | ||
508 | sas_address = raid_device->wwid; | ||
509 | device_name = 0; | ||
510 | enclosure_logical_id = 0; | ||
511 | slot = 0; | ||
512 | } | ||
513 | |||
514 | if (!ioc->req_boot_device.device) { | ||
515 | if (_scsih_is_boot_device(sas_address, device_name, | ||
516 | enclosure_logical_id, slot, | ||
517 | (ioc->bios_pg2.ReqBootDeviceForm & | ||
518 | MPI2_BIOSPAGE2_FORM_MASK), | ||
519 | &ioc->bios_pg2.RequestedBootDevice)) { | ||
520 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
521 | "%s: req_boot_device(0x%016llx)\n", | ||
522 | ioc->name, __func__, | ||
523 | (unsigned long long)sas_address)); | ||
524 | ioc->req_boot_device.device = device; | ||
525 | ioc->req_boot_device.is_raid = is_raid; | ||
526 | } | ||
527 | } | ||
528 | |||
529 | if (!ioc->req_alt_boot_device.device) { | ||
530 | if (_scsih_is_boot_device(sas_address, device_name, | ||
531 | enclosure_logical_id, slot, | ||
532 | (ioc->bios_pg2.ReqAltBootDeviceForm & | ||
533 | MPI2_BIOSPAGE2_FORM_MASK), | ||
534 | &ioc->bios_pg2.RequestedAltBootDevice)) { | ||
535 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
536 | "%s: req_alt_boot_device(0x%016llx)\n", | ||
537 | ioc->name, __func__, | ||
538 | (unsigned long long)sas_address)); | ||
539 | ioc->req_alt_boot_device.device = device; | ||
540 | ioc->req_alt_boot_device.is_raid = is_raid; | ||
541 | } | ||
542 | } | ||
543 | |||
544 | if (!ioc->current_boot_device.device) { | ||
545 | if (_scsih_is_boot_device(sas_address, device_name, | ||
546 | enclosure_logical_id, slot, | ||
547 | (ioc->bios_pg2.CurrentBootDeviceForm & | ||
548 | MPI2_BIOSPAGE2_FORM_MASK), | ||
549 | &ioc->bios_pg2.CurrentBootDevice)) { | ||
550 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
551 | "%s: current_boot_device(0x%016llx)\n", | ||
552 | ioc->name, __func__, | ||
553 | (unsigned long long)sas_address)); | ||
554 | ioc->current_boot_device.device = device; | ||
555 | ioc->current_boot_device.is_raid = is_raid; | ||
556 | } | ||
557 | } | ||
558 | } | ||
559 | |||
560 | static struct _sas_device * | ||
561 | __mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc, | ||
562 | struct MPT2SAS_TARGET *tgt_priv) | ||
563 | { | ||
564 | struct _sas_device *ret; | ||
565 | |||
566 | assert_spin_locked(&ioc->sas_device_lock); | ||
567 | |||
568 | ret = tgt_priv->sdev; | ||
569 | if (ret) | ||
570 | sas_device_get(ret); | ||
571 | |||
572 | return ret; | ||
573 | } | ||
574 | |||
575 | static struct _sas_device * | ||
576 | mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc, | ||
577 | struct MPT2SAS_TARGET *tgt_priv) | ||
578 | { | ||
579 | struct _sas_device *ret; | ||
580 | unsigned long flags; | ||
581 | |||
582 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
583 | ret = __mpt2sas_get_sdev_from_target(ioc, tgt_priv); | ||
584 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
585 | |||
586 | return ret; | ||
587 | } | ||
588 | |||
589 | |||
590 | struct _sas_device * | ||
591 | __mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc, | ||
592 | u64 sas_address) | ||
593 | { | ||
594 | struct _sas_device *sas_device; | ||
595 | |||
596 | assert_spin_locked(&ioc->sas_device_lock); | ||
597 | |||
598 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | ||
599 | if (sas_device->sas_address == sas_address) | ||
600 | goto found_device; | ||
601 | |||
602 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | ||
603 | if (sas_device->sas_address == sas_address) | ||
604 | goto found_device; | ||
605 | |||
606 | return NULL; | ||
607 | |||
608 | found_device: | ||
609 | sas_device_get(sas_device); | ||
610 | return sas_device; | ||
611 | } | ||
612 | |||
613 | /** | ||
614 | * mpt2sas_get_sdev_by_addr - sas device search | ||
615 | * @ioc: per adapter object | ||
616 | * @sas_address: sas address | ||
617 | * Context: Calling function should acquire ioc->sas_device_lock | ||
618 | * | ||
619 | * This searches for sas_device based on sas_address, then return sas_device | ||
620 | * object. | ||
621 | */ | ||
622 | struct _sas_device * | ||
623 | mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc, | ||
624 | u64 sas_address) | ||
625 | { | ||
626 | struct _sas_device *sas_device; | ||
627 | unsigned long flags; | ||
628 | |||
629 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
630 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
631 | sas_address); | ||
632 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
633 | |||
634 | return sas_device; | ||
635 | } | ||
636 | |||
637 | static struct _sas_device * | ||
638 | __mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
639 | { | ||
640 | struct _sas_device *sas_device; | ||
641 | |||
642 | assert_spin_locked(&ioc->sas_device_lock); | ||
643 | |||
644 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) | ||
645 | if (sas_device->handle == handle) | ||
646 | goto found_device; | ||
647 | |||
648 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) | ||
649 | if (sas_device->handle == handle) | ||
650 | goto found_device; | ||
651 | |||
652 | return NULL; | ||
653 | |||
654 | found_device: | ||
655 | sas_device_get(sas_device); | ||
656 | return sas_device; | ||
657 | } | ||
658 | |||
659 | /** | ||
660 | * mpt2sas_get_sdev_by_handle - sas device search | ||
661 | * @ioc: per adapter object | ||
662 | * @handle: sas device handle (assigned by firmware) | ||
663 | * Context: Calling function should acquire ioc->sas_device_lock | ||
664 | * | ||
665 | * This searches for sas_device based on sas_address, then return sas_device | ||
666 | * object. | ||
667 | */ | ||
668 | static struct _sas_device * | ||
669 | mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
670 | { | ||
671 | struct _sas_device *sas_device; | ||
672 | unsigned long flags; | ||
673 | |||
674 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
675 | sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle); | ||
676 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
677 | |||
678 | return sas_device; | ||
679 | } | ||
680 | |||
681 | /** | ||
682 | * _scsih_sas_device_remove - remove sas_device from list. | ||
683 | * @ioc: per adapter object | ||
684 | * @sas_device: the sas_device object | ||
685 | * Context: This function will acquire ioc->sas_device_lock. | ||
686 | * | ||
687 | * If sas_device is on the list, remove it and decrement its reference count. | ||
688 | */ | ||
689 | static void | ||
690 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, | ||
691 | struct _sas_device *sas_device) | ||
692 | { | ||
693 | unsigned long flags; | ||
694 | |||
695 | if (!sas_device) | ||
696 | return; | ||
697 | |||
698 | /* | ||
699 | * The lock serializes access to the list, but we still need to verify | ||
700 | * that nobody removed the entry while we were waiting on the lock. | ||
701 | */ | ||
702 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
703 | if (!list_empty(&sas_device->list)) { | ||
704 | list_del_init(&sas_device->list); | ||
705 | sas_device_put(sas_device); | ||
706 | } | ||
707 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
708 | } | ||
709 | |||
710 | |||
711 | /** | ||
712 | * _scsih_sas_device_add - insert sas_device to the list. | ||
713 | * @ioc: per adapter object | ||
714 | * @sas_device: the sas_device object | ||
715 | * Context: This function will acquire ioc->sas_device_lock. | ||
716 | * | ||
717 | * Adding new object to the ioc->sas_device_list. | ||
718 | */ | ||
719 | static void | ||
720 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, | ||
721 | struct _sas_device *sas_device) | ||
722 | { | ||
723 | unsigned long flags; | ||
724 | |||
725 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" | ||
726 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, | ||
727 | sas_device->handle, (unsigned long long)sas_device->sas_address)); | ||
728 | |||
729 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
730 | sas_device_get(sas_device); | ||
731 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | ||
732 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
733 | |||
734 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, | ||
735 | sas_device->sas_address_parent)) { | ||
736 | _scsih_sas_device_remove(ioc, sas_device); | ||
737 | } else if (!sas_device->starget) { | ||
738 | /* When asyn scanning is enabled, its not possible to remove | ||
739 | * devices while scanning is turned on due to an oops in | ||
740 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() | ||
741 | */ | ||
742 | if (!ioc->is_driver_loading) { | ||
743 | mpt2sas_transport_port_remove(ioc, | ||
744 | sas_device->sas_address, | ||
745 | sas_device->sas_address_parent); | ||
746 | _scsih_sas_device_remove(ioc, sas_device); | ||
747 | } | ||
748 | } | ||
749 | } | ||
750 | |||
751 | /** | ||
752 | * _scsih_sas_device_init_add - insert sas_device to the list. | ||
753 | * @ioc: per adapter object | ||
754 | * @sas_device: the sas_device object | ||
755 | * Context: This function will acquire ioc->sas_device_lock. | ||
756 | * | ||
757 | * Adding new object at driver load time to the ioc->sas_device_init_list. | ||
758 | */ | ||
759 | static void | ||
760 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, | ||
761 | struct _sas_device *sas_device) | ||
762 | { | ||
763 | unsigned long flags; | ||
764 | |||
765 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" | ||
766 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, | ||
767 | sas_device->handle, (unsigned long long)sas_device->sas_address)); | ||
768 | |||
769 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
770 | sas_device_get(sas_device); | ||
771 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); | ||
772 | _scsih_determine_boot_device(ioc, sas_device, 0); | ||
773 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
774 | } | ||
775 | |||
776 | /** | ||
777 | * _scsih_raid_device_find_by_id - raid device search | ||
778 | * @ioc: per adapter object | ||
779 | * @id: sas device target id | ||
780 | * @channel: sas device channel | ||
781 | * Context: Calling function should acquire ioc->raid_device_lock | ||
782 | * | ||
783 | * This searches for raid_device based on target id, then return raid_device | ||
784 | * object. | ||
785 | */ | ||
786 | static struct _raid_device * | ||
787 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) | ||
788 | { | ||
789 | struct _raid_device *raid_device, *r; | ||
790 | |||
791 | r = NULL; | ||
792 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | ||
793 | if (raid_device->id == id && raid_device->channel == channel) { | ||
794 | r = raid_device; | ||
795 | goto out; | ||
796 | } | ||
797 | } | ||
798 | |||
799 | out: | ||
800 | return r; | ||
801 | } | ||
802 | |||
803 | /** | ||
804 | * _scsih_raid_device_find_by_handle - raid device search | ||
805 | * @ioc: per adapter object | ||
806 | * @handle: sas device handle (assigned by firmware) | ||
807 | * Context: Calling function should acquire ioc->raid_device_lock | ||
808 | * | ||
809 | * This searches for raid_device based on handle, then return raid_device | ||
810 | * object. | ||
811 | */ | ||
812 | static struct _raid_device * | ||
813 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
814 | { | ||
815 | struct _raid_device *raid_device, *r; | ||
816 | |||
817 | r = NULL; | ||
818 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | ||
819 | if (raid_device->handle != handle) | ||
820 | continue; | ||
821 | r = raid_device; | ||
822 | goto out; | ||
823 | } | ||
824 | |||
825 | out: | ||
826 | return r; | ||
827 | } | ||
828 | |||
829 | /** | ||
830 | * _scsih_raid_device_find_by_wwid - raid device search | ||
831 | * @ioc: per adapter object | ||
832 | * @handle: sas device handle (assigned by firmware) | ||
833 | * Context: Calling function should acquire ioc->raid_device_lock | ||
834 | * | ||
835 | * This searches for raid_device based on wwid, then return raid_device | ||
836 | * object. | ||
837 | */ | ||
838 | static struct _raid_device * | ||
839 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) | ||
840 | { | ||
841 | struct _raid_device *raid_device, *r; | ||
842 | |||
843 | r = NULL; | ||
844 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | ||
845 | if (raid_device->wwid != wwid) | ||
846 | continue; | ||
847 | r = raid_device; | ||
848 | goto out; | ||
849 | } | ||
850 | |||
851 | out: | ||
852 | return r; | ||
853 | } | ||
854 | |||
855 | /** | ||
856 | * _scsih_raid_device_add - add raid_device object | ||
857 | * @ioc: per adapter object | ||
858 | * @raid_device: raid_device object | ||
859 | * | ||
860 | * This is added to the raid_device_list link list. | ||
861 | */ | ||
862 | static void | ||
863 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, | ||
864 | struct _raid_device *raid_device) | ||
865 | { | ||
866 | unsigned long flags; | ||
867 | |||
868 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" | ||
869 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, | ||
870 | raid_device->handle, (unsigned long long)raid_device->wwid)); | ||
871 | |||
872 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
873 | list_add_tail(&raid_device->list, &ioc->raid_device_list); | ||
874 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
875 | } | ||
876 | |||
877 | /** | ||
878 | * _scsih_raid_device_remove - delete raid_device object | ||
879 | * @ioc: per adapter object | ||
880 | * @raid_device: raid_device object | ||
881 | * | ||
882 | */ | ||
883 | static void | ||
884 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, | ||
885 | struct _raid_device *raid_device) | ||
886 | { | ||
887 | unsigned long flags; | ||
888 | |||
889 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
890 | list_del(&raid_device->list); | ||
891 | kfree(raid_device); | ||
892 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
893 | } | ||
894 | |||
895 | /** | ||
896 | * mpt2sas_scsih_expander_find_by_handle - expander device search | ||
897 | * @ioc: per adapter object | ||
898 | * @handle: expander handle (assigned by firmware) | ||
899 | * Context: Calling function should acquire ioc->sas_device_lock | ||
900 | * | ||
901 | * This searches for expander device based on handle, then returns the | ||
902 | * sas_node object. | ||
903 | */ | ||
904 | struct _sas_node * | ||
905 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
906 | { | ||
907 | struct _sas_node *sas_expander, *r; | ||
908 | |||
909 | r = NULL; | ||
910 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | ||
911 | if (sas_expander->handle != handle) | ||
912 | continue; | ||
913 | r = sas_expander; | ||
914 | goto out; | ||
915 | } | ||
916 | out: | ||
917 | return r; | ||
918 | } | ||
919 | |||
920 | /** | ||
921 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search | ||
922 | * @ioc: per adapter object | ||
923 | * @sas_address: sas address | ||
924 | * Context: Calling function should acquire ioc->sas_node_lock. | ||
925 | * | ||
926 | * This searches for expander device based on sas_address, then returns the | ||
927 | * sas_node object. | ||
928 | */ | ||
929 | struct _sas_node * | ||
930 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, | ||
931 | u64 sas_address) | ||
932 | { | ||
933 | struct _sas_node *sas_expander, *r; | ||
934 | |||
935 | r = NULL; | ||
936 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | ||
937 | if (sas_expander->sas_address != sas_address) | ||
938 | continue; | ||
939 | r = sas_expander; | ||
940 | goto out; | ||
941 | } | ||
942 | out: | ||
943 | return r; | ||
944 | } | ||
945 | |||
946 | /** | ||
947 | * _scsih_expander_node_add - insert expander device to the list. | ||
948 | * @ioc: per adapter object | ||
949 | * @sas_expander: the sas_device object | ||
950 | * Context: This function will acquire ioc->sas_node_lock. | ||
951 | * | ||
952 | * Adding new object to the ioc->sas_expander_list. | ||
953 | * | ||
954 | * Return nothing. | ||
955 | */ | ||
956 | static void | ||
957 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, | ||
958 | struct _sas_node *sas_expander) | ||
959 | { | ||
960 | unsigned long flags; | ||
961 | |||
962 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
963 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); | ||
964 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
965 | } | ||
966 | |||
967 | /** | ||
968 | * _scsih_is_end_device - determines if device is an end device | ||
969 | * @device_info: bitfield providing information about the device. | ||
970 | * Context: none | ||
971 | * | ||
972 | * Returns 1 if end device. | ||
973 | */ | ||
974 | static int | ||
975 | _scsih_is_end_device(u32 device_info) | ||
976 | { | ||
977 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && | ||
978 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | | ||
979 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | | ||
980 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) | ||
981 | return 1; | ||
982 | else | ||
983 | return 0; | ||
984 | } | ||
985 | |||
986 | /** | ||
987 | * _scsih_scsi_lookup_get - returns scmd entry | ||
988 | * @ioc: per adapter object | ||
989 | * @smid: system request message index | ||
990 | * | ||
991 | * Returns the smid stored scmd pointer. | ||
992 | */ | ||
993 | static struct scsi_cmnd * | ||
994 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
995 | { | ||
996 | return ioc->scsi_lookup[smid - 1].scmd; | ||
997 | } | ||
998 | |||
999 | /** | ||
1000 | * _scsih_scsi_lookup_get_clear - returns scmd entry | ||
1001 | * @ioc: per adapter object | ||
1002 | * @smid: system request message index | ||
1003 | * | ||
1004 | * Returns the smid stored scmd pointer. | ||
1005 | * Then will derefrence the stored scmd pointer. | ||
1006 | */ | ||
1007 | static inline struct scsi_cmnd * | ||
1008 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1009 | { | ||
1010 | unsigned long flags; | ||
1011 | struct scsi_cmnd *scmd; | ||
1012 | |||
1013 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1014 | scmd = ioc->scsi_lookup[smid - 1].scmd; | ||
1015 | ioc->scsi_lookup[smid - 1].scmd = NULL; | ||
1016 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1017 | |||
1018 | return scmd; | ||
1019 | } | ||
1020 | |||
1021 | /** | ||
1022 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup | ||
1023 | * @ioc: per adapter object | ||
1024 | * @smid: system request message index | ||
1025 | * @scmd: pointer to scsi command object | ||
1026 | * Context: This function will acquire ioc->scsi_lookup_lock. | ||
1027 | * | ||
1028 | * This will search for a scmd pointer in the scsi_lookup array, | ||
1029 | * returning the revelent smid. A returned value of zero means invalid. | ||
1030 | */ | ||
1031 | static u16 | ||
1032 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd | ||
1033 | *scmd) | ||
1034 | { | ||
1035 | u16 smid; | ||
1036 | unsigned long flags; | ||
1037 | int i; | ||
1038 | |||
1039 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1040 | smid = 0; | ||
1041 | for (i = 0; i < ioc->scsiio_depth; i++) { | ||
1042 | if (ioc->scsi_lookup[i].scmd == scmd) { | ||
1043 | smid = ioc->scsi_lookup[i].smid; | ||
1044 | goto out; | ||
1045 | } | ||
1046 | } | ||
1047 | out: | ||
1048 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1049 | return smid; | ||
1050 | } | ||
1051 | |||
1052 | /** | ||
1053 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id | ||
1054 | * @ioc: per adapter object | ||
1055 | * @id: target id | ||
1056 | * @channel: channel | ||
1057 | * Context: This function will acquire ioc->scsi_lookup_lock. | ||
1058 | * | ||
1059 | * This will search for a matching channel:id in the scsi_lookup array, | ||
1060 | * returning 1 if found. | ||
1061 | */ | ||
1062 | static u8 | ||
1063 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, | ||
1064 | int channel) | ||
1065 | { | ||
1066 | u8 found; | ||
1067 | unsigned long flags; | ||
1068 | int i; | ||
1069 | |||
1070 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1071 | found = 0; | ||
1072 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | ||
1073 | if (ioc->scsi_lookup[i].scmd && | ||
1074 | (ioc->scsi_lookup[i].scmd->device->id == id && | ||
1075 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { | ||
1076 | found = 1; | ||
1077 | goto out; | ||
1078 | } | ||
1079 | } | ||
1080 | out: | ||
1081 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1082 | return found; | ||
1083 | } | ||
1084 | |||
1085 | /** | ||
1086 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun | ||
1087 | * @ioc: per adapter object | ||
1088 | * @id: target id | ||
1089 | * @lun: lun number | ||
1090 | * @channel: channel | ||
1091 | * Context: This function will acquire ioc->scsi_lookup_lock. | ||
1092 | * | ||
1093 | * This will search for a matching channel:id:lun in the scsi_lookup array, | ||
1094 | * returning 1 if found. | ||
1095 | */ | ||
1096 | static u8 | ||
1097 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, | ||
1098 | unsigned int lun, int channel) | ||
1099 | { | ||
1100 | u8 found; | ||
1101 | unsigned long flags; | ||
1102 | int i; | ||
1103 | |||
1104 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1105 | found = 0; | ||
1106 | for (i = 0 ; i < ioc->scsiio_depth; i++) { | ||
1107 | if (ioc->scsi_lookup[i].scmd && | ||
1108 | (ioc->scsi_lookup[i].scmd->device->id == id && | ||
1109 | ioc->scsi_lookup[i].scmd->device->channel == channel && | ||
1110 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { | ||
1111 | found = 1; | ||
1112 | goto out; | ||
1113 | } | ||
1114 | } | ||
1115 | out: | ||
1116 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1117 | return found; | ||
1118 | } | ||
1119 | |||
1120 | /** | ||
1121 | * _scsih_get_chain_buffer_tracker - obtain chain tracker | ||
1122 | * @ioc: per adapter object | ||
1123 | * @smid: smid associated to an IO request | ||
1124 | * | ||
1125 | * Returns chain tracker(from ioc->free_chain_list) | ||
1126 | */ | ||
1127 | static struct chain_tracker * | ||
1128 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
1129 | { | ||
1130 | struct chain_tracker *chain_req; | ||
1131 | unsigned long flags; | ||
1132 | |||
1133 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
1134 | if (list_empty(&ioc->free_chain_list)) { | ||
1135 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1136 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not " | ||
1137 | "available\n", ioc->name)); | ||
1138 | return NULL; | ||
1139 | } | ||
1140 | chain_req = list_entry(ioc->free_chain_list.next, | ||
1141 | struct chain_tracker, tracker_list); | ||
1142 | list_del_init(&chain_req->tracker_list); | ||
1143 | list_add_tail(&chain_req->tracker_list, | ||
1144 | &ioc->scsi_lookup[smid - 1].chain_list); | ||
1145 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
1146 | return chain_req; | ||
1147 | } | ||
1148 | |||
1149 | /** | ||
1150 | * _scsih_build_scatter_gather - main sg creation routine | ||
1151 | * @ioc: per adapter object | ||
1152 | * @scmd: scsi command | ||
1153 | * @smid: system request message index | ||
1154 | * Context: none. | ||
1155 | * | ||
1156 | * The main routine that builds scatter gather table from a given | ||
1157 | * scsi request sent via the .queuecommand main handler. | ||
1158 | * | ||
1159 | * Returns 0 success, anything else error | ||
1160 | */ | ||
1161 | static int | ||
1162 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, | ||
1163 | struct scsi_cmnd *scmd, u16 smid) | ||
1164 | { | ||
1165 | Mpi2SCSIIORequest_t *mpi_request; | ||
1166 | dma_addr_t chain_dma; | ||
1167 | struct scatterlist *sg_scmd; | ||
1168 | void *sg_local, *chain; | ||
1169 | u32 chain_offset; | ||
1170 | u32 chain_length; | ||
1171 | u32 chain_flags; | ||
1172 | int sges_left; | ||
1173 | u32 sges_in_segment; | ||
1174 | u32 sgl_flags; | ||
1175 | u32 sgl_flags_last_element; | ||
1176 | u32 sgl_flags_end_buffer; | ||
1177 | struct chain_tracker *chain_req; | ||
1178 | |||
1179 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
1180 | |||
1181 | /* init scatter gather flags */ | ||
1182 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; | ||
1183 | if (scmd->sc_data_direction == DMA_TO_DEVICE) | ||
1184 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; | ||
1185 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) | ||
1186 | << MPI2_SGE_FLAGS_SHIFT; | ||
1187 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | | ||
1188 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) | ||
1189 | << MPI2_SGE_FLAGS_SHIFT; | ||
1190 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
1191 | |||
1192 | sg_scmd = scsi_sglist(scmd); | ||
1193 | sges_left = scsi_dma_map(scmd); | ||
1194 | if (sges_left < 0) { | ||
1195 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" | ||
1196 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); | ||
1197 | return -ENOMEM; | ||
1198 | } | ||
1199 | |||
1200 | sg_local = &mpi_request->SGL; | ||
1201 | sges_in_segment = ioc->max_sges_in_main_message; | ||
1202 | if (sges_left <= sges_in_segment) | ||
1203 | goto fill_in_last_segment; | ||
1204 | |||
1205 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + | ||
1206 | (sges_in_segment * ioc->sge_size))/4; | ||
1207 | |||
1208 | /* fill in main message segment when there is a chain following */ | ||
1209 | while (sges_in_segment) { | ||
1210 | if (sges_in_segment == 1) | ||
1211 | ioc->base_add_sg_single(sg_local, | ||
1212 | sgl_flags_last_element | sg_dma_len(sg_scmd), | ||
1213 | sg_dma_address(sg_scmd)); | ||
1214 | else | ||
1215 | ioc->base_add_sg_single(sg_local, sgl_flags | | ||
1216 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); | ||
1217 | sg_scmd = sg_next(sg_scmd); | ||
1218 | sg_local += ioc->sge_size; | ||
1219 | sges_left--; | ||
1220 | sges_in_segment--; | ||
1221 | } | ||
1222 | |||
1223 | /* initializing the chain flags and pointers */ | ||
1224 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; | ||
1225 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); | ||
1226 | if (!chain_req) | ||
1227 | return -1; | ||
1228 | chain = chain_req->chain_buffer; | ||
1229 | chain_dma = chain_req->chain_buffer_dma; | ||
1230 | do { | ||
1231 | sges_in_segment = (sges_left <= | ||
1232 | ioc->max_sges_in_chain_message) ? sges_left : | ||
1233 | ioc->max_sges_in_chain_message; | ||
1234 | chain_offset = (sges_left == sges_in_segment) ? | ||
1235 | 0 : (sges_in_segment * ioc->sge_size)/4; | ||
1236 | chain_length = sges_in_segment * ioc->sge_size; | ||
1237 | if (chain_offset) { | ||
1238 | chain_offset = chain_offset << | ||
1239 | MPI2_SGE_CHAIN_OFFSET_SHIFT; | ||
1240 | chain_length += ioc->sge_size; | ||
1241 | } | ||
1242 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | | ||
1243 | chain_length, chain_dma); | ||
1244 | sg_local = chain; | ||
1245 | if (!chain_offset) | ||
1246 | goto fill_in_last_segment; | ||
1247 | |||
1248 | /* fill in chain segments */ | ||
1249 | while (sges_in_segment) { | ||
1250 | if (sges_in_segment == 1) | ||
1251 | ioc->base_add_sg_single(sg_local, | ||
1252 | sgl_flags_last_element | | ||
1253 | sg_dma_len(sg_scmd), | ||
1254 | sg_dma_address(sg_scmd)); | ||
1255 | else | ||
1256 | ioc->base_add_sg_single(sg_local, sgl_flags | | ||
1257 | sg_dma_len(sg_scmd), | ||
1258 | sg_dma_address(sg_scmd)); | ||
1259 | sg_scmd = sg_next(sg_scmd); | ||
1260 | sg_local += ioc->sge_size; | ||
1261 | sges_left--; | ||
1262 | sges_in_segment--; | ||
1263 | } | ||
1264 | |||
1265 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); | ||
1266 | if (!chain_req) | ||
1267 | return -1; | ||
1268 | chain = chain_req->chain_buffer; | ||
1269 | chain_dma = chain_req->chain_buffer_dma; | ||
1270 | } while (1); | ||
1271 | |||
1272 | |||
1273 | fill_in_last_segment: | ||
1274 | |||
1275 | /* fill the last segment */ | ||
1276 | while (sges_left) { | ||
1277 | if (sges_left == 1) | ||
1278 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | | ||
1279 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); | ||
1280 | else | ||
1281 | ioc->base_add_sg_single(sg_local, sgl_flags | | ||
1282 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); | ||
1283 | sg_scmd = sg_next(sg_scmd); | ||
1284 | sg_local += ioc->sge_size; | ||
1285 | sges_left--; | ||
1286 | } | ||
1287 | |||
1288 | return 0; | ||
1289 | } | ||
1290 | |||
1291 | /** | ||
1292 | * _scsih_change_queue_depth - setting device queue depth | ||
1293 | * @sdev: scsi device struct | ||
1294 | * @qdepth: requested queue depth | ||
1295 | * | ||
1296 | * Returns queue depth. | ||
1297 | */ | ||
1298 | static int | ||
1299 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) | ||
1300 | { | ||
1301 | struct Scsi_Host *shost = sdev->host; | ||
1302 | int max_depth; | ||
1303 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
1304 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
1305 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
1306 | struct _sas_device *sas_device; | ||
1307 | unsigned long flags; | ||
1308 | |||
1309 | max_depth = shost->can_queue; | ||
1310 | |||
1311 | /* limit max device queue for SATA to 32 */ | ||
1312 | sas_device_priv_data = sdev->hostdata; | ||
1313 | if (!sas_device_priv_data) | ||
1314 | goto not_sata; | ||
1315 | sas_target_priv_data = sas_device_priv_data->sas_target; | ||
1316 | if (!sas_target_priv_data) | ||
1317 | goto not_sata; | ||
1318 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) | ||
1319 | goto not_sata; | ||
1320 | |||
1321 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1322 | sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data); | ||
1323 | if (sas_device) { | ||
1324 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | ||
1325 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; | ||
1326 | |||
1327 | sas_device_put(sas_device); | ||
1328 | } | ||
1329 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1330 | |||
1331 | not_sata: | ||
1332 | if (!sdev->tagged_supported) | ||
1333 | max_depth = 1; | ||
1334 | if (qdepth > max_depth) | ||
1335 | qdepth = max_depth; | ||
1336 | return scsi_change_queue_depth(sdev, qdepth); | ||
1337 | } | ||
1338 | |||
1339 | /** | ||
1340 | * _scsih_target_alloc - target add routine | ||
1341 | * @starget: scsi target struct | ||
1342 | * | ||
1343 | * Returns 0 if ok. Any other return is assumed to be an error and | ||
1344 | * the device is ignored. | ||
1345 | */ | ||
1346 | static int | ||
1347 | _scsih_target_alloc(struct scsi_target *starget) | ||
1348 | { | ||
1349 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | ||
1350 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
1351 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
1352 | struct _sas_device *sas_device; | ||
1353 | struct _raid_device *raid_device; | ||
1354 | unsigned long flags; | ||
1355 | struct sas_rphy *rphy; | ||
1356 | |||
1357 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), | ||
1358 | GFP_KERNEL); | ||
1359 | if (!sas_target_priv_data) | ||
1360 | return -ENOMEM; | ||
1361 | |||
1362 | starget->hostdata = sas_target_priv_data; | ||
1363 | sas_target_priv_data->starget = starget; | ||
1364 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; | ||
1365 | |||
1366 | /* RAID volumes */ | ||
1367 | if (starget->channel == RAID_CHANNEL) { | ||
1368 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1369 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | ||
1370 | starget->channel); | ||
1371 | if (raid_device) { | ||
1372 | sas_target_priv_data->handle = raid_device->handle; | ||
1373 | sas_target_priv_data->sas_address = raid_device->wwid; | ||
1374 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; | ||
1375 | if (ioc->is_warpdrive) | ||
1376 | sas_target_priv_data->raid_device = raid_device; | ||
1377 | raid_device->starget = starget; | ||
1378 | } | ||
1379 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1380 | return 0; | ||
1381 | } | ||
1382 | |||
1383 | /* sas/sata devices */ | ||
1384 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1385 | rphy = dev_to_rphy(starget->dev.parent); | ||
1386 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
1387 | rphy->identify.sas_address); | ||
1388 | |||
1389 | if (sas_device) { | ||
1390 | sas_target_priv_data->handle = sas_device->handle; | ||
1391 | sas_target_priv_data->sas_address = sas_device->sas_address; | ||
1392 | sas_target_priv_data->sdev = sas_device; | ||
1393 | sas_device->starget = starget; | ||
1394 | sas_device->id = starget->id; | ||
1395 | sas_device->channel = starget->channel; | ||
1396 | if (test_bit(sas_device->handle, ioc->pd_handles)) | ||
1397 | sas_target_priv_data->flags |= | ||
1398 | MPT_TARGET_FLAGS_RAID_COMPONENT; | ||
1399 | |||
1400 | } | ||
1401 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1402 | |||
1403 | return 0; | ||
1404 | } | ||
1405 | |||
1406 | /** | ||
1407 | * _scsih_target_destroy - target destroy routine | ||
1408 | * @starget: scsi target struct | ||
1409 | * | ||
1410 | * Returns nothing. | ||
1411 | */ | ||
1412 | static void | ||
1413 | _scsih_target_destroy(struct scsi_target *starget) | ||
1414 | { | ||
1415 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | ||
1416 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
1417 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
1418 | struct _sas_device *sas_device; | ||
1419 | struct _raid_device *raid_device; | ||
1420 | unsigned long flags; | ||
1421 | struct sas_rphy *rphy; | ||
1422 | |||
1423 | sas_target_priv_data = starget->hostdata; | ||
1424 | if (!sas_target_priv_data) | ||
1425 | return; | ||
1426 | |||
1427 | if (starget->channel == RAID_CHANNEL) { | ||
1428 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1429 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, | ||
1430 | starget->channel); | ||
1431 | if (raid_device) { | ||
1432 | raid_device->starget = NULL; | ||
1433 | raid_device->sdev = NULL; | ||
1434 | } | ||
1435 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1436 | goto out; | ||
1437 | } | ||
1438 | |||
1439 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1440 | rphy = dev_to_rphy(starget->dev.parent); | ||
1441 | sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data); | ||
1442 | if (sas_device && (sas_device->starget == starget) && | ||
1443 | (sas_device->id == starget->id) && | ||
1444 | (sas_device->channel == starget->channel)) | ||
1445 | sas_device->starget = NULL; | ||
1446 | |||
1447 | if (sas_device) { | ||
1448 | /* | ||
1449 | * Corresponding get() is in _scsih_target_alloc() | ||
1450 | */ | ||
1451 | sas_target_priv_data->sdev = NULL; | ||
1452 | sas_device_put(sas_device); | ||
1453 | |||
1454 | sas_device_put(sas_device); | ||
1455 | } | ||
1456 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1457 | |||
1458 | out: | ||
1459 | kfree(sas_target_priv_data); | ||
1460 | starget->hostdata = NULL; | ||
1461 | } | ||
1462 | |||
1463 | /** | ||
1464 | * _scsih_slave_alloc - device add routine | ||
1465 | * @sdev: scsi device struct | ||
1466 | * | ||
1467 | * Returns 0 if ok. Any other return is assumed to be an error and | ||
1468 | * the device is ignored. | ||
1469 | */ | ||
1470 | static int | ||
1471 | _scsih_slave_alloc(struct scsi_device *sdev) | ||
1472 | { | ||
1473 | struct Scsi_Host *shost; | ||
1474 | struct MPT2SAS_ADAPTER *ioc; | ||
1475 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
1476 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
1477 | struct scsi_target *starget; | ||
1478 | struct _raid_device *raid_device; | ||
1479 | struct _sas_device *sas_device; | ||
1480 | unsigned long flags; | ||
1481 | |||
1482 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), | ||
1483 | GFP_KERNEL); | ||
1484 | if (!sas_device_priv_data) | ||
1485 | return -ENOMEM; | ||
1486 | |||
1487 | sas_device_priv_data->lun = sdev->lun; | ||
1488 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; | ||
1489 | |||
1490 | starget = scsi_target(sdev); | ||
1491 | sas_target_priv_data = starget->hostdata; | ||
1492 | sas_target_priv_data->num_luns++; | ||
1493 | sas_device_priv_data->sas_target = sas_target_priv_data; | ||
1494 | sdev->hostdata = sas_device_priv_data; | ||
1495 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) | ||
1496 | sdev->no_uld_attach = 1; | ||
1497 | |||
1498 | shost = dev_to_shost(&starget->dev); | ||
1499 | ioc = shost_priv(shost); | ||
1500 | if (starget->channel == RAID_CHANNEL) { | ||
1501 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1502 | raid_device = _scsih_raid_device_find_by_id(ioc, | ||
1503 | starget->id, starget->channel); | ||
1504 | if (raid_device) | ||
1505 | raid_device->sdev = sdev; /* raid is single lun */ | ||
1506 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1507 | } | ||
1508 | |||
1509 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | ||
1510 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1511 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
1512 | sas_target_priv_data->sas_address); | ||
1513 | if (sas_device && (sas_device->starget == NULL)) { | ||
1514 | sdev_printk(KERN_INFO, sdev, | ||
1515 | "%s : sas_device->starget set to starget @ %d\n", | ||
1516 | __func__, __LINE__); | ||
1517 | sas_device->starget = starget; | ||
1518 | } | ||
1519 | |||
1520 | if (sas_device) | ||
1521 | sas_device_put(sas_device); | ||
1522 | |||
1523 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1524 | } | ||
1525 | |||
1526 | return 0; | ||
1527 | } | ||
1528 | |||
1529 | /** | ||
1530 | * _scsih_slave_destroy - device destroy routine | ||
1531 | * @sdev: scsi device struct | ||
1532 | * | ||
1533 | * Returns nothing. | ||
1534 | */ | ||
1535 | static void | ||
1536 | _scsih_slave_destroy(struct scsi_device *sdev) | ||
1537 | { | ||
1538 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
1539 | struct scsi_target *starget; | ||
1540 | struct Scsi_Host *shost; | ||
1541 | struct MPT2SAS_ADAPTER *ioc; | ||
1542 | struct _sas_device *sas_device; | ||
1543 | unsigned long flags; | ||
1544 | |||
1545 | if (!sdev->hostdata) | ||
1546 | return; | ||
1547 | |||
1548 | starget = scsi_target(sdev); | ||
1549 | sas_target_priv_data = starget->hostdata; | ||
1550 | sas_target_priv_data->num_luns--; | ||
1551 | |||
1552 | shost = dev_to_shost(&starget->dev); | ||
1553 | ioc = shost_priv(shost); | ||
1554 | |||
1555 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { | ||
1556 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1557 | sas_device = __mpt2sas_get_sdev_from_target(ioc, | ||
1558 | sas_target_priv_data); | ||
1559 | if (sas_device && !sas_target_priv_data->num_luns) | ||
1560 | sas_device->starget = NULL; | ||
1561 | |||
1562 | if (sas_device) | ||
1563 | sas_device_put(sas_device); | ||
1564 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1565 | } | ||
1566 | |||
1567 | kfree(sdev->hostdata); | ||
1568 | sdev->hostdata = NULL; | ||
1569 | } | ||
1570 | |||
1571 | /** | ||
1572 | * _scsih_display_sata_capabilities - sata capabilities | ||
1573 | * @ioc: per adapter object | ||
1574 | * @handle: device handle | ||
1575 | * @sdev: scsi device struct | ||
1576 | */ | ||
1577 | static void | ||
1578 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, | ||
1579 | u16 handle, struct scsi_device *sdev) | ||
1580 | { | ||
1581 | Mpi2ConfigReply_t mpi_reply; | ||
1582 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
1583 | u32 ioc_status; | ||
1584 | u16 flags; | ||
1585 | u32 device_info; | ||
1586 | |||
1587 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
1588 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | ||
1589 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1590 | ioc->name, __FILE__, __LINE__, __func__); | ||
1591 | return; | ||
1592 | } | ||
1593 | |||
1594 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1595 | MPI2_IOCSTATUS_MASK; | ||
1596 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
1597 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1598 | ioc->name, __FILE__, __LINE__, __func__); | ||
1599 | return; | ||
1600 | } | ||
1601 | |||
1602 | flags = le16_to_cpu(sas_device_pg0.Flags); | ||
1603 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | ||
1604 | |||
1605 | sdev_printk(KERN_INFO, sdev, | ||
1606 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " | ||
1607 | "sw_preserve(%s)\n", | ||
1608 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", | ||
1609 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", | ||
1610 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : | ||
1611 | "n", | ||
1612 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", | ||
1613 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", | ||
1614 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); | ||
1615 | } | ||
1616 | |||
1617 | /** | ||
1618 | * _scsih_is_raid - return boolean indicating device is raid volume | ||
1619 | * @dev the device struct object | ||
1620 | */ | ||
1621 | static int | ||
1622 | _scsih_is_raid(struct device *dev) | ||
1623 | { | ||
1624 | struct scsi_device *sdev = to_scsi_device(dev); | ||
1625 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); | ||
1626 | |||
1627 | if (ioc->is_warpdrive) | ||
1628 | return 0; | ||
1629 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; | ||
1630 | } | ||
1631 | |||
1632 | /** | ||
1633 | * _scsih_get_resync - get raid volume resync percent complete | ||
1634 | * @dev the device struct object | ||
1635 | */ | ||
1636 | static void | ||
1637 | _scsih_get_resync(struct device *dev) | ||
1638 | { | ||
1639 | struct scsi_device *sdev = to_scsi_device(dev); | ||
1640 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); | ||
1641 | static struct _raid_device *raid_device; | ||
1642 | unsigned long flags; | ||
1643 | Mpi2RaidVolPage0_t vol_pg0; | ||
1644 | Mpi2ConfigReply_t mpi_reply; | ||
1645 | u32 volume_status_flags; | ||
1646 | u8 percent_complete; | ||
1647 | u16 handle; | ||
1648 | |||
1649 | percent_complete = 0; | ||
1650 | handle = 0; | ||
1651 | if (ioc->is_warpdrive) | ||
1652 | goto out; | ||
1653 | |||
1654 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1655 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | ||
1656 | sdev->channel); | ||
1657 | if (raid_device) { | ||
1658 | handle = raid_device->handle; | ||
1659 | percent_complete = raid_device->percent_complete; | ||
1660 | } | ||
1661 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1662 | |||
1663 | if (!handle) | ||
1664 | goto out; | ||
1665 | |||
1666 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | ||
1667 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | ||
1668 | sizeof(Mpi2RaidVolPage0_t))) { | ||
1669 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1670 | ioc->name, __FILE__, __LINE__, __func__); | ||
1671 | percent_complete = 0; | ||
1672 | goto out; | ||
1673 | } | ||
1674 | |||
1675 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); | ||
1676 | if (!(volume_status_flags & | ||
1677 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) | ||
1678 | percent_complete = 0; | ||
1679 | |||
1680 | out: | ||
1681 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); | ||
1682 | } | ||
1683 | |||
1684 | /** | ||
1685 | * _scsih_get_state - get raid volume level | ||
1686 | * @dev the device struct object | ||
1687 | */ | ||
1688 | static void | ||
1689 | _scsih_get_state(struct device *dev) | ||
1690 | { | ||
1691 | struct scsi_device *sdev = to_scsi_device(dev); | ||
1692 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); | ||
1693 | static struct _raid_device *raid_device; | ||
1694 | unsigned long flags; | ||
1695 | Mpi2RaidVolPage0_t vol_pg0; | ||
1696 | Mpi2ConfigReply_t mpi_reply; | ||
1697 | u32 volstate; | ||
1698 | enum raid_state state = RAID_STATE_UNKNOWN; | ||
1699 | u16 handle = 0; | ||
1700 | |||
1701 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1702 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, | ||
1703 | sdev->channel); | ||
1704 | if (raid_device) | ||
1705 | handle = raid_device->handle; | ||
1706 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1707 | |||
1708 | if (!raid_device) | ||
1709 | goto out; | ||
1710 | |||
1711 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, | ||
1712 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | ||
1713 | sizeof(Mpi2RaidVolPage0_t))) { | ||
1714 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1715 | ioc->name, __FILE__, __LINE__, __func__); | ||
1716 | goto out; | ||
1717 | } | ||
1718 | |||
1719 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); | ||
1720 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { | ||
1721 | state = RAID_STATE_RESYNCING; | ||
1722 | goto out; | ||
1723 | } | ||
1724 | |||
1725 | switch (vol_pg0.VolumeState) { | ||
1726 | case MPI2_RAID_VOL_STATE_OPTIMAL: | ||
1727 | case MPI2_RAID_VOL_STATE_ONLINE: | ||
1728 | state = RAID_STATE_ACTIVE; | ||
1729 | break; | ||
1730 | case MPI2_RAID_VOL_STATE_DEGRADED: | ||
1731 | state = RAID_STATE_DEGRADED; | ||
1732 | break; | ||
1733 | case MPI2_RAID_VOL_STATE_FAILED: | ||
1734 | case MPI2_RAID_VOL_STATE_MISSING: | ||
1735 | state = RAID_STATE_OFFLINE; | ||
1736 | break; | ||
1737 | } | ||
1738 | out: | ||
1739 | raid_set_state(mpt2sas_raid_template, dev, state); | ||
1740 | } | ||
1741 | |||
1742 | /** | ||
1743 | * _scsih_set_level - set raid level | ||
1744 | * @sdev: scsi device struct | ||
1745 | * @volume_type: volume type | ||
1746 | */ | ||
1747 | static void | ||
1748 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) | ||
1749 | { | ||
1750 | enum raid_level level = RAID_LEVEL_UNKNOWN; | ||
1751 | |||
1752 | switch (volume_type) { | ||
1753 | case MPI2_RAID_VOL_TYPE_RAID0: | ||
1754 | level = RAID_LEVEL_0; | ||
1755 | break; | ||
1756 | case MPI2_RAID_VOL_TYPE_RAID10: | ||
1757 | level = RAID_LEVEL_10; | ||
1758 | break; | ||
1759 | case MPI2_RAID_VOL_TYPE_RAID1E: | ||
1760 | level = RAID_LEVEL_1E; | ||
1761 | break; | ||
1762 | case MPI2_RAID_VOL_TYPE_RAID1: | ||
1763 | level = RAID_LEVEL_1; | ||
1764 | break; | ||
1765 | } | ||
1766 | |||
1767 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); | ||
1768 | } | ||
1769 | |||
1770 | /** | ||
1771 | * _scsih_get_volume_capabilities - volume capabilities | ||
1772 | * @ioc: per adapter object | ||
1773 | * @sas_device: the raid_device object | ||
1774 | * | ||
1775 | * Returns 0 for success, else 1 | ||
1776 | */ | ||
1777 | static int | ||
1778 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, | ||
1779 | struct _raid_device *raid_device) | ||
1780 | { | ||
1781 | Mpi2RaidVolPage0_t *vol_pg0; | ||
1782 | Mpi2RaidPhysDiskPage0_t pd_pg0; | ||
1783 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
1784 | Mpi2ConfigReply_t mpi_reply; | ||
1785 | u16 sz; | ||
1786 | u8 num_pds; | ||
1787 | |||
1788 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, | ||
1789 | &num_pds)) || !num_pds) { | ||
1790 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
1791 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | ||
1792 | __func__)); | ||
1793 | return 1; | ||
1794 | } | ||
1795 | |||
1796 | raid_device->num_pds = num_pds; | ||
1797 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | ||
1798 | sizeof(Mpi2RaidVol0PhysDisk_t)); | ||
1799 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | ||
1800 | if (!vol_pg0) { | ||
1801 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
1802 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | ||
1803 | __func__)); | ||
1804 | return 1; | ||
1805 | } | ||
1806 | |||
1807 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | ||
1808 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | ||
1809 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
1810 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, | ||
1811 | __func__)); | ||
1812 | kfree(vol_pg0); | ||
1813 | return 1; | ||
1814 | } | ||
1815 | |||
1816 | raid_device->volume_type = vol_pg0->VolumeType; | ||
1817 | |||
1818 | /* figure out what the underlying devices are by | ||
1819 | * obtaining the device_info bits for the 1st device | ||
1820 | */ | ||
1821 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | ||
1822 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | ||
1823 | vol_pg0->PhysDisk[0].PhysDiskNum))) { | ||
1824 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, | ||
1825 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | ||
1826 | le16_to_cpu(pd_pg0.DevHandle)))) { | ||
1827 | raid_device->device_info = | ||
1828 | le32_to_cpu(sas_device_pg0.DeviceInfo); | ||
1829 | } | ||
1830 | } | ||
1831 | |||
1832 | kfree(vol_pg0); | ||
1833 | return 0; | ||
1834 | } | ||
1835 | /** | ||
1836 | * _scsih_disable_ddio - Disable direct I/O for all the volumes | ||
1837 | * @ioc: per adapter object | ||
1838 | */ | ||
1839 | static void | ||
1840 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) | ||
1841 | { | ||
1842 | Mpi2RaidVolPage1_t vol_pg1; | ||
1843 | Mpi2ConfigReply_t mpi_reply; | ||
1844 | struct _raid_device *raid_device; | ||
1845 | u16 handle; | ||
1846 | u16 ioc_status; | ||
1847 | unsigned long flags; | ||
1848 | |||
1849 | handle = 0xFFFF; | ||
1850 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | ||
1851 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | ||
1852 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1853 | MPI2_IOCSTATUS_MASK; | ||
1854 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) | ||
1855 | break; | ||
1856 | handle = le16_to_cpu(vol_pg1.DevHandle); | ||
1857 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
1858 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | ||
1859 | if (raid_device) | ||
1860 | raid_device->direct_io_enabled = 0; | ||
1861 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
1862 | } | ||
1863 | return; | ||
1864 | } | ||
1865 | |||
1866 | |||
1867 | /** | ||
1868 | * _scsih_get_num_volumes - Get number of volumes in the ioc | ||
1869 | * @ioc: per adapter object | ||
1870 | */ | ||
1871 | static u8 | ||
1872 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) | ||
1873 | { | ||
1874 | Mpi2RaidVolPage1_t vol_pg1; | ||
1875 | Mpi2ConfigReply_t mpi_reply; | ||
1876 | u16 handle; | ||
1877 | u8 vol_cnt = 0; | ||
1878 | u16 ioc_status; | ||
1879 | |||
1880 | handle = 0xFFFF; | ||
1881 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | ||
1882 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | ||
1883 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1884 | MPI2_IOCSTATUS_MASK; | ||
1885 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) | ||
1886 | break; | ||
1887 | vol_cnt++; | ||
1888 | handle = le16_to_cpu(vol_pg1.DevHandle); | ||
1889 | } | ||
1890 | return vol_cnt; | ||
1891 | } | ||
1892 | |||
1893 | |||
1894 | /** | ||
1895 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. | ||
1896 | * @ioc: per adapter object | ||
1897 | * @raid_device: the raid_device object | ||
1898 | */ | ||
1899 | static void | ||
1900 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, | ||
1901 | struct _raid_device *raid_device) | ||
1902 | { | ||
1903 | Mpi2RaidVolPage0_t *vol_pg0; | ||
1904 | Mpi2RaidPhysDiskPage0_t pd_pg0; | ||
1905 | Mpi2ConfigReply_t mpi_reply; | ||
1906 | u16 sz; | ||
1907 | u8 num_pds, count; | ||
1908 | unsigned long stripe_sz, block_sz; | ||
1909 | u8 stripe_exp, block_exp; | ||
1910 | u64 dev_max_lba; | ||
1911 | |||
1912 | if (!ioc->is_warpdrive) | ||
1913 | return; | ||
1914 | |||
1915 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { | ||
1916 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
1917 | "globally as drives are exposed\n", ioc->name); | ||
1918 | return; | ||
1919 | } | ||
1920 | if (_scsih_get_num_volumes(ioc) > 1) { | ||
1921 | _scsih_disable_ddio(ioc); | ||
1922 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
1923 | "globally as number of drives > 1\n", ioc->name); | ||
1924 | return; | ||
1925 | } | ||
1926 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, | ||
1927 | &num_pds)) || !num_pds) { | ||
1928 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
1929 | "Failure in computing number of drives\n", ioc->name); | ||
1930 | return; | ||
1931 | } | ||
1932 | |||
1933 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * | ||
1934 | sizeof(Mpi2RaidVol0PhysDisk_t)); | ||
1935 | vol_pg0 = kzalloc(sz, GFP_KERNEL); | ||
1936 | if (!vol_pg0) { | ||
1937 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
1938 | "Memory allocation failure for RVPG0\n", ioc->name); | ||
1939 | return; | ||
1940 | } | ||
1941 | |||
1942 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, | ||
1943 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { | ||
1944 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
1945 | "Failure in retrieving RVPG0\n", ioc->name); | ||
1946 | kfree(vol_pg0); | ||
1947 | return; | ||
1948 | } | ||
1949 | |||
1950 | /* | ||
1951 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds | ||
1952 | * assumed for WARPDRIVE, disable direct I/O | ||
1953 | */ | ||
1954 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { | ||
1955 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " | ||
1956 | "for the drive with handle(0x%04x): num_mem=%d, " | ||
1957 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, | ||
1958 | num_pds, MPT_MAX_WARPDRIVE_PDS); | ||
1959 | kfree(vol_pg0); | ||
1960 | return; | ||
1961 | } | ||
1962 | for (count = 0; count < num_pds; count++) { | ||
1963 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | ||
1964 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, | ||
1965 | vol_pg0->PhysDisk[count].PhysDiskNum) || | ||
1966 | le16_to_cpu(pd_pg0.DevHandle) == | ||
1967 | MPT2SAS_INVALID_DEVICE_HANDLE) { | ||
1968 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " | ||
1969 | "disabled for the drive with handle(0x%04x) member" | ||
1970 | "handle retrieval failed for member number=%d\n", | ||
1971 | ioc->name, raid_device->handle, | ||
1972 | vol_pg0->PhysDisk[count].PhysDiskNum); | ||
1973 | goto out_error; | ||
1974 | } | ||
1975 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ | ||
1976 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); | ||
1977 | if (dev_max_lba >> 32) { | ||
1978 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " | ||
1979 | "disabled for the drive with handle(0x%04x) member" | ||
1980 | "handle (0x%04x) unsupported max lba 0x%016llx\n", | ||
1981 | ioc->name, raid_device->handle, | ||
1982 | le16_to_cpu(pd_pg0.DevHandle), | ||
1983 | (unsigned long long)dev_max_lba); | ||
1984 | goto out_error; | ||
1985 | } | ||
1986 | |||
1987 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); | ||
1988 | } | ||
1989 | |||
1990 | /* | ||
1991 | * Assumption for WD: Direct I/O is not supported if the volume is | ||
1992 | * not RAID0 | ||
1993 | */ | ||
1994 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { | ||
1995 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
1996 | "for the drive with handle(0x%04x): type=%d, " | ||
1997 | "s_sz=%uK, blk_size=%u\n", ioc->name, | ||
1998 | raid_device->handle, raid_device->volume_type, | ||
1999 | (le32_to_cpu(vol_pg0->StripeSize) * | ||
2000 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, | ||
2001 | le16_to_cpu(vol_pg0->BlockSize)); | ||
2002 | goto out_error; | ||
2003 | } | ||
2004 | |||
2005 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); | ||
2006 | stripe_exp = find_first_bit(&stripe_sz, 32); | ||
2007 | if (stripe_exp == 32) { | ||
2008 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
2009 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", | ||
2010 | ioc->name, raid_device->handle, | ||
2011 | (le32_to_cpu(vol_pg0->StripeSize) * | ||
2012 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); | ||
2013 | goto out_error; | ||
2014 | } | ||
2015 | raid_device->stripe_exponent = stripe_exp; | ||
2016 | block_sz = le16_to_cpu(vol_pg0->BlockSize); | ||
2017 | block_exp = find_first_bit(&block_sz, 16); | ||
2018 | if (block_exp == 16) { | ||
2019 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " | ||
2020 | "for the drive with handle(0x%04x) invalid block sz %u\n", | ||
2021 | ioc->name, raid_device->handle, | ||
2022 | le16_to_cpu(vol_pg0->BlockSize)); | ||
2023 | goto out_error; | ||
2024 | } | ||
2025 | raid_device->block_exponent = block_exp; | ||
2026 | raid_device->direct_io_enabled = 1; | ||
2027 | |||
2028 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" | ||
2029 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); | ||
2030 | /* | ||
2031 | * WARPDRIVE: Though the following fields are not used for direct IO, | ||
2032 | * stored for future purpose: | ||
2033 | */ | ||
2034 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); | ||
2035 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); | ||
2036 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); | ||
2037 | |||
2038 | |||
2039 | kfree(vol_pg0); | ||
2040 | return; | ||
2041 | |||
2042 | out_error: | ||
2043 | raid_device->direct_io_enabled = 0; | ||
2044 | for (count = 0; count < num_pds; count++) | ||
2045 | raid_device->pd_handle[count] = 0; | ||
2046 | kfree(vol_pg0); | ||
2047 | return; | ||
2048 | } | ||
2049 | |||
2050 | /** | ||
2051 | * _scsih_enable_tlr - setting TLR flags | ||
2052 | * @ioc: per adapter object | ||
2053 | * @sdev: scsi device struct | ||
2054 | * | ||
2055 | * Enabling Transaction Layer Retries for tape devices when | ||
2056 | * vpd page 0x90 is present | ||
2057 | * | ||
2058 | */ | ||
2059 | static void | ||
2060 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) | ||
2061 | { | ||
2062 | /* only for TAPE */ | ||
2063 | if (sdev->type != TYPE_TAPE) | ||
2064 | return; | ||
2065 | |||
2066 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) | ||
2067 | return; | ||
2068 | |||
2069 | sas_enable_tlr(sdev); | ||
2070 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", | ||
2071 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); | ||
2072 | return; | ||
2073 | |||
2074 | } | ||
2075 | |||
2076 | /** | ||
2077 | * _scsih_slave_configure - device configure routine. | ||
2078 | * @sdev: scsi device struct | ||
2079 | * | ||
2080 | * Returns 0 if ok. Any other return is assumed to be an error and | ||
2081 | * the device is ignored. | ||
2082 | */ | ||
2083 | static int | ||
2084 | _scsih_slave_configure(struct scsi_device *sdev) | ||
2085 | { | ||
2086 | struct Scsi_Host *shost = sdev->host; | ||
2087 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
2088 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
2089 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
2090 | struct _sas_device *sas_device; | ||
2091 | struct _raid_device *raid_device; | ||
2092 | unsigned long flags; | ||
2093 | int qdepth; | ||
2094 | u8 ssp_target = 0; | ||
2095 | char *ds = ""; | ||
2096 | char *r_level = ""; | ||
2097 | u16 handle, volume_handle = 0; | ||
2098 | u64 volume_wwid = 0; | ||
2099 | |||
2100 | qdepth = 1; | ||
2101 | sas_device_priv_data = sdev->hostdata; | ||
2102 | sas_device_priv_data->configured_lun = 1; | ||
2103 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; | ||
2104 | sas_target_priv_data = sas_device_priv_data->sas_target; | ||
2105 | handle = sas_target_priv_data->handle; | ||
2106 | |||
2107 | /* raid volume handling */ | ||
2108 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { | ||
2109 | |||
2110 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
2111 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | ||
2112 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
2113 | if (!raid_device) { | ||
2114 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
2115 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | ||
2116 | __LINE__, __func__)); | ||
2117 | return 1; | ||
2118 | } | ||
2119 | |||
2120 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { | ||
2121 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
2122 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | ||
2123 | __LINE__, __func__)); | ||
2124 | return 1; | ||
2125 | } | ||
2126 | /* | ||
2127 | * WARPDRIVE: Initialize the required data for Direct IO | ||
2128 | */ | ||
2129 | _scsih_init_warpdrive_properties(ioc, raid_device); | ||
2130 | |||
2131 | /* RAID Queue Depth Support | ||
2132 | * IS volume = underlying qdepth of drive type, either | ||
2133 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH | ||
2134 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) | ||
2135 | */ | ||
2136 | if (raid_device->device_info & | ||
2137 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | ||
2138 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; | ||
2139 | ds = "SSP"; | ||
2140 | } else { | ||
2141 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; | ||
2142 | if (raid_device->device_info & | ||
2143 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | ||
2144 | ds = "SATA"; | ||
2145 | else | ||
2146 | ds = "STP"; | ||
2147 | } | ||
2148 | |||
2149 | switch (raid_device->volume_type) { | ||
2150 | case MPI2_RAID_VOL_TYPE_RAID0: | ||
2151 | r_level = "RAID0"; | ||
2152 | break; | ||
2153 | case MPI2_RAID_VOL_TYPE_RAID1E: | ||
2154 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; | ||
2155 | if (ioc->manu_pg10.OEMIdentifier && | ||
2156 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & | ||
2157 | MFG10_GF0_R10_DISPLAY) && | ||
2158 | !(raid_device->num_pds % 2)) | ||
2159 | r_level = "RAID10"; | ||
2160 | else | ||
2161 | r_level = "RAID1E"; | ||
2162 | break; | ||
2163 | case MPI2_RAID_VOL_TYPE_RAID1: | ||
2164 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; | ||
2165 | r_level = "RAID1"; | ||
2166 | break; | ||
2167 | case MPI2_RAID_VOL_TYPE_RAID10: | ||
2168 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; | ||
2169 | r_level = "RAID10"; | ||
2170 | break; | ||
2171 | case MPI2_RAID_VOL_TYPE_UNKNOWN: | ||
2172 | default: | ||
2173 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; | ||
2174 | r_level = "RAIDX"; | ||
2175 | break; | ||
2176 | } | ||
2177 | |||
2178 | if (!ioc->hide_ir_msg) | ||
2179 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " | ||
2180 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", | ||
2181 | r_level, raid_device->handle, | ||
2182 | (unsigned long long)raid_device->wwid, | ||
2183 | raid_device->num_pds, ds); | ||
2184 | _scsih_change_queue_depth(sdev, qdepth); | ||
2185 | /* raid transport support */ | ||
2186 | if (!ioc->is_warpdrive) | ||
2187 | _scsih_set_level(sdev, raid_device->volume_type); | ||
2188 | return 0; | ||
2189 | } | ||
2190 | |||
2191 | /* non-raid handling */ | ||
2192 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { | ||
2193 | if (mpt2sas_config_get_volume_handle(ioc, handle, | ||
2194 | &volume_handle)) { | ||
2195 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
2196 | "failure at %s:%d/%s()!\n", ioc->name, | ||
2197 | __FILE__, __LINE__, __func__)); | ||
2198 | return 1; | ||
2199 | } | ||
2200 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, | ||
2201 | volume_handle, &volume_wwid)) { | ||
2202 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
2203 | "failure at %s:%d/%s()!\n", ioc->name, | ||
2204 | __FILE__, __LINE__, __func__)); | ||
2205 | return 1; | ||
2206 | } | ||
2207 | } | ||
2208 | |||
2209 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
2210 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
2211 | sas_device_priv_data->sas_target->sas_address); | ||
2212 | if (!sas_device) { | ||
2213 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
2214 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT | ||
2215 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, | ||
2216 | __LINE__, __func__)); | ||
2217 | return 1; | ||
2218 | } | ||
2219 | sas_device->volume_handle = volume_handle; | ||
2220 | sas_device->volume_wwid = volume_wwid; | ||
2221 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { | ||
2222 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; | ||
2223 | ssp_target = 1; | ||
2224 | ds = "SSP"; | ||
2225 | } else { | ||
2226 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; | ||
2227 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | ||
2228 | ds = "STP"; | ||
2229 | else if (sas_device->device_info & | ||
2230 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | ||
2231 | ds = "SATA"; | ||
2232 | } | ||
2233 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " | ||
2234 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", | ||
2235 | ds, sas_device->handle, | ||
2236 | (unsigned long long)sas_device->sas_address, | ||
2237 | sas_device->phy, | ||
2238 | (unsigned long long)sas_device->device_name); | ||
2239 | sdev_printk(KERN_INFO, sdev, "%s: " | ||
2240 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, | ||
2241 | (unsigned long long) sas_device->enclosure_logical_id, | ||
2242 | sas_device->slot); | ||
2243 | |||
2244 | sas_device_put(sas_device); | ||
2245 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
2246 | if (!ssp_target) | ||
2247 | _scsih_display_sata_capabilities(ioc, handle, sdev); | ||
2248 | |||
2249 | _scsih_change_queue_depth(sdev, qdepth); | ||
2250 | |||
2251 | if (ssp_target) { | ||
2252 | sas_read_port_mode_page(sdev); | ||
2253 | _scsih_enable_tlr(ioc, sdev); | ||
2254 | } | ||
2255 | |||
2256 | return 0; | ||
2257 | } | ||
2258 | |||
2259 | /** | ||
2260 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk | ||
2261 | * @sdev: scsi device struct | ||
2262 | * @bdev: pointer to block device context | ||
2263 | * @capacity: device size (in 512 byte sectors) | ||
2264 | * @params: three element array to place output: | ||
2265 | * params[0] number of heads (max 255) | ||
2266 | * params[1] number of sectors (max 63) | ||
2267 | * params[2] number of cylinders | ||
2268 | * | ||
2269 | * Return nothing. | ||
2270 | */ | ||
2271 | static int | ||
2272 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, | ||
2273 | sector_t capacity, int params[]) | ||
2274 | { | ||
2275 | int heads; | ||
2276 | int sectors; | ||
2277 | sector_t cylinders; | ||
2278 | ulong dummy; | ||
2279 | |||
2280 | heads = 64; | ||
2281 | sectors = 32; | ||
2282 | |||
2283 | dummy = heads * sectors; | ||
2284 | cylinders = capacity; | ||
2285 | sector_div(cylinders, dummy); | ||
2286 | |||
2287 | /* | ||
2288 | * Handle extended translation size for logical drives | ||
2289 | * > 1Gb | ||
2290 | */ | ||
2291 | if ((ulong)capacity >= 0x200000) { | ||
2292 | heads = 255; | ||
2293 | sectors = 63; | ||
2294 | dummy = heads * sectors; | ||
2295 | cylinders = capacity; | ||
2296 | sector_div(cylinders, dummy); | ||
2297 | } | ||
2298 | |||
2299 | /* return result */ | ||
2300 | params[0] = heads; | ||
2301 | params[1] = sectors; | ||
2302 | params[2] = cylinders; | ||
2303 | |||
2304 | return 0; | ||
2305 | } | ||
2306 | |||
2307 | /** | ||
2308 | * _scsih_response_code - translation of device response code | ||
2309 | * @ioc: per adapter object | ||
2310 | * @response_code: response code returned by the device | ||
2311 | * | ||
2312 | * Return nothing. | ||
2313 | */ | ||
2314 | static void | ||
2315 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) | ||
2316 | { | ||
2317 | char *desc; | ||
2318 | |||
2319 | switch (response_code) { | ||
2320 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: | ||
2321 | desc = "task management request completed"; | ||
2322 | break; | ||
2323 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: | ||
2324 | desc = "invalid frame"; | ||
2325 | break; | ||
2326 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: | ||
2327 | desc = "task management request not supported"; | ||
2328 | break; | ||
2329 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: | ||
2330 | desc = "task management request failed"; | ||
2331 | break; | ||
2332 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: | ||
2333 | desc = "task management request succeeded"; | ||
2334 | break; | ||
2335 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: | ||
2336 | desc = "invalid lun"; | ||
2337 | break; | ||
2338 | case 0xA: | ||
2339 | desc = "overlapped tag attempted"; | ||
2340 | break; | ||
2341 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: | ||
2342 | desc = "task queued, however not sent to target"; | ||
2343 | break; | ||
2344 | default: | ||
2345 | desc = "unknown"; | ||
2346 | break; | ||
2347 | } | ||
2348 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", | ||
2349 | ioc->name, response_code, desc); | ||
2350 | } | ||
2351 | |||
2352 | /** | ||
2353 | * _scsih_tm_done - tm completion routine | ||
2354 | * @ioc: per adapter object | ||
2355 | * @smid: system request message index | ||
2356 | * @msix_index: MSIX table index supplied by the OS | ||
2357 | * @reply: reply message frame(lower 32bit addr) | ||
2358 | * Context: none. | ||
2359 | * | ||
2360 | * The callback handler when using scsih_issue_tm. | ||
2361 | * | ||
2362 | * Return 1 meaning mf should be freed from _base_interrupt | ||
2363 | * 0 means the mf is freed from this function. | ||
2364 | */ | ||
2365 | static u8 | ||
2366 | _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | ||
2367 | { | ||
2368 | MPI2DefaultReply_t *mpi_reply; | ||
2369 | |||
2370 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) | ||
2371 | return 1; | ||
2372 | if (ioc->tm_cmds.smid != smid) | ||
2373 | return 1; | ||
2374 | mpt2sas_base_flush_reply_queues(ioc); | ||
2375 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; | ||
2376 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
2377 | if (mpi_reply) { | ||
2378 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); | ||
2379 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
2380 | } | ||
2381 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; | ||
2382 | complete(&ioc->tm_cmds.done); | ||
2383 | return 1; | ||
2384 | } | ||
2385 | |||
2386 | /** | ||
2387 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy | ||
2388 | * @ioc: per adapter object | ||
2389 | * @handle: device handle | ||
2390 | * | ||
2391 | * During taskmangement request, we need to freeze the device queue. | ||
2392 | */ | ||
2393 | void | ||
2394 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
2395 | { | ||
2396 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
2397 | struct scsi_device *sdev; | ||
2398 | u8 skip = 0; | ||
2399 | |||
2400 | shost_for_each_device(sdev, ioc->shost) { | ||
2401 | if (skip) | ||
2402 | continue; | ||
2403 | sas_device_priv_data = sdev->hostdata; | ||
2404 | if (!sas_device_priv_data) | ||
2405 | continue; | ||
2406 | if (sas_device_priv_data->sas_target->handle == handle) { | ||
2407 | sas_device_priv_data->sas_target->tm_busy = 1; | ||
2408 | skip = 1; | ||
2409 | ioc->ignore_loginfos = 1; | ||
2410 | } | ||
2411 | } | ||
2412 | } | ||
2413 | |||
2414 | /** | ||
2415 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy | ||
2416 | * @ioc: per adapter object | ||
2417 | * @handle: device handle | ||
2418 | * | ||
2419 | * During taskmangement request, we need to freeze the device queue. | ||
2420 | */ | ||
2421 | void | ||
2422 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
2423 | { | ||
2424 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
2425 | struct scsi_device *sdev; | ||
2426 | u8 skip = 0; | ||
2427 | |||
2428 | shost_for_each_device(sdev, ioc->shost) { | ||
2429 | if (skip) | ||
2430 | continue; | ||
2431 | sas_device_priv_data = sdev->hostdata; | ||
2432 | if (!sas_device_priv_data) | ||
2433 | continue; | ||
2434 | if (sas_device_priv_data->sas_target->handle == handle) { | ||
2435 | sas_device_priv_data->sas_target->tm_busy = 0; | ||
2436 | skip = 1; | ||
2437 | ioc->ignore_loginfos = 0; | ||
2438 | } | ||
2439 | } | ||
2440 | } | ||
2441 | |||
2442 | |||
2443 | /** | ||
2444 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests | ||
2445 | * @ioc: per adapter struct | ||
2446 | * @device_handle: device handle | ||
2447 | * @channel: the channel assigned by the OS | ||
2448 | * @id: the id assigned by the OS | ||
2449 | * @lun: lun number | ||
2450 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) | ||
2451 | * @smid_task: smid assigned to the task | ||
2452 | * @timeout: timeout in seconds | ||
2453 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF | ||
2454 | * Context: user | ||
2455 | * | ||
2456 | * A generic API for sending task management requests to firmware. | ||
2457 | * | ||
2458 | * The callback index is set inside `ioc->tm_cb_idx`. | ||
2459 | * | ||
2460 | * Return SUCCESS or FAILED. | ||
2461 | */ | ||
2462 | int | ||
2463 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, | ||
2464 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, | ||
2465 | enum mutex_type m_type) | ||
2466 | { | ||
2467 | Mpi2SCSITaskManagementRequest_t *mpi_request; | ||
2468 | Mpi2SCSITaskManagementReply_t *mpi_reply; | ||
2469 | u16 smid = 0; | ||
2470 | u32 ioc_state; | ||
2471 | unsigned long timeleft; | ||
2472 | struct scsiio_tracker *scsi_lookup = NULL; | ||
2473 | int rc; | ||
2474 | |||
2475 | if (m_type == TM_MUTEX_ON) | ||
2476 | mutex_lock(&ioc->tm_cmds.mutex); | ||
2477 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { | ||
2478 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", | ||
2479 | __func__, ioc->name); | ||
2480 | rc = FAILED; | ||
2481 | goto err_out; | ||
2482 | } | ||
2483 | |||
2484 | if (ioc->shost_recovery || ioc->remove_host || | ||
2485 | ioc->pci_error_recovery) { | ||
2486 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", | ||
2487 | __func__, ioc->name); | ||
2488 | rc = FAILED; | ||
2489 | goto err_out; | ||
2490 | } | ||
2491 | |||
2492 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); | ||
2493 | if (ioc_state & MPI2_DOORBELL_USED) { | ||
2494 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " | ||
2495 | "active!\n", ioc->name)); | ||
2496 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
2497 | FORCE_BIG_HAMMER); | ||
2498 | rc = (!rc) ? SUCCESS : FAILED; | ||
2499 | goto err_out; | ||
2500 | } | ||
2501 | |||
2502 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { | ||
2503 | mpt2sas_base_fault_info(ioc, ioc_state & | ||
2504 | MPI2_DOORBELL_DATA_MASK); | ||
2505 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
2506 | FORCE_BIG_HAMMER); | ||
2507 | rc = (!rc) ? SUCCESS : FAILED; | ||
2508 | goto err_out; | ||
2509 | } | ||
2510 | |||
2511 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); | ||
2512 | if (!smid) { | ||
2513 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
2514 | ioc->name, __func__); | ||
2515 | rc = FAILED; | ||
2516 | goto err_out; | ||
2517 | } | ||
2518 | |||
2519 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) | ||
2520 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; | ||
2521 | |||
2522 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," | ||
2523 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, | ||
2524 | smid_task)); | ||
2525 | ioc->tm_cmds.status = MPT2_CMD_PENDING; | ||
2526 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
2527 | ioc->tm_cmds.smid = smid; | ||
2528 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | ||
2529 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); | ||
2530 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | ||
2531 | mpi_request->DevHandle = cpu_to_le16(handle); | ||
2532 | mpi_request->TaskType = type; | ||
2533 | mpi_request->TaskMID = cpu_to_le16(smid_task); | ||
2534 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); | ||
2535 | mpt2sas_scsih_set_tm_flag(ioc, handle); | ||
2536 | init_completion(&ioc->tm_cmds.done); | ||
2537 | mpt2sas_base_put_smid_hi_priority(ioc, smid); | ||
2538 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); | ||
2539 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { | ||
2540 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
2541 | ioc->name, __func__); | ||
2542 | _debug_dump_mf(mpi_request, | ||
2543 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | ||
2544 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { | ||
2545 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
2546 | FORCE_BIG_HAMMER); | ||
2547 | rc = (!rc) ? SUCCESS : FAILED; | ||
2548 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; | ||
2549 | mpt2sas_scsih_clear_tm_flag(ioc, handle); | ||
2550 | goto err_out; | ||
2551 | } | ||
2552 | } | ||
2553 | |||
2554 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { | ||
2555 | mpi_reply = ioc->tm_cmds.reply; | ||
2556 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " | ||
2557 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", | ||
2558 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | ||
2559 | le32_to_cpu(mpi_reply->IOCLogInfo), | ||
2560 | le32_to_cpu(mpi_reply->TerminationCount))); | ||
2561 | if (ioc->logging_level & MPT_DEBUG_TM) { | ||
2562 | _scsih_response_code(ioc, mpi_reply->ResponseCode); | ||
2563 | if (mpi_reply->IOCStatus) | ||
2564 | _debug_dump_mf(mpi_request, | ||
2565 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); | ||
2566 | } | ||
2567 | } | ||
2568 | |||
2569 | switch (type) { | ||
2570 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: | ||
2571 | rc = SUCCESS; | ||
2572 | if (scsi_lookup->scmd == NULL) | ||
2573 | break; | ||
2574 | rc = FAILED; | ||
2575 | break; | ||
2576 | |||
2577 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: | ||
2578 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) | ||
2579 | rc = FAILED; | ||
2580 | else | ||
2581 | rc = SUCCESS; | ||
2582 | break; | ||
2583 | |||
2584 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: | ||
2585 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: | ||
2586 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) | ||
2587 | rc = FAILED; | ||
2588 | else | ||
2589 | rc = SUCCESS; | ||
2590 | break; | ||
2591 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: | ||
2592 | rc = SUCCESS; | ||
2593 | break; | ||
2594 | default: | ||
2595 | rc = FAILED; | ||
2596 | break; | ||
2597 | } | ||
2598 | |||
2599 | mpt2sas_scsih_clear_tm_flag(ioc, handle); | ||
2600 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; | ||
2601 | if (m_type == TM_MUTEX_ON) | ||
2602 | mutex_unlock(&ioc->tm_cmds.mutex); | ||
2603 | |||
2604 | return rc; | ||
2605 | |||
2606 | err_out: | ||
2607 | if (m_type == TM_MUTEX_ON) | ||
2608 | mutex_unlock(&ioc->tm_cmds.mutex); | ||
2609 | return rc; | ||
2610 | } | ||
2611 | |||
2612 | /** | ||
2613 | * _scsih_tm_display_info - displays info about the device | ||
2614 | * @ioc: per adapter struct | ||
2615 | * @scmd: pointer to scsi command object | ||
2616 | * | ||
2617 | * Called by task management callback handlers. | ||
2618 | */ | ||
2619 | static void | ||
2620 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) | ||
2621 | { | ||
2622 | struct scsi_target *starget = scmd->device->sdev_target; | ||
2623 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; | ||
2624 | struct _sas_device *sas_device = NULL; | ||
2625 | unsigned long flags; | ||
2626 | char *device_str = NULL; | ||
2627 | |||
2628 | if (!priv_target) | ||
2629 | return; | ||
2630 | if (ioc->hide_ir_msg) | ||
2631 | device_str = "WarpDrive"; | ||
2632 | else | ||
2633 | device_str = "volume"; | ||
2634 | |||
2635 | scsi_print_command(scmd); | ||
2636 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | ||
2637 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " | ||
2638 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, | ||
2639 | device_str, (unsigned long long)priv_target->sas_address); | ||
2640 | } else { | ||
2641 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
2642 | sas_device = __mpt2sas_get_sdev_from_target(ioc, priv_target); | ||
2643 | if (sas_device) { | ||
2644 | if (priv_target->flags & | ||
2645 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | ||
2646 | starget_printk(KERN_INFO, starget, | ||
2647 | "volume handle(0x%04x), " | ||
2648 | "volume wwid(0x%016llx)\n", | ||
2649 | sas_device->volume_handle, | ||
2650 | (unsigned long long)sas_device->volume_wwid); | ||
2651 | } | ||
2652 | starget_printk(KERN_INFO, starget, | ||
2653 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", | ||
2654 | sas_device->handle, | ||
2655 | (unsigned long long)sas_device->sas_address, | ||
2656 | sas_device->phy); | ||
2657 | starget_printk(KERN_INFO, starget, | ||
2658 | "enclosure_logical_id(0x%016llx), slot(%d)\n", | ||
2659 | (unsigned long long)sas_device->enclosure_logical_id, | ||
2660 | sas_device->slot); | ||
2661 | |||
2662 | sas_device_put(sas_device); | ||
2663 | } | ||
2664 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
2665 | } | ||
2666 | } | ||
2667 | |||
2668 | /** | ||
2669 | * _scsih_abort - eh threads main abort routine | ||
2670 | * @scmd: pointer to scsi command object | ||
2671 | * | ||
2672 | * Returns SUCCESS if command aborted else FAILED | ||
2673 | */ | ||
2674 | static int | ||
2675 | _scsih_abort(struct scsi_cmnd *scmd) | ||
2676 | { | ||
2677 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | ||
2678 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
2679 | u16 smid; | ||
2680 | u16 handle; | ||
2681 | int r; | ||
2682 | |||
2683 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " | ||
2684 | "scmd(%p)\n", scmd); | ||
2685 | _scsih_tm_display_info(ioc, scmd); | ||
2686 | |||
2687 | sas_device_priv_data = scmd->device->hostdata; | ||
2688 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | ||
2689 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " | ||
2690 | "scmd(%p)\n", scmd); | ||
2691 | scmd->result = DID_NO_CONNECT << 16; | ||
2692 | scmd->scsi_done(scmd); | ||
2693 | r = SUCCESS; | ||
2694 | goto out; | ||
2695 | } | ||
2696 | |||
2697 | /* search for the command */ | ||
2698 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); | ||
2699 | if (!smid) { | ||
2700 | scmd->result = DID_RESET << 16; | ||
2701 | r = SUCCESS; | ||
2702 | goto out; | ||
2703 | } | ||
2704 | |||
2705 | /* for hidden raid components and volumes this is not supported */ | ||
2706 | if (sas_device_priv_data->sas_target->flags & | ||
2707 | MPT_TARGET_FLAGS_RAID_COMPONENT || | ||
2708 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { | ||
2709 | scmd->result = DID_RESET << 16; | ||
2710 | r = FAILED; | ||
2711 | goto out; | ||
2712 | } | ||
2713 | |||
2714 | mpt2sas_halt_firmware(ioc); | ||
2715 | |||
2716 | handle = sas_device_priv_data->sas_target->handle; | ||
2717 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | ||
2718 | scmd->device->id, scmd->device->lun, | ||
2719 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON); | ||
2720 | |||
2721 | out: | ||
2722 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", | ||
2723 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | ||
2724 | return r; | ||
2725 | } | ||
2726 | |||
2727 | /** | ||
2728 | * _scsih_dev_reset - eh threads main device reset routine | ||
2729 | * @scmd: pointer to scsi command object | ||
2730 | * | ||
2731 | * Returns SUCCESS if command aborted else FAILED | ||
2732 | */ | ||
2733 | static int | ||
2734 | _scsih_dev_reset(struct scsi_cmnd *scmd) | ||
2735 | { | ||
2736 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | ||
2737 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
2738 | struct _sas_device *sas_device = NULL; | ||
2739 | u16 handle; | ||
2740 | int r; | ||
2741 | |||
2742 | struct scsi_target *starget = scmd->device->sdev_target; | ||
2743 | struct MPT2SAS_TARGET *target_priv_data = starget->hostdata; | ||
2744 | |||
2745 | starget_printk(KERN_INFO, starget, "attempting device reset! " | ||
2746 | "scmd(%p)\n", scmd); | ||
2747 | _scsih_tm_display_info(ioc, scmd); | ||
2748 | |||
2749 | sas_device_priv_data = scmd->device->hostdata; | ||
2750 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | ||
2751 | starget_printk(KERN_INFO, starget, "device been deleted! " | ||
2752 | "scmd(%p)\n", scmd); | ||
2753 | scmd->result = DID_NO_CONNECT << 16; | ||
2754 | scmd->scsi_done(scmd); | ||
2755 | r = SUCCESS; | ||
2756 | goto out; | ||
2757 | } | ||
2758 | |||
2759 | /* for hidden raid components obtain the volume_handle */ | ||
2760 | handle = 0; | ||
2761 | if (sas_device_priv_data->sas_target->flags & | ||
2762 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | ||
2763 | sas_device = mpt2sas_get_sdev_from_target(ioc, | ||
2764 | target_priv_data); | ||
2765 | if (sas_device) | ||
2766 | handle = sas_device->volume_handle; | ||
2767 | } else | ||
2768 | handle = sas_device_priv_data->sas_target->handle; | ||
2769 | |||
2770 | if (!handle) { | ||
2771 | scmd->result = DID_RESET << 16; | ||
2772 | r = FAILED; | ||
2773 | goto out; | ||
2774 | } | ||
2775 | |||
2776 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | ||
2777 | scmd->device->id, scmd->device->lun, | ||
2778 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON); | ||
2779 | |||
2780 | out: | ||
2781 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", | ||
2782 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | ||
2783 | |||
2784 | if (sas_device) | ||
2785 | sas_device_put(sas_device); | ||
2786 | |||
2787 | return r; | ||
2788 | } | ||
2789 | |||
2790 | /** | ||
2791 | * _scsih_target_reset - eh threads main target reset routine | ||
2792 | * @scmd: pointer to scsi command object | ||
2793 | * | ||
2794 | * Returns SUCCESS if command aborted else FAILED | ||
2795 | */ | ||
2796 | static int | ||
2797 | _scsih_target_reset(struct scsi_cmnd *scmd) | ||
2798 | { | ||
2799 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | ||
2800 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
2801 | struct _sas_device *sas_device = NULL; | ||
2802 | u16 handle; | ||
2803 | int r; | ||
2804 | struct scsi_target *starget = scmd->device->sdev_target; | ||
2805 | struct MPT2SAS_TARGET *target_priv_data = starget->hostdata; | ||
2806 | |||
2807 | starget_printk(KERN_INFO, starget, "attempting target reset! " | ||
2808 | "scmd(%p)\n", scmd); | ||
2809 | _scsih_tm_display_info(ioc, scmd); | ||
2810 | |||
2811 | sas_device_priv_data = scmd->device->hostdata; | ||
2812 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | ||
2813 | starget_printk(KERN_INFO, starget, "target been deleted! " | ||
2814 | "scmd(%p)\n", scmd); | ||
2815 | scmd->result = DID_NO_CONNECT << 16; | ||
2816 | scmd->scsi_done(scmd); | ||
2817 | r = SUCCESS; | ||
2818 | goto out; | ||
2819 | } | ||
2820 | |||
2821 | /* for hidden raid components obtain the volume_handle */ | ||
2822 | handle = 0; | ||
2823 | if (sas_device_priv_data->sas_target->flags & | ||
2824 | MPT_TARGET_FLAGS_RAID_COMPONENT) { | ||
2825 | sas_device = mpt2sas_get_sdev_from_target(ioc, | ||
2826 | target_priv_data); | ||
2827 | if (sas_device) | ||
2828 | handle = sas_device->volume_handle; | ||
2829 | } else | ||
2830 | handle = sas_device_priv_data->sas_target->handle; | ||
2831 | |||
2832 | if (!handle) { | ||
2833 | scmd->result = DID_RESET << 16; | ||
2834 | r = FAILED; | ||
2835 | goto out; | ||
2836 | } | ||
2837 | |||
2838 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, | ||
2839 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, | ||
2840 | 30, TM_MUTEX_ON); | ||
2841 | |||
2842 | out: | ||
2843 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", | ||
2844 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | ||
2845 | |||
2846 | if (sas_device) | ||
2847 | sas_device_put(sas_device); | ||
2848 | |||
2849 | return r; | ||
2850 | } | ||
2851 | |||
2852 | /** | ||
2853 | * _scsih_host_reset - eh threads main host reset routine | ||
2854 | * @scmd: pointer to scsi command object | ||
2855 | * | ||
2856 | * Returns SUCCESS if command aborted else FAILED | ||
2857 | */ | ||
2858 | static int | ||
2859 | _scsih_host_reset(struct scsi_cmnd *scmd) | ||
2860 | { | ||
2861 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); | ||
2862 | int r, retval; | ||
2863 | |||
2864 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", | ||
2865 | ioc->name, scmd); | ||
2866 | scsi_print_command(scmd); | ||
2867 | |||
2868 | if (ioc->is_driver_loading) { | ||
2869 | printk(MPT2SAS_INFO_FMT "Blocking the host reset\n", | ||
2870 | ioc->name); | ||
2871 | r = FAILED; | ||
2872 | goto out; | ||
2873 | } | ||
2874 | |||
2875 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
2876 | FORCE_BIG_HAMMER); | ||
2877 | r = (retval < 0) ? FAILED : SUCCESS; | ||
2878 | |||
2879 | out: | ||
2880 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", | ||
2881 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); | ||
2882 | |||
2883 | return r; | ||
2884 | } | ||
2885 | |||
2886 | /** | ||
2887 | * _scsih_fw_event_add - insert and queue up fw_event | ||
2888 | * @ioc: per adapter object | ||
2889 | * @fw_event: object describing the event | ||
2890 | * Context: This function will acquire ioc->fw_event_lock. | ||
2891 | * | ||
2892 | * This adds the firmware event object into link list, then queues it up to | ||
2893 | * be processed from user context. | ||
2894 | * | ||
2895 | * Return nothing. | ||
2896 | */ | ||
2897 | static void | ||
2898 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) | ||
2899 | { | ||
2900 | unsigned long flags; | ||
2901 | |||
2902 | if (ioc->firmware_event_thread == NULL) | ||
2903 | return; | ||
2904 | |||
2905 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | ||
2906 | fw_event_work_get(fw_event); | ||
2907 | list_add_tail(&fw_event->list, &ioc->fw_event_list); | ||
2908 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); | ||
2909 | fw_event_work_get(fw_event); | ||
2910 | queue_delayed_work(ioc->firmware_event_thread, | ||
2911 | &fw_event->delayed_work, 0); | ||
2912 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | ||
2913 | } | ||
2914 | |||
2915 | /** | ||
2916 | * _scsih_fw_event_del_from_list - delete fw_event from the list | ||
2917 | * @ioc: per adapter object | ||
2918 | * @fw_event: object describing the event | ||
2919 | * Context: This function will acquire ioc->fw_event_lock. | ||
2920 | * | ||
2921 | * If the fw_event is on the fw_event_list, remove it and do a put. | ||
2922 | * | ||
2923 | * Return nothing. | ||
2924 | */ | ||
2925 | static void | ||
2926 | _scsih_fw_event_del_from_list(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work | ||
2927 | *fw_event) | ||
2928 | { | ||
2929 | unsigned long flags; | ||
2930 | |||
2931 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | ||
2932 | if (!list_empty(&fw_event->list)) { | ||
2933 | list_del_init(&fw_event->list); | ||
2934 | fw_event_work_put(fw_event); | ||
2935 | } | ||
2936 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | ||
2937 | } | ||
2938 | |||
2939 | /** | ||
2940 | * _scsih_error_recovery_delete_devices - remove devices not responding | ||
2941 | * @ioc: per adapter object | ||
2942 | * | ||
2943 | * Return nothing. | ||
2944 | */ | ||
2945 | static void | ||
2946 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) | ||
2947 | { | ||
2948 | struct fw_event_work *fw_event; | ||
2949 | |||
2950 | if (ioc->is_driver_loading) | ||
2951 | return; | ||
2952 | |||
2953 | fw_event = alloc_fw_event_work(0); | ||
2954 | if (!fw_event) | ||
2955 | return; | ||
2956 | |||
2957 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; | ||
2958 | fw_event->ioc = ioc; | ||
2959 | _scsih_fw_event_add(ioc, fw_event); | ||
2960 | fw_event_work_put(fw_event); | ||
2961 | } | ||
2962 | |||
2963 | /** | ||
2964 | * mpt2sas_port_enable_complete - port enable completed (fake event) | ||
2965 | * @ioc: per adapter object | ||
2966 | * | ||
2967 | * Return nothing. | ||
2968 | */ | ||
2969 | void | ||
2970 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) | ||
2971 | { | ||
2972 | struct fw_event_work *fw_event; | ||
2973 | |||
2974 | fw_event = alloc_fw_event_work(0); | ||
2975 | if (!fw_event) | ||
2976 | return; | ||
2977 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; | ||
2978 | fw_event->ioc = ioc; | ||
2979 | _scsih_fw_event_add(ioc, fw_event); | ||
2980 | fw_event_work_put(fw_event); | ||
2981 | } | ||
2982 | |||
2983 | static struct fw_event_work *dequeue_next_fw_event(struct MPT2SAS_ADAPTER *ioc) | ||
2984 | { | ||
2985 | unsigned long flags; | ||
2986 | struct fw_event_work *fw_event = NULL; | ||
2987 | |||
2988 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | ||
2989 | if (!list_empty(&ioc->fw_event_list)) { | ||
2990 | fw_event = list_first_entry(&ioc->fw_event_list, | ||
2991 | struct fw_event_work, list); | ||
2992 | list_del_init(&fw_event->list); | ||
2993 | } | ||
2994 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | ||
2995 | |||
2996 | return fw_event; | ||
2997 | } | ||
2998 | |||
2999 | /** | ||
3000 | * _scsih_fw_event_cleanup_queue - cleanup event queue | ||
3001 | * @ioc: per adapter object | ||
3002 | * | ||
3003 | * Walk the firmware event queue, either killing timers, or waiting | ||
3004 | * for outstanding events to complete | ||
3005 | * | ||
3006 | * Return nothing. | ||
3007 | */ | ||
3008 | static void | ||
3009 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) | ||
3010 | { | ||
3011 | struct fw_event_work *fw_event; | ||
3012 | |||
3013 | if (list_empty(&ioc->fw_event_list) || | ||
3014 | !ioc->firmware_event_thread || in_interrupt()) | ||
3015 | return; | ||
3016 | |||
3017 | while ((fw_event = dequeue_next_fw_event(ioc))) { | ||
3018 | /* | ||
3019 | * Wait on the fw_event to complete. If this returns 1, then | ||
3020 | * the event was never executed, and we need a put for the | ||
3021 | * reference the delayed_work had on the fw_event. | ||
3022 | * | ||
3023 | * If it did execute, we wait for it to finish, and the put will | ||
3024 | * happen from _firmware_event_work() | ||
3025 | */ | ||
3026 | if (cancel_delayed_work_sync(&fw_event->delayed_work)) | ||
3027 | fw_event_work_put(fw_event); | ||
3028 | |||
3029 | fw_event_work_put(fw_event); | ||
3030 | } | ||
3031 | } | ||
3032 | |||
3033 | /** | ||
3034 | * _scsih_ublock_io_all_device - unblock every device | ||
3035 | * @ioc: per adapter object | ||
3036 | * | ||
3037 | * change the device state from block to running | ||
3038 | */ | ||
3039 | static void | ||
3040 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) | ||
3041 | { | ||
3042 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
3043 | struct scsi_device *sdev; | ||
3044 | |||
3045 | shost_for_each_device(sdev, ioc->shost) { | ||
3046 | sas_device_priv_data = sdev->hostdata; | ||
3047 | if (!sas_device_priv_data) | ||
3048 | continue; | ||
3049 | if (!sas_device_priv_data->block) | ||
3050 | continue; | ||
3051 | sas_device_priv_data->block = 0; | ||
3052 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " | ||
3053 | "handle(0x%04x)\n", | ||
3054 | sas_device_priv_data->sas_target->handle)); | ||
3055 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); | ||
3056 | } | ||
3057 | } | ||
3058 | /** | ||
3059 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING | ||
3060 | * @ioc: per adapter object | ||
3061 | * @handle: device handle | ||
3062 | * | ||
3063 | * During device pull we need to appropiately set the sdev state. | ||
3064 | */ | ||
3065 | static void | ||
3066 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) | ||
3067 | { | ||
3068 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
3069 | struct scsi_device *sdev; | ||
3070 | |||
3071 | shost_for_each_device(sdev, ioc->shost) { | ||
3072 | sas_device_priv_data = sdev->hostdata; | ||
3073 | if (!sas_device_priv_data) | ||
3074 | continue; | ||
3075 | if (!sas_device_priv_data->block) | ||
3076 | continue; | ||
3077 | if (sas_device_priv_data->sas_target->sas_address == | ||
3078 | sas_address) { | ||
3079 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, | ||
3080 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " | ||
3081 | "sas address(0x%016llx)\n", ioc->name, | ||
3082 | (unsigned long long)sas_address)); | ||
3083 | sas_device_priv_data->block = 0; | ||
3084 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); | ||
3085 | } | ||
3086 | } | ||
3087 | } | ||
3088 | |||
3089 | /** | ||
3090 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK | ||
3091 | * @ioc: per adapter object | ||
3092 | * @handle: device handle | ||
3093 | * | ||
3094 | * During device pull we need to appropiately set the sdev state. | ||
3095 | */ | ||
3096 | static void | ||
3097 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) | ||
3098 | { | ||
3099 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
3100 | struct scsi_device *sdev; | ||
3101 | |||
3102 | shost_for_each_device(sdev, ioc->shost) { | ||
3103 | sas_device_priv_data = sdev->hostdata; | ||
3104 | if (!sas_device_priv_data) | ||
3105 | continue; | ||
3106 | if (sas_device_priv_data->block) | ||
3107 | continue; | ||
3108 | sas_device_priv_data->block = 1; | ||
3109 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " | ||
3110 | "handle(0x%04x)\n", | ||
3111 | sas_device_priv_data->sas_target->handle)); | ||
3112 | scsi_internal_device_block(sdev); | ||
3113 | } | ||
3114 | } | ||
3115 | |||
3116 | |||
3117 | /** | ||
3118 | * _scsih_block_io_device - set the device state to SDEV_BLOCK | ||
3119 | * @ioc: per adapter object | ||
3120 | * @handle: device handle | ||
3121 | * | ||
3122 | * During device pull we need to appropiately set the sdev state. | ||
3123 | */ | ||
3124 | static void | ||
3125 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
3126 | { | ||
3127 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
3128 | struct scsi_device *sdev; | ||
3129 | |||
3130 | shost_for_each_device(sdev, ioc->shost) { | ||
3131 | sas_device_priv_data = sdev->hostdata; | ||
3132 | if (!sas_device_priv_data) | ||
3133 | continue; | ||
3134 | if (sas_device_priv_data->block) | ||
3135 | continue; | ||
3136 | if (sas_device_priv_data->sas_target->handle == handle) { | ||
3137 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, | ||
3138 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " | ||
3139 | "handle(0x%04x)\n", ioc->name, handle)); | ||
3140 | sas_device_priv_data->block = 1; | ||
3141 | scsi_internal_device_block(sdev); | ||
3142 | } | ||
3143 | } | ||
3144 | } | ||
3145 | |||
3146 | /** | ||
3147 | * _scsih_block_io_to_children_attached_to_ex | ||
3148 | * @ioc: per adapter object | ||
3149 | * @sas_expander: the sas_device object | ||
3150 | * | ||
3151 | * This routine set sdev state to SDEV_BLOCK for all devices | ||
3152 | * attached to this expander. This function called when expander is | ||
3153 | * pulled. | ||
3154 | */ | ||
3155 | static void | ||
3156 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, | ||
3157 | struct _sas_node *sas_expander) | ||
3158 | { | ||
3159 | struct _sas_port *mpt2sas_port; | ||
3160 | struct _sas_device *sas_device; | ||
3161 | struct _sas_node *expander_sibling; | ||
3162 | unsigned long flags; | ||
3163 | |||
3164 | if (!sas_expander) | ||
3165 | return; | ||
3166 | |||
3167 | list_for_each_entry(mpt2sas_port, | ||
3168 | &sas_expander->sas_port_list, port_list) { | ||
3169 | if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) { | ||
3170 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
3171 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
3172 | mpt2sas_port->remote_identify.sas_address); | ||
3173 | if (sas_device) { | ||
3174 | set_bit(sas_device->handle, | ||
3175 | ioc->blocking_handles); | ||
3176 | sas_device_put(sas_device); | ||
3177 | } | ||
3178 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
3179 | } | ||
3180 | } | ||
3181 | |||
3182 | list_for_each_entry(mpt2sas_port, | ||
3183 | &sas_expander->sas_port_list, port_list) { | ||
3184 | |||
3185 | if (mpt2sas_port->remote_identify.device_type == | ||
3186 | SAS_EDGE_EXPANDER_DEVICE || | ||
3187 | mpt2sas_port->remote_identify.device_type == | ||
3188 | SAS_FANOUT_EXPANDER_DEVICE) { | ||
3189 | expander_sibling = | ||
3190 | mpt2sas_scsih_expander_find_by_sas_address( | ||
3191 | ioc, mpt2sas_port->remote_identify.sas_address); | ||
3192 | _scsih_block_io_to_children_attached_to_ex(ioc, | ||
3193 | expander_sibling); | ||
3194 | } | ||
3195 | } | ||
3196 | } | ||
3197 | |||
3198 | /** | ||
3199 | * _scsih_block_io_to_children_attached_directly | ||
3200 | * @ioc: per adapter object | ||
3201 | * @event_data: topology change event data | ||
3202 | * | ||
3203 | * This routine set sdev state to SDEV_BLOCK for all devices | ||
3204 | * direct attached during device pull. | ||
3205 | */ | ||
3206 | static void | ||
3207 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, | ||
3208 | Mpi2EventDataSasTopologyChangeList_t *event_data) | ||
3209 | { | ||
3210 | int i; | ||
3211 | u16 handle; | ||
3212 | u16 reason_code; | ||
3213 | u8 phy_number; | ||
3214 | |||
3215 | for (i = 0; i < event_data->NumEntries; i++) { | ||
3216 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | ||
3217 | if (!handle) | ||
3218 | continue; | ||
3219 | phy_number = event_data->StartPhyNum + i; | ||
3220 | reason_code = event_data->PHY[i].PhyStatus & | ||
3221 | MPI2_EVENT_SAS_TOPO_RC_MASK; | ||
3222 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) | ||
3223 | _scsih_block_io_device(ioc, handle); | ||
3224 | } | ||
3225 | } | ||
3226 | |||
3227 | /** | ||
3228 | * _scsih_tm_tr_send - send task management request | ||
3229 | * @ioc: per adapter object | ||
3230 | * @handle: device handle | ||
3231 | * Context: interrupt time. | ||
3232 | * | ||
3233 | * This code is to initiate the device removal handshake protocol | ||
3234 | * with controller firmware. This function will issue target reset | ||
3235 | * using high priority request queue. It will send a sas iounit | ||
3236 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. | ||
3237 | * | ||
3238 | * This is designed to send muliple task management request at the same | ||
3239 | * time to the fifo. If the fifo is full, we will append the request, | ||
3240 | * and process it in a future completion. | ||
3241 | */ | ||
3242 | static void | ||
3243 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
3244 | { | ||
3245 | Mpi2SCSITaskManagementRequest_t *mpi_request; | ||
3246 | u16 smid; | ||
3247 | struct _sas_device *sas_device = NULL; | ||
3248 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; | ||
3249 | u64 sas_address = 0; | ||
3250 | unsigned long flags; | ||
3251 | struct _tr_list *delayed_tr; | ||
3252 | u32 ioc_state; | ||
3253 | |||
3254 | if (ioc->remove_host) { | ||
3255 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " | ||
3256 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); | ||
3257 | return; | ||
3258 | } else if (ioc->pci_error_recovery) { | ||
3259 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " | ||
3260 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, | ||
3261 | handle)); | ||
3262 | return; | ||
3263 | } | ||
3264 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
3265 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
3266 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " | ||
3267 | "operational: handle(0x%04x)\n", __func__, ioc->name, | ||
3268 | handle)); | ||
3269 | return; | ||
3270 | } | ||
3271 | |||
3272 | /* if PD, then return */ | ||
3273 | if (test_bit(handle, ioc->pd_handles)) | ||
3274 | return; | ||
3275 | |||
3276 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
3277 | sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle); | ||
3278 | if (sas_device && sas_device->starget && | ||
3279 | sas_device->starget->hostdata) { | ||
3280 | sas_target_priv_data = sas_device->starget->hostdata; | ||
3281 | sas_target_priv_data->deleted = 1; | ||
3282 | sas_address = sas_device->sas_address; | ||
3283 | } | ||
3284 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
3285 | |||
3286 | if (sas_target_priv_data) { | ||
3287 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " | ||
3288 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, | ||
3289 | (unsigned long long)sas_address)); | ||
3290 | _scsih_ublock_io_device(ioc, sas_address); | ||
3291 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; | ||
3292 | } | ||
3293 | |||
3294 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); | ||
3295 | if (!smid) { | ||
3296 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | ||
3297 | if (!delayed_tr) | ||
3298 | goto out; | ||
3299 | INIT_LIST_HEAD(&delayed_tr->list); | ||
3300 | delayed_tr->handle = handle; | ||
3301 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | ||
3302 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3303 | "DELAYED:tr:handle(0x%04x), (open)\n", | ||
3304 | ioc->name, handle)); | ||
3305 | goto out; | ||
3306 | } | ||
3307 | |||
3308 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " | ||
3309 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, | ||
3310 | ioc->tm_tr_cb_idx)); | ||
3311 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3312 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | ||
3313 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | ||
3314 | mpi_request->DevHandle = cpu_to_le16(handle); | ||
3315 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | ||
3316 | mpt2sas_base_put_smid_hi_priority(ioc, smid); | ||
3317 | out: | ||
3318 | if (sas_device) | ||
3319 | sas_device_put(sas_device); | ||
3320 | } | ||
3321 | |||
3322 | |||
3323 | |||
3324 | /** | ||
3325 | * _scsih_sas_control_complete - completion routine | ||
3326 | * @ioc: per adapter object | ||
3327 | * @smid: system request message index | ||
3328 | * @msix_index: MSIX table index supplied by the OS | ||
3329 | * @reply: reply message frame(lower 32bit addr) | ||
3330 | * Context: interrupt time. | ||
3331 | * | ||
3332 | * This is the sas iounit control completion routine. | ||
3333 | * This code is part of the code to initiate the device removal | ||
3334 | * handshake protocol with controller firmware. | ||
3335 | * | ||
3336 | * Return 1 meaning mf should be freed from _base_interrupt | ||
3337 | * 0 means the mf is freed from this function. | ||
3338 | */ | ||
3339 | static u8 | ||
3340 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
3341 | u8 msix_index, u32 reply) | ||
3342 | { | ||
3343 | Mpi2SasIoUnitControlReply_t *mpi_reply = | ||
3344 | mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
3345 | if (likely(mpi_reply)) { | ||
3346 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3347 | "sc_complete:handle(0x%04x), (open) " | ||
3348 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
3349 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, | ||
3350 | le16_to_cpu(mpi_reply->IOCStatus), | ||
3351 | le32_to_cpu(mpi_reply->IOCLogInfo))); | ||
3352 | } else { | ||
3353 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", | ||
3354 | ioc->name, __FILE__, __LINE__, __func__); | ||
3355 | } | ||
3356 | return 1; | ||
3357 | } | ||
3358 | |||
3359 | /** | ||
3360 | * _scsih_tm_tr_volume_send - send target reset request for volumes | ||
3361 | * @ioc: per adapter object | ||
3362 | * @handle: device handle | ||
3363 | * Context: interrupt time. | ||
3364 | * | ||
3365 | * This is designed to send muliple task management request at the same | ||
3366 | * time to the fifo. If the fifo is full, we will append the request, | ||
3367 | * and process it in a future completion. | ||
3368 | */ | ||
3369 | static void | ||
3370 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
3371 | { | ||
3372 | Mpi2SCSITaskManagementRequest_t *mpi_request; | ||
3373 | u16 smid; | ||
3374 | struct _tr_list *delayed_tr; | ||
3375 | |||
3376 | if (ioc->shost_recovery || ioc->remove_host || | ||
3377 | ioc->pci_error_recovery) { | ||
3378 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " | ||
3379 | "progress!\n", __func__, ioc->name)); | ||
3380 | return; | ||
3381 | } | ||
3382 | |||
3383 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); | ||
3384 | if (!smid) { | ||
3385 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | ||
3386 | if (!delayed_tr) | ||
3387 | return; | ||
3388 | INIT_LIST_HEAD(&delayed_tr->list); | ||
3389 | delayed_tr->handle = handle; | ||
3390 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); | ||
3391 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3392 | "DELAYED:tr:handle(0x%04x), (open)\n", | ||
3393 | ioc->name, handle)); | ||
3394 | return; | ||
3395 | } | ||
3396 | |||
3397 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " | ||
3398 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, | ||
3399 | ioc->tm_tr_volume_cb_idx)); | ||
3400 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3401 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); | ||
3402 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; | ||
3403 | mpi_request->DevHandle = cpu_to_le16(handle); | ||
3404 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; | ||
3405 | mpt2sas_base_put_smid_hi_priority(ioc, smid); | ||
3406 | } | ||
3407 | |||
3408 | /** | ||
3409 | * _scsih_tm_volume_tr_complete - target reset completion | ||
3410 | * @ioc: per adapter object | ||
3411 | * @smid: system request message index | ||
3412 | * @msix_index: MSIX table index supplied by the OS | ||
3413 | * @reply: reply message frame(lower 32bit addr) | ||
3414 | * Context: interrupt time. | ||
3415 | * | ||
3416 | * Return 1 meaning mf should be freed from _base_interrupt | ||
3417 | * 0 means the mf is freed from this function. | ||
3418 | */ | ||
3419 | static u8 | ||
3420 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, | ||
3421 | u8 msix_index, u32 reply) | ||
3422 | { | ||
3423 | u16 handle; | ||
3424 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | ||
3425 | Mpi2SCSITaskManagementReply_t *mpi_reply = | ||
3426 | mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
3427 | |||
3428 | if (ioc->shost_recovery || ioc->remove_host || | ||
3429 | ioc->pci_error_recovery) { | ||
3430 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " | ||
3431 | "progress!\n", __func__, ioc->name)); | ||
3432 | return 1; | ||
3433 | } | ||
3434 | if (unlikely(!mpi_reply)) { | ||
3435 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", | ||
3436 | ioc->name, __FILE__, __LINE__, __func__); | ||
3437 | return 1; | ||
3438 | } | ||
3439 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3440 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | ||
3441 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | ||
3442 | dewtprintk(ioc, printk("spurious interrupt: " | ||
3443 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, | ||
3444 | le16_to_cpu(mpi_reply->DevHandle), smid)); | ||
3445 | return 0; | ||
3446 | } | ||
3447 | |||
3448 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3449 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | ||
3450 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | ||
3451 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | ||
3452 | le32_to_cpu(mpi_reply->IOCLogInfo), | ||
3453 | le32_to_cpu(mpi_reply->TerminationCount))); | ||
3454 | |||
3455 | return _scsih_check_for_pending_tm(ioc, smid); | ||
3456 | } | ||
3457 | |||
3458 | /** | ||
3459 | * _scsih_tm_tr_complete - | ||
3460 | * @ioc: per adapter object | ||
3461 | * @smid: system request message index | ||
3462 | * @msix_index: MSIX table index supplied by the OS | ||
3463 | * @reply: reply message frame(lower 32bit addr) | ||
3464 | * Context: interrupt time. | ||
3465 | * | ||
3466 | * This is the target reset completion routine. | ||
3467 | * This code is part of the code to initiate the device removal | ||
3468 | * handshake protocol with controller firmware. | ||
3469 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) | ||
3470 | * | ||
3471 | * Return 1 meaning mf should be freed from _base_interrupt | ||
3472 | * 0 means the mf is freed from this function. | ||
3473 | */ | ||
3474 | static u8 | ||
3475 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
3476 | u32 reply) | ||
3477 | { | ||
3478 | u16 handle; | ||
3479 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; | ||
3480 | Mpi2SCSITaskManagementReply_t *mpi_reply = | ||
3481 | mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
3482 | Mpi2SasIoUnitControlRequest_t *mpi_request; | ||
3483 | u16 smid_sas_ctrl; | ||
3484 | u32 ioc_state; | ||
3485 | |||
3486 | if (ioc->remove_host) { | ||
3487 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " | ||
3488 | "removed\n", __func__, ioc->name)); | ||
3489 | return 1; | ||
3490 | } else if (ioc->pci_error_recovery) { | ||
3491 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " | ||
3492 | "error recovery\n", __func__, ioc->name)); | ||
3493 | return 1; | ||
3494 | } | ||
3495 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
3496 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
3497 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " | ||
3498 | "operational\n", __func__, ioc->name)); | ||
3499 | return 1; | ||
3500 | } | ||
3501 | if (unlikely(!mpi_reply)) { | ||
3502 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", | ||
3503 | ioc->name, __FILE__, __LINE__, __func__); | ||
3504 | return 1; | ||
3505 | } | ||
3506 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); | ||
3507 | handle = le16_to_cpu(mpi_request_tm->DevHandle); | ||
3508 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { | ||
3509 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " | ||
3510 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, | ||
3511 | le16_to_cpu(mpi_reply->DevHandle), smid)); | ||
3512 | return 0; | ||
3513 | } | ||
3514 | |||
3515 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3516 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " | ||
3517 | "loginfo(0x%08x), completed(%d)\n", ioc->name, | ||
3518 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), | ||
3519 | le32_to_cpu(mpi_reply->IOCLogInfo), | ||
3520 | le32_to_cpu(mpi_reply->TerminationCount))); | ||
3521 | |||
3522 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); | ||
3523 | if (!smid_sas_ctrl) { | ||
3524 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
3525 | ioc->name, __func__); | ||
3526 | return 1; | ||
3527 | } | ||
3528 | |||
3529 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " | ||
3530 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, | ||
3531 | ioc->tm_sas_control_cb_idx)); | ||
3532 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); | ||
3533 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); | ||
3534 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | ||
3535 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; | ||
3536 | mpi_request->DevHandle = mpi_request_tm->DevHandle; | ||
3537 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); | ||
3538 | |||
3539 | return _scsih_check_for_pending_tm(ioc, smid); | ||
3540 | } | ||
3541 | |||
3542 | /** | ||
3543 | * _scsih_check_for_pending_tm - check for pending task management | ||
3544 | * @ioc: per adapter object | ||
3545 | * @smid: system request message index | ||
3546 | * | ||
3547 | * This will check delayed target reset list, and feed the | ||
3548 | * next reqeust. | ||
3549 | * | ||
3550 | * Return 1 meaning mf should be freed from _base_interrupt | ||
3551 | * 0 means the mf is freed from this function. | ||
3552 | */ | ||
3553 | static u8 | ||
3554 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
3555 | { | ||
3556 | struct _tr_list *delayed_tr; | ||
3557 | |||
3558 | if (!list_empty(&ioc->delayed_tr_volume_list)) { | ||
3559 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, | ||
3560 | struct _tr_list, list); | ||
3561 | mpt2sas_base_free_smid(ioc, smid); | ||
3562 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); | ||
3563 | list_del(&delayed_tr->list); | ||
3564 | kfree(delayed_tr); | ||
3565 | return 0; | ||
3566 | } | ||
3567 | |||
3568 | if (!list_empty(&ioc->delayed_tr_list)) { | ||
3569 | delayed_tr = list_entry(ioc->delayed_tr_list.next, | ||
3570 | struct _tr_list, list); | ||
3571 | mpt2sas_base_free_smid(ioc, smid); | ||
3572 | _scsih_tm_tr_send(ioc, delayed_tr->handle); | ||
3573 | list_del(&delayed_tr->list); | ||
3574 | kfree(delayed_tr); | ||
3575 | return 0; | ||
3576 | } | ||
3577 | |||
3578 | return 1; | ||
3579 | } | ||
3580 | |||
3581 | /** | ||
3582 | * _scsih_check_topo_delete_events - sanity check on topo events | ||
3583 | * @ioc: per adapter object | ||
3584 | * @event_data: the event data payload | ||
3585 | * | ||
3586 | * This routine added to better handle cable breaker. | ||
3587 | * | ||
3588 | * This handles the case where driver receives multiple expander | ||
3589 | * add and delete events in a single shot. When there is a delete event | ||
3590 | * the routine will void any pending add events waiting in the event queue. | ||
3591 | * | ||
3592 | * Return nothing. | ||
3593 | */ | ||
3594 | static void | ||
3595 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, | ||
3596 | Mpi2EventDataSasTopologyChangeList_t *event_data) | ||
3597 | { | ||
3598 | struct fw_event_work *fw_event; | ||
3599 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; | ||
3600 | u16 expander_handle; | ||
3601 | struct _sas_node *sas_expander; | ||
3602 | unsigned long flags; | ||
3603 | int i, reason_code; | ||
3604 | u16 handle; | ||
3605 | |||
3606 | for (i = 0 ; i < event_data->NumEntries; i++) { | ||
3607 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | ||
3608 | if (!handle) | ||
3609 | continue; | ||
3610 | reason_code = event_data->PHY[i].PhyStatus & | ||
3611 | MPI2_EVENT_SAS_TOPO_RC_MASK; | ||
3612 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) | ||
3613 | _scsih_tm_tr_send(ioc, handle); | ||
3614 | } | ||
3615 | |||
3616 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); | ||
3617 | if (expander_handle < ioc->sas_hba.num_phys) { | ||
3618 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | ||
3619 | return; | ||
3620 | } | ||
3621 | if (event_data->ExpStatus == | ||
3622 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { | ||
3623 | /* put expander attached devices into blocking state */ | ||
3624 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
3625 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, | ||
3626 | expander_handle); | ||
3627 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); | ||
3628 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
3629 | do { | ||
3630 | handle = find_first_bit(ioc->blocking_handles, | ||
3631 | ioc->facts.MaxDevHandle); | ||
3632 | if (handle < ioc->facts.MaxDevHandle) | ||
3633 | _scsih_block_io_device(ioc, handle); | ||
3634 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); | ||
3635 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) | ||
3636 | _scsih_block_io_to_children_attached_directly(ioc, event_data); | ||
3637 | |||
3638 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) | ||
3639 | return; | ||
3640 | |||
3641 | /* mark ignore flag for pending events */ | ||
3642 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | ||
3643 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { | ||
3644 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || | ||
3645 | fw_event->ignore) | ||
3646 | continue; | ||
3647 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) | ||
3648 | fw_event->event_data; | ||
3649 | if (local_event_data->ExpStatus == | ||
3650 | MPI2_EVENT_SAS_TOPO_ES_ADDED || | ||
3651 | local_event_data->ExpStatus == | ||
3652 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { | ||
3653 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == | ||
3654 | expander_handle) { | ||
3655 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3656 | "setting ignoring flag\n", ioc->name)); | ||
3657 | fw_event->ignore = 1; | ||
3658 | } | ||
3659 | } | ||
3660 | } | ||
3661 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | ||
3662 | } | ||
3663 | |||
3664 | /** | ||
3665 | * _scsih_set_volume_delete_flag - setting volume delete flag | ||
3666 | * @ioc: per adapter object | ||
3667 | * @handle: device handle | ||
3668 | * | ||
3669 | * This | ||
3670 | * Return nothing. | ||
3671 | */ | ||
3672 | static void | ||
3673 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
3674 | { | ||
3675 | struct _raid_device *raid_device; | ||
3676 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
3677 | unsigned long flags; | ||
3678 | |||
3679 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
3680 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | ||
3681 | if (raid_device && raid_device->starget && | ||
3682 | raid_device->starget->hostdata) { | ||
3683 | sas_target_priv_data = | ||
3684 | raid_device->starget->hostdata; | ||
3685 | sas_target_priv_data->deleted = 1; | ||
3686 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3687 | "setting delete flag: handle(0x%04x), " | ||
3688 | "wwid(0x%016llx)\n", ioc->name, handle, | ||
3689 | (unsigned long long) raid_device->wwid)); | ||
3690 | } | ||
3691 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
3692 | } | ||
3693 | |||
3694 | /** | ||
3695 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume | ||
3696 | * @handle: input handle | ||
3697 | * @a: handle for volume a | ||
3698 | * @b: handle for volume b | ||
3699 | * | ||
3700 | * IR firmware only supports two raid volumes. The purpose of this | ||
3701 | * routine is to set the volume handle in either a or b. When the given | ||
3702 | * input handle is non-zero, or when a and b have not been set before. | ||
3703 | */ | ||
3704 | static void | ||
3705 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) | ||
3706 | { | ||
3707 | if (!handle || handle == *a || handle == *b) | ||
3708 | return; | ||
3709 | if (!*a) | ||
3710 | *a = handle; | ||
3711 | else if (!*b) | ||
3712 | *b = handle; | ||
3713 | } | ||
3714 | |||
3715 | /** | ||
3716 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events | ||
3717 | * @ioc: per adapter object | ||
3718 | * @event_data: the event data payload | ||
3719 | * Context: interrupt time. | ||
3720 | * | ||
3721 | * This routine will send target reset to volume, followed by target | ||
3722 | * resets to the PDs. This is called when a PD has been removed, or | ||
3723 | * volume has been deleted or removed. When the target reset is sent | ||
3724 | * to volume, the PD target resets need to be queued to start upon | ||
3725 | * completion of the volume target reset. | ||
3726 | * | ||
3727 | * Return nothing. | ||
3728 | */ | ||
3729 | static void | ||
3730 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, | ||
3731 | Mpi2EventDataIrConfigChangeList_t *event_data) | ||
3732 | { | ||
3733 | Mpi2EventIrConfigElement_t *element; | ||
3734 | int i; | ||
3735 | u16 handle, volume_handle, a, b; | ||
3736 | struct _tr_list *delayed_tr; | ||
3737 | |||
3738 | a = 0; | ||
3739 | b = 0; | ||
3740 | |||
3741 | if (ioc->is_warpdrive) | ||
3742 | return; | ||
3743 | |||
3744 | /* Volume Resets for Deleted or Removed */ | ||
3745 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | ||
3746 | for (i = 0; i < event_data->NumElements; i++, element++) { | ||
3747 | if (element->ReasonCode == | ||
3748 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || | ||
3749 | element->ReasonCode == | ||
3750 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { | ||
3751 | volume_handle = le16_to_cpu(element->VolDevHandle); | ||
3752 | _scsih_set_volume_delete_flag(ioc, volume_handle); | ||
3753 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | ||
3754 | } | ||
3755 | } | ||
3756 | |||
3757 | /* Volume Resets for UNHIDE events */ | ||
3758 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | ||
3759 | for (i = 0; i < event_data->NumElements; i++, element++) { | ||
3760 | if (le32_to_cpu(event_data->Flags) & | ||
3761 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) | ||
3762 | continue; | ||
3763 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { | ||
3764 | volume_handle = le16_to_cpu(element->VolDevHandle); | ||
3765 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); | ||
3766 | } | ||
3767 | } | ||
3768 | |||
3769 | if (a) | ||
3770 | _scsih_tm_tr_volume_send(ioc, a); | ||
3771 | if (b) | ||
3772 | _scsih_tm_tr_volume_send(ioc, b); | ||
3773 | |||
3774 | /* PD target resets */ | ||
3775 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | ||
3776 | for (i = 0; i < event_data->NumElements; i++, element++) { | ||
3777 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) | ||
3778 | continue; | ||
3779 | handle = le16_to_cpu(element->PhysDiskDevHandle); | ||
3780 | volume_handle = le16_to_cpu(element->VolDevHandle); | ||
3781 | clear_bit(handle, ioc->pd_handles); | ||
3782 | if (!volume_handle) | ||
3783 | _scsih_tm_tr_send(ioc, handle); | ||
3784 | else if (volume_handle == a || volume_handle == b) { | ||
3785 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); | ||
3786 | BUG_ON(!delayed_tr); | ||
3787 | INIT_LIST_HEAD(&delayed_tr->list); | ||
3788 | delayed_tr->handle = handle; | ||
3789 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); | ||
3790 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
3791 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, | ||
3792 | handle)); | ||
3793 | } else | ||
3794 | _scsih_tm_tr_send(ioc, handle); | ||
3795 | } | ||
3796 | } | ||
3797 | |||
3798 | |||
3799 | /** | ||
3800 | * _scsih_check_volume_delete_events - set delete flag for volumes | ||
3801 | * @ioc: per adapter object | ||
3802 | * @event_data: the event data payload | ||
3803 | * Context: interrupt time. | ||
3804 | * | ||
3805 | * This will handle the case when the cable connected to entire volume is | ||
3806 | * pulled. We will take care of setting the deleted flag so normal IO will | ||
3807 | * not be sent. | ||
3808 | * | ||
3809 | * Return nothing. | ||
3810 | */ | ||
3811 | static void | ||
3812 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, | ||
3813 | Mpi2EventDataIrVolume_t *event_data) | ||
3814 | { | ||
3815 | u32 state; | ||
3816 | |||
3817 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | ||
3818 | return; | ||
3819 | state = le32_to_cpu(event_data->NewValue); | ||
3820 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == | ||
3821 | MPI2_RAID_VOL_STATE_FAILED) | ||
3822 | _scsih_set_volume_delete_flag(ioc, | ||
3823 | le16_to_cpu(event_data->VolDevHandle)); | ||
3824 | } | ||
3825 | |||
3826 | /** | ||
3827 | * _scsih_temp_threshold_events - display temperature threshold exceeded events | ||
3828 | * @ioc: per adapter object | ||
3829 | * @event_data: the temp threshold event data | ||
3830 | * Context: interrupt time. | ||
3831 | * | ||
3832 | * Return nothing. | ||
3833 | */ | ||
3834 | static void | ||
3835 | _scsih_temp_threshold_events(struct MPT2SAS_ADAPTER *ioc, | ||
3836 | Mpi2EventDataTemperature_t *event_data) | ||
3837 | { | ||
3838 | if (ioc->temp_sensors_count >= event_data->SensorNum) { | ||
3839 | printk(MPT2SAS_ERR_FMT "Temperature Threshold flags %s%s%s%s" | ||
3840 | " exceeded for Sensor: %d !!!\n", ioc->name, | ||
3841 | ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ", | ||
3842 | ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ", | ||
3843 | ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ", | ||
3844 | ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ", | ||
3845 | event_data->SensorNum); | ||
3846 | printk(MPT2SAS_ERR_FMT "Current Temp In Celsius: %d\n", | ||
3847 | ioc->name, event_data->CurrentTemperature); | ||
3848 | } | ||
3849 | } | ||
3850 | |||
3851 | /** | ||
3852 | * _scsih_flush_running_cmds - completing outstanding commands. | ||
3853 | * @ioc: per adapter object | ||
3854 | * | ||
3855 | * The flushing out of all pending scmd commands following host reset, | ||
3856 | * where all IO is dropped to the floor. | ||
3857 | * | ||
3858 | * Return nothing. | ||
3859 | */ | ||
3860 | static void | ||
3861 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) | ||
3862 | { | ||
3863 | struct scsi_cmnd *scmd; | ||
3864 | u16 smid; | ||
3865 | u16 count = 0; | ||
3866 | |||
3867 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | ||
3868 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | ||
3869 | if (!scmd) | ||
3870 | continue; | ||
3871 | count++; | ||
3872 | mpt2sas_base_free_smid(ioc, smid); | ||
3873 | scsi_dma_unmap(scmd); | ||
3874 | if (ioc->pci_error_recovery) | ||
3875 | scmd->result = DID_NO_CONNECT << 16; | ||
3876 | else | ||
3877 | scmd->result = DID_RESET << 16; | ||
3878 | scmd->scsi_done(scmd); | ||
3879 | } | ||
3880 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", | ||
3881 | ioc->name, count)); | ||
3882 | } | ||
3883 | |||
3884 | /** | ||
3885 | * _scsih_setup_eedp - setup MPI request for EEDP transfer | ||
3886 | * @scmd: pointer to scsi command object | ||
3887 | * @mpi_request: pointer to the SCSI_IO reqest message frame | ||
3888 | * | ||
3889 | * Supporting protection 1 and 3. | ||
3890 | * | ||
3891 | * Returns nothing | ||
3892 | */ | ||
3893 | static void | ||
3894 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) | ||
3895 | { | ||
3896 | u16 eedp_flags; | ||
3897 | unsigned char prot_op = scsi_get_prot_op(scmd); | ||
3898 | unsigned char prot_type = scsi_get_prot_type(scmd); | ||
3899 | |||
3900 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) | ||
3901 | return; | ||
3902 | |||
3903 | if (prot_op == SCSI_PROT_READ_STRIP) | ||
3904 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; | ||
3905 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | ||
3906 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; | ||
3907 | else | ||
3908 | return; | ||
3909 | |||
3910 | switch (prot_type) { | ||
3911 | case SCSI_PROT_DIF_TYPE1: | ||
3912 | case SCSI_PROT_DIF_TYPE2: | ||
3913 | |||
3914 | /* | ||
3915 | * enable ref/guard checking | ||
3916 | * auto increment ref tag | ||
3917 | */ | ||
3918 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | | ||
3919 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | | ||
3920 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | ||
3921 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = | ||
3922 | cpu_to_be32(scsi_get_lba(scmd)); | ||
3923 | break; | ||
3924 | |||
3925 | case SCSI_PROT_DIF_TYPE3: | ||
3926 | |||
3927 | /* | ||
3928 | * enable guard checking | ||
3929 | */ | ||
3930 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; | ||
3931 | break; | ||
3932 | } | ||
3933 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); | ||
3934 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); | ||
3935 | } | ||
3936 | |||
3937 | /** | ||
3938 | * _scsih_eedp_error_handling - return sense code for EEDP errors | ||
3939 | * @scmd: pointer to scsi command object | ||
3940 | * @ioc_status: ioc status | ||
3941 | * | ||
3942 | * Returns nothing | ||
3943 | */ | ||
3944 | static void | ||
3945 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) | ||
3946 | { | ||
3947 | u8 ascq; | ||
3948 | |||
3949 | switch (ioc_status) { | ||
3950 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | ||
3951 | ascq = 0x01; | ||
3952 | break; | ||
3953 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | ||
3954 | ascq = 0x02; | ||
3955 | break; | ||
3956 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | ||
3957 | ascq = 0x03; | ||
3958 | break; | ||
3959 | default: | ||
3960 | ascq = 0x00; | ||
3961 | break; | ||
3962 | } | ||
3963 | |||
3964 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq); | ||
3965 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | | ||
3966 | SAM_STAT_CHECK_CONDITION; | ||
3967 | } | ||
3968 | |||
3969 | /** | ||
3970 | * _scsih_scsi_direct_io_get - returns direct io flag | ||
3971 | * @ioc: per adapter object | ||
3972 | * @smid: system request message index | ||
3973 | * | ||
3974 | * Returns the smid stored scmd pointer. | ||
3975 | */ | ||
3976 | static inline u8 | ||
3977 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) | ||
3978 | { | ||
3979 | return ioc->scsi_lookup[smid - 1].direct_io; | ||
3980 | } | ||
3981 | |||
3982 | /** | ||
3983 | * _scsih_scsi_direct_io_set - sets direct io flag | ||
3984 | * @ioc: per adapter object | ||
3985 | * @smid: system request message index | ||
3986 | * @direct_io: Zero or non-zero value to set in the direct_io flag | ||
3987 | * | ||
3988 | * Returns Nothing. | ||
3989 | */ | ||
3990 | static inline void | ||
3991 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) | ||
3992 | { | ||
3993 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; | ||
3994 | } | ||
3995 | |||
3996 | |||
3997 | /** | ||
3998 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O | ||
3999 | * @ioc: per adapter object | ||
4000 | * @scmd: pointer to scsi command object | ||
4001 | * @raid_device: pointer to raid device data structure | ||
4002 | * @mpi_request: pointer to the SCSI_IO reqest message frame | ||
4003 | * @smid: system request message index | ||
4004 | * | ||
4005 | * Returns nothing | ||
4006 | */ | ||
4007 | static void | ||
4008 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | ||
4009 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, | ||
4010 | u16 smid) | ||
4011 | { | ||
4012 | sector_t v_lba, p_lba, stripe_off, column, io_size; | ||
4013 | u32 stripe_sz, stripe_exp; | ||
4014 | u8 num_pds, cmd = scmd->cmnd[0]; | ||
4015 | |||
4016 | if (cmd != READ_10 && cmd != WRITE_10 && | ||
4017 | cmd != READ_16 && cmd != WRITE_16) | ||
4018 | return; | ||
4019 | |||
4020 | if (cmd == READ_10 || cmd == WRITE_10) | ||
4021 | v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]); | ||
4022 | else | ||
4023 | v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]); | ||
4024 | |||
4025 | io_size = scsi_bufflen(scmd) >> raid_device->block_exponent; | ||
4026 | |||
4027 | if (v_lba + io_size - 1 > raid_device->max_lba) | ||
4028 | return; | ||
4029 | |||
4030 | stripe_sz = raid_device->stripe_sz; | ||
4031 | stripe_exp = raid_device->stripe_exponent; | ||
4032 | stripe_off = v_lba & (stripe_sz - 1); | ||
4033 | |||
4034 | /* Return unless IO falls within a stripe */ | ||
4035 | if (stripe_off + io_size > stripe_sz) | ||
4036 | return; | ||
4037 | |||
4038 | num_pds = raid_device->num_pds; | ||
4039 | p_lba = v_lba >> stripe_exp; | ||
4040 | column = sector_div(p_lba, num_pds); | ||
4041 | p_lba = (p_lba << stripe_exp) + stripe_off; | ||
4042 | |||
4043 | mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]); | ||
4044 | |||
4045 | if (cmd == READ_10 || cmd == WRITE_10) | ||
4046 | put_unaligned_be32(lower_32_bits(p_lba), | ||
4047 | &mpi_request->CDB.CDB32[2]); | ||
4048 | else | ||
4049 | put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]); | ||
4050 | |||
4051 | _scsih_scsi_direct_io_set(ioc, smid, 1); | ||
4052 | } | ||
4053 | |||
4054 | /** | ||
4055 | * _scsih_qcmd - main scsi request entry point | ||
4056 | * @scmd: pointer to scsi command object | ||
4057 | * @done: function pointer to be invoked on completion | ||
4058 | * | ||
4059 | * The callback index is set inside `ioc->scsi_io_cb_idx`. | ||
4060 | * | ||
4061 | * Returns 0 on success. If there's a failure, return either: | ||
4062 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or | ||
4063 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full | ||
4064 | */ | ||
4065 | static int | ||
4066 | _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) | ||
4067 | { | ||
4068 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
4069 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
4070 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
4071 | struct _raid_device *raid_device; | ||
4072 | Mpi2SCSIIORequest_t *mpi_request; | ||
4073 | u32 mpi_control; | ||
4074 | u16 smid; | ||
4075 | |||
4076 | sas_device_priv_data = scmd->device->hostdata; | ||
4077 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { | ||
4078 | scmd->result = DID_NO_CONNECT << 16; | ||
4079 | scmd->scsi_done(scmd); | ||
4080 | return 0; | ||
4081 | } | ||
4082 | |||
4083 | if (ioc->pci_error_recovery || ioc->remove_host) { | ||
4084 | scmd->result = DID_NO_CONNECT << 16; | ||
4085 | scmd->scsi_done(scmd); | ||
4086 | return 0; | ||
4087 | } | ||
4088 | |||
4089 | sas_target_priv_data = sas_device_priv_data->sas_target; | ||
4090 | /* invalid device handle */ | ||
4091 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { | ||
4092 | scmd->result = DID_NO_CONNECT << 16; | ||
4093 | scmd->scsi_done(scmd); | ||
4094 | return 0; | ||
4095 | } | ||
4096 | |||
4097 | /* host recovery or link resets sent via IOCTLs */ | ||
4098 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) | ||
4099 | return SCSI_MLQUEUE_HOST_BUSY; | ||
4100 | /* device busy with task management */ | ||
4101 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) | ||
4102 | return SCSI_MLQUEUE_DEVICE_BUSY; | ||
4103 | /* device has been deleted */ | ||
4104 | else if (sas_target_priv_data->deleted) { | ||
4105 | scmd->result = DID_NO_CONNECT << 16; | ||
4106 | scmd->scsi_done(scmd); | ||
4107 | return 0; | ||
4108 | } | ||
4109 | |||
4110 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) | ||
4111 | mpi_control = MPI2_SCSIIO_CONTROL_READ; | ||
4112 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) | ||
4113 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; | ||
4114 | else | ||
4115 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; | ||
4116 | |||
4117 | /* set tags */ | ||
4118 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; | ||
4119 | |||
4120 | /* Make sure Device is not raid volume. | ||
4121 | * We do not expose raid functionality to upper layer for warpdrive. | ||
4122 | */ | ||
4123 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && | ||
4124 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) | ||
4125 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; | ||
4126 | |||
4127 | smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); | ||
4128 | if (!smid) { | ||
4129 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
4130 | ioc->name, __func__); | ||
4131 | goto out; | ||
4132 | } | ||
4133 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
4134 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); | ||
4135 | _scsih_setup_eedp(scmd, mpi_request); | ||
4136 | if (scmd->cmd_len == 32) | ||
4137 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; | ||
4138 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | ||
4139 | if (sas_device_priv_data->sas_target->flags & | ||
4140 | MPT_TARGET_FLAGS_RAID_COMPONENT) | ||
4141 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; | ||
4142 | else | ||
4143 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; | ||
4144 | mpi_request->DevHandle = | ||
4145 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | ||
4146 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); | ||
4147 | mpi_request->Control = cpu_to_le32(mpi_control); | ||
4148 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); | ||
4149 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; | ||
4150 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; | ||
4151 | mpi_request->SenseBufferLowAddress = | ||
4152 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); | ||
4153 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; | ||
4154 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + | ||
4155 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); | ||
4156 | mpi_request->VF_ID = 0; /* TODO */ | ||
4157 | mpi_request->VP_ID = 0; | ||
4158 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) | ||
4159 | mpi_request->LUN); | ||
4160 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | ||
4161 | |||
4162 | if (!mpi_request->DataLength) { | ||
4163 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); | ||
4164 | } else { | ||
4165 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { | ||
4166 | mpt2sas_base_free_smid(ioc, smid); | ||
4167 | goto out; | ||
4168 | } | ||
4169 | } | ||
4170 | |||
4171 | raid_device = sas_target_priv_data->raid_device; | ||
4172 | if (raid_device && raid_device->direct_io_enabled) | ||
4173 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, | ||
4174 | smid); | ||
4175 | |||
4176 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) | ||
4177 | mpt2sas_base_put_smid_scsi_io(ioc, smid, | ||
4178 | le16_to_cpu(mpi_request->DevHandle)); | ||
4179 | else | ||
4180 | mpt2sas_base_put_smid_default(ioc, smid); | ||
4181 | return 0; | ||
4182 | |||
4183 | out: | ||
4184 | return SCSI_MLQUEUE_HOST_BUSY; | ||
4185 | } | ||
4186 | |||
4187 | /** | ||
4188 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data | ||
4189 | * @sense_buffer: sense data returned by target | ||
4190 | * @data: normalized skey/asc/ascq | ||
4191 | * | ||
4192 | * Return nothing. | ||
4193 | */ | ||
4194 | static void | ||
4195 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) | ||
4196 | { | ||
4197 | if ((sense_buffer[0] & 0x7F) >= 0x72) { | ||
4198 | /* descriptor format */ | ||
4199 | data->skey = sense_buffer[1] & 0x0F; | ||
4200 | data->asc = sense_buffer[2]; | ||
4201 | data->ascq = sense_buffer[3]; | ||
4202 | } else { | ||
4203 | /* fixed format */ | ||
4204 | data->skey = sense_buffer[2] & 0x0F; | ||
4205 | data->asc = sense_buffer[12]; | ||
4206 | data->ascq = sense_buffer[13]; | ||
4207 | } | ||
4208 | } | ||
4209 | |||
4210 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
4211 | /** | ||
4212 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request | ||
4213 | * @ioc: per adapter object | ||
4214 | * @scmd: pointer to scsi command object | ||
4215 | * @mpi_reply: reply mf payload returned from firmware | ||
4216 | * | ||
4217 | * scsi_status - SCSI Status code returned from target device | ||
4218 | * scsi_state - state info associated with SCSI_IO determined by ioc | ||
4219 | * ioc_status - ioc supplied status info | ||
4220 | * | ||
4221 | * Return nothing. | ||
4222 | */ | ||
4223 | static void | ||
4224 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, | ||
4225 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) | ||
4226 | { | ||
4227 | u32 response_info; | ||
4228 | u8 *response_bytes; | ||
4229 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & | ||
4230 | MPI2_IOCSTATUS_MASK; | ||
4231 | u8 scsi_state = mpi_reply->SCSIState; | ||
4232 | u8 scsi_status = mpi_reply->SCSIStatus; | ||
4233 | char *desc_ioc_state = NULL; | ||
4234 | char *desc_scsi_status = NULL; | ||
4235 | char *desc_scsi_state = ioc->tmp_string; | ||
4236 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | ||
4237 | struct _sas_device *sas_device = NULL; | ||
4238 | struct scsi_target *starget = scmd->device->sdev_target; | ||
4239 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; | ||
4240 | char *device_str = NULL; | ||
4241 | |||
4242 | if (!priv_target) | ||
4243 | return; | ||
4244 | |||
4245 | if (ioc->hide_ir_msg) | ||
4246 | device_str = "WarpDrive"; | ||
4247 | else | ||
4248 | device_str = "volume"; | ||
4249 | |||
4250 | if (log_info == 0x31170000) | ||
4251 | return; | ||
4252 | |||
4253 | switch (ioc_status) { | ||
4254 | case MPI2_IOCSTATUS_SUCCESS: | ||
4255 | desc_ioc_state = "success"; | ||
4256 | break; | ||
4257 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | ||
4258 | desc_ioc_state = "invalid function"; | ||
4259 | break; | ||
4260 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | ||
4261 | desc_ioc_state = "scsi recovered error"; | ||
4262 | break; | ||
4263 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: | ||
4264 | desc_ioc_state = "scsi invalid dev handle"; | ||
4265 | break; | ||
4266 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | ||
4267 | desc_ioc_state = "scsi device not there"; | ||
4268 | break; | ||
4269 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | ||
4270 | desc_ioc_state = "scsi data overrun"; | ||
4271 | break; | ||
4272 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | ||
4273 | desc_ioc_state = "scsi data underrun"; | ||
4274 | break; | ||
4275 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | ||
4276 | desc_ioc_state = "scsi io data error"; | ||
4277 | break; | ||
4278 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | ||
4279 | desc_ioc_state = "scsi protocol error"; | ||
4280 | break; | ||
4281 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | ||
4282 | desc_ioc_state = "scsi task terminated"; | ||
4283 | break; | ||
4284 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | ||
4285 | desc_ioc_state = "scsi residual mismatch"; | ||
4286 | break; | ||
4287 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | ||
4288 | desc_ioc_state = "scsi task mgmt failed"; | ||
4289 | break; | ||
4290 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | ||
4291 | desc_ioc_state = "scsi ioc terminated"; | ||
4292 | break; | ||
4293 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | ||
4294 | desc_ioc_state = "scsi ext terminated"; | ||
4295 | break; | ||
4296 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | ||
4297 | desc_ioc_state = "eedp guard error"; | ||
4298 | break; | ||
4299 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | ||
4300 | desc_ioc_state = "eedp ref tag error"; | ||
4301 | break; | ||
4302 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | ||
4303 | desc_ioc_state = "eedp app tag error"; | ||
4304 | break; | ||
4305 | default: | ||
4306 | desc_ioc_state = "unknown"; | ||
4307 | break; | ||
4308 | } | ||
4309 | |||
4310 | switch (scsi_status) { | ||
4311 | case MPI2_SCSI_STATUS_GOOD: | ||
4312 | desc_scsi_status = "good"; | ||
4313 | break; | ||
4314 | case MPI2_SCSI_STATUS_CHECK_CONDITION: | ||
4315 | desc_scsi_status = "check condition"; | ||
4316 | break; | ||
4317 | case MPI2_SCSI_STATUS_CONDITION_MET: | ||
4318 | desc_scsi_status = "condition met"; | ||
4319 | break; | ||
4320 | case MPI2_SCSI_STATUS_BUSY: | ||
4321 | desc_scsi_status = "busy"; | ||
4322 | break; | ||
4323 | case MPI2_SCSI_STATUS_INTERMEDIATE: | ||
4324 | desc_scsi_status = "intermediate"; | ||
4325 | break; | ||
4326 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: | ||
4327 | desc_scsi_status = "intermediate condmet"; | ||
4328 | break; | ||
4329 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: | ||
4330 | desc_scsi_status = "reservation conflict"; | ||
4331 | break; | ||
4332 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: | ||
4333 | desc_scsi_status = "command terminated"; | ||
4334 | break; | ||
4335 | case MPI2_SCSI_STATUS_TASK_SET_FULL: | ||
4336 | desc_scsi_status = "task set full"; | ||
4337 | break; | ||
4338 | case MPI2_SCSI_STATUS_ACA_ACTIVE: | ||
4339 | desc_scsi_status = "aca active"; | ||
4340 | break; | ||
4341 | case MPI2_SCSI_STATUS_TASK_ABORTED: | ||
4342 | desc_scsi_status = "task aborted"; | ||
4343 | break; | ||
4344 | default: | ||
4345 | desc_scsi_status = "unknown"; | ||
4346 | break; | ||
4347 | } | ||
4348 | |||
4349 | desc_scsi_state[0] = '\0'; | ||
4350 | if (!scsi_state) | ||
4351 | desc_scsi_state = " "; | ||
4352 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | ||
4353 | strcat(desc_scsi_state, "response info "); | ||
4354 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | ||
4355 | strcat(desc_scsi_state, "state terminated "); | ||
4356 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) | ||
4357 | strcat(desc_scsi_state, "no status "); | ||
4358 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) | ||
4359 | strcat(desc_scsi_state, "autosense failed "); | ||
4360 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) | ||
4361 | strcat(desc_scsi_state, "autosense valid "); | ||
4362 | |||
4363 | scsi_print_command(scmd); | ||
4364 | |||
4365 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { | ||
4366 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, | ||
4367 | device_str, (unsigned long long)priv_target->sas_address); | ||
4368 | } else { | ||
4369 | sas_device = mpt2sas_get_sdev_from_target(ioc, priv_target); | ||
4370 | if (sas_device) { | ||
4371 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " | ||
4372 | "phy(%d)\n", ioc->name, sas_device->sas_address, | ||
4373 | sas_device->phy); | ||
4374 | printk(MPT2SAS_WARN_FMT | ||
4375 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", | ||
4376 | ioc->name, sas_device->enclosure_logical_id, | ||
4377 | sas_device->slot); | ||
4378 | |||
4379 | sas_device_put(sas_device); | ||
4380 | } | ||
4381 | } | ||
4382 | |||
4383 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " | ||
4384 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), | ||
4385 | desc_ioc_state, ioc_status, smid); | ||
4386 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " | ||
4387 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, | ||
4388 | scsi_get_resid(scmd)); | ||
4389 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " | ||
4390 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), | ||
4391 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); | ||
4392 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " | ||
4393 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, | ||
4394 | scsi_status, desc_scsi_state, scsi_state); | ||
4395 | |||
4396 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | ||
4397 | struct sense_info data; | ||
4398 | _scsih_normalize_sense(scmd->sense_buffer, &data); | ||
4399 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " | ||
4400 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, | ||
4401 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); | ||
4402 | } | ||
4403 | |||
4404 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { | ||
4405 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); | ||
4406 | response_bytes = (u8 *)&response_info; | ||
4407 | _scsih_response_code(ioc, response_bytes[0]); | ||
4408 | } | ||
4409 | } | ||
4410 | #endif | ||
4411 | |||
4412 | /** | ||
4413 | * _scsih_turn_on_pfa_led - illuminate PFA LED | ||
4414 | * @ioc: per adapter object | ||
4415 | * @handle: device handle | ||
4416 | * Context: process | ||
4417 | * | ||
4418 | * Return nothing. | ||
4419 | */ | ||
4420 | static void | ||
4421 | _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
4422 | { | ||
4423 | Mpi2SepReply_t mpi_reply; | ||
4424 | Mpi2SepRequest_t mpi_request; | ||
4425 | struct _sas_device *sas_device; | ||
4426 | |||
4427 | sas_device = mpt2sas_get_sdev_by_handle(ioc, handle); | ||
4428 | if (!sas_device) | ||
4429 | return; | ||
4430 | |||
4431 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | ||
4432 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | ||
4433 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | ||
4434 | mpi_request.SlotStatus = | ||
4435 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); | ||
4436 | mpi_request.DevHandle = cpu_to_le16(handle); | ||
4437 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; | ||
4438 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | ||
4439 | &mpi_request)) != 0) { | ||
4440 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, | ||
4441 | __FILE__, __LINE__, __func__); | ||
4442 | goto out; | ||
4443 | } | ||
4444 | sas_device->pfa_led_on = 1; | ||
4445 | |||
4446 | |||
4447 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | ||
4448 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
4449 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", | ||
4450 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), | ||
4451 | le32_to_cpu(mpi_reply.IOCLogInfo))); | ||
4452 | goto out; | ||
4453 | } | ||
4454 | out: | ||
4455 | sas_device_put(sas_device); | ||
4456 | } | ||
4457 | |||
4458 | /** | ||
4459 | * _scsih_turn_off_pfa_led - turn off PFA LED | ||
4460 | * @ioc: per adapter object | ||
4461 | * @sas_device: sas device whose PFA LED has to turned off | ||
4462 | * Context: process | ||
4463 | * | ||
4464 | * Return nothing. | ||
4465 | */ | ||
4466 | static void | ||
4467 | _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc, | ||
4468 | struct _sas_device *sas_device) | ||
4469 | { | ||
4470 | Mpi2SepReply_t mpi_reply; | ||
4471 | Mpi2SepRequest_t mpi_request; | ||
4472 | |||
4473 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); | ||
4474 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; | ||
4475 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; | ||
4476 | mpi_request.SlotStatus = 0; | ||
4477 | mpi_request.Slot = cpu_to_le16(sas_device->slot); | ||
4478 | mpi_request.DevHandle = 0; | ||
4479 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); | ||
4480 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; | ||
4481 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, | ||
4482 | &mpi_request)) != 0) { | ||
4483 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, | ||
4484 | __FILE__, __LINE__, __func__); | ||
4485 | return; | ||
4486 | } | ||
4487 | |||
4488 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { | ||
4489 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " | ||
4490 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, | ||
4491 | le16_to_cpu(mpi_reply.IOCStatus), | ||
4492 | le32_to_cpu(mpi_reply.IOCLogInfo))); | ||
4493 | return; | ||
4494 | } | ||
4495 | } | ||
4496 | |||
4497 | /** | ||
4498 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event | ||
4499 | * @ioc: per adapter object | ||
4500 | * @handle: device handle | ||
4501 | * Context: interrupt. | ||
4502 | * | ||
4503 | * Return nothing. | ||
4504 | */ | ||
4505 | static void | ||
4506 | _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
4507 | { | ||
4508 | struct fw_event_work *fw_event; | ||
4509 | |||
4510 | fw_event = alloc_fw_event_work(0); | ||
4511 | if (!fw_event) | ||
4512 | return; | ||
4513 | fw_event->event = MPT2SAS_TURN_ON_PFA_LED; | ||
4514 | fw_event->device_handle = handle; | ||
4515 | fw_event->ioc = ioc; | ||
4516 | _scsih_fw_event_add(ioc, fw_event); | ||
4517 | fw_event_work_put(fw_event); | ||
4518 | } | ||
4519 | |||
4520 | /** | ||
4521 | * _scsih_smart_predicted_fault - process smart errors | ||
4522 | * @ioc: per adapter object | ||
4523 | * @handle: device handle | ||
4524 | * Context: interrupt. | ||
4525 | * | ||
4526 | * Return nothing. | ||
4527 | */ | ||
4528 | static void | ||
4529 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
4530 | { | ||
4531 | struct scsi_target *starget; | ||
4532 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
4533 | Mpi2EventNotificationReply_t *event_reply; | ||
4534 | Mpi2EventDataSasDeviceStatusChange_t *event_data; | ||
4535 | struct _sas_device *sas_device; | ||
4536 | ssize_t sz; | ||
4537 | unsigned long flags; | ||
4538 | |||
4539 | /* only handle non-raid devices */ | ||
4540 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
4541 | sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle); | ||
4542 | if (!sas_device) { | ||
4543 | goto out_unlock; | ||
4544 | } | ||
4545 | starget = sas_device->starget; | ||
4546 | sas_target_priv_data = starget->hostdata; | ||
4547 | |||
4548 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || | ||
4549 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) | ||
4550 | goto out_unlock; | ||
4551 | |||
4552 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); | ||
4553 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
4554 | |||
4555 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | ||
4556 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); | ||
4557 | |||
4558 | /* insert into event log */ | ||
4559 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + | ||
4560 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); | ||
4561 | event_reply = kzalloc(sz, GFP_ATOMIC); | ||
4562 | if (!event_reply) { | ||
4563 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4564 | ioc->name, __FILE__, __LINE__, __func__); | ||
4565 | goto out; | ||
4566 | } | ||
4567 | |||
4568 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; | ||
4569 | event_reply->Event = | ||
4570 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); | ||
4571 | event_reply->MsgLength = sz/4; | ||
4572 | event_reply->EventDataLength = | ||
4573 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); | ||
4574 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) | ||
4575 | event_reply->EventData; | ||
4576 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; | ||
4577 | event_data->ASC = 0x5D; | ||
4578 | event_data->DevHandle = cpu_to_le16(handle); | ||
4579 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); | ||
4580 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); | ||
4581 | kfree(event_reply); | ||
4582 | out: | ||
4583 | if (sas_device) | ||
4584 | sas_device_put(sas_device); | ||
4585 | return; | ||
4586 | |||
4587 | out_unlock: | ||
4588 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
4589 | goto out; | ||
4590 | } | ||
4591 | |||
4592 | /** | ||
4593 | * _scsih_io_done - scsi request callback | ||
4594 | * @ioc: per adapter object | ||
4595 | * @smid: system request message index | ||
4596 | * @msix_index: MSIX table index supplied by the OS | ||
4597 | * @reply: reply message frame(lower 32bit addr) | ||
4598 | * | ||
4599 | * Callback handler when using _scsih_qcmd. | ||
4600 | * | ||
4601 | * Return 1 meaning mf should be freed from _base_interrupt | ||
4602 | * 0 means the mf is freed from this function. | ||
4603 | */ | ||
4604 | static u8 | ||
4605 | _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | ||
4606 | { | ||
4607 | Mpi2SCSIIORequest_t *mpi_request; | ||
4608 | Mpi2SCSIIOReply_t *mpi_reply; | ||
4609 | struct scsi_cmnd *scmd; | ||
4610 | u16 ioc_status; | ||
4611 | u32 xfer_cnt; | ||
4612 | u8 scsi_state; | ||
4613 | u8 scsi_status; | ||
4614 | u32 log_info; | ||
4615 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
4616 | u32 response_code = 0; | ||
4617 | unsigned long flags; | ||
4618 | |||
4619 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
4620 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); | ||
4621 | if (scmd == NULL) | ||
4622 | return 1; | ||
4623 | |||
4624 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
4625 | |||
4626 | if (mpi_reply == NULL) { | ||
4627 | scmd->result = DID_OK << 16; | ||
4628 | goto out; | ||
4629 | } | ||
4630 | |||
4631 | sas_device_priv_data = scmd->device->hostdata; | ||
4632 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || | ||
4633 | sas_device_priv_data->sas_target->deleted) { | ||
4634 | scmd->result = DID_NO_CONNECT << 16; | ||
4635 | goto out; | ||
4636 | } | ||
4637 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); | ||
4638 | /* | ||
4639 | * WARPDRIVE: If direct_io is set then it is directIO, | ||
4640 | * the failed direct I/O should be redirected to volume | ||
4641 | */ | ||
4642 | if (_scsih_scsi_direct_io_get(ioc, smid) && | ||
4643 | ((ioc_status & MPI2_IOCSTATUS_MASK) | ||
4644 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { | ||
4645 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
4646 | ioc->scsi_lookup[smid - 1].scmd = scmd; | ||
4647 | _scsih_scsi_direct_io_set(ioc, smid, 0); | ||
4648 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
4649 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); | ||
4650 | mpi_request->DevHandle = | ||
4651 | cpu_to_le16(sas_device_priv_data->sas_target->handle); | ||
4652 | mpt2sas_base_put_smid_scsi_io(ioc, smid, | ||
4653 | sas_device_priv_data->sas_target->handle); | ||
4654 | return 0; | ||
4655 | } | ||
4656 | |||
4657 | |||
4658 | /* turning off TLR */ | ||
4659 | scsi_state = mpi_reply->SCSIState; | ||
4660 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) | ||
4661 | response_code = | ||
4662 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; | ||
4663 | if (!sas_device_priv_data->tlr_snoop_check) { | ||
4664 | sas_device_priv_data->tlr_snoop_check++; | ||
4665 | /* Make sure Device is not raid volume. | ||
4666 | * We do not expose raid functionality to upper layer for warpdrive. | ||
4667 | */ | ||
4668 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && | ||
4669 | sas_is_tlr_enabled(scmd->device) && | ||
4670 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { | ||
4671 | sas_disable_tlr(scmd->device); | ||
4672 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); | ||
4673 | } | ||
4674 | } | ||
4675 | |||
4676 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); | ||
4677 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); | ||
4678 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) | ||
4679 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); | ||
4680 | else | ||
4681 | log_info = 0; | ||
4682 | ioc_status &= MPI2_IOCSTATUS_MASK; | ||
4683 | scsi_status = mpi_reply->SCSIStatus; | ||
4684 | |||
4685 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && | ||
4686 | (scsi_status == MPI2_SCSI_STATUS_BUSY || | ||
4687 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || | ||
4688 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { | ||
4689 | ioc_status = MPI2_IOCSTATUS_SUCCESS; | ||
4690 | } | ||
4691 | |||
4692 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { | ||
4693 | struct sense_info data; | ||
4694 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, | ||
4695 | smid); | ||
4696 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, | ||
4697 | le32_to_cpu(mpi_reply->SenseCount)); | ||
4698 | memcpy(scmd->sense_buffer, sense_data, sz); | ||
4699 | _scsih_normalize_sense(scmd->sense_buffer, &data); | ||
4700 | /* failure prediction threshold exceeded */ | ||
4701 | if (data.asc == 0x5D) | ||
4702 | _scsih_smart_predicted_fault(ioc, | ||
4703 | le16_to_cpu(mpi_reply->DevHandle)); | ||
4704 | } | ||
4705 | |||
4706 | switch (ioc_status) { | ||
4707 | case MPI2_IOCSTATUS_BUSY: | ||
4708 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: | ||
4709 | scmd->result = SAM_STAT_BUSY; | ||
4710 | break; | ||
4711 | |||
4712 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: | ||
4713 | scmd->result = DID_NO_CONNECT << 16; | ||
4714 | break; | ||
4715 | |||
4716 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: | ||
4717 | if (sas_device_priv_data->block) { | ||
4718 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; | ||
4719 | goto out; | ||
4720 | } | ||
4721 | if (log_info == 0x32010081) { | ||
4722 | scmd->result = DID_RESET << 16; | ||
4723 | break; | ||
4724 | } | ||
4725 | scmd->result = DID_SOFT_ERROR << 16; | ||
4726 | break; | ||
4727 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: | ||
4728 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: | ||
4729 | scmd->result = DID_RESET << 16; | ||
4730 | break; | ||
4731 | |||
4732 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: | ||
4733 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) | ||
4734 | scmd->result = DID_SOFT_ERROR << 16; | ||
4735 | else | ||
4736 | scmd->result = (DID_OK << 16) | scsi_status; | ||
4737 | break; | ||
4738 | |||
4739 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: | ||
4740 | scmd->result = (DID_OK << 16) | scsi_status; | ||
4741 | |||
4742 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) | ||
4743 | break; | ||
4744 | |||
4745 | if (xfer_cnt < scmd->underflow) { | ||
4746 | if (scsi_status == SAM_STAT_BUSY) | ||
4747 | scmd->result = SAM_STAT_BUSY; | ||
4748 | else | ||
4749 | scmd->result = DID_SOFT_ERROR << 16; | ||
4750 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | ||
4751 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) | ||
4752 | scmd->result = DID_SOFT_ERROR << 16; | ||
4753 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | ||
4754 | scmd->result = DID_RESET << 16; | ||
4755 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { | ||
4756 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; | ||
4757 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; | ||
4758 | scmd->result = (DRIVER_SENSE << 24) | | ||
4759 | SAM_STAT_CHECK_CONDITION; | ||
4760 | scmd->sense_buffer[0] = 0x70; | ||
4761 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; | ||
4762 | scmd->sense_buffer[12] = 0x20; | ||
4763 | scmd->sense_buffer[13] = 0; | ||
4764 | } | ||
4765 | break; | ||
4766 | |||
4767 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: | ||
4768 | scsi_set_resid(scmd, 0); | ||
4769 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: | ||
4770 | case MPI2_IOCSTATUS_SUCCESS: | ||
4771 | scmd->result = (DID_OK << 16) | scsi_status; | ||
4772 | if (response_code == | ||
4773 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || | ||
4774 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | | ||
4775 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) | ||
4776 | scmd->result = DID_SOFT_ERROR << 16; | ||
4777 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) | ||
4778 | scmd->result = DID_RESET << 16; | ||
4779 | break; | ||
4780 | |||
4781 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: | ||
4782 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: | ||
4783 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: | ||
4784 | _scsih_eedp_error_handling(scmd, ioc_status); | ||
4785 | break; | ||
4786 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: | ||
4787 | case MPI2_IOCSTATUS_INVALID_FUNCTION: | ||
4788 | case MPI2_IOCSTATUS_INVALID_SGL: | ||
4789 | case MPI2_IOCSTATUS_INTERNAL_ERROR: | ||
4790 | case MPI2_IOCSTATUS_INVALID_FIELD: | ||
4791 | case MPI2_IOCSTATUS_INVALID_STATE: | ||
4792 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: | ||
4793 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: | ||
4794 | default: | ||
4795 | scmd->result = DID_SOFT_ERROR << 16; | ||
4796 | break; | ||
4797 | |||
4798 | } | ||
4799 | |||
4800 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
4801 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) | ||
4802 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); | ||
4803 | #endif | ||
4804 | |||
4805 | out: | ||
4806 | scsi_dma_unmap(scmd); | ||
4807 | scmd->scsi_done(scmd); | ||
4808 | return 1; | ||
4809 | } | ||
4810 | |||
4811 | /** | ||
4812 | * _scsih_sas_host_refresh - refreshing sas host object contents | ||
4813 | * @ioc: per adapter object | ||
4814 | * Context: user | ||
4815 | * | ||
4816 | * During port enable, fw will send topology events for every device. Its | ||
4817 | * possible that the handles may change from the previous setting, so this | ||
4818 | * code keeping handles updating if changed. | ||
4819 | * | ||
4820 | * Return nothing. | ||
4821 | */ | ||
4822 | static void | ||
4823 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) | ||
4824 | { | ||
4825 | u16 sz; | ||
4826 | u16 ioc_status; | ||
4827 | int i; | ||
4828 | Mpi2ConfigReply_t mpi_reply; | ||
4829 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | ||
4830 | u16 attached_handle; | ||
4831 | u8 link_rate; | ||
4832 | |||
4833 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
4834 | "updating handles for sas_host(0x%016llx)\n", | ||
4835 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); | ||
4836 | |||
4837 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys | ||
4838 | * sizeof(Mpi2SasIOUnit0PhyData_t)); | ||
4839 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | ||
4840 | if (!sas_iounit_pg0) { | ||
4841 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4842 | ioc->name, __FILE__, __LINE__, __func__); | ||
4843 | return; | ||
4844 | } | ||
4845 | |||
4846 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | ||
4847 | sas_iounit_pg0, sz)) != 0) | ||
4848 | goto out; | ||
4849 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
4850 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
4851 | goto out; | ||
4852 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | ||
4853 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; | ||
4854 | if (i == 0) | ||
4855 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | ||
4856 | PhyData[0].ControllerDevHandle); | ||
4857 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | ||
4858 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. | ||
4859 | AttachedDevHandle); | ||
4860 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | ||
4861 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; | ||
4862 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, | ||
4863 | attached_handle, i, link_rate); | ||
4864 | } | ||
4865 | out: | ||
4866 | kfree(sas_iounit_pg0); | ||
4867 | } | ||
4868 | |||
4869 | /** | ||
4870 | * _scsih_sas_host_add - create sas host object | ||
4871 | * @ioc: per adapter object | ||
4872 | * | ||
4873 | * Creating host side data object, stored in ioc->sas_hba | ||
4874 | * | ||
4875 | * Return nothing. | ||
4876 | */ | ||
4877 | static void | ||
4878 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) | ||
4879 | { | ||
4880 | int i; | ||
4881 | Mpi2ConfigReply_t mpi_reply; | ||
4882 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | ||
4883 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | ||
4884 | Mpi2SasPhyPage0_t phy_pg0; | ||
4885 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
4886 | Mpi2SasEnclosurePage0_t enclosure_pg0; | ||
4887 | u16 ioc_status; | ||
4888 | u16 sz; | ||
4889 | u16 device_missing_delay; | ||
4890 | |||
4891 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); | ||
4892 | if (!ioc->sas_hba.num_phys) { | ||
4893 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4894 | ioc->name, __FILE__, __LINE__, __func__); | ||
4895 | return; | ||
4896 | } | ||
4897 | |||
4898 | /* sas_iounit page 0 */ | ||
4899 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | ||
4900 | sizeof(Mpi2SasIOUnit0PhyData_t)); | ||
4901 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | ||
4902 | if (!sas_iounit_pg0) { | ||
4903 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4904 | ioc->name, __FILE__, __LINE__, __func__); | ||
4905 | return; | ||
4906 | } | ||
4907 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | ||
4908 | sas_iounit_pg0, sz))) { | ||
4909 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4910 | ioc->name, __FILE__, __LINE__, __func__); | ||
4911 | goto out; | ||
4912 | } | ||
4913 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
4914 | MPI2_IOCSTATUS_MASK; | ||
4915 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
4916 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4917 | ioc->name, __FILE__, __LINE__, __func__); | ||
4918 | goto out; | ||
4919 | } | ||
4920 | |||
4921 | /* sas_iounit page 1 */ | ||
4922 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | ||
4923 | sizeof(Mpi2SasIOUnit1PhyData_t)); | ||
4924 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | ||
4925 | if (!sas_iounit_pg1) { | ||
4926 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4927 | ioc->name, __FILE__, __LINE__, __func__); | ||
4928 | goto out; | ||
4929 | } | ||
4930 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | ||
4931 | sas_iounit_pg1, sz))) { | ||
4932 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4933 | ioc->name, __FILE__, __LINE__, __func__); | ||
4934 | goto out; | ||
4935 | } | ||
4936 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
4937 | MPI2_IOCSTATUS_MASK; | ||
4938 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
4939 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4940 | ioc->name, __FILE__, __LINE__, __func__); | ||
4941 | goto out; | ||
4942 | } | ||
4943 | |||
4944 | ioc->io_missing_delay = | ||
4945 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); | ||
4946 | device_missing_delay = | ||
4947 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); | ||
4948 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) | ||
4949 | ioc->device_missing_delay = (device_missing_delay & | ||
4950 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; | ||
4951 | else | ||
4952 | ioc->device_missing_delay = device_missing_delay & | ||
4953 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; | ||
4954 | |||
4955 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; | ||
4956 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, | ||
4957 | sizeof(struct _sas_phy), GFP_KERNEL); | ||
4958 | if (!ioc->sas_hba.phy) { | ||
4959 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4960 | ioc->name, __FILE__, __LINE__, __func__); | ||
4961 | goto out; | ||
4962 | } | ||
4963 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | ||
4964 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | ||
4965 | i))) { | ||
4966 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4967 | ioc->name, __FILE__, __LINE__, __func__); | ||
4968 | goto out; | ||
4969 | } | ||
4970 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
4971 | MPI2_IOCSTATUS_MASK; | ||
4972 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
4973 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4974 | ioc->name, __FILE__, __LINE__, __func__); | ||
4975 | goto out; | ||
4976 | } | ||
4977 | |||
4978 | if (i == 0) | ||
4979 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> | ||
4980 | PhyData[0].ControllerDevHandle); | ||
4981 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; | ||
4982 | ioc->sas_hba.phy[i].phy_id = i; | ||
4983 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], | ||
4984 | phy_pg0, ioc->sas_hba.parent_dev); | ||
4985 | } | ||
4986 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
4987 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { | ||
4988 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
4989 | ioc->name, __FILE__, __LINE__, __func__); | ||
4990 | goto out; | ||
4991 | } | ||
4992 | ioc->sas_hba.enclosure_handle = | ||
4993 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | ||
4994 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | ||
4995 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " | ||
4996 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, | ||
4997 | (unsigned long long) ioc->sas_hba.sas_address, | ||
4998 | ioc->sas_hba.num_phys) ; | ||
4999 | |||
5000 | if (ioc->sas_hba.enclosure_handle) { | ||
5001 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, | ||
5002 | &enclosure_pg0, | ||
5003 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | ||
5004 | ioc->sas_hba.enclosure_handle))) { | ||
5005 | ioc->sas_hba.enclosure_logical_id = | ||
5006 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | ||
5007 | } | ||
5008 | } | ||
5009 | |||
5010 | out: | ||
5011 | kfree(sas_iounit_pg1); | ||
5012 | kfree(sas_iounit_pg0); | ||
5013 | } | ||
5014 | |||
5015 | /** | ||
5016 | * _scsih_expander_add - creating expander object | ||
5017 | * @ioc: per adapter object | ||
5018 | * @handle: expander handle | ||
5019 | * | ||
5020 | * Creating expander object, stored in ioc->sas_expander_list. | ||
5021 | * | ||
5022 | * Return 0 for success, else error. | ||
5023 | */ | ||
5024 | static int | ||
5025 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
5026 | { | ||
5027 | struct _sas_node *sas_expander; | ||
5028 | Mpi2ConfigReply_t mpi_reply; | ||
5029 | Mpi2ExpanderPage0_t expander_pg0; | ||
5030 | Mpi2ExpanderPage1_t expander_pg1; | ||
5031 | Mpi2SasEnclosurePage0_t enclosure_pg0; | ||
5032 | u32 ioc_status; | ||
5033 | u16 parent_handle; | ||
5034 | u64 sas_address, sas_address_parent = 0; | ||
5035 | int i; | ||
5036 | unsigned long flags; | ||
5037 | struct _sas_port *mpt2sas_port = NULL; | ||
5038 | int rc = 0; | ||
5039 | |||
5040 | if (!handle) | ||
5041 | return -1; | ||
5042 | |||
5043 | if (ioc->shost_recovery || ioc->pci_error_recovery) | ||
5044 | return -1; | ||
5045 | |||
5046 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | ||
5047 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { | ||
5048 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5049 | ioc->name, __FILE__, __LINE__, __func__); | ||
5050 | return -1; | ||
5051 | } | ||
5052 | |||
5053 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
5054 | MPI2_IOCSTATUS_MASK; | ||
5055 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
5056 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5057 | ioc->name, __FILE__, __LINE__, __func__); | ||
5058 | return -1; | ||
5059 | } | ||
5060 | |||
5061 | /* handle out of order topology events */ | ||
5062 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); | ||
5063 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) | ||
5064 | != 0) { | ||
5065 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5066 | ioc->name, __FILE__, __LINE__, __func__); | ||
5067 | return -1; | ||
5068 | } | ||
5069 | if (sas_address_parent != ioc->sas_hba.sas_address) { | ||
5070 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
5071 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, | ||
5072 | sas_address_parent); | ||
5073 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
5074 | if (!sas_expander) { | ||
5075 | rc = _scsih_expander_add(ioc, parent_handle); | ||
5076 | if (rc != 0) | ||
5077 | return rc; | ||
5078 | } | ||
5079 | } | ||
5080 | |||
5081 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
5082 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | ||
5083 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, | ||
5084 | sas_address); | ||
5085 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
5086 | |||
5087 | if (sas_expander) | ||
5088 | return 0; | ||
5089 | |||
5090 | sas_expander = kzalloc(sizeof(struct _sas_node), | ||
5091 | GFP_KERNEL); | ||
5092 | if (!sas_expander) { | ||
5093 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5094 | ioc->name, __FILE__, __LINE__, __func__); | ||
5095 | return -1; | ||
5096 | } | ||
5097 | |||
5098 | sas_expander->handle = handle; | ||
5099 | sas_expander->num_phys = expander_pg0.NumPhys; | ||
5100 | sas_expander->sas_address_parent = sas_address_parent; | ||
5101 | sas_expander->sas_address = sas_address; | ||
5102 | |||
5103 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," | ||
5104 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, | ||
5105 | handle, parent_handle, (unsigned long long) | ||
5106 | sas_expander->sas_address, sas_expander->num_phys); | ||
5107 | |||
5108 | if (!sas_expander->num_phys) | ||
5109 | goto out_fail; | ||
5110 | sas_expander->phy = kcalloc(sas_expander->num_phys, | ||
5111 | sizeof(struct _sas_phy), GFP_KERNEL); | ||
5112 | if (!sas_expander->phy) { | ||
5113 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5114 | ioc->name, __FILE__, __LINE__, __func__); | ||
5115 | rc = -1; | ||
5116 | goto out_fail; | ||
5117 | } | ||
5118 | |||
5119 | INIT_LIST_HEAD(&sas_expander->sas_port_list); | ||
5120 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, | ||
5121 | sas_address_parent); | ||
5122 | if (!mpt2sas_port) { | ||
5123 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5124 | ioc->name, __FILE__, __LINE__, __func__); | ||
5125 | rc = -1; | ||
5126 | goto out_fail; | ||
5127 | } | ||
5128 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; | ||
5129 | |||
5130 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | ||
5131 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, | ||
5132 | &expander_pg1, i, handle))) { | ||
5133 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5134 | ioc->name, __FILE__, __LINE__, __func__); | ||
5135 | rc = -1; | ||
5136 | goto out_fail; | ||
5137 | } | ||
5138 | sas_expander->phy[i].handle = handle; | ||
5139 | sas_expander->phy[i].phy_id = i; | ||
5140 | |||
5141 | if ((mpt2sas_transport_add_expander_phy(ioc, | ||
5142 | &sas_expander->phy[i], expander_pg1, | ||
5143 | sas_expander->parent_dev))) { | ||
5144 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5145 | ioc->name, __FILE__, __LINE__, __func__); | ||
5146 | rc = -1; | ||
5147 | goto out_fail; | ||
5148 | } | ||
5149 | } | ||
5150 | |||
5151 | if (sas_expander->enclosure_handle) { | ||
5152 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, | ||
5153 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | ||
5154 | sas_expander->enclosure_handle))) { | ||
5155 | sas_expander->enclosure_logical_id = | ||
5156 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | ||
5157 | } | ||
5158 | } | ||
5159 | |||
5160 | _scsih_expander_node_add(ioc, sas_expander); | ||
5161 | return 0; | ||
5162 | |||
5163 | out_fail: | ||
5164 | |||
5165 | if (mpt2sas_port) | ||
5166 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, | ||
5167 | sas_address_parent); | ||
5168 | kfree(sas_expander); | ||
5169 | return rc; | ||
5170 | } | ||
5171 | |||
5172 | /** | ||
5173 | * _scsih_done - scsih callback handler. | ||
5174 | * @ioc: per adapter object | ||
5175 | * @smid: system request message index | ||
5176 | * @msix_index: MSIX table index supplied by the OS | ||
5177 | * @reply: reply message frame(lower 32bit addr) | ||
5178 | * | ||
5179 | * Callback handler when sending internal generated message frames. | ||
5180 | * The callback index passed is `ioc->scsih_cb_idx` | ||
5181 | * | ||
5182 | * Return 1 meaning mf should be freed from _base_interrupt | ||
5183 | * 0 means the mf is freed from this function. | ||
5184 | */ | ||
5185 | static u8 | ||
5186 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) | ||
5187 | { | ||
5188 | MPI2DefaultReply_t *mpi_reply; | ||
5189 | |||
5190 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
5191 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) | ||
5192 | return 1; | ||
5193 | if (ioc->scsih_cmds.smid != smid) | ||
5194 | return 1; | ||
5195 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; | ||
5196 | if (mpi_reply) { | ||
5197 | memcpy(ioc->scsih_cmds.reply, mpi_reply, | ||
5198 | mpi_reply->MsgLength*4); | ||
5199 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
5200 | } | ||
5201 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; | ||
5202 | complete(&ioc->scsih_cmds.done); | ||
5203 | return 1; | ||
5204 | } | ||
5205 | |||
5206 | /** | ||
5207 | * mpt2sas_expander_remove - removing expander object | ||
5208 | * @ioc: per adapter object | ||
5209 | * @sas_address: expander sas_address | ||
5210 | * | ||
5211 | * Return nothing. | ||
5212 | */ | ||
5213 | void | ||
5214 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) | ||
5215 | { | ||
5216 | struct _sas_node *sas_expander; | ||
5217 | unsigned long flags; | ||
5218 | |||
5219 | if (ioc->shost_recovery) | ||
5220 | return; | ||
5221 | |||
5222 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
5223 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, | ||
5224 | sas_address); | ||
5225 | if (sas_expander) | ||
5226 | list_del(&sas_expander->list); | ||
5227 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
5228 | if (sas_expander) | ||
5229 | _scsih_expander_node_remove(ioc, sas_expander); | ||
5230 | } | ||
5231 | |||
5232 | /** | ||
5233 | * _scsih_check_access_status - check access flags | ||
5234 | * @ioc: per adapter object | ||
5235 | * @sas_address: sas address | ||
5236 | * @handle: sas device handle | ||
5237 | * @access_flags: errors returned during discovery of the device | ||
5238 | * | ||
5239 | * Return 0 for success, else failure | ||
5240 | */ | ||
5241 | static u8 | ||
5242 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, | ||
5243 | u16 handle, u8 access_status) | ||
5244 | { | ||
5245 | u8 rc = 1; | ||
5246 | char *desc = NULL; | ||
5247 | |||
5248 | switch (access_status) { | ||
5249 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: | ||
5250 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: | ||
5251 | rc = 0; | ||
5252 | break; | ||
5253 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: | ||
5254 | desc = "sata capability failed"; | ||
5255 | break; | ||
5256 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: | ||
5257 | desc = "sata affiliation conflict"; | ||
5258 | break; | ||
5259 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: | ||
5260 | desc = "route not addressable"; | ||
5261 | break; | ||
5262 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: | ||
5263 | desc = "smp error not addressable"; | ||
5264 | break; | ||
5265 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: | ||
5266 | desc = "device blocked"; | ||
5267 | break; | ||
5268 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: | ||
5269 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: | ||
5270 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: | ||
5271 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: | ||
5272 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: | ||
5273 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: | ||
5274 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: | ||
5275 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: | ||
5276 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: | ||
5277 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: | ||
5278 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: | ||
5279 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: | ||
5280 | desc = "sata initialization failed"; | ||
5281 | break; | ||
5282 | default: | ||
5283 | desc = "unknown"; | ||
5284 | break; | ||
5285 | } | ||
5286 | |||
5287 | if (!rc) | ||
5288 | return 0; | ||
5289 | |||
5290 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " | ||
5291 | "handle(0x%04x)\n", ioc->name, desc, | ||
5292 | (unsigned long long)sas_address, handle); | ||
5293 | return rc; | ||
5294 | } | ||
5295 | |||
5296 | static void | ||
5297 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
5298 | { | ||
5299 | Mpi2ConfigReply_t mpi_reply; | ||
5300 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
5301 | struct _sas_device *sas_device; | ||
5302 | u32 ioc_status; | ||
5303 | unsigned long flags; | ||
5304 | u64 sas_address; | ||
5305 | struct scsi_target *starget; | ||
5306 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
5307 | u32 device_info; | ||
5308 | |||
5309 | |||
5310 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
5311 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) | ||
5312 | return; | ||
5313 | |||
5314 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; | ||
5315 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
5316 | return; | ||
5317 | |||
5318 | /* check if this is end device */ | ||
5319 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | ||
5320 | if (!(_scsih_is_end_device(device_info))) | ||
5321 | return; | ||
5322 | |||
5323 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
5324 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | ||
5325 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
5326 | sas_address); | ||
5327 | |||
5328 | if (!sas_device) { | ||
5329 | printk(MPT2SAS_ERR_FMT "device is not present " | ||
5330 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); | ||
5331 | goto out_unlock; | ||
5332 | } | ||
5333 | |||
5334 | if (unlikely(sas_device->handle != handle)) { | ||
5335 | starget = sas_device->starget; | ||
5336 | sas_target_priv_data = starget->hostdata; | ||
5337 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" | ||
5338 | " to (0x%04x)!!!\n", sas_device->handle, handle); | ||
5339 | sas_target_priv_data->handle = handle; | ||
5340 | sas_device->handle = handle; | ||
5341 | } | ||
5342 | |||
5343 | /* check if device is present */ | ||
5344 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | ||
5345 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | ||
5346 | printk(MPT2SAS_ERR_FMT "device is not present " | ||
5347 | "handle(0x%04x), flags!!!\n", ioc->name, handle); | ||
5348 | goto out_unlock; | ||
5349 | } | ||
5350 | |||
5351 | /* check if there were any issues with discovery */ | ||
5352 | if (_scsih_check_access_status(ioc, sas_address, handle, | ||
5353 | sas_device_pg0.AccessStatus)) | ||
5354 | goto out_unlock; | ||
5355 | |||
5356 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
5357 | _scsih_ublock_io_device(ioc, sas_address); | ||
5358 | if (sas_device) | ||
5359 | sas_device_put(sas_device); | ||
5360 | return; | ||
5361 | |||
5362 | out_unlock: | ||
5363 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
5364 | if (sas_device) | ||
5365 | sas_device_put(sas_device); | ||
5366 | } | ||
5367 | |||
5368 | /** | ||
5369 | * _scsih_add_device - creating sas device object | ||
5370 | * @ioc: per adapter object | ||
5371 | * @handle: sas device handle | ||
5372 | * @phy_num: phy number end device attached to | ||
5373 | * @is_pd: is this hidden raid component | ||
5374 | * | ||
5375 | * Creating end device object, stored in ioc->sas_device_list. | ||
5376 | * | ||
5377 | * Returns 0 for success, non-zero for failure. | ||
5378 | */ | ||
5379 | static int | ||
5380 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) | ||
5381 | { | ||
5382 | Mpi2ConfigReply_t mpi_reply; | ||
5383 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
5384 | Mpi2SasEnclosurePage0_t enclosure_pg0; | ||
5385 | struct _sas_device *sas_device; | ||
5386 | u32 ioc_status; | ||
5387 | __le64 sas_address; | ||
5388 | u32 device_info; | ||
5389 | |||
5390 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
5391 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | ||
5392 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5393 | ioc->name, __FILE__, __LINE__, __func__); | ||
5394 | return -1; | ||
5395 | } | ||
5396 | |||
5397 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
5398 | MPI2_IOCSTATUS_MASK; | ||
5399 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
5400 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5401 | ioc->name, __FILE__, __LINE__, __func__); | ||
5402 | return -1; | ||
5403 | } | ||
5404 | |||
5405 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | ||
5406 | |||
5407 | /* check if device is present */ | ||
5408 | if (!(le16_to_cpu(sas_device_pg0.Flags) & | ||
5409 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { | ||
5410 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5411 | ioc->name, __FILE__, __LINE__, __func__); | ||
5412 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", | ||
5413 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); | ||
5414 | return -1; | ||
5415 | } | ||
5416 | |||
5417 | /* check if there were any issues with discovery */ | ||
5418 | if (_scsih_check_access_status(ioc, sas_address, handle, | ||
5419 | sas_device_pg0.AccessStatus)) | ||
5420 | return -1; | ||
5421 | |||
5422 | /* check if this is end device */ | ||
5423 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | ||
5424 | if (!(_scsih_is_end_device(device_info))) { | ||
5425 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5426 | ioc->name, __FILE__, __LINE__, __func__); | ||
5427 | return -1; | ||
5428 | } | ||
5429 | |||
5430 | sas_device = mpt2sas_get_sdev_by_addr(ioc, | ||
5431 | sas_address); | ||
5432 | |||
5433 | if (sas_device) { | ||
5434 | sas_device_put(sas_device); | ||
5435 | return 0; | ||
5436 | } | ||
5437 | |||
5438 | sas_device = kzalloc(sizeof(struct _sas_device), | ||
5439 | GFP_KERNEL); | ||
5440 | if (!sas_device) { | ||
5441 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5442 | ioc->name, __FILE__, __LINE__, __func__); | ||
5443 | return -1; | ||
5444 | } | ||
5445 | |||
5446 | kref_init(&sas_device->refcount); | ||
5447 | sas_device->handle = handle; | ||
5448 | if (_scsih_get_sas_address(ioc, le16_to_cpu | ||
5449 | (sas_device_pg0.ParentDevHandle), | ||
5450 | &sas_device->sas_address_parent) != 0) | ||
5451 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
5452 | ioc->name, __FILE__, __LINE__, __func__); | ||
5453 | sas_device->enclosure_handle = | ||
5454 | le16_to_cpu(sas_device_pg0.EnclosureHandle); | ||
5455 | sas_device->slot = | ||
5456 | le16_to_cpu(sas_device_pg0.Slot); | ||
5457 | sas_device->device_info = device_info; | ||
5458 | sas_device->sas_address = sas_address; | ||
5459 | sas_device->phy = sas_device_pg0.PhyNum; | ||
5460 | |||
5461 | /* get enclosure_logical_id */ | ||
5462 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( | ||
5463 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, | ||
5464 | sas_device->enclosure_handle))) | ||
5465 | sas_device->enclosure_logical_id = | ||
5466 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); | ||
5467 | |||
5468 | /* get device name */ | ||
5469 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); | ||
5470 | |||
5471 | if (ioc->wait_for_discovery_to_complete) | ||
5472 | _scsih_sas_device_init_add(ioc, sas_device); | ||
5473 | else | ||
5474 | _scsih_sas_device_add(ioc, sas_device); | ||
5475 | |||
5476 | sas_device_put(sas_device); | ||
5477 | return 0; | ||
5478 | } | ||
5479 | |||
5480 | /** | ||
5481 | * _scsih_remove_device - removing sas device object | ||
5482 | * @ioc: per adapter object | ||
5483 | * @sas_device_delete: the sas_device object | ||
5484 | * | ||
5485 | * Return nothing. | ||
5486 | */ | ||
5487 | static void | ||
5488 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, | ||
5489 | struct _sas_device *sas_device) | ||
5490 | { | ||
5491 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
5492 | |||
5493 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && | ||
5494 | (sas_device->pfa_led_on)) { | ||
5495 | _scsih_turn_off_pfa_led(ioc, sas_device); | ||
5496 | sas_device->pfa_led_on = 0; | ||
5497 | } | ||
5498 | |||
5499 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " | ||
5500 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, | ||
5501 | sas_device->handle, (unsigned long long) | ||
5502 | sas_device->sas_address)); | ||
5503 | |||
5504 | if (sas_device->starget && sas_device->starget->hostdata) { | ||
5505 | sas_target_priv_data = sas_device->starget->hostdata; | ||
5506 | sas_target_priv_data->deleted = 1; | ||
5507 | _scsih_ublock_io_device(ioc, sas_device->sas_address); | ||
5508 | sas_target_priv_data->handle = | ||
5509 | MPT2SAS_INVALID_DEVICE_HANDLE; | ||
5510 | } | ||
5511 | |||
5512 | if (!ioc->hide_drives) | ||
5513 | mpt2sas_transport_port_remove(ioc, | ||
5514 | sas_device->sas_address, | ||
5515 | sas_device->sas_address_parent); | ||
5516 | |||
5517 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" | ||
5518 | "(0x%016llx)\n", ioc->name, sas_device->handle, | ||
5519 | (unsigned long long) sas_device->sas_address); | ||
5520 | |||
5521 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " | ||
5522 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, | ||
5523 | sas_device->handle, (unsigned long long) | ||
5524 | sas_device->sas_address)); | ||
5525 | } | ||
5526 | /** | ||
5527 | * _scsih_device_remove_by_handle - removing device object by handle | ||
5528 | * @ioc: per adapter object | ||
5529 | * @handle: device handle | ||
5530 | * | ||
5531 | * Return nothing. | ||
5532 | */ | ||
5533 | static void | ||
5534 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
5535 | { | ||
5536 | struct _sas_device *sas_device; | ||
5537 | unsigned long flags; | ||
5538 | |||
5539 | if (ioc->shost_recovery) | ||
5540 | return; | ||
5541 | |||
5542 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
5543 | sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle); | ||
5544 | if (sas_device) { | ||
5545 | list_del_init(&sas_device->list); | ||
5546 | sas_device_put(sas_device); | ||
5547 | } | ||
5548 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
5549 | |||
5550 | if (sas_device) { | ||
5551 | _scsih_remove_device(ioc, sas_device); | ||
5552 | sas_device_put(sas_device); | ||
5553 | } | ||
5554 | } | ||
5555 | |||
5556 | /** | ||
5557 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address | ||
5558 | * @ioc: per adapter object | ||
5559 | * @sas_address: device sas_address | ||
5560 | * | ||
5561 | * Return nothing. | ||
5562 | */ | ||
5563 | void | ||
5564 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, | ||
5565 | u64 sas_address) | ||
5566 | { | ||
5567 | struct _sas_device *sas_device; | ||
5568 | unsigned long flags; | ||
5569 | |||
5570 | if (ioc->shost_recovery) | ||
5571 | return; | ||
5572 | |||
5573 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
5574 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, sas_address); | ||
5575 | if (sas_device) { | ||
5576 | list_del_init(&sas_device->list); | ||
5577 | sas_device_put(sas_device); | ||
5578 | } | ||
5579 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
5580 | |||
5581 | if (sas_device) { | ||
5582 | _scsih_remove_device(ioc, sas_device); | ||
5583 | sas_device_put(sas_device); | ||
5584 | } | ||
5585 | } | ||
5586 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
5587 | /** | ||
5588 | * _scsih_sas_topology_change_event_debug - debug for topology event | ||
5589 | * @ioc: per adapter object | ||
5590 | * @event_data: event data payload | ||
5591 | * Context: user. | ||
5592 | */ | ||
5593 | static void | ||
5594 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, | ||
5595 | Mpi2EventDataSasTopologyChangeList_t *event_data) | ||
5596 | { | ||
5597 | int i; | ||
5598 | u16 handle; | ||
5599 | u16 reason_code; | ||
5600 | u8 phy_number; | ||
5601 | char *status_str = NULL; | ||
5602 | u8 link_rate, prev_link_rate; | ||
5603 | |||
5604 | switch (event_data->ExpStatus) { | ||
5605 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: | ||
5606 | status_str = "add"; | ||
5607 | break; | ||
5608 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: | ||
5609 | status_str = "remove"; | ||
5610 | break; | ||
5611 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: | ||
5612 | case 0: | ||
5613 | status_str = "responding"; | ||
5614 | break; | ||
5615 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: | ||
5616 | status_str = "remove delay"; | ||
5617 | break; | ||
5618 | default: | ||
5619 | status_str = "unknown status"; | ||
5620 | break; | ||
5621 | } | ||
5622 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", | ||
5623 | ioc->name, status_str); | ||
5624 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " | ||
5625 | "start_phy(%02d), count(%d)\n", | ||
5626 | le16_to_cpu(event_data->ExpanderDevHandle), | ||
5627 | le16_to_cpu(event_data->EnclosureHandle), | ||
5628 | event_data->StartPhyNum, event_data->NumEntries); | ||
5629 | for (i = 0; i < event_data->NumEntries; i++) { | ||
5630 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | ||
5631 | if (!handle) | ||
5632 | continue; | ||
5633 | phy_number = event_data->StartPhyNum + i; | ||
5634 | reason_code = event_data->PHY[i].PhyStatus & | ||
5635 | MPI2_EVENT_SAS_TOPO_RC_MASK; | ||
5636 | switch (reason_code) { | ||
5637 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | ||
5638 | status_str = "target add"; | ||
5639 | break; | ||
5640 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | ||
5641 | status_str = "target remove"; | ||
5642 | break; | ||
5643 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: | ||
5644 | status_str = "delay target remove"; | ||
5645 | break; | ||
5646 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | ||
5647 | status_str = "link rate change"; | ||
5648 | break; | ||
5649 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: | ||
5650 | status_str = "target responding"; | ||
5651 | break; | ||
5652 | default: | ||
5653 | status_str = "unknown"; | ||
5654 | break; | ||
5655 | } | ||
5656 | link_rate = event_data->PHY[i].LinkRate >> 4; | ||
5657 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | ||
5658 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" | ||
5659 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, | ||
5660 | handle, status_str, link_rate, prev_link_rate); | ||
5661 | |||
5662 | } | ||
5663 | } | ||
5664 | #endif | ||
5665 | |||
5666 | /** | ||
5667 | * _scsih_sas_topology_change_event - handle topology changes | ||
5668 | * @ioc: per adapter object | ||
5669 | * @fw_event: The fw_event_work object | ||
5670 | * Context: user. | ||
5671 | * | ||
5672 | */ | ||
5673 | static void | ||
5674 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, | ||
5675 | struct fw_event_work *fw_event) | ||
5676 | { | ||
5677 | int i; | ||
5678 | u16 parent_handle, handle; | ||
5679 | u16 reason_code; | ||
5680 | u8 phy_number, max_phys; | ||
5681 | struct _sas_node *sas_expander; | ||
5682 | u64 sas_address; | ||
5683 | unsigned long flags; | ||
5684 | u8 link_rate, prev_link_rate; | ||
5685 | Mpi2EventDataSasTopologyChangeList_t *event_data = | ||
5686 | (Mpi2EventDataSasTopologyChangeList_t *) | ||
5687 | fw_event->event_data; | ||
5688 | |||
5689 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
5690 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | ||
5691 | _scsih_sas_topology_change_event_debug(ioc, event_data); | ||
5692 | #endif | ||
5693 | |||
5694 | if (ioc->remove_host || ioc->pci_error_recovery) | ||
5695 | return; | ||
5696 | |||
5697 | if (!ioc->sas_hba.num_phys) | ||
5698 | _scsih_sas_host_add(ioc); | ||
5699 | else | ||
5700 | _scsih_sas_host_refresh(ioc); | ||
5701 | |||
5702 | if (fw_event->ignore) { | ||
5703 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " | ||
5704 | "event\n", ioc->name)); | ||
5705 | return; | ||
5706 | } | ||
5707 | |||
5708 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); | ||
5709 | |||
5710 | /* handle expander add */ | ||
5711 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) | ||
5712 | if (_scsih_expander_add(ioc, parent_handle) != 0) | ||
5713 | return; | ||
5714 | |||
5715 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
5716 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, | ||
5717 | parent_handle); | ||
5718 | if (sas_expander) { | ||
5719 | sas_address = sas_expander->sas_address; | ||
5720 | max_phys = sas_expander->num_phys; | ||
5721 | } else if (parent_handle < ioc->sas_hba.num_phys) { | ||
5722 | sas_address = ioc->sas_hba.sas_address; | ||
5723 | max_phys = ioc->sas_hba.num_phys; | ||
5724 | } else { | ||
5725 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
5726 | return; | ||
5727 | } | ||
5728 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
5729 | |||
5730 | /* handle siblings events */ | ||
5731 | for (i = 0; i < event_data->NumEntries; i++) { | ||
5732 | if (fw_event->ignore) { | ||
5733 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " | ||
5734 | "expander event\n", ioc->name)); | ||
5735 | return; | ||
5736 | } | ||
5737 | if (ioc->shost_recovery || ioc->remove_host || | ||
5738 | ioc->pci_error_recovery) | ||
5739 | return; | ||
5740 | phy_number = event_data->StartPhyNum + i; | ||
5741 | if (phy_number >= max_phys) | ||
5742 | continue; | ||
5743 | reason_code = event_data->PHY[i].PhyStatus & | ||
5744 | MPI2_EVENT_SAS_TOPO_RC_MASK; | ||
5745 | if ((event_data->PHY[i].PhyStatus & | ||
5746 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != | ||
5747 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) | ||
5748 | continue; | ||
5749 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); | ||
5750 | if (!handle) | ||
5751 | continue; | ||
5752 | link_rate = event_data->PHY[i].LinkRate >> 4; | ||
5753 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; | ||
5754 | switch (reason_code) { | ||
5755 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: | ||
5756 | |||
5757 | if (ioc->shost_recovery) | ||
5758 | break; | ||
5759 | |||
5760 | if (link_rate == prev_link_rate) | ||
5761 | break; | ||
5762 | |||
5763 | mpt2sas_transport_update_links(ioc, sas_address, | ||
5764 | handle, phy_number, link_rate); | ||
5765 | |||
5766 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) | ||
5767 | break; | ||
5768 | |||
5769 | _scsih_check_device(ioc, handle); | ||
5770 | break; | ||
5771 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: | ||
5772 | |||
5773 | if (ioc->shost_recovery) | ||
5774 | break; | ||
5775 | |||
5776 | mpt2sas_transport_update_links(ioc, sas_address, | ||
5777 | handle, phy_number, link_rate); | ||
5778 | |||
5779 | _scsih_add_device(ioc, handle, phy_number, 0); | ||
5780 | break; | ||
5781 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: | ||
5782 | |||
5783 | _scsih_device_remove_by_handle(ioc, handle); | ||
5784 | break; | ||
5785 | } | ||
5786 | } | ||
5787 | |||
5788 | /* handle expander removal */ | ||
5789 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && | ||
5790 | sas_expander) | ||
5791 | mpt2sas_expander_remove(ioc, sas_address); | ||
5792 | |||
5793 | } | ||
5794 | |||
5795 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
5796 | /** | ||
5797 | * _scsih_sas_device_status_change_event_debug - debug for device event | ||
5798 | * @event_data: event data payload | ||
5799 | * Context: user. | ||
5800 | * | ||
5801 | * Return nothing. | ||
5802 | */ | ||
5803 | static void | ||
5804 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, | ||
5805 | Mpi2EventDataSasDeviceStatusChange_t *event_data) | ||
5806 | { | ||
5807 | char *reason_str = NULL; | ||
5808 | |||
5809 | switch (event_data->ReasonCode) { | ||
5810 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: | ||
5811 | reason_str = "smart data"; | ||
5812 | break; | ||
5813 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: | ||
5814 | reason_str = "unsupported device discovered"; | ||
5815 | break; | ||
5816 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: | ||
5817 | reason_str = "internal device reset"; | ||
5818 | break; | ||
5819 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: | ||
5820 | reason_str = "internal task abort"; | ||
5821 | break; | ||
5822 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: | ||
5823 | reason_str = "internal task abort set"; | ||
5824 | break; | ||
5825 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: | ||
5826 | reason_str = "internal clear task set"; | ||
5827 | break; | ||
5828 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: | ||
5829 | reason_str = "internal query task"; | ||
5830 | break; | ||
5831 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: | ||
5832 | reason_str = "sata init failure"; | ||
5833 | break; | ||
5834 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: | ||
5835 | reason_str = "internal device reset complete"; | ||
5836 | break; | ||
5837 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: | ||
5838 | reason_str = "internal task abort complete"; | ||
5839 | break; | ||
5840 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: | ||
5841 | reason_str = "internal async notification"; | ||
5842 | break; | ||
5843 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: | ||
5844 | reason_str = "expander reduced functionality"; | ||
5845 | break; | ||
5846 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: | ||
5847 | reason_str = "expander reduced functionality complete"; | ||
5848 | break; | ||
5849 | default: | ||
5850 | reason_str = "unknown reason"; | ||
5851 | break; | ||
5852 | } | ||
5853 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" | ||
5854 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", | ||
5855 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), | ||
5856 | (unsigned long long)le64_to_cpu(event_data->SASAddress), | ||
5857 | le16_to_cpu(event_data->TaskTag)); | ||
5858 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) | ||
5859 | printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, | ||
5860 | event_data->ASC, event_data->ASCQ); | ||
5861 | printk(KERN_INFO "\n"); | ||
5862 | } | ||
5863 | #endif | ||
5864 | |||
5865 | /** | ||
5866 | * _scsih_sas_device_status_change_event - handle device status change | ||
5867 | * @ioc: per adapter object | ||
5868 | * @fw_event: The fw_event_work object | ||
5869 | * Context: user. | ||
5870 | * | ||
5871 | * Return nothing. | ||
5872 | */ | ||
5873 | static void | ||
5874 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, | ||
5875 | struct fw_event_work *fw_event) | ||
5876 | { | ||
5877 | struct MPT2SAS_TARGET *target_priv_data; | ||
5878 | struct _sas_device *sas_device; | ||
5879 | u64 sas_address; | ||
5880 | unsigned long flags; | ||
5881 | Mpi2EventDataSasDeviceStatusChange_t *event_data = | ||
5882 | (Mpi2EventDataSasDeviceStatusChange_t *) | ||
5883 | fw_event->event_data; | ||
5884 | |||
5885 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
5886 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | ||
5887 | _scsih_sas_device_status_change_event_debug(ioc, | ||
5888 | event_data); | ||
5889 | #endif | ||
5890 | |||
5891 | /* In MPI Revision K (0xC), the internal device reset complete was | ||
5892 | * implemented, so avoid setting tm_busy flag for older firmware. | ||
5893 | */ | ||
5894 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) | ||
5895 | return; | ||
5896 | |||
5897 | if (event_data->ReasonCode != | ||
5898 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && | ||
5899 | event_data->ReasonCode != | ||
5900 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) | ||
5901 | return; | ||
5902 | |||
5903 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
5904 | sas_address = le64_to_cpu(event_data->SASAddress); | ||
5905 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
5906 | sas_address); | ||
5907 | |||
5908 | if (!sas_device || !sas_device->starget) | ||
5909 | goto out; | ||
5910 | |||
5911 | target_priv_data = sas_device->starget->hostdata; | ||
5912 | if (!target_priv_data) | ||
5913 | goto out; | ||
5914 | |||
5915 | if (event_data->ReasonCode == | ||
5916 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) | ||
5917 | target_priv_data->tm_busy = 1; | ||
5918 | else | ||
5919 | target_priv_data->tm_busy = 0; | ||
5920 | |||
5921 | out: | ||
5922 | if (sas_device) | ||
5923 | sas_device_put(sas_device); | ||
5924 | |||
5925 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
5926 | |||
5927 | } | ||
5928 | |||
5929 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
5930 | /** | ||
5931 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event | ||
5932 | * @ioc: per adapter object | ||
5933 | * @event_data: event data payload | ||
5934 | * Context: user. | ||
5935 | * | ||
5936 | * Return nothing. | ||
5937 | */ | ||
5938 | static void | ||
5939 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, | ||
5940 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) | ||
5941 | { | ||
5942 | char *reason_str = NULL; | ||
5943 | |||
5944 | switch (event_data->ReasonCode) { | ||
5945 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: | ||
5946 | reason_str = "enclosure add"; | ||
5947 | break; | ||
5948 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: | ||
5949 | reason_str = "enclosure remove"; | ||
5950 | break; | ||
5951 | default: | ||
5952 | reason_str = "unknown reason"; | ||
5953 | break; | ||
5954 | } | ||
5955 | |||
5956 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" | ||
5957 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" | ||
5958 | " number slots(%d)\n", ioc->name, reason_str, | ||
5959 | le16_to_cpu(event_data->EnclosureHandle), | ||
5960 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), | ||
5961 | le16_to_cpu(event_data->StartSlot)); | ||
5962 | } | ||
5963 | #endif | ||
5964 | |||
5965 | /** | ||
5966 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events | ||
5967 | * @ioc: per adapter object | ||
5968 | * @fw_event: The fw_event_work object | ||
5969 | * Context: user. | ||
5970 | * | ||
5971 | * Return nothing. | ||
5972 | */ | ||
5973 | static void | ||
5974 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, | ||
5975 | struct fw_event_work *fw_event) | ||
5976 | { | ||
5977 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
5978 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | ||
5979 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, | ||
5980 | (Mpi2EventDataSasEnclDevStatusChange_t *) | ||
5981 | fw_event->event_data); | ||
5982 | #endif | ||
5983 | } | ||
5984 | |||
5985 | /** | ||
5986 | * _scsih_sas_broadcast_primitive_event - handle broadcast events | ||
5987 | * @ioc: per adapter object | ||
5988 | * @fw_event: The fw_event_work object | ||
5989 | * Context: user. | ||
5990 | * | ||
5991 | * Return nothing. | ||
5992 | */ | ||
5993 | static void | ||
5994 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, | ||
5995 | struct fw_event_work *fw_event) | ||
5996 | { | ||
5997 | struct scsi_cmnd *scmd; | ||
5998 | struct scsi_device *sdev; | ||
5999 | u16 smid, handle; | ||
6000 | u32 lun; | ||
6001 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
6002 | u32 termination_count; | ||
6003 | u32 query_count; | ||
6004 | Mpi2SCSITaskManagementReply_t *mpi_reply; | ||
6005 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = | ||
6006 | (Mpi2EventDataSasBroadcastPrimitive_t *) | ||
6007 | fw_event->event_data; | ||
6008 | u16 ioc_status; | ||
6009 | unsigned long flags; | ||
6010 | int r; | ||
6011 | u8 max_retries = 0; | ||
6012 | u8 task_abort_retries; | ||
6013 | |||
6014 | mutex_lock(&ioc->tm_cmds.mutex); | ||
6015 | pr_info(MPT2SAS_FMT | ||
6016 | "%s: enter: phy number(%d), width(%d)\n", | ||
6017 | ioc->name, __func__, event_data->PhyNum, | ||
6018 | event_data->PortWidth); | ||
6019 | |||
6020 | _scsih_block_io_all_device(ioc); | ||
6021 | |||
6022 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
6023 | mpi_reply = ioc->tm_cmds.reply; | ||
6024 | broadcast_aen_retry: | ||
6025 | |||
6026 | /* sanity checks for retrying this loop */ | ||
6027 | if (max_retries++ == 5) { | ||
6028 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", | ||
6029 | ioc->name, __func__)); | ||
6030 | goto out; | ||
6031 | } else if (max_retries > 1) | ||
6032 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", | ||
6033 | ioc->name, __func__, max_retries - 1)); | ||
6034 | |||
6035 | termination_count = 0; | ||
6036 | query_count = 0; | ||
6037 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { | ||
6038 | if (ioc->shost_recovery) | ||
6039 | goto out; | ||
6040 | scmd = _scsih_scsi_lookup_get(ioc, smid); | ||
6041 | if (!scmd) | ||
6042 | continue; | ||
6043 | sdev = scmd->device; | ||
6044 | sas_device_priv_data = sdev->hostdata; | ||
6045 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) | ||
6046 | continue; | ||
6047 | /* skip hidden raid components */ | ||
6048 | if (sas_device_priv_data->sas_target->flags & | ||
6049 | MPT_TARGET_FLAGS_RAID_COMPONENT) | ||
6050 | continue; | ||
6051 | /* skip volumes */ | ||
6052 | if (sas_device_priv_data->sas_target->flags & | ||
6053 | MPT_TARGET_FLAGS_VOLUME) | ||
6054 | continue; | ||
6055 | |||
6056 | handle = sas_device_priv_data->sas_target->handle; | ||
6057 | lun = sas_device_priv_data->lun; | ||
6058 | query_count++; | ||
6059 | |||
6060 | if (ioc->shost_recovery) | ||
6061 | goto out; | ||
6062 | |||
6063 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
6064 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, | ||
6065 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, | ||
6066 | TM_MUTEX_OFF); | ||
6067 | if (r == FAILED) { | ||
6068 | sdev_printk(KERN_WARNING, sdev, | ||
6069 | "mpt2sas_scsih_issue_tm: FAILED when sending " | ||
6070 | "QUERY_TASK: scmd(%p)\n", scmd); | ||
6071 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
6072 | goto broadcast_aen_retry; | ||
6073 | } | ||
6074 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) | ||
6075 | & MPI2_IOCSTATUS_MASK; | ||
6076 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
6077 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " | ||
6078 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, | ||
6079 | scmd); | ||
6080 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
6081 | goto broadcast_aen_retry; | ||
6082 | } | ||
6083 | |||
6084 | /* see if IO is still owned by IOC and target */ | ||
6085 | if (mpi_reply->ResponseCode == | ||
6086 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || | ||
6087 | mpi_reply->ResponseCode == | ||
6088 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { | ||
6089 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
6090 | continue; | ||
6091 | } | ||
6092 | task_abort_retries = 0; | ||
6093 | tm_retry: | ||
6094 | if (task_abort_retries++ == 60) { | ||
6095 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
6096 | "%s: ABORT_TASK: giving up\n", ioc->name, | ||
6097 | __func__)); | ||
6098 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
6099 | goto broadcast_aen_retry; | ||
6100 | } | ||
6101 | |||
6102 | if (ioc->shost_recovery) | ||
6103 | goto out_no_lock; | ||
6104 | |||
6105 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, | ||
6106 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, | ||
6107 | TM_MUTEX_OFF); | ||
6108 | if (r == FAILED) { | ||
6109 | sdev_printk(KERN_WARNING, sdev, | ||
6110 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " | ||
6111 | "scmd(%p)\n", scmd); | ||
6112 | goto tm_retry; | ||
6113 | } | ||
6114 | |||
6115 | if (task_abort_retries > 1) | ||
6116 | sdev_printk(KERN_WARNING, sdev, | ||
6117 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" | ||
6118 | " scmd(%p)\n", | ||
6119 | task_abort_retries - 1, scmd); | ||
6120 | |||
6121 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); | ||
6122 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); | ||
6123 | } | ||
6124 | |||
6125 | if (ioc->broadcast_aen_pending) { | ||
6126 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" | ||
6127 | " pending AEN\n", ioc->name, __func__)); | ||
6128 | ioc->broadcast_aen_pending = 0; | ||
6129 | goto broadcast_aen_retry; | ||
6130 | } | ||
6131 | |||
6132 | out: | ||
6133 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); | ||
6134 | out_no_lock: | ||
6135 | |||
6136 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
6137 | "%s - exit, query_count = %d termination_count = %d\n", | ||
6138 | ioc->name, __func__, query_count, termination_count)); | ||
6139 | |||
6140 | ioc->broadcast_aen_busy = 0; | ||
6141 | if (!ioc->shost_recovery) | ||
6142 | _scsih_ublock_io_all_device(ioc); | ||
6143 | mutex_unlock(&ioc->tm_cmds.mutex); | ||
6144 | } | ||
6145 | |||
6146 | /** | ||
6147 | * _scsih_sas_discovery_event - handle discovery events | ||
6148 | * @ioc: per adapter object | ||
6149 | * @fw_event: The fw_event_work object | ||
6150 | * Context: user. | ||
6151 | * | ||
6152 | * Return nothing. | ||
6153 | */ | ||
6154 | static void | ||
6155 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, | ||
6156 | struct fw_event_work *fw_event) | ||
6157 | { | ||
6158 | Mpi2EventDataSasDiscovery_t *event_data = | ||
6159 | (Mpi2EventDataSasDiscovery_t *) | ||
6160 | fw_event->event_data; | ||
6161 | |||
6162 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
6163 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { | ||
6164 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, | ||
6165 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? | ||
6166 | "start" : "stop"); | ||
6167 | if (event_data->DiscoveryStatus) | ||
6168 | printk("discovery_status(0x%08x)", | ||
6169 | le32_to_cpu(event_data->DiscoveryStatus)); | ||
6170 | printk("\n"); | ||
6171 | } | ||
6172 | #endif | ||
6173 | |||
6174 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && | ||
6175 | !ioc->sas_hba.num_phys) { | ||
6176 | if (disable_discovery > 0 && ioc->shost_recovery) { | ||
6177 | /* Wait for the reset to complete */ | ||
6178 | while (ioc->shost_recovery) | ||
6179 | ssleep(1); | ||
6180 | } | ||
6181 | _scsih_sas_host_add(ioc); | ||
6182 | } | ||
6183 | } | ||
6184 | |||
6185 | /** | ||
6186 | * _scsih_reprobe_lun - reprobing lun | ||
6187 | * @sdev: scsi device struct | ||
6188 | * @no_uld_attach: sdev->no_uld_attach flag setting | ||
6189 | * | ||
6190 | **/ | ||
6191 | static void | ||
6192 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) | ||
6193 | { | ||
6194 | int rc; | ||
6195 | |||
6196 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; | ||
6197 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", | ||
6198 | sdev->no_uld_attach ? "hidding" : "exposing"); | ||
6199 | rc = scsi_device_reprobe(sdev); | ||
6200 | } | ||
6201 | |||
6202 | /** | ||
6203 | * _scsih_sas_volume_add - add new volume | ||
6204 | * @ioc: per adapter object | ||
6205 | * @element: IR config element data | ||
6206 | * Context: user. | ||
6207 | * | ||
6208 | * Return nothing. | ||
6209 | */ | ||
6210 | static void | ||
6211 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, | ||
6212 | Mpi2EventIrConfigElement_t *element) | ||
6213 | { | ||
6214 | struct _raid_device *raid_device; | ||
6215 | unsigned long flags; | ||
6216 | u64 wwid; | ||
6217 | u16 handle = le16_to_cpu(element->VolDevHandle); | ||
6218 | int rc; | ||
6219 | |||
6220 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); | ||
6221 | if (!wwid) { | ||
6222 | printk(MPT2SAS_ERR_FMT | ||
6223 | "failure at %s:%d/%s()!\n", ioc->name, | ||
6224 | __FILE__, __LINE__, __func__); | ||
6225 | return; | ||
6226 | } | ||
6227 | |||
6228 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
6229 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); | ||
6230 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
6231 | |||
6232 | if (raid_device) | ||
6233 | return; | ||
6234 | |||
6235 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | ||
6236 | if (!raid_device) { | ||
6237 | printk(MPT2SAS_ERR_FMT | ||
6238 | "failure at %s:%d/%s()!\n", ioc->name, | ||
6239 | __FILE__, __LINE__, __func__); | ||
6240 | return; | ||
6241 | } | ||
6242 | |||
6243 | raid_device->id = ioc->sas_id++; | ||
6244 | raid_device->channel = RAID_CHANNEL; | ||
6245 | raid_device->handle = handle; | ||
6246 | raid_device->wwid = wwid; | ||
6247 | _scsih_raid_device_add(ioc, raid_device); | ||
6248 | if (!ioc->wait_for_discovery_to_complete) { | ||
6249 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | ||
6250 | raid_device->id, 0); | ||
6251 | if (rc) | ||
6252 | _scsih_raid_device_remove(ioc, raid_device); | ||
6253 | } else { | ||
6254 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
6255 | _scsih_determine_boot_device(ioc, raid_device, 1); | ||
6256 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
6257 | } | ||
6258 | } | ||
6259 | |||
6260 | /** | ||
6261 | * _scsih_sas_volume_delete - delete volume | ||
6262 | * @ioc: per adapter object | ||
6263 | * @handle: volume device handle | ||
6264 | * Context: user. | ||
6265 | * | ||
6266 | * Return nothing. | ||
6267 | */ | ||
6268 | static void | ||
6269 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) | ||
6270 | { | ||
6271 | struct _raid_device *raid_device; | ||
6272 | unsigned long flags; | ||
6273 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
6274 | struct scsi_target *starget = NULL; | ||
6275 | |||
6276 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
6277 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | ||
6278 | if (raid_device) { | ||
6279 | if (raid_device->starget) { | ||
6280 | starget = raid_device->starget; | ||
6281 | sas_target_priv_data = starget->hostdata; | ||
6282 | sas_target_priv_data->deleted = 1; | ||
6283 | } | ||
6284 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" | ||
6285 | "(0x%016llx)\n", ioc->name, raid_device->handle, | ||
6286 | (unsigned long long) raid_device->wwid); | ||
6287 | list_del(&raid_device->list); | ||
6288 | kfree(raid_device); | ||
6289 | } | ||
6290 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
6291 | if (starget) | ||
6292 | scsi_remove_target(&starget->dev); | ||
6293 | } | ||
6294 | |||
6295 | /** | ||
6296 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX | ||
6297 | * @ioc: per adapter object | ||
6298 | * @element: IR config element data | ||
6299 | * Context: user. | ||
6300 | * | ||
6301 | * Return nothing. | ||
6302 | */ | ||
6303 | static void | ||
6304 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, | ||
6305 | Mpi2EventIrConfigElement_t *element) | ||
6306 | { | ||
6307 | struct _sas_device *sas_device; | ||
6308 | struct scsi_target *starget = NULL; | ||
6309 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
6310 | unsigned long flags; | ||
6311 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | ||
6312 | |||
6313 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
6314 | sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle); | ||
6315 | if (sas_device) { | ||
6316 | sas_device->volume_handle = 0; | ||
6317 | sas_device->volume_wwid = 0; | ||
6318 | clear_bit(handle, ioc->pd_handles); | ||
6319 | if (sas_device->starget && sas_device->starget->hostdata) { | ||
6320 | starget = sas_device->starget; | ||
6321 | sas_target_priv_data = starget->hostdata; | ||
6322 | sas_target_priv_data->flags &= | ||
6323 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; | ||
6324 | } | ||
6325 | } | ||
6326 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
6327 | if (!sas_device) | ||
6328 | return; | ||
6329 | |||
6330 | /* exposing raid component */ | ||
6331 | if (starget) | ||
6332 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); | ||
6333 | |||
6334 | sas_device_put(sas_device); | ||
6335 | } | ||
6336 | |||
6337 | /** | ||
6338 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX | ||
6339 | * @ioc: per adapter object | ||
6340 | * @element: IR config element data | ||
6341 | * Context: user. | ||
6342 | * | ||
6343 | * Return nothing. | ||
6344 | */ | ||
6345 | static void | ||
6346 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, | ||
6347 | Mpi2EventIrConfigElement_t *element) | ||
6348 | { | ||
6349 | struct _sas_device *sas_device; | ||
6350 | struct scsi_target *starget = NULL; | ||
6351 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
6352 | unsigned long flags; | ||
6353 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | ||
6354 | u16 volume_handle = 0; | ||
6355 | u64 volume_wwid = 0; | ||
6356 | |||
6357 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); | ||
6358 | if (volume_handle) | ||
6359 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, | ||
6360 | &volume_wwid); | ||
6361 | |||
6362 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
6363 | sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle); | ||
6364 | if (sas_device) { | ||
6365 | set_bit(handle, ioc->pd_handles); | ||
6366 | if (sas_device->starget && sas_device->starget->hostdata) { | ||
6367 | starget = sas_device->starget; | ||
6368 | sas_target_priv_data = starget->hostdata; | ||
6369 | sas_target_priv_data->flags |= | ||
6370 | MPT_TARGET_FLAGS_RAID_COMPONENT; | ||
6371 | sas_device->volume_handle = volume_handle; | ||
6372 | sas_device->volume_wwid = volume_wwid; | ||
6373 | } | ||
6374 | } | ||
6375 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
6376 | if (!sas_device) | ||
6377 | return; | ||
6378 | |||
6379 | /* hiding raid component */ | ||
6380 | if (starget) | ||
6381 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); | ||
6382 | |||
6383 | sas_device_put(sas_device); | ||
6384 | } | ||
6385 | |||
6386 | /** | ||
6387 | * _scsih_sas_pd_delete - delete pd component | ||
6388 | * @ioc: per adapter object | ||
6389 | * @element: IR config element data | ||
6390 | * Context: user. | ||
6391 | * | ||
6392 | * Return nothing. | ||
6393 | */ | ||
6394 | static void | ||
6395 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, | ||
6396 | Mpi2EventIrConfigElement_t *element) | ||
6397 | { | ||
6398 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | ||
6399 | |||
6400 | _scsih_device_remove_by_handle(ioc, handle); | ||
6401 | } | ||
6402 | |||
6403 | /** | ||
6404 | * _scsih_sas_pd_add - remove pd component | ||
6405 | * @ioc: per adapter object | ||
6406 | * @element: IR config element data | ||
6407 | * Context: user. | ||
6408 | * | ||
6409 | * Return nothing. | ||
6410 | */ | ||
6411 | static void | ||
6412 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, | ||
6413 | Mpi2EventIrConfigElement_t *element) | ||
6414 | { | ||
6415 | struct _sas_device *sas_device; | ||
6416 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); | ||
6417 | Mpi2ConfigReply_t mpi_reply; | ||
6418 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
6419 | u32 ioc_status; | ||
6420 | u64 sas_address; | ||
6421 | u16 parent_handle; | ||
6422 | |||
6423 | set_bit(handle, ioc->pd_handles); | ||
6424 | |||
6425 | sas_device = mpt2sas_get_sdev_by_handle(ioc, handle); | ||
6426 | if (sas_device) { | ||
6427 | sas_device_put(sas_device); | ||
6428 | return; | ||
6429 | } | ||
6430 | |||
6431 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
6432 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | ||
6433 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
6434 | ioc->name, __FILE__, __LINE__, __func__); | ||
6435 | return; | ||
6436 | } | ||
6437 | |||
6438 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
6439 | MPI2_IOCSTATUS_MASK; | ||
6440 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
6441 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
6442 | ioc->name, __FILE__, __LINE__, __func__); | ||
6443 | return; | ||
6444 | } | ||
6445 | |||
6446 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | ||
6447 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | ||
6448 | mpt2sas_transport_update_links(ioc, sas_address, handle, | ||
6449 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | ||
6450 | |||
6451 | _scsih_add_device(ioc, handle, 0, 1); | ||
6452 | } | ||
6453 | |||
6454 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
6455 | /** | ||
6456 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events | ||
6457 | * @ioc: per adapter object | ||
6458 | * @event_data: event data payload | ||
6459 | * Context: user. | ||
6460 | * | ||
6461 | * Return nothing. | ||
6462 | */ | ||
6463 | static void | ||
6464 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, | ||
6465 | Mpi2EventDataIrConfigChangeList_t *event_data) | ||
6466 | { | ||
6467 | Mpi2EventIrConfigElement_t *element; | ||
6468 | u8 element_type; | ||
6469 | int i; | ||
6470 | char *reason_str = NULL, *element_str = NULL; | ||
6471 | |||
6472 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | ||
6473 | |||
6474 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", | ||
6475 | ioc->name, (le32_to_cpu(event_data->Flags) & | ||
6476 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? | ||
6477 | "foreign" : "native", event_data->NumElements); | ||
6478 | for (i = 0; i < event_data->NumElements; i++, element++) { | ||
6479 | switch (element->ReasonCode) { | ||
6480 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | ||
6481 | reason_str = "add"; | ||
6482 | break; | ||
6483 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | ||
6484 | reason_str = "remove"; | ||
6485 | break; | ||
6486 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: | ||
6487 | reason_str = "no change"; | ||
6488 | break; | ||
6489 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | ||
6490 | reason_str = "hide"; | ||
6491 | break; | ||
6492 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | ||
6493 | reason_str = "unhide"; | ||
6494 | break; | ||
6495 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | ||
6496 | reason_str = "volume_created"; | ||
6497 | break; | ||
6498 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | ||
6499 | reason_str = "volume_deleted"; | ||
6500 | break; | ||
6501 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | ||
6502 | reason_str = "pd_created"; | ||
6503 | break; | ||
6504 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | ||
6505 | reason_str = "pd_deleted"; | ||
6506 | break; | ||
6507 | default: | ||
6508 | reason_str = "unknown reason"; | ||
6509 | break; | ||
6510 | } | ||
6511 | element_type = le16_to_cpu(element->ElementFlags) & | ||
6512 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; | ||
6513 | switch (element_type) { | ||
6514 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: | ||
6515 | element_str = "volume"; | ||
6516 | break; | ||
6517 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: | ||
6518 | element_str = "phys disk"; | ||
6519 | break; | ||
6520 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: | ||
6521 | element_str = "hot spare"; | ||
6522 | break; | ||
6523 | default: | ||
6524 | element_str = "unknown element"; | ||
6525 | break; | ||
6526 | } | ||
6527 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " | ||
6528 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, | ||
6529 | reason_str, le16_to_cpu(element->VolDevHandle), | ||
6530 | le16_to_cpu(element->PhysDiskDevHandle), | ||
6531 | element->PhysDiskNum); | ||
6532 | } | ||
6533 | } | ||
6534 | #endif | ||
6535 | |||
6536 | /** | ||
6537 | * _scsih_sas_ir_config_change_event - handle ir configuration change events | ||
6538 | * @ioc: per adapter object | ||
6539 | * @fw_event: The fw_event_work object | ||
6540 | * Context: user. | ||
6541 | * | ||
6542 | * Return nothing. | ||
6543 | */ | ||
6544 | static void | ||
6545 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, | ||
6546 | struct fw_event_work *fw_event) | ||
6547 | { | ||
6548 | Mpi2EventIrConfigElement_t *element; | ||
6549 | int i; | ||
6550 | u8 foreign_config; | ||
6551 | Mpi2EventDataIrConfigChangeList_t *event_data = | ||
6552 | (Mpi2EventDataIrConfigChangeList_t *) | ||
6553 | fw_event->event_data; | ||
6554 | |||
6555 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
6556 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | ||
6557 | && !ioc->hide_ir_msg) | ||
6558 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); | ||
6559 | |||
6560 | #endif | ||
6561 | |||
6562 | if (ioc->shost_recovery) | ||
6563 | return; | ||
6564 | |||
6565 | foreign_config = (le32_to_cpu(event_data->Flags) & | ||
6566 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; | ||
6567 | |||
6568 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; | ||
6569 | for (i = 0; i < event_data->NumElements; i++, element++) { | ||
6570 | |||
6571 | switch (element->ReasonCode) { | ||
6572 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: | ||
6573 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: | ||
6574 | if (!foreign_config) | ||
6575 | _scsih_sas_volume_add(ioc, element); | ||
6576 | break; | ||
6577 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: | ||
6578 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: | ||
6579 | if (!foreign_config) | ||
6580 | _scsih_sas_volume_delete(ioc, | ||
6581 | le16_to_cpu(element->VolDevHandle)); | ||
6582 | break; | ||
6583 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: | ||
6584 | if (!ioc->is_warpdrive) | ||
6585 | _scsih_sas_pd_hide(ioc, element); | ||
6586 | break; | ||
6587 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: | ||
6588 | if (!ioc->is_warpdrive) | ||
6589 | _scsih_sas_pd_expose(ioc, element); | ||
6590 | break; | ||
6591 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: | ||
6592 | if (!ioc->is_warpdrive) | ||
6593 | _scsih_sas_pd_add(ioc, element); | ||
6594 | break; | ||
6595 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: | ||
6596 | if (!ioc->is_warpdrive) | ||
6597 | _scsih_sas_pd_delete(ioc, element); | ||
6598 | break; | ||
6599 | } | ||
6600 | } | ||
6601 | } | ||
6602 | |||
6603 | /** | ||
6604 | * _scsih_sas_ir_volume_event - IR volume event | ||
6605 | * @ioc: per adapter object | ||
6606 | * @fw_event: The fw_event_work object | ||
6607 | * Context: user. | ||
6608 | * | ||
6609 | * Return nothing. | ||
6610 | */ | ||
6611 | static void | ||
6612 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, | ||
6613 | struct fw_event_work *fw_event) | ||
6614 | { | ||
6615 | u64 wwid; | ||
6616 | unsigned long flags; | ||
6617 | struct _raid_device *raid_device; | ||
6618 | u16 handle; | ||
6619 | u32 state; | ||
6620 | int rc; | ||
6621 | Mpi2EventDataIrVolume_t *event_data = | ||
6622 | (Mpi2EventDataIrVolume_t *) | ||
6623 | fw_event->event_data; | ||
6624 | |||
6625 | if (ioc->shost_recovery) | ||
6626 | return; | ||
6627 | |||
6628 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) | ||
6629 | return; | ||
6630 | |||
6631 | handle = le16_to_cpu(event_data->VolDevHandle); | ||
6632 | state = le32_to_cpu(event_data->NewValue); | ||
6633 | if (!ioc->hide_ir_msg) | ||
6634 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " | ||
6635 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, | ||
6636 | le32_to_cpu(event_data->PreviousValue), state)); | ||
6637 | |||
6638 | switch (state) { | ||
6639 | case MPI2_RAID_VOL_STATE_MISSING: | ||
6640 | case MPI2_RAID_VOL_STATE_FAILED: | ||
6641 | _scsih_sas_volume_delete(ioc, handle); | ||
6642 | break; | ||
6643 | |||
6644 | case MPI2_RAID_VOL_STATE_ONLINE: | ||
6645 | case MPI2_RAID_VOL_STATE_DEGRADED: | ||
6646 | case MPI2_RAID_VOL_STATE_OPTIMAL: | ||
6647 | |||
6648 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
6649 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | ||
6650 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
6651 | |||
6652 | if (raid_device) | ||
6653 | break; | ||
6654 | |||
6655 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); | ||
6656 | if (!wwid) { | ||
6657 | printk(MPT2SAS_ERR_FMT | ||
6658 | "failure at %s:%d/%s()!\n", ioc->name, | ||
6659 | __FILE__, __LINE__, __func__); | ||
6660 | break; | ||
6661 | } | ||
6662 | |||
6663 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); | ||
6664 | if (!raid_device) { | ||
6665 | printk(MPT2SAS_ERR_FMT | ||
6666 | "failure at %s:%d/%s()!\n", ioc->name, | ||
6667 | __FILE__, __LINE__, __func__); | ||
6668 | break; | ||
6669 | } | ||
6670 | |||
6671 | raid_device->id = ioc->sas_id++; | ||
6672 | raid_device->channel = RAID_CHANNEL; | ||
6673 | raid_device->handle = handle; | ||
6674 | raid_device->wwid = wwid; | ||
6675 | _scsih_raid_device_add(ioc, raid_device); | ||
6676 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | ||
6677 | raid_device->id, 0); | ||
6678 | if (rc) | ||
6679 | _scsih_raid_device_remove(ioc, raid_device); | ||
6680 | break; | ||
6681 | |||
6682 | case MPI2_RAID_VOL_STATE_INITIALIZING: | ||
6683 | default: | ||
6684 | break; | ||
6685 | } | ||
6686 | } | ||
6687 | |||
6688 | /** | ||
6689 | * _scsih_sas_ir_physical_disk_event - PD event | ||
6690 | * @ioc: per adapter object | ||
6691 | * @fw_event: The fw_event_work object | ||
6692 | * Context: user. | ||
6693 | * | ||
6694 | * Return nothing. | ||
6695 | */ | ||
6696 | static void | ||
6697 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, | ||
6698 | struct fw_event_work *fw_event) | ||
6699 | { | ||
6700 | u16 handle, parent_handle; | ||
6701 | u32 state; | ||
6702 | struct _sas_device *sas_device; | ||
6703 | Mpi2ConfigReply_t mpi_reply; | ||
6704 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
6705 | u32 ioc_status; | ||
6706 | Mpi2EventDataIrPhysicalDisk_t *event_data = | ||
6707 | (Mpi2EventDataIrPhysicalDisk_t *) | ||
6708 | fw_event->event_data; | ||
6709 | u64 sas_address; | ||
6710 | |||
6711 | if (ioc->shost_recovery) | ||
6712 | return; | ||
6713 | |||
6714 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) | ||
6715 | return; | ||
6716 | |||
6717 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); | ||
6718 | state = le32_to_cpu(event_data->NewValue); | ||
6719 | |||
6720 | if (!ioc->hide_ir_msg) | ||
6721 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " | ||
6722 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, | ||
6723 | le32_to_cpu(event_data->PreviousValue), state)); | ||
6724 | |||
6725 | switch (state) { | ||
6726 | case MPI2_RAID_PD_STATE_ONLINE: | ||
6727 | case MPI2_RAID_PD_STATE_DEGRADED: | ||
6728 | case MPI2_RAID_PD_STATE_REBUILDING: | ||
6729 | case MPI2_RAID_PD_STATE_OPTIMAL: | ||
6730 | case MPI2_RAID_PD_STATE_HOT_SPARE: | ||
6731 | |||
6732 | if (!ioc->is_warpdrive) | ||
6733 | set_bit(handle, ioc->pd_handles); | ||
6734 | |||
6735 | sas_device = mpt2sas_get_sdev_by_handle(ioc, handle); | ||
6736 | if (sas_device) { | ||
6737 | sas_device_put(sas_device); | ||
6738 | return; | ||
6739 | } | ||
6740 | |||
6741 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, | ||
6742 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | ||
6743 | handle))) { | ||
6744 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
6745 | ioc->name, __FILE__, __LINE__, __func__); | ||
6746 | return; | ||
6747 | } | ||
6748 | |||
6749 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
6750 | MPI2_IOCSTATUS_MASK; | ||
6751 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
6752 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
6753 | ioc->name, __FILE__, __LINE__, __func__); | ||
6754 | return; | ||
6755 | } | ||
6756 | |||
6757 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | ||
6758 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) | ||
6759 | mpt2sas_transport_update_links(ioc, sas_address, handle, | ||
6760 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | ||
6761 | |||
6762 | _scsih_add_device(ioc, handle, 0, 1); | ||
6763 | |||
6764 | break; | ||
6765 | |||
6766 | case MPI2_RAID_PD_STATE_OFFLINE: | ||
6767 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: | ||
6768 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: | ||
6769 | default: | ||
6770 | break; | ||
6771 | } | ||
6772 | } | ||
6773 | |||
6774 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
6775 | /** | ||
6776 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event | ||
6777 | * @ioc: per adapter object | ||
6778 | * @event_data: event data payload | ||
6779 | * Context: user. | ||
6780 | * | ||
6781 | * Return nothing. | ||
6782 | */ | ||
6783 | static void | ||
6784 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, | ||
6785 | Mpi2EventDataIrOperationStatus_t *event_data) | ||
6786 | { | ||
6787 | char *reason_str = NULL; | ||
6788 | |||
6789 | switch (event_data->RAIDOperation) { | ||
6790 | case MPI2_EVENT_IR_RAIDOP_RESYNC: | ||
6791 | reason_str = "resync"; | ||
6792 | break; | ||
6793 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: | ||
6794 | reason_str = "online capacity expansion"; | ||
6795 | break; | ||
6796 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: | ||
6797 | reason_str = "consistency check"; | ||
6798 | break; | ||
6799 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: | ||
6800 | reason_str = "background init"; | ||
6801 | break; | ||
6802 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: | ||
6803 | reason_str = "make data consistent"; | ||
6804 | break; | ||
6805 | } | ||
6806 | |||
6807 | if (!reason_str) | ||
6808 | return; | ||
6809 | |||
6810 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" | ||
6811 | "\thandle(0x%04x), percent complete(%d)\n", | ||
6812 | ioc->name, reason_str, | ||
6813 | le16_to_cpu(event_data->VolDevHandle), | ||
6814 | event_data->PercentComplete); | ||
6815 | } | ||
6816 | #endif | ||
6817 | |||
6818 | /** | ||
6819 | * _scsih_sas_ir_operation_status_event - handle RAID operation events | ||
6820 | * @ioc: per adapter object | ||
6821 | * @fw_event: The fw_event_work object | ||
6822 | * Context: user. | ||
6823 | * | ||
6824 | * Return nothing. | ||
6825 | */ | ||
6826 | static void | ||
6827 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, | ||
6828 | struct fw_event_work *fw_event) | ||
6829 | { | ||
6830 | Mpi2EventDataIrOperationStatus_t *event_data = | ||
6831 | (Mpi2EventDataIrOperationStatus_t *) | ||
6832 | fw_event->event_data; | ||
6833 | static struct _raid_device *raid_device; | ||
6834 | unsigned long flags; | ||
6835 | u16 handle; | ||
6836 | |||
6837 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING | ||
6838 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) | ||
6839 | && !ioc->hide_ir_msg) | ||
6840 | _scsih_sas_ir_operation_status_event_debug(ioc, | ||
6841 | event_data); | ||
6842 | #endif | ||
6843 | |||
6844 | /* code added for raid transport support */ | ||
6845 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { | ||
6846 | |||
6847 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
6848 | handle = le16_to_cpu(event_data->VolDevHandle); | ||
6849 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); | ||
6850 | if (raid_device) | ||
6851 | raid_device->percent_complete = | ||
6852 | event_data->PercentComplete; | ||
6853 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
6854 | } | ||
6855 | } | ||
6856 | |||
6857 | /** | ||
6858 | * _scsih_prep_device_scan - initialize parameters prior to device scan | ||
6859 | * @ioc: per adapter object | ||
6860 | * | ||
6861 | * Set the deleted flag prior to device scan. If the device is found during | ||
6862 | * the scan, then we clear the deleted flag. | ||
6863 | */ | ||
6864 | static void | ||
6865 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) | ||
6866 | { | ||
6867 | struct MPT2SAS_DEVICE *sas_device_priv_data; | ||
6868 | struct scsi_device *sdev; | ||
6869 | |||
6870 | shost_for_each_device(sdev, ioc->shost) { | ||
6871 | sas_device_priv_data = sdev->hostdata; | ||
6872 | if (sas_device_priv_data && sas_device_priv_data->sas_target) | ||
6873 | sas_device_priv_data->sas_target->deleted = 1; | ||
6874 | } | ||
6875 | } | ||
6876 | |||
6877 | /** | ||
6878 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding | ||
6879 | * @ioc: per adapter object | ||
6880 | * @sas_address: sas address | ||
6881 | * @slot: enclosure slot id | ||
6882 | * @handle: device handle | ||
6883 | * | ||
6884 | * After host reset, find out whether devices are still responding. | ||
6885 | * Used in _scsi_remove_unresponsive_sas_devices. | ||
6886 | * | ||
6887 | * Return nothing. | ||
6888 | */ | ||
6889 | static void | ||
6890 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, | ||
6891 | u16 slot, u16 handle) | ||
6892 | { | ||
6893 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; | ||
6894 | struct scsi_target *starget; | ||
6895 | struct _sas_device *sas_device; | ||
6896 | unsigned long flags; | ||
6897 | |||
6898 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
6899 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { | ||
6900 | if (sas_device->sas_address == sas_address && | ||
6901 | sas_device->slot == slot) { | ||
6902 | sas_device->responding = 1; | ||
6903 | starget = sas_device->starget; | ||
6904 | if (starget && starget->hostdata) { | ||
6905 | sas_target_priv_data = starget->hostdata; | ||
6906 | sas_target_priv_data->tm_busy = 0; | ||
6907 | sas_target_priv_data->deleted = 0; | ||
6908 | } else | ||
6909 | sas_target_priv_data = NULL; | ||
6910 | if (starget) | ||
6911 | starget_printk(KERN_INFO, starget, | ||
6912 | "handle(0x%04x), sas_addr(0x%016llx), " | ||
6913 | "enclosure logical id(0x%016llx), " | ||
6914 | "slot(%d)\n", handle, | ||
6915 | (unsigned long long)sas_device->sas_address, | ||
6916 | (unsigned long long) | ||
6917 | sas_device->enclosure_logical_id, | ||
6918 | sas_device->slot); | ||
6919 | if (sas_device->handle == handle) | ||
6920 | goto out; | ||
6921 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", | ||
6922 | sas_device->handle); | ||
6923 | sas_device->handle = handle; | ||
6924 | if (sas_target_priv_data) | ||
6925 | sas_target_priv_data->handle = handle; | ||
6926 | goto out; | ||
6927 | } | ||
6928 | } | ||
6929 | out: | ||
6930 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
6931 | } | ||
6932 | |||
6933 | /** | ||
6934 | * _scsih_search_responding_sas_devices - | ||
6935 | * @ioc: per adapter object | ||
6936 | * | ||
6937 | * After host reset, find out whether devices are still responding. | ||
6938 | * If not remove. | ||
6939 | * | ||
6940 | * Return nothing. | ||
6941 | */ | ||
6942 | static void | ||
6943 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) | ||
6944 | { | ||
6945 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
6946 | Mpi2ConfigReply_t mpi_reply; | ||
6947 | u16 ioc_status; | ||
6948 | __le64 sas_address; | ||
6949 | u16 handle; | ||
6950 | u32 device_info; | ||
6951 | u16 slot; | ||
6952 | |||
6953 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); | ||
6954 | |||
6955 | if (list_empty(&ioc->sas_device_list)) | ||
6956 | goto out; | ||
6957 | |||
6958 | handle = 0xFFFF; | ||
6959 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, | ||
6960 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | ||
6961 | handle))) { | ||
6962 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
6963 | MPI2_IOCSTATUS_MASK; | ||
6964 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
6965 | break; | ||
6966 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | ||
6967 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | ||
6968 | if (!(_scsih_is_end_device(device_info))) | ||
6969 | continue; | ||
6970 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | ||
6971 | slot = le16_to_cpu(sas_device_pg0.Slot); | ||
6972 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, | ||
6973 | handle); | ||
6974 | } | ||
6975 | out: | ||
6976 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", | ||
6977 | ioc->name); | ||
6978 | } | ||
6979 | |||
6980 | /** | ||
6981 | * _scsih_mark_responding_raid_device - mark a raid_device as responding | ||
6982 | * @ioc: per adapter object | ||
6983 | * @wwid: world wide identifier for raid volume | ||
6984 | * @handle: device handle | ||
6985 | * | ||
6986 | * After host reset, find out whether devices are still responding. | ||
6987 | * Used in _scsi_remove_unresponsive_raid_devices. | ||
6988 | * | ||
6989 | * Return nothing. | ||
6990 | */ | ||
6991 | static void | ||
6992 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, | ||
6993 | u16 handle) | ||
6994 | { | ||
6995 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
6996 | struct scsi_target *starget; | ||
6997 | struct _raid_device *raid_device; | ||
6998 | unsigned long flags; | ||
6999 | |||
7000 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
7001 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { | ||
7002 | if (raid_device->wwid == wwid && raid_device->starget) { | ||
7003 | starget = raid_device->starget; | ||
7004 | if (starget && starget->hostdata) { | ||
7005 | sas_target_priv_data = starget->hostdata; | ||
7006 | sas_target_priv_data->deleted = 0; | ||
7007 | } else | ||
7008 | sas_target_priv_data = NULL; | ||
7009 | raid_device->responding = 1; | ||
7010 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
7011 | starget_printk(KERN_INFO, raid_device->starget, | ||
7012 | "handle(0x%04x), wwid(0x%016llx)\n", handle, | ||
7013 | (unsigned long long)raid_device->wwid); | ||
7014 | /* | ||
7015 | * WARPDRIVE: The handles of the PDs might have changed | ||
7016 | * across the host reset so re-initialize the | ||
7017 | * required data for Direct IO | ||
7018 | */ | ||
7019 | _scsih_init_warpdrive_properties(ioc, raid_device); | ||
7020 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
7021 | if (raid_device->handle == handle) { | ||
7022 | spin_unlock_irqrestore(&ioc->raid_device_lock, | ||
7023 | flags); | ||
7024 | return; | ||
7025 | } | ||
7026 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", | ||
7027 | raid_device->handle); | ||
7028 | raid_device->handle = handle; | ||
7029 | if (sas_target_priv_data) | ||
7030 | sas_target_priv_data->handle = handle; | ||
7031 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
7032 | return; | ||
7033 | } | ||
7034 | } | ||
7035 | |||
7036 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
7037 | } | ||
7038 | |||
7039 | /** | ||
7040 | * _scsih_search_responding_raid_devices - | ||
7041 | * @ioc: per adapter object | ||
7042 | * | ||
7043 | * After host reset, find out whether devices are still responding. | ||
7044 | * If not remove. | ||
7045 | * | ||
7046 | * Return nothing. | ||
7047 | */ | ||
7048 | static void | ||
7049 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) | ||
7050 | { | ||
7051 | Mpi2RaidVolPage1_t volume_pg1; | ||
7052 | Mpi2RaidVolPage0_t volume_pg0; | ||
7053 | Mpi2RaidPhysDiskPage0_t pd_pg0; | ||
7054 | Mpi2ConfigReply_t mpi_reply; | ||
7055 | u16 ioc_status; | ||
7056 | u16 handle; | ||
7057 | u8 phys_disk_num; | ||
7058 | |||
7059 | if (!ioc->ir_firmware) | ||
7060 | return; | ||
7061 | |||
7062 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", | ||
7063 | ioc->name); | ||
7064 | |||
7065 | if (list_empty(&ioc->raid_device_list)) | ||
7066 | goto out; | ||
7067 | |||
7068 | handle = 0xFFFF; | ||
7069 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | ||
7070 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | ||
7071 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7072 | MPI2_IOCSTATUS_MASK; | ||
7073 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
7074 | break; | ||
7075 | handle = le16_to_cpu(volume_pg1.DevHandle); | ||
7076 | |||
7077 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | ||
7078 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | ||
7079 | sizeof(Mpi2RaidVolPage0_t))) | ||
7080 | continue; | ||
7081 | |||
7082 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | ||
7083 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | ||
7084 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) | ||
7085 | _scsih_mark_responding_raid_device(ioc, | ||
7086 | le64_to_cpu(volume_pg1.WWID), handle); | ||
7087 | } | ||
7088 | |||
7089 | /* refresh the pd_handles */ | ||
7090 | if (!ioc->is_warpdrive) { | ||
7091 | phys_disk_num = 0xFF; | ||
7092 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); | ||
7093 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | ||
7094 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | ||
7095 | phys_disk_num))) { | ||
7096 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7097 | MPI2_IOCSTATUS_MASK; | ||
7098 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
7099 | break; | ||
7100 | phys_disk_num = pd_pg0.PhysDiskNum; | ||
7101 | handle = le16_to_cpu(pd_pg0.DevHandle); | ||
7102 | set_bit(handle, ioc->pd_handles); | ||
7103 | } | ||
7104 | } | ||
7105 | out: | ||
7106 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " | ||
7107 | "complete\n", ioc->name); | ||
7108 | } | ||
7109 | |||
7110 | /** | ||
7111 | * _scsih_mark_responding_expander - mark a expander as responding | ||
7112 | * @ioc: per adapter object | ||
7113 | * @sas_address: sas address | ||
7114 | * @handle: | ||
7115 | * | ||
7116 | * After host reset, find out whether devices are still responding. | ||
7117 | * Used in _scsi_remove_unresponsive_expanders. | ||
7118 | * | ||
7119 | * Return nothing. | ||
7120 | */ | ||
7121 | static void | ||
7122 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, | ||
7123 | u16 handle) | ||
7124 | { | ||
7125 | struct _sas_node *sas_expander; | ||
7126 | unsigned long flags; | ||
7127 | int i; | ||
7128 | |||
7129 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
7130 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { | ||
7131 | if (sas_expander->sas_address != sas_address) | ||
7132 | continue; | ||
7133 | sas_expander->responding = 1; | ||
7134 | if (sas_expander->handle == handle) | ||
7135 | goto out; | ||
7136 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" | ||
7137 | " from(0x%04x) to (0x%04x)!!!\n", | ||
7138 | (unsigned long long)sas_expander->sas_address, | ||
7139 | sas_expander->handle, handle); | ||
7140 | sas_expander->handle = handle; | ||
7141 | for (i = 0 ; i < sas_expander->num_phys ; i++) | ||
7142 | sas_expander->phy[i].handle = handle; | ||
7143 | goto out; | ||
7144 | } | ||
7145 | out: | ||
7146 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
7147 | } | ||
7148 | |||
7149 | /** | ||
7150 | * _scsih_search_responding_expanders - | ||
7151 | * @ioc: per adapter object | ||
7152 | * | ||
7153 | * After host reset, find out whether devices are still responding. | ||
7154 | * If not remove. | ||
7155 | * | ||
7156 | * Return nothing. | ||
7157 | */ | ||
7158 | static void | ||
7159 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) | ||
7160 | { | ||
7161 | Mpi2ExpanderPage0_t expander_pg0; | ||
7162 | Mpi2ConfigReply_t mpi_reply; | ||
7163 | u16 ioc_status; | ||
7164 | u64 sas_address; | ||
7165 | u16 handle; | ||
7166 | |||
7167 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); | ||
7168 | |||
7169 | if (list_empty(&ioc->sas_expander_list)) | ||
7170 | goto out; | ||
7171 | |||
7172 | handle = 0xFFFF; | ||
7173 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | ||
7174 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | ||
7175 | |||
7176 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7177 | MPI2_IOCSTATUS_MASK; | ||
7178 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) | ||
7179 | break; | ||
7180 | |||
7181 | handle = le16_to_cpu(expander_pg0.DevHandle); | ||
7182 | sas_address = le64_to_cpu(expander_pg0.SASAddress); | ||
7183 | printk(KERN_INFO "\texpander present: handle(0x%04x), " | ||
7184 | "sas_addr(0x%016llx)\n", handle, | ||
7185 | (unsigned long long)sas_address); | ||
7186 | _scsih_mark_responding_expander(ioc, sas_address, handle); | ||
7187 | } | ||
7188 | |||
7189 | out: | ||
7190 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); | ||
7191 | } | ||
7192 | |||
7193 | /** | ||
7194 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices | ||
7195 | * @ioc: per adapter object | ||
7196 | * | ||
7197 | * Return nothing. | ||
7198 | */ | ||
7199 | static void | ||
7200 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) | ||
7201 | { | ||
7202 | struct _sas_device *sas_device, *sas_device_next; | ||
7203 | struct _sas_node *sas_expander, *sas_expander_next; | ||
7204 | struct _raid_device *raid_device, *raid_device_next; | ||
7205 | struct list_head tmp_list; | ||
7206 | unsigned long flags; | ||
7207 | LIST_HEAD(head); | ||
7208 | |||
7209 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", | ||
7210 | ioc->name); | ||
7211 | |||
7212 | /* removing unresponding end devices */ | ||
7213 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", | ||
7214 | ioc->name); | ||
7215 | |||
7216 | /* | ||
7217 | * Iterate, pulling off devices marked as non-responding. We become the | ||
7218 | * owner for the reference the list had on any object we prune. | ||
7219 | */ | ||
7220 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
7221 | list_for_each_entry_safe(sas_device, sas_device_next, | ||
7222 | &ioc->sas_device_list, list) { | ||
7223 | if (!sas_device->responding) | ||
7224 | list_move_tail(&sas_device->list, &head); | ||
7225 | else | ||
7226 | sas_device->responding = 0; | ||
7227 | } | ||
7228 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
7229 | |||
7230 | /* | ||
7231 | * Now, uninitialize and remove the unresponding devices we pruned. | ||
7232 | */ | ||
7233 | list_for_each_entry_safe(sas_device, sas_device_next, &head, list) { | ||
7234 | _scsih_remove_device(ioc, sas_device); | ||
7235 | list_del_init(&sas_device->list); | ||
7236 | sas_device_put(sas_device); | ||
7237 | } | ||
7238 | |||
7239 | /* removing unresponding volumes */ | ||
7240 | if (ioc->ir_firmware) { | ||
7241 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " | ||
7242 | "volumes\n", ioc->name); | ||
7243 | list_for_each_entry_safe(raid_device, raid_device_next, | ||
7244 | &ioc->raid_device_list, list) { | ||
7245 | if (!raid_device->responding) | ||
7246 | _scsih_sas_volume_delete(ioc, | ||
7247 | raid_device->handle); | ||
7248 | else | ||
7249 | raid_device->responding = 0; | ||
7250 | } | ||
7251 | } | ||
7252 | /* removing unresponding expanders */ | ||
7253 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", | ||
7254 | ioc->name); | ||
7255 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
7256 | INIT_LIST_HEAD(&tmp_list); | ||
7257 | list_for_each_entry_safe(sas_expander, sas_expander_next, | ||
7258 | &ioc->sas_expander_list, list) { | ||
7259 | if (!sas_expander->responding) | ||
7260 | list_move_tail(&sas_expander->list, &tmp_list); | ||
7261 | else | ||
7262 | sas_expander->responding = 0; | ||
7263 | } | ||
7264 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
7265 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, | ||
7266 | list) { | ||
7267 | list_del(&sas_expander->list); | ||
7268 | _scsih_expander_node_remove(ioc, sas_expander); | ||
7269 | } | ||
7270 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", | ||
7271 | ioc->name); | ||
7272 | /* unblock devices */ | ||
7273 | _scsih_ublock_io_all_device(ioc); | ||
7274 | } | ||
7275 | |||
7276 | static void | ||
7277 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, | ||
7278 | struct _sas_node *sas_expander, u16 handle) | ||
7279 | { | ||
7280 | Mpi2ExpanderPage1_t expander_pg1; | ||
7281 | Mpi2ConfigReply_t mpi_reply; | ||
7282 | int i; | ||
7283 | |||
7284 | for (i = 0 ; i < sas_expander->num_phys ; i++) { | ||
7285 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, | ||
7286 | &expander_pg1, i, handle))) { | ||
7287 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
7288 | ioc->name, __FILE__, __LINE__, __func__); | ||
7289 | return; | ||
7290 | } | ||
7291 | |||
7292 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, | ||
7293 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, | ||
7294 | expander_pg1.NegotiatedLinkRate >> 4); | ||
7295 | } | ||
7296 | } | ||
7297 | |||
7298 | /** | ||
7299 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset | ||
7300 | * @ioc: per adapter object | ||
7301 | * | ||
7302 | * Return nothing. | ||
7303 | */ | ||
7304 | static void | ||
7305 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) | ||
7306 | { | ||
7307 | Mpi2ExpanderPage0_t expander_pg0; | ||
7308 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
7309 | Mpi2RaidVolPage1_t volume_pg1; | ||
7310 | Mpi2RaidVolPage0_t volume_pg0; | ||
7311 | Mpi2RaidPhysDiskPage0_t pd_pg0; | ||
7312 | Mpi2EventIrConfigElement_t element; | ||
7313 | Mpi2ConfigReply_t mpi_reply; | ||
7314 | u8 phys_disk_num; | ||
7315 | u16 ioc_status; | ||
7316 | u16 handle, parent_handle; | ||
7317 | u64 sas_address; | ||
7318 | struct _sas_device *sas_device; | ||
7319 | struct _sas_node *expander_device; | ||
7320 | static struct _raid_device *raid_device; | ||
7321 | u8 retry_count; | ||
7322 | unsigned long flags; | ||
7323 | |||
7324 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); | ||
7325 | |||
7326 | _scsih_sas_host_refresh(ioc); | ||
7327 | |||
7328 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n", | ||
7329 | ioc->name); | ||
7330 | /* expanders */ | ||
7331 | handle = 0xFFFF; | ||
7332 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, | ||
7333 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { | ||
7334 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7335 | MPI2_IOCSTATUS_MASK; | ||
7336 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
7337 | printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: " | ||
7338 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7339 | ioc->name, ioc_status, | ||
7340 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
7341 | break; | ||
7342 | } | ||
7343 | handle = le16_to_cpu(expander_pg0.DevHandle); | ||
7344 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
7345 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( | ||
7346 | ioc, le64_to_cpu(expander_pg0.SASAddress)); | ||
7347 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
7348 | if (expander_device) | ||
7349 | _scsih_refresh_expander_links(ioc, expander_device, | ||
7350 | handle); | ||
7351 | else { | ||
7352 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: " | ||
7353 | "handle (0x%04x), sas_addr(0x%016llx)\n", | ||
7354 | ioc->name, handle, (unsigned long long) | ||
7355 | le64_to_cpu(expander_pg0.SASAddress)); | ||
7356 | _scsih_expander_add(ioc, handle); | ||
7357 | printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: " | ||
7358 | "handle (0x%04x), sas_addr(0x%016llx)\n", | ||
7359 | ioc->name, handle, (unsigned long long) | ||
7360 | le64_to_cpu(expander_pg0.SASAddress)); | ||
7361 | } | ||
7362 | } | ||
7363 | |||
7364 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n", | ||
7365 | ioc->name); | ||
7366 | |||
7367 | if (!ioc->ir_firmware) | ||
7368 | goto skip_to_sas; | ||
7369 | |||
7370 | printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name); | ||
7371 | /* phys disk */ | ||
7372 | phys_disk_num = 0xFF; | ||
7373 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, | ||
7374 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, | ||
7375 | phys_disk_num))) { | ||
7376 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7377 | MPI2_IOCSTATUS_MASK; | ||
7378 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
7379 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:" | ||
7380 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7381 | ioc->name, ioc_status, | ||
7382 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
7383 | break; | ||
7384 | } | ||
7385 | phys_disk_num = pd_pg0.PhysDiskNum; | ||
7386 | handle = le16_to_cpu(pd_pg0.DevHandle); | ||
7387 | sas_device = mpt2sas_get_sdev_by_handle(ioc, handle); | ||
7388 | if (sas_device) { | ||
7389 | sas_device_put(sas_device); | ||
7390 | continue; | ||
7391 | } | ||
7392 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, | ||
7393 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, | ||
7394 | handle) != 0) | ||
7395 | continue; | ||
7396 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7397 | MPI2_IOCSTATUS_MASK; | ||
7398 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
7399 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan " | ||
7400 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7401 | ioc->name, ioc_status, | ||
7402 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
7403 | break; | ||
7404 | } | ||
7405 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | ||
7406 | if (!_scsih_get_sas_address(ioc, parent_handle, | ||
7407 | &sas_address)) { | ||
7408 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: " | ||
7409 | " handle (0x%04x), sas_addr(0x%016llx)\n", | ||
7410 | ioc->name, handle, (unsigned long long) | ||
7411 | le64_to_cpu(sas_device_pg0.SASAddress)); | ||
7412 | mpt2sas_transport_update_links(ioc, sas_address, | ||
7413 | handle, sas_device_pg0.PhyNum, | ||
7414 | MPI2_SAS_NEG_LINK_RATE_1_5); | ||
7415 | set_bit(handle, ioc->pd_handles); | ||
7416 | retry_count = 0; | ||
7417 | /* This will retry adding the end device. | ||
7418 | * _scsih_add_device() will decide on retries and | ||
7419 | * return "1" when it should be retried | ||
7420 | */ | ||
7421 | while (_scsih_add_device(ioc, handle, retry_count++, | ||
7422 | 1)) { | ||
7423 | ssleep(1); | ||
7424 | } | ||
7425 | printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: " | ||
7426 | " handle (0x%04x), sas_addr(0x%016llx)\n", | ||
7427 | ioc->name, handle, (unsigned long long) | ||
7428 | le64_to_cpu(sas_device_pg0.SASAddress)); | ||
7429 | } | ||
7430 | } | ||
7431 | |||
7432 | printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n", | ||
7433 | ioc->name); | ||
7434 | |||
7435 | printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name); | ||
7436 | /* volumes */ | ||
7437 | handle = 0xFFFF; | ||
7438 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, | ||
7439 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { | ||
7440 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7441 | MPI2_IOCSTATUS_MASK; | ||
7442 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
7443 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " | ||
7444 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7445 | ioc->name, ioc_status, | ||
7446 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
7447 | break; | ||
7448 | } | ||
7449 | handle = le16_to_cpu(volume_pg1.DevHandle); | ||
7450 | spin_lock_irqsave(&ioc->raid_device_lock, flags); | ||
7451 | raid_device = _scsih_raid_device_find_by_wwid(ioc, | ||
7452 | le64_to_cpu(volume_pg1.WWID)); | ||
7453 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); | ||
7454 | if (raid_device) | ||
7455 | continue; | ||
7456 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, | ||
7457 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, | ||
7458 | sizeof(Mpi2RaidVolPage0_t))) | ||
7459 | continue; | ||
7460 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7461 | MPI2_IOCSTATUS_MASK; | ||
7462 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
7463 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " | ||
7464 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7465 | ioc->name, ioc_status, | ||
7466 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
7467 | break; | ||
7468 | } | ||
7469 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || | ||
7470 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || | ||
7471 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { | ||
7472 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); | ||
7473 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; | ||
7474 | element.VolDevHandle = volume_pg1.DevHandle; | ||
7475 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: " | ||
7476 | " handle (0x%04x)\n", ioc->name, | ||
7477 | volume_pg1.DevHandle); | ||
7478 | _scsih_sas_volume_add(ioc, &element); | ||
7479 | printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: " | ||
7480 | " handle (0x%04x)\n", ioc->name, | ||
7481 | volume_pg1.DevHandle); | ||
7482 | } | ||
7483 | } | ||
7484 | |||
7485 | printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n", | ||
7486 | ioc->name); | ||
7487 | |||
7488 | skip_to_sas: | ||
7489 | |||
7490 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n", | ||
7491 | ioc->name); | ||
7492 | /* sas devices */ | ||
7493 | handle = 0xFFFF; | ||
7494 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, | ||
7495 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, | ||
7496 | handle))) { | ||
7497 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
7498 | MPI2_IOCSTATUS_MASK; | ||
7499 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
7500 | printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:" | ||
7501 | " ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7502 | ioc->name, ioc_status, | ||
7503 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
7504 | break; | ||
7505 | } | ||
7506 | handle = le16_to_cpu(sas_device_pg0.DevHandle); | ||
7507 | if (!(_scsih_is_end_device( | ||
7508 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) | ||
7509 | continue; | ||
7510 | sas_device = mpt2sas_get_sdev_by_addr(ioc, | ||
7511 | le64_to_cpu(sas_device_pg0.SASAddress)); | ||
7512 | if (sas_device) { | ||
7513 | sas_device_put(sas_device); | ||
7514 | continue; | ||
7515 | } | ||
7516 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); | ||
7517 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { | ||
7518 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: " | ||
7519 | "handle (0x%04x), sas_addr(0x%016llx)\n", | ||
7520 | ioc->name, handle, (unsigned long long) | ||
7521 | le64_to_cpu(sas_device_pg0.SASAddress)); | ||
7522 | mpt2sas_transport_update_links(ioc, sas_address, handle, | ||
7523 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); | ||
7524 | retry_count = 0; | ||
7525 | /* This will retry adding the end device. | ||
7526 | * _scsih_add_device() will decide on retries and | ||
7527 | * return "1" when it should be retried | ||
7528 | */ | ||
7529 | while (_scsih_add_device(ioc, handle, retry_count++, | ||
7530 | 0)) { | ||
7531 | ssleep(1); | ||
7532 | } | ||
7533 | printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: " | ||
7534 | "handle (0x%04x), sas_addr(0x%016llx)\n", | ||
7535 | ioc->name, handle, (unsigned long long) | ||
7536 | le64_to_cpu(sas_device_pg0.SASAddress)); | ||
7537 | } | ||
7538 | } | ||
7539 | |||
7540 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n", | ||
7541 | ioc->name); | ||
7542 | |||
7543 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); | ||
7544 | } | ||
7545 | |||
7546 | |||
7547 | /** | ||
7548 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) | ||
7549 | * @ioc: per adapter object | ||
7550 | * @reset_phase: phase | ||
7551 | * | ||
7552 | * The handler for doing any required cleanup or initialization. | ||
7553 | * | ||
7554 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, | ||
7555 | * MPT2_IOC_DONE_RESET | ||
7556 | * | ||
7557 | * Return nothing. | ||
7558 | */ | ||
7559 | void | ||
7560 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) | ||
7561 | { | ||
7562 | switch (reset_phase) { | ||
7563 | case MPT2_IOC_PRE_RESET: | ||
7564 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
7565 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); | ||
7566 | break; | ||
7567 | case MPT2_IOC_AFTER_RESET: | ||
7568 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
7569 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); | ||
7570 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { | ||
7571 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; | ||
7572 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); | ||
7573 | complete(&ioc->scsih_cmds.done); | ||
7574 | } | ||
7575 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { | ||
7576 | ioc->tm_cmds.status |= MPT2_CMD_RESET; | ||
7577 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); | ||
7578 | complete(&ioc->tm_cmds.done); | ||
7579 | } | ||
7580 | _scsih_fw_event_cleanup_queue(ioc); | ||
7581 | _scsih_flush_running_cmds(ioc); | ||
7582 | break; | ||
7583 | case MPT2_IOC_DONE_RESET: | ||
7584 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " | ||
7585 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); | ||
7586 | _scsih_sas_host_refresh(ioc); | ||
7587 | _scsih_prep_device_scan(ioc); | ||
7588 | _scsih_search_responding_sas_devices(ioc); | ||
7589 | _scsih_search_responding_raid_devices(ioc); | ||
7590 | _scsih_search_responding_expanders(ioc); | ||
7591 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && | ||
7592 | !ioc->sas_hba.num_phys)) { | ||
7593 | _scsih_prep_device_scan(ioc); | ||
7594 | _scsih_search_responding_sas_devices(ioc); | ||
7595 | _scsih_search_responding_raid_devices(ioc); | ||
7596 | _scsih_search_responding_expanders(ioc); | ||
7597 | _scsih_error_recovery_delete_devices(ioc); | ||
7598 | } | ||
7599 | break; | ||
7600 | } | ||
7601 | } | ||
7602 | |||
7603 | /** | ||
7604 | * _firmware_event_work - delayed task for processing firmware events | ||
7605 | * @ioc: per adapter object | ||
7606 | * @work: equal to the fw_event_work object | ||
7607 | * Context: user. | ||
7608 | * | ||
7609 | * Return nothing. | ||
7610 | */ | ||
7611 | static void | ||
7612 | _firmware_event_work(struct work_struct *work) | ||
7613 | { | ||
7614 | struct fw_event_work *fw_event = container_of(work, | ||
7615 | struct fw_event_work, delayed_work.work); | ||
7616 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; | ||
7617 | |||
7618 | _scsih_fw_event_del_from_list(ioc, fw_event); | ||
7619 | |||
7620 | /* the queue is being flushed so ignore this event */ | ||
7621 | if (ioc->remove_host || ioc->pci_error_recovery) { | ||
7622 | fw_event_work_put(fw_event); | ||
7623 | return; | ||
7624 | } | ||
7625 | |||
7626 | switch (fw_event->event) { | ||
7627 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: | ||
7628 | while (scsi_host_in_recovery(ioc->shost) || | ||
7629 | ioc->shost_recovery) { | ||
7630 | /* | ||
7631 | * If we're unloading, bail. Otherwise, this can become | ||
7632 | * an infinite loop. | ||
7633 | */ | ||
7634 | if (ioc->remove_host) | ||
7635 | goto out; | ||
7636 | |||
7637 | ssleep(1); | ||
7638 | } | ||
7639 | _scsih_remove_unresponding_sas_devices(ioc); | ||
7640 | _scsih_scan_for_devices_after_reset(ioc); | ||
7641 | break; | ||
7642 | case MPT2SAS_PORT_ENABLE_COMPLETE: | ||
7643 | ioc->start_scan = 0; | ||
7644 | |||
7645 | if (missing_delay[0] != -1 && missing_delay[1] != -1) | ||
7646 | mpt2sas_base_update_missing_delay(ioc, missing_delay[0], | ||
7647 | missing_delay[1]); | ||
7648 | |||
7649 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " | ||
7650 | "from worker thread\n", ioc->name)); | ||
7651 | break; | ||
7652 | case MPT2SAS_TURN_ON_PFA_LED: | ||
7653 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); | ||
7654 | break; | ||
7655 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | ||
7656 | _scsih_sas_topology_change_event(ioc, fw_event); | ||
7657 | break; | ||
7658 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | ||
7659 | _scsih_sas_device_status_change_event(ioc, | ||
7660 | fw_event); | ||
7661 | break; | ||
7662 | case MPI2_EVENT_SAS_DISCOVERY: | ||
7663 | _scsih_sas_discovery_event(ioc, | ||
7664 | fw_event); | ||
7665 | break; | ||
7666 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | ||
7667 | _scsih_sas_broadcast_primitive_event(ioc, | ||
7668 | fw_event); | ||
7669 | break; | ||
7670 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | ||
7671 | _scsih_sas_enclosure_dev_status_change_event(ioc, | ||
7672 | fw_event); | ||
7673 | break; | ||
7674 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | ||
7675 | _scsih_sas_ir_config_change_event(ioc, fw_event); | ||
7676 | break; | ||
7677 | case MPI2_EVENT_IR_VOLUME: | ||
7678 | _scsih_sas_ir_volume_event(ioc, fw_event); | ||
7679 | break; | ||
7680 | case MPI2_EVENT_IR_PHYSICAL_DISK: | ||
7681 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); | ||
7682 | break; | ||
7683 | case MPI2_EVENT_IR_OPERATION_STATUS: | ||
7684 | _scsih_sas_ir_operation_status_event(ioc, fw_event); | ||
7685 | break; | ||
7686 | } | ||
7687 | out: | ||
7688 | fw_event_work_put(fw_event); | ||
7689 | } | ||
7690 | |||
7691 | /** | ||
7692 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) | ||
7693 | * @ioc: per adapter object | ||
7694 | * @msix_index: MSIX table index supplied by the OS | ||
7695 | * @reply: reply message frame(lower 32bit addr) | ||
7696 | * Context: interrupt. | ||
7697 | * | ||
7698 | * This function merely adds a new work task into ioc->firmware_event_thread. | ||
7699 | * The tasks are worked from _firmware_event_work in user context. | ||
7700 | * | ||
7701 | * Returns void. | ||
7702 | */ | ||
7703 | void | ||
7704 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, | ||
7705 | u32 reply) | ||
7706 | { | ||
7707 | struct fw_event_work *fw_event; | ||
7708 | Mpi2EventNotificationReply_t *mpi_reply; | ||
7709 | u16 event; | ||
7710 | u16 sz; | ||
7711 | |||
7712 | /* events turned off due to host reset or driver unloading */ | ||
7713 | if (ioc->remove_host || ioc->pci_error_recovery) | ||
7714 | return; | ||
7715 | |||
7716 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
7717 | |||
7718 | if (unlikely(!mpi_reply)) { | ||
7719 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", | ||
7720 | ioc->name, __FILE__, __LINE__, __func__); | ||
7721 | return; | ||
7722 | } | ||
7723 | |||
7724 | event = le16_to_cpu(mpi_reply->Event); | ||
7725 | |||
7726 | switch (event) { | ||
7727 | /* handle these */ | ||
7728 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: | ||
7729 | { | ||
7730 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = | ||
7731 | (Mpi2EventDataSasBroadcastPrimitive_t *) | ||
7732 | mpi_reply->EventData; | ||
7733 | |||
7734 | if (baen_data->Primitive != | ||
7735 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) | ||
7736 | return; | ||
7737 | |||
7738 | if (ioc->broadcast_aen_busy) { | ||
7739 | ioc->broadcast_aen_pending++; | ||
7740 | return; | ||
7741 | } else | ||
7742 | ioc->broadcast_aen_busy = 1; | ||
7743 | break; | ||
7744 | } | ||
7745 | |||
7746 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: | ||
7747 | _scsih_check_topo_delete_events(ioc, | ||
7748 | (Mpi2EventDataSasTopologyChangeList_t *) | ||
7749 | mpi_reply->EventData); | ||
7750 | break; | ||
7751 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: | ||
7752 | _scsih_check_ir_config_unhide_events(ioc, | ||
7753 | (Mpi2EventDataIrConfigChangeList_t *) | ||
7754 | mpi_reply->EventData); | ||
7755 | break; | ||
7756 | case MPI2_EVENT_IR_VOLUME: | ||
7757 | _scsih_check_volume_delete_events(ioc, | ||
7758 | (Mpi2EventDataIrVolume_t *) | ||
7759 | mpi_reply->EventData); | ||
7760 | break; | ||
7761 | case MPI2_EVENT_LOG_ENTRY_ADDED: | ||
7762 | { | ||
7763 | Mpi2EventDataLogEntryAdded_t *log_entry; | ||
7764 | __le32 *log_code; | ||
7765 | |||
7766 | if (!ioc->is_warpdrive) | ||
7767 | break; | ||
7768 | |||
7769 | log_entry = (Mpi2EventDataLogEntryAdded_t *) | ||
7770 | mpi_reply->EventData; | ||
7771 | log_code = (__le32 *)log_entry->LogData; | ||
7772 | |||
7773 | if (le16_to_cpu(log_entry->LogEntryQualifier) | ||
7774 | != MPT2_WARPDRIVE_LOGENTRY) | ||
7775 | break; | ||
7776 | |||
7777 | switch (le32_to_cpu(*log_code)) { | ||
7778 | case MPT2_WARPDRIVE_LC_SSDT: | ||
7779 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " | ||
7780 | "IO Throttling has occurred in the WarpDrive " | ||
7781 | "subsystem. Check WarpDrive documentation for " | ||
7782 | "additional details.\n", ioc->name); | ||
7783 | break; | ||
7784 | case MPT2_WARPDRIVE_LC_SSDLW: | ||
7785 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " | ||
7786 | "Program/Erase Cycles for the WarpDrive subsystem " | ||
7787 | "in degraded range. Check WarpDrive documentation " | ||
7788 | "for additional details.\n", ioc->name); | ||
7789 | break; | ||
7790 | case MPT2_WARPDRIVE_LC_SSDLF: | ||
7791 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " | ||
7792 | "There are no Program/Erase Cycles for the " | ||
7793 | "WarpDrive subsystem. The storage device will be " | ||
7794 | "in read-only mode. Check WarpDrive documentation " | ||
7795 | "for additional details.\n", ioc->name); | ||
7796 | break; | ||
7797 | case MPT2_WARPDRIVE_LC_BRMF: | ||
7798 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " | ||
7799 | "The Backup Rail Monitor has failed on the " | ||
7800 | "WarpDrive subsystem. Check WarpDrive " | ||
7801 | "documentation for additional details.\n", | ||
7802 | ioc->name); | ||
7803 | break; | ||
7804 | } | ||
7805 | |||
7806 | break; | ||
7807 | } | ||
7808 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: | ||
7809 | case MPI2_EVENT_IR_OPERATION_STATUS: | ||
7810 | case MPI2_EVENT_SAS_DISCOVERY: | ||
7811 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: | ||
7812 | case MPI2_EVENT_IR_PHYSICAL_DISK: | ||
7813 | break; | ||
7814 | |||
7815 | case MPI2_EVENT_TEMP_THRESHOLD: | ||
7816 | _scsih_temp_threshold_events(ioc, | ||
7817 | (Mpi2EventDataTemperature_t *) | ||
7818 | mpi_reply->EventData); | ||
7819 | break; | ||
7820 | |||
7821 | default: /* ignore the rest */ | ||
7822 | return; | ||
7823 | } | ||
7824 | |||
7825 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; | ||
7826 | fw_event = alloc_fw_event_work(sz); | ||
7827 | if (!fw_event) { | ||
7828 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
7829 | ioc->name, __FILE__, __LINE__, __func__); | ||
7830 | return; | ||
7831 | } | ||
7832 | |||
7833 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); | ||
7834 | fw_event->ioc = ioc; | ||
7835 | fw_event->VF_ID = mpi_reply->VF_ID; | ||
7836 | fw_event->VP_ID = mpi_reply->VP_ID; | ||
7837 | fw_event->event = event; | ||
7838 | _scsih_fw_event_add(ioc, fw_event); | ||
7839 | fw_event_work_put(fw_event); | ||
7840 | return; | ||
7841 | } | ||
7842 | |||
7843 | /* shost template */ | ||
7844 | static struct scsi_host_template scsih_driver_template = { | ||
7845 | .module = THIS_MODULE, | ||
7846 | .name = "Fusion MPT SAS Host", | ||
7847 | .proc_name = MPT2SAS_DRIVER_NAME, | ||
7848 | .queuecommand = _scsih_qcmd, | ||
7849 | .target_alloc = _scsih_target_alloc, | ||
7850 | .slave_alloc = _scsih_slave_alloc, | ||
7851 | .slave_configure = _scsih_slave_configure, | ||
7852 | .target_destroy = _scsih_target_destroy, | ||
7853 | .slave_destroy = _scsih_slave_destroy, | ||
7854 | .scan_finished = _scsih_scan_finished, | ||
7855 | .scan_start = _scsih_scan_start, | ||
7856 | .change_queue_depth = _scsih_change_queue_depth, | ||
7857 | .eh_abort_handler = _scsih_abort, | ||
7858 | .eh_device_reset_handler = _scsih_dev_reset, | ||
7859 | .eh_target_reset_handler = _scsih_target_reset, | ||
7860 | .eh_host_reset_handler = _scsih_host_reset, | ||
7861 | .bios_param = _scsih_bios_param, | ||
7862 | .can_queue = 1, | ||
7863 | .this_id = -1, | ||
7864 | .sg_tablesize = MPT2SAS_SG_DEPTH, | ||
7865 | .max_sectors = 32767, | ||
7866 | .cmd_per_lun = 7, | ||
7867 | .use_clustering = ENABLE_CLUSTERING, | ||
7868 | .shost_attrs = mpt2sas_host_attrs, | ||
7869 | .sdev_attrs = mpt2sas_dev_attrs, | ||
7870 | .track_queue_depth = 1, | ||
7871 | }; | ||
7872 | |||
7873 | /** | ||
7874 | * _scsih_expander_node_remove - removing expander device from list. | ||
7875 | * @ioc: per adapter object | ||
7876 | * @sas_expander: the sas_device object | ||
7877 | * Context: Calling function should acquire ioc->sas_node_lock. | ||
7878 | * | ||
7879 | * Removing object and freeing associated memory from the | ||
7880 | * ioc->sas_expander_list. | ||
7881 | * | ||
7882 | * Return nothing. | ||
7883 | */ | ||
7884 | static void | ||
7885 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, | ||
7886 | struct _sas_node *sas_expander) | ||
7887 | { | ||
7888 | struct _sas_port *mpt2sas_port, *next; | ||
7889 | |||
7890 | /* remove sibling ports attached to this expander */ | ||
7891 | list_for_each_entry_safe(mpt2sas_port, next, | ||
7892 | &sas_expander->sas_port_list, port_list) { | ||
7893 | if (ioc->shost_recovery) | ||
7894 | return; | ||
7895 | if (mpt2sas_port->remote_identify.device_type == | ||
7896 | SAS_END_DEVICE) | ||
7897 | mpt2sas_device_remove_by_sas_address(ioc, | ||
7898 | mpt2sas_port->remote_identify.sas_address); | ||
7899 | else if (mpt2sas_port->remote_identify.device_type == | ||
7900 | SAS_EDGE_EXPANDER_DEVICE || | ||
7901 | mpt2sas_port->remote_identify.device_type == | ||
7902 | SAS_FANOUT_EXPANDER_DEVICE) | ||
7903 | mpt2sas_expander_remove(ioc, | ||
7904 | mpt2sas_port->remote_identify.sas_address); | ||
7905 | } | ||
7906 | |||
7907 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, | ||
7908 | sas_expander->sas_address_parent); | ||
7909 | |||
7910 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" | ||
7911 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, | ||
7912 | sas_expander->handle, (unsigned long long) | ||
7913 | sas_expander->sas_address); | ||
7914 | |||
7915 | kfree(sas_expander->phy); | ||
7916 | kfree(sas_expander); | ||
7917 | } | ||
7918 | |||
7919 | /** | ||
7920 | * _scsih_ir_shutdown - IR shutdown notification | ||
7921 | * @ioc: per adapter object | ||
7922 | * | ||
7923 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that | ||
7924 | * the host system is shutting down. | ||
7925 | * | ||
7926 | * Return nothing. | ||
7927 | */ | ||
7928 | static void | ||
7929 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) | ||
7930 | { | ||
7931 | Mpi2RaidActionRequest_t *mpi_request; | ||
7932 | Mpi2RaidActionReply_t *mpi_reply; | ||
7933 | u16 smid; | ||
7934 | |||
7935 | /* is IR firmware build loaded ? */ | ||
7936 | if (!ioc->ir_firmware) | ||
7937 | return; | ||
7938 | |||
7939 | mutex_lock(&ioc->scsih_cmds.mutex); | ||
7940 | |||
7941 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { | ||
7942 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", | ||
7943 | ioc->name, __func__); | ||
7944 | goto out; | ||
7945 | } | ||
7946 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; | ||
7947 | |||
7948 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); | ||
7949 | if (!smid) { | ||
7950 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
7951 | ioc->name, __func__); | ||
7952 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; | ||
7953 | goto out; | ||
7954 | } | ||
7955 | |||
7956 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
7957 | ioc->scsih_cmds.smid = smid; | ||
7958 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); | ||
7959 | |||
7960 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; | ||
7961 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; | ||
7962 | |||
7963 | if (!ioc->hide_ir_msg) | ||
7964 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); | ||
7965 | init_completion(&ioc->scsih_cmds.done); | ||
7966 | mpt2sas_base_put_smid_default(ioc, smid); | ||
7967 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); | ||
7968 | |||
7969 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { | ||
7970 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
7971 | ioc->name, __func__); | ||
7972 | goto out; | ||
7973 | } | ||
7974 | |||
7975 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { | ||
7976 | mpi_reply = ioc->scsih_cmds.reply; | ||
7977 | |||
7978 | if (!ioc->hide_ir_msg) | ||
7979 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " | ||
7980 | "ioc_status(0x%04x), loginfo(0x%08x)\n", | ||
7981 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), | ||
7982 | le32_to_cpu(mpi_reply->IOCLogInfo)); | ||
7983 | } | ||
7984 | |||
7985 | out: | ||
7986 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; | ||
7987 | mutex_unlock(&ioc->scsih_cmds.mutex); | ||
7988 | } | ||
7989 | |||
7990 | /** | ||
7991 | * _scsih_shutdown - routine call during system shutdown | ||
7992 | * @pdev: PCI device struct | ||
7993 | * | ||
7994 | * Return nothing. | ||
7995 | */ | ||
7996 | static void | ||
7997 | _scsih_shutdown(struct pci_dev *pdev) | ||
7998 | { | ||
7999 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8000 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8001 | struct workqueue_struct *wq; | ||
8002 | unsigned long flags; | ||
8003 | |||
8004 | ioc->remove_host = 1; | ||
8005 | _scsih_fw_event_cleanup_queue(ioc); | ||
8006 | |||
8007 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | ||
8008 | wq = ioc->firmware_event_thread; | ||
8009 | ioc->firmware_event_thread = NULL; | ||
8010 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | ||
8011 | if (wq) | ||
8012 | destroy_workqueue(wq); | ||
8013 | |||
8014 | _scsih_ir_shutdown(ioc); | ||
8015 | mpt2sas_base_detach(ioc); | ||
8016 | } | ||
8017 | |||
8018 | /** | ||
8019 | * _scsih_remove - detach and remove add host | ||
8020 | * @pdev: PCI device struct | ||
8021 | * | ||
8022 | * Routine called when unloading the driver. | ||
8023 | * Return nothing. | ||
8024 | */ | ||
8025 | static void | ||
8026 | _scsih_remove(struct pci_dev *pdev) | ||
8027 | { | ||
8028 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8029 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8030 | struct _sas_port *mpt2sas_port, *next_port; | ||
8031 | struct _raid_device *raid_device, *next; | ||
8032 | struct MPT2SAS_TARGET *sas_target_priv_data; | ||
8033 | struct workqueue_struct *wq; | ||
8034 | unsigned long flags; | ||
8035 | |||
8036 | ioc->remove_host = 1; | ||
8037 | _scsih_fw_event_cleanup_queue(ioc); | ||
8038 | |||
8039 | spin_lock_irqsave(&ioc->fw_event_lock, flags); | ||
8040 | wq = ioc->firmware_event_thread; | ||
8041 | ioc->firmware_event_thread = NULL; | ||
8042 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); | ||
8043 | if (wq) | ||
8044 | destroy_workqueue(wq); | ||
8045 | |||
8046 | /* release all the volumes */ | ||
8047 | _scsih_ir_shutdown(ioc); | ||
8048 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, | ||
8049 | list) { | ||
8050 | if (raid_device->starget) { | ||
8051 | sas_target_priv_data = | ||
8052 | raid_device->starget->hostdata; | ||
8053 | sas_target_priv_data->deleted = 1; | ||
8054 | scsi_remove_target(&raid_device->starget->dev); | ||
8055 | } | ||
8056 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" | ||
8057 | "(0x%016llx)\n", ioc->name, raid_device->handle, | ||
8058 | (unsigned long long) raid_device->wwid); | ||
8059 | _scsih_raid_device_remove(ioc, raid_device); | ||
8060 | } | ||
8061 | |||
8062 | /* free ports attached to the sas_host */ | ||
8063 | list_for_each_entry_safe(mpt2sas_port, next_port, | ||
8064 | &ioc->sas_hba.sas_port_list, port_list) { | ||
8065 | if (mpt2sas_port->remote_identify.device_type == | ||
8066 | SAS_END_DEVICE) | ||
8067 | mpt2sas_device_remove_by_sas_address(ioc, | ||
8068 | mpt2sas_port->remote_identify.sas_address); | ||
8069 | else if (mpt2sas_port->remote_identify.device_type == | ||
8070 | SAS_EDGE_EXPANDER_DEVICE || | ||
8071 | mpt2sas_port->remote_identify.device_type == | ||
8072 | SAS_FANOUT_EXPANDER_DEVICE) | ||
8073 | mpt2sas_expander_remove(ioc, | ||
8074 | mpt2sas_port->remote_identify.sas_address); | ||
8075 | } | ||
8076 | |||
8077 | /* free phys attached to the sas_host */ | ||
8078 | if (ioc->sas_hba.num_phys) { | ||
8079 | kfree(ioc->sas_hba.phy); | ||
8080 | ioc->sas_hba.phy = NULL; | ||
8081 | ioc->sas_hba.num_phys = 0; | ||
8082 | } | ||
8083 | |||
8084 | sas_remove_host(shost); | ||
8085 | scsi_remove_host(shost); | ||
8086 | mpt2sas_base_detach(ioc); | ||
8087 | spin_lock(&gioc_lock); | ||
8088 | list_del(&ioc->list); | ||
8089 | spin_unlock(&gioc_lock); | ||
8090 | scsi_host_put(shost); | ||
8091 | } | ||
8092 | |||
8093 | /** | ||
8094 | * _scsih_probe_boot_devices - reports 1st device | ||
8095 | * @ioc: per adapter object | ||
8096 | * | ||
8097 | * If specified in bios page 2, this routine reports the 1st | ||
8098 | * device scsi-ml or sas transport for persistent boot device | ||
8099 | * purposes. Please refer to function _scsih_determine_boot_device() | ||
8100 | */ | ||
8101 | static void | ||
8102 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) | ||
8103 | { | ||
8104 | u8 is_raid; | ||
8105 | void *device; | ||
8106 | struct _sas_device *sas_device; | ||
8107 | struct _raid_device *raid_device; | ||
8108 | u16 handle; | ||
8109 | u64 sas_address_parent; | ||
8110 | u64 sas_address; | ||
8111 | unsigned long flags; | ||
8112 | int rc; | ||
8113 | |||
8114 | /* no Bios, return immediately */ | ||
8115 | if (!ioc->bios_pg3.BiosVersion) | ||
8116 | return; | ||
8117 | |||
8118 | device = NULL; | ||
8119 | is_raid = 0; | ||
8120 | if (ioc->req_boot_device.device) { | ||
8121 | device = ioc->req_boot_device.device; | ||
8122 | is_raid = ioc->req_boot_device.is_raid; | ||
8123 | } else if (ioc->req_alt_boot_device.device) { | ||
8124 | device = ioc->req_alt_boot_device.device; | ||
8125 | is_raid = ioc->req_alt_boot_device.is_raid; | ||
8126 | } else if (ioc->current_boot_device.device) { | ||
8127 | device = ioc->current_boot_device.device; | ||
8128 | is_raid = ioc->current_boot_device.is_raid; | ||
8129 | } | ||
8130 | |||
8131 | if (!device) | ||
8132 | return; | ||
8133 | |||
8134 | if (is_raid) { | ||
8135 | raid_device = device; | ||
8136 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | ||
8137 | raid_device->id, 0); | ||
8138 | if (rc) | ||
8139 | _scsih_raid_device_remove(ioc, raid_device); | ||
8140 | } else { | ||
8141 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
8142 | sas_device = device; | ||
8143 | handle = sas_device->handle; | ||
8144 | sas_address_parent = sas_device->sas_address_parent; | ||
8145 | sas_address = sas_device->sas_address; | ||
8146 | list_move_tail(&sas_device->list, &ioc->sas_device_list); | ||
8147 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
8148 | |||
8149 | if (ioc->hide_drives) | ||
8150 | return; | ||
8151 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, | ||
8152 | sas_device->sas_address_parent)) { | ||
8153 | _scsih_sas_device_remove(ioc, sas_device); | ||
8154 | } else if (!sas_device->starget) { | ||
8155 | if (!ioc->is_driver_loading) { | ||
8156 | mpt2sas_transport_port_remove(ioc, | ||
8157 | sas_address, | ||
8158 | sas_address_parent); | ||
8159 | _scsih_sas_device_remove(ioc, sas_device); | ||
8160 | } | ||
8161 | } | ||
8162 | } | ||
8163 | } | ||
8164 | |||
8165 | /** | ||
8166 | * _scsih_probe_raid - reporting raid volumes to scsi-ml | ||
8167 | * @ioc: per adapter object | ||
8168 | * | ||
8169 | * Called during initial loading of the driver. | ||
8170 | */ | ||
8171 | static void | ||
8172 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) | ||
8173 | { | ||
8174 | struct _raid_device *raid_device, *raid_next; | ||
8175 | int rc; | ||
8176 | |||
8177 | list_for_each_entry_safe(raid_device, raid_next, | ||
8178 | &ioc->raid_device_list, list) { | ||
8179 | if (raid_device->starget) | ||
8180 | continue; | ||
8181 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, | ||
8182 | raid_device->id, 0); | ||
8183 | if (rc) | ||
8184 | _scsih_raid_device_remove(ioc, raid_device); | ||
8185 | } | ||
8186 | } | ||
8187 | |||
8188 | static struct _sas_device *get_next_sas_device(struct MPT2SAS_ADAPTER *ioc) | ||
8189 | { | ||
8190 | struct _sas_device *sas_device = NULL; | ||
8191 | unsigned long flags; | ||
8192 | |||
8193 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
8194 | if (!list_empty(&ioc->sas_device_init_list)) { | ||
8195 | sas_device = list_first_entry(&ioc->sas_device_init_list, | ||
8196 | struct _sas_device, list); | ||
8197 | sas_device_get(sas_device); | ||
8198 | } | ||
8199 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
8200 | |||
8201 | return sas_device; | ||
8202 | } | ||
8203 | |||
8204 | static void sas_device_make_active(struct MPT2SAS_ADAPTER *ioc, | ||
8205 | struct _sas_device *sas_device) | ||
8206 | { | ||
8207 | unsigned long flags; | ||
8208 | |||
8209 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
8210 | |||
8211 | /* | ||
8212 | * Since we dropped the lock during the call to port_add(), we need to | ||
8213 | * be careful here that somebody else didn't move or delete this item | ||
8214 | * while we were busy with other things. | ||
8215 | * | ||
8216 | * If it was on the list, we need a put() for the reference the list | ||
8217 | * had. Either way, we need a get() for the destination list. | ||
8218 | */ | ||
8219 | if (!list_empty(&sas_device->list)) { | ||
8220 | list_del_init(&sas_device->list); | ||
8221 | sas_device_put(sas_device); | ||
8222 | } | ||
8223 | |||
8224 | sas_device_get(sas_device); | ||
8225 | list_add_tail(&sas_device->list, &ioc->sas_device_list); | ||
8226 | |||
8227 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
8228 | } | ||
8229 | |||
8230 | /** | ||
8231 | * _scsih_probe_sas - reporting sas devices to sas transport | ||
8232 | * @ioc: per adapter object | ||
8233 | * | ||
8234 | * Called during initial loading of the driver. | ||
8235 | */ | ||
8236 | static void | ||
8237 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) | ||
8238 | { | ||
8239 | struct _sas_device *sas_device; | ||
8240 | |||
8241 | if (ioc->hide_drives) | ||
8242 | return; | ||
8243 | |||
8244 | while ((sas_device = get_next_sas_device(ioc))) { | ||
8245 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, | ||
8246 | sas_device->sas_address_parent)) { | ||
8247 | _scsih_sas_device_remove(ioc, sas_device); | ||
8248 | sas_device_put(sas_device); | ||
8249 | continue; | ||
8250 | } else if (!sas_device->starget) { | ||
8251 | if (!ioc->is_driver_loading) { | ||
8252 | mpt2sas_transport_port_remove(ioc, | ||
8253 | sas_device->sas_address, | ||
8254 | sas_device->sas_address_parent); | ||
8255 | _scsih_sas_device_remove(ioc, sas_device); | ||
8256 | sas_device_put(sas_device); | ||
8257 | continue; | ||
8258 | } | ||
8259 | } | ||
8260 | |||
8261 | sas_device_make_active(ioc, sas_device); | ||
8262 | sas_device_put(sas_device); | ||
8263 | } | ||
8264 | } | ||
8265 | |||
8266 | /** | ||
8267 | * _scsih_probe_devices - probing for devices | ||
8268 | * @ioc: per adapter object | ||
8269 | * | ||
8270 | * Called during initial loading of the driver. | ||
8271 | */ | ||
8272 | static void | ||
8273 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) | ||
8274 | { | ||
8275 | u16 volume_mapping_flags; | ||
8276 | |||
8277 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) | ||
8278 | return; /* return when IOC doesn't support initiator mode */ | ||
8279 | |||
8280 | _scsih_probe_boot_devices(ioc); | ||
8281 | |||
8282 | if (ioc->ir_firmware) { | ||
8283 | volume_mapping_flags = | ||
8284 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & | ||
8285 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; | ||
8286 | if (volume_mapping_flags == | ||
8287 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { | ||
8288 | _scsih_probe_raid(ioc); | ||
8289 | _scsih_probe_sas(ioc); | ||
8290 | } else { | ||
8291 | _scsih_probe_sas(ioc); | ||
8292 | _scsih_probe_raid(ioc); | ||
8293 | } | ||
8294 | } else | ||
8295 | _scsih_probe_sas(ioc); | ||
8296 | } | ||
8297 | |||
8298 | |||
8299 | /** | ||
8300 | * _scsih_scan_start - scsi lld callback for .scan_start | ||
8301 | * @shost: SCSI host pointer | ||
8302 | * | ||
8303 | * The shost has the ability to discover targets on its own instead | ||
8304 | * of scanning the entire bus. In our implemention, we will kick off | ||
8305 | * firmware discovery. | ||
8306 | */ | ||
8307 | static void | ||
8308 | _scsih_scan_start(struct Scsi_Host *shost) | ||
8309 | { | ||
8310 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8311 | int rc; | ||
8312 | |||
8313 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) | ||
8314 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); | ||
8315 | |||
8316 | if (disable_discovery > 0) | ||
8317 | return; | ||
8318 | |||
8319 | ioc->start_scan = 1; | ||
8320 | rc = mpt2sas_port_enable(ioc); | ||
8321 | |||
8322 | if (rc != 0) | ||
8323 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); | ||
8324 | } | ||
8325 | |||
8326 | /** | ||
8327 | * _scsih_scan_finished - scsi lld callback for .scan_finished | ||
8328 | * @shost: SCSI host pointer | ||
8329 | * @time: elapsed time of the scan in jiffies | ||
8330 | * | ||
8331 | * This function will be called periodically until it returns 1 with the | ||
8332 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, | ||
8333 | * we wait for firmware discovery to complete, then return 1. | ||
8334 | */ | ||
8335 | static int | ||
8336 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) | ||
8337 | { | ||
8338 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8339 | |||
8340 | if (disable_discovery > 0) { | ||
8341 | ioc->is_driver_loading = 0; | ||
8342 | ioc->wait_for_discovery_to_complete = 0; | ||
8343 | return 1; | ||
8344 | } | ||
8345 | |||
8346 | if (time >= (300 * HZ)) { | ||
8347 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
8348 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " | ||
8349 | "(timeout=300s)\n", ioc->name); | ||
8350 | ioc->is_driver_loading = 0; | ||
8351 | return 1; | ||
8352 | } | ||
8353 | |||
8354 | if (ioc->start_scan) | ||
8355 | return 0; | ||
8356 | |||
8357 | if (ioc->start_scan_failed) { | ||
8358 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " | ||
8359 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); | ||
8360 | ioc->is_driver_loading = 0; | ||
8361 | ioc->wait_for_discovery_to_complete = 0; | ||
8362 | ioc->remove_host = 1; | ||
8363 | return 1; | ||
8364 | } | ||
8365 | |||
8366 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); | ||
8367 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; | ||
8368 | |||
8369 | if (ioc->wait_for_discovery_to_complete) { | ||
8370 | ioc->wait_for_discovery_to_complete = 0; | ||
8371 | _scsih_probe_devices(ioc); | ||
8372 | } | ||
8373 | mpt2sas_base_start_watchdog(ioc); | ||
8374 | ioc->is_driver_loading = 0; | ||
8375 | return 1; | ||
8376 | } | ||
8377 | |||
8378 | |||
8379 | /** | ||
8380 | * _scsih_probe - attach and add scsi host | ||
8381 | * @pdev: PCI device struct | ||
8382 | * @id: pci device id | ||
8383 | * | ||
8384 | * Returns 0 success, anything else error. | ||
8385 | */ | ||
8386 | static int | ||
8387 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) | ||
8388 | { | ||
8389 | struct MPT2SAS_ADAPTER *ioc; | ||
8390 | struct Scsi_Host *shost; | ||
8391 | int rv; | ||
8392 | |||
8393 | shost = scsi_host_alloc(&scsih_driver_template, | ||
8394 | sizeof(struct MPT2SAS_ADAPTER)); | ||
8395 | if (!shost) | ||
8396 | return -ENODEV; | ||
8397 | |||
8398 | /* init local params */ | ||
8399 | ioc = shost_priv(shost); | ||
8400 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); | ||
8401 | INIT_LIST_HEAD(&ioc->list); | ||
8402 | spin_lock(&gioc_lock); | ||
8403 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); | ||
8404 | spin_unlock(&gioc_lock); | ||
8405 | ioc->shost = shost; | ||
8406 | ioc->id = mpt_ids++; | ||
8407 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); | ||
8408 | ioc->pdev = pdev; | ||
8409 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { | ||
8410 | ioc->is_warpdrive = 1; | ||
8411 | ioc->hide_ir_msg = 1; | ||
8412 | } else | ||
8413 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; | ||
8414 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; | ||
8415 | ioc->tm_cb_idx = tm_cb_idx; | ||
8416 | ioc->ctl_cb_idx = ctl_cb_idx; | ||
8417 | ioc->base_cb_idx = base_cb_idx; | ||
8418 | ioc->port_enable_cb_idx = port_enable_cb_idx; | ||
8419 | ioc->transport_cb_idx = transport_cb_idx; | ||
8420 | ioc->scsih_cb_idx = scsih_cb_idx; | ||
8421 | ioc->config_cb_idx = config_cb_idx; | ||
8422 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; | ||
8423 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; | ||
8424 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; | ||
8425 | ioc->logging_level = logging_level; | ||
8426 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; | ||
8427 | /* misc semaphores and spin locks */ | ||
8428 | mutex_init(&ioc->reset_in_progress_mutex); | ||
8429 | /* initializing pci_access_mutex lock */ | ||
8430 | mutex_init(&ioc->pci_access_mutex); | ||
8431 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); | ||
8432 | spin_lock_init(&ioc->scsi_lookup_lock); | ||
8433 | spin_lock_init(&ioc->sas_device_lock); | ||
8434 | spin_lock_init(&ioc->sas_node_lock); | ||
8435 | spin_lock_init(&ioc->fw_event_lock); | ||
8436 | spin_lock_init(&ioc->raid_device_lock); | ||
8437 | |||
8438 | INIT_LIST_HEAD(&ioc->sas_device_list); | ||
8439 | INIT_LIST_HEAD(&ioc->sas_device_init_list); | ||
8440 | INIT_LIST_HEAD(&ioc->sas_expander_list); | ||
8441 | INIT_LIST_HEAD(&ioc->fw_event_list); | ||
8442 | INIT_LIST_HEAD(&ioc->raid_device_list); | ||
8443 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); | ||
8444 | INIT_LIST_HEAD(&ioc->delayed_tr_list); | ||
8445 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); | ||
8446 | INIT_LIST_HEAD(&ioc->reply_queue_list); | ||
8447 | |||
8448 | /* init shost parameters */ | ||
8449 | shost->max_cmd_len = 32; | ||
8450 | shost->max_lun = max_lun; | ||
8451 | shost->transportt = mpt2sas_transport_template; | ||
8452 | shost->unique_id = ioc->id; | ||
8453 | |||
8454 | if (max_sectors != 0xFFFF) { | ||
8455 | if (max_sectors < 64) { | ||
8456 | shost->max_sectors = 64; | ||
8457 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " | ||
8458 | "for max_sectors, range is 64 to 32767. Assigning " | ||
8459 | "value of 64.\n", ioc->name, max_sectors); | ||
8460 | } else if (max_sectors > 32767) { | ||
8461 | shost->max_sectors = 32767; | ||
8462 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " | ||
8463 | "for max_sectors, range is 64 to 8192. Assigning " | ||
8464 | "default value of 32767.\n", ioc->name, | ||
8465 | max_sectors); | ||
8466 | } else { | ||
8467 | shost->max_sectors = max_sectors & 0xFFFE; | ||
8468 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " | ||
8469 | "set to %d\n", ioc->name, shost->max_sectors); | ||
8470 | } | ||
8471 | } | ||
8472 | |||
8473 | /* register EEDP capabilities with SCSI layer */ | ||
8474 | if (prot_mask) | ||
8475 | scsi_host_set_prot(shost, prot_mask); | ||
8476 | else | ||
8477 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION | ||
8478 | | SHOST_DIF_TYPE2_PROTECTION | ||
8479 | | SHOST_DIF_TYPE3_PROTECTION); | ||
8480 | |||
8481 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); | ||
8482 | |||
8483 | /* event thread */ | ||
8484 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), | ||
8485 | "fw_event%d", ioc->id); | ||
8486 | ioc->firmware_event_thread = create_singlethread_workqueue( | ||
8487 | ioc->firmware_event_name); | ||
8488 | if (!ioc->firmware_event_thread) { | ||
8489 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
8490 | ioc->name, __FILE__, __LINE__, __func__); | ||
8491 | rv = -ENODEV; | ||
8492 | goto out_thread_fail; | ||
8493 | } | ||
8494 | |||
8495 | ioc->is_driver_loading = 1; | ||
8496 | if ((mpt2sas_base_attach(ioc))) { | ||
8497 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
8498 | ioc->name, __FILE__, __LINE__, __func__); | ||
8499 | rv = -ENODEV; | ||
8500 | goto out_attach_fail; | ||
8501 | } | ||
8502 | |||
8503 | if (ioc->is_warpdrive) { | ||
8504 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) | ||
8505 | ioc->hide_drives = 0; | ||
8506 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) | ||
8507 | ioc->hide_drives = 1; | ||
8508 | else { | ||
8509 | if (_scsih_get_num_volumes(ioc)) | ||
8510 | ioc->hide_drives = 1; | ||
8511 | else | ||
8512 | ioc->hide_drives = 0; | ||
8513 | } | ||
8514 | } else | ||
8515 | ioc->hide_drives = 0; | ||
8516 | |||
8517 | rv = scsi_add_host(shost, &pdev->dev); | ||
8518 | if (rv) { | ||
8519 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
8520 | ioc->name, __FILE__, __LINE__, __func__); | ||
8521 | goto out_add_shost_fail; | ||
8522 | } | ||
8523 | |||
8524 | scsi_scan_host(shost); | ||
8525 | |||
8526 | return 0; | ||
8527 | |||
8528 | out_add_shost_fail: | ||
8529 | mpt2sas_base_detach(ioc); | ||
8530 | out_attach_fail: | ||
8531 | destroy_workqueue(ioc->firmware_event_thread); | ||
8532 | out_thread_fail: | ||
8533 | spin_lock(&gioc_lock); | ||
8534 | list_del(&ioc->list); | ||
8535 | spin_unlock(&gioc_lock); | ||
8536 | scsi_host_put(shost); | ||
8537 | return rv; | ||
8538 | } | ||
8539 | |||
8540 | #ifdef CONFIG_PM | ||
8541 | /** | ||
8542 | * _scsih_suspend - power management suspend main entry point | ||
8543 | * @pdev: PCI device struct | ||
8544 | * @state: PM state change to (usually PCI_D3) | ||
8545 | * | ||
8546 | * Returns 0 success, anything else error. | ||
8547 | */ | ||
8548 | static int | ||
8549 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) | ||
8550 | { | ||
8551 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8552 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8553 | pci_power_t device_state; | ||
8554 | |||
8555 | mpt2sas_base_stop_watchdog(ioc); | ||
8556 | scsi_block_requests(shost); | ||
8557 | _scsih_ir_shutdown(ioc); | ||
8558 | device_state = pci_choose_state(pdev, state); | ||
8559 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " | ||
8560 | "operating state [D%d]\n", ioc->name, pdev, | ||
8561 | pci_name(pdev), device_state); | ||
8562 | |||
8563 | mpt2sas_base_free_resources(ioc); | ||
8564 | pci_save_state(pdev); | ||
8565 | pci_set_power_state(pdev, device_state); | ||
8566 | return 0; | ||
8567 | } | ||
8568 | |||
8569 | /** | ||
8570 | * _scsih_resume - power management resume main entry point | ||
8571 | * @pdev: PCI device struct | ||
8572 | * | ||
8573 | * Returns 0 success, anything else error. | ||
8574 | */ | ||
8575 | static int | ||
8576 | _scsih_resume(struct pci_dev *pdev) | ||
8577 | { | ||
8578 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8579 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8580 | pci_power_t device_state = pdev->current_state; | ||
8581 | int r; | ||
8582 | |||
8583 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " | ||
8584 | "operating state [D%d]\n", ioc->name, pdev, | ||
8585 | pci_name(pdev), device_state); | ||
8586 | |||
8587 | pci_set_power_state(pdev, PCI_D0); | ||
8588 | pci_enable_wake(pdev, PCI_D0, 0); | ||
8589 | pci_restore_state(pdev); | ||
8590 | ioc->pdev = pdev; | ||
8591 | r = mpt2sas_base_map_resources(ioc); | ||
8592 | if (r) | ||
8593 | return r; | ||
8594 | |||
8595 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); | ||
8596 | scsi_unblock_requests(shost); | ||
8597 | mpt2sas_base_start_watchdog(ioc); | ||
8598 | return 0; | ||
8599 | } | ||
8600 | #endif /* CONFIG_PM */ | ||
8601 | |||
8602 | /** | ||
8603 | * _scsih_pci_error_detected - Called when a PCI error is detected. | ||
8604 | * @pdev: PCI device struct | ||
8605 | * @state: PCI channel state | ||
8606 | * | ||
8607 | * Description: Called when a PCI error is detected. | ||
8608 | * | ||
8609 | * Return value: | ||
8610 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT | ||
8611 | */ | ||
8612 | static pci_ers_result_t | ||
8613 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | ||
8614 | { | ||
8615 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8616 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8617 | |||
8618 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", | ||
8619 | ioc->name, state); | ||
8620 | |||
8621 | switch (state) { | ||
8622 | case pci_channel_io_normal: | ||
8623 | return PCI_ERS_RESULT_CAN_RECOVER; | ||
8624 | case pci_channel_io_frozen: | ||
8625 | /* Fatal error, prepare for slot reset */ | ||
8626 | ioc->pci_error_recovery = 1; | ||
8627 | scsi_block_requests(ioc->shost); | ||
8628 | mpt2sas_base_stop_watchdog(ioc); | ||
8629 | mpt2sas_base_free_resources(ioc); | ||
8630 | return PCI_ERS_RESULT_NEED_RESET; | ||
8631 | case pci_channel_io_perm_failure: | ||
8632 | /* Permanent error, prepare for device removal */ | ||
8633 | ioc->pci_error_recovery = 1; | ||
8634 | mpt2sas_base_stop_watchdog(ioc); | ||
8635 | _scsih_flush_running_cmds(ioc); | ||
8636 | return PCI_ERS_RESULT_DISCONNECT; | ||
8637 | } | ||
8638 | return PCI_ERS_RESULT_NEED_RESET; | ||
8639 | } | ||
8640 | |||
8641 | /** | ||
8642 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. | ||
8643 | * @pdev: PCI device struct | ||
8644 | * | ||
8645 | * Description: This routine is called by the pci error recovery | ||
8646 | * code after the PCI slot has been reset, just before we | ||
8647 | * should resume normal operations. | ||
8648 | */ | ||
8649 | static pci_ers_result_t | ||
8650 | _scsih_pci_slot_reset(struct pci_dev *pdev) | ||
8651 | { | ||
8652 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8653 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8654 | int rc; | ||
8655 | |||
8656 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", | ||
8657 | ioc->name); | ||
8658 | |||
8659 | ioc->pci_error_recovery = 0; | ||
8660 | ioc->pdev = pdev; | ||
8661 | pci_restore_state(pdev); | ||
8662 | rc = mpt2sas_base_map_resources(ioc); | ||
8663 | if (rc) | ||
8664 | return PCI_ERS_RESULT_DISCONNECT; | ||
8665 | |||
8666 | |||
8667 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
8668 | FORCE_BIG_HAMMER); | ||
8669 | |||
8670 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, | ||
8671 | (rc == 0) ? "success" : "failed"); | ||
8672 | |||
8673 | if (!rc) | ||
8674 | return PCI_ERS_RESULT_RECOVERED; | ||
8675 | else | ||
8676 | return PCI_ERS_RESULT_DISCONNECT; | ||
8677 | } | ||
8678 | |||
8679 | /** | ||
8680 | * _scsih_pci_resume() - resume normal ops after PCI reset | ||
8681 | * @pdev: pointer to PCI device | ||
8682 | * | ||
8683 | * Called when the error recovery driver tells us that its | ||
8684 | * OK to resume normal operation. Use completion to allow | ||
8685 | * halted scsi ops to resume. | ||
8686 | */ | ||
8687 | static void | ||
8688 | _scsih_pci_resume(struct pci_dev *pdev) | ||
8689 | { | ||
8690 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8691 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8692 | |||
8693 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); | ||
8694 | |||
8695 | pci_cleanup_aer_uncorrect_error_status(pdev); | ||
8696 | mpt2sas_base_start_watchdog(ioc); | ||
8697 | scsi_unblock_requests(ioc->shost); | ||
8698 | } | ||
8699 | |||
8700 | /** | ||
8701 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers | ||
8702 | * @pdev: pointer to PCI device | ||
8703 | */ | ||
8704 | static pci_ers_result_t | ||
8705 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) | ||
8706 | { | ||
8707 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
8708 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
8709 | |||
8710 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", | ||
8711 | ioc->name); | ||
8712 | |||
8713 | /* TODO - dump whatever for debugging purposes */ | ||
8714 | |||
8715 | /* Request a slot reset. */ | ||
8716 | return PCI_ERS_RESULT_NEED_RESET; | ||
8717 | } | ||
8718 | |||
8719 | static const struct pci_error_handlers _scsih_err_handler = { | ||
8720 | .error_detected = _scsih_pci_error_detected, | ||
8721 | .mmio_enabled = _scsih_pci_mmio_enabled, | ||
8722 | .slot_reset = _scsih_pci_slot_reset, | ||
8723 | .resume = _scsih_pci_resume, | ||
8724 | }; | ||
8725 | |||
8726 | static struct pci_driver scsih_driver = { | ||
8727 | .name = MPT2SAS_DRIVER_NAME, | ||
8728 | .id_table = scsih_pci_table, | ||
8729 | .probe = _scsih_probe, | ||
8730 | .remove = _scsih_remove, | ||
8731 | .shutdown = _scsih_shutdown, | ||
8732 | .err_handler = &_scsih_err_handler, | ||
8733 | #ifdef CONFIG_PM | ||
8734 | .suspend = _scsih_suspend, | ||
8735 | .resume = _scsih_resume, | ||
8736 | #endif | ||
8737 | }; | ||
8738 | |||
8739 | /* raid transport support */ | ||
8740 | static struct raid_function_template mpt2sas_raid_functions = { | ||
8741 | .cookie = &scsih_driver_template, | ||
8742 | .is_raid = _scsih_is_raid, | ||
8743 | .get_resync = _scsih_get_resync, | ||
8744 | .get_state = _scsih_get_state, | ||
8745 | }; | ||
8746 | |||
8747 | /** | ||
8748 | * _scsih_init - main entry point for this driver. | ||
8749 | * | ||
8750 | * Returns 0 success, anything else error. | ||
8751 | */ | ||
8752 | static int __init | ||
8753 | _scsih_init(void) | ||
8754 | { | ||
8755 | int error; | ||
8756 | |||
8757 | mpt_ids = 0; | ||
8758 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, | ||
8759 | MPT2SAS_DRIVER_VERSION); | ||
8760 | |||
8761 | mpt2sas_transport_template = | ||
8762 | sas_attach_transport(&mpt2sas_transport_functions); | ||
8763 | if (!mpt2sas_transport_template) | ||
8764 | return -ENODEV; | ||
8765 | /* raid transport support */ | ||
8766 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); | ||
8767 | if (!mpt2sas_raid_template) { | ||
8768 | sas_release_transport(mpt2sas_transport_template); | ||
8769 | return -ENODEV; | ||
8770 | } | ||
8771 | |||
8772 | mpt2sas_base_initialize_callback_handler(); | ||
8773 | |||
8774 | /* queuecommand callback hander */ | ||
8775 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); | ||
8776 | |||
8777 | /* task management callback handler */ | ||
8778 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); | ||
8779 | |||
8780 | /* base internal commands callback handler */ | ||
8781 | base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); | ||
8782 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( | ||
8783 | mpt2sas_port_enable_done); | ||
8784 | |||
8785 | /* transport internal commands callback handler */ | ||
8786 | transport_cb_idx = mpt2sas_base_register_callback_handler( | ||
8787 | mpt2sas_transport_done); | ||
8788 | |||
8789 | /* scsih internal commands callback handler */ | ||
8790 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); | ||
8791 | |||
8792 | /* configuration page API internal commands callback handler */ | ||
8793 | config_cb_idx = mpt2sas_base_register_callback_handler( | ||
8794 | mpt2sas_config_done); | ||
8795 | |||
8796 | /* ctl module callback handler */ | ||
8797 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); | ||
8798 | |||
8799 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( | ||
8800 | _scsih_tm_tr_complete); | ||
8801 | |||
8802 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( | ||
8803 | _scsih_tm_volume_tr_complete); | ||
8804 | |||
8805 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( | ||
8806 | _scsih_sas_control_complete); | ||
8807 | |||
8808 | mpt2sas_ctl_init(); | ||
8809 | |||
8810 | error = pci_register_driver(&scsih_driver); | ||
8811 | if (error) { | ||
8812 | /* raid transport support */ | ||
8813 | raid_class_release(mpt2sas_raid_template); | ||
8814 | sas_release_transport(mpt2sas_transport_template); | ||
8815 | } | ||
8816 | |||
8817 | return error; | ||
8818 | } | ||
8819 | |||
8820 | /** | ||
8821 | * _scsih_exit - exit point for this driver (when it is a module). | ||
8822 | * | ||
8823 | * Returns 0 success, anything else error. | ||
8824 | */ | ||
8825 | static void __exit | ||
8826 | _scsih_exit(void) | ||
8827 | { | ||
8828 | printk(KERN_INFO "mpt2sas version %s unloading\n", | ||
8829 | MPT2SAS_DRIVER_VERSION); | ||
8830 | |||
8831 | pci_unregister_driver(&scsih_driver); | ||
8832 | |||
8833 | mpt2sas_ctl_exit(); | ||
8834 | |||
8835 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); | ||
8836 | mpt2sas_base_release_callback_handler(tm_cb_idx); | ||
8837 | mpt2sas_base_release_callback_handler(base_cb_idx); | ||
8838 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); | ||
8839 | mpt2sas_base_release_callback_handler(transport_cb_idx); | ||
8840 | mpt2sas_base_release_callback_handler(scsih_cb_idx); | ||
8841 | mpt2sas_base_release_callback_handler(config_cb_idx); | ||
8842 | mpt2sas_base_release_callback_handler(ctl_cb_idx); | ||
8843 | |||
8844 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); | ||
8845 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); | ||
8846 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); | ||
8847 | |||
8848 | /* raid transport support */ | ||
8849 | raid_class_release(mpt2sas_raid_template); | ||
8850 | sas_release_transport(mpt2sas_transport_template); | ||
8851 | |||
8852 | } | ||
8853 | |||
8854 | module_init(_scsih_init); | ||
8855 | module_exit(_scsih_exit); | ||
diff --git a/drivers/scsi/mpt2sas/mpt2sas_transport.c b/drivers/scsi/mpt2sas/mpt2sas_transport.c deleted file mode 100644 index af868009395d..000000000000 --- a/drivers/scsi/mpt2sas/mpt2sas_transport.c +++ /dev/null | |||
@@ -1,2173 +0,0 @@ | |||
1 | /* | ||
2 | * SAS Transport Layer for MPT (Message Passing Technology) based controllers | ||
3 | * | ||
4 | * This code is based on drivers/scsi/mpt2sas/mpt2_transport.c | ||
5 | * Copyright (C) 2007-2014 LSI Corporation | ||
6 | * Copyright (C) 20013-2014 Avago Technologies | ||
7 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version 2 | ||
12 | * of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * NO WARRANTY | ||
20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT | ||
22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, | ||
23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is | ||
24 | * solely responsible for determining the appropriateness of using and | ||
25 | * distributing the Program and assumes all risks associated with its | ||
26 | * exercise of rights under this Agreement, including but not limited to | ||
27 | * the risks and costs of program errors, damage to or loss of data, | ||
28 | * programs or equipment, and unavailability or interruption of operations. | ||
29 | |||
30 | * DISCLAIMER OF LIABILITY | ||
31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY | ||
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND | ||
34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | ||
37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES | ||
38 | |||
39 | * You should have received a copy of the GNU General Public License | ||
40 | * along with this program; if not, write to the Free Software | ||
41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
42 | * USA. | ||
43 | */ | ||
44 | |||
45 | #include <linux/module.h> | ||
46 | #include <linux/kernel.h> | ||
47 | #include <linux/init.h> | ||
48 | #include <linux/errno.h> | ||
49 | #include <linux/sched.h> | ||
50 | #include <linux/workqueue.h> | ||
51 | #include <linux/delay.h> | ||
52 | #include <linux/pci.h> | ||
53 | #include <linux/slab.h> | ||
54 | |||
55 | #include <scsi/scsi.h> | ||
56 | #include <scsi/scsi_cmnd.h> | ||
57 | #include <scsi/scsi_device.h> | ||
58 | #include <scsi/scsi_host.h> | ||
59 | #include <scsi/scsi_transport_sas.h> | ||
60 | #include <scsi/scsi_dbg.h> | ||
61 | |||
62 | #include "mpt2sas_base.h" | ||
63 | /** | ||
64 | * _transport_sas_node_find_by_sas_address - sas node search | ||
65 | * @ioc: per adapter object | ||
66 | * @sas_address: sas address of expander or sas host | ||
67 | * Context: Calling function should acquire ioc->sas_node_lock. | ||
68 | * | ||
69 | * Search for either hba phys or expander device based on handle, then returns | ||
70 | * the sas_node object. | ||
71 | */ | ||
72 | static struct _sas_node * | ||
73 | _transport_sas_node_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, | ||
74 | u64 sas_address) | ||
75 | { | ||
76 | if (ioc->sas_hba.sas_address == sas_address) | ||
77 | return &ioc->sas_hba; | ||
78 | else | ||
79 | return mpt2sas_scsih_expander_find_by_sas_address(ioc, | ||
80 | sas_address); | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * _transport_convert_phy_link_rate - | ||
85 | * @link_rate: link rate returned from mpt firmware | ||
86 | * | ||
87 | * Convert link_rate from mpi fusion into sas_transport form. | ||
88 | */ | ||
89 | static enum sas_linkrate | ||
90 | _transport_convert_phy_link_rate(u8 link_rate) | ||
91 | { | ||
92 | enum sas_linkrate rc; | ||
93 | |||
94 | switch (link_rate) { | ||
95 | case MPI2_SAS_NEG_LINK_RATE_1_5: | ||
96 | rc = SAS_LINK_RATE_1_5_GBPS; | ||
97 | break; | ||
98 | case MPI2_SAS_NEG_LINK_RATE_3_0: | ||
99 | rc = SAS_LINK_RATE_3_0_GBPS; | ||
100 | break; | ||
101 | case MPI2_SAS_NEG_LINK_RATE_6_0: | ||
102 | rc = SAS_LINK_RATE_6_0_GBPS; | ||
103 | break; | ||
104 | case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED: | ||
105 | rc = SAS_PHY_DISABLED; | ||
106 | break; | ||
107 | case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED: | ||
108 | rc = SAS_LINK_RATE_FAILED; | ||
109 | break; | ||
110 | case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR: | ||
111 | rc = SAS_SATA_PORT_SELECTOR; | ||
112 | break; | ||
113 | case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS: | ||
114 | rc = SAS_PHY_RESET_IN_PROGRESS; | ||
115 | break; | ||
116 | default: | ||
117 | case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE: | ||
118 | case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE: | ||
119 | rc = SAS_LINK_RATE_UNKNOWN; | ||
120 | break; | ||
121 | } | ||
122 | return rc; | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * _transport_set_identify - set identify for phys and end devices | ||
127 | * @ioc: per adapter object | ||
128 | * @handle: device handle | ||
129 | * @identify: sas identify info | ||
130 | * | ||
131 | * Populates sas identify info. | ||
132 | * | ||
133 | * Returns 0 for success, non-zero for failure. | ||
134 | */ | ||
135 | static int | ||
136 | _transport_set_identify(struct MPT2SAS_ADAPTER *ioc, u16 handle, | ||
137 | struct sas_identify *identify) | ||
138 | { | ||
139 | Mpi2SasDevicePage0_t sas_device_pg0; | ||
140 | Mpi2ConfigReply_t mpi_reply; | ||
141 | u32 device_info; | ||
142 | u32 ioc_status; | ||
143 | |||
144 | if (ioc->shost_recovery || ioc->pci_error_recovery) { | ||
145 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", | ||
146 | __func__, ioc->name); | ||
147 | return -EFAULT; | ||
148 | } | ||
149 | |||
150 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, | ||
151 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { | ||
152 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
153 | |||
154 | ioc->name, __FILE__, __LINE__, __func__); | ||
155 | return -ENXIO; | ||
156 | } | ||
157 | |||
158 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
159 | MPI2_IOCSTATUS_MASK; | ||
160 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
161 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)" | ||
162 | "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, | ||
163 | __FILE__, __LINE__, __func__); | ||
164 | return -EIO; | ||
165 | } | ||
166 | |||
167 | memset(identify, 0, sizeof(struct sas_identify)); | ||
168 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); | ||
169 | |||
170 | /* sas_address */ | ||
171 | identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress); | ||
172 | |||
173 | /* phy number of the parent device this device is linked to */ | ||
174 | identify->phy_identifier = sas_device_pg0.PhyNum; | ||
175 | |||
176 | /* device_type */ | ||
177 | switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { | ||
178 | case MPI2_SAS_DEVICE_INFO_NO_DEVICE: | ||
179 | identify->device_type = SAS_PHY_UNUSED; | ||
180 | break; | ||
181 | case MPI2_SAS_DEVICE_INFO_END_DEVICE: | ||
182 | identify->device_type = SAS_END_DEVICE; | ||
183 | break; | ||
184 | case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER: | ||
185 | identify->device_type = SAS_EDGE_EXPANDER_DEVICE; | ||
186 | break; | ||
187 | case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER: | ||
188 | identify->device_type = SAS_FANOUT_EXPANDER_DEVICE; | ||
189 | break; | ||
190 | } | ||
191 | |||
192 | /* initiator_port_protocols */ | ||
193 | if (device_info & MPI2_SAS_DEVICE_INFO_SSP_INITIATOR) | ||
194 | identify->initiator_port_protocols |= SAS_PROTOCOL_SSP; | ||
195 | if (device_info & MPI2_SAS_DEVICE_INFO_STP_INITIATOR) | ||
196 | identify->initiator_port_protocols |= SAS_PROTOCOL_STP; | ||
197 | if (device_info & MPI2_SAS_DEVICE_INFO_SMP_INITIATOR) | ||
198 | identify->initiator_port_protocols |= SAS_PROTOCOL_SMP; | ||
199 | if (device_info & MPI2_SAS_DEVICE_INFO_SATA_HOST) | ||
200 | identify->initiator_port_protocols |= SAS_PROTOCOL_SATA; | ||
201 | |||
202 | /* target_port_protocols */ | ||
203 | if (device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | ||
204 | identify->target_port_protocols |= SAS_PROTOCOL_SSP; | ||
205 | if (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | ||
206 | identify->target_port_protocols |= SAS_PROTOCOL_STP; | ||
207 | if (device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET) | ||
208 | identify->target_port_protocols |= SAS_PROTOCOL_SMP; | ||
209 | if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) | ||
210 | identify->target_port_protocols |= SAS_PROTOCOL_SATA; | ||
211 | |||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * mpt2sas_transport_done - internal transport layer callback handler. | ||
217 | * @ioc: per adapter object | ||
218 | * @smid: system request message index | ||
219 | * @msix_index: MSIX table index supplied by the OS | ||
220 | * @reply: reply message frame(lower 32bit addr) | ||
221 | * | ||
222 | * Callback handler when sending internal generated transport cmds. | ||
223 | * The callback index passed is `ioc->transport_cb_idx` | ||
224 | * | ||
225 | * Return 1 meaning mf should be freed from _base_interrupt | ||
226 | * 0 means the mf is freed from this function. | ||
227 | */ | ||
228 | u8 | ||
229 | mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, | ||
230 | u32 reply) | ||
231 | { | ||
232 | MPI2DefaultReply_t *mpi_reply; | ||
233 | |||
234 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); | ||
235 | if (ioc->transport_cmds.status == MPT2_CMD_NOT_USED) | ||
236 | return 1; | ||
237 | if (ioc->transport_cmds.smid != smid) | ||
238 | return 1; | ||
239 | ioc->transport_cmds.status |= MPT2_CMD_COMPLETE; | ||
240 | if (mpi_reply) { | ||
241 | memcpy(ioc->transport_cmds.reply, mpi_reply, | ||
242 | mpi_reply->MsgLength*4); | ||
243 | ioc->transport_cmds.status |= MPT2_CMD_REPLY_VALID; | ||
244 | } | ||
245 | ioc->transport_cmds.status &= ~MPT2_CMD_PENDING; | ||
246 | complete(&ioc->transport_cmds.done); | ||
247 | return 1; | ||
248 | } | ||
249 | |||
250 | /* report manufacture request structure */ | ||
251 | struct rep_manu_request{ | ||
252 | u8 smp_frame_type; | ||
253 | u8 function; | ||
254 | u8 reserved; | ||
255 | u8 request_length; | ||
256 | }; | ||
257 | |||
258 | /* report manufacture reply structure */ | ||
259 | struct rep_manu_reply{ | ||
260 | u8 smp_frame_type; /* 0x41 */ | ||
261 | u8 function; /* 0x01 */ | ||
262 | u8 function_result; | ||
263 | u8 response_length; | ||
264 | u16 expander_change_count; | ||
265 | u8 reserved0[2]; | ||
266 | u8 sas_format; | ||
267 | u8 reserved2[3]; | ||
268 | u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN]; | ||
269 | u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN]; | ||
270 | u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN]; | ||
271 | u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN]; | ||
272 | u16 component_id; | ||
273 | u8 component_revision_id; | ||
274 | u8 reserved3; | ||
275 | u8 vendor_specific[8]; | ||
276 | }; | ||
277 | |||
278 | /** | ||
279 | * _transport_expander_report_manufacture - obtain SMP report_manufacture | ||
280 | * @ioc: per adapter object | ||
281 | * @sas_address: expander sas address | ||
282 | * @edev: the sas_expander_device object | ||
283 | * | ||
284 | * Fills in the sas_expander_device object when SMP port is created. | ||
285 | * | ||
286 | * Returns 0 for success, non-zero for failure. | ||
287 | */ | ||
288 | static int | ||
289 | _transport_expander_report_manufacture(struct MPT2SAS_ADAPTER *ioc, | ||
290 | u64 sas_address, struct sas_expander_device *edev) | ||
291 | { | ||
292 | Mpi2SmpPassthroughRequest_t *mpi_request; | ||
293 | Mpi2SmpPassthroughReply_t *mpi_reply; | ||
294 | struct rep_manu_reply *manufacture_reply; | ||
295 | struct rep_manu_request *manufacture_request; | ||
296 | int rc; | ||
297 | u16 smid; | ||
298 | u32 ioc_state; | ||
299 | unsigned long timeleft; | ||
300 | void *psge; | ||
301 | u32 sgl_flags; | ||
302 | u8 issue_reset = 0; | ||
303 | void *data_out = NULL; | ||
304 | dma_addr_t data_out_dma; | ||
305 | u32 sz; | ||
306 | u16 wait_state_count; | ||
307 | |||
308 | if (ioc->shost_recovery || ioc->pci_error_recovery) { | ||
309 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", | ||
310 | __func__, ioc->name); | ||
311 | return -EFAULT; | ||
312 | } | ||
313 | |||
314 | mutex_lock(&ioc->transport_cmds.mutex); | ||
315 | |||
316 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { | ||
317 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", | ||
318 | ioc->name, __func__); | ||
319 | rc = -EAGAIN; | ||
320 | goto out; | ||
321 | } | ||
322 | ioc->transport_cmds.status = MPT2_CMD_PENDING; | ||
323 | |||
324 | wait_state_count = 0; | ||
325 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
326 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
327 | if (wait_state_count++ == 10) { | ||
328 | printk(MPT2SAS_ERR_FMT | ||
329 | "%s: failed due to ioc not operational\n", | ||
330 | ioc->name, __func__); | ||
331 | rc = -EFAULT; | ||
332 | goto out; | ||
333 | } | ||
334 | ssleep(1); | ||
335 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
336 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
337 | "operational state(count=%d)\n", ioc->name, | ||
338 | __func__, wait_state_count); | ||
339 | } | ||
340 | if (wait_state_count) | ||
341 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", | ||
342 | ioc->name, __func__); | ||
343 | |||
344 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); | ||
345 | if (!smid) { | ||
346 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
347 | ioc->name, __func__); | ||
348 | rc = -EAGAIN; | ||
349 | goto out; | ||
350 | } | ||
351 | |||
352 | rc = 0; | ||
353 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
354 | ioc->transport_cmds.smid = smid; | ||
355 | |||
356 | sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply); | ||
357 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); | ||
358 | |||
359 | if (!data_out) { | ||
360 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
361 | __LINE__, __func__); | ||
362 | rc = -ENOMEM; | ||
363 | mpt2sas_base_free_smid(ioc, smid); | ||
364 | goto out; | ||
365 | } | ||
366 | |||
367 | manufacture_request = data_out; | ||
368 | manufacture_request->smp_frame_type = 0x40; | ||
369 | manufacture_request->function = 1; | ||
370 | manufacture_request->reserved = 0; | ||
371 | manufacture_request->request_length = 0; | ||
372 | |||
373 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); | ||
374 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; | ||
375 | mpi_request->PhysicalPort = 0xFF; | ||
376 | mpi_request->VF_ID = 0; /* TODO */ | ||
377 | mpi_request->VP_ID = 0; | ||
378 | mpi_request->SASAddress = cpu_to_le64(sas_address); | ||
379 | mpi_request->RequestDataLength = | ||
380 | cpu_to_le16(sizeof(struct rep_manu_request)); | ||
381 | psge = &mpi_request->SGL; | ||
382 | |||
383 | /* WRITE sgel first */ | ||
384 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
385 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); | ||
386 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
387 | ioc->base_add_sg_single(psge, sgl_flags | | ||
388 | sizeof(struct rep_manu_request), data_out_dma); | ||
389 | |||
390 | /* incr sgel */ | ||
391 | psge += ioc->sge_size; | ||
392 | |||
393 | /* READ sgel last */ | ||
394 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
395 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
396 | MPI2_SGE_FLAGS_END_OF_LIST); | ||
397 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
398 | ioc->base_add_sg_single(psge, sgl_flags | | ||
399 | sizeof(struct rep_manu_reply), data_out_dma + | ||
400 | sizeof(struct rep_manu_request)); | ||
401 | |||
402 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - " | ||
403 | "send to sas_addr(0x%016llx)\n", ioc->name, | ||
404 | (unsigned long long)sas_address)); | ||
405 | init_completion(&ioc->transport_cmds.done); | ||
406 | mpt2sas_base_put_smid_default(ioc, smid); | ||
407 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, | ||
408 | 10*HZ); | ||
409 | |||
410 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { | ||
411 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
412 | ioc->name, __func__); | ||
413 | _debug_dump_mf(mpi_request, | ||
414 | sizeof(Mpi2SmpPassthroughRequest_t)/4); | ||
415 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) | ||
416 | issue_reset = 1; | ||
417 | goto issue_host_reset; | ||
418 | } | ||
419 | |||
420 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - " | ||
421 | "complete\n", ioc->name)); | ||
422 | |||
423 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { | ||
424 | u8 *tmp; | ||
425 | |||
426 | mpi_reply = ioc->transport_cmds.reply; | ||
427 | |||
428 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
429 | "report_manufacture - reply data transfer size(%d)\n", | ||
430 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); | ||
431 | |||
432 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != | ||
433 | sizeof(struct rep_manu_reply)) | ||
434 | goto out; | ||
435 | |||
436 | manufacture_reply = data_out + sizeof(struct rep_manu_request); | ||
437 | strncpy(edev->vendor_id, manufacture_reply->vendor_id, | ||
438 | SAS_EXPANDER_VENDOR_ID_LEN); | ||
439 | strncpy(edev->product_id, manufacture_reply->product_id, | ||
440 | SAS_EXPANDER_PRODUCT_ID_LEN); | ||
441 | strncpy(edev->product_rev, manufacture_reply->product_rev, | ||
442 | SAS_EXPANDER_PRODUCT_REV_LEN); | ||
443 | edev->level = manufacture_reply->sas_format & 1; | ||
444 | if (edev->level) { | ||
445 | strncpy(edev->component_vendor_id, | ||
446 | manufacture_reply->component_vendor_id, | ||
447 | SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN); | ||
448 | tmp = (u8 *)&manufacture_reply->component_id; | ||
449 | edev->component_id = tmp[0] << 8 | tmp[1]; | ||
450 | edev->component_revision_id = | ||
451 | manufacture_reply->component_revision_id; | ||
452 | } | ||
453 | } else | ||
454 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
455 | "report_manufacture - no reply\n", ioc->name)); | ||
456 | |||
457 | issue_host_reset: | ||
458 | if (issue_reset) | ||
459 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
460 | FORCE_BIG_HAMMER); | ||
461 | out: | ||
462 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; | ||
463 | if (data_out) | ||
464 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); | ||
465 | |||
466 | mutex_unlock(&ioc->transport_cmds.mutex); | ||
467 | return rc; | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * _transport_delete_port - helper function to removing a port | ||
472 | * @ioc: per adapter object | ||
473 | * @mpt2sas_port: mpt2sas per port object | ||
474 | * | ||
475 | * Returns nothing. | ||
476 | */ | ||
477 | static void | ||
478 | _transport_delete_port(struct MPT2SAS_ADAPTER *ioc, | ||
479 | struct _sas_port *mpt2sas_port) | ||
480 | { | ||
481 | u64 sas_address = mpt2sas_port->remote_identify.sas_address; | ||
482 | enum sas_device_type device_type = | ||
483 | mpt2sas_port->remote_identify.device_type; | ||
484 | |||
485 | dev_printk(KERN_INFO, &mpt2sas_port->port->dev, | ||
486 | "remove: sas_addr(0x%016llx)\n", | ||
487 | (unsigned long long) sas_address); | ||
488 | |||
489 | ioc->logging_level |= MPT_DEBUG_TRANSPORT; | ||
490 | if (device_type == SAS_END_DEVICE) | ||
491 | mpt2sas_device_remove_by_sas_address(ioc, sas_address); | ||
492 | else if (device_type == SAS_EDGE_EXPANDER_DEVICE || | ||
493 | device_type == SAS_FANOUT_EXPANDER_DEVICE) | ||
494 | mpt2sas_expander_remove(ioc, sas_address); | ||
495 | ioc->logging_level &= ~MPT_DEBUG_TRANSPORT; | ||
496 | } | ||
497 | |||
498 | /** | ||
499 | * _transport_delete_phy - helper function to removing single phy from port | ||
500 | * @ioc: per adapter object | ||
501 | * @mpt2sas_port: mpt2sas per port object | ||
502 | * @mpt2sas_phy: mpt2sas per phy object | ||
503 | * | ||
504 | * Returns nothing. | ||
505 | */ | ||
506 | static void | ||
507 | _transport_delete_phy(struct MPT2SAS_ADAPTER *ioc, | ||
508 | struct _sas_port *mpt2sas_port, struct _sas_phy *mpt2sas_phy) | ||
509 | { | ||
510 | u64 sas_address = mpt2sas_port->remote_identify.sas_address; | ||
511 | |||
512 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, | ||
513 | "remove: sas_addr(0x%016llx), phy(%d)\n", | ||
514 | (unsigned long long) sas_address, mpt2sas_phy->phy_id); | ||
515 | |||
516 | list_del(&mpt2sas_phy->port_siblings); | ||
517 | mpt2sas_port->num_phys--; | ||
518 | sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy); | ||
519 | mpt2sas_phy->phy_belongs_to_port = 0; | ||
520 | } | ||
521 | |||
522 | /** | ||
523 | * _transport_add_phy - helper function to adding single phy to port | ||
524 | * @ioc: per adapter object | ||
525 | * @mpt2sas_port: mpt2sas per port object | ||
526 | * @mpt2sas_phy: mpt2sas per phy object | ||
527 | * | ||
528 | * Returns nothing. | ||
529 | */ | ||
530 | static void | ||
531 | _transport_add_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_port *mpt2sas_port, | ||
532 | struct _sas_phy *mpt2sas_phy) | ||
533 | { | ||
534 | u64 sas_address = mpt2sas_port->remote_identify.sas_address; | ||
535 | |||
536 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, | ||
537 | "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long) | ||
538 | sas_address, mpt2sas_phy->phy_id); | ||
539 | |||
540 | list_add_tail(&mpt2sas_phy->port_siblings, &mpt2sas_port->phy_list); | ||
541 | mpt2sas_port->num_phys++; | ||
542 | sas_port_add_phy(mpt2sas_port->port, mpt2sas_phy->phy); | ||
543 | mpt2sas_phy->phy_belongs_to_port = 1; | ||
544 | } | ||
545 | |||
546 | /** | ||
547 | * _transport_add_phy_to_an_existing_port - adding new phy to existing port | ||
548 | * @ioc: per adapter object | ||
549 | * @sas_node: sas node object (either expander or sas host) | ||
550 | * @mpt2sas_phy: mpt2sas per phy object | ||
551 | * @sas_address: sas address of device/expander were phy needs to be added to | ||
552 | * | ||
553 | * Returns nothing. | ||
554 | */ | ||
555 | static void | ||
556 | _transport_add_phy_to_an_existing_port(struct MPT2SAS_ADAPTER *ioc, | ||
557 | struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy, u64 sas_address) | ||
558 | { | ||
559 | struct _sas_port *mpt2sas_port; | ||
560 | struct _sas_phy *phy_srch; | ||
561 | |||
562 | if (mpt2sas_phy->phy_belongs_to_port == 1) | ||
563 | return; | ||
564 | |||
565 | list_for_each_entry(mpt2sas_port, &sas_node->sas_port_list, | ||
566 | port_list) { | ||
567 | if (mpt2sas_port->remote_identify.sas_address != | ||
568 | sas_address) | ||
569 | continue; | ||
570 | list_for_each_entry(phy_srch, &mpt2sas_port->phy_list, | ||
571 | port_siblings) { | ||
572 | if (phy_srch == mpt2sas_phy) | ||
573 | return; | ||
574 | } | ||
575 | _transport_add_phy(ioc, mpt2sas_port, mpt2sas_phy); | ||
576 | return; | ||
577 | } | ||
578 | |||
579 | } | ||
580 | |||
581 | /** | ||
582 | * _transport_del_phy_from_an_existing_port - delete phy from existing port | ||
583 | * @ioc: per adapter object | ||
584 | * @sas_node: sas node object (either expander or sas host) | ||
585 | * @mpt2sas_phy: mpt2sas per phy object | ||
586 | * | ||
587 | * Returns nothing. | ||
588 | */ | ||
589 | static void | ||
590 | _transport_del_phy_from_an_existing_port(struct MPT2SAS_ADAPTER *ioc, | ||
591 | struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy) | ||
592 | { | ||
593 | struct _sas_port *mpt2sas_port, *next; | ||
594 | struct _sas_phy *phy_srch; | ||
595 | |||
596 | if (mpt2sas_phy->phy_belongs_to_port == 0) | ||
597 | return; | ||
598 | |||
599 | list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list, | ||
600 | port_list) { | ||
601 | list_for_each_entry(phy_srch, &mpt2sas_port->phy_list, | ||
602 | port_siblings) { | ||
603 | if (phy_srch != mpt2sas_phy) | ||
604 | continue; | ||
605 | if (mpt2sas_port->num_phys == 1) | ||
606 | _transport_delete_port(ioc, mpt2sas_port); | ||
607 | else | ||
608 | _transport_delete_phy(ioc, mpt2sas_port, | ||
609 | mpt2sas_phy); | ||
610 | return; | ||
611 | } | ||
612 | } | ||
613 | } | ||
614 | |||
615 | /** | ||
616 | * _transport_sanity_check - sanity check when adding a new port | ||
617 | * @ioc: per adapter object | ||
618 | * @sas_node: sas node object (either expander or sas host) | ||
619 | * @sas_address: sas address of device being added | ||
620 | * | ||
621 | * See the explanation above from _transport_delete_duplicate_port | ||
622 | */ | ||
623 | static void | ||
624 | _transport_sanity_check(struct MPT2SAS_ADAPTER *ioc, struct _sas_node *sas_node, | ||
625 | u64 sas_address) | ||
626 | { | ||
627 | int i; | ||
628 | |||
629 | for (i = 0; i < sas_node->num_phys; i++) { | ||
630 | if (sas_node->phy[i].remote_identify.sas_address != sas_address) | ||
631 | continue; | ||
632 | if (sas_node->phy[i].phy_belongs_to_port == 1) | ||
633 | _transport_del_phy_from_an_existing_port(ioc, sas_node, | ||
634 | &sas_node->phy[i]); | ||
635 | } | ||
636 | } | ||
637 | |||
638 | /** | ||
639 | * mpt2sas_transport_port_add - insert port to the list | ||
640 | * @ioc: per adapter object | ||
641 | * @handle: handle of attached device | ||
642 | * @sas_address: sas address of parent expander or sas host | ||
643 | * Context: This function will acquire ioc->sas_node_lock. | ||
644 | * | ||
645 | * Adding new port object to the sas_node->sas_port_list. | ||
646 | * | ||
647 | * Returns mpt2sas_port. | ||
648 | */ | ||
649 | struct _sas_port * | ||
650 | mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, u16 handle, | ||
651 | u64 sas_address) | ||
652 | { | ||
653 | struct _sas_phy *mpt2sas_phy, *next; | ||
654 | struct _sas_port *mpt2sas_port; | ||
655 | unsigned long flags; | ||
656 | struct _sas_node *sas_node; | ||
657 | struct sas_rphy *rphy; | ||
658 | int i; | ||
659 | struct sas_port *port; | ||
660 | |||
661 | mpt2sas_port = kzalloc(sizeof(struct _sas_port), | ||
662 | GFP_KERNEL); | ||
663 | if (!mpt2sas_port) { | ||
664 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
665 | ioc->name, __FILE__, __LINE__, __func__); | ||
666 | return NULL; | ||
667 | } | ||
668 | |||
669 | INIT_LIST_HEAD(&mpt2sas_port->port_list); | ||
670 | INIT_LIST_HEAD(&mpt2sas_port->phy_list); | ||
671 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
672 | sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); | ||
673 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
674 | |||
675 | if (!sas_node) { | ||
676 | printk(MPT2SAS_ERR_FMT "%s: Could not find " | ||
677 | "parent sas_address(0x%016llx)!\n", ioc->name, | ||
678 | __func__, (unsigned long long)sas_address); | ||
679 | goto out_fail; | ||
680 | } | ||
681 | |||
682 | if ((_transport_set_identify(ioc, handle, | ||
683 | &mpt2sas_port->remote_identify))) { | ||
684 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
685 | ioc->name, __FILE__, __LINE__, __func__); | ||
686 | goto out_fail; | ||
687 | } | ||
688 | |||
689 | if (mpt2sas_port->remote_identify.device_type == SAS_PHY_UNUSED) { | ||
690 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
691 | ioc->name, __FILE__, __LINE__, __func__); | ||
692 | goto out_fail; | ||
693 | } | ||
694 | |||
695 | _transport_sanity_check(ioc, sas_node, | ||
696 | mpt2sas_port->remote_identify.sas_address); | ||
697 | |||
698 | for (i = 0; i < sas_node->num_phys; i++) { | ||
699 | if (sas_node->phy[i].remote_identify.sas_address != | ||
700 | mpt2sas_port->remote_identify.sas_address) | ||
701 | continue; | ||
702 | list_add_tail(&sas_node->phy[i].port_siblings, | ||
703 | &mpt2sas_port->phy_list); | ||
704 | mpt2sas_port->num_phys++; | ||
705 | } | ||
706 | |||
707 | if (!mpt2sas_port->num_phys) { | ||
708 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
709 | ioc->name, __FILE__, __LINE__, __func__); | ||
710 | goto out_fail; | ||
711 | } | ||
712 | |||
713 | port = sas_port_alloc_num(sas_node->parent_dev); | ||
714 | if ((sas_port_add(port))) { | ||
715 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
716 | ioc->name, __FILE__, __LINE__, __func__); | ||
717 | goto out_fail; | ||
718 | } | ||
719 | |||
720 | list_for_each_entry(mpt2sas_phy, &mpt2sas_port->phy_list, | ||
721 | port_siblings) { | ||
722 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) | ||
723 | dev_printk(KERN_INFO, &port->dev, "add: handle(0x%04x)" | ||
724 | ", sas_addr(0x%016llx), phy(%d)\n", handle, | ||
725 | (unsigned long long) | ||
726 | mpt2sas_port->remote_identify.sas_address, | ||
727 | mpt2sas_phy->phy_id); | ||
728 | sas_port_add_phy(port, mpt2sas_phy->phy); | ||
729 | mpt2sas_phy->phy_belongs_to_port = 1; | ||
730 | } | ||
731 | |||
732 | mpt2sas_port->port = port; | ||
733 | if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) | ||
734 | rphy = sas_end_device_alloc(port); | ||
735 | else | ||
736 | rphy = sas_expander_alloc(port, | ||
737 | mpt2sas_port->remote_identify.device_type); | ||
738 | |||
739 | rphy->identify = mpt2sas_port->remote_identify; | ||
740 | if ((sas_rphy_add(rphy))) { | ||
741 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
742 | ioc->name, __FILE__, __LINE__, __func__); | ||
743 | } | ||
744 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) | ||
745 | dev_printk(KERN_INFO, &rphy->dev, "add: handle(0x%04x), " | ||
746 | "sas_addr(0x%016llx)\n", handle, | ||
747 | (unsigned long long) | ||
748 | mpt2sas_port->remote_identify.sas_address); | ||
749 | mpt2sas_port->rphy = rphy; | ||
750 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
751 | list_add_tail(&mpt2sas_port->port_list, &sas_node->sas_port_list); | ||
752 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
753 | |||
754 | /* fill in report manufacture */ | ||
755 | if (mpt2sas_port->remote_identify.device_type == | ||
756 | MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER || | ||
757 | mpt2sas_port->remote_identify.device_type == | ||
758 | MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) | ||
759 | _transport_expander_report_manufacture(ioc, | ||
760 | mpt2sas_port->remote_identify.sas_address, | ||
761 | rphy_to_expander_device(rphy)); | ||
762 | |||
763 | return mpt2sas_port; | ||
764 | |||
765 | out_fail: | ||
766 | list_for_each_entry_safe(mpt2sas_phy, next, &mpt2sas_port->phy_list, | ||
767 | port_siblings) | ||
768 | list_del(&mpt2sas_phy->port_siblings); | ||
769 | kfree(mpt2sas_port); | ||
770 | return NULL; | ||
771 | } | ||
772 | |||
773 | /** | ||
774 | * mpt2sas_transport_port_remove - remove port from the list | ||
775 | * @ioc: per adapter object | ||
776 | * @sas_address: sas address of attached device | ||
777 | * @sas_address_parent: sas address of parent expander or sas host | ||
778 | * Context: This function will acquire ioc->sas_node_lock. | ||
779 | * | ||
780 | * Removing object and freeing associated memory from the | ||
781 | * ioc->sas_port_list. | ||
782 | * | ||
783 | * Return nothing. | ||
784 | */ | ||
785 | void | ||
786 | mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, | ||
787 | u64 sas_address_parent) | ||
788 | { | ||
789 | int i; | ||
790 | unsigned long flags; | ||
791 | struct _sas_port *mpt2sas_port, *next; | ||
792 | struct _sas_node *sas_node; | ||
793 | u8 found = 0; | ||
794 | struct _sas_phy *mpt2sas_phy, *next_phy; | ||
795 | |||
796 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
797 | sas_node = _transport_sas_node_find_by_sas_address(ioc, | ||
798 | sas_address_parent); | ||
799 | if (!sas_node) { | ||
800 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
801 | return; | ||
802 | } | ||
803 | list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list, | ||
804 | port_list) { | ||
805 | if (mpt2sas_port->remote_identify.sas_address != sas_address) | ||
806 | continue; | ||
807 | found = 1; | ||
808 | list_del(&mpt2sas_port->port_list); | ||
809 | goto out; | ||
810 | } | ||
811 | out: | ||
812 | if (!found) { | ||
813 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
814 | return; | ||
815 | } | ||
816 | |||
817 | for (i = 0; i < sas_node->num_phys; i++) { | ||
818 | if (sas_node->phy[i].remote_identify.sas_address == sas_address) | ||
819 | memset(&sas_node->phy[i].remote_identify, 0 , | ||
820 | sizeof(struct sas_identify)); | ||
821 | } | ||
822 | |||
823 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
824 | list_for_each_entry_safe(mpt2sas_phy, next_phy, | ||
825 | &mpt2sas_port->phy_list, port_siblings) { | ||
826 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) | ||
827 | dev_printk(KERN_INFO, &mpt2sas_port->port->dev, | ||
828 | "remove: sas_addr(0x%016llx), phy(%d)\n", | ||
829 | (unsigned long long) | ||
830 | mpt2sas_port->remote_identify.sas_address, | ||
831 | mpt2sas_phy->phy_id); | ||
832 | mpt2sas_phy->phy_belongs_to_port = 0; | ||
833 | sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy); | ||
834 | list_del(&mpt2sas_phy->port_siblings); | ||
835 | } | ||
836 | sas_port_delete(mpt2sas_port->port); | ||
837 | kfree(mpt2sas_port); | ||
838 | } | ||
839 | |||
840 | /** | ||
841 | * mpt2sas_transport_add_host_phy - report sas_host phy to transport | ||
842 | * @ioc: per adapter object | ||
843 | * @mpt2sas_phy: mpt2sas per phy object | ||
844 | * @phy_pg0: sas phy page 0 | ||
845 | * @parent_dev: parent device class object | ||
846 | * | ||
847 | * Returns 0 for success, non-zero for failure. | ||
848 | */ | ||
849 | int | ||
850 | mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy | ||
851 | *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev) | ||
852 | { | ||
853 | struct sas_phy *phy; | ||
854 | int phy_index = mpt2sas_phy->phy_id; | ||
855 | |||
856 | |||
857 | INIT_LIST_HEAD(&mpt2sas_phy->port_siblings); | ||
858 | phy = sas_phy_alloc(parent_dev, phy_index); | ||
859 | if (!phy) { | ||
860 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
861 | ioc->name, __FILE__, __LINE__, __func__); | ||
862 | return -1; | ||
863 | } | ||
864 | if ((_transport_set_identify(ioc, mpt2sas_phy->handle, | ||
865 | &mpt2sas_phy->identify))) { | ||
866 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
867 | ioc->name, __FILE__, __LINE__, __func__); | ||
868 | return -1; | ||
869 | } | ||
870 | phy->identify = mpt2sas_phy->identify; | ||
871 | mpt2sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle); | ||
872 | if (mpt2sas_phy->attached_handle) | ||
873 | _transport_set_identify(ioc, mpt2sas_phy->attached_handle, | ||
874 | &mpt2sas_phy->remote_identify); | ||
875 | phy->identify.phy_identifier = mpt2sas_phy->phy_id; | ||
876 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( | ||
877 | phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); | ||
878 | phy->minimum_linkrate_hw = _transport_convert_phy_link_rate( | ||
879 | phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK); | ||
880 | phy->maximum_linkrate_hw = _transport_convert_phy_link_rate( | ||
881 | phy_pg0.HwLinkRate >> 4); | ||
882 | phy->minimum_linkrate = _transport_convert_phy_link_rate( | ||
883 | phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); | ||
884 | phy->maximum_linkrate = _transport_convert_phy_link_rate( | ||
885 | phy_pg0.ProgrammedLinkRate >> 4); | ||
886 | |||
887 | if ((sas_phy_add(phy))) { | ||
888 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
889 | ioc->name, __FILE__, __LINE__, __func__); | ||
890 | sas_phy_free(phy); | ||
891 | return -1; | ||
892 | } | ||
893 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) | ||
894 | dev_printk(KERN_INFO, &phy->dev, | ||
895 | "add: handle(0x%04x), sas_addr(0x%016llx)\n" | ||
896 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", | ||
897 | mpt2sas_phy->handle, (unsigned long long) | ||
898 | mpt2sas_phy->identify.sas_address, | ||
899 | mpt2sas_phy->attached_handle, | ||
900 | (unsigned long long) | ||
901 | mpt2sas_phy->remote_identify.sas_address); | ||
902 | mpt2sas_phy->phy = phy; | ||
903 | return 0; | ||
904 | } | ||
905 | |||
906 | |||
907 | /** | ||
908 | * mpt2sas_transport_add_expander_phy - report expander phy to transport | ||
909 | * @ioc: per adapter object | ||
910 | * @mpt2sas_phy: mpt2sas per phy object | ||
911 | * @expander_pg1: expander page 1 | ||
912 | * @parent_dev: parent device class object | ||
913 | * | ||
914 | * Returns 0 for success, non-zero for failure. | ||
915 | */ | ||
916 | int | ||
917 | mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy | ||
918 | *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev) | ||
919 | { | ||
920 | struct sas_phy *phy; | ||
921 | int phy_index = mpt2sas_phy->phy_id; | ||
922 | |||
923 | INIT_LIST_HEAD(&mpt2sas_phy->port_siblings); | ||
924 | phy = sas_phy_alloc(parent_dev, phy_index); | ||
925 | if (!phy) { | ||
926 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
927 | ioc->name, __FILE__, __LINE__, __func__); | ||
928 | return -1; | ||
929 | } | ||
930 | if ((_transport_set_identify(ioc, mpt2sas_phy->handle, | ||
931 | &mpt2sas_phy->identify))) { | ||
932 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
933 | ioc->name, __FILE__, __LINE__, __func__); | ||
934 | return -1; | ||
935 | } | ||
936 | phy->identify = mpt2sas_phy->identify; | ||
937 | mpt2sas_phy->attached_handle = | ||
938 | le16_to_cpu(expander_pg1.AttachedDevHandle); | ||
939 | if (mpt2sas_phy->attached_handle) | ||
940 | _transport_set_identify(ioc, mpt2sas_phy->attached_handle, | ||
941 | &mpt2sas_phy->remote_identify); | ||
942 | phy->identify.phy_identifier = mpt2sas_phy->phy_id; | ||
943 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( | ||
944 | expander_pg1.NegotiatedLinkRate & | ||
945 | MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); | ||
946 | phy->minimum_linkrate_hw = _transport_convert_phy_link_rate( | ||
947 | expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK); | ||
948 | phy->maximum_linkrate_hw = _transport_convert_phy_link_rate( | ||
949 | expander_pg1.HwLinkRate >> 4); | ||
950 | phy->minimum_linkrate = _transport_convert_phy_link_rate( | ||
951 | expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); | ||
952 | phy->maximum_linkrate = _transport_convert_phy_link_rate( | ||
953 | expander_pg1.ProgrammedLinkRate >> 4); | ||
954 | |||
955 | if ((sas_phy_add(phy))) { | ||
956 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
957 | ioc->name, __FILE__, __LINE__, __func__); | ||
958 | sas_phy_free(phy); | ||
959 | return -1; | ||
960 | } | ||
961 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) | ||
962 | dev_printk(KERN_INFO, &phy->dev, | ||
963 | "add: handle(0x%04x), sas_addr(0x%016llx)\n" | ||
964 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", | ||
965 | mpt2sas_phy->handle, (unsigned long long) | ||
966 | mpt2sas_phy->identify.sas_address, | ||
967 | mpt2sas_phy->attached_handle, | ||
968 | (unsigned long long) | ||
969 | mpt2sas_phy->remote_identify.sas_address); | ||
970 | mpt2sas_phy->phy = phy; | ||
971 | return 0; | ||
972 | } | ||
973 | |||
974 | /** | ||
975 | * mpt2sas_transport_update_links - refreshing phy link changes | ||
976 | * @ioc: per adapter object | ||
977 | * @sas_address: sas address of parent expander or sas host | ||
978 | * @handle: attached device handle | ||
979 | * @phy_numberv: phy number | ||
980 | * @link_rate: new link rate | ||
981 | * | ||
982 | * Returns nothing. | ||
983 | */ | ||
984 | void | ||
985 | mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc, | ||
986 | u64 sas_address, u16 handle, u8 phy_number, u8 link_rate) | ||
987 | { | ||
988 | unsigned long flags; | ||
989 | struct _sas_node *sas_node; | ||
990 | struct _sas_phy *mpt2sas_phy; | ||
991 | |||
992 | if (ioc->shost_recovery || ioc->pci_error_recovery) | ||
993 | return; | ||
994 | |||
995 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
996 | sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); | ||
997 | if (!sas_node) { | ||
998 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
999 | return; | ||
1000 | } | ||
1001 | |||
1002 | mpt2sas_phy = &sas_node->phy[phy_number]; | ||
1003 | mpt2sas_phy->attached_handle = handle; | ||
1004 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1005 | if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) { | ||
1006 | _transport_set_identify(ioc, handle, | ||
1007 | &mpt2sas_phy->remote_identify); | ||
1008 | _transport_add_phy_to_an_existing_port(ioc, sas_node, | ||
1009 | mpt2sas_phy, mpt2sas_phy->remote_identify.sas_address); | ||
1010 | } else | ||
1011 | memset(&mpt2sas_phy->remote_identify, 0 , sizeof(struct | ||
1012 | sas_identify)); | ||
1013 | |||
1014 | if (mpt2sas_phy->phy) | ||
1015 | mpt2sas_phy->phy->negotiated_linkrate = | ||
1016 | _transport_convert_phy_link_rate(link_rate); | ||
1017 | |||
1018 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) | ||
1019 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, | ||
1020 | "refresh: parent sas_addr(0x%016llx),\n" | ||
1021 | "\tlink_rate(0x%02x), phy(%d)\n" | ||
1022 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", | ||
1023 | (unsigned long long)sas_address, | ||
1024 | link_rate, phy_number, handle, (unsigned long long) | ||
1025 | mpt2sas_phy->remote_identify.sas_address); | ||
1026 | } | ||
1027 | |||
1028 | static inline void * | ||
1029 | phy_to_ioc(struct sas_phy *phy) | ||
1030 | { | ||
1031 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); | ||
1032 | return shost_priv(shost); | ||
1033 | } | ||
1034 | |||
1035 | static inline void * | ||
1036 | rphy_to_ioc(struct sas_rphy *rphy) | ||
1037 | { | ||
1038 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); | ||
1039 | return shost_priv(shost); | ||
1040 | } | ||
1041 | |||
1042 | |||
1043 | /* report phy error log structure */ | ||
1044 | struct phy_error_log_request{ | ||
1045 | u8 smp_frame_type; /* 0x40 */ | ||
1046 | u8 function; /* 0x11 */ | ||
1047 | u8 allocated_response_length; | ||
1048 | u8 request_length; /* 02 */ | ||
1049 | u8 reserved_1[5]; | ||
1050 | u8 phy_identifier; | ||
1051 | u8 reserved_2[2]; | ||
1052 | }; | ||
1053 | |||
1054 | /* report phy error log reply structure */ | ||
1055 | struct phy_error_log_reply{ | ||
1056 | u8 smp_frame_type; /* 0x41 */ | ||
1057 | u8 function; /* 0x11 */ | ||
1058 | u8 function_result; | ||
1059 | u8 response_length; | ||
1060 | __be16 expander_change_count; | ||
1061 | u8 reserved_1[3]; | ||
1062 | u8 phy_identifier; | ||
1063 | u8 reserved_2[2]; | ||
1064 | __be32 invalid_dword; | ||
1065 | __be32 running_disparity_error; | ||
1066 | __be32 loss_of_dword_sync; | ||
1067 | __be32 phy_reset_problem; | ||
1068 | }; | ||
1069 | |||
1070 | /** | ||
1071 | * _transport_get_expander_phy_error_log - return expander counters | ||
1072 | * @ioc: per adapter object | ||
1073 | * @phy: The sas phy object | ||
1074 | * | ||
1075 | * Returns 0 for success, non-zero for failure. | ||
1076 | * | ||
1077 | */ | ||
1078 | static int | ||
1079 | _transport_get_expander_phy_error_log(struct MPT2SAS_ADAPTER *ioc, | ||
1080 | struct sas_phy *phy) | ||
1081 | { | ||
1082 | Mpi2SmpPassthroughRequest_t *mpi_request; | ||
1083 | Mpi2SmpPassthroughReply_t *mpi_reply; | ||
1084 | struct phy_error_log_request *phy_error_log_request; | ||
1085 | struct phy_error_log_reply *phy_error_log_reply; | ||
1086 | int rc; | ||
1087 | u16 smid; | ||
1088 | u32 ioc_state; | ||
1089 | unsigned long timeleft; | ||
1090 | void *psge; | ||
1091 | u32 sgl_flags; | ||
1092 | u8 issue_reset = 0; | ||
1093 | void *data_out = NULL; | ||
1094 | dma_addr_t data_out_dma; | ||
1095 | u32 sz; | ||
1096 | u16 wait_state_count; | ||
1097 | |||
1098 | if (ioc->shost_recovery || ioc->pci_error_recovery) { | ||
1099 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", | ||
1100 | __func__, ioc->name); | ||
1101 | return -EFAULT; | ||
1102 | } | ||
1103 | |||
1104 | mutex_lock(&ioc->transport_cmds.mutex); | ||
1105 | |||
1106 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { | ||
1107 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", | ||
1108 | ioc->name, __func__); | ||
1109 | rc = -EAGAIN; | ||
1110 | goto out; | ||
1111 | } | ||
1112 | ioc->transport_cmds.status = MPT2_CMD_PENDING; | ||
1113 | |||
1114 | wait_state_count = 0; | ||
1115 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
1116 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
1117 | if (wait_state_count++ == 10) { | ||
1118 | printk(MPT2SAS_ERR_FMT | ||
1119 | "%s: failed due to ioc not operational\n", | ||
1120 | ioc->name, __func__); | ||
1121 | rc = -EFAULT; | ||
1122 | goto out; | ||
1123 | } | ||
1124 | ssleep(1); | ||
1125 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
1126 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
1127 | "operational state(count=%d)\n", ioc->name, | ||
1128 | __func__, wait_state_count); | ||
1129 | } | ||
1130 | if (wait_state_count) | ||
1131 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", | ||
1132 | ioc->name, __func__); | ||
1133 | |||
1134 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); | ||
1135 | if (!smid) { | ||
1136 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
1137 | ioc->name, __func__); | ||
1138 | rc = -EAGAIN; | ||
1139 | goto out; | ||
1140 | } | ||
1141 | |||
1142 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
1143 | ioc->transport_cmds.smid = smid; | ||
1144 | |||
1145 | sz = sizeof(struct phy_error_log_request) + | ||
1146 | sizeof(struct phy_error_log_reply); | ||
1147 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); | ||
1148 | if (!data_out) { | ||
1149 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
1150 | __LINE__, __func__); | ||
1151 | rc = -ENOMEM; | ||
1152 | mpt2sas_base_free_smid(ioc, smid); | ||
1153 | goto out; | ||
1154 | } | ||
1155 | |||
1156 | rc = -EINVAL; | ||
1157 | memset(data_out, 0, sz); | ||
1158 | phy_error_log_request = data_out; | ||
1159 | phy_error_log_request->smp_frame_type = 0x40; | ||
1160 | phy_error_log_request->function = 0x11; | ||
1161 | phy_error_log_request->request_length = 2; | ||
1162 | phy_error_log_request->allocated_response_length = 0; | ||
1163 | phy_error_log_request->phy_identifier = phy->number; | ||
1164 | |||
1165 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); | ||
1166 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; | ||
1167 | mpi_request->PhysicalPort = 0xFF; | ||
1168 | mpi_request->VF_ID = 0; /* TODO */ | ||
1169 | mpi_request->VP_ID = 0; | ||
1170 | mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address); | ||
1171 | mpi_request->RequestDataLength = | ||
1172 | cpu_to_le16(sizeof(struct phy_error_log_request)); | ||
1173 | psge = &mpi_request->SGL; | ||
1174 | |||
1175 | /* WRITE sgel first */ | ||
1176 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
1177 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); | ||
1178 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
1179 | ioc->base_add_sg_single(psge, sgl_flags | | ||
1180 | sizeof(struct phy_error_log_request), data_out_dma); | ||
1181 | |||
1182 | /* incr sgel */ | ||
1183 | psge += ioc->sge_size; | ||
1184 | |||
1185 | /* READ sgel last */ | ||
1186 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
1187 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
1188 | MPI2_SGE_FLAGS_END_OF_LIST); | ||
1189 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
1190 | ioc->base_add_sg_single(psge, sgl_flags | | ||
1191 | sizeof(struct phy_error_log_reply), data_out_dma + | ||
1192 | sizeof(struct phy_error_log_request)); | ||
1193 | |||
1194 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - " | ||
1195 | "send to sas_addr(0x%016llx), phy(%d)\n", ioc->name, | ||
1196 | (unsigned long long)phy->identify.sas_address, phy->number)); | ||
1197 | init_completion(&ioc->transport_cmds.done); | ||
1198 | mpt2sas_base_put_smid_default(ioc, smid); | ||
1199 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, | ||
1200 | 10*HZ); | ||
1201 | |||
1202 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { | ||
1203 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
1204 | ioc->name, __func__); | ||
1205 | _debug_dump_mf(mpi_request, | ||
1206 | sizeof(Mpi2SmpPassthroughRequest_t)/4); | ||
1207 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) | ||
1208 | issue_reset = 1; | ||
1209 | goto issue_host_reset; | ||
1210 | } | ||
1211 | |||
1212 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - " | ||
1213 | "complete\n", ioc->name)); | ||
1214 | |||
1215 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { | ||
1216 | |||
1217 | mpi_reply = ioc->transport_cmds.reply; | ||
1218 | |||
1219 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1220 | "phy_error_log - reply data transfer size(%d)\n", | ||
1221 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); | ||
1222 | |||
1223 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != | ||
1224 | sizeof(struct phy_error_log_reply)) | ||
1225 | goto out; | ||
1226 | |||
1227 | phy_error_log_reply = data_out + | ||
1228 | sizeof(struct phy_error_log_request); | ||
1229 | |||
1230 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1231 | "phy_error_log - function_result(%d)\n", | ||
1232 | ioc->name, phy_error_log_reply->function_result)); | ||
1233 | |||
1234 | phy->invalid_dword_count = | ||
1235 | be32_to_cpu(phy_error_log_reply->invalid_dword); | ||
1236 | phy->running_disparity_error_count = | ||
1237 | be32_to_cpu(phy_error_log_reply->running_disparity_error); | ||
1238 | phy->loss_of_dword_sync_count = | ||
1239 | be32_to_cpu(phy_error_log_reply->loss_of_dword_sync); | ||
1240 | phy->phy_reset_problem_count = | ||
1241 | be32_to_cpu(phy_error_log_reply->phy_reset_problem); | ||
1242 | rc = 0; | ||
1243 | } else | ||
1244 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1245 | "phy_error_log - no reply\n", ioc->name)); | ||
1246 | |||
1247 | issue_host_reset: | ||
1248 | if (issue_reset) | ||
1249 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
1250 | FORCE_BIG_HAMMER); | ||
1251 | out: | ||
1252 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; | ||
1253 | if (data_out) | ||
1254 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); | ||
1255 | |||
1256 | mutex_unlock(&ioc->transport_cmds.mutex); | ||
1257 | return rc; | ||
1258 | } | ||
1259 | |||
1260 | /** | ||
1261 | * _transport_get_linkerrors - return phy counters for both hba and expanders | ||
1262 | * @phy: The sas phy object | ||
1263 | * | ||
1264 | * Returns 0 for success, non-zero for failure. | ||
1265 | * | ||
1266 | */ | ||
1267 | static int | ||
1268 | _transport_get_linkerrors(struct sas_phy *phy) | ||
1269 | { | ||
1270 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); | ||
1271 | unsigned long flags; | ||
1272 | Mpi2ConfigReply_t mpi_reply; | ||
1273 | Mpi2SasPhyPage1_t phy_pg1; | ||
1274 | |||
1275 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
1276 | if (_transport_sas_node_find_by_sas_address(ioc, | ||
1277 | phy->identify.sas_address) == NULL) { | ||
1278 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1279 | return -EINVAL; | ||
1280 | } | ||
1281 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1282 | |||
1283 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) | ||
1284 | return _transport_get_expander_phy_error_log(ioc, phy); | ||
1285 | |||
1286 | /* get hba phy error logs */ | ||
1287 | if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1, | ||
1288 | phy->number))) { | ||
1289 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1290 | ioc->name, __FILE__, __LINE__, __func__); | ||
1291 | return -ENXIO; | ||
1292 | } | ||
1293 | |||
1294 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) | ||
1295 | printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" | ||
1296 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, | ||
1297 | phy->number, le16_to_cpu(mpi_reply.IOCStatus), | ||
1298 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
1299 | |||
1300 | phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount); | ||
1301 | phy->running_disparity_error_count = | ||
1302 | le32_to_cpu(phy_pg1.RunningDisparityErrorCount); | ||
1303 | phy->loss_of_dword_sync_count = | ||
1304 | le32_to_cpu(phy_pg1.LossDwordSynchCount); | ||
1305 | phy->phy_reset_problem_count = | ||
1306 | le32_to_cpu(phy_pg1.PhyResetProblemCount); | ||
1307 | return 0; | ||
1308 | } | ||
1309 | |||
1310 | /** | ||
1311 | * _transport_get_enclosure_identifier - | ||
1312 | * @phy: The sas phy object | ||
1313 | * | ||
1314 | * Obtain the enclosure logical id for an expander. | ||
1315 | * Returns 0 for success, non-zero for failure. | ||
1316 | */ | ||
1317 | static int | ||
1318 | _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) | ||
1319 | { | ||
1320 | struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); | ||
1321 | struct _sas_device *sas_device; | ||
1322 | unsigned long flags; | ||
1323 | int rc; | ||
1324 | |||
1325 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1326 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
1327 | rphy->identify.sas_address); | ||
1328 | if (sas_device) { | ||
1329 | *identifier = sas_device->enclosure_logical_id; | ||
1330 | rc = 0; | ||
1331 | sas_device_put(sas_device); | ||
1332 | } else { | ||
1333 | *identifier = 0; | ||
1334 | rc = -ENXIO; | ||
1335 | } | ||
1336 | |||
1337 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1338 | return rc; | ||
1339 | } | ||
1340 | |||
1341 | /** | ||
1342 | * _transport_get_bay_identifier - | ||
1343 | * @phy: The sas phy object | ||
1344 | * | ||
1345 | * Returns the slot id for a device that resides inside an enclosure. | ||
1346 | */ | ||
1347 | static int | ||
1348 | _transport_get_bay_identifier(struct sas_rphy *rphy) | ||
1349 | { | ||
1350 | struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); | ||
1351 | struct _sas_device *sas_device; | ||
1352 | unsigned long flags; | ||
1353 | int rc; | ||
1354 | |||
1355 | spin_lock_irqsave(&ioc->sas_device_lock, flags); | ||
1356 | sas_device = __mpt2sas_get_sdev_by_addr(ioc, | ||
1357 | rphy->identify.sas_address); | ||
1358 | if (sas_device) { | ||
1359 | rc = sas_device->slot; | ||
1360 | sas_device_put(sas_device); | ||
1361 | } else { | ||
1362 | rc = -ENXIO; | ||
1363 | } | ||
1364 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); | ||
1365 | return rc; | ||
1366 | } | ||
1367 | |||
1368 | /* phy control request structure */ | ||
1369 | struct phy_control_request{ | ||
1370 | u8 smp_frame_type; /* 0x40 */ | ||
1371 | u8 function; /* 0x91 */ | ||
1372 | u8 allocated_response_length; | ||
1373 | u8 request_length; /* 0x09 */ | ||
1374 | u16 expander_change_count; | ||
1375 | u8 reserved_1[3]; | ||
1376 | u8 phy_identifier; | ||
1377 | u8 phy_operation; | ||
1378 | u8 reserved_2[13]; | ||
1379 | u64 attached_device_name; | ||
1380 | u8 programmed_min_physical_link_rate; | ||
1381 | u8 programmed_max_physical_link_rate; | ||
1382 | u8 reserved_3[6]; | ||
1383 | }; | ||
1384 | |||
1385 | /* phy control reply structure */ | ||
1386 | struct phy_control_reply{ | ||
1387 | u8 smp_frame_type; /* 0x41 */ | ||
1388 | u8 function; /* 0x11 */ | ||
1389 | u8 function_result; | ||
1390 | u8 response_length; | ||
1391 | }; | ||
1392 | |||
1393 | #define SMP_PHY_CONTROL_LINK_RESET (0x01) | ||
1394 | #define SMP_PHY_CONTROL_HARD_RESET (0x02) | ||
1395 | #define SMP_PHY_CONTROL_DISABLE (0x03) | ||
1396 | |||
1397 | /** | ||
1398 | * _transport_expander_phy_control - expander phy control | ||
1399 | * @ioc: per adapter object | ||
1400 | * @phy: The sas phy object | ||
1401 | * | ||
1402 | * Returns 0 for success, non-zero for failure. | ||
1403 | * | ||
1404 | */ | ||
1405 | static int | ||
1406 | _transport_expander_phy_control(struct MPT2SAS_ADAPTER *ioc, | ||
1407 | struct sas_phy *phy, u8 phy_operation) | ||
1408 | { | ||
1409 | Mpi2SmpPassthroughRequest_t *mpi_request; | ||
1410 | Mpi2SmpPassthroughReply_t *mpi_reply; | ||
1411 | struct phy_control_request *phy_control_request; | ||
1412 | struct phy_control_reply *phy_control_reply; | ||
1413 | int rc; | ||
1414 | u16 smid; | ||
1415 | u32 ioc_state; | ||
1416 | unsigned long timeleft; | ||
1417 | void *psge; | ||
1418 | u32 sgl_flags; | ||
1419 | u8 issue_reset = 0; | ||
1420 | void *data_out = NULL; | ||
1421 | dma_addr_t data_out_dma; | ||
1422 | u32 sz; | ||
1423 | u16 wait_state_count; | ||
1424 | |||
1425 | if (ioc->shost_recovery) { | ||
1426 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", | ||
1427 | __func__, ioc->name); | ||
1428 | return -EFAULT; | ||
1429 | } | ||
1430 | |||
1431 | mutex_lock(&ioc->transport_cmds.mutex); | ||
1432 | |||
1433 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { | ||
1434 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", | ||
1435 | ioc->name, __func__); | ||
1436 | rc = -EAGAIN; | ||
1437 | goto out; | ||
1438 | } | ||
1439 | ioc->transport_cmds.status = MPT2_CMD_PENDING; | ||
1440 | |||
1441 | wait_state_count = 0; | ||
1442 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
1443 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
1444 | if (wait_state_count++ == 10) { | ||
1445 | printk(MPT2SAS_ERR_FMT | ||
1446 | "%s: failed due to ioc not operational\n", | ||
1447 | ioc->name, __func__); | ||
1448 | rc = -EFAULT; | ||
1449 | goto out; | ||
1450 | } | ||
1451 | ssleep(1); | ||
1452 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
1453 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
1454 | "operational state(count=%d)\n", ioc->name, | ||
1455 | __func__, wait_state_count); | ||
1456 | } | ||
1457 | if (wait_state_count) | ||
1458 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", | ||
1459 | ioc->name, __func__); | ||
1460 | |||
1461 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); | ||
1462 | if (!smid) { | ||
1463 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
1464 | ioc->name, __func__); | ||
1465 | rc = -EAGAIN; | ||
1466 | goto out; | ||
1467 | } | ||
1468 | |||
1469 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
1470 | ioc->transport_cmds.smid = smid; | ||
1471 | |||
1472 | sz = sizeof(struct phy_control_request) + | ||
1473 | sizeof(struct phy_control_reply); | ||
1474 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); | ||
1475 | if (!data_out) { | ||
1476 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, | ||
1477 | __LINE__, __func__); | ||
1478 | rc = -ENOMEM; | ||
1479 | mpt2sas_base_free_smid(ioc, smid); | ||
1480 | goto out; | ||
1481 | } | ||
1482 | |||
1483 | rc = -EINVAL; | ||
1484 | memset(data_out, 0, sz); | ||
1485 | phy_control_request = data_out; | ||
1486 | phy_control_request->smp_frame_type = 0x40; | ||
1487 | phy_control_request->function = 0x91; | ||
1488 | phy_control_request->request_length = 9; | ||
1489 | phy_control_request->allocated_response_length = 0; | ||
1490 | phy_control_request->phy_identifier = phy->number; | ||
1491 | phy_control_request->phy_operation = phy_operation; | ||
1492 | phy_control_request->programmed_min_physical_link_rate = | ||
1493 | phy->minimum_linkrate << 4; | ||
1494 | phy_control_request->programmed_max_physical_link_rate = | ||
1495 | phy->maximum_linkrate << 4; | ||
1496 | |||
1497 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); | ||
1498 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; | ||
1499 | mpi_request->PhysicalPort = 0xFF; | ||
1500 | mpi_request->VF_ID = 0; /* TODO */ | ||
1501 | mpi_request->VP_ID = 0; | ||
1502 | mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address); | ||
1503 | mpi_request->RequestDataLength = | ||
1504 | cpu_to_le16(sizeof(struct phy_error_log_request)); | ||
1505 | psge = &mpi_request->SGL; | ||
1506 | |||
1507 | /* WRITE sgel first */ | ||
1508 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
1509 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); | ||
1510 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
1511 | ioc->base_add_sg_single(psge, sgl_flags | | ||
1512 | sizeof(struct phy_control_request), data_out_dma); | ||
1513 | |||
1514 | /* incr sgel */ | ||
1515 | psge += ioc->sge_size; | ||
1516 | |||
1517 | /* READ sgel last */ | ||
1518 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
1519 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
1520 | MPI2_SGE_FLAGS_END_OF_LIST); | ||
1521 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
1522 | ioc->base_add_sg_single(psge, sgl_flags | | ||
1523 | sizeof(struct phy_control_reply), data_out_dma + | ||
1524 | sizeof(struct phy_control_request)); | ||
1525 | |||
1526 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - " | ||
1527 | "send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n", ioc->name, | ||
1528 | (unsigned long long)phy->identify.sas_address, phy->number, | ||
1529 | phy_operation)); | ||
1530 | |||
1531 | init_completion(&ioc->transport_cmds.done); | ||
1532 | mpt2sas_base_put_smid_default(ioc, smid); | ||
1533 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, | ||
1534 | 10*HZ); | ||
1535 | |||
1536 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { | ||
1537 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", | ||
1538 | ioc->name, __func__); | ||
1539 | _debug_dump_mf(mpi_request, | ||
1540 | sizeof(Mpi2SmpPassthroughRequest_t)/4); | ||
1541 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) | ||
1542 | issue_reset = 1; | ||
1543 | goto issue_host_reset; | ||
1544 | } | ||
1545 | |||
1546 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - " | ||
1547 | "complete\n", ioc->name)); | ||
1548 | |||
1549 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { | ||
1550 | |||
1551 | mpi_reply = ioc->transport_cmds.reply; | ||
1552 | |||
1553 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1554 | "phy_control - reply data transfer size(%d)\n", | ||
1555 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); | ||
1556 | |||
1557 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != | ||
1558 | sizeof(struct phy_control_reply)) | ||
1559 | goto out; | ||
1560 | |||
1561 | phy_control_reply = data_out + | ||
1562 | sizeof(struct phy_control_request); | ||
1563 | |||
1564 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1565 | "phy_control - function_result(%d)\n", | ||
1566 | ioc->name, phy_control_reply->function_result)); | ||
1567 | |||
1568 | rc = 0; | ||
1569 | } else | ||
1570 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
1571 | "phy_control - no reply\n", ioc->name)); | ||
1572 | |||
1573 | issue_host_reset: | ||
1574 | if (issue_reset) | ||
1575 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
1576 | FORCE_BIG_HAMMER); | ||
1577 | out: | ||
1578 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; | ||
1579 | if (data_out) | ||
1580 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); | ||
1581 | |||
1582 | mutex_unlock(&ioc->transport_cmds.mutex); | ||
1583 | return rc; | ||
1584 | } | ||
1585 | |||
1586 | /** | ||
1587 | * _transport_phy_reset - | ||
1588 | * @phy: The sas phy object | ||
1589 | * @hard_reset: | ||
1590 | * | ||
1591 | * Returns 0 for success, non-zero for failure. | ||
1592 | */ | ||
1593 | static int | ||
1594 | _transport_phy_reset(struct sas_phy *phy, int hard_reset) | ||
1595 | { | ||
1596 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); | ||
1597 | Mpi2SasIoUnitControlReply_t mpi_reply; | ||
1598 | Mpi2SasIoUnitControlRequest_t mpi_request; | ||
1599 | unsigned long flags; | ||
1600 | |||
1601 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
1602 | if (_transport_sas_node_find_by_sas_address(ioc, | ||
1603 | phy->identify.sas_address) == NULL) { | ||
1604 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1605 | return -EINVAL; | ||
1606 | } | ||
1607 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1608 | |||
1609 | /* handle expander phys */ | ||
1610 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) | ||
1611 | return _transport_expander_phy_control(ioc, phy, | ||
1612 | (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET : | ||
1613 | SMP_PHY_CONTROL_LINK_RESET); | ||
1614 | |||
1615 | /* handle hba phys */ | ||
1616 | memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlReply_t)); | ||
1617 | mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; | ||
1618 | mpi_request.Operation = hard_reset ? | ||
1619 | MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET; | ||
1620 | mpi_request.PhyNum = phy->number; | ||
1621 | |||
1622 | if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) { | ||
1623 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1624 | ioc->name, __FILE__, __LINE__, __func__); | ||
1625 | return -ENXIO; | ||
1626 | } | ||
1627 | |||
1628 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) | ||
1629 | printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" | ||
1630 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, | ||
1631 | phy->number, le16_to_cpu(mpi_reply.IOCStatus), | ||
1632 | le32_to_cpu(mpi_reply.IOCLogInfo)); | ||
1633 | |||
1634 | return 0; | ||
1635 | } | ||
1636 | |||
1637 | /** | ||
1638 | * _transport_phy_enable - enable/disable phys | ||
1639 | * @phy: The sas phy object | ||
1640 | * @enable: enable phy when true | ||
1641 | * | ||
1642 | * Only support sas_host direct attached phys. | ||
1643 | * Returns 0 for success, non-zero for failure. | ||
1644 | */ | ||
1645 | static int | ||
1646 | _transport_phy_enable(struct sas_phy *phy, int enable) | ||
1647 | { | ||
1648 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); | ||
1649 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | ||
1650 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; | ||
1651 | Mpi2ConfigReply_t mpi_reply; | ||
1652 | u16 ioc_status; | ||
1653 | u16 sz; | ||
1654 | int rc = 0; | ||
1655 | unsigned long flags; | ||
1656 | int i, discovery_active; | ||
1657 | |||
1658 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
1659 | if (_transport_sas_node_find_by_sas_address(ioc, | ||
1660 | phy->identify.sas_address) == NULL) { | ||
1661 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1662 | return -EINVAL; | ||
1663 | } | ||
1664 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1665 | |||
1666 | /* handle expander phys */ | ||
1667 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) | ||
1668 | return _transport_expander_phy_control(ioc, phy, | ||
1669 | (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET : | ||
1670 | SMP_PHY_CONTROL_DISABLE); | ||
1671 | |||
1672 | /* handle hba phys */ | ||
1673 | |||
1674 | /* read sas_iounit page 0 */ | ||
1675 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * | ||
1676 | sizeof(Mpi2SasIOUnit0PhyData_t)); | ||
1677 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); | ||
1678 | if (!sas_iounit_pg0) { | ||
1679 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1680 | ioc->name, __FILE__, __LINE__, __func__); | ||
1681 | rc = -ENOMEM; | ||
1682 | goto out; | ||
1683 | } | ||
1684 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, | ||
1685 | sas_iounit_pg0, sz))) { | ||
1686 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1687 | ioc->name, __FILE__, __LINE__, __func__); | ||
1688 | rc = -ENXIO; | ||
1689 | goto out; | ||
1690 | } | ||
1691 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1692 | MPI2_IOCSTATUS_MASK; | ||
1693 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
1694 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1695 | ioc->name, __FILE__, __LINE__, __func__); | ||
1696 | rc = -EIO; | ||
1697 | goto out; | ||
1698 | } | ||
1699 | |||
1700 | /* unable to enable/disable phys when when discovery is active */ | ||
1701 | for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) { | ||
1702 | if (sas_iounit_pg0->PhyData[i].PortFlags & | ||
1703 | MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) { | ||
1704 | printk(MPT2SAS_ERR_FMT "discovery is active on " | ||
1705 | "port = %d, phy = %d: unable to enable/disable " | ||
1706 | "phys, try again later!\n", ioc->name, | ||
1707 | sas_iounit_pg0->PhyData[i].Port, i); | ||
1708 | discovery_active = 1; | ||
1709 | } | ||
1710 | } | ||
1711 | |||
1712 | if (discovery_active) { | ||
1713 | rc = -EAGAIN; | ||
1714 | goto out; | ||
1715 | } | ||
1716 | |||
1717 | /* read sas_iounit page 1 */ | ||
1718 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | ||
1719 | sizeof(Mpi2SasIOUnit1PhyData_t)); | ||
1720 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | ||
1721 | if (!sas_iounit_pg1) { | ||
1722 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1723 | ioc->name, __FILE__, __LINE__, __func__); | ||
1724 | rc = -ENOMEM; | ||
1725 | goto out; | ||
1726 | } | ||
1727 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | ||
1728 | sas_iounit_pg1, sz))) { | ||
1729 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1730 | ioc->name, __FILE__, __LINE__, __func__); | ||
1731 | rc = -ENXIO; | ||
1732 | goto out; | ||
1733 | } | ||
1734 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1735 | MPI2_IOCSTATUS_MASK; | ||
1736 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
1737 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1738 | ioc->name, __FILE__, __LINE__, __func__); | ||
1739 | rc = -EIO; | ||
1740 | goto out; | ||
1741 | } | ||
1742 | /* copy Port/PortFlags/PhyFlags from page 0 */ | ||
1743 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { | ||
1744 | sas_iounit_pg1->PhyData[i].Port = | ||
1745 | sas_iounit_pg0->PhyData[i].Port; | ||
1746 | sas_iounit_pg1->PhyData[i].PortFlags = | ||
1747 | (sas_iounit_pg0->PhyData[i].PortFlags & | ||
1748 | MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG); | ||
1749 | sas_iounit_pg1->PhyData[i].PhyFlags = | ||
1750 | (sas_iounit_pg0->PhyData[i].PhyFlags & | ||
1751 | (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED + | ||
1752 | MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED)); | ||
1753 | } | ||
1754 | if (enable) | ||
1755 | sas_iounit_pg1->PhyData[phy->number].PhyFlags | ||
1756 | &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE; | ||
1757 | else | ||
1758 | sas_iounit_pg1->PhyData[phy->number].PhyFlags | ||
1759 | |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE; | ||
1760 | |||
1761 | mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz); | ||
1762 | |||
1763 | /* link reset */ | ||
1764 | if (enable) | ||
1765 | _transport_phy_reset(phy, 0); | ||
1766 | |||
1767 | out: | ||
1768 | kfree(sas_iounit_pg1); | ||
1769 | kfree(sas_iounit_pg0); | ||
1770 | return rc; | ||
1771 | } | ||
1772 | |||
1773 | /** | ||
1774 | * _transport_phy_speed - set phy min/max link rates | ||
1775 | * @phy: The sas phy object | ||
1776 | * @rates: rates defined in sas_phy_linkrates | ||
1777 | * | ||
1778 | * Only support sas_host direct attached phys. | ||
1779 | * Returns 0 for success, non-zero for failure. | ||
1780 | */ | ||
1781 | static int | ||
1782 | _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates) | ||
1783 | { | ||
1784 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); | ||
1785 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; | ||
1786 | Mpi2SasPhyPage0_t phy_pg0; | ||
1787 | Mpi2ConfigReply_t mpi_reply; | ||
1788 | u16 ioc_status; | ||
1789 | u16 sz; | ||
1790 | int i; | ||
1791 | int rc = 0; | ||
1792 | unsigned long flags; | ||
1793 | |||
1794 | spin_lock_irqsave(&ioc->sas_node_lock, flags); | ||
1795 | if (_transport_sas_node_find_by_sas_address(ioc, | ||
1796 | phy->identify.sas_address) == NULL) { | ||
1797 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1798 | return -EINVAL; | ||
1799 | } | ||
1800 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); | ||
1801 | |||
1802 | if (!rates->minimum_linkrate) | ||
1803 | rates->minimum_linkrate = phy->minimum_linkrate; | ||
1804 | else if (rates->minimum_linkrate < phy->minimum_linkrate_hw) | ||
1805 | rates->minimum_linkrate = phy->minimum_linkrate_hw; | ||
1806 | |||
1807 | if (!rates->maximum_linkrate) | ||
1808 | rates->maximum_linkrate = phy->maximum_linkrate; | ||
1809 | else if (rates->maximum_linkrate > phy->maximum_linkrate_hw) | ||
1810 | rates->maximum_linkrate = phy->maximum_linkrate_hw; | ||
1811 | |||
1812 | /* handle expander phys */ | ||
1813 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) { | ||
1814 | phy->minimum_linkrate = rates->minimum_linkrate; | ||
1815 | phy->maximum_linkrate = rates->maximum_linkrate; | ||
1816 | return _transport_expander_phy_control(ioc, phy, | ||
1817 | SMP_PHY_CONTROL_LINK_RESET); | ||
1818 | } | ||
1819 | |||
1820 | /* handle hba phys */ | ||
1821 | |||
1822 | /* sas_iounit page 1 */ | ||
1823 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * | ||
1824 | sizeof(Mpi2SasIOUnit1PhyData_t)); | ||
1825 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); | ||
1826 | if (!sas_iounit_pg1) { | ||
1827 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1828 | ioc->name, __FILE__, __LINE__, __func__); | ||
1829 | rc = -ENOMEM; | ||
1830 | goto out; | ||
1831 | } | ||
1832 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, | ||
1833 | sas_iounit_pg1, sz))) { | ||
1834 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1835 | ioc->name, __FILE__, __LINE__, __func__); | ||
1836 | rc = -ENXIO; | ||
1837 | goto out; | ||
1838 | } | ||
1839 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & | ||
1840 | MPI2_IOCSTATUS_MASK; | ||
1841 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { | ||
1842 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1843 | ioc->name, __FILE__, __LINE__, __func__); | ||
1844 | rc = -EIO; | ||
1845 | goto out; | ||
1846 | } | ||
1847 | |||
1848 | for (i = 0; i < ioc->sas_hba.num_phys; i++) { | ||
1849 | if (phy->number != i) { | ||
1850 | sas_iounit_pg1->PhyData[i].MaxMinLinkRate = | ||
1851 | (ioc->sas_hba.phy[i].phy->minimum_linkrate + | ||
1852 | (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4)); | ||
1853 | } else { | ||
1854 | sas_iounit_pg1->PhyData[i].MaxMinLinkRate = | ||
1855 | (rates->minimum_linkrate + | ||
1856 | (rates->maximum_linkrate << 4)); | ||
1857 | } | ||
1858 | } | ||
1859 | |||
1860 | if (mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, | ||
1861 | sz)) { | ||
1862 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", | ||
1863 | ioc->name, __FILE__, __LINE__, __func__); | ||
1864 | rc = -ENXIO; | ||
1865 | goto out; | ||
1866 | } | ||
1867 | |||
1868 | /* link reset */ | ||
1869 | _transport_phy_reset(phy, 0); | ||
1870 | |||
1871 | /* read phy page 0, then update the rates in the sas transport phy */ | ||
1872 | if (!mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, | ||
1873 | phy->number)) { | ||
1874 | phy->minimum_linkrate = _transport_convert_phy_link_rate( | ||
1875 | phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); | ||
1876 | phy->maximum_linkrate = _transport_convert_phy_link_rate( | ||
1877 | phy_pg0.ProgrammedLinkRate >> 4); | ||
1878 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( | ||
1879 | phy_pg0.NegotiatedLinkRate & | ||
1880 | MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); | ||
1881 | } | ||
1882 | |||
1883 | out: | ||
1884 | kfree(sas_iounit_pg1); | ||
1885 | return rc; | ||
1886 | } | ||
1887 | |||
1888 | |||
1889 | /** | ||
1890 | * _transport_smp_handler - transport portal for smp passthru | ||
1891 | * @shost: shost object | ||
1892 | * @rphy: sas transport rphy object | ||
1893 | * @req: | ||
1894 | * | ||
1895 | * This used primarily for smp_utils. | ||
1896 | * Example: | ||
1897 | * smp_rep_general /sys/class/bsg/expander-5:0 | ||
1898 | */ | ||
1899 | static int | ||
1900 | _transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, | ||
1901 | struct request *req) | ||
1902 | { | ||
1903 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); | ||
1904 | Mpi2SmpPassthroughRequest_t *mpi_request; | ||
1905 | Mpi2SmpPassthroughReply_t *mpi_reply; | ||
1906 | int rc; | ||
1907 | u16 smid; | ||
1908 | u32 ioc_state; | ||
1909 | unsigned long timeleft; | ||
1910 | void *psge; | ||
1911 | u32 sgl_flags; | ||
1912 | u8 issue_reset = 0; | ||
1913 | dma_addr_t dma_addr_in = 0; | ||
1914 | dma_addr_t dma_addr_out = 0; | ||
1915 | dma_addr_t pci_dma_in = 0; | ||
1916 | dma_addr_t pci_dma_out = 0; | ||
1917 | void *pci_addr_in = NULL; | ||
1918 | void *pci_addr_out = NULL; | ||
1919 | u16 wait_state_count; | ||
1920 | struct request *rsp = req->next_rq; | ||
1921 | struct bio_vec bvec; | ||
1922 | struct bvec_iter iter; | ||
1923 | |||
1924 | if (!rsp) { | ||
1925 | printk(MPT2SAS_ERR_FMT "%s: the smp response space is " | ||
1926 | "missing\n", ioc->name, __func__); | ||
1927 | return -EINVAL; | ||
1928 | } | ||
1929 | if (ioc->shost_recovery || ioc->pci_error_recovery) { | ||
1930 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", | ||
1931 | __func__, ioc->name); | ||
1932 | return -EFAULT; | ||
1933 | } | ||
1934 | |||
1935 | rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex); | ||
1936 | if (rc) | ||
1937 | return rc; | ||
1938 | |||
1939 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { | ||
1940 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", ioc->name, | ||
1941 | __func__); | ||
1942 | rc = -EAGAIN; | ||
1943 | goto out; | ||
1944 | } | ||
1945 | ioc->transport_cmds.status = MPT2_CMD_PENDING; | ||
1946 | |||
1947 | /* Check if the request is split across multiple segments */ | ||
1948 | if (bio_multiple_segments(req->bio)) { | ||
1949 | u32 offset = 0; | ||
1950 | |||
1951 | /* Allocate memory and copy the request */ | ||
1952 | pci_addr_out = pci_alloc_consistent(ioc->pdev, | ||
1953 | blk_rq_bytes(req), &pci_dma_out); | ||
1954 | if (!pci_addr_out) { | ||
1955 | printk(MPT2SAS_INFO_FMT "%s(): PCI Addr out = NULL\n", | ||
1956 | ioc->name, __func__); | ||
1957 | rc = -ENOMEM; | ||
1958 | goto out; | ||
1959 | } | ||
1960 | |||
1961 | bio_for_each_segment(bvec, req->bio, iter) { | ||
1962 | memcpy(pci_addr_out + offset, | ||
1963 | page_address(bvec.bv_page) + bvec.bv_offset, | ||
1964 | bvec.bv_len); | ||
1965 | offset += bvec.bv_len; | ||
1966 | } | ||
1967 | } else { | ||
1968 | dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), | ||
1969 | blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL); | ||
1970 | if (!dma_addr_out) { | ||
1971 | printk(MPT2SAS_INFO_FMT "%s(): DMA Addr out = NULL\n", | ||
1972 | ioc->name, __func__); | ||
1973 | rc = -ENOMEM; | ||
1974 | goto free_pci; | ||
1975 | } | ||
1976 | } | ||
1977 | |||
1978 | /* Check if the response needs to be populated across | ||
1979 | * multiple segments */ | ||
1980 | if (bio_multiple_segments(rsp->bio)) { | ||
1981 | pci_addr_in = pci_alloc_consistent(ioc->pdev, blk_rq_bytes(rsp), | ||
1982 | &pci_dma_in); | ||
1983 | if (!pci_addr_in) { | ||
1984 | printk(MPT2SAS_INFO_FMT "%s(): PCI Addr in = NULL\n", | ||
1985 | ioc->name, __func__); | ||
1986 | rc = -ENOMEM; | ||
1987 | goto unmap; | ||
1988 | } | ||
1989 | } else { | ||
1990 | dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), | ||
1991 | blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL); | ||
1992 | if (!dma_addr_in) { | ||
1993 | printk(MPT2SAS_INFO_FMT "%s(): DMA Addr in = NULL\n", | ||
1994 | ioc->name, __func__); | ||
1995 | rc = -ENOMEM; | ||
1996 | goto unmap; | ||
1997 | } | ||
1998 | } | ||
1999 | |||
2000 | wait_state_count = 0; | ||
2001 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
2002 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { | ||
2003 | if (wait_state_count++ == 10) { | ||
2004 | printk(MPT2SAS_ERR_FMT | ||
2005 | "%s: failed due to ioc not operational\n", | ||
2006 | ioc->name, __func__); | ||
2007 | rc = -EFAULT; | ||
2008 | goto unmap; | ||
2009 | } | ||
2010 | ssleep(1); | ||
2011 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); | ||
2012 | printk(MPT2SAS_INFO_FMT "%s: waiting for " | ||
2013 | "operational state(count=%d)\n", ioc->name, | ||
2014 | __func__, wait_state_count); | ||
2015 | } | ||
2016 | if (wait_state_count) | ||
2017 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", | ||
2018 | ioc->name, __func__); | ||
2019 | |||
2020 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); | ||
2021 | if (!smid) { | ||
2022 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", | ||
2023 | ioc->name, __func__); | ||
2024 | rc = -EAGAIN; | ||
2025 | goto unmap; | ||
2026 | } | ||
2027 | |||
2028 | rc = 0; | ||
2029 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); | ||
2030 | ioc->transport_cmds.smid = smid; | ||
2031 | |||
2032 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); | ||
2033 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; | ||
2034 | mpi_request->PhysicalPort = 0xFF; | ||
2035 | mpi_request->VF_ID = 0; /* TODO */ | ||
2036 | mpi_request->VP_ID = 0; | ||
2037 | mpi_request->SASAddress = (rphy) ? | ||
2038 | cpu_to_le64(rphy->identify.sas_address) : | ||
2039 | cpu_to_le64(ioc->sas_hba.sas_address); | ||
2040 | mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4); | ||
2041 | psge = &mpi_request->SGL; | ||
2042 | |||
2043 | /* WRITE sgel first */ | ||
2044 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
2045 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); | ||
2046 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
2047 | if (bio_multiple_segments(req->bio)) { | ||
2048 | ioc->base_add_sg_single(psge, sgl_flags | | ||
2049 | (blk_rq_bytes(req) - 4), pci_dma_out); | ||
2050 | } else { | ||
2051 | ioc->base_add_sg_single(psge, sgl_flags | | ||
2052 | (blk_rq_bytes(req) - 4), dma_addr_out); | ||
2053 | } | ||
2054 | |||
2055 | /* incr sgel */ | ||
2056 | psge += ioc->sge_size; | ||
2057 | |||
2058 | /* READ sgel last */ | ||
2059 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | | ||
2060 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | | ||
2061 | MPI2_SGE_FLAGS_END_OF_LIST); | ||
2062 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; | ||
2063 | if (bio_multiple_segments(rsp->bio)) { | ||
2064 | ioc->base_add_sg_single(psge, sgl_flags | | ||
2065 | (blk_rq_bytes(rsp) + 4), pci_dma_in); | ||
2066 | } else { | ||
2067 | ioc->base_add_sg_single(psge, sgl_flags | | ||
2068 | (blk_rq_bytes(rsp) + 4), dma_addr_in); | ||
2069 | } | ||
2070 | |||
2071 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - " | ||
2072 | "sending smp request\n", ioc->name, __func__)); | ||
2073 | |||
2074 | init_completion(&ioc->transport_cmds.done); | ||
2075 | mpt2sas_base_put_smid_default(ioc, smid); | ||
2076 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, | ||
2077 | 10*HZ); | ||
2078 | |||
2079 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { | ||
2080 | printk(MPT2SAS_ERR_FMT "%s : timeout\n", | ||
2081 | __func__, ioc->name); | ||
2082 | _debug_dump_mf(mpi_request, | ||
2083 | sizeof(Mpi2SmpPassthroughRequest_t)/4); | ||
2084 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) | ||
2085 | issue_reset = 1; | ||
2086 | goto issue_host_reset; | ||
2087 | } | ||
2088 | |||
2089 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - " | ||
2090 | "complete\n", ioc->name, __func__)); | ||
2091 | |||
2092 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { | ||
2093 | |||
2094 | mpi_reply = ioc->transport_cmds.reply; | ||
2095 | |||
2096 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2097 | "%s - reply data transfer size(%d)\n", | ||
2098 | ioc->name, __func__, | ||
2099 | le16_to_cpu(mpi_reply->ResponseDataLength))); | ||
2100 | |||
2101 | memcpy(req->sense, mpi_reply, sizeof(*mpi_reply)); | ||
2102 | req->sense_len = sizeof(*mpi_reply); | ||
2103 | req->resid_len = 0; | ||
2104 | rsp->resid_len -= | ||
2105 | le16_to_cpu(mpi_reply->ResponseDataLength); | ||
2106 | /* check if the resp needs to be copied from the allocated | ||
2107 | * pci mem */ | ||
2108 | if (bio_multiple_segments(rsp->bio)) { | ||
2109 | u32 offset = 0; | ||
2110 | u32 bytes_to_copy = | ||
2111 | le16_to_cpu(mpi_reply->ResponseDataLength); | ||
2112 | bio_for_each_segment(bvec, rsp->bio, iter) { | ||
2113 | if (bytes_to_copy <= bvec.bv_len) { | ||
2114 | memcpy(page_address(bvec.bv_page) + | ||
2115 | bvec.bv_offset, pci_addr_in + | ||
2116 | offset, bytes_to_copy); | ||
2117 | break; | ||
2118 | } else { | ||
2119 | memcpy(page_address(bvec.bv_page) + | ||
2120 | bvec.bv_offset, pci_addr_in + | ||
2121 | offset, bvec.bv_len); | ||
2122 | bytes_to_copy -= bvec.bv_len; | ||
2123 | } | ||
2124 | offset += bvec.bv_len; | ||
2125 | } | ||
2126 | } | ||
2127 | } else { | ||
2128 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT | ||
2129 | "%s - no reply\n", ioc->name, __func__)); | ||
2130 | rc = -ENXIO; | ||
2131 | } | ||
2132 | |||
2133 | issue_host_reset: | ||
2134 | if (issue_reset) { | ||
2135 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, | ||
2136 | FORCE_BIG_HAMMER); | ||
2137 | rc = -ETIMEDOUT; | ||
2138 | } | ||
2139 | |||
2140 | unmap: | ||
2141 | if (dma_addr_out) | ||
2142 | pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req), | ||
2143 | PCI_DMA_BIDIRECTIONAL); | ||
2144 | if (dma_addr_in) | ||
2145 | pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp), | ||
2146 | PCI_DMA_BIDIRECTIONAL); | ||
2147 | |||
2148 | free_pci: | ||
2149 | if (pci_addr_out) | ||
2150 | pci_free_consistent(ioc->pdev, blk_rq_bytes(req), pci_addr_out, | ||
2151 | pci_dma_out); | ||
2152 | |||
2153 | if (pci_addr_in) | ||
2154 | pci_free_consistent(ioc->pdev, blk_rq_bytes(rsp), pci_addr_in, | ||
2155 | pci_dma_in); | ||
2156 | |||
2157 | out: | ||
2158 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; | ||
2159 | mutex_unlock(&ioc->transport_cmds.mutex); | ||
2160 | return rc; | ||
2161 | } | ||
2162 | |||
2163 | struct sas_function_template mpt2sas_transport_functions = { | ||
2164 | .get_linkerrors = _transport_get_linkerrors, | ||
2165 | .get_enclosure_identifier = _transport_get_enclosure_identifier, | ||
2166 | .get_bay_identifier = _transport_get_bay_identifier, | ||
2167 | .phy_reset = _transport_phy_reset, | ||
2168 | .phy_enable = _transport_phy_enable, | ||
2169 | .set_phy_speed = _transport_phy_speed, | ||
2170 | .smp_handler = _transport_smp_handler, | ||
2171 | }; | ||
2172 | |||
2173 | struct scsi_transport_template *mpt2sas_transport_template; | ||