97fd48457b580636a6c863930fa5d9c6fe42f5fd
[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 !!(GET_MFW_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 = GET_MFW_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 !!(GET_MFW_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 = GET_MFW_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 bool ecore_dcbx_iwarp_tlv(struct ecore_hwfn *p_hwfn, u32 app_info_bitmap,
76                                  u16 proto_id, bool ieee)
77 {
78         bool port;
79
80         if (!p_hwfn->p_dcbx_info->iwarp_port)
81                 return false;
82
83         if (ieee)
84                 port = ecore_dcbx_ieee_app_port(app_info_bitmap,
85                                                 DCBX_APP_SF_IEEE_TCP_PORT);
86         else
87                 port = ecore_dcbx_app_port(app_info_bitmap);
88
89         return !!(port && (proto_id == p_hwfn->p_dcbx_info->iwarp_port));
90 }
91
92 static void
93 ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
94                        struct ecore_dcbx_results *p_data)
95 {
96         enum dcbx_protocol_type id;
97         int i;
98
99         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "DCBX negotiated: %d\n",
100                    p_data->dcbx_enabled);
101
102         for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
103                 id = ecore_dcbx_app_update[i].id;
104
105                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
106                            "%s info: update %d, enable %d, prio %d, tc %d,"
107                            " num_active_tc %d dscp_enable = %d dscp_val = %d\n",
108                            ecore_dcbx_app_update[i].name,
109                            p_data->arr[id].update,
110                            p_data->arr[id].enable, p_data->arr[id].priority,
111                            p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc,
112                            p_data->arr[id].dscp_enable,
113                            p_data->arr[id].dscp_val);
114         }
115 }
116
117 u8 ecore_dcbx_get_dscp_value(struct ecore_hwfn *p_hwfn, u8 pri)
118 {
119         struct ecore_dcbx_dscp_params *dscp = &p_hwfn->p_dcbx_info->get.dscp;
120         u8 i;
121
122         if (!dscp->enabled)
123                 return ECORE_DCBX_DSCP_DISABLED;
124
125         for (i = 0; i < ECORE_DCBX_DSCP_SIZE; i++)
126                 if (pri == dscp->dscp_pri_map[i])
127                         return i;
128
129         return ECORE_DCBX_DSCP_DISABLED;
130 }
131
132 static void
133 ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
134                       struct ecore_hwfn *p_hwfn,
135                       bool enable, u8 prio, u8 tc,
136                       enum dcbx_protocol_type type,
137                       enum ecore_pci_personality personality)
138 {
139         /* PF update ramrod data */
140         p_data->arr[type].enable = enable;
141         p_data->arr[type].priority = prio;
142         p_data->arr[type].tc = tc;
143         p_data->arr[type].dscp_val = ecore_dcbx_get_dscp_value(p_hwfn, prio);
144         if (p_data->arr[type].dscp_val == ECORE_DCBX_DSCP_DISABLED) {
145                 p_data->arr[type].dscp_enable = false;
146                 p_data->arr[type].dscp_val = 0;
147         } else {
148                 p_data->arr[type].dscp_enable = true;
149         }
150         p_data->arr[type].update = UPDATE_DCB_DSCP;
151
152         /* QM reconf data */
153         if (p_hwfn->hw_info.personality == personality)
154                 p_hwfn->hw_info.offload_tc = tc;
155 }
156
157 /* Update app protocol data and hw_info fields with the TLV info */
158 static void
159 ecore_dcbx_update_app_info(struct ecore_dcbx_results *p_data,
160                            struct ecore_hwfn *p_hwfn,
161                            bool enable, u8 prio, u8 tc,
162                            enum dcbx_protocol_type type)
163 {
164         enum ecore_pci_personality personality;
165         enum dcbx_protocol_type id;
166         const char *name;       /* @DPDK */
167         int i;
168
169         for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
170                 id = ecore_dcbx_app_update[i].id;
171
172                 if (type != id)
173                         continue;
174
175                 personality = ecore_dcbx_app_update[i].personality;
176                 name = ecore_dcbx_app_update[i].name;
177
178                 ecore_dcbx_set_params(p_data, p_hwfn, enable,
179                                       prio, tc, type, personality);
180         }
181 }
182
183 static enum _ecore_status_t
184 ecore_dcbx_get_app_priority(u8 pri_bitmap, u8 *priority)
185 {
186         u32 pri_mask, pri = ECORE_MAX_PFC_PRIORITIES;
187         u32 index = ECORE_MAX_PFC_PRIORITIES - 1;
188         enum _ecore_status_t rc = ECORE_SUCCESS;
189
190         /* Bitmap 1 corresponds to priority 0, return priority 0 */
191         if (pri_bitmap == 1) {
192                 *priority = 0;
193                 return rc;
194         }
195
196         /* Choose the highest priority */
197         while ((pri == ECORE_MAX_PFC_PRIORITIES) && index) {
198                 pri_mask = 1 << index;
199                 if (pri_bitmap & pri_mask)
200                         pri = index;
201                 index--;
202         }
203
204         if (pri < ECORE_MAX_PFC_PRIORITIES)
205                 *priority = (u8)pri;
206         else
207                 rc = ECORE_INVAL;
208
209         return rc;
210 }
211
212 static bool
213 ecore_dcbx_get_app_protocol_type(struct ecore_hwfn *p_hwfn,
214                                  u32 app_prio_bitmap, u16 id,
215                                  enum dcbx_protocol_type *type, bool ieee)
216 {
217         if (ecore_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
218                 *type = DCBX_PROTOCOL_ETH;
219         } else {
220                 *type = DCBX_MAX_PROTOCOL_TYPE;
221                 DP_ERR(p_hwfn,
222                        "No action required, App TLV id = 0x%x"
223                        " app_prio_bitmap = 0x%x\n",
224                        id, app_prio_bitmap);
225                 return false;
226         }
227
228         return true;
229 }
230
231 /*  Parse app TLV's to update TC information in hw_info structure for
232  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
233  */
234 static enum _ecore_status_t
235 ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
236                        struct ecore_dcbx_results *p_data,
237                        struct dcbx_app_priority_entry *p_tbl, u32 pri_tc_tbl,
238                        int count, u8 dcbx_version)
239 {
240         enum dcbx_protocol_type type;
241         bool enable, ieee, eth_tlv;
242         u8 tc, priority_map;
243         u16 protocol_id;
244         u8 priority;
245         enum _ecore_status_t rc = ECORE_SUCCESS;
246         int i;
247
248         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
249                    "Num APP entries = %d pri_tc_tbl = 0x%x dcbx_version = %u\n",
250                    count, pri_tc_tbl, dcbx_version);
251
252         ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
253         eth_tlv = false;
254         /* Parse APP TLV */
255         for (i = 0; i < count; i++) {
256                 protocol_id = GET_MFW_FIELD(p_tbl[i].entry,
257                                             DCBX_APP_PROTOCOL_ID);
258                 priority_map = GET_MFW_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
259                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Id = 0x%x pri_map = %u\n",
260                            protocol_id, priority_map);
261                 rc = ecore_dcbx_get_app_priority(priority_map, &priority);
262                 if (rc == ECORE_INVAL) {
263                         DP_ERR(p_hwfn, "Invalid priority\n");
264                         return ECORE_INVAL;
265                 }
266
267                 tc = ECORE_DCBX_PRIO2TC(pri_tc_tbl, priority);
268                 if (ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
269                                                      protocol_id, &type,
270                                                      ieee)) {
271                         /* ETH always have the enable bit reset, as it gets
272                          * vlan information per packet. For other protocols,
273                          * should be set according to the dcbx_enabled
274                          * indication, but we only got here if there was an
275                          * app tlv for the protocol, so dcbx must be enabled.
276                          */
277                         if (type == DCBX_PROTOCOL_ETH) {
278                                 enable = false;
279                                 eth_tlv = true;
280                         } else {
281                                 enable = true;
282                         }
283
284                         ecore_dcbx_update_app_info(p_data, p_hwfn, enable,
285                                                    priority, tc, type);
286                 }
287         }
288
289         /* If Eth TLV is not detected, use UFP TC as default TC */
290         if (OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC,
291                           &p_hwfn->p_dev->mf_bits) && !eth_tlv)
292                 p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
293
294         /* Update ramrod protocol data and hw_info fields
295          * with default info when corresponding APP TLV's are not detected.
296          * The enabled field has a different logic for ethernet as only for
297          * ethernet dcb should disabled by default, as the information arrives
298          * from the OS (unless an explicit app tlv was present).
299          */
300         tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
301         priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
302         for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
303                 if (p_data->arr[type].update)
304                         continue;
305
306                 enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
307                 ecore_dcbx_update_app_info(p_data, p_hwfn, enable,
308                                            priority, tc, type);
309         }
310
311         return ECORE_SUCCESS;
312 }
313
314 /* Parse app TLV's to update TC information in hw_info structure for
315  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
316  */
317 static enum _ecore_status_t
318 ecore_dcbx_process_mib_info(struct ecore_hwfn *p_hwfn)
319 {
320         struct dcbx_app_priority_feature *p_app;
321         enum _ecore_status_t rc = ECORE_SUCCESS;
322         struct ecore_dcbx_results data = { 0 };
323         struct dcbx_app_priority_entry *p_tbl;
324         struct dcbx_ets_feature *p_ets;
325         struct ecore_hw_info *p_info;
326         u32 pri_tc_tbl, flags;
327         u8 dcbx_version;
328         int num_entries;
329
330         flags = p_hwfn->p_dcbx_info->operational.flags;
331         dcbx_version = GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION);
332
333         p_app = &p_hwfn->p_dcbx_info->operational.features.app;
334         p_tbl = p_app->app_pri_tbl;
335
336         p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
337         pri_tc_tbl = p_ets->pri_tc_tbl[0];
338
339         p_info = &p_hwfn->hw_info;
340         num_entries = GET_MFW_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
341
342         rc = ecore_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
343                                     num_entries, dcbx_version);
344         if (rc != ECORE_SUCCESS)
345                 return rc;
346
347         p_info->num_active_tc = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
348         p_hwfn->qm_info.ooo_tc = GET_MFW_FIELD(p_ets->flags, DCBX_OOO_TC);
349         data.pf_id = p_hwfn->rel_pf_id;
350         data.dcbx_enabled = !!dcbx_version;
351
352         ecore_dcbx_dp_protocol(p_hwfn, &data);
353
354         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->results, &data,
355                     sizeof(struct ecore_dcbx_results));
356
357         return ECORE_SUCCESS;
358 }
359
360 static enum _ecore_status_t
361 ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
362                     struct ecore_ptt *p_ptt,
363                     struct ecore_dcbx_mib_meta_data *p_data,
364                     enum ecore_mib_read_type type)
365 {
366         enum _ecore_status_t rc = ECORE_SUCCESS;
367         u32 prefix_seq_num, suffix_seq_num;
368         int read_count = 0;
369
370         /* The data is considered to be valid only if both sequence numbers are
371          * the same.
372          */
373         do {
374                 if (type == ECORE_DCBX_REMOTE_LLDP_MIB) {
375                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
376                                           p_data->addr, p_data->size);
377                         prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
378                         suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
379                 } else if (type == ECORE_DCBX_LLDP_TLVS) {
380                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_tlvs,
381                                           p_data->addr, p_data->size);
382                         prefix_seq_num = p_data->lldp_tlvs->prefix_seq_num;
383                         suffix_seq_num = p_data->lldp_tlvs->suffix_seq_num;
384
385                 } else {
386                         ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
387                                           p_data->addr, p_data->size);
388                         prefix_seq_num = p_data->mib->prefix_seq_num;
389                         suffix_seq_num = p_data->mib->suffix_seq_num;
390                 }
391                 read_count++;
392
393                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
394                            "mib type = %d, try count = %d prefix seq num  ="
395                            " %d suffix seq num = %d\n",
396                            type, read_count, prefix_seq_num, suffix_seq_num);
397         } while ((prefix_seq_num != suffix_seq_num) &&
398                  (read_count < ECORE_DCBX_MAX_MIB_READ_TRY));
399
400         if (read_count >= ECORE_DCBX_MAX_MIB_READ_TRY) {
401                 DP_ERR(p_hwfn,
402                        "MIB read err, mib type = %d, try count ="
403                        " %d prefix seq num = %d suffix seq num = %d\n",
404                        type, read_count, prefix_seq_num, suffix_seq_num);
405                 rc = ECORE_IO;
406         }
407
408         return rc;
409 }
410
411 static void
412 ecore_dcbx_get_priority_info(struct ecore_hwfn *p_hwfn,
413                              struct ecore_dcbx_app_prio *p_prio,
414                              struct ecore_dcbx_results *p_results)
415 {
416         u8 val;
417
418         if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
419             p_results->arr[DCBX_PROTOCOL_ETH].enable)
420                 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
421
422         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
423                    "Priorities: eth %d\n",
424                    p_prio->eth);
425 }
426
427 static void
428 ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
429                         struct dcbx_app_priority_feature *p_app,
430                         struct dcbx_app_priority_entry *p_tbl,
431                         struct ecore_dcbx_params *p_params, bool ieee)
432 {
433         struct ecore_app_entry *entry;
434         u8 pri_map;
435         int i;
436
437         p_params->app_willing = GET_MFW_FIELD(p_app->flags, DCBX_APP_WILLING);
438         p_params->app_valid = GET_MFW_FIELD(p_app->flags, DCBX_APP_ENABLED);
439         p_params->app_error = GET_MFW_FIELD(p_app->flags, DCBX_APP_ERROR);
440         p_params->num_app_entries = GET_MFW_FIELD(p_app->flags,
441                                                   DCBX_APP_NUM_ENTRIES);
442         for (i = 0; i < p_params->num_app_entries; i++) {
443                 entry = &p_params->app_entry[i];
444                 if (ieee) {
445                         u8 sf_ieee;
446                         u32 val;
447
448                         sf_ieee = GET_MFW_FIELD(p_tbl[i].entry,
449                                                 DCBX_APP_SF_IEEE);
450                         switch (sf_ieee) {
451                         case DCBX_APP_SF_IEEE_RESERVED:
452                                 /* Old MFW */
453                                 val = GET_MFW_FIELD(p_tbl[i].entry,
454                                                     DCBX_APP_SF);
455                                 entry->sf_ieee = val ?
456                                         ECORE_DCBX_SF_IEEE_TCP_UDP_PORT :
457                                         ECORE_DCBX_SF_IEEE_ETHTYPE;
458                                 break;
459                         case DCBX_APP_SF_IEEE_ETHTYPE:
460                                 entry->sf_ieee = ECORE_DCBX_SF_IEEE_ETHTYPE;
461                                 break;
462                         case DCBX_APP_SF_IEEE_TCP_PORT:
463                                 entry->sf_ieee = ECORE_DCBX_SF_IEEE_TCP_PORT;
464                                 break;
465                         case DCBX_APP_SF_IEEE_UDP_PORT:
466                                 entry->sf_ieee = ECORE_DCBX_SF_IEEE_UDP_PORT;
467                                 break;
468                         case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
469                                 entry->sf_ieee =
470                                                 ECORE_DCBX_SF_IEEE_TCP_UDP_PORT;
471                                 break;
472                         }
473                 } else {
474                         entry->ethtype = !(GET_MFW_FIELD(p_tbl[i].entry,
475                                                          DCBX_APP_SF));
476                 }
477
478                 pri_map = GET_MFW_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
479                 ecore_dcbx_get_app_priority(pri_map, &entry->prio);
480                 entry->proto_id = GET_MFW_FIELD(p_tbl[i].entry,
481                                                 DCBX_APP_PROTOCOL_ID);
482                 ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
483                                                  entry->proto_id,
484                                                  &entry->proto_type, ieee);
485         }
486
487         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
488                    "APP params: willing %d, valid %d error = %d\n",
489                    p_params->app_willing, p_params->app_valid,
490                    p_params->app_error);
491 }
492
493 static void
494 ecore_dcbx_get_pfc_data(struct ecore_hwfn *p_hwfn,
495                         u32 pfc, struct ecore_dcbx_params *p_params)
496 {
497         u8 pfc_map;
498
499         p_params->pfc.willing = GET_MFW_FIELD(pfc, DCBX_PFC_WILLING);
500         p_params->pfc.max_tc = GET_MFW_FIELD(pfc, DCBX_PFC_CAPS);
501         p_params->pfc.enabled = GET_MFW_FIELD(pfc, DCBX_PFC_ENABLED);
502         pfc_map = GET_MFW_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
503         p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
504         p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
505         p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
506         p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
507         p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
508         p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
509         p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
510         p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
511
512         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
513                    "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
514                    p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
515                    p_params->pfc.enabled);
516 }
517
518 static void
519 ecore_dcbx_get_ets_data(struct ecore_hwfn *p_hwfn,
520                         struct dcbx_ets_feature *p_ets,
521                         struct ecore_dcbx_params *p_params)
522 {
523         u32 bw_map[2], tsa_map[2], pri_map;
524         int i;
525
526         p_params->ets_willing = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_WILLING);
527         p_params->ets_enabled = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_ENABLED);
528         p_params->ets_cbs = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_CBS);
529         p_params->max_ets_tc = GET_MFW_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
530         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
531                    "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
532                    p_params->ets_willing, p_params->ets_enabled,
533                    p_params->ets_cbs, p_ets->pri_tc_tbl[0],
534                    p_params->max_ets_tc);
535
536         /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
537          * encoded in a type u32 array of size 2.
538          */
539         bw_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[0]);
540         bw_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[1]);
541         tsa_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[0]);
542         tsa_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[1]);
543         pri_map = p_ets->pri_tc_tbl[0];
544         for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
545                 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
546                 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
547                 p_params->ets_pri_tc_tbl[i] = ECORE_DCBX_PRIO2TC(pri_map, i);
548                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
549                            "elem %d  bw_tbl %x tsa_tbl %x\n",
550                            i, p_params->ets_tc_bw_tbl[i],
551                            p_params->ets_tc_tsa_tbl[i]);
552         }
553 }
554
555 static void
556 ecore_dcbx_get_common_params(struct ecore_hwfn *p_hwfn,
557                              struct dcbx_app_priority_feature *p_app,
558                              struct dcbx_app_priority_entry *p_tbl,
559                              struct dcbx_ets_feature *p_ets,
560                              u32 pfc, struct ecore_dcbx_params *p_params,
561                              bool ieee)
562 {
563         ecore_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
564         ecore_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
565         ecore_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
566 }
567
568 static void
569 ecore_dcbx_get_local_params(struct ecore_hwfn *p_hwfn,
570                             struct ecore_dcbx_get *params)
571 {
572         struct dcbx_features *p_feat;
573
574         p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
575         ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
576                                      p_feat->app.app_pri_tbl, &p_feat->ets,
577                                      p_feat->pfc, &params->local.params, false);
578         params->local.valid = true;
579 }
580
581 static void
582 ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
583                              struct ecore_dcbx_get *params)
584 {
585         struct dcbx_features *p_feat;
586
587         p_feat = &p_hwfn->p_dcbx_info->remote.features;
588         ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
589                                      p_feat->app.app_pri_tbl, &p_feat->ets,
590                                      p_feat->pfc, &params->remote.params,
591                                      false);
592         params->remote.valid = true;
593 }
594
595 static void  ecore_dcbx_get_dscp_params(struct ecore_hwfn *p_hwfn,
596                                         struct ecore_dcbx_get *params)
597 {
598         struct ecore_dcbx_dscp_params *p_dscp;
599         struct dcb_dscp_map *p_dscp_map;
600         int i, j, entry;
601         u32 pri_map;
602
603         p_dscp = &params->dscp;
604         p_dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
605         p_dscp->enabled = GET_MFW_FIELD(p_dscp_map->flags, DCB_DSCP_ENABLE);
606
607         /* MFW encodes 64 dscp entries into 8 element array of u32 entries,
608          * where each entry holds the 4bit priority map for 8 dscp entries.
609          */
610         for (i = 0, entry = 0; i < ECORE_DCBX_DSCP_SIZE / 8; i++) {
611                 pri_map = OSAL_BE32_TO_CPU(p_dscp_map->dscp_pri_map[i]);
612                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "elem %d pri_map 0x%x\n",
613                            entry, pri_map);
614                 for (j = 0; j < ECORE_DCBX_DSCP_SIZE / 8; j++, entry++)
615                         p_dscp->dscp_pri_map[entry] = (u32)(pri_map >>
616                                                            (j * 4)) & 0xf;
617         }
618 }
619
620 static void
621 ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
622                                   struct ecore_dcbx_get *params)
623 {
624         struct ecore_dcbx_operational_params *p_operational;
625         struct ecore_dcbx_results *p_results;
626         struct dcbx_features *p_feat;
627         bool enabled, err;
628         u32 flags;
629         bool val;
630
631         flags = p_hwfn->p_dcbx_info->operational.flags;
632
633         /* If DCBx version is non zero, then negotiation
634          * was successfuly performed
635          */
636         p_operational = &params->operational;
637         enabled = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) !=
638                      DCBX_CONFIG_VERSION_DISABLED);
639         if (!enabled) {
640                 p_operational->enabled = enabled;
641                 p_operational->valid = false;
642                 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Dcbx is disabled\n");
643                 return;
644         }
645
646         p_feat = &p_hwfn->p_dcbx_info->operational.features;
647         p_results = &p_hwfn->p_dcbx_info->results;
648
649         val = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) ==
650                  DCBX_CONFIG_VERSION_IEEE);
651         p_operational->ieee = val;
652
653         val = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) ==
654                  DCBX_CONFIG_VERSION_CEE);
655         p_operational->cee = val;
656
657         val = !!(GET_MFW_FIELD(flags, DCBX_CONFIG_VERSION) ==
658                  DCBX_CONFIG_VERSION_STATIC);
659         p_operational->local = val;
660
661         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
662                    "Version support: ieee %d, cee %d, static %d\n",
663                    p_operational->ieee, p_operational->cee,
664                    p_operational->local);
665
666         ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
667                                      p_feat->app.app_pri_tbl, &p_feat->ets,
668                                      p_feat->pfc, &params->operational.params,
669                                      p_operational->ieee);
670         ecore_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio,
671                                      p_results);
672         err = GET_MFW_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
673         p_operational->err = err;
674         p_operational->enabled = enabled;
675         p_operational->valid = true;
676 }
677
678 static void ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
679                                              struct ecore_dcbx_get *params)
680 {
681         struct lldp_config_params_s *p_local;
682
683         p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
684
685         OSAL_MEMCPY(params->lldp_local.local_chassis_id,
686                     p_local->local_chassis_id,
687                     OSAL_ARRAY_SIZE(p_local->local_chassis_id));
688         OSAL_MEMCPY(params->lldp_local.local_port_id, p_local->local_port_id,
689                     OSAL_ARRAY_SIZE(p_local->local_port_id));
690 }
691
692 static void ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
693                                               struct ecore_dcbx_get *params)
694 {
695         struct lldp_status_params_s *p_remote;
696
697         p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
698
699         OSAL_MEMCPY(params->lldp_remote.peer_chassis_id,
700                     p_remote->peer_chassis_id,
701                     OSAL_ARRAY_SIZE(p_remote->peer_chassis_id));
702         OSAL_MEMCPY(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
703                     OSAL_ARRAY_SIZE(p_remote->peer_port_id));
704 }
705
706 static enum _ecore_status_t
707 ecore_dcbx_get_params(struct ecore_hwfn *p_hwfn,
708                       struct ecore_dcbx_get *p_params,
709                       enum ecore_mib_read_type type)
710 {
711         switch (type) {
712         case ECORE_DCBX_REMOTE_MIB:
713                 ecore_dcbx_get_remote_params(p_hwfn, p_params);
714                 break;
715         case ECORE_DCBX_LOCAL_MIB:
716                 ecore_dcbx_get_local_params(p_hwfn, p_params);
717                 break;
718         case ECORE_DCBX_OPERATIONAL_MIB:
719                 ecore_dcbx_get_operational_params(p_hwfn, p_params);
720                 break;
721         case ECORE_DCBX_REMOTE_LLDP_MIB:
722                 ecore_dcbx_get_remote_lldp_params(p_hwfn, p_params);
723                 break;
724         case ECORE_DCBX_LOCAL_LLDP_MIB:
725                 ecore_dcbx_get_local_lldp_params(p_hwfn, p_params);
726                 break;
727         default:
728                 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
729                 return ECORE_INVAL;
730         }
731
732         return ECORE_SUCCESS;
733 }
734
735 static enum _ecore_status_t
736 ecore_dcbx_read_local_lldp_mib(struct ecore_hwfn *p_hwfn,
737                                struct ecore_ptt *p_ptt)
738 {
739         struct ecore_dcbx_mib_meta_data data;
740         enum _ecore_status_t rc = ECORE_SUCCESS;
741
742         OSAL_MEM_ZERO(&data, sizeof(data));
743         data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
744                                                            lldp_config_params);
745         data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
746         data.size = sizeof(struct lldp_config_params_s);
747         ecore_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
748
749         return rc;
750 }
751
752 static enum _ecore_status_t
753 ecore_dcbx_read_remote_lldp_mib(struct ecore_hwfn *p_hwfn,
754                                 struct ecore_ptt *p_ptt,
755                                 enum ecore_mib_read_type type)
756 {
757         struct ecore_dcbx_mib_meta_data data;
758         enum _ecore_status_t rc = ECORE_SUCCESS;
759
760         OSAL_MEM_ZERO(&data, sizeof(data));
761         data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
762                                                            lldp_status_params);
763         data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
764         data.size = sizeof(struct lldp_status_params_s);
765         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
766
767         return rc;
768 }
769
770 static enum _ecore_status_t
771 ecore_dcbx_read_operational_mib(struct ecore_hwfn *p_hwfn,
772                                 struct ecore_ptt *p_ptt,
773                                 enum ecore_mib_read_type type)
774 {
775         struct ecore_dcbx_mib_meta_data data;
776         enum _ecore_status_t rc = ECORE_SUCCESS;
777
778         OSAL_MEM_ZERO(&data, sizeof(data));
779         data.addr = p_hwfn->mcp_info->port_addr +
780             offsetof(struct public_port, operational_dcbx_mib);
781         data.mib = &p_hwfn->p_dcbx_info->operational;
782         data.size = sizeof(struct dcbx_mib);
783         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
784
785         return rc;
786 }
787
788 static enum _ecore_status_t
789 ecore_dcbx_read_remote_mib(struct ecore_hwfn *p_hwfn,
790                            struct ecore_ptt *p_ptt,
791                            enum ecore_mib_read_type type)
792 {
793         struct ecore_dcbx_mib_meta_data data;
794         enum _ecore_status_t rc = ECORE_SUCCESS;
795
796         OSAL_MEM_ZERO(&data, sizeof(data));
797         data.addr = p_hwfn->mcp_info->port_addr +
798             offsetof(struct public_port, remote_dcbx_mib);
799         data.mib = &p_hwfn->p_dcbx_info->remote;
800         data.size = sizeof(struct dcbx_mib);
801         rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
802
803         return rc;
804 }
805
806 static enum _ecore_status_t
807 ecore_dcbx_read_local_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
808 {
809         struct ecore_dcbx_mib_meta_data data;
810         enum _ecore_status_t rc = ECORE_SUCCESS;
811
812         OSAL_MEM_ZERO(&data, sizeof(data));
813         data.addr = p_hwfn->mcp_info->port_addr +
814             offsetof(struct public_port, local_admin_dcbx_mib);
815         data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
816         data.size = sizeof(struct dcbx_local_params);
817         ecore_memcpy_from(p_hwfn, p_ptt, data.local_admin,
818                           data.addr, data.size);
819
820         return rc;
821 }
822
823 static void
824 ecore_dcbx_read_dscp_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
825 {
826         struct ecore_dcbx_mib_meta_data data;
827
828         data.addr = p_hwfn->mcp_info->port_addr +
829                         offsetof(struct public_port, dcb_dscp_map);
830         data.dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
831         data.size = sizeof(struct dcb_dscp_map);
832         ecore_memcpy_from(p_hwfn, p_ptt, data.dscp_map, data.addr, data.size);
833 }
834
835 static enum _ecore_status_t ecore_dcbx_read_mib(struct ecore_hwfn *p_hwfn,
836                                                 struct ecore_ptt *p_ptt,
837                                                 enum ecore_mib_read_type type)
838 {
839         enum _ecore_status_t rc = ECORE_INVAL;
840
841         switch (type) {
842         case ECORE_DCBX_OPERATIONAL_MIB:
843                 ecore_dcbx_read_dscp_mib(p_hwfn, p_ptt);
844                 rc = ecore_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
845                 break;
846         case ECORE_DCBX_REMOTE_MIB:
847                 rc = ecore_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
848                 break;
849         case ECORE_DCBX_LOCAL_MIB:
850                 rc = ecore_dcbx_read_local_mib(p_hwfn, p_ptt);
851                 break;
852         case ECORE_DCBX_REMOTE_LLDP_MIB:
853                 rc = ecore_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
854                 break;
855         case ECORE_DCBX_LOCAL_LLDP_MIB:
856                 rc = ecore_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
857                 break;
858         default:
859                 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
860         }
861
862         return rc;
863 }
864
865 /*
866  * Read updated MIB.
867  * Reconfigure QM and invoke PF update ramrod command if operational MIB
868  * change is detected.
869  */
870 enum _ecore_status_t
871 ecore_dcbx_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
872                             enum ecore_mib_read_type type)
873 {
874         enum _ecore_status_t rc = ECORE_SUCCESS;
875
876         rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
877         if (rc)
878                 return rc;
879
880         if (type == ECORE_DCBX_OPERATIONAL_MIB) {
881                 ecore_dcbx_get_dscp_params(p_hwfn, &p_hwfn->p_dcbx_info->get);
882
883                 rc = ecore_dcbx_process_mib_info(p_hwfn);
884                 if (!rc) {
885                         bool enabled;
886
887                         /* reconfigure tcs of QM queues according
888                          * to negotiation results
889                          */
890                         ecore_qm_reconf(p_hwfn, p_ptt);
891
892                         /* update storm FW with negotiation results */
893                         ecore_sp_pf_update_dcbx(p_hwfn);
894
895                         /* set eagle enigne 1 flow control workaround
896                          * according to negotiation results
897                          */
898                         enabled = p_hwfn->p_dcbx_info->results.dcbx_enabled;
899                 }
900         }
901
902         ecore_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
903
904         /* Update the DSCP to TC mapping bit if required */
905         if ((type == ECORE_DCBX_OPERATIONAL_MIB) &&
906             p_hwfn->p_dcbx_info->dscp_nig_update) {
907                 u8 val = !!p_hwfn->p_dcbx_info->get.dscp.enabled;
908
909                 ecore_wr(p_hwfn, p_ptt, NIG_REG_DSCP_TO_TC_MAP_ENABLE, val);
910                 p_hwfn->p_dcbx_info->dscp_nig_update = false;
911         }
912
913         OSAL_DCBX_AEN(p_hwfn, type);
914
915         return rc;
916 }
917
918 enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
919 {
920         p_hwfn->p_dcbx_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
921                                           sizeof(*p_hwfn->p_dcbx_info));
922         if (!p_hwfn->p_dcbx_info) {
923                 DP_NOTICE(p_hwfn, true,
924                           "Failed to allocate `struct ecore_dcbx_info'");
925                 return ECORE_NOMEM;
926         }
927
928         p_hwfn->p_dcbx_info->iwarp_port =
929                 p_hwfn->pf_params.rdma_pf_params.iwarp_port;
930
931         return ECORE_SUCCESS;
932 }
933
934 void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn)
935 {
936         OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
937 }
938
939 static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
940                                             struct ecore_dcbx_results *p_src,
941                                             enum dcbx_protocol_type type)
942 {
943         p_data->dcb_enable_flag = p_src->arr[type].enable;
944         p_data->dcb_priority = p_src->arr[type].priority;
945         p_data->dcb_tc = p_src->arr[type].tc;
946         p_data->dscp_enable_flag = p_src->arr[type].dscp_enable;
947         p_data->dscp_val = p_src->arr[type].dscp_val;
948 }
949
950 /* Set pf update ramrod command params */
951 void ecore_dcbx_set_pf_update_params(struct ecore_dcbx_results *p_src,
952                                      struct pf_update_ramrod_data *p_dest)
953 {
954         struct protocol_dcb_data *p_dcb_data;
955         u8 update_flag;
956
957         update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
958         p_dest->update_eth_dcb_data_mode = update_flag;
959         update_flag = p_src->arr[DCBX_PROTOCOL_IWARP].update;
960         p_dest->update_iwarp_dcb_data_mode = update_flag;
961
962         p_dcb_data = &p_dest->eth_dcb_data;
963         ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
964         p_dcb_data = &p_dest->iwarp_dcb_data;
965         ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_IWARP);
966 }
967
968 enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
969                                              struct ecore_dcbx_get *p_get,
970                                              enum ecore_mib_read_type type)
971 {
972         struct ecore_ptt *p_ptt;
973         enum _ecore_status_t rc;
974
975         if (IS_VF(p_hwfn->p_dev))
976                 return ECORE_INVAL;
977
978         p_ptt = ecore_ptt_acquire(p_hwfn);
979         if (!p_ptt)
980                 return ECORE_TIMEOUT;
981
982         rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
983         if (rc != ECORE_SUCCESS)
984                 goto out;
985
986         ecore_dcbx_get_dscp_params(p_hwfn, p_get);
987
988         rc = ecore_dcbx_get_params(p_hwfn, p_get, type);
989
990 out:
991         ecore_ptt_release(p_hwfn, p_ptt);
992         return rc;
993 }
994
995 static void
996 ecore_dcbx_set_pfc_data(struct ecore_hwfn *p_hwfn,
997                         u32 *pfc, struct ecore_dcbx_params *p_params)
998 {
999         u8 pfc_map = 0;
1000         int i;
1001
1002         if (p_params->pfc.willing)
1003                 *pfc |= DCBX_PFC_WILLING_MASK;
1004         else
1005                 *pfc &= ~DCBX_PFC_WILLING_MASK;
1006
1007         if (p_params->pfc.enabled)
1008                 *pfc |= DCBX_PFC_ENABLED_MASK;
1009         else
1010                 *pfc &= ~DCBX_PFC_ENABLED_MASK;
1011
1012         *pfc &= ~DCBX_PFC_CAPS_MASK;
1013         *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_OFFSET;
1014
1015         for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++)
1016                 if (p_params->pfc.prio[i])
1017                         pfc_map |= (1 << i);
1018         *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
1019         *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_OFFSET);
1020
1021         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "pfc = 0x%x\n", *pfc);
1022 }
1023
1024 static void
1025 ecore_dcbx_set_ets_data(struct ecore_hwfn *p_hwfn,
1026                         struct dcbx_ets_feature *p_ets,
1027                         struct ecore_dcbx_params *p_params)
1028 {
1029         u8 *bw_map, *tsa_map;
1030         u32 val;
1031         int i;
1032
1033         if (p_params->ets_willing)
1034                 p_ets->flags |= DCBX_ETS_WILLING_MASK;
1035         else
1036                 p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
1037
1038         if (p_params->ets_cbs)
1039                 p_ets->flags |= DCBX_ETS_CBS_MASK;
1040         else
1041                 p_ets->flags &= ~DCBX_ETS_CBS_MASK;
1042
1043         if (p_params->ets_enabled)
1044                 p_ets->flags |= DCBX_ETS_ENABLED_MASK;
1045         else
1046                 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
1047
1048         p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
1049         p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_OFFSET;
1050
1051         bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
1052         tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
1053         p_ets->pri_tc_tbl[0] = 0;
1054         for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
1055                 bw_map[i] = p_params->ets_tc_bw_tbl[i];
1056                 tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
1057                 /* Copy the priority value to the corresponding 4 bits in the
1058                  * traffic class table.
1059                  */
1060                 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
1061                 p_ets->pri_tc_tbl[0] |= val;
1062         }
1063         for (i = 0; i < 2; i++) {
1064                 p_ets->tc_bw_tbl[i] = OSAL_CPU_TO_BE32(p_ets->tc_bw_tbl[i]);
1065                 p_ets->tc_tsa_tbl[i] = OSAL_CPU_TO_BE32(p_ets->tc_tsa_tbl[i]);
1066         }
1067
1068         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
1069                    "flags = 0x%x pri_tc = 0x%x tc_bwl[] = {0x%x, 0x%x} tc_tsa = {0x%x, 0x%x}\n",
1070                    p_ets->flags, p_ets->pri_tc_tbl[0], p_ets->tc_bw_tbl[0],
1071                    p_ets->tc_bw_tbl[1], p_ets->tc_tsa_tbl[0],
1072                    p_ets->tc_tsa_tbl[1]);
1073 }
1074
1075 static void
1076 ecore_dcbx_set_app_data(struct ecore_hwfn *p_hwfn,
1077                         struct dcbx_app_priority_feature *p_app,
1078                         struct ecore_dcbx_params *p_params, bool ieee)
1079 {
1080         u32 *entry;
1081         int i;
1082
1083         if (p_params->app_willing)
1084                 p_app->flags |= DCBX_APP_WILLING_MASK;
1085         else
1086                 p_app->flags &= ~DCBX_APP_WILLING_MASK;
1087
1088         if (p_params->app_valid)
1089                 p_app->flags |= DCBX_APP_ENABLED_MASK;
1090         else
1091                 p_app->flags &= ~DCBX_APP_ENABLED_MASK;
1092
1093         p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
1094         p_app->flags |= (u32)p_params->num_app_entries <<
1095                         DCBX_APP_NUM_ENTRIES_OFFSET;
1096
1097         for (i = 0; i < p_params->num_app_entries; i++) {
1098                 entry = &p_app->app_pri_tbl[i].entry;
1099                 *entry = 0;
1100                 if (ieee) {
1101                         *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
1102                         switch (p_params->app_entry[i].sf_ieee) {
1103                         case ECORE_DCBX_SF_IEEE_ETHTYPE:
1104                                 *entry  |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
1105                                             DCBX_APP_SF_IEEE_OFFSET);
1106                                 *entry  |= ((u32)DCBX_APP_SF_ETHTYPE <<
1107                                             DCBX_APP_SF_OFFSET);
1108                                 break;
1109                         case ECORE_DCBX_SF_IEEE_TCP_PORT:
1110                                 *entry  |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1111                                             DCBX_APP_SF_IEEE_OFFSET);
1112                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1113                                             DCBX_APP_SF_OFFSET);
1114                                 break;
1115                         case ECORE_DCBX_SF_IEEE_UDP_PORT:
1116                                 *entry  |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1117                                             DCBX_APP_SF_IEEE_OFFSET);
1118                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1119                                             DCBX_APP_SF_OFFSET);
1120                                 break;
1121                         case ECORE_DCBX_SF_IEEE_TCP_UDP_PORT:
1122                                 *entry  |= (u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1123                                             DCBX_APP_SF_IEEE_OFFSET;
1124                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1125                                             DCBX_APP_SF_OFFSET);
1126                                 break;
1127                         }
1128                 } else {
1129                         *entry &= ~DCBX_APP_SF_MASK;
1130                         if (p_params->app_entry[i].ethtype)
1131                                 *entry  |= ((u32)DCBX_APP_SF_ETHTYPE <<
1132                                             DCBX_APP_SF_OFFSET);
1133                         else
1134                                 *entry  |= ((u32)DCBX_APP_SF_PORT <<
1135                                             DCBX_APP_SF_OFFSET);
1136                 }
1137                 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
1138                 *entry |= ((u32)p_params->app_entry[i].proto_id <<
1139                            DCBX_APP_PROTOCOL_ID_OFFSET);
1140                 *entry &= ~DCBX_APP_PRI_MAP_MASK;
1141                 *entry |= ((u32)(p_params->app_entry[i].prio) <<
1142                            DCBX_APP_PRI_MAP_OFFSET);
1143         }
1144
1145         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "flags = 0x%x\n", p_app->flags);
1146 }
1147
1148 static void
1149 ecore_dcbx_set_local_params(struct ecore_hwfn *p_hwfn,
1150                             struct dcbx_local_params *local_admin,
1151                             struct ecore_dcbx_set *params)
1152 {
1153         bool ieee = false;
1154
1155         local_admin->flags = 0;
1156         OSAL_MEMCPY(&local_admin->features,
1157                     &p_hwfn->p_dcbx_info->operational.features,
1158                     sizeof(local_admin->features));
1159
1160         if (params->enabled) {
1161                 local_admin->config = params->ver_num;
1162                 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1163         } else {
1164                 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1165         }
1166
1167         if (params->override_flags & ECORE_DCBX_OVERRIDE_PFC_CFG)
1168                 ecore_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
1169                                         &params->config.params);
1170
1171         if (params->override_flags & ECORE_DCBX_OVERRIDE_ETS_CFG)
1172                 ecore_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
1173                                         &params->config.params);
1174
1175         if (params->override_flags & ECORE_DCBX_OVERRIDE_APP_CFG)
1176                 ecore_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1177                                         &params->config.params, ieee);
1178 }
1179
1180 static enum _ecore_status_t
1181 ecore_dcbx_set_dscp_params(struct ecore_hwfn *p_hwfn,
1182                            struct dcb_dscp_map *p_dscp_map,
1183                            struct ecore_dcbx_set *p_params)
1184 {
1185         int entry, i, j;
1186         u32 val;
1187
1188         OSAL_MEMCPY(p_dscp_map, &p_hwfn->p_dcbx_info->dscp_map,
1189                     sizeof(*p_dscp_map));
1190
1191         p_dscp_map->flags &= ~DCB_DSCP_ENABLE_MASK;
1192         if (p_params->dscp.enabled)
1193                 p_dscp_map->flags |= DCB_DSCP_ENABLE_MASK;
1194
1195         for (i = 0, entry = 0; i < 8; i++) {
1196                 val = 0;
1197                 for (j = 0; j < 8; j++, entry++)
1198                         val |= (((u32)p_params->dscp.dscp_pri_map[entry]) <<
1199                                 (j * 4));
1200
1201                 p_dscp_map->dscp_pri_map[i] = OSAL_CPU_TO_BE32(val);
1202         }
1203
1204         p_hwfn->p_dcbx_info->dscp_nig_update = true;
1205
1206         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "flags = 0x%x\n", p_dscp_map->flags);
1207         DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
1208                    "pri_map[] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1209                    p_dscp_map->dscp_pri_map[0], p_dscp_map->dscp_pri_map[1],
1210                    p_dscp_map->dscp_pri_map[2], p_dscp_map->dscp_pri_map[3],
1211                    p_dscp_map->dscp_pri_map[4], p_dscp_map->dscp_pri_map[5],
1212                    p_dscp_map->dscp_pri_map[6], p_dscp_map->dscp_pri_map[7]);
1213
1214         return ECORE_SUCCESS;
1215 }
1216
1217 enum _ecore_status_t ecore_dcbx_config_params(struct ecore_hwfn *p_hwfn,
1218                                               struct ecore_ptt *p_ptt,
1219                                               struct ecore_dcbx_set *params,
1220                                               bool hw_commit)
1221 {
1222         struct dcbx_local_params local_admin;
1223         struct ecore_dcbx_mib_meta_data data;
1224         struct dcb_dscp_map dscp_map;
1225         u32 resp = 0, param = 0;
1226         enum _ecore_status_t rc = ECORE_SUCCESS;
1227
1228         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set, params,
1229                     sizeof(p_hwfn->p_dcbx_info->set));
1230         if (!hw_commit)
1231                 return ECORE_SUCCESS;
1232
1233         OSAL_MEMSET(&local_admin, 0, sizeof(local_admin));
1234         ecore_dcbx_set_local_params(p_hwfn, &local_admin, params);
1235
1236         data.addr = p_hwfn->mcp_info->port_addr +
1237                         offsetof(struct public_port, local_admin_dcbx_mib);
1238         data.local_admin = &local_admin;
1239         data.size = sizeof(struct dcbx_local_params);
1240         ecore_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
1241
1242         if (params->override_flags & ECORE_DCBX_OVERRIDE_DSCP_CFG) {
1243                 OSAL_MEMSET(&dscp_map, 0, sizeof(dscp_map));
1244                 ecore_dcbx_set_dscp_params(p_hwfn, &dscp_map, params);
1245
1246                 data.addr = p_hwfn->mcp_info->port_addr +
1247                                 offsetof(struct public_port, dcb_dscp_map);
1248                 data.dscp_map = &dscp_map;
1249                 data.size = sizeof(struct dcb_dscp_map);
1250                 ecore_memcpy_to(p_hwfn, p_ptt, data.addr, data.dscp_map,
1251                                 data.size);
1252         }
1253
1254         rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
1255                            1 << DRV_MB_PARAM_LLDP_SEND_OFFSET, &resp, &param);
1256         if (rc != ECORE_SUCCESS)
1257                 DP_NOTICE(p_hwfn, false,
1258                           "Failed to send DCBX update request\n");
1259
1260         return rc;
1261 }
1262
1263 enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
1264                                                   struct ecore_dcbx_set *params)
1265 {
1266         struct ecore_dcbx_get *dcbx_info;
1267         int rc;
1268
1269         if (p_hwfn->p_dcbx_info->set.config.valid) {
1270                 OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
1271                             sizeof(struct ecore_dcbx_set));
1272                 return ECORE_SUCCESS;
1273         }
1274
1275         dcbx_info = OSAL_ALLOC(p_hwfn->p_dev, GFP_KERNEL,
1276                                sizeof(*dcbx_info));
1277         if (!dcbx_info)
1278                 return ECORE_NOMEM;
1279
1280         OSAL_MEMSET(dcbx_info, 0, sizeof(*dcbx_info));
1281         rc = ecore_dcbx_query_params(p_hwfn, dcbx_info,
1282                                      ECORE_DCBX_OPERATIONAL_MIB);
1283         if (rc) {
1284                 OSAL_FREE(p_hwfn->p_dev, dcbx_info);
1285                 return rc;
1286         }
1287         p_hwfn->p_dcbx_info->set.override_flags = 0;
1288
1289         p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
1290         if (dcbx_info->operational.cee)
1291                 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
1292         if (dcbx_info->operational.ieee)
1293                 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
1294         if (dcbx_info->operational.local)
1295                 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
1296
1297         p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
1298         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.dscp,
1299                     &p_hwfn->p_dcbx_info->get.dscp,
1300                     sizeof(struct ecore_dcbx_dscp_params));
1301         OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.config.params,
1302                     &dcbx_info->operational.params,
1303                     sizeof(p_hwfn->p_dcbx_info->set.config.params));
1304         p_hwfn->p_dcbx_info->set.config.valid = true;
1305
1306         OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
1307                     sizeof(struct ecore_dcbx_set));
1308
1309         OSAL_FREE(p_hwfn->p_dev, dcbx_info);
1310
1311         return ECORE_SUCCESS;
1312 }
1313
1314 enum _ecore_status_t ecore_lldp_register_tlv(struct ecore_hwfn *p_hwfn,
1315                                              struct ecore_ptt *p_ptt,
1316                                              enum ecore_lldp_agent agent,
1317                                              u8 tlv_type)
1318 {
1319         u32 mb_param = 0, mcp_resp = 0, mcp_param = 0, val = 0;
1320         enum _ecore_status_t rc = ECORE_SUCCESS;
1321
1322         switch (agent) {
1323         case ECORE_LLDP_NEAREST_BRIDGE:
1324                 val = LLDP_NEAREST_BRIDGE;
1325                 break;
1326         case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
1327                 val = LLDP_NEAREST_NON_TPMR_BRIDGE;
1328                 break;
1329         case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
1330                 val = LLDP_NEAREST_CUSTOMER_BRIDGE;
1331                 break;
1332         default:
1333                 DP_ERR(p_hwfn, "Invalid agent type %d\n", agent);
1334                 return ECORE_INVAL;
1335         }
1336
1337         SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_AGENT, val);
1338         SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_TLV_RX_TYPE, tlv_type);
1339
1340         rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_REGISTER_LLDP_TLVS_RX,
1341                            mb_param, &mcp_resp, &mcp_param);
1342         if (rc != ECORE_SUCCESS)
1343                 DP_NOTICE(p_hwfn, false, "Failed to register TLV\n");
1344
1345         return rc;
1346 }
1347
1348 enum _ecore_status_t
1349 ecore_lldp_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1350 {
1351         struct ecore_dcbx_mib_meta_data data;
1352         enum _ecore_status_t rc = ECORE_SUCCESS;
1353         struct lldp_received_tlvs_s tlvs;
1354         int i;
1355
1356         for (i = 0; i < LLDP_MAX_LLDP_AGENTS; i++) {
1357                 OSAL_MEM_ZERO(&data, sizeof(data));
1358                 data.addr = p_hwfn->mcp_info->port_addr +
1359                             offsetof(struct public_port, lldp_received_tlvs[i]);
1360                 data.lldp_tlvs = &tlvs;
1361                 data.size = sizeof(tlvs);
1362                 rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data,
1363                                          ECORE_DCBX_LLDP_TLVS);
1364                 if (rc != ECORE_SUCCESS) {
1365                         DP_NOTICE(p_hwfn, false, "Failed to read lldp TLVs\n");
1366                         return rc;
1367                 }
1368
1369                 if (!tlvs.length)
1370                         continue;
1371
1372                 for (i = 0; i < MAX_TLV_BUFFER; i++)
1373                         tlvs.tlvs_buffer[i] =
1374                                 OSAL_CPU_TO_BE32(tlvs.tlvs_buffer[i]);
1375
1376                 OSAL_LLDP_RX_TLVS(p_hwfn, tlvs.tlvs_buffer, tlvs.length);
1377         }
1378
1379         return rc;
1380 }
1381
1382 enum _ecore_status_t
1383 ecore_lldp_get_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1384                       struct ecore_lldp_config_params *p_params)
1385 {
1386         struct lldp_config_params_s lldp_params;
1387         u32 addr, val;
1388         int i;
1389
1390         switch (p_params->agent) {
1391         case ECORE_LLDP_NEAREST_BRIDGE:
1392                 val = LLDP_NEAREST_BRIDGE;
1393                 break;
1394         case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
1395                 val = LLDP_NEAREST_NON_TPMR_BRIDGE;
1396                 break;
1397         case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
1398                 val = LLDP_NEAREST_CUSTOMER_BRIDGE;
1399                 break;
1400         default:
1401                 DP_ERR(p_hwfn, "Invalid agent type %d\n", p_params->agent);
1402                 return ECORE_INVAL;
1403         }
1404
1405         addr = p_hwfn->mcp_info->port_addr +
1406                         offsetof(struct public_port, lldp_config_params[val]);
1407
1408         ecore_memcpy_from(p_hwfn, p_ptt, &lldp_params, addr,
1409                           sizeof(lldp_params));
1410
1411         p_params->tx_interval = GET_MFW_FIELD(lldp_params.config,
1412                                               LLDP_CONFIG_TX_INTERVAL);
1413         p_params->tx_hold = GET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_HOLD);
1414         p_params->tx_credit = GET_MFW_FIELD(lldp_params.config,
1415                                             LLDP_CONFIG_MAX_CREDIT);
1416         p_params->rx_enable = GET_MFW_FIELD(lldp_params.config,
1417                                             LLDP_CONFIG_ENABLE_RX);
1418         p_params->tx_enable = GET_MFW_FIELD(lldp_params.config,
1419                                             LLDP_CONFIG_ENABLE_TX);
1420
1421         OSAL_MEMCPY(p_params->chassis_id_tlv, lldp_params.local_chassis_id,
1422                     sizeof(p_params->chassis_id_tlv));
1423         for (i = 0; i < ECORE_LLDP_CHASSIS_ID_STAT_LEN; i++)
1424                 p_params->chassis_id_tlv[i] =
1425                                 OSAL_BE32_TO_CPU(p_params->chassis_id_tlv[i]);
1426
1427         OSAL_MEMCPY(p_params->port_id_tlv, lldp_params.local_port_id,
1428                     sizeof(p_params->port_id_tlv));
1429         for (i = 0; i < ECORE_LLDP_PORT_ID_STAT_LEN; i++)
1430                 p_params->port_id_tlv[i] =
1431                                 OSAL_BE32_TO_CPU(p_params->port_id_tlv[i]);
1432
1433         return ECORE_SUCCESS;
1434 }
1435
1436 enum _ecore_status_t
1437 ecore_lldp_set_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1438                       struct ecore_lldp_config_params *p_params)
1439 {
1440         u32 mb_param = 0, mcp_resp = 0, mcp_param = 0;
1441         struct lldp_config_params_s lldp_params;
1442         enum _ecore_status_t rc = ECORE_SUCCESS;
1443         u32 addr, val;
1444         int i;
1445
1446         switch (p_params->agent) {
1447         case ECORE_LLDP_NEAREST_BRIDGE:
1448                 val = LLDP_NEAREST_BRIDGE;
1449                 break;
1450         case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
1451                 val = LLDP_NEAREST_NON_TPMR_BRIDGE;
1452                 break;
1453         case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
1454                 val = LLDP_NEAREST_CUSTOMER_BRIDGE;
1455                 break;
1456         default:
1457                 DP_ERR(p_hwfn, "Invalid agent type %d\n", p_params->agent);
1458                 return ECORE_INVAL;
1459         }
1460
1461         SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_AGENT, val);
1462         addr = p_hwfn->mcp_info->port_addr +
1463                         offsetof(struct public_port, lldp_config_params[val]);
1464
1465         OSAL_MEMSET(&lldp_params, 0, sizeof(lldp_params));
1466         SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_TX_INTERVAL,
1467                       p_params->tx_interval);
1468         SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_HOLD, p_params->tx_hold);
1469         SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_MAX_CREDIT,
1470                       p_params->tx_credit);
1471         SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_ENABLE_RX,
1472                       !!p_params->rx_enable);
1473         SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_ENABLE_TX,
1474                       !!p_params->tx_enable);
1475
1476         for (i = 0; i < ECORE_LLDP_CHASSIS_ID_STAT_LEN; i++)
1477                 p_params->chassis_id_tlv[i] =
1478                                 OSAL_CPU_TO_BE32(p_params->chassis_id_tlv[i]);
1479         OSAL_MEMCPY(lldp_params.local_chassis_id, p_params->chassis_id_tlv,
1480                     sizeof(lldp_params.local_chassis_id));
1481
1482         for (i = 0; i < ECORE_LLDP_PORT_ID_STAT_LEN; i++)
1483                 p_params->port_id_tlv[i] =
1484                                 OSAL_CPU_TO_BE32(p_params->port_id_tlv[i]);
1485         OSAL_MEMCPY(lldp_params.local_port_id, p_params->port_id_tlv,
1486                     sizeof(lldp_params.local_port_id));
1487
1488         ecore_memcpy_to(p_hwfn, p_ptt, addr, &lldp_params, sizeof(lldp_params));
1489
1490         rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LLDP,
1491                            mb_param, &mcp_resp, &mcp_param);
1492         if (rc != ECORE_SUCCESS)
1493                 DP_NOTICE(p_hwfn, false, "SET_LLDP failed, error = %d\n", rc);
1494
1495         return rc;
1496 }
1497
1498 enum _ecore_status_t
1499 ecore_lldp_set_system_tlvs(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1500                            struct ecore_lldp_sys_tlvs *p_params)
1501 {
1502         u32 mb_param = 0, mcp_resp = 0, mcp_param = 0;
1503         enum _ecore_status_t rc = ECORE_SUCCESS;
1504         struct lldp_system_tlvs_buffer_s lld_tlv_buf;
1505         u32 addr, *p_val;
1506         u8 len;
1507         int i;
1508
1509         p_val = (u32 *)p_params->buf;
1510         for (i = 0; i < ECORE_LLDP_SYS_TLV_SIZE / 4; i++)
1511                 p_val[i] = OSAL_CPU_TO_BE32(p_val[i]);
1512
1513         OSAL_MEMSET(&lld_tlv_buf, 0, sizeof(lld_tlv_buf));
1514         SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_VALID, 1);
1515         SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_MANDATORY,
1516                       !!p_params->discard_mandatory_tlv);
1517         SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_LENGTH,
1518                       p_params->buf_size);
1519         len = ECORE_LLDP_SYS_TLV_SIZE / 2;
1520         OSAL_MEMCPY(lld_tlv_buf.data, p_params->buf, len);
1521
1522         addr = p_hwfn->mcp_info->port_addr +
1523                 offsetof(struct public_port, system_lldp_tlvs_buf);
1524         ecore_memcpy_to(p_hwfn, p_ptt, addr, &lld_tlv_buf, sizeof(lld_tlv_buf));
1525
1526         if  (p_params->buf_size > len) {
1527                 addr = p_hwfn->mcp_info->port_addr +
1528                         offsetof(struct public_port, system_lldp_tlvs_buf2);
1529                 ecore_memcpy_to(p_hwfn, p_ptt, addr, &p_params->buf[len],
1530                                 ECORE_LLDP_SYS_TLV_SIZE / 2);
1531         }
1532
1533         rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LLDP,
1534                            mb_param, &mcp_resp, &mcp_param);
1535         if (rc != ECORE_SUCCESS)
1536                 DP_NOTICE(p_hwfn, false, "SET_LLDP failed, error = %d\n", rc);
1537
1538         return rc;
1539 }