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