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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This program is free software; you may redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mempool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "snic_disc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "snic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "snic_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* snic target types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const char * const snic_tgt_type_str[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	[SNIC_TGT_DAS] = "DAS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	[SNIC_TGT_SAN] = "SAN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static inline const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) snic_tgt_type_to_str(int typ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	return ((typ > SNIC_TGT_NONE && typ <= SNIC_TGT_SAN) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		 snic_tgt_type_str[typ] : "Unknown");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static const char * const snic_tgt_state_str[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	[SNIC_TGT_STAT_INIT]	= "INIT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	[SNIC_TGT_STAT_ONLINE]	= "ONLINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	[SNIC_TGT_STAT_OFFLINE]	= "OFFLINE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	[SNIC_TGT_STAT_DEL]	= "DELETION IN PROGRESS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) snic_tgt_state_to_str(int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return ((state >= SNIC_TGT_STAT_INIT && state <= SNIC_TGT_STAT_DEL) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		snic_tgt_state_str[state] : "UNKNOWN");
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * Initiate report_tgt req desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) snic_report_tgt_init(struct snic_host_req *req, u32 hid, u8 *buf, u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		     dma_addr_t rsp_buf_pa, ulong ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct snic_sg_desc *sgd = NULL;
^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) 	snic_io_hdr_enc(&req->hdr, SNIC_REQ_REPORT_TGTS, 0, SCSI_NO_TAG, hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			1, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	req->u.rpt_tgts.sg_cnt = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	sgd = req_to_sgl(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	sgd[0].addr = cpu_to_le64(rsp_buf_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	sgd[0].len = cpu_to_le32(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	sgd[0]._resvd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	req->u.rpt_tgts.sg_addr = cpu_to_le64((ulong)sgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * snic_queue_report_tgt_req: Queues report target request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) snic_queue_report_tgt_req(struct snic *snic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct snic_req_info *rqi = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	u32 ntgts, buf_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	u8 *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	dma_addr_t pa = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	rqi = snic_req_init(snic, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!rqi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (snic->fwinfo.max_tgts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		ntgts = min_t(u32, snic->fwinfo.max_tgts, snic->shost->max_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		ntgts = snic->shost->max_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* Allocate Response Buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	SNIC_BUG_ON(ntgts == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	buf_len = ntgts * sizeof(struct snic_tgt_id) + SNIC_SG_DESC_ALIGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	buf = kzalloc(buf_len, GFP_KERNEL|GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		snic_req_free(snic, rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		SNIC_HOST_ERR(snic->shost, "Resp Buf Alloc Failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	SNIC_BUG_ON((((unsigned long)buf) % SNIC_SG_DESC_ALIGN) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	pa = dma_map_single(&snic->pdev->dev, buf, buf_len, DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (dma_mapping_error(&snic->pdev->dev, pa)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		SNIC_HOST_ERR(snic->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			      "Rpt-tgt rspbuf %p: PCI DMA Mapping Failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			      buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		snic_req_free(snic, rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		goto error;
^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) 	SNIC_BUG_ON(pa == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	rqi->sge_va = (ulong) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	snic_report_tgt_init(rqi->req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			     snic->config.hid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			     buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			     buf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			     pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			     (ulong)rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	snic_handle_untagged_req(snic, rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ret = snic_queue_wq_desc(snic, rqi->req, rqi->req_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		dma_unmap_single(&snic->pdev->dev, pa, buf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				 DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		rqi->sge_va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		snic_release_untagged_req(snic, rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		SNIC_HOST_ERR(snic->shost, "Queuing Report Tgts Failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	SNIC_DISC_DBG(snic->shost, "Report Targets Issued.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	SNIC_HOST_ERR(snic->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		      "Queuing Report Targets Failed, err = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		      ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } /* end of snic_queue_report_tgt_req */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* call into SML */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) snic_scsi_scan_tgt(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct snic_tgt *tgt = container_of(work, struct snic_tgt, scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct Scsi_Host *shost = dev_to_shost(&tgt->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	SNIC_HOST_INFO(shost, "Scanning Target id 0x%x\n", tgt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	scsi_scan_target(&tgt->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			 tgt->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			 tgt->scsi_tgt_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			 SCAN_WILD_CARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			 SCSI_SCAN_RESCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	spin_lock_irqsave(shost->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	tgt->flags &= ~SNIC_TGT_SCAN_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	spin_unlock_irqrestore(shost->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) } /* end of snic_scsi_scan_tgt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * snic_tgt_lookup :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static struct snic_tgt *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) snic_tgt_lookup(struct snic *snic, struct snic_tgt_id *tgtid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct list_head *cur, *nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct snic_tgt *tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	list_for_each_safe(cur, nxt, &snic->disc.tgt_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		tgt = list_entry(cur, struct snic_tgt, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (tgt->id == le32_to_cpu(tgtid->tgt_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			return tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) } /* end of snic_tgt_lookup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * snic_tgt_dev_release : Called on dropping last ref for snic_tgt object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) snic_tgt_dev_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct snic_tgt *tgt = dev_to_tgt(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	SNIC_HOST_INFO(snic_tgt_to_shost(tgt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		       "Target Device ID %d (%s) Permanently Deleted.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		       tgt->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		       dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	SNIC_BUG_ON(!list_empty(&tgt->list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	kfree(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * snic_tgt_del : work function to delete snic_tgt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) snic_tgt_del(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct snic_tgt *tgt = container_of(work, struct snic_tgt, del_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct Scsi_Host *shost = snic_tgt_to_shost(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (tgt->flags & SNIC_TGT_SCAN_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		scsi_flush_work(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* Block IOs on child devices, stops new IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	scsi_target_block(&tgt->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* Cleanup IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	snic_tgt_scsi_abort_io(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* Unblock IOs now, to flush if there are any. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	scsi_target_unblock(&tgt->dev, SDEV_TRANSPORT_OFFLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	/* Delete SCSI Target and sdevs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	scsi_remove_target(&tgt->dev);  /* ?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	device_del(&tgt->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	put_device(&tgt->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) } /* end of snic_tgt_del */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* snic_tgt_create: checks for existence of snic_tgt, if it doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * it creates one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static struct snic_tgt *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct snic_tgt *tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	tgt = snic_tgt_lookup(snic, tgtid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (tgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		/* update the information if required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	tgt = kzalloc(sizeof(*tgt), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (!tgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		SNIC_HOST_ERR(snic->shost, "Failure to allocate snic_tgt.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	INIT_LIST_HEAD(&tgt->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	tgt->id = le32_to_cpu(tgtid->tgt_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	tgt->channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	SNIC_BUG_ON(le16_to_cpu(tgtid->tgt_type) > SNIC_TGT_SAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	tgt->tdata.typ = le16_to_cpu(tgtid->tgt_type);
^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) 	 * Plugging into SML Device Tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	tgt->tdata.disc_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	tgt->state = SNIC_TGT_STAT_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	device_initialize(&tgt->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	tgt->dev.parent = get_device(&snic->shost->shost_gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	tgt->dev.release = snic_tgt_dev_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	INIT_WORK(&tgt->scan_work, snic_scsi_scan_tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	INIT_WORK(&tgt->del_work, snic_tgt_del);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	switch (tgt->tdata.typ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	case SNIC_TGT_DAS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		dev_set_name(&tgt->dev, "snic_das_tgt:%d:%d-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			     snic->shost->host_no, tgt->channel, tgt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	case SNIC_TGT_SAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		dev_set_name(&tgt->dev, "snic_san_tgt:%d:%d-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			     snic->shost->host_no, tgt->channel, tgt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		SNIC_HOST_INFO(snic->shost, "Target type Unknown Detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		dev_set_name(&tgt->dev, "snic_das_tgt:%d:%d-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			     snic->shost->host_no, tgt->channel, tgt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	spin_lock_irqsave(snic->shost->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	list_add_tail(&tgt->list, &snic->disc.tgt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	tgt->scsi_tgt_id = snic->disc.nxt_tgt_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	tgt->state = SNIC_TGT_STAT_ONLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	spin_unlock_irqrestore(snic->shost->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	SNIC_HOST_INFO(snic->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		       "Tgt %d, type = %s detected. Adding..\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		       tgt->id, snic_tgt_type_to_str(tgt->tdata.typ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	ret = device_add(&tgt->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		SNIC_HOST_ERR(snic->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			      "Snic Tgt: device_add, with err = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			      ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		put_device(&snic->shost->shost_gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		kfree(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	SNIC_HOST_INFO(snic->shost, "Scanning %s.\n", dev_name(&tgt->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	scsi_queue_work(snic->shost, &tgt->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) } /* end of snic_tgt_create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Handler for discovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) snic_handle_tgt_disc(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	struct snic *snic = container_of(work, struct snic, tgt_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	struct snic_tgt_id *tgtid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	struct snic_tgt *tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	spin_lock_irqsave(&snic->snic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (snic->in_remove) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		spin_unlock_irqrestore(&snic->snic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		kfree(snic->disc.rtgt_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	spin_unlock_irqrestore(&snic->snic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	mutex_lock(&snic->disc.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	/* Discover triggered during disc in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (snic->disc.req_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		snic->disc.state = SNIC_DISC_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		snic->disc.req_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		mutex_unlock(&snic->disc.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		kfree(snic->disc.rtgt_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		snic->disc.rtgt_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		SNIC_HOST_INFO(snic->shost, "tgt_disc: Discovery restart.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		/* Start Discovery Again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		snic_disc_start(snic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	tgtid = (struct snic_tgt_id *)snic->disc.rtgt_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	SNIC_BUG_ON(snic->disc.rtgt_cnt == 0 || tgtid == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	for (i = 0; i < snic->disc.rtgt_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		tgt = snic_tgt_create(snic, &tgtid[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		if (!tgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			int buf_sz = snic->disc.rtgt_cnt * sizeof(*tgtid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			SNIC_HOST_ERR(snic->shost, "Failed to create tgt.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			snic_hex_dump("rpt_tgt_rsp", (char *)tgtid, buf_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	snic->disc.rtgt_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	snic->disc.state = SNIC_DISC_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	mutex_unlock(&snic->disc.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	SNIC_HOST_INFO(snic->shost, "Discovery Completed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	kfree(tgtid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) } /* end of snic_handle_tgt_disc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) snic_report_tgt_cmpl_handler(struct snic *snic, struct snic_fw_req *fwreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	u8 typ, cmpl_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	u32 cmnd_id, hid, tgt_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	ulong ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct snic_req_info *rqi = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct snic_tgt_id *tgtid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	snic_io_hdr_dec(&fwreq->hdr, &typ, &cmpl_stat, &cmnd_id, &hid, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	rqi = (struct snic_req_info *) ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	tgtid = (struct snic_tgt_id *) rqi->sge_va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	tgt_cnt = le32_to_cpu(fwreq->u.rpt_tgts_cmpl.tgt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (tgt_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		SNIC_HOST_ERR(snic->shost, "No Targets Found on this host.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		goto end;
^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) 	/* printing list of targets here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	SNIC_HOST_INFO(snic->shost, "Target Count = %d\n", tgt_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	SNIC_BUG_ON(tgt_cnt > snic->fwinfo.max_tgts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	for (i = 0; i < tgt_cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		SNIC_HOST_INFO(snic->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			       "Tgt id = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			       le32_to_cpu(tgtid[i].tgt_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	 * Queue work for further processing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	 * Response Buffer Memory is freed after creating targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	snic->disc.rtgt_cnt = tgt_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	snic->disc.rtgt_info = (u8 *) tgtid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	queue_work(snic_glob->event_q, &snic->tgt_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	/* Unmap Response Buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	snic_pci_unmap_rsp_buf(snic, rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		kfree(tgtid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	rqi->sge_va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	snic_release_untagged_req(snic, rqi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) } /* end of snic_report_tgt_cmpl_handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* Discovery init fn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) snic_disc_init(struct snic_disc *disc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	INIT_LIST_HEAD(&disc->tgt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	mutex_init(&disc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	disc->disc_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	disc->nxt_tgt_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	disc->state = SNIC_DISC_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	disc->req_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	disc->rtgt_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	disc->rtgt_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	disc->cb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) } /* end of snic_disc_init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* Discovery, uninit fn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) snic_disc_term(struct snic *snic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct snic_disc *disc = &snic->disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	mutex_lock(&disc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	if (disc->req_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		disc->req_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		SNIC_SCSI_DBG(snic->shost, "Terminating Discovery.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	mutex_unlock(&disc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * snic_disc_start: Discovery Start ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) snic_disc_start(struct snic *snic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	struct snic_disc *disc = &snic->disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	SNIC_SCSI_DBG(snic->shost, "Discovery Start.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	spin_lock_irqsave(&snic->snic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (snic->in_remove) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		spin_unlock_irqrestore(&snic->snic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		SNIC_ERR("snic driver removal in progress ...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	spin_unlock_irqrestore(&snic->snic_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	mutex_lock(&disc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (disc->state == SNIC_DISC_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		disc->req_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		mutex_unlock(&disc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	disc->state = SNIC_DISC_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	mutex_unlock(&disc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	ret = snic_queue_report_tgt_req(snic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		SNIC_HOST_INFO(snic->shost, "Discovery Failed, err=%d.\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) } /* end of snic_disc_start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * snic_disc_work :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) snic_handle_disc(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	struct snic *snic = container_of(work, struct snic, disc_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	SNIC_HOST_INFO(snic->shost, "disc_work: Discovery\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	ret = snic_disc_start(snic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		goto disc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) disc_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	SNIC_HOST_ERR(snic->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		      "disc_work: Discovery Failed w/ err = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		      ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) } /* end of snic_disc_work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)  * snic_tgt_del_all : cleanup all snic targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  * Called on unbinding the interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) snic_tgt_del_all(struct snic *snic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	struct snic_tgt *tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	struct list_head *cur, *nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	scsi_flush_work(snic->shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	mutex_lock(&snic->disc.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	spin_lock_irqsave(snic->shost->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	list_for_each_safe(cur, nxt, &snic->disc.tgt_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		tgt = list_entry(cur, struct snic_tgt, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		tgt->state = SNIC_TGT_STAT_DEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		list_del_init(&tgt->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		SNIC_HOST_INFO(snic->shost, "Tgt %d q'ing for del\n", tgt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		queue_work(snic_glob->event_q, &tgt->del_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	spin_unlock_irqrestore(snic->shost->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	mutex_unlock(&snic->disc.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	flush_workqueue(snic_glob->event_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) } /* end of snic_tgt_del_all */