xref: /freebsd/sys/dev/bxe/bxe_dcb.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2007-2014 QLogic Corporation. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #ifndef BXE_DCB_H
33 #define BXE_DCB_H
34 
35 #define LLFC_DRIVER_TRAFFIC_TYPE_MAX 3 /* NW, iSCSI, FCoE */
36 struct bxe_dcbx_app_params {
37     uint32_t enabled;
38     uint32_t traffic_type_priority[LLFC_DRIVER_TRAFFIC_TYPE_MAX];
39 };
40 
41 #define DCBX_COS_MAX_NUM_E2 DCBX_E2E3_MAX_NUM_COS
42 /* bxe currently limits numbers of supported COSes to 3 to be extended to 6 */
43 #define BXE_MAX_COS_SUPPORT   3
44 #define DCBX_COS_MAX_NUM_E3B0 BXE_MAX_COS_SUPPORT
45 #define DCBX_COS_MAX_NUM      BXE_MAX_COS_SUPPORT
46 
47 struct bxe_dcbx_cos_params {
48     uint32_t bw_tbl;
49     uint32_t pri_bitmask;
50     /*
51      * strict priority: valid values are 0..5; 0 is highest priority.
52      * There can't be two COSes with the same priority.
53      */
54     uint8_t  strict;
55 #define BXE_DCBX_STRICT_INVALID                DCBX_COS_MAX_NUM
56 #define BXE_DCBX_STRICT_COS_HIGHEST            0
57 #define BXE_DCBX_STRICT_COS_NEXT_LOWER_PRI(sp) ((sp) + 1)
58     uint8_t  pauseable;
59 };
60 
61 struct bxe_dcbx_pg_params {
62     uint32_t enabled;
63     uint8_t  num_of_cos; /* valid COS entries */
64     struct bxe_dcbx_cos_params cos_params[DCBX_COS_MAX_NUM];
65 };
66 
67 struct bxe_dcbx_pfc_params {
68     uint32_t enabled;
69     uint32_t priority_non_pauseable_mask;
70 };
71 
72 struct bxe_dcbx_port_params {
73     struct bxe_dcbx_pfc_params pfc;
74     struct bxe_dcbx_pg_params  ets;
75     struct bxe_dcbx_app_params app;
76 };
77 
78 #define BXE_DCBX_CONFIG_INV_VALUE           (0xFFFFFFFF)
79 #define BXE_DCBX_OVERWRITE_SETTINGS_DISABLE 0
80 #define BXE_DCBX_OVERWRITE_SETTINGS_ENABLE  1
81 #define BXE_DCBX_OVERWRITE_SETTINGS_INVALID (BXE_DCBX_CONFIG_INV_VALUE)
82 #define BXE_IS_ETS_ENABLED(sc)              \
83     ((sc)->dcb_state == BXE_DCB_STATE_ON && \
84      (sc)->dcbx_port_params.ets.enabled)
85 
86 struct bxe_config_lldp_params {
87     uint32_t overwrite_settings;
88     uint32_t msg_tx_hold;
89     uint32_t msg_fast_tx;
90     uint32_t tx_credit_max;
91     uint32_t msg_tx_interval;
92     uint32_t tx_fast;
93 };
94 
95 struct bxe_lldp_params_get {
96     uint32_t ver_num;
97 #define LLDP_PARAMS_VER_NUM 2
98     struct bxe_config_lldp_params config_lldp_params;
99     /* The reserved field should follow in case the struct above will increase*/
100     uint32_t _reserved[20];
101     uint32_t admin_status;
102 #define LLDP_TX_ONLY  0x01
103 #define LLDP_RX_ONLY  0x02
104 #define LLDP_TX_RX    0x03
105 #define LLDP_DISABLED 0x04
106     uint32_t remote_chassis_id[REM_CHASSIS_ID_STAT_LEN];
107     uint32_t remote_port_id[REM_PORT_ID_STAT_LEN];
108     uint32_t local_chassis_id[LOCAL_CHASSIS_ID_STAT_LEN];
109     uint32_t local_port_id[LOCAL_PORT_ID_STAT_LEN];
110 };
111 
112 struct bxe_admin_priority_app_table {
113     uint32_t valid;
114     uint32_t priority;
115 #define INVALID_TRAFFIC_TYPE_PRIORITY   (0xFFFFFFFF)
116     uint32_t traffic_type;
117 #define TRAFFIC_TYPE_ETH        0
118 #define TRAFFIC_TYPE_PORT       1
119     uint32_t app_id;
120 };
121 
122 #define DCBX_CONFIG_MAX_APP_PROTOCOL 4
123 struct bxe_config_dcbx_params {
124     uint32_t overwrite_settings;
125     uint32_t admin_dcbx_version;
126     uint32_t admin_ets_enable;
127     uint32_t admin_pfc_enable;
128     uint32_t admin_tc_supported_tx_enable;
129     uint32_t admin_ets_configuration_tx_enable;
130     uint32_t admin_ets_recommendation_tx_enable;
131     uint32_t admin_pfc_tx_enable;
132     uint32_t admin_application_priority_tx_enable;
133     uint32_t admin_ets_willing;
134     uint32_t admin_ets_reco_valid;
135     uint32_t admin_pfc_willing;
136     uint32_t admin_app_priority_willing;
137     uint32_t admin_configuration_bw_precentage[8];
138     uint32_t admin_configuration_ets_pg[8];
139     uint32_t admin_recommendation_bw_precentage[8];
140     uint32_t admin_recommendation_ets_pg[8];
141     uint32_t admin_pfc_bitmap;
142     struct bxe_admin_priority_app_table
143         admin_priority_app_table[DCBX_CONFIG_MAX_APP_PROTOCOL];
144     uint32_t admin_default_priority;
145 };
146 
147 //#define DCBX_PARAMS_VER_NUM 3 /* XXX conflict with common_uif.h */
148 struct bxe_dcbx_params_get {
149     uint32_t ver_num;
150     uint32_t dcb_state;
151     uint32_t dcbx_enabled;
152     struct bxe_config_dcbx_params config_dcbx_params;
153     /* The reserved field should follow in case the struct above will increase*/
154     uint32_t _reserved[19];
155 
156     uint32_t dcb_current_state;
157 #define BXE_DCBX_CURRENT_STATE_IS_SYNC            (1 << 0)
158 #define BXE_PFC_IS_CURRENTLY_OPERATIONAL          (1 << 1)
159 #define BXE_ETS_IS_CURRENTLY_OPERATIONAL          (1 << 2)
160 #define BXE_PRIORITY_TAGGING_IS_CURRENTLY_OPERATIONAL     (1 << 3)
161 
162     uint32_t local_tc_supported;
163     uint32_t local_pfc_caps;
164     uint32_t remote_tc_supported;
165     uint32_t remote_pfc_cap;
166     uint32_t remote_ets_willing;
167     uint32_t remote_ets_reco_valid;
168     uint32_t remote_pfc_willing;
169     uint32_t remote_app_priority_willing;
170     uint32_t remote_configuration_bw_precentage[8];
171     uint32_t remote_configuration_ets_pg[8];
172     uint32_t remote_recommendation_bw_precentage[8];
173     uint32_t remote_recommendation_ets_pg[8];
174     uint32_t remote_pfc_bitmap;
175     struct bxe_admin_priority_app_table
176         remote_priority_app_table[DCBX_MAX_APP_PROTOCOL];
177     uint32_t local_ets_enable;
178     uint32_t local_pfc_enable;
179     uint32_t local_configuration_bw_precentage[8];
180     uint32_t local_configuration_ets_pg[8];
181     uint32_t local_pfc_bitmap;
182     struct bxe_admin_priority_app_table
183         local_priority_app_table[DCBX_MAX_APP_PROTOCOL];
184     uint32_t pfc_mismatch;
185     uint32_t priority_app_mismatch;
186     uint32_t dcbx_frames_sent;
187     uint32_t dcbx_frames_received;
188     uint32_t pfc_frames_sent[2];
189     uint32_t pfc_frames_received[2];
190 };
191 
192 struct bxe_dcbx_params_set {
193     uint32_t ver_num;
194     uint32_t dcb_state;
195     uint32_t dcbx_enabled;
196     struct bxe_config_dcbx_params config_dcbx_params;
197 };
198 
199 #define GET_FLAGS(flags, bits)   ((flags) & (bits))
200 #define SET_FLAGS(flags, bits)   ((flags) |= (bits))
201 #define RESET_FLAGS(flags, bits) ((flags) &= ~(bits))
202 
203 enum {
204     DCBX_READ_LOCAL_MIB,
205     DCBX_READ_REMOTE_MIB
206 };
207 
208 #define ETH_TYPE_FCOE  (0x8906)
209 #define TCP_PORT_ISCSI (0xCBC)
210 
211 #define PFC_VALUE_FRAME_SIZE (512)
212 #define PFC_QUANTA_IN_NANOSEC_FROM_SPEED_MEGA(mega_speed) \
213     ((1000 * PFC_VALUE_FRAME_SIZE)/(mega_speed))
214 
215 #define PFC_BRB1_REG_HIGH_LLFC_LOW_THRESHOLD  130
216 #define PFC_BRB1_REG_HIGH_LLFC_HIGH_THRESHOLD 170
217 
218 struct cos_entry_help_data {
219     uint32_t pri_join_mask;
220     uint32_t cos_bw;
221     uint8_t  strict;
222     uint8_t  pausable;
223 };
224 
225 struct cos_help_data {
226     struct cos_entry_help_data data[DCBX_COS_MAX_NUM];
227     uint8_t num_of_cos;
228 };
229 
230 #define DCBX_ILLEGAL_PG      (0xFF)
231 #define DCBX_PFC_PRI_MASK    (0xFF)
232 #define DCBX_STRICT_PRIORITY (15)
233 #define DCBX_INVALID_COS_BW  (0xFFFFFFFF)
234 #define DCBX_PFC_PRI_NON_PAUSE_MASK(sc)                      \
235     ((sc)->dcbx_port_params.pfc.priority_non_pauseable_mask)
236 #define DCBX_PFC_PRI_PAUSE_MASK(sc)             \
237     ((uint8_t)~DCBX_PFC_PRI_NON_PAUSE_MASK(sc))
238 #define DCBX_PFC_PRI_GET_PAUSE(sc, pg_pri)     \
239     ((pg_pri) & (DCBX_PFC_PRI_PAUSE_MASK(sc)))
240 #define DCBX_PFC_PRI_GET_NON_PAUSE(sc, pg_pri)   \
241     (DCBX_PFC_PRI_NON_PAUSE_MASK(sc) & (pg_pri))
242 #define DCBX_IS_PFC_PRI_SOME_PAUSE(sc, pg_pri) \
243     (0 != DCBX_PFC_PRI_GET_PAUSE(sc, pg_pri))
244 #define IS_DCBX_PFC_PRI_ONLY_PAUSE(sc, pg_pri)         \
245     (pg_pri == DCBX_PFC_PRI_GET_PAUSE((sc), (pg_pri)))
246 #define IS_DCBX_PFC_PRI_ONLY_NON_PAUSE(sc, pg_pri)           \
247     ((pg_pri) == DCBX_PFC_PRI_GET_NON_PAUSE((sc), (pg_pri)))
248 #define IS_DCBX_PFC_PRI_MIX_PAUSE(sc, pg_pri)            \
249     (!(IS_DCBX_PFC_PRI_ONLY_NON_PAUSE((sc), (pg_pri)) || \
250        IS_DCBX_PFC_PRI_ONLY_PAUSE((sc), (pg_pri))))
251 
252 struct pg_entry_help_data {
253     uint8_t  num_of_dif_pri;
254     uint8_t  pg;
255     uint32_t pg_priority;
256 };
257 
258 struct pg_help_data {
259     struct pg_entry_help_data data[LLFC_DRIVER_TRAFFIC_TYPE_MAX];
260     uint8_t num_of_pg;
261 };
262 
263 /* forward DCB/PFC related declarations */
264 struct bxe_softc;
265 /* void bxe_dcbx_update(struct work_struct *work); */
266 void bxe_dcbx_init_params(struct bxe_softc *sc);
267 void bxe_dcbx_set_state(struct bxe_softc *sc, uint8_t dcb_on, uint32_t dcbx_enabled);
268 int  bxe_dcb_get_lldp_params_ioctl(struct bxe_softc *sc, void *uaddr);
269 int  bxe_dcb_get_dcbx_params_ioctl(struct bxe_softc *sc, void *uaddr);
270 int  bxe_dcb_set_dcbx_params_ioctl(struct bxe_softc *sc, void *uaddr);
271 
272 enum {
273     BXE_DCBX_STATE_NEG_RECEIVED = 0x1,
274     BXE_DCBX_STATE_TX_PAUSED,
275     BXE_DCBX_STATE_TX_RELEASED
276 };
277 
278 void bxe_dcbx_set_params(struct bxe_softc *sc, uint32_t state);
279 void bxe_dcbx_pmf_update(struct bxe_softc *sc);
280 
281 #endif /* BXE_DCB_H */
282 
283