1 /*
2  * Broadcom NetXtreme-E RoCE driver.
3  *
4  * Copyright (c) 2016 - 2017, Broadcom. All rights reserved.  The term
5  * Broadcom refers to Broadcom Limited and/or its subsidiaries.
6  *
7  * This software is available to you under a choice of one of two
8  * licenses.  You may choose to be licensed under the terms of the GNU
9  * General Public License (GPL) Version 2, available from the file
10  * COPYING in the main directory of this source tree, or the
11  * BSD license below:
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in
21  *    the documentation and/or other materials provided with the
22  *    distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Description: Slow Path Operators (header)
37  *
38  */
39 
40 #ifndef __BNXT_RE_H__
41 #define __BNXT_RE_H__
42 #include "hw_counters.h"
43 #define ROCE_DRV_MODULE_NAME		"bnxt_re"
44 
45 #define BNXT_RE_DESC	"Broadcom NetXtreme-C/E RoCE Driver"
46 
47 #define BNXT_RE_PAGE_SHIFT_1G		(30)
48 #define BNXT_RE_PAGE_SIZE_SUPPORTED	0x7FFFF000 /* 4kb - 1G */
49 
50 #define BNXT_RE_MAX_MR_SIZE_LOW		BIT_ULL(BNXT_RE_PAGE_SHIFT_1G)
51 #define BNXT_RE_MAX_MR_SIZE_HIGH	BIT_ULL(39)
52 #define BNXT_RE_MAX_MR_SIZE		BNXT_RE_MAX_MR_SIZE_HIGH
53 
54 #define BNXT_RE_MAX_QPC_COUNT		(64 * 1024)
55 #define BNXT_RE_MAX_MRW_COUNT		(64 * 1024)
56 #define BNXT_RE_MAX_SRQC_COUNT		(64 * 1024)
57 #define BNXT_RE_MAX_CQ_COUNT		(64 * 1024)
58 #define BNXT_RE_MAX_MRW_COUNT_64K	(64 * 1024)
59 #define BNXT_RE_MAX_MRW_COUNT_256K	(256 * 1024)
60 
61 /* Number of MRs to reserve for PF, leaving remainder for VFs */
62 #define BNXT_RE_RESVD_MR_FOR_PF         (32 * 1024)
63 #define BNXT_RE_MAX_GID_PER_VF          128
64 
65 /*
66  * Percentage of resources of each type reserved for PF.
67  * Remaining resources are divided equally among VFs.
68  * [0, 100]
69  */
70 #define BNXT_RE_PCT_RSVD_FOR_PF         50
71 
72 #define BNXT_RE_UD_QP_HW_STALL		0x400000
73 
74 #define BNXT_RE_RQ_WQE_THRESHOLD	32
75 
76 /*
77  * Setting the default ack delay value to 16, which means
78  * the default timeout is approx. 260ms(4 usec * 2 ^(timeout))
79  */
80 
81 #define BNXT_RE_DEFAULT_ACK_DELAY	16
82 
83 struct bnxt_re_ring_attr {
84 	dma_addr_t	*dma_arr;
85 	int		pages;
86 	int		type;
87 	u32		depth;
88 	u32		lrid; /* Logical ring id */
89 	u8		mode;
90 };
91 
92 struct bnxt_re_sqp_entries {
93 	struct bnxt_qplib_sge sge;
94 	u64 wrid;
95 	/* For storing the actual qp1 cqe */
96 	struct bnxt_qplib_cqe cqe;
97 	struct bnxt_re_qp *qp1_qp;
98 };
99 
100 #define BNXT_RE_MAX_GSI_SQP_ENTRIES	1024
101 struct bnxt_re_gsi_context {
102 	struct	bnxt_re_qp *gsi_qp;
103 	struct	bnxt_re_qp *gsi_sqp;
104 	struct	bnxt_re_ah *gsi_sah;
105 	struct	bnxt_re_sqp_entries *sqp_tbl;
106 };
107 
108 #define BNXT_RE_MIN_MSIX		2
109 #define BNXT_RE_MAX_MSIX		9
110 #define BNXT_RE_AEQ_IDX			0
111 #define BNXT_RE_NQ_IDX			1
112 #define BNXT_RE_GEN_P5_MAX_VF		64
113 
114 struct bnxt_re_dev {
115 	struct ib_device		ibdev;
116 	struct list_head		list;
117 	unsigned long			flags;
118 #define BNXT_RE_FLAG_NETDEV_REGISTERED		0
119 #define BNXT_RE_FLAG_GOT_MSIX			2
120 #define BNXT_RE_FLAG_HAVE_L2_REF		3
121 #define BNXT_RE_FLAG_RCFW_CHANNEL_EN		4
122 #define BNXT_RE_FLAG_QOS_WORK_REG		5
123 #define BNXT_RE_FLAG_RESOURCES_ALLOCATED	7
124 #define BNXT_RE_FLAG_RESOURCES_INITIALIZED	8
125 #define BNXT_RE_FLAG_ERR_DEVICE_DETACHED       17
126 #define BNXT_RE_FLAG_ISSUE_ROCE_STATS          29
127 	struct net_device		*netdev;
128 	struct notifier_block		nb;
129 	unsigned int			version, major, minor;
130 	struct bnxt_qplib_chip_ctx	*chip_ctx;
131 	struct bnxt_en_dev		*en_dev;
132 	int				num_msix;
133 
134 	int				id;
135 
136 	struct delayed_work		worker;
137 	u8				cur_prio_map;
138 	u16				active_speed;
139 	u8				active_width;
140 
141 	/* FP Notification Queue (CQ & SRQ) */
142 	struct tasklet_struct		nq_task;
143 
144 	/* RCFW Channel */
145 	struct bnxt_qplib_rcfw		rcfw;
146 
147 	/* NQ */
148 	struct bnxt_qplib_nq		nq[BNXT_RE_MAX_MSIX];
149 
150 	/* Device Resources */
151 	struct bnxt_qplib_dev_attr	dev_attr;
152 	struct bnxt_qplib_ctx		qplib_ctx;
153 	struct bnxt_qplib_res		qplib_res;
154 	struct bnxt_qplib_dpi		dpi_privileged;
155 
156 	atomic_t			qp_count;
157 	struct mutex			qp_lock;	/* protect qp list */
158 	struct list_head		qp_list;
159 
160 	atomic_t			cq_count;
161 	atomic_t			srq_count;
162 	atomic_t			mr_count;
163 	atomic_t			mw_count;
164 	atomic_t			ah_count;
165 	atomic_t			pd_count;
166 	/* Max of 2 lossless traffic class supported per port */
167 	u16				cosq[2];
168 
169 	/* QP for handling QP1 packets */
170 	struct bnxt_re_gsi_context	gsi_ctx;
171 	struct bnxt_re_stats		stats;
172 	atomic_t nq_alloc_cnt;
173 	u32 is_virtfn;
174 	u32 num_vfs;
175 };
176 
177 #define to_bnxt_re_dev(ptr, member)	\
178 	container_of((ptr), struct bnxt_re_dev, member)
179 
180 #define BNXT_RE_ROCE_V1_PACKET		0
181 #define BNXT_RE_ROCEV2_IPV4_PACKET	2
182 #define BNXT_RE_ROCEV2_IPV6_PACKET	3
183 
184 static inline struct device *rdev_to_dev(struct bnxt_re_dev *rdev)
185 {
186 	if (rdev)
187 		return  &rdev->ibdev.dev;
188 	return NULL;
189 }
190 #endif
191