blob: ea16850b8ec536da042c03c4dd7e46eb3e5882ae [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[] = {
67 {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_DEFAULT},
68 {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_DEFAULT},
69 {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_DEFAULT},
70 {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_DEFAULT},
71 {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH}
72};
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,
559 "PFC params: willing %d, pfc_bitmap %d\n",
560 p_params->pfc.willing, pfc_map);
561}
562
563static void
564qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
565 struct dcbx_ets_feature *p_ets,
566 struct qed_dcbx_params *p_params)
567{
568 u32 bw_map[2], tsa_map[2], pri_map;
569 int i;
570
571 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
572 DCBX_ETS_WILLING);
573 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
574 DCBX_ETS_ENABLED);
575 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
576 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
577 DCBX_ETS_MAX_TCS);
578 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
579 "ETS params: willing %d, ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
580 p_params->ets_willing,
581 p_params->ets_cbs,
582 p_ets->pri_tc_tbl[0], p_params->max_ets_tc);
583
sudarsana.kalluru@cavium.com66367da2017-04-19 03:19:52 -0700584 if (p_params->ets_enabled && !p_params->max_ets_tc) {
585 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
586 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
587 "ETS params: max_ets_tc is forced to %d\n",
588 p_params->max_ets_tc);
589 }
590
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400591 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
592 * encoded in a type u32 array of size 2.
593 */
594 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
595 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
596 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
597 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
Sudarsana Reddy Kalluruc0c45a62016-08-08 21:57:40 -0400598 pri_map = p_ets->pri_tc_tbl[0];
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400599 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
600 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
601 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
602 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
603 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
604 "elem %d bw_tbl %x tsa_tbl %x\n",
605 i, p_params->ets_tc_bw_tbl[i],
606 p_params->ets_tc_tsa_tbl[i]);
607 }
608}
609
610static void
611qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
612 struct dcbx_app_priority_feature *p_app,
613 struct dcbx_app_priority_entry *p_tbl,
614 struct dcbx_ets_feature *p_ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400615 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400616{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400617 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400618 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
619 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
620}
621
622static void
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700623qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400624{
625 struct dcbx_features *p_feat;
626
627 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
628 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
629 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400630 p_feat->pfc, &params->local.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400631 params->local.valid = true;
632}
633
634static void
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700635qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400636{
637 struct dcbx_features *p_feat;
638
639 p_feat = &p_hwfn->p_dcbx_info->remote.features;
640 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
641 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400642 p_feat->pfc, &params->remote.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400643 params->remote.valid = true;
644}
645
646static void
647qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400648 struct qed_dcbx_get *params)
649{
650 struct qed_dcbx_operational_params *p_operational;
651 struct qed_dcbx_results *p_results;
652 struct dcbx_features *p_feat;
653 bool enabled, err;
654 u32 flags;
655 bool val;
656
657 flags = p_hwfn->p_dcbx_info->operational.flags;
658
659 /* If DCBx version is non zero, then negotiation
660 * was successfuly performed
661 */
662 p_operational = &params->operational;
663 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
664 DCBX_CONFIG_VERSION_DISABLED);
665 if (!enabled) {
666 p_operational->enabled = enabled;
667 p_operational->valid = false;
668 return;
669 }
670
671 p_feat = &p_hwfn->p_dcbx_info->operational.features;
672 p_results = &p_hwfn->p_dcbx_info->results;
673
674 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
675 DCBX_CONFIG_VERSION_IEEE);
676 p_operational->ieee = val;
677 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
678 DCBX_CONFIG_VERSION_CEE);
679 p_operational->cee = val;
680
681 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Version support: ieee %d, cee %d\n",
682 p_operational->ieee, p_operational->cee);
683
684 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
685 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400686 p_feat->pfc, &params->operational.params,
687 p_operational->ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400688 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
689 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
690 p_operational->err = err;
691 p_operational->enabled = enabled;
692 p_operational->valid = true;
693}
694
695static void
696qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400697 struct qed_dcbx_get *params)
698{
699 struct lldp_config_params_s *p_local;
700
701 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
702
703 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
704 ARRAY_SIZE(p_local->local_chassis_id));
705 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
706 ARRAY_SIZE(p_local->local_port_id));
707}
708
709static void
710qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400711 struct qed_dcbx_get *params)
712{
713 struct lldp_status_params_s *p_remote;
714
715 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
716
717 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
718 ARRAY_SIZE(p_remote->peer_chassis_id));
719 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
720 ARRAY_SIZE(p_remote->peer_port_id));
721}
722
723static int
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700724qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400725 enum qed_mib_read_type type)
726{
727 switch (type) {
728 case QED_DCBX_REMOTE_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700729 qed_dcbx_get_remote_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400730 break;
731 case QED_DCBX_LOCAL_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700732 qed_dcbx_get_local_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400733 break;
734 case QED_DCBX_OPERATIONAL_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700735 qed_dcbx_get_operational_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400736 break;
737 case QED_DCBX_REMOTE_LLDP_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700738 qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400739 break;
740 case QED_DCBX_LOCAL_LLDP_MIB:
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700741 qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400742 break;
743 default:
744 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
745 return -EINVAL;
746 }
747
748 return 0;
749}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400750
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400751static int
752qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
753{
754 struct qed_dcbx_mib_meta_data data;
755 int rc = 0;
756
757 memset(&data, 0, sizeof(data));
758 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
759 lldp_config_params);
760 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
761 data.size = sizeof(struct lldp_config_params_s);
762 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
763
764 return rc;
765}
766
767static int
768qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
769 struct qed_ptt *p_ptt,
770 enum qed_mib_read_type type)
771{
772 struct qed_dcbx_mib_meta_data data;
773 int rc = 0;
774
775 memset(&data, 0, sizeof(data));
776 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
777 lldp_status_params);
778 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
779 data.size = sizeof(struct lldp_status_params_s);
780 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
781
782 return rc;
783}
784
785static int
786qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
787 struct qed_ptt *p_ptt,
788 enum qed_mib_read_type type)
789{
790 struct qed_dcbx_mib_meta_data data;
791 int rc = 0;
792
793 memset(&data, 0, sizeof(data));
794 data.addr = p_hwfn->mcp_info->port_addr +
795 offsetof(struct public_port, operational_dcbx_mib);
796 data.mib = &p_hwfn->p_dcbx_info->operational;
797 data.size = sizeof(struct dcbx_mib);
798 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
799
800 return rc;
801}
802
803static int
804qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
805 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
806{
807 struct qed_dcbx_mib_meta_data data;
808 int rc = 0;
809
810 memset(&data, 0, sizeof(data));
811 data.addr = p_hwfn->mcp_info->port_addr +
812 offsetof(struct public_port, remote_dcbx_mib);
813 data.mib = &p_hwfn->p_dcbx_info->remote;
814 data.size = sizeof(struct dcbx_mib);
815 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
816
817 return rc;
818}
819
820static int
821qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
822{
823 struct qed_dcbx_mib_meta_data data;
824 int rc = 0;
825
826 memset(&data, 0, sizeof(data));
827 data.addr = p_hwfn->mcp_info->port_addr +
828 offsetof(struct public_port, local_admin_dcbx_mib);
829 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
830 data.size = sizeof(struct dcbx_local_params);
831 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
832
833 return rc;
834}
835
836static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
837 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
838{
839 int rc = -EINVAL;
840
841 switch (type) {
842 case QED_DCBX_OPERATIONAL_MIB:
843 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
844 break;
845 case QED_DCBX_REMOTE_MIB:
846 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
847 break;
848 case QED_DCBX_LOCAL_MIB:
849 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
850 break;
851 case QED_DCBX_REMOTE_LLDP_MIB:
852 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
853 break;
854 case QED_DCBX_LOCAL_LLDP_MIB:
855 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
856 break;
857 default:
858 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
859 }
860
861 return rc;
862}
863
Arun Easi1e128c82017-02-15 06:28:22 -0800864void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
865{
866 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
867 void *cookie = hwfn->cdev->ops_cookie;
868
869 if (cookie && op->dcbx_aen)
870 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
871}
872
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400873/* Read updated MIB.
874 * Reconfigure QM and invoke PF update ramrod command if operational MIB
875 * change is detected.
876 */
877int
878qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
879 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
880{
881 int rc = 0;
882
883 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
884 if (rc)
885 return rc;
886
887 if (type == QED_DCBX_OPERATIONAL_MIB) {
888 rc = qed_dcbx_process_mib_info(p_hwfn);
889 if (!rc) {
890 /* reconfigure tcs of QM queues according
891 * to negotiation results
892 */
893 qed_qm_reconf(p_hwfn, p_ptt);
894
895 /* update storm FW with negotiation results */
896 qed_sp_pf_update(p_hwfn);
897 }
898 }
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700899
900 qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
Arun Easi1e128c82017-02-15 06:28:22 -0800901 qed_dcbx_aen(p_hwfn, type);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400902
903 return rc;
904}
905
906int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
907{
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400908 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -0700909 if (!p_hwfn->p_dcbx_info)
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700910 return -ENOMEM;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400911
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700912 return 0;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400913}
914
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700915void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400916{
917 kfree(p_hwfn->p_dcbx_info);
918}
919
920static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
921 struct qed_dcbx_results *p_src,
922 enum dcbx_protocol_type type)
923{
924 p_data->dcb_enable_flag = p_src->arr[type].enable;
925 p_data->dcb_priority = p_src->arr[type].priority;
926 p_data->dcb_tc = p_src->arr[type].tc;
927}
928
929/* Set pf update ramrod command params */
930void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
931 struct pf_update_ramrod_data *p_dest)
932{
933 struct protocol_dcb_data *p_dcb_data;
934 bool update_flag = false;
935
936 p_dest->pf_id = p_src->pf_id;
937
938 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
939 p_dest->update_fcoe_dcb_data_flag = update_flag;
940
941 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
942 p_dest->update_roce_dcb_data_flag = update_flag;
943 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
944 p_dest->update_roce_dcb_data_flag = update_flag;
945
946 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
947 p_dest->update_iscsi_dcb_data_flag = update_flag;
948 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
949 p_dest->update_eth_dcb_data_flag = update_flag;
950
951 p_dcb_data = &p_dest->fcoe_dcb_data;
952 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
953 p_dcb_data = &p_dest->roce_dcb_data;
sudarsana.kalluru@cavium.com449ad502017-04-20 22:31:17 -0700954 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
955 p_dcb_data = &p_dest->rroce_dcb_data;
956 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400957 p_dcb_data = &p_dest->iscsi_dcb_data;
958 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
959 p_dcb_data = &p_dest->eth_dcb_data;
960 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
961}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400962
963#ifdef CONFIG_DCB
964static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
965 struct qed_dcbx_get *p_get,
966 enum qed_mib_read_type type)
967{
968 struct qed_ptt *p_ptt;
969 int rc;
970
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400971 if (IS_VF(p_hwfn->cdev))
972 return -EINVAL;
973
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400974 p_ptt = qed_ptt_acquire(p_hwfn);
975 if (!p_ptt)
976 return -EBUSY;
977
978 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
979 if (rc)
980 goto out;
981
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700982 rc = qed_dcbx_get_params(p_hwfn, p_get, type);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400983
984out:
985 qed_ptt_release(p_hwfn, p_ptt);
986 return rc;
987}
988
989static void
990qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
991 u32 *pfc, struct qed_dcbx_params *p_params)
992{
993 u8 pfc_map = 0;
994 int i;
995
sudarsana.kalluru@cavium.com6cf75f12017-04-19 03:19:53 -0700996 *pfc &= ~DCBX_PFC_ERROR_MASK;
997
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400998 if (p_params->pfc.willing)
999 *pfc |= DCBX_PFC_WILLING_MASK;
1000 else
1001 *pfc &= ~DCBX_PFC_WILLING_MASK;
1002
1003 if (p_params->pfc.enabled)
1004 *pfc |= DCBX_PFC_ENABLED_MASK;
1005 else
1006 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1007
1008 *pfc &= ~DCBX_PFC_CAPS_MASK;
1009 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
1010
1011 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1012 if (p_params->pfc.prio[i])
1013 pfc_map |= BIT(i);
1014
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001015 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001016 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
1017
1018 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
1019}
1020
1021static void
1022qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
1023 struct dcbx_ets_feature *p_ets,
1024 struct qed_dcbx_params *p_params)
1025{
1026 u8 *bw_map, *tsa_map;
1027 u32 val;
1028 int i;
1029
1030 if (p_params->ets_willing)
1031 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1032 else
1033 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1034
1035 if (p_params->ets_cbs)
1036 p_ets->flags |= DCBX_ETS_CBS_MASK;
1037 else
1038 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1039
1040 if (p_params->ets_enabled)
1041 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1042 else
1043 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1044
1045 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1046 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1047
1048 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1049 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1050 p_ets->pri_tc_tbl[0] = 0;
1051 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1052 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1053 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1054 /* Copy the priority value to the corresponding 4 bits in the
1055 * traffic class table.
1056 */
1057 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1058 p_ets->pri_tc_tbl[0] |= val;
1059 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001060 for (i = 0; i < 2; i++) {
1061 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1062 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1063 }
1064}
1065
1066static void
1067qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1068 struct dcbx_app_priority_feature *p_app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001069 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001070{
1071 u32 *entry;
1072 int i;
1073
1074 if (p_params->app_willing)
1075 p_app->flags |= DCBX_APP_WILLING_MASK;
1076 else
1077 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1078
1079 if (p_params->app_valid)
1080 p_app->flags |= DCBX_APP_ENABLED_MASK;
1081 else
1082 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1083
1084 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1085 p_app->flags |= (u32)p_params->num_app_entries <<
1086 DCBX_APP_NUM_ENTRIES_SHIFT;
1087
1088 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1089 entry = &p_app->app_pri_tbl[i].entry;
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001090 *entry = 0;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001091 if (ieee) {
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001092 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001093 switch (p_params->app_entry[i].sf_ieee) {
1094 case QED_DCBX_SF_IEEE_ETHTYPE:
1095 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1096 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001097 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1098 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001099 break;
1100 case QED_DCBX_SF_IEEE_TCP_PORT:
1101 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1102 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001103 *entry |= ((u32)DCBX_APP_SF_PORT <<
1104 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001105 break;
1106 case QED_DCBX_SF_IEEE_UDP_PORT:
1107 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1108 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001109 *entry |= ((u32)DCBX_APP_SF_PORT <<
1110 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001111 break;
1112 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1113 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1114 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001115 *entry |= ((u32)DCBX_APP_SF_PORT <<
1116 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001117 break;
1118 }
1119 } else {
1120 *entry &= ~DCBX_APP_SF_MASK;
1121 if (p_params->app_entry[i].ethtype)
1122 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1123 DCBX_APP_SF_SHIFT);
1124 else
1125 *entry |= ((u32)DCBX_APP_SF_PORT <<
1126 DCBX_APP_SF_SHIFT);
1127 }
1128
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001129 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1130 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1131 DCBX_APP_PROTOCOL_ID_SHIFT);
1132 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1133 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1134 DCBX_APP_PRI_MAP_SHIFT);
1135 }
1136}
1137
1138static void
1139qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1140 struct dcbx_local_params *local_admin,
1141 struct qed_dcbx_set *params)
1142{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001143 bool ieee = false;
1144
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001145 local_admin->flags = 0;
1146 memcpy(&local_admin->features,
1147 &p_hwfn->p_dcbx_info->operational.features,
1148 sizeof(local_admin->features));
1149
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001150 if (params->enabled) {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001151 local_admin->config = params->ver_num;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001152 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1153 } else {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001154 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001155 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001156
1157 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1158 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1159 &params->config.params);
1160
1161 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1162 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1163 &params->config.params);
1164
1165 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1166 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001167 &params->config.params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001168}
1169
1170int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1171 struct qed_dcbx_set *params, bool hw_commit)
1172{
1173 struct dcbx_local_params local_admin;
1174 struct qed_dcbx_mib_meta_data data;
1175 u32 resp = 0, param = 0;
1176 int rc = 0;
1177
1178 if (!hw_commit) {
1179 memcpy(&p_hwfn->p_dcbx_info->set, params,
1180 sizeof(struct qed_dcbx_set));
1181 return 0;
1182 }
1183
1184 /* clear set-parmas cache */
1185 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1186
1187 memset(&local_admin, 0, sizeof(local_admin));
1188 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1189
1190 data.addr = p_hwfn->mcp_info->port_addr +
1191 offsetof(struct public_port, local_admin_dcbx_mib);
1192 data.local_admin = &local_admin;
1193 data.size = sizeof(struct dcbx_local_params);
1194 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1195
1196 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1197 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
1198 if (rc)
1199 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1200
1201 return rc;
1202}
1203
1204int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1205 struct qed_dcbx_set *params)
1206{
1207 struct qed_dcbx_get *dcbx_info;
1208 int rc;
1209
1210 if (p_hwfn->p_dcbx_info->set.config.valid) {
1211 memcpy(params, &p_hwfn->p_dcbx_info->set,
1212 sizeof(struct qed_dcbx_set));
1213 return 0;
1214 }
1215
Wu Fengguang561ed232016-09-01 14:45:12 +08001216 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -07001217 if (!dcbx_info)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001218 return -ENOMEM;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001219
Sudarsana Reddy Kalluru15c6de22016-10-21 04:43:44 -04001220 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001221 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1222 if (rc) {
1223 kfree(dcbx_info);
1224 return rc;
1225 }
1226
1227 p_hwfn->p_dcbx_info->set.override_flags = 0;
1228 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1229 if (dcbx_info->operational.cee)
1230 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1231 if (dcbx_info->operational.ieee)
1232 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1233
1234 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1235 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1236 &dcbx_info->operational.params,
1237 sizeof(struct qed_dcbx_admin_params));
1238 p_hwfn->p_dcbx_info->set.config.valid = true;
1239
1240 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1241
1242 kfree(dcbx_info);
1243
1244 return 0;
1245}
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001246
1247static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1248 enum qed_mib_read_type type)
1249{
1250 struct qed_dcbx_get *dcbx_info;
1251
sudarsana.kalluru@cavium.com62289ba2017-04-19 03:19:54 -07001252 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
Joe Perches2591c282016-09-04 14:24:03 -07001253 if (!dcbx_info)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001254 return NULL;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001255
Sudarsana Reddy Kalluru15c6de22016-10-21 04:43:44 -04001256 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001257 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1258 kfree(dcbx_info);
1259 return NULL;
1260 }
1261
1262 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1263 !dcbx_info->operational.enabled) {
1264 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1265 kfree(dcbx_info);
1266 return NULL;
1267 }
1268
1269 return dcbx_info;
1270}
1271
1272static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1273{
1274 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1275 struct qed_dcbx_get *dcbx_info;
1276 bool enabled;
1277
1278 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1279 if (!dcbx_info)
1280 return 0;
1281
1282 enabled = dcbx_info->operational.enabled;
1283 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1284 kfree(dcbx_info);
1285
1286 return enabled;
1287}
1288
1289static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1290{
1291 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1292 struct qed_dcbx_set dcbx_set;
1293 struct qed_ptt *ptt;
1294 int rc;
1295
1296 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1297
1298 memset(&dcbx_set, 0, sizeof(dcbx_set));
1299 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1300 if (rc)
1301 return 1;
1302
1303 dcbx_set.enabled = !!state;
1304
1305 ptt = qed_ptt_acquire(hwfn);
1306 if (!ptt)
1307 return 1;
1308
1309 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1310
1311 qed_ptt_release(hwfn, ptt);
1312
1313 return rc ? 1 : 0;
1314}
1315
1316static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1317 u8 *pgid, u8 *bw_pct, u8 *up_map)
1318{
1319 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1320 struct qed_dcbx_get *dcbx_info;
1321
1322 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1323 *prio_type = *pgid = *bw_pct = *up_map = 0;
1324 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1325 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1326 return;
1327 }
1328
1329 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1330 if (!dcbx_info)
1331 return;
1332
1333 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1334 kfree(dcbx_info);
1335}
1336
1337static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1338{
1339 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1340 struct qed_dcbx_get *dcbx_info;
1341
1342 *bw_pct = 0;
1343 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1344 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1345 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1346 return;
1347 }
1348
1349 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1350 if (!dcbx_info)
1351 return;
1352
1353 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1354 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1355 kfree(dcbx_info);
1356}
1357
1358static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1359 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1360{
1361 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1362 *prio = *bwg_id = *bw_pct = *up_map = 0;
1363}
1364
1365static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1366 int bwg_id, u8 *bw_pct)
1367{
1368 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1369 *bw_pct = 0;
1370}
1371
1372static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1373 int priority, u8 *setting)
1374{
1375 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1376 struct qed_dcbx_get *dcbx_info;
1377
1378 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1379 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1380 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1381 return;
1382 }
1383
1384 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1385 if (!dcbx_info)
1386 return;
1387
1388 *setting = dcbx_info->operational.params.pfc.prio[priority];
1389 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1390 kfree(dcbx_info);
1391}
1392
1393static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1394{
1395 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1396 struct qed_dcbx_set dcbx_set;
1397 struct qed_ptt *ptt;
1398 int rc;
1399
1400 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1401 priority, setting);
1402 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1403 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1404 return;
1405 }
1406
1407 memset(&dcbx_set, 0, sizeof(dcbx_set));
1408 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1409 if (rc)
1410 return;
1411
1412 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1413 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1414
1415 ptt = qed_ptt_acquire(hwfn);
1416 if (!ptt)
1417 return;
1418
1419 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1420
1421 qed_ptt_release(hwfn, ptt);
1422}
1423
1424static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1425{
1426 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1427 struct qed_dcbx_get *dcbx_info;
1428 int rc = 0;
1429
1430 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1431 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1432 if (!dcbx_info)
1433 return 1;
1434
1435 switch (capid) {
1436 case DCB_CAP_ATTR_PG:
1437 case DCB_CAP_ATTR_PFC:
1438 case DCB_CAP_ATTR_UP2TC:
1439 case DCB_CAP_ATTR_GSP:
1440 *cap = true;
1441 break;
1442 case DCB_CAP_ATTR_PG_TCS:
1443 case DCB_CAP_ATTR_PFC_TCS:
1444 *cap = 0x80;
1445 break;
1446 case DCB_CAP_ATTR_DCBX:
1447 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
1448 DCB_CAP_DCBX_VER_IEEE);
1449 break;
1450 default:
1451 *cap = false;
1452 rc = 1;
1453 }
1454
1455 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1456 kfree(dcbx_info);
1457
1458 return rc;
1459}
1460
1461static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1462{
1463 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1464 struct qed_dcbx_get *dcbx_info;
1465 int rc = 0;
1466
1467 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1468 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1469 if (!dcbx_info)
1470 return -EINVAL;
1471
1472 switch (tcid) {
1473 case DCB_NUMTCS_ATTR_PG:
1474 *num = dcbx_info->operational.params.max_ets_tc;
1475 break;
1476 case DCB_NUMTCS_ATTR_PFC:
1477 *num = dcbx_info->operational.params.pfc.max_tc;
1478 break;
1479 default:
1480 rc = -EINVAL;
1481 }
1482
1483 kfree(dcbx_info);
1484 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1485
1486 return rc;
1487}
1488
1489static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1490{
1491 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1492 struct qed_dcbx_get *dcbx_info;
1493 bool enabled;
1494
1495 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1496 if (!dcbx_info)
1497 return 0;
1498
1499 enabled = dcbx_info->operational.params.pfc.enabled;
1500 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1501 kfree(dcbx_info);
1502
1503 return enabled;
1504}
1505
1506static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1507{
1508 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1509 struct qed_dcbx_get *dcbx_info;
1510 u8 mode = 0;
1511
1512 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1513 if (!dcbx_info)
1514 return 0;
1515
1516 if (dcbx_info->operational.enabled)
1517 mode |= DCB_CAP_DCBX_LLD_MANAGED;
1518 if (dcbx_info->operational.ieee)
1519 mode |= DCB_CAP_DCBX_VER_IEEE;
1520 if (dcbx_info->operational.cee)
1521 mode |= DCB_CAP_DCBX_VER_CEE;
1522
1523 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1524 kfree(dcbx_info);
1525
1526 return mode;
1527}
1528
1529static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1530 int tc,
1531 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1532{
1533 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1534 struct qed_dcbx_set dcbx_set;
1535 struct qed_ptt *ptt;
1536 int rc;
1537
1538 DP_VERBOSE(hwfn, QED_MSG_DCB,
1539 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1540 tc, pri_type, pgid, bw_pct, up_map);
1541
1542 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1543 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1544 return;
1545 }
1546
1547 memset(&dcbx_set, 0, sizeof(dcbx_set));
1548 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1549 if (rc)
1550 return;
1551
1552 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1553 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1554
1555 ptt = qed_ptt_acquire(hwfn);
1556 if (!ptt)
1557 return;
1558
1559 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1560
1561 qed_ptt_release(hwfn, ptt);
1562}
1563
1564static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1565 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1566{
1567 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1568}
1569
1570static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1571{
1572 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1573 struct qed_dcbx_set dcbx_set;
1574 struct qed_ptt *ptt;
1575 int rc;
1576
1577 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1578 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1579 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1580 return;
1581 }
1582
1583 memset(&dcbx_set, 0, sizeof(dcbx_set));
1584 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1585 if (rc)
1586 return;
1587
1588 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1589 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1590
1591 ptt = qed_ptt_acquire(hwfn);
1592 if (!ptt)
1593 return;
1594
1595 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1596
1597 qed_ptt_release(hwfn, ptt);
1598}
1599
1600static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1601{
1602 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1603}
1604
1605static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1606{
1607 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1608 struct qed_dcbx_set dcbx_set;
1609 struct qed_ptt *ptt;
1610 int rc;
1611
1612 memset(&dcbx_set, 0, sizeof(dcbx_set));
1613 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1614 if (rc)
1615 return 1;
1616
1617 ptt = qed_ptt_acquire(hwfn);
1618 if (!ptt)
1619 return 1;
1620
1621 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1622
1623 qed_ptt_release(hwfn, ptt);
1624
1625 return rc;
1626}
1627
1628static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1629{
1630 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1631 struct qed_dcbx_set dcbx_set;
1632 struct qed_ptt *ptt;
1633 int rc;
1634
1635 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1636 memset(&dcbx_set, 0, sizeof(dcbx_set));
1637 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1638 if (rc)
1639 return 1;
1640
1641 switch (tcid) {
1642 case DCB_NUMTCS_ATTR_PG:
1643 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1644 dcbx_set.config.params.max_ets_tc = num;
1645 break;
1646 case DCB_NUMTCS_ATTR_PFC:
1647 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1648 dcbx_set.config.params.pfc.max_tc = num;
1649 break;
1650 default:
1651 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1652 return -EINVAL;
1653 }
1654
1655 ptt = qed_ptt_acquire(hwfn);
1656 if (!ptt)
1657 return -EINVAL;
1658
1659 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1660
1661 qed_ptt_release(hwfn, ptt);
1662
1663 return 0;
1664}
1665
1666static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1667{
1668 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1669 struct qed_dcbx_set dcbx_set;
1670 struct qed_ptt *ptt;
1671 int rc;
1672
1673 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1674
1675 memset(&dcbx_set, 0, sizeof(dcbx_set));
1676 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1677 if (rc)
1678 return;
1679
1680 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1681 dcbx_set.config.params.pfc.enabled = !!state;
1682
1683 ptt = qed_ptt_acquire(hwfn);
1684 if (!ptt)
1685 return;
1686
1687 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1688
1689 qed_ptt_release(hwfn, ptt);
1690}
1691
1692static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1693{
1694 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1695 struct qed_dcbx_get *dcbx_info;
1696 struct qed_app_entry *entry;
1697 bool ethtype;
1698 u8 prio = 0;
1699 int i;
1700
1701 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1702 if (!dcbx_info)
1703 return -EINVAL;
1704
1705 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1706 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1707 entry = &dcbx_info->operational.params.app_entry[i];
1708 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1709 prio = entry->prio;
1710 break;
1711 }
1712 }
1713
1714 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1715 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1716 kfree(dcbx_info);
1717 return -EINVAL;
1718 }
1719
1720 kfree(dcbx_info);
1721
1722 return prio;
1723}
1724
1725static int qed_dcbnl_setapp(struct qed_dev *cdev,
1726 u8 idtype, u16 idval, u8 pri_map)
1727{
1728 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1729 struct qed_dcbx_set dcbx_set;
1730 struct qed_app_entry *entry;
1731 struct qed_ptt *ptt;
1732 bool ethtype;
1733 int rc, i;
1734
1735 memset(&dcbx_set, 0, sizeof(dcbx_set));
1736 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1737 if (rc)
1738 return -EINVAL;
1739
1740 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1741 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1742 entry = &dcbx_set.config.params.app_entry[i];
1743 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1744 break;
1745 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001746 if (!entry->proto_id) {
1747 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001748 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001749 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001750 }
1751
1752 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1753 DP_ERR(cdev, "App table is full\n");
1754 return -EBUSY;
1755 }
1756
1757 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1758 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1759 dcbx_set.config.params.app_entry[i].proto_id = idval;
1760 dcbx_set.config.params.app_entry[i].prio = pri_map;
1761
1762 ptt = qed_ptt_acquire(hwfn);
1763 if (!ptt)
1764 return -EBUSY;
1765
1766 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1767
1768 qed_ptt_release(hwfn, ptt);
1769
1770 return rc;
1771}
1772
1773static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1774{
1775 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1776 struct qed_dcbx_set dcbx_set;
1777 struct qed_ptt *ptt;
1778 int rc;
1779
1780 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1781
1782 if (!(mode & DCB_CAP_DCBX_VER_IEEE) && !(mode & DCB_CAP_DCBX_VER_CEE)) {
1783 DP_INFO(hwfn, "Allowed mode is cee, ieee or both\n");
1784 return 1;
1785 }
1786
1787 memset(&dcbx_set, 0, sizeof(dcbx_set));
1788 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1789 if (rc)
1790 return 1;
1791
1792 dcbx_set.ver_num = 0;
1793 if (mode & DCB_CAP_DCBX_VER_CEE) {
1794 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1795 dcbx_set.enabled = true;
1796 }
1797
1798 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1799 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1800 dcbx_set.enabled = true;
1801 }
1802
1803 ptt = qed_ptt_acquire(hwfn);
1804 if (!ptt)
1805 return 1;
1806
1807 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1808
1809 qed_ptt_release(hwfn, ptt);
1810
1811 return 0;
1812}
1813
1814static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1815{
1816 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1817 struct qed_dcbx_get *dcbx_info;
1818
1819 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1820 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1821 if (!dcbx_info)
1822 return 1;
1823
1824 *flags = 0;
1825 switch (featid) {
1826 case DCB_FEATCFG_ATTR_PG:
1827 if (dcbx_info->operational.params.ets_enabled)
1828 *flags = DCB_FEATCFG_ENABLE;
1829 else
1830 *flags = DCB_FEATCFG_ERROR;
1831 break;
1832 case DCB_FEATCFG_ATTR_PFC:
1833 if (dcbx_info->operational.params.pfc.enabled)
1834 *flags = DCB_FEATCFG_ENABLE;
1835 else
1836 *flags = DCB_FEATCFG_ERROR;
1837 break;
1838 case DCB_FEATCFG_ATTR_APP:
1839 if (dcbx_info->operational.params.app_valid)
1840 *flags = DCB_FEATCFG_ENABLE;
1841 else
1842 *flags = DCB_FEATCFG_ERROR;
1843 break;
1844 default:
1845 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1846 kfree(dcbx_info);
1847 return 1;
1848 }
1849
1850 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1851 kfree(dcbx_info);
1852
1853 return 0;
1854}
1855
1856static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1857{
1858 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1859 struct qed_dcbx_set dcbx_set;
1860 bool enabled, willing;
1861 struct qed_ptt *ptt;
1862 int rc;
1863
1864 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1865 featid, flags);
1866 memset(&dcbx_set, 0, sizeof(dcbx_set));
1867 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1868 if (rc)
1869 return 1;
1870
1871 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1872 willing = !!(flags & DCB_FEATCFG_WILLING);
1873 switch (featid) {
1874 case DCB_FEATCFG_ATTR_PG:
1875 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1876 dcbx_set.config.params.ets_enabled = enabled;
1877 dcbx_set.config.params.ets_willing = willing;
1878 break;
1879 case DCB_FEATCFG_ATTR_PFC:
1880 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1881 dcbx_set.config.params.pfc.enabled = enabled;
1882 dcbx_set.config.params.pfc.willing = willing;
1883 break;
1884 case DCB_FEATCFG_ATTR_APP:
1885 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1886 dcbx_set.config.params.app_willing = willing;
1887 break;
1888 default:
1889 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1890 return 1;
1891 }
1892
1893 ptt = qed_ptt_acquire(hwfn);
1894 if (!ptt)
1895 return 1;
1896
1897 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1898
1899 qed_ptt_release(hwfn, ptt);
1900
1901 return 0;
1902}
1903
1904static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1905 struct dcb_peer_app_info *info,
1906 u16 *app_count)
1907{
1908 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1909 struct qed_dcbx_get *dcbx_info;
1910
1911 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1912 if (!dcbx_info)
1913 return -EINVAL;
1914
1915 info->willing = dcbx_info->remote.params.app_willing;
1916 info->error = dcbx_info->remote.params.app_error;
1917 *app_count = dcbx_info->remote.params.num_app_entries;
1918 kfree(dcbx_info);
1919
1920 return 0;
1921}
1922
1923static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1924 struct dcb_app *table)
1925{
1926 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1927 struct qed_dcbx_get *dcbx_info;
1928 int i;
1929
1930 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1931 if (!dcbx_info)
1932 return -EINVAL;
1933
1934 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1935 if (dcbx_info->remote.params.app_entry[i].ethtype)
1936 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1937 else
1938 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1939 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1940 table[i].protocol =
1941 dcbx_info->remote.params.app_entry[i].proto_id;
1942 }
1943
1944 kfree(dcbx_info);
1945
1946 return 0;
1947}
1948
1949static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1950{
1951 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1952 struct qed_dcbx_get *dcbx_info;
1953 int i;
1954
1955 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1956 if (!dcbx_info)
1957 return -EINVAL;
1958
1959 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1960 if (dcbx_info->remote.params.pfc.prio[i])
1961 pfc->pfc_en |= BIT(i);
1962
1963 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1964 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
1965 pfc->pfc_en, pfc->tcs_supported);
1966 kfree(dcbx_info);
1967
1968 return 0;
1969}
1970
1971static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
1972{
1973 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1974 struct qed_dcbx_get *dcbx_info;
1975 int i;
1976
1977 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1978 if (!dcbx_info)
1979 return -EINVAL;
1980
1981 pg->willing = dcbx_info->remote.params.ets_willing;
1982 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1983 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
1984 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
1985 }
1986
1987 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
1988 kfree(dcbx_info);
1989
1990 return 0;
1991}
1992
1993static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
1994 struct ieee_pfc *pfc, bool remote)
1995{
1996 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1997 struct qed_dcbx_params *params;
1998 struct qed_dcbx_get *dcbx_info;
1999 int rc, i;
2000
2001 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2002 if (!dcbx_info)
2003 return -EINVAL;
2004
2005 if (!dcbx_info->operational.ieee) {
2006 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
Wei Yongjun02ee9b12016-08-11 23:29:54 +00002007 kfree(dcbx_info);
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002008 return -EINVAL;
2009 }
2010
2011 if (remote) {
2012 memset(dcbx_info, 0, sizeof(*dcbx_info));
2013 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2014 QED_DCBX_REMOTE_MIB);
2015 if (rc) {
2016 kfree(dcbx_info);
2017 return -EINVAL;
2018 }
2019
2020 params = &dcbx_info->remote.params;
2021 } else {
2022 params = &dcbx_info->operational.params;
2023 }
2024
2025 pfc->pfc_cap = params->pfc.max_tc;
2026 pfc->pfc_en = 0;
2027 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2028 if (params->pfc.prio[i])
2029 pfc->pfc_en |= BIT(i);
2030
2031 kfree(dcbx_info);
2032
2033 return 0;
2034}
2035
2036static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2037{
2038 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2039}
2040
2041static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2042{
2043 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2044 struct qed_dcbx_get *dcbx_info;
2045 struct qed_dcbx_set dcbx_set;
2046 struct qed_ptt *ptt;
2047 int rc, i;
2048
2049 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2050 if (!dcbx_info)
2051 return -EINVAL;
2052
2053 if (!dcbx_info->operational.ieee) {
2054 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2055 kfree(dcbx_info);
2056 return -EINVAL;
2057 }
2058
2059 kfree(dcbx_info);
2060
2061 memset(&dcbx_set, 0, sizeof(dcbx_set));
2062 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2063 if (rc)
2064 return -EINVAL;
2065
2066 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2067 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2068 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2069
sudarsana.kalluru@cavium.comc0c5dbe2017-04-19 03:19:55 -07002070 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2071
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002072 ptt = qed_ptt_acquire(hwfn);
2073 if (!ptt)
2074 return -EINVAL;
2075
2076 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2077
2078 qed_ptt_release(hwfn, ptt);
2079
2080 return rc;
2081}
2082
2083static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2084 struct ieee_ets *ets, bool remote)
2085{
2086 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2087 struct qed_dcbx_get *dcbx_info;
2088 struct qed_dcbx_params *params;
2089 int rc;
2090
2091 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2092 if (!dcbx_info)
2093 return -EINVAL;
2094
2095 if (!dcbx_info->operational.ieee) {
2096 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2097 kfree(dcbx_info);
2098 return -EINVAL;
2099 }
2100
2101 if (remote) {
2102 memset(dcbx_info, 0, sizeof(*dcbx_info));
2103 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2104 QED_DCBX_REMOTE_MIB);
2105 if (rc) {
2106 kfree(dcbx_info);
2107 return -EINVAL;
2108 }
2109
2110 params = &dcbx_info->remote.params;
2111 } else {
2112 params = &dcbx_info->operational.params;
2113 }
2114
2115 ets->ets_cap = params->max_ets_tc;
2116 ets->willing = params->ets_willing;
2117 ets->cbs = params->ets_cbs;
2118 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2119 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2120 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2121 kfree(dcbx_info);
2122
2123 return 0;
2124}
2125
2126static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2127{
2128 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2129}
2130
2131static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2132{
2133 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2134 struct qed_dcbx_get *dcbx_info;
2135 struct qed_dcbx_set dcbx_set;
2136 struct qed_ptt *ptt;
2137 int rc;
2138
2139 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2140 if (!dcbx_info)
2141 return -EINVAL;
2142
2143 if (!dcbx_info->operational.ieee) {
2144 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2145 kfree(dcbx_info);
2146 return -EINVAL;
2147 }
2148
2149 kfree(dcbx_info);
2150
2151 memset(&dcbx_set, 0, sizeof(dcbx_set));
2152 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2153 if (rc)
2154 return -EINVAL;
2155
2156 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2157 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2158 dcbx_set.config.params.ets_willing = ets->willing;
2159 dcbx_set.config.params.ets_cbs = ets->cbs;
2160 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2161 sizeof(ets->tc_tx_bw));
2162 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2163 sizeof(ets->tc_tsa));
2164 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2165 sizeof(ets->prio_tc));
2166
2167 ptt = qed_ptt_acquire(hwfn);
2168 if (!ptt)
2169 return -EINVAL;
2170
2171 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2172
2173 qed_ptt_release(hwfn, ptt);
2174
2175 return rc;
2176}
2177
Baoyou Xieba569472016-09-09 09:21:15 +08002178static int
2179qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002180{
2181 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2182}
2183
Baoyou Xieba569472016-09-09 09:21:15 +08002184static int
2185qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002186{
2187 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2188}
2189
Baoyou Xieba569472016-09-09 09:21:15 +08002190static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002191{
2192 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2193 struct qed_dcbx_get *dcbx_info;
2194 struct qed_app_entry *entry;
2195 bool ethtype;
2196 u8 prio = 0;
2197 int i;
2198
2199 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2200 if (!dcbx_info)
2201 return -EINVAL;
2202
2203 if (!dcbx_info->operational.ieee) {
2204 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2205 kfree(dcbx_info);
2206 return -EINVAL;
2207 }
2208
2209 /* ieee defines the selector field value for ethertype to be 1 */
2210 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2211 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2212 entry = &dcbx_info->operational.params.app_entry[i];
2213 if ((entry->ethtype == ethtype) &&
2214 (entry->proto_id == app->protocol)) {
2215 prio = entry->prio;
2216 break;
2217 }
2218 }
2219
2220 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2221 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2222 app->protocol);
2223 kfree(dcbx_info);
2224 return -EINVAL;
2225 }
2226
2227 app->priority = ffs(prio) - 1;
2228
2229 kfree(dcbx_info);
2230
2231 return 0;
2232}
2233
Baoyou Xieba569472016-09-09 09:21:15 +08002234static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002235{
2236 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2237 struct qed_dcbx_get *dcbx_info;
2238 struct qed_dcbx_set dcbx_set;
2239 struct qed_app_entry *entry;
2240 struct qed_ptt *ptt;
2241 bool ethtype;
2242 int rc, i;
2243
2244 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2245 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2246 return -EINVAL;
2247 }
2248
2249 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2250 if (!dcbx_info)
2251 return -EINVAL;
2252
2253 if (!dcbx_info->operational.ieee) {
2254 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2255 kfree(dcbx_info);
2256 return -EINVAL;
2257 }
2258
2259 kfree(dcbx_info);
2260
2261 memset(&dcbx_set, 0, sizeof(dcbx_set));
2262 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2263 if (rc)
2264 return -EINVAL;
2265
2266 /* ieee defines the selector field value for ethertype to be 1 */
2267 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2268 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2269 entry = &dcbx_set.config.params.app_entry[i];
2270 if ((entry->ethtype == ethtype) &&
2271 (entry->proto_id == app->protocol))
2272 break;
2273 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002274 if (!entry->proto_id) {
2275 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002276 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002277 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002278 }
2279
2280 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2281 DP_ERR(cdev, "App table is full\n");
2282 return -EBUSY;
2283 }
2284
2285 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2286 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
2287 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2288 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2289
2290 ptt = qed_ptt_acquire(hwfn);
2291 if (!ptt)
2292 return -EBUSY;
2293
2294 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2295
2296 qed_ptt_release(hwfn, ptt);
2297
2298 return rc;
2299}
2300
2301const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2302 .getstate = qed_dcbnl_getstate,
2303 .setstate = qed_dcbnl_setstate,
2304 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2305 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2306 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2307 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2308 .getpfccfg = qed_dcbnl_getpfccfg,
2309 .setpfccfg = qed_dcbnl_setpfccfg,
2310 .getcap = qed_dcbnl_getcap,
2311 .getnumtcs = qed_dcbnl_getnumtcs,
2312 .getpfcstate = qed_dcbnl_getpfcstate,
2313 .getdcbx = qed_dcbnl_getdcbx,
2314 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2315 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2316 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2317 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2318 .setall = qed_dcbnl_setall,
2319 .setnumtcs = qed_dcbnl_setnumtcs,
2320 .setpfcstate = qed_dcbnl_setpfcstate,
2321 .setapp = qed_dcbnl_setapp,
2322 .setdcbx = qed_dcbnl_setdcbx,
2323 .setfeatcfg = qed_dcbnl_setfeatcfg,
2324 .getfeatcfg = qed_dcbnl_getfeatcfg,
2325 .getapp = qed_dcbnl_getapp,
2326 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2327 .peer_getapptable = qed_dcbnl_peer_getapptable,
2328 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2329 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2330 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2331 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2332 .ieee_getets = qed_dcbnl_ieee_getets,
2333 .ieee_setets = qed_dcbnl_ieee_setets,
2334 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2335 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2336 .ieee_getapp = qed_dcbnl_ieee_getapp,
2337 .ieee_setapp = qed_dcbnl_ieee_setapp,
2338};
2339
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04002340#endif