net/qede/base: use the correct size value
[dpdk.git] / drivers / net / qede / base / ecore_dcbx.c
index 25ae21c..201b7d5 100644 (file)
@@ -114,6 +114,21 @@ ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
        }
 }
 
+u8 ecore_dcbx_get_dscp_value(struct ecore_hwfn *p_hwfn, u8 pri)
+{
+       struct ecore_dcbx_dscp_params *dscp = &p_hwfn->p_dcbx_info->get.dscp;
+       u8 i;
+
+       if (!dscp->enabled)
+               return ECORE_DCBX_DSCP_DISABLED;
+
+       for (i = 0; i < ECORE_DCBX_DSCP_SIZE; i++)
+               if (pri == dscp->dscp_pri_map[i])
+                       return i;
+
+       return ECORE_DCBX_DSCP_DISABLED;
+}
+
 static void
 ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
                      struct ecore_hwfn *p_hwfn,
@@ -121,29 +136,18 @@ ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
                      enum dcbx_protocol_type type,
                      enum ecore_pci_personality personality)
 {
-       struct ecore_dcbx_dscp_params *dscp = &p_hwfn->p_dcbx_info->get.dscp;
-
        /* PF update ramrod data */
        p_data->arr[type].enable = enable;
        p_data->arr[type].priority = prio;
        p_data->arr[type].tc = tc;
-       p_data->arr[type].dscp_enable = dscp->enabled;
-       if (p_data->arr[type].dscp_enable) {
-               u8 i;
-
-               for (i = 0; i < ECORE_DCBX_DSCP_SIZE; i++)
-                       if (prio == dscp->dscp_pri_map[i]) {
-                               p_data->arr[type].dscp_val = i;
-                               break;
-                       }
+       p_data->arr[type].dscp_val = ecore_dcbx_get_dscp_value(p_hwfn, prio);
+       if (p_data->arr[type].dscp_val == ECORE_DCBX_DSCP_DISABLED) {
+               p_data->arr[type].dscp_enable = false;
+               p_data->arr[type].dscp_val = 0;
+       } else {
+               p_data->arr[type].dscp_enable = true;
        }
-
-       if (enable && p_data->arr[type].dscp_enable)
-               p_data->arr[type].update = UPDATE_DCB_DSCP;
-       else if (enable)
-               p_data->arr[type].update = UPDATE_DCB;
-       else
-               p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
+       p_data->arr[type].update = UPDATE_DCB_DSCP;
 
        /* QM reconf data */
        if (p_hwfn->hw_info.personality == personality)
@@ -234,8 +238,8 @@ ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
                       int count, u8 dcbx_version)
 {
        enum dcbx_protocol_type type;
+       bool enable, ieee, eth_tlv;
        u8 tc, priority_map;
-       bool enable, ieee;
        u16 protocol_id;
        u8 priority;
        enum _ecore_status_t rc = ECORE_SUCCESS;
@@ -246,6 +250,7 @@ ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
                   count, pri_tc_tbl, dcbx_version);
 
        ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
+       eth_tlv = false;
        /* Parse APP TLV */
        for (i = 0; i < count; i++) {
                protocol_id = GET_MFW_FIELD(p_tbl[i].entry,
@@ -269,12 +274,23 @@ ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
                         * indication, but we only got here if there was an
                         * app tlv for the protocol, so dcbx must be enabled.
                         */
-                       enable = !(type == DCBX_PROTOCOL_ETH);
+                       if (type == DCBX_PROTOCOL_ETH) {
+                               enable = false;
+                               eth_tlv = true;
+                       } else {
+                               enable = true;
+                       }
 
                        ecore_dcbx_update_app_info(p_data, p_hwfn, enable,
                                                   priority, tc, type);
                }
        }
+
+       /* If Eth TLV is not detected, use UFP TC as default TC */
+       if (OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC,
+                         &p_hwfn->p_dev->mf_bits) && !eth_tlv)
+               p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
+
        /* Update ramrod protocol data and hw_info fields
         * with default info when corresponding APP TLV's are not detected.
         * The enabled field has a different logic for ethernet as only for
@@ -360,6 +376,12 @@ ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
                                          p_data->addr, p_data->size);
                        prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
                        suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
+               } else if (type == ECORE_DCBX_LLDP_TLVS) {
+                       ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_tlvs,
+                                         p_data->addr, p_data->size);
+                       prefix_seq_num = p_data->lldp_tlvs->prefix_seq_num;
+                       suffix_seq_num = p_data->lldp_tlvs->suffix_seq_num;
+
                } else {
                        ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
                                          p_data->addr, p_data->size);
@@ -417,7 +439,7 @@ ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
        p_params->app_error = GET_MFW_FIELD(p_app->flags, DCBX_APP_ERROR);
        p_params->num_app_entries = GET_MFW_FIELD(p_app->flags,
                                                  DCBX_APP_NUM_ENTRIES);
-       for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
+       for (i = 0; i < p_params->num_app_entries; i++) {
                entry = &p_params->app_entry[i];
                if (ieee) {
                        u8 sf_ieee;
@@ -570,7 +592,32 @@ ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
        params->remote.valid = true;
 }
 
-static enum _ecore_status_t
+static void  ecore_dcbx_get_dscp_params(struct ecore_hwfn *p_hwfn,
+                                       struct ecore_dcbx_get *params)
+{
+       struct ecore_dcbx_dscp_params *p_dscp;
+       struct dcb_dscp_map *p_dscp_map;
+       int i, j, entry;
+       u32 pri_map;
+
+       p_dscp = &params->dscp;
+       p_dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
+       p_dscp->enabled = GET_MFW_FIELD(p_dscp_map->flags, DCB_DSCP_ENABLE);
+
+       /* MFW encodes 64 dscp entries into 8 element array of u32 entries,
+        * where each entry holds the 4bit priority map for 8 dscp entries.
+        */
+       for (i = 0, entry = 0; i < ECORE_DCBX_DSCP_SIZE / 8; i++) {
+               pri_map = OSAL_BE32_TO_CPU(p_dscp_map->dscp_pri_map[i]);
+               DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "elem %d pri_map 0x%x\n",
+                          entry, pri_map);
+               for (j = 0; j < ECORE_DCBX_DSCP_SIZE / 8; j++, entry++)
+                       p_dscp->dscp_pri_map[entry] = (u32)(pri_map >>
+                                                          (j * 4)) & 0xf;
+       }
+}
+
+static void
 ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
                                  struct ecore_dcbx_get *params)
 {
@@ -593,7 +640,7 @@ ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
                p_operational->enabled = enabled;
                p_operational->valid = false;
                DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Dcbx is disabled\n");
-               return ECORE_INVAL;
+               return;
        }
 
        p_feat = &p_hwfn->p_dcbx_info->operational.features;
@@ -626,33 +673,6 @@ ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
        p_operational->err = err;
        p_operational->enabled = enabled;
        p_operational->valid = true;
-
-       return ECORE_SUCCESS;
-}
-
-static void  ecore_dcbx_get_dscp_params(struct ecore_hwfn *p_hwfn,
-                                       struct ecore_dcbx_get *params)
-{
-       struct ecore_dcbx_dscp_params *p_dscp;
-       struct dcb_dscp_map *p_dscp_map;
-       int i, j, entry;
-       u32 pri_map;
-
-       p_dscp = &params->dscp;
-       p_dscp_map = &p_hwfn->p_dcbx_info->dscp_map;
-       p_dscp->enabled = GET_MFW_FIELD(p_dscp_map->flags, DCB_DSCP_ENABLE);
-
-       /* MFW encodes 64 dscp entries into 8 element array of u32 entries,
-        * where each entry holds the 4bit priority map for 8 dscp entries.
-        */
-       for (i = 0, entry = 0; i < ECORE_DCBX_DSCP_SIZE / 8; i++) {
-               pri_map = OSAL_BE32_TO_CPU(p_dscp_map->dscp_pri_map[i]);
-               DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "elem %d pri_map 0x%x\n",
-                          entry, pri_map);
-               for (j = 0; j < ECORE_DCBX_DSCP_SIZE / 8; j++, entry++)
-                       p_dscp->dscp_pri_map[entry] = (u32)(pri_map >>
-                                                          (j * 4)) & 0xf;
-       }
 }
 
 static void ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
@@ -664,9 +684,9 @@ static void ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
 
        OSAL_MEMCPY(params->lldp_local.local_chassis_id,
                    p_local->local_chassis_id,
-                   OSAL_ARRAY_SIZE(p_local->local_chassis_id));
+                   sizeof(params->lldp_local.local_chassis_id));
        OSAL_MEMCPY(params->lldp_local.local_port_id, p_local->local_port_id,
-                   OSAL_ARRAY_SIZE(p_local->local_port_id));
+                   sizeof(params->lldp_local.local_port_id));
 }
 
 static void ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
@@ -678,9 +698,9 @@ static void ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
 
        OSAL_MEMCPY(params->lldp_remote.peer_chassis_id,
                    p_remote->peer_chassis_id,
-                   OSAL_ARRAY_SIZE(p_remote->peer_chassis_id));
+                   sizeof(params->lldp_remote.peer_chassis_id));
        OSAL_MEMCPY(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
-                   OSAL_ARRAY_SIZE(p_remote->peer_port_id));
+                   sizeof(params->lldp_remote.peer_port_id));
 }
 
 static enum _ecore_status_t
@@ -884,7 +904,9 @@ ecore_dcbx_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
        /* Update the DSCP to TC mapping bit if required */
        if ((type == ECORE_DCBX_OPERATIONAL_MIB) &&
            p_hwfn->p_dcbx_info->dscp_nig_update) {
-               ecore_wr(p_hwfn, p_ptt, NIG_REG_DSCP_TO_TC_MAP_ENABLE, 0x1);
+               u8 val = !!p_hwfn->p_dcbx_info->get.dscp.enabled;
+
+               ecore_wr(p_hwfn, p_ptt, NIG_REG_DSCP_TO_TC_MAP_ENABLE, val);
                p_hwfn->p_dcbx_info->dscp_nig_update = false;
        }
 
@@ -909,8 +931,7 @@ enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
        return ECORE_SUCCESS;
 }
 
-void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn,
-                         struct ecore_dcbx_info *p_dcbx_info)
+void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn)
 {
        OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
 }
@@ -933,8 +954,6 @@ void ecore_dcbx_set_pf_update_params(struct ecore_dcbx_results *p_src,
        struct protocol_dcb_data *p_dcb_data;
        u8 update_flag;
 
-       p_dest->pf_id = p_src->pf_id;
-
        update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
        p_dest->update_eth_dcb_data_mode = update_flag;
        update_flag = p_src->arr[DCBX_PROTOCOL_IWARP].update;
@@ -957,16 +976,15 @@ enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
                return ECORE_INVAL;
 
        p_ptt = ecore_ptt_acquire(p_hwfn);
-       if (!p_ptt) {
-               rc = ECORE_TIMEOUT;
-               DP_ERR(p_hwfn, "rc = %d\n", rc);
-               return rc;
-       }
+       if (!p_ptt)
+               return ECORE_TIMEOUT;
 
        rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
        if (rc != ECORE_SUCCESS)
                goto out;
 
+       ecore_dcbx_get_dscp_params(p_hwfn, p_get);
+
        rc = ecore_dcbx_get_params(p_hwfn, p_get, type);
 
 out:
@@ -1076,7 +1094,7 @@ ecore_dcbx_set_app_data(struct ecore_hwfn *p_hwfn,
        p_app->flags |= (u32)p_params->num_app_entries <<
                        DCBX_APP_NUM_ENTRIES_OFFSET;
 
-       for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
+       for (i = 0; i < p_params->num_app_entries; i++) {
                entry = &p_app->app_pri_tbl[i].entry;
                *entry = 0;
                if (ieee) {
@@ -1127,7 +1145,7 @@ ecore_dcbx_set_app_data(struct ecore_hwfn *p_hwfn,
        DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "flags = 0x%x\n", p_app->flags);
 }
 
-static enum _ecore_status_t
+static void
 ecore_dcbx_set_local_params(struct ecore_hwfn *p_hwfn,
                            struct dcbx_local_params *local_admin,
                            struct ecore_dcbx_set *params)
@@ -1157,8 +1175,6 @@ ecore_dcbx_set_local_params(struct ecore_hwfn *p_hwfn,
        if (params->override_flags & ECORE_DCBX_OVERRIDE_APP_CFG)
                ecore_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
                                        &params->config.params, ieee);
-
-       return ECORE_SUCCESS;
 }
 
 static enum _ecore_status_t
@@ -1188,6 +1204,12 @@ ecore_dcbx_set_dscp_params(struct ecore_hwfn *p_hwfn,
        p_hwfn->p_dcbx_info->dscp_nig_update = true;
 
        DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "flags = 0x%x\n", p_dscp_map->flags);
+       DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
+                  "pri_map[] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
+                  p_dscp_map->dscp_pri_map[0], p_dscp_map->dscp_pri_map[1],
+                  p_dscp_map->dscp_pri_map[2], p_dscp_map->dscp_pri_map[3],
+                  p_dscp_map->dscp_pri_map[4], p_dscp_map->dscp_pri_map[5],
+                  p_dscp_map->dscp_pri_map[6], p_dscp_map->dscp_pri_map[7]);
 
        return ECORE_SUCCESS;
 }
@@ -1203,15 +1225,10 @@ enum _ecore_status_t ecore_dcbx_config_params(struct ecore_hwfn *p_hwfn,
        u32 resp = 0, param = 0;
        enum _ecore_status_t rc = ECORE_SUCCESS;
 
-       if (!hw_commit) {
-               OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set, params,
-                           sizeof(p_hwfn->p_dcbx_info->set));
+       OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set, params,
+                   sizeof(p_hwfn->p_dcbx_info->set));
+       if (!hw_commit)
                return ECORE_SUCCESS;
-       }
-
-       /* clear set-parmas cache */
-       OSAL_MEMSET(&p_hwfn->p_dcbx_info->set, 0,
-                   sizeof(struct ecore_dcbx_set));
 
        OSAL_MEMSET(&local_admin, 0, sizeof(local_admin));
        ecore_dcbx_set_local_params(p_hwfn, &local_admin, params);
@@ -1257,10 +1274,8 @@ enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
 
        dcbx_info = OSAL_ALLOC(p_hwfn->p_dev, GFP_KERNEL,
                               sizeof(*dcbx_info));
-       if (!dcbx_info) {
-               DP_ERR(p_hwfn, "Failed to allocate struct ecore_dcbx_info\n");
+       if (!dcbx_info)
                return ECORE_NOMEM;
-       }
 
        OSAL_MEMSET(dcbx_info, 0, sizeof(*dcbx_info));
        rc = ecore_dcbx_query_params(p_hwfn, dcbx_info,
@@ -1280,9 +1295,12 @@ enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
                p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
 
        p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
+       OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.dscp,
+                   &p_hwfn->p_dcbx_info->get.dscp,
+                   sizeof(struct ecore_dcbx_dscp_params));
        OSAL_MEMCPY(&p_hwfn->p_dcbx_info->set.config.params,
                    &dcbx_info->operational.params,
-                   sizeof(struct ecore_dcbx_admin_params));
+                   sizeof(p_hwfn->p_dcbx_info->set.config.params));
        p_hwfn->p_dcbx_info->set.config.valid = true;
 
        OSAL_MEMCPY(params, &p_hwfn->p_dcbx_info->set,
@@ -1292,3 +1310,230 @@ enum _ecore_status_t ecore_dcbx_get_config_params(struct ecore_hwfn *p_hwfn,
 
        return ECORE_SUCCESS;
 }
+
+enum _ecore_status_t ecore_lldp_register_tlv(struct ecore_hwfn *p_hwfn,
+                                            struct ecore_ptt *p_ptt,
+                                            enum ecore_lldp_agent agent,
+                                            u8 tlv_type)
+{
+       u32 mb_param = 0, mcp_resp = 0, mcp_param = 0, val = 0;
+       enum _ecore_status_t rc = ECORE_SUCCESS;
+
+       switch (agent) {
+       case ECORE_LLDP_NEAREST_BRIDGE:
+               val = LLDP_NEAREST_BRIDGE;
+               break;
+       case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
+               val = LLDP_NEAREST_NON_TPMR_BRIDGE;
+               break;
+       case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
+               val = LLDP_NEAREST_CUSTOMER_BRIDGE;
+               break;
+       default:
+               DP_ERR(p_hwfn, "Invalid agent type %d\n", agent);
+               return ECORE_INVAL;
+       }
+
+       SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_AGENT, val);
+       SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_TLV_RX_TYPE, tlv_type);
+
+       rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_REGISTER_LLDP_TLVS_RX,
+                          mb_param, &mcp_resp, &mcp_param);
+       if (rc != ECORE_SUCCESS)
+               DP_NOTICE(p_hwfn, false, "Failed to register TLV\n");
+
+       return rc;
+}
+
+enum _ecore_status_t
+ecore_lldp_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
+{
+       struct ecore_dcbx_mib_meta_data data;
+       enum _ecore_status_t rc = ECORE_SUCCESS;
+       struct lldp_received_tlvs_s tlvs;
+       int i;
+
+       for (i = 0; i < LLDP_MAX_LLDP_AGENTS; i++) {
+               OSAL_MEM_ZERO(&data, sizeof(data));
+               data.addr = p_hwfn->mcp_info->port_addr +
+                           offsetof(struct public_port, lldp_received_tlvs[i]);
+               data.lldp_tlvs = &tlvs;
+               data.size = sizeof(tlvs);
+               rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data,
+                                        ECORE_DCBX_LLDP_TLVS);
+               if (rc != ECORE_SUCCESS) {
+                       DP_NOTICE(p_hwfn, false, "Failed to read lldp TLVs\n");
+                       return rc;
+               }
+
+               if (!tlvs.length)
+                       continue;
+
+               for (i = 0; i < MAX_TLV_BUFFER; i++)
+                       tlvs.tlvs_buffer[i] =
+                               OSAL_CPU_TO_BE32(tlvs.tlvs_buffer[i]);
+
+               OSAL_LLDP_RX_TLVS(p_hwfn, tlvs.tlvs_buffer, tlvs.length);
+       }
+
+       return rc;
+}
+
+enum _ecore_status_t
+ecore_lldp_get_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
+                     struct ecore_lldp_config_params *p_params)
+{
+       struct lldp_config_params_s lldp_params;
+       u32 addr, val;
+       int i;
+
+       switch (p_params->agent) {
+       case ECORE_LLDP_NEAREST_BRIDGE:
+               val = LLDP_NEAREST_BRIDGE;
+               break;
+       case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
+               val = LLDP_NEAREST_NON_TPMR_BRIDGE;
+               break;
+       case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
+               val = LLDP_NEAREST_CUSTOMER_BRIDGE;
+               break;
+       default:
+               DP_ERR(p_hwfn, "Invalid agent type %d\n", p_params->agent);
+               return ECORE_INVAL;
+       }
+
+       addr = p_hwfn->mcp_info->port_addr +
+                       offsetof(struct public_port, lldp_config_params[val]);
+
+       ecore_memcpy_from(p_hwfn, p_ptt, &lldp_params, addr,
+                         sizeof(lldp_params));
+
+       p_params->tx_interval = GET_MFW_FIELD(lldp_params.config,
+                                             LLDP_CONFIG_TX_INTERVAL);
+       p_params->tx_hold = GET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_HOLD);
+       p_params->tx_credit = GET_MFW_FIELD(lldp_params.config,
+                                           LLDP_CONFIG_MAX_CREDIT);
+       p_params->rx_enable = GET_MFW_FIELD(lldp_params.config,
+                                           LLDP_CONFIG_ENABLE_RX);
+       p_params->tx_enable = GET_MFW_FIELD(lldp_params.config,
+                                           LLDP_CONFIG_ENABLE_TX);
+
+       OSAL_MEMCPY(p_params->chassis_id_tlv, lldp_params.local_chassis_id,
+                   sizeof(p_params->chassis_id_tlv));
+       for (i = 0; i < ECORE_LLDP_CHASSIS_ID_STAT_LEN; i++)
+               p_params->chassis_id_tlv[i] =
+                               OSAL_BE32_TO_CPU(p_params->chassis_id_tlv[i]);
+
+       OSAL_MEMCPY(p_params->port_id_tlv, lldp_params.local_port_id,
+                   sizeof(p_params->port_id_tlv));
+       for (i = 0; i < ECORE_LLDP_PORT_ID_STAT_LEN; i++)
+               p_params->port_id_tlv[i] =
+                               OSAL_BE32_TO_CPU(p_params->port_id_tlv[i]);
+
+       return ECORE_SUCCESS;
+}
+
+enum _ecore_status_t
+ecore_lldp_set_params(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
+                     struct ecore_lldp_config_params *p_params)
+{
+       u32 mb_param = 0, mcp_resp = 0, mcp_param = 0;
+       struct lldp_config_params_s lldp_params;
+       enum _ecore_status_t rc = ECORE_SUCCESS;
+       u32 addr, val;
+       int i;
+
+       switch (p_params->agent) {
+       case ECORE_LLDP_NEAREST_BRIDGE:
+               val = LLDP_NEAREST_BRIDGE;
+               break;
+       case ECORE_LLDP_NEAREST_NON_TPMR_BRIDGE:
+               val = LLDP_NEAREST_NON_TPMR_BRIDGE;
+               break;
+       case ECORE_LLDP_NEAREST_CUSTOMER_BRIDGE:
+               val = LLDP_NEAREST_CUSTOMER_BRIDGE;
+               break;
+       default:
+               DP_ERR(p_hwfn, "Invalid agent type %d\n", p_params->agent);
+               return ECORE_INVAL;
+       }
+
+       SET_MFW_FIELD(mb_param, DRV_MB_PARAM_LLDP_AGENT, val);
+       addr = p_hwfn->mcp_info->port_addr +
+                       offsetof(struct public_port, lldp_config_params[val]);
+
+       OSAL_MEMSET(&lldp_params, 0, sizeof(lldp_params));
+       SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_TX_INTERVAL,
+                     p_params->tx_interval);
+       SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_HOLD, p_params->tx_hold);
+       SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_MAX_CREDIT,
+                     p_params->tx_credit);
+       SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_ENABLE_RX,
+                     !!p_params->rx_enable);
+       SET_MFW_FIELD(lldp_params.config, LLDP_CONFIG_ENABLE_TX,
+                     !!p_params->tx_enable);
+
+       for (i = 0; i < ECORE_LLDP_CHASSIS_ID_STAT_LEN; i++)
+               p_params->chassis_id_tlv[i] =
+                               OSAL_CPU_TO_BE32(p_params->chassis_id_tlv[i]);
+       OSAL_MEMCPY(lldp_params.local_chassis_id, p_params->chassis_id_tlv,
+                   sizeof(lldp_params.local_chassis_id));
+
+       for (i = 0; i < ECORE_LLDP_PORT_ID_STAT_LEN; i++)
+               p_params->port_id_tlv[i] =
+                               OSAL_CPU_TO_BE32(p_params->port_id_tlv[i]);
+       OSAL_MEMCPY(lldp_params.local_port_id, p_params->port_id_tlv,
+                   sizeof(lldp_params.local_port_id));
+
+       ecore_memcpy_to(p_hwfn, p_ptt, addr, &lldp_params, sizeof(lldp_params));
+
+       rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LLDP,
+                          mb_param, &mcp_resp, &mcp_param);
+       if (rc != ECORE_SUCCESS)
+               DP_NOTICE(p_hwfn, false, "SET_LLDP failed, error = %d\n", rc);
+
+       return rc;
+}
+
+enum _ecore_status_t
+ecore_lldp_set_system_tlvs(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
+                          struct ecore_lldp_sys_tlvs *p_params)
+{
+       u32 mb_param = 0, mcp_resp = 0, mcp_param = 0;
+       enum _ecore_status_t rc = ECORE_SUCCESS;
+       struct lldp_system_tlvs_buffer_s lld_tlv_buf;
+       u32 addr, *p_val;
+       u8 len;
+       int i;
+
+       p_val = (u32 *)p_params->buf;
+       for (i = 0; i < ECORE_LLDP_SYS_TLV_SIZE / 4; i++)
+               p_val[i] = OSAL_CPU_TO_BE32(p_val[i]);
+
+       OSAL_MEMSET(&lld_tlv_buf, 0, sizeof(lld_tlv_buf));
+       SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_VALID, 1);
+       SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_MANDATORY,
+                     !!p_params->discard_mandatory_tlv);
+       SET_MFW_FIELD(lld_tlv_buf.flags, LLDP_SYSTEM_TLV_LENGTH,
+                     p_params->buf_size);
+       len = ECORE_LLDP_SYS_TLV_SIZE / 2;
+       OSAL_MEMCPY(lld_tlv_buf.data, p_params->buf, len);
+
+       addr = p_hwfn->mcp_info->port_addr +
+               offsetof(struct public_port, system_lldp_tlvs_buf);
+       ecore_memcpy_to(p_hwfn, p_ptt, addr, &lld_tlv_buf, sizeof(lld_tlv_buf));
+
+       if  (p_params->buf_size > len) {
+               addr = p_hwfn->mcp_info->port_addr +
+                       offsetof(struct public_port, system_lldp_tlvs_buf2);
+               ecore_memcpy_to(p_hwfn, p_ptt, addr, &p_params->buf[len],
+                               ECORE_LLDP_SYS_TLV_SIZE / 2);
+       }
+
+       rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LLDP,
+                          mb_param, &mcp_resp, &mcp_param);
+       if (rc != ECORE_SUCCESS)
+               DP_NOTICE(p_hwfn, false, "SET_LLDP failed, error = %d\n", rc);
+
+       return rc;
+}