1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
8 #include <linux/kthread.h>
9 #include <linux/vmalloc.h>
10 #include <linux/delay.h>
11 #include <linux/bsg-lib.h>
13 static void qla2xxx_free_fcport_work(struct work_struct *work)
15 struct fc_port *fcport = container_of(work, typeof(*fcport),
18 qla2x00_free_fcport(fcport);
21 /* BSG support for ELS/CT pass through */
22 void qla2x00_bsg_job_done(srb_t *sp, int res)
24 struct bsg_job *bsg_job = sp->u.bsg_job;
25 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
29 bsg_reply->result = res;
30 bsg_job_done(bsg_job, bsg_reply->result,
31 bsg_reply->reply_payload_rcv_len);
34 void qla2x00_bsg_sp_free(srb_t *sp)
36 struct qla_hw_data *ha = sp->vha->hw;
37 struct bsg_job *bsg_job = sp->u.bsg_job;
38 struct fc_bsg_request *bsg_request = bsg_job->request;
39 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
41 if (sp->type == SRB_FXIOCB_BCMD) {
42 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
43 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
45 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
46 dma_unmap_sg(&ha->pdev->dev,
47 bsg_job->request_payload.sg_list,
48 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
50 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
51 dma_unmap_sg(&ha->pdev->dev,
52 bsg_job->reply_payload.sg_list,
53 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
55 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
56 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
58 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
59 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
62 if (sp->type == SRB_CT_CMD ||
63 sp->type == SRB_FXIOCB_BCMD ||
64 sp->type == SRB_ELS_CMD_HST) {
65 INIT_WORK(&sp->fcport->free_work, qla2xxx_free_fcport_work);
66 queue_work(ha->wq, &sp->fcport->free_work);
73 qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
74 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
76 int i, ret, num_valid;
78 struct qla_fcp_prio_entry *pri_entry;
79 uint32_t *bcode_val_ptr, bcode_val;
83 bcode = (uint8_t *)pri_cfg;
84 bcode_val_ptr = (uint32_t *)pri_cfg;
85 bcode_val = (uint32_t)(*bcode_val_ptr);
87 if (bcode_val == 0xFFFFFFFF) {
88 /* No FCP Priority config data in flash */
89 ql_dbg(ql_dbg_user, vha, 0x7051,
90 "No FCP Priority config data.\n");
94 if (memcmp(bcode, "HQOS", 4)) {
95 /* Invalid FCP priority data header*/
96 ql_dbg(ql_dbg_user, vha, 0x7052,
97 "Invalid FCP Priority data header. bcode=0x%x.\n",
104 pri_entry = &pri_cfg->entry[0];
105 for (i = 0; i < pri_cfg->num_entries; i++) {
106 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
111 if (num_valid == 0) {
112 /* No valid FCP priority data entries */
113 ql_dbg(ql_dbg_user, vha, 0x7053,
114 "No valid FCP Priority data entries.\n");
117 /* FCP priority data is valid */
118 ql_dbg(ql_dbg_user, vha, 0x7054,
119 "Valid FCP priority data. num entries = %d.\n",
127 qla24xx_proc_fcp_prio_cfg_cmd(struct bsg_job *bsg_job)
129 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
130 struct fc_bsg_request *bsg_request = bsg_job->request;
131 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
132 scsi_qla_host_t *vha = shost_priv(host);
133 struct qla_hw_data *ha = vha->hw;
138 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
140 goto exit_fcp_prio_cfg;
143 /* Get the sub command */
144 oper = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
146 /* Only set config is allowed if config memory is not allocated */
147 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
149 goto exit_fcp_prio_cfg;
152 case QLFC_FCP_PRIO_DISABLE:
153 if (ha->flags.fcp_prio_enabled) {
154 ha->flags.fcp_prio_enabled = 0;
155 ha->fcp_prio_cfg->attributes &=
156 ~FCP_PRIO_ATTR_ENABLE;
157 qla24xx_update_all_fcp_prio(vha);
158 bsg_reply->result = DID_OK;
161 bsg_reply->result = (DID_ERROR << 16);
162 goto exit_fcp_prio_cfg;
166 case QLFC_FCP_PRIO_ENABLE:
167 if (!ha->flags.fcp_prio_enabled) {
168 if (ha->fcp_prio_cfg) {
169 ha->flags.fcp_prio_enabled = 1;
170 ha->fcp_prio_cfg->attributes |=
171 FCP_PRIO_ATTR_ENABLE;
172 qla24xx_update_all_fcp_prio(vha);
173 bsg_reply->result = DID_OK;
176 bsg_reply->result = (DID_ERROR << 16);
177 goto exit_fcp_prio_cfg;
182 case QLFC_FCP_PRIO_GET_CONFIG:
183 len = bsg_job->reply_payload.payload_len;
184 if (!len || len > FCP_PRIO_CFG_SIZE) {
186 bsg_reply->result = (DID_ERROR << 16);
187 goto exit_fcp_prio_cfg;
190 bsg_reply->result = DID_OK;
191 bsg_reply->reply_payload_rcv_len =
193 bsg_job->reply_payload.sg_list,
194 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
199 case QLFC_FCP_PRIO_SET_CONFIG:
200 len = bsg_job->request_payload.payload_len;
201 if (!len || len > FCP_PRIO_CFG_SIZE) {
202 bsg_reply->result = (DID_ERROR << 16);
204 goto exit_fcp_prio_cfg;
207 if (!ha->fcp_prio_cfg) {
208 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
209 if (!ha->fcp_prio_cfg) {
210 ql_log(ql_log_warn, vha, 0x7050,
211 "Unable to allocate memory for fcp prio "
212 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
213 bsg_reply->result = (DID_ERROR << 16);
215 goto exit_fcp_prio_cfg;
219 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
220 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
221 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
224 /* validate fcp priority data */
226 if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 1)) {
227 bsg_reply->result = (DID_ERROR << 16);
229 /* If buffer was invalidatic int
230 * fcp_prio_cfg is of no use
232 vfree(ha->fcp_prio_cfg);
233 ha->fcp_prio_cfg = NULL;
234 goto exit_fcp_prio_cfg;
237 ha->flags.fcp_prio_enabled = 0;
238 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
239 ha->flags.fcp_prio_enabled = 1;
240 qla24xx_update_all_fcp_prio(vha);
241 bsg_reply->result = DID_OK;
249 bsg_job_done(bsg_job, bsg_reply->result,
250 bsg_reply->reply_payload_rcv_len);
255 qla2x00_process_els(struct bsg_job *bsg_job)
257 struct fc_bsg_request *bsg_request = bsg_job->request;
258 struct fc_rport *rport;
259 fc_port_t *fcport = NULL;
260 struct Scsi_Host *host;
261 scsi_qla_host_t *vha;
262 struct qla_hw_data *ha;
265 int req_sg_cnt, rsp_sg_cnt;
266 int rval = (DID_ERROR << 16);
267 uint16_t nextlid = 0;
269 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
270 rport = fc_bsg_to_rport(bsg_job);
275 fcport = *(fc_port_t **) rport->dd_data;
276 host = rport_to_shost(rport);
277 vha = shost_priv(host);
279 type = "FC_BSG_RPT_ELS";
281 host = fc_bsg_to_shost(bsg_job);
282 vha = shost_priv(host);
284 type = "FC_BSG_HST_ELS_NOLOGIN";
287 if (!vha->flags.online) {
288 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
293 /* pass through is supported only for ISP 4Gb or higher */
294 if (!IS_FWI2_CAPABLE(ha)) {
295 ql_dbg(ql_dbg_user, vha, 0x7001,
296 "ELS passthru not supported for ISP23xx based adapters.\n");
301 /* Multiple SG's are not supported for ELS requests */
302 if (bsg_job->request_payload.sg_cnt > 1 ||
303 bsg_job->reply_payload.sg_cnt > 1) {
304 ql_dbg(ql_dbg_user, vha, 0x7002,
305 "Multiple SG's are not supported for ELS requests, "
306 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
307 bsg_job->request_payload.sg_cnt,
308 bsg_job->reply_payload.sg_cnt);
313 /* ELS request for rport */
314 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
315 /* make sure the rport is logged in,
316 * if not perform fabric login
318 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
319 ql_dbg(ql_dbg_user, vha, 0x7003,
320 "Failed to login port %06X for ELS passthru.\n",
326 /* Allocate a dummy fcport structure, since functions
327 * preparing the IOCB and mailbox command retrieves port
328 * specific information from fcport structure. For Host based
329 * ELS commands there will be no fcport structure allocated
331 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
337 /* Initialize all required fields of fcport */
339 fcport->d_id.b.al_pa =
340 bsg_request->rqst_data.h_els.port_id[0];
341 fcport->d_id.b.area =
342 bsg_request->rqst_data.h_els.port_id[1];
343 fcport->d_id.b.domain =
344 bsg_request->rqst_data.h_els.port_id[2];
346 (fcport->d_id.b.al_pa == 0xFD) ?
347 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
351 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
352 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
354 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
355 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
357 goto done_free_fcport;
360 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
361 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
363 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
364 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
366 goto done_free_fcport;
369 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
370 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
371 ql_log(ql_log_warn, vha, 0x7008,
372 "dma mapping resulted in different sg counts, "
373 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
374 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
375 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
380 /* Alloc SRB structure */
381 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
388 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
389 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
391 (bsg_request->msgcode == FC_BSG_RPT_ELS ?
392 "bsg_els_rpt" : "bsg_els_hst");
393 sp->u.bsg_job = bsg_job;
394 sp->free = qla2x00_bsg_sp_free;
395 sp->done = qla2x00_bsg_job_done;
397 ql_dbg(ql_dbg_user, vha, 0x700a,
398 "bsg rqst type: %s els type: %x - loop-id=%x "
399 "portid=%-2x%02x%02x.\n", type,
400 bsg_request->rqst_data.h_els.command_code, fcport->loop_id,
401 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
403 rval = qla2x00_start_sp(sp);
404 if (rval != QLA_SUCCESS) {
405 ql_log(ql_log_warn, vha, 0x700e,
406 "qla2x00_start_sp failed = %d\n", rval);
414 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
415 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
416 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
417 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
418 goto done_free_fcport;
421 if (bsg_request->msgcode != FC_BSG_RPT_ELS)
422 qla2x00_free_fcport(fcport);
427 static inline uint16_t
428 qla24xx_calc_ct_iocbs(uint16_t dsds)
434 iocbs += (dsds - 2) / 5;
442 qla2x00_process_ct(struct bsg_job *bsg_job)
445 struct fc_bsg_request *bsg_request = bsg_job->request;
446 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
447 scsi_qla_host_t *vha = shost_priv(host);
448 struct qla_hw_data *ha = vha->hw;
449 int rval = (DID_ERROR << 16);
450 int req_sg_cnt, rsp_sg_cnt;
452 struct fc_port *fcport;
453 char *type = "FC_BSG_HST_CT";
456 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
457 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
459 ql_log(ql_log_warn, vha, 0x700f,
460 "dma_map_sg return %d for request\n", req_sg_cnt);
465 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
466 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
468 ql_log(ql_log_warn, vha, 0x7010,
469 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
474 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
475 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
476 ql_log(ql_log_warn, vha, 0x7011,
477 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
478 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
479 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
484 if (!vha->flags.online) {
485 ql_log(ql_log_warn, vha, 0x7012,
486 "Host is not online.\n");
492 (bsg_request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
499 loop_id = vha->mgmt_svr_loop_id;
502 ql_dbg(ql_dbg_user, vha, 0x7013,
503 "Unknown loop id: %x.\n", loop_id);
508 /* Allocate a dummy fcport structure, since functions preparing the
509 * IOCB and mailbox command retrieves port specific information
510 * from fcport structure. For Host based ELS commands there will be
511 * no fcport structure allocated
513 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
515 ql_log(ql_log_warn, vha, 0x7014,
516 "Failed to allocate fcport.\n");
521 /* Initialize all required fields of fcport */
523 fcport->d_id.b.al_pa = bsg_request->rqst_data.h_ct.port_id[0];
524 fcport->d_id.b.area = bsg_request->rqst_data.h_ct.port_id[1];
525 fcport->d_id.b.domain = bsg_request->rqst_data.h_ct.port_id[2];
526 fcport->loop_id = loop_id;
528 /* Alloc SRB structure */
529 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
531 ql_log(ql_log_warn, vha, 0x7015,
532 "qla2x00_get_sp failed.\n");
534 goto done_free_fcport;
537 sp->type = SRB_CT_CMD;
539 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
540 sp->u.bsg_job = bsg_job;
541 sp->free = qla2x00_bsg_sp_free;
542 sp->done = qla2x00_bsg_job_done;
544 ql_dbg(ql_dbg_user, vha, 0x7016,
545 "bsg rqst type: %s else type: %x - "
546 "loop-id=%x portid=%02x%02x%02x.\n", type,
547 (bsg_request->rqst_data.h_ct.preamble_word2 >> 16),
548 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
549 fcport->d_id.b.al_pa);
551 rval = qla2x00_start_sp(sp);
552 if (rval != QLA_SUCCESS) {
553 ql_log(ql_log_warn, vha, 0x7017,
554 "qla2x00_start_sp failed=%d.\n", rval);
557 goto done_free_fcport;
562 qla2x00_free_fcport(fcport);
564 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
565 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
566 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
567 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
572 /* Disable loopback mode */
574 qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
579 uint16_t new_config[4];
580 struct qla_hw_data *ha = vha->hw;
582 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
583 goto done_reset_internal;
585 memset(new_config, 0 , sizeof(new_config));
586 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
587 ENABLE_INTERNAL_LOOPBACK ||
588 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
589 ENABLE_EXTERNAL_LOOPBACK) {
590 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
591 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
592 (new_config[0] & INTERNAL_LOOPBACK_MASK));
593 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
595 ha->notify_dcbx_comp = wait;
596 ha->notify_lb_portup_comp = wait2;
598 ret = qla81xx_set_port_config(vha, new_config);
599 if (ret != QLA_SUCCESS) {
600 ql_log(ql_log_warn, vha, 0x7025,
601 "Set port config failed.\n");
602 ha->notify_dcbx_comp = 0;
603 ha->notify_lb_portup_comp = 0;
605 goto done_reset_internal;
608 /* Wait for DCBX complete event */
609 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
610 (DCBX_COMP_TIMEOUT * HZ))) {
611 ql_dbg(ql_dbg_user, vha, 0x7026,
612 "DCBX completion not received.\n");
613 ha->notify_dcbx_comp = 0;
614 ha->notify_lb_portup_comp = 0;
616 goto done_reset_internal;
618 ql_dbg(ql_dbg_user, vha, 0x7027,
619 "DCBX completion received.\n");
622 !wait_for_completion_timeout(&ha->lb_portup_comp,
623 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
624 ql_dbg(ql_dbg_user, vha, 0x70c5,
625 "Port up completion not received.\n");
626 ha->notify_lb_portup_comp = 0;
628 goto done_reset_internal;
630 ql_dbg(ql_dbg_user, vha, 0x70c6,
631 "Port up completion received.\n");
633 ha->notify_dcbx_comp = 0;
634 ha->notify_lb_portup_comp = 0;
641 * Set the port configuration to enable the internal or external loopback
642 * depending on the loopback mode.
645 qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
646 uint16_t *new_config, uint16_t mode)
650 unsigned long rem_tmo = 0, current_tmo = 0;
651 struct qla_hw_data *ha = vha->hw;
653 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
654 goto done_set_internal;
656 if (mode == INTERNAL_LOOPBACK)
657 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
658 else if (mode == EXTERNAL_LOOPBACK)
659 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
660 ql_dbg(ql_dbg_user, vha, 0x70be,
661 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
663 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
665 ha->notify_dcbx_comp = 1;
666 ret = qla81xx_set_port_config(vha, new_config);
667 if (ret != QLA_SUCCESS) {
668 ql_log(ql_log_warn, vha, 0x7021,
669 "set port config failed.\n");
670 ha->notify_dcbx_comp = 0;
672 goto done_set_internal;
675 /* Wait for DCBX complete event */
676 current_tmo = DCBX_COMP_TIMEOUT * HZ;
678 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
680 if (!ha->idc_extend_tmo || rem_tmo) {
681 ha->idc_extend_tmo = 0;
684 current_tmo = ha->idc_extend_tmo * HZ;
685 ha->idc_extend_tmo = 0;
689 ql_dbg(ql_dbg_user, vha, 0x7022,
690 "DCBX completion not received.\n");
691 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
693 * If the reset of the loopback mode doesn't work take a FCoE
694 * dump and reset the chip.
697 qla2xxx_dump_fw(vha);
698 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
702 if (ha->flags.idc_compl_status) {
703 ql_dbg(ql_dbg_user, vha, 0x70c3,
704 "Bad status in IDC Completion AEN\n");
706 ha->flags.idc_compl_status = 0;
708 ql_dbg(ql_dbg_user, vha, 0x7023,
709 "DCBX completion received.\n");
712 ha->notify_dcbx_comp = 0;
713 ha->idc_extend_tmo = 0;
720 qla2x00_process_loopback(struct bsg_job *bsg_job)
722 struct fc_bsg_request *bsg_request = bsg_job->request;
723 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
724 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
725 scsi_qla_host_t *vha = shost_priv(host);
726 struct qla_hw_data *ha = vha->hw;
728 uint8_t command_sent;
730 struct msg_echo_lb elreq;
731 uint16_t response[MAILBOX_REGISTER_COUNT];
732 uint16_t config[4], new_config[4];
734 void *req_data = NULL;
735 dma_addr_t req_data_dma;
736 uint32_t req_data_len;
737 uint8_t *rsp_data = NULL;
738 dma_addr_t rsp_data_dma;
739 uint32_t rsp_data_len;
741 if (!vha->flags.online) {
742 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
746 memset(&elreq, 0, sizeof(elreq));
748 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
749 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
752 if (!elreq.req_sg_cnt) {
753 ql_log(ql_log_warn, vha, 0x701a,
754 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
758 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
759 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
762 if (!elreq.rsp_sg_cnt) {
763 ql_log(ql_log_warn, vha, 0x701b,
764 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
766 goto done_unmap_req_sg;
769 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
770 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
771 ql_log(ql_log_warn, vha, 0x701c,
772 "dma mapping resulted in different sg counts, "
773 "request_sg_cnt: %x dma_request_sg_cnt: %x "
774 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
775 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
776 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
780 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
781 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
782 &req_data_dma, GFP_KERNEL);
784 ql_log(ql_log_warn, vha, 0x701d,
785 "dma alloc failed for req_data.\n");
790 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
791 &rsp_data_dma, GFP_KERNEL);
793 ql_log(ql_log_warn, vha, 0x7004,
794 "dma alloc failed for rsp_data.\n");
796 goto done_free_dma_req;
799 /* Copy the request buffer in req_data now */
800 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
801 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
803 elreq.send_dma = req_data_dma;
804 elreq.rcv_dma = rsp_data_dma;
805 elreq.transfer_size = req_data_len;
807 elreq.options = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
808 elreq.iteration_count =
809 bsg_request->rqst_data.h_vendor.vendor_cmd[2];
811 if (atomic_read(&vha->loop_state) == LOOP_READY &&
812 ((ha->current_topology == ISP_CFG_F && (elreq.options & 7) >= 2) ||
813 ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
814 get_unaligned_le32(req_data) == ELS_OPCODE_BYTE &&
815 req_data_len == MAX_ELS_FRAME_PAYLOAD &&
816 elreq.options == EXTERNAL_LOOPBACK))) {
817 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
818 ql_dbg(ql_dbg_user, vha, 0x701e,
819 "BSG request type: %s.\n", type);
820 command_sent = INT_DEF_LB_ECHO_CMD;
821 rval = qla2x00_echo_test(vha, &elreq, response);
823 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
824 memset(config, 0, sizeof(config));
825 memset(new_config, 0, sizeof(new_config));
827 if (qla81xx_get_port_config(vha, config)) {
828 ql_log(ql_log_warn, vha, 0x701f,
829 "Get port config failed.\n");
831 goto done_free_dma_rsp;
834 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
835 ql_dbg(ql_dbg_user, vha, 0x70c4,
836 "Loopback operation already in "
839 goto done_free_dma_rsp;
842 ql_dbg(ql_dbg_user, vha, 0x70c0,
843 "elreq.options=%04x\n", elreq.options);
845 if (elreq.options == EXTERNAL_LOOPBACK)
846 if (IS_QLA8031(ha) || IS_QLA8044(ha))
847 rval = qla81xx_set_loopback_mode(vha,
848 config, new_config, elreq.options);
850 rval = qla81xx_reset_loopback_mode(vha,
853 rval = qla81xx_set_loopback_mode(vha, config,
854 new_config, elreq.options);
858 goto done_free_dma_rsp;
861 type = "FC_BSG_HST_VENDOR_LOOPBACK";
862 ql_dbg(ql_dbg_user, vha, 0x7028,
863 "BSG request type: %s.\n", type);
865 command_sent = INT_DEF_LB_LOOPBACK_CMD;
866 rval = qla2x00_loopback_test(vha, &elreq, response);
868 if (response[0] == MBS_COMMAND_ERROR &&
869 response[1] == MBS_LB_RESET) {
870 ql_log(ql_log_warn, vha, 0x7029,
871 "MBX command error, Aborting ISP.\n");
872 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
873 qla2xxx_wake_dpc(vha);
874 qla2x00_wait_for_chip_reset(vha);
875 /* Also reset the MPI */
876 if (IS_QLA81XX(ha)) {
877 if (qla81xx_restart_mpi_firmware(vha) !=
879 ql_log(ql_log_warn, vha, 0x702a,
880 "MPI reset failed.\n");
885 goto done_free_dma_rsp;
891 /* Revert back to original port config
892 * Also clear internal loopback
894 ret = qla81xx_reset_loopback_mode(vha,
898 * If the reset of the loopback mode
899 * doesn't work take FCoE dump and then
902 qla2xxx_dump_fw(vha);
903 set_bit(ISP_ABORT_NEEDED,
910 type = "FC_BSG_HST_VENDOR_LOOPBACK";
911 ql_dbg(ql_dbg_user, vha, 0x702b,
912 "BSG request type: %s.\n", type);
913 command_sent = INT_DEF_LB_LOOPBACK_CMD;
914 rval = qla2x00_loopback_test(vha, &elreq, response);
919 ql_log(ql_log_warn, vha, 0x702c,
920 "Vendor request %s failed.\n", type);
923 bsg_reply->result = (DID_ERROR << 16);
924 bsg_reply->reply_payload_rcv_len = 0;
926 ql_dbg(ql_dbg_user, vha, 0x702d,
927 "Vendor request %s completed.\n", type);
928 bsg_reply->result = (DID_OK << 16);
929 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
930 bsg_job->reply_payload.sg_cnt, rsp_data,
934 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
935 sizeof(response) + sizeof(uint8_t);
936 fw_sts_ptr = bsg_job->reply + sizeof(struct fc_bsg_reply);
937 memcpy(bsg_job->reply + sizeof(struct fc_bsg_reply), response,
939 fw_sts_ptr += sizeof(response);
940 *fw_sts_ptr = command_sent;
943 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
944 rsp_data, rsp_data_dma);
946 dma_free_coherent(&ha->pdev->dev, req_data_len,
947 req_data, req_data_dma);
949 dma_unmap_sg(&ha->pdev->dev,
950 bsg_job->reply_payload.sg_list,
951 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
953 dma_unmap_sg(&ha->pdev->dev,
954 bsg_job->request_payload.sg_list,
955 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
957 bsg_job_done(bsg_job, bsg_reply->result,
958 bsg_reply->reply_payload_rcv_len);
963 qla84xx_reset(struct bsg_job *bsg_job)
965 struct fc_bsg_request *bsg_request = bsg_job->request;
966 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
967 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
968 scsi_qla_host_t *vha = shost_priv(host);
969 struct qla_hw_data *ha = vha->hw;
973 if (!IS_QLA84XX(ha)) {
974 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
978 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
980 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
983 ql_log(ql_log_warn, vha, 0x7030,
984 "Vendor request 84xx reset failed.\n");
985 rval = (DID_ERROR << 16);
988 ql_dbg(ql_dbg_user, vha, 0x7031,
989 "Vendor request 84xx reset completed.\n");
990 bsg_reply->result = DID_OK;
991 bsg_job_done(bsg_job, bsg_reply->result,
992 bsg_reply->reply_payload_rcv_len);
999 qla84xx_updatefw(struct bsg_job *bsg_job)
1001 struct fc_bsg_request *bsg_request = bsg_job->request;
1002 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1003 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1004 scsi_qla_host_t *vha = shost_priv(host);
1005 struct qla_hw_data *ha = vha->hw;
1006 struct verify_chip_entry_84xx *mn = NULL;
1007 dma_addr_t mn_dma, fw_dma;
1008 void *fw_buf = NULL;
1016 if (!IS_QLA84XX(ha)) {
1017 ql_dbg(ql_dbg_user, vha, 0x7032,
1018 "Not 84xx, exiting.\n");
1022 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1023 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1025 ql_log(ql_log_warn, vha, 0x7033,
1026 "dma_map_sg returned %d for request.\n", sg_cnt);
1030 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1031 ql_log(ql_log_warn, vha, 0x7034,
1032 "DMA mapping resulted in different sg counts, "
1033 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1034 bsg_job->request_payload.sg_cnt, sg_cnt);
1039 data_len = bsg_job->request_payload.payload_len;
1040 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1041 &fw_dma, GFP_KERNEL);
1043 ql_log(ql_log_warn, vha, 0x7035,
1044 "DMA alloc failed for fw_buf.\n");
1049 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1050 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1052 mn = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1054 ql_log(ql_log_warn, vha, 0x7036,
1055 "DMA alloc failed for fw buffer.\n");
1057 goto done_free_fw_buf;
1060 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1061 fw_ver = get_unaligned_le32((uint32_t *)fw_buf + 2);
1063 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1064 mn->entry_count = 1;
1066 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1067 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1068 options |= VCO_DIAG_FW;
1070 mn->options = cpu_to_le16(options);
1071 mn->fw_ver = cpu_to_le32(fw_ver);
1072 mn->fw_size = cpu_to_le32(data_len);
1073 mn->fw_seq_size = cpu_to_le32(data_len);
1074 put_unaligned_le64(fw_dma, &mn->dsd.address);
1075 mn->dsd.length = cpu_to_le32(data_len);
1076 mn->data_seg_cnt = cpu_to_le16(1);
1078 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1081 ql_log(ql_log_warn, vha, 0x7037,
1082 "Vendor request 84xx updatefw failed.\n");
1084 rval = (DID_ERROR << 16);
1086 ql_dbg(ql_dbg_user, vha, 0x7038,
1087 "Vendor request 84xx updatefw completed.\n");
1089 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1090 bsg_reply->result = DID_OK;
1093 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1096 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1099 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1100 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1103 bsg_job_done(bsg_job, bsg_reply->result,
1104 bsg_reply->reply_payload_rcv_len);
1109 qla84xx_mgmt_cmd(struct bsg_job *bsg_job)
1111 struct fc_bsg_request *bsg_request = bsg_job->request;
1112 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1113 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1114 scsi_qla_host_t *vha = shost_priv(host);
1115 struct qla_hw_data *ha = vha->hw;
1116 struct access_chip_84xx *mn = NULL;
1117 dma_addr_t mn_dma, mgmt_dma;
1118 void *mgmt_b = NULL;
1120 struct qla_bsg_a84_mgmt *ql84_mgmt;
1122 uint32_t data_len = 0;
1123 uint32_t dma_direction = DMA_NONE;
1125 if (!IS_QLA84XX(ha)) {
1126 ql_log(ql_log_warn, vha, 0x703a,
1127 "Not 84xx, exiting.\n");
1131 mn = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1133 ql_log(ql_log_warn, vha, 0x703c,
1134 "DMA alloc failed for fw buffer.\n");
1138 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1139 mn->entry_count = 1;
1140 ql84_mgmt = (void *)bsg_request + sizeof(struct fc_bsg_request);
1141 switch (ql84_mgmt->mgmt.cmd) {
1142 case QLA84_MGMT_READ_MEM:
1143 case QLA84_MGMT_GET_INFO:
1144 sg_cnt = dma_map_sg(&ha->pdev->dev,
1145 bsg_job->reply_payload.sg_list,
1146 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1148 ql_log(ql_log_warn, vha, 0x703d,
1149 "dma_map_sg returned %d for reply.\n", sg_cnt);
1154 dma_direction = DMA_FROM_DEVICE;
1156 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
1157 ql_log(ql_log_warn, vha, 0x703e,
1158 "DMA mapping resulted in different sg counts, "
1159 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1160 bsg_job->reply_payload.sg_cnt, sg_cnt);
1165 data_len = bsg_job->reply_payload.payload_len;
1167 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1168 &mgmt_dma, GFP_KERNEL);
1170 ql_log(ql_log_warn, vha, 0x703f,
1171 "DMA alloc failed for mgmt_b.\n");
1176 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1177 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1180 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1182 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1183 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1185 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1189 ql84_mgmt->mgmt.mgmtp.u.info.context);
1193 case QLA84_MGMT_WRITE_MEM:
1194 sg_cnt = dma_map_sg(&ha->pdev->dev,
1195 bsg_job->request_payload.sg_list,
1196 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1199 ql_log(ql_log_warn, vha, 0x7040,
1200 "dma_map_sg returned %d.\n", sg_cnt);
1205 dma_direction = DMA_TO_DEVICE;
1207 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
1208 ql_log(ql_log_warn, vha, 0x7041,
1209 "DMA mapping resulted in different sg counts, "
1210 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1211 bsg_job->request_payload.sg_cnt, sg_cnt);
1216 data_len = bsg_job->request_payload.payload_len;
1217 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1218 &mgmt_dma, GFP_KERNEL);
1220 ql_log(ql_log_warn, vha, 0x7042,
1221 "DMA alloc failed for mgmt_b.\n");
1226 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1227 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1229 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1231 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1234 case QLA84_MGMT_CHNG_CONFIG:
1235 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1237 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1240 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1243 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1251 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1252 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1253 mn->dseg_count = cpu_to_le16(1);
1254 put_unaligned_le64(mgmt_dma, &mn->dsd.address);
1255 mn->dsd.length = cpu_to_le32(ql84_mgmt->mgmt.len);
1258 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1261 ql_log(ql_log_warn, vha, 0x7043,
1262 "Vendor request 84xx mgmt failed.\n");
1264 rval = (DID_ERROR << 16);
1267 ql_dbg(ql_dbg_user, vha, 0x7044,
1268 "Vendor request 84xx mgmt completed.\n");
1270 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1271 bsg_reply->result = DID_OK;
1273 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1274 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1275 bsg_reply->reply_payload_rcv_len =
1276 bsg_job->reply_payload.payload_len;
1278 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1279 bsg_job->reply_payload.sg_cnt, mgmt_b,
1286 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1288 if (dma_direction == DMA_TO_DEVICE)
1289 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1290 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1291 else if (dma_direction == DMA_FROM_DEVICE)
1292 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1293 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1296 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1299 bsg_job_done(bsg_job, bsg_reply->result,
1300 bsg_reply->reply_payload_rcv_len);
1305 qla24xx_iidma(struct bsg_job *bsg_job)
1307 struct fc_bsg_request *bsg_request = bsg_job->request;
1308 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1309 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1310 scsi_qla_host_t *vha = shost_priv(host);
1312 struct qla_port_param *port_param = NULL;
1313 fc_port_t *fcport = NULL;
1315 uint16_t mb[MAILBOX_REGISTER_COUNT];
1316 uint8_t *rsp_ptr = NULL;
1318 if (!IS_IIDMA_CAPABLE(vha->hw)) {
1319 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
1323 port_param = (void *)bsg_request + sizeof(struct fc_bsg_request);
1324 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
1325 ql_log(ql_log_warn, vha, 0x7048,
1326 "Invalid destination type.\n");
1330 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1331 if (fcport->port_type != FCT_TARGET)
1334 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1335 fcport->port_name, sizeof(fcport->port_name)))
1343 ql_log(ql_log_warn, vha, 0x7049,
1344 "Failed to find port.\n");
1348 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1349 ql_log(ql_log_warn, vha, 0x704a,
1350 "Port is not online.\n");
1354 if (fcport->flags & FCF_LOGIN_NEEDED) {
1355 ql_log(ql_log_warn, vha, 0x704b,
1356 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
1360 if (port_param->mode)
1361 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1362 port_param->speed, mb);
1364 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1365 &port_param->speed, mb);
1368 ql_log(ql_log_warn, vha, 0x704c,
1369 "iiDMA cmd failed for %8phN -- "
1370 "%04x %x %04x %04x.\n", fcport->port_name,
1371 rval, fcport->fp_speed, mb[0], mb[1]);
1372 rval = (DID_ERROR << 16);
1374 if (!port_param->mode) {
1375 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1376 sizeof(struct qla_port_param);
1378 rsp_ptr = ((uint8_t *)bsg_reply) +
1379 sizeof(struct fc_bsg_reply);
1381 memcpy(rsp_ptr, port_param,
1382 sizeof(struct qla_port_param));
1385 bsg_reply->result = DID_OK;
1386 bsg_job_done(bsg_job, bsg_reply->result,
1387 bsg_reply->reply_payload_rcv_len);
1394 qla2x00_optrom_setup(struct bsg_job *bsg_job, scsi_qla_host_t *vha,
1397 struct fc_bsg_request *bsg_request = bsg_job->request;
1400 struct qla_hw_data *ha = vha->hw;
1402 if (unlikely(pci_channel_offline(ha->pdev)))
1405 start = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1406 if (start > ha->optrom_size) {
1407 ql_log(ql_log_warn, vha, 0x7055,
1408 "start %d > optrom_size %d.\n", start, ha->optrom_size);
1412 if (ha->optrom_state != QLA_SWAITING) {
1413 ql_log(ql_log_info, vha, 0x7056,
1414 "optrom_state %d.\n", ha->optrom_state);
1418 ha->optrom_region_start = start;
1419 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
1421 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1423 else if (start == (ha->flt_region_boot * 4) ||
1424 start == (ha->flt_region_fw * 4))
1426 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1427 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
1431 ql_log(ql_log_warn, vha, 0x7058,
1432 "Invalid start region 0x%x/0x%x.\n", start,
1433 bsg_job->request_payload.payload_len);
1437 ha->optrom_region_size = start +
1438 bsg_job->request_payload.payload_len > ha->optrom_size ?
1439 ha->optrom_size - start :
1440 bsg_job->request_payload.payload_len;
1441 ha->optrom_state = QLA_SWRITING;
1443 ha->optrom_region_size = start +
1444 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1445 ha->optrom_size - start :
1446 bsg_job->reply_payload.payload_len;
1447 ha->optrom_state = QLA_SREADING;
1450 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
1451 if (!ha->optrom_buffer) {
1452 ql_log(ql_log_warn, vha, 0x7059,
1453 "Read: Unable to allocate memory for optrom retrieval "
1454 "(%x)\n", ha->optrom_region_size);
1456 ha->optrom_state = QLA_SWAITING;
1464 qla2x00_read_optrom(struct bsg_job *bsg_job)
1466 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1467 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1468 scsi_qla_host_t *vha = shost_priv(host);
1469 struct qla_hw_data *ha = vha->hw;
1472 if (ha->flags.nic_core_reset_hdlr_active)
1475 mutex_lock(&ha->optrom_mutex);
1476 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
1478 mutex_unlock(&ha->optrom_mutex);
1482 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1483 ha->optrom_region_start, ha->optrom_region_size);
1485 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1486 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1487 ha->optrom_region_size);
1489 bsg_reply->reply_payload_rcv_len = ha->optrom_region_size;
1490 bsg_reply->result = DID_OK;
1491 vfree(ha->optrom_buffer);
1492 ha->optrom_buffer = NULL;
1493 ha->optrom_state = QLA_SWAITING;
1494 mutex_unlock(&ha->optrom_mutex);
1495 bsg_job_done(bsg_job, bsg_reply->result,
1496 bsg_reply->reply_payload_rcv_len);
1501 qla2x00_update_optrom(struct bsg_job *bsg_job)
1503 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1504 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1505 scsi_qla_host_t *vha = shost_priv(host);
1506 struct qla_hw_data *ha = vha->hw;
1509 mutex_lock(&ha->optrom_mutex);
1510 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
1512 mutex_unlock(&ha->optrom_mutex);
1516 /* Set the isp82xx_no_md_cap not to capture minidump */
1517 ha->flags.isp82xx_no_md_cap = 1;
1519 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1520 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1521 ha->optrom_region_size);
1523 rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1524 ha->optrom_region_start, ha->optrom_region_size);
1527 bsg_reply->result = -EINVAL;
1530 bsg_reply->result = DID_OK;
1532 vfree(ha->optrom_buffer);
1533 ha->optrom_buffer = NULL;
1534 ha->optrom_state = QLA_SWAITING;
1535 mutex_unlock(&ha->optrom_mutex);
1536 bsg_job_done(bsg_job, bsg_reply->result,
1537 bsg_reply->reply_payload_rcv_len);
1542 qla2x00_update_fru_versions(struct bsg_job *bsg_job)
1544 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1545 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1546 scsi_qla_host_t *vha = shost_priv(host);
1547 struct qla_hw_data *ha = vha->hw;
1549 uint8_t bsg[DMA_POOL_SIZE];
1550 struct qla_image_version_list *list = (void *)bsg;
1551 struct qla_image_version *image;
1554 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1557 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1558 EXT_STATUS_NO_MEMORY;
1562 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1563 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1565 image = list->version;
1566 count = list->count;
1568 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1569 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1570 image->field_address.device, image->field_address.offset,
1571 sizeof(image->field_info), image->field_address.option);
1573 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1580 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1583 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1586 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1587 bsg_reply->result = DID_OK << 16;
1588 bsg_job_done(bsg_job, bsg_reply->result,
1589 bsg_reply->reply_payload_rcv_len);
1595 qla2x00_read_fru_status(struct bsg_job *bsg_job)
1597 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1598 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1599 scsi_qla_host_t *vha = shost_priv(host);
1600 struct qla_hw_data *ha = vha->hw;
1602 uint8_t bsg[DMA_POOL_SIZE];
1603 struct qla_status_reg *sr = (void *)bsg;
1605 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1608 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1609 EXT_STATUS_NO_MEMORY;
1613 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1614 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1616 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1617 sr->field_address.device, sr->field_address.offset,
1618 sizeof(sr->status_reg), sr->field_address.option);
1619 sr->status_reg = *sfp;
1622 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1627 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1628 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1630 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1633 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1636 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1637 bsg_reply->reply_payload_rcv_len = sizeof(*sr);
1638 bsg_reply->result = DID_OK << 16;
1639 bsg_job_done(bsg_job, bsg_reply->result,
1640 bsg_reply->reply_payload_rcv_len);
1646 qla2x00_write_fru_status(struct bsg_job *bsg_job)
1648 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1649 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1650 scsi_qla_host_t *vha = shost_priv(host);
1651 struct qla_hw_data *ha = vha->hw;
1653 uint8_t bsg[DMA_POOL_SIZE];
1654 struct qla_status_reg *sr = (void *)bsg;
1656 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1659 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1660 EXT_STATUS_NO_MEMORY;
1664 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1665 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1667 *sfp = sr->status_reg;
1668 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1669 sr->field_address.device, sr->field_address.offset,
1670 sizeof(sr->status_reg), sr->field_address.option);
1673 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1678 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1681 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1684 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1685 bsg_reply->result = DID_OK << 16;
1686 bsg_job_done(bsg_job, bsg_reply->result,
1687 bsg_reply->reply_payload_rcv_len);
1693 qla2x00_write_i2c(struct bsg_job *bsg_job)
1695 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1696 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1697 scsi_qla_host_t *vha = shost_priv(host);
1698 struct qla_hw_data *ha = vha->hw;
1700 uint8_t bsg[DMA_POOL_SIZE];
1701 struct qla_i2c_access *i2c = (void *)bsg;
1703 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1706 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1707 EXT_STATUS_NO_MEMORY;
1711 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1712 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1714 memcpy(sfp, i2c->buffer, i2c->length);
1715 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1716 i2c->device, i2c->offset, i2c->length, i2c->option);
1719 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1724 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1727 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1730 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1731 bsg_reply->result = DID_OK << 16;
1732 bsg_job_done(bsg_job, bsg_reply->result,
1733 bsg_reply->reply_payload_rcv_len);
1739 qla2x00_read_i2c(struct bsg_job *bsg_job)
1741 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1742 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1743 scsi_qla_host_t *vha = shost_priv(host);
1744 struct qla_hw_data *ha = vha->hw;
1746 uint8_t bsg[DMA_POOL_SIZE];
1747 struct qla_i2c_access *i2c = (void *)bsg;
1749 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1752 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1753 EXT_STATUS_NO_MEMORY;
1757 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1758 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1760 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1761 i2c->device, i2c->offset, i2c->length, i2c->option);
1764 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
1769 memcpy(i2c->buffer, sfp, i2c->length);
1770 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1771 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1773 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1776 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1779 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1780 bsg_reply->reply_payload_rcv_len = sizeof(*i2c);
1781 bsg_reply->result = DID_OK << 16;
1782 bsg_job_done(bsg_job, bsg_reply->result,
1783 bsg_reply->reply_payload_rcv_len);
1789 qla24xx_process_bidir_cmd(struct bsg_job *bsg_job)
1791 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
1792 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1793 scsi_qla_host_t *vha = shost_priv(host);
1794 struct qla_hw_data *ha = vha->hw;
1795 uint32_t rval = EXT_STATUS_OK;
1796 uint16_t req_sg_cnt = 0;
1797 uint16_t rsp_sg_cnt = 0;
1798 uint16_t nextlid = 0;
1801 uint32_t req_data_len;
1802 uint32_t rsp_data_len;
1804 /* Check the type of the adapter */
1805 if (!IS_BIDI_CAPABLE(ha)) {
1806 ql_log(ql_log_warn, vha, 0x70a0,
1807 "This adapter is not supported\n");
1808 rval = EXT_STATUS_NOT_SUPPORTED;
1812 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1813 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1814 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1815 rval = EXT_STATUS_BUSY;
1819 /* Check if host is online */
1820 if (!vha->flags.online) {
1821 ql_log(ql_log_warn, vha, 0x70a1,
1822 "Host is not online\n");
1823 rval = EXT_STATUS_DEVICE_OFFLINE;
1827 /* Check if cable is plugged in or not */
1828 if (vha->device_flags & DFLG_NO_CABLE) {
1829 ql_log(ql_log_warn, vha, 0x70a2,
1830 "Cable is unplugged...\n");
1831 rval = EXT_STATUS_INVALID_CFG;
1835 /* Check if the switch is connected or not */
1836 if (ha->current_topology != ISP_CFG_F) {
1837 ql_log(ql_log_warn, vha, 0x70a3,
1838 "Host is not connected to the switch\n");
1839 rval = EXT_STATUS_INVALID_CFG;
1843 /* Check if operating mode is P2P */
1844 if (ha->operating_mode != P2P) {
1845 ql_log(ql_log_warn, vha, 0x70a4,
1846 "Host operating mode is not P2p\n");
1847 rval = EXT_STATUS_INVALID_CFG;
1851 mutex_lock(&ha->selflogin_lock);
1852 if (vha->self_login_loop_id == 0) {
1853 /* Initialize all required fields of fcport */
1854 vha->bidir_fcport.vha = vha;
1855 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1856 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1857 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1858 vha->bidir_fcport.loop_id = vha->loop_id;
1860 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1861 ql_log(ql_log_warn, vha, 0x70a7,
1862 "Failed to login port %06X for bidirectional IOCB\n",
1863 vha->bidir_fcport.d_id.b24);
1864 mutex_unlock(&ha->selflogin_lock);
1865 rval = EXT_STATUS_MAILBOX;
1868 vha->self_login_loop_id = nextlid - 1;
1871 /* Assign the self login loop id to fcport */
1872 mutex_unlock(&ha->selflogin_lock);
1874 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1876 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1877 bsg_job->request_payload.sg_list,
1878 bsg_job->request_payload.sg_cnt,
1882 rval = EXT_STATUS_NO_MEMORY;
1886 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1887 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1891 rval = EXT_STATUS_NO_MEMORY;
1892 goto done_unmap_req_sg;
1895 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1896 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1897 ql_dbg(ql_dbg_user, vha, 0x70a9,
1898 "Dma mapping resulted in different sg counts "
1899 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1900 "%x dma_reply_sg_cnt: %x]\n",
1901 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1902 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1903 rval = EXT_STATUS_NO_MEMORY;
1907 req_data_len = bsg_job->request_payload.payload_len;
1908 rsp_data_len = bsg_job->reply_payload.payload_len;
1910 if (req_data_len != rsp_data_len) {
1911 rval = EXT_STATUS_BUSY;
1912 ql_log(ql_log_warn, vha, 0x70aa,
1913 "req_data_len != rsp_data_len\n");
1917 /* Alloc SRB structure */
1918 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1920 ql_dbg(ql_dbg_user, vha, 0x70ac,
1921 "Alloc SRB structure failed\n");
1922 rval = EXT_STATUS_NO_MEMORY;
1926 /*Populate srb->ctx with bidir ctx*/
1927 sp->u.bsg_job = bsg_job;
1928 sp->free = qla2x00_bsg_sp_free;
1929 sp->type = SRB_BIDI_CMD;
1930 sp->done = qla2x00_bsg_job_done;
1932 /* Add the read and write sg count */
1933 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1935 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1936 if (rval != EXT_STATUS_OK)
1938 /* the bsg request will be completed in the interrupt handler */
1942 mempool_free(sp, ha->srb_mempool);
1944 dma_unmap_sg(&ha->pdev->dev,
1945 bsg_job->reply_payload.sg_list,
1946 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1948 dma_unmap_sg(&ha->pdev->dev,
1949 bsg_job->request_payload.sg_list,
1950 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1953 /* Return an error vendor specific response
1954 * and complete the bsg request
1956 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1957 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1958 bsg_reply->reply_payload_rcv_len = 0;
1959 bsg_reply->result = (DID_OK) << 16;
1960 bsg_job_done(bsg_job, bsg_reply->result,
1961 bsg_reply->reply_payload_rcv_len);
1962 /* Always return success, vendor rsp carries correct status */
1967 qlafx00_mgmt_cmd(struct bsg_job *bsg_job)
1969 struct fc_bsg_request *bsg_request = bsg_job->request;
1970 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
1971 scsi_qla_host_t *vha = shost_priv(host);
1972 struct qla_hw_data *ha = vha->hw;
1973 int rval = (DID_ERROR << 16);
1974 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1976 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1977 struct fc_port *fcport;
1978 char *type = "FC_BSG_HST_FX_MGMT";
1980 /* Copy the IOCB specific information */
1981 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1982 &bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1984 /* Dump the vendor information */
1985 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1986 piocb_rqst, sizeof(*piocb_rqst));
1988 if (!vha->flags.online) {
1989 ql_log(ql_log_warn, vha, 0x70d0,
1990 "Host is not online.\n");
1995 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1996 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1997 bsg_job->request_payload.sg_list,
1998 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2000 ql_log(ql_log_warn, vha, 0x70c7,
2001 "dma_map_sg return %d for request\n", req_sg_cnt);
2007 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
2008 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
2009 bsg_job->reply_payload.sg_list,
2010 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2012 ql_log(ql_log_warn, vha, 0x70c8,
2013 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
2015 goto done_unmap_req_sg;
2019 ql_dbg(ql_dbg_user, vha, 0x70c9,
2020 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
2021 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
2022 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
2024 /* Allocate a dummy fcport structure, since functions preparing the
2025 * IOCB and mailbox command retrieves port specific information
2026 * from fcport structure. For Host based ELS commands there will be
2027 * no fcport structure allocated
2029 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2031 ql_log(ql_log_warn, vha, 0x70ca,
2032 "Failed to allocate fcport.\n");
2034 goto done_unmap_rsp_sg;
2037 /* Alloc SRB structure */
2038 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
2040 ql_log(ql_log_warn, vha, 0x70cb,
2041 "qla2x00_get_sp failed.\n");
2043 goto done_free_fcport;
2046 /* Initialize all required fields of fcport */
2048 fcport->loop_id = le32_to_cpu(piocb_rqst->dataword);
2050 sp->type = SRB_FXIOCB_BCMD;
2051 sp->name = "bsg_fx_mgmt";
2052 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
2053 sp->u.bsg_job = bsg_job;
2054 sp->free = qla2x00_bsg_sp_free;
2055 sp->done = qla2x00_bsg_job_done;
2057 ql_dbg(ql_dbg_user, vha, 0x70cc,
2058 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2059 type, piocb_rqst->func_type, fcport->loop_id);
2061 rval = qla2x00_start_sp(sp);
2062 if (rval != QLA_SUCCESS) {
2063 ql_log(ql_log_warn, vha, 0x70cd,
2064 "qla2x00_start_sp failed=%d.\n", rval);
2065 mempool_free(sp, ha->srb_mempool);
2067 goto done_free_fcport;
2072 qla2x00_free_fcport(fcport);
2075 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2076 dma_unmap_sg(&ha->pdev->dev,
2077 bsg_job->reply_payload.sg_list,
2078 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2080 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2081 dma_unmap_sg(&ha->pdev->dev,
2082 bsg_job->request_payload.sg_list,
2083 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2090 qla26xx_serdes_op(struct bsg_job *bsg_job)
2092 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2093 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2094 scsi_qla_host_t *vha = shost_priv(host);
2096 struct qla_serdes_reg sr;
2098 memset(&sr, 0, sizeof(sr));
2100 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2101 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2104 case INT_SC_SERDES_WRITE_REG:
2105 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
2106 bsg_reply->reply_payload_rcv_len = 0;
2108 case INT_SC_SERDES_READ_REG:
2109 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2110 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2111 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2112 bsg_reply->reply_payload_rcv_len = sizeof(sr);
2115 ql_dbg(ql_dbg_user, vha, 0x708c,
2116 "Unknown serdes cmd %x.\n", sr.cmd);
2121 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2122 rval ? EXT_STATUS_MAILBOX : 0;
2124 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2125 bsg_reply->result = DID_OK << 16;
2126 bsg_job_done(bsg_job, bsg_reply->result,
2127 bsg_reply->reply_payload_rcv_len);
2132 qla8044_serdes_op(struct bsg_job *bsg_job)
2134 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2135 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2136 scsi_qla_host_t *vha = shost_priv(host);
2138 struct qla_serdes_reg_ex sr;
2140 memset(&sr, 0, sizeof(sr));
2142 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2143 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2146 case INT_SC_SERDES_WRITE_REG:
2147 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
2148 bsg_reply->reply_payload_rcv_len = 0;
2150 case INT_SC_SERDES_READ_REG:
2151 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2152 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2153 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2154 bsg_reply->reply_payload_rcv_len = sizeof(sr);
2157 ql_dbg(ql_dbg_user, vha, 0x7020,
2158 "Unknown serdes cmd %x.\n", sr.cmd);
2163 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2164 rval ? EXT_STATUS_MAILBOX : 0;
2166 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2167 bsg_reply->result = DID_OK << 16;
2168 bsg_job_done(bsg_job, bsg_reply->result,
2169 bsg_reply->reply_payload_rcv_len);
2174 qla27xx_get_flash_upd_cap(struct bsg_job *bsg_job)
2176 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2177 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2178 scsi_qla_host_t *vha = shost_priv(host);
2179 struct qla_hw_data *ha = vha->hw;
2180 struct qla_flash_update_caps cap;
2182 if (!(IS_QLA27XX(ha)) && !IS_QLA28XX(ha))
2185 memset(&cap, 0, sizeof(cap));
2186 cap.capabilities = (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 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2192 bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
2193 bsg_reply->reply_payload_rcv_len = sizeof(cap);
2195 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2198 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2199 bsg_reply->result = DID_OK << 16;
2200 bsg_job_done(bsg_job, bsg_reply->result,
2201 bsg_reply->reply_payload_rcv_len);
2206 qla27xx_set_flash_upd_cap(struct bsg_job *bsg_job)
2208 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2209 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2210 scsi_qla_host_t *vha = shost_priv(host);
2211 struct qla_hw_data *ha = vha->hw;
2212 uint64_t online_fw_attr = 0;
2213 struct qla_flash_update_caps cap;
2215 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2218 memset(&cap, 0, sizeof(cap));
2219 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2220 bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
2222 online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2223 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2224 (uint64_t)ha->fw_attributes_h << 16 |
2225 (uint64_t)ha->fw_attributes;
2227 if (online_fw_attr != cap.capabilities) {
2228 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2229 EXT_STATUS_INVALID_PARAM;
2233 if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
2234 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2235 EXT_STATUS_INVALID_PARAM;
2239 bsg_reply->reply_payload_rcv_len = 0;
2241 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2244 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2245 bsg_reply->result = DID_OK << 16;
2246 bsg_job_done(bsg_job, bsg_reply->result,
2247 bsg_reply->reply_payload_rcv_len);
2252 qla27xx_get_bbcr_data(struct bsg_job *bsg_job)
2254 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2255 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2256 scsi_qla_host_t *vha = shost_priv(host);
2257 struct qla_hw_data *ha = vha->hw;
2258 struct qla_bbcr_data bbcr;
2259 uint16_t loop_id, topo, sw_cap;
2260 uint8_t domain, area, al_pa, state;
2263 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2266 memset(&bbcr, 0, sizeof(bbcr));
2268 if (vha->flags.bbcr_enable)
2269 bbcr.status = QLA_BBCR_STATUS_ENABLED;
2271 bbcr.status = QLA_BBCR_STATUS_DISABLED;
2273 if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
2274 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2275 &area, &domain, &topo, &sw_cap);
2276 if (rval != QLA_SUCCESS) {
2277 bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
2278 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2279 bbcr.mbx1 = loop_id;
2283 state = (vha->bbcr >> 12) & 0x1;
2286 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2287 bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
2289 bbcr.state = QLA_BBCR_STATE_ONLINE;
2290 bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
2293 bbcr.configured_bbscn = vha->bbcr & 0xf;
2297 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2298 bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
2299 bsg_reply->reply_payload_rcv_len = sizeof(bbcr);
2301 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2303 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2304 bsg_reply->result = DID_OK << 16;
2305 bsg_job_done(bsg_job, bsg_reply->result,
2306 bsg_reply->reply_payload_rcv_len);
2311 qla2x00_get_priv_stats(struct bsg_job *bsg_job)
2313 struct fc_bsg_request *bsg_request = bsg_job->request;
2314 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2315 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2316 scsi_qla_host_t *vha = shost_priv(host);
2317 struct qla_hw_data *ha = vha->hw;
2318 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2319 struct link_statistics *stats = NULL;
2320 dma_addr_t stats_dma;
2322 uint32_t *cmd = bsg_request->rqst_data.h_vendor.vendor_cmd;
2323 uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
2325 if (test_bit(UNLOADING, &vha->dpc_flags))
2328 if (unlikely(pci_channel_offline(ha->pdev)))
2331 if (qla2x00_reset_active(vha))
2334 if (!IS_FWI2_CAPABLE(ha))
2337 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2340 ql_log(ql_log_warn, vha, 0x70e2,
2341 "Failed to allocate memory for stats.\n");
2345 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
2347 if (rval == QLA_SUCCESS) {
2348 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e5,
2349 stats, sizeof(*stats));
2350 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2351 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
2354 bsg_reply->reply_payload_rcv_len = sizeof(*stats);
2355 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2356 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2358 bsg_job->reply_len = sizeof(*bsg_reply);
2359 bsg_reply->result = DID_OK << 16;
2360 bsg_job_done(bsg_job, bsg_reply->result,
2361 bsg_reply->reply_payload_rcv_len);
2363 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2370 qla2x00_do_dport_diagnostics(struct bsg_job *bsg_job)
2372 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2373 struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
2374 scsi_qla_host_t *vha = shost_priv(host);
2376 struct qla_dport_diag *dd;
2378 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2379 !IS_QLA28XX(vha->hw))
2382 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
2384 ql_log(ql_log_warn, vha, 0x70db,
2385 "Failed to allocate memory for dport.\n");
2389 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2390 bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
2392 rval = qla26xx_dport_diagnostics(
2393 vha, dd->buf, sizeof(dd->buf), dd->options);
2394 if (rval == QLA_SUCCESS) {
2395 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2396 bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
2399 bsg_reply->reply_payload_rcv_len = sizeof(*dd);
2400 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
2401 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2403 bsg_job->reply_len = sizeof(*bsg_reply);
2404 bsg_reply->result = DID_OK << 16;
2405 bsg_job_done(bsg_job, bsg_reply->result,
2406 bsg_reply->reply_payload_rcv_len);
2414 qla2x00_get_flash_image_status(struct bsg_job *bsg_job)
2416 scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
2417 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2418 struct qla_hw_data *ha = vha->hw;
2419 struct qla_active_regions regions = { };
2420 struct active_regions active_regions = { };
2422 qla27xx_get_active_image(vha, &active_regions);
2423 regions.global_image = active_regions.global;
2425 if (IS_QLA28XX(ha)) {
2426 qla28xx_get_aux_images(vha, &active_regions);
2427 regions.board_config = active_regions.aux.board_config;
2428 regions.vpd_nvram = active_regions.aux.vpd_nvram;
2429 regions.npiv_config_0_1 = active_regions.aux.npiv_config_0_1;
2430 regions.npiv_config_2_3 = active_regions.aux.npiv_config_2_3;
2433 ql_dbg(ql_dbg_user, vha, 0x70e1,
2434 "%s(%lu): FW=%u BCFG=%u VPDNVR=%u NPIV01=%u NPIV02=%u\n",
2435 __func__, vha->host_no, regions.global_image,
2436 regions.board_config, regions.vpd_nvram,
2437 regions.npiv_config_0_1, regions.npiv_config_2_3);
2439 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2440 bsg_job->reply_payload.sg_cnt, ®ions, sizeof(regions));
2442 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2443 bsg_reply->reply_payload_rcv_len = sizeof(regions);
2444 bsg_reply->result = DID_OK << 16;
2445 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2446 bsg_job_done(bsg_job, bsg_reply->result,
2447 bsg_reply->reply_payload_rcv_len);
2453 qla2x00_process_vendor_specific(struct bsg_job *bsg_job)
2455 struct fc_bsg_request *bsg_request = bsg_job->request;
2457 switch (bsg_request->rqst_data.h_vendor.vendor_cmd[0]) {
2458 case QL_VND_LOOPBACK:
2459 return qla2x00_process_loopback(bsg_job);
2461 case QL_VND_A84_RESET:
2462 return qla84xx_reset(bsg_job);
2464 case QL_VND_A84_UPDATE_FW:
2465 return qla84xx_updatefw(bsg_job);
2467 case QL_VND_A84_MGMT_CMD:
2468 return qla84xx_mgmt_cmd(bsg_job);
2471 return qla24xx_iidma(bsg_job);
2473 case QL_VND_FCP_PRIO_CFG_CMD:
2474 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2476 case QL_VND_READ_FLASH:
2477 return qla2x00_read_optrom(bsg_job);
2479 case QL_VND_UPDATE_FLASH:
2480 return qla2x00_update_optrom(bsg_job);
2482 case QL_VND_SET_FRU_VERSION:
2483 return qla2x00_update_fru_versions(bsg_job);
2485 case QL_VND_READ_FRU_STATUS:
2486 return qla2x00_read_fru_status(bsg_job);
2488 case QL_VND_WRITE_FRU_STATUS:
2489 return qla2x00_write_fru_status(bsg_job);
2491 case QL_VND_WRITE_I2C:
2492 return qla2x00_write_i2c(bsg_job);
2494 case QL_VND_READ_I2C:
2495 return qla2x00_read_i2c(bsg_job);
2497 case QL_VND_DIAG_IO_CMD:
2498 return qla24xx_process_bidir_cmd(bsg_job);
2500 case QL_VND_FX00_MGMT_CMD:
2501 return qlafx00_mgmt_cmd(bsg_job);
2503 case QL_VND_SERDES_OP:
2504 return qla26xx_serdes_op(bsg_job);
2506 case QL_VND_SERDES_OP_EX:
2507 return qla8044_serdes_op(bsg_job);
2509 case QL_VND_GET_FLASH_UPDATE_CAPS:
2510 return qla27xx_get_flash_upd_cap(bsg_job);
2512 case QL_VND_SET_FLASH_UPDATE_CAPS:
2513 return qla27xx_set_flash_upd_cap(bsg_job);
2515 case QL_VND_GET_BBCR_DATA:
2516 return qla27xx_get_bbcr_data(bsg_job);
2518 case QL_VND_GET_PRIV_STATS:
2519 case QL_VND_GET_PRIV_STATS_EX:
2520 return qla2x00_get_priv_stats(bsg_job);
2522 case QL_VND_DPORT_DIAGNOSTICS:
2523 return qla2x00_do_dport_diagnostics(bsg_job);
2525 case QL_VND_SS_GET_FLASH_IMAGE_STATUS:
2526 return qla2x00_get_flash_image_status(bsg_job);
2534 qla24xx_bsg_request(struct bsg_job *bsg_job)
2536 struct fc_bsg_request *bsg_request = bsg_job->request;
2537 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2539 struct fc_rport *rport;
2540 struct Scsi_Host *host;
2541 scsi_qla_host_t *vha;
2543 /* In case no data transferred. */
2544 bsg_reply->reply_payload_rcv_len = 0;
2546 if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
2547 rport = fc_bsg_to_rport(bsg_job);
2550 host = rport_to_shost(rport);
2551 vha = shost_priv(host);
2553 host = fc_bsg_to_shost(bsg_job);
2554 vha = shost_priv(host);
2557 if (qla2x00_chip_is_down(vha)) {
2558 ql_dbg(ql_dbg_user, vha, 0x709f,
2559 "BSG: ISP abort active/needed -- cmd=%d.\n",
2560 bsg_request->msgcode);
2564 ql_dbg(ql_dbg_user, vha, 0x7000,
2565 "Entered %s msgcode=0x%x.\n", __func__, bsg_request->msgcode);
2567 switch (bsg_request->msgcode) {
2568 case FC_BSG_RPT_ELS:
2569 case FC_BSG_HST_ELS_NOLOGIN:
2570 ret = qla2x00_process_els(bsg_job);
2573 ret = qla2x00_process_ct(bsg_job);
2575 case FC_BSG_HST_VENDOR:
2576 ret = qla2x00_process_vendor_specific(bsg_job);
2578 case FC_BSG_HST_ADD_RPORT:
2579 case FC_BSG_HST_DEL_RPORT:
2582 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
2589 qla24xx_bsg_timeout(struct bsg_job *bsg_job)
2591 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2592 scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
2593 struct qla_hw_data *ha = vha->hw;
2596 unsigned long flags;
2597 struct req_que *req;
2599 /* find the bsg job from the active list of commands */
2600 spin_lock_irqsave(&ha->hardware_lock, flags);
2601 for (que = 0; que < ha->max_req_queues; que++) {
2602 req = ha->req_q_map[que];
2606 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
2607 sp = req->outstanding_cmds[cnt];
2609 if (((sp->type == SRB_CT_CMD) ||
2610 (sp->type == SRB_ELS_CMD_HST) ||
2611 (sp->type == SRB_FXIOCB_BCMD))
2612 && (sp->u.bsg_job == bsg_job)) {
2613 req->outstanding_cmds[cnt] = NULL;
2614 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2615 if (ha->isp_ops->abort_command(sp)) {
2616 ql_log(ql_log_warn, vha, 0x7089,
2617 "mbx abort_command "
2619 bsg_reply->result = -EIO;
2621 ql_dbg(ql_dbg_user, vha, 0x708a,
2622 "mbx abort_command "
2624 bsg_reply->result = 0;
2626 spin_lock_irqsave(&ha->hardware_lock, flags);
2632 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2633 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
2634 bsg_reply->result = -ENXIO;
2638 spin_unlock_irqrestore(&ha->hardware_lock, flags);