18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2017 Broadcom. All Rights Reserved.
48c2ecf20Sopenharmony_ci * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Contact Information:
78c2ecf20Sopenharmony_ci * linux-drivers@broadcom.com
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _BEISCSI_MAIN_
118c2ecf20Sopenharmony_ci#define _BEISCSI_MAIN_
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/pci.h>
158c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
168c2ecf20Sopenharmony_ci#include <linux/in.h>
178c2ecf20Sopenharmony_ci#include <linux/ctype.h>
188c2ecf20Sopenharmony_ci#include <linux/module.h>
198c2ecf20Sopenharmony_ci#include <linux/aer.h>
208c2ecf20Sopenharmony_ci#include <scsi/scsi.h>
218c2ecf20Sopenharmony_ci#include <scsi/scsi_cmnd.h>
228c2ecf20Sopenharmony_ci#include <scsi/scsi_device.h>
238c2ecf20Sopenharmony_ci#include <scsi/scsi_host.h>
248c2ecf20Sopenharmony_ci#include <scsi/iscsi_proto.h>
258c2ecf20Sopenharmony_ci#include <scsi/libiscsi.h>
268c2ecf20Sopenharmony_ci#include <scsi/scsi_transport_iscsi.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define DRV_NAME		"be2iscsi"
298c2ecf20Sopenharmony_ci#define BUILD_STR		"11.4.0.1"
308c2ecf20Sopenharmony_ci#define BE_NAME			"Emulex OneConnect" \
318c2ecf20Sopenharmony_ci				"Open-iSCSI Driver version" BUILD_STR
328c2ecf20Sopenharmony_ci#define DRV_DESC		BE_NAME " " "Driver"
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define BE_VENDOR_ID		0x19A2
358c2ecf20Sopenharmony_ci#define ELX_VENDOR_ID		0x10DF
368c2ecf20Sopenharmony_ci/* DEVICE ID's for BE2 */
378c2ecf20Sopenharmony_ci#define BE_DEVICE_ID1		0x212
388c2ecf20Sopenharmony_ci#define OC_DEVICE_ID1		0x702
398c2ecf20Sopenharmony_ci#define OC_DEVICE_ID2		0x703
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* DEVICE ID's for BE3 */
428c2ecf20Sopenharmony_ci#define BE_DEVICE_ID2		0x222
438c2ecf20Sopenharmony_ci#define OC_DEVICE_ID3		0x712
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* DEVICE ID for SKH */
468c2ecf20Sopenharmony_ci#define OC_SKH_ID1		0x722
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define BE2_IO_DEPTH		1024
498c2ecf20Sopenharmony_ci#define BE2_MAX_SESSIONS	256
508c2ecf20Sopenharmony_ci#define BE2_TMFS		16
518c2ecf20Sopenharmony_ci#define BE2_NOPOUT_REQ		16
528c2ecf20Sopenharmony_ci#define BE2_SGE			32
538c2ecf20Sopenharmony_ci#define BE2_DEFPDU_HDR_SZ	64
548c2ecf20Sopenharmony_ci#define BE2_DEFPDU_DATA_SZ	8192
558c2ecf20Sopenharmony_ci#define BE2_MAX_NUM_CQ_PROC	512
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define MAX_CPUS		64U
588c2ecf20Sopenharmony_ci#define BEISCSI_MAX_NUM_CPUS	7
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define BEISCSI_VER_STRLEN 32
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define BEISCSI_SGLIST_ELEMENTS	30
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/**
658c2ecf20Sopenharmony_ci * BE_INVLDT_CMD_TBL_SZ is 128 which is total number commands that can
668c2ecf20Sopenharmony_ci * be invalidated at a time, consider it before changing the value of
678c2ecf20Sopenharmony_ci * BEISCSI_CMD_PER_LUN.
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_ci#define BEISCSI_CMD_PER_LUN	128	/* scsi_host->cmd_per_lun */
708c2ecf20Sopenharmony_ci#define BEISCSI_MAX_SECTORS	1024	/* scsi_host->max_sectors */
718c2ecf20Sopenharmony_ci#define BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE 128 /* Template size per cxn */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define BEISCSI_MAX_CMD_LEN	16	/* scsi_host->max_cmd_len */
748c2ecf20Sopenharmony_ci#define BEISCSI_NUM_MAX_LUN	256	/* scsi_host->max_lun */
758c2ecf20Sopenharmony_ci#define BEISCSI_MAX_FRAGS_INIT	192
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define BE_SENSE_INFO_SIZE		258
788c2ecf20Sopenharmony_ci#define BE_ISCSI_PDU_HEADER_SIZE	64
798c2ecf20Sopenharmony_ci#define BE_MIN_MEM_SIZE			16384
808c2ecf20Sopenharmony_ci#define MAX_CMD_SZ			65536
818c2ecf20Sopenharmony_ci#define IIOC_SCSI_DATA                  0x05	/* Write Operation */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/**
848c2ecf20Sopenharmony_ci * hardware needs the async PDU buffers to be posted in multiples of 8
858c2ecf20Sopenharmony_ci * So have atleast 8 of them by default
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define HWI_GET_ASYNC_PDU_CTX(phwi, ulp_num)	\
898c2ecf20Sopenharmony_ci	(phwi->phwi_ctxt->pasync_ctx[ulp_num])
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/********* Memory BAR register ************/
928c2ecf20Sopenharmony_ci#define PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET	0xfc
938c2ecf20Sopenharmony_ci/**
948c2ecf20Sopenharmony_ci * Host Interrupt Enable, if set interrupts are enabled although "PCI Interrupt
958c2ecf20Sopenharmony_ci * Disable" may still globally block interrupts in addition to individual
968c2ecf20Sopenharmony_ci * interrupt masks; a mechanism for the device driver to block all interrupts
978c2ecf20Sopenharmony_ci * atomically without having to arbitrate for the PCI Interrupt Disable bit
988c2ecf20Sopenharmony_ci * with the OS.
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci#define MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK	(1 << 29)	/* bit 29 */
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/********* ISR0 Register offset **********/
1038c2ecf20Sopenharmony_ci#define CEV_ISR0_OFFSET				0xC18
1048c2ecf20Sopenharmony_ci#define CEV_ISR_SIZE				4
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/**
1078c2ecf20Sopenharmony_ci * Macros for reading/writing a protection domain or CSR registers
1088c2ecf20Sopenharmony_ci * in BladeEngine.
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define DB_TXULP0_OFFSET 0x40
1128c2ecf20Sopenharmony_ci#define DB_RXULP0_OFFSET 0xA0
1138c2ecf20Sopenharmony_ci/********* Event Q door bell *************/
1148c2ecf20Sopenharmony_ci#define DB_EQ_OFFSET			DB_CQ_OFFSET
1158c2ecf20Sopenharmony_ci#define DB_EQ_RING_ID_LOW_MASK		0x1FF	/* bits 0 - 8 */
1168c2ecf20Sopenharmony_ci/* Clear the interrupt for this eq */
1178c2ecf20Sopenharmony_ci#define DB_EQ_CLR_SHIFT			(9)	/* bit 9 */
1188c2ecf20Sopenharmony_ci/* Must be 1 */
1198c2ecf20Sopenharmony_ci#define DB_EQ_EVNT_SHIFT		(10)	/* bit 10 */
1208c2ecf20Sopenharmony_ci/* Higher Order EQ_ID bit */
1218c2ecf20Sopenharmony_ci#define DB_EQ_RING_ID_HIGH_MASK	0x1F /* bits 11 - 15 */
1228c2ecf20Sopenharmony_ci#define DB_EQ_HIGH_SET_SHIFT	11
1238c2ecf20Sopenharmony_ci#define DB_EQ_HIGH_FEILD_SHIFT	9
1248c2ecf20Sopenharmony_ci/* Number of event entries processed */
1258c2ecf20Sopenharmony_ci#define DB_EQ_NUM_POPPED_SHIFT		(16)	/* bits 16 - 28 */
1268c2ecf20Sopenharmony_ci/* Rearm bit */
1278c2ecf20Sopenharmony_ci#define DB_EQ_REARM_SHIFT		(29)	/* bit 29 */
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/********* Compl Q door bell *************/
1308c2ecf20Sopenharmony_ci#define DB_CQ_OFFSET			0x120
1318c2ecf20Sopenharmony_ci#define DB_CQ_RING_ID_LOW_MASK		0x3FF	/* bits 0 - 9 */
1328c2ecf20Sopenharmony_ci/* Higher Order CQ_ID bit */
1338c2ecf20Sopenharmony_ci#define DB_CQ_RING_ID_HIGH_MASK	0x1F /* bits 11 - 15 */
1348c2ecf20Sopenharmony_ci#define DB_CQ_HIGH_SET_SHIFT	11
1358c2ecf20Sopenharmony_ci#define DB_CQ_HIGH_FEILD_SHIFT	10
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/* Number of event entries processed */
1388c2ecf20Sopenharmony_ci#define DB_CQ_NUM_POPPED_SHIFT		(16)	/* bits 16 - 28 */
1398c2ecf20Sopenharmony_ci/* Rearm bit */
1408c2ecf20Sopenharmony_ci#define DB_CQ_REARM_SHIFT		(29)	/* bit 29 */
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define GET_HWI_CONTROLLER_WS(pc)	(pc->phwi_ctrlr)
1438c2ecf20Sopenharmony_ci#define HWI_GET_DEF_BUFQ_ID(pc, ulp_num) (((struct hwi_controller *)\
1448c2ecf20Sopenharmony_ci		(GET_HWI_CONTROLLER_WS(pc)))->default_pdu_data[ulp_num].id)
1458c2ecf20Sopenharmony_ci#define HWI_GET_DEF_HDRQ_ID(pc, ulp_num) (((struct hwi_controller *)\
1468c2ecf20Sopenharmony_ci		(GET_HWI_CONTROLLER_WS(pc)))->default_pdu_hdr[ulp_num].id)
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#define PAGES_REQUIRED(x) \
1498c2ecf20Sopenharmony_ci	((x < PAGE_SIZE) ? 1 :  ((x + PAGE_SIZE - 1) / PAGE_SIZE))
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#define MEM_DESCR_OFFSET 8
1528c2ecf20Sopenharmony_ci#define BEISCSI_DEFQ_HDR 1
1538c2ecf20Sopenharmony_ci#define BEISCSI_DEFQ_DATA 0
1548c2ecf20Sopenharmony_cienum be_mem_enum {
1558c2ecf20Sopenharmony_ci	HWI_MEM_ADDN_CONTEXT,
1568c2ecf20Sopenharmony_ci	HWI_MEM_WRB,
1578c2ecf20Sopenharmony_ci	HWI_MEM_WRBH,
1588c2ecf20Sopenharmony_ci	HWI_MEM_SGLH,
1598c2ecf20Sopenharmony_ci	HWI_MEM_SGE,
1608c2ecf20Sopenharmony_ci	HWI_MEM_TEMPLATE_HDR_ULP0,
1618c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_HEADER_BUF_ULP0,	/* 6 */
1628c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_DATA_BUF_ULP0,
1638c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_HEADER_RING_ULP0,
1648c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_DATA_RING_ULP0,
1658c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_HEADER_HANDLE_ULP0,
1668c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_DATA_HANDLE_ULP0,	/* 11 */
1678c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_PDU_CONTEXT_ULP0,
1688c2ecf20Sopenharmony_ci	HWI_MEM_TEMPLATE_HDR_ULP1,
1698c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_HEADER_BUF_ULP1,	/* 14 */
1708c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_DATA_BUF_ULP1,
1718c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_HEADER_RING_ULP1,
1728c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_DATA_RING_ULP1,
1738c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_HEADER_HANDLE_ULP1,
1748c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_DATA_HANDLE_ULP1,	/* 19 */
1758c2ecf20Sopenharmony_ci	HWI_MEM_ASYNC_PDU_CONTEXT_ULP1,
1768c2ecf20Sopenharmony_ci	ISCSI_MEM_GLOBAL_HEADER,
1778c2ecf20Sopenharmony_ci	SE_MEM_MAX
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistruct be_bus_address32 {
1818c2ecf20Sopenharmony_ci	unsigned int address_lo;
1828c2ecf20Sopenharmony_ci	unsigned int address_hi;
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistruct be_bus_address64 {
1868c2ecf20Sopenharmony_ci	unsigned long long address;
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistruct be_bus_address {
1908c2ecf20Sopenharmony_ci	union {
1918c2ecf20Sopenharmony_ci		struct be_bus_address32 a32;
1928c2ecf20Sopenharmony_ci		struct be_bus_address64 a64;
1938c2ecf20Sopenharmony_ci	} u;
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistruct mem_array {
1978c2ecf20Sopenharmony_ci	struct be_bus_address bus_address;	/* Bus address of location */
1988c2ecf20Sopenharmony_ci	void *virtual_address;		/* virtual address to the location */
1998c2ecf20Sopenharmony_ci	unsigned int size;		/* Size required by memory block */
2008c2ecf20Sopenharmony_ci};
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistruct be_mem_descriptor {
2038c2ecf20Sopenharmony_ci	unsigned int size_in_bytes;	/* Size required by memory block */
2048c2ecf20Sopenharmony_ci	unsigned int num_elements;
2058c2ecf20Sopenharmony_ci	struct mem_array *mem_array;
2068c2ecf20Sopenharmony_ci};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistruct sgl_handle {
2098c2ecf20Sopenharmony_ci	unsigned int sgl_index;
2108c2ecf20Sopenharmony_ci	unsigned int type;
2118c2ecf20Sopenharmony_ci	unsigned int cid;
2128c2ecf20Sopenharmony_ci	struct iscsi_task *task;
2138c2ecf20Sopenharmony_ci	struct iscsi_sge *pfrag;
2148c2ecf20Sopenharmony_ci};
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cistruct hba_parameters {
2178c2ecf20Sopenharmony_ci	unsigned int ios_per_ctrl;
2188c2ecf20Sopenharmony_ci	unsigned int cxns_per_ctrl;
2198c2ecf20Sopenharmony_ci	unsigned int icds_per_ctrl;
2208c2ecf20Sopenharmony_ci	unsigned int num_sge_per_io;
2218c2ecf20Sopenharmony_ci	unsigned int defpdu_hdr_sz;
2228c2ecf20Sopenharmony_ci	unsigned int defpdu_data_sz;
2238c2ecf20Sopenharmony_ci	unsigned int num_cq_entries;
2248c2ecf20Sopenharmony_ci	unsigned int num_eq_entries;
2258c2ecf20Sopenharmony_ci	unsigned int wrbs_per_cxn;
2268c2ecf20Sopenharmony_ci	unsigned int hwi_ws_sz;
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cri) \
2308c2ecf20Sopenharmony_ci	(phwi_ctrlr->wrb_context[cri].ulp_num)
2318c2ecf20Sopenharmony_cistruct hwi_wrb_context {
2328c2ecf20Sopenharmony_ci	spinlock_t wrb_lock;
2338c2ecf20Sopenharmony_ci	struct wrb_handle **pwrb_handle_base;
2348c2ecf20Sopenharmony_ci	struct wrb_handle **pwrb_handle_basestd;
2358c2ecf20Sopenharmony_ci	struct iscsi_wrb *plast_wrb;
2368c2ecf20Sopenharmony_ci	unsigned short alloc_index;
2378c2ecf20Sopenharmony_ci	unsigned short free_index;
2388c2ecf20Sopenharmony_ci	unsigned short wrb_handles_available;
2398c2ecf20Sopenharmony_ci	unsigned short cid;
2408c2ecf20Sopenharmony_ci	uint8_t ulp_num;	/* ULP to which CID binded */
2418c2ecf20Sopenharmony_ci	uint32_t doorbell_offset;
2428c2ecf20Sopenharmony_ci};
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistruct ulp_cid_info {
2458c2ecf20Sopenharmony_ci	unsigned short *cid_array;
2468c2ecf20Sopenharmony_ci	unsigned short avlbl_cids;
2478c2ecf20Sopenharmony_ci	unsigned short cid_alloc;
2488c2ecf20Sopenharmony_ci	unsigned short cid_free;
2498c2ecf20Sopenharmony_ci};
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci#include "be.h"
2528c2ecf20Sopenharmony_ci#define chip_be2(phba)      (phba->generation == BE_GEN2)
2538c2ecf20Sopenharmony_ci#define chip_be3_r(phba)    (phba->generation == BE_GEN3)
2548c2ecf20Sopenharmony_ci#define is_chip_be2_be3r(phba) (chip_be3_r(phba) || (chip_be2(phba)))
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci#define BEISCSI_ULP0    0
2578c2ecf20Sopenharmony_ci#define BEISCSI_ULP1    1
2588c2ecf20Sopenharmony_ci#define BEISCSI_ULP_COUNT   2
2598c2ecf20Sopenharmony_ci#define BEISCSI_ULP0_LOADED 0x01
2608c2ecf20Sopenharmony_ci#define BEISCSI_ULP1_LOADED 0x02
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci#define BEISCSI_ULP_AVLBL_CID(phba, ulp_num) \
2638c2ecf20Sopenharmony_ci	(((struct ulp_cid_info *)phba->cid_array_info[ulp_num])->avlbl_cids)
2648c2ecf20Sopenharmony_ci#define BEISCSI_ULP0_AVLBL_CID(phba) \
2658c2ecf20Sopenharmony_ci	BEISCSI_ULP_AVLBL_CID(phba, BEISCSI_ULP0)
2668c2ecf20Sopenharmony_ci#define BEISCSI_ULP1_AVLBL_CID(phba) \
2678c2ecf20Sopenharmony_ci	BEISCSI_ULP_AVLBL_CID(phba, BEISCSI_ULP1)
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistruct beiscsi_hba {
2708c2ecf20Sopenharmony_ci	struct hba_parameters params;
2718c2ecf20Sopenharmony_ci	struct hwi_controller *phwi_ctrlr;
2728c2ecf20Sopenharmony_ci	unsigned int mem_req[SE_MEM_MAX];
2738c2ecf20Sopenharmony_ci	/* PCI BAR mapped addresses */
2748c2ecf20Sopenharmony_ci	u8 __iomem *csr_va;	/* CSR */
2758c2ecf20Sopenharmony_ci	u8 __iomem *db_va;	/* Door  Bell  */
2768c2ecf20Sopenharmony_ci	u8 __iomem *pci_va;	/* PCI Config */
2778c2ecf20Sopenharmony_ci	/* PCI representation of our HBA */
2788c2ecf20Sopenharmony_ci	struct pci_dev *pcidev;
2798c2ecf20Sopenharmony_ci	unsigned int num_cpus;
2808c2ecf20Sopenharmony_ci	unsigned int nxt_cqid;
2818c2ecf20Sopenharmony_ci	char *msi_name[MAX_CPUS];
2828c2ecf20Sopenharmony_ci	struct be_mem_descriptor *init_mem;
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci	unsigned short io_sgl_alloc_index;
2858c2ecf20Sopenharmony_ci	unsigned short io_sgl_free_index;
2868c2ecf20Sopenharmony_ci	unsigned short io_sgl_hndl_avbl;
2878c2ecf20Sopenharmony_ci	struct sgl_handle **io_sgl_hndl_base;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	unsigned short eh_sgl_alloc_index;
2908c2ecf20Sopenharmony_ci	unsigned short eh_sgl_free_index;
2918c2ecf20Sopenharmony_ci	unsigned short eh_sgl_hndl_avbl;
2928c2ecf20Sopenharmony_ci	struct sgl_handle **eh_sgl_hndl_base;
2938c2ecf20Sopenharmony_ci	spinlock_t io_sgl_lock;
2948c2ecf20Sopenharmony_ci	spinlock_t mgmt_sgl_lock;
2958c2ecf20Sopenharmony_ci	spinlock_t async_pdu_lock;
2968c2ecf20Sopenharmony_ci	struct list_head hba_queue;
2978c2ecf20Sopenharmony_ci#define BE_MAX_SESSION 2048
2988c2ecf20Sopenharmony_ci#define BE_INVALID_CID 0xffff
2998c2ecf20Sopenharmony_ci#define BE_SET_CID_TO_CRI(cri_index, cid) \
3008c2ecf20Sopenharmony_ci			  (phba->cid_to_cri_map[cid] = cri_index)
3018c2ecf20Sopenharmony_ci#define BE_GET_CRI_FROM_CID(cid) (phba->cid_to_cri_map[cid])
3028c2ecf20Sopenharmony_ci	unsigned short cid_to_cri_map[BE_MAX_SESSION];
3038c2ecf20Sopenharmony_ci	struct ulp_cid_info *cid_array_info[BEISCSI_ULP_COUNT];
3048c2ecf20Sopenharmony_ci	struct iscsi_endpoint **ep_array;
3058c2ecf20Sopenharmony_ci	struct beiscsi_conn **conn_table;
3068c2ecf20Sopenharmony_ci	struct Scsi_Host *shost;
3078c2ecf20Sopenharmony_ci	struct iscsi_iface *ipv4_iface;
3088c2ecf20Sopenharmony_ci	struct iscsi_iface *ipv6_iface;
3098c2ecf20Sopenharmony_ci	struct {
3108c2ecf20Sopenharmony_ci		/**
3118c2ecf20Sopenharmony_ci		 * group together since they are used most frequently
3128c2ecf20Sopenharmony_ci		 * for cid to cri conversion
3138c2ecf20Sopenharmony_ci		 */
3148c2ecf20Sopenharmony_ci#define BEISCSI_PHYS_PORT_MAX	4
3158c2ecf20Sopenharmony_ci		unsigned int phys_port;
3168c2ecf20Sopenharmony_ci		/* valid values of phys_port id are 0, 1, 2, 3 */
3178c2ecf20Sopenharmony_ci		unsigned int eqid_count;
3188c2ecf20Sopenharmony_ci		unsigned int cqid_count;
3198c2ecf20Sopenharmony_ci		unsigned int iscsi_cid_start[BEISCSI_ULP_COUNT];
3208c2ecf20Sopenharmony_ci#define BEISCSI_GET_CID_COUNT(phba, ulp_num) \
3218c2ecf20Sopenharmony_ci		(phba->fw_config.iscsi_cid_count[ulp_num])
3228c2ecf20Sopenharmony_ci		unsigned int iscsi_cid_count[BEISCSI_ULP_COUNT];
3238c2ecf20Sopenharmony_ci		unsigned int iscsi_icd_count[BEISCSI_ULP_COUNT];
3248c2ecf20Sopenharmony_ci		unsigned int iscsi_icd_start[BEISCSI_ULP_COUNT];
3258c2ecf20Sopenharmony_ci		unsigned int iscsi_chain_start[BEISCSI_ULP_COUNT];
3268c2ecf20Sopenharmony_ci		unsigned int iscsi_chain_count[BEISCSI_ULP_COUNT];
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci		unsigned short iscsi_features;
3298c2ecf20Sopenharmony_ci		uint16_t dual_ulp_aware;
3308c2ecf20Sopenharmony_ci		unsigned long ulp_supported;
3318c2ecf20Sopenharmony_ci	} fw_config;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	unsigned long state;
3348c2ecf20Sopenharmony_ci#define BEISCSI_HBA_ONLINE	0
3358c2ecf20Sopenharmony_ci#define BEISCSI_HBA_LINK_UP	1
3368c2ecf20Sopenharmony_ci#define BEISCSI_HBA_BOOT_FOUND	2
3378c2ecf20Sopenharmony_ci#define BEISCSI_HBA_BOOT_WORK	3
3388c2ecf20Sopenharmony_ci#define BEISCSI_HBA_UER_SUPP	4
3398c2ecf20Sopenharmony_ci#define BEISCSI_HBA_PCI_ERR	5
3408c2ecf20Sopenharmony_ci#define BEISCSI_HBA_FW_TIMEOUT	6
3418c2ecf20Sopenharmony_ci#define BEISCSI_HBA_IN_UE	7
3428c2ecf20Sopenharmony_ci#define BEISCSI_HBA_IN_TPE	8
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci/* error bits */
3458c2ecf20Sopenharmony_ci#define BEISCSI_HBA_IN_ERR	((1 << BEISCSI_HBA_PCI_ERR) | \
3468c2ecf20Sopenharmony_ci				 (1 << BEISCSI_HBA_FW_TIMEOUT) | \
3478c2ecf20Sopenharmony_ci				 (1 << BEISCSI_HBA_IN_UE) | \
3488c2ecf20Sopenharmony_ci				 (1 << BEISCSI_HBA_IN_TPE))
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	u8 optic_state;
3518c2ecf20Sopenharmony_ci	struct delayed_work eqd_update;
3528c2ecf20Sopenharmony_ci	/* update EQ delay timer every 1000ms */
3538c2ecf20Sopenharmony_ci#define BEISCSI_EQD_UPDATE_INTERVAL	1000
3548c2ecf20Sopenharmony_ci	struct timer_list hw_check;
3558c2ecf20Sopenharmony_ci	/* check for UE every 1000ms */
3568c2ecf20Sopenharmony_ci#define BEISCSI_UE_DETECT_INTERVAL	1000
3578c2ecf20Sopenharmony_ci	u32 ue2rp;
3588c2ecf20Sopenharmony_ci	struct delayed_work recover_port;
3598c2ecf20Sopenharmony_ci	struct work_struct sess_work;
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	bool mac_addr_set;
3628c2ecf20Sopenharmony_ci	u8 mac_address[ETH_ALEN];
3638c2ecf20Sopenharmony_ci	u8 port_name;
3648c2ecf20Sopenharmony_ci	u8 port_speed;
3658c2ecf20Sopenharmony_ci	char fw_ver_str[BEISCSI_VER_STRLEN];
3668c2ecf20Sopenharmony_ci	struct workqueue_struct *wq;	/* The actuak work queue */
3678c2ecf20Sopenharmony_ci	struct be_ctrl_info ctrl;
3688c2ecf20Sopenharmony_ci	unsigned int generation;
3698c2ecf20Sopenharmony_ci	unsigned int interface_handle;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	struct be_aic_obj aic_obj[MAX_CPUS];
3728c2ecf20Sopenharmony_ci	unsigned int attr_log_enable;
3738c2ecf20Sopenharmony_ci	int (*iotask_fn)(struct iscsi_task *,
3748c2ecf20Sopenharmony_ci			struct scatterlist *sg,
3758c2ecf20Sopenharmony_ci			uint32_t num_sg, uint32_t xferlen,
3768c2ecf20Sopenharmony_ci			uint32_t writedir);
3778c2ecf20Sopenharmony_ci	struct boot_struct {
3788c2ecf20Sopenharmony_ci		int retry;
3798c2ecf20Sopenharmony_ci		unsigned int tag;
3808c2ecf20Sopenharmony_ci		unsigned int s_handle;
3818c2ecf20Sopenharmony_ci		struct be_dma_mem nonemb_cmd;
3828c2ecf20Sopenharmony_ci		enum {
3838c2ecf20Sopenharmony_ci			BEISCSI_BOOT_REOPEN_SESS = 1,
3848c2ecf20Sopenharmony_ci			BEISCSI_BOOT_GET_SHANDLE,
3858c2ecf20Sopenharmony_ci			BEISCSI_BOOT_GET_SINFO,
3868c2ecf20Sopenharmony_ci			BEISCSI_BOOT_LOGOUT_SESS,
3878c2ecf20Sopenharmony_ci			BEISCSI_BOOT_CREATE_KSET,
3888c2ecf20Sopenharmony_ci		} action;
3898c2ecf20Sopenharmony_ci		struct mgmt_session_info boot_sess;
3908c2ecf20Sopenharmony_ci		struct iscsi_boot_kset *boot_kset;
3918c2ecf20Sopenharmony_ci	} boot_struct;
3928c2ecf20Sopenharmony_ci	struct work_struct boot_work;
3938c2ecf20Sopenharmony_ci};
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci#define beiscsi_hba_in_error(phba) ((phba)->state & BEISCSI_HBA_IN_ERR)
3968c2ecf20Sopenharmony_ci#define beiscsi_hba_is_online(phba) \
3978c2ecf20Sopenharmony_ci	(!beiscsi_hba_in_error((phba)) && \
3988c2ecf20Sopenharmony_ci	 test_bit(BEISCSI_HBA_ONLINE, &phba->state))
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistruct beiscsi_session {
4018c2ecf20Sopenharmony_ci	struct dma_pool *bhs_pool;
4028c2ecf20Sopenharmony_ci};
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci/**
4058c2ecf20Sopenharmony_ci * struct beiscsi_conn - iscsi connection structure
4068c2ecf20Sopenharmony_ci */
4078c2ecf20Sopenharmony_cistruct beiscsi_conn {
4088c2ecf20Sopenharmony_ci	struct iscsi_conn *conn;
4098c2ecf20Sopenharmony_ci	struct beiscsi_hba *phba;
4108c2ecf20Sopenharmony_ci	u32 exp_statsn;
4118c2ecf20Sopenharmony_ci	u32 doorbell_offset;
4128c2ecf20Sopenharmony_ci	u32 beiscsi_conn_cid;
4138c2ecf20Sopenharmony_ci	struct beiscsi_endpoint *ep;
4148c2ecf20Sopenharmony_ci	unsigned short login_in_progress;
4158c2ecf20Sopenharmony_ci	struct wrb_handle *plogin_wrb_handle;
4168c2ecf20Sopenharmony_ci	struct sgl_handle *plogin_sgl_handle;
4178c2ecf20Sopenharmony_ci	struct beiscsi_session *beiscsi_sess;
4188c2ecf20Sopenharmony_ci	struct iscsi_task *task;
4198c2ecf20Sopenharmony_ci};
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci/* This structure is used by the chip */
4228c2ecf20Sopenharmony_cistruct pdu_data_out {
4238c2ecf20Sopenharmony_ci	u32 dw[12];
4248c2ecf20Sopenharmony_ci};
4258c2ecf20Sopenharmony_ci/**
4268c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
4278c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
4288c2ecf20Sopenharmony_ci */
4298c2ecf20Sopenharmony_cistruct amap_pdu_data_out {
4308c2ecf20Sopenharmony_ci	u8 opcode[6];		/* opcode */
4318c2ecf20Sopenharmony_ci	u8 rsvd0[2];		/* should be 0 */
4328c2ecf20Sopenharmony_ci	u8 rsvd1[7];
4338c2ecf20Sopenharmony_ci	u8 final_bit;		/* F bit */
4348c2ecf20Sopenharmony_ci	u8 rsvd2[16];
4358c2ecf20Sopenharmony_ci	u8 ahs_length[8];	/* no AHS */
4368c2ecf20Sopenharmony_ci	u8 data_len_hi[8];
4378c2ecf20Sopenharmony_ci	u8 data_len_lo[16];	/* DataSegmentLength */
4388c2ecf20Sopenharmony_ci	u8 lun[64];
4398c2ecf20Sopenharmony_ci	u8 itt[32];		/* ITT; initiator task tag */
4408c2ecf20Sopenharmony_ci	u8 ttt[32];		/* TTT; valid for R2T or 0xffffffff */
4418c2ecf20Sopenharmony_ci	u8 rsvd3[32];
4428c2ecf20Sopenharmony_ci	u8 exp_stat_sn[32];
4438c2ecf20Sopenharmony_ci	u8 rsvd4[32];
4448c2ecf20Sopenharmony_ci	u8 data_sn[32];
4458c2ecf20Sopenharmony_ci	u8 buffer_offset[32];
4468c2ecf20Sopenharmony_ci	u8 rsvd5[32];
4478c2ecf20Sopenharmony_ci};
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_cistruct be_cmd_bhs {
4508c2ecf20Sopenharmony_ci	struct iscsi_scsi_req iscsi_hdr;
4518c2ecf20Sopenharmony_ci	unsigned char pad1[16];
4528c2ecf20Sopenharmony_ci	struct pdu_data_out iscsi_data_pdu;
4538c2ecf20Sopenharmony_ci	unsigned char pad2[BE_SENSE_INFO_SIZE -
4548c2ecf20Sopenharmony_ci			sizeof(struct pdu_data_out)];
4558c2ecf20Sopenharmony_ci};
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistruct beiscsi_io_task {
4588c2ecf20Sopenharmony_ci	struct wrb_handle *pwrb_handle;
4598c2ecf20Sopenharmony_ci	struct sgl_handle *psgl_handle;
4608c2ecf20Sopenharmony_ci	struct beiscsi_conn *conn;
4618c2ecf20Sopenharmony_ci	struct scsi_cmnd *scsi_cmnd;
4628c2ecf20Sopenharmony_ci	int num_sg;
4638c2ecf20Sopenharmony_ci	struct hwi_wrb_context *pwrb_context;
4648c2ecf20Sopenharmony_ci	itt_t libiscsi_itt;
4658c2ecf20Sopenharmony_ci	struct be_cmd_bhs *cmd_bhs;
4668c2ecf20Sopenharmony_ci	struct be_bus_address bhs_pa;
4678c2ecf20Sopenharmony_ci	unsigned short bhs_len;
4688c2ecf20Sopenharmony_ci	dma_addr_t mtask_addr;
4698c2ecf20Sopenharmony_ci	uint32_t mtask_data_count;
4708c2ecf20Sopenharmony_ci	uint8_t wrb_type;
4718c2ecf20Sopenharmony_ci};
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistruct be_nonio_bhs {
4748c2ecf20Sopenharmony_ci	struct iscsi_hdr iscsi_hdr;
4758c2ecf20Sopenharmony_ci	unsigned char pad1[16];
4768c2ecf20Sopenharmony_ci	struct pdu_data_out iscsi_data_pdu;
4778c2ecf20Sopenharmony_ci	unsigned char pad2[BE_SENSE_INFO_SIZE -
4788c2ecf20Sopenharmony_ci			sizeof(struct pdu_data_out)];
4798c2ecf20Sopenharmony_ci};
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_cistruct be_status_bhs {
4828c2ecf20Sopenharmony_ci	struct iscsi_scsi_req iscsi_hdr;
4838c2ecf20Sopenharmony_ci	unsigned char pad1[16];
4848c2ecf20Sopenharmony_ci	/**
4858c2ecf20Sopenharmony_ci	 * The plus 2 below is to hold the sense info length that gets
4868c2ecf20Sopenharmony_ci	 * DMA'ed by RxULP
4878c2ecf20Sopenharmony_ci	 */
4888c2ecf20Sopenharmony_ci	unsigned char sense_info[BE_SENSE_INFO_SIZE];
4898c2ecf20Sopenharmony_ci};
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_cistruct iscsi_sge {
4928c2ecf20Sopenharmony_ci	u32 dw[4];
4938c2ecf20Sopenharmony_ci};
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci/**
4968c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
4978c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
4988c2ecf20Sopenharmony_ci */
4998c2ecf20Sopenharmony_cistruct amap_iscsi_sge {
5008c2ecf20Sopenharmony_ci	u8 addr_hi[32];
5018c2ecf20Sopenharmony_ci	u8 addr_lo[32];
5028c2ecf20Sopenharmony_ci	u8 sge_offset[22];	/* DWORD 2 */
5038c2ecf20Sopenharmony_ci	u8 rsvd0[9];		/* DWORD 2 */
5048c2ecf20Sopenharmony_ci	u8 last_sge;		/* DWORD 2 */
5058c2ecf20Sopenharmony_ci	u8 len[17];		/* DWORD 3 */
5068c2ecf20Sopenharmony_ci	u8 rsvd1[15];		/* DWORD 3 */
5078c2ecf20Sopenharmony_ci};
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_cistruct beiscsi_offload_params {
5108c2ecf20Sopenharmony_ci	u32 dw[6];
5118c2ecf20Sopenharmony_ci};
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_ERL	0x00000003
5148c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_DDE	0x00000004
5158c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_HDE	0x00000008
5168c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_IR2T	0x00000010
5178c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_IMD	0x00000020
5188c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_DATA_SEQ_INORDER   0x00000040
5198c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_PDU_SEQ_INORDER    0x00000080
5208c2ecf20Sopenharmony_ci#define OFFLD_PARAMS_MAX_R2T 0x00FFFF00
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci/**
5238c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
5248c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
5258c2ecf20Sopenharmony_ci */
5268c2ecf20Sopenharmony_cistruct amap_beiscsi_offload_params {
5278c2ecf20Sopenharmony_ci	u8 max_burst_length[32];
5288c2ecf20Sopenharmony_ci	u8 max_send_data_segment_length[32];
5298c2ecf20Sopenharmony_ci	u8 first_burst_length[32];
5308c2ecf20Sopenharmony_ci	u8 erl[2];
5318c2ecf20Sopenharmony_ci	u8 dde[1];
5328c2ecf20Sopenharmony_ci	u8 hde[1];
5338c2ecf20Sopenharmony_ci	u8 ir2t[1];
5348c2ecf20Sopenharmony_ci	u8 imd[1];
5358c2ecf20Sopenharmony_ci	u8 data_seq_inorder[1];
5368c2ecf20Sopenharmony_ci	u8 pdu_seq_inorder[1];
5378c2ecf20Sopenharmony_ci	u8 max_r2t[16];
5388c2ecf20Sopenharmony_ci	u8 pad[8];
5398c2ecf20Sopenharmony_ci	u8 exp_statsn[32];
5408c2ecf20Sopenharmony_ci	u8 max_recv_data_segment_length[32];
5418c2ecf20Sopenharmony_ci};
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistruct hd_async_handle {
5448c2ecf20Sopenharmony_ci	struct list_head link;
5458c2ecf20Sopenharmony_ci	struct be_bus_address pa;
5468c2ecf20Sopenharmony_ci	void *pbuffer;
5478c2ecf20Sopenharmony_ci	u32 buffer_len;
5488c2ecf20Sopenharmony_ci	u16 index;
5498c2ecf20Sopenharmony_ci	u16 cri;
5508c2ecf20Sopenharmony_ci	u8 is_header;
5518c2ecf20Sopenharmony_ci	u8 is_final;
5528c2ecf20Sopenharmony_ci	u8 in_use;
5538c2ecf20Sopenharmony_ci};
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_ci#define BEISCSI_ASYNC_HDQ_SIZE(phba, ulp) \
5568c2ecf20Sopenharmony_ci	(BEISCSI_GET_CID_COUNT((phba), (ulp)) * 2)
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci/**
5598c2ecf20Sopenharmony_ci * This has list of async PDUs that are waiting to be processed.
5608c2ecf20Sopenharmony_ci * Buffers live in this list for a brief duration before they get
5618c2ecf20Sopenharmony_ci * processed and posted back to hardware.
5628c2ecf20Sopenharmony_ci * Note that we don't really need one cri_wait_queue per async_entry.
5638c2ecf20Sopenharmony_ci * We need one cri_wait_queue per CRI. Its easier to manage if this
5648c2ecf20Sopenharmony_ci * is tagged along with the async_entry.
5658c2ecf20Sopenharmony_ci */
5668c2ecf20Sopenharmony_cistruct hd_async_entry {
5678c2ecf20Sopenharmony_ci	struct cri_wait_queue {
5688c2ecf20Sopenharmony_ci		unsigned short hdr_len;
5698c2ecf20Sopenharmony_ci		unsigned int bytes_received;
5708c2ecf20Sopenharmony_ci		unsigned int bytes_needed;
5718c2ecf20Sopenharmony_ci		struct list_head list;
5728c2ecf20Sopenharmony_ci	} wq;
5738c2ecf20Sopenharmony_ci	/* handles posted to FW resides here */
5748c2ecf20Sopenharmony_ci	struct hd_async_handle *header;
5758c2ecf20Sopenharmony_ci	struct hd_async_handle *data;
5768c2ecf20Sopenharmony_ci};
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_cistruct hd_async_buf_context {
5798c2ecf20Sopenharmony_ci	struct be_bus_address pa_base;
5808c2ecf20Sopenharmony_ci	void *va_base;
5818c2ecf20Sopenharmony_ci	void *ring_base;
5828c2ecf20Sopenharmony_ci	struct hd_async_handle *handle_base;
5838c2ecf20Sopenharmony_ci	u32 buffer_size;
5848c2ecf20Sopenharmony_ci	u16 pi;
5858c2ecf20Sopenharmony_ci};
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci/**
5888c2ecf20Sopenharmony_ci * hd_async_context is declared for each ULP supporting iSCSI function.
5898c2ecf20Sopenharmony_ci */
5908c2ecf20Sopenharmony_cistruct hd_async_context {
5918c2ecf20Sopenharmony_ci	struct hd_async_buf_context async_header;
5928c2ecf20Sopenharmony_ci	struct hd_async_buf_context async_data;
5938c2ecf20Sopenharmony_ci	u16 num_entries;
5948c2ecf20Sopenharmony_ci	/**
5958c2ecf20Sopenharmony_ci	 * When unsol PDU is in, it needs to be chained till all the bytes are
5968c2ecf20Sopenharmony_ci	 * received and then processing is done. hd_async_entry is created
5978c2ecf20Sopenharmony_ci	 * based on the cid_count for each ULP. When unsol PDU comes in based
5988c2ecf20Sopenharmony_ci	 * on the conn_id it needs to be added to the correct async_entry wq.
5998c2ecf20Sopenharmony_ci	 * Below defined cid_to_async_cri_map is used to reterive the
6008c2ecf20Sopenharmony_ci	 * async_cri_map for a particular connection.
6018c2ecf20Sopenharmony_ci	 *
6028c2ecf20Sopenharmony_ci	 * This array is initialized after beiscsi_create_wrb_rings returns.
6038c2ecf20Sopenharmony_ci	 *
6048c2ecf20Sopenharmony_ci	 * - this method takes more memory space, fixed to 2K
6058c2ecf20Sopenharmony_ci	 * - any support for connections greater than this the array size needs
6068c2ecf20Sopenharmony_ci	 * to be incremented
6078c2ecf20Sopenharmony_ci	 */
6088c2ecf20Sopenharmony_ci#define BE_GET_ASYNC_CRI_FROM_CID(cid) (pasync_ctx->cid_to_async_cri_map[cid])
6098c2ecf20Sopenharmony_ci	unsigned short cid_to_async_cri_map[BE_MAX_SESSION];
6108c2ecf20Sopenharmony_ci	/**
6118c2ecf20Sopenharmony_ci	 * This is a variable size array. Don`t add anything after this field!!
6128c2ecf20Sopenharmony_ci	 */
6138c2ecf20Sopenharmony_ci	struct hd_async_entry *async_entry;
6148c2ecf20Sopenharmony_ci};
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_cistruct i_t_dpdu_cqe {
6178c2ecf20Sopenharmony_ci	u32 dw[4];
6188c2ecf20Sopenharmony_ci} __packed;
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci/**
6218c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
6228c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
6238c2ecf20Sopenharmony_ci */
6248c2ecf20Sopenharmony_cistruct amap_i_t_dpdu_cqe {
6258c2ecf20Sopenharmony_ci	u8 db_addr_hi[32];
6268c2ecf20Sopenharmony_ci	u8 db_addr_lo[32];
6278c2ecf20Sopenharmony_ci	u8 code[6];
6288c2ecf20Sopenharmony_ci	u8 cid[10];
6298c2ecf20Sopenharmony_ci	u8 dpl[16];
6308c2ecf20Sopenharmony_ci	u8 index[16];
6318c2ecf20Sopenharmony_ci	u8 num_cons[10];
6328c2ecf20Sopenharmony_ci	u8 rsvd0[4];
6338c2ecf20Sopenharmony_ci	u8 final;
6348c2ecf20Sopenharmony_ci	u8 valid;
6358c2ecf20Sopenharmony_ci} __packed;
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_cistruct amap_i_t_dpdu_cqe_v2 {
6388c2ecf20Sopenharmony_ci	u8 db_addr_hi[32];  /* DWORD 0 */
6398c2ecf20Sopenharmony_ci	u8 db_addr_lo[32];  /* DWORD 1 */
6408c2ecf20Sopenharmony_ci	u8 code[6]; /* DWORD 2 */
6418c2ecf20Sopenharmony_ci	u8 num_cons; /* DWORD 2*/
6428c2ecf20Sopenharmony_ci	u8 rsvd0[8]; /* DWORD 2 */
6438c2ecf20Sopenharmony_ci	u8 dpl[17]; /* DWORD 2 */
6448c2ecf20Sopenharmony_ci	u8 index[16]; /* DWORD 3 */
6458c2ecf20Sopenharmony_ci	u8 cid[13]; /* DWORD 3 */
6468c2ecf20Sopenharmony_ci	u8 rsvd1; /* DWORD 3 */
6478c2ecf20Sopenharmony_ci	u8 final; /* DWORD 3 */
6488c2ecf20Sopenharmony_ci	u8 valid; /* DWORD 3 */
6498c2ecf20Sopenharmony_ci} __packed;
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci#define CQE_VALID_MASK	0x80000000
6528c2ecf20Sopenharmony_ci#define CQE_CODE_MASK	0x0000003F
6538c2ecf20Sopenharmony_ci#define CQE_CID_MASK	0x0000FFC0
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci#define EQE_VALID_MASK		0x00000001
6568c2ecf20Sopenharmony_ci#define EQE_MAJORCODE_MASK	0x0000000E
6578c2ecf20Sopenharmony_ci#define EQE_RESID_MASK		0xFFFF0000
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_cistruct be_eq_entry {
6608c2ecf20Sopenharmony_ci	u32 dw[1];
6618c2ecf20Sopenharmony_ci} __packed;
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci/**
6648c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
6658c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
6668c2ecf20Sopenharmony_ci */
6678c2ecf20Sopenharmony_cistruct amap_eq_entry {
6688c2ecf20Sopenharmony_ci	u8 valid;		/* DWORD 0 */
6698c2ecf20Sopenharmony_ci	u8 major_code[3];	/* DWORD 0 */
6708c2ecf20Sopenharmony_ci	u8 minor_code[12];	/* DWORD 0 */
6718c2ecf20Sopenharmony_ci	u8 resource_id[16];	/* DWORD 0 */
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci} __packed;
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_cistruct cq_db {
6768c2ecf20Sopenharmony_ci	u32 dw[1];
6778c2ecf20Sopenharmony_ci} __packed;
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci/**
6808c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
6818c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
6828c2ecf20Sopenharmony_ci */
6838c2ecf20Sopenharmony_cistruct amap_cq_db {
6848c2ecf20Sopenharmony_ci	u8 qid[10];
6858c2ecf20Sopenharmony_ci	u8 event[1];
6868c2ecf20Sopenharmony_ci	u8 rsvd0[5];
6878c2ecf20Sopenharmony_ci	u8 num_popped[13];
6888c2ecf20Sopenharmony_ci	u8 rearm[1];
6898c2ecf20Sopenharmony_ci	u8 rsvd1[2];
6908c2ecf20Sopenharmony_ci} __packed;
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_civoid beiscsi_process_eq(struct beiscsi_hba *phba);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_cistruct iscsi_wrb {
6958c2ecf20Sopenharmony_ci	u32 dw[16];
6968c2ecf20Sopenharmony_ci} __packed;
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci#define WRB_TYPE_MASK 0xF0000000
6998c2ecf20Sopenharmony_ci#define SKH_WRB_TYPE_OFFSET 27
7008c2ecf20Sopenharmony_ci#define BE_WRB_TYPE_OFFSET  28
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci#define ADAPTER_SET_WRB_TYPE(pwrb, wrb_type, type_offset) \
7038c2ecf20Sopenharmony_ci		(pwrb->dw[0] |= (wrb_type << type_offset))
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci/**
7068c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
7078c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
7088c2ecf20Sopenharmony_ci */
7098c2ecf20Sopenharmony_cistruct amap_iscsi_wrb {
7108c2ecf20Sopenharmony_ci	u8 lun[14];		/* DWORD 0 */
7118c2ecf20Sopenharmony_ci	u8 lt;			/* DWORD 0 */
7128c2ecf20Sopenharmony_ci	u8 invld;		/* DWORD 0 */
7138c2ecf20Sopenharmony_ci	u8 wrb_idx[8];		/* DWORD 0 */
7148c2ecf20Sopenharmony_ci	u8 dsp;			/* DWORD 0 */
7158c2ecf20Sopenharmony_ci	u8 dmsg;		/* DWORD 0 */
7168c2ecf20Sopenharmony_ci	u8 undr_run;		/* DWORD 0 */
7178c2ecf20Sopenharmony_ci	u8 over_run;		/* DWORD 0 */
7188c2ecf20Sopenharmony_ci	u8 type[4];		/* DWORD 0 */
7198c2ecf20Sopenharmony_ci	u8 ptr2nextwrb[8];	/* DWORD 1 */
7208c2ecf20Sopenharmony_ci	u8 r2t_exp_dtl[24];	/* DWORD 1 */
7218c2ecf20Sopenharmony_ci	u8 sgl_icd_idx[12];	/* DWORD 2 */
7228c2ecf20Sopenharmony_ci	u8 rsvd0[20];		/* DWORD 2 */
7238c2ecf20Sopenharmony_ci	u8 exp_data_sn[32];	/* DWORD 3 */
7248c2ecf20Sopenharmony_ci	u8 iscsi_bhs_addr_hi[32];	/* DWORD 4 */
7258c2ecf20Sopenharmony_ci	u8 iscsi_bhs_addr_lo[32];	/* DWORD 5 */
7268c2ecf20Sopenharmony_ci	u8 cmdsn_itt[32];	/* DWORD 6 */
7278c2ecf20Sopenharmony_ci	u8 dif_ref_tag[32];	/* DWORD 7 */
7288c2ecf20Sopenharmony_ci	u8 sge0_addr_hi[32];	/* DWORD 8 */
7298c2ecf20Sopenharmony_ci	u8 sge0_addr_lo[32];	/* DWORD 9  */
7308c2ecf20Sopenharmony_ci	u8 sge0_offset[22];	/* DWORD 10 */
7318c2ecf20Sopenharmony_ci	u8 pbs;			/* DWORD 10 */
7328c2ecf20Sopenharmony_ci	u8 dif_mode[2];		/* DWORD 10 */
7338c2ecf20Sopenharmony_ci	u8 rsvd1[6];		/* DWORD 10 */
7348c2ecf20Sopenharmony_ci	u8 sge0_last;		/* DWORD 10 */
7358c2ecf20Sopenharmony_ci	u8 sge0_len[17];	/* DWORD 11 */
7368c2ecf20Sopenharmony_ci	u8 dif_meta_tag[14];	/* DWORD 11 */
7378c2ecf20Sopenharmony_ci	u8 sge0_in_ddr;		/* DWORD 11 */
7388c2ecf20Sopenharmony_ci	u8 sge1_addr_hi[32];	/* DWORD 12 */
7398c2ecf20Sopenharmony_ci	u8 sge1_addr_lo[32];	/* DWORD 13 */
7408c2ecf20Sopenharmony_ci	u8 sge1_r2t_offset[22];	/* DWORD 14 */
7418c2ecf20Sopenharmony_ci	u8 rsvd2[9];		/* DWORD 14 */
7428c2ecf20Sopenharmony_ci	u8 sge1_last;		/* DWORD 14 */
7438c2ecf20Sopenharmony_ci	u8 sge1_len[17];	/* DWORD 15 */
7448c2ecf20Sopenharmony_ci	u8 ref_sgl_icd_idx[12];	/* DWORD 15 */
7458c2ecf20Sopenharmony_ci	u8 rsvd3[2];		/* DWORD 15 */
7468c2ecf20Sopenharmony_ci	u8 sge1_in_ddr;		/* DWORD 15 */
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci} __packed;
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_cistruct amap_iscsi_wrb_v2 {
7518c2ecf20Sopenharmony_ci	u8 r2t_exp_dtl[25]; /* DWORD 0 */
7528c2ecf20Sopenharmony_ci	u8 rsvd0[2];    /* DWORD 0*/
7538c2ecf20Sopenharmony_ci	u8 type[5];     /* DWORD 0 */
7548c2ecf20Sopenharmony_ci	u8 ptr2nextwrb[8];  /* DWORD 1 */
7558c2ecf20Sopenharmony_ci	u8 wrb_idx[8];      /* DWORD 1 */
7568c2ecf20Sopenharmony_ci	u8 lun[16];     /* DWORD 1 */
7578c2ecf20Sopenharmony_ci	u8 sgl_idx[16]; /* DWORD 2 */
7588c2ecf20Sopenharmony_ci	u8 ref_sgl_icd_idx[16]; /* DWORD 2 */
7598c2ecf20Sopenharmony_ci	u8 exp_data_sn[32]; /* DWORD 3 */
7608c2ecf20Sopenharmony_ci	u8 iscsi_bhs_addr_hi[32];   /* DWORD 4 */
7618c2ecf20Sopenharmony_ci	u8 iscsi_bhs_addr_lo[32];   /* DWORD 5 */
7628c2ecf20Sopenharmony_ci	u8 cq_id[16];   /* DWORD 6 */
7638c2ecf20Sopenharmony_ci	u8 rsvd1[16];   /* DWORD 6 */
7648c2ecf20Sopenharmony_ci	u8 cmdsn_itt[32];   /* DWORD 7 */
7658c2ecf20Sopenharmony_ci	u8 sge0_addr_hi[32];    /* DWORD 8 */
7668c2ecf20Sopenharmony_ci	u8 sge0_addr_lo[32];    /* DWORD 9 */
7678c2ecf20Sopenharmony_ci	u8 sge0_offset[24]; /* DWORD 10 */
7688c2ecf20Sopenharmony_ci	u8 rsvd2[7];    /* DWORD 10 */
7698c2ecf20Sopenharmony_ci	u8 sge0_last;   /* DWORD 10 */
7708c2ecf20Sopenharmony_ci	u8 sge0_len[17];    /* DWORD 11 */
7718c2ecf20Sopenharmony_ci	u8 rsvd3[7];    /* DWORD 11 */
7728c2ecf20Sopenharmony_ci	u8 diff_enbl;   /* DWORD 11 */
7738c2ecf20Sopenharmony_ci	u8 u_run;       /* DWORD 11 */
7748c2ecf20Sopenharmony_ci	u8 o_run;       /* DWORD 11 */
7758c2ecf20Sopenharmony_ci	u8 invld;     /* DWORD 11 */
7768c2ecf20Sopenharmony_ci	u8 dsp;         /* DWORD 11 */
7778c2ecf20Sopenharmony_ci	u8 dmsg;        /* DWORD 11 */
7788c2ecf20Sopenharmony_ci	u8 rsvd4;       /* DWORD 11 */
7798c2ecf20Sopenharmony_ci	u8 lt;          /* DWORD 11 */
7808c2ecf20Sopenharmony_ci	u8 sge1_addr_hi[32];    /* DWORD 12 */
7818c2ecf20Sopenharmony_ci	u8 sge1_addr_lo[32];    /* DWORD 13 */
7828c2ecf20Sopenharmony_ci	u8 sge1_r2t_offset[24]; /* DWORD 14 */
7838c2ecf20Sopenharmony_ci	u8 rsvd5[7];    /* DWORD 14 */
7848c2ecf20Sopenharmony_ci	u8 sge1_last;   /* DWORD 14 */
7858c2ecf20Sopenharmony_ci	u8 sge1_len[17];    /* DWORD 15 */
7868c2ecf20Sopenharmony_ci	u8 rsvd6[15];   /* DWORD 15 */
7878c2ecf20Sopenharmony_ci} __packed;
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci
7908c2ecf20Sopenharmony_cistruct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid,
7918c2ecf20Sopenharmony_ci				     struct hwi_wrb_context **pcontext);
7928c2ecf20Sopenharmony_civoid
7938c2ecf20Sopenharmony_cifree_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle);
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_civoid beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
7968c2ecf20Sopenharmony_ci				     struct iscsi_task *task);
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_civoid hwi_ring_cq_db(struct beiscsi_hba *phba,
7998c2ecf20Sopenharmony_ci		     unsigned int id, unsigned int num_processed,
8008c2ecf20Sopenharmony_ci		     unsigned char rearm);
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ciunsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget);
8038c2ecf20Sopenharmony_civoid beiscsi_process_mcc_cq(struct beiscsi_hba *phba);
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_cistruct pdu_nop_out {
8068c2ecf20Sopenharmony_ci	u32 dw[12];
8078c2ecf20Sopenharmony_ci};
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci/**
8108c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
8118c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
8128c2ecf20Sopenharmony_ci */
8138c2ecf20Sopenharmony_cistruct amap_pdu_nop_out {
8148c2ecf20Sopenharmony_ci	u8 opcode[6];		/* opcode 0x00 */
8158c2ecf20Sopenharmony_ci	u8 i_bit;		/* I Bit */
8168c2ecf20Sopenharmony_ci	u8 x_bit;		/* reserved; should be 0 */
8178c2ecf20Sopenharmony_ci	u8 fp_bit_filler1[7];
8188c2ecf20Sopenharmony_ci	u8 f_bit;		/* always 1 */
8198c2ecf20Sopenharmony_ci	u8 reserved1[16];
8208c2ecf20Sopenharmony_ci	u8 ahs_length[8];	/* no AHS */
8218c2ecf20Sopenharmony_ci	u8 data_len_hi[8];
8228c2ecf20Sopenharmony_ci	u8 data_len_lo[16];	/* DataSegmentLength */
8238c2ecf20Sopenharmony_ci	u8 lun[64];
8248c2ecf20Sopenharmony_ci	u8 itt[32];		/* initiator id for ping or 0xffffffff */
8258c2ecf20Sopenharmony_ci	u8 ttt[32];		/* target id for ping or 0xffffffff */
8268c2ecf20Sopenharmony_ci	u8 cmd_sn[32];
8278c2ecf20Sopenharmony_ci	u8 exp_stat_sn[32];
8288c2ecf20Sopenharmony_ci	u8 reserved5[128];
8298c2ecf20Sopenharmony_ci};
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci#define PDUBASE_OPCODE_MASK	0x0000003F
8328c2ecf20Sopenharmony_ci#define PDUBASE_DATALENHI_MASK	0x0000FF00
8338c2ecf20Sopenharmony_ci#define PDUBASE_DATALENLO_MASK	0xFFFF0000
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_cistruct pdu_base {
8368c2ecf20Sopenharmony_ci	u32 dw[16];
8378c2ecf20Sopenharmony_ci} __packed;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci/**
8408c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
8418c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
8428c2ecf20Sopenharmony_ci */
8438c2ecf20Sopenharmony_cistruct amap_pdu_base {
8448c2ecf20Sopenharmony_ci	u8 opcode[6];
8458c2ecf20Sopenharmony_ci	u8 i_bit;		/* immediate bit */
8468c2ecf20Sopenharmony_ci	u8 x_bit;		/* reserved, always 0 */
8478c2ecf20Sopenharmony_ci	u8 reserved1[24];	/* opcode-specific fields */
8488c2ecf20Sopenharmony_ci	u8 ahs_length[8];	/* length units is 4 byte words */
8498c2ecf20Sopenharmony_ci	u8 data_len_hi[8];
8508c2ecf20Sopenharmony_ci	u8 data_len_lo[16];	/* DatasegmentLength */
8518c2ecf20Sopenharmony_ci	u8 lun[64];		/* lun or opcode-specific fields */
8528c2ecf20Sopenharmony_ci	u8 itt[32];		/* initiator task tag */
8538c2ecf20Sopenharmony_ci	u8 reserved4[224];
8548c2ecf20Sopenharmony_ci};
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_cistruct iscsi_target_context_update_wrb {
8578c2ecf20Sopenharmony_ci	u32 dw[16];
8588c2ecf20Sopenharmony_ci} __packed;
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci/**
8618c2ecf20Sopenharmony_ci * Pseudo amap definition in which each bit of the actual structure is defined
8628c2ecf20Sopenharmony_ci * as a byte: used to calculate offset/shift/mask of each field
8638c2ecf20Sopenharmony_ci */
8648c2ecf20Sopenharmony_ci#define BE_TGT_CTX_UPDT_CMD 0x07
8658c2ecf20Sopenharmony_cistruct amap_iscsi_target_context_update_wrb {
8668c2ecf20Sopenharmony_ci	u8 lun[14];		/* DWORD 0 */
8678c2ecf20Sopenharmony_ci	u8 lt;			/* DWORD 0 */
8688c2ecf20Sopenharmony_ci	u8 invld;		/* DWORD 0 */
8698c2ecf20Sopenharmony_ci	u8 wrb_idx[8];		/* DWORD 0 */
8708c2ecf20Sopenharmony_ci	u8 dsp;			/* DWORD 0 */
8718c2ecf20Sopenharmony_ci	u8 dmsg;		/* DWORD 0 */
8728c2ecf20Sopenharmony_ci	u8 undr_run;		/* DWORD 0 */
8738c2ecf20Sopenharmony_ci	u8 over_run;		/* DWORD 0 */
8748c2ecf20Sopenharmony_ci	u8 type[4];		/* DWORD 0 */
8758c2ecf20Sopenharmony_ci	u8 ptr2nextwrb[8];	/* DWORD 1 */
8768c2ecf20Sopenharmony_ci	u8 max_burst_length[19];	/* DWORD 1 */
8778c2ecf20Sopenharmony_ci	u8 rsvd0[5];		/* DWORD 1 */
8788c2ecf20Sopenharmony_ci	u8 rsvd1[15];		/* DWORD 2 */
8798c2ecf20Sopenharmony_ci	u8 max_send_data_segment_length[17];	/* DWORD 2 */
8808c2ecf20Sopenharmony_ci	u8 first_burst_length[14];	/* DWORD 3 */
8818c2ecf20Sopenharmony_ci	u8 rsvd2[2];		/* DWORD 3 */
8828c2ecf20Sopenharmony_ci	u8 tx_wrbindex_drv_msg[8];	/* DWORD 3 */
8838c2ecf20Sopenharmony_ci	u8 rsvd3[5];		/* DWORD 3 */
8848c2ecf20Sopenharmony_ci	u8 session_state[3];	/* DWORD 3 */
8858c2ecf20Sopenharmony_ci	u8 rsvd4[16];		/* DWORD 4 */
8868c2ecf20Sopenharmony_ci	u8 tx_jumbo;		/* DWORD 4 */
8878c2ecf20Sopenharmony_ci	u8 hde;			/* DWORD 4 */
8888c2ecf20Sopenharmony_ci	u8 dde;			/* DWORD 4 */
8898c2ecf20Sopenharmony_ci	u8 erl[2];		/* DWORD 4 */
8908c2ecf20Sopenharmony_ci	u8 domain_id[5];		/* DWORD 4 */
8918c2ecf20Sopenharmony_ci	u8 mode;		/* DWORD 4 */
8928c2ecf20Sopenharmony_ci	u8 imd;			/* DWORD 4 */
8938c2ecf20Sopenharmony_ci	u8 ir2t;		/* DWORD 4 */
8948c2ecf20Sopenharmony_ci	u8 notpredblq[2];	/* DWORD 4 */
8958c2ecf20Sopenharmony_ci	u8 compltonack;		/* DWORD 4 */
8968c2ecf20Sopenharmony_ci	u8 stat_sn[32];		/* DWORD 5 */
8978c2ecf20Sopenharmony_ci	u8 pad_buffer_addr_hi[32];	/* DWORD 6 */
8988c2ecf20Sopenharmony_ci	u8 pad_buffer_addr_lo[32];	/* DWORD 7 */
8998c2ecf20Sopenharmony_ci	u8 pad_addr_hi[32];	/* DWORD 8 */
9008c2ecf20Sopenharmony_ci	u8 pad_addr_lo[32];	/* DWORD 9 */
9018c2ecf20Sopenharmony_ci	u8 rsvd5[32];		/* DWORD 10 */
9028c2ecf20Sopenharmony_ci	u8 rsvd6[32];		/* DWORD 11 */
9038c2ecf20Sopenharmony_ci	u8 rsvd7[32];		/* DWORD 12 */
9048c2ecf20Sopenharmony_ci	u8 rsvd8[32];		/* DWORD 13 */
9058c2ecf20Sopenharmony_ci	u8 rsvd9[32];		/* DWORD 14 */
9068c2ecf20Sopenharmony_ci	u8 rsvd10[32];		/* DWORD 15 */
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci} __packed;
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci#define BEISCSI_MAX_RECV_DATASEG_LEN    (64 * 1024)
9118c2ecf20Sopenharmony_ci#define BEISCSI_MAX_CXNS    1
9128c2ecf20Sopenharmony_cistruct amap_iscsi_target_context_update_wrb_v2 {
9138c2ecf20Sopenharmony_ci	u8 max_burst_length[24];    /* DWORD 0 */
9148c2ecf20Sopenharmony_ci	u8 rsvd0[3];    /* DWORD 0 */
9158c2ecf20Sopenharmony_ci	u8 type[5];     /* DWORD 0 */
9168c2ecf20Sopenharmony_ci	u8 ptr2nextwrb[8];  /* DWORD 1 */
9178c2ecf20Sopenharmony_ci	u8 wrb_idx[8];      /* DWORD 1 */
9188c2ecf20Sopenharmony_ci	u8 rsvd1[16];       /* DWORD 1 */
9198c2ecf20Sopenharmony_ci	u8 max_send_data_segment_length[24];    /* DWORD 2 */
9208c2ecf20Sopenharmony_ci	u8 rsvd2[8];    /* DWORD 2 */
9218c2ecf20Sopenharmony_ci	u8 first_burst_length[24]; /* DWORD 3 */
9228c2ecf20Sopenharmony_ci	u8 rsvd3[8]; /* DOWRD 3 */
9238c2ecf20Sopenharmony_ci	u8 max_r2t[16]; /* DWORD 4 */
9248c2ecf20Sopenharmony_ci	u8 rsvd4;       /* DWORD 4 */
9258c2ecf20Sopenharmony_ci	u8 hde;         /* DWORD 4 */
9268c2ecf20Sopenharmony_ci	u8 dde;         /* DWORD 4 */
9278c2ecf20Sopenharmony_ci	u8 erl[2];      /* DWORD 4 */
9288c2ecf20Sopenharmony_ci	u8 rsvd5[6];    /* DWORD 4 */
9298c2ecf20Sopenharmony_ci	u8 imd;         /* DWORD 4 */
9308c2ecf20Sopenharmony_ci	u8 ir2t;        /* DWORD 4 */
9318c2ecf20Sopenharmony_ci	u8 rsvd6[3];    /* DWORD 4 */
9328c2ecf20Sopenharmony_ci	u8 stat_sn[32];     /* DWORD 5 */
9338c2ecf20Sopenharmony_ci	u8 rsvd7[32];   /* DWORD 6 */
9348c2ecf20Sopenharmony_ci	u8 rsvd8[32];   /* DWORD 7 */
9358c2ecf20Sopenharmony_ci	u8 max_recv_dataseg_len[24];    /* DWORD 8 */
9368c2ecf20Sopenharmony_ci	u8 rsvd9[8]; /* DWORD 8 */
9378c2ecf20Sopenharmony_ci	u8 rsvd10[32];   /* DWORD 9 */
9388c2ecf20Sopenharmony_ci	u8 rsvd11[32];   /* DWORD 10 */
9398c2ecf20Sopenharmony_ci	u8 max_cxns[16]; /* DWORD 11 */
9408c2ecf20Sopenharmony_ci	u8 rsvd12[11]; /* DWORD  11*/
9418c2ecf20Sopenharmony_ci	u8 invld; /* DWORD 11 */
9428c2ecf20Sopenharmony_ci	u8 rsvd13;/* DWORD 11*/
9438c2ecf20Sopenharmony_ci	u8 dmsg; /* DWORD 11 */
9448c2ecf20Sopenharmony_ci	u8 data_seq_inorder; /* DWORD 11 */
9458c2ecf20Sopenharmony_ci	u8 pdu_seq_inorder; /* DWORD 11 */
9468c2ecf20Sopenharmony_ci	u8 rsvd14[32]; /*DWORD 12 */
9478c2ecf20Sopenharmony_ci	u8 rsvd15[32]; /* DWORD 13 */
9488c2ecf20Sopenharmony_ci	u8 rsvd16[32]; /* DWORD 14 */
9498c2ecf20Sopenharmony_ci	u8 rsvd17[32]; /* DWORD 15 */
9508c2ecf20Sopenharmony_ci} __packed;
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_cistruct be_ring {
9548c2ecf20Sopenharmony_ci	u32 pages;		/* queue size in pages */
9558c2ecf20Sopenharmony_ci	u32 id;			/* queue id assigned by beklib */
9568c2ecf20Sopenharmony_ci	u32 num;		/* number of elements in queue */
9578c2ecf20Sopenharmony_ci	u32 cidx;		/* consumer index */
9588c2ecf20Sopenharmony_ci	u32 pidx;		/* producer index -- not used by most rings */
9598c2ecf20Sopenharmony_ci	u32 item_size;		/* size in bytes of one object */
9608c2ecf20Sopenharmony_ci	u8 ulp_num;	/* ULP to which CID binded */
9618c2ecf20Sopenharmony_ci	u16 register_set;
9628c2ecf20Sopenharmony_ci	u16 doorbell_format;
9638c2ecf20Sopenharmony_ci	u32 doorbell_offset;
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci	void *va;		/* The virtual address of the ring.  This
9668c2ecf20Sopenharmony_ci				 * should be last to allow 32 & 64 bit debugger
9678c2ecf20Sopenharmony_ci				 * extensions to work.
9688c2ecf20Sopenharmony_ci				 */
9698c2ecf20Sopenharmony_ci};
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_cistruct hwi_controller {
9728c2ecf20Sopenharmony_ci	struct hwi_wrb_context *wrb_context;
9738c2ecf20Sopenharmony_ci	struct be_ring default_pdu_hdr[BEISCSI_ULP_COUNT];
9748c2ecf20Sopenharmony_ci	struct be_ring default_pdu_data[BEISCSI_ULP_COUNT];
9758c2ecf20Sopenharmony_ci	struct hwi_context_memory *phwi_ctxt;
9768c2ecf20Sopenharmony_ci};
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_cienum hwh_type_enum {
9798c2ecf20Sopenharmony_ci	HWH_TYPE_IO = 1,
9808c2ecf20Sopenharmony_ci	HWH_TYPE_LOGOUT = 2,
9818c2ecf20Sopenharmony_ci	HWH_TYPE_TMF = 3,
9828c2ecf20Sopenharmony_ci	HWH_TYPE_NOP = 4,
9838c2ecf20Sopenharmony_ci	HWH_TYPE_IO_RD = 5,
9848c2ecf20Sopenharmony_ci	HWH_TYPE_LOGIN = 11,
9858c2ecf20Sopenharmony_ci	HWH_TYPE_INVALID = 0xFFFFFFFF
9868c2ecf20Sopenharmony_ci};
9878c2ecf20Sopenharmony_ci
9888c2ecf20Sopenharmony_cistruct wrb_handle {
9898c2ecf20Sopenharmony_ci	unsigned short wrb_index;
9908c2ecf20Sopenharmony_ci	struct iscsi_task *pio_handle;
9918c2ecf20Sopenharmony_ci	struct iscsi_wrb *pwrb;
9928c2ecf20Sopenharmony_ci};
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_cistruct hwi_context_memory {
9958c2ecf20Sopenharmony_ci	struct be_eq_obj be_eq[MAX_CPUS];
9968c2ecf20Sopenharmony_ci	struct be_queue_info be_cq[MAX_CPUS - 1];
9978c2ecf20Sopenharmony_ci
9988c2ecf20Sopenharmony_ci	struct be_queue_info *be_wrbq;
9998c2ecf20Sopenharmony_ci	/**
10008c2ecf20Sopenharmony_ci	 * Create array of ULP number for below entries as DEFQ
10018c2ecf20Sopenharmony_ci	 * will be created for both ULP if iSCSI Protocol is
10028c2ecf20Sopenharmony_ci	 * loaded on both ULP.
10038c2ecf20Sopenharmony_ci	 */
10048c2ecf20Sopenharmony_ci	struct be_queue_info be_def_hdrq[BEISCSI_ULP_COUNT];
10058c2ecf20Sopenharmony_ci	struct be_queue_info be_def_dataq[BEISCSI_ULP_COUNT];
10068c2ecf20Sopenharmony_ci	struct hd_async_context *pasync_ctx[BEISCSI_ULP_COUNT];
10078c2ecf20Sopenharmony_ci};
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_civoid beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle);
10108c2ecf20Sopenharmony_ci
10118c2ecf20Sopenharmony_ci/* Logging related definitions */
10128c2ecf20Sopenharmony_ci#define BEISCSI_LOG_INIT	0x0001	/* Initialization events */
10138c2ecf20Sopenharmony_ci#define BEISCSI_LOG_MBOX	0x0002	/* Mailbox Events */
10148c2ecf20Sopenharmony_ci#define BEISCSI_LOG_MISC	0x0004	/* Miscllaneous Events */
10158c2ecf20Sopenharmony_ci#define BEISCSI_LOG_EH		0x0008	/* Error Handler */
10168c2ecf20Sopenharmony_ci#define BEISCSI_LOG_IO		0x0010	/* IO Code Path */
10178c2ecf20Sopenharmony_ci#define BEISCSI_LOG_CONFIG	0x0020	/* CONFIG Code Path */
10188c2ecf20Sopenharmony_ci#define BEISCSI_LOG_ISCSI	0x0040	/* SCSI/iSCSI Protocol related Logs */
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_ci#define __beiscsi_log(phba, level, fmt, arg...) \
10218c2ecf20Sopenharmony_ci	shost_printk(level, phba->shost, fmt, __LINE__, ##arg)
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci#define beiscsi_log(phba, level, mask, fmt, arg...) \
10248c2ecf20Sopenharmony_cido { \
10258c2ecf20Sopenharmony_ci	uint32_t log_value = phba->attr_log_enable; \
10268c2ecf20Sopenharmony_ci		if (((mask) & log_value) || (level[1] <= '3')) \
10278c2ecf20Sopenharmony_ci			__beiscsi_log(phba, level, fmt, ##arg); \
10288c2ecf20Sopenharmony_ci} while (0);
10298c2ecf20Sopenharmony_ci
10308c2ecf20Sopenharmony_ci#endif
1031