blob: b83fe1d9e988a731ab77a237a0888858ed45db02 [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,
194 bool update,
195 u8 prio,
196 u8 tc,
197 enum dcbx_protocol_type type,
198 enum qed_pci_personality personality)
199{
200 /* PF update ramrod data */
201 p_data->arr[type].update = update;
202 p_data->arr[type].enable = enable;
203 p_data->arr[type].priority = prio;
204 p_data->arr[type].tc = tc;
205
206 /* QM reconf data */
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300207 if (p_info->personality == personality)
208 p_info->offload_tc = tc;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400209}
210
211/* Update app protocol data and hw_info fields with the TLV info */
212static void
213qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
214 struct qed_hwfn *p_hwfn,
215 bool enable,
216 bool update,
217 u8 prio, u8 tc, enum dcbx_protocol_type type)
218{
219 struct qed_hw_info *p_info = &p_hwfn->hw_info;
220 enum qed_pci_personality personality;
221 enum dcbx_protocol_type id;
222 char *name;
223 int i;
224
225 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
226 id = qed_dcbx_app_update[i].id;
227
228 if (type != id)
229 continue;
230
231 personality = qed_dcbx_app_update[i].personality;
232 name = qed_dcbx_app_update[i].name;
233
234 qed_dcbx_set_params(p_data, p_info, enable, update,
235 prio, tc, type, personality);
236 }
237}
238
239static bool
240qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
241 u32 app_prio_bitmap,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400242 u16 id, enum dcbx_protocol_type *type, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400243{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400244 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400245 *type = DCBX_PROTOCOL_FCOE;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400246 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400247 *type = DCBX_PROTOCOL_ROCE;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400248 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400249 *type = DCBX_PROTOCOL_ISCSI;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400250 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400251 *type = DCBX_PROTOCOL_ETH;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400252 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400253 *type = DCBX_PROTOCOL_ROCE_V2;
254 } else {
255 *type = DCBX_MAX_PROTOCOL_TYPE;
256 DP_ERR(p_hwfn,
257 "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
258 id, app_prio_bitmap);
259 return false;
260 }
261
262 return true;
263}
264
265/* Parse app TLV's to update TC information in hw_info structure for
266 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
267 */
268static int
269qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
270 struct qed_dcbx_results *p_data,
271 struct dcbx_app_priority_entry *p_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400272 u32 pri_tc_tbl, int count, u8 dcbx_version)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400273{
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400274 enum dcbx_protocol_type type;
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700275 u8 tc, priority_map;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400276 bool enable, ieee;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400277 u16 protocol_id;
Dan Carpenter54b94302016-05-23 13:19:35 +0300278 int priority;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400279 int i;
280
281 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
282
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400283 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400284 /* Parse APP TLV */
285 for (i = 0; i < count; i++) {
286 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
287 DCBX_APP_PROTOCOL_ID);
288 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
289 DCBX_APP_PRI_MAP);
290 priority = ffs(priority_map) - 1;
291 if (priority < 0) {
292 DP_ERR(p_hwfn, "Invalid priority\n");
293 return -EINVAL;
294 }
295
296 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
297 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400298 protocol_id, &type, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400299 /* ETH always have the enable bit reset, as it gets
300 * vlan information per packet. For other protocols,
301 * should be set according to the dcbx_enabled
302 * indication, but we only got here if there was an
303 * app tlv for the protocol, so dcbx must be enabled.
304 */
Sudarsana Reddy Kalluruec7c7f52016-05-24 05:25:23 -0400305 enable = !(type == DCBX_PROTOCOL_ETH);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400306
307 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true,
308 priority, tc, type);
309 }
310 }
311
312 /* If RoCE-V2 TLV is not detected, driver need to use RoCE app
313 * data for RoCE-v2 not the default app data.
314 */
315 if (!p_data->arr[DCBX_PROTOCOL_ROCE_V2].update &&
316 p_data->arr[DCBX_PROTOCOL_ROCE].update) {
317 tc = p_data->arr[DCBX_PROTOCOL_ROCE].tc;
318 priority = p_data->arr[DCBX_PROTOCOL_ROCE].priority;
319 qed_dcbx_update_app_info(p_data, p_hwfn, true, true,
320 priority, tc, DCBX_PROTOCOL_ROCE_V2);
321 }
322
323 /* Update ramrod protocol data and hw_info fields
324 * with default info when corresponding APP TLV's are not detected.
325 * The enabled field has a different logic for ethernet as only for
326 * ethernet dcb should disabled by default, as the information arrives
327 * from the OS (unless an explicit app tlv was present).
328 */
329 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
330 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
331 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
332 if (p_data->arr[type].update)
333 continue;
334
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400335 enable = !(type == DCBX_PROTOCOL_ETH);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400336 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true,
337 priority, tc, type);
338 }
339
340 return 0;
341}
342
343/* Parse app TLV's to update TC information in hw_info structure for
344 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
345 */
346static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
347{
348 struct dcbx_app_priority_feature *p_app;
349 struct dcbx_app_priority_entry *p_tbl;
350 struct qed_dcbx_results data = { 0 };
351 struct dcbx_ets_feature *p_ets;
352 struct qed_hw_info *p_info;
353 u32 pri_tc_tbl, flags;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400354 u8 dcbx_version;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400355 int num_entries;
356 int rc = 0;
357
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400358 flags = p_hwfn->p_dcbx_info->operational.flags;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400359 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400360
361 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
362 p_tbl = p_app->app_pri_tbl;
363
364 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
365 pri_tc_tbl = p_ets->pri_tc_tbl[0];
366
367 p_info = &p_hwfn->hw_info;
368 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
369
370 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400371 num_entries, dcbx_version);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400372 if (rc)
373 return rc;
374
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300375 p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
376 DCBX_ETS_MAX_TCS);
377 p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400378 data.pf_id = p_hwfn->rel_pf_id;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400379 data.dcbx_enabled = !!dcbx_version;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400380
381 qed_dcbx_dp_protocol(p_hwfn, &data);
382
383 memcpy(&p_hwfn->p_dcbx_info->results, &data,
384 sizeof(struct qed_dcbx_results));
385
386 return 0;
387}
388
389static int
390qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
391 struct qed_ptt *p_ptt,
392 struct qed_dcbx_mib_meta_data *p_data,
393 enum qed_mib_read_type type)
394{
395 u32 prefix_seq_num, suffix_seq_num;
396 int read_count = 0;
397 int rc = 0;
398
399 /* The data is considered to be valid only if both sequence numbers are
400 * the same.
401 */
402 do {
403 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
404 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
405 p_data->addr, p_data->size);
406 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
407 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
408 } else {
409 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
410 p_data->addr, p_data->size);
411 prefix_seq_num = p_data->mib->prefix_seq_num;
412 suffix_seq_num = p_data->mib->suffix_seq_num;
413 }
414 read_count++;
415
416 DP_VERBOSE(p_hwfn,
417 QED_MSG_DCB,
418 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
419 type, read_count, prefix_seq_num, suffix_seq_num);
420 } while ((prefix_seq_num != suffix_seq_num) &&
421 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
422
423 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
424 DP_ERR(p_hwfn,
425 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
426 type, read_count, prefix_seq_num, suffix_seq_num);
427 rc = -EIO;
428 }
429
430 return rc;
431}
432
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400433static void
434qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
435 struct qed_dcbx_app_prio *p_prio,
436 struct qed_dcbx_results *p_results)
437{
438 u8 val;
439
440 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
441 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
442 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
443 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
444
445 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
446 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
447 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
448
449 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
450 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
451 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
452 p_prio->roce_v2 = val;
453 }
454
455 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
456 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
457 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
458
459 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
460 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
461 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
462
463 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
464 p_results->arr[DCBX_PROTOCOL_ETH].enable)
465 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
466
467 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
468 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
469 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
470 p_prio->eth);
471}
472
473static void
474qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
475 struct dcbx_app_priority_feature *p_app,
476 struct dcbx_app_priority_entry *p_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400477 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400478{
479 struct qed_app_entry *entry;
480 u8 pri_map;
481 int i;
482
483 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
484 DCBX_APP_WILLING);
485 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
486 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
487 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
488 DCBX_APP_NUM_ENTRIES);
489 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
490 entry = &p_params->app_entry[i];
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400491 if (ieee) {
492 u8 sf_ieee;
493 u32 val;
494
495 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
496 DCBX_APP_SF_IEEE);
497 switch (sf_ieee) {
498 case DCBX_APP_SF_IEEE_RESERVED:
499 /* Old MFW */
500 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
501 DCBX_APP_SF);
502 entry->sf_ieee = val ?
503 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
504 QED_DCBX_SF_IEEE_ETHTYPE;
505 break;
506 case DCBX_APP_SF_IEEE_ETHTYPE:
507 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
508 break;
509 case DCBX_APP_SF_IEEE_TCP_PORT:
510 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
511 break;
512 case DCBX_APP_SF_IEEE_UDP_PORT:
513 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
514 break;
515 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
516 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
517 break;
518 }
519 } else {
520 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
521 DCBX_APP_SF));
522 }
523
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400524 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
525 entry->prio = ffs(pri_map) - 1;
526 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
527 DCBX_APP_PROTOCOL_ID);
528 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
529 entry->proto_id,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400530 &entry->proto_type, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400531 }
532
533 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
534 "APP params: willing %d, valid %d error = %d\n",
535 p_params->app_willing, p_params->app_valid,
536 p_params->app_error);
537}
538
539static void
540qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
541 u32 pfc, struct qed_dcbx_params *p_params)
542{
543 u8 pfc_map;
544
545 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
546 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
547 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
548 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
549 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
550 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
551 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
552 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
553 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
554 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
555 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
556 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
557
558 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -0700559 "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
560 p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
561 p_params->pfc.enabled);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400562}
563
564static void
565qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
566 struct dcbx_ets_feature *p_ets,
567 struct qed_dcbx_params *p_params)
568{
569 u32 bw_map[2], tsa_map[2], pri_map;
570 int i;
571
572 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
573 DCBX_ETS_WILLING);
574 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
575 DCBX_ETS_ENABLED);
576 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
577 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
578 DCBX_ETS_MAX_TCS);
579 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -0700580 "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
581 p_params->ets_willing, p_params->ets_enabled,
582 p_params->ets_cbs, p_ets->pri_tc_tbl[0],
583 p_params->max_ets_tc);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400584
sudarsana.kalluru@cavium.com66367da2017-04-19 03:19:52 -0700585 if (p_params->ets_enabled && !p_params->max_ets_tc) {
586 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
587 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
588 "ETS params: max_ets_tc is forced to %d\n",
589 p_params->max_ets_tc);
590 }
591
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400592 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
593 * encoded in a type u32 array of size 2.
594 */
595 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
596 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
597 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
598 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
Sudarsana Reddy Kalluruc0c45a62016-08-08 21:57:40 -0400599 pri_map = p_ets->pri_tc_tbl[0];
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400600 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
601 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
602 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
603 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
604 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
605 "elem %d bw_tbl %x tsa_tbl %x\n",
606 i, p_params->ets_tc_bw_tbl[i],
607 p_params->ets_tc_tsa_tbl[i]);
608 }
609}
610
611static void
612qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
613 struct dcbx_app_priority_feature *p_app,
614 struct dcbx_app_priority_entry *p_tbl,
615 struct dcbx_ets_feature *p_ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400616 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400617{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400618 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400619 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
620 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
621}
622
623static void
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700624qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400625{
626 struct dcbx_features *p_feat;
627
628 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
629 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
630 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400631 p_feat->pfc, &params->local.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400632 params->local.valid = true;
633}
634
635static void
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700636qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400637{
638 struct dcbx_features *p_feat;
639
640 p_feat = &p_hwfn->p_dcbx_info->remote.features;
641 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
642 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400643 p_feat->pfc, &params->remote.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400644 params->remote.valid = true;
645}
646
647static void
648qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400649 struct qed_dcbx_get *params)
650{
651 struct qed_dcbx_operational_params *p_operational;
652 struct qed_dcbx_results *p_results;
653 struct dcbx_features *p_feat;
654 bool enabled, err;
655 u32 flags;
656 bool val;
657
658 flags = p_hwfn->p_dcbx_info->operational.flags;
659
660 /* If DCBx version is non zero, then negotiation
661 * was successfuly performed
662 */
663 p_operational = &params->operational;
664 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
665 DCBX_CONFIG_VERSION_DISABLED);
666 if (!enabled) {
667 p_operational->enabled = enabled;
668 p_operational->valid = false;
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -0700669 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400670 return;
671 }
672
673 p_feat = &p_hwfn->p_dcbx_info->operational.features;
674 p_results = &p_hwfn->p_dcbx_info->results;
675
676 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
677 DCBX_CONFIG_VERSION_IEEE);
678 p_operational->ieee = val;
679 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
680 DCBX_CONFIG_VERSION_CEE);
681 p_operational->cee = val;
682
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -0700683 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
684 DCBX_CONFIG_VERSION_STATIC);
685 p_operational->local = val;
686
687 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
688 "Version support: ieee %d, cee %d, static %d\n",
689 p_operational->ieee, p_operational->cee,
690 p_operational->local);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400691
692 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
693 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400694 p_feat->pfc, &params->operational.params,
695 p_operational->ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400696 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
697 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
698 p_operational->err = err;
699 p_operational->enabled = enabled;
700 p_operational->valid = true;
701}
702
703static void
704qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400705 struct qed_dcbx_get *params)
706{
707 struct lldp_config_params_s *p_local;
708
709 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
710
711 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
712 ARRAY_SIZE(p_local->local_chassis_id));
713 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
714 ARRAY_SIZE(p_local->local_port_id));
715}
716
717static void
718qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400719 struct qed_dcbx_get *params)
720{
721 struct lldp_status_params_s *p_remote;
722
723 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
724
725 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
726 ARRAY_SIZE(p_remote->peer_chassis_id));
727 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
728 ARRAY_SIZE(p_remote->peer_port_id));
729}
730
731static int
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700732qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400733 enum qed_mib_read_type type)
734{
735 switch (type) {
736 case QED_DCBX_REMOTE_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700737 qed_dcbx_get_remote_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400738 break;
739 case QED_DCBX_LOCAL_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700740 qed_dcbx_get_local_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400741 break;
742 case QED_DCBX_OPERATIONAL_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700743 qed_dcbx_get_operational_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400744 break;
745 case QED_DCBX_REMOTE_LLDP_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700746 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400747 break;
748 case QED_DCBX_LOCAL_LLDP_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700749 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400750 break;
751 default:
752 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
753 return -EINVAL;
754 }
755
756 return 0;
757}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400758
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400759static int
760qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
761{
762 struct qed_dcbx_mib_meta_data data;
763 int rc = 0;
764
765 memset(&data, 0, sizeof(data));
766 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
767 lldp_config_params);
768 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
769 data.size = sizeof(struct lldp_config_params_s);
770 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
771
772 return rc;
773}
774
775static int
776qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
777 struct qed_ptt *p_ptt,
778 enum qed_mib_read_type type)
779{
780 struct qed_dcbx_mib_meta_data data;
781 int rc = 0;
782
783 memset(&data, 0, sizeof(data));
784 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
785 lldp_status_params);
786 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
787 data.size = sizeof(struct lldp_status_params_s);
788 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
789
790 return rc;
791}
792
793static int
794qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
795 struct qed_ptt *p_ptt,
796 enum qed_mib_read_type type)
797{
798 struct qed_dcbx_mib_meta_data data;
799 int rc = 0;
800
801 memset(&data, 0, sizeof(data));
802 data.addr = p_hwfn->mcp_info->port_addr +
803 offsetof(struct public_port, operational_dcbx_mib);
804 data.mib = &p_hwfn->p_dcbx_info->operational;
805 data.size = sizeof(struct dcbx_mib);
806 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
807
808 return rc;
809}
810
811static int
812qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
813 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
814{
815 struct qed_dcbx_mib_meta_data data;
816 int rc = 0;
817
818 memset(&data, 0, sizeof(data));
819 data.addr = p_hwfn->mcp_info->port_addr +
820 offsetof(struct public_port, remote_dcbx_mib);
821 data.mib = &p_hwfn->p_dcbx_info->remote;
822 data.size = sizeof(struct dcbx_mib);
823 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
824
825 return rc;
826}
827
828static int
829qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
830{
831 struct qed_dcbx_mib_meta_data data;
832 int rc = 0;
833
834 memset(&data, 0, sizeof(data));
835 data.addr = p_hwfn->mcp_info->port_addr +
836 offsetof(struct public_port, local_admin_dcbx_mib);
837 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
838 data.size = sizeof(struct dcbx_local_params);
839 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
840
841 return rc;
842}
843
844static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
845 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
846{
847 int rc = -EINVAL;
848
849 switch (type) {
850 case QED_DCBX_OPERATIONAL_MIB:
851 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
852 break;
853 case QED_DCBX_REMOTE_MIB:
854 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
855 break;
856 case QED_DCBX_LOCAL_MIB:
857 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
858 break;
859 case QED_DCBX_REMOTE_LLDP_MIB:
860 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
861 break;
862 case QED_DCBX_LOCAL_LLDP_MIB:
863 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
864 break;
865 default:
866 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
867 }
868
869 return rc;
870}
871
Arun Easi1e128c82017-02-15 06:28:22 -0800872void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
873{
874 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
875 void *cookie = hwfn->cdev->ops_cookie;
876
877 if (cookie && op->dcbx_aen)
878 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
879}
880
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400881/* Read updated MIB.
882 * Reconfigure QM and invoke PF update ramrod command if operational MIB
883 * change is detected.
884 */
885int
886qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
887 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
888{
889 int rc = 0;
890
891 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
892 if (rc)
893 return rc;
894
895 if (type == QED_DCBX_OPERATIONAL_MIB) {
896 rc = qed_dcbx_process_mib_info(p_hwfn);
897 if (!rc) {
898 /* reconfigure tcs of QM queues according
899 * to negotiation results
900 */
901 qed_qm_reconf(p_hwfn, p_ptt);
902
903 /* update storm FW with negotiation results */
904 qed_sp_pf_update(p_hwfn);
905 }
906 }
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700907
908 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
Arun Easi1e128c82017-02-15 06:28:22 -0800909 qed_dcbx_aen(p_hwfn, type);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400910
911 return rc;
912}
913
914int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
915{
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400916 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -0700917 if (!p_hwfn->p_dcbx_info)
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700918 return -ENOMEM;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400919
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700920 return 0;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400921}
922
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700923void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400924{
925 kfree(p_hwfn->p_dcbx_info);
Tomer Tayar3587cb82017-05-21 12:10:56 +0300926 p_hwfn->p_dcbx_info = NULL;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400927}
928
929static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
930 struct qed_dcbx_results *p_src,
931 enum dcbx_protocol_type type)
932{
933 p_data->dcb_enable_flag = p_src->arr[type].enable;
934 p_data->dcb_priority = p_src->arr[type].priority;
935 p_data->dcb_tc = p_src->arr[type].tc;
936}
937
938/* Set pf update ramrod command params */
939void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
940 struct pf_update_ramrod_data *p_dest)
941{
942 struct protocol_dcb_data *p_dcb_data;
943 bool update_flag = false;
944
945 p_dest->pf_id = p_src->pf_id;
946
947 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300948 p_dest->update_fcoe_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400949
950 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300951 p_dest->update_roce_dcb_data_mode = update_flag;
952
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400953 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300954 p_dest->update_rroce_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400955
956 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300957 p_dest->update_iscsi_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400958 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
Mintz, Yuval7b6859f2017-05-18 19:41:04 +0300959 p_dest->update_eth_dcb_data_mode = update_flag;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400960
961 p_dcb_data = &p_dest->fcoe_dcb_data;
962 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
963 p_dcb_data = &p_dest->roce_dcb_data;
sudarsana.kalluru@cavium.com449ad502017-04-20 22:31:17 -0700964 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
965 p_dcb_data = &p_dest->rroce_dcb_data;
966 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400967 p_dcb_data = &p_dest->iscsi_dcb_data;
968 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
969 p_dcb_data = &p_dest->eth_dcb_data;
970 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
971}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400972
973#ifdef CONFIG_DCB
974static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
975 struct qed_dcbx_get *p_get,
976 enum qed_mib_read_type type)
977{
978 struct qed_ptt *p_ptt;
979 int rc;
980
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400981 if (IS_VF(p_hwfn->cdev))
982 return -EINVAL;
983
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400984 p_ptt = qed_ptt_acquire(p_hwfn);
985 if (!p_ptt)
986 return -EBUSY;
987
988 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
989 if (rc)
990 goto out;
991
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700992 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400993
994out:
995 qed_ptt_release(p_hwfn, p_ptt);
996 return rc;
997}
998
999static void
1000qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1001 u32 *pfc, struct qed_dcbx_params *p_params)
1002{
1003 u8 pfc_map = 0;
1004 int i;
1005
sudarsana.kalluru@cavium.com6cf75f12017-04-19 03:19:53 -07001006 *pfc &= ~DCBX_PFC_ERROR_MASK;
1007
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001008 if (p_params->pfc.willing)
1009 *pfc |= DCBX_PFC_WILLING_MASK;
1010 else
1011 *pfc &= ~DCBX_PFC_WILLING_MASK;
1012
1013 if (p_params->pfc.enabled)
1014 *pfc |= DCBX_PFC_ENABLED_MASK;
1015 else
1016 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1017
1018 *pfc &= ~DCBX_PFC_CAPS_MASK;
1019 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1020
1021 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1022 if (p_params->pfc.prio[i])
1023 pfc_map |= BIT(i);
1024
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001025 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001026 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1027
1028 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1029}
1030
1031static void
1032qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1033 struct dcbx_ets_feature *p_ets,
1034 struct qed_dcbx_params *p_params)
1035{
1036 u8 *bw_map, *tsa_map;
1037 u32 val;
1038 int i;
1039
1040 if (p_params->ets_willing)
1041 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1042 else
1043 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1044
1045 if (p_params->ets_cbs)
1046 p_ets->flags |= DCBX_ETS_CBS_MASK;
1047 else
1048 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1049
1050 if (p_params->ets_enabled)
1051 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1052 else
1053 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1054
1055 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1056 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1057
1058 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1059 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1060 p_ets->pri_tc_tbl[0] = 0;
1061 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1062 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1063 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1064 /* Copy the priority value to the corresponding 4 bits in the
1065 * traffic class table.
1066 */
1067 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1068 p_ets->pri_tc_tbl[0] |= val;
1069 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001070 for (i = 0; i < 2; i++) {
1071 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1072 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1073 }
1074}
1075
1076static void
1077qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1078 struct dcbx_app_priority_feature *p_app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001079 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001080{
1081 u32 *entry;
1082 int i;
1083
1084 if (p_params->app_willing)
1085 p_app->flags |= DCBX_APP_WILLING_MASK;
1086 else
1087 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1088
1089 if (p_params->app_valid)
1090 p_app->flags |= DCBX_APP_ENABLED_MASK;
1091 else
1092 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1093
1094 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1095 p_app->flags |= (u32)p_params->num_app_entries <<
1096 DCBX_APP_NUM_ENTRIES_SHIFT;
1097
1098 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1099 entry = &p_app->app_pri_tbl[i].entry;
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001100 *entry = 0;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001101 if (ieee) {
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001102 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001103 switch (p_params->app_entry[i].sf_ieee) {
1104 case QED_DCBX_SF_IEEE_ETHTYPE:
1105 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1106 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001107 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1108 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001109 break;
1110 case QED_DCBX_SF_IEEE_TCP_PORT:
1111 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1112 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001113 *entry |= ((u32)DCBX_APP_SF_PORT <<
1114 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001115 break;
1116 case QED_DCBX_SF_IEEE_UDP_PORT:
1117 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1118 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001119 *entry |= ((u32)DCBX_APP_SF_PORT <<
1120 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001121 break;
1122 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1123 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1124 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001125 *entry |= ((u32)DCBX_APP_SF_PORT <<
1126 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001127 break;
1128 }
1129 } else {
1130 *entry &= ~DCBX_APP_SF_MASK;
1131 if (p_params->app_entry[i].ethtype)
1132 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1133 DCBX_APP_SF_SHIFT);
1134 else
1135 *entry |= ((u32)DCBX_APP_SF_PORT <<
1136 DCBX_APP_SF_SHIFT);
1137 }
1138
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001139 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1140 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1141 DCBX_APP_PROTOCOL_ID_SHIFT);
1142 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1143 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1144 DCBX_APP_PRI_MAP_SHIFT);
1145 }
1146}
1147
1148static void
1149qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1150 struct dcbx_local_params *local_admin,
1151 struct qed_dcbx_set *params)
1152{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001153 bool ieee = false;
1154
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001155 local_admin->flags = 0;
1156 memcpy(&local_admin->features,
1157 &p_hwfn->p_dcbx_info->operational.features,
1158 sizeof(local_admin->features));
1159
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001160 if (params->enabled) {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001161 local_admin->config = params->ver_num;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001162 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1163 } else {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001164 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001165 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001166
sudarsana.kalluru@cavium.comdfbeb852017-04-20 22:31:18 -07001167 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
1168 local_admin->config);
1169
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001170 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1171 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1172 &params->config.params);
1173
1174 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1175 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1176 &params->config.params);
1177
1178 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1179 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001180 &params->config.params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001181}
1182
1183int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1184 struct qed_dcbx_set *params, bool hw_commit)
1185{
1186 struct dcbx_local_params local_admin;
1187 struct qed_dcbx_mib_meta_data data;
1188 u32 resp = 0, param = 0;
1189 int rc = 0;
1190
1191 if (!hw_commit) {
1192 memcpy(&p_hwfn->p_dcbx_info->set, params,
1193 sizeof(struct qed_dcbx_set));
1194 return 0;
1195 }
1196
1197 /* clear set-parmas cache */
1198 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1199
1200 memset(&local_admin, 0, sizeof(local_admin));
1201 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1202
1203 data.addr = p_hwfn->mcp_info->port_addr +
1204 offsetof(struct public_port, local_admin_dcbx_mib);
1205 data.local_admin = &local_admin;
1206 data.size = sizeof(struct dcbx_local_params);
1207 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1208
1209 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1210 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
1211 if (rc)
1212 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1213
1214 return rc;
1215}
1216
1217int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1218 struct qed_dcbx_set *params)
1219{
1220 struct qed_dcbx_get *dcbx_info;
1221 int rc;
1222
1223 if (p_hwfn->p_dcbx_info->set.config.valid) {
1224 memcpy(params, &p_hwfn->p_dcbx_info->set,
1225 sizeof(struct qed_dcbx_set));
1226 return 0;
1227 }
1228
Wu Fengguang561ed232016-09-01 14:45:12 +08001229 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -07001230 if (!dcbx_info)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001231 return -ENOMEM;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001232
Sudarsana Reddy Kalluru15c6de22016-10-21 04:43:44 -04001233 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001234 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1235 if (rc) {
1236 kfree(dcbx_info);
1237 return rc;
1238 }
1239
1240 p_hwfn->p_dcbx_info->set.override_flags = 0;
1241 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1242 if (dcbx_info->operational.cee)
1243 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1244 if (dcbx_info->operational.ieee)
1245 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001246 if (dcbx_info->operational.local)
1247 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001248
1249 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1250 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1251 &dcbx_info->operational.params,
1252 sizeof(struct qed_dcbx_admin_params));
1253 p_hwfn->p_dcbx_info->set.config.valid = true;
1254
1255 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1256
1257 kfree(dcbx_info);
1258
1259 return 0;
1260}
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001261
1262static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1263 enum qed_mib_read_type type)
1264{
1265 struct qed_dcbx_get *dcbx_info;
1266
sudarsana.kalluru@cavium.com62289ba2017-04-19 03:19:54 -07001267 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
Joe Perches2591c282016-09-04 14:24:03 -07001268 if (!dcbx_info)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001269 return NULL;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001270
Sudarsana Reddy Kalluru15c6de22016-10-21 04:43:44 -04001271 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001272 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1273 kfree(dcbx_info);
1274 return NULL;
1275 }
1276
1277 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1278 !dcbx_info->operational.enabled) {
1279 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1280 kfree(dcbx_info);
1281 return NULL;
1282 }
1283
1284 return dcbx_info;
1285}
1286
1287static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1288{
1289 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1290 struct qed_dcbx_get *dcbx_info;
1291 bool enabled;
1292
1293 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1294 if (!dcbx_info)
1295 return 0;
1296
1297 enabled = dcbx_info->operational.enabled;
1298 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1299 kfree(dcbx_info);
1300
1301 return enabled;
1302}
1303
1304static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1305{
1306 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1307 struct qed_dcbx_set dcbx_set;
1308 struct qed_ptt *ptt;
1309 int rc;
1310
1311 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1312
1313 memset(&dcbx_set, 0, sizeof(dcbx_set));
1314 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1315 if (rc)
1316 return 1;
1317
1318 dcbx_set.enabled = !!state;
1319
1320 ptt = qed_ptt_acquire(hwfn);
1321 if (!ptt)
1322 return 1;
1323
1324 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1325
1326 qed_ptt_release(hwfn, ptt);
1327
1328 return rc ? 1 : 0;
1329}
1330
1331static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1332 u8 *pgid, u8 *bw_pct, u8 *up_map)
1333{
1334 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1335 struct qed_dcbx_get *dcbx_info;
1336
1337 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1338 *prio_type = *pgid = *bw_pct = *up_map = 0;
1339 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1340 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1341 return;
1342 }
1343
1344 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1345 if (!dcbx_info)
1346 return;
1347
1348 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1349 kfree(dcbx_info);
1350}
1351
1352static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1353{
1354 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1355 struct qed_dcbx_get *dcbx_info;
1356
1357 *bw_pct = 0;
1358 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1359 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1360 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1361 return;
1362 }
1363
1364 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1365 if (!dcbx_info)
1366 return;
1367
1368 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1369 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1370 kfree(dcbx_info);
1371}
1372
1373static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1374 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1375{
1376 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1377 *prio = *bwg_id = *bw_pct = *up_map = 0;
1378}
1379
1380static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1381 int bwg_id, u8 *bw_pct)
1382{
1383 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1384 *bw_pct = 0;
1385}
1386
1387static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1388 int priority, u8 *setting)
1389{
1390 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1391 struct qed_dcbx_get *dcbx_info;
1392
1393 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1394 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1395 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1396 return;
1397 }
1398
1399 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1400 if (!dcbx_info)
1401 return;
1402
1403 *setting = dcbx_info->operational.params.pfc.prio[priority];
1404 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1405 kfree(dcbx_info);
1406}
1407
1408static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1409{
1410 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1411 struct qed_dcbx_set dcbx_set;
1412 struct qed_ptt *ptt;
1413 int rc;
1414
1415 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1416 priority, setting);
1417 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1418 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1419 return;
1420 }
1421
1422 memset(&dcbx_set, 0, sizeof(dcbx_set));
1423 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1424 if (rc)
1425 return;
1426
1427 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1428 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1429
1430 ptt = qed_ptt_acquire(hwfn);
1431 if (!ptt)
1432 return;
1433
1434 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1435
1436 qed_ptt_release(hwfn, ptt);
1437}
1438
1439static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1440{
1441 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1442 struct qed_dcbx_get *dcbx_info;
1443 int rc = 0;
1444
1445 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1446 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1447 if (!dcbx_info)
1448 return 1;
1449
1450 switch (capid) {
1451 case DCB_CAP_ATTR_PG:
1452 case DCB_CAP_ATTR_PFC:
1453 case DCB_CAP_ATTR_UP2TC:
1454 case DCB_CAP_ATTR_GSP:
1455 *cap = true;
1456 break;
1457 case DCB_CAP_ATTR_PG_TCS:
1458 case DCB_CAP_ATTR_PFC_TCS:
1459 *cap = 0x80;
1460 break;
1461 case DCB_CAP_ATTR_DCBX:
1462 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
1463 DCB_CAP_DCBX_VER_IEEE);
1464 break;
1465 default:
1466 *cap = false;
1467 rc = 1;
1468 }
1469
1470 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1471 kfree(dcbx_info);
1472
1473 return rc;
1474}
1475
1476static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1477{
1478 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1479 struct qed_dcbx_get *dcbx_info;
1480 int rc = 0;
1481
1482 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1483 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1484 if (!dcbx_info)
1485 return -EINVAL;
1486
1487 switch (tcid) {
1488 case DCB_NUMTCS_ATTR_PG:
1489 *num = dcbx_info->operational.params.max_ets_tc;
1490 break;
1491 case DCB_NUMTCS_ATTR_PFC:
1492 *num = dcbx_info->operational.params.pfc.max_tc;
1493 break;
1494 default:
1495 rc = -EINVAL;
1496 }
1497
1498 kfree(dcbx_info);
1499 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1500
1501 return rc;
1502}
1503
1504static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1505{
1506 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1507 struct qed_dcbx_get *dcbx_info;
1508 bool enabled;
1509
1510 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1511 if (!dcbx_info)
1512 return 0;
1513
1514 enabled = dcbx_info->operational.params.pfc.enabled;
1515 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1516 kfree(dcbx_info);
1517
1518 return enabled;
1519}
1520
1521static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1522{
1523 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1524 struct qed_dcbx_get *dcbx_info;
1525 u8 mode = 0;
1526
1527 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1528 if (!dcbx_info)
1529 return 0;
1530
1531 if (dcbx_info->operational.enabled)
1532 mode |= DCB_CAP_DCBX_LLD_MANAGED;
1533 if (dcbx_info->operational.ieee)
1534 mode |= DCB_CAP_DCBX_VER_IEEE;
1535 if (dcbx_info->operational.cee)
1536 mode |= DCB_CAP_DCBX_VER_CEE;
1537
1538 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1539 kfree(dcbx_info);
1540
1541 return mode;
1542}
1543
1544static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1545 int tc,
1546 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1547{
1548 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1549 struct qed_dcbx_set dcbx_set;
1550 struct qed_ptt *ptt;
1551 int rc;
1552
1553 DP_VERBOSE(hwfn, QED_MSG_DCB,
1554 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1555 tc, pri_type, pgid, bw_pct, up_map);
1556
1557 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1558 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1559 return;
1560 }
1561
1562 memset(&dcbx_set, 0, sizeof(dcbx_set));
1563 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1564 if (rc)
1565 return;
1566
1567 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1568 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1569
1570 ptt = qed_ptt_acquire(hwfn);
1571 if (!ptt)
1572 return;
1573
1574 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1575
1576 qed_ptt_release(hwfn, ptt);
1577}
1578
1579static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1580 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1581{
1582 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1583}
1584
1585static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1586{
1587 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1588 struct qed_dcbx_set dcbx_set;
1589 struct qed_ptt *ptt;
1590 int rc;
1591
1592 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1593 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1594 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1595 return;
1596 }
1597
1598 memset(&dcbx_set, 0, sizeof(dcbx_set));
1599 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1600 if (rc)
1601 return;
1602
1603 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1604 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1605
1606 ptt = qed_ptt_acquire(hwfn);
1607 if (!ptt)
1608 return;
1609
1610 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1611
1612 qed_ptt_release(hwfn, ptt);
1613}
1614
1615static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1616{
1617 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1618}
1619
1620static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1621{
1622 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1623 struct qed_dcbx_set dcbx_set;
1624 struct qed_ptt *ptt;
1625 int rc;
1626
1627 memset(&dcbx_set, 0, sizeof(dcbx_set));
1628 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1629 if (rc)
1630 return 1;
1631
1632 ptt = qed_ptt_acquire(hwfn);
1633 if (!ptt)
1634 return 1;
1635
1636 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1637
1638 qed_ptt_release(hwfn, ptt);
1639
1640 return rc;
1641}
1642
1643static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1644{
1645 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1646 struct qed_dcbx_set dcbx_set;
1647 struct qed_ptt *ptt;
1648 int rc;
1649
1650 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1651 memset(&dcbx_set, 0, sizeof(dcbx_set));
1652 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1653 if (rc)
1654 return 1;
1655
1656 switch (tcid) {
1657 case DCB_NUMTCS_ATTR_PG:
1658 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1659 dcbx_set.config.params.max_ets_tc = num;
1660 break;
1661 case DCB_NUMTCS_ATTR_PFC:
1662 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1663 dcbx_set.config.params.pfc.max_tc = num;
1664 break;
1665 default:
1666 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1667 return -EINVAL;
1668 }
1669
1670 ptt = qed_ptt_acquire(hwfn);
1671 if (!ptt)
1672 return -EINVAL;
1673
1674 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1675
1676 qed_ptt_release(hwfn, ptt);
1677
1678 return 0;
1679}
1680
1681static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1682{
1683 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1684 struct qed_dcbx_set dcbx_set;
1685 struct qed_ptt *ptt;
1686 int rc;
1687
1688 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1689
1690 memset(&dcbx_set, 0, sizeof(dcbx_set));
1691 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1692 if (rc)
1693 return;
1694
1695 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1696 dcbx_set.config.params.pfc.enabled = !!state;
1697
1698 ptt = qed_ptt_acquire(hwfn);
1699 if (!ptt)
1700 return;
1701
1702 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1703
1704 qed_ptt_release(hwfn, ptt);
1705}
1706
1707static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1708{
1709 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1710 struct qed_dcbx_get *dcbx_info;
1711 struct qed_app_entry *entry;
1712 bool ethtype;
1713 u8 prio = 0;
1714 int i;
1715
1716 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1717 if (!dcbx_info)
1718 return -EINVAL;
1719
1720 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1721 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1722 entry = &dcbx_info->operational.params.app_entry[i];
1723 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1724 prio = entry->prio;
1725 break;
1726 }
1727 }
1728
1729 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1730 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1731 kfree(dcbx_info);
1732 return -EINVAL;
1733 }
1734
1735 kfree(dcbx_info);
1736
1737 return prio;
1738}
1739
1740static int qed_dcbnl_setapp(struct qed_dev *cdev,
1741 u8 idtype, u16 idval, u8 pri_map)
1742{
1743 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1744 struct qed_dcbx_set dcbx_set;
1745 struct qed_app_entry *entry;
1746 struct qed_ptt *ptt;
1747 bool ethtype;
1748 int rc, i;
1749
1750 memset(&dcbx_set, 0, sizeof(dcbx_set));
1751 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1752 if (rc)
1753 return -EINVAL;
1754
1755 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1756 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1757 entry = &dcbx_set.config.params.app_entry[i];
1758 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1759 break;
1760 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001761 if (!entry->proto_id) {
1762 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001763 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001764 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001765 }
1766
1767 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1768 DP_ERR(cdev, "App table is full\n");
1769 return -EBUSY;
1770 }
1771
1772 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1773 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1774 dcbx_set.config.params.app_entry[i].proto_id = idval;
1775 dcbx_set.config.params.app_entry[i].prio = pri_map;
1776
1777 ptt = qed_ptt_acquire(hwfn);
1778 if (!ptt)
1779 return -EBUSY;
1780
1781 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1782
1783 qed_ptt_release(hwfn, ptt);
1784
1785 return rc;
1786}
1787
1788static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1789{
1790 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1791 struct qed_dcbx_set dcbx_set;
1792 struct qed_ptt *ptt;
1793 int rc;
1794
1795 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1796
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001797 if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
1798 !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
1799 DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001800 return 1;
1801 }
1802
1803 memset(&dcbx_set, 0, sizeof(dcbx_set));
1804 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1805 if (rc)
1806 return 1;
1807
1808 dcbx_set.ver_num = 0;
1809 if (mode & DCB_CAP_DCBX_VER_CEE) {
1810 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1811 dcbx_set.enabled = true;
1812 }
1813
1814 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1815 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1816 dcbx_set.enabled = true;
1817 }
1818
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001819 if (mode & DCB_CAP_DCBX_STATIC) {
1820 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1821 dcbx_set.enabled = true;
1822 }
1823
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001824 ptt = qed_ptt_acquire(hwfn);
1825 if (!ptt)
1826 return 1;
1827
1828 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1829
1830 qed_ptt_release(hwfn, ptt);
1831
sudarsana.kalluru@cavium.com49632b582017-04-20 22:31:20 -07001832 return rc;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001833}
1834
1835static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1836{
1837 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1838 struct qed_dcbx_get *dcbx_info;
1839
1840 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1841 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1842 if (!dcbx_info)
1843 return 1;
1844
1845 *flags = 0;
1846 switch (featid) {
1847 case DCB_FEATCFG_ATTR_PG:
1848 if (dcbx_info->operational.params.ets_enabled)
1849 *flags = DCB_FEATCFG_ENABLE;
1850 else
1851 *flags = DCB_FEATCFG_ERROR;
1852 break;
1853 case DCB_FEATCFG_ATTR_PFC:
1854 if (dcbx_info->operational.params.pfc.enabled)
1855 *flags = DCB_FEATCFG_ENABLE;
1856 else
1857 *flags = DCB_FEATCFG_ERROR;
1858 break;
1859 case DCB_FEATCFG_ATTR_APP:
1860 if (dcbx_info->operational.params.app_valid)
1861 *flags = DCB_FEATCFG_ENABLE;
1862 else
1863 *flags = DCB_FEATCFG_ERROR;
1864 break;
1865 default:
1866 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1867 kfree(dcbx_info);
1868 return 1;
1869 }
1870
1871 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1872 kfree(dcbx_info);
1873
1874 return 0;
1875}
1876
1877static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1878{
1879 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1880 struct qed_dcbx_set dcbx_set;
1881 bool enabled, willing;
1882 struct qed_ptt *ptt;
1883 int rc;
1884
1885 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1886 featid, flags);
1887 memset(&dcbx_set, 0, sizeof(dcbx_set));
1888 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1889 if (rc)
1890 return 1;
1891
1892 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1893 willing = !!(flags & DCB_FEATCFG_WILLING);
1894 switch (featid) {
1895 case DCB_FEATCFG_ATTR_PG:
1896 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1897 dcbx_set.config.params.ets_enabled = enabled;
1898 dcbx_set.config.params.ets_willing = willing;
1899 break;
1900 case DCB_FEATCFG_ATTR_PFC:
1901 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1902 dcbx_set.config.params.pfc.enabled = enabled;
1903 dcbx_set.config.params.pfc.willing = willing;
1904 break;
1905 case DCB_FEATCFG_ATTR_APP:
1906 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1907 dcbx_set.config.params.app_willing = willing;
1908 break;
1909 default:
1910 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1911 return 1;
1912 }
1913
1914 ptt = qed_ptt_acquire(hwfn);
1915 if (!ptt)
1916 return 1;
1917
1918 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1919
1920 qed_ptt_release(hwfn, ptt);
1921
1922 return 0;
1923}
1924
1925static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1926 struct dcb_peer_app_info *info,
1927 u16 *app_count)
1928{
1929 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1930 struct qed_dcbx_get *dcbx_info;
1931
1932 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1933 if (!dcbx_info)
1934 return -EINVAL;
1935
1936 info->willing = dcbx_info->remote.params.app_willing;
1937 info->error = dcbx_info->remote.params.app_error;
1938 *app_count = dcbx_info->remote.params.num_app_entries;
1939 kfree(dcbx_info);
1940
1941 return 0;
1942}
1943
1944static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1945 struct dcb_app *table)
1946{
1947 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1948 struct qed_dcbx_get *dcbx_info;
1949 int i;
1950
1951 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1952 if (!dcbx_info)
1953 return -EINVAL;
1954
1955 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1956 if (dcbx_info->remote.params.app_entry[i].ethtype)
1957 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1958 else
1959 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1960 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1961 table[i].protocol =
1962 dcbx_info->remote.params.app_entry[i].proto_id;
1963 }
1964
1965 kfree(dcbx_info);
1966
1967 return 0;
1968}
1969
1970static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1971{
1972 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1973 struct qed_dcbx_get *dcbx_info;
1974 int i;
1975
1976 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1977 if (!dcbx_info)
1978 return -EINVAL;
1979
1980 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1981 if (dcbx_info->remote.params.pfc.prio[i])
1982 pfc->pfc_en |= BIT(i);
1983
1984 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1985 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
1986 pfc->pfc_en, pfc->tcs_supported);
1987 kfree(dcbx_info);
1988
1989 return 0;
1990}
1991
1992static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
1993{
1994 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1995 struct qed_dcbx_get *dcbx_info;
1996 int i;
1997
1998 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1999 if (!dcbx_info)
2000 return -EINVAL;
2001
2002 pg->willing = dcbx_info->remote.params.ets_willing;
2003 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
2004 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
2005 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
2006 }
2007
2008 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
2009 kfree(dcbx_info);
2010
2011 return 0;
2012}
2013
2014static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
2015 struct ieee_pfc *pfc, bool remote)
2016{
2017 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2018 struct qed_dcbx_params *params;
2019 struct qed_dcbx_get *dcbx_info;
2020 int rc, i;
2021
2022 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2023 if (!dcbx_info)
2024 return -EINVAL;
2025
2026 if (!dcbx_info->operational.ieee) {
2027 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
Wei Yongjun02ee9b12016-08-11 23:29:54 +00002028 kfree(dcbx_info);
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002029 return -EINVAL;
2030 }
2031
2032 if (remote) {
2033 memset(dcbx_info, 0, sizeof(*dcbx_info));
2034 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2035 QED_DCBX_REMOTE_MIB);
2036 if (rc) {
2037 kfree(dcbx_info);
2038 return -EINVAL;
2039 }
2040
2041 params = &dcbx_info->remote.params;
2042 } else {
2043 params = &dcbx_info->operational.params;
2044 }
2045
2046 pfc->pfc_cap = params->pfc.max_tc;
2047 pfc->pfc_en = 0;
2048 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2049 if (params->pfc.prio[i])
2050 pfc->pfc_en |= BIT(i);
2051
2052 kfree(dcbx_info);
2053
2054 return 0;
2055}
2056
2057static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2058{
2059 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2060}
2061
2062static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2063{
2064 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2065 struct qed_dcbx_get *dcbx_info;
2066 struct qed_dcbx_set dcbx_set;
2067 struct qed_ptt *ptt;
2068 int rc, i;
2069
2070 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2071 if (!dcbx_info)
2072 return -EINVAL;
2073
2074 if (!dcbx_info->operational.ieee) {
2075 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2076 kfree(dcbx_info);
2077 return -EINVAL;
2078 }
2079
2080 kfree(dcbx_info);
2081
2082 memset(&dcbx_set, 0, sizeof(dcbx_set));
2083 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2084 if (rc)
2085 return -EINVAL;
2086
2087 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2088 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2089 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2090
sudarsana.kalluru@cavium.comc0c5dbe2017-04-19 03:19:55 -07002091 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2092
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002093 ptt = qed_ptt_acquire(hwfn);
2094 if (!ptt)
2095 return -EINVAL;
2096
2097 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2098
2099 qed_ptt_release(hwfn, ptt);
2100
2101 return rc;
2102}
2103
2104static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2105 struct ieee_ets *ets, bool remote)
2106{
2107 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2108 struct qed_dcbx_get *dcbx_info;
2109 struct qed_dcbx_params *params;
2110 int rc;
2111
2112 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2113 if (!dcbx_info)
2114 return -EINVAL;
2115
2116 if (!dcbx_info->operational.ieee) {
2117 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2118 kfree(dcbx_info);
2119 return -EINVAL;
2120 }
2121
2122 if (remote) {
2123 memset(dcbx_info, 0, sizeof(*dcbx_info));
2124 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2125 QED_DCBX_REMOTE_MIB);
2126 if (rc) {
2127 kfree(dcbx_info);
2128 return -EINVAL;
2129 }
2130
2131 params = &dcbx_info->remote.params;
2132 } else {
2133 params = &dcbx_info->operational.params;
2134 }
2135
2136 ets->ets_cap = params->max_ets_tc;
2137 ets->willing = params->ets_willing;
2138 ets->cbs = params->ets_cbs;
2139 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2140 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2141 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2142 kfree(dcbx_info);
2143
2144 return 0;
2145}
2146
2147static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2148{
2149 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2150}
2151
2152static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2153{
2154 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2155 struct qed_dcbx_get *dcbx_info;
2156 struct qed_dcbx_set dcbx_set;
2157 struct qed_ptt *ptt;
2158 int rc;
2159
2160 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2161 if (!dcbx_info)
2162 return -EINVAL;
2163
2164 if (!dcbx_info->operational.ieee) {
2165 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2166 kfree(dcbx_info);
2167 return -EINVAL;
2168 }
2169
2170 kfree(dcbx_info);
2171
2172 memset(&dcbx_set, 0, sizeof(dcbx_set));
2173 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2174 if (rc)
2175 return -EINVAL;
2176
2177 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2178 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2179 dcbx_set.config.params.ets_willing = ets->willing;
2180 dcbx_set.config.params.ets_cbs = ets->cbs;
2181 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2182 sizeof(ets->tc_tx_bw));
2183 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2184 sizeof(ets->tc_tsa));
2185 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2186 sizeof(ets->prio_tc));
2187
2188 ptt = qed_ptt_acquire(hwfn);
2189 if (!ptt)
2190 return -EINVAL;
2191
2192 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2193
2194 qed_ptt_release(hwfn, ptt);
2195
2196 return rc;
2197}
2198
Baoyou Xieba569472016-09-09 09:21:15 +08002199static int
2200qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002201{
2202 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2203}
2204
Baoyou Xieba569472016-09-09 09:21:15 +08002205static int
2206qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002207{
2208 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2209}
2210
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002211static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
2212{
2213 switch (selector) {
2214 case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
2215 *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
2216 break;
2217 case IEEE_8021QAZ_APP_SEL_STREAM:
2218 *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
2219 break;
2220 case IEEE_8021QAZ_APP_SEL_DGRAM:
2221 *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
2222 break;
2223 case IEEE_8021QAZ_APP_SEL_ANY:
2224 *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
2225 break;
2226 default:
2227 return -EINVAL;
2228 }
2229
2230 return 0;
2231}
2232
Baoyou Xieba569472016-09-09 09:21:15 +08002233static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002234{
2235 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2236 struct qed_dcbx_get *dcbx_info;
2237 struct qed_app_entry *entry;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002238 u8 prio = 0;
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002239 u8 sf_ieee;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002240 int i;
2241
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002242 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
2243 app->selector, app->protocol);
2244
2245 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2246 DP_INFO(cdev, "Invalid selector field value %d\n",
2247 app->selector);
2248 return -EINVAL;
2249 }
2250
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002251 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2252 if (!dcbx_info)
2253 return -EINVAL;
2254
2255 if (!dcbx_info->operational.ieee) {
2256 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2257 kfree(dcbx_info);
2258 return -EINVAL;
2259 }
2260
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002261 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2262 entry = &dcbx_info->operational.params.app_entry[i];
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002263 if ((entry->sf_ieee == sf_ieee) &&
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002264 (entry->proto_id == app->protocol)) {
2265 prio = entry->prio;
2266 break;
2267 }
2268 }
2269
2270 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2271 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2272 app->protocol);
2273 kfree(dcbx_info);
2274 return -EINVAL;
2275 }
2276
2277 app->priority = ffs(prio) - 1;
2278
2279 kfree(dcbx_info);
2280
2281 return 0;
2282}
2283
Baoyou Xieba569472016-09-09 09:21:15 +08002284static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002285{
2286 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2287 struct qed_dcbx_get *dcbx_info;
2288 struct qed_dcbx_set dcbx_set;
2289 struct qed_app_entry *entry;
2290 struct qed_ptt *ptt;
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002291 u8 sf_ieee;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002292 int rc, i;
2293
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002294 DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
2295 app->selector, app->protocol, app->priority);
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002296 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2297 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2298 return -EINVAL;
2299 }
2300
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002301 if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
2302 DP_INFO(cdev, "Invalid selector field value %d\n",
2303 app->selector);
2304 return -EINVAL;
2305 }
2306
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002307 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2308 if (!dcbx_info)
2309 return -EINVAL;
2310
2311 if (!dcbx_info->operational.ieee) {
2312 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2313 kfree(dcbx_info);
2314 return -EINVAL;
2315 }
2316
2317 kfree(dcbx_info);
2318
2319 memset(&dcbx_set, 0, sizeof(dcbx_set));
2320 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2321 if (rc)
2322 return -EINVAL;
2323
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002324 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2325 entry = &dcbx_set.config.params.app_entry[i];
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002326 if ((entry->sf_ieee == sf_ieee) &&
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002327 (entry->proto_id == app->protocol))
2328 break;
2329 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002330 if (!entry->proto_id) {
2331 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002332 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002333 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002334 }
2335
2336 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2337 DP_ERR(cdev, "App table is full\n");
2338 return -EBUSY;
2339 }
2340
2341 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
sudarsana.kalluru@cavium.com05a79f92017-04-20 22:31:19 -07002342 dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002343 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2344 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2345
2346 ptt = qed_ptt_acquire(hwfn);
2347 if (!ptt)
2348 return -EBUSY;
2349
2350 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2351
2352 qed_ptt_release(hwfn, ptt);
2353
2354 return rc;
2355}
2356
2357const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2358 .getstate = qed_dcbnl_getstate,
2359 .setstate = qed_dcbnl_setstate,
2360 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2361 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2362 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2363 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2364 .getpfccfg = qed_dcbnl_getpfccfg,
2365 .setpfccfg = qed_dcbnl_setpfccfg,
2366 .getcap = qed_dcbnl_getcap,
2367 .getnumtcs = qed_dcbnl_getnumtcs,
2368 .getpfcstate = qed_dcbnl_getpfcstate,
2369 .getdcbx = qed_dcbnl_getdcbx,
2370 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2371 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2372 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2373 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2374 .setall = qed_dcbnl_setall,
2375 .setnumtcs = qed_dcbnl_setnumtcs,
2376 .setpfcstate = qed_dcbnl_setpfcstate,
2377 .setapp = qed_dcbnl_setapp,
2378 .setdcbx = qed_dcbnl_setdcbx,
2379 .setfeatcfg = qed_dcbnl_setfeatcfg,
2380 .getfeatcfg = qed_dcbnl_getfeatcfg,
2381 .getapp = qed_dcbnl_getapp,
2382 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2383 .peer_getapptable = qed_dcbnl_peer_getapptable,
2384 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2385 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2386 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2387 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2388 .ieee_getets = qed_dcbnl_ieee_getets,
2389 .ieee_setets = qed_dcbnl_ieee_setets,
2390 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2391 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2392 .ieee_getapp = qed_dcbnl_ieee_getapp,
2393 .ieee_setapp = qed_dcbnl_ieee_setapp,
2394};
2395
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04002396#endif