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