18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is part of the Chelsio FCoE driver for Linux.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
78c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
138c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
148c2ecf20Sopenharmony_ci *     conditions are met:
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
178c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
188c2ecf20Sopenharmony_ci *        disclaimer.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
218c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
228c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
238c2ecf20Sopenharmony_ci *        provided with the distribution.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
328c2ecf20Sopenharmony_ci * SOFTWARE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef __CSIO_WR_H__
368c2ecf20Sopenharmony_ci#define __CSIO_WR_H__
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/cache.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#include "csio_defs.h"
418c2ecf20Sopenharmony_ci#include "t4fw_api.h"
428c2ecf20Sopenharmony_ci#include "t4fw_api_stor.h"
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/*
458c2ecf20Sopenharmony_ci * SGE register field values.
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_32B		0
488c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_64B		1
498c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_128B		2
508c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_256B		3
518c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_512B		4
528c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_1024B		5
538c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_2048B		6
548c2ecf20Sopenharmony_ci#define X_INGPCIEBOUNDARY_4096B		7
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* GTS register */
578c2ecf20Sopenharmony_ci#define X_TIMERREG_COUNTER0		0
588c2ecf20Sopenharmony_ci#define X_TIMERREG_COUNTER1		1
598c2ecf20Sopenharmony_ci#define X_TIMERREG_COUNTER2		2
608c2ecf20Sopenharmony_ci#define X_TIMERREG_COUNTER3		3
618c2ecf20Sopenharmony_ci#define X_TIMERREG_COUNTER4		4
628c2ecf20Sopenharmony_ci#define X_TIMERREG_COUNTER5		5
638c2ecf20Sopenharmony_ci#define X_TIMERREG_RESTART_COUNTER	6
648c2ecf20Sopenharmony_ci#define X_TIMERREG_UPDATE_CIDX		7
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Egress Context field values
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_ci#define X_FETCHBURSTMIN_16B		0
708c2ecf20Sopenharmony_ci#define X_FETCHBURSTMIN_32B		1
718c2ecf20Sopenharmony_ci#define X_FETCHBURSTMIN_64B		2
728c2ecf20Sopenharmony_ci#define X_FETCHBURSTMIN_128B		3
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define X_FETCHBURSTMAX_64B		0
758c2ecf20Sopenharmony_ci#define X_FETCHBURSTMAX_128B		1
768c2ecf20Sopenharmony_ci#define X_FETCHBURSTMAX_256B		2
778c2ecf20Sopenharmony_ci#define X_FETCHBURSTMAX_512B		3
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define X_HOSTFCMODE_NONE		0
808c2ecf20Sopenharmony_ci#define X_HOSTFCMODE_INGRESS_QUEUE	1
818c2ecf20Sopenharmony_ci#define X_HOSTFCMODE_STATUS_PAGE	2
828c2ecf20Sopenharmony_ci#define X_HOSTFCMODE_BOTH		3
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/*
858c2ecf20Sopenharmony_ci * Ingress Context field values
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_ci#define X_UPDATESCHEDULING_TIMER	0
888c2ecf20Sopenharmony_ci#define X_UPDATESCHEDULING_COUNTER_OPTTIMER	1
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define X_UPDATEDELIVERY_NONE		0
918c2ecf20Sopenharmony_ci#define X_UPDATEDELIVERY_INTERRUPT	1
928c2ecf20Sopenharmony_ci#define X_UPDATEDELIVERY_STATUS_PAGE	2
938c2ecf20Sopenharmony_ci#define X_UPDATEDELIVERY_BOTH		3
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define X_INTERRUPTDESTINATION_PCIE	0
968c2ecf20Sopenharmony_ci#define X_INTERRUPTDESTINATION_IQ	1
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define X_RSPD_TYPE_FLBUF		0
998c2ecf20Sopenharmony_ci#define X_RSPD_TYPE_CPL			1
1008c2ecf20Sopenharmony_ci#define X_RSPD_TYPE_INTR		2
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* WR status is at the same position as retval in a CMD header */
1038c2ecf20Sopenharmony_ci#define csio_wr_status(_wr)		\
1048c2ecf20Sopenharmony_ci		(FW_CMD_RETVAL_G(ntohl(((struct fw_cmd_hdr *)(_wr))->lo)))
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistruct csio_hw;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciextern int csio_intr_coalesce_cnt;
1098c2ecf20Sopenharmony_ciextern int csio_intr_coalesce_time;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/* Ingress queue params */
1128c2ecf20Sopenharmony_cistruct csio_iq_params {
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	uint8_t		iq_start:1;
1158c2ecf20Sopenharmony_ci	uint8_t		iq_stop:1;
1168c2ecf20Sopenharmony_ci	uint8_t		pfn:3;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	uint8_t		vfn;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	uint16_t	physiqid;
1218c2ecf20Sopenharmony_ci	uint16_t	iqid;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	uint16_t	fl0id;
1248c2ecf20Sopenharmony_ci	uint16_t	fl1id;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	uint8_t		viid;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	uint8_t		type;
1298c2ecf20Sopenharmony_ci	uint8_t		iqasynch;
1308c2ecf20Sopenharmony_ci	uint8_t		reserved4;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	uint8_t		iqandst;
1338c2ecf20Sopenharmony_ci	uint8_t		iqanus;
1348c2ecf20Sopenharmony_ci	uint8_t		iqanud;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	uint16_t	iqandstindex;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	uint8_t		iqdroprss;
1398c2ecf20Sopenharmony_ci	uint8_t		iqpciech;
1408c2ecf20Sopenharmony_ci	uint8_t		iqdcaen;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	uint8_t		iqdcacpu;
1438c2ecf20Sopenharmony_ci	uint8_t		iqintcntthresh;
1448c2ecf20Sopenharmony_ci	uint8_t		iqo;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	uint8_t		iqcprio;
1478c2ecf20Sopenharmony_ci	uint8_t		iqesize;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	uint16_t	iqsize;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	uint64_t	iqaddr;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	uint8_t		iqflintiqhsen;
1548c2ecf20Sopenharmony_ci	uint8_t		reserved5;
1558c2ecf20Sopenharmony_ci	uint8_t		iqflintcongen;
1568c2ecf20Sopenharmony_ci	uint8_t		iqflintcngchmap;
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	uint32_t	reserved6;
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	uint8_t		fl0hostfcmode;
1618c2ecf20Sopenharmony_ci	uint8_t		fl0cprio;
1628c2ecf20Sopenharmony_ci	uint8_t		fl0paden;
1638c2ecf20Sopenharmony_ci	uint8_t		fl0packen;
1648c2ecf20Sopenharmony_ci	uint8_t		fl0congen;
1658c2ecf20Sopenharmony_ci	uint8_t		fl0dcaen;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	uint8_t		fl0dcacpu;
1688c2ecf20Sopenharmony_ci	uint8_t		fl0fbmin;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	uint8_t		fl0fbmax;
1718c2ecf20Sopenharmony_ci	uint8_t		fl0cidxfthresho;
1728c2ecf20Sopenharmony_ci	uint8_t		fl0cidxfthresh;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	uint16_t	fl0size;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	uint64_t	fl0addr;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	uint64_t	reserved7;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	uint8_t		fl1hostfcmode;
1818c2ecf20Sopenharmony_ci	uint8_t		fl1cprio;
1828c2ecf20Sopenharmony_ci	uint8_t		fl1paden;
1838c2ecf20Sopenharmony_ci	uint8_t		fl1packen;
1848c2ecf20Sopenharmony_ci	uint8_t		fl1congen;
1858c2ecf20Sopenharmony_ci	uint8_t		fl1dcaen;
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	uint8_t		fl1dcacpu;
1888c2ecf20Sopenharmony_ci	uint8_t		fl1fbmin;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	uint8_t		fl1fbmax;
1918c2ecf20Sopenharmony_ci	uint8_t		fl1cidxfthresho;
1928c2ecf20Sopenharmony_ci	uint8_t		fl1cidxfthresh;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	uint16_t	fl1size;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	uint64_t	fl1addr;
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* Egress queue params */
2008c2ecf20Sopenharmony_cistruct csio_eq_params {
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	uint8_t		pfn;
2038c2ecf20Sopenharmony_ci	uint8_t		vfn;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	uint8_t		eqstart:1;
2068c2ecf20Sopenharmony_ci	uint8_t		eqstop:1;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	uint16_t        physeqid;
2098c2ecf20Sopenharmony_ci	uint32_t	eqid;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	uint8_t		hostfcmode:2;
2128c2ecf20Sopenharmony_ci	uint8_t		cprio:1;
2138c2ecf20Sopenharmony_ci	uint8_t		pciechn:3;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	uint16_t	iqid;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	uint8_t		dcaen:1;
2188c2ecf20Sopenharmony_ci	uint8_t		dcacpu:5;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	uint8_t		fbmin:3;
2218c2ecf20Sopenharmony_ci	uint8_t		fbmax:3;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	uint8_t		cidxfthresho:1;
2248c2ecf20Sopenharmony_ci	uint8_t		cidxfthresh:3;
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	uint16_t	eqsize;
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	uint64_t	eqaddr;
2298c2ecf20Sopenharmony_ci};
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistruct csio_dma_buf {
2328c2ecf20Sopenharmony_ci	struct list_head	list;
2338c2ecf20Sopenharmony_ci	void			*vaddr;		/* Virtual address */
2348c2ecf20Sopenharmony_ci	dma_addr_t		paddr;		/* Physical address */
2358c2ecf20Sopenharmony_ci	uint32_t		len;		/* Buffer size */
2368c2ecf20Sopenharmony_ci};
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* Generic I/O request structure */
2398c2ecf20Sopenharmony_cistruct csio_ioreq {
2408c2ecf20Sopenharmony_ci	struct csio_sm		sm;		/* SM, List
2418c2ecf20Sopenharmony_ci						 * should be the first member
2428c2ecf20Sopenharmony_ci						 */
2438c2ecf20Sopenharmony_ci	int			iq_idx;		/* Ingress queue index */
2448c2ecf20Sopenharmony_ci	int			eq_idx;		/* Egress queue index */
2458c2ecf20Sopenharmony_ci	uint32_t		nsge;		/* Number of SG elements */
2468c2ecf20Sopenharmony_ci	uint32_t		tmo;		/* Driver timeout */
2478c2ecf20Sopenharmony_ci	uint32_t		datadir;	/* Data direction */
2488c2ecf20Sopenharmony_ci	struct csio_dma_buf	dma_buf;	/* Req/resp DMA buffers */
2498c2ecf20Sopenharmony_ci	uint16_t		wr_status;	/* WR completion status */
2508c2ecf20Sopenharmony_ci	int16_t			drv_status;	/* Driver internal status */
2518c2ecf20Sopenharmony_ci	struct csio_lnode	*lnode;		/* Owner lnode */
2528c2ecf20Sopenharmony_ci	struct csio_rnode	*rnode;		/* Src/destination rnode */
2538c2ecf20Sopenharmony_ci	void (*io_cbfn) (struct csio_hw *, struct csio_ioreq *);
2548c2ecf20Sopenharmony_ci						/* completion callback */
2558c2ecf20Sopenharmony_ci	void			*scratch1;	/* Scratch area 1.
2568c2ecf20Sopenharmony_ci						 */
2578c2ecf20Sopenharmony_ci	void			*scratch2;	/* Scratch area 2. */
2588c2ecf20Sopenharmony_ci	struct list_head	gen_list;	/* Any list associated with
2598c2ecf20Sopenharmony_ci						 * this ioreq.
2608c2ecf20Sopenharmony_ci						 */
2618c2ecf20Sopenharmony_ci	uint64_t		fw_handle;	/* Unique handle passed
2628c2ecf20Sopenharmony_ci						 * to FW
2638c2ecf20Sopenharmony_ci						 */
2648c2ecf20Sopenharmony_ci	uint8_t			dcopy;		/* Data copy required */
2658c2ecf20Sopenharmony_ci	uint8_t			reserved1;
2668c2ecf20Sopenharmony_ci	uint16_t		reserved2;
2678c2ecf20Sopenharmony_ci	struct completion	cmplobj;	/* ioreq completion object */
2688c2ecf20Sopenharmony_ci} ____cacheline_aligned_in_smp;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci/*
2718c2ecf20Sopenharmony_ci * Egress status page for egress cidx updates
2728c2ecf20Sopenharmony_ci */
2738c2ecf20Sopenharmony_cistruct csio_qstatus_page {
2748c2ecf20Sopenharmony_ci	__be32 qid;
2758c2ecf20Sopenharmony_ci	__be16 cidx;
2768c2ecf20Sopenharmony_ci	__be16 pidx;
2778c2ecf20Sopenharmony_ci};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cienum {
2818c2ecf20Sopenharmony_ci	CSIO_MAX_FLBUF_PER_IQWR = 4,
2828c2ecf20Sopenharmony_ci	CSIO_QCREDIT_SZ  = 64,			/* pidx/cidx increments
2838c2ecf20Sopenharmony_ci						 * in bytes
2848c2ecf20Sopenharmony_ci						 */
2858c2ecf20Sopenharmony_ci	CSIO_MAX_QID = 0xFFFF,
2868c2ecf20Sopenharmony_ci	CSIO_MAX_IQ = 128,
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	CSIO_SGE_NTIMERS = 6,
2898c2ecf20Sopenharmony_ci	CSIO_SGE_NCOUNTERS = 4,
2908c2ecf20Sopenharmony_ci	CSIO_SGE_FL_SIZE_REGS = 16,
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/* Defines for type */
2948c2ecf20Sopenharmony_cienum {
2958c2ecf20Sopenharmony_ci	CSIO_EGRESS	= 1,
2968c2ecf20Sopenharmony_ci	CSIO_INGRESS	= 2,
2978c2ecf20Sopenharmony_ci	CSIO_FREELIST	= 3,
2988c2ecf20Sopenharmony_ci};
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci/*
3018c2ecf20Sopenharmony_ci * Structure for footer (last 2 flits) of Ingress Queue Entry.
3028c2ecf20Sopenharmony_ci */
3038c2ecf20Sopenharmony_cistruct csio_iqwr_footer {
3048c2ecf20Sopenharmony_ci	__be32			hdrbuflen_pidx;
3058c2ecf20Sopenharmony_ci	__be32			pldbuflen_qid;
3068c2ecf20Sopenharmony_ci	union {
3078c2ecf20Sopenharmony_ci		u8		type_gen;
3088c2ecf20Sopenharmony_ci		__be64		last_flit;
3098c2ecf20Sopenharmony_ci	} u;
3108c2ecf20Sopenharmony_ci};
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci#define IQWRF_NEWBUF		(1 << 31)
3138c2ecf20Sopenharmony_ci#define IQWRF_LEN_GET(x)	(((x) >> 0) & 0x7fffffffU)
3148c2ecf20Sopenharmony_ci#define IQWRF_GEN_SHIFT		7
3158c2ecf20Sopenharmony_ci#define IQWRF_TYPE_GET(x)	(((x) >> 4) & 0x3U)
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/*
3198c2ecf20Sopenharmony_ci * WR pair:
3208c2ecf20Sopenharmony_ci * ========
3218c2ecf20Sopenharmony_ci * A WR can start towards the end of a queue, and then continue at the
3228c2ecf20Sopenharmony_ci * beginning, since the queue is considered to be circular. This will
3238c2ecf20Sopenharmony_ci * require a pair of address/len to be passed back to the caller -
3248c2ecf20Sopenharmony_ci * hence the Work request pair structure.
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_cistruct csio_wr_pair {
3278c2ecf20Sopenharmony_ci	void			*addr1;
3288c2ecf20Sopenharmony_ci	uint32_t		size1;
3298c2ecf20Sopenharmony_ci	void			*addr2;
3308c2ecf20Sopenharmony_ci	uint32_t		size2;
3318c2ecf20Sopenharmony_ci};
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/*
3348c2ecf20Sopenharmony_ci * The following structure is used by ingress processing to return the
3358c2ecf20Sopenharmony_ci * free list buffers to consumers.
3368c2ecf20Sopenharmony_ci */
3378c2ecf20Sopenharmony_cistruct csio_fl_dma_buf {
3388c2ecf20Sopenharmony_ci	struct csio_dma_buf	flbufs[CSIO_MAX_FLBUF_PER_IQWR];
3398c2ecf20Sopenharmony_ci						/* Freelist DMA buffers */
3408c2ecf20Sopenharmony_ci	int			offset;		/* Offset within the
3418c2ecf20Sopenharmony_ci						 * first FL buf.
3428c2ecf20Sopenharmony_ci						 */
3438c2ecf20Sopenharmony_ci	uint32_t		totlen;		/* Total length */
3448c2ecf20Sopenharmony_ci	uint8_t			defer_free;	/* Free of buffer can
3458c2ecf20Sopenharmony_ci						 * deferred
3468c2ecf20Sopenharmony_ci						 */
3478c2ecf20Sopenharmony_ci};
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci/* Data-types */
3508c2ecf20Sopenharmony_citypedef void (*iq_handler_t)(struct csio_hw *, void *, uint32_t,
3518c2ecf20Sopenharmony_ci			     struct csio_fl_dma_buf *, void *);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_cistruct csio_iq {
3548c2ecf20Sopenharmony_ci	uint16_t		iqid;		/* Queue ID */
3558c2ecf20Sopenharmony_ci	uint16_t		physiqid;	/* Physical Queue ID */
3568c2ecf20Sopenharmony_ci	uint16_t		genbit;		/* Generation bit,
3578c2ecf20Sopenharmony_ci						 * initially set to 1
3588c2ecf20Sopenharmony_ci						 */
3598c2ecf20Sopenharmony_ci	int			flq_idx;	/* Freelist queue index */
3608c2ecf20Sopenharmony_ci	iq_handler_t		iq_intx_handler; /* IQ INTx handler routine */
3618c2ecf20Sopenharmony_ci};
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_cistruct csio_eq {
3648c2ecf20Sopenharmony_ci	uint16_t		eqid;		/* Qid */
3658c2ecf20Sopenharmony_ci	uint16_t		physeqid;	/* Physical Queue ID */
3668c2ecf20Sopenharmony_ci	uint8_t			wrap[512];	/* Temp area for q-wrap around*/
3678c2ecf20Sopenharmony_ci};
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistruct csio_fl {
3708c2ecf20Sopenharmony_ci	uint16_t		flid;		/* Qid */
3718c2ecf20Sopenharmony_ci	uint16_t		packen;		/* Packing enabled? */
3728c2ecf20Sopenharmony_ci	int			offset;		/* Offset within FL buf */
3738c2ecf20Sopenharmony_ci	int			sreg;		/* Size register */
3748c2ecf20Sopenharmony_ci	struct csio_dma_buf	*bufs;		/* Free list buffer ptr array
3758c2ecf20Sopenharmony_ci						 * indexed using flq->cidx/pidx
3768c2ecf20Sopenharmony_ci						 */
3778c2ecf20Sopenharmony_ci};
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistruct csio_qstats {
3808c2ecf20Sopenharmony_ci	uint32_t	n_tot_reqs;		/* Total no. of Requests */
3818c2ecf20Sopenharmony_ci	uint32_t	n_tot_rsps;		/* Total no. of responses */
3828c2ecf20Sopenharmony_ci	uint32_t	n_qwrap;		/* Queue wraps */
3838c2ecf20Sopenharmony_ci	uint32_t	n_eq_wr_split;		/* Number of split EQ WRs */
3848c2ecf20Sopenharmony_ci	uint32_t	n_qentry;		/* Queue entry */
3858c2ecf20Sopenharmony_ci	uint32_t	n_qempty;		/* Queue empty */
3868c2ecf20Sopenharmony_ci	uint32_t	n_qfull;		/* Queue fulls */
3878c2ecf20Sopenharmony_ci	uint32_t	n_rsp_unknown;		/* Unknown response type */
3888c2ecf20Sopenharmony_ci	uint32_t	n_stray_comp;		/* Stray completion intr */
3898c2ecf20Sopenharmony_ci	uint32_t	n_flq_refill;		/* Number of FL refills */
3908c2ecf20Sopenharmony_ci};
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci/* Queue metadata */
3938c2ecf20Sopenharmony_cistruct csio_q {
3948c2ecf20Sopenharmony_ci	uint16_t		type;		/* Type: Ingress/Egress/FL */
3958c2ecf20Sopenharmony_ci	uint16_t		pidx;		/* producer index */
3968c2ecf20Sopenharmony_ci	uint16_t		cidx;		/* consumer index */
3978c2ecf20Sopenharmony_ci	uint16_t		inc_idx;	/* Incremental index */
3988c2ecf20Sopenharmony_ci	uint32_t		wr_sz;		/* Size of all WRs in this q
3998c2ecf20Sopenharmony_ci						 * if fixed
4008c2ecf20Sopenharmony_ci						 */
4018c2ecf20Sopenharmony_ci	void			*vstart;	/* Base virtual address
4028c2ecf20Sopenharmony_ci						 * of queue
4038c2ecf20Sopenharmony_ci						 */
4048c2ecf20Sopenharmony_ci	void			*vwrap;		/* Virtual end address to
4058c2ecf20Sopenharmony_ci						 * wrap around at
4068c2ecf20Sopenharmony_ci						 */
4078c2ecf20Sopenharmony_ci	uint32_t		credits;	/* Size of queue in credits */
4088c2ecf20Sopenharmony_ci	void			*owner;		/* Owner */
4098c2ecf20Sopenharmony_ci	union {					/* Queue contexts */
4108c2ecf20Sopenharmony_ci		struct csio_iq	iq;
4118c2ecf20Sopenharmony_ci		struct csio_eq	eq;
4128c2ecf20Sopenharmony_ci		struct csio_fl	fl;
4138c2ecf20Sopenharmony_ci	} un;
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	dma_addr_t		pstart;		/* Base physical address of
4168c2ecf20Sopenharmony_ci						 * queue
4178c2ecf20Sopenharmony_ci						 */
4188c2ecf20Sopenharmony_ci	uint32_t		portid;		/* PCIE Channel */
4198c2ecf20Sopenharmony_ci	uint32_t		size;		/* Size of queue in bytes */
4208c2ecf20Sopenharmony_ci	struct csio_qstats	stats;		/* Statistics */
4218c2ecf20Sopenharmony_ci} ____cacheline_aligned_in_smp;
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_cistruct csio_sge {
4248c2ecf20Sopenharmony_ci	uint32_t	csio_fl_align;		/* Calculated and cached
4258c2ecf20Sopenharmony_ci						 * for fast path
4268c2ecf20Sopenharmony_ci						 */
4278c2ecf20Sopenharmony_ci	uint32_t	sge_control;		/* padding, boundaries,
4288c2ecf20Sopenharmony_ci						 * lengths, etc.
4298c2ecf20Sopenharmony_ci						 */
4308c2ecf20Sopenharmony_ci	uint32_t	sge_host_page_size;	/* Host page size */
4318c2ecf20Sopenharmony_ci	uint32_t	sge_fl_buf_size[CSIO_SGE_FL_SIZE_REGS];
4328c2ecf20Sopenharmony_ci						/* free list buffer sizes */
4338c2ecf20Sopenharmony_ci	uint16_t	timer_val[CSIO_SGE_NTIMERS];
4348c2ecf20Sopenharmony_ci	uint8_t		counter_val[CSIO_SGE_NCOUNTERS];
4358c2ecf20Sopenharmony_ci};
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci/* Work request module */
4388c2ecf20Sopenharmony_cistruct csio_wrm {
4398c2ecf20Sopenharmony_ci	int			num_q;		/* Number of queues */
4408c2ecf20Sopenharmony_ci	struct csio_q		**q_arr;	/* Array of queue pointers
4418c2ecf20Sopenharmony_ci						 * allocated dynamically
4428c2ecf20Sopenharmony_ci						 * based on configured values
4438c2ecf20Sopenharmony_ci						 */
4448c2ecf20Sopenharmony_ci	uint32_t		fw_iq_start;	/* Start ID of IQ for this fn*/
4458c2ecf20Sopenharmony_ci	uint32_t		fw_eq_start;	/* Start ID of EQ for this fn*/
4468c2ecf20Sopenharmony_ci	struct csio_q		*intr_map[CSIO_MAX_IQ];
4478c2ecf20Sopenharmony_ci						/* IQ-id to IQ map table. */
4488c2ecf20Sopenharmony_ci	int			free_qidx;	/* queue idx of free queue */
4498c2ecf20Sopenharmony_ci	struct csio_sge		sge;		/* SGE params */
4508c2ecf20Sopenharmony_ci};
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci#define csio_get_q(__hw, __idx)		((__hw)->wrm.q_arr[__idx])
4538c2ecf20Sopenharmony_ci#define	csio_q_type(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->type)
4548c2ecf20Sopenharmony_ci#define	csio_q_pidx(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->pidx)
4558c2ecf20Sopenharmony_ci#define	csio_q_cidx(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->cidx)
4568c2ecf20Sopenharmony_ci#define	csio_q_inc_idx(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->inc_idx)
4578c2ecf20Sopenharmony_ci#define	csio_q_vstart(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->vstart)
4588c2ecf20Sopenharmony_ci#define	csio_q_pstart(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->pstart)
4598c2ecf20Sopenharmony_ci#define	csio_q_size(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->size)
4608c2ecf20Sopenharmony_ci#define	csio_q_credits(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->credits)
4618c2ecf20Sopenharmony_ci#define	csio_q_portid(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->portid)
4628c2ecf20Sopenharmony_ci#define	csio_q_wr_sz(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->wr_sz)
4638c2ecf20Sopenharmony_ci#define	csio_q_iqid(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->un.iq.iqid)
4648c2ecf20Sopenharmony_ci#define csio_q_physiqid(__hw, __idx)					\
4658c2ecf20Sopenharmony_ci				((__hw)->wrm.q_arr[(__idx)]->un.iq.physiqid)
4668c2ecf20Sopenharmony_ci#define csio_q_iq_flq_idx(__hw, __idx)					\
4678c2ecf20Sopenharmony_ci				((__hw)->wrm.q_arr[(__idx)]->un.iq.flq_idx)
4688c2ecf20Sopenharmony_ci#define	csio_q_eqid(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->un.eq.eqid)
4698c2ecf20Sopenharmony_ci#define	csio_q_flid(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->un.fl.flid)
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci#define csio_q_physeqid(__hw, __idx)					\
4728c2ecf20Sopenharmony_ci				((__hw)->wrm.q_arr[(__idx)]->un.eq.physeqid)
4738c2ecf20Sopenharmony_ci#define csio_iq_has_fl(__iq)		((__iq)->un.iq.flq_idx != -1)
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci#define csio_q_iq_to_flid(__hw, __iq_idx)				\
4768c2ecf20Sopenharmony_ci	csio_q_flid((__hw), (__hw)->wrm.q_arr[(__iq_qidx)]->un.iq.flq_idx)
4778c2ecf20Sopenharmony_ci#define csio_q_set_intr_map(__hw, __iq_idx, __rel_iq_id)		\
4788c2ecf20Sopenharmony_ci		(__hw)->wrm.intr_map[__rel_iq_id] = csio_get_q(__hw, __iq_idx)
4798c2ecf20Sopenharmony_ci#define	csio_q_eq_wrap(__hw, __idx)	((__hw)->wrm.q_arr[(__idx)]->un.eq.wrap)
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_cistruct csio_mb;
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ciint csio_wr_alloc_q(struct csio_hw *, uint32_t, uint32_t,
4848c2ecf20Sopenharmony_ci		    uint16_t, void *, uint32_t, int, iq_handler_t);
4858c2ecf20Sopenharmony_ciint csio_wr_iq_create(struct csio_hw *, void *, int,
4868c2ecf20Sopenharmony_ci				uint32_t, uint8_t, bool,
4878c2ecf20Sopenharmony_ci				void (*)(struct csio_hw *, struct csio_mb *));
4888c2ecf20Sopenharmony_ciint csio_wr_eq_create(struct csio_hw *, void *, int, int, uint8_t,
4898c2ecf20Sopenharmony_ci				void (*)(struct csio_hw *, struct csio_mb *));
4908c2ecf20Sopenharmony_ciint csio_wr_destroy_queues(struct csio_hw *, bool cmd);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ciint csio_wr_get(struct csio_hw *, int, uint32_t,
4948c2ecf20Sopenharmony_ci			  struct csio_wr_pair *);
4958c2ecf20Sopenharmony_civoid csio_wr_copy_to_wrp(void *, struct csio_wr_pair *, uint32_t, uint32_t);
4968c2ecf20Sopenharmony_ciint csio_wr_issue(struct csio_hw *, int, bool);
4978c2ecf20Sopenharmony_ciint csio_wr_process_iq(struct csio_hw *, struct csio_q *,
4988c2ecf20Sopenharmony_ci				 void (*)(struct csio_hw *, void *,
4998c2ecf20Sopenharmony_ci					  uint32_t, struct csio_fl_dma_buf *,
5008c2ecf20Sopenharmony_ci					  void *),
5018c2ecf20Sopenharmony_ci				 void *);
5028c2ecf20Sopenharmony_ciint csio_wr_process_iq_idx(struct csio_hw *, int,
5038c2ecf20Sopenharmony_ci				 void (*)(struct csio_hw *, void *,
5048c2ecf20Sopenharmony_ci					  uint32_t, struct csio_fl_dma_buf *,
5058c2ecf20Sopenharmony_ci					  void *),
5068c2ecf20Sopenharmony_ci				 void *);
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_civoid csio_wr_sge_init(struct csio_hw *);
5098c2ecf20Sopenharmony_ciint csio_wrm_init(struct csio_wrm *, struct csio_hw *);
5108c2ecf20Sopenharmony_civoid csio_wrm_exit(struct csio_wrm *, struct csio_hw *);
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci#endif /* ifndef __CSIO_WR_H__ */
513