Commit | Line | Data |
---|---|---|
f1c3b0fc JS |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
3 | * Fibre Channel Host Bus Adapters. * | |
792581de | 4 | * Copyright (C) 2009-2011 Emulex. All rights reserved. * |
f1c3b0fc JS |
5 | * EMULEX and SLI are trademarks of Emulex. * |
6 | * www.emulex.com * | |
7 | * * | |
8 | * This program is free software; you can redistribute it and/or * | |
9 | * modify it under the terms of version 2 of the GNU General * | |
10 | * Public License as published by the Free Software Foundation. * | |
11 | * This program is distributed in the hope that it will be useful. * | |
12 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
13 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
14 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
15 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
16 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
17 | * more details, a copy of which can be found in the file COPYING * | |
18 | * included with this package. * | |
19 | *******************************************************************/ | |
20 | ||
21 | #include <linux/interrupt.h> | |
22 | #include <linux/mempool.h> | |
23 | #include <linux/pci.h> | |
5a0e3ad6 | 24 | #include <linux/slab.h> |
277e76f1 | 25 | #include <linux/delay.h> |
7ad20aa9 | 26 | #include <linux/list.h> |
f1c3b0fc JS |
27 | |
28 | #include <scsi/scsi.h> | |
29 | #include <scsi/scsi_host.h> | |
30 | #include <scsi/scsi_transport_fc.h> | |
31 | #include <scsi/scsi_bsg_fc.h> | |
6a9c52cf | 32 | #include <scsi/fc/fc_fs.h> |
f1c3b0fc JS |
33 | |
34 | #include "lpfc_hw4.h" | |
35 | #include "lpfc_hw.h" | |
36 | #include "lpfc_sli.h" | |
37 | #include "lpfc_sli4.h" | |
38 | #include "lpfc_nl.h" | |
4fede78f | 39 | #include "lpfc_bsg.h" |
f1c3b0fc JS |
40 | #include "lpfc_disc.h" |
41 | #include "lpfc_scsi.h" | |
42 | #include "lpfc.h" | |
43 | #include "lpfc_logmsg.h" | |
44 | #include "lpfc_crtn.h" | |
b76f2dc9 | 45 | #include "lpfc_debugfs.h" |
f1c3b0fc JS |
46 | #include "lpfc_vport.h" |
47 | #include "lpfc_version.h" | |
48 | ||
4cc0e56e JS |
49 | struct lpfc_bsg_event { |
50 | struct list_head node; | |
51 | struct kref kref; | |
52 | wait_queue_head_t wq; | |
53 | ||
54 | /* Event type and waiter identifiers */ | |
55 | uint32_t type_mask; | |
56 | uint32_t req_id; | |
57 | uint32_t reg_id; | |
58 | ||
59 | /* next two flags are here for the auto-delete logic */ | |
60 | unsigned long wait_time_stamp; | |
61 | int waiting; | |
62 | ||
63 | /* seen and not seen events */ | |
64 | struct list_head events_to_get; | |
65 | struct list_head events_to_see; | |
66 | ||
67 | /* job waiting for this event to finish */ | |
68 | struct fc_bsg_job *set_job; | |
69 | }; | |
70 | ||
71 | struct lpfc_bsg_iocb { | |
72 | struct lpfc_iocbq *cmdiocbq; | |
73 | struct lpfc_iocbq *rspiocbq; | |
74 | struct lpfc_dmabuf *bmp; | |
75 | struct lpfc_nodelist *ndlp; | |
76 | ||
77 | /* job waiting for this iocb to finish */ | |
78 | struct fc_bsg_job *set_job; | |
79 | }; | |
80 | ||
3b5dd52a JS |
81 | struct lpfc_bsg_mbox { |
82 | LPFC_MBOXQ_t *pmboxq; | |
83 | MAILBOX_t *mb; | |
7ad20aa9 | 84 | struct lpfc_dmabuf *dmabuffers; /* for BIU diags */ |
7a470277 JS |
85 | uint8_t *ext; /* extended mailbox data */ |
86 | uint32_t mbOffset; /* from app */ | |
87 | uint32_t inExtWLen; /* from app */ | |
c7495937 | 88 | uint32_t outExtWLen; /* from app */ |
3b5dd52a JS |
89 | |
90 | /* job waiting for this mbox command to finish */ | |
91 | struct fc_bsg_job *set_job; | |
92 | }; | |
93 | ||
e2aed29f JS |
94 | #define MENLO_DID 0x0000FC0E |
95 | ||
96 | struct lpfc_bsg_menlo { | |
97 | struct lpfc_iocbq *cmdiocbq; | |
98 | struct lpfc_iocbq *rspiocbq; | |
99 | struct lpfc_dmabuf *bmp; | |
100 | ||
101 | /* job waiting for this iocb to finish */ | |
102 | struct fc_bsg_job *set_job; | |
103 | }; | |
104 | ||
4cc0e56e JS |
105 | #define TYPE_EVT 1 |
106 | #define TYPE_IOCB 2 | |
3b5dd52a | 107 | #define TYPE_MBOX 3 |
e2aed29f | 108 | #define TYPE_MENLO 4 |
4cc0e56e JS |
109 | struct bsg_job_data { |
110 | uint32_t type; | |
111 | union { | |
112 | struct lpfc_bsg_event *evt; | |
113 | struct lpfc_bsg_iocb iocb; | |
3b5dd52a | 114 | struct lpfc_bsg_mbox mbox; |
e2aed29f | 115 | struct lpfc_bsg_menlo menlo; |
4cc0e56e JS |
116 | } context_un; |
117 | }; | |
118 | ||
119 | struct event_data { | |
120 | struct list_head node; | |
121 | uint32_t type; | |
122 | uint32_t immed_dat; | |
123 | void *data; | |
124 | uint32_t len; | |
125 | }; | |
126 | ||
3b5dd52a | 127 | #define BUF_SZ_4K 4096 |
4cc0e56e JS |
128 | #define SLI_CT_ELX_LOOPBACK 0x10 |
129 | ||
130 | enum ELX_LOOPBACK_CMD { | |
131 | ELX_LOOPBACK_XRI_SETUP, | |
132 | ELX_LOOPBACK_DATA, | |
133 | }; | |
134 | ||
3b5dd52a JS |
135 | #define ELX_LOOPBACK_HEADER_SZ \ |
136 | (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un) | |
137 | ||
4cc0e56e JS |
138 | struct lpfc_dmabufext { |
139 | struct lpfc_dmabuf dma; | |
140 | uint32_t size; | |
141 | uint32_t flag; | |
142 | }; | |
143 | ||
144 | /** | |
145 | * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler | |
146 | * @phba: Pointer to HBA context object. | |
147 | * @cmdiocbq: Pointer to command iocb. | |
148 | * @rspiocbq: Pointer to response iocb. | |
149 | * | |
150 | * This function is the completion handler for iocbs issued using | |
151 | * lpfc_bsg_send_mgmt_cmd function. This function is called by the | |
152 | * ring event handler function without any lock held. This function | |
153 | * can be called from both worker thread context and interrupt | |
154 | * context. This function also can be called from another thread which | |
155 | * cleans up the SLI layer objects. | |
156 | * This function copies the contents of the response iocb to the | |
157 | * response iocb memory object provided by the caller of | |
158 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
159 | * sleeps for the iocb completion. | |
160 | **/ | |
161 | static void | |
162 | lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba, | |
163 | struct lpfc_iocbq *cmdiocbq, | |
164 | struct lpfc_iocbq *rspiocbq) | |
165 | { | |
4cc0e56e JS |
166 | struct bsg_job_data *dd_data; |
167 | struct fc_bsg_job *job; | |
168 | IOCB_t *rsp; | |
169 | struct lpfc_dmabuf *bmp; | |
170 | struct lpfc_nodelist *ndlp; | |
171 | struct lpfc_bsg_iocb *iocb; | |
172 | unsigned long flags; | |
173 | int rc = 0; | |
174 | ||
175 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
be858b65 | 176 | dd_data = cmdiocbq->context2; |
4cc0e56e JS |
177 | if (!dd_data) { |
178 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
be858b65 | 179 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
4cc0e56e JS |
180 | return; |
181 | } | |
182 | ||
183 | iocb = &dd_data->context_un.iocb; | |
184 | job = iocb->set_job; | |
185 | job->dd_data = NULL; /* so timeout handler does not reply */ | |
186 | ||
4cc0e56e | 187 | bmp = iocb->bmp; |
4cc0e56e | 188 | rsp = &rspiocbq->iocb; |
be858b65 | 189 | ndlp = cmdiocbq->context1; |
4cc0e56e JS |
190 | |
191 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
192 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
193 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
194 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
195 | ||
196 | if (rsp->ulpStatus) { | |
197 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
198 | switch (rsp->un.ulpWord[4] & 0xff) { | |
199 | case IOERR_SEQUENCE_TIMEOUT: | |
200 | rc = -ETIMEDOUT; | |
201 | break; | |
202 | case IOERR_INVALID_RPI: | |
203 | rc = -EFAULT; | |
204 | break; | |
205 | default: | |
206 | rc = -EACCES; | |
207 | break; | |
208 | } | |
209 | } else | |
210 | rc = -EACCES; | |
211 | } else | |
212 | job->reply->reply_payload_rcv_len = | |
213 | rsp->un.genreq64.bdl.bdeSize; | |
214 | ||
215 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
4cc0e56e JS |
216 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
217 | lpfc_nlp_put(ndlp); | |
218 | kfree(bmp); | |
219 | kfree(dd_data); | |
220 | /* make error code available to userspace */ | |
221 | job->reply->result = rc; | |
222 | /* complete the job back to userspace */ | |
223 | job->job_done(job); | |
224 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
225 | return; | |
226 | } | |
227 | ||
f1c3b0fc | 228 | /** |
4cc0e56e | 229 | * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request |
f1c3b0fc | 230 | * @job: fc_bsg_job to handle |
3b5dd52a | 231 | **/ |
f1c3b0fc | 232 | static int |
4cc0e56e | 233 | lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job) |
f1c3b0fc | 234 | { |
f1c3b0fc JS |
235 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
236 | struct lpfc_hba *phba = vport->phba; | |
237 | struct lpfc_rport_data *rdata = job->rport->dd_data; | |
238 | struct lpfc_nodelist *ndlp = rdata->pnode; | |
239 | struct ulp_bde64 *bpl = NULL; | |
240 | uint32_t timeout; | |
241 | struct lpfc_iocbq *cmdiocbq = NULL; | |
f1c3b0fc | 242 | IOCB_t *cmd; |
f1c3b0fc JS |
243 | struct lpfc_dmabuf *bmp = NULL; |
244 | int request_nseg; | |
245 | int reply_nseg; | |
246 | struct scatterlist *sgel = NULL; | |
247 | int numbde; | |
248 | dma_addr_t busaddr; | |
4cc0e56e JS |
249 | struct bsg_job_data *dd_data; |
250 | uint32_t creg_val; | |
f1c3b0fc | 251 | int rc = 0; |
d439d286 | 252 | int iocb_stat; |
f1c3b0fc JS |
253 | |
254 | /* in case no data is transferred */ | |
255 | job->reply->reply_payload_rcv_len = 0; | |
256 | ||
4cc0e56e JS |
257 | /* allocate our bsg tracking structure */ |
258 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
259 | if (!dd_data) { | |
260 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
261 | "2733 Failed allocation of dd_data\n"); | |
262 | rc = -ENOMEM; | |
263 | goto no_dd_data; | |
264 | } | |
265 | ||
f1c3b0fc | 266 | if (!lpfc_nlp_get(ndlp)) { |
4cc0e56e JS |
267 | rc = -ENODEV; |
268 | goto no_ndlp; | |
269 | } | |
270 | ||
271 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
272 | if (!bmp) { | |
273 | rc = -ENOMEM; | |
274 | goto free_ndlp; | |
f1c3b0fc JS |
275 | } |
276 | ||
277 | if (ndlp->nlp_flag & NLP_ELS_SND_MASK) { | |
278 | rc = -ENODEV; | |
4cc0e56e | 279 | goto free_bmp; |
f1c3b0fc JS |
280 | } |
281 | ||
f1c3b0fc JS |
282 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
283 | if (!cmdiocbq) { | |
284 | rc = -ENOMEM; | |
4cc0e56e | 285 | goto free_bmp; |
f1c3b0fc | 286 | } |
f1c3b0fc | 287 | |
4cc0e56e | 288 | cmd = &cmdiocbq->iocb; |
f1c3b0fc JS |
289 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); |
290 | if (!bmp->virt) { | |
291 | rc = -ENOMEM; | |
be858b65 | 292 | goto free_cmdiocbq; |
f1c3b0fc | 293 | } |
f1c3b0fc JS |
294 | |
295 | INIT_LIST_HEAD(&bmp->list); | |
296 | bpl = (struct ulp_bde64 *) bmp->virt; | |
f1c3b0fc JS |
297 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, |
298 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
299 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { | |
300 | busaddr = sg_dma_address(sgel); | |
301 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
302 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
303 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
304 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
305 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
306 | bpl++; | |
307 | } | |
308 | ||
309 | reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list, | |
310 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
311 | for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) { | |
312 | busaddr = sg_dma_address(sgel); | |
313 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
314 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
315 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
316 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
317 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
318 | bpl++; | |
319 | } | |
320 | ||
321 | cmd->un.genreq64.bdl.ulpIoTag32 = 0; | |
322 | cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
323 | cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
324 | cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
325 | cmd->un.genreq64.bdl.bdeSize = | |
326 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); | |
327 | cmd->ulpCommand = CMD_GEN_REQUEST64_CR; | |
328 | cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); | |
329 | cmd->un.genreq64.w5.hcsw.Dfctl = 0; | |
6a9c52cf JS |
330 | cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
331 | cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; | |
f1c3b0fc JS |
332 | cmd->ulpBdeCount = 1; |
333 | cmd->ulpLe = 1; | |
334 | cmd->ulpClass = CLASS3; | |
335 | cmd->ulpContext = ndlp->nlp_rpi; | |
6d368e53 JS |
336 | if (phba->sli_rev == LPFC_SLI_REV4) |
337 | cmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; | |
f1c3b0fc JS |
338 | cmd->ulpOwner = OWN_CHIP; |
339 | cmdiocbq->vport = phba->pport; | |
4cc0e56e | 340 | cmdiocbq->context3 = bmp; |
f1c3b0fc | 341 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
f1c3b0fc | 342 | timeout = phba->fc_ratov * 2; |
4cc0e56e JS |
343 | cmd->ulpTimeout = timeout; |
344 | ||
345 | cmdiocbq->iocb_cmpl = lpfc_bsg_send_mgmt_cmd_cmp; | |
be858b65 JS |
346 | cmdiocbq->context1 = ndlp; |
347 | cmdiocbq->context2 = dd_data; | |
4cc0e56e JS |
348 | dd_data->type = TYPE_IOCB; |
349 | dd_data->context_un.iocb.cmdiocbq = cmdiocbq; | |
4cc0e56e JS |
350 | dd_data->context_un.iocb.set_job = job; |
351 | dd_data->context_un.iocb.bmp = bmp; | |
4cc0e56e JS |
352 | |
353 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
9940b97b JS |
354 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
355 | rc = -EIO ; | |
356 | goto free_cmdiocbq; | |
357 | } | |
4cc0e56e JS |
358 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
359 | writel(creg_val, phba->HCregaddr); | |
360 | readl(phba->HCregaddr); /* flush */ | |
f1c3b0fc JS |
361 | } |
362 | ||
d439d286 JS |
363 | iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); |
364 | if (iocb_stat == IOCB_SUCCESS) | |
4cc0e56e | 365 | return 0; /* done for now */ |
d439d286 JS |
366 | else if (iocb_stat == IOCB_BUSY) |
367 | rc = -EAGAIN; | |
2a9bf3d0 | 368 | else |
d439d286 | 369 | rc = -EIO; |
2a9bf3d0 | 370 | |
f1c3b0fc | 371 | |
4cc0e56e JS |
372 | /* iocb failed so cleanup */ |
373 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
374 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
375 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
376 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
f1c3b0fc | 377 | |
f1c3b0fc | 378 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
4cc0e56e | 379 | |
f1c3b0fc JS |
380 | free_cmdiocbq: |
381 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
4cc0e56e JS |
382 | free_bmp: |
383 | kfree(bmp); | |
384 | free_ndlp: | |
f1c3b0fc | 385 | lpfc_nlp_put(ndlp); |
4cc0e56e JS |
386 | no_ndlp: |
387 | kfree(dd_data); | |
388 | no_dd_data: | |
389 | /* make error code available to userspace */ | |
390 | job->reply->result = rc; | |
391 | job->dd_data = NULL; | |
392 | return rc; | |
393 | } | |
394 | ||
395 | /** | |
396 | * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler | |
397 | * @phba: Pointer to HBA context object. | |
398 | * @cmdiocbq: Pointer to command iocb. | |
399 | * @rspiocbq: Pointer to response iocb. | |
400 | * | |
401 | * This function is the completion handler for iocbs issued using | |
402 | * lpfc_bsg_rport_els_cmp function. This function is called by the | |
403 | * ring event handler function without any lock held. This function | |
404 | * can be called from both worker thread context and interrupt | |
405 | * context. This function also can be called from other thread which | |
406 | * cleans up the SLI layer objects. | |
3b5dd52a | 407 | * This function copies the contents of the response iocb to the |
4cc0e56e JS |
408 | * response iocb memory object provided by the caller of |
409 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
410 | * sleeps for the iocb completion. | |
411 | **/ | |
412 | static void | |
413 | lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba, | |
414 | struct lpfc_iocbq *cmdiocbq, | |
415 | struct lpfc_iocbq *rspiocbq) | |
416 | { | |
417 | struct bsg_job_data *dd_data; | |
418 | struct fc_bsg_job *job; | |
419 | IOCB_t *rsp; | |
420 | struct lpfc_nodelist *ndlp; | |
421 | struct lpfc_dmabuf *pbuflist = NULL; | |
422 | struct fc_bsg_ctels_reply *els_reply; | |
423 | uint8_t *rjt_data; | |
424 | unsigned long flags; | |
425 | int rc = 0; | |
426 | ||
427 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
428 | dd_data = cmdiocbq->context1; | |
429 | /* normal completion and timeout crossed paths, already done */ | |
430 | if (!dd_data) { | |
67221a42 | 431 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4cc0e56e JS |
432 | return; |
433 | } | |
434 | ||
435 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; | |
436 | if (cmdiocbq->context2 && rspiocbq) | |
437 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
438 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
439 | ||
440 | job = dd_data->context_un.iocb.set_job; | |
441 | cmdiocbq = dd_data->context_un.iocb.cmdiocbq; | |
442 | rspiocbq = dd_data->context_un.iocb.rspiocbq; | |
443 | rsp = &rspiocbq->iocb; | |
444 | ndlp = dd_data->context_un.iocb.ndlp; | |
445 | ||
446 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
447 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
448 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
449 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
450 | ||
451 | if (job->reply->result == -EAGAIN) | |
452 | rc = -EAGAIN; | |
453 | else if (rsp->ulpStatus == IOSTAT_SUCCESS) | |
454 | job->reply->reply_payload_rcv_len = | |
455 | rsp->un.elsreq64.bdl.bdeSize; | |
456 | else if (rsp->ulpStatus == IOSTAT_LS_RJT) { | |
457 | job->reply->reply_payload_rcv_len = | |
458 | sizeof(struct fc_bsg_ctels_reply); | |
459 | /* LS_RJT data returned in word 4 */ | |
460 | rjt_data = (uint8_t *)&rsp->un.ulpWord[4]; | |
461 | els_reply = &job->reply->reply_data.ctels_reply; | |
462 | els_reply->status = FC_CTELS_STATUS_REJECT; | |
463 | els_reply->rjt_data.action = rjt_data[3]; | |
464 | els_reply->rjt_data.reason_code = rjt_data[2]; | |
465 | els_reply->rjt_data.reason_explanation = rjt_data[1]; | |
466 | els_reply->rjt_data.vendor_unique = rjt_data[0]; | |
467 | } else | |
468 | rc = -EIO; | |
f1c3b0fc | 469 | |
4cc0e56e JS |
470 | pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3; |
471 | lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys); | |
472 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
473 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
474 | lpfc_nlp_put(ndlp); | |
475 | kfree(dd_data); | |
f1c3b0fc JS |
476 | /* make error code available to userspace */ |
477 | job->reply->result = rc; | |
4cc0e56e | 478 | job->dd_data = NULL; |
f1c3b0fc JS |
479 | /* complete the job back to userspace */ |
480 | job->job_done(job); | |
4cc0e56e JS |
481 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
482 | return; | |
f1c3b0fc JS |
483 | } |
484 | ||
485 | /** | |
486 | * lpfc_bsg_rport_els - send an ELS command from a bsg request | |
487 | * @job: fc_bsg_job to handle | |
3b5dd52a | 488 | **/ |
f1c3b0fc JS |
489 | static int |
490 | lpfc_bsg_rport_els(struct fc_bsg_job *job) | |
491 | { | |
492 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
493 | struct lpfc_hba *phba = vport->phba; | |
494 | struct lpfc_rport_data *rdata = job->rport->dd_data; | |
495 | struct lpfc_nodelist *ndlp = rdata->pnode; | |
f1c3b0fc JS |
496 | uint32_t elscmd; |
497 | uint32_t cmdsize; | |
498 | uint32_t rspsize; | |
499 | struct lpfc_iocbq *rspiocbq; | |
500 | struct lpfc_iocbq *cmdiocbq; | |
501 | IOCB_t *rsp; | |
502 | uint16_t rpi = 0; | |
503 | struct lpfc_dmabuf *pcmd; | |
504 | struct lpfc_dmabuf *prsp; | |
505 | struct lpfc_dmabuf *pbuflist = NULL; | |
506 | struct ulp_bde64 *bpl; | |
f1c3b0fc JS |
507 | int request_nseg; |
508 | int reply_nseg; | |
509 | struct scatterlist *sgel = NULL; | |
510 | int numbde; | |
511 | dma_addr_t busaddr; | |
4cc0e56e JS |
512 | struct bsg_job_data *dd_data; |
513 | uint32_t creg_val; | |
f1c3b0fc JS |
514 | int rc = 0; |
515 | ||
516 | /* in case no data is transferred */ | |
517 | job->reply->reply_payload_rcv_len = 0; | |
518 | ||
4cc0e56e JS |
519 | /* allocate our bsg tracking structure */ |
520 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
521 | if (!dd_data) { | |
522 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
523 | "2735 Failed allocation of dd_data\n"); | |
524 | rc = -ENOMEM; | |
525 | goto no_dd_data; | |
526 | } | |
527 | ||
f1c3b0fc JS |
528 | if (!lpfc_nlp_get(ndlp)) { |
529 | rc = -ENODEV; | |
4cc0e56e | 530 | goto free_dd_data; |
f1c3b0fc JS |
531 | } |
532 | ||
533 | elscmd = job->request->rqst_data.r_els.els_code; | |
534 | cmdsize = job->request_payload.payload_len; | |
535 | rspsize = job->reply_payload.payload_len; | |
536 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
537 | if (!rspiocbq) { | |
538 | lpfc_nlp_put(ndlp); | |
539 | rc = -ENOMEM; | |
4cc0e56e | 540 | goto free_dd_data; |
f1c3b0fc JS |
541 | } |
542 | ||
543 | rsp = &rspiocbq->iocb; | |
544 | rpi = ndlp->nlp_rpi; | |
545 | ||
4cc0e56e | 546 | cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, |
f1c3b0fc | 547 | ndlp->nlp_DID, elscmd); |
f1c3b0fc | 548 | if (!cmdiocbq) { |
4cc0e56e JS |
549 | rc = -EIO; |
550 | goto free_rspiocbq; | |
f1c3b0fc JS |
551 | } |
552 | ||
4cc0e56e | 553 | /* prep els iocb set context1 to the ndlp, context2 to the command |
3b5dd52a JS |
554 | * dmabuf, context3 holds the data dmabuf |
555 | */ | |
f1c3b0fc JS |
556 | pcmd = (struct lpfc_dmabuf *) cmdiocbq->context2; |
557 | prsp = (struct lpfc_dmabuf *) pcmd->list.next; | |
f1c3b0fc JS |
558 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
559 | kfree(pcmd); | |
560 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | |
561 | kfree(prsp); | |
562 | cmdiocbq->context2 = NULL; | |
563 | ||
564 | pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3; | |
565 | bpl = (struct ulp_bde64 *) pbuflist->virt; | |
566 | ||
567 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, | |
568 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
f1c3b0fc JS |
569 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { |
570 | busaddr = sg_dma_address(sgel); | |
571 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
572 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
573 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
574 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
575 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
576 | bpl++; | |
577 | } | |
578 | ||
579 | reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list, | |
580 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
581 | for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) { | |
582 | busaddr = sg_dma_address(sgel); | |
583 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
584 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
585 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
586 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
587 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
588 | bpl++; | |
589 | } | |
f1c3b0fc JS |
590 | cmdiocbq->iocb.un.elsreq64.bdl.bdeSize = |
591 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); | |
592 | cmdiocbq->iocb.ulpContext = rpi; | |
593 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
594 | cmdiocbq->context1 = NULL; | |
595 | cmdiocbq->context2 = NULL; | |
596 | ||
4cc0e56e JS |
597 | cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp; |
598 | cmdiocbq->context1 = dd_data; | |
599 | cmdiocbq->context2 = rspiocbq; | |
600 | dd_data->type = TYPE_IOCB; | |
601 | dd_data->context_un.iocb.cmdiocbq = cmdiocbq; | |
602 | dd_data->context_un.iocb.rspiocbq = rspiocbq; | |
603 | dd_data->context_un.iocb.set_job = job; | |
6eab04a8 | 604 | dd_data->context_un.iocb.bmp = NULL; |
4cc0e56e JS |
605 | dd_data->context_un.iocb.ndlp = ndlp; |
606 | ||
607 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
9940b97b JS |
608 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
609 | rc = -EIO; | |
610 | goto linkdown_err; | |
611 | } | |
4cc0e56e JS |
612 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
613 | writel(creg_val, phba->HCregaddr); | |
614 | readl(phba->HCregaddr); /* flush */ | |
615 | } | |
616 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); | |
f1c3b0fc | 617 | lpfc_nlp_put(ndlp); |
4cc0e56e JS |
618 | if (rc == IOCB_SUCCESS) |
619 | return 0; /* done for now */ | |
2a9bf3d0 | 620 | else if (rc == IOCB_BUSY) |
d439d286 | 621 | rc = -EAGAIN; |
2a9bf3d0 | 622 | else |
d439d286 | 623 | rc = -EIO; |
f1c3b0fc | 624 | |
9940b97b | 625 | linkdown_err: |
4cc0e56e JS |
626 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, |
627 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
628 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
629 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
f1c3b0fc | 630 | |
4cc0e56e | 631 | lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys); |
f1c3b0fc | 632 | |
4cc0e56e | 633 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
f1c3b0fc | 634 | |
4cc0e56e JS |
635 | free_rspiocbq: |
636 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
f1c3b0fc | 637 | |
4cc0e56e JS |
638 | free_dd_data: |
639 | kfree(dd_data); | |
f1c3b0fc | 640 | |
4cc0e56e JS |
641 | no_dd_data: |
642 | /* make error code available to userspace */ | |
643 | job->reply->result = rc; | |
644 | job->dd_data = NULL; | |
645 | return rc; | |
f1c3b0fc JS |
646 | } |
647 | ||
3b5dd52a JS |
648 | /** |
649 | * lpfc_bsg_event_free - frees an allocated event structure | |
650 | * @kref: Pointer to a kref. | |
651 | * | |
652 | * Called from kref_put. Back cast the kref into an event structure address. | |
653 | * Free any events to get, delete associated nodes, free any events to see, | |
654 | * free any data then free the event itself. | |
655 | **/ | |
f1c3b0fc | 656 | static void |
4cc0e56e | 657 | lpfc_bsg_event_free(struct kref *kref) |
f1c3b0fc | 658 | { |
4cc0e56e JS |
659 | struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event, |
660 | kref); | |
f1c3b0fc JS |
661 | struct event_data *ed; |
662 | ||
663 | list_del(&evt->node); | |
664 | ||
665 | while (!list_empty(&evt->events_to_get)) { | |
666 | ed = list_entry(evt->events_to_get.next, typeof(*ed), node); | |
667 | list_del(&ed->node); | |
668 | kfree(ed->data); | |
669 | kfree(ed); | |
670 | } | |
671 | ||
672 | while (!list_empty(&evt->events_to_see)) { | |
673 | ed = list_entry(evt->events_to_see.next, typeof(*ed), node); | |
674 | list_del(&ed->node); | |
675 | kfree(ed->data); | |
676 | kfree(ed); | |
677 | } | |
678 | ||
679 | kfree(evt); | |
680 | } | |
681 | ||
3b5dd52a JS |
682 | /** |
683 | * lpfc_bsg_event_ref - increments the kref for an event | |
684 | * @evt: Pointer to an event structure. | |
685 | **/ | |
f1c3b0fc | 686 | static inline void |
4cc0e56e | 687 | lpfc_bsg_event_ref(struct lpfc_bsg_event *evt) |
f1c3b0fc | 688 | { |
4cc0e56e | 689 | kref_get(&evt->kref); |
f1c3b0fc JS |
690 | } |
691 | ||
3b5dd52a JS |
692 | /** |
693 | * lpfc_bsg_event_unref - Uses kref_put to free an event structure | |
694 | * @evt: Pointer to an event structure. | |
695 | **/ | |
f1c3b0fc | 696 | static inline void |
4cc0e56e | 697 | lpfc_bsg_event_unref(struct lpfc_bsg_event *evt) |
f1c3b0fc | 698 | { |
4cc0e56e | 699 | kref_put(&evt->kref, lpfc_bsg_event_free); |
f1c3b0fc JS |
700 | } |
701 | ||
3b5dd52a JS |
702 | /** |
703 | * lpfc_bsg_event_new - allocate and initialize a event structure | |
704 | * @ev_mask: Mask of events. | |
705 | * @ev_reg_id: Event reg id. | |
706 | * @ev_req_id: Event request id. | |
707 | **/ | |
4cc0e56e JS |
708 | static struct lpfc_bsg_event * |
709 | lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id) | |
710 | { | |
711 | struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL); | |
f1c3b0fc | 712 | |
4cc0e56e JS |
713 | if (!evt) |
714 | return NULL; | |
715 | ||
716 | INIT_LIST_HEAD(&evt->events_to_get); | |
717 | INIT_LIST_HEAD(&evt->events_to_see); | |
718 | evt->type_mask = ev_mask; | |
719 | evt->req_id = ev_req_id; | |
720 | evt->reg_id = ev_reg_id; | |
721 | evt->wait_time_stamp = jiffies; | |
722 | init_waitqueue_head(&evt->wq); | |
723 | kref_init(&evt->kref); | |
724 | return evt; | |
725 | } | |
726 | ||
3b5dd52a JS |
727 | /** |
728 | * diag_cmd_data_free - Frees an lpfc dma buffer extension | |
729 | * @phba: Pointer to HBA context object. | |
730 | * @mlist: Pointer to an lpfc dma buffer extension. | |
731 | **/ | |
4cc0e56e | 732 | static int |
3b5dd52a | 733 | diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist) |
4cc0e56e JS |
734 | { |
735 | struct lpfc_dmabufext *mlast; | |
736 | struct pci_dev *pcidev; | |
737 | struct list_head head, *curr, *next; | |
738 | ||
739 | if ((!mlist) || (!lpfc_is_link_up(phba) && | |
740 | (phba->link_flag & LS_LOOPBACK_MODE))) { | |
741 | return 0; | |
742 | } | |
743 | ||
744 | pcidev = phba->pcidev; | |
745 | list_add_tail(&head, &mlist->dma.list); | |
746 | ||
747 | list_for_each_safe(curr, next, &head) { | |
748 | mlast = list_entry(curr, struct lpfc_dmabufext , dma.list); | |
749 | if (mlast->dma.virt) | |
750 | dma_free_coherent(&pcidev->dev, | |
751 | mlast->size, | |
752 | mlast->dma.virt, | |
753 | mlast->dma.phys); | |
754 | kfree(mlast); | |
755 | } | |
756 | return 0; | |
757 | } | |
f1c3b0fc JS |
758 | |
759 | /** | |
760 | * lpfc_bsg_ct_unsol_event - process an unsolicited CT command | |
761 | * @phba: | |
762 | * @pring: | |
763 | * @piocbq: | |
764 | * | |
765 | * This function is called when an unsolicited CT command is received. It | |
4cc0e56e | 766 | * forwards the event to any processes registered to receive CT events. |
3b5dd52a | 767 | **/ |
4fede78f | 768 | int |
f1c3b0fc JS |
769 | lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
770 | struct lpfc_iocbq *piocbq) | |
771 | { | |
772 | uint32_t evt_req_id = 0; | |
773 | uint32_t cmd; | |
774 | uint32_t len; | |
775 | struct lpfc_dmabuf *dmabuf = NULL; | |
4cc0e56e | 776 | struct lpfc_bsg_event *evt; |
f1c3b0fc JS |
777 | struct event_data *evt_dat = NULL; |
778 | struct lpfc_iocbq *iocbq; | |
779 | size_t offset = 0; | |
780 | struct list_head head; | |
781 | struct ulp_bde64 *bde; | |
782 | dma_addr_t dma_addr; | |
783 | int i; | |
784 | struct lpfc_dmabuf *bdeBuf1 = piocbq->context2; | |
785 | struct lpfc_dmabuf *bdeBuf2 = piocbq->context3; | |
786 | struct lpfc_hbq_entry *hbqe; | |
787 | struct lpfc_sli_ct_request *ct_req; | |
4cc0e56e | 788 | struct fc_bsg_job *job = NULL; |
4fede78f | 789 | unsigned long flags; |
4cc0e56e | 790 | int size = 0; |
f1c3b0fc JS |
791 | |
792 | INIT_LIST_HEAD(&head); | |
793 | list_add_tail(&head, &piocbq->list); | |
794 | ||
795 | if (piocbq->iocb.ulpBdeCount == 0 || | |
796 | piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0) | |
797 | goto error_ct_unsol_exit; | |
798 | ||
4cc0e56e JS |
799 | if (phba->link_state == LPFC_HBA_ERROR || |
800 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) | |
801 | goto error_ct_unsol_exit; | |
802 | ||
f1c3b0fc JS |
803 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
804 | dmabuf = bdeBuf1; | |
805 | else { | |
806 | dma_addr = getPaddr(piocbq->iocb.un.cont64[0].addrHigh, | |
807 | piocbq->iocb.un.cont64[0].addrLow); | |
808 | dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr); | |
809 | } | |
4cc0e56e JS |
810 | if (dmabuf == NULL) |
811 | goto error_ct_unsol_exit; | |
f1c3b0fc JS |
812 | ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt; |
813 | evt_req_id = ct_req->FsType; | |
814 | cmd = ct_req->CommandResponse.bits.CmdRsp; | |
815 | len = ct_req->CommandResponse.bits.Size; | |
816 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) | |
817 | lpfc_sli_ringpostbuf_put(phba, pring, dmabuf); | |
818 | ||
4fede78f | 819 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc | 820 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
4cc0e56e JS |
821 | if (!(evt->type_mask & FC_REG_CT_EVENT) || |
822 | evt->req_id != evt_req_id) | |
f1c3b0fc JS |
823 | continue; |
824 | ||
4cc0e56e JS |
825 | lpfc_bsg_event_ref(evt); |
826 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
f1c3b0fc | 827 | evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL); |
4cc0e56e JS |
828 | if (evt_dat == NULL) { |
829 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
830 | lpfc_bsg_event_unref(evt); | |
f1c3b0fc JS |
831 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
832 | "2614 Memory allocation failed for " | |
833 | "CT event\n"); | |
834 | break; | |
835 | } | |
836 | ||
f1c3b0fc JS |
837 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
838 | /* take accumulated byte count from the last iocbq */ | |
839 | iocbq = list_entry(head.prev, typeof(*iocbq), list); | |
840 | evt_dat->len = iocbq->iocb.unsli3.rcvsli3.acc_len; | |
841 | } else { | |
842 | list_for_each_entry(iocbq, &head, list) { | |
843 | for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) | |
844 | evt_dat->len += | |
845 | iocbq->iocb.un.cont64[i].tus.f.bdeSize; | |
846 | } | |
847 | } | |
848 | ||
849 | evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL); | |
4cc0e56e | 850 | if (evt_dat->data == NULL) { |
f1c3b0fc JS |
851 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
852 | "2615 Memory allocation failed for " | |
853 | "CT event data, size %d\n", | |
854 | evt_dat->len); | |
855 | kfree(evt_dat); | |
4fede78f | 856 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
4cc0e56e | 857 | lpfc_bsg_event_unref(evt); |
4fede78f | 858 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
859 | goto error_ct_unsol_exit; |
860 | } | |
861 | ||
862 | list_for_each_entry(iocbq, &head, list) { | |
4cc0e56e | 863 | size = 0; |
f1c3b0fc JS |
864 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
865 | bdeBuf1 = iocbq->context2; | |
866 | bdeBuf2 = iocbq->context3; | |
867 | } | |
868 | for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) { | |
f1c3b0fc JS |
869 | if (phba->sli3_options & |
870 | LPFC_SLI3_HBQ_ENABLED) { | |
871 | if (i == 0) { | |
872 | hbqe = (struct lpfc_hbq_entry *) | |
873 | &iocbq->iocb.un.ulpWord[0]; | |
874 | size = hbqe->bde.tus.f.bdeSize; | |
875 | dmabuf = bdeBuf1; | |
876 | } else if (i == 1) { | |
877 | hbqe = (struct lpfc_hbq_entry *) | |
878 | &iocbq->iocb.unsli3. | |
879 | sli3Words[4]; | |
880 | size = hbqe->bde.tus.f.bdeSize; | |
881 | dmabuf = bdeBuf2; | |
882 | } | |
883 | if ((offset + size) > evt_dat->len) | |
884 | size = evt_dat->len - offset; | |
885 | } else { | |
886 | size = iocbq->iocb.un.cont64[i]. | |
887 | tus.f.bdeSize; | |
888 | bde = &iocbq->iocb.un.cont64[i]; | |
889 | dma_addr = getPaddr(bde->addrHigh, | |
890 | bde->addrLow); | |
891 | dmabuf = lpfc_sli_ringpostbuf_get(phba, | |
892 | pring, dma_addr); | |
893 | } | |
894 | if (!dmabuf) { | |
895 | lpfc_printf_log(phba, KERN_ERR, | |
896 | LOG_LIBDFC, "2616 No dmabuf " | |
897 | "found for iocbq 0x%p\n", | |
898 | iocbq); | |
899 | kfree(evt_dat->data); | |
900 | kfree(evt_dat); | |
4fede78f JS |
901 | spin_lock_irqsave(&phba->ct_ev_lock, |
902 | flags); | |
4cc0e56e | 903 | lpfc_bsg_event_unref(evt); |
4fede78f JS |
904 | spin_unlock_irqrestore( |
905 | &phba->ct_ev_lock, flags); | |
f1c3b0fc JS |
906 | goto error_ct_unsol_exit; |
907 | } | |
908 | memcpy((char *)(evt_dat->data) + offset, | |
909 | dmabuf->virt, size); | |
910 | offset += size; | |
911 | if (evt_req_id != SLI_CT_ELX_LOOPBACK && | |
912 | !(phba->sli3_options & | |
913 | LPFC_SLI3_HBQ_ENABLED)) { | |
914 | lpfc_sli_ringpostbuf_put(phba, pring, | |
915 | dmabuf); | |
916 | } else { | |
917 | switch (cmd) { | |
4cc0e56e | 918 | case ELX_LOOPBACK_DATA: |
3b5dd52a | 919 | diag_cmd_data_free(phba, |
4cc0e56e JS |
920 | (struct lpfc_dmabufext *) |
921 | dmabuf); | |
922 | break; | |
f1c3b0fc | 923 | case ELX_LOOPBACK_XRI_SETUP: |
4cc0e56e JS |
924 | if ((phba->sli_rev == |
925 | LPFC_SLI_REV2) || | |
926 | (phba->sli3_options & | |
927 | LPFC_SLI3_HBQ_ENABLED | |
928 | )) { | |
929 | lpfc_in_buf_free(phba, | |
930 | dmabuf); | |
931 | } else { | |
f1c3b0fc JS |
932 | lpfc_post_buffer(phba, |
933 | pring, | |
934 | 1); | |
4cc0e56e | 935 | } |
f1c3b0fc JS |
936 | break; |
937 | default: | |
938 | if (!(phba->sli3_options & | |
939 | LPFC_SLI3_HBQ_ENABLED)) | |
940 | lpfc_post_buffer(phba, | |
941 | pring, | |
942 | 1); | |
943 | break; | |
944 | } | |
945 | } | |
946 | } | |
947 | } | |
948 | ||
4fede78f | 949 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
950 | if (phba->sli_rev == LPFC_SLI_REV4) { |
951 | evt_dat->immed_dat = phba->ctx_idx; | |
952 | phba->ctx_idx = (phba->ctx_idx + 1) % 64; | |
589a52d6 JS |
953 | /* Provide warning for over-run of the ct_ctx array */ |
954 | if (phba->ct_ctx[evt_dat->immed_dat].flags & | |
955 | UNSOL_VALID) | |
956 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
957 | "2717 CT context array entry " | |
958 | "[%d] over-run: oxid:x%x, " | |
959 | "sid:x%x\n", phba->ctx_idx, | |
960 | phba->ct_ctx[ | |
961 | evt_dat->immed_dat].oxid, | |
962 | phba->ct_ctx[ | |
963 | evt_dat->immed_dat].SID); | |
7851fe2c JS |
964 | phba->ct_ctx[evt_dat->immed_dat].rxid = |
965 | piocbq->iocb.ulpContext; | |
f1c3b0fc | 966 | phba->ct_ctx[evt_dat->immed_dat].oxid = |
7851fe2c | 967 | piocbq->iocb.unsli3.rcvsli3.ox_id; |
f1c3b0fc JS |
968 | phba->ct_ctx[evt_dat->immed_dat].SID = |
969 | piocbq->iocb.un.rcvels.remoteID; | |
589a52d6 | 970 | phba->ct_ctx[evt_dat->immed_dat].flags = UNSOL_VALID; |
f1c3b0fc JS |
971 | } else |
972 | evt_dat->immed_dat = piocbq->iocb.ulpContext; | |
973 | ||
974 | evt_dat->type = FC_REG_CT_EVENT; | |
975 | list_add(&evt_dat->node, &evt->events_to_see); | |
4cc0e56e JS |
976 | if (evt_req_id == SLI_CT_ELX_LOOPBACK) { |
977 | wake_up_interruptible(&evt->wq); | |
978 | lpfc_bsg_event_unref(evt); | |
f1c3b0fc | 979 | break; |
4cc0e56e JS |
980 | } |
981 | ||
982 | list_move(evt->events_to_see.prev, &evt->events_to_get); | |
983 | lpfc_bsg_event_unref(evt); | |
984 | ||
985 | job = evt->set_job; | |
986 | evt->set_job = NULL; | |
987 | if (job) { | |
988 | job->reply->reply_payload_rcv_len = size; | |
989 | /* make error code available to userspace */ | |
990 | job->reply->result = 0; | |
991 | job->dd_data = NULL; | |
992 | /* complete the job back to userspace */ | |
993 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
994 | job->job_done(job); | |
995 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
996 | } | |
f1c3b0fc | 997 | } |
4fede78f | 998 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
999 | |
1000 | error_ct_unsol_exit: | |
1001 | if (!list_empty(&head)) | |
1002 | list_del(&head); | |
4cc0e56e JS |
1003 | if (evt_req_id == SLI_CT_ELX_LOOPBACK) |
1004 | return 0; | |
4fede78f | 1005 | return 1; |
f1c3b0fc JS |
1006 | } |
1007 | ||
1008 | /** | |
4cc0e56e | 1009 | * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command |
f1c3b0fc | 1010 | * @job: SET_EVENT fc_bsg_job |
3b5dd52a | 1011 | **/ |
f1c3b0fc | 1012 | static int |
4cc0e56e | 1013 | lpfc_bsg_hba_set_event(struct fc_bsg_job *job) |
f1c3b0fc JS |
1014 | { |
1015 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
1016 | struct lpfc_hba *phba = vport->phba; | |
1017 | struct set_ct_event *event_req; | |
4cc0e56e | 1018 | struct lpfc_bsg_event *evt; |
f1c3b0fc | 1019 | int rc = 0; |
4cc0e56e JS |
1020 | struct bsg_job_data *dd_data = NULL; |
1021 | uint32_t ev_mask; | |
1022 | unsigned long flags; | |
f1c3b0fc JS |
1023 | |
1024 | if (job->request_len < | |
1025 | sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) { | |
1026 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1027 | "2612 Received SET_CT_EVENT below minimum " | |
1028 | "size\n"); | |
4cc0e56e JS |
1029 | rc = -EINVAL; |
1030 | goto job_error; | |
1031 | } | |
1032 | ||
1033 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
1034 | if (dd_data == NULL) { | |
1035 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1036 | "2734 Failed allocation of dd_data\n"); | |
1037 | rc = -ENOMEM; | |
1038 | goto job_error; | |
f1c3b0fc JS |
1039 | } |
1040 | ||
1041 | event_req = (struct set_ct_event *) | |
1042 | job->request->rqst_data.h_vendor.vendor_cmd; | |
4cc0e56e JS |
1043 | ev_mask = ((uint32_t)(unsigned long)event_req->type_mask & |
1044 | FC_REG_EVENT_MASK); | |
4fede78f | 1045 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1046 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
1047 | if (evt->reg_id == event_req->ev_reg_id) { | |
4cc0e56e | 1048 | lpfc_bsg_event_ref(evt); |
f1c3b0fc JS |
1049 | evt->wait_time_stamp = jiffies; |
1050 | break; | |
1051 | } | |
1052 | } | |
4fede78f | 1053 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1054 | |
1055 | if (&evt->node == &phba->ct_ev_waiters) { | |
1056 | /* no event waiting struct yet - first call */ | |
4cc0e56e | 1057 | evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id, |
f1c3b0fc JS |
1058 | event_req->ev_req_id); |
1059 | if (!evt) { | |
1060 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1061 | "2617 Failed allocation of event " | |
1062 | "waiter\n"); | |
4cc0e56e JS |
1063 | rc = -ENOMEM; |
1064 | goto job_error; | |
f1c3b0fc JS |
1065 | } |
1066 | ||
4fede78f | 1067 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc | 1068 | list_add(&evt->node, &phba->ct_ev_waiters); |
4cc0e56e JS |
1069 | lpfc_bsg_event_ref(evt); |
1070 | evt->wait_time_stamp = jiffies; | |
4fede78f | 1071 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1072 | } |
1073 | ||
4fede78f | 1074 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
4cc0e56e JS |
1075 | evt->waiting = 1; |
1076 | dd_data->type = TYPE_EVT; | |
1077 | dd_data->context_un.evt = evt; | |
1078 | evt->set_job = job; /* for unsolicited command */ | |
1079 | job->dd_data = dd_data; /* for fc transport timeout callback*/ | |
4fede78f | 1080 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4cc0e56e | 1081 | return 0; /* call job done later */ |
f1c3b0fc | 1082 | |
4cc0e56e JS |
1083 | job_error: |
1084 | if (dd_data != NULL) | |
1085 | kfree(dd_data); | |
f1c3b0fc | 1086 | |
4cc0e56e JS |
1087 | job->dd_data = NULL; |
1088 | return rc; | |
f1c3b0fc JS |
1089 | } |
1090 | ||
1091 | /** | |
4cc0e56e | 1092 | * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command |
f1c3b0fc | 1093 | * @job: GET_EVENT fc_bsg_job |
3b5dd52a | 1094 | **/ |
f1c3b0fc | 1095 | static int |
4cc0e56e | 1096 | lpfc_bsg_hba_get_event(struct fc_bsg_job *job) |
f1c3b0fc JS |
1097 | { |
1098 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
1099 | struct lpfc_hba *phba = vport->phba; | |
1100 | struct get_ct_event *event_req; | |
1101 | struct get_ct_event_reply *event_reply; | |
4cc0e56e | 1102 | struct lpfc_bsg_event *evt; |
f1c3b0fc | 1103 | struct event_data *evt_dat = NULL; |
4fede78f | 1104 | unsigned long flags; |
4cc0e56e | 1105 | uint32_t rc = 0; |
f1c3b0fc JS |
1106 | |
1107 | if (job->request_len < | |
1108 | sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) { | |
1109 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1110 | "2613 Received GET_CT_EVENT request below " | |
1111 | "minimum size\n"); | |
4cc0e56e JS |
1112 | rc = -EINVAL; |
1113 | goto job_error; | |
f1c3b0fc JS |
1114 | } |
1115 | ||
1116 | event_req = (struct get_ct_event *) | |
1117 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1118 | ||
1119 | event_reply = (struct get_ct_event_reply *) | |
1120 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
4fede78f | 1121 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1122 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
1123 | if (evt->reg_id == event_req->ev_reg_id) { | |
1124 | if (list_empty(&evt->events_to_get)) | |
1125 | break; | |
4cc0e56e | 1126 | lpfc_bsg_event_ref(evt); |
f1c3b0fc JS |
1127 | evt->wait_time_stamp = jiffies; |
1128 | evt_dat = list_entry(evt->events_to_get.prev, | |
1129 | struct event_data, node); | |
1130 | list_del(&evt_dat->node); | |
1131 | break; | |
1132 | } | |
1133 | } | |
4fede78f | 1134 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc | 1135 | |
4cc0e56e JS |
1136 | /* The app may continue to ask for event data until it gets |
1137 | * an error indicating that there isn't anymore | |
1138 | */ | |
1139 | if (evt_dat == NULL) { | |
f1c3b0fc JS |
1140 | job->reply->reply_payload_rcv_len = 0; |
1141 | rc = -ENOENT; | |
4cc0e56e | 1142 | goto job_error; |
f1c3b0fc JS |
1143 | } |
1144 | ||
4cc0e56e JS |
1145 | if (evt_dat->len > job->request_payload.payload_len) { |
1146 | evt_dat->len = job->request_payload.payload_len; | |
1147 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1148 | "2618 Truncated event data at %d " | |
1149 | "bytes\n", | |
1150 | job->request_payload.payload_len); | |
f1c3b0fc JS |
1151 | } |
1152 | ||
4cc0e56e | 1153 | event_reply->type = evt_dat->type; |
f1c3b0fc | 1154 | event_reply->immed_data = evt_dat->immed_dat; |
f1c3b0fc JS |
1155 | if (evt_dat->len > 0) |
1156 | job->reply->reply_payload_rcv_len = | |
4cc0e56e JS |
1157 | sg_copy_from_buffer(job->request_payload.sg_list, |
1158 | job->request_payload.sg_cnt, | |
f1c3b0fc JS |
1159 | evt_dat->data, evt_dat->len); |
1160 | else | |
1161 | job->reply->reply_payload_rcv_len = 0; | |
f1c3b0fc | 1162 | |
4cc0e56e | 1163 | if (evt_dat) { |
f1c3b0fc | 1164 | kfree(evt_dat->data); |
4cc0e56e JS |
1165 | kfree(evt_dat); |
1166 | } | |
1167 | ||
4fede78f | 1168 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
4cc0e56e | 1169 | lpfc_bsg_event_unref(evt); |
4fede78f | 1170 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4cc0e56e JS |
1171 | job->dd_data = NULL; |
1172 | job->reply->result = 0; | |
f1c3b0fc | 1173 | job->job_done(job); |
4cc0e56e | 1174 | return 0; |
f1c3b0fc | 1175 | |
4cc0e56e JS |
1176 | job_error: |
1177 | job->dd_data = NULL; | |
1178 | job->reply->result = rc; | |
f1c3b0fc JS |
1179 | return rc; |
1180 | } | |
1181 | ||
1182 | /** | |
3b5dd52a JS |
1183 | * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler |
1184 | * @phba: Pointer to HBA context object. | |
1185 | * @cmdiocbq: Pointer to command iocb. | |
1186 | * @rspiocbq: Pointer to response iocb. | |
1187 | * | |
1188 | * This function is the completion handler for iocbs issued using | |
1189 | * lpfc_issue_ct_rsp_cmp function. This function is called by the | |
1190 | * ring event handler function without any lock held. This function | |
1191 | * can be called from both worker thread context and interrupt | |
1192 | * context. This function also can be called from other thread which | |
1193 | * cleans up the SLI layer objects. | |
1194 | * This function copy the contents of the response iocb to the | |
1195 | * response iocb memory object provided by the caller of | |
1196 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
1197 | * sleeps for the iocb completion. | |
1198 | **/ | |
1199 | static void | |
1200 | lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba, | |
1201 | struct lpfc_iocbq *cmdiocbq, | |
1202 | struct lpfc_iocbq *rspiocbq) | |
1203 | { | |
1204 | struct bsg_job_data *dd_data; | |
1205 | struct fc_bsg_job *job; | |
1206 | IOCB_t *rsp; | |
1207 | struct lpfc_dmabuf *bmp; | |
1208 | struct lpfc_nodelist *ndlp; | |
1209 | unsigned long flags; | |
1210 | int rc = 0; | |
1211 | ||
1212 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
be858b65 | 1213 | dd_data = cmdiocbq->context2; |
3b5dd52a JS |
1214 | /* normal completion and timeout crossed paths, already done */ |
1215 | if (!dd_data) { | |
67221a42 | 1216 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
3b5dd52a JS |
1217 | return; |
1218 | } | |
1219 | ||
1220 | job = dd_data->context_un.iocb.set_job; | |
1221 | bmp = dd_data->context_un.iocb.bmp; | |
1222 | rsp = &rspiocbq->iocb; | |
1223 | ndlp = dd_data->context_un.iocb.ndlp; | |
1224 | ||
1225 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
1226 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1227 | ||
1228 | if (rsp->ulpStatus) { | |
1229 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
1230 | switch (rsp->un.ulpWord[4] & 0xff) { | |
1231 | case IOERR_SEQUENCE_TIMEOUT: | |
1232 | rc = -ETIMEDOUT; | |
1233 | break; | |
1234 | case IOERR_INVALID_RPI: | |
1235 | rc = -EFAULT; | |
1236 | break; | |
1237 | default: | |
1238 | rc = -EACCES; | |
1239 | break; | |
1240 | } | |
1241 | } else | |
1242 | rc = -EACCES; | |
1243 | } else | |
1244 | job->reply->reply_payload_rcv_len = | |
1245 | rsp->un.genreq64.bdl.bdeSize; | |
1246 | ||
1247 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
1248 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
1249 | lpfc_nlp_put(ndlp); | |
1250 | kfree(bmp); | |
1251 | kfree(dd_data); | |
1252 | /* make error code available to userspace */ | |
1253 | job->reply->result = rc; | |
1254 | job->dd_data = NULL; | |
1255 | /* complete the job back to userspace */ | |
1256 | job->job_done(job); | |
1257 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
1258 | return; | |
1259 | } | |
1260 | ||
1261 | /** | |
1262 | * lpfc_issue_ct_rsp - issue a ct response | |
1263 | * @phba: Pointer to HBA context object. | |
1264 | * @job: Pointer to the job object. | |
1265 | * @tag: tag index value into the ports context exchange array. | |
1266 | * @bmp: Pointer to a dma buffer descriptor. | |
1267 | * @num_entry: Number of enties in the bde. | |
1268 | **/ | |
f1c3b0fc | 1269 | static int |
3b5dd52a JS |
1270 | lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag, |
1271 | struct lpfc_dmabuf *bmp, int num_entry) | |
f1c3b0fc | 1272 | { |
3b5dd52a JS |
1273 | IOCB_t *icmd; |
1274 | struct lpfc_iocbq *ctiocb = NULL; | |
1275 | int rc = 0; | |
1276 | struct lpfc_nodelist *ndlp = NULL; | |
1277 | struct bsg_job_data *dd_data; | |
1278 | uint32_t creg_val; | |
f1c3b0fc | 1279 | |
3b5dd52a JS |
1280 | /* allocate our bsg tracking structure */ |
1281 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
1282 | if (!dd_data) { | |
1283 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1284 | "2736 Failed allocation of dd_data\n"); | |
1285 | rc = -ENOMEM; | |
1286 | goto no_dd_data; | |
1287 | } | |
f1c3b0fc | 1288 | |
3b5dd52a JS |
1289 | /* Allocate buffer for command iocb */ |
1290 | ctiocb = lpfc_sli_get_iocbq(phba); | |
1291 | if (!ctiocb) { | |
d439d286 | 1292 | rc = -ENOMEM; |
3b5dd52a JS |
1293 | goto no_ctiocb; |
1294 | } | |
1295 | ||
1296 | icmd = &ctiocb->iocb; | |
1297 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; | |
1298 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
1299 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
1300 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
1301 | icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); | |
1302 | icmd->un.xseq64.w5.hcsw.Fctl = (LS | LA); | |
1303 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; | |
1304 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL; | |
1305 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; | |
1306 | ||
1307 | /* Fill in rest of iocb */ | |
1308 | icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; | |
1309 | icmd->ulpBdeCount = 1; | |
1310 | icmd->ulpLe = 1; | |
1311 | icmd->ulpClass = CLASS3; | |
1312 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
1313 | /* Do not issue unsol response if oxid not marked as valid */ | |
1314 | if (!(phba->ct_ctx[tag].flags & UNSOL_VALID)) { | |
1315 | rc = IOCB_ERROR; | |
1316 | goto issue_ct_rsp_exit; | |
1317 | } | |
7851fe2c JS |
1318 | icmd->ulpContext = phba->ct_ctx[tag].rxid; |
1319 | icmd->unsli3.rcvsli3.ox_id = phba->ct_ctx[tag].oxid; | |
3b5dd52a JS |
1320 | ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID); |
1321 | if (!ndlp) { | |
1322 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
1323 | "2721 ndlp null for oxid %x SID %x\n", | |
1324 | icmd->ulpContext, | |
1325 | phba->ct_ctx[tag].SID); | |
1326 | rc = IOCB_ERROR; | |
1327 | goto issue_ct_rsp_exit; | |
1328 | } | |
589a52d6 JS |
1329 | |
1330 | /* Check if the ndlp is active */ | |
1331 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | |
1332 | rc = -IOCB_ERROR; | |
1333 | goto issue_ct_rsp_exit; | |
1334 | } | |
1335 | ||
1336 | /* get a refernece count so the ndlp doesn't go away while | |
1337 | * we respond | |
1338 | */ | |
1339 | if (!lpfc_nlp_get(ndlp)) { | |
1340 | rc = -IOCB_ERROR; | |
1341 | goto issue_ct_rsp_exit; | |
1342 | } | |
1343 | ||
7851fe2c | 1344 | icmd->un.ulpWord[3] = |
6d368e53 JS |
1345 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
1346 | ||
3b5dd52a JS |
1347 | /* The exchange is done, mark the entry as invalid */ |
1348 | phba->ct_ctx[tag].flags &= ~UNSOL_VALID; | |
1349 | } else | |
1350 | icmd->ulpContext = (ushort) tag; | |
1351 | ||
1352 | icmd->ulpTimeout = phba->fc_ratov * 2; | |
1353 | ||
1354 | /* Xmit CT response on exchange <xid> */ | |
1355 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
7851fe2c JS |
1356 | "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n", |
1357 | icmd->ulpContext, icmd->ulpIoTag, tag, phba->link_state); | |
3b5dd52a JS |
1358 | |
1359 | ctiocb->iocb_cmpl = NULL; | |
1360 | ctiocb->iocb_flag |= LPFC_IO_LIBDFC; | |
1361 | ctiocb->vport = phba->pport; | |
1362 | ctiocb->context3 = bmp; | |
1363 | ||
1364 | ctiocb->iocb_cmpl = lpfc_issue_ct_rsp_cmp; | |
be858b65 JS |
1365 | ctiocb->context2 = dd_data; |
1366 | ctiocb->context1 = ndlp; | |
3b5dd52a JS |
1367 | dd_data->type = TYPE_IOCB; |
1368 | dd_data->context_un.iocb.cmdiocbq = ctiocb; | |
1369 | dd_data->context_un.iocb.rspiocbq = NULL; | |
1370 | dd_data->context_un.iocb.set_job = job; | |
1371 | dd_data->context_un.iocb.bmp = bmp; | |
1372 | dd_data->context_un.iocb.ndlp = ndlp; | |
1373 | ||
1374 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
9940b97b JS |
1375 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1376 | rc = -IOCB_ERROR; | |
1377 | goto issue_ct_rsp_exit; | |
1378 | } | |
3b5dd52a JS |
1379 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
1380 | writel(creg_val, phba->HCregaddr); | |
1381 | readl(phba->HCregaddr); /* flush */ | |
f1c3b0fc | 1382 | } |
4cc0e56e | 1383 | |
3b5dd52a JS |
1384 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
1385 | ||
1386 | if (rc == IOCB_SUCCESS) | |
1387 | return 0; /* done for now */ | |
1388 | ||
1389 | issue_ct_rsp_exit: | |
1390 | lpfc_sli_release_iocbq(phba, ctiocb); | |
1391 | no_ctiocb: | |
1392 | kfree(dd_data); | |
1393 | no_dd_data: | |
4cc0e56e | 1394 | return rc; |
f1c3b0fc JS |
1395 | } |
1396 | ||
1397 | /** | |
3b5dd52a JS |
1398 | * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command |
1399 | * @job: SEND_MGMT_RESP fc_bsg_job | |
1400 | **/ | |
1401 | static int | |
1402 | lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job) | |
f1c3b0fc | 1403 | { |
3b5dd52a JS |
1404 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
1405 | struct lpfc_hba *phba = vport->phba; | |
1406 | struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *) | |
1407 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1408 | struct ulp_bde64 *bpl; | |
1409 | struct lpfc_dmabuf *bmp = NULL; | |
1410 | struct scatterlist *sgel = NULL; | |
1411 | int request_nseg; | |
1412 | int numbde; | |
1413 | dma_addr_t busaddr; | |
1414 | uint32_t tag = mgmt_resp->tag; | |
1415 | unsigned long reqbfrcnt = | |
1416 | (unsigned long)job->request_payload.payload_len; | |
1417 | int rc = 0; | |
f1c3b0fc | 1418 | |
3b5dd52a JS |
1419 | /* in case no data is transferred */ |
1420 | job->reply->reply_payload_rcv_len = 0; | |
1421 | ||
1422 | if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) { | |
1423 | rc = -ERANGE; | |
1424 | goto send_mgmt_rsp_exit; | |
1425 | } | |
1426 | ||
1427 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
1428 | if (!bmp) { | |
1429 | rc = -ENOMEM; | |
1430 | goto send_mgmt_rsp_exit; | |
1431 | } | |
1432 | ||
1433 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); | |
1434 | if (!bmp->virt) { | |
1435 | rc = -ENOMEM; | |
1436 | goto send_mgmt_rsp_free_bmp; | |
1437 | } | |
1438 | ||
1439 | INIT_LIST_HEAD(&bmp->list); | |
1440 | bpl = (struct ulp_bde64 *) bmp->virt; | |
1441 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, | |
1442 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1443 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { | |
1444 | busaddr = sg_dma_address(sgel); | |
1445 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1446 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
1447 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
1448 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
1449 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
1450 | bpl++; | |
f1c3b0fc JS |
1451 | } |
1452 | ||
3b5dd52a JS |
1453 | rc = lpfc_issue_ct_rsp(phba, job, tag, bmp, request_nseg); |
1454 | ||
1455 | if (rc == IOCB_SUCCESS) | |
1456 | return 0; /* done for now */ | |
1457 | ||
1458 | /* TBD need to handle a timeout */ | |
1459 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
1460 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1461 | rc = -EACCES; | |
1462 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
1463 | ||
1464 | send_mgmt_rsp_free_bmp: | |
1465 | kfree(bmp); | |
1466 | send_mgmt_rsp_exit: | |
1467 | /* make error code available to userspace */ | |
1468 | job->reply->result = rc; | |
1469 | job->dd_data = NULL; | |
f1c3b0fc JS |
1470 | return rc; |
1471 | } | |
1472 | ||
1473 | /** | |
7ad20aa9 JS |
1474 | * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode |
1475 | * @phba: Pointer to HBA context object. | |
7ad20aa9 JS |
1476 | * |
1477 | * This function is responsible for preparing driver for diag loopback | |
1478 | * on device. | |
1479 | */ | |
1480 | static int | |
88a2cfbb | 1481 | lpfc_bsg_diag_mode_enter(struct lpfc_hba *phba) |
7ad20aa9 JS |
1482 | { |
1483 | struct lpfc_vport **vports; | |
1484 | struct Scsi_Host *shost; | |
1485 | struct lpfc_sli *psli; | |
1486 | struct lpfc_sli_ring *pring; | |
1487 | int i = 0; | |
1488 | ||
1489 | psli = &phba->sli; | |
1490 | if (!psli) | |
1491 | return -ENODEV; | |
1492 | ||
1493 | pring = &psli->ring[LPFC_FCP_RING]; | |
1494 | if (!pring) | |
1495 | return -ENODEV; | |
1496 | ||
1497 | if ((phba->link_state == LPFC_HBA_ERROR) || | |
1498 | (psli->sli_flag & LPFC_BLOCK_MGMT_IO) || | |
1499 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) | |
1500 | return -EACCES; | |
1501 | ||
1502 | vports = lpfc_create_vport_work_array(phba); | |
1503 | if (vports) { | |
1504 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
1505 | shost = lpfc_shost_from_vport(vports[i]); | |
1506 | scsi_block_requests(shost); | |
1507 | } | |
1508 | lpfc_destroy_vport_work_array(phba, vports); | |
1509 | } else { | |
1510 | shost = lpfc_shost_from_vport(phba->pport); | |
1511 | scsi_block_requests(shost); | |
1512 | } | |
1513 | ||
1514 | while (pring->txcmplq_cnt) { | |
1515 | if (i++ > 500) /* wait up to 5 seconds */ | |
1516 | break; | |
1517 | msleep(10); | |
1518 | } | |
1519 | return 0; | |
1520 | } | |
1521 | ||
1522 | /** | |
1523 | * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode | |
1524 | * @phba: Pointer to HBA context object. | |
7ad20aa9 JS |
1525 | * |
1526 | * This function is responsible for driver exit processing of setting up | |
1527 | * diag loopback mode on device. | |
1528 | */ | |
1529 | static void | |
1530 | lpfc_bsg_diag_mode_exit(struct lpfc_hba *phba) | |
1531 | { | |
1532 | struct Scsi_Host *shost; | |
1533 | struct lpfc_vport **vports; | |
1534 | int i; | |
1535 | ||
1536 | vports = lpfc_create_vport_work_array(phba); | |
1537 | if (vports) { | |
1538 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
1539 | shost = lpfc_shost_from_vport(vports[i]); | |
1540 | scsi_unblock_requests(shost); | |
1541 | } | |
1542 | lpfc_destroy_vport_work_array(phba, vports); | |
1543 | } else { | |
1544 | shost = lpfc_shost_from_vport(phba->pport); | |
1545 | scsi_unblock_requests(shost); | |
1546 | } | |
1547 | return; | |
1548 | } | |
1549 | ||
1550 | /** | |
1551 | * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command | |
1552 | * @phba: Pointer to HBA context object. | |
3b5dd52a | 1553 | * @job: LPFC_BSG_VENDOR_DIAG_MODE |
f1c3b0fc | 1554 | * |
7ad20aa9 JS |
1555 | * This function is responsible for placing an sli3 port into diagnostic |
1556 | * loopback mode in order to perform a diagnostic loopback test. | |
3b5dd52a JS |
1557 | * All new scsi requests are blocked, a small delay is used to allow the |
1558 | * scsi requests to complete then the link is brought down. If the link is | |
1559 | * is placed in loopback mode then scsi requests are again allowed | |
1560 | * so the scsi mid-layer doesn't give up on the port. | |
1561 | * All of this is done in-line. | |
f1c3b0fc | 1562 | */ |
3b5dd52a | 1563 | static int |
7ad20aa9 | 1564 | lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job) |
f1c3b0fc | 1565 | { |
3b5dd52a | 1566 | struct diag_mode_set *loopback_mode; |
3b5dd52a JS |
1567 | uint32_t link_flags; |
1568 | uint32_t timeout; | |
3b5dd52a | 1569 | LPFC_MBOXQ_t *pmboxq; |
b76f2dc9 | 1570 | int mbxstatus = MBX_SUCCESS; |
3b5dd52a JS |
1571 | int i = 0; |
1572 | int rc = 0; | |
f1c3b0fc | 1573 | |
3b5dd52a JS |
1574 | /* no data to return just the return code */ |
1575 | job->reply->reply_payload_rcv_len = 0; | |
1576 | ||
7ad20aa9 JS |
1577 | if (job->request_len < sizeof(struct fc_bsg_request) + |
1578 | sizeof(struct diag_mode_set)) { | |
3b5dd52a | 1579 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
7ad20aa9 JS |
1580 | "2738 Received DIAG MODE request size:%d " |
1581 | "below the minimum size:%d\n", | |
1582 | job->request_len, | |
1583 | (int)(sizeof(struct fc_bsg_request) + | |
1584 | sizeof(struct diag_mode_set))); | |
3b5dd52a JS |
1585 | rc = -EINVAL; |
1586 | goto job_error; | |
1587 | } | |
1588 | ||
88a2cfbb | 1589 | rc = lpfc_bsg_diag_mode_enter(phba); |
7ad20aa9 JS |
1590 | if (rc) |
1591 | goto job_error; | |
1592 | ||
1593 | /* bring the link to diagnostic mode */ | |
3b5dd52a JS |
1594 | loopback_mode = (struct diag_mode_set *) |
1595 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1596 | link_flags = loopback_mode->type; | |
515e0aa2 | 1597 | timeout = loopback_mode->timeout * 100; |
3b5dd52a | 1598 | |
3b5dd52a JS |
1599 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1600 | if (!pmboxq) { | |
1601 | rc = -ENOMEM; | |
7ad20aa9 | 1602 | goto loopback_mode_exit; |
3b5dd52a | 1603 | } |
3b5dd52a JS |
1604 | memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
1605 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; | |
1606 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
1607 | ||
1608 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); | |
1609 | ||
1610 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) { | |
1611 | /* wait for link down before proceeding */ | |
1612 | i = 0; | |
1613 | while (phba->link_state != LPFC_LINK_DOWN) { | |
1614 | if (i++ > timeout) { | |
1615 | rc = -ETIMEDOUT; | |
1616 | goto loopback_mode_exit; | |
1617 | } | |
1618 | ||
1619 | msleep(10); | |
1620 | } | |
1621 | ||
1622 | memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
1623 | if (link_flags == INTERNAL_LOOP_BACK) | |
1624 | pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB; | |
1625 | else | |
1626 | pmboxq->u.mb.un.varInitLnk.link_flags = | |
1627 | FLAGS_TOPOLOGY_MODE_LOOP; | |
1628 | ||
1629 | pmboxq->u.mb.mbxCommand = MBX_INIT_LINK; | |
1630 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
1631 | ||
1632 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | |
1633 | LPFC_MBOX_TMO); | |
1634 | ||
1635 | if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) | |
1636 | rc = -ENODEV; | |
1637 | else { | |
1638 | phba->link_flag |= LS_LOOPBACK_MODE; | |
1639 | /* wait for the link attention interrupt */ | |
1640 | msleep(100); | |
1641 | ||
1642 | i = 0; | |
1643 | while (phba->link_state != LPFC_HBA_READY) { | |
1644 | if (i++ > timeout) { | |
1645 | rc = -ETIMEDOUT; | |
1646 | break; | |
1647 | } | |
1648 | ||
1649 | msleep(10); | |
1650 | } | |
1651 | } | |
1652 | ||
1653 | } else | |
1654 | rc = -ENODEV; | |
1655 | ||
1656 | loopback_mode_exit: | |
7ad20aa9 | 1657 | lpfc_bsg_diag_mode_exit(phba); |
3b5dd52a JS |
1658 | |
1659 | /* | |
1660 | * Let SLI layer release mboxq if mbox command completed after timeout. | |
1661 | */ | |
1662 | if (mbxstatus != MBX_TIMEOUT) | |
1663 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1664 | ||
1665 | job_error: | |
1666 | /* make error code available to userspace */ | |
1667 | job->reply->result = rc; | |
1668 | /* complete the job back to userspace if no error */ | |
1669 | if (rc == 0) | |
1670 | job->job_done(job); | |
1671 | return rc; | |
1672 | } | |
1673 | ||
1674 | /** | |
7ad20aa9 JS |
1675 | * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state |
1676 | * @phba: Pointer to HBA context object. | |
1677 | * @diag: Flag for set link to diag or nomral operation state. | |
3b5dd52a | 1678 | * |
7ad20aa9 JS |
1679 | * This function is responsible for issuing a sli4 mailbox command for setting |
1680 | * link to either diag state or normal operation state. | |
1681 | */ | |
1682 | static int | |
1683 | lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba *phba, uint32_t diag) | |
3b5dd52a | 1684 | { |
7ad20aa9 JS |
1685 | LPFC_MBOXQ_t *pmboxq; |
1686 | struct lpfc_mbx_set_link_diag_state *link_diag_state; | |
1687 | uint32_t req_len, alloc_len; | |
1688 | int mbxstatus = MBX_SUCCESS, rc; | |
3b5dd52a | 1689 | |
7ad20aa9 JS |
1690 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1691 | if (!pmboxq) | |
d439d286 | 1692 | return -ENOMEM; |
3b5dd52a | 1693 | |
7ad20aa9 JS |
1694 | req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) - |
1695 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
1696 | alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
1697 | LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE, | |
1698 | req_len, LPFC_SLI4_MBX_EMBED); | |
1699 | if (alloc_len != req_len) { | |
1700 | rc = -ENOMEM; | |
1701 | goto link_diag_state_set_out; | |
3b5dd52a | 1702 | } |
7ad20aa9 JS |
1703 | link_diag_state = &pmboxq->u.mqe.un.link_diag_state; |
1704 | bf_set(lpfc_mbx_set_diag_state_link_num, &link_diag_state->u.req, | |
1705 | phba->sli4_hba.link_state.number); | |
1706 | bf_set(lpfc_mbx_set_diag_state_link_type, &link_diag_state->u.req, | |
1707 | phba->sli4_hba.link_state.type); | |
1708 | if (diag) | |
1709 | bf_set(lpfc_mbx_set_diag_state_diag, | |
1710 | &link_diag_state->u.req, 1); | |
1711 | else | |
1712 | bf_set(lpfc_mbx_set_diag_state_diag, | |
1713 | &link_diag_state->u.req, 0); | |
3b5dd52a | 1714 | |
7ad20aa9 | 1715 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); |
3b5dd52a | 1716 | |
7ad20aa9 JS |
1717 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) |
1718 | rc = 0; | |
1719 | else | |
1720 | rc = -ENODEV; | |
3b5dd52a | 1721 | |
7ad20aa9 JS |
1722 | link_diag_state_set_out: |
1723 | if (pmboxq && (mbxstatus != MBX_TIMEOUT)) | |
1724 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
3b5dd52a | 1725 | |
7ad20aa9 | 1726 | return rc; |
3b5dd52a JS |
1727 | } |
1728 | ||
1729 | /** | |
7ad20aa9 JS |
1730 | * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command |
1731 | * @phba: Pointer to HBA context object. | |
1732 | * @job: LPFC_BSG_VENDOR_DIAG_MODE | |
3b5dd52a | 1733 | * |
7ad20aa9 JS |
1734 | * This function is responsible for placing an sli4 port into diagnostic |
1735 | * loopback mode in order to perform a diagnostic loopback test. | |
1736 | */ | |
1737 | static int | |
1738 | lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job) | |
3b5dd52a | 1739 | { |
7ad20aa9 JS |
1740 | struct diag_mode_set *loopback_mode; |
1741 | uint32_t link_flags, timeout, req_len, alloc_len; | |
1742 | struct lpfc_mbx_set_link_diag_loopback *link_diag_loopback; | |
1743 | LPFC_MBOXQ_t *pmboxq = NULL; | |
b76f2dc9 | 1744 | int mbxstatus = MBX_SUCCESS, i, rc = 0; |
3b5dd52a | 1745 | |
7ad20aa9 JS |
1746 | /* no data to return just the return code */ |
1747 | job->reply->reply_payload_rcv_len = 0; | |
3b5dd52a | 1748 | |
7ad20aa9 JS |
1749 | if (job->request_len < sizeof(struct fc_bsg_request) + |
1750 | sizeof(struct diag_mode_set)) { | |
1751 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1752 | "3011 Received DIAG MODE request size:%d " | |
1753 | "below the minimum size:%d\n", | |
1754 | job->request_len, | |
1755 | (int)(sizeof(struct fc_bsg_request) + | |
1756 | sizeof(struct diag_mode_set))); | |
1757 | rc = -EINVAL; | |
1758 | goto job_error; | |
1759 | } | |
3b5dd52a | 1760 | |
88a2cfbb | 1761 | rc = lpfc_bsg_diag_mode_enter(phba); |
7ad20aa9 JS |
1762 | if (rc) |
1763 | goto job_error; | |
1764 | ||
1765 | /* bring the link to diagnostic mode */ | |
1766 | loopback_mode = (struct diag_mode_set *) | |
1767 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1768 | link_flags = loopback_mode->type; | |
1769 | timeout = loopback_mode->timeout * 100; | |
1770 | ||
1771 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1); | |
1772 | if (rc) | |
1773 | goto loopback_mode_exit; | |
1774 | ||
1775 | /* wait for link down before proceeding */ | |
1776 | i = 0; | |
1777 | while (phba->link_state != LPFC_LINK_DOWN) { | |
1778 | if (i++ > timeout) { | |
1779 | rc = -ETIMEDOUT; | |
1780 | goto loopback_mode_exit; | |
1781 | } | |
1782 | msleep(10); | |
3b5dd52a | 1783 | } |
7ad20aa9 JS |
1784 | /* set up loopback mode */ |
1785 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1786 | if (!pmboxq) { | |
1787 | rc = -ENOMEM; | |
1788 | goto loopback_mode_exit; | |
1789 | } | |
1790 | req_len = (sizeof(struct lpfc_mbx_set_link_diag_loopback) - | |
1791 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
1792 | alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
1793 | LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK, | |
1794 | req_len, LPFC_SLI4_MBX_EMBED); | |
1795 | if (alloc_len != req_len) { | |
1796 | rc = -ENOMEM; | |
1797 | goto loopback_mode_exit; | |
1798 | } | |
1799 | link_diag_loopback = &pmboxq->u.mqe.un.link_diag_loopback; | |
1800 | bf_set(lpfc_mbx_set_diag_state_link_num, | |
1801 | &link_diag_loopback->u.req, phba->sli4_hba.link_state.number); | |
1802 | bf_set(lpfc_mbx_set_diag_state_link_type, | |
1803 | &link_diag_loopback->u.req, phba->sli4_hba.link_state.type); | |
1804 | if (link_flags == INTERNAL_LOOP_BACK) | |
1805 | bf_set(lpfc_mbx_set_diag_lpbk_type, | |
1806 | &link_diag_loopback->u.req, | |
1807 | LPFC_DIAG_LOOPBACK_TYPE_INTERNAL); | |
1808 | else | |
1809 | bf_set(lpfc_mbx_set_diag_lpbk_type, | |
1810 | &link_diag_loopback->u.req, | |
1811 | LPFC_DIAG_LOOPBACK_TYPE_EXTERNAL); | |
1812 | ||
1813 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); | |
1814 | if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) | |
1815 | rc = -ENODEV; | |
1816 | else { | |
1817 | phba->link_flag |= LS_LOOPBACK_MODE; | |
1818 | /* wait for the link attention interrupt */ | |
1819 | msleep(100); | |
1820 | i = 0; | |
1821 | while (phba->link_state != LPFC_HBA_READY) { | |
1822 | if (i++ > timeout) { | |
1823 | rc = -ETIMEDOUT; | |
1824 | break; | |
1825 | } | |
1826 | msleep(10); | |
1827 | } | |
1828 | } | |
1829 | ||
1830 | loopback_mode_exit: | |
1831 | lpfc_bsg_diag_mode_exit(phba); | |
1832 | ||
1833 | /* | |
1834 | * Let SLI layer release mboxq if mbox command completed after timeout. | |
1835 | */ | |
1836 | if (pmboxq && (mbxstatus != MBX_TIMEOUT)) | |
1837 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1838 | ||
1839 | job_error: | |
1840 | /* make error code available to userspace */ | |
1841 | job->reply->result = rc; | |
1842 | /* complete the job back to userspace if no error */ | |
1843 | if (rc == 0) | |
1844 | job->job_done(job); | |
1845 | return rc; | |
3b5dd52a JS |
1846 | } |
1847 | ||
1848 | /** | |
7ad20aa9 JS |
1849 | * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode |
1850 | * @job: LPFC_BSG_VENDOR_DIAG_MODE | |
3b5dd52a | 1851 | * |
7ad20aa9 JS |
1852 | * This function is responsible for responding to check and dispatch bsg diag |
1853 | * command from the user to proper driver action routines. | |
1854 | */ | |
1855 | static int | |
1856 | lpfc_bsg_diag_loopback_mode(struct fc_bsg_job *job) | |
1857 | { | |
1858 | struct Scsi_Host *shost; | |
1859 | struct lpfc_vport *vport; | |
1860 | struct lpfc_hba *phba; | |
1861 | int rc; | |
1862 | ||
1863 | shost = job->shost; | |
1864 | if (!shost) | |
1865 | return -ENODEV; | |
1866 | vport = (struct lpfc_vport *)job->shost->hostdata; | |
1867 | if (!vport) | |
1868 | return -ENODEV; | |
1869 | phba = vport->phba; | |
1870 | if (!phba) | |
1871 | return -ENODEV; | |
1872 | ||
1873 | if (phba->sli_rev < LPFC_SLI_REV4) | |
1874 | rc = lpfc_sli3_bsg_diag_loopback_mode(phba, job); | |
1875 | else if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
1876 | LPFC_SLI_INTF_IF_TYPE_2) | |
1877 | rc = lpfc_sli4_bsg_diag_loopback_mode(phba, job); | |
1878 | else | |
1879 | rc = -ENODEV; | |
1880 | ||
1881 | return rc; | |
1882 | ||
1883 | } | |
1884 | ||
1885 | /** | |
1886 | * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode | |
1887 | * @job: LPFC_BSG_VENDOR_DIAG_MODE_END | |
1888 | * | |
1889 | * This function is responsible for responding to check and dispatch bsg diag | |
1890 | * command from the user to proper driver action routines. | |
1891 | */ | |
1892 | static int | |
1893 | lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job *job) | |
1894 | { | |
1895 | struct Scsi_Host *shost; | |
1896 | struct lpfc_vport *vport; | |
1897 | struct lpfc_hba *phba; | |
1898 | int rc; | |
1899 | ||
1900 | shost = job->shost; | |
1901 | if (!shost) | |
1902 | return -ENODEV; | |
1903 | vport = (struct lpfc_vport *)job->shost->hostdata; | |
1904 | if (!vport) | |
1905 | return -ENODEV; | |
1906 | phba = vport->phba; | |
1907 | if (!phba) | |
1908 | return -ENODEV; | |
1909 | ||
1910 | if (phba->sli_rev < LPFC_SLI_REV4) | |
1911 | return -ENODEV; | |
1912 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
1913 | LPFC_SLI_INTF_IF_TYPE_2) | |
1914 | return -ENODEV; | |
1915 | ||
1916 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0); | |
1917 | ||
1918 | if (!rc) | |
1919 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
1920 | ||
1921 | return rc; | |
1922 | } | |
1923 | ||
1924 | /** | |
1925 | * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test | |
1926 | * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST | |
1927 | * | |
1928 | * This function is to perform SLI4 diag link test request from the user | |
1929 | * applicaiton. | |
1930 | */ | |
1931 | static int | |
1932 | lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job *job) | |
1933 | { | |
1934 | struct Scsi_Host *shost; | |
1935 | struct lpfc_vport *vport; | |
1936 | struct lpfc_hba *phba; | |
1937 | LPFC_MBOXQ_t *pmboxq; | |
1938 | struct sli4_link_diag *link_diag_test_cmd; | |
1939 | uint32_t req_len, alloc_len; | |
1940 | uint32_t timeout; | |
1941 | struct lpfc_mbx_run_link_diag_test *run_link_diag_test; | |
1942 | union lpfc_sli4_cfg_shdr *shdr; | |
1943 | uint32_t shdr_status, shdr_add_status; | |
1944 | struct diag_status *diag_status_reply; | |
1945 | int mbxstatus, rc = 0; | |
1946 | ||
1947 | shost = job->shost; | |
1948 | if (!shost) { | |
1949 | rc = -ENODEV; | |
1950 | goto job_error; | |
1951 | } | |
1952 | vport = (struct lpfc_vport *)job->shost->hostdata; | |
1953 | if (!vport) { | |
1954 | rc = -ENODEV; | |
1955 | goto job_error; | |
1956 | } | |
1957 | phba = vport->phba; | |
1958 | if (!phba) { | |
1959 | rc = -ENODEV; | |
1960 | goto job_error; | |
1961 | } | |
1962 | ||
1963 | if (phba->sli_rev < LPFC_SLI_REV4) { | |
1964 | rc = -ENODEV; | |
1965 | goto job_error; | |
1966 | } | |
1967 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
1968 | LPFC_SLI_INTF_IF_TYPE_2) { | |
1969 | rc = -ENODEV; | |
1970 | goto job_error; | |
1971 | } | |
1972 | ||
1973 | if (job->request_len < sizeof(struct fc_bsg_request) + | |
1974 | sizeof(struct sli4_link_diag)) { | |
1975 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1976 | "3013 Received LINK DIAG TEST request " | |
1977 | " size:%d below the minimum size:%d\n", | |
1978 | job->request_len, | |
1979 | (int)(sizeof(struct fc_bsg_request) + | |
1980 | sizeof(struct sli4_link_diag))); | |
1981 | rc = -EINVAL; | |
1982 | goto job_error; | |
1983 | } | |
1984 | ||
88a2cfbb | 1985 | rc = lpfc_bsg_diag_mode_enter(phba); |
7ad20aa9 JS |
1986 | if (rc) |
1987 | goto job_error; | |
1988 | ||
1989 | link_diag_test_cmd = (struct sli4_link_diag *) | |
1990 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1991 | timeout = link_diag_test_cmd->timeout * 100; | |
1992 | ||
1993 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1); | |
1994 | ||
1995 | if (rc) | |
1996 | goto job_error; | |
1997 | ||
1998 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1999 | if (!pmboxq) { | |
2000 | rc = -ENOMEM; | |
2001 | goto link_diag_test_exit; | |
2002 | } | |
2003 | ||
2004 | req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) - | |
2005 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
2006 | alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
2007 | LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE, | |
2008 | req_len, LPFC_SLI4_MBX_EMBED); | |
2009 | if (alloc_len != req_len) { | |
2010 | rc = -ENOMEM; | |
2011 | goto link_diag_test_exit; | |
2012 | } | |
2013 | run_link_diag_test = &pmboxq->u.mqe.un.link_diag_test; | |
2014 | bf_set(lpfc_mbx_run_diag_test_link_num, &run_link_diag_test->u.req, | |
2015 | phba->sli4_hba.link_state.number); | |
2016 | bf_set(lpfc_mbx_run_diag_test_link_type, &run_link_diag_test->u.req, | |
2017 | phba->sli4_hba.link_state.type); | |
2018 | bf_set(lpfc_mbx_run_diag_test_test_id, &run_link_diag_test->u.req, | |
2019 | link_diag_test_cmd->test_id); | |
2020 | bf_set(lpfc_mbx_run_diag_test_loops, &run_link_diag_test->u.req, | |
2021 | link_diag_test_cmd->loops); | |
2022 | bf_set(lpfc_mbx_run_diag_test_test_ver, &run_link_diag_test->u.req, | |
2023 | link_diag_test_cmd->test_version); | |
2024 | bf_set(lpfc_mbx_run_diag_test_err_act, &run_link_diag_test->u.req, | |
2025 | link_diag_test_cmd->error_action); | |
2026 | ||
2027 | mbxstatus = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | |
2028 | ||
2029 | shdr = (union lpfc_sli4_cfg_shdr *) | |
2030 | &pmboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
2031 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
2032 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
2033 | if (shdr_status || shdr_add_status || mbxstatus) { | |
2034 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
2035 | "3010 Run link diag test mailbox failed with " | |
2036 | "mbx_status x%x status x%x, add_status x%x\n", | |
2037 | mbxstatus, shdr_status, shdr_add_status); | |
2038 | } | |
2039 | ||
2040 | diag_status_reply = (struct diag_status *) | |
2041 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
2042 | ||
2043 | if (job->reply_len < | |
2044 | sizeof(struct fc_bsg_request) + sizeof(struct diag_status)) { | |
2045 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2046 | "3012 Received Run link diag test reply " | |
2047 | "below minimum size (%d): reply_len:%d\n", | |
2048 | (int)(sizeof(struct fc_bsg_request) + | |
2049 | sizeof(struct diag_status)), | |
2050 | job->reply_len); | |
2051 | rc = -EINVAL; | |
2052 | goto job_error; | |
2053 | } | |
2054 | ||
2055 | diag_status_reply->mbox_status = mbxstatus; | |
2056 | diag_status_reply->shdr_status = shdr_status; | |
2057 | diag_status_reply->shdr_add_status = shdr_add_status; | |
2058 | ||
2059 | link_diag_test_exit: | |
2060 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0); | |
2061 | ||
2062 | if (pmboxq) | |
2063 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
2064 | ||
2065 | lpfc_bsg_diag_mode_exit(phba); | |
2066 | ||
2067 | job_error: | |
2068 | /* make error code available to userspace */ | |
2069 | job->reply->result = rc; | |
2070 | /* complete the job back to userspace if no error */ | |
2071 | if (rc == 0) | |
2072 | job->job_done(job); | |
2073 | return rc; | |
2074 | } | |
2075 | ||
2076 | /** | |
2077 | * lpfcdiag_loop_self_reg - obtains a remote port login id | |
2078 | * @phba: Pointer to HBA context object | |
2079 | * @rpi: Pointer to a remote port login id | |
2080 | * | |
2081 | * This function obtains a remote port login id so the diag loopback test | |
2082 | * can send and receive its own unsolicited CT command. | |
2083 | **/ | |
2084 | static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t *rpi) | |
2085 | { | |
2086 | LPFC_MBOXQ_t *mbox; | |
2087 | struct lpfc_dmabuf *dmabuff; | |
2088 | int status; | |
2089 | ||
2090 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2091 | if (!mbox) | |
2092 | return -ENOMEM; | |
2093 | ||
2094 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2095 | *rpi = lpfc_sli4_alloc_rpi(phba); | |
2096 | status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID, | |
2097 | (uint8_t *)&phba->pport->fc_sparam, mbox, *rpi); | |
2098 | if (status) { | |
2099 | mempool_free(mbox, phba->mbox_mem_pool); | |
2100 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2101 | lpfc_sli4_free_rpi(phba, *rpi); | |
2102 | return -ENOMEM; | |
2103 | } | |
2104 | ||
2105 | dmabuff = (struct lpfc_dmabuf *) mbox->context1; | |
2106 | mbox->context1 = NULL; | |
2107 | mbox->context2 = NULL; | |
2108 | status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
2109 | ||
2110 | if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { | |
2111 | lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys); | |
2112 | kfree(dmabuff); | |
2113 | if (status != MBX_TIMEOUT) | |
2114 | mempool_free(mbox, phba->mbox_mem_pool); | |
2115 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2116 | lpfc_sli4_free_rpi(phba, *rpi); | |
2117 | return -ENODEV; | |
2118 | } | |
2119 | ||
2120 | *rpi = mbox->u.mb.un.varWords[0]; | |
2121 | ||
2122 | lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys); | |
2123 | kfree(dmabuff); | |
2124 | mempool_free(mbox, phba->mbox_mem_pool); | |
2125 | return 0; | |
2126 | } | |
2127 | ||
2128 | /** | |
2129 | * lpfcdiag_loop_self_unreg - unregs from the rpi | |
2130 | * @phba: Pointer to HBA context object | |
2131 | * @rpi: Remote port login id | |
2132 | * | |
2133 | * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg | |
2134 | **/ | |
2135 | static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi) | |
2136 | { | |
2137 | LPFC_MBOXQ_t *mbox; | |
2138 | int status; | |
2139 | ||
2140 | /* Allocate mboxq structure */ | |
2141 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2142 | if (mbox == NULL) | |
2143 | return -ENOMEM; | |
2144 | ||
2145 | lpfc_unreg_login(phba, 0, rpi, mbox); | |
2146 | status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
2147 | ||
2148 | if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { | |
2149 | if (status != MBX_TIMEOUT) | |
2150 | mempool_free(mbox, phba->mbox_mem_pool); | |
2151 | return -EIO; | |
2152 | } | |
2153 | mempool_free(mbox, phba->mbox_mem_pool); | |
2154 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2155 | lpfc_sli4_free_rpi(phba, rpi); | |
2156 | return 0; | |
2157 | } | |
2158 | ||
2159 | /** | |
2160 | * lpfcdiag_loop_get_xri - obtains the transmit and receive ids | |
2161 | * @phba: Pointer to HBA context object | |
2162 | * @rpi: Remote port login id | |
2163 | * @txxri: Pointer to transmit exchange id | |
2164 | * @rxxri: Pointer to response exchabge id | |
2165 | * | |
2166 | * This function obtains the transmit and receive ids required to send | |
2167 | * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp | |
2168 | * flags are used to the unsolicted response handler is able to process | |
2169 | * the ct command sent on the same port. | |
2170 | **/ | |
2171 | static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi, | |
2172 | uint16_t *txxri, uint16_t * rxxri) | |
3b5dd52a JS |
2173 | { |
2174 | struct lpfc_bsg_event *evt; | |
2175 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; | |
2176 | IOCB_t *cmd, *rsp; | |
2177 | struct lpfc_dmabuf *dmabuf; | |
2178 | struct ulp_bde64 *bpl = NULL; | |
2179 | struct lpfc_sli_ct_request *ctreq = NULL; | |
2180 | int ret_val = 0; | |
d439d286 | 2181 | int time_left; |
515e0aa2 | 2182 | int iocb_stat = 0; |
3b5dd52a JS |
2183 | unsigned long flags; |
2184 | ||
2185 | *txxri = 0; | |
2186 | *rxxri = 0; | |
2187 | evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, | |
2188 | SLI_CT_ELX_LOOPBACK); | |
2189 | if (!evt) | |
d439d286 | 2190 | return -ENOMEM; |
3b5dd52a JS |
2191 | |
2192 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2193 | list_add(&evt->node, &phba->ct_ev_waiters); | |
2194 | lpfc_bsg_event_ref(evt); | |
2195 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2196 | ||
2197 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
2198 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
2199 | ||
2200 | dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2201 | if (dmabuf) { | |
2202 | dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys); | |
c7495937 JS |
2203 | if (dmabuf->virt) { |
2204 | INIT_LIST_HEAD(&dmabuf->list); | |
2205 | bpl = (struct ulp_bde64 *) dmabuf->virt; | |
2206 | memset(bpl, 0, sizeof(*bpl)); | |
2207 | ctreq = (struct lpfc_sli_ct_request *)(bpl + 1); | |
2208 | bpl->addrHigh = | |
2209 | le32_to_cpu(putPaddrHigh(dmabuf->phys + | |
2210 | sizeof(*bpl))); | |
2211 | bpl->addrLow = | |
2212 | le32_to_cpu(putPaddrLow(dmabuf->phys + | |
2213 | sizeof(*bpl))); | |
2214 | bpl->tus.f.bdeFlags = 0; | |
2215 | bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ; | |
2216 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
2217 | } | |
3b5dd52a JS |
2218 | } |
2219 | ||
2220 | if (cmdiocbq == NULL || rspiocbq == NULL || | |
c7495937 JS |
2221 | dmabuf == NULL || bpl == NULL || ctreq == NULL || |
2222 | dmabuf->virt == NULL) { | |
d439d286 | 2223 | ret_val = -ENOMEM; |
3b5dd52a JS |
2224 | goto err_get_xri_exit; |
2225 | } | |
2226 | ||
2227 | cmd = &cmdiocbq->iocb; | |
2228 | rsp = &rspiocbq->iocb; | |
2229 | ||
2230 | memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ); | |
2231 | ||
2232 | ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
2233 | ctreq->RevisionId.bits.InId = 0; | |
2234 | ctreq->FsType = SLI_CT_ELX_LOOPBACK; | |
2235 | ctreq->FsSubType = 0; | |
2236 | ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP; | |
2237 | ctreq->CommandResponse.bits.Size = 0; | |
2238 | ||
2239 | ||
2240 | cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(dmabuf->phys); | |
2241 | cmd->un.xseq64.bdl.addrLow = putPaddrLow(dmabuf->phys); | |
2242 | cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
2243 | cmd->un.xseq64.bdl.bdeSize = sizeof(*bpl); | |
2244 | ||
2245 | cmd->un.xseq64.w5.hcsw.Fctl = LA; | |
2246 | cmd->un.xseq64.w5.hcsw.Dfctl = 0; | |
2247 | cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; | |
2248 | cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; | |
2249 | ||
2250 | cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR; | |
2251 | cmd->ulpBdeCount = 1; | |
2252 | cmd->ulpLe = 1; | |
2253 | cmd->ulpClass = CLASS3; | |
2254 | cmd->ulpContext = rpi; | |
2255 | ||
2256 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
2257 | cmdiocbq->vport = phba->pport; | |
2258 | ||
d439d286 | 2259 | iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, |
3b5dd52a JS |
2260 | rspiocbq, |
2261 | (phba->fc_ratov * 2) | |
2262 | + LPFC_DRVR_TIMEOUT); | |
d439d286 JS |
2263 | if (iocb_stat) { |
2264 | ret_val = -EIO; | |
3b5dd52a | 2265 | goto err_get_xri_exit; |
d439d286 | 2266 | } |
3b5dd52a JS |
2267 | *txxri = rsp->ulpContext; |
2268 | ||
2269 | evt->waiting = 1; | |
2270 | evt->wait_time_stamp = jiffies; | |
d439d286 | 2271 | time_left = wait_event_interruptible_timeout( |
3b5dd52a JS |
2272 | evt->wq, !list_empty(&evt->events_to_see), |
2273 | ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ); | |
2274 | if (list_empty(&evt->events_to_see)) | |
d439d286 | 2275 | ret_val = (time_left) ? -EINTR : -ETIMEDOUT; |
3b5dd52a | 2276 | else { |
3b5dd52a JS |
2277 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
2278 | list_move(evt->events_to_see.prev, &evt->events_to_get); | |
2279 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2280 | *rxxri = (list_entry(evt->events_to_get.prev, | |
2281 | typeof(struct event_data), | |
2282 | node))->immed_dat; | |
2283 | } | |
2284 | evt->waiting = 0; | |
2285 | ||
2286 | err_get_xri_exit: | |
2287 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2288 | lpfc_bsg_event_unref(evt); /* release ref */ | |
2289 | lpfc_bsg_event_unref(evt); /* delete */ | |
2290 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2291 | ||
2292 | if (dmabuf) { | |
2293 | if (dmabuf->virt) | |
2294 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); | |
2295 | kfree(dmabuf); | |
2296 | } | |
2297 | ||
d439d286 | 2298 | if (cmdiocbq && (iocb_stat != IOCB_TIMEDOUT)) |
3b5dd52a JS |
2299 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
2300 | if (rspiocbq) | |
2301 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
2302 | return ret_val; | |
2303 | } | |
2304 | ||
7ad20aa9 JS |
2305 | /** |
2306 | * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers | |
2307 | * @phba: Pointer to HBA context object | |
2308 | * | |
2309 | * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and. | |
2310 | * retruns the pointer to the buffer. | |
2311 | **/ | |
2312 | static struct lpfc_dmabuf * | |
2313 | lpfc_bsg_dma_page_alloc(struct lpfc_hba *phba) | |
2314 | { | |
2315 | struct lpfc_dmabuf *dmabuf; | |
2316 | struct pci_dev *pcidev = phba->pcidev; | |
2317 | ||
2318 | /* allocate dma buffer struct */ | |
2319 | dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2320 | if (!dmabuf) | |
2321 | return NULL; | |
2322 | ||
2323 | INIT_LIST_HEAD(&dmabuf->list); | |
2324 | ||
2325 | /* now, allocate dma buffer */ | |
2326 | dmabuf->virt = dma_alloc_coherent(&pcidev->dev, BSG_MBOX_SIZE, | |
2327 | &(dmabuf->phys), GFP_KERNEL); | |
2328 | ||
2329 | if (!dmabuf->virt) { | |
2330 | kfree(dmabuf); | |
2331 | return NULL; | |
2332 | } | |
2333 | memset((uint8_t *)dmabuf->virt, 0, BSG_MBOX_SIZE); | |
2334 | ||
2335 | return dmabuf; | |
2336 | } | |
2337 | ||
2338 | /** | |
2339 | * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer | |
2340 | * @phba: Pointer to HBA context object. | |
2341 | * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor. | |
2342 | * | |
2343 | * This routine just simply frees a dma buffer and its associated buffer | |
2344 | * descriptor referred by @dmabuf. | |
2345 | **/ | |
2346 | static void | |
2347 | lpfc_bsg_dma_page_free(struct lpfc_hba *phba, struct lpfc_dmabuf *dmabuf) | |
2348 | { | |
2349 | struct pci_dev *pcidev = phba->pcidev; | |
2350 | ||
2351 | if (!dmabuf) | |
2352 | return; | |
2353 | ||
2354 | if (dmabuf->virt) | |
2355 | dma_free_coherent(&pcidev->dev, BSG_MBOX_SIZE, | |
2356 | dmabuf->virt, dmabuf->phys); | |
2357 | kfree(dmabuf); | |
2358 | return; | |
2359 | } | |
2360 | ||
2361 | /** | |
2362 | * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers | |
2363 | * @phba: Pointer to HBA context object. | |
2364 | * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs. | |
2365 | * | |
2366 | * This routine just simply frees all dma buffers and their associated buffer | |
2367 | * descriptors referred by @dmabuf_list. | |
2368 | **/ | |
2369 | static void | |
2370 | lpfc_bsg_dma_page_list_free(struct lpfc_hba *phba, | |
2371 | struct list_head *dmabuf_list) | |
2372 | { | |
2373 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; | |
2374 | ||
2375 | if (list_empty(dmabuf_list)) | |
2376 | return; | |
2377 | ||
2378 | list_for_each_entry_safe(dmabuf, next_dmabuf, dmabuf_list, list) { | |
2379 | list_del_init(&dmabuf->list); | |
2380 | lpfc_bsg_dma_page_free(phba, dmabuf); | |
2381 | } | |
2382 | return; | |
2383 | } | |
2384 | ||
3b5dd52a JS |
2385 | /** |
2386 | * diag_cmd_data_alloc - fills in a bde struct with dma buffers | |
2387 | * @phba: Pointer to HBA context object | |
2388 | * @bpl: Pointer to 64 bit bde structure | |
2389 | * @size: Number of bytes to process | |
2390 | * @nocopydata: Flag to copy user data into the allocated buffer | |
2391 | * | |
2392 | * This function allocates page size buffers and populates an lpfc_dmabufext. | |
2393 | * If allowed the user data pointed to with indataptr is copied into the kernel | |
2394 | * memory. The chained list of page size buffers is returned. | |
2395 | **/ | |
2396 | static struct lpfc_dmabufext * | |
2397 | diag_cmd_data_alloc(struct lpfc_hba *phba, | |
2398 | struct ulp_bde64 *bpl, uint32_t size, | |
2399 | int nocopydata) | |
2400 | { | |
2401 | struct lpfc_dmabufext *mlist = NULL; | |
2402 | struct lpfc_dmabufext *dmp; | |
2403 | int cnt, offset = 0, i = 0; | |
2404 | struct pci_dev *pcidev; | |
2405 | ||
2406 | pcidev = phba->pcidev; | |
2407 | ||
2408 | while (size) { | |
2409 | /* We get chunks of 4K */ | |
2410 | if (size > BUF_SZ_4K) | |
2411 | cnt = BUF_SZ_4K; | |
2412 | else | |
2413 | cnt = size; | |
2414 | ||
2415 | /* allocate struct lpfc_dmabufext buffer header */ | |
2416 | dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL); | |
2417 | if (!dmp) | |
2418 | goto out; | |
2419 | ||
2420 | INIT_LIST_HEAD(&dmp->dma.list); | |
2421 | ||
2422 | /* Queue it to a linked list */ | |
2423 | if (mlist) | |
2424 | list_add_tail(&dmp->dma.list, &mlist->dma.list); | |
2425 | else | |
2426 | mlist = dmp; | |
2427 | ||
2428 | /* allocate buffer */ | |
2429 | dmp->dma.virt = dma_alloc_coherent(&pcidev->dev, | |
2430 | cnt, | |
2431 | &(dmp->dma.phys), | |
2432 | GFP_KERNEL); | |
2433 | ||
2434 | if (!dmp->dma.virt) | |
2435 | goto out; | |
2436 | ||
2437 | dmp->size = cnt; | |
2438 | ||
2439 | if (nocopydata) { | |
2440 | bpl->tus.f.bdeFlags = 0; | |
2441 | pci_dma_sync_single_for_device(phba->pcidev, | |
2442 | dmp->dma.phys, LPFC_BPL_SIZE, PCI_DMA_TODEVICE); | |
2443 | ||
2444 | } else { | |
2445 | memset((uint8_t *)dmp->dma.virt, 0, cnt); | |
2446 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
2447 | } | |
2448 | ||
2449 | /* build buffer ptr list for IOCB */ | |
2450 | bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys)); | |
2451 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys)); | |
2452 | bpl->tus.f.bdeSize = (ushort) cnt; | |
2453 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
2454 | bpl++; | |
2455 | ||
2456 | i++; | |
2457 | offset += cnt; | |
2458 | size -= cnt; | |
2459 | } | |
2460 | ||
2461 | mlist->flag = i; | |
2462 | return mlist; | |
2463 | out: | |
2464 | diag_cmd_data_free(phba, mlist); | |
2465 | return NULL; | |
2466 | } | |
2467 | ||
2468 | /** | |
2469 | * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd | |
2470 | * @phba: Pointer to HBA context object | |
2471 | * @rxxri: Receive exchange id | |
2472 | * @len: Number of data bytes | |
2473 | * | |
25985edc | 2474 | * This function allocates and posts a data buffer of sufficient size to receive |
3b5dd52a JS |
2475 | * an unsolicted CT command. |
2476 | **/ | |
2477 | static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri, | |
2478 | size_t len) | |
2479 | { | |
2480 | struct lpfc_sli *psli = &phba->sli; | |
2481 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
2482 | struct lpfc_iocbq *cmdiocbq; | |
2483 | IOCB_t *cmd = NULL; | |
2484 | struct list_head head, *curr, *next; | |
2485 | struct lpfc_dmabuf *rxbmp; | |
2486 | struct lpfc_dmabuf *dmp; | |
2487 | struct lpfc_dmabuf *mp[2] = {NULL, NULL}; | |
2488 | struct ulp_bde64 *rxbpl = NULL; | |
2489 | uint32_t num_bde; | |
2490 | struct lpfc_dmabufext *rxbuffer = NULL; | |
2491 | int ret_val = 0; | |
d439d286 | 2492 | int iocb_stat; |
3b5dd52a JS |
2493 | int i = 0; |
2494 | ||
2495 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
2496 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2497 | if (rxbmp != NULL) { | |
2498 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); | |
c7495937 JS |
2499 | if (rxbmp->virt) { |
2500 | INIT_LIST_HEAD(&rxbmp->list); | |
2501 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; | |
2502 | rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0); | |
2503 | } | |
3b5dd52a JS |
2504 | } |
2505 | ||
2506 | if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) { | |
d439d286 | 2507 | ret_val = -ENOMEM; |
3b5dd52a JS |
2508 | goto err_post_rxbufs_exit; |
2509 | } | |
2510 | ||
2511 | /* Queue buffers for the receive exchange */ | |
2512 | num_bde = (uint32_t)rxbuffer->flag; | |
2513 | dmp = &rxbuffer->dma; | |
2514 | ||
2515 | cmd = &cmdiocbq->iocb; | |
2516 | i = 0; | |
2517 | ||
2518 | INIT_LIST_HEAD(&head); | |
2519 | list_add_tail(&head, &dmp->list); | |
2520 | list_for_each_safe(curr, next, &head) { | |
2521 | mp[i] = list_entry(curr, struct lpfc_dmabuf, list); | |
2522 | list_del(curr); | |
2523 | ||
2524 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { | |
2525 | mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba); | |
2526 | cmd->un.quexri64cx.buff.bde.addrHigh = | |
2527 | putPaddrHigh(mp[i]->phys); | |
2528 | cmd->un.quexri64cx.buff.bde.addrLow = | |
2529 | putPaddrLow(mp[i]->phys); | |
2530 | cmd->un.quexri64cx.buff.bde.tus.f.bdeSize = | |
2531 | ((struct lpfc_dmabufext *)mp[i])->size; | |
2532 | cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag; | |
2533 | cmd->ulpCommand = CMD_QUE_XRI64_CX; | |
2534 | cmd->ulpPU = 0; | |
2535 | cmd->ulpLe = 1; | |
2536 | cmd->ulpBdeCount = 1; | |
2537 | cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0; | |
2538 | ||
2539 | } else { | |
2540 | cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys); | |
2541 | cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys); | |
2542 | cmd->un.cont64[i].tus.f.bdeSize = | |
2543 | ((struct lpfc_dmabufext *)mp[i])->size; | |
2544 | cmd->ulpBdeCount = ++i; | |
2545 | ||
2546 | if ((--num_bde > 0) && (i < 2)) | |
2547 | continue; | |
2548 | ||
2549 | cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX; | |
2550 | cmd->ulpLe = 1; | |
2551 | } | |
2552 | ||
2553 | cmd->ulpClass = CLASS3; | |
2554 | cmd->ulpContext = rxxri; | |
2555 | ||
d439d286 JS |
2556 | iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, |
2557 | 0); | |
2558 | if (iocb_stat == IOCB_ERROR) { | |
3b5dd52a JS |
2559 | diag_cmd_data_free(phba, |
2560 | (struct lpfc_dmabufext *)mp[0]); | |
2561 | if (mp[1]) | |
2562 | diag_cmd_data_free(phba, | |
2563 | (struct lpfc_dmabufext *)mp[1]); | |
2564 | dmp = list_entry(next, struct lpfc_dmabuf, list); | |
d439d286 | 2565 | ret_val = -EIO; |
3b5dd52a JS |
2566 | goto err_post_rxbufs_exit; |
2567 | } | |
2568 | ||
2569 | lpfc_sli_ringpostbuf_put(phba, pring, mp[0]); | |
2570 | if (mp[1]) { | |
2571 | lpfc_sli_ringpostbuf_put(phba, pring, mp[1]); | |
2572 | mp[1] = NULL; | |
2573 | } | |
2574 | ||
2575 | /* The iocb was freed by lpfc_sli_issue_iocb */ | |
2576 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
2577 | if (!cmdiocbq) { | |
2578 | dmp = list_entry(next, struct lpfc_dmabuf, list); | |
d439d286 | 2579 | ret_val = -EIO; |
3b5dd52a JS |
2580 | goto err_post_rxbufs_exit; |
2581 | } | |
2582 | ||
2583 | cmd = &cmdiocbq->iocb; | |
2584 | i = 0; | |
2585 | } | |
2586 | list_del(&head); | |
2587 | ||
2588 | err_post_rxbufs_exit: | |
2589 | ||
2590 | if (rxbmp) { | |
2591 | if (rxbmp->virt) | |
2592 | lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys); | |
2593 | kfree(rxbmp); | |
2594 | } | |
2595 | ||
2596 | if (cmdiocbq) | |
2597 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
2598 | return ret_val; | |
2599 | } | |
2600 | ||
2601 | /** | |
7ad20aa9 | 2602 | * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself |
3b5dd52a JS |
2603 | * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job |
2604 | * | |
2605 | * This function receives a user data buffer to be transmitted and received on | |
2606 | * the same port, the link must be up and in loopback mode prior | |
2607 | * to being called. | |
2608 | * 1. A kernel buffer is allocated to copy the user data into. | |
2609 | * 2. The port registers with "itself". | |
2610 | * 3. The transmit and receive exchange ids are obtained. | |
2611 | * 4. The receive exchange id is posted. | |
2612 | * 5. A new els loopback event is created. | |
2613 | * 6. The command and response iocbs are allocated. | |
2614 | * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback. | |
2615 | * | |
2616 | * This function is meant to be called n times while the port is in loopback | |
2617 | * so it is the apps responsibility to issue a reset to take the port out | |
2618 | * of loopback mode. | |
2619 | **/ | |
2620 | static int | |
7ad20aa9 | 2621 | lpfc_bsg_diag_loopback_run(struct fc_bsg_job *job) |
3b5dd52a JS |
2622 | { |
2623 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
2624 | struct lpfc_hba *phba = vport->phba; | |
2625 | struct diag_mode_test *diag_mode; | |
2626 | struct lpfc_bsg_event *evt; | |
2627 | struct event_data *evdat; | |
2628 | struct lpfc_sli *psli = &phba->sli; | |
2629 | uint32_t size; | |
2630 | uint32_t full_size; | |
2631 | size_t segment_len = 0, segment_offset = 0, current_offset = 0; | |
4042629e | 2632 | uint16_t rpi = 0; |
3b5dd52a JS |
2633 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; |
2634 | IOCB_t *cmd, *rsp; | |
2635 | struct lpfc_sli_ct_request *ctreq; | |
2636 | struct lpfc_dmabuf *txbmp; | |
2637 | struct ulp_bde64 *txbpl = NULL; | |
2638 | struct lpfc_dmabufext *txbuffer = NULL; | |
2639 | struct list_head head; | |
2640 | struct lpfc_dmabuf *curr; | |
2641 | uint16_t txxri, rxxri; | |
2642 | uint32_t num_bde; | |
2643 | uint8_t *ptr = NULL, *rx_databuf = NULL; | |
2644 | int rc = 0; | |
d439d286 JS |
2645 | int time_left; |
2646 | int iocb_stat; | |
3b5dd52a JS |
2647 | unsigned long flags; |
2648 | void *dataout = NULL; | |
2649 | uint32_t total_mem; | |
2650 | ||
2651 | /* in case no data is returned return just the return code */ | |
2652 | job->reply->reply_payload_rcv_len = 0; | |
2653 | ||
2654 | if (job->request_len < | |
2655 | sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) { | |
2656 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2657 | "2739 Received DIAG TEST request below minimum " | |
2658 | "size\n"); | |
2659 | rc = -EINVAL; | |
2660 | goto loopback_test_exit; | |
2661 | } | |
2662 | ||
2663 | if (job->request_payload.payload_len != | |
2664 | job->reply_payload.payload_len) { | |
2665 | rc = -EINVAL; | |
2666 | goto loopback_test_exit; | |
2667 | } | |
2668 | ||
2669 | diag_mode = (struct diag_mode_test *) | |
2670 | job->request->rqst_data.h_vendor.vendor_cmd; | |
2671 | ||
2672 | if ((phba->link_state == LPFC_HBA_ERROR) || | |
2673 | (psli->sli_flag & LPFC_BLOCK_MGMT_IO) || | |
2674 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) { | |
2675 | rc = -EACCES; | |
2676 | goto loopback_test_exit; | |
2677 | } | |
2678 | ||
2679 | if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) { | |
2680 | rc = -EACCES; | |
2681 | goto loopback_test_exit; | |
2682 | } | |
2683 | ||
2684 | size = job->request_payload.payload_len; | |
2685 | full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */ | |
2686 | ||
2687 | if ((size == 0) || (size > 80 * BUF_SZ_4K)) { | |
2688 | rc = -ERANGE; | |
2689 | goto loopback_test_exit; | |
2690 | } | |
2691 | ||
63e801ce | 2692 | if (full_size >= BUF_SZ_4K) { |
3b5dd52a JS |
2693 | /* |
2694 | * Allocate memory for ioctl data. If buffer is bigger than 64k, | |
2695 | * then we allocate 64k and re-use that buffer over and over to | |
2696 | * xfer the whole block. This is because Linux kernel has a | |
2697 | * problem allocating more than 120k of kernel space memory. Saw | |
2698 | * problem with GET_FCPTARGETMAPPING... | |
2699 | */ | |
2700 | if (size <= (64 * 1024)) | |
63e801ce | 2701 | total_mem = full_size; |
3b5dd52a JS |
2702 | else |
2703 | total_mem = 64 * 1024; | |
2704 | } else | |
2705 | /* Allocate memory for ioctl data */ | |
2706 | total_mem = BUF_SZ_4K; | |
2707 | ||
2708 | dataout = kmalloc(total_mem, GFP_KERNEL); | |
2709 | if (dataout == NULL) { | |
2710 | rc = -ENOMEM; | |
2711 | goto loopback_test_exit; | |
2712 | } | |
2713 | ||
2714 | ptr = dataout; | |
2715 | ptr += ELX_LOOPBACK_HEADER_SZ; | |
2716 | sg_copy_to_buffer(job->request_payload.sg_list, | |
2717 | job->request_payload.sg_cnt, | |
2718 | ptr, size); | |
3b5dd52a | 2719 | rc = lpfcdiag_loop_self_reg(phba, &rpi); |
d439d286 | 2720 | if (rc) |
3b5dd52a | 2721 | goto loopback_test_exit; |
3b5dd52a JS |
2722 | |
2723 | rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri); | |
2724 | if (rc) { | |
2725 | lpfcdiag_loop_self_unreg(phba, rpi); | |
3b5dd52a JS |
2726 | goto loopback_test_exit; |
2727 | } | |
2728 | ||
2729 | rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size); | |
2730 | if (rc) { | |
2731 | lpfcdiag_loop_self_unreg(phba, rpi); | |
3b5dd52a JS |
2732 | goto loopback_test_exit; |
2733 | } | |
2734 | ||
2735 | evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, | |
2736 | SLI_CT_ELX_LOOPBACK); | |
2737 | if (!evt) { | |
2738 | lpfcdiag_loop_self_unreg(phba, rpi); | |
2739 | rc = -ENOMEM; | |
2740 | goto loopback_test_exit; | |
2741 | } | |
2742 | ||
2743 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2744 | list_add(&evt->node, &phba->ct_ev_waiters); | |
2745 | lpfc_bsg_event_ref(evt); | |
2746 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2747 | ||
2748 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
2749 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
2750 | txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2751 | ||
2752 | if (txbmp) { | |
2753 | txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys); | |
c7495937 JS |
2754 | if (txbmp->virt) { |
2755 | INIT_LIST_HEAD(&txbmp->list); | |
2756 | txbpl = (struct ulp_bde64 *) txbmp->virt; | |
3b5dd52a JS |
2757 | txbuffer = diag_cmd_data_alloc(phba, |
2758 | txbpl, full_size, 0); | |
c7495937 | 2759 | } |
3b5dd52a JS |
2760 | } |
2761 | ||
c7495937 JS |
2762 | if (!cmdiocbq || !rspiocbq || !txbmp || !txbpl || !txbuffer || |
2763 | !txbmp->virt) { | |
3b5dd52a JS |
2764 | rc = -ENOMEM; |
2765 | goto err_loopback_test_exit; | |
2766 | } | |
2767 | ||
2768 | cmd = &cmdiocbq->iocb; | |
2769 | rsp = &rspiocbq->iocb; | |
2770 | ||
2771 | INIT_LIST_HEAD(&head); | |
2772 | list_add_tail(&head, &txbuffer->dma.list); | |
2773 | list_for_each_entry(curr, &head, list) { | |
2774 | segment_len = ((struct lpfc_dmabufext *)curr)->size; | |
2775 | if (current_offset == 0) { | |
2776 | ctreq = curr->virt; | |
2777 | memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ); | |
2778 | ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
2779 | ctreq->RevisionId.bits.InId = 0; | |
2780 | ctreq->FsType = SLI_CT_ELX_LOOPBACK; | |
2781 | ctreq->FsSubType = 0; | |
2782 | ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_DATA; | |
2783 | ctreq->CommandResponse.bits.Size = size; | |
2784 | segment_offset = ELX_LOOPBACK_HEADER_SZ; | |
2785 | } else | |
2786 | segment_offset = 0; | |
2787 | ||
2788 | BUG_ON(segment_offset >= segment_len); | |
2789 | memcpy(curr->virt + segment_offset, | |
2790 | ptr + current_offset, | |
2791 | segment_len - segment_offset); | |
2792 | ||
2793 | current_offset += segment_len - segment_offset; | |
2794 | BUG_ON(current_offset > size); | |
2795 | } | |
2796 | list_del(&head); | |
2797 | ||
2798 | /* Build the XMIT_SEQUENCE iocb */ | |
2799 | ||
2800 | num_bde = (uint32_t)txbuffer->flag; | |
2801 | ||
2802 | cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(txbmp->phys); | |
2803 | cmd->un.xseq64.bdl.addrLow = putPaddrLow(txbmp->phys); | |
2804 | cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
2805 | cmd->un.xseq64.bdl.bdeSize = (num_bde * sizeof(struct ulp_bde64)); | |
2806 | ||
2807 | cmd->un.xseq64.w5.hcsw.Fctl = (LS | LA); | |
2808 | cmd->un.xseq64.w5.hcsw.Dfctl = 0; | |
2809 | cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; | |
2810 | cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; | |
2811 | ||
2812 | cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; | |
2813 | cmd->ulpBdeCount = 1; | |
2814 | cmd->ulpLe = 1; | |
2815 | cmd->ulpClass = CLASS3; | |
2816 | cmd->ulpContext = txxri; | |
2817 | ||
2818 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
2819 | cmdiocbq->vport = phba->pport; | |
2820 | ||
d439d286 JS |
2821 | iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, |
2822 | rspiocbq, (phba->fc_ratov * 2) + | |
2823 | LPFC_DRVR_TIMEOUT); | |
3b5dd52a | 2824 | |
d439d286 | 2825 | if ((iocb_stat != IOCB_SUCCESS) || (rsp->ulpStatus != IOCB_SUCCESS)) { |
3b5dd52a JS |
2826 | rc = -EIO; |
2827 | goto err_loopback_test_exit; | |
2828 | } | |
2829 | ||
2830 | evt->waiting = 1; | |
d439d286 | 2831 | time_left = wait_event_interruptible_timeout( |
3b5dd52a JS |
2832 | evt->wq, !list_empty(&evt->events_to_see), |
2833 | ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ); | |
2834 | evt->waiting = 0; | |
2835 | if (list_empty(&evt->events_to_see)) | |
d439d286 | 2836 | rc = (time_left) ? -EINTR : -ETIMEDOUT; |
3b5dd52a JS |
2837 | else { |
2838 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2839 | list_move(evt->events_to_see.prev, &evt->events_to_get); | |
2840 | evdat = list_entry(evt->events_to_get.prev, | |
2841 | typeof(*evdat), node); | |
2842 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2843 | rx_databuf = evdat->data; | |
2844 | if (evdat->len != full_size) { | |
2845 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
2846 | "1603 Loopback test did not receive expected " | |
2847 | "data length. actual length 0x%x expected " | |
2848 | "length 0x%x\n", | |
2849 | evdat->len, full_size); | |
2850 | rc = -EIO; | |
2851 | } else if (rx_databuf == NULL) | |
2852 | rc = -EIO; | |
2853 | else { | |
2854 | rc = IOCB_SUCCESS; | |
2855 | /* skip over elx loopback header */ | |
2856 | rx_databuf += ELX_LOOPBACK_HEADER_SZ; | |
2857 | job->reply->reply_payload_rcv_len = | |
2858 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
2859 | job->reply_payload.sg_cnt, | |
2860 | rx_databuf, size); | |
2861 | job->reply->reply_payload_rcv_len = size; | |
2862 | } | |
2863 | } | |
2864 | ||
2865 | err_loopback_test_exit: | |
2866 | lpfcdiag_loop_self_unreg(phba, rpi); | |
2867 | ||
2868 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2869 | lpfc_bsg_event_unref(evt); /* release ref */ | |
2870 | lpfc_bsg_event_unref(evt); /* delete */ | |
2871 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2872 | ||
2873 | if (cmdiocbq != NULL) | |
2874 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
2875 | ||
2876 | if (rspiocbq != NULL) | |
2877 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
2878 | ||
2879 | if (txbmp != NULL) { | |
2880 | if (txbpl != NULL) { | |
2881 | if (txbuffer != NULL) | |
2882 | diag_cmd_data_free(phba, txbuffer); | |
2883 | lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys); | |
2884 | } | |
2885 | kfree(txbmp); | |
2886 | } | |
2887 | ||
2888 | loopback_test_exit: | |
2889 | kfree(dataout); | |
2890 | /* make error code available to userspace */ | |
2891 | job->reply->result = rc; | |
2892 | job->dd_data = NULL; | |
2893 | /* complete the job back to userspace if no error */ | |
2894 | if (rc == 0) | |
2895 | job->job_done(job); | |
2896 | return rc; | |
2897 | } | |
2898 | ||
2899 | /** | |
2900 | * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command | |
2901 | * @job: GET_DFC_REV fc_bsg_job | |
2902 | **/ | |
2903 | static int | |
2904 | lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job) | |
2905 | { | |
2906 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
2907 | struct lpfc_hba *phba = vport->phba; | |
2908 | struct get_mgmt_rev *event_req; | |
2909 | struct get_mgmt_rev_reply *event_reply; | |
2910 | int rc = 0; | |
2911 | ||
2912 | if (job->request_len < | |
2913 | sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) { | |
2914 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2915 | "2740 Received GET_DFC_REV request below " | |
2916 | "minimum size\n"); | |
2917 | rc = -EINVAL; | |
2918 | goto job_error; | |
2919 | } | |
2920 | ||
2921 | event_req = (struct get_mgmt_rev *) | |
2922 | job->request->rqst_data.h_vendor.vendor_cmd; | |
2923 | ||
2924 | event_reply = (struct get_mgmt_rev_reply *) | |
2925 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
2926 | ||
2927 | if (job->reply_len < | |
2928 | sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev_reply)) { | |
2929 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2930 | "2741 Received GET_DFC_REV reply below " | |
2931 | "minimum size\n"); | |
2932 | rc = -EINVAL; | |
2933 | goto job_error; | |
2934 | } | |
2935 | ||
2936 | event_reply->info.a_Major = MANAGEMENT_MAJOR_REV; | |
2937 | event_reply->info.a_Minor = MANAGEMENT_MINOR_REV; | |
2938 | job_error: | |
2939 | job->reply->result = rc; | |
2940 | if (rc == 0) | |
2941 | job->job_done(job); | |
2942 | return rc; | |
2943 | } | |
2944 | ||
2945 | /** | |
7ad20aa9 | 2946 | * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler |
3b5dd52a JS |
2947 | * @phba: Pointer to HBA context object. |
2948 | * @pmboxq: Pointer to mailbox command. | |
2949 | * | |
2950 | * This is completion handler function for mailbox commands issued from | |
2951 | * lpfc_bsg_issue_mbox function. This function is called by the | |
2952 | * mailbox event handler function with no lock held. This function | |
2953 | * will wake up thread waiting on the wait queue pointed by context1 | |
2954 | * of the mailbox. | |
2955 | **/ | |
2956 | void | |
7ad20aa9 | 2957 | lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
3b5dd52a JS |
2958 | { |
2959 | struct bsg_job_data *dd_data; | |
3b5dd52a JS |
2960 | struct fc_bsg_job *job; |
2961 | uint32_t size; | |
2962 | unsigned long flags; | |
7ad20aa9 | 2963 | uint8_t *pmb, *pmb_buf; |
3b5dd52a JS |
2964 | |
2965 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2966 | dd_data = pmboxq->context1; | |
7a470277 | 2967 | /* job already timed out? */ |
3b5dd52a JS |
2968 | if (!dd_data) { |
2969 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2970 | return; | |
2971 | } | |
2972 | ||
7ad20aa9 JS |
2973 | /* |
2974 | * The outgoing buffer is readily referred from the dma buffer, | |
2975 | * just need to get header part from mailboxq structure. | |
7a470277 | 2976 | */ |
7ad20aa9 JS |
2977 | pmb = (uint8_t *)&pmboxq->u.mb; |
2978 | pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb; | |
2979 | memcpy(pmb_buf, pmb, sizeof(MAILBOX_t)); | |
7a470277 | 2980 | |
3b5dd52a | 2981 | job = dd_data->context_un.mbox.set_job; |
5a6f133e JS |
2982 | if (job) { |
2983 | size = job->reply_payload.payload_len; | |
2984 | job->reply->reply_payload_rcv_len = | |
2985 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
7ad20aa9 JS |
2986 | job->reply_payload.sg_cnt, |
2987 | pmb_buf, size); | |
b6e3b9c6 JS |
2988 | /* need to hold the lock until we set job->dd_data to NULL |
2989 | * to hold off the timeout handler returning to the mid-layer | |
2990 | * while we are still processing the job. | |
2991 | */ | |
5a6f133e | 2992 | job->dd_data = NULL; |
b6e3b9c6 JS |
2993 | dd_data->context_un.mbox.set_job = NULL; |
2994 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
b6e3b9c6 JS |
2995 | } else { |
2996 | dd_data->context_un.mbox.set_job = NULL; | |
2997 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
5a6f133e | 2998 | } |
7a470277 | 2999 | |
3b5dd52a | 3000 | mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool); |
7ad20aa9 JS |
3001 | lpfc_bsg_dma_page_free(phba, dd_data->context_un.mbox.dmabuffers); |
3002 | kfree(dd_data); | |
3003 | ||
3004 | if (job) { | |
3005 | job->reply->result = 0; | |
3006 | job->job_done(job); | |
3007 | } | |
3008 | return; | |
3009 | } | |
3010 | ||
3011 | /** | |
3012 | * lpfc_bsg_check_cmd_access - test for a supported mailbox command | |
3013 | * @phba: Pointer to HBA context object. | |
3014 | * @mb: Pointer to a mailbox object. | |
3015 | * @vport: Pointer to a vport object. | |
3016 | * | |
3017 | * Some commands require the port to be offline, some may not be called from | |
3018 | * the application. | |
3019 | **/ | |
3020 | static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba, | |
3021 | MAILBOX_t *mb, struct lpfc_vport *vport) | |
3022 | { | |
3023 | /* return negative error values for bsg job */ | |
3024 | switch (mb->mbxCommand) { | |
3025 | /* Offline only */ | |
3026 | case MBX_INIT_LINK: | |
3027 | case MBX_DOWN_LINK: | |
3028 | case MBX_CONFIG_LINK: | |
3029 | case MBX_CONFIG_RING: | |
3030 | case MBX_RESET_RING: | |
3031 | case MBX_UNREG_LOGIN: | |
3032 | case MBX_CLEAR_LA: | |
3033 | case MBX_DUMP_CONTEXT: | |
3034 | case MBX_RUN_DIAGS: | |
3035 | case MBX_RESTART: | |
3036 | case MBX_SET_MASK: | |
3037 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { | |
3038 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
3039 | "2743 Command 0x%x is illegal in on-line " | |
3040 | "state\n", | |
3041 | mb->mbxCommand); | |
3042 | return -EPERM; | |
3043 | } | |
3044 | case MBX_WRITE_NV: | |
3045 | case MBX_WRITE_VPARMS: | |
3046 | case MBX_LOAD_SM: | |
3047 | case MBX_READ_NV: | |
3048 | case MBX_READ_CONFIG: | |
3049 | case MBX_READ_RCONFIG: | |
3050 | case MBX_READ_STATUS: | |
3051 | case MBX_READ_XRI: | |
3052 | case MBX_READ_REV: | |
3053 | case MBX_READ_LNK_STAT: | |
3054 | case MBX_DUMP_MEMORY: | |
3055 | case MBX_DOWN_LOAD: | |
3056 | case MBX_UPDATE_CFG: | |
3057 | case MBX_KILL_BOARD: | |
3058 | case MBX_LOAD_AREA: | |
3059 | case MBX_LOAD_EXP_ROM: | |
3060 | case MBX_BEACON: | |
3061 | case MBX_DEL_LD_ENTRY: | |
3062 | case MBX_SET_DEBUG: | |
3063 | case MBX_WRITE_WWN: | |
3064 | case MBX_SLI4_CONFIG: | |
3065 | case MBX_READ_EVENT_LOG: | |
3066 | case MBX_READ_EVENT_LOG_STATUS: | |
3067 | case MBX_WRITE_EVENT_LOG: | |
3068 | case MBX_PORT_CAPABILITIES: | |
3069 | case MBX_PORT_IOV_CONTROL: | |
3070 | case MBX_RUN_BIU_DIAG64: | |
3071 | break; | |
3072 | case MBX_SET_VARIABLE: | |
3073 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3074 | "1226 mbox: set_variable 0x%x, 0x%x\n", | |
3075 | mb->un.varWords[0], | |
3076 | mb->un.varWords[1]); | |
3077 | if ((mb->un.varWords[0] == SETVAR_MLOMNT) | |
3078 | && (mb->un.varWords[1] == 1)) { | |
3079 | phba->wait_4_mlo_maint_flg = 1; | |
3080 | } else if (mb->un.varWords[0] == SETVAR_MLORST) { | |
3081 | phba->link_flag &= ~LS_LOOPBACK_MODE; | |
3082 | phba->fc_topology = LPFC_TOPOLOGY_PT_PT; | |
3083 | } | |
3084 | break; | |
3085 | case MBX_READ_SPARM64: | |
3086 | case MBX_READ_TOPOLOGY: | |
3087 | case MBX_REG_LOGIN: | |
3088 | case MBX_REG_LOGIN64: | |
3089 | case MBX_CONFIG_PORT: | |
3090 | case MBX_RUN_BIU_DIAG: | |
3091 | default: | |
3092 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
3093 | "2742 Unknown Command 0x%x\n", | |
3094 | mb->mbxCommand); | |
3095 | return -EPERM; | |
3096 | } | |
3097 | ||
3098 | return 0; /* ok */ | |
3099 | } | |
3100 | ||
3101 | /** | |
3102 | * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session | |
3103 | * @phba: Pointer to HBA context object. | |
3104 | * | |
3105 | * This is routine clean up and reset BSG handling of multi-buffer mbox | |
3106 | * command session. | |
3107 | **/ | |
3108 | static void | |
3109 | lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba *phba) | |
3110 | { | |
3111 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) | |
3112 | return; | |
3113 | ||
3114 | /* free all memory, including dma buffers */ | |
3115 | lpfc_bsg_dma_page_list_free(phba, | |
3116 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
3117 | lpfc_bsg_dma_page_free(phba, phba->mbox_ext_buf_ctx.mbx_dmabuf); | |
3118 | /* multi-buffer write mailbox command pass-through complete */ | |
3119 | memset((char *)&phba->mbox_ext_buf_ctx, 0, | |
3120 | sizeof(struct lpfc_mbox_ext_buf_ctx)); | |
3121 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
3122 | ||
3123 | return; | |
3124 | } | |
3125 | ||
3126 | /** | |
3127 | * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl | |
3128 | * @phba: Pointer to HBA context object. | |
3129 | * @pmboxq: Pointer to mailbox command. | |
3130 | * | |
3131 | * This is routine handles BSG job for mailbox commands completions with | |
3132 | * multiple external buffers. | |
3133 | **/ | |
3134 | static struct fc_bsg_job * | |
3135 | lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
3136 | { | |
3137 | struct bsg_job_data *dd_data; | |
3138 | struct fc_bsg_job *job; | |
3139 | uint8_t *pmb, *pmb_buf; | |
3140 | unsigned long flags; | |
3141 | uint32_t size; | |
3142 | int rc = 0; | |
026abb87 JS |
3143 | struct lpfc_dmabuf *dmabuf; |
3144 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3145 | uint8_t *pmbx; | |
7ad20aa9 JS |
3146 | |
3147 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
3148 | dd_data = pmboxq->context1; | |
3149 | /* has the job already timed out? */ | |
3150 | if (!dd_data) { | |
3151 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3152 | job = NULL; | |
3153 | goto job_done_out; | |
3154 | } | |
3155 | ||
3156 | /* | |
3157 | * The outgoing buffer is readily referred from the dma buffer, | |
3158 | * just need to get header part from mailboxq structure. | |
3159 | */ | |
3160 | pmb = (uint8_t *)&pmboxq->u.mb; | |
3161 | pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb; | |
026abb87 | 3162 | /* Copy the byte swapped response mailbox back to the user */ |
7ad20aa9 | 3163 | memcpy(pmb_buf, pmb, sizeof(MAILBOX_t)); |
026abb87 JS |
3164 | /* if there is any non-embedded extended data copy that too */ |
3165 | dmabuf = phba->mbox_ext_buf_ctx.mbx_dmabuf; | |
3166 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; | |
3167 | if (!bsg_bf_get(lpfc_mbox_hdr_emb, | |
3168 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) { | |
3169 | pmbx = (uint8_t *)dmabuf->virt; | |
3170 | /* byte swap the extended data following the mailbox command */ | |
3171 | lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)], | |
3172 | &pmbx[sizeof(MAILBOX_t)], | |
3173 | sli_cfg_mbx->un.sli_config_emb0_subsys.mse[0].buf_len); | |
3174 | } | |
7ad20aa9 JS |
3175 | |
3176 | job = dd_data->context_un.mbox.set_job; | |
3177 | if (job) { | |
3178 | size = job->reply_payload.payload_len; | |
3179 | job->reply->reply_payload_rcv_len = | |
3180 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
3181 | job->reply_payload.sg_cnt, | |
3182 | pmb_buf, size); | |
3183 | /* result for successful */ | |
3184 | job->reply->result = 0; | |
3185 | job->dd_data = NULL; | |
3186 | /* need to hold the lock util we set job->dd_data to NULL | |
3187 | * to hold off the timeout handler from midlayer to take | |
3188 | * any action. | |
3189 | */ | |
3190 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3191 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3192 | "2937 SLI_CONFIG ext-buffer maibox command " | |
3193 | "(x%x/x%x) complete bsg job done, bsize:%d\n", | |
3194 | phba->mbox_ext_buf_ctx.nembType, | |
3195 | phba->mbox_ext_buf_ctx.mboxType, size); | |
b76f2dc9 JS |
3196 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, |
3197 | phba->mbox_ext_buf_ctx.nembType, | |
3198 | phba->mbox_ext_buf_ctx.mboxType, | |
3199 | dma_ebuf, sta_pos_addr, | |
3200 | phba->mbox_ext_buf_ctx.mbx_dmabuf, 0); | |
7ad20aa9 JS |
3201 | } else |
3202 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3203 | ||
3204 | job_done_out: | |
3205 | if (!job) | |
3206 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
3207 | "2938 SLI_CONFIG ext-buffer maibox " | |
3208 | "command (x%x/x%x) failure, rc:x%x\n", | |
3209 | phba->mbox_ext_buf_ctx.nembType, | |
3210 | phba->mbox_ext_buf_ctx.mboxType, rc); | |
3211 | /* state change */ | |
3212 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_DONE; | |
3213 | kfree(dd_data); | |
3214 | ||
3215 | return job; | |
3216 | } | |
3217 | ||
3218 | /** | |
3219 | * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox | |
3220 | * @phba: Pointer to HBA context object. | |
3221 | * @pmboxq: Pointer to mailbox command. | |
3222 | * | |
3223 | * This is completion handler function for mailbox read commands with multiple | |
3224 | * external buffers. | |
3225 | **/ | |
3226 | static void | |
3227 | lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
3228 | { | |
3229 | struct fc_bsg_job *job; | |
3230 | ||
3231 | /* handle the BSG job with mailbox command */ | |
3232 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_ABTS) | |
3233 | pmboxq->u.mb.mbxStatus = MBXERR_ERROR; | |
3234 | ||
3235 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3236 | "2939 SLI_CONFIG ext-buffer rd maibox command " | |
3237 | "complete, ctxState:x%x, mbxStatus:x%x\n", | |
3238 | phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus); | |
3239 | ||
3240 | job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq); | |
3241 | ||
3242 | if (pmboxq->u.mb.mbxStatus || phba->mbox_ext_buf_ctx.numBuf == 1) | |
3243 | lpfc_bsg_mbox_ext_session_reset(phba); | |
3244 | ||
3245 | /* free base driver mailbox structure memory */ | |
3246 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
3247 | ||
3248 | /* complete the bsg job if we have it */ | |
3249 | if (job) | |
3250 | job->job_done(job); | |
3251 | ||
3252 | return; | |
3253 | } | |
3254 | ||
3255 | /** | |
3256 | * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox | |
3257 | * @phba: Pointer to HBA context object. | |
3258 | * @pmboxq: Pointer to mailbox command. | |
3259 | * | |
3260 | * This is completion handler function for mailbox write commands with multiple | |
3261 | * external buffers. | |
3262 | **/ | |
3263 | static void | |
3264 | lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
3265 | { | |
3266 | struct fc_bsg_job *job; | |
3267 | ||
3268 | /* handle the BSG job with the mailbox command */ | |
3269 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_ABTS) | |
3270 | pmboxq->u.mb.mbxStatus = MBXERR_ERROR; | |
3271 | ||
3272 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3273 | "2940 SLI_CONFIG ext-buffer wr maibox command " | |
3274 | "complete, ctxState:x%x, mbxStatus:x%x\n", | |
3275 | phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus); | |
3276 | ||
3277 | job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq); | |
3278 | ||
3279 | /* free all memory, including dma buffers */ | |
3280 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
3281 | lpfc_bsg_mbox_ext_session_reset(phba); | |
3282 | ||
3283 | /* complete the bsg job if we have it */ | |
3284 | if (job) | |
3285 | job->job_done(job); | |
3286 | ||
3287 | return; | |
3288 | } | |
3289 | ||
3290 | static void | |
3291 | lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba *phba, enum nemb_type nemb_tp, | |
3292 | uint32_t index, struct lpfc_dmabuf *mbx_dmabuf, | |
3293 | struct lpfc_dmabuf *ext_dmabuf) | |
3294 | { | |
3295 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3296 | ||
3297 | /* pointer to the start of mailbox command */ | |
3298 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)mbx_dmabuf->virt; | |
3299 | ||
3300 | if (nemb_tp == nemb_mse) { | |
3301 | if (index == 0) { | |
3302 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3303 | mse[index].pa_hi = | |
3304 | putPaddrHigh(mbx_dmabuf->phys + | |
3305 | sizeof(MAILBOX_t)); | |
3306 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3307 | mse[index].pa_lo = | |
3308 | putPaddrLow(mbx_dmabuf->phys + | |
3309 | sizeof(MAILBOX_t)); | |
3310 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3311 | "2943 SLI_CONFIG(mse)[%d], " | |
3312 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", | |
3313 | index, | |
3314 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3315 | mse[index].buf_len, | |
3316 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3317 | mse[index].pa_hi, | |
3318 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3319 | mse[index].pa_lo); | |
3320 | } else { | |
3321 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3322 | mse[index].pa_hi = | |
3323 | putPaddrHigh(ext_dmabuf->phys); | |
3324 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3325 | mse[index].pa_lo = | |
3326 | putPaddrLow(ext_dmabuf->phys); | |
3327 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3328 | "2944 SLI_CONFIG(mse)[%d], " | |
3329 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", | |
3330 | index, | |
3331 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3332 | mse[index].buf_len, | |
3333 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3334 | mse[index].pa_hi, | |
3335 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3336 | mse[index].pa_lo); | |
3337 | } | |
3338 | } else { | |
3339 | if (index == 0) { | |
3340 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3341 | hbd[index].pa_hi = | |
3342 | putPaddrHigh(mbx_dmabuf->phys + | |
3343 | sizeof(MAILBOX_t)); | |
3344 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3345 | hbd[index].pa_lo = | |
3346 | putPaddrLow(mbx_dmabuf->phys + | |
3347 | sizeof(MAILBOX_t)); | |
3348 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3349 | "3007 SLI_CONFIG(hbd)[%d], " | |
3350 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", | |
3351 | index, | |
3352 | bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, | |
3353 | &sli_cfg_mbx->un. | |
3354 | sli_config_emb1_subsys.hbd[index]), | |
3355 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3356 | hbd[index].pa_hi, | |
3357 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3358 | hbd[index].pa_lo); | |
3359 | ||
3360 | } else { | |
3361 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3362 | hbd[index].pa_hi = | |
3363 | putPaddrHigh(ext_dmabuf->phys); | |
3364 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3365 | hbd[index].pa_lo = | |
3366 | putPaddrLow(ext_dmabuf->phys); | |
3367 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3368 | "3008 SLI_CONFIG(hbd)[%d], " | |
3369 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", | |
3370 | index, | |
3371 | bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, | |
3372 | &sli_cfg_mbx->un. | |
3373 | sli_config_emb1_subsys.hbd[index]), | |
3374 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3375 | hbd[index].pa_hi, | |
3376 | sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3377 | hbd[index].pa_lo); | |
3378 | } | |
3379 | } | |
3380 | return; | |
3381 | } | |
3382 | ||
3383 | /** | |
3384 | * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read | |
3385 | * @phba: Pointer to HBA context object. | |
3386 | * @mb: Pointer to a BSG mailbox object. | |
3387 | * @nemb_tp: Enumerate of non-embedded mailbox command type. | |
3388 | * @dmabuff: Pointer to a DMA buffer descriptor. | |
3389 | * | |
3390 | * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with | |
3391 | * non-embedded external bufffers. | |
3392 | **/ | |
3393 | static int | |
3394 | lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
3395 | enum nemb_type nemb_tp, | |
3396 | struct lpfc_dmabuf *dmabuf) | |
3397 | { | |
3398 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3399 | struct dfc_mbox_req *mbox_req; | |
3400 | struct lpfc_dmabuf *curr_dmabuf, *next_dmabuf; | |
3401 | uint32_t ext_buf_cnt, ext_buf_index; | |
3402 | struct lpfc_dmabuf *ext_dmabuf = NULL; | |
3403 | struct bsg_job_data *dd_data = NULL; | |
3404 | LPFC_MBOXQ_t *pmboxq = NULL; | |
3405 | MAILBOX_t *pmb; | |
3406 | uint8_t *pmbx; | |
3407 | int rc, i; | |
3408 | ||
3409 | mbox_req = | |
3410 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; | |
3411 | ||
3412 | /* pointer to the start of mailbox command */ | |
3413 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; | |
3414 | ||
3415 | if (nemb_tp == nemb_mse) { | |
3416 | ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt, | |
3417 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr); | |
3418 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) { | |
3419 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
3420 | "2945 Handled SLI_CONFIG(mse) rd, " | |
3421 | "ext_buf_cnt(%d) out of range(%d)\n", | |
3422 | ext_buf_cnt, | |
3423 | LPFC_MBX_SLI_CONFIG_MAX_MSE); | |
3424 | rc = -ERANGE; | |
3425 | goto job_error; | |
3426 | } | |
3427 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3428 | "2941 Handled SLI_CONFIG(mse) rd, " | |
3429 | "ext_buf_cnt:%d\n", ext_buf_cnt); | |
3430 | } else { | |
3431 | /* sanity check on interface type for support */ | |
3432 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
3433 | LPFC_SLI_INTF_IF_TYPE_2) { | |
3434 | rc = -ENODEV; | |
3435 | goto job_error; | |
3436 | } | |
3437 | /* nemb_tp == nemb_hbd */ | |
3438 | ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count; | |
3439 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) { | |
3440 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
3441 | "2946 Handled SLI_CONFIG(hbd) rd, " | |
3442 | "ext_buf_cnt(%d) out of range(%d)\n", | |
3443 | ext_buf_cnt, | |
3444 | LPFC_MBX_SLI_CONFIG_MAX_HBD); | |
3445 | rc = -ERANGE; | |
3446 | goto job_error; | |
3447 | } | |
3448 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3449 | "2942 Handled SLI_CONFIG(hbd) rd, " | |
3450 | "ext_buf_cnt:%d\n", ext_buf_cnt); | |
3451 | } | |
3452 | ||
b76f2dc9 JS |
3453 | /* before dma descriptor setup */ |
3454 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox, | |
3455 | sta_pre_addr, dmabuf, ext_buf_cnt); | |
3456 | ||
7ad20aa9 JS |
3457 | /* reject non-embedded mailbox command with none external buffer */ |
3458 | if (ext_buf_cnt == 0) { | |
3459 | rc = -EPERM; | |
3460 | goto job_error; | |
3461 | } else if (ext_buf_cnt > 1) { | |
3462 | /* additional external read buffers */ | |
3463 | for (i = 1; i < ext_buf_cnt; i++) { | |
3464 | ext_dmabuf = lpfc_bsg_dma_page_alloc(phba); | |
3465 | if (!ext_dmabuf) { | |
3466 | rc = -ENOMEM; | |
3467 | goto job_error; | |
3468 | } | |
3469 | list_add_tail(&ext_dmabuf->list, | |
3470 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
3471 | } | |
3472 | } | |
3473 | ||
3474 | /* bsg tracking structure */ | |
3475 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
3476 | if (!dd_data) { | |
3477 | rc = -ENOMEM; | |
3478 | goto job_error; | |
3479 | } | |
3480 | ||
3481 | /* mailbox command structure for base driver */ | |
3482 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3483 | if (!pmboxq) { | |
3484 | rc = -ENOMEM; | |
3485 | goto job_error; | |
3486 | } | |
3487 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
3488 | ||
3489 | /* for the first external buffer */ | |
3490 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf); | |
3491 | ||
3492 | /* for the rest of external buffer descriptors if any */ | |
3493 | if (ext_buf_cnt > 1) { | |
3494 | ext_buf_index = 1; | |
3495 | list_for_each_entry_safe(curr_dmabuf, next_dmabuf, | |
3496 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list, list) { | |
3497 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, | |
3498 | ext_buf_index, dmabuf, | |
3499 | curr_dmabuf); | |
3500 | ext_buf_index++; | |
3501 | } | |
3502 | } | |
3503 | ||
b76f2dc9 JS |
3504 | /* after dma descriptor setup */ |
3505 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox, | |
3506 | sta_pos_addr, dmabuf, ext_buf_cnt); | |
3507 | ||
7ad20aa9 JS |
3508 | /* construct base driver mbox command */ |
3509 | pmb = &pmboxq->u.mb; | |
3510 | pmbx = (uint8_t *)dmabuf->virt; | |
3511 | memcpy(pmb, pmbx, sizeof(*pmb)); | |
3512 | pmb->mbxOwner = OWN_HOST; | |
3513 | pmboxq->vport = phba->pport; | |
3514 | ||
3515 | /* multi-buffer handling context */ | |
3516 | phba->mbox_ext_buf_ctx.nembType = nemb_tp; | |
3517 | phba->mbox_ext_buf_ctx.mboxType = mbox_rd; | |
3518 | phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt; | |
3519 | phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag; | |
3520 | phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum; | |
3521 | phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf; | |
3522 | ||
3523 | /* callback for multi-buffer read mailbox command */ | |
3524 | pmboxq->mbox_cmpl = lpfc_bsg_issue_read_mbox_ext_cmpl; | |
3525 | ||
3526 | /* context fields to callback function */ | |
3527 | pmboxq->context1 = dd_data; | |
3528 | dd_data->type = TYPE_MBOX; | |
3529 | dd_data->context_un.mbox.pmboxq = pmboxq; | |
3530 | dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx; | |
3531 | dd_data->context_un.mbox.set_job = job; | |
3532 | job->dd_data = dd_data; | |
3533 | ||
3534 | /* state change */ | |
3535 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT; | |
3536 | ||
026abb87 JS |
3537 | /* |
3538 | * Non-embedded mailbox subcommand data gets byte swapped here because | |
3539 | * the lower level driver code only does the first 64 mailbox words. | |
3540 | */ | |
3541 | if ((!bsg_bf_get(lpfc_mbox_hdr_emb, | |
3542 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) && | |
3543 | (nemb_tp == nemb_mse)) | |
3544 | lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)], | |
3545 | &pmbx[sizeof(MAILBOX_t)], | |
3546 | sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3547 | mse[0].buf_len); | |
3548 | ||
7ad20aa9 JS |
3549 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
3550 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) { | |
3551 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3552 | "2947 Issued SLI_CONFIG ext-buffer " | |
3553 | "maibox command, rc:x%x\n", rc); | |
88a2cfbb | 3554 | return SLI_CONFIG_HANDLED; |
7ad20aa9 JS |
3555 | } |
3556 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
3557 | "2948 Failed to issue SLI_CONFIG ext-buffer " | |
3558 | "maibox command, rc:x%x\n", rc); | |
3559 | rc = -EPIPE; | |
3560 | ||
3561 | job_error: | |
3562 | if (pmboxq) | |
3563 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
3564 | lpfc_bsg_dma_page_list_free(phba, | |
3565 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
3566 | kfree(dd_data); | |
3567 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE; | |
3568 | return rc; | |
3569 | } | |
3570 | ||
3571 | /** | |
3572 | * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write | |
3573 | * @phba: Pointer to HBA context object. | |
3574 | * @mb: Pointer to a BSG mailbox object. | |
3575 | * @dmabuff: Pointer to a DMA buffer descriptor. | |
3576 | * | |
3577 | * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with | |
3578 | * non-embedded external bufffers. | |
3579 | **/ | |
3580 | static int | |
3581 | lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
3582 | enum nemb_type nemb_tp, | |
3583 | struct lpfc_dmabuf *dmabuf) | |
3584 | { | |
3585 | struct dfc_mbox_req *mbox_req; | |
3586 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3587 | uint32_t ext_buf_cnt; | |
3588 | struct bsg_job_data *dd_data = NULL; | |
3589 | LPFC_MBOXQ_t *pmboxq = NULL; | |
3590 | MAILBOX_t *pmb; | |
3591 | uint8_t *mbx; | |
88a2cfbb | 3592 | int rc = SLI_CONFIG_NOT_HANDLED, i; |
7ad20aa9 JS |
3593 | |
3594 | mbox_req = | |
3595 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; | |
3596 | ||
3597 | /* pointer to the start of mailbox command */ | |
3598 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; | |
3599 | ||
3600 | if (nemb_tp == nemb_mse) { | |
3601 | ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt, | |
3602 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr); | |
3603 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) { | |
3604 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
026abb87 | 3605 | "2953 Failed SLI_CONFIG(mse) wr, " |
7ad20aa9 JS |
3606 | "ext_buf_cnt(%d) out of range(%d)\n", |
3607 | ext_buf_cnt, | |
3608 | LPFC_MBX_SLI_CONFIG_MAX_MSE); | |
3609 | return -ERANGE; | |
3610 | } | |
3611 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3612 | "2949 Handled SLI_CONFIG(mse) wr, " | |
3613 | "ext_buf_cnt:%d\n", ext_buf_cnt); | |
3614 | } else { | |
3615 | /* sanity check on interface type for support */ | |
3616 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
3617 | LPFC_SLI_INTF_IF_TYPE_2) | |
3618 | return -ENODEV; | |
3619 | /* nemb_tp == nemb_hbd */ | |
3620 | ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count; | |
3621 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) { | |
3622 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
026abb87 | 3623 | "2954 Failed SLI_CONFIG(hbd) wr, " |
7ad20aa9 JS |
3624 | "ext_buf_cnt(%d) out of range(%d)\n", |
3625 | ext_buf_cnt, | |
3626 | LPFC_MBX_SLI_CONFIG_MAX_HBD); | |
3627 | return -ERANGE; | |
3628 | } | |
3629 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3630 | "2950 Handled SLI_CONFIG(hbd) wr, " | |
3631 | "ext_buf_cnt:%d\n", ext_buf_cnt); | |
3632 | } | |
3633 | ||
b76f2dc9 JS |
3634 | /* before dma buffer descriptor setup */ |
3635 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox, | |
3636 | sta_pre_addr, dmabuf, ext_buf_cnt); | |
3637 | ||
7ad20aa9 JS |
3638 | if (ext_buf_cnt == 0) |
3639 | return -EPERM; | |
3640 | ||
3641 | /* for the first external buffer */ | |
3642 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf); | |
3643 | ||
b76f2dc9 JS |
3644 | /* after dma descriptor setup */ |
3645 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox, | |
3646 | sta_pos_addr, dmabuf, ext_buf_cnt); | |
3647 | ||
7ad20aa9 JS |
3648 | /* log for looking forward */ |
3649 | for (i = 1; i < ext_buf_cnt; i++) { | |
3650 | if (nemb_tp == nemb_mse) | |
3651 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3652 | "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n", | |
3653 | i, sli_cfg_mbx->un.sli_config_emb0_subsys. | |
3654 | mse[i].buf_len); | |
3655 | else | |
3656 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3657 | "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n", | |
3658 | i, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, | |
3659 | &sli_cfg_mbx->un.sli_config_emb1_subsys. | |
3660 | hbd[i])); | |
3661 | } | |
3662 | ||
3663 | /* multi-buffer handling context */ | |
3664 | phba->mbox_ext_buf_ctx.nembType = nemb_tp; | |
3665 | phba->mbox_ext_buf_ctx.mboxType = mbox_wr; | |
3666 | phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt; | |
3667 | phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag; | |
3668 | phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum; | |
3669 | phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf; | |
3670 | ||
3671 | if (ext_buf_cnt == 1) { | |
3672 | /* bsg tracking structure */ | |
3673 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
3674 | if (!dd_data) { | |
3675 | rc = -ENOMEM; | |
3676 | goto job_error; | |
3677 | } | |
3678 | ||
3679 | /* mailbox command structure for base driver */ | |
3680 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3681 | if (!pmboxq) { | |
3682 | rc = -ENOMEM; | |
3683 | goto job_error; | |
3684 | } | |
3685 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
3686 | pmb = &pmboxq->u.mb; | |
3687 | mbx = (uint8_t *)dmabuf->virt; | |
3688 | memcpy(pmb, mbx, sizeof(*pmb)); | |
3689 | pmb->mbxOwner = OWN_HOST; | |
3690 | pmboxq->vport = phba->pport; | |
3691 | ||
3692 | /* callback for multi-buffer read mailbox command */ | |
3693 | pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl; | |
3694 | ||
3695 | /* context fields to callback function */ | |
3696 | pmboxq->context1 = dd_data; | |
3697 | dd_data->type = TYPE_MBOX; | |
3698 | dd_data->context_un.mbox.pmboxq = pmboxq; | |
3699 | dd_data->context_un.mbox.mb = (MAILBOX_t *)mbx; | |
3700 | dd_data->context_un.mbox.set_job = job; | |
3701 | job->dd_data = dd_data; | |
3702 | ||
3703 | /* state change */ | |
3704 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT; | |
3705 | ||
3706 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
3707 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) { | |
3708 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3709 | "2955 Issued SLI_CONFIG ext-buffer " | |
3710 | "maibox command, rc:x%x\n", rc); | |
88a2cfbb | 3711 | return SLI_CONFIG_HANDLED; |
7ad20aa9 JS |
3712 | } |
3713 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
3714 | "2956 Failed to issue SLI_CONFIG ext-buffer " | |
3715 | "maibox command, rc:x%x\n", rc); | |
3716 | rc = -EPIPE; | |
026abb87 | 3717 | goto job_error; |
7ad20aa9 JS |
3718 | } |
3719 | ||
88a2cfbb JS |
3720 | /* wait for additoinal external buffers */ |
3721 | job->reply->result = 0; | |
3722 | job->job_done(job); | |
3723 | return SLI_CONFIG_HANDLED; | |
3724 | ||
7ad20aa9 JS |
3725 | job_error: |
3726 | if (pmboxq) | |
3727 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
3728 | kfree(dd_data); | |
3729 | ||
3730 | return rc; | |
3731 | } | |
3732 | ||
3733 | /** | |
3734 | * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer | |
3735 | * @phba: Pointer to HBA context object. | |
3736 | * @mb: Pointer to a BSG mailbox object. | |
3737 | * @dmabuff: Pointer to a DMA buffer descriptor. | |
3738 | * | |
3739 | * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded | |
3740 | * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B | |
3741 | * with embedded sussystem 0x1 and opcodes with external HBDs. | |
3742 | **/ | |
3743 | static int | |
3744 | lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
3745 | struct lpfc_dmabuf *dmabuf) | |
3746 | { | |
3747 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3748 | uint32_t subsys; | |
3749 | uint32_t opcode; | |
3750 | int rc = SLI_CONFIG_NOT_HANDLED; | |
3751 | ||
026abb87 | 3752 | /* state change on new multi-buffer pass-through mailbox command */ |
7ad20aa9 JS |
3753 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_HOST; |
3754 | ||
3755 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; | |
3756 | ||
3757 | if (!bsg_bf_get(lpfc_mbox_hdr_emb, | |
3758 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) { | |
3759 | subsys = bsg_bf_get(lpfc_emb0_subcmnd_subsys, | |
3760 | &sli_cfg_mbx->un.sli_config_emb0_subsys); | |
3761 | opcode = bsg_bf_get(lpfc_emb0_subcmnd_opcode, | |
3762 | &sli_cfg_mbx->un.sli_config_emb0_subsys); | |
3763 | if (subsys == SLI_CONFIG_SUBSYS_FCOE) { | |
3764 | switch (opcode) { | |
3765 | case FCOE_OPCODE_READ_FCF: | |
3766 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3767 | "2957 Handled SLI_CONFIG " | |
3768 | "subsys_fcoe, opcode:x%x\n", | |
3769 | opcode); | |
3770 | rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job, | |
3771 | nemb_mse, dmabuf); | |
3772 | break; | |
3773 | case FCOE_OPCODE_ADD_FCF: | |
3774 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3775 | "2958 Handled SLI_CONFIG " | |
3776 | "subsys_fcoe, opcode:x%x\n", | |
3777 | opcode); | |
3778 | rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job, | |
3779 | nemb_mse, dmabuf); | |
3780 | break; | |
3781 | default: | |
3782 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
026abb87 | 3783 | "2959 Reject SLI_CONFIG " |
7ad20aa9 JS |
3784 | "subsys_fcoe, opcode:x%x\n", |
3785 | opcode); | |
026abb87 JS |
3786 | rc = -EPERM; |
3787 | break; | |
3788 | } | |
3789 | } else if (subsys == SLI_CONFIG_SUBSYS_COMN) { | |
3790 | switch (opcode) { | |
3791 | case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES: | |
3792 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3793 | "3106 Handled SLI_CONFIG " | |
3794 | "subsys_fcoe, opcode:x%x\n", | |
3795 | opcode); | |
3796 | rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job, | |
3797 | nemb_mse, dmabuf); | |
3798 | break; | |
3799 | default: | |
3800 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3801 | "3107 Reject SLI_CONFIG " | |
3802 | "subsys_fcoe, opcode:x%x\n", | |
3803 | opcode); | |
3804 | rc = -EPERM; | |
7ad20aa9 JS |
3805 | break; |
3806 | } | |
3807 | } else { | |
3808 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
026abb87 | 3809 | "2977 Reject SLI_CONFIG " |
7ad20aa9 JS |
3810 | "subsys:x%d, opcode:x%x\n", |
3811 | subsys, opcode); | |
026abb87 | 3812 | rc = -EPERM; |
7ad20aa9 JS |
3813 | } |
3814 | } else { | |
3815 | subsys = bsg_bf_get(lpfc_emb1_subcmnd_subsys, | |
3816 | &sli_cfg_mbx->un.sli_config_emb1_subsys); | |
3817 | opcode = bsg_bf_get(lpfc_emb1_subcmnd_opcode, | |
3818 | &sli_cfg_mbx->un.sli_config_emb1_subsys); | |
3819 | if (subsys == SLI_CONFIG_SUBSYS_COMN) { | |
3820 | switch (opcode) { | |
3821 | case COMN_OPCODE_READ_OBJECT: | |
3822 | case COMN_OPCODE_READ_OBJECT_LIST: | |
3823 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3824 | "2960 Handled SLI_CONFIG " | |
3825 | "subsys_comn, opcode:x%x\n", | |
3826 | opcode); | |
3827 | rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job, | |
3828 | nemb_hbd, dmabuf); | |
3829 | break; | |
3830 | case COMN_OPCODE_WRITE_OBJECT: | |
3831 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3832 | "2961 Handled SLI_CONFIG " | |
3833 | "subsys_comn, opcode:x%x\n", | |
3834 | opcode); | |
3835 | rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job, | |
3836 | nemb_hbd, dmabuf); | |
3837 | break; | |
3838 | default: | |
3839 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3840 | "2962 Not handled SLI_CONFIG " | |
3841 | "subsys_comn, opcode:x%x\n", | |
3842 | opcode); | |
3843 | rc = SLI_CONFIG_NOT_HANDLED; | |
3844 | break; | |
3845 | } | |
3846 | } else { | |
3847 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
026abb87 | 3848 | "2978 Not handled SLI_CONFIG " |
7ad20aa9 JS |
3849 | "subsys:x%d, opcode:x%x\n", |
3850 | subsys, opcode); | |
3851 | rc = SLI_CONFIG_NOT_HANDLED; | |
3852 | } | |
3853 | } | |
026abb87 JS |
3854 | |
3855 | /* state reset on not handled new multi-buffer mailbox command */ | |
3856 | if (rc != SLI_CONFIG_HANDLED) | |
3857 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE; | |
3858 | ||
7ad20aa9 JS |
3859 | return rc; |
3860 | } | |
3861 | ||
3862 | /** | |
3863 | * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers | |
3864 | * @phba: Pointer to HBA context object. | |
3865 | * | |
3866 | * This routine is for requesting to abort a pass-through mailbox command with | |
3867 | * multiple external buffers due to error condition. | |
3868 | **/ | |
3869 | static void | |
3870 | lpfc_bsg_mbox_ext_abort(struct lpfc_hba *phba) | |
3871 | { | |
3872 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT) | |
3873 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS; | |
3874 | else | |
3875 | lpfc_bsg_mbox_ext_session_reset(phba); | |
3876 | return; | |
3877 | } | |
3878 | ||
3879 | /** | |
3880 | * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer | |
3881 | * @phba: Pointer to HBA context object. | |
3882 | * @dmabuf: Pointer to a DMA buffer descriptor. | |
3883 | * | |
3884 | * This routine extracts the next mailbox read external buffer back to | |
3885 | * user space through BSG. | |
3886 | **/ | |
3887 | static int | |
3888 | lpfc_bsg_read_ebuf_get(struct lpfc_hba *phba, struct fc_bsg_job *job) | |
3889 | { | |
3890 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3891 | struct lpfc_dmabuf *dmabuf; | |
3892 | uint8_t *pbuf; | |
3893 | uint32_t size; | |
3894 | uint32_t index; | |
3895 | ||
3896 | index = phba->mbox_ext_buf_ctx.seqNum; | |
3897 | phba->mbox_ext_buf_ctx.seqNum++; | |
3898 | ||
3899 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *) | |
3900 | phba->mbox_ext_buf_ctx.mbx_dmabuf->virt; | |
3901 | ||
3902 | if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) { | |
3903 | size = bsg_bf_get(lpfc_mbox_sli_config_mse_len, | |
3904 | &sli_cfg_mbx->un.sli_config_emb0_subsys.mse[index]); | |
3905 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3906 | "2963 SLI_CONFIG (mse) ext-buffer rd get " | |
3907 | "buffer[%d], size:%d\n", index, size); | |
3908 | } else { | |
3909 | size = bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, | |
3910 | &sli_cfg_mbx->un.sli_config_emb1_subsys.hbd[index]); | |
3911 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3912 | "2964 SLI_CONFIG (hbd) ext-buffer rd get " | |
3913 | "buffer[%d], size:%d\n", index, size); | |
3914 | } | |
3915 | if (list_empty(&phba->mbox_ext_buf_ctx.ext_dmabuf_list)) | |
3916 | return -EPIPE; | |
3917 | dmabuf = list_first_entry(&phba->mbox_ext_buf_ctx.ext_dmabuf_list, | |
3918 | struct lpfc_dmabuf, list); | |
3919 | list_del_init(&dmabuf->list); | |
b76f2dc9 JS |
3920 | |
3921 | /* after dma buffer descriptor setup */ | |
3922 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType, | |
3923 | mbox_rd, dma_ebuf, sta_pos_addr, | |
3924 | dmabuf, index); | |
3925 | ||
7ad20aa9 JS |
3926 | pbuf = (uint8_t *)dmabuf->virt; |
3927 | job->reply->reply_payload_rcv_len = | |
3928 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
3929 | job->reply_payload.sg_cnt, | |
3930 | pbuf, size); | |
3931 | ||
3932 | lpfc_bsg_dma_page_free(phba, dmabuf); | |
3933 | ||
3934 | if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) { | |
3935 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3936 | "2965 SLI_CONFIG (hbd) ext-buffer rd mbox " | |
3937 | "command session done\n"); | |
3938 | lpfc_bsg_mbox_ext_session_reset(phba); | |
3939 | } | |
3940 | ||
3941 | job->reply->result = 0; | |
3942 | job->job_done(job); | |
3943 | ||
3944 | return SLI_CONFIG_HANDLED; | |
3945 | } | |
3946 | ||
3947 | /** | |
3948 | * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer | |
3949 | * @phba: Pointer to HBA context object. | |
3950 | * @dmabuf: Pointer to a DMA buffer descriptor. | |
3951 | * | |
3952 | * This routine sets up the next mailbox read external buffer obtained | |
3953 | * from user space through BSG. | |
3954 | **/ | |
3955 | static int | |
3956 | lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
3957 | struct lpfc_dmabuf *dmabuf) | |
3958 | { | |
3959 | struct lpfc_sli_config_mbox *sli_cfg_mbx; | |
3960 | struct bsg_job_data *dd_data = NULL; | |
3961 | LPFC_MBOXQ_t *pmboxq = NULL; | |
3962 | MAILBOX_t *pmb; | |
3963 | enum nemb_type nemb_tp; | |
3964 | uint8_t *pbuf; | |
3965 | uint32_t size; | |
3966 | uint32_t index; | |
3967 | int rc; | |
3968 | ||
3969 | index = phba->mbox_ext_buf_ctx.seqNum; | |
3970 | phba->mbox_ext_buf_ctx.seqNum++; | |
3971 | nemb_tp = phba->mbox_ext_buf_ctx.nembType; | |
3972 | ||
3973 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *) | |
3974 | phba->mbox_ext_buf_ctx.mbx_dmabuf->virt; | |
3975 | ||
3976 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
3977 | if (!dd_data) { | |
3978 | rc = -ENOMEM; | |
3979 | goto job_error; | |
3980 | } | |
3981 | ||
3982 | pbuf = (uint8_t *)dmabuf->virt; | |
3983 | size = job->request_payload.payload_len; | |
3984 | sg_copy_to_buffer(job->request_payload.sg_list, | |
3985 | job->request_payload.sg_cnt, | |
3986 | pbuf, size); | |
3987 | ||
3988 | if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) { | |
3989 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3990 | "2966 SLI_CONFIG (mse) ext-buffer wr set " | |
3991 | "buffer[%d], size:%d\n", | |
3992 | phba->mbox_ext_buf_ctx.seqNum, size); | |
3993 | ||
3994 | } else { | |
3995 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
3996 | "2967 SLI_CONFIG (hbd) ext-buffer wr set " | |
3997 | "buffer[%d], size:%d\n", | |
3998 | phba->mbox_ext_buf_ctx.seqNum, size); | |
3999 | ||
4000 | } | |
4001 | ||
4002 | /* set up external buffer descriptor and add to external buffer list */ | |
4003 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, index, | |
4004 | phba->mbox_ext_buf_ctx.mbx_dmabuf, | |
4005 | dmabuf); | |
4006 | list_add_tail(&dmabuf->list, &phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
4007 | ||
b76f2dc9 JS |
4008 | /* after write dma buffer */ |
4009 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType, | |
4010 | mbox_wr, dma_ebuf, sta_pos_addr, | |
4011 | dmabuf, index); | |
4012 | ||
7ad20aa9 JS |
4013 | if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) { |
4014 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
4015 | "2968 SLI_CONFIG ext-buffer wr all %d " | |
4016 | "ebuffers received\n", | |
4017 | phba->mbox_ext_buf_ctx.numBuf); | |
4018 | /* mailbox command structure for base driver */ | |
4019 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4020 | if (!pmboxq) { | |
4021 | rc = -ENOMEM; | |
4022 | goto job_error; | |
4023 | } | |
4024 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
4025 | pbuf = (uint8_t *)phba->mbox_ext_buf_ctx.mbx_dmabuf->virt; | |
4026 | pmb = &pmboxq->u.mb; | |
4027 | memcpy(pmb, pbuf, sizeof(*pmb)); | |
4028 | pmb->mbxOwner = OWN_HOST; | |
4029 | pmboxq->vport = phba->pport; | |
4030 | ||
4031 | /* callback for multi-buffer write mailbox command */ | |
4032 | pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl; | |
4033 | ||
4034 | /* context fields to callback function */ | |
4035 | pmboxq->context1 = dd_data; | |
4036 | dd_data->type = TYPE_MBOX; | |
4037 | dd_data->context_un.mbox.pmboxq = pmboxq; | |
4038 | dd_data->context_un.mbox.mb = (MAILBOX_t *)pbuf; | |
4039 | dd_data->context_un.mbox.set_job = job; | |
4040 | job->dd_data = dd_data; | |
4041 | ||
4042 | /* state change */ | |
4043 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT; | |
4044 | ||
4045 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
4046 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) { | |
4047 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
4048 | "2969 Issued SLI_CONFIG ext-buffer " | |
4049 | "maibox command, rc:x%x\n", rc); | |
88a2cfbb | 4050 | return SLI_CONFIG_HANDLED; |
7ad20aa9 JS |
4051 | } |
4052 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
4053 | "2970 Failed to issue SLI_CONFIG ext-buffer " | |
4054 | "maibox command, rc:x%x\n", rc); | |
4055 | rc = -EPIPE; | |
4056 | goto job_error; | |
4057 | } | |
4058 | ||
4059 | /* wait for additoinal external buffers */ | |
4060 | job->reply->result = 0; | |
4061 | job->job_done(job); | |
4062 | return SLI_CONFIG_HANDLED; | |
4063 | ||
4064 | job_error: | |
4065 | lpfc_bsg_dma_page_free(phba, dmabuf); | |
4066 | kfree(dd_data); | |
4067 | ||
4068 | return rc; | |
4069 | } | |
4070 | ||
4071 | /** | |
4072 | * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd | |
4073 | * @phba: Pointer to HBA context object. | |
4074 | * @mb: Pointer to a BSG mailbox object. | |
4075 | * @dmabuff: Pointer to a DMA buffer descriptor. | |
4076 | * | |
4077 | * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox | |
4078 | * command with multiple non-embedded external buffers. | |
4079 | **/ | |
4080 | static int | |
4081 | lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
4082 | struct lpfc_dmabuf *dmabuf) | |
4083 | { | |
4084 | int rc; | |
4085 | ||
4086 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
4087 | "2971 SLI_CONFIG buffer (type:x%x)\n", | |
4088 | phba->mbox_ext_buf_ctx.mboxType); | |
4089 | ||
4090 | if (phba->mbox_ext_buf_ctx.mboxType == mbox_rd) { | |
4091 | if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_DONE) { | |
4092 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
4093 | "2972 SLI_CONFIG rd buffer state " | |
4094 | "mismatch:x%x\n", | |
4095 | phba->mbox_ext_buf_ctx.state); | |
4096 | lpfc_bsg_mbox_ext_abort(phba); | |
4097 | return -EPIPE; | |
4098 | } | |
4099 | rc = lpfc_bsg_read_ebuf_get(phba, job); | |
4100 | if (rc == SLI_CONFIG_HANDLED) | |
4101 | lpfc_bsg_dma_page_free(phba, dmabuf); | |
4102 | } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */ | |
4103 | if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_HOST) { | |
4104 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
4105 | "2973 SLI_CONFIG wr buffer state " | |
4106 | "mismatch:x%x\n", | |
4107 | phba->mbox_ext_buf_ctx.state); | |
4108 | lpfc_bsg_mbox_ext_abort(phba); | |
4109 | return -EPIPE; | |
4110 | } | |
4111 | rc = lpfc_bsg_write_ebuf_set(phba, job, dmabuf); | |
7a470277 | 4112 | } |
7ad20aa9 | 4113 | return rc; |
3b5dd52a JS |
4114 | } |
4115 | ||
4116 | /** | |
7ad20aa9 | 4117 | * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer |
3b5dd52a | 4118 | * @phba: Pointer to HBA context object. |
7ad20aa9 JS |
4119 | * @mb: Pointer to a BSG mailbox object. |
4120 | * @dmabuff: Pointer to a DMA buffer descriptor. | |
3b5dd52a | 4121 | * |
7ad20aa9 JS |
4122 | * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG |
4123 | * (0x9B) mailbox commands and external buffers. | |
3b5dd52a | 4124 | **/ |
7ad20aa9 JS |
4125 | static int |
4126 | lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
4127 | struct lpfc_dmabuf *dmabuf) | |
3b5dd52a | 4128 | { |
7ad20aa9 | 4129 | struct dfc_mbox_req *mbox_req; |
88a2cfbb | 4130 | int rc = SLI_CONFIG_NOT_HANDLED; |
7ad20aa9 JS |
4131 | |
4132 | mbox_req = | |
4133 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; | |
4134 | ||
4135 | /* mbox command with/without single external buffer */ | |
4136 | if (mbox_req->extMboxTag == 0 && mbox_req->extSeqNum == 0) | |
88a2cfbb | 4137 | return rc; |
7ad20aa9 JS |
4138 | |
4139 | /* mbox command and first external buffer */ | |
4140 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) { | |
4141 | if (mbox_req->extSeqNum == 1) { | |
4142 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
4143 | "2974 SLI_CONFIG mailbox: tag:%d, " | |
4144 | "seq:%d\n", mbox_req->extMboxTag, | |
4145 | mbox_req->extSeqNum); | |
4146 | rc = lpfc_bsg_handle_sli_cfg_mbox(phba, job, dmabuf); | |
4147 | return rc; | |
4148 | } else | |
4149 | goto sli_cfg_ext_error; | |
3b5dd52a JS |
4150 | } |
4151 | ||
7ad20aa9 JS |
4152 | /* |
4153 | * handle additional external buffers | |
4154 | */ | |
4155 | ||
4156 | /* check broken pipe conditions */ | |
4157 | if (mbox_req->extMboxTag != phba->mbox_ext_buf_ctx.mbxTag) | |
4158 | goto sli_cfg_ext_error; | |
4159 | if (mbox_req->extSeqNum > phba->mbox_ext_buf_ctx.numBuf) | |
4160 | goto sli_cfg_ext_error; | |
4161 | if (mbox_req->extSeqNum != phba->mbox_ext_buf_ctx.seqNum + 1) | |
4162 | goto sli_cfg_ext_error; | |
4163 | ||
4164 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, | |
4165 | "2975 SLI_CONFIG mailbox external buffer: " | |
4166 | "extSta:x%x, tag:%d, seq:%d\n", | |
4167 | phba->mbox_ext_buf_ctx.state, mbox_req->extMboxTag, | |
4168 | mbox_req->extSeqNum); | |
4169 | rc = lpfc_bsg_handle_sli_cfg_ebuf(phba, job, dmabuf); | |
4170 | return rc; | |
4171 | ||
4172 | sli_cfg_ext_error: | |
4173 | /* all other cases, broken pipe */ | |
4174 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
4175 | "2976 SLI_CONFIG mailbox broken pipe: " | |
4176 | "ctxSta:x%x, ctxNumBuf:%d " | |
4177 | "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n", | |
4178 | phba->mbox_ext_buf_ctx.state, | |
4179 | phba->mbox_ext_buf_ctx.numBuf, | |
4180 | phba->mbox_ext_buf_ctx.mbxTag, | |
4181 | phba->mbox_ext_buf_ctx.seqNum, | |
4182 | mbox_req->extMboxTag, mbox_req->extSeqNum); | |
4183 | ||
4184 | lpfc_bsg_mbox_ext_session_reset(phba); | |
4185 | ||
4186 | return -EPIPE; | |
3b5dd52a JS |
4187 | } |
4188 | ||
4189 | /** | |
4190 | * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app | |
4191 | * @phba: Pointer to HBA context object. | |
4192 | * @mb: Pointer to a mailbox object. | |
4193 | * @vport: Pointer to a vport object. | |
4194 | * | |
4195 | * Allocate a tracking object, mailbox command memory, get a mailbox | |
4196 | * from the mailbox pool, copy the caller mailbox command. | |
4197 | * | |
4198 | * If offline and the sli is active we need to poll for the command (port is | |
4199 | * being reset) and com-plete the job, otherwise issue the mailbox command and | |
4200 | * let our completion handler finish the command. | |
4201 | **/ | |
4202 | static uint32_t | |
4203 | lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
4204 | struct lpfc_vport *vport) | |
4205 | { | |
7a470277 JS |
4206 | LPFC_MBOXQ_t *pmboxq = NULL; /* internal mailbox queue */ |
4207 | MAILBOX_t *pmb; /* shortcut to the pmboxq mailbox */ | |
4208 | /* a 4k buffer to hold the mb and extended data from/to the bsg */ | |
7ad20aa9 | 4209 | uint8_t *pmbx = NULL; |
7a470277 | 4210 | struct bsg_job_data *dd_data = NULL; /* bsg data tracking structure */ |
7ad20aa9 JS |
4211 | struct lpfc_dmabuf *dmabuf = NULL; |
4212 | struct dfc_mbox_req *mbox_req; | |
b6e3b9c6 JS |
4213 | struct READ_EVENT_LOG_VAR *rdEventLog; |
4214 | uint32_t transmit_length, receive_length, mode; | |
7ad20aa9 | 4215 | struct lpfc_mbx_sli4_config *sli4_config; |
b6e3b9c6 JS |
4216 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
4217 | struct mbox_header *header; | |
4218 | struct ulp_bde64 *bde; | |
7a470277 | 4219 | uint8_t *ext = NULL; |
3b5dd52a | 4220 | int rc = 0; |
7a470277 | 4221 | uint8_t *from; |
7ad20aa9 JS |
4222 | uint32_t size; |
4223 | ||
7a470277 JS |
4224 | |
4225 | /* in case no data is transferred */ | |
4226 | job->reply->reply_payload_rcv_len = 0; | |
4227 | ||
b6e3b9c6 JS |
4228 | /* sanity check to protect driver */ |
4229 | if (job->reply_payload.payload_len > BSG_MBOX_SIZE || | |
4230 | job->request_payload.payload_len > BSG_MBOX_SIZE) { | |
4231 | rc = -ERANGE; | |
4232 | goto job_done; | |
4233 | } | |
4234 | ||
7ad20aa9 JS |
4235 | /* |
4236 | * Don't allow mailbox commands to be sent when blocked or when in | |
4237 | * the middle of discovery | |
4238 | */ | |
4239 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { | |
4240 | rc = -EAGAIN; | |
4241 | goto job_done; | |
4242 | } | |
4243 | ||
4244 | mbox_req = | |
4245 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; | |
4246 | ||
7a470277 | 4247 | /* check if requested extended data lengths are valid */ |
b6e3b9c6 JS |
4248 | if ((mbox_req->inExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t)) || |
4249 | (mbox_req->outExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t))) { | |
7a470277 JS |
4250 | rc = -ERANGE; |
4251 | goto job_done; | |
4252 | } | |
3b5dd52a | 4253 | |
7ad20aa9 JS |
4254 | dmabuf = lpfc_bsg_dma_page_alloc(phba); |
4255 | if (!dmabuf || !dmabuf->virt) { | |
4256 | rc = -ENOMEM; | |
4257 | goto job_done; | |
4258 | } | |
4259 | ||
4260 | /* Get the mailbox command or external buffer from BSG */ | |
4261 | pmbx = (uint8_t *)dmabuf->virt; | |
4262 | size = job->request_payload.payload_len; | |
4263 | sg_copy_to_buffer(job->request_payload.sg_list, | |
4264 | job->request_payload.sg_cnt, pmbx, size); | |
4265 | ||
4266 | /* Handle possible SLI_CONFIG with non-embedded payloads */ | |
4267 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
4268 | rc = lpfc_bsg_handle_sli_cfg_ext(phba, job, dmabuf); | |
4269 | if (rc == SLI_CONFIG_HANDLED) | |
4270 | goto job_cont; | |
4271 | if (rc) | |
4272 | goto job_done; | |
4273 | /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */ | |
4274 | } | |
4275 | ||
4276 | rc = lpfc_bsg_check_cmd_access(phba, (MAILBOX_t *)pmbx, vport); | |
4277 | if (rc != 0) | |
4278 | goto job_done; /* must be negative */ | |
4279 | ||
3b5dd52a JS |
4280 | /* allocate our bsg tracking structure */ |
4281 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
4282 | if (!dd_data) { | |
4283 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
4284 | "2727 Failed allocation of dd_data\n"); | |
7a470277 JS |
4285 | rc = -ENOMEM; |
4286 | goto job_done; | |
3b5dd52a JS |
4287 | } |
4288 | ||
3b5dd52a JS |
4289 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4290 | if (!pmboxq) { | |
7a470277 JS |
4291 | rc = -ENOMEM; |
4292 | goto job_done; | |
3b5dd52a | 4293 | } |
7a470277 | 4294 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
3b5dd52a | 4295 | |
3b5dd52a | 4296 | pmb = &pmboxq->u.mb; |
7ad20aa9 | 4297 | memcpy(pmb, pmbx, sizeof(*pmb)); |
3b5dd52a | 4298 | pmb->mbxOwner = OWN_HOST; |
3b5dd52a JS |
4299 | pmboxq->vport = vport; |
4300 | ||
c7495937 JS |
4301 | /* If HBA encountered an error attention, allow only DUMP |
4302 | * or RESTART mailbox commands until the HBA is restarted. | |
4303 | */ | |
4304 | if (phba->pport->stopped && | |
4305 | pmb->mbxCommand != MBX_DUMP_MEMORY && | |
4306 | pmb->mbxCommand != MBX_RESTART && | |
4307 | pmb->mbxCommand != MBX_WRITE_VPARMS && | |
4308 | pmb->mbxCommand != MBX_WRITE_WWN) | |
4309 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
4310 | "2797 mbox: Issued mailbox cmd " | |
4311 | "0x%x while in stopped state.\n", | |
4312 | pmb->mbxCommand); | |
4313 | ||
7a470277 | 4314 | /* extended mailbox commands will need an extended buffer */ |
c7495937 | 4315 | if (mbox_req->inExtWLen || mbox_req->outExtWLen) { |
026abb87 JS |
4316 | from = pmbx; |
4317 | ext = from + sizeof(MAILBOX_t); | |
7a470277 JS |
4318 | pmboxq->context2 = ext; |
4319 | pmboxq->in_ext_byte_len = | |
4320 | mbox_req->inExtWLen * sizeof(uint32_t); | |
4321 | pmboxq->out_ext_byte_len = | |
c7495937 | 4322 | mbox_req->outExtWLen * sizeof(uint32_t); |
7a470277 JS |
4323 | pmboxq->mbox_offset_word = mbox_req->mbOffset; |
4324 | } | |
4325 | ||
4326 | /* biu diag will need a kernel buffer to transfer the data | |
4327 | * allocate our own buffer and setup the mailbox command to | |
4328 | * use ours | |
4329 | */ | |
4330 | if (pmb->mbxCommand == MBX_RUN_BIU_DIAG64) { | |
b6e3b9c6 JS |
4331 | transmit_length = pmb->un.varWords[1]; |
4332 | receive_length = pmb->un.varWords[4]; | |
c7495937 JS |
4333 | /* transmit length cannot be greater than receive length or |
4334 | * mailbox extension size | |
4335 | */ | |
4336 | if ((transmit_length > receive_length) || | |
88a2cfbb | 4337 | (transmit_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t))) { |
c7495937 JS |
4338 | rc = -ERANGE; |
4339 | goto job_done; | |
4340 | } | |
7a470277 | 4341 | pmb->un.varBIUdiag.un.s2.xmit_bde64.addrHigh = |
7ad20aa9 | 4342 | putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t)); |
7a470277 | 4343 | pmb->un.varBIUdiag.un.s2.xmit_bde64.addrLow = |
7ad20aa9 | 4344 | putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t)); |
7a470277 JS |
4345 | |
4346 | pmb->un.varBIUdiag.un.s2.rcv_bde64.addrHigh = | |
7ad20aa9 JS |
4347 | putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t) |
4348 | + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize); | |
7a470277 | 4349 | pmb->un.varBIUdiag.un.s2.rcv_bde64.addrLow = |
7ad20aa9 JS |
4350 | putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t) |
4351 | + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize); | |
c7495937 | 4352 | } else if (pmb->mbxCommand == MBX_READ_EVENT_LOG) { |
b6e3b9c6 JS |
4353 | rdEventLog = &pmb->un.varRdEventLog; |
4354 | receive_length = rdEventLog->rcv_bde64.tus.f.bdeSize; | |
4355 | mode = bf_get(lpfc_event_log, rdEventLog); | |
c7495937 JS |
4356 | |
4357 | /* receive length cannot be greater than mailbox | |
4358 | * extension size | |
4359 | */ | |
88a2cfbb | 4360 | if (receive_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t)) { |
c7495937 JS |
4361 | rc = -ERANGE; |
4362 | goto job_done; | |
4363 | } | |
4364 | ||
4365 | /* mode zero uses a bde like biu diags command */ | |
4366 | if (mode == 0) { | |
7ad20aa9 JS |
4367 | pmb->un.varWords[3] = putPaddrLow(dmabuf->phys |
4368 | + sizeof(MAILBOX_t)); | |
4369 | pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys | |
4370 | + sizeof(MAILBOX_t)); | |
c7495937 JS |
4371 | } |
4372 | } else if (phba->sli_rev == LPFC_SLI_REV4) { | |
4373 | if (pmb->mbxCommand == MBX_DUMP_MEMORY) { | |
4374 | /* rebuild the command for sli4 using our own buffers | |
4375 | * like we do for biu diags | |
4376 | */ | |
b6e3b9c6 | 4377 | receive_length = pmb->un.varWords[2]; |
c7495937 JS |
4378 | /* receive length cannot be greater than mailbox |
4379 | * extension size | |
4380 | */ | |
7ad20aa9 | 4381 | if (receive_length == 0) { |
c7495937 JS |
4382 | rc = -ERANGE; |
4383 | goto job_done; | |
4384 | } | |
7ad20aa9 JS |
4385 | pmb->un.varWords[3] = putPaddrLow(dmabuf->phys |
4386 | + sizeof(MAILBOX_t)); | |
4387 | pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys | |
4388 | + sizeof(MAILBOX_t)); | |
c7495937 JS |
4389 | } else if ((pmb->mbxCommand == MBX_UPDATE_CFG) && |
4390 | pmb->un.varUpdateCfg.co) { | |
b6e3b9c6 | 4391 | bde = (struct ulp_bde64 *)&pmb->un.varWords[4]; |
c7495937 JS |
4392 | |
4393 | /* bde size cannot be greater than mailbox ext size */ | |
88a2cfbb JS |
4394 | if (bde->tus.f.bdeSize > |
4395 | BSG_MBOX_SIZE - sizeof(MAILBOX_t)) { | |
c7495937 JS |
4396 | rc = -ERANGE; |
4397 | goto job_done; | |
4398 | } | |
7ad20aa9 JS |
4399 | bde->addrHigh = putPaddrHigh(dmabuf->phys |
4400 | + sizeof(MAILBOX_t)); | |
4401 | bde->addrLow = putPaddrLow(dmabuf->phys | |
4402 | + sizeof(MAILBOX_t)); | |
515e0aa2 | 4403 | } else if (pmb->mbxCommand == MBX_SLI4_CONFIG) { |
7ad20aa9 JS |
4404 | /* Handling non-embedded SLI_CONFIG mailbox command */ |
4405 | sli4_config = &pmboxq->u.mqe.un.sli4_config; | |
4406 | if (!bf_get(lpfc_mbox_hdr_emb, | |
4407 | &sli4_config->header.cfg_mhdr)) { | |
4408 | /* rebuild the command for sli4 using our | |
4409 | * own buffers like we do for biu diags | |
4410 | */ | |
4411 | header = (struct mbox_header *) | |
4412 | &pmb->un.varWords[0]; | |
4413 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) | |
4414 | &pmb->un.varWords[0]; | |
4415 | receive_length = nembed_sge->sge[0].length; | |
4416 | ||
4417 | /* receive length cannot be greater than | |
4418 | * mailbox extension size | |
4419 | */ | |
4420 | if ((receive_length == 0) || | |
88a2cfbb JS |
4421 | (receive_length > |
4422 | BSG_MBOX_SIZE - sizeof(MAILBOX_t))) { | |
7ad20aa9 JS |
4423 | rc = -ERANGE; |
4424 | goto job_done; | |
4425 | } | |
515e0aa2 | 4426 | |
7ad20aa9 JS |
4427 | nembed_sge->sge[0].pa_hi = |
4428 | putPaddrHigh(dmabuf->phys | |
4429 | + sizeof(MAILBOX_t)); | |
4430 | nembed_sge->sge[0].pa_lo = | |
4431 | putPaddrLow(dmabuf->phys | |
4432 | + sizeof(MAILBOX_t)); | |
515e0aa2 | 4433 | } |
c7495937 | 4434 | } |
7a470277 JS |
4435 | } |
4436 | ||
7ad20aa9 | 4437 | dd_data->context_un.mbox.dmabuffers = dmabuf; |
c7495937 | 4438 | |
7a470277 | 4439 | /* setup wake call as IOCB callback */ |
7ad20aa9 | 4440 | pmboxq->mbox_cmpl = lpfc_bsg_issue_mbox_cmpl; |
7a470277 JS |
4441 | |
4442 | /* setup context field to pass wait_queue pointer to wake function */ | |
4443 | pmboxq->context1 = dd_data; | |
4444 | dd_data->type = TYPE_MBOX; | |
4445 | dd_data->context_un.mbox.pmboxq = pmboxq; | |
7ad20aa9 | 4446 | dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx; |
7a470277 JS |
4447 | dd_data->context_un.mbox.set_job = job; |
4448 | dd_data->context_un.mbox.ext = ext; | |
4449 | dd_data->context_un.mbox.mbOffset = mbox_req->mbOffset; | |
4450 | dd_data->context_un.mbox.inExtWLen = mbox_req->inExtWLen; | |
c7495937 | 4451 | dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen; |
7a470277 JS |
4452 | job->dd_data = dd_data; |
4453 | ||
3b5dd52a JS |
4454 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
4455 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) { | |
4456 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | |
4457 | if (rc != MBX_SUCCESS) { | |
7a470277 JS |
4458 | rc = (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
4459 | goto job_done; | |
3b5dd52a JS |
4460 | } |
4461 | ||
7a470277 | 4462 | /* job finished, copy the data */ |
7ad20aa9 | 4463 | memcpy(pmbx, pmb, sizeof(*pmb)); |
3b5dd52a JS |
4464 | job->reply->reply_payload_rcv_len = |
4465 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
7ad20aa9 JS |
4466 | job->reply_payload.sg_cnt, |
4467 | pmbx, size); | |
3b5dd52a | 4468 | /* not waiting mbox already done */ |
7a470277 JS |
4469 | rc = 0; |
4470 | goto job_done; | |
3b5dd52a JS |
4471 | } |
4472 | ||
3b5dd52a | 4473 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
7a470277 JS |
4474 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) |
4475 | return 1; /* job started */ | |
4476 | ||
4477 | job_done: | |
4478 | /* common exit for error or job completed inline */ | |
7a470277 | 4479 | if (pmboxq) |
3b5dd52a | 4480 | mempool_free(pmboxq, phba->mbox_mem_pool); |
7ad20aa9 | 4481 | lpfc_bsg_dma_page_free(phba, dmabuf); |
7a470277 | 4482 | kfree(dd_data); |
3b5dd52a | 4483 | |
7ad20aa9 | 4484 | job_cont: |
7a470277 | 4485 | return rc; |
3b5dd52a JS |
4486 | } |
4487 | ||
4488 | /** | |
4489 | * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command | |
4490 | * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX. | |
4491 | **/ | |
4492 | static int | |
4493 | lpfc_bsg_mbox_cmd(struct fc_bsg_job *job) | |
4494 | { | |
4495 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
4496 | struct lpfc_hba *phba = vport->phba; | |
7ad20aa9 | 4497 | struct dfc_mbox_req *mbox_req; |
3b5dd52a JS |
4498 | int rc = 0; |
4499 | ||
7ad20aa9 | 4500 | /* mix-and-match backward compatibility */ |
3b5dd52a JS |
4501 | job->reply->reply_payload_rcv_len = 0; |
4502 | if (job->request_len < | |
4503 | sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) { | |
7ad20aa9 JS |
4504 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
4505 | "2737 Mix-and-match backward compability " | |
4506 | "between MBOX_REQ old size:%d and " | |
4507 | "new request size:%d\n", | |
4508 | (int)(job->request_len - | |
4509 | sizeof(struct fc_bsg_request)), | |
4510 | (int)sizeof(struct dfc_mbox_req)); | |
4511 | mbox_req = (struct dfc_mbox_req *) | |
4512 | job->request->rqst_data.h_vendor.vendor_cmd; | |
4513 | mbox_req->extMboxTag = 0; | |
4514 | mbox_req->extSeqNum = 0; | |
3b5dd52a JS |
4515 | } |
4516 | ||
4517 | rc = lpfc_bsg_issue_mbox(phba, job, vport); | |
4518 | ||
3b5dd52a JS |
4519 | if (rc == 0) { |
4520 | /* job done */ | |
4521 | job->reply->result = 0; | |
4522 | job->dd_data = NULL; | |
4523 | job->job_done(job); | |
4524 | } else if (rc == 1) | |
4525 | /* job submitted, will complete later*/ | |
4526 | rc = 0; /* return zero, no error */ | |
4527 | else { | |
4528 | /* some error occurred */ | |
4529 | job->reply->result = rc; | |
4530 | job->dd_data = NULL; | |
4531 | } | |
4532 | ||
4533 | return rc; | |
4534 | } | |
4535 | ||
e2aed29f JS |
4536 | /** |
4537 | * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler | |
4538 | * @phba: Pointer to HBA context object. | |
4539 | * @cmdiocbq: Pointer to command iocb. | |
4540 | * @rspiocbq: Pointer to response iocb. | |
4541 | * | |
4542 | * This function is the completion handler for iocbs issued using | |
4543 | * lpfc_menlo_cmd function. This function is called by the | |
4544 | * ring event handler function without any lock held. This function | |
4545 | * can be called from both worker thread context and interrupt | |
4546 | * context. This function also can be called from another thread which | |
4547 | * cleans up the SLI layer objects. | |
4548 | * This function copies the contents of the response iocb to the | |
4549 | * response iocb memory object provided by the caller of | |
4550 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
4551 | * sleeps for the iocb completion. | |
4552 | **/ | |
4553 | static void | |
4554 | lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba *phba, | |
4555 | struct lpfc_iocbq *cmdiocbq, | |
4556 | struct lpfc_iocbq *rspiocbq) | |
4557 | { | |
4558 | struct bsg_job_data *dd_data; | |
4559 | struct fc_bsg_job *job; | |
4560 | IOCB_t *rsp; | |
4561 | struct lpfc_dmabuf *bmp; | |
4562 | struct lpfc_bsg_menlo *menlo; | |
4563 | unsigned long flags; | |
4564 | struct menlo_response *menlo_resp; | |
4565 | int rc = 0; | |
4566 | ||
4567 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
4568 | dd_data = cmdiocbq->context1; | |
4569 | if (!dd_data) { | |
4570 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4571 | return; | |
4572 | } | |
4573 | ||
4574 | menlo = &dd_data->context_un.menlo; | |
4575 | job = menlo->set_job; | |
4576 | job->dd_data = NULL; /* so timeout handler does not reply */ | |
4577 | ||
5989b8d4 | 4578 | spin_lock(&phba->hbalock); |
e2aed29f JS |
4579 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
4580 | if (cmdiocbq->context2 && rspiocbq) | |
4581 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
4582 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
5989b8d4 | 4583 | spin_unlock(&phba->hbalock); |
e2aed29f JS |
4584 | |
4585 | bmp = menlo->bmp; | |
4586 | rspiocbq = menlo->rspiocbq; | |
4587 | rsp = &rspiocbq->iocb; | |
4588 | ||
4589 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
4590 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
4591 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
4592 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
4593 | ||
4594 | /* always return the xri, this would be used in the case | |
4595 | * of a menlo download to allow the data to be sent as a continuation | |
4596 | * of the exchange. | |
4597 | */ | |
4598 | menlo_resp = (struct menlo_response *) | |
4599 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
4600 | menlo_resp->xri = rsp->ulpContext; | |
4601 | if (rsp->ulpStatus) { | |
4602 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
4603 | switch (rsp->un.ulpWord[4] & 0xff) { | |
4604 | case IOERR_SEQUENCE_TIMEOUT: | |
4605 | rc = -ETIMEDOUT; | |
4606 | break; | |
4607 | case IOERR_INVALID_RPI: | |
4608 | rc = -EFAULT; | |
4609 | break; | |
4610 | default: | |
4611 | rc = -EACCES; | |
4612 | break; | |
4613 | } | |
4614 | } else | |
4615 | rc = -EACCES; | |
4616 | } else | |
4617 | job->reply->reply_payload_rcv_len = | |
4618 | rsp->un.genreq64.bdl.bdeSize; | |
4619 | ||
4620 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
4621 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
4622 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
4623 | kfree(bmp); | |
4624 | kfree(dd_data); | |
4625 | /* make error code available to userspace */ | |
4626 | job->reply->result = rc; | |
4627 | /* complete the job back to userspace */ | |
4628 | job->job_done(job); | |
4629 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4630 | return; | |
4631 | } | |
4632 | ||
4633 | /** | |
4634 | * lpfc_menlo_cmd - send an ioctl for menlo hardware | |
4635 | * @job: fc_bsg_job to handle | |
4636 | * | |
4637 | * This function issues a gen request 64 CR ioctl for all menlo cmd requests, | |
4638 | * all the command completions will return the xri for the command. | |
4639 | * For menlo data requests a gen request 64 CX is used to continue the exchange | |
4640 | * supplied in the menlo request header xri field. | |
4641 | **/ | |
4642 | static int | |
4643 | lpfc_menlo_cmd(struct fc_bsg_job *job) | |
4644 | { | |
4645 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
4646 | struct lpfc_hba *phba = vport->phba; | |
4647 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; | |
4648 | IOCB_t *cmd, *rsp; | |
4649 | int rc = 0; | |
4650 | struct menlo_command *menlo_cmd; | |
4651 | struct menlo_response *menlo_resp; | |
4652 | struct lpfc_dmabuf *bmp = NULL; | |
4653 | int request_nseg; | |
4654 | int reply_nseg; | |
4655 | struct scatterlist *sgel = NULL; | |
4656 | int numbde; | |
4657 | dma_addr_t busaddr; | |
4658 | struct bsg_job_data *dd_data; | |
4659 | struct ulp_bde64 *bpl = NULL; | |
4660 | ||
4661 | /* in case no data is returned return just the return code */ | |
4662 | job->reply->reply_payload_rcv_len = 0; | |
4663 | ||
4664 | if (job->request_len < | |
4665 | sizeof(struct fc_bsg_request) + | |
4666 | sizeof(struct menlo_command)) { | |
4667 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
4668 | "2784 Received MENLO_CMD request below " | |
4669 | "minimum size\n"); | |
4670 | rc = -ERANGE; | |
4671 | goto no_dd_data; | |
4672 | } | |
4673 | ||
4674 | if (job->reply_len < | |
4675 | sizeof(struct fc_bsg_request) + sizeof(struct menlo_response)) { | |
4676 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
4677 | "2785 Received MENLO_CMD reply below " | |
4678 | "minimum size\n"); | |
4679 | rc = -ERANGE; | |
4680 | goto no_dd_data; | |
4681 | } | |
4682 | ||
4683 | if (!(phba->menlo_flag & HBA_MENLO_SUPPORT)) { | |
4684 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
4685 | "2786 Adapter does not support menlo " | |
4686 | "commands\n"); | |
4687 | rc = -EPERM; | |
4688 | goto no_dd_data; | |
4689 | } | |
4690 | ||
4691 | menlo_cmd = (struct menlo_command *) | |
4692 | job->request->rqst_data.h_vendor.vendor_cmd; | |
4693 | ||
4694 | menlo_resp = (struct menlo_response *) | |
4695 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
4696 | ||
4697 | /* allocate our bsg tracking structure */ | |
4698 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
4699 | if (!dd_data) { | |
4700 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
4701 | "2787 Failed allocation of dd_data\n"); | |
4702 | rc = -ENOMEM; | |
4703 | goto no_dd_data; | |
4704 | } | |
4705 | ||
4706 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
4707 | if (!bmp) { | |
4708 | rc = -ENOMEM; | |
4709 | goto free_dd; | |
4710 | } | |
4711 | ||
4712 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
4713 | if (!cmdiocbq) { | |
4714 | rc = -ENOMEM; | |
4715 | goto free_bmp; | |
4716 | } | |
4717 | ||
4718 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
4719 | if (!rspiocbq) { | |
4720 | rc = -ENOMEM; | |
4721 | goto free_cmdiocbq; | |
4722 | } | |
4723 | ||
4724 | rsp = &rspiocbq->iocb; | |
4725 | ||
4726 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); | |
4727 | if (!bmp->virt) { | |
4728 | rc = -ENOMEM; | |
4729 | goto free_rspiocbq; | |
4730 | } | |
4731 | ||
4732 | INIT_LIST_HEAD(&bmp->list); | |
4733 | bpl = (struct ulp_bde64 *) bmp->virt; | |
4734 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, | |
4735 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
4736 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { | |
4737 | busaddr = sg_dma_address(sgel); | |
4738 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
4739 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
4740 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
4741 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
4742 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
4743 | bpl++; | |
4744 | } | |
4745 | ||
4746 | reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list, | |
4747 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
4748 | for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) { | |
4749 | busaddr = sg_dma_address(sgel); | |
4750 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
4751 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
4752 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
4753 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
4754 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
4755 | bpl++; | |
4756 | } | |
4757 | ||
4758 | cmd = &cmdiocbq->iocb; | |
4759 | cmd->un.genreq64.bdl.ulpIoTag32 = 0; | |
4760 | cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
4761 | cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
4762 | cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
4763 | cmd->un.genreq64.bdl.bdeSize = | |
4764 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); | |
4765 | cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); | |
4766 | cmd->un.genreq64.w5.hcsw.Dfctl = 0; | |
4767 | cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CMD; | |
4768 | cmd->un.genreq64.w5.hcsw.Type = MENLO_TRANSPORT_TYPE; /* 0xfe */ | |
4769 | cmd->ulpBdeCount = 1; | |
4770 | cmd->ulpClass = CLASS3; | |
4771 | cmd->ulpOwner = OWN_CHIP; | |
4772 | cmd->ulpLe = 1; /* Limited Edition */ | |
4773 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
4774 | cmdiocbq->vport = phba->pport; | |
4775 | /* We want the firmware to timeout before we do */ | |
4776 | cmd->ulpTimeout = MENLO_TIMEOUT - 5; | |
4777 | cmdiocbq->context3 = bmp; | |
4778 | cmdiocbq->context2 = rspiocbq; | |
4779 | cmdiocbq->iocb_cmpl = lpfc_bsg_menlo_cmd_cmp; | |
4780 | cmdiocbq->context1 = dd_data; | |
4781 | cmdiocbq->context2 = rspiocbq; | |
4782 | if (menlo_cmd->cmd == LPFC_BSG_VENDOR_MENLO_CMD) { | |
4783 | cmd->ulpCommand = CMD_GEN_REQUEST64_CR; | |
4784 | cmd->ulpPU = MENLO_PU; /* 3 */ | |
4785 | cmd->un.ulpWord[4] = MENLO_DID; /* 0x0000FC0E */ | |
4786 | cmd->ulpContext = MENLO_CONTEXT; /* 0 */ | |
4787 | } else { | |
4788 | cmd->ulpCommand = CMD_GEN_REQUEST64_CX; | |
4789 | cmd->ulpPU = 1; | |
4790 | cmd->un.ulpWord[4] = 0; | |
4791 | cmd->ulpContext = menlo_cmd->xri; | |
4792 | } | |
4793 | ||
4794 | dd_data->type = TYPE_MENLO; | |
4795 | dd_data->context_un.menlo.cmdiocbq = cmdiocbq; | |
4796 | dd_data->context_un.menlo.rspiocbq = rspiocbq; | |
4797 | dd_data->context_un.menlo.set_job = job; | |
4798 | dd_data->context_un.menlo.bmp = bmp; | |
4799 | ||
4800 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, | |
4801 | MENLO_TIMEOUT - 5); | |
4802 | if (rc == IOCB_SUCCESS) | |
4803 | return 0; /* done for now */ | |
4804 | ||
4805 | /* iocb failed so cleanup */ | |
4806 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
4807 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
4808 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
4809 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
4810 | ||
4811 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
4812 | ||
4813 | free_rspiocbq: | |
4814 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
4815 | free_cmdiocbq: | |
4816 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
4817 | free_bmp: | |
4818 | kfree(bmp); | |
4819 | free_dd: | |
4820 | kfree(dd_data); | |
4821 | no_dd_data: | |
4822 | /* make error code available to userspace */ | |
4823 | job->reply->result = rc; | |
4824 | job->dd_data = NULL; | |
4825 | return rc; | |
4826 | } | |
b6e3b9c6 | 4827 | |
3b5dd52a JS |
4828 | /** |
4829 | * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job | |
4830 | * @job: fc_bsg_job to handle | |
4831 | **/ | |
4832 | static int | |
4833 | lpfc_bsg_hst_vendor(struct fc_bsg_job *job) | |
4834 | { | |
4835 | int command = job->request->rqst_data.h_vendor.vendor_cmd[0]; | |
4836 | int rc; | |
4837 | ||
4838 | switch (command) { | |
4839 | case LPFC_BSG_VENDOR_SET_CT_EVENT: | |
4840 | rc = lpfc_bsg_hba_set_event(job); | |
4841 | break; | |
4842 | case LPFC_BSG_VENDOR_GET_CT_EVENT: | |
4843 | rc = lpfc_bsg_hba_get_event(job); | |
4844 | break; | |
4845 | case LPFC_BSG_VENDOR_SEND_MGMT_RESP: | |
4846 | rc = lpfc_bsg_send_mgmt_rsp(job); | |
4847 | break; | |
4848 | case LPFC_BSG_VENDOR_DIAG_MODE: | |
7ad20aa9 JS |
4849 | rc = lpfc_bsg_diag_loopback_mode(job); |
4850 | break; | |
4851 | case LPFC_BSG_VENDOR_DIAG_MODE_END: | |
4852 | rc = lpfc_sli4_bsg_diag_mode_end(job); | |
4853 | break; | |
4854 | case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK: | |
4855 | rc = lpfc_bsg_diag_loopback_run(job); | |
3b5dd52a | 4856 | break; |
7ad20aa9 JS |
4857 | case LPFC_BSG_VENDOR_LINK_DIAG_TEST: |
4858 | rc = lpfc_sli4_bsg_link_diag_test(job); | |
3b5dd52a JS |
4859 | break; |
4860 | case LPFC_BSG_VENDOR_GET_MGMT_REV: | |
4861 | rc = lpfc_bsg_get_dfc_rev(job); | |
4862 | break; | |
4863 | case LPFC_BSG_VENDOR_MBOX: | |
4864 | rc = lpfc_bsg_mbox_cmd(job); | |
4865 | break; | |
e2aed29f JS |
4866 | case LPFC_BSG_VENDOR_MENLO_CMD: |
4867 | case LPFC_BSG_VENDOR_MENLO_DATA: | |
4868 | rc = lpfc_menlo_cmd(job); | |
4869 | break; | |
3b5dd52a JS |
4870 | default: |
4871 | rc = -EINVAL; | |
4872 | job->reply->reply_payload_rcv_len = 0; | |
4873 | /* make error code available to userspace */ | |
4874 | job->reply->result = rc; | |
4875 | break; | |
4876 | } | |
4877 | ||
4878 | return rc; | |
4879 | } | |
4880 | ||
4881 | /** | |
4882 | * lpfc_bsg_request - handle a bsg request from the FC transport | |
4883 | * @job: fc_bsg_job to handle | |
4884 | **/ | |
4885 | int | |
4886 | lpfc_bsg_request(struct fc_bsg_job *job) | |
4887 | { | |
4888 | uint32_t msgcode; | |
4889 | int rc; | |
4890 | ||
4891 | msgcode = job->request->msgcode; | |
4892 | switch (msgcode) { | |
4893 | case FC_BSG_HST_VENDOR: | |
4894 | rc = lpfc_bsg_hst_vendor(job); | |
4895 | break; | |
4896 | case FC_BSG_RPT_ELS: | |
4897 | rc = lpfc_bsg_rport_els(job); | |
4898 | break; | |
4899 | case FC_BSG_RPT_CT: | |
4900 | rc = lpfc_bsg_send_mgmt_cmd(job); | |
4901 | break; | |
4902 | default: | |
4903 | rc = -EINVAL; | |
4904 | job->reply->reply_payload_rcv_len = 0; | |
4905 | /* make error code available to userspace */ | |
4906 | job->reply->result = rc; | |
4907 | break; | |
4908 | } | |
4909 | ||
4910 | return rc; | |
4911 | } | |
4912 | ||
4913 | /** | |
4914 | * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport | |
4915 | * @job: fc_bsg_job that has timed out | |
4916 | * | |
4917 | * This function just aborts the job's IOCB. The aborted IOCB will return to | |
4918 | * the waiting function which will handle passing the error back to userspace | |
4919 | **/ | |
4920 | int | |
4921 | lpfc_bsg_timeout(struct fc_bsg_job *job) | |
4922 | { | |
4923 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
4924 | struct lpfc_hba *phba = vport->phba; | |
4925 | struct lpfc_iocbq *cmdiocb; | |
4926 | struct lpfc_bsg_event *evt; | |
4927 | struct lpfc_bsg_iocb *iocb; | |
4928 | struct lpfc_bsg_mbox *mbox; | |
e2aed29f | 4929 | struct lpfc_bsg_menlo *menlo; |
3b5dd52a JS |
4930 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
4931 | struct bsg_job_data *dd_data; | |
4932 | unsigned long flags; | |
4933 | ||
4934 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
4935 | dd_data = (struct bsg_job_data *)job->dd_data; | |
4936 | /* timeout and completion crossed paths if no dd_data */ | |
4937 | if (!dd_data) { | |
4938 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4939 | return 0; | |
4cc0e56e JS |
4940 | } |
4941 | ||
4942 | switch (dd_data->type) { | |
4943 | case TYPE_IOCB: | |
4944 | iocb = &dd_data->context_un.iocb; | |
4945 | cmdiocb = iocb->cmdiocbq; | |
4946 | /* hint to completion handler that the job timed out */ | |
4947 | job->reply->result = -EAGAIN; | |
4948 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4949 | /* this will call our completion handler */ | |
4950 | spin_lock_irq(&phba->hbalock); | |
f1c3b0fc | 4951 | lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); |
4cc0e56e JS |
4952 | spin_unlock_irq(&phba->hbalock); |
4953 | break; | |
4954 | case TYPE_EVT: | |
4955 | evt = dd_data->context_un.evt; | |
4956 | /* this event has no job anymore */ | |
4957 | evt->set_job = NULL; | |
4958 | job->dd_data = NULL; | |
4959 | job->reply->reply_payload_rcv_len = 0; | |
4960 | /* Return -EAGAIN which is our way of signallying the | |
4961 | * app to retry. | |
4962 | */ | |
4963 | job->reply->result = -EAGAIN; | |
4964 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4965 | job->job_done(job); | |
4966 | break; | |
3b5dd52a JS |
4967 | case TYPE_MBOX: |
4968 | mbox = &dd_data->context_un.mbox; | |
4969 | /* this mbox has no job anymore */ | |
4970 | mbox->set_job = NULL; | |
4971 | job->dd_data = NULL; | |
4972 | job->reply->reply_payload_rcv_len = 0; | |
4973 | job->reply->result = -EAGAIN; | |
7a470277 | 4974 | /* the mbox completion handler can now be run */ |
3b5dd52a JS |
4975 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4976 | job->job_done(job); | |
7ad20aa9 JS |
4977 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT) |
4978 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS; | |
3b5dd52a | 4979 | break; |
e2aed29f JS |
4980 | case TYPE_MENLO: |
4981 | menlo = &dd_data->context_un.menlo; | |
4982 | cmdiocb = menlo->cmdiocbq; | |
4983 | /* hint to completion handler that the job timed out */ | |
4984 | job->reply->result = -EAGAIN; | |
4985 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4986 | /* this will call our completion handler */ | |
4987 | spin_lock_irq(&phba->hbalock); | |
4988 | lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); | |
4989 | spin_unlock_irq(&phba->hbalock); | |
4990 | break; | |
4cc0e56e JS |
4991 | default: |
4992 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
4993 | break; | |
4994 | } | |
f1c3b0fc | 4995 | |
4cc0e56e JS |
4996 | /* scsi transport fc fc_bsg_job_timeout expects a zero return code, |
4997 | * otherwise an error message will be displayed on the console | |
4998 | * so always return success (zero) | |
4999 | */ | |
f1c3b0fc JS |
5000 | return 0; |
5001 | } |