scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly
[linux/fpc-iii.git] / drivers / scsi / qla2xxx / qla_bsg.c
blob40f7c1081e8d9b9b41b8ef3b95d66a1349178c1f
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
13 /* BSG support for ELS/CT pass through */
14 void
15 qla2x00_bsg_job_done(void *data, void *ptr, int res)
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 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
22 bsg_reply->result = res;
23 bsg_job->job_done(bsg_job);
24 sp->free(vha, sp);
27 void
28 qla2x00_bsg_sp_free(void *data, void *ptr)
30 srb_t *sp = (srb_t *)ptr;
31 struct scsi_qla_host *vha = sp->fcport->vha;
32 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
33 struct fc_bsg_request *bsg_request = bsg_job->request;
35 struct qla_hw_data *ha = vha->hw;
36 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
38 if (sp->type == SRB_FXIOCB_BCMD) {
39 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
40 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
42 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
43 dma_unmap_sg(&ha->pdev->dev,
44 bsg_job->request_payload.sg_list,
45 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
47 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
48 dma_unmap_sg(&ha->pdev->dev,
49 bsg_job->reply_payload.sg_list,
50 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
51 } else {
52 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
53 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
55 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
56 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
59 if (sp->type == SRB_CT_CMD ||
60 sp->type == SRB_FXIOCB_BCMD ||
61 sp->type == SRB_ELS_CMD_HST)
62 kfree(sp->fcport);
63 qla2x00_rel_sp(vha, sp);
66 int
67 qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
68 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
70 int i, ret, num_valid;
71 uint8_t *bcode;
72 struct qla_fcp_prio_entry *pri_entry;
73 uint32_t *bcode_val_ptr, bcode_val;
75 ret = 1;
76 num_valid = 0;
77 bcode = (uint8_t *)pri_cfg;
78 bcode_val_ptr = (uint32_t *)pri_cfg;
79 bcode_val = (uint32_t)(*bcode_val_ptr);
81 if (bcode_val == 0xFFFFFFFF) {
82 /* No FCP Priority config data in flash */
83 ql_dbg(ql_dbg_user, vha, 0x7051,
84 "No FCP Priority config data.\n");
85 return 0;
88 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
89 bcode[3] != 'S') {
90 /* Invalid FCP priority data header*/
91 ql_dbg(ql_dbg_user, vha, 0x7052,
92 "Invalid FCP Priority data header. bcode=0x%x.\n",
93 bcode_val);
94 return 0;
96 if (flag != 1)
97 return ret;
99 pri_entry = &pri_cfg->entry[0];
100 for (i = 0; i < pri_cfg->num_entries; i++) {
101 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
102 num_valid++;
103 pri_entry++;
106 if (num_valid == 0) {
107 /* No valid FCP priority data entries */
108 ql_dbg(ql_dbg_user, vha, 0x7053,
109 "No valid FCP Priority data entries.\n");
110 ret = 0;
111 } else {
112 /* FCP priority data is valid */
113 ql_dbg(ql_dbg_user, vha, 0x7054,
114 "Valid FCP priority data. num entries = %d.\n",
115 num_valid);
118 return ret;
121 static int
122 qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
124 struct Scsi_Host *host = bsg_job->shost;
125 struct fc_bsg_request *bsg_request = bsg_job->request;
126 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
127 scsi_qla_host_t *vha = shost_priv(host);
128 struct qla_hw_data *ha = vha->hw;
129 int ret = 0;
130 uint32_t len;
131 uint32_t oper;
133 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
134 ret = -EINVAL;
135 goto exit_fcp_prio_cfg;
138 /* Get the sub command */
139 oper = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
141 /* Only set config is allowed if config memory is not allocated */
142 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
143 ret = -EINVAL;
144 goto exit_fcp_prio_cfg;
146 switch (oper) {
147 case QLFC_FCP_PRIO_DISABLE:
148 if (ha->flags.fcp_prio_enabled) {
149 ha->flags.fcp_prio_enabled = 0;
150 ha->fcp_prio_cfg->attributes &=
151 ~FCP_PRIO_ATTR_ENABLE;
152 qla24xx_update_all_fcp_prio(vha);
153 bsg_reply->result = DID_OK;
154 } else {
155 ret = -EINVAL;
156 bsg_reply->result = (DID_ERROR << 16);
157 goto exit_fcp_prio_cfg;
159 break;
161 case QLFC_FCP_PRIO_ENABLE:
162 if (!ha->flags.fcp_prio_enabled) {
163 if (ha->fcp_prio_cfg) {
164 ha->flags.fcp_prio_enabled = 1;
165 ha->fcp_prio_cfg->attributes |=
166 FCP_PRIO_ATTR_ENABLE;
167 qla24xx_update_all_fcp_prio(vha);
168 bsg_reply->result = DID_OK;
169 } else {
170 ret = -EINVAL;
171 bsg_reply->result = (DID_ERROR << 16);
172 goto exit_fcp_prio_cfg;
175 break;
177 case QLFC_FCP_PRIO_GET_CONFIG:
178 len = bsg_job->reply_payload.payload_len;
179 if (!len || len > FCP_PRIO_CFG_SIZE) {
180 ret = -EINVAL;
181 bsg_reply->result = (DID_ERROR << 16);
182 goto exit_fcp_prio_cfg;
185 bsg_reply->result = DID_OK;
186 bsg_reply->reply_payload_rcv_len =
187 sg_copy_from_buffer(
188 bsg_job->reply_payload.sg_list,
189 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
190 len);
192 break;
194 case QLFC_FCP_PRIO_SET_CONFIG:
195 len = bsg_job->request_payload.payload_len;
196 if (!len || len > FCP_PRIO_CFG_SIZE) {
197 bsg_reply->result = (DID_ERROR << 16);
198 ret = -EINVAL;
199 goto exit_fcp_prio_cfg;
202 if (!ha->fcp_prio_cfg) {
203 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
204 if (!ha->fcp_prio_cfg) {
205 ql_log(ql_log_warn, vha, 0x7050,
206 "Unable to allocate memory for fcp prio "
207 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
208 bsg_reply->result = (DID_ERROR << 16);
209 ret = -ENOMEM;
210 goto exit_fcp_prio_cfg;
214 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
215 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
216 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
217 FCP_PRIO_CFG_SIZE);
219 /* validate fcp priority data */
221 if (!qla24xx_fcp_prio_cfg_valid(vha,
222 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
223 bsg_reply->result = (DID_ERROR << 16);
224 ret = -EINVAL;
225 /* If buffer was invalidatic int
226 * fcp_prio_cfg is of no use
228 vfree(ha->fcp_prio_cfg);
229 ha->fcp_prio_cfg = NULL;
230 goto exit_fcp_prio_cfg;
233 ha->flags.fcp_prio_enabled = 0;
234 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
235 ha->flags.fcp_prio_enabled = 1;
236 qla24xx_update_all_fcp_prio(vha);
237 bsg_reply->result = DID_OK;
238 break;
239 default:
240 ret = -EINVAL;
241 break;
243 exit_fcp_prio_cfg:
244 if (!ret)
245 bsg_job->job_done(bsg_job);
246 return ret;
249 static int
250 qla2x00_process_els(struct fc_bsg_job *bsg_job)
252 struct fc_bsg_request *bsg_request = bsg_job->request;
253 struct fc_rport *rport;
254 fc_port_t *fcport = NULL;
255 struct Scsi_Host *host;
256 scsi_qla_host_t *vha;
257 struct qla_hw_data *ha;
258 srb_t *sp;
259 const char *type;
260 int req_sg_cnt, rsp_sg_cnt;
261 int rval = (DRIVER_ERROR << 16);
262 uint16_t nextlid = 0;
264 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
265 rport = bsg_job->rport;
266 fcport = *(fc_port_t **) rport->dd_data;
267 host = rport_to_shost(rport);
268 vha = shost_priv(host);
269 ha = vha->hw;
270 type = "FC_BSG_RPT_ELS";
271 } else {
272 host = bsg_job->shost;
273 vha = shost_priv(host);
274 ha = vha->hw;
275 type = "FC_BSG_HST_ELS_NOLOGIN";
278 if (!vha->flags.online) {
279 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
280 rval = -EIO;
281 goto done;
284 /* pass through is supported only for ISP 4Gb or higher */
285 if (!IS_FWI2_CAPABLE(ha)) {
286 ql_dbg(ql_dbg_user, vha, 0x7001,
287 "ELS passthru not supported for ISP23xx based adapters.\n");
288 rval = -EPERM;
289 goto done;
292 /* Multiple SG's are not supported for ELS requests */
293 if (bsg_job->request_payload.sg_cnt > 1 ||
294 bsg_job->reply_payload.sg_cnt > 1) {
295 ql_dbg(ql_dbg_user, vha, 0x7002,
296 "Multiple SG's are not suppored for ELS requests, "
297 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
298 bsg_job->request_payload.sg_cnt,
299 bsg_job->reply_payload.sg_cnt);
300 rval = -EPERM;
301 goto done;
304 /* ELS request for rport */
305 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
306 /* make sure the rport is logged in,
307 * if not perform fabric login
309 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
310 ql_dbg(ql_dbg_user, vha, 0x7003,
311 "Failed to login port %06X for ELS passthru.\n",
312 fcport->d_id.b24);
313 rval = -EIO;
314 goto done;
316 } else {
317 /* Allocate a dummy fcport structure, since functions
318 * preparing the IOCB and mailbox command retrieves port
319 * specific information from fcport structure. For Host based
320 * ELS commands there will be no fcport structure allocated
322 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
323 if (!fcport) {
324 rval = -ENOMEM;
325 goto done;
328 /* Initialize all required fields of fcport */
329 fcport->vha = vha;
330 fcport->d_id.b.al_pa =
331 bsg_request->rqst_data.h_els.port_id[0];
332 fcport->d_id.b.area =
333 bsg_request->rqst_data.h_els.port_id[1];
334 fcport->d_id.b.domain =
335 bsg_request->rqst_data.h_els.port_id[2];
336 fcport->loop_id =
337 (fcport->d_id.b.al_pa == 0xFD) ?
338 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
341 req_sg_cnt =
342 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
343 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
344 if (!req_sg_cnt) {
345 rval = -ENOMEM;
346 goto done_free_fcport;
349 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
350 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
351 if (!rsp_sg_cnt) {
352 rval = -ENOMEM;
353 goto done_free_fcport;
356 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
357 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
358 ql_log(ql_log_warn, vha, 0x7008,
359 "dma mapping resulted in different sg counts, "
360 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
361 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
362 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
363 rval = -EAGAIN;
364 goto done_unmap_sg;
367 /* Alloc SRB structure */
368 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
369 if (!sp) {
370 rval = -ENOMEM;
371 goto done_unmap_sg;
374 sp->type =
375 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
376 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
377 sp->name =
378 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
379 "bsg_els_rpt" : "bsg_els_hst");
380 sp->u.bsg_job = bsg_job;
381 sp->free = qla2x00_bsg_sp_free;
382 sp->done = qla2x00_bsg_job_done;
384 ql_dbg(ql_dbg_user, vha, 0x700a,
385 "bsg rqst type: %s els type: %x - loop-id=%x "
386 "portid=%-2x%02x%02x.\n", type,
387 bsg_request->rqst_data.h_els.command_code, fcport->loop_id,
388 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
390 rval = qla2x00_start_sp(sp);
391 if (rval != QLA_SUCCESS) {
392 ql_log(ql_log_warn, vha, 0x700e,
393 "qla2x00_start_sp failed = %d\n", rval);
394 qla2x00_rel_sp(vha, sp);
395 rval = -EIO;
396 goto done_unmap_sg;
398 return rval;
400 done_unmap_sg:
401 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
402 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
403 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
404 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
405 goto done_free_fcport;
407 done_free_fcport:
408 if (bsg_request->msgcode == FC_BSG_RPT_ELS)
409 kfree(fcport);
410 done:
411 return rval;
414 static inline uint16_t
415 qla24xx_calc_ct_iocbs(uint16_t dsds)
417 uint16_t iocbs;
419 iocbs = 1;
420 if (dsds > 2) {
421 iocbs += (dsds - 2) / 5;
422 if ((dsds - 2) % 5)
423 iocbs++;
425 return iocbs;
428 static int
429 qla2x00_process_ct(struct fc_bsg_job *bsg_job)
431 srb_t *sp;
432 struct fc_bsg_request *bsg_request = bsg_job->request;
433 struct Scsi_Host *host = bsg_job->shost;
434 scsi_qla_host_t *vha = shost_priv(host);
435 struct qla_hw_data *ha = vha->hw;
436 int rval = (DRIVER_ERROR << 16);
437 int req_sg_cnt, rsp_sg_cnt;
438 uint16_t loop_id;
439 struct fc_port *fcport;
440 char *type = "FC_BSG_HST_CT";
442 req_sg_cnt =
443 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
444 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
445 if (!req_sg_cnt) {
446 ql_log(ql_log_warn, vha, 0x700f,
447 "dma_map_sg return %d for request\n", req_sg_cnt);
448 rval = -ENOMEM;
449 goto done;
452 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
453 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
454 if (!rsp_sg_cnt) {
455 ql_log(ql_log_warn, vha, 0x7010,
456 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
457 rval = -ENOMEM;
458 goto done;
461 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
462 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
463 ql_log(ql_log_warn, vha, 0x7011,
464 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
465 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
466 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
467 rval = -EAGAIN;
468 goto done_unmap_sg;
471 if (!vha->flags.online) {
472 ql_log(ql_log_warn, vha, 0x7012,
473 "Host is not online.\n");
474 rval = -EIO;
475 goto done_unmap_sg;
478 loop_id =
479 (bsg_request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
480 >> 24;
481 switch (loop_id) {
482 case 0xFC:
483 loop_id = cpu_to_le16(NPH_SNS);
484 break;
485 case 0xFA:
486 loop_id = vha->mgmt_svr_loop_id;
487 break;
488 default:
489 ql_dbg(ql_dbg_user, vha, 0x7013,
490 "Unknown loop id: %x.\n", loop_id);
491 rval = -EINVAL;
492 goto done_unmap_sg;
495 /* Allocate a dummy fcport structure, since functions preparing the
496 * IOCB and mailbox command retrieves port specific information
497 * from fcport structure. For Host based ELS commands there will be
498 * no fcport structure allocated
500 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
501 if (!fcport) {
502 ql_log(ql_log_warn, vha, 0x7014,
503 "Failed to allocate fcport.\n");
504 rval = -ENOMEM;
505 goto done_unmap_sg;
508 /* Initialize all required fields of fcport */
509 fcport->vha = vha;
510 fcport->d_id.b.al_pa = bsg_request->rqst_data.h_ct.port_id[0];
511 fcport->d_id.b.area = bsg_request->rqst_data.h_ct.port_id[1];
512 fcport->d_id.b.domain = bsg_request->rqst_data.h_ct.port_id[2];
513 fcport->loop_id = loop_id;
515 /* Alloc SRB structure */
516 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
517 if (!sp) {
518 ql_log(ql_log_warn, vha, 0x7015,
519 "qla2x00_get_sp failed.\n");
520 rval = -ENOMEM;
521 goto done_free_fcport;
524 sp->type = SRB_CT_CMD;
525 sp->name = "bsg_ct";
526 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
527 sp->u.bsg_job = bsg_job;
528 sp->free = qla2x00_bsg_sp_free;
529 sp->done = qla2x00_bsg_job_done;
531 ql_dbg(ql_dbg_user, vha, 0x7016,
532 "bsg rqst type: %s else type: %x - "
533 "loop-id=%x portid=%02x%02x%02x.\n", type,
534 (bsg_request->rqst_data.h_ct.preamble_word2 >> 16),
535 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
536 fcport->d_id.b.al_pa);
538 rval = qla2x00_start_sp(sp);
539 if (rval != QLA_SUCCESS) {
540 ql_log(ql_log_warn, vha, 0x7017,
541 "qla2x00_start_sp failed=%d.\n", rval);
542 qla2x00_rel_sp(vha, sp);
543 rval = -EIO;
544 goto done_free_fcport;
546 return rval;
548 done_free_fcport:
549 kfree(fcport);
550 done_unmap_sg:
551 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
552 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
553 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
554 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
555 done:
556 return rval;
559 /* Disable loopback mode */
560 static inline int
561 qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
562 int wait, int wait2)
564 int ret = 0;
565 int rval = 0;
566 uint16_t new_config[4];
567 struct qla_hw_data *ha = vha->hw;
569 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
570 goto done_reset_internal;
572 memset(new_config, 0 , sizeof(new_config));
573 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
574 ENABLE_INTERNAL_LOOPBACK ||
575 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
576 ENABLE_EXTERNAL_LOOPBACK) {
577 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
578 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
579 (new_config[0] & INTERNAL_LOOPBACK_MASK));
580 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
582 ha->notify_dcbx_comp = wait;
583 ha->notify_lb_portup_comp = wait2;
585 ret = qla81xx_set_port_config(vha, new_config);
586 if (ret != QLA_SUCCESS) {
587 ql_log(ql_log_warn, vha, 0x7025,
588 "Set port config failed.\n");
589 ha->notify_dcbx_comp = 0;
590 ha->notify_lb_portup_comp = 0;
591 rval = -EINVAL;
592 goto done_reset_internal;
595 /* Wait for DCBX complete event */
596 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
597 (DCBX_COMP_TIMEOUT * HZ))) {
598 ql_dbg(ql_dbg_user, vha, 0x7026,
599 "DCBX completion not received.\n");
600 ha->notify_dcbx_comp = 0;
601 ha->notify_lb_portup_comp = 0;
602 rval = -EINVAL;
603 goto done_reset_internal;
604 } else
605 ql_dbg(ql_dbg_user, vha, 0x7027,
606 "DCBX completion received.\n");
608 if (wait2 &&
609 !wait_for_completion_timeout(&ha->lb_portup_comp,
610 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
611 ql_dbg(ql_dbg_user, vha, 0x70c5,
612 "Port up completion not received.\n");
613 ha->notify_lb_portup_comp = 0;
614 rval = -EINVAL;
615 goto done_reset_internal;
616 } else
617 ql_dbg(ql_dbg_user, vha, 0x70c6,
618 "Port up completion received.\n");
620 ha->notify_dcbx_comp = 0;
621 ha->notify_lb_portup_comp = 0;
623 done_reset_internal:
624 return rval;
628 * Set the port configuration to enable the internal or external loopback
629 * depending on the loopback mode.
631 static inline int
632 qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
633 uint16_t *new_config, uint16_t mode)
635 int ret = 0;
636 int rval = 0;
637 unsigned long rem_tmo = 0, current_tmo = 0;
638 struct qla_hw_data *ha = vha->hw;
640 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
641 goto done_set_internal;
643 if (mode == INTERNAL_LOOPBACK)
644 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
645 else if (mode == EXTERNAL_LOOPBACK)
646 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
647 ql_dbg(ql_dbg_user, vha, 0x70be,
648 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
650 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
652 ha->notify_dcbx_comp = 1;
653 ret = qla81xx_set_port_config(vha, new_config);
654 if (ret != QLA_SUCCESS) {
655 ql_log(ql_log_warn, vha, 0x7021,
656 "set port config failed.\n");
657 ha->notify_dcbx_comp = 0;
658 rval = -EINVAL;
659 goto done_set_internal;
662 /* Wait for DCBX complete event */
663 current_tmo = DCBX_COMP_TIMEOUT * HZ;
664 while (1) {
665 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
666 current_tmo);
667 if (!ha->idc_extend_tmo || rem_tmo) {
668 ha->idc_extend_tmo = 0;
669 break;
671 current_tmo = ha->idc_extend_tmo * HZ;
672 ha->idc_extend_tmo = 0;
675 if (!rem_tmo) {
676 ql_dbg(ql_dbg_user, vha, 0x7022,
677 "DCBX completion not received.\n");
678 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
680 * If the reset of the loopback mode doesn't work take a FCoE
681 * dump and reset the chip.
683 if (ret) {
684 ha->isp_ops->fw_dump(vha, 0);
685 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
687 rval = -EINVAL;
688 } else {
689 if (ha->flags.idc_compl_status) {
690 ql_dbg(ql_dbg_user, vha, 0x70c3,
691 "Bad status in IDC Completion AEN\n");
692 rval = -EINVAL;
693 ha->flags.idc_compl_status = 0;
694 } else
695 ql_dbg(ql_dbg_user, vha, 0x7023,
696 "DCBX completion received.\n");
699 ha->notify_dcbx_comp = 0;
700 ha->idc_extend_tmo = 0;
702 done_set_internal:
703 return rval;
706 static int
707 qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
709 struct fc_bsg_request *bsg_request = bsg_job->request;
710 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
711 struct Scsi_Host *host = bsg_job->shost;
712 scsi_qla_host_t *vha = shost_priv(host);
713 struct qla_hw_data *ha = vha->hw;
714 int rval;
715 uint8_t command_sent;
716 char *type;
717 struct msg_echo_lb elreq;
718 uint16_t response[MAILBOX_REGISTER_COUNT];
719 uint16_t config[4], new_config[4];
720 uint8_t *fw_sts_ptr;
721 uint8_t *req_data = NULL;
722 dma_addr_t req_data_dma;
723 uint32_t req_data_len;
724 uint8_t *rsp_data = NULL;
725 dma_addr_t rsp_data_dma;
726 uint32_t rsp_data_len;
728 if (!vha->flags.online) {
729 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
730 return -EIO;
733 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
734 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
735 DMA_TO_DEVICE);
737 if (!elreq.req_sg_cnt) {
738 ql_log(ql_log_warn, vha, 0x701a,
739 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
740 return -ENOMEM;
743 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
744 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
745 DMA_FROM_DEVICE);
747 if (!elreq.rsp_sg_cnt) {
748 ql_log(ql_log_warn, vha, 0x701b,
749 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
750 rval = -ENOMEM;
751 goto done_unmap_req_sg;
754 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
755 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
756 ql_log(ql_log_warn, vha, 0x701c,
757 "dma mapping resulted in different sg counts, "
758 "request_sg_cnt: %x dma_request_sg_cnt: %x "
759 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
760 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
761 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
762 rval = -EAGAIN;
763 goto done_unmap_sg;
765 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
766 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
767 &req_data_dma, GFP_KERNEL);
768 if (!req_data) {
769 ql_log(ql_log_warn, vha, 0x701d,
770 "dma alloc failed for req_data.\n");
771 rval = -ENOMEM;
772 goto done_unmap_sg;
775 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
776 &rsp_data_dma, GFP_KERNEL);
777 if (!rsp_data) {
778 ql_log(ql_log_warn, vha, 0x7004,
779 "dma alloc failed for rsp_data.\n");
780 rval = -ENOMEM;
781 goto done_free_dma_req;
784 /* Copy the request buffer in req_data now */
785 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
786 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
788 elreq.send_dma = req_data_dma;
789 elreq.rcv_dma = rsp_data_dma;
790 elreq.transfer_size = req_data_len;
792 elreq.options = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
793 elreq.iteration_count =
794 bsg_request->rqst_data.h_vendor.vendor_cmd[2];
796 if (atomic_read(&vha->loop_state) == LOOP_READY &&
797 (ha->current_topology == ISP_CFG_F ||
798 ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
799 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
800 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
801 elreq.options == EXTERNAL_LOOPBACK) {
802 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
803 ql_dbg(ql_dbg_user, vha, 0x701e,
804 "BSG request type: %s.\n", type);
805 command_sent = INT_DEF_LB_ECHO_CMD;
806 rval = qla2x00_echo_test(vha, &elreq, response);
807 } else {
808 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
809 memset(config, 0, sizeof(config));
810 memset(new_config, 0, sizeof(new_config));
812 if (qla81xx_get_port_config(vha, config)) {
813 ql_log(ql_log_warn, vha, 0x701f,
814 "Get port config failed.\n");
815 rval = -EPERM;
816 goto done_free_dma_rsp;
819 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
820 ql_dbg(ql_dbg_user, vha, 0x70c4,
821 "Loopback operation already in "
822 "progress.\n");
823 rval = -EAGAIN;
824 goto done_free_dma_rsp;
827 ql_dbg(ql_dbg_user, vha, 0x70c0,
828 "elreq.options=%04x\n", elreq.options);
830 if (elreq.options == EXTERNAL_LOOPBACK)
831 if (IS_QLA8031(ha) || IS_QLA8044(ha))
832 rval = qla81xx_set_loopback_mode(vha,
833 config, new_config, elreq.options);
834 else
835 rval = qla81xx_reset_loopback_mode(vha,
836 config, 1, 0);
837 else
838 rval = qla81xx_set_loopback_mode(vha, config,
839 new_config, elreq.options);
841 if (rval) {
842 rval = -EPERM;
843 goto done_free_dma_rsp;
846 type = "FC_BSG_HST_VENDOR_LOOPBACK";
847 ql_dbg(ql_dbg_user, vha, 0x7028,
848 "BSG request type: %s.\n", type);
850 command_sent = INT_DEF_LB_LOOPBACK_CMD;
851 rval = qla2x00_loopback_test(vha, &elreq, response);
853 if (response[0] == MBS_COMMAND_ERROR &&
854 response[1] == MBS_LB_RESET) {
855 ql_log(ql_log_warn, vha, 0x7029,
856 "MBX command error, Aborting ISP.\n");
857 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
858 qla2xxx_wake_dpc(vha);
859 qla2x00_wait_for_chip_reset(vha);
860 /* Also reset the MPI */
861 if (IS_QLA81XX(ha)) {
862 if (qla81xx_restart_mpi_firmware(vha) !=
863 QLA_SUCCESS) {
864 ql_log(ql_log_warn, vha, 0x702a,
865 "MPI reset failed.\n");
869 rval = -EIO;
870 goto done_free_dma_rsp;
873 if (new_config[0]) {
874 int ret;
876 /* Revert back to original port config
877 * Also clear internal loopback
879 ret = qla81xx_reset_loopback_mode(vha,
880 new_config, 0, 1);
881 if (ret) {
883 * If the reset of the loopback mode
884 * doesn't work take FCoE dump and then
885 * reset the chip.
887 ha->isp_ops->fw_dump(vha, 0);
888 set_bit(ISP_ABORT_NEEDED,
889 &vha->dpc_flags);
894 } else {
895 type = "FC_BSG_HST_VENDOR_LOOPBACK";
896 ql_dbg(ql_dbg_user, vha, 0x702b,
897 "BSG request type: %s.\n", type);
898 command_sent = INT_DEF_LB_LOOPBACK_CMD;
899 rval = qla2x00_loopback_test(vha, &elreq, response);
903 if (rval) {
904 ql_log(ql_log_warn, vha, 0x702c,
905 "Vendor request %s failed.\n", type);
907 rval = 0;
908 bsg_reply->result = (DID_ERROR << 16);
909 bsg_reply->reply_payload_rcv_len = 0;
910 } else {
911 ql_dbg(ql_dbg_user, vha, 0x702d,
912 "Vendor request %s completed.\n", type);
913 bsg_reply->result = (DID_OK << 16);
914 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
915 bsg_job->reply_payload.sg_cnt, rsp_data,
916 rsp_data_len);
919 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
920 sizeof(response) + sizeof(uint8_t);
921 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
922 sizeof(struct fc_bsg_reply);
923 memcpy(fw_sts_ptr, response, sizeof(response));
924 fw_sts_ptr += sizeof(response);
925 *fw_sts_ptr = command_sent;
927 done_free_dma_rsp:
928 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
929 rsp_data, rsp_data_dma);
930 done_free_dma_req:
931 dma_free_coherent(&ha->pdev->dev, req_data_len,
932 req_data, req_data_dma);
933 done_unmap_sg:
934 dma_unmap_sg(&ha->pdev->dev,
935 bsg_job->reply_payload.sg_list,
936 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
937 done_unmap_req_sg:
938 dma_unmap_sg(&ha->pdev->dev,
939 bsg_job->request_payload.sg_list,
940 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
941 if (!rval)
942 bsg_job->job_done(bsg_job);
943 return rval;
946 static int
947 qla84xx_reset(struct fc_bsg_job *bsg_job)
949 struct fc_bsg_request *bsg_request = bsg_job->request;
950 struct Scsi_Host *host = bsg_job->shost;
951 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
952 scsi_qla_host_t *vha = shost_priv(host);
953 struct qla_hw_data *ha = vha->hw;
954 int rval = 0;
955 uint32_t flag;
957 if (!IS_QLA84XX(ha)) {
958 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
959 return -EINVAL;
962 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
964 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
966 if (rval) {
967 ql_log(ql_log_warn, vha, 0x7030,
968 "Vendor request 84xx reset failed.\n");
969 rval = (DID_ERROR << 16);
971 } else {
972 ql_dbg(ql_dbg_user, vha, 0x7031,
973 "Vendor request 84xx reset completed.\n");
974 bsg_reply->result = DID_OK;
975 bsg_job->job_done(bsg_job);
978 return rval;
981 static int
982 qla84xx_updatefw(struct fc_bsg_job *bsg_job)
984 struct fc_bsg_request *bsg_request = bsg_job->request;
985 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
986 struct Scsi_Host *host = bsg_job->shost;
987 scsi_qla_host_t *vha = shost_priv(host);
988 struct qla_hw_data *ha = vha->hw;
989 struct verify_chip_entry_84xx *mn = NULL;
990 dma_addr_t mn_dma, fw_dma;
991 void *fw_buf = NULL;
992 int rval = 0;
993 uint32_t sg_cnt;
994 uint32_t data_len;
995 uint16_t options;
996 uint32_t flag;
997 uint32_t fw_ver;
999 if (!IS_QLA84XX(ha)) {
1000 ql_dbg(ql_dbg_user, vha, 0x7032,
1001 "Not 84xx, exiting.\n");
1002 return -EINVAL;
1005 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1006 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1007 if (!sg_cnt) {
1008 ql_log(ql_log_warn, vha, 0x7033,
1009 "dma_map_sg returned %d for request.\n", sg_cnt);
1010 return -ENOMEM;
1013 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1014 ql_log(ql_log_warn, vha, 0x7034,
1015 "DMA mapping resulted in different sg counts, "
1016 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1017 bsg_job->request_payload.sg_cnt, sg_cnt);
1018 rval = -EAGAIN;
1019 goto done_unmap_sg;
1022 data_len = bsg_job->request_payload.payload_len;
1023 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1024 &fw_dma, GFP_KERNEL);
1025 if (!fw_buf) {
1026 ql_log(ql_log_warn, vha, 0x7035,
1027 "DMA alloc failed for fw_buf.\n");
1028 rval = -ENOMEM;
1029 goto done_unmap_sg;
1032 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1033 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1035 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1036 if (!mn) {
1037 ql_log(ql_log_warn, vha, 0x7036,
1038 "DMA alloc failed for fw buffer.\n");
1039 rval = -ENOMEM;
1040 goto done_free_fw_buf;
1043 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1044 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1046 memset(mn, 0, sizeof(struct access_chip_84xx));
1047 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1048 mn->entry_count = 1;
1050 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1051 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1052 options |= VCO_DIAG_FW;
1054 mn->options = cpu_to_le16(options);
1055 mn->fw_ver = cpu_to_le32(fw_ver);
1056 mn->fw_size = cpu_to_le32(data_len);
1057 mn->fw_seq_size = cpu_to_le32(data_len);
1058 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1059 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1060 mn->dseg_length = cpu_to_le32(data_len);
1061 mn->data_seg_cnt = cpu_to_le16(1);
1063 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1065 if (rval) {
1066 ql_log(ql_log_warn, vha, 0x7037,
1067 "Vendor request 84xx updatefw failed.\n");
1069 rval = (DID_ERROR << 16);
1070 } else {
1071 ql_dbg(ql_dbg_user, vha, 0x7038,
1072 "Vendor request 84xx updatefw completed.\n");
1074 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1075 bsg_reply->result = DID_OK;
1078 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1080 done_free_fw_buf:
1081 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1083 done_unmap_sg:
1084 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1085 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1087 if (!rval)
1088 bsg_job->job_done(bsg_job);
1089 return rval;
1092 static int
1093 qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1095 struct fc_bsg_request *bsg_request = bsg_job->request;
1096 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1097 struct Scsi_Host *host = bsg_job->shost;
1098 scsi_qla_host_t *vha = shost_priv(host);
1099 struct qla_hw_data *ha = vha->hw;
1100 struct access_chip_84xx *mn = NULL;
1101 dma_addr_t mn_dma, mgmt_dma;
1102 void *mgmt_b = NULL;
1103 int rval = 0;
1104 struct qla_bsg_a84_mgmt *ql84_mgmt;
1105 uint32_t sg_cnt;
1106 uint32_t data_len = 0;
1107 uint32_t dma_direction = DMA_NONE;
1109 if (!IS_QLA84XX(ha)) {
1110 ql_log(ql_log_warn, vha, 0x703a,
1111 "Not 84xx, exiting.\n");
1112 return -EINVAL;
1115 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1116 if (!mn) {
1117 ql_log(ql_log_warn, vha, 0x703c,
1118 "DMA alloc failed for fw buffer.\n");
1119 return -ENOMEM;
1122 memset(mn, 0, sizeof(struct access_chip_84xx));
1123 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1124 mn->entry_count = 1;
1125 ql84_mgmt = (void *)bsg_request + sizeof(struct fc_bsg_request);
1126 switch (ql84_mgmt->mgmt.cmd) {
1127 case QLA84_MGMT_READ_MEM:
1128 case QLA84_MGMT_GET_INFO:
1129 sg_cnt = dma_map_sg(&ha->pdev->dev,
1130 bsg_job->reply_payload.sg_list,
1131 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1132 if (!sg_cnt) {
1133 ql_log(ql_log_warn, vha, 0x703d,
1134 "dma_map_sg returned %d for reply.\n", sg_cnt);
1135 rval = -ENOMEM;
1136 goto exit_mgmt;
1139 dma_direction = DMA_FROM_DEVICE;
1141 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
1142 ql_log(ql_log_warn, vha, 0x703e,
1143 "DMA mapping resulted in different sg counts, "
1144 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1145 bsg_job->reply_payload.sg_cnt, sg_cnt);
1146 rval = -EAGAIN;
1147 goto done_unmap_sg;
1150 data_len = bsg_job->reply_payload.payload_len;
1152 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1153 &mgmt_dma, GFP_KERNEL);
1154 if (!mgmt_b) {
1155 ql_log(ql_log_warn, vha, 0x703f,
1156 "DMA alloc failed for mgmt_b.\n");
1157 rval = -ENOMEM;
1158 goto done_unmap_sg;
1161 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1162 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1163 mn->parameter1 =
1164 cpu_to_le32(
1165 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1167 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1168 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1169 mn->parameter1 =
1170 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1172 mn->parameter2 =
1173 cpu_to_le32(
1174 ql84_mgmt->mgmt.mgmtp.u.info.context);
1176 break;
1178 case QLA84_MGMT_WRITE_MEM:
1179 sg_cnt = dma_map_sg(&ha->pdev->dev,
1180 bsg_job->request_payload.sg_list,
1181 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1183 if (!sg_cnt) {
1184 ql_log(ql_log_warn, vha, 0x7040,
1185 "dma_map_sg returned %d.\n", sg_cnt);
1186 rval = -ENOMEM;
1187 goto exit_mgmt;
1190 dma_direction = DMA_TO_DEVICE;
1192 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1193 ql_log(ql_log_warn, vha, 0x7041,
1194 "DMA mapping resulted in different sg counts, "
1195 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1196 bsg_job->request_payload.sg_cnt, sg_cnt);
1197 rval = -EAGAIN;
1198 goto done_unmap_sg;
1201 data_len = bsg_job->request_payload.payload_len;
1202 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1203 &mgmt_dma, GFP_KERNEL);
1204 if (!mgmt_b) {
1205 ql_log(ql_log_warn, vha, 0x7042,
1206 "DMA alloc failed for mgmt_b.\n");
1207 rval = -ENOMEM;
1208 goto done_unmap_sg;
1211 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1212 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1214 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1215 mn->parameter1 =
1216 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1217 break;
1219 case QLA84_MGMT_CHNG_CONFIG:
1220 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1221 mn->parameter1 =
1222 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1224 mn->parameter2 =
1225 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1227 mn->parameter3 =
1228 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1229 break;
1231 default:
1232 rval = -EIO;
1233 goto exit_mgmt;
1236 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1237 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1238 mn->dseg_count = cpu_to_le16(1);
1239 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1240 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1241 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1244 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1246 if (rval) {
1247 ql_log(ql_log_warn, vha, 0x7043,
1248 "Vendor request 84xx mgmt failed.\n");
1250 rval = (DID_ERROR << 16);
1252 } else {
1253 ql_dbg(ql_dbg_user, vha, 0x7044,
1254 "Vendor request 84xx mgmt completed.\n");
1256 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1257 bsg_reply->result = DID_OK;
1259 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1260 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1261 bsg_reply->reply_payload_rcv_len =
1262 bsg_job->reply_payload.payload_len;
1264 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1265 bsg_job->reply_payload.sg_cnt, mgmt_b,
1266 data_len);
1270 done_unmap_sg:
1271 if (mgmt_b)
1272 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1274 if (dma_direction == DMA_TO_DEVICE)
1275 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1276 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1277 else if (dma_direction == DMA_FROM_DEVICE)
1278 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1279 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1281 exit_mgmt:
1282 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1284 if (!rval)
1285 bsg_job->job_done(bsg_job);
1286 return rval;
1289 static int
1290 qla24xx_iidma(struct fc_bsg_job *bsg_job)
1292 struct fc_bsg_request *bsg_request = bsg_job->request;
1293 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1294 struct Scsi_Host *host = bsg_job->shost;
1295 scsi_qla_host_t *vha = shost_priv(host);
1296 int rval = 0;
1297 struct qla_port_param *port_param = NULL;
1298 fc_port_t *fcport = NULL;
1299 int found = 0;
1300 uint16_t mb[MAILBOX_REGISTER_COUNT];
1301 uint8_t *rsp_ptr = NULL;
1303 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1304 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
1305 return -EINVAL;
1308 port_param = (void *)bsg_request + sizeof(struct fc_bsg_request);
1309 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1310 ql_log(ql_log_warn, vha, 0x7048,
1311 "Invalid destination type.\n");
1312 return -EINVAL;
1315 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1316 if (fcport->port_type != FCT_TARGET)
1317 continue;
1319 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1320 fcport->port_name, sizeof(fcport->port_name)))
1321 continue;
1323 found = 1;
1324 break;
1327 if (!found) {
1328 ql_log(ql_log_warn, vha, 0x7049,
1329 "Failed to find port.\n");
1330 return -EINVAL;
1333 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1334 ql_log(ql_log_warn, vha, 0x704a,
1335 "Port is not online.\n");
1336 return -EINVAL;
1339 if (fcport->flags & FCF_LOGIN_NEEDED) {
1340 ql_log(ql_log_warn, vha, 0x704b,
1341 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
1342 return -EINVAL;
1345 if (port_param->mode)
1346 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1347 port_param->speed, mb);
1348 else
1349 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1350 &port_param->speed, mb);
1352 if (rval) {
1353 ql_log(ql_log_warn, vha, 0x704c,
1354 "iIDMA cmd failed for %8phN -- "
1355 "%04x %x %04x %04x.\n", fcport->port_name,
1356 rval, fcport->fp_speed, mb[0], mb[1]);
1357 rval = (DID_ERROR << 16);
1358 } else {
1359 if (!port_param->mode) {
1360 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1361 sizeof(struct qla_port_param);
1363 rsp_ptr = ((uint8_t *)bsg_reply) +
1364 sizeof(struct fc_bsg_reply);
1366 memcpy(rsp_ptr, port_param,
1367 sizeof(struct qla_port_param));
1370 bsg_reply->result = DID_OK;
1371 bsg_job->job_done(bsg_job);
1374 return rval;
1377 static int
1378 qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
1379 uint8_t is_update)
1381 struct fc_bsg_request *bsg_request = bsg_job->request;
1382 uint32_t start = 0;
1383 int valid = 0;
1384 struct qla_hw_data *ha = vha->hw;
1386 if (unlikely(pci_channel_offline(ha->pdev)))
1387 return -EINVAL;
1389 start = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1390 if (start > ha->optrom_size) {
1391 ql_log(ql_log_warn, vha, 0x7055,
1392 "start %d > optrom_size %d.\n", start, ha->optrom_size);
1393 return -EINVAL;
1396 if (ha->optrom_state != QLA_SWAITING) {
1397 ql_log(ql_log_info, vha, 0x7056,
1398 "optrom_state %d.\n", ha->optrom_state);
1399 return -EBUSY;
1402 ha->optrom_region_start = start;
1403 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
1404 if (is_update) {
1405 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1406 valid = 1;
1407 else if (start == (ha->flt_region_boot * 4) ||
1408 start == (ha->flt_region_fw * 4))
1409 valid = 1;
1410 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1411 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha))
1412 valid = 1;
1413 if (!valid) {
1414 ql_log(ql_log_warn, vha, 0x7058,
1415 "Invalid start region 0x%x/0x%x.\n", start,
1416 bsg_job->request_payload.payload_len);
1417 return -EINVAL;
1420 ha->optrom_region_size = start +
1421 bsg_job->request_payload.payload_len > ha->optrom_size ?
1422 ha->optrom_size - start :
1423 bsg_job->request_payload.payload_len;
1424 ha->optrom_state = QLA_SWRITING;
1425 } else {
1426 ha->optrom_region_size = start +
1427 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1428 ha->optrom_size - start :
1429 bsg_job->reply_payload.payload_len;
1430 ha->optrom_state = QLA_SREADING;
1433 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1434 if (!ha->optrom_buffer) {
1435 ql_log(ql_log_warn, vha, 0x7059,
1436 "Read: Unable to allocate memory for optrom retrieval "
1437 "(%x)\n", ha->optrom_region_size);
1439 ha->optrom_state = QLA_SWAITING;
1440 return -ENOMEM;
1443 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1444 return 0;
1447 static int
1448 qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1450 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1451 struct Scsi_Host *host = bsg_job->shost;
1452 scsi_qla_host_t *vha = shost_priv(host);
1453 struct qla_hw_data *ha = vha->hw;
1454 int rval = 0;
1456 if (ha->flags.nic_core_reset_hdlr_active)
1457 return -EBUSY;
1459 mutex_lock(&ha->optrom_mutex);
1460 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1461 if (rval) {
1462 mutex_unlock(&ha->optrom_mutex);
1463 return rval;
1466 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1467 ha->optrom_region_start, ha->optrom_region_size);
1469 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1470 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1471 ha->optrom_region_size);
1473 bsg_reply->reply_payload_rcv_len = ha->optrom_region_size;
1474 bsg_reply->result = DID_OK;
1475 vfree(ha->optrom_buffer);
1476 ha->optrom_buffer = NULL;
1477 ha->optrom_state = QLA_SWAITING;
1478 mutex_unlock(&ha->optrom_mutex);
1479 bsg_job->job_done(bsg_job);
1480 return rval;
1483 static int
1484 qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1486 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1487 struct Scsi_Host *host = bsg_job->shost;
1488 scsi_qla_host_t *vha = shost_priv(host);
1489 struct qla_hw_data *ha = vha->hw;
1490 int rval = 0;
1492 mutex_lock(&ha->optrom_mutex);
1493 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
1494 if (rval) {
1495 mutex_unlock(&ha->optrom_mutex);
1496 return rval;
1499 /* Set the isp82xx_no_md_cap not to capture minidump */
1500 ha->flags.isp82xx_no_md_cap = 1;
1502 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1503 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1504 ha->optrom_region_size);
1506 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1507 ha->optrom_region_start, ha->optrom_region_size);
1509 bsg_reply->result = DID_OK;
1510 vfree(ha->optrom_buffer);
1511 ha->optrom_buffer = NULL;
1512 ha->optrom_state = QLA_SWAITING;
1513 mutex_unlock(&ha->optrom_mutex);
1514 bsg_job->job_done(bsg_job);
1515 return rval;
1518 static int
1519 qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1521 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1522 struct Scsi_Host *host = bsg_job->shost;
1523 scsi_qla_host_t *vha = shost_priv(host);
1524 struct qla_hw_data *ha = vha->hw;
1525 int rval = 0;
1526 uint8_t bsg[DMA_POOL_SIZE];
1527 struct qla_image_version_list *list = (void *)bsg;
1528 struct qla_image_version *image;
1529 uint32_t count;
1530 dma_addr_t sfp_dma;
1531 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1532 if (!sfp) {
1533 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1534 EXT_STATUS_NO_MEMORY;
1535 goto done;
1538 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1539 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1541 image = list->version;
1542 count = list->count;
1543 while (count--) {
1544 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1545 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1546 image->field_address.device, image->field_address.offset,
1547 sizeof(image->field_info), image->field_address.option);
1548 if (rval) {
1549 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1550 EXT_STATUS_MAILBOX;
1551 goto dealloc;
1553 image++;
1556 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1558 dealloc:
1559 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1561 done:
1562 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1563 bsg_reply->result = DID_OK << 16;
1564 bsg_job->job_done(bsg_job);
1566 return 0;
1569 static int
1570 qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1572 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1573 struct Scsi_Host *host = bsg_job->shost;
1574 scsi_qla_host_t *vha = shost_priv(host);
1575 struct qla_hw_data *ha = vha->hw;
1576 int rval = 0;
1577 uint8_t bsg[DMA_POOL_SIZE];
1578 struct qla_status_reg *sr = (void *)bsg;
1579 dma_addr_t sfp_dma;
1580 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1581 if (!sfp) {
1582 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1583 EXT_STATUS_NO_MEMORY;
1584 goto done;
1587 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1588 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1590 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1591 sr->field_address.device, sr->field_address.offset,
1592 sizeof(sr->status_reg), sr->field_address.option);
1593 sr->status_reg = *sfp;
1595 if (rval) {
1596 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1597 EXT_STATUS_MAILBOX;
1598 goto dealloc;
1601 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1602 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1604 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1606 dealloc:
1607 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1609 done:
1610 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1611 bsg_reply->reply_payload_rcv_len = sizeof(*sr);
1612 bsg_reply->result = DID_OK << 16;
1613 bsg_job->job_done(bsg_job);
1615 return 0;
1618 static int
1619 qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1621 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1622 struct Scsi_Host *host = bsg_job->shost;
1623 scsi_qla_host_t *vha = shost_priv(host);
1624 struct qla_hw_data *ha = vha->hw;
1625 int rval = 0;
1626 uint8_t bsg[DMA_POOL_SIZE];
1627 struct qla_status_reg *sr = (void *)bsg;
1628 dma_addr_t sfp_dma;
1629 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1630 if (!sfp) {
1631 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1632 EXT_STATUS_NO_MEMORY;
1633 goto done;
1636 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1637 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1639 *sfp = sr->status_reg;
1640 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1641 sr->field_address.device, sr->field_address.offset,
1642 sizeof(sr->status_reg), sr->field_address.option);
1644 if (rval) {
1645 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1646 EXT_STATUS_MAILBOX;
1647 goto dealloc;
1650 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1652 dealloc:
1653 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1655 done:
1656 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1657 bsg_reply->result = DID_OK << 16;
1658 bsg_job->job_done(bsg_job);
1660 return 0;
1663 static int
1664 qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
1666 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1667 struct Scsi_Host *host = bsg_job->shost;
1668 scsi_qla_host_t *vha = shost_priv(host);
1669 struct qla_hw_data *ha = vha->hw;
1670 int rval = 0;
1671 uint8_t bsg[DMA_POOL_SIZE];
1672 struct qla_i2c_access *i2c = (void *)bsg;
1673 dma_addr_t sfp_dma;
1674 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1675 if (!sfp) {
1676 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1677 EXT_STATUS_NO_MEMORY;
1678 goto done;
1681 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1682 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1684 memcpy(sfp, i2c->buffer, i2c->length);
1685 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1686 i2c->device, i2c->offset, i2c->length, i2c->option);
1688 if (rval) {
1689 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1690 EXT_STATUS_MAILBOX;
1691 goto dealloc;
1694 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1696 dealloc:
1697 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1699 done:
1700 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1701 bsg_reply->result = DID_OK << 16;
1702 bsg_job->job_done(bsg_job);
1704 return 0;
1707 static int
1708 qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1710 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1711 struct Scsi_Host *host = bsg_job->shost;
1712 scsi_qla_host_t *vha = shost_priv(host);
1713 struct qla_hw_data *ha = vha->hw;
1714 int rval = 0;
1715 uint8_t bsg[DMA_POOL_SIZE];
1716 struct qla_i2c_access *i2c = (void *)bsg;
1717 dma_addr_t sfp_dma;
1718 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1719 if (!sfp) {
1720 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1721 EXT_STATUS_NO_MEMORY;
1722 goto done;
1725 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1726 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1728 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1729 i2c->device, i2c->offset, i2c->length, i2c->option);
1731 if (rval) {
1732 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1733 EXT_STATUS_MAILBOX;
1734 goto dealloc;
1737 memcpy(i2c->buffer, sfp, i2c->length);
1738 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1739 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1741 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1743 dealloc:
1744 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1746 done:
1747 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1748 bsg_reply->reply_payload_rcv_len = sizeof(*i2c);
1749 bsg_reply->result = DID_OK << 16;
1750 bsg_job->job_done(bsg_job);
1752 return 0;
1755 static int
1756 qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1758 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1759 struct Scsi_Host *host = bsg_job->shost;
1760 scsi_qla_host_t *vha = shost_priv(host);
1761 struct qla_hw_data *ha = vha->hw;
1762 uint32_t rval = EXT_STATUS_OK;
1763 uint16_t req_sg_cnt = 0;
1764 uint16_t rsp_sg_cnt = 0;
1765 uint16_t nextlid = 0;
1766 uint32_t tot_dsds;
1767 srb_t *sp = NULL;
1768 uint32_t req_data_len = 0;
1769 uint32_t rsp_data_len = 0;
1771 /* Check the type of the adapter */
1772 if (!IS_BIDI_CAPABLE(ha)) {
1773 ql_log(ql_log_warn, vha, 0x70a0,
1774 "This adapter is not supported\n");
1775 rval = EXT_STATUS_NOT_SUPPORTED;
1776 goto done;
1779 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1780 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1781 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1782 rval = EXT_STATUS_BUSY;
1783 goto done;
1786 /* Check if host is online */
1787 if (!vha->flags.online) {
1788 ql_log(ql_log_warn, vha, 0x70a1,
1789 "Host is not online\n");
1790 rval = EXT_STATUS_DEVICE_OFFLINE;
1791 goto done;
1794 /* Check if cable is plugged in or not */
1795 if (vha->device_flags & DFLG_NO_CABLE) {
1796 ql_log(ql_log_warn, vha, 0x70a2,
1797 "Cable is unplugged...\n");
1798 rval = EXT_STATUS_INVALID_CFG;
1799 goto done;
1802 /* Check if the switch is connected or not */
1803 if (ha->current_topology != ISP_CFG_F) {
1804 ql_log(ql_log_warn, vha, 0x70a3,
1805 "Host is not connected to the switch\n");
1806 rval = EXT_STATUS_INVALID_CFG;
1807 goto done;
1810 /* Check if operating mode is P2P */
1811 if (ha->operating_mode != P2P) {
1812 ql_log(ql_log_warn, vha, 0x70a4,
1813 "Host is operating mode is not P2p\n");
1814 rval = EXT_STATUS_INVALID_CFG;
1815 goto done;
1818 mutex_lock(&ha->selflogin_lock);
1819 if (vha->self_login_loop_id == 0) {
1820 /* Initialize all required fields of fcport */
1821 vha->bidir_fcport.vha = vha;
1822 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1823 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1824 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1825 vha->bidir_fcport.loop_id = vha->loop_id;
1827 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1828 ql_log(ql_log_warn, vha, 0x70a7,
1829 "Failed to login port %06X for bidirectional IOCB\n",
1830 vha->bidir_fcport.d_id.b24);
1831 mutex_unlock(&ha->selflogin_lock);
1832 rval = EXT_STATUS_MAILBOX;
1833 goto done;
1835 vha->self_login_loop_id = nextlid - 1;
1838 /* Assign the self login loop id to fcport */
1839 mutex_unlock(&ha->selflogin_lock);
1841 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1843 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1844 bsg_job->request_payload.sg_list,
1845 bsg_job->request_payload.sg_cnt,
1846 DMA_TO_DEVICE);
1848 if (!req_sg_cnt) {
1849 rval = EXT_STATUS_NO_MEMORY;
1850 goto done;
1853 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1854 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1855 DMA_FROM_DEVICE);
1857 if (!rsp_sg_cnt) {
1858 rval = EXT_STATUS_NO_MEMORY;
1859 goto done_unmap_req_sg;
1862 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1863 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1864 ql_dbg(ql_dbg_user, vha, 0x70a9,
1865 "Dma mapping resulted in different sg counts "
1866 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1867 "%x dma_reply_sg_cnt: %x]\n",
1868 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1869 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1870 rval = EXT_STATUS_NO_MEMORY;
1871 goto done_unmap_sg;
1874 if (req_data_len != rsp_data_len) {
1875 rval = EXT_STATUS_BUSY;
1876 ql_log(ql_log_warn, vha, 0x70aa,
1877 "req_data_len != rsp_data_len\n");
1878 goto done_unmap_sg;
1881 req_data_len = bsg_job->request_payload.payload_len;
1882 rsp_data_len = bsg_job->reply_payload.payload_len;
1885 /* Alloc SRB structure */
1886 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1887 if (!sp) {
1888 ql_dbg(ql_dbg_user, vha, 0x70ac,
1889 "Alloc SRB structure failed\n");
1890 rval = EXT_STATUS_NO_MEMORY;
1891 goto done_unmap_sg;
1894 /*Populate srb->ctx with bidir ctx*/
1895 sp->u.bsg_job = bsg_job;
1896 sp->free = qla2x00_bsg_sp_free;
1897 sp->type = SRB_BIDI_CMD;
1898 sp->done = qla2x00_bsg_job_done;
1900 /* Add the read and write sg count */
1901 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1903 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1904 if (rval != EXT_STATUS_OK)
1905 goto done_free_srb;
1906 /* the bsg request will be completed in the interrupt handler */
1907 return rval;
1909 done_free_srb:
1910 mempool_free(sp, ha->srb_mempool);
1911 done_unmap_sg:
1912 dma_unmap_sg(&ha->pdev->dev,
1913 bsg_job->reply_payload.sg_list,
1914 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1915 done_unmap_req_sg:
1916 dma_unmap_sg(&ha->pdev->dev,
1917 bsg_job->request_payload.sg_list,
1918 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1919 done:
1921 /* Return an error vendor specific response
1922 * and complete the bsg request
1924 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1925 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1926 bsg_reply->reply_payload_rcv_len = 0;
1927 bsg_reply->result = (DID_OK) << 16;
1928 bsg_job->job_done(bsg_job);
1929 /* Always return success, vendor rsp carries correct status */
1930 return 0;
1933 static int
1934 qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
1936 struct fc_bsg_request *bsg_request = bsg_job->request;
1937 struct Scsi_Host *host = bsg_job->shost;
1938 scsi_qla_host_t *vha = shost_priv(host);
1939 struct qla_hw_data *ha = vha->hw;
1940 int rval = (DRIVER_ERROR << 16);
1941 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1942 srb_t *sp;
1943 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1944 struct fc_port *fcport;
1945 char *type = "FC_BSG_HST_FX_MGMT";
1947 /* Copy the IOCB specific information */
1948 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1949 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1951 /* Dump the vendor information */
1952 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1953 (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1955 if (!vha->flags.online) {
1956 ql_log(ql_log_warn, vha, 0x70d0,
1957 "Host is not online.\n");
1958 rval = -EIO;
1959 goto done;
1962 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1963 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1964 bsg_job->request_payload.sg_list,
1965 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1966 if (!req_sg_cnt) {
1967 ql_log(ql_log_warn, vha, 0x70c7,
1968 "dma_map_sg return %d for request\n", req_sg_cnt);
1969 rval = -ENOMEM;
1970 goto done;
1974 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1975 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1976 bsg_job->reply_payload.sg_list,
1977 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1978 if (!rsp_sg_cnt) {
1979 ql_log(ql_log_warn, vha, 0x70c8,
1980 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1981 rval = -ENOMEM;
1982 goto done_unmap_req_sg;
1986 ql_dbg(ql_dbg_user, vha, 0x70c9,
1987 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
1988 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
1989 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1991 /* Allocate a dummy fcport structure, since functions preparing the
1992 * IOCB and mailbox command retrieves port specific information
1993 * from fcport structure. For Host based ELS commands there will be
1994 * no fcport structure allocated
1996 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1997 if (!fcport) {
1998 ql_log(ql_log_warn, vha, 0x70ca,
1999 "Failed to allocate fcport.\n");
2000 rval = -ENOMEM;
2001 goto done_unmap_rsp_sg;
2004 /* Alloc SRB structure */
2005 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
2006 if (!sp) {
2007 ql_log(ql_log_warn, vha, 0x70cb,
2008 "qla2x00_get_sp failed.\n");
2009 rval = -ENOMEM;
2010 goto done_free_fcport;
2013 /* Initialize all required fields of fcport */
2014 fcport->vha = vha;
2015 fcport->loop_id = piocb_rqst->dataword;
2017 sp->type = SRB_FXIOCB_BCMD;
2018 sp->name = "bsg_fx_mgmt";
2019 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
2020 sp->u.bsg_job = bsg_job;
2021 sp->free = qla2x00_bsg_sp_free;
2022 sp->done = qla2x00_bsg_job_done;
2024 ql_dbg(ql_dbg_user, vha, 0x70cc,
2025 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2026 type, piocb_rqst->func_type, fcport->loop_id);
2028 rval = qla2x00_start_sp(sp);
2029 if (rval != QLA_SUCCESS) {
2030 ql_log(ql_log_warn, vha, 0x70cd,
2031 "qla2x00_start_sp failed=%d.\n", rval);
2032 mempool_free(sp, ha->srb_mempool);
2033 rval = -EIO;
2034 goto done_free_fcport;
2036 return rval;
2038 done_free_fcport:
2039 kfree(fcport);
2041 done_unmap_rsp_sg:
2042 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2043 dma_unmap_sg(&ha->pdev->dev,
2044 bsg_job->reply_payload.sg_list,
2045 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2046 done_unmap_req_sg:
2047 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2048 dma_unmap_sg(&ha->pdev->dev,
2049 bsg_job->request_payload.sg_list,
2050 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2052 done:
2053 return rval;
2056 static int
2057 qla26xx_serdes_op(struct fc_bsg_job *bsg_job)
2059 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2060 struct Scsi_Host *host = bsg_job->shost;
2061 scsi_qla_host_t *vha = shost_priv(host);
2062 int rval = 0;
2063 struct qla_serdes_reg sr;
2065 memset(&sr, 0, sizeof(sr));
2067 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2068 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2070 switch (sr.cmd) {
2071 case INT_SC_SERDES_WRITE_REG:
2072 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
2073 bsg_reply->reply_payload_rcv_len = 0;
2074 break;
2075 case INT_SC_SERDES_READ_REG:
2076 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2077 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2078 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2079 bsg_reply->reply_payload_rcv_len = sizeof(sr);
2080 break;
2081 default:
2082 ql_dbg(ql_dbg_user, vha, 0x708c,
2083 "Unknown serdes cmd %x.\n", sr.cmd);
2084 rval = -EINVAL;
2085 break;
2088 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2089 rval ? EXT_STATUS_MAILBOX : 0;
2091 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2092 bsg_reply->result = DID_OK << 16;
2093 bsg_job->job_done(bsg_job);
2094 return 0;
2097 static int
2098 qla8044_serdes_op(struct fc_bsg_job *bsg_job)
2100 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2101 struct Scsi_Host *host = bsg_job->shost;
2102 scsi_qla_host_t *vha = shost_priv(host);
2103 int rval = 0;
2104 struct qla_serdes_reg_ex sr;
2106 memset(&sr, 0, sizeof(sr));
2108 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2109 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2111 switch (sr.cmd) {
2112 case INT_SC_SERDES_WRITE_REG:
2113 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
2114 bsg_reply->reply_payload_rcv_len = 0;
2115 break;
2116 case INT_SC_SERDES_READ_REG:
2117 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2118 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2119 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2120 bsg_reply->reply_payload_rcv_len = sizeof(sr);
2121 break;
2122 default:
2123 ql_dbg(ql_dbg_user, vha, 0x70cf,
2124 "Unknown serdes cmd %x.\n", sr.cmd);
2125 rval = -EINVAL;
2126 break;
2129 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2130 rval ? EXT_STATUS_MAILBOX : 0;
2132 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2133 bsg_reply->result = DID_OK << 16;
2134 bsg_job->job_done(bsg_job);
2135 return 0;
2138 static int
2139 qla27xx_get_flash_upd_cap(struct fc_bsg_job *bsg_job)
2141 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2142 struct Scsi_Host *host = bsg_job->shost;
2143 scsi_qla_host_t *vha = shost_priv(host);
2144 struct qla_hw_data *ha = vha->hw;
2145 struct qla_flash_update_caps cap;
2147 if (!(IS_QLA27XX(ha)))
2148 return -EPERM;
2150 memset(&cap, 0, sizeof(cap));
2151 cap.capabilities = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2152 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2153 (uint64_t)ha->fw_attributes_h << 16 |
2154 (uint64_t)ha->fw_attributes;
2156 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2157 bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
2158 bsg_reply->reply_payload_rcv_len = sizeof(cap);
2160 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2161 EXT_STATUS_OK;
2163 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2164 bsg_reply->result = DID_OK << 16;
2165 bsg_job->job_done(bsg_job);
2166 return 0;
2169 static int
2170 qla27xx_set_flash_upd_cap(struct fc_bsg_job *bsg_job)
2172 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2173 struct Scsi_Host *host = bsg_job->shost;
2174 scsi_qla_host_t *vha = shost_priv(host);
2175 struct qla_hw_data *ha = vha->hw;
2176 uint64_t online_fw_attr = 0;
2177 struct qla_flash_update_caps cap;
2179 if (!(IS_QLA27XX(ha)))
2180 return -EPERM;
2182 memset(&cap, 0, sizeof(cap));
2183 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2184 bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
2186 online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2187 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2188 (uint64_t)ha->fw_attributes_h << 16 |
2189 (uint64_t)ha->fw_attributes;
2191 if (online_fw_attr != cap.capabilities) {
2192 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2193 EXT_STATUS_INVALID_PARAM;
2194 return -EINVAL;
2197 if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
2198 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2199 EXT_STATUS_INVALID_PARAM;
2200 return -EINVAL;
2203 bsg_reply->reply_payload_rcv_len = 0;
2205 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2206 EXT_STATUS_OK;
2208 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2209 bsg_reply->result = DID_OK << 16;
2210 bsg_job->job_done(bsg_job);
2211 return 0;
2214 static int
2215 qla27xx_get_bbcr_data(struct fc_bsg_job *bsg_job)
2217 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2218 struct Scsi_Host *host = bsg_job->shost;
2219 scsi_qla_host_t *vha = shost_priv(host);
2220 struct qla_hw_data *ha = vha->hw;
2221 struct qla_bbcr_data bbcr;
2222 uint16_t loop_id, topo, sw_cap;
2223 uint8_t domain, area, al_pa, state;
2224 int rval;
2226 if (!(IS_QLA27XX(ha)))
2227 return -EPERM;
2229 memset(&bbcr, 0, sizeof(bbcr));
2231 if (vha->flags.bbcr_enable)
2232 bbcr.status = QLA_BBCR_STATUS_ENABLED;
2233 else
2234 bbcr.status = QLA_BBCR_STATUS_DISABLED;
2236 if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
2237 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2238 &area, &domain, &topo, &sw_cap);
2239 if (rval != QLA_SUCCESS) {
2240 bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
2241 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2242 bbcr.mbx1 = loop_id;
2243 goto done;
2246 state = (vha->bbcr >> 12) & 0x1;
2248 if (state) {
2249 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2250 bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
2251 } else {
2252 bbcr.state = QLA_BBCR_STATE_ONLINE;
2253 bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
2256 bbcr.configured_bbscn = vha->bbcr & 0xf;
2259 done:
2260 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2261 bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
2262 bsg_reply->reply_payload_rcv_len = sizeof(bbcr);
2264 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2266 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2267 bsg_reply->result = DID_OK << 16;
2268 bsg_job->job_done(bsg_job);
2269 return 0;
2272 static int
2273 qla2x00_get_priv_stats(struct fc_bsg_job *bsg_job)
2275 struct fc_bsg_request *bsg_request = bsg_job->request;
2276 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2277 struct Scsi_Host *host = bsg_job->shost;
2278 scsi_qla_host_t *vha = shost_priv(host);
2279 struct qla_hw_data *ha = vha->hw;
2280 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2281 struct link_statistics *stats = NULL;
2282 dma_addr_t stats_dma;
2283 int rval;
2284 uint32_t *cmd = bsg_request->rqst_data.h_vendor.vendor_cmd;
2285 uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
2287 if (test_bit(UNLOADING, &vha->dpc_flags))
2288 return -ENODEV;
2290 if (unlikely(pci_channel_offline(ha->pdev)))
2291 return -ENODEV;
2293 if (qla2x00_reset_active(vha))
2294 return -EBUSY;
2296 if (!IS_FWI2_CAPABLE(ha))
2297 return -EPERM;
2299 stats = dma_alloc_coherent(&ha->pdev->dev,
2300 sizeof(*stats), &stats_dma, GFP_KERNEL);
2301 if (!stats) {
2302 ql_log(ql_log_warn, vha, 0x70e2,
2303 "Failed to allocate memory for stats.\n");
2304 return -ENOMEM;
2307 memset(stats, 0, sizeof(*stats));
2309 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
2311 if (rval == QLA_SUCCESS) {
2312 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e3,
2313 (uint8_t *)stats, sizeof(*stats));
2314 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2315 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
2318 bsg_reply->reply_payload_rcv_len = sizeof(*stats);
2319 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2320 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2322 bsg_job->reply_len = sizeof(*bsg_reply);
2323 bsg_reply->result = DID_OK << 16;
2324 bsg_job->job_done(bsg_job);
2326 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2327 stats, stats_dma);
2329 return 0;
2332 static int
2333 qla2x00_do_dport_diagnostics(struct fc_bsg_job *bsg_job)
2335 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2336 struct Scsi_Host *host = bsg_job->shost;
2337 scsi_qla_host_t *vha = shost_priv(host);
2338 int rval;
2339 struct qla_dport_diag *dd;
2341 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
2342 return -EPERM;
2344 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
2345 if (!dd) {
2346 ql_log(ql_log_warn, vha, 0x70db,
2347 "Failed to allocate memory for dport.\n");
2348 return -ENOMEM;
2351 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2352 bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
2354 rval = qla26xx_dport_diagnostics(
2355 vha, dd->buf, sizeof(dd->buf), dd->options);
2356 if (rval == QLA_SUCCESS) {
2357 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2358 bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
2361 bsg_reply->reply_payload_rcv_len = sizeof(*dd);
2362 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2363 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2365 bsg_job->reply_len = sizeof(*bsg_reply);
2366 bsg_reply->result = DID_OK << 16;
2367 bsg_job->job_done(bsg_job);
2369 kfree(dd);
2371 return 0;
2374 static int
2375 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2377 struct fc_bsg_request *bsg_request = bsg_job->request;
2379 switch (bsg_request->rqst_data.h_vendor.vendor_cmd[0]) {
2380 case QL_VND_LOOPBACK:
2381 return qla2x00_process_loopback(bsg_job);
2383 case QL_VND_A84_RESET:
2384 return qla84xx_reset(bsg_job);
2386 case QL_VND_A84_UPDATE_FW:
2387 return qla84xx_updatefw(bsg_job);
2389 case QL_VND_A84_MGMT_CMD:
2390 return qla84xx_mgmt_cmd(bsg_job);
2392 case QL_VND_IIDMA:
2393 return qla24xx_iidma(bsg_job);
2395 case QL_VND_FCP_PRIO_CFG_CMD:
2396 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2398 case QL_VND_READ_FLASH:
2399 return qla2x00_read_optrom(bsg_job);
2401 case QL_VND_UPDATE_FLASH:
2402 return qla2x00_update_optrom(bsg_job);
2404 case QL_VND_SET_FRU_VERSION:
2405 return qla2x00_update_fru_versions(bsg_job);
2407 case QL_VND_READ_FRU_STATUS:
2408 return qla2x00_read_fru_status(bsg_job);
2410 case QL_VND_WRITE_FRU_STATUS:
2411 return qla2x00_write_fru_status(bsg_job);
2413 case QL_VND_WRITE_I2C:
2414 return qla2x00_write_i2c(bsg_job);
2416 case QL_VND_READ_I2C:
2417 return qla2x00_read_i2c(bsg_job);
2419 case QL_VND_DIAG_IO_CMD:
2420 return qla24xx_process_bidir_cmd(bsg_job);
2422 case QL_VND_FX00_MGMT_CMD:
2423 return qlafx00_mgmt_cmd(bsg_job);
2425 case QL_VND_SERDES_OP:
2426 return qla26xx_serdes_op(bsg_job);
2428 case QL_VND_SERDES_OP_EX:
2429 return qla8044_serdes_op(bsg_job);
2431 case QL_VND_GET_FLASH_UPDATE_CAPS:
2432 return qla27xx_get_flash_upd_cap(bsg_job);
2434 case QL_VND_SET_FLASH_UPDATE_CAPS:
2435 return qla27xx_set_flash_upd_cap(bsg_job);
2437 case QL_VND_GET_BBCR_DATA:
2438 return qla27xx_get_bbcr_data(bsg_job);
2440 case QL_VND_GET_PRIV_STATS:
2441 case QL_VND_GET_PRIV_STATS_EX:
2442 return qla2x00_get_priv_stats(bsg_job);
2444 case QL_VND_DPORT_DIAGNOSTICS:
2445 return qla2x00_do_dport_diagnostics(bsg_job);
2447 default:
2448 return -ENOSYS;
2453 qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2455 struct fc_bsg_request *bsg_request = bsg_job->request;
2456 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2457 int ret = -EINVAL;
2458 struct fc_rport *rport;
2459 struct Scsi_Host *host;
2460 scsi_qla_host_t *vha;
2462 /* In case no data transferred. */
2463 bsg_reply->reply_payload_rcv_len = 0;
2465 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
2466 rport = bsg_job->rport;
2467 host = rport_to_shost(rport);
2468 vha = shost_priv(host);
2469 } else {
2470 host = bsg_job->shost;
2471 vha = shost_priv(host);
2474 if (qla2x00_reset_active(vha)) {
2475 ql_dbg(ql_dbg_user, vha, 0x709f,
2476 "BSG: ISP abort active/needed -- cmd=%d.\n",
2477 bsg_request->msgcode);
2478 return -EBUSY;
2481 ql_dbg(ql_dbg_user, vha, 0x7000,
2482 "Entered %s msgcode=0x%x.\n", __func__, bsg_request->msgcode);
2484 switch (bsg_request->msgcode) {
2485 case FC_BSG_RPT_ELS:
2486 case FC_BSG_HST_ELS_NOLOGIN:
2487 ret = qla2x00_process_els(bsg_job);
2488 break;
2489 case FC_BSG_HST_CT:
2490 ret = qla2x00_process_ct(bsg_job);
2491 break;
2492 case FC_BSG_HST_VENDOR:
2493 ret = qla2x00_process_vendor_specific(bsg_job);
2494 break;
2495 case FC_BSG_HST_ADD_RPORT:
2496 case FC_BSG_HST_DEL_RPORT:
2497 case FC_BSG_RPT_CT:
2498 default:
2499 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
2500 break;
2502 return ret;
2506 qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2508 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2509 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2510 struct qla_hw_data *ha = vha->hw;
2511 srb_t *sp;
2512 int cnt, que;
2513 unsigned long flags;
2514 struct req_que *req;
2516 /* find the bsg job from the active list of commands */
2517 spin_lock_irqsave(&ha->hardware_lock, flags);
2518 for (que = 0; que < ha->max_req_queues; que++) {
2519 req = ha->req_q_map[que];
2520 if (!req)
2521 continue;
2523 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
2524 sp = req->outstanding_cmds[cnt];
2525 if (sp) {
2526 if (((sp->type == SRB_CT_CMD) ||
2527 (sp->type == SRB_ELS_CMD_HST) ||
2528 (sp->type == SRB_FXIOCB_BCMD))
2529 && (sp->u.bsg_job == bsg_job)) {
2530 req->outstanding_cmds[cnt] = NULL;
2531 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2532 if (ha->isp_ops->abort_command(sp)) {
2533 ql_log(ql_log_warn, vha, 0x7089,
2534 "mbx abort_command "
2535 "failed.\n");
2536 bsg_job->req->errors =
2537 bsg_reply->result = -EIO;
2538 } else {
2539 ql_dbg(ql_dbg_user, vha, 0x708a,
2540 "mbx abort_command "
2541 "success.\n");
2542 bsg_job->req->errors =
2543 bsg_reply->result = 0;
2545 spin_lock_irqsave(&ha->hardware_lock, flags);
2546 goto done;
2551 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2552 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
2553 bsg_job->req->errors = bsg_reply->result = -ENXIO;
2554 return 0;
2556 done:
2557 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2558 sp->free(vha, sp);
2559 return 0;