blob: 192a886edfe911f046196b3aeaf9f0435848dd9e [file] [log] [blame]
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -04001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#include <linux/types.h>
10#include <asm/byteorder.h>
11#include <linux/bitops.h>
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -040012#include <linux/dcbnl.h>
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040013#include <linux/errno.h>
14#include <linux/kernel.h>
15#include <linux/slab.h>
16#include <linux/string.h>
17#include "qed.h"
18#include "qed_cxt.h"
19#include "qed_dcbx.h"
20#include "qed_hsi.h"
21#include "qed_sp.h"
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -040022#include "qed_sriov.h"
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -040023#ifdef CONFIG_DCB
24#include <linux/qed/qed_eth_if.h>
25#endif
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040026
27#define QED_DCBX_MAX_MIB_READ_TRY (100)
28#define QED_ETH_TYPE_DEFAULT (0)
29#define QED_ETH_TYPE_ROCE (0x8915)
30#define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7)
31#define QED_ETH_TYPE_FCOE (0x8906)
32#define QED_TCP_PORT_ISCSI (0xCBC)
33
34#define QED_DCBX_INVALID_PRIORITY 0xFF
35
36/* Get Traffic Class from priority traffic class table, 4 bits represent
37 * the traffic class corresponding to the priority.
38 */
39#define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \
40 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
41
42static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = {
43 {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_DEFAULT},
44 {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_DEFAULT},
45 {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_DEFAULT},
46 {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_DEFAULT},
47 {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH}
48};
49
50static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
51{
52 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
53 DCBX_APP_SF_ETHTYPE);
54}
55
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -040056static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
57{
58 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
59
60 /* Old MFW */
61 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
62 return qed_dcbx_app_ethtype(app_info_bitmap);
63
64 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
65}
66
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040067static bool qed_dcbx_app_port(u32 app_info_bitmap)
68{
69 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
70 DCBX_APP_SF_PORT);
71}
72
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -040073static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
74{
75 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
76
77 /* Old MFW */
78 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
79 return qed_dcbx_app_port(app_info_bitmap);
80
81 return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
82}
83
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -040084static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040085{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -040086 bool ethtype;
87
88 if (ieee)
89 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
90 else
91 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
92
93 return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040094}
95
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -040096static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040097{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -040098 bool port;
99
100 if (ieee)
101 port = qed_dcbx_ieee_app_port(app_info_bitmap,
102 DCBX_APP_SF_IEEE_TCP_PORT);
103 else
104 port = qed_dcbx_app_port(app_info_bitmap);
105
106 return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400107}
108
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400109static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400110{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400111 bool ethtype;
112
113 if (ieee)
114 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
115 else
116 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
117
118 return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400119}
120
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400121static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400122{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400123 bool ethtype;
124
125 if (ieee)
126 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
127 else
128 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
129
130 return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400131}
132
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400133static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400134{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400135 bool port;
136
137 if (ieee)
138 port = qed_dcbx_ieee_app_port(app_info_bitmap,
139 DCBX_APP_SF_IEEE_UDP_PORT);
140 else
141 port = qed_dcbx_app_port(app_info_bitmap);
142
143 return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400144}
145
146static void
147qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data)
148{
149 enum dcbx_protocol_type id;
150 int i;
151
152 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n",
153 p_data->dcbx_enabled);
154
155 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
156 id = qed_dcbx_app_update[i].id;
157
158 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
159 "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
160 qed_dcbx_app_update[i].name, p_data->arr[id].update,
161 p_data->arr[id].enable, p_data->arr[id].priority,
162 p_data->arr[id].tc, p_hwfn->hw_info.num_tc);
163 }
164}
165
166static void
167qed_dcbx_set_params(struct qed_dcbx_results *p_data,
168 struct qed_hw_info *p_info,
169 bool enable,
170 bool update,
171 u8 prio,
172 u8 tc,
173 enum dcbx_protocol_type type,
174 enum qed_pci_personality personality)
175{
176 /* PF update ramrod data */
177 p_data->arr[type].update = update;
178 p_data->arr[type].enable = enable;
179 p_data->arr[type].priority = prio;
180 p_data->arr[type].tc = tc;
181
182 /* QM reconf data */
183 if (p_info->personality == personality) {
184 if (personality == QED_PCI_ETH)
185 p_info->non_offload_tc = tc;
186 else
187 p_info->offload_tc = tc;
188 }
189}
190
191/* Update app protocol data and hw_info fields with the TLV info */
192static void
193qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
194 struct qed_hwfn *p_hwfn,
195 bool enable,
196 bool update,
197 u8 prio, u8 tc, enum dcbx_protocol_type type)
198{
199 struct qed_hw_info *p_info = &p_hwfn->hw_info;
200 enum qed_pci_personality personality;
201 enum dcbx_protocol_type id;
202 char *name;
203 int i;
204
205 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
206 id = qed_dcbx_app_update[i].id;
207
208 if (type != id)
209 continue;
210
211 personality = qed_dcbx_app_update[i].personality;
212 name = qed_dcbx_app_update[i].name;
213
214 qed_dcbx_set_params(p_data, p_info, enable, update,
215 prio, tc, type, personality);
216 }
217}
218
219static bool
220qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
221 u32 app_prio_bitmap,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400222 u16 id, enum dcbx_protocol_type *type, bool ieee)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400223{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400224 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400225 *type = DCBX_PROTOCOL_FCOE;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400226 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400227 *type = DCBX_PROTOCOL_ROCE;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400228 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400229 *type = DCBX_PROTOCOL_ISCSI;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400230 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400231 *type = DCBX_PROTOCOL_ETH;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400232 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400233 *type = DCBX_PROTOCOL_ROCE_V2;
234 } else {
235 *type = DCBX_MAX_PROTOCOL_TYPE;
236 DP_ERR(p_hwfn,
237 "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
238 id, app_prio_bitmap);
239 return false;
240 }
241
242 return true;
243}
244
245/* Parse app TLV's to update TC information in hw_info structure for
246 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
247 */
248static int
249qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
250 struct qed_dcbx_results *p_data,
251 struct dcbx_app_priority_entry *p_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400252 u32 pri_tc_tbl, int count, u8 dcbx_version)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400253{
Dan Carpenter54b94302016-05-23 13:19:35 +0300254 u8 tc, priority_map;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400255 enum dcbx_protocol_type type;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400256 bool enable, ieee;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400257 u16 protocol_id;
Dan Carpenter54b94302016-05-23 13:19:35 +0300258 int priority;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400259 int i;
260
261 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
262
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400263 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400264 /* Parse APP TLV */
265 for (i = 0; i < count; i++) {
266 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
267 DCBX_APP_PROTOCOL_ID);
268 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
269 DCBX_APP_PRI_MAP);
270 priority = ffs(priority_map) - 1;
271 if (priority < 0) {
272 DP_ERR(p_hwfn, "Invalid priority\n");
273 return -EINVAL;
274 }
275
276 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
277 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400278 protocol_id, &type, ieee)) {
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400279 /* ETH always have the enable bit reset, as it gets
280 * vlan information per packet. For other protocols,
281 * should be set according to the dcbx_enabled
282 * indication, but we only got here if there was an
283 * app tlv for the protocol, so dcbx must be enabled.
284 */
Sudarsana Reddy Kalluruec7c7f52016-05-24 05:25:23 -0400285 enable = !(type == DCBX_PROTOCOL_ETH);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400286
287 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true,
288 priority, tc, type);
289 }
290 }
291
292 /* If RoCE-V2 TLV is not detected, driver need to use RoCE app
293 * data for RoCE-v2 not the default app data.
294 */
295 if (!p_data->arr[DCBX_PROTOCOL_ROCE_V2].update &&
296 p_data->arr[DCBX_PROTOCOL_ROCE].update) {
297 tc = p_data->arr[DCBX_PROTOCOL_ROCE].tc;
298 priority = p_data->arr[DCBX_PROTOCOL_ROCE].priority;
299 qed_dcbx_update_app_info(p_data, p_hwfn, true, true,
300 priority, tc, DCBX_PROTOCOL_ROCE_V2);
301 }
302
303 /* Update ramrod protocol data and hw_info fields
304 * with default info when corresponding APP TLV's are not detected.
305 * The enabled field has a different logic for ethernet as only for
306 * ethernet dcb should disabled by default, as the information arrives
307 * from the OS (unless an explicit app tlv was present).
308 */
309 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
310 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
311 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
312 if (p_data->arr[type].update)
313 continue;
314
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400315 enable = !(type == DCBX_PROTOCOL_ETH);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400316 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true,
317 priority, tc, type);
318 }
319
320 return 0;
321}
322
323/* Parse app TLV's to update TC information in hw_info structure for
324 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
325 */
326static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
327{
328 struct dcbx_app_priority_feature *p_app;
329 struct dcbx_app_priority_entry *p_tbl;
330 struct qed_dcbx_results data = { 0 };
331 struct dcbx_ets_feature *p_ets;
332 struct qed_hw_info *p_info;
333 u32 pri_tc_tbl, flags;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400334 u8 dcbx_version;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400335 int num_entries;
336 int rc = 0;
337
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400338 flags = p_hwfn->p_dcbx_info->operational.flags;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400339 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400340
341 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
342 p_tbl = p_app->app_pri_tbl;
343
344 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
345 pri_tc_tbl = p_ets->pri_tc_tbl[0];
346
347 p_info = &p_hwfn->hw_info;
348 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
349
350 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400351 num_entries, dcbx_version);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400352 if (rc)
353 return rc;
354
355 p_info->num_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
356 data.pf_id = p_hwfn->rel_pf_id;
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400357 data.dcbx_enabled = !!dcbx_version;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400358
359 qed_dcbx_dp_protocol(p_hwfn, &data);
360
361 memcpy(&p_hwfn->p_dcbx_info->results, &data,
362 sizeof(struct qed_dcbx_results));
363
364 return 0;
365}
366
367static int
368qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
369 struct qed_ptt *p_ptt,
370 struct qed_dcbx_mib_meta_data *p_data,
371 enum qed_mib_read_type type)
372{
373 u32 prefix_seq_num, suffix_seq_num;
374 int read_count = 0;
375 int rc = 0;
376
377 /* The data is considered to be valid only if both sequence numbers are
378 * the same.
379 */
380 do {
381 if (type == QED_DCBX_REMOTE_LLDP_MIB) {
382 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
383 p_data->addr, p_data->size);
384 prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
385 suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
386 } else {
387 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
388 p_data->addr, p_data->size);
389 prefix_seq_num = p_data->mib->prefix_seq_num;
390 suffix_seq_num = p_data->mib->suffix_seq_num;
391 }
392 read_count++;
393
394 DP_VERBOSE(p_hwfn,
395 QED_MSG_DCB,
396 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
397 type, read_count, prefix_seq_num, suffix_seq_num);
398 } while ((prefix_seq_num != suffix_seq_num) &&
399 (read_count < QED_DCBX_MAX_MIB_READ_TRY));
400
401 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
402 DP_ERR(p_hwfn,
403 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
404 type, read_count, prefix_seq_num, suffix_seq_num);
405 rc = -EIO;
406 }
407
408 return rc;
409}
410
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400411#ifdef CONFIG_DCB
412static void
413qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
414 struct qed_dcbx_app_prio *p_prio,
415 struct qed_dcbx_results *p_results)
416{
417 u8 val;
418
419 p_prio->roce = QED_DCBX_INVALID_PRIORITY;
420 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
421 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
422 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
423
424 if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
425 p_results->arr[DCBX_PROTOCOL_ROCE].enable)
426 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
427
428 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
429 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
430 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
431 p_prio->roce_v2 = val;
432 }
433
434 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
435 p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
436 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
437
438 if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
439 p_results->arr[DCBX_PROTOCOL_FCOE].enable)
440 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
441
442 if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
443 p_results->arr[DCBX_PROTOCOL_ETH].enable)
444 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
445
446 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
447 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
448 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
449 p_prio->eth);
450}
451
452static void
453qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
454 struct dcbx_app_priority_feature *p_app,
455 struct dcbx_app_priority_entry *p_tbl,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400456 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400457{
458 struct qed_app_entry *entry;
459 u8 pri_map;
460 int i;
461
462 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
463 DCBX_APP_WILLING);
464 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
465 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
466 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
467 DCBX_APP_NUM_ENTRIES);
468 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
469 entry = &p_params->app_entry[i];
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -0400470 if (ieee) {
471 u8 sf_ieee;
472 u32 val;
473
474 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
475 DCBX_APP_SF_IEEE);
476 switch (sf_ieee) {
477 case DCBX_APP_SF_IEEE_RESERVED:
478 /* Old MFW */
479 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
480 DCBX_APP_SF);
481 entry->sf_ieee = val ?
482 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
483 QED_DCBX_SF_IEEE_ETHTYPE;
484 break;
485 case DCBX_APP_SF_IEEE_ETHTYPE:
486 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
487 break;
488 case DCBX_APP_SF_IEEE_TCP_PORT:
489 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
490 break;
491 case DCBX_APP_SF_IEEE_UDP_PORT:
492 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
493 break;
494 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
495 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
496 break;
497 }
498 } else {
499 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
500 DCBX_APP_SF));
501 }
502
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400503 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
504 entry->prio = ffs(pri_map) - 1;
505 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
506 DCBX_APP_PROTOCOL_ID);
507 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
508 entry->proto_id,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400509 &entry->proto_type, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400510 }
511
512 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
513 "APP params: willing %d, valid %d error = %d\n",
514 p_params->app_willing, p_params->app_valid,
515 p_params->app_error);
516}
517
518static void
519qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
520 u32 pfc, struct qed_dcbx_params *p_params)
521{
522 u8 pfc_map;
523
524 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
525 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
526 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
527 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
528 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
529 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
530 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
531 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
532 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
533 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
534 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
535 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
536
537 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
538 "PFC params: willing %d, pfc_bitmap %d\n",
539 p_params->pfc.willing, pfc_map);
540}
541
542static void
543qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
544 struct dcbx_ets_feature *p_ets,
545 struct qed_dcbx_params *p_params)
546{
547 u32 bw_map[2], tsa_map[2], pri_map;
548 int i;
549
550 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
551 DCBX_ETS_WILLING);
552 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
553 DCBX_ETS_ENABLED);
554 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
555 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
556 DCBX_ETS_MAX_TCS);
557 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
558 "ETS params: willing %d, ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
559 p_params->ets_willing,
560 p_params->ets_cbs,
561 p_ets->pri_tc_tbl[0], p_params->max_ets_tc);
562
563 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
564 * encoded in a type u32 array of size 2.
565 */
566 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
567 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
568 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
569 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
Sudarsana Reddy Kalluruc0c45a62016-08-08 21:57:40 -0400570 pri_map = p_ets->pri_tc_tbl[0];
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400571 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
572 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
573 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
574 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
575 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
576 "elem %d bw_tbl %x tsa_tbl %x\n",
577 i, p_params->ets_tc_bw_tbl[i],
578 p_params->ets_tc_tsa_tbl[i]);
579 }
580}
581
582static void
583qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
584 struct dcbx_app_priority_feature *p_app,
585 struct dcbx_app_priority_entry *p_tbl,
586 struct dcbx_ets_feature *p_ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400587 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400588{
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400589 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400590 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
591 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
592}
593
594static void
595qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn,
596 struct qed_ptt *p_ptt, struct qed_dcbx_get *params)
597{
598 struct dcbx_features *p_feat;
599
600 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
601 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
602 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400603 p_feat->pfc, &params->local.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400604 params->local.valid = true;
605}
606
607static void
608qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn,
609 struct qed_ptt *p_ptt, struct qed_dcbx_get *params)
610{
611 struct dcbx_features *p_feat;
612
613 p_feat = &p_hwfn->p_dcbx_info->remote.features;
614 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
615 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400616 p_feat->pfc, &params->remote.params, false);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400617 params->remote.valid = true;
618}
619
620static void
621qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
622 struct qed_ptt *p_ptt,
623 struct qed_dcbx_get *params)
624{
625 struct qed_dcbx_operational_params *p_operational;
626 struct qed_dcbx_results *p_results;
627 struct dcbx_features *p_feat;
628 bool enabled, err;
629 u32 flags;
630 bool val;
631
632 flags = p_hwfn->p_dcbx_info->operational.flags;
633
634 /* If DCBx version is non zero, then negotiation
635 * was successfuly performed
636 */
637 p_operational = &params->operational;
638 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
639 DCBX_CONFIG_VERSION_DISABLED);
640 if (!enabled) {
641 p_operational->enabled = enabled;
642 p_operational->valid = false;
643 return;
644 }
645
646 p_feat = &p_hwfn->p_dcbx_info->operational.features;
647 p_results = &p_hwfn->p_dcbx_info->results;
648
649 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
650 DCBX_CONFIG_VERSION_IEEE);
651 p_operational->ieee = val;
652 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
653 DCBX_CONFIG_VERSION_CEE);
654 p_operational->cee = val;
655
656 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Version support: ieee %d, cee %d\n",
657 p_operational->ieee, p_operational->cee);
658
659 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
660 p_feat->app.app_pri_tbl, &p_feat->ets,
Sudarsana Reddy Kallurufb9ea8a2016-08-08 21:57:41 -0400661 p_feat->pfc, &params->operational.params,
662 p_operational->ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400663 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
664 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
665 p_operational->err = err;
666 p_operational->enabled = enabled;
667 p_operational->valid = true;
668}
669
670static void
671qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
672 struct qed_ptt *p_ptt,
673 struct qed_dcbx_get *params)
674{
675 struct lldp_config_params_s *p_local;
676
677 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
678
679 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
680 ARRAY_SIZE(p_local->local_chassis_id));
681 memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
682 ARRAY_SIZE(p_local->local_port_id));
683}
684
685static void
686qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
687 struct qed_ptt *p_ptt,
688 struct qed_dcbx_get *params)
689{
690 struct lldp_status_params_s *p_remote;
691
692 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
693
694 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
695 ARRAY_SIZE(p_remote->peer_chassis_id));
696 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
697 ARRAY_SIZE(p_remote->peer_port_id));
698}
699
700static int
701qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
702 struct qed_dcbx_get *p_params,
703 enum qed_mib_read_type type)
704{
705 switch (type) {
706 case QED_DCBX_REMOTE_MIB:
707 qed_dcbx_get_remote_params(p_hwfn, p_ptt, p_params);
708 break;
709 case QED_DCBX_LOCAL_MIB:
710 qed_dcbx_get_local_params(p_hwfn, p_ptt, p_params);
711 break;
712 case QED_DCBX_OPERATIONAL_MIB:
713 qed_dcbx_get_operational_params(p_hwfn, p_ptt, p_params);
714 break;
715 case QED_DCBX_REMOTE_LLDP_MIB:
716 qed_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params);
717 break;
718 case QED_DCBX_LOCAL_LLDP_MIB:
719 qed_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params);
720 break;
721 default:
722 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
723 return -EINVAL;
724 }
725
726 return 0;
727}
728#endif
729
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400730static int
731qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
732{
733 struct qed_dcbx_mib_meta_data data;
734 int rc = 0;
735
736 memset(&data, 0, sizeof(data));
737 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
738 lldp_config_params);
739 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
740 data.size = sizeof(struct lldp_config_params_s);
741 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
742
743 return rc;
744}
745
746static int
747qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
748 struct qed_ptt *p_ptt,
749 enum qed_mib_read_type type)
750{
751 struct qed_dcbx_mib_meta_data data;
752 int rc = 0;
753
754 memset(&data, 0, sizeof(data));
755 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
756 lldp_status_params);
757 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
758 data.size = sizeof(struct lldp_status_params_s);
759 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
760
761 return rc;
762}
763
764static int
765qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
766 struct qed_ptt *p_ptt,
767 enum qed_mib_read_type type)
768{
769 struct qed_dcbx_mib_meta_data data;
770 int rc = 0;
771
772 memset(&data, 0, sizeof(data));
773 data.addr = p_hwfn->mcp_info->port_addr +
774 offsetof(struct public_port, operational_dcbx_mib);
775 data.mib = &p_hwfn->p_dcbx_info->operational;
776 data.size = sizeof(struct dcbx_mib);
777 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
778
779 return rc;
780}
781
782static int
783qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
784 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
785{
786 struct qed_dcbx_mib_meta_data data;
787 int rc = 0;
788
789 memset(&data, 0, sizeof(data));
790 data.addr = p_hwfn->mcp_info->port_addr +
791 offsetof(struct public_port, remote_dcbx_mib);
792 data.mib = &p_hwfn->p_dcbx_info->remote;
793 data.size = sizeof(struct dcbx_mib);
794 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
795
796 return rc;
797}
798
799static int
800qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
801{
802 struct qed_dcbx_mib_meta_data data;
803 int rc = 0;
804
805 memset(&data, 0, sizeof(data));
806 data.addr = p_hwfn->mcp_info->port_addr +
807 offsetof(struct public_port, local_admin_dcbx_mib);
808 data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
809 data.size = sizeof(struct dcbx_local_params);
810 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
811
812 return rc;
813}
814
815static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
816 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
817{
818 int rc = -EINVAL;
819
820 switch (type) {
821 case QED_DCBX_OPERATIONAL_MIB:
822 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
823 break;
824 case QED_DCBX_REMOTE_MIB:
825 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
826 break;
827 case QED_DCBX_LOCAL_MIB:
828 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
829 break;
830 case QED_DCBX_REMOTE_LLDP_MIB:
831 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
832 break;
833 case QED_DCBX_LOCAL_LLDP_MIB:
834 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
835 break;
836 default:
837 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
838 }
839
840 return rc;
841}
842
843/* Read updated MIB.
844 * Reconfigure QM and invoke PF update ramrod command if operational MIB
845 * change is detected.
846 */
847int
848qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
849 struct qed_ptt *p_ptt, enum qed_mib_read_type type)
850{
851 int rc = 0;
852
853 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
854 if (rc)
855 return rc;
856
857 if (type == QED_DCBX_OPERATIONAL_MIB) {
858 rc = qed_dcbx_process_mib_info(p_hwfn);
859 if (!rc) {
860 /* reconfigure tcs of QM queues according
861 * to negotiation results
862 */
863 qed_qm_reconf(p_hwfn, p_ptt);
864
865 /* update storm FW with negotiation results */
866 qed_sp_pf_update(p_hwfn);
867 }
868 }
869
870 return rc;
871}
872
873int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
874{
875 int rc = 0;
876
877 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
878 if (!p_hwfn->p_dcbx_info) {
879 DP_NOTICE(p_hwfn,
880 "Failed to allocate 'struct qed_dcbx_info'\n");
881 rc = -ENOMEM;
882 }
883
884 return rc;
885}
886
887void qed_dcbx_info_free(struct qed_hwfn *p_hwfn,
888 struct qed_dcbx_info *p_dcbx_info)
889{
890 kfree(p_hwfn->p_dcbx_info);
891}
892
893static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
894 struct qed_dcbx_results *p_src,
895 enum dcbx_protocol_type type)
896{
897 p_data->dcb_enable_flag = p_src->arr[type].enable;
898 p_data->dcb_priority = p_src->arr[type].priority;
899 p_data->dcb_tc = p_src->arr[type].tc;
900}
901
902/* Set pf update ramrod command params */
903void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
904 struct pf_update_ramrod_data *p_dest)
905{
906 struct protocol_dcb_data *p_dcb_data;
907 bool update_flag = false;
908
909 p_dest->pf_id = p_src->pf_id;
910
911 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
912 p_dest->update_fcoe_dcb_data_flag = update_flag;
913
914 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
915 p_dest->update_roce_dcb_data_flag = update_flag;
916 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
917 p_dest->update_roce_dcb_data_flag = update_flag;
918
919 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
920 p_dest->update_iscsi_dcb_data_flag = update_flag;
921 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
922 p_dest->update_eth_dcb_data_flag = update_flag;
923
924 p_dcb_data = &p_dest->fcoe_dcb_data;
925 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
926 p_dcb_data = &p_dest->roce_dcb_data;
927
928 if (p_src->arr[DCBX_PROTOCOL_ROCE].update)
929 qed_dcbx_update_protocol_data(p_dcb_data, p_src,
930 DCBX_PROTOCOL_ROCE);
931 if (p_src->arr[DCBX_PROTOCOL_ROCE_V2].update)
932 qed_dcbx_update_protocol_data(p_dcb_data, p_src,
933 DCBX_PROTOCOL_ROCE_V2);
934
935 p_dcb_data = &p_dest->iscsi_dcb_data;
936 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
937 p_dcb_data = &p_dest->eth_dcb_data;
938 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
939}
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400940
941#ifdef CONFIG_DCB
942static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
943 struct qed_dcbx_get *p_get,
944 enum qed_mib_read_type type)
945{
946 struct qed_ptt *p_ptt;
947 int rc;
948
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400949 if (IS_VF(p_hwfn->cdev))
950 return -EINVAL;
951
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400952 p_ptt = qed_ptt_acquire(p_hwfn);
953 if (!p_ptt)
954 return -EBUSY;
955
956 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
957 if (rc)
958 goto out;
959
960 rc = qed_dcbx_get_params(p_hwfn, p_ptt, p_get, type);
961
962out:
963 qed_ptt_release(p_hwfn, p_ptt);
964 return rc;
965}
966
967static void
968qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
969 u32 *pfc, struct qed_dcbx_params *p_params)
970{
971 u8 pfc_map = 0;
972 int i;
973
974 if (p_params->pfc.willing)
975 *pfc |= DCBX_PFC_WILLING_MASK;
976 else
977 *pfc &= ~DCBX_PFC_WILLING_MASK;
978
979 if (p_params->pfc.enabled)
980 *pfc |= DCBX_PFC_ENABLED_MASK;
981 else
982 *pfc &= ~DCBX_PFC_ENABLED_MASK;
983
984 *pfc &= ~DCBX_PFC_CAPS_MASK;
985 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
986
987 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
988 if (p_params->pfc.prio[i])
989 pfc_map |= BIT(i);
990
991 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
992
993 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
994}
995
996static void
997qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
998 struct dcbx_ets_feature *p_ets,
999 struct qed_dcbx_params *p_params)
1000{
1001 u8 *bw_map, *tsa_map;
1002 u32 val;
1003 int i;
1004
1005 if (p_params->ets_willing)
1006 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1007 else
1008 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1009
1010 if (p_params->ets_cbs)
1011 p_ets->flags |= DCBX_ETS_CBS_MASK;
1012 else
1013 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1014
1015 if (p_params->ets_enabled)
1016 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1017 else
1018 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1019
1020 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1021 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1022
1023 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1024 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1025 p_ets->pri_tc_tbl[0] = 0;
1026 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1027 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1028 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1029 /* Copy the priority value to the corresponding 4 bits in the
1030 * traffic class table.
1031 */
1032 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1033 p_ets->pri_tc_tbl[0] |= val;
1034 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001035 for (i = 0; i < 2; i++) {
1036 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1037 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1038 }
1039}
1040
1041static void
1042qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1043 struct dcbx_app_priority_feature *p_app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001044 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001045{
1046 u32 *entry;
1047 int i;
1048
1049 if (p_params->app_willing)
1050 p_app->flags |= DCBX_APP_WILLING_MASK;
1051 else
1052 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1053
1054 if (p_params->app_valid)
1055 p_app->flags |= DCBX_APP_ENABLED_MASK;
1056 else
1057 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1058
1059 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1060 p_app->flags |= (u32)p_params->num_app_entries <<
1061 DCBX_APP_NUM_ENTRIES_SHIFT;
1062
1063 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1064 entry = &p_app->app_pri_tbl[i].entry;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001065 if (ieee) {
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001066 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001067 switch (p_params->app_entry[i].sf_ieee) {
1068 case QED_DCBX_SF_IEEE_ETHTYPE:
1069 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1070 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001071 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1072 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001073 break;
1074 case QED_DCBX_SF_IEEE_TCP_PORT:
1075 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1076 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001077 *entry |= ((u32)DCBX_APP_SF_PORT <<
1078 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001079 break;
1080 case QED_DCBX_SF_IEEE_UDP_PORT:
1081 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1082 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001083 *entry |= ((u32)DCBX_APP_SF_PORT <<
1084 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001085 break;
1086 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1087 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1088 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001089 *entry |= ((u32)DCBX_APP_SF_PORT <<
1090 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001091 break;
1092 }
1093 } else {
1094 *entry &= ~DCBX_APP_SF_MASK;
1095 if (p_params->app_entry[i].ethtype)
1096 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1097 DCBX_APP_SF_SHIFT);
1098 else
1099 *entry |= ((u32)DCBX_APP_SF_PORT <<
1100 DCBX_APP_SF_SHIFT);
1101 }
1102
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001103 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1104 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1105 DCBX_APP_PROTOCOL_ID_SHIFT);
1106 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1107 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1108 DCBX_APP_PRI_MAP_SHIFT);
1109 }
1110}
1111
1112static void
1113qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1114 struct dcbx_local_params *local_admin,
1115 struct qed_dcbx_set *params)
1116{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001117 bool ieee = false;
1118
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001119 local_admin->flags = 0;
1120 memcpy(&local_admin->features,
1121 &p_hwfn->p_dcbx_info->operational.features,
1122 sizeof(local_admin->features));
1123
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001124 if (params->enabled) {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001125 local_admin->config = params->ver_num;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001126 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1127 } else {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001128 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001129 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001130
1131 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1132 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1133 &params->config.params);
1134
1135 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1136 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1137 &params->config.params);
1138
1139 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1140 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001141 &params->config.params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001142}
1143
1144int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1145 struct qed_dcbx_set *params, bool hw_commit)
1146{
1147 struct dcbx_local_params local_admin;
1148 struct qed_dcbx_mib_meta_data data;
1149 u32 resp = 0, param = 0;
1150 int rc = 0;
1151
1152 if (!hw_commit) {
1153 memcpy(&p_hwfn->p_dcbx_info->set, params,
1154 sizeof(struct qed_dcbx_set));
1155 return 0;
1156 }
1157
1158 /* clear set-parmas cache */
1159 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1160
1161 memset(&local_admin, 0, sizeof(local_admin));
1162 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1163
1164 data.addr = p_hwfn->mcp_info->port_addr +
1165 offsetof(struct public_port, local_admin_dcbx_mib);
1166 data.local_admin = &local_admin;
1167 data.size = sizeof(struct dcbx_local_params);
1168 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1169
1170 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1171 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
1172 if (rc)
1173 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1174
1175 return rc;
1176}
1177
1178int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1179 struct qed_dcbx_set *params)
1180{
1181 struct qed_dcbx_get *dcbx_info;
1182 int rc;
1183
1184 if (p_hwfn->p_dcbx_info->set.config.valid) {
1185 memcpy(params, &p_hwfn->p_dcbx_info->set,
1186 sizeof(struct qed_dcbx_set));
1187 return 0;
1188 }
1189
1190 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
1191 if (!dcbx_info) {
1192 DP_ERR(p_hwfn, "Failed to allocate struct qed_dcbx_info\n");
1193 return -ENOMEM;
1194 }
1195
1196 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1197 if (rc) {
1198 kfree(dcbx_info);
1199 return rc;
1200 }
1201
1202 p_hwfn->p_dcbx_info->set.override_flags = 0;
1203 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1204 if (dcbx_info->operational.cee)
1205 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1206 if (dcbx_info->operational.ieee)
1207 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1208
1209 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1210 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1211 &dcbx_info->operational.params,
1212 sizeof(struct qed_dcbx_admin_params));
1213 p_hwfn->p_dcbx_info->set.config.valid = true;
1214
1215 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1216
1217 kfree(dcbx_info);
1218
1219 return 0;
1220}
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001221
1222static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1223 enum qed_mib_read_type type)
1224{
1225 struct qed_dcbx_get *dcbx_info;
1226
1227 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
1228 if (!dcbx_info) {
1229 DP_ERR(hwfn->cdev, "Failed to allocate memory for dcbx_info\n");
1230 return NULL;
1231 }
1232
1233 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1234 kfree(dcbx_info);
1235 return NULL;
1236 }
1237
1238 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1239 !dcbx_info->operational.enabled) {
1240 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1241 kfree(dcbx_info);
1242 return NULL;
1243 }
1244
1245 return dcbx_info;
1246}
1247
1248static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1249{
1250 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1251 struct qed_dcbx_get *dcbx_info;
1252 bool enabled;
1253
1254 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1255 if (!dcbx_info)
1256 return 0;
1257
1258 enabled = dcbx_info->operational.enabled;
1259 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1260 kfree(dcbx_info);
1261
1262 return enabled;
1263}
1264
1265static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1266{
1267 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1268 struct qed_dcbx_set dcbx_set;
1269 struct qed_ptt *ptt;
1270 int rc;
1271
1272 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1273
1274 memset(&dcbx_set, 0, sizeof(dcbx_set));
1275 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1276 if (rc)
1277 return 1;
1278
1279 dcbx_set.enabled = !!state;
1280
1281 ptt = qed_ptt_acquire(hwfn);
1282 if (!ptt)
1283 return 1;
1284
1285 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1286
1287 qed_ptt_release(hwfn, ptt);
1288
1289 return rc ? 1 : 0;
1290}
1291
1292static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1293 u8 *pgid, u8 *bw_pct, u8 *up_map)
1294{
1295 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1296 struct qed_dcbx_get *dcbx_info;
1297
1298 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1299 *prio_type = *pgid = *bw_pct = *up_map = 0;
1300 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1301 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1302 return;
1303 }
1304
1305 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1306 if (!dcbx_info)
1307 return;
1308
1309 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1310 kfree(dcbx_info);
1311}
1312
1313static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1314{
1315 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1316 struct qed_dcbx_get *dcbx_info;
1317
1318 *bw_pct = 0;
1319 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1320 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1321 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1322 return;
1323 }
1324
1325 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1326 if (!dcbx_info)
1327 return;
1328
1329 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1330 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1331 kfree(dcbx_info);
1332}
1333
1334static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1335 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1336{
1337 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1338 *prio = *bwg_id = *bw_pct = *up_map = 0;
1339}
1340
1341static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1342 int bwg_id, u8 *bw_pct)
1343{
1344 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1345 *bw_pct = 0;
1346}
1347
1348static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1349 int priority, u8 *setting)
1350{
1351 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1352 struct qed_dcbx_get *dcbx_info;
1353
1354 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1355 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1356 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1357 return;
1358 }
1359
1360 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1361 if (!dcbx_info)
1362 return;
1363
1364 *setting = dcbx_info->operational.params.pfc.prio[priority];
1365 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1366 kfree(dcbx_info);
1367}
1368
1369static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1370{
1371 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1372 struct qed_dcbx_set dcbx_set;
1373 struct qed_ptt *ptt;
1374 int rc;
1375
1376 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1377 priority, setting);
1378 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1379 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1380 return;
1381 }
1382
1383 memset(&dcbx_set, 0, sizeof(dcbx_set));
1384 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1385 if (rc)
1386 return;
1387
1388 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1389 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1390
1391 ptt = qed_ptt_acquire(hwfn);
1392 if (!ptt)
1393 return;
1394
1395 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1396
1397 qed_ptt_release(hwfn, ptt);
1398}
1399
1400static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1401{
1402 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1403 struct qed_dcbx_get *dcbx_info;
1404 int rc = 0;
1405
1406 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1407 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1408 if (!dcbx_info)
1409 return 1;
1410
1411 switch (capid) {
1412 case DCB_CAP_ATTR_PG:
1413 case DCB_CAP_ATTR_PFC:
1414 case DCB_CAP_ATTR_UP2TC:
1415 case DCB_CAP_ATTR_GSP:
1416 *cap = true;
1417 break;
1418 case DCB_CAP_ATTR_PG_TCS:
1419 case DCB_CAP_ATTR_PFC_TCS:
1420 *cap = 0x80;
1421 break;
1422 case DCB_CAP_ATTR_DCBX:
1423 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
1424 DCB_CAP_DCBX_VER_IEEE);
1425 break;
1426 default:
1427 *cap = false;
1428 rc = 1;
1429 }
1430
1431 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1432 kfree(dcbx_info);
1433
1434 return rc;
1435}
1436
1437static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1438{
1439 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1440 struct qed_dcbx_get *dcbx_info;
1441 int rc = 0;
1442
1443 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1444 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1445 if (!dcbx_info)
1446 return -EINVAL;
1447
1448 switch (tcid) {
1449 case DCB_NUMTCS_ATTR_PG:
1450 *num = dcbx_info->operational.params.max_ets_tc;
1451 break;
1452 case DCB_NUMTCS_ATTR_PFC:
1453 *num = dcbx_info->operational.params.pfc.max_tc;
1454 break;
1455 default:
1456 rc = -EINVAL;
1457 }
1458
1459 kfree(dcbx_info);
1460 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1461
1462 return rc;
1463}
1464
1465static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1466{
1467 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1468 struct qed_dcbx_get *dcbx_info;
1469 bool enabled;
1470
1471 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1472 if (!dcbx_info)
1473 return 0;
1474
1475 enabled = dcbx_info->operational.params.pfc.enabled;
1476 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1477 kfree(dcbx_info);
1478
1479 return enabled;
1480}
1481
1482static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1483{
1484 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1485 struct qed_dcbx_get *dcbx_info;
1486 u8 mode = 0;
1487
1488 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1489 if (!dcbx_info)
1490 return 0;
1491
1492 if (dcbx_info->operational.enabled)
1493 mode |= DCB_CAP_DCBX_LLD_MANAGED;
1494 if (dcbx_info->operational.ieee)
1495 mode |= DCB_CAP_DCBX_VER_IEEE;
1496 if (dcbx_info->operational.cee)
1497 mode |= DCB_CAP_DCBX_VER_CEE;
1498
1499 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1500 kfree(dcbx_info);
1501
1502 return mode;
1503}
1504
1505static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1506 int tc,
1507 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1508{
1509 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1510 struct qed_dcbx_set dcbx_set;
1511 struct qed_ptt *ptt;
1512 int rc;
1513
1514 DP_VERBOSE(hwfn, QED_MSG_DCB,
1515 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1516 tc, pri_type, pgid, bw_pct, up_map);
1517
1518 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1519 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1520 return;
1521 }
1522
1523 memset(&dcbx_set, 0, sizeof(dcbx_set));
1524 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1525 if (rc)
1526 return;
1527
1528 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1529 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1530
1531 ptt = qed_ptt_acquire(hwfn);
1532 if (!ptt)
1533 return;
1534
1535 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1536
1537 qed_ptt_release(hwfn, ptt);
1538}
1539
1540static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1541 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1542{
1543 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1544}
1545
1546static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
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, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1554 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1555 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1556 return;
1557 }
1558
1559 memset(&dcbx_set, 0, sizeof(dcbx_set));
1560 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1561 if (rc)
1562 return;
1563
1564 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1565 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1566
1567 ptt = qed_ptt_acquire(hwfn);
1568 if (!ptt)
1569 return;
1570
1571 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1572
1573 qed_ptt_release(hwfn, ptt);
1574}
1575
1576static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1577{
1578 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1579}
1580
1581static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1582{
1583 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1584 struct qed_dcbx_set dcbx_set;
1585 struct qed_ptt *ptt;
1586 int rc;
1587
1588 memset(&dcbx_set, 0, sizeof(dcbx_set));
1589 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1590 if (rc)
1591 return 1;
1592
1593 ptt = qed_ptt_acquire(hwfn);
1594 if (!ptt)
1595 return 1;
1596
1597 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1598
1599 qed_ptt_release(hwfn, ptt);
1600
1601 return rc;
1602}
1603
1604static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1605{
1606 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1607 struct qed_dcbx_set dcbx_set;
1608 struct qed_ptt *ptt;
1609 int rc;
1610
1611 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
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 switch (tcid) {
1618 case DCB_NUMTCS_ATTR_PG:
1619 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1620 dcbx_set.config.params.max_ets_tc = num;
1621 break;
1622 case DCB_NUMTCS_ATTR_PFC:
1623 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1624 dcbx_set.config.params.pfc.max_tc = num;
1625 break;
1626 default:
1627 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1628 return -EINVAL;
1629 }
1630
1631 ptt = qed_ptt_acquire(hwfn);
1632 if (!ptt)
1633 return -EINVAL;
1634
1635 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1636
1637 qed_ptt_release(hwfn, ptt);
1638
1639 return 0;
1640}
1641
1642static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1643{
1644 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1645 struct qed_dcbx_set dcbx_set;
1646 struct qed_ptt *ptt;
1647 int rc;
1648
1649 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1650
1651 memset(&dcbx_set, 0, sizeof(dcbx_set));
1652 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1653 if (rc)
1654 return;
1655
1656 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1657 dcbx_set.config.params.pfc.enabled = !!state;
1658
1659 ptt = qed_ptt_acquire(hwfn);
1660 if (!ptt)
1661 return;
1662
1663 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1664
1665 qed_ptt_release(hwfn, ptt);
1666}
1667
1668static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1669{
1670 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1671 struct qed_dcbx_get *dcbx_info;
1672 struct qed_app_entry *entry;
1673 bool ethtype;
1674 u8 prio = 0;
1675 int i;
1676
1677 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1678 if (!dcbx_info)
1679 return -EINVAL;
1680
1681 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1682 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1683 entry = &dcbx_info->operational.params.app_entry[i];
1684 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1685 prio = entry->prio;
1686 break;
1687 }
1688 }
1689
1690 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1691 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1692 kfree(dcbx_info);
1693 return -EINVAL;
1694 }
1695
1696 kfree(dcbx_info);
1697
1698 return prio;
1699}
1700
1701static int qed_dcbnl_setapp(struct qed_dev *cdev,
1702 u8 idtype, u16 idval, u8 pri_map)
1703{
1704 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1705 struct qed_dcbx_set dcbx_set;
1706 struct qed_app_entry *entry;
1707 struct qed_ptt *ptt;
1708 bool ethtype;
1709 int rc, i;
1710
1711 memset(&dcbx_set, 0, sizeof(dcbx_set));
1712 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1713 if (rc)
1714 return -EINVAL;
1715
1716 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1717 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1718 entry = &dcbx_set.config.params.app_entry[i];
1719 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1720 break;
1721 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001722 if (!entry->proto_id) {
1723 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001724 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001725 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001726 }
1727
1728 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1729 DP_ERR(cdev, "App table is full\n");
1730 return -EBUSY;
1731 }
1732
1733 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1734 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1735 dcbx_set.config.params.app_entry[i].proto_id = idval;
1736 dcbx_set.config.params.app_entry[i].prio = pri_map;
1737
1738 ptt = qed_ptt_acquire(hwfn);
1739 if (!ptt)
1740 return -EBUSY;
1741
1742 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1743
1744 qed_ptt_release(hwfn, ptt);
1745
1746 return rc;
1747}
1748
1749static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1750{
1751 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1752 struct qed_dcbx_set dcbx_set;
1753 struct qed_ptt *ptt;
1754 int rc;
1755
1756 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1757
1758 if (!(mode & DCB_CAP_DCBX_VER_IEEE) && !(mode & DCB_CAP_DCBX_VER_CEE)) {
1759 DP_INFO(hwfn, "Allowed mode is cee, ieee or both\n");
1760 return 1;
1761 }
1762
1763 memset(&dcbx_set, 0, sizeof(dcbx_set));
1764 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1765 if (rc)
1766 return 1;
1767
1768 dcbx_set.ver_num = 0;
1769 if (mode & DCB_CAP_DCBX_VER_CEE) {
1770 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1771 dcbx_set.enabled = true;
1772 }
1773
1774 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1775 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1776 dcbx_set.enabled = true;
1777 }
1778
1779 ptt = qed_ptt_acquire(hwfn);
1780 if (!ptt)
1781 return 1;
1782
1783 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1784
1785 qed_ptt_release(hwfn, ptt);
1786
1787 return 0;
1788}
1789
1790static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1791{
1792 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1793 struct qed_dcbx_get *dcbx_info;
1794
1795 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1796 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1797 if (!dcbx_info)
1798 return 1;
1799
1800 *flags = 0;
1801 switch (featid) {
1802 case DCB_FEATCFG_ATTR_PG:
1803 if (dcbx_info->operational.params.ets_enabled)
1804 *flags = DCB_FEATCFG_ENABLE;
1805 else
1806 *flags = DCB_FEATCFG_ERROR;
1807 break;
1808 case DCB_FEATCFG_ATTR_PFC:
1809 if (dcbx_info->operational.params.pfc.enabled)
1810 *flags = DCB_FEATCFG_ENABLE;
1811 else
1812 *flags = DCB_FEATCFG_ERROR;
1813 break;
1814 case DCB_FEATCFG_ATTR_APP:
1815 if (dcbx_info->operational.params.app_valid)
1816 *flags = DCB_FEATCFG_ENABLE;
1817 else
1818 *flags = DCB_FEATCFG_ERROR;
1819 break;
1820 default:
1821 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1822 kfree(dcbx_info);
1823 return 1;
1824 }
1825
1826 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1827 kfree(dcbx_info);
1828
1829 return 0;
1830}
1831
1832static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1833{
1834 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1835 struct qed_dcbx_set dcbx_set;
1836 bool enabled, willing;
1837 struct qed_ptt *ptt;
1838 int rc;
1839
1840 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1841 featid, flags);
1842 memset(&dcbx_set, 0, sizeof(dcbx_set));
1843 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1844 if (rc)
1845 return 1;
1846
1847 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1848 willing = !!(flags & DCB_FEATCFG_WILLING);
1849 switch (featid) {
1850 case DCB_FEATCFG_ATTR_PG:
1851 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1852 dcbx_set.config.params.ets_enabled = enabled;
1853 dcbx_set.config.params.ets_willing = willing;
1854 break;
1855 case DCB_FEATCFG_ATTR_PFC:
1856 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1857 dcbx_set.config.params.pfc.enabled = enabled;
1858 dcbx_set.config.params.pfc.willing = willing;
1859 break;
1860 case DCB_FEATCFG_ATTR_APP:
1861 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1862 dcbx_set.config.params.app_willing = willing;
1863 break;
1864 default:
1865 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1866 return 1;
1867 }
1868
1869 ptt = qed_ptt_acquire(hwfn);
1870 if (!ptt)
1871 return 1;
1872
1873 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1874
1875 qed_ptt_release(hwfn, ptt);
1876
1877 return 0;
1878}
1879
1880static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1881 struct dcb_peer_app_info *info,
1882 u16 *app_count)
1883{
1884 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1885 struct qed_dcbx_get *dcbx_info;
1886
1887 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1888 if (!dcbx_info)
1889 return -EINVAL;
1890
1891 info->willing = dcbx_info->remote.params.app_willing;
1892 info->error = dcbx_info->remote.params.app_error;
1893 *app_count = dcbx_info->remote.params.num_app_entries;
1894 kfree(dcbx_info);
1895
1896 return 0;
1897}
1898
1899static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1900 struct dcb_app *table)
1901{
1902 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1903 struct qed_dcbx_get *dcbx_info;
1904 int i;
1905
1906 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1907 if (!dcbx_info)
1908 return -EINVAL;
1909
1910 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1911 if (dcbx_info->remote.params.app_entry[i].ethtype)
1912 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1913 else
1914 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1915 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1916 table[i].protocol =
1917 dcbx_info->remote.params.app_entry[i].proto_id;
1918 }
1919
1920 kfree(dcbx_info);
1921
1922 return 0;
1923}
1924
1925static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1926{
1927 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1928 struct qed_dcbx_get *dcbx_info;
1929 int i;
1930
1931 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1932 if (!dcbx_info)
1933 return -EINVAL;
1934
1935 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1936 if (dcbx_info->remote.params.pfc.prio[i])
1937 pfc->pfc_en |= BIT(i);
1938
1939 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1940 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
1941 pfc->pfc_en, pfc->tcs_supported);
1942 kfree(dcbx_info);
1943
1944 return 0;
1945}
1946
1947static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
1948{
1949 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1950 struct qed_dcbx_get *dcbx_info;
1951 int i;
1952
1953 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1954 if (!dcbx_info)
1955 return -EINVAL;
1956
1957 pg->willing = dcbx_info->remote.params.ets_willing;
1958 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1959 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
1960 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
1961 }
1962
1963 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
1964 kfree(dcbx_info);
1965
1966 return 0;
1967}
1968
1969static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
1970 struct ieee_pfc *pfc, bool remote)
1971{
1972 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1973 struct qed_dcbx_params *params;
1974 struct qed_dcbx_get *dcbx_info;
1975 int rc, i;
1976
1977 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1978 if (!dcbx_info)
1979 return -EINVAL;
1980
1981 if (!dcbx_info->operational.ieee) {
1982 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
1983 return -EINVAL;
1984 }
1985
1986 if (remote) {
1987 memset(dcbx_info, 0, sizeof(*dcbx_info));
1988 rc = qed_dcbx_query_params(hwfn, dcbx_info,
1989 QED_DCBX_REMOTE_MIB);
1990 if (rc) {
1991 kfree(dcbx_info);
1992 return -EINVAL;
1993 }
1994
1995 params = &dcbx_info->remote.params;
1996 } else {
1997 params = &dcbx_info->operational.params;
1998 }
1999
2000 pfc->pfc_cap = params->pfc.max_tc;
2001 pfc->pfc_en = 0;
2002 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2003 if (params->pfc.prio[i])
2004 pfc->pfc_en |= BIT(i);
2005
2006 kfree(dcbx_info);
2007
2008 return 0;
2009}
2010
2011static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2012{
2013 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2014}
2015
2016static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2017{
2018 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2019 struct qed_dcbx_get *dcbx_info;
2020 struct qed_dcbx_set dcbx_set;
2021 struct qed_ptt *ptt;
2022 int rc, i;
2023
2024 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2025 if (!dcbx_info)
2026 return -EINVAL;
2027
2028 if (!dcbx_info->operational.ieee) {
2029 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2030 kfree(dcbx_info);
2031 return -EINVAL;
2032 }
2033
2034 kfree(dcbx_info);
2035
2036 memset(&dcbx_set, 0, sizeof(dcbx_set));
2037 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2038 if (rc)
2039 return -EINVAL;
2040
2041 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2042 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2043 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2044
2045 ptt = qed_ptt_acquire(hwfn);
2046 if (!ptt)
2047 return -EINVAL;
2048
2049 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2050
2051 qed_ptt_release(hwfn, ptt);
2052
2053 return rc;
2054}
2055
2056static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2057 struct ieee_ets *ets, bool remote)
2058{
2059 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2060 struct qed_dcbx_get *dcbx_info;
2061 struct qed_dcbx_params *params;
2062 int rc;
2063
2064 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2065 if (!dcbx_info)
2066 return -EINVAL;
2067
2068 if (!dcbx_info->operational.ieee) {
2069 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2070 kfree(dcbx_info);
2071 return -EINVAL;
2072 }
2073
2074 if (remote) {
2075 memset(dcbx_info, 0, sizeof(*dcbx_info));
2076 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2077 QED_DCBX_REMOTE_MIB);
2078 if (rc) {
2079 kfree(dcbx_info);
2080 return -EINVAL;
2081 }
2082
2083 params = &dcbx_info->remote.params;
2084 } else {
2085 params = &dcbx_info->operational.params;
2086 }
2087
2088 ets->ets_cap = params->max_ets_tc;
2089 ets->willing = params->ets_willing;
2090 ets->cbs = params->ets_cbs;
2091 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2092 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2093 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2094 kfree(dcbx_info);
2095
2096 return 0;
2097}
2098
2099static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2100{
2101 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2102}
2103
2104static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2105{
2106 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2107 struct qed_dcbx_get *dcbx_info;
2108 struct qed_dcbx_set dcbx_set;
2109 struct qed_ptt *ptt;
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 kfree(dcbx_info);
2123
2124 memset(&dcbx_set, 0, sizeof(dcbx_set));
2125 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2126 if (rc)
2127 return -EINVAL;
2128
2129 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2130 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2131 dcbx_set.config.params.ets_willing = ets->willing;
2132 dcbx_set.config.params.ets_cbs = ets->cbs;
2133 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2134 sizeof(ets->tc_tx_bw));
2135 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2136 sizeof(ets->tc_tsa));
2137 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2138 sizeof(ets->prio_tc));
2139
2140 ptt = qed_ptt_acquire(hwfn);
2141 if (!ptt)
2142 return -EINVAL;
2143
2144 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2145
2146 qed_ptt_release(hwfn, ptt);
2147
2148 return rc;
2149}
2150
2151int qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2152{
2153 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2154}
2155
2156int qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2157{
2158 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2159}
2160
2161int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2162{
2163 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2164 struct qed_dcbx_get *dcbx_info;
2165 struct qed_app_entry *entry;
2166 bool ethtype;
2167 u8 prio = 0;
2168 int i;
2169
2170 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2171 if (!dcbx_info)
2172 return -EINVAL;
2173
2174 if (!dcbx_info->operational.ieee) {
2175 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2176 kfree(dcbx_info);
2177 return -EINVAL;
2178 }
2179
2180 /* ieee defines the selector field value for ethertype to be 1 */
2181 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2182 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2183 entry = &dcbx_info->operational.params.app_entry[i];
2184 if ((entry->ethtype == ethtype) &&
2185 (entry->proto_id == app->protocol)) {
2186 prio = entry->prio;
2187 break;
2188 }
2189 }
2190
2191 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2192 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2193 app->protocol);
2194 kfree(dcbx_info);
2195 return -EINVAL;
2196 }
2197
2198 app->priority = ffs(prio) - 1;
2199
2200 kfree(dcbx_info);
2201
2202 return 0;
2203}
2204
2205int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2206{
2207 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2208 struct qed_dcbx_get *dcbx_info;
2209 struct qed_dcbx_set dcbx_set;
2210 struct qed_app_entry *entry;
2211 struct qed_ptt *ptt;
2212 bool ethtype;
2213 int rc, i;
2214
2215 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2216 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2217 return -EINVAL;
2218 }
2219
2220 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2221 if (!dcbx_info)
2222 return -EINVAL;
2223
2224 if (!dcbx_info->operational.ieee) {
2225 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2226 kfree(dcbx_info);
2227 return -EINVAL;
2228 }
2229
2230 kfree(dcbx_info);
2231
2232 memset(&dcbx_set, 0, sizeof(dcbx_set));
2233 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2234 if (rc)
2235 return -EINVAL;
2236
2237 /* ieee defines the selector field value for ethertype to be 1 */
2238 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2239 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2240 entry = &dcbx_set.config.params.app_entry[i];
2241 if ((entry->ethtype == ethtype) &&
2242 (entry->proto_id == app->protocol))
2243 break;
2244 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002245 if (!entry->proto_id) {
2246 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002247 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002248 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002249 }
2250
2251 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2252 DP_ERR(cdev, "App table is full\n");
2253 return -EBUSY;
2254 }
2255
2256 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2257 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
2258 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2259 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2260
2261 ptt = qed_ptt_acquire(hwfn);
2262 if (!ptt)
2263 return -EBUSY;
2264
2265 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2266
2267 qed_ptt_release(hwfn, ptt);
2268
2269 return rc;
2270}
2271
2272const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2273 .getstate = qed_dcbnl_getstate,
2274 .setstate = qed_dcbnl_setstate,
2275 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2276 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2277 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2278 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2279 .getpfccfg = qed_dcbnl_getpfccfg,
2280 .setpfccfg = qed_dcbnl_setpfccfg,
2281 .getcap = qed_dcbnl_getcap,
2282 .getnumtcs = qed_dcbnl_getnumtcs,
2283 .getpfcstate = qed_dcbnl_getpfcstate,
2284 .getdcbx = qed_dcbnl_getdcbx,
2285 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2286 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2287 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2288 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2289 .setall = qed_dcbnl_setall,
2290 .setnumtcs = qed_dcbnl_setnumtcs,
2291 .setpfcstate = qed_dcbnl_setpfcstate,
2292 .setapp = qed_dcbnl_setapp,
2293 .setdcbx = qed_dcbnl_setdcbx,
2294 .setfeatcfg = qed_dcbnl_setfeatcfg,
2295 .getfeatcfg = qed_dcbnl_getfeatcfg,
2296 .getapp = qed_dcbnl_getapp,
2297 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2298 .peer_getapptable = qed_dcbnl_peer_getapptable,
2299 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2300 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2301 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2302 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2303 .ieee_getets = qed_dcbnl_ieee_getets,
2304 .ieee_setets = qed_dcbnl_ieee_setets,
2305 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2306 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2307 .ieee_getapp = qed_dcbnl_ieee_getapp,
2308 .ieee_setapp = qed_dcbnl_ieee_setapp,
2309};
2310
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04002311#endif