1acd884deSSumit Saxena /*
2acd884deSSumit Saxena * Copyright (c) 2015-2024, Broadcom. All rights reserved. The term
3acd884deSSumit Saxena * Broadcom refers to Broadcom Limited and/or its subsidiaries.
4acd884deSSumit Saxena *
5acd884deSSumit Saxena * Redistribution and use in source and binary forms, with or without
6acd884deSSumit Saxena * modification, are permitted provided that the following conditions
7acd884deSSumit Saxena * are met:
8acd884deSSumit Saxena *
9acd884deSSumit Saxena * 1. Redistributions of source code must retain the above copyright
10acd884deSSumit Saxena * notice, this list of conditions and the following disclaimer.
11acd884deSSumit Saxena * 2. Redistributions in binary form must reproduce the above copyright
12acd884deSSumit Saxena * notice, this list of conditions and the following disclaimer in
13acd884deSSumit Saxena * the documentation and/or other materials provided with the
14acd884deSSumit Saxena * distribution.
15acd884deSSumit Saxena *
16acd884deSSumit Saxena * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
17acd884deSSumit Saxena * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18acd884deSSumit Saxena * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19acd884deSSumit Saxena * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
20acd884deSSumit Saxena * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21acd884deSSumit Saxena * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22acd884deSSumit Saxena * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23acd884deSSumit Saxena * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24acd884deSSumit Saxena * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25acd884deSSumit Saxena * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26acd884deSSumit Saxena * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27acd884deSSumit Saxena *
28acd884deSSumit Saxena * Description: main (header)
29acd884deSSumit Saxena */
30acd884deSSumit Saxena
31acd884deSSumit Saxena #ifndef __BNXT_RE_H__
32acd884deSSumit Saxena #define __BNXT_RE_H__
33acd884deSSumit Saxena
34acd884deSSumit Saxena #include <linux/module.h>
35acd884deSSumit Saxena #include <linux/netdevice.h>
36acd884deSSumit Saxena #include <linux/mutex.h>
37acd884deSSumit Saxena #include <linux/list.h>
38acd884deSSumit Saxena #include <linux/rculist.h>
39acd884deSSumit Saxena #include <linux/spinlock.h>
40acd884deSSumit Saxena #include <net/ipv6.h>
41acd884deSSumit Saxena #include <linux/if_ether.h>
42acd884deSSumit Saxena #include <linux/debugfs.h>
43acd884deSSumit Saxena #include <linux/seq_file.h>
44acd884deSSumit Saxena #include <linux/interrupt.h>
45acd884deSSumit Saxena #include <linux/vmalloc.h>
46acd884deSSumit Saxena #include <linux/delay.h>
47acd884deSSumit Saxena #include <rdma/ib_verbs.h>
48acd884deSSumit Saxena #include <rdma/ib_user_verbs.h>
49acd884deSSumit Saxena #include <rdma/ib_umem.h>
50acd884deSSumit Saxena #include <rdma/ib_addr.h>
51acd884deSSumit Saxena #include <rdma/ib_mad.h>
52acd884deSSumit Saxena #include <rdma/ib_cache.h>
53acd884deSSumit Saxena #include <linux/pci.h>
54acd884deSSumit Saxena
55acd884deSSumit Saxena #include "bnxt.h"
56acd884deSSumit Saxena #include "bnxt_ulp.h"
57acd884deSSumit Saxena #include "hsi_struct_def.h"
58acd884deSSumit Saxena #include "qplib_res.h"
59acd884deSSumit Saxena #include "qplib_sp.h"
60acd884deSSumit Saxena #include "qplib_fp.h"
61acd884deSSumit Saxena #include "qplib_rcfw.h"
62acd884deSSumit Saxena #include "ib_verbs.h"
63acd884deSSumit Saxena #include "stats.h"
64acd884deSSumit Saxena
65acd884deSSumit Saxena #define ROCE_DRV_MODULE_NAME "bnxt_re"
66acd884deSSumit Saxena #define ROCE_DRV_MODULE_VERSION "230.0.133.0"
67acd884deSSumit Saxena #define ROCE_DRV_MODULE_RELDATE "April 22, 2024"
68acd884deSSumit Saxena
69acd884deSSumit Saxena #define BNXT_RE_REF_WAIT_COUNT 20
70acd884deSSumit Saxena #define BNXT_RE_ROCE_V1_ETH_TYPE 0x8915
71acd884deSSumit Saxena #define BNXT_RE_ROCE_V2_PORT_NO 4791
72acd884deSSumit Saxena #define BNXT_RE_RES_FREE_WAIT_COUNT 1000
73acd884deSSumit Saxena
74acd884deSSumit Saxena #define BNXT_RE_PAGE_SHIFT_4K (12)
75acd884deSSumit Saxena #define BNXT_RE_PAGE_SHIFT_8K (13)
76acd884deSSumit Saxena #define BNXT_RE_PAGE_SHIFT_64K (16)
77acd884deSSumit Saxena #define BNXT_RE_PAGE_SHIFT_2M (21)
78acd884deSSumit Saxena #define BNXT_RE_PAGE_SHIFT_8M (23)
79acd884deSSumit Saxena #define BNXT_RE_PAGE_SHIFT_1G (30)
80acd884deSSumit Saxena
81acd884deSSumit Saxena #define BNXT_RE_PAGE_SIZE_4K BIT(BNXT_RE_PAGE_SHIFT_4K)
82acd884deSSumit Saxena #define BNXT_RE_PAGE_SIZE_8K BIT(BNXT_RE_PAGE_SHIFT_8K)
83acd884deSSumit Saxena #define BNXT_RE_PAGE_SIZE_64K BIT(BNXT_RE_PAGE_SHIFT_64K)
84acd884deSSumit Saxena #define BNXT_RE_PAGE_SIZE_2M BIT(BNXT_RE_PAGE_SHIFT_2M)
85acd884deSSumit Saxena #define BNXT_RE_PAGE_SIZE_8M BIT(BNXT_RE_PAGE_SHIFT_8M)
86acd884deSSumit Saxena #define BNXT_RE_PAGE_SIZE_1G BIT(BNXT_RE_PAGE_SHIFT_1G)
87acd884deSSumit Saxena
88acd884deSSumit Saxena #define BNXT_RE_MAX_MR_SIZE_LOW BIT(BNXT_RE_PAGE_SHIFT_1G)
89acd884deSSumit Saxena #define BNXT_RE_MAX_MR_SIZE_HIGH BIT(39)
90acd884deSSumit Saxena #define BNXT_RE_MAX_MR_SIZE BNXT_RE_MAX_MR_SIZE_HIGH
91acd884deSSumit Saxena
92acd884deSSumit Saxena /* Number of MRs to reserve for PF, leaving remainder for VFs */
93acd884deSSumit Saxena #define BNXT_RE_RESVD_MR_FOR_PF (32 * 1024)
94acd884deSSumit Saxena #define BNXT_RE_MAX_GID_PER_VF 128
95acd884deSSumit Saxena
96acd884deSSumit Saxena #define BNXT_RE_MAX_VF_QPS_PER_PF (6 * 1024)
97acd884deSSumit Saxena
98acd884deSSumit Saxena /**
99acd884deSSumit Saxena * min_not_zero - return the minimum that is _not_ zero, unless both are zero
100acd884deSSumit Saxena * @x: value1
101acd884deSSumit Saxena * @y: value2
102acd884deSSumit Saxena */
10307c7c41cSVladimir Kondratyev #ifndef min_not_zero
104acd884deSSumit Saxena #define min_not_zero(x, y) ({ \
105acd884deSSumit Saxena typeof(x) __x = (x); \
106acd884deSSumit Saxena typeof(y) __y = (y); \
107acd884deSSumit Saxena __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
10807c7c41cSVladimir Kondratyev #endif
109acd884deSSumit Saxena
110acd884deSSumit Saxena struct ib_mr_init_attr {
111acd884deSSumit Saxena int max_reg_descriptors;
112acd884deSSumit Saxena u32 flags;
113acd884deSSumit Saxena };
114acd884deSSumit Saxena
115acd884deSSumit Saxena struct bnxt_re_dev;
116acd884deSSumit Saxena
117acd884deSSumit Saxena int bnxt_re_register_netdevice_notifier(struct notifier_block *nb);
118acd884deSSumit Saxena int bnxt_re_unregister_netdevice_notifier(struct notifier_block *nb);
119acd884deSSumit Saxena int ib_register_device_compat(struct bnxt_re_dev *rdev);
120acd884deSSumit Saxena
121acd884deSSumit Saxena #ifndef __struct_group
122acd884deSSumit Saxena #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
123acd884deSSumit Saxena union { \
124acd884deSSumit Saxena struct { MEMBERS } ATTRS; \
125acd884deSSumit Saxena struct TAG { MEMBERS } ATTRS NAME; \
126acd884deSSumit Saxena }
127acd884deSSumit Saxena #endif /* __struct_group */
128acd884deSSumit Saxena #ifndef struct_group_attr
129acd884deSSumit Saxena #define struct_group_attr(NAME, ATTRS, MEMBERS...) \
130acd884deSSumit Saxena __struct_group(/* no tag */, NAME, ATTRS, MEMBERS)
131acd884deSSumit Saxena #endif /* struct_group_attr */
132acd884deSSumit Saxena /*
133acd884deSSumit Saxena * Percentage of resources of each type reserved for PF.
134acd884deSSumit Saxena * Remaining resources are divided equally among VFs.
135acd884deSSumit Saxena * [0, 100]
136acd884deSSumit Saxena */
137acd884deSSumit Saxena
138acd884deSSumit Saxena #define BNXT_RE_RQ_WQE_THRESHOLD 32
139acd884deSSumit Saxena #define BNXT_RE_UD_QP_HW_STALL 0x400000
140acd884deSSumit Saxena
141acd884deSSumit Saxena /*
142acd884deSSumit Saxena * Setting the default ack delay value to 16, which means
143acd884deSSumit Saxena * the default timeout is approx. 260ms(4 usec * 2 ^(timeout))
144acd884deSSumit Saxena */
145acd884deSSumit Saxena
146acd884deSSumit Saxena #define BNXT_RE_DEFAULT_ACK_DELAY 16
147acd884deSSumit Saxena #define BNXT_RE_BOND_PF_MAX 2
148acd884deSSumit Saxena
149acd884deSSumit Saxena #define BNXT_RE_STATS_CTX_UPDATE_TIMER 250
150acd884deSSumit Saxena #define BNXT_RE_30SEC_MSEC (30 * 1000)
151acd884deSSumit Saxena
152acd884deSSumit Saxena #define BNXT_RE_BOND_RESCHED_CNT 10
153acd884deSSumit Saxena
154acd884deSSumit Saxena #define BNXT_RE_CHIP_NUM_57454 0xC454
155acd884deSSumit Saxena #define BNXT_RE_CHIP_NUM_57452 0xC452
156acd884deSSumit Saxena
157acd884deSSumit Saxena #define BNXT_RE_CHIP_NUM_5745X(chip_num) \
158acd884deSSumit Saxena ((chip_num) == BNXT_RE_CHIP_NUM_57454 || \
159acd884deSSumit Saxena (chip_num) == BNXT_RE_CHIP_NUM_57452)
160acd884deSSumit Saxena
161acd884deSSumit Saxena #define BNXT_RE_MIN_KERNEL_QP_TX_DEPTH 4096
162acd884deSSumit Saxena #define BNXT_RE_STOP_QPS_BUDGET 200
163acd884deSSumit Saxena
164acd884deSSumit Saxena #define BNXT_RE_HWRM_CMD_TIMEOUT(rdev) \
165acd884deSSumit Saxena ((rdev)->chip_ctx->hwrm_cmd_max_timeout * 1000)
166acd884deSSumit Saxena
167acd884deSSumit Saxena extern unsigned int min_tx_depth;
168acd884deSSumit Saxena extern struct mutex bnxt_re_dev_lock;
169acd884deSSumit Saxena extern struct mutex bnxt_re_mutex;
170acd884deSSumit Saxena extern struct list_head bnxt_re_dev_list;
171acd884deSSumit Saxena
172acd884deSSumit Saxena struct bnxt_re_ring_attr {
173acd884deSSumit Saxena dma_addr_t *dma_arr;
174acd884deSSumit Saxena int pages;
175acd884deSSumit Saxena int type;
176acd884deSSumit Saxena u32 depth;
177acd884deSSumit Saxena u32 lrid; /* Logical ring id */
178acd884deSSumit Saxena u16 flags;
179acd884deSSumit Saxena u8 mode;
180acd884deSSumit Saxena u8 rsvd;
181acd884deSSumit Saxena };
182acd884deSSumit Saxena
183acd884deSSumit Saxena #define BNXT_RE_MAX_DEVICES 256
184acd884deSSumit Saxena #define BNXT_RE_MSIX_FROM_MOD_PARAM -1
185acd884deSSumit Saxena #define BNXT_RE_MIN_MSIX 2
186acd884deSSumit Saxena #define BNXT_RE_MAX_MSIX_VF 2
187acd884deSSumit Saxena #define BNXT_RE_MAX_MSIX_PF 9
188acd884deSSumit Saxena #define BNXT_RE_MAX_MSIX_NPAR_PF 5
189acd884deSSumit Saxena #define BNXT_RE_MAX_MSIX 64
190acd884deSSumit Saxena #define BNXT_RE_MAX_MSIX_GEN_P5_PF BNXT_RE_MAX_MSIX
191acd884deSSumit Saxena #define BNXT_RE_GEN_P5_MAX_VF 64
192acd884deSSumit Saxena
193acd884deSSumit Saxena struct bnxt_re_nq_record {
194acd884deSSumit Saxena struct bnxt_msix_entry msix_entries[BNXT_RE_MAX_MSIX];
195acd884deSSumit Saxena /* FP Notification Queue (CQ & SRQ) */
196acd884deSSumit Saxena struct bnxt_qplib_nq nq[BNXT_RE_MAX_MSIX];
197acd884deSSumit Saxena int num_msix;
198acd884deSSumit Saxena int max_init;
199acd884deSSumit Saxena struct mutex load_lock;
200acd884deSSumit Saxena };
201acd884deSSumit Saxena
202acd884deSSumit Saxena struct bnxt_re_work {
203acd884deSSumit Saxena struct work_struct work;
204acd884deSSumit Saxena unsigned long event;
205acd884deSSumit Saxena struct bnxt_re_dev *rdev;
206acd884deSSumit Saxena struct ifnet *vlan_dev;
207acd884deSSumit Saxena bool do_lag;
208acd884deSSumit Saxena
209acd884deSSumit Saxena /* netdev where we received the event */
210acd884deSSumit Saxena struct ifnet *netdev;
211acd884deSSumit Saxena struct auxiliary_device *adev;
212acd884deSSumit Saxena };
213acd884deSSumit Saxena
214acd884deSSumit Saxena /*
215acd884deSSumit Saxena * Data structure and defines to handle
216acd884deSSumit Saxena * recovery
217acd884deSSumit Saxena */
218acd884deSSumit Saxena #define BNXT_RE_RECOVERY_IB_UNINIT_WAIT_RETRY 20
219acd884deSSumit Saxena #define BNXT_RE_RECOVERY_IB_UNINIT_WAIT_TIME_MS 30000 /* 30sec timeout */
220acd884deSSumit Saxena #define BNXT_RE_PRE_RECOVERY_REMOVE 0x1
221acd884deSSumit Saxena #define BNXT_RE_COMPLETE_REMOVE 0x2
222acd884deSSumit Saxena #define BNXT_RE_POST_RECOVERY_INIT 0x4
223acd884deSSumit Saxena #define BNXT_RE_COMPLETE_INIT 0x8
224acd884deSSumit Saxena #define BNXT_RE_COMPLETE_SHUTDOWN 0x10
225acd884deSSumit Saxena
226acd884deSSumit Saxena /* QP1 SQ entry data strucutre */
227acd884deSSumit Saxena struct bnxt_re_sqp_entries {
228acd884deSSumit Saxena u64 wrid;
229acd884deSSumit Saxena struct bnxt_qplib_sge sge;
230acd884deSSumit Saxena /* For storing the actual qp1 cqe */
231acd884deSSumit Saxena struct bnxt_qplib_cqe cqe;
232acd884deSSumit Saxena struct bnxt_re_qp *qp1_qp;
233acd884deSSumit Saxena };
234acd884deSSumit Saxena
235acd884deSSumit Saxena /* GSI QP mode enum */
236acd884deSSumit Saxena enum bnxt_re_gsi_mode {
237acd884deSSumit Saxena BNXT_RE_GSI_MODE_INVALID = 0,
238acd884deSSumit Saxena BNXT_RE_GSI_MODE_ALL = 1,
239acd884deSSumit Saxena BNXT_RE_GSI_MODE_ROCE_V1,
240acd884deSSumit Saxena BNXT_RE_GSI_MODE_ROCE_V2_IPV4,
241acd884deSSumit Saxena BNXT_RE_GSI_MODE_ROCE_V2_IPV6,
242acd884deSSumit Saxena BNXT_RE_GSI_MODE_UD
243acd884deSSumit Saxena };
244acd884deSSumit Saxena
245acd884deSSumit Saxena enum bnxt_re_roce_cap {
246acd884deSSumit Saxena BNXT_RE_FLAG_ROCEV1_CAP = 1,
247acd884deSSumit Saxena BNXT_RE_FLAG_ROCEV2_CAP,
248acd884deSSumit Saxena BNXT_RE_FLAG_ROCEV1_V2_CAP,
249acd884deSSumit Saxena };
250acd884deSSumit Saxena
251acd884deSSumit Saxena #define BNXT_RE_MAX_GSI_SQP_ENTRIES 1024
252acd884deSSumit Saxena struct bnxt_re_gsi_context {
253acd884deSSumit Saxena u8 gsi_qp_mode;
254acd884deSSumit Saxena bool first_cq_created;
255acd884deSSumit Saxena /* Start: used only in gsi_mode_all */
256acd884deSSumit Saxena struct bnxt_re_qp *gsi_qp;
257acd884deSSumit Saxena struct bnxt_re_qp *gsi_sqp;
258acd884deSSumit Saxena struct bnxt_re_ah *gsi_sah;
259acd884deSSumit Saxena struct bnxt_re_sqp_entries *sqp_tbl;
260acd884deSSumit Saxena /* End: used only in gsi_mode_all */
261acd884deSSumit Saxena };
262acd884deSSumit Saxena
263acd884deSSumit Saxena struct bnxt_re_tc_rec {
264acd884deSSumit Saxena u8 cos_id_roce;
265acd884deSSumit Saxena u8 tc_roce;
266acd884deSSumit Saxena u8 cos_id_cnp;
267acd884deSSumit Saxena u8 tc_cnp;
268acd884deSSumit Saxena u8 tc_def;
269acd884deSSumit Saxena u8 cos_id_def;
270acd884deSSumit Saxena u8 max_tc;
271acd884deSSumit Saxena u8 roce_prio;
272acd884deSSumit Saxena u8 cnp_prio;
273acd884deSSumit Saxena u8 roce_dscp;
274acd884deSSumit Saxena u8 cnp_dscp;
275acd884deSSumit Saxena u8 prio_valid;
276acd884deSSumit Saxena u8 dscp_valid;
277acd884deSSumit Saxena bool ecn_enabled;
278acd884deSSumit Saxena bool serv_type_enabled;
279acd884deSSumit Saxena u64 cnp_dscp_bv;
280acd884deSSumit Saxena u64 roce_dscp_bv;
281acd884deSSumit Saxena };
282acd884deSSumit Saxena
283acd884deSSumit Saxena struct bnxt_re_dscp2pri {
284acd884deSSumit Saxena u8 dscp;
285acd884deSSumit Saxena u8 mask;
286acd884deSSumit Saxena u8 pri;
287acd884deSSumit Saxena };
288acd884deSSumit Saxena
289acd884deSSumit Saxena struct bnxt_re_cos2bw_cfg {
290acd884deSSumit Saxena u8 pad[3];
291acd884deSSumit Saxena struct_group_attr(cfg, __packed,
292acd884deSSumit Saxena u8 queue_id;
293acd884deSSumit Saxena __le32 min_bw;
294acd884deSSumit Saxena __le32 max_bw;
295acd884deSSumit Saxena u8 tsa;
296acd884deSSumit Saxena u8 pri_lvl;
297acd884deSSumit Saxena u8 bw_weight;
298acd884deSSumit Saxena );
299acd884deSSumit Saxena u8 unused;
300acd884deSSumit Saxena };
301acd884deSSumit Saxena
302acd884deSSumit Saxena #define BNXT_RE_AEQ_IDX 0
303acd884deSSumit Saxena #define BNXT_RE_MAX_SGID_ENTRIES 256
304acd884deSSumit Saxena
305acd884deSSumit Saxena #define BNXT_RE_DBGFS_FILE_MEM 65536
306acd884deSSumit Saxena enum {
307acd884deSSumit Saxena BNXT_RE_STATS_QUERY = 1,
308acd884deSSumit Saxena BNXT_RE_QP_QUERY = 2,
309acd884deSSumit Saxena BNXT_RE_SERVICE_FN_QUERY = 3,
310acd884deSSumit Saxena };
311acd884deSSumit Saxena
312acd884deSSumit Saxena struct bnxt_re_dbg_file {
313acd884deSSumit Saxena struct bnxt_re_dev *rdev;
314acd884deSSumit Saxena u32 type;
315acd884deSSumit Saxena union {
316acd884deSSumit Saxena struct bnxt_qplib_query_stats_info sinfo;
317acd884deSSumit Saxena struct bnxt_qplib_query_fn_info fninfo;
318acd884deSSumit Saxena }params;
319acd884deSSumit Saxena char dbg_buf[BNXT_RE_DBGFS_FILE_MEM];
320acd884deSSumit Saxena };
321acd884deSSumit Saxena
322acd884deSSumit Saxena struct bnxt_re_debug_entries {
323acd884deSSumit Saxena /* Dir entries */
324acd884deSSumit Saxena struct dentry *qpinfo_dir;
325acd884deSSumit Saxena struct dentry *service_fn_dir;
326acd884deSSumit Saxena /* file entries */
327acd884deSSumit Saxena struct dentry *stat_query;
328acd884deSSumit Saxena struct bnxt_re_dbg_file stat_file;
329acd884deSSumit Saxena struct dentry *qplist_query;
330acd884deSSumit Saxena struct bnxt_re_dbg_file qp_file;
331acd884deSSumit Saxena struct dentry *service_fn_query;
332acd884deSSumit Saxena struct bnxt_re_dbg_file service_fn_file;
333acd884deSSumit Saxena };
334acd884deSSumit Saxena
335acd884deSSumit Saxena struct bnxt_re_en_dev_info {
336acd884deSSumit Saxena struct list_head en_list;
337acd884deSSumit Saxena struct bnxt_en_dev *en_dev;
338acd884deSSumit Saxena struct bnxt_re_dev *rdev;
339acd884deSSumit Saxena unsigned long flags;
340acd884deSSumit Saxena #define BNXT_RE_FLAG_EN_DEV_NETDEV_REG 0
341acd884deSSumit Saxena #define BNXT_RE_FLAG_EN_DEV_PRIMARY_DEV 1
342acd884deSSumit Saxena #define BNXT_RE_FLAG_EN_DEV_SECONDARY_DEV 2
343acd884deSSumit Saxena u8 wqe_mode;
344acd884deSSumit Saxena u8 gsi_mode;
345acd884deSSumit Saxena bool te_bypass;
346acd884deSSumit Saxena bool ib_uninit_done;
347acd884deSSumit Saxena u32 num_msix_requested;
348acd884deSSumit Saxena wait_queue_head_t waitq;
349acd884deSSumit Saxena };
350acd884deSSumit Saxena
351acd884deSSumit Saxena #define BNXT_RE_DB_FIFO_ROOM_MASK_P5 0x1FFF8000
352acd884deSSumit Saxena #define BNXT_RE_MAX_FIFO_DEPTH_P5 0x2c00
353acd884deSSumit Saxena #define BNXT_RE_DB_FIFO_ROOM_SHIFT 15
354acd884deSSumit Saxena
355acd884deSSumit Saxena #define BNXT_RE_DB_FIFO_ROOM_MASK_P7 0x3FFF8000
356acd884deSSumit Saxena #define BNXT_RE_MAX_FIFO_DEPTH_P7 0x8000
357acd884deSSumit Saxena
358acd884deSSumit Saxena #define BNXT_RE_DB_FIFO_ROOM_MASK(ctx) \
359acd884deSSumit Saxena (_is_chip_p7((ctx)) ? \
360acd884deSSumit Saxena BNXT_RE_DB_FIFO_ROOM_MASK_P7 :\
361acd884deSSumit Saxena BNXT_RE_DB_FIFO_ROOM_MASK_P5)
362acd884deSSumit Saxena #define BNXT_RE_MAX_FIFO_DEPTH(ctx) \
363acd884deSSumit Saxena (_is_chip_p7((ctx)) ? \
364acd884deSSumit Saxena BNXT_RE_MAX_FIFO_DEPTH_P7 :\
365acd884deSSumit Saxena BNXT_RE_MAX_FIFO_DEPTH_P5)
366acd884deSSumit Saxena
367acd884deSSumit Saxena struct bnxt_dbq_nq_list {
368acd884deSSumit Saxena int num_nql_entries;
369acd884deSSumit Saxena u16 nq_id[16];
370acd884deSSumit Saxena };
371acd884deSSumit Saxena
372acd884deSSumit Saxena #define BNXT_RE_ASYNC_ERR_REP_BASE(_type) \
373acd884deSSumit Saxena (ASYNC_EVENT_CMPL_ERROR_REPORT_BASE_EVENT_DATA1_ERROR_##_type)
374acd884deSSumit Saxena
375acd884deSSumit Saxena #define BNXT_RE_ASYNC_ERR_DBR_TRESH(_type) \
376acd884deSSumit Saxena (ASYNC_EVENT_CMPL_ERROR_REPORT_DOORBELL_DROP_THRESHOLD_##_type)
377acd884deSSumit Saxena
378acd884deSSumit Saxena #define BNXT_RE_EVENT_DBR_EPOCH(data) \
379acd884deSSumit Saxena (((data) & \
380acd884deSSumit Saxena BNXT_RE_ASYNC_ERR_DBR_TRESH(EVENT_DATA1_EPOCH_MASK)) >> \
381acd884deSSumit Saxena BNXT_RE_ASYNC_ERR_DBR_TRESH(EVENT_DATA1_EPOCH_SFT))
382acd884deSSumit Saxena
383acd884deSSumit Saxena #define BNXT_RE_EVENT_ERROR_REPORT_TYPE(data1) \
384acd884deSSumit Saxena (((data1) & \
385acd884deSSumit Saxena BNXT_RE_ASYNC_ERR_REP_BASE(TYPE_MASK)) >> \
386acd884deSSumit Saxena BNXT_RE_ASYNC_ERR_REP_BASE(TYPE_SFT))
387acd884deSSumit Saxena
388acd884deSSumit Saxena #define BNXT_RE_DBR_LIST_ADD(_rdev, _res, _type) \
389acd884deSSumit Saxena { \
390acd884deSSumit Saxena spin_lock(&(_rdev)->res_list[_type].lock); \
391acd884deSSumit Saxena list_add_tail(&(_res)->dbr_list, \
392acd884deSSumit Saxena &(_rdev)->res_list[_type].head); \
393acd884deSSumit Saxena spin_unlock(&(_rdev)->res_list[_type].lock); \
394acd884deSSumit Saxena }
395acd884deSSumit Saxena
396acd884deSSumit Saxena #define BNXT_RE_DBR_LIST_DEL(_rdev, _res, _type) \
397acd884deSSumit Saxena { \
398acd884deSSumit Saxena spin_lock(&(_rdev)->res_list[_type].lock); \
399acd884deSSumit Saxena list_del(&(_res)->dbr_list); \
400acd884deSSumit Saxena spin_unlock(&(_rdev)->res_list[_type].lock); \
401acd884deSSumit Saxena }
402acd884deSSumit Saxena
403acd884deSSumit Saxena #define BNXT_RE_CQ_PAGE_LIST_ADD(_uctx, _cq) \
404acd884deSSumit Saxena { \
405acd884deSSumit Saxena mutex_lock(&(_uctx)->cq_lock); \
406acd884deSSumit Saxena list_add_tail(&(_cq)->cq_list, &(_uctx)->cq_list); \
407acd884deSSumit Saxena mutex_unlock(&(_uctx)->cq_lock); \
408acd884deSSumit Saxena }
409acd884deSSumit Saxena
410acd884deSSumit Saxena #define BNXT_RE_CQ_PAGE_LIST_DEL(_uctx, _cq) \
411acd884deSSumit Saxena { \
412acd884deSSumit Saxena mutex_lock(&(_uctx)->cq_lock); \
413acd884deSSumit Saxena list_del(&(_cq)->cq_list); \
414acd884deSSumit Saxena mutex_unlock(&(_uctx)->cq_lock); \
415acd884deSSumit Saxena }
416acd884deSSumit Saxena
417acd884deSSumit Saxena #define BNXT_RE_NETDEV_EVENT(event, x) \
418acd884deSSumit Saxena do { \
419acd884deSSumit Saxena if ((event) == (x)) \
420acd884deSSumit Saxena return #x; \
421acd884deSSumit Saxena } while (0)
422acd884deSSumit Saxena
423acd884deSSumit Saxena /* Do not change the seq of this enum which is followed by dbr recov */
424acd884deSSumit Saxena enum {
425acd884deSSumit Saxena BNXT_RE_RES_TYPE_CQ = 0,
426acd884deSSumit Saxena BNXT_RE_RES_TYPE_UCTX,
427acd884deSSumit Saxena BNXT_RE_RES_TYPE_QP,
428acd884deSSumit Saxena BNXT_RE_RES_TYPE_SRQ,
429acd884deSSumit Saxena BNXT_RE_RES_TYPE_MAX
430acd884deSSumit Saxena };
431acd884deSSumit Saxena
432acd884deSSumit Saxena struct bnxt_re_dbr_res_list {
433acd884deSSumit Saxena struct list_head head;
434acd884deSSumit Saxena spinlock_t lock;
435acd884deSSumit Saxena };
436acd884deSSumit Saxena
437acd884deSSumit Saxena struct bnxt_re_dbr_drop_recov_work {
438acd884deSSumit Saxena struct work_struct work;
439acd884deSSumit Saxena struct bnxt_re_dev *rdev;
440acd884deSSumit Saxena u32 curr_epoch;
441acd884deSSumit Saxena };
442acd884deSSumit Saxena
443acd884deSSumit Saxena struct bnxt_re_aer_work {
444acd884deSSumit Saxena struct work_struct work;
445acd884deSSumit Saxena struct bnxt_re_dev *rdev;
446acd884deSSumit Saxena };
447acd884deSSumit Saxena
448acd884deSSumit Saxena struct bnxt_re_dbq_stats {
449acd884deSSumit Saxena u64 fifo_occup_slab_1;
450acd884deSSumit Saxena u64 fifo_occup_slab_2;
451acd884deSSumit Saxena u64 fifo_occup_slab_3;
452acd884deSSumit Saxena u64 fifo_occup_slab_4;
453acd884deSSumit Saxena u64 fifo_occup_water_mark;
454acd884deSSumit Saxena u64 do_pacing_slab_1;
455acd884deSSumit Saxena u64 do_pacing_slab_2;
456acd884deSSumit Saxena u64 do_pacing_slab_3;
457acd884deSSumit Saxena u64 do_pacing_slab_4;
458acd884deSSumit Saxena u64 do_pacing_slab_5;
459acd884deSSumit Saxena u64 do_pacing_water_mark;
460acd884deSSumit Saxena };
461acd884deSSumit Saxena
462acd884deSSumit Saxena /* Device debug statistics */
463acd884deSSumit Saxena struct bnxt_re_drv_dbg_stats {
464acd884deSSumit Saxena struct bnxt_re_dbq_stats dbq;
465acd884deSSumit Saxena };
466acd884deSSumit Saxena
467acd884deSSumit Saxena /* DB pacing counters */
468acd884deSSumit Saxena struct bnxt_re_dbr_sw_stats {
469acd884deSSumit Saxena u64 dbq_int_recv;
470acd884deSSumit Saxena u64 dbq_int_en;
471acd884deSSumit Saxena u64 dbq_pacing_resched;
472acd884deSSumit Saxena u64 dbq_pacing_complete;
473acd884deSSumit Saxena u64 dbq_pacing_alerts;
474acd884deSSumit Saxena u64 dbr_drop_recov_events;
475acd884deSSumit Saxena u64 dbr_drop_recov_timeouts;
476acd884deSSumit Saxena u64 dbr_drop_recov_timeout_users;
477acd884deSSumit Saxena u64 dbr_drop_recov_event_skips;
478acd884deSSumit Saxena };
479acd884deSSumit Saxena
480acd884deSSumit Saxena struct bnxt_re_dev {
481acd884deSSumit Saxena struct ib_device ibdev;
482acd884deSSumit Saxena struct list_head list;
483acd884deSSumit Saxena atomic_t ref_count;
484acd884deSSumit Saxena atomic_t sched_count;
485acd884deSSumit Saxena unsigned long flags;
486acd884deSSumit Saxena #define BNXT_RE_FLAG_NETDEV_REGISTERED 0
487acd884deSSumit Saxena #define BNXT_RE_FLAG_IBDEV_REGISTERED 1
488acd884deSSumit Saxena #define BNXT_RE_FLAG_GOT_MSIX 2
489acd884deSSumit Saxena #define BNXT_RE_FLAG_HAVE_L2_REF 3
490acd884deSSumit Saxena #define BNXT_RE_FLAG_ALLOC_RCFW 4
491acd884deSSumit Saxena #define BNXT_RE_FLAG_NET_RING_ALLOC 5
492acd884deSSumit Saxena #define BNXT_RE_FLAG_RCFW_CHANNEL_EN 6
493acd884deSSumit Saxena #define BNXT_RE_FLAG_ALLOC_CTX 7
494acd884deSSumit Saxena #define BNXT_RE_FLAG_STATS_CTX_ALLOC 8
495acd884deSSumit Saxena #define BNXT_RE_FLAG_STATS_CTX2_ALLOC 9
496acd884deSSumit Saxena #define BNXT_RE_FLAG_RCFW_CHANNEL_INIT 10
497acd884deSSumit Saxena #define BNXT_RE_FLAG_WORKER_REG 11
498acd884deSSumit Saxena #define BNXT_RE_FLAG_TBLS_ALLOCINIT 12
499acd884deSSumit Saxena #define BNXT_RE_FLAG_SETUP_NQ 13
500acd884deSSumit Saxena #define BNXT_RE_FLAG_BOND_DEV_REGISTERED 14
501acd884deSSumit Saxena #define BNXT_RE_FLAG_PER_PORT_DEBUG_INFO 15
502acd884deSSumit Saxena #define BNXT_RE_FLAG_DEV_LIST_INITIALIZED 16
503acd884deSSumit Saxena #define BNXT_RE_FLAG_ERR_DEVICE_DETACHED 17
504acd884deSSumit Saxena #define BNXT_RE_FLAG_INIT_DCBX_CC_PARAM 18
505acd884deSSumit Saxena #define BNXT_RE_FLAG_STOP_IN_PROGRESS 20
506acd884deSSumit Saxena #define BNXT_RE_FLAG_ISSUE_ROCE_STATS 29
507acd884deSSumit Saxena #define BNXT_RE_FLAG_ISSUE_CFA_FLOW_STATS 30
508acd884deSSumit Saxena struct ifnet *netdev;
509acd884deSSumit Saxena struct auxiliary_device *adev;
510acd884deSSumit Saxena struct bnxt_qplib_chip_ctx *chip_ctx;
511acd884deSSumit Saxena struct bnxt_en_dev *en_dev;
512acd884deSSumit Saxena struct bnxt_re_nq_record nqr;
513acd884deSSumit Saxena int id;
514acd884deSSumit Saxena struct delayed_work worker;
515acd884deSSumit Saxena u16 worker_30s;
516acd884deSSumit Saxena struct bnxt_re_tc_rec tc_rec[2];
517acd884deSSumit Saxena u8 cur_prio_map;
518acd884deSSumit Saxena /* RCFW Channel */
519acd884deSSumit Saxena struct bnxt_qplib_rcfw rcfw;
520acd884deSSumit Saxena /* Device Resources */
521acd884deSSumit Saxena struct bnxt_qplib_dev_attr *dev_attr;
522acd884deSSumit Saxena struct bnxt_qplib_res qplib_res;
523acd884deSSumit Saxena struct bnxt_qplib_dpi dpi_privileged;
524acd884deSSumit Saxena struct bnxt_qplib_cc_param cc_param;
525acd884deSSumit Saxena struct mutex cc_lock;
526acd884deSSumit Saxena struct mutex qp_lock;
527acd884deSSumit Saxena struct list_head qp_list;
528acd884deSSumit Saxena u8 roce_mode;
529acd884deSSumit Saxena
530acd884deSSumit Saxena /* Max of 2 lossless traffic class supported per port */
531acd884deSSumit Saxena u16 cosq[2];
532acd884deSSumit Saxena /* Start: QP for handling QP1 packets */
533acd884deSSumit Saxena struct bnxt_re_gsi_context gsi_ctx;
534acd884deSSumit Saxena /* End: QP for handling QP1 packets */
535acd884deSSumit Saxena bool is_virtfn;
536acd884deSSumit Saxena u32 num_vfs;
537acd884deSSumit Saxena u32 espeed;
538acd884deSSumit Saxena /*
539acd884deSSumit Saxena * For storing the speed of slave interfaces.
540acd884deSSumit Saxena * Same as espeed when bond is not configured
541acd884deSSumit Saxena */
542acd884deSSumit Saxena u32 sl_espeed;
543acd884deSSumit Saxena /* To be used for a workaround for ISER stack */
544acd884deSSumit Saxena u32 min_tx_depth;
545acd884deSSumit Saxena /* To enable qp debug info. Disabled during driver load */
546acd884deSSumit Saxena u32 en_qp_dbg;
547acd884deSSumit Saxena /* Array to handle gid mapping */
548acd884deSSumit Saxena char *gid_map;
549acd884deSSumit Saxena
550acd884deSSumit Saxena struct bnxt_re_device_stats stats;
551acd884deSSumit Saxena struct bnxt_re_drv_dbg_stats *dbg_stats;
552acd884deSSumit Saxena /* debugfs to expose per port information*/
553acd884deSSumit Saxena struct dentry *port_debug_dir;
554acd884deSSumit Saxena struct dentry *info;
555acd884deSSumit Saxena struct dentry *drv_dbg_stats;
556acd884deSSumit Saxena struct dentry *sp_perf_stats;
557acd884deSSumit Saxena struct dentry *pdev_debug_dir;
558acd884deSSumit Saxena struct dentry *pdev_qpinfo_dir;
559acd884deSSumit Saxena struct bnxt_re_debug_entries *dbg_ent;
560acd884deSSumit Saxena struct workqueue_struct *resolve_wq;
561acd884deSSumit Saxena struct list_head mac_wq_list;
562acd884deSSumit Saxena struct workqueue_struct *dcb_wq;
563acd884deSSumit Saxena struct workqueue_struct *aer_wq;
564acd884deSSumit Saxena u32 event_bitmap[3];
565acd884deSSumit Saxena bool unreg_sched;
566acd884deSSumit Saxena u64 dbr_throttling_reg_off;
567acd884deSSumit Saxena u64 dbr_aeq_arm_reg_off;
568acd884deSSumit Saxena u64 dbr_db_fifo_reg_off;
569acd884deSSumit Saxena void *dbr_page;
570acd884deSSumit Saxena u64 dbr_bar_addr;
571acd884deSSumit Saxena u32 pacing_algo_th;
572acd884deSSumit Saxena u32 pacing_en_int_th;
573acd884deSSumit Saxena u32 do_pacing_save;
574acd884deSSumit Saxena struct workqueue_struct *dbq_wq;
575acd884deSSumit Saxena struct workqueue_struct *dbr_drop_recov_wq;
576acd884deSSumit Saxena struct work_struct dbq_fifo_check_work;
577acd884deSSumit Saxena struct delayed_work dbq_pacing_work;
578acd884deSSumit Saxena /* protect DB pacing */
579acd884deSSumit Saxena struct mutex dbq_lock;
580acd884deSSumit Saxena /* Control DBR pacing feature. Set if enabled */
581acd884deSSumit Saxena bool dbr_pacing;
582acd884deSSumit Saxena /* Control DBR recovery feature. Set if enabled */
583acd884deSSumit Saxena bool dbr_drop_recov;
584acd884deSSumit Saxena bool user_dbr_drop_recov;
585acd884deSSumit Saxena /* DBR recovery feature. Set if running */
586acd884deSSumit Saxena bool dbr_recovery_on;
587acd884deSSumit Saxena u32 user_dbr_drop_recov_timeout;
588acd884deSSumit Saxena /*
589acd884deSSumit Saxena * Value used for pacing algo when pacing is active
590acd884deSSumit Saxena */
591acd884deSSumit Saxena #define BNXT_RE_MAX_DBR_DO_PACING 0xFFFF
592acd884deSSumit Saxena u32 dbr_do_pacing;
593acd884deSSumit Saxena u32 dbq_watermark; /* Current watermark set in HW registers */
594acd884deSSumit Saxena u32 dbq_nq_id; /* Current NQ ID for DBQ events */
595acd884deSSumit Saxena u32 dbq_pacing_time; /* ms */
596acd884deSSumit Saxena u32 dbr_def_do_pacing; /* do_pacing when no congestion */
597acd884deSSumit Saxena u32 dbr_evt_curr_epoch;
598acd884deSSumit Saxena bool dbq_int_disable;
599acd884deSSumit Saxena
600acd884deSSumit Saxena bool mod_exit;
601acd884deSSumit Saxena struct bnxt_re_dbr_sw_stats *dbr_sw_stats;
602acd884deSSumit Saxena struct bnxt_re_dbr_res_list res_list[BNXT_RE_RES_TYPE_MAX];
603acd884deSSumit Saxena struct bnxt_dbq_nq_list nq_list;
604acd884deSSumit Saxena char dev_name[IB_DEVICE_NAME_MAX];
605acd884deSSumit Saxena atomic_t dbq_intr_running;
606acd884deSSumit Saxena u32 num_msix_requested;
607acd884deSSumit Saxena unsigned char *dev_addr; /* For netdev->dev_addr */
608acd884deSSumit Saxena };
609acd884deSSumit Saxena
610acd884deSSumit Saxena #define BNXT_RE_RESOLVE_RETRY_COUNT_US 5000000 /* 5 sec */
611acd884deSSumit Saxena struct bnxt_re_resolve_dmac_work{
612acd884deSSumit Saxena struct work_struct work;
613acd884deSSumit Saxena struct list_head list;
614acd884deSSumit Saxena struct bnxt_re_dev *rdev;
615acd884deSSumit Saxena struct ib_ah_attr *ah_attr;
616acd884deSSumit Saxena struct bnxt_re_ah_info *ah_info;
617acd884deSSumit Saxena atomic_t status_wait;
618acd884deSSumit Saxena };
619acd884deSSumit Saxena
bnxt_re_get_prio(u8 prio_map)620acd884deSSumit Saxena static inline u8 bnxt_re_get_prio(u8 prio_map)
621acd884deSSumit Saxena {
622acd884deSSumit Saxena u8 prio = 0xFF;
623acd884deSSumit Saxena
624acd884deSSumit Saxena for (prio = 0; prio < 8; prio++)
625acd884deSSumit Saxena if (prio_map & (1UL << prio))
626acd884deSSumit Saxena break;
627acd884deSSumit Saxena return prio;
628acd884deSSumit Saxena }
629acd884deSSumit Saxena
630acd884deSSumit Saxena /* This should be called with bnxt_re_dev_lock mutex held */
__bnxt_re_is_rdev_valid(struct bnxt_re_dev * rdev)631acd884deSSumit Saxena static inline bool __bnxt_re_is_rdev_valid(struct bnxt_re_dev *rdev)
632acd884deSSumit Saxena {
633acd884deSSumit Saxena struct bnxt_re_dev *tmp_rdev;
634acd884deSSumit Saxena
635acd884deSSumit Saxena list_for_each_entry(tmp_rdev, &bnxt_re_dev_list, list) {
636acd884deSSumit Saxena if (rdev == tmp_rdev)
637acd884deSSumit Saxena return true;
638acd884deSSumit Saxena }
639acd884deSSumit Saxena return false;
640acd884deSSumit Saxena }
641acd884deSSumit Saxena
bnxt_re_is_rdev_valid(struct bnxt_re_dev * rdev)642acd884deSSumit Saxena static inline bool bnxt_re_is_rdev_valid(struct bnxt_re_dev *rdev)
643acd884deSSumit Saxena {
644acd884deSSumit Saxena struct bnxt_re_dev *tmp_rdev;
645acd884deSSumit Saxena
646acd884deSSumit Saxena mutex_lock(&bnxt_re_dev_lock);
647acd884deSSumit Saxena list_for_each_entry(tmp_rdev, &bnxt_re_dev_list, list) {
648acd884deSSumit Saxena if (rdev == tmp_rdev) {
649acd884deSSumit Saxena mutex_unlock(&bnxt_re_dev_lock);
650acd884deSSumit Saxena return true;
651acd884deSSumit Saxena }
652acd884deSSumit Saxena }
653acd884deSSumit Saxena mutex_unlock(&bnxt_re_dev_lock);
654acd884deSSumit Saxena
655acd884deSSumit Saxena pr_debug("bnxt_re: %s : Invalid rdev received rdev = %p\n",
656acd884deSSumit Saxena __func__, rdev);
657acd884deSSumit Saxena return false;
658acd884deSSumit Saxena }
659acd884deSSumit Saxena
660acd884deSSumit Saxena int bnxt_re_send_hwrm_cmd(struct bnxt_re_dev *rdev, void *cmd,
661acd884deSSumit Saxena int cmdlen);
662acd884deSSumit Saxena void bnxt_re_stopqps_and_ib_uninit(struct bnxt_re_dev *rdev);
663acd884deSSumit Saxena int bnxt_re_set_hwrm_dscp2pri(struct bnxt_re_dev *rdev,
664acd884deSSumit Saxena struct bnxt_re_dscp2pri *d2p, u16 count,
665acd884deSSumit Saxena u16 target_id);
666acd884deSSumit Saxena int bnxt_re_query_hwrm_dscp2pri(struct bnxt_re_dev *rdev,
667acd884deSSumit Saxena struct bnxt_re_dscp2pri *d2p, u16 *count,
668acd884deSSumit Saxena u16 target_id);
669acd884deSSumit Saxena int bnxt_re_query_hwrm_qportcfg(struct bnxt_re_dev *rdev,
670acd884deSSumit Saxena struct bnxt_re_tc_rec *cnprec, u16 tid);
671acd884deSSumit Saxena int bnxt_re_hwrm_cos2bw_qcfg(struct bnxt_re_dev *rdev, u16 target_id,
672acd884deSSumit Saxena struct bnxt_re_cos2bw_cfg *cfg);
673acd884deSSumit Saxena int bnxt_re_hwrm_cos2bw_cfg(struct bnxt_re_dev *rdev, u16 target_id,
674acd884deSSumit Saxena struct bnxt_re_cos2bw_cfg *cfg);
675acd884deSSumit Saxena int bnxt_re_hwrm_pri2cos_cfg(struct bnxt_re_dev *rdev,
676acd884deSSumit Saxena u16 target_id, u16 port_id,
677acd884deSSumit Saxena u8 *cos_id_map, u8 pri_map);
678acd884deSSumit Saxena int bnxt_re_prio_vlan_tx_update(struct bnxt_re_dev *rdev);
679acd884deSSumit Saxena int bnxt_re_get_slot_pf_count(struct bnxt_re_dev *rdev);
680acd884deSSumit Saxena struct bnxt_re_dev *bnxt_re_get_peer_pf(struct bnxt_re_dev *rdev);
681acd884deSSumit Saxena struct bnxt_re_dev *bnxt_re_from_netdev(struct ifnet *netdev);
682acd884deSSumit Saxena u8 bnxt_re_get_priority_mask(struct bnxt_re_dev *rdev, u8 selector);
683acd884deSSumit Saxena struct bnxt_qplib_nq * bnxt_re_get_nq(struct bnxt_re_dev *rdev);
684acd884deSSumit Saxena void bnxt_re_put_nq(struct bnxt_re_dev *rdev, struct bnxt_qplib_nq *nq);
685acd884deSSumit Saxena
686acd884deSSumit Saxena #define to_bnxt_re(ptr, type, member) \
687acd884deSSumit Saxena container_of(ptr, type, member)
688acd884deSSumit Saxena
689acd884deSSumit Saxena #define to_bnxt_re_dev(ptr, member) \
690acd884deSSumit Saxena container_of((ptr), struct bnxt_re_dev, member)
691acd884deSSumit Saxena
692acd884deSSumit Saxena /* Even number functions from port 0 and odd number from port 1 */
693acd884deSSumit Saxena #define BNXT_RE_IS_PORT0(rdev) (!(rdev->en_dev->pdev->devfn & 1))
694acd884deSSumit Saxena
695acd884deSSumit Saxena #define BNXT_RE_ROCE_V1_PACKET 0
696acd884deSSumit Saxena #define BNXT_RE_ROCEV2_IPV4_PACKET 2
697acd884deSSumit Saxena #define BNXT_RE_ROCEV2_IPV6_PACKET 3
698acd884deSSumit Saxena #define BNXT_RE_ACTIVE_MAP_PORT1 0x1 /*port-1 active */
699acd884deSSumit Saxena #define BNXT_RE_ACTIVE_MAP_PORT2 0x2 /*port-2 active */
700acd884deSSumit Saxena
701acd884deSSumit Saxena #define BNXT_RE_MEMBER_PORT_MAP (BNXT_RE_ACTIVE_MAP_PORT1 | \
702acd884deSSumit Saxena BNXT_RE_ACTIVE_MAP_PORT2)
703acd884deSSumit Saxena
704acd884deSSumit Saxena #define rdev_to_dev(rdev) ((rdev) ? (&(rdev)->ibdev.dev) : NULL)
705acd884deSSumit Saxena
706acd884deSSumit Saxena void bnxt_re_set_dma_device(struct ib_device *ibdev, struct bnxt_re_dev *rdev);
707acd884deSSumit Saxena bool bnxt_re_is_rdev_valid(struct bnxt_re_dev *rdev);
708acd884deSSumit Saxena
709acd884deSSumit Saxena #define bnxt_re_rdev_ready(rdev) (bnxt_re_is_rdev_valid(rdev) && \
710acd884deSSumit Saxena (test_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags)))
711acd884deSSumit Saxena #define BNXT_RE_SRIOV_CFG_TIMEOUT 6
712acd884deSSumit Saxena
713acd884deSSumit Saxena int bnxt_re_get_device_stats(struct bnxt_re_dev *rdev);
714acd884deSSumit Saxena void bnxt_re_remove_device(struct bnxt_re_dev *rdev, u8 removal_type,
715acd884deSSumit Saxena struct auxiliary_device *aux_dev);
716acd884deSSumit Saxena void bnxt_re_destroy_lag(struct bnxt_re_dev **rdev);
717acd884deSSumit Saxena int bnxt_re_add_device(struct bnxt_re_dev **rdev,
718acd884deSSumit Saxena struct ifnet *netdev,
719acd884deSSumit Saxena u8 qp_mode, u8 op_type, u8 wqe_mode, u32 num_msix_requested,
720acd884deSSumit Saxena struct auxiliary_device *aux_dev);
721acd884deSSumit Saxena void bnxt_re_create_base_interface(bool primary);
722acd884deSSumit Saxena int bnxt_re_schedule_work(struct bnxt_re_dev *rdev, unsigned long event,
723acd884deSSumit Saxena struct ifnet *vlan_dev,
724acd884deSSumit Saxena struct ifnet *netdev,
725acd884deSSumit Saxena struct auxiliary_device *aux_dev);
726acd884deSSumit Saxena void bnxt_re_get_link_speed(struct bnxt_re_dev *rdev);
727acd884deSSumit Saxena int _bnxt_re_ib_init(struct bnxt_re_dev *rdev);
728acd884deSSumit Saxena int _bnxt_re_ib_init2(struct bnxt_re_dev *rdev);
729acd884deSSumit Saxena void bnxt_re_init_resolve_wq(struct bnxt_re_dev *rdev);
730acd884deSSumit Saxena void bnxt_re_uninit_resolve_wq(struct bnxt_re_dev *rdev);
731acd884deSSumit Saxena
732acd884deSSumit Saxena /* The rdev ref_count is to protect immature removal of the device */
bnxt_re_hold(struct bnxt_re_dev * rdev)733acd884deSSumit Saxena static inline void bnxt_re_hold(struct bnxt_re_dev *rdev)
734acd884deSSumit Saxena {
735acd884deSSumit Saxena atomic_inc(&rdev->ref_count);
736acd884deSSumit Saxena dev_dbg(rdev_to_dev(rdev),
737acd884deSSumit Saxena "Hold ref_count = 0x%x", atomic_read(&rdev->ref_count));
738acd884deSSumit Saxena }
739acd884deSSumit Saxena
bnxt_re_put(struct bnxt_re_dev * rdev)740acd884deSSumit Saxena static inline void bnxt_re_put(struct bnxt_re_dev *rdev)
741acd884deSSumit Saxena {
742acd884deSSumit Saxena atomic_dec(&rdev->ref_count);
743acd884deSSumit Saxena dev_dbg(rdev_to_dev(rdev),
744acd884deSSumit Saxena "Put ref_count = 0x%x", atomic_read(&rdev->ref_count));
745acd884deSSumit Saxena }
746acd884deSSumit Saxena
747acd884deSSumit Saxena /*
748acd884deSSumit Saxena * Responder Error reason codes
749acd884deSSumit Saxena * FIXME: Remove these when the defs
750acd884deSSumit Saxena * are properly included in hsi header
751acd884deSSumit Saxena */
752acd884deSSumit Saxena enum res_err_state_reason {
753acd884deSSumit Saxena /* No error. */
754acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_NO_ERROR = 0,
755acd884deSSumit Saxena /*
756acd884deSSumit Saxena * Incoming Send, RDMA write, or RDMA read exceeds the maximum
757acd884deSSumit Saxena * transfer length. Detected on RX first and only packets for
758acd884deSSumit Saxena * write. Detected on RX request for read. This is an RX
759acd884deSSumit Saxena * Detected Error.
760acd884deSSumit Saxena */
761acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_EXCEED_MAX,
762acd884deSSumit Saxena /*
763acd884deSSumit Saxena * RDMA write payload size does not match write length. Detected
764acd884deSSumit Saxena * when total write payload is not equal to the RDMA write
765acd884deSSumit Saxena * length that was given in the first or only packet of the
766acd884deSSumit Saxena * request. This is an RX Detected Error.
767acd884deSSumit Saxena */
768acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_PAYLOAD_LENGTH_MISMATCH,
769acd884deSSumit Saxena /*
770acd884deSSumit Saxena * Send payload exceeds RQ/SRQ WQE buffer capacity. The total
771acd884deSSumit Saxena * send payload that arrived is more than the size of the WQE
772acd884deSSumit Saxena * buffer that was fetched from the RQ/SRQ. This is an RX
773acd884deSSumit Saxena * Detected Error.
774acd884deSSumit Saxena */
775acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_EXCEEDS_WQE,
776acd884deSSumit Saxena /*
777acd884deSSumit Saxena * Responder detected opcode error. * First, only, middle, last
778acd884deSSumit Saxena * for incoming requests are improperly ordered with respect to
779acd884deSSumit Saxena * previous (PSN) packet. * First or middle packet is not full
780acd884deSSumit Saxena * MTU size. This is an RX Detected Error.
781acd884deSSumit Saxena */
782acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_OPCODE_ERROR,
783acd884deSSumit Saxena /*
784acd884deSSumit Saxena * PSN sequence error retry limit exceeded. The responder
785acd884deSSumit Saxena * encountered a PSN sequence error for the same PSN too many
786acd884deSSumit Saxena * times. This can occur via implicit or explicit NAK. This is
787acd884deSSumit Saxena * an RX Detected Error.
788acd884deSSumit Saxena */
789acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_PSN_SEQ_ERROR_RETRY_LIMIT,
790acd884deSSumit Saxena /*
791acd884deSSumit Saxena * Invalid R_Key. An incoming request contained an R_Key that
792acd884deSSumit Saxena * did not reference a valid MR/MW. This error may be detected
793acd884deSSumit Saxena * by the RX engine for RDMA write or by the TX engine for RDMA
794acd884deSSumit Saxena * read (detected while servicing IRRQ). This is an RX Detected
795acd884deSSumit Saxena * Error.
796acd884deSSumit Saxena */
797acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_RX_INVALID_R_KEY,
798acd884deSSumit Saxena /*
799acd884deSSumit Saxena * Domain error. An incoming request specified an R_Key which
800acd884deSSumit Saxena * referenced a MR/MW that was not in the same PD as the QP on
801acd884deSSumit Saxena * which the request arrived. This is an RX Detected Error.
802acd884deSSumit Saxena */
803acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_RX_DOMAIN_ERROR,
804acd884deSSumit Saxena /*
805acd884deSSumit Saxena * No permission. An incoming request contained an R_Key that
806acd884deSSumit Saxena * referenced a MR/MW which did not have the access permission
807acd884deSSumit Saxena * needed for the operation. This is an RX Detected Error.
808acd884deSSumit Saxena */
809acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_RX_NO_PERMISSION,
810acd884deSSumit Saxena /*
811acd884deSSumit Saxena * Range error. An incoming request had a combination of R_Key,
812acd884deSSumit Saxena * VA, and length that was out of bounds of the associated
813acd884deSSumit Saxena * MR/MW. This is an RX Detected Error.
814acd884deSSumit Saxena */
815acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_RX_RANGE_ERROR,
816acd884deSSumit Saxena /*
817acd884deSSumit Saxena * Invalid R_Key. An incoming request contained an R_Key that
818acd884deSSumit Saxena * did not reference a valid MR/MW. This error may be detected
819acd884deSSumit Saxena * by the RX engine for RDMA write or by the TX engine for RDMA
820acd884deSSumit Saxena * read (detected while servicing IRRQ). This is a TX Detected
821acd884deSSumit Saxena * Error.
822acd884deSSumit Saxena */
823acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_TX_INVALID_R_KEY,
824acd884deSSumit Saxena /*
825acd884deSSumit Saxena * Domain error. An incoming request specified an R_Key which
826acd884deSSumit Saxena * referenced a MR/MW that was not in the same PD as the QP on
827acd884deSSumit Saxena * which the request arrived. This is a TX Detected Error.
828acd884deSSumit Saxena */
829acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_TX_DOMAIN_ERROR,
830acd884deSSumit Saxena /*
831acd884deSSumit Saxena * No permission. An incoming request contained an R_Key that
832acd884deSSumit Saxena * referenced a MR/MW which did not have the access permission
833acd884deSSumit Saxena * needed for the operation. This is a TX Detected Error.
834acd884deSSumit Saxena */
835acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_TX_NO_PERMISSION,
836acd884deSSumit Saxena /*
837acd884deSSumit Saxena * Range error. An incoming request had a combination of R_Key,
838acd884deSSumit Saxena * VA, and length that was out of bounds of the associated
839acd884deSSumit Saxena * MR/MW. This is a TX Detected Error.
840acd884deSSumit Saxena */
841acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_TX_RANGE_ERROR,
842acd884deSSumit Saxena /*
843acd884deSSumit Saxena * IRRQ overflow. The peer sent us more RDMA read or atomic
844acd884deSSumit Saxena * requests than the negotiated maximum. This is an RX Detected
845acd884deSSumit Saxena * Error.
846acd884deSSumit Saxena */
847acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_IRRQ_OFLOW,
848acd884deSSumit Saxena /*
849acd884deSSumit Saxena * Unsupported opcode. The peer sent us a request with an opcode
850acd884deSSumit Saxena * for a request type that is not supported on this QP. This is
851acd884deSSumit Saxena * an RX Detected Error.
852acd884deSSumit Saxena */
853acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_UNSUPPORTED_OPCODE,
854acd884deSSumit Saxena /*
855acd884deSSumit Saxena * Unaligned atomic operation. The VA of an atomic request is on
856acd884deSSumit Saxena * a memory boundary that prevents atomic execution. This is an
857acd884deSSumit Saxena * RX Detected Error.
858acd884deSSumit Saxena */
859acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_UNALIGN_ATOMIC,
860acd884deSSumit Saxena /*
861acd884deSSumit Saxena * Remote invalidate error. A send with invalidate request
862acd884deSSumit Saxena * arrived in which the R_Key to invalidate did not describe a
863acd884deSSumit Saxena * MR/MW which could be invalidated. RQ WQE completes with error
864acd884deSSumit Saxena * status. This error is only reported if the send operation did
865acd884deSSumit Saxena * not fail. If the send operation failed then the remote
866acd884deSSumit Saxena * invalidate error is not reported. This is an RX Detected
867acd884deSSumit Saxena * Error.
868acd884deSSumit Saxena */
869acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_REM_INVALIDATE,
870acd884deSSumit Saxena /*
871acd884deSSumit Saxena * Local memory error. An RQ/SRQ SGE described an inaccessible
872acd884deSSumit Saxena * memory. This is an RX Detected Error.
873acd884deSSumit Saxena */
874acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_MEMORY_ERROR,
875acd884deSSumit Saxena /*
876acd884deSSumit Saxena * SRQ in error. The QP is moving to error state because it
877acd884deSSumit Saxena * found SRQ it uses in error. This is an RX Detected Error.
878acd884deSSumit Saxena */
879acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_SRQ_ERROR,
880acd884deSSumit Saxena /*
881acd884deSSumit Saxena * Completion error. No CQE space available on queue or CQ not
882acd884deSSumit Saxena * in VALID state. This is a Completion Detected Error.
883acd884deSSumit Saxena */
884acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_CMP_ERROR,
885acd884deSSumit Saxena /*
886acd884deSSumit Saxena * Invalid R_Key while resending responses to duplicate request.
887acd884deSSumit Saxena * This is a TX Detected Error.
888acd884deSSumit Saxena */
889acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_IVALID_DUP_RKEY,
890acd884deSSumit Saxena /*
891acd884deSSumit Saxena * Problem was found in the format of a WQE in the RQ/SRQ. This
892acd884deSSumit Saxena * is an RX Detected Error.
893acd884deSSumit Saxena */
894acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_WQE_FORMAT_ERROR,
895acd884deSSumit Saxena /*
896acd884deSSumit Saxena * A load error occurred on an attempt to load the CQ Context.
897acd884deSSumit Saxena * This is a Completion Detected Error.
898acd884deSSumit Saxena */
899acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_CQ_LOAD_ERROR = 0x18,
900acd884deSSumit Saxena /*
901acd884deSSumit Saxena * A load error occurred on an attempt to load the SRQ Context.
902acd884deSSumit Saxena * This is an RX Detected Error.
903acd884deSSumit Saxena */
904acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_SRQ_LOAD_ERROR,
905acd884deSSumit Saxena /*
906acd884deSSumit Saxena * A fatal error was detected on an attempt to read from or
907acd884deSSumit Saxena * write to PCIe on the transmit side. This error is detected by
908acd884deSSumit Saxena * the TX side, but has the priority of a Completion Detected
909acd884deSSumit Saxena * Error.
910acd884deSSumit Saxena */
911acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_TX_PCI_ERROR = 0x1b,
912acd884deSSumit Saxena /*
913acd884deSSumit Saxena * A fatal error was detected on an attempt to read from or
914acd884deSSumit Saxena * write to PCIe on the receive side. This error is detected by
915acd884deSSumit Saxena * the RX side (or CAGR), but has the priority of a Completion
916acd884deSSumit Saxena * Detected Error.
917acd884deSSumit Saxena */
918acd884deSSumit Saxena CFCQ_RES_ERR_STATE_REASON_RES_RX_PCI_ERROR = 0x1c
919acd884deSSumit Saxena };
920acd884deSSumit Saxena
921acd884deSSumit Saxena int bnxt_re_host_pf_id_query(struct bnxt_re_dev *rdev,
922acd884deSSumit Saxena struct bnxt_qplib_query_fn_info *fn_info,
923acd884deSSumit Saxena u32 *pf_mask, u32 *first_pf);
924acd884deSSumit Saxena
925acd884deSSumit Saxena /* Default DCBx and CC values */
926acd884deSSumit Saxena #define BNXT_RE_DEFAULT_CNP_DSCP 48
927acd884deSSumit Saxena #define BNXT_RE_DEFAULT_CNP_PRI 7
928acd884deSSumit Saxena #define BNXT_RE_DEFAULT_ROCE_DSCP 26
929acd884deSSumit Saxena #define BNXT_RE_DEFAULT_ROCE_PRI 3
930acd884deSSumit Saxena
931acd884deSSumit Saxena #define BNXT_RE_DEFAULT_L2_BW 50
932acd884deSSumit Saxena #define BNXT_RE_DEFAULT_ROCE_BW 50
933acd884deSSumit Saxena
934acd884deSSumit Saxena #define ROCE_PRIO_VALID 0x0
935acd884deSSumit Saxena #define CNP_PRIO_VALID 0x1
936acd884deSSumit Saxena #define ROCE_DSCP_VALID 0x0
937acd884deSSumit Saxena #define CNP_DSCP_VALID 0x1
938acd884deSSumit Saxena
939acd884deSSumit Saxena int bnxt_re_get_pri_dscp_settings(struct bnxt_re_dev *rdev,
940acd884deSSumit Saxena u16 target_id,
941acd884deSSumit Saxena struct bnxt_re_tc_rec *tc_rec);
942acd884deSSumit Saxena
943acd884deSSumit Saxena int bnxt_re_setup_dscp(struct bnxt_re_dev *rdev);
944acd884deSSumit Saxena int bnxt_re_clear_dscp(struct bnxt_re_dev *rdev);
945acd884deSSumit Saxena int bnxt_re_setup_cnp_cos(struct bnxt_re_dev *rdev, bool reset);
946acd884deSSumit Saxena
bnxt_re_get_link_state(struct bnxt_re_dev * rdev)947acd884deSSumit Saxena static inline enum ib_port_state bnxt_re_get_link_state(struct bnxt_re_dev *rdev)
948acd884deSSumit Saxena {
949*84d7ec4cSJustin Hibbits if (if_getdrvflags(rdev->netdev) & IFF_DRV_RUNNING &&
950*84d7ec4cSJustin Hibbits if_getlinkstate(rdev->netdev) == LINK_STATE_UP)
951acd884deSSumit Saxena return IB_PORT_ACTIVE;
952acd884deSSumit Saxena return IB_PORT_DOWN;
953acd884deSSumit Saxena }
954acd884deSSumit Saxena
bnxt_re_link_state(struct bnxt_re_dev * rdev)955acd884deSSumit Saxena static inline int bnxt_re_link_state(struct bnxt_re_dev *rdev)
956acd884deSSumit Saxena {
957acd884deSSumit Saxena return bnxt_re_get_link_state(rdev) == IB_PORT_ACTIVE ? 1:0;
958acd884deSSumit Saxena }
959acd884deSSumit Saxena
is_cc_enabled(struct bnxt_re_dev * rdev)960acd884deSSumit Saxena static inline int is_cc_enabled(struct bnxt_re_dev *rdev)
961acd884deSSumit Saxena {
962acd884deSSumit Saxena return rdev->cc_param.enable;
963acd884deSSumit Saxena }
964acd884deSSumit Saxena
bnxt_re_init_hwrm_hdr(struct bnxt_re_dev * rdev,struct input * hdr,u16 opcd,u16 crid,u16 trid)965acd884deSSumit Saxena static inline void bnxt_re_init_hwrm_hdr(struct bnxt_re_dev *rdev,
966acd884deSSumit Saxena struct input *hdr, u16 opcd,
967acd884deSSumit Saxena u16 crid, u16 trid)
968acd884deSSumit Saxena {
969acd884deSSumit Saxena hdr->req_type = cpu_to_le16(opcd);
970acd884deSSumit Saxena hdr->cmpl_ring = cpu_to_le16(crid);
971acd884deSSumit Saxena hdr->target_id = cpu_to_le16(trid);
972acd884deSSumit Saxena }
973acd884deSSumit Saxena
bnxt_re_fill_fw_msg(struct bnxt_fw_msg * fw_msg,void * msg,int msg_len,void * resp,int resp_max_len,int timeout)974acd884deSSumit Saxena static inline void bnxt_re_fill_fw_msg(struct bnxt_fw_msg *fw_msg,
975acd884deSSumit Saxena void *msg, int msg_len, void *resp,
976acd884deSSumit Saxena int resp_max_len, int timeout)
977acd884deSSumit Saxena {
978acd884deSSumit Saxena fw_msg->msg = msg;
979acd884deSSumit Saxena fw_msg->msg_len = msg_len;
980acd884deSSumit Saxena fw_msg->resp = resp;
981acd884deSSumit Saxena fw_msg->resp_max_len = resp_max_len;
982acd884deSSumit Saxena fw_msg->timeout = timeout;
983acd884deSSumit Saxena }
984acd884deSSumit Saxena
is_qport_service_type_supported(struct bnxt_re_dev * rdev)985acd884deSSumit Saxena static inline bool is_qport_service_type_supported(struct bnxt_re_dev *rdev)
986acd884deSSumit Saxena {
987acd884deSSumit Saxena return rdev->tc_rec[0].serv_type_enabled;
988acd884deSSumit Saxena }
989acd884deSSumit Saxena
is_bnxt_roce_queue(struct bnxt_re_dev * rdev,u8 ser_prof,u8 prof_type)990acd884deSSumit Saxena static inline bool is_bnxt_roce_queue(struct bnxt_re_dev *rdev, u8 ser_prof, u8 prof_type)
991acd884deSSumit Saxena {
992acd884deSSumit Saxena if (is_qport_service_type_supported(rdev))
993acd884deSSumit Saxena return (prof_type & HWRM_QUEUE_QPORTCFG_OUTPUT_QUEUE_ID1_SERVICE_PROFILE_TYPE_ROCE);
994acd884deSSumit Saxena else
995acd884deSSumit Saxena return (ser_prof == HWRM_QUEUE_QPORTCFG_OUTPUT_QUEUE_ID0_SERVICE_PROFILE_LOSSLESS_ROCE);
996acd884deSSumit Saxena }
997acd884deSSumit Saxena
is_bnxt_cnp_queue(struct bnxt_re_dev * rdev,u8 ser_prof,u8 prof_type)998acd884deSSumit Saxena static inline bool is_bnxt_cnp_queue(struct bnxt_re_dev *rdev, u8 ser_prof, u8 prof_type)
999acd884deSSumit Saxena {
1000acd884deSSumit Saxena if (is_qport_service_type_supported(rdev))
1001acd884deSSumit Saxena return (prof_type & HWRM_QUEUE_QPORTCFG_OUTPUT_QUEUE_ID1_SERVICE_PROFILE_TYPE_CNP);
1002acd884deSSumit Saxena else
1003acd884deSSumit Saxena return (ser_prof == HWRM_QUEUE_QPORTCFG_OUTPUT_QUEUE_ID0_SERVICE_PROFILE_LOSSY_ROCE_CNP);
1004acd884deSSumit Saxena }
1005acd884deSSumit Saxena
1006acd884deSSumit Saxena #define BNXT_RE_MAP_SH_PAGE 0x0
1007acd884deSSumit Saxena #define BNXT_RE_MAP_WC 0x1
1008acd884deSSumit Saxena #define BNXT_RE_DBR_PAGE 0x2
1009acd884deSSumit Saxena #define BNXT_RE_MAP_DB_RECOVERY_PAGE 0x3
1010acd884deSSumit Saxena
1011acd884deSSumit Saxena #define BNXT_RE_DBR_RECOV_USERLAND_TIMEOUT (20) /* 20 ms */
1012acd884deSSumit Saxena #define BNXT_RE_DBR_INT_TIME 5 /* ms */
1013acd884deSSumit Saxena #define BNXT_RE_PACING_EN_INT_THRESHOLD 50 /* Entries in DB FIFO */
1014acd884deSSumit Saxena #define BNXT_RE_PACING_ALGO_THRESHOLD 250 /* Entries in DB FIFO */
1015acd884deSSumit Saxena /* Percentage of DB FIFO depth */
1016acd884deSSumit Saxena #define BNXT_RE_PACING_DBQ_THRESHOLD BNXT_RE_PACING_DBQ_HIGH_WATERMARK
1017acd884deSSumit Saxena
1018acd884deSSumit Saxena #define BNXT_RE_PACING_ALARM_TH_MULTIPLE(ctx) (_is_chip_p7(ctx) ? 0 : 2)
1019acd884deSSumit Saxena
1020acd884deSSumit Saxena /*
1021acd884deSSumit Saxena * Maximum Percentage of configurable DB FIFO depth.
1022acd884deSSumit Saxena * The Doorbell FIFO depth is 0x2c00. But the DBR_REG_DB_THROTTLING register has only 12 bits
1023acd884deSSumit Saxena * to program the high watermark. This means user can configure maximum 36% only(4095/11264).
1024acd884deSSumit Saxena */
1025acd884deSSumit Saxena #define BNXT_RE_PACING_DBQ_HIGH_WATERMARK 36
1026acd884deSSumit Saxena
1027acd884deSSumit Saxena /* Default do_pacing value when there is no congestion */
1028acd884deSSumit Saxena #define BNXT_RE_DBR_DO_PACING_NO_CONGESTION 0x7F /* 1 in 512 probability */
1029acd884deSSumit Saxena
1030acd884deSSumit Saxena enum {
1031acd884deSSumit Saxena BNXT_RE_DBQ_EVENT_SCHED = 0,
1032acd884deSSumit Saxena BNXT_RE_DBR_PACING_EVENT = 1,
1033acd884deSSumit Saxena BNXT_RE_DBR_NQ_PACING_NOTIFICATION = 2,
1034acd884deSSumit Saxena };
1035acd884deSSumit Saxena
1036acd884deSSumit Saxena struct bnxt_re_dbq_work {
1037acd884deSSumit Saxena struct work_struct work;
1038acd884deSSumit Saxena struct bnxt_re_dev *rdev;
1039acd884deSSumit Saxena struct hwrm_async_event_cmpl cmpl;
1040acd884deSSumit Saxena u32 event;
1041acd884deSSumit Saxena };
1042acd884deSSumit Saxena
1043acd884deSSumit Saxena int bnxt_re_hwrm_qcaps(struct bnxt_re_dev *rdev);
1044acd884deSSumit Saxena int bnxt_re_enable_dbr_pacing(struct bnxt_re_dev *rdev);
1045acd884deSSumit Saxena int bnxt_re_disable_dbr_pacing(struct bnxt_re_dev *rdev);
1046acd884deSSumit Saxena int bnxt_re_set_dbq_throttling_reg(struct bnxt_re_dev *rdev,
1047acd884deSSumit Saxena u16 nq_id, u32 throttle);
1048acd884deSSumit Saxena void bnxt_re_pacing_alert(struct bnxt_re_dev *rdev);
1049acd884deSSumit Saxena int bnxt_re_hwrm_pri2cos_qcfg(struct bnxt_re_dev *rdev, struct bnxt_re_tc_rec *tc_rec,
1050acd884deSSumit Saxena u16 target_id);
1051acd884deSSumit Saxena void writel_fbsd(struct bnxt_softc *bp, u32, u8, u32);
1052acd884deSSumit Saxena u32 readl_fbsd(struct bnxt_softc *bp, u32, u8);
1053acd884deSSumit Saxena
bnxt_re_get_total_mr_mw_count(struct bnxt_re_dev * rdev)1054acd884deSSumit Saxena static inline unsigned int bnxt_re_get_total_mr_mw_count(struct bnxt_re_dev *rdev)
1055acd884deSSumit Saxena {
1056acd884deSSumit Saxena return (atomic_read(&rdev->stats.rsors.mr_count) +
1057acd884deSSumit Saxena atomic_read(&rdev->stats.rsors.mw_count));
1058acd884deSSumit Saxena }
1059acd884deSSumit Saxena
bnxt_re_set_def_pacing_threshold(struct bnxt_re_dev * rdev)1060acd884deSSumit Saxena static inline void bnxt_re_set_def_pacing_threshold(struct bnxt_re_dev *rdev)
1061acd884deSSumit Saxena {
1062acd884deSSumit Saxena rdev->qplib_res.pacing_data->pacing_th = rdev->pacing_algo_th;
1063acd884deSSumit Saxena rdev->qplib_res.pacing_data->alarm_th =
1064acd884deSSumit Saxena rdev->pacing_algo_th * BNXT_RE_PACING_ALARM_TH_MULTIPLE(rdev->chip_ctx);
1065acd884deSSumit Saxena }
1066acd884deSSumit Saxena
bnxt_re_set_def_do_pacing(struct bnxt_re_dev * rdev)1067acd884deSSumit Saxena static inline void bnxt_re_set_def_do_pacing(struct bnxt_re_dev *rdev)
1068acd884deSSumit Saxena {
1069acd884deSSumit Saxena rdev->qplib_res.pacing_data->do_pacing = rdev->dbr_def_do_pacing;
1070acd884deSSumit Saxena }
1071acd884deSSumit Saxena
bnxt_re_set_pacing_dev_state(struct bnxt_re_dev * rdev)1072acd884deSSumit Saxena static inline void bnxt_re_set_pacing_dev_state(struct bnxt_re_dev *rdev)
1073acd884deSSumit Saxena {
1074acd884deSSumit Saxena rdev->qplib_res.pacing_data->dev_err_state =
1075acd884deSSumit Saxena test_bit(BNXT_RE_FLAG_ERR_DEVICE_DETACHED, &rdev->flags);
1076acd884deSSumit Saxena }
1077acd884deSSumit Saxena #endif
1078