Imported Upstream version 16.07-rc1
[deb_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
17 #define ECORE_DCBX_MAX_MIB_READ_TRY     (100)
18 #define ECORE_MAX_PFC_PRIORITIES        8
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)(pri_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) ? true : false;
33 }
34
35 static bool ecore_dcbx_app_port(u32 app_info_bitmap)
36 {
37         return (ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
38                 DCBX_APP_SF_PORT) ? true : false;
39 }
40
41 static bool ecore_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id)
42 {
43         return (ecore_dcbx_app_ethtype(app_info_bitmap) &&
44                 proto_id == ECORE_ETH_TYPE_DEFAULT) ? true : false;
45 }
46
47 static bool ecore_dcbx_enabled(u32 dcbx_cfg_bitmap)
48 {
49         return (ECORE_MFW_GET_FIELD(dcbx_cfg_bitmap, DCBX_CONFIG_VERSION) ==
50                 DCBX_CONFIG_VERSION_DISABLED) ? false : true;
51 }
52
53 static bool ecore_dcbx_cee(u32 dcbx_cfg_bitmap)
54 {
55         return (ECORE_MFW_GET_FIELD(dcbx_cfg_bitmap, DCBX_CONFIG_VERSION) ==
56                 DCBX_CONFIG_VERSION_CEE) ? true : false;
57 }
58
59 static bool ecore_dcbx_ieee(u32 dcbx_cfg_bitmap)
60 {
61         return (ECORE_MFW_GET_FIELD(dcbx_cfg_bitmap, DCBX_CONFIG_VERSION) ==
62                 DCBX_CONFIG_VERSION_IEEE) ? true : false;
63 }
64
65 /* @@@TBD A0 Eagle workaround */
66 void ecore_dcbx_eagle_workaround(struct ecore_hwfn *p_hwfn,
67                                  struct ecore_ptt *p_ptt, bool set_to_pfc)
68 {
69         if (!ENABLE_EAGLE_ENG1_WORKAROUND(p_hwfn))
70                 return;
71
72         ecore_wr(p_hwfn, p_ptt,
73                  YSEM_REG_FAST_MEMORY + 0x20000 /* RAM in FASTMEM */  +
74                  YSTORM_FLOW_CONTROL_MODE_OFFSET,
75                  set_to_pfc ? flow_ctrl_pfc : flow_ctrl_pause);
76         ecore_wr(p_hwfn, p_ptt, NIG_REG_FLOWCTRL_MODE,
77                  EAGLE_ENG1_WORKAROUND_NIG_FLOWCTRL_MODE);
78 }
79
80 static void
81 ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
82                        struct ecore_dcbx_results *p_data)
83 {
84         struct ecore_hw_info *p_info = &p_hwfn->hw_info;
85         enum dcbx_protocol_type id;
86         bool enable, update;
87         u8 prio, tc, size;
88         const char *name;       /* @DPDK */
89         int i;
90
91         size = OSAL_ARRAY_SIZE(ecore_dcbx_app_update);
92
93         DP_INFO(p_hwfn, "DCBX negotiated: %d\n", p_data->dcbx_enabled);
94
95         for (i = 0; i < size; i++) {
96                 id = ecore_dcbx_app_update[i].id;
97                 name = ecore_dcbx_app_update[i].name;
98
99                 enable = p_data->arr[id].enable;
100                 update = p_data->arr[id].update;
101                 tc = p_data->arr[id].tc;
102                 prio = p_data->arr[id].priority;
103
104                 DP_INFO(p_hwfn,
105                         "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
106                         name, update, enable, prio, tc, p_info->num_tc);
107         }
108 }
109
110 static void
111 ecore_dcbx_set_pf_tcs(struct ecore_hw_info *p_info,
112                       u8 tc, enum ecore_pci_personality personality)
113 {
114         /* QM reconf data */
115         if (p_info->personality == personality) {
116                 if (personality == ECORE_PCI_ETH)
117                         p_info->non_offload_tc = tc;
118                 else
119                         p_info->offload_tc = tc;
120         }
121 }
122
123 void
124 ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
125                       struct ecore_hw_info *p_info,
126                       bool enable, bool update, u8 prio, u8 tc,
127                       enum dcbx_protocol_type type,
128                       enum ecore_pci_personality personality)
129 {
130         /* PF update ramrod data */
131         p_data->arr[type].update = update;
132         p_data->arr[type].enable = enable;
133         p_data->arr[type].priority = prio;
134         p_data->arr[type].tc = tc;
135
136         ecore_dcbx_set_pf_tcs(p_info, tc, personality);
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         struct ecore_hw_info *p_info = &p_hwfn->hw_info;
147         enum ecore_pci_personality personality;
148         enum dcbx_protocol_type id;
149         const char *name;       /* @DPDK */
150         u8 size;
151         int i;
152
153         size = OSAL_ARRAY_SIZE(ecore_dcbx_app_update);
154
155         for (i = 0; i < size; i++) {
156                 id = ecore_dcbx_app_update[i].id;
157
158                 if (type != id)
159                         continue;
160
161                 personality = ecore_dcbx_app_update[i].personality;
162                 name = ecore_dcbx_app_update[i].name;
163
164                 ecore_dcbx_set_params(p_data, p_info, enable, update,
165                                       prio, tc, type, personality);
166         }
167 }
168
169 static enum _ecore_status_t
170 ecore_dcbx_get_app_priority(u8 pri_bitmap, u8 *priority)
171 {
172         u32 pri_mask, pri = ECORE_MAX_PFC_PRIORITIES;
173         u32 index = ECORE_MAX_PFC_PRIORITIES - 1;
174         enum _ecore_status_t rc = ECORE_SUCCESS;
175
176         /* Bitmap 1 corresponds to priority 0, return priority 0 */
177         if (pri_bitmap == 1) {
178                 *priority = 0;
179                 return rc;
180         }
181
182         /* Choose the highest priority */
183         while ((pri == ECORE_MAX_PFC_PRIORITIES) && index) {
184                 pri_mask = 1 << index;
185                 if (pri_bitmap & pri_mask)
186                         pri = index;
187                 index--;
188         }
189
190         if (pri < ECORE_MAX_PFC_PRIORITIES)
191                 *priority = (u8)pri;
192         else
193                 rc = ECORE_INVAL;
194
195         return rc;
196 }
197
198 static bool
199 ecore_dcbx_get_app_protocol_type(struct ecore_hwfn *p_hwfn,
200                                  u32 app_prio_bitmap, u16 id, int *type)
201 {
202         bool status = false;
203
204         if (ecore_dcbx_default_tlv(app_prio_bitmap, id)) {
205                 *type = DCBX_PROTOCOL_ETH;
206                 status = true;
207         } else {
208                 DP_ERR(p_hwfn, "Unsupported protocol %d\n", id);
209         }
210
211         return status;
212 }
213
214 /*  Parse app TLV's to update TC information in hw_info structure for
215  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
216  */
217 static enum _ecore_status_t
218 ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
219                        struct ecore_dcbx_results *p_data,
220                        struct dcbx_app_priority_entry *p_tbl, u32 pri_tc_tbl,
221                        int count, bool dcbx_enabled)
222 {
223         enum _ecore_status_t rc = ECORE_SUCCESS;
224         u8 tc, priority, priority_map;
225         int i, type = -1;
226         u16 protocol_id;
227         bool enable;
228
229         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Num APP entries = %d\n", count);
230
231         /* Parse APP TLV */
232         for (i = 0; i < count; i++) {
233                 protocol_id = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
234                                                   DCBX_APP_PROTOCOL_ID);
235                 priority_map = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
236                                                    DCBX_APP_PRI_MAP);
237                 rc = ecore_dcbx_get_app_priority(priority_map, &priority);
238                 if (rc == ECORE_INVAL) {
239                         DP_ERR(p_hwfn, "Invalid priority\n");
240                         return rc;
241                 }
242
243                 tc = ECORE_DCBX_PRIO2TC(pri_tc_tbl, priority);
244                 if (ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
245                                                      protocol_id, &type)) {
246                         /* ETH always have the enable bit reset, as it gets
247                          * vlan information per packet. For other protocols,
248                          * should be set according to the dcbx_enabled
249                          * indication, but we only got here if there was an
250                          * app tlv for the protocol, so dcbx must be enabled.
251                          */
252                         enable = (type == DCBX_PROTOCOL_ETH ? false : true);
253
254                         ecore_dcbx_update_app_info(p_data, p_hwfn, enable, true,
255                                                    priority, tc, type);
256                 }
257         }
258         /* Update ramrod protocol data and hw_info fields
259          * with default info when corresponding APP TLV's are not detected.
260          * The enabled field has a different logic for ethernet as only for
261          * ethernet dcb should disabled by default, as the information arrives
262          * from the OS (unless an explicit app tlv was present).
263          */
264         tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
265         priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
266         for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
267                 if (p_data->arr[type].update)
268                         continue;
269
270                 enable = (type == DCBX_PROTOCOL_ETH) ? false : dcbx_enabled;
271                 ecore_dcbx_update_app_info(p_data, p_hwfn, enable, true,
272                                            priority, tc, type);
273         }
274
275         return ECORE_SUCCESS;
276 }
277
278 /* Parse app TLV's to update TC information in hw_info structure for
279  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
280  */
281 static enum _ecore_status_t
282 ecore_dcbx_process_mib_info(struct ecore_hwfn *p_hwfn)
283 {
284         struct dcbx_app_priority_feature *p_app;
285         enum _ecore_status_t rc = ECORE_SUCCESS;
286         struct ecore_dcbx_results data = { 0 };
287         struct dcbx_app_priority_entry *p_tbl;
288         struct dcbx_ets_feature *p_ets;
289         struct ecore_hw_info *p_info;
290         u32 pri_tc_tbl, flags;
291         bool dcbx_enabled;
292         int num_entries;
293
294         /* If DCBx version is non zero, then negotiation was
295          * successfuly performed
296          */
297         flags = p_hwfn->p_dcbx_info->operational.flags;
298         dcbx_enabled = ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) != 0;
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_enabled);
311         if (rc != ECORE_SUCCESS)
312                 return rc;
313
314         p_info->num_tc = ECORE_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
315         data.pf_id = p_hwfn->rel_pf_id;
316         data.dcbx_enabled = dcbx_enabled;
317
318         ecore_dcbx_dp_protocol(p_hwfn, &data);
319
320         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->results, &data,
321                     sizeof(struct ecore_dcbx_results));
322
323         return ECORE_SUCCESS;
324 }
325
326 static enum _ecore_status_t
327 ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
328                     struct ecore_ptt *p_ptt,
329                     struct ecore_dcbx_mib_meta_data *p_data,
330                     enum ecore_mib_read_type type)
331 {
332         enum _ecore_status_t rc = ECORE_SUCCESS;
333         u32 prefix_seq_num, suffix_seq_num;
334         int read_count = 0;
335
336         do {
337                 if (type == ECORE_DCBX_REMOTE_LLDP_MIB) {
338                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
339                                           p_data->addr, p_data->size);
340                         prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
341                         suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
342                 } else {
343                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
344                                           p_data->addr, p_data->size);
345                         prefix_seq_num = p_data->mib->prefix_seq_num;
346                         suffix_seq_num = p_data->mib->suffix_seq_num;
347                 }
348                 read_count++;
349
350                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
351                            "mib type = %d, try count = %d prefix seq num  = %d suffix seq num = %d\n",
352                            type, read_count, prefix_seq_num, suffix_seq_num);
353         } while ((prefix_seq_num != suffix_seq_num) &&
354                  (read_count < ECORE_DCBX_MAX_MIB_READ_TRY));
355
356         if (read_count >= ECORE_DCBX_MAX_MIB_READ_TRY) {
357                 DP_ERR(p_hwfn,
358                        "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
359                        type, read_count, prefix_seq_num, suffix_seq_num);
360                 rc = ECORE_IO;
361         }
362
363         return rc;
364 }
365
366 static enum _ecore_status_t
367 ecore_dcbx_get_priority_info(struct ecore_hwfn *p_hwfn,
368                              struct ecore_dcbx_app_prio *p_prio,
369                              struct ecore_dcbx_results *p_results)
370 {
371         enum _ecore_status_t rc = ECORE_SUCCESS;
372
373         if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
374             p_results->arr[DCBX_PROTOCOL_ETH].enable) {
375                 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
376                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
377                            "Priority: eth %d\n", p_prio->eth);
378         }
379
380         return rc;
381 }
382
383 static void
384 ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
385                         struct dcbx_app_priority_feature *p_app,
386                         struct dcbx_app_priority_entry *p_tbl,
387                         struct ecore_dcbx_params *p_params)
388 {
389         int i;
390
391         p_params->app_willing = ECORE_MFW_GET_FIELD(p_app->flags,
392                                                     DCBX_APP_WILLING);
393         p_params->app_valid = ECORE_MFW_GET_FIELD(p_app->flags,
394                                                   DCBX_APP_ENABLED);
395         p_params->num_app_entries = ECORE_MFW_GET_FIELD(p_app->flags,
396                                                         DCBX_APP_ENABLED);
397         for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++)
398                 p_params->app_bitmap[i] = p_tbl[i].entry;
399
400         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
401                    "APP params: willing %d, valid %d\n",
402                    p_params->app_willing, p_params->app_valid);
403 }
404
405 static void
406 ecore_dcbx_get_pfc_data(struct ecore_hwfn *p_hwfn,
407                         u32 pfc, struct ecore_dcbx_params *p_params)
408 {
409         p_params->pfc_willing = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
410         p_params->max_pfc_tc = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
411         p_params->pfc_enabled = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
412         p_params->pfc_bitmap = pfc;
413
414         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
415                    "PFC params: willing %d, pfc_bitmap %d\n",
416                    p_params->pfc_willing, p_params->pfc_bitmap);
417 }
418
419 static void
420 ecore_dcbx_get_ets_data(struct ecore_hwfn *p_hwfn,
421                         struct dcbx_ets_feature *p_ets,
422                         struct ecore_dcbx_params *p_params)
423 {
424         int i;
425
426         p_params->ets_willing = ECORE_MFW_GET_FIELD(p_ets->flags,
427                                                     DCBX_ETS_WILLING);
428         p_params->ets_enabled = ECORE_MFW_GET_FIELD(p_ets->flags,
429                                                     DCBX_ETS_ENABLED);
430         p_params->max_ets_tc = ECORE_MFW_GET_FIELD(p_ets->flags,
431                                                    DCBX_ETS_MAX_TCS);
432         p_params->ets_pri_tc_tbl[0] = p_ets->pri_tc_tbl[0];
433
434         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
435                    "ETS params: willing %d, pri_tc_tbl_0 %x max_ets_tc %d\n",
436                    p_params->ets_willing, p_params->ets_pri_tc_tbl[0],
437                    p_params->max_ets_tc);
438
439         /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
440          * encoded in a type u32 array of size 2.
441          */
442         for (i = 0; i < 2; i++) {
443                 p_params->ets_tc_tsa_tbl[i] = p_ets->tc_tsa_tbl[i];
444                 p_params->ets_tc_bw_tbl[i] = p_ets->tc_bw_tbl[i];
445
446                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
447                            "elem %d  bw_tbl %x tsa_tbl %x\n",
448                            i, p_params->ets_tc_bw_tbl[i],
449                            p_params->ets_tc_tsa_tbl[i]);
450         }
451 }
452
453 static enum _ecore_status_t
454 ecore_dcbx_get_common_params(struct ecore_hwfn *p_hwfn,
455                              struct dcbx_app_priority_feature *p_app,
456                              struct dcbx_app_priority_entry *p_tbl,
457                              struct dcbx_ets_feature *p_ets,
458                              u32 pfc, struct ecore_dcbx_params *p_params)
459 {
460         ecore_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params);
461         ecore_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
462         ecore_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
463
464         return ECORE_SUCCESS;
465 }
466
467 static enum _ecore_status_t
468 ecore_dcbx_get_local_params(struct ecore_hwfn *p_hwfn,
469                             struct ecore_ptt *p_ptt,
470                             struct ecore_dcbx_get *params)
471 {
472         struct ecore_dcbx_admin_params *p_local;
473         struct dcbx_app_priority_feature *p_app;
474         struct dcbx_app_priority_entry *p_tbl;
475         struct ecore_dcbx_params *p_data;
476         struct dcbx_ets_feature *p_ets;
477         u32 pfc;
478
479         p_local = &params->local;
480         p_data = &p_local->params;
481         p_app = &p_hwfn->p_dcbx_info->local_admin.features.app;
482         p_tbl = p_app->app_pri_tbl;
483         p_ets = &p_hwfn->p_dcbx_info->local_admin.features.ets;
484         pfc = p_hwfn->p_dcbx_info->local_admin.features.pfc;
485
486         ecore_dcbx_get_common_params(p_hwfn, p_app, p_tbl, p_ets, pfc, p_data);
487         p_local->valid = true;
488
489         return ECORE_SUCCESS;
490 }
491
492 static enum _ecore_status_t
493 ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
494                              struct ecore_ptt *p_ptt,
495                              struct ecore_dcbx_get *params)
496 {
497         struct ecore_dcbx_remote_params *p_remote;
498         struct dcbx_app_priority_feature *p_app;
499         struct dcbx_app_priority_entry *p_tbl;
500         struct ecore_dcbx_params *p_data;
501         struct dcbx_ets_feature *p_ets;
502         u32 pfc;
503
504         p_remote = &params->remote;
505         p_data = &p_remote->params;
506         p_app = &p_hwfn->p_dcbx_info->remote.features.app;
507         p_tbl = p_app->app_pri_tbl;
508         p_ets = &p_hwfn->p_dcbx_info->remote.features.ets;
509         pfc = p_hwfn->p_dcbx_info->remote.features.pfc;
510
511         ecore_dcbx_get_common_params(p_hwfn, p_app, p_tbl, p_ets, pfc, p_data);
512         p_remote->valid = true;
513
514         return ECORE_SUCCESS;
515 }
516
517 static enum _ecore_status_t
518 ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
519                                   struct ecore_ptt *p_ptt,
520                                   struct ecore_dcbx_get *params)
521 {
522         struct ecore_dcbx_operational_params *p_operational;
523         enum _ecore_status_t rc = ECORE_SUCCESS;
524         struct dcbx_app_priority_feature *p_app;
525         struct dcbx_app_priority_entry *p_tbl;
526         struct ecore_dcbx_results *p_results;
527         struct ecore_dcbx_params *p_data;
528         struct dcbx_ets_feature *p_ets;
529         bool enabled, err;
530         u32 pfc, flags;
531
532         flags = p_hwfn->p_dcbx_info->operational.flags;
533
534         /* If DCBx version is non zero, then negotiation
535          * was successfuly performed
536          */
537         p_operational = &params->operational;
538         enabled = ecore_dcbx_enabled(flags);
539         if (!enabled) {
540                 p_operational->enabled = enabled;
541                 p_operational->valid = false;
542                 return ECORE_INVAL;
543         }
544
545         p_data = &p_operational->params;
546         p_results = &p_hwfn->p_dcbx_info->results;
547         p_app = &p_hwfn->p_dcbx_info->operational.features.app;
548         p_tbl = p_app->app_pri_tbl;
549         p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
550         pfc = p_hwfn->p_dcbx_info->operational.features.pfc;
551
552         p_operational->ieee = ecore_dcbx_ieee(flags);
553         p_operational->cee = ecore_dcbx_cee(flags);
554
555         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
556                    "Version support: ieee %d, cee %d\n",
557                    p_operational->ieee, p_operational->cee);
558
559         ecore_dcbx_get_common_params(p_hwfn, p_app, p_tbl, p_ets, pfc, p_data);
560         ecore_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio,
561                                      p_results);
562         err = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
563         p_operational->err = err;
564         p_operational->enabled = enabled;
565         p_operational->valid = true;
566
567         return rc;
568 }
569
570 static enum _ecore_status_t
571 ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
572                                  struct ecore_ptt *p_ptt,
573                                  struct ecore_dcbx_get *params)
574 {
575         struct ecore_dcbx_lldp_local *p_local;
576         osal_size_t size;
577         u32 *dest;
578
579         p_local = &params->lldp_local;
580
581         size = OSAL_ARRAY_SIZE(p_local->local_chassis_id);
582         dest = p_hwfn->p_dcbx_info->get.lldp_local.local_chassis_id;
583         OSAL_MEMCPY(dest, p_local->local_chassis_id, size);
584
585         size = OSAL_ARRAY_SIZE(p_local->local_port_id);
586         dest = p_hwfn->p_dcbx_info->get.lldp_local.local_port_id;
587         OSAL_MEMCPY(dest, p_local->local_port_id, size);
588
589         return ECORE_SUCCESS;
590 }
591
592 static enum _ecore_status_t
593 ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
594                                   struct ecore_ptt *p_ptt,
595                                   struct ecore_dcbx_get *params)
596 {
597         struct ecore_dcbx_lldp_remote *p_remote;
598         osal_size_t size;
599         u32 *dest;
600
601         p_remote = &params->lldp_remote;
602
603         size = OSAL_ARRAY_SIZE(p_remote->peer_chassis_id);
604         dest = p_hwfn->p_dcbx_info->get.lldp_remote.peer_chassis_id;
605         OSAL_MEMCPY(dest, p_remote->peer_chassis_id, size);
606
607         size = OSAL_ARRAY_SIZE(p_remote->peer_port_id);
608         dest = p_hwfn->p_dcbx_info->get.lldp_remote.peer_port_id;
609         OSAL_MEMCPY(dest, p_remote->peer_port_id, size);
610
611         return ECORE_SUCCESS;
612 }
613
614 static enum _ecore_status_t
615 ecore_dcbx_get_params(struct ecore_hwfn *p_hwfn,
616                       struct ecore_ptt *p_ptt, enum ecore_mib_read_type type)
617 {
618         enum _ecore_status_t rc = ECORE_SUCCESS;
619         struct ecore_dcbx_get *p_params;
620
621         p_params = &p_hwfn->p_dcbx_info->get;
622
623         switch (type) {
624         case ECORE_DCBX_REMOTE_MIB:
625                 ecore_dcbx_get_remote_params(p_hwfn, p_ptt, p_params);
626                 break;
627         case ECORE_DCBX_LOCAL_MIB:
628                 ecore_dcbx_get_local_params(p_hwfn, p_ptt, p_params);
629                 break;
630         case ECORE_DCBX_OPERATIONAL_MIB:
631                 ecore_dcbx_get_operational_params(p_hwfn, p_ptt, p_params);
632                 break;
633         case ECORE_DCBX_REMOTE_LLDP_MIB:
634                 rc = ecore_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params);
635                 break;
636         case ECORE_DCBX_LOCAL_LLDP_MIB:
637                 rc = ecore_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params);
638                 break;
639         default:
640                 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
641                 return ECORE_INVAL;
642         }
643
644         return rc;
645 }
646
647 static enum _ecore_status_t
648 ecore_dcbx_read_local_lldp_mib(struct ecore_hwfn *p_hwfn,
649                                struct ecore_ptt *p_ptt)
650 {
651         enum _ecore_status_t rc = ECORE_SUCCESS;
652         struct ecore_dcbx_mib_meta_data data;
653
654         data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
655                                                            lldp_config_params);
656         data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
657         data.size = sizeof(struct lldp_config_params_s);
658         ecore_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
659
660         return rc;
661 }
662
663 static enum _ecore_status_t
664 ecore_dcbx_read_remote_lldp_mib(struct ecore_hwfn *p_hwfn,
665                                 struct ecore_ptt *p_ptt,
666                                 enum ecore_mib_read_type type)
667 {
668         enum _ecore_status_t rc = ECORE_SUCCESS;
669         struct ecore_dcbx_mib_meta_data data;
670
671         data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
672                                                            lldp_status_params);
673         data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
674         data.size = sizeof(struct lldp_status_params_s);
675         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
676
677         return rc;
678 }
679
680 static enum _ecore_status_t
681 ecore_dcbx_read_operational_mib(struct ecore_hwfn *p_hwfn,
682                                 struct ecore_ptt *p_ptt,
683                                 enum ecore_mib_read_type type)
684 {
685         struct ecore_dcbx_mib_meta_data data;
686         enum _ecore_status_t rc = ECORE_SUCCESS;
687
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 = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
693
694         return rc;
695 }
696
697 static enum _ecore_status_t
698 ecore_dcbx_read_remote_mib(struct ecore_hwfn *p_hwfn,
699                            struct ecore_ptt *p_ptt,
700                            enum ecore_mib_read_type type)
701 {
702         struct ecore_dcbx_mib_meta_data data;
703         enum _ecore_status_t rc = ECORE_SUCCESS;
704
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 = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
710
711         return rc;
712 }
713
714 static enum _ecore_status_t
715 ecore_dcbx_read_local_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
716 {
717         struct ecore_dcbx_mib_meta_data data;
718         enum _ecore_status_t rc = ECORE_SUCCESS;
719
720         data.addr = p_hwfn->mcp_info->port_addr +
721             offsetof(struct public_port, local_admin_dcbx_mib);
722         data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
723         data.size = sizeof(struct dcbx_local_params);
724         ecore_memcpy_from(p_hwfn, p_ptt, data.local_admin,
725                           data.addr, data.size);
726
727         return rc;
728 }
729
730 static enum _ecore_status_t ecore_dcbx_read_mib(struct ecore_hwfn *p_hwfn,
731                                                 struct ecore_ptt *p_ptt,
732                                                 enum ecore_mib_read_type type)
733 {
734         enum _ecore_status_t rc = ECORE_SUCCESS;
735
736         switch (type) {
737         case ECORE_DCBX_OPERATIONAL_MIB:
738                 rc = ecore_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
739                 break;
740         case ECORE_DCBX_REMOTE_MIB:
741                 rc = ecore_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
742                 break;
743         case ECORE_DCBX_LOCAL_MIB:
744                 rc = ecore_dcbx_read_local_mib(p_hwfn, p_ptt);
745                 break;
746         case ECORE_DCBX_REMOTE_LLDP_MIB:
747                 rc = ecore_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
748                 break;
749         case ECORE_DCBX_LOCAL_LLDP_MIB:
750                 rc = ecore_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
751                 break;
752         default:
753                 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
754                 return ECORE_INVAL;
755         }
756
757         return rc;
758 }
759
760 /*
761  * Read updated MIB.
762  * Reconfigure QM and invoke PF update ramrod command if operational MIB
763  * change is detected.
764  */
765 enum _ecore_status_t
766 ecore_dcbx_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
767                             enum ecore_mib_read_type type)
768 {
769         enum _ecore_status_t rc = ECORE_SUCCESS;
770
771         rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
772         if (rc)
773                 return rc;
774
775         if (type == ECORE_DCBX_OPERATIONAL_MIB) {
776                 rc = ecore_dcbx_process_mib_info(p_hwfn);
777                 if (!rc) {
778                         bool enabled;
779
780                         /* reconfigure tcs of QM queues according
781                          * to negotiation results
782                          */
783                         ecore_qm_reconf(p_hwfn, p_ptt);
784
785                         /* update storm FW with negotiation results */
786                         ecore_sp_pf_update(p_hwfn);
787
788                         /* set eagle enigne 1 flow control workaround
789                          * according to negotiation results
790                          */
791                         enabled = p_hwfn->p_dcbx_info->results.dcbx_enabled;
792                         ecore_dcbx_eagle_workaround(p_hwfn, p_ptt, enabled);
793                 }
794         }
795         ecore_dcbx_get_params(p_hwfn, p_ptt, type);
796         OSAL_DCBX_AEN(p_hwfn, type);
797
798         return rc;
799 }
800
801 enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
802 {
803         enum _ecore_status_t rc = ECORE_SUCCESS;
804
805         p_hwfn->p_dcbx_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
806                                           sizeof(struct ecore_dcbx_info));
807         if (!p_hwfn->p_dcbx_info) {
808                 DP_NOTICE(p_hwfn, true,
809                           "Failed to allocate `struct ecore_dcbx_info'");
810                 rc = ECORE_NOMEM;
811         }
812
813         return rc;
814 }
815
816 void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn,
817                           struct ecore_dcbx_info *p_dcbx_info)
818 {
819         OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
820 }
821
822 static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
823                                             struct ecore_dcbx_results *p_src,
824                                             enum dcbx_protocol_type type)
825 {
826         p_data->dcb_enable_flag = p_src->arr[type].enable;
827         p_data->dcb_priority = p_src->arr[type].priority;
828         p_data->dcb_tc = p_src->arr[type].tc;
829 }
830
831 /* Set pf update ramrod command params */
832 void ecore_dcbx_set_pf_update_params(struct ecore_dcbx_results *p_src,
833                                      struct pf_update_ramrod_data *p_dest)
834 {
835         struct protocol_dcb_data *p_dcb_data;
836         bool update_flag;
837
838         p_dest->pf_id = p_src->pf_id;
839
840         update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
841         p_dest->update_eth_dcb_data_flag = update_flag;
842
843         p_dcb_data = &p_dest->eth_dcb_data;
844         ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
845 }
846
847 static
848 enum _ecore_status_t ecore_dcbx_query(struct ecore_hwfn *p_hwfn,
849                                       enum ecore_mib_read_type type)
850 {
851         struct ecore_ptt *p_ptt;
852         enum _ecore_status_t rc;
853
854         p_ptt = ecore_ptt_acquire(p_hwfn);
855         if (!p_ptt) {
856                 rc = ECORE_TIMEOUT;
857                 DP_ERR(p_hwfn, "rc = %d\n", rc);
858                 return rc;
859         }
860
861         rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
862         if (rc != ECORE_SUCCESS)
863                 goto out;
864
865         rc = ecore_dcbx_get_params(p_hwfn, p_ptt, type);
866
867 out:
868         ecore_ptt_release(p_hwfn, p_ptt);
869         return rc;
870 }
871
872 enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
873                                              struct ecore_dcbx_get *p_get,
874                                              enum ecore_mib_read_type type)
875 {
876         enum _ecore_status_t rc;
877
878         rc = ecore_dcbx_query(p_hwfn, type);
879         if (rc)
880                 return rc;
881
882         if (p_get != OSAL_NULL)
883                 OSAL_MEMCPY(p_get, &p_hwfn->p_dcbx_info->get,
884                             sizeof(struct ecore_dcbx_get));
885
886         return rc;
887 }