Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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