| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * QLogic iSCSI Offload Driver | 
 | 3 |  * Copyright (c) 2016 Cavium Inc. | 
 | 4 |  * | 
 | 5 |  * This software is available under the terms of the GNU General Public License | 
 | 6 |  * (GPL) Version 2, available from the file COPYING in the main directory of | 
 | 7 |  * this source tree. | 
 | 8 |  */ | 
 | 9 |  | 
 | 10 | #ifndef _QEDI_H_ | 
 | 11 | #define _QEDI_H_ | 
 | 12 |  | 
 | 13 | #define __PREVENT_QED_HSI__ | 
 | 14 |  | 
 | 15 | #include <scsi/scsi_transport_iscsi.h> | 
 | 16 | #include <scsi/libiscsi.h> | 
 | 17 | #include <scsi/scsi_host.h> | 
 | 18 | #include <linux/uio_driver.h> | 
 | 19 |  | 
 | 20 | #include "qedi_hsi.h" | 
 | 21 | #include <linux/qed/qed_if.h> | 
 | 22 | #include "qedi_dbg.h" | 
 | 23 | #include <linux/qed/qed_iscsi_if.h> | 
 | 24 | #include <linux/qed/qed_ll2_if.h> | 
 | 25 | #include "qedi_version.h" | 
 | 26 | #include "qedi_nvm_iscsi_cfg.h" | 
 | 27 |  | 
 | 28 | #define QEDI_MODULE_NAME		"qedi" | 
 | 29 |  | 
 | 30 | struct qedi_endpoint; | 
 | 31 |  | 
 | 32 | #ifndef GET_FIELD2 | 
 | 33 | #define GET_FIELD2(value, name) \ | 
 | 34 | 	(((value) & (name ## _MASK)) >> (name ## _OFFSET)) | 
 | 35 | #endif | 
 | 36 |  | 
 | 37 | /* | 
 | 38 |  * PCI function probe defines | 
 | 39 |  */ | 
 | 40 | #define QEDI_MODE_NORMAL	0 | 
 | 41 | #define QEDI_MODE_RECOVERY	1 | 
 | 42 |  | 
 | 43 | #define ISCSI_WQE_SET_PTU_INVALIDATE	1 | 
 | 44 | #define QEDI_MAX_ISCSI_TASK		4096 | 
 | 45 | #define QEDI_MAX_TASK_NUM		0x0FFF | 
 | 46 | #define QEDI_MAX_ISCSI_CONNS_PER_HBA	1024 | 
 | 47 | #define QEDI_ISCSI_MAX_BDS_PER_CMD	255	/* Firmware max BDs is 255 */ | 
 | 48 | #define MAX_OUSTANDING_TASKS_PER_CON	1024 | 
 | 49 |  | 
 | 50 | #define QEDI_MAX_BD_LEN		0xffff | 
 | 51 | #define QEDI_BD_SPLIT_SZ	0x1000 | 
 | 52 | #define QEDI_PAGE_SIZE		4096 | 
 | 53 | #define QEDI_FAST_SGE_COUNT	4 | 
 | 54 | /* MAX Length for cached SGL */ | 
 | 55 | #define MAX_SGLEN_FOR_CACHESGL	((1U << 16) - 1) | 
 | 56 |  | 
 | 57 | #define MIN_NUM_CPUS_MSIX(x)	min_t(u32, x->dev_info.num_cqs, \ | 
 | 58 | 					num_online_cpus()) | 
 | 59 |  | 
 | 60 | #define QEDI_LOCAL_PORT_MIN     60000 | 
 | 61 | #define QEDI_LOCAL_PORT_MAX     61024 | 
 | 62 | #define QEDI_LOCAL_PORT_RANGE   (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN) | 
 | 63 | #define QEDI_LOCAL_PORT_INVALID	0xffff | 
 | 64 | #define TX_RX_RING		16 | 
 | 65 | #define RX_RING			(TX_RX_RING - 1) | 
 | 66 | #define LL2_SINGLE_BUF_SIZE	0x400 | 
 | 67 | #define QEDI_PAGE_SIZE		4096 | 
 | 68 | #define QEDI_PAGE_ALIGN(addr)	ALIGN(addr, QEDI_PAGE_SIZE) | 
 | 69 | #define QEDI_PAGE_MASK		(~((QEDI_PAGE_SIZE) - 1)) | 
 | 70 |  | 
 | 71 | #define QEDI_PAGE_SIZE		4096 | 
 | 72 | #define QEDI_HW_DMA_BOUNDARY	0xfff | 
 | 73 | #define QEDI_PATH_HANDLE	0xFE0000000UL | 
 | 74 |  | 
 | 75 | enum qedi_nvm_tgts { | 
 | 76 | 	QEDI_NVM_TGT_PRI, | 
 | 77 | 	QEDI_NVM_TGT_SEC, | 
 | 78 | }; | 
 | 79 |  | 
 | 80 | struct qedi_nvm_iscsi_image { | 
 | 81 | 	struct nvm_iscsi_cfg iscsi_cfg; | 
 | 82 | 	u32 crc; | 
 | 83 | }; | 
 | 84 |  | 
 | 85 | struct qedi_uio_ctrl { | 
 | 86 | 	/* meta data */ | 
 | 87 | 	u32 uio_hsi_version; | 
 | 88 |  | 
 | 89 | 	/* user writes */ | 
 | 90 | 	u32 host_tx_prod; | 
 | 91 | 	u32 host_rx_cons; | 
 | 92 | 	u32 host_rx_bd_cons; | 
 | 93 | 	u32 host_tx_pkt_len; | 
 | 94 | 	u32 host_rx_cons_cnt; | 
 | 95 |  | 
 | 96 | 	/* driver writes */ | 
 | 97 | 	u32 hw_tx_cons; | 
 | 98 | 	u32 hw_rx_prod; | 
 | 99 | 	u32 hw_rx_bd_prod; | 
 | 100 | 	u32 hw_rx_prod_cnt; | 
 | 101 |  | 
 | 102 | 	/* other */ | 
 | 103 | 	u8 mac_addr[6]; | 
 | 104 | 	u8 reserve[2]; | 
 | 105 | }; | 
 | 106 |  | 
 | 107 | struct qedi_rx_bd { | 
 | 108 | 	u32 rx_pkt_index; | 
 | 109 | 	u32 rx_pkt_len; | 
 | 110 | 	u16 vlan_id; | 
 | 111 | }; | 
 | 112 |  | 
 | 113 | #define QEDI_RX_DESC_CNT	(QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd)) | 
 | 114 | #define QEDI_MAX_RX_DESC_CNT	(QEDI_RX_DESC_CNT - 1) | 
 | 115 | #define QEDI_NUM_RX_BD		(QEDI_RX_DESC_CNT * 1) | 
 | 116 | #define QEDI_MAX_RX_BD		(QEDI_NUM_RX_BD - 1) | 
 | 117 |  | 
 | 118 | #define QEDI_NEXT_RX_IDX(x)	((((x) & (QEDI_MAX_RX_DESC_CNT)) ==	\ | 
 | 119 | 				  (QEDI_MAX_RX_DESC_CNT - 1)) ?		\ | 
 | 120 | 				 (x) + 2 : (x) + 1) | 
 | 121 |  | 
 | 122 | struct qedi_uio_dev { | 
 | 123 | 	struct uio_info		qedi_uinfo; | 
 | 124 | 	u32			uio_dev; | 
 | 125 | 	struct list_head	list; | 
 | 126 |  | 
 | 127 | 	u32			ll2_ring_size; | 
 | 128 | 	void			*ll2_ring; | 
 | 129 |  | 
 | 130 | 	u32			ll2_buf_size; | 
 | 131 | 	void			*ll2_buf; | 
 | 132 |  | 
 | 133 | 	void			*rx_pkt; | 
 | 134 | 	void			*tx_pkt; | 
 | 135 |  | 
 | 136 | 	struct qedi_ctx		*qedi; | 
 | 137 | 	struct pci_dev		*pdev; | 
 | 138 | 	void			*uctrl; | 
 | 139 | }; | 
 | 140 |  | 
 | 141 | /* List to maintain the skb pointers */ | 
 | 142 | struct skb_work_list { | 
 | 143 | 	struct list_head list; | 
 | 144 | 	struct sk_buff *skb; | 
 | 145 | 	u16 vlan_id; | 
 | 146 | }; | 
 | 147 |  | 
 | 148 | /* Queue sizes in number of elements */ | 
 | 149 | #define QEDI_SQ_SIZE		MAX_OUSTANDING_TASKS_PER_CON | 
 | 150 | #define QEDI_CQ_SIZE		2048 | 
 | 151 | #define QEDI_CMDQ_SIZE		QEDI_MAX_ISCSI_TASK | 
 | 152 | #define QEDI_PROTO_CQ_PROD_IDX	0 | 
 | 153 |  | 
 | 154 | struct qedi_glbl_q_params { | 
 | 155 | 	u64 hw_p_cq;	/* Completion queue PBL */ | 
 | 156 | 	u64 hw_p_rq;	/* Request queue PBL */ | 
 | 157 | 	u64 hw_p_cmdq;	/* Command queue PBL */ | 
 | 158 | }; | 
 | 159 |  | 
 | 160 | struct global_queue { | 
 | 161 | 	union iscsi_cqe *cq; | 
 | 162 | 	dma_addr_t cq_dma; | 
 | 163 | 	u32 cq_mem_size; | 
 | 164 | 	u32 cq_cons_idx; /* Completion queue consumer index */ | 
 | 165 |  | 
 | 166 | 	void *cq_pbl; | 
 | 167 | 	dma_addr_t cq_pbl_dma; | 
 | 168 | 	u32 cq_pbl_size; | 
 | 169 |  | 
 | 170 | }; | 
 | 171 |  | 
 | 172 | struct qedi_fastpath { | 
 | 173 | 	struct qed_sb_info	*sb_info; | 
 | 174 | 	u16			sb_id; | 
 | 175 | #define QEDI_NAME_SIZE		16 | 
 | 176 | 	char			name[QEDI_NAME_SIZE]; | 
 | 177 | 	struct qedi_ctx         *qedi; | 
 | 178 | }; | 
 | 179 |  | 
 | 180 | /* Used to pass fastpath information needed to process CQEs */ | 
 | 181 | struct qedi_io_work { | 
 | 182 | 	struct list_head list; | 
 | 183 | 	struct iscsi_cqe_solicited cqe; | 
 | 184 | 	u16	que_idx; | 
 | 185 | }; | 
 | 186 |  | 
 | 187 | /** | 
 | 188 |  * struct iscsi_cid_queue - Per adapter iscsi cid queue | 
 | 189 |  * | 
 | 190 |  * @cid_que_base:           queue base memory | 
 | 191 |  * @cid_que:                queue memory pointer | 
 | 192 |  * @cid_q_prod_idx:         produce index | 
 | 193 |  * @cid_q_cons_idx:         consumer index | 
 | 194 |  * @cid_q_max_idx:          max index. used to detect wrap around condition | 
 | 195 |  * @cid_free_cnt:           queue size | 
 | 196 |  * @conn_cid_tbl:           iscsi cid to conn structure mapping table | 
 | 197 |  * | 
 | 198 |  * Per adapter iSCSI CID Queue | 
 | 199 |  */ | 
 | 200 | struct iscsi_cid_queue { | 
 | 201 | 	void *cid_que_base; | 
 | 202 | 	u32 *cid_que; | 
 | 203 | 	u32 cid_q_prod_idx; | 
 | 204 | 	u32 cid_q_cons_idx; | 
 | 205 | 	u32 cid_q_max_idx; | 
 | 206 | 	u32 cid_free_cnt; | 
 | 207 | 	struct qedi_conn **conn_cid_tbl; | 
 | 208 | }; | 
 | 209 |  | 
 | 210 | struct qedi_portid_tbl { | 
 | 211 | 	spinlock_t      lock;	/* Port id lock */ | 
 | 212 | 	u16             start; | 
 | 213 | 	u16             max; | 
 | 214 | 	u16             next; | 
 | 215 | 	unsigned long   *table; | 
 | 216 | }; | 
 | 217 |  | 
 | 218 | struct qedi_itt_map { | 
 | 219 | 	__le32	itt; | 
 | 220 | 	struct qedi_cmd *p_cmd; | 
 | 221 | }; | 
 | 222 |  | 
 | 223 | /* I/O tracing entry */ | 
 | 224 | #define QEDI_IO_TRACE_SIZE             2048 | 
 | 225 | struct qedi_io_log { | 
 | 226 | #define QEDI_IO_TRACE_REQ              0 | 
 | 227 | #define QEDI_IO_TRACE_RSP              1 | 
 | 228 | 	u8 direction; | 
 | 229 | 	u16 task_id; | 
 | 230 | 	u32 cid; | 
 | 231 | 	u32 port_id;	/* Remote port fabric ID */ | 
 | 232 | 	int lun; | 
 | 233 | 	u8 op;		/* SCSI CDB */ | 
 | 234 | 	u8 lba[4]; | 
 | 235 | 	unsigned int bufflen;	/* SCSI buffer length */ | 
 | 236 | 	unsigned int sg_count;	/* Number of SG elements */ | 
 | 237 | 	u8 fast_sgs;		/* number of fast sgls */ | 
 | 238 | 	u8 slow_sgs;		/* number of slow sgls */ | 
 | 239 | 	u8 cached_sgs;		/* number of cached sgls */ | 
 | 240 | 	int result;		/* Result passed back to mid-layer */ | 
 | 241 | 	unsigned long jiffies;	/* Time stamp when I/O logged */ | 
 | 242 | 	int refcount;		/* Reference count for task id */ | 
 | 243 | 	unsigned int blk_req_cpu; /* CPU that the task is queued on by | 
 | 244 | 				   * blk layer | 
 | 245 | 				   */ | 
 | 246 | 	unsigned int req_cpu;	/* CPU that the task is queued on */ | 
 | 247 | 	unsigned int intr_cpu;	/* Interrupt CPU that the task is received on */ | 
 | 248 | 	unsigned int blk_rsp_cpu;/* CPU that task is actually processed and | 
 | 249 | 				  * returned to blk layer | 
 | 250 | 				  */ | 
 | 251 | 	bool cached_sge; | 
 | 252 | 	bool slow_sge; | 
 | 253 | 	bool fast_sge; | 
 | 254 | }; | 
 | 255 |  | 
 | 256 | /* Number of entries in BDQ */ | 
 | 257 | #define QEDI_BDQ_NUM		256 | 
 | 258 | #define QEDI_BDQ_BUF_SIZE	256 | 
 | 259 |  | 
 | 260 | /* DMA coherent buffers for BDQ */ | 
 | 261 | struct qedi_bdq_buf { | 
 | 262 | 	void *buf_addr; | 
 | 263 | 	dma_addr_t buf_dma; | 
 | 264 | }; | 
 | 265 |  | 
 | 266 | /* Main port level struct */ | 
 | 267 | struct qedi_ctx { | 
 | 268 | 	struct qedi_dbg_ctx dbg_ctx; | 
 | 269 | 	struct Scsi_Host *shost; | 
 | 270 | 	struct pci_dev *pdev; | 
 | 271 | 	struct qed_dev *cdev; | 
 | 272 | 	struct qed_dev_iscsi_info dev_info; | 
 | 273 | 	struct qed_int_info int_info; | 
 | 274 | 	struct qedi_glbl_q_params *p_cpuq; | 
 | 275 | 	struct global_queue **global_queues; | 
 | 276 | 	/* uio declaration */ | 
 | 277 | 	struct qedi_uio_dev *udev; | 
 | 278 | 	struct list_head ll2_skb_list; | 
 | 279 | 	spinlock_t ll2_lock;	/* Light L2 lock */ | 
 | 280 | 	spinlock_t hba_lock;	/* per port lock */ | 
 | 281 | 	struct task_struct *ll2_recv_thread; | 
 | 282 | 	unsigned long flags; | 
 | 283 | #define UIO_DEV_OPENED		1 | 
 | 284 | #define QEDI_IOTHREAD_WAKE	2 | 
 | 285 | #define QEDI_IN_RECOVERY	5 | 
 | 286 | #define QEDI_IN_OFFLINE		6 | 
 | 287 |  | 
 | 288 | 	u8 mac[ETH_ALEN]; | 
 | 289 | 	u32 src_ip[4]; | 
 | 290 | 	u8 ip_type; | 
 | 291 |  | 
 | 292 | 	/* Physical address of above array */ | 
 | 293 | 	dma_addr_t hw_p_cpuq; | 
 | 294 |  | 
 | 295 | 	struct qedi_bdq_buf bdq[QEDI_BDQ_NUM]; | 
 | 296 | 	void *bdq_pbl; | 
 | 297 | 	dma_addr_t bdq_pbl_dma; | 
 | 298 | 	size_t bdq_pbl_mem_size; | 
 | 299 | 	void *bdq_pbl_list; | 
 | 300 | 	dma_addr_t bdq_pbl_list_dma; | 
 | 301 | 	u8 bdq_pbl_list_num_entries; | 
 | 302 | 	struct qedi_nvm_iscsi_image *iscsi_image; | 
 | 303 | 	dma_addr_t nvm_buf_dma; | 
 | 304 | 	void __iomem *bdq_primary_prod; | 
 | 305 | 	void __iomem *bdq_secondary_prod; | 
 | 306 | 	u16 bdq_prod_idx; | 
 | 307 | 	u16 rq_num_entries; | 
 | 308 |  | 
 | 309 | 	u32 max_sqes; | 
 | 310 | 	u8 num_queues; | 
 | 311 | 	u32 max_active_conns; | 
 | 312 |  | 
 | 313 | 	struct iscsi_cid_queue cid_que; | 
 | 314 | 	struct qedi_endpoint **ep_tbl; | 
 | 315 | 	struct qedi_portid_tbl lcl_port_tbl; | 
 | 316 |  | 
 | 317 | 	/* Rx fast path intr context */ | 
 | 318 | 	struct qed_sb_info	*sb_array; | 
 | 319 | 	struct qedi_fastpath	*fp_array; | 
 | 320 | 	struct qed_iscsi_tid	tasks; | 
 | 321 |  | 
 | 322 | #define QEDI_LINK_DOWN		0 | 
 | 323 | #define QEDI_LINK_UP		1 | 
 | 324 | 	atomic_t link_state; | 
 | 325 |  | 
 | 326 | #define QEDI_RESERVE_TASK_ID	0 | 
 | 327 | #define MAX_ISCSI_TASK_ENTRIES	4096 | 
 | 328 | #define QEDI_INVALID_TASK_ID	(MAX_ISCSI_TASK_ENTRIES + 1) | 
 | 329 | 	unsigned long task_idx_map[MAX_ISCSI_TASK_ENTRIES / BITS_PER_LONG]; | 
 | 330 | 	struct qedi_itt_map *itt_map; | 
 | 331 | 	u16 tid_reuse_count[QEDI_MAX_ISCSI_TASK]; | 
 | 332 | 	struct qed_pf_params pf_params; | 
 | 333 |  | 
 | 334 | 	struct workqueue_struct *tmf_thread; | 
 | 335 | 	struct workqueue_struct *offload_thread; | 
 | 336 |  | 
 | 337 | 	u16 ll2_mtu; | 
 | 338 |  | 
 | 339 | 	struct workqueue_struct *dpc_wq; | 
 | 340 |  | 
 | 341 | 	spinlock_t task_idx_lock;	/* To protect gbl context */ | 
 | 342 | 	s32 last_tidx_alloc; | 
 | 343 | 	s32 last_tidx_clear; | 
 | 344 |  | 
 | 345 | 	struct qedi_io_log io_trace_buf[QEDI_IO_TRACE_SIZE]; | 
 | 346 | 	spinlock_t io_trace_lock;	/* prtect trace Log buf */ | 
 | 347 | 	u16 io_trace_idx; | 
 | 348 | 	unsigned int intr_cpu; | 
 | 349 | 	u32 cached_sgls; | 
 | 350 | 	bool use_cached_sge; | 
 | 351 | 	u32 slow_sgls; | 
 | 352 | 	bool use_slow_sge; | 
 | 353 | 	u32 fast_sgls; | 
 | 354 | 	bool use_fast_sge; | 
 | 355 |  | 
 | 356 | 	atomic_t num_offloads; | 
 | 357 | #define SYSFS_FLAG_FW_SEL_BOOT 2 | 
 | 358 | #define IPV6_LEN	41 | 
 | 359 | #define IPV4_LEN	17 | 
 | 360 | 	struct iscsi_boot_kset *boot_kset; | 
 | 361 |  | 
 | 362 | 	/* Used for iscsi statistics */ | 
 | 363 | 	struct mutex stats_lock; | 
 | 364 | }; | 
 | 365 |  | 
 | 366 | struct qedi_work { | 
 | 367 | 	struct list_head list; | 
 | 368 | 	struct qedi_ctx *qedi; | 
 | 369 | 	union iscsi_cqe cqe; | 
 | 370 | 	u16     que_idx; | 
 | 371 | 	bool is_solicited; | 
 | 372 | }; | 
 | 373 |  | 
 | 374 | struct qedi_percpu_s { | 
 | 375 | 	struct task_struct *iothread; | 
 | 376 | 	struct list_head work_list; | 
 | 377 | 	spinlock_t p_work_lock;		/* Per cpu worker lock */ | 
 | 378 | }; | 
 | 379 |  | 
 | 380 | static inline void *qedi_get_task_mem(struct qed_iscsi_tid *info, u32 tid) | 
 | 381 | { | 
 | 382 | 	return (info->blocks[tid / info->num_tids_per_block] + | 
 | 383 | 		(tid % info->num_tids_per_block) * info->size); | 
 | 384 | } | 
 | 385 |  | 
 | 386 | #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32)) | 
 | 387 | #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff)) | 
 | 388 |  | 
 | 389 | #endif /* _QEDI_H_ */ |