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) /* bnx2i_hwi.c: QLogic NetXtreme II iSCSI driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Copyright (c) 2006 - 2013 Broadcom Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 2007, 2008 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2007, 2008 Mike Christie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2014, QLogic Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * Maintained by: QLogic-Storage-Upstream@qlogic.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <scsi/libiscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "bnx2i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) DECLARE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * bnx2i_get_cid_num - get cid from ep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * @ep: 	endpoint pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * Only applicable to 57710 family of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	u32 cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 		cid = ep->ep_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 		cid = GET_CID_NUM(ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	return cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  * @hba: 		Adapter for which adjustments is to be made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  * Only applicable to 57710 family of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	u32 num_elements_per_pg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	    test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	    test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 		if (!is_power_of_2(hba->max_sqes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 			hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 		if (!is_power_of_2(hba->max_rqes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 			hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
^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) 	/* Adjust each queue size if the user selection does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	 * yield integral num of page buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	/* adjust SQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	if (hba->max_sqes < num_elements_per_pg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 		hba->max_sqes = num_elements_per_pg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	else if (hba->max_sqes % num_elements_per_pg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 				 ~(num_elements_per_pg - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	/* adjust CQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_CQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	if (hba->max_cqes < num_elements_per_pg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		hba->max_cqes = num_elements_per_pg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	else if (hba->max_cqes % num_elements_per_pg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 				 ~(num_elements_per_pg - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	/* adjust RQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	if (hba->max_rqes < num_elements_per_pg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		hba->max_rqes = num_elements_per_pg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	else if (hba->max_rqes % num_elements_per_pg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 				 ~(num_elements_per_pg - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * bnx2i_get_link_state - get network interface link state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * @hba:	adapter instance pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  * updates adapter structure flag based on netdev state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static void bnx2i_get_link_state(struct bnx2i_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 		clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * bnx2i_iscsi_license_error - displays iscsi license related error message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * @hba:		adapter instance pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * @error_code:		error classification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * Puts out an error log when driver is unable to offload iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  *	due to license restrictions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		/* iSCSI offload not supported on this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 				hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		/* iSCSI offload not supported on this LOM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		printk(KERN_ERR "bnx2i: LOM is not enable to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 				"offload iSCSI connections, dev=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 				hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)  * @ep:		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  * @action:	action, ARM or DISARM. For now only ARM_CQE is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)  * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  *	the driver. EQ event is generated CQ index is hit or at least 1 CQ is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  *	outstanding and on chip timer expires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) int bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	struct bnx2i_5771x_cq_db *cq_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	u16 cq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	u16 next_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	u32 num_active_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	/* Coalesce CQ entries only on 10G devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	/* Do not update CQ DB multiple times before firmware writes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	 * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	 * interrupts and other unwanted results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	if (action != CNIC_ARM_CQE_FP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	if (action == CNIC_ARM_CQE || action == CNIC_ARM_CQE_FP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		num_active_cmds = atomic_read(&ep->num_active_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		if (num_active_cmds <= event_coal_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			next_index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 			next_index = num_active_cmds >> ep->ec_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			if (next_index > num_active_cmds - event_coal_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 				next_index = num_active_cmds - event_coal_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		if (!next_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 			next_index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		if (cq_index > ep->qp.cqe_size * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 			cq_index -= ep->qp.cqe_size * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		if (!cq_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			cq_index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		cq_db->sqn[0] = cq_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	return next_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183)  * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184)  * @bnx2i_conn:		iscsi connection on which RQ event occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)  * @ptr:		driver buffer to which RQ buffer contents is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)  *			be copied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)  * @len:		length of valid data inside RQ buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  * Copies RQ buffer contents from shared (DMA'able) memory region to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  *	driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  *	scsi sense info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	if (!bnx2i_conn->ep->qp.rqe_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	bnx2i_conn->ep->qp.rqe_left--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		bnx2i_conn->ep->qp.rq_cons_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		bnx2i_conn->ep->qp.rq_cons_qe++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		bnx2i_conn->ep->qp.rq_cons_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	struct bnx2i_5771x_dbell dbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	u32 msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	memset(&dbell, 0, sizeof(dbell));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 			      B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	msg = *((u32 *)&dbell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	/* TODO : get doorbell register mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)  * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)  * @bnx2i_conn:	iscsi connection on which event to post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227)  * @count:	number of RQ buffer being posted to chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)  * No need to ring hardware doorbell for 57710 family of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct bnx2i_5771x_sq_rq_db *rq_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	struct bnx2i_endpoint *ep = bnx2i_conn->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	ep->qp.rqe_left += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	ep->qp.rq_prod_idx &= 0x7FFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	ep->qp.rq_prod_idx += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		if (!hi_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			ep->qp.rq_prod_idx |= 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		ep->qp.rq_prod_idx |= hi_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		rq_db->prod_idx = ep->qp.rq_prod_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		/* no need to ring hardware doorbell for 57710 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		writew(ep->qp.rq_prod_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		       ep->qp.ctx_base + CNIC_RECV_DOORBELL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  * @bnx2i_conn:		iscsi connection to which new SQ entries belong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  * @count: 		number of SQ WQEs to post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)  * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)  *	of devices. For 5706/5708/5709 new SQ WQE count is written into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)  *	doorbell register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	struct bnx2i_5771x_sq_rq_db *sq_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	struct bnx2i_endpoint *ep = bnx2i_conn->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	atomic_inc(&ep->num_active_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	wmb();	/* flush SQ WQE memory before the doorbell is rung */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		sq_db->prod_idx = ep->qp.sq_prod_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		bnx2i_ring_577xx_doorbell(bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  * @bnx2i_conn:	iscsi connection to which new SQ entries belong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  * @count:	number of SQ WQEs to post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  * this routine will update SQ driver parameters and ring the doorbell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 					      int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	int tmp_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	if (count == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		if (bnx2i_conn->ep->qp.sq_prod_qe ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		    bnx2i_conn->ep->qp.sq_last_qe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			bnx2i_conn->ep->qp.sq_prod_qe =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 						bnx2i_conn->ep->qp.sq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			bnx2i_conn->ep->qp.sq_prod_qe++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		    bnx2i_conn->ep->qp.sq_last_qe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			bnx2i_conn->ep->qp.sq_prod_qe += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 				bnx2i_conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			bnx2i_conn->ep->qp.sq_prod_qe =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 				&bnx2i_conn->ep->qp.sq_first_qe[count -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 								(tmp_cnt + 1)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	bnx2i_conn->ep->qp.sq_prod_idx += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	/* Ring the doorbell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322)  * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323)  * @bnx2i_conn:	iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324)  * @task: transport layer's command structure pointer which is requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325)  *	  a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327)  * prepare and post an iSCSI Login request WQE to CNIC firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			   struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	struct bnx2i_login_request *login_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	struct iscsi_login_req *login_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	u32 dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	login_hdr = (struct iscsi_login_req *)task->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	login_wqe = (struct bnx2i_login_request *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 						bnx2i_conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	login_wqe->op_code = login_hdr->opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	login_wqe->op_attr = login_hdr->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	login_wqe->version_max = login_hdr->max_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	login_wqe->version_min = login_hdr->min_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	login_wqe->data_length = ntoh24(login_hdr->dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	login_wqe->isid_lo = *((u32 *) login_hdr->isid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	login_wqe->tsih = login_hdr->tsih;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	login_wqe->itt = task->itt |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		(ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	login_wqe->cid = login_hdr->cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	login_wqe->resp_bd_list_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		(u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		 (bnx2i_conn->gen_pdu.resp_buf_size <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		  ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	login_wqe->resp_buffer = dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	login_wqe->bd_list_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		(u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	login_wqe->num_bds = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375)  * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)  * @bnx2i_conn:	iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)  * @mtask:	driver command structure which is requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  *		a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)  * prepare and post an iSCSI Login request WQE to CNIC firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			 struct iscsi_task *mtask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	struct iscsi_tm *tmfabort_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	struct scsi_cmnd *ref_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	struct iscsi_task *ctask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	struct bnx2i_tmf_request *tmfabort_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	u32 dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	u32 scsi_lun[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	tmfabort_wqe = (struct bnx2i_tmf_request *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 						bnx2i_conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	tmfabort_wqe->op_code = tmfabort_hdr->opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	tmfabort_wqe->op_attr = tmfabort_hdr->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	tmfabort_wqe->reserved2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	case ISCSI_TM_FUNC_ABORT_TASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	case ISCSI_TM_FUNC_TASK_REASSIGN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		if (!ctask || !ctask->sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			 * the iscsi layer must have completed the cmd while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			 * was starting up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			 * Note: In the case of a SCSI cmd timeout, the task's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			 *       sc is still active; hence ctask->sc != 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			 *       In this case, the task must be aborted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		ref_sc = ctask->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			dword = (ISCSI_TASK_TYPE_WRITE <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 				 ISCSI_CMD_REQUEST_TYPE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 			dword = (ISCSI_TASK_TYPE_READ <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 				 ISCSI_CMD_REQUEST_TYPE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		tmfabort_wqe->ref_itt = (dword |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 					(tmfabort_hdr->rtt & ISCSI_ITT_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		tmfabort_wqe->ref_itt = RESERVED_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	memcpy(scsi_lun, &tmfabort_hdr->lun, sizeof(struct scsi_lun));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	tmfabort_wqe->bd_list_addr_hi = (u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 				((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	tmfabort_wqe->num_bds = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449)  * bnx2i_send_iscsi_text - post iSCSI text WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  * @bnx2i_conn:	iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  * @mtask:	driver command structure which is requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  *		a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)  * prepare and post an iSCSI Text request WQE to CNIC firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) int bnx2i_send_iscsi_text(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 			  struct iscsi_task *mtask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	struct bnx2i_text_request *text_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	struct iscsi_text *text_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	u32 dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	text_hdr = (struct iscsi_text *)mtask->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	text_wqe = (struct bnx2i_text_request *) bnx2i_conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	memset(text_wqe, 0, sizeof(struct bnx2i_text_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	text_wqe->op_code = text_hdr->opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	text_wqe->op_attr = text_hdr->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	text_wqe->data_length = ntoh24(text_hdr->dlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	text_wqe->itt = mtask->itt |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		(ISCSI_TASK_TYPE_MPATH << ISCSI_TEXT_REQUEST_TYPE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	text_wqe->ttt = be32_to_cpu(text_hdr->ttt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	text_wqe->cmd_sn = be32_to_cpu(text_hdr->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	text_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	text_wqe->resp_bd_list_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			(u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	dword = ((1 << ISCSI_TEXT_REQUEST_NUM_RESP_BDS_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		 (bnx2i_conn->gen_pdu.resp_buf_size <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		  ISCSI_TEXT_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	text_wqe->resp_buffer = dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	text_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	text_wqe->bd_list_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			(u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	text_wqe->num_bds = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	text_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497)  * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498)  * @bnx2i_conn:	iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499)  * @cmd:	driver command structure which is requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500)  *		a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502)  * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			     struct bnx2i_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	struct bnx2i_cmd_request *scsi_cmd_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	scsi_cmd_wqe = (struct bnx2i_cmd_request *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 						bnx2i_conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)  * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  * @bnx2i_conn:		iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  * @task:		transport layer's command structure pointer which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522)  *                      requesting a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523)  * @datap:		payload buffer pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524)  * @data_len:		payload data length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525)  * @unsol:		indicated whether nopout pdu is unsolicited pdu or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526)  *			in response to target's NOPIN w/ TTT != FFFFFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528)  * prepare and post a nopout request WQE to CNIC firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			    struct iscsi_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 			    char *datap, int data_len, int unsol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	struct bnx2i_endpoint *ep = bnx2i_conn->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	struct bnx2i_nop_out_request *nopout_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	struct iscsi_nopout *nopout_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	nopout_hdr = (struct iscsi_nopout *)task->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	nopout_wqe->op_code = nopout_hdr->opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	memcpy(nopout_wqe->lun, &nopout_hdr->lun, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	/* 57710 requires LUN field to be swapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		swap(nopout_wqe->lun[0], nopout_wqe->lun[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	nopout_wqe->itt = ((u16)task->itt |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			   (ISCSI_TASK_TYPE_MPATH <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			    ISCSI_TMF_REQUEST_TYPE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	nopout_wqe->ttt = be32_to_cpu(nopout_hdr->ttt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	nopout_wqe->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	if (!unsol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	else if (nopout_hdr->itt == RESERVED_ITT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	nopout_wqe->data_length = data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	if (data_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		/* handle payload data, not required in first release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		nopout_wqe->bd_list_addr_lo = (u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 					bnx2i_conn->hba->mp_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		nopout_wqe->bd_list_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 			(u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		nopout_wqe->num_bds = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) }
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581)  * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582)  * @bnx2i_conn:	iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583)  * @task:	transport layer's command structure pointer which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)  *		requesting a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)  * prepare and post logout request WQE to CNIC firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 			    struct iscsi_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	struct bnx2i_logout_request *logout_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	struct iscsi_logout *logout_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	logout_hdr = (struct iscsi_logout *)task->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	logout_wqe = (struct bnx2i_logout_request *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 						bnx2i_conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	logout_wqe->op_code = logout_hdr->opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	logout_wqe->op_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 			logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	logout_wqe->itt = ((u16)task->itt |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			   (ISCSI_TASK_TYPE_MPATH <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			    ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	logout_wqe->data_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	logout_wqe->cid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	logout_wqe->bd_list_addr_hi = (u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 				((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	logout_wqe->num_bds = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)  * @conn:	iscsi connection which requires iscsi parameter update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)  * sends down iSCSI Conn Update request to move iSCSI conn to FFP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	struct bnx2i_conn *bnx2i_conn = conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	struct bnx2i_hba *hba = bnx2i_conn->hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	struct kwqe *kwqe_arr[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	struct iscsi_kwqe_conn_update *update_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	struct iscsi_kwqe_conn_update conn_update_kwqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	update_wqe = &conn_update_kwqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	update_wqe->hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	/* 5771x requires conn context id to be passed as is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		update_wqe->context_id = bnx2i_conn->ep->ep_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	update_wqe->conn_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	if (conn->hdrdgst_en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	if (conn->datadgst_en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (conn->session->initial_r2t_en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	if (conn->session->imm_data_en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	update_wqe->first_burst_length = conn->session->first_burst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	update_wqe->max_burst_length = conn->session->max_burst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	update_wqe->exp_stat_sn = conn->exp_statsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	update_wqe->session_error_recovery_level = conn->session->erl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	iscsi_conn_printk(KERN_ALERT, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			  "bnx2i: conn update - MBL 0x%x FBL 0x%x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 			  "MRDSL_I 0x%x MRDSL_T 0x%x \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			  update_wqe->max_burst_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 			  update_wqe->first_burst_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			  update_wqe->max_recv_pdu_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			  update_wqe->max_send_pdu_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	kwqe_arr[0] = (struct kwqe *) update_wqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	if (hba->cnic && hba->cnic->submit_kwqes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680)  * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681)  * @t:	timer context used to fetch the endpoint (transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682)  *	handle) structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684)  * routine to handle connection offload/destroy request timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) void bnx2i_ep_ofld_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	struct bnx2i_endpoint *ep = from_timer(ep, t, ofld_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	if (ep->state == EP_STATE_OFLD_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		ep->state = EP_STATE_OFLD_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	} else if (ep->state == EP_STATE_DISCONN_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		ep->state = EP_STATE_DISCONN_TIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	} else if (ep->state == EP_STATE_CLEANUP_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		ep->state = EP_STATE_CLEANUP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) static int bnx2i_power_of2(u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	u32 power = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (val & (val - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		return power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	val--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	while (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		val = val >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		power++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	return power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720)  * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721)  * @hba:	adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722)  * @cmd:	driver command structure which is requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723)  *		a WQE to sent to chip for further processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725)  * prepares and posts CONN_OFLD_REQ1/2 KWQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	struct bnx2i_cleanup_request *cmd_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	cmd_cleanup =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		(struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	cmd_cleanup->itt = cmd->req.itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744)  * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)  * @hba:	adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)  * @ep:		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748)  * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749)  * 	iscsi connection context clean-up process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	struct kwqe *kwqe_arr[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	struct iscsi_kwqe_conn_destroy conn_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	int rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	conn_cleanup.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	/* 5771x requires conn context id to be passed as is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		conn_cleanup.context_id = ep->ep_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		conn_cleanup.context_id = (ep->ep_cid >> 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	if (hba->cnic && hba->cnic->submit_kwqes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	return rc;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)  * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780)  * @hba: 		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781)  * @ep: 		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783)  * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 					 struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	struct kwqe *kwqe_arr[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	struct iscsi_kwqe_conn_offload1 ofld_req1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	struct iscsi_kwqe_conn_offload2 ofld_req2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	dma_addr_t dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	int num_kwqes = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	u32 *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	int rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	ofld_req1.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	dma_addr = ep->qp.sq_pgtbl_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	dma_addr = ep->qp.cq_pgtbl_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	ofld_req2.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	dma_addr = ep->qp.rq_pgtbl_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	ofld_req2.sq_first_pte.hi = *ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	ofld_req2.sq_first_pte.lo = *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	ofld_req2.cq_first_pte.hi = *ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	ofld_req2.cq_first_pte.lo = *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	kwqe_arr[0] = (struct kwqe *) &ofld_req1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	kwqe_arr[1] = (struct kwqe *) &ofld_req2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	ofld_req2.num_additional_wqes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	if (hba->cnic && hba->cnic->submit_kwqes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839)  * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840)  * @hba: 		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)  * @ep: 		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843)  * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 					  struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	struct kwqe *kwqe_arr[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	struct iscsi_kwqe_conn_offload1 ofld_req1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	struct iscsi_kwqe_conn_offload2 ofld_req2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	struct iscsi_kwqe_conn_offload3 ofld_req3[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	dma_addr_t dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	int num_kwqes = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	u32 *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	int rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	ofld_req1.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	ofld_req2.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	ofld_req2.sq_first_pte.hi = *ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	ofld_req2.sq_first_pte.lo = *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	ofld_req2.cq_first_pte.hi = *ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	ofld_req2.cq_first_pte.lo = *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	kwqe_arr[0] = (struct kwqe *) &ofld_req1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	kwqe_arr[1] = (struct kwqe *) &ofld_req2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	ofld_req2.num_additional_wqes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	ofld_req3[0].qp_first_pte[0].lo = *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	kwqe_arr[2] = (struct kwqe *) ofld_req3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	/* need if we decide to go with multiple KCQE's per conn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	num_kwqes += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	if (hba->cnic && hba->cnic->submit_kwqes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)  * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)  * @hba: 		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)  * @ep: 		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)  * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928)  * setup_qp_page_tables - iscsi QP page table setup function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929)  * @ep:		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)  * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932)  * 	64-bit address in big endian format. Whereas 10G/sec (57710) requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933)  * 	PT in little endian format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	int num_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	u32 *ptbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	dma_addr_t page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	int cnic_dev_10g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		cnic_dev_10g = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		cnic_dev_10g = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	/* SQ page table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	num_pages = ep->qp.sq_mem_size / CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	page = ep->qp.sq_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (cnic_dev_10g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	while (num_pages--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		if (cnic_dev_10g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			/* PTE is written in little endian format for 57710 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			*ptbl = (u32) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			*ptbl = (u32) ((u64) page >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			page += CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			/* PTE is written in big endian format for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 			 * 5706/5708/5709 devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 			*ptbl = (u32) ((u64) page >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			*ptbl = (u32) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			page += CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	/* RQ page table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	num_pages = ep->qp.rq_mem_size / CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	page = ep->qp.rq_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	if (cnic_dev_10g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	while (num_pages--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		if (cnic_dev_10g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			/* PTE is written in little endian format for 57710 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 			*ptbl = (u32) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			*ptbl = (u32) ((u64) page >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			page += CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 			/* PTE is written in big endian format for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			 * 5706/5708/5709 devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			*ptbl = (u32) ((u64) page >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			*ptbl = (u32) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 			page += CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	/* CQ page table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	num_pages = ep->qp.cq_mem_size / CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	page = ep->qp.cq_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	if (cnic_dev_10g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	while (num_pages--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		if (cnic_dev_10g) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 			/* PTE is written in little endian format for 57710 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 			*ptbl = (u32) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 			*ptbl = (u32) ((u64) page >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			page += CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			/* PTE is written in big endian format for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			 * 5706/5708/5709 devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 			*ptbl = (u32) ((u64) page >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 			*ptbl = (u32) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			ptbl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 			page += CNIC_PAGE_SIZE;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)  * bnx2i_alloc_qp_resc - allocates required resources for QP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)  * @hba:	adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  * @ep:		endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)  *	memory for SQ/RQ/CQ and page tables. EP structure elements such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)  *	as producer/consumer indexes/pointers, queue sizes and page table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)  *	contents are setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	struct bnx2i_5771x_cq_db *cq_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	ep->hba = hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	ep->conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	/* Allocate page table memory for SQ which is page aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	ep->qp.sq_mem_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		(ep->qp.sq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	ep->qp.sq_pgtbl_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		(ep->qp.sq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	ep->qp.sq_pgtbl_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		(ep->qp.sq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	ep->qp.sq_pgtbl_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 				   &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	if (!ep->qp.sq_pgtbl_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 				  ep->qp.sq_pgtbl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		goto mem_alloc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	/* Allocate memory area for actual SQ element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	ep->qp.sq_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 				   &ep->qp.sq_phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	if (!ep->qp.sq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 				  ep->qp.sq_mem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		goto mem_alloc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	ep->qp.sq_first_qe = ep->qp.sq_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	ep->qp.sq_prod_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	ep->qp.sq_cons_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	ep->qp.sqe_left = hba->max_sqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	/* Allocate page table memory for CQ which is page aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	ep->qp.cq_mem_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		(ep->qp.cq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	ep->qp.cq_pgtbl_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		(ep->qp.cq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	ep->qp.cq_pgtbl_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		(ep->qp.cq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	ep->qp.cq_pgtbl_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 				   &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	if (!ep->qp.cq_pgtbl_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 				  ep->qp.cq_pgtbl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		goto mem_alloc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	/* Allocate memory area for actual CQ element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	ep->qp.cq_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 				   &ep->qp.cq_phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	if (!ep->qp.cq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 				  ep->qp.cq_mem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		goto mem_alloc_err;
^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) 	ep->qp.cq_first_qe = ep->qp.cq_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	ep->qp.cq_prod_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	ep->qp.cq_cons_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	ep->qp.cqe_left = hba->max_cqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	ep->qp.cqe_size = hba->max_cqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	/* Invalidate all EQ CQE index, req only for 57710 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	/* Allocate page table memory for RQ which is page aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	ep->qp.rq_mem_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		(ep->qp.rq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	ep->qp.rq_pgtbl_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		(ep->qp.rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	ep->qp.rq_pgtbl_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		(ep->qp.rq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	ep->qp.rq_pgtbl_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 				   &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	if (!ep->qp.rq_pgtbl_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 				  ep->qp.rq_pgtbl_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		goto mem_alloc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	/* Allocate memory area for actual RQ element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	ep->qp.rq_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 				   &ep->qp.rq_phys, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	if (!ep->qp.rq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 				  ep->qp.rq_mem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 		goto mem_alloc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	ep->qp.rq_first_qe = ep->qp.rq_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	ep->qp.rq_prod_idx = 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	ep->qp.rq_cons_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	ep->qp.rqe_left = hba->max_rqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	setup_qp_page_tables(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) mem_alloc_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	bnx2i_free_qp_resc(hba, ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)  * bnx2i_free_qp_resc - free memory resources held by QP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  * @hba:	adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  * @ep:	endpoint (transport identifier) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)  * Free QP resources - SQ/RQ/CQ memory and page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	if (ep->qp.ctx_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		iounmap(ep->qp.ctx_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		ep->qp.ctx_base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	/* Free SQ mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	if (ep->qp.sq_pgtbl_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 				  ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		ep->qp.sq_pgtbl_virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		ep->qp.sq_pgtbl_phys = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	if (ep->qp.sq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 				  ep->qp.sq_virt, ep->qp.sq_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		ep->qp.sq_virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		ep->qp.sq_phys = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	/* Free RQ mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	if (ep->qp.rq_pgtbl_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 				  ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		ep->qp.rq_pgtbl_virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		ep->qp.rq_pgtbl_phys = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	if (ep->qp.rq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 				  ep->qp.rq_virt, ep->qp.rq_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		ep->qp.rq_virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		ep->qp.rq_phys = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	/* Free CQ mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	if (ep->qp.cq_pgtbl_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 				  ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		ep->qp.cq_pgtbl_virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		ep->qp.cq_pgtbl_phys = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	if (ep->qp.cq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 		dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 				  ep->qp.cq_virt, ep->qp.cq_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		ep->qp.cq_virt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		ep->qp.cq_phys = 0;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)  * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)  * @hba:	adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)  * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)  * 	This results in iSCSi support validation and on-chip context manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)  * 	initialization.  Firmware completes this handshake with a CQE carrying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)  * 	the result of iscsi support validation. Parameter carried by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)  * 	iscsi init request determines the number of offloaded connection and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)  * 	tolerance level for iscsi protocol violation this hba/chip can support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	struct kwqe *kwqe_arr[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	struct iscsi_kwqe_init1 iscsi_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	struct iscsi_kwqe_init2 iscsi_init2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	u64 mask64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	memset(&iscsi_init, 0x00, sizeof(struct iscsi_kwqe_init1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	memset(&iscsi_init2, 0x00, sizeof(struct iscsi_kwqe_init2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	bnx2i_adjust_qp_size(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	iscsi_init.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		(CNIC_PAGE_BITS - 8) << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	if (en_tcp_dack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	iscsi_init.reserved0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	iscsi_init.num_cqs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	iscsi_init.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	iscsi_init.dummy_buffer_addr_hi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		(u32) ((u64) hba->dummy_buf_dma >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	hba->num_ccell = hba->max_sqes >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	hba->ctx_ccell_tasks =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	iscsi_init.num_ccells_per_conn = hba->num_ccell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	iscsi_init.num_tasks_per_conn = hba->max_sqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	iscsi_init.sq_wqes_per_page = CNIC_PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	iscsi_init.sq_num_wqes = hba->max_sqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	iscsi_init.cq_log_wqes_per_page =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		(u8) bnx2i_power_of2(CNIC_PAGE_SIZE / BNX2I_CQE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	iscsi_init.cq_num_wqes = hba->max_cqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 				   (CNIC_PAGE_SIZE - 1)) / CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 				   (CNIC_PAGE_SIZE - 1)) / CNIC_PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	iscsi_init.rq_num_wqes = hba->max_rqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	iscsi_init2.hdr.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		(ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	mask64 = 0x0ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	mask64 |= (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		/* CISCO MDS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		(1UL <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		  ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		/* HP MSA1510i */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		(1UL <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		  ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		/* EMC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		(1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	if (error_mask1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		iscsi_init2.error_bit_map[0] = error_mask1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		mask64 ^= (u32)(mask64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		mask64 |= error_mask1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		iscsi_init2.error_bit_map[0] = (u32) mask64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	if (error_mask2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		iscsi_init2.error_bit_map[1] = error_mask2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		mask64 &= 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		mask64 |= ((u64)error_mask2 << 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	iscsi_error_mask = mask64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	kwqe_arr[0] = (struct kwqe *) &iscsi_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	if (hba->cnic && hba->cnic->submit_kwqes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)  * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)  * @session:	iscsi session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)  * @bnx2i_conn:	bnx2i connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)  * @cqe:	pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)  * process SCSI CMD Response CQE & complete the request to SCSI-ML
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 				struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 				struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	struct bnx2i_hba *hba = bnx2i_conn->hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	struct bnx2i_cmd_response *resp_cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	struct bnx2i_cmd *bnx2i_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	struct iscsi_scsi_rsp *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	u32 datalen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	resp_cqe = (struct bnx2i_cmd_response *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	spin_lock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 				 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	bnx2i_cmd = task->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		conn->datain_pdus_cnt +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			resp_cqe->task_stat.read_stat.num_data_ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		conn->rxdata_octets +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			bnx2i_cmd->req.total_data_transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		ADD_STATS_64(hba, rx_pdus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			     resp_cqe->task_stat.read_stat.num_data_ins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		ADD_STATS_64(hba, rx_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			     bnx2i_cmd->req.total_data_transfer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		conn->dataout_pdus_cnt +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			resp_cqe->task_stat.write_stat.num_data_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		conn->r2t_pdus_cnt +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 			resp_cqe->task_stat.write_stat.num_r2ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		conn->txdata_octets +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			bnx2i_cmd->req.total_data_transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		ADD_STATS_64(hba, tx_pdus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 			     resp_cqe->task_stat.write_stat.num_data_outs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		ADD_STATS_64(hba, tx_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 			     bnx2i_cmd->req.total_data_transfer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		ADD_STATS_64(hba, rx_pdus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			     resp_cqe->task_stat.write_stat.num_r2ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	hdr = (struct iscsi_scsi_rsp *)task->hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	resp_cqe = (struct bnx2i_cmd_response *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	hdr->opcode = resp_cqe->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	hdr->response = resp_cqe->response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	hdr->cmd_status = resp_cqe->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	hdr->flags = resp_cqe->response_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		datalen = resp_cqe->data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		if (datalen < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		if (datalen > BNX2I_RQ_WQE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 					  "sense data len %d > RQ sz\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 					  datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 			datalen = BNX2I_RQ_WQE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		} else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			iscsi_conn_printk(KERN_ERR, conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 					  "sense data len %d > conn data\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 					  datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 			     conn->data, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	spin_unlock_bh(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)  * bnx2i_process_login_resp - this function handles iscsi login response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)  * process Login Response CQE & complete it to open-iscsi user daemon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) static int bnx2i_process_login_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 				    struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 				    struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	struct bnx2i_login_response *login;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	struct iscsi_login_rsp *resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	int pld_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	int pad_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	login = (struct bnx2i_login_response *) cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 				 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	resp_hdr->opcode = login->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	resp_hdr->flags = login->response_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	resp_hdr->max_version = login->version_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	resp_hdr->active_version = login->version_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	resp_hdr->hlength = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	hton24(resp_hdr->dlength, login->data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	memcpy(resp_hdr->isid, &login->isid_lo, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	resp_hdr->tsih = cpu_to_be16(login->tsih);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	resp_hdr->itt = task->hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	resp_hdr->statsn = cpu_to_be32(login->stat_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	resp_hdr->status_class = login->status_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	resp_hdr->status_detail = login->status_detail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	pld_len = login->data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	bnx2i_conn->gen_pdu.resp_wr_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 					bnx2i_conn->gen_pdu.resp_buf + pld_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	pad_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	if (pld_len & 0x3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		pad_len = 4 - (pld_len % 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	if (pad_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		for (i = 0; i < pad_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 			bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			bnx2i_conn->gen_pdu.resp_wr_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		bnx2i_conn->gen_pdu.resp_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)  * bnx2i_process_text_resp - this function handles iscsi text response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)  * @session:	iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)  * @bnx2i_conn:	iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)  * @cqe:	pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)  * process iSCSI Text Response CQE&  complete it to open-iscsi user daemon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) static int bnx2i_process_text_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 				   struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 				   struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	struct bnx2i_text_response *text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	struct iscsi_text_rsp *resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	int pld_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	int pad_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	text = (struct bnx2i_text_response *) cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	resp_hdr->opcode = text->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	resp_hdr->flags = text->response_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	resp_hdr->hlength = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	hton24(resp_hdr->dlength, text->data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	resp_hdr->itt = task->hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	resp_hdr->ttt = cpu_to_be32(text->ttt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	resp_hdr->statsn = task->hdr->exp_statsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	pld_len = text->data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 					  pld_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	pad_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	if (pld_len & 0x3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		pad_len = 4 - (pld_len % 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	if (pad_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 		int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		for (i = 0; i < pad_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 			bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 			bnx2i_conn->gen_pdu.resp_wr_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 			     bnx2i_conn->gen_pdu.resp_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 			     bnx2i_conn->gen_pdu.resp_wr_ptr -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 			     bnx2i_conn->gen_pdu.resp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)  * bnx2i_process_tmf_resp - this function handles iscsi TMF response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)  * process iSCSI TMF Response CQE and wake up the driver eh thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) static int bnx2i_process_tmf_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 				  struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 				  struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	struct bnx2i_tmf_response *tmf_cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	struct iscsi_tm_rsp *resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	tmf_cqe = (struct bnx2i_tmf_response *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 				 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	resp_hdr->opcode = tmf_cqe->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	resp_hdr->itt = task->hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	resp_hdr->response = tmf_cqe->response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)  * bnx2i_process_logout_resp - this function handles iscsi logout response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)  * process iSCSI Logout Response CQE & make function call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)  * notify the user daemon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) static int bnx2i_process_logout_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 				     struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 				     struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	struct bnx2i_logout_response *logout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	struct iscsi_logout_rsp *resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	logout = (struct bnx2i_logout_response *) cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 				 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	resp_hdr->opcode = logout->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	resp_hdr->flags = logout->response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	resp_hdr->hlength = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	resp_hdr->itt = task->hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	resp_hdr->statsn = task->hdr->exp_statsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)  * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)  * process iSCSI NOPIN local completion CQE, frees IIT and command structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 					   struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 					   struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	struct bnx2i_nop_in_msg *nop_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	nop_in = (struct bnx2i_nop_in_msg *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 				 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	if (task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		__iscsi_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)  * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)  * @bnx2i_conn:	iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)  * Firmware advances RQ producer index for every unsolicited PDU even if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)  *	payload data length is '0'. This function makes corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)  *	adjustments on the driver side to match this f/w behavior
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	char dummy_rq_data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	bnx2i_put_rq_buf(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)  * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)  * process iSCSI target's proactive iSCSI NOPIN request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 				     struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 				     struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	struct bnx2i_nop_in_msg *nop_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	struct iscsi_nopin *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	int tgt_async_nop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	nop_in = (struct bnx2i_nop_in_msg *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	memset(hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	hdr->opcode = nop_in->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	hdr->ttt = cpu_to_be32(nop_in->ttt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	if (nop_in->itt == (u16) RESERVED_ITT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 		bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 		hdr->itt = RESERVED_ITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 		tgt_async_nop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	/* this is a response to one of our nop-outs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 			 (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	if (task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		hdr->flags = ISCSI_FLAG_CMD_FINAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 		hdr->itt = task->hdr->itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 		hdr->ttt = cpu_to_be32(nop_in->ttt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		memcpy(&hdr->lun, nop_in->lun, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	return tgt_async_nop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)  * bnx2i_process_async_mesg - this function handles iscsi async message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)  * process iSCSI ASYNC Message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) static void bnx2i_process_async_mesg(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 				     struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 				     struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	struct bnx2i_async_msg *async_cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	struct iscsi_async *resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	u8 async_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	async_cqe = (struct bnx2i_async_msg *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	async_event = async_cqe->async_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 		iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 				  "async: scsi events not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	resp_hdr->opcode = async_cqe->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	resp_hdr->flags = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	memcpy(&resp_hdr->lun, async_cqe->lun, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	resp_hdr->async_event = async_cqe->async_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	resp_hdr->async_vcode = async_cqe->async_vcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	__iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 			     (struct iscsi_hdr *)resp_hdr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)  * bnx2i_process_reject_mesg - process iscsi reject pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)  * process iSCSI REJECT message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) static void bnx2i_process_reject_mesg(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 				      struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 				      struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	struct bnx2i_reject_msg *reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	struct iscsi_reject *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	reject = (struct bnx2i_reject_msg *) cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	if (reject->data_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 		bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 		bnx2i_put_rq_buf(bnx2i_conn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	memset(hdr, 0, sizeof(struct iscsi_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	hdr->opcode = reject->op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	hdr->reason = reject->reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	hton24(hdr->dlength, reject->data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	__iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 			     reject->data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)  * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)  * @session:		iscsi session pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)  * @bnx2i_conn:		iscsi connection pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)  * process command cleanup response CQE during conn shutdown or error recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 					   struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 					   struct cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	struct bnx2i_cleanup_response *cmd_clean_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	task = iscsi_itt_to_task(conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 			cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 		printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 			cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	complete(&bnx2i_conn->cmd_cleanup_cmpl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)  * bnx2i_percpu_io_thread - thread per cpu for ios
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)  * @arg:	ptr to bnx2i_percpu_info structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) int bnx2i_percpu_io_thread(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	struct bnx2i_percpu_s *p = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	struct bnx2i_work *work, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	LIST_HEAD(work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	set_user_nice(current, MIN_NICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 		spin_lock_bh(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 		while (!list_empty(&p->work_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 			list_splice_init(&p->work_list, &work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 			spin_unlock_bh(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 			list_for_each_entry_safe(work, tmp, &work_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 				list_del_init(&work->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 				/* work allocated in the bh, freed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 				bnx2i_process_scsi_cmd_resp(work->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 							    work->bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 							    &work->cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 				atomic_dec(&work->bnx2i_conn->work_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 				kfree(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 			spin_lock_bh(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 		spin_unlock_bh(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	__set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)  * bnx2i_queue_scsi_cmd_resp - queue cmd completion to the percpu thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)  * @session:		iscsi session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)  * @bnx2i_conn:		bnx2i connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)  * @cqe:		pointer to newly DMA'ed CQE entry for processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)  * this function is called by generic KCQ handler to queue all pending cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)  * completion CQEs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)  * The implementation is to queue the cmd response based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)  * last recorded command for the given connection.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)  * cpu_id gets recorded upon task_xmit.  No out-of-order completion!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) static int bnx2i_queue_scsi_cmd_resp(struct iscsi_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 				     struct bnx2i_conn *bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 				     struct bnx2i_nop_in_msg *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	struct bnx2i_work *bnx2i_work = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	struct bnx2i_percpu_s *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	struct iscsi_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	struct scsi_cmnd *sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	spin_lock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	task = iscsi_itt_to_task(bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 				 cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	if (!task || !task->sc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	sc = task->sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	spin_unlock(&session->back_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	p = &per_cpu(bnx2i_percpu, blk_mq_rq_cpu(sc->request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	spin_lock(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	if (unlikely(!p->iothread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	/* Alloc and copy to the cqe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	bnx2i_work = kzalloc(sizeof(struct bnx2i_work), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	if (bnx2i_work) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		INIT_LIST_HEAD(&bnx2i_work->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		bnx2i_work->session = session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 		bnx2i_work->bnx2i_conn = bnx2i_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		memcpy(&bnx2i_work->cqe, cqe, sizeof(struct cqe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 		list_add_tail(&bnx2i_work->list, &p->work_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		atomic_inc(&bnx2i_conn->work_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 		wake_up_process(p->iothread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		spin_unlock(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	spin_unlock(&p->p_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	bnx2i_process_scsi_cmd_resp(session, bnx2i_conn, (struct cqe *)cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)  * bnx2i_process_new_cqes - process newly DMA'ed CQE's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951)  * @bnx2i_conn:		bnx2i connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953)  * this function is called by generic KCQ handler to process all pending CQE's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) static int bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	struct iscsi_session *session = conn->session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	struct bnx2i_hba *hba = bnx2i_conn->hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	struct qp_info *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	struct bnx2i_nop_in_msg *nopin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	int tgt_async_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	int cqe_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	if (bnx2i_conn->ep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	qp = &bnx2i_conn->ep->qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	if (!qp->cq_virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 		printk(KERN_ALERT "bnx2i (%s): cq resr freed in bh execution!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 		       hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 		nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 		if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 			if (nopin->op_code == ISCSI_OP_NOOP_IN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 			    nopin->itt == (u16) RESERVED_ITT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 				printk(KERN_ALERT "bnx2i: Unsolicited "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 				       "NOP-In detected for suspended "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 				       "connection dev=%s!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 				       hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 				bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 				goto cqe_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 		tgt_async_msg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 		switch (nopin->op_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		case ISCSI_OP_SCSI_CMD_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 		case ISCSI_OP_SCSI_DATA_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 			/* Run the kthread engine only for data cmds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 			   All other cmds will be completed in this bh! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 			bnx2i_queue_scsi_cmd_resp(session, bnx2i_conn, nopin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 		case ISCSI_OP_LOGIN_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 			bnx2i_process_login_resp(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 						 qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		case ISCSI_OP_SCSI_TMFUNC_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 			bnx2i_process_tmf_resp(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 					       qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 		case ISCSI_OP_TEXT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 			bnx2i_process_text_resp(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 						qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		case ISCSI_OP_LOGOUT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 			bnx2i_process_logout_resp(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 						  qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		case ISCSI_OP_NOOP_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 			if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 						     qp->cq_cons_qe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 				tgt_async_msg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 		case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 			bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 						       qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		case ISCSI_OP_ASYNC_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 			bnx2i_process_async_mesg(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 						 qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 			tgt_async_msg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		case ISCSI_OP_REJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 			bnx2i_process_reject_mesg(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 						  qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 		case ISCSI_OPCODE_CLEANUP_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 			bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 						       qp->cq_cons_qe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 			printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 					  nopin->op_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		ADD_STATS_64(hba, rx_pdus, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		ADD_STATS_64(hba, rx_bytes, nopin->data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		if (!tgt_async_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 			if (!atomic_read(&bnx2i_conn->ep->num_active_cmds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 				printk(KERN_ALERT "bnx2i (%s): no active cmd! "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 				       "op 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 				       hba->netdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 				       nopin->op_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 				atomic_dec(&bnx2i_conn->ep->num_active_cmds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) cqe_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		/* clear out in production version only, till beta keep opcode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		 * field intact, will be helpful in debugging (context dump)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		 * nopin->op_code = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 		cqe_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		qp->cqe_exp_seq_sn++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 		if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 			qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		if (qp->cq_cons_qe == qp->cq_last_qe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 			qp->cq_cons_qe = qp->cq_first_qe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 			qp->cq_cons_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 			qp->cq_cons_qe++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 			qp->cq_cons_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	return cqe_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)  * bnx2i_fastpath_notification - process global event queue (KCQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)  * @hba:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)  * @new_cqe_kcqe:	pointer to newly DMA'ed KCQE entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)  * Fast path event notification handler, KCQ entry carries context id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)  *	of the connection that has 1 or more pending CQ entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 					struct iscsi_kcqe *new_cqe_kcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	struct bnx2i_conn *bnx2i_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	u32 iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	int nxt_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	if (!bnx2i_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 		printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 	if (!bnx2i_conn->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	bnx2i_process_new_cqes(bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	nxt_idx = bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 						CNIC_ARM_CQE_FP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	if (nxt_idx && nxt_idx == bnx2i_process_new_cqes(bnx2i_conn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE_FP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)  * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)  * @hba:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)  * @update_kcqe:	kcqe pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)  * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 					   struct iscsi_kcqe *update_kcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 	struct bnx2i_conn *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	u32 iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	iscsi_cid = update_kcqe->iscsi_conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 	conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	if (!conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 	if (!conn->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 		printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	if (update_kcqe->completion_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 		printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 		conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	wake_up_interruptible(&conn->ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)  * bnx2i_recovery_que_add_conn - add connection to recovery queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)  * @hba:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)  * @bnx2i_conn:		iscsi connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153)  * Add connection to recovery queue and schedule adapter eh worker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 					struct bnx2i_conn *bnx2i_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 			   ISCSI_ERR_CONN_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)  * bnx2i_process_tcp_error - process error notification on a given connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166)  * @hba: 		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)  * @tcp_err: 		tcp error kcqe pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169)  * handles tcp level error notifications from FW.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 				    struct iscsi_kcqe *tcp_err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	struct bnx2i_conn *bnx2i_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	u32 iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	iscsi_cid = tcp_err->iscsi_conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	if (!bnx2i_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 			  iscsi_cid, tcp_err->completion_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)  * bnx2i_process_iscsi_error - process error notification on a given connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193)  * @hba:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194)  * @iscsi_err:		iscsi error kcqe pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)  * handles iscsi error notifications from the FW. Firmware based in initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197)  *	handshake classifies iscsi protocol / TCP rfc violation into either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)  *	warning or error indications. If indication is of "Error" type, driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199)  *	will initiate session recovery for that connection/session. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)  *	"Warning" type indication, driver will put out a system log message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201)  *	(there will be only one message for each type for the life of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)  *	session, this is to avoid un-necessarily overloading the system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 				      struct iscsi_kcqe *iscsi_err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	struct bnx2i_conn *bnx2i_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	u32 iscsi_cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	char warn_notice[] = "iscsi_warning";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	char error_notice[] = "iscsi_error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	char additional_notice[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	char *message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	int need_recovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	u64 err_mask64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	iscsi_cid = iscsi_err->iscsi_conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	if (!bnx2i_conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 		printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	err_mask64 = (0x1ULL << iscsi_err->completion_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	if (err_mask64 & iscsi_error_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		need_recovery = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		message = warn_notice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 		need_recovery = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 		message = error_notice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	switch (iscsi_err->completion_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		strcpy(additional_notice, "hdr digest err");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		strcpy(additional_notice, "data digest err");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 		strcpy(additional_notice, "wrong opcode rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		strcpy(additional_notice, "AHS len > 0 rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 		strcpy(additional_notice, "invalid ITT rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		strcpy(additional_notice, "wrong StatSN rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 		strcpy(additional_notice, "wrong DataSN rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 		strcpy(additional_notice, "pend R2T violation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 		strcpy(additional_notice, "ERL0, UO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		strcpy(additional_notice, "ERL0, U1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		strcpy(additional_notice, "ERL0, U2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 		strcpy(additional_notice, "ERL0, U3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 		strcpy(additional_notice, "ERL0, U4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		strcpy(additional_notice, "ERL0, U5");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		strcpy(additional_notice, "ERL0, U6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		strcpy(additional_notice, "invalid resi len");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 		strcpy(additional_notice, "MRDSL violation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 		strcpy(additional_notice, "F-bit not set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 		strcpy(additional_notice, "invalid TTT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 		strcpy(additional_notice, "invalid DataSN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 		strcpy(additional_notice, "burst len violation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 		strcpy(additional_notice, "buf offset violation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 		strcpy(additional_notice, "invalid LUN field");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		strcpy(additional_notice, "invalid R2TSN field");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 		strcpy(additional_notice, "invalid cmd len1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 	ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 		strcpy(additional_notice, "invalid cmd len2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 		strcpy(additional_notice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 		       "pend r2t exceeds MaxOutstandingR2T value");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 		strcpy(additional_notice, "TTT is rsvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 		strcpy(additional_notice, "MBL violation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO 	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 		strcpy(additional_notice, "data seg len != 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 		strcpy(additional_notice, "reject pdu len error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		strcpy(additional_notice, "async pdu len error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 		strcpy(additional_notice, "nopin pdu len error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) #define BNX2_ERR_PEND_R2T_IN_CLEANUP			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 	ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	case BNX2_ERR_PEND_R2T_IN_CLEANUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 		strcpy(additional_notice, "pend r2t in cleanup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 		strcpy(additional_notice, "IP fragments rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 	case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 		strcpy(additional_notice, "IP options error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 		strcpy(additional_notice, "urgent flag error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 		printk(KERN_ALERT "iscsi_err - unknown err %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 				  iscsi_err->completion_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	if (need_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		iscsi_conn_printk(KERN_ALERT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 				  bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 				  "bnx2i: %s - %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 				  message, additional_notice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 		iscsi_conn_printk(KERN_ALERT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 				  bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 				  "conn_err - hostno %d conn %p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 				  "iscsi_cid %x cid %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 				  bnx2i_conn->hba->shost->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 				  bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 				  bnx2i_conn->ep->ep_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 		bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 		if (!test_and_set_bit(iscsi_err->completion_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 				      (void *) &bnx2i_conn->violation_notified))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 			iscsi_conn_printk(KERN_ALERT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 					  bnx2i_conn->cls_conn->dd_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 					  "bnx2i: %s - %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 					  message, additional_notice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)  * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386)  * @hba:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387)  * @conn_destroy:	conn destroy kcqe pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389)  * handles connection destroy completion request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 					    struct iscsi_kcqe *conn_destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	struct bnx2i_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 		printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 				  "offload request, unexpected completion\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	if (hba != ep->hba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		printk(KERN_ALERT "conn destroy- error hba mis-match\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	if (conn_destroy->completion_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 		printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 		ep->state = EP_STATE_CLEANUP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 		ep->state = EP_STATE_CLEANUP_CMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)  * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)  * @hba:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)  * @ofld_kcqe:		conn offload kcqe pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)  * handles initial connection offload completion, ep_connect() thread is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)  *	woken-up to continue with LLP connect process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 				    struct iscsi_kcqe *ofld_kcqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	u32 cid_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	struct bnx2i_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	if (!ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 		printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	if (hba != ep->hba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	if (ofld_kcqe->completion_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 		ep->state = EP_STATE_OFLD_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 		if (ofld_kcqe->completion_status ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 		    ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 			printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 				"to allocate iSCSI context resources\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 				hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 		else if (ofld_kcqe->completion_status ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 			 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 			printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 				"opcode\n", hba->netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 		else if (ofld_kcqe->completion_status ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 			 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 			/* error status code valid only for 5771x chipset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 			ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 			printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 				"error code %d\n", hba->netdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 				ofld_kcqe->completion_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 		ep->state = EP_STATE_OFLD_COMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 		cid_addr = ofld_kcqe->iscsi_conn_context_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		ep->ep_cid = cid_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 		ep->qp.ctx_base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)  * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)  * @context:		adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)  * @kcqe:		kcqe pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474)  * @num_cqe:		number of kcqes to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476)  * Generic KCQ event handler/dispatcher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 				u32 num_cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	struct bnx2i_hba *hba = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	struct iscsi_kcqe *ikcqe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 	while (i < num_cqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 		ikcqe = (struct iscsi_kcqe *) kcqe[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 		if (ikcqe->op_code ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 		    ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 			bnx2i_fastpath_notification(hba, ikcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 		else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 			bnx2i_process_ofld_cmpl(hba, ikcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 		else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 			bnx2i_process_update_conn_cmpl(hba, ikcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 			if (ikcqe->completion_status !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 			    ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 				bnx2i_iscsi_license_error(hba, ikcqe->\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 							  completion_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 				set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 				bnx2i_get_link_state(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 				printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 						 "ISCSI_INIT passed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 						 (u8)hba->pcidev->bus->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 						 hba->pci_devno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 						 (u8)hba->pci_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 		} else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 			bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 		else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 			bnx2i_process_iscsi_error(hba, ikcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 		else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 			bnx2i_process_tcp_error(hba, ikcqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 			printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 					  ikcqe->op_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525)  * bnx2i_indicate_netevent - Generic netdev event handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526)  * @context:	adapter structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)  * @event:	event type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)  * @vlan_id:	vlans id - associated vlan id with this event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530)  * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531)  *	NETDEV_GOING_DOWN and NETDEV_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) static void bnx2i_indicate_netevent(void *context, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 				    u16 vlan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 	struct bnx2i_hba *hba = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	/* Ignore all netevent coming from vlans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 	if (vlan_id != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 	case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 		if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 			bnx2i_send_fw_iscsi_init_msg(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 	case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 		clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 		clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	case NETDEV_GOING_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 		iscsi_host_for_each_session(hba->shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 					    bnx2i_drop_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 		bnx2i_get_link_state(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566)  * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)  * @cm_sk: 		cnic sock structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)  * function callback exported via bnx2i - cnic driver interface to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570)  *	indicate completion of option-2 TCP connect request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 	struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 	if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 		ep->state = EP_STATE_CONNECT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 	else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 		ep->state = EP_STATE_CONNECT_COMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		ep->state = EP_STATE_CONNECT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 	wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588)  * bnx2i_cm_close_cmpl - process tcp conn close completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)  * @cm_sk:	cnic sock structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591)  * function callback exported via bnx2i - cnic driver interface to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)  *	indicate completion of option-2 graceful TCP connect shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 	struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 	ep->state = EP_STATE_DISCONN_COMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)  * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)  * @cm_sk:	cnic sock structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607)  * function callback exported via bnx2i - cnic driver interface to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608)  *	indicate completion of option-2 abortive TCP connect termination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	ep->state = EP_STATE_DISCONN_COMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 	wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620)  * bnx2i_cm_remote_close - process received TCP FIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621)  * @cm_sk:	cnic sock structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623)  * function callback exported via bnx2i - cnic driver interface to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624)  *	async TCP events such as FIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	ep->state = EP_STATE_TCP_FIN_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	if (ep->conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 		bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636)  * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)  * @cm_sk:	cnic sock structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639)  * function callback exported via bnx2i - cnic driver interface to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)  *	indicate async TCP events (RST) sent by the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 	struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 	u32 old_state = ep->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 	ep->state = EP_STATE_TCP_RST_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 	if (old_state == EP_STATE_DISCONN_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 		wake_up_interruptible(&ep->ofld_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 		if (ep->conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 			bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 			      char *buf, u16 buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	struct bnx2i_hba *hba = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	if (!hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 				msg_type, buf, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 		printk(KERN_ALERT "bnx2i: private nl message send error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675)  * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)  *			carrying callback function pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) struct cnic_ulp_ops bnx2i_cnic_cb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 	.cnic_init = bnx2i_ulp_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	.cnic_exit = bnx2i_ulp_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 	.cnic_start = bnx2i_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	.cnic_stop = bnx2i_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 	.indicate_kcqes = bnx2i_indicate_kcqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 	.indicate_netevent = bnx2i_indicate_netevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 	.cm_connect_complete = bnx2i_cm_connect_cmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 	.cm_close_complete = bnx2i_cm_close_cmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 	.cm_abort_complete = bnx2i_cm_abort_cmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	.cm_remote_close = bnx2i_cm_remote_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	.cm_remote_abort = bnx2i_cm_remote_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 	.iscsi_nl_send_msg = bnx2i_send_nl_mesg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	.cnic_get_stats = bnx2i_get_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 	.owner = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)  * bnx2i_map_ep_dbell_regs - map connection doorbell registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)  * @ep: bnx2i endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700)  * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)  *	register in BAR #0. Whereas in 57710 these register are accessed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)  *	mapping BAR #1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 	u32 cid_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	u32 reg_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 	u32 first_l4l5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	u32 ctx_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 	u32 config2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 	resource_size_t reg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 	cid_num = bnx2i_get_cid_num(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 	if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 		reg_base = pci_resource_start(ep->hba->pcidev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 					      BNX2X_DOORBELL_PCI_BAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 		reg_off = (1 << BNX2X_DB_SHIFT) * (cid_num & 0x1FFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 		ep->qp.ctx_base = ioremap(reg_base + reg_off, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 		if (!ep->qp.ctx_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 		goto arm_cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	    (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 		config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 		first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 		ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 		if (ctx_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 			reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 				  + BNX2I_570X_PAGE_SIZE_DEFAULT *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 				  (((cid_num - first_l4l5) / ctx_sz) + 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 			reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 		/* 5709 device in normal node and 5706/5708 devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 		reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 	ep->qp.ctx_base = ioremap(ep->hba->reg_base + reg_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 					  MB_KERNEL_CTX_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	if (!ep->qp.ctx_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) arm_cq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) }