[SCSI] qla2xxx: Clean up qla24xx_iidma()
[deliverable/linux.git] / drivers / scsi / qla2xxx / qla_bsg.c
CommitLineData
6e98016c
GM
1/*
2 * QLogic Fibre Channel HBA Driver
46152ceb 3 * Copyright (c) 2003-2012 QLogic Corporation
6e98016c
GM
4 *
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7#include "qla_def.h"
8
9#include <linux/kthread.h>
10#include <linux/vmalloc.h>
11#include <linux/delay.h>
12
13/* BSG support for ELS/CT pass through */
9ba56b95
GM
14void
15qla2x00_bsg_job_done(void *data, void *ptr, int res)
6e98016c 16{
9ba56b95
GM
17 srb_t *sp = (srb_t *)ptr;
18 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
19 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
20
21 bsg_job->reply->result = res;
22 bsg_job->job_done(bsg_job);
23 sp->free(vha, sp);
24}
25
26void
27qla2x00_bsg_sp_free(void *data, void *ptr)
28{
29 srb_t *sp = (srb_t *)ptr;
b00ee7d7 30 struct scsi_qla_host *vha = sp->fcport->vha;
9ba56b95 31 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
6e98016c 32 struct qla_hw_data *ha = vha->hw;
8ae6d9c7 33 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
6e98016c 34
8ae6d9c7
GM
35 if (sp->type == SRB_FXIOCB_BCMD) {
36 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
37 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
6e98016c 38
8ae6d9c7
GM
39 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
40 dma_unmap_sg(&ha->pdev->dev,
41 bsg_job->request_payload.sg_list,
42 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
43
44 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
45 dma_unmap_sg(&ha->pdev->dev,
46 bsg_job->reply_payload.sg_list,
47 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
48 } else {
49 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
50 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
51
52 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
53 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
54 }
9ba56b95
GM
55
56 if (sp->type == SRB_CT_CMD ||
8ae6d9c7 57 sp->type == SRB_FXIOCB_BCMD ||
9ba56b95
GM
58 sp->type == SRB_ELS_CMD_HST)
59 kfree(sp->fcport);
b00ee7d7 60 qla2x00_rel_sp(vha, sp);
6e98016c
GM
61}
62
09ff701a 63int
7c3df132
SK
64qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
65 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
09ff701a
SR
66{
67 int i, ret, num_valid;
68 uint8_t *bcode;
69 struct qla_fcp_prio_entry *pri_entry;
2f0f3f4f 70 uint32_t *bcode_val_ptr, bcode_val;
09ff701a
SR
71
72 ret = 1;
73 num_valid = 0;
74 bcode = (uint8_t *)pri_cfg;
2f0f3f4f
MI
75 bcode_val_ptr = (uint32_t *)pri_cfg;
76 bcode_val = (uint32_t)(*bcode_val_ptr);
09ff701a 77
2f0f3f4f
MI
78 if (bcode_val == 0xFFFFFFFF) {
79 /* No FCP Priority config data in flash */
7c3df132
SK
80 ql_dbg(ql_dbg_user, vha, 0x7051,
81 "No FCP Priority config data.\n");
2f0f3f4f
MI
82 return 0;
83 }
84
85 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
86 bcode[3] != 'S') {
87 /* Invalid FCP priority data header*/
7c3df132
SK
88 ql_dbg(ql_dbg_user, vha, 0x7052,
89 "Invalid FCP Priority data header. bcode=0x%x.\n",
90 bcode_val);
09ff701a
SR
91 return 0;
92 }
93 if (flag != 1)
94 return ret;
95
96 pri_entry = &pri_cfg->entry[0];
97 for (i = 0; i < pri_cfg->num_entries; i++) {
98 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
99 num_valid++;
100 pri_entry++;
101 }
102
2f0f3f4f
MI
103 if (num_valid == 0) {
104 /* No valid FCP priority data entries */
7c3df132
SK
105 ql_dbg(ql_dbg_user, vha, 0x7053,
106 "No valid FCP Priority data entries.\n");
09ff701a 107 ret = 0;
2f0f3f4f
MI
108 } else {
109 /* FCP priority data is valid */
7c3df132
SK
110 ql_dbg(ql_dbg_user, vha, 0x7054,
111 "Valid FCP priority data. num entries = %d.\n",
112 num_valid);
2f0f3f4f 113 }
09ff701a
SR
114
115 return ret;
116}
117
118static int
119qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
120{
121 struct Scsi_Host *host = bsg_job->shost;
122 scsi_qla_host_t *vha = shost_priv(host);
123 struct qla_hw_data *ha = vha->hw;
124 int ret = 0;
125 uint32_t len;
126 uint32_t oper;
127
a00f6296 128 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) {
2f0f3f4f
MI
129 ret = -EINVAL;
130 goto exit_fcp_prio_cfg;
131 }
132
09ff701a
SR
133 /* Get the sub command */
134 oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
135
136 /* Only set config is allowed if config memory is not allocated */
137 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
138 ret = -EINVAL;
139 goto exit_fcp_prio_cfg;
140 }
141 switch (oper) {
142 case QLFC_FCP_PRIO_DISABLE:
143 if (ha->flags.fcp_prio_enabled) {
144 ha->flags.fcp_prio_enabled = 0;
145 ha->fcp_prio_cfg->attributes &=
146 ~FCP_PRIO_ATTR_ENABLE;
147 qla24xx_update_all_fcp_prio(vha);
148 bsg_job->reply->result = DID_OK;
149 } else {
150 ret = -EINVAL;
151 bsg_job->reply->result = (DID_ERROR << 16);
152 goto exit_fcp_prio_cfg;
153 }
154 break;
155
156 case QLFC_FCP_PRIO_ENABLE:
157 if (!ha->flags.fcp_prio_enabled) {
158 if (ha->fcp_prio_cfg) {
159 ha->flags.fcp_prio_enabled = 1;
160 ha->fcp_prio_cfg->attributes |=
161 FCP_PRIO_ATTR_ENABLE;
162 qla24xx_update_all_fcp_prio(vha);
163 bsg_job->reply->result = DID_OK;
164 } else {
165 ret = -EINVAL;
166 bsg_job->reply->result = (DID_ERROR << 16);
167 goto exit_fcp_prio_cfg;
168 }
169 }
170 break;
171
172 case QLFC_FCP_PRIO_GET_CONFIG:
173 len = bsg_job->reply_payload.payload_len;
174 if (!len || len > FCP_PRIO_CFG_SIZE) {
175 ret = -EINVAL;
176 bsg_job->reply->result = (DID_ERROR << 16);
177 goto exit_fcp_prio_cfg;
178 }
179
180 bsg_job->reply->result = DID_OK;
181 bsg_job->reply->reply_payload_rcv_len =
182 sg_copy_from_buffer(
183 bsg_job->reply_payload.sg_list,
184 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
185 len);
186
187 break;
188
189 case QLFC_FCP_PRIO_SET_CONFIG:
190 len = bsg_job->request_payload.payload_len;
191 if (!len || len > FCP_PRIO_CFG_SIZE) {
192 bsg_job->reply->result = (DID_ERROR << 16);
193 ret = -EINVAL;
194 goto exit_fcp_prio_cfg;
195 }
196
197 if (!ha->fcp_prio_cfg) {
198 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
199 if (!ha->fcp_prio_cfg) {
7c3df132
SK
200 ql_log(ql_log_warn, vha, 0x7050,
201 "Unable to allocate memory for fcp prio "
202 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
09ff701a
SR
203 bsg_job->reply->result = (DID_ERROR << 16);
204 ret = -ENOMEM;
205 goto exit_fcp_prio_cfg;
206 }
207 }
208
209 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
210 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
211 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
212 FCP_PRIO_CFG_SIZE);
213
214 /* validate fcp priority data */
7c3df132
SK
215
216 if (!qla24xx_fcp_prio_cfg_valid(vha,
217 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
09ff701a
SR
218 bsg_job->reply->result = (DID_ERROR << 16);
219 ret = -EINVAL;
220 /* If buffer was invalidatic int
221 * fcp_prio_cfg is of no use
222 */
223 vfree(ha->fcp_prio_cfg);
224 ha->fcp_prio_cfg = NULL;
225 goto exit_fcp_prio_cfg;
226 }
227
228 ha->flags.fcp_prio_enabled = 0;
229 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
230 ha->flags.fcp_prio_enabled = 1;
231 qla24xx_update_all_fcp_prio(vha);
232 bsg_job->reply->result = DID_OK;
233 break;
234 default:
235 ret = -EINVAL;
236 break;
237 }
238exit_fcp_prio_cfg:
63ea923a
AB
239 if (!ret)
240 bsg_job->job_done(bsg_job);
09ff701a
SR
241 return ret;
242}
9ba56b95 243
6e98016c
GM
244static int
245qla2x00_process_els(struct fc_bsg_job *bsg_job)
246{
247 struct fc_rport *rport;
08f71e09 248 fc_port_t *fcport = NULL;
6e98016c
GM
249 struct Scsi_Host *host;
250 scsi_qla_host_t *vha;
251 struct qla_hw_data *ha;
252 srb_t *sp;
253 const char *type;
254 int req_sg_cnt, rsp_sg_cnt;
255 int rval = (DRIVER_ERROR << 16);
256 uint16_t nextlid = 0;
6e98016c 257
08f71e09
HZ
258 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
259 rport = bsg_job->rport;
260 fcport = *(fc_port_t **) rport->dd_data;
261 host = rport_to_shost(rport);
262 vha = shost_priv(host);
263 ha = vha->hw;
264 type = "FC_BSG_RPT_ELS";
265 } else {
266 host = bsg_job->shost;
267 vha = shost_priv(host);
268 ha = vha->hw;
269 type = "FC_BSG_HST_ELS_NOLOGIN";
270 }
271
272 /* pass through is supported only for ISP 4Gb or higher */
273 if (!IS_FWI2_CAPABLE(ha)) {
7c3df132
SK
274 ql_dbg(ql_dbg_user, vha, 0x7001,
275 "ELS passthru not supported for ISP23xx based adapters.\n");
08f71e09
HZ
276 rval = -EPERM;
277 goto done;
278 }
279
6e98016c
GM
280 /* Multiple SG's are not supported for ELS requests */
281 if (bsg_job->request_payload.sg_cnt > 1 ||
282 bsg_job->reply_payload.sg_cnt > 1) {
7c3df132
SK
283 ql_dbg(ql_dbg_user, vha, 0x7002,
284 "Multiple SG's are not suppored for ELS requests, "
285 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
286 bsg_job->request_payload.sg_cnt,
287 bsg_job->reply_payload.sg_cnt);
6e98016c
GM
288 rval = -EPERM;
289 goto done;
290 }
291
292 /* ELS request for rport */
293 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
6e98016c
GM
294 /* make sure the rport is logged in,
295 * if not perform fabric login
296 */
297 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
7c3df132
SK
298 ql_dbg(ql_dbg_user, vha, 0x7003,
299 "Failed to login port %06X for ELS passthru.\n",
300 fcport->d_id.b24);
6e98016c
GM
301 rval = -EIO;
302 goto done;
303 }
304 } else {
6e98016c
GM
305 /* Allocate a dummy fcport structure, since functions
306 * preparing the IOCB and mailbox command retrieves port
307 * specific information from fcport structure. For Host based
308 * ELS commands there will be no fcport structure allocated
309 */
310 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
311 if (!fcport) {
312 rval = -ENOMEM;
313 goto done;
314 }
315
316 /* Initialize all required fields of fcport */
317 fcport->vha = vha;
6e98016c
GM
318 fcport->d_id.b.al_pa =
319 bsg_job->request->rqst_data.h_els.port_id[0];
320 fcport->d_id.b.area =
321 bsg_job->request->rqst_data.h_els.port_id[1];
322 fcport->d_id.b.domain =
323 bsg_job->request->rqst_data.h_els.port_id[2];
324 fcport->loop_id =
325 (fcport->d_id.b.al_pa == 0xFD) ?
326 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
327 }
328
329 if (!vha->flags.online) {
7c3df132 330 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
6e98016c
GM
331 rval = -EIO;
332 goto done;
333 }
334
335 req_sg_cnt =
336 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
337 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
338 if (!req_sg_cnt) {
339 rval = -ENOMEM;
340 goto done_free_fcport;
341 }
6c452a45
AV
342
343 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
344 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
6e98016c
GM
345 if (!rsp_sg_cnt) {
346 rval = -ENOMEM;
347 goto done_free_fcport;
348 }
349
350 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
6c452a45 351 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
7c3df132
SK
352 ql_log(ql_log_warn, vha, 0x7008,
353 "dma mapping resulted in different sg counts, "
354 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
355 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
356 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
6e98016c
GM
357 rval = -EAGAIN;
358 goto done_unmap_sg;
359 }
360
361 /* Alloc SRB structure */
9ba56b95 362 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
6e98016c
GM
363 if (!sp) {
364 rval = -ENOMEM;
6c452a45 365 goto done_unmap_sg;
6e98016c
GM
366 }
367
9ba56b95 368 sp->type =
6e98016c
GM
369 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
370 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
9ba56b95 371 sp->name =
3822263e
MI
372 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
373 "bsg_els_rpt" : "bsg_els_hst");
9ba56b95
GM
374 sp->u.bsg_job = bsg_job;
375 sp->free = qla2x00_bsg_sp_free;
376 sp->done = qla2x00_bsg_job_done;
6e98016c 377
7c3df132
SK
378 ql_dbg(ql_dbg_user, vha, 0x700a,
379 "bsg rqst type: %s els type: %x - loop-id=%x "
380 "portid=%-2x%02x%02x.\n", type,
381 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
382 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
6e98016c
GM
383
384 rval = qla2x00_start_sp(sp);
385 if (rval != QLA_SUCCESS) {
7c3df132
SK
386 ql_log(ql_log_warn, vha, 0x700e,
387 "qla2x00_start_sp failed = %d\n", rval);
b00ee7d7 388 qla2x00_rel_sp(vha, sp);
6e98016c
GM
389 rval = -EIO;
390 goto done_unmap_sg;
391 }
392 return rval;
393
394done_unmap_sg:
395 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
396 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
397 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
398 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
399 goto done_free_fcport;
400
401done_free_fcport:
402 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
403 kfree(fcport);
404done:
405 return rval;
406}
407
5780790e
AV
408inline uint16_t
409qla24xx_calc_ct_iocbs(uint16_t dsds)
410{
411 uint16_t iocbs;
412
413 iocbs = 1;
414 if (dsds > 2) {
415 iocbs += (dsds - 2) / 5;
416 if ((dsds - 2) % 5)
417 iocbs++;
418 }
419 return iocbs;
420}
421
6e98016c
GM
422static int
423qla2x00_process_ct(struct fc_bsg_job *bsg_job)
424{
425 srb_t *sp;
426 struct Scsi_Host *host = bsg_job->shost;
427 scsi_qla_host_t *vha = shost_priv(host);
428 struct qla_hw_data *ha = vha->hw;
429 int rval = (DRIVER_ERROR << 16);
430 int req_sg_cnt, rsp_sg_cnt;
431 uint16_t loop_id;
432 struct fc_port *fcport;
433 char *type = "FC_BSG_HST_CT";
6e98016c 434
6e98016c
GM
435 req_sg_cnt =
436 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
437 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
6c452a45 438 if (!req_sg_cnt) {
7c3df132
SK
439 ql_log(ql_log_warn, vha, 0x700f,
440 "dma_map_sg return %d for request\n", req_sg_cnt);
6e98016c
GM
441 rval = -ENOMEM;
442 goto done;
443 }
444
445 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
446 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
447 if (!rsp_sg_cnt) {
7c3df132
SK
448 ql_log(ql_log_warn, vha, 0x7010,
449 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
6e98016c
GM
450 rval = -ENOMEM;
451 goto done;
452 }
453
454 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
6c452a45 455 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
7c3df132
SK
456 ql_log(ql_log_warn, vha, 0x7011,
457 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
458 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
459 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
6e98016c 460 rval = -EAGAIN;
6c452a45 461 goto done_unmap_sg;
6e98016c
GM
462 }
463
464 if (!vha->flags.online) {
7c3df132
SK
465 ql_log(ql_log_warn, vha, 0x7012,
466 "Host is not online.\n");
6e98016c
GM
467 rval = -EIO;
468 goto done_unmap_sg;
469 }
470
471 loop_id =
472 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
473 >> 24;
474 switch (loop_id) {
6c452a45
AV
475 case 0xFC:
476 loop_id = cpu_to_le16(NPH_SNS);
477 break;
478 case 0xFA:
479 loop_id = vha->mgmt_svr_loop_id;
480 break;
481 default:
7c3df132
SK
482 ql_dbg(ql_dbg_user, vha, 0x7013,
483 "Unknown loop id: %x.\n", loop_id);
6c452a45
AV
484 rval = -EINVAL;
485 goto done_unmap_sg;
6e98016c
GM
486 }
487
488 /* Allocate a dummy fcport structure, since functions preparing the
489 * IOCB and mailbox command retrieves port specific information
490 * from fcport structure. For Host based ELS commands there will be
491 * no fcport structure allocated
492 */
493 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6c452a45 494 if (!fcport) {
7c3df132
SK
495 ql_log(ql_log_warn, vha, 0x7014,
496 "Failed to allocate fcport.\n");
6e98016c 497 rval = -ENOMEM;
6c452a45 498 goto done_unmap_sg;
6e98016c
GM
499 }
500
501 /* Initialize all required fields of fcport */
502 fcport->vha = vha;
6e98016c
GM
503 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
504 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
505 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
506 fcport->loop_id = loop_id;
507
508 /* Alloc SRB structure */
9ba56b95 509 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
6e98016c 510 if (!sp) {
7c3df132 511 ql_log(ql_log_warn, vha, 0x7015,
9ba56b95 512 "qla2x00_get_sp failed.\n");
6e98016c
GM
513 rval = -ENOMEM;
514 goto done_free_fcport;
515 }
516
9ba56b95
GM
517 sp->type = SRB_CT_CMD;
518 sp->name = "bsg_ct";
519 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
520 sp->u.bsg_job = bsg_job;
521 sp->free = qla2x00_bsg_sp_free;
522 sp->done = qla2x00_bsg_job_done;
6e98016c 523
7c3df132
SK
524 ql_dbg(ql_dbg_user, vha, 0x7016,
525 "bsg rqst type: %s else type: %x - "
526 "loop-id=%x portid=%02x%02x%02x.\n", type,
527 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
528 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
529 fcport->d_id.b.al_pa);
6e98016c
GM
530
531 rval = qla2x00_start_sp(sp);
532 if (rval != QLA_SUCCESS) {
7c3df132
SK
533 ql_log(ql_log_warn, vha, 0x7017,
534 "qla2x00_start_sp failed=%d.\n", rval);
b00ee7d7 535 qla2x00_rel_sp(vha, sp);
6e98016c
GM
536 rval = -EIO;
537 goto done_free_fcport;
538 }
539 return rval;
540
541done_free_fcport:
542 kfree(fcport);
543done_unmap_sg:
544 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
545 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
546 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
547 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
548done:
549 return rval;
550}
67b2a31f
CD
551
552/* Disable loopback mode */
553static inline int
554qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
f356bef1 555 int wait, int wait2)
67b2a31f
CD
556{
557 int ret = 0;
558 int rval = 0;
559 uint16_t new_config[4];
560 struct qla_hw_data *ha = vha->hw;
561
562 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
563 goto done_reset_internal;
564
565 memset(new_config, 0 , sizeof(new_config));
566 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
567 ENABLE_INTERNAL_LOOPBACK ||
568 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
569 ENABLE_EXTERNAL_LOOPBACK) {
570 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
571 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
572 (new_config[0] & INTERNAL_LOOPBACK_MASK));
573 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
574
575 ha->notify_dcbx_comp = wait;
f356bef1
CD
576 ha->notify_lb_portup_comp = wait2;
577
67b2a31f
CD
578 ret = qla81xx_set_port_config(vha, new_config);
579 if (ret != QLA_SUCCESS) {
580 ql_log(ql_log_warn, vha, 0x7025,
581 "Set port config failed.\n");
582 ha->notify_dcbx_comp = 0;
f356bef1 583 ha->notify_lb_portup_comp = 0;
67b2a31f
CD
584 rval = -EINVAL;
585 goto done_reset_internal;
586 }
587
588 /* Wait for DCBX complete event */
589 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
f356bef1 590 (DCBX_COMP_TIMEOUT * HZ))) {
67b2a31f 591 ql_dbg(ql_dbg_user, vha, 0x7026,
f356bef1 592 "DCBX completion not received.\n");
67b2a31f 593 ha->notify_dcbx_comp = 0;
f356bef1 594 ha->notify_lb_portup_comp = 0;
67b2a31f
CD
595 rval = -EINVAL;
596 goto done_reset_internal;
597 } else
598 ql_dbg(ql_dbg_user, vha, 0x7027,
f356bef1
CD
599 "DCBX completion received.\n");
600
601 if (wait2 &&
602 !wait_for_completion_timeout(&ha->lb_portup_comp,
603 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
604 ql_dbg(ql_dbg_user, vha, 0x70c5,
605 "Port up completion not received.\n");
606 ha->notify_lb_portup_comp = 0;
607 rval = -EINVAL;
608 goto done_reset_internal;
609 } else
610 ql_dbg(ql_dbg_user, vha, 0x70c6,
611 "Port up completion received.\n");
67b2a31f
CD
612
613 ha->notify_dcbx_comp = 0;
f356bef1 614 ha->notify_lb_portup_comp = 0;
67b2a31f
CD
615 }
616done_reset_internal:
617 return rval;
618}
619
8fcd6b8b
CD
620/*
621 * Set the port configuration to enable the internal or external loopback
622 * depending on the loopback mode.
23f2ebd1
SR
623 */
624static inline int
8fcd6b8b
CD
625qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
626 uint16_t *new_config, uint16_t mode)
23f2ebd1
SR
627{
628 int ret = 0;
629 int rval = 0;
630 struct qla_hw_data *ha = vha->hw;
631
f863f603 632 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
23f2ebd1
SR
633 goto done_set_internal;
634
8fcd6b8b
CD
635 if (mode == INTERNAL_LOOPBACK)
636 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
637 else if (mode == EXTERNAL_LOOPBACK)
638 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
639 ql_dbg(ql_dbg_user, vha, 0x70be,
640 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
641
642 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
23f2ebd1
SR
643
644 ha->notify_dcbx_comp = 1;
645 ret = qla81xx_set_port_config(vha, new_config);
646 if (ret != QLA_SUCCESS) {
7c3df132
SK
647 ql_log(ql_log_warn, vha, 0x7021,
648 "set port config failed.\n");
23f2ebd1
SR
649 ha->notify_dcbx_comp = 0;
650 rval = -EINVAL;
651 goto done_set_internal;
652 }
653
654 /* Wait for DCBX complete event */
f356bef1
CD
655 if (!wait_for_completion_timeout(&ha->dcbx_comp,
656 (DCBX_COMP_TIMEOUT * HZ))) {
7c3df132 657 ql_dbg(ql_dbg_user, vha, 0x7022,
f356bef1
CD
658 "DCBX completion not received.\n");
659 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
67b2a31f
CD
660 /*
661 * If the reset of the loopback mode doesn't work take a FCoE
662 * dump and reset the chip.
663 */
664 if (ret) {
665 ha->isp_ops->fw_dump(vha, 0);
666 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
667 }
bf5b8ad7
CD
668 rval = -EINVAL;
669 } else {
670 if (ha->flags.idc_compl_status) {
671 ql_dbg(ql_dbg_user, vha, 0x70c3,
672 "Bad status in IDC Completion AEN\n");
673 rval = -EINVAL;
674 ha->flags.idc_compl_status = 0;
675 } else
676 ql_dbg(ql_dbg_user, vha, 0x7023,
f356bef1 677 "DCBX completion received.\n");
bf5b8ad7 678 }
23f2ebd1
SR
679
680 ha->notify_dcbx_comp = 0;
681
682done_set_internal:
683 return rval;
684}
685
6e98016c
GM
686static int
687qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
688{
689 struct Scsi_Host *host = bsg_job->shost;
690 scsi_qla_host_t *vha = shost_priv(host);
691 struct qla_hw_data *ha = vha->hw;
692 int rval;
693 uint8_t command_sent;
694 char *type;
695 struct msg_echo_lb elreq;
696 uint16_t response[MAILBOX_REGISTER_COUNT];
23f2ebd1 697 uint16_t config[4], new_config[4];
6c452a45 698 uint8_t *fw_sts_ptr;
6e98016c
GM
699 uint8_t *req_data = NULL;
700 dma_addr_t req_data_dma;
701 uint32_t req_data_len;
702 uint8_t *rsp_data = NULL;
703 dma_addr_t rsp_data_dma;
704 uint32_t rsp_data_len;
705
6e98016c 706 if (!vha->flags.online) {
7c3df132 707 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
6e98016c
GM
708 return -EIO;
709 }
710
711 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
712 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
713 DMA_TO_DEVICE);
714
7c3df132
SK
715 if (!elreq.req_sg_cnt) {
716 ql_log(ql_log_warn, vha, 0x701a,
717 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
6e98016c 718 return -ENOMEM;
7c3df132 719 }
6e98016c
GM
720
721 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
722 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
723 DMA_FROM_DEVICE);
724
725 if (!elreq.rsp_sg_cnt) {
7c3df132
SK
726 ql_log(ql_log_warn, vha, 0x701b,
727 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
6e98016c
GM
728 rval = -ENOMEM;
729 goto done_unmap_req_sg;
6c452a45 730 }
6e98016c
GM
731
732 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
733 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
7c3df132
SK
734 ql_log(ql_log_warn, vha, 0x701c,
735 "dma mapping resulted in different sg counts, "
736 "request_sg_cnt: %x dma_request_sg_cnt: %x "
737 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
738 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
739 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
6e98016c
GM
740 rval = -EAGAIN;
741 goto done_unmap_sg;
742 }
743 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
744 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
745 &req_data_dma, GFP_KERNEL);
746 if (!req_data) {
7c3df132
SK
747 ql_log(ql_log_warn, vha, 0x701d,
748 "dma alloc failed for req_data.\n");
6e98016c
GM
749 rval = -ENOMEM;
750 goto done_unmap_sg;
751 }
752
753 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
754 &rsp_data_dma, GFP_KERNEL);
755 if (!rsp_data) {
7c3df132
SK
756 ql_log(ql_log_warn, vha, 0x7004,
757 "dma alloc failed for rsp_data.\n");
6e98016c
GM
758 rval = -ENOMEM;
759 goto done_free_dma_req;
760 }
761
762 /* Copy the request buffer in req_data now */
763 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
764 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
765
766 elreq.send_dma = req_data_dma;
767 elreq.rcv_dma = rsp_data_dma;
768 elreq.transfer_size = req_data_len;
769
770 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1b98b421
JC
771 elreq.iteration_count =
772 bsg_job->request->rqst_data.h_vendor.vendor_cmd[2];
6e98016c 773
8fcd6b8b
CD
774 if (atomic_read(&vha->loop_state) == LOOP_READY &&
775 (ha->current_topology == ISP_CFG_F ||
f863f603 776 ((IS_QLA81XX(ha) || IS_QLA8031(ha)) &&
23f2ebd1
SR
777 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
778 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
779 elreq.options == EXTERNAL_LOOPBACK) {
780 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
7c3df132
SK
781 ql_dbg(ql_dbg_user, vha, 0x701e,
782 "BSG request type: %s.\n", type);
23f2ebd1
SR
783 command_sent = INT_DEF_LB_ECHO_CMD;
784 rval = qla2x00_echo_test(vha, &elreq, response);
785 } else {
6246b8a1 786 if (IS_QLA81XX(ha) || IS_QLA8031(ha)) {
23f2ebd1
SR
787 memset(config, 0, sizeof(config));
788 memset(new_config, 0, sizeof(new_config));
f356bef1 789
23f2ebd1 790 if (qla81xx_get_port_config(vha, config)) {
7c3df132
SK
791 ql_log(ql_log_warn, vha, 0x701f,
792 "Get port config failed.\n");
23f2ebd1 793 rval = -EPERM;
9bceab4e 794 goto done_free_dma_rsp;
23f2ebd1
SR
795 }
796
1bcc46cb
CD
797 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
798 ql_dbg(ql_dbg_user, vha, 0x70c4,
799 "Loopback operation already in "
800 "progress.\n");
801 rval = -EAGAIN;
802 goto done_free_dma_rsp;
803 }
804
8fcd6b8b
CD
805 ql_dbg(ql_dbg_user, vha, 0x70c0,
806 "elreq.options=%04x\n", elreq.options);
807
808 if (elreq.options == EXTERNAL_LOOPBACK)
809 if (IS_QLA8031(ha))
810 rval = qla81xx_set_loopback_mode(vha,
811 config, new_config, elreq.options);
812 else
813 rval = qla81xx_reset_loopback_mode(vha,
f356bef1 814 config, 1, 0);
8fcd6b8b
CD
815 else
816 rval = qla81xx_set_loopback_mode(vha, config,
817 new_config, elreq.options);
818
819 if (rval) {
8fcd6b8b 820 rval = -EPERM;
9bceab4e 821 goto done_free_dma_rsp;
23f2ebd1
SR
822 }
823
824 type = "FC_BSG_HST_VENDOR_LOOPBACK";
7c3df132
SK
825 ql_dbg(ql_dbg_user, vha, 0x7028,
826 "BSG request type: %s.\n", type);
23f2ebd1
SR
827
828 command_sent = INT_DEF_LB_LOOPBACK_CMD;
829 rval = qla2x00_loopback_test(vha, &elreq, response);
830
992357c6
CD
831 if (response[0] == MBS_COMMAND_ERROR &&
832 response[1] == MBS_LB_RESET) {
833 ql_log(ql_log_warn, vha, 0x7029,
834 "MBX command error, Aborting ISP.\n");
835 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
836 qla2xxx_wake_dpc(vha);
837 qla2x00_wait_for_chip_reset(vha);
838 /* Also reset the MPI */
839 if (IS_QLA81XX(ha)) {
840 if (qla81xx_restart_mpi_firmware(vha) !=
841 QLA_SUCCESS) {
842 ql_log(ql_log_warn, vha, 0x702a,
843 "MPI reset failed.\n");
844 }
845 }
846
847 rval = -EIO;
848 goto done_free_dma_rsp;
849 }
850
4052bd57 851 if (new_config[0]) {
67b2a31f
CD
852 int ret;
853
23f2ebd1
SR
854 /* Revert back to original port config
855 * Also clear internal loopback
856 */
67b2a31f 857 ret = qla81xx_reset_loopback_mode(vha,
f356bef1 858 new_config, 0, 1);
67b2a31f
CD
859 if (ret) {
860 /*
861 * If the reset of the loopback mode
862 * doesn't work take FCoE dump and then
863 * reset the chip.
864 */
865 ha->isp_ops->fw_dump(vha, 0);
866 set_bit(ISP_ABORT_NEEDED,
867 &vha->dpc_flags);
868 }
869
23f2ebd1
SR
870 }
871
23f2ebd1
SR
872 } else {
873 type = "FC_BSG_HST_VENDOR_LOOPBACK";
7c3df132
SK
874 ql_dbg(ql_dbg_user, vha, 0x702b,
875 "BSG request type: %s.\n", type);
23f2ebd1
SR
876 command_sent = INT_DEF_LB_LOOPBACK_CMD;
877 rval = qla2x00_loopback_test(vha, &elreq, response);
6e98016c 878 }
6e98016c
GM
879 }
880
881 if (rval) {
7c3df132
SK
882 ql_log(ql_log_warn, vha, 0x702c,
883 "Vendor request %s failed.\n", type);
6e98016c 884
6e98016c 885 rval = 0;
6e98016c 886 bsg_job->reply->result = (DID_ERROR << 16);
63ea923a 887 bsg_job->reply->reply_payload_rcv_len = 0;
6e98016c 888 } else {
7c3df132
SK
889 ql_dbg(ql_dbg_user, vha, 0x702d,
890 "Vendor request %s completed.\n", type);
63ea923a 891 bsg_job->reply->result = (DID_OK << 16);
6e98016c
GM
892 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
893 bsg_job->reply_payload.sg_cnt, rsp_data,
894 rsp_data_len);
895 }
63ea923a
AB
896
897 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
898 sizeof(response) + sizeof(uint8_t);
899 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
900 sizeof(struct fc_bsg_reply);
901 memcpy(fw_sts_ptr, response, sizeof(response));
902 fw_sts_ptr += sizeof(response);
903 *fw_sts_ptr = command_sent;
6e98016c 904
9bceab4e 905done_free_dma_rsp:
6e98016c
GM
906 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
907 rsp_data, rsp_data_dma);
908done_free_dma_req:
909 dma_free_coherent(&ha->pdev->dev, req_data_len,
910 req_data, req_data_dma);
911done_unmap_sg:
912 dma_unmap_sg(&ha->pdev->dev,
913 bsg_job->reply_payload.sg_list,
914 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
915done_unmap_req_sg:
916 dma_unmap_sg(&ha->pdev->dev,
917 bsg_job->request_payload.sg_list,
918 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
63ea923a
AB
919 if (!rval)
920 bsg_job->job_done(bsg_job);
6c452a45 921 return rval;
6e98016c
GM
922}
923
924static int
925qla84xx_reset(struct fc_bsg_job *bsg_job)
926{
927 struct Scsi_Host *host = bsg_job->shost;
928 scsi_qla_host_t *vha = shost_priv(host);
929 struct qla_hw_data *ha = vha->hw;
930 int rval = 0;
931 uint32_t flag;
932
6e98016c 933 if (!IS_QLA84XX(ha)) {
7c3df132 934 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
6e98016c
GM
935 return -EINVAL;
936 }
937
938 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
939
940 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
941
942 if (rval) {
7c3df132
SK
943 ql_log(ql_log_warn, vha, 0x7030,
944 "Vendor request 84xx reset failed.\n");
63ea923a 945 rval = (DID_ERROR << 16);
6e98016c
GM
946
947 } else {
7c3df132
SK
948 ql_dbg(ql_dbg_user, vha, 0x7031,
949 "Vendor request 84xx reset completed.\n");
6e98016c 950 bsg_job->reply->result = DID_OK;
63ea923a 951 bsg_job->job_done(bsg_job);
6e98016c
GM
952 }
953
6e98016c
GM
954 return rval;
955}
956
957static int
958qla84xx_updatefw(struct fc_bsg_job *bsg_job)
959{
960 struct Scsi_Host *host = bsg_job->shost;
961 scsi_qla_host_t *vha = shost_priv(host);
962 struct qla_hw_data *ha = vha->hw;
963 struct verify_chip_entry_84xx *mn = NULL;
964 dma_addr_t mn_dma, fw_dma;
965 void *fw_buf = NULL;
966 int rval = 0;
967 uint32_t sg_cnt;
968 uint32_t data_len;
969 uint16_t options;
970 uint32_t flag;
971 uint32_t fw_ver;
972
6e98016c 973 if (!IS_QLA84XX(ha)) {
7c3df132
SK
974 ql_dbg(ql_dbg_user, vha, 0x7032,
975 "Not 84xx, exiting.\n");
6e98016c
GM
976 return -EINVAL;
977 }
978
979 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
980 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
7c3df132
SK
981 if (!sg_cnt) {
982 ql_log(ql_log_warn, vha, 0x7033,
983 "dma_map_sg returned %d for request.\n", sg_cnt);
6e98016c 984 return -ENOMEM;
7c3df132 985 }
6e98016c
GM
986
987 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
7c3df132
SK
988 ql_log(ql_log_warn, vha, 0x7034,
989 "DMA mapping resulted in different sg counts, "
990 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
991 bsg_job->request_payload.sg_cnt, sg_cnt);
6e98016c
GM
992 rval = -EAGAIN;
993 goto done_unmap_sg;
994 }
995
996 data_len = bsg_job->request_payload.payload_len;
997 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
998 &fw_dma, GFP_KERNEL);
999 if (!fw_buf) {
7c3df132
SK
1000 ql_log(ql_log_warn, vha, 0x7035,
1001 "DMA alloc failed for fw_buf.\n");
6e98016c
GM
1002 rval = -ENOMEM;
1003 goto done_unmap_sg;
1004 }
1005
1006 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1007 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1008
1009 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1010 if (!mn) {
7c3df132
SK
1011 ql_log(ql_log_warn, vha, 0x7036,
1012 "DMA alloc failed for fw buffer.\n");
6e98016c
GM
1013 rval = -ENOMEM;
1014 goto done_free_fw_buf;
1015 }
1016
1017 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1018 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1019
1020 memset(mn, 0, sizeof(struct access_chip_84xx));
1021 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1022 mn->entry_count = 1;
1023
1024 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1025 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1026 options |= VCO_DIAG_FW;
1027
1028 mn->options = cpu_to_le16(options);
1029 mn->fw_ver = cpu_to_le32(fw_ver);
1030 mn->fw_size = cpu_to_le32(data_len);
1031 mn->fw_seq_size = cpu_to_le32(data_len);
1032 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1033 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1034 mn->dseg_length = cpu_to_le32(data_len);
1035 mn->data_seg_cnt = cpu_to_le16(1);
1036
1037 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1038
1039 if (rval) {
7c3df132
SK
1040 ql_log(ql_log_warn, vha, 0x7037,
1041 "Vendor request 84xx updatefw failed.\n");
6e98016c 1042
63ea923a 1043 rval = (DID_ERROR << 16);
6e98016c 1044 } else {
7c3df132
SK
1045 ql_dbg(ql_dbg_user, vha, 0x7038,
1046 "Vendor request 84xx updatefw completed.\n");
6e98016c
GM
1047
1048 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1049 bsg_job->reply->result = DID_OK;
1050 }
1051
6e98016c
GM
1052 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1053
1054done_free_fw_buf:
1055 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1056
1057done_unmap_sg:
1058 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1059 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1060
63ea923a
AB
1061 if (!rval)
1062 bsg_job->job_done(bsg_job);
6e98016c
GM
1063 return rval;
1064}
1065
1066static int
1067qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1068{
1069 struct Scsi_Host *host = bsg_job->shost;
1070 scsi_qla_host_t *vha = shost_priv(host);
1071 struct qla_hw_data *ha = vha->hw;
1072 struct access_chip_84xx *mn = NULL;
1073 dma_addr_t mn_dma, mgmt_dma;
1074 void *mgmt_b = NULL;
1075 int rval = 0;
1076 struct qla_bsg_a84_mgmt *ql84_mgmt;
1077 uint32_t sg_cnt;
d5459083 1078 uint32_t data_len = 0;
6e98016c
GM
1079 uint32_t dma_direction = DMA_NONE;
1080
6e98016c 1081 if (!IS_QLA84XX(ha)) {
7c3df132
SK
1082 ql_log(ql_log_warn, vha, 0x703a,
1083 "Not 84xx, exiting.\n");
6e98016c
GM
1084 return -EINVAL;
1085 }
1086
1087 ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
1088 sizeof(struct fc_bsg_request));
1089 if (!ql84_mgmt) {
7c3df132
SK
1090 ql_log(ql_log_warn, vha, 0x703b,
1091 "MGMT header not provided, exiting.\n");
6e98016c
GM
1092 return -EINVAL;
1093 }
1094
1095 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1096 if (!mn) {
7c3df132
SK
1097 ql_log(ql_log_warn, vha, 0x703c,
1098 "DMA alloc failed for fw buffer.\n");
6e98016c
GM
1099 return -ENOMEM;
1100 }
1101
1102 memset(mn, 0, sizeof(struct access_chip_84xx));
1103 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1104 mn->entry_count = 1;
1105
1106 switch (ql84_mgmt->mgmt.cmd) {
1107 case QLA84_MGMT_READ_MEM:
1108 case QLA84_MGMT_GET_INFO:
1109 sg_cnt = dma_map_sg(&ha->pdev->dev,
1110 bsg_job->reply_payload.sg_list,
1111 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1112 if (!sg_cnt) {
7c3df132
SK
1113 ql_log(ql_log_warn, vha, 0x703d,
1114 "dma_map_sg returned %d for reply.\n", sg_cnt);
6e98016c
GM
1115 rval = -ENOMEM;
1116 goto exit_mgmt;
1117 }
1118
1119 dma_direction = DMA_FROM_DEVICE;
1120
1121 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
7c3df132
SK
1122 ql_log(ql_log_warn, vha, 0x703e,
1123 "DMA mapping resulted in different sg counts, "
1124 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1125 bsg_job->reply_payload.sg_cnt, sg_cnt);
6e98016c
GM
1126 rval = -EAGAIN;
1127 goto done_unmap_sg;
1128 }
1129
1130 data_len = bsg_job->reply_payload.payload_len;
1131
1132 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1133 &mgmt_dma, GFP_KERNEL);
1134 if (!mgmt_b) {
7c3df132
SK
1135 ql_log(ql_log_warn, vha, 0x703f,
1136 "DMA alloc failed for mgmt_b.\n");
6e98016c
GM
1137 rval = -ENOMEM;
1138 goto done_unmap_sg;
1139 }
1140
1141 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1142 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1143 mn->parameter1 =
1144 cpu_to_le32(
1145 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1146
1147 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1148 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1149 mn->parameter1 =
1150 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1151
1152 mn->parameter2 =
1153 cpu_to_le32(
1154 ql84_mgmt->mgmt.mgmtp.u.info.context);
1155 }
1156 break;
1157
1158 case QLA84_MGMT_WRITE_MEM:
1159 sg_cnt = dma_map_sg(&ha->pdev->dev,
1160 bsg_job->request_payload.sg_list,
1161 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1162
1163 if (!sg_cnt) {
7c3df132
SK
1164 ql_log(ql_log_warn, vha, 0x7040,
1165 "dma_map_sg returned %d.\n", sg_cnt);
6e98016c
GM
1166 rval = -ENOMEM;
1167 goto exit_mgmt;
1168 }
1169
1170 dma_direction = DMA_TO_DEVICE;
1171
1172 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
7c3df132
SK
1173 ql_log(ql_log_warn, vha, 0x7041,
1174 "DMA mapping resulted in different sg counts, "
1175 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1176 bsg_job->request_payload.sg_cnt, sg_cnt);
6e98016c
GM
1177 rval = -EAGAIN;
1178 goto done_unmap_sg;
1179 }
1180
1181 data_len = bsg_job->request_payload.payload_len;
1182 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1183 &mgmt_dma, GFP_KERNEL);
1184 if (!mgmt_b) {
7c3df132
SK
1185 ql_log(ql_log_warn, vha, 0x7042,
1186 "DMA alloc failed for mgmt_b.\n");
6e98016c
GM
1187 rval = -ENOMEM;
1188 goto done_unmap_sg;
1189 }
1190
1191 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1192 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1193
1194 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1195 mn->parameter1 =
1196 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1197 break;
1198
1199 case QLA84_MGMT_CHNG_CONFIG:
1200 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1201 mn->parameter1 =
1202 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1203
1204 mn->parameter2 =
1205 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1206
1207 mn->parameter3 =
1208 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1209 break;
1210
1211 default:
1212 rval = -EIO;
1213 goto exit_mgmt;
1214 }
1215
1216 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1217 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1218 mn->dseg_count = cpu_to_le16(1);
1219 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1220 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1221 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1222 }
1223
1224 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1225
1226 if (rval) {
7c3df132
SK
1227 ql_log(ql_log_warn, vha, 0x7043,
1228 "Vendor request 84xx mgmt failed.\n");
6e98016c 1229
63ea923a 1230 rval = (DID_ERROR << 16);
6e98016c
GM
1231
1232 } else {
7c3df132
SK
1233 ql_dbg(ql_dbg_user, vha, 0x7044,
1234 "Vendor request 84xx mgmt completed.\n");
6e98016c
GM
1235
1236 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1237 bsg_job->reply->result = DID_OK;
1238
1239 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1240 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1241 bsg_job->reply->reply_payload_rcv_len =
1242 bsg_job->reply_payload.payload_len;
1243
1244 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
6c452a45
AV
1245 bsg_job->reply_payload.sg_cnt, mgmt_b,
1246 data_len);
6e98016c
GM
1247 }
1248 }
1249
6e98016c 1250done_unmap_sg:
d5459083
HZ
1251 if (mgmt_b)
1252 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1253
6e98016c
GM
1254 if (dma_direction == DMA_TO_DEVICE)
1255 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1256 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1257 else if (dma_direction == DMA_FROM_DEVICE)
1258 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1259 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1260
1261exit_mgmt:
1262 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1263
63ea923a
AB
1264 if (!rval)
1265 bsg_job->job_done(bsg_job);
6e98016c
GM
1266 return rval;
1267}
1268
1269static int
1270qla24xx_iidma(struct fc_bsg_job *bsg_job)
1271{
1272 struct Scsi_Host *host = bsg_job->shost;
1273 scsi_qla_host_t *vha = shost_priv(host);
6e98016c
GM
1274 int rval = 0;
1275 struct qla_port_param *port_param = NULL;
1276 fc_port_t *fcport = NULL;
1277 uint16_t mb[MAILBOX_REGISTER_COUNT];
1278 uint8_t *rsp_ptr = NULL;
1279
6e98016c 1280 if (!IS_IIDMA_CAPABLE(vha->hw)) {
7c3df132 1281 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
6e98016c
GM
1282 return -EINVAL;
1283 }
1284
090fc2e2 1285 port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
6e98016c 1286 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
7c3df132
SK
1287 ql_log(ql_log_warn, vha, 0x7048,
1288 "Invalid destination type.\n");
6e98016c
GM
1289 return -EINVAL;
1290 }
1291
1292 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1293 if (fcport->port_type != FCT_TARGET)
1294 continue;
1295
1296 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1297 fcport->port_name, sizeof(fcport->port_name)))
1298 continue;
1299 break;
1300 }
1301
1302 if (!fcport) {
7c3df132
SK
1303 ql_log(ql_log_warn, vha, 0x7049,
1304 "Failed to find port.\n");
6e98016c
GM
1305 return -EINVAL;
1306 }
1307
c9afb9a2 1308 if (atomic_read(&fcport->state) != FCS_ONLINE) {
7c3df132
SK
1309 ql_log(ql_log_warn, vha, 0x704a,
1310 "Port is not online.\n");
17cf2c5d
MI
1311 return -EINVAL;
1312 }
1313
9a15eb4b 1314 if (fcport->flags & FCF_LOGIN_NEEDED) {
7c3df132
SK
1315 ql_log(ql_log_warn, vha, 0x704b,
1316 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
9a15eb4b
MI
1317 return -EINVAL;
1318 }
1319
6e98016c
GM
1320 if (port_param->mode)
1321 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1322 port_param->speed, mb);
1323 else
1324 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1325 &port_param->speed, mb);
1326
1327 if (rval) {
7c3df132
SK
1328 ql_log(ql_log_warn, vha, 0x704c,
1329 "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- "
1330 "%04x %x %04x %04x.\n", fcport->port_name[0],
1331 fcport->port_name[1], fcport->port_name[2],
1332 fcport->port_name[3], fcport->port_name[4],
1333 fcport->port_name[5], fcport->port_name[6],
1334 fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]);
63ea923a 1335 rval = (DID_ERROR << 16);
6e98016c
GM
1336 } else {
1337 if (!port_param->mode) {
1338 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1339 sizeof(struct qla_port_param);
1340
1341 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1342 sizeof(struct fc_bsg_reply);
1343
1344 memcpy(rsp_ptr, port_param,
1345 sizeof(struct qla_port_param));
1346 }
1347
1348 bsg_job->reply->result = DID_OK;
63ea923a 1349 bsg_job->job_done(bsg_job);
6e98016c
GM
1350 }
1351
6e98016c
GM
1352 return rval;
1353}
1354
f19af163 1355static int
7c3df132 1356qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
f19af163
HZ
1357 uint8_t is_update)
1358{
1359 uint32_t start = 0;
1360 int valid = 0;
7c3df132 1361 struct qla_hw_data *ha = vha->hw;
f19af163 1362
f19af163
HZ
1363 if (unlikely(pci_channel_offline(ha->pdev)))
1364 return -EINVAL;
1365
1366 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
7c3df132
SK
1367 if (start > ha->optrom_size) {
1368 ql_log(ql_log_warn, vha, 0x7055,
1369 "start %d > optrom_size %d.\n", start, ha->optrom_size);
f19af163 1370 return -EINVAL;
7c3df132 1371 }
f19af163 1372
7c3df132
SK
1373 if (ha->optrom_state != QLA_SWAITING) {
1374 ql_log(ql_log_info, vha, 0x7056,
1375 "optrom_state %d.\n", ha->optrom_state);
f19af163 1376 return -EBUSY;
7c3df132 1377 }
f19af163
HZ
1378
1379 ha->optrom_region_start = start;
7c3df132 1380 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
f19af163
HZ
1381 if (is_update) {
1382 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1383 valid = 1;
1384 else if (start == (ha->flt_region_boot * 4) ||
1385 start == (ha->flt_region_fw * 4))
1386 valid = 1;
1387 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
6246b8a1 1388 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
f19af163
HZ
1389 valid = 1;
1390 if (!valid) {
7c3df132
SK
1391 ql_log(ql_log_warn, vha, 0x7058,
1392 "Invalid start region 0x%x/0x%x.\n", start,
1393 bsg_job->request_payload.payload_len);
f19af163
HZ
1394 return -EINVAL;
1395 }
1396
1397 ha->optrom_region_size = start +
1398 bsg_job->request_payload.payload_len > ha->optrom_size ?
1399 ha->optrom_size - start :
1400 bsg_job->request_payload.payload_len;
1401 ha->optrom_state = QLA_SWRITING;
1402 } else {
1403 ha->optrom_region_size = start +
1404 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1405 ha->optrom_size - start :
1406 bsg_job->reply_payload.payload_len;
1407 ha->optrom_state = QLA_SREADING;
1408 }
1409
1410 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1411 if (!ha->optrom_buffer) {
7c3df132 1412 ql_log(ql_log_warn, vha, 0x7059,
f19af163 1413 "Read: Unable to allocate memory for optrom retrieval "
7c3df132 1414 "(%x)\n", ha->optrom_region_size);
f19af163
HZ
1415
1416 ha->optrom_state = QLA_SWAITING;
1417 return -ENOMEM;
1418 }
1419
1420 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1421 return 0;
1422}
1423
1424static int
1425qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1426{
1427 struct Scsi_Host *host = bsg_job->shost;
1428 scsi_qla_host_t *vha = shost_priv(host);
1429 struct qla_hw_data *ha = vha->hw;
1430 int rval = 0;
1431
7d613ac6 1432 if (ha->flags.nic_core_reset_hdlr_active)
a49393f2
GM
1433 return -EBUSY;
1434
7c3df132 1435 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
f19af163
HZ
1436 if (rval)
1437 return rval;
1438
1439 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1440 ha->optrom_region_start, ha->optrom_region_size);
1441
1442 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1443 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1444 ha->optrom_region_size);
1445
1446 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1447 bsg_job->reply->result = DID_OK;
1448 vfree(ha->optrom_buffer);
1449 ha->optrom_buffer = NULL;
1450 ha->optrom_state = QLA_SWAITING;
1451 bsg_job->job_done(bsg_job);
1452 return rval;
1453}
1454
1455static int
1456qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1457{
1458 struct Scsi_Host *host = bsg_job->shost;
1459 scsi_qla_host_t *vha = shost_priv(host);
1460 struct qla_hw_data *ha = vha->hw;
1461 int rval = 0;
1462
7c3df132 1463 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
f19af163
HZ
1464 if (rval)
1465 return rval;
1466
b6d0d9d5
GM
1467 /* Set the isp82xx_no_md_cap not to capture minidump */
1468 ha->flags.isp82xx_no_md_cap = 1;
1469
f19af163
HZ
1470 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1471 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1472 ha->optrom_region_size);
1473
1474 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1475 ha->optrom_region_start, ha->optrom_region_size);
1476
1477 bsg_job->reply->result = DID_OK;
1478 vfree(ha->optrom_buffer);
1479 ha->optrom_buffer = NULL;
1480 ha->optrom_state = QLA_SWAITING;
1481 bsg_job->job_done(bsg_job);
1482 return rval;
1483}
1484
697a4bc6
JC
1485static int
1486qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1487{
1488 struct Scsi_Host *host = bsg_job->shost;
1489 scsi_qla_host_t *vha = shost_priv(host);
1490 struct qla_hw_data *ha = vha->hw;
1491 int rval = 0;
1492 uint8_t bsg[DMA_POOL_SIZE];
1493 struct qla_image_version_list *list = (void *)bsg;
1494 struct qla_image_version *image;
1495 uint32_t count;
1496 dma_addr_t sfp_dma;
1497 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1498 if (!sfp) {
1499 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1500 EXT_STATUS_NO_MEMORY;
1501 goto done;
1502 }
1503
1504 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1505 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1506
1507 image = list->version;
1508 count = list->count;
1509 while (count--) {
1510 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1511 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1512 image->field_address.device, image->field_address.offset,
1513 sizeof(image->field_info), image->field_address.option);
1514 if (rval) {
1515 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1516 EXT_STATUS_MAILBOX;
1517 goto dealloc;
1518 }
1519 image++;
1520 }
1521
1522 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1523
1524dealloc:
1525 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1526
1527done:
1528 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1529 bsg_job->reply->result = DID_OK << 16;
1530 bsg_job->job_done(bsg_job);
1531
1532 return 0;
1533}
1534
1535static int
1536qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1537{
1538 struct Scsi_Host *host = bsg_job->shost;
1539 scsi_qla_host_t *vha = shost_priv(host);
1540 struct qla_hw_data *ha = vha->hw;
1541 int rval = 0;
1542 uint8_t bsg[DMA_POOL_SIZE];
1543 struct qla_status_reg *sr = (void *)bsg;
1544 dma_addr_t sfp_dma;
1545 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1546 if (!sfp) {
1547 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1548 EXT_STATUS_NO_MEMORY;
1549 goto done;
1550 }
1551
1552 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1553 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1554
1555 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1556 sr->field_address.device, sr->field_address.offset,
1557 sizeof(sr->status_reg), sr->field_address.option);
1558 sr->status_reg = *sfp;
1559
1560 if (rval) {
1561 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1562 EXT_STATUS_MAILBOX;
1563 goto dealloc;
1564 }
1565
1566 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1567 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1568
1569 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1570
1571dealloc:
1572 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1573
1574done:
1575 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1576 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1577 bsg_job->reply->result = DID_OK << 16;
1578 bsg_job->job_done(bsg_job);
1579
1580 return 0;
1581}
1582
1583static int
1584qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1585{
1586 struct Scsi_Host *host = bsg_job->shost;
1587 scsi_qla_host_t *vha = shost_priv(host);
1588 struct qla_hw_data *ha = vha->hw;
1589 int rval = 0;
1590 uint8_t bsg[DMA_POOL_SIZE];
1591 struct qla_status_reg *sr = (void *)bsg;
1592 dma_addr_t sfp_dma;
1593 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1594 if (!sfp) {
1595 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1596 EXT_STATUS_NO_MEMORY;
1597 goto done;
1598 }
1599
1600 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1601 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1602
1603 *sfp = sr->status_reg;
1604 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1605 sr->field_address.device, sr->field_address.offset,
1606 sizeof(sr->status_reg), sr->field_address.option);
1607
1608 if (rval) {
1609 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1610 EXT_STATUS_MAILBOX;
1611 goto dealloc;
1612 }
1613
1614 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1615
1616dealloc:
1617 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1618
1619done:
1620 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1621 bsg_job->reply->result = DID_OK << 16;
1622 bsg_job->job_done(bsg_job);
1623
1624 return 0;
1625}
1626
9ebb5d9c
JC
1627static int
1628qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
1629{
1630 struct Scsi_Host *host = bsg_job->shost;
1631 scsi_qla_host_t *vha = shost_priv(host);
1632 struct qla_hw_data *ha = vha->hw;
1633 int rval = 0;
1634 uint8_t bsg[DMA_POOL_SIZE];
1635 struct qla_i2c_access *i2c = (void *)bsg;
1636 dma_addr_t sfp_dma;
1637 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1638 if (!sfp) {
1639 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1640 EXT_STATUS_NO_MEMORY;
1641 goto done;
1642 }
1643
1644 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1645 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1646
1647 memcpy(sfp, i2c->buffer, i2c->length);
1648 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1649 i2c->device, i2c->offset, i2c->length, i2c->option);
1650
1651 if (rval) {
1652 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1653 EXT_STATUS_MAILBOX;
1654 goto dealloc;
1655 }
1656
1657 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1658
1659dealloc:
1660 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1661
1662done:
1663 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1664 bsg_job->reply->result = DID_OK << 16;
1665 bsg_job->job_done(bsg_job);
1666
1667 return 0;
1668}
1669
1670static int
1671qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1672{
1673 struct Scsi_Host *host = bsg_job->shost;
1674 scsi_qla_host_t *vha = shost_priv(host);
1675 struct qla_hw_data *ha = vha->hw;
1676 int rval = 0;
1677 uint8_t bsg[DMA_POOL_SIZE];
1678 struct qla_i2c_access *i2c = (void *)bsg;
1679 dma_addr_t sfp_dma;
1680 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1681 if (!sfp) {
1682 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1683 EXT_STATUS_NO_MEMORY;
1684 goto done;
1685 }
1686
1687 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1688 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1689
1690 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1691 i2c->device, i2c->offset, i2c->length, i2c->option);
1692
1693 if (rval) {
1694 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1695 EXT_STATUS_MAILBOX;
1696 goto dealloc;
1697 }
1698
1699 memcpy(i2c->buffer, sfp, i2c->length);
1700 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1701 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1702
1703 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1704
1705dealloc:
1706 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1707
1708done:
1709 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1710 bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
1711 bsg_job->reply->result = DID_OK << 16;
1712 bsg_job->job_done(bsg_job);
1713
1714 return 0;
1715}
1716
a9b6f722
SK
1717static int
1718qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1719{
1720 struct Scsi_Host *host = bsg_job->shost;
1721 scsi_qla_host_t *vha = shost_priv(host);
1722 struct qla_hw_data *ha = vha->hw;
1723 uint16_t thread_id;
1724 uint32_t rval = EXT_STATUS_OK;
1725 uint16_t req_sg_cnt = 0;
1726 uint16_t rsp_sg_cnt = 0;
1727 uint16_t nextlid = 0;
1728 uint32_t tot_dsds;
1729 srb_t *sp = NULL;
1730 uint32_t req_data_len = 0;
1731 uint32_t rsp_data_len = 0;
1732
1733 /* Check the type of the adapter */
1734 if (!IS_BIDI_CAPABLE(ha)) {
1735 ql_log(ql_log_warn, vha, 0x70a0,
1736 "This adapter is not supported\n");
1737 rval = EXT_STATUS_NOT_SUPPORTED;
1738 goto done;
1739 }
1740
1741 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1742 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1743 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1744 rval = EXT_STATUS_BUSY;
1745 goto done;
1746 }
1747
1748 /* Check if host is online */
1749 if (!vha->flags.online) {
1750 ql_log(ql_log_warn, vha, 0x70a1,
1751 "Host is not online\n");
1752 rval = EXT_STATUS_DEVICE_OFFLINE;
1753 goto done;
1754 }
1755
1756 /* Check if cable is plugged in or not */
1757 if (vha->device_flags & DFLG_NO_CABLE) {
1758 ql_log(ql_log_warn, vha, 0x70a2,
1759 "Cable is unplugged...\n");
1760 rval = EXT_STATUS_INVALID_CFG;
1761 goto done;
1762 }
1763
1764 /* Check if the switch is connected or not */
1765 if (ha->current_topology != ISP_CFG_F) {
1766 ql_log(ql_log_warn, vha, 0x70a3,
1767 "Host is not connected to the switch\n");
1768 rval = EXT_STATUS_INVALID_CFG;
1769 goto done;
1770 }
1771
1772 /* Check if operating mode is P2P */
1773 if (ha->operating_mode != P2P) {
1774 ql_log(ql_log_warn, vha, 0x70a4,
1775 "Host is operating mode is not P2p\n");
1776 rval = EXT_STATUS_INVALID_CFG;
1777 goto done;
1778 }
1779
1780 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1781
1782 mutex_lock(&ha->selflogin_lock);
1783 if (vha->self_login_loop_id == 0) {
1784 /* Initialize all required fields of fcport */
1785 vha->bidir_fcport.vha = vha;
1786 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1787 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1788 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1789 vha->bidir_fcport.loop_id = vha->loop_id;
1790
1791 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1792 ql_log(ql_log_warn, vha, 0x70a7,
1793 "Failed to login port %06X for bidirectional IOCB\n",
1794 vha->bidir_fcport.d_id.b24);
1795 mutex_unlock(&ha->selflogin_lock);
1796 rval = EXT_STATUS_MAILBOX;
1797 goto done;
1798 }
1799 vha->self_login_loop_id = nextlid - 1;
1800
1801 }
1802 /* Assign the self login loop id to fcport */
1803 mutex_unlock(&ha->selflogin_lock);
1804
1805 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1806
1807 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1808 bsg_job->request_payload.sg_list,
1809 bsg_job->request_payload.sg_cnt,
1810 DMA_TO_DEVICE);
1811
1812 if (!req_sg_cnt) {
1813 rval = EXT_STATUS_NO_MEMORY;
1814 goto done;
1815 }
1816
1817 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1818 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1819 DMA_FROM_DEVICE);
1820
1821 if (!rsp_sg_cnt) {
1822 rval = EXT_STATUS_NO_MEMORY;
1823 goto done_unmap_req_sg;
1824 }
1825
1826 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1827 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1828 ql_dbg(ql_dbg_user, vha, 0x70a9,
1829 "Dma mapping resulted in different sg counts "
1830 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1831 "%x dma_reply_sg_cnt: %x]\n",
1832 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1833 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1834 rval = EXT_STATUS_NO_MEMORY;
1835 goto done_unmap_sg;
1836 }
1837
1838 if (req_data_len != rsp_data_len) {
1839 rval = EXT_STATUS_BUSY;
1840 ql_log(ql_log_warn, vha, 0x70aa,
1841 "req_data_len != rsp_data_len\n");
1842 goto done_unmap_sg;
1843 }
1844
1845 req_data_len = bsg_job->request_payload.payload_len;
1846 rsp_data_len = bsg_job->reply_payload.payload_len;
1847
1848
1849 /* Alloc SRB structure */
1850 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1851 if (!sp) {
1852 ql_dbg(ql_dbg_user, vha, 0x70ac,
1853 "Alloc SRB structure failed\n");
1854 rval = EXT_STATUS_NO_MEMORY;
1855 goto done_unmap_sg;
1856 }
1857
1858 /*Populate srb->ctx with bidir ctx*/
1859 sp->u.bsg_job = bsg_job;
1860 sp->free = qla2x00_bsg_sp_free;
1861 sp->type = SRB_BIDI_CMD;
1862 sp->done = qla2x00_bsg_job_done;
1863
1864 /* Add the read and write sg count */
1865 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1866
1867 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1868 if (rval != EXT_STATUS_OK)
1869 goto done_free_srb;
1870 /* the bsg request will be completed in the interrupt handler */
1871 return rval;
1872
1873done_free_srb:
1874 mempool_free(sp, ha->srb_mempool);
1875done_unmap_sg:
1876 dma_unmap_sg(&ha->pdev->dev,
1877 bsg_job->reply_payload.sg_list,
1878 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1879done_unmap_req_sg:
1880 dma_unmap_sg(&ha->pdev->dev,
1881 bsg_job->request_payload.sg_list,
1882 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1883done:
1884
1885 /* Return an error vendor specific response
1886 * and complete the bsg request
1887 */
1888 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1889 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1890 bsg_job->reply->reply_payload_rcv_len = 0;
1891 bsg_job->reply->result = (DID_OK) << 16;
1892 bsg_job->job_done(bsg_job);
1893 /* Always retrun success, vendor rsp carries correct status */
1894 return 0;
1895}
1896
8ae6d9c7
GM
1897static int
1898qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
1899{
1900 struct Scsi_Host *host = bsg_job->shost;
1901 scsi_qla_host_t *vha = shost_priv(host);
1902 struct qla_hw_data *ha = vha->hw;
1903 int rval = (DRIVER_ERROR << 16);
1904 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1905 srb_t *sp;
1906 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1907 struct fc_port *fcport;
1908 char *type = "FC_BSG_HST_FX_MGMT";
1909
1910 /* Copy the IOCB specific information */
1911 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1912 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1913
1914 /* Dump the vendor information */
1915 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1916 (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1917
1918 if (!vha->flags.online) {
1919 ql_log(ql_log_warn, vha, 0x70d0,
1920 "Host is not online.\n");
1921 rval = -EIO;
1922 goto done;
1923 }
1924
1925 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1926 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1927 bsg_job->request_payload.sg_list,
1928 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1929 if (!req_sg_cnt) {
1930 ql_log(ql_log_warn, vha, 0x70c7,
1931 "dma_map_sg return %d for request\n", req_sg_cnt);
1932 rval = -ENOMEM;
1933 goto done;
1934 }
1935 }
1936
1937 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1938 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1939 bsg_job->reply_payload.sg_list,
1940 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1941 if (!rsp_sg_cnt) {
1942 ql_log(ql_log_warn, vha, 0x70c8,
1943 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1944 rval = -ENOMEM;
1945 goto done_unmap_req_sg;
1946 }
1947 }
1948
1949 ql_dbg(ql_dbg_user, vha, 0x70c9,
1950 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
1951 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
1952 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1953
1954 /* Allocate a dummy fcport structure, since functions preparing the
1955 * IOCB and mailbox command retrieves port specific information
1956 * from fcport structure. For Host based ELS commands there will be
1957 * no fcport structure allocated
1958 */
1959 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1960 if (!fcport) {
1961 ql_log(ql_log_warn, vha, 0x70ca,
1962 "Failed to allocate fcport.\n");
1963 rval = -ENOMEM;
1964 goto done_unmap_rsp_sg;
1965 }
1966
1967 /* Alloc SRB structure */
1968 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1969 if (!sp) {
1970 ql_log(ql_log_warn, vha, 0x70cb,
1971 "qla2x00_get_sp failed.\n");
1972 rval = -ENOMEM;
1973 goto done_free_fcport;
1974 }
1975
1976 /* Initialize all required fields of fcport */
1977 fcport->vha = vha;
1978 fcport->loop_id = piocb_rqst->dataword;
1979
1980 sp->type = SRB_FXIOCB_BCMD;
1981 sp->name = "bsg_fx_mgmt";
1982 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
1983 sp->u.bsg_job = bsg_job;
1984 sp->free = qla2x00_bsg_sp_free;
1985 sp->done = qla2x00_bsg_job_done;
1986
1987 ql_dbg(ql_dbg_user, vha, 0x70cc,
1988 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
1989 type, piocb_rqst->func_type, fcport->loop_id);
1990
1991 rval = qla2x00_start_sp(sp);
1992 if (rval != QLA_SUCCESS) {
1993 ql_log(ql_log_warn, vha, 0x70cd,
1994 "qla2x00_start_sp failed=%d.\n", rval);
1995 mempool_free(sp, ha->srb_mempool);
1996 rval = -EIO;
1997 goto done_free_fcport;
1998 }
1999 return rval;
2000
2001done_free_fcport:
2002 kfree(fcport);
2003
2004done_unmap_rsp_sg:
2005 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2006 dma_unmap_sg(&ha->pdev->dev,
2007 bsg_job->reply_payload.sg_list,
2008 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2009done_unmap_req_sg:
2010 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2011 dma_unmap_sg(&ha->pdev->dev,
2012 bsg_job->request_payload.sg_list,
2013 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2014
2015done:
2016 return rval;
2017}
2018
6e98016c
GM
2019static int
2020qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2021{
2022 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
2023 case QL_VND_LOOPBACK:
2024 return qla2x00_process_loopback(bsg_job);
2025
2026 case QL_VND_A84_RESET:
2027 return qla84xx_reset(bsg_job);
2028
2029 case QL_VND_A84_UPDATE_FW:
2030 return qla84xx_updatefw(bsg_job);
2031
2032 case QL_VND_A84_MGMT_CMD:
2033 return qla84xx_mgmt_cmd(bsg_job);
2034
2035 case QL_VND_IIDMA:
2036 return qla24xx_iidma(bsg_job);
2037
09ff701a
SR
2038 case QL_VND_FCP_PRIO_CFG_CMD:
2039 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2040
f19af163
HZ
2041 case QL_VND_READ_FLASH:
2042 return qla2x00_read_optrom(bsg_job);
2043
2044 case QL_VND_UPDATE_FLASH:
2045 return qla2x00_update_optrom(bsg_job);
2046
697a4bc6
JC
2047 case QL_VND_SET_FRU_VERSION:
2048 return qla2x00_update_fru_versions(bsg_job);
2049
2050 case QL_VND_READ_FRU_STATUS:
2051 return qla2x00_read_fru_status(bsg_job);
2052
2053 case QL_VND_WRITE_FRU_STATUS:
2054 return qla2x00_write_fru_status(bsg_job);
2055
9ebb5d9c
JC
2056 case QL_VND_WRITE_I2C:
2057 return qla2x00_write_i2c(bsg_job);
2058
2059 case QL_VND_READ_I2C:
2060 return qla2x00_read_i2c(bsg_job);
2061
a9b6f722
SK
2062 case QL_VND_DIAG_IO_CMD:
2063 return qla24xx_process_bidir_cmd(bsg_job);
2064
8ae6d9c7
GM
2065 case QL_VND_FX00_MGMT_CMD:
2066 return qlafx00_mgmt_cmd(bsg_job);
6e98016c 2067 default:
6e98016c
GM
2068 return -ENOSYS;
2069 }
2070}
2071
2072int
2073qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2074{
2075 int ret = -EINVAL;
7c3df132
SK
2076 struct fc_rport *rport;
2077 fc_port_t *fcport = NULL;
2078 struct Scsi_Host *host;
2079 scsi_qla_host_t *vha;
2080
b7bfbe12
AV
2081 /* In case no data transferred. */
2082 bsg_job->reply->reply_payload_rcv_len = 0;
2083
7c3df132
SK
2084 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
2085 rport = bsg_job->rport;
2086 fcport = *(fc_port_t **) rport->dd_data;
2087 host = rport_to_shost(rport);
2088 vha = shost_priv(host);
2089 } else {
2090 host = bsg_job->shost;
2091 vha = shost_priv(host);
2092 }
2093
d051a5aa
AV
2094 if (qla2x00_reset_active(vha)) {
2095 ql_dbg(ql_dbg_user, vha, 0x709f,
2096 "BSG: ISP abort active/needed -- cmd=%d.\n",
2097 bsg_job->request->msgcode);
d051a5aa
AV
2098 return -EBUSY;
2099 }
2100
7c3df132 2101 ql_dbg(ql_dbg_user, vha, 0x7000,
cfb0919c 2102 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
6e98016c
GM
2103
2104 switch (bsg_job->request->msgcode) {
2105 case FC_BSG_RPT_ELS:
2106 case FC_BSG_HST_ELS_NOLOGIN:
2107 ret = qla2x00_process_els(bsg_job);
2108 break;
2109 case FC_BSG_HST_CT:
2110 ret = qla2x00_process_ct(bsg_job);
2111 break;
2112 case FC_BSG_HST_VENDOR:
2113 ret = qla2x00_process_vendor_specific(bsg_job);
2114 break;
2115 case FC_BSG_HST_ADD_RPORT:
2116 case FC_BSG_HST_DEL_RPORT:
2117 case FC_BSG_RPT_CT:
2118 default:
7c3df132 2119 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
6e98016c 2120 break;
6c452a45 2121 }
6e98016c
GM
2122 return ret;
2123}
2124
2125int
2126qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2127{
2128 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2129 struct qla_hw_data *ha = vha->hw;
2130 srb_t *sp;
2131 int cnt, que;
2132 unsigned long flags;
2133 struct req_que *req;
6e98016c
GM
2134
2135 /* find the bsg job from the active list of commands */
2136 spin_lock_irqsave(&ha->hardware_lock, flags);
2137 for (que = 0; que < ha->max_req_queues; que++) {
2138 req = ha->req_q_map[que];
2139 if (!req)
2140 continue;
2141
8d93f550 2142 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
6e98016c 2143 sp = req->outstanding_cmds[cnt];
6e98016c 2144 if (sp) {
9ba56b95 2145 if (((sp->type == SRB_CT_CMD) ||
8ae6d9c7
GM
2146 (sp->type == SRB_ELS_CMD_HST) ||
2147 (sp->type == SRB_FXIOCB_BCMD))
9ba56b95 2148 && (sp->u.bsg_job == bsg_job)) {
8edf3edd 2149 req->outstanding_cmds[cnt] = NULL;
900a36e3 2150 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6e98016c 2151 if (ha->isp_ops->abort_command(sp)) {
7c3df132
SK
2152 ql_log(ql_log_warn, vha, 0x7089,
2153 "mbx abort_command "
2154 "failed.\n");
6e98016c
GM
2155 bsg_job->req->errors =
2156 bsg_job->reply->result = -EIO;
2157 } else {
7c3df132
SK
2158 ql_dbg(ql_dbg_user, vha, 0x708a,
2159 "mbx abort_command "
2160 "success.\n");
6e98016c
GM
2161 bsg_job->req->errors =
2162 bsg_job->reply->result = 0;
2163 }
900a36e3 2164 spin_lock_irqsave(&ha->hardware_lock, flags);
6e98016c
GM
2165 goto done;
2166 }
2167 }
2168 }
2169 }
2170 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7c3df132 2171 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
6e98016c
GM
2172 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2173 return 0;
2174
2175done:
2176 spin_unlock_irqrestore(&ha->hardware_lock, flags);
8edf3edd 2177 sp->free(vha, sp);
6e98016c
GM
2178 return 0;
2179}
This page took 0.320309 seconds and 5 git commands to generate.