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)  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 2014- QLogic Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * All rights reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * www.qlogic.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  bfad_im.c Linux driver IM module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include "bfad_drv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include "bfad_im.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "bfa_fcs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) BFA_TRC_FILE(LDRV, IM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) DEFINE_IDR(bfad_im_port_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) struct scsi_transport_template *bfad_im_scsi_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) static void bfad_im_itnim_work_handler(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) static int bfad_im_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) static int bfad_im_slave_alloc(struct scsi_device *sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) static void bfad_im_fc_rport_add(struct bfad_im_port_s  *im_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 				struct bfad_itnim_s *itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) bfa_cb_ioim_done(void *drv, struct bfad_ioim_s *dio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 			enum bfi_ioim_status io_status, u8 scsi_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 			int sns_len, u8 *sns_info, s32 residue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	struct bfad_s         *bfad = drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	struct bfad_itnim_data_s *itnim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	struct bfad_itnim_s *itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	u8         host_status = DID_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	switch (io_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	case BFI_IOIM_STS_OK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 		bfa_trc(bfad, scsi_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 		scsi_set_resid(cmnd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 		if (sns_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 			bfa_trc(bfad, sns_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 			if (sns_len > SCSI_SENSE_BUFFERSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 				sns_len = SCSI_SENSE_BUFFERSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 			memcpy(cmnd->sense_buffer, sns_info, sns_len);
^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) 		if (residue > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 			bfa_trc(bfad, residue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 			scsi_set_resid(cmnd, residue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			if (!sns_len && (scsi_status == SAM_STAT_GOOD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 				(scsi_bufflen(cmnd) - residue) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 					cmnd->underflow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 				bfa_trc(bfad, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 				host_status = DID_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		cmnd->result = host_status << 16 | scsi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	case BFI_IOIM_STS_TIMEDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		cmnd->result = DID_TIME_OUT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	case BFI_IOIM_STS_PATHTOV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 		cmnd->result = DID_TRANSPORT_DISRUPTED << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		cmnd->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	if (cmnd->device->host != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 		scsi_dma_unmap(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	cmnd->host_scribble = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	bfa_trc(bfad, cmnd->result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	itnim_data = cmnd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	if (itnim_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		itnim = itnim_data->itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		if (!cmnd->result && itnim &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			 (bfa_lun_queue_depth > cmnd->device->queue_depth)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			/* Queue depth adjustment for good status completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			bfad_ramp_up_qdepth(itnim, cmnd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 		} else if (cmnd->result == SAM_STAT_TASK_SET_FULL && itnim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 			/* qfull handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 			bfad_handle_qfull(itnim, cmnd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	cmnd->scsi_done(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) bfa_cb_ioim_good_comp(void *drv, struct bfad_ioim_s *dio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	struct bfad_itnim_data_s *itnim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	struct bfad_itnim_s *itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	cmnd->result = DID_OK << 16 | SCSI_STATUS_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	if (cmnd->device->host != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 		scsi_dma_unmap(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	cmnd->host_scribble = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	/* Queue depth adjustment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	if (bfa_lun_queue_depth > cmnd->device->queue_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		itnim_data = cmnd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		if (itnim_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 			itnim = itnim_data->itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 			if (itnim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 				bfad_ramp_up_qdepth(itnim, cmnd->device);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	cmnd->scsi_done(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) bfa_cb_ioim_abort(void *drv, struct bfad_ioim_s *dio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	struct bfad_s         *bfad = drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	cmnd->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	if (cmnd->device->host != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 		scsi_dma_unmap(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	bfa_trc(bfad, cmnd->result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	cmnd->host_scribble = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		   enum bfi_tskim_status tsk_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dtsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	wait_queue_head_t *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	cmnd->SCp.Status |= tsk_status << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	set_bit(IO_DONE_BIT, (unsigned long *)&cmnd->SCp.Status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	wq = (wait_queue_head_t *) cmnd->SCp.ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	cmnd->SCp.ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	if (wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		wake_up(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  *  Scsi_Host_template SCSI host template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  * Scsi_Host template entry, returns BFAD PCI info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) static const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) bfad_im_info(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	static char     bfa_buf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	struct bfad_im_port_s *im_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 			(struct bfad_im_port_s *) shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	struct bfad_s *bfad = im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	memset(bfa_buf, 0, sizeof(bfa_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	snprintf(bfa_buf, sizeof(bfa_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		"QLogic BR-series FC/FCOE Adapter, hwpath: %s driver: %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		bfad->pci_name, BFAD_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	return bfa_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)  * Scsi_Host template entry, aborts the specified SCSI command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)  * Returns: SUCCESS or FAILED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) bfad_im_abort_handler(struct scsi_cmnd *cmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	struct Scsi_Host *shost = cmnd->device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	struct bfad_im_port_s *im_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 			(struct bfad_im_port_s *) shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	struct bfad_s         *bfad = im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct bfa_ioim_s *hal_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	unsigned long   flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	u32        timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	int             rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	hal_io = (struct bfa_ioim_s *) cmnd->host_scribble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	if (!hal_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		/* IO has been completed, return success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		rc = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (hal_io->dio != (struct bfad_ioim_s *) cmnd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	bfa_trc(bfad, hal_io->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	BFA_LOG(KERN_INFO, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		"scsi%d: abort cmnd %p iotag %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		im_port->shost->host_no, cmnd, hal_io->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	(void) bfa_ioim_abort(hal_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	/* Need to wait until the command get aborted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	timeout = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	while ((struct bfa_ioim_s *) cmnd->host_scribble == hal_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		schedule_timeout(timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		if (timeout < 4 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 			timeout *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	cmnd->scsi_done(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	bfa_trc(bfad, hal_io->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	BFA_LOG(KERN_INFO, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		"scsi%d: complete abort 0x%p iotag 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		im_port->shost->host_no, cmnd, hal_io->iotag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) static bfa_status_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) bfad_im_target_reset_send(struct bfad_s *bfad, struct scsi_cmnd *cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		     struct bfad_itnim_s *itnim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	struct bfa_tskim_s *tskim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	struct bfa_itnim_s *bfa_itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	bfa_status_t    rc = BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct scsi_lun scsilun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	if (!tskim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		BFA_LOG(KERN_ERR, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 			"target reset, fail to allocate tskim\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		rc = BFA_STATUS_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	 * Set host_scribble to NULL to avoid aborting a task command if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	 * happens.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	cmnd->host_scribble = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	cmnd->SCp.Status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	 * bfa_itnim can be NULL if the port gets disconnected and the bfa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	 * and fcs layers have cleaned up their nexus with the targets and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	 * the same has not been cleaned up by the shim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	if (bfa_itnim == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		bfa_tskim_free(tskim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		BFA_LOG(KERN_ERR, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			"target reset, bfa_itnim is NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		rc = BFA_STATUS_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	memset(&scsilun, 0, sizeof(scsilun));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	bfa_tskim_start(tskim, bfa_itnim, scsilun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 			    FCP_TM_TARGET_RESET, BFAD_TARGET_RESET_TMO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * Scsi_Host template entry, resets a LUN and abort its all commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  * Returns: SUCCESS or FAILED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) bfad_im_reset_lun_handler(struct scsi_cmnd *cmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	struct Scsi_Host *shost = cmnd->device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	struct bfad_im_port_s *im_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			(struct bfad_im_port_s *) shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	struct bfad_s         *bfad = im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	struct bfa_tskim_s *tskim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	struct bfad_itnim_s   *itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	struct bfa_itnim_s *bfa_itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	int             rc = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	unsigned long   flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	enum bfi_tskim_status task_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	struct scsi_lun scsilun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	itnim = itnim_data->itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (!itnim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	if (!tskim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		BFA_LOG(KERN_ERR, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 				"LUN reset, fail to allocate tskim");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	 * Set host_scribble to NULL to avoid aborting a task command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	 * if happens.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	cmnd->host_scribble = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	cmnd->SCp.ptr = (char *)&wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	cmnd->SCp.Status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	 * bfa_itnim can be NULL if the port gets disconnected and the bfa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	 * and fcs layers have cleaned up their nexus with the targets and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	 * the same has not been cleaned up by the shim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	if (bfa_itnim == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		bfa_tskim_free(tskim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		BFA_LOG(KERN_ERR, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			"lun reset, bfa_itnim is NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	int_to_scsilun(cmnd->device->lun, &scsilun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	bfa_tskim_start(tskim, bfa_itnim, scsilun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			    FCP_TM_LUN_RESET, BFAD_LUN_RESET_TMO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	wait_event(wq, test_bit(IO_DONE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			(unsigned long *)&cmnd->SCp.Status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	task_status = cmnd->SCp.Status >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	if (task_status != BFI_TSKIM_STS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		BFA_LOG(KERN_ERR, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			"LUN reset failure, status: %d\n", task_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		rc = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) }
^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)  * Scsi_Host template entry, resets the target and abort all commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) bfad_im_reset_target_handler(struct scsi_cmnd *cmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	struct Scsi_Host *shost = cmnd->device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	struct scsi_target *starget = scsi_target(cmnd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	struct bfad_im_port_s *im_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 				(struct bfad_im_port_s *) shost->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	struct bfad_s         *bfad = im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	struct bfad_itnim_s   *itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	unsigned long   flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	u32        rc, rtn = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	enum bfi_tskim_status task_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	itnim = bfad_get_itnim(im_port, starget->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (itnim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		cmnd->SCp.ptr = (char *)&wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		rc = bfad_im_target_reset_send(bfad, cmnd, itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		if (rc == BFA_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			/* wait target reset to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			wait_event(wq, test_bit(IO_DONE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 					(unsigned long *)&cmnd->SCp.Status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			task_status = cmnd->SCp.Status >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			if (task_status != BFI_TSKIM_STS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 				BFA_LOG(KERN_ERR, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 					"target reset failure,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 					" status: %d\n", task_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 				rtn = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	return rtn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  * Scsi_Host template entry slave_destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) bfad_im_slave_destroy(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	sdev->hostdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  *  BFA FCS itnim callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)  * BFA FCS itnim alloc callback, after successful PRLI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)  * Context: Interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		    struct bfad_itnim_s **itnim_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	*itnim_drv = kzalloc(sizeof(struct bfad_itnim_s), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	if (*itnim_drv == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	(*itnim_drv)->im = bfad->im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	*itnim = &(*itnim_drv)->fcs_itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	(*itnim_drv)->state = ITNIM_STATE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	 * Initiaze the itnim_work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	INIT_WORK(&(*itnim_drv)->itnim_work, bfad_im_itnim_work_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	bfad->bfad_flags |= BFAD_RPORT_ONLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446)  * BFA FCS itnim free callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447)  * Context: Interrupt. bfad_lock is held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) bfa_fcb_itnim_free(struct bfad_s *bfad, struct bfad_itnim_s *itnim_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	struct bfad_port_s    *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	wwn_t wwpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	u32 fcid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	char wwpn_str[32], fcid_str[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	struct bfad_im_s	*im = itnim_drv->im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	/* online to free state transtion should not happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	WARN_ON(itnim_drv->state == ITNIM_STATE_ONLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	itnim_drv->queue_work = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	/* offline request is not yet done, use the same request to free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	if (itnim_drv->state == ITNIM_STATE_OFFLINE_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		itnim_drv->queue_work = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	itnim_drv->state = ITNIM_STATE_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	itnim_drv->im_port = port->im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	wwpn = bfa_fcs_itnim_get_pwwn(&itnim_drv->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	fcid = bfa_fcs_itnim_get_fcid(&itnim_drv->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	wwn2str(wwpn_str, wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	fcid2str(fcid_str, fcid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	BFA_LOG(KERN_INFO, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		"ITNIM FREE scsi%d: FCID: %s WWPN: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		port->im_port->shost->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		fcid_str, wwpn_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	/* ITNIM processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (itnim_drv->queue_work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		queue_work(im->drv_workq, &itnim_drv->itnim_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  * BFA FCS itnim online callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)  * Context: Interrupt. bfad_lock is held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	struct bfad_port_s    *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	struct bfad_im_s	*im = itnim_drv->im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	itnim_drv->bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim_drv->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	itnim_drv->state = ITNIM_STATE_ONLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	itnim_drv->queue_work = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	itnim_drv->im_port = port->im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	/* ITNIM processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	if (itnim_drv->queue_work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		queue_work(im->drv_workq, &itnim_drv->itnim_work);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  * BFA FCS itnim offline callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)  * Context: Interrupt. bfad_lock is held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) bfa_fcb_itnim_offline(struct bfad_itnim_s *itnim_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	struct bfad_port_s    *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	struct bfad_s *bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	struct bfad_im_s	*im = itnim_drv->im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if ((bfad->pport.flags & BFAD_PORT_DELETE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		 (port->flags & BFAD_PORT_DELETE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		itnim_drv->state = ITNIM_STATE_OFFLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	itnim_drv->im_port = port->im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	itnim_drv->state = ITNIM_STATE_OFFLINE_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	itnim_drv->queue_work = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	/* ITNIM processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	if (itnim_drv->queue_work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		queue_work(im->drv_workq, &itnim_drv->itnim_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  * Allocate a Scsi_Host for a port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	struct bfad_im_port_pointer *im_portp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	mutex_lock(&bfad_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	error = idr_alloc(&bfad_im_port_index, im_port, 0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		mutex_unlock(&bfad_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		printk(KERN_WARNING "idr_alloc failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	im_port->idr_id = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	mutex_unlock(&bfad_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	im_port->shost = bfad_scsi_host_alloc(im_port, bfad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	if (!im_port->shost) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		goto out_free_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	im_portp = shost_priv(im_port->shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	im_portp->p = im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	im_port->shost->unique_id = im_port->idr_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	im_port->shost->this_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	im_port->shost->max_id = MAX_FCP_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	im_port->shost->max_lun = MAX_FCP_LUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	im_port->shost->max_cmd_len = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	im_port->shost->can_queue = bfad->cfg_data.ioc_queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		im_port->shost->transportt = bfad_im_scsi_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		im_port->shost->transportt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 				bfad_im_scsi_vport_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	error = scsi_add_host_with_dma(im_port->shost, dev, &bfad->pcidev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		printk(KERN_WARNING "scsi_add_host failure %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		goto out_fc_rel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) out_fc_rel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	scsi_host_put(im_port->shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	im_port->shost = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) out_free_idr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	mutex_lock(&bfad_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	idr_remove(&bfad_im_port_index, im_port->idr_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	mutex_unlock(&bfad_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	bfa_trc(bfad, bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	BFA_LOG(KERN_INFO, bfad, bfa_log_level, "Free scsi%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			im_port->shost->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	fc_remove_host(im_port->shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	scsi_remove_host(im_port->shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	scsi_host_put(im_port->shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	mutex_lock(&bfad_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	idr_remove(&bfad_im_port_index, im_port->idr_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	mutex_unlock(&bfad_mutex);
^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 void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) bfad_im_port_delete_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	struct bfad_im_port_s *im_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		container_of(work, struct bfad_im_port_s, port_delete_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	if (im_port->port->pvb_type != BFAD_PORT_PHYS_BASE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		im_port->flags |= BFAD_PORT_DELETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		fc_vport_terminate(im_port->fc_vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) bfa_status_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	int             rc = BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	struct bfad_im_port_s *im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	im_port = kzalloc(sizeof(struct bfad_im_port_s), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	if (im_port == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		rc = BFA_STATUS_ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		goto ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	port->im_port = im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	im_port->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	im_port->bfad = bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	INIT_WORK(&im_port->port_delete_work, bfad_im_port_delete_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	INIT_LIST_HEAD(&im_port->itnim_mapped_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	INIT_LIST_HEAD(&im_port->binding_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) ext:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	struct bfad_im_port_s *im_port = port->im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	queue_work(bfad->im->drv_workq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 				&im_port->port_delete_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) bfad_im_port_clean(struct bfad_im_port_s *im_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	struct bfad_fcp_binding *bp, *bp_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	struct bfad_s *bfad =  im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	list_for_each_entry_safe(bp, bp_new, &im_port->binding_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 					list_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		list_del(&bp->list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		kfree(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	/* the itnim_mapped_list must be empty at this time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	WARN_ON(!list_empty(&im_port->itnim_mapped_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^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) static void bfad_aen_im_notify_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	struct bfad_im_s *im =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		container_of(work, struct bfad_im_s, aen_im_notify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	struct bfa_aen_entry_s *aen_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	struct bfad_s *bfad = im->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	struct Scsi_Host *shost = bfad->pport.im_port->shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	void *event_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	while (!list_empty(&bfad->active_aen_q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		spin_lock_irqsave(&bfad->bfad_aen_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		bfa_q_deq(&bfad->active_aen_q, &aen_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		spin_unlock_irqrestore(&bfad->bfad_aen_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		event_data = (char *)aen_entry + sizeof(struct list_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		fc_host_post_vendor_event(shost, fc_get_event_number(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 				sizeof(struct bfa_aen_entry_s) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 				sizeof(struct list_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 				(char *)event_data, BFAD_NL_VENDOR_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		spin_lock_irqsave(&bfad->bfad_aen_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		list_add_tail(&aen_entry->qe, &bfad->free_aen_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		spin_unlock_irqrestore(&bfad->bfad_aen_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) bfa_status_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) bfad_im_probe(struct bfad_s *bfad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	struct bfad_im_s      *im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	im = kzalloc(sizeof(struct bfad_im_s), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	if (im == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		return BFA_STATUS_ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	bfad->im = im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	im->bfad = bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (bfad_thread_workq(bfad) != BFA_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		kfree(im);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		return BFA_STATUS_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	INIT_WORK(&im->aen_im_notify_work, bfad_aen_im_notify_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	return BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) bfad_im_probe_undo(struct bfad_s *bfad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	if (bfad->im) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		bfad_destroy_workq(bfad->im);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		kfree(bfad->im);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		bfad->im = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) struct Scsi_Host *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) bfad_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	struct scsi_host_template *sht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		sht = &bfad_im_scsi_host_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		sht = &bfad_im_vport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	if (max_xfer_size != BFAD_MAX_SECTORS >> 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		sht->max_sectors = max_xfer_size << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	sht->sg_tablesize = bfad->cfg_data.io_max_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	return scsi_host_alloc(sht, sizeof(struct bfad_im_port_pointer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) bfad_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (!(im_port->flags & BFAD_PORT_DELETE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		flush_workqueue(bfad->im->drv_workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	bfad_im_scsi_host_free(im_port->bfad, im_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	bfad_im_port_clean(im_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	kfree(im_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) bfad_destroy_workq(struct bfad_im_s *im)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	if (im && im->drv_workq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		flush_workqueue(im->drv_workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		destroy_workqueue(im->drv_workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		im->drv_workq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	}
^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) bfa_status_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) bfad_thread_workq(struct bfad_s *bfad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	struct bfad_im_s      *im = bfad->im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	bfa_trc(bfad, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	snprintf(im->drv_workq_name, KOBJ_NAME_LEN, "bfad_wq_%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		 bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	im->drv_workq = create_singlethread_workqueue(im->drv_workq_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	if (!im->drv_workq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		return BFA_STATUS_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	return BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781)  * Scsi_Host template entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784)  * OS entry point to adjust the queue_depths on a per-device basis.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785)  * Called once per device during the bus scan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786)  * Return non-zero if fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) bfad_im_slave_configure(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	scsi_change_queue_depth(sdev, bfa_lun_queue_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	return 0;
^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) struct scsi_host_template bfad_im_scsi_host_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	.module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	.name = BFAD_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	.info = bfad_im_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	.queuecommand = bfad_im_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	.eh_timed_out = fc_eh_timed_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	.eh_abort_handler = bfad_im_abort_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	.eh_device_reset_handler = bfad_im_reset_lun_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	.eh_target_reset_handler = bfad_im_reset_target_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	.slave_alloc = bfad_im_slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	.slave_configure = bfad_im_slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	.slave_destroy = bfad_im_slave_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	.this_id = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	.sg_tablesize = BFAD_IO_MAX_SGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	.cmd_per_lun = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	.shost_attrs = bfad_im_host_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	.max_sectors = BFAD_MAX_SECTORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	.vendor_id = BFA_PCI_VENDOR_ID_BROCADE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) struct scsi_host_template bfad_im_vport_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	.module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	.name = BFAD_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	.info = bfad_im_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	.queuecommand = bfad_im_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	.eh_timed_out = fc_eh_timed_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	.eh_abort_handler = bfad_im_abort_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	.eh_device_reset_handler = bfad_im_reset_lun_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	.eh_target_reset_handler = bfad_im_reset_target_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	.slave_alloc = bfad_im_slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	.slave_configure = bfad_im_slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	.slave_destroy = bfad_im_slave_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	.this_id = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	.sg_tablesize = BFAD_IO_MAX_SGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	.cmd_per_lun = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	.shost_attrs = bfad_im_vport_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	.max_sectors = BFAD_MAX_SECTORS,
^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) bfa_status_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) bfad_im_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	bfad_im_scsi_transport_template =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		fc_attach_transport(&bfad_im_fc_function_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (!bfad_im_scsi_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		return BFA_STATUS_ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	bfad_im_scsi_vport_transport_template =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		fc_attach_transport(&bfad_im_vport_fc_function_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	if (!bfad_im_scsi_vport_transport_template) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		fc_release_transport(bfad_im_scsi_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		return BFA_STATUS_ENOMEM;
^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) 	return BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) bfad_im_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	if (bfad_im_scsi_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		fc_release_transport(bfad_im_scsi_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	if (bfad_im_scsi_vport_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		fc_release_transport(bfad_im_scsi_vport_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	idr_destroy(&bfad_im_port_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	struct scsi_device *tmp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	if (((jiffies - itnim->last_ramp_up_time) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		BFA_QUEUE_FULL_RAMP_UP_TIME * HZ) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		((jiffies - itnim->last_queue_full_time) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		BFA_QUEUE_FULL_RAMP_UP_TIME * HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		shost_for_each_device(tmp_sdev, sdev->host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 				if (tmp_sdev->id != sdev->id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 				scsi_change_queue_depth(tmp_sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 					tmp_sdev->queue_depth + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 				itnim->last_ramp_up_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct scsi_device *tmp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	itnim->last_queue_full_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	shost_for_each_device(tmp_sdev, sdev->host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		if (tmp_sdev->id != sdev->id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
^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) struct bfad_itnim_s *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) bfad_get_itnim(struct bfad_im_port_s *im_port, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	struct bfad_itnim_s   *itnim = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	/* Search the mapped list for this target ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		if (id == itnim->scsi_tgt_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 			return itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  * Function is invoked from the SCSI Host Template slave_alloc() entry point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)  * Has the logic to query the LUN Mask database to check if this LUN needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)  * be made visible to the SCSI mid-layer or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923)  * Returns BFA_STATUS_OK if this LUN needs to be added to the OS stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924)  * Returns -ENXIO to notify SCSI mid-layer to not add this LUN to the OS stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) bfad_im_check_if_make_lun_visible(struct scsi_device *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 				  struct fc_rport *rport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	struct bfad_itnim_data_s *itnim_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 				(struct bfad_itnim_data_s *) rport->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	struct bfa_s *bfa = itnim_data->itnim->bfa_itnim->bfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	struct bfa_rport_s *bfa_rport = itnim_data->itnim->bfa_itnim->rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	struct bfa_lun_mask_s *lun_list = bfa_get_lun_mask_list(bfa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	int i = 0, ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		if (lun_list[i].state == BFA_IOIM_LUN_MASK_ACTIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		    scsilun_to_int(&lun_list[i].lun) == sdev->lun &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		    lun_list[i].rp_tag == bfa_rport->rport_tag &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		    lun_list[i].lp_tag == (u8)bfa_rport->rport_info.lp_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 			ret = BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950)  * Scsi_Host template entry slave_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) bfad_im_slave_alloc(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	struct bfad_itnim_data_s *itnim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	struct bfa_s *bfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	if (!rport || fc_remote_port_chkready(rport))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	itnim_data = (struct bfad_itnim_data_s *) rport->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	bfa = itnim_data->itnim->bfa_itnim->bfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		 * We should not mask LUN 0 - since this will translate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		 * to no LUN / TARGET for SCSI ml resulting no scan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		if (sdev->lun == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			sdev->sdev_bflags |= BLIST_NOREPORTLUN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 					     BLIST_SPARSELUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		 * Query LUN Mask configuration - to expose this LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		 * to the SCSI mid-layer or to mask it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		if (bfad_im_check_if_make_lun_visible(sdev, rport) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 							BFA_STATUS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	sdev->hostdata = rport->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) bfad_im_supported_speeds(struct bfa_s *bfa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	struct bfa_ioc_attr_s *ioc_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	u32 supported_speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	ioc_attr = kzalloc(sizeof(struct bfa_ioc_attr_s), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	if (!ioc_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	bfa_ioc_get_attr(&bfa->ioc, ioc_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_16GBPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		supported_speed |=  FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 				FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	else if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_8GBPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		if (ioc_attr->adapter_attr.is_mezz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			supported_speed |= FC_PORTSPEED_8GBIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 				FC_PORTSPEED_4GBIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 				FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			supported_speed |= FC_PORTSPEED_8GBIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 				FC_PORTSPEED_4GBIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 				FC_PORTSPEED_2GBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	} else if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_4GBPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		supported_speed |=  FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 				FC_PORTSPEED_1GBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	} else if (ioc_attr->adapter_attr.max_speed == BFA_PORT_SPEED_10GBPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		supported_speed |= FC_PORTSPEED_10GBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	kfree(ioc_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	return supported_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) bfad_fc_host_init(struct bfad_im_port_s *im_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	struct Scsi_Host *host = im_port->shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	struct bfad_s         *bfad = im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	struct bfad_port_s    *port = im_port->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	char symname[BFA_SYMNAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	fc_host_node_name(host) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		cpu_to_be64((bfa_fcs_lport_get_nwwn(port->fcs_port)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	fc_host_port_name(host) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		cpu_to_be64((bfa_fcs_lport_get_pwwn(port->fcs_port)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	fc_host_supported_classes(host) = FC_COS_CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	memset(fc_host_supported_fc4s(host), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	       sizeof(fc_host_supported_fc4s(host)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		/* For FCP type 0x08 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		fc_host_supported_fc4s(host)[2] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	/* For fibre channel services type 0x20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	fc_host_supported_fc4s(host)[7] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	strlcpy(symname, bfad->bfa_fcs.fabric.bport.port_cfg.sym_name.symname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		BFA_SYMNAME_MAXLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	sprintf(fc_host_symbolic_name(host), "%s", symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	fc_host_supported_speeds(host) = bfad_im_supported_speeds(&bfad->bfa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	fc_host_maxframe_size(host) = fcport->cfg.maxfrsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	struct fc_rport_identifiers rport_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	struct fc_rport *fc_rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	struct bfad_itnim_data_s *itnim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	rport_ids.node_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		cpu_to_be64(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	rport_ids.port_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		cpu_to_be64(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	rport_ids.port_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		bfa_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	itnim->fc_rport = fc_rport =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		fc_remote_port_add(im_port->shost, 0, &rport_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (!fc_rport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	fc_rport->maxframe_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		bfa_fcs_itnim_get_maxfrsize(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	fc_rport->supported_classes = bfa_fcs_itnim_get_cos(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	itnim_data = fc_rport->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	itnim_data->itnim = itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		fc_remote_port_rolechg(fc_rport, rport_ids.roles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	if ((fc_rport->scsi_target_id != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	    && (fc_rport->scsi_target_id < MAX_FCP_TARGET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		itnim->scsi_tgt_id = fc_rport->scsi_target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	itnim->channel = fc_rport->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)  * Work queue handler using FC transport service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) * Context: kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) bfad_im_itnim_work_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	struct bfad_itnim_s   *itnim = container_of(work, struct bfad_itnim_s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 							itnim_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	struct bfad_im_s      *im = itnim->im;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	struct bfad_s         *bfad = im->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	struct bfad_im_port_s *im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	unsigned long   flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	struct fc_rport *fc_rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	wwn_t wwpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	u32 fcid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	char wwpn_str[32], fcid_str[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	im_port = itnim->im_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	bfa_trc(bfad, itnim->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	switch (itnim->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	case ITNIM_STATE_ONLINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 		if (!itnim->fc_rport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			bfad_im_fc_rport_add(im_port, itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 			spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 			wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 			wwn2str(wwpn_str, wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			fcid2str(fcid_str, fcid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			list_add_tail(&itnim->list_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 				&im_port->itnim_mapped_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			BFA_LOG(KERN_INFO, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 				"ITNIM ONLINE Target: %d:0:%d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 				"FCID: %s WWPN: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 				im_port->shost->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 				itnim->scsi_tgt_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 				fcid_str, wwpn_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 				"%s: itnim %llx is already in online state\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 				__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 				bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	case ITNIM_STATE_OFFLINE_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		itnim->state = ITNIM_STATE_OFFLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		if (itnim->fc_rport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 			fc_rport = itnim->fc_rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			((struct bfad_itnim_data_s *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 				fc_rport->dd_data)->itnim = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 			itnim->fc_rport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 			if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 				spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 				fc_rport->dev_loss_tmo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 					bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 				fc_remote_port_delete(fc_rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 				spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 			fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			wwn2str(wwpn_str, wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			fcid2str(fcid_str, fcid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 			list_del(&itnim->list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 			BFA_LOG(KERN_INFO, bfad, bfa_log_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 				"ITNIM OFFLINE Target: %d:0:%d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 				"FCID: %s WWPN: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 				im_port->shost->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 				itnim->scsi_tgt_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 				fcid_str, wwpn_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	case ITNIM_STATE_FREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		if (itnim->fc_rport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 			fc_rport = itnim->fc_rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 			((struct bfad_itnim_data_s *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 				fc_rport->dd_data)->itnim = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 			itnim->fc_rport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 			if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 				spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 				fc_rport->dev_loss_tmo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 					bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 				fc_remote_port_delete(fc_rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 				spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 			list_del(&itnim->list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		kfree(itnim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)  * Scsi_Host template entry, queue a SCSI command to the BFAD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) bfad_im_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	struct bfad_im_port_s *im_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		(struct bfad_im_port_s *) cmnd->device->host->hostdata[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	struct bfad_s         *bfad = im_port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	struct bfad_itnim_s   *itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	struct bfa_ioim_s *hal_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	unsigned long   flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	int             rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	int       sg_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	rc = fc_remote_port_chkready(rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		cmnd->result = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		done(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	if (bfad->bfad_flags & BFAD_EEH_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		if (bfad->bfad_flags & BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			cmnd->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			cmnd->result = DID_REQUEUE << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		done(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	sg_cnt = scsi_dma_map(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	if (sg_cnt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	cmnd->scsi_done = done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	if (!(bfad->bfad_flags & BFAD_HAL_START_DONE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			"bfad%d, queuecommand %p %x failed, BFA stopped\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		       bfad->inst_no, cmnd, cmnd->cmnd[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		cmnd->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		goto out_fail_cmd;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	itnim = itnim_data->itnim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (!itnim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		cmnd->result = DID_IMM_RETRY << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		goto out_fail_cmd;
^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) 	hal_io = bfa_ioim_alloc(&bfad->bfa, (struct bfad_ioim_s *) cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 				    itnim->bfa_itnim, sg_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	if (!hal_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		printk(KERN_WARNING "hal_io failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		scsi_dma_unmap(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	cmnd->host_scribble = (char *)hal_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	bfa_ioim_start(hal_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) out_fail_cmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	scsi_dma_unmap(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	if (done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		done(cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static DEF_SCSI_QCMD(bfad_im_queuecommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) bfad_rport_online_wait(struct bfad_s *bfad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	int rport_delay = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	for (i = 0; !(bfad->bfad_flags & BFAD_PORT_ONLINE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		&& i < bfa_linkup_delay; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		schedule_timeout(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	if (bfad->bfad_flags & BFAD_PORT_ONLINE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		rport_delay = rport_delay < bfa_linkup_delay ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 			rport_delay : bfa_linkup_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		for (i = 0; !(bfad->bfad_flags & BFAD_RPORT_ONLINE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			&& i < rport_delay; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 			set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			schedule_timeout(HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		if (rport_delay > 0 && (bfad->bfad_flags & BFAD_RPORT_ONLINE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 			schedule_timeout(rport_delay * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) bfad_get_linkup_delay(struct bfad_s *bfad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	u8		nwwns = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	wwn_t		wwns[BFA_PREBOOT_BOOTLUN_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	int		linkup_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	 * Querying for the boot target port wwns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	 * -- read from boot information in flash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	 * If nwwns > 0 => boot over SAN and set linkup_delay = 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	 * else => local boot machine set linkup_delay = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	bfa_iocfc_get_bootwwns(&bfad->bfa, &nwwns, wwns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	if (nwwns > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		/* If Boot over SAN set linkup_delay = 30sec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		linkup_delay = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		/* If local boot; no linkup_delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		linkup_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	return linkup_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }