114b24e2bSVaishali Kulkarni /*
214b24e2bSVaishali Kulkarni * CDDL HEADER START
314b24e2bSVaishali Kulkarni *
414b24e2bSVaishali Kulkarni * The contents of this file are subject to the terms of the
514b24e2bSVaishali Kulkarni * Common Development and Distribution License, v.1,  (the "License").
614b24e2bSVaishali Kulkarni * You may not use this file except in compliance with the License.
714b24e2bSVaishali Kulkarni *
814b24e2bSVaishali Kulkarni * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
914b24e2bSVaishali Kulkarni * or http://opensource.org/licenses/CDDL-1.0.
1014b24e2bSVaishali Kulkarni * See the License for the specific language governing permissions
1114b24e2bSVaishali Kulkarni * and limitations under the License.
1214b24e2bSVaishali Kulkarni *
1314b24e2bSVaishali Kulkarni * When distributing Covered Code, include this CDDL HEADER in each
1414b24e2bSVaishali Kulkarni * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1514b24e2bSVaishali Kulkarni * If applicable, add the following below this CDDL HEADER, with the
1614b24e2bSVaishali Kulkarni * fields enclosed by brackets "[]" replaced with your own identifying
1714b24e2bSVaishali Kulkarni * information: Portions Copyright [yyyy] [name of copyright owner]
1814b24e2bSVaishali Kulkarni *
1914b24e2bSVaishali Kulkarni * CDDL HEADER END
2014b24e2bSVaishali Kulkarni */
2114b24e2bSVaishali Kulkarni 
2214b24e2bSVaishali Kulkarni /*
2314b24e2bSVaishali Kulkarni * Copyright 2014-2017 Cavium, Inc.
2414b24e2bSVaishali Kulkarni * The contents of this file are subject to the terms of the Common Development
2514b24e2bSVaishali Kulkarni * and Distribution License, v.1,  (the "License").
2614b24e2bSVaishali Kulkarni 
2714b24e2bSVaishali Kulkarni * You may not use this file except in compliance with the License.
2814b24e2bSVaishali Kulkarni 
2914b24e2bSVaishali Kulkarni * You can obtain a copy of the License at available
3014b24e2bSVaishali Kulkarni * at http://opensource.org/licenses/CDDL-1.0
3114b24e2bSVaishali Kulkarni 
3214b24e2bSVaishali Kulkarni * See the License for the specific language governing permissions and
3314b24e2bSVaishali Kulkarni * limitations under the License.
3414b24e2bSVaishali Kulkarni */
3514b24e2bSVaishali Kulkarni 
36*b68ddc76SJohn Levon /*
37*b68ddc76SJohn Levon  * Copyright 2018 Joyent, Inc.
38*b68ddc76SJohn Levon  */
39*b68ddc76SJohn Levon 
4014b24e2bSVaishali Kulkarni #include "bcm_osal.h"
4114b24e2bSVaishali Kulkarni #include "ecore.h"
4214b24e2bSVaishali Kulkarni #include "ecore_sp_commands.h"
4314b24e2bSVaishali Kulkarni #include "ecore_dcbx.h"
4414b24e2bSVaishali Kulkarni #include "ecore_cxt.h"
4514b24e2bSVaishali Kulkarni #include "ecore_gtt_reg_addr.h"
4614b24e2bSVaishali Kulkarni #include "ecore_iro.h"
4714b24e2bSVaishali Kulkarni #ifdef CONFIG_ECORE_ROCE
4814b24e2bSVaishali Kulkarni #include "ecore_roce.h"
4914b24e2bSVaishali Kulkarni #endif
5014b24e2bSVaishali Kulkarni #include "ecore_iov_api.h"
5114b24e2bSVaishali Kulkarni 
5214b24e2bSVaishali Kulkarni #define ECORE_DCBX_MAX_MIB_READ_TRY	(100)
5314b24e2bSVaishali Kulkarni #define ECORE_ETH_TYPE_DEFAULT		(0)
5414b24e2bSVaishali Kulkarni #define ECORE_ETH_TYPE_ROCE		(0x8915)
5514b24e2bSVaishali Kulkarni #define ECORE_UDP_PORT_TYPE_ROCE_V2	(0x12B7)
5614b24e2bSVaishali Kulkarni #define ECORE_ETH_TYPE_FCOE		(0x8906)
5714b24e2bSVaishali Kulkarni #define ECORE_TCP_PORT_ISCSI		(0xCBC)
5814b24e2bSVaishali Kulkarni 
5914b24e2bSVaishali Kulkarni #define ECORE_DCBX_INVALID_PRIORITY	0xFF
6014b24e2bSVaishali Kulkarni 
6114b24e2bSVaishali Kulkarni /* Get Traffic Class from priority traffic class table, 4 bits represent
6214b24e2bSVaishali Kulkarni  * the traffic class corresponding to the priority.
6314b24e2bSVaishali Kulkarni  */
6414b24e2bSVaishali Kulkarni #define ECORE_DCBX_PRIO2TC(prio_tc_tbl, prio) \
6514b24e2bSVaishali Kulkarni 		((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
6614b24e2bSVaishali Kulkarni 
ecore_dcbx_app_ethtype(u32 app_info_bitmap)6714b24e2bSVaishali Kulkarni static bool ecore_dcbx_app_ethtype(u32 app_info_bitmap)
6814b24e2bSVaishali Kulkarni {
6914b24e2bSVaishali Kulkarni 	return !!(ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
7014b24e2bSVaishali Kulkarni 		  DCBX_APP_SF_ETHTYPE);
7114b24e2bSVaishali Kulkarni }
7214b24e2bSVaishali Kulkarni 
ecore_dcbx_ieee_app_ethtype(u32 app_info_bitmap)7314b24e2bSVaishali Kulkarni static bool ecore_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
7414b24e2bSVaishali Kulkarni {
7514b24e2bSVaishali Kulkarni 	u8 mfw_val = ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
7614b24e2bSVaishali Kulkarni 
7714b24e2bSVaishali Kulkarni 	/* Old MFW */
7814b24e2bSVaishali Kulkarni 	if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
7914b24e2bSVaishali Kulkarni 		return ecore_dcbx_app_ethtype(app_info_bitmap);
8014b24e2bSVaishali Kulkarni 
8114b24e2bSVaishali Kulkarni 	return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
8214b24e2bSVaishali Kulkarni }
8314b24e2bSVaishali Kulkarni 
ecore_dcbx_app_port(u32 app_info_bitmap)8414b24e2bSVaishali Kulkarni static bool ecore_dcbx_app_port(u32 app_info_bitmap)
8514b24e2bSVaishali Kulkarni {
8614b24e2bSVaishali Kulkarni 	return !!(ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
8714b24e2bSVaishali Kulkarni 		  DCBX_APP_SF_PORT);
8814b24e2bSVaishali Kulkarni }
8914b24e2bSVaishali Kulkarni 
ecore_dcbx_ieee_app_port(u32 app_info_bitmap,u8 type)9014b24e2bSVaishali Kulkarni static bool ecore_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
9114b24e2bSVaishali Kulkarni {
9214b24e2bSVaishali Kulkarni 	u8 mfw_val = ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
9314b24e2bSVaishali Kulkarni 
9414b24e2bSVaishali Kulkarni 	/* Old MFW */
9514b24e2bSVaishali Kulkarni 	if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
9614b24e2bSVaishali Kulkarni 		return ecore_dcbx_app_port(app_info_bitmap);
9714b24e2bSVaishali Kulkarni 
9814b24e2bSVaishali Kulkarni 	return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
9914b24e2bSVaishali Kulkarni }
10014b24e2bSVaishali Kulkarni 
ecore_dcbx_default_tlv(u32 app_info_bitmap,u16 proto_id,bool ieee)10114b24e2bSVaishali Kulkarni static bool ecore_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
10214b24e2bSVaishali Kulkarni {
10314b24e2bSVaishali Kulkarni 	bool ethtype;
10414b24e2bSVaishali Kulkarni 
10514b24e2bSVaishali Kulkarni 	if (ieee)
10614b24e2bSVaishali Kulkarni 		ethtype = ecore_dcbx_ieee_app_ethtype(app_info_bitmap);
10714b24e2bSVaishali Kulkarni 	else
10814b24e2bSVaishali Kulkarni 		ethtype = ecore_dcbx_app_ethtype(app_info_bitmap);
10914b24e2bSVaishali Kulkarni 
11014b24e2bSVaishali Kulkarni 	return !!(ethtype && (proto_id == ECORE_ETH_TYPE_DEFAULT));
11114b24e2bSVaishali Kulkarni }
11214b24e2bSVaishali Kulkarni 
ecore_dcbx_iscsi_tlv(u32 app_info_bitmap,u16 proto_id,bool ieee)11314b24e2bSVaishali Kulkarni static bool ecore_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
11414b24e2bSVaishali Kulkarni {
11514b24e2bSVaishali Kulkarni 	bool port;
11614b24e2bSVaishali Kulkarni 
11714b24e2bSVaishali Kulkarni 	if (ieee)
11814b24e2bSVaishali Kulkarni 		port = ecore_dcbx_ieee_app_port(app_info_bitmap,
11914b24e2bSVaishali Kulkarni 						DCBX_APP_SF_IEEE_TCP_PORT);
12014b24e2bSVaishali Kulkarni 	else
12114b24e2bSVaishali Kulkarni 		port = ecore_dcbx_app_port(app_info_bitmap);
12214b24e2bSVaishali Kulkarni 
12314b24e2bSVaishali Kulkarni 	return !!(port && (proto_id == ECORE_TCP_PORT_ISCSI));
12414b24e2bSVaishali Kulkarni }
12514b24e2bSVaishali Kulkarni 
ecore_dcbx_fcoe_tlv(u32 app_info_bitmap,u16 proto_id,bool ieee)12614b24e2bSVaishali Kulkarni static bool ecore_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
12714b24e2bSVaishali Kulkarni {
12814b24e2bSVaishali Kulkarni 	bool ethtype;
12914b24e2bSVaishali Kulkarni 
13014b24e2bSVaishali Kulkarni 	if (ieee)
13114b24e2bSVaishali Kulkarni 		ethtype = ecore_dcbx_ieee_app_ethtype(app_info_bitmap);
13214b24e2bSVaishali Kulkarni 	else
13314b24e2bSVaishali Kulkarni 		ethtype = ecore_dcbx_app_ethtype(app_info_bitmap);
13414b24e2bSVaishali Kulkarni 
13514b24e2bSVaishali Kulkarni 	return !!(ethtype && (proto_id == ECORE_ETH_TYPE_FCOE));
13614b24e2bSVaishali Kulkarni }
13714b24e2bSVaishali Kulkarni 
ecore_dcbx_roce_tlv(u32 app_info_bitmap,u16 proto_id,bool ieee)13814b24e2bSVaishali Kulkarni static bool ecore_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
13914b24e2bSVaishali Kulkarni {
14014b24e2bSVaishali Kulkarni 	bool ethtype;
14114b24e2bSVaishali Kulkarni 
14214b24e2bSVaishali Kulkarni 	if (ieee)
14314b24e2bSVaishali Kulkarni 		ethtype = ecore_dcbx_ieee_app_ethtype(app_info_bitmap);
14414b24e2bSVaishali Kulkarni 	else
14514b24e2bSVaishali Kulkarni 		ethtype = ecore_dcbx_app_ethtype(app_info_bitmap);
14614b24e2bSVaishali Kulkarni 
14714b24e2bSVaishali Kulkarni 	return !!(ethtype && (proto_id == ECORE_ETH_TYPE_ROCE));
14814b24e2bSVaishali Kulkarni }
14914b24e2bSVaishali Kulkarni 
ecore_dcbx_roce_v2_tlv(u32 app_info_bitmap,u16 proto_id,bool ieee)15014b24e2bSVaishali Kulkarni static bool ecore_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
15114b24e2bSVaishali Kulkarni {
15214b24e2bSVaishali Kulkarni 	bool port;
15314b24e2bSVaishali Kulkarni 
15414b24e2bSVaishali Kulkarni 	if (ieee)
15514b24e2bSVaishali Kulkarni 		port = ecore_dcbx_ieee_app_port(app_info_bitmap,
15614b24e2bSVaishali Kulkarni 						DCBX_APP_SF_IEEE_UDP_PORT);
15714b24e2bSVaishali Kulkarni 	else
15814b24e2bSVaishali Kulkarni 		port = ecore_dcbx_app_port(app_info_bitmap);
15914b24e2bSVaishali Kulkarni 
16014b24e2bSVaishali Kulkarni 	return !!(port && (proto_id == ECORE_UDP_PORT_TYPE_ROCE_V2));
16114b24e2bSVaishali Kulkarni }
16214b24e2bSVaishali Kulkarni 
ecore_dcbx_iwarp_tlv(struct ecore_hwfn * p_hwfn,u32 app_info_bitmap,u16 proto_id,bool ieee)16314b24e2bSVaishali Kulkarni static bool ecore_dcbx_iwarp_tlv(struct ecore_hwfn *p_hwfn, u32 app_info_bitmap,
16414b24e2bSVaishali Kulkarni 				 u16 proto_id, bool ieee)
16514b24e2bSVaishali Kulkarni {
16614b24e2bSVaishali Kulkarni 	bool port;
16714b24e2bSVaishali Kulkarni 
16814b24e2bSVaishali Kulkarni 	if (!p_hwfn->p_dcbx_info->iwarp_port)
16914b24e2bSVaishali Kulkarni 		return false;
17014b24e2bSVaishali Kulkarni 
17114b24e2bSVaishali Kulkarni 	if (ieee)
17214b24e2bSVaishali Kulkarni 		port = ecore_dcbx_ieee_app_port(app_info_bitmap,
17314b24e2bSVaishali Kulkarni 						DCBX_APP_SF_IEEE_TCP_PORT);
17414b24e2bSVaishali Kulkarni 	else
17514b24e2bSVaishali Kulkarni 		port = ecore_dcbx_app_port(app_info_bitmap);
17614b24e2bSVaishali Kulkarni 
17714b24e2bSVaishali Kulkarni 	return !!(port && (proto_id == p_hwfn->p_dcbx_info->iwarp_port));
17814b24e2bSVaishali Kulkarni }
17914b24e2bSVaishali Kulkarni 
18014b24e2bSVaishali Kulkarni static void
ecore_dcbx_dp_protocol(struct ecore_hwfn * p_hwfn,struct ecore_dcbx_results * p_data)18114b24e2bSVaishali Kulkarni ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
18214b24e2bSVaishali Kulkarni 		       struct ecore_dcbx_results *p_data)
18314b24e2bSVaishali Kulkarni {
18414b24e2bSVaishali Kulkarni 	enum dcbx_protocol_type id;
18514b24e2bSVaishali Kulkarni 	int i;
18614b24e2bSVaishali Kulkarni 
18714b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "DCBX negotiated: %d\n",
18814b24e2bSVaishali Kulkarni 		   p_data->dcbx_enabled);
18914b24e2bSVaishali Kulkarni 
19014b24e2bSVaishali Kulkarni 	for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
19114b24e2bSVaishali Kulkarni 		id = ecore_dcbx_app_update[i].id;
19214b24e2bSVaishali Kulkarni 
19314b24e2bSVaishali Kulkarni 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
19414b24e2bSVaishali Kulkarni 			   "%s info: update %d, enable %d, prio %d, tc %d, num_active_tc %d dscp_enable = %d dscp_val = %d\n",
19514b24e2bSVaishali Kulkarni 			   ecore_dcbx_app_update[i].name, p_data->arr[id].update,
19614b24e2bSVaishali Kulkarni 			   p_data->arr[id].enable, p_data->arr[id].priority,
19714b24e2bSVaishali Kulkarni 			   p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc,
19814b24e2bSVaishali Kulkarni 			   p_data->arr[id].dscp_enable,
19914b24e2bSVaishali Kulkarni 			   p_data->arr[id].dscp_val);
20014b24e2bSVaishali Kulkarni 	}
20114b24e2bSVaishali Kulkarni }
20214b24e2bSVaishali Kulkarni 
20314b24e2bSVaishali Kulkarni static void
ecore_dcbx_set_params(struct ecore_dcbx_results * p_data,struct ecore_hwfn * p_hwfn,bool enable,u8 prio,u8 tc,enum dcbx_protocol_type type,enum ecore_pci_personality personality)20414b24e2bSVaishali Kulkarni ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
20514b24e2bSVaishali Kulkarni 		      struct ecore_hwfn *p_hwfn,
20614b24e2bSVaishali Kulkarni 		      bool enable, u8 prio, u8 tc,
20714b24e2bSVaishali Kulkarni 		      enum dcbx_protocol_type type,
20814b24e2bSVaishali Kulkarni 		      enum ecore_pci_personality personality)
20914b24e2bSVaishali Kulkarni {
21014b24e2bSVaishali Kulkarni 	struct ecore_dcbx_dscp_params *dscp = &p_hwfn->p_dcbx_info->get.dscp;
21114b24e2bSVaishali Kulkarni 
21214b24e2bSVaishali Kulkarni 	/* PF update ramrod data */
21314b24e2bSVaishali Kulkarni 	p_data->arr[type].enable = enable;
21414b24e2bSVaishali Kulkarni 	p_data->arr[type].priority = prio;
21514b24e2bSVaishali Kulkarni 	p_data->arr[type].tc = tc;
21614b24e2bSVaishali Kulkarni 	p_data->arr[type].dscp_enable = dscp->enabled;
21714b24e2bSVaishali Kulkarni 	if (p_data->arr[type].dscp_enable) {
21814b24e2bSVaishali Kulkarni 		u8 i;
21914b24e2bSVaishali Kulkarni 
22014b24e2bSVaishali Kulkarni 		for (i = 0; i < ECORE_DCBX_DSCP_SIZE; i++)
22114b24e2bSVaishali Kulkarni 			if (prio == dscp->dscp_pri_map[i]) {
22214b24e2bSVaishali Kulkarni 				p_data->arr[type].dscp_val = i;
22314b24e2bSVaishali Kulkarni 				break;
22414b24e2bSVaishali Kulkarni 			}
22514b24e2bSVaishali Kulkarni 	}
22614b24e2bSVaishali Kulkarni 
22714b24e2bSVaishali Kulkarni 	if (enable && p_data->arr[type].dscp_enable)
22814b24e2bSVaishali Kulkarni 		p_data->arr[type].update = UPDATE_DCB_DSCP;
22914b24e2bSVaishali Kulkarni 	else if (enable)
23014b24e2bSVaishali Kulkarni 		p_data->arr[type].update = UPDATE_DCB;
23114b24e2bSVaishali Kulkarni 	else
23214b24e2bSVaishali Kulkarni 		p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
23314b24e2bSVaishali Kulkarni 
23414b24e2bSVaishali Kulkarni 	/* QM reconf data */
23514b24e2bSVaishali Kulkarni 	if (p_hwfn->hw_info.personality == personality)
23614b24e2bSVaishali Kulkarni 		p_hwfn->hw_info.offload_tc = tc;
23714b24e2bSVaishali Kulkarni }
23814b24e2bSVaishali Kulkarni 
23914b24e2bSVaishali Kulkarni /* Update app protocol data and hw_info fields with the TLV info */
24014b24e2bSVaishali Kulkarni static void
ecore_dcbx_update_app_info(struct ecore_dcbx_results * p_data,struct ecore_hwfn * p_hwfn,bool enable,u8 prio,u8 tc,enum dcbx_protocol_type type)24114b24e2bSVaishali Kulkarni ecore_dcbx_update_app_info(struct ecore_dcbx_results *p_data,
24214b24e2bSVaishali Kulkarni 			   struct ecore_hwfn *p_hwfn,
24314b24e2bSVaishali Kulkarni 			   bool enable, u8 prio, u8 tc,
24414b24e2bSVaishali Kulkarni 			   enum dcbx_protocol_type type)
24514b24e2bSVaishali Kulkarni {
24614b24e2bSVaishali Kulkarni 	enum ecore_pci_personality personality;
24714b24e2bSVaishali Kulkarni 	enum dcbx_protocol_type id;
24814b24e2bSVaishali Kulkarni 	int i;
24914b24e2bSVaishali Kulkarni 
25014b24e2bSVaishali Kulkarni 	for (i = 0; i < OSAL_ARRAY_SIZE(ecore_dcbx_app_update); i++) {
25114b24e2bSVaishali Kulkarni 		id = ecore_dcbx_app_update[i].id;
25214b24e2bSVaishali Kulkarni 
25314b24e2bSVaishali Kulkarni 		if (type != id)
25414b24e2bSVaishali Kulkarni 			continue;
25514b24e2bSVaishali Kulkarni 
25614b24e2bSVaishali Kulkarni 		personality = ecore_dcbx_app_update[i].personality;
25714b24e2bSVaishali Kulkarni 
25814b24e2bSVaishali Kulkarni 		ecore_dcbx_set_params(p_data, p_hwfn, enable,
25914b24e2bSVaishali Kulkarni 				      prio, tc, type, personality);
26014b24e2bSVaishali Kulkarni 	}
26114b24e2bSVaishali Kulkarni }
26214b24e2bSVaishali Kulkarni 
26314b24e2bSVaishali Kulkarni static enum _ecore_status_t
ecore_dcbx_get_app_priority(u8 pri_bitmap,u8 * priority)26414b24e2bSVaishali Kulkarni ecore_dcbx_get_app_priority(u8 pri_bitmap, u8 *priority)
26514b24e2bSVaishali Kulkarni {
26614b24e2bSVaishali Kulkarni 	u32 pri_mask, pri = ECORE_MAX_PFC_PRIORITIES;
26714b24e2bSVaishali Kulkarni 	u32 index = ECORE_MAX_PFC_PRIORITIES - 1;
26814b24e2bSVaishali Kulkarni 	enum _ecore_status_t rc = ECORE_SUCCESS;
26914b24e2bSVaishali Kulkarni 
27014b24e2bSVaishali Kulkarni 	/* Bitmap 1 corresponds to priority 0, return priority 0 */
27114b24e2bSVaishali Kulkarni 	if (pri_bitmap == 1) {
27214b24e2bSVaishali Kulkarni 		*priority = 0;
27314b24e2bSVaishali Kulkarni 		return rc;
27414b24e2bSVaishali Kulkarni 	}
27514b24e2bSVaishali Kulkarni 
27614b24e2bSVaishali Kulkarni 	/* Choose the highest priority */
27714b24e2bSVaishali Kulkarni 	while ((ECORE_MAX_PFC_PRIORITIES == pri) && index) {
27814b24e2bSVaishali Kulkarni 		pri_mask = 1 << index;
27914b24e2bSVaishali Kulkarni 		if (pri_bitmap & pri_mask)
28014b24e2bSVaishali Kulkarni 			pri = index;
28114b24e2bSVaishali Kulkarni 		index--;
28214b24e2bSVaishali Kulkarni 	}
28314b24e2bSVaishali Kulkarni 
28414b24e2bSVaishali Kulkarni 	if (pri < ECORE_MAX_PFC_PRIORITIES)
28514b24e2bSVaishali Kulkarni 		*priority = (u8)pri;
28614b24e2bSVaishali Kulkarni 	else
28714b24e2bSVaishali Kulkarni 		rc = ECORE_INVAL;
28814b24e2bSVaishali Kulkarni 
28914b24e2bSVaishali Kulkarni 	return rc;
29014b24e2bSVaishali Kulkarni }
29114b24e2bSVaishali Kulkarni 
29214b24e2bSVaishali Kulkarni static bool
ecore_dcbx_get_app_protocol_type(struct ecore_hwfn * p_hwfn,u32 app_prio_bitmap,u16 id,enum dcbx_protocol_type * type,bool ieee)29314b24e2bSVaishali Kulkarni ecore_dcbx_get_app_protocol_type(struct ecore_hwfn *p_hwfn,
29414b24e2bSVaishali Kulkarni 				 u32 app_prio_bitmap, u16 id,
29514b24e2bSVaishali Kulkarni 				 enum dcbx_protocol_type *type, bool ieee)
29614b24e2bSVaishali Kulkarni {
29714b24e2bSVaishali Kulkarni 	if (ecore_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
29814b24e2bSVaishali Kulkarni 		*type = DCBX_PROTOCOL_FCOE;
29914b24e2bSVaishali Kulkarni 	} else if (ecore_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
30014b24e2bSVaishali Kulkarni 		*type = DCBX_PROTOCOL_ROCE;
30114b24e2bSVaishali Kulkarni 	} else if (ecore_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
30214b24e2bSVaishali Kulkarni 		*type = DCBX_PROTOCOL_ISCSI;
30314b24e2bSVaishali Kulkarni 	} else if (ecore_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
30414b24e2bSVaishali Kulkarni 		*type = DCBX_PROTOCOL_ETH;
30514b24e2bSVaishali Kulkarni 	} else if (ecore_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
30614b24e2bSVaishali Kulkarni 		*type = DCBX_PROTOCOL_ROCE_V2;
30714b24e2bSVaishali Kulkarni 	} else if (ecore_dcbx_iwarp_tlv(p_hwfn, app_prio_bitmap, id, ieee)) {
30814b24e2bSVaishali Kulkarni 		*type = DCBX_PROTOCOL_IWARP;
30914b24e2bSVaishali Kulkarni 	} else {
31014b24e2bSVaishali Kulkarni 		*type = DCBX_MAX_PROTOCOL_TYPE;
31114b24e2bSVaishali Kulkarni 		DP_ERR(p_hwfn,
31214b24e2bSVaishali Kulkarni 		       "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
31314b24e2bSVaishali Kulkarni 		       id, app_prio_bitmap);
31414b24e2bSVaishali Kulkarni 		return false;
31514b24e2bSVaishali Kulkarni 	}
31614b24e2bSVaishali Kulkarni 
31714b24e2bSVaishali Kulkarni 	return true;
31814b24e2bSVaishali Kulkarni }
31914b24e2bSVaishali Kulkarni 
32014b24e2bSVaishali Kulkarni /*  Parse app TLV's to update TC information in hw_info structure for
32114b24e2bSVaishali Kulkarni  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
32214b24e2bSVaishali Kulkarni  */
32314b24e2bSVaishali Kulkarni static enum _ecore_status_t
ecore_dcbx_process_tlv(struct ecore_hwfn * p_hwfn,struct ecore_dcbx_results * p_data,struct dcbx_app_priority_entry * p_tbl,u32 pri_tc_tbl,int count,u8 dcbx_version)32414b24e2bSVaishali Kulkarni ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
32514b24e2bSVaishali Kulkarni 		       struct ecore_dcbx_results *p_data,
32614b24e2bSVaishali Kulkarni 		       struct dcbx_app_priority_entry *p_tbl, u32 pri_tc_tbl,
32714b24e2bSVaishali Kulkarni 		       int count, u8 dcbx_version)
32814b24e2bSVaishali Kulkarni {
32914b24e2bSVaishali Kulkarni 	enum dcbx_protocol_type type;
33014b24e2bSVaishali Kulkarni 	u8 tc, priority_map;
33114b24e2bSVaishali Kulkarni 	bool enable, ieee;
33214b24e2bSVaishali Kulkarni 	u16 protocol_id;
33314b24e2bSVaishali Kulkarni 	u8 priority;
33414b24e2bSVaishali Kulkarni 	enum _ecore_status_t rc = ECORE_SUCCESS;
33514b24e2bSVaishali Kulkarni 	int i;
33614b24e2bSVaishali Kulkarni 
33714b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
33814b24e2bSVaishali Kulkarni 		   "Num APP entries = %d pri_tc_tbl = 0x%x dcbx_version = %u\n",
33914b24e2bSVaishali Kulkarni 		   count, pri_tc_tbl, dcbx_version);
34014b24e2bSVaishali Kulkarni 
34114b24e2bSVaishali Kulkarni 	ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
34214b24e2bSVaishali Kulkarni 	/* Parse APP TLV */
34314b24e2bSVaishali Kulkarni 	for (i = 0; i < count; i++) {
34414b24e2bSVaishali Kulkarni 		protocol_id = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
34514b24e2bSVaishali Kulkarni 						  DCBX_APP_PROTOCOL_ID);
34614b24e2bSVaishali Kulkarni 		priority_map = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
34714b24e2bSVaishali Kulkarni 						   DCBX_APP_PRI_MAP);
34814b24e2bSVaishali Kulkarni 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Id = 0x%x pri_map = %u\n",
34914b24e2bSVaishali Kulkarni 			   protocol_id, priority_map);
35014b24e2bSVaishali Kulkarni 		rc = ecore_dcbx_get_app_priority(priority_map, &priority);
35114b24e2bSVaishali Kulkarni 		if (rc == ECORE_INVAL) {
35214b24e2bSVaishali Kulkarni 			DP_ERR(p_hwfn, "Invalid priority\n");
35314b24e2bSVaishali Kulkarni 			return ECORE_INVAL;
35414b24e2bSVaishali Kulkarni 		}
35514b24e2bSVaishali Kulkarni 
35614b24e2bSVaishali Kulkarni 		tc = ECORE_DCBX_PRIO2TC(pri_tc_tbl, priority);
35714b24e2bSVaishali Kulkarni 		if (ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
35814b24e2bSVaishali Kulkarni 						     protocol_id, &type,
35914b24e2bSVaishali Kulkarni 						     ieee)) {
36014b24e2bSVaishali Kulkarni 			/* ETH always have the enable bit reset, as it gets
36114b24e2bSVaishali Kulkarni 			 * vlan information per packet. For other protocols,
36214b24e2bSVaishali Kulkarni 			 * should be set according to the dcbx_enabled
36314b24e2bSVaishali Kulkarni 			 * indication, but we only got here if there was an
36414b24e2bSVaishali Kulkarni 			 * app tlv for the protocol, so dcbx must be enabled.
36514b24e2bSVaishali Kulkarni 			 */
36614b24e2bSVaishali Kulkarni 			enable = !(type == DCBX_PROTOCOL_ETH);
36714b24e2bSVaishali Kulkarni 
36814b24e2bSVaishali Kulkarni 			ecore_dcbx_update_app_info(p_data, p_hwfn, enable,
36914b24e2bSVaishali Kulkarni 						   priority, tc, type);
37014b24e2bSVaishali Kulkarni 		}
37114b24e2bSVaishali Kulkarni 	}
37214b24e2bSVaishali Kulkarni 
37314b24e2bSVaishali Kulkarni 	/* Update ramrod protocol data and hw_info fields
37414b24e2bSVaishali Kulkarni 	 * with default info when corresponding APP TLV's are not detected.
37514b24e2bSVaishali Kulkarni 	 * The enabled field has a different logic for ethernet as only for
37614b24e2bSVaishali Kulkarni 	 * ethernet dcb should disabled by default, as the information arrives
37714b24e2bSVaishali Kulkarni 	 * from the OS (unless an explicit app tlv was present).
37814b24e2bSVaishali Kulkarni 	 */
37914b24e2bSVaishali Kulkarni 	tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
38014b24e2bSVaishali Kulkarni 	priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
38114b24e2bSVaishali Kulkarni 	for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
38214b24e2bSVaishali Kulkarni 		if (p_data->arr[type].update)
38314b24e2bSVaishali Kulkarni 			continue;
38414b24e2bSVaishali Kulkarni 
38514b24e2bSVaishali Kulkarni 		enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
38614b24e2bSVaishali Kulkarni 		ecore_dcbx_update_app_info(p_data, p_hwfn, enable,
38714b24e2bSVaishali Kulkarni 					   priority, tc, type);
38814b24e2bSVaishali Kulkarni 	}
38914b24e2bSVaishali Kulkarni 
39014b24e2bSVaishali Kulkarni 	return ECORE_SUCCESS;
39114b24e2bSVaishali Kulkarni }
39214b24e2bSVaishali Kulkarni 
39314b24e2bSVaishali Kulkarni /* Parse app TLV's to update TC information in hw_info structure for
39414b24e2bSVaishali Kulkarni  * reconfiguring QM. Get protocol specific data for PF update ramrod command.
39514b24e2bSVaishali Kulkarni  */
39614b24e2bSVaishali Kulkarni static enum _ecore_status_t
ecore_dcbx_process_mib_info(struct ecore_hwfn * p_hwfn)39714b24e2bSVaishali Kulkarni ecore_dcbx_process_mib_info(struct ecore_hwfn *p_hwfn)
39814b24e2bSVaishali Kulkarni {
39914b24e2bSVaishali Kulkarni 	struct dcbx_app_priority_feature *p_app;
40014b24e2bSVaishali Kulkarni 	enum _ecore_status_t rc = ECORE_SUCCESS;
40114b24e2bSVaishali Kulkarni 	struct ecore_dcbx_results data = { 0 };
40214b24e2bSVaishali Kulkarni 	struct dcbx_app_priority_entry *p_tbl;
40314b24e2bSVaishali Kulkarni 	struct dcbx_ets_feature *p_ets;
40414b24e2bSVaishali Kulkarni 	struct ecore_hw_info *p_info;
40514b24e2bSVaishali Kulkarni 	u32 pri_tc_tbl, flags;
40614b24e2bSVaishali Kulkarni 	u8 dcbx_version;
40714b24e2bSVaishali Kulkarni 	int num_entries;
40814b24e2bSVaishali Kulkarni 
40914b24e2bSVaishali Kulkarni 	flags = p_hwfn->p_dcbx_info->operational.flags;
41014b24e2bSVaishali Kulkarni 	dcbx_version = ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
41114b24e2bSVaishali Kulkarni 
41214b24e2bSVaishali Kulkarni 	p_app = &p_hwfn->p_dcbx_info->operational.features.app;
41314b24e2bSVaishali Kulkarni 	p_tbl = p_app->app_pri_tbl;
41414b24e2bSVaishali Kulkarni 
41514b24e2bSVaishali Kulkarni 	p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
41614b24e2bSVaishali Kulkarni 	pri_tc_tbl = p_ets->pri_tc_tbl[0];
41714b24e2bSVaishali Kulkarni 
41814b24e2bSVaishali Kulkarni 	p_info = &p_hwfn->hw_info;
41914b24e2bSVaishali Kulkarni 	num_entries = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
42014b24e2bSVaishali Kulkarni 
42114b24e2bSVaishali Kulkarni 	rc = ecore_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
42214b24e2bSVaishali Kulkarni 				    num_entries, dcbx_version);
42314b24e2bSVaishali Kulkarni 	if (rc != ECORE_SUCCESS)
42414b24e2bSVaishali Kulkarni 		return rc;
42514b24e2bSVaishali Kulkarni 
42614b24e2bSVaishali Kulkarni 	p_info->num_active_tc = ECORE_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
42714b24e2bSVaishali Kulkarni 	p_hwfn->qm_info.ooo_tc = ECORE_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
42814b24e2bSVaishali Kulkarni 	data.pf_id = p_hwfn->rel_pf_id;
42914b24e2bSVaishali Kulkarni 	data.dcbx_enabled = !!dcbx_version;
43014b24e2bSVaishali Kulkarni 
43114b24e2bSVaishali Kulkarni 	ecore_dcbx_dp_protocol(p_hwfn, &data);
43214b24e2bSVaishali Kulkarni 
43314b24e2bSVaishali Kulkarni 	OSAL_MEMCPY(&p_hwfn->p_dcbx_info->results, &data,
43414b24e2bSVaishali Kulkarni 		    sizeof(struct ecore_dcbx_results));
43514b24e2bSVaishali Kulkarni 
43614b24e2bSVaishali Kulkarni 	return ECORE_SUCCESS;
43714b24e2bSVaishali Kulkarni }
43814b24e2bSVaishali Kulkarni 
43914b24e2bSVaishali Kulkarni static enum _ecore_status_t
ecore_dcbx_copy_mib(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_dcbx_mib_meta_data * p_data,enum ecore_mib_read_type type)44014b24e2bSVaishali Kulkarni ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
44114b24e2bSVaishali Kulkarni 		    struct ecore_ptt *p_ptt,
44214b24e2bSVaishali Kulkarni 		    struct ecore_dcbx_mib_meta_data *p_data,
44314b24e2bSVaishali Kulkarni 		    enum ecore_mib_read_type type)
44414b24e2bSVaishali Kulkarni {
44514b24e2bSVaishali Kulkarni 	enum _ecore_status_t rc = ECORE_SUCCESS;
44614b24e2bSVaishali Kulkarni 	u32 prefix_seq_num, suffix_seq_num;
44714b24e2bSVaishali Kulkarni 	int read_count = 0;
44814b24e2bSVaishali Kulkarni 
44914b24e2bSVaishali Kulkarni 	/* The data is considered to be valid only if both sequence numbers are
45014b24e2bSVaishali Kulkarni 	 * the same.
45114b24e2bSVaishali Kulkarni 	 */
45214b24e2bSVaishali Kulkarni 	do {
45314b24e2bSVaishali Kulkarni 		if (type == ECORE_DCBX_REMOTE_LLDP_MIB) {
45414b24e2bSVaishali Kulkarni 			ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
45514b24e2bSVaishali Kulkarni 					  p_data->addr, p_data->size);
45614b24e2bSVaishali Kulkarni 			prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
45714b24e2bSVaishali Kulkarni 			suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
45814b24e2bSVaishali Kulkarni 		} else {
45914b24e2bSVaishali Kulkarni 			ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
46014b24e2bSVaishali Kulkarni 					  p_data->addr, p_data->size);
46114b24e2bSVaishali Kulkarni 			prefix_seq_num = p_data->mib->prefix_seq_num;
46214b24e2bSVaishali Kulkarni 			suffix_seq_num = p_data->mib->suffix_seq_num;
46314b24e2bSVaishali Kulkarni 		}
46414b24e2bSVaishali Kulkarni 		read_count++;
46514b24e2bSVaishali Kulkarni 
46614b24e2bSVaishali Kulkarni 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
46714b24e2bSVaishali Kulkarni 			   "mib type = %d, try count = %d prefix seq num  = %d suffix seq num = %d\n",
46814b24e2bSVaishali Kulkarni 			   type, read_count, prefix_seq_num, suffix_seq_num);
46914b24e2bSVaishali Kulkarni 	} while ((prefix_seq_num != suffix_seq_num) &&
47014b24e2bSVaishali Kulkarni 		 (read_count < ECORE_DCBX_MAX_MIB_READ_TRY));
47114b24e2bSVaishali Kulkarni 
47214b24e2bSVaishali Kulkarni 	if (read_count >= ECORE_DCBX_MAX_MIB_READ_TRY) {
47314b24e2bSVaishali Kulkarni 		DP_ERR(p_hwfn,
47414b24e2bSVaishali Kulkarni 		       "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
47514b24e2bSVaishali Kulkarni 		       type, read_count, prefix_seq_num, suffix_seq_num);
47614b24e2bSVaishali Kulkarni 		rc = ECORE_IO;
47714b24e2bSVaishali Kulkarni 	}
47814b24e2bSVaishali Kulkarni 
47914b24e2bSVaishali Kulkarni 	return rc;
48014b24e2bSVaishali Kulkarni }
48114b24e2bSVaishali Kulkarni 
48214b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_priority_info(struct ecore_hwfn * p_hwfn,struct ecore_dcbx_app_prio * p_prio,struct ecore_dcbx_results * p_results)48314b24e2bSVaishali Kulkarni ecore_dcbx_get_priority_info(struct ecore_hwfn *p_hwfn,
48414b24e2bSVaishali Kulkarni 			     struct ecore_dcbx_app_prio *p_prio,
48514b24e2bSVaishali Kulkarni 			     struct ecore_dcbx_results *p_results)
48614b24e2bSVaishali Kulkarni {
48714b24e2bSVaishali Kulkarni 	u8 val;
48814b24e2bSVaishali Kulkarni 
48914b24e2bSVaishali Kulkarni 	p_prio->roce = ECORE_DCBX_INVALID_PRIORITY;
49014b24e2bSVaishali Kulkarni 	p_prio->roce_v2 = ECORE_DCBX_INVALID_PRIORITY;
49114b24e2bSVaishali Kulkarni 	p_prio->iscsi = ECORE_DCBX_INVALID_PRIORITY;
49214b24e2bSVaishali Kulkarni 	p_prio->fcoe = ECORE_DCBX_INVALID_PRIORITY;
49314b24e2bSVaishali Kulkarni 
49414b24e2bSVaishali Kulkarni 	if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
49514b24e2bSVaishali Kulkarni 	    p_results->arr[DCBX_PROTOCOL_ROCE].enable)
49614b24e2bSVaishali Kulkarni 		p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
49714b24e2bSVaishali Kulkarni 
49814b24e2bSVaishali Kulkarni 	if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
49914b24e2bSVaishali Kulkarni 	    p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
50014b24e2bSVaishali Kulkarni 		val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
50114b24e2bSVaishali Kulkarni 		p_prio->roce_v2 = val;
50214b24e2bSVaishali Kulkarni 	}
50314b24e2bSVaishali Kulkarni 
50414b24e2bSVaishali Kulkarni 	if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
50514b24e2bSVaishali Kulkarni 	    p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
50614b24e2bSVaishali Kulkarni 		p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
50714b24e2bSVaishali Kulkarni 
50814b24e2bSVaishali Kulkarni 	if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
50914b24e2bSVaishali Kulkarni 	    p_results->arr[DCBX_PROTOCOL_FCOE].enable)
51014b24e2bSVaishali Kulkarni 		p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
51114b24e2bSVaishali Kulkarni 
51214b24e2bSVaishali Kulkarni 	if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
51314b24e2bSVaishali Kulkarni 	    p_results->arr[DCBX_PROTOCOL_ETH].enable)
51414b24e2bSVaishali Kulkarni 		p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
51514b24e2bSVaishali Kulkarni 
51614b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
51714b24e2bSVaishali Kulkarni 		   "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
51814b24e2bSVaishali Kulkarni 		   p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
51914b24e2bSVaishali Kulkarni 		   p_prio->eth);
52014b24e2bSVaishali Kulkarni }
52114b24e2bSVaishali Kulkarni 
52214b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_app_data(struct ecore_hwfn * p_hwfn,struct dcbx_app_priority_feature * p_app,struct dcbx_app_priority_entry * p_tbl,struct ecore_dcbx_params * p_params,bool ieee)52314b24e2bSVaishali Kulkarni ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
52414b24e2bSVaishali Kulkarni 			struct dcbx_app_priority_feature *p_app,
52514b24e2bSVaishali Kulkarni 			struct dcbx_app_priority_entry *p_tbl,
52614b24e2bSVaishali Kulkarni 			struct ecore_dcbx_params *p_params, bool ieee)
52714b24e2bSVaishali Kulkarni {
52814b24e2bSVaishali Kulkarni 	struct ecore_app_entry *entry;
52914b24e2bSVaishali Kulkarni 	u8 pri_map;
53014b24e2bSVaishali Kulkarni 	int i;
53114b24e2bSVaishali Kulkarni 
53214b24e2bSVaishali Kulkarni 	p_params->app_willing = ECORE_MFW_GET_FIELD(p_app->flags,
53314b24e2bSVaishali Kulkarni 						    DCBX_APP_WILLING);
53414b24e2bSVaishali Kulkarni 	p_params->app_valid = ECORE_MFW_GET_FIELD(p_app->flags,
53514b24e2bSVaishali Kulkarni 						  DCBX_APP_ENABLED);
53614b24e2bSVaishali Kulkarni 	p_params->app_error = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
53714b24e2bSVaishali Kulkarni 	p_params->num_app_entries = ECORE_MFW_GET_FIELD(p_app->flags,
53814b24e2bSVaishali Kulkarni 							DCBX_APP_NUM_ENTRIES);
53914b24e2bSVaishali Kulkarni 	for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
54014b24e2bSVaishali Kulkarni 		entry = &p_params->app_entry[i];
54114b24e2bSVaishali Kulkarni 		if (ieee) {
54214b24e2bSVaishali Kulkarni 			u8 sf_ieee;
54314b24e2bSVaishali Kulkarni 			u32 val;
54414b24e2bSVaishali Kulkarni 
54514b24e2bSVaishali Kulkarni 			sf_ieee = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
54614b24e2bSVaishali Kulkarni 						      DCBX_APP_SF_IEEE);
54714b24e2bSVaishali Kulkarni 			switch (sf_ieee) {
54814b24e2bSVaishali Kulkarni 			case DCBX_APP_SF_IEEE_RESERVED:
54914b24e2bSVaishali Kulkarni 				/* Old MFW */
55014b24e2bSVaishali Kulkarni 				val = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
55114b24e2bSVaishali Kulkarni 							    DCBX_APP_SF);
55214b24e2bSVaishali Kulkarni 				entry->sf_ieee = val ?
55314b24e2bSVaishali Kulkarni 					ECORE_DCBX_SF_IEEE_TCP_UDP_PORT :
55414b24e2bSVaishali Kulkarni 					ECORE_DCBX_SF_IEEE_ETHTYPE;
55514b24e2bSVaishali Kulkarni 				break;
55614b24e2bSVaishali Kulkarni 			case DCBX_APP_SF_IEEE_ETHTYPE:
55714b24e2bSVaishali Kulkarni 				entry->sf_ieee = ECORE_DCBX_SF_IEEE_ETHTYPE;
55814b24e2bSVaishali Kulkarni 				break;
55914b24e2bSVaishali Kulkarni 			case DCBX_APP_SF_IEEE_TCP_PORT:
56014b24e2bSVaishali Kulkarni 				entry->sf_ieee = ECORE_DCBX_SF_IEEE_TCP_PORT;
56114b24e2bSVaishali Kulkarni 				break;
56214b24e2bSVaishali Kulkarni 			case DCBX_APP_SF_IEEE_UDP_PORT:
56314b24e2bSVaishali Kulkarni 				entry->sf_ieee = ECORE_DCBX_SF_IEEE_UDP_PORT;
56414b24e2bSVaishali Kulkarni 				break;
56514b24e2bSVaishali Kulkarni 			case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
56614b24e2bSVaishali Kulkarni 				entry->sf_ieee = ECORE_DCBX_SF_IEEE_TCP_UDP_PORT;
56714b24e2bSVaishali Kulkarni 				break;
56814b24e2bSVaishali Kulkarni 			}
56914b24e2bSVaishali Kulkarni 		} else {
57014b24e2bSVaishali Kulkarni 			entry->ethtype = !(ECORE_MFW_GET_FIELD(p_tbl[i].entry,
57114b24e2bSVaishali Kulkarni 							       DCBX_APP_SF));
57214b24e2bSVaishali Kulkarni 		}
57314b24e2bSVaishali Kulkarni 
57414b24e2bSVaishali Kulkarni 		pri_map = ECORE_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
57514b24e2bSVaishali Kulkarni 		ecore_dcbx_get_app_priority(pri_map, &entry->prio);
57614b24e2bSVaishali Kulkarni 		entry->proto_id = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
57714b24e2bSVaishali Kulkarni 						      DCBX_APP_PROTOCOL_ID);
57814b24e2bSVaishali Kulkarni 		ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
57914b24e2bSVaishali Kulkarni 						 entry->proto_id,
58014b24e2bSVaishali Kulkarni 						 &entry->proto_type, ieee);
58114b24e2bSVaishali Kulkarni 	}
58214b24e2bSVaishali Kulkarni 
58314b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
58414b24e2bSVaishali Kulkarni 		   "APP params: willing %d, valid %d error = %d\n",
58514b24e2bSVaishali Kulkarni 		   p_params->app_willing, p_params->app_valid,
58614b24e2bSVaishali Kulkarni 		   p_params->app_error);
58714b24e2bSVaishali Kulkarni }
58814b24e2bSVaishali Kulkarni 
58914b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_pfc_data(struct ecore_hwfn * p_hwfn,u32 pfc,struct ecore_dcbx_params * p_params)59014b24e2bSVaishali Kulkarni ecore_dcbx_get_pfc_data(struct ecore_hwfn *p_hwfn,
59114b24e2bSVaishali Kulkarni 			u32 pfc, struct ecore_dcbx_params *p_params)
59214b24e2bSVaishali Kulkarni {
59314b24e2bSVaishali Kulkarni 	u8 pfc_map;
59414b24e2bSVaishali Kulkarni 
59514b24e2bSVaishali Kulkarni 	p_params->pfc.willing = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
59614b24e2bSVaishali Kulkarni 	p_params->pfc.max_tc = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
59714b24e2bSVaishali Kulkarni 	p_params->pfc.enabled = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
59814b24e2bSVaishali Kulkarni 	pfc_map = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
59914b24e2bSVaishali Kulkarni 	p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
60014b24e2bSVaishali Kulkarni 	p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
60114b24e2bSVaishali Kulkarni 	p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
60214b24e2bSVaishali Kulkarni 	p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
60314b24e2bSVaishali Kulkarni 	p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
60414b24e2bSVaishali Kulkarni 	p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
60514b24e2bSVaishali Kulkarni 	p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
60614b24e2bSVaishali Kulkarni 	p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
60714b24e2bSVaishali Kulkarni 
60814b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
60914b24e2bSVaishali Kulkarni 		   "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
61014b24e2bSVaishali Kulkarni 		   p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
61114b24e2bSVaishali Kulkarni 		   p_params->pfc.enabled);
61214b24e2bSVaishali Kulkarni }
61314b24e2bSVaishali Kulkarni 
61414b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_ets_data(struct ecore_hwfn * p_hwfn,struct dcbx_ets_feature * p_ets,struct ecore_dcbx_params * p_params)61514b24e2bSVaishali Kulkarni ecore_dcbx_get_ets_data(struct ecore_hwfn *p_hwfn,
61614b24e2bSVaishali Kulkarni 			struct dcbx_ets_feature *p_ets,
61714b24e2bSVaishali Kulkarni 			struct ecore_dcbx_params *p_params)
61814b24e2bSVaishali Kulkarni {
61914b24e2bSVaishali Kulkarni 	u32 bw_map[2], tsa_map[2], pri_map;
62014b24e2bSVaishali Kulkarni 	int i;
62114b24e2bSVaishali Kulkarni 
62214b24e2bSVaishali Kulkarni 	p_params->ets_willing = ECORE_MFW_GET_FIELD(p_ets->flags,
62314b24e2bSVaishali Kulkarni 						    DCBX_ETS_WILLING);
62414b24e2bSVaishali Kulkarni 	p_params->ets_enabled = ECORE_MFW_GET_FIELD(p_ets->flags,
62514b24e2bSVaishali Kulkarni 						    DCBX_ETS_ENABLED);
62614b24e2bSVaishali Kulkarni 	p_params->ets_cbs = ECORE_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
62714b24e2bSVaishali Kulkarni 	p_params->max_ets_tc = ECORE_MFW_GET_FIELD(p_ets->flags,
62814b24e2bSVaishali Kulkarni 						   DCBX_ETS_MAX_TCS);
62914b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
63014b24e2bSVaishali Kulkarni 		   "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
63114b24e2bSVaishali Kulkarni 		   p_params->ets_willing, p_params->ets_enabled,
63214b24e2bSVaishali Kulkarni 		   p_params->ets_cbs, p_ets->pri_tc_tbl[0],
63314b24e2bSVaishali Kulkarni 		   p_params->max_ets_tc);
63414b24e2bSVaishali Kulkarni 	if (p_params->ets_enabled && !p_params->max_ets_tc)
63514b24e2bSVaishali Kulkarni 	{
63614b24e2bSVaishali Kulkarni 		p_params->max_ets_tc = ECORE_MAX_PFC_PRIORITIES;
63714b24e2bSVaishali Kulkarni 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
63814b24e2bSVaishali Kulkarni 			   "ETS params: max_ets_tc is forced to %d\n",
63914b24e2bSVaishali Kulkarni 		   p_params->max_ets_tc);
64014b24e2bSVaishali Kulkarni 	}
64114b24e2bSVaishali Kulkarni 	/* 8 bit tsa and bw data corresponding to each of the 8 TC's are
64214b24e2bSVaishali Kulkarni 	 * encoded in a type u32 array of size 2.
64314b24e2bSVaishali Kulkarni 	 */
64414b24e2bSVaishali Kulkarni 	bw_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[0]);
64514b24e2bSVaishali Kulkarni 	bw_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_bw_tbl[1]);
64614b24e2bSVaishali Kulkarni 	tsa_map[0] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[0]);
64714b24e2bSVaishali Kulkarni 	tsa_map[1] = OSAL_BE32_TO_CPU(p_ets->tc_tsa_tbl[1]);
64814b24e2bSVaishali Kulkarni 	pri_map = p_ets->pri_tc_tbl[0];
64914b24e2bSVaishali Kulkarni 	for (i = 0; i < ECORE_MAX_PFC_PRIORITIES; i++) {
65014b24e2bSVaishali Kulkarni 		p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
65114b24e2bSVaishali Kulkarni 		p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
65214b24e2bSVaishali Kulkarni 		p_params->ets_pri_tc_tbl[i] = ECORE_DCBX_PRIO2TC(pri_map, i);
65314b24e2bSVaishali Kulkarni 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
65414b24e2bSVaishali Kulkarni 			   "elem %d  bw_tbl %x tsa_tbl %x\n",
65514b24e2bSVaishali Kulkarni 			   i, p_params->ets_tc_bw_tbl[i],
65614b24e2bSVaishali Kulkarni 			   p_params->ets_tc_tsa_tbl[i]);
65714b24e2bSVaishali Kulkarni 	}
65814b24e2bSVaishali Kulkarni }
65914b24e2bSVaishali Kulkarni 
66014b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_common_params(struct ecore_hwfn * p_hwfn,struct dcbx_app_priority_feature * p_app,struct dcbx_app_priority_entry * p_tbl,struct dcbx_ets_feature * p_ets,u32 pfc,struct ecore_dcbx_params * p_params,bool ieee)66114b24e2bSVaishali Kulkarni ecore_dcbx_get_common_params(struct ecore_hwfn *p_hwfn,
66214b24e2bSVaishali Kulkarni 			     struct dcbx_app_priority_feature *p_app,
66314b24e2bSVaishali Kulkarni 			     struct dcbx_app_priority_entry *p_tbl,
66414b24e2bSVaishali Kulkarni 			     struct dcbx_ets_feature *p_ets,
66514b24e2bSVaishali Kulkarni 			     u32 pfc, struct ecore_dcbx_params *p_params,
66614b24e2bSVaishali Kulkarni 			     bool ieee)
66714b24e2bSVaishali Kulkarni {
66814b24e2bSVaishali Kulkarni 	ecore_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
66914b24e2bSVaishali Kulkarni 	ecore_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
67014b24e2bSVaishali Kulkarni 	ecore_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
67114b24e2bSVaishali Kulkarni }
67214b24e2bSVaishali Kulkarni 
67314b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_local_params(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_dcbx_get * params)67414b24e2bSVaishali Kulkarni ecore_dcbx_get_local_params(struct ecore_hwfn *p_hwfn,
67514b24e2bSVaishali Kulkarni 			    struct ecore_ptt *p_ptt,
67614b24e2bSVaishali Kulkarni 			    struct ecore_dcbx_get *params)
67714b24e2bSVaishali Kulkarni {
67814b24e2bSVaishali Kulkarni 	struct dcbx_features *p_feat;
67914b24e2bSVaishali Kulkarni 
68014b24e2bSVaishali Kulkarni 	p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
68114b24e2bSVaishali Kulkarni 	ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
68214b24e2bSVaishali Kulkarni 				     p_feat->app.app_pri_tbl, &p_feat->ets,
68314b24e2bSVaishali Kulkarni 				     p_feat->pfc, &params->local.params, false);
68414b24e2bSVaishali Kulkarni 	params->local.valid = true;
68514b24e2bSVaishali Kulkarni }
68614b24e2bSVaishali Kulkarni 
68714b24e2bSVaishali Kulkarni static void
ecore_dcbx_get_remote_params(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_dcbx_get * params)68814b24e2bSVaishali Kulkarni ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
68914b24e2bSVaishali Kulkarni 			     struct ecore_ptt *p_ptt,
69014b24e2bSVaishali Kulkarni 			     struct ecore_dcbx_get *params)
69114b24e2bSVaishali Kulkarni {
69214b24e2bSVaishali Kulkarni 	struct dcbx_features *p_feat;
69314b24e2bSVaishali Kulkarni 
69414b24e2bSVaishali Kulkarni 	p_feat = &p_hwfn->p_dcbx_info->remote.features;
69514b24e2bSVaishali Kulkarni 	ecore_dcbx_get_common_params(p_hwfn, &p_feat->app,
69614b24e2bSVaishali Kulkarni 				     p_feat->app.app_pri_tbl, &p_feat->ets,
69714b24e2bSVaishali Kulkarni 				     p_feat->pfc, &params->remote.params,
69814b24e2bSVaishali Kulkarni 				     false);
69914b24e2bSVaishali Kulkarni 	params->remote.valid = true;
70014b24e2bSVaishali Kulkarni }
70114b24e2bSVaishali Kulkarni 
70214b24e2bSVaishali Kulkarni static enum _ecore_status_t
ecore_dcbx_get_operational_params(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_dcbx_get * params)70314b24e2bSVaishali Kulkarni ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
70414b24e2bSVaishali Kulkarni 				  struct ecore_ptt *p_ptt,
70514b24e2bSVaishali Kulkarni 				  struct ecore_dcbx_get *params)
70614b24e2bSVaishali Kulkarni {
70714b24e2bSVaishali Kulkarni 	struct ecore_dcbx_operational_params *p_operational;
70814b24e2bSVaishali Kulkarni 	struct ecore_dcbx_results *p_results;
70914b24e2bSVaishali Kulkarni 	struct dcbx_features *p_feat;
71014b24e2bSVaishali Kulkarni 	bool enabled, err;
71114b24e2bSVaishali Kulkarni 	u32 flags;
71214b24e2bSVaishali Kulkarni 	bool val;
71314b24e2bSVaishali Kulkarni 
71414b24e2bSVaishali Kulkarni 	flags = p_hwfn->p_dcbx_info->operational.flags;
71514b24e2bSVaishali Kulkarni 
71614b24e2bSVaishali Kulkarni 	/* If DCBx version is non zero, then negotiation
71714b24e2bSVaishali Kulkarni 	 * was successfuly performed
71814b24e2bSVaishali Kulkarni 	 */
71914b24e2bSVaishali Kulkarni 	p_operational = &params->operational;
72014b24e2bSVaishali Kulkarni 	enabled = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
72114b24e2bSVaishali Kulkarni 		     DCBX_CONFIG_VERSION_DISABLED);
72214b24e2bSVaishali Kulkarni 	if (!enabled) {
72314b24e2bSVaishali Kulkarni 		p_operational->enabled = enabled;
72414b24e2bSVaishali Kulkarni 		p_operational->valid = false;
72514b24e2bSVaishali Kulkarni 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Dcbx is disabled\n");
72614b24e2bSVaishali Kulkarni 		return ECORE_INVAL;
72714b24e2bSVaishali Kulkarni 	}
72814b24e2bSVaishali Kulkarni 
72914b24e2bSVaishali Kulkarni 	p_feat = &p_hwfn->p_dcbx_info->operational.features;
73014b24e2bSVaishali Kulkarni 	p_results = &p_hwfn->p_dcbx_info->results;
73114b24e2bSVaishali Kulkarni 
73214b24e2bSVaishali Kulkarni 	val = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
73314b24e2bSVaishali Kulkarni 		 DCBX_CONFIG_VERSION_IEEE);
73414b24e2bSVaishali Kulkarni 	p_operational->ieee = val;
73514b24e2bSVaishali Kulkarni 
73614b24e2bSVaishali Kulkarni 	val = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
73714b24e2bSVaishali Kulkarni 		 DCBX_CONFIG_VERSION_CEE);
73814b24e2bSVaishali Kulkarni 	p_operational->cee = val;
73914b24e2bSVaishali Kulkarni 
74014b24e2bSVaishali Kulkarni 	val = !!(ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
74114b24e2bSVaishali Kulkarni 		 DCBX_CONFIG_VERSION_STATIC);
74214b24e2bSVaishali Kulkarni 	p_operational->local = val;
74314b24e2bSVaishali Kulkarni 
74414b24e2bSVaishali Kulkarni 	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
74514b24e2bSVaishali Kulkarni 		   "Version support: ieee %d, cee %d, static %d\n",
74614b24e2bSVaishali Ku