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