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