net/mlx5: fix VLAN stripping indication
[dpdk.git] / drivers / net / qede / base / ecore_dcbx.c
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #include "bcm_osal.h"
10 #include "ecore.h"
11 #include "ecore_sp_commands.h"
12 #include "ecore_dcbx.h"
13 #include "ecore_cxt.h"
14 #include "ecore_gtt_reg_addr.h"
15 #include "ecore_iro.h"
16 #include "ecore_iov_api.h"
17
18 #define ECORE_DCBX_MAX_MIB_READ_TRY     (100)
19 #define ECORE_ETH_TYPE_DEFAULT          (0)
20
21 #define ECORE_DCBX_INVALID_PRIORITY     0xFF
22
23 /* Get Traffic Class from priority traffic class table, 4 bits represent
24  * the traffic class corresponding to the priority.
25  */
26 #define ECORE_DCBX_PRIO2TC(prio_tc_tbl, prio) \
27                 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
28
29 static bool ecore_dcbx_app_ethtype(u32 app_info_bitmap)
30 {
31         return !!(ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
32                   DCBX_APP_SF_ETHTYPE);
33 }
34
35 static bool ecore_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
36 {
37         u8 mfw_val = ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
38
39         /* Old MFW */
40         if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
41                 return ecore_dcbx_app_ethtype(app_info_bitmap);
42
43         return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
44 }
45
46 static bool ecore_dcbx_app_port(u32 app_info_bitmap)
47 {
48         return !!(ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
49                   DCBX_APP_SF_PORT);
50 }
51
52 static bool ecore_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
53 {
54         u8 mfw_val = ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
55
56         /* Old MFW */
57         if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
58                 return ecore_dcbx_app_port(app_info_bitmap);
59
60         return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
61 }
62
63 static bool ecore_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
64 {
65         bool ethtype;
66
67         if (ieee)
68                 ethtype = ecore_dcbx_ieee_app_ethtype(app_info_bitmap);
69         else
70                 ethtype = ecore_dcbx_app_ethtype(app_info_bitmap);
71
72         return !!(ethtype && (proto_id == ECORE_ETH_TYPE_DEFAULT));
73 }
74
75 static void
76 ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
77                        struct ecore_dcbx_results *p_data)
78 {
79         enum dcbx_protocol_type id;
80         int i;
81
82         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "DCBX negotiated: %d\n",
83                    p_data->dcbx_enabled);
84
85         for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
86                 id = ecore_dcbx_app_update[i].id;
87
88                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
89                            "%s info: update %d, enable %d, prio %d, tc %d,"
90                            " num_active_tc %d dscp_enable = %d dscp_val = %d\n",
91                            ecore_dcbx_app_update[i].name,
92                            p_data->arr[id].update,
93                            p_data->arr[id].enable, p_data->arr[id].priority,
94                            p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc,
95                            p_data->arr[id].dscp_enable,
96                            p_data->arr[id].dscp_val);
97         }
98 }
99
100 void
101 ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
102                       struct ecore_hwfn *p_hwfn,
103                       bool enable, bool update, u8 prio, u8 tc,
104                       enum dcbx_protocol_type type,
105                       enum ecore_pci_personality personality)
106 {
107         struct ecore_dcbx_dscp_params *dscp = &p_hwfn->p_dcbx_info->get.dscp;
108
109         /* PF update ramrod data */
110         p_data->arr[type].enable = enable;
111         p_data->arr[type].priority = prio;
112         p_data->arr[type].tc = tc;
113         p_data->arr[type].dscp_enable = dscp->enabled;
114         if (p_data->arr[type].dscp_enable) {
115                 u8 i;
116
117                 for (i = 0; i < ECORE_DCBX_DSCP_SIZE; i++)
118                         if (prio == dscp->dscp_pri_map[i]) {
119                                 p_data->arr[type].dscp_val = i;
120                                 break;
121                         }
122         }
123
124         if (enable && p_data->arr[type].dscp_enable)
125                 p_data->arr[type].update = UPDATE_DCB_DSCP;
126         else if (enable)
127                 p_data->arr[type].update = UPDATE_DCB;
128         else
129                 p_data->arr[type].update = DONT_UPDATE_DCB_DHCP;
130
131         /* QM reconf data */
132         if (p_hwfn->hw_info.personality == personality) {
133                 p_hwfn->hw_info.offload_tc = tc;
134                 if (personality == ECORE_PCI_ISCSI)
135                         p_hwfn->hw_info.ooo_tc = DCBX_ISCSI_OOO_TC;
136         }
137 }
138
139 /* Update app protocol data and hw_info fields with the TLV info */
140 static void
141 ecore_dcbx_update_app_info(struct ecore_dcbx_results *p_data,
142                            struct ecore_hwfn *p_hwfn,
143                            bool enable, bool update, u8 prio, u8 tc,
144                            enum dcbx_protocol_type type)
145 {
146         enum ecore_pci_personality personality;
147         enum dcbx_protocol_type id;
148         const char *name;       /* @DPDK */
149         int i;
150
151         for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
152                 id = ecore_dcbx_app_update[i].id;
153
154                 if (type != id)
155                         continue;
156
157                 personality = ecore_dcbx_app_update[i].personality;
158                 name = ecore_dcbx_app_update[i].name;
159
160                 ecore_dcbx_set_params(p_data, p_hwfn, enable, update,
161                                       prio, tc, type, personality);
162         }
163 }
164
165 static enum _ecore_status_t
166 ecore_dcbx_get_app_priority(u8 pri_bitmap, u8 *priority)
167 {
168         u32 pri_mask, pri = ECORE_MAX_PFC_PRIORITIES;
169         u32 index = ECORE_MAX_PFC_PRIORITIES - 1;
170         enum _ecore_status_t rc = ECORE_SUCCESS;
171
172         /* Bitmap 1 corresponds to priority 0, return priority 0 */
173         if (pri_bitmap == 1) {
174                 *priority = 0;
175                 return rc;
176         }
177
178         /* Choose the highest priority */
179         while ((pri == ECORE_MAX_PFC_PRIORITIES) && index) {
180                 pri_mask = 1 << index;
181                 if (pri_bitmap & pri_mask)
182                         pri = index;
183                 index--;
184         }
185
186         if (pri < ECORE_MAX_PFC_PRIORITIES)
187                 *priority = (u8)pri;
188         else
189                 rc = ECORE_INVAL;
190
191         return rc;
192 }
193
194 static bool
195 ecore_dcbx_get_app_protocol_type(struct ecore_hwfn *p_hwfn,
196                                  u32 app_prio_bitmap, u16 id,
197                                  enum dcbx_protocol_type *type, bool ieee)
198 {
199         if (ecore_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
200                 *type = DCBX_PROTOCOL_ETH;
201         } else {
202                 *type = DCBX_MAX_PROTOCOL_TYPE;
203                 DP_ERR(p_hwfn,
204                        "No action required, App TLV id = 0x%x"
205                        " app_prio_bitmap = 0x%x\n",
206                        id, app_prio_bitmap);
207                 return false;
208         }
209
210         return true;
211 }
212
213 /*  Parse app TLV's to update TC information in hw_info structure for
214  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
215  */
216 static enum _ecore_status_t
217 ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
218                        struct ecore_dcbx_results *p_data,
219                        struct dcbx_app_priority_entry *p_tbl, u32 pri_tc_tbl,
220                        int count, u8 dcbx_version)
221 {
222         enum dcbx_protocol_type type;
223         u8 tc, priority_map;
224         bool enable, ieee;
225         u16 protocol_id;
226         u8 priority;
227         enum _ecore_status_t rc = ECORE_SUCCESS;
228         int i;
229
230         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Num APP entries = %d\n", count);
231
232         ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
233         /* Parse APP TLV */
234         for (i = 0; i < count; i++) {
235                 protocol_id = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
236                                                   DCBX_APP_PROTOCOL_ID);
237                 priority_map = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
238                                                    DCBX_APP_PRI_MAP);
239                 rc = ecore_dcbx_get_app_priority(priority_map, &priority);
240                 if (rc == ECORE_INVAL) {
241                         DP_ERR(p_hwfn, "Invalid priority\n");
242                         return ECORE_INVAL;
243                 }
244
245                 tc = ECORE_DCBX_PRIO2TC(pri_tc_tbl, priority);
246                 if (ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
247                                                      protocol_id, &type,
248                                                      ieee)) {
249                         /* ETH always have the enable bit reset, as it gets
250                          * vlan information per packet. For other protocols,
251                          * should be set according to the dcbx_enabled
252                          * indication, but we only got here if there was an
253                          * app tlv for the protocol, so dcbx must be enabled.
254                          */
255                         enable = !(type == DCBX_PROTOCOL_ETH);
256
257                         ecore_dcbx_update_app_info(p_data, p_hwfn, enable, true,
258                                                    priority, tc, type);
259                 }
260         }
261         /* Update ramrod protocol data and hw_info fields
262          * with default info when corresponding APP TLV's are not detected.
263          * The enabled field has a different logic for ethernet as only for
264          * ethernet dcb should disabled by default, as the information arrives
265          * from the OS (unless an explicit app tlv was present).
266          */
267         tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
268         priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
269         for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
270                 if (p_data->arr[type].update)
271                         continue;
272
273                 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
274                 ecore_dcbx_update_app_info(p_data, p_hwfn, enable, true,
275                                            priority, tc, type);
276         }
277
278         return ECORE_SUCCESS;
279 }
280
281 /* Parse app TLV's to update TC information in hw_info structure for
282  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
283  */
284 static enum _ecore_status_t
285 ecore_dcbx_process_mib_info(struct ecore_hwfn *p_hwfn)
286 {
287         struct dcbx_app_priority_feature *p_app;
288         enum _ecore_status_t rc = ECORE_SUCCESS;
289         struct ecore_dcbx_results data = { 0 };
290         struct dcbx_app_priority_entry *p_tbl;
291         struct dcbx_ets_feature *p_ets;
292         struct ecore_hw_info *p_info;
293         u32 pri_tc_tbl, flags;
294         u8 dcbx_version;
295         int num_entries;
296
297         flags = p_hwfn->p_dcbx_info->operational.flags;
298         dcbx_version = ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
299
300         p_app = &p_hwfn->p_dcbx_info->operational.features.app;
301         p_tbl = p_app->app_pri_tbl;
302
303         p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
304         pri_tc_tbl = p_ets->pri_tc_tbl[0];
305
306         p_info = &p_hwfn->hw_info;
307         num_entries = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
308
309         rc = ecore_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
310                                     num_entries, dcbx_version);
311         if (rc != ECORE_SUCCESS)
312                 return rc;
313
314         p_info->num_active_tc = ECORE_MFW_GET_FIELD(p_ets->flags,
315                                                     DCBX_ETS_MAX_TCS);
316         data.pf_id = p_hwfn->rel_pf_id;
317         data.dcbx_enabled = !!dcbx_version;
318
319         ecore_dcbx_dp_protocol(p_hwfn, &data);
320
321         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->results, &data,
322                     sizeof(struct ecore_dcbx_results));
323
324         return ECORE_SUCCESS;
325 }
326
327 static enum _ecore_status_t
328 ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
329                     struct ecore_ptt *p_ptt,
330                     struct ecore_dcbx_mib_meta_data *p_data,
331                     enum ecore_mib_read_type type)
332 {
333         enum _ecore_status_t rc = ECORE_SUCCESS;
334         u32 prefix_seq_num, suffix_seq_num;
335         int read_count = 0;
336
337         /* The data is considered to be valid only if both sequence numbers are
338          * the same.
339          */
340         do {
341                 if (type == ECORE_DCBX_REMOTE_LLDP_MIB) {
342                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
343                                           p_data->addr, p_data->size);
344                         prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
345                         suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
346                 } else {
347                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
348                                           p_data->addr, p_data->size);
349                         prefix_seq_num = p_data->mib->prefix_seq_num;
350                         suffix_seq_num = p_data->mib->suffix_seq_num;
351                 }
352                 read_count++;
353
354                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
355                            "mib type = %d, try count = %d prefix seq num  ="
356                            " %d suffix seq num = %d\n",
357                            type, read_count, prefix_seq_num, suffix_seq_num);
358         } while ((prefix_seq_num != suffix_seq_num) &&
359                  (read_count < ECORE_DCBX_MAX_MIB_READ_TRY));
360
361         if (read_count >= ECORE_DCBX_MAX_MIB_READ_TRY) {
362                 DP_ERR(p_hwfn,
363                        "MIB read err, mib type = %d, try count ="
364                        " %d prefix seq num = %d suffix seq num = %d\n",
365                        type, read_count, prefix_seq_num, suffix_seq_num);
366                 rc = ECORE_IO;
367         }
368
369         return rc;
370 }
371
372 static void
373 ecore_dcbx_get_priority_info(struct ecore_hwfn *p_hwfn,
374                              struct ecore_dcbx_app_prio *p_prio,
375                              struct ecore_dcbx_results *p_results)
376 {
377         u8 val;
378
379         if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
380             p_results->arr[DCBX_PROTOCOL_ETH].enable)
381                 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
382
383         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
384                    "Priorities: eth %d\n",
385                    p_prio->eth);
386 }
387
388 static void
389 ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
390                         struct dcbx_app_priority_feature *p_app,
391                         struct dcbx_app_priority_entry *p_tbl,
392                         struct ecore_dcbx_params *p_params, bool ieee)
393 {
394         struct ecore_app_entry *entry;
395         u8 pri_map;
396         int i;
397
398         p_params->app_willing = ECORE_MFW_GET_FIELD(p_app->flags,
399                                                     DCBX_APP_WILLING);
400         p_params->app_valid = ECORE_MFW_GET_FIELD(p_app->flags,
401                                                   DCBX_APP_ENABLED);
402         p_params->app_error = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
403         p_params->num_app_entries = ECORE_MFW_GET_FIELD(p_app->flags,
404                                                         DCBX_APP_NUM_ENTRIES);
405         for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
406                 entry = &p_params->app_entry[i];
407                 if (ieee) {
408                         u8 sf_ieee;
409                         u32 val;
410
411                         sf_ieee = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
412                                                       DCBX_APP_SF_IEEE);
413                         switch (sf_ieee) {
414                         case DCBX_APP_SF_IEEE_RESERVED:
415                                 /* Old MFW */
416                                 val = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
417                                                             DCBX_APP_SF);
418                                 entry->sf_ieee = val ?
419                                         ECORE_DCBX_SF_IEEE_TCP_UDP_PORT :
420                                         ECORE_DCBX_SF_IEEE_ETHTYPE;
421                                 break;
422                         case DCBX_APP_SF_IEEE_ETHTYPE:
423                                 entry->sf_ieee = ECORE_DCBX_SF_IEEE_ETHTYPE;
424                                 break;
425                         case DCBX_APP_SF_IEEE_TCP_PORT:
426                                 entry->sf_ieee = ECORE_DCBX_SF_IEEE_TCP_PORT;
427                                 break;
428                         case DCBX_APP_SF_IEEE_UDP_PORT:
429                                 entry->sf_ieee = ECORE_DCBX_SF_IEEE_UDP_PORT;
430                                 break;
431                         case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
432                                 entry->sf_ieee =
433                                                 ECORE_DCBX_SF_IEEE_TCP_UDP_PORT;
434                                 break;
435                         }
436                 } else {
437                         entry->ethtype = !(ECORE_MFW_GET_FIELD(p_tbl[i].entry,
438                                                                DCBX_APP_SF));
439                 }
440
441                 pri_map = ECORE_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
442                 ecore_dcbx_get_app_priority(pri_map, &entry->prio);
443                 entry->proto_id = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
444                                                       DCBX_APP_PROTOCOL_ID);
445                 ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
446                                                  entry->proto_id,
447                                                  &entry->proto_type, ieee);
448         }
449
450         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
451                    "APP params: willing %d, valid %d error = %d\n",
452                    p_params->app_willing, p_params->app_valid,
453                    p_params->app_error);
454 }
455
456 static void
457 ecore_dcbx_get_pfc_data(struct ecore_hwfn *p_hwfn,
458                         u32 pfc, struct ecore_dcbx_params *p_params)
459 {
460         u8 pfc_map;
461
462         p_params->pfc.willing = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
463         p_params->pfc.max_tc = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
464         p_params->pfc.enabled = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
465         pfc_map = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
466         p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
467         p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
468         p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
469         p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
470         p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
471         p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
472         p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
473         p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
474
475         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
476                    "PFC params: willing %d, pfc_bitmap %d\n",
477                    p_params->pfc.willing, pfc_map);
478 }
479
480 static void
481 ecore_dcbx_get_ets_data(struct ecore_hwfn *p_hwfn,
482                         struct dcbx_ets_feature *p_ets,
483                         struct ecore_dcbx_params *p_params)
484 {
485         u32 bw_map[2], tsa_map[2], pri_map;
486         int i;
487
488         p_params->ets_willing = ECORE_MFW_GET_FIELD(p_ets->flags,
489                                                     DCBX_ETS_WILLING);
490         p_params->ets_enabled = ECORE_MFW_GET_FIELD(p_ets->flags,
491                                                     DCBX_ETS_ENABLED);
492         p_params->ets_cbs = ECORE_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
493         p_params->max_ets_tc = ECORE_MFW_GET_FIELD(p_ets->flags,
494                                                    DCBX_ETS_MAX_TCS);
495         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
496                    "ETS params: willing %d, ets_cbs %d pri_tc_tbl_0 %x"
497                    " max_ets_tc %d\n",
498                    p_params->ets_willing, p_params->ets_cbs,
499                    p_ets->pri_tc_tbl[0], p_params->max_ets_tc);
500
501         /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
502          * encoded in a type u32 array of size 2.
503          */
504         bw_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[0]);
505         bw_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[1]);
506         tsa_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[0]);
507         tsa_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[1]);
508         pri_map = p_ets->pri_tc_tbl[0];
509         for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
510                 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
511                 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
512                 p_params->ets_pri_tc_tbl[i] = ECORE_DCBX_PRIO2TC(pri_map, i);
513                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
514                            "elem %d  bw_tbl %x tsa_tbl %x\n",
515                            i, p_params->ets_tc_bw_tbl[i],
516                            p_params->ets_tc_tsa_tbl[i]);
517         }
518 }
519
520 static void
521 ecore_dcbx_get_common_params(struct ecore_hwfn *p_hwfn,
522                              struct dcbx_app_priority_feature *p_app,
523                              struct dcbx_app_priority_entry *p_tbl,
524                              struct dcbx_ets_feature *p_ets,
525                              u32 pfc, struct ecore_dcbx_params *p_params,
526                              bool ieee)
527 {
528         ecore_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
529         ecore_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
530         ecore_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
531 }
532
533 static void
534 ecore_dcbx_get_local_params(struct ecore_hwfn *p_hwfn,
535                             struct ecore_ptt *p_ptt,
536                             struct ecore_dcbx_get *params)
537 {
538         struct dcbx_features *p_feat;
539
540         p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
541         ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
542                                      p_feat->app.app_pri_tbl, &p_feat->ets,
543                                      p_feat->pfc, &params->local.params, false);
544         params->local.valid = true;
545 }
546
547 static void
548 ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
549                              struct ecore_ptt *p_ptt,
550                              struct ecore_dcbx_get *params)
551 {
552         struct dcbx_features *p_feat;
553
554         p_feat = &p_hwfn->p_dcbx_info->remote.features;
555         ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
556                                      p_feat->app.app_pri_tbl, &p_feat->ets,
557                                      p_feat->pfc, &params->remote.params,
558                                      false);
559         params->remote.valid = true;
560 }
561
562 static enum _ecore_status_t
563 ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
564                                   struct ecore_ptt *p_ptt,
565                                   struct ecore_dcbx_get *params)
566 {
567         struct ecore_dcbx_operational_params *p_operational;
568         struct ecore_dcbx_results *p_results;
569         struct dcbx_features *p_feat;
570         bool enabled, err;
571         u32 flags;
572         bool val;
573
574         flags = p_hwfn->p_dcbx_info->operational.flags;
575
576         /* If DCBx version is non zero, then negotiation
577          * was successfuly performed
578          */
579         p_operational = &params->operational;
580         enabled = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
581                      DCBX_CONFIG_VERSION_DISABLED);
582         if (!enabled) {
583                 p_operational->enabled = enabled;
584                 p_operational->valid = false;
585                 return ECORE_INVAL;
586         }
587
588         p_feat = &p_hwfn->p_dcbx_info->operational.features;
589         p_results = &p_hwfn->p_dcbx_info->results;
590
591         val = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
592                  DCBX_CONFIG_VERSION_IEEE);
593         p_operational->ieee = val;
594
595         val = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
596                  DCBX_CONFIG_VERSION_CEE);
597         p_operational->cee = val;
598
599         val = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
600                  DCBX_CONFIG_VERSION_STATIC);
601         p_operational->local = val;
602
603         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
604                    "Version support: ieee %d, cee %d, static %d\n",
605                    p_operational->ieee, p_operational->cee,
606                    p_operational->local);
607
608         ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
609                                      p_feat->app.app_pri_tbl, &p_feat->ets,
610                                      p_feat->pfc, &params->operational.params,
611                                      p_operational->ieee);
612         ecore_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio,
613                                      p_results);
614         err = ECORE_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
615         p_operational->err = err;
616         p_operational->enabled = enabled;
617         p_operational->valid = true;
618
619         return ECORE_SUCCESS;
620 }
621
622 static void
623 ecore_dcbx_get_dscp_params(struct ecore_hwfn *p_hwfn,
624                            struct ecore_ptt *p_ptt,
625                            struct ecore_dcbx_get *params)
626 {
627         struct ecore_dcbx_dscp_params *p_dscp;
628         struct dcb_dscp_map *p_dscp_map;
629         int i, j, entry;
630         u32 pri_map;
631
632         p_dscp = &params->dscp;
633         p_dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
634         p_dscp->enabled = ECORE_MFW_GET_FIELD(p_dscp_map->flags,
635                                               DCB_DSCP_ENABLE);
636         /* MFW encodes 64 dscp entries into 8 element array of u32 entries,
637          * where each entry holds the 4bit priority map for 8 dscp entries.
638          */
639         for (i = 0, entry = 0; i < ECORE_DCBX_DSCP_SIZE / 8; i++) {
640                 pri_map = OSAL_BE32_TO_CPU(p_dscp_map->dscp_pri_map[i]);
641                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "elem %d pri_map 0x%x\n",
642                            entry, pri_map);
643                 for (j = 0; j < ECORE_DCBX_DSCP_SIZE / 8; j++, entry++)
644                         p_dscp->dscp_pri_map[entry] = (u32)(pri_map >>
645                                                            (j * 4)) & 0xf;
646         }
647 }
648
649 static void
650 ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
651                                  struct ecore_ptt *p_ptt,
652                                  struct ecore_dcbx_get *params)
653 {
654         struct lldp_config_params_s *p_local;
655
656         p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
657
658         OSAL_MEMCPY(params->lldp_local.local_chassis_id,
659                     p_local->local_chassis_id,
660                     OSAL_ARRAY_SIZE(p_local->local_chassis_id));
661         OSAL_MEMCPY(params->lldp_local.local_port_id, p_local->local_port_id,
662                     OSAL_ARRAY_SIZE(p_local->local_port_id));
663 }
664
665 static void
666 ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
667                                   struct ecore_ptt *p_ptt,
668                                   struct ecore_dcbx_get *params)
669 {
670         struct lldp_status_params_s *p_remote;
671
672         p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
673
674         OSAL_MEMCPY(params->lldp_remote.peer_chassis_id,
675                     p_remote->peer_chassis_id,
676                     OSAL_ARRAY_SIZE(p_remote->peer_chassis_id));
677         OSAL_MEMCPY(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
678                     OSAL_ARRAY_SIZE(p_remote->peer_port_id));
679 }
680
681 static enum _ecore_status_t
682 ecore_dcbx_get_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
683                       struct ecore_dcbx_get *p_params,
684                       enum ecore_mib_read_type type)
685 {
686         enum _ecore_status_t rc = ECORE_SUCCESS;
687
688         switch (type) {
689         case ECORE_DCBX_REMOTE_MIB:
690                 ecore_dcbx_get_remote_params(p_hwfn, p_ptt, p_params);
691                 break;
692         case ECORE_DCBX_LOCAL_MIB:
693                 ecore_dcbx_get_local_params(p_hwfn, p_ptt, p_params);
694                 break;
695         case ECORE_DCBX_OPERATIONAL_MIB:
696                 ecore_dcbx_get_operational_params(p_hwfn, p_ptt, p_params);
697                 break;
698         case ECORE_DCBX_REMOTE_LLDP_MIB:
699                 ecore_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params);
700                 break;
701         case ECORE_DCBX_LOCAL_LLDP_MIB:
702                 ecore_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params);
703                 break;
704         default:
705                 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
706                 return ECORE_INVAL;
707         }
708
709         return rc;
710 }
711
712 static enum _ecore_status_t
713 ecore_dcbx_read_local_lldp_mib(struct ecore_hwfn *p_hwfn,
714                                struct ecore_ptt *p_ptt)
715 {
716         struct ecore_dcbx_mib_meta_data data;
717         enum _ecore_status_t rc = ECORE_SUCCESS;
718
719         OSAL_MEM_ZERO(&data, sizeof(data));
720         data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
721                                                            lldp_config_params);
722         data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
723         data.size = sizeof(struct lldp_config_params_s);
724         ecore_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
725
726         return rc;
727 }
728
729 static enum _ecore_status_t
730 ecore_dcbx_read_remote_lldp_mib(struct ecore_hwfn *p_hwfn,
731                                 struct ecore_ptt *p_ptt,
732                                 enum ecore_mib_read_type type)
733 {
734         struct ecore_dcbx_mib_meta_data data;
735         enum _ecore_status_t rc = ECORE_SUCCESS;
736
737         OSAL_MEM_ZERO(&data, sizeof(data));
738         data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
739                                                            lldp_status_params);
740         data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
741         data.size = sizeof(struct lldp_status_params_s);
742         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
743
744         return rc;
745 }
746
747 static enum _ecore_status_t
748 ecore_dcbx_read_operational_mib(struct ecore_hwfn *p_hwfn,
749                                 struct ecore_ptt *p_ptt,
750                                 enum ecore_mib_read_type type)
751 {
752         struct ecore_dcbx_mib_meta_data data;
753         enum _ecore_status_t rc = ECORE_SUCCESS;
754
755         OSAL_MEM_ZERO(&data, sizeof(data));
756         data.addr = p_hwfn->mcp_info->port_addr +
757             offsetof(struct public_port, operational_dcbx_mib);
758         data.mib = &p_hwfn->p_dcbx_info->operational;
759         data.size = sizeof(struct dcbx_mib);
760         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
761
762         return rc;
763 }
764
765 static enum _ecore_status_t
766 ecore_dcbx_read_remote_mib(struct ecore_hwfn *p_hwfn,
767                            struct ecore_ptt *p_ptt,
768                            enum ecore_mib_read_type type)
769 {
770         struct ecore_dcbx_mib_meta_data data;
771         enum _ecore_status_t rc = ECORE_SUCCESS;
772
773         OSAL_MEM_ZERO(&data, sizeof(data));
774         data.addr = p_hwfn->mcp_info->port_addr +
775             offsetof(struct public_port, remote_dcbx_mib);
776         data.mib = &p_hwfn->p_dcbx_info->remote;
777         data.size = sizeof(struct dcbx_mib);
778         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
779
780         return rc;
781 }
782
783 static enum _ecore_status_t
784 ecore_dcbx_read_local_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
785 {
786         struct ecore_dcbx_mib_meta_data data;
787         enum _ecore_status_t rc = ECORE_SUCCESS;
788
789         OSAL_MEM_ZERO(&data, sizeof(data));
790         data.addr = p_hwfn->mcp_info->port_addr +
791             offsetof(struct public_port, local_admin_dcbx_mib);
792         data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
793         data.size = sizeof(struct dcbx_local_params);
794         ecore_memcpy_from(p_hwfn, p_ptt, data.local_admin,
795                           data.addr, data.size);
796
797         return rc;
798 }
799
800 static void
801 ecore_dcbx_read_dscp_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
802 {
803         struct ecore_dcbx_mib_meta_data data;
804
805         data.addr = p_hwfn->mcp_info->port_addr +
806                         offsetof(struct public_port, dcb_dscp_map);
807         data.dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
808         data.size = sizeof(struct dcb_dscp_map);
809         ecore_memcpy_from(p_hwfn, p_ptt, data.dscp_map, data.addr, data.size);
810 }
811
812 static enum _ecore_status_t ecore_dcbx_read_mib(struct ecore_hwfn *p_hwfn,
813                                                 struct ecore_ptt *p_ptt,
814                                                 enum ecore_mib_read_type type)
815 {
816         enum _ecore_status_t rc = ECORE_INVAL;
817
818         switch (type) {
819         case ECORE_DCBX_OPERATIONAL_MIB:
820                 ecore_dcbx_read_dscp_mib(p_hwfn, p_ptt);
821                 rc = ecore_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
822                 break;
823         case ECORE_DCBX_REMOTE_MIB:
824                 rc = ecore_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
825                 break;
826         case ECORE_DCBX_LOCAL_MIB:
827                 rc = ecore_dcbx_read_local_mib(p_hwfn, p_ptt);
828                 break;
829         case ECORE_DCBX_REMOTE_LLDP_MIB:
830                 rc = ecore_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
831                 break;
832         case ECORE_DCBX_LOCAL_LLDP_MIB:
833                 rc = ecore_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
834                 break;
835         default:
836                 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
837         }
838
839         return rc;
840 }
841
842 /*
843  * Read updated MIB.
844  * Reconfigure QM and invoke PF update ramrod command if operational MIB
845  * change is detected.
846  */
847 enum _ecore_status_t
848 ecore_dcbx_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
849                             enum ecore_mib_read_type type)
850 {
851         enum _ecore_status_t rc = ECORE_SUCCESS;
852
853         rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
854         if (rc)
855                 return rc;
856
857         if (type == ECORE_DCBX_OPERATIONAL_MIB) {
858                 ecore_dcbx_get_dscp_params(p_hwfn, p_ptt,
859                                            &p_hwfn->p_dcbx_info->get);
860
861                 rc = ecore_dcbx_process_mib_info(p_hwfn);
862                 if (!rc) {
863                         bool enabled;
864
865                         /* reconfigure tcs of QM queues according
866                          * to negotiation results
867                          */
868                         ecore_qm_reconf(p_hwfn, p_ptt);
869
870                         /* update storm FW with negotiation results */
871                         ecore_sp_pf_update(p_hwfn);
872
873                         /* set eagle enigne 1 flow control workaround
874                          * according to negotiation results
875                          */
876                         enabled = p_hwfn->p_dcbx_info->results.dcbx_enabled;
877                 }
878         }
879         ecore_dcbx_get_params(p_hwfn, p_ptt, &p_hwfn->p_dcbx_info->get, type);
880
881         /* Update the DSCP to TC mapping bit if required */
882         if ((type == ECORE_DCBX_OPERATIONAL_MIB) &&
883             p_hwfn->p_dcbx_info->dscp_nig_update) {
884                 ecore_wr(p_hwfn, p_ptt, NIG_REG_DSCP_TO_TC_MAP_ENABLE, 0x1);
885                 p_hwfn->p_dcbx_info->dscp_nig_update = false;
886         }
887
888         OSAL_DCBX_AEN(p_hwfn, type);
889
890         return rc;
891 }
892
893 enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
894 {
895         enum _ecore_status_t rc = ECORE_SUCCESS;
896
897         p_hwfn->p_dcbx_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
898                                           sizeof(*p_hwfn->p_dcbx_info));
899         if (!p_hwfn->p_dcbx_info) {
900                 DP_NOTICE(p_hwfn, true,
901                           "Failed to allocate `struct ecore_dcbx_info'");
902                 rc = ECORE_NOMEM;
903         }
904
905         return rc;
906 }
907
908 void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn,
909                           struct ecore_dcbx_info *p_dcbx_info)
910 {
911         OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
912 }
913
914 static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
915                                             struct ecore_dcbx_results *p_src,
916                                             enum dcbx_protocol_type type)
917 {
918         p_data->dcb_enable_flag = p_src->arr[type].enable;
919         p_data->dcb_priority = p_src->arr[type].priority;
920         p_data->dcb_tc = p_src->arr[type].tc;
921         p_data->dscp_enable_flag = p_src->arr[type].dscp_enable;
922         p_data->dscp_val = p_src->arr[type].dscp_val;
923 }
924
925 /* Set pf update ramrod command params */
926 void ecore_dcbx_set_pf_update_params(struct ecore_dcbx_results *p_src,
927                                      struct pf_update_ramrod_data *p_dest)
928 {
929         struct protocol_dcb_data *p_dcb_data;
930         bool update_flag = false;
931
932         p_dest->pf_id = p_src->pf_id;
933
934         update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
935         p_dest->update_eth_dcb_data_flag = update_flag;
936
937         p_dcb_data = &p_dest->eth_dcb_data;
938         ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
939 }
940
941 enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
942                                              struct ecore_dcbx_get *p_get,
943                                              enum ecore_mib_read_type type)
944 {
945         struct ecore_ptt *p_ptt;
946         enum _ecore_status_t rc;
947
948         if (IS_VF(p_hwfn->p_dev))
949                 return ECORE_INVAL;
950
951         p_ptt = ecore_ptt_acquire(p_hwfn);
952         if (!p_ptt) {
953                 rc = ECORE_TIMEOUT;
954                 DP_ERR(p_hwfn, "rc = %d\n", rc);
955                 return rc;
956         }
957
958         rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
959         if (rc != ECORE_SUCCESS)
960                 goto out;
961
962         rc = ecore_dcbx_get_params(p_hwfn, p_ptt, p_get, type);
963
964 out:
965         ecore_ptt_release(p_hwfn, p_ptt);
966         return rc;
967 }
968
969 static void
970 ecore_dcbx_set_pfc_data(struct ecore_hwfn *p_hwfn,
971                         u32 *pfc, struct ecore_dcbx_params *p_params)
972 {
973         u8 pfc_map = 0;
974         int i;
975
976         if (p_params->pfc.willing)
977                 *pfc |= DCBX_PFC_WILLING_MASK;
978         else
979                 *pfc &= ~DCBX_PFC_WILLING_MASK;
980
981         if (p_params->pfc.enabled)
982                 *pfc |= DCBX_PFC_ENABLED_MASK;
983         else
984                 *pfc &= ~DCBX_PFC_ENABLED_MASK;
985
986         *pfc &= ~DCBX_PFC_CAPS_MASK;
987         *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
988
989         for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++)
990                 if (p_params->pfc.prio[i])
991                         pfc_map |= (1 << i);
992         *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
993         *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
994
995         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "pfc = 0x%x\n", *pfc);
996 }
997
998 static void
999 ecore_dcbx_set_ets_data(struct ecore_hwfn *p_hwfn,
1000                         struct dcbx_ets_feature *p_ets,
1001                         struct ecore_dcbx_params *p_params)
1002 {
1003         u8 *bw_map, *tsa_map;
1004         u32 val;
1005         int i;
1006
1007         if (p_params->ets_willing)
1008                 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1009         else
1010                 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1011
1012         if (p_params->ets_cbs)
1013                 p_ets->flags |= DCBX_ETS_CBS_MASK;
1014         else
1015                 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1016
1017         if (p_params->ets_enabled)
1018                 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1019         else
1020                 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1021
1022         p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1023         p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
1024
1025         bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1026         tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1027         p_ets->pri_tc_tbl[0] = 0;
1028         for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
1029                 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1030                 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1031                 /* Copy the priority value to the corresponding 4 bits in the
1032                  * traffic class table.
1033                  */
1034                 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1035                 p_ets->pri_tc_tbl[0] |= val;
1036         }
1037         for (i = 0; i < 2; i++) {
1038                 p_ets->tc_bw_tbl[i] = OSAL_CPU_TO_BE32(p_ets->tc_bw_tbl[i]);
1039                 p_ets->tc_tsa_tbl[i] = OSAL_CPU_TO_BE32(p_ets->tc_tsa_tbl[i]);
1040         }
1041 }
1042
1043 static void
1044 ecore_dcbx_set_app_data(struct ecore_hwfn *p_hwfn,
1045                         struct dcbx_app_priority_feature *p_app,
1046                         struct ecore_dcbx_params *p_params, bool ieee)
1047 {
1048         u32 *entry;
1049         int i;
1050
1051         if (p_params->app_willing)
1052                 p_app->flags |= DCBX_APP_WILLING_MASK;
1053         else
1054                 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1055
1056         if (p_params->app_valid)
1057                 p_app->flags |= DCBX_APP_ENABLED_MASK;
1058         else
1059                 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1060
1061         p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1062         p_app->flags |= (u32)p_params->num_app_entries <<
1063                                         DCBX_APP_NUM_ENTRIES_SHIFT;
1064
1065         for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
1066                 entry = &p_app->app_pri_tbl[i].entry;
1067                 *entry = 0;
1068                 if (ieee) {
1069                         *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1070                         switch (p_params->app_entry[i].sf_ieee) {
1071                         case ECORE_DCBX_SF_IEEE_ETHTYPE:
1072                                 *entry  |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1073                                             DCBX_APP_SF_IEEE_SHIFT);
1074                                 *entry  |= ((u32)DCBX_APP_SF_ETHTYPE <<
1075                                             DCBX_APP_SF_SHIFT);
1076                                 break;
1077                         case ECORE_DCBX_SF_IEEE_TCP_PORT:
1078                                 *entry  |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1079                                             DCBX_APP_SF_IEEE_SHIFT);
1080                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1081                                             DCBX_APP_SF_SHIFT);
1082                                 break;
1083                         case ECORE_DCBX_SF_IEEE_UDP_PORT:
1084                                 *entry  |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1085                                             DCBX_APP_SF_IEEE_SHIFT);
1086                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1087                                             DCBX_APP_SF_SHIFT);
1088                                 break;
1089                         case ECORE_DCBX_SF_IEEE_TCP_UDP_PORT:
1090                                 *entry  |= (u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1091                                             DCBX_APP_SF_IEEE_SHIFT;
1092                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1093                                             DCBX_APP_SF_SHIFT);
1094                                 break;
1095                         }
1096                 } else {
1097                         *entry &= ~DCBX_APP_SF_MASK;
1098                         if (p_params->app_entry[i].ethtype)
1099                                 *entry  |= ((u32)DCBX_APP_SF_ETHTYPE <<
1100                                             DCBX_APP_SF_SHIFT);
1101                         else
1102                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1103                                             DCBX_APP_SF_SHIFT);
1104                 }
1105                 *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
1114 static enum _ecore_status_t
1115 ecore_dcbx_set_local_params(struct ecore_hwfn *p_hwfn,
1116                             struct dcbx_local_params *local_admin,
1117                             struct ecore_dcbx_set *params)
1118 {
1119         bool ieee = false;
1120
1121         local_admin->flags = 0;
1122         OSAL_MEMCPY(&local_admin->features,
1123                     &p_hwfn->p_dcbx_info->operational.features,
1124                     sizeof(local_admin->features));
1125
1126         if (params->enabled) {
1127                 local_admin->config = params->ver_num;
1128                 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1129         } else {
1130                 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1131         }
1132
1133         if (params->override_flags & ECORE_DCBX_OVERRIDE_PFC_CFG)
1134                 ecore_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1135                                         &params->config.params);
1136
1137         if (params->override_flags & ECORE_DCBX_OVERRIDE_ETS_CFG)
1138                 ecore_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1139                                         &params->config.params);
1140
1141         if (params->override_flags & ECORE_DCBX_OVERRIDE_APP_CFG)
1142                 ecore_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1143                                         &params->config.params, ieee);
1144
1145         return ECORE_SUCCESS;
1146 }
1147
1148 static enum _ecore_status_t
1149 ecore_dcbx_set_dscp_params(struct ecore_hwfn *p_hwfn,
1150                            struct dcb_dscp_map *p_dscp_map,
1151                            struct ecore_dcbx_set *p_params)
1152 {
1153         int entry, i, j;
1154         u32 val;
1155
1156         OSAL_MEMCPY(p_dscp_map, &p_hwfn->p_dcbx_info->dscp_map,
1157                     sizeof(*p_dscp_map));
1158
1159         p_dscp_map->flags &= ~DCB_DSCP_ENABLE_MASK;
1160         if (p_params->dscp.enabled)
1161                 p_dscp_map->flags |= DCB_DSCP_ENABLE_MASK;
1162
1163         for (i = 0, entry = 0; i < 8; i++) {
1164                 val = 0;
1165                 for (j = 0; j < 8; j++, entry++)
1166                         val |= (((u32)p_params->dscp.dscp_pri_map[entry]) <<
1167                                 (j * 4));
1168
1169                 p_dscp_map->dscp_pri_map[i] = OSAL_CPU_TO_BE32(val);
1170         }
1171
1172         p_hwfn->p_dcbx_info->dscp_nig_update = true;
1173
1174         return ECORE_SUCCESS;
1175 }
1176
1177 enum _ecore_status_t ecore_dcbx_config_params(struct ecore_hwfn *p_hwfn,
1178                                               struct ecore_ptt *p_ptt,
1179                                               struct ecore_dcbx_set *params,
1180                                               bool hw_commit)
1181 {
1182         struct dcbx_local_params local_admin;
1183         struct ecore_dcbx_mib_meta_data data;
1184         struct dcb_dscp_map dscp_map;
1185         u32 resp = 0, param = 0;
1186         enum _ecore_status_t rc = ECORE_SUCCESS;
1187
1188         if (!hw_commit) {
1189                 OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set, params,
1190                             sizeof(p_hwfn->p_dcbx_info->set));
1191                 return ECORE_SUCCESS;
1192         }
1193
1194         /* clear set-parmas cache */
1195         OSAL_MEMSET(&p_hwfn->p_dcbx_info->set, 0,
1196                     sizeof(struct ecore_dcbx_set));
1197
1198         OSAL_MEMSET(&local_admin, 0, sizeof(local_admin));
1199         ecore_dcbx_set_local_params(p_hwfn, &local_admin, params);
1200
1201         data.addr = p_hwfn->mcp_info->port_addr +
1202                         offsetof(struct public_port, local_admin_dcbx_mib);
1203         data.local_admin = &local_admin;
1204         data.size = sizeof(struct dcbx_local_params);
1205         ecore_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1206
1207         if (params->override_flags & ECORE_DCBX_OVERRIDE_DSCP_CFG) {
1208                 OSAL_MEMSET(&dscp_map, 0, sizeof(dscp_map));
1209                 ecore_dcbx_set_dscp_params(p_hwfn, &dscp_map, params);
1210
1211                 data.addr = p_hwfn->mcp_info->port_addr +
1212                                 offsetof(struct public_port, dcb_dscp_map);
1213                 data.dscp_map = &dscp_map;
1214                 data.size = sizeof(struct dcb_dscp_map);
1215                 ecore_memcpy_to(p_hwfn, p_ptt, data.addr, data.dscp_map,
1216                                 data.size);
1217         }
1218
1219         rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1220                            1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
1221         if (rc != ECORE_SUCCESS) {
1222                 DP_NOTICE(p_hwfn, false,
1223                           "Failed to send DCBX update request\n");
1224                 return rc;
1225         }
1226
1227         return rc;
1228 }
1229
1230 enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
1231                                                   struct ecore_dcbx_set *params)
1232 {
1233         struct ecore_dcbx_get *dcbx_info;
1234         int rc;
1235
1236         if (p_hwfn->p_dcbx_info->set.config.valid) {
1237                 OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
1238                             sizeof(struct ecore_dcbx_set));
1239                 return ECORE_SUCCESS;
1240         }
1241
1242         dcbx_info = OSAL_ALLOC(p_hwfn->p_dev, GFP_KERNEL,
1243                                sizeof(*dcbx_info));
1244         if (!dcbx_info) {
1245                 DP_ERR(p_hwfn, "Failed to allocate struct ecore_dcbx_info\n");
1246                 return ECORE_NOMEM;
1247         }
1248
1249         OSAL_MEMSET(dcbx_info, 0, sizeof(*dcbx_info));
1250         rc = ecore_dcbx_query_params(p_hwfn, dcbx_info,
1251                                      ECORE_DCBX_OPERATIONAL_MIB);
1252         if (rc) {
1253                 OSAL_FREE(p_hwfn->p_dev, dcbx_info);
1254                 return rc;
1255         }
1256         p_hwfn->p_dcbx_info->set.override_flags = 0;
1257
1258         p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1259         if (dcbx_info->operational.cee)
1260                 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1261         if (dcbx_info->operational.ieee)
1262                 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1263         if (dcbx_info->operational.local)
1264                 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1265
1266         p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1267         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.config.params,
1268                     &dcbx_info->operational.params,
1269                     sizeof(struct ecore_dcbx_admin_params));
1270         p_hwfn->p_dcbx_info->set.config.valid = true;
1271
1272         OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
1273                     sizeof(struct ecore_dcbx_set));
1274
1275         OSAL_FREE(p_hwfn->p_dev, dcbx_info);
1276
1277         return ECORE_SUCCESS;
1278 }