blob: 64c2e7cfa82282f1254c47bfde482d9803cc2ba4 [file] [log] [blame]
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -04001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -04003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040031 */
32
33#include <linux/types.h>
34#include <asm/byteorder.h>
35#include <linux/bitops.h>
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -040036#include <linux/dcbnl.h>
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040037#include <linux/errno.h>
38#include <linux/kernel.h>
39#include <linux/slab.h>
40#include <linux/string.h>
41#include "qed.h"
42#include "qed_cxt.h"
43#include "qed_dcbx.h"
44#include "qed_hsi.h"
45#include "qed_sp.h"
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -040046#include "qed_sriov.h"
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -040047#ifdef CONFIG_DCB
48#include <linux/qed/qed_eth_if.h>
49#endif
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040050
51#define QED_DCBX_MAX_MIB_READ_TRY (100)
52#define QED_ETH_TYPE_DEFAULT (0)
53#define QED_ETH_TYPE_ROCE (0x8915)
54#define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7)
55#define QED_ETH_TYPE_FCOE (0x8906)
56#define QED_TCP_PORT_ISCSI (0xCBC)
57
58#define QED_DCBX_INVALID_PRIORITY 0xFF
59
60/* Get Traffic Class from priority traffic class table, 4 bits represent
61 * the traffic class corresponding to the priority.
62 */
63#define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \
64 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
65
66static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = {
sudarsana.kalluru@cavium.comc8fcd132017-04-24 20:59:10 -070067 {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_ISCSI},
68 {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_FCOE},
69 {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_ETH_ROCE},
70 {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_ETH_ROCE},
71 {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH},
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040072};
73
74static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
75{
76 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
77 DCBX_APP_SF_ETHTYPE);
78}
79
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -040080static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
81{
82 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
83
84 /* Old MFW */
85 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
86 return qed_dcbx_app_ethtype(app_info_bitmap);
87
88 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
89}
90
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040091static bool qed_dcbx_app_port(u32 app_info_bitmap)
92{
93 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
94 DCBX_APP_SF_PORT);
95}
96
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -040097static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040098{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -040099 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
100
101 /* Old MFW */
102 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
103 return qed_dcbx_app_port(app_info_bitmap);
104
105 return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400106}
107
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400108static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400109{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400110 bool ethtype;
111
112 if (ieee)
113 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
114 else
115 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
116
117 return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400118}
119
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400120static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400121{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400122 bool port;
123
124 if (ieee)
125 port = qed_dcbx_ieee_app_port(app_info_bitmap,
126 DCBX_APP_SF_IEEE_TCP_PORT);
127 else
128 port = qed_dcbx_app_port(app_info_bitmap);
129
130 return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400131}
132
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400133static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400134{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400135 bool ethtype;
136
137 if (ieee)
138 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
139 else
140 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
141
142 return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400143}
144
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400145static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400146{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400147 bool ethtype;
148
149 if (ieee)
150 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
151 else
152 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
153
154 return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400155}
156
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400157static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400158{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400159 bool port;
160
161 if (ieee)
162 port = qed_dcbx_ieee_app_port(app_info_bitmap,
163 DCBX_APP_SF_IEEE_UDP_PORT);
164 else
165 port = qed_dcbx_app_port(app_info_bitmap);
166
167 return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400168}
169
170static void
171qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data)
172{
173 enum dcbx_protocol_type id;
174 int i;
175
176 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n",
177 p_data->dcbx_enabled);
178
179 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
180 id = qed_dcbx_app_update[i].id;
181
182 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
183 "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
184 qed_dcbx_app_update[i].name, p_data->arr[id].update,
185 p_data->arr[id].enable, p_data->arr[id].priority,
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300186 p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400187 }
188}
189
190static void
191qed_dcbx_set_params(struct qed_dcbx_results *p_data,
192 struct qed_hw_info *p_info,
193 bool enable,
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400194 u8 prio,
195 u8 tc,
196 enum dcbx_protocol_type type,
197 enum qed_pci_personality personality)
198{
199 /* PF update ramrod data */
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400200 p_data->arr[type].enable = enable;
201 p_data->arr[type].priority = prio;
202 p_data->arr[type].tc = tc;
Sudarsana Reddy Kallurudfc268f2017-05-29 09:53:06 +0300203 if (enable)
204 p_data->arr[type].update = UPDATE_DCB;
205 else
206 p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400207
208 /* QM reconf data */
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300209 if (p_info->personality == personality)
210 p_info->offload_tc = tc;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400211}
212
213/* Update app protocol data and hw_info fields with the TLV info */
214static void
215qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
216 struct qed_hwfn *p_hwfn,
217 bool enable,
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400218 u8 prio, u8 tc, enum dcbx_protocol_type type)
219{
220 struct qed_hw_info *p_info = &p_hwfn->hw_info;
221 enum qed_pci_personality personality;
222 enum dcbx_protocol_type id;
223 char *name;
224 int i;
225
226 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
227 id = qed_dcbx_app_update[i].id;
228
229 if (type != id)
230 continue;
231
232 personality = qed_dcbx_app_update[i].personality;
233 name = qed_dcbx_app_update[i].name;
234
Sudarsana Reddy Kallurudfc268f2017-05-29 09:53:06 +0300235 qed_dcbx_set_params(p_data, p_info, enable,
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400236 prio, tc, type, personality);
237 }
238}
239
240static bool
241qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
242 u32 app_prio_bitmap,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400243 u16 id, enum dcbx_protocol_type *type, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400244{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400245 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400246 *type = DCBX_PROTOCOL_FCOE;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400247 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400248 *type = DCBX_PROTOCOL_ROCE;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400249 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400250 *type = DCBX_PROTOCOL_ISCSI;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400251 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400252 *type = DCBX_PROTOCOL_ETH;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400253 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400254 *type = DCBX_PROTOCOL_ROCE_V2;
255 } else {
256 *type = DCBX_MAX_PROTOCOL_TYPE;
257 DP_ERR(p_hwfn,
258 "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
259 id, app_prio_bitmap);
260 return false;
261 }
262
263 return true;
264}
265
266/* Parse app TLV's to update TC information in hw_info structure for
267 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
268 */
269static int
270qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
271 struct qed_dcbx_results *p_data,
272 struct dcbx_app_priority_entry *p_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400273 u32 pri_tc_tbl, int count, u8 dcbx_version)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400274{
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400275 enum dcbx_protocol_type type;
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700276 u8 tc, priority_map;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400277 bool enable, ieee;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400278 u16 protocol_id;
Dan Carpenter54b94302016-05-23 13:19:35 +0300279 int priority;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400280 int i;
281
282 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
283
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400284 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400285 /* Parse APP TLV */
286 for (i = 0; i < count; i++) {
287 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
288 DCBX_APP_PROTOCOL_ID);
289 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
290 DCBX_APP_PRI_MAP);
291 priority = ffs(priority_map) - 1;
292 if (priority < 0) {
293 DP_ERR(p_hwfn, "Invalid priority\n");
294 return -EINVAL;
295 }
296
297 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
298 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400299 protocol_id, &type, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400300 /* ETH always have the enable bit reset, as it gets
301 * vlan information per packet. For other protocols,
302 * should be set according to the dcbx_enabled
303 * indication, but we only got here if there was an
304 * app tlv for the protocol, so dcbx must be enabled.
305 */
Sudarsana Reddy Kalluruec7c7f52016-05-24 05:25:23 -0400306 enable = !(type == DCBX_PROTOCOL_ETH);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400307
Sudarsana Reddy Kallurudfc268f2017-05-29 09:53:06 +0300308 qed_dcbx_update_app_info(p_data, p_hwfn, enable,
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400309 priority, tc, type);
310 }
311 }
312
313 /* If RoCE-V2 TLV is not detected, driver need to use RoCE app
314 * data for RoCE-v2 not the default app data.
315 */
316 if (!p_data->arr[DCBX_PROTOCOL_ROCE_V2].update &&
317 p_data->arr[DCBX_PROTOCOL_ROCE].update) {
318 tc = p_data->arr[DCBX_PROTOCOL_ROCE].tc;
319 priority = p_data->arr[DCBX_PROTOCOL_ROCE].priority;
Sudarsana Reddy Kallurudfc268f2017-05-29 09:53:06 +0300320 qed_dcbx_update_app_info(p_data, p_hwfn, true,
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400321 priority, tc, DCBX_PROTOCOL_ROCE_V2);
322 }
323
324 /* Update ramrod protocol data and hw_info fields
325 * with default info when corresponding APP TLV's are not detected.
326 * The enabled field has a different logic for ethernet as only for
327 * ethernet dcb should disabled by default, as the information arrives
328 * from the OS (unless an explicit app tlv was present).
329 */
330 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
331 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
332 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
333 if (p_data->arr[type].update)
334 continue;
335
Sudarsana Reddy Kallurudfc268f2017-05-29 09:53:06 +0300336 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
337 qed_dcbx_update_app_info(p_data, p_hwfn, enable,
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400338 priority, tc, type);
339 }
340
341 return 0;
342}
343
344/* Parse app TLV's to update TC information in hw_info structure for
345 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
346 */
347static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
348{
349 struct dcbx_app_priority_feature *p_app;
350 struct dcbx_app_priority_entry *p_tbl;
351 struct qed_dcbx_results data = { 0 };
352 struct dcbx_ets_feature *p_ets;
353 struct qed_hw_info *p_info;
354 u32 pri_tc_tbl, flags;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400355 u8 dcbx_version;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400356 int num_entries;
357 int rc = 0;
358
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400359 flags = p_hwfn->p_dcbx_info->operational.flags;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400360 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400361
362 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
363 p_tbl = p_app->app_pri_tbl;
364
365 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
366 pri_tc_tbl = p_ets->pri_tc_tbl[0];
367
368 p_info = &p_hwfn->hw_info;
369 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
370
371 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400372 num_entries, dcbx_version);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400373 if (rc)
374 return rc;
375
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300376 p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
377 DCBX_ETS_MAX_TCS);
378 p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400379 data.pf_id = p_hwfn->rel_pf_id;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400380 data.dcbx_enabled = !!dcbx_version;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400381
382 qed_dcbx_dp_protocol(p_hwfn, &data);
383
384 memcpy(&p_hwfn->p_dcbx_info->results, &data,
385 sizeof(struct qed_dcbx_results));
386
387 return 0;
388}
389
390static int
391qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
392 struct qed_ptt *p_ptt,
393 struct qed_dcbx_mib_meta_data *p_data,
394 enum qed_mib_read_type type)
395{
396 u32 prefix_seq_num, suffix_seq_num;
397 int read_count = 0;
398 int rc = 0;
399
400 /* The data is considered to be valid only if both sequence numbers are
401 * the same.
402 */
403 do {
404 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
405 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
406 p_data->addr, p_data->size);
407 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
408 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
409 } else {
410 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
411 p_data->addr, p_data->size);
412 prefix_seq_num = p_data->mib->prefix_seq_num;
413 suffix_seq_num = p_data->mib->suffix_seq_num;
414 }
415 read_count++;
416
417 DP_VERBOSE(p_hwfn,
418 QED_MSG_DCB,
419 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
420 type, read_count, prefix_seq_num, suffix_seq_num);
421 } while ((prefix_seq_num != suffix_seq_num) &&
422 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
423
424 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
425 DP_ERR(p_hwfn,
426 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
427 type, read_count, prefix_seq_num, suffix_seq_num);
428 rc = -EIO;
429 }
430
431 return rc;
432}
433
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400434static void
435qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
436 struct qed_dcbx_app_prio *p_prio,
437 struct qed_dcbx_results *p_results)
438{
439 u8 val;
440
441 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
442 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
443 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
444 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
445
446 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
447 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
448 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
449
450 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
451 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
452 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
453 p_prio->roce_v2 = val;
454 }
455
456 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
457 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
458 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
459
460 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
461 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
462 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
463
464 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
465 p_results->arr[DCBX_PROTOCOL_ETH].enable)
466 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
467
468 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
469 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
470 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
471 p_prio->eth);
472}
473
474static void
475qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
476 struct dcbx_app_priority_feature *p_app,
477 struct dcbx_app_priority_entry *p_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400478 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400479{
480 struct qed_app_entry *entry;
481 u8 pri_map;
482 int i;
483
484 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
485 DCBX_APP_WILLING);
486 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
487 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
488 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
489 DCBX_APP_NUM_ENTRIES);
490 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
491 entry = &p_params->app_entry[i];
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400492 if (ieee) {
493 u8 sf_ieee;
494 u32 val;
495
496 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
497 DCBX_APP_SF_IEEE);
498 switch (sf_ieee) {
499 case DCBX_APP_SF_IEEE_RESERVED:
500 /* Old MFW */
501 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
502 DCBX_APP_SF);
503 entry->sf_ieee = val ?
504 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
505 QED_DCBX_SF_IEEE_ETHTYPE;
506 break;
507 case DCBX_APP_SF_IEEE_ETHTYPE:
508 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
509 break;
510 case DCBX_APP_SF_IEEE_TCP_PORT:
511 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
512 break;
513 case DCBX_APP_SF_IEEE_UDP_PORT:
514 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
515 break;
516 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
517 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
518 break;
519 }
520 } else {
521 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
522 DCBX_APP_SF));
523 }
524
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400525 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
526 entry->prio = ffs(pri_map) - 1;
527 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
528 DCBX_APP_PROTOCOL_ID);
529 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
530 entry->proto_id,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400531 &entry->proto_type, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400532 }
533
534 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
535 "APP params: willing %d, valid %d error = %d\n",
536 p_params->app_willing, p_params->app_valid,
537 p_params->app_error);
538}
539
540static void
541qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
542 u32 pfc, struct qed_dcbx_params *p_params)
543{
544 u8 pfc_map;
545
546 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
547 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
548 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
549 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
550 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
551 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
552 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
553 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
554 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
555 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
556 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
557 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
558
559 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -0700560 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
561 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
562 p_params->pfc.enabled);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400563}
564
565static void
566qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
567 struct dcbx_ets_feature *p_ets,
568 struct qed_dcbx_params *p_params)
569{
570 u32 bw_map[2], tsa_map[2], pri_map;
571 int i;
572
573 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
574 DCBX_ETS_WILLING);
575 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
576 DCBX_ETS_ENABLED);
577 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
578 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
579 DCBX_ETS_MAX_TCS);
580 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -0700581 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
582 p_params->ets_willing, p_params->ets_enabled,
583 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
584 p_params->max_ets_tc);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400585
sudarsana.kalluru@cavium.com66367da2017-04-19 03:19:52 -0700586 if (p_params->ets_enabled && !p_params->max_ets_tc) {
587 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
588 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
589 "ETS params: max_ets_tc is forced to %d\n",
590 p_params->max_ets_tc);
591 }
592
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400593 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
594 * encoded in a type u32 array of size 2.
595 */
596 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
597 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
598 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
599 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
Sudarsana Reddy Kalluruc0c45a62016-08-08 21:57:40 -0400600 pri_map = p_ets->pri_tc_tbl[0];
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400601 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
602 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
603 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
604 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
605 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
606 "elem %d bw_tbl %x tsa_tbl %x\n",
607 i, p_params->ets_tc_bw_tbl[i],
608 p_params->ets_tc_tsa_tbl[i]);
609 }
610}
611
612static void
613qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
614 struct dcbx_app_priority_feature *p_app,
615 struct dcbx_app_priority_entry *p_tbl,
616 struct dcbx_ets_feature *p_ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400617 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400618{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400619 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400620 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
621 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
622}
623
624static void
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700625qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400626{
627 struct dcbx_features *p_feat;
628
629 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
630 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
631 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400632 p_feat->pfc, &params->local.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400633 params->local.valid = true;
634}
635
636static void
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700637qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400638{
639 struct dcbx_features *p_feat;
640
641 p_feat = &p_hwfn->p_dcbx_info->remote.features;
642 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
643 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400644 p_feat->pfc, &params->remote.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400645 params->remote.valid = true;
646}
647
648static void
649qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400650 struct qed_dcbx_get *params)
651{
652 struct qed_dcbx_operational_params *p_operational;
653 struct qed_dcbx_results *p_results;
654 struct dcbx_features *p_feat;
655 bool enabled, err;
656 u32 flags;
657 bool val;
658
659 flags = p_hwfn->p_dcbx_info->operational.flags;
660
661 /* If DCBx version is non zero, then negotiation
662 * was successfuly performed
663 */
664 p_operational = &params->operational;
665 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
666 DCBX_CONFIG_VERSION_DISABLED);
667 if (!enabled) {
668 p_operational->enabled = enabled;
669 p_operational->valid = false;
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -0700670 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400671 return;
672 }
673
674 p_feat = &p_hwfn->p_dcbx_info->operational.features;
675 p_results = &p_hwfn->p_dcbx_info->results;
676
677 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
678 DCBX_CONFIG_VERSION_IEEE);
679 p_operational->ieee = val;
680 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
681 DCBX_CONFIG_VERSION_CEE);
682 p_operational->cee = val;
683
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -0700684 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
685 DCBX_CONFIG_VERSION_STATIC);
686 p_operational->local = val;
687
688 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
689 "Version support: ieee %d, cee %d, static %d\n",
690 p_operational->ieee, p_operational->cee,
691 p_operational->local);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400692
693 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
694 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400695 p_feat->pfc, &params->operational.params,
696 p_operational->ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400697 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
698 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
699 p_operational->err = err;
700 p_operational->enabled = enabled;
701 p_operational->valid = true;
702}
703
704static void
705qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400706 struct qed_dcbx_get *params)
707{
708 struct lldp_config_params_s *p_local;
709
710 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
711
712 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
713 ARRAY_SIZE(p_local->local_chassis_id));
714 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
715 ARRAY_SIZE(p_local->local_port_id));
716}
717
718static void
719qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400720 struct qed_dcbx_get *params)
721{
722 struct lldp_status_params_s *p_remote;
723
724 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
725
726 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
727 ARRAY_SIZE(p_remote->peer_chassis_id));
728 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
729 ARRAY_SIZE(p_remote->peer_port_id));
730}
731
732static int
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700733qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400734 enum qed_mib_read_type type)
735{
736 switch (type) {
737 case QED_DCBX_REMOTE_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700738 qed_dcbx_get_remote_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400739 break;
740 case QED_DCBX_LOCAL_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700741 qed_dcbx_get_local_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400742 break;
743 case QED_DCBX_OPERATIONAL_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700744 qed_dcbx_get_operational_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400745 break;
746 case QED_DCBX_REMOTE_LLDP_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700747 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400748 break;
749 case QED_DCBX_LOCAL_LLDP_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700750 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400751 break;
752 default:
753 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
754 return -EINVAL;
755 }
756
757 return 0;
758}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400759
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400760static int
761qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
762{
763 struct qed_dcbx_mib_meta_data data;
764 int rc = 0;
765
766 memset(&data, 0, sizeof(data));
767 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
768 lldp_config_params);
769 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
770 data.size = sizeof(struct lldp_config_params_s);
771 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
772
773 return rc;
774}
775
776static int
777qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
778 struct qed_ptt *p_ptt,
779 enum qed_mib_read_type type)
780{
781 struct qed_dcbx_mib_meta_data data;
782 int rc = 0;
783
784 memset(&data, 0, sizeof(data));
785 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
786 lldp_status_params);
787 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
788 data.size = sizeof(struct lldp_status_params_s);
789 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
790
791 return rc;
792}
793
794static int
795qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
796 struct qed_ptt *p_ptt,
797 enum qed_mib_read_type type)
798{
799 struct qed_dcbx_mib_meta_data data;
800 int rc = 0;
801
802 memset(&data, 0, sizeof(data));
803 data.addr = p_hwfn->mcp_info->port_addr +
804 offsetof(struct public_port, operational_dcbx_mib);
805 data.mib = &p_hwfn->p_dcbx_info->operational;
806 data.size = sizeof(struct dcbx_mib);
807 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
808
809 return rc;
810}
811
812static int
813qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
814 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
815{
816 struct qed_dcbx_mib_meta_data data;
817 int rc = 0;
818
819 memset(&data, 0, sizeof(data));
820 data.addr = p_hwfn->mcp_info->port_addr +
821 offsetof(struct public_port, remote_dcbx_mib);
822 data.mib = &p_hwfn->p_dcbx_info->remote;
823 data.size = sizeof(struct dcbx_mib);
824 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
825
826 return rc;
827}
828
829static int
830qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
831{
832 struct qed_dcbx_mib_meta_data data;
833 int rc = 0;
834
835 memset(&data, 0, sizeof(data));
836 data.addr = p_hwfn->mcp_info->port_addr +
837 offsetof(struct public_port, local_admin_dcbx_mib);
838 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
839 data.size = sizeof(struct dcbx_local_params);
840 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
841
842 return rc;
843}
844
845static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
846 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
847{
848 int rc = -EINVAL;
849
850 switch (type) {
851 case QED_DCBX_OPERATIONAL_MIB:
852 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
853 break;
854 case QED_DCBX_REMOTE_MIB:
855 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
856 break;
857 case QED_DCBX_LOCAL_MIB:
858 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
859 break;
860 case QED_DCBX_REMOTE_LLDP_MIB:
861 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
862 break;
863 case QED_DCBX_LOCAL_LLDP_MIB:
864 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
865 break;
866 default:
867 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
868 }
869
870 return rc;
871}
872
Arun Easi1e128c82017-02-15 06:28:22 -0800873void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
874{
875 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
876 void *cookie = hwfn->cdev->ops_cookie;
877
878 if (cookie && op->dcbx_aen)
879 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
880}
881
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400882/* Read updated MIB.
883 * Reconfigure QM and invoke PF update ramrod command if operational MIB
884 * change is detected.
885 */
886int
887qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
888 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
889{
890 int rc = 0;
891
892 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
893 if (rc)
894 return rc;
895
896 if (type == QED_DCBX_OPERATIONAL_MIB) {
897 rc = qed_dcbx_process_mib_info(p_hwfn);
898 if (!rc) {
899 /* reconfigure tcs of QM queues according
900 * to negotiation results
901 */
902 qed_qm_reconf(p_hwfn, p_ptt);
903
904 /* update storm FW with negotiation results */
905 qed_sp_pf_update(p_hwfn);
906 }
907 }
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700908
909 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
Arun Easi1e128c82017-02-15 06:28:22 -0800910 qed_dcbx_aen(p_hwfn, type);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400911
912 return rc;
913}
914
915int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
916{
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400917 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -0700918 if (!p_hwfn->p_dcbx_info)
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700919 return -ENOMEM;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400920
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700921 return 0;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400922}
923
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700924void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400925{
926 kfree(p_hwfn->p_dcbx_info);
Tomer Tayar3587cb82017-05-21 12:10:56 +0300927 p_hwfn->p_dcbx_info = NULL;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400928}
929
930static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
931 struct qed_dcbx_results *p_src,
932 enum dcbx_protocol_type type)
933{
934 p_data->dcb_enable_flag = p_src->arr[type].enable;
935 p_data->dcb_priority = p_src->arr[type].priority;
936 p_data->dcb_tc = p_src->arr[type].tc;
937}
938
939/* Set pf update ramrod command params */
940void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
941 struct pf_update_ramrod_data *p_dest)
942{
943 struct protocol_dcb_data *p_dcb_data;
944 bool update_flag = false;
945
946 p_dest->pf_id = p_src->pf_id;
947
948 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300949 p_dest->update_fcoe_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400950
951 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300952 p_dest->update_roce_dcb_data_mode = update_flag;
953
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400954 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300955 p_dest->update_rroce_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400956
957 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300958 p_dest->update_iscsi_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400959 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300960 p_dest->update_eth_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400961
962 p_dcb_data = &p_dest->fcoe_dcb_data;
963 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
964 p_dcb_data = &p_dest->roce_dcb_data;
sudarsana.kalluru@cavium.com449ad502017-04-20 22:31:17 -0700965 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
966 p_dcb_data = &p_dest->rroce_dcb_data;
967 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400968 p_dcb_data = &p_dest->iscsi_dcb_data;
969 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
970 p_dcb_data = &p_dest->eth_dcb_data;
971 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
972}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400973
974#ifdef CONFIG_DCB
975static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
976 struct qed_dcbx_get *p_get,
977 enum qed_mib_read_type type)
978{
979 struct qed_ptt *p_ptt;
980 int rc;
981
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400982 if (IS_VF(p_hwfn->cdev))
983 return -EINVAL;
984
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400985 p_ptt = qed_ptt_acquire(p_hwfn);
986 if (!p_ptt)
987 return -EBUSY;
988
989 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
990 if (rc)
991 goto out;
992
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700993 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400994
995out:
996 qed_ptt_release(p_hwfn, p_ptt);
997 return rc;
998}
999
1000static void
1001qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1002 u32 *pfc, struct qed_dcbx_params *p_params)
1003{
1004 u8 pfc_map = 0;
1005 int i;
1006
sudarsana.kalluru@cavium.com6cf75f12017-04-19 03:19:53 -07001007 *pfc &= ~DCBX_PFC_ERROR_MASK;
1008
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001009 if (p_params->pfc.willing)
1010 *pfc |= DCBX_PFC_WILLING_MASK;
1011 else
1012 *pfc &= ~DCBX_PFC_WILLING_MASK;
1013
1014 if (p_params->pfc.enabled)
1015 *pfc |= DCBX_PFC_ENABLED_MASK;
1016 else
1017 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1018
1019 *pfc &= ~DCBX_PFC_CAPS_MASK;
1020 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1021
1022 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1023 if (p_params->pfc.prio[i])
1024 pfc_map |= BIT(i);
1025
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001026 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001027 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1028
1029 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1030}
1031
1032static void
1033qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1034 struct dcbx_ets_feature *p_ets,
1035 struct qed_dcbx_params *p_params)
1036{
1037 u8 *bw_map, *tsa_map;
1038 u32 val;
1039 int i;
1040
1041 if (p_params->ets_willing)
1042 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1043 else
1044 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1045
1046 if (p_params->ets_cbs)
1047 p_ets->flags |= DCBX_ETS_CBS_MASK;
1048 else
1049 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1050
1051 if (p_params->ets_enabled)
1052 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1053 else
1054 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1055
1056 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1057 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1058
1059 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1060 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1061 p_ets->pri_tc_tbl[0] = 0;
1062 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1063 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1064 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1065 /* Copy the priority value to the corresponding 4 bits in the
1066 * traffic class table.
1067 */
1068 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1069 p_ets->pri_tc_tbl[0] |= val;
1070 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001071 for (i = 0; i < 2; i++) {
1072 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1073 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1074 }
1075}
1076
1077static void
1078qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1079 struct dcbx_app_priority_feature *p_app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001080 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001081{
1082 u32 *entry;
1083 int i;
1084
1085 if (p_params->app_willing)
1086 p_app->flags |= DCBX_APP_WILLING_MASK;
1087 else
1088 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1089
1090 if (p_params->app_valid)
1091 p_app->flags |= DCBX_APP_ENABLED_MASK;
1092 else
1093 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1094
1095 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1096 p_app->flags |= (u32)p_params->num_app_entries <<
1097 DCBX_APP_NUM_ENTRIES_SHIFT;
1098
1099 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1100 entry = &p_app->app_pri_tbl[i].entry;
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001101 *entry = 0;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001102 if (ieee) {
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001103 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001104 switch (p_params->app_entry[i].sf_ieee) {
1105 case QED_DCBX_SF_IEEE_ETHTYPE:
1106 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1107 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001108 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1109 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001110 break;
1111 case QED_DCBX_SF_IEEE_TCP_PORT:
1112 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1113 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001114 *entry |= ((u32)DCBX_APP_SF_PORT <<
1115 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001116 break;
1117 case QED_DCBX_SF_IEEE_UDP_PORT:
1118 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1119 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001120 *entry |= ((u32)DCBX_APP_SF_PORT <<
1121 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001122 break;
1123 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1124 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1125 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001126 *entry |= ((u32)DCBX_APP_SF_PORT <<
1127 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001128 break;
1129 }
1130 } else {
1131 *entry &= ~DCBX_APP_SF_MASK;
1132 if (p_params->app_entry[i].ethtype)
1133 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1134 DCBX_APP_SF_SHIFT);
1135 else
1136 *entry |= ((u32)DCBX_APP_SF_PORT <<
1137 DCBX_APP_SF_SHIFT);
1138 }
1139
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001140 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1141 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1142 DCBX_APP_PROTOCOL_ID_SHIFT);
1143 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1144 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1145 DCBX_APP_PRI_MAP_SHIFT);
1146 }
1147}
1148
1149static void
1150qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1151 struct dcbx_local_params *local_admin,
1152 struct qed_dcbx_set *params)
1153{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001154 bool ieee = false;
1155
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001156 local_admin->flags = 0;
1157 memcpy(&local_admin->features,
1158 &p_hwfn->p_dcbx_info->operational.features,
1159 sizeof(local_admin->features));
1160
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001161 if (params->enabled) {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001162 local_admin->config = params->ver_num;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001163 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1164 } else {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001165 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001166 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001167
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -07001168 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
1169 local_admin->config);
1170
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001171 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1172 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1173 &params->config.params);
1174
1175 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1176 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1177 &params->config.params);
1178
1179 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1180 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001181 &params->config.params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001182}
1183
1184int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1185 struct qed_dcbx_set *params, bool hw_commit)
1186{
1187 struct dcbx_local_params local_admin;
1188 struct qed_dcbx_mib_meta_data data;
1189 u32 resp = 0, param = 0;
1190 int rc = 0;
1191
1192 if (!hw_commit) {
1193 memcpy(&p_hwfn->p_dcbx_info->set, params,
1194 sizeof(struct qed_dcbx_set));
1195 return 0;
1196 }
1197
1198 /* clear set-parmas cache */
1199 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1200
1201 memset(&local_admin, 0, sizeof(local_admin));
1202 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1203
1204 data.addr = p_hwfn->mcp_info->port_addr +
1205 offsetof(struct public_port, local_admin_dcbx_mib);
1206 data.local_admin = &local_admin;
1207 data.size = sizeof(struct dcbx_local_params);
1208 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1209
1210 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1211 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
1212 if (rc)
1213 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1214
1215 return rc;
1216}
1217
1218int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1219 struct qed_dcbx_set *params)
1220{
1221 struct qed_dcbx_get *dcbx_info;
1222 int rc;
1223
1224 if (p_hwfn->p_dcbx_info->set.config.valid) {
1225 memcpy(params, &p_hwfn->p_dcbx_info->set,
1226 sizeof(struct qed_dcbx_set));
1227 return 0;
1228 }
1229
Wu Fengguang561ed232016-09-01 14:45:12 +08001230 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -07001231 if (!dcbx_info)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001232 return -ENOMEM;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001233
Sudarsana Reddy Kalluru15c6de22016-10-21 04:43:44 -04001234 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001235 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1236 if (rc) {
1237 kfree(dcbx_info);
1238 return rc;
1239 }
1240
1241 p_hwfn->p_dcbx_info->set.override_flags = 0;
1242 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1243 if (dcbx_info->operational.cee)
1244 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1245 if (dcbx_info->operational.ieee)
1246 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001247 if (dcbx_info->operational.local)
1248 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001249
1250 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1251 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1252 &dcbx_info->operational.params,
1253 sizeof(struct qed_dcbx_admin_params));
1254 p_hwfn->p_dcbx_info->set.config.valid = true;
1255
1256 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1257
1258 kfree(dcbx_info);
1259
1260 return 0;
1261}
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001262
1263static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1264 enum qed_mib_read_type type)
1265{
1266 struct qed_dcbx_get *dcbx_info;
1267
sudarsana.kalluru@cavium.com62289ba2017-04-19 03:19:54 -07001268 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
Joe Perches2591c282016-09-04 14:24:03 -07001269 if (!dcbx_info)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001270 return NULL;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001271
Sudarsana Reddy Kalluru15c6de22016-10-21 04:43:44 -04001272 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001273 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1274 kfree(dcbx_info);
1275 return NULL;
1276 }
1277
1278 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1279 !dcbx_info->operational.enabled) {
1280 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1281 kfree(dcbx_info);
1282 return NULL;
1283 }
1284
1285 return dcbx_info;
1286}
1287
1288static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1289{
1290 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1291 struct qed_dcbx_get *dcbx_info;
1292 bool enabled;
1293
1294 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1295 if (!dcbx_info)
1296 return 0;
1297
1298 enabled = dcbx_info->operational.enabled;
1299 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1300 kfree(dcbx_info);
1301
1302 return enabled;
1303}
1304
1305static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1306{
1307 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1308 struct qed_dcbx_set dcbx_set;
1309 struct qed_ptt *ptt;
1310 int rc;
1311
1312 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1313
1314 memset(&dcbx_set, 0, sizeof(dcbx_set));
1315 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1316 if (rc)
1317 return 1;
1318
1319 dcbx_set.enabled = !!state;
1320
1321 ptt = qed_ptt_acquire(hwfn);
1322 if (!ptt)
1323 return 1;
1324
1325 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1326
1327 qed_ptt_release(hwfn, ptt);
1328
1329 return rc ? 1 : 0;
1330}
1331
1332static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1333 u8 *pgid, u8 *bw_pct, u8 *up_map)
1334{
1335 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1336 struct qed_dcbx_get *dcbx_info;
1337
1338 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1339 *prio_type = *pgid = *bw_pct = *up_map = 0;
1340 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1341 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1342 return;
1343 }
1344
1345 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1346 if (!dcbx_info)
1347 return;
1348
1349 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1350 kfree(dcbx_info);
1351}
1352
1353static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1354{
1355 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1356 struct qed_dcbx_get *dcbx_info;
1357
1358 *bw_pct = 0;
1359 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1360 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1361 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1362 return;
1363 }
1364
1365 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1366 if (!dcbx_info)
1367 return;
1368
1369 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1370 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1371 kfree(dcbx_info);
1372}
1373
1374static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1375 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1376{
1377 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1378 *prio = *bwg_id = *bw_pct = *up_map = 0;
1379}
1380
1381static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1382 int bwg_id, u8 *bw_pct)
1383{
1384 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1385 *bw_pct = 0;
1386}
1387
1388static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1389 int priority, u8 *setting)
1390{
1391 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1392 struct qed_dcbx_get *dcbx_info;
1393
1394 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1395 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1396 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1397 return;
1398 }
1399
1400 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1401 if (!dcbx_info)
1402 return;
1403
1404 *setting = dcbx_info->operational.params.pfc.prio[priority];
1405 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1406 kfree(dcbx_info);
1407}
1408
1409static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1410{
1411 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1412 struct qed_dcbx_set dcbx_set;
1413 struct qed_ptt *ptt;
1414 int rc;
1415
1416 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1417 priority, setting);
1418 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1419 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1420 return;
1421 }
1422
1423 memset(&dcbx_set, 0, sizeof(dcbx_set));
1424 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1425 if (rc)
1426 return;
1427
1428 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1429 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1430
1431 ptt = qed_ptt_acquire(hwfn);
1432 if (!ptt)
1433 return;
1434
1435 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1436
1437 qed_ptt_release(hwfn, ptt);
1438}
1439
1440static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1441{
1442 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1443 struct qed_dcbx_get *dcbx_info;
1444 int rc = 0;
1445
1446 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1447 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1448 if (!dcbx_info)
1449 return 1;
1450
1451 switch (capid) {
1452 case DCB_CAP_ATTR_PG:
1453 case DCB_CAP_ATTR_PFC:
1454 case DCB_CAP_ATTR_UP2TC:
1455 case DCB_CAP_ATTR_GSP:
1456 *cap = true;
1457 break;
1458 case DCB_CAP_ATTR_PG_TCS:
1459 case DCB_CAP_ATTR_PFC_TCS:
1460 *cap = 0x80;
1461 break;
1462 case DCB_CAP_ATTR_DCBX:
1463 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
Sudarsana Reddy Kalluru05930d12017-05-29 09:53:05 +03001464 DCB_CAP_DCBX_VER_IEEE | DCB_CAP_DCBX_STATIC);
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001465 break;
1466 default:
1467 *cap = false;
1468 rc = 1;
1469 }
1470
1471 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1472 kfree(dcbx_info);
1473
1474 return rc;
1475}
1476
1477static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1478{
1479 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1480 struct qed_dcbx_get *dcbx_info;
1481 int rc = 0;
1482
1483 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1484 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1485 if (!dcbx_info)
1486 return -EINVAL;
1487
1488 switch (tcid) {
1489 case DCB_NUMTCS_ATTR_PG:
1490 *num = dcbx_info->operational.params.max_ets_tc;
1491 break;
1492 case DCB_NUMTCS_ATTR_PFC:
1493 *num = dcbx_info->operational.params.pfc.max_tc;
1494 break;
1495 default:
1496 rc = -EINVAL;
1497 }
1498
1499 kfree(dcbx_info);
1500 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1501
1502 return rc;
1503}
1504
1505static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1506{
1507 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1508 struct qed_dcbx_get *dcbx_info;
1509 bool enabled;
1510
1511 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1512 if (!dcbx_info)
1513 return 0;
1514
1515 enabled = dcbx_info->operational.params.pfc.enabled;
1516 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1517 kfree(dcbx_info);
1518
1519 return enabled;
1520}
1521
1522static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1523{
1524 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1525 struct qed_dcbx_get *dcbx_info;
1526 u8 mode = 0;
1527
1528 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1529 if (!dcbx_info)
1530 return 0;
1531
1532 if (dcbx_info->operational.enabled)
1533 mode |= DCB_CAP_DCBX_LLD_MANAGED;
1534 if (dcbx_info->operational.ieee)
1535 mode |= DCB_CAP_DCBX_VER_IEEE;
1536 if (dcbx_info->operational.cee)
1537 mode |= DCB_CAP_DCBX_VER_CEE;
Sudarsana Reddy Kalluru05930d12017-05-29 09:53:05 +03001538 if (dcbx_info->operational.local)
1539 mode |= DCB_CAP_DCBX_STATIC;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001540
1541 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1542 kfree(dcbx_info);
1543
1544 return mode;
1545}
1546
1547static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1548 int tc,
1549 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1550{
1551 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1552 struct qed_dcbx_set dcbx_set;
1553 struct qed_ptt *ptt;
1554 int rc;
1555
1556 DP_VERBOSE(hwfn, QED_MSG_DCB,
1557 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1558 tc, pri_type, pgid, bw_pct, up_map);
1559
1560 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1561 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1562 return;
1563 }
1564
1565 memset(&dcbx_set, 0, sizeof(dcbx_set));
1566 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1567 if (rc)
1568 return;
1569
1570 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1571 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1572
1573 ptt = qed_ptt_acquire(hwfn);
1574 if (!ptt)
1575 return;
1576
1577 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1578
1579 qed_ptt_release(hwfn, ptt);
1580}
1581
1582static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1583 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1584{
1585 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1586}
1587
1588static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1589{
1590 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1591 struct qed_dcbx_set dcbx_set;
1592 struct qed_ptt *ptt;
1593 int rc;
1594
1595 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1596 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1597 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1598 return;
1599 }
1600
1601 memset(&dcbx_set, 0, sizeof(dcbx_set));
1602 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1603 if (rc)
1604 return;
1605
1606 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1607 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1608
1609 ptt = qed_ptt_acquire(hwfn);
1610 if (!ptt)
1611 return;
1612
1613 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1614
1615 qed_ptt_release(hwfn, ptt);
1616}
1617
1618static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1619{
1620 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1621}
1622
1623static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1624{
1625 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1626 struct qed_dcbx_set dcbx_set;
1627 struct qed_ptt *ptt;
1628 int rc;
1629
1630 memset(&dcbx_set, 0, sizeof(dcbx_set));
1631 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1632 if (rc)
1633 return 1;
1634
1635 ptt = qed_ptt_acquire(hwfn);
1636 if (!ptt)
1637 return 1;
1638
1639 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1640
1641 qed_ptt_release(hwfn, ptt);
1642
1643 return rc;
1644}
1645
1646static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1647{
1648 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1649 struct qed_dcbx_set dcbx_set;
1650 struct qed_ptt *ptt;
1651 int rc;
1652
1653 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1654 memset(&dcbx_set, 0, sizeof(dcbx_set));
1655 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1656 if (rc)
1657 return 1;
1658
1659 switch (tcid) {
1660 case DCB_NUMTCS_ATTR_PG:
1661 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1662 dcbx_set.config.params.max_ets_tc = num;
1663 break;
1664 case DCB_NUMTCS_ATTR_PFC:
1665 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1666 dcbx_set.config.params.pfc.max_tc = num;
1667 break;
1668 default:
1669 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1670 return -EINVAL;
1671 }
1672
1673 ptt = qed_ptt_acquire(hwfn);
1674 if (!ptt)
1675 return -EINVAL;
1676
1677 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1678
1679 qed_ptt_release(hwfn, ptt);
1680
1681 return 0;
1682}
1683
1684static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1685{
1686 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1687 struct qed_dcbx_set dcbx_set;
1688 struct qed_ptt *ptt;
1689 int rc;
1690
1691 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1692
1693 memset(&dcbx_set, 0, sizeof(dcbx_set));
1694 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1695 if (rc)
1696 return;
1697
1698 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1699 dcbx_set.config.params.pfc.enabled = !!state;
1700
1701 ptt = qed_ptt_acquire(hwfn);
1702 if (!ptt)
1703 return;
1704
1705 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1706
1707 qed_ptt_release(hwfn, ptt);
1708}
1709
1710static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1711{
1712 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1713 struct qed_dcbx_get *dcbx_info;
1714 struct qed_app_entry *entry;
1715 bool ethtype;
1716 u8 prio = 0;
1717 int i;
1718
1719 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1720 if (!dcbx_info)
1721 return -EINVAL;
1722
1723 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1724 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1725 entry = &dcbx_info->operational.params.app_entry[i];
1726 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1727 prio = entry->prio;
1728 break;
1729 }
1730 }
1731
1732 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1733 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1734 kfree(dcbx_info);
1735 return -EINVAL;
1736 }
1737
1738 kfree(dcbx_info);
1739
1740 return prio;
1741}
1742
1743static int qed_dcbnl_setapp(struct qed_dev *cdev,
1744 u8 idtype, u16 idval, u8 pri_map)
1745{
1746 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1747 struct qed_dcbx_set dcbx_set;
1748 struct qed_app_entry *entry;
1749 struct qed_ptt *ptt;
1750 bool ethtype;
1751 int rc, i;
1752
1753 memset(&dcbx_set, 0, sizeof(dcbx_set));
1754 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1755 if (rc)
1756 return -EINVAL;
1757
1758 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1759 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1760 entry = &dcbx_set.config.params.app_entry[i];
1761 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1762 break;
1763 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001764 if (!entry->proto_id) {
1765 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001766 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001767 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001768 }
1769
1770 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1771 DP_ERR(cdev, "App table is full\n");
1772 return -EBUSY;
1773 }
1774
1775 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1776 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1777 dcbx_set.config.params.app_entry[i].proto_id = idval;
1778 dcbx_set.config.params.app_entry[i].prio = pri_map;
1779
1780 ptt = qed_ptt_acquire(hwfn);
1781 if (!ptt)
1782 return -EBUSY;
1783
1784 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1785
1786 qed_ptt_release(hwfn, ptt);
1787
1788 return rc;
1789}
1790
1791static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1792{
1793 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1794 struct qed_dcbx_set dcbx_set;
1795 struct qed_ptt *ptt;
1796 int rc;
1797
1798 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1799
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001800 if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
1801 !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
1802 DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001803 return 1;
1804 }
1805
1806 memset(&dcbx_set, 0, sizeof(dcbx_set));
1807 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1808 if (rc)
1809 return 1;
1810
1811 dcbx_set.ver_num = 0;
1812 if (mode & DCB_CAP_DCBX_VER_CEE) {
1813 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1814 dcbx_set.enabled = true;
1815 }
1816
1817 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1818 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1819 dcbx_set.enabled = true;
1820 }
1821
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001822 if (mode & DCB_CAP_DCBX_STATIC) {
1823 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1824 dcbx_set.enabled = true;
1825 }
1826
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001827 ptt = qed_ptt_acquire(hwfn);
1828 if (!ptt)
1829 return 1;
1830
1831 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1832
1833 qed_ptt_release(hwfn, ptt);
1834
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001835 return rc;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001836}
1837
1838static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1839{
1840 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1841 struct qed_dcbx_get *dcbx_info;
1842
1843 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1844 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1845 if (!dcbx_info)
1846 return 1;
1847
1848 *flags = 0;
1849 switch (featid) {
1850 case DCB_FEATCFG_ATTR_PG:
1851 if (dcbx_info->operational.params.ets_enabled)
1852 *flags = DCB_FEATCFG_ENABLE;
1853 else
1854 *flags = DCB_FEATCFG_ERROR;
1855 break;
1856 case DCB_FEATCFG_ATTR_PFC:
1857 if (dcbx_info->operational.params.pfc.enabled)
1858 *flags = DCB_FEATCFG_ENABLE;
1859 else
1860 *flags = DCB_FEATCFG_ERROR;
1861 break;
1862 case DCB_FEATCFG_ATTR_APP:
1863 if (dcbx_info->operational.params.app_valid)
1864 *flags = DCB_FEATCFG_ENABLE;
1865 else
1866 *flags = DCB_FEATCFG_ERROR;
1867 break;
1868 default:
1869 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1870 kfree(dcbx_info);
1871 return 1;
1872 }
1873
1874 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1875 kfree(dcbx_info);
1876
1877 return 0;
1878}
1879
1880static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1881{
1882 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1883 struct qed_dcbx_set dcbx_set;
1884 bool enabled, willing;
1885 struct qed_ptt *ptt;
1886 int rc;
1887
1888 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1889 featid, flags);
1890 memset(&dcbx_set, 0, sizeof(dcbx_set));
1891 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1892 if (rc)
1893 return 1;
1894
1895 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1896 willing = !!(flags & DCB_FEATCFG_WILLING);
1897 switch (featid) {
1898 case DCB_FEATCFG_ATTR_PG:
1899 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1900 dcbx_set.config.params.ets_enabled = enabled;
1901 dcbx_set.config.params.ets_willing = willing;
1902 break;
1903 case DCB_FEATCFG_ATTR_PFC:
1904 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1905 dcbx_set.config.params.pfc.enabled = enabled;
1906 dcbx_set.config.params.pfc.willing = willing;
1907 break;
1908 case DCB_FEATCFG_ATTR_APP:
1909 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1910 dcbx_set.config.params.app_willing = willing;
1911 break;
1912 default:
1913 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1914 return 1;
1915 }
1916
1917 ptt = qed_ptt_acquire(hwfn);
1918 if (!ptt)
1919 return 1;
1920
1921 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1922
1923 qed_ptt_release(hwfn, ptt);
1924
1925 return 0;
1926}
1927
1928static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1929 struct dcb_peer_app_info *info,
1930 u16 *app_count)
1931{
1932 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1933 struct qed_dcbx_get *dcbx_info;
1934
1935 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1936 if (!dcbx_info)
1937 return -EINVAL;
1938
1939 info->willing = dcbx_info->remote.params.app_willing;
1940 info->error = dcbx_info->remote.params.app_error;
1941 *app_count = dcbx_info->remote.params.num_app_entries;
1942 kfree(dcbx_info);
1943
1944 return 0;
1945}
1946
1947static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1948 struct dcb_app *table)
1949{
1950 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1951 struct qed_dcbx_get *dcbx_info;
1952 int i;
1953
1954 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1955 if (!dcbx_info)
1956 return -EINVAL;
1957
1958 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1959 if (dcbx_info->remote.params.app_entry[i].ethtype)
1960 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1961 else
1962 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1963 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1964 table[i].protocol =
1965 dcbx_info->remote.params.app_entry[i].proto_id;
1966 }
1967
1968 kfree(dcbx_info);
1969
1970 return 0;
1971}
1972
1973static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1974{
1975 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1976 struct qed_dcbx_get *dcbx_info;
1977 int i;
1978
1979 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1980 if (!dcbx_info)
1981 return -EINVAL;
1982
1983 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1984 if (dcbx_info->remote.params.pfc.prio[i])
1985 pfc->pfc_en |= BIT(i);
1986
1987 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1988 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
1989 pfc->pfc_en, pfc->tcs_supported);
1990 kfree(dcbx_info);
1991
1992 return 0;
1993}
1994
1995static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
1996{
1997 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1998 struct qed_dcbx_get *dcbx_info;
1999 int i;
2000
2001 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
2002 if (!dcbx_info)
2003 return -EINVAL;
2004
2005 pg->willing = dcbx_info->remote.params.ets_willing;
2006 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
2007 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
2008 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
2009 }
2010
2011 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
2012 kfree(dcbx_info);
2013
2014 return 0;
2015}
2016
2017static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
2018 struct ieee_pfc *pfc, bool remote)
2019{
2020 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2021 struct qed_dcbx_params *params;
2022 struct qed_dcbx_get *dcbx_info;
2023 int rc, i;
2024
2025 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2026 if (!dcbx_info)
2027 return -EINVAL;
2028
2029 if (!dcbx_info->operational.ieee) {
2030 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
Wei Yongjun02ee9b12016-08-11 23:29:54 +00002031 kfree(dcbx_info);
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002032 return -EINVAL;
2033 }
2034
2035 if (remote) {
2036 memset(dcbx_info, 0, sizeof(*dcbx_info));
2037 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2038 QED_DCBX_REMOTE_MIB);
2039 if (rc) {
2040 kfree(dcbx_info);
2041 return -EINVAL;
2042 }
2043
2044 params = &dcbx_info->remote.params;
2045 } else {
2046 params = &dcbx_info->operational.params;
2047 }
2048
2049 pfc->pfc_cap = params->pfc.max_tc;
2050 pfc->pfc_en = 0;
2051 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2052 if (params->pfc.prio[i])
2053 pfc->pfc_en |= BIT(i);
2054
2055 kfree(dcbx_info);
2056
2057 return 0;
2058}
2059
2060static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2061{
2062 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2063}
2064
2065static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2066{
2067 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2068 struct qed_dcbx_get *dcbx_info;
2069 struct qed_dcbx_set dcbx_set;
2070 struct qed_ptt *ptt;
2071 int rc, i;
2072
2073 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2074 if (!dcbx_info)
2075 return -EINVAL;
2076
2077 if (!dcbx_info->operational.ieee) {
2078 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2079 kfree(dcbx_info);
2080 return -EINVAL;
2081 }
2082
2083 kfree(dcbx_info);
2084
2085 memset(&dcbx_set, 0, sizeof(dcbx_set));
2086 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2087 if (rc)
2088 return -EINVAL;
2089
2090 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2091 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2092 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2093
sudarsana.kalluru@cavium.comc0c5dbe2017-04-19 03:19:55 -07002094 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2095
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002096 ptt = qed_ptt_acquire(hwfn);
2097 if (!ptt)
2098 return -EINVAL;
2099
2100 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2101
2102 qed_ptt_release(hwfn, ptt);
2103
2104 return rc;
2105}
2106
2107static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2108 struct ieee_ets *ets, bool remote)
2109{
2110 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2111 struct qed_dcbx_get *dcbx_info;
2112 struct qed_dcbx_params *params;
2113 int rc;
2114
2115 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2116 if (!dcbx_info)
2117 return -EINVAL;
2118
2119 if (!dcbx_info->operational.ieee) {
2120 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2121 kfree(dcbx_info);
2122 return -EINVAL;
2123 }
2124
2125 if (remote) {
2126 memset(dcbx_info, 0, sizeof(*dcbx_info));
2127 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2128 QED_DCBX_REMOTE_MIB);
2129 if (rc) {
2130 kfree(dcbx_info);
2131 return -EINVAL;
2132 }
2133
2134 params = &dcbx_info->remote.params;
2135 } else {
2136 params = &dcbx_info->operational.params;
2137 }
2138
2139 ets->ets_cap = params->max_ets_tc;
2140 ets->willing = params->ets_willing;
2141 ets->cbs = params->ets_cbs;
2142 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2143 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2144 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2145 kfree(dcbx_info);
2146
2147 return 0;
2148}
2149
2150static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2151{
2152 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2153}
2154
2155static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2156{
2157 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2158 struct qed_dcbx_get *dcbx_info;
2159 struct qed_dcbx_set dcbx_set;
2160 struct qed_ptt *ptt;
2161 int rc;
2162
2163 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2164 if (!dcbx_info)
2165 return -EINVAL;
2166
2167 if (!dcbx_info->operational.ieee) {
2168 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2169 kfree(dcbx_info);
2170 return -EINVAL;
2171 }
2172
2173 kfree(dcbx_info);
2174
2175 memset(&dcbx_set, 0, sizeof(dcbx_set));
2176 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2177 if (rc)
2178 return -EINVAL;
2179
2180 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2181 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2182 dcbx_set.config.params.ets_willing = ets->willing;
2183 dcbx_set.config.params.ets_cbs = ets->cbs;
2184 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2185 sizeof(ets->tc_tx_bw));
2186 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2187 sizeof(ets->tc_tsa));
2188 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2189 sizeof(ets->prio_tc));
2190
2191 ptt = qed_ptt_acquire(hwfn);
2192 if (!ptt)
2193 return -EINVAL;
2194
2195 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2196
2197 qed_ptt_release(hwfn, ptt);
2198
2199 return rc;
2200}
2201
Baoyou Xieba569472016-09-09 09:21:15 +08002202static int
2203qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002204{
2205 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2206}
2207
Baoyou Xieba569472016-09-09 09:21:15 +08002208static int
2209qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002210{
2211 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2212}
2213
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002214static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
2215{
2216 switch (selector) {
2217 case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
2218 *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
2219 break;
2220 case IEEE_8021QAZ_APP_SEL_STREAM:
2221 *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
2222 break;
2223 case IEEE_8021QAZ_APP_SEL_DGRAM:
2224 *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
2225 break;
2226 case IEEE_8021QAZ_APP_SEL_ANY:
2227 *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
2228 break;
2229 default:
2230 return -EINVAL;
2231 }
2232
2233 return 0;
2234}
2235
Baoyou Xieba569472016-09-09 09:21:15 +08002236static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002237{
2238 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2239 struct qed_dcbx_get *dcbx_info;
2240 struct qed_app_entry *entry;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002241 u8 prio = 0;
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002242 u8 sf_ieee;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002243 int i;
2244
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002245 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
2246 app->selector, app->protocol);
2247
2248 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2249 DP_INFO(cdev, "Invalid selector field value %d\n",
2250 app->selector);
2251 return -EINVAL;
2252 }
2253
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002254 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2255 if (!dcbx_info)
2256 return -EINVAL;
2257
2258 if (!dcbx_info->operational.ieee) {
2259 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2260 kfree(dcbx_info);
2261 return -EINVAL;
2262 }
2263
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002264 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2265 entry = &dcbx_info->operational.params.app_entry[i];
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002266 if ((entry->sf_ieee == sf_ieee) &&
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002267 (entry->proto_id == app->protocol)) {
2268 prio = entry->prio;
2269 break;
2270 }
2271 }
2272
2273 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2274 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2275 app->protocol);
2276 kfree(dcbx_info);
2277 return -EINVAL;
2278 }
2279
2280 app->priority = ffs(prio) - 1;
2281
2282 kfree(dcbx_info);
2283
2284 return 0;
2285}
2286
Baoyou Xieba569472016-09-09 09:21:15 +08002287static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002288{
2289 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2290 struct qed_dcbx_get *dcbx_info;
2291 struct qed_dcbx_set dcbx_set;
2292 struct qed_app_entry *entry;
2293 struct qed_ptt *ptt;
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002294 u8 sf_ieee;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002295 int rc, i;
2296
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002297 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
2298 app->selector, app->protocol, app->priority);
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002299 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2300 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2301 return -EINVAL;
2302 }
2303
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002304 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2305 DP_INFO(cdev, "Invalid selector field value %d\n",
2306 app->selector);
2307 return -EINVAL;
2308 }
2309
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002310 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2311 if (!dcbx_info)
2312 return -EINVAL;
2313
2314 if (!dcbx_info->operational.ieee) {
2315 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2316 kfree(dcbx_info);
2317 return -EINVAL;
2318 }
2319
2320 kfree(dcbx_info);
2321
2322 memset(&dcbx_set, 0, sizeof(dcbx_set));
2323 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2324 if (rc)
2325 return -EINVAL;
2326
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002327 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2328 entry = &dcbx_set.config.params.app_entry[i];
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002329 if ((entry->sf_ieee == sf_ieee) &&
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002330 (entry->proto_id == app->protocol))
2331 break;
2332 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002333 if (!entry->proto_id) {
2334 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002335 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002336 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002337 }
2338
2339 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2340 DP_ERR(cdev, "App table is full\n");
2341 return -EBUSY;
2342 }
2343
2344 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002345 dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002346 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2347 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2348
2349 ptt = qed_ptt_acquire(hwfn);
2350 if (!ptt)
2351 return -EBUSY;
2352
2353 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2354
2355 qed_ptt_release(hwfn, ptt);
2356
2357 return rc;
2358}
2359
2360const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2361 .getstate = qed_dcbnl_getstate,
2362 .setstate = qed_dcbnl_setstate,
2363 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2364 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2365 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2366 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2367 .getpfccfg = qed_dcbnl_getpfccfg,
2368 .setpfccfg = qed_dcbnl_setpfccfg,
2369 .getcap = qed_dcbnl_getcap,
2370 .getnumtcs = qed_dcbnl_getnumtcs,
2371 .getpfcstate = qed_dcbnl_getpfcstate,
2372 .getdcbx = qed_dcbnl_getdcbx,
2373 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2374 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2375 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2376 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2377 .setall = qed_dcbnl_setall,
2378 .setnumtcs = qed_dcbnl_setnumtcs,
2379 .setpfcstate = qed_dcbnl_setpfcstate,
2380 .setapp = qed_dcbnl_setapp,
2381 .setdcbx = qed_dcbnl_setdcbx,
2382 .setfeatcfg = qed_dcbnl_setfeatcfg,
2383 .getfeatcfg = qed_dcbnl_getfeatcfg,
2384 .getapp = qed_dcbnl_getapp,
2385 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2386 .peer_getapptable = qed_dcbnl_peer_getapptable,
2387 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2388 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2389 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2390 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2391 .ieee_getets = qed_dcbnl_ieee_getets,
2392 .ieee_setets = qed_dcbnl_ieee_setets,
2393 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2394 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2395 .ieee_getapp = qed_dcbnl_ieee_getapp,
2396 .ieee_setapp = qed_dcbnl_ieee_setapp,
2397};
2398
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04002399#endif