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