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 iSCSI HBA Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2011-2013 QLogic Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "ql4_def.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "ql4_glbl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "ql4_bsg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) qla4xxx_read_flash(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	uint32_t length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	dma_addr_t flash_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	uint8_t *flash = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (ha->flash_state != QLFLASH_WAITING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		ql4_printk(KERN_ERR, ha, "%s: another flash operation "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			   "active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	ha->flash_state = QLFLASH_READING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	length = bsg_job->reply_payload.payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	flash = dma_alloc_coherent(&ha->pdev->dev, length, &flash_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!flash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			   "data\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	rval = qla4xxx_get_flash(ha, flash_dma, offset, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		ql4_printk(KERN_ERR, ha, "%s: get flash failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		bsg_reply->reply_payload_rcv_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 					    bsg_job->reply_payload.sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 					    flash, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	ha->flash_state = QLFLASH_WAITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) qla4xxx_update_flash(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	uint32_t length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	uint32_t options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	dma_addr_t flash_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	uint8_t *flash = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (ha->flash_state != QLFLASH_WAITING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		ql4_printk(KERN_ERR, ha, "%s: another flash operation "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			   "active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	ha->flash_state = QLFLASH_WRITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	length = bsg_job->request_payload.payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	options = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	flash = dma_alloc_coherent(&ha->pdev->dev, length, &flash_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!flash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			   "data\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	sg_copy_to_buffer(bsg_job->request_payload.sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			  bsg_job->request_payload.sg_cnt, flash, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	rval = qla4xxx_set_flash(ha, flash_dma, offset, length, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		ql4_printk(KERN_ERR, ha, "%s: set flash failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ha->flash_state = QLFLASH_WAITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) qla4xxx_get_acb_state(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	uint32_t status[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	uint32_t acb_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	uint32_t ip_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/* Only 4022 and above adapters are supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (is_qla4010(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (bsg_job->reply_payload.payload_len < sizeof(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		ql4_printk(KERN_ERR, ha, "%s: invalid payload len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			   __func__, bsg_job->reply_payload.payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	acb_idx = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	ip_idx = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	rval = qla4xxx_get_ip_state(ha, acb_idx, ip_idx, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		ql4_printk(KERN_ERR, ha, "%s: get ip state failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		bsg_reply->reply_payload_rcv_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 					    bsg_job->reply_payload.sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 					    status, sizeof(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) qla4xxx_read_nvram(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	uint32_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	uint32_t total_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	dma_addr_t nvram_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	uint8_t *nvram = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* Only 40xx adapters are supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (!(is_qla4010(ha) || is_qla4022(ha) || is_qla4032(ha)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	len = bsg_job->reply_payload.payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	total_len = offset + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/* total len should not be greater than max NVRAM size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if ((is_qla4010(ha) && total_len > QL4010_NVRAM_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	    ((is_qla4022(ha) || is_qla4032(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	     total_len > QL40X2_NVRAM_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		ql4_printk(KERN_ERR, ha, "%s: offset+len greater than max"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			   " nvram size, offset=%d len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			   __func__, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	nvram = dma_alloc_coherent(&ha->pdev->dev, len, &nvram_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (!nvram) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for nvram "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			   "data\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	rval = qla4xxx_get_nvram(ha, nvram_dma, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		ql4_printk(KERN_ERR, ha, "%s: get nvram failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		bsg_reply->reply_payload_rcv_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 					    bsg_job->reply_payload.sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					    nvram, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	dma_free_coherent(&ha->pdev->dev, len, nvram, nvram_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) qla4xxx_update_nvram(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	uint32_t offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	uint32_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	uint32_t total_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	dma_addr_t nvram_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	uint8_t *nvram = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!(is_qla4010(ha) || is_qla4022(ha) || is_qla4032(ha)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	len = bsg_job->request_payload.payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	total_len = offset + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* total len should not be greater than max NVRAM size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if ((is_qla4010(ha) && total_len > QL4010_NVRAM_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	    ((is_qla4022(ha) || is_qla4032(ha)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	     total_len > QL40X2_NVRAM_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		ql4_printk(KERN_ERR, ha, "%s: offset+len greater than max"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			   " nvram size, offset=%d len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			   __func__, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	nvram = dma_alloc_coherent(&ha->pdev->dev, len, &nvram_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!nvram) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			   "data\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	sg_copy_to_buffer(bsg_job->request_payload.sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			  bsg_job->request_payload.sg_cnt, nvram, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	rval = qla4xxx_set_nvram(ha, nvram_dma, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		ql4_printk(KERN_ERR, ha, "%s: set nvram failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	dma_free_coherent(&ha->pdev->dev, len, nvram, nvram_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) qla4xxx_restore_defaults(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	uint32_t region = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	uint32_t field0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	uint32_t field1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (is_qla4010(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		goto leave;
^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) 	region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	field0 = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	field1 = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	rval = qla4xxx_restore_factory_defaults(ha, region, field0, field1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		ql4_printk(KERN_ERR, ha, "%s: set nvram failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return rval;
^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) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) qla4xxx_bsg_get_acb(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	uint32_t acb_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	uint32_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	dma_addr_t acb_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	uint8_t *acb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (unlikely(pci_channel_offline(ha->pdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	/* Only 4022 and above adapters are supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (is_qla4010(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (ql4xxx_reset_active(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	acb_type = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	len = bsg_job->reply_payload.payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (len < sizeof(struct addr_ctrl_blk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		ql4_printk(KERN_ERR, ha, "%s: invalid acb len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			   __func__, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	acb = dma_alloc_coherent(&ha->pdev->dev, len, &acb_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (!acb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for acb "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			   "data\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		rval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	rval = qla4xxx_get_acb(ha, acb_dma, acb_type, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		ql4_printk(KERN_ERR, ha, "%s: get acb failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		rval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		bsg_reply->reply_payload_rcv_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 					    bsg_job->reply_payload.sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 					    acb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	dma_free_coherent(&ha->pdev->dev, len, acb, acb_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static void ql4xxx_execute_diag_cmd(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	uint8_t *rsp_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	uint32_t mbox_cmd[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	uint32_t mbox_sts[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	int status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: in\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		ql4_printk(KERN_INFO, ha, "%s: Adapter reset in progress. Invalid Request\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		goto exit_diag_mem_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	memcpy(mbox_cmd, &bsg_req->rqst_data.h_vendor.vendor_cmd[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	       sizeof(uint32_t) * MBOX_REG_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			  "%s: mbox_cmd: %08X %08X %08X %08X %08X %08X %08X %08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			  __func__, mbox_cmd[0], mbox_cmd[1], mbox_cmd[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			  mbox_cmd[3], mbox_cmd[4], mbox_cmd[5], mbox_cmd[6],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			  mbox_cmd[7]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 8, &mbox_cmd[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 					 &mbox_sts[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			  "%s: mbox_sts: %08X %08X %08X %08X %08X %08X %08X %08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			  __func__, mbox_sts[0], mbox_sts[1], mbox_sts[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			  mbox_sts[3], mbox_sts[4], mbox_sts[5], mbox_sts[6],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			  mbox_sts[7]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	if (status == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	/* Send mbox_sts to application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	bsg_job->reply_len = sizeof(struct iscsi_bsg_reply) + sizeof(mbox_sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	rsp_ptr = ((uint8_t *)bsg_reply) + sizeof(struct iscsi_bsg_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	memcpy(rsp_ptr, mbox_sts, sizeof(mbox_sts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) exit_diag_mem_test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			  "%s: bsg_reply->result = x%x, status = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			  __func__, bsg_reply->result, STATUS(status)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static int qla4_83xx_wait_for_loopback_config_comp(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 						   int wait_for_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	if (!wait_for_completion_timeout(&ha->idc_comp, (IDC_COMP_TOV * HZ))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		ql4_printk(KERN_INFO, ha, "%s: IDC Complete notification not received, Waiting for another %d timeout",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			   __func__, ha->idc_extend_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		if (ha->idc_extend_tmo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			if (!wait_for_completion_timeout(&ha->idc_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 						(ha->idc_extend_tmo * HZ))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 				ha->notify_idc_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 				ha->notify_link_up_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 				ql4_printk(KERN_WARNING, ha, "%s: Aborting: IDC Complete notification not received",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 					   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 				status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 				goto exit_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 				DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 						  "%s: IDC Complete notification received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 						  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 				  "%s: IDC Complete notification received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 				  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	ha->notify_idc_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (wait_for_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		if (!wait_for_completion_timeout(&ha->link_up_comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 						 (IDC_COMP_TOV * HZ))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			ha->notify_link_up_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			ql4_printk(KERN_WARNING, ha, "%s: Aborting: LINK UP notification not received",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			goto exit_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 					  "%s: LINK UP notification received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 					  __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		ha->notify_link_up_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) exit_wait:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static int qla4_83xx_pre_loopback_config(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 					 uint32_t *mbox_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	uint32_t config = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: in\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	status = qla4_83xx_get_port_config(ha, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	if (status != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		goto exit_pre_loopback_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Default port config=%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			  __func__, config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	if ((config & ENABLE_INTERNAL_LOOPBACK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	    (config & ENABLE_EXTERNAL_LOOPBACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		ql4_printk(KERN_INFO, ha, "%s: Loopback diagnostics already in progress. Invalid request\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		goto exit_pre_loopback_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (mbox_cmd[1] == QL_DIAG_CMD_TEST_INT_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		config |= ENABLE_INTERNAL_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	if (mbox_cmd[1] == QL_DIAG_CMD_TEST_EXT_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		config |= ENABLE_EXTERNAL_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	config &= ~ENABLE_DCBX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: New port config=%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 			  __func__, config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	ha->notify_idc_comp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	ha->notify_link_up_comp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	/* get the link state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	qla4xxx_get_firmware_state(ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	status = qla4_83xx_set_port_config(ha, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		ha->notify_idc_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		ha->notify_link_up_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		goto exit_pre_loopback_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) exit_pre_loopback_config:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: status = %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 			  STATUS(status)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static int qla4_83xx_post_loopback_config(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 					  uint32_t *mbox_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	int status = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	uint32_t config = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: in\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	status = qla4_83xx_get_port_config(ha, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (status != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		goto exit_post_loopback_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: port config=%08X\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 			  config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	if (mbox_cmd[1] == QL_DIAG_CMD_TEST_INT_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		config &= ~ENABLE_INTERNAL_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	else if (mbox_cmd[1] == QL_DIAG_CMD_TEST_EXT_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		config &= ~ENABLE_EXTERNAL_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	config |= ENABLE_DCBX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 			  "%s: Restore default port config=%08X\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 			  config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	ha->notify_idc_comp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	if (ha->addl_fw_state & FW_ADDSTATE_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		ha->notify_link_up_comp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	status = qla4_83xx_set_port_config(ha, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		ql4_printk(KERN_INFO, ha, "%s: Scheduling adapter reset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		set_bit(DPC_RESET_HA, &ha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		clear_bit(AF_LOOPBACK, &ha->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		goto exit_post_loopback_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) exit_post_loopback_config:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: status = %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 			  STATUS(status)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static void qla4xxx_execute_diag_loopback_cmd(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	uint8_t *rsp_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	uint32_t mbox_cmd[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	uint32_t mbox_sts[MBOX_REG_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	int wait_for_link = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	int status = QLA_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: in\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	if (test_bit(AF_LOOPBACK, &ha->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		ql4_printk(KERN_INFO, ha, "%s: Loopback Diagnostics already in progress. Invalid Request\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		goto exit_loopback_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		ql4_printk(KERN_INFO, ha, "%s: Adapter reset in progress. Invalid Request\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		goto exit_loopback_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	memcpy(mbox_cmd, &bsg_req->rqst_data.h_vendor.vendor_cmd[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	       sizeof(uint32_t) * MBOX_REG_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		status = qla4_83xx_pre_loopback_config(ha, mbox_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 			bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 			goto exit_loopback_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		status = qla4_83xx_wait_for_loopback_config_comp(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 								 wait_for_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 		if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 			bsg_reply->result = DID_TIME_OUT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 			goto restore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 			  "%s: mbox_cmd: %08X %08X %08X %08X %08X %08X %08X %08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 			  __func__, mbox_cmd[0], mbox_cmd[1], mbox_cmd[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 			  mbox_cmd[3], mbox_cmd[4], mbox_cmd[5], mbox_cmd[6],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 			  mbox_cmd[7]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 8, &mbox_cmd[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 				&mbox_sts[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	if (status == QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		bsg_reply->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 			  "%s: mbox_sts: %08X %08X %08X %08X %08X %08X %08X %08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 			  __func__, mbox_sts[0], mbox_sts[1], mbox_sts[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			  mbox_sts[3], mbox_sts[4], mbox_sts[5], mbox_sts[6],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 			  mbox_sts[7]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	/* Send mbox_sts to application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	bsg_job->reply_len = sizeof(struct iscsi_bsg_reply) + sizeof(mbox_sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	rsp_ptr = ((uint8_t *)bsg_reply) + sizeof(struct iscsi_bsg_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	memcpy(rsp_ptr, mbox_sts, sizeof(mbox_sts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) restore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	if (is_qla8032(ha) || is_qla8042(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		status = qla4_83xx_post_loopback_config(ha, mbox_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 			bsg_reply->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 			goto exit_loopback_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 		/* for pre_loopback_config() wait for LINK UP only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		 * if PHY LINK is UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		if (!(ha->addl_fw_state & FW_ADDSTATE_LINK_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 			wait_for_link = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 		status = qla4_83xx_wait_for_loopback_config_comp(ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 								 wait_for_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		if (status != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 			bsg_reply->result = DID_TIME_OUT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			goto exit_loopback_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) exit_loopback_cmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	DEBUG2(ql4_printk(KERN_INFO, ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 			  "%s: bsg_reply->result = x%x, status = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 			  __func__, bsg_reply->result, STATUS(status)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) static int qla4xxx_execute_diag_test(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	uint32_t diag_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	int rval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	DEBUG2(ql4_printk(KERN_INFO, ha, "%s: in\n", __func__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	diag_cmd = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	if (diag_cmd == MBOX_CMD_DIAG_TEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		switch (bsg_req->rqst_data.h_vendor.vendor_cmd[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		case QL_DIAG_CMD_TEST_DDR_SIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		case QL_DIAG_CMD_TEST_DDR_RW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		case QL_DIAG_CMD_TEST_ONCHIP_MEM_RW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		case QL_DIAG_CMD_TEST_NVRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		case QL_DIAG_CMD_TEST_FLASH_ROM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 		case QL_DIAG_CMD_TEST_DMA_XFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		case QL_DIAG_CMD_SELF_DDR_RW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		case QL_DIAG_CMD_SELF_ONCHIP_MEM_RW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 			/* Execute diag test for adapter RAM/FLASH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 			ql4xxx_execute_diag_cmd(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 			/* Always return success as we want to sent bsg_reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 			 * to Application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 			rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		case QL_DIAG_CMD_TEST_INT_LOOPBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 		case QL_DIAG_CMD_TEST_EXT_LOOPBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 			/* Execute diag test for Network */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 			qla4xxx_execute_diag_loopback_cmd(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 			/* Always return success as we want to sent bsg_reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 			 * to Application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 			rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 			ql4_printk(KERN_ERR, ha, "%s: Invalid diag test: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 				   __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 				   bsg_req->rqst_data.h_vendor.vendor_cmd[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	} else if ((diag_cmd == MBOX_CMD_SET_LED_CONFIG) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 		   (diag_cmd == MBOX_CMD_GET_LED_CONFIG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 		ql4xxx_execute_diag_cmd(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 		rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 		ql4_printk(KERN_ERR, ha, "%s: Invalid diag cmd: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 			   __func__, diag_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)  * qla4xxx_process_vendor_specific - handle vendor specific bsg request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)  * @bsg_job: iscsi_bsg_job to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int qla4xxx_process_vendor_specific(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	case QLISCSI_VND_READ_FLASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		return qla4xxx_read_flash(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	case QLISCSI_VND_UPDATE_FLASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 		return qla4xxx_update_flash(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	case QLISCSI_VND_GET_ACB_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 		return qla4xxx_get_acb_state(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	case QLISCSI_VND_READ_NVRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		return qla4xxx_read_nvram(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	case QLISCSI_VND_UPDATE_NVRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 		return qla4xxx_update_nvram(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	case QLISCSI_VND_RESTORE_DEFAULTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 		return qla4xxx_restore_defaults(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	case QLISCSI_VND_GET_ACB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		return qla4xxx_bsg_get_acb(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	case QLISCSI_VND_DIAG_TEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		return qla4xxx_execute_diag_test(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		ql4_printk(KERN_ERR, ha, "%s: invalid BSG vendor command: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 			   "0x%x\n", __func__, bsg_req->msgcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		bsg_reply->result = (DID_ERROR << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 		bsg_reply->reply_payload_rcv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		bsg_job_done(bsg_job, bsg_reply->result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 			     bsg_reply->reply_payload_rcv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)  * qla4xxx_bsg_request - handle bsg request from ISCSI transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)  * @bsg_job: iscsi_bsg_job to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) int qla4xxx_bsg_request(struct bsg_job *bsg_job)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	struct iscsi_bsg_request *bsg_req = bsg_job->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	struct scsi_qla_host *ha = to_qla_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	switch (bsg_req->msgcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	case ISCSI_BSG_HST_VENDOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		return qla4xxx_process_vendor_specific(bsg_job);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 		ql4_printk(KERN_ERR, ha, "%s: invalid BSG command: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 			   __func__, bsg_req->msgcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }