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