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)  * This file is part of the Emulex Linux Device Driver for Enterprise iSCSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Host Bus Adapters. Refer to the README file included with this package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * for driver version and adapter compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 2018 Broadcom. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Contact Information:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * linux-drivers@broadcom.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <scsi/libiscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <scsi/scsi_transport_iscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <scsi/scsi_netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include "be_iscsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) extern struct iscsi_transport beiscsi_iscsi_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * beiscsi_session_create - creates a new iscsi session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * @ep: pointer to iscsi ep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * @cmds_max: max commands supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * @qdepth: max queue depth supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * @initial_cmdsn: initial iscsi CMDSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 						 u16 cmds_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 						 u16 qdepth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 						 u32 initial_cmdsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	struct beiscsi_endpoint *beiscsi_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	struct iscsi_cls_session *cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	struct beiscsi_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	struct beiscsi_session *beiscsi_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	struct beiscsi_io_task *io_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 		pr_err("beiscsi_session_create: invalid ep\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	phba = beiscsi_ep->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		    "BS_%d : In beiscsi_session_create\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 			    "BS_%d : Cannot handle %d cmds."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 			    "Max cmds per session supported is %d. Using %d."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 			    "\n", cmds_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 			    beiscsi_ep->phba->params.wrbs_per_cxn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 			    beiscsi_ep->phba->params.wrbs_per_cxn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	shost = phba->shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 					  shost, cmds_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 					  sizeof(*beiscsi_sess),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 					  sizeof(*io_task),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 					  initial_cmdsn, ISCSI_MAX_TARGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	if (!cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	beiscsi_sess = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	beiscsi_sess->bhs_pool =  dma_pool_create("beiscsi_bhs_pool",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 						   &phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 						   sizeof(struct be_cmd_bhs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 						   64, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	if (!beiscsi_sess->bhs_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 		goto destroy_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	return cls_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) destroy_sess:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	iscsi_session_teardown(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	return NULL;
^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)  * beiscsi_session_destroy - destroys iscsi session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  * @cls_session:	pointer to iscsi cls session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  * Destroys iSCSI session instance and releases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  * resources allocated for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	struct iscsi_session *sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	struct beiscsi_session *beiscsi_sess = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	printk(KERN_INFO "In beiscsi_session_destroy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	dma_pool_destroy(beiscsi_sess->bhs_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	iscsi_session_teardown(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * beiscsi_session_fail(): Closing session with appropriate error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  * @cls_session: ptr to session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) void beiscsi_session_fail(struct iscsi_cls_session *cls_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^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)  * beiscsi_conn_create - create an instance of iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  * @cls_session: ptr to iscsi_cls_session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  * @cid: iscsi cid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) struct iscsi_cls_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	struct beiscsi_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	struct iscsi_cls_conn *cls_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	struct beiscsi_conn *beiscsi_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct iscsi_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct iscsi_session *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	struct beiscsi_session *beiscsi_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	shost = iscsi_session_to_shost(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		    "BS_%d : In beiscsi_conn_create ,cid"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		    "from iscsi layer=%d\n", cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	if (!cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	beiscsi_conn = conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	beiscsi_conn->ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	beiscsi_conn->phba = phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	beiscsi_conn->conn = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	sess = cls_session->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	beiscsi_sess = sess->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	beiscsi_conn->beiscsi_sess = beiscsi_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	return cls_conn;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  * @cls_session: pointer to iscsi cls session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  * @cls_conn: pointer to iscsi cls conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  * @transport_fd: EP handle(64 bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  * @is_leading: indicate if this is the session leading connection (MCS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * This function binds the TCP Conn with iSCSI Connection and Session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		      struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		      u64 transport_fd, int is_leading)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	struct beiscsi_conn *beiscsi_conn = conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	struct hwi_controller *phwi_ctrlr = phba->phwi_ctrlr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	struct hwi_wrb_context *pwrb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	struct beiscsi_endpoint *beiscsi_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	struct iscsi_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	uint16_t cri_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	ep = iscsi_lookup_endpoint(transport_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	if (!ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	if (beiscsi_ep->phba != phba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 			    "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			    beiscsi_ep->phba, phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	if (phba->conn_table[cri_index]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		if (beiscsi_conn != phba->conn_table[cri_index] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		    beiscsi_ep != phba->conn_table[cri_index]->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 				      "BS_%d : conn_table not empty at %u: cid %u conn %p:%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 				      cri_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 				      beiscsi_ep->ep_cid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 				      beiscsi_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 				      phba->conn_table[cri_index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	beiscsi_conn->ep = beiscsi_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	beiscsi_ep->conn = beiscsi_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	 * Each connection is associated with a WRBQ kept in wrb_context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	 * Store doorbell offset for transmit path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	beiscsi_conn->doorbell_offset = pwrb_context->doorbell_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		    "BS_%d : cid %d phba->conn_table[%u]=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		    beiscsi_ep->ep_cid, cri_index, beiscsi_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	phba->conn_table[cri_index] = beiscsi_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	if (phba->ipv4_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	phba->ipv4_iface = iscsi_create_iface(phba->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 					      &beiscsi_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 					      ISCSI_IFACE_TYPE_IPV4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 					      0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (!phba->ipv4_iface) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 			    "BS_%d : Could not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			    "create default IPv4 address.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) static int beiscsi_iface_create_ipv6(struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	if (phba->ipv6_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	phba->ipv6_iface = iscsi_create_iface(phba->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 					      &beiscsi_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 					      ISCSI_IFACE_TYPE_IPV6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 					      0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	if (!phba->ipv6_iface) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 			    "BS_%d : Could not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 			    "create default IPv6 address.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) void beiscsi_iface_create_default(struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	struct be_cmd_get_if_info_resp *if_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	if (!beiscsi_if_get_info(phba, BEISCSI_IP_TYPE_V4, &if_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		beiscsi_iface_create_ipv4(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		kfree(if_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	if (!beiscsi_if_get_info(phba, BEISCSI_IP_TYPE_V6, &if_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		beiscsi_iface_create_ipv6(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		kfree(if_info);
^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) void beiscsi_iface_destroy_default(struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	if (phba->ipv6_iface) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		iscsi_destroy_iface(phba->ipv6_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		phba->ipv6_iface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	if (phba->ipv4_iface) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		iscsi_destroy_iface(phba->ipv4_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		phba->ipv4_iface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  * beiscsi_set_vlan_tag()- Set the VLAN TAG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)  * @shost: Scsi Host for the driver instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)  * @iface_param: Interface paramters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)  * Set the VLAN TAG for the adapter or disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)  * the VLAN config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305)  * returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)  *	Success: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)  *	Failure: Non-Zero Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) beiscsi_iface_config_vlan(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			  struct iscsi_iface_param_info *iface_param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	int ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	switch (iface_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		if (iface_param->value[0] != ISCSI_VLAN_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			ret = beiscsi_if_set_vlan(phba, BEISCSI_VLAN_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	case ISCSI_NET_PARAM_VLAN_TAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		ret = beiscsi_if_set_vlan(phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 					  *((uint16_t *)iface_param->value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) beiscsi_iface_config_ipv4(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			  struct iscsi_iface_param_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			  void *data, uint32_t dt_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	u8 *ip = NULL, *subnet = NULL, *gw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	struct nlattr *nla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	int ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	/* Check the param */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	switch (info->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		if (info->value[0] == ISCSI_IFACE_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			ret = beiscsi_iface_create_ipv4(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			iscsi_destroy_iface(phba->ipv4_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			phba->ipv4_iface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	case ISCSI_NET_PARAM_IPV4_GW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		gw = info->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		ret = beiscsi_if_set_gw(phba, BEISCSI_IP_TYPE_V4, gw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		if (info->value[0] == ISCSI_BOOTPROTO_DHCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 			ret = beiscsi_if_en_dhcp(phba, BEISCSI_IP_TYPE_V4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		else if (info->value[0] == ISCSI_BOOTPROTO_STATIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			/* release DHCP IP address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 						   NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 				    "BS_%d : Invalid BOOTPROTO: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 				    info->value[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		ip = info->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		if (nla) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			info = nla_data(nla);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			subnet = info->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 					   ip, subnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		 * OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR ioctl needs IP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		 * and subnet both. Find IP to be applied for this subnet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		subnet = info->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		if (nla) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			info = nla_data(nla);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			ip = info->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 					   ip, subnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) beiscsi_iface_config_ipv6(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			  struct iscsi_iface_param_info *iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 			  void *data, uint32_t dt_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	int ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	switch (iface_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			ret = beiscsi_iface_create_ipv6(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			iscsi_destroy_iface(phba->ipv6_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			phba->ipv6_iface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 					   iface_param->value, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	return ret;
^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) int beiscsi_iface_set_param(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			    void *data, uint32_t dt_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct iscsi_iface_param_info *iface_param = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	struct nlattr *attrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	uint32_t rm_len = dt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	/* update interface_handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	ret = beiscsi_if_get_handle(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 			    "BS_%d : Getting Interface Handle Failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		return ret;
^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) 	nla_for_each_attr(attrib, data, dt_len, rm_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		iface_param = nla_data(attrib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		if (iface_param->param_type != ISCSI_NET_PARAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		 * BE2ISCSI only supports 1 interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		if (iface_param->iface_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 				    "BS_%d : Invalid iface_num %d."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				    "Only iface_num 0 is supported.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 				    iface_param->iface_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			    "BS_%d : %s.0 set param %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			    (iface_param->iface_type == ISCSI_IFACE_TYPE_IPV4) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			    "ipv4" : "ipv6", iface_param->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		switch (iface_param->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		case ISCSI_NET_PARAM_VLAN_TAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			ret = beiscsi_iface_config_vlan(shost, iface_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			switch (iface_param->iface_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			case ISCSI_IFACE_TYPE_IPV4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 				ret = beiscsi_iface_config_ipv4(shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 								iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 								data, dt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			case ISCSI_IFACE_TYPE_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 				ret = beiscsi_iface_config_ipv6(shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 								iface_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 								data, dt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		if (ret == -EPERM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 				      "BS_%d : %s.0 set param %d not permitted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 				      (iface_param->iface_type ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				       ISCSI_IFACE_TYPE_IPV4) ? "ipv4" : "ipv6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 				      iface_param->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	return ret;
^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) static int __beiscsi_iface_get_param(struct beiscsi_hba *phba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 				     struct iscsi_iface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 				     int param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	struct be_cmd_get_if_info_resp *if_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	int len, ip_type = BEISCSI_IP_TYPE_V4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		ip_type = BEISCSI_IP_TYPE_V6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	len = beiscsi_if_get_info(phba, ip_type, &if_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	if (len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		len = sprintf(buf, "%pI4\n", if_info->ip_addr.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		len = sprintf(buf, "%pI6\n", if_info->ip_addr.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		if (!if_info->dhcp_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			len = sprintf(buf, "static\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			len = sprintf(buf, "dhcp\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		len = sprintf(buf, "%pI4\n", if_info->ip_addr.subnet_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		len = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			      (if_info->vlan_priority == BEISCSI_VLAN_DISABLE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			      "disable" : "enable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	case ISCSI_NET_PARAM_VLAN_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			len = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 				      (if_info->vlan_priority &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 				       ISCSI_MAX_VLAN_ID));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	case ISCSI_NET_PARAM_VLAN_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			len = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 			len = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 				      ((if_info->vlan_priority >> 13) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 				       ISCSI_MAX_VLAN_PRIORITY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	kfree(if_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) int beiscsi_iface_get_param(struct iscsi_iface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			    enum iscsi_param_type param_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 			    int param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	struct be_cmd_get_def_gateway_resp gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	int len = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	if (param_type != ISCSI_NET_PARAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	case ISCSI_NET_PARAM_VLAN_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	case ISCSI_NET_PARAM_VLAN_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		len = __beiscsi_iface_get_param(phba, iface, param, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			len = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 				      phba->ipv4_iface ? "enable" : "disable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			len = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 				      phba->ipv6_iface ? "enable" : "disable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	case ISCSI_NET_PARAM_IPV4_GW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		memset(&gateway, 0, sizeof(gateway));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		len = beiscsi_if_get_gw(phba, BEISCSI_IP_TYPE_V4, &gateway);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610)  * beiscsi_ep_get_param - get the iscsi parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611)  * @ep: pointer to iscsi ep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612)  * @param: parameter type identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)  * @buf: buffer pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615)  * returns iscsi parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 			   enum iscsi_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	beiscsi_log(beiscsi_ep->phba, KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		    BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		    "BS_%d : In beiscsi_ep_get_param,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		    " param= %d\n", param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	case ISCSI_PARAM_CONN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	case ISCSI_PARAM_CONN_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		if (beiscsi_ep->ip_type == BEISCSI_IP_TYPE_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		len = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		      enum iscsi_param param, char *buf, int buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	struct beiscsi_hba *phba = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		    "BS_%d : In beiscsi_conn_set_param,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		    " param= %d\n", param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	ret = iscsi_set_param(cls_conn, param, buf, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	 * If userspace tried to set the value to higher than we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	 * support override here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	case ISCSI_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		if (session->first_burst > 8192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 			session->first_burst = 8192;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	case ISCSI_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		if (conn->max_recv_dlength > 65536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			conn->max_recv_dlength = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	case ISCSI_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		if (session->max_burst > 262144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			session->max_burst = 262144;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	case ISCSI_PARAM_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		if (conn->max_xmit_dlength > 65536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			conn->max_xmit_dlength = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689)  * beiscsi_get_port_state - Get the Port State
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690)  * @shost : pointer to scsi_host structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) static void beiscsi_get_port_state(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	struct iscsi_cls_host *ihost = shost->shost_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	ihost->port_state = test_bit(BEISCSI_HBA_LINK_UP, &phba->state) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)  * beiscsi_get_port_speed  - Get the Port Speed from Adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  * @shost : pointer to scsi_host structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) static void beiscsi_get_port_speed(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	struct iscsi_cls_host *ihost = shost->shost_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	switch (phba->port_speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	case BE2ISCSI_LINK_SPEED_10MBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	case BE2ISCSI_LINK_SPEED_100MBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		ihost->port_speed = ISCSI_PORT_SPEED_100MBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	case BE2ISCSI_LINK_SPEED_1GBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	case BE2ISCSI_LINK_SPEED_10GBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	case BE2ISCSI_LINK_SPEED_25GBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		ihost->port_speed = ISCSI_PORT_SPEED_25GBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	case BE2ISCSI_LINK_SPEED_40GBPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		ihost->port_speed = ISCSI_PORT_SPEED_40GBPS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737)  * beiscsi_get_host_param - get the iscsi parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738)  * @shost: pointer to scsi_host structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739)  * @param: parameter type identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)  * @buf: buffer pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) int beiscsi_get_host_param(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			   enum iscsi_host_param param, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		    "BS_%d : In beiscsi_get_host_param, param = %d\n", param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	case ISCSI_HOST_PARAM_HWADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		status = beiscsi_get_macaddr(buf, phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 				    "BS_%d : beiscsi_get_macaddr Failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	case ISCSI_HOST_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		/* try fetching user configured name first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		status = beiscsi_get_initiator_name(phba, buf, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 			status = beiscsi_get_initiator_name(phba, buf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 			if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 				beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 					    "BS_%d : Retrieving Initiator Name Failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 				status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	case ISCSI_HOST_PARAM_PORT_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		beiscsi_get_port_state(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	case ISCSI_HOST_PARAM_PORT_SPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		beiscsi_get_port_speed(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		return iscsi_host_get_param(shost, param, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	struct be_cmd_get_nic_conf_resp resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (phba->mac_addr_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	memset(&resp, 0, sizeof(resp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	rc = mgmt_get_nic_conf(phba, &resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	phba->mac_addr_set = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)  * beiscsi_conn_get_stats - get the iscsi stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  * @cls_conn: pointer to iscsi cls conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)  * @stats: pointer to iscsi_stats structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815)  * returns iscsi stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			    struct iscsi_stats *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	struct beiscsi_hba *phba = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		    "BS_%d : In beiscsi_conn_get_stats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	stats->txdata_octets = conn->txdata_octets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	stats->rxdata_octets = conn->rxdata_octets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	stats->dataout_pdus = conn->dataout_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	stats->datain_pdus = conn->datain_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	stats->r2t_pdus = conn->r2t_pdus_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	stats->digest_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	stats->timeout_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	stats->custom_length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	strcpy(stats->custom[0].desc, "eh_abort_cnt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	stats->custom[0].value = conn->eh_abort_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844)  * beiscsi_set_params_for_offld - get the parameters for offload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845)  * @beiscsi_conn: pointer to beiscsi_conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846)  * @params: pointer to offload_params structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) static void  beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 					  struct beiscsi_offload_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	struct iscsi_conn *conn = beiscsi_conn->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		      params, session->max_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		      max_send_data_segment_length, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		      conn->max_xmit_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		      params, session->first_burst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		      session->erl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		      conn->datadgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		      conn->hdrdgst_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		      session->initial_r2t_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		      session->imm_data_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		      data_seq_inorder, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		      session->dataseq_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		      pdu_seq_inorder, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		      session->pdu_inorder_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_r2t, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		      session->max_r2t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		      (conn->exp_statsn - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	AMAP_SET_BITS(struct amap_beiscsi_offload_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		      max_recv_data_segment_length, params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		      conn->max_recv_dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^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)  * beiscsi_conn_start - offload of session to chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889)  * @cls_conn: pointer to beiscsi_conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct iscsi_conn *conn = cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct beiscsi_conn *beiscsi_conn = conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	struct beiscsi_endpoint *beiscsi_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	struct beiscsi_offload_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	struct beiscsi_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	beiscsi_log(beiscsi_conn->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		    "BS_%d : In beiscsi_conn_start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	memset(&params, 0, sizeof(struct beiscsi_offload_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	beiscsi_ep = beiscsi_conn->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	if (!beiscsi_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		beiscsi_log(beiscsi_conn->phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			    BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 			    "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	beiscsi_conn->login_in_progress = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	beiscsi_set_params_for_offld(beiscsi_conn, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	beiscsi_offload_connection(beiscsi_conn, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	iscsi_conn_start(cls_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924)  * beiscsi_get_cid - Allocate a cid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925)  * @phba: The phba instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) static int beiscsi_get_cid(struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	uint16_t cid_avlbl_ulp0, cid_avlbl_ulp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	unsigned short cid, cid_from_ulp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	struct ulp_cid_info *cid_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	/* Find the ULP which has more CID available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	cid_avlbl_ulp0 = (phba->cid_array_info[BEISCSI_ULP0]) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			  BEISCSI_ULP0_AVLBL_CID(phba) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	cid_avlbl_ulp1 = (phba->cid_array_info[BEISCSI_ULP1]) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 			  BEISCSI_ULP1_AVLBL_CID(phba) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	cid_from_ulp = (cid_avlbl_ulp0 > cid_avlbl_ulp1) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			BEISCSI_ULP0 : BEISCSI_ULP1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	 * If iSCSI protocol is loaded only on ULP 0, and when cid_avlbl_ulp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	 * is ZERO for both, ULP 1 is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	 * Check if ULP is loaded before getting new CID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	if (!test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		return BE_INVALID_CID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	cid_info = phba->cid_array_info[cid_from_ulp];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	cid = cid_info->cid_array[cid_info->cid_alloc];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	if (!cid_info->avlbl_cids || cid == BE_INVALID_CID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 				"BS_%d : failed to get cid: available %u:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 				cid_info->avlbl_cids, cid_info->cid_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		return BE_INVALID_CID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	/* empty the slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	cid_info->cid_array[cid_info->cid_alloc++] = BE_INVALID_CID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(phba, cid_from_ulp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		cid_info->cid_alloc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	cid_info->avlbl_cids--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	return cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)  * beiscsi_put_cid - Free the cid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)  * @phba: The phba for which the cid is being freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  * @cid: The cid to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	struct hwi_wrb_context *pwrb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	struct hwi_controller *phwi_ctrlr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct ulp_cid_info *cid_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	uint16_t cid_post_ulp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	phwi_ctrlr = phba->phwi_ctrlr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	cid_post_ulp = pwrb_context->ulp_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	cid_info = phba->cid_array_info[cid_post_ulp];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	/* fill only in empty slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	if (cid_info->cid_array[cid_info->cid_free] != BE_INVALID_CID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			      "BS_%d : failed to put cid %u: available %u:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			      cid, cid_info->avlbl_cids, cid_info->cid_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	cid_info->cid_array[cid_info->cid_free++] = cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	if (cid_info->cid_free == BEISCSI_GET_CID_COUNT(phba, cid_post_ulp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		cid_info->cid_free = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	cid_info->avlbl_cids++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996)  * beiscsi_free_ep - free endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997)  * @beiscsi_ep: pointer to device endpoint struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	struct beiscsi_hba *phba = beiscsi_ep->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	struct beiscsi_conn *beiscsi_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	beiscsi_ep->phba = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	/* clear this to track freeing in beiscsi_ep_disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	phba->ep_array[BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid)] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	 * Check if any connection resource allocated by driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 * is to be freed.This case occurs when target redirection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * or connection retry is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	if (!beiscsi_ep->conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	beiscsi_conn = beiscsi_ep->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	 * Break ep->conn link here so that completions after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	 * this are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	beiscsi_ep->conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	if (beiscsi_conn->login_in_progress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		beiscsi_free_mgmt_task_handles(beiscsi_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 					       beiscsi_conn->task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		beiscsi_conn->login_in_progress = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)  * beiscsi_open_conn - Ask FW to open a TCP connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)  * @ep: pointer to device endpoint struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)  * @src_addr: The source IP address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)  * @dst_addr: The Destination  IP address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)  * @non_blocking: blocking or non-blocking call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)  * Asks the FW to open a TCP connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static int beiscsi_open_conn(struct iscsi_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			     struct sockaddr *src_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			     struct sockaddr *dst_addr, int non_blocking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	struct beiscsi_hba *phba = beiscsi_ep->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	struct tcp_connect_and_offload_out *ptcpcnct_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	struct be_dma_mem nonemb_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	unsigned int tag, req_memsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		    "BS_%d : In beiscsi_open_conn\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (beiscsi_ep->ep_cid == BE_INVALID_CID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			    "BS_%d : No free cid available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		    "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		    beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	phba->ep_array[BE_GET_CRI_FROM_CID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		       (beiscsi_ep->ep_cid)] = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	beiscsi_ep->cid_vld = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	if (is_chip_be2_be3r(phba))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		req_memsize = sizeof(struct tcp_connect_and_offload_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		req_memsize = sizeof(struct tcp_connect_and_offload_in_v1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 				req_memsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 				&nonemb_cmd.dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	if (nonemb_cmd.va == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 			    "BS_%d : Failed to allocate memory for"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 			    " mgmt_open_connection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		beiscsi_free_ep(beiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	nonemb_cmd.size = req_memsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	memset(nonemb_cmd.va, 0, nonemb_cmd.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	if (!tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 			    "BS_%d : mgmt_open_connection Failed for cid=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 			    beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 				    nonemb_cmd.va, nonemb_cmd.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		beiscsi_free_ep(beiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		return -EAGAIN;
^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) 	ret = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			    BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			    "BS_%d : mgmt_open_connection Failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		if (ret != -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			dma_free_coherent(&phba->ctrl.pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 					nonemb_cmd.size, nonemb_cmd.va,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 					nonemb_cmd.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		beiscsi_free_ep(beiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	ptcpcnct_out = (struct tcp_connect_and_offload_out *)nonemb_cmd.va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	beiscsi_ep->cid_vld = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		    "BS_%d : mgmt_open_connection Success\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			    nonemb_cmd.va, nonemb_cmd.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)  * beiscsi_ep_connect - Ask chip to create TCP Conn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)  * @shost: Pointer to scsi_host structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)  * @dst_addr: The IP address of Target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)  * @non_blocking: blocking or non-blocking call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)  * This routines first asks chip to create a connection and then allocates an EP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) struct iscsi_endpoint *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		   int non_blocking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	struct beiscsi_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	struct beiscsi_endpoint *beiscsi_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	struct iscsi_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	if (!shost) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		pr_err("beiscsi_ep_connect shost is NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	phba = iscsi_host_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (!test_bit(BEISCSI_HBA_LINK_UP, &phba->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			    "BS_%d : The Adapter Port state is Down!!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	beiscsi_ep->phba = phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	beiscsi_ep->openiscsi_ep = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 			    "BS_%d : Failed in beiscsi_open_conn\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		goto free_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	return ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) free_ep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	iscsi_destroy_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)  * beiscsi_ep_poll - Poll to see if connection is established
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)  * @ep:	endpoint to be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)  * @timeout_ms: timeout specified in millisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  * Poll to see if TCP connection established
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		    "BS_%d : In  beiscsi_ep_poll\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	if (beiscsi_ep->cid_vld == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)  * beiscsi_flush_cq()- Flush the CQ created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)  * @phba: ptr device priv structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)  * Before the connection resource are freed flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)  * all the CQ enteries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) static void beiscsi_flush_cq(struct beiscsi_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	uint16_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	struct be_eq_obj *pbe_eq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	struct hwi_controller *phwi_ctrlr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	struct hwi_context_memory *phwi_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	phwi_ctrlr = phba->phwi_ctrlr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	phwi_context = phwi_ctrlr->phwi_ctxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	for (i = 0; i < phba->num_cpus; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 		pbe_eq = &phwi_context->be_eq[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		irq_poll_disable(&pbe_eq->iopoll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		beiscsi_process_cq(pbe_eq, BE2_MAX_NUM_CQ_PROC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		irq_poll_enable(&pbe_eq->iopoll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	}
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)  * beiscsi_conn_close - Invalidate and upload connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)  * @beiscsi_ep: pointer to device endpoint struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)  * Returns 0 on success,  -1 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) static int beiscsi_conn_close(struct beiscsi_endpoint *beiscsi_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	struct beiscsi_hba *phba = beiscsi_ep->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	unsigned int tag, attempts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	 * Without successfully invalidating and uploading connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	 * driver can't reuse the CID so attempt more than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	attempts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	while (attempts++ < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		tag = beiscsi_invalidate_cxn(phba, beiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		if (tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 			ret = beiscsi_mccq_compl_wait(phba, tag, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 				    "BS_%d : invalidate conn failed cid %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 				    beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	/* wait for all completions to arrive, then process them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	msleep(250);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	/* flush CQ entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	beiscsi_flush_cq(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	if (attempts > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	attempts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	while (attempts++ < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		tag = beiscsi_upload_cxn(phba, beiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		if (tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			ret = beiscsi_mccq_compl_wait(phba, tag, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 			if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 			beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 				    "BS_%d : upload conn failed cid %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 				    beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	if (attempts > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)  * beiscsi_ep_disconnect - Tears down the TCP connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)  * @ep:	endpoint to be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)  * Tears down the TCP connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	struct beiscsi_endpoint *beiscsi_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	struct beiscsi_conn *beiscsi_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	struct beiscsi_hba *phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	uint16_t cri_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	beiscsi_ep = ep->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	phba = beiscsi_ep->phba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		    "BS_%d : In beiscsi_ep_disconnect for ep_cid = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		    beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	if (!phba->ep_array[cri_index]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 			      "BS_%d : ep_array at %u cid %u empty\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			      cri_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			      beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	if (beiscsi_ep->conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		beiscsi_conn = beiscsi_ep->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		iscsi_suspend_queue(beiscsi_conn->conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	if (!beiscsi_hba_is_online(phba)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 			    "BS_%d : HBA in error 0x%lx\n", phba->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		 * Make CID available even if close fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		 * If not freed, FW might fail open using the CID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		if (beiscsi_conn_close(beiscsi_ep) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 			__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 				      "BS_%d : close conn failed cid %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 				      beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	beiscsi_free_ep(beiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	if (!phba->conn_table[cri_index])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		__beiscsi_log(phba, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 			      "BS_%d : conn_table empty at %u: cid %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 			      cri_index, beiscsi_ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	phba->conn_table[cri_index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) umode_t beiscsi_attr_is_visible(int param_type, int param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	switch (param_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	case ISCSI_NET_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		case ISCSI_NET_PARAM_IFACE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		case ISCSI_NET_PARAM_IPV4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		case ISCSI_NET_PARAM_IPV4_SUBNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		case ISCSI_NET_PARAM_IPV4_GW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		case ISCSI_NET_PARAM_IPV6_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		case ISCSI_NET_PARAM_VLAN_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		case ISCSI_NET_PARAM_VLAN_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		case ISCSI_NET_PARAM_VLAN_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	case ISCSI_HOST_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		case ISCSI_HOST_PARAM_HWADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		case ISCSI_HOST_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		case ISCSI_HOST_PARAM_PORT_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		case ISCSI_HOST_PARAM_PORT_SPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	case ISCSI_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		case ISCSI_PARAM_MAX_RECV_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		case ISCSI_PARAM_MAX_XMIT_DLENGTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		case ISCSI_PARAM_HDRDGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		case ISCSI_PARAM_DATADGST_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		case ISCSI_PARAM_CONN_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 		case ISCSI_PARAM_CONN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 		case ISCSI_PARAM_EXP_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		case ISCSI_PARAM_PERSISTENT_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 		case ISCSI_PARAM_PERSISTENT_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		case ISCSI_PARAM_PING_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		case ISCSI_PARAM_RECV_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		case ISCSI_PARAM_INITIAL_R2T_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		case ISCSI_PARAM_MAX_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		case ISCSI_PARAM_IMM_DATA_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		case ISCSI_PARAM_FIRST_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		case ISCSI_PARAM_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		case ISCSI_PARAM_PDU_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		case ISCSI_PARAM_DATASEQ_INORDER_EN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		case ISCSI_PARAM_ERL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		case ISCSI_PARAM_TARGET_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		case ISCSI_PARAM_TPGT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		case ISCSI_PARAM_USERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		case ISCSI_PARAM_PASSWORD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		case ISCSI_PARAM_USERNAME_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		case ISCSI_PARAM_PASSWORD_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		case ISCSI_PARAM_FAST_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		case ISCSI_PARAM_ABORT_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		case ISCSI_PARAM_LU_RESET_TMO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		case ISCSI_PARAM_IFACE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		case ISCSI_PARAM_INITIATOR_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 			return S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }