xref: /freebsd/sys/dev/qlnx/qlnxe/qlnx_def.h (revision 1c45a62a2f667b45ec10a92ad58ff5a34e68b569)
111e25f0dSDavid C Somayajulu /*
211e25f0dSDavid C Somayajulu  * Copyright (c) 2017-2018 Cavium, Inc.
311e25f0dSDavid C Somayajulu  * All rights reserved.
411e25f0dSDavid C Somayajulu  *
511e25f0dSDavid C Somayajulu  *  Redistribution and use in source and binary forms, with or without
611e25f0dSDavid C Somayajulu  *  modification, are permitted provided that the following conditions
711e25f0dSDavid C Somayajulu  *  are met:
811e25f0dSDavid C Somayajulu  *
911e25f0dSDavid C Somayajulu  *  1. Redistributions of source code must retain the above copyright
1011e25f0dSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer.
1111e25f0dSDavid C Somayajulu  *  2. Redistributions in binary form must reproduce the above copyright
1211e25f0dSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer in the
1311e25f0dSDavid C Somayajulu  *     documentation and/or other materials provided with the distribution.
1411e25f0dSDavid C Somayajulu  *
1511e25f0dSDavid C Somayajulu  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1611e25f0dSDavid C Somayajulu  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1711e25f0dSDavid C Somayajulu  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1811e25f0dSDavid C Somayajulu  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
1911e25f0dSDavid C Somayajulu  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2011e25f0dSDavid C Somayajulu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2111e25f0dSDavid C Somayajulu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2211e25f0dSDavid C Somayajulu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2311e25f0dSDavid C Somayajulu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2411e25f0dSDavid C Somayajulu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2511e25f0dSDavid C Somayajulu  *  POSSIBILITY OF SUCH DAMAGE.
2611e25f0dSDavid C Somayajulu  *
2711e25f0dSDavid C Somayajulu  */
2811e25f0dSDavid C Somayajulu 
2911e25f0dSDavid C Somayajulu /*
3011e25f0dSDavid C Somayajulu  * File: qlnx_def.h
3111e25f0dSDavid C Somayajulu  * Author : David C Somayajulu, Cavium Inc., San Jose, CA 95131.
3211e25f0dSDavid C Somayajulu  */
3311e25f0dSDavid C Somayajulu 
3411e25f0dSDavid C Somayajulu #ifndef _QLNX_DEF_H_
3511e25f0dSDavid C Somayajulu #define _QLNX_DEF_H_
3611e25f0dSDavid C Somayajulu 
3711e25f0dSDavid C Somayajulu #define VER_SIZE 16
3811e25f0dSDavid C Somayajulu 
3911e25f0dSDavid C Somayajulu struct qlnx_ivec {
4011e25f0dSDavid C Somayajulu         uint32_t                rss_idx;
4111e25f0dSDavid C Somayajulu         void                    *ha;
4211e25f0dSDavid C Somayajulu         struct resource         *irq;
4311e25f0dSDavid C Somayajulu         void                    *handle;
4411e25f0dSDavid C Somayajulu         int                     irq_rid;
4511e25f0dSDavid C Somayajulu };
4611e25f0dSDavid C Somayajulu 
4711e25f0dSDavid C Somayajulu typedef struct qlnx_ivec qlnx_ivec_t;
4811e25f0dSDavid C Somayajulu 
4911e25f0dSDavid C Somayajulu //#define QLNX_MAX_RSS		30
50217ec208SDavid C Somayajulu #define QLNX_MAX_VF_RSS		4
5145f13123SDavid C Somayajulu #define QLNX_MAX_RSS		36
5245f13123SDavid C Somayajulu #define QLNX_DEFAULT_RSS	16
5311e25f0dSDavid C Somayajulu #define QLNX_MAX_TC		1
5411e25f0dSDavid C Somayajulu 
5511e25f0dSDavid C Somayajulu enum QLNX_STATE {
5611e25f0dSDavid C Somayajulu         QLNX_STATE_CLOSED,
5711e25f0dSDavid C Somayajulu         QLNX_STATE_OPEN,
5811e25f0dSDavid C Somayajulu };
5911e25f0dSDavid C Somayajulu 
6011e25f0dSDavid C Somayajulu #define HILO_U64(hi, lo)                ((((u64)(hi)) << 32) + (lo))
6111e25f0dSDavid C Somayajulu 
6211e25f0dSDavid C Somayajulu #define MAX_NUM_TC      8
6311e25f0dSDavid C Somayajulu #define MAX_NUM_PRI     8
6411e25f0dSDavid C Somayajulu 
6511e25f0dSDavid C Somayajulu #ifndef BITS_PER_BYTE
6611e25f0dSDavid C Somayajulu #define BITS_PER_BYTE	8
6711e25f0dSDavid C Somayajulu #endif /* #ifndef BITS_PER_BYTE */
6811e25f0dSDavid C Somayajulu 
6911e25f0dSDavid C Somayajulu /*
7011e25f0dSDavid C Somayajulu  * RX ring buffer contains pointer to kmalloc() data only,
7111e25f0dSDavid C Somayajulu  */
7211e25f0dSDavid C Somayajulu struct sw_rx_data {
7311e25f0dSDavid C Somayajulu         void		*data;
7411e25f0dSDavid C Somayajulu 	bus_dmamap_t	map;
7511e25f0dSDavid C Somayajulu 	dma_addr_t	dma_addr;
7611e25f0dSDavid C Somayajulu };
7711e25f0dSDavid C Somayajulu 
7811e25f0dSDavid C Somayajulu enum qlnx_agg_state {
7911e25f0dSDavid C Somayajulu         QLNX_AGG_STATE_NONE  = 0,
8011e25f0dSDavid C Somayajulu         QLNX_AGG_STATE_START = 1,
8111e25f0dSDavid C Somayajulu         QLNX_AGG_STATE_ERROR = 2
8211e25f0dSDavid C Somayajulu };
8311e25f0dSDavid C Somayajulu 
8411e25f0dSDavid C Somayajulu struct qlnx_agg_info {
8511e25f0dSDavid C Somayajulu         /* rx_buf is a data buffer that can be placed /consumed from rx bd
8611e25f0dSDavid C Somayajulu          * chain. It has two purposes: We will preallocate the data buffer
8711e25f0dSDavid C Somayajulu          * for each aggregation when we open the interface and will place this
8811e25f0dSDavid C Somayajulu          * buffer on the rx-bd-ring when we receive TPA_START. We don't want
8911e25f0dSDavid C Somayajulu          * to be in a state where allocation fails, as we can't reuse the
9011e25f0dSDavid C Somayajulu          * consumer buffer in the rx-chain since FW may still be writing to it
9111e25f0dSDavid C Somayajulu          * (since header needs to be modified for TPA.
9211e25f0dSDavid C Somayajulu          * The second purpose is to keep a pointer to the bd buffer during
9311e25f0dSDavid C Somayajulu          * aggregation.
9411e25f0dSDavid C Somayajulu          */
9511e25f0dSDavid C Somayajulu         struct sw_rx_data       rx_buf;
9611e25f0dSDavid C Somayajulu         enum qlnx_agg_state     agg_state;
9711e25f0dSDavid C Somayajulu 	uint16_t		placement_offset;
9811e25f0dSDavid C Somayajulu         struct mbuf             *mpf; /* first mbuf in chain */
9911e25f0dSDavid C Somayajulu         struct mbuf             *mpl; /* last mbuf in chain */
10011e25f0dSDavid C Somayajulu };
10111e25f0dSDavid C Somayajulu 
10211e25f0dSDavid C Somayajulu #define RX_RING_SIZE_POW        13
10311e25f0dSDavid C Somayajulu #define RX_RING_SIZE            (1 << RX_RING_SIZE_POW)
10411e25f0dSDavid C Somayajulu 
10511e25f0dSDavid C Somayajulu #define TX_RING_SIZE_POW        14
10611e25f0dSDavid C Somayajulu #define TX_RING_SIZE            (1 << TX_RING_SIZE_POW)
10711e25f0dSDavid C Somayajulu 
10811e25f0dSDavid C Somayajulu struct qlnx_rx_queue {
10911e25f0dSDavid C Somayajulu         volatile __le16         *hw_cons_ptr;
11011e25f0dSDavid C Somayajulu         struct sw_rx_data       sw_rx_ring[RX_RING_SIZE];
11111e25f0dSDavid C Somayajulu         uint16_t		sw_rx_cons;
11211e25f0dSDavid C Somayajulu         uint16_t		sw_rx_prod;
11311e25f0dSDavid C Somayajulu         struct ecore_chain      rx_bd_ring;
11411e25f0dSDavid C Somayajulu         struct ecore_chain      rx_comp_ring;
11511e25f0dSDavid C Somayajulu         void __iomem            *hw_rxq_prod_addr;
11611e25f0dSDavid C Somayajulu 	void 			*handle;
11711e25f0dSDavid C Somayajulu 
11811e25f0dSDavid C Somayajulu         /* LRO */
11911e25f0dSDavid C Somayajulu         struct qlnx_agg_info    tpa_info[ETH_TPA_MAX_AGGS_NUM];
12011e25f0dSDavid C Somayajulu 
12111e25f0dSDavid C Somayajulu         uint32_t		rx_buf_size;
12211e25f0dSDavid C Somayajulu 
12311e25f0dSDavid C Somayajulu         uint16_t		num_rx_buffers;
12411e25f0dSDavid C Somayajulu         uint16_t		rxq_id;
12511e25f0dSDavid C Somayajulu 
12611e25f0dSDavid C Somayajulu #ifdef QLNX_SOFT_LRO
12711e25f0dSDavid C Somayajulu 	struct lro_ctrl		lro;
12811e25f0dSDavid C Somayajulu #endif
12911e25f0dSDavid C Somayajulu };
13011e25f0dSDavid C Somayajulu 
13111e25f0dSDavid C Somayajulu union db_prod {
13211e25f0dSDavid C Somayajulu         struct eth_db_data	data;
13311e25f0dSDavid C Somayajulu         uint32_t		raw;
13411e25f0dSDavid C Somayajulu };
13511e25f0dSDavid C Somayajulu 
13611e25f0dSDavid C Somayajulu struct sw_tx_bd {
13711e25f0dSDavid C Somayajulu         struct mbuf		*mp;
13811e25f0dSDavid C Somayajulu 	bus_dmamap_t		map;
13911e25f0dSDavid C Somayajulu         uint8_t			flags;
14011e25f0dSDavid C Somayajulu 	int			nsegs;
14111e25f0dSDavid C Somayajulu 
14211e25f0dSDavid C Somayajulu /* Set on the first BD descriptor when there is a split BD */
14311e25f0dSDavid C Somayajulu #define QLNX_TSO_SPLIT_BD               (1<<0)
14411e25f0dSDavid C Somayajulu };
14511e25f0dSDavid C Somayajulu 
14611e25f0dSDavid C Somayajulu #define QLNX_MAX_SEGMENTS		255
14711e25f0dSDavid C Somayajulu struct qlnx_tx_queue {
14811e25f0dSDavid C Somayajulu         int                     index; /* Queue index */
14911e25f0dSDavid C Somayajulu         volatile __le16         *hw_cons_ptr;
15011e25f0dSDavid C Somayajulu         struct sw_tx_bd         sw_tx_ring[TX_RING_SIZE];
15111e25f0dSDavid C Somayajulu         uint16_t		sw_tx_cons;
15211e25f0dSDavid C Somayajulu         uint16_t		sw_tx_prod;
15311e25f0dSDavid C Somayajulu         struct ecore_chain	tx_pbl;
15411e25f0dSDavid C Somayajulu         void __iomem            *doorbell_addr;
15511e25f0dSDavid C Somayajulu 	void 			*handle;
15611e25f0dSDavid C Somayajulu         union db_prod           tx_db;
15711e25f0dSDavid C Somayajulu 
15811e25f0dSDavid C Somayajulu 	bus_dma_segment_t	segs[QLNX_MAX_SEGMENTS];
15911e25f0dSDavid C Somayajulu 
16011e25f0dSDavid C Somayajulu         uint16_t		num_tx_buffers;
16111e25f0dSDavid C Somayajulu };
16211e25f0dSDavid C Somayajulu 
16311e25f0dSDavid C Somayajulu #define BD_UNMAP_ADDR(bd)	HILO_U64(le32toh((bd)->addr.hi), \
16411e25f0dSDavid C Somayajulu 					le32toh((bd)->addr.lo))
16511e25f0dSDavid C Somayajulu #define BD_UNMAP_LEN(bd)	(le16toh((bd)->nbytes))
16611e25f0dSDavid C Somayajulu 
16711e25f0dSDavid C Somayajulu #define BD_SET_UNMAP_ADDR_LEN(bd, maddr, len) \
16811e25f0dSDavid C Somayajulu         do { \
16911e25f0dSDavid C Somayajulu                 (bd)->addr.hi = htole32(U64_HI(maddr)); \
17011e25f0dSDavid C Somayajulu                 (bd)->addr.lo = htole32(U64_LO(maddr)); \
17111e25f0dSDavid C Somayajulu                 (bd)->nbytes = htole16(len); \
17211e25f0dSDavid C Somayajulu         } while (0);
17311e25f0dSDavid C Somayajulu 
17411e25f0dSDavid C Somayajulu #define QLNX_FP_MAX_SEGS	24
17511e25f0dSDavid C Somayajulu 
17611e25f0dSDavid C Somayajulu struct qlnx_fastpath {
17711e25f0dSDavid C Somayajulu         void			*edev;
17811e25f0dSDavid C Somayajulu         uint8_t			rss_id;
17911e25f0dSDavid C Somayajulu         struct ecore_sb_info    *sb_info;
18011e25f0dSDavid C Somayajulu         struct qlnx_rx_queue    *rxq;
18111e25f0dSDavid C Somayajulu         struct qlnx_tx_queue    *txq[MAX_NUM_TC];
18211e25f0dSDavid C Somayajulu 	char			name[64];
18311e25f0dSDavid C Somayajulu 
18411e25f0dSDavid C Somayajulu 	struct mtx		tx_mtx;
18511e25f0dSDavid C Somayajulu 	char			tx_mtx_name[32];
18611e25f0dSDavid C Somayajulu 	struct buf_ring		*tx_br;
18777388ed2SDavid C Somayajulu 	uint32_t		tx_ring_full;
18811e25f0dSDavid C Somayajulu 
18911e25f0dSDavid C Somayajulu 	struct task		fp_task;
19011e25f0dSDavid C Somayajulu 	struct taskqueue	*fp_taskqueue;
19111e25f0dSDavid C Somayajulu 
19211e25f0dSDavid C Somayajulu 	/* transmit statistics */
19311e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_processed;
19411e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_freed;
19511e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_transmitted;
19611e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_completed;
19745f13123SDavid C Somayajulu 	uint64_t		tx_tso_pkts;
19845f13123SDavid C Somayajulu 	uint64_t		tx_non_tso_pkts;
19945f13123SDavid C Somayajulu 
20045f13123SDavid C Somayajulu #ifdef QLNX_TRACE_PERF_DATA
20145f13123SDavid C Somayajulu 	uint64_t		tx_pkts_trans_ctx;
20245f13123SDavid C Somayajulu 	uint64_t		tx_pkts_compl_ctx;
20345f13123SDavid C Somayajulu 	uint64_t		tx_pkts_trans_fp;
20445f13123SDavid C Somayajulu 	uint64_t		tx_pkts_compl_fp;
20545f13123SDavid C Somayajulu 	uint64_t		tx_pkts_compl_intr;
20645f13123SDavid C Somayajulu #endif
20745f13123SDavid C Somayajulu 
20811e25f0dSDavid C Somayajulu 	uint64_t		tx_lso_wnd_min_len;
20911e25f0dSDavid C Somayajulu 	uint64_t		tx_defrag;
21011e25f0dSDavid C Somayajulu 	uint64_t		tx_nsegs_gt_elem_left;
21111e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_max_nsegs;
21211e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_min_nsegs;
21311e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_max_pkt_len;
21411e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_min_pkt_len;
21511e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts[QLNX_FP_MAX_SEGS];
21645f13123SDavid C Somayajulu 
21745f13123SDavid C Somayajulu #ifdef QLNX_TRACE_PERF_DATA
21845f13123SDavid C Somayajulu 	uint64_t		tx_pkts_hist[QLNX_FP_MAX_SEGS];
21945f13123SDavid C Somayajulu 	uint64_t		tx_comInt[QLNX_FP_MAX_SEGS];
22045f13123SDavid C Somayajulu 	uint64_t		tx_pkts_q[QLNX_FP_MAX_SEGS];
22145f13123SDavid C Somayajulu #endif
22245f13123SDavid C Somayajulu 
22311e25f0dSDavid C Somayajulu 	uint64_t		err_tx_nsegs_gt_elem_left;
22411e25f0dSDavid C Somayajulu         uint64_t                err_tx_dmamap_create;
22511e25f0dSDavid C Somayajulu         uint64_t                err_tx_defrag_dmamap_load;
22611e25f0dSDavid C Somayajulu         uint64_t                err_tx_non_tso_max_seg;
22711e25f0dSDavid C Somayajulu         uint64_t                err_tx_dmamap_load;
22811e25f0dSDavid C Somayajulu         uint64_t                err_tx_defrag;
22911e25f0dSDavid C Somayajulu         uint64_t                err_tx_free_pkt_null;
23011e25f0dSDavid C Somayajulu         uint64_t                err_tx_cons_idx_conflict;
23111e25f0dSDavid C Somayajulu 
23211e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_64;
23311e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_128;
23411e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_256;
23511e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_512;
23611e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_1024;
23711e25f0dSDavid C Somayajulu 
23811e25f0dSDavid C Somayajulu 	/* receive statistics */
23911e25f0dSDavid C Somayajulu 	uint64_t		rx_pkts;
24011e25f0dSDavid C Somayajulu 	uint64_t		tpa_start;
24111e25f0dSDavid C Somayajulu 	uint64_t		tpa_cont;
24211e25f0dSDavid C Somayajulu 	uint64_t		tpa_end;
24311e25f0dSDavid C Somayajulu         uint64_t                err_m_getcl;
24411e25f0dSDavid C Somayajulu         uint64_t                err_m_getjcl;
24511e25f0dSDavid C Somayajulu         uint64_t		err_rx_hw_errors;
24611e25f0dSDavid C Somayajulu         uint64_t		err_rx_alloc_errors;
24711e25f0dSDavid C Somayajulu 	uint64_t		err_rx_jumbo_chain_pkts;
24811e25f0dSDavid C Somayajulu 	uint64_t		err_rx_mp_null;
24911e25f0dSDavid C Somayajulu 	uint64_t		err_rx_tpa_invalid_agg_num;
25011e25f0dSDavid C Somayajulu };
25111e25f0dSDavid C Somayajulu 
25211e25f0dSDavid C Somayajulu struct qlnx_update_vport_params {
25311e25f0dSDavid C Somayajulu         uint8_t			vport_id;
25411e25f0dSDavid C Somayajulu         uint8_t			update_vport_active_rx_flg;
25511e25f0dSDavid C Somayajulu         uint8_t			vport_active_rx_flg;
25611e25f0dSDavid C Somayajulu         uint8_t			update_vport_active_tx_flg;
25711e25f0dSDavid C Somayajulu         uint8_t			vport_active_tx_flg;
25811e25f0dSDavid C Somayajulu         uint8_t			update_inner_vlan_removal_flg;
25911e25f0dSDavid C Somayajulu         uint8_t			inner_vlan_removal_flg;
26011e25f0dSDavid C Somayajulu         struct ecore_rss_params	*rss_params;
26111e25f0dSDavid C Somayajulu 	struct ecore_sge_tpa_params *sge_tpa_params;
26211e25f0dSDavid C Somayajulu };
26311e25f0dSDavid C Somayajulu 
26411e25f0dSDavid C Somayajulu /*
26511e25f0dSDavid C Somayajulu  * link related
26611e25f0dSDavid C Somayajulu  */
26711e25f0dSDavid C Somayajulu struct qlnx_link_output {
26811e25f0dSDavid C Somayajulu 	bool		link_up;
26911e25f0dSDavid C Somayajulu 	uint32_t	supported_caps;
27011e25f0dSDavid C Somayajulu 	uint32_t	advertised_caps;
27111e25f0dSDavid C Somayajulu 	uint32_t	link_partner_caps;
27211e25f0dSDavid C Somayajulu 	uint32_t	speed; /* In Mb/s */
27311e25f0dSDavid C Somayajulu 	bool		autoneg;
27411e25f0dSDavid C Somayajulu 	uint32_t	media_type;
27511e25f0dSDavid C Somayajulu 	uint32_t	duplex;
27611e25f0dSDavid C Somayajulu };
27711e25f0dSDavid C Somayajulu typedef struct qlnx_link_output qlnx_link_output_t;
27811e25f0dSDavid C Somayajulu 
27911e25f0dSDavid C Somayajulu #define QLNX_LINK_DUPLEX			0x0001
28011e25f0dSDavid C Somayajulu 
28111e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_FIBRE			0x0001
28211e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_Autoneg			0x0002
28311e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_Pause			0x0004
28411e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_Asym_Pause		0x0008
28511e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_1000baseT_Half		0x0010
28611e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_1000baseT_Full		0x0020
28711e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_10000baseKR_Full		0x0040
28811e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_25000baseKR_Full		0x0080
28911e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_40000baseLR4_Full		0x0100
29011e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_50000baseKR2_Full		0x0200
29111e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_100000baseKR4_Full	0x0400
29211e25f0dSDavid C Somayajulu 
29311e25f0dSDavid C Somayajulu /* Functions definition */
29411e25f0dSDavid C Somayajulu 
29511e25f0dSDavid C Somayajulu #define XMIT_PLAIN              0
29611e25f0dSDavid C Somayajulu #define XMIT_L4_CSUM            (1 << 0)
29711e25f0dSDavid C Somayajulu #define XMIT_LSO                (1 << 1)
29811e25f0dSDavid C Somayajulu 
29911e25f0dSDavid C Somayajulu #define CQE_FLAGS_ERR   (PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<       \
30011e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT |       \
30111e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<     \
30211e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT |     \
30311e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_MASK << \
30411e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_SHIFT | \
30511e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_MASK << \
30611e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_SHIFT)
30711e25f0dSDavid C Somayajulu 
30811e25f0dSDavid C Somayajulu #define RX_COPY_THRESH          92
30911e25f0dSDavid C Somayajulu #define ETH_MAX_PACKET_SIZE     1500
31011e25f0dSDavid C Somayajulu 
31111e25f0dSDavid C Somayajulu #define QLNX_MFW_VERSION_LENGTH 32
31211e25f0dSDavid C Somayajulu #define QLNX_STORMFW_VERSION_LENGTH 32
31311e25f0dSDavid C Somayajulu 
31411e25f0dSDavid C Somayajulu #define QLNX_TX_ELEM_RESERVE		2
31545f13123SDavid C Somayajulu #define QLNX_TX_ELEM_THRESH		128
31645f13123SDavid C Somayajulu #define QLNX_TX_ELEM_MAX_THRESH		512
31745f13123SDavid C Somayajulu #define QLNX_TX_ELEM_MIN_THRESH		32
31845f13123SDavid C Somayajulu #define QLNX_TX_COMPL_THRESH		32
31945f13123SDavid C Somayajulu 
32011e25f0dSDavid C Somayajulu #define QLNX_TPA_MAX_AGG_BUFFERS             (20)
32111e25f0dSDavid C Somayajulu 
32211e25f0dSDavid C Somayajulu #define QLNX_MAX_NUM_MULTICAST_ADDRS	ECORE_MAX_MC_ADDRS
32311e25f0dSDavid C Somayajulu typedef struct _qlnx_mcast {
32411e25f0dSDavid C Somayajulu         uint16_t        rsrvd;
32511e25f0dSDavid C Somayajulu         uint8_t         addr[6];
32611e25f0dSDavid C Somayajulu } __packed qlnx_mcast_t;
32711e25f0dSDavid C Somayajulu 
328217ec208SDavid C Somayajulu typedef struct _qlnx_vf_attr {
329217ec208SDavid C Somayajulu 	uint8_t		mac_addr[ETHER_ADDR_LEN];
330217ec208SDavid C Somayajulu 	uint32_t	num_rings;
331217ec208SDavid C Somayajulu } qlnx_vf_attr_t;
332217ec208SDavid C Somayajulu 
333217ec208SDavid C Somayajulu typedef struct _qlnx_sriov_task {
334217ec208SDavid C Somayajulu 	struct task		pf_task;
335217ec208SDavid C Somayajulu 	struct taskqueue	*pf_taskqueue;
336217ec208SDavid C Somayajulu 
337217ec208SDavid C Somayajulu #define QLNX_SRIOV_TASK_FLAGS_VF_PF_MSG		0x01
338217ec208SDavid C Somayajulu #define QLNX_SRIOV_TASK_FLAGS_VF_FLR_UPDATE	0x02
339217ec208SDavid C Somayajulu #define QLNX_SRIOV_TASK_FLAGS_BULLETIN_UPDATE	0x04
340217ec208SDavid C Somayajulu 	volatile uint32_t	flags;
341217ec208SDavid C Somayajulu 
342217ec208SDavid C Somayajulu } qlnx_sriov_task_t;
343217ec208SDavid C Somayajulu 
34411e25f0dSDavid C Somayajulu /*
34511e25f0dSDavid C Somayajulu  * Adapter structure contains the hardware independent information of the
34611e25f0dSDavid C Somayajulu  * pci function.
34711e25f0dSDavid C Somayajulu  */
34811e25f0dSDavid C Somayajulu struct qlnx_host {
34911e25f0dSDavid C Somayajulu 	/* interface to ecore */
35011e25f0dSDavid C Somayajulu 
35111e25f0dSDavid C Somayajulu 	struct ecore_dev	cdev;
35211e25f0dSDavid C Somayajulu 
35311e25f0dSDavid C Somayajulu 	uint32_t		state;
35411e25f0dSDavid C Somayajulu 
35511e25f0dSDavid C Somayajulu 	/* some flags */
35611e25f0dSDavid C Somayajulu         volatile struct {
35711e25f0dSDavid C Somayajulu                 volatile uint32_t
358217ec208SDavid C Somayajulu 			hw_init			:1,
35911e25f0dSDavid C Somayajulu 			callout_init		:1,
36011e25f0dSDavid C Somayajulu                         slowpath_start		:1,
36111e25f0dSDavid C Somayajulu                         parent_tag		:1,
36211e25f0dSDavid C Somayajulu                         lock_init		:1;
36311e25f0dSDavid C Somayajulu         } flags;
36411e25f0dSDavid C Somayajulu 
36511e25f0dSDavid C Somayajulu 	/* interface to o.s */
36611e25f0dSDavid C Somayajulu 
36711e25f0dSDavid C Somayajulu 	device_t		pci_dev;
36811e25f0dSDavid C Somayajulu 	uint8_t			pci_func;
36911e25f0dSDavid C Somayajulu 	uint8_t			dev_unit;
370217ec208SDavid C Somayajulu 	uint16_t		device_id;
37111e25f0dSDavid C Somayajulu 
372727bfe38SJustin Hibbits 	if_t			ifp;
37311e25f0dSDavid C Somayajulu 	int			if_flags;
37411e25f0dSDavid C Somayajulu 	volatile int		link_up;
37511e25f0dSDavid C Somayajulu 	struct ifmedia		media;
37611e25f0dSDavid C Somayajulu 	uint16_t		max_frame_size;
37711e25f0dSDavid C Somayajulu 
37811e25f0dSDavid C Somayajulu 	struct cdev		*ioctl_dev;
37911e25f0dSDavid C Somayajulu 
38011e25f0dSDavid C Somayajulu 	/* resources */
38111e25f0dSDavid C Somayajulu         struct resource         *pci_reg;
38211e25f0dSDavid C Somayajulu         int                     reg_rid;
38311e25f0dSDavid C Somayajulu 
38411e25f0dSDavid C Somayajulu         struct resource         *pci_dbells;
38511e25f0dSDavid C Somayajulu         int                     dbells_rid;
38611e25f0dSDavid C Somayajulu 	uint64_t		dbells_phys_addr;
38711e25f0dSDavid C Somayajulu 	uint32_t		dbells_size;
38811e25f0dSDavid C Somayajulu 
38911e25f0dSDavid C Somayajulu         struct resource         *msix_bar;
39011e25f0dSDavid C Somayajulu         int                     msix_rid;
39111e25f0dSDavid C Somayajulu 
39211e25f0dSDavid C Somayajulu 	int			msix_count;
39311e25f0dSDavid C Somayajulu 
394*1c45a62aSKeith Reynolds 	struct sx		hw_lock;
39511e25f0dSDavid C Somayajulu 
39611e25f0dSDavid C Somayajulu 	/* debug */
39711e25f0dSDavid C Somayajulu 
39811e25f0dSDavid C Somayajulu 	uint32_t                dbg_level;
39977388ed2SDavid C Somayajulu 	uint32_t                dbg_trace_lro_cnt;
40077388ed2SDavid C Somayajulu 	uint32_t                dbg_trace_tso_pkt_len;
40111e25f0dSDavid C Somayajulu 	uint32_t                dp_level;
40211e25f0dSDavid C Somayajulu 	uint32_t                dp_module;
40311e25f0dSDavid C Somayajulu 
40411e25f0dSDavid C Somayajulu 	/* misc */
40511e25f0dSDavid C Somayajulu 	uint8_t 		mfw_ver[QLNX_MFW_VERSION_LENGTH];
40611e25f0dSDavid C Somayajulu 	uint8_t 		stormfw_ver[QLNX_STORMFW_VERSION_LENGTH];
40711e25f0dSDavid C Somayajulu 	uint32_t		flash_size;
40811e25f0dSDavid C Somayajulu 
40911e25f0dSDavid C Somayajulu 	/* dma related */
41011e25f0dSDavid C Somayajulu 
41111e25f0dSDavid C Somayajulu 	bus_dma_tag_t		parent_tag;
41211e25f0dSDavid C Somayajulu 	bus_dma_tag_t		tx_tag;
41311e25f0dSDavid C Somayajulu 	bus_dma_tag_t		rx_tag;
41411e25f0dSDavid C Somayajulu 
41511e25f0dSDavid C Somayajulu         struct ecore_sb_info    sb_array[QLNX_MAX_RSS];
41611e25f0dSDavid C Somayajulu         struct qlnx_rx_queue    rxq_array[QLNX_MAX_RSS];
41711e25f0dSDavid C Somayajulu         struct qlnx_tx_queue    txq_array[(QLNX_MAX_RSS * MAX_NUM_TC)];
41811e25f0dSDavid C Somayajulu         struct qlnx_fastpath    fp_array[QLNX_MAX_RSS];
41911e25f0dSDavid C Somayajulu 
42011e25f0dSDavid C Somayajulu 	/* tx related */
42111e25f0dSDavid C Somayajulu 	struct callout		tx_callout;
42211e25f0dSDavid C Somayajulu 	uint32_t		txr_idx;
42311e25f0dSDavid C Somayajulu 
42411e25f0dSDavid C Somayajulu 	/* rx related */
42511e25f0dSDavid C Somayajulu 	uint32_t		rx_pkt_threshold;
42611e25f0dSDavid C Somayajulu 	uint32_t		rx_jumbo_buf_eq_mtu;
42711e25f0dSDavid C Somayajulu 
42811e25f0dSDavid C Somayajulu 	/* slow path related */
42911e25f0dSDavid C Somayajulu         struct resource         *sp_irq[MAX_HWFNS_PER_DEVICE];
43011e25f0dSDavid C Somayajulu         void                    *sp_handle[MAX_HWFNS_PER_DEVICE];
43111e25f0dSDavid C Somayajulu         int                     sp_irq_rid[MAX_HWFNS_PER_DEVICE];
43211e25f0dSDavid C Somayajulu 	struct task		sp_task[MAX_HWFNS_PER_DEVICE];
43311e25f0dSDavid C Somayajulu 	struct taskqueue	*sp_taskqueue[MAX_HWFNS_PER_DEVICE];
43411e25f0dSDavid C Somayajulu 
43511e25f0dSDavid C Somayajulu 	struct callout          qlnx_callout;
43611e25f0dSDavid C Somayajulu 
43711e25f0dSDavid C Somayajulu 	/* fast path related */
43811e25f0dSDavid C Somayajulu 	int			num_rss;
43911e25f0dSDavid C Somayajulu 	int			num_tc;
44011e25f0dSDavid C Somayajulu 
44111e25f0dSDavid C Somayajulu #define QLNX_MAX_TSS_CNT(ha)	((ha->num_rss) * (ha->num_tc))
44211e25f0dSDavid C Somayajulu 
44311e25f0dSDavid C Somayajulu 	qlnx_ivec_t              irq_vec[QLNX_MAX_RSS];
44411e25f0dSDavid C Somayajulu 
44511e25f0dSDavid C Somayajulu 	uint8_t			filter;
44611e25f0dSDavid C Somayajulu 	uint32_t                nmcast;
44711e25f0dSDavid C Somayajulu 	qlnx_mcast_t            mcast[QLNX_MAX_NUM_MULTICAST_ADDRS];
44811e25f0dSDavid C Somayajulu 	struct ecore_filter_mcast ecore_mcast;
44911e25f0dSDavid C Somayajulu 	uint8_t			primary_mac[ETH_ALEN];
45011e25f0dSDavid C Somayajulu 	uint8_t			prio_to_tc[MAX_NUM_PRI];
45111e25f0dSDavid C Somayajulu 	struct ecore_eth_stats	hw_stats;
45211e25f0dSDavid C Somayajulu 	struct ecore_rss_params	rss_params;
45311e25f0dSDavid C Somayajulu         uint32_t		rx_buf_size;
45411e25f0dSDavid C Somayajulu         bool			rx_csum_offload;
45511e25f0dSDavid C Somayajulu 
45611e25f0dSDavid C Somayajulu 	uint32_t		rx_coalesce_usecs;
45711e25f0dSDavid C Somayajulu 	uint32_t		tx_coalesce_usecs;
45811e25f0dSDavid C Somayajulu 
45911e25f0dSDavid C Somayajulu 	/* link related */
46011e25f0dSDavid C Somayajulu 	qlnx_link_output_t	if_link;
46111e25f0dSDavid C Somayajulu 
46211e25f0dSDavid C Somayajulu 	/* global counters */
46311e25f0dSDavid C Somayajulu 	uint64_t		sp_interrupts;
46411e25f0dSDavid C Somayajulu 	uint64_t		err_illegal_intr;
46511e25f0dSDavid C Somayajulu 	uint64_t		err_fp_null;
46611e25f0dSDavid C Somayajulu 	uint64_t		err_get_proto_invalid_type;
46711e25f0dSDavid C Somayajulu 
468217ec208SDavid C Somayajulu 	/* error recovery related */
469217ec208SDavid C Somayajulu 	uint32_t		error_recovery;
470217ec208SDavid C Somayajulu 	struct task		err_task;
471217ec208SDavid C Somayajulu 	struct taskqueue	*err_taskqueue;
472217ec208SDavid C Somayajulu 
47311e25f0dSDavid C Somayajulu 	/* grcdump related */
47411e25f0dSDavid C Somayajulu 	uint32_t		err_inject;
47511e25f0dSDavid C Somayajulu 	uint32_t		grcdump_taken;
47611e25f0dSDavid C Somayajulu 	uint32_t		grcdump_dwords[QLNX_MAX_HW_FUNCS];
47711e25f0dSDavid C Somayajulu 	uint32_t		grcdump_size[QLNX_MAX_HW_FUNCS];
47811e25f0dSDavid C Somayajulu 	void			*grcdump[QLNX_MAX_HW_FUNCS];
47911e25f0dSDavid C Somayajulu 
48011e25f0dSDavid C Somayajulu 	uint32_t		idle_chk_taken;
48111e25f0dSDavid C Somayajulu 	uint32_t		idle_chk_dwords[QLNX_MAX_HW_FUNCS];
48211e25f0dSDavid C Somayajulu 	uint32_t		idle_chk_size[QLNX_MAX_HW_FUNCS];
48311e25f0dSDavid C Somayajulu 	void			*idle_chk[QLNX_MAX_HW_FUNCS];
48411e25f0dSDavid C Somayajulu 
48511e25f0dSDavid C Somayajulu 	/* storm stats related */
48611e25f0dSDavid C Somayajulu #define QLNX_STORM_STATS_TOTAL \
48711e25f0dSDavid C Somayajulu 		(QLNX_MAX_HW_FUNCS * QLNX_STORM_STATS_SAMPLES_PER_HWFN)
48811e25f0dSDavid C Somayajulu 	qlnx_storm_stats_t	storm_stats[QLNX_STORM_STATS_TOTAL];
48911e25f0dSDavid C Somayajulu 	uint32_t		storm_stats_index;
49011e25f0dSDavid C Somayajulu 	uint32_t		storm_stats_enable;
49145f13123SDavid C Somayajulu 	uint32_t		storm_stats_gather;
49211e25f0dSDavid C Somayajulu 
49311e25f0dSDavid C Somayajulu 	uint32_t		personality;
494217ec208SDavid C Somayajulu 
495217ec208SDavid C Somayajulu 	uint16_t		sriov_initialized;
496217ec208SDavid C Somayajulu 	uint16_t		num_vfs;
497217ec208SDavid C Somayajulu 	qlnx_vf_attr_t		*vf_attr;
498217ec208SDavid C Somayajulu 	qlnx_sriov_task_t	sriov_task[MAX_HWFNS_PER_DEVICE];
499217ec208SDavid C Somayajulu 	uint32_t		curr_vf;
500217ec208SDavid C Somayajulu 
501217ec208SDavid C Somayajulu 	void			*next;
502217ec208SDavid C Somayajulu 	void			*qlnx_rdma;
503217ec208SDavid C Somayajulu 	volatile int		qlnxr_debug;
50411e25f0dSDavid C Somayajulu };
50511e25f0dSDavid C Somayajulu 
50611e25f0dSDavid C Somayajulu typedef struct qlnx_host qlnx_host_t;
50711e25f0dSDavid C Somayajulu 
50811e25f0dSDavid C Somayajulu /* note that align has to be a power of 2 */
509217ec208SDavid C Somayajulu #define QL_ALIGN(size, align) (((size) + ((align) - 1)) & (~((align) - 1)));
51011e25f0dSDavid C Somayajulu #define QL_MIN(x, y) ((x < y) ? x : y)
51111e25f0dSDavid C Somayajulu 
51211e25f0dSDavid C Somayajulu #define QL_RUNNING(ifp) \
513727bfe38SJustin Hibbits 		((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) == \
51411e25f0dSDavid C Somayajulu 			IFF_DRV_RUNNING)
51511e25f0dSDavid C Somayajulu 
51611e25f0dSDavid C Somayajulu #define QLNX_MAX_MTU			9000
51711e25f0dSDavid C Somayajulu #define QLNX_MAX_SEGMENTS_NON_TSO	(ETH_TX_MAX_BDS_PER_NON_LSO_PACKET - 1)
51845f13123SDavid C Somayajulu //#define QLNX_MAX_TSO_FRAME_SIZE		((64 * 1024 - 1) + 22)
51945f13123SDavid C Somayajulu #define QLNX_MAX_TSO_FRAME_SIZE		65536
52045f13123SDavid C Somayajulu #define QLNX_MAX_TX_MBUF_SIZE		65536    /* bytes - bd_len = 16bits */
52145f13123SDavid C Somayajulu 
52211e25f0dSDavid C Somayajulu #define QL_MAC_CMP(mac1, mac2)    \
52311e25f0dSDavid C Somayajulu         ((((*(uint32_t *) mac1) == (*(uint32_t *) mac2) && \
52411e25f0dSDavid C Somayajulu         (*(uint16_t *)(mac1 + 4)) == (*(uint16_t *)(mac2 + 4)))) ? 0 : 1)
52511e25f0dSDavid C Somayajulu #define for_each_rss(i) for (i = 0; i < ha->num_rss; i++)
52611e25f0dSDavid C Somayajulu 
52711e25f0dSDavid C Somayajulu /*
52811e25f0dSDavid C Somayajulu  * Debug Related
52911e25f0dSDavid C Somayajulu  */
53011e25f0dSDavid C Somayajulu 
53111e25f0dSDavid C Somayajulu #ifdef QLNX_DEBUG
53211e25f0dSDavid C Somayajulu 
5337a377fbeSDavid C Somayajulu #define QL_DPRINT1(ha, x, ...) 					\
5347a377fbeSDavid C Somayajulu 	do { 							\
5357a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0001) {			\
5367a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5377a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5387a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5397a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5407a377fbeSDavid C Somayajulu 		}						\
5417a377fbeSDavid C Somayajulu 	} while (0)
5427a377fbeSDavid C Somayajulu 
5437a377fbeSDavid C Somayajulu #define QL_DPRINT2(ha, x, ...)					\
5447a377fbeSDavid C Somayajulu 	do { 							\
5457a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0002) {			\
5467a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5477a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5487a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5497a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5507a377fbeSDavid C Somayajulu 		}						\
5517a377fbeSDavid C Somayajulu 	} while (0)
5527a377fbeSDavid C Somayajulu 
5537a377fbeSDavid C Somayajulu #define QL_DPRINT3(ha, x, ...)					\
5547a377fbeSDavid C Somayajulu 	do { 							\
5557a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0004) {			\
5567a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5577a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5587a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5597a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5607a377fbeSDavid C Somayajulu 		}						\
5617a377fbeSDavid C Somayajulu 	} while (0)
5627a377fbeSDavid C Somayajulu 
5637a377fbeSDavid C Somayajulu #define QL_DPRINT4(ha, x, ...)					\
5647a377fbeSDavid C Somayajulu 	do { 							\
5657a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0008) {			\
5667a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5677a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5687a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5697a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5707a377fbeSDavid C Somayajulu 		}						\
5717a377fbeSDavid C Somayajulu 	} while (0)
5727a377fbeSDavid C Somayajulu 
5737a377fbeSDavid C Somayajulu #define QL_DPRINT5(ha, x, ...)					\
5747a377fbeSDavid C Somayajulu 	do { 							\
5757a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0010) {			\
5767a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5777a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5787a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5797a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5807a377fbeSDavid C Somayajulu 		}						\
5817a377fbeSDavid C Somayajulu 	} while (0)
5827a377fbeSDavid C Somayajulu 
5837a377fbeSDavid C Somayajulu #define QL_DPRINT6(ha, x, ...)					\
5847a377fbeSDavid C Somayajulu 	do { 							\
5857a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0020) {			\
5867a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5877a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5887a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5897a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5907a377fbeSDavid C Somayajulu 		}						\
5917a377fbeSDavid C Somayajulu 	} while (0)
5927a377fbeSDavid C Somayajulu 
5937a377fbeSDavid C Somayajulu #define QL_DPRINT7(ha, x, ...)					\
5947a377fbeSDavid C Somayajulu 	do { 							\
5957a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0040) {			\
5967a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5977a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5987a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5997a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6007a377fbeSDavid C Somayajulu 		}						\
6017a377fbeSDavid C Somayajulu 	} while (0)
6027a377fbeSDavid C Somayajulu 
6037a377fbeSDavid C Somayajulu #define QL_DPRINT8(ha, x, ...)					\
6047a377fbeSDavid C Somayajulu 	do { 							\
6057a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0080) {			\
6067a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6077a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6087a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6097a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6107a377fbeSDavid C Somayajulu 		}						\
6117a377fbeSDavid C Somayajulu 	} while (0)
6127a377fbeSDavid C Somayajulu 
6137a377fbeSDavid C Somayajulu #define QL_DPRINT9(ha, x, ...)					\
6147a377fbeSDavid C Somayajulu 	do { 							\
6157a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0100) {			\
6167a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6177a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6187a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6197a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6207a377fbeSDavid C Somayajulu 		}						\
6217a377fbeSDavid C Somayajulu 	} while (0)
6227a377fbeSDavid C Somayajulu 
6237a377fbeSDavid C Somayajulu #define QL_DPRINT11(ha, x, ...)					\
6247a377fbeSDavid C Somayajulu 	do { 							\
6257a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0400) {			\
6267a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6277a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6287a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6297a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6307a377fbeSDavid C Somayajulu 		}						\
6317a377fbeSDavid C Somayajulu 	} while (0)
6327a377fbeSDavid C Somayajulu 
6337a377fbeSDavid C Somayajulu #define QL_DPRINT12(ha, x, ...)					\
6347a377fbeSDavid C Somayajulu 	do { 							\
6357a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0800) {			\
6367a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6377a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6387a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6397a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6407a377fbeSDavid C Somayajulu 		}						\
6417a377fbeSDavid C Somayajulu 	} while (0)
6427a377fbeSDavid C Somayajulu 
6437a377fbeSDavid C Somayajulu #define QL_DPRINT13(ha, x, ...)					\
6447a377fbeSDavid C Somayajulu 	do { 							\
6457a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x1000) {			\
6467a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6477a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6487a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6497a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6507a377fbeSDavid C Somayajulu 		}						\
6517a377fbeSDavid C Somayajulu 	} while (0)
6527a377fbeSDavid C Somayajulu 
65311e25f0dSDavid C Somayajulu #else
65411e25f0dSDavid C Somayajulu 
6557a377fbeSDavid C Somayajulu #define QL_DPRINT1(ha, x, ...)
6567a377fbeSDavid C Somayajulu #define QL_DPRINT2(ha, x, ...)
6577a377fbeSDavid C Somayajulu #define QL_DPRINT3(ha, x, ...)
6587a377fbeSDavid C Somayajulu #define QL_DPRINT4(ha, x, ...)
6597a377fbeSDavid C Somayajulu #define QL_DPRINT5(ha, x, ...)
6607a377fbeSDavid C Somayajulu #define QL_DPRINT6(ha, x, ...)
6617a377fbeSDavid C Somayajulu #define QL_DPRINT7(ha, x, ...)
6627a377fbeSDavid C Somayajulu #define QL_DPRINT8(ha, x, ...)
6637a377fbeSDavid C Somayajulu #define QL_DPRINT9(ha, x, ...)
6647a377fbeSDavid C Somayajulu #define QL_DPRINT11(ha, x, ...)
6657a377fbeSDavid C Somayajulu #define QL_DPRINT12(ha, x, ...)
6667a377fbeSDavid C Somayajulu #define QL_DPRINT13(ha, x, ...)
66711e25f0dSDavid C Somayajulu 
66811e25f0dSDavid C Somayajulu #endif /* #ifdef QLNX_DEBUG */
66911e25f0dSDavid C Somayajulu 
67011e25f0dSDavid C Somayajulu #define QL_ASSERT(ha, x, y)     if (!x) panic y
67111e25f0dSDavid C Somayajulu 
67211e25f0dSDavid C Somayajulu #define QL_ERR_INJECT(ha, val)		(ha->err_inject == val)
67311e25f0dSDavid C Somayajulu #define QL_RESET_ERR_INJECT(ha, val)	{if (ha->err_inject == val) ha->err_inject = 0;}
67411e25f0dSDavid C Somayajulu #define QL_ERR_INJCT_TX_INT_DIFF	0x0001
67511e25f0dSDavid C Somayajulu #define QL_ERR_INJCT_TX_INT_MBUF_NULL	0x0002
67611e25f0dSDavid C Somayajulu 
67711e25f0dSDavid C Somayajulu /*
67811e25f0dSDavid C Somayajulu  * exported functions
67911e25f0dSDavid C Somayajulu  */
68011e25f0dSDavid C Somayajulu extern int qlnx_make_cdev(qlnx_host_t *ha);
68111e25f0dSDavid C Somayajulu extern void qlnx_del_cdev(qlnx_host_t *ha);
68211e25f0dSDavid C Somayajulu extern int qlnx_grc_dump(qlnx_host_t *ha, uint32_t *num_dumped_dwords,
68311e25f0dSDavid C Somayajulu 		int hwfn_index);
68411e25f0dSDavid C Somayajulu extern int qlnx_idle_chk(qlnx_host_t *ha, uint32_t *num_dumped_dwords,
68511e25f0dSDavid C Somayajulu 		int hwfn_index);
68611e25f0dSDavid C Somayajulu extern uint8_t *qlnx_get_mac_addr(qlnx_host_t *ha);
687217ec208SDavid C Somayajulu extern void qlnx_fill_link(qlnx_host_t *ha, struct ecore_hwfn *hwfn,
68811e25f0dSDavid C Somayajulu                           struct qlnx_link_output *if_link);
689217ec208SDavid C Somayajulu extern int qlnx_set_lldp_tlvx(qlnx_host_t *ha, qlnx_lldp_sys_tlvs_t *lldp_tlvs);
690217ec208SDavid C Somayajulu extern int qlnx_vf_device(qlnx_host_t *ha);
691217ec208SDavid C Somayajulu extern void qlnx_free_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info);
692217ec208SDavid C Somayajulu extern int qlnx_alloc_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info,
693217ec208SDavid C Somayajulu 		u16 sb_id);
694217ec208SDavid C Somayajulu 
69511e25f0dSDavid C Somayajulu /*
69611e25f0dSDavid C Somayajulu  * Some OS specific stuff
69711e25f0dSDavid C Somayajulu  */
69811e25f0dSDavid C Somayajulu 
69911e25f0dSDavid C Somayajulu #if (defined IFM_100G_SR4)
70011e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_SR4 IFM_100G_SR4
70111e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_LR4 IFM_100G_LR4
70211e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_CR4 IFM_100G_CR4
70311e25f0dSDavid C Somayajulu #else
70411e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_SR4 IFM_UNKNOWN
70511e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_LR4 IFM_UNKNOWN
706217ec208SDavid C Somayajulu #endif /* #if (defined IFM_100G_SR4) */
70711e25f0dSDavid C Somayajulu 
70811e25f0dSDavid C Somayajulu #if (defined IFM_25G_SR)
70911e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_SR IFM_25G_SR
71011e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_CR IFM_25G_CR
71111e25f0dSDavid C Somayajulu #else
71211e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_SR IFM_UNKNOWN
71311e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_CR IFM_UNKNOWN
714217ec208SDavid C Somayajulu #endif /* #if (defined IFM_25G_SR) */
71511e25f0dSDavid C Somayajulu 
71611e25f0dSDavid C Somayajulu #define QLNX_INC_IERRORS(ifp)	if_inc_counter(ifp, IFCOUNTER_IERRORS, 1)
71711e25f0dSDavid C Somayajulu #define QLNX_INC_IQDROPS(ifp)	if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1)
71811e25f0dSDavid C Somayajulu #define QLNX_INC_IPACKETS(ifp)	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1)
71911e25f0dSDavid C Somayajulu #define QLNX_INC_OPACKETS(ifp)	if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1)
72011e25f0dSDavid C Somayajulu 
72111e25f0dSDavid C Somayajulu #define QLNX_INC_OBYTES(ifp, len)	\
72211e25f0dSDavid C Somayajulu 			if_inc_counter(ifp, IFCOUNTER_OBYTES, len)
72311e25f0dSDavid C Somayajulu #define QLNX_INC_IBYTES(ifp, len)	\
72411e25f0dSDavid C Somayajulu 			if_inc_counter(ha->ifp, IFCOUNTER_IBYTES, len)
72511e25f0dSDavid C Somayajulu 
72611e25f0dSDavid C Somayajulu #define CQE_L3_PACKET(flags)    \
7279efd0ba7SDavid C Somayajulu         ((((flags) & PARSING_AND_ERR_FLAGS_L3TYPE_MASK) == e_l3_type_ipv4) || \
7289efd0ba7SDavid C Somayajulu         (((flags) & PARSING_AND_ERR_FLAGS_L3TYPE_MASK) == e_l3_type_ipv6))
72911e25f0dSDavid C Somayajulu 
73011e25f0dSDavid C Somayajulu #define CQE_IP_HDR_ERR(flags) \
73111e25f0dSDavid C Somayajulu         ((flags) & (PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK \
73211e25f0dSDavid C Somayajulu                 << PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT))
73311e25f0dSDavid C Somayajulu 
73411e25f0dSDavid C Somayajulu #define CQE_L4_HAS_CSUM(flags) \
73511e25f0dSDavid C Somayajulu         ((flags) & (PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK \
73611e25f0dSDavid C Somayajulu                 << PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT))
73711e25f0dSDavid C Somayajulu 
73811e25f0dSDavid C Somayajulu #define CQE_HAS_VLAN(flags) \
73911e25f0dSDavid C Somayajulu         ((flags) & (PARSING_AND_ERR_FLAGS_TAG8021QEXIST_MASK \
74011e25f0dSDavid C Somayajulu                 << PARSING_AND_ERR_FLAGS_TAG8021QEXIST_SHIFT))
74111e25f0dSDavid C Somayajulu 
742217ec208SDavid C Somayajulu #ifndef QLNX_RDMA
74345f13123SDavid C Somayajulu #if defined(__i386__) || defined(__amd64__)
74445f13123SDavid C Somayajulu 
74545f13123SDavid C Somayajulu static __inline
prefetch(void * x)74645f13123SDavid C Somayajulu void prefetch(void *x)
74745f13123SDavid C Somayajulu {
74845f13123SDavid C Somayajulu         __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
74945f13123SDavid C Somayajulu }
75045f13123SDavid C Somayajulu 
75145f13123SDavid C Somayajulu #else
75245f13123SDavid C Somayajulu #define prefetch(x)
75345f13123SDavid C Somayajulu #endif
754217ec208SDavid C Somayajulu #endif
75545f13123SDavid C Somayajulu 
75611e25f0dSDavid C Somayajulu #endif /* #ifndef _QLNX_DEF_H_ */
757