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