blob: ad023fe7d156758b2844308068e090f5fbdd3f18 [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
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -0400991 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -0400992 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
993
994 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
995}
996
997static void
998qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
999 struct dcbx_ets_feature *p_ets,
1000 struct qed_dcbx_params *p_params)
1001{
1002 u8 *bw_map, *tsa_map;
1003 u32 val;
1004 int i;
1005
1006 if (p_params->ets_willing)
1007 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1008 else
1009 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1010
1011 if (p_params->ets_cbs)
1012 p_ets->flags |= DCBX_ETS_CBS_MASK;
1013 else
1014 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1015
1016 if (p_params->ets_enabled)
1017 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1018 else
1019 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1020
1021 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1022 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1023
1024 bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1025 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1026 p_ets->pri_tc_tbl[0] = 0;
1027 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1028 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1029 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1030 /* Copy the priority value to the corresponding 4 bits in the
1031 * traffic class table.
1032 */
1033 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1034 p_ets->pri_tc_tbl[0] |= val;
1035 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001036 for (i = 0; i < 2; i++) {
1037 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
1038 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
1039 }
1040}
1041
1042static void
1043qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
1044 struct dcbx_app_priority_feature *p_app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001045 struct qed_dcbx_params *p_params, bool ieee)
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001046{
1047 u32 *entry;
1048 int i;
1049
1050 if (p_params->app_willing)
1051 p_app->flags |= DCBX_APP_WILLING_MASK;
1052 else
1053 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1054
1055 if (p_params->app_valid)
1056 p_app->flags |= DCBX_APP_ENABLED_MASK;
1057 else
1058 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1059
1060 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1061 p_app->flags |= (u32)p_params->num_app_entries <<
1062 DCBX_APP_NUM_ENTRIES_SHIFT;
1063
1064 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1065 entry = &p_app->app_pri_tbl[i].entry;
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001066 *entry = 0;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001067 if (ieee) {
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001068 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001069 switch (p_params->app_entry[i].sf_ieee) {
1070 case QED_DCBX_SF_IEEE_ETHTYPE:
1071 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1072 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001073 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1074 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001075 break;
1076 case QED_DCBX_SF_IEEE_TCP_PORT:
1077 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1078 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001079 *entry |= ((u32)DCBX_APP_SF_PORT <<
1080 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001081 break;
1082 case QED_DCBX_SF_IEEE_UDP_PORT:
1083 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1084 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001085 *entry |= ((u32)DCBX_APP_SF_PORT <<
1086 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001087 break;
1088 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1089 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1090 DCBX_APP_SF_IEEE_SHIFT);
Sudarsana Reddy Kalluru5ec5dfa2016-08-29 08:29:53 -04001091 *entry |= ((u32)DCBX_APP_SF_PORT <<
1092 DCBX_APP_SF_SHIFT);
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001093 break;
1094 }
1095 } else {
1096 *entry &= ~DCBX_APP_SF_MASK;
1097 if (p_params->app_entry[i].ethtype)
1098 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1099 DCBX_APP_SF_SHIFT);
1100 else
1101 *entry |= ((u32)DCBX_APP_SF_PORT <<
1102 DCBX_APP_SF_SHIFT);
1103 }
1104
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001105 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1106 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1107 DCBX_APP_PROTOCOL_ID_SHIFT);
1108 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1109 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1110 DCBX_APP_PRI_MAP_SHIFT);
1111 }
1112}
1113
1114static void
1115qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1116 struct dcbx_local_params *local_admin,
1117 struct qed_dcbx_set *params)
1118{
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001119 bool ieee = false;
1120
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001121 local_admin->flags = 0;
1122 memcpy(&local_admin->features,
1123 &p_hwfn->p_dcbx_info->operational.features,
1124 sizeof(local_admin->features));
1125
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001126 if (params->enabled) {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001127 local_admin->config = params->ver_num;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001128 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1129 } else {
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001130 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001131 }
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001132
1133 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1134 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1135 &params->config.params);
1136
1137 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
1138 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1139 &params->config.params);
1140
1141 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1142 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
Sudarsana Reddy Kalluru59bcb792016-08-08 21:57:42 -04001143 &params->config.params, ieee);
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001144}
1145
1146int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1147 struct qed_dcbx_set *params, bool hw_commit)
1148{
1149 struct dcbx_local_params local_admin;
1150 struct qed_dcbx_mib_meta_data data;
1151 u32 resp = 0, param = 0;
1152 int rc = 0;
1153
1154 if (!hw_commit) {
1155 memcpy(&p_hwfn->p_dcbx_info->set, params,
1156 sizeof(struct qed_dcbx_set));
1157 return 0;
1158 }
1159
1160 /* clear set-parmas cache */
1161 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
1162
1163 memset(&local_admin, 0, sizeof(local_admin));
1164 qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
1165
1166 data.addr = p_hwfn->mcp_info->port_addr +
1167 offsetof(struct public_port, local_admin_dcbx_mib);
1168 data.local_admin = &local_admin;
1169 data.size = sizeof(struct dcbx_local_params);
1170 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1171
1172 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1173 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
1174 if (rc)
1175 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
1176
1177 return rc;
1178}
1179
1180int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1181 struct qed_dcbx_set *params)
1182{
1183 struct qed_dcbx_get *dcbx_info;
1184 int rc;
1185
1186 if (p_hwfn->p_dcbx_info->set.config.valid) {
1187 memcpy(params, &p_hwfn->p_dcbx_info->set,
1188 sizeof(struct qed_dcbx_set));
1189 return 0;
1190 }
1191
1192 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
1193 if (!dcbx_info) {
1194 DP_ERR(p_hwfn, "Failed to allocate struct qed_dcbx_info\n");
1195 return -ENOMEM;
1196 }
1197
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001198 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04001199 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1200 if (rc) {
1201 kfree(dcbx_info);
1202 return rc;
1203 }
1204
1205 p_hwfn->p_dcbx_info->set.override_flags = 0;
1206 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1207 if (dcbx_info->operational.cee)
1208 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1209 if (dcbx_info->operational.ieee)
1210 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1211
1212 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1213 memcpy(&p_hwfn->p_dcbx_info->set.config.params,
1214 &dcbx_info->operational.params,
1215 sizeof(struct qed_dcbx_admin_params));
1216 p_hwfn->p_dcbx_info->set.config.valid = true;
1217
1218 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
1219
1220 kfree(dcbx_info);
1221
1222 return 0;
1223}
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001224
1225static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1226 enum qed_mib_read_type type)
1227{
1228 struct qed_dcbx_get *dcbx_info;
1229
1230 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
1231 if (!dcbx_info) {
1232 DP_ERR(hwfn->cdev, "Failed to allocate memory for dcbx_info\n");
1233 return NULL;
1234 }
1235
Sudarsana Reddy Kalluruc5e801d2016-08-29 08:29:54 -04001236 memset(dcbx_info, 0, sizeof(*dcbx_info));
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001237 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1238 kfree(dcbx_info);
1239 return NULL;
1240 }
1241
1242 if ((type == QED_DCBX_OPERATIONAL_MIB) &&
1243 !dcbx_info->operational.enabled) {
1244 DP_INFO(hwfn, "DCBX is not enabled/operational\n");
1245 kfree(dcbx_info);
1246 return NULL;
1247 }
1248
1249 return dcbx_info;
1250}
1251
1252static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
1253{
1254 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1255 struct qed_dcbx_get *dcbx_info;
1256 bool enabled;
1257
1258 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1259 if (!dcbx_info)
1260 return 0;
1261
1262 enabled = dcbx_info->operational.enabled;
1263 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
1264 kfree(dcbx_info);
1265
1266 return enabled;
1267}
1268
1269static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
1270{
1271 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1272 struct qed_dcbx_set dcbx_set;
1273 struct qed_ptt *ptt;
1274 int rc;
1275
1276 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
1277
1278 memset(&dcbx_set, 0, sizeof(dcbx_set));
1279 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1280 if (rc)
1281 return 1;
1282
1283 dcbx_set.enabled = !!state;
1284
1285 ptt = qed_ptt_acquire(hwfn);
1286 if (!ptt)
1287 return 1;
1288
1289 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1290
1291 qed_ptt_release(hwfn, ptt);
1292
1293 return rc ? 1 : 0;
1294}
1295
1296static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
1297 u8 *pgid, u8 *bw_pct, u8 *up_map)
1298{
1299 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1300 struct qed_dcbx_get *dcbx_info;
1301
1302 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
1303 *prio_type = *pgid = *bw_pct = *up_map = 0;
1304 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1305 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1306 return;
1307 }
1308
1309 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1310 if (!dcbx_info)
1311 return;
1312
1313 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
1314 kfree(dcbx_info);
1315}
1316
1317static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
1318{
1319 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1320 struct qed_dcbx_get *dcbx_info;
1321
1322 *bw_pct = 0;
1323 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
1324 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1325 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1326 return;
1327 }
1328
1329 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1330 if (!dcbx_info)
1331 return;
1332
1333 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
1334 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
1335 kfree(dcbx_info);
1336}
1337
1338static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
1339 u8 *bwg_id, u8 *bw_pct, u8 *up_map)
1340{
1341 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1342 *prio = *bwg_id = *bw_pct = *up_map = 0;
1343}
1344
1345static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
1346 int bwg_id, u8 *bw_pct)
1347{
1348 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1349 *bw_pct = 0;
1350}
1351
1352static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
1353 int priority, u8 *setting)
1354{
1355 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1356 struct qed_dcbx_get *dcbx_info;
1357
1358 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
1359 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1360 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1361 return;
1362 }
1363
1364 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1365 if (!dcbx_info)
1366 return;
1367
1368 *setting = dcbx_info->operational.params.pfc.prio[priority];
1369 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
1370 kfree(dcbx_info);
1371}
1372
1373static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
1374{
1375 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1376 struct qed_dcbx_set dcbx_set;
1377 struct qed_ptt *ptt;
1378 int rc;
1379
1380 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
1381 priority, setting);
1382 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
1383 DP_INFO(hwfn, "Invalid priority %d\n", priority);
1384 return;
1385 }
1386
1387 memset(&dcbx_set, 0, sizeof(dcbx_set));
1388 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1389 if (rc)
1390 return;
1391
1392 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1393 dcbx_set.config.params.pfc.prio[priority] = !!setting;
1394
1395 ptt = qed_ptt_acquire(hwfn);
1396 if (!ptt)
1397 return;
1398
1399 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1400
1401 qed_ptt_release(hwfn, ptt);
1402}
1403
1404static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
1405{
1406 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1407 struct qed_dcbx_get *dcbx_info;
1408 int rc = 0;
1409
1410 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
1411 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1412 if (!dcbx_info)
1413 return 1;
1414
1415 switch (capid) {
1416 case DCB_CAP_ATTR_PG:
1417 case DCB_CAP_ATTR_PFC:
1418 case DCB_CAP_ATTR_UP2TC:
1419 case DCB_CAP_ATTR_GSP:
1420 *cap = true;
1421 break;
1422 case DCB_CAP_ATTR_PG_TCS:
1423 case DCB_CAP_ATTR_PFC_TCS:
1424 *cap = 0x80;
1425 break;
1426 case DCB_CAP_ATTR_DCBX:
1427 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
1428 DCB_CAP_DCBX_VER_IEEE);
1429 break;
1430 default:
1431 *cap = false;
1432 rc = 1;
1433 }
1434
1435 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
1436 kfree(dcbx_info);
1437
1438 return rc;
1439}
1440
1441static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
1442{
1443 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1444 struct qed_dcbx_get *dcbx_info;
1445 int rc = 0;
1446
1447 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
1448 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1449 if (!dcbx_info)
1450 return -EINVAL;
1451
1452 switch (tcid) {
1453 case DCB_NUMTCS_ATTR_PG:
1454 *num = dcbx_info->operational.params.max_ets_tc;
1455 break;
1456 case DCB_NUMTCS_ATTR_PFC:
1457 *num = dcbx_info->operational.params.pfc.max_tc;
1458 break;
1459 default:
1460 rc = -EINVAL;
1461 }
1462
1463 kfree(dcbx_info);
1464 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
1465
1466 return rc;
1467}
1468
1469static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
1470{
1471 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1472 struct qed_dcbx_get *dcbx_info;
1473 bool enabled;
1474
1475 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1476 if (!dcbx_info)
1477 return 0;
1478
1479 enabled = dcbx_info->operational.params.pfc.enabled;
1480 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
1481 kfree(dcbx_info);
1482
1483 return enabled;
1484}
1485
1486static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
1487{
1488 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1489 struct qed_dcbx_get *dcbx_info;
1490 u8 mode = 0;
1491
1492 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1493 if (!dcbx_info)
1494 return 0;
1495
1496 if (dcbx_info->operational.enabled)
1497 mode |= DCB_CAP_DCBX_LLD_MANAGED;
1498 if (dcbx_info->operational.ieee)
1499 mode |= DCB_CAP_DCBX_VER_IEEE;
1500 if (dcbx_info->operational.cee)
1501 mode |= DCB_CAP_DCBX_VER_CEE;
1502
1503 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
1504 kfree(dcbx_info);
1505
1506 return mode;
1507}
1508
1509static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
1510 int tc,
1511 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1512{
1513 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1514 struct qed_dcbx_set dcbx_set;
1515 struct qed_ptt *ptt;
1516 int rc;
1517
1518 DP_VERBOSE(hwfn, QED_MSG_DCB,
1519 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
1520 tc, pri_type, pgid, bw_pct, up_map);
1521
1522 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
1523 DP_INFO(hwfn, "Invalid tc %d\n", tc);
1524 return;
1525 }
1526
1527 memset(&dcbx_set, 0, sizeof(dcbx_set));
1528 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1529 if (rc)
1530 return;
1531
1532 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1533 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
1534
1535 ptt = qed_ptt_acquire(hwfn);
1536 if (!ptt)
1537 return;
1538
1539 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1540
1541 qed_ptt_release(hwfn, ptt);
1542}
1543
1544static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
1545 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
1546{
1547 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1548}
1549
1550static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1551{
1552 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1553 struct qed_dcbx_set dcbx_set;
1554 struct qed_ptt *ptt;
1555 int rc;
1556
1557 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
1558 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
1559 DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
1560 return;
1561 }
1562
1563 memset(&dcbx_set, 0, sizeof(dcbx_set));
1564 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1565 if (rc)
1566 return;
1567
1568 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1569 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
1570
1571 ptt = qed_ptt_acquire(hwfn);
1572 if (!ptt)
1573 return;
1574
1575 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1576
1577 qed_ptt_release(hwfn, ptt);
1578}
1579
1580static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
1581{
1582 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
1583}
1584
1585static u8 qed_dcbnl_setall(struct qed_dev *cdev)
1586{
1587 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1588 struct qed_dcbx_set dcbx_set;
1589 struct qed_ptt *ptt;
1590 int rc;
1591
1592 memset(&dcbx_set, 0, sizeof(dcbx_set));
1593 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1594 if (rc)
1595 return 1;
1596
1597 ptt = qed_ptt_acquire(hwfn);
1598 if (!ptt)
1599 return 1;
1600
1601 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
1602
1603 qed_ptt_release(hwfn, ptt);
1604
1605 return rc;
1606}
1607
1608static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
1609{
1610 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1611 struct qed_dcbx_set dcbx_set;
1612 struct qed_ptt *ptt;
1613 int rc;
1614
1615 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
1616 memset(&dcbx_set, 0, sizeof(dcbx_set));
1617 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1618 if (rc)
1619 return 1;
1620
1621 switch (tcid) {
1622 case DCB_NUMTCS_ATTR_PG:
1623 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1624 dcbx_set.config.params.max_ets_tc = num;
1625 break;
1626 case DCB_NUMTCS_ATTR_PFC:
1627 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1628 dcbx_set.config.params.pfc.max_tc = num;
1629 break;
1630 default:
1631 DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
1632 return -EINVAL;
1633 }
1634
1635 ptt = qed_ptt_acquire(hwfn);
1636 if (!ptt)
1637 return -EINVAL;
1638
1639 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1640
1641 qed_ptt_release(hwfn, ptt);
1642
1643 return 0;
1644}
1645
1646static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
1647{
1648 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1649 struct qed_dcbx_set dcbx_set;
1650 struct qed_ptt *ptt;
1651 int rc;
1652
1653 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
1654
1655 memset(&dcbx_set, 0, sizeof(dcbx_set));
1656 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1657 if (rc)
1658 return;
1659
1660 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1661 dcbx_set.config.params.pfc.enabled = !!state;
1662
1663 ptt = qed_ptt_acquire(hwfn);
1664 if (!ptt)
1665 return;
1666
1667 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1668
1669 qed_ptt_release(hwfn, ptt);
1670}
1671
1672static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
1673{
1674 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1675 struct qed_dcbx_get *dcbx_info;
1676 struct qed_app_entry *entry;
1677 bool ethtype;
1678 u8 prio = 0;
1679 int i;
1680
1681 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1682 if (!dcbx_info)
1683 return -EINVAL;
1684
1685 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1686 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1687 entry = &dcbx_info->operational.params.app_entry[i];
1688 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
1689 prio = entry->prio;
1690 break;
1691 }
1692 }
1693
1694 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1695 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
1696 kfree(dcbx_info);
1697 return -EINVAL;
1698 }
1699
1700 kfree(dcbx_info);
1701
1702 return prio;
1703}
1704
1705static int qed_dcbnl_setapp(struct qed_dev *cdev,
1706 u8 idtype, u16 idval, u8 pri_map)
1707{
1708 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1709 struct qed_dcbx_set dcbx_set;
1710 struct qed_app_entry *entry;
1711 struct qed_ptt *ptt;
1712 bool ethtype;
1713 int rc, i;
1714
1715 memset(&dcbx_set, 0, sizeof(dcbx_set));
1716 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1717 if (rc)
1718 return -EINVAL;
1719
1720 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
1721 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
1722 entry = &dcbx_set.config.params.app_entry[i];
1723 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1724 break;
1725 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001726 if (!entry->proto_id) {
1727 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001728 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04001729 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04001730 }
1731
1732 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
1733 DP_ERR(cdev, "App table is full\n");
1734 return -EBUSY;
1735 }
1736
1737 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1738 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
1739 dcbx_set.config.params.app_entry[i].proto_id = idval;
1740 dcbx_set.config.params.app_entry[i].prio = pri_map;
1741
1742 ptt = qed_ptt_acquire(hwfn);
1743 if (!ptt)
1744 return -EBUSY;
1745
1746 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1747
1748 qed_ptt_release(hwfn, ptt);
1749
1750 return rc;
1751}
1752
1753static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
1754{
1755 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1756 struct qed_dcbx_set dcbx_set;
1757 struct qed_ptt *ptt;
1758 int rc;
1759
1760 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
1761
1762 if (!(mode & DCB_CAP_DCBX_VER_IEEE) && !(mode & DCB_CAP_DCBX_VER_CEE)) {
1763 DP_INFO(hwfn, "Allowed mode is cee, ieee or both\n");
1764 return 1;
1765 }
1766
1767 memset(&dcbx_set, 0, sizeof(dcbx_set));
1768 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1769 if (rc)
1770 return 1;
1771
1772 dcbx_set.ver_num = 0;
1773 if (mode & DCB_CAP_DCBX_VER_CEE) {
1774 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1775 dcbx_set.enabled = true;
1776 }
1777
1778 if (mode & DCB_CAP_DCBX_VER_IEEE) {
1779 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1780 dcbx_set.enabled = true;
1781 }
1782
1783 ptt = qed_ptt_acquire(hwfn);
1784 if (!ptt)
1785 return 1;
1786
1787 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1788
1789 qed_ptt_release(hwfn, ptt);
1790
1791 return 0;
1792}
1793
1794static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
1795{
1796 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1797 struct qed_dcbx_get *dcbx_info;
1798
1799 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
1800 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1801 if (!dcbx_info)
1802 return 1;
1803
1804 *flags = 0;
1805 switch (featid) {
1806 case DCB_FEATCFG_ATTR_PG:
1807 if (dcbx_info->operational.params.ets_enabled)
1808 *flags = DCB_FEATCFG_ENABLE;
1809 else
1810 *flags = DCB_FEATCFG_ERROR;
1811 break;
1812 case DCB_FEATCFG_ATTR_PFC:
1813 if (dcbx_info->operational.params.pfc.enabled)
1814 *flags = DCB_FEATCFG_ENABLE;
1815 else
1816 *flags = DCB_FEATCFG_ERROR;
1817 break;
1818 case DCB_FEATCFG_ATTR_APP:
1819 if (dcbx_info->operational.params.app_valid)
1820 *flags = DCB_FEATCFG_ENABLE;
1821 else
1822 *flags = DCB_FEATCFG_ERROR;
1823 break;
1824 default:
1825 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1826 kfree(dcbx_info);
1827 return 1;
1828 }
1829
1830 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
1831 kfree(dcbx_info);
1832
1833 return 0;
1834}
1835
1836static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
1837{
1838 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1839 struct qed_dcbx_set dcbx_set;
1840 bool enabled, willing;
1841 struct qed_ptt *ptt;
1842 int rc;
1843
1844 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
1845 featid, flags);
1846 memset(&dcbx_set, 0, sizeof(dcbx_set));
1847 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
1848 if (rc)
1849 return 1;
1850
1851 enabled = !!(flags & DCB_FEATCFG_ENABLE);
1852 willing = !!(flags & DCB_FEATCFG_WILLING);
1853 switch (featid) {
1854 case DCB_FEATCFG_ATTR_PG:
1855 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
1856 dcbx_set.config.params.ets_enabled = enabled;
1857 dcbx_set.config.params.ets_willing = willing;
1858 break;
1859 case DCB_FEATCFG_ATTR_PFC:
1860 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
1861 dcbx_set.config.params.pfc.enabled = enabled;
1862 dcbx_set.config.params.pfc.willing = willing;
1863 break;
1864 case DCB_FEATCFG_ATTR_APP:
1865 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
1866 dcbx_set.config.params.app_willing = willing;
1867 break;
1868 default:
1869 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
1870 return 1;
1871 }
1872
1873 ptt = qed_ptt_acquire(hwfn);
1874 if (!ptt)
1875 return 1;
1876
1877 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
1878
1879 qed_ptt_release(hwfn, ptt);
1880
1881 return 0;
1882}
1883
1884static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
1885 struct dcb_peer_app_info *info,
1886 u16 *app_count)
1887{
1888 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1889 struct qed_dcbx_get *dcbx_info;
1890
1891 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1892 if (!dcbx_info)
1893 return -EINVAL;
1894
1895 info->willing = dcbx_info->remote.params.app_willing;
1896 info->error = dcbx_info->remote.params.app_error;
1897 *app_count = dcbx_info->remote.params.num_app_entries;
1898 kfree(dcbx_info);
1899
1900 return 0;
1901}
1902
1903static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
1904 struct dcb_app *table)
1905{
1906 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1907 struct qed_dcbx_get *dcbx_info;
1908 int i;
1909
1910 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1911 if (!dcbx_info)
1912 return -EINVAL;
1913
1914 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
1915 if (dcbx_info->remote.params.app_entry[i].ethtype)
1916 table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
1917 else
1918 table[i].selector = DCB_APP_IDTYPE_PORTNUM;
1919 table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
1920 table[i].protocol =
1921 dcbx_info->remote.params.app_entry[i].proto_id;
1922 }
1923
1924 kfree(dcbx_info);
1925
1926 return 0;
1927}
1928
1929static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
1930{
1931 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1932 struct qed_dcbx_get *dcbx_info;
1933 int i;
1934
1935 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1936 if (!dcbx_info)
1937 return -EINVAL;
1938
1939 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
1940 if (dcbx_info->remote.params.pfc.prio[i])
1941 pfc->pfc_en |= BIT(i);
1942
1943 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
1944 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
1945 pfc->pfc_en, pfc->tcs_supported);
1946 kfree(dcbx_info);
1947
1948 return 0;
1949}
1950
1951static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
1952{
1953 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1954 struct qed_dcbx_get *dcbx_info;
1955 int i;
1956
1957 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
1958 if (!dcbx_info)
1959 return -EINVAL;
1960
1961 pg->willing = dcbx_info->remote.params.ets_willing;
1962 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
1963 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
1964 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
1965 }
1966
1967 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
1968 kfree(dcbx_info);
1969
1970 return 0;
1971}
1972
1973static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
1974 struct ieee_pfc *pfc, bool remote)
1975{
1976 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1977 struct qed_dcbx_params *params;
1978 struct qed_dcbx_get *dcbx_info;
1979 int rc, i;
1980
1981 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
1982 if (!dcbx_info)
1983 return -EINVAL;
1984
1985 if (!dcbx_info->operational.ieee) {
1986 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
1987 return -EINVAL;
1988 }
1989
1990 if (remote) {
1991 memset(dcbx_info, 0, sizeof(*dcbx_info));
1992 rc = qed_dcbx_query_params(hwfn, dcbx_info,
1993 QED_DCBX_REMOTE_MIB);
1994 if (rc) {
1995 kfree(dcbx_info);
1996 return -EINVAL;
1997 }
1998
1999 params = &dcbx_info->remote.params;
2000 } else {
2001 params = &dcbx_info->operational.params;
2002 }
2003
2004 pfc->pfc_cap = params->pfc.max_tc;
2005 pfc->pfc_en = 0;
2006 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2007 if (params->pfc.prio[i])
2008 pfc->pfc_en |= BIT(i);
2009
2010 kfree(dcbx_info);
2011
2012 return 0;
2013}
2014
2015static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2016{
2017 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
2018}
2019
2020static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2021{
2022 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2023 struct qed_dcbx_get *dcbx_info;
2024 struct qed_dcbx_set dcbx_set;
2025 struct qed_ptt *ptt;
2026 int rc, i;
2027
2028 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2029 if (!dcbx_info)
2030 return -EINVAL;
2031
2032 if (!dcbx_info->operational.ieee) {
2033 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2034 kfree(dcbx_info);
2035 return -EINVAL;
2036 }
2037
2038 kfree(dcbx_info);
2039
2040 memset(&dcbx_set, 0, sizeof(dcbx_set));
2041 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2042 if (rc)
2043 return -EINVAL;
2044
2045 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
2046 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2047 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2048
2049 ptt = qed_ptt_acquire(hwfn);
2050 if (!ptt)
2051 return -EINVAL;
2052
2053 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2054
2055 qed_ptt_release(hwfn, ptt);
2056
2057 return rc;
2058}
2059
2060static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
2061 struct ieee_ets *ets, bool remote)
2062{
2063 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2064 struct qed_dcbx_get *dcbx_info;
2065 struct qed_dcbx_params *params;
2066 int rc;
2067
2068 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2069 if (!dcbx_info)
2070 return -EINVAL;
2071
2072 if (!dcbx_info->operational.ieee) {
2073 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2074 kfree(dcbx_info);
2075 return -EINVAL;
2076 }
2077
2078 if (remote) {
2079 memset(dcbx_info, 0, sizeof(*dcbx_info));
2080 rc = qed_dcbx_query_params(hwfn, dcbx_info,
2081 QED_DCBX_REMOTE_MIB);
2082 if (rc) {
2083 kfree(dcbx_info);
2084 return -EINVAL;
2085 }
2086
2087 params = &dcbx_info->remote.params;
2088 } else {
2089 params = &dcbx_info->operational.params;
2090 }
2091
2092 ets->ets_cap = params->max_ets_tc;
2093 ets->willing = params->ets_willing;
2094 ets->cbs = params->ets_cbs;
2095 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
2096 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
2097 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
2098 kfree(dcbx_info);
2099
2100 return 0;
2101}
2102
2103static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2104{
2105 return qed_dcbnl_get_ieee_ets(cdev, ets, false);
2106}
2107
2108static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
2109{
2110 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2111 struct qed_dcbx_get *dcbx_info;
2112 struct qed_dcbx_set dcbx_set;
2113 struct qed_ptt *ptt;
2114 int rc;
2115
2116 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2117 if (!dcbx_info)
2118 return -EINVAL;
2119
2120 if (!dcbx_info->operational.ieee) {
2121 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2122 kfree(dcbx_info);
2123 return -EINVAL;
2124 }
2125
2126 kfree(dcbx_info);
2127
2128 memset(&dcbx_set, 0, sizeof(dcbx_set));
2129 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2130 if (rc)
2131 return -EINVAL;
2132
2133 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
2134 dcbx_set.config.params.max_ets_tc = ets->ets_cap;
2135 dcbx_set.config.params.ets_willing = ets->willing;
2136 dcbx_set.config.params.ets_cbs = ets->cbs;
2137 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
2138 sizeof(ets->tc_tx_bw));
2139 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
2140 sizeof(ets->tc_tsa));
2141 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
2142 sizeof(ets->prio_tc));
2143
2144 ptt = qed_ptt_acquire(hwfn);
2145 if (!ptt)
2146 return -EINVAL;
2147
2148 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2149
2150 qed_ptt_release(hwfn, ptt);
2151
2152 return rc;
2153}
2154
2155int qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
2156{
2157 return qed_dcbnl_get_ieee_ets(cdev, ets, true);
2158}
2159
2160int qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2161{
2162 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
2163}
2164
2165int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
2166{
2167 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2168 struct qed_dcbx_get *dcbx_info;
2169 struct qed_app_entry *entry;
2170 bool ethtype;
2171 u8 prio = 0;
2172 int i;
2173
2174 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2175 if (!dcbx_info)
2176 return -EINVAL;
2177
2178 if (!dcbx_info->operational.ieee) {
2179 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2180 kfree(dcbx_info);
2181 return -EINVAL;
2182 }
2183
2184 /* ieee defines the selector field value for ethertype to be 1 */
2185 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2186 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2187 entry = &dcbx_info->operational.params.app_entry[i];
2188 if ((entry->ethtype == ethtype) &&
2189 (entry->proto_id == app->protocol)) {
2190 prio = entry->prio;
2191 break;
2192 }
2193 }
2194
2195 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2196 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
2197 app->protocol);
2198 kfree(dcbx_info);
2199 return -EINVAL;
2200 }
2201
2202 app->priority = ffs(prio) - 1;
2203
2204 kfree(dcbx_info);
2205
2206 return 0;
2207}
2208
2209int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2210{
2211 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2212 struct qed_dcbx_get *dcbx_info;
2213 struct qed_dcbx_set dcbx_set;
2214 struct qed_app_entry *entry;
2215 struct qed_ptt *ptt;
2216 bool ethtype;
2217 int rc, i;
2218
2219 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
2220 DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
2221 return -EINVAL;
2222 }
2223
2224 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
2225 if (!dcbx_info)
2226 return -EINVAL;
2227
2228 if (!dcbx_info->operational.ieee) {
2229 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
2230 kfree(dcbx_info);
2231 return -EINVAL;
2232 }
2233
2234 kfree(dcbx_info);
2235
2236 memset(&dcbx_set, 0, sizeof(dcbx_set));
2237 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
2238 if (rc)
2239 return -EINVAL;
2240
2241 /* ieee defines the selector field value for ethertype to be 1 */
2242 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
2243 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
2244 entry = &dcbx_set.config.params.app_entry[i];
2245 if ((entry->ethtype == ethtype) &&
2246 (entry->proto_id == app->protocol))
2247 break;
2248 /* First empty slot */
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002249 if (!entry->proto_id) {
2250 dcbx_set.config.params.num_app_entries++;
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002251 break;
Sudarsana Reddy Kalluru1d7406ce2016-08-08 21:57:43 -04002252 }
Sudarsana Reddy Kallurua1d8d8a2016-06-08 06:22:11 -04002253 }
2254
2255 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
2256 DP_ERR(cdev, "App table is full\n");
2257 return -EBUSY;
2258 }
2259
2260 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
2261 dcbx_set.config.params.app_entry[i].ethtype = ethtype;
2262 dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
2263 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
2264
2265 ptt = qed_ptt_acquire(hwfn);
2266 if (!ptt)
2267 return -EBUSY;
2268
2269 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
2270
2271 qed_ptt_release(hwfn, ptt);
2272
2273 return rc;
2274}
2275
2276const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
2277 .getstate = qed_dcbnl_getstate,
2278 .setstate = qed_dcbnl_setstate,
2279 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
2280 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
2281 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
2282 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
2283 .getpfccfg = qed_dcbnl_getpfccfg,
2284 .setpfccfg = qed_dcbnl_setpfccfg,
2285 .getcap = qed_dcbnl_getcap,
2286 .getnumtcs = qed_dcbnl_getnumtcs,
2287 .getpfcstate = qed_dcbnl_getpfcstate,
2288 .getdcbx = qed_dcbnl_getdcbx,
2289 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
2290 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
2291 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
2292 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
2293 .setall = qed_dcbnl_setall,
2294 .setnumtcs = qed_dcbnl_setnumtcs,
2295 .setpfcstate = qed_dcbnl_setpfcstate,
2296 .setapp = qed_dcbnl_setapp,
2297 .setdcbx = qed_dcbnl_setdcbx,
2298 .setfeatcfg = qed_dcbnl_setfeatcfg,
2299 .getfeatcfg = qed_dcbnl_getfeatcfg,
2300 .getapp = qed_dcbnl_getapp,
2301 .peer_getappinfo = qed_dcbnl_peer_getappinfo,
2302 .peer_getapptable = qed_dcbnl_peer_getapptable,
2303 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
2304 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
2305 .ieee_getpfc = qed_dcbnl_ieee_getpfc,
2306 .ieee_setpfc = qed_dcbnl_ieee_setpfc,
2307 .ieee_getets = qed_dcbnl_ieee_getets,
2308 .ieee_setets = qed_dcbnl_ieee_setets,
2309 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
2310 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
2311 .ieee_getapp = qed_dcbnl_ieee_getapp,
2312 .ieee_setapp = qed_dcbnl_ieee_setapp,
2313};
2314
Sudarsana Reddy Kalluru6ad8c632016-06-08 06:22:10 -04002315#endif