Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
792581de | 4 | * Copyright (C) 2004-2011 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
dea3101e | 21 | #include <linux/pci.h> |
5a0e3ad6 | 22 | #include <linux/slab.h> |
dea3101e | 23 | #include <linux/interrupt.h> |
a90f5684 | 24 | #include <linux/delay.h> |
e2a0a9d6 | 25 | #include <asm/unaligned.h> |
dea3101e | 26 | |
27 | #include <scsi/scsi.h> | |
28 | #include <scsi/scsi_device.h> | |
e2a0a9d6 | 29 | #include <scsi/scsi_eh.h> |
dea3101e | 30 | #include <scsi/scsi_host.h> |
31 | #include <scsi/scsi_tcq.h> | |
32 | #include <scsi/scsi_transport_fc.h> | |
33 | ||
34 | #include "lpfc_version.h" | |
da0436e9 | 35 | #include "lpfc_hw4.h" |
dea3101e | 36 | #include "lpfc_hw.h" |
37 | #include "lpfc_sli.h" | |
da0436e9 | 38 | #include "lpfc_sli4.h" |
ea2151b4 | 39 | #include "lpfc_nl.h" |
dea3101e | 40 | #include "lpfc_disc.h" |
41 | #include "lpfc_scsi.h" | |
42 | #include "lpfc.h" | |
43 | #include "lpfc_logmsg.h" | |
44 | #include "lpfc_crtn.h" | |
92d7f7b0 | 45 | #include "lpfc_vport.h" |
dea3101e | 46 | |
47 | #define LPFC_RESET_WAIT 2 | |
48 | #define LPFC_ABORT_WAIT 2 | |
49 | ||
e2a0a9d6 JS |
50 | int _dump_buf_done; |
51 | ||
52 | static char *dif_op_str[] = { | |
53 | "SCSI_PROT_NORMAL", | |
54 | "SCSI_PROT_READ_INSERT", | |
55 | "SCSI_PROT_WRITE_STRIP", | |
56 | "SCSI_PROT_READ_STRIP", | |
57 | "SCSI_PROT_WRITE_INSERT", | |
58 | "SCSI_PROT_READ_PASS", | |
59 | "SCSI_PROT_WRITE_PASS", | |
e2a0a9d6 | 60 | }; |
da0436e9 JS |
61 | static void |
62 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); | |
1c6f4ef5 JS |
63 | static void |
64 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); | |
e2a0a9d6 JS |
65 | |
66 | static void | |
6a9c52cf | 67 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
e2a0a9d6 JS |
68 | { |
69 | void *src, *dst; | |
70 | struct scatterlist *sgde = scsi_sglist(cmnd); | |
71 | ||
72 | if (!_dump_buf_data) { | |
6a9c52cf JS |
73 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
74 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", | |
e2a0a9d6 JS |
75 | __func__); |
76 | return; | |
77 | } | |
78 | ||
79 | ||
80 | if (!sgde) { | |
6a9c52cf JS |
81 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
82 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); | |
e2a0a9d6 JS |
83 | return; |
84 | } | |
85 | ||
86 | dst = (void *) _dump_buf_data; | |
87 | while (sgde) { | |
88 | src = sg_virt(sgde); | |
89 | memcpy(dst, src, sgde->length); | |
90 | dst += sgde->length; | |
91 | sgde = sg_next(sgde); | |
92 | } | |
93 | } | |
94 | ||
95 | static void | |
6a9c52cf | 96 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
e2a0a9d6 JS |
97 | { |
98 | void *src, *dst; | |
99 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); | |
100 | ||
101 | if (!_dump_buf_dif) { | |
6a9c52cf JS |
102 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
103 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", | |
e2a0a9d6 JS |
104 | __func__); |
105 | return; | |
106 | } | |
107 | ||
108 | if (!sgde) { | |
6a9c52cf JS |
109 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
110 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); | |
e2a0a9d6 JS |
111 | return; |
112 | } | |
113 | ||
114 | dst = _dump_buf_dif; | |
115 | while (sgde) { | |
116 | src = sg_virt(sgde); | |
117 | memcpy(dst, src, sgde->length); | |
118 | dst += sgde->length; | |
119 | sgde = sg_next(sgde); | |
120 | } | |
121 | } | |
122 | ||
f1126688 JS |
123 | /** |
124 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. | |
125 | * @phba: Pointer to HBA object. | |
126 | * @lpfc_cmd: lpfc scsi command object pointer. | |
127 | * | |
128 | * This function is called from the lpfc_prep_task_mgmt_cmd function to | |
129 | * set the last bit in the response sge entry. | |
130 | **/ | |
131 | static void | |
132 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, | |
133 | struct lpfc_scsi_buf *lpfc_cmd) | |
134 | { | |
135 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
136 | if (sgl) { | |
137 | sgl += 1; | |
138 | sgl->word2 = le32_to_cpu(sgl->word2); | |
139 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
140 | sgl->word2 = cpu_to_le32(sgl->word2); | |
141 | } | |
142 | } | |
143 | ||
ea2151b4 | 144 | /** |
3621a710 | 145 | * lpfc_update_stats - Update statistical data for the command completion |
ea2151b4 JS |
146 | * @phba: Pointer to HBA object. |
147 | * @lpfc_cmd: lpfc scsi command object pointer. | |
148 | * | |
149 | * This function is called when there is a command completion and this | |
150 | * function updates the statistical data for the command completion. | |
151 | **/ | |
152 | static void | |
153 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
154 | { | |
155 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; | |
156 | struct lpfc_nodelist *pnode = rdata->pnode; | |
157 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
158 | unsigned long flags; | |
159 | struct Scsi_Host *shost = cmd->device->host; | |
160 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
161 | unsigned long latency; | |
162 | int i; | |
163 | ||
164 | if (cmd->result) | |
165 | return; | |
166 | ||
9f1e1b50 JS |
167 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
168 | ||
ea2151b4 JS |
169 | spin_lock_irqsave(shost->host_lock, flags); |
170 | if (!vport->stat_data_enabled || | |
171 | vport->stat_data_blocked || | |
5989b8d4 | 172 | !pnode || |
ea2151b4 JS |
173 | !pnode->lat_data || |
174 | (phba->bucket_type == LPFC_NO_BUCKET)) { | |
175 | spin_unlock_irqrestore(shost->host_lock, flags); | |
176 | return; | |
177 | } | |
ea2151b4 JS |
178 | |
179 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { | |
180 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ | |
181 | phba->bucket_step; | |
9f1e1b50 JS |
182 | /* check array subscript bounds */ |
183 | if (i < 0) | |
184 | i = 0; | |
185 | else if (i >= LPFC_MAX_BUCKET_COUNT) | |
186 | i = LPFC_MAX_BUCKET_COUNT - 1; | |
ea2151b4 JS |
187 | } else { |
188 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) | |
189 | if (latency <= (phba->bucket_base + | |
190 | ((1<<i)*phba->bucket_step))) | |
191 | break; | |
192 | } | |
193 | ||
194 | pnode->lat_data[i].cmd_count++; | |
195 | spin_unlock_irqrestore(shost->host_lock, flags); | |
196 | } | |
197 | ||
ea2151b4 | 198 | /** |
3621a710 | 199 | * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event |
ea2151b4 JS |
200 | * @phba: Pointer to HBA context object. |
201 | * @vport: Pointer to vport object. | |
202 | * @ndlp: Pointer to FC node associated with the target. | |
203 | * @lun: Lun number of the scsi device. | |
204 | * @old_val: Old value of the queue depth. | |
205 | * @new_val: New value of the queue depth. | |
206 | * | |
207 | * This function sends an event to the mgmt application indicating | |
208 | * there is a change in the scsi device queue depth. | |
209 | **/ | |
210 | static void | |
211 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, | |
212 | struct lpfc_vport *vport, | |
213 | struct lpfc_nodelist *ndlp, | |
214 | uint32_t lun, | |
215 | uint32_t old_val, | |
216 | uint32_t new_val) | |
217 | { | |
218 | struct lpfc_fast_path_event *fast_path_evt; | |
219 | unsigned long flags; | |
220 | ||
221 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
222 | if (!fast_path_evt) | |
223 | return; | |
224 | ||
225 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = | |
226 | FC_REG_SCSI_EVENT; | |
227 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = | |
228 | LPFC_EVENT_VARQUEDEPTH; | |
229 | ||
230 | /* Report all luns with change in queue depth */ | |
231 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; | |
232 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | |
233 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, | |
234 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); | |
235 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, | |
236 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | |
237 | } | |
238 | ||
239 | fast_path_evt->un.queue_depth_evt.oldval = old_val; | |
240 | fast_path_evt->un.queue_depth_evt.newval = new_val; | |
241 | fast_path_evt->vport = vport; | |
242 | ||
243 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; | |
244 | spin_lock_irqsave(&phba->hbalock, flags); | |
245 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); | |
246 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
247 | lpfc_worker_wake_up(phba); | |
248 | ||
249 | return; | |
250 | } | |
251 | ||
5ffc266e JS |
252 | /** |
253 | * lpfc_change_queue_depth - Alter scsi device queue depth | |
254 | * @sdev: Pointer the scsi device on which to change the queue depth. | |
255 | * @qdepth: New queue depth to set the sdev to. | |
256 | * @reason: The reason for the queue depth change. | |
257 | * | |
258 | * This function is called by the midlayer and the LLD to alter the queue | |
259 | * depth for a scsi device. This function sets the queue depth to the new | |
260 | * value and sends an event out to log the queue depth change. | |
261 | **/ | |
262 | int | |
263 | lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) | |
264 | { | |
265 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; | |
266 | struct lpfc_hba *phba = vport->phba; | |
267 | struct lpfc_rport_data *rdata; | |
268 | unsigned long new_queue_depth, old_queue_depth; | |
269 | ||
270 | old_queue_depth = sdev->queue_depth; | |
271 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | |
272 | new_queue_depth = sdev->queue_depth; | |
273 | rdata = sdev->hostdata; | |
274 | if (rdata) | |
275 | lpfc_send_sdev_queuedepth_change_event(phba, vport, | |
276 | rdata->pnode, sdev->lun, | |
277 | old_queue_depth, | |
278 | new_queue_depth); | |
279 | return sdev->queue_depth; | |
280 | } | |
281 | ||
9bad7671 | 282 | /** |
3621a710 | 283 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
9bad7671 JS |
284 | * @phba: The Hba for which this call is being executed. |
285 | * | |
286 | * This routine is called when there is resource error in driver or firmware. | |
287 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine | |
288 | * posts at most 1 event each second. This routine wakes up worker thread of | |
289 | * @phba to process WORKER_RAM_DOWN_EVENT event. | |
290 | * | |
291 | * This routine should be called with no lock held. | |
292 | **/ | |
92d7f7b0 | 293 | void |
eaf15d5b | 294 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
92d7f7b0 JS |
295 | { |
296 | unsigned long flags; | |
5e9d9b82 | 297 | uint32_t evt_posted; |
92d7f7b0 JS |
298 | |
299 | spin_lock_irqsave(&phba->hbalock, flags); | |
300 | atomic_inc(&phba->num_rsrc_err); | |
301 | phba->last_rsrc_error_time = jiffies; | |
302 | ||
303 | if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) { | |
304 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
305 | return; | |
306 | } | |
307 | ||
308 | phba->last_ramp_down_time = jiffies; | |
309 | ||
310 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
311 | ||
312 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); | |
5e9d9b82 JS |
313 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
314 | if (!evt_posted) | |
92d7f7b0 | 315 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
92d7f7b0 JS |
316 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
317 | ||
5e9d9b82 JS |
318 | if (!evt_posted) |
319 | lpfc_worker_wake_up(phba); | |
92d7f7b0 JS |
320 | return; |
321 | } | |
322 | ||
9bad7671 | 323 | /** |
3621a710 | 324 | * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread |
9bad7671 JS |
325 | * @phba: The Hba for which this call is being executed. |
326 | * | |
327 | * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine | |
328 | * post at most 1 event every 5 minute after last_ramp_up_time or | |
329 | * last_rsrc_error_time. This routine wakes up worker thread of @phba | |
330 | * to process WORKER_RAM_DOWN_EVENT event. | |
331 | * | |
332 | * This routine should be called with no lock held. | |
333 | **/ | |
92d7f7b0 | 334 | static inline void |
3de2a653 | 335 | lpfc_rampup_queue_depth(struct lpfc_vport *vport, |
a257bf90 | 336 | uint32_t queue_depth) |
92d7f7b0 JS |
337 | { |
338 | unsigned long flags; | |
3de2a653 | 339 | struct lpfc_hba *phba = vport->phba; |
5e9d9b82 | 340 | uint32_t evt_posted; |
92d7f7b0 JS |
341 | atomic_inc(&phba->num_cmd_success); |
342 | ||
a257bf90 | 343 | if (vport->cfg_lun_queue_depth <= queue_depth) |
92d7f7b0 | 344 | return; |
92d7f7b0 | 345 | spin_lock_irqsave(&phba->hbalock, flags); |
5ffc266e JS |
346 | if (time_before(jiffies, |
347 | phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) || | |
348 | time_before(jiffies, | |
349 | phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) { | |
92d7f7b0 JS |
350 | spin_unlock_irqrestore(&phba->hbalock, flags); |
351 | return; | |
352 | } | |
92d7f7b0 JS |
353 | phba->last_ramp_up_time = jiffies; |
354 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
355 | ||
356 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); | |
5e9d9b82 JS |
357 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE; |
358 | if (!evt_posted) | |
92d7f7b0 | 359 | phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; |
92d7f7b0 JS |
360 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
361 | ||
5e9d9b82 JS |
362 | if (!evt_posted) |
363 | lpfc_worker_wake_up(phba); | |
364 | return; | |
92d7f7b0 JS |
365 | } |
366 | ||
9bad7671 | 367 | /** |
3621a710 | 368 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
9bad7671 JS |
369 | * @phba: The Hba for which this call is being executed. |
370 | * | |
371 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker | |
372 | * thread.This routine reduces queue depth for all scsi device on each vport | |
373 | * associated with @phba. | |
374 | **/ | |
92d7f7b0 JS |
375 | void |
376 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) | |
377 | { | |
549e55cd JS |
378 | struct lpfc_vport **vports; |
379 | struct Scsi_Host *shost; | |
92d7f7b0 | 380 | struct scsi_device *sdev; |
5ffc266e | 381 | unsigned long new_queue_depth; |
92d7f7b0 | 382 | unsigned long num_rsrc_err, num_cmd_success; |
549e55cd | 383 | int i; |
92d7f7b0 JS |
384 | |
385 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); | |
386 | num_cmd_success = atomic_read(&phba->num_cmd_success); | |
387 | ||
549e55cd JS |
388 | vports = lpfc_create_vport_work_array(phba); |
389 | if (vports != NULL) | |
21e9a0a5 | 390 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
391 | shost = lpfc_shost_from_vport(vports[i]); |
392 | shost_for_each_device(sdev, shost) { | |
92d7f7b0 | 393 | new_queue_depth = |
549e55cd JS |
394 | sdev->queue_depth * num_rsrc_err / |
395 | (num_rsrc_err + num_cmd_success); | |
396 | if (!new_queue_depth) | |
397 | new_queue_depth = sdev->queue_depth - 1; | |
398 | else | |
399 | new_queue_depth = sdev->queue_depth - | |
400 | new_queue_depth; | |
5ffc266e JS |
401 | lpfc_change_queue_depth(sdev, new_queue_depth, |
402 | SCSI_QDEPTH_DEFAULT); | |
549e55cd | 403 | } |
92d7f7b0 | 404 | } |
09372820 | 405 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 JS |
406 | atomic_set(&phba->num_rsrc_err, 0); |
407 | atomic_set(&phba->num_cmd_success, 0); | |
408 | } | |
409 | ||
9bad7671 | 410 | /** |
3621a710 | 411 | * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler |
9bad7671 JS |
412 | * @phba: The Hba for which this call is being executed. |
413 | * | |
414 | * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker | |
415 | * thread.This routine increases queue depth for all scsi device on each vport | |
416 | * associated with @phba by 1. This routine also sets @phba num_rsrc_err and | |
417 | * num_cmd_success to zero. | |
418 | **/ | |
92d7f7b0 JS |
419 | void |
420 | lpfc_ramp_up_queue_handler(struct lpfc_hba *phba) | |
421 | { | |
549e55cd JS |
422 | struct lpfc_vport **vports; |
423 | struct Scsi_Host *shost; | |
92d7f7b0 | 424 | struct scsi_device *sdev; |
549e55cd JS |
425 | int i; |
426 | ||
427 | vports = lpfc_create_vport_work_array(phba); | |
428 | if (vports != NULL) | |
21e9a0a5 | 429 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
430 | shost = lpfc_shost_from_vport(vports[i]); |
431 | shost_for_each_device(sdev, shost) { | |
97eab634 JS |
432 | if (vports[i]->cfg_lun_queue_depth <= |
433 | sdev->queue_depth) | |
434 | continue; | |
5ffc266e JS |
435 | lpfc_change_queue_depth(sdev, |
436 | sdev->queue_depth+1, | |
437 | SCSI_QDEPTH_RAMP_UP); | |
549e55cd | 438 | } |
92d7f7b0 | 439 | } |
09372820 | 440 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 JS |
441 | atomic_set(&phba->num_rsrc_err, 0); |
442 | atomic_set(&phba->num_cmd_success, 0); | |
443 | } | |
444 | ||
a8e497d5 | 445 | /** |
3621a710 | 446 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
a8e497d5 JS |
447 | * @phba: Pointer to HBA context object. |
448 | * | |
449 | * This function walks vport list and set each SCSI host to block state | |
450 | * by invoking fc_remote_port_delete() routine. This function is invoked | |
451 | * with EEH when device's PCI slot has been permanently disabled. | |
452 | **/ | |
453 | void | |
454 | lpfc_scsi_dev_block(struct lpfc_hba *phba) | |
455 | { | |
456 | struct lpfc_vport **vports; | |
457 | struct Scsi_Host *shost; | |
458 | struct scsi_device *sdev; | |
459 | struct fc_rport *rport; | |
460 | int i; | |
461 | ||
462 | vports = lpfc_create_vport_work_array(phba); | |
463 | if (vports != NULL) | |
21e9a0a5 | 464 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8e497d5 JS |
465 | shost = lpfc_shost_from_vport(vports[i]); |
466 | shost_for_each_device(sdev, shost) { | |
467 | rport = starget_to_rport(scsi_target(sdev)); | |
468 | fc_remote_port_delete(rport); | |
469 | } | |
470 | } | |
471 | lpfc_destroy_vport_work_array(phba, vports); | |
472 | } | |
473 | ||
9bad7671 | 474 | /** |
3772a991 | 475 | * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec |
9bad7671 | 476 | * @vport: The virtual port for which this call being executed. |
3772a991 | 477 | * @num_to_allocate: The requested number of buffers to allocate. |
9bad7671 | 478 | * |
3772a991 JS |
479 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
480 | * the scsi buffer contains all the necessary information needed to initiate | |
481 | * a SCSI I/O. The non-DMAable buffer region contains information to build | |
482 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, | |
483 | * and the initial BPL. In addition to allocating memory, the FCP CMND and | |
484 | * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB. | |
9bad7671 JS |
485 | * |
486 | * Return codes: | |
3772a991 JS |
487 | * int - number of scsi buffers that were allocated. |
488 | * 0 = failure, less than num_to_alloc is a partial failure. | |
9bad7671 | 489 | **/ |
3772a991 JS |
490 | static int |
491 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) | |
dea3101e | 492 | { |
2e0fef85 | 493 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 494 | struct lpfc_scsi_buf *psb; |
495 | struct ulp_bde64 *bpl; | |
496 | IOCB_t *iocb; | |
34b02dcd JS |
497 | dma_addr_t pdma_phys_fcp_cmd; |
498 | dma_addr_t pdma_phys_fcp_rsp; | |
499 | dma_addr_t pdma_phys_bpl; | |
604a3e30 | 500 | uint16_t iotag; |
3772a991 | 501 | int bcnt; |
dea3101e | 502 | |
3772a991 JS |
503 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
504 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | |
505 | if (!psb) | |
506 | break; | |
dea3101e | 507 | |
3772a991 JS |
508 | /* |
509 | * Get memory from the pci pool to map the virt space to pci | |
510 | * bus space for an I/O. The DMA buffer includes space for the | |
511 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's | |
512 | * necessary to support the sg_tablesize. | |
513 | */ | |
514 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, | |
515 | GFP_KERNEL, &psb->dma_handle); | |
516 | if (!psb->data) { | |
517 | kfree(psb); | |
518 | break; | |
519 | } | |
520 | ||
521 | /* Initialize virtual ptrs to dma_buf region. */ | |
522 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); | |
523 | ||
524 | /* Allocate iotag for psb->cur_iocbq. */ | |
525 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | |
526 | if (iotag == 0) { | |
527 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, | |
528 | psb->data, psb->dma_handle); | |
529 | kfree(psb); | |
530 | break; | |
531 | } | |
532 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; | |
533 | ||
534 | psb->fcp_cmnd = psb->data; | |
535 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); | |
536 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + | |
34b02dcd | 537 | sizeof(struct fcp_rsp); |
dea3101e | 538 | |
3772a991 JS |
539 | /* Initialize local short-hand pointers. */ |
540 | bpl = psb->fcp_bpl; | |
541 | pdma_phys_fcp_cmd = psb->dma_handle; | |
542 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); | |
543 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + | |
544 | sizeof(struct fcp_rsp); | |
545 | ||
546 | /* | |
547 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance | |
548 | * are sg list bdes. Initialize the first two and leave the | |
549 | * rest for queuecommand. | |
550 | */ | |
551 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); | |
552 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); | |
553 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); | |
554 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
555 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); | |
556 | ||
557 | /* Setup the physical region for the FCP RSP */ | |
558 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); | |
559 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); | |
560 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); | |
561 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
562 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); | |
563 | ||
564 | /* | |
565 | * Since the IOCB for the FCP I/O is built into this | |
566 | * lpfc_scsi_buf, initialize it with all known data now. | |
567 | */ | |
568 | iocb = &psb->cur_iocbq.iocb; | |
569 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | |
570 | if ((phba->sli_rev == 3) && | |
571 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { | |
572 | /* fill in immediate fcp command BDE */ | |
573 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; | |
574 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | |
575 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, | |
576 | unsli3.fcp_ext.icd); | |
577 | iocb->un.fcpi64.bdl.addrHigh = 0; | |
578 | iocb->ulpBdeCount = 0; | |
579 | iocb->ulpLe = 0; | |
25985edc | 580 | /* fill in response BDE */ |
3772a991 JS |
581 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
582 | BUFF_TYPE_BDE_64; | |
583 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = | |
584 | sizeof(struct fcp_rsp); | |
585 | iocb->unsli3.fcp_ext.rbde.addrLow = | |
586 | putPaddrLow(pdma_phys_fcp_rsp); | |
587 | iocb->unsli3.fcp_ext.rbde.addrHigh = | |
588 | putPaddrHigh(pdma_phys_fcp_rsp); | |
589 | } else { | |
590 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
591 | iocb->un.fcpi64.bdl.bdeSize = | |
592 | (2 * sizeof(struct ulp_bde64)); | |
593 | iocb->un.fcpi64.bdl.addrLow = | |
594 | putPaddrLow(pdma_phys_bpl); | |
595 | iocb->un.fcpi64.bdl.addrHigh = | |
596 | putPaddrHigh(pdma_phys_bpl); | |
597 | iocb->ulpBdeCount = 1; | |
598 | iocb->ulpLe = 1; | |
599 | } | |
600 | iocb->ulpClass = CLASS3; | |
601 | psb->status = IOSTAT_SUCCESS; | |
da0436e9 | 602 | /* Put it back into the SCSI buffer list */ |
eee8877e | 603 | psb->cur_iocbq.context1 = psb; |
1c6f4ef5 | 604 | lpfc_release_scsi_buf_s3(phba, psb); |
dea3101e | 605 | |
34b02dcd | 606 | } |
dea3101e | 607 | |
3772a991 | 608 | return bcnt; |
dea3101e | 609 | } |
610 | ||
1151e3ec JS |
611 | /** |
612 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport | |
613 | * @vport: pointer to lpfc vport data structure. | |
614 | * | |
615 | * This routine is invoked by the vport cleanup for deletions and the cleanup | |
616 | * for an ndlp on removal. | |
617 | **/ | |
618 | void | |
619 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) | |
620 | { | |
621 | struct lpfc_hba *phba = vport->phba; | |
622 | struct lpfc_scsi_buf *psb, *next_psb; | |
623 | unsigned long iflag = 0; | |
624 | ||
625 | spin_lock_irqsave(&phba->hbalock, iflag); | |
626 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
627 | list_for_each_entry_safe(psb, next_psb, | |
628 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { | |
629 | if (psb->rdata && psb->rdata->pnode | |
630 | && psb->rdata->pnode->vport == vport) | |
631 | psb->rdata = NULL; | |
632 | } | |
633 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
634 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
635 | } | |
636 | ||
da0436e9 JS |
637 | /** |
638 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort | |
639 | * @phba: pointer to lpfc hba data structure. | |
640 | * @axri: pointer to the fcp xri abort wcqe structure. | |
641 | * | |
642 | * This routine is invoked by the worker thread to process a SLI4 fast-path | |
643 | * FCP aborted xri. | |
644 | **/ | |
645 | void | |
646 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, | |
647 | struct sli4_wcqe_xri_aborted *axri) | |
648 | { | |
649 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); | |
19ca7609 | 650 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
da0436e9 JS |
651 | struct lpfc_scsi_buf *psb, *next_psb; |
652 | unsigned long iflag = 0; | |
0f65ff68 JS |
653 | struct lpfc_iocbq *iocbq; |
654 | int i; | |
19ca7609 JS |
655 | struct lpfc_nodelist *ndlp; |
656 | int rrq_empty = 0; | |
589a52d6 | 657 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
da0436e9 | 658 | |
0f65ff68 JS |
659 | spin_lock_irqsave(&phba->hbalock, iflag); |
660 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
da0436e9 JS |
661 | list_for_each_entry_safe(psb, next_psb, |
662 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { | |
663 | if (psb->cur_iocbq.sli4_xritag == xri) { | |
664 | list_del(&psb->list); | |
341af102 | 665 | psb->exch_busy = 0; |
da0436e9 | 666 | psb->status = IOSTAT_SUCCESS; |
0f65ff68 JS |
667 | spin_unlock( |
668 | &phba->sli4_hba.abts_scsi_buf_list_lock); | |
1151e3ec JS |
669 | if (psb->rdata && psb->rdata->pnode) |
670 | ndlp = psb->rdata->pnode; | |
671 | else | |
672 | ndlp = NULL; | |
673 | ||
19ca7609 | 674 | rrq_empty = list_empty(&phba->active_rrq_list); |
0f65ff68 | 675 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
19ca7609 JS |
676 | if (ndlp) |
677 | lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1); | |
da0436e9 | 678 | lpfc_release_scsi_buf_s4(phba, psb); |
19ca7609 JS |
679 | if (rrq_empty) |
680 | lpfc_worker_wake_up(phba); | |
da0436e9 JS |
681 | return; |
682 | } | |
683 | } | |
0f65ff68 JS |
684 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
685 | for (i = 1; i <= phba->sli.last_iotag; i++) { | |
686 | iocbq = phba->sli.iocbq_lookup[i]; | |
687 | ||
688 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || | |
689 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
690 | continue; | |
691 | if (iocbq->sli4_xritag != xri) | |
692 | continue; | |
693 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); | |
694 | psb->exch_busy = 0; | |
695 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
589a52d6 JS |
696 | if (pring->txq_cnt) |
697 | lpfc_worker_wake_up(phba); | |
0f65ff68 JS |
698 | return; |
699 | ||
700 | } | |
701 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
da0436e9 JS |
702 | } |
703 | ||
704 | /** | |
705 | * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block | |
706 | * @phba: pointer to lpfc hba data structure. | |
707 | * | |
708 | * This routine walks the list of scsi buffers that have been allocated and | |
709 | * repost them to the HBA by using SGL block post. This is needed after a | |
710 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine | |
711 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list | |
712 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. | |
713 | * | |
714 | * Returns: 0 = success, non-zero failure. | |
715 | **/ | |
716 | int | |
717 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) | |
718 | { | |
719 | struct lpfc_scsi_buf *psb; | |
720 | int index, status, bcnt = 0, rcnt = 0, rc = 0; | |
721 | LIST_HEAD(sblist); | |
722 | ||
723 | for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) { | |
724 | psb = phba->sli4_hba.lpfc_scsi_psb_array[index]; | |
725 | if (psb) { | |
726 | /* Remove from SCSI buffer list */ | |
727 | list_del(&psb->list); | |
728 | /* Add it to a local SCSI buffer list */ | |
729 | list_add_tail(&psb->list, &sblist); | |
730 | if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
731 | bcnt = rcnt; | |
732 | rcnt = 0; | |
733 | } | |
734 | } else | |
735 | /* A hole present in the XRI array, need to skip */ | |
736 | bcnt = rcnt; | |
737 | ||
738 | if (index == phba->sli4_hba.scsi_xri_cnt - 1) | |
739 | /* End of XRI array for SCSI buffer, complete */ | |
740 | bcnt = rcnt; | |
741 | ||
742 | /* Continue until collect up to a nembed page worth of sgls */ | |
743 | if (bcnt == 0) | |
744 | continue; | |
745 | /* Now, post the SCSI buffer list sgls as a block */ | |
6d368e53 JS |
746 | if (!phba->sli4_hba.extents_in_use) |
747 | status = lpfc_sli4_post_scsi_sgl_block(phba, | |
748 | &sblist, | |
749 | bcnt); | |
750 | else | |
751 | status = lpfc_sli4_post_scsi_sgl_blk_ext(phba, | |
752 | &sblist, | |
753 | bcnt); | |
da0436e9 JS |
754 | /* Reset SCSI buffer count for next round of posting */ |
755 | bcnt = 0; | |
756 | while (!list_empty(&sblist)) { | |
757 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, | |
758 | list); | |
759 | if (status) { | |
760 | /* Put this back on the abort scsi list */ | |
341af102 | 761 | psb->exch_busy = 1; |
da0436e9 | 762 | rc++; |
341af102 JS |
763 | } else { |
764 | psb->exch_busy = 0; | |
da0436e9 | 765 | psb->status = IOSTAT_SUCCESS; |
341af102 | 766 | } |
da0436e9 JS |
767 | /* Put it back into the SCSI buffer list */ |
768 | lpfc_release_scsi_buf_s4(phba, psb); | |
769 | } | |
770 | } | |
771 | return rc; | |
772 | } | |
773 | ||
774 | /** | |
775 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec | |
776 | * @vport: The virtual port for which this call being executed. | |
777 | * @num_to_allocate: The requested number of buffers to allocate. | |
778 | * | |
779 | * This routine allocates a scsi buffer for device with SLI-4 interface spec, | |
780 | * the scsi buffer contains all the necessary information needed to initiate | |
781 | * a SCSI I/O. | |
782 | * | |
783 | * Return codes: | |
784 | * int - number of scsi buffers that were allocated. | |
785 | * 0 = failure, less than num_to_alloc is a partial failure. | |
786 | **/ | |
787 | static int | |
788 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) | |
789 | { | |
790 | struct lpfc_hba *phba = vport->phba; | |
791 | struct lpfc_scsi_buf *psb; | |
792 | struct sli4_sge *sgl; | |
793 | IOCB_t *iocb; | |
794 | dma_addr_t pdma_phys_fcp_cmd; | |
795 | dma_addr_t pdma_phys_fcp_rsp; | |
796 | dma_addr_t pdma_phys_bpl, pdma_phys_bpl1; | |
6d368e53 | 797 | uint16_t iotag, last_xritag = NO_XRI, lxri = 0; |
da0436e9 JS |
798 | int status = 0, index; |
799 | int bcnt; | |
800 | int non_sequential_xri = 0; | |
da0436e9 JS |
801 | LIST_HEAD(sblist); |
802 | ||
803 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { | |
804 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | |
805 | if (!psb) | |
806 | break; | |
807 | ||
808 | /* | |
809 | * Get memory from the pci pool to map the virt space to pci bus | |
810 | * space for an I/O. The DMA buffer includes space for the | |
811 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's | |
812 | * necessary to support the sg_tablesize. | |
813 | */ | |
814 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, | |
815 | GFP_KERNEL, &psb->dma_handle); | |
816 | if (!psb->data) { | |
817 | kfree(psb); | |
818 | break; | |
819 | } | |
820 | ||
821 | /* Initialize virtual ptrs to dma_buf region. */ | |
822 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); | |
823 | ||
824 | /* Allocate iotag for psb->cur_iocbq. */ | |
825 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | |
826 | if (iotag == 0) { | |
b92938b4 JS |
827 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
828 | psb->data, psb->dma_handle); | |
da0436e9 JS |
829 | kfree(psb); |
830 | break; | |
831 | } | |
832 | ||
6d368e53 JS |
833 | lxri = lpfc_sli4_next_xritag(phba); |
834 | if (lxri == NO_XRI) { | |
da0436e9 JS |
835 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
836 | psb->data, psb->dma_handle); | |
837 | kfree(psb); | |
838 | break; | |
839 | } | |
6d368e53 JS |
840 | psb->cur_iocbq.sli4_lxritag = lxri; |
841 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
da0436e9 JS |
842 | if (last_xritag != NO_XRI |
843 | && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) { | |
844 | non_sequential_xri = 1; | |
845 | } else | |
846 | list_add_tail(&psb->list, &sblist); | |
847 | last_xritag = psb->cur_iocbq.sli4_xritag; | |
848 | ||
849 | index = phba->sli4_hba.scsi_xri_cnt++; | |
850 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; | |
851 | ||
852 | psb->fcp_bpl = psb->data; | |
853 | psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size) | |
854 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
855 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + | |
856 | sizeof(struct fcp_cmnd)); | |
857 | ||
858 | /* Initialize local short-hand pointers. */ | |
859 | sgl = (struct sli4_sge *)psb->fcp_bpl; | |
860 | pdma_phys_bpl = psb->dma_handle; | |
861 | pdma_phys_fcp_cmd = | |
862 | (psb->dma_handle + phba->cfg_sg_dma_buf_size) | |
863 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
864 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); | |
865 | ||
866 | /* | |
867 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance | |
868 | * are sg list bdes. Initialize the first two and leave the | |
869 | * rest for queuecommand. | |
870 | */ | |
871 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); | |
872 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); | |
0558056c | 873 | sgl->word2 = le32_to_cpu(sgl->word2); |
da0436e9 JS |
874 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
875 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 | 876 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
da0436e9 JS |
877 | sgl++; |
878 | ||
879 | /* Setup the physical region for the FCP RSP */ | |
880 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); | |
881 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); | |
0558056c | 882 | sgl->word2 = le32_to_cpu(sgl->word2); |
da0436e9 JS |
883 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
884 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 | 885 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
da0436e9 JS |
886 | |
887 | /* | |
888 | * Since the IOCB for the FCP I/O is built into this | |
889 | * lpfc_scsi_buf, initialize it with all known data now. | |
890 | */ | |
891 | iocb = &psb->cur_iocbq.iocb; | |
892 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | |
893 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; | |
894 | /* setting the BLP size to 2 * sizeof BDE may not be correct. | |
895 | * We are setting the bpl to point to out sgl. An sgl's | |
896 | * entries are 16 bytes, a bpl entries are 12 bytes. | |
897 | */ | |
898 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | |
899 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); | |
900 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); | |
901 | iocb->ulpBdeCount = 1; | |
902 | iocb->ulpLe = 1; | |
903 | iocb->ulpClass = CLASS3; | |
eee8877e | 904 | psb->cur_iocbq.context1 = psb; |
da0436e9 JS |
905 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
906 | pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE; | |
907 | else | |
908 | pdma_phys_bpl1 = 0; | |
909 | psb->dma_phys_bpl = pdma_phys_bpl; | |
910 | phba->sli4_hba.lpfc_scsi_psb_array[index] = psb; | |
911 | if (non_sequential_xri) { | |
912 | status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl, | |
913 | pdma_phys_bpl1, | |
914 | psb->cur_iocbq.sli4_xritag); | |
915 | if (status) { | |
916 | /* Put this back on the abort scsi list */ | |
341af102 | 917 | psb->exch_busy = 1; |
341af102 JS |
918 | } else { |
919 | psb->exch_busy = 0; | |
da0436e9 | 920 | psb->status = IOSTAT_SUCCESS; |
341af102 | 921 | } |
da0436e9 JS |
922 | /* Put it back into the SCSI buffer list */ |
923 | lpfc_release_scsi_buf_s4(phba, psb); | |
924 | break; | |
925 | } | |
926 | } | |
927 | if (bcnt) { | |
6d368e53 JS |
928 | if (!phba->sli4_hba.extents_in_use) |
929 | status = lpfc_sli4_post_scsi_sgl_block(phba, | |
930 | &sblist, | |
931 | bcnt); | |
932 | else | |
933 | status = lpfc_sli4_post_scsi_sgl_blk_ext(phba, | |
934 | &sblist, | |
935 | bcnt); | |
936 | ||
937 | if (status) { | |
938 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
939 | "3021 SCSI SGL post error %d\n", | |
940 | status); | |
941 | bcnt = 0; | |
942 | } | |
da0436e9 JS |
943 | /* Reset SCSI buffer count for next round of posting */ |
944 | while (!list_empty(&sblist)) { | |
945 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, | |
946 | list); | |
947 | if (status) { | |
948 | /* Put this back on the abort scsi list */ | |
341af102 | 949 | psb->exch_busy = 1; |
341af102 JS |
950 | } else { |
951 | psb->exch_busy = 0; | |
da0436e9 | 952 | psb->status = IOSTAT_SUCCESS; |
341af102 | 953 | } |
da0436e9 JS |
954 | /* Put it back into the SCSI buffer list */ |
955 | lpfc_release_scsi_buf_s4(phba, psb); | |
956 | } | |
957 | } | |
958 | ||
d7c47992 | 959 | return bcnt + non_sequential_xri; |
da0436e9 JS |
960 | } |
961 | ||
9bad7671 | 962 | /** |
3772a991 JS |
963 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
964 | * @vport: The virtual port for which this call being executed. | |
965 | * @num_to_allocate: The requested number of buffers to allocate. | |
966 | * | |
967 | * This routine wraps the actual SCSI buffer allocator function pointer from | |
968 | * the lpfc_hba struct. | |
969 | * | |
970 | * Return codes: | |
971 | * int - number of scsi buffers that were allocated. | |
972 | * 0 = failure, less than num_to_alloc is a partial failure. | |
973 | **/ | |
974 | static inline int | |
975 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) | |
976 | { | |
977 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); | |
978 | } | |
979 | ||
980 | /** | |
19ca7609 | 981 | * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
3772a991 | 982 | * @phba: The HBA for which this call is being executed. |
9bad7671 JS |
983 | * |
984 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
985 | * and returns to caller. | |
986 | * | |
987 | * Return codes: | |
988 | * NULL - Error | |
989 | * Pointer to lpfc_scsi_buf - Success | |
990 | **/ | |
455c53ec | 991 | static struct lpfc_scsi_buf* |
19ca7609 | 992 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
dea3101e | 993 | { |
0bd4ca25 JSEC |
994 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
995 | struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list; | |
875fbdfe | 996 | unsigned long iflag = 0; |
0bd4ca25 | 997 | |
875fbdfe | 998 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
0bd4ca25 | 999 | list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list); |
1dcb58e5 JS |
1000 | if (lpfc_cmd) { |
1001 | lpfc_cmd->seg_cnt = 0; | |
1002 | lpfc_cmd->nonsg_phys = 0; | |
e2a0a9d6 | 1003 | lpfc_cmd->prot_seg_cnt = 0; |
1dcb58e5 | 1004 | } |
875fbdfe | 1005 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
0bd4ca25 JSEC |
1006 | return lpfc_cmd; |
1007 | } | |
19ca7609 JS |
1008 | /** |
1009 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA | |
1010 | * @phba: The HBA for which this call is being executed. | |
1011 | * | |
1012 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
1013 | * and returns to caller. | |
1014 | * | |
1015 | * Return codes: | |
1016 | * NULL - Error | |
1017 | * Pointer to lpfc_scsi_buf - Success | |
1018 | **/ | |
1019 | static struct lpfc_scsi_buf* | |
1020 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) | |
1021 | { | |
1151e3ec | 1022 | struct lpfc_scsi_buf *lpfc_cmd ; |
19ca7609 JS |
1023 | unsigned long iflag = 0; |
1024 | int found = 0; | |
1025 | ||
1026 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
1151e3ec JS |
1027 | list_for_each_entry(lpfc_cmd, &phba->lpfc_scsi_buf_list, |
1028 | list) { | |
19ca7609 | 1029 | if (lpfc_test_rrq_active(phba, ndlp, |
1151e3ec JS |
1030 | lpfc_cmd->cur_iocbq.sli4_xritag)) |
1031 | continue; | |
1032 | list_del(&lpfc_cmd->list); | |
19ca7609 JS |
1033 | found = 1; |
1034 | lpfc_cmd->seg_cnt = 0; | |
1035 | lpfc_cmd->nonsg_phys = 0; | |
1036 | lpfc_cmd->prot_seg_cnt = 0; | |
1151e3ec | 1037 | break; |
19ca7609 | 1038 | } |
1151e3ec JS |
1039 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, |
1040 | iflag); | |
1041 | if (!found) | |
1042 | return NULL; | |
1043 | else | |
1044 | return lpfc_cmd; | |
19ca7609 JS |
1045 | } |
1046 | /** | |
1047 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA | |
1048 | * @phba: The HBA for which this call is being executed. | |
1049 | * | |
1050 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
1051 | * and returns to caller. | |
1052 | * | |
1053 | * Return codes: | |
1054 | * NULL - Error | |
1055 | * Pointer to lpfc_scsi_buf - Success | |
1056 | **/ | |
1057 | static struct lpfc_scsi_buf* | |
1058 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) | |
1059 | { | |
1060 | return phba->lpfc_get_scsi_buf(phba, ndlp); | |
1061 | } | |
dea3101e | 1062 | |
9bad7671 | 1063 | /** |
3772a991 | 1064 | * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list |
9bad7671 JS |
1065 | * @phba: The Hba for which this call is being executed. |
1066 | * @psb: The scsi buffer which is being released. | |
1067 | * | |
1068 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
1069 | * lpfc_scsi_buf_list list. | |
1070 | **/ | |
0bd4ca25 | 1071 | static void |
3772a991 | 1072 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
0bd4ca25 | 1073 | { |
875fbdfe | 1074 | unsigned long iflag = 0; |
dea3101e | 1075 | |
875fbdfe | 1076 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
0bd4ca25 | 1077 | psb->pCmd = NULL; |
dea3101e | 1078 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
875fbdfe | 1079 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
dea3101e | 1080 | } |
1081 | ||
da0436e9 JS |
1082 | /** |
1083 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. | |
1084 | * @phba: The Hba for which this call is being executed. | |
1085 | * @psb: The scsi buffer which is being released. | |
1086 | * | |
1087 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
1088 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer | |
1089 | * and cannot be reused for at least RA_TOV amount of time if it was | |
1090 | * aborted. | |
1091 | **/ | |
1092 | static void | |
1093 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |
1094 | { | |
1095 | unsigned long iflag = 0; | |
1096 | ||
341af102 | 1097 | if (psb->exch_busy) { |
da0436e9 JS |
1098 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
1099 | iflag); | |
1100 | psb->pCmd = NULL; | |
1101 | list_add_tail(&psb->list, | |
1102 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
1103 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, | |
1104 | iflag); | |
1105 | } else { | |
1106 | ||
1107 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
1108 | psb->pCmd = NULL; | |
1109 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); | |
1110 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
1111 | } | |
1112 | } | |
1113 | ||
9bad7671 | 1114 | /** |
3772a991 JS |
1115 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
1116 | * @phba: The Hba for which this call is being executed. | |
1117 | * @psb: The scsi buffer which is being released. | |
1118 | * | |
1119 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
1120 | * lpfc_scsi_buf_list list. | |
1121 | **/ | |
1122 | static void | |
1123 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |
1124 | { | |
1125 | ||
1126 | phba->lpfc_release_scsi_buf(phba, psb); | |
1127 | } | |
1128 | ||
1129 | /** | |
1130 | * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec | |
9bad7671 JS |
1131 | * @phba: The Hba for which this call is being executed. |
1132 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
1133 | * | |
1134 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | |
3772a991 JS |
1135 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
1136 | * through sg elements and format the bdea. This routine also initializes all | |
1137 | * IOCB fields which are dependent on scsi command request buffer. | |
9bad7671 JS |
1138 | * |
1139 | * Return codes: | |
1140 | * 1 - Error | |
1141 | * 0 - Success | |
1142 | **/ | |
dea3101e | 1143 | static int |
3772a991 | 1144 | lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
dea3101e | 1145 | { |
1146 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
1147 | struct scatterlist *sgel = NULL; | |
1148 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
1149 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; | |
0f65ff68 | 1150 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
dea3101e | 1151 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
34b02dcd | 1152 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
dea3101e | 1153 | dma_addr_t physaddr; |
34b02dcd | 1154 | uint32_t num_bde = 0; |
a0b4f78f | 1155 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
dea3101e | 1156 | |
1157 | /* | |
1158 | * There are three possibilities here - use scatter-gather segment, use | |
1159 | * the single mapping, or neither. Start the lpfc command prep by | |
1160 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
1161 | * data bde entry. | |
1162 | */ | |
1163 | bpl += 2; | |
c59fd9eb | 1164 | if (scsi_sg_count(scsi_cmnd)) { |
dea3101e | 1165 | /* |
1166 | * The driver stores the segment count returned from pci_map_sg | |
1167 | * because this a count of dma-mappings used to map the use_sg | |
1168 | * pages. They are not guaranteed to be the same for those | |
1169 | * architectures that implement an IOMMU. | |
1170 | */ | |
dea3101e | 1171 | |
c59fd9eb FT |
1172 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
1173 | scsi_sg_count(scsi_cmnd), datadir); | |
1174 | if (unlikely(!nseg)) | |
1175 | return 1; | |
1176 | ||
a0b4f78f | 1177 | lpfc_cmd->seg_cnt = nseg; |
dea3101e | 1178 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
6a9c52cf JS |
1179 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1180 | "9064 BLKGRD: %s: Too many sg segments from " | |
e2a0a9d6 | 1181 | "dma_map_sg. Config %d, seg_cnt %d\n", |
cadbd4a5 | 1182 | __func__, phba->cfg_sg_seg_cnt, |
dea3101e | 1183 | lpfc_cmd->seg_cnt); |
a0b4f78f | 1184 | scsi_dma_unmap(scsi_cmnd); |
dea3101e | 1185 | return 1; |
1186 | } | |
1187 | ||
1188 | /* | |
1189 | * The driver established a maximum scatter-gather segment count | |
1190 | * during probe that limits the number of sg elements in any | |
1191 | * single scsi command. Just run through the seg_cnt and format | |
1192 | * the bde's. | |
34b02dcd JS |
1193 | * When using SLI-3 the driver will try to fit all the BDEs into |
1194 | * the IOCB. If it can't then the BDEs get added to a BPL as it | |
1195 | * does for SLI-2 mode. | |
dea3101e | 1196 | */ |
34b02dcd | 1197 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
dea3101e | 1198 | physaddr = sg_dma_address(sgel); |
34b02dcd | 1199 | if (phba->sli_rev == 3 && |
e2a0a9d6 | 1200 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
0f65ff68 | 1201 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
34b02dcd JS |
1202 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
1203 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1204 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); | |
1205 | data_bde->addrLow = putPaddrLow(physaddr); | |
1206 | data_bde->addrHigh = putPaddrHigh(physaddr); | |
1207 | data_bde++; | |
1208 | } else { | |
1209 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1210 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
1211 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1212 | bpl->addrLow = | |
1213 | le32_to_cpu(putPaddrLow(physaddr)); | |
1214 | bpl->addrHigh = | |
1215 | le32_to_cpu(putPaddrHigh(physaddr)); | |
1216 | bpl++; | |
1217 | } | |
dea3101e | 1218 | } |
c59fd9eb | 1219 | } |
dea3101e | 1220 | |
1221 | /* | |
1222 | * Finish initializing those IOCB fields that are dependent on the | |
34b02dcd JS |
1223 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
1224 | * explicitly reinitialized and for SLI-3 the extended bde count is | |
1225 | * explicitly reinitialized since all iocb memory resources are reused. | |
dea3101e | 1226 | */ |
e2a0a9d6 | 1227 | if (phba->sli_rev == 3 && |
0f65ff68 JS |
1228 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
1229 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { | |
34b02dcd JS |
1230 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
1231 | /* | |
1232 | * The extended IOCB format can only fit 3 BDE or a BPL. | |
1233 | * This I/O has more than 3 BDE so the 1st data bde will | |
1234 | * be a BPL that is filled in here. | |
1235 | */ | |
1236 | physaddr = lpfc_cmd->dma_handle; | |
1237 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; | |
1238 | data_bde->tus.f.bdeSize = (num_bde * | |
1239 | sizeof(struct ulp_bde64)); | |
1240 | physaddr += (sizeof(struct fcp_cmnd) + | |
1241 | sizeof(struct fcp_rsp) + | |
1242 | (2 * sizeof(struct ulp_bde64))); | |
1243 | data_bde->addrHigh = putPaddrHigh(physaddr); | |
1244 | data_bde->addrLow = putPaddrLow(physaddr); | |
25985edc | 1245 | /* ebde count includes the response bde and data bpl */ |
34b02dcd JS |
1246 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
1247 | } else { | |
25985edc | 1248 | /* ebde count includes the response bde and data bdes */ |
34b02dcd JS |
1249 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
1250 | } | |
1251 | } else { | |
1252 | iocb_cmd->un.fcpi64.bdl.bdeSize = | |
1253 | ((num_bde + 2) * sizeof(struct ulp_bde64)); | |
0f65ff68 | 1254 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
34b02dcd | 1255 | } |
09372820 | 1256 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
e2a0a9d6 JS |
1257 | |
1258 | /* | |
1259 | * Due to difference in data length between DIF/non-DIF paths, | |
1260 | * we need to set word 4 of IOCB here | |
1261 | */ | |
a257bf90 | 1262 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
e2a0a9d6 JS |
1263 | return 0; |
1264 | } | |
1265 | ||
1266 | /* | |
6c8eea54 JS |
1267 | * Given a scsi cmnd, determine the BlockGuard opcodes to be used with it |
1268 | * @sc: The SCSI command to examine | |
1269 | * @txopt: (out) BlockGuard operation for transmitted data | |
1270 | * @rxopt: (out) BlockGuard operation for received data | |
1271 | * | |
1272 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined | |
1273 | * | |
e2a0a9d6 JS |
1274 | */ |
1275 | static int | |
6c8eea54 JS |
1276 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
1277 | uint8_t *txop, uint8_t *rxop) | |
e2a0a9d6 JS |
1278 | { |
1279 | uint8_t guard_type = scsi_host_get_guard(sc->device->host); | |
6c8eea54 | 1280 | uint8_t ret = 0; |
e2a0a9d6 JS |
1281 | |
1282 | if (guard_type == SHOST_DIX_GUARD_IP) { | |
1283 | switch (scsi_get_prot_op(sc)) { | |
1284 | case SCSI_PROT_READ_INSERT: | |
1285 | case SCSI_PROT_WRITE_STRIP: | |
6c8eea54 JS |
1286 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
1287 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; | |
e2a0a9d6 JS |
1288 | break; |
1289 | ||
1290 | case SCSI_PROT_READ_STRIP: | |
1291 | case SCSI_PROT_WRITE_INSERT: | |
6c8eea54 JS |
1292 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
1293 | *rxop = BG_OP_IN_CRC_OUT_NODIF; | |
e2a0a9d6 JS |
1294 | break; |
1295 | ||
c6af4042 MP |
1296 | case SCSI_PROT_READ_PASS: |
1297 | case SCSI_PROT_WRITE_PASS: | |
6c8eea54 JS |
1298 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
1299 | *rxop = BG_OP_IN_CRC_OUT_CSUM; | |
e2a0a9d6 JS |
1300 | break; |
1301 | ||
e2a0a9d6 JS |
1302 | case SCSI_PROT_NORMAL: |
1303 | default: | |
6a9c52cf | 1304 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
7c56b9fd JS |
1305 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
1306 | scsi_get_prot_op(sc)); | |
6c8eea54 | 1307 | ret = 1; |
e2a0a9d6 JS |
1308 | break; |
1309 | ||
1310 | } | |
7c56b9fd | 1311 | } else { |
e2a0a9d6 JS |
1312 | switch (scsi_get_prot_op(sc)) { |
1313 | case SCSI_PROT_READ_STRIP: | |
1314 | case SCSI_PROT_WRITE_INSERT: | |
6c8eea54 JS |
1315 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
1316 | *rxop = BG_OP_IN_CRC_OUT_NODIF; | |
e2a0a9d6 JS |
1317 | break; |
1318 | ||
1319 | case SCSI_PROT_READ_PASS: | |
1320 | case SCSI_PROT_WRITE_PASS: | |
6c8eea54 JS |
1321 | *txop = BG_OP_IN_CRC_OUT_CRC; |
1322 | *rxop = BG_OP_IN_CRC_OUT_CRC; | |
e2a0a9d6 JS |
1323 | break; |
1324 | ||
e2a0a9d6 JS |
1325 | case SCSI_PROT_READ_INSERT: |
1326 | case SCSI_PROT_WRITE_STRIP: | |
7c56b9fd JS |
1327 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
1328 | *rxop = BG_OP_IN_NODIF_OUT_CRC; | |
1329 | break; | |
1330 | ||
e2a0a9d6 JS |
1331 | case SCSI_PROT_NORMAL: |
1332 | default: | |
6a9c52cf | 1333 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
7c56b9fd JS |
1334 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
1335 | scsi_get_prot_op(sc)); | |
6c8eea54 | 1336 | ret = 1; |
e2a0a9d6 JS |
1337 | break; |
1338 | } | |
e2a0a9d6 JS |
1339 | } |
1340 | ||
6c8eea54 | 1341 | return ret; |
e2a0a9d6 JS |
1342 | } |
1343 | ||
1344 | struct scsi_dif_tuple { | |
1345 | __be16 guard_tag; /* Checksum */ | |
1346 | __be16 app_tag; /* Opaque storage */ | |
1347 | __be32 ref_tag; /* Target LBA or indirect LBA */ | |
1348 | }; | |
1349 | ||
1350 | static inline unsigned | |
1351 | lpfc_cmd_blksize(struct scsi_cmnd *sc) | |
1352 | { | |
1353 | return sc->device->sector_size; | |
1354 | } | |
1355 | ||
e2a0a9d6 JS |
1356 | /* |
1357 | * This function sets up buffer list for protection groups of | |
1358 | * type LPFC_PG_TYPE_NO_DIF | |
1359 | * | |
1360 | * This is usually used when the HBA is instructed to generate | |
1361 | * DIFs and insert them into data stream (or strip DIF from | |
1362 | * incoming data stream) | |
1363 | * | |
1364 | * The buffer list consists of just one protection group described | |
1365 | * below: | |
1366 | * +-------------------------+ | |
6c8eea54 JS |
1367 | * start of prot group --> | PDE_5 | |
1368 | * +-------------------------+ | |
1369 | * | PDE_6 | | |
e2a0a9d6 JS |
1370 | * +-------------------------+ |
1371 | * | Data BDE | | |
1372 | * +-------------------------+ | |
1373 | * |more Data BDE's ... (opt)| | |
1374 | * +-------------------------+ | |
1375 | * | |
1376 | * @sc: pointer to scsi command we're working on | |
1377 | * @bpl: pointer to buffer list for protection groups | |
1378 | * @datacnt: number of segments of data that have been dma mapped | |
1379 | * | |
1380 | * Note: Data s/g buffers have been dma mapped | |
1381 | */ | |
1382 | static int | |
1383 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
1384 | struct ulp_bde64 *bpl, int datasegcnt) | |
1385 | { | |
1386 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
6c8eea54 JS |
1387 | struct lpfc_pde5 *pde5 = NULL; |
1388 | struct lpfc_pde6 *pde6 = NULL; | |
e2a0a9d6 | 1389 | dma_addr_t physaddr; |
6c8eea54 | 1390 | int i = 0, num_bde = 0, status; |
e2a0a9d6 | 1391 | int datadir = sc->sc_data_direction; |
e2a0a9d6 | 1392 | uint32_t reftag; |
7c56b9fd | 1393 | unsigned blksize; |
6c8eea54 | 1394 | uint8_t txop, rxop; |
e2a0a9d6 | 1395 | |
6c8eea54 JS |
1396 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
1397 | if (status) | |
e2a0a9d6 JS |
1398 | goto out; |
1399 | ||
6c8eea54 | 1400 | /* extract some info from the scsi command for pde*/ |
e2a0a9d6 | 1401 | blksize = lpfc_cmd_blksize(sc); |
7c56b9fd | 1402 | reftag = scsi_get_lba(sc) & 0xffffffff; |
e2a0a9d6 | 1403 | |
6c8eea54 JS |
1404 | /* setup PDE5 with what we have */ |
1405 | pde5 = (struct lpfc_pde5 *) bpl; | |
1406 | memset(pde5, 0, sizeof(struct lpfc_pde5)); | |
1407 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); | |
6c8eea54 | 1408 | |
bc73905a | 1409 | /* Endianness conversion if necessary for PDE5 */ |
589a52d6 | 1410 | pde5->word0 = cpu_to_le32(pde5->word0); |
7c56b9fd | 1411 | pde5->reftag = cpu_to_le32(reftag); |
589a52d6 | 1412 | |
6c8eea54 JS |
1413 | /* advance bpl and increment bde count */ |
1414 | num_bde++; | |
1415 | bpl++; | |
1416 | pde6 = (struct lpfc_pde6 *) bpl; | |
1417 | ||
1418 | /* setup PDE6 with the rest of the info */ | |
1419 | memset(pde6, 0, sizeof(struct lpfc_pde6)); | |
1420 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); | |
1421 | bf_set(pde6_optx, pde6, txop); | |
1422 | bf_set(pde6_oprx, pde6, rxop); | |
1423 | if (datadir == DMA_FROM_DEVICE) { | |
1424 | bf_set(pde6_ce, pde6, 1); | |
1425 | bf_set(pde6_re, pde6, 1); | |
6c8eea54 JS |
1426 | } |
1427 | bf_set(pde6_ai, pde6, 1); | |
7c56b9fd JS |
1428 | bf_set(pde6_ae, pde6, 0); |
1429 | bf_set(pde6_apptagval, pde6, 0); | |
e2a0a9d6 | 1430 | |
bc73905a | 1431 | /* Endianness conversion if necessary for PDE6 */ |
589a52d6 JS |
1432 | pde6->word0 = cpu_to_le32(pde6->word0); |
1433 | pde6->word1 = cpu_to_le32(pde6->word1); | |
1434 | pde6->word2 = cpu_to_le32(pde6->word2); | |
1435 | ||
6c8eea54 | 1436 | /* advance bpl and increment bde count */ |
e2a0a9d6 JS |
1437 | num_bde++; |
1438 | bpl++; | |
1439 | ||
1440 | /* assumption: caller has already run dma_map_sg on command data */ | |
1441 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { | |
1442 | physaddr = sg_dma_address(sgde); | |
1443 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
1444 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); | |
1445 | bpl->tus.f.bdeSize = sg_dma_len(sgde); | |
1446 | if (datadir == DMA_TO_DEVICE) | |
1447 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1448 | else | |
1449 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
1450 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1451 | bpl++; | |
1452 | num_bde++; | |
1453 | } | |
1454 | ||
1455 | out: | |
1456 | return num_bde; | |
1457 | } | |
1458 | ||
1459 | /* | |
1460 | * This function sets up buffer list for protection groups of | |
1461 | * type LPFC_PG_TYPE_DIF_BUF | |
1462 | * | |
1463 | * This is usually used when DIFs are in their own buffers, | |
1464 | * separate from the data. The HBA can then by instructed | |
1465 | * to place the DIFs in the outgoing stream. For read operations, | |
1466 | * The HBA could extract the DIFs and place it in DIF buffers. | |
1467 | * | |
1468 | * The buffer list for this type consists of one or more of the | |
1469 | * protection groups described below: | |
1470 | * +-------------------------+ | |
6c8eea54 | 1471 | * start of first prot group --> | PDE_5 | |
e2a0a9d6 | 1472 | * +-------------------------+ |
6c8eea54 JS |
1473 | * | PDE_6 | |
1474 | * +-------------------------+ | |
1475 | * | PDE_7 (Prot BDE) | | |
e2a0a9d6 JS |
1476 | * +-------------------------+ |
1477 | * | Data BDE | | |
1478 | * +-------------------------+ | |
1479 | * |more Data BDE's ... (opt)| | |
1480 | * +-------------------------+ | |
6c8eea54 | 1481 | * start of new prot group --> | PDE_5 | |
e2a0a9d6 JS |
1482 | * +-------------------------+ |
1483 | * | ... | | |
1484 | * +-------------------------+ | |
1485 | * | |
1486 | * @sc: pointer to scsi command we're working on | |
1487 | * @bpl: pointer to buffer list for protection groups | |
1488 | * @datacnt: number of segments of data that have been dma mapped | |
1489 | * @protcnt: number of segment of protection data that have been dma mapped | |
1490 | * | |
1491 | * Note: It is assumed that both data and protection s/g buffers have been | |
1492 | * mapped for DMA | |
1493 | */ | |
1494 | static int | |
1495 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
1496 | struct ulp_bde64 *bpl, int datacnt, int protcnt) | |
1497 | { | |
1498 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
1499 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ | |
6c8eea54 JS |
1500 | struct lpfc_pde5 *pde5 = NULL; |
1501 | struct lpfc_pde6 *pde6 = NULL; | |
7f86059a | 1502 | struct lpfc_pde7 *pde7 = NULL; |
e2a0a9d6 JS |
1503 | dma_addr_t dataphysaddr, protphysaddr; |
1504 | unsigned short curr_data = 0, curr_prot = 0; | |
7f86059a JS |
1505 | unsigned int split_offset; |
1506 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; | |
e2a0a9d6 JS |
1507 | unsigned int protgrp_blks, protgrp_bytes; |
1508 | unsigned int remainder, subtotal; | |
6c8eea54 | 1509 | int status; |
e2a0a9d6 JS |
1510 | int datadir = sc->sc_data_direction; |
1511 | unsigned char pgdone = 0, alldone = 0; | |
1512 | unsigned blksize; | |
1513 | uint32_t reftag; | |
6c8eea54 | 1514 | uint8_t txop, rxop; |
e2a0a9d6 JS |
1515 | int num_bde = 0; |
1516 | ||
1517 | sgpe = scsi_prot_sglist(sc); | |
1518 | sgde = scsi_sglist(sc); | |
1519 | ||
1520 | if (!sgpe || !sgde) { | |
1521 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1522 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", | |
1523 | sgpe, sgde); | |
1524 | return 0; | |
1525 | } | |
1526 | ||
6c8eea54 JS |
1527 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
1528 | if (status) | |
e2a0a9d6 JS |
1529 | goto out; |
1530 | ||
6c8eea54 | 1531 | /* extract some info from the scsi command */ |
e2a0a9d6 | 1532 | blksize = lpfc_cmd_blksize(sc); |
7c56b9fd | 1533 | reftag = scsi_get_lba(sc) & 0xffffffff; |
e2a0a9d6 JS |
1534 | |
1535 | split_offset = 0; | |
1536 | do { | |
6c8eea54 JS |
1537 | /* setup PDE5 with what we have */ |
1538 | pde5 = (struct lpfc_pde5 *) bpl; | |
1539 | memset(pde5, 0, sizeof(struct lpfc_pde5)); | |
1540 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); | |
e2a0a9d6 | 1541 | |
bc73905a | 1542 | /* Endianness conversion if necessary for PDE5 */ |
589a52d6 | 1543 | pde5->word0 = cpu_to_le32(pde5->word0); |
7c56b9fd | 1544 | pde5->reftag = cpu_to_le32(reftag); |
589a52d6 | 1545 | |
6c8eea54 JS |
1546 | /* advance bpl and increment bde count */ |
1547 | num_bde++; | |
1548 | bpl++; | |
1549 | pde6 = (struct lpfc_pde6 *) bpl; | |
1550 | ||
1551 | /* setup PDE6 with the rest of the info */ | |
1552 | memset(pde6, 0, sizeof(struct lpfc_pde6)); | |
1553 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); | |
1554 | bf_set(pde6_optx, pde6, txop); | |
1555 | bf_set(pde6_oprx, pde6, rxop); | |
1556 | bf_set(pde6_ce, pde6, 1); | |
1557 | bf_set(pde6_re, pde6, 1); | |
6c8eea54 | 1558 | bf_set(pde6_ai, pde6, 1); |
7c56b9fd JS |
1559 | bf_set(pde6_ae, pde6, 0); |
1560 | bf_set(pde6_apptagval, pde6, 0); | |
6c8eea54 | 1561 | |
bc73905a | 1562 | /* Endianness conversion if necessary for PDE6 */ |
589a52d6 JS |
1563 | pde6->word0 = cpu_to_le32(pde6->word0); |
1564 | pde6->word1 = cpu_to_le32(pde6->word1); | |
1565 | pde6->word2 = cpu_to_le32(pde6->word2); | |
1566 | ||
6c8eea54 | 1567 | /* advance bpl and increment bde count */ |
e2a0a9d6 JS |
1568 | num_bde++; |
1569 | bpl++; | |
1570 | ||
1571 | /* setup the first BDE that points to protection buffer */ | |
7f86059a JS |
1572 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
1573 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; | |
e2a0a9d6 | 1574 | |
e2a0a9d6 JS |
1575 | /* must be integer multiple of the DIF block length */ |
1576 | BUG_ON(protgroup_len % 8); | |
1577 | ||
7f86059a JS |
1578 | pde7 = (struct lpfc_pde7 *) bpl; |
1579 | memset(pde7, 0, sizeof(struct lpfc_pde7)); | |
1580 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); | |
1581 | ||
7c56b9fd JS |
1582 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); |
1583 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); | |
7f86059a | 1584 | |
e2a0a9d6 JS |
1585 | protgrp_blks = protgroup_len / 8; |
1586 | protgrp_bytes = protgrp_blks * blksize; | |
1587 | ||
7f86059a JS |
1588 | /* check if this pde is crossing the 4K boundary; if so split */ |
1589 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { | |
1590 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); | |
1591 | protgroup_offset += protgroup_remainder; | |
1592 | protgrp_blks = protgroup_remainder / 8; | |
7c56b9fd | 1593 | protgrp_bytes = protgrp_blks * blksize; |
7f86059a JS |
1594 | } else { |
1595 | protgroup_offset = 0; | |
1596 | curr_prot++; | |
1597 | } | |
e2a0a9d6 | 1598 | |
e2a0a9d6 JS |
1599 | num_bde++; |
1600 | ||
1601 | /* setup BDE's for data blocks associated with DIF data */ | |
1602 | pgdone = 0; | |
1603 | subtotal = 0; /* total bytes processed for current prot grp */ | |
1604 | while (!pgdone) { | |
1605 | if (!sgde) { | |
6a9c52cf JS |
1606 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1607 | "9065 BLKGRD:%s Invalid data segment\n", | |
e2a0a9d6 JS |
1608 | __func__); |
1609 | return 0; | |
1610 | } | |
1611 | bpl++; | |
1612 | dataphysaddr = sg_dma_address(sgde) + split_offset; | |
1613 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); | |
1614 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); | |
1615 | ||
1616 | remainder = sg_dma_len(sgde) - split_offset; | |
1617 | ||
1618 | if ((subtotal + remainder) <= protgrp_bytes) { | |
1619 | /* we can use this whole buffer */ | |
1620 | bpl->tus.f.bdeSize = remainder; | |
1621 | split_offset = 0; | |
1622 | ||
1623 | if ((subtotal + remainder) == protgrp_bytes) | |
1624 | pgdone = 1; | |
1625 | } else { | |
1626 | /* must split this buffer with next prot grp */ | |
1627 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; | |
1628 | split_offset += bpl->tus.f.bdeSize; | |
1629 | } | |
1630 | ||
1631 | subtotal += bpl->tus.f.bdeSize; | |
1632 | ||
1633 | if (datadir == DMA_TO_DEVICE) | |
1634 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1635 | else | |
1636 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
1637 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1638 | ||
1639 | num_bde++; | |
1640 | curr_data++; | |
1641 | ||
1642 | if (split_offset) | |
1643 | break; | |
1644 | ||
1645 | /* Move to the next s/g segment if possible */ | |
1646 | sgde = sg_next(sgde); | |
6c8eea54 | 1647 | |
e2a0a9d6 JS |
1648 | } |
1649 | ||
7f86059a JS |
1650 | if (protgroup_offset) { |
1651 | /* update the reference tag */ | |
1652 | reftag += protgrp_blks; | |
1653 | bpl++; | |
1654 | continue; | |
1655 | } | |
1656 | ||
e2a0a9d6 JS |
1657 | /* are we done ? */ |
1658 | if (curr_prot == protcnt) { | |
1659 | alldone = 1; | |
1660 | } else if (curr_prot < protcnt) { | |
1661 | /* advance to next prot buffer */ | |
1662 | sgpe = sg_next(sgpe); | |
1663 | bpl++; | |
1664 | ||
1665 | /* update the reference tag */ | |
1666 | reftag += protgrp_blks; | |
1667 | } else { | |
1668 | /* if we're here, we have a bug */ | |
6a9c52cf JS |
1669 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1670 | "9054 BLKGRD: bug in %s\n", __func__); | |
e2a0a9d6 JS |
1671 | } |
1672 | ||
1673 | } while (!alldone); | |
1674 | ||
1675 | out: | |
1676 | ||
e2a0a9d6 JS |
1677 | return num_bde; |
1678 | } | |
7f86059a | 1679 | |
e2a0a9d6 JS |
1680 | /* |
1681 | * Given a SCSI command that supports DIF, determine composition of protection | |
1682 | * groups involved in setting up buffer lists | |
1683 | * | |
1684 | * Returns: | |
1685 | * for DIF (for both read and write) | |
1686 | * */ | |
1687 | static int | |
1688 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) | |
1689 | { | |
1690 | int ret = LPFC_PG_TYPE_INVALID; | |
1691 | unsigned char op = scsi_get_prot_op(sc); | |
1692 | ||
1693 | switch (op) { | |
1694 | case SCSI_PROT_READ_STRIP: | |
1695 | case SCSI_PROT_WRITE_INSERT: | |
1696 | ret = LPFC_PG_TYPE_NO_DIF; | |
1697 | break; | |
1698 | case SCSI_PROT_READ_INSERT: | |
1699 | case SCSI_PROT_WRITE_STRIP: | |
1700 | case SCSI_PROT_READ_PASS: | |
1701 | case SCSI_PROT_WRITE_PASS: | |
e2a0a9d6 JS |
1702 | ret = LPFC_PG_TYPE_DIF_BUF; |
1703 | break; | |
1704 | default: | |
1705 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1706 | "9021 Unsupported protection op:%d\n", op); | |
1707 | break; | |
1708 | } | |
1709 | ||
1710 | return ret; | |
1711 | } | |
1712 | ||
1713 | /* | |
1714 | * This is the protection/DIF aware version of | |
1715 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the | |
1716 | * two functions eventually, but for now, it's here | |
1717 | */ | |
1718 | static int | |
1719 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, | |
1720 | struct lpfc_scsi_buf *lpfc_cmd) | |
1721 | { | |
1722 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
1723 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
1724 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; | |
1725 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
1726 | uint32_t num_bde = 0; | |
1727 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; | |
1728 | int prot_group_type = 0; | |
1729 | int diflen, fcpdl; | |
1730 | unsigned blksize; | |
1731 | ||
1732 | /* | |
1733 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd | |
1734 | * fcp_rsp regions to the first data bde entry | |
1735 | */ | |
1736 | bpl += 2; | |
1737 | if (scsi_sg_count(scsi_cmnd)) { | |
1738 | /* | |
1739 | * The driver stores the segment count returned from pci_map_sg | |
1740 | * because this a count of dma-mappings used to map the use_sg | |
1741 | * pages. They are not guaranteed to be the same for those | |
1742 | * architectures that implement an IOMMU. | |
1743 | */ | |
1744 | datasegcnt = dma_map_sg(&phba->pcidev->dev, | |
1745 | scsi_sglist(scsi_cmnd), | |
1746 | scsi_sg_count(scsi_cmnd), datadir); | |
1747 | if (unlikely(!datasegcnt)) | |
1748 | return 1; | |
1749 | ||
1750 | lpfc_cmd->seg_cnt = datasegcnt; | |
1751 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { | |
6a9c52cf JS |
1752 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1753 | "9067 BLKGRD: %s: Too many sg segments" | |
1754 | " from dma_map_sg. Config %d, seg_cnt" | |
1755 | " %d\n", | |
e2a0a9d6 JS |
1756 | __func__, phba->cfg_sg_seg_cnt, |
1757 | lpfc_cmd->seg_cnt); | |
1758 | scsi_dma_unmap(scsi_cmnd); | |
1759 | return 1; | |
1760 | } | |
1761 | ||
1762 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); | |
1763 | ||
1764 | switch (prot_group_type) { | |
1765 | case LPFC_PG_TYPE_NO_DIF: | |
1766 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, | |
1767 | datasegcnt); | |
c9404c9c | 1768 | /* we should have 2 or more entries in buffer list */ |
e2a0a9d6 JS |
1769 | if (num_bde < 2) |
1770 | goto err; | |
1771 | break; | |
1772 | case LPFC_PG_TYPE_DIF_BUF:{ | |
1773 | /* | |
1774 | * This type indicates that protection buffers are | |
1775 | * passed to the driver, so that needs to be prepared | |
1776 | * for DMA | |
1777 | */ | |
1778 | protsegcnt = dma_map_sg(&phba->pcidev->dev, | |
1779 | scsi_prot_sglist(scsi_cmnd), | |
1780 | scsi_prot_sg_count(scsi_cmnd), datadir); | |
1781 | if (unlikely(!protsegcnt)) { | |
1782 | scsi_dma_unmap(scsi_cmnd); | |
1783 | return 1; | |
1784 | } | |
1785 | ||
1786 | lpfc_cmd->prot_seg_cnt = protsegcnt; | |
1787 | if (lpfc_cmd->prot_seg_cnt | |
1788 | > phba->cfg_prot_sg_seg_cnt) { | |
6a9c52cf JS |
1789 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1790 | "9068 BLKGRD: %s: Too many prot sg " | |
1791 | "segments from dma_map_sg. Config %d," | |
e2a0a9d6 JS |
1792 | "prot_seg_cnt %d\n", __func__, |
1793 | phba->cfg_prot_sg_seg_cnt, | |
1794 | lpfc_cmd->prot_seg_cnt); | |
1795 | dma_unmap_sg(&phba->pcidev->dev, | |
1796 | scsi_prot_sglist(scsi_cmnd), | |
1797 | scsi_prot_sg_count(scsi_cmnd), | |
1798 | datadir); | |
1799 | scsi_dma_unmap(scsi_cmnd); | |
1800 | return 1; | |
1801 | } | |
1802 | ||
1803 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, | |
1804 | datasegcnt, protsegcnt); | |
c9404c9c | 1805 | /* we should have 3 or more entries in buffer list */ |
e2a0a9d6 JS |
1806 | if (num_bde < 3) |
1807 | goto err; | |
1808 | break; | |
1809 | } | |
1810 | case LPFC_PG_TYPE_INVALID: | |
1811 | default: | |
1812 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1813 | "9022 Unexpected protection group %i\n", | |
1814 | prot_group_type); | |
1815 | return 1; | |
1816 | } | |
1817 | } | |
1818 | ||
1819 | /* | |
1820 | * Finish initializing those IOCB fields that are dependent on the | |
1821 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly | |
1822 | * reinitialized since all iocb memory resources are used many times | |
1823 | * for transmit, receive, and continuation bpl's. | |
1824 | */ | |
1825 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); | |
1826 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); | |
1827 | iocb_cmd->ulpBdeCount = 1; | |
1828 | iocb_cmd->ulpLe = 1; | |
1829 | ||
1830 | fcpdl = scsi_bufflen(scsi_cmnd); | |
1831 | ||
1832 | if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) { | |
1833 | /* | |
1834 | * We are in DIF Type 1 mode | |
1835 | * Every data block has a 8 byte DIF (trailer) | |
1836 | * attached to it. Must ajust FCP data length | |
1837 | */ | |
1838 | blksize = lpfc_cmd_blksize(scsi_cmnd); | |
1839 | diflen = (fcpdl / blksize) * 8; | |
1840 | fcpdl += diflen; | |
1841 | } | |
1842 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); | |
1843 | ||
1844 | /* | |
1845 | * Due to difference in data length between DIF/non-DIF paths, | |
1846 | * we need to set word 4 of IOCB here | |
1847 | */ | |
1848 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; | |
1849 | ||
dea3101e | 1850 | return 0; |
e2a0a9d6 JS |
1851 | err: |
1852 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1853 | "9023 Could not setup all needed BDE's" | |
1854 | "prot_group_type=%d, num_bde=%d\n", | |
1855 | prot_group_type, num_bde); | |
1856 | return 1; | |
1857 | } | |
1858 | ||
1859 | /* | |
1860 | * This function checks for BlockGuard errors detected by | |
1861 | * the HBA. In case of errors, the ASC/ASCQ fields in the | |
1862 | * sense buffer will be set accordingly, paired with | |
1863 | * ILLEGAL_REQUEST to signal to the kernel that the HBA | |
1864 | * detected corruption. | |
1865 | * | |
1866 | * Returns: | |
1867 | * 0 - No error found | |
1868 | * 1 - BlockGuard error found | |
1869 | * -1 - Internal error (bad profile, ...etc) | |
1870 | */ | |
1871 | static int | |
1872 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, | |
1873 | struct lpfc_iocbq *pIocbOut) | |
1874 | { | |
1875 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
1876 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; | |
1877 | int ret = 0; | |
1878 | uint32_t bghm = bgf->bghm; | |
1879 | uint32_t bgstat = bgf->bgstat; | |
1880 | uint64_t failing_sector = 0; | |
1881 | ||
6a9c52cf JS |
1882 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9069 BLKGRD: BG ERROR in cmd" |
1883 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
e2a0a9d6 | 1884 | "bgstat=0x%x bghm=0x%x\n", |
87b5c328 | 1885 | cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd), |
83096ebf | 1886 | blk_rq_sectors(cmd->request), bgstat, bghm); |
e2a0a9d6 JS |
1887 | |
1888 | spin_lock(&_dump_buf_lock); | |
1889 | if (!_dump_buf_done) { | |
6a9c52cf JS |
1890 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
1891 | " Data for %u blocks to debugfs\n", | |
e2a0a9d6 | 1892 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
6a9c52cf | 1893 | lpfc_debug_save_data(phba, cmd); |
e2a0a9d6 JS |
1894 | |
1895 | /* If we have a prot sgl, save the DIF buffer */ | |
1896 | if (lpfc_prot_group_type(phba, cmd) == | |
1897 | LPFC_PG_TYPE_DIF_BUF) { | |
6a9c52cf JS |
1898 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
1899 | "Saving DIF for %u blocks to debugfs\n", | |
1900 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); | |
1901 | lpfc_debug_save_dif(phba, cmd); | |
e2a0a9d6 JS |
1902 | } |
1903 | ||
1904 | _dump_buf_done = 1; | |
1905 | } | |
1906 | spin_unlock(&_dump_buf_lock); | |
1907 | ||
1908 | if (lpfc_bgs_get_invalid_prof(bgstat)) { | |
1909 | cmd->result = ScsiResult(DID_ERROR, 0); | |
6a9c52cf JS |
1910 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9072 BLKGRD: Invalid" |
1911 | " BlockGuard profile. bgstat:0x%x\n", | |
1912 | bgstat); | |
e2a0a9d6 JS |
1913 | ret = (-1); |
1914 | goto out; | |
1915 | } | |
1916 | ||
1917 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { | |
1918 | cmd->result = ScsiResult(DID_ERROR, 0); | |
6a9c52cf JS |
1919 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9073 BLKGRD: " |
1920 | "Invalid BlockGuard DIF Block. bgstat:0x%x\n", | |
e2a0a9d6 JS |
1921 | bgstat); |
1922 | ret = (-1); | |
1923 | goto out; | |
1924 | } | |
1925 | ||
1926 | if (lpfc_bgs_get_guard_err(bgstat)) { | |
1927 | ret = 1; | |
1928 | ||
1929 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1930 | 0x10, 0x1); | |
1c9fbafc | 1931 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
1932 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
1933 | phba->bg_guard_err_cnt++; | |
6a9c52cf JS |
1934 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1935 | "9055 BLKGRD: guard_tag error\n"); | |
e2a0a9d6 JS |
1936 | } |
1937 | ||
1938 | if (lpfc_bgs_get_reftag_err(bgstat)) { | |
1939 | ret = 1; | |
1940 | ||
1941 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1942 | 0x10, 0x3); | |
1c9fbafc | 1943 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
1944 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
1945 | ||
1946 | phba->bg_reftag_err_cnt++; | |
6a9c52cf JS |
1947 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1948 | "9056 BLKGRD: ref_tag error\n"); | |
e2a0a9d6 JS |
1949 | } |
1950 | ||
1951 | if (lpfc_bgs_get_apptag_err(bgstat)) { | |
1952 | ret = 1; | |
1953 | ||
1954 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1955 | 0x10, 0x2); | |
1c9fbafc | 1956 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
1957 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
1958 | ||
1959 | phba->bg_apptag_err_cnt++; | |
6a9c52cf JS |
1960 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1961 | "9061 BLKGRD: app_tag error\n"); | |
e2a0a9d6 JS |
1962 | } |
1963 | ||
1964 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { | |
1965 | /* | |
1966 | * setup sense data descriptor 0 per SPC-4 as an information | |
7c56b9fd JS |
1967 | * field, and put the failing LBA in it. |
1968 | * This code assumes there was also a guard/app/ref tag error | |
1969 | * indication. | |
e2a0a9d6 | 1970 | */ |
7c56b9fd JS |
1971 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
1972 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ | |
1973 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ | |
1974 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ | |
2344b5b6 | 1975 | bghm /= cmd->device->sector_size; |
e2a0a9d6 JS |
1976 | |
1977 | failing_sector = scsi_get_lba(cmd); | |
1978 | failing_sector += bghm; | |
1979 | ||
7c56b9fd JS |
1980 | /* Descriptor Information */ |
1981 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); | |
e2a0a9d6 JS |
1982 | } |
1983 | ||
1984 | if (!ret) { | |
1985 | /* No error was reported - problem in FW? */ | |
1986 | cmd->result = ScsiResult(DID_ERROR, 0); | |
6a9c52cf JS |
1987 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1988 | "9057 BLKGRD: no errors reported!\n"); | |
e2a0a9d6 JS |
1989 | } |
1990 | ||
1991 | out: | |
1992 | return ret; | |
dea3101e | 1993 | } |
1994 | ||
da0436e9 JS |
1995 | /** |
1996 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec | |
1997 | * @phba: The Hba for which this call is being executed. | |
1998 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
1999 | * | |
2000 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | |
2001 | * field of @lpfc_cmd for device with SLI-4 interface spec. | |
2002 | * | |
2003 | * Return codes: | |
6c8eea54 JS |
2004 | * 1 - Error |
2005 | * 0 - Success | |
da0436e9 JS |
2006 | **/ |
2007 | static int | |
2008 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
2009 | { | |
2010 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
2011 | struct scatterlist *sgel = NULL; | |
2012 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
2013 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
fedd3b7b | 2014 | struct sli4_sge *first_data_sgl; |
da0436e9 JS |
2015 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
2016 | dma_addr_t physaddr; | |
2017 | uint32_t num_bde = 0; | |
2018 | uint32_t dma_len; | |
2019 | uint32_t dma_offset = 0; | |
2020 | int nseg; | |
fedd3b7b | 2021 | struct ulp_bde64 *bde; |
da0436e9 JS |
2022 | |
2023 | /* | |
2024 | * There are three possibilities here - use scatter-gather segment, use | |
2025 | * the single mapping, or neither. Start the lpfc command prep by | |
2026 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
2027 | * data bde entry. | |
2028 | */ | |
2029 | if (scsi_sg_count(scsi_cmnd)) { | |
2030 | /* | |
2031 | * The driver stores the segment count returned from pci_map_sg | |
2032 | * because this a count of dma-mappings used to map the use_sg | |
2033 | * pages. They are not guaranteed to be the same for those | |
2034 | * architectures that implement an IOMMU. | |
2035 | */ | |
2036 | ||
2037 | nseg = scsi_dma_map(scsi_cmnd); | |
2038 | if (unlikely(!nseg)) | |
2039 | return 1; | |
2040 | sgl += 1; | |
2041 | /* clear the last flag in the fcp_rsp map entry */ | |
2042 | sgl->word2 = le32_to_cpu(sgl->word2); | |
2043 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
2044 | sgl->word2 = cpu_to_le32(sgl->word2); | |
2045 | sgl += 1; | |
fedd3b7b | 2046 | first_data_sgl = sgl; |
da0436e9 JS |
2047 | lpfc_cmd->seg_cnt = nseg; |
2048 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { | |
6a9c52cf JS |
2049 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
2050 | " %s: Too many sg segments from " | |
2051 | "dma_map_sg. Config %d, seg_cnt %d\n", | |
2052 | __func__, phba->cfg_sg_seg_cnt, | |
da0436e9 JS |
2053 | lpfc_cmd->seg_cnt); |
2054 | scsi_dma_unmap(scsi_cmnd); | |
2055 | return 1; | |
2056 | } | |
2057 | ||
2058 | /* | |
2059 | * The driver established a maximum scatter-gather segment count | |
2060 | * during probe that limits the number of sg elements in any | |
2061 | * single scsi command. Just run through the seg_cnt and format | |
2062 | * the sge's. | |
2063 | * When using SLI-3 the driver will try to fit all the BDEs into | |
2064 | * the IOCB. If it can't then the BDEs get added to a BPL as it | |
2065 | * does for SLI-2 mode. | |
2066 | */ | |
2067 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { | |
2068 | physaddr = sg_dma_address(sgel); | |
2069 | dma_len = sg_dma_len(sgel); | |
da0436e9 JS |
2070 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
2071 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); | |
0558056c | 2072 | sgl->word2 = le32_to_cpu(sgl->word2); |
da0436e9 JS |
2073 | if ((num_bde + 1) == nseg) |
2074 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
2075 | else | |
2076 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
2077 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); | |
2078 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 | 2079 | sgl->sge_len = cpu_to_le32(dma_len); |
da0436e9 JS |
2080 | dma_offset += dma_len; |
2081 | sgl++; | |
2082 | } | |
fedd3b7b JS |
2083 | /* setup the performance hint (first data BDE) if enabled */ |
2084 | if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) { | |
2085 | bde = (struct ulp_bde64 *) | |
2086 | &(iocb_cmd->unsli3.sli3Words[5]); | |
2087 | bde->addrLow = first_data_sgl->addr_lo; | |
2088 | bde->addrHigh = first_data_sgl->addr_hi; | |
2089 | bde->tus.f.bdeSize = | |
2090 | le32_to_cpu(first_data_sgl->sge_len); | |
2091 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
2092 | bde->tus.w = cpu_to_le32(bde->tus.w); | |
2093 | } | |
da0436e9 JS |
2094 | } else { |
2095 | sgl += 1; | |
2096 | /* clear the last flag in the fcp_rsp map entry */ | |
2097 | sgl->word2 = le32_to_cpu(sgl->word2); | |
2098 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
2099 | sgl->word2 = cpu_to_le32(sgl->word2); | |
2100 | } | |
2101 | ||
2102 | /* | |
2103 | * Finish initializing those IOCB fields that are dependent on the | |
2104 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is | |
2105 | * explicitly reinitialized. | |
2106 | * all iocb memory resources are reused. | |
2107 | */ | |
2108 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); | |
2109 | ||
2110 | /* | |
2111 | * Due to difference in data length between DIF/non-DIF paths, | |
2112 | * we need to set word 4 of IOCB here | |
2113 | */ | |
2114 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); | |
2115 | return 0; | |
2116 | } | |
2117 | ||
3772a991 JS |
2118 | /** |
2119 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer | |
2120 | * @phba: The Hba for which this call is being executed. | |
2121 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
2122 | * | |
2123 | * This routine wraps the actual DMA mapping function pointer from the | |
2124 | * lpfc_hba struct. | |
2125 | * | |
2126 | * Return codes: | |
6c8eea54 JS |
2127 | * 1 - Error |
2128 | * 0 - Success | |
3772a991 JS |
2129 | **/ |
2130 | static inline int | |
2131 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
2132 | { | |
2133 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); | |
2134 | } | |
2135 | ||
ea2151b4 | 2136 | /** |
3621a710 | 2137 | * lpfc_send_scsi_error_event - Posts an event when there is SCSI error |
ea2151b4 JS |
2138 | * @phba: Pointer to hba context object. |
2139 | * @vport: Pointer to vport object. | |
2140 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. | |
2141 | * @rsp_iocb: Pointer to response iocb object which reported error. | |
2142 | * | |
2143 | * This function posts an event when there is a SCSI command reporting | |
2144 | * error from the scsi device. | |
2145 | **/ | |
2146 | static void | |
2147 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, | |
2148 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { | |
2149 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; | |
2150 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; | |
2151 | uint32_t resp_info = fcprsp->rspStatus2; | |
2152 | uint32_t scsi_status = fcprsp->rspStatus3; | |
2153 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; | |
2154 | struct lpfc_fast_path_event *fast_path_evt = NULL; | |
2155 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; | |
2156 | unsigned long flags; | |
2157 | ||
5989b8d4 JS |
2158 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
2159 | return; | |
2160 | ||
ea2151b4 JS |
2161 | /* If there is queuefull or busy condition send a scsi event */ |
2162 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || | |
2163 | (cmnd->result == SAM_STAT_BUSY)) { | |
2164 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
2165 | if (!fast_path_evt) | |
2166 | return; | |
2167 | fast_path_evt->un.scsi_evt.event_type = | |
2168 | FC_REG_SCSI_EVENT; | |
2169 | fast_path_evt->un.scsi_evt.subcategory = | |
2170 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? | |
2171 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; | |
2172 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; | |
2173 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, | |
2174 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
2175 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, | |
2176 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
2177 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && | |
2178 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { | |
2179 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
2180 | if (!fast_path_evt) | |
2181 | return; | |
2182 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = | |
2183 | FC_REG_SCSI_EVENT; | |
2184 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = | |
2185 | LPFC_EVENT_CHECK_COND; | |
2186 | fast_path_evt->un.check_cond_evt.scsi_event.lun = | |
2187 | cmnd->device->lun; | |
2188 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, | |
2189 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
2190 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, | |
2191 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
2192 | fast_path_evt->un.check_cond_evt.sense_key = | |
2193 | cmnd->sense_buffer[2] & 0xf; | |
2194 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; | |
2195 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; | |
2196 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && | |
2197 | fcpi_parm && | |
2198 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || | |
2199 | ((scsi_status == SAM_STAT_GOOD) && | |
2200 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { | |
2201 | /* | |
2202 | * If status is good or resid does not match with fcp_param and | |
2203 | * there is valid fcpi_parm, then there is a read_check error | |
2204 | */ | |
2205 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
2206 | if (!fast_path_evt) | |
2207 | return; | |
2208 | fast_path_evt->un.read_check_error.header.event_type = | |
2209 | FC_REG_FABRIC_EVENT; | |
2210 | fast_path_evt->un.read_check_error.header.subcategory = | |
2211 | LPFC_EVENT_FCPRDCHKERR; | |
2212 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, | |
2213 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
2214 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, | |
2215 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
2216 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; | |
2217 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; | |
2218 | fast_path_evt->un.read_check_error.fcpiparam = | |
2219 | fcpi_parm; | |
2220 | } else | |
2221 | return; | |
2222 | ||
2223 | fast_path_evt->vport = vport; | |
2224 | spin_lock_irqsave(&phba->hbalock, flags); | |
2225 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); | |
2226 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
2227 | lpfc_worker_wake_up(phba); | |
2228 | return; | |
2229 | } | |
9bad7671 JS |
2230 | |
2231 | /** | |
f1126688 | 2232 | * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev |
3772a991 | 2233 | * @phba: The HBA for which this call is being executed. |
9bad7671 JS |
2234 | * @psb: The scsi buffer which is going to be un-mapped. |
2235 | * | |
2236 | * This routine does DMA un-mapping of scatter gather list of scsi command | |
3772a991 | 2237 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
9bad7671 | 2238 | **/ |
bcf4dbfa | 2239 | static void |
f1126688 | 2240 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
bcf4dbfa JS |
2241 | { |
2242 | /* | |
2243 | * There are only two special cases to consider. (1) the scsi command | |
2244 | * requested scatter-gather usage or (2) the scsi command allocated | |
2245 | * a request buffer, but did not request use_sg. There is a third | |
2246 | * case, but it does not require resource deallocation. | |
2247 | */ | |
a0b4f78f FT |
2248 | if (psb->seg_cnt > 0) |
2249 | scsi_dma_unmap(psb->pCmd); | |
e2a0a9d6 JS |
2250 | if (psb->prot_seg_cnt > 0) |
2251 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), | |
2252 | scsi_prot_sg_count(psb->pCmd), | |
2253 | psb->pCmd->sc_data_direction); | |
bcf4dbfa JS |
2254 | } |
2255 | ||
9bad7671 | 2256 | /** |
3621a710 | 2257 | * lpfc_handler_fcp_err - FCP response handler |
9bad7671 JS |
2258 | * @vport: The virtual port for which this call is being executed. |
2259 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | |
2260 | * @rsp_iocb: The response IOCB which contains FCP error. | |
2261 | * | |
2262 | * This routine is called to process response IOCB with status field | |
2263 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command | |
2264 | * based upon SCSI and FCP error. | |
2265 | **/ | |
dea3101e | 2266 | static void |
2e0fef85 JS |
2267 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
2268 | struct lpfc_iocbq *rsp_iocb) | |
dea3101e | 2269 | { |
2270 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; | |
2271 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; | |
2272 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; | |
7054a606 | 2273 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
dea3101e | 2274 | uint32_t resp_info = fcprsp->rspStatus2; |
2275 | uint32_t scsi_status = fcprsp->rspStatus3; | |
c7743956 | 2276 | uint32_t *lp; |
dea3101e | 2277 | uint32_t host_status = DID_OK; |
2278 | uint32_t rsplen = 0; | |
c7743956 | 2279 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
dea3101e | 2280 | |
ea2151b4 | 2281 | |
dea3101e | 2282 | /* |
2283 | * If this is a task management command, there is no | |
2284 | * scsi packet associated with this lpfc_cmd. The driver | |
2285 | * consumes it. | |
2286 | */ | |
2287 | if (fcpcmd->fcpCntl2) { | |
2288 | scsi_status = 0; | |
2289 | goto out; | |
2290 | } | |
2291 | ||
6a9c52cf JS |
2292 | if (resp_info & RSP_LEN_VALID) { |
2293 | rsplen = be32_to_cpu(fcprsp->rspRspLen); | |
e40a02c1 | 2294 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
6a9c52cf JS |
2295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
2296 | "2719 Invalid response length: " | |
2297 | "tgt x%x lun x%x cmnd x%x rsplen x%x\n", | |
2298 | cmnd->device->id, | |
2299 | cmnd->device->lun, cmnd->cmnd[0], | |
2300 | rsplen); | |
2301 | host_status = DID_ERROR; | |
2302 | goto out; | |
2303 | } | |
e40a02c1 JS |
2304 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
2305 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
2306 | "2757 Protocol failure detected during " | |
2307 | "processing of FCP I/O op: " | |
2308 | "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n", | |
2309 | cmnd->device->id, | |
2310 | cmnd->device->lun, cmnd->cmnd[0], | |
2311 | fcprsp->rspInfo3); | |
2312 | host_status = DID_ERROR; | |
2313 | goto out; | |
2314 | } | |
6a9c52cf JS |
2315 | } |
2316 | ||
c7743956 JS |
2317 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
2318 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); | |
2319 | if (snslen > SCSI_SENSE_BUFFERSIZE) | |
2320 | snslen = SCSI_SENSE_BUFFERSIZE; | |
2321 | ||
2322 | if (resp_info & RSP_LEN_VALID) | |
2323 | rsplen = be32_to_cpu(fcprsp->rspRspLen); | |
2324 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); | |
2325 | } | |
2326 | lp = (uint32_t *)cmnd->sense_buffer; | |
2327 | ||
73d91e50 JS |
2328 | if (!scsi_status && (resp_info & RESID_UNDER) && |
2329 | vport->cfg_log_verbose & LOG_FCP_UNDER) | |
2330 | logit = LOG_FCP_UNDER; | |
c7743956 | 2331 | |
e8b62011 | 2332 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
e2a0a9d6 | 2333 | "9024 FCP command x%x failed: x%x SNS x%x x%x " |
e8b62011 JS |
2334 | "Data: x%x x%x x%x x%x x%x\n", |
2335 | cmnd->cmnd[0], scsi_status, | |
2336 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, | |
2337 | be32_to_cpu(fcprsp->rspResId), | |
2338 | be32_to_cpu(fcprsp->rspSnsLen), | |
2339 | be32_to_cpu(fcprsp->rspRspLen), | |
2340 | fcprsp->rspInfo3); | |
dea3101e | 2341 | |
a0b4f78f | 2342 | scsi_set_resid(cmnd, 0); |
dea3101e | 2343 | if (resp_info & RESID_UNDER) { |
a0b4f78f | 2344 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
dea3101e | 2345 | |
73d91e50 | 2346 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
e2a0a9d6 | 2347 | "9025 FCP Read Underrun, expected %d, " |
e8b62011 JS |
2348 | "residual %d Data: x%x x%x x%x\n", |
2349 | be32_to_cpu(fcpcmd->fcpDl), | |
2350 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], | |
2351 | cmnd->underflow); | |
dea3101e | 2352 | |
7054a606 JS |
2353 | /* |
2354 | * If there is an under run check if under run reported by | |
2355 | * storage array is same as the under run reported by HBA. | |
2356 | * If this is not same, there is a dropped frame. | |
2357 | */ | |
2358 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && | |
2359 | fcpi_parm && | |
a0b4f78f | 2360 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
e8b62011 JS |
2361 | lpfc_printf_vlog(vport, KERN_WARNING, |
2362 | LOG_FCP | LOG_FCP_ERROR, | |
e2a0a9d6 | 2363 | "9026 FCP Read Check Error " |
e8b62011 JS |
2364 | "and Underrun Data: x%x x%x x%x x%x\n", |
2365 | be32_to_cpu(fcpcmd->fcpDl), | |
2366 | scsi_get_resid(cmnd), fcpi_parm, | |
2367 | cmnd->cmnd[0]); | |
a0b4f78f | 2368 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
7054a606 JS |
2369 | host_status = DID_ERROR; |
2370 | } | |
dea3101e | 2371 | /* |
2372 | * The cmnd->underflow is the minimum number of bytes that must | |
25985edc | 2373 | * be transferred for this command. Provided a sense condition |
dea3101e | 2374 | * is not present, make sure the actual amount transferred is at |
2375 | * least the underflow value or fail. | |
2376 | */ | |
2377 | if (!(resp_info & SNS_LEN_VALID) && | |
2378 | (scsi_status == SAM_STAT_GOOD) && | |
a0b4f78f FT |
2379 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
2380 | < cmnd->underflow)) { | |
e8b62011 | 2381 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
e2a0a9d6 | 2382 | "9027 FCP command x%x residual " |
e8b62011 JS |
2383 | "underrun converted to error " |
2384 | "Data: x%x x%x x%x\n", | |
66dbfbe6 | 2385 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
e8b62011 | 2386 | scsi_get_resid(cmnd), cmnd->underflow); |
dea3101e | 2387 | host_status = DID_ERROR; |
2388 | } | |
2389 | } else if (resp_info & RESID_OVER) { | |
e8b62011 | 2390 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
e2a0a9d6 | 2391 | "9028 FCP command x%x residual overrun error. " |
e4e74273 | 2392 | "Data: x%x x%x\n", cmnd->cmnd[0], |
e8b62011 | 2393 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
dea3101e | 2394 | host_status = DID_ERROR; |
2395 | ||
2396 | /* | |
2397 | * Check SLI validation that all the transfer was actually done | |
2398 | * (fcpi_parm should be zero). Apply check only to reads. | |
2399 | */ | |
eee8877e | 2400 | } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
e8b62011 | 2401 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
e2a0a9d6 | 2402 | "9029 FCP Read Check Error Data: " |
eee8877e | 2403 | "x%x x%x x%x x%x x%x\n", |
e8b62011 JS |
2404 | be32_to_cpu(fcpcmd->fcpDl), |
2405 | be32_to_cpu(fcprsp->rspResId), | |
eee8877e JS |
2406 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
2407 | switch (scsi_status) { | |
2408 | case SAM_STAT_GOOD: | |
2409 | case SAM_STAT_CHECK_CONDITION: | |
2410 | /* Fabric dropped a data frame. Fail any successful | |
2411 | * command in which we detected dropped frames. | |
2412 | * A status of good or some check conditions could | |
2413 | * be considered a successful command. | |
2414 | */ | |
2415 | host_status = DID_ERROR; | |
2416 | break; | |
2417 | } | |
a0b4f78f | 2418 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
dea3101e | 2419 | } |
2420 | ||
2421 | out: | |
2422 | cmnd->result = ScsiResult(host_status, scsi_status); | |
ea2151b4 | 2423 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
dea3101e | 2424 | } |
2425 | ||
9bad7671 | 2426 | /** |
3621a710 | 2427 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
9bad7671 JS |
2428 | * @phba: The Hba for which this call is being executed. |
2429 | * @pIocbIn: The command IOCBQ for the scsi cmnd. | |
3772a991 | 2430 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
9bad7671 JS |
2431 | * |
2432 | * This routine assigns scsi command result by looking into response IOCB | |
2433 | * status field appropriately. This routine handles QUEUE FULL condition as | |
2434 | * well by ramping down device queue depth. | |
2435 | **/ | |
dea3101e | 2436 | static void |
2437 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, | |
2438 | struct lpfc_iocbq *pIocbOut) | |
2439 | { | |
2440 | struct lpfc_scsi_buf *lpfc_cmd = | |
2441 | (struct lpfc_scsi_buf *) pIocbIn->context1; | |
2e0fef85 | 2442 | struct lpfc_vport *vport = pIocbIn->vport; |
dea3101e | 2443 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
2444 | struct lpfc_nodelist *pnode = rdata->pnode; | |
75baf696 | 2445 | struct scsi_cmnd *cmd; |
445cf4f4 | 2446 | int result; |
a257bf90 | 2447 | struct scsi_device *tmp_sdev; |
5ffc266e | 2448 | int depth; |
fa61a54e | 2449 | unsigned long flags; |
ea2151b4 | 2450 | struct lpfc_fast_path_event *fast_path_evt; |
75baf696 | 2451 | struct Scsi_Host *shost; |
a257bf90 | 2452 | uint32_t queue_depth, scsi_id; |
73d91e50 | 2453 | uint32_t logit = LOG_FCP; |
dea3101e | 2454 | |
75baf696 JS |
2455 | /* Sanity check on return of outstanding command */ |
2456 | if (!(lpfc_cmd->pCmd)) | |
2457 | return; | |
2458 | cmd = lpfc_cmd->pCmd; | |
2459 | shost = cmd->device->host; | |
2460 | ||
dea3101e | 2461 | lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; |
2462 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; | |
341af102 JS |
2463 | /* pick up SLI4 exhange busy status from HBA */ |
2464 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; | |
2465 | ||
109f6ed0 JS |
2466 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
2467 | atomic_dec(&pnode->cmd_pending); | |
dea3101e | 2468 | |
2469 | if (lpfc_cmd->status) { | |
2470 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && | |
2471 | (lpfc_cmd->result & IOERR_DRVR_MASK)) | |
2472 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; | |
2473 | else if (lpfc_cmd->status >= IOSTAT_CNT) | |
2474 | lpfc_cmd->status = IOSTAT_DEFAULT; | |
73d91e50 JS |
2475 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR |
2476 | && !lpfc_cmd->fcp_rsp->rspStatus3 | |
2477 | && (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) | |
2478 | && !(phba->cfg_log_verbose & LOG_FCP_UNDER)) | |
2479 | logit = 0; | |
2480 | else | |
2481 | logit = LOG_FCP | LOG_FCP_UNDER; | |
2482 | lpfc_printf_vlog(vport, KERN_WARNING, logit, | |
2483 | "9030 FCP cmd x%x failed <%d/%d> " | |
2484 | "status: x%x result: x%x Data: x%x x%x\n", | |
2485 | cmd->cmnd[0], | |
2486 | cmd->device ? cmd->device->id : 0xffff, | |
2487 | cmd->device ? cmd->device->lun : 0xffff, | |
2488 | lpfc_cmd->status, lpfc_cmd->result, | |
2489 | pIocbOut->iocb.ulpContext, | |
2490 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); | |
dea3101e | 2491 | |
2492 | switch (lpfc_cmd->status) { | |
2493 | case IOSTAT_FCP_RSP_ERROR: | |
2494 | /* Call FCP RSP handler to determine result */ | |
2e0fef85 | 2495 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
dea3101e | 2496 | break; |
2497 | case IOSTAT_NPORT_BSY: | |
2498 | case IOSTAT_FABRIC_BSY: | |
0f1f53a7 | 2499 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
ea2151b4 JS |
2500 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
2501 | if (!fast_path_evt) | |
2502 | break; | |
2503 | fast_path_evt->un.fabric_evt.event_type = | |
2504 | FC_REG_FABRIC_EVENT; | |
2505 | fast_path_evt->un.fabric_evt.subcategory = | |
2506 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? | |
2507 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; | |
2508 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { | |
2509 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, | |
2510 | &pnode->nlp_portname, | |
2511 | sizeof(struct lpfc_name)); | |
2512 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, | |
2513 | &pnode->nlp_nodename, | |
2514 | sizeof(struct lpfc_name)); | |
2515 | } | |
2516 | fast_path_evt->vport = vport; | |
2517 | fast_path_evt->work_evt.evt = | |
2518 | LPFC_EVT_FASTPATH_MGMT_EVT; | |
2519 | spin_lock_irqsave(&phba->hbalock, flags); | |
2520 | list_add_tail(&fast_path_evt->work_evt.evt_listp, | |
2521 | &phba->work_list); | |
2522 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
2523 | lpfc_worker_wake_up(phba); | |
dea3101e | 2524 | break; |
92d7f7b0 | 2525 | case IOSTAT_LOCAL_REJECT: |
1151e3ec | 2526 | case IOSTAT_REMOTE_STOP: |
ab56dc2e JS |
2527 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
2528 | lpfc_cmd->result == | |
2529 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || | |
2530 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || | |
2531 | lpfc_cmd->result == | |
2532 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { | |
2533 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); | |
2534 | break; | |
2535 | } | |
d7c255b2 | 2536 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
92d7f7b0 | 2537 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
b92938b4 JS |
2538 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
2539 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { | |
92d7f7b0 | 2540 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
58da1ffb | 2541 | break; |
e2a0a9d6 | 2542 | } |
e2a0a9d6 JS |
2543 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
2544 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && | |
2545 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { | |
2546 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { | |
2547 | /* | |
2548 | * This is a response for a BG enabled | |
2549 | * cmd. Parse BG error | |
2550 | */ | |
2551 | lpfc_parse_bg_err(phba, lpfc_cmd, | |
2552 | pIocbOut); | |
2553 | break; | |
2554 | } else { | |
2555 | lpfc_printf_vlog(vport, KERN_WARNING, | |
2556 | LOG_BG, | |
2557 | "9031 non-zero BGSTAT " | |
6a9c52cf | 2558 | "on unprotected cmd\n"); |
e2a0a9d6 JS |
2559 | } |
2560 | } | |
1151e3ec JS |
2561 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
2562 | && (phba->sli_rev == LPFC_SLI_REV4) | |
2563 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { | |
2564 | /* This IO was aborted by the target, we don't | |
2565 | * know the rxid and because we did not send the | |
2566 | * ABTS we cannot generate and RRQ. | |
2567 | */ | |
2568 | lpfc_set_rrq_active(phba, pnode, | |
2569 | lpfc_cmd->cur_iocbq.sli4_xritag, | |
2570 | 0, 0); | |
2571 | } | |
e2a0a9d6 | 2572 | /* else: fall through */ |
dea3101e | 2573 | default: |
2574 | cmd->result = ScsiResult(DID_ERROR, 0); | |
2575 | break; | |
2576 | } | |
2577 | ||
58da1ffb | 2578 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
19a7b4ae | 2579 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
0f1f53a7 JS |
2580 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
2581 | SAM_STAT_BUSY); | |
ab56dc2e | 2582 | } else |
dea3101e | 2583 | cmd->result = ScsiResult(DID_OK, 0); |
dea3101e | 2584 | |
2585 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { | |
2586 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; | |
2587 | ||
e8b62011 JS |
2588 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
2589 | "0710 Iodone <%d/%d> cmd %p, error " | |
2590 | "x%x SNS x%x x%x Data: x%x x%x\n", | |
2591 | cmd->device->id, cmd->device->lun, cmd, | |
2592 | cmd->result, *lp, *(lp + 3), cmd->retries, | |
2593 | scsi_get_resid(cmd)); | |
dea3101e | 2594 | } |
2595 | ||
ea2151b4 | 2596 | lpfc_update_stats(phba, lpfc_cmd); |
445cf4f4 | 2597 | result = cmd->result; |
977b5a0a JS |
2598 | if (vport->cfg_max_scsicmpl_time && |
2599 | time_after(jiffies, lpfc_cmd->start_time + | |
2600 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { | |
a257bf90 | 2601 | spin_lock_irqsave(shost->host_lock, flags); |
109f6ed0 JS |
2602 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
2603 | if (pnode->cmd_qdepth > | |
2604 | atomic_read(&pnode->cmd_pending) && | |
2605 | (atomic_read(&pnode->cmd_pending) > | |
2606 | LPFC_MIN_TGT_QDEPTH) && | |
2607 | ((cmd->cmnd[0] == READ_10) || | |
2608 | (cmd->cmnd[0] == WRITE_10))) | |
2609 | pnode->cmd_qdepth = | |
2610 | atomic_read(&pnode->cmd_pending); | |
2611 | ||
2612 | pnode->last_change_time = jiffies; | |
2613 | } | |
a257bf90 | 2614 | spin_unlock_irqrestore(shost->host_lock, flags); |
109f6ed0 | 2615 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
7dc517df | 2616 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
977b5a0a | 2617 | time_after(jiffies, pnode->last_change_time + |
109f6ed0 | 2618 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
a257bf90 | 2619 | spin_lock_irqsave(shost->host_lock, flags); |
7dc517df JS |
2620 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
2621 | / 100; | |
2622 | depth = depth ? depth : 1; | |
2623 | pnode->cmd_qdepth += depth; | |
2624 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) | |
2625 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; | |
109f6ed0 | 2626 | pnode->last_change_time = jiffies; |
a257bf90 | 2627 | spin_unlock_irqrestore(shost->host_lock, flags); |
109f6ed0 | 2628 | } |
977b5a0a JS |
2629 | } |
2630 | ||
1dcb58e5 | 2631 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
a257bf90 JS |
2632 | |
2633 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ | |
2634 | queue_depth = cmd->device->queue_depth; | |
2635 | scsi_id = cmd->device->id; | |
0bd4ca25 JSEC |
2636 | cmd->scsi_done(cmd); |
2637 | ||
b808608b | 2638 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
fa61a54e JS |
2639 | /* |
2640 | * If there is a thread waiting for command completion | |
2641 | * wake up the thread. | |
2642 | */ | |
a257bf90 | 2643 | spin_lock_irqsave(shost->host_lock, flags); |
495a714c | 2644 | lpfc_cmd->pCmd = NULL; |
fa61a54e JS |
2645 | if (lpfc_cmd->waitq) |
2646 | wake_up(lpfc_cmd->waitq); | |
a257bf90 | 2647 | spin_unlock_irqrestore(shost->host_lock, flags); |
b808608b JW |
2648 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
2649 | return; | |
2650 | } | |
2651 | ||
92d7f7b0 | 2652 | if (!result) |
a257bf90 | 2653 | lpfc_rampup_queue_depth(vport, queue_depth); |
92d7f7b0 | 2654 | |
445cf4f4 JSEC |
2655 | /* |
2656 | * Check for queue full. If the lun is reporting queue full, then | |
2657 | * back off the lun queue depth to prevent target overloads. | |
2658 | */ | |
58da1ffb JS |
2659 | if (result == SAM_STAT_TASK_SET_FULL && pnode && |
2660 | NLP_CHK_NODE_ACT(pnode)) { | |
a257bf90 JS |
2661 | shost_for_each_device(tmp_sdev, shost) { |
2662 | if (tmp_sdev->id != scsi_id) | |
445cf4f4 JSEC |
2663 | continue; |
2664 | depth = scsi_track_queue_full(tmp_sdev, | |
5ffc266e JS |
2665 | tmp_sdev->queue_depth-1); |
2666 | if (depth <= 0) | |
2667 | continue; | |
e8b62011 JS |
2668 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
2669 | "0711 detected queue full - lun queue " | |
2670 | "depth adjusted to %d.\n", depth); | |
ea2151b4 | 2671 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
5ffc266e JS |
2672 | pnode, |
2673 | tmp_sdev->lun, | |
2674 | depth+1, depth); | |
445cf4f4 JSEC |
2675 | } |
2676 | } | |
2677 | ||
fa61a54e JS |
2678 | /* |
2679 | * If there is a thread waiting for command completion | |
2680 | * wake up the thread. | |
2681 | */ | |
a257bf90 | 2682 | spin_lock_irqsave(shost->host_lock, flags); |
495a714c | 2683 | lpfc_cmd->pCmd = NULL; |
fa61a54e JS |
2684 | if (lpfc_cmd->waitq) |
2685 | wake_up(lpfc_cmd->waitq); | |
a257bf90 | 2686 | spin_unlock_irqrestore(shost->host_lock, flags); |
fa61a54e | 2687 | |
0bd4ca25 | 2688 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
dea3101e | 2689 | } |
2690 | ||
34b02dcd | 2691 | /** |
3621a710 | 2692 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
34b02dcd JS |
2693 | * @data: A pointer to the immediate command data portion of the IOCB. |
2694 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. | |
2695 | * | |
2696 | * The routine copies the entire FCP command from @fcp_cmnd to @data while | |
2697 | * byte swapping the data to big endian format for transmission on the wire. | |
2698 | **/ | |
2699 | static void | |
2700 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) | |
2701 | { | |
2702 | int i, j; | |
2703 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); | |
2704 | i += sizeof(uint32_t), j++) { | |
2705 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); | |
2706 | } | |
2707 | } | |
2708 | ||
9bad7671 | 2709 | /** |
f1126688 | 2710 | * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit |
9bad7671 JS |
2711 | * @vport: The virtual port for which this call is being executed. |
2712 | * @lpfc_cmd: The scsi command which needs to send. | |
2713 | * @pnode: Pointer to lpfc_nodelist. | |
2714 | * | |
2715 | * This routine initializes fcp_cmnd and iocb data structure from scsi command | |
3772a991 | 2716 | * to transfer for device with SLI3 interface spec. |
9bad7671 | 2717 | **/ |
dea3101e | 2718 | static void |
f1126688 | 2719 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
2e0fef85 | 2720 | struct lpfc_nodelist *pnode) |
dea3101e | 2721 | { |
2e0fef85 | 2722 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2723 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
2724 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
2725 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
2726 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); | |
2727 | int datadir = scsi_cmnd->sc_data_direction; | |
7e2b19fb | 2728 | char tag[2]; |
dea3101e | 2729 | |
58da1ffb JS |
2730 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
2731 | return; | |
2732 | ||
dea3101e | 2733 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
69859dc4 JSEC |
2734 | /* clear task management bits */ |
2735 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; | |
dea3101e | 2736 | |
91886523 JSEC |
2737 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
2738 | &lpfc_cmd->fcp_cmnd->fcp_lun); | |
dea3101e | 2739 | |
2740 | memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); | |
2741 | ||
7e2b19fb JS |
2742 | if (scsi_populate_tag_msg(scsi_cmnd, tag)) { |
2743 | switch (tag[0]) { | |
dea3101e | 2744 | case HEAD_OF_QUEUE_TAG: |
2745 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; | |
2746 | break; | |
2747 | case ORDERED_QUEUE_TAG: | |
2748 | fcp_cmnd->fcpCntl1 = ORDERED_Q; | |
2749 | break; | |
2750 | default: | |
2751 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; | |
2752 | break; | |
2753 | } | |
2754 | } else | |
2755 | fcp_cmnd->fcpCntl1 = 0; | |
2756 | ||
2757 | /* | |
2758 | * There are three possibilities here - use scatter-gather segment, use | |
2759 | * the single mapping, or neither. Start the lpfc command prep by | |
2760 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
2761 | * data bde entry. | |
2762 | */ | |
a0b4f78f | 2763 | if (scsi_sg_count(scsi_cmnd)) { |
dea3101e | 2764 | if (datadir == DMA_TO_DEVICE) { |
2765 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; | |
3772a991 JS |
2766 | if (phba->sli_rev < LPFC_SLI_REV4) { |
2767 | iocb_cmd->un.fcpi.fcpi_parm = 0; | |
2768 | iocb_cmd->ulpPU = 0; | |
2769 | } else | |
2770 | iocb_cmd->ulpPU = PARM_READ_CHECK; | |
dea3101e | 2771 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
2772 | phba->fc4OutputRequests++; | |
2773 | } else { | |
2774 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; | |
2775 | iocb_cmd->ulpPU = PARM_READ_CHECK; | |
dea3101e | 2776 | fcp_cmnd->fcpCntl3 = READ_DATA; |
2777 | phba->fc4InputRequests++; | |
2778 | } | |
2779 | } else { | |
2780 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; | |
2781 | iocb_cmd->un.fcpi.fcpi_parm = 0; | |
2782 | iocb_cmd->ulpPU = 0; | |
2783 | fcp_cmnd->fcpCntl3 = 0; | |
2784 | phba->fc4ControlRequests++; | |
2785 | } | |
e2a0a9d6 JS |
2786 | if (phba->sli_rev == 3 && |
2787 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) | |
34b02dcd | 2788 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
dea3101e | 2789 | /* |
2790 | * Finish initializing those IOCB fields that are independent | |
2791 | * of the scsi_cmnd request_buffer | |
2792 | */ | |
2793 | piocbq->iocb.ulpContext = pnode->nlp_rpi; | |
6d368e53 JS |
2794 | if (phba->sli_rev == LPFC_SLI_REV4) |
2795 | piocbq->iocb.ulpContext = | |
2796 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; | |
dea3101e | 2797 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
2798 | piocbq->iocb.ulpFCP2Rcvy = 1; | |
09372820 JS |
2799 | else |
2800 | piocbq->iocb.ulpFCP2Rcvy = 0; | |
dea3101e | 2801 | |
2802 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); | |
2803 | piocbq->context1 = lpfc_cmd; | |
2804 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; | |
2805 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; | |
2e0fef85 | 2806 | piocbq->vport = vport; |
dea3101e | 2807 | } |
2808 | ||
da0436e9 | 2809 | /** |
6d368e53 | 2810 | * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit |
9bad7671 JS |
2811 | * @vport: The virtual port for which this call is being executed. |
2812 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | |
2813 | * @lun: Logical unit number. | |
2814 | * @task_mgmt_cmd: SCSI task management command. | |
2815 | * | |
3772a991 JS |
2816 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
2817 | * for device with SLI-3 interface spec. | |
9bad7671 JS |
2818 | * |
2819 | * Return codes: | |
2820 | * 0 - Error | |
2821 | * 1 - Success | |
2822 | **/ | |
dea3101e | 2823 | static int |
f1126688 | 2824 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
dea3101e | 2825 | struct lpfc_scsi_buf *lpfc_cmd, |
420b630d | 2826 | unsigned int lun, |
dea3101e | 2827 | uint8_t task_mgmt_cmd) |
2828 | { | |
dea3101e | 2829 | struct lpfc_iocbq *piocbq; |
2830 | IOCB_t *piocb; | |
2831 | struct fcp_cmnd *fcp_cmnd; | |
0b18ac42 | 2832 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
dea3101e | 2833 | struct lpfc_nodelist *ndlp = rdata->pnode; |
2834 | ||
58da1ffb JS |
2835 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
2836 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) | |
dea3101e | 2837 | return 0; |
dea3101e | 2838 | |
dea3101e | 2839 | piocbq = &(lpfc_cmd->cur_iocbq); |
2e0fef85 JS |
2840 | piocbq->vport = vport; |
2841 | ||
dea3101e | 2842 | piocb = &piocbq->iocb; |
2843 | ||
2844 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
34b02dcd JS |
2845 | /* Clear out any old data in the FCP command area */ |
2846 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); | |
2847 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); | |
dea3101e | 2848 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
e2a0a9d6 JS |
2849 | if (vport->phba->sli_rev == 3 && |
2850 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) | |
34b02dcd | 2851 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
dea3101e | 2852 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
dea3101e | 2853 | piocb->ulpContext = ndlp->nlp_rpi; |
6d368e53 JS |
2854 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
2855 | piocb->ulpContext = | |
2856 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; | |
2857 | } | |
dea3101e | 2858 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
2859 | piocb->ulpFCP2Rcvy = 1; | |
2860 | } | |
2861 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); | |
2862 | ||
2863 | /* ulpTimeout is only one byte */ | |
2864 | if (lpfc_cmd->timeout > 0xff) { | |
2865 | /* | |
2866 | * Do not timeout the command at the firmware level. | |
2867 | * The driver will provide the timeout mechanism. | |
2868 | */ | |
2869 | piocb->ulpTimeout = 0; | |
f1126688 | 2870 | } else |
dea3101e | 2871 | piocb->ulpTimeout = lpfc_cmd->timeout; |
da0436e9 | 2872 | |
f1126688 JS |
2873 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
2874 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); | |
3772a991 | 2875 | |
f1126688 | 2876 | return 1; |
3772a991 JS |
2877 | } |
2878 | ||
2879 | /** | |
25985edc | 2880 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
3772a991 JS |
2881 | * @phba: The hba struct for which this call is being executed. |
2882 | * @dev_grp: The HBA PCI-Device group number. | |
2883 | * | |
2884 | * This routine sets up the SCSI interface API function jump table in @phba | |
2885 | * struct. | |
2886 | * Returns: 0 - success, -ENODEV - failure. | |
2887 | **/ | |
2888 | int | |
2889 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
2890 | { | |
2891 | ||
f1126688 JS |
2892 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
2893 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; | |
f1126688 | 2894 | |
3772a991 JS |
2895 | switch (dev_grp) { |
2896 | case LPFC_PCI_DEV_LP: | |
2897 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; | |
2898 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; | |
3772a991 | 2899 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
19ca7609 | 2900 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
3772a991 | 2901 | break; |
da0436e9 JS |
2902 | case LPFC_PCI_DEV_OC: |
2903 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; | |
2904 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; | |
da0436e9 | 2905 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
19ca7609 | 2906 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
da0436e9 | 2907 | break; |
3772a991 JS |
2908 | default: |
2909 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2910 | "1418 Invalid HBA PCI-device group: 0x%x\n", | |
2911 | dev_grp); | |
2912 | return -ENODEV; | |
2913 | break; | |
2914 | } | |
3772a991 | 2915 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
84d1b006 | 2916 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
3772a991 JS |
2917 | return 0; |
2918 | } | |
2919 | ||
9bad7671 | 2920 | /** |
3621a710 | 2921 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
9bad7671 JS |
2922 | * @phba: The Hba for which this call is being executed. |
2923 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. | |
2924 | * @rspiocbq: Pointer to lpfc_iocbq data structure. | |
2925 | * | |
2926 | * This routine is IOCB completion routine for device reset and target reset | |
2927 | * routine. This routine release scsi buffer associated with lpfc_cmd. | |
2928 | **/ | |
7054a606 JS |
2929 | static void |
2930 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, | |
2931 | struct lpfc_iocbq *cmdiocbq, | |
2932 | struct lpfc_iocbq *rspiocbq) | |
2933 | { | |
2934 | struct lpfc_scsi_buf *lpfc_cmd = | |
2935 | (struct lpfc_scsi_buf *) cmdiocbq->context1; | |
2936 | if (lpfc_cmd) | |
2937 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
2938 | return; | |
2939 | } | |
2940 | ||
9bad7671 | 2941 | /** |
3621a710 | 2942 | * lpfc_info - Info entry point of scsi_host_template data structure |
9bad7671 JS |
2943 | * @host: The scsi host for which this call is being executed. |
2944 | * | |
2945 | * This routine provides module information about hba. | |
2946 | * | |
2947 | * Reutrn code: | |
2948 | * Pointer to char - Success. | |
2949 | **/ | |
dea3101e | 2950 | const char * |
2951 | lpfc_info(struct Scsi_Host *host) | |
2952 | { | |
2e0fef85 JS |
2953 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
2954 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2955 | int len; |
2956 | static char lpfcinfobuf[384]; | |
2957 | ||
2958 | memset(lpfcinfobuf,0,384); | |
2959 | if (phba && phba->pcidev){ | |
2960 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); | |
2961 | len = strlen(lpfcinfobuf); | |
2962 | snprintf(lpfcinfobuf + len, | |
2963 | 384-len, | |
2964 | " on PCI bus %02x device %02x irq %d", | |
2965 | phba->pcidev->bus->number, | |
2966 | phba->pcidev->devfn, | |
2967 | phba->pcidev->irq); | |
2968 | len = strlen(lpfcinfobuf); | |
2969 | if (phba->Port[0]) { | |
2970 | snprintf(lpfcinfobuf + len, | |
2971 | 384-len, | |
2972 | " port %s", | |
2973 | phba->Port); | |
2974 | } | |
65467b6b JS |
2975 | len = strlen(lpfcinfobuf); |
2976 | if (phba->sli4_hba.link_state.logical_speed) { | |
2977 | snprintf(lpfcinfobuf + len, | |
2978 | 384-len, | |
2979 | " Logical Link Speed: %d Mbps", | |
2980 | phba->sli4_hba.link_state.logical_speed * 10); | |
2981 | } | |
dea3101e | 2982 | } |
2983 | return lpfcinfobuf; | |
2984 | } | |
2985 | ||
9bad7671 | 2986 | /** |
3621a710 | 2987 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
9bad7671 JS |
2988 | * @phba: The Hba for which this call is being executed. |
2989 | * | |
2990 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. | |
2991 | * The default value of cfg_poll_tmo is 10 milliseconds. | |
2992 | **/ | |
875fbdfe JSEC |
2993 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
2994 | { | |
2995 | unsigned long poll_tmo_expires = | |
2996 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); | |
2997 | ||
2998 | if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt) | |
2999 | mod_timer(&phba->fcp_poll_timer, | |
3000 | poll_tmo_expires); | |
3001 | } | |
3002 | ||
9bad7671 | 3003 | /** |
3621a710 | 3004 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
9bad7671 JS |
3005 | * @phba: The Hba for which this call is being executed. |
3006 | * | |
3007 | * This routine starts the fcp_poll_timer of @phba. | |
3008 | **/ | |
875fbdfe JSEC |
3009 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
3010 | { | |
3011 | lpfc_poll_rearm_timer(phba); | |
3012 | } | |
3013 | ||
9bad7671 | 3014 | /** |
3621a710 | 3015 | * lpfc_poll_timeout - Restart polling timer |
9bad7671 JS |
3016 | * @ptr: Map to lpfc_hba data structure pointer. |
3017 | * | |
3018 | * This routine restarts fcp_poll timer, when FCP ring polling is enable | |
3019 | * and FCP Ring interrupt is disable. | |
3020 | **/ | |
3021 | ||
875fbdfe JSEC |
3022 | void lpfc_poll_timeout(unsigned long ptr) |
3023 | { | |
2e0fef85 | 3024 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
875fbdfe JSEC |
3025 | |
3026 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { | |
45ed1190 JS |
3027 | lpfc_sli_handle_fast_ring_event(phba, |
3028 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
3029 | ||
875fbdfe JSEC |
3030 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
3031 | lpfc_poll_rearm_timer(phba); | |
3032 | } | |
875fbdfe JSEC |
3033 | } |
3034 | ||
9bad7671 | 3035 | /** |
3621a710 | 3036 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
9bad7671 JS |
3037 | * @cmnd: Pointer to scsi_cmnd data structure. |
3038 | * @done: Pointer to done routine. | |
3039 | * | |
3040 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. | |
3041 | * This routine prepares an IOCB from scsi command and provides to firmware. | |
3042 | * The @done callback is invoked after driver finished processing the command. | |
3043 | * | |
3044 | * Return value : | |
3045 | * 0 - Success | |
3046 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. | |
3047 | **/ | |
dea3101e | 3048 | static int |
f281233d | 3049 | lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) |
dea3101e | 3050 | { |
2e0fef85 JS |
3051 | struct Scsi_Host *shost = cmnd->device->host; |
3052 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3053 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3054 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
1c6f4ef5 | 3055 | struct lpfc_nodelist *ndlp; |
0bd4ca25 | 3056 | struct lpfc_scsi_buf *lpfc_cmd; |
19a7b4ae | 3057 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
19a7b4ae | 3058 | int err; |
dea3101e | 3059 | |
19a7b4ae JSEC |
3060 | err = fc_remote_port_chkready(rport); |
3061 | if (err) { | |
3062 | cmnd->result = err; | |
dea3101e | 3063 | goto out_fail_command; |
3064 | } | |
1c6f4ef5 | 3065 | ndlp = rdata->pnode; |
dea3101e | 3066 | |
bf08611b JS |
3067 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
3068 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) || | |
3069 | (phba->sli_rev == LPFC_SLI_REV4))) { | |
e2a0a9d6 | 3070 | |
6a9c52cf JS |
3071 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
3072 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" | |
3073 | " op:%02x str=%s without registering for" | |
3074 | " BlockGuard - Rejecting command\n", | |
e2a0a9d6 JS |
3075 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
3076 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
3077 | goto out_fail_command; | |
3078 | } | |
3079 | ||
dea3101e | 3080 | /* |
19a7b4ae JSEC |
3081 | * Catch race where our node has transitioned, but the |
3082 | * transport is still transitioning. | |
dea3101e | 3083 | */ |
b522d7d4 | 3084 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
f55ca84d | 3085 | cmnd->result = ScsiResult(DID_IMM_RETRY, 0); |
b522d7d4 JS |
3086 | goto out_fail_command; |
3087 | } | |
7dc517df | 3088 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
3496343d | 3089 | goto out_tgt_busy; |
a93ce024 | 3090 | |
19ca7609 | 3091 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
dea3101e | 3092 | if (lpfc_cmd == NULL) { |
eaf15d5b | 3093 | lpfc_rampdown_queue_depth(phba); |
92d7f7b0 | 3094 | |
e8b62011 JS |
3095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
3096 | "0707 driver's buffer pool is empty, " | |
3097 | "IO busied\n"); | |
dea3101e | 3098 | goto out_host_busy; |
3099 | } | |
3100 | ||
3101 | /* | |
3102 | * Store the midlayer's command structure for the completion phase | |
3103 | * and complete the command initialization. | |
3104 | */ | |
3105 | lpfc_cmd->pCmd = cmnd; | |
3106 | lpfc_cmd->rdata = rdata; | |
3107 | lpfc_cmd->timeout = 0; | |
977b5a0a | 3108 | lpfc_cmd->start_time = jiffies; |
dea3101e | 3109 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
3110 | cmnd->scsi_done = done; | |
3111 | ||
e2a0a9d6 | 3112 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
6a9c52cf JS |
3113 | if (vport->phba->cfg_enable_bg) { |
3114 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
e2a0a9d6 JS |
3115 | "9033 BLKGRD: rcvd protected cmd:%02x op:%02x " |
3116 | "str=%s\n", | |
3117 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), | |
3118 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
6a9c52cf | 3119 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
e2a0a9d6 | 3120 | "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x " |
e4e74273 | 3121 | "%02x %02x %02x %02x %02x\n", |
e2a0a9d6 JS |
3122 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], |
3123 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], | |
3124 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], | |
3125 | cmnd->cmnd[9]); | |
6a9c52cf JS |
3126 | if (cmnd->cmnd[0] == READ_10) |
3127 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
e2a0a9d6 | 3128 | "9035 BLKGRD: READ @ sector %llu, " |
83096ebf TH |
3129 | "count %u\n", |
3130 | (unsigned long long)scsi_get_lba(cmnd), | |
3131 | blk_rq_sectors(cmnd->request)); | |
6a9c52cf JS |
3132 | else if (cmnd->cmnd[0] == WRITE_10) |
3133 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
e2a0a9d6 | 3134 | "9036 BLKGRD: WRITE @ sector %llu, " |
83096ebf | 3135 | "count %u cmd=%p\n", |
87b5c328 | 3136 | (unsigned long long)scsi_get_lba(cmnd), |
83096ebf | 3137 | blk_rq_sectors(cmnd->request), |
e2a0a9d6 | 3138 | cmnd); |
6a9c52cf | 3139 | } |
e2a0a9d6 JS |
3140 | |
3141 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); | |
3142 | } else { | |
6a9c52cf | 3143 | if (vport->phba->cfg_enable_bg) { |
e2a0a9d6 | 3144 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, |
6a9c52cf JS |
3145 | "9038 BLKGRD: rcvd unprotected cmd:" |
3146 | "%02x op:%02x str=%s\n", | |
3147 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), | |
3148 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
3149 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
3150 | "9039 BLKGRD: CDB: %02x %02x %02x " | |
3151 | "%02x %02x %02x %02x %02x %02x %02x\n", | |
3152 | cmnd->cmnd[0], cmnd->cmnd[1], | |
3153 | cmnd->cmnd[2], cmnd->cmnd[3], | |
3154 | cmnd->cmnd[4], cmnd->cmnd[5], | |
3155 | cmnd->cmnd[6], cmnd->cmnd[7], | |
3156 | cmnd->cmnd[8], cmnd->cmnd[9]); | |
3157 | if (cmnd->cmnd[0] == READ_10) | |
3158 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
3159 | "9040 dbg: READ @ sector %llu, " | |
3160 | "count %u\n", | |
3161 | (unsigned long long)scsi_get_lba(cmnd), | |
83096ebf | 3162 | blk_rq_sectors(cmnd->request)); |
6a9c52cf JS |
3163 | else if (cmnd->cmnd[0] == WRITE_10) |
3164 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
e2a0a9d6 | 3165 | "9041 dbg: WRITE @ sector %llu, " |
83096ebf | 3166 | "count %u cmd=%p\n", |
87b5c328 | 3167 | (unsigned long long)scsi_get_lba(cmnd), |
83096ebf | 3168 | blk_rq_sectors(cmnd->request), cmnd); |
6a9c52cf JS |
3169 | else |
3170 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
e2a0a9d6 | 3171 | "9042 dbg: parser not implemented\n"); |
6a9c52cf | 3172 | } |
e2a0a9d6 JS |
3173 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
3174 | } | |
3175 | ||
dea3101e | 3176 | if (err) |
3177 | goto out_host_busy_free_buf; | |
3178 | ||
2e0fef85 | 3179 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
dea3101e | 3180 | |
977b5a0a | 3181 | atomic_inc(&ndlp->cmd_pending); |
3772a991 | 3182 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
92d7f7b0 | 3183 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
eaf15d5b JS |
3184 | if (err) { |
3185 | atomic_dec(&ndlp->cmd_pending); | |
dea3101e | 3186 | goto out_host_busy_free_buf; |
eaf15d5b | 3187 | } |
875fbdfe | 3188 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
45ed1190 JS |
3189 | spin_unlock(shost->host_lock); |
3190 | lpfc_sli_handle_fast_ring_event(phba, | |
3191 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
3192 | ||
3193 | spin_lock(shost->host_lock); | |
875fbdfe JSEC |
3194 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
3195 | lpfc_poll_rearm_timer(phba); | |
3196 | } | |
3197 | ||
dea3101e | 3198 | return 0; |
3199 | ||
3200 | out_host_busy_free_buf: | |
bcf4dbfa | 3201 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
0bd4ca25 | 3202 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
dea3101e | 3203 | out_host_busy: |
3204 | return SCSI_MLQUEUE_HOST_BUSY; | |
3205 | ||
3496343d MC |
3206 | out_tgt_busy: |
3207 | return SCSI_MLQUEUE_TARGET_BUSY; | |
3208 | ||
dea3101e | 3209 | out_fail_command: |
3210 | done(cmnd); | |
3211 | return 0; | |
3212 | } | |
3213 | ||
f281233d JG |
3214 | static DEF_SCSI_QCMD(lpfc_queuecommand) |
3215 | ||
9bad7671 | 3216 | /** |
3621a710 | 3217 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
9bad7671 JS |
3218 | * @cmnd: Pointer to scsi_cmnd data structure. |
3219 | * | |
3220 | * This routine aborts @cmnd pending in base driver. | |
3221 | * | |
3222 | * Return code : | |
3223 | * 0x2003 - Error | |
3224 | * 0x2002 - Success | |
3225 | **/ | |
dea3101e | 3226 | static int |
63c59c3b | 3227 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
dea3101e | 3228 | { |
2e0fef85 JS |
3229 | struct Scsi_Host *shost = cmnd->device->host; |
3230 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3231 | struct lpfc_hba *phba = vport->phba; | |
0bd4ca25 JSEC |
3232 | struct lpfc_iocbq *iocb; |
3233 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 3234 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 3235 | IOCB_t *cmd, *icmd; |
0bd4ca25 | 3236 | int ret = SUCCESS; |
fa61a54e | 3237 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
dea3101e | 3238 | |
589a52d6 JS |
3239 | ret = fc_block_scsi_eh(cmnd); |
3240 | if (ret) | |
3241 | return ret; | |
0bd4ca25 | 3242 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
eee8877e JS |
3243 | if (!lpfc_cmd) { |
3244 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, | |
3245 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " | |
5cd049a5 CH |
3246 | "x%x ID %d LUN %d\n", |
3247 | ret, cmnd->device->id, cmnd->device->lun); | |
eee8877e JS |
3248 | return SUCCESS; |
3249 | } | |
dea3101e | 3250 | |
0bd4ca25 JSEC |
3251 | /* |
3252 | * If pCmd field of the corresponding lpfc_scsi_buf structure | |
3253 | * points to a different SCSI command, then the driver has | |
3254 | * already completed this command, but the midlayer did not | |
3255 | * see the completion before the eh fired. Just return | |
3256 | * SUCCESS. | |
3257 | */ | |
3258 | iocb = &lpfc_cmd->cur_iocbq; | |
3259 | if (lpfc_cmd->pCmd != cmnd) | |
3260 | goto out; | |
dea3101e | 3261 | |
0bd4ca25 | 3262 | BUG_ON(iocb->context1 != lpfc_cmd); |
dea3101e | 3263 | |
0bd4ca25 JSEC |
3264 | abtsiocb = lpfc_sli_get_iocbq(phba); |
3265 | if (abtsiocb == NULL) { | |
3266 | ret = FAILED; | |
dea3101e | 3267 | goto out; |
3268 | } | |
3269 | ||
dea3101e | 3270 | /* |
0bd4ca25 JSEC |
3271 | * The scsi command can not be in txq and it is in flight because the |
3272 | * pCmd is still pointig at the SCSI command we have to abort. There | |
3273 | * is no need to search the txcmplq. Just send an abort to the FW. | |
dea3101e | 3274 | */ |
dea3101e | 3275 | |
0bd4ca25 JSEC |
3276 | cmd = &iocb->iocb; |
3277 | icmd = &abtsiocb->iocb; | |
3278 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; | |
3279 | icmd->un.acxri.abortContextTag = cmd->ulpContext; | |
3772a991 JS |
3280 | if (phba->sli_rev == LPFC_SLI_REV4) |
3281 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; | |
3282 | else | |
3283 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 3284 | |
0bd4ca25 JSEC |
3285 | icmd->ulpLe = 1; |
3286 | icmd->ulpClass = cmd->ulpClass; | |
5ffc266e JS |
3287 | |
3288 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
3289 | abtsiocb->fcp_wqidx = iocb->fcp_wqidx; | |
341af102 | 3290 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
5ffc266e | 3291 | |
2e0fef85 | 3292 | if (lpfc_is_link_up(phba)) |
0bd4ca25 JSEC |
3293 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
3294 | else | |
3295 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 3296 | |
0bd4ca25 | 3297 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
2e0fef85 | 3298 | abtsiocb->vport = vport; |
3772a991 JS |
3299 | if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == |
3300 | IOCB_ERROR) { | |
0bd4ca25 JSEC |
3301 | lpfc_sli_release_iocbq(phba, abtsiocb); |
3302 | ret = FAILED; | |
3303 | goto out; | |
3304 | } | |
dea3101e | 3305 | |
875fbdfe | 3306 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
45ed1190 JS |
3307 | lpfc_sli_handle_fast_ring_event(phba, |
3308 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
875fbdfe | 3309 | |
fa61a54e | 3310 | lpfc_cmd->waitq = &waitq; |
0bd4ca25 | 3311 | /* Wait for abort to complete */ |
fa61a54e JS |
3312 | wait_event_timeout(waitq, |
3313 | (lpfc_cmd->pCmd != cmnd), | |
3314 | (2*vport->cfg_devloss_tmo*HZ)); | |
875fbdfe | 3315 | |
fa61a54e JS |
3316 | spin_lock_irq(shost->host_lock); |
3317 | lpfc_cmd->waitq = NULL; | |
3318 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 3319 | |
0bd4ca25 JSEC |
3320 | if (lpfc_cmd->pCmd == cmnd) { |
3321 | ret = FAILED; | |
e8b62011 JS |
3322 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3323 | "0748 abort handler timed out waiting " | |
3324 | "for abort to complete: ret %#x, ID %d, " | |
5cd049a5 CH |
3325 | "LUN %d\n", |
3326 | ret, cmnd->device->id, cmnd->device->lun); | |
dea3101e | 3327 | } |
3328 | ||
3329 | out: | |
e8b62011 JS |
3330 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
3331 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " | |
5cd049a5 CH |
3332 | "LUN %d\n", ret, cmnd->device->id, |
3333 | cmnd->device->lun); | |
63c59c3b | 3334 | return ret; |
8fa728a2 JG |
3335 | } |
3336 | ||
bbb9d180 JS |
3337 | static char * |
3338 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) | |
3339 | { | |
3340 | switch (task_mgmt_cmd) { | |
3341 | case FCP_ABORT_TASK_SET: | |
3342 | return "ABORT_TASK_SET"; | |
3343 | case FCP_CLEAR_TASK_SET: | |
3344 | return "FCP_CLEAR_TASK_SET"; | |
3345 | case FCP_BUS_RESET: | |
3346 | return "FCP_BUS_RESET"; | |
3347 | case FCP_LUN_RESET: | |
3348 | return "FCP_LUN_RESET"; | |
3349 | case FCP_TARGET_RESET: | |
3350 | return "FCP_TARGET_RESET"; | |
3351 | case FCP_CLEAR_ACA: | |
3352 | return "FCP_CLEAR_ACA"; | |
3353 | case FCP_TERMINATE_TASK: | |
3354 | return "FCP_TERMINATE_TASK"; | |
3355 | default: | |
3356 | return "unknown"; | |
3357 | } | |
3358 | } | |
3359 | ||
9bad7671 | 3360 | /** |
bbb9d180 JS |
3361 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
3362 | * @vport: The virtual port for which this call is being executed. | |
3363 | * @rdata: Pointer to remote port local data | |
3364 | * @tgt_id: Target ID of remote device. | |
3365 | * @lun_id: Lun number for the TMF | |
3366 | * @task_mgmt_cmd: type of TMF to send | |
9bad7671 | 3367 | * |
bbb9d180 JS |
3368 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
3369 | * a remote port. | |
9bad7671 | 3370 | * |
bbb9d180 JS |
3371 | * Return Code: |
3372 | * 0x2003 - Error | |
3373 | * 0x2002 - Success. | |
9bad7671 | 3374 | **/ |
dea3101e | 3375 | static int |
bbb9d180 JS |
3376 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata, |
3377 | unsigned tgt_id, unsigned int lun_id, | |
3378 | uint8_t task_mgmt_cmd) | |
dea3101e | 3379 | { |
2e0fef85 | 3380 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 | 3381 | struct lpfc_scsi_buf *lpfc_cmd; |
bbb9d180 JS |
3382 | struct lpfc_iocbq *iocbq; |
3383 | struct lpfc_iocbq *iocbqrsp; | |
5989b8d4 | 3384 | struct lpfc_nodelist *pnode = rdata->pnode; |
bbb9d180 | 3385 | int ret; |
915caaaf | 3386 | int status; |
dea3101e | 3387 | |
5989b8d4 | 3388 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
915caaaf | 3389 | return FAILED; |
bbb9d180 | 3390 | |
19ca7609 | 3391 | lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode); |
dea3101e | 3392 | if (lpfc_cmd == NULL) |
915caaaf | 3393 | return FAILED; |
dea3101e | 3394 | lpfc_cmd->timeout = 60; |
0b18ac42 | 3395 | lpfc_cmd->rdata = rdata; |
dea3101e | 3396 | |
bbb9d180 JS |
3397 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
3398 | task_mgmt_cmd); | |
915caaaf JS |
3399 | if (!status) { |
3400 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3401 | return FAILED; | |
3402 | } | |
dea3101e | 3403 | |
bbb9d180 | 3404 | iocbq = &lpfc_cmd->cur_iocbq; |
0bd4ca25 | 3405 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
915caaaf JS |
3406 | if (iocbqrsp == NULL) { |
3407 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3408 | return FAILED; | |
3409 | } | |
bbb9d180 | 3410 | |
e8b62011 | 3411 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
bbb9d180 | 3412 | "0702 Issue %s to TGT %d LUN %d " |
6d368e53 | 3413 | "rpi x%x nlp_flag x%x Data: x%x x%x\n", |
bbb9d180 | 3414 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
6d368e53 JS |
3415 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
3416 | iocbq->iocb_flag); | |
bbb9d180 | 3417 | |
3772a991 | 3418 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
915caaaf | 3419 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
bbb9d180 JS |
3420 | if (status != IOCB_SUCCESS) { |
3421 | if (status == IOCB_TIMEDOUT) { | |
3422 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; | |
3423 | ret = TIMEOUT_ERROR; | |
3424 | } else | |
915caaaf | 3425 | ret = FAILED; |
bbb9d180 JS |
3426 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
3427 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
6d368e53 JS |
3428 | "0727 TMF %s to TGT %d LUN %d failed (%d, %d) " |
3429 | "iocb_flag x%x\n", | |
bbb9d180 JS |
3430 | lpfc_taskmgmt_name(task_mgmt_cmd), |
3431 | tgt_id, lun_id, iocbqrsp->iocb.ulpStatus, | |
6d368e53 JS |
3432 | iocbqrsp->iocb.un.ulpWord[4], |
3433 | iocbq->iocb_flag); | |
2a9bf3d0 JS |
3434 | } else if (status == IOCB_BUSY) |
3435 | ret = FAILED; | |
3436 | else | |
bbb9d180 JS |
3437 | ret = SUCCESS; |
3438 | ||
6175c02a | 3439 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
bbb9d180 JS |
3440 | |
3441 | if (ret != TIMEOUT_ERROR) | |
3442 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3443 | ||
3444 | return ret; | |
3445 | } | |
3446 | ||
3447 | /** | |
3448 | * lpfc_chk_tgt_mapped - | |
3449 | * @vport: The virtual port to check on | |
3450 | * @cmnd: Pointer to scsi_cmnd data structure. | |
3451 | * | |
3452 | * This routine delays until the scsi target (aka rport) for the | |
3453 | * command exists (is present and logged in) or we declare it non-existent. | |
3454 | * | |
3455 | * Return code : | |
3456 | * 0x2003 - Error | |
3457 | * 0x2002 - Success | |
3458 | **/ | |
3459 | static int | |
3460 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) | |
3461 | { | |
3462 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | |
1c6f4ef5 | 3463 | struct lpfc_nodelist *pnode; |
bbb9d180 JS |
3464 | unsigned long later; |
3465 | ||
1c6f4ef5 JS |
3466 | if (!rdata) { |
3467 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, | |
3468 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); | |
3469 | return FAILED; | |
3470 | } | |
3471 | pnode = rdata->pnode; | |
bbb9d180 JS |
3472 | /* |
3473 | * If target is not in a MAPPED state, delay until | |
3474 | * target is rediscovered or devloss timeout expires. | |
3475 | */ | |
3476 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; | |
3477 | while (time_after(later, jiffies)) { | |
3478 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) | |
3479 | return FAILED; | |
3480 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) | |
3481 | return SUCCESS; | |
3482 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); | |
3483 | rdata = cmnd->device->hostdata; | |
3484 | if (!rdata) | |
3485 | return FAILED; | |
3486 | pnode = rdata->pnode; | |
3487 | } | |
3488 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || | |
3489 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) | |
3490 | return FAILED; | |
3491 | return SUCCESS; | |
3492 | } | |
3493 | ||
3494 | /** | |
3495 | * lpfc_reset_flush_io_context - | |
3496 | * @vport: The virtual port (scsi_host) for the flush context | |
3497 | * @tgt_id: If aborting by Target contect - specifies the target id | |
3498 | * @lun_id: If aborting by Lun context - specifies the lun id | |
3499 | * @context: specifies the context level to flush at. | |
3500 | * | |
3501 | * After a reset condition via TMF, we need to flush orphaned i/o | |
3502 | * contexts from the adapter. This routine aborts any contexts | |
3503 | * outstanding, then waits for their completions. The wait is | |
3504 | * bounded by devloss_tmo though. | |
3505 | * | |
3506 | * Return code : | |
3507 | * 0x2003 - Error | |
3508 | * 0x2002 - Success | |
3509 | **/ | |
3510 | static int | |
3511 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, | |
3512 | uint64_t lun_id, lpfc_ctx_cmd context) | |
3513 | { | |
3514 | struct lpfc_hba *phba = vport->phba; | |
3515 | unsigned long later; | |
3516 | int cnt; | |
3517 | ||
3518 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); | |
6175c02a | 3519 | if (cnt) |
51ef4c26 | 3520 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
bbb9d180 | 3521 | tgt_id, lun_id, context); |
915caaaf JS |
3522 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
3523 | while (time_after(later, jiffies) && cnt) { | |
3524 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); | |
bbb9d180 | 3525 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
dea3101e | 3526 | } |
dea3101e | 3527 | if (cnt) { |
e8b62011 | 3528 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
bbb9d180 JS |
3529 | "0724 I/O flush failure for context %s : cnt x%x\n", |
3530 | ((context == LPFC_CTX_LUN) ? "LUN" : | |
3531 | ((context == LPFC_CTX_TGT) ? "TGT" : | |
3532 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), | |
3533 | cnt); | |
3534 | return FAILED; | |
dea3101e | 3535 | } |
bbb9d180 JS |
3536 | return SUCCESS; |
3537 | } | |
3538 | ||
3539 | /** | |
3540 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point | |
3541 | * @cmnd: Pointer to scsi_cmnd data structure. | |
3542 | * | |
3543 | * This routine does a device reset by sending a LUN_RESET task management | |
3544 | * command. | |
3545 | * | |
3546 | * Return code : | |
3547 | * 0x2003 - Error | |
3548 | * 0x2002 - Success | |
3549 | **/ | |
3550 | static int | |
3551 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) | |
3552 | { | |
3553 | struct Scsi_Host *shost = cmnd->device->host; | |
3554 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3555 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | |
1c6f4ef5 | 3556 | struct lpfc_nodelist *pnode; |
bbb9d180 JS |
3557 | unsigned tgt_id = cmnd->device->id; |
3558 | unsigned int lun_id = cmnd->device->lun; | |
3559 | struct lpfc_scsi_event_header scsi_event; | |
3560 | int status; | |
3561 | ||
1c6f4ef5 JS |
3562 | if (!rdata) { |
3563 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3564 | "0798 Device Reset rport failure: rdata x%p\n", rdata); | |
3565 | return FAILED; | |
3566 | } | |
3567 | pnode = rdata->pnode; | |
589a52d6 JS |
3568 | status = fc_block_scsi_eh(cmnd); |
3569 | if (status) | |
3570 | return status; | |
bbb9d180 JS |
3571 | |
3572 | status = lpfc_chk_tgt_mapped(vport, cmnd); | |
3573 | if (status == FAILED) { | |
3574 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3575 | "0721 Device Reset rport failure: rdata x%p\n", rdata); | |
3576 | return FAILED; | |
3577 | } | |
3578 | ||
3579 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
3580 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; | |
3581 | scsi_event.lun = lun_id; | |
3582 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
3583 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
3584 | ||
3585 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
3586 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); | |
3587 | ||
3588 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, | |
3589 | FCP_LUN_RESET); | |
3590 | ||
3591 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3592 | "0713 SCSI layer issued Device Reset (%d, %d) " | |
3593 | "return x%x\n", tgt_id, lun_id, status); | |
3594 | ||
3595 | /* | |
3596 | * We have to clean up i/o as : they may be orphaned by the TMF; | |
3597 | * or if the TMF failed, they may be in an indeterminate state. | |
3598 | * So, continue on. | |
3599 | * We will report success if all the i/o aborts successfully. | |
3600 | */ | |
3601 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, | |
3602 | LPFC_CTX_LUN); | |
3603 | return status; | |
3604 | } | |
3605 | ||
3606 | /** | |
3607 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point | |
3608 | * @cmnd: Pointer to scsi_cmnd data structure. | |
3609 | * | |
3610 | * This routine does a target reset by sending a TARGET_RESET task management | |
3611 | * command. | |
3612 | * | |
3613 | * Return code : | |
3614 | * 0x2003 - Error | |
3615 | * 0x2002 - Success | |
3616 | **/ | |
3617 | static int | |
3618 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) | |
3619 | { | |
3620 | struct Scsi_Host *shost = cmnd->device->host; | |
3621 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3622 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | |
1c6f4ef5 | 3623 | struct lpfc_nodelist *pnode; |
bbb9d180 JS |
3624 | unsigned tgt_id = cmnd->device->id; |
3625 | unsigned int lun_id = cmnd->device->lun; | |
3626 | struct lpfc_scsi_event_header scsi_event; | |
3627 | int status; | |
3628 | ||
1c6f4ef5 JS |
3629 | if (!rdata) { |
3630 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3631 | "0799 Target Reset rport failure: rdata x%p\n", rdata); | |
3632 | return FAILED; | |
3633 | } | |
3634 | pnode = rdata->pnode; | |
589a52d6 JS |
3635 | status = fc_block_scsi_eh(cmnd); |
3636 | if (status) | |
3637 | return status; | |
bbb9d180 JS |
3638 | |
3639 | status = lpfc_chk_tgt_mapped(vport, cmnd); | |
3640 | if (status == FAILED) { | |
3641 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3642 | "0722 Target Reset rport failure: rdata x%p\n", rdata); | |
3643 | return FAILED; | |
3644 | } | |
3645 | ||
3646 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
3647 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; | |
3648 | scsi_event.lun = 0; | |
3649 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
3650 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
3651 | ||
3652 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
3653 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); | |
3654 | ||
3655 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, | |
3656 | FCP_TARGET_RESET); | |
3657 | ||
3658 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3659 | "0723 SCSI layer issued Target Reset (%d, %d) " | |
3660 | "return x%x\n", tgt_id, lun_id, status); | |
3661 | ||
3662 | /* | |
3663 | * We have to clean up i/o as : they may be orphaned by the TMF; | |
3664 | * or if the TMF failed, they may be in an indeterminate state. | |
3665 | * So, continue on. | |
3666 | * We will report success if all the i/o aborts successfully. | |
3667 | */ | |
3668 | status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, | |
3669 | LPFC_CTX_TGT); | |
3670 | return status; | |
dea3101e | 3671 | } |
3672 | ||
9bad7671 | 3673 | /** |
3621a710 | 3674 | * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point |
9bad7671 JS |
3675 | * @cmnd: Pointer to scsi_cmnd data structure. |
3676 | * | |
bbb9d180 JS |
3677 | * This routine does target reset to all targets on @cmnd->device->host. |
3678 | * This emulates Parallel SCSI Bus Reset Semantics. | |
9bad7671 | 3679 | * |
bbb9d180 JS |
3680 | * Return code : |
3681 | * 0x2003 - Error | |
3682 | * 0x2002 - Success | |
9bad7671 | 3683 | **/ |
94d0e7b8 | 3684 | static int |
7054a606 | 3685 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
dea3101e | 3686 | { |
2e0fef85 JS |
3687 | struct Scsi_Host *shost = cmnd->device->host; |
3688 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
dea3101e | 3689 | struct lpfc_nodelist *ndlp = NULL; |
ea2151b4 | 3690 | struct lpfc_scsi_event_header scsi_event; |
bbb9d180 JS |
3691 | int match; |
3692 | int ret = SUCCESS, status, i; | |
ea2151b4 JS |
3693 | |
3694 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
3695 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; | |
3696 | scsi_event.lun = 0; | |
3697 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); | |
3698 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
3699 | ||
bbb9d180 JS |
3700 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
3701 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); | |
dea3101e | 3702 | |
bf08611b JS |
3703 | status = fc_block_scsi_eh(cmnd); |
3704 | if (status) | |
3705 | return status; | |
bbb9d180 | 3706 | |
dea3101e | 3707 | /* |
3708 | * Since the driver manages a single bus device, reset all | |
3709 | * targets known to the driver. Should any target reset | |
3710 | * fail, this routine returns failure to the midlayer. | |
3711 | */ | |
e17da18e | 3712 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
685f0bf7 | 3713 | /* Search for mapped node by target ID */ |
dea3101e | 3714 | match = 0; |
2e0fef85 JS |
3715 | spin_lock_irq(shost->host_lock); |
3716 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
3717 | if (!NLP_CHK_NODE_ACT(ndlp)) |
3718 | continue; | |
685f0bf7 | 3719 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
915caaaf | 3720 | ndlp->nlp_sid == i && |
685f0bf7 | 3721 | ndlp->rport) { |
dea3101e | 3722 | match = 1; |
3723 | break; | |
3724 | } | |
3725 | } | |
2e0fef85 | 3726 | spin_unlock_irq(shost->host_lock); |
dea3101e | 3727 | if (!match) |
3728 | continue; | |
bbb9d180 JS |
3729 | |
3730 | status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data, | |
3731 | i, 0, FCP_TARGET_RESET); | |
3732 | ||
3733 | if (status != SUCCESS) { | |
e8b62011 JS |
3734 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3735 | "0700 Bus Reset on target %d failed\n", | |
3736 | i); | |
915caaaf | 3737 | ret = FAILED; |
dea3101e | 3738 | } |
3739 | } | |
6175c02a | 3740 | /* |
bbb9d180 JS |
3741 | * We have to clean up i/o as : they may be orphaned by the TMFs |
3742 | * above; or if any of the TMFs failed, they may be in an | |
3743 | * indeterminate state. | |
3744 | * We will report success if all the i/o aborts successfully. | |
6175c02a | 3745 | */ |
bbb9d180 JS |
3746 | |
3747 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); | |
3748 | if (status != SUCCESS) | |
0bd4ca25 | 3749 | ret = FAILED; |
bbb9d180 | 3750 | |
e8b62011 JS |
3751 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3752 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); | |
dea3101e | 3753 | return ret; |
3754 | } | |
3755 | ||
9bad7671 | 3756 | /** |
3621a710 | 3757 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
9bad7671 JS |
3758 | * @sdev: Pointer to scsi_device. |
3759 | * | |
3760 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's | |
3761 | * globally available list of scsi buffers. This routine also makes sure scsi | |
3762 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list | |
3763 | * of scsi buffer exists for the lifetime of the driver. | |
3764 | * | |
3765 | * Return codes: | |
3766 | * non-0 - Error | |
3767 | * 0 - Success | |
3768 | **/ | |
dea3101e | 3769 | static int |
3770 | lpfc_slave_alloc(struct scsi_device *sdev) | |
3771 | { | |
2e0fef85 JS |
3772 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
3773 | struct lpfc_hba *phba = vport->phba; | |
19a7b4ae | 3774 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
3772a991 | 3775 | uint32_t total = 0; |
dea3101e | 3776 | uint32_t num_to_alloc = 0; |
3772a991 | 3777 | int num_allocated = 0; |
d7c47992 | 3778 | uint32_t sdev_cnt; |
dea3101e | 3779 | |
19a7b4ae | 3780 | if (!rport || fc_remote_port_chkready(rport)) |
dea3101e | 3781 | return -ENXIO; |
3782 | ||
19a7b4ae | 3783 | sdev->hostdata = rport->dd_data; |
d7c47992 | 3784 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
dea3101e | 3785 | |
3786 | /* | |
3787 | * Populate the cmds_per_lun count scsi_bufs into this host's globally | |
3788 | * available list of scsi buffers. Don't allocate more than the | |
a784efbf JSEC |
3789 | * HBA limit conveyed to the midlayer via the host structure. The |
3790 | * formula accounts for the lun_queue_depth + error handlers + 1 | |
3791 | * extra. This list of scsi bufs exists for the lifetime of the driver. | |
dea3101e | 3792 | */ |
3793 | total = phba->total_scsi_bufs; | |
3de2a653 | 3794 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
92d7f7b0 | 3795 | |
d7c47992 JS |
3796 | /* If allocated buffers are enough do nothing */ |
3797 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) | |
3798 | return 0; | |
3799 | ||
92d7f7b0 JS |
3800 | /* Allow some exchanges to be available always to complete discovery */ |
3801 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { | |
e8b62011 JS |
3802 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
3803 | "0704 At limitation of %d preallocated " | |
3804 | "command buffers\n", total); | |
dea3101e | 3805 | return 0; |
92d7f7b0 JS |
3806 | /* Allow some exchanges to be available always to complete discovery */ |
3807 | } else if (total + num_to_alloc > | |
3808 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { | |
e8b62011 JS |
3809 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
3810 | "0705 Allocation request of %d " | |
3811 | "command buffers will exceed max of %d. " | |
3812 | "Reducing allocation request to %d.\n", | |
3813 | num_to_alloc, phba->cfg_hba_queue_depth, | |
3814 | (phba->cfg_hba_queue_depth - total)); | |
dea3101e | 3815 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
3816 | } | |
3772a991 JS |
3817 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
3818 | if (num_to_alloc != num_allocated) { | |
3819 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, | |
3820 | "0708 Allocation request of %d " | |
3821 | "command buffers did not succeed. " | |
3822 | "Allocated %d buffers.\n", | |
3823 | num_to_alloc, num_allocated); | |
dea3101e | 3824 | } |
1c6f4ef5 JS |
3825 | if (num_allocated > 0) |
3826 | phba->total_scsi_bufs += num_allocated; | |
dea3101e | 3827 | return 0; |
3828 | } | |
3829 | ||
9bad7671 | 3830 | /** |
3621a710 | 3831 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
9bad7671 JS |
3832 | * @sdev: Pointer to scsi_device. |
3833 | * | |
3834 | * This routine configures following items | |
3835 | * - Tag command queuing support for @sdev if supported. | |
9bad7671 JS |
3836 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
3837 | * | |
3838 | * Return codes: | |
3839 | * 0 - Success | |
3840 | **/ | |
dea3101e | 3841 | static int |
3842 | lpfc_slave_configure(struct scsi_device *sdev) | |
3843 | { | |
2e0fef85 JS |
3844 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
3845 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3846 | |
3847 | if (sdev->tagged_supported) | |
3de2a653 | 3848 | scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth); |
dea3101e | 3849 | else |
3de2a653 | 3850 | scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth); |
dea3101e | 3851 | |
875fbdfe | 3852 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
45ed1190 JS |
3853 | lpfc_sli_handle_fast_ring_event(phba, |
3854 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
875fbdfe JSEC |
3855 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
3856 | lpfc_poll_rearm_timer(phba); | |
3857 | } | |
3858 | ||
dea3101e | 3859 | return 0; |
3860 | } | |
3861 | ||
9bad7671 | 3862 | /** |
3621a710 | 3863 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
9bad7671 JS |
3864 | * @sdev: Pointer to scsi_device. |
3865 | * | |
3866 | * This routine sets @sdev hostatdata filed to null. | |
3867 | **/ | |
dea3101e | 3868 | static void |
3869 | lpfc_slave_destroy(struct scsi_device *sdev) | |
3870 | { | |
d7c47992 JS |
3871 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
3872 | struct lpfc_hba *phba = vport->phba; | |
3873 | atomic_dec(&phba->sdev_cnt); | |
dea3101e | 3874 | sdev->hostdata = NULL; |
3875 | return; | |
3876 | } | |
3877 | ||
92d7f7b0 | 3878 | |
dea3101e | 3879 | struct scsi_host_template lpfc_template = { |
3880 | .module = THIS_MODULE, | |
3881 | .name = LPFC_DRIVER_NAME, | |
3882 | .info = lpfc_info, | |
3883 | .queuecommand = lpfc_queuecommand, | |
3884 | .eh_abort_handler = lpfc_abort_handler, | |
bbb9d180 JS |
3885 | .eh_device_reset_handler = lpfc_device_reset_handler, |
3886 | .eh_target_reset_handler = lpfc_target_reset_handler, | |
7054a606 | 3887 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
dea3101e | 3888 | .slave_alloc = lpfc_slave_alloc, |
3889 | .slave_configure = lpfc_slave_configure, | |
3890 | .slave_destroy = lpfc_slave_destroy, | |
47a8617c | 3891 | .scan_finished = lpfc_scan_finished, |
dea3101e | 3892 | .this_id = -1, |
83108bd3 | 3893 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
dea3101e | 3894 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
3895 | .use_clustering = ENABLE_CLUSTERING, | |
2e0fef85 | 3896 | .shost_attrs = lpfc_hba_attrs, |
564b2960 | 3897 | .max_sectors = 0xFFFF, |
f1c3b0fc | 3898 | .vendor_id = LPFC_NL_VENDOR_ID, |
5ffc266e | 3899 | .change_queue_depth = lpfc_change_queue_depth, |
dea3101e | 3900 | }; |
3de2a653 JS |
3901 | |
3902 | struct scsi_host_template lpfc_vport_template = { | |
3903 | .module = THIS_MODULE, | |
3904 | .name = LPFC_DRIVER_NAME, | |
3905 | .info = lpfc_info, | |
3906 | .queuecommand = lpfc_queuecommand, | |
3907 | .eh_abort_handler = lpfc_abort_handler, | |
bbb9d180 JS |
3908 | .eh_device_reset_handler = lpfc_device_reset_handler, |
3909 | .eh_target_reset_handler = lpfc_target_reset_handler, | |
3de2a653 JS |
3910 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
3911 | .slave_alloc = lpfc_slave_alloc, | |
3912 | .slave_configure = lpfc_slave_configure, | |
3913 | .slave_destroy = lpfc_slave_destroy, | |
3914 | .scan_finished = lpfc_scan_finished, | |
3915 | .this_id = -1, | |
83108bd3 | 3916 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
3de2a653 JS |
3917 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
3918 | .use_clustering = ENABLE_CLUSTERING, | |
3919 | .shost_attrs = lpfc_vport_attrs, | |
3920 | .max_sectors = 0xFFFF, | |
5ffc266e | 3921 | .change_queue_depth = lpfc_change_queue_depth, |
3de2a653 | 3922 | }; |