Commit | Line | Data |
---|---|---|
d85296cf | 1 | /******************************************************************* |
dea3101e | 2 | * This file is part of the Emulex Linux Device Driver for * |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
92c13f29 | 4 | * Copyright (C) 2004-2013 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> |
09703660 | 24 | #include <linux/export.h> |
a90f5684 | 25 | #include <linux/delay.h> |
e2a0a9d6 | 26 | #include <asm/unaligned.h> |
737d4248 JS |
27 | #include <linux/crc-t10dif.h> |
28 | #include <net/checksum.h> | |
dea3101e | 29 | |
30 | #include <scsi/scsi.h> | |
31 | #include <scsi/scsi_device.h> | |
e2a0a9d6 | 32 | #include <scsi/scsi_eh.h> |
dea3101e | 33 | #include <scsi/scsi_host.h> |
34 | #include <scsi/scsi_tcq.h> | |
35 | #include <scsi/scsi_transport_fc.h> | |
36 | ||
37 | #include "lpfc_version.h" | |
da0436e9 | 38 | #include "lpfc_hw4.h" |
dea3101e | 39 | #include "lpfc_hw.h" |
40 | #include "lpfc_sli.h" | |
da0436e9 | 41 | #include "lpfc_sli4.h" |
ea2151b4 | 42 | #include "lpfc_nl.h" |
dea3101e | 43 | #include "lpfc_disc.h" |
dea3101e | 44 | #include "lpfc.h" |
9a6b09c0 | 45 | #include "lpfc_scsi.h" |
dea3101e | 46 | #include "lpfc_logmsg.h" |
47 | #include "lpfc_crtn.h" | |
92d7f7b0 | 48 | #include "lpfc_vport.h" |
dea3101e | 49 | |
50 | #define LPFC_RESET_WAIT 2 | |
51 | #define LPFC_ABORT_WAIT 2 | |
52 | ||
737d4248 | 53 | int _dump_buf_done = 1; |
e2a0a9d6 JS |
54 | |
55 | static char *dif_op_str[] = { | |
9a6b09c0 JS |
56 | "PROT_NORMAL", |
57 | "PROT_READ_INSERT", | |
58 | "PROT_WRITE_STRIP", | |
59 | "PROT_READ_STRIP", | |
60 | "PROT_WRITE_INSERT", | |
61 | "PROT_READ_PASS", | |
62 | "PROT_WRITE_PASS", | |
63 | }; | |
64 | ||
f9bb2da1 JS |
65 | struct scsi_dif_tuple { |
66 | __be16 guard_tag; /* Checksum */ | |
67 | __be16 app_tag; /* Opaque storage */ | |
68 | __be32 ref_tag; /* Target LBA or indirect LBA */ | |
69 | }; | |
70 | ||
da0436e9 JS |
71 | static void |
72 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); | |
1c6f4ef5 JS |
73 | static void |
74 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); | |
9c6aa9d7 JS |
75 | static int |
76 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc); | |
e2a0a9d6 JS |
77 | |
78 | static void | |
6a9c52cf | 79 | lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
e2a0a9d6 JS |
80 | { |
81 | void *src, *dst; | |
82 | struct scatterlist *sgde = scsi_sglist(cmnd); | |
83 | ||
84 | if (!_dump_buf_data) { | |
6a9c52cf JS |
85 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
86 | "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n", | |
e2a0a9d6 JS |
87 | __func__); |
88 | return; | |
89 | } | |
90 | ||
91 | ||
92 | if (!sgde) { | |
6a9c52cf JS |
93 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
94 | "9051 BLKGRD: ERROR: data scatterlist is null\n"); | |
e2a0a9d6 JS |
95 | return; |
96 | } | |
97 | ||
98 | dst = (void *) _dump_buf_data; | |
99 | while (sgde) { | |
100 | src = sg_virt(sgde); | |
101 | memcpy(dst, src, sgde->length); | |
102 | dst += sgde->length; | |
103 | sgde = sg_next(sgde); | |
104 | } | |
105 | } | |
106 | ||
107 | static void | |
6a9c52cf | 108 | lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd) |
e2a0a9d6 JS |
109 | { |
110 | void *src, *dst; | |
111 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); | |
112 | ||
113 | if (!_dump_buf_dif) { | |
6a9c52cf JS |
114 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
115 | "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n", | |
e2a0a9d6 JS |
116 | __func__); |
117 | return; | |
118 | } | |
119 | ||
120 | if (!sgde) { | |
6a9c52cf JS |
121 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
122 | "9053 BLKGRD: ERROR: prot scatterlist is null\n"); | |
e2a0a9d6 JS |
123 | return; |
124 | } | |
125 | ||
126 | dst = _dump_buf_dif; | |
127 | while (sgde) { | |
128 | src = sg_virt(sgde); | |
129 | memcpy(dst, src, sgde->length); | |
130 | dst += sgde->length; | |
131 | sgde = sg_next(sgde); | |
132 | } | |
133 | } | |
134 | ||
9c6aa9d7 JS |
135 | static inline unsigned |
136 | lpfc_cmd_blksize(struct scsi_cmnd *sc) | |
137 | { | |
138 | return sc->device->sector_size; | |
139 | } | |
140 | ||
141 | #define LPFC_CHECK_PROTECT_GUARD 1 | |
142 | #define LPFC_CHECK_PROTECT_REF 2 | |
143 | static inline unsigned | |
144 | lpfc_cmd_protect(struct scsi_cmnd *sc, int flag) | |
145 | { | |
146 | return 1; | |
147 | } | |
148 | ||
149 | static inline unsigned | |
150 | lpfc_cmd_guard_csum(struct scsi_cmnd *sc) | |
151 | { | |
152 | if (lpfc_prot_group_type(NULL, sc) == LPFC_PG_TYPE_NO_DIF) | |
153 | return 0; | |
154 | if (scsi_host_get_guard(sc->device->host) == SHOST_DIX_GUARD_IP) | |
155 | return 1; | |
156 | return 0; | |
157 | } | |
158 | ||
f1126688 JS |
159 | /** |
160 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. | |
161 | * @phba: Pointer to HBA object. | |
162 | * @lpfc_cmd: lpfc scsi command object pointer. | |
163 | * | |
164 | * This function is called from the lpfc_prep_task_mgmt_cmd function to | |
165 | * set the last bit in the response sge entry. | |
166 | **/ | |
167 | static void | |
168 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, | |
169 | struct lpfc_scsi_buf *lpfc_cmd) | |
170 | { | |
171 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
172 | if (sgl) { | |
173 | sgl += 1; | |
174 | sgl->word2 = le32_to_cpu(sgl->word2); | |
175 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
176 | sgl->word2 = cpu_to_le32(sgl->word2); | |
177 | } | |
178 | } | |
179 | ||
ea2151b4 | 180 | /** |
3621a710 | 181 | * lpfc_update_stats - Update statistical data for the command completion |
ea2151b4 JS |
182 | * @phba: Pointer to HBA object. |
183 | * @lpfc_cmd: lpfc scsi command object pointer. | |
184 | * | |
185 | * This function is called when there is a command completion and this | |
186 | * function updates the statistical data for the command completion. | |
187 | **/ | |
188 | static void | |
189 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
190 | { | |
191 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; | |
192 | struct lpfc_nodelist *pnode = rdata->pnode; | |
193 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
194 | unsigned long flags; | |
195 | struct Scsi_Host *shost = cmd->device->host; | |
196 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
197 | unsigned long latency; | |
198 | int i; | |
199 | ||
200 | if (cmd->result) | |
201 | return; | |
202 | ||
9f1e1b50 JS |
203 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
204 | ||
ea2151b4 JS |
205 | spin_lock_irqsave(shost->host_lock, flags); |
206 | if (!vport->stat_data_enabled || | |
207 | vport->stat_data_blocked || | |
5989b8d4 | 208 | !pnode || |
ea2151b4 JS |
209 | !pnode->lat_data || |
210 | (phba->bucket_type == LPFC_NO_BUCKET)) { | |
211 | spin_unlock_irqrestore(shost->host_lock, flags); | |
212 | return; | |
213 | } | |
ea2151b4 JS |
214 | |
215 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { | |
216 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ | |
217 | phba->bucket_step; | |
9f1e1b50 JS |
218 | /* check array subscript bounds */ |
219 | if (i < 0) | |
220 | i = 0; | |
221 | else if (i >= LPFC_MAX_BUCKET_COUNT) | |
222 | i = LPFC_MAX_BUCKET_COUNT - 1; | |
ea2151b4 JS |
223 | } else { |
224 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) | |
225 | if (latency <= (phba->bucket_base + | |
226 | ((1<<i)*phba->bucket_step))) | |
227 | break; | |
228 | } | |
229 | ||
230 | pnode->lat_data[i].cmd_count++; | |
231 | spin_unlock_irqrestore(shost->host_lock, flags); | |
232 | } | |
233 | ||
ea2151b4 | 234 | /** |
3621a710 | 235 | * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event |
ea2151b4 JS |
236 | * @phba: Pointer to HBA context object. |
237 | * @vport: Pointer to vport object. | |
238 | * @ndlp: Pointer to FC node associated with the target. | |
239 | * @lun: Lun number of the scsi device. | |
240 | * @old_val: Old value of the queue depth. | |
241 | * @new_val: New value of the queue depth. | |
242 | * | |
243 | * This function sends an event to the mgmt application indicating | |
244 | * there is a change in the scsi device queue depth. | |
245 | **/ | |
246 | static void | |
247 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, | |
248 | struct lpfc_vport *vport, | |
249 | struct lpfc_nodelist *ndlp, | |
250 | uint32_t lun, | |
251 | uint32_t old_val, | |
252 | uint32_t new_val) | |
253 | { | |
254 | struct lpfc_fast_path_event *fast_path_evt; | |
255 | unsigned long flags; | |
256 | ||
257 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
258 | if (!fast_path_evt) | |
259 | return; | |
260 | ||
261 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = | |
262 | FC_REG_SCSI_EVENT; | |
263 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = | |
264 | LPFC_EVENT_VARQUEDEPTH; | |
265 | ||
266 | /* Report all luns with change in queue depth */ | |
267 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; | |
268 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | |
269 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, | |
270 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); | |
271 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, | |
272 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | |
273 | } | |
274 | ||
275 | fast_path_evt->un.queue_depth_evt.oldval = old_val; | |
276 | fast_path_evt->un.queue_depth_evt.newval = new_val; | |
277 | fast_path_evt->vport = vport; | |
278 | ||
279 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; | |
280 | spin_lock_irqsave(&phba->hbalock, flags); | |
281 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); | |
282 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
283 | lpfc_worker_wake_up(phba); | |
284 | ||
285 | return; | |
286 | } | |
287 | ||
5ffc266e JS |
288 | /** |
289 | * lpfc_change_queue_depth - Alter scsi device queue depth | |
290 | * @sdev: Pointer the scsi device on which to change the queue depth. | |
291 | * @qdepth: New queue depth to set the sdev to. | |
292 | * @reason: The reason for the queue depth change. | |
293 | * | |
294 | * This function is called by the midlayer and the LLD to alter the queue | |
295 | * depth for a scsi device. This function sets the queue depth to the new | |
296 | * value and sends an event out to log the queue depth change. | |
297 | **/ | |
298 | int | |
299 | lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) | |
300 | { | |
301 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; | |
302 | struct lpfc_hba *phba = vport->phba; | |
303 | struct lpfc_rport_data *rdata; | |
304 | unsigned long new_queue_depth, old_queue_depth; | |
305 | ||
306 | old_queue_depth = sdev->queue_depth; | |
307 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | |
308 | new_queue_depth = sdev->queue_depth; | |
309 | rdata = sdev->hostdata; | |
310 | if (rdata) | |
311 | lpfc_send_sdev_queuedepth_change_event(phba, vport, | |
312 | rdata->pnode, sdev->lun, | |
313 | old_queue_depth, | |
314 | new_queue_depth); | |
315 | return sdev->queue_depth; | |
316 | } | |
317 | ||
fe8f7f9c JS |
318 | /** |
319 | * lpfc_change_queue_type() - Change a device's scsi tag queuing type | |
320 | * @sdev: Pointer the scsi device whose queue depth is to change | |
321 | * @tag_type: Identifier for queue tag type | |
322 | */ | |
323 | static int | |
324 | lpfc_change_queue_type(struct scsi_device *sdev, int tag_type) | |
325 | { | |
326 | if (sdev->tagged_supported) { | |
327 | scsi_set_tag_type(sdev, tag_type); | |
328 | if (tag_type) | |
329 | scsi_activate_tcq(sdev, sdev->queue_depth); | |
330 | else | |
331 | scsi_deactivate_tcq(sdev, sdev->queue_depth); | |
332 | } else | |
333 | tag_type = 0; | |
334 | ||
335 | return tag_type; | |
336 | } | |
337 | ||
9bad7671 | 338 | /** |
3621a710 | 339 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
9bad7671 JS |
340 | * @phba: The Hba for which this call is being executed. |
341 | * | |
342 | * This routine is called when there is resource error in driver or firmware. | |
343 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine | |
344 | * posts at most 1 event each second. This routine wakes up worker thread of | |
345 | * @phba to process WORKER_RAM_DOWN_EVENT event. | |
346 | * | |
347 | * This routine should be called with no lock held. | |
348 | **/ | |
92d7f7b0 | 349 | void |
eaf15d5b | 350 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
92d7f7b0 JS |
351 | { |
352 | unsigned long flags; | |
5e9d9b82 | 353 | uint32_t evt_posted; |
92d7f7b0 JS |
354 | |
355 | spin_lock_irqsave(&phba->hbalock, flags); | |
356 | atomic_inc(&phba->num_rsrc_err); | |
357 | phba->last_rsrc_error_time = jiffies; | |
358 | ||
359 | if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) { | |
360 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
361 | return; | |
362 | } | |
363 | ||
364 | phba->last_ramp_down_time = jiffies; | |
365 | ||
366 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
367 | ||
368 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); | |
5e9d9b82 JS |
369 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
370 | if (!evt_posted) | |
92d7f7b0 | 371 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
92d7f7b0 JS |
372 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
373 | ||
5e9d9b82 JS |
374 | if (!evt_posted) |
375 | lpfc_worker_wake_up(phba); | |
92d7f7b0 JS |
376 | return; |
377 | } | |
378 | ||
9bad7671 | 379 | /** |
3621a710 | 380 | * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread |
9bad7671 JS |
381 | * @phba: The Hba for which this call is being executed. |
382 | * | |
383 | * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine | |
384 | * post at most 1 event every 5 minute after last_ramp_up_time or | |
385 | * last_rsrc_error_time. This routine wakes up worker thread of @phba | |
386 | * to process WORKER_RAM_DOWN_EVENT event. | |
387 | * | |
388 | * This routine should be called with no lock held. | |
389 | **/ | |
92d7f7b0 | 390 | static inline void |
3de2a653 | 391 | lpfc_rampup_queue_depth(struct lpfc_vport *vport, |
a257bf90 | 392 | uint32_t queue_depth) |
92d7f7b0 JS |
393 | { |
394 | unsigned long flags; | |
3de2a653 | 395 | struct lpfc_hba *phba = vport->phba; |
5e9d9b82 | 396 | uint32_t evt_posted; |
92d7f7b0 JS |
397 | atomic_inc(&phba->num_cmd_success); |
398 | ||
a257bf90 | 399 | if (vport->cfg_lun_queue_depth <= queue_depth) |
92d7f7b0 | 400 | return; |
92d7f7b0 | 401 | spin_lock_irqsave(&phba->hbalock, flags); |
5ffc266e JS |
402 | if (time_before(jiffies, |
403 | phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) || | |
404 | time_before(jiffies, | |
405 | phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) { | |
92d7f7b0 JS |
406 | spin_unlock_irqrestore(&phba->hbalock, flags); |
407 | return; | |
408 | } | |
92d7f7b0 JS |
409 | phba->last_ramp_up_time = jiffies; |
410 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
411 | ||
412 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); | |
5e9d9b82 JS |
413 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE; |
414 | if (!evt_posted) | |
92d7f7b0 | 415 | phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; |
92d7f7b0 JS |
416 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
417 | ||
5e9d9b82 JS |
418 | if (!evt_posted) |
419 | lpfc_worker_wake_up(phba); | |
420 | return; | |
92d7f7b0 JS |
421 | } |
422 | ||
9bad7671 | 423 | /** |
3621a710 | 424 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
9bad7671 JS |
425 | * @phba: The Hba for which this call is being executed. |
426 | * | |
427 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker | |
428 | * thread.This routine reduces queue depth for all scsi device on each vport | |
429 | * associated with @phba. | |
430 | **/ | |
92d7f7b0 JS |
431 | void |
432 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) | |
433 | { | |
549e55cd JS |
434 | struct lpfc_vport **vports; |
435 | struct Scsi_Host *shost; | |
92d7f7b0 | 436 | struct scsi_device *sdev; |
5ffc266e | 437 | unsigned long new_queue_depth; |
92d7f7b0 | 438 | unsigned long num_rsrc_err, num_cmd_success; |
549e55cd | 439 | int i; |
92d7f7b0 JS |
440 | |
441 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); | |
442 | num_cmd_success = atomic_read(&phba->num_cmd_success); | |
443 | ||
75ad83a4 JS |
444 | /* |
445 | * The error and success command counters are global per | |
446 | * driver instance. If another handler has already | |
447 | * operated on this error event, just exit. | |
448 | */ | |
449 | if (num_rsrc_err == 0) | |
450 | return; | |
451 | ||
549e55cd JS |
452 | vports = lpfc_create_vport_work_array(phba); |
453 | if (vports != NULL) | |
21e9a0a5 | 454 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
455 | shost = lpfc_shost_from_vport(vports[i]); |
456 | shost_for_each_device(sdev, shost) { | |
92d7f7b0 | 457 | new_queue_depth = |
549e55cd JS |
458 | sdev->queue_depth * num_rsrc_err / |
459 | (num_rsrc_err + num_cmd_success); | |
460 | if (!new_queue_depth) | |
461 | new_queue_depth = sdev->queue_depth - 1; | |
462 | else | |
463 | new_queue_depth = sdev->queue_depth - | |
464 | new_queue_depth; | |
5ffc266e JS |
465 | lpfc_change_queue_depth(sdev, new_queue_depth, |
466 | SCSI_QDEPTH_DEFAULT); | |
549e55cd | 467 | } |
92d7f7b0 | 468 | } |
09372820 | 469 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 JS |
470 | atomic_set(&phba->num_rsrc_err, 0); |
471 | atomic_set(&phba->num_cmd_success, 0); | |
472 | } | |
473 | ||
9bad7671 | 474 | /** |
3621a710 | 475 | * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler |
9bad7671 JS |
476 | * @phba: The Hba for which this call is being executed. |
477 | * | |
478 | * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker | |
479 | * thread.This routine increases queue depth for all scsi device on each vport | |
480 | * associated with @phba by 1. This routine also sets @phba num_rsrc_err and | |
481 | * num_cmd_success to zero. | |
482 | **/ | |
92d7f7b0 JS |
483 | void |
484 | lpfc_ramp_up_queue_handler(struct lpfc_hba *phba) | |
485 | { | |
549e55cd JS |
486 | struct lpfc_vport **vports; |
487 | struct Scsi_Host *shost; | |
92d7f7b0 | 488 | struct scsi_device *sdev; |
549e55cd JS |
489 | int i; |
490 | ||
491 | vports = lpfc_create_vport_work_array(phba); | |
492 | if (vports != NULL) | |
21e9a0a5 | 493 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
494 | shost = lpfc_shost_from_vport(vports[i]); |
495 | shost_for_each_device(sdev, shost) { | |
97eab634 JS |
496 | if (vports[i]->cfg_lun_queue_depth <= |
497 | sdev->queue_depth) | |
498 | continue; | |
5ffc266e JS |
499 | lpfc_change_queue_depth(sdev, |
500 | sdev->queue_depth+1, | |
501 | SCSI_QDEPTH_RAMP_UP); | |
549e55cd | 502 | } |
92d7f7b0 | 503 | } |
09372820 | 504 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 JS |
505 | atomic_set(&phba->num_rsrc_err, 0); |
506 | atomic_set(&phba->num_cmd_success, 0); | |
507 | } | |
508 | ||
a8e497d5 | 509 | /** |
3621a710 | 510 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
a8e497d5 JS |
511 | * @phba: Pointer to HBA context object. |
512 | * | |
513 | * This function walks vport list and set each SCSI host to block state | |
514 | * by invoking fc_remote_port_delete() routine. This function is invoked | |
515 | * with EEH when device's PCI slot has been permanently disabled. | |
516 | **/ | |
517 | void | |
518 | lpfc_scsi_dev_block(struct lpfc_hba *phba) | |
519 | { | |
520 | struct lpfc_vport **vports; | |
521 | struct Scsi_Host *shost; | |
522 | struct scsi_device *sdev; | |
523 | struct fc_rport *rport; | |
524 | int i; | |
525 | ||
526 | vports = lpfc_create_vport_work_array(phba); | |
527 | if (vports != NULL) | |
21e9a0a5 | 528 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8e497d5 JS |
529 | shost = lpfc_shost_from_vport(vports[i]); |
530 | shost_for_each_device(sdev, shost) { | |
531 | rport = starget_to_rport(scsi_target(sdev)); | |
532 | fc_remote_port_delete(rport); | |
533 | } | |
534 | } | |
535 | lpfc_destroy_vport_work_array(phba, vports); | |
536 | } | |
537 | ||
9bad7671 | 538 | /** |
3772a991 | 539 | * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec |
9bad7671 | 540 | * @vport: The virtual port for which this call being executed. |
3772a991 | 541 | * @num_to_allocate: The requested number of buffers to allocate. |
9bad7671 | 542 | * |
3772a991 JS |
543 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
544 | * the scsi buffer contains all the necessary information needed to initiate | |
545 | * a SCSI I/O. The non-DMAable buffer region contains information to build | |
546 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, | |
547 | * and the initial BPL. In addition to allocating memory, the FCP CMND and | |
548 | * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB. | |
9bad7671 JS |
549 | * |
550 | * Return codes: | |
3772a991 JS |
551 | * int - number of scsi buffers that were allocated. |
552 | * 0 = failure, less than num_to_alloc is a partial failure. | |
9bad7671 | 553 | **/ |
3772a991 JS |
554 | static int |
555 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) | |
dea3101e | 556 | { |
2e0fef85 | 557 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 558 | struct lpfc_scsi_buf *psb; |
559 | struct ulp_bde64 *bpl; | |
560 | IOCB_t *iocb; | |
34b02dcd JS |
561 | dma_addr_t pdma_phys_fcp_cmd; |
562 | dma_addr_t pdma_phys_fcp_rsp; | |
563 | dma_addr_t pdma_phys_bpl; | |
604a3e30 | 564 | uint16_t iotag; |
96f7077f JS |
565 | int bcnt, bpl_size; |
566 | ||
567 | bpl_size = phba->cfg_sg_dma_buf_size - | |
568 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
569 | ||
570 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, | |
571 | "9067 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", | |
572 | num_to_alloc, phba->cfg_sg_dma_buf_size, | |
573 | (int)sizeof(struct fcp_cmnd), | |
574 | (int)sizeof(struct fcp_rsp), bpl_size); | |
dea3101e | 575 | |
3772a991 JS |
576 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
577 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | |
578 | if (!psb) | |
579 | break; | |
dea3101e | 580 | |
3772a991 JS |
581 | /* |
582 | * Get memory from the pci pool to map the virt space to pci | |
583 | * bus space for an I/O. The DMA buffer includes space for the | |
584 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's | |
585 | * necessary to support the sg_tablesize. | |
586 | */ | |
587 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, | |
588 | GFP_KERNEL, &psb->dma_handle); | |
589 | if (!psb->data) { | |
590 | kfree(psb); | |
591 | break; | |
592 | } | |
593 | ||
594 | /* Initialize virtual ptrs to dma_buf region. */ | |
595 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); | |
596 | ||
597 | /* Allocate iotag for psb->cur_iocbq. */ | |
598 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | |
599 | if (iotag == 0) { | |
600 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, | |
601 | psb->data, psb->dma_handle); | |
602 | kfree(psb); | |
603 | break; | |
604 | } | |
605 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; | |
606 | ||
607 | psb->fcp_cmnd = psb->data; | |
608 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); | |
609 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + | |
34b02dcd | 610 | sizeof(struct fcp_rsp); |
dea3101e | 611 | |
3772a991 JS |
612 | /* Initialize local short-hand pointers. */ |
613 | bpl = psb->fcp_bpl; | |
614 | pdma_phys_fcp_cmd = psb->dma_handle; | |
615 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); | |
616 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + | |
617 | sizeof(struct fcp_rsp); | |
618 | ||
619 | /* | |
620 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance | |
621 | * are sg list bdes. Initialize the first two and leave the | |
622 | * rest for queuecommand. | |
623 | */ | |
624 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); | |
625 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); | |
626 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); | |
627 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
628 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); | |
629 | ||
630 | /* Setup the physical region for the FCP RSP */ | |
631 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); | |
632 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); | |
633 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); | |
634 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
635 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); | |
636 | ||
637 | /* | |
638 | * Since the IOCB for the FCP I/O is built into this | |
639 | * lpfc_scsi_buf, initialize it with all known data now. | |
640 | */ | |
641 | iocb = &psb->cur_iocbq.iocb; | |
642 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | |
643 | if ((phba->sli_rev == 3) && | |
644 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { | |
645 | /* fill in immediate fcp command BDE */ | |
646 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; | |
647 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | |
648 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, | |
649 | unsli3.fcp_ext.icd); | |
650 | iocb->un.fcpi64.bdl.addrHigh = 0; | |
651 | iocb->ulpBdeCount = 0; | |
652 | iocb->ulpLe = 0; | |
25985edc | 653 | /* fill in response BDE */ |
3772a991 JS |
654 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = |
655 | BUFF_TYPE_BDE_64; | |
656 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = | |
657 | sizeof(struct fcp_rsp); | |
658 | iocb->unsli3.fcp_ext.rbde.addrLow = | |
659 | putPaddrLow(pdma_phys_fcp_rsp); | |
660 | iocb->unsli3.fcp_ext.rbde.addrHigh = | |
661 | putPaddrHigh(pdma_phys_fcp_rsp); | |
662 | } else { | |
663 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
664 | iocb->un.fcpi64.bdl.bdeSize = | |
665 | (2 * sizeof(struct ulp_bde64)); | |
666 | iocb->un.fcpi64.bdl.addrLow = | |
667 | putPaddrLow(pdma_phys_bpl); | |
668 | iocb->un.fcpi64.bdl.addrHigh = | |
669 | putPaddrHigh(pdma_phys_bpl); | |
670 | iocb->ulpBdeCount = 1; | |
671 | iocb->ulpLe = 1; | |
672 | } | |
673 | iocb->ulpClass = CLASS3; | |
674 | psb->status = IOSTAT_SUCCESS; | |
da0436e9 | 675 | /* Put it back into the SCSI buffer list */ |
eee8877e | 676 | psb->cur_iocbq.context1 = psb; |
1c6f4ef5 | 677 | lpfc_release_scsi_buf_s3(phba, psb); |
dea3101e | 678 | |
34b02dcd | 679 | } |
dea3101e | 680 | |
3772a991 | 681 | return bcnt; |
dea3101e | 682 | } |
683 | ||
1151e3ec JS |
684 | /** |
685 | * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport | |
686 | * @vport: pointer to lpfc vport data structure. | |
687 | * | |
688 | * This routine is invoked by the vport cleanup for deletions and the cleanup | |
689 | * for an ndlp on removal. | |
690 | **/ | |
691 | void | |
692 | lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport) | |
693 | { | |
694 | struct lpfc_hba *phba = vport->phba; | |
695 | struct lpfc_scsi_buf *psb, *next_psb; | |
696 | unsigned long iflag = 0; | |
697 | ||
698 | spin_lock_irqsave(&phba->hbalock, iflag); | |
699 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
700 | list_for_each_entry_safe(psb, next_psb, | |
701 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { | |
702 | if (psb->rdata && psb->rdata->pnode | |
703 | && psb->rdata->pnode->vport == vport) | |
704 | psb->rdata = NULL; | |
705 | } | |
706 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
707 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
708 | } | |
709 | ||
da0436e9 JS |
710 | /** |
711 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort | |
712 | * @phba: pointer to lpfc hba data structure. | |
713 | * @axri: pointer to the fcp xri abort wcqe structure. | |
714 | * | |
715 | * This routine is invoked by the worker thread to process a SLI4 fast-path | |
716 | * FCP aborted xri. | |
717 | **/ | |
718 | void | |
719 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, | |
720 | struct sli4_wcqe_xri_aborted *axri) | |
721 | { | |
722 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); | |
19ca7609 | 723 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
da0436e9 JS |
724 | struct lpfc_scsi_buf *psb, *next_psb; |
725 | unsigned long iflag = 0; | |
0f65ff68 JS |
726 | struct lpfc_iocbq *iocbq; |
727 | int i; | |
19ca7609 JS |
728 | struct lpfc_nodelist *ndlp; |
729 | int rrq_empty = 0; | |
589a52d6 | 730 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
da0436e9 | 731 | |
0f65ff68 JS |
732 | spin_lock_irqsave(&phba->hbalock, iflag); |
733 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
da0436e9 JS |
734 | list_for_each_entry_safe(psb, next_psb, |
735 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { | |
736 | if (psb->cur_iocbq.sli4_xritag == xri) { | |
737 | list_del(&psb->list); | |
341af102 | 738 | psb->exch_busy = 0; |
da0436e9 | 739 | psb->status = IOSTAT_SUCCESS; |
0f65ff68 JS |
740 | spin_unlock( |
741 | &phba->sli4_hba.abts_scsi_buf_list_lock); | |
1151e3ec JS |
742 | if (psb->rdata && psb->rdata->pnode) |
743 | ndlp = psb->rdata->pnode; | |
744 | else | |
745 | ndlp = NULL; | |
746 | ||
19ca7609 | 747 | rrq_empty = list_empty(&phba->active_rrq_list); |
0f65ff68 | 748 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
cb69f7de | 749 | if (ndlp) { |
ee0f4fe1 JS |
750 | lpfc_set_rrq_active(phba, ndlp, |
751 | psb->cur_iocbq.sli4_lxritag, rxid, 1); | |
cb69f7de JS |
752 | lpfc_sli4_abts_err_handler(phba, ndlp, axri); |
753 | } | |
da0436e9 | 754 | lpfc_release_scsi_buf_s4(phba, psb); |
19ca7609 JS |
755 | if (rrq_empty) |
756 | lpfc_worker_wake_up(phba); | |
da0436e9 JS |
757 | return; |
758 | } | |
759 | } | |
0f65ff68 JS |
760 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
761 | for (i = 1; i <= phba->sli.last_iotag; i++) { | |
762 | iocbq = phba->sli.iocbq_lookup[i]; | |
763 | ||
764 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || | |
765 | (iocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
766 | continue; | |
767 | if (iocbq->sli4_xritag != xri) | |
768 | continue; | |
769 | psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); | |
770 | psb->exch_busy = 0; | |
771 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
0e9bb8d7 | 772 | if (!list_empty(&pring->txq)) |
589a52d6 | 773 | lpfc_worker_wake_up(phba); |
0f65ff68 JS |
774 | return; |
775 | ||
776 | } | |
777 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
da0436e9 JS |
778 | } |
779 | ||
780 | /** | |
8a9d2e80 | 781 | * lpfc_sli4_post_scsi_sgl_list - Psot blocks of scsi buffer sgls from a list |
da0436e9 | 782 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 | 783 | * @post_sblist: pointer to the scsi buffer list. |
da0436e9 | 784 | * |
8a9d2e80 JS |
785 | * This routine walks a list of scsi buffers that was passed in. It attempts |
786 | * to construct blocks of scsi buffer sgls which contains contiguous xris and | |
787 | * uses the non-embedded SGL block post mailbox commands to post to the port. | |
788 | * For single SCSI buffer sgl with non-contiguous xri, if any, it shall use | |
789 | * embedded SGL post mailbox command for posting. The @post_sblist passed in | |
790 | * must be local list, thus no lock is needed when manipulate the list. | |
da0436e9 | 791 | * |
8a9d2e80 | 792 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
da0436e9 JS |
793 | **/ |
794 | int | |
8a9d2e80 JS |
795 | lpfc_sli4_post_scsi_sgl_list(struct lpfc_hba *phba, |
796 | struct list_head *post_sblist, int sb_count) | |
da0436e9 | 797 | { |
8a9d2e80 | 798 | struct lpfc_scsi_buf *psb, *psb_next; |
96f7077f | 799 | int status, sgl_size; |
8a9d2e80 JS |
800 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
801 | dma_addr_t pdma_phys_bpl1; | |
802 | int last_xritag = NO_XRI; | |
803 | LIST_HEAD(prep_sblist); | |
804 | LIST_HEAD(blck_sblist); | |
805 | LIST_HEAD(scsi_sblist); | |
806 | ||
807 | /* sanity check */ | |
808 | if (sb_count <= 0) | |
809 | return -EINVAL; | |
810 | ||
96f7077f JS |
811 | sgl_size = phba->cfg_sg_dma_buf_size - |
812 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
813 | ||
8a9d2e80 JS |
814 | list_for_each_entry_safe(psb, psb_next, post_sblist, list) { |
815 | list_del_init(&psb->list); | |
816 | block_cnt++; | |
817 | if ((last_xritag != NO_XRI) && | |
818 | (psb->cur_iocbq.sli4_xritag != last_xritag + 1)) { | |
819 | /* a hole in xri block, form a sgl posting block */ | |
820 | list_splice_init(&prep_sblist, &blck_sblist); | |
821 | post_cnt = block_cnt - 1; | |
822 | /* prepare list for next posting block */ | |
823 | list_add_tail(&psb->list, &prep_sblist); | |
824 | block_cnt = 1; | |
825 | } else { | |
826 | /* prepare list for next posting block */ | |
827 | list_add_tail(&psb->list, &prep_sblist); | |
828 | /* enough sgls for non-embed sgl mbox command */ | |
829 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
830 | list_splice_init(&prep_sblist, &blck_sblist); | |
831 | post_cnt = block_cnt; | |
832 | block_cnt = 0; | |
da0436e9 | 833 | } |
8a9d2e80 JS |
834 | } |
835 | num_posting++; | |
836 | last_xritag = psb->cur_iocbq.sli4_xritag; | |
da0436e9 | 837 | |
8a9d2e80 JS |
838 | /* end of repost sgl list condition for SCSI buffers */ |
839 | if (num_posting == sb_count) { | |
840 | if (post_cnt == 0) { | |
841 | /* last sgl posting block */ | |
842 | list_splice_init(&prep_sblist, &blck_sblist); | |
843 | post_cnt = block_cnt; | |
844 | } else if (block_cnt == 1) { | |
845 | /* last single sgl with non-contiguous xri */ | |
96f7077f | 846 | if (sgl_size > SGL_PAGE_SIZE) |
8a9d2e80 JS |
847 | pdma_phys_bpl1 = psb->dma_phys_bpl + |
848 | SGL_PAGE_SIZE; | |
849 | else | |
850 | pdma_phys_bpl1 = 0; | |
851 | status = lpfc_sli4_post_sgl(phba, | |
852 | psb->dma_phys_bpl, | |
853 | pdma_phys_bpl1, | |
854 | psb->cur_iocbq.sli4_xritag); | |
855 | if (status) { | |
856 | /* failure, put on abort scsi list */ | |
857 | psb->exch_busy = 1; | |
858 | } else { | |
859 | /* success, put on SCSI buffer list */ | |
860 | psb->exch_busy = 0; | |
861 | psb->status = IOSTAT_SUCCESS; | |
862 | num_posted++; | |
863 | } | |
864 | /* success, put on SCSI buffer sgl list */ | |
865 | list_add_tail(&psb->list, &scsi_sblist); | |
866 | } | |
867 | } | |
da0436e9 | 868 | |
8a9d2e80 JS |
869 | /* continue until a nembed page worth of sgls */ |
870 | if (post_cnt == 0) | |
da0436e9 | 871 | continue; |
8a9d2e80 JS |
872 | |
873 | /* post block of SCSI buffer list sgls */ | |
874 | status = lpfc_sli4_post_scsi_sgl_block(phba, &blck_sblist, | |
875 | post_cnt); | |
876 | ||
877 | /* don't reset xirtag due to hole in xri block */ | |
878 | if (block_cnt == 0) | |
879 | last_xritag = NO_XRI; | |
880 | ||
881 | /* reset SCSI buffer post count for next round of posting */ | |
882 | post_cnt = 0; | |
883 | ||
884 | /* put posted SCSI buffer-sgl posted on SCSI buffer sgl list */ | |
885 | while (!list_empty(&blck_sblist)) { | |
886 | list_remove_head(&blck_sblist, psb, | |
887 | struct lpfc_scsi_buf, list); | |
da0436e9 | 888 | if (status) { |
8a9d2e80 | 889 | /* failure, put on abort scsi list */ |
341af102 | 890 | psb->exch_busy = 1; |
341af102 | 891 | } else { |
8a9d2e80 | 892 | /* success, put on SCSI buffer list */ |
341af102 | 893 | psb->exch_busy = 0; |
da0436e9 | 894 | psb->status = IOSTAT_SUCCESS; |
8a9d2e80 | 895 | num_posted++; |
341af102 | 896 | } |
8a9d2e80 | 897 | list_add_tail(&psb->list, &scsi_sblist); |
da0436e9 JS |
898 | } |
899 | } | |
8a9d2e80 JS |
900 | /* Push SCSI buffers with sgl posted to the availble list */ |
901 | while (!list_empty(&scsi_sblist)) { | |
902 | list_remove_head(&scsi_sblist, psb, | |
903 | struct lpfc_scsi_buf, list); | |
904 | lpfc_release_scsi_buf_s4(phba, psb); | |
905 | } | |
906 | return num_posted; | |
907 | } | |
908 | ||
909 | /** | |
910 | * lpfc_sli4_repost_scsi_sgl_list - Repsot all the allocated scsi buffer sgls | |
911 | * @phba: pointer to lpfc hba data structure. | |
912 | * | |
913 | * This routine walks the list of scsi buffers that have been allocated and | |
914 | * repost them to the port by using SGL block post. This is needed after a | |
915 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine | |
916 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list | |
917 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. | |
918 | * | |
919 | * Returns: 0 = success, non-zero failure. | |
920 | **/ | |
921 | int | |
922 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) | |
923 | { | |
924 | LIST_HEAD(post_sblist); | |
925 | int num_posted, rc = 0; | |
926 | ||
927 | /* get all SCSI buffers need to repost to a local list */ | |
a40fc5f0 JS |
928 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
929 | spin_lock_irq(&phba->scsi_buf_list_put_lock); | |
930 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &post_sblist); | |
931 | list_splice(&phba->lpfc_scsi_buf_list_put, &post_sblist); | |
932 | spin_unlock_irq(&phba->scsi_buf_list_put_lock); | |
933 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); | |
8a9d2e80 JS |
934 | |
935 | /* post the list of scsi buffer sgls to port if available */ | |
936 | if (!list_empty(&post_sblist)) { | |
937 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, &post_sblist, | |
938 | phba->sli4_hba.scsi_xri_cnt); | |
939 | /* failed to post any scsi buffer, return error */ | |
940 | if (num_posted == 0) | |
941 | rc = -EIO; | |
942 | } | |
da0436e9 JS |
943 | return rc; |
944 | } | |
945 | ||
946 | /** | |
947 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec | |
948 | * @vport: The virtual port for which this call being executed. | |
949 | * @num_to_allocate: The requested number of buffers to allocate. | |
950 | * | |
8a9d2e80 | 951 | * This routine allocates scsi buffers for device with SLI-4 interface spec, |
da0436e9 | 952 | * the scsi buffer contains all the necessary information needed to initiate |
8a9d2e80 JS |
953 | * a SCSI I/O. After allocating up to @num_to_allocate SCSI buffers and put |
954 | * them on a list, it post them to the port by using SGL block post. | |
da0436e9 JS |
955 | * |
956 | * Return codes: | |
8a9d2e80 | 957 | * int - number of scsi buffers that were allocated and posted. |
da0436e9 JS |
958 | * 0 = failure, less than num_to_alloc is a partial failure. |
959 | **/ | |
960 | static int | |
961 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) | |
962 | { | |
963 | struct lpfc_hba *phba = vport->phba; | |
964 | struct lpfc_scsi_buf *psb; | |
965 | struct sli4_sge *sgl; | |
966 | IOCB_t *iocb; | |
967 | dma_addr_t pdma_phys_fcp_cmd; | |
968 | dma_addr_t pdma_phys_fcp_rsp; | |
96f7077f | 969 | dma_addr_t pdma_phys_bpl; |
8a9d2e80 | 970 | uint16_t iotag, lxri = 0; |
96f7077f | 971 | int bcnt, num_posted, sgl_size; |
8a9d2e80 JS |
972 | LIST_HEAD(prep_sblist); |
973 | LIST_HEAD(post_sblist); | |
974 | LIST_HEAD(scsi_sblist); | |
da0436e9 | 975 | |
96f7077f JS |
976 | sgl_size = phba->cfg_sg_dma_buf_size - |
977 | (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
978 | ||
979 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, | |
980 | "9068 ALLOC %d scsi_bufs: %d (%d + %d + %d)\n", | |
981 | num_to_alloc, phba->cfg_sg_dma_buf_size, sgl_size, | |
982 | (int)sizeof(struct fcp_cmnd), | |
983 | (int)sizeof(struct fcp_rsp)); | |
984 | ||
da0436e9 JS |
985 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
986 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | |
987 | if (!psb) | |
988 | break; | |
da0436e9 | 989 | /* |
8a9d2e80 JS |
990 | * Get memory from the pci pool to map the virt space to |
991 | * pci bus space for an I/O. The DMA buffer includes space | |
992 | * for the struct fcp_cmnd, struct fcp_rsp and the number | |
993 | * of bde's necessary to support the sg_tablesize. | |
da0436e9 JS |
994 | */ |
995 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, | |
996 | GFP_KERNEL, &psb->dma_handle); | |
997 | if (!psb->data) { | |
998 | kfree(psb); | |
999 | break; | |
1000 | } | |
da0436e9 JS |
1001 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
1002 | ||
092cb034 JS |
1003 | /* |
1004 | * 4K Page alignment is CRITICAL to BlockGuard, double check | |
1005 | * to be sure. | |
1006 | */ | |
1007 | if (phba->cfg_enable_bg && (((unsigned long)(psb->data) & | |
1008 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { | |
96f7077f JS |
1009 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
1010 | psb->data, psb->dma_handle); | |
1011 | kfree(psb); | |
1012 | break; | |
1013 | } | |
1014 | ||
da0436e9 JS |
1015 | /* Allocate iotag for psb->cur_iocbq. */ |
1016 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | |
1017 | if (iotag == 0) { | |
b92938b4 JS |
1018 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
1019 | psb->data, psb->dma_handle); | |
da0436e9 JS |
1020 | kfree(psb); |
1021 | break; | |
1022 | } | |
1023 | ||
6d368e53 JS |
1024 | lxri = lpfc_sli4_next_xritag(phba); |
1025 | if (lxri == NO_XRI) { | |
da0436e9 JS |
1026 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
1027 | psb->data, psb->dma_handle); | |
1028 | kfree(psb); | |
1029 | break; | |
1030 | } | |
6d368e53 JS |
1031 | psb->cur_iocbq.sli4_lxritag = lxri; |
1032 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
da0436e9 | 1033 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
da0436e9 | 1034 | psb->fcp_bpl = psb->data; |
96f7077f | 1035 | psb->fcp_cmnd = (psb->data + sgl_size); |
da0436e9 JS |
1036 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + |
1037 | sizeof(struct fcp_cmnd)); | |
1038 | ||
1039 | /* Initialize local short-hand pointers. */ | |
1040 | sgl = (struct sli4_sge *)psb->fcp_bpl; | |
1041 | pdma_phys_bpl = psb->dma_handle; | |
96f7077f | 1042 | pdma_phys_fcp_cmd = (psb->dma_handle + sgl_size); |
da0436e9 JS |
1043 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); |
1044 | ||
1045 | /* | |
8a9d2e80 JS |
1046 | * The first two bdes are the FCP_CMD and FCP_RSP. |
1047 | * The balance are sg list bdes. Initialize the | |
1048 | * first two and leave the rest for queuecommand. | |
da0436e9 JS |
1049 | */ |
1050 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); | |
1051 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); | |
0558056c | 1052 | sgl->word2 = le32_to_cpu(sgl->word2); |
da0436e9 JS |
1053 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
1054 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 | 1055 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd)); |
da0436e9 JS |
1056 | sgl++; |
1057 | ||
1058 | /* Setup the physical region for the FCP RSP */ | |
1059 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); | |
1060 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); | |
0558056c | 1061 | sgl->word2 = le32_to_cpu(sgl->word2); |
da0436e9 JS |
1062 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
1063 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 | 1064 | sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp)); |
da0436e9 JS |
1065 | |
1066 | /* | |
1067 | * Since the IOCB for the FCP I/O is built into this | |
1068 | * lpfc_scsi_buf, initialize it with all known data now. | |
1069 | */ | |
1070 | iocb = &psb->cur_iocbq.iocb; | |
1071 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | |
1072 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; | |
1073 | /* setting the BLP size to 2 * sizeof BDE may not be correct. | |
1074 | * We are setting the bpl to point to out sgl. An sgl's | |
1075 | * entries are 16 bytes, a bpl entries are 12 bytes. | |
1076 | */ | |
1077 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | |
1078 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); | |
1079 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); | |
1080 | iocb->ulpBdeCount = 1; | |
1081 | iocb->ulpLe = 1; | |
1082 | iocb->ulpClass = CLASS3; | |
8a9d2e80 | 1083 | psb->cur_iocbq.context1 = psb; |
da0436e9 | 1084 | psb->dma_phys_bpl = pdma_phys_bpl; |
da0436e9 | 1085 | |
8a9d2e80 JS |
1086 | /* add the scsi buffer to a post list */ |
1087 | list_add_tail(&psb->list, &post_sblist); | |
a40fc5f0 | 1088 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 | 1089 | phba->sli4_hba.scsi_xri_cnt++; |
a40fc5f0 | 1090 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 JS |
1091 | } |
1092 | lpfc_printf_log(phba, KERN_INFO, LOG_BG, | |
1093 | "3021 Allocate %d out of %d requested new SCSI " | |
1094 | "buffers\n", bcnt, num_to_alloc); | |
1095 | ||
1096 | /* post the list of scsi buffer sgls to port if available */ | |
1097 | if (!list_empty(&post_sblist)) | |
1098 | num_posted = lpfc_sli4_post_scsi_sgl_list(phba, | |
1099 | &post_sblist, bcnt); | |
1100 | else | |
1101 | num_posted = 0; | |
1102 | ||
1103 | return num_posted; | |
da0436e9 JS |
1104 | } |
1105 | ||
9bad7671 | 1106 | /** |
3772a991 JS |
1107 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
1108 | * @vport: The virtual port for which this call being executed. | |
1109 | * @num_to_allocate: The requested number of buffers to allocate. | |
1110 | * | |
1111 | * This routine wraps the actual SCSI buffer allocator function pointer from | |
1112 | * the lpfc_hba struct. | |
1113 | * | |
1114 | * Return codes: | |
1115 | * int - number of scsi buffers that were allocated. | |
1116 | * 0 = failure, less than num_to_alloc is a partial failure. | |
1117 | **/ | |
1118 | static inline int | |
1119 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) | |
1120 | { | |
1121 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); | |
1122 | } | |
1123 | ||
1124 | /** | |
19ca7609 | 1125 | * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA |
3772a991 | 1126 | * @phba: The HBA for which this call is being executed. |
9bad7671 JS |
1127 | * |
1128 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
1129 | * and returns to caller. | |
1130 | * | |
1131 | * Return codes: | |
1132 | * NULL - Error | |
1133 | * Pointer to lpfc_scsi_buf - Success | |
1134 | **/ | |
455c53ec | 1135 | static struct lpfc_scsi_buf* |
19ca7609 | 1136 | lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
dea3101e | 1137 | { |
0bd4ca25 | 1138 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
a40fc5f0 JS |
1139 | struct list_head *scsi_buf_list_get = &phba->lpfc_scsi_buf_list_get; |
1140 | unsigned long gflag = 0; | |
1141 | unsigned long pflag = 0; | |
1142 | ||
1143 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, gflag); | |
1144 | list_remove_head(scsi_buf_list_get, lpfc_cmd, struct lpfc_scsi_buf, | |
1145 | list); | |
1146 | if (!lpfc_cmd) { | |
1147 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, pflag); | |
1148 | list_splice(&phba->lpfc_scsi_buf_list_put, | |
1149 | &phba->lpfc_scsi_buf_list_get); | |
1150 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); | |
1151 | list_remove_head(scsi_buf_list_get, lpfc_cmd, | |
1152 | struct lpfc_scsi_buf, list); | |
1153 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, pflag); | |
1dcb58e5 | 1154 | } |
a40fc5f0 | 1155 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, gflag); |
0bd4ca25 JSEC |
1156 | return lpfc_cmd; |
1157 | } | |
19ca7609 JS |
1158 | /** |
1159 | * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA | |
1160 | * @phba: The HBA for which this call is being executed. | |
1161 | * | |
1162 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
1163 | * and returns to caller. | |
1164 | * | |
1165 | * Return codes: | |
1166 | * NULL - Error | |
1167 | * Pointer to lpfc_scsi_buf - Success | |
1168 | **/ | |
1169 | static struct lpfc_scsi_buf* | |
1170 | lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) | |
1171 | { | |
3be30e0e | 1172 | struct lpfc_scsi_buf *lpfc_cmd, *lpfc_cmd_next; |
a40fc5f0 JS |
1173 | unsigned long gflag = 0; |
1174 | unsigned long pflag = 0; | |
19ca7609 JS |
1175 | int found = 0; |
1176 | ||
a40fc5f0 | 1177 | spin_lock_irqsave(&phba->scsi_buf_list_get_lock, gflag); |
3be30e0e JS |
1178 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
1179 | &phba->lpfc_scsi_buf_list_get, list) { | |
19ca7609 | 1180 | if (lpfc_test_rrq_active(phba, ndlp, |
ee0f4fe1 | 1181 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
1151e3ec JS |
1182 | continue; |
1183 | list_del(&lpfc_cmd->list); | |
19ca7609 | 1184 | found = 1; |
1151e3ec | 1185 | break; |
19ca7609 | 1186 | } |
a40fc5f0 JS |
1187 | if (!found) { |
1188 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, pflag); | |
1189 | list_splice(&phba->lpfc_scsi_buf_list_put, | |
1190 | &phba->lpfc_scsi_buf_list_get); | |
1191 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); | |
1192 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, pflag); | |
3be30e0e JS |
1193 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
1194 | &phba->lpfc_scsi_buf_list_get, list) { | |
a40fc5f0 JS |
1195 | if (lpfc_test_rrq_active( |
1196 | phba, ndlp, lpfc_cmd->cur_iocbq.sli4_lxritag)) | |
1197 | continue; | |
1198 | list_del(&lpfc_cmd->list); | |
1199 | found = 1; | |
1200 | break; | |
1201 | } | |
1202 | } | |
1203 | spin_unlock_irqrestore(&phba->scsi_buf_list_get_lock, gflag); | |
1151e3ec JS |
1204 | if (!found) |
1205 | return NULL; | |
a40fc5f0 | 1206 | return lpfc_cmd; |
19ca7609 JS |
1207 | } |
1208 | /** | |
1209 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA | |
1210 | * @phba: The HBA for which this call is being executed. | |
1211 | * | |
1212 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
1213 | * and returns to caller. | |
1214 | * | |
1215 | * Return codes: | |
1216 | * NULL - Error | |
1217 | * Pointer to lpfc_scsi_buf - Success | |
1218 | **/ | |
1219 | static struct lpfc_scsi_buf* | |
1220 | lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) | |
1221 | { | |
1222 | return phba->lpfc_get_scsi_buf(phba, ndlp); | |
1223 | } | |
dea3101e | 1224 | |
9bad7671 | 1225 | /** |
3772a991 | 1226 | * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list |
9bad7671 JS |
1227 | * @phba: The Hba for which this call is being executed. |
1228 | * @psb: The scsi buffer which is being released. | |
1229 | * | |
1230 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
1231 | * lpfc_scsi_buf_list list. | |
1232 | **/ | |
0bd4ca25 | 1233 | static void |
3772a991 | 1234 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
0bd4ca25 | 1235 | { |
875fbdfe | 1236 | unsigned long iflag = 0; |
dea3101e | 1237 | |
a40fc5f0 JS |
1238 | psb->seg_cnt = 0; |
1239 | psb->nonsg_phys = 0; | |
1240 | psb->prot_seg_cnt = 0; | |
1241 | ||
1242 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); | |
0bd4ca25 | 1243 | psb->pCmd = NULL; |
6a485eb9 | 1244 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
a40fc5f0 JS |
1245 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); |
1246 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); | |
dea3101e | 1247 | } |
1248 | ||
da0436e9 JS |
1249 | /** |
1250 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. | |
1251 | * @phba: The Hba for which this call is being executed. | |
1252 | * @psb: The scsi buffer which is being released. | |
1253 | * | |
1254 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
1255 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer | |
1256 | * and cannot be reused for at least RA_TOV amount of time if it was | |
1257 | * aborted. | |
1258 | **/ | |
1259 | static void | |
1260 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |
1261 | { | |
1262 | unsigned long iflag = 0; | |
1263 | ||
a40fc5f0 JS |
1264 | psb->seg_cnt = 0; |
1265 | psb->nonsg_phys = 0; | |
1266 | psb->prot_seg_cnt = 0; | |
1267 | ||
341af102 | 1268 | if (psb->exch_busy) { |
da0436e9 JS |
1269 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, |
1270 | iflag); | |
1271 | psb->pCmd = NULL; | |
1272 | list_add_tail(&psb->list, | |
1273 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
1274 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, | |
1275 | iflag); | |
1276 | } else { | |
da0436e9 | 1277 | psb->pCmd = NULL; |
6a485eb9 | 1278 | psb->cur_iocbq.iocb_flag = LPFC_IO_FCP; |
a40fc5f0 JS |
1279 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
1280 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list_put); | |
1281 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); | |
da0436e9 JS |
1282 | } |
1283 | } | |
1284 | ||
9bad7671 | 1285 | /** |
3772a991 JS |
1286 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
1287 | * @phba: The Hba for which this call is being executed. | |
1288 | * @psb: The scsi buffer which is being released. | |
1289 | * | |
1290 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
1291 | * lpfc_scsi_buf_list list. | |
1292 | **/ | |
1293 | static void | |
1294 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |
1295 | { | |
1296 | ||
1297 | phba->lpfc_release_scsi_buf(phba, psb); | |
1298 | } | |
1299 | ||
1300 | /** | |
1301 | * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec | |
9bad7671 JS |
1302 | * @phba: The Hba for which this call is being executed. |
1303 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
1304 | * | |
1305 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | |
3772a991 JS |
1306 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
1307 | * through sg elements and format the bdea. This routine also initializes all | |
1308 | * IOCB fields which are dependent on scsi command request buffer. | |
9bad7671 JS |
1309 | * |
1310 | * Return codes: | |
1311 | * 1 - Error | |
1312 | * 0 - Success | |
1313 | **/ | |
dea3101e | 1314 | static int |
3772a991 | 1315 | lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
dea3101e | 1316 | { |
1317 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
1318 | struct scatterlist *sgel = NULL; | |
1319 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
1320 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; | |
0f65ff68 | 1321 | struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq; |
dea3101e | 1322 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
34b02dcd | 1323 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
dea3101e | 1324 | dma_addr_t physaddr; |
34b02dcd | 1325 | uint32_t num_bde = 0; |
a0b4f78f | 1326 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
dea3101e | 1327 | |
1328 | /* | |
1329 | * There are three possibilities here - use scatter-gather segment, use | |
1330 | * the single mapping, or neither. Start the lpfc command prep by | |
1331 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
1332 | * data bde entry. | |
1333 | */ | |
1334 | bpl += 2; | |
c59fd9eb | 1335 | if (scsi_sg_count(scsi_cmnd)) { |
dea3101e | 1336 | /* |
1337 | * The driver stores the segment count returned from pci_map_sg | |
1338 | * because this a count of dma-mappings used to map the use_sg | |
1339 | * pages. They are not guaranteed to be the same for those | |
1340 | * architectures that implement an IOMMU. | |
1341 | */ | |
dea3101e | 1342 | |
c59fd9eb FT |
1343 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
1344 | scsi_sg_count(scsi_cmnd), datadir); | |
1345 | if (unlikely(!nseg)) | |
1346 | return 1; | |
1347 | ||
a0b4f78f | 1348 | lpfc_cmd->seg_cnt = nseg; |
dea3101e | 1349 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
6a9c52cf JS |
1350 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1351 | "9064 BLKGRD: %s: Too many sg segments from " | |
e2a0a9d6 | 1352 | "dma_map_sg. Config %d, seg_cnt %d\n", |
cadbd4a5 | 1353 | __func__, phba->cfg_sg_seg_cnt, |
dea3101e | 1354 | lpfc_cmd->seg_cnt); |
96f7077f | 1355 | lpfc_cmd->seg_cnt = 0; |
a0b4f78f | 1356 | scsi_dma_unmap(scsi_cmnd); |
dea3101e | 1357 | return 1; |
1358 | } | |
1359 | ||
1360 | /* | |
1361 | * The driver established a maximum scatter-gather segment count | |
1362 | * during probe that limits the number of sg elements in any | |
1363 | * single scsi command. Just run through the seg_cnt and format | |
1364 | * the bde's. | |
34b02dcd JS |
1365 | * When using SLI-3 the driver will try to fit all the BDEs into |
1366 | * the IOCB. If it can't then the BDEs get added to a BPL as it | |
1367 | * does for SLI-2 mode. | |
dea3101e | 1368 | */ |
34b02dcd | 1369 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
dea3101e | 1370 | physaddr = sg_dma_address(sgel); |
34b02dcd | 1371 | if (phba->sli_rev == 3 && |
e2a0a9d6 | 1372 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
0f65ff68 | 1373 | !(iocbq->iocb_flag & DSS_SECURITY_OP) && |
34b02dcd JS |
1374 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
1375 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1376 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); | |
1377 | data_bde->addrLow = putPaddrLow(physaddr); | |
1378 | data_bde->addrHigh = putPaddrHigh(physaddr); | |
1379 | data_bde++; | |
1380 | } else { | |
1381 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1382 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
1383 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1384 | bpl->addrLow = | |
1385 | le32_to_cpu(putPaddrLow(physaddr)); | |
1386 | bpl->addrHigh = | |
1387 | le32_to_cpu(putPaddrHigh(physaddr)); | |
1388 | bpl++; | |
1389 | } | |
dea3101e | 1390 | } |
c59fd9eb | 1391 | } |
dea3101e | 1392 | |
1393 | /* | |
1394 | * Finish initializing those IOCB fields that are dependent on the | |
34b02dcd JS |
1395 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
1396 | * explicitly reinitialized and for SLI-3 the extended bde count is | |
1397 | * explicitly reinitialized since all iocb memory resources are reused. | |
dea3101e | 1398 | */ |
e2a0a9d6 | 1399 | if (phba->sli_rev == 3 && |
0f65ff68 JS |
1400 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
1401 | !(iocbq->iocb_flag & DSS_SECURITY_OP)) { | |
34b02dcd JS |
1402 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
1403 | /* | |
1404 | * The extended IOCB format can only fit 3 BDE or a BPL. | |
1405 | * This I/O has more than 3 BDE so the 1st data bde will | |
1406 | * be a BPL that is filled in here. | |
1407 | */ | |
1408 | physaddr = lpfc_cmd->dma_handle; | |
1409 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; | |
1410 | data_bde->tus.f.bdeSize = (num_bde * | |
1411 | sizeof(struct ulp_bde64)); | |
1412 | physaddr += (sizeof(struct fcp_cmnd) + | |
1413 | sizeof(struct fcp_rsp) + | |
1414 | (2 * sizeof(struct ulp_bde64))); | |
1415 | data_bde->addrHigh = putPaddrHigh(physaddr); | |
1416 | data_bde->addrLow = putPaddrLow(physaddr); | |
25985edc | 1417 | /* ebde count includes the response bde and data bpl */ |
34b02dcd JS |
1418 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; |
1419 | } else { | |
25985edc | 1420 | /* ebde count includes the response bde and data bdes */ |
34b02dcd JS |
1421 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
1422 | } | |
1423 | } else { | |
1424 | iocb_cmd->un.fcpi64.bdl.bdeSize = | |
1425 | ((num_bde + 2) * sizeof(struct ulp_bde64)); | |
0f65ff68 | 1426 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); |
34b02dcd | 1427 | } |
09372820 | 1428 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
e2a0a9d6 JS |
1429 | |
1430 | /* | |
1431 | * Due to difference in data length between DIF/non-DIF paths, | |
1432 | * we need to set word 4 of IOCB here | |
1433 | */ | |
a257bf90 | 1434 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
e2a0a9d6 JS |
1435 | return 0; |
1436 | } | |
1437 | ||
f9bb2da1 | 1438 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
acd6859b | 1439 | |
9a6b09c0 JS |
1440 | /* Return if if error injection is detected by Initiator */ |
1441 | #define BG_ERR_INIT 0x1 | |
1442 | /* Return if if error injection is detected by Target */ | |
1443 | #define BG_ERR_TGT 0x2 | |
1444 | /* Return if if swapping CSUM<-->CRC is required for error injection */ | |
1445 | #define BG_ERR_SWAP 0x10 | |
1446 | /* Return if disabling Guard/Ref/App checking is required for error injection */ | |
1447 | #define BG_ERR_CHECK 0x20 | |
acd6859b JS |
1448 | |
1449 | /** | |
1450 | * lpfc_bg_err_inject - Determine if we should inject an error | |
1451 | * @phba: The Hba for which this call is being executed. | |
f9bb2da1 JS |
1452 | * @sc: The SCSI command to examine |
1453 | * @reftag: (out) BlockGuard reference tag for transmitted data | |
1454 | * @apptag: (out) BlockGuard application tag for transmitted data | |
1455 | * @new_guard (in) Value to replace CRC with if needed | |
1456 | * | |
9a6b09c0 | 1457 | * Returns BG_ERR_* bit mask or 0 if request ignored |
acd6859b | 1458 | **/ |
f9bb2da1 JS |
1459 | static int |
1460 | lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
1461 | uint32_t *reftag, uint16_t *apptag, uint32_t new_guard) | |
1462 | { | |
1463 | struct scatterlist *sgpe; /* s/g prot entry */ | |
1464 | struct scatterlist *sgde; /* s/g data entry */ | |
9a6b09c0 | 1465 | struct lpfc_scsi_buf *lpfc_cmd = NULL; |
acd6859b | 1466 | struct scsi_dif_tuple *src = NULL; |
4ac9b226 JS |
1467 | struct lpfc_nodelist *ndlp; |
1468 | struct lpfc_rport_data *rdata; | |
f9bb2da1 JS |
1469 | uint32_t op = scsi_get_prot_op(sc); |
1470 | uint32_t blksize; | |
1471 | uint32_t numblks; | |
1472 | sector_t lba; | |
1473 | int rc = 0; | |
acd6859b | 1474 | int blockoff = 0; |
f9bb2da1 JS |
1475 | |
1476 | if (op == SCSI_PROT_NORMAL) | |
1477 | return 0; | |
1478 | ||
acd6859b JS |
1479 | sgpe = scsi_prot_sglist(sc); |
1480 | sgde = scsi_sglist(sc); | |
f9bb2da1 | 1481 | lba = scsi_get_lba(sc); |
4ac9b226 JS |
1482 | |
1483 | /* First check if we need to match the LBA */ | |
f9bb2da1 JS |
1484 | if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) { |
1485 | blksize = lpfc_cmd_blksize(sc); | |
1486 | numblks = (scsi_bufflen(sc) + blksize - 1) / blksize; | |
1487 | ||
1488 | /* Make sure we have the right LBA if one is specified */ | |
1489 | if ((phba->lpfc_injerr_lba < lba) || | |
1490 | (phba->lpfc_injerr_lba >= (lba + numblks))) | |
1491 | return 0; | |
acd6859b JS |
1492 | if (sgpe) { |
1493 | blockoff = phba->lpfc_injerr_lba - lba; | |
1494 | numblks = sg_dma_len(sgpe) / | |
1495 | sizeof(struct scsi_dif_tuple); | |
1496 | if (numblks < blockoff) | |
1497 | blockoff = numblks; | |
acd6859b | 1498 | } |
f9bb2da1 JS |
1499 | } |
1500 | ||
4ac9b226 JS |
1501 | /* Next check if we need to match the remote NPortID or WWPN */ |
1502 | rdata = sc->device->hostdata; | |
1503 | if (rdata && rdata->pnode) { | |
1504 | ndlp = rdata->pnode; | |
1505 | ||
1506 | /* Make sure we have the right NPortID if one is specified */ | |
1507 | if (phba->lpfc_injerr_nportid && | |
1508 | (phba->lpfc_injerr_nportid != ndlp->nlp_DID)) | |
1509 | return 0; | |
1510 | ||
1511 | /* | |
1512 | * Make sure we have the right WWPN if one is specified. | |
1513 | * wwn[0] should be a non-zero NAA in a good WWPN. | |
1514 | */ | |
1515 | if (phba->lpfc_injerr_wwpn.u.wwn[0] && | |
1516 | (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn, | |
1517 | sizeof(struct lpfc_name)) != 0)) | |
1518 | return 0; | |
1519 | } | |
1520 | ||
1521 | /* Setup a ptr to the protection data if the SCSI host provides it */ | |
1522 | if (sgpe) { | |
1523 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); | |
1524 | src += blockoff; | |
1525 | lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble; | |
1526 | } | |
1527 | ||
f9bb2da1 JS |
1528 | /* Should we change the Reference Tag */ |
1529 | if (reftag) { | |
acd6859b JS |
1530 | if (phba->lpfc_injerr_wref_cnt) { |
1531 | switch (op) { | |
1532 | case SCSI_PROT_WRITE_PASS: | |
9a6b09c0 JS |
1533 | if (src) { |
1534 | /* | |
1535 | * For WRITE_PASS, force the error | |
1536 | * to be sent on the wire. It should | |
1537 | * be detected by the Target. | |
1538 | * If blockoff != 0 error will be | |
1539 | * inserted in middle of the IO. | |
1540 | */ | |
acd6859b JS |
1541 | |
1542 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
1543 | "9076 BLKGRD: Injecting reftag error: " | |
1544 | "write lba x%lx + x%x oldrefTag x%x\n", | |
1545 | (unsigned long)lba, blockoff, | |
9a6b09c0 | 1546 | be32_to_cpu(src->ref_tag)); |
f9bb2da1 | 1547 | |
acd6859b | 1548 | /* |
9a6b09c0 JS |
1549 | * Save the old ref_tag so we can |
1550 | * restore it on completion. | |
acd6859b | 1551 | */ |
9a6b09c0 JS |
1552 | if (lpfc_cmd) { |
1553 | lpfc_cmd->prot_data_type = | |
1554 | LPFC_INJERR_REFTAG; | |
1555 | lpfc_cmd->prot_data_segment = | |
1556 | src; | |
1557 | lpfc_cmd->prot_data = | |
1558 | src->ref_tag; | |
1559 | } | |
1560 | src->ref_tag = cpu_to_be32(0xDEADBEEF); | |
acd6859b | 1561 | phba->lpfc_injerr_wref_cnt--; |
4ac9b226 JS |
1562 | if (phba->lpfc_injerr_wref_cnt == 0) { |
1563 | phba->lpfc_injerr_nportid = 0; | |
1564 | phba->lpfc_injerr_lba = | |
1565 | LPFC_INJERR_LBA_OFF; | |
1566 | memset(&phba->lpfc_injerr_wwpn, | |
1567 | 0, sizeof(struct lpfc_name)); | |
1568 | } | |
9a6b09c0 JS |
1569 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
1570 | ||
acd6859b JS |
1571 | break; |
1572 | } | |
1573 | /* Drop thru */ | |
9a6b09c0 | 1574 | case SCSI_PROT_WRITE_INSERT: |
acd6859b | 1575 | /* |
9a6b09c0 JS |
1576 | * For WRITE_INSERT, force the error |
1577 | * to be sent on the wire. It should be | |
1578 | * detected by the Target. | |
acd6859b | 1579 | */ |
9a6b09c0 | 1580 | /* DEADBEEF will be the reftag on the wire */ |
acd6859b JS |
1581 | *reftag = 0xDEADBEEF; |
1582 | phba->lpfc_injerr_wref_cnt--; | |
4ac9b226 JS |
1583 | if (phba->lpfc_injerr_wref_cnt == 0) { |
1584 | phba->lpfc_injerr_nportid = 0; | |
1585 | phba->lpfc_injerr_lba = | |
1586 | LPFC_INJERR_LBA_OFF; | |
1587 | memset(&phba->lpfc_injerr_wwpn, | |
1588 | 0, sizeof(struct lpfc_name)); | |
1589 | } | |
9a6b09c0 | 1590 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
acd6859b JS |
1591 | |
1592 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
9a6b09c0 | 1593 | "9078 BLKGRD: Injecting reftag error: " |
acd6859b JS |
1594 | "write lba x%lx\n", (unsigned long)lba); |
1595 | break; | |
9a6b09c0 | 1596 | case SCSI_PROT_WRITE_STRIP: |
acd6859b | 1597 | /* |
9a6b09c0 JS |
1598 | * For WRITE_STRIP and WRITE_PASS, |
1599 | * force the error on data | |
1600 | * being copied from SLI-Host to SLI-Port. | |
acd6859b | 1601 | */ |
f9bb2da1 JS |
1602 | *reftag = 0xDEADBEEF; |
1603 | phba->lpfc_injerr_wref_cnt--; | |
4ac9b226 JS |
1604 | if (phba->lpfc_injerr_wref_cnt == 0) { |
1605 | phba->lpfc_injerr_nportid = 0; | |
1606 | phba->lpfc_injerr_lba = | |
1607 | LPFC_INJERR_LBA_OFF; | |
1608 | memset(&phba->lpfc_injerr_wwpn, | |
1609 | 0, sizeof(struct lpfc_name)); | |
1610 | } | |
9a6b09c0 | 1611 | rc = BG_ERR_INIT; |
f9bb2da1 JS |
1612 | |
1613 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
9a6b09c0 | 1614 | "9077 BLKGRD: Injecting reftag error: " |
f9bb2da1 | 1615 | "write lba x%lx\n", (unsigned long)lba); |
acd6859b | 1616 | break; |
f9bb2da1 | 1617 | } |
acd6859b JS |
1618 | } |
1619 | if (phba->lpfc_injerr_rref_cnt) { | |
1620 | switch (op) { | |
1621 | case SCSI_PROT_READ_INSERT: | |
acd6859b JS |
1622 | case SCSI_PROT_READ_STRIP: |
1623 | case SCSI_PROT_READ_PASS: | |
1624 | /* | |
1625 | * For READ_STRIP and READ_PASS, force the | |
1626 | * error on data being read off the wire. It | |
1627 | * should force an IO error to the driver. | |
1628 | */ | |
f9bb2da1 JS |
1629 | *reftag = 0xDEADBEEF; |
1630 | phba->lpfc_injerr_rref_cnt--; | |
4ac9b226 JS |
1631 | if (phba->lpfc_injerr_rref_cnt == 0) { |
1632 | phba->lpfc_injerr_nportid = 0; | |
1633 | phba->lpfc_injerr_lba = | |
1634 | LPFC_INJERR_LBA_OFF; | |
1635 | memset(&phba->lpfc_injerr_wwpn, | |
1636 | 0, sizeof(struct lpfc_name)); | |
1637 | } | |
acd6859b | 1638 | rc = BG_ERR_INIT; |
f9bb2da1 JS |
1639 | |
1640 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
acd6859b | 1641 | "9079 BLKGRD: Injecting reftag error: " |
f9bb2da1 | 1642 | "read lba x%lx\n", (unsigned long)lba); |
acd6859b | 1643 | break; |
f9bb2da1 JS |
1644 | } |
1645 | } | |
1646 | } | |
1647 | ||
1648 | /* Should we change the Application Tag */ | |
1649 | if (apptag) { | |
acd6859b JS |
1650 | if (phba->lpfc_injerr_wapp_cnt) { |
1651 | switch (op) { | |
1652 | case SCSI_PROT_WRITE_PASS: | |
4ac9b226 | 1653 | if (src) { |
9a6b09c0 JS |
1654 | /* |
1655 | * For WRITE_PASS, force the error | |
1656 | * to be sent on the wire. It should | |
1657 | * be detected by the Target. | |
1658 | * If blockoff != 0 error will be | |
1659 | * inserted in middle of the IO. | |
1660 | */ | |
1661 | ||
acd6859b JS |
1662 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
1663 | "9080 BLKGRD: Injecting apptag error: " | |
1664 | "write lba x%lx + x%x oldappTag x%x\n", | |
1665 | (unsigned long)lba, blockoff, | |
9a6b09c0 | 1666 | be16_to_cpu(src->app_tag)); |
acd6859b JS |
1667 | |
1668 | /* | |
9a6b09c0 JS |
1669 | * Save the old app_tag so we can |
1670 | * restore it on completion. | |
acd6859b | 1671 | */ |
9a6b09c0 JS |
1672 | if (lpfc_cmd) { |
1673 | lpfc_cmd->prot_data_type = | |
1674 | LPFC_INJERR_APPTAG; | |
1675 | lpfc_cmd->prot_data_segment = | |
1676 | src; | |
1677 | lpfc_cmd->prot_data = | |
1678 | src->app_tag; | |
1679 | } | |
1680 | src->app_tag = cpu_to_be16(0xDEAD); | |
acd6859b | 1681 | phba->lpfc_injerr_wapp_cnt--; |
4ac9b226 JS |
1682 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
1683 | phba->lpfc_injerr_nportid = 0; | |
1684 | phba->lpfc_injerr_lba = | |
1685 | LPFC_INJERR_LBA_OFF; | |
1686 | memset(&phba->lpfc_injerr_wwpn, | |
1687 | 0, sizeof(struct lpfc_name)); | |
1688 | } | |
9a6b09c0 | 1689 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
acd6859b JS |
1690 | break; |
1691 | } | |
1692 | /* Drop thru */ | |
9a6b09c0 | 1693 | case SCSI_PROT_WRITE_INSERT: |
acd6859b | 1694 | /* |
9a6b09c0 JS |
1695 | * For WRITE_INSERT, force the |
1696 | * error to be sent on the wire. It should be | |
1697 | * detected by the Target. | |
acd6859b | 1698 | */ |
9a6b09c0 | 1699 | /* DEAD will be the apptag on the wire */ |
acd6859b JS |
1700 | *apptag = 0xDEAD; |
1701 | phba->lpfc_injerr_wapp_cnt--; | |
4ac9b226 JS |
1702 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
1703 | phba->lpfc_injerr_nportid = 0; | |
1704 | phba->lpfc_injerr_lba = | |
1705 | LPFC_INJERR_LBA_OFF; | |
1706 | memset(&phba->lpfc_injerr_wwpn, | |
1707 | 0, sizeof(struct lpfc_name)); | |
1708 | } | |
9a6b09c0 | 1709 | rc = BG_ERR_TGT | BG_ERR_CHECK; |
f9bb2da1 | 1710 | |
acd6859b | 1711 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
9a6b09c0 | 1712 | "0813 BLKGRD: Injecting apptag error: " |
acd6859b JS |
1713 | "write lba x%lx\n", (unsigned long)lba); |
1714 | break; | |
9a6b09c0 | 1715 | case SCSI_PROT_WRITE_STRIP: |
acd6859b | 1716 | /* |
9a6b09c0 JS |
1717 | * For WRITE_STRIP and WRITE_PASS, |
1718 | * force the error on data | |
1719 | * being copied from SLI-Host to SLI-Port. | |
acd6859b | 1720 | */ |
f9bb2da1 JS |
1721 | *apptag = 0xDEAD; |
1722 | phba->lpfc_injerr_wapp_cnt--; | |
4ac9b226 JS |
1723 | if (phba->lpfc_injerr_wapp_cnt == 0) { |
1724 | phba->lpfc_injerr_nportid = 0; | |
1725 | phba->lpfc_injerr_lba = | |
1726 | LPFC_INJERR_LBA_OFF; | |
1727 | memset(&phba->lpfc_injerr_wwpn, | |
1728 | 0, sizeof(struct lpfc_name)); | |
1729 | } | |
9a6b09c0 | 1730 | rc = BG_ERR_INIT; |
f9bb2da1 JS |
1731 | |
1732 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
9a6b09c0 | 1733 | "0812 BLKGRD: Injecting apptag error: " |
f9bb2da1 | 1734 | "write lba x%lx\n", (unsigned long)lba); |
acd6859b | 1735 | break; |
f9bb2da1 | 1736 | } |
acd6859b JS |
1737 | } |
1738 | if (phba->lpfc_injerr_rapp_cnt) { | |
1739 | switch (op) { | |
1740 | case SCSI_PROT_READ_INSERT: | |
acd6859b JS |
1741 | case SCSI_PROT_READ_STRIP: |
1742 | case SCSI_PROT_READ_PASS: | |
1743 | /* | |
1744 | * For READ_STRIP and READ_PASS, force the | |
1745 | * error on data being read off the wire. It | |
1746 | * should force an IO error to the driver. | |
1747 | */ | |
f9bb2da1 JS |
1748 | *apptag = 0xDEAD; |
1749 | phba->lpfc_injerr_rapp_cnt--; | |
4ac9b226 JS |
1750 | if (phba->lpfc_injerr_rapp_cnt == 0) { |
1751 | phba->lpfc_injerr_nportid = 0; | |
1752 | phba->lpfc_injerr_lba = | |
1753 | LPFC_INJERR_LBA_OFF; | |
1754 | memset(&phba->lpfc_injerr_wwpn, | |
1755 | 0, sizeof(struct lpfc_name)); | |
1756 | } | |
acd6859b | 1757 | rc = BG_ERR_INIT; |
f9bb2da1 JS |
1758 | |
1759 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
acd6859b | 1760 | "0814 BLKGRD: Injecting apptag error: " |
f9bb2da1 | 1761 | "read lba x%lx\n", (unsigned long)lba); |
acd6859b | 1762 | break; |
f9bb2da1 JS |
1763 | } |
1764 | } | |
1765 | } | |
1766 | ||
acd6859b | 1767 | |
f9bb2da1 | 1768 | /* Should we change the Guard Tag */ |
acd6859b JS |
1769 | if (new_guard) { |
1770 | if (phba->lpfc_injerr_wgrd_cnt) { | |
1771 | switch (op) { | |
1772 | case SCSI_PROT_WRITE_PASS: | |
9a6b09c0 | 1773 | rc = BG_ERR_CHECK; |
acd6859b | 1774 | /* Drop thru */ |
9a6b09c0 JS |
1775 | |
1776 | case SCSI_PROT_WRITE_INSERT: | |
acd6859b | 1777 | /* |
9a6b09c0 JS |
1778 | * For WRITE_INSERT, force the |
1779 | * error to be sent on the wire. It should be | |
1780 | * detected by the Target. | |
acd6859b JS |
1781 | */ |
1782 | phba->lpfc_injerr_wgrd_cnt--; | |
4ac9b226 JS |
1783 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
1784 | phba->lpfc_injerr_nportid = 0; | |
1785 | phba->lpfc_injerr_lba = | |
1786 | LPFC_INJERR_LBA_OFF; | |
1787 | memset(&phba->lpfc_injerr_wwpn, | |
1788 | 0, sizeof(struct lpfc_name)); | |
1789 | } | |
f9bb2da1 | 1790 | |
9a6b09c0 | 1791 | rc |= BG_ERR_TGT | BG_ERR_SWAP; |
acd6859b | 1792 | /* Signals the caller to swap CRC->CSUM */ |
f9bb2da1 | 1793 | |
acd6859b | 1794 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
9a6b09c0 | 1795 | "0817 BLKGRD: Injecting guard error: " |
acd6859b JS |
1796 | "write lba x%lx\n", (unsigned long)lba); |
1797 | break; | |
9a6b09c0 | 1798 | case SCSI_PROT_WRITE_STRIP: |
acd6859b | 1799 | /* |
9a6b09c0 JS |
1800 | * For WRITE_STRIP and WRITE_PASS, |
1801 | * force the error on data | |
1802 | * being copied from SLI-Host to SLI-Port. | |
acd6859b JS |
1803 | */ |
1804 | phba->lpfc_injerr_wgrd_cnt--; | |
4ac9b226 JS |
1805 | if (phba->lpfc_injerr_wgrd_cnt == 0) { |
1806 | phba->lpfc_injerr_nportid = 0; | |
1807 | phba->lpfc_injerr_lba = | |
1808 | LPFC_INJERR_LBA_OFF; | |
1809 | memset(&phba->lpfc_injerr_wwpn, | |
1810 | 0, sizeof(struct lpfc_name)); | |
1811 | } | |
f9bb2da1 | 1812 | |
9a6b09c0 | 1813 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
acd6859b JS |
1814 | /* Signals the caller to swap CRC->CSUM */ |
1815 | ||
1816 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
9a6b09c0 | 1817 | "0816 BLKGRD: Injecting guard error: " |
acd6859b JS |
1818 | "write lba x%lx\n", (unsigned long)lba); |
1819 | break; | |
1820 | } | |
1821 | } | |
1822 | if (phba->lpfc_injerr_rgrd_cnt) { | |
1823 | switch (op) { | |
1824 | case SCSI_PROT_READ_INSERT: | |
acd6859b JS |
1825 | case SCSI_PROT_READ_STRIP: |
1826 | case SCSI_PROT_READ_PASS: | |
1827 | /* | |
1828 | * For READ_STRIP and READ_PASS, force the | |
1829 | * error on data being read off the wire. It | |
1830 | * should force an IO error to the driver. | |
1831 | */ | |
acd6859b | 1832 | phba->lpfc_injerr_rgrd_cnt--; |
4ac9b226 JS |
1833 | if (phba->lpfc_injerr_rgrd_cnt == 0) { |
1834 | phba->lpfc_injerr_nportid = 0; | |
1835 | phba->lpfc_injerr_lba = | |
1836 | LPFC_INJERR_LBA_OFF; | |
1837 | memset(&phba->lpfc_injerr_wwpn, | |
1838 | 0, sizeof(struct lpfc_name)); | |
1839 | } | |
acd6859b | 1840 | |
9a6b09c0 | 1841 | rc = BG_ERR_INIT | BG_ERR_SWAP; |
acd6859b JS |
1842 | /* Signals the caller to swap CRC->CSUM */ |
1843 | ||
1844 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
1845 | "0818 BLKGRD: Injecting guard error: " | |
1846 | "read lba x%lx\n", (unsigned long)lba); | |
1847 | } | |
f9bb2da1 JS |
1848 | } |
1849 | } | |
acd6859b | 1850 | |
f9bb2da1 JS |
1851 | return rc; |
1852 | } | |
1853 | #endif | |
1854 | ||
acd6859b JS |
1855 | /** |
1856 | * lpfc_sc_to_bg_opcodes - Determine the BlockGuard opcodes to be used with | |
1857 | * the specified SCSI command. | |
1858 | * @phba: The Hba for which this call is being executed. | |
6c8eea54 JS |
1859 | * @sc: The SCSI command to examine |
1860 | * @txopt: (out) BlockGuard operation for transmitted data | |
1861 | * @rxopt: (out) BlockGuard operation for received data | |
1862 | * | |
1863 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined | |
1864 | * | |
acd6859b | 1865 | **/ |
e2a0a9d6 | 1866 | static int |
6c8eea54 JS |
1867 | lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, |
1868 | uint8_t *txop, uint8_t *rxop) | |
e2a0a9d6 | 1869 | { |
6c8eea54 | 1870 | uint8_t ret = 0; |
e2a0a9d6 | 1871 | |
9c6aa9d7 | 1872 | if (lpfc_cmd_guard_csum(sc)) { |
e2a0a9d6 JS |
1873 | switch (scsi_get_prot_op(sc)) { |
1874 | case SCSI_PROT_READ_INSERT: | |
1875 | case SCSI_PROT_WRITE_STRIP: | |
6c8eea54 | 1876 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
4ac9b226 | 1877 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
e2a0a9d6 JS |
1878 | break; |
1879 | ||
1880 | case SCSI_PROT_READ_STRIP: | |
1881 | case SCSI_PROT_WRITE_INSERT: | |
6c8eea54 | 1882 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
4ac9b226 | 1883 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
e2a0a9d6 JS |
1884 | break; |
1885 | ||
c6af4042 MP |
1886 | case SCSI_PROT_READ_PASS: |
1887 | case SCSI_PROT_WRITE_PASS: | |
6c8eea54 | 1888 | *rxop = BG_OP_IN_CRC_OUT_CSUM; |
4ac9b226 | 1889 | *txop = BG_OP_IN_CSUM_OUT_CRC; |
e2a0a9d6 JS |
1890 | break; |
1891 | ||
e2a0a9d6 JS |
1892 | case SCSI_PROT_NORMAL: |
1893 | default: | |
6a9c52cf | 1894 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
7c56b9fd JS |
1895 | "9063 BLKGRD: Bad op/guard:%d/IP combination\n", |
1896 | scsi_get_prot_op(sc)); | |
6c8eea54 | 1897 | ret = 1; |
e2a0a9d6 JS |
1898 | break; |
1899 | ||
1900 | } | |
7c56b9fd | 1901 | } else { |
e2a0a9d6 JS |
1902 | switch (scsi_get_prot_op(sc)) { |
1903 | case SCSI_PROT_READ_STRIP: | |
1904 | case SCSI_PROT_WRITE_INSERT: | |
6c8eea54 | 1905 | *rxop = BG_OP_IN_CRC_OUT_NODIF; |
4ac9b226 | 1906 | *txop = BG_OP_IN_NODIF_OUT_CRC; |
e2a0a9d6 JS |
1907 | break; |
1908 | ||
1909 | case SCSI_PROT_READ_PASS: | |
1910 | case SCSI_PROT_WRITE_PASS: | |
6c8eea54 | 1911 | *rxop = BG_OP_IN_CRC_OUT_CRC; |
4ac9b226 | 1912 | *txop = BG_OP_IN_CRC_OUT_CRC; |
e2a0a9d6 JS |
1913 | break; |
1914 | ||
e2a0a9d6 JS |
1915 | case SCSI_PROT_READ_INSERT: |
1916 | case SCSI_PROT_WRITE_STRIP: | |
7c56b9fd | 1917 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
4ac9b226 | 1918 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
7c56b9fd JS |
1919 | break; |
1920 | ||
e2a0a9d6 JS |
1921 | case SCSI_PROT_NORMAL: |
1922 | default: | |
6a9c52cf | 1923 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
7c56b9fd JS |
1924 | "9075 BLKGRD: Bad op/guard:%d/CRC combination\n", |
1925 | scsi_get_prot_op(sc)); | |
6c8eea54 | 1926 | ret = 1; |
e2a0a9d6 JS |
1927 | break; |
1928 | } | |
e2a0a9d6 JS |
1929 | } |
1930 | ||
6c8eea54 | 1931 | return ret; |
e2a0a9d6 JS |
1932 | } |
1933 | ||
acd6859b JS |
1934 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
1935 | /** | |
1936 | * lpfc_bg_err_opcodes - reDetermine the BlockGuard opcodes to be used with | |
1937 | * the specified SCSI command in order to force a guard tag error. | |
1938 | * @phba: The Hba for which this call is being executed. | |
1939 | * @sc: The SCSI command to examine | |
1940 | * @txopt: (out) BlockGuard operation for transmitted data | |
1941 | * @rxopt: (out) BlockGuard operation for received data | |
1942 | * | |
1943 | * Returns: zero on success; non-zero if tx and/or rx op cannot be determined | |
1944 | * | |
1945 | **/ | |
1946 | static int | |
1947 | lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
1948 | uint8_t *txop, uint8_t *rxop) | |
1949 | { | |
acd6859b JS |
1950 | uint8_t ret = 0; |
1951 | ||
9c6aa9d7 | 1952 | if (lpfc_cmd_guard_csum(sc)) { |
acd6859b JS |
1953 | switch (scsi_get_prot_op(sc)) { |
1954 | case SCSI_PROT_READ_INSERT: | |
1955 | case SCSI_PROT_WRITE_STRIP: | |
acd6859b | 1956 | *rxop = BG_OP_IN_NODIF_OUT_CRC; |
4ac9b226 | 1957 | *txop = BG_OP_IN_CRC_OUT_NODIF; |
acd6859b JS |
1958 | break; |
1959 | ||
1960 | case SCSI_PROT_READ_STRIP: | |
1961 | case SCSI_PROT_WRITE_INSERT: | |
acd6859b | 1962 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
4ac9b226 | 1963 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
acd6859b JS |
1964 | break; |
1965 | ||
1966 | case SCSI_PROT_READ_PASS: | |
1967 | case SCSI_PROT_WRITE_PASS: | |
4ac9b226 | 1968 | *rxop = BG_OP_IN_CSUM_OUT_CRC; |
9a6b09c0 | 1969 | *txop = BG_OP_IN_CRC_OUT_CSUM; |
acd6859b JS |
1970 | break; |
1971 | ||
1972 | case SCSI_PROT_NORMAL: | |
1973 | default: | |
1974 | break; | |
1975 | ||
1976 | } | |
1977 | } else { | |
1978 | switch (scsi_get_prot_op(sc)) { | |
1979 | case SCSI_PROT_READ_STRIP: | |
1980 | case SCSI_PROT_WRITE_INSERT: | |
acd6859b | 1981 | *rxop = BG_OP_IN_CSUM_OUT_NODIF; |
4ac9b226 | 1982 | *txop = BG_OP_IN_NODIF_OUT_CSUM; |
acd6859b JS |
1983 | break; |
1984 | ||
1985 | case SCSI_PROT_READ_PASS: | |
1986 | case SCSI_PROT_WRITE_PASS: | |
4ac9b226 | 1987 | *rxop = BG_OP_IN_CSUM_OUT_CSUM; |
9a6b09c0 | 1988 | *txop = BG_OP_IN_CSUM_OUT_CSUM; |
acd6859b JS |
1989 | break; |
1990 | ||
1991 | case SCSI_PROT_READ_INSERT: | |
1992 | case SCSI_PROT_WRITE_STRIP: | |
acd6859b | 1993 | *rxop = BG_OP_IN_NODIF_OUT_CSUM; |
4ac9b226 | 1994 | *txop = BG_OP_IN_CSUM_OUT_NODIF; |
acd6859b JS |
1995 | break; |
1996 | ||
1997 | case SCSI_PROT_NORMAL: | |
1998 | default: | |
1999 | break; | |
2000 | } | |
2001 | } | |
2002 | ||
2003 | return ret; | |
2004 | } | |
2005 | #endif | |
2006 | ||
2007 | /** | |
2008 | * lpfc_bg_setup_bpl - Setup BlockGuard BPL with no protection data | |
2009 | * @phba: The Hba for which this call is being executed. | |
2010 | * @sc: pointer to scsi command we're working on | |
2011 | * @bpl: pointer to buffer list for protection groups | |
2012 | * @datacnt: number of segments of data that have been dma mapped | |
2013 | * | |
2014 | * This function sets up BPL buffer list for protection groups of | |
e2a0a9d6 JS |
2015 | * type LPFC_PG_TYPE_NO_DIF |
2016 | * | |
2017 | * This is usually used when the HBA is instructed to generate | |
2018 | * DIFs and insert them into data stream (or strip DIF from | |
2019 | * incoming data stream) | |
2020 | * | |
2021 | * The buffer list consists of just one protection group described | |
2022 | * below: | |
2023 | * +-------------------------+ | |
6c8eea54 JS |
2024 | * start of prot group --> | PDE_5 | |
2025 | * +-------------------------+ | |
2026 | * | PDE_6 | | |
e2a0a9d6 JS |
2027 | * +-------------------------+ |
2028 | * | Data BDE | | |
2029 | * +-------------------------+ | |
2030 | * |more Data BDE's ... (opt)| | |
2031 | * +-------------------------+ | |
2032 | * | |
e2a0a9d6 JS |
2033 | * |
2034 | * Note: Data s/g buffers have been dma mapped | |
acd6859b JS |
2035 | * |
2036 | * Returns the number of BDEs added to the BPL. | |
2037 | **/ | |
e2a0a9d6 JS |
2038 | static int |
2039 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
2040 | struct ulp_bde64 *bpl, int datasegcnt) | |
2041 | { | |
2042 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
6c8eea54 JS |
2043 | struct lpfc_pde5 *pde5 = NULL; |
2044 | struct lpfc_pde6 *pde6 = NULL; | |
e2a0a9d6 | 2045 | dma_addr_t physaddr; |
6c8eea54 | 2046 | int i = 0, num_bde = 0, status; |
e2a0a9d6 | 2047 | int datadir = sc->sc_data_direction; |
0829a19a | 2048 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
acd6859b | 2049 | uint32_t rc; |
0829a19a | 2050 | #endif |
acd6859b | 2051 | uint32_t checking = 1; |
e2a0a9d6 | 2052 | uint32_t reftag; |
7c56b9fd | 2053 | unsigned blksize; |
6c8eea54 | 2054 | uint8_t txop, rxop; |
e2a0a9d6 | 2055 | |
6c8eea54 JS |
2056 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
2057 | if (status) | |
e2a0a9d6 JS |
2058 | goto out; |
2059 | ||
6c8eea54 | 2060 | /* extract some info from the scsi command for pde*/ |
e2a0a9d6 | 2061 | blksize = lpfc_cmd_blksize(sc); |
acd6859b | 2062 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
e2a0a9d6 | 2063 | |
f9bb2da1 | 2064 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
4ac9b226 | 2065 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
acd6859b | 2066 | if (rc) { |
9a6b09c0 | 2067 | if (rc & BG_ERR_SWAP) |
acd6859b | 2068 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
9a6b09c0 | 2069 | if (rc & BG_ERR_CHECK) |
acd6859b JS |
2070 | checking = 0; |
2071 | } | |
f9bb2da1 JS |
2072 | #endif |
2073 | ||
6c8eea54 JS |
2074 | /* setup PDE5 with what we have */ |
2075 | pde5 = (struct lpfc_pde5 *) bpl; | |
2076 | memset(pde5, 0, sizeof(struct lpfc_pde5)); | |
2077 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); | |
6c8eea54 | 2078 | |
bc73905a | 2079 | /* Endianness conversion if necessary for PDE5 */ |
589a52d6 | 2080 | pde5->word0 = cpu_to_le32(pde5->word0); |
7c56b9fd | 2081 | pde5->reftag = cpu_to_le32(reftag); |
589a52d6 | 2082 | |
6c8eea54 JS |
2083 | /* advance bpl and increment bde count */ |
2084 | num_bde++; | |
2085 | bpl++; | |
2086 | pde6 = (struct lpfc_pde6 *) bpl; | |
2087 | ||
2088 | /* setup PDE6 with the rest of the info */ | |
2089 | memset(pde6, 0, sizeof(struct lpfc_pde6)); | |
2090 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); | |
2091 | bf_set(pde6_optx, pde6, txop); | |
2092 | bf_set(pde6_oprx, pde6, rxop); | |
a6887e28 JS |
2093 | |
2094 | /* | |
2095 | * We only need to check the data on READs, for WRITEs | |
2096 | * protection data is automatically generated, not checked. | |
2097 | */ | |
6c8eea54 | 2098 | if (datadir == DMA_FROM_DEVICE) { |
9c6aa9d7 | 2099 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
a6887e28 JS |
2100 | bf_set(pde6_ce, pde6, checking); |
2101 | else | |
2102 | bf_set(pde6_ce, pde6, 0); | |
2103 | ||
9c6aa9d7 | 2104 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
a6887e28 JS |
2105 | bf_set(pde6_re, pde6, checking); |
2106 | else | |
2107 | bf_set(pde6_re, pde6, 0); | |
6c8eea54 JS |
2108 | } |
2109 | bf_set(pde6_ai, pde6, 1); | |
7c56b9fd JS |
2110 | bf_set(pde6_ae, pde6, 0); |
2111 | bf_set(pde6_apptagval, pde6, 0); | |
e2a0a9d6 | 2112 | |
bc73905a | 2113 | /* Endianness conversion if necessary for PDE6 */ |
589a52d6 JS |
2114 | pde6->word0 = cpu_to_le32(pde6->word0); |
2115 | pde6->word1 = cpu_to_le32(pde6->word1); | |
2116 | pde6->word2 = cpu_to_le32(pde6->word2); | |
2117 | ||
6c8eea54 | 2118 | /* advance bpl and increment bde count */ |
e2a0a9d6 JS |
2119 | num_bde++; |
2120 | bpl++; | |
2121 | ||
2122 | /* assumption: caller has already run dma_map_sg on command data */ | |
2123 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { | |
2124 | physaddr = sg_dma_address(sgde); | |
2125 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
2126 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); | |
2127 | bpl->tus.f.bdeSize = sg_dma_len(sgde); | |
2128 | if (datadir == DMA_TO_DEVICE) | |
2129 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
2130 | else | |
2131 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
2132 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
2133 | bpl++; | |
2134 | num_bde++; | |
2135 | } | |
2136 | ||
2137 | out: | |
2138 | return num_bde; | |
2139 | } | |
2140 | ||
acd6859b JS |
2141 | /** |
2142 | * lpfc_bg_setup_bpl_prot - Setup BlockGuard BPL with protection data | |
2143 | * @phba: The Hba for which this call is being executed. | |
2144 | * @sc: pointer to scsi command we're working on | |
2145 | * @bpl: pointer to buffer list for protection groups | |
2146 | * @datacnt: number of segments of data that have been dma mapped | |
2147 | * @protcnt: number of segment of protection data that have been dma mapped | |
2148 | * | |
2149 | * This function sets up BPL buffer list for protection groups of | |
2150 | * type LPFC_PG_TYPE_DIF | |
e2a0a9d6 JS |
2151 | * |
2152 | * This is usually used when DIFs are in their own buffers, | |
2153 | * separate from the data. The HBA can then by instructed | |
2154 | * to place the DIFs in the outgoing stream. For read operations, | |
2155 | * The HBA could extract the DIFs and place it in DIF buffers. | |
2156 | * | |
2157 | * The buffer list for this type consists of one or more of the | |
2158 | * protection groups described below: | |
2159 | * +-------------------------+ | |
6c8eea54 | 2160 | * start of first prot group --> | PDE_5 | |
e2a0a9d6 | 2161 | * +-------------------------+ |
6c8eea54 JS |
2162 | * | PDE_6 | |
2163 | * +-------------------------+ | |
2164 | * | PDE_7 (Prot BDE) | | |
e2a0a9d6 JS |
2165 | * +-------------------------+ |
2166 | * | Data BDE | | |
2167 | * +-------------------------+ | |
2168 | * |more Data BDE's ... (opt)| | |
2169 | * +-------------------------+ | |
6c8eea54 | 2170 | * start of new prot group --> | PDE_5 | |
e2a0a9d6 JS |
2171 | * +-------------------------+ |
2172 | * | ... | | |
2173 | * +-------------------------+ | |
2174 | * | |
e2a0a9d6 JS |
2175 | * Note: It is assumed that both data and protection s/g buffers have been |
2176 | * mapped for DMA | |
acd6859b JS |
2177 | * |
2178 | * Returns the number of BDEs added to the BPL. | |
2179 | **/ | |
e2a0a9d6 JS |
2180 | static int |
2181 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
2182 | struct ulp_bde64 *bpl, int datacnt, int protcnt) | |
2183 | { | |
2184 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
2185 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ | |
6c8eea54 JS |
2186 | struct lpfc_pde5 *pde5 = NULL; |
2187 | struct lpfc_pde6 *pde6 = NULL; | |
7f86059a | 2188 | struct lpfc_pde7 *pde7 = NULL; |
e2a0a9d6 JS |
2189 | dma_addr_t dataphysaddr, protphysaddr; |
2190 | unsigned short curr_data = 0, curr_prot = 0; | |
7f86059a JS |
2191 | unsigned int split_offset; |
2192 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; | |
e2a0a9d6 JS |
2193 | unsigned int protgrp_blks, protgrp_bytes; |
2194 | unsigned int remainder, subtotal; | |
6c8eea54 | 2195 | int status; |
e2a0a9d6 JS |
2196 | int datadir = sc->sc_data_direction; |
2197 | unsigned char pgdone = 0, alldone = 0; | |
2198 | unsigned blksize; | |
0829a19a | 2199 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
acd6859b | 2200 | uint32_t rc; |
0829a19a | 2201 | #endif |
acd6859b | 2202 | uint32_t checking = 1; |
e2a0a9d6 | 2203 | uint32_t reftag; |
6c8eea54 | 2204 | uint8_t txop, rxop; |
e2a0a9d6 JS |
2205 | int num_bde = 0; |
2206 | ||
2207 | sgpe = scsi_prot_sglist(sc); | |
2208 | sgde = scsi_sglist(sc); | |
2209 | ||
2210 | if (!sgpe || !sgde) { | |
2211 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
acd6859b JS |
2212 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", |
2213 | sgpe, sgde); | |
2214 | return 0; | |
2215 | } | |
2216 | ||
2217 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); | |
2218 | if (status) | |
2219 | goto out; | |
2220 | ||
2221 | /* extract some info from the scsi command */ | |
2222 | blksize = lpfc_cmd_blksize(sc); | |
2223 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ | |
2224 | ||
2225 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS | |
4ac9b226 | 2226 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
acd6859b | 2227 | if (rc) { |
9a6b09c0 | 2228 | if (rc & BG_ERR_SWAP) |
acd6859b | 2229 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
9a6b09c0 | 2230 | if (rc & BG_ERR_CHECK) |
acd6859b JS |
2231 | checking = 0; |
2232 | } | |
2233 | #endif | |
2234 | ||
2235 | split_offset = 0; | |
2236 | do { | |
96f7077f JS |
2237 | /* Check to see if we ran out of space */ |
2238 | if (num_bde >= (phba->cfg_total_seg_cnt - 2)) | |
2239 | return num_bde + 3; | |
2240 | ||
acd6859b JS |
2241 | /* setup PDE5 with what we have */ |
2242 | pde5 = (struct lpfc_pde5 *) bpl; | |
2243 | memset(pde5, 0, sizeof(struct lpfc_pde5)); | |
2244 | bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); | |
2245 | ||
2246 | /* Endianness conversion if necessary for PDE5 */ | |
2247 | pde5->word0 = cpu_to_le32(pde5->word0); | |
2248 | pde5->reftag = cpu_to_le32(reftag); | |
2249 | ||
2250 | /* advance bpl and increment bde count */ | |
2251 | num_bde++; | |
2252 | bpl++; | |
2253 | pde6 = (struct lpfc_pde6 *) bpl; | |
2254 | ||
2255 | /* setup PDE6 with the rest of the info */ | |
2256 | memset(pde6, 0, sizeof(struct lpfc_pde6)); | |
2257 | bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR); | |
2258 | bf_set(pde6_optx, pde6, txop); | |
2259 | bf_set(pde6_oprx, pde6, rxop); | |
a6887e28 | 2260 | |
9c6aa9d7 | 2261 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
a6887e28 JS |
2262 | bf_set(pde6_ce, pde6, checking); |
2263 | else | |
2264 | bf_set(pde6_ce, pde6, 0); | |
2265 | ||
9c6aa9d7 | 2266 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
a6887e28 JS |
2267 | bf_set(pde6_re, pde6, checking); |
2268 | else | |
2269 | bf_set(pde6_re, pde6, 0); | |
2270 | ||
acd6859b JS |
2271 | bf_set(pde6_ai, pde6, 1); |
2272 | bf_set(pde6_ae, pde6, 0); | |
2273 | bf_set(pde6_apptagval, pde6, 0); | |
2274 | ||
2275 | /* Endianness conversion if necessary for PDE6 */ | |
2276 | pde6->word0 = cpu_to_le32(pde6->word0); | |
2277 | pde6->word1 = cpu_to_le32(pde6->word1); | |
2278 | pde6->word2 = cpu_to_le32(pde6->word2); | |
2279 | ||
2280 | /* advance bpl and increment bde count */ | |
2281 | num_bde++; | |
2282 | bpl++; | |
2283 | ||
2284 | /* setup the first BDE that points to protection buffer */ | |
2285 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; | |
2286 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; | |
2287 | ||
2288 | /* must be integer multiple of the DIF block length */ | |
2289 | BUG_ON(protgroup_len % 8); | |
2290 | ||
2291 | pde7 = (struct lpfc_pde7 *) bpl; | |
2292 | memset(pde7, 0, sizeof(struct lpfc_pde7)); | |
2293 | bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR); | |
2294 | ||
2295 | pde7->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); | |
2296 | pde7->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); | |
2297 | ||
2298 | protgrp_blks = protgroup_len / 8; | |
2299 | protgrp_bytes = protgrp_blks * blksize; | |
2300 | ||
2301 | /* check if this pde is crossing the 4K boundary; if so split */ | |
2302 | if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) { | |
2303 | protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff); | |
2304 | protgroup_offset += protgroup_remainder; | |
2305 | protgrp_blks = protgroup_remainder / 8; | |
2306 | protgrp_bytes = protgrp_blks * blksize; | |
2307 | } else { | |
2308 | protgroup_offset = 0; | |
2309 | curr_prot++; | |
2310 | } | |
2311 | ||
2312 | num_bde++; | |
2313 | ||
2314 | /* setup BDE's for data blocks associated with DIF data */ | |
2315 | pgdone = 0; | |
2316 | subtotal = 0; /* total bytes processed for current prot grp */ | |
2317 | while (!pgdone) { | |
96f7077f JS |
2318 | /* Check to see if we ran out of space */ |
2319 | if (num_bde >= phba->cfg_total_seg_cnt) | |
2320 | return num_bde + 1; | |
2321 | ||
acd6859b JS |
2322 | if (!sgde) { |
2323 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
2324 | "9065 BLKGRD:%s Invalid data segment\n", | |
2325 | __func__); | |
2326 | return 0; | |
2327 | } | |
2328 | bpl++; | |
2329 | dataphysaddr = sg_dma_address(sgde) + split_offset; | |
2330 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); | |
2331 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); | |
2332 | ||
2333 | remainder = sg_dma_len(sgde) - split_offset; | |
2334 | ||
2335 | if ((subtotal + remainder) <= protgrp_bytes) { | |
2336 | /* we can use this whole buffer */ | |
2337 | bpl->tus.f.bdeSize = remainder; | |
2338 | split_offset = 0; | |
2339 | ||
2340 | if ((subtotal + remainder) == protgrp_bytes) | |
2341 | pgdone = 1; | |
2342 | } else { | |
2343 | /* must split this buffer with next prot grp */ | |
2344 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; | |
2345 | split_offset += bpl->tus.f.bdeSize; | |
2346 | } | |
2347 | ||
2348 | subtotal += bpl->tus.f.bdeSize; | |
2349 | ||
2350 | if (datadir == DMA_TO_DEVICE) | |
2351 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
2352 | else | |
2353 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
2354 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
2355 | ||
2356 | num_bde++; | |
2357 | curr_data++; | |
2358 | ||
2359 | if (split_offset) | |
2360 | break; | |
2361 | ||
2362 | /* Move to the next s/g segment if possible */ | |
2363 | sgde = sg_next(sgde); | |
2364 | ||
2365 | } | |
2366 | ||
2367 | if (protgroup_offset) { | |
2368 | /* update the reference tag */ | |
2369 | reftag += protgrp_blks; | |
2370 | bpl++; | |
2371 | continue; | |
2372 | } | |
2373 | ||
2374 | /* are we done ? */ | |
2375 | if (curr_prot == protcnt) { | |
2376 | alldone = 1; | |
2377 | } else if (curr_prot < protcnt) { | |
2378 | /* advance to next prot buffer */ | |
2379 | sgpe = sg_next(sgpe); | |
2380 | bpl++; | |
2381 | ||
2382 | /* update the reference tag */ | |
2383 | reftag += protgrp_blks; | |
2384 | } else { | |
2385 | /* if we're here, we have a bug */ | |
2386 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, | |
2387 | "9054 BLKGRD: bug in %s\n", __func__); | |
2388 | } | |
2389 | ||
2390 | } while (!alldone); | |
2391 | out: | |
2392 | ||
2393 | return num_bde; | |
2394 | } | |
2395 | ||
2396 | /** | |
2397 | * lpfc_bg_setup_sgl - Setup BlockGuard SGL with no protection data | |
2398 | * @phba: The Hba for which this call is being executed. | |
2399 | * @sc: pointer to scsi command we're working on | |
2400 | * @sgl: pointer to buffer list for protection groups | |
2401 | * @datacnt: number of segments of data that have been dma mapped | |
2402 | * | |
2403 | * This function sets up SGL buffer list for protection groups of | |
2404 | * type LPFC_PG_TYPE_NO_DIF | |
2405 | * | |
2406 | * This is usually used when the HBA is instructed to generate | |
2407 | * DIFs and insert them into data stream (or strip DIF from | |
2408 | * incoming data stream) | |
2409 | * | |
2410 | * The buffer list consists of just one protection group described | |
2411 | * below: | |
2412 | * +-------------------------+ | |
2413 | * start of prot group --> | DI_SEED | | |
2414 | * +-------------------------+ | |
2415 | * | Data SGE | | |
2416 | * +-------------------------+ | |
2417 | * |more Data SGE's ... (opt)| | |
2418 | * +-------------------------+ | |
2419 | * | |
2420 | * | |
2421 | * Note: Data s/g buffers have been dma mapped | |
2422 | * | |
2423 | * Returns the number of SGEs added to the SGL. | |
2424 | **/ | |
2425 | static int | |
2426 | lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
2427 | struct sli4_sge *sgl, int datasegcnt) | |
2428 | { | |
2429 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
2430 | struct sli4_sge_diseed *diseed = NULL; | |
2431 | dma_addr_t physaddr; | |
2432 | int i = 0, num_sge = 0, status; | |
acd6859b JS |
2433 | uint32_t reftag; |
2434 | unsigned blksize; | |
2435 | uint8_t txop, rxop; | |
0829a19a | 2436 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
acd6859b | 2437 | uint32_t rc; |
0829a19a | 2438 | #endif |
acd6859b JS |
2439 | uint32_t checking = 1; |
2440 | uint32_t dma_len; | |
2441 | uint32_t dma_offset = 0; | |
2442 | ||
2443 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); | |
2444 | if (status) | |
2445 | goto out; | |
2446 | ||
2447 | /* extract some info from the scsi command for pde*/ | |
2448 | blksize = lpfc_cmd_blksize(sc); | |
2449 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ | |
2450 | ||
2451 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS | |
4ac9b226 | 2452 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
acd6859b | 2453 | if (rc) { |
9a6b09c0 | 2454 | if (rc & BG_ERR_SWAP) |
acd6859b | 2455 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
9a6b09c0 | 2456 | if (rc & BG_ERR_CHECK) |
acd6859b JS |
2457 | checking = 0; |
2458 | } | |
2459 | #endif | |
2460 | ||
2461 | /* setup DISEED with what we have */ | |
2462 | diseed = (struct sli4_sge_diseed *) sgl; | |
2463 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); | |
2464 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); | |
2465 | ||
2466 | /* Endianness conversion if necessary */ | |
2467 | diseed->ref_tag = cpu_to_le32(reftag); | |
2468 | diseed->ref_tag_tran = diseed->ref_tag; | |
2469 | ||
a6887e28 JS |
2470 | /* |
2471 | * We only need to check the data on READs, for WRITEs | |
2472 | * protection data is automatically generated, not checked. | |
2473 | */ | |
2474 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { | |
9c6aa9d7 | 2475 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) |
a6887e28 JS |
2476 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
2477 | else | |
2478 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); | |
2479 | ||
9c6aa9d7 | 2480 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
a6887e28 JS |
2481 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
2482 | else | |
2483 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); | |
2484 | } | |
2485 | ||
acd6859b JS |
2486 | /* setup DISEED with the rest of the info */ |
2487 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); | |
2488 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); | |
a6887e28 | 2489 | |
acd6859b JS |
2490 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
2491 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); | |
2492 | ||
2493 | /* Endianness conversion if necessary for DISEED */ | |
2494 | diseed->word2 = cpu_to_le32(diseed->word2); | |
2495 | diseed->word3 = cpu_to_le32(diseed->word3); | |
2496 | ||
2497 | /* advance bpl and increment sge count */ | |
2498 | num_sge++; | |
2499 | sgl++; | |
2500 | ||
2501 | /* assumption: caller has already run dma_map_sg on command data */ | |
2502 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { | |
2503 | physaddr = sg_dma_address(sgde); | |
2504 | dma_len = sg_dma_len(sgde); | |
2505 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); | |
2506 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); | |
2507 | if ((i + 1) == datasegcnt) | |
2508 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
2509 | else | |
2510 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
2511 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); | |
2512 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); | |
2513 | ||
2514 | sgl->sge_len = cpu_to_le32(dma_len); | |
2515 | dma_offset += dma_len; | |
2516 | ||
2517 | sgl++; | |
2518 | num_sge++; | |
2519 | } | |
2520 | ||
2521 | out: | |
2522 | return num_sge; | |
2523 | } | |
2524 | ||
2525 | /** | |
2526 | * lpfc_bg_setup_sgl_prot - Setup BlockGuard SGL with protection data | |
2527 | * @phba: The Hba for which this call is being executed. | |
2528 | * @sc: pointer to scsi command we're working on | |
2529 | * @sgl: pointer to buffer list for protection groups | |
2530 | * @datacnt: number of segments of data that have been dma mapped | |
2531 | * @protcnt: number of segment of protection data that have been dma mapped | |
2532 | * | |
2533 | * This function sets up SGL buffer list for protection groups of | |
2534 | * type LPFC_PG_TYPE_DIF | |
2535 | * | |
2536 | * This is usually used when DIFs are in their own buffers, | |
2537 | * separate from the data. The HBA can then by instructed | |
2538 | * to place the DIFs in the outgoing stream. For read operations, | |
2539 | * The HBA could extract the DIFs and place it in DIF buffers. | |
2540 | * | |
2541 | * The buffer list for this type consists of one or more of the | |
2542 | * protection groups described below: | |
2543 | * +-------------------------+ | |
2544 | * start of first prot group --> | DISEED | | |
2545 | * +-------------------------+ | |
2546 | * | DIF (Prot SGE) | | |
2547 | * +-------------------------+ | |
2548 | * | Data SGE | | |
2549 | * +-------------------------+ | |
2550 | * |more Data SGE's ... (opt)| | |
2551 | * +-------------------------+ | |
2552 | * start of new prot group --> | DISEED | | |
2553 | * +-------------------------+ | |
2554 | * | ... | | |
2555 | * +-------------------------+ | |
2556 | * | |
2557 | * Note: It is assumed that both data and protection s/g buffers have been | |
2558 | * mapped for DMA | |
2559 | * | |
2560 | * Returns the number of SGEs added to the SGL. | |
2561 | **/ | |
2562 | static int | |
2563 | lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
2564 | struct sli4_sge *sgl, int datacnt, int protcnt) | |
2565 | { | |
2566 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
2567 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ | |
2568 | struct sli4_sge_diseed *diseed = NULL; | |
2569 | dma_addr_t dataphysaddr, protphysaddr; | |
2570 | unsigned short curr_data = 0, curr_prot = 0; | |
2571 | unsigned int split_offset; | |
2572 | unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder; | |
2573 | unsigned int protgrp_blks, protgrp_bytes; | |
2574 | unsigned int remainder, subtotal; | |
2575 | int status; | |
2576 | unsigned char pgdone = 0, alldone = 0; | |
2577 | unsigned blksize; | |
2578 | uint32_t reftag; | |
2579 | uint8_t txop, rxop; | |
2580 | uint32_t dma_len; | |
0829a19a | 2581 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
acd6859b | 2582 | uint32_t rc; |
0829a19a | 2583 | #endif |
acd6859b JS |
2584 | uint32_t checking = 1; |
2585 | uint32_t dma_offset = 0; | |
2586 | int num_sge = 0; | |
2587 | ||
2588 | sgpe = scsi_prot_sglist(sc); | |
2589 | sgde = scsi_sglist(sc); | |
2590 | ||
2591 | if (!sgpe || !sgde) { | |
2592 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
2593 | "9082 Invalid s/g entry: data=0x%p prot=0x%p\n", | |
e2a0a9d6 JS |
2594 | sgpe, sgde); |
2595 | return 0; | |
2596 | } | |
2597 | ||
6c8eea54 JS |
2598 | status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop); |
2599 | if (status) | |
e2a0a9d6 JS |
2600 | goto out; |
2601 | ||
6c8eea54 | 2602 | /* extract some info from the scsi command */ |
e2a0a9d6 | 2603 | blksize = lpfc_cmd_blksize(sc); |
acd6859b | 2604 | reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */ |
e2a0a9d6 | 2605 | |
f9bb2da1 | 2606 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
4ac9b226 | 2607 | rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1); |
acd6859b | 2608 | if (rc) { |
9a6b09c0 | 2609 | if (rc & BG_ERR_SWAP) |
acd6859b | 2610 | lpfc_bg_err_opcodes(phba, sc, &txop, &rxop); |
9a6b09c0 | 2611 | if (rc & BG_ERR_CHECK) |
acd6859b JS |
2612 | checking = 0; |
2613 | } | |
f9bb2da1 JS |
2614 | #endif |
2615 | ||
e2a0a9d6 JS |
2616 | split_offset = 0; |
2617 | do { | |
96f7077f JS |
2618 | /* Check to see if we ran out of space */ |
2619 | if (num_sge >= (phba->cfg_total_seg_cnt - 2)) | |
2620 | return num_sge + 3; | |
2621 | ||
acd6859b JS |
2622 | /* setup DISEED with what we have */ |
2623 | diseed = (struct sli4_sge_diseed *) sgl; | |
2624 | memset(diseed, 0, sizeof(struct sli4_sge_diseed)); | |
2625 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DISEED); | |
2626 | ||
2627 | /* Endianness conversion if necessary */ | |
2628 | diseed->ref_tag = cpu_to_le32(reftag); | |
2629 | diseed->ref_tag_tran = diseed->ref_tag; | |
2630 | ||
9c6aa9d7 | 2631 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_GUARD)) { |
a6887e28 JS |
2632 | bf_set(lpfc_sli4_sge_dif_ce, diseed, checking); |
2633 | ||
2634 | } else { | |
2635 | bf_set(lpfc_sli4_sge_dif_ce, diseed, 0); | |
2636 | /* | |
2637 | * When in this mode, the hardware will replace | |
2638 | * the guard tag from the host with a | |
2639 | * newly generated good CRC for the wire. | |
2640 | * Switch to raw mode here to avoid this | |
2641 | * behavior. What the host sends gets put on the wire. | |
2642 | */ | |
2643 | if (txop == BG_OP_IN_CRC_OUT_CRC) { | |
2644 | txop = BG_OP_RAW_MODE; | |
2645 | rxop = BG_OP_RAW_MODE; | |
2646 | } | |
2647 | } | |
2648 | ||
2649 | ||
9c6aa9d7 | 2650 | if (lpfc_cmd_protect(sc, LPFC_CHECK_PROTECT_REF)) |
a6887e28 JS |
2651 | bf_set(lpfc_sli4_sge_dif_re, diseed, checking); |
2652 | else | |
2653 | bf_set(lpfc_sli4_sge_dif_re, diseed, 0); | |
2654 | ||
acd6859b JS |
2655 | /* setup DISEED with the rest of the info */ |
2656 | bf_set(lpfc_sli4_sge_dif_optx, diseed, txop); | |
2657 | bf_set(lpfc_sli4_sge_dif_oprx, diseed, rxop); | |
a6887e28 | 2658 | |
acd6859b JS |
2659 | bf_set(lpfc_sli4_sge_dif_ai, diseed, 1); |
2660 | bf_set(lpfc_sli4_sge_dif_me, diseed, 0); | |
2661 | ||
2662 | /* Endianness conversion if necessary for DISEED */ | |
2663 | diseed->word2 = cpu_to_le32(diseed->word2); | |
2664 | diseed->word3 = cpu_to_le32(diseed->word3); | |
2665 | ||
2666 | /* advance sgl and increment bde count */ | |
2667 | num_sge++; | |
2668 | sgl++; | |
e2a0a9d6 JS |
2669 | |
2670 | /* setup the first BDE that points to protection buffer */ | |
7f86059a JS |
2671 | protphysaddr = sg_dma_address(sgpe) + protgroup_offset; |
2672 | protgroup_len = sg_dma_len(sgpe) - protgroup_offset; | |
e2a0a9d6 | 2673 | |
e2a0a9d6 JS |
2674 | /* must be integer multiple of the DIF block length */ |
2675 | BUG_ON(protgroup_len % 8); | |
2676 | ||
acd6859b JS |
2677 | /* Now setup DIF SGE */ |
2678 | sgl->word2 = 0; | |
2679 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DIF); | |
2680 | sgl->addr_hi = le32_to_cpu(putPaddrHigh(protphysaddr)); | |
2681 | sgl->addr_lo = le32_to_cpu(putPaddrLow(protphysaddr)); | |
2682 | sgl->word2 = cpu_to_le32(sgl->word2); | |
7f86059a | 2683 | |
e2a0a9d6 JS |
2684 | protgrp_blks = protgroup_len / 8; |
2685 | protgrp_bytes = protgrp_blks * blksize; | |
2686 | ||
acd6859b JS |
2687 | /* check if DIF SGE is crossing the 4K boundary; if so split */ |
2688 | if ((sgl->addr_lo & 0xfff) + protgroup_len > 0x1000) { | |
2689 | protgroup_remainder = 0x1000 - (sgl->addr_lo & 0xfff); | |
7f86059a JS |
2690 | protgroup_offset += protgroup_remainder; |
2691 | protgrp_blks = protgroup_remainder / 8; | |
7c56b9fd | 2692 | protgrp_bytes = protgrp_blks * blksize; |
7f86059a JS |
2693 | } else { |
2694 | protgroup_offset = 0; | |
2695 | curr_prot++; | |
2696 | } | |
e2a0a9d6 | 2697 | |
acd6859b | 2698 | num_sge++; |
e2a0a9d6 | 2699 | |
acd6859b | 2700 | /* setup SGE's for data blocks associated with DIF data */ |
e2a0a9d6 JS |
2701 | pgdone = 0; |
2702 | subtotal = 0; /* total bytes processed for current prot grp */ | |
2703 | while (!pgdone) { | |
96f7077f JS |
2704 | /* Check to see if we ran out of space */ |
2705 | if (num_sge >= phba->cfg_total_seg_cnt) | |
2706 | return num_sge + 1; | |
2707 | ||
e2a0a9d6 | 2708 | if (!sgde) { |
6a9c52cf | 2709 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
acd6859b | 2710 | "9086 BLKGRD:%s Invalid data segment\n", |
e2a0a9d6 JS |
2711 | __func__); |
2712 | return 0; | |
2713 | } | |
acd6859b | 2714 | sgl++; |
e2a0a9d6 | 2715 | dataphysaddr = sg_dma_address(sgde) + split_offset; |
e2a0a9d6 JS |
2716 | |
2717 | remainder = sg_dma_len(sgde) - split_offset; | |
2718 | ||
2719 | if ((subtotal + remainder) <= protgrp_bytes) { | |
2720 | /* we can use this whole buffer */ | |
acd6859b | 2721 | dma_len = remainder; |
e2a0a9d6 JS |
2722 | split_offset = 0; |
2723 | ||
2724 | if ((subtotal + remainder) == protgrp_bytes) | |
2725 | pgdone = 1; | |
2726 | } else { | |
2727 | /* must split this buffer with next prot grp */ | |
acd6859b JS |
2728 | dma_len = protgrp_bytes - subtotal; |
2729 | split_offset += dma_len; | |
e2a0a9d6 JS |
2730 | } |
2731 | ||
acd6859b | 2732 | subtotal += dma_len; |
e2a0a9d6 | 2733 | |
acd6859b JS |
2734 | sgl->addr_lo = cpu_to_le32(putPaddrLow(dataphysaddr)); |
2735 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(dataphysaddr)); | |
2736 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
2737 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); | |
2738 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); | |
e2a0a9d6 | 2739 | |
acd6859b JS |
2740 | sgl->sge_len = cpu_to_le32(dma_len); |
2741 | dma_offset += dma_len; | |
2742 | ||
2743 | num_sge++; | |
e2a0a9d6 JS |
2744 | curr_data++; |
2745 | ||
2746 | if (split_offset) | |
2747 | break; | |
2748 | ||
2749 | /* Move to the next s/g segment if possible */ | |
2750 | sgde = sg_next(sgde); | |
2751 | } | |
2752 | ||
7f86059a JS |
2753 | if (protgroup_offset) { |
2754 | /* update the reference tag */ | |
2755 | reftag += protgrp_blks; | |
acd6859b | 2756 | sgl++; |
7f86059a JS |
2757 | continue; |
2758 | } | |
2759 | ||
e2a0a9d6 JS |
2760 | /* are we done ? */ |
2761 | if (curr_prot == protcnt) { | |
acd6859b | 2762 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
e2a0a9d6 JS |
2763 | alldone = 1; |
2764 | } else if (curr_prot < protcnt) { | |
2765 | /* advance to next prot buffer */ | |
2766 | sgpe = sg_next(sgpe); | |
acd6859b | 2767 | sgl++; |
e2a0a9d6 JS |
2768 | |
2769 | /* update the reference tag */ | |
2770 | reftag += protgrp_blks; | |
2771 | } else { | |
2772 | /* if we're here, we have a bug */ | |
6a9c52cf | 2773 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
acd6859b | 2774 | "9085 BLKGRD: bug in %s\n", __func__); |
e2a0a9d6 JS |
2775 | } |
2776 | ||
2777 | } while (!alldone); | |
acd6859b | 2778 | |
e2a0a9d6 JS |
2779 | out: |
2780 | ||
acd6859b | 2781 | return num_sge; |
e2a0a9d6 | 2782 | } |
7f86059a | 2783 | |
acd6859b JS |
2784 | /** |
2785 | * lpfc_prot_group_type - Get prtotection group type of SCSI command | |
2786 | * @phba: The Hba for which this call is being executed. | |
2787 | * @sc: pointer to scsi command we're working on | |
2788 | * | |
e2a0a9d6 JS |
2789 | * Given a SCSI command that supports DIF, determine composition of protection |
2790 | * groups involved in setting up buffer lists | |
2791 | * | |
acd6859b JS |
2792 | * Returns: Protection group type (with or without DIF) |
2793 | * | |
2794 | **/ | |
e2a0a9d6 JS |
2795 | static int |
2796 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) | |
2797 | { | |
2798 | int ret = LPFC_PG_TYPE_INVALID; | |
2799 | unsigned char op = scsi_get_prot_op(sc); | |
2800 | ||
2801 | switch (op) { | |
2802 | case SCSI_PROT_READ_STRIP: | |
2803 | case SCSI_PROT_WRITE_INSERT: | |
2804 | ret = LPFC_PG_TYPE_NO_DIF; | |
2805 | break; | |
2806 | case SCSI_PROT_READ_INSERT: | |
2807 | case SCSI_PROT_WRITE_STRIP: | |
2808 | case SCSI_PROT_READ_PASS: | |
2809 | case SCSI_PROT_WRITE_PASS: | |
e2a0a9d6 JS |
2810 | ret = LPFC_PG_TYPE_DIF_BUF; |
2811 | break; | |
2812 | default: | |
9c6aa9d7 JS |
2813 | if (phba) |
2814 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
2815 | "9021 Unsupported protection op:%d\n", | |
2816 | op); | |
e2a0a9d6 JS |
2817 | break; |
2818 | } | |
e2a0a9d6 JS |
2819 | return ret; |
2820 | } | |
2821 | ||
a6887e28 JS |
2822 | /** |
2823 | * lpfc_bg_scsi_adjust_dl - Adjust SCSI data length for BlockGuard | |
2824 | * @phba: The Hba for which this call is being executed. | |
2825 | * @lpfc_cmd: The scsi buffer which is going to be adjusted. | |
2826 | * | |
2827 | * Adjust the data length to account for how much data | |
2828 | * is actually on the wire. | |
2829 | * | |
2830 | * returns the adjusted data length | |
2831 | **/ | |
2832 | static int | |
2833 | lpfc_bg_scsi_adjust_dl(struct lpfc_hba *phba, | |
2834 | struct lpfc_scsi_buf *lpfc_cmd) | |
2835 | { | |
2836 | struct scsi_cmnd *sc = lpfc_cmd->pCmd; | |
2837 | int fcpdl; | |
2838 | ||
2839 | fcpdl = scsi_bufflen(sc); | |
2840 | ||
2841 | /* Check if there is protection data on the wire */ | |
2842 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { | |
9c6aa9d7 | 2843 | /* Read check for protection data */ |
a6887e28 JS |
2844 | if (scsi_get_prot_op(sc) == SCSI_PROT_READ_INSERT) |
2845 | return fcpdl; | |
2846 | ||
2847 | } else { | |
9c6aa9d7 | 2848 | /* Write check for protection data */ |
a6887e28 JS |
2849 | if (scsi_get_prot_op(sc) == SCSI_PROT_WRITE_STRIP) |
2850 | return fcpdl; | |
2851 | } | |
2852 | ||
2853 | /* | |
2854 | * If we are in DIF Type 1 mode every data block has a 8 byte | |
9c6aa9d7 JS |
2855 | * DIF (trailer) attached to it. Must ajust FCP data length |
2856 | * to account for the protection data. | |
a6887e28 | 2857 | */ |
9c6aa9d7 | 2858 | fcpdl += (fcpdl / lpfc_cmd_blksize(sc)) * 8; |
a6887e28 JS |
2859 | |
2860 | return fcpdl; | |
2861 | } | |
2862 | ||
acd6859b JS |
2863 | /** |
2864 | * lpfc_bg_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec | |
2865 | * @phba: The Hba for which this call is being executed. | |
2866 | * @lpfc_cmd: The scsi buffer which is going to be prep'ed. | |
2867 | * | |
e2a0a9d6 JS |
2868 | * This is the protection/DIF aware version of |
2869 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the | |
2870 | * two functions eventually, but for now, it's here | |
acd6859b | 2871 | **/ |
e2a0a9d6 | 2872 | static int |
acd6859b | 2873 | lpfc_bg_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, |
e2a0a9d6 JS |
2874 | struct lpfc_scsi_buf *lpfc_cmd) |
2875 | { | |
2876 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
2877 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
2878 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; | |
2879 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
2880 | uint32_t num_bde = 0; | |
2881 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; | |
2882 | int prot_group_type = 0; | |
a6887e28 | 2883 | int fcpdl; |
e2a0a9d6 JS |
2884 | |
2885 | /* | |
2886 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd | |
2887 | * fcp_rsp regions to the first data bde entry | |
2888 | */ | |
2889 | bpl += 2; | |
2890 | if (scsi_sg_count(scsi_cmnd)) { | |
2891 | /* | |
2892 | * The driver stores the segment count returned from pci_map_sg | |
2893 | * because this a count of dma-mappings used to map the use_sg | |
2894 | * pages. They are not guaranteed to be the same for those | |
2895 | * architectures that implement an IOMMU. | |
2896 | */ | |
2897 | datasegcnt = dma_map_sg(&phba->pcidev->dev, | |
2898 | scsi_sglist(scsi_cmnd), | |
2899 | scsi_sg_count(scsi_cmnd), datadir); | |
2900 | if (unlikely(!datasegcnt)) | |
2901 | return 1; | |
2902 | ||
2903 | lpfc_cmd->seg_cnt = datasegcnt; | |
96f7077f JS |
2904 | |
2905 | /* First check if data segment count from SCSI Layer is good */ | |
2906 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) | |
2907 | goto err; | |
e2a0a9d6 JS |
2908 | |
2909 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); | |
2910 | ||
2911 | switch (prot_group_type) { | |
2912 | case LPFC_PG_TYPE_NO_DIF: | |
96f7077f JS |
2913 | |
2914 | /* Here we need to add a PDE5 and PDE6 to the count */ | |
2915 | if ((lpfc_cmd->seg_cnt + 2) > phba->cfg_total_seg_cnt) | |
2916 | goto err; | |
2917 | ||
e2a0a9d6 JS |
2918 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, |
2919 | datasegcnt); | |
c9404c9c | 2920 | /* we should have 2 or more entries in buffer list */ |
e2a0a9d6 JS |
2921 | if (num_bde < 2) |
2922 | goto err; | |
2923 | break; | |
96f7077f JS |
2924 | |
2925 | case LPFC_PG_TYPE_DIF_BUF: | |
e2a0a9d6 JS |
2926 | /* |
2927 | * This type indicates that protection buffers are | |
2928 | * passed to the driver, so that needs to be prepared | |
2929 | * for DMA | |
2930 | */ | |
2931 | protsegcnt = dma_map_sg(&phba->pcidev->dev, | |
2932 | scsi_prot_sglist(scsi_cmnd), | |
2933 | scsi_prot_sg_count(scsi_cmnd), datadir); | |
2934 | if (unlikely(!protsegcnt)) { | |
2935 | scsi_dma_unmap(scsi_cmnd); | |
2936 | return 1; | |
2937 | } | |
2938 | ||
2939 | lpfc_cmd->prot_seg_cnt = protsegcnt; | |
96f7077f JS |
2940 | |
2941 | /* | |
2942 | * There is a minimun of 4 BPLs used for every | |
2943 | * protection data segment. | |
2944 | */ | |
2945 | if ((lpfc_cmd->prot_seg_cnt * 4) > | |
2946 | (phba->cfg_total_seg_cnt - 2)) | |
2947 | goto err; | |
e2a0a9d6 JS |
2948 | |
2949 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, | |
2950 | datasegcnt, protsegcnt); | |
c9404c9c | 2951 | /* we should have 3 or more entries in buffer list */ |
96f7077f JS |
2952 | if ((num_bde < 3) || |
2953 | (num_bde > phba->cfg_total_seg_cnt)) | |
e2a0a9d6 JS |
2954 | goto err; |
2955 | break; | |
96f7077f | 2956 | |
e2a0a9d6 JS |
2957 | case LPFC_PG_TYPE_INVALID: |
2958 | default: | |
96f7077f JS |
2959 | scsi_dma_unmap(scsi_cmnd); |
2960 | lpfc_cmd->seg_cnt = 0; | |
2961 | ||
e2a0a9d6 JS |
2962 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
2963 | "9022 Unexpected protection group %i\n", | |
2964 | prot_group_type); | |
2965 | return 1; | |
2966 | } | |
2967 | } | |
2968 | ||
2969 | /* | |
2970 | * Finish initializing those IOCB fields that are dependent on the | |
2971 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly | |
2972 | * reinitialized since all iocb memory resources are used many times | |
2973 | * for transmit, receive, and continuation bpl's. | |
2974 | */ | |
2975 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); | |
2976 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); | |
2977 | iocb_cmd->ulpBdeCount = 1; | |
2978 | iocb_cmd->ulpLe = 1; | |
2979 | ||
a6887e28 | 2980 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
e2a0a9d6 JS |
2981 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
2982 | ||
2983 | /* | |
2984 | * Due to difference in data length between DIF/non-DIF paths, | |
2985 | * we need to set word 4 of IOCB here | |
2986 | */ | |
2987 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; | |
2988 | ||
dea3101e | 2989 | return 0; |
e2a0a9d6 | 2990 | err: |
96f7077f JS |
2991 | if (lpfc_cmd->seg_cnt) |
2992 | scsi_dma_unmap(scsi_cmnd); | |
2993 | if (lpfc_cmd->prot_seg_cnt) | |
2994 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), | |
2995 | scsi_prot_sg_count(scsi_cmnd), | |
2996 | scsi_cmnd->sc_data_direction); | |
2997 | ||
e2a0a9d6 | 2998 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
96f7077f JS |
2999 | "9023 Cannot setup S/G List for HBA" |
3000 | "IO segs %d/%d BPL %d SCSI %d: %d %d\n", | |
3001 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, | |
3002 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, | |
e2a0a9d6 | 3003 | prot_group_type, num_bde); |
96f7077f JS |
3004 | |
3005 | lpfc_cmd->seg_cnt = 0; | |
3006 | lpfc_cmd->prot_seg_cnt = 0; | |
e2a0a9d6 JS |
3007 | return 1; |
3008 | } | |
3009 | ||
737d4248 JS |
3010 | /* |
3011 | * This function calcuates the T10 DIF guard tag | |
3012 | * on the specified data using a CRC algorithmn | |
3013 | * using crc_t10dif. | |
3014 | */ | |
3015 | uint16_t | |
3016 | lpfc_bg_crc(uint8_t *data, int count) | |
3017 | { | |
3018 | uint16_t crc = 0; | |
3019 | uint16_t x; | |
3020 | ||
3021 | crc = crc_t10dif(data, count); | |
3022 | x = cpu_to_be16(crc); | |
3023 | return x; | |
3024 | } | |
3025 | ||
3026 | /* | |
3027 | * This function calcuates the T10 DIF guard tag | |
3028 | * on the specified data using a CSUM algorithmn | |
3029 | * using ip_compute_csum. | |
3030 | */ | |
3031 | uint16_t | |
3032 | lpfc_bg_csum(uint8_t *data, int count) | |
3033 | { | |
3034 | uint16_t ret; | |
3035 | ||
3036 | ret = ip_compute_csum(data, count); | |
3037 | return ret; | |
3038 | } | |
3039 | ||
3040 | /* | |
3041 | * This function examines the protection data to try to determine | |
3042 | * what type of T10-DIF error occurred. | |
3043 | */ | |
3044 | void | |
3045 | lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
3046 | { | |
3047 | struct scatterlist *sgpe; /* s/g prot entry */ | |
3048 | struct scatterlist *sgde; /* s/g data entry */ | |
3049 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
3050 | struct scsi_dif_tuple *src = NULL; | |
3051 | uint8_t *data_src = NULL; | |
3052 | uint16_t guard_tag, guard_type; | |
3053 | uint16_t start_app_tag, app_tag; | |
3054 | uint32_t start_ref_tag, ref_tag; | |
3055 | int prot, protsegcnt; | |
3056 | int err_type, len, data_len; | |
3057 | int chk_ref, chk_app, chk_guard; | |
3058 | uint16_t sum; | |
3059 | unsigned blksize; | |
3060 | ||
3061 | err_type = BGS_GUARD_ERR_MASK; | |
3062 | sum = 0; | |
3063 | guard_tag = 0; | |
3064 | ||
3065 | /* First check to see if there is protection data to examine */ | |
3066 | prot = scsi_get_prot_op(cmd); | |
3067 | if ((prot == SCSI_PROT_READ_STRIP) || | |
3068 | (prot == SCSI_PROT_WRITE_INSERT) || | |
3069 | (prot == SCSI_PROT_NORMAL)) | |
3070 | goto out; | |
3071 | ||
3072 | /* Currently the driver just supports ref_tag and guard_tag checking */ | |
3073 | chk_ref = 1; | |
3074 | chk_app = 0; | |
3075 | chk_guard = 0; | |
3076 | ||
3077 | /* Setup a ptr to the protection data provided by the SCSI host */ | |
3078 | sgpe = scsi_prot_sglist(cmd); | |
3079 | protsegcnt = lpfc_cmd->prot_seg_cnt; | |
3080 | ||
3081 | if (sgpe && protsegcnt) { | |
3082 | ||
3083 | /* | |
3084 | * We will only try to verify guard tag if the segment | |
3085 | * data length is a multiple of the blksize. | |
3086 | */ | |
3087 | sgde = scsi_sglist(cmd); | |
3088 | blksize = lpfc_cmd_blksize(cmd); | |
3089 | data_src = (uint8_t *)sg_virt(sgde); | |
3090 | data_len = sgde->length; | |
3091 | if ((data_len & (blksize - 1)) == 0) | |
3092 | chk_guard = 1; | |
3093 | guard_type = scsi_host_get_guard(cmd->device->host); | |
3094 | ||
e85d8f9f | 3095 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); |
a6887e28 | 3096 | start_ref_tag = (uint32_t)scsi_get_lba(cmd); /* Truncate LBA */ |
737d4248 | 3097 | start_app_tag = src->app_tag; |
737d4248 JS |
3098 | len = sgpe->length; |
3099 | while (src && protsegcnt) { | |
3100 | while (len) { | |
3101 | ||
3102 | /* | |
3103 | * First check to see if a protection data | |
3104 | * check is valid | |
3105 | */ | |
3106 | if ((src->ref_tag == 0xffffffff) || | |
3107 | (src->app_tag == 0xffff)) { | |
3108 | start_ref_tag++; | |
3109 | goto skipit; | |
3110 | } | |
3111 | ||
9c6aa9d7 | 3112 | /* First Guard Tag checking */ |
737d4248 JS |
3113 | if (chk_guard) { |
3114 | guard_tag = src->guard_tag; | |
9c6aa9d7 | 3115 | if (lpfc_cmd_guard_csum(cmd)) |
737d4248 JS |
3116 | sum = lpfc_bg_csum(data_src, |
3117 | blksize); | |
3118 | else | |
3119 | sum = lpfc_bg_crc(data_src, | |
3120 | blksize); | |
3121 | if ((guard_tag != sum)) { | |
3122 | err_type = BGS_GUARD_ERR_MASK; | |
3123 | goto out; | |
3124 | } | |
3125 | } | |
9c6aa9d7 JS |
3126 | |
3127 | /* Reference Tag checking */ | |
3128 | ref_tag = be32_to_cpu(src->ref_tag); | |
3129 | if (chk_ref && (ref_tag != start_ref_tag)) { | |
3130 | err_type = BGS_REFTAG_ERR_MASK; | |
3131 | goto out; | |
3132 | } | |
3133 | start_ref_tag++; | |
3134 | ||
3135 | /* App Tag checking */ | |
3136 | app_tag = src->app_tag; | |
3137 | if (chk_app && (app_tag != start_app_tag)) { | |
3138 | err_type = BGS_APPTAG_ERR_MASK; | |
3139 | goto out; | |
3140 | } | |
737d4248 JS |
3141 | skipit: |
3142 | len -= sizeof(struct scsi_dif_tuple); | |
3143 | if (len < 0) | |
3144 | len = 0; | |
3145 | src++; | |
3146 | ||
3147 | data_src += blksize; | |
3148 | data_len -= blksize; | |
3149 | ||
3150 | /* | |
3151 | * Are we at the end of the Data segment? | |
3152 | * The data segment is only used for Guard | |
3153 | * tag checking. | |
3154 | */ | |
3155 | if (chk_guard && (data_len == 0)) { | |
3156 | chk_guard = 0; | |
3157 | sgde = sg_next(sgde); | |
3158 | if (!sgde) | |
3159 | goto out; | |
3160 | ||
3161 | data_src = (uint8_t *)sg_virt(sgde); | |
3162 | data_len = sgde->length; | |
3163 | if ((data_len & (blksize - 1)) == 0) | |
3164 | chk_guard = 1; | |
3165 | } | |
3166 | } | |
3167 | ||
3168 | /* Goto the next Protection data segment */ | |
3169 | sgpe = sg_next(sgpe); | |
3170 | if (sgpe) { | |
3171 | src = (struct scsi_dif_tuple *)sg_virt(sgpe); | |
3172 | len = sgpe->length; | |
3173 | } else { | |
3174 | src = NULL; | |
3175 | } | |
3176 | protsegcnt--; | |
3177 | } | |
3178 | } | |
3179 | out: | |
3180 | if (err_type == BGS_GUARD_ERR_MASK) { | |
3181 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
3182 | 0x10, 0x1); | |
3183 | cmd->result = DRIVER_SENSE << 24 | |
3184 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); | |
3185 | phba->bg_guard_err_cnt++; | |
3186 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, | |
3187 | "9069 BLKGRD: LBA %lx grd_tag error %x != %x\n", | |
3188 | (unsigned long)scsi_get_lba(cmd), | |
3189 | sum, guard_tag); | |
3190 | ||
3191 | } else if (err_type == BGS_REFTAG_ERR_MASK) { | |
3192 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
3193 | 0x10, 0x3); | |
3194 | cmd->result = DRIVER_SENSE << 24 | |
3195 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); | |
3196 | ||
3197 | phba->bg_reftag_err_cnt++; | |
3198 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, | |
3199 | "9066 BLKGRD: LBA %lx ref_tag error %x != %x\n", | |
3200 | (unsigned long)scsi_get_lba(cmd), | |
3201 | ref_tag, start_ref_tag); | |
3202 | ||
3203 | } else if (err_type == BGS_APPTAG_ERR_MASK) { | |
3204 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
3205 | 0x10, 0x2); | |
3206 | cmd->result = DRIVER_SENSE << 24 | |
3207 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); | |
3208 | ||
3209 | phba->bg_apptag_err_cnt++; | |
3210 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, | |
3211 | "9041 BLKGRD: LBA %lx app_tag error %x != %x\n", | |
3212 | (unsigned long)scsi_get_lba(cmd), | |
3213 | app_tag, start_app_tag); | |
3214 | } | |
3215 | } | |
3216 | ||
3217 | ||
e2a0a9d6 JS |
3218 | /* |
3219 | * This function checks for BlockGuard errors detected by | |
3220 | * the HBA. In case of errors, the ASC/ASCQ fields in the | |
3221 | * sense buffer will be set accordingly, paired with | |
3222 | * ILLEGAL_REQUEST to signal to the kernel that the HBA | |
3223 | * detected corruption. | |
3224 | * | |
3225 | * Returns: | |
3226 | * 0 - No error found | |
3227 | * 1 - BlockGuard error found | |
3228 | * -1 - Internal error (bad profile, ...etc) | |
3229 | */ | |
3230 | static int | |
3231 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, | |
3232 | struct lpfc_iocbq *pIocbOut) | |
3233 | { | |
3234 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
3235 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; | |
3236 | int ret = 0; | |
3237 | uint32_t bghm = bgf->bghm; | |
3238 | uint32_t bgstat = bgf->bgstat; | |
3239 | uint64_t failing_sector = 0; | |
3240 | ||
e2a0a9d6 JS |
3241 | spin_lock(&_dump_buf_lock); |
3242 | if (!_dump_buf_done) { | |
6a9c52cf JS |
3243 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving" |
3244 | " Data for %u blocks to debugfs\n", | |
e2a0a9d6 | 3245 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); |
6a9c52cf | 3246 | lpfc_debug_save_data(phba, cmd); |
e2a0a9d6 JS |
3247 | |
3248 | /* If we have a prot sgl, save the DIF buffer */ | |
3249 | if (lpfc_prot_group_type(phba, cmd) == | |
3250 | LPFC_PG_TYPE_DIF_BUF) { | |
6a9c52cf JS |
3251 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: " |
3252 | "Saving DIF for %u blocks to debugfs\n", | |
3253 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); | |
3254 | lpfc_debug_save_dif(phba, cmd); | |
e2a0a9d6 JS |
3255 | } |
3256 | ||
3257 | _dump_buf_done = 1; | |
3258 | } | |
3259 | spin_unlock(&_dump_buf_lock); | |
3260 | ||
3261 | if (lpfc_bgs_get_invalid_prof(bgstat)) { | |
3262 | cmd->result = ScsiResult(DID_ERROR, 0); | |
737d4248 JS |
3263 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
3264 | "9072 BLKGRD: Invalid BG Profile in cmd" | |
3265 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
3266 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], | |
3267 | (unsigned long long)scsi_get_lba(cmd), | |
3268 | blk_rq_sectors(cmd->request), bgstat, bghm); | |
e2a0a9d6 JS |
3269 | ret = (-1); |
3270 | goto out; | |
3271 | } | |
3272 | ||
3273 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { | |
3274 | cmd->result = ScsiResult(DID_ERROR, 0); | |
737d4248 JS |
3275 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
3276 | "9073 BLKGRD: Invalid BG PDIF Block in cmd" | |
3277 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
3278 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], | |
3279 | (unsigned long long)scsi_get_lba(cmd), | |
3280 | blk_rq_sectors(cmd->request), bgstat, bghm); | |
e2a0a9d6 JS |
3281 | ret = (-1); |
3282 | goto out; | |
3283 | } | |
3284 | ||
3285 | if (lpfc_bgs_get_guard_err(bgstat)) { | |
3286 | ret = 1; | |
3287 | ||
3288 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
3289 | 0x10, 0x1); | |
1c9fbafc | 3290 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
3291 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
3292 | phba->bg_guard_err_cnt++; | |
737d4248 JS |
3293 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
3294 | "9055 BLKGRD: Guard Tag error in cmd" | |
3295 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
3296 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], | |
3297 | (unsigned long long)scsi_get_lba(cmd), | |
3298 | blk_rq_sectors(cmd->request), bgstat, bghm); | |
e2a0a9d6 JS |
3299 | } |
3300 | ||
3301 | if (lpfc_bgs_get_reftag_err(bgstat)) { | |
3302 | ret = 1; | |
3303 | ||
3304 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
3305 | 0x10, 0x3); | |
1c9fbafc | 3306 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
3307 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
3308 | ||
3309 | phba->bg_reftag_err_cnt++; | |
737d4248 JS |
3310 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
3311 | "9056 BLKGRD: Ref Tag error in cmd" | |
3312 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
3313 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], | |
3314 | (unsigned long long)scsi_get_lba(cmd), | |
3315 | blk_rq_sectors(cmd->request), bgstat, bghm); | |
e2a0a9d6 JS |
3316 | } |
3317 | ||
3318 | if (lpfc_bgs_get_apptag_err(bgstat)) { | |
3319 | ret = 1; | |
3320 | ||
3321 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
3322 | 0x10, 0x2); | |
1c9fbafc | 3323 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
3324 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
3325 | ||
3326 | phba->bg_apptag_err_cnt++; | |
737d4248 JS |
3327 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
3328 | "9061 BLKGRD: App Tag error in cmd" | |
3329 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
3330 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], | |
3331 | (unsigned long long)scsi_get_lba(cmd), | |
3332 | blk_rq_sectors(cmd->request), bgstat, bghm); | |
e2a0a9d6 JS |
3333 | } |
3334 | ||
3335 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { | |
3336 | /* | |
3337 | * setup sense data descriptor 0 per SPC-4 as an information | |
7c56b9fd JS |
3338 | * field, and put the failing LBA in it. |
3339 | * This code assumes there was also a guard/app/ref tag error | |
3340 | * indication. | |
e2a0a9d6 | 3341 | */ |
7c56b9fd JS |
3342 | cmd->sense_buffer[7] = 0xc; /* Additional sense length */ |
3343 | cmd->sense_buffer[8] = 0; /* Information descriptor type */ | |
3344 | cmd->sense_buffer[9] = 0xa; /* Additional descriptor length */ | |
3345 | cmd->sense_buffer[10] = 0x80; /* Validity bit */ | |
acd6859b JS |
3346 | |
3347 | /* bghm is a "on the wire" FC frame based count */ | |
3348 | switch (scsi_get_prot_op(cmd)) { | |
3349 | case SCSI_PROT_READ_INSERT: | |
3350 | case SCSI_PROT_WRITE_STRIP: | |
3351 | bghm /= cmd->device->sector_size; | |
3352 | break; | |
3353 | case SCSI_PROT_READ_STRIP: | |
3354 | case SCSI_PROT_WRITE_INSERT: | |
3355 | case SCSI_PROT_READ_PASS: | |
3356 | case SCSI_PROT_WRITE_PASS: | |
3357 | bghm /= (cmd->device->sector_size + | |
3358 | sizeof(struct scsi_dif_tuple)); | |
3359 | break; | |
3360 | } | |
e2a0a9d6 JS |
3361 | |
3362 | failing_sector = scsi_get_lba(cmd); | |
3363 | failing_sector += bghm; | |
3364 | ||
7c56b9fd JS |
3365 | /* Descriptor Information */ |
3366 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[12]); | |
e2a0a9d6 JS |
3367 | } |
3368 | ||
3369 | if (!ret) { | |
3370 | /* No error was reported - problem in FW? */ | |
737d4248 JS |
3371 | lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, |
3372 | "9057 BLKGRD: Unknown error in cmd" | |
3373 | " 0x%x lba 0x%llx blk cnt 0x%x " | |
3374 | "bgstat=x%x bghm=x%x\n", cmd->cmnd[0], | |
3375 | (unsigned long long)scsi_get_lba(cmd), | |
3376 | blk_rq_sectors(cmd->request), bgstat, bghm); | |
3377 | ||
3378 | /* Calcuate what type of error it was */ | |
3379 | lpfc_calc_bg_err(phba, lpfc_cmd); | |
e2a0a9d6 | 3380 | } |
e2a0a9d6 JS |
3381 | out: |
3382 | return ret; | |
dea3101e | 3383 | } |
3384 | ||
da0436e9 JS |
3385 | /** |
3386 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec | |
3387 | * @phba: The Hba for which this call is being executed. | |
3388 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
3389 | * | |
3390 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | |
3391 | * field of @lpfc_cmd for device with SLI-4 interface spec. | |
3392 | * | |
3393 | * Return codes: | |
6c8eea54 JS |
3394 | * 1 - Error |
3395 | * 0 - Success | |
da0436e9 JS |
3396 | **/ |
3397 | static int | |
3398 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
3399 | { | |
3400 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
3401 | struct scatterlist *sgel = NULL; | |
3402 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
3403 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
fedd3b7b | 3404 | struct sli4_sge *first_data_sgl; |
da0436e9 JS |
3405 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; |
3406 | dma_addr_t physaddr; | |
3407 | uint32_t num_bde = 0; | |
3408 | uint32_t dma_len; | |
3409 | uint32_t dma_offset = 0; | |
3410 | int nseg; | |
fedd3b7b | 3411 | struct ulp_bde64 *bde; |
da0436e9 JS |
3412 | |
3413 | /* | |
3414 | * There are three possibilities here - use scatter-gather segment, use | |
3415 | * the single mapping, or neither. Start the lpfc command prep by | |
3416 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
3417 | * data bde entry. | |
3418 | */ | |
3419 | if (scsi_sg_count(scsi_cmnd)) { | |
3420 | /* | |
3421 | * The driver stores the segment count returned from pci_map_sg | |
3422 | * because this a count of dma-mappings used to map the use_sg | |
3423 | * pages. They are not guaranteed to be the same for those | |
3424 | * architectures that implement an IOMMU. | |
3425 | */ | |
3426 | ||
3427 | nseg = scsi_dma_map(scsi_cmnd); | |
3428 | if (unlikely(!nseg)) | |
3429 | return 1; | |
3430 | sgl += 1; | |
3431 | /* clear the last flag in the fcp_rsp map entry */ | |
3432 | sgl->word2 = le32_to_cpu(sgl->word2); | |
3433 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
3434 | sgl->word2 = cpu_to_le32(sgl->word2); | |
3435 | sgl += 1; | |
fedd3b7b | 3436 | first_data_sgl = sgl; |
da0436e9 JS |
3437 | lpfc_cmd->seg_cnt = nseg; |
3438 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { | |
6a9c52cf JS |
3439 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" |
3440 | " %s: Too many sg segments from " | |
3441 | "dma_map_sg. Config %d, seg_cnt %d\n", | |
3442 | __func__, phba->cfg_sg_seg_cnt, | |
da0436e9 | 3443 | lpfc_cmd->seg_cnt); |
96f7077f | 3444 | lpfc_cmd->seg_cnt = 0; |
da0436e9 JS |
3445 | scsi_dma_unmap(scsi_cmnd); |
3446 | return 1; | |
3447 | } | |
3448 | ||
3449 | /* | |
3450 | * The driver established a maximum scatter-gather segment count | |
3451 | * during probe that limits the number of sg elements in any | |
3452 | * single scsi command. Just run through the seg_cnt and format | |
3453 | * the sge's. | |
3454 | * When using SLI-3 the driver will try to fit all the BDEs into | |
3455 | * the IOCB. If it can't then the BDEs get added to a BPL as it | |
3456 | * does for SLI-2 mode. | |
3457 | */ | |
3458 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { | |
3459 | physaddr = sg_dma_address(sgel); | |
3460 | dma_len = sg_dma_len(sgel); | |
da0436e9 JS |
3461 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); |
3462 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); | |
0558056c | 3463 | sgl->word2 = le32_to_cpu(sgl->word2); |
da0436e9 JS |
3464 | if ((num_bde + 1) == nseg) |
3465 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
3466 | else | |
3467 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
3468 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); | |
f9bb2da1 | 3469 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); |
da0436e9 | 3470 | sgl->word2 = cpu_to_le32(sgl->word2); |
28baac74 | 3471 | sgl->sge_len = cpu_to_le32(dma_len); |
da0436e9 JS |
3472 | dma_offset += dma_len; |
3473 | sgl++; | |
3474 | } | |
fedd3b7b JS |
3475 | /* setup the performance hint (first data BDE) if enabled */ |
3476 | if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) { | |
3477 | bde = (struct ulp_bde64 *) | |
3478 | &(iocb_cmd->unsli3.sli3Words[5]); | |
3479 | bde->addrLow = first_data_sgl->addr_lo; | |
3480 | bde->addrHigh = first_data_sgl->addr_hi; | |
3481 | bde->tus.f.bdeSize = | |
3482 | le32_to_cpu(first_data_sgl->sge_len); | |
3483 | bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
3484 | bde->tus.w = cpu_to_le32(bde->tus.w); | |
3485 | } | |
da0436e9 JS |
3486 | } else { |
3487 | sgl += 1; | |
3488 | /* clear the last flag in the fcp_rsp map entry */ | |
3489 | sgl->word2 = le32_to_cpu(sgl->word2); | |
3490 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
3491 | sgl->word2 = cpu_to_le32(sgl->word2); | |
3492 | } | |
3493 | ||
3494 | /* | |
3495 | * Finish initializing those IOCB fields that are dependent on the | |
3496 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is | |
3497 | * explicitly reinitialized. | |
3498 | * all iocb memory resources are reused. | |
3499 | */ | |
3500 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); | |
3501 | ||
3502 | /* | |
3503 | * Due to difference in data length between DIF/non-DIF paths, | |
3504 | * we need to set word 4 of IOCB here | |
3505 | */ | |
3506 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); | |
3507 | return 0; | |
3508 | } | |
3509 | ||
acd6859b JS |
3510 | /** |
3511 | * lpfc_bg_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec | |
3512 | * @phba: The Hba for which this call is being executed. | |
3513 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
3514 | * | |
3515 | * This is the protection/DIF aware version of | |
3516 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the | |
3517 | * two functions eventually, but for now, it's here | |
3518 | **/ | |
3519 | static int | |
3520 | lpfc_bg_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, | |
3521 | struct lpfc_scsi_buf *lpfc_cmd) | |
3522 | { | |
3523 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
3524 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
3525 | struct sli4_sge *sgl = (struct sli4_sge *)(lpfc_cmd->fcp_bpl); | |
3526 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
96f7077f | 3527 | uint32_t num_sge = 0; |
acd6859b JS |
3528 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; |
3529 | int prot_group_type = 0; | |
3530 | int fcpdl; | |
3531 | ||
3532 | /* | |
3533 | * Start the lpfc command prep by bumping the sgl beyond fcp_cmnd | |
96f7077f | 3534 | * fcp_rsp regions to the first data sge entry |
acd6859b JS |
3535 | */ |
3536 | if (scsi_sg_count(scsi_cmnd)) { | |
3537 | /* | |
3538 | * The driver stores the segment count returned from pci_map_sg | |
3539 | * because this a count of dma-mappings used to map the use_sg | |
3540 | * pages. They are not guaranteed to be the same for those | |
3541 | * architectures that implement an IOMMU. | |
3542 | */ | |
3543 | datasegcnt = dma_map_sg(&phba->pcidev->dev, | |
3544 | scsi_sglist(scsi_cmnd), | |
3545 | scsi_sg_count(scsi_cmnd), datadir); | |
3546 | if (unlikely(!datasegcnt)) | |
3547 | return 1; | |
3548 | ||
3549 | sgl += 1; | |
3550 | /* clear the last flag in the fcp_rsp map entry */ | |
3551 | sgl->word2 = le32_to_cpu(sgl->word2); | |
3552 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
3553 | sgl->word2 = cpu_to_le32(sgl->word2); | |
3554 | ||
3555 | sgl += 1; | |
3556 | lpfc_cmd->seg_cnt = datasegcnt; | |
96f7077f JS |
3557 | |
3558 | /* First check if data segment count from SCSI Layer is good */ | |
3559 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) | |
3560 | goto err; | |
acd6859b JS |
3561 | |
3562 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); | |
3563 | ||
3564 | switch (prot_group_type) { | |
3565 | case LPFC_PG_TYPE_NO_DIF: | |
96f7077f JS |
3566 | /* Here we need to add a DISEED to the count */ |
3567 | if ((lpfc_cmd->seg_cnt + 1) > phba->cfg_total_seg_cnt) | |
3568 | goto err; | |
3569 | ||
3570 | num_sge = lpfc_bg_setup_sgl(phba, scsi_cmnd, sgl, | |
acd6859b | 3571 | datasegcnt); |
96f7077f | 3572 | |
acd6859b | 3573 | /* we should have 2 or more entries in buffer list */ |
96f7077f | 3574 | if (num_sge < 2) |
acd6859b JS |
3575 | goto err; |
3576 | break; | |
96f7077f JS |
3577 | |
3578 | case LPFC_PG_TYPE_DIF_BUF: | |
acd6859b JS |
3579 | /* |
3580 | * This type indicates that protection buffers are | |
3581 | * passed to the driver, so that needs to be prepared | |
3582 | * for DMA | |
3583 | */ | |
3584 | protsegcnt = dma_map_sg(&phba->pcidev->dev, | |
3585 | scsi_prot_sglist(scsi_cmnd), | |
3586 | scsi_prot_sg_count(scsi_cmnd), datadir); | |
3587 | if (unlikely(!protsegcnt)) { | |
3588 | scsi_dma_unmap(scsi_cmnd); | |
3589 | return 1; | |
3590 | } | |
3591 | ||
3592 | lpfc_cmd->prot_seg_cnt = protsegcnt; | |
96f7077f JS |
3593 | /* |
3594 | * There is a minimun of 3 SGEs used for every | |
3595 | * protection data segment. | |
3596 | */ | |
3597 | if ((lpfc_cmd->prot_seg_cnt * 3) > | |
3598 | (phba->cfg_total_seg_cnt - 2)) | |
3599 | goto err; | |
acd6859b | 3600 | |
96f7077f | 3601 | num_sge = lpfc_bg_setup_sgl_prot(phba, scsi_cmnd, sgl, |
acd6859b | 3602 | datasegcnt, protsegcnt); |
96f7077f | 3603 | |
acd6859b | 3604 | /* we should have 3 or more entries in buffer list */ |
96f7077f JS |
3605 | if ((num_sge < 3) || |
3606 | (num_sge > phba->cfg_total_seg_cnt)) | |
acd6859b JS |
3607 | goto err; |
3608 | break; | |
96f7077f | 3609 | |
acd6859b JS |
3610 | case LPFC_PG_TYPE_INVALID: |
3611 | default: | |
96f7077f JS |
3612 | scsi_dma_unmap(scsi_cmnd); |
3613 | lpfc_cmd->seg_cnt = 0; | |
3614 | ||
acd6859b JS |
3615 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
3616 | "9083 Unexpected protection group %i\n", | |
3617 | prot_group_type); | |
3618 | return 1; | |
3619 | } | |
3620 | } | |
3621 | ||
8012cc38 JS |
3622 | switch (scsi_get_prot_op(scsi_cmnd)) { |
3623 | case SCSI_PROT_WRITE_STRIP: | |
3624 | case SCSI_PROT_READ_STRIP: | |
3625 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_STRIP; | |
3626 | break; | |
3627 | case SCSI_PROT_WRITE_INSERT: | |
3628 | case SCSI_PROT_READ_INSERT: | |
3629 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_INSERT; | |
3630 | break; | |
3631 | case SCSI_PROT_WRITE_PASS: | |
3632 | case SCSI_PROT_READ_PASS: | |
3633 | lpfc_cmd->cur_iocbq.iocb_flag |= LPFC_IO_DIF_PASS; | |
3634 | break; | |
3635 | } | |
3636 | ||
acd6859b | 3637 | fcpdl = lpfc_bg_scsi_adjust_dl(phba, lpfc_cmd); |
acd6859b JS |
3638 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); |
3639 | ||
3640 | /* | |
3641 | * Due to difference in data length between DIF/non-DIF paths, | |
3642 | * we need to set word 4 of IOCB here | |
3643 | */ | |
3644 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; | |
acd6859b JS |
3645 | |
3646 | return 0; | |
3647 | err: | |
96f7077f JS |
3648 | if (lpfc_cmd->seg_cnt) |
3649 | scsi_dma_unmap(scsi_cmnd); | |
3650 | if (lpfc_cmd->prot_seg_cnt) | |
3651 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(scsi_cmnd), | |
3652 | scsi_prot_sg_count(scsi_cmnd), | |
3653 | scsi_cmnd->sc_data_direction); | |
3654 | ||
acd6859b | 3655 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, |
96f7077f JS |
3656 | "9084 Cannot setup S/G List for HBA" |
3657 | "IO segs %d/%d SGL %d SCSI %d: %d %d\n", | |
3658 | lpfc_cmd->seg_cnt, lpfc_cmd->prot_seg_cnt, | |
3659 | phba->cfg_total_seg_cnt, phba->cfg_sg_seg_cnt, | |
3660 | prot_group_type, num_sge); | |
3661 | ||
3662 | lpfc_cmd->seg_cnt = 0; | |
3663 | lpfc_cmd->prot_seg_cnt = 0; | |
acd6859b JS |
3664 | return 1; |
3665 | } | |
3666 | ||
3772a991 JS |
3667 | /** |
3668 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer | |
3669 | * @phba: The Hba for which this call is being executed. | |
3670 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
3671 | * | |
3672 | * This routine wraps the actual DMA mapping function pointer from the | |
3673 | * lpfc_hba struct. | |
3674 | * | |
3675 | * Return codes: | |
6c8eea54 JS |
3676 | * 1 - Error |
3677 | * 0 - Success | |
3772a991 JS |
3678 | **/ |
3679 | static inline int | |
3680 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
3681 | { | |
3682 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); | |
3683 | } | |
3684 | ||
acd6859b JS |
3685 | /** |
3686 | * lpfc_bg_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer | |
3687 | * using BlockGuard. | |
3688 | * @phba: The Hba for which this call is being executed. | |
3689 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
3690 | * | |
3691 | * This routine wraps the actual DMA mapping function pointer from the | |
3692 | * lpfc_hba struct. | |
3693 | * | |
3694 | * Return codes: | |
3695 | * 1 - Error | |
3696 | * 0 - Success | |
3697 | **/ | |
3698 | static inline int | |
3699 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
3700 | { | |
3701 | return phba->lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); | |
3702 | } | |
3703 | ||
ea2151b4 | 3704 | /** |
3621a710 | 3705 | * lpfc_send_scsi_error_event - Posts an event when there is SCSI error |
ea2151b4 JS |
3706 | * @phba: Pointer to hba context object. |
3707 | * @vport: Pointer to vport object. | |
3708 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. | |
3709 | * @rsp_iocb: Pointer to response iocb object which reported error. | |
3710 | * | |
3711 | * This function posts an event when there is a SCSI command reporting | |
3712 | * error from the scsi device. | |
3713 | **/ | |
3714 | static void | |
3715 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, | |
3716 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { | |
3717 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; | |
3718 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; | |
3719 | uint32_t resp_info = fcprsp->rspStatus2; | |
3720 | uint32_t scsi_status = fcprsp->rspStatus3; | |
3721 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; | |
3722 | struct lpfc_fast_path_event *fast_path_evt = NULL; | |
3723 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; | |
3724 | unsigned long flags; | |
3725 | ||
5989b8d4 JS |
3726 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
3727 | return; | |
3728 | ||
ea2151b4 JS |
3729 | /* If there is queuefull or busy condition send a scsi event */ |
3730 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || | |
3731 | (cmnd->result == SAM_STAT_BUSY)) { | |
3732 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
3733 | if (!fast_path_evt) | |
3734 | return; | |
3735 | fast_path_evt->un.scsi_evt.event_type = | |
3736 | FC_REG_SCSI_EVENT; | |
3737 | fast_path_evt->un.scsi_evt.subcategory = | |
3738 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? | |
3739 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; | |
3740 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; | |
3741 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, | |
3742 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
3743 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, | |
3744 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
3745 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && | |
3746 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { | |
3747 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
3748 | if (!fast_path_evt) | |
3749 | return; | |
3750 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = | |
3751 | FC_REG_SCSI_EVENT; | |
3752 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = | |
3753 | LPFC_EVENT_CHECK_COND; | |
3754 | fast_path_evt->un.check_cond_evt.scsi_event.lun = | |
3755 | cmnd->device->lun; | |
3756 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, | |
3757 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
3758 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, | |
3759 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
3760 | fast_path_evt->un.check_cond_evt.sense_key = | |
3761 | cmnd->sense_buffer[2] & 0xf; | |
3762 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; | |
3763 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; | |
3764 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && | |
3765 | fcpi_parm && | |
3766 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || | |
3767 | ((scsi_status == SAM_STAT_GOOD) && | |
3768 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { | |
3769 | /* | |
3770 | * If status is good or resid does not match with fcp_param and | |
3771 | * there is valid fcpi_parm, then there is a read_check error | |
3772 | */ | |
3773 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
3774 | if (!fast_path_evt) | |
3775 | return; | |
3776 | fast_path_evt->un.read_check_error.header.event_type = | |
3777 | FC_REG_FABRIC_EVENT; | |
3778 | fast_path_evt->un.read_check_error.header.subcategory = | |
3779 | LPFC_EVENT_FCPRDCHKERR; | |
3780 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, | |
3781 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
3782 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, | |
3783 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
3784 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; | |
3785 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; | |
3786 | fast_path_evt->un.read_check_error.fcpiparam = | |
3787 | fcpi_parm; | |
3788 | } else | |
3789 | return; | |
3790 | ||
3791 | fast_path_evt->vport = vport; | |
3792 | spin_lock_irqsave(&phba->hbalock, flags); | |
3793 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); | |
3794 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
3795 | lpfc_worker_wake_up(phba); | |
3796 | return; | |
3797 | } | |
9bad7671 JS |
3798 | |
3799 | /** | |
f1126688 | 3800 | * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev |
3772a991 | 3801 | * @phba: The HBA for which this call is being executed. |
9bad7671 JS |
3802 | * @psb: The scsi buffer which is going to be un-mapped. |
3803 | * | |
3804 | * This routine does DMA un-mapping of scatter gather list of scsi command | |
3772a991 | 3805 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
9bad7671 | 3806 | **/ |
bcf4dbfa | 3807 | static void |
f1126688 | 3808 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
bcf4dbfa JS |
3809 | { |
3810 | /* | |
3811 | * There are only two special cases to consider. (1) the scsi command | |
3812 | * requested scatter-gather usage or (2) the scsi command allocated | |
3813 | * a request buffer, but did not request use_sg. There is a third | |
3814 | * case, but it does not require resource deallocation. | |
3815 | */ | |
a0b4f78f FT |
3816 | if (psb->seg_cnt > 0) |
3817 | scsi_dma_unmap(psb->pCmd); | |
e2a0a9d6 JS |
3818 | if (psb->prot_seg_cnt > 0) |
3819 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), | |
3820 | scsi_prot_sg_count(psb->pCmd), | |
3821 | psb->pCmd->sc_data_direction); | |
bcf4dbfa JS |
3822 | } |
3823 | ||
9bad7671 | 3824 | /** |
3621a710 | 3825 | * lpfc_handler_fcp_err - FCP response handler |
9bad7671 JS |
3826 | * @vport: The virtual port for which this call is being executed. |
3827 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | |
3828 | * @rsp_iocb: The response IOCB which contains FCP error. | |
3829 | * | |
3830 | * This routine is called to process response IOCB with status field | |
3831 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command | |
3832 | * based upon SCSI and FCP error. | |
3833 | **/ | |
dea3101e | 3834 | static void |
2e0fef85 JS |
3835 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
3836 | struct lpfc_iocbq *rsp_iocb) | |
dea3101e | 3837 | { |
3838 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; | |
3839 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; | |
3840 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; | |
7054a606 | 3841 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
dea3101e | 3842 | uint32_t resp_info = fcprsp->rspStatus2; |
3843 | uint32_t scsi_status = fcprsp->rspStatus3; | |
c7743956 | 3844 | uint32_t *lp; |
dea3101e | 3845 | uint32_t host_status = DID_OK; |
3846 | uint32_t rsplen = 0; | |
c7743956 | 3847 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
dea3101e | 3848 | |
ea2151b4 | 3849 | |
dea3101e | 3850 | /* |
3851 | * If this is a task management command, there is no | |
3852 | * scsi packet associated with this lpfc_cmd. The driver | |
3853 | * consumes it. | |
3854 | */ | |
3855 | if (fcpcmd->fcpCntl2) { | |
3856 | scsi_status = 0; | |
3857 | goto out; | |
3858 | } | |
3859 | ||
6a9c52cf JS |
3860 | if (resp_info & RSP_LEN_VALID) { |
3861 | rsplen = be32_to_cpu(fcprsp->rspRspLen); | |
e40a02c1 | 3862 | if (rsplen != 0 && rsplen != 4 && rsplen != 8) { |
6a9c52cf JS |
3863 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3864 | "2719 Invalid response length: " | |
3865 | "tgt x%x lun x%x cmnd x%x rsplen x%x\n", | |
3866 | cmnd->device->id, | |
3867 | cmnd->device->lun, cmnd->cmnd[0], | |
3868 | rsplen); | |
3869 | host_status = DID_ERROR; | |
3870 | goto out; | |
3871 | } | |
e40a02c1 JS |
3872 | if (fcprsp->rspInfo3 != RSP_NO_FAILURE) { |
3873 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3874 | "2757 Protocol failure detected during " | |
3875 | "processing of FCP I/O op: " | |
3876 | "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n", | |
3877 | cmnd->device->id, | |
3878 | cmnd->device->lun, cmnd->cmnd[0], | |
3879 | fcprsp->rspInfo3); | |
3880 | host_status = DID_ERROR; | |
3881 | goto out; | |
3882 | } | |
6a9c52cf JS |
3883 | } |
3884 | ||
c7743956 JS |
3885 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
3886 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); | |
3887 | if (snslen > SCSI_SENSE_BUFFERSIZE) | |
3888 | snslen = SCSI_SENSE_BUFFERSIZE; | |
3889 | ||
3890 | if (resp_info & RSP_LEN_VALID) | |
3891 | rsplen = be32_to_cpu(fcprsp->rspRspLen); | |
3892 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); | |
3893 | } | |
3894 | lp = (uint32_t *)cmnd->sense_buffer; | |
3895 | ||
aa1c7ee7 JS |
3896 | /* special handling for under run conditions */ |
3897 | if (!scsi_status && (resp_info & RESID_UNDER)) { | |
3898 | /* don't log under runs if fcp set... */ | |
3899 | if (vport->cfg_log_verbose & LOG_FCP) | |
3900 | logit = LOG_FCP_ERROR; | |
3901 | /* unless operator says so */ | |
3902 | if (vport->cfg_log_verbose & LOG_FCP_UNDER) | |
3903 | logit = LOG_FCP_UNDER; | |
3904 | } | |
c7743956 | 3905 | |
e8b62011 | 3906 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
e2a0a9d6 | 3907 | "9024 FCP command x%x failed: x%x SNS x%x x%x " |
e8b62011 JS |
3908 | "Data: x%x x%x x%x x%x x%x\n", |
3909 | cmnd->cmnd[0], scsi_status, | |
3910 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, | |
3911 | be32_to_cpu(fcprsp->rspResId), | |
3912 | be32_to_cpu(fcprsp->rspSnsLen), | |
3913 | be32_to_cpu(fcprsp->rspRspLen), | |
3914 | fcprsp->rspInfo3); | |
dea3101e | 3915 | |
a0b4f78f | 3916 | scsi_set_resid(cmnd, 0); |
dea3101e | 3917 | if (resp_info & RESID_UNDER) { |
a0b4f78f | 3918 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
dea3101e | 3919 | |
73d91e50 | 3920 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP_UNDER, |
e2a0a9d6 | 3921 | "9025 FCP Read Underrun, expected %d, " |
e8b62011 JS |
3922 | "residual %d Data: x%x x%x x%x\n", |
3923 | be32_to_cpu(fcpcmd->fcpDl), | |
3924 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], | |
3925 | cmnd->underflow); | |
dea3101e | 3926 | |
7054a606 JS |
3927 | /* |
3928 | * If there is an under run check if under run reported by | |
3929 | * storage array is same as the under run reported by HBA. | |
3930 | * If this is not same, there is a dropped frame. | |
3931 | */ | |
3932 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && | |
3933 | fcpi_parm && | |
a0b4f78f | 3934 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
e8b62011 JS |
3935 | lpfc_printf_vlog(vport, KERN_WARNING, |
3936 | LOG_FCP | LOG_FCP_ERROR, | |
e2a0a9d6 | 3937 | "9026 FCP Read Check Error " |
e8b62011 JS |
3938 | "and Underrun Data: x%x x%x x%x x%x\n", |
3939 | be32_to_cpu(fcpcmd->fcpDl), | |
3940 | scsi_get_resid(cmnd), fcpi_parm, | |
3941 | cmnd->cmnd[0]); | |
a0b4f78f | 3942 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
7054a606 JS |
3943 | host_status = DID_ERROR; |
3944 | } | |
dea3101e | 3945 | /* |
3946 | * The cmnd->underflow is the minimum number of bytes that must | |
25985edc | 3947 | * be transferred for this command. Provided a sense condition |
dea3101e | 3948 | * is not present, make sure the actual amount transferred is at |
3949 | * least the underflow value or fail. | |
3950 | */ | |
3951 | if (!(resp_info & SNS_LEN_VALID) && | |
3952 | (scsi_status == SAM_STAT_GOOD) && | |
a0b4f78f FT |
3953 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
3954 | < cmnd->underflow)) { | |
e8b62011 | 3955 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
e2a0a9d6 | 3956 | "9027 FCP command x%x residual " |
e8b62011 JS |
3957 | "underrun converted to error " |
3958 | "Data: x%x x%x x%x\n", | |
66dbfbe6 | 3959 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
e8b62011 | 3960 | scsi_get_resid(cmnd), cmnd->underflow); |
dea3101e | 3961 | host_status = DID_ERROR; |
3962 | } | |
3963 | } else if (resp_info & RESID_OVER) { | |
e8b62011 | 3964 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
e2a0a9d6 | 3965 | "9028 FCP command x%x residual overrun error. " |
e4e74273 | 3966 | "Data: x%x x%x\n", cmnd->cmnd[0], |
e8b62011 | 3967 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); |
dea3101e | 3968 | host_status = DID_ERROR; |
3969 | ||
3970 | /* | |
3971 | * Check SLI validation that all the transfer was actually done | |
26373d23 | 3972 | * (fcpi_parm should be zero). Apply check only to reads. |
dea3101e | 3973 | */ |
26373d23 | 3974 | } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { |
e8b62011 | 3975 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
26373d23 | 3976 | "9029 FCP Read Check Error Data: " |
eee8877e | 3977 | "x%x x%x x%x x%x x%x\n", |
e8b62011 JS |
3978 | be32_to_cpu(fcpcmd->fcpDl), |
3979 | be32_to_cpu(fcprsp->rspResId), | |
eee8877e JS |
3980 | fcpi_parm, cmnd->cmnd[0], scsi_status); |
3981 | switch (scsi_status) { | |
3982 | case SAM_STAT_GOOD: | |
3983 | case SAM_STAT_CHECK_CONDITION: | |
3984 | /* Fabric dropped a data frame. Fail any successful | |
3985 | * command in which we detected dropped frames. | |
3986 | * A status of good or some check conditions could | |
3987 | * be considered a successful command. | |
3988 | */ | |
3989 | host_status = DID_ERROR; | |
3990 | break; | |
3991 | } | |
a0b4f78f | 3992 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
dea3101e | 3993 | } |
3994 | ||
3995 | out: | |
3996 | cmnd->result = ScsiResult(host_status, scsi_status); | |
ea2151b4 | 3997 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
dea3101e | 3998 | } |
3999 | ||
9bad7671 | 4000 | /** |
3621a710 | 4001 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
9bad7671 JS |
4002 | * @phba: The Hba for which this call is being executed. |
4003 | * @pIocbIn: The command IOCBQ for the scsi cmnd. | |
3772a991 | 4004 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
9bad7671 JS |
4005 | * |
4006 | * This routine assigns scsi command result by looking into response IOCB | |
4007 | * status field appropriately. This routine handles QUEUE FULL condition as | |
4008 | * well by ramping down device queue depth. | |
4009 | **/ | |
dea3101e | 4010 | static void |
4011 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, | |
4012 | struct lpfc_iocbq *pIocbOut) | |
4013 | { | |
4014 | struct lpfc_scsi_buf *lpfc_cmd = | |
4015 | (struct lpfc_scsi_buf *) pIocbIn->context1; | |
2e0fef85 | 4016 | struct lpfc_vport *vport = pIocbIn->vport; |
dea3101e | 4017 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
4018 | struct lpfc_nodelist *pnode = rdata->pnode; | |
75baf696 | 4019 | struct scsi_cmnd *cmd; |
445cf4f4 | 4020 | int result; |
a257bf90 | 4021 | struct scsi_device *tmp_sdev; |
5ffc266e | 4022 | int depth; |
fa61a54e | 4023 | unsigned long flags; |
ea2151b4 | 4024 | struct lpfc_fast_path_event *fast_path_evt; |
75baf696 | 4025 | struct Scsi_Host *shost; |
a257bf90 | 4026 | uint32_t queue_depth, scsi_id; |
73d91e50 | 4027 | uint32_t logit = LOG_FCP; |
dea3101e | 4028 | |
75baf696 JS |
4029 | /* Sanity check on return of outstanding command */ |
4030 | if (!(lpfc_cmd->pCmd)) | |
4031 | return; | |
4032 | cmd = lpfc_cmd->pCmd; | |
4033 | shost = cmd->device->host; | |
4034 | ||
e3d2b802 | 4035 | lpfc_cmd->result = (pIocbOut->iocb.un.ulpWord[4] & IOERR_PARAM_MASK); |
dea3101e | 4036 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; |
341af102 JS |
4037 | /* pick up SLI4 exhange busy status from HBA */ |
4038 | lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY; | |
4039 | ||
9a6b09c0 JS |
4040 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
4041 | if (lpfc_cmd->prot_data_type) { | |
4042 | struct scsi_dif_tuple *src = NULL; | |
4043 | ||
4044 | src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment; | |
4045 | /* | |
4046 | * Used to restore any changes to protection | |
4047 | * data for error injection. | |
4048 | */ | |
4049 | switch (lpfc_cmd->prot_data_type) { | |
4050 | case LPFC_INJERR_REFTAG: | |
4051 | src->ref_tag = | |
4052 | lpfc_cmd->prot_data; | |
4053 | break; | |
4054 | case LPFC_INJERR_APPTAG: | |
4055 | src->app_tag = | |
4056 | (uint16_t)lpfc_cmd->prot_data; | |
4057 | break; | |
4058 | case LPFC_INJERR_GUARD: | |
4059 | src->guard_tag = | |
4060 | (uint16_t)lpfc_cmd->prot_data; | |
4061 | break; | |
4062 | default: | |
4063 | break; | |
4064 | } | |
4065 | ||
4066 | lpfc_cmd->prot_data = 0; | |
4067 | lpfc_cmd->prot_data_type = 0; | |
4068 | lpfc_cmd->prot_data_segment = NULL; | |
4069 | } | |
4070 | #endif | |
109f6ed0 JS |
4071 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
4072 | atomic_dec(&pnode->cmd_pending); | |
dea3101e | 4073 | |
4074 | if (lpfc_cmd->status) { | |
4075 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && | |
4076 | (lpfc_cmd->result & IOERR_DRVR_MASK)) | |
4077 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; | |
4078 | else if (lpfc_cmd->status >= IOSTAT_CNT) | |
4079 | lpfc_cmd->status = IOSTAT_DEFAULT; | |
aa1c7ee7 JS |
4080 | if (lpfc_cmd->status == IOSTAT_FCP_RSP_ERROR && |
4081 | !lpfc_cmd->fcp_rsp->rspStatus3 && | |
4082 | (lpfc_cmd->fcp_rsp->rspStatus2 & RESID_UNDER) && | |
4083 | !(vport->cfg_log_verbose & LOG_FCP_UNDER)) | |
73d91e50 JS |
4084 | logit = 0; |
4085 | else | |
4086 | logit = LOG_FCP | LOG_FCP_UNDER; | |
4087 | lpfc_printf_vlog(vport, KERN_WARNING, logit, | |
4088 | "9030 FCP cmd x%x failed <%d/%d> " | |
5a0d80fc JS |
4089 | "status: x%x result: x%x " |
4090 | "sid: x%x did: x%x oxid: x%x " | |
4091 | "Data: x%x x%x\n", | |
73d91e50 JS |
4092 | cmd->cmnd[0], |
4093 | cmd->device ? cmd->device->id : 0xffff, | |
4094 | cmd->device ? cmd->device->lun : 0xffff, | |
4095 | lpfc_cmd->status, lpfc_cmd->result, | |
3bf41ba9 JS |
4096 | vport->fc_myDID, |
4097 | (pnode) ? pnode->nlp_DID : 0, | |
5a0d80fc JS |
4098 | phba->sli_rev == LPFC_SLI_REV4 ? |
4099 | lpfc_cmd->cur_iocbq.sli4_xritag : 0xffff, | |
73d91e50 JS |
4100 | pIocbOut->iocb.ulpContext, |
4101 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); | |
dea3101e | 4102 | |
4103 | switch (lpfc_cmd->status) { | |
4104 | case IOSTAT_FCP_RSP_ERROR: | |
4105 | /* Call FCP RSP handler to determine result */ | |
2e0fef85 | 4106 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
dea3101e | 4107 | break; |
4108 | case IOSTAT_NPORT_BSY: | |
4109 | case IOSTAT_FABRIC_BSY: | |
0f1f53a7 | 4110 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
ea2151b4 JS |
4111 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
4112 | if (!fast_path_evt) | |
4113 | break; | |
4114 | fast_path_evt->un.fabric_evt.event_type = | |
4115 | FC_REG_FABRIC_EVENT; | |
4116 | fast_path_evt->un.fabric_evt.subcategory = | |
4117 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? | |
4118 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; | |
4119 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { | |
4120 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, | |
4121 | &pnode->nlp_portname, | |
4122 | sizeof(struct lpfc_name)); | |
4123 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, | |
4124 | &pnode->nlp_nodename, | |
4125 | sizeof(struct lpfc_name)); | |
4126 | } | |
4127 | fast_path_evt->vport = vport; | |
4128 | fast_path_evt->work_evt.evt = | |
4129 | LPFC_EVT_FASTPATH_MGMT_EVT; | |
4130 | spin_lock_irqsave(&phba->hbalock, flags); | |
4131 | list_add_tail(&fast_path_evt->work_evt.evt_listp, | |
4132 | &phba->work_list); | |
4133 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
4134 | lpfc_worker_wake_up(phba); | |
dea3101e | 4135 | break; |
92d7f7b0 | 4136 | case IOSTAT_LOCAL_REJECT: |
1151e3ec | 4137 | case IOSTAT_REMOTE_STOP: |
ab56dc2e JS |
4138 | if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR || |
4139 | lpfc_cmd->result == | |
4140 | IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR || | |
4141 | lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR || | |
4142 | lpfc_cmd->result == | |
4143 | IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) { | |
4144 | cmd->result = ScsiResult(DID_NO_CONNECT, 0); | |
4145 | break; | |
4146 | } | |
d7c255b2 | 4147 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
92d7f7b0 | 4148 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
b92938b4 JS |
4149 | lpfc_cmd->result == IOERR_ABORT_REQUESTED || |
4150 | lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) { | |
92d7f7b0 | 4151 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
58da1ffb | 4152 | break; |
e2a0a9d6 | 4153 | } |
e2a0a9d6 JS |
4154 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || |
4155 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && | |
4156 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { | |
4157 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { | |
4158 | /* | |
4159 | * This is a response for a BG enabled | |
4160 | * cmd. Parse BG error | |
4161 | */ | |
4162 | lpfc_parse_bg_err(phba, lpfc_cmd, | |
4163 | pIocbOut); | |
4164 | break; | |
4165 | } else { | |
4166 | lpfc_printf_vlog(vport, KERN_WARNING, | |
4167 | LOG_BG, | |
4168 | "9031 non-zero BGSTAT " | |
6a9c52cf | 4169 | "on unprotected cmd\n"); |
e2a0a9d6 JS |
4170 | } |
4171 | } | |
1151e3ec JS |
4172 | if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP) |
4173 | && (phba->sli_rev == LPFC_SLI_REV4) | |
4174 | && (pnode && NLP_CHK_NODE_ACT(pnode))) { | |
4175 | /* This IO was aborted by the target, we don't | |
4176 | * know the rxid and because we did not send the | |
4177 | * ABTS we cannot generate and RRQ. | |
4178 | */ | |
4179 | lpfc_set_rrq_active(phba, pnode, | |
ee0f4fe1 JS |
4180 | lpfc_cmd->cur_iocbq.sli4_lxritag, |
4181 | 0, 0); | |
1151e3ec | 4182 | } |
e2a0a9d6 | 4183 | /* else: fall through */ |
dea3101e | 4184 | default: |
4185 | cmd->result = ScsiResult(DID_ERROR, 0); | |
4186 | break; | |
4187 | } | |
4188 | ||
58da1ffb | 4189 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
19a7b4ae | 4190 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
0f1f53a7 JS |
4191 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
4192 | SAM_STAT_BUSY); | |
ab56dc2e | 4193 | } else |
dea3101e | 4194 | cmd->result = ScsiResult(DID_OK, 0); |
dea3101e | 4195 | |
4196 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { | |
4197 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; | |
4198 | ||
e8b62011 JS |
4199 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
4200 | "0710 Iodone <%d/%d> cmd %p, error " | |
4201 | "x%x SNS x%x x%x Data: x%x x%x\n", | |
4202 | cmd->device->id, cmd->device->lun, cmd, | |
4203 | cmd->result, *lp, *(lp + 3), cmd->retries, | |
4204 | scsi_get_resid(cmd)); | |
dea3101e | 4205 | } |
4206 | ||
ea2151b4 | 4207 | lpfc_update_stats(phba, lpfc_cmd); |
445cf4f4 | 4208 | result = cmd->result; |
977b5a0a JS |
4209 | if (vport->cfg_max_scsicmpl_time && |
4210 | time_after(jiffies, lpfc_cmd->start_time + | |
4211 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { | |
a257bf90 | 4212 | spin_lock_irqsave(shost->host_lock, flags); |
109f6ed0 JS |
4213 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
4214 | if (pnode->cmd_qdepth > | |
4215 | atomic_read(&pnode->cmd_pending) && | |
4216 | (atomic_read(&pnode->cmd_pending) > | |
4217 | LPFC_MIN_TGT_QDEPTH) && | |
4218 | ((cmd->cmnd[0] == READ_10) || | |
4219 | (cmd->cmnd[0] == WRITE_10))) | |
4220 | pnode->cmd_qdepth = | |
4221 | atomic_read(&pnode->cmd_pending); | |
4222 | ||
4223 | pnode->last_change_time = jiffies; | |
4224 | } | |
a257bf90 | 4225 | spin_unlock_irqrestore(shost->host_lock, flags); |
109f6ed0 | 4226 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
7dc517df | 4227 | if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) && |
977b5a0a | 4228 | time_after(jiffies, pnode->last_change_time + |
109f6ed0 | 4229 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
a257bf90 | 4230 | spin_lock_irqsave(shost->host_lock, flags); |
7dc517df JS |
4231 | depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT |
4232 | / 100; | |
4233 | depth = depth ? depth : 1; | |
4234 | pnode->cmd_qdepth += depth; | |
4235 | if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth) | |
4236 | pnode->cmd_qdepth = vport->cfg_tgt_queue_depth; | |
109f6ed0 | 4237 | pnode->last_change_time = jiffies; |
a257bf90 | 4238 | spin_unlock_irqrestore(shost->host_lock, flags); |
109f6ed0 | 4239 | } |
977b5a0a JS |
4240 | } |
4241 | ||
1dcb58e5 | 4242 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
a257bf90 JS |
4243 | |
4244 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ | |
4245 | queue_depth = cmd->device->queue_depth; | |
4246 | scsi_id = cmd->device->id; | |
0bd4ca25 JSEC |
4247 | cmd->scsi_done(cmd); |
4248 | ||
b808608b | 4249 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
876dd7d0 | 4250 | spin_lock_irqsave(&phba->hbalock, flags); |
92e3af66 | 4251 | lpfc_cmd->pCmd = NULL; |
876dd7d0 | 4252 | spin_unlock_irqrestore(&phba->hbalock, flags); |
92e3af66 | 4253 | |
fa61a54e JS |
4254 | /* |
4255 | * If there is a thread waiting for command completion | |
4256 | * wake up the thread. | |
4257 | */ | |
a257bf90 | 4258 | spin_lock_irqsave(shost->host_lock, flags); |
fa61a54e JS |
4259 | if (lpfc_cmd->waitq) |
4260 | wake_up(lpfc_cmd->waitq); | |
a257bf90 | 4261 | spin_unlock_irqrestore(shost->host_lock, flags); |
b808608b JW |
4262 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
4263 | return; | |
4264 | } | |
4265 | ||
92d7f7b0 | 4266 | if (!result) |
a257bf90 | 4267 | lpfc_rampup_queue_depth(vport, queue_depth); |
92d7f7b0 | 4268 | |
445cf4f4 JSEC |
4269 | /* |
4270 | * Check for queue full. If the lun is reporting queue full, then | |
4271 | * back off the lun queue depth to prevent target overloads. | |
4272 | */ | |
58da1ffb JS |
4273 | if (result == SAM_STAT_TASK_SET_FULL && pnode && |
4274 | NLP_CHK_NODE_ACT(pnode)) { | |
a257bf90 JS |
4275 | shost_for_each_device(tmp_sdev, shost) { |
4276 | if (tmp_sdev->id != scsi_id) | |
445cf4f4 JSEC |
4277 | continue; |
4278 | depth = scsi_track_queue_full(tmp_sdev, | |
5ffc266e JS |
4279 | tmp_sdev->queue_depth-1); |
4280 | if (depth <= 0) | |
4281 | continue; | |
e8b62011 JS |
4282 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
4283 | "0711 detected queue full - lun queue " | |
4284 | "depth adjusted to %d.\n", depth); | |
ea2151b4 | 4285 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
5ffc266e JS |
4286 | pnode, |
4287 | tmp_sdev->lun, | |
4288 | depth+1, depth); | |
445cf4f4 JSEC |
4289 | } |
4290 | } | |
4291 | ||
876dd7d0 | 4292 | spin_lock_irqsave(&phba->hbalock, flags); |
92e3af66 | 4293 | lpfc_cmd->pCmd = NULL; |
876dd7d0 | 4294 | spin_unlock_irqrestore(&phba->hbalock, flags); |
92e3af66 | 4295 | |
fa61a54e JS |
4296 | /* |
4297 | * If there is a thread waiting for command completion | |
4298 | * wake up the thread. | |
4299 | */ | |
a257bf90 | 4300 | spin_lock_irqsave(shost->host_lock, flags); |
fa61a54e JS |
4301 | if (lpfc_cmd->waitq) |
4302 | wake_up(lpfc_cmd->waitq); | |
a257bf90 | 4303 | spin_unlock_irqrestore(shost->host_lock, flags); |
fa61a54e | 4304 | |
0bd4ca25 | 4305 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
dea3101e | 4306 | } |
4307 | ||
34b02dcd | 4308 | /** |
3621a710 | 4309 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
34b02dcd JS |
4310 | * @data: A pointer to the immediate command data portion of the IOCB. |
4311 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. | |
4312 | * | |
4313 | * The routine copies the entire FCP command from @fcp_cmnd to @data while | |
4314 | * byte swapping the data to big endian format for transmission on the wire. | |
4315 | **/ | |
4316 | static void | |
4317 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) | |
4318 | { | |
4319 | int i, j; | |
4320 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); | |
4321 | i += sizeof(uint32_t), j++) { | |
4322 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); | |
4323 | } | |
4324 | } | |
4325 | ||
9bad7671 | 4326 | /** |
f1126688 | 4327 | * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit |
9bad7671 JS |
4328 | * @vport: The virtual port for which this call is being executed. |
4329 | * @lpfc_cmd: The scsi command which needs to send. | |
4330 | * @pnode: Pointer to lpfc_nodelist. | |
4331 | * | |
4332 | * This routine initializes fcp_cmnd and iocb data structure from scsi command | |
3772a991 | 4333 | * to transfer for device with SLI3 interface spec. |
9bad7671 | 4334 | **/ |
dea3101e | 4335 | static void |
f1126688 | 4336 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
2e0fef85 | 4337 | struct lpfc_nodelist *pnode) |
dea3101e | 4338 | { |
2e0fef85 | 4339 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4340 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
4341 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
4342 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
4343 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); | |
4344 | int datadir = scsi_cmnd->sc_data_direction; | |
7e2b19fb | 4345 | char tag[2]; |
027140ea JS |
4346 | uint8_t *ptr; |
4347 | bool sli4; | |
98bbf5f7 | 4348 | uint32_t fcpdl; |
dea3101e | 4349 | |
58da1ffb JS |
4350 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
4351 | return; | |
4352 | ||
dea3101e | 4353 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
69859dc4 JSEC |
4354 | /* clear task management bits */ |
4355 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; | |
dea3101e | 4356 | |
91886523 JSEC |
4357 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
4358 | &lpfc_cmd->fcp_cmnd->fcp_lun); | |
dea3101e | 4359 | |
027140ea JS |
4360 | ptr = &fcp_cmnd->fcpCdb[0]; |
4361 | memcpy(ptr, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); | |
4362 | if (scsi_cmnd->cmd_len < LPFC_FCP_CDB_LEN) { | |
4363 | ptr += scsi_cmnd->cmd_len; | |
4364 | memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); | |
4365 | } | |
4366 | ||
7e2b19fb JS |
4367 | if (scsi_populate_tag_msg(scsi_cmnd, tag)) { |
4368 | switch (tag[0]) { | |
dea3101e | 4369 | case HEAD_OF_QUEUE_TAG: |
4370 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; | |
4371 | break; | |
4372 | case ORDERED_QUEUE_TAG: | |
4373 | fcp_cmnd->fcpCntl1 = ORDERED_Q; | |
4374 | break; | |
4375 | default: | |
4376 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; | |
4377 | break; | |
4378 | } | |
4379 | } else | |
fe8f7f9c | 4380 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; |
dea3101e | 4381 | |
027140ea JS |
4382 | sli4 = (phba->sli_rev == LPFC_SLI_REV4); |
4383 | ||
dea3101e | 4384 | /* |
4385 | * There are three possibilities here - use scatter-gather segment, use | |
4386 | * the single mapping, or neither. Start the lpfc command prep by | |
4387 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
4388 | * data bde entry. | |
4389 | */ | |
a0b4f78f | 4390 | if (scsi_sg_count(scsi_cmnd)) { |
dea3101e | 4391 | if (datadir == DMA_TO_DEVICE) { |
4392 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; | |
182ba753 | 4393 | iocb_cmd->ulpPU = PARM_READ_CHECK; |
3cb01c57 JS |
4394 | if (vport->cfg_first_burst_size && |
4395 | (pnode->nlp_flag & NLP_FIRSTBURST)) { | |
98bbf5f7 JS |
4396 | fcpdl = scsi_bufflen(scsi_cmnd); |
4397 | if (fcpdl < vport->cfg_first_burst_size) | |
4398 | piocbq->iocb.un.fcpi.fcpi_XRdy = fcpdl; | |
4399 | else | |
4400 | piocbq->iocb.un.fcpi.fcpi_XRdy = | |
4401 | vport->cfg_first_burst_size; | |
3cb01c57 | 4402 | } |
dea3101e | 4403 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
4404 | phba->fc4OutputRequests++; | |
4405 | } else { | |
4406 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; | |
4407 | iocb_cmd->ulpPU = PARM_READ_CHECK; | |
dea3101e | 4408 | fcp_cmnd->fcpCntl3 = READ_DATA; |
4409 | phba->fc4InputRequests++; | |
4410 | } | |
4411 | } else { | |
4412 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; | |
4413 | iocb_cmd->un.fcpi.fcpi_parm = 0; | |
4414 | iocb_cmd->ulpPU = 0; | |
4415 | fcp_cmnd->fcpCntl3 = 0; | |
4416 | phba->fc4ControlRequests++; | |
4417 | } | |
e2a0a9d6 JS |
4418 | if (phba->sli_rev == 3 && |
4419 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) | |
34b02dcd | 4420 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
dea3101e | 4421 | /* |
4422 | * Finish initializing those IOCB fields that are independent | |
4423 | * of the scsi_cmnd request_buffer | |
4424 | */ | |
4425 | piocbq->iocb.ulpContext = pnode->nlp_rpi; | |
027140ea | 4426 | if (sli4) |
6d368e53 JS |
4427 | piocbq->iocb.ulpContext = |
4428 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]; | |
dea3101e | 4429 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) |
4430 | piocbq->iocb.ulpFCP2Rcvy = 1; | |
09372820 JS |
4431 | else |
4432 | piocbq->iocb.ulpFCP2Rcvy = 0; | |
dea3101e | 4433 | |
4434 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); | |
4435 | piocbq->context1 = lpfc_cmd; | |
4436 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; | |
4437 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; | |
2e0fef85 | 4438 | piocbq->vport = vport; |
dea3101e | 4439 | } |
4440 | ||
da0436e9 | 4441 | /** |
6d368e53 | 4442 | * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit |
9bad7671 JS |
4443 | * @vport: The virtual port for which this call is being executed. |
4444 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | |
4445 | * @lun: Logical unit number. | |
4446 | * @task_mgmt_cmd: SCSI task management command. | |
4447 | * | |
3772a991 JS |
4448 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
4449 | * for device with SLI-3 interface spec. | |
9bad7671 JS |
4450 | * |
4451 | * Return codes: | |
4452 | * 0 - Error | |
4453 | * 1 - Success | |
4454 | **/ | |
dea3101e | 4455 | static int |
f1126688 | 4456 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
dea3101e | 4457 | struct lpfc_scsi_buf *lpfc_cmd, |
420b630d | 4458 | unsigned int lun, |
dea3101e | 4459 | uint8_t task_mgmt_cmd) |
4460 | { | |
dea3101e | 4461 | struct lpfc_iocbq *piocbq; |
4462 | IOCB_t *piocb; | |
4463 | struct fcp_cmnd *fcp_cmnd; | |
0b18ac42 | 4464 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
dea3101e | 4465 | struct lpfc_nodelist *ndlp = rdata->pnode; |
4466 | ||
58da1ffb JS |
4467 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
4468 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) | |
dea3101e | 4469 | return 0; |
dea3101e | 4470 | |
dea3101e | 4471 | piocbq = &(lpfc_cmd->cur_iocbq); |
2e0fef85 JS |
4472 | piocbq->vport = vport; |
4473 | ||
dea3101e | 4474 | piocb = &piocbq->iocb; |
4475 | ||
4476 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
34b02dcd JS |
4477 | /* Clear out any old data in the FCP command area */ |
4478 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); | |
4479 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); | |
dea3101e | 4480 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
e2a0a9d6 JS |
4481 | if (vport->phba->sli_rev == 3 && |
4482 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) | |
34b02dcd | 4483 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
dea3101e | 4484 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
dea3101e | 4485 | piocb->ulpContext = ndlp->nlp_rpi; |
6d368e53 JS |
4486 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
4487 | piocb->ulpContext = | |
4488 | vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; | |
4489 | } | |
dea3101e | 4490 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
4491 | piocb->ulpFCP2Rcvy = 1; | |
4492 | } | |
4493 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); | |
4494 | ||
4495 | /* ulpTimeout is only one byte */ | |
4496 | if (lpfc_cmd->timeout > 0xff) { | |
4497 | /* | |
4498 | * Do not timeout the command at the firmware level. | |
4499 | * The driver will provide the timeout mechanism. | |
4500 | */ | |
4501 | piocb->ulpTimeout = 0; | |
f1126688 | 4502 | } else |
dea3101e | 4503 | piocb->ulpTimeout = lpfc_cmd->timeout; |
da0436e9 | 4504 | |
f1126688 JS |
4505 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
4506 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); | |
3772a991 | 4507 | |
f1126688 | 4508 | return 1; |
3772a991 JS |
4509 | } |
4510 | ||
4511 | /** | |
25985edc | 4512 | * lpfc_scsi_api_table_setup - Set up scsi api function jump table |
3772a991 JS |
4513 | * @phba: The hba struct for which this call is being executed. |
4514 | * @dev_grp: The HBA PCI-Device group number. | |
4515 | * | |
4516 | * This routine sets up the SCSI interface API function jump table in @phba | |
4517 | * struct. | |
4518 | * Returns: 0 - success, -ENODEV - failure. | |
4519 | **/ | |
4520 | int | |
4521 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4522 | { | |
4523 | ||
f1126688 JS |
4524 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
4525 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; | |
f1126688 | 4526 | |
3772a991 JS |
4527 | switch (dev_grp) { |
4528 | case LPFC_PCI_DEV_LP: | |
4529 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; | |
4530 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; | |
acd6859b | 4531 | phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s3; |
3772a991 | 4532 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
19ca7609 | 4533 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3; |
3772a991 | 4534 | break; |
da0436e9 JS |
4535 | case LPFC_PCI_DEV_OC: |
4536 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; | |
4537 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; | |
acd6859b | 4538 | phba->lpfc_bg_scsi_prep_dma_buf = lpfc_bg_scsi_prep_dma_buf_s4; |
da0436e9 | 4539 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
19ca7609 | 4540 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4; |
da0436e9 | 4541 | break; |
3772a991 JS |
4542 | default: |
4543 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4544 | "1418 Invalid HBA PCI-device group: 0x%x\n", | |
4545 | dev_grp); | |
4546 | return -ENODEV; | |
4547 | break; | |
4548 | } | |
3772a991 | 4549 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; |
84d1b006 | 4550 | phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; |
3772a991 JS |
4551 | return 0; |
4552 | } | |
4553 | ||
9bad7671 | 4554 | /** |
3621a710 | 4555 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
9bad7671 JS |
4556 | * @phba: The Hba for which this call is being executed. |
4557 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. | |
4558 | * @rspiocbq: Pointer to lpfc_iocbq data structure. | |
4559 | * | |
4560 | * This routine is IOCB completion routine for device reset and target reset | |
4561 | * routine. This routine release scsi buffer associated with lpfc_cmd. | |
4562 | **/ | |
7054a606 JS |
4563 | static void |
4564 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, | |
4565 | struct lpfc_iocbq *cmdiocbq, | |
4566 | struct lpfc_iocbq *rspiocbq) | |
4567 | { | |
4568 | struct lpfc_scsi_buf *lpfc_cmd = | |
4569 | (struct lpfc_scsi_buf *) cmdiocbq->context1; | |
4570 | if (lpfc_cmd) | |
4571 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
4572 | return; | |
4573 | } | |
4574 | ||
9bad7671 | 4575 | /** |
3621a710 | 4576 | * lpfc_info - Info entry point of scsi_host_template data structure |
9bad7671 JS |
4577 | * @host: The scsi host for which this call is being executed. |
4578 | * | |
4579 | * This routine provides module information about hba. | |
4580 | * | |
4581 | * Reutrn code: | |
4582 | * Pointer to char - Success. | |
4583 | **/ | |
dea3101e | 4584 | const char * |
4585 | lpfc_info(struct Scsi_Host *host) | |
4586 | { | |
2e0fef85 JS |
4587 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
4588 | struct lpfc_hba *phba = vport->phba; | |
8b68cd52 | 4589 | int len, link_speed = 0; |
dea3101e | 4590 | static char lpfcinfobuf[384]; |
4591 | ||
4592 | memset(lpfcinfobuf,0,384); | |
4593 | if (phba && phba->pcidev){ | |
4594 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); | |
4595 | len = strlen(lpfcinfobuf); | |
4596 | snprintf(lpfcinfobuf + len, | |
4597 | 384-len, | |
4598 | " on PCI bus %02x device %02x irq %d", | |
4599 | phba->pcidev->bus->number, | |
4600 | phba->pcidev->devfn, | |
4601 | phba->pcidev->irq); | |
4602 | len = strlen(lpfcinfobuf); | |
4603 | if (phba->Port[0]) { | |
4604 | snprintf(lpfcinfobuf + len, | |
4605 | 384-len, | |
4606 | " port %s", | |
4607 | phba->Port); | |
4608 | } | |
65467b6b | 4609 | len = strlen(lpfcinfobuf); |
8b68cd52 JS |
4610 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
4611 | link_speed = lpfc_sli_port_speed_get(phba); | |
4612 | } else { | |
4613 | if (phba->sli4_hba.link_state.logical_speed) | |
4614 | link_speed = | |
4615 | phba->sli4_hba.link_state.logical_speed; | |
4616 | else | |
4617 | link_speed = phba->sli4_hba.link_state.speed; | |
65467b6b | 4618 | } |
8b68cd52 JS |
4619 | if (link_speed != 0) |
4620 | snprintf(lpfcinfobuf + len, 384-len, | |
4621 | " Logical Link Speed: %d Mbps", link_speed); | |
dea3101e | 4622 | } |
4623 | return lpfcinfobuf; | |
4624 | } | |
4625 | ||
9bad7671 | 4626 | /** |
3621a710 | 4627 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
9bad7671 JS |
4628 | * @phba: The Hba for which this call is being executed. |
4629 | * | |
4630 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. | |
4631 | * The default value of cfg_poll_tmo is 10 milliseconds. | |
4632 | **/ | |
875fbdfe JSEC |
4633 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
4634 | { | |
4635 | unsigned long poll_tmo_expires = | |
4636 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); | |
4637 | ||
0e9bb8d7 | 4638 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) |
875fbdfe JSEC |
4639 | mod_timer(&phba->fcp_poll_timer, |
4640 | poll_tmo_expires); | |
4641 | } | |
4642 | ||
9bad7671 | 4643 | /** |
3621a710 | 4644 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
9bad7671 JS |
4645 | * @phba: The Hba for which this call is being executed. |
4646 | * | |
4647 | * This routine starts the fcp_poll_timer of @phba. | |
4648 | **/ | |
875fbdfe JSEC |
4649 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
4650 | { | |
4651 | lpfc_poll_rearm_timer(phba); | |
4652 | } | |
4653 | ||
9bad7671 | 4654 | /** |
3621a710 | 4655 | * lpfc_poll_timeout - Restart polling timer |
9bad7671 JS |
4656 | * @ptr: Map to lpfc_hba data structure pointer. |
4657 | * | |
4658 | * This routine restarts fcp_poll timer, when FCP ring polling is enable | |
4659 | * and FCP Ring interrupt is disable. | |
4660 | **/ | |
4661 | ||
875fbdfe JSEC |
4662 | void lpfc_poll_timeout(unsigned long ptr) |
4663 | { | |
2e0fef85 | 4664 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
875fbdfe JSEC |
4665 | |
4666 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { | |
45ed1190 JS |
4667 | lpfc_sli_handle_fast_ring_event(phba, |
4668 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
4669 | ||
875fbdfe JSEC |
4670 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
4671 | lpfc_poll_rearm_timer(phba); | |
4672 | } | |
875fbdfe JSEC |
4673 | } |
4674 | ||
9bad7671 | 4675 | /** |
3621a710 | 4676 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
9bad7671 JS |
4677 | * @cmnd: Pointer to scsi_cmnd data structure. |
4678 | * @done: Pointer to done routine. | |
4679 | * | |
4680 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. | |
4681 | * This routine prepares an IOCB from scsi command and provides to firmware. | |
4682 | * The @done callback is invoked after driver finished processing the command. | |
4683 | * | |
4684 | * Return value : | |
4685 | * 0 - Success | |
4686 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. | |
4687 | **/ | |
dea3101e | 4688 | static int |
b9a7c631 | 4689 | lpfc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) |
dea3101e | 4690 | { |
2e0fef85 JS |
4691 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4692 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 4693 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
1c6f4ef5 | 4694 | struct lpfc_nodelist *ndlp; |
0bd4ca25 | 4695 | struct lpfc_scsi_buf *lpfc_cmd; |
19a7b4ae | 4696 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
19a7b4ae | 4697 | int err; |
dea3101e | 4698 | |
19a7b4ae JSEC |
4699 | err = fc_remote_port_chkready(rport); |
4700 | if (err) { | |
4701 | cmnd->result = err; | |
dea3101e | 4702 | goto out_fail_command; |
4703 | } | |
1c6f4ef5 | 4704 | ndlp = rdata->pnode; |
dea3101e | 4705 | |
bf08611b | 4706 | if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) && |
acd6859b | 4707 | (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED))) { |
e2a0a9d6 | 4708 | |
6a9c52cf JS |
4709 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4710 | "9058 BLKGRD: ERROR: rcvd protected cmd:%02x" | |
4711 | " op:%02x str=%s without registering for" | |
4712 | " BlockGuard - Rejecting command\n", | |
e2a0a9d6 JS |
4713 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), |
4714 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
4715 | goto out_fail_command; | |
4716 | } | |
4717 | ||
dea3101e | 4718 | /* |
19a7b4ae JSEC |
4719 | * Catch race where our node has transitioned, but the |
4720 | * transport is still transitioning. | |
dea3101e | 4721 | */ |
6b415f5d JS |
4722 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
4723 | goto out_tgt_busy; | |
7dc517df | 4724 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) |
3496343d | 4725 | goto out_tgt_busy; |
a93ce024 | 4726 | |
19ca7609 | 4727 | lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); |
dea3101e | 4728 | if (lpfc_cmd == NULL) { |
eaf15d5b | 4729 | lpfc_rampdown_queue_depth(phba); |
92d7f7b0 | 4730 | |
e8b62011 JS |
4731 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
4732 | "0707 driver's buffer pool is empty, " | |
4733 | "IO busied\n"); | |
dea3101e | 4734 | goto out_host_busy; |
4735 | } | |
4736 | ||
4737 | /* | |
4738 | * Store the midlayer's command structure for the completion phase | |
4739 | * and complete the command initialization. | |
4740 | */ | |
4741 | lpfc_cmd->pCmd = cmnd; | |
4742 | lpfc_cmd->rdata = rdata; | |
4743 | lpfc_cmd->timeout = 0; | |
977b5a0a | 4744 | lpfc_cmd->start_time = jiffies; |
dea3101e | 4745 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
dea3101e | 4746 | |
e2a0a9d6 | 4747 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
6a9c52cf | 4748 | if (vport->phba->cfg_enable_bg) { |
737d4248 JS |
4749 | lpfc_printf_vlog(vport, |
4750 | KERN_INFO, LOG_SCSI_CMD, | |
2613470a JS |
4751 | "9033 BLKGRD: rcvd %s cmd:x%x " |
4752 | "sector x%llx cnt %u pt %x\n", | |
4753 | dif_op_str[scsi_get_prot_op(cmnd)], | |
4754 | cmnd->cmnd[0], | |
4755 | (unsigned long long)scsi_get_lba(cmnd), | |
4756 | blk_rq_sectors(cmnd->request), | |
4757 | (cmnd->cmnd[1]>>5)); | |
6a9c52cf | 4758 | } |
e2a0a9d6 JS |
4759 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); |
4760 | } else { | |
6a9c52cf | 4761 | if (vport->phba->cfg_enable_bg) { |
737d4248 JS |
4762 | lpfc_printf_vlog(vport, |
4763 | KERN_INFO, LOG_SCSI_CMD, | |
2613470a JS |
4764 | "9038 BLKGRD: rcvd PROT_NORMAL cmd: " |
4765 | "x%x sector x%llx cnt %u pt %x\n", | |
4766 | cmnd->cmnd[0], | |
4767 | (unsigned long long)scsi_get_lba(cmnd), | |
9a6b09c0 | 4768 | blk_rq_sectors(cmnd->request), |
2613470a | 4769 | (cmnd->cmnd[1]>>5)); |
6a9c52cf | 4770 | } |
e2a0a9d6 JS |
4771 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); |
4772 | } | |
4773 | ||
dea3101e | 4774 | if (err) |
4775 | goto out_host_busy_free_buf; | |
4776 | ||
2e0fef85 | 4777 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
dea3101e | 4778 | |
977b5a0a | 4779 | atomic_inc(&ndlp->cmd_pending); |
3772a991 | 4780 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
92d7f7b0 | 4781 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
eaf15d5b JS |
4782 | if (err) { |
4783 | atomic_dec(&ndlp->cmd_pending); | |
dea3101e | 4784 | goto out_host_busy_free_buf; |
eaf15d5b | 4785 | } |
875fbdfe | 4786 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
45ed1190 JS |
4787 | lpfc_sli_handle_fast_ring_event(phba, |
4788 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
4789 | ||
875fbdfe JSEC |
4790 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
4791 | lpfc_poll_rearm_timer(phba); | |
4792 | } | |
4793 | ||
dea3101e | 4794 | return 0; |
4795 | ||
4796 | out_host_busy_free_buf: | |
bcf4dbfa | 4797 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
0bd4ca25 | 4798 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
dea3101e | 4799 | out_host_busy: |
4800 | return SCSI_MLQUEUE_HOST_BUSY; | |
4801 | ||
3496343d MC |
4802 | out_tgt_busy: |
4803 | return SCSI_MLQUEUE_TARGET_BUSY; | |
4804 | ||
dea3101e | 4805 | out_fail_command: |
b9a7c631 | 4806 | cmnd->scsi_done(cmnd); |
dea3101e | 4807 | return 0; |
4808 | } | |
4809 | ||
f281233d | 4810 | |
9bad7671 | 4811 | /** |
3621a710 | 4812 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
9bad7671 JS |
4813 | * @cmnd: Pointer to scsi_cmnd data structure. |
4814 | * | |
4815 | * This routine aborts @cmnd pending in base driver. | |
4816 | * | |
4817 | * Return code : | |
4818 | * 0x2003 - Error | |
4819 | * 0x2002 - Success | |
4820 | **/ | |
dea3101e | 4821 | static int |
63c59c3b | 4822 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
dea3101e | 4823 | { |
2e0fef85 JS |
4824 | struct Scsi_Host *shost = cmnd->device->host; |
4825 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
4826 | struct lpfc_hba *phba = vport->phba; | |
0bd4ca25 JSEC |
4827 | struct lpfc_iocbq *iocb; |
4828 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 4829 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 4830 | IOCB_t *cmd, *icmd; |
3a70730a | 4831 | int ret = SUCCESS, status = 0; |
876dd7d0 | 4832 | unsigned long flags; |
fa61a54e | 4833 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
dea3101e | 4834 | |
3a70730a | 4835 | status = fc_block_scsi_eh(cmnd); |
908e18e4 | 4836 | if (status != 0 && status != SUCCESS) |
3a70730a | 4837 | return status; |
4f2e66c6 | 4838 | |
876dd7d0 | 4839 | spin_lock_irqsave(&phba->hbalock, flags); |
4f2e66c6 JS |
4840 | /* driver queued commands are in process of being flushed */ |
4841 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { | |
876dd7d0 | 4842 | spin_unlock_irqrestore(&phba->hbalock, flags); |
4f2e66c6 JS |
4843 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
4844 | "3168 SCSI Layer abort requested I/O has been " | |
4845 | "flushed by LLD.\n"); | |
4846 | return FAILED; | |
4847 | } | |
4848 | ||
0bd4ca25 | 4849 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
92e3af66 | 4850 | if (!lpfc_cmd || !lpfc_cmd->pCmd) { |
876dd7d0 | 4851 | spin_unlock_irqrestore(&phba->hbalock, flags); |
eee8877e JS |
4852 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
4853 | "2873 SCSI Layer I/O Abort Request IO CMPL Status " | |
5cd049a5 | 4854 | "x%x ID %d LUN %d\n", |
3a70730a | 4855 | SUCCESS, cmnd->device->id, cmnd->device->lun); |
eee8877e JS |
4856 | return SUCCESS; |
4857 | } | |
dea3101e | 4858 | |
4f2e66c6 JS |
4859 | iocb = &lpfc_cmd->cur_iocbq; |
4860 | /* the command is in process of being cancelled */ | |
4861 | if (!(iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { | |
876dd7d0 | 4862 | spin_unlock_irqrestore(&phba->hbalock, flags); |
4f2e66c6 JS |
4863 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
4864 | "3169 SCSI Layer abort requested I/O has been " | |
4865 | "cancelled by LLD.\n"); | |
4866 | return FAILED; | |
4867 | } | |
0bd4ca25 JSEC |
4868 | /* |
4869 | * If pCmd field of the corresponding lpfc_scsi_buf structure | |
4870 | * points to a different SCSI command, then the driver has | |
4871 | * already completed this command, but the midlayer did not | |
4f2e66c6 | 4872 | * see the completion before the eh fired. Just return SUCCESS. |
0bd4ca25 | 4873 | */ |
4f2e66c6 JS |
4874 | if (lpfc_cmd->pCmd != cmnd) { |
4875 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, | |
4876 | "3170 SCSI Layer abort requested I/O has been " | |
4877 | "completed by LLD.\n"); | |
4878 | goto out_unlock; | |
4879 | } | |
dea3101e | 4880 | |
0bd4ca25 | 4881 | BUG_ON(iocb->context1 != lpfc_cmd); |
dea3101e | 4882 | |
4f2e66c6 | 4883 | abtsiocb = __lpfc_sli_get_iocbq(phba); |
0bd4ca25 JSEC |
4884 | if (abtsiocb == NULL) { |
4885 | ret = FAILED; | |
4f2e66c6 | 4886 | goto out_unlock; |
dea3101e | 4887 | } |
4888 | ||
dea3101e | 4889 | /* |
0bd4ca25 JSEC |
4890 | * The scsi command can not be in txq and it is in flight because the |
4891 | * pCmd is still pointig at the SCSI command we have to abort. There | |
4892 | * is no need to search the txcmplq. Just send an abort to the FW. | |
dea3101e | 4893 | */ |
dea3101e | 4894 | |
0bd4ca25 JSEC |
4895 | cmd = &iocb->iocb; |
4896 | icmd = &abtsiocb->iocb; | |
4897 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; | |
4898 | icmd->un.acxri.abortContextTag = cmd->ulpContext; | |
3772a991 JS |
4899 | if (phba->sli_rev == LPFC_SLI_REV4) |
4900 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; | |
4901 | else | |
4902 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 4903 | |
0bd4ca25 JSEC |
4904 | icmd->ulpLe = 1; |
4905 | icmd->ulpClass = cmd->ulpClass; | |
5ffc266e JS |
4906 | |
4907 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
4908 | abtsiocb->fcp_wqidx = iocb->fcp_wqidx; | |
341af102 | 4909 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
5ffc266e | 4910 | |
2e0fef85 | 4911 | if (lpfc_is_link_up(phba)) |
0bd4ca25 JSEC |
4912 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
4913 | else | |
4914 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 4915 | |
0bd4ca25 | 4916 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
2e0fef85 | 4917 | abtsiocb->vport = vport; |
4f2e66c6 | 4918 | /* no longer need the lock after this point */ |
876dd7d0 | 4919 | spin_unlock_irqrestore(&phba->hbalock, flags); |
4f2e66c6 | 4920 | |
3772a991 JS |
4921 | if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == |
4922 | IOCB_ERROR) { | |
0bd4ca25 JSEC |
4923 | lpfc_sli_release_iocbq(phba, abtsiocb); |
4924 | ret = FAILED; | |
4925 | goto out; | |
4926 | } | |
dea3101e | 4927 | |
875fbdfe | 4928 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
45ed1190 JS |
4929 | lpfc_sli_handle_fast_ring_event(phba, |
4930 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
875fbdfe | 4931 | |
fa61a54e | 4932 | lpfc_cmd->waitq = &waitq; |
0bd4ca25 | 4933 | /* Wait for abort to complete */ |
fa61a54e JS |
4934 | wait_event_timeout(waitq, |
4935 | (lpfc_cmd->pCmd != cmnd), | |
256ec0d0 | 4936 | msecs_to_jiffies(2*vport->cfg_devloss_tmo*1000)); |
fa61a54e | 4937 | lpfc_cmd->waitq = NULL; |
dea3101e | 4938 | |
0bd4ca25 JSEC |
4939 | if (lpfc_cmd->pCmd == cmnd) { |
4940 | ret = FAILED; | |
e8b62011 JS |
4941 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
4942 | "0748 abort handler timed out waiting " | |
247ca945 JS |
4943 | "for abortng I/O (xri:x%x) to complete: " |
4944 | "ret %#x, ID %d, LUN %d\n", | |
4945 | iocb->sli4_xritag, ret, | |
4946 | cmnd->device->id, cmnd->device->lun); | |
dea3101e | 4947 | } |
4f2e66c6 | 4948 | goto out; |
dea3101e | 4949 | |
4f2e66c6 | 4950 | out_unlock: |
876dd7d0 | 4951 | spin_unlock_irqrestore(&phba->hbalock, flags); |
4f2e66c6 | 4952 | out: |
e8b62011 JS |
4953 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
4954 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " | |
5cd049a5 CH |
4955 | "LUN %d\n", ret, cmnd->device->id, |
4956 | cmnd->device->lun); | |
63c59c3b | 4957 | return ret; |
8fa728a2 JG |
4958 | } |
4959 | ||
bbb9d180 JS |
4960 | static char * |
4961 | lpfc_taskmgmt_name(uint8_t task_mgmt_cmd) | |
4962 | { | |
4963 | switch (task_mgmt_cmd) { | |
4964 | case FCP_ABORT_TASK_SET: | |
4965 | return "ABORT_TASK_SET"; | |
4966 | case FCP_CLEAR_TASK_SET: | |
4967 | return "FCP_CLEAR_TASK_SET"; | |
4968 | case FCP_BUS_RESET: | |
4969 | return "FCP_BUS_RESET"; | |
4970 | case FCP_LUN_RESET: | |
4971 | return "FCP_LUN_RESET"; | |
4972 | case FCP_TARGET_RESET: | |
4973 | return "FCP_TARGET_RESET"; | |
4974 | case FCP_CLEAR_ACA: | |
4975 | return "FCP_CLEAR_ACA"; | |
4976 | case FCP_TERMINATE_TASK: | |
4977 | return "FCP_TERMINATE_TASK"; | |
4978 | default: | |
4979 | return "unknown"; | |
4980 | } | |
4981 | } | |
4982 | ||
9bad7671 | 4983 | /** |
bbb9d180 JS |
4984 | * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler |
4985 | * @vport: The virtual port for which this call is being executed. | |
4986 | * @rdata: Pointer to remote port local data | |
4987 | * @tgt_id: Target ID of remote device. | |
4988 | * @lun_id: Lun number for the TMF | |
4989 | * @task_mgmt_cmd: type of TMF to send | |
9bad7671 | 4990 | * |
bbb9d180 JS |
4991 | * This routine builds and sends a TMF (SCSI Task Mgmt Function) to |
4992 | * a remote port. | |
9bad7671 | 4993 | * |
bbb9d180 JS |
4994 | * Return Code: |
4995 | * 0x2003 - Error | |
4996 | * 0x2002 - Success. | |
9bad7671 | 4997 | **/ |
dea3101e | 4998 | static int |
bbb9d180 JS |
4999 | lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata, |
5000 | unsigned tgt_id, unsigned int lun_id, | |
5001 | uint8_t task_mgmt_cmd) | |
dea3101e | 5002 | { |
2e0fef85 | 5003 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 | 5004 | struct lpfc_scsi_buf *lpfc_cmd; |
bbb9d180 JS |
5005 | struct lpfc_iocbq *iocbq; |
5006 | struct lpfc_iocbq *iocbqrsp; | |
5989b8d4 | 5007 | struct lpfc_nodelist *pnode = rdata->pnode; |
bbb9d180 | 5008 | int ret; |
915caaaf | 5009 | int status; |
dea3101e | 5010 | |
5989b8d4 | 5011 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
915caaaf | 5012 | return FAILED; |
bbb9d180 | 5013 | |
19ca7609 | 5014 | lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode); |
dea3101e | 5015 | if (lpfc_cmd == NULL) |
915caaaf | 5016 | return FAILED; |
dea3101e | 5017 | lpfc_cmd->timeout = 60; |
0b18ac42 | 5018 | lpfc_cmd->rdata = rdata; |
dea3101e | 5019 | |
bbb9d180 JS |
5020 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id, |
5021 | task_mgmt_cmd); | |
915caaaf JS |
5022 | if (!status) { |
5023 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
5024 | return FAILED; | |
5025 | } | |
dea3101e | 5026 | |
bbb9d180 | 5027 | iocbq = &lpfc_cmd->cur_iocbq; |
0bd4ca25 | 5028 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
915caaaf JS |
5029 | if (iocbqrsp == NULL) { |
5030 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
5031 | return FAILED; | |
5032 | } | |
5a0916b4 | 5033 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
bbb9d180 | 5034 | |
e8b62011 | 5035 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
bbb9d180 | 5036 | "0702 Issue %s to TGT %d LUN %d " |
6d368e53 | 5037 | "rpi x%x nlp_flag x%x Data: x%x x%x\n", |
bbb9d180 | 5038 | lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id, |
6d368e53 JS |
5039 | pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag, |
5040 | iocbq->iocb_flag); | |
bbb9d180 | 5041 | |
3772a991 | 5042 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
915caaaf | 5043 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
bbb9d180 JS |
5044 | if (status != IOCB_SUCCESS) { |
5045 | if (status == IOCB_TIMEDOUT) { | |
bbb9d180 JS |
5046 | ret = TIMEOUT_ERROR; |
5047 | } else | |
915caaaf | 5048 | ret = FAILED; |
bbb9d180 JS |
5049 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
5050 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
6d368e53 JS |
5051 | "0727 TMF %s to TGT %d LUN %d failed (%d, %d) " |
5052 | "iocb_flag x%x\n", | |
bbb9d180 JS |
5053 | lpfc_taskmgmt_name(task_mgmt_cmd), |
5054 | tgt_id, lun_id, iocbqrsp->iocb.ulpStatus, | |
6d368e53 JS |
5055 | iocbqrsp->iocb.un.ulpWord[4], |
5056 | iocbq->iocb_flag); | |
2a9bf3d0 JS |
5057 | } else if (status == IOCB_BUSY) |
5058 | ret = FAILED; | |
5059 | else | |
bbb9d180 JS |
5060 | ret = SUCCESS; |
5061 | ||
6175c02a | 5062 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
bbb9d180 JS |
5063 | |
5064 | if (ret != TIMEOUT_ERROR) | |
5065 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
5066 | ||
5067 | return ret; | |
5068 | } | |
5069 | ||
5070 | /** | |
5071 | * lpfc_chk_tgt_mapped - | |
5072 | * @vport: The virtual port to check on | |
5073 | * @cmnd: Pointer to scsi_cmnd data structure. | |
5074 | * | |
5075 | * This routine delays until the scsi target (aka rport) for the | |
5076 | * command exists (is present and logged in) or we declare it non-existent. | |
5077 | * | |
5078 | * Return code : | |
5079 | * 0x2003 - Error | |
5080 | * 0x2002 - Success | |
5081 | **/ | |
5082 | static int | |
5083 | lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd) | |
5084 | { | |
5085 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | |
1c6f4ef5 | 5086 | struct lpfc_nodelist *pnode; |
bbb9d180 JS |
5087 | unsigned long later; |
5088 | ||
1c6f4ef5 JS |
5089 | if (!rdata) { |
5090 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, | |
5091 | "0797 Tgt Map rport failure: rdata x%p\n", rdata); | |
5092 | return FAILED; | |
5093 | } | |
5094 | pnode = rdata->pnode; | |
bbb9d180 JS |
5095 | /* |
5096 | * If target is not in a MAPPED state, delay until | |
5097 | * target is rediscovered or devloss timeout expires. | |
5098 | */ | |
5099 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; | |
5100 | while (time_after(later, jiffies)) { | |
5101 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) | |
5102 | return FAILED; | |
5103 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) | |
5104 | return SUCCESS; | |
5105 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); | |
5106 | rdata = cmnd->device->hostdata; | |
5107 | if (!rdata) | |
5108 | return FAILED; | |
5109 | pnode = rdata->pnode; | |
5110 | } | |
5111 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) || | |
5112 | (pnode->nlp_state != NLP_STE_MAPPED_NODE)) | |
5113 | return FAILED; | |
5114 | return SUCCESS; | |
5115 | } | |
5116 | ||
5117 | /** | |
5118 | * lpfc_reset_flush_io_context - | |
5119 | * @vport: The virtual port (scsi_host) for the flush context | |
5120 | * @tgt_id: If aborting by Target contect - specifies the target id | |
5121 | * @lun_id: If aborting by Lun context - specifies the lun id | |
5122 | * @context: specifies the context level to flush at. | |
5123 | * | |
5124 | * After a reset condition via TMF, we need to flush orphaned i/o | |
5125 | * contexts from the adapter. This routine aborts any contexts | |
5126 | * outstanding, then waits for their completions. The wait is | |
5127 | * bounded by devloss_tmo though. | |
5128 | * | |
5129 | * Return code : | |
5130 | * 0x2003 - Error | |
5131 | * 0x2002 - Success | |
5132 | **/ | |
5133 | static int | |
5134 | lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id, | |
5135 | uint64_t lun_id, lpfc_ctx_cmd context) | |
5136 | { | |
5137 | struct lpfc_hba *phba = vport->phba; | |
5138 | unsigned long later; | |
5139 | int cnt; | |
5140 | ||
5141 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); | |
6175c02a | 5142 | if (cnt) |
51ef4c26 | 5143 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
bbb9d180 | 5144 | tgt_id, lun_id, context); |
915caaaf JS |
5145 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
5146 | while (time_after(later, jiffies) && cnt) { | |
5147 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); | |
bbb9d180 | 5148 | cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context); |
dea3101e | 5149 | } |
dea3101e | 5150 | if (cnt) { |
e8b62011 | 5151 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
bbb9d180 JS |
5152 | "0724 I/O flush failure for context %s : cnt x%x\n", |
5153 | ((context == LPFC_CTX_LUN) ? "LUN" : | |
5154 | ((context == LPFC_CTX_TGT) ? "TGT" : | |
5155 | ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))), | |
5156 | cnt); | |
5157 | return FAILED; | |
dea3101e | 5158 | } |
bbb9d180 JS |
5159 | return SUCCESS; |
5160 | } | |
5161 | ||
5162 | /** | |
5163 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point | |
5164 | * @cmnd: Pointer to scsi_cmnd data structure. | |
5165 | * | |
5166 | * This routine does a device reset by sending a LUN_RESET task management | |
5167 | * command. | |
5168 | * | |
5169 | * Return code : | |
5170 | * 0x2003 - Error | |
5171 | * 0x2002 - Success | |
5172 | **/ | |
5173 | static int | |
5174 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) | |
5175 | { | |
5176 | struct Scsi_Host *shost = cmnd->device->host; | |
5177 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
5178 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | |
1c6f4ef5 | 5179 | struct lpfc_nodelist *pnode; |
bbb9d180 JS |
5180 | unsigned tgt_id = cmnd->device->id; |
5181 | unsigned int lun_id = cmnd->device->lun; | |
5182 | struct lpfc_scsi_event_header scsi_event; | |
3a70730a | 5183 | int status, ret = SUCCESS; |
bbb9d180 | 5184 | |
1c6f4ef5 JS |
5185 | if (!rdata) { |
5186 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5187 | "0798 Device Reset rport failure: rdata x%p\n", rdata); | |
5188 | return FAILED; | |
5189 | } | |
5190 | pnode = rdata->pnode; | |
589a52d6 | 5191 | status = fc_block_scsi_eh(cmnd); |
908e18e4 | 5192 | if (status != 0 && status != SUCCESS) |
589a52d6 | 5193 | return status; |
bbb9d180 JS |
5194 | |
5195 | status = lpfc_chk_tgt_mapped(vport, cmnd); | |
5196 | if (status == FAILED) { | |
5197 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5198 | "0721 Device Reset rport failure: rdata x%p\n", rdata); | |
5199 | return FAILED; | |
5200 | } | |
5201 | ||
5202 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
5203 | scsi_event.subcategory = LPFC_EVENT_LUNRESET; | |
5204 | scsi_event.lun = lun_id; | |
5205 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
5206 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
5207 | ||
5208 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5209 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); | |
5210 | ||
5211 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, | |
5212 | FCP_LUN_RESET); | |
5213 | ||
5214 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5215 | "0713 SCSI layer issued Device Reset (%d, %d) " | |
5216 | "return x%x\n", tgt_id, lun_id, status); | |
5217 | ||
5218 | /* | |
5219 | * We have to clean up i/o as : they may be orphaned by the TMF; | |
5220 | * or if the TMF failed, they may be in an indeterminate state. | |
5221 | * So, continue on. | |
5222 | * We will report success if all the i/o aborts successfully. | |
5223 | */ | |
3a70730a | 5224 | ret = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
bbb9d180 | 5225 | LPFC_CTX_LUN); |
3a70730a | 5226 | return ret; |
bbb9d180 JS |
5227 | } |
5228 | ||
5229 | /** | |
5230 | * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point | |
5231 | * @cmnd: Pointer to scsi_cmnd data structure. | |
5232 | * | |
5233 | * This routine does a target reset by sending a TARGET_RESET task management | |
5234 | * command. | |
5235 | * | |
5236 | * Return code : | |
5237 | * 0x2003 - Error | |
5238 | * 0x2002 - Success | |
5239 | **/ | |
5240 | static int | |
5241 | lpfc_target_reset_handler(struct scsi_cmnd *cmnd) | |
5242 | { | |
5243 | struct Scsi_Host *shost = cmnd->device->host; | |
5244 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
5245 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | |
1c6f4ef5 | 5246 | struct lpfc_nodelist *pnode; |
bbb9d180 JS |
5247 | unsigned tgt_id = cmnd->device->id; |
5248 | unsigned int lun_id = cmnd->device->lun; | |
5249 | struct lpfc_scsi_event_header scsi_event; | |
3a70730a | 5250 | int status, ret = SUCCESS; |
bbb9d180 | 5251 | |
1c6f4ef5 JS |
5252 | if (!rdata) { |
5253 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5254 | "0799 Target Reset rport failure: rdata x%p\n", rdata); | |
5255 | return FAILED; | |
5256 | } | |
5257 | pnode = rdata->pnode; | |
589a52d6 | 5258 | status = fc_block_scsi_eh(cmnd); |
908e18e4 | 5259 | if (status != 0 && status != SUCCESS) |
589a52d6 | 5260 | return status; |
bbb9d180 JS |
5261 | |
5262 | status = lpfc_chk_tgt_mapped(vport, cmnd); | |
5263 | if (status == FAILED) { | |
5264 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5265 | "0722 Target Reset rport failure: rdata x%p\n", rdata); | |
5266 | return FAILED; | |
5267 | } | |
5268 | ||
5269 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
5270 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; | |
5271 | scsi_event.lun = 0; | |
5272 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
5273 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
5274 | ||
5275 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5276 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); | |
5277 | ||
5278 | status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id, | |
5279 | FCP_TARGET_RESET); | |
5280 | ||
5281 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5282 | "0723 SCSI layer issued Target Reset (%d, %d) " | |
5283 | "return x%x\n", tgt_id, lun_id, status); | |
5284 | ||
5285 | /* | |
5286 | * We have to clean up i/o as : they may be orphaned by the TMF; | |
5287 | * or if the TMF failed, they may be in an indeterminate state. | |
5288 | * So, continue on. | |
5289 | * We will report success if all the i/o aborts successfully. | |
5290 | */ | |
3a70730a JS |
5291 | ret = lpfc_reset_flush_io_context(vport, tgt_id, lun_id, |
5292 | LPFC_CTX_TGT); | |
5293 | return ret; | |
dea3101e | 5294 | } |
5295 | ||
9bad7671 | 5296 | /** |
3621a710 | 5297 | * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point |
9bad7671 JS |
5298 | * @cmnd: Pointer to scsi_cmnd data structure. |
5299 | * | |
bbb9d180 JS |
5300 | * This routine does target reset to all targets on @cmnd->device->host. |
5301 | * This emulates Parallel SCSI Bus Reset Semantics. | |
9bad7671 | 5302 | * |
bbb9d180 JS |
5303 | * Return code : |
5304 | * 0x2003 - Error | |
5305 | * 0x2002 - Success | |
9bad7671 | 5306 | **/ |
94d0e7b8 | 5307 | static int |
7054a606 | 5308 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
dea3101e | 5309 | { |
2e0fef85 JS |
5310 | struct Scsi_Host *shost = cmnd->device->host; |
5311 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
dea3101e | 5312 | struct lpfc_nodelist *ndlp = NULL; |
ea2151b4 | 5313 | struct lpfc_scsi_event_header scsi_event; |
bbb9d180 JS |
5314 | int match; |
5315 | int ret = SUCCESS, status, i; | |
ea2151b4 JS |
5316 | |
5317 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
5318 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; | |
5319 | scsi_event.lun = 0; | |
5320 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); | |
5321 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
5322 | ||
bbb9d180 JS |
5323 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
5324 | sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID); | |
dea3101e | 5325 | |
bf08611b | 5326 | status = fc_block_scsi_eh(cmnd); |
908e18e4 | 5327 | if (status != 0 && status != SUCCESS) |
bf08611b | 5328 | return status; |
bbb9d180 | 5329 | |
dea3101e | 5330 | /* |
5331 | * Since the driver manages a single bus device, reset all | |
5332 | * targets known to the driver. Should any target reset | |
5333 | * fail, this routine returns failure to the midlayer. | |
5334 | */ | |
e17da18e | 5335 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
685f0bf7 | 5336 | /* Search for mapped node by target ID */ |
dea3101e | 5337 | match = 0; |
2e0fef85 JS |
5338 | spin_lock_irq(shost->host_lock); |
5339 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
5340 | if (!NLP_CHK_NODE_ACT(ndlp)) |
5341 | continue; | |
a6571c6e JS |
5342 | if (vport->phba->cfg_fcp2_no_tgt_reset && |
5343 | (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) | |
5344 | continue; | |
685f0bf7 | 5345 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
915caaaf | 5346 | ndlp->nlp_sid == i && |
685f0bf7 | 5347 | ndlp->rport) { |
dea3101e | 5348 | match = 1; |
5349 | break; | |
5350 | } | |
5351 | } | |
2e0fef85 | 5352 | spin_unlock_irq(shost->host_lock); |
dea3101e | 5353 | if (!match) |
5354 | continue; | |
bbb9d180 JS |
5355 | |
5356 | status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data, | |
5357 | i, 0, FCP_TARGET_RESET); | |
5358 | ||
5359 | if (status != SUCCESS) { | |
e8b62011 JS |
5360 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
5361 | "0700 Bus Reset on target %d failed\n", | |
5362 | i); | |
915caaaf | 5363 | ret = FAILED; |
dea3101e | 5364 | } |
5365 | } | |
6175c02a | 5366 | /* |
bbb9d180 JS |
5367 | * We have to clean up i/o as : they may be orphaned by the TMFs |
5368 | * above; or if any of the TMFs failed, they may be in an | |
5369 | * indeterminate state. | |
5370 | * We will report success if all the i/o aborts successfully. | |
6175c02a | 5371 | */ |
bbb9d180 JS |
5372 | |
5373 | status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST); | |
5374 | if (status != SUCCESS) | |
0bd4ca25 | 5375 | ret = FAILED; |
bbb9d180 | 5376 | |
e8b62011 JS |
5377 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
5378 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); | |
dea3101e | 5379 | return ret; |
5380 | } | |
5381 | ||
27b01b82 JS |
5382 | /** |
5383 | * lpfc_host_reset_handler - scsi_host_template eh_host_reset_handler entry pt | |
5384 | * @cmnd: Pointer to scsi_cmnd data structure. | |
5385 | * | |
5386 | * This routine does host reset to the adaptor port. It brings the HBA | |
5387 | * offline, performs a board restart, and then brings the board back online. | |
5388 | * The lpfc_offline calls lpfc_sli_hba_down which will abort and local | |
5389 | * reject all outstanding SCSI commands to the host and error returned | |
5390 | * back to SCSI mid-level. As this will be SCSI mid-level's last resort | |
5391 | * of error handling, it will only return error if resetting of the adapter | |
5392 | * is not successful; in all other cases, will return success. | |
5393 | * | |
5394 | * Return code : | |
5395 | * 0x2003 - Error | |
5396 | * 0x2002 - Success | |
5397 | **/ | |
5398 | static int | |
5399 | lpfc_host_reset_handler(struct scsi_cmnd *cmnd) | |
5400 | { | |
5401 | struct Scsi_Host *shost = cmnd->device->host; | |
5402 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
5403 | struct lpfc_hba *phba = vport->phba; | |
5404 | int rc, ret = SUCCESS; | |
5405 | ||
a88dbb6a JS |
5406 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
5407 | "3172 SCSI layer issued Host Reset Data:\n"); | |
5408 | ||
618a5230 | 5409 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
27b01b82 JS |
5410 | lpfc_offline(phba); |
5411 | rc = lpfc_sli_brdrestart(phba); | |
5412 | if (rc) | |
5413 | ret = FAILED; | |
a88dbb6a JS |
5414 | rc = lpfc_online(phba); |
5415 | if (rc) | |
5416 | ret = FAILED; | |
27b01b82 JS |
5417 | lpfc_unblock_mgmt_io(phba); |
5418 | ||
a88dbb6a JS |
5419 | if (ret == FAILED) { |
5420 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
5421 | "3323 Failed host reset, bring it offline\n"); | |
5422 | lpfc_sli4_offline_eratt(phba); | |
5423 | } | |
27b01b82 JS |
5424 | return ret; |
5425 | } | |
5426 | ||
9bad7671 | 5427 | /** |
3621a710 | 5428 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
9bad7671 JS |
5429 | * @sdev: Pointer to scsi_device. |
5430 | * | |
5431 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's | |
5432 | * globally available list of scsi buffers. This routine also makes sure scsi | |
5433 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list | |
5434 | * of scsi buffer exists for the lifetime of the driver. | |
5435 | * | |
5436 | * Return codes: | |
5437 | * non-0 - Error | |
5438 | * 0 - Success | |
5439 | **/ | |
dea3101e | 5440 | static int |
5441 | lpfc_slave_alloc(struct scsi_device *sdev) | |
5442 | { | |
2e0fef85 JS |
5443 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
5444 | struct lpfc_hba *phba = vport->phba; | |
19a7b4ae | 5445 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
3772a991 | 5446 | uint32_t total = 0; |
dea3101e | 5447 | uint32_t num_to_alloc = 0; |
3772a991 | 5448 | int num_allocated = 0; |
d7c47992 | 5449 | uint32_t sdev_cnt; |
dea3101e | 5450 | |
19a7b4ae | 5451 | if (!rport || fc_remote_port_chkready(rport)) |
dea3101e | 5452 | return -ENXIO; |
5453 | ||
19a7b4ae | 5454 | sdev->hostdata = rport->dd_data; |
d7c47992 | 5455 | sdev_cnt = atomic_inc_return(&phba->sdev_cnt); |
dea3101e | 5456 | |
5457 | /* | |
5458 | * Populate the cmds_per_lun count scsi_bufs into this host's globally | |
5459 | * available list of scsi buffers. Don't allocate more than the | |
a784efbf JSEC |
5460 | * HBA limit conveyed to the midlayer via the host structure. The |
5461 | * formula accounts for the lun_queue_depth + error handlers + 1 | |
5462 | * extra. This list of scsi bufs exists for the lifetime of the driver. | |
dea3101e | 5463 | */ |
5464 | total = phba->total_scsi_bufs; | |
3de2a653 | 5465 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
92d7f7b0 | 5466 | |
d7c47992 JS |
5467 | /* If allocated buffers are enough do nothing */ |
5468 | if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total) | |
5469 | return 0; | |
5470 | ||
92d7f7b0 JS |
5471 | /* Allow some exchanges to be available always to complete discovery */ |
5472 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { | |
e8b62011 JS |
5473 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
5474 | "0704 At limitation of %d preallocated " | |
5475 | "command buffers\n", total); | |
dea3101e | 5476 | return 0; |
92d7f7b0 JS |
5477 | /* Allow some exchanges to be available always to complete discovery */ |
5478 | } else if (total + num_to_alloc > | |
5479 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { | |
e8b62011 JS |
5480 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
5481 | "0705 Allocation request of %d " | |
5482 | "command buffers will exceed max of %d. " | |
5483 | "Reducing allocation request to %d.\n", | |
5484 | num_to_alloc, phba->cfg_hba_queue_depth, | |
5485 | (phba->cfg_hba_queue_depth - total)); | |
dea3101e | 5486 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
5487 | } | |
3772a991 JS |
5488 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
5489 | if (num_to_alloc != num_allocated) { | |
96f7077f JS |
5490 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
5491 | "0708 Allocation request of %d " | |
5492 | "command buffers did not succeed. " | |
5493 | "Allocated %d buffers.\n", | |
5494 | num_to_alloc, num_allocated); | |
dea3101e | 5495 | } |
1c6f4ef5 JS |
5496 | if (num_allocated > 0) |
5497 | phba->total_scsi_bufs += num_allocated; | |
dea3101e | 5498 | return 0; |
5499 | } | |
5500 | ||
9bad7671 | 5501 | /** |
3621a710 | 5502 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
9bad7671 JS |
5503 | * @sdev: Pointer to scsi_device. |
5504 | * | |
5505 | * This routine configures following items | |
5506 | * - Tag command queuing support for @sdev if supported. | |
9bad7671 JS |
5507 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. |
5508 | * | |
5509 | * Return codes: | |
5510 | * 0 - Success | |
5511 | **/ | |
dea3101e | 5512 | static int |
5513 | lpfc_slave_configure(struct scsi_device *sdev) | |
5514 | { | |
2e0fef85 JS |
5515 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
5516 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5517 | |
5518 | if (sdev->tagged_supported) | |
3de2a653 | 5519 | scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth); |
dea3101e | 5520 | else |
3de2a653 | 5521 | scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth); |
dea3101e | 5522 | |
875fbdfe | 5523 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
45ed1190 JS |
5524 | lpfc_sli_handle_fast_ring_event(phba, |
5525 | &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ); | |
875fbdfe JSEC |
5526 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
5527 | lpfc_poll_rearm_timer(phba); | |
5528 | } | |
5529 | ||
dea3101e | 5530 | return 0; |
5531 | } | |
5532 | ||
9bad7671 | 5533 | /** |
3621a710 | 5534 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
9bad7671 JS |
5535 | * @sdev: Pointer to scsi_device. |
5536 | * | |
5537 | * This routine sets @sdev hostatdata filed to null. | |
5538 | **/ | |
dea3101e | 5539 | static void |
5540 | lpfc_slave_destroy(struct scsi_device *sdev) | |
5541 | { | |
d7c47992 JS |
5542 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
5543 | struct lpfc_hba *phba = vport->phba; | |
5544 | atomic_dec(&phba->sdev_cnt); | |
dea3101e | 5545 | sdev->hostdata = NULL; |
5546 | return; | |
5547 | } | |
5548 | ||
92d7f7b0 | 5549 | |
dea3101e | 5550 | struct scsi_host_template lpfc_template = { |
5551 | .module = THIS_MODULE, | |
5552 | .name = LPFC_DRIVER_NAME, | |
5553 | .info = lpfc_info, | |
5554 | .queuecommand = lpfc_queuecommand, | |
5555 | .eh_abort_handler = lpfc_abort_handler, | |
bbb9d180 JS |
5556 | .eh_device_reset_handler = lpfc_device_reset_handler, |
5557 | .eh_target_reset_handler = lpfc_target_reset_handler, | |
7054a606 | 5558 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
27b01b82 | 5559 | .eh_host_reset_handler = lpfc_host_reset_handler, |
dea3101e | 5560 | .slave_alloc = lpfc_slave_alloc, |
5561 | .slave_configure = lpfc_slave_configure, | |
5562 | .slave_destroy = lpfc_slave_destroy, | |
47a8617c | 5563 | .scan_finished = lpfc_scan_finished, |
dea3101e | 5564 | .this_id = -1, |
83108bd3 | 5565 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
dea3101e | 5566 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
5567 | .use_clustering = ENABLE_CLUSTERING, | |
2e0fef85 | 5568 | .shost_attrs = lpfc_hba_attrs, |
564b2960 | 5569 | .max_sectors = 0xFFFF, |
f1c3b0fc | 5570 | .vendor_id = LPFC_NL_VENDOR_ID, |
5ffc266e | 5571 | .change_queue_depth = lpfc_change_queue_depth, |
fe8f7f9c | 5572 | .change_queue_type = lpfc_change_queue_type, |
dea3101e | 5573 | }; |
3de2a653 JS |
5574 | |
5575 | struct scsi_host_template lpfc_vport_template = { | |
5576 | .module = THIS_MODULE, | |
5577 | .name = LPFC_DRIVER_NAME, | |
5578 | .info = lpfc_info, | |
5579 | .queuecommand = lpfc_queuecommand, | |
5580 | .eh_abort_handler = lpfc_abort_handler, | |
bbb9d180 JS |
5581 | .eh_device_reset_handler = lpfc_device_reset_handler, |
5582 | .eh_target_reset_handler = lpfc_target_reset_handler, | |
3de2a653 JS |
5583 | .eh_bus_reset_handler = lpfc_bus_reset_handler, |
5584 | .slave_alloc = lpfc_slave_alloc, | |
5585 | .slave_configure = lpfc_slave_configure, | |
5586 | .slave_destroy = lpfc_slave_destroy, | |
5587 | .scan_finished = lpfc_scan_finished, | |
5588 | .this_id = -1, | |
83108bd3 | 5589 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
3de2a653 JS |
5590 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
5591 | .use_clustering = ENABLE_CLUSTERING, | |
5592 | .shost_attrs = lpfc_vport_attrs, | |
5593 | .max_sectors = 0xFFFF, | |
5ffc266e | 5594 | .change_queue_depth = lpfc_change_queue_depth, |
fe8f7f9c | 5595 | .change_queue_type = lpfc_change_queue_type, |
3de2a653 | 5596 | }; |