xref: /freebsd/sys/dev/qlnx/qlnxe/qlnx_def.h (revision 45f13123879297168b648a1ad571196f0d4ee929)
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  * $FreeBSD$
2811e25f0dSDavid C Somayajulu  *
2911e25f0dSDavid C Somayajulu  */
3011e25f0dSDavid C Somayajulu 
3111e25f0dSDavid C Somayajulu 
3211e25f0dSDavid C Somayajulu 
3311e25f0dSDavid C Somayajulu /*
3411e25f0dSDavid C Somayajulu  * File: qlnx_def.h
3511e25f0dSDavid C Somayajulu  * Author : David C Somayajulu, Cavium Inc., San Jose, CA 95131.
3611e25f0dSDavid C Somayajulu  */
3711e25f0dSDavid C Somayajulu 
3811e25f0dSDavid C Somayajulu #ifndef _QLNX_DEF_H_
3911e25f0dSDavid C Somayajulu #define _QLNX_DEF_H_
4011e25f0dSDavid C Somayajulu 
4111e25f0dSDavid C Somayajulu #define VER_SIZE 16
4211e25f0dSDavid C Somayajulu 
4311e25f0dSDavid C Somayajulu struct qlnx_ivec {
4411e25f0dSDavid C Somayajulu         uint32_t                rss_idx;
4511e25f0dSDavid C Somayajulu         void                    *ha;
4611e25f0dSDavid C Somayajulu         struct resource         *irq;
4711e25f0dSDavid C Somayajulu         void                    *handle;
4811e25f0dSDavid C Somayajulu         int                     irq_rid;
4911e25f0dSDavid C Somayajulu };
5011e25f0dSDavid C Somayajulu 
5111e25f0dSDavid C Somayajulu typedef struct qlnx_ivec qlnx_ivec_t;
5211e25f0dSDavid C Somayajulu 
5311e25f0dSDavid C Somayajulu //#define QLNX_MAX_RSS		30
54*45f13123SDavid C Somayajulu #define QLNX_MAX_RSS		36
55*45f13123SDavid C Somayajulu #define QLNX_DEFAULT_RSS	16
5611e25f0dSDavid C Somayajulu #define QLNX_MAX_TC		1
5711e25f0dSDavid C Somayajulu 
5811e25f0dSDavid C Somayajulu enum QLNX_STATE {
5911e25f0dSDavid C Somayajulu         QLNX_STATE_CLOSED,
6011e25f0dSDavid C Somayajulu         QLNX_STATE_OPEN,
6111e25f0dSDavid C Somayajulu };
6211e25f0dSDavid C Somayajulu 
6311e25f0dSDavid C Somayajulu #define HILO_U64(hi, lo)                ((((u64)(hi)) << 32) + (lo))
6411e25f0dSDavid C Somayajulu 
6511e25f0dSDavid C Somayajulu #define MAX_NUM_TC      8
6611e25f0dSDavid C Somayajulu #define MAX_NUM_PRI     8
6711e25f0dSDavid C Somayajulu 
6811e25f0dSDavid C Somayajulu #ifndef BITS_PER_BYTE
6911e25f0dSDavid C Somayajulu #define BITS_PER_BYTE	8
7011e25f0dSDavid C Somayajulu #endif /* #ifndef BITS_PER_BYTE */
7111e25f0dSDavid C Somayajulu 
7211e25f0dSDavid C Somayajulu 
7311e25f0dSDavid C Somayajulu /*
7411e25f0dSDavid C Somayajulu  * RX ring buffer contains pointer to kmalloc() data only,
7511e25f0dSDavid C Somayajulu  */
7611e25f0dSDavid C Somayajulu struct sw_rx_data {
7711e25f0dSDavid C Somayajulu         void		*data;
7811e25f0dSDavid C Somayajulu 	bus_dmamap_t	map;
7911e25f0dSDavid C Somayajulu 	dma_addr_t	dma_addr;
8011e25f0dSDavid C Somayajulu };
8111e25f0dSDavid C Somayajulu 
8211e25f0dSDavid C Somayajulu enum qlnx_agg_state {
8311e25f0dSDavid C Somayajulu         QLNX_AGG_STATE_NONE  = 0,
8411e25f0dSDavid C Somayajulu         QLNX_AGG_STATE_START = 1,
8511e25f0dSDavid C Somayajulu         QLNX_AGG_STATE_ERROR = 2
8611e25f0dSDavid C Somayajulu };
8711e25f0dSDavid C Somayajulu 
8811e25f0dSDavid C Somayajulu struct qlnx_agg_info {
8911e25f0dSDavid C Somayajulu         /* rx_buf is a data buffer that can be placed /consumed from rx bd
9011e25f0dSDavid C Somayajulu          * chain. It has two purposes: We will preallocate the data buffer
9111e25f0dSDavid C Somayajulu          * for each aggregation when we open the interface and will place this
9211e25f0dSDavid C Somayajulu          * buffer on the rx-bd-ring when we receive TPA_START. We don't want
9311e25f0dSDavid C Somayajulu          * to be in a state where allocation fails, as we can't reuse the
9411e25f0dSDavid C Somayajulu          * consumer buffer in the rx-chain since FW may still be writing to it
9511e25f0dSDavid C Somayajulu          * (since header needs to be modified for TPA.
9611e25f0dSDavid C Somayajulu          * The second purpose is to keep a pointer to the bd buffer during
9711e25f0dSDavid C Somayajulu          * aggregation.
9811e25f0dSDavid C Somayajulu          */
9911e25f0dSDavid C Somayajulu         struct sw_rx_data       rx_buf;
10011e25f0dSDavid C Somayajulu         enum qlnx_agg_state     agg_state;
10111e25f0dSDavid C Somayajulu 	uint16_t		placement_offset;
10211e25f0dSDavid C Somayajulu         struct mbuf             *mpf; /* first mbuf in chain */
10311e25f0dSDavid C Somayajulu         struct mbuf             *mpl; /* last mbuf in chain */
10411e25f0dSDavid C Somayajulu };
10511e25f0dSDavid C Somayajulu 
10611e25f0dSDavid C Somayajulu #define RX_RING_SIZE_POW        13
10711e25f0dSDavid C Somayajulu #define RX_RING_SIZE            (1 << RX_RING_SIZE_POW)
10811e25f0dSDavid C Somayajulu 
10911e25f0dSDavid C Somayajulu #define TX_RING_SIZE_POW        14
11011e25f0dSDavid C Somayajulu #define TX_RING_SIZE            (1 << TX_RING_SIZE_POW)
11111e25f0dSDavid C Somayajulu 
11211e25f0dSDavid C Somayajulu struct qlnx_rx_queue {
11311e25f0dSDavid C Somayajulu         volatile __le16         *hw_cons_ptr;
11411e25f0dSDavid C Somayajulu         struct sw_rx_data       sw_rx_ring[RX_RING_SIZE];
11511e25f0dSDavid C Somayajulu         uint16_t		sw_rx_cons;
11611e25f0dSDavid C Somayajulu         uint16_t		sw_rx_prod;
11711e25f0dSDavid C Somayajulu         struct ecore_chain      rx_bd_ring;
11811e25f0dSDavid C Somayajulu         struct ecore_chain      rx_comp_ring;
11911e25f0dSDavid C Somayajulu         void __iomem            *hw_rxq_prod_addr;
12011e25f0dSDavid C Somayajulu 	void 			*handle;
12111e25f0dSDavid C Somayajulu 
12211e25f0dSDavid C Somayajulu         /* LRO */
12311e25f0dSDavid C Somayajulu         struct qlnx_agg_info    tpa_info[ETH_TPA_MAX_AGGS_NUM];
12411e25f0dSDavid C Somayajulu 
12511e25f0dSDavid C Somayajulu         uint32_t		rx_buf_size;
12611e25f0dSDavid C Somayajulu 
12711e25f0dSDavid C Somayajulu         uint16_t		num_rx_buffers;
12811e25f0dSDavid C Somayajulu         uint16_t		rxq_id;
12911e25f0dSDavid C Somayajulu 
13011e25f0dSDavid C Somayajulu 
13111e25f0dSDavid C Somayajulu #ifdef QLNX_SOFT_LRO
13211e25f0dSDavid C Somayajulu 	struct lro_ctrl		lro;
13311e25f0dSDavid C Somayajulu #endif
13411e25f0dSDavid C Somayajulu };
13511e25f0dSDavid C Somayajulu 
13611e25f0dSDavid C Somayajulu 
13711e25f0dSDavid C Somayajulu union db_prod {
13811e25f0dSDavid C Somayajulu         struct eth_db_data	data;
13911e25f0dSDavid C Somayajulu         uint32_t		raw;
14011e25f0dSDavid C Somayajulu };
14111e25f0dSDavid C Somayajulu 
14211e25f0dSDavid C Somayajulu struct sw_tx_bd {
14311e25f0dSDavid C Somayajulu         struct mbuf		*mp;
14411e25f0dSDavid C Somayajulu 	bus_dmamap_t		map;
14511e25f0dSDavid C Somayajulu         uint8_t			flags;
14611e25f0dSDavid C Somayajulu 	int			nsegs;
14711e25f0dSDavid C Somayajulu 
14811e25f0dSDavid C Somayajulu /* Set on the first BD descriptor when there is a split BD */
14911e25f0dSDavid C Somayajulu #define QLNX_TSO_SPLIT_BD               (1<<0)
15011e25f0dSDavid C Somayajulu };
15111e25f0dSDavid C Somayajulu 
15211e25f0dSDavid C Somayajulu #define QLNX_MAX_SEGMENTS		255
15311e25f0dSDavid C Somayajulu struct qlnx_tx_queue {
15411e25f0dSDavid C Somayajulu 
15511e25f0dSDavid C Somayajulu         int                     index; /* Queue index */
15611e25f0dSDavid C Somayajulu         volatile __le16         *hw_cons_ptr;
15711e25f0dSDavid C Somayajulu         struct sw_tx_bd         sw_tx_ring[TX_RING_SIZE];
15811e25f0dSDavid C Somayajulu         uint16_t		sw_tx_cons;
15911e25f0dSDavid C Somayajulu         uint16_t		sw_tx_prod;
16011e25f0dSDavid C Somayajulu         struct ecore_chain	tx_pbl;
16111e25f0dSDavid C Somayajulu         void __iomem            *doorbell_addr;
16211e25f0dSDavid C Somayajulu 	void 			*handle;
16311e25f0dSDavid C Somayajulu         union db_prod           tx_db;
16411e25f0dSDavid C Somayajulu 
16511e25f0dSDavid C Somayajulu 	bus_dma_segment_t	segs[QLNX_MAX_SEGMENTS];
16611e25f0dSDavid C Somayajulu 
16711e25f0dSDavid C Somayajulu         uint16_t		num_tx_buffers;
16811e25f0dSDavid C Somayajulu };
16911e25f0dSDavid C Somayajulu 
17011e25f0dSDavid C Somayajulu #define BD_UNMAP_ADDR(bd)	HILO_U64(le32toh((bd)->addr.hi), \
17111e25f0dSDavid C Somayajulu 					le32toh((bd)->addr.lo))
17211e25f0dSDavid C Somayajulu #define BD_UNMAP_LEN(bd)	(le16toh((bd)->nbytes))
17311e25f0dSDavid C Somayajulu 
17411e25f0dSDavid C Somayajulu #define BD_SET_UNMAP_ADDR_LEN(bd, maddr, len) \
17511e25f0dSDavid C Somayajulu         do { \
17611e25f0dSDavid C Somayajulu                 (bd)->addr.hi = htole32(U64_HI(maddr)); \
17711e25f0dSDavid C Somayajulu                 (bd)->addr.lo = htole32(U64_LO(maddr)); \
17811e25f0dSDavid C Somayajulu                 (bd)->nbytes = htole16(len); \
17911e25f0dSDavid C Somayajulu         } while (0);
18011e25f0dSDavid C Somayajulu 
18111e25f0dSDavid C Somayajulu 
18211e25f0dSDavid C Somayajulu #define QLNX_FP_MAX_SEGS	24
18311e25f0dSDavid C Somayajulu 
18411e25f0dSDavid C Somayajulu struct qlnx_fastpath {
18511e25f0dSDavid C Somayajulu         void			*edev;
18611e25f0dSDavid C Somayajulu         uint8_t			rss_id;
18711e25f0dSDavid C Somayajulu         struct ecore_sb_info    *sb_info;
18811e25f0dSDavid C Somayajulu         struct qlnx_rx_queue    *rxq;
18911e25f0dSDavid C Somayajulu         struct qlnx_tx_queue    *txq[MAX_NUM_TC];
19011e25f0dSDavid C Somayajulu 	char			name[64];
19111e25f0dSDavid C Somayajulu 
19211e25f0dSDavid C Somayajulu 	struct mtx		tx_mtx;
19311e25f0dSDavid C Somayajulu 	char			tx_mtx_name[32];
19411e25f0dSDavid C Somayajulu 	struct buf_ring		*tx_br;
19577388ed2SDavid C Somayajulu 	uint32_t		tx_ring_full;
19611e25f0dSDavid C Somayajulu 
19711e25f0dSDavid C Somayajulu 	struct task		fp_task;
19811e25f0dSDavid C Somayajulu 	struct taskqueue	*fp_taskqueue;
19911e25f0dSDavid C Somayajulu 
20011e25f0dSDavid C Somayajulu 	/* transmit statistics */
20111e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_processed;
20211e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_freed;
20311e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_transmitted;
20411e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts_completed;
205*45f13123SDavid C Somayajulu 	uint64_t		tx_tso_pkts;
206*45f13123SDavid C Somayajulu 	uint64_t		tx_non_tso_pkts;
207*45f13123SDavid C Somayajulu 
208*45f13123SDavid C Somayajulu #ifdef QLNX_TRACE_PERF_DATA
209*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_trans_ctx;
210*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_compl_ctx;
211*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_trans_fp;
212*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_compl_fp;
213*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_compl_intr;
214*45f13123SDavid C Somayajulu #endif
215*45f13123SDavid C Somayajulu 
21611e25f0dSDavid C Somayajulu 	uint64_t		tx_lso_wnd_min_len;
21711e25f0dSDavid C Somayajulu 	uint64_t		tx_defrag;
21811e25f0dSDavid C Somayajulu 	uint64_t		tx_nsegs_gt_elem_left;
21911e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_max_nsegs;
22011e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_min_nsegs;
22111e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_max_pkt_len;
22211e25f0dSDavid C Somayajulu 	uint32_t		tx_tso_min_pkt_len;
22311e25f0dSDavid C Somayajulu 	uint64_t		tx_pkts[QLNX_FP_MAX_SEGS];
224*45f13123SDavid C Somayajulu 
225*45f13123SDavid C Somayajulu #ifdef QLNX_TRACE_PERF_DATA
226*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_hist[QLNX_FP_MAX_SEGS];
227*45f13123SDavid C Somayajulu 	uint64_t		tx_comInt[QLNX_FP_MAX_SEGS];
228*45f13123SDavid C Somayajulu 	uint64_t		tx_pkts_q[QLNX_FP_MAX_SEGS];
229*45f13123SDavid C Somayajulu #endif
230*45f13123SDavid C Somayajulu 
23111e25f0dSDavid C Somayajulu 	uint64_t		err_tx_nsegs_gt_elem_left;
23211e25f0dSDavid C Somayajulu         uint64_t                err_tx_dmamap_create;
23311e25f0dSDavid C Somayajulu         uint64_t                err_tx_defrag_dmamap_load;
23411e25f0dSDavid C Somayajulu         uint64_t                err_tx_non_tso_max_seg;
23511e25f0dSDavid C Somayajulu         uint64_t                err_tx_dmamap_load;
23611e25f0dSDavid C Somayajulu         uint64_t                err_tx_defrag;
23711e25f0dSDavid C Somayajulu         uint64_t                err_tx_free_pkt_null;
23811e25f0dSDavid C Somayajulu         uint64_t                err_tx_cons_idx_conflict;
23911e25f0dSDavid C Somayajulu 
24011e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_64;
24111e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_128;
24211e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_256;
24311e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_512;
24411e25f0dSDavid C Somayajulu         uint64_t                lro_cnt_1024;
24511e25f0dSDavid C Somayajulu 
24611e25f0dSDavid C Somayajulu 	/* receive statistics */
24711e25f0dSDavid C Somayajulu 	uint64_t		rx_pkts;
24811e25f0dSDavid C Somayajulu 	uint64_t		tpa_start;
24911e25f0dSDavid C Somayajulu 	uint64_t		tpa_cont;
25011e25f0dSDavid C Somayajulu 	uint64_t		tpa_end;
25111e25f0dSDavid C Somayajulu         uint64_t                err_m_getcl;
25211e25f0dSDavid C Somayajulu         uint64_t                err_m_getjcl;
25311e25f0dSDavid C Somayajulu         uint64_t		err_rx_hw_errors;
25411e25f0dSDavid C Somayajulu         uint64_t		err_rx_alloc_errors;
25511e25f0dSDavid C Somayajulu 	uint64_t		err_rx_jumbo_chain_pkts;
25611e25f0dSDavid C Somayajulu 	uint64_t		err_rx_mp_null;
25711e25f0dSDavid C Somayajulu 	uint64_t		err_rx_tpa_invalid_agg_num;
25811e25f0dSDavid C Somayajulu };
25911e25f0dSDavid C Somayajulu 
26011e25f0dSDavid C Somayajulu struct qlnx_update_vport_params {
26111e25f0dSDavid C Somayajulu         uint8_t			vport_id;
26211e25f0dSDavid C Somayajulu         uint8_t			update_vport_active_rx_flg;
26311e25f0dSDavid C Somayajulu         uint8_t			vport_active_rx_flg;
26411e25f0dSDavid C Somayajulu         uint8_t			update_vport_active_tx_flg;
26511e25f0dSDavid C Somayajulu         uint8_t			vport_active_tx_flg;
26611e25f0dSDavid C Somayajulu         uint8_t			update_inner_vlan_removal_flg;
26711e25f0dSDavid C Somayajulu         uint8_t			inner_vlan_removal_flg;
26811e25f0dSDavid C Somayajulu         struct ecore_rss_params	*rss_params;
26911e25f0dSDavid C Somayajulu 	struct ecore_sge_tpa_params *sge_tpa_params;
27011e25f0dSDavid C Somayajulu };
27111e25f0dSDavid C Somayajulu 
27211e25f0dSDavid C Somayajulu /*
27311e25f0dSDavid C Somayajulu  * link related
27411e25f0dSDavid C Somayajulu  */
27511e25f0dSDavid C Somayajulu struct qlnx_link_output {
27611e25f0dSDavid C Somayajulu 	bool		link_up;
27711e25f0dSDavid C Somayajulu 	uint32_t	supported_caps;
27811e25f0dSDavid C Somayajulu 	uint32_t	advertised_caps;
27911e25f0dSDavid C Somayajulu 	uint32_t	link_partner_caps;
28011e25f0dSDavid C Somayajulu 	uint32_t	speed; /* In Mb/s */
28111e25f0dSDavid C Somayajulu 	bool		autoneg;
28211e25f0dSDavid C Somayajulu 	uint32_t	media_type;
28311e25f0dSDavid C Somayajulu 	uint32_t	duplex;
28411e25f0dSDavid C Somayajulu };
28511e25f0dSDavid C Somayajulu typedef struct qlnx_link_output qlnx_link_output_t;
28611e25f0dSDavid C Somayajulu 
28711e25f0dSDavid C Somayajulu #define QLNX_LINK_DUPLEX			0x0001
28811e25f0dSDavid C Somayajulu 
28911e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_FIBRE			0x0001
29011e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_Autoneg			0x0002
29111e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_Pause			0x0004
29211e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_Asym_Pause		0x0008
29311e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_1000baseT_Half		0x0010
29411e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_1000baseT_Full		0x0020
29511e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_10000baseKR_Full		0x0040
29611e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_25000baseKR_Full		0x0080
29711e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_40000baseLR4_Full		0x0100
29811e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_50000baseKR2_Full		0x0200
29911e25f0dSDavid C Somayajulu #define QLNX_LINK_CAP_100000baseKR4_Full	0x0400
30011e25f0dSDavid C Somayajulu 
30111e25f0dSDavid C Somayajulu 
30211e25f0dSDavid C Somayajulu /* Functions definition */
30311e25f0dSDavid C Somayajulu 
30411e25f0dSDavid C Somayajulu #define XMIT_PLAIN              0
30511e25f0dSDavid C Somayajulu #define XMIT_L4_CSUM            (1 << 0)
30611e25f0dSDavid C Somayajulu #define XMIT_LSO                (1 << 1)
30711e25f0dSDavid C Somayajulu 
30811e25f0dSDavid C Somayajulu #define CQE_FLAGS_ERR   (PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<       \
30911e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT |       \
31011e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<     \
31111e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT |     \
31211e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_MASK << \
31311e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_SHIFT | \
31411e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_MASK << \
31511e25f0dSDavid C Somayajulu                          PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_SHIFT)
31611e25f0dSDavid C Somayajulu 
31711e25f0dSDavid C Somayajulu #define RX_COPY_THRESH          92
31811e25f0dSDavid C Somayajulu #define ETH_MAX_PACKET_SIZE     1500
31911e25f0dSDavid C Somayajulu 
32011e25f0dSDavid C Somayajulu #define QLNX_MFW_VERSION_LENGTH 32
32111e25f0dSDavid C Somayajulu #define QLNX_STORMFW_VERSION_LENGTH 32
32211e25f0dSDavid C Somayajulu 
32311e25f0dSDavid C Somayajulu #define QLNX_TX_ELEM_RESERVE		2
324*45f13123SDavid C Somayajulu #define QLNX_TX_ELEM_THRESH		128
325*45f13123SDavid C Somayajulu #define QLNX_TX_ELEM_MAX_THRESH		512
326*45f13123SDavid C Somayajulu #define QLNX_TX_ELEM_MIN_THRESH		32
327*45f13123SDavid C Somayajulu #define QLNX_TX_COMPL_THRESH		32
328*45f13123SDavid C Somayajulu 
32911e25f0dSDavid C Somayajulu 
33011e25f0dSDavid C Somayajulu #define QLNX_TPA_MAX_AGG_BUFFERS             (20)
33111e25f0dSDavid C Somayajulu 
33211e25f0dSDavid C Somayajulu #define QLNX_MAX_NUM_MULTICAST_ADDRS	ECORE_MAX_MC_ADDRS
33311e25f0dSDavid C Somayajulu typedef struct _qlnx_mcast {
33411e25f0dSDavid C Somayajulu         uint16_t        rsrvd;
33511e25f0dSDavid C Somayajulu         uint8_t         addr[6];
33611e25f0dSDavid C Somayajulu } __packed qlnx_mcast_t;
33711e25f0dSDavid C Somayajulu 
33811e25f0dSDavid C Somayajulu /*
33911e25f0dSDavid C Somayajulu  * Adapter structure contains the hardware independent information of the
34011e25f0dSDavid C Somayajulu  * pci function.
34111e25f0dSDavid C Somayajulu  */
34211e25f0dSDavid C Somayajulu struct qlnx_host {
34311e25f0dSDavid C Somayajulu 
34411e25f0dSDavid C Somayajulu 	/* interface to ecore */
34511e25f0dSDavid C Somayajulu 
34611e25f0dSDavid C Somayajulu 	struct ecore_dev	cdev;
34711e25f0dSDavid C Somayajulu 
34811e25f0dSDavid C Somayajulu 	uint32_t		state;
34911e25f0dSDavid C Somayajulu 
35011e25f0dSDavid C Somayajulu 	/* some flags */
35111e25f0dSDavid C Somayajulu         volatile struct {
35211e25f0dSDavid C Somayajulu                 volatile uint32_t
35311e25f0dSDavid C Somayajulu 			callout_init		:1,
35411e25f0dSDavid C Somayajulu                         slowpath_start		:1,
35511e25f0dSDavid C Somayajulu                         parent_tag		:1,
35611e25f0dSDavid C Somayajulu                         lock_init		:1;
35711e25f0dSDavid C Somayajulu         } flags;
35811e25f0dSDavid C Somayajulu 
35911e25f0dSDavid C Somayajulu 	/* interface to o.s */
36011e25f0dSDavid C Somayajulu 
36111e25f0dSDavid C Somayajulu 	device_t		pci_dev;
36211e25f0dSDavid C Somayajulu 	uint8_t			pci_func;
36311e25f0dSDavid C Somayajulu 	uint8_t			dev_unit;
36411e25f0dSDavid C Somayajulu 
36511e25f0dSDavid C Somayajulu 	struct ifnet		*ifp;
36611e25f0dSDavid C Somayajulu 	int			if_flags;
36711e25f0dSDavid C Somayajulu 	volatile int		link_up;
36811e25f0dSDavid C Somayajulu 	struct ifmedia		media;
36911e25f0dSDavid C Somayajulu 	uint16_t		max_frame_size;
37011e25f0dSDavid C Somayajulu 
37111e25f0dSDavid C Somayajulu 	struct cdev		*ioctl_dev;
37211e25f0dSDavid C Somayajulu 
37311e25f0dSDavid C Somayajulu 	/* resources */
37411e25f0dSDavid C Somayajulu         struct resource         *pci_reg;
37511e25f0dSDavid C Somayajulu         int                     reg_rid;
37611e25f0dSDavid C Somayajulu 
37711e25f0dSDavid C Somayajulu         struct resource         *pci_dbells;
37811e25f0dSDavid C Somayajulu         int                     dbells_rid;
37911e25f0dSDavid C Somayajulu 	uint64_t		dbells_phys_addr;
38011e25f0dSDavid C Somayajulu 	uint32_t		dbells_size;
38111e25f0dSDavid C Somayajulu 
38211e25f0dSDavid C Somayajulu         struct resource         *msix_bar;
38311e25f0dSDavid C Somayajulu         int                     msix_rid;
38411e25f0dSDavid C Somayajulu 
38511e25f0dSDavid C Somayajulu 	int			msix_count;
38611e25f0dSDavid C Somayajulu 
38711e25f0dSDavid C Somayajulu 	struct mtx		hw_lock;
38811e25f0dSDavid C Somayajulu 
38911e25f0dSDavid C Somayajulu 	/* debug */
39011e25f0dSDavid C Somayajulu 
39111e25f0dSDavid C Somayajulu 	uint32_t                dbg_level;
39277388ed2SDavid C Somayajulu 	uint32_t                dbg_trace_lro_cnt;
39377388ed2SDavid C Somayajulu 	uint32_t                dbg_trace_tso_pkt_len;
39411e25f0dSDavid C Somayajulu 	uint32_t                dp_level;
39511e25f0dSDavid C Somayajulu 	uint32_t                dp_module;
39611e25f0dSDavid C Somayajulu 
39711e25f0dSDavid C Somayajulu 	/* misc */
39811e25f0dSDavid C Somayajulu 	uint8_t 		mfw_ver[QLNX_MFW_VERSION_LENGTH];
39911e25f0dSDavid C Somayajulu 	uint8_t 		stormfw_ver[QLNX_STORMFW_VERSION_LENGTH];
40011e25f0dSDavid C Somayajulu 	uint32_t		flash_size;
40111e25f0dSDavid C Somayajulu 
40211e25f0dSDavid C Somayajulu 	/* dma related */
40311e25f0dSDavid C Somayajulu 
40411e25f0dSDavid C Somayajulu 	bus_dma_tag_t		parent_tag;
40511e25f0dSDavid C Somayajulu 	bus_dma_tag_t		tx_tag;
40611e25f0dSDavid C Somayajulu 	bus_dma_tag_t		rx_tag;
40711e25f0dSDavid C Somayajulu 
40811e25f0dSDavid C Somayajulu 
40911e25f0dSDavid C Somayajulu         struct ecore_sb_info    sb_array[QLNX_MAX_RSS];
41011e25f0dSDavid C Somayajulu         struct qlnx_rx_queue    rxq_array[QLNX_MAX_RSS];
41111e25f0dSDavid C Somayajulu         struct qlnx_tx_queue    txq_array[(QLNX_MAX_RSS * MAX_NUM_TC)];
41211e25f0dSDavid C Somayajulu         struct qlnx_fastpath    fp_array[QLNX_MAX_RSS];
41311e25f0dSDavid C Somayajulu 
41411e25f0dSDavid C Somayajulu 	/* tx related */
41511e25f0dSDavid C Somayajulu 	struct callout		tx_callout;
41611e25f0dSDavid C Somayajulu 	uint32_t		txr_idx;
41711e25f0dSDavid C Somayajulu 
41811e25f0dSDavid C Somayajulu 	/* rx related */
41911e25f0dSDavid C Somayajulu 	uint32_t		rx_pkt_threshold;
42011e25f0dSDavid C Somayajulu 	uint32_t		rx_jumbo_buf_eq_mtu;
42111e25f0dSDavid C Somayajulu 
42211e25f0dSDavid C Somayajulu 	/* slow path related */
42311e25f0dSDavid C Somayajulu         struct resource         *sp_irq[MAX_HWFNS_PER_DEVICE];
42411e25f0dSDavid C Somayajulu         void                    *sp_handle[MAX_HWFNS_PER_DEVICE];
42511e25f0dSDavid C Somayajulu         int                     sp_irq_rid[MAX_HWFNS_PER_DEVICE];
42611e25f0dSDavid C Somayajulu 	struct task		sp_task[MAX_HWFNS_PER_DEVICE];
42711e25f0dSDavid C Somayajulu 	struct taskqueue	*sp_taskqueue[MAX_HWFNS_PER_DEVICE];
42811e25f0dSDavid C Somayajulu 
42911e25f0dSDavid C Somayajulu 	struct callout          qlnx_callout;
43011e25f0dSDavid C Somayajulu 
43111e25f0dSDavid C Somayajulu 	/* fast path related */
43211e25f0dSDavid C Somayajulu 	int			num_rss;
43311e25f0dSDavid C Somayajulu 	int			num_tc;
43411e25f0dSDavid C Somayajulu 
43511e25f0dSDavid C Somayajulu #define QLNX_MAX_TSS_CNT(ha)	((ha->num_rss) * (ha->num_tc))
43611e25f0dSDavid C Somayajulu 
43711e25f0dSDavid C Somayajulu 	qlnx_ivec_t              irq_vec[QLNX_MAX_RSS];
43811e25f0dSDavid C Somayajulu 
43911e25f0dSDavid C Somayajulu 
44011e25f0dSDavid C Somayajulu 	uint8_t			filter;
44111e25f0dSDavid C Somayajulu 	uint32_t                nmcast;
44211e25f0dSDavid C Somayajulu 	qlnx_mcast_t            mcast[QLNX_MAX_NUM_MULTICAST_ADDRS];
44311e25f0dSDavid C Somayajulu 	struct ecore_filter_mcast ecore_mcast;
44411e25f0dSDavid C Somayajulu 	uint8_t			primary_mac[ETH_ALEN];
44511e25f0dSDavid C Somayajulu 	uint8_t			prio_to_tc[MAX_NUM_PRI];
44611e25f0dSDavid C Somayajulu 	struct ecore_eth_stats	hw_stats;
44711e25f0dSDavid C Somayajulu 	struct ecore_rss_params	rss_params;
44811e25f0dSDavid C Somayajulu         uint32_t		rx_buf_size;
44911e25f0dSDavid C Somayajulu         bool			rx_csum_offload;
45011e25f0dSDavid C Somayajulu 
45111e25f0dSDavid C Somayajulu 	uint32_t		rx_coalesce_usecs;
45211e25f0dSDavid C Somayajulu 	uint32_t		tx_coalesce_usecs;
45311e25f0dSDavid C Somayajulu 
45411e25f0dSDavid C Somayajulu 	/* link related */
45511e25f0dSDavid C Somayajulu 	qlnx_link_output_t	if_link;
45611e25f0dSDavid C Somayajulu 
45711e25f0dSDavid C Somayajulu 	/* global counters */
45811e25f0dSDavid C Somayajulu 	uint64_t		sp_interrupts;
45911e25f0dSDavid C Somayajulu 	uint64_t		err_illegal_intr;
46011e25f0dSDavid C Somayajulu 	uint64_t		err_fp_null;
46111e25f0dSDavid C Somayajulu 	uint64_t		err_get_proto_invalid_type;
46211e25f0dSDavid C Somayajulu 
46311e25f0dSDavid C Somayajulu 	/* grcdump related */
46411e25f0dSDavid C Somayajulu 	uint32_t		err_inject;
46511e25f0dSDavid C Somayajulu 	uint32_t		grcdump_taken;
46611e25f0dSDavid C Somayajulu 	uint32_t		grcdump_dwords[QLNX_MAX_HW_FUNCS];
46711e25f0dSDavid C Somayajulu 	uint32_t		grcdump_size[QLNX_MAX_HW_FUNCS];
46811e25f0dSDavid C Somayajulu 	void			*grcdump[QLNX_MAX_HW_FUNCS];
46911e25f0dSDavid C Somayajulu 
47011e25f0dSDavid C Somayajulu 	uint32_t		idle_chk_taken;
47111e25f0dSDavid C Somayajulu 	uint32_t		idle_chk_dwords[QLNX_MAX_HW_FUNCS];
47211e25f0dSDavid C Somayajulu 	uint32_t		idle_chk_size[QLNX_MAX_HW_FUNCS];
47311e25f0dSDavid C Somayajulu 	void			*idle_chk[QLNX_MAX_HW_FUNCS];
47411e25f0dSDavid C Somayajulu 
47511e25f0dSDavid C Somayajulu 	/* storm stats related */
47611e25f0dSDavid C Somayajulu #define QLNX_STORM_STATS_TOTAL \
47711e25f0dSDavid C Somayajulu 		(QLNX_MAX_HW_FUNCS * QLNX_STORM_STATS_SAMPLES_PER_HWFN)
47811e25f0dSDavid C Somayajulu 	qlnx_storm_stats_t	storm_stats[QLNX_STORM_STATS_TOTAL];
47911e25f0dSDavid C Somayajulu 	uint32_t		storm_stats_index;
48011e25f0dSDavid C Somayajulu 	uint32_t		storm_stats_enable;
481*45f13123SDavid C Somayajulu 	uint32_t		storm_stats_gather;
48211e25f0dSDavid C Somayajulu 
48311e25f0dSDavid C Somayajulu 	uint32_t		personality;
48411e25f0dSDavid C Somayajulu };
48511e25f0dSDavid C Somayajulu 
48611e25f0dSDavid C Somayajulu typedef struct qlnx_host qlnx_host_t;
48711e25f0dSDavid C Somayajulu 
48811e25f0dSDavid C Somayajulu /* note that align has to be a power of 2 */
48911e25f0dSDavid C Somayajulu #define QL_ALIGN(size, align) (size + (align - 1)) & ~(align - 1);
49011e25f0dSDavid C Somayajulu #define QL_MIN(x, y) ((x < y) ? x : y)
49111e25f0dSDavid C Somayajulu 
49211e25f0dSDavid C Somayajulu #define QL_RUNNING(ifp) \
49311e25f0dSDavid C Somayajulu 		((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) == \
49411e25f0dSDavid C Somayajulu 			IFF_DRV_RUNNING)
49511e25f0dSDavid C Somayajulu 
49611e25f0dSDavid C Somayajulu #define QLNX_MAX_MTU			9000
49711e25f0dSDavid C Somayajulu #define QLNX_MAX_SEGMENTS_NON_TSO	(ETH_TX_MAX_BDS_PER_NON_LSO_PACKET - 1)
498*45f13123SDavid C Somayajulu //#define QLNX_MAX_TSO_FRAME_SIZE		((64 * 1024 - 1) + 22)
499*45f13123SDavid C Somayajulu #define QLNX_MAX_TSO_FRAME_SIZE		65536
500*45f13123SDavid C Somayajulu #define QLNX_MAX_TX_MBUF_SIZE		65536    /* bytes - bd_len = 16bits */
501*45f13123SDavid C Somayajulu 
50211e25f0dSDavid C Somayajulu 
50311e25f0dSDavid C Somayajulu #define QL_MAC_CMP(mac1, mac2)    \
50411e25f0dSDavid C Somayajulu         ((((*(uint32_t *) mac1) == (*(uint32_t *) mac2) && \
50511e25f0dSDavid C Somayajulu         (*(uint16_t *)(mac1 + 4)) == (*(uint16_t *)(mac2 + 4)))) ? 0 : 1)
50611e25f0dSDavid C Somayajulu #define for_each_rss(i) for (i = 0; i < ha->num_rss; i++)
50711e25f0dSDavid C Somayajulu 
50811e25f0dSDavid C Somayajulu /*
50911e25f0dSDavid C Somayajulu  * Debug Related
51011e25f0dSDavid C Somayajulu  */
51111e25f0dSDavid C Somayajulu 
51211e25f0dSDavid C Somayajulu #ifdef QLNX_DEBUG
51311e25f0dSDavid C Somayajulu 
5147a377fbeSDavid C Somayajulu #define QL_DPRINT1(ha, x, ...) 					\
5157a377fbeSDavid C Somayajulu 	do { 							\
5167a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0001) {			\
5177a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5187a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5197a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5207a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5217a377fbeSDavid C Somayajulu 		}						\
5227a377fbeSDavid C Somayajulu 	} while (0)
5237a377fbeSDavid C Somayajulu 
5247a377fbeSDavid C Somayajulu #define QL_DPRINT2(ha, x, ...)					\
5257a377fbeSDavid C Somayajulu 	do { 							\
5267a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0002) {			\
5277a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5287a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5297a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5307a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5317a377fbeSDavid C Somayajulu 		}						\
5327a377fbeSDavid C Somayajulu 	} while (0)
5337a377fbeSDavid C Somayajulu 
5347a377fbeSDavid C Somayajulu #define QL_DPRINT3(ha, x, ...)					\
5357a377fbeSDavid C Somayajulu 	do { 							\
5367a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0004) {			\
5377a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5387a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5397a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5407a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5417a377fbeSDavid C Somayajulu 		}						\
5427a377fbeSDavid C Somayajulu 	} while (0)
5437a377fbeSDavid C Somayajulu 
5447a377fbeSDavid C Somayajulu #define QL_DPRINT4(ha, x, ...)					\
5457a377fbeSDavid C Somayajulu 	do { 							\
5467a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0008) {			\
5477a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5487a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5497a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5507a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5517a377fbeSDavid C Somayajulu 		}						\
5527a377fbeSDavid C Somayajulu 	} while (0)
5537a377fbeSDavid C Somayajulu 
5547a377fbeSDavid C Somayajulu #define QL_DPRINT5(ha, x, ...)					\
5557a377fbeSDavid C Somayajulu 	do { 							\
5567a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0010) {			\
5577a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5587a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5597a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5607a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5617a377fbeSDavid C Somayajulu 		}						\
5627a377fbeSDavid C Somayajulu 	} while (0)
5637a377fbeSDavid C Somayajulu 
5647a377fbeSDavid C Somayajulu #define QL_DPRINT6(ha, x, ...)					\
5657a377fbeSDavid C Somayajulu 	do { 							\
5667a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0020) {			\
5677a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5687a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5697a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5707a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5717a377fbeSDavid C Somayajulu 		}						\
5727a377fbeSDavid C Somayajulu 	} while (0)
5737a377fbeSDavid C Somayajulu 
5747a377fbeSDavid C Somayajulu #define QL_DPRINT7(ha, x, ...)					\
5757a377fbeSDavid C Somayajulu 	do { 							\
5767a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0040) {			\
5777a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5787a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5797a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5807a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5817a377fbeSDavid C Somayajulu 		}						\
5827a377fbeSDavid C Somayajulu 	} while (0)
5837a377fbeSDavid C Somayajulu 
5847a377fbeSDavid C Somayajulu #define QL_DPRINT8(ha, x, ...)					\
5857a377fbeSDavid C Somayajulu 	do { 							\
5867a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0080) {			\
5877a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5887a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5897a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
5907a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
5917a377fbeSDavid C Somayajulu 		}						\
5927a377fbeSDavid C Somayajulu 	} while (0)
5937a377fbeSDavid C Somayajulu 
5947a377fbeSDavid C Somayajulu #define QL_DPRINT9(ha, x, ...)					\
5957a377fbeSDavid C Somayajulu 	do { 							\
5967a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0100) {			\
5977a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
5987a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
5997a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6007a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6017a377fbeSDavid C Somayajulu 		}						\
6027a377fbeSDavid C Somayajulu 	} while (0)
6037a377fbeSDavid C Somayajulu 
6047a377fbeSDavid C Somayajulu #define QL_DPRINT11(ha, x, ...)					\
6057a377fbeSDavid C Somayajulu 	do { 							\
6067a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0400) {			\
6077a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6087a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6097a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6107a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6117a377fbeSDavid C Somayajulu 		}						\
6127a377fbeSDavid C Somayajulu 	} while (0)
6137a377fbeSDavid C Somayajulu 
6147a377fbeSDavid C Somayajulu #define QL_DPRINT12(ha, x, ...)					\
6157a377fbeSDavid C Somayajulu 	do { 							\
6167a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x0800) {			\
6177a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6187a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6197a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6207a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6217a377fbeSDavid C Somayajulu 		}						\
6227a377fbeSDavid C Somayajulu 	} while (0)
6237a377fbeSDavid C Somayajulu 
6247a377fbeSDavid C Somayajulu #define QL_DPRINT13(ha, x, ...)					\
6257a377fbeSDavid C Somayajulu 	do { 							\
6267a377fbeSDavid C Somayajulu 		if ((ha)->dbg_level & 0x1000) {			\
6277a377fbeSDavid C Somayajulu 			device_printf ((ha)->pci_dev,		\
6287a377fbeSDavid C Somayajulu 				"[%s:%d]" x,			\
6297a377fbeSDavid C Somayajulu 				__func__, __LINE__,		\
6307a377fbeSDavid C Somayajulu 				## __VA_ARGS__);		\
6317a377fbeSDavid C Somayajulu 		}						\
6327a377fbeSDavid C Somayajulu 	} while (0)
6337a377fbeSDavid C Somayajulu 
63411e25f0dSDavid C Somayajulu 
63511e25f0dSDavid C Somayajulu #else
63611e25f0dSDavid C Somayajulu 
6377a377fbeSDavid C Somayajulu #define QL_DPRINT1(ha, x, ...)
6387a377fbeSDavid C Somayajulu #define QL_DPRINT2(ha, x, ...)
6397a377fbeSDavid C Somayajulu #define QL_DPRINT3(ha, x, ...)
6407a377fbeSDavid C Somayajulu #define QL_DPRINT4(ha, x, ...)
6417a377fbeSDavid C Somayajulu #define QL_DPRINT5(ha, x, ...)
6427a377fbeSDavid C Somayajulu #define QL_DPRINT6(ha, x, ...)
6437a377fbeSDavid C Somayajulu #define QL_DPRINT7(ha, x, ...)
6447a377fbeSDavid C Somayajulu #define QL_DPRINT8(ha, x, ...)
6457a377fbeSDavid C Somayajulu #define QL_DPRINT9(ha, x, ...)
6467a377fbeSDavid C Somayajulu #define QL_DPRINT11(ha, x, ...)
6477a377fbeSDavid C Somayajulu #define QL_DPRINT12(ha, x, ...)
6487a377fbeSDavid C Somayajulu #define QL_DPRINT13(ha, x, ...)
64911e25f0dSDavid C Somayajulu 
65011e25f0dSDavid C Somayajulu #endif /* #ifdef QLNX_DEBUG */
65111e25f0dSDavid C Somayajulu 
65211e25f0dSDavid C Somayajulu #define QL_ASSERT(ha, x, y)     if (!x) panic y
65311e25f0dSDavid C Somayajulu 
65411e25f0dSDavid C Somayajulu #define QL_ERR_INJECT(ha, val)		(ha->err_inject == val)
65511e25f0dSDavid C Somayajulu #define QL_RESET_ERR_INJECT(ha, val)	{if (ha->err_inject == val) ha->err_inject = 0;}
65611e25f0dSDavid C Somayajulu #define QL_ERR_INJCT_TX_INT_DIFF	0x0001
65711e25f0dSDavid C Somayajulu #define QL_ERR_INJCT_TX_INT_MBUF_NULL	0x0002
65811e25f0dSDavid C Somayajulu 
65911e25f0dSDavid C Somayajulu 
66011e25f0dSDavid C Somayajulu /*
66111e25f0dSDavid C Somayajulu  * exported functions
66211e25f0dSDavid C Somayajulu  */
66311e25f0dSDavid C Somayajulu extern int qlnx_make_cdev(qlnx_host_t *ha);
66411e25f0dSDavid C Somayajulu extern void qlnx_del_cdev(qlnx_host_t *ha);
66511e25f0dSDavid C Somayajulu extern int qlnx_grc_dump(qlnx_host_t *ha, uint32_t *num_dumped_dwords,
66611e25f0dSDavid C Somayajulu 		int hwfn_index);
66711e25f0dSDavid C Somayajulu extern int qlnx_idle_chk(qlnx_host_t *ha, uint32_t *num_dumped_dwords,
66811e25f0dSDavid C Somayajulu 		int hwfn_index);
66911e25f0dSDavid C Somayajulu extern uint8_t *qlnx_get_mac_addr(qlnx_host_t *ha);
67011e25f0dSDavid C Somayajulu extern void qlnx_fill_link(struct ecore_hwfn *hwfn,
67111e25f0dSDavid C Somayajulu                           struct qlnx_link_output *if_link);
67211e25f0dSDavid C Somayajulu 
67311e25f0dSDavid C Somayajulu /*
67411e25f0dSDavid C Somayajulu  * Some OS specific stuff
67511e25f0dSDavid C Somayajulu  */
67611e25f0dSDavid C Somayajulu 
67711e25f0dSDavid C Somayajulu #if (defined IFM_100G_SR4)
67811e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_SR4 IFM_100G_SR4
67911e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_LR4 IFM_100G_LR4
68011e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_CR4 IFM_100G_CR4
68111e25f0dSDavid C Somayajulu #else
68211e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_SR4 IFM_UNKNOWN
68311e25f0dSDavid C Somayajulu #define QLNX_IFM_100G_LR4 IFM_UNKNOWN
68411e25f0dSDavid C Somayajulu #endif
68511e25f0dSDavid C Somayajulu 
68611e25f0dSDavid C Somayajulu #if (defined IFM_25G_SR)
68711e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_SR IFM_25G_SR
68811e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_CR IFM_25G_CR
68911e25f0dSDavid C Somayajulu #else
69011e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_SR IFM_UNKNOWN
69111e25f0dSDavid C Somayajulu #define QLNX_IFM_25G_CR IFM_UNKNOWN
69211e25f0dSDavid C Somayajulu #endif
69311e25f0dSDavid C Somayajulu 
69411e25f0dSDavid C Somayajulu 
69511e25f0dSDavid C Somayajulu #if __FreeBSD_version < 1100000
69611e25f0dSDavid C Somayajulu 
69711e25f0dSDavid C Somayajulu #define QLNX_INC_IERRORS(ifp)		ifp->if_ierrors++
69811e25f0dSDavid C Somayajulu #define QLNX_INC_IQDROPS(ifp)		ifp->if_iqdrops++
69911e25f0dSDavid C Somayajulu #define QLNX_INC_IPACKETS(ifp)		ifp->if_ipackets++
70011e25f0dSDavid C Somayajulu #define QLNX_INC_OPACKETS(ifp)		ifp->if_opackets++
70111e25f0dSDavid C Somayajulu #define QLNX_INC_OBYTES(ifp, len)	ifp->if_obytes += len
70211e25f0dSDavid C Somayajulu #define QLNX_INC_IBYTES(ifp, len)	ifp->if_ibytes += len
70311e25f0dSDavid C Somayajulu 
70411e25f0dSDavid C Somayajulu #else
70511e25f0dSDavid C Somayajulu 
70611e25f0dSDavid C Somayajulu #define QLNX_INC_IERRORS(ifp)	if_inc_counter(ifp, IFCOUNTER_IERRORS, 1)
70711e25f0dSDavid C Somayajulu #define QLNX_INC_IQDROPS(ifp)	if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1)
70811e25f0dSDavid C Somayajulu #define QLNX_INC_IPACKETS(ifp)	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1)
70911e25f0dSDavid C Somayajulu #define QLNX_INC_OPACKETS(ifp)	if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1)
71011e25f0dSDavid C Somayajulu 
71111e25f0dSDavid C Somayajulu #define QLNX_INC_OBYTES(ifp, len)	\
71211e25f0dSDavid C Somayajulu 			if_inc_counter(ifp, IFCOUNTER_OBYTES, len)
71311e25f0dSDavid C Somayajulu #define QLNX_INC_IBYTES(ifp, len)	\
71411e25f0dSDavid C Somayajulu 			if_inc_counter(ha->ifp, IFCOUNTER_IBYTES, len)
71511e25f0dSDavid C Somayajulu 
71611e25f0dSDavid C Somayajulu #endif /* #if __FreeBSD_version < 1100000 */
71711e25f0dSDavid C Somayajulu 
71811e25f0dSDavid C Somayajulu #define CQE_L3_PACKET(flags)    \
7199efd0ba7SDavid C Somayajulu         ((((flags) & PARSING_AND_ERR_FLAGS_L3TYPE_MASK) == e_l3_type_ipv4) || \
7209efd0ba7SDavid C Somayajulu         (((flags) & PARSING_AND_ERR_FLAGS_L3TYPE_MASK) == e_l3_type_ipv6))
72111e25f0dSDavid C Somayajulu 
72211e25f0dSDavid C Somayajulu #define CQE_IP_HDR_ERR(flags) \
72311e25f0dSDavid C Somayajulu         ((flags) & (PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK \
72411e25f0dSDavid C Somayajulu                 << PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT))
72511e25f0dSDavid C Somayajulu 
72611e25f0dSDavid C Somayajulu #define CQE_L4_HAS_CSUM(flags) \
72711e25f0dSDavid C Somayajulu         ((flags) & (PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK \
72811e25f0dSDavid C Somayajulu                 << PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT))
72911e25f0dSDavid C Somayajulu 
73011e25f0dSDavid C Somayajulu #define CQE_HAS_VLAN(flags) \
73111e25f0dSDavid C Somayajulu         ((flags) & (PARSING_AND_ERR_FLAGS_TAG8021QEXIST_MASK \
73211e25f0dSDavid C Somayajulu                 << PARSING_AND_ERR_FLAGS_TAG8021QEXIST_SHIFT))
73311e25f0dSDavid C Somayajulu 
734*45f13123SDavid C Somayajulu #if defined(__i386__) || defined(__amd64__)
735*45f13123SDavid C Somayajulu 
736*45f13123SDavid C Somayajulu static __inline
737*45f13123SDavid C Somayajulu void prefetch(void *x)
738*45f13123SDavid C Somayajulu {
739*45f13123SDavid C Somayajulu         __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
740*45f13123SDavid C Somayajulu }
741*45f13123SDavid C Somayajulu 
742*45f13123SDavid C Somayajulu #else
743*45f13123SDavid C Somayajulu #define prefetch(x)
744*45f13123SDavid C Somayajulu #endif
745*45f13123SDavid C Somayajulu 
74611e25f0dSDavid C Somayajulu 
74711e25f0dSDavid C Somayajulu #endif /* #ifndef _QLNX_DEF_H_ */
748