Commit | Line | Data |
---|---|---|
f1c3b0fc JS |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
3 | * Fibre Channel Host Bus Adapters. * | |
4fede78f | 4 | * Copyright (C) 2009-2010 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> |
f1c3b0fc JS |
26 | |
27 | #include <scsi/scsi.h> | |
28 | #include <scsi/scsi_host.h> | |
29 | #include <scsi/scsi_transport_fc.h> | |
30 | #include <scsi/scsi_bsg_fc.h> | |
6a9c52cf | 31 | #include <scsi/fc/fc_fs.h> |
f1c3b0fc JS |
32 | |
33 | #include "lpfc_hw4.h" | |
34 | #include "lpfc_hw.h" | |
35 | #include "lpfc_sli.h" | |
36 | #include "lpfc_sli4.h" | |
37 | #include "lpfc_nl.h" | |
4fede78f | 38 | #include "lpfc_bsg.h" |
f1c3b0fc JS |
39 | #include "lpfc_disc.h" |
40 | #include "lpfc_scsi.h" | |
41 | #include "lpfc.h" | |
42 | #include "lpfc_logmsg.h" | |
43 | #include "lpfc_crtn.h" | |
44 | #include "lpfc_vport.h" | |
45 | #include "lpfc_version.h" | |
46 | ||
4cc0e56e JS |
47 | struct lpfc_bsg_event { |
48 | struct list_head node; | |
49 | struct kref kref; | |
50 | wait_queue_head_t wq; | |
51 | ||
52 | /* Event type and waiter identifiers */ | |
53 | uint32_t type_mask; | |
54 | uint32_t req_id; | |
55 | uint32_t reg_id; | |
56 | ||
57 | /* next two flags are here for the auto-delete logic */ | |
58 | unsigned long wait_time_stamp; | |
59 | int waiting; | |
60 | ||
61 | /* seen and not seen events */ | |
62 | struct list_head events_to_get; | |
63 | struct list_head events_to_see; | |
64 | ||
65 | /* job waiting for this event to finish */ | |
66 | struct fc_bsg_job *set_job; | |
67 | }; | |
68 | ||
69 | struct lpfc_bsg_iocb { | |
70 | struct lpfc_iocbq *cmdiocbq; | |
71 | struct lpfc_iocbq *rspiocbq; | |
72 | struct lpfc_dmabuf *bmp; | |
73 | struct lpfc_nodelist *ndlp; | |
74 | ||
75 | /* job waiting for this iocb to finish */ | |
76 | struct fc_bsg_job *set_job; | |
77 | }; | |
78 | ||
3b5dd52a JS |
79 | struct lpfc_bsg_mbox { |
80 | LPFC_MBOXQ_t *pmboxq; | |
81 | MAILBOX_t *mb; | |
7a470277 JS |
82 | struct lpfc_dmabuf *rxbmp; /* for BIU diags */ |
83 | struct lpfc_dmabufext *dmp; /* for BIU diags */ | |
84 | uint8_t *ext; /* extended mailbox data */ | |
85 | uint32_t mbOffset; /* from app */ | |
86 | uint32_t inExtWLen; /* from app */ | |
c7495937 | 87 | uint32_t outExtWLen; /* from app */ |
3b5dd52a JS |
88 | |
89 | /* job waiting for this mbox command to finish */ | |
90 | struct fc_bsg_job *set_job; | |
91 | }; | |
92 | ||
e2aed29f JS |
93 | #define MENLO_DID 0x0000FC0E |
94 | ||
95 | struct lpfc_bsg_menlo { | |
96 | struct lpfc_iocbq *cmdiocbq; | |
97 | struct lpfc_iocbq *rspiocbq; | |
98 | struct lpfc_dmabuf *bmp; | |
99 | ||
100 | /* job waiting for this iocb to finish */ | |
101 | struct fc_bsg_job *set_job; | |
102 | }; | |
103 | ||
4cc0e56e JS |
104 | #define TYPE_EVT 1 |
105 | #define TYPE_IOCB 2 | |
3b5dd52a | 106 | #define TYPE_MBOX 3 |
e2aed29f | 107 | #define TYPE_MENLO 4 |
4cc0e56e JS |
108 | struct bsg_job_data { |
109 | uint32_t type; | |
110 | union { | |
111 | struct lpfc_bsg_event *evt; | |
112 | struct lpfc_bsg_iocb iocb; | |
3b5dd52a | 113 | struct lpfc_bsg_mbox mbox; |
e2aed29f | 114 | struct lpfc_bsg_menlo menlo; |
4cc0e56e JS |
115 | } context_un; |
116 | }; | |
117 | ||
118 | struct event_data { | |
119 | struct list_head node; | |
120 | uint32_t type; | |
121 | uint32_t immed_dat; | |
122 | void *data; | |
123 | uint32_t len; | |
124 | }; | |
125 | ||
3b5dd52a | 126 | #define BUF_SZ_4K 4096 |
4cc0e56e JS |
127 | #define SLI_CT_ELX_LOOPBACK 0x10 |
128 | ||
129 | enum ELX_LOOPBACK_CMD { | |
130 | ELX_LOOPBACK_XRI_SETUP, | |
131 | ELX_LOOPBACK_DATA, | |
132 | }; | |
133 | ||
3b5dd52a JS |
134 | #define ELX_LOOPBACK_HEADER_SZ \ |
135 | (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un) | |
136 | ||
4cc0e56e JS |
137 | struct lpfc_dmabufext { |
138 | struct lpfc_dmabuf dma; | |
139 | uint32_t size; | |
140 | uint32_t flag; | |
141 | }; | |
142 | ||
143 | /** | |
144 | * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler | |
145 | * @phba: Pointer to HBA context object. | |
146 | * @cmdiocbq: Pointer to command iocb. | |
147 | * @rspiocbq: Pointer to response iocb. | |
148 | * | |
149 | * This function is the completion handler for iocbs issued using | |
150 | * lpfc_bsg_send_mgmt_cmd function. This function is called by the | |
151 | * ring event handler function without any lock held. This function | |
152 | * can be called from both worker thread context and interrupt | |
153 | * context. This function also can be called from another thread which | |
154 | * cleans up the SLI layer objects. | |
155 | * This function copies the contents of the response iocb to the | |
156 | * response iocb memory object provided by the caller of | |
157 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
158 | * sleeps for the iocb completion. | |
159 | **/ | |
160 | static void | |
161 | lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba, | |
162 | struct lpfc_iocbq *cmdiocbq, | |
163 | struct lpfc_iocbq *rspiocbq) | |
164 | { | |
165 | unsigned long iflags; | |
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); | |
176 | dd_data = cmdiocbq->context1; | |
177 | if (!dd_data) { | |
178 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
179 | return; | |
180 | } | |
181 | ||
182 | iocb = &dd_data->context_un.iocb; | |
183 | job = iocb->set_job; | |
184 | job->dd_data = NULL; /* so timeout handler does not reply */ | |
185 | ||
186 | spin_lock_irqsave(&phba->hbalock, iflags); | |
187 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; | |
188 | if (cmdiocbq->context2 && rspiocbq) | |
189 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
190 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
191 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
192 | ||
193 | bmp = iocb->bmp; | |
194 | rspiocbq = iocb->rspiocbq; | |
195 | rsp = &rspiocbq->iocb; | |
196 | ndlp = iocb->ndlp; | |
197 | ||
198 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
199 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
200 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
201 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
202 | ||
203 | if (rsp->ulpStatus) { | |
204 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
205 | switch (rsp->un.ulpWord[4] & 0xff) { | |
206 | case IOERR_SEQUENCE_TIMEOUT: | |
207 | rc = -ETIMEDOUT; | |
208 | break; | |
209 | case IOERR_INVALID_RPI: | |
210 | rc = -EFAULT; | |
211 | break; | |
212 | default: | |
213 | rc = -EACCES; | |
214 | break; | |
215 | } | |
216 | } else | |
217 | rc = -EACCES; | |
218 | } else | |
219 | job->reply->reply_payload_rcv_len = | |
220 | rsp->un.genreq64.bdl.bdeSize; | |
221 | ||
222 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
223 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
224 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
225 | lpfc_nlp_put(ndlp); | |
226 | kfree(bmp); | |
227 | kfree(dd_data); | |
228 | /* make error code available to userspace */ | |
229 | job->reply->result = rc; | |
230 | /* complete the job back to userspace */ | |
231 | job->job_done(job); | |
232 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
233 | return; | |
234 | } | |
235 | ||
f1c3b0fc | 236 | /** |
4cc0e56e | 237 | * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request |
f1c3b0fc | 238 | * @job: fc_bsg_job to handle |
3b5dd52a | 239 | **/ |
f1c3b0fc | 240 | static int |
4cc0e56e | 241 | lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job) |
f1c3b0fc | 242 | { |
f1c3b0fc JS |
243 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
244 | struct lpfc_hba *phba = vport->phba; | |
245 | struct lpfc_rport_data *rdata = job->rport->dd_data; | |
246 | struct lpfc_nodelist *ndlp = rdata->pnode; | |
247 | struct ulp_bde64 *bpl = NULL; | |
248 | uint32_t timeout; | |
249 | struct lpfc_iocbq *cmdiocbq = NULL; | |
250 | struct lpfc_iocbq *rspiocbq = NULL; | |
251 | IOCB_t *cmd; | |
252 | IOCB_t *rsp; | |
253 | struct lpfc_dmabuf *bmp = NULL; | |
254 | int request_nseg; | |
255 | int reply_nseg; | |
256 | struct scatterlist *sgel = NULL; | |
257 | int numbde; | |
258 | dma_addr_t busaddr; | |
4cc0e56e JS |
259 | struct bsg_job_data *dd_data; |
260 | uint32_t creg_val; | |
f1c3b0fc JS |
261 | int rc = 0; |
262 | ||
263 | /* in case no data is transferred */ | |
264 | job->reply->reply_payload_rcv_len = 0; | |
265 | ||
4cc0e56e JS |
266 | /* allocate our bsg tracking structure */ |
267 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
268 | if (!dd_data) { | |
269 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
270 | "2733 Failed allocation of dd_data\n"); | |
271 | rc = -ENOMEM; | |
272 | goto no_dd_data; | |
273 | } | |
274 | ||
f1c3b0fc | 275 | if (!lpfc_nlp_get(ndlp)) { |
4cc0e56e JS |
276 | rc = -ENODEV; |
277 | goto no_ndlp; | |
278 | } | |
279 | ||
280 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
281 | if (!bmp) { | |
282 | rc = -ENOMEM; | |
283 | goto free_ndlp; | |
f1c3b0fc JS |
284 | } |
285 | ||
286 | if (ndlp->nlp_flag & NLP_ELS_SND_MASK) { | |
287 | rc = -ENODEV; | |
4cc0e56e | 288 | goto free_bmp; |
f1c3b0fc JS |
289 | } |
290 | ||
f1c3b0fc JS |
291 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
292 | if (!cmdiocbq) { | |
293 | rc = -ENOMEM; | |
4cc0e56e | 294 | goto free_bmp; |
f1c3b0fc | 295 | } |
f1c3b0fc | 296 | |
4cc0e56e | 297 | cmd = &cmdiocbq->iocb; |
f1c3b0fc JS |
298 | rspiocbq = lpfc_sli_get_iocbq(phba); |
299 | if (!rspiocbq) { | |
300 | rc = -ENOMEM; | |
301 | goto free_cmdiocbq; | |
302 | } | |
f1c3b0fc JS |
303 | |
304 | rsp = &rspiocbq->iocb; | |
f1c3b0fc JS |
305 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); |
306 | if (!bmp->virt) { | |
307 | rc = -ENOMEM; | |
4cc0e56e | 308 | goto free_rspiocbq; |
f1c3b0fc | 309 | } |
f1c3b0fc JS |
310 | |
311 | INIT_LIST_HEAD(&bmp->list); | |
312 | bpl = (struct ulp_bde64 *) bmp->virt; | |
f1c3b0fc JS |
313 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, |
314 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
315 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { | |
316 | busaddr = sg_dma_address(sgel); | |
317 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
318 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
319 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
320 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
321 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
322 | bpl++; | |
323 | } | |
324 | ||
325 | reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list, | |
326 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
327 | for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) { | |
328 | busaddr = sg_dma_address(sgel); | |
329 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
330 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
331 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
332 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
333 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
334 | bpl++; | |
335 | } | |
336 | ||
337 | cmd->un.genreq64.bdl.ulpIoTag32 = 0; | |
338 | cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
339 | cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
340 | cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
341 | cmd->un.genreq64.bdl.bdeSize = | |
342 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); | |
343 | cmd->ulpCommand = CMD_GEN_REQUEST64_CR; | |
344 | cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); | |
345 | cmd->un.genreq64.w5.hcsw.Dfctl = 0; | |
6a9c52cf JS |
346 | cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
347 | cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; | |
f1c3b0fc JS |
348 | cmd->ulpBdeCount = 1; |
349 | cmd->ulpLe = 1; | |
350 | cmd->ulpClass = CLASS3; | |
351 | cmd->ulpContext = ndlp->nlp_rpi; | |
352 | cmd->ulpOwner = OWN_CHIP; | |
353 | cmdiocbq->vport = phba->pport; | |
4cc0e56e | 354 | cmdiocbq->context3 = bmp; |
f1c3b0fc | 355 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
f1c3b0fc | 356 | timeout = phba->fc_ratov * 2; |
4cc0e56e JS |
357 | cmd->ulpTimeout = timeout; |
358 | ||
359 | cmdiocbq->iocb_cmpl = lpfc_bsg_send_mgmt_cmd_cmp; | |
360 | cmdiocbq->context1 = dd_data; | |
361 | cmdiocbq->context2 = rspiocbq; | |
362 | dd_data->type = TYPE_IOCB; | |
363 | dd_data->context_un.iocb.cmdiocbq = cmdiocbq; | |
364 | dd_data->context_un.iocb.rspiocbq = rspiocbq; | |
365 | dd_data->context_un.iocb.set_job = job; | |
366 | dd_data->context_un.iocb.bmp = bmp; | |
367 | dd_data->context_un.iocb.ndlp = ndlp; | |
368 | ||
369 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
370 | creg_val = readl(phba->HCregaddr); | |
371 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
372 | writel(creg_val, phba->HCregaddr); | |
373 | readl(phba->HCregaddr); /* flush */ | |
f1c3b0fc JS |
374 | } |
375 | ||
4cc0e56e | 376 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); |
f1c3b0fc | 377 | |
4cc0e56e JS |
378 | if (rc == IOCB_SUCCESS) |
379 | return 0; /* done for now */ | |
2a9bf3d0 JS |
380 | else if (rc == IOCB_BUSY) |
381 | rc = EAGAIN; | |
382 | else | |
383 | rc = EIO; | |
384 | ||
f1c3b0fc | 385 | |
4cc0e56e JS |
386 | /* iocb failed so cleanup */ |
387 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
388 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
389 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
390 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
f1c3b0fc | 391 | |
f1c3b0fc | 392 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
4cc0e56e | 393 | |
f1c3b0fc JS |
394 | free_rspiocbq: |
395 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
396 | free_cmdiocbq: | |
397 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
4cc0e56e JS |
398 | free_bmp: |
399 | kfree(bmp); | |
400 | free_ndlp: | |
f1c3b0fc | 401 | lpfc_nlp_put(ndlp); |
4cc0e56e JS |
402 | no_ndlp: |
403 | kfree(dd_data); | |
404 | no_dd_data: | |
405 | /* make error code available to userspace */ | |
406 | job->reply->result = rc; | |
407 | job->dd_data = NULL; | |
408 | return rc; | |
409 | } | |
410 | ||
411 | /** | |
412 | * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler | |
413 | * @phba: Pointer to HBA context object. | |
414 | * @cmdiocbq: Pointer to command iocb. | |
415 | * @rspiocbq: Pointer to response iocb. | |
416 | * | |
417 | * This function is the completion handler for iocbs issued using | |
418 | * lpfc_bsg_rport_els_cmp function. This function is called by the | |
419 | * ring event handler function without any lock held. This function | |
420 | * can be called from both worker thread context and interrupt | |
421 | * context. This function also can be called from other thread which | |
422 | * cleans up the SLI layer objects. | |
3b5dd52a | 423 | * This function copies the contents of the response iocb to the |
4cc0e56e JS |
424 | * response iocb memory object provided by the caller of |
425 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
426 | * sleeps for the iocb completion. | |
427 | **/ | |
428 | static void | |
429 | lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba, | |
430 | struct lpfc_iocbq *cmdiocbq, | |
431 | struct lpfc_iocbq *rspiocbq) | |
432 | { | |
433 | struct bsg_job_data *dd_data; | |
434 | struct fc_bsg_job *job; | |
435 | IOCB_t *rsp; | |
436 | struct lpfc_nodelist *ndlp; | |
437 | struct lpfc_dmabuf *pbuflist = NULL; | |
438 | struct fc_bsg_ctels_reply *els_reply; | |
439 | uint8_t *rjt_data; | |
440 | unsigned long flags; | |
441 | int rc = 0; | |
442 | ||
443 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
444 | dd_data = cmdiocbq->context1; | |
445 | /* normal completion and timeout crossed paths, already done */ | |
446 | if (!dd_data) { | |
67221a42 | 447 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4cc0e56e JS |
448 | return; |
449 | } | |
450 | ||
451 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; | |
452 | if (cmdiocbq->context2 && rspiocbq) | |
453 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
454 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
455 | ||
456 | job = dd_data->context_un.iocb.set_job; | |
457 | cmdiocbq = dd_data->context_un.iocb.cmdiocbq; | |
458 | rspiocbq = dd_data->context_un.iocb.rspiocbq; | |
459 | rsp = &rspiocbq->iocb; | |
460 | ndlp = dd_data->context_un.iocb.ndlp; | |
461 | ||
462 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
463 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
464 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
465 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
466 | ||
467 | if (job->reply->result == -EAGAIN) | |
468 | rc = -EAGAIN; | |
469 | else if (rsp->ulpStatus == IOSTAT_SUCCESS) | |
470 | job->reply->reply_payload_rcv_len = | |
471 | rsp->un.elsreq64.bdl.bdeSize; | |
472 | else if (rsp->ulpStatus == IOSTAT_LS_RJT) { | |
473 | job->reply->reply_payload_rcv_len = | |
474 | sizeof(struct fc_bsg_ctels_reply); | |
475 | /* LS_RJT data returned in word 4 */ | |
476 | rjt_data = (uint8_t *)&rsp->un.ulpWord[4]; | |
477 | els_reply = &job->reply->reply_data.ctels_reply; | |
478 | els_reply->status = FC_CTELS_STATUS_REJECT; | |
479 | els_reply->rjt_data.action = rjt_data[3]; | |
480 | els_reply->rjt_data.reason_code = rjt_data[2]; | |
481 | els_reply->rjt_data.reason_explanation = rjt_data[1]; | |
482 | els_reply->rjt_data.vendor_unique = rjt_data[0]; | |
483 | } else | |
484 | rc = -EIO; | |
f1c3b0fc | 485 | |
4cc0e56e JS |
486 | pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3; |
487 | lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys); | |
488 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
489 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
490 | lpfc_nlp_put(ndlp); | |
491 | kfree(dd_data); | |
f1c3b0fc JS |
492 | /* make error code available to userspace */ |
493 | job->reply->result = rc; | |
4cc0e56e | 494 | job->dd_data = NULL; |
f1c3b0fc JS |
495 | /* complete the job back to userspace */ |
496 | job->job_done(job); | |
4cc0e56e JS |
497 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
498 | return; | |
f1c3b0fc JS |
499 | } |
500 | ||
501 | /** | |
502 | * lpfc_bsg_rport_els - send an ELS command from a bsg request | |
503 | * @job: fc_bsg_job to handle | |
3b5dd52a | 504 | **/ |
f1c3b0fc JS |
505 | static int |
506 | lpfc_bsg_rport_els(struct fc_bsg_job *job) | |
507 | { | |
508 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
509 | struct lpfc_hba *phba = vport->phba; | |
510 | struct lpfc_rport_data *rdata = job->rport->dd_data; | |
511 | struct lpfc_nodelist *ndlp = rdata->pnode; | |
f1c3b0fc JS |
512 | uint32_t elscmd; |
513 | uint32_t cmdsize; | |
514 | uint32_t rspsize; | |
515 | struct lpfc_iocbq *rspiocbq; | |
516 | struct lpfc_iocbq *cmdiocbq; | |
517 | IOCB_t *rsp; | |
518 | uint16_t rpi = 0; | |
519 | struct lpfc_dmabuf *pcmd; | |
520 | struct lpfc_dmabuf *prsp; | |
521 | struct lpfc_dmabuf *pbuflist = NULL; | |
522 | struct ulp_bde64 *bpl; | |
f1c3b0fc JS |
523 | int request_nseg; |
524 | int reply_nseg; | |
525 | struct scatterlist *sgel = NULL; | |
526 | int numbde; | |
527 | dma_addr_t busaddr; | |
4cc0e56e JS |
528 | struct bsg_job_data *dd_data; |
529 | uint32_t creg_val; | |
f1c3b0fc JS |
530 | int rc = 0; |
531 | ||
532 | /* in case no data is transferred */ | |
533 | job->reply->reply_payload_rcv_len = 0; | |
534 | ||
4cc0e56e JS |
535 | /* allocate our bsg tracking structure */ |
536 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
537 | if (!dd_data) { | |
538 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
539 | "2735 Failed allocation of dd_data\n"); | |
540 | rc = -ENOMEM; | |
541 | goto no_dd_data; | |
542 | } | |
543 | ||
f1c3b0fc JS |
544 | if (!lpfc_nlp_get(ndlp)) { |
545 | rc = -ENODEV; | |
4cc0e56e | 546 | goto free_dd_data; |
f1c3b0fc JS |
547 | } |
548 | ||
549 | elscmd = job->request->rqst_data.r_els.els_code; | |
550 | cmdsize = job->request_payload.payload_len; | |
551 | rspsize = job->reply_payload.payload_len; | |
552 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
553 | if (!rspiocbq) { | |
554 | lpfc_nlp_put(ndlp); | |
555 | rc = -ENOMEM; | |
4cc0e56e | 556 | goto free_dd_data; |
f1c3b0fc JS |
557 | } |
558 | ||
559 | rsp = &rspiocbq->iocb; | |
560 | rpi = ndlp->nlp_rpi; | |
561 | ||
4cc0e56e | 562 | cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, |
f1c3b0fc | 563 | ndlp->nlp_DID, elscmd); |
f1c3b0fc | 564 | if (!cmdiocbq) { |
4cc0e56e JS |
565 | rc = -EIO; |
566 | goto free_rspiocbq; | |
f1c3b0fc JS |
567 | } |
568 | ||
4cc0e56e | 569 | /* prep els iocb set context1 to the ndlp, context2 to the command |
3b5dd52a JS |
570 | * dmabuf, context3 holds the data dmabuf |
571 | */ | |
f1c3b0fc JS |
572 | pcmd = (struct lpfc_dmabuf *) cmdiocbq->context2; |
573 | prsp = (struct lpfc_dmabuf *) pcmd->list.next; | |
f1c3b0fc JS |
574 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
575 | kfree(pcmd); | |
576 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | |
577 | kfree(prsp); | |
578 | cmdiocbq->context2 = NULL; | |
579 | ||
580 | pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3; | |
581 | bpl = (struct ulp_bde64 *) pbuflist->virt; | |
582 | ||
583 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, | |
584 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
f1c3b0fc JS |
585 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { |
586 | busaddr = sg_dma_address(sgel); | |
587 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
588 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
589 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
590 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
591 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
592 | bpl++; | |
593 | } | |
594 | ||
595 | reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list, | |
596 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
597 | for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) { | |
598 | busaddr = sg_dma_address(sgel); | |
599 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
600 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
601 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
602 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
603 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
604 | bpl++; | |
605 | } | |
f1c3b0fc JS |
606 | cmdiocbq->iocb.un.elsreq64.bdl.bdeSize = |
607 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); | |
608 | cmdiocbq->iocb.ulpContext = rpi; | |
609 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
610 | cmdiocbq->context1 = NULL; | |
611 | cmdiocbq->context2 = NULL; | |
612 | ||
4cc0e56e JS |
613 | cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp; |
614 | cmdiocbq->context1 = dd_data; | |
615 | cmdiocbq->context2 = rspiocbq; | |
616 | dd_data->type = TYPE_IOCB; | |
617 | dd_data->context_un.iocb.cmdiocbq = cmdiocbq; | |
618 | dd_data->context_un.iocb.rspiocbq = rspiocbq; | |
619 | dd_data->context_un.iocb.set_job = job; | |
620 | dd_data->context_un.iocb.bmp = NULL;; | |
621 | dd_data->context_un.iocb.ndlp = ndlp; | |
622 | ||
623 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
624 | creg_val = readl(phba->HCregaddr); | |
625 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
626 | writel(creg_val, phba->HCregaddr); | |
627 | readl(phba->HCregaddr); /* flush */ | |
628 | } | |
629 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); | |
f1c3b0fc | 630 | lpfc_nlp_put(ndlp); |
4cc0e56e JS |
631 | if (rc == IOCB_SUCCESS) |
632 | return 0; /* done for now */ | |
2a9bf3d0 JS |
633 | else if (rc == IOCB_BUSY) |
634 | rc = EAGAIN; | |
635 | else | |
636 | rc = EIO; | |
f1c3b0fc | 637 | |
4cc0e56e JS |
638 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, |
639 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
640 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
641 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
f1c3b0fc | 642 | |
4cc0e56e | 643 | lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys); |
f1c3b0fc | 644 | |
4cc0e56e | 645 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
f1c3b0fc | 646 | |
4cc0e56e JS |
647 | free_rspiocbq: |
648 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
f1c3b0fc | 649 | |
4cc0e56e JS |
650 | free_dd_data: |
651 | kfree(dd_data); | |
f1c3b0fc | 652 | |
4cc0e56e JS |
653 | no_dd_data: |
654 | /* make error code available to userspace */ | |
655 | job->reply->result = rc; | |
656 | job->dd_data = NULL; | |
657 | return rc; | |
f1c3b0fc JS |
658 | } |
659 | ||
3b5dd52a JS |
660 | /** |
661 | * lpfc_bsg_event_free - frees an allocated event structure | |
662 | * @kref: Pointer to a kref. | |
663 | * | |
664 | * Called from kref_put. Back cast the kref into an event structure address. | |
665 | * Free any events to get, delete associated nodes, free any events to see, | |
666 | * free any data then free the event itself. | |
667 | **/ | |
f1c3b0fc | 668 | static void |
4cc0e56e | 669 | lpfc_bsg_event_free(struct kref *kref) |
f1c3b0fc | 670 | { |
4cc0e56e JS |
671 | struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event, |
672 | kref); | |
f1c3b0fc JS |
673 | struct event_data *ed; |
674 | ||
675 | list_del(&evt->node); | |
676 | ||
677 | while (!list_empty(&evt->events_to_get)) { | |
678 | ed = list_entry(evt->events_to_get.next, typeof(*ed), node); | |
679 | list_del(&ed->node); | |
680 | kfree(ed->data); | |
681 | kfree(ed); | |
682 | } | |
683 | ||
684 | while (!list_empty(&evt->events_to_see)) { | |
685 | ed = list_entry(evt->events_to_see.next, typeof(*ed), node); | |
686 | list_del(&ed->node); | |
687 | kfree(ed->data); | |
688 | kfree(ed); | |
689 | } | |
690 | ||
691 | kfree(evt); | |
692 | } | |
693 | ||
3b5dd52a JS |
694 | /** |
695 | * lpfc_bsg_event_ref - increments the kref for an event | |
696 | * @evt: Pointer to an event structure. | |
697 | **/ | |
f1c3b0fc | 698 | static inline void |
4cc0e56e | 699 | lpfc_bsg_event_ref(struct lpfc_bsg_event *evt) |
f1c3b0fc | 700 | { |
4cc0e56e | 701 | kref_get(&evt->kref); |
f1c3b0fc JS |
702 | } |
703 | ||
3b5dd52a JS |
704 | /** |
705 | * lpfc_bsg_event_unref - Uses kref_put to free an event structure | |
706 | * @evt: Pointer to an event structure. | |
707 | **/ | |
f1c3b0fc | 708 | static inline void |
4cc0e56e | 709 | lpfc_bsg_event_unref(struct lpfc_bsg_event *evt) |
f1c3b0fc | 710 | { |
4cc0e56e | 711 | kref_put(&evt->kref, lpfc_bsg_event_free); |
f1c3b0fc JS |
712 | } |
713 | ||
3b5dd52a JS |
714 | /** |
715 | * lpfc_bsg_event_new - allocate and initialize a event structure | |
716 | * @ev_mask: Mask of events. | |
717 | * @ev_reg_id: Event reg id. | |
718 | * @ev_req_id: Event request id. | |
719 | **/ | |
4cc0e56e JS |
720 | static struct lpfc_bsg_event * |
721 | lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id) | |
722 | { | |
723 | struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL); | |
f1c3b0fc | 724 | |
4cc0e56e JS |
725 | if (!evt) |
726 | return NULL; | |
727 | ||
728 | INIT_LIST_HEAD(&evt->events_to_get); | |
729 | INIT_LIST_HEAD(&evt->events_to_see); | |
730 | evt->type_mask = ev_mask; | |
731 | evt->req_id = ev_req_id; | |
732 | evt->reg_id = ev_reg_id; | |
733 | evt->wait_time_stamp = jiffies; | |
734 | init_waitqueue_head(&evt->wq); | |
735 | kref_init(&evt->kref); | |
736 | return evt; | |
737 | } | |
738 | ||
3b5dd52a JS |
739 | /** |
740 | * diag_cmd_data_free - Frees an lpfc dma buffer extension | |
741 | * @phba: Pointer to HBA context object. | |
742 | * @mlist: Pointer to an lpfc dma buffer extension. | |
743 | **/ | |
4cc0e56e | 744 | static int |
3b5dd52a | 745 | diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist) |
4cc0e56e JS |
746 | { |
747 | struct lpfc_dmabufext *mlast; | |
748 | struct pci_dev *pcidev; | |
749 | struct list_head head, *curr, *next; | |
750 | ||
751 | if ((!mlist) || (!lpfc_is_link_up(phba) && | |
752 | (phba->link_flag & LS_LOOPBACK_MODE))) { | |
753 | return 0; | |
754 | } | |
755 | ||
756 | pcidev = phba->pcidev; | |
757 | list_add_tail(&head, &mlist->dma.list); | |
758 | ||
759 | list_for_each_safe(curr, next, &head) { | |
760 | mlast = list_entry(curr, struct lpfc_dmabufext , dma.list); | |
761 | if (mlast->dma.virt) | |
762 | dma_free_coherent(&pcidev->dev, | |
763 | mlast->size, | |
764 | mlast->dma.virt, | |
765 | mlast->dma.phys); | |
766 | kfree(mlast); | |
767 | } | |
768 | return 0; | |
769 | } | |
f1c3b0fc JS |
770 | |
771 | /** | |
772 | * lpfc_bsg_ct_unsol_event - process an unsolicited CT command | |
773 | * @phba: | |
774 | * @pring: | |
775 | * @piocbq: | |
776 | * | |
777 | * This function is called when an unsolicited CT command is received. It | |
4cc0e56e | 778 | * forwards the event to any processes registered to receive CT events. |
3b5dd52a | 779 | **/ |
4fede78f | 780 | int |
f1c3b0fc JS |
781 | lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
782 | struct lpfc_iocbq *piocbq) | |
783 | { | |
784 | uint32_t evt_req_id = 0; | |
785 | uint32_t cmd; | |
786 | uint32_t len; | |
787 | struct lpfc_dmabuf *dmabuf = NULL; | |
4cc0e56e | 788 | struct lpfc_bsg_event *evt; |
f1c3b0fc JS |
789 | struct event_data *evt_dat = NULL; |
790 | struct lpfc_iocbq *iocbq; | |
791 | size_t offset = 0; | |
792 | struct list_head head; | |
793 | struct ulp_bde64 *bde; | |
794 | dma_addr_t dma_addr; | |
795 | int i; | |
796 | struct lpfc_dmabuf *bdeBuf1 = piocbq->context2; | |
797 | struct lpfc_dmabuf *bdeBuf2 = piocbq->context3; | |
798 | struct lpfc_hbq_entry *hbqe; | |
799 | struct lpfc_sli_ct_request *ct_req; | |
4cc0e56e | 800 | struct fc_bsg_job *job = NULL; |
4fede78f | 801 | unsigned long flags; |
4cc0e56e | 802 | int size = 0; |
f1c3b0fc JS |
803 | |
804 | INIT_LIST_HEAD(&head); | |
805 | list_add_tail(&head, &piocbq->list); | |
806 | ||
807 | if (piocbq->iocb.ulpBdeCount == 0 || | |
808 | piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0) | |
809 | goto error_ct_unsol_exit; | |
810 | ||
4cc0e56e JS |
811 | if (phba->link_state == LPFC_HBA_ERROR || |
812 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) | |
813 | goto error_ct_unsol_exit; | |
814 | ||
f1c3b0fc JS |
815 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
816 | dmabuf = bdeBuf1; | |
817 | else { | |
818 | dma_addr = getPaddr(piocbq->iocb.un.cont64[0].addrHigh, | |
819 | piocbq->iocb.un.cont64[0].addrLow); | |
820 | dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr); | |
821 | } | |
4cc0e56e JS |
822 | if (dmabuf == NULL) |
823 | goto error_ct_unsol_exit; | |
f1c3b0fc JS |
824 | ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt; |
825 | evt_req_id = ct_req->FsType; | |
826 | cmd = ct_req->CommandResponse.bits.CmdRsp; | |
827 | len = ct_req->CommandResponse.bits.Size; | |
828 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) | |
829 | lpfc_sli_ringpostbuf_put(phba, pring, dmabuf); | |
830 | ||
4fede78f | 831 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc | 832 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
4cc0e56e JS |
833 | if (!(evt->type_mask & FC_REG_CT_EVENT) || |
834 | evt->req_id != evt_req_id) | |
f1c3b0fc JS |
835 | continue; |
836 | ||
4cc0e56e JS |
837 | lpfc_bsg_event_ref(evt); |
838 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
f1c3b0fc | 839 | evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL); |
4cc0e56e JS |
840 | if (evt_dat == NULL) { |
841 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
842 | lpfc_bsg_event_unref(evt); | |
f1c3b0fc JS |
843 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
844 | "2614 Memory allocation failed for " | |
845 | "CT event\n"); | |
846 | break; | |
847 | } | |
848 | ||
f1c3b0fc JS |
849 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
850 | /* take accumulated byte count from the last iocbq */ | |
851 | iocbq = list_entry(head.prev, typeof(*iocbq), list); | |
852 | evt_dat->len = iocbq->iocb.unsli3.rcvsli3.acc_len; | |
853 | } else { | |
854 | list_for_each_entry(iocbq, &head, list) { | |
855 | for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) | |
856 | evt_dat->len += | |
857 | iocbq->iocb.un.cont64[i].tus.f.bdeSize; | |
858 | } | |
859 | } | |
860 | ||
861 | evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL); | |
4cc0e56e | 862 | if (evt_dat->data == NULL) { |
f1c3b0fc JS |
863 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
864 | "2615 Memory allocation failed for " | |
865 | "CT event data, size %d\n", | |
866 | evt_dat->len); | |
867 | kfree(evt_dat); | |
4fede78f | 868 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
4cc0e56e | 869 | lpfc_bsg_event_unref(evt); |
4fede78f | 870 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
871 | goto error_ct_unsol_exit; |
872 | } | |
873 | ||
874 | list_for_each_entry(iocbq, &head, list) { | |
4cc0e56e | 875 | size = 0; |
f1c3b0fc JS |
876 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
877 | bdeBuf1 = iocbq->context2; | |
878 | bdeBuf2 = iocbq->context3; | |
879 | } | |
880 | for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) { | |
f1c3b0fc JS |
881 | if (phba->sli3_options & |
882 | LPFC_SLI3_HBQ_ENABLED) { | |
883 | if (i == 0) { | |
884 | hbqe = (struct lpfc_hbq_entry *) | |
885 | &iocbq->iocb.un.ulpWord[0]; | |
886 | size = hbqe->bde.tus.f.bdeSize; | |
887 | dmabuf = bdeBuf1; | |
888 | } else if (i == 1) { | |
889 | hbqe = (struct lpfc_hbq_entry *) | |
890 | &iocbq->iocb.unsli3. | |
891 | sli3Words[4]; | |
892 | size = hbqe->bde.tus.f.bdeSize; | |
893 | dmabuf = bdeBuf2; | |
894 | } | |
895 | if ((offset + size) > evt_dat->len) | |
896 | size = evt_dat->len - offset; | |
897 | } else { | |
898 | size = iocbq->iocb.un.cont64[i]. | |
899 | tus.f.bdeSize; | |
900 | bde = &iocbq->iocb.un.cont64[i]; | |
901 | dma_addr = getPaddr(bde->addrHigh, | |
902 | bde->addrLow); | |
903 | dmabuf = lpfc_sli_ringpostbuf_get(phba, | |
904 | pring, dma_addr); | |
905 | } | |
906 | if (!dmabuf) { | |
907 | lpfc_printf_log(phba, KERN_ERR, | |
908 | LOG_LIBDFC, "2616 No dmabuf " | |
909 | "found for iocbq 0x%p\n", | |
910 | iocbq); | |
911 | kfree(evt_dat->data); | |
912 | kfree(evt_dat); | |
4fede78f JS |
913 | spin_lock_irqsave(&phba->ct_ev_lock, |
914 | flags); | |
4cc0e56e | 915 | lpfc_bsg_event_unref(evt); |
4fede78f JS |
916 | spin_unlock_irqrestore( |
917 | &phba->ct_ev_lock, flags); | |
f1c3b0fc JS |
918 | goto error_ct_unsol_exit; |
919 | } | |
920 | memcpy((char *)(evt_dat->data) + offset, | |
921 | dmabuf->virt, size); | |
922 | offset += size; | |
923 | if (evt_req_id != SLI_CT_ELX_LOOPBACK && | |
924 | !(phba->sli3_options & | |
925 | LPFC_SLI3_HBQ_ENABLED)) { | |
926 | lpfc_sli_ringpostbuf_put(phba, pring, | |
927 | dmabuf); | |
928 | } else { | |
929 | switch (cmd) { | |
4cc0e56e | 930 | case ELX_LOOPBACK_DATA: |
3b5dd52a | 931 | diag_cmd_data_free(phba, |
4cc0e56e JS |
932 | (struct lpfc_dmabufext *) |
933 | dmabuf); | |
934 | break; | |
f1c3b0fc | 935 | case ELX_LOOPBACK_XRI_SETUP: |
4cc0e56e JS |
936 | if ((phba->sli_rev == |
937 | LPFC_SLI_REV2) || | |
938 | (phba->sli3_options & | |
939 | LPFC_SLI3_HBQ_ENABLED | |
940 | )) { | |
941 | lpfc_in_buf_free(phba, | |
942 | dmabuf); | |
943 | } else { | |
f1c3b0fc JS |
944 | lpfc_post_buffer(phba, |
945 | pring, | |
946 | 1); | |
4cc0e56e | 947 | } |
f1c3b0fc JS |
948 | break; |
949 | default: | |
950 | if (!(phba->sli3_options & | |
951 | LPFC_SLI3_HBQ_ENABLED)) | |
952 | lpfc_post_buffer(phba, | |
953 | pring, | |
954 | 1); | |
955 | break; | |
956 | } | |
957 | } | |
958 | } | |
959 | } | |
960 | ||
4fede78f | 961 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
962 | if (phba->sli_rev == LPFC_SLI_REV4) { |
963 | evt_dat->immed_dat = phba->ctx_idx; | |
964 | phba->ctx_idx = (phba->ctx_idx + 1) % 64; | |
965 | phba->ct_ctx[evt_dat->immed_dat].oxid = | |
966 | piocbq->iocb.ulpContext; | |
967 | phba->ct_ctx[evt_dat->immed_dat].SID = | |
968 | piocbq->iocb.un.rcvels.remoteID; | |
969 | } else | |
970 | evt_dat->immed_dat = piocbq->iocb.ulpContext; | |
971 | ||
972 | evt_dat->type = FC_REG_CT_EVENT; | |
973 | list_add(&evt_dat->node, &evt->events_to_see); | |
4cc0e56e JS |
974 | if (evt_req_id == SLI_CT_ELX_LOOPBACK) { |
975 | wake_up_interruptible(&evt->wq); | |
976 | lpfc_bsg_event_unref(evt); | |
f1c3b0fc | 977 | break; |
4cc0e56e JS |
978 | } |
979 | ||
980 | list_move(evt->events_to_see.prev, &evt->events_to_get); | |
981 | lpfc_bsg_event_unref(evt); | |
982 | ||
983 | job = evt->set_job; | |
984 | evt->set_job = NULL; | |
985 | if (job) { | |
986 | job->reply->reply_payload_rcv_len = size; | |
987 | /* make error code available to userspace */ | |
988 | job->reply->result = 0; | |
989 | job->dd_data = NULL; | |
990 | /* complete the job back to userspace */ | |
991 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
992 | job->job_done(job); | |
993 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
994 | } | |
f1c3b0fc | 995 | } |
4fede78f | 996 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
997 | |
998 | error_ct_unsol_exit: | |
999 | if (!list_empty(&head)) | |
1000 | list_del(&head); | |
4cc0e56e JS |
1001 | if (evt_req_id == SLI_CT_ELX_LOOPBACK) |
1002 | return 0; | |
4fede78f | 1003 | return 1; |
f1c3b0fc JS |
1004 | } |
1005 | ||
1006 | /** | |
4cc0e56e | 1007 | * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command |
f1c3b0fc | 1008 | * @job: SET_EVENT fc_bsg_job |
3b5dd52a | 1009 | **/ |
f1c3b0fc | 1010 | static int |
4cc0e56e | 1011 | lpfc_bsg_hba_set_event(struct fc_bsg_job *job) |
f1c3b0fc JS |
1012 | { |
1013 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
1014 | struct lpfc_hba *phba = vport->phba; | |
1015 | struct set_ct_event *event_req; | |
4cc0e56e | 1016 | struct lpfc_bsg_event *evt; |
f1c3b0fc | 1017 | int rc = 0; |
4cc0e56e JS |
1018 | struct bsg_job_data *dd_data = NULL; |
1019 | uint32_t ev_mask; | |
1020 | unsigned long flags; | |
f1c3b0fc JS |
1021 | |
1022 | if (job->request_len < | |
1023 | sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) { | |
1024 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1025 | "2612 Received SET_CT_EVENT below minimum " | |
1026 | "size\n"); | |
4cc0e56e JS |
1027 | rc = -EINVAL; |
1028 | goto job_error; | |
1029 | } | |
1030 | ||
1031 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
1032 | if (dd_data == NULL) { | |
1033 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1034 | "2734 Failed allocation of dd_data\n"); | |
1035 | rc = -ENOMEM; | |
1036 | goto job_error; | |
f1c3b0fc JS |
1037 | } |
1038 | ||
1039 | event_req = (struct set_ct_event *) | |
1040 | job->request->rqst_data.h_vendor.vendor_cmd; | |
4cc0e56e JS |
1041 | ev_mask = ((uint32_t)(unsigned long)event_req->type_mask & |
1042 | FC_REG_EVENT_MASK); | |
4fede78f | 1043 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1044 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
1045 | if (evt->reg_id == event_req->ev_reg_id) { | |
4cc0e56e | 1046 | lpfc_bsg_event_ref(evt); |
f1c3b0fc JS |
1047 | evt->wait_time_stamp = jiffies; |
1048 | break; | |
1049 | } | |
1050 | } | |
4fede78f | 1051 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1052 | |
1053 | if (&evt->node == &phba->ct_ev_waiters) { | |
1054 | /* no event waiting struct yet - first call */ | |
4cc0e56e | 1055 | evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id, |
f1c3b0fc JS |
1056 | event_req->ev_req_id); |
1057 | if (!evt) { | |
1058 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1059 | "2617 Failed allocation of event " | |
1060 | "waiter\n"); | |
4cc0e56e JS |
1061 | rc = -ENOMEM; |
1062 | goto job_error; | |
f1c3b0fc JS |
1063 | } |
1064 | ||
4fede78f | 1065 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc | 1066 | list_add(&evt->node, &phba->ct_ev_waiters); |
4cc0e56e JS |
1067 | lpfc_bsg_event_ref(evt); |
1068 | evt->wait_time_stamp = jiffies; | |
4fede78f | 1069 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1070 | } |
1071 | ||
4fede78f | 1072 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
4cc0e56e JS |
1073 | evt->waiting = 1; |
1074 | dd_data->type = TYPE_EVT; | |
1075 | dd_data->context_un.evt = evt; | |
1076 | evt->set_job = job; /* for unsolicited command */ | |
1077 | job->dd_data = dd_data; /* for fc transport timeout callback*/ | |
4fede78f | 1078 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4cc0e56e | 1079 | return 0; /* call job done later */ |
f1c3b0fc | 1080 | |
4cc0e56e JS |
1081 | job_error: |
1082 | if (dd_data != NULL) | |
1083 | kfree(dd_data); | |
f1c3b0fc | 1084 | |
4cc0e56e JS |
1085 | job->dd_data = NULL; |
1086 | return rc; | |
f1c3b0fc JS |
1087 | } |
1088 | ||
1089 | /** | |
4cc0e56e | 1090 | * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command |
f1c3b0fc | 1091 | * @job: GET_EVENT fc_bsg_job |
3b5dd52a | 1092 | **/ |
f1c3b0fc | 1093 | static int |
4cc0e56e | 1094 | lpfc_bsg_hba_get_event(struct fc_bsg_job *job) |
f1c3b0fc JS |
1095 | { |
1096 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
1097 | struct lpfc_hba *phba = vport->phba; | |
1098 | struct get_ct_event *event_req; | |
1099 | struct get_ct_event_reply *event_reply; | |
4cc0e56e | 1100 | struct lpfc_bsg_event *evt; |
f1c3b0fc | 1101 | struct event_data *evt_dat = NULL; |
4fede78f | 1102 | unsigned long flags; |
4cc0e56e | 1103 | uint32_t rc = 0; |
f1c3b0fc JS |
1104 | |
1105 | if (job->request_len < | |
1106 | sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) { | |
1107 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1108 | "2613 Received GET_CT_EVENT request below " | |
1109 | "minimum size\n"); | |
4cc0e56e JS |
1110 | rc = -EINVAL; |
1111 | goto job_error; | |
f1c3b0fc JS |
1112 | } |
1113 | ||
1114 | event_req = (struct get_ct_event *) | |
1115 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1116 | ||
1117 | event_reply = (struct get_ct_event_reply *) | |
1118 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
4fede78f | 1119 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
f1c3b0fc JS |
1120 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
1121 | if (evt->reg_id == event_req->ev_reg_id) { | |
1122 | if (list_empty(&evt->events_to_get)) | |
1123 | break; | |
4cc0e56e | 1124 | lpfc_bsg_event_ref(evt); |
f1c3b0fc JS |
1125 | evt->wait_time_stamp = jiffies; |
1126 | evt_dat = list_entry(evt->events_to_get.prev, | |
1127 | struct event_data, node); | |
1128 | list_del(&evt_dat->node); | |
1129 | break; | |
1130 | } | |
1131 | } | |
4fede78f | 1132 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
f1c3b0fc | 1133 | |
4cc0e56e JS |
1134 | /* The app may continue to ask for event data until it gets |
1135 | * an error indicating that there isn't anymore | |
1136 | */ | |
1137 | if (evt_dat == NULL) { | |
f1c3b0fc JS |
1138 | job->reply->reply_payload_rcv_len = 0; |
1139 | rc = -ENOENT; | |
4cc0e56e | 1140 | goto job_error; |
f1c3b0fc JS |
1141 | } |
1142 | ||
4cc0e56e JS |
1143 | if (evt_dat->len > job->request_payload.payload_len) { |
1144 | evt_dat->len = job->request_payload.payload_len; | |
1145 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1146 | "2618 Truncated event data at %d " | |
1147 | "bytes\n", | |
1148 | job->request_payload.payload_len); | |
f1c3b0fc JS |
1149 | } |
1150 | ||
4cc0e56e | 1151 | event_reply->type = evt_dat->type; |
f1c3b0fc | 1152 | event_reply->immed_data = evt_dat->immed_dat; |
f1c3b0fc JS |
1153 | if (evt_dat->len > 0) |
1154 | job->reply->reply_payload_rcv_len = | |
4cc0e56e JS |
1155 | sg_copy_from_buffer(job->request_payload.sg_list, |
1156 | job->request_payload.sg_cnt, | |
f1c3b0fc JS |
1157 | evt_dat->data, evt_dat->len); |
1158 | else | |
1159 | job->reply->reply_payload_rcv_len = 0; | |
f1c3b0fc | 1160 | |
4cc0e56e | 1161 | if (evt_dat) { |
f1c3b0fc | 1162 | kfree(evt_dat->data); |
4cc0e56e JS |
1163 | kfree(evt_dat); |
1164 | } | |
1165 | ||
4fede78f | 1166 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
4cc0e56e | 1167 | lpfc_bsg_event_unref(evt); |
4fede78f | 1168 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
4cc0e56e JS |
1169 | job->dd_data = NULL; |
1170 | job->reply->result = 0; | |
f1c3b0fc | 1171 | job->job_done(job); |
4cc0e56e | 1172 | return 0; |
f1c3b0fc | 1173 | |
4cc0e56e JS |
1174 | job_error: |
1175 | job->dd_data = NULL; | |
1176 | job->reply->result = rc; | |
f1c3b0fc JS |
1177 | return rc; |
1178 | } | |
1179 | ||
1180 | /** | |
3b5dd52a JS |
1181 | * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler |
1182 | * @phba: Pointer to HBA context object. | |
1183 | * @cmdiocbq: Pointer to command iocb. | |
1184 | * @rspiocbq: Pointer to response iocb. | |
1185 | * | |
1186 | * This function is the completion handler for iocbs issued using | |
1187 | * lpfc_issue_ct_rsp_cmp function. This function is called by the | |
1188 | * ring event handler function without any lock held. This function | |
1189 | * can be called from both worker thread context and interrupt | |
1190 | * context. This function also can be called from other thread which | |
1191 | * cleans up the SLI layer objects. | |
1192 | * This function copy the contents of the response iocb to the | |
1193 | * response iocb memory object provided by the caller of | |
1194 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
1195 | * sleeps for the iocb completion. | |
1196 | **/ | |
1197 | static void | |
1198 | lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba, | |
1199 | struct lpfc_iocbq *cmdiocbq, | |
1200 | struct lpfc_iocbq *rspiocbq) | |
1201 | { | |
1202 | struct bsg_job_data *dd_data; | |
1203 | struct fc_bsg_job *job; | |
1204 | IOCB_t *rsp; | |
1205 | struct lpfc_dmabuf *bmp; | |
1206 | struct lpfc_nodelist *ndlp; | |
1207 | unsigned long flags; | |
1208 | int rc = 0; | |
1209 | ||
1210 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
1211 | dd_data = cmdiocbq->context1; | |
1212 | /* normal completion and timeout crossed paths, already done */ | |
1213 | if (!dd_data) { | |
67221a42 | 1214 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
3b5dd52a JS |
1215 | return; |
1216 | } | |
1217 | ||
1218 | job = dd_data->context_un.iocb.set_job; | |
1219 | bmp = dd_data->context_un.iocb.bmp; | |
1220 | rsp = &rspiocbq->iocb; | |
1221 | ndlp = dd_data->context_un.iocb.ndlp; | |
1222 | ||
1223 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
1224 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1225 | ||
1226 | if (rsp->ulpStatus) { | |
1227 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
1228 | switch (rsp->un.ulpWord[4] & 0xff) { | |
1229 | case IOERR_SEQUENCE_TIMEOUT: | |
1230 | rc = -ETIMEDOUT; | |
1231 | break; | |
1232 | case IOERR_INVALID_RPI: | |
1233 | rc = -EFAULT; | |
1234 | break; | |
1235 | default: | |
1236 | rc = -EACCES; | |
1237 | break; | |
1238 | } | |
1239 | } else | |
1240 | rc = -EACCES; | |
1241 | } else | |
1242 | job->reply->reply_payload_rcv_len = | |
1243 | rsp->un.genreq64.bdl.bdeSize; | |
1244 | ||
1245 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
1246 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
1247 | lpfc_nlp_put(ndlp); | |
1248 | kfree(bmp); | |
1249 | kfree(dd_data); | |
1250 | /* make error code available to userspace */ | |
1251 | job->reply->result = rc; | |
1252 | job->dd_data = NULL; | |
1253 | /* complete the job back to userspace */ | |
1254 | job->job_done(job); | |
1255 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
1256 | return; | |
1257 | } | |
1258 | ||
1259 | /** | |
1260 | * lpfc_issue_ct_rsp - issue a ct response | |
1261 | * @phba: Pointer to HBA context object. | |
1262 | * @job: Pointer to the job object. | |
1263 | * @tag: tag index value into the ports context exchange array. | |
1264 | * @bmp: Pointer to a dma buffer descriptor. | |
1265 | * @num_entry: Number of enties in the bde. | |
1266 | **/ | |
f1c3b0fc | 1267 | static int |
3b5dd52a JS |
1268 | lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag, |
1269 | struct lpfc_dmabuf *bmp, int num_entry) | |
f1c3b0fc | 1270 | { |
3b5dd52a JS |
1271 | IOCB_t *icmd; |
1272 | struct lpfc_iocbq *ctiocb = NULL; | |
1273 | int rc = 0; | |
1274 | struct lpfc_nodelist *ndlp = NULL; | |
1275 | struct bsg_job_data *dd_data; | |
1276 | uint32_t creg_val; | |
f1c3b0fc | 1277 | |
3b5dd52a JS |
1278 | /* allocate our bsg tracking structure */ |
1279 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
1280 | if (!dd_data) { | |
1281 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1282 | "2736 Failed allocation of dd_data\n"); | |
1283 | rc = -ENOMEM; | |
1284 | goto no_dd_data; | |
1285 | } | |
f1c3b0fc | 1286 | |
3b5dd52a JS |
1287 | /* Allocate buffer for command iocb */ |
1288 | ctiocb = lpfc_sli_get_iocbq(phba); | |
1289 | if (!ctiocb) { | |
1290 | rc = ENOMEM; | |
1291 | goto no_ctiocb; | |
1292 | } | |
1293 | ||
1294 | icmd = &ctiocb->iocb; | |
1295 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; | |
1296 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
1297 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
1298 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
1299 | icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); | |
1300 | icmd->un.xseq64.w5.hcsw.Fctl = (LS | LA); | |
1301 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; | |
1302 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL; | |
1303 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; | |
1304 | ||
1305 | /* Fill in rest of iocb */ | |
1306 | icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; | |
1307 | icmd->ulpBdeCount = 1; | |
1308 | icmd->ulpLe = 1; | |
1309 | icmd->ulpClass = CLASS3; | |
1310 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
1311 | /* Do not issue unsol response if oxid not marked as valid */ | |
1312 | if (!(phba->ct_ctx[tag].flags & UNSOL_VALID)) { | |
1313 | rc = IOCB_ERROR; | |
1314 | goto issue_ct_rsp_exit; | |
1315 | } | |
1316 | icmd->ulpContext = phba->ct_ctx[tag].oxid; | |
1317 | ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID); | |
1318 | if (!ndlp) { | |
1319 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
1320 | "2721 ndlp null for oxid %x SID %x\n", | |
1321 | icmd->ulpContext, | |
1322 | phba->ct_ctx[tag].SID); | |
1323 | rc = IOCB_ERROR; | |
1324 | goto issue_ct_rsp_exit; | |
1325 | } | |
1326 | icmd->un.ulpWord[3] = ndlp->nlp_rpi; | |
1327 | /* The exchange is done, mark the entry as invalid */ | |
1328 | phba->ct_ctx[tag].flags &= ~UNSOL_VALID; | |
1329 | } else | |
1330 | icmd->ulpContext = (ushort) tag; | |
1331 | ||
1332 | icmd->ulpTimeout = phba->fc_ratov * 2; | |
1333 | ||
1334 | /* Xmit CT response on exchange <xid> */ | |
1335 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
1336 | "2722 Xmit CT response on exchange x%x Data: x%x x%x\n", | |
1337 | icmd->ulpContext, icmd->ulpIoTag, phba->link_state); | |
1338 | ||
1339 | ctiocb->iocb_cmpl = NULL; | |
1340 | ctiocb->iocb_flag |= LPFC_IO_LIBDFC; | |
1341 | ctiocb->vport = phba->pport; | |
1342 | ctiocb->context3 = bmp; | |
1343 | ||
1344 | ctiocb->iocb_cmpl = lpfc_issue_ct_rsp_cmp; | |
1345 | ctiocb->context1 = dd_data; | |
1346 | ctiocb->context2 = NULL; | |
1347 | dd_data->type = TYPE_IOCB; | |
1348 | dd_data->context_un.iocb.cmdiocbq = ctiocb; | |
1349 | dd_data->context_un.iocb.rspiocbq = NULL; | |
1350 | dd_data->context_un.iocb.set_job = job; | |
1351 | dd_data->context_un.iocb.bmp = bmp; | |
1352 | dd_data->context_un.iocb.ndlp = ndlp; | |
1353 | ||
1354 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
1355 | creg_val = readl(phba->HCregaddr); | |
1356 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
1357 | writel(creg_val, phba->HCregaddr); | |
1358 | readl(phba->HCregaddr); /* flush */ | |
f1c3b0fc | 1359 | } |
4cc0e56e | 1360 | |
3b5dd52a JS |
1361 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
1362 | ||
1363 | if (rc == IOCB_SUCCESS) | |
1364 | return 0; /* done for now */ | |
1365 | ||
1366 | issue_ct_rsp_exit: | |
1367 | lpfc_sli_release_iocbq(phba, ctiocb); | |
1368 | no_ctiocb: | |
1369 | kfree(dd_data); | |
1370 | no_dd_data: | |
4cc0e56e | 1371 | return rc; |
f1c3b0fc JS |
1372 | } |
1373 | ||
1374 | /** | |
3b5dd52a JS |
1375 | * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command |
1376 | * @job: SEND_MGMT_RESP fc_bsg_job | |
1377 | **/ | |
1378 | static int | |
1379 | lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job) | |
f1c3b0fc | 1380 | { |
3b5dd52a JS |
1381 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
1382 | struct lpfc_hba *phba = vport->phba; | |
1383 | struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *) | |
1384 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1385 | struct ulp_bde64 *bpl; | |
1386 | struct lpfc_dmabuf *bmp = NULL; | |
1387 | struct scatterlist *sgel = NULL; | |
1388 | int request_nseg; | |
1389 | int numbde; | |
1390 | dma_addr_t busaddr; | |
1391 | uint32_t tag = mgmt_resp->tag; | |
1392 | unsigned long reqbfrcnt = | |
1393 | (unsigned long)job->request_payload.payload_len; | |
1394 | int rc = 0; | |
f1c3b0fc | 1395 | |
3b5dd52a JS |
1396 | /* in case no data is transferred */ |
1397 | job->reply->reply_payload_rcv_len = 0; | |
1398 | ||
1399 | if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) { | |
1400 | rc = -ERANGE; | |
1401 | goto send_mgmt_rsp_exit; | |
1402 | } | |
1403 | ||
1404 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
1405 | if (!bmp) { | |
1406 | rc = -ENOMEM; | |
1407 | goto send_mgmt_rsp_exit; | |
1408 | } | |
1409 | ||
1410 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); | |
1411 | if (!bmp->virt) { | |
1412 | rc = -ENOMEM; | |
1413 | goto send_mgmt_rsp_free_bmp; | |
1414 | } | |
1415 | ||
1416 | INIT_LIST_HEAD(&bmp->list); | |
1417 | bpl = (struct ulp_bde64 *) bmp->virt; | |
1418 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, | |
1419 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1420 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { | |
1421 | busaddr = sg_dma_address(sgel); | |
1422 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1423 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
1424 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
1425 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
1426 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
1427 | bpl++; | |
f1c3b0fc JS |
1428 | } |
1429 | ||
3b5dd52a JS |
1430 | rc = lpfc_issue_ct_rsp(phba, job, tag, bmp, request_nseg); |
1431 | ||
1432 | if (rc == IOCB_SUCCESS) | |
1433 | return 0; /* done for now */ | |
1434 | ||
1435 | /* TBD need to handle a timeout */ | |
1436 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
1437 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1438 | rc = -EACCES; | |
1439 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
1440 | ||
1441 | send_mgmt_rsp_free_bmp: | |
1442 | kfree(bmp); | |
1443 | send_mgmt_rsp_exit: | |
1444 | /* make error code available to userspace */ | |
1445 | job->reply->result = rc; | |
1446 | job->dd_data = NULL; | |
f1c3b0fc JS |
1447 | return rc; |
1448 | } | |
1449 | ||
1450 | /** | |
3b5dd52a JS |
1451 | * lpfc_bsg_diag_mode - process a LPFC_BSG_VENDOR_DIAG_MODE bsg vendor command |
1452 | * @job: LPFC_BSG_VENDOR_DIAG_MODE | |
f1c3b0fc | 1453 | * |
3b5dd52a JS |
1454 | * This function is responsible for placing a port into diagnostic loopback |
1455 | * mode in order to perform a diagnostic loopback test. | |
1456 | * All new scsi requests are blocked, a small delay is used to allow the | |
1457 | * scsi requests to complete then the link is brought down. If the link is | |
1458 | * is placed in loopback mode then scsi requests are again allowed | |
1459 | * so the scsi mid-layer doesn't give up on the port. | |
1460 | * All of this is done in-line. | |
f1c3b0fc | 1461 | */ |
3b5dd52a JS |
1462 | static int |
1463 | lpfc_bsg_diag_mode(struct fc_bsg_job *job) | |
f1c3b0fc | 1464 | { |
3b5dd52a | 1465 | struct Scsi_Host *shost = job->shost; |
f1c3b0fc JS |
1466 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
1467 | struct lpfc_hba *phba = vport->phba; | |
3b5dd52a JS |
1468 | struct diag_mode_set *loopback_mode; |
1469 | struct lpfc_sli *psli = &phba->sli; | |
1470 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; | |
1471 | uint32_t link_flags; | |
1472 | uint32_t timeout; | |
1473 | struct lpfc_vport **vports; | |
1474 | LPFC_MBOXQ_t *pmboxq; | |
1475 | int mbxstatus; | |
1476 | int i = 0; | |
1477 | int rc = 0; | |
f1c3b0fc | 1478 | |
3b5dd52a JS |
1479 | /* no data to return just the return code */ |
1480 | job->reply->reply_payload_rcv_len = 0; | |
1481 | ||
1482 | if (job->request_len < | |
1483 | sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_set)) { | |
1484 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
1485 | "2738 Received DIAG MODE request below minimum " | |
1486 | "size\n"); | |
1487 | rc = -EINVAL; | |
1488 | goto job_error; | |
1489 | } | |
1490 | ||
1491 | loopback_mode = (struct diag_mode_set *) | |
1492 | job->request->rqst_data.h_vendor.vendor_cmd; | |
1493 | link_flags = loopback_mode->type; | |
1494 | timeout = loopback_mode->timeout; | |
1495 | ||
1496 | if ((phba->link_state == LPFC_HBA_ERROR) || | |
1497 | (psli->sli_flag & LPFC_BLOCK_MGMT_IO) || | |
1498 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) { | |
1499 | rc = -EACCES; | |
1500 | goto job_error; | |
1501 | } | |
1502 | ||
1503 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1504 | if (!pmboxq) { | |
1505 | rc = -ENOMEM; | |
1506 | goto job_error; | |
1507 | } | |
1508 | ||
1509 | vports = lpfc_create_vport_work_array(phba); | |
1510 | if (vports) { | |
1511 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
1512 | shost = lpfc_shost_from_vport(vports[i]); | |
1513 | scsi_block_requests(shost); | |
1514 | } | |
1515 | ||
1516 | lpfc_destroy_vport_work_array(phba, vports); | |
1517 | } else { | |
1518 | shost = lpfc_shost_from_vport(phba->pport); | |
1519 | scsi_block_requests(shost); | |
1520 | } | |
1521 | ||
1522 | while (pring->txcmplq_cnt) { | |
1523 | if (i++ > 500) /* wait up to 5 seconds */ | |
1524 | break; | |
1525 | ||
1526 | msleep(10); | |
1527 | } | |
1528 | ||
1529 | memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
1530 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; | |
1531 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
1532 | ||
1533 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); | |
1534 | ||
1535 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) { | |
1536 | /* wait for link down before proceeding */ | |
1537 | i = 0; | |
1538 | while (phba->link_state != LPFC_LINK_DOWN) { | |
1539 | if (i++ > timeout) { | |
1540 | rc = -ETIMEDOUT; | |
1541 | goto loopback_mode_exit; | |
1542 | } | |
1543 | ||
1544 | msleep(10); | |
1545 | } | |
1546 | ||
1547 | memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
1548 | if (link_flags == INTERNAL_LOOP_BACK) | |
1549 | pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB; | |
1550 | else | |
1551 | pmboxq->u.mb.un.varInitLnk.link_flags = | |
1552 | FLAGS_TOPOLOGY_MODE_LOOP; | |
1553 | ||
1554 | pmboxq->u.mb.mbxCommand = MBX_INIT_LINK; | |
1555 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
1556 | ||
1557 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | |
1558 | LPFC_MBOX_TMO); | |
1559 | ||
1560 | if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) | |
1561 | rc = -ENODEV; | |
1562 | else { | |
1563 | phba->link_flag |= LS_LOOPBACK_MODE; | |
1564 | /* wait for the link attention interrupt */ | |
1565 | msleep(100); | |
1566 | ||
1567 | i = 0; | |
1568 | while (phba->link_state != LPFC_HBA_READY) { | |
1569 | if (i++ > timeout) { | |
1570 | rc = -ETIMEDOUT; | |
1571 | break; | |
1572 | } | |
1573 | ||
1574 | msleep(10); | |
1575 | } | |
1576 | } | |
1577 | ||
1578 | } else | |
1579 | rc = -ENODEV; | |
1580 | ||
1581 | loopback_mode_exit: | |
1582 | vports = lpfc_create_vport_work_array(phba); | |
1583 | if (vports) { | |
1584 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
1585 | shost = lpfc_shost_from_vport(vports[i]); | |
1586 | scsi_unblock_requests(shost); | |
1587 | } | |
1588 | lpfc_destroy_vport_work_array(phba, vports); | |
1589 | } else { | |
1590 | shost = lpfc_shost_from_vport(phba->pport); | |
1591 | scsi_unblock_requests(shost); | |
1592 | } | |
1593 | ||
1594 | /* | |
1595 | * Let SLI layer release mboxq if mbox command completed after timeout. | |
1596 | */ | |
1597 | if (mbxstatus != MBX_TIMEOUT) | |
1598 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1599 | ||
1600 | job_error: | |
1601 | /* make error code available to userspace */ | |
1602 | job->reply->result = rc; | |
1603 | /* complete the job back to userspace if no error */ | |
1604 | if (rc == 0) | |
1605 | job->job_done(job); | |
1606 | return rc; | |
1607 | } | |
1608 | ||
1609 | /** | |
1610 | * lpfcdiag_loop_self_reg - obtains a remote port login id | |
1611 | * @phba: Pointer to HBA context object | |
1612 | * @rpi: Pointer to a remote port login id | |
1613 | * | |
1614 | * This function obtains a remote port login id so the diag loopback test | |
1615 | * can send and receive its own unsolicited CT command. | |
1616 | **/ | |
1617 | static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t * rpi) | |
1618 | { | |
1619 | LPFC_MBOXQ_t *mbox; | |
1620 | struct lpfc_dmabuf *dmabuff; | |
1621 | int status; | |
1622 | ||
1623 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1624 | if (!mbox) | |
1625 | return ENOMEM; | |
1626 | ||
1627 | status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID, | |
1628 | (uint8_t *)&phba->pport->fc_sparam, mbox, 0); | |
1629 | if (status) { | |
1630 | mempool_free(mbox, phba->mbox_mem_pool); | |
1631 | return ENOMEM; | |
1632 | } | |
1633 | ||
1634 | dmabuff = (struct lpfc_dmabuf *) mbox->context1; | |
1635 | mbox->context1 = NULL; | |
1636 | status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
1637 | ||
1638 | if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { | |
1639 | lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys); | |
1640 | kfree(dmabuff); | |
1641 | if (status != MBX_TIMEOUT) | |
1642 | mempool_free(mbox, phba->mbox_mem_pool); | |
1643 | return ENODEV; | |
1644 | } | |
1645 | ||
1646 | *rpi = mbox->u.mb.un.varWords[0]; | |
1647 | ||
1648 | lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys); | |
1649 | kfree(dmabuff); | |
1650 | mempool_free(mbox, phba->mbox_mem_pool); | |
1651 | return 0; | |
1652 | } | |
1653 | ||
1654 | /** | |
1655 | * lpfcdiag_loop_self_unreg - unregs from the rpi | |
1656 | * @phba: Pointer to HBA context object | |
1657 | * @rpi: Remote port login id | |
1658 | * | |
1659 | * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg | |
1660 | **/ | |
1661 | static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi) | |
1662 | { | |
1663 | LPFC_MBOXQ_t *mbox; | |
1664 | int status; | |
1665 | ||
1666 | /* Allocate mboxq structure */ | |
1667 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1668 | if (mbox == NULL) | |
1669 | return ENOMEM; | |
1670 | ||
1671 | lpfc_unreg_login(phba, 0, rpi, mbox); | |
1672 | status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
1673 | ||
1674 | if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { | |
1675 | if (status != MBX_TIMEOUT) | |
1676 | mempool_free(mbox, phba->mbox_mem_pool); | |
1677 | return EIO; | |
1678 | } | |
1679 | ||
1680 | mempool_free(mbox, phba->mbox_mem_pool); | |
1681 | return 0; | |
1682 | } | |
1683 | ||
1684 | /** | |
1685 | * lpfcdiag_loop_get_xri - obtains the transmit and receive ids | |
1686 | * @phba: Pointer to HBA context object | |
1687 | * @rpi: Remote port login id | |
1688 | * @txxri: Pointer to transmit exchange id | |
1689 | * @rxxri: Pointer to response exchabge id | |
1690 | * | |
1691 | * This function obtains the transmit and receive ids required to send | |
1692 | * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp | |
1693 | * flags are used to the unsolicted response handler is able to process | |
1694 | * the ct command sent on the same port. | |
1695 | **/ | |
1696 | static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi, | |
1697 | uint16_t *txxri, uint16_t * rxxri) | |
1698 | { | |
1699 | struct lpfc_bsg_event *evt; | |
1700 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; | |
1701 | IOCB_t *cmd, *rsp; | |
1702 | struct lpfc_dmabuf *dmabuf; | |
1703 | struct ulp_bde64 *bpl = NULL; | |
1704 | struct lpfc_sli_ct_request *ctreq = NULL; | |
1705 | int ret_val = 0; | |
1706 | unsigned long flags; | |
1707 | ||
1708 | *txxri = 0; | |
1709 | *rxxri = 0; | |
1710 | evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, | |
1711 | SLI_CT_ELX_LOOPBACK); | |
1712 | if (!evt) | |
1713 | return ENOMEM; | |
1714 | ||
1715 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
1716 | list_add(&evt->node, &phba->ct_ev_waiters); | |
1717 | lpfc_bsg_event_ref(evt); | |
1718 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
1719 | ||
1720 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
1721 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
1722 | ||
1723 | dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
1724 | if (dmabuf) { | |
1725 | dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys); | |
c7495937 JS |
1726 | if (dmabuf->virt) { |
1727 | INIT_LIST_HEAD(&dmabuf->list); | |
1728 | bpl = (struct ulp_bde64 *) dmabuf->virt; | |
1729 | memset(bpl, 0, sizeof(*bpl)); | |
1730 | ctreq = (struct lpfc_sli_ct_request *)(bpl + 1); | |
1731 | bpl->addrHigh = | |
1732 | le32_to_cpu(putPaddrHigh(dmabuf->phys + | |
1733 | sizeof(*bpl))); | |
1734 | bpl->addrLow = | |
1735 | le32_to_cpu(putPaddrLow(dmabuf->phys + | |
1736 | sizeof(*bpl))); | |
1737 | bpl->tus.f.bdeFlags = 0; | |
1738 | bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ; | |
1739 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1740 | } | |
3b5dd52a JS |
1741 | } |
1742 | ||
1743 | if (cmdiocbq == NULL || rspiocbq == NULL || | |
c7495937 JS |
1744 | dmabuf == NULL || bpl == NULL || ctreq == NULL || |
1745 | dmabuf->virt == NULL) { | |
3b5dd52a JS |
1746 | ret_val = ENOMEM; |
1747 | goto err_get_xri_exit; | |
1748 | } | |
1749 | ||
1750 | cmd = &cmdiocbq->iocb; | |
1751 | rsp = &rspiocbq->iocb; | |
1752 | ||
1753 | memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ); | |
1754 | ||
1755 | ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
1756 | ctreq->RevisionId.bits.InId = 0; | |
1757 | ctreq->FsType = SLI_CT_ELX_LOOPBACK; | |
1758 | ctreq->FsSubType = 0; | |
1759 | ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP; | |
1760 | ctreq->CommandResponse.bits.Size = 0; | |
1761 | ||
1762 | ||
1763 | cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(dmabuf->phys); | |
1764 | cmd->un.xseq64.bdl.addrLow = putPaddrLow(dmabuf->phys); | |
1765 | cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
1766 | cmd->un.xseq64.bdl.bdeSize = sizeof(*bpl); | |
1767 | ||
1768 | cmd->un.xseq64.w5.hcsw.Fctl = LA; | |
1769 | cmd->un.xseq64.w5.hcsw.Dfctl = 0; | |
1770 | cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; | |
1771 | cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; | |
1772 | ||
1773 | cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR; | |
1774 | cmd->ulpBdeCount = 1; | |
1775 | cmd->ulpLe = 1; | |
1776 | cmd->ulpClass = CLASS3; | |
1777 | cmd->ulpContext = rpi; | |
1778 | ||
1779 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
1780 | cmdiocbq->vport = phba->pport; | |
1781 | ||
1782 | ret_val = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, | |
1783 | rspiocbq, | |
1784 | (phba->fc_ratov * 2) | |
1785 | + LPFC_DRVR_TIMEOUT); | |
1786 | if (ret_val) | |
1787 | goto err_get_xri_exit; | |
1788 | ||
1789 | *txxri = rsp->ulpContext; | |
1790 | ||
1791 | evt->waiting = 1; | |
1792 | evt->wait_time_stamp = jiffies; | |
1793 | ret_val = wait_event_interruptible_timeout( | |
1794 | evt->wq, !list_empty(&evt->events_to_see), | |
1795 | ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ); | |
1796 | if (list_empty(&evt->events_to_see)) | |
1797 | ret_val = (ret_val) ? EINTR : ETIMEDOUT; | |
1798 | else { | |
1799 | ret_val = IOCB_SUCCESS; | |
1800 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
1801 | list_move(evt->events_to_see.prev, &evt->events_to_get); | |
1802 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
1803 | *rxxri = (list_entry(evt->events_to_get.prev, | |
1804 | typeof(struct event_data), | |
1805 | node))->immed_dat; | |
1806 | } | |
1807 | evt->waiting = 0; | |
1808 | ||
1809 | err_get_xri_exit: | |
1810 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
1811 | lpfc_bsg_event_unref(evt); /* release ref */ | |
1812 | lpfc_bsg_event_unref(evt); /* delete */ | |
1813 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
1814 | ||
1815 | if (dmabuf) { | |
1816 | if (dmabuf->virt) | |
1817 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); | |
1818 | kfree(dmabuf); | |
1819 | } | |
1820 | ||
1821 | if (cmdiocbq && (ret_val != IOCB_TIMEDOUT)) | |
1822 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
1823 | if (rspiocbq) | |
1824 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
1825 | return ret_val; | |
1826 | } | |
1827 | ||
1828 | /** | |
1829 | * diag_cmd_data_alloc - fills in a bde struct with dma buffers | |
1830 | * @phba: Pointer to HBA context object | |
1831 | * @bpl: Pointer to 64 bit bde structure | |
1832 | * @size: Number of bytes to process | |
1833 | * @nocopydata: Flag to copy user data into the allocated buffer | |
1834 | * | |
1835 | * This function allocates page size buffers and populates an lpfc_dmabufext. | |
1836 | * If allowed the user data pointed to with indataptr is copied into the kernel | |
1837 | * memory. The chained list of page size buffers is returned. | |
1838 | **/ | |
1839 | static struct lpfc_dmabufext * | |
1840 | diag_cmd_data_alloc(struct lpfc_hba *phba, | |
1841 | struct ulp_bde64 *bpl, uint32_t size, | |
1842 | int nocopydata) | |
1843 | { | |
1844 | struct lpfc_dmabufext *mlist = NULL; | |
1845 | struct lpfc_dmabufext *dmp; | |
1846 | int cnt, offset = 0, i = 0; | |
1847 | struct pci_dev *pcidev; | |
1848 | ||
1849 | pcidev = phba->pcidev; | |
1850 | ||
1851 | while (size) { | |
1852 | /* We get chunks of 4K */ | |
1853 | if (size > BUF_SZ_4K) | |
1854 | cnt = BUF_SZ_4K; | |
1855 | else | |
1856 | cnt = size; | |
1857 | ||
1858 | /* allocate struct lpfc_dmabufext buffer header */ | |
1859 | dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL); | |
1860 | if (!dmp) | |
1861 | goto out; | |
1862 | ||
1863 | INIT_LIST_HEAD(&dmp->dma.list); | |
1864 | ||
1865 | /* Queue it to a linked list */ | |
1866 | if (mlist) | |
1867 | list_add_tail(&dmp->dma.list, &mlist->dma.list); | |
1868 | else | |
1869 | mlist = dmp; | |
1870 | ||
1871 | /* allocate buffer */ | |
1872 | dmp->dma.virt = dma_alloc_coherent(&pcidev->dev, | |
1873 | cnt, | |
1874 | &(dmp->dma.phys), | |
1875 | GFP_KERNEL); | |
1876 | ||
1877 | if (!dmp->dma.virt) | |
1878 | goto out; | |
1879 | ||
1880 | dmp->size = cnt; | |
1881 | ||
1882 | if (nocopydata) { | |
1883 | bpl->tus.f.bdeFlags = 0; | |
1884 | pci_dma_sync_single_for_device(phba->pcidev, | |
1885 | dmp->dma.phys, LPFC_BPL_SIZE, PCI_DMA_TODEVICE); | |
1886 | ||
1887 | } else { | |
1888 | memset((uint8_t *)dmp->dma.virt, 0, cnt); | |
1889 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
1890 | } | |
1891 | ||
1892 | /* build buffer ptr list for IOCB */ | |
1893 | bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys)); | |
1894 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys)); | |
1895 | bpl->tus.f.bdeSize = (ushort) cnt; | |
1896 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1897 | bpl++; | |
1898 | ||
1899 | i++; | |
1900 | offset += cnt; | |
1901 | size -= cnt; | |
1902 | } | |
1903 | ||
1904 | mlist->flag = i; | |
1905 | return mlist; | |
1906 | out: | |
1907 | diag_cmd_data_free(phba, mlist); | |
1908 | return NULL; | |
1909 | } | |
1910 | ||
1911 | /** | |
1912 | * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd | |
1913 | * @phba: Pointer to HBA context object | |
1914 | * @rxxri: Receive exchange id | |
1915 | * @len: Number of data bytes | |
1916 | * | |
1917 | * This function allocates and posts a data buffer of sufficient size to recieve | |
1918 | * an unsolicted CT command. | |
1919 | **/ | |
1920 | static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri, | |
1921 | size_t len) | |
1922 | { | |
1923 | struct lpfc_sli *psli = &phba->sli; | |
1924 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
1925 | struct lpfc_iocbq *cmdiocbq; | |
1926 | IOCB_t *cmd = NULL; | |
1927 | struct list_head head, *curr, *next; | |
1928 | struct lpfc_dmabuf *rxbmp; | |
1929 | struct lpfc_dmabuf *dmp; | |
1930 | struct lpfc_dmabuf *mp[2] = {NULL, NULL}; | |
1931 | struct ulp_bde64 *rxbpl = NULL; | |
1932 | uint32_t num_bde; | |
1933 | struct lpfc_dmabufext *rxbuffer = NULL; | |
1934 | int ret_val = 0; | |
1935 | int i = 0; | |
1936 | ||
1937 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
1938 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
1939 | if (rxbmp != NULL) { | |
1940 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); | |
c7495937 JS |
1941 | if (rxbmp->virt) { |
1942 | INIT_LIST_HEAD(&rxbmp->list); | |
1943 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; | |
1944 | rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0); | |
1945 | } | |
3b5dd52a JS |
1946 | } |
1947 | ||
1948 | if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) { | |
1949 | ret_val = ENOMEM; | |
1950 | goto err_post_rxbufs_exit; | |
1951 | } | |
1952 | ||
1953 | /* Queue buffers for the receive exchange */ | |
1954 | num_bde = (uint32_t)rxbuffer->flag; | |
1955 | dmp = &rxbuffer->dma; | |
1956 | ||
1957 | cmd = &cmdiocbq->iocb; | |
1958 | i = 0; | |
1959 | ||
1960 | INIT_LIST_HEAD(&head); | |
1961 | list_add_tail(&head, &dmp->list); | |
1962 | list_for_each_safe(curr, next, &head) { | |
1963 | mp[i] = list_entry(curr, struct lpfc_dmabuf, list); | |
1964 | list_del(curr); | |
1965 | ||
1966 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { | |
1967 | mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba); | |
1968 | cmd->un.quexri64cx.buff.bde.addrHigh = | |
1969 | putPaddrHigh(mp[i]->phys); | |
1970 | cmd->un.quexri64cx.buff.bde.addrLow = | |
1971 | putPaddrLow(mp[i]->phys); | |
1972 | cmd->un.quexri64cx.buff.bde.tus.f.bdeSize = | |
1973 | ((struct lpfc_dmabufext *)mp[i])->size; | |
1974 | cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag; | |
1975 | cmd->ulpCommand = CMD_QUE_XRI64_CX; | |
1976 | cmd->ulpPU = 0; | |
1977 | cmd->ulpLe = 1; | |
1978 | cmd->ulpBdeCount = 1; | |
1979 | cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0; | |
1980 | ||
1981 | } else { | |
1982 | cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys); | |
1983 | cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys); | |
1984 | cmd->un.cont64[i].tus.f.bdeSize = | |
1985 | ((struct lpfc_dmabufext *)mp[i])->size; | |
1986 | cmd->ulpBdeCount = ++i; | |
1987 | ||
1988 | if ((--num_bde > 0) && (i < 2)) | |
1989 | continue; | |
1990 | ||
1991 | cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX; | |
1992 | cmd->ulpLe = 1; | |
1993 | } | |
1994 | ||
1995 | cmd->ulpClass = CLASS3; | |
1996 | cmd->ulpContext = rxxri; | |
1997 | ||
1998 | ret_val = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); | |
1999 | ||
2000 | if (ret_val == IOCB_ERROR) { | |
2001 | diag_cmd_data_free(phba, | |
2002 | (struct lpfc_dmabufext *)mp[0]); | |
2003 | if (mp[1]) | |
2004 | diag_cmd_data_free(phba, | |
2005 | (struct lpfc_dmabufext *)mp[1]); | |
2006 | dmp = list_entry(next, struct lpfc_dmabuf, list); | |
2007 | ret_val = EIO; | |
2008 | goto err_post_rxbufs_exit; | |
2009 | } | |
2010 | ||
2011 | lpfc_sli_ringpostbuf_put(phba, pring, mp[0]); | |
2012 | if (mp[1]) { | |
2013 | lpfc_sli_ringpostbuf_put(phba, pring, mp[1]); | |
2014 | mp[1] = NULL; | |
2015 | } | |
2016 | ||
2017 | /* The iocb was freed by lpfc_sli_issue_iocb */ | |
2018 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
2019 | if (!cmdiocbq) { | |
2020 | dmp = list_entry(next, struct lpfc_dmabuf, list); | |
2021 | ret_val = EIO; | |
2022 | goto err_post_rxbufs_exit; | |
2023 | } | |
2024 | ||
2025 | cmd = &cmdiocbq->iocb; | |
2026 | i = 0; | |
2027 | } | |
2028 | list_del(&head); | |
2029 | ||
2030 | err_post_rxbufs_exit: | |
2031 | ||
2032 | if (rxbmp) { | |
2033 | if (rxbmp->virt) | |
2034 | lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys); | |
2035 | kfree(rxbmp); | |
2036 | } | |
2037 | ||
2038 | if (cmdiocbq) | |
2039 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
2040 | return ret_val; | |
2041 | } | |
2042 | ||
2043 | /** | |
2044 | * lpfc_bsg_diag_test - with a port in loopback issues a Ct cmd to itself | |
2045 | * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job | |
2046 | * | |
2047 | * This function receives a user data buffer to be transmitted and received on | |
2048 | * the same port, the link must be up and in loopback mode prior | |
2049 | * to being called. | |
2050 | * 1. A kernel buffer is allocated to copy the user data into. | |
2051 | * 2. The port registers with "itself". | |
2052 | * 3. The transmit and receive exchange ids are obtained. | |
2053 | * 4. The receive exchange id is posted. | |
2054 | * 5. A new els loopback event is created. | |
2055 | * 6. The command and response iocbs are allocated. | |
2056 | * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback. | |
2057 | * | |
2058 | * This function is meant to be called n times while the port is in loopback | |
2059 | * so it is the apps responsibility to issue a reset to take the port out | |
2060 | * of loopback mode. | |
2061 | **/ | |
2062 | static int | |
2063 | lpfc_bsg_diag_test(struct fc_bsg_job *job) | |
2064 | { | |
2065 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
2066 | struct lpfc_hba *phba = vport->phba; | |
2067 | struct diag_mode_test *diag_mode; | |
2068 | struct lpfc_bsg_event *evt; | |
2069 | struct event_data *evdat; | |
2070 | struct lpfc_sli *psli = &phba->sli; | |
2071 | uint32_t size; | |
2072 | uint32_t full_size; | |
2073 | size_t segment_len = 0, segment_offset = 0, current_offset = 0; | |
2074 | uint16_t rpi; | |
2075 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; | |
2076 | IOCB_t *cmd, *rsp; | |
2077 | struct lpfc_sli_ct_request *ctreq; | |
2078 | struct lpfc_dmabuf *txbmp; | |
2079 | struct ulp_bde64 *txbpl = NULL; | |
2080 | struct lpfc_dmabufext *txbuffer = NULL; | |
2081 | struct list_head head; | |
2082 | struct lpfc_dmabuf *curr; | |
2083 | uint16_t txxri, rxxri; | |
2084 | uint32_t num_bde; | |
2085 | uint8_t *ptr = NULL, *rx_databuf = NULL; | |
2086 | int rc = 0; | |
2087 | unsigned long flags; | |
2088 | void *dataout = NULL; | |
2089 | uint32_t total_mem; | |
2090 | ||
2091 | /* in case no data is returned return just the return code */ | |
2092 | job->reply->reply_payload_rcv_len = 0; | |
2093 | ||
2094 | if (job->request_len < | |
2095 | sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) { | |
2096 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2097 | "2739 Received DIAG TEST request below minimum " | |
2098 | "size\n"); | |
2099 | rc = -EINVAL; | |
2100 | goto loopback_test_exit; | |
2101 | } | |
2102 | ||
2103 | if (job->request_payload.payload_len != | |
2104 | job->reply_payload.payload_len) { | |
2105 | rc = -EINVAL; | |
2106 | goto loopback_test_exit; | |
2107 | } | |
2108 | ||
2109 | diag_mode = (struct diag_mode_test *) | |
2110 | job->request->rqst_data.h_vendor.vendor_cmd; | |
2111 | ||
2112 | if ((phba->link_state == LPFC_HBA_ERROR) || | |
2113 | (psli->sli_flag & LPFC_BLOCK_MGMT_IO) || | |
2114 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) { | |
2115 | rc = -EACCES; | |
2116 | goto loopback_test_exit; | |
2117 | } | |
2118 | ||
2119 | if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) { | |
2120 | rc = -EACCES; | |
2121 | goto loopback_test_exit; | |
2122 | } | |
2123 | ||
2124 | size = job->request_payload.payload_len; | |
2125 | full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */ | |
2126 | ||
2127 | if ((size == 0) || (size > 80 * BUF_SZ_4K)) { | |
2128 | rc = -ERANGE; | |
2129 | goto loopback_test_exit; | |
2130 | } | |
2131 | ||
2132 | if (size >= BUF_SZ_4K) { | |
2133 | /* | |
2134 | * Allocate memory for ioctl data. If buffer is bigger than 64k, | |
2135 | * then we allocate 64k and re-use that buffer over and over to | |
2136 | * xfer the whole block. This is because Linux kernel has a | |
2137 | * problem allocating more than 120k of kernel space memory. Saw | |
2138 | * problem with GET_FCPTARGETMAPPING... | |
2139 | */ | |
2140 | if (size <= (64 * 1024)) | |
2141 | total_mem = size; | |
2142 | else | |
2143 | total_mem = 64 * 1024; | |
2144 | } else | |
2145 | /* Allocate memory for ioctl data */ | |
2146 | total_mem = BUF_SZ_4K; | |
2147 | ||
2148 | dataout = kmalloc(total_mem, GFP_KERNEL); | |
2149 | if (dataout == NULL) { | |
2150 | rc = -ENOMEM; | |
2151 | goto loopback_test_exit; | |
2152 | } | |
2153 | ||
2154 | ptr = dataout; | |
2155 | ptr += ELX_LOOPBACK_HEADER_SZ; | |
2156 | sg_copy_to_buffer(job->request_payload.sg_list, | |
2157 | job->request_payload.sg_cnt, | |
2158 | ptr, size); | |
2159 | ||
2160 | rc = lpfcdiag_loop_self_reg(phba, &rpi); | |
2161 | if (rc) { | |
2162 | rc = -ENOMEM; | |
2163 | goto loopback_test_exit; | |
2164 | } | |
2165 | ||
2166 | rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri); | |
2167 | if (rc) { | |
2168 | lpfcdiag_loop_self_unreg(phba, rpi); | |
2169 | rc = -ENOMEM; | |
2170 | goto loopback_test_exit; | |
2171 | } | |
2172 | ||
2173 | rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size); | |
2174 | if (rc) { | |
2175 | lpfcdiag_loop_self_unreg(phba, rpi); | |
2176 | rc = -ENOMEM; | |
2177 | goto loopback_test_exit; | |
2178 | } | |
2179 | ||
2180 | evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, | |
2181 | SLI_CT_ELX_LOOPBACK); | |
2182 | if (!evt) { | |
2183 | lpfcdiag_loop_self_unreg(phba, rpi); | |
2184 | rc = -ENOMEM; | |
2185 | goto loopback_test_exit; | |
2186 | } | |
2187 | ||
2188 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2189 | list_add(&evt->node, &phba->ct_ev_waiters); | |
2190 | lpfc_bsg_event_ref(evt); | |
2191 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2192 | ||
2193 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
2194 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
2195 | txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2196 | ||
2197 | if (txbmp) { | |
2198 | txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys); | |
c7495937 JS |
2199 | if (txbmp->virt) { |
2200 | INIT_LIST_HEAD(&txbmp->list); | |
2201 | txbpl = (struct ulp_bde64 *) txbmp->virt; | |
3b5dd52a JS |
2202 | txbuffer = diag_cmd_data_alloc(phba, |
2203 | txbpl, full_size, 0); | |
c7495937 | 2204 | } |
3b5dd52a JS |
2205 | } |
2206 | ||
c7495937 JS |
2207 | if (!cmdiocbq || !rspiocbq || !txbmp || !txbpl || !txbuffer || |
2208 | !txbmp->virt) { | |
3b5dd52a JS |
2209 | rc = -ENOMEM; |
2210 | goto err_loopback_test_exit; | |
2211 | } | |
2212 | ||
2213 | cmd = &cmdiocbq->iocb; | |
2214 | rsp = &rspiocbq->iocb; | |
2215 | ||
2216 | INIT_LIST_HEAD(&head); | |
2217 | list_add_tail(&head, &txbuffer->dma.list); | |
2218 | list_for_each_entry(curr, &head, list) { | |
2219 | segment_len = ((struct lpfc_dmabufext *)curr)->size; | |
2220 | if (current_offset == 0) { | |
2221 | ctreq = curr->virt; | |
2222 | memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ); | |
2223 | ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
2224 | ctreq->RevisionId.bits.InId = 0; | |
2225 | ctreq->FsType = SLI_CT_ELX_LOOPBACK; | |
2226 | ctreq->FsSubType = 0; | |
2227 | ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_DATA; | |
2228 | ctreq->CommandResponse.bits.Size = size; | |
2229 | segment_offset = ELX_LOOPBACK_HEADER_SZ; | |
2230 | } else | |
2231 | segment_offset = 0; | |
2232 | ||
2233 | BUG_ON(segment_offset >= segment_len); | |
2234 | memcpy(curr->virt + segment_offset, | |
2235 | ptr + current_offset, | |
2236 | segment_len - segment_offset); | |
2237 | ||
2238 | current_offset += segment_len - segment_offset; | |
2239 | BUG_ON(current_offset > size); | |
2240 | } | |
2241 | list_del(&head); | |
2242 | ||
2243 | /* Build the XMIT_SEQUENCE iocb */ | |
2244 | ||
2245 | num_bde = (uint32_t)txbuffer->flag; | |
2246 | ||
2247 | cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(txbmp->phys); | |
2248 | cmd->un.xseq64.bdl.addrLow = putPaddrLow(txbmp->phys); | |
2249 | cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
2250 | cmd->un.xseq64.bdl.bdeSize = (num_bde * sizeof(struct ulp_bde64)); | |
2251 | ||
2252 | cmd->un.xseq64.w5.hcsw.Fctl = (LS | LA); | |
2253 | cmd->un.xseq64.w5.hcsw.Dfctl = 0; | |
2254 | cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; | |
2255 | cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; | |
2256 | ||
2257 | cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; | |
2258 | cmd->ulpBdeCount = 1; | |
2259 | cmd->ulpLe = 1; | |
2260 | cmd->ulpClass = CLASS3; | |
2261 | cmd->ulpContext = txxri; | |
2262 | ||
2263 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
2264 | cmdiocbq->vport = phba->pport; | |
2265 | ||
2266 | rc = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, rspiocbq, | |
2267 | (phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT); | |
2268 | ||
2269 | if ((rc != IOCB_SUCCESS) || (rsp->ulpStatus != IOCB_SUCCESS)) { | |
2270 | rc = -EIO; | |
2271 | goto err_loopback_test_exit; | |
2272 | } | |
2273 | ||
2274 | evt->waiting = 1; | |
2275 | rc = wait_event_interruptible_timeout( | |
2276 | evt->wq, !list_empty(&evt->events_to_see), | |
2277 | ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ); | |
2278 | evt->waiting = 0; | |
2279 | if (list_empty(&evt->events_to_see)) | |
2280 | rc = (rc) ? -EINTR : -ETIMEDOUT; | |
2281 | else { | |
2282 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2283 | list_move(evt->events_to_see.prev, &evt->events_to_get); | |
2284 | evdat = list_entry(evt->events_to_get.prev, | |
2285 | typeof(*evdat), node); | |
2286 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2287 | rx_databuf = evdat->data; | |
2288 | if (evdat->len != full_size) { | |
2289 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, | |
2290 | "1603 Loopback test did not receive expected " | |
2291 | "data length. actual length 0x%x expected " | |
2292 | "length 0x%x\n", | |
2293 | evdat->len, full_size); | |
2294 | rc = -EIO; | |
2295 | } else if (rx_databuf == NULL) | |
2296 | rc = -EIO; | |
2297 | else { | |
2298 | rc = IOCB_SUCCESS; | |
2299 | /* skip over elx loopback header */ | |
2300 | rx_databuf += ELX_LOOPBACK_HEADER_SZ; | |
2301 | job->reply->reply_payload_rcv_len = | |
2302 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
2303 | job->reply_payload.sg_cnt, | |
2304 | rx_databuf, size); | |
2305 | job->reply->reply_payload_rcv_len = size; | |
2306 | } | |
2307 | } | |
2308 | ||
2309 | err_loopback_test_exit: | |
2310 | lpfcdiag_loop_self_unreg(phba, rpi); | |
2311 | ||
2312 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2313 | lpfc_bsg_event_unref(evt); /* release ref */ | |
2314 | lpfc_bsg_event_unref(evt); /* delete */ | |
2315 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2316 | ||
2317 | if (cmdiocbq != NULL) | |
2318 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
2319 | ||
2320 | if (rspiocbq != NULL) | |
2321 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
2322 | ||
2323 | if (txbmp != NULL) { | |
2324 | if (txbpl != NULL) { | |
2325 | if (txbuffer != NULL) | |
2326 | diag_cmd_data_free(phba, txbuffer); | |
2327 | lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys); | |
2328 | } | |
2329 | kfree(txbmp); | |
2330 | } | |
2331 | ||
2332 | loopback_test_exit: | |
2333 | kfree(dataout); | |
2334 | /* make error code available to userspace */ | |
2335 | job->reply->result = rc; | |
2336 | job->dd_data = NULL; | |
2337 | /* complete the job back to userspace if no error */ | |
2338 | if (rc == 0) | |
2339 | job->job_done(job); | |
2340 | return rc; | |
2341 | } | |
2342 | ||
2343 | /** | |
2344 | * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command | |
2345 | * @job: GET_DFC_REV fc_bsg_job | |
2346 | **/ | |
2347 | static int | |
2348 | lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job) | |
2349 | { | |
2350 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
2351 | struct lpfc_hba *phba = vport->phba; | |
2352 | struct get_mgmt_rev *event_req; | |
2353 | struct get_mgmt_rev_reply *event_reply; | |
2354 | int rc = 0; | |
2355 | ||
2356 | if (job->request_len < | |
2357 | sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) { | |
2358 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2359 | "2740 Received GET_DFC_REV request below " | |
2360 | "minimum size\n"); | |
2361 | rc = -EINVAL; | |
2362 | goto job_error; | |
2363 | } | |
2364 | ||
2365 | event_req = (struct get_mgmt_rev *) | |
2366 | job->request->rqst_data.h_vendor.vendor_cmd; | |
2367 | ||
2368 | event_reply = (struct get_mgmt_rev_reply *) | |
2369 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
2370 | ||
2371 | if (job->reply_len < | |
2372 | sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev_reply)) { | |
2373 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2374 | "2741 Received GET_DFC_REV reply below " | |
2375 | "minimum size\n"); | |
2376 | rc = -EINVAL; | |
2377 | goto job_error; | |
2378 | } | |
2379 | ||
2380 | event_reply->info.a_Major = MANAGEMENT_MAJOR_REV; | |
2381 | event_reply->info.a_Minor = MANAGEMENT_MINOR_REV; | |
2382 | job_error: | |
2383 | job->reply->result = rc; | |
2384 | if (rc == 0) | |
2385 | job->job_done(job); | |
2386 | return rc; | |
2387 | } | |
2388 | ||
2389 | /** | |
2390 | * lpfc_bsg_wake_mbox_wait - lpfc_bsg_issue_mbox mbox completion handler | |
2391 | * @phba: Pointer to HBA context object. | |
2392 | * @pmboxq: Pointer to mailbox command. | |
2393 | * | |
2394 | * This is completion handler function for mailbox commands issued from | |
2395 | * lpfc_bsg_issue_mbox function. This function is called by the | |
2396 | * mailbox event handler function with no lock held. This function | |
2397 | * will wake up thread waiting on the wait queue pointed by context1 | |
2398 | * of the mailbox. | |
2399 | **/ | |
2400 | void | |
2401 | lpfc_bsg_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
2402 | { | |
2403 | struct bsg_job_data *dd_data; | |
3b5dd52a JS |
2404 | struct fc_bsg_job *job; |
2405 | uint32_t size; | |
2406 | unsigned long flags; | |
7a470277 JS |
2407 | uint8_t *to; |
2408 | uint8_t *from; | |
3b5dd52a JS |
2409 | |
2410 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
2411 | dd_data = pmboxq->context1; | |
7a470277 | 2412 | /* job already timed out? */ |
3b5dd52a JS |
2413 | if (!dd_data) { |
2414 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
2415 | return; | |
2416 | } | |
2417 | ||
7a470277 JS |
2418 | /* build the outgoing buffer to do an sg copy |
2419 | * the format is the response mailbox followed by any extended | |
2420 | * mailbox data | |
2421 | */ | |
2422 | from = (uint8_t *)&pmboxq->u.mb; | |
2423 | to = (uint8_t *)dd_data->context_un.mbox.mb; | |
2424 | memcpy(to, from, sizeof(MAILBOX_t)); | |
c7495937 JS |
2425 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) { |
2426 | /* copy the extended data if any, count is in words */ | |
2427 | if (dd_data->context_un.mbox.outExtWLen) { | |
2428 | from = (uint8_t *)dd_data->context_un.mbox.ext; | |
2429 | to += sizeof(MAILBOX_t); | |
2430 | size = dd_data->context_un.mbox.outExtWLen * | |
2431 | sizeof(uint32_t); | |
2432 | memcpy(to, from, size); | |
2433 | } else if (pmboxq->u.mb.mbxCommand == MBX_RUN_BIU_DIAG64) { | |
2434 | from = (uint8_t *)dd_data->context_un.mbox. | |
2435 | dmp->dma.virt; | |
2436 | to += sizeof(MAILBOX_t); | |
2437 | size = dd_data->context_un.mbox.dmp->size; | |
2438 | memcpy(to, from, size); | |
2439 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && | |
2440 | (pmboxq->u.mb.mbxCommand == MBX_DUMP_MEMORY)) { | |
2441 | from = (uint8_t *)dd_data->context_un.mbox.dmp->dma. | |
2442 | virt; | |
2443 | to += sizeof(MAILBOX_t); | |
2444 | size = pmboxq->u.mb.un.varWords[5]; | |
2445 | memcpy(to, from, size); | |
2446 | } else if (pmboxq->u.mb.mbxCommand == MBX_READ_EVENT_LOG) { | |
2447 | from = (uint8_t *)dd_data->context_un. | |
2448 | mbox.dmp->dma.virt; | |
2449 | to += sizeof(MAILBOX_t); | |
2450 | size = dd_data->context_un.mbox.dmp->size; | |
2451 | memcpy(to, from, size); | |
2452 | } | |
7a470277 JS |
2453 | } |
2454 | ||
2455 | from = (uint8_t *)dd_data->context_un.mbox.mb; | |
3b5dd52a | 2456 | job = dd_data->context_un.mbox.set_job; |
7a470277 | 2457 | size = job->reply_payload.payload_len; |
3b5dd52a JS |
2458 | job->reply->reply_payload_rcv_len = |
2459 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
2460 | job->reply_payload.sg_cnt, | |
7a470277 | 2461 | from, size); |
3b5dd52a | 2462 | job->reply->result = 0; |
7a470277 | 2463 | |
3b5dd52a JS |
2464 | dd_data->context_un.mbox.set_job = NULL; |
2465 | job->dd_data = NULL; | |
2466 | job->job_done(job); | |
7a470277 JS |
2467 | /* need to hold the lock until we call job done to hold off |
2468 | * the timeout handler returning to the midlayer while | |
2469 | * we are stillprocessing the job | |
2470 | */ | |
3b5dd52a | 2471 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
7a470277 JS |
2472 | |
2473 | kfree(dd_data->context_un.mbox.mb); | |
3b5dd52a | 2474 | mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool); |
7a470277 JS |
2475 | kfree(dd_data->context_un.mbox.ext); |
2476 | if (dd_data->context_un.mbox.dmp) { | |
2477 | dma_free_coherent(&phba->pcidev->dev, | |
2478 | dd_data->context_un.mbox.dmp->size, | |
2479 | dd_data->context_un.mbox.dmp->dma.virt, | |
2480 | dd_data->context_un.mbox.dmp->dma.phys); | |
2481 | kfree(dd_data->context_un.mbox.dmp); | |
2482 | } | |
2483 | if (dd_data->context_un.mbox.rxbmp) { | |
2484 | lpfc_mbuf_free(phba, dd_data->context_un.mbox.rxbmp->virt, | |
2485 | dd_data->context_un.mbox.rxbmp->phys); | |
2486 | kfree(dd_data->context_un.mbox.rxbmp); | |
2487 | } | |
3b5dd52a JS |
2488 | kfree(dd_data); |
2489 | return; | |
2490 | } | |
2491 | ||
2492 | /** | |
2493 | * lpfc_bsg_check_cmd_access - test for a supported mailbox command | |
2494 | * @phba: Pointer to HBA context object. | |
2495 | * @mb: Pointer to a mailbox object. | |
2496 | * @vport: Pointer to a vport object. | |
2497 | * | |
2498 | * Some commands require the port to be offline, some may not be called from | |
2499 | * the application. | |
2500 | **/ | |
2501 | static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba, | |
2502 | MAILBOX_t *mb, struct lpfc_vport *vport) | |
2503 | { | |
2504 | /* return negative error values for bsg job */ | |
2505 | switch (mb->mbxCommand) { | |
2506 | /* Offline only */ | |
2507 | case MBX_INIT_LINK: | |
2508 | case MBX_DOWN_LINK: | |
2509 | case MBX_CONFIG_LINK: | |
2510 | case MBX_CONFIG_RING: | |
2511 | case MBX_RESET_RING: | |
2512 | case MBX_UNREG_LOGIN: | |
2513 | case MBX_CLEAR_LA: | |
2514 | case MBX_DUMP_CONTEXT: | |
2515 | case MBX_RUN_DIAGS: | |
2516 | case MBX_RESTART: | |
2517 | case MBX_SET_MASK: | |
2518 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { | |
2519 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2520 | "2743 Command 0x%x is illegal in on-line " | |
2521 | "state\n", | |
2522 | mb->mbxCommand); | |
2523 | return -EPERM; | |
2524 | } | |
2525 | case MBX_WRITE_NV: | |
2526 | case MBX_WRITE_VPARMS: | |
2527 | case MBX_LOAD_SM: | |
2528 | case MBX_READ_NV: | |
2529 | case MBX_READ_CONFIG: | |
2530 | case MBX_READ_RCONFIG: | |
2531 | case MBX_READ_STATUS: | |
2532 | case MBX_READ_XRI: | |
2533 | case MBX_READ_REV: | |
2534 | case MBX_READ_LNK_STAT: | |
2535 | case MBX_DUMP_MEMORY: | |
2536 | case MBX_DOWN_LOAD: | |
2537 | case MBX_UPDATE_CFG: | |
2538 | case MBX_KILL_BOARD: | |
2539 | case MBX_LOAD_AREA: | |
2540 | case MBX_LOAD_EXP_ROM: | |
2541 | case MBX_BEACON: | |
2542 | case MBX_DEL_LD_ENTRY: | |
2543 | case MBX_SET_DEBUG: | |
2544 | case MBX_WRITE_WWN: | |
2545 | case MBX_SLI4_CONFIG: | |
c7495937 | 2546 | case MBX_READ_EVENT_LOG: |
3b5dd52a JS |
2547 | case MBX_READ_EVENT_LOG_STATUS: |
2548 | case MBX_WRITE_EVENT_LOG: | |
2549 | case MBX_PORT_CAPABILITIES: | |
2550 | case MBX_PORT_IOV_CONTROL: | |
7a470277 | 2551 | case MBX_RUN_BIU_DIAG64: |
3b5dd52a JS |
2552 | break; |
2553 | case MBX_SET_VARIABLE: | |
e2aed29f JS |
2554 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2555 | "1226 mbox: set_variable 0x%x, 0x%x\n", | |
2556 | mb->un.varWords[0], | |
2557 | mb->un.varWords[1]); | |
2558 | if ((mb->un.varWords[0] == SETVAR_MLOMNT) | |
2559 | && (mb->un.varWords[1] == 1)) { | |
2560 | phba->wait_4_mlo_maint_flg = 1; | |
2561 | } else if (mb->un.varWords[0] == SETVAR_MLORST) { | |
2562 | phba->link_flag &= ~LS_LOOPBACK_MODE; | |
2563 | phba->fc_topology = TOPOLOGY_PT_PT; | |
2564 | } | |
2565 | break; | |
3b5dd52a JS |
2566 | case MBX_READ_SPARM64: |
2567 | case MBX_READ_LA: | |
2568 | case MBX_READ_LA64: | |
2569 | case MBX_REG_LOGIN: | |
2570 | case MBX_REG_LOGIN64: | |
2571 | case MBX_CONFIG_PORT: | |
2572 | case MBX_RUN_BIU_DIAG: | |
2573 | default: | |
2574 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2575 | "2742 Unknown Command 0x%x\n", | |
2576 | mb->mbxCommand); | |
2577 | return -EPERM; | |
2578 | } | |
2579 | ||
2580 | return 0; /* ok */ | |
2581 | } | |
2582 | ||
2583 | /** | |
2584 | * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app | |
2585 | * @phba: Pointer to HBA context object. | |
2586 | * @mb: Pointer to a mailbox object. | |
2587 | * @vport: Pointer to a vport object. | |
2588 | * | |
2589 | * Allocate a tracking object, mailbox command memory, get a mailbox | |
2590 | * from the mailbox pool, copy the caller mailbox command. | |
2591 | * | |
2592 | * If offline and the sli is active we need to poll for the command (port is | |
2593 | * being reset) and com-plete the job, otherwise issue the mailbox command and | |
2594 | * let our completion handler finish the command. | |
2595 | **/ | |
2596 | static uint32_t | |
2597 | lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job, | |
2598 | struct lpfc_vport *vport) | |
2599 | { | |
7a470277 JS |
2600 | LPFC_MBOXQ_t *pmboxq = NULL; /* internal mailbox queue */ |
2601 | MAILBOX_t *pmb; /* shortcut to the pmboxq mailbox */ | |
2602 | /* a 4k buffer to hold the mb and extended data from/to the bsg */ | |
2603 | MAILBOX_t *mb = NULL; | |
2604 | struct bsg_job_data *dd_data = NULL; /* bsg data tracking structure */ | |
3b5dd52a | 2605 | uint32_t size; |
7a470277 JS |
2606 | struct lpfc_dmabuf *rxbmp = NULL; /* for biu diag */ |
2607 | struct lpfc_dmabufext *dmp = NULL; /* for biu diag */ | |
2608 | struct ulp_bde64 *rxbpl = NULL; | |
2609 | struct dfc_mbox_req *mbox_req = (struct dfc_mbox_req *) | |
2610 | job->request->rqst_data.h_vendor.vendor_cmd; | |
2611 | uint8_t *ext = NULL; | |
3b5dd52a | 2612 | int rc = 0; |
7a470277 JS |
2613 | uint8_t *from; |
2614 | ||
2615 | /* in case no data is transferred */ | |
2616 | job->reply->reply_payload_rcv_len = 0; | |
2617 | ||
2618 | /* check if requested extended data lengths are valid */ | |
2619 | if ((mbox_req->inExtWLen > MAILBOX_EXT_SIZE) || | |
c7495937 | 2620 | (mbox_req->outExtWLen > MAILBOX_EXT_SIZE)) { |
7a470277 JS |
2621 | rc = -ERANGE; |
2622 | goto job_done; | |
2623 | } | |
3b5dd52a JS |
2624 | |
2625 | /* allocate our bsg tracking structure */ | |
2626 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
2627 | if (!dd_data) { | |
2628 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2629 | "2727 Failed allocation of dd_data\n"); | |
7a470277 JS |
2630 | rc = -ENOMEM; |
2631 | goto job_done; | |
3b5dd52a JS |
2632 | } |
2633 | ||
49198b37 | 2634 | mb = kzalloc(BSG_MBOX_SIZE, GFP_KERNEL); |
3b5dd52a | 2635 | if (!mb) { |
7a470277 JS |
2636 | rc = -ENOMEM; |
2637 | goto job_done; | |
3b5dd52a JS |
2638 | } |
2639 | ||
2640 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2641 | if (!pmboxq) { | |
7a470277 JS |
2642 | rc = -ENOMEM; |
2643 | goto job_done; | |
3b5dd52a | 2644 | } |
7a470277 | 2645 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
3b5dd52a JS |
2646 | |
2647 | size = job->request_payload.payload_len; | |
7a470277 JS |
2648 | sg_copy_to_buffer(job->request_payload.sg_list, |
2649 | job->request_payload.sg_cnt, | |
2650 | mb, size); | |
3b5dd52a JS |
2651 | |
2652 | rc = lpfc_bsg_check_cmd_access(phba, mb, vport); | |
7a470277 JS |
2653 | if (rc != 0) |
2654 | goto job_done; /* must be negative */ | |
3b5dd52a | 2655 | |
3b5dd52a JS |
2656 | pmb = &pmboxq->u.mb; |
2657 | memcpy(pmb, mb, sizeof(*pmb)); | |
2658 | pmb->mbxOwner = OWN_HOST; | |
3b5dd52a JS |
2659 | pmboxq->vport = vport; |
2660 | ||
c7495937 JS |
2661 | /* If HBA encountered an error attention, allow only DUMP |
2662 | * or RESTART mailbox commands until the HBA is restarted. | |
2663 | */ | |
2664 | if (phba->pport->stopped && | |
2665 | pmb->mbxCommand != MBX_DUMP_MEMORY && | |
2666 | pmb->mbxCommand != MBX_RESTART && | |
2667 | pmb->mbxCommand != MBX_WRITE_VPARMS && | |
2668 | pmb->mbxCommand != MBX_WRITE_WWN) | |
2669 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
2670 | "2797 mbox: Issued mailbox cmd " | |
2671 | "0x%x while in stopped state.\n", | |
2672 | pmb->mbxCommand); | |
2673 | ||
2674 | /* Don't allow mailbox commands to be sent when blocked | |
2675 | * or when in the middle of discovery | |
2676 | */ | |
2677 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { | |
2678 | rc = -EAGAIN; | |
2679 | goto job_done; | |
2680 | } | |
2681 | ||
7a470277 | 2682 | /* extended mailbox commands will need an extended buffer */ |
c7495937 | 2683 | if (mbox_req->inExtWLen || mbox_req->outExtWLen) { |
7a470277 JS |
2684 | ext = kzalloc(MAILBOX_EXT_SIZE, GFP_KERNEL); |
2685 | if (!ext) { | |
2686 | rc = -ENOMEM; | |
2687 | goto job_done; | |
2688 | } | |
2689 | ||
2690 | /* any data for the device? */ | |
2691 | if (mbox_req->inExtWLen) { | |
2692 | from = (uint8_t *)mb; | |
2693 | from += sizeof(MAILBOX_t); | |
2694 | memcpy((uint8_t *)ext, from, | |
2695 | mbox_req->inExtWLen * sizeof(uint32_t)); | |
2696 | } | |
2697 | ||
2698 | pmboxq->context2 = ext; | |
2699 | pmboxq->in_ext_byte_len = | |
2700 | mbox_req->inExtWLen * | |
2701 | sizeof(uint32_t); | |
2702 | pmboxq->out_ext_byte_len = | |
c7495937 | 2703 | mbox_req->outExtWLen * |
7a470277 JS |
2704 | sizeof(uint32_t); |
2705 | pmboxq->mbox_offset_word = | |
2706 | mbox_req->mbOffset; | |
2707 | pmboxq->context2 = ext; | |
2708 | pmboxq->in_ext_byte_len = | |
2709 | mbox_req->inExtWLen * sizeof(uint32_t); | |
2710 | pmboxq->out_ext_byte_len = | |
c7495937 | 2711 | mbox_req->outExtWLen * sizeof(uint32_t); |
7a470277 JS |
2712 | pmboxq->mbox_offset_word = mbox_req->mbOffset; |
2713 | } | |
2714 | ||
2715 | /* biu diag will need a kernel buffer to transfer the data | |
2716 | * allocate our own buffer and setup the mailbox command to | |
2717 | * use ours | |
2718 | */ | |
2719 | if (pmb->mbxCommand == MBX_RUN_BIU_DIAG64) { | |
c7495937 JS |
2720 | uint32_t transmit_length = pmb->un.varWords[1]; |
2721 | uint32_t receive_length = pmb->un.varWords[4]; | |
2722 | /* transmit length cannot be greater than receive length or | |
2723 | * mailbox extension size | |
2724 | */ | |
2725 | if ((transmit_length > receive_length) || | |
2726 | (transmit_length > MAILBOX_EXT_SIZE)) { | |
2727 | rc = -ERANGE; | |
2728 | goto job_done; | |
2729 | } | |
2730 | ||
7a470277 JS |
2731 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
2732 | if (!rxbmp) { | |
2733 | rc = -ENOMEM; | |
2734 | goto job_done; | |
2735 | } | |
2736 | ||
2737 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); | |
c7495937 JS |
2738 | if (!rxbmp->virt) { |
2739 | rc = -ENOMEM; | |
2740 | goto job_done; | |
2741 | } | |
2742 | ||
7a470277 JS |
2743 | INIT_LIST_HEAD(&rxbmp->list); |
2744 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; | |
c7495937 | 2745 | dmp = diag_cmd_data_alloc(phba, rxbpl, transmit_length, 0); |
7a470277 JS |
2746 | if (!dmp) { |
2747 | rc = -ENOMEM; | |
2748 | goto job_done; | |
2749 | } | |
2750 | ||
7a470277 JS |
2751 | INIT_LIST_HEAD(&dmp->dma.list); |
2752 | pmb->un.varBIUdiag.un.s2.xmit_bde64.addrHigh = | |
2753 | putPaddrHigh(dmp->dma.phys); | |
2754 | pmb->un.varBIUdiag.un.s2.xmit_bde64.addrLow = | |
2755 | putPaddrLow(dmp->dma.phys); | |
2756 | ||
2757 | pmb->un.varBIUdiag.un.s2.rcv_bde64.addrHigh = | |
2758 | putPaddrHigh(dmp->dma.phys + | |
2759 | pmb->un.varBIUdiag.un.s2. | |
2760 | xmit_bde64.tus.f.bdeSize); | |
2761 | pmb->un.varBIUdiag.un.s2.rcv_bde64.addrLow = | |
2762 | putPaddrLow(dmp->dma.phys + | |
2763 | pmb->un.varBIUdiag.un.s2. | |
2764 | xmit_bde64.tus.f.bdeSize); | |
c7495937 JS |
2765 | |
2766 | /* copy the transmit data found in the mailbox extension area */ | |
2767 | from = (uint8_t *)mb; | |
2768 | from += sizeof(MAILBOX_t); | |
2769 | memcpy((uint8_t *)dmp->dma.virt, from, transmit_length); | |
2770 | } else if (pmb->mbxCommand == MBX_READ_EVENT_LOG) { | |
2771 | struct READ_EVENT_LOG_VAR *rdEventLog = | |
2772 | &pmb->un.varRdEventLog ; | |
2773 | uint32_t receive_length = rdEventLog->rcv_bde64.tus.f.bdeSize; | |
2774 | uint32_t mode = bf_get(lpfc_event_log, rdEventLog); | |
2775 | ||
2776 | /* receive length cannot be greater than mailbox | |
2777 | * extension size | |
2778 | */ | |
2779 | if (receive_length > MAILBOX_EXT_SIZE) { | |
2780 | rc = -ERANGE; | |
2781 | goto job_done; | |
2782 | } | |
2783 | ||
2784 | /* mode zero uses a bde like biu diags command */ | |
2785 | if (mode == 0) { | |
2786 | ||
2787 | /* rebuild the command for sli4 using our own buffers | |
2788 | * like we do for biu diags | |
2789 | */ | |
2790 | ||
2791 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2792 | if (!rxbmp) { | |
2793 | rc = -ENOMEM; | |
2794 | goto job_done; | |
2795 | } | |
2796 | ||
2797 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); | |
2798 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; | |
2799 | if (rxbpl) { | |
2800 | INIT_LIST_HEAD(&rxbmp->list); | |
2801 | dmp = diag_cmd_data_alloc(phba, rxbpl, | |
2802 | receive_length, 0); | |
2803 | } | |
2804 | ||
2805 | if (!dmp) { | |
2806 | rc = -ENOMEM; | |
2807 | goto job_done; | |
2808 | } | |
2809 | ||
2810 | INIT_LIST_HEAD(&dmp->dma.list); | |
2811 | pmb->un.varWords[3] = putPaddrLow(dmp->dma.phys); | |
2812 | pmb->un.varWords[4] = putPaddrHigh(dmp->dma.phys); | |
2813 | } | |
2814 | } else if (phba->sli_rev == LPFC_SLI_REV4) { | |
2815 | if (pmb->mbxCommand == MBX_DUMP_MEMORY) { | |
2816 | /* rebuild the command for sli4 using our own buffers | |
2817 | * like we do for biu diags | |
2818 | */ | |
2819 | uint32_t receive_length = pmb->un.varWords[2]; | |
2820 | /* receive length cannot be greater than mailbox | |
2821 | * extension size | |
2822 | */ | |
2823 | if ((receive_length == 0) || | |
2824 | (receive_length > MAILBOX_EXT_SIZE)) { | |
2825 | rc = -ERANGE; | |
2826 | goto job_done; | |
2827 | } | |
2828 | ||
2829 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2830 | if (!rxbmp) { | |
2831 | rc = -ENOMEM; | |
2832 | goto job_done; | |
2833 | } | |
2834 | ||
2835 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); | |
2836 | if (!rxbmp->virt) { | |
2837 | rc = -ENOMEM; | |
2838 | goto job_done; | |
2839 | } | |
2840 | ||
2841 | INIT_LIST_HEAD(&rxbmp->list); | |
2842 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; | |
2843 | dmp = diag_cmd_data_alloc(phba, rxbpl, receive_length, | |
2844 | 0); | |
2845 | if (!dmp) { | |
2846 | rc = -ENOMEM; | |
2847 | goto job_done; | |
2848 | } | |
2849 | ||
2850 | INIT_LIST_HEAD(&dmp->dma.list); | |
2851 | pmb->un.varWords[3] = putPaddrLow(dmp->dma.phys); | |
2852 | pmb->un.varWords[4] = putPaddrHigh(dmp->dma.phys); | |
2853 | } else if ((pmb->mbxCommand == MBX_UPDATE_CFG) && | |
2854 | pmb->un.varUpdateCfg.co) { | |
2855 | struct ulp_bde64 *bde = | |
2856 | (struct ulp_bde64 *)&pmb->un.varWords[4]; | |
2857 | ||
2858 | /* bde size cannot be greater than mailbox ext size */ | |
2859 | if (bde->tus.f.bdeSize > MAILBOX_EXT_SIZE) { | |
2860 | rc = -ERANGE; | |
2861 | goto job_done; | |
2862 | } | |
2863 | ||
2864 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
2865 | if (!rxbmp) { | |
2866 | rc = -ENOMEM; | |
2867 | goto job_done; | |
2868 | } | |
2869 | ||
2870 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); | |
2871 | if (!rxbmp->virt) { | |
2872 | rc = -ENOMEM; | |
2873 | goto job_done; | |
2874 | } | |
2875 | ||
2876 | INIT_LIST_HEAD(&rxbmp->list); | |
2877 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; | |
2878 | dmp = diag_cmd_data_alloc(phba, rxbpl, | |
2879 | bde->tus.f.bdeSize, 0); | |
2880 | if (!dmp) { | |
2881 | rc = -ENOMEM; | |
2882 | goto job_done; | |
2883 | } | |
2884 | ||
2885 | INIT_LIST_HEAD(&dmp->dma.list); | |
2886 | bde->addrHigh = putPaddrHigh(dmp->dma.phys); | |
2887 | bde->addrLow = putPaddrLow(dmp->dma.phys); | |
2888 | ||
2889 | /* copy the transmit data found in the mailbox | |
2890 | * extension area | |
2891 | */ | |
2892 | from = (uint8_t *)mb; | |
2893 | from += sizeof(MAILBOX_t); | |
2894 | memcpy((uint8_t *)dmp->dma.virt, from, | |
2895 | bde->tus.f.bdeSize); | |
2896 | } | |
7a470277 JS |
2897 | } |
2898 | ||
c7495937 JS |
2899 | dd_data->context_un.mbox.rxbmp = rxbmp; |
2900 | dd_data->context_un.mbox.dmp = dmp; | |
2901 | ||
7a470277 JS |
2902 | /* setup wake call as IOCB callback */ |
2903 | pmboxq->mbox_cmpl = lpfc_bsg_wake_mbox_wait; | |
2904 | ||
2905 | /* setup context field to pass wait_queue pointer to wake function */ | |
2906 | pmboxq->context1 = dd_data; | |
2907 | dd_data->type = TYPE_MBOX; | |
2908 | dd_data->context_un.mbox.pmboxq = pmboxq; | |
2909 | dd_data->context_un.mbox.mb = mb; | |
2910 | dd_data->context_un.mbox.set_job = job; | |
2911 | dd_data->context_un.mbox.ext = ext; | |
2912 | dd_data->context_un.mbox.mbOffset = mbox_req->mbOffset; | |
2913 | dd_data->context_un.mbox.inExtWLen = mbox_req->inExtWLen; | |
c7495937 | 2914 | dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen; |
7a470277 JS |
2915 | job->dd_data = dd_data; |
2916 | ||
3b5dd52a JS |
2917 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
2918 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) { | |
2919 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | |
2920 | if (rc != MBX_SUCCESS) { | |
7a470277 JS |
2921 | rc = (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
2922 | goto job_done; | |
3b5dd52a JS |
2923 | } |
2924 | ||
7a470277 | 2925 | /* job finished, copy the data */ |
3b5dd52a JS |
2926 | memcpy(mb, pmb, sizeof(*pmb)); |
2927 | job->reply->reply_payload_rcv_len = | |
2928 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
2929 | job->reply_payload.sg_cnt, | |
2930 | mb, size); | |
3b5dd52a | 2931 | /* not waiting mbox already done */ |
7a470277 JS |
2932 | rc = 0; |
2933 | goto job_done; | |
3b5dd52a JS |
2934 | } |
2935 | ||
3b5dd52a | 2936 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
7a470277 JS |
2937 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) |
2938 | return 1; /* job started */ | |
2939 | ||
2940 | job_done: | |
2941 | /* common exit for error or job completed inline */ | |
2942 | kfree(mb); | |
2943 | if (pmboxq) | |
3b5dd52a | 2944 | mempool_free(pmboxq, phba->mbox_mem_pool); |
7a470277 JS |
2945 | kfree(ext); |
2946 | if (dmp) { | |
2947 | dma_free_coherent(&phba->pcidev->dev, | |
2948 | dmp->size, dmp->dma.virt, | |
2949 | dmp->dma.phys); | |
2950 | kfree(dmp); | |
2951 | } | |
2952 | if (rxbmp) { | |
2953 | lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys); | |
2954 | kfree(rxbmp); | |
3b5dd52a | 2955 | } |
7a470277 | 2956 | kfree(dd_data); |
3b5dd52a | 2957 | |
7a470277 | 2958 | return rc; |
3b5dd52a JS |
2959 | } |
2960 | ||
2961 | /** | |
2962 | * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command | |
2963 | * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX. | |
2964 | **/ | |
2965 | static int | |
2966 | lpfc_bsg_mbox_cmd(struct fc_bsg_job *job) | |
2967 | { | |
2968 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
2969 | struct lpfc_hba *phba = vport->phba; | |
2970 | int rc = 0; | |
2971 | ||
2972 | /* in case no data is transferred */ | |
2973 | job->reply->reply_payload_rcv_len = 0; | |
2974 | if (job->request_len < | |
2975 | sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) { | |
2976 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
2977 | "2737 Received MBOX_REQ request below " | |
2978 | "minimum size\n"); | |
2979 | rc = -EINVAL; | |
2980 | goto job_error; | |
2981 | } | |
2982 | ||
49198b37 | 2983 | if (job->request_payload.payload_len != BSG_MBOX_SIZE) { |
3b5dd52a JS |
2984 | rc = -EINVAL; |
2985 | goto job_error; | |
2986 | } | |
2987 | ||
49198b37 | 2988 | if (job->reply_payload.payload_len != BSG_MBOX_SIZE) { |
7a470277 JS |
2989 | rc = -EINVAL; |
2990 | goto job_error; | |
2991 | } | |
2992 | ||
3b5dd52a JS |
2993 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { |
2994 | rc = -EAGAIN; | |
2995 | goto job_error; | |
2996 | } | |
2997 | ||
2998 | rc = lpfc_bsg_issue_mbox(phba, job, vport); | |
2999 | ||
3000 | job_error: | |
3001 | if (rc == 0) { | |
3002 | /* job done */ | |
3003 | job->reply->result = 0; | |
3004 | job->dd_data = NULL; | |
3005 | job->job_done(job); | |
3006 | } else if (rc == 1) | |
3007 | /* job submitted, will complete later*/ | |
3008 | rc = 0; /* return zero, no error */ | |
3009 | else { | |
3010 | /* some error occurred */ | |
3011 | job->reply->result = rc; | |
3012 | job->dd_data = NULL; | |
3013 | } | |
3014 | ||
3015 | return rc; | |
3016 | } | |
3017 | ||
e2aed29f JS |
3018 | /** |
3019 | * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler | |
3020 | * @phba: Pointer to HBA context object. | |
3021 | * @cmdiocbq: Pointer to command iocb. | |
3022 | * @rspiocbq: Pointer to response iocb. | |
3023 | * | |
3024 | * This function is the completion handler for iocbs issued using | |
3025 | * lpfc_menlo_cmd function. This function is called by the | |
3026 | * ring event handler function without any lock held. This function | |
3027 | * can be called from both worker thread context and interrupt | |
3028 | * context. This function also can be called from another thread which | |
3029 | * cleans up the SLI layer objects. | |
3030 | * This function copies the contents of the response iocb to the | |
3031 | * response iocb memory object provided by the caller of | |
3032 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
3033 | * sleeps for the iocb completion. | |
3034 | **/ | |
3035 | static void | |
3036 | lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba *phba, | |
3037 | struct lpfc_iocbq *cmdiocbq, | |
3038 | struct lpfc_iocbq *rspiocbq) | |
3039 | { | |
3040 | struct bsg_job_data *dd_data; | |
3041 | struct fc_bsg_job *job; | |
3042 | IOCB_t *rsp; | |
3043 | struct lpfc_dmabuf *bmp; | |
3044 | struct lpfc_bsg_menlo *menlo; | |
3045 | unsigned long flags; | |
3046 | struct menlo_response *menlo_resp; | |
3047 | int rc = 0; | |
3048 | ||
3049 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
3050 | dd_data = cmdiocbq->context1; | |
3051 | if (!dd_data) { | |
3052 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3053 | return; | |
3054 | } | |
3055 | ||
3056 | menlo = &dd_data->context_un.menlo; | |
3057 | job = menlo->set_job; | |
3058 | job->dd_data = NULL; /* so timeout handler does not reply */ | |
3059 | ||
3060 | spin_lock_irqsave(&phba->hbalock, flags); | |
3061 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; | |
3062 | if (cmdiocbq->context2 && rspiocbq) | |
3063 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
3064 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
3065 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
3066 | ||
3067 | bmp = menlo->bmp; | |
3068 | rspiocbq = menlo->rspiocbq; | |
3069 | rsp = &rspiocbq->iocb; | |
3070 | ||
3071 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
3072 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
3073 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
3074 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
3075 | ||
3076 | /* always return the xri, this would be used in the case | |
3077 | * of a menlo download to allow the data to be sent as a continuation | |
3078 | * of the exchange. | |
3079 | */ | |
3080 | menlo_resp = (struct menlo_response *) | |
3081 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
3082 | menlo_resp->xri = rsp->ulpContext; | |
3083 | if (rsp->ulpStatus) { | |
3084 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
3085 | switch (rsp->un.ulpWord[4] & 0xff) { | |
3086 | case IOERR_SEQUENCE_TIMEOUT: | |
3087 | rc = -ETIMEDOUT; | |
3088 | break; | |
3089 | case IOERR_INVALID_RPI: | |
3090 | rc = -EFAULT; | |
3091 | break; | |
3092 | default: | |
3093 | rc = -EACCES; | |
3094 | break; | |
3095 | } | |
3096 | } else | |
3097 | rc = -EACCES; | |
3098 | } else | |
3099 | job->reply->reply_payload_rcv_len = | |
3100 | rsp->un.genreq64.bdl.bdeSize; | |
3101 | ||
3102 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
3103 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
3104 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
3105 | kfree(bmp); | |
3106 | kfree(dd_data); | |
3107 | /* make error code available to userspace */ | |
3108 | job->reply->result = rc; | |
3109 | /* complete the job back to userspace */ | |
3110 | job->job_done(job); | |
3111 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3112 | return; | |
3113 | } | |
3114 | ||
3115 | /** | |
3116 | * lpfc_menlo_cmd - send an ioctl for menlo hardware | |
3117 | * @job: fc_bsg_job to handle | |
3118 | * | |
3119 | * This function issues a gen request 64 CR ioctl for all menlo cmd requests, | |
3120 | * all the command completions will return the xri for the command. | |
3121 | * For menlo data requests a gen request 64 CX is used to continue the exchange | |
3122 | * supplied in the menlo request header xri field. | |
3123 | **/ | |
3124 | static int | |
3125 | lpfc_menlo_cmd(struct fc_bsg_job *job) | |
3126 | { | |
3127 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
3128 | struct lpfc_hba *phba = vport->phba; | |
3129 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; | |
3130 | IOCB_t *cmd, *rsp; | |
3131 | int rc = 0; | |
3132 | struct menlo_command *menlo_cmd; | |
3133 | struct menlo_response *menlo_resp; | |
3134 | struct lpfc_dmabuf *bmp = NULL; | |
3135 | int request_nseg; | |
3136 | int reply_nseg; | |
3137 | struct scatterlist *sgel = NULL; | |
3138 | int numbde; | |
3139 | dma_addr_t busaddr; | |
3140 | struct bsg_job_data *dd_data; | |
3141 | struct ulp_bde64 *bpl = NULL; | |
3142 | ||
3143 | /* in case no data is returned return just the return code */ | |
3144 | job->reply->reply_payload_rcv_len = 0; | |
3145 | ||
3146 | if (job->request_len < | |
3147 | sizeof(struct fc_bsg_request) + | |
3148 | sizeof(struct menlo_command)) { | |
3149 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
3150 | "2784 Received MENLO_CMD request below " | |
3151 | "minimum size\n"); | |
3152 | rc = -ERANGE; | |
3153 | goto no_dd_data; | |
3154 | } | |
3155 | ||
3156 | if (job->reply_len < | |
3157 | sizeof(struct fc_bsg_request) + sizeof(struct menlo_response)) { | |
3158 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
3159 | "2785 Received MENLO_CMD reply below " | |
3160 | "minimum size\n"); | |
3161 | rc = -ERANGE; | |
3162 | goto no_dd_data; | |
3163 | } | |
3164 | ||
3165 | if (!(phba->menlo_flag & HBA_MENLO_SUPPORT)) { | |
3166 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
3167 | "2786 Adapter does not support menlo " | |
3168 | "commands\n"); | |
3169 | rc = -EPERM; | |
3170 | goto no_dd_data; | |
3171 | } | |
3172 | ||
3173 | menlo_cmd = (struct menlo_command *) | |
3174 | job->request->rqst_data.h_vendor.vendor_cmd; | |
3175 | ||
3176 | menlo_resp = (struct menlo_response *) | |
3177 | job->reply->reply_data.vendor_reply.vendor_rsp; | |
3178 | ||
3179 | /* allocate our bsg tracking structure */ | |
3180 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); | |
3181 | if (!dd_data) { | |
3182 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, | |
3183 | "2787 Failed allocation of dd_data\n"); | |
3184 | rc = -ENOMEM; | |
3185 | goto no_dd_data; | |
3186 | } | |
3187 | ||
3188 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3189 | if (!bmp) { | |
3190 | rc = -ENOMEM; | |
3191 | goto free_dd; | |
3192 | } | |
3193 | ||
3194 | cmdiocbq = lpfc_sli_get_iocbq(phba); | |
3195 | if (!cmdiocbq) { | |
3196 | rc = -ENOMEM; | |
3197 | goto free_bmp; | |
3198 | } | |
3199 | ||
3200 | rspiocbq = lpfc_sli_get_iocbq(phba); | |
3201 | if (!rspiocbq) { | |
3202 | rc = -ENOMEM; | |
3203 | goto free_cmdiocbq; | |
3204 | } | |
3205 | ||
3206 | rsp = &rspiocbq->iocb; | |
3207 | ||
3208 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); | |
3209 | if (!bmp->virt) { | |
3210 | rc = -ENOMEM; | |
3211 | goto free_rspiocbq; | |
3212 | } | |
3213 | ||
3214 | INIT_LIST_HEAD(&bmp->list); | |
3215 | bpl = (struct ulp_bde64 *) bmp->virt; | |
3216 | request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, | |
3217 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
3218 | for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { | |
3219 | busaddr = sg_dma_address(sgel); | |
3220 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
3221 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
3222 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
3223 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
3224 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
3225 | bpl++; | |
3226 | } | |
3227 | ||
3228 | reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list, | |
3229 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
3230 | for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) { | |
3231 | busaddr = sg_dma_address(sgel); | |
3232 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
3233 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
3234 | bpl->tus.w = cpu_to_le32(bpl->tus.w); | |
3235 | bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr)); | |
3236 | bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); | |
3237 | bpl++; | |
3238 | } | |
3239 | ||
3240 | cmd = &cmdiocbq->iocb; | |
3241 | cmd->un.genreq64.bdl.ulpIoTag32 = 0; | |
3242 | cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
3243 | cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
3244 | cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
3245 | cmd->un.genreq64.bdl.bdeSize = | |
3246 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); | |
3247 | cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); | |
3248 | cmd->un.genreq64.w5.hcsw.Dfctl = 0; | |
3249 | cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CMD; | |
3250 | cmd->un.genreq64.w5.hcsw.Type = MENLO_TRANSPORT_TYPE; /* 0xfe */ | |
3251 | cmd->ulpBdeCount = 1; | |
3252 | cmd->ulpClass = CLASS3; | |
3253 | cmd->ulpOwner = OWN_CHIP; | |
3254 | cmd->ulpLe = 1; /* Limited Edition */ | |
3255 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; | |
3256 | cmdiocbq->vport = phba->pport; | |
3257 | /* We want the firmware to timeout before we do */ | |
3258 | cmd->ulpTimeout = MENLO_TIMEOUT - 5; | |
3259 | cmdiocbq->context3 = bmp; | |
3260 | cmdiocbq->context2 = rspiocbq; | |
3261 | cmdiocbq->iocb_cmpl = lpfc_bsg_menlo_cmd_cmp; | |
3262 | cmdiocbq->context1 = dd_data; | |
3263 | cmdiocbq->context2 = rspiocbq; | |
3264 | if (menlo_cmd->cmd == LPFC_BSG_VENDOR_MENLO_CMD) { | |
3265 | cmd->ulpCommand = CMD_GEN_REQUEST64_CR; | |
3266 | cmd->ulpPU = MENLO_PU; /* 3 */ | |
3267 | cmd->un.ulpWord[4] = MENLO_DID; /* 0x0000FC0E */ | |
3268 | cmd->ulpContext = MENLO_CONTEXT; /* 0 */ | |
3269 | } else { | |
3270 | cmd->ulpCommand = CMD_GEN_REQUEST64_CX; | |
3271 | cmd->ulpPU = 1; | |
3272 | cmd->un.ulpWord[4] = 0; | |
3273 | cmd->ulpContext = menlo_cmd->xri; | |
3274 | } | |
3275 | ||
3276 | dd_data->type = TYPE_MENLO; | |
3277 | dd_data->context_un.menlo.cmdiocbq = cmdiocbq; | |
3278 | dd_data->context_un.menlo.rspiocbq = rspiocbq; | |
3279 | dd_data->context_un.menlo.set_job = job; | |
3280 | dd_data->context_un.menlo.bmp = bmp; | |
3281 | ||
3282 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, | |
3283 | MENLO_TIMEOUT - 5); | |
3284 | if (rc == IOCB_SUCCESS) | |
3285 | return 0; /* done for now */ | |
3286 | ||
3287 | /* iocb failed so cleanup */ | |
3288 | pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, | |
3289 | job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
3290 | pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, | |
3291 | job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
3292 | ||
3293 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); | |
3294 | ||
3295 | free_rspiocbq: | |
3296 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
3297 | free_cmdiocbq: | |
3298 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
3299 | free_bmp: | |
3300 | kfree(bmp); | |
3301 | free_dd: | |
3302 | kfree(dd_data); | |
3303 | no_dd_data: | |
3304 | /* make error code available to userspace */ | |
3305 | job->reply->result = rc; | |
3306 | job->dd_data = NULL; | |
3307 | return rc; | |
3308 | } | |
3b5dd52a JS |
3309 | /** |
3310 | * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job | |
3311 | * @job: fc_bsg_job to handle | |
3312 | **/ | |
3313 | static int | |
3314 | lpfc_bsg_hst_vendor(struct fc_bsg_job *job) | |
3315 | { | |
3316 | int command = job->request->rqst_data.h_vendor.vendor_cmd[0]; | |
3317 | int rc; | |
3318 | ||
3319 | switch (command) { | |
3320 | case LPFC_BSG_VENDOR_SET_CT_EVENT: | |
3321 | rc = lpfc_bsg_hba_set_event(job); | |
3322 | break; | |
3323 | case LPFC_BSG_VENDOR_GET_CT_EVENT: | |
3324 | rc = lpfc_bsg_hba_get_event(job); | |
3325 | break; | |
3326 | case LPFC_BSG_VENDOR_SEND_MGMT_RESP: | |
3327 | rc = lpfc_bsg_send_mgmt_rsp(job); | |
3328 | break; | |
3329 | case LPFC_BSG_VENDOR_DIAG_MODE: | |
3330 | rc = lpfc_bsg_diag_mode(job); | |
3331 | break; | |
3332 | case LPFC_BSG_VENDOR_DIAG_TEST: | |
3333 | rc = lpfc_bsg_diag_test(job); | |
3334 | break; | |
3335 | case LPFC_BSG_VENDOR_GET_MGMT_REV: | |
3336 | rc = lpfc_bsg_get_dfc_rev(job); | |
3337 | break; | |
3338 | case LPFC_BSG_VENDOR_MBOX: | |
3339 | rc = lpfc_bsg_mbox_cmd(job); | |
3340 | break; | |
e2aed29f JS |
3341 | case LPFC_BSG_VENDOR_MENLO_CMD: |
3342 | case LPFC_BSG_VENDOR_MENLO_DATA: | |
3343 | rc = lpfc_menlo_cmd(job); | |
3344 | break; | |
3b5dd52a JS |
3345 | default: |
3346 | rc = -EINVAL; | |
3347 | job->reply->reply_payload_rcv_len = 0; | |
3348 | /* make error code available to userspace */ | |
3349 | job->reply->result = rc; | |
3350 | break; | |
3351 | } | |
3352 | ||
3353 | return rc; | |
3354 | } | |
3355 | ||
3356 | /** | |
3357 | * lpfc_bsg_request - handle a bsg request from the FC transport | |
3358 | * @job: fc_bsg_job to handle | |
3359 | **/ | |
3360 | int | |
3361 | lpfc_bsg_request(struct fc_bsg_job *job) | |
3362 | { | |
3363 | uint32_t msgcode; | |
3364 | int rc; | |
3365 | ||
3366 | msgcode = job->request->msgcode; | |
3367 | switch (msgcode) { | |
3368 | case FC_BSG_HST_VENDOR: | |
3369 | rc = lpfc_bsg_hst_vendor(job); | |
3370 | break; | |
3371 | case FC_BSG_RPT_ELS: | |
3372 | rc = lpfc_bsg_rport_els(job); | |
3373 | break; | |
3374 | case FC_BSG_RPT_CT: | |
3375 | rc = lpfc_bsg_send_mgmt_cmd(job); | |
3376 | break; | |
3377 | default: | |
3378 | rc = -EINVAL; | |
3379 | job->reply->reply_payload_rcv_len = 0; | |
3380 | /* make error code available to userspace */ | |
3381 | job->reply->result = rc; | |
3382 | break; | |
3383 | } | |
3384 | ||
3385 | return rc; | |
3386 | } | |
3387 | ||
3388 | /** | |
3389 | * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport | |
3390 | * @job: fc_bsg_job that has timed out | |
3391 | * | |
3392 | * This function just aborts the job's IOCB. The aborted IOCB will return to | |
3393 | * the waiting function which will handle passing the error back to userspace | |
3394 | **/ | |
3395 | int | |
3396 | lpfc_bsg_timeout(struct fc_bsg_job *job) | |
3397 | { | |
3398 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; | |
3399 | struct lpfc_hba *phba = vport->phba; | |
3400 | struct lpfc_iocbq *cmdiocb; | |
3401 | struct lpfc_bsg_event *evt; | |
3402 | struct lpfc_bsg_iocb *iocb; | |
3403 | struct lpfc_bsg_mbox *mbox; | |
e2aed29f | 3404 | struct lpfc_bsg_menlo *menlo; |
3b5dd52a JS |
3405 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
3406 | struct bsg_job_data *dd_data; | |
3407 | unsigned long flags; | |
3408 | ||
3409 | spin_lock_irqsave(&phba->ct_ev_lock, flags); | |
3410 | dd_data = (struct bsg_job_data *)job->dd_data; | |
3411 | /* timeout and completion crossed paths if no dd_data */ | |
3412 | if (!dd_data) { | |
3413 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3414 | return 0; | |
4cc0e56e JS |
3415 | } |
3416 | ||
3417 | switch (dd_data->type) { | |
3418 | case TYPE_IOCB: | |
3419 | iocb = &dd_data->context_un.iocb; | |
3420 | cmdiocb = iocb->cmdiocbq; | |
3421 | /* hint to completion handler that the job timed out */ | |
3422 | job->reply->result = -EAGAIN; | |
3423 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3424 | /* this will call our completion handler */ | |
3425 | spin_lock_irq(&phba->hbalock); | |
f1c3b0fc | 3426 | lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); |
4cc0e56e JS |
3427 | spin_unlock_irq(&phba->hbalock); |
3428 | break; | |
3429 | case TYPE_EVT: | |
3430 | evt = dd_data->context_un.evt; | |
3431 | /* this event has no job anymore */ | |
3432 | evt->set_job = NULL; | |
3433 | job->dd_data = NULL; | |
3434 | job->reply->reply_payload_rcv_len = 0; | |
3435 | /* Return -EAGAIN which is our way of signallying the | |
3436 | * app to retry. | |
3437 | */ | |
3438 | job->reply->result = -EAGAIN; | |
3439 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3440 | job->job_done(job); | |
3441 | break; | |
3b5dd52a JS |
3442 | case TYPE_MBOX: |
3443 | mbox = &dd_data->context_un.mbox; | |
3444 | /* this mbox has no job anymore */ | |
3445 | mbox->set_job = NULL; | |
3446 | job->dd_data = NULL; | |
3447 | job->reply->reply_payload_rcv_len = 0; | |
3448 | job->reply->result = -EAGAIN; | |
7a470277 | 3449 | /* the mbox completion handler can now be run */ |
3b5dd52a JS |
3450 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
3451 | job->job_done(job); | |
3452 | break; | |
e2aed29f JS |
3453 | case TYPE_MENLO: |
3454 | menlo = &dd_data->context_un.menlo; | |
3455 | cmdiocb = menlo->cmdiocbq; | |
3456 | /* hint to completion handler that the job timed out */ | |
3457 | job->reply->result = -EAGAIN; | |
3458 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3459 | /* this will call our completion handler */ | |
3460 | spin_lock_irq(&phba->hbalock); | |
3461 | lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); | |
3462 | spin_unlock_irq(&phba->hbalock); | |
3463 | break; | |
4cc0e56e JS |
3464 | default: |
3465 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); | |
3466 | break; | |
3467 | } | |
f1c3b0fc | 3468 | |
4cc0e56e JS |
3469 | /* scsi transport fc fc_bsg_job_timeout expects a zero return code, |
3470 | * otherwise an error message will be displayed on the console | |
3471 | * so always return success (zero) | |
3472 | */ | |
f1c3b0fc JS |
3473 | return 0; |
3474 | } |