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