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