18c2ecf20Sopenharmony_ci/* bnx2i.h: QLogic NetXtreme II iSCSI driver.
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright (c) 2006 - 2013 Broadcom Corporation
48c2ecf20Sopenharmony_ci * Copyright (c) 2007, 2008 Red Hat, Inc.  All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright (c) 2007, 2008 Mike Christie
68c2ecf20Sopenharmony_ci * Copyright (c) 2014, QLogic Corporation
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
98c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
108c2ecf20Sopenharmony_ci * the Free Software Foundation.
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
138c2ecf20Sopenharmony_ci * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
148c2ecf20Sopenharmony_ci * Maintained by: QLogic-Storage-Upstream@qlogic.com
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifndef _BNX2I_H_
188c2ecf20Sopenharmony_ci#define _BNX2I_H_
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/module.h>
218c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include <linux/errno.h>
248c2ecf20Sopenharmony_ci#include <linux/pci.h>
258c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
268c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
278c2ecf20Sopenharmony_ci#include <linux/delay.h>
288c2ecf20Sopenharmony_ci#include <linux/sched/signal.h>
298c2ecf20Sopenharmony_ci#include <linux/in.h>
308c2ecf20Sopenharmony_ci#include <linux/kfifo.h>
318c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
328c2ecf20Sopenharmony_ci#include <linux/completion.h>
338c2ecf20Sopenharmony_ci#include <linux/kthread.h>
348c2ecf20Sopenharmony_ci#include <linux/cpu.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <scsi/scsi_cmnd.h>
378c2ecf20Sopenharmony_ci#include <scsi/scsi_device.h>
388c2ecf20Sopenharmony_ci#include <scsi/scsi_eh.h>
398c2ecf20Sopenharmony_ci#include <scsi/scsi_host.h>
408c2ecf20Sopenharmony_ci#include <scsi/scsi.h>
418c2ecf20Sopenharmony_ci#include <scsi/iscsi_proto.h>
428c2ecf20Sopenharmony_ci#include <scsi/libiscsi.h>
438c2ecf20Sopenharmony_ci#include <scsi/scsi_transport_iscsi.h>
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#include "../../net/ethernet/broadcom/cnic_if.h"
468c2ecf20Sopenharmony_ci#include "57xx_iscsi_hsi.h"
478c2ecf20Sopenharmony_ci#include "57xx_iscsi_constants.h"
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#include "../../net/ethernet/broadcom/bnx2x/bnx2x_mfw_req.h"
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define BNX2_ISCSI_DRIVER_NAME		"bnx2i"
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define BNX2I_MAX_ADAPTERS		8
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define ISCSI_MAX_CONNS_PER_HBA		128
568c2ecf20Sopenharmony_ci#define ISCSI_MAX_SESS_PER_HBA		ISCSI_MAX_CONNS_PER_HBA
578c2ecf20Sopenharmony_ci#define ISCSI_MAX_CMDS_PER_SESS		128
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* Total active commands across all connections supported by devices */
608c2ecf20Sopenharmony_ci#define ISCSI_MAX_CMDS_PER_HBA_5708	(28 * (ISCSI_MAX_CMDS_PER_SESS - 1))
618c2ecf20Sopenharmony_ci#define ISCSI_MAX_CMDS_PER_HBA_5709	(128 * (ISCSI_MAX_CMDS_PER_SESS - 1))
628c2ecf20Sopenharmony_ci#define ISCSI_MAX_CMDS_PER_HBA_57710	(256 * (ISCSI_MAX_CMDS_PER_SESS - 1))
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define ISCSI_MAX_BDS_PER_CMD		32
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define MAX_PAGES_PER_CTRL_STRUCT_POOL	8
678c2ecf20Sopenharmony_ci#define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS	4
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define BNX2X_DB_SHIFT			3
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* 5706/08 hardware has limit on maximum buffer size per BD it can handle */
728c2ecf20Sopenharmony_ci#define MAX_BD_LENGTH			65535
738c2ecf20Sopenharmony_ci#define BD_SPLIT_SIZE			32768
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* min, max & default values for SQ/RQ/CQ size, configurable via' modparam */
768c2ecf20Sopenharmony_ci#define BNX2I_SQ_WQES_MIN		16
778c2ecf20Sopenharmony_ci#define BNX2I_570X_SQ_WQES_MAX		128
788c2ecf20Sopenharmony_ci#define BNX2I_5770X_SQ_WQES_MAX		512
798c2ecf20Sopenharmony_ci#define BNX2I_570X_SQ_WQES_DEFAULT	128
808c2ecf20Sopenharmony_ci#define BNX2I_5770X_SQ_WQES_DEFAULT	128
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define BNX2I_570X_CQ_WQES_MAX 		128
838c2ecf20Sopenharmony_ci#define BNX2I_5770X_CQ_WQES_MAX 	512
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define BNX2I_RQ_WQES_MIN 		16
868c2ecf20Sopenharmony_ci#define BNX2I_RQ_WQES_MAX 		32
878c2ecf20Sopenharmony_ci#define BNX2I_RQ_WQES_DEFAULT 		16
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* CCELLs per conn */
908c2ecf20Sopenharmony_ci#define BNX2I_CCELLS_MIN		16
918c2ecf20Sopenharmony_ci#define BNX2I_CCELLS_MAX		96
928c2ecf20Sopenharmony_ci#define BNX2I_CCELLS_DEFAULT		64
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define ITT_INVALID_SIGNATURE		0xFFFF
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define ISCSI_CMD_CLEANUP_TIMEOUT	100
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define BNX2I_CONN_CTX_BUF_SIZE		16384
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define BNX2I_SQ_WQE_SIZE		64
1018c2ecf20Sopenharmony_ci#define BNX2I_RQ_WQE_SIZE		256
1028c2ecf20Sopenharmony_ci#define BNX2I_CQE_SIZE			64
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define MB_KERNEL_CTX_SHIFT		8
1058c2ecf20Sopenharmony_ci#define MB_KERNEL_CTX_SIZE		(1 << MB_KERNEL_CTX_SHIFT)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define CTX_SHIFT			7
1088c2ecf20Sopenharmony_ci#define GET_CID_NUM(cid_addr)		((cid_addr) >> CTX_SHIFT)
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define CTX_OFFSET 			0x10000
1118c2ecf20Sopenharmony_ci#define MAX_CID_CNT			0x4000
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#define BNX2I_570X_PAGE_SIZE_DEFAULT	4096
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* 5709 context registers */
1168c2ecf20Sopenharmony_ci#define BNX2_MQ_CONFIG2			0x00003d00
1178c2ecf20Sopenharmony_ci#define BNX2_MQ_CONFIG2_CONT_SZ		(0x7L<<4)
1188c2ecf20Sopenharmony_ci#define BNX2_MQ_CONFIG2_FIRST_L4L5	(0x1fL<<8)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* 57710's BAR2 is mapped to doorbell registers */
1218c2ecf20Sopenharmony_ci#define BNX2X_DOORBELL_PCI_BAR		2
1228c2ecf20Sopenharmony_ci#define BNX2X_MAX_CQS			8
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define CNIC_ARM_CQE			1
1258c2ecf20Sopenharmony_ci#define CNIC_ARM_CQE_FP			2
1268c2ecf20Sopenharmony_ci#define CNIC_DISARM_CQE			0
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define REG_RD(__hba, offset)				\
1298c2ecf20Sopenharmony_ci		readl(__hba->regview + offset)
1308c2ecf20Sopenharmony_ci#define REG_WR(__hba, offset, val)			\
1318c2ecf20Sopenharmony_ci		writel(val, __hba->regview + offset)
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#ifdef CONFIG_32BIT
1348c2ecf20Sopenharmony_ci#define GET_STATS_64(__hba, dst, field)				\
1358c2ecf20Sopenharmony_ci	do {							\
1368c2ecf20Sopenharmony_ci		spin_lock_bh(&__hba->stat_lock);		\
1378c2ecf20Sopenharmony_ci		dst->field##_lo = __hba->stats.field##_lo;	\
1388c2ecf20Sopenharmony_ci		dst->field##_hi = __hba->stats.field##_hi;	\
1398c2ecf20Sopenharmony_ci		spin_unlock_bh(&__hba->stat_lock);		\
1408c2ecf20Sopenharmony_ci	} while (0)
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define ADD_STATS_64(__hba, field, len)				\
1438c2ecf20Sopenharmony_ci	do {							\
1448c2ecf20Sopenharmony_ci		if (spin_trylock(&__hba->stat_lock)) {		\
1458c2ecf20Sopenharmony_ci			if (__hba->stats.field##_lo + len <	\
1468c2ecf20Sopenharmony_ci			    __hba->stats.field##_lo)		\
1478c2ecf20Sopenharmony_ci				__hba->stats.field##_hi++;	\
1488c2ecf20Sopenharmony_ci			__hba->stats.field##_lo += len;		\
1498c2ecf20Sopenharmony_ci			spin_unlock(&__hba->stat_lock);		\
1508c2ecf20Sopenharmony_ci		}						\
1518c2ecf20Sopenharmony_ci	} while (0)
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#else
1548c2ecf20Sopenharmony_ci#define GET_STATS_64(__hba, dst, field)				\
1558c2ecf20Sopenharmony_ci	do {							\
1568c2ecf20Sopenharmony_ci		u64 val, *out;					\
1578c2ecf20Sopenharmony_ci								\
1588c2ecf20Sopenharmony_ci		val = __hba->bnx2i_stats.field;			\
1598c2ecf20Sopenharmony_ci		out = (u64 *)&__hba->stats.field##_lo;		\
1608c2ecf20Sopenharmony_ci		*out = cpu_to_le64(val);			\
1618c2ecf20Sopenharmony_ci		out = (u64 *)&dst->field##_lo;			\
1628c2ecf20Sopenharmony_ci		*out = cpu_to_le64(val);			\
1638c2ecf20Sopenharmony_ci	} while (0)
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#define ADD_STATS_64(__hba, field, len)				\
1668c2ecf20Sopenharmony_ci	do {							\
1678c2ecf20Sopenharmony_ci		__hba->bnx2i_stats.field += len;		\
1688c2ecf20Sopenharmony_ci	} while (0)
1698c2ecf20Sopenharmony_ci#endif
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/**
1728c2ecf20Sopenharmony_ci * struct generic_pdu_resc - login pdu resource structure
1738c2ecf20Sopenharmony_ci *
1748c2ecf20Sopenharmony_ci * @req_buf:            driver buffer used to stage payload associated with
1758c2ecf20Sopenharmony_ci *                      the login request
1768c2ecf20Sopenharmony_ci * @req_dma_addr:       dma address for iscsi login request payload buffer
1778c2ecf20Sopenharmony_ci * @req_buf_size:       actual login request payload length
1788c2ecf20Sopenharmony_ci * @req_wr_ptr:         pointer into login request buffer when next data is
1798c2ecf20Sopenharmony_ci *                      to be written
1808c2ecf20Sopenharmony_ci * @resp_hdr:           iscsi header where iscsi login response header is to
1818c2ecf20Sopenharmony_ci *                      be recreated
1828c2ecf20Sopenharmony_ci * @resp_buf:           buffer to stage login response payload
1838c2ecf20Sopenharmony_ci * @resp_dma_addr:      login response payload buffer dma address
1848c2ecf20Sopenharmony_ci * @resp_buf_size:      login response paylod length
1858c2ecf20Sopenharmony_ci * @resp_wr_ptr:        pointer into login response buffer when next data is
1868c2ecf20Sopenharmony_ci *                      to be written
1878c2ecf20Sopenharmony_ci * @req_bd_tbl:         iscsi login request payload BD table
1888c2ecf20Sopenharmony_ci * @req_bd_dma:         login request BD table dma address
1898c2ecf20Sopenharmony_ci * @resp_bd_tbl:        iscsi login response payload BD table
1908c2ecf20Sopenharmony_ci * @resp_bd_dma:        login request BD table dma address
1918c2ecf20Sopenharmony_ci *
1928c2ecf20Sopenharmony_ci * following structure defines buffer info for generic pdus such as iSCSI Login,
1938c2ecf20Sopenharmony_ci *	Logout and NOP
1948c2ecf20Sopenharmony_ci */
1958c2ecf20Sopenharmony_cistruct generic_pdu_resc {
1968c2ecf20Sopenharmony_ci	char *req_buf;
1978c2ecf20Sopenharmony_ci	dma_addr_t req_dma_addr;
1988c2ecf20Sopenharmony_ci	u32 req_buf_size;
1998c2ecf20Sopenharmony_ci	char *req_wr_ptr;
2008c2ecf20Sopenharmony_ci	struct iscsi_hdr resp_hdr;
2018c2ecf20Sopenharmony_ci	char *resp_buf;
2028c2ecf20Sopenharmony_ci	dma_addr_t resp_dma_addr;
2038c2ecf20Sopenharmony_ci	u32 resp_buf_size;
2048c2ecf20Sopenharmony_ci	char *resp_wr_ptr;
2058c2ecf20Sopenharmony_ci	char *req_bd_tbl;
2068c2ecf20Sopenharmony_ci	dma_addr_t req_bd_dma;
2078c2ecf20Sopenharmony_ci	char *resp_bd_tbl;
2088c2ecf20Sopenharmony_ci	dma_addr_t resp_bd_dma;
2098c2ecf20Sopenharmony_ci};
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci/**
2138c2ecf20Sopenharmony_ci * struct bd_resc_page - tracks DMA'able memory allocated for BD tables
2148c2ecf20Sopenharmony_ci *
2158c2ecf20Sopenharmony_ci * @link:               list head to link elements
2168c2ecf20Sopenharmony_ci * @max_ptrs:           maximun pointers that can be stored in this page
2178c2ecf20Sopenharmony_ci * @num_valid:          number of pointer valid in this page
2188c2ecf20Sopenharmony_ci * @page:               base addess for page pointer array
2198c2ecf20Sopenharmony_ci *
2208c2ecf20Sopenharmony_ci * structure to track DMA'able memory allocated for command BD tables
2218c2ecf20Sopenharmony_ci */
2228c2ecf20Sopenharmony_cistruct bd_resc_page {
2238c2ecf20Sopenharmony_ci	struct list_head link;
2248c2ecf20Sopenharmony_ci	u32 max_ptrs;
2258c2ecf20Sopenharmony_ci	u32 num_valid;
2268c2ecf20Sopenharmony_ci	void *page[1];
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci/**
2318c2ecf20Sopenharmony_ci * struct io_bdt - I/O buffer destricptor table
2328c2ecf20Sopenharmony_ci *
2338c2ecf20Sopenharmony_ci * @bd_tbl:             BD table's virtual address
2348c2ecf20Sopenharmony_ci * @bd_tbl_dma:         BD table's dma address
2358c2ecf20Sopenharmony_ci * @bd_valid:           num valid BD entries
2368c2ecf20Sopenharmony_ci *
2378c2ecf20Sopenharmony_ci * IO BD table
2388c2ecf20Sopenharmony_ci */
2398c2ecf20Sopenharmony_cistruct io_bdt {
2408c2ecf20Sopenharmony_ci	struct iscsi_bd *bd_tbl;
2418c2ecf20Sopenharmony_ci	dma_addr_t bd_tbl_dma;
2428c2ecf20Sopenharmony_ci	u16 bd_valid;
2438c2ecf20Sopenharmony_ci};
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci/**
2478c2ecf20Sopenharmony_ci * bnx2i_cmd - iscsi command structure
2488c2ecf20Sopenharmony_ci *
2498c2ecf20Sopenharmony_ci * @hdr:                iSCSI header
2508c2ecf20Sopenharmony_ci * @conn:               iscsi_conn pointer
2518c2ecf20Sopenharmony_ci * @scsi_cmd:           SCSI-ML task pointer corresponding to this iscsi cmd
2528c2ecf20Sopenharmony_ci * @sg:                 SG list
2538c2ecf20Sopenharmony_ci * @io_tbl:             buffer descriptor (BD) table
2548c2ecf20Sopenharmony_ci * @bd_tbl_dma:         buffer descriptor (BD) table's dma address
2558c2ecf20Sopenharmony_ci * @req:                bnx2i specific command request struct
2568c2ecf20Sopenharmony_ci */
2578c2ecf20Sopenharmony_cistruct bnx2i_cmd {
2588c2ecf20Sopenharmony_ci	struct iscsi_hdr hdr;
2598c2ecf20Sopenharmony_ci	struct bnx2i_conn *conn;
2608c2ecf20Sopenharmony_ci	struct scsi_cmnd *scsi_cmd;
2618c2ecf20Sopenharmony_ci	struct scatterlist *sg;
2628c2ecf20Sopenharmony_ci	struct io_bdt io_tbl;
2638c2ecf20Sopenharmony_ci	dma_addr_t bd_tbl_dma;
2648c2ecf20Sopenharmony_ci	struct bnx2i_cmd_request req;
2658c2ecf20Sopenharmony_ci};
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/**
2698c2ecf20Sopenharmony_ci * struct bnx2i_conn - iscsi connection structure
2708c2ecf20Sopenharmony_ci *
2718c2ecf20Sopenharmony_ci * @cls_conn:              pointer to iscsi cls conn
2728c2ecf20Sopenharmony_ci * @hba:                   adapter structure pointer
2738c2ecf20Sopenharmony_ci * @iscsi_conn_cid:        iscsi conn id
2748c2ecf20Sopenharmony_ci * @fw_cid:                firmware iscsi context id
2758c2ecf20Sopenharmony_ci * @ep:                    endpoint structure pointer
2768c2ecf20Sopenharmony_ci * @gen_pdu:               login/nopout/logout pdu resources
2778c2ecf20Sopenharmony_ci * @violation_notified:    bit mask used to track iscsi error/warning messages
2788c2ecf20Sopenharmony_ci *                         already printed out
2798c2ecf20Sopenharmony_ci * @work_cnt:              keeps track of the number of outstanding work
2808c2ecf20Sopenharmony_ci *
2818c2ecf20Sopenharmony_ci * iSCSI connection structure
2828c2ecf20Sopenharmony_ci */
2838c2ecf20Sopenharmony_cistruct bnx2i_conn {
2848c2ecf20Sopenharmony_ci	struct iscsi_cls_conn *cls_conn;
2858c2ecf20Sopenharmony_ci	struct bnx2i_hba *hba;
2868c2ecf20Sopenharmony_ci	struct completion cmd_cleanup_cmpl;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	u32 iscsi_conn_cid;
2898c2ecf20Sopenharmony_ci#define BNX2I_CID_RESERVED	0x5AFF
2908c2ecf20Sopenharmony_ci	u32 fw_cid;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	struct timer_list poll_timer;
2938c2ecf20Sopenharmony_ci	/*
2948c2ecf20Sopenharmony_ci	 * Queue Pair (QP) related structure elements.
2958c2ecf20Sopenharmony_ci	 */
2968c2ecf20Sopenharmony_ci	struct bnx2i_endpoint *ep;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	/*
2998c2ecf20Sopenharmony_ci	 * Buffer for login negotiation process
3008c2ecf20Sopenharmony_ci	 */
3018c2ecf20Sopenharmony_ci	struct generic_pdu_resc gen_pdu;
3028c2ecf20Sopenharmony_ci	u64 violation_notified;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	atomic_t work_cnt;
3058c2ecf20Sopenharmony_ci};
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci/**
3108c2ecf20Sopenharmony_ci * struct iscsi_cid_queue - Per adapter iscsi cid queue
3118c2ecf20Sopenharmony_ci *
3128c2ecf20Sopenharmony_ci * @cid_que_base:           queue base memory
3138c2ecf20Sopenharmony_ci * @cid_que:                queue memory pointer
3148c2ecf20Sopenharmony_ci * @cid_q_prod_idx:         produce index
3158c2ecf20Sopenharmony_ci * @cid_q_cons_idx:         consumer index
3168c2ecf20Sopenharmony_ci * @cid_q_max_idx:          max index. used to detect wrap around condition
3178c2ecf20Sopenharmony_ci * @cid_free_cnt:           queue size
3188c2ecf20Sopenharmony_ci * @conn_cid_tbl:           iscsi cid to conn structure mapping table
3198c2ecf20Sopenharmony_ci *
3208c2ecf20Sopenharmony_ci * Per adapter iSCSI CID Queue
3218c2ecf20Sopenharmony_ci */
3228c2ecf20Sopenharmony_cistruct iscsi_cid_queue {
3238c2ecf20Sopenharmony_ci	void *cid_que_base;
3248c2ecf20Sopenharmony_ci	u32 *cid_que;
3258c2ecf20Sopenharmony_ci	u32 cid_q_prod_idx;
3268c2ecf20Sopenharmony_ci	u32 cid_q_cons_idx;
3278c2ecf20Sopenharmony_ci	u32 cid_q_max_idx;
3288c2ecf20Sopenharmony_ci	u32 cid_free_cnt;
3298c2ecf20Sopenharmony_ci	struct bnx2i_conn **conn_cid_tbl;
3308c2ecf20Sopenharmony_ci};
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistruct bnx2i_stats_info {
3348c2ecf20Sopenharmony_ci	u64 rx_pdus;
3358c2ecf20Sopenharmony_ci	u64 rx_bytes;
3368c2ecf20Sopenharmony_ci	u64 tx_pdus;
3378c2ecf20Sopenharmony_ci	u64 tx_bytes;
3388c2ecf20Sopenharmony_ci};
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci/**
3428c2ecf20Sopenharmony_ci * struct bnx2i_hba - bnx2i adapter structure
3438c2ecf20Sopenharmony_ci *
3448c2ecf20Sopenharmony_ci * @link:                  list head to link elements
3458c2ecf20Sopenharmony_ci * @cnic:                  pointer to cnic device
3468c2ecf20Sopenharmony_ci * @pcidev:                pointer to pci dev
3478c2ecf20Sopenharmony_ci * @netdev:                pointer to netdev structure
3488c2ecf20Sopenharmony_ci * @regview:               mapped PCI register space
3498c2ecf20Sopenharmony_ci * @age:                   age, incremented by every recovery
3508c2ecf20Sopenharmony_ci * @cnic_dev_type:         cnic device type, 5706/5708/5709/57710
3518c2ecf20Sopenharmony_ci * @mail_queue_access:     mailbox queue access mode, applicable to 5709 only
3528c2ecf20Sopenharmony_ci * @reg_with_cnic:         indicates whether the device is register with CNIC
3538c2ecf20Sopenharmony_ci * @adapter_state:         adapter state, UP, GOING_DOWN, LINK_DOWN
3548c2ecf20Sopenharmony_ci * @mtu_supported:         Ethernet MTU supported
3558c2ecf20Sopenharmony_ci * @shost:                 scsi host pointer
3568c2ecf20Sopenharmony_ci * @max_sqes:              SQ size
3578c2ecf20Sopenharmony_ci * @max_rqes:              RQ size
3588c2ecf20Sopenharmony_ci * @max_cqes:              CQ size
3598c2ecf20Sopenharmony_ci * @num_ccell:             number of command cells per connection
3608c2ecf20Sopenharmony_ci * @ofld_conns_active:     active connection list
3618c2ecf20Sopenharmony_ci * @eh_wait:               wait queue for the endpoint to shutdown
3628c2ecf20Sopenharmony_ci * @max_active_conns:      max offload connections supported by this device
3638c2ecf20Sopenharmony_ci * @cid_que:               iscsi cid queue
3648c2ecf20Sopenharmony_ci * @ep_rdwr_lock:          read / write lock to synchronize various ep lists
3658c2ecf20Sopenharmony_ci * @ep_ofld_list:          connection list for pending offload completion
3668c2ecf20Sopenharmony_ci * @ep_active_list:        connection list for active offload endpoints
3678c2ecf20Sopenharmony_ci * @ep_destroy_list:       connection list for pending offload completion
3688c2ecf20Sopenharmony_ci * @mp_bd_tbl:             BD table to be used with middle path requests
3698c2ecf20Sopenharmony_ci * @mp_bd_dma:             DMA address of 'mp_bd_tbl' memory buffer
3708c2ecf20Sopenharmony_ci * @dummy_buffer:          Dummy buffer to be used with zero length scsicmd reqs
3718c2ecf20Sopenharmony_ci * @dummy_buf_dma:         DMA address of 'dummy_buffer' memory buffer
3728c2ecf20Sopenharmony_ci * @lock:              	   lock to synchonize access to hba structure
3738c2ecf20Sopenharmony_ci * @hba_shutdown_tmo:      Timeout value to shutdown each connection
3748c2ecf20Sopenharmony_ci * @conn_teardown_tmo:     Timeout value to tear down each connection
3758c2ecf20Sopenharmony_ci * @conn_ctx_destroy_tmo:  Timeout value to destroy context of each connection
3768c2ecf20Sopenharmony_ci * @pci_did:               PCI device ID
3778c2ecf20Sopenharmony_ci * @pci_vid:               PCI vendor ID
3788c2ecf20Sopenharmony_ci * @pci_sdid:              PCI subsystem device ID
3798c2ecf20Sopenharmony_ci * @pci_svid:              PCI subsystem vendor ID
3808c2ecf20Sopenharmony_ci * @pci_func:              PCI function number in system pci tree
3818c2ecf20Sopenharmony_ci * @pci_devno:             PCI device number in system pci tree
3828c2ecf20Sopenharmony_ci * @num_wqe_sent:          statistic counter, total wqe's sent
3838c2ecf20Sopenharmony_ci * @num_cqe_rcvd:          statistic counter, total cqe's received
3848c2ecf20Sopenharmony_ci * @num_intr_claimed:      statistic counter, total interrupts claimed
3858c2ecf20Sopenharmony_ci * @link_changed_count:    statistic counter, num of link change notifications
3868c2ecf20Sopenharmony_ci *                         received
3878c2ecf20Sopenharmony_ci * @ipaddr_changed_count:  statistic counter, num times IP address changed while
3888c2ecf20Sopenharmony_ci *                         at least one connection is offloaded
3898c2ecf20Sopenharmony_ci * @num_sess_opened:       statistic counter, total num sessions opened
3908c2ecf20Sopenharmony_ci * @num_conn_opened:       statistic counter, total num conns opened on this hba
3918c2ecf20Sopenharmony_ci * @ctx_ccell_tasks:       captures number of ccells and tasks supported by
3928c2ecf20Sopenharmony_ci *                         currently offloaded connection, used to decode
3938c2ecf20Sopenharmony_ci *                         context memory
3948c2ecf20Sopenharmony_ci * @stat_lock:		   spin lock used by the statistic collector (32 bit)
3958c2ecf20Sopenharmony_ci * @stats:		   local iSCSI statistic collection place holder
3968c2ecf20Sopenharmony_ci *
3978c2ecf20Sopenharmony_ci * Adapter Data Structure
3988c2ecf20Sopenharmony_ci */
3998c2ecf20Sopenharmony_cistruct bnx2i_hba {
4008c2ecf20Sopenharmony_ci	struct list_head link;
4018c2ecf20Sopenharmony_ci	struct cnic_dev *cnic;
4028c2ecf20Sopenharmony_ci	struct pci_dev *pcidev;
4038c2ecf20Sopenharmony_ci	struct net_device *netdev;
4048c2ecf20Sopenharmony_ci	void __iomem *regview;
4058c2ecf20Sopenharmony_ci	resource_size_t reg_base;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci	u32 age;
4088c2ecf20Sopenharmony_ci	unsigned long cnic_dev_type;
4098c2ecf20Sopenharmony_ci		#define BNX2I_NX2_DEV_5706		0x0
4108c2ecf20Sopenharmony_ci		#define BNX2I_NX2_DEV_5708		0x1
4118c2ecf20Sopenharmony_ci		#define BNX2I_NX2_DEV_5709		0x2
4128c2ecf20Sopenharmony_ci		#define BNX2I_NX2_DEV_57710		0x3
4138c2ecf20Sopenharmony_ci	u32 mail_queue_access;
4148c2ecf20Sopenharmony_ci		#define BNX2I_MQ_KERNEL_MODE		0x0
4158c2ecf20Sopenharmony_ci		#define BNX2I_MQ_KERNEL_BYPASS_MODE	0x1
4168c2ecf20Sopenharmony_ci		#define BNX2I_MQ_BIN_MODE		0x2
4178c2ecf20Sopenharmony_ci	unsigned long  reg_with_cnic;
4188c2ecf20Sopenharmony_ci		#define BNX2I_CNIC_REGISTERED		1
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	unsigned long  adapter_state;
4218c2ecf20Sopenharmony_ci		#define ADAPTER_STATE_UP		0
4228c2ecf20Sopenharmony_ci		#define ADAPTER_STATE_GOING_DOWN	1
4238c2ecf20Sopenharmony_ci		#define ADAPTER_STATE_LINK_DOWN		2
4248c2ecf20Sopenharmony_ci		#define ADAPTER_STATE_INIT_FAILED	31
4258c2ecf20Sopenharmony_ci	unsigned int mtu_supported;
4268c2ecf20Sopenharmony_ci		#define BNX2I_MAX_MTU_SUPPORTED		9000
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	struct Scsi_Host *shost;
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	u32 max_sqes;
4318c2ecf20Sopenharmony_ci	u32 max_rqes;
4328c2ecf20Sopenharmony_ci	u32 max_cqes;
4338c2ecf20Sopenharmony_ci	u32 num_ccell;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	int ofld_conns_active;
4368c2ecf20Sopenharmony_ci	wait_queue_head_t eh_wait;
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	int max_active_conns;
4398c2ecf20Sopenharmony_ci	struct iscsi_cid_queue cid_que;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	rwlock_t ep_rdwr_lock;
4428c2ecf20Sopenharmony_ci	struct list_head ep_ofld_list;
4438c2ecf20Sopenharmony_ci	struct list_head ep_active_list;
4448c2ecf20Sopenharmony_ci	struct list_head ep_destroy_list;
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	/*
4478c2ecf20Sopenharmony_ci	 * BD table to be used with MP (Middle Path requests.
4488c2ecf20Sopenharmony_ci	 */
4498c2ecf20Sopenharmony_ci	char *mp_bd_tbl;
4508c2ecf20Sopenharmony_ci	dma_addr_t mp_bd_dma;
4518c2ecf20Sopenharmony_ci	char *dummy_buffer;
4528c2ecf20Sopenharmony_ci	dma_addr_t dummy_buf_dma;
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	spinlock_t lock;	/* protects hba structure access */
4558c2ecf20Sopenharmony_ci	struct mutex net_dev_lock;/* sync net device access */
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	int hba_shutdown_tmo;
4588c2ecf20Sopenharmony_ci	int conn_teardown_tmo;
4598c2ecf20Sopenharmony_ci	int conn_ctx_destroy_tmo;
4608c2ecf20Sopenharmony_ci	/*
4618c2ecf20Sopenharmony_ci	 * PCI related info.
4628c2ecf20Sopenharmony_ci	 */
4638c2ecf20Sopenharmony_ci	u16 pci_did;
4648c2ecf20Sopenharmony_ci	u16 pci_vid;
4658c2ecf20Sopenharmony_ci	u16 pci_sdid;
4668c2ecf20Sopenharmony_ci	u16 pci_svid;
4678c2ecf20Sopenharmony_ci	u16 pci_func;
4688c2ecf20Sopenharmony_ci	u16 pci_devno;
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	/*
4718c2ecf20Sopenharmony_ci	 * Following are a bunch of statistics useful during development
4728c2ecf20Sopenharmony_ci	 * and later stage for score boarding.
4738c2ecf20Sopenharmony_ci	 */
4748c2ecf20Sopenharmony_ci	u32 num_wqe_sent;
4758c2ecf20Sopenharmony_ci	u32 num_cqe_rcvd;
4768c2ecf20Sopenharmony_ci	u32 num_intr_claimed;
4778c2ecf20Sopenharmony_ci	u32 link_changed_count;
4788c2ecf20Sopenharmony_ci	u32 ipaddr_changed_count;
4798c2ecf20Sopenharmony_ci	u32 num_sess_opened;
4808c2ecf20Sopenharmony_ci	u32 num_conn_opened;
4818c2ecf20Sopenharmony_ci	unsigned int ctx_ccell_tasks;
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci#ifdef CONFIG_32BIT
4848c2ecf20Sopenharmony_ci	spinlock_t stat_lock;
4858c2ecf20Sopenharmony_ci#endif
4868c2ecf20Sopenharmony_ci	struct bnx2i_stats_info bnx2i_stats;
4878c2ecf20Sopenharmony_ci	struct iscsi_stats_info stats;
4888c2ecf20Sopenharmony_ci};
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci/*******************************************************************************
4928c2ecf20Sopenharmony_ci * 	QP [ SQ / RQ / CQ ] info.
4938c2ecf20Sopenharmony_ci ******************************************************************************/
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci/*
4968c2ecf20Sopenharmony_ci * SQ/RQ/CQ generic structure definition
4978c2ecf20Sopenharmony_ci */
4988c2ecf20Sopenharmony_cistruct 	sqe {
4998c2ecf20Sopenharmony_ci	u8 sqe_byte[BNX2I_SQ_WQE_SIZE];
5008c2ecf20Sopenharmony_ci};
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_cistruct 	rqe {
5038c2ecf20Sopenharmony_ci	u8 rqe_byte[BNX2I_RQ_WQE_SIZE];
5048c2ecf20Sopenharmony_ci};
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_cistruct 	cqe {
5078c2ecf20Sopenharmony_ci	u8 cqe_byte[BNX2I_CQE_SIZE];
5088c2ecf20Sopenharmony_ci};
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_cienum {
5128c2ecf20Sopenharmony_ci#if defined(__LITTLE_ENDIAN)
5138c2ecf20Sopenharmony_ci	CNIC_EVENT_COAL_INDEX	= 0x0,
5148c2ecf20Sopenharmony_ci	CNIC_SEND_DOORBELL	= 0x4,
5158c2ecf20Sopenharmony_ci	CNIC_EVENT_CQ_ARM	= 0x7,
5168c2ecf20Sopenharmony_ci	CNIC_RECV_DOORBELL	= 0x8
5178c2ecf20Sopenharmony_ci#elif defined(__BIG_ENDIAN)
5188c2ecf20Sopenharmony_ci	CNIC_EVENT_COAL_INDEX	= 0x2,
5198c2ecf20Sopenharmony_ci	CNIC_SEND_DOORBELL	= 0x6,
5208c2ecf20Sopenharmony_ci	CNIC_EVENT_CQ_ARM	= 0x4,
5218c2ecf20Sopenharmony_ci	CNIC_RECV_DOORBELL	= 0xa
5228c2ecf20Sopenharmony_ci#endif
5238c2ecf20Sopenharmony_ci};
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci/*
5278c2ecf20Sopenharmony_ci * CQ DB
5288c2ecf20Sopenharmony_ci */
5298c2ecf20Sopenharmony_cistruct bnx2x_iscsi_cq_pend_cmpl {
5308c2ecf20Sopenharmony_ci	/* CQ producer, updated by Ustorm */
5318c2ecf20Sopenharmony_ci	u16 ustrom_prod;
5328c2ecf20Sopenharmony_ci	/* CQ pending completion counter */
5338c2ecf20Sopenharmony_ci	u16 pend_cntr;
5348c2ecf20Sopenharmony_ci};
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_cistruct bnx2i_5771x_cq_db {
5388c2ecf20Sopenharmony_ci	struct bnx2x_iscsi_cq_pend_cmpl qp_pend_cmpl[BNX2X_MAX_CQS];
5398c2ecf20Sopenharmony_ci	/* CQ pending completion ITT array */
5408c2ecf20Sopenharmony_ci	u16 itt[BNX2X_MAX_CQS];
5418c2ecf20Sopenharmony_ci	/* Cstorm CQ sequence to notify array, updated by driver */;
5428c2ecf20Sopenharmony_ci	u16 sqn[BNX2X_MAX_CQS];
5438c2ecf20Sopenharmony_ci	u32 reserved[4] /* 16 byte allignment */;
5448c2ecf20Sopenharmony_ci};
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_cistruct bnx2i_5771x_sq_rq_db {
5488c2ecf20Sopenharmony_ci	u16 prod_idx;
5498c2ecf20Sopenharmony_ci	u8 reserved0[62]; /* Pad structure size to 64 bytes */
5508c2ecf20Sopenharmony_ci};
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_cistruct bnx2i_5771x_dbell_hdr {
5548c2ecf20Sopenharmony_ci	u8 header;
5558c2ecf20Sopenharmony_ci	/* 1 for rx doorbell, 0 for tx doorbell */
5568c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_RX				(0x1<<0)
5578c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_RX_SHIFT			0
5588c2ecf20Sopenharmony_ci	/* 0 for normal doorbell, 1 for advertise wnd doorbell */
5598c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_DB_TYPE			(0x1<<1)
5608c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_DB_TYPE_SHIFT		1
5618c2ecf20Sopenharmony_ci	/* rdma tx only: DPM transaction size specifier (64/128/256/512B) */
5628c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_DPM_SIZE			(0x3<<2)
5638c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_DPM_SIZE_SHIFT		2
5648c2ecf20Sopenharmony_ci	/* connection type */
5658c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_CONN_TYPE			(0xF<<4)
5668c2ecf20Sopenharmony_ci#define B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT		4
5678c2ecf20Sopenharmony_ci};
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_cistruct bnx2i_5771x_dbell {
5708c2ecf20Sopenharmony_ci	struct bnx2i_5771x_dbell_hdr dbell;
5718c2ecf20Sopenharmony_ci	u8 pad[3];
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci};
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci/**
5768c2ecf20Sopenharmony_ci * struct qp_info - QP (share queue region) atrributes structure
5778c2ecf20Sopenharmony_ci *
5788c2ecf20Sopenharmony_ci * @ctx_base:           ioremapped pci register base to access doorbell register
5798c2ecf20Sopenharmony_ci *                      pertaining to this offloaded connection
5808c2ecf20Sopenharmony_ci * @sq_virt:            virtual address of send queue (SQ) region
5818c2ecf20Sopenharmony_ci * @sq_phys:            DMA address of SQ memory region
5828c2ecf20Sopenharmony_ci * @sq_mem_size:        SQ size
5838c2ecf20Sopenharmony_ci * @sq_prod_qe:         SQ producer entry pointer
5848c2ecf20Sopenharmony_ci * @sq_cons_qe:         SQ consumer entry pointer
5858c2ecf20Sopenharmony_ci * @sq_first_qe:        virtual address of first entry in SQ
5868c2ecf20Sopenharmony_ci * @sq_last_qe:         virtual address of last entry in SQ
5878c2ecf20Sopenharmony_ci * @sq_prod_idx:        SQ producer index
5888c2ecf20Sopenharmony_ci * @sq_cons_idx:        SQ consumer index
5898c2ecf20Sopenharmony_ci * @sqe_left:           number sq entry left
5908c2ecf20Sopenharmony_ci * @sq_pgtbl_virt:      page table describing buffer consituting SQ region
5918c2ecf20Sopenharmony_ci * @sq_pgtbl_phys:      dma address of 'sq_pgtbl_virt'
5928c2ecf20Sopenharmony_ci * @sq_pgtbl_size:      SQ page table size
5938c2ecf20Sopenharmony_ci * @cq_virt:            virtual address of completion queue (CQ) region
5948c2ecf20Sopenharmony_ci * @cq_phys:            DMA address of RQ memory region
5958c2ecf20Sopenharmony_ci * @cq_mem_size:        CQ size
5968c2ecf20Sopenharmony_ci * @cq_prod_qe:         CQ producer entry pointer
5978c2ecf20Sopenharmony_ci * @cq_cons_qe:         CQ consumer entry pointer
5988c2ecf20Sopenharmony_ci * @cq_first_qe:        virtual address of first entry in CQ
5998c2ecf20Sopenharmony_ci * @cq_last_qe:         virtual address of last entry in CQ
6008c2ecf20Sopenharmony_ci * @cq_prod_idx:        CQ producer index
6018c2ecf20Sopenharmony_ci * @cq_cons_idx:        CQ consumer index
6028c2ecf20Sopenharmony_ci * @cqe_left:           number cq entry left
6038c2ecf20Sopenharmony_ci * @cqe_size:           size of each CQ entry
6048c2ecf20Sopenharmony_ci * @cqe_exp_seq_sn:     next expected CQE sequence number
6058c2ecf20Sopenharmony_ci * @cq_pgtbl_virt:      page table describing buffer consituting CQ region
6068c2ecf20Sopenharmony_ci * @cq_pgtbl_phys:      dma address of 'cq_pgtbl_virt'
6078c2ecf20Sopenharmony_ci * @cq_pgtbl_size:    	CQ page table size
6088c2ecf20Sopenharmony_ci * @rq_virt:            virtual address of receive queue (RQ) region
6098c2ecf20Sopenharmony_ci * @rq_phys:            DMA address of RQ memory region
6108c2ecf20Sopenharmony_ci * @rq_mem_size:        RQ size
6118c2ecf20Sopenharmony_ci * @rq_prod_qe:         RQ producer entry pointer
6128c2ecf20Sopenharmony_ci * @rq_cons_qe:         RQ consumer entry pointer
6138c2ecf20Sopenharmony_ci * @rq_first_qe:        virtual address of first entry in RQ
6148c2ecf20Sopenharmony_ci * @rq_last_qe:         virtual address of last entry in RQ
6158c2ecf20Sopenharmony_ci * @rq_prod_idx:        RQ producer index
6168c2ecf20Sopenharmony_ci * @rq_cons_idx:        RQ consumer index
6178c2ecf20Sopenharmony_ci * @rqe_left:           number rq entry left
6188c2ecf20Sopenharmony_ci * @rq_pgtbl_virt:      page table describing buffer consituting RQ region
6198c2ecf20Sopenharmony_ci * @rq_pgtbl_phys:      dma address of 'rq_pgtbl_virt'
6208c2ecf20Sopenharmony_ci * @rq_pgtbl_size:      RQ page table size
6218c2ecf20Sopenharmony_ci *
6228c2ecf20Sopenharmony_ci * queue pair (QP) is a per connection shared data structure which is used
6238c2ecf20Sopenharmony_ci *	to send work requests (SQ), receive completion notifications (CQ)
6248c2ecf20Sopenharmony_ci *	and receive asynchoronous / scsi sense info (RQ). 'qp_info' structure
6258c2ecf20Sopenharmony_ci *	below holds queue memory, consumer/producer indexes and page table
6268c2ecf20Sopenharmony_ci *	information
6278c2ecf20Sopenharmony_ci */
6288c2ecf20Sopenharmony_cistruct qp_info {
6298c2ecf20Sopenharmony_ci	void __iomem *ctx_base;
6308c2ecf20Sopenharmony_ci#define DPM_TRIGER_TYPE			0x40
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci#define BNX2I_570x_QUE_DB_SIZE		0
6338c2ecf20Sopenharmony_ci#define BNX2I_5771x_QUE_DB_SIZE		16
6348c2ecf20Sopenharmony_ci	struct sqe *sq_virt;
6358c2ecf20Sopenharmony_ci	dma_addr_t sq_phys;
6368c2ecf20Sopenharmony_ci	u32 sq_mem_size;
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	struct sqe *sq_prod_qe;
6398c2ecf20Sopenharmony_ci	struct sqe *sq_cons_qe;
6408c2ecf20Sopenharmony_ci	struct sqe *sq_first_qe;
6418c2ecf20Sopenharmony_ci	struct sqe *sq_last_qe;
6428c2ecf20Sopenharmony_ci	u16 sq_prod_idx;
6438c2ecf20Sopenharmony_ci	u16 sq_cons_idx;
6448c2ecf20Sopenharmony_ci	u32 sqe_left;
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci	void *sq_pgtbl_virt;
6478c2ecf20Sopenharmony_ci	dma_addr_t sq_pgtbl_phys;
6488c2ecf20Sopenharmony_ci	u32 sq_pgtbl_size;	/* set to PAGE_SIZE for 5708 & 5709 */
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	struct cqe *cq_virt;
6518c2ecf20Sopenharmony_ci	dma_addr_t cq_phys;
6528c2ecf20Sopenharmony_ci	u32 cq_mem_size;
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	struct cqe *cq_prod_qe;
6558c2ecf20Sopenharmony_ci	struct cqe *cq_cons_qe;
6568c2ecf20Sopenharmony_ci	struct cqe *cq_first_qe;
6578c2ecf20Sopenharmony_ci	struct cqe *cq_last_qe;
6588c2ecf20Sopenharmony_ci	u16 cq_prod_idx;
6598c2ecf20Sopenharmony_ci	u16 cq_cons_idx;
6608c2ecf20Sopenharmony_ci	u32 cqe_left;
6618c2ecf20Sopenharmony_ci	u32 cqe_size;
6628c2ecf20Sopenharmony_ci	u32 cqe_exp_seq_sn;
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci	void *cq_pgtbl_virt;
6658c2ecf20Sopenharmony_ci	dma_addr_t cq_pgtbl_phys;
6668c2ecf20Sopenharmony_ci	u32 cq_pgtbl_size;	/* set to PAGE_SIZE for 5708 & 5709 */
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	struct rqe *rq_virt;
6698c2ecf20Sopenharmony_ci	dma_addr_t rq_phys;
6708c2ecf20Sopenharmony_ci	u32 rq_mem_size;
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ci	struct rqe *rq_prod_qe;
6738c2ecf20Sopenharmony_ci	struct rqe *rq_cons_qe;
6748c2ecf20Sopenharmony_ci	struct rqe *rq_first_qe;
6758c2ecf20Sopenharmony_ci	struct rqe *rq_last_qe;
6768c2ecf20Sopenharmony_ci	u16 rq_prod_idx;
6778c2ecf20Sopenharmony_ci	u16 rq_cons_idx;
6788c2ecf20Sopenharmony_ci	u32 rqe_left;
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	void *rq_pgtbl_virt;
6818c2ecf20Sopenharmony_ci	dma_addr_t rq_pgtbl_phys;
6828c2ecf20Sopenharmony_ci	u32 rq_pgtbl_size;	/* set to PAGE_SIZE for 5708 & 5709 */
6838c2ecf20Sopenharmony_ci};
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci/*
6888c2ecf20Sopenharmony_ci * CID handles
6898c2ecf20Sopenharmony_ci */
6908c2ecf20Sopenharmony_cistruct ep_handles {
6918c2ecf20Sopenharmony_ci	u32 fw_cid;
6928c2ecf20Sopenharmony_ci	u32 drv_iscsi_cid;
6938c2ecf20Sopenharmony_ci	u16 pg_cid;
6948c2ecf20Sopenharmony_ci	u16 rsvd;
6958c2ecf20Sopenharmony_ci};
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cienum {
6998c2ecf20Sopenharmony_ci	EP_STATE_IDLE                   = 0x0,
7008c2ecf20Sopenharmony_ci	EP_STATE_PG_OFLD_START          = 0x1,
7018c2ecf20Sopenharmony_ci	EP_STATE_PG_OFLD_COMPL          = 0x2,
7028c2ecf20Sopenharmony_ci	EP_STATE_OFLD_START             = 0x4,
7038c2ecf20Sopenharmony_ci	EP_STATE_OFLD_COMPL             = 0x8,
7048c2ecf20Sopenharmony_ci	EP_STATE_CONNECT_START          = 0x10,
7058c2ecf20Sopenharmony_ci	EP_STATE_CONNECT_COMPL          = 0x20,
7068c2ecf20Sopenharmony_ci	EP_STATE_ULP_UPDATE_START       = 0x40,
7078c2ecf20Sopenharmony_ci	EP_STATE_ULP_UPDATE_COMPL       = 0x80,
7088c2ecf20Sopenharmony_ci	EP_STATE_DISCONN_START          = 0x100,
7098c2ecf20Sopenharmony_ci	EP_STATE_DISCONN_COMPL          = 0x200,
7108c2ecf20Sopenharmony_ci	EP_STATE_CLEANUP_START          = 0x400,
7118c2ecf20Sopenharmony_ci	EP_STATE_CLEANUP_CMPL           = 0x800,
7128c2ecf20Sopenharmony_ci	EP_STATE_TCP_FIN_RCVD           = 0x1000,
7138c2ecf20Sopenharmony_ci	EP_STATE_TCP_RST_RCVD           = 0x2000,
7148c2ecf20Sopenharmony_ci	EP_STATE_LOGOUT_SENT            = 0x4000,
7158c2ecf20Sopenharmony_ci	EP_STATE_LOGOUT_RESP_RCVD       = 0x8000,
7168c2ecf20Sopenharmony_ci	EP_STATE_PG_OFLD_FAILED         = 0x1000000,
7178c2ecf20Sopenharmony_ci	EP_STATE_ULP_UPDATE_FAILED      = 0x2000000,
7188c2ecf20Sopenharmony_ci	EP_STATE_CLEANUP_FAILED         = 0x4000000,
7198c2ecf20Sopenharmony_ci	EP_STATE_OFLD_FAILED            = 0x8000000,
7208c2ecf20Sopenharmony_ci	EP_STATE_CONNECT_FAILED         = 0x10000000,
7218c2ecf20Sopenharmony_ci	EP_STATE_DISCONN_TIMEDOUT       = 0x20000000,
7228c2ecf20Sopenharmony_ci	EP_STATE_OFLD_FAILED_CID_BUSY   = 0x80000000,
7238c2ecf20Sopenharmony_ci};
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci/**
7268c2ecf20Sopenharmony_ci * struct bnx2i_endpoint - representation of tcp connection in NX2 world
7278c2ecf20Sopenharmony_ci *
7288c2ecf20Sopenharmony_ci * @link:               list head to link elements
7298c2ecf20Sopenharmony_ci * @hba:                adapter to which this connection belongs
7308c2ecf20Sopenharmony_ci * @conn:               iscsi connection this EP is linked to
7318c2ecf20Sopenharmony_ci * @cls_ep:             associated iSCSI endpoint pointer
7328c2ecf20Sopenharmony_ci * @cm_sk:              cnic sock struct
7338c2ecf20Sopenharmony_ci * @hba_age:            age to detect if 'iscsid' issues ep_disconnect()
7348c2ecf20Sopenharmony_ci *                      after HBA reset is completed by bnx2i/cnic/bnx2
7358c2ecf20Sopenharmony_ci *                      modules
7368c2ecf20Sopenharmony_ci * @state:              tracks offload connection state machine
7378c2ecf20Sopenharmony_ci * @timestamp:          tracks the start time when the ep begins to connect
7388c2ecf20Sopenharmony_ci * @num_active_cmds:    tracks the number of outstanding commands for this ep
7398c2ecf20Sopenharmony_ci * @ec_shift:           the amount of shift as part of the event coal calc
7408c2ecf20Sopenharmony_ci * @qp:                 QP information
7418c2ecf20Sopenharmony_ci * @ids:                contains chip allocated *context id* & driver assigned
7428c2ecf20Sopenharmony_ci *                      *iscsi cid*
7438c2ecf20Sopenharmony_ci * @ofld_timer:         offload timer to detect timeout
7448c2ecf20Sopenharmony_ci * @ofld_wait:          wait queue
7458c2ecf20Sopenharmony_ci *
7468c2ecf20Sopenharmony_ci * Endpoint Structure - equivalent of tcp socket structure
7478c2ecf20Sopenharmony_ci */
7488c2ecf20Sopenharmony_cistruct bnx2i_endpoint {
7498c2ecf20Sopenharmony_ci	struct list_head link;
7508c2ecf20Sopenharmony_ci	struct bnx2i_hba *hba;
7518c2ecf20Sopenharmony_ci	struct bnx2i_conn *conn;
7528c2ecf20Sopenharmony_ci	struct iscsi_endpoint *cls_ep;
7538c2ecf20Sopenharmony_ci	struct cnic_sock *cm_sk;
7548c2ecf20Sopenharmony_ci	u32 hba_age;
7558c2ecf20Sopenharmony_ci	u32 state;
7568c2ecf20Sopenharmony_ci	unsigned long timestamp;
7578c2ecf20Sopenharmony_ci	atomic_t num_active_cmds;
7588c2ecf20Sopenharmony_ci	u32 ec_shift;
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci	struct qp_info qp;
7618c2ecf20Sopenharmony_ci	struct ep_handles ids;
7628c2ecf20Sopenharmony_ci		#define ep_iscsi_cid	ids.drv_iscsi_cid
7638c2ecf20Sopenharmony_ci		#define ep_cid		ids.fw_cid
7648c2ecf20Sopenharmony_ci		#define ep_pg_cid	ids.pg_cid
7658c2ecf20Sopenharmony_ci	struct timer_list ofld_timer;
7668c2ecf20Sopenharmony_ci	wait_queue_head_t ofld_wait;
7678c2ecf20Sopenharmony_ci};
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_cistruct bnx2i_work {
7718c2ecf20Sopenharmony_ci	struct list_head list;
7728c2ecf20Sopenharmony_ci	struct iscsi_session *session;
7738c2ecf20Sopenharmony_ci	struct bnx2i_conn *bnx2i_conn;
7748c2ecf20Sopenharmony_ci	struct cqe cqe;
7758c2ecf20Sopenharmony_ci};
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_cistruct bnx2i_percpu_s {
7788c2ecf20Sopenharmony_ci	struct task_struct *iothread;
7798c2ecf20Sopenharmony_ci	struct list_head work_list;
7808c2ecf20Sopenharmony_ci	spinlock_t p_work_lock;
7818c2ecf20Sopenharmony_ci};
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci/* Global variables */
7858c2ecf20Sopenharmony_ciextern unsigned int error_mask1, error_mask2;
7868c2ecf20Sopenharmony_ciextern u64 iscsi_error_mask;
7878c2ecf20Sopenharmony_ciextern unsigned int en_tcp_dack;
7888c2ecf20Sopenharmony_ciextern unsigned int event_coal_div;
7898c2ecf20Sopenharmony_ciextern unsigned int event_coal_min;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ciextern struct scsi_transport_template *bnx2i_scsi_xport_template;
7928c2ecf20Sopenharmony_ciextern struct iscsi_transport bnx2i_iscsi_transport;
7938c2ecf20Sopenharmony_ciextern struct cnic_ulp_ops bnx2i_cnic_cb;
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ciextern unsigned int sq_size;
7968c2ecf20Sopenharmony_ciextern unsigned int rq_size;
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ciextern struct device_attribute *bnx2i_dev_attributes[];
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci/*
8038c2ecf20Sopenharmony_ci * Function Prototypes
8048c2ecf20Sopenharmony_ci */
8058c2ecf20Sopenharmony_ciextern void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev);
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ciextern void bnx2i_ulp_init(struct cnic_dev *dev);
8088c2ecf20Sopenharmony_ciextern void bnx2i_ulp_exit(struct cnic_dev *dev);
8098c2ecf20Sopenharmony_ciextern void bnx2i_start(void *handle);
8108c2ecf20Sopenharmony_ciextern void bnx2i_stop(void *handle);
8118c2ecf20Sopenharmony_ciextern int bnx2i_get_stats(void *handle);
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ciextern struct bnx2i_hba *get_adapter_list_head(void);
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_cistruct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
8168c2ecf20Sopenharmony_ci					  u16 iscsi_cid);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ciint bnx2i_alloc_ep_pool(void);
8198c2ecf20Sopenharmony_civoid bnx2i_release_ep_pool(void);
8208c2ecf20Sopenharmony_cistruct bnx2i_endpoint *bnx2i_ep_ofld_list_next(struct bnx2i_hba *hba);
8218c2ecf20Sopenharmony_cistruct bnx2i_endpoint *bnx2i_ep_destroy_list_next(struct bnx2i_hba *hba);
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_cistruct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic);
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_cistruct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic);
8268c2ecf20Sopenharmony_civoid bnx2i_free_hba(struct bnx2i_hba *hba);
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_civoid bnx2i_get_rq_buf(struct bnx2i_conn *conn, char *ptr, int len);
8298c2ecf20Sopenharmony_civoid bnx2i_put_rq_buf(struct bnx2i_conn *conn, int count);
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_civoid bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd);
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_civoid bnx2i_drop_session(struct iscsi_cls_session *session);
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ciextern int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba);
8368c2ecf20Sopenharmony_ciextern int bnx2i_send_iscsi_login(struct bnx2i_conn *conn,
8378c2ecf20Sopenharmony_ci				  struct iscsi_task *mtask);
8388c2ecf20Sopenharmony_ciextern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn,
8398c2ecf20Sopenharmony_ci				  struct iscsi_task *mtask);
8408c2ecf20Sopenharmony_ciextern int bnx2i_send_iscsi_text(struct bnx2i_conn *conn,
8418c2ecf20Sopenharmony_ci				 struct iscsi_task *mtask);
8428c2ecf20Sopenharmony_ciextern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn,
8438c2ecf20Sopenharmony_ci				    struct bnx2i_cmd *cmnd);
8448c2ecf20Sopenharmony_ciextern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn,
8458c2ecf20Sopenharmony_ci				   struct iscsi_task *mtask,
8468c2ecf20Sopenharmony_ci				   char *datap, int data_len, int unsol);
8478c2ecf20Sopenharmony_ciextern int bnx2i_send_iscsi_logout(struct bnx2i_conn *conn,
8488c2ecf20Sopenharmony_ci				   struct iscsi_task *mtask);
8498c2ecf20Sopenharmony_ciextern void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba,
8508c2ecf20Sopenharmony_ci				       struct bnx2i_cmd *cmd);
8518c2ecf20Sopenharmony_ciextern int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba,
8528c2ecf20Sopenharmony_ci				    struct bnx2i_endpoint *ep);
8538c2ecf20Sopenharmony_ciextern void bnx2i_update_iscsi_conn(struct iscsi_conn *conn);
8548c2ecf20Sopenharmony_ciextern int bnx2i_send_conn_destroy(struct bnx2i_hba *hba,
8558c2ecf20Sopenharmony_ci				   struct bnx2i_endpoint *ep);
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ciextern int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
8588c2ecf20Sopenharmony_ci			       struct bnx2i_endpoint *ep);
8598c2ecf20Sopenharmony_ciextern void bnx2i_free_qp_resc(struct bnx2i_hba *hba,
8608c2ecf20Sopenharmony_ci			       struct bnx2i_endpoint *ep);
8618c2ecf20Sopenharmony_ciextern void bnx2i_ep_ofld_timer(struct timer_list *t);
8628c2ecf20Sopenharmony_ciextern struct bnx2i_endpoint *bnx2i_find_ep_in_ofld_list(
8638c2ecf20Sopenharmony_ci		struct bnx2i_hba *hba, u32 iscsi_cid);
8648c2ecf20Sopenharmony_ciextern struct bnx2i_endpoint *bnx2i_find_ep_in_destroy_list(
8658c2ecf20Sopenharmony_ci		struct bnx2i_hba *hba, u32 iscsi_cid);
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ciextern int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep);
8688c2ecf20Sopenharmony_ciextern int bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action);
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ciextern int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep);
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci/* Debug related function prototypes */
8738c2ecf20Sopenharmony_ciextern void bnx2i_print_pend_cmd_queue(struct bnx2i_conn *conn);
8748c2ecf20Sopenharmony_ciextern void bnx2i_print_active_cmd_queue(struct bnx2i_conn *conn);
8758c2ecf20Sopenharmony_ciextern void bnx2i_print_xmit_pdu_queue(struct bnx2i_conn *conn);
8768c2ecf20Sopenharmony_ciextern void bnx2i_print_recv_state(struct bnx2i_conn *conn);
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ciextern int bnx2i_percpu_io_thread(void *arg);
8798c2ecf20Sopenharmony_ciextern int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
8808c2ecf20Sopenharmony_ci				       struct bnx2i_conn *bnx2i_conn,
8818c2ecf20Sopenharmony_ci				       struct cqe *cqe);
8828c2ecf20Sopenharmony_ci#endif
883