Commit | Line | Data |
---|---|---|
01649561 JS |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
3 | * Fibre Channel Host Bus Adapters. * | |
4 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * | |
5 | * EMULEX and SLI are trademarks of Emulex. * | |
6 | * www.emulex.com * | |
7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * | |
8 | * * | |
9 | * This program is free software; you can redistribute it and/or * | |
10 | * modify it under the terms of version 2 of the GNU General * | |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
20 | ********************************************************************/ | |
21 | #include <linux/pci.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/interrupt.h> | |
24 | #include <linux/delay.h> | |
25 | #include <asm/unaligned.h> | |
26 | #include <linux/crc-t10dif.h> | |
27 | #include <net/checksum.h> | |
28 | ||
29 | #include <scsi/scsi.h> | |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_eh.h> | |
32 | #include <scsi/scsi_host.h> | |
33 | #include <scsi/scsi_tcq.h> | |
34 | #include <scsi/scsi_transport_fc.h> | |
35 | #include <scsi/fc/fc_fs.h> | |
36 | ||
37 | #include <linux/nvme.h> | |
38 | #include <linux/nvme-fc-driver.h> | |
39 | #include <linux/nvme-fc.h> | |
40 | #include "lpfc_version.h" | |
41 | #include "lpfc_hw4.h" | |
42 | #include "lpfc_hw.h" | |
43 | #include "lpfc_sli.h" | |
44 | #include "lpfc_sli4.h" | |
45 | #include "lpfc_nl.h" | |
46 | #include "lpfc_disc.h" | |
47 | #include "lpfc.h" | |
48 | #include "lpfc_nvme.h" | |
49 | #include "lpfc_scsi.h" | |
50 | #include "lpfc_logmsg.h" | |
51 | #include "lpfc_crtn.h" | |
52 | #include "lpfc_vport.h" | |
bd2cdd5e | 53 | #include "lpfc_debugfs.h" |
01649561 JS |
54 | |
55 | /* NVME initiator-based functions */ | |
56 | ||
57 | static struct lpfc_nvme_buf * | |
58 | lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp); | |
59 | ||
60 | static void | |
61 | lpfc_release_nvme_buf(struct lpfc_hba *, struct lpfc_nvme_buf *); | |
62 | ||
63 | ||
64 | /** | |
65 | * lpfc_nvme_create_queue - | |
66 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
67 | * @qidx: An cpu index used to affinitize IO queues and MSIX vectors. | |
68 | * @handle: An opaque driver handle used in follow-up calls. | |
69 | * | |
70 | * Driver registers this routine to preallocate and initialize any | |
71 | * internal data structures to bind the @qidx to its internal IO queues. | |
72 | * A hardware queue maps (qidx) to a specific driver MSI-X vector/EQ/CQ/WQ. | |
73 | * | |
74 | * Return value : | |
75 | * 0 - Success | |
76 | * -EINVAL - Unsupported input value. | |
77 | * -ENOMEM - Could not alloc necessary memory | |
78 | **/ | |
79 | static int | |
80 | lpfc_nvme_create_queue(struct nvme_fc_local_port *pnvme_lport, | |
81 | unsigned int qidx, u16 qsize, | |
82 | void **handle) | |
83 | { | |
84 | struct lpfc_nvme_lport *lport; | |
85 | struct lpfc_vport *vport; | |
86 | struct lpfc_nvme_qhandle *qhandle; | |
87 | char *str; | |
88 | ||
89 | lport = (struct lpfc_nvme_lport *)pnvme_lport->private; | |
90 | vport = lport->vport; | |
91 | qhandle = kzalloc(sizeof(struct lpfc_nvme_qhandle), GFP_KERNEL); | |
92 | if (qhandle == NULL) | |
93 | return -ENOMEM; | |
94 | ||
95 | qhandle->cpu_id = smp_processor_id(); | |
96 | qhandle->qidx = qidx; | |
97 | /* | |
98 | * NVME qidx == 0 is the admin queue, so both admin queue | |
99 | * and first IO queue will use MSI-X vector and associated | |
100 | * EQ/CQ/WQ at index 0. After that they are sequentially assigned. | |
101 | */ | |
102 | if (qidx) { | |
103 | str = "IO "; /* IO queue */ | |
104 | qhandle->index = ((qidx - 1) % | |
105 | vport->phba->cfg_nvme_io_channel); | |
106 | } else { | |
107 | str = "ADM"; /* Admin queue */ | |
108 | qhandle->index = qidx; | |
109 | } | |
110 | ||
111 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
112 | "6073 Binding %s HdwQueue %d (cpu %d) to " | |
113 | "io_channel %d qhandle %p\n", str, | |
114 | qidx, qhandle->cpu_id, qhandle->index, qhandle); | |
115 | *handle = (void *)qhandle; | |
116 | return 0; | |
117 | } | |
118 | ||
119 | /** | |
120 | * lpfc_nvme_delete_queue - | |
121 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
122 | * @qidx: An cpu index used to affinitize IO queues and MSIX vectors. | |
123 | * @handle: An opaque driver handle from lpfc_nvme_create_queue | |
124 | * | |
125 | * Driver registers this routine to free | |
126 | * any internal data structures to bind the @qidx to its internal | |
127 | * IO queues. | |
128 | * | |
129 | * Return value : | |
130 | * 0 - Success | |
131 | * TODO: What are the failure codes. | |
132 | **/ | |
133 | static void | |
134 | lpfc_nvme_delete_queue(struct nvme_fc_local_port *pnvme_lport, | |
135 | unsigned int qidx, | |
136 | void *handle) | |
137 | { | |
138 | struct lpfc_nvme_lport *lport; | |
139 | struct lpfc_vport *vport; | |
140 | ||
141 | lport = (struct lpfc_nvme_lport *)pnvme_lport->private; | |
142 | vport = lport->vport; | |
143 | ||
144 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, | |
145 | "6001 ENTER. lpfc_pnvme %p, qidx x%xi qhandle %p\n", | |
146 | lport, qidx, handle); | |
147 | kfree(handle); | |
148 | } | |
149 | ||
150 | static void | |
151 | lpfc_nvme_localport_delete(struct nvme_fc_local_port *localport) | |
152 | { | |
153 | struct lpfc_nvme_lport *lport = localport->private; | |
154 | ||
155 | /* release any threads waiting for the unreg to complete */ | |
156 | complete(&lport->lport_unreg_done); | |
157 | } | |
158 | ||
159 | /* lpfc_nvme_remoteport_delete | |
160 | * | |
161 | * @remoteport: Pointer to an nvme transport remoteport instance. | |
162 | * | |
163 | * This is a template downcall. NVME transport calls this function | |
164 | * when it has completed the unregistration of a previously | |
165 | * registered remoteport. | |
166 | * | |
167 | * Return value : | |
168 | * None | |
169 | */ | |
170 | void | |
171 | lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport) | |
172 | { | |
173 | struct lpfc_nvme_rport *rport = remoteport->private; | |
174 | struct lpfc_vport *vport; | |
175 | struct lpfc_nodelist *ndlp; | |
176 | ||
177 | ndlp = rport->ndlp; | |
178 | if (!ndlp) | |
179 | goto rport_err; | |
180 | ||
181 | vport = ndlp->vport; | |
182 | if (!vport) | |
183 | goto rport_err; | |
184 | ||
185 | /* Remove this rport from the lport's list - memory is owned by the | |
186 | * transport. Remove the ndlp reference for the NVME transport before | |
187 | * calling state machine to remove the node, this is devloss = 0 | |
188 | * semantics. | |
189 | */ | |
190 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
191 | "6146 remoteport delete complete %p\n", | |
192 | remoteport); | |
193 | list_del(&rport->list); | |
194 | lpfc_nlp_put(ndlp); | |
195 | ||
196 | rport_err: | |
197 | /* This call has to execute as long as the rport is valid. | |
198 | * Release any threads waiting for the unreg to complete. | |
199 | */ | |
200 | complete(&rport->rport_unreg_done); | |
201 | } | |
202 | ||
203 | static void | |
204 | lpfc_nvme_cmpl_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdwqe, | |
205 | struct lpfc_wcqe_complete *wcqe) | |
206 | { | |
207 | struct lpfc_vport *vport = cmdwqe->vport; | |
208 | uint32_t status; | |
209 | struct nvmefc_ls_req *pnvme_lsreq; | |
210 | struct lpfc_dmabuf *buf_ptr; | |
211 | struct lpfc_nodelist *ndlp; | |
212 | ||
213 | vport->phba->fc4NvmeLsCmpls++; | |
214 | ||
215 | pnvme_lsreq = (struct nvmefc_ls_req *)cmdwqe->context2; | |
216 | status = bf_get(lpfc_wcqe_c_status, wcqe) & LPFC_IOCB_STATUS_MASK; | |
217 | ndlp = (struct lpfc_nodelist *)cmdwqe->context1; | |
218 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
219 | "6047 nvme cmpl Enter " | |
220 | "Data %p DID %x Xri: %x status %x cmd:%p lsreg:%p " | |
221 | "bmp:%p ndlp:%p\n", | |
222 | pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0, | |
223 | cmdwqe->sli4_xritag, status, | |
224 | cmdwqe, pnvme_lsreq, cmdwqe->context3, ndlp); | |
225 | ||
bd2cdd5e JS |
226 | lpfc_nvmeio_data(phba, "NVME LS CMPL: xri x%x stat x%x parm x%x\n", |
227 | cmdwqe->sli4_xritag, status, wcqe->parameter); | |
228 | ||
01649561 JS |
229 | if (cmdwqe->context3) { |
230 | buf_ptr = (struct lpfc_dmabuf *)cmdwqe->context3; | |
231 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
232 | kfree(buf_ptr); | |
233 | cmdwqe->context3 = NULL; | |
234 | } | |
235 | if (pnvme_lsreq->done) | |
236 | pnvme_lsreq->done(pnvme_lsreq, status); | |
237 | else | |
238 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
239 | "6046 nvme cmpl without done call back? " | |
240 | "Data %p DID %x Xri: %x status %x\n", | |
241 | pnvme_lsreq, ndlp ? ndlp->nlp_DID : 0, | |
242 | cmdwqe->sli4_xritag, status); | |
243 | if (ndlp) { | |
244 | lpfc_nlp_put(ndlp); | |
245 | cmdwqe->context1 = NULL; | |
246 | } | |
247 | lpfc_sli_release_iocbq(phba, cmdwqe); | |
248 | } | |
249 | ||
250 | static int | |
251 | lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, | |
252 | struct lpfc_dmabuf *inp, | |
253 | struct nvmefc_ls_req *pnvme_lsreq, | |
254 | void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, | |
255 | struct lpfc_wcqe_complete *), | |
256 | struct lpfc_nodelist *ndlp, uint32_t num_entry, | |
257 | uint32_t tmo, uint8_t retry) | |
258 | { | |
259 | struct lpfc_hba *phba = vport->phba; | |
260 | union lpfc_wqe *wqe; | |
261 | struct lpfc_iocbq *genwqe; | |
262 | struct ulp_bde64 *bpl; | |
263 | struct ulp_bde64 bde; | |
264 | int i, rc, xmit_len, first_len; | |
265 | ||
266 | /* Allocate buffer for command WQE */ | |
267 | genwqe = lpfc_sli_get_iocbq(phba); | |
268 | if (genwqe == NULL) | |
269 | return 1; | |
270 | ||
271 | wqe = &genwqe->wqe; | |
272 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
273 | ||
274 | genwqe->context3 = (uint8_t *)bmp; | |
275 | genwqe->iocb_flag |= LPFC_IO_NVME_LS; | |
276 | ||
277 | /* Save for completion so we can release these resources */ | |
278 | genwqe->context1 = lpfc_nlp_get(ndlp); | |
279 | genwqe->context2 = (uint8_t *)pnvme_lsreq; | |
280 | /* Fill in payload, bp points to frame payload */ | |
281 | ||
282 | if (!tmo) | |
283 | /* FC spec states we need 3 * ratov for CT requests */ | |
284 | tmo = (3 * phba->fc_ratov); | |
285 | ||
286 | /* For this command calculate the xmit length of the request bde. */ | |
287 | xmit_len = 0; | |
288 | first_len = 0; | |
289 | bpl = (struct ulp_bde64 *)bmp->virt; | |
290 | for (i = 0; i < num_entry; i++) { | |
291 | bde.tus.w = bpl[i].tus.w; | |
292 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) | |
293 | break; | |
294 | xmit_len += bde.tus.f.bdeSize; | |
295 | if (i == 0) | |
296 | first_len = xmit_len; | |
297 | } | |
298 | ||
299 | genwqe->rsvd2 = num_entry; | |
300 | genwqe->hba_wqidx = 0; | |
301 | ||
302 | /* Words 0 - 2 */ | |
303 | wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
304 | wqe->generic.bde.tus.f.bdeSize = first_len; | |
305 | wqe->generic.bde.addrLow = bpl[0].addrLow; | |
306 | wqe->generic.bde.addrHigh = bpl[0].addrHigh; | |
307 | ||
308 | /* Word 3 */ | |
309 | wqe->gen_req.request_payload_len = first_len; | |
310 | ||
311 | /* Word 4 */ | |
312 | ||
313 | /* Word 5 */ | |
314 | bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0); | |
315 | bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1); | |
316 | bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1); | |
317 | bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_DD_UNSOL_CTL); | |
318 | bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME); | |
319 | ||
320 | /* Word 6 */ | |
321 | bf_set(wqe_ctxt_tag, &wqe->gen_req.wqe_com, | |
322 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
323 | bf_set(wqe_xri_tag, &wqe->gen_req.wqe_com, genwqe->sli4_xritag); | |
324 | ||
325 | /* Word 7 */ | |
326 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, (vport->phba->fc_ratov-1)); | |
327 | bf_set(wqe_class, &wqe->gen_req.wqe_com, CLASS3); | |
328 | bf_set(wqe_cmnd, &wqe->gen_req.wqe_com, CMD_GEN_REQUEST64_WQE); | |
329 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, SLI4_CT_RPI); | |
330 | ||
331 | /* Word 8 */ | |
332 | wqe->gen_req.wqe_com.abort_tag = genwqe->iotag; | |
333 | ||
334 | /* Word 9 */ | |
335 | bf_set(wqe_reqtag, &wqe->gen_req.wqe_com, genwqe->iotag); | |
336 | ||
337 | /* Word 10 */ | |
338 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
339 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
340 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
341 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
342 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
343 | ||
344 | /* Word 11 */ | |
345 | bf_set(wqe_cqid, &wqe->gen_req.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
346 | bf_set(wqe_cmd_type, &wqe->gen_req.wqe_com, OTHER_COMMAND); | |
347 | ||
348 | ||
349 | /* Issue GEN REQ WQE for NPORT <did> */ | |
350 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
351 | "6050 Issue GEN REQ WQE to NPORT x%x " | |
352 | "Data: x%x x%x wq:%p lsreq:%p bmp:%p xmit:%d 1st:%d\n", | |
353 | ndlp->nlp_DID, genwqe->iotag, | |
354 | vport->port_state, | |
355 | genwqe, pnvme_lsreq, bmp, xmit_len, first_len); | |
356 | genwqe->wqe_cmpl = cmpl; | |
357 | genwqe->iocb_cmpl = NULL; | |
358 | genwqe->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT; | |
359 | genwqe->vport = vport; | |
360 | genwqe->retry = retry; | |
361 | ||
bd2cdd5e JS |
362 | lpfc_nvmeio_data(phba, "NVME LS XMIT: xri x%x iotag x%x to x%06x\n", |
363 | genwqe->sli4_xritag, genwqe->iotag, ndlp->nlp_DID); | |
364 | ||
01649561 JS |
365 | rc = lpfc_sli4_issue_wqe(phba, LPFC_ELS_RING, genwqe); |
366 | if (rc == WQE_ERROR) { | |
367 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
368 | "6045 Issue GEN REQ WQE to NPORT x%x " | |
369 | "Data: x%x x%x\n", | |
370 | ndlp->nlp_DID, genwqe->iotag, | |
371 | vport->port_state); | |
372 | lpfc_sli_release_iocbq(phba, genwqe); | |
373 | return 1; | |
374 | } | |
375 | return 0; | |
376 | } | |
377 | ||
378 | /** | |
379 | * lpfc_nvme_ls_req - Issue an Link Service request | |
380 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
381 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
382 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
383 | * | |
384 | * Driver registers this routine to handle any link service request | |
385 | * from the nvme_fc transport to a remote nvme-aware port. | |
386 | * | |
387 | * Return value : | |
388 | * 0 - Success | |
389 | * TODO: What are the failure codes. | |
390 | **/ | |
391 | static int | |
392 | lpfc_nvme_ls_req(struct nvme_fc_local_port *pnvme_lport, | |
393 | struct nvme_fc_remote_port *pnvme_rport, | |
394 | struct nvmefc_ls_req *pnvme_lsreq) | |
395 | { | |
396 | int ret = 0; | |
397 | struct lpfc_nvme_lport *lport; | |
398 | struct lpfc_vport *vport; | |
399 | struct lpfc_nodelist *ndlp; | |
400 | struct ulp_bde64 *bpl; | |
401 | struct lpfc_dmabuf *bmp; | |
402 | ||
403 | /* there are two dma buf in the request, actually there is one and | |
404 | * the second one is just the start address + cmd size. | |
405 | * Before calling lpfc_nvme_gen_req these buffers need to be wrapped | |
406 | * in a lpfc_dmabuf struct. When freeing we just free the wrapper | |
407 | * because the nvem layer owns the data bufs. | |
408 | * We do not have to break these packets open, we don't care what is in | |
409 | * them. And we do not have to look at the resonse data, we only care | |
410 | * that we got a response. All of the caring is going to happen in the | |
411 | * nvme-fc layer. | |
412 | */ | |
413 | ||
414 | lport = (struct lpfc_nvme_lport *)pnvme_lport->private; | |
415 | vport = lport->vport; | |
416 | ||
417 | ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id); | |
418 | if (!ndlp) { | |
419 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
420 | "6043 Could not find node for DID %x\n", | |
421 | pnvme_rport->port_id); | |
422 | return 1; | |
423 | } | |
424 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
425 | if (!bmp) { | |
426 | ||
427 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
428 | "6044 Could not find node for DID %x\n", | |
429 | pnvme_rport->port_id); | |
430 | return 2; | |
431 | } | |
432 | INIT_LIST_HEAD(&bmp->list); | |
433 | bmp->virt = lpfc_mbuf_alloc(vport->phba, MEM_PRI, &(bmp->phys)); | |
434 | if (!bmp->virt) { | |
435 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
436 | "6042 Could not find node for DID %x\n", | |
437 | pnvme_rport->port_id); | |
438 | kfree(bmp); | |
439 | return 3; | |
440 | } | |
441 | bpl = (struct ulp_bde64 *)bmp->virt; | |
442 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rqstdma)); | |
443 | bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rqstdma)); | |
444 | bpl->tus.f.bdeFlags = 0; | |
445 | bpl->tus.f.bdeSize = pnvme_lsreq->rqstlen; | |
446 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
447 | bpl++; | |
448 | ||
449 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pnvme_lsreq->rspdma)); | |
450 | bpl->addrLow = le32_to_cpu(putPaddrLow(pnvme_lsreq->rspdma)); | |
451 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
452 | bpl->tus.f.bdeSize = pnvme_lsreq->rsplen; | |
453 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
454 | ||
455 | /* Expand print to include key fields. */ | |
456 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
457 | "6051 ENTER. lport %p, rport %p lsreq%p rqstlen:%d " | |
458 | "rsplen:%d %llux %llux\n", | |
459 | pnvme_lport, pnvme_rport, | |
460 | pnvme_lsreq, pnvme_lsreq->rqstlen, | |
461 | pnvme_lsreq->rsplen, pnvme_lsreq->rqstdma, | |
462 | pnvme_lsreq->rspdma); | |
463 | ||
464 | vport->phba->fc4NvmeLsRequests++; | |
465 | ||
466 | /* Hardcode the wait to 30 seconds. Connections are failing otherwise. | |
467 | * This code allows it all to work. | |
468 | */ | |
469 | ret = lpfc_nvme_gen_req(vport, bmp, pnvme_lsreq->rqstaddr, | |
470 | pnvme_lsreq, lpfc_nvme_cmpl_gen_req, | |
471 | ndlp, 2, 30, 0); | |
472 | if (ret != WQE_SUCCESS) { | |
473 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
474 | "6052 EXIT. issue ls wqe failed lport %p, " | |
475 | "rport %p lsreq%p Status %x DID %x\n", | |
476 | pnvme_lport, pnvme_rport, pnvme_lsreq, | |
477 | ret, ndlp->nlp_DID); | |
478 | lpfc_mbuf_free(vport->phba, bmp->virt, bmp->phys); | |
479 | kfree(bmp); | |
480 | return ret; | |
481 | } | |
482 | ||
483 | /* Stub in routine and return 0 for now. */ | |
484 | return ret; | |
485 | } | |
486 | ||
487 | /** | |
488 | * lpfc_nvme_ls_abort - Issue an Link Service request | |
489 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
490 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
491 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
492 | * | |
493 | * Driver registers this routine to handle any link service request | |
494 | * from the nvme_fc transport to a remote nvme-aware port. | |
495 | * | |
496 | * Return value : | |
497 | * 0 - Success | |
498 | * TODO: What are the failure codes. | |
499 | **/ | |
500 | static void | |
501 | lpfc_nvme_ls_abort(struct nvme_fc_local_port *pnvme_lport, | |
502 | struct nvme_fc_remote_port *pnvme_rport, | |
503 | struct nvmefc_ls_req *pnvme_lsreq) | |
504 | { | |
505 | struct lpfc_nvme_lport *lport; | |
506 | struct lpfc_vport *vport; | |
507 | struct lpfc_hba *phba; | |
508 | struct lpfc_nodelist *ndlp; | |
509 | LIST_HEAD(abort_list); | |
510 | struct lpfc_sli_ring *pring; | |
511 | struct lpfc_iocbq *wqe, *next_wqe; | |
512 | ||
513 | lport = (struct lpfc_nvme_lport *)pnvme_lport->private; | |
514 | vport = lport->vport; | |
515 | phba = vport->phba; | |
516 | ||
517 | ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id); | |
518 | if (!ndlp) { | |
519 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, | |
520 | "6049 Could not find node for DID %x\n", | |
521 | pnvme_rport->port_id); | |
522 | return; | |
523 | } | |
524 | ||
525 | /* Expand print to include key fields. */ | |
526 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, | |
527 | "6040 ENTER. lport %p, rport %p lsreq %p rqstlen:%d " | |
528 | "rsplen:%d %llux %llux\n", | |
529 | pnvme_lport, pnvme_rport, | |
530 | pnvme_lsreq, pnvme_lsreq->rqstlen, | |
531 | pnvme_lsreq->rsplen, pnvme_lsreq->rqstdma, | |
532 | pnvme_lsreq->rspdma); | |
533 | ||
534 | /* | |
535 | * Lock the ELS ring txcmplq and build a local list of all ELS IOs | |
536 | * that need an ABTS. The IOs need to stay on the txcmplq so that | |
537 | * the abort operation completes them successfully. | |
538 | */ | |
539 | pring = phba->sli4_hba.nvmels_wq->pring; | |
540 | spin_lock_irq(&phba->hbalock); | |
541 | spin_lock(&pring->ring_lock); | |
542 | list_for_each_entry_safe(wqe, next_wqe, &pring->txcmplq, list) { | |
543 | /* Add to abort_list on on NDLP match. */ | |
544 | if (lpfc_check_sli_ndlp(phba, pring, wqe, ndlp)) { | |
545 | wqe->iocb_flag |= LPFC_DRIVER_ABORTED; | |
546 | list_add_tail(&wqe->dlist, &abort_list); | |
547 | } | |
548 | } | |
549 | spin_unlock(&pring->ring_lock); | |
550 | spin_unlock_irq(&phba->hbalock); | |
551 | ||
552 | /* Abort the targeted IOs and remove them from the abort list. */ | |
553 | list_for_each_entry_safe(wqe, next_wqe, &abort_list, dlist) { | |
554 | spin_lock_irq(&phba->hbalock); | |
555 | list_del_init(&wqe->dlist); | |
556 | lpfc_sli_issue_abort_iotag(phba, pring, wqe); | |
557 | spin_unlock_irq(&phba->hbalock); | |
558 | } | |
559 | } | |
560 | ||
561 | /* Fix up the existing sgls for NVME IO. */ | |
562 | static void | |
563 | lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport, | |
564 | struct lpfc_nvme_buf *lpfc_ncmd, | |
565 | struct nvmefc_fcp_req *nCmd) | |
566 | { | |
567 | struct sli4_sge *sgl; | |
568 | union lpfc_wqe128 *wqe; | |
569 | uint32_t *wptr, *dptr; | |
570 | ||
571 | /* | |
572 | * Adjust the FCP_CMD and FCP_RSP DMA data and sge_len to | |
573 | * match NVME. NVME sends 96 bytes. Also, use the | |
574 | * nvme commands command and response dma addresses | |
575 | * rather than the virtual memory to ease the restore | |
576 | * operation. | |
577 | */ | |
578 | sgl = lpfc_ncmd->nvme_sgl; | |
579 | sgl->sge_len = cpu_to_le32(nCmd->cmdlen); | |
580 | ||
581 | sgl++; | |
582 | ||
583 | /* Setup the physical region for the FCP RSP */ | |
584 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(nCmd->rspdma)); | |
585 | sgl->addr_lo = cpu_to_le32(putPaddrLow(nCmd->rspdma)); | |
586 | sgl->word2 = le32_to_cpu(sgl->word2); | |
587 | if (nCmd->sg_cnt) | |
588 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
589 | else | |
590 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
591 | sgl->word2 = cpu_to_le32(sgl->word2); | |
592 | sgl->sge_len = cpu_to_le32(nCmd->rsplen); | |
593 | ||
594 | /* | |
595 | * Get a local pointer to the built-in wqe and correct | |
596 | * the cmd size to match NVME's 96 bytes and fix | |
597 | * the dma address. | |
598 | */ | |
599 | ||
600 | /* 128 byte wqe support here */ | |
601 | wqe = (union lpfc_wqe128 *)&lpfc_ncmd->cur_iocbq.wqe; | |
602 | ||
603 | /* Word 0-2 - NVME CMND IU (embedded payload) */ | |
604 | wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_IMMED; | |
605 | wqe->generic.bde.tus.f.bdeSize = 60; | |
606 | wqe->generic.bde.addrHigh = 0; | |
607 | wqe->generic.bde.addrLow = 64; /* Word 16 */ | |
608 | ||
609 | /* Word 3 */ | |
610 | bf_set(payload_offset_len, &wqe->fcp_icmd, | |
611 | (nCmd->rsplen + nCmd->cmdlen)); | |
612 | ||
613 | /* Word 10 */ | |
614 | bf_set(wqe_nvme, &wqe->fcp_icmd.wqe_com, 1); | |
615 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); | |
616 | ||
617 | /* | |
618 | * Embed the payload in the last half of the WQE | |
619 | * WQE words 16-30 get the NVME CMD IU payload | |
620 | * | |
621 | * WQE Word 16 is already setup with flags | |
622 | * WQE words 17-19 get payload Words 2-4 | |
623 | * WQE words 20-21 get payload Words 6-7 | |
624 | * WQE words 22-29 get payload Words 16-23 | |
625 | */ | |
626 | wptr = &wqe->words[17]; /* WQE ptr */ | |
627 | dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */ | |
628 | dptr += 2; /* Skip Words 0-1 in payload */ | |
629 | ||
630 | *wptr++ = *dptr++; /* Word 2 */ | |
631 | *wptr++ = *dptr++; /* Word 3 */ | |
632 | *wptr++ = *dptr++; /* Word 4 */ | |
633 | dptr++; /* Skip Word 5 in payload */ | |
634 | *wptr++ = *dptr++; /* Word 6 */ | |
635 | *wptr++ = *dptr++; /* Word 7 */ | |
636 | dptr += 8; /* Skip Words 8-15 in payload */ | |
637 | *wptr++ = *dptr++; /* Word 16 */ | |
638 | *wptr++ = *dptr++; /* Word 17 */ | |
639 | *wptr++ = *dptr++; /* Word 18 */ | |
640 | *wptr++ = *dptr++; /* Word 19 */ | |
641 | *wptr++ = *dptr++; /* Word 20 */ | |
642 | *wptr++ = *dptr++; /* Word 21 */ | |
643 | *wptr++ = *dptr++; /* Word 22 */ | |
644 | *wptr = *dptr; /* Word 23 */ | |
645 | } | |
646 | ||
bd2cdd5e JS |
647 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
648 | static void | |
649 | lpfc_nvme_ktime(struct lpfc_hba *phba, | |
650 | struct lpfc_nvme_buf *lpfc_ncmd) | |
651 | { | |
652 | uint64_t seg1, seg2, seg3, seg4; | |
653 | ||
654 | if (!phba->ktime_on) | |
655 | return; | |
656 | if (!lpfc_ncmd->ts_last_cmd || | |
657 | !lpfc_ncmd->ts_cmd_start || | |
658 | !lpfc_ncmd->ts_cmd_wqput || | |
659 | !lpfc_ncmd->ts_isr_cmpl || | |
660 | !lpfc_ncmd->ts_data_nvme) | |
661 | return; | |
662 | if (lpfc_ncmd->ts_cmd_start < lpfc_ncmd->ts_last_cmd) | |
663 | return; | |
664 | if (lpfc_ncmd->ts_cmd_wqput < lpfc_ncmd->ts_cmd_start) | |
665 | return; | |
666 | if (lpfc_ncmd->ts_isr_cmpl < lpfc_ncmd->ts_cmd_wqput) | |
667 | return; | |
668 | if (lpfc_ncmd->ts_data_nvme < lpfc_ncmd->ts_isr_cmpl) | |
669 | return; | |
670 | /* | |
671 | * Segment 1 - Time from Last FCP command cmpl is handed | |
672 | * off to NVME Layer to start of next command. | |
673 | * Segment 2 - Time from Driver receives a IO cmd start | |
674 | * from NVME Layer to WQ put is done on IO cmd. | |
675 | * Segment 3 - Time from Driver WQ put is done on IO cmd | |
676 | * to MSI-X ISR for IO cmpl. | |
677 | * Segment 4 - Time from MSI-X ISR for IO cmpl to when | |
678 | * cmpl is handled off to the NVME Layer. | |
679 | */ | |
680 | seg1 = lpfc_ncmd->ts_cmd_start - lpfc_ncmd->ts_last_cmd; | |
681 | if (seg1 > 5000000) /* 5 ms - for sequential IOs */ | |
682 | return; | |
683 | ||
684 | /* Calculate times relative to start of IO */ | |
685 | seg2 = (lpfc_ncmd->ts_cmd_wqput - lpfc_ncmd->ts_cmd_start); | |
686 | seg3 = (lpfc_ncmd->ts_isr_cmpl - | |
687 | lpfc_ncmd->ts_cmd_start) - seg2; | |
688 | seg4 = (lpfc_ncmd->ts_data_nvme - | |
689 | lpfc_ncmd->ts_cmd_start) - seg2 - seg3; | |
690 | phba->ktime_data_samples++; | |
691 | phba->ktime_seg1_total += seg1; | |
692 | if (seg1 < phba->ktime_seg1_min) | |
693 | phba->ktime_seg1_min = seg1; | |
694 | else if (seg1 > phba->ktime_seg1_max) | |
695 | phba->ktime_seg1_max = seg1; | |
696 | phba->ktime_seg2_total += seg2; | |
697 | if (seg2 < phba->ktime_seg2_min) | |
698 | phba->ktime_seg2_min = seg2; | |
699 | else if (seg2 > phba->ktime_seg2_max) | |
700 | phba->ktime_seg2_max = seg2; | |
701 | phba->ktime_seg3_total += seg3; | |
702 | if (seg3 < phba->ktime_seg3_min) | |
703 | phba->ktime_seg3_min = seg3; | |
704 | else if (seg3 > phba->ktime_seg3_max) | |
705 | phba->ktime_seg3_max = seg3; | |
706 | phba->ktime_seg4_total += seg4; | |
707 | if (seg4 < phba->ktime_seg4_min) | |
708 | phba->ktime_seg4_min = seg4; | |
709 | else if (seg4 > phba->ktime_seg4_max) | |
710 | phba->ktime_seg4_max = seg4; | |
711 | ||
712 | lpfc_ncmd->ts_last_cmd = 0; | |
713 | lpfc_ncmd->ts_cmd_start = 0; | |
714 | lpfc_ncmd->ts_cmd_wqput = 0; | |
715 | lpfc_ncmd->ts_isr_cmpl = 0; | |
716 | lpfc_ncmd->ts_data_nvme = 0; | |
717 | } | |
718 | #endif | |
719 | ||
01649561 JS |
720 | /** |
721 | * lpfc_nvme_io_cmd_wqe_cmpl - Complete an NVME-over-FCP IO | |
722 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
723 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
724 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
725 | * | |
726 | * Driver registers this routine as it io request handler. This | |
727 | * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq | |
728 | * data structure to the rport indicated in @lpfc_nvme_rport. | |
729 | * | |
730 | * Return value : | |
731 | * 0 - Success | |
732 | * TODO: What are the failure codes. | |
733 | **/ | |
734 | static void | |
735 | lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn, | |
736 | struct lpfc_wcqe_complete *wcqe) | |
737 | { | |
738 | struct lpfc_nvme_buf *lpfc_ncmd = | |
739 | (struct lpfc_nvme_buf *)pwqeIn->context1; | |
740 | struct lpfc_vport *vport = pwqeIn->vport; | |
741 | struct nvmefc_fcp_req *nCmd; | |
742 | struct nvme_fc_ersp_iu *ep; | |
743 | struct nvme_fc_cmd_iu *cp; | |
744 | struct lpfc_nvme_rport *rport; | |
745 | struct lpfc_nodelist *ndlp; | |
746 | unsigned long flags; | |
747 | uint32_t code; | |
748 | uint16_t cid, sqhd, data; | |
749 | uint32_t *ptr; | |
750 | ||
751 | /* Sanity check on return of outstanding command */ | |
752 | if (!lpfc_ncmd || !lpfc_ncmd->nvmeCmd || !lpfc_ncmd->nrport) { | |
753 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, | |
754 | "6071 Completion pointers bad on wqe %p.\n", | |
755 | wcqe); | |
756 | return; | |
757 | } | |
758 | phba->fc4NvmeIoCmpls++; | |
759 | ||
760 | nCmd = lpfc_ncmd->nvmeCmd; | |
761 | rport = lpfc_ncmd->nrport; | |
762 | ||
bd2cdd5e JS |
763 | lpfc_nvmeio_data(phba, "NVME FCP CMPL: xri x%x stat x%x parm x%x\n", |
764 | lpfc_ncmd->cur_iocbq.sli4_xritag, | |
765 | bf_get(lpfc_wcqe_c_status, wcqe), wcqe->parameter); | |
01649561 JS |
766 | /* |
767 | * Catch race where our node has transitioned, but the | |
768 | * transport is still transitioning. | |
769 | */ | |
770 | ndlp = rport->ndlp; | |
771 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | |
772 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, | |
773 | "6061 rport %p, ndlp %p, DID x%06x ndlp " | |
774 | "not ready.\n", | |
775 | rport, ndlp, rport->remoteport->port_id); | |
776 | ||
777 | ndlp = lpfc_findnode_did(vport, rport->remoteport->port_id); | |
778 | if (!ndlp) { | |
779 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, | |
780 | "6062 Ignoring NVME cmpl. No ndlp\n"); | |
781 | goto out_err; | |
782 | } | |
783 | } | |
784 | ||
785 | code = bf_get(lpfc_wcqe_c_code, wcqe); | |
786 | if (code == CQE_CODE_NVME_ERSP) { | |
787 | /* For this type of CQE, we need to rebuild the rsp */ | |
788 | ep = (struct nvme_fc_ersp_iu *)nCmd->rspaddr; | |
789 | ||
790 | /* | |
791 | * Get Command Id from cmd to plug into response. This | |
792 | * code is not needed in the next NVME Transport drop. | |
793 | */ | |
794 | cp = (struct nvme_fc_cmd_iu *)nCmd->cmdaddr; | |
795 | cid = cp->sqe.common.command_id; | |
796 | ||
797 | /* | |
798 | * RSN is in CQE word 2 | |
799 | * SQHD is in CQE Word 3 bits 15:0 | |
800 | * Cmd Specific info is in CQE Word 1 | |
801 | * and in CQE Word 0 bits 15:0 | |
802 | */ | |
803 | sqhd = bf_get(lpfc_wcqe_c_sqhead, wcqe); | |
804 | ||
805 | /* Now lets build the NVME ERSP IU */ | |
806 | ep->iu_len = cpu_to_be16(8); | |
807 | ep->rsn = wcqe->parameter; | |
808 | ep->xfrd_len = cpu_to_be32(nCmd->payload_length); | |
809 | ep->rsvd12 = 0; | |
810 | ptr = (uint32_t *)&ep->cqe.result.u64; | |
811 | *ptr++ = wcqe->total_data_placed; | |
812 | data = bf_get(lpfc_wcqe_c_ersp0, wcqe); | |
813 | *ptr = (uint32_t)data; | |
814 | ep->cqe.sq_head = sqhd; | |
815 | ep->cqe.sq_id = nCmd->sqid; | |
816 | ep->cqe.command_id = cid; | |
817 | ep->cqe.status = 0; | |
818 | ||
819 | lpfc_ncmd->status = IOSTAT_SUCCESS; | |
820 | lpfc_ncmd->result = 0; | |
821 | nCmd->rcv_rsplen = LPFC_NVME_ERSP_LEN; | |
822 | nCmd->transferred_length = nCmd->payload_length; | |
823 | } else { | |
824 | lpfc_ncmd->status = (bf_get(lpfc_wcqe_c_status, wcqe) & | |
825 | LPFC_IOCB_STATUS_MASK); | |
826 | lpfc_ncmd->result = wcqe->parameter; | |
827 | ||
828 | /* For NVME, the only failure path that results in an | |
829 | * IO error is when the adapter rejects it. All other | |
830 | * conditions are a success case and resolved by the | |
831 | * transport. | |
832 | * IOSTAT_FCP_RSP_ERROR means: | |
833 | * 1. Length of data received doesn't match total | |
834 | * transfer length in WQE | |
835 | * 2. If the RSP payload does NOT match these cases: | |
836 | * a. RSP length 12/24 bytes and all zeros | |
837 | * b. NVME ERSP | |
838 | */ | |
839 | switch (lpfc_ncmd->status) { | |
840 | case IOSTAT_SUCCESS: | |
841 | nCmd->transferred_length = wcqe->total_data_placed; | |
842 | nCmd->rcv_rsplen = 0; | |
843 | nCmd->status = 0; | |
844 | break; | |
845 | case IOSTAT_FCP_RSP_ERROR: | |
846 | nCmd->transferred_length = wcqe->total_data_placed; | |
847 | nCmd->rcv_rsplen = wcqe->parameter; | |
848 | nCmd->status = 0; | |
849 | /* Sanity check */ | |
850 | if (nCmd->rcv_rsplen == LPFC_NVME_ERSP_LEN) | |
851 | break; | |
852 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, | |
853 | "6081 NVME Completion Protocol Error: " | |
854 | "status x%x result x%x placed x%x\n", | |
855 | lpfc_ncmd->status, lpfc_ncmd->result, | |
856 | wcqe->total_data_placed); | |
857 | break; | |
858 | default: | |
859 | out_err: | |
860 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, | |
861 | "6072 NVME Completion Error: " | |
862 | "status x%x result x%x placed x%x\n", | |
863 | lpfc_ncmd->status, lpfc_ncmd->result, | |
864 | wcqe->total_data_placed); | |
865 | nCmd->transferred_length = 0; | |
866 | nCmd->rcv_rsplen = 0; | |
867 | nCmd->status = NVME_SC_FC_TRANSPORT_ERROR; | |
868 | } | |
869 | } | |
870 | ||
871 | /* pick up SLI4 exhange busy condition */ | |
872 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) | |
873 | lpfc_ncmd->flags |= LPFC_SBUF_XBUSY; | |
874 | else | |
875 | lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY; | |
876 | ||
877 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) | |
878 | atomic_dec(&ndlp->cmd_pending); | |
879 | ||
880 | /* Update stats and complete the IO. There is | |
881 | * no need for dma unprep because the nvme_transport | |
882 | * owns the dma address. | |
883 | */ | |
bd2cdd5e JS |
884 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
885 | if (phba->ktime_on) { | |
886 | lpfc_ncmd->ts_isr_cmpl = pwqeIn->isr_timestamp; | |
887 | lpfc_ncmd->ts_data_nvme = ktime_get_ns(); | |
888 | phba->ktime_last_cmd = lpfc_ncmd->ts_data_nvme; | |
889 | lpfc_nvme_ktime(phba, lpfc_ncmd); | |
890 | } | |
891 | if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) { | |
892 | if (lpfc_ncmd->cpu != smp_processor_id()) | |
893 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, | |
894 | "6701 CPU Check cmpl: " | |
895 | "cpu %d expect %d\n", | |
896 | smp_processor_id(), lpfc_ncmd->cpu); | |
897 | if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT) | |
898 | phba->cpucheck_cmpl_io[lpfc_ncmd->cpu]++; | |
899 | } | |
900 | #endif | |
01649561 JS |
901 | nCmd->done(nCmd); |
902 | ||
903 | spin_lock_irqsave(&phba->hbalock, flags); | |
904 | lpfc_ncmd->nrport = NULL; | |
905 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
906 | ||
907 | lpfc_release_nvme_buf(phba, lpfc_ncmd); | |
908 | } | |
909 | ||
910 | ||
911 | /** | |
912 | * lpfc_nvme_prep_io_cmd - Issue an NVME-over-FCP IO | |
913 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
914 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
915 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
916 | * @lpfc_nvme_fcreq: IO request from nvme fc to driver. | |
917 | * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue | |
918 | * | |
919 | * Driver registers this routine as it io request handler. This | |
920 | * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq | |
921 | * data structure to the rport indicated in @lpfc_nvme_rport. | |
922 | * | |
923 | * Return value : | |
924 | * 0 - Success | |
925 | * TODO: What are the failure codes. | |
926 | **/ | |
927 | static int | |
928 | lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport, | |
929 | struct lpfc_nvme_buf *lpfc_ncmd, | |
930 | struct lpfc_nodelist *pnode) | |
931 | { | |
932 | struct lpfc_hba *phba = vport->phba; | |
933 | struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd; | |
934 | struct lpfc_iocbq *pwqeq = &(lpfc_ncmd->cur_iocbq); | |
935 | union lpfc_wqe128 *wqe = (union lpfc_wqe128 *)&pwqeq->wqe; | |
936 | uint32_t req_len; | |
937 | ||
938 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) | |
939 | return -EINVAL; | |
940 | ||
941 | /* | |
942 | * There are three possibilities here - use scatter-gather segment, use | |
943 | * the single mapping, or neither. | |
944 | */ | |
945 | wqe->fcp_iwrite.initial_xfer_len = 0; | |
946 | if (nCmd->sg_cnt) { | |
947 | if (nCmd->io_dir == NVMEFC_FCP_WRITE) { | |
948 | /* Word 5 */ | |
949 | if ((phba->cfg_nvme_enable_fb) && | |
950 | (pnode->nlp_flag & NLP_FIRSTBURST)) { | |
951 | req_len = lpfc_ncmd->nvmeCmd->payload_length; | |
952 | if (req_len < pnode->nvme_fb_size) | |
953 | wqe->fcp_iwrite.initial_xfer_len = | |
954 | req_len; | |
955 | else | |
956 | wqe->fcp_iwrite.initial_xfer_len = | |
957 | pnode->nvme_fb_size; | |
958 | } | |
959 | ||
960 | /* Word 7 */ | |
961 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, | |
962 | CMD_FCP_IWRITE64_WQE); | |
963 | bf_set(wqe_pu, &wqe->generic.wqe_com, | |
964 | PARM_READ_CHECK); | |
965 | ||
966 | /* Word 10 */ | |
967 | bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0); | |
968 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, | |
969 | LPFC_WQE_IOD_WRITE); | |
970 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
971 | LPFC_WQE_LENLOC_WORD4); | |
972 | if (phba->cfg_nvme_oas) | |
973 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); | |
974 | ||
975 | /* Word 11 */ | |
976 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, | |
977 | NVME_WRITE_CMD); | |
978 | ||
979 | /* Word 16 */ | |
980 | wqe->words[16] = LPFC_NVME_EMBED_WRITE; | |
981 | ||
982 | phba->fc4NvmeOutputRequests++; | |
983 | } else { | |
984 | /* Word 7 */ | |
985 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, | |
986 | CMD_FCP_IREAD64_WQE); | |
987 | bf_set(wqe_pu, &wqe->generic.wqe_com, | |
988 | PARM_READ_CHECK); | |
989 | ||
990 | /* Word 10 */ | |
991 | bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0); | |
992 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, | |
993 | LPFC_WQE_IOD_READ); | |
994 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
995 | LPFC_WQE_LENLOC_WORD4); | |
996 | if (phba->cfg_nvme_oas) | |
997 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); | |
998 | ||
999 | /* Word 11 */ | |
1000 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, | |
1001 | NVME_READ_CMD); | |
1002 | ||
1003 | /* Word 16 */ | |
1004 | wqe->words[16] = LPFC_NVME_EMBED_READ; | |
1005 | ||
1006 | phba->fc4NvmeInputRequests++; | |
1007 | } | |
1008 | } else { | |
1009 | /* Word 4 */ | |
1010 | wqe->fcp_icmd.rsrvd4 = 0; | |
1011 | ||
1012 | /* Word 7 */ | |
1013 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_FCP_ICMND64_WQE); | |
1014 | bf_set(wqe_pu, &wqe->generic.wqe_com, 0); | |
1015 | ||
1016 | /* Word 10 */ | |
1017 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
1018 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
1019 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
1020 | LPFC_WQE_LENLOC_NONE); | |
1021 | if (phba->cfg_nvme_oas) | |
1022 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); | |
1023 | ||
1024 | /* Word 11 */ | |
1025 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, NVME_READ_CMD); | |
1026 | ||
1027 | /* Word 16 */ | |
1028 | wqe->words[16] = LPFC_NVME_EMBED_CMD; | |
1029 | ||
1030 | phba->fc4NvmeControlRequests++; | |
1031 | } | |
1032 | /* | |
1033 | * Finish initializing those WQE fields that are independent | |
1034 | * of the nvme_cmnd request_buffer | |
1035 | */ | |
1036 | ||
1037 | /* Word 6 */ | |
1038 | bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, | |
1039 | phba->sli4_hba.rpi_ids[pnode->nlp_rpi]); | |
1040 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, pwqeq->sli4_xritag); | |
1041 | ||
1042 | /* Word 7 */ | |
1043 | /* Preserve Class data in the ndlp. */ | |
1044 | bf_set(wqe_class, &wqe->generic.wqe_com, | |
1045 | (pnode->nlp_fcp_info & 0x0f)); | |
1046 | ||
1047 | /* Word 8 */ | |
1048 | wqe->generic.wqe_com.abort_tag = pwqeq->iotag; | |
1049 | ||
1050 | /* Word 9 */ | |
1051 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, pwqeq->iotag); | |
1052 | ||
1053 | /* Word 11 */ | |
1054 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
1055 | ||
1056 | pwqeq->vport = vport; | |
1057 | return 0; | |
1058 | } | |
1059 | ||
1060 | ||
1061 | /** | |
1062 | * lpfc_nvme_prep_io_dma - Issue an NVME-over-FCP IO | |
1063 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
1064 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
1065 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
1066 | * @lpfc_nvme_fcreq: IO request from nvme fc to driver. | |
1067 | * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue | |
1068 | * | |
1069 | * Driver registers this routine as it io request handler. This | |
1070 | * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq | |
1071 | * data structure to the rport indicated in @lpfc_nvme_rport. | |
1072 | * | |
1073 | * Return value : | |
1074 | * 0 - Success | |
1075 | * TODO: What are the failure codes. | |
1076 | **/ | |
1077 | static int | |
1078 | lpfc_nvme_prep_io_dma(struct lpfc_vport *vport, | |
1079 | struct lpfc_nvme_buf *lpfc_ncmd) | |
1080 | { | |
1081 | struct lpfc_hba *phba = vport->phba; | |
1082 | struct nvmefc_fcp_req *nCmd = lpfc_ncmd->nvmeCmd; | |
1083 | union lpfc_wqe128 *wqe = (union lpfc_wqe128 *)&lpfc_ncmd->cur_iocbq.wqe; | |
1084 | struct sli4_sge *sgl = lpfc_ncmd->nvme_sgl; | |
1085 | struct scatterlist *data_sg; | |
1086 | struct sli4_sge *first_data_sgl; | |
1087 | dma_addr_t physaddr; | |
1088 | uint32_t num_bde = 0; | |
1089 | uint32_t dma_len; | |
1090 | uint32_t dma_offset = 0; | |
1091 | int nseg, i; | |
1092 | ||
1093 | /* Fix up the command and response DMA stuff. */ | |
1094 | lpfc_nvme_adj_fcp_sgls(vport, lpfc_ncmd, nCmd); | |
1095 | ||
1096 | /* | |
1097 | * There are three possibilities here - use scatter-gather segment, use | |
1098 | * the single mapping, or neither. | |
1099 | */ | |
1100 | if (nCmd->sg_cnt) { | |
1101 | /* | |
1102 | * Jump over the cmd and rsp SGEs. The fix routine | |
1103 | * has already adjusted for this. | |
1104 | */ | |
1105 | sgl += 2; | |
1106 | ||
1107 | first_data_sgl = sgl; | |
1108 | lpfc_ncmd->seg_cnt = nCmd->sg_cnt; | |
1109 | if (lpfc_ncmd->seg_cnt > phba->cfg_sg_seg_cnt) { | |
1110 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, | |
1111 | "6058 Too many sg segments from " | |
1112 | "NVME Transport. Max %d, " | |
1113 | "nvmeIO sg_cnt %d\n", | |
1114 | phba->cfg_sg_seg_cnt, | |
1115 | lpfc_ncmd->seg_cnt); | |
1116 | lpfc_ncmd->seg_cnt = 0; | |
1117 | return 1; | |
1118 | } | |
1119 | ||
1120 | /* | |
1121 | * The driver established a maximum scatter-gather segment count | |
1122 | * during probe that limits the number of sg elements in any | |
1123 | * single nvme command. Just run through the seg_cnt and format | |
1124 | * the sge's. | |
1125 | */ | |
1126 | nseg = nCmd->sg_cnt; | |
1127 | data_sg = nCmd->first_sgl; | |
1128 | for (i = 0; i < nseg; i++) { | |
1129 | if (data_sg == NULL) { | |
1130 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, | |
1131 | "6059 dptr err %d, nseg %d\n", | |
1132 | i, nseg); | |
1133 | lpfc_ncmd->seg_cnt = 0; | |
1134 | return 1; | |
1135 | } | |
1136 | physaddr = data_sg->dma_address; | |
1137 | dma_len = data_sg->length; | |
1138 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); | |
1139 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); | |
1140 | sgl->word2 = le32_to_cpu(sgl->word2); | |
1141 | if ((num_bde + 1) == nseg) | |
1142 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
1143 | else | |
1144 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
1145 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); | |
1146 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_DATA); | |
1147 | sgl->word2 = cpu_to_le32(sgl->word2); | |
1148 | sgl->sge_len = cpu_to_le32(dma_len); | |
1149 | ||
1150 | dma_offset += dma_len; | |
1151 | data_sg = sg_next(data_sg); | |
1152 | sgl++; | |
1153 | } | |
1154 | } else { | |
1155 | /* For this clause to be valid, the payload_length | |
1156 | * and sg_cnt must zero. | |
1157 | */ | |
1158 | if (nCmd->payload_length != 0) { | |
1159 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, | |
1160 | "6063 NVME DMA Prep Err: sg_cnt %d " | |
1161 | "payload_length x%x\n", | |
1162 | nCmd->sg_cnt, nCmd->payload_length); | |
1163 | return 1; | |
1164 | } | |
1165 | } | |
1166 | ||
1167 | /* | |
1168 | * Due to difference in data length between DIF/non-DIF paths, | |
1169 | * we need to set word 4 of WQE here | |
1170 | */ | |
1171 | wqe->fcp_iread.total_xfer_len = nCmd->payload_length; | |
1172 | return 0; | |
1173 | } | |
1174 | ||
1175 | /** | |
1176 | * lpfc_nvme_fcp_io_submit - Issue an NVME-over-FCP IO | |
1177 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
1178 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
1179 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
1180 | * @lpfc_nvme_fcreq: IO request from nvme fc to driver. | |
1181 | * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue | |
1182 | * | |
1183 | * Driver registers this routine as it io request handler. This | |
1184 | * routine issues an fcp WQE with data from the @lpfc_nvme_fcpreq | |
1185 | * data structure to the rport | |
1186 | indicated in @lpfc_nvme_rport. | |
1187 | * | |
1188 | * Return value : | |
1189 | * 0 - Success | |
1190 | * TODO: What are the failure codes. | |
1191 | **/ | |
1192 | static int | |
1193 | lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport, | |
1194 | struct nvme_fc_remote_port *pnvme_rport, | |
1195 | void *hw_queue_handle, | |
1196 | struct nvmefc_fcp_req *pnvme_fcreq) | |
1197 | { | |
1198 | int ret = 0; | |
1199 | struct lpfc_nvme_lport *lport; | |
1200 | struct lpfc_vport *vport; | |
1201 | struct lpfc_hba *phba; | |
1202 | struct lpfc_nodelist *ndlp; | |
1203 | struct lpfc_nvme_buf *lpfc_ncmd; | |
1204 | struct lpfc_nvme_rport *rport; | |
1205 | struct lpfc_nvme_qhandle *lpfc_queue_info; | |
bd2cdd5e JS |
1206 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
1207 | uint64_t start = 0; | |
1208 | #endif | |
01649561 JS |
1209 | |
1210 | lport = (struct lpfc_nvme_lport *)pnvme_lport->private; | |
1211 | vport = lport->vport; | |
1212 | phba = vport->phba; | |
1213 | ||
bd2cdd5e JS |
1214 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
1215 | if (phba->ktime_on) | |
1216 | start = ktime_get_ns(); | |
1217 | #endif | |
01649561 JS |
1218 | rport = (struct lpfc_nvme_rport *)pnvme_rport->private; |
1219 | lpfc_queue_info = (struct lpfc_nvme_qhandle *)hw_queue_handle; | |
1220 | ||
1221 | /* | |
1222 | * Catch race where our node has transitioned, but the | |
1223 | * transport is still transitioning. | |
1224 | */ | |
1225 | ndlp = rport->ndlp; | |
1226 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | |
1227 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, | |
1228 | "6053 rport %p, ndlp %p, DID x%06x " | |
1229 | "ndlp not ready.\n", | |
1230 | rport, ndlp, pnvme_rport->port_id); | |
1231 | ||
1232 | ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id); | |
1233 | if (!ndlp) { | |
1234 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, | |
1235 | "6066 Missing node for DID %x\n", | |
1236 | pnvme_rport->port_id); | |
1237 | ret = -ENODEV; | |
1238 | goto out_fail; | |
1239 | } | |
1240 | } | |
1241 | ||
1242 | /* The remote node has to be a mapped target or it's an error. */ | |
1243 | if ((ndlp->nlp_type & NLP_NVME_TARGET) && | |
1244 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | |
1245 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_IOERR, | |
1246 | "6036 rport %p, DID x%06x not ready for " | |
1247 | "IO. State x%x, Type x%x\n", | |
1248 | rport, pnvme_rport->port_id, | |
1249 | ndlp->nlp_state, ndlp->nlp_type); | |
1250 | ret = -ENODEV; | |
1251 | goto out_fail; | |
1252 | ||
1253 | } | |
1254 | ||
1255 | /* The node is shared with FCP IO, make sure the IO pending count does | |
1256 | * not exceed the programmed depth. | |
1257 | */ | |
1258 | if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) { | |
1259 | ret = -EAGAIN; | |
1260 | goto out_fail; | |
1261 | } | |
1262 | ||
1263 | lpfc_ncmd = lpfc_get_nvme_buf(phba, ndlp); | |
1264 | if (lpfc_ncmd == NULL) { | |
1265 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR, | |
1266 | "6065 driver's buffer pool is empty, " | |
1267 | "IO failed\n"); | |
1268 | ret = -ENOMEM; | |
1269 | goto out_fail; | |
1270 | } | |
bd2cdd5e JS |
1271 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
1272 | if (phba->ktime_on) { | |
1273 | lpfc_ncmd->ts_cmd_start = start; | |
1274 | lpfc_ncmd->ts_last_cmd = phba->ktime_last_cmd; | |
1275 | } | |
1276 | #endif | |
01649561 JS |
1277 | |
1278 | /* | |
1279 | * Store the data needed by the driver to issue, abort, and complete | |
1280 | * an IO. | |
1281 | * Do not let the IO hang out forever. There is no midlayer issuing | |
1282 | * an abort so inform the FW of the maximum IO pending time. | |
1283 | */ | |
1284 | pnvme_fcreq->private = (void *)lpfc_ncmd; | |
1285 | lpfc_ncmd->nvmeCmd = pnvme_fcreq; | |
1286 | lpfc_ncmd->nrport = rport; | |
1287 | lpfc_ncmd->start_time = jiffies; | |
1288 | ||
1289 | lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp); | |
1290 | ret = lpfc_nvme_prep_io_dma(vport, lpfc_ncmd); | |
1291 | if (ret) { | |
1292 | ret = -ENOMEM; | |
1293 | goto out_free_nvme_buf; | |
1294 | } | |
1295 | ||
1296 | atomic_inc(&ndlp->cmd_pending); | |
1297 | ||
1298 | /* | |
1299 | * Issue the IO on the WQ indicated by index in the hw_queue_handle. | |
1300 | * This identfier was create in our hardware queue create callback | |
1301 | * routine. The driver now is dependent on the IO queue steering from | |
1302 | * the transport. We are trusting the upper NVME layers know which | |
1303 | * index to use and that they have affinitized a CPU to this hardware | |
1304 | * queue. A hardware queue maps to a driver MSI-X vector/EQ/CQ/WQ. | |
1305 | */ | |
1306 | lpfc_ncmd->cur_iocbq.hba_wqidx = lpfc_queue_info->index; | |
1307 | ||
bd2cdd5e JS |
1308 | lpfc_nvmeio_data(phba, "NVME FCP XMIT: xri x%x idx %d to %06x\n", |
1309 | lpfc_ncmd->cur_iocbq.sli4_xritag, | |
1310 | lpfc_queue_info->index, ndlp->nlp_DID); | |
1311 | ||
01649561 JS |
1312 | ret = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, &lpfc_ncmd->cur_iocbq); |
1313 | if (ret) { | |
1314 | atomic_dec(&ndlp->cmd_pending); | |
1315 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_IOERR, | |
1316 | "6113 FCP could not issue WQE err %x " | |
1317 | "sid: x%x did: x%x oxid: x%x\n", | |
1318 | ret, vport->fc_myDID, ndlp->nlp_DID, | |
1319 | lpfc_ncmd->cur_iocbq.sli4_xritag); | |
1320 | ret = -EINVAL; | |
1321 | goto out_free_nvme_buf; | |
1322 | } | |
1323 | ||
bd2cdd5e JS |
1324 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
1325 | if (phba->ktime_on) | |
1326 | lpfc_ncmd->ts_cmd_wqput = ktime_get_ns(); | |
1327 | ||
1328 | if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) { | |
1329 | lpfc_ncmd->cpu = smp_processor_id(); | |
1330 | if (lpfc_ncmd->cpu != lpfc_queue_info->index) { | |
1331 | /* Check for admin queue */ | |
1332 | if (lpfc_queue_info->qidx) { | |
1333 | lpfc_printf_vlog(vport, | |
1334 | KERN_ERR, LOG_NVME_IOERR, | |
1335 | "6702 CPU Check cmd: " | |
1336 | "cpu %d wq %d\n", | |
1337 | lpfc_ncmd->cpu, | |
1338 | lpfc_queue_info->index); | |
1339 | } | |
1340 | lpfc_ncmd->cpu = lpfc_queue_info->index; | |
1341 | } | |
1342 | if (lpfc_ncmd->cpu < LPFC_CHECK_CPU_CNT) | |
1343 | phba->cpucheck_xmt_io[lpfc_ncmd->cpu]++; | |
1344 | } | |
1345 | #endif | |
01649561 JS |
1346 | return 0; |
1347 | ||
1348 | out_free_nvme_buf: | |
1349 | lpfc_release_nvme_buf(phba, lpfc_ncmd); | |
1350 | out_fail: | |
1351 | return ret; | |
1352 | } | |
1353 | ||
1354 | /** | |
1355 | * lpfc_nvme_abort_fcreq_cmpl - Complete an NVME FCP abort request. | |
1356 | * @phba: Pointer to HBA context object | |
1357 | * @cmdiocb: Pointer to command iocb object. | |
1358 | * @rspiocb: Pointer to response iocb object. | |
1359 | * | |
1360 | * This is the callback function for any NVME FCP IO that was aborted. | |
1361 | * | |
1362 | * Return value: | |
1363 | * None | |
1364 | **/ | |
1365 | void | |
1366 | lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1367 | struct lpfc_wcqe_complete *abts_cmpl) | |
1368 | { | |
1369 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME, | |
1370 | "6145 ABORT_XRI_CN completing on rpi x%x " | |
1371 | "original iotag x%x, abort cmd iotag x%x " | |
1372 | "req_tag x%x, status x%x, hwstatus x%x\n", | |
1373 | cmdiocb->iocb.un.acxri.abortContextTag, | |
1374 | cmdiocb->iocb.un.acxri.abortIoTag, | |
1375 | cmdiocb->iotag, | |
1376 | bf_get(lpfc_wcqe_c_request_tag, abts_cmpl), | |
1377 | bf_get(lpfc_wcqe_c_status, abts_cmpl), | |
1378 | bf_get(lpfc_wcqe_c_hw_status, abts_cmpl)); | |
1379 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
1380 | } | |
1381 | ||
1382 | /** | |
1383 | * lpfc_nvme_fcp_abort - Issue an NVME-over-FCP ABTS | |
1384 | * @lpfc_pnvme: Pointer to the driver's nvme instance data | |
1385 | * @lpfc_nvme_lport: Pointer to the driver's local port data | |
1386 | * @lpfc_nvme_rport: Pointer to the rport getting the @lpfc_nvme_ereq | |
1387 | * @lpfc_nvme_fcreq: IO request from nvme fc to driver. | |
1388 | * @hw_queue_handle: Driver-returned handle in lpfc_nvme_create_queue | |
1389 | * | |
1390 | * Driver registers this routine as its nvme request io abort handler. This | |
1391 | * routine issues an fcp Abort WQE with data from the @lpfc_nvme_fcpreq | |
1392 | * data structure to the rport indicated in @lpfc_nvme_rport. This routine | |
1393 | * is executed asynchronously - one the target is validated as "MAPPED" and | |
1394 | * ready for IO, the driver issues the abort request and returns. | |
1395 | * | |
1396 | * Return value: | |
1397 | * None | |
1398 | **/ | |
1399 | static void | |
1400 | lpfc_nvme_fcp_abort(struct nvme_fc_local_port *pnvme_lport, | |
1401 | struct nvme_fc_remote_port *pnvme_rport, | |
1402 | void *hw_queue_handle, | |
1403 | struct nvmefc_fcp_req *pnvme_fcreq) | |
1404 | { | |
1405 | struct lpfc_nvme_lport *lport; | |
1406 | struct lpfc_vport *vport; | |
1407 | struct lpfc_hba *phba; | |
1408 | struct lpfc_nodelist *ndlp; | |
1409 | struct lpfc_nvme_rport *rport; | |
1410 | struct lpfc_nvme_buf *lpfc_nbuf; | |
1411 | struct lpfc_iocbq *abts_buf; | |
1412 | struct lpfc_iocbq *nvmereq_wqe; | |
1413 | union lpfc_wqe *abts_wqe; | |
1414 | unsigned long flags; | |
1415 | int ret_val; | |
1416 | ||
1417 | lport = (struct lpfc_nvme_lport *)pnvme_lport->private; | |
1418 | rport = (struct lpfc_nvme_rport *)pnvme_rport->private; | |
1419 | vport = lport->vport; | |
1420 | phba = vport->phba; | |
1421 | ||
1422 | /* Announce entry to new IO submit field. */ | |
1423 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, | |
1424 | "6002 Abort Request to rport DID x%06x " | |
1425 | "for nvme_fc_req %p\n", | |
1426 | pnvme_rport->port_id, | |
1427 | pnvme_fcreq); | |
1428 | ||
1429 | /* | |
1430 | * Catch race where our node has transitioned, but the | |
1431 | * transport is still transitioning. | |
1432 | */ | |
1433 | ndlp = rport->ndlp; | |
1434 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | |
1435 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_ABTS, | |
1436 | "6054 rport %p, ndlp %p, DID x%06x ndlp " | |
1437 | " not ready.\n", | |
1438 | rport, ndlp, pnvme_rport->port_id); | |
1439 | ||
1440 | ndlp = lpfc_findnode_did(vport, pnvme_rport->port_id); | |
1441 | if (!ndlp) { | |
1442 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_ABTS, | |
1443 | "6055 Could not find node for " | |
1444 | "DID %x\n", | |
1445 | pnvme_rport->port_id); | |
1446 | return; | |
1447 | } | |
1448 | } | |
1449 | ||
1450 | /* The remote node has to be ready to send an abort. */ | |
1451 | if ((ndlp->nlp_state != NLP_STE_MAPPED_NODE) && | |
1452 | !(ndlp->nlp_type & NLP_NVME_TARGET)) { | |
1453 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE | LOG_NVME_ABTS, | |
1454 | "6048 rport %p, DID x%06x not ready for " | |
1455 | "IO. State x%x, Type x%x\n", | |
1456 | rport, pnvme_rport->port_id, | |
1457 | ndlp->nlp_state, ndlp->nlp_type); | |
1458 | return; | |
1459 | } | |
1460 | ||
1461 | /* If the hba is getting reset, this flag is set. It is | |
1462 | * cleared when the reset is complete and rings reestablished. | |
1463 | */ | |
1464 | spin_lock_irqsave(&phba->hbalock, flags); | |
1465 | /* driver queued commands are in process of being flushed */ | |
1466 | if (phba->hba_flag & HBA_NVME_IOQ_FLUSH) { | |
1467 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1468 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1469 | "6139 Driver in reset cleanup - flushing " | |
1470 | "NVME Req now. hba_flag x%x\n", | |
1471 | phba->hba_flag); | |
1472 | return; | |
1473 | } | |
1474 | ||
1475 | lpfc_nbuf = (struct lpfc_nvme_buf *)pnvme_fcreq->private; | |
1476 | if (!lpfc_nbuf) { | |
1477 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1478 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1479 | "6140 NVME IO req has no matching lpfc nvme " | |
1480 | "io buffer. Skipping abort req.\n"); | |
1481 | return; | |
1482 | } else if (!lpfc_nbuf->nvmeCmd) { | |
1483 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1484 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1485 | "6141 lpfc NVME IO req has no nvme_fcreq " | |
1486 | "io buffer. Skipping abort req.\n"); | |
1487 | return; | |
1488 | } | |
1489 | ||
1490 | /* | |
1491 | * The lpfc_nbuf and the mapped nvme_fcreq in the driver's | |
1492 | * state must match the nvme_fcreq passed by the nvme | |
1493 | * transport. If they don't match, it is likely the driver | |
1494 | * has already completed the NVME IO and the nvme transport | |
1495 | * has not seen it yet. | |
1496 | */ | |
1497 | if (lpfc_nbuf->nvmeCmd != pnvme_fcreq) { | |
1498 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1499 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1500 | "6143 NVME req mismatch: " | |
1501 | "lpfc_nbuf %p nvmeCmd %p, " | |
1502 | "pnvme_fcreq %p. Skipping Abort\n", | |
1503 | lpfc_nbuf, lpfc_nbuf->nvmeCmd, | |
1504 | pnvme_fcreq); | |
1505 | return; | |
1506 | } | |
1507 | ||
1508 | /* Don't abort IOs no longer on the pending queue. */ | |
1509 | nvmereq_wqe = &lpfc_nbuf->cur_iocbq; | |
1510 | if (!(nvmereq_wqe->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { | |
1511 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1512 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1513 | "6142 NVME IO req %p not queued - skipping " | |
1514 | "abort req\n", | |
1515 | pnvme_fcreq); | |
1516 | return; | |
1517 | } | |
1518 | ||
bd2cdd5e JS |
1519 | lpfc_nvmeio_data(phba, "NVME FCP ABORT: xri x%x idx %d to %06x\n", |
1520 | nvmereq_wqe->sli4_xritag, | |
1521 | nvmereq_wqe->hba_wqidx, ndlp->nlp_DID); | |
1522 | ||
01649561 JS |
1523 | /* Outstanding abort is in progress */ |
1524 | if (nvmereq_wqe->iocb_flag & LPFC_DRIVER_ABORTED) { | |
1525 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1526 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1527 | "6144 Outstanding NVME I/O Abort Request " | |
1528 | "still pending on nvme_fcreq %p, " | |
1529 | "lpfc_ncmd %p\n", | |
1530 | pnvme_fcreq, lpfc_nbuf); | |
1531 | return; | |
1532 | } | |
1533 | ||
1534 | abts_buf = __lpfc_sli_get_iocbq(phba); | |
1535 | if (!abts_buf) { | |
1536 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1537 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1538 | "6136 No available abort wqes. Skipping " | |
1539 | "Abts req for nvme_fcreq %p.\n", | |
1540 | pnvme_fcreq); | |
1541 | return; | |
1542 | } | |
1543 | ||
1544 | /* Ready - mark outstanding as aborted by driver. */ | |
1545 | nvmereq_wqe->iocb_flag |= LPFC_DRIVER_ABORTED; | |
1546 | ||
1547 | /* Complete prepping the abort wqe and issue to the FW. */ | |
1548 | abts_wqe = &abts_buf->wqe; | |
1549 | ||
1550 | /* WQEs are reused. Clear stale data and set key fields to | |
1551 | * zero like ia, iaab, iaar, xri_tag, and ctxt_tag. | |
1552 | */ | |
1553 | memset(abts_wqe, 0, sizeof(union lpfc_wqe)); | |
1554 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); | |
1555 | ||
1556 | /* word 7 */ | |
1557 | bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); | |
1558 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); | |
1559 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, | |
1560 | nvmereq_wqe->iocb.ulpClass); | |
1561 | ||
1562 | /* word 8 - tell the FW to abort the IO associated with this | |
1563 | * outstanding exchange ID. | |
1564 | */ | |
1565 | abts_wqe->abort_cmd.wqe_com.abort_tag = nvmereq_wqe->sli4_xritag; | |
1566 | ||
1567 | /* word 9 - this is the iotag for the abts_wqe completion. */ | |
1568 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, | |
1569 | abts_buf->iotag); | |
1570 | ||
1571 | /* word 10 */ | |
1572 | bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, nvmereq_wqe->hba_wqidx); | |
1573 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); | |
1574 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); | |
1575 | ||
1576 | /* word 11 */ | |
1577 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); | |
1578 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); | |
1579 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
1580 | ||
1581 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
1582 | abts_buf->iocb_flag |= LPFC_IO_NVME; | |
1583 | abts_buf->hba_wqidx = nvmereq_wqe->hba_wqidx; | |
1584 | abts_buf->vport = vport; | |
1585 | abts_buf->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; | |
1586 | ret_val = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abts_buf); | |
1587 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1588 | if (ret_val == IOCB_ERROR) { | |
1589 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1590 | "6137 Failed abts issue_wqe with status x%x " | |
1591 | "for nvme_fcreq %p.\n", | |
1592 | ret_val, pnvme_fcreq); | |
1593 | lpfc_sli_release_iocbq(phba, abts_buf); | |
1594 | return; | |
1595 | } | |
1596 | ||
1597 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
1598 | "6138 Transport Abort NVME Request Issued for\n" | |
1599 | "ox_id x%x on reqtag x%x\n", | |
1600 | nvmereq_wqe->sli4_xritag, | |
1601 | abts_buf->iotag); | |
1602 | } | |
1603 | ||
1604 | /* Declare and initialization an instance of the FC NVME template. */ | |
1605 | static struct nvme_fc_port_template lpfc_nvme_template = { | |
1606 | /* initiator-based functions */ | |
1607 | .localport_delete = lpfc_nvme_localport_delete, | |
1608 | .remoteport_delete = lpfc_nvme_remoteport_delete, | |
1609 | .create_queue = lpfc_nvme_create_queue, | |
1610 | .delete_queue = lpfc_nvme_delete_queue, | |
1611 | .ls_req = lpfc_nvme_ls_req, | |
1612 | .fcp_io = lpfc_nvme_fcp_io_submit, | |
1613 | .ls_abort = lpfc_nvme_ls_abort, | |
1614 | .fcp_abort = lpfc_nvme_fcp_abort, | |
1615 | ||
1616 | .max_hw_queues = 1, | |
1617 | .max_sgl_segments = LPFC_NVME_DEFAULT_SEGS, | |
1618 | .max_dif_sgl_segments = LPFC_NVME_DEFAULT_SEGS, | |
1619 | .dma_boundary = 0xFFFFFFFF, | |
1620 | ||
1621 | /* Sizes of additional private data for data structures. | |
1622 | * No use for the last two sizes at this time. | |
1623 | */ | |
1624 | .local_priv_sz = sizeof(struct lpfc_nvme_lport), | |
1625 | .remote_priv_sz = sizeof(struct lpfc_nvme_rport), | |
1626 | .lsrqst_priv_sz = 0, | |
1627 | .fcprqst_priv_sz = 0, | |
1628 | }; | |
1629 | ||
1630 | /** | |
1631 | * lpfc_sli4_post_nvme_sgl_block - post a block of nvme sgl list to firmware | |
1632 | * @phba: pointer to lpfc hba data structure. | |
1633 | * @nblist: pointer to nvme buffer list. | |
1634 | * @count: number of scsi buffers on the list. | |
1635 | * | |
1636 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
1637 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. | |
1638 | * No Lock is held. | |
1639 | * | |
1640 | **/ | |
1641 | static int | |
1642 | lpfc_sli4_post_nvme_sgl_block(struct lpfc_hba *phba, | |
1643 | struct list_head *nblist, | |
1644 | int count) | |
1645 | { | |
1646 | struct lpfc_nvme_buf *lpfc_ncmd; | |
1647 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
1648 | struct sgl_page_pairs *sgl_pg_pairs; | |
1649 | void *viraddr; | |
1650 | LPFC_MBOXQ_t *mbox; | |
1651 | uint32_t reqlen, alloclen, pg_pairs; | |
1652 | uint32_t mbox_tmo; | |
1653 | uint16_t xritag_start = 0; | |
1654 | int rc = 0; | |
1655 | uint32_t shdr_status, shdr_add_status; | |
1656 | dma_addr_t pdma_phys_bpl1; | |
1657 | union lpfc_sli4_cfg_shdr *shdr; | |
1658 | ||
1659 | /* Calculate the requested length of the dma memory */ | |
1660 | reqlen = count * sizeof(struct sgl_page_pairs) + | |
1661 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
1662 | if (reqlen > SLI4_PAGE_SIZE) { | |
1663 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
1664 | "6118 Block sgl registration required DMA " | |
1665 | "size (%d) great than a page\n", reqlen); | |
1666 | return -ENOMEM; | |
1667 | } | |
1668 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1669 | if (!mbox) { | |
1670 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1671 | "6119 Failed to allocate mbox cmd memory\n"); | |
1672 | return -ENOMEM; | |
1673 | } | |
1674 | ||
1675 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
1676 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
1677 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
1678 | LPFC_SLI4_MBX_NEMBED); | |
1679 | ||
1680 | if (alloclen < reqlen) { | |
1681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1682 | "6120 Allocated DMA memory size (%d) is " | |
1683 | "less than the requested DMA memory " | |
1684 | "size (%d)\n", alloclen, reqlen); | |
1685 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
1686 | return -ENOMEM; | |
1687 | } | |
1688 | ||
1689 | /* Get the first SGE entry from the non-embedded DMA memory */ | |
1690 | viraddr = mbox->sge_array->addr[0]; | |
1691 | ||
1692 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
1693 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
1694 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
1695 | ||
1696 | pg_pairs = 0; | |
1697 | list_for_each_entry(lpfc_ncmd, nblist, list) { | |
1698 | /* Set up the sge entry */ | |
1699 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
1700 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); | |
1701 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
1702 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); | |
1703 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
1704 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + | |
1705 | SGL_PAGE_SIZE; | |
1706 | else | |
1707 | pdma_phys_bpl1 = 0; | |
1708 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
1709 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
1710 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
1711 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
1712 | /* Keep the first xritag on the list */ | |
1713 | if (pg_pairs == 0) | |
1714 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; | |
1715 | sgl_pg_pairs++; | |
1716 | pg_pairs++; | |
1717 | } | |
1718 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
1719 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
1720 | /* Perform endian conversion if necessary */ | |
1721 | sgl->word0 = cpu_to_le32(sgl->word0); | |
1722 | ||
1723 | if (!phba->sli4_hba.intr_enable) | |
1724 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
1725 | else { | |
1726 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); | |
1727 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
1728 | } | |
1729 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; | |
1730 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
1731 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
1732 | if (rc != MBX_TIMEOUT) | |
1733 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
1734 | if (shdr_status || shdr_add_status || rc) { | |
1735 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
1736 | "6125 POST_SGL_BLOCK mailbox command failed " | |
1737 | "status x%x add_status x%x mbx status x%x\n", | |
1738 | shdr_status, shdr_add_status, rc); | |
1739 | rc = -ENXIO; | |
1740 | } | |
1741 | return rc; | |
1742 | } | |
1743 | ||
1744 | /** | |
1745 | * lpfc_post_nvme_sgl_list - Post blocks of nvme buffer sgls from a list | |
1746 | * @phba: pointer to lpfc hba data structure. | |
1747 | * @post_nblist: pointer to the nvme buffer list. | |
1748 | * | |
1749 | * This routine walks a list of nvme buffers that was passed in. It attempts | |
1750 | * to construct blocks of nvme buffer sgls which contains contiguous xris and | |
1751 | * uses the non-embedded SGL block post mailbox commands to post to the port. | |
1752 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use | |
1753 | * embedded SGL post mailbox command for posting. The @post_nblist passed in | |
1754 | * must be local list, thus no lock is needed when manipulate the list. | |
1755 | * | |
1756 | * Returns: 0 = failure, non-zero number of successfully posted buffers. | |
1757 | **/ | |
1758 | static int | |
1759 | lpfc_post_nvme_sgl_list(struct lpfc_hba *phba, | |
1760 | struct list_head *post_nblist, int sb_count) | |
1761 | { | |
1762 | struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next; | |
1763 | int status, sgl_size; | |
1764 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; | |
1765 | dma_addr_t pdma_phys_sgl1; | |
1766 | int last_xritag = NO_XRI; | |
1767 | int cur_xritag; | |
1768 | LIST_HEAD(prep_nblist); | |
1769 | LIST_HEAD(blck_nblist); | |
1770 | LIST_HEAD(nvme_nblist); | |
1771 | ||
1772 | /* sanity check */ | |
1773 | if (sb_count <= 0) | |
1774 | return -EINVAL; | |
1775 | ||
1776 | sgl_size = phba->cfg_sg_dma_buf_size; | |
1777 | ||
1778 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { | |
1779 | list_del_init(&lpfc_ncmd->list); | |
1780 | block_cnt++; | |
1781 | if ((last_xritag != NO_XRI) && | |
1782 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { | |
1783 | /* a hole in xri block, form a sgl posting block */ | |
1784 | list_splice_init(&prep_nblist, &blck_nblist); | |
1785 | post_cnt = block_cnt - 1; | |
1786 | /* prepare list for next posting block */ | |
1787 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); | |
1788 | block_cnt = 1; | |
1789 | } else { | |
1790 | /* prepare list for next posting block */ | |
1791 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); | |
1792 | /* enough sgls for non-embed sgl mbox command */ | |
1793 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
1794 | list_splice_init(&prep_nblist, &blck_nblist); | |
1795 | post_cnt = block_cnt; | |
1796 | block_cnt = 0; | |
1797 | } | |
1798 | } | |
1799 | num_posting++; | |
1800 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; | |
1801 | ||
1802 | /* end of repost sgl list condition for NVME buffers */ | |
1803 | if (num_posting == sb_count) { | |
1804 | if (post_cnt == 0) { | |
1805 | /* last sgl posting block */ | |
1806 | list_splice_init(&prep_nblist, &blck_nblist); | |
1807 | post_cnt = block_cnt; | |
1808 | } else if (block_cnt == 1) { | |
1809 | /* last single sgl with non-contiguous xri */ | |
1810 | if (sgl_size > SGL_PAGE_SIZE) | |
1811 | pdma_phys_sgl1 = | |
1812 | lpfc_ncmd->dma_phys_sgl + | |
1813 | SGL_PAGE_SIZE; | |
1814 | else | |
1815 | pdma_phys_sgl1 = 0; | |
1816 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; | |
1817 | status = lpfc_sli4_post_sgl(phba, | |
1818 | lpfc_ncmd->dma_phys_sgl, | |
1819 | pdma_phys_sgl1, cur_xritag); | |
1820 | if (status) { | |
1821 | /* failure, put on abort nvme list */ | |
1822 | lpfc_ncmd->exch_busy = 1; | |
1823 | } else { | |
1824 | /* success, put on NVME buffer list */ | |
1825 | lpfc_ncmd->exch_busy = 0; | |
1826 | lpfc_ncmd->status = IOSTAT_SUCCESS; | |
1827 | num_posted++; | |
1828 | } | |
1829 | /* success, put on NVME buffer sgl list */ | |
1830 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); | |
1831 | } | |
1832 | } | |
1833 | ||
1834 | /* continue until a nembed page worth of sgls */ | |
1835 | if (post_cnt == 0) | |
1836 | continue; | |
1837 | ||
1838 | /* post block of NVME buffer list sgls */ | |
1839 | status = lpfc_sli4_post_nvme_sgl_block(phba, &blck_nblist, | |
1840 | post_cnt); | |
1841 | ||
1842 | /* don't reset xirtag due to hole in xri block */ | |
1843 | if (block_cnt == 0) | |
1844 | last_xritag = NO_XRI; | |
1845 | ||
1846 | /* reset NVME buffer post count for next round of posting */ | |
1847 | post_cnt = 0; | |
1848 | ||
1849 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ | |
1850 | while (!list_empty(&blck_nblist)) { | |
1851 | list_remove_head(&blck_nblist, lpfc_ncmd, | |
1852 | struct lpfc_nvme_buf, list); | |
1853 | if (status) { | |
1854 | /* failure, put on abort nvme list */ | |
1855 | lpfc_ncmd->exch_busy = 1; | |
1856 | } else { | |
1857 | /* success, put on NVME buffer list */ | |
1858 | lpfc_ncmd->exch_busy = 0; | |
1859 | lpfc_ncmd->status = IOSTAT_SUCCESS; | |
1860 | num_posted++; | |
1861 | } | |
1862 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); | |
1863 | } | |
1864 | } | |
1865 | /* Push NVME buffers with sgl posted to the available list */ | |
1866 | while (!list_empty(&nvme_nblist)) { | |
1867 | list_remove_head(&nvme_nblist, lpfc_ncmd, | |
1868 | struct lpfc_nvme_buf, list); | |
1869 | lpfc_release_nvme_buf(phba, lpfc_ncmd); | |
1870 | } | |
1871 | return num_posted; | |
1872 | } | |
1873 | ||
1874 | /** | |
1875 | * lpfc_repost_nvme_sgl_list - Repost all the allocated nvme buffer sgls | |
1876 | * @phba: pointer to lpfc hba data structure. | |
1877 | * | |
1878 | * This routine walks the list of nvme buffers that have been allocated and | |
1879 | * repost them to the port by using SGL block post. This is needed after a | |
1880 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine | |
1881 | * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list | |
1882 | * to the lpfc_nvme_buf_list. If the repost fails, reject all nvme buffers. | |
1883 | * | |
1884 | * Returns: 0 = success, non-zero failure. | |
1885 | **/ | |
1886 | int | |
1887 | lpfc_repost_nvme_sgl_list(struct lpfc_hba *phba) | |
1888 | { | |
1889 | LIST_HEAD(post_nblist); | |
1890 | int num_posted, rc = 0; | |
1891 | ||
1892 | /* get all NVME buffers need to repost to a local list */ | |
1893 | spin_lock_irq(&phba->nvme_buf_list_get_lock); | |
1894 | spin_lock(&phba->nvme_buf_list_put_lock); | |
1895 | list_splice_init(&phba->lpfc_nvme_buf_list_get, &post_nblist); | |
1896 | list_splice(&phba->lpfc_nvme_buf_list_put, &post_nblist); | |
1897 | spin_unlock(&phba->nvme_buf_list_put_lock); | |
1898 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); | |
1899 | ||
1900 | /* post the list of nvme buffer sgls to port if available */ | |
1901 | if (!list_empty(&post_nblist)) { | |
1902 | num_posted = lpfc_post_nvme_sgl_list(phba, &post_nblist, | |
1903 | phba->sli4_hba.nvme_xri_cnt); | |
1904 | /* failed to post any nvme buffer, return error */ | |
1905 | if (num_posted == 0) | |
1906 | rc = -EIO; | |
1907 | } | |
1908 | return rc; | |
1909 | } | |
1910 | ||
1911 | /** | |
1912 | * lpfc_new_nvme_buf - Scsi buffer allocator for HBA with SLI4 IF spec | |
1913 | * @vport: The virtual port for which this call being executed. | |
1914 | * @num_to_allocate: The requested number of buffers to allocate. | |
1915 | * | |
1916 | * This routine allocates nvme buffers for device with SLI-4 interface spec, | |
1917 | * the nvme buffer contains all the necessary information needed to initiate | |
1918 | * a NVME I/O. After allocating up to @num_to_allocate NVME buffers and put | |
1919 | * them on a list, it post them to the port by using SGL block post. | |
1920 | * | |
1921 | * Return codes: | |
1922 | * int - number of nvme buffers that were allocated and posted. | |
1923 | * 0 = failure, less than num_to_alloc is a partial failure. | |
1924 | **/ | |
1925 | static int | |
1926 | lpfc_new_nvme_buf(struct lpfc_vport *vport, int num_to_alloc) | |
1927 | { | |
1928 | struct lpfc_hba *phba = vport->phba; | |
1929 | struct lpfc_nvme_buf *lpfc_ncmd; | |
1930 | struct lpfc_iocbq *pwqeq; | |
1931 | union lpfc_wqe128 *wqe; | |
1932 | struct sli4_sge *sgl; | |
1933 | dma_addr_t pdma_phys_sgl; | |
1934 | uint16_t iotag, lxri = 0; | |
1935 | int bcnt, num_posted, sgl_size; | |
1936 | LIST_HEAD(prep_nblist); | |
1937 | LIST_HEAD(post_nblist); | |
1938 | LIST_HEAD(nvme_nblist); | |
1939 | ||
1940 | sgl_size = phba->cfg_sg_dma_buf_size; | |
1941 | ||
1942 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { | |
1943 | lpfc_ncmd = kzalloc(sizeof(struct lpfc_nvme_buf), GFP_KERNEL); | |
1944 | if (!lpfc_ncmd) | |
1945 | break; | |
1946 | /* | |
1947 | * Get memory from the pci pool to map the virt space to | |
1948 | * pci bus space for an I/O. The DMA buffer includes the | |
1949 | * number of SGE's necessary to support the sg_tablesize. | |
1950 | */ | |
1951 | lpfc_ncmd->data = pci_pool_alloc(phba->lpfc_sg_dma_buf_pool, | |
1952 | GFP_KERNEL, | |
1953 | &lpfc_ncmd->dma_handle); | |
1954 | if (!lpfc_ncmd->data) { | |
1955 | kfree(lpfc_ncmd); | |
1956 | break; | |
1957 | } | |
1958 | memset(lpfc_ncmd->data, 0, phba->cfg_sg_dma_buf_size); | |
1959 | ||
1960 | lxri = lpfc_sli4_next_xritag(phba); | |
1961 | if (lxri == NO_XRI) { | |
1962 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, | |
1963 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); | |
1964 | kfree(lpfc_ncmd); | |
1965 | break; | |
1966 | } | |
1967 | pwqeq = &(lpfc_ncmd->cur_iocbq); | |
1968 | wqe = (union lpfc_wqe128 *)&pwqeq->wqe; | |
1969 | ||
1970 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ | |
1971 | iotag = lpfc_sli_next_iotag(phba, pwqeq); | |
1972 | if (iotag == 0) { | |
1973 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, | |
1974 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); | |
1975 | kfree(lpfc_ncmd); | |
1976 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, | |
1977 | "6121 Failed to allocated IOTAG for" | |
1978 | " XRI:0x%x\n", lxri); | |
1979 | lpfc_sli4_free_xri(phba, lxri); | |
1980 | break; | |
1981 | } | |
1982 | pwqeq->sli4_lxritag = lxri; | |
1983 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
1984 | pwqeq->iocb_flag |= LPFC_IO_NVME; | |
1985 | pwqeq->context1 = lpfc_ncmd; | |
1986 | pwqeq->wqe_cmpl = lpfc_nvme_io_cmd_wqe_cmpl; | |
1987 | ||
1988 | /* Initialize local short-hand pointers. */ | |
1989 | lpfc_ncmd->nvme_sgl = lpfc_ncmd->data; | |
1990 | sgl = lpfc_ncmd->nvme_sgl; | |
1991 | pdma_phys_sgl = lpfc_ncmd->dma_handle; | |
1992 | lpfc_ncmd->dma_phys_sgl = pdma_phys_sgl; | |
1993 | ||
1994 | /* Rsp SGE will be filled in when we rcv an IO | |
1995 | * from the NVME Layer to be sent. | |
1996 | * The cmd is going to be embedded so we need a SKIP SGE. | |
1997 | */ | |
1998 | bf_set(lpfc_sli4_sge_type, sgl, LPFC_SGE_TYPE_SKIP); | |
1999 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
2000 | sgl->word2 = cpu_to_le32(sgl->word2); | |
2001 | /* Fill in word 3 / sgl_len during cmd submission */ | |
2002 | ||
2003 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; | |
2004 | ||
2005 | /* Word 7 */ | |
2006 | bf_set(wqe_erp, &wqe->generic.wqe_com, 0); | |
2007 | /* NVME upper layers will time things out, if needed */ | |
2008 | bf_set(wqe_tmo, &wqe->generic.wqe_com, 0); | |
2009 | ||
2010 | /* Word 10 */ | |
2011 | bf_set(wqe_ebde_cnt, &wqe->generic.wqe_com, 0); | |
2012 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); | |
2013 | ||
2014 | /* add the nvme buffer to a post list */ | |
2015 | list_add_tail(&lpfc_ncmd->list, &post_nblist); | |
2016 | spin_lock_irq(&phba->nvme_buf_list_get_lock); | |
2017 | phba->sli4_hba.nvme_xri_cnt++; | |
2018 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); | |
2019 | } | |
2020 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, | |
2021 | "6114 Allocate %d out of %d requested new NVME " | |
2022 | "buffers\n", bcnt, num_to_alloc); | |
2023 | ||
2024 | /* post the list of nvme buffer sgls to port if available */ | |
2025 | if (!list_empty(&post_nblist)) | |
2026 | num_posted = lpfc_post_nvme_sgl_list(phba, | |
2027 | &post_nblist, bcnt); | |
2028 | else | |
2029 | num_posted = 0; | |
2030 | ||
2031 | return num_posted; | |
2032 | } | |
2033 | ||
2034 | /** | |
2035 | * lpfc_get_nvme_buf - Get a nvme buffer from lpfc_nvme_buf_list of the HBA | |
2036 | * @phba: The HBA for which this call is being executed. | |
2037 | * | |
2038 | * This routine removes a nvme buffer from head of @phba lpfc_nvme_buf_list list | |
2039 | * and returns to caller. | |
2040 | * | |
2041 | * Return codes: | |
2042 | * NULL - Error | |
2043 | * Pointer to lpfc_nvme_buf - Success | |
2044 | **/ | |
2045 | static struct lpfc_nvme_buf * | |
2046 | lpfc_get_nvme_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) | |
2047 | { | |
2048 | struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next; | |
2049 | unsigned long iflag = 0; | |
2050 | int found = 0; | |
2051 | ||
2052 | spin_lock_irqsave(&phba->nvme_buf_list_get_lock, iflag); | |
2053 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, | |
2054 | &phba->lpfc_nvme_buf_list_get, list) { | |
2055 | if (lpfc_test_rrq_active(phba, ndlp, | |
2056 | lpfc_ncmd->cur_iocbq.sli4_lxritag)) | |
2057 | continue; | |
2058 | list_del(&lpfc_ncmd->list); | |
2059 | found = 1; | |
2060 | break; | |
2061 | } | |
2062 | if (!found) { | |
2063 | spin_lock(&phba->nvme_buf_list_put_lock); | |
2064 | list_splice(&phba->lpfc_nvme_buf_list_put, | |
2065 | &phba->lpfc_nvme_buf_list_get); | |
2066 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); | |
2067 | spin_unlock(&phba->nvme_buf_list_put_lock); | |
2068 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, | |
2069 | &phba->lpfc_nvme_buf_list_get, list) { | |
2070 | if (lpfc_test_rrq_active( | |
2071 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) | |
2072 | continue; | |
2073 | list_del(&lpfc_ncmd->list); | |
2074 | found = 1; | |
2075 | break; | |
2076 | } | |
2077 | } | |
2078 | spin_unlock_irqrestore(&phba->nvme_buf_list_get_lock, iflag); | |
2079 | if (!found) | |
2080 | return NULL; | |
2081 | return lpfc_ncmd; | |
2082 | } | |
2083 | ||
2084 | /** | |
2085 | * lpfc_release_nvme_buf: Return a nvme buffer back to hba nvme buf list. | |
2086 | * @phba: The Hba for which this call is being executed. | |
2087 | * @lpfc_ncmd: The nvme buffer which is being released. | |
2088 | * | |
2089 | * This routine releases @lpfc_ncmd nvme buffer by adding it to tail of @phba | |
2090 | * lpfc_nvme_buf_list list. For SLI4 XRI's are tied to the nvme buffer | |
2091 | * and cannot be reused for at least RA_TOV amount of time if it was | |
2092 | * aborted. | |
2093 | **/ | |
2094 | static void | |
2095 | lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd) | |
2096 | { | |
2097 | unsigned long iflag = 0; | |
2098 | ||
2099 | lpfc_ncmd->nonsg_phys = 0; | |
2100 | if (lpfc_ncmd->exch_busy) { | |
2101 | spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock, | |
2102 | iflag); | |
2103 | lpfc_ncmd->nvmeCmd = NULL; | |
2104 | list_add_tail(&lpfc_ncmd->list, | |
2105 | &phba->sli4_hba.lpfc_abts_nvme_buf_list); | |
2106 | spin_unlock_irqrestore(&phba->sli4_hba.abts_nvme_buf_list_lock, | |
2107 | iflag); | |
2108 | } else { | |
2109 | lpfc_ncmd->nvmeCmd = NULL; | |
2110 | lpfc_ncmd->cur_iocbq.iocb_flag = LPFC_IO_NVME; | |
2111 | spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag); | |
2112 | list_add_tail(&lpfc_ncmd->list, &phba->lpfc_nvme_buf_list_put); | |
2113 | spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag); | |
2114 | } | |
2115 | } | |
2116 | ||
2117 | /** | |
2118 | * lpfc_nvme_create_localport - Create/Bind an nvme localport instance. | |
2119 | * @pvport - the lpfc_vport instance requesting a localport. | |
2120 | * | |
2121 | * This routine is invoked to create an nvme localport instance to bind | |
2122 | * to the nvme_fc_transport. It is called once during driver load | |
2123 | * like lpfc_create_shost after all other services are initialized. | |
2124 | * It requires a vport, vpi, and wwns at call time. Other localport | |
2125 | * parameters are modified as the driver's FCID and the Fabric WWN | |
2126 | * are established. | |
2127 | * | |
2128 | * Return codes | |
2129 | * 0 - successful | |
2130 | * -ENOMEM - no heap memory available | |
2131 | * other values - from nvme registration upcall | |
2132 | **/ | |
2133 | int | |
2134 | lpfc_nvme_create_localport(struct lpfc_vport *vport) | |
2135 | { | |
2136 | struct lpfc_hba *phba = vport->phba; | |
2137 | struct nvme_fc_port_info nfcp_info; | |
2138 | struct nvme_fc_local_port *localport; | |
2139 | struct lpfc_nvme_lport *lport; | |
2140 | int len, ret = 0; | |
2141 | ||
2142 | /* Initialize this localport instance. The vport wwn usage ensures | |
2143 | * that NPIV is accounted for. | |
2144 | */ | |
2145 | memset(&nfcp_info, 0, sizeof(struct nvme_fc_port_info)); | |
2146 | nfcp_info.port_role = FC_PORT_ROLE_NVME_INITIATOR; | |
2147 | nfcp_info.node_name = wwn_to_u64(vport->fc_nodename.u.wwn); | |
2148 | nfcp_info.port_name = wwn_to_u64(vport->fc_portname.u.wwn); | |
2149 | ||
2150 | /* For now need + 1 to get around NVME transport logic */ | |
2151 | lpfc_nvme_template.max_sgl_segments = phba->cfg_sg_seg_cnt + 1; | |
2152 | lpfc_nvme_template.max_hw_queues = phba->cfg_nvme_io_channel; | |
2153 | ||
2154 | /* localport is allocated from the stack, but the registration | |
2155 | * call allocates heap memory as well as the private area. | |
2156 | */ | |
2157 | ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template, | |
2158 | &vport->phba->pcidev->dev, &localport); | |
2159 | if (!ret) { | |
2160 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC, | |
2161 | "6005 Successfully registered local " | |
2162 | "NVME port num %d, localP %p, private %p, " | |
2163 | "sg_seg %d\n", | |
2164 | localport->port_num, localport, | |
2165 | localport->private, | |
2166 | lpfc_nvme_template.max_sgl_segments); | |
2167 | ||
2168 | /* Private is our lport size declared in the template. */ | |
2169 | lport = (struct lpfc_nvme_lport *)localport->private; | |
2170 | vport->localport = localport; | |
2171 | lport->vport = vport; | |
2172 | INIT_LIST_HEAD(&lport->rport_list); | |
2173 | vport->nvmei_support = 1; | |
2174 | } | |
2175 | ||
2176 | len = lpfc_new_nvme_buf(vport, phba->sli4_hba.nvme_xri_max); | |
2177 | vport->phba->total_nvme_bufs += len; | |
2178 | return ret; | |
2179 | } | |
2180 | ||
2181 | /** | |
2182 | * lpfc_nvme_destroy_localport - Destroy lpfc_nvme bound to nvme transport. | |
2183 | * @pnvme: pointer to lpfc nvme data structure. | |
2184 | * | |
2185 | * This routine is invoked to destroy all lports bound to the phba. | |
2186 | * The lport memory was allocated by the nvme fc transport and is | |
2187 | * released there. This routine ensures all rports bound to the | |
2188 | * lport have been disconnected. | |
2189 | * | |
2190 | **/ | |
2191 | void | |
2192 | lpfc_nvme_destroy_localport(struct lpfc_vport *vport) | |
2193 | { | |
2194 | struct nvme_fc_local_port *localport; | |
2195 | struct lpfc_nvme_lport *lport; | |
2196 | struct lpfc_nvme_rport *rport = NULL, *rport_next = NULL; | |
2197 | int ret; | |
2198 | ||
2199 | if (vport->nvmei_support == 0) | |
2200 | return; | |
2201 | ||
2202 | localport = vport->localport; | |
2203 | vport->localport = NULL; | |
2204 | lport = (struct lpfc_nvme_lport *)localport->private; | |
2205 | ||
2206 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, | |
2207 | "6011 Destroying NVME localport %p\n", | |
2208 | localport); | |
2209 | ||
2210 | list_for_each_entry_safe(rport, rport_next, &lport->rport_list, list) { | |
2211 | /* The last node ref has to get released now before the rport | |
2212 | * private memory area is released by the transport. | |
2213 | */ | |
2214 | list_del(&rport->list); | |
2215 | ||
2216 | init_completion(&rport->rport_unreg_done); | |
2217 | ret = nvme_fc_unregister_remoteport(rport->remoteport); | |
2218 | if (ret) | |
2219 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
2220 | "6008 rport fail destroy %x\n", ret); | |
2221 | wait_for_completion_timeout(&rport->rport_unreg_done, 5); | |
2222 | } | |
2223 | /* lport's rport list is clear. Unregister | |
2224 | * lport and release resources. | |
2225 | */ | |
2226 | init_completion(&lport->lport_unreg_done); | |
2227 | ret = nvme_fc_unregister_localport(localport); | |
2228 | wait_for_completion_timeout(&lport->lport_unreg_done, 5); | |
2229 | ||
2230 | /* Regardless of the unregister upcall response, clear | |
2231 | * nvmei_support. All rports are unregistered and the | |
2232 | * driver will clean up. | |
2233 | */ | |
2234 | vport->nvmei_support = 0; | |
2235 | if (ret == 0) { | |
2236 | lpfc_printf_vlog(vport, | |
2237 | KERN_INFO, LOG_NVME_DISC, | |
2238 | "6009 Unregistered lport Success\n"); | |
2239 | } else { | |
2240 | lpfc_printf_vlog(vport, | |
2241 | KERN_INFO, LOG_NVME_DISC, | |
2242 | "6010 Unregistered lport " | |
2243 | "Failed, status x%x\n", | |
2244 | ret); | |
2245 | } | |
2246 | } | |
2247 | ||
2248 | void | |
2249 | lpfc_nvme_update_localport(struct lpfc_vport *vport) | |
2250 | { | |
2251 | struct nvme_fc_local_port *localport; | |
2252 | struct lpfc_nvme_lport *lport; | |
2253 | ||
2254 | localport = vport->localport; | |
2255 | lport = (struct lpfc_nvme_lport *)localport->private; | |
2256 | ||
2257 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, | |
2258 | "6012 Update NVME lport %p did x%x\n", | |
2259 | localport, vport->fc_myDID); | |
2260 | ||
2261 | localport->port_id = vport->fc_myDID; | |
2262 | if (localport->port_id == 0) | |
2263 | localport->port_role = FC_PORT_ROLE_NVME_DISCOVERY; | |
2264 | else | |
2265 | localport->port_role = FC_PORT_ROLE_NVME_INITIATOR; | |
2266 | ||
2267 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
2268 | "6030 bound lport %p to DID x%06x\n", | |
2269 | lport, localport->port_id); | |
2270 | ||
2271 | } | |
2272 | ||
2273 | int | |
2274 | lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
2275 | { | |
2276 | int ret = 0; | |
2277 | struct nvme_fc_local_port *localport; | |
2278 | struct lpfc_nvme_lport *lport; | |
2279 | struct lpfc_nvme_rport *rport; | |
2280 | struct nvme_fc_remote_port *remote_port; | |
2281 | struct nvme_fc_port_info rpinfo; | |
2282 | ||
2283 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC, | |
2284 | "6006 Register NVME PORT. DID x%06x nlptype x%x\n", | |
2285 | ndlp->nlp_DID, ndlp->nlp_type); | |
2286 | ||
2287 | localport = vport->localport; | |
2288 | lport = (struct lpfc_nvme_lport *)localport->private; | |
2289 | ||
2290 | if (ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_INITIATOR)) { | |
2291 | ||
2292 | /* The driver isn't expecting the rport wwn to change | |
2293 | * but it might get a different DID on a different | |
2294 | * fabric. | |
2295 | */ | |
2296 | list_for_each_entry(rport, &lport->rport_list, list) { | |
2297 | if (rport->remoteport->port_name != | |
2298 | wwn_to_u64(ndlp->nlp_portname.u.wwn)) | |
2299 | continue; | |
2300 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NVME_DISC, | |
2301 | "6035 lport %p, found matching rport " | |
2302 | "at wwpn 0x%llx, Data: x%x x%x x%x " | |
2303 | "x%06x\n", | |
2304 | lport, | |
2305 | rport->remoteport->port_name, | |
2306 | rport->remoteport->port_id, | |
2307 | rport->remoteport->port_role, | |
2308 | ndlp->nlp_type, | |
2309 | ndlp->nlp_DID); | |
2310 | remote_port = rport->remoteport; | |
2311 | if ((remote_port->port_id == 0) && | |
2312 | (remote_port->port_role == | |
2313 | FC_PORT_ROLE_NVME_DISCOVERY)) { | |
2314 | remote_port->port_id = ndlp->nlp_DID; | |
2315 | remote_port->port_role &= | |
2316 | ~FC_PORT_ROLE_NVME_DISCOVERY; | |
2317 | if (ndlp->nlp_type & NLP_NVME_TARGET) | |
2318 | remote_port->port_role |= | |
2319 | FC_PORT_ROLE_NVME_TARGET; | |
2320 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) | |
2321 | remote_port->port_role |= | |
2322 | FC_PORT_ROLE_NVME_INITIATOR; | |
2323 | ||
2324 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, | |
2325 | LOG_NVME_DISC, | |
2326 | "6014 Rebinding lport to " | |
2327 | "rport wwpn 0x%llx, " | |
2328 | "Data: x%x x%x x%x x%06x\n", | |
2329 | remote_port->port_name, | |
2330 | remote_port->port_id, | |
2331 | remote_port->port_role, | |
2332 | ndlp->nlp_type, | |
2333 | ndlp->nlp_DID); | |
2334 | } | |
2335 | return 0; | |
2336 | } | |
2337 | ||
2338 | /* NVME rports are not preserved across devloss. | |
2339 | * Just register this instance. | |
2340 | */ | |
2341 | rpinfo.port_id = ndlp->nlp_DID; | |
2342 | rpinfo.port_role = 0; | |
2343 | if (ndlp->nlp_type & NLP_NVME_TARGET) | |
2344 | rpinfo.port_role |= FC_PORT_ROLE_NVME_TARGET; | |
2345 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) | |
2346 | rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR; | |
2347 | rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); | |
2348 | rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); | |
2349 | ||
2350 | ret = nvme_fc_register_remoteport(localport, &rpinfo, | |
2351 | &remote_port); | |
2352 | if (!ret) { | |
2353 | rport = remote_port->private; | |
2354 | rport->remoteport = remote_port; | |
2355 | rport->lport = lport; | |
2356 | rport->ndlp = lpfc_nlp_get(ndlp); | |
2357 | if (!rport->ndlp) | |
2358 | return -1; | |
2359 | ndlp->nrport = rport; | |
2360 | INIT_LIST_HEAD(&rport->list); | |
2361 | list_add_tail(&rport->list, &lport->rport_list); | |
2362 | lpfc_printf_vlog(vport, KERN_INFO, | |
2363 | LOG_NVME_DISC | LOG_NODE, | |
2364 | "6022 Binding new rport to lport %p " | |
2365 | "Rport WWNN 0x%llx, Rport WWPN 0x%llx " | |
2366 | "DID x%06x Role x%x\n", | |
2367 | lport, | |
2368 | rpinfo.node_name, rpinfo.port_name, | |
2369 | rpinfo.port_id, rpinfo.port_role); | |
2370 | } else { | |
2371 | lpfc_printf_vlog(vport, KERN_ERR, | |
2372 | LOG_NVME_DISC | LOG_NODE, | |
2373 | "6031 RemotePort Registration failed " | |
2374 | "err: %d, DID x%06x\n", | |
2375 | ret, ndlp->nlp_DID); | |
2376 | } | |
2377 | } else { | |
2378 | ret = -EINVAL; | |
2379 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
2380 | "6027 Unknown nlp_type x%x on DID x%06x " | |
2381 | "ndlp %p. Not Registering nvme rport\n", | |
2382 | ndlp->nlp_type, ndlp->nlp_DID, ndlp); | |
2383 | } | |
2384 | return ret; | |
2385 | } | |
2386 | ||
2387 | /* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport. | |
2388 | * | |
2389 | * There is no notion of Devloss or rport recovery from the current | |
2390 | * nvme_transport perspective. Loss of an rport just means IO cannot | |
2391 | * be sent and recovery is completely up to the initator. | |
2392 | * For now, the driver just unbinds the DID and port_role so that | |
2393 | * no further IO can be issued. Changes are planned for later. | |
2394 | * | |
2395 | * Notes - the ndlp reference count is not decremented here since | |
2396 | * since there is no nvme_transport api for devloss. Node ref count | |
2397 | * is only adjusted in driver unload. | |
2398 | */ | |
2399 | void | |
2400 | lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
2401 | { | |
2402 | int ret; | |
2403 | struct nvme_fc_local_port *localport; | |
2404 | struct lpfc_nvme_lport *lport; | |
2405 | struct lpfc_nvme_rport *rport; | |
2406 | struct nvme_fc_remote_port *remoteport; | |
2407 | ||
2408 | localport = vport->localport; | |
2409 | ||
2410 | /* This is fundamental error. The localport is always | |
2411 | * available until driver unload. Just exit. | |
2412 | */ | |
2413 | if (!localport) | |
2414 | return; | |
2415 | ||
2416 | lport = (struct lpfc_nvme_lport *)localport->private; | |
2417 | if (!lport) | |
2418 | goto input_err; | |
2419 | ||
2420 | rport = ndlp->nrport; | |
2421 | if (!rport) | |
2422 | goto input_err; | |
2423 | ||
2424 | remoteport = rport->remoteport; | |
2425 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
2426 | "6033 Unreg nvme remoteport %p, portname x%llx, " | |
2427 | "port_id x%06x, portstate x%x port type x%x\n", | |
2428 | remoteport, remoteport->port_name, | |
2429 | remoteport->port_id, remoteport->port_state, | |
2430 | ndlp->nlp_type); | |
2431 | ||
2432 | /* Sanity check ndlp type. Only call for NVME ports. Don't | |
2433 | * clear any rport state until the transport calls back. | |
2434 | */ | |
2435 | if (ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_INITIATOR)) { | |
2436 | init_completion(&rport->rport_unreg_done); | |
2437 | ret = nvme_fc_unregister_remoteport(remoteport); | |
2438 | if (ret != 0) { | |
2439 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
2440 | "6167 NVME unregister failed %d " | |
2441 | "port_state x%x\n", | |
2442 | ret, remoteport->port_state); | |
2443 | } | |
2444 | ||
2445 | /* Wait for the driver's delete completion routine to finish | |
2446 | * before proceeding. This guarantees the transport and driver | |
2447 | * have completed the unreg process. | |
2448 | */ | |
2449 | ret = wait_for_completion_timeout(&rport->rport_unreg_done, 5); | |
2450 | if (ret == 0) { | |
2451 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
2452 | "6169 Unreg nvme wait failed %d\n", | |
2453 | ret); | |
2454 | } | |
2455 | } | |
2456 | return; | |
2457 | ||
2458 | input_err: | |
2459 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, | |
2460 | "6168: State error: lport %p, rport%p FCID x%06x\n", | |
2461 | vport->localport, ndlp->rport, ndlp->nlp_DID); | |
2462 | } |