xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_dev.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
111e25f0dSDavid C Somayajulu /*
211e25f0dSDavid C Somayajulu  * Copyright (c) 2017-2018 Cavium, Inc.
311e25f0dSDavid C Somayajulu  * All rights reserved.
411e25f0dSDavid C Somayajulu  *
511e25f0dSDavid C Somayajulu  *  Redistribution and use in source and binary forms, with or without
611e25f0dSDavid C Somayajulu  *  modification, are permitted provided that the following conditions
711e25f0dSDavid C Somayajulu  *  are met:
811e25f0dSDavid C Somayajulu  *
911e25f0dSDavid C Somayajulu  *  1. Redistributions of source code must retain the above copyright
1011e25f0dSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer.
1111e25f0dSDavid C Somayajulu  *  2. Redistributions in binary form must reproduce the above copyright
1211e25f0dSDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer in the
1311e25f0dSDavid C Somayajulu  *     documentation and/or other materials provided with the distribution.
1411e25f0dSDavid C Somayajulu  *
1511e25f0dSDavid C Somayajulu  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1611e25f0dSDavid C Somayajulu  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1711e25f0dSDavid C Somayajulu  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1811e25f0dSDavid C Somayajulu  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
1911e25f0dSDavid C Somayajulu  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2011e25f0dSDavid C Somayajulu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2111e25f0dSDavid C Somayajulu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2211e25f0dSDavid C Somayajulu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2311e25f0dSDavid C Somayajulu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2411e25f0dSDavid C Somayajulu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2511e25f0dSDavid C Somayajulu  *  POSSIBILITY OF SUCH DAMAGE.
2611e25f0dSDavid C Somayajulu  */
2711e25f0dSDavid C Somayajulu 
2811e25f0dSDavid C Somayajulu /*
2911e25f0dSDavid C Somayajulu  * File : ecore_dev.c
3011e25f0dSDavid C Somayajulu  */
3111e25f0dSDavid C Somayajulu #include <sys/cdefs.h>
3211e25f0dSDavid C Somayajulu #include "bcm_osal.h"
3311e25f0dSDavid C Somayajulu #include "reg_addr.h"
3411e25f0dSDavid C Somayajulu #include "ecore_gtt_reg_addr.h"
3511e25f0dSDavid C Somayajulu #include "ecore.h"
3611e25f0dSDavid C Somayajulu #include "ecore_chain.h"
3711e25f0dSDavid C Somayajulu #include "ecore_status.h"
3811e25f0dSDavid C Somayajulu #include "ecore_hw.h"
3911e25f0dSDavid C Somayajulu #include "ecore_rt_defs.h"
4011e25f0dSDavid C Somayajulu #include "ecore_init_ops.h"
4111e25f0dSDavid C Somayajulu #include "ecore_int.h"
4211e25f0dSDavid C Somayajulu #include "ecore_cxt.h"
4311e25f0dSDavid C Somayajulu #include "ecore_spq.h"
4411e25f0dSDavid C Somayajulu #include "ecore_init_fw_funcs.h"
4511e25f0dSDavid C Somayajulu #include "ecore_sp_commands.h"
4611e25f0dSDavid C Somayajulu #include "ecore_dev_api.h"
4711e25f0dSDavid C Somayajulu #include "ecore_sriov.h"
4811e25f0dSDavid C Somayajulu #include "ecore_vf.h"
4911e25f0dSDavid C Somayajulu #include "ecore_ll2.h"
5011e25f0dSDavid C Somayajulu #include "ecore_fcoe.h"
5111e25f0dSDavid C Somayajulu #include "ecore_iscsi.h"
5211e25f0dSDavid C Somayajulu #include "ecore_ooo.h"
5311e25f0dSDavid C Somayajulu #include "ecore_mcp.h"
5411e25f0dSDavid C Somayajulu #include "ecore_hw_defs.h"
5511e25f0dSDavid C Somayajulu #include "mcp_public.h"
56*217ec208SDavid C Somayajulu #include "ecore_rdma.h"
5711e25f0dSDavid C Somayajulu #include "ecore_iro.h"
5811e25f0dSDavid C Somayajulu #include "nvm_cfg.h"
5911e25f0dSDavid C Somayajulu #include "ecore_dev_api.h"
6011e25f0dSDavid C Somayajulu #include "ecore_dcbx.h"
6111e25f0dSDavid C Somayajulu #include "pcics_reg_driver.h"
6211e25f0dSDavid C Somayajulu #include "ecore_l2.h"
63*217ec208SDavid C Somayajulu #ifndef LINUX_REMOVE
64*217ec208SDavid C Somayajulu #include "ecore_tcp_ip.h"
65*217ec208SDavid C Somayajulu #endif
66*217ec208SDavid C Somayajulu 
67*217ec208SDavid C Somayajulu #ifdef _NTDDK_
68*217ec208SDavid C Somayajulu #pragma warning(push)
69*217ec208SDavid C Somayajulu #pragma warning(disable : 28167)
70*217ec208SDavid C Somayajulu #pragma warning(disable : 28123)
71*217ec208SDavid C Somayajulu #endif
7211e25f0dSDavid C Somayajulu 
7311e25f0dSDavid C Somayajulu /* TODO - there's a bug in DCBx re-configuration flows in MF, as the QM
7411e25f0dSDavid C Somayajulu  * registers involved are not split and thus configuration is a race where
7511e25f0dSDavid C Somayajulu  * some of the PFs configuration might be lost.
7611e25f0dSDavid C Somayajulu  * Eventually, this needs to move into a MFW-covered HW-lock as arbitration
7711e25f0dSDavid C Somayajulu  * mechanism as this doesn't cover some cases [E.g., PDA or scenarios where
7811e25f0dSDavid C Somayajulu  * there's more than a single compiled ecore component in system].
7911e25f0dSDavid C Somayajulu  */
8011e25f0dSDavid C Somayajulu static osal_spinlock_t qm_lock;
81*217ec208SDavid C Somayajulu static u32 qm_lock_ref_cnt;
82*217ec208SDavid C Somayajulu 
ecore_set_ilt_page_size(struct ecore_dev * p_dev,u8 ilt_page_size)83*217ec208SDavid C Somayajulu void ecore_set_ilt_page_size(struct ecore_dev *p_dev, u8 ilt_page_size)
84*217ec208SDavid C Somayajulu {
85*217ec208SDavid C Somayajulu 	p_dev->ilt_page_size = ilt_page_size;
86*217ec208SDavid C Somayajulu }
8711e25f0dSDavid C Somayajulu 
889efd0ba7SDavid C Somayajulu /******************** Doorbell Recovery *******************/
899efd0ba7SDavid C Somayajulu /* The doorbell recovery mechanism consists of a list of entries which represent
909efd0ba7SDavid C Somayajulu  * doorbelling entities (l2 queues, roce sq/rq/cqs, the slowpath spq, etc). Each
919efd0ba7SDavid C Somayajulu  * entity needs to register with the mechanism and provide the parameters
929efd0ba7SDavid C Somayajulu  * describing it's doorbell, including a location where last used doorbell data
939efd0ba7SDavid C Somayajulu  * can be found. The doorbell execute function will traverse the list and
949efd0ba7SDavid C Somayajulu  * doorbell all of the registered entries.
959efd0ba7SDavid C Somayajulu  */
969efd0ba7SDavid C Somayajulu struct ecore_db_recovery_entry {
979efd0ba7SDavid C Somayajulu 	osal_list_entry_t	list_entry;
989efd0ba7SDavid C Somayajulu 	void OSAL_IOMEM		*db_addr;
999efd0ba7SDavid C Somayajulu 	void			*db_data;
1009efd0ba7SDavid C Somayajulu 	enum ecore_db_rec_width	db_width;
1019efd0ba7SDavid C Somayajulu 	enum ecore_db_rec_space	db_space;
1029efd0ba7SDavid C Somayajulu 	u8			hwfn_idx;
1039efd0ba7SDavid C Somayajulu };
1049efd0ba7SDavid C Somayajulu 
1059efd0ba7SDavid C Somayajulu /* display a single doorbell recovery entry */
ecore_db_recovery_dp_entry(struct ecore_hwfn * p_hwfn,struct ecore_db_recovery_entry * db_entry,char * action)1069efd0ba7SDavid C Somayajulu static void ecore_db_recovery_dp_entry(struct ecore_hwfn *p_hwfn,
1079efd0ba7SDavid C Somayajulu 				struct ecore_db_recovery_entry *db_entry,
1089efd0ba7SDavid C Somayajulu 				char *action)
1099efd0ba7SDavid C Somayajulu {
1109efd0ba7SDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ, "(%s: db_entry %p, addr %p, data %p, width %s, %s space, hwfn %d)\n",
1119efd0ba7SDavid C Somayajulu 		   action, db_entry, db_entry->db_addr, db_entry->db_data,
1129efd0ba7SDavid C Somayajulu 		   db_entry->db_width == DB_REC_WIDTH_32B ? "32b" : "64b",
1139efd0ba7SDavid C Somayajulu 		   db_entry->db_space == DB_REC_USER ? "user" : "kernel",
1149efd0ba7SDavid C Somayajulu 		   db_entry->hwfn_idx);
1159efd0ba7SDavid C Somayajulu }
1169efd0ba7SDavid C Somayajulu 
1179efd0ba7SDavid C Somayajulu /* doorbell address sanity (address within doorbell bar range) */
ecore_db_rec_sanity(struct ecore_dev * p_dev,void OSAL_IOMEM * db_addr,void * db_data)118*217ec208SDavid C Somayajulu static bool ecore_db_rec_sanity(struct ecore_dev *p_dev, void OSAL_IOMEM *db_addr,
119*217ec208SDavid C Somayajulu 			 void *db_data)
1209efd0ba7SDavid C Somayajulu {
121*217ec208SDavid C Somayajulu 	/* make sure doorbell address  is within the doorbell bar */
122*217ec208SDavid C Somayajulu 	if (db_addr < p_dev->doorbells || (u8 *)db_addr >
123*217ec208SDavid C Somayajulu 			(u8 *)p_dev->doorbells + p_dev->db_size) {
1249efd0ba7SDavid C Somayajulu 		OSAL_WARN(true,
1259efd0ba7SDavid C Somayajulu 			  "Illegal doorbell address: %p. Legal range for doorbell addresses is [%p..%p]\n",
1269efd0ba7SDavid C Somayajulu 			  db_addr, p_dev->doorbells,
127*217ec208SDavid C Somayajulu 			  (u8 *)p_dev->doorbells + p_dev->db_size);
1289efd0ba7SDavid C Somayajulu 		return false;
1299efd0ba7SDavid C Somayajulu 	}
130*217ec208SDavid C Somayajulu 
131*217ec208SDavid C Somayajulu 	/* make sure doorbell data pointer is not null */
132*217ec208SDavid C Somayajulu 	if (!db_data) {
133*217ec208SDavid C Somayajulu 		OSAL_WARN(true, "Illegal doorbell data pointer: %p", db_data);
134*217ec208SDavid C Somayajulu 		return false;
135*217ec208SDavid C Somayajulu 	}
136*217ec208SDavid C Somayajulu 
137*217ec208SDavid C Somayajulu 	return true;
1389efd0ba7SDavid C Somayajulu }
1399efd0ba7SDavid C Somayajulu 
1409efd0ba7SDavid C Somayajulu /* find hwfn according to the doorbell address */
ecore_db_rec_find_hwfn(struct ecore_dev * p_dev,void OSAL_IOMEM * db_addr)1419efd0ba7SDavid C Somayajulu static struct ecore_hwfn *ecore_db_rec_find_hwfn(struct ecore_dev *p_dev,
1429efd0ba7SDavid C Somayajulu 					  void OSAL_IOMEM *db_addr)
1439efd0ba7SDavid C Somayajulu {
1449efd0ba7SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn;
1459efd0ba7SDavid C Somayajulu 
1469efd0ba7SDavid C Somayajulu 	/* in CMT doorbell bar is split down the middle between engine 0 and enigne 1 */
147*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_dev))
1489efd0ba7SDavid C Somayajulu 		p_hwfn = db_addr < p_dev->hwfns[1].doorbells ?
1499efd0ba7SDavid C Somayajulu 			&p_dev->hwfns[0] : &p_dev->hwfns[1];
1509efd0ba7SDavid C Somayajulu 	else
1519efd0ba7SDavid C Somayajulu 		p_hwfn = ECORE_LEADING_HWFN(p_dev);
1529efd0ba7SDavid C Somayajulu 
1539efd0ba7SDavid C Somayajulu 	return p_hwfn;
1549efd0ba7SDavid C Somayajulu }
1559efd0ba7SDavid C Somayajulu 
1569efd0ba7SDavid C Somayajulu /* add a new entry to the doorbell recovery mechanism */
ecore_db_recovery_add(struct ecore_dev * p_dev,void OSAL_IOMEM * db_addr,void * db_data,enum ecore_db_rec_width db_width,enum ecore_db_rec_space db_space)1579efd0ba7SDavid C Somayajulu enum _ecore_status_t ecore_db_recovery_add(struct ecore_dev *p_dev,
1589efd0ba7SDavid C Somayajulu 					   void OSAL_IOMEM *db_addr,
1599efd0ba7SDavid C Somayajulu 					   void *db_data,
1609efd0ba7SDavid C Somayajulu 					   enum ecore_db_rec_width db_width,
1619efd0ba7SDavid C Somayajulu 					   enum ecore_db_rec_space db_space)
1629efd0ba7SDavid C Somayajulu {
1639efd0ba7SDavid C Somayajulu 	struct ecore_db_recovery_entry *db_entry;
1649efd0ba7SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn;
1659efd0ba7SDavid C Somayajulu 
1669efd0ba7SDavid C Somayajulu 	/* shortcircuit VFs, for now */
1679efd0ba7SDavid C Somayajulu 	if (IS_VF(p_dev)) {
1689efd0ba7SDavid C Somayajulu 		DP_VERBOSE(p_dev, ECORE_MSG_IOV, "db recovery - skipping VF doorbell\n");
1699efd0ba7SDavid C Somayajulu 		return ECORE_SUCCESS;
1709efd0ba7SDavid C Somayajulu 	}
1719efd0ba7SDavid C Somayajulu 
1729efd0ba7SDavid C Somayajulu 	/* sanitize doorbell address */
173*217ec208SDavid C Somayajulu 	if (!ecore_db_rec_sanity(p_dev, db_addr, db_data))
1749efd0ba7SDavid C Somayajulu 		return ECORE_INVAL;
1759efd0ba7SDavid C Somayajulu 
1769efd0ba7SDavid C Somayajulu 	/* obtain hwfn from doorbell address */
1779efd0ba7SDavid C Somayajulu 	p_hwfn = ecore_db_rec_find_hwfn(p_dev, db_addr);
1789efd0ba7SDavid C Somayajulu 
1799efd0ba7SDavid C Somayajulu 	/* create entry */
1809efd0ba7SDavid C Somayajulu 	db_entry = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*db_entry));
1819efd0ba7SDavid C Somayajulu 	if (!db_entry) {
1829efd0ba7SDavid C Somayajulu 		DP_NOTICE(p_dev, false, "Failed to allocate a db recovery entry\n");
1839efd0ba7SDavid C Somayajulu 		return ECORE_NOMEM;
1849efd0ba7SDavid C Somayajulu 	}
1859efd0ba7SDavid C Somayajulu 
1869efd0ba7SDavid C Somayajulu 	/* populate entry */
1879efd0ba7SDavid C Somayajulu 	db_entry->db_addr = db_addr;
1889efd0ba7SDavid C Somayajulu 	db_entry->db_data = db_data;
1899efd0ba7SDavid C Somayajulu 	db_entry->db_width = db_width;
1909efd0ba7SDavid C Somayajulu 	db_entry->db_space = db_space;
1919efd0ba7SDavid C Somayajulu 	db_entry->hwfn_idx = p_hwfn->my_id;
1929efd0ba7SDavid C Somayajulu 
1939efd0ba7SDavid C Somayajulu 	/* display */
1949efd0ba7SDavid C Somayajulu 	ecore_db_recovery_dp_entry(p_hwfn, db_entry, "Adding");
1959efd0ba7SDavid C Somayajulu 
1969efd0ba7SDavid C Somayajulu 	/* protect the list */
1979efd0ba7SDavid C Somayajulu 	OSAL_SPIN_LOCK(&p_hwfn->db_recovery_info.lock);
1989efd0ba7SDavid C Somayajulu 	OSAL_LIST_PUSH_TAIL(&db_entry->list_entry,
1999efd0ba7SDavid C Somayajulu 			    &p_hwfn->db_recovery_info.list);
2009efd0ba7SDavid C Somayajulu 	OSAL_SPIN_UNLOCK(&p_hwfn->db_recovery_info.lock);
2019efd0ba7SDavid C Somayajulu 
2029efd0ba7SDavid C Somayajulu 	return ECORE_SUCCESS;
2039efd0ba7SDavid C Somayajulu }
2049efd0ba7SDavid C Somayajulu 
2059efd0ba7SDavid C Somayajulu /* remove an entry from the doorbell recovery mechanism */
ecore_db_recovery_del(struct ecore_dev * p_dev,void OSAL_IOMEM * db_addr,void * db_data)2069efd0ba7SDavid C Somayajulu enum _ecore_status_t ecore_db_recovery_del(struct ecore_dev *p_dev,
2079efd0ba7SDavid C Somayajulu 					   void OSAL_IOMEM *db_addr,
2089efd0ba7SDavid C Somayajulu 					   void *db_data)
2099efd0ba7SDavid C Somayajulu {
2109efd0ba7SDavid C Somayajulu 	struct ecore_db_recovery_entry *db_entry = OSAL_NULL;
2119efd0ba7SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_INVAL;
2129efd0ba7SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn;
2139efd0ba7SDavid C Somayajulu 
2149efd0ba7SDavid C Somayajulu 	/* shortcircuit VFs, for now */
2159efd0ba7SDavid C Somayajulu 	if (IS_VF(p_dev)) {
2169efd0ba7SDavid C Somayajulu 		DP_VERBOSE(p_dev, ECORE_MSG_IOV, "db recovery - skipping VF doorbell\n");
2179efd0ba7SDavid C Somayajulu 		return ECORE_SUCCESS;
2189efd0ba7SDavid C Somayajulu 	}
2199efd0ba7SDavid C Somayajulu 
2209efd0ba7SDavid C Somayajulu 	/* sanitize doorbell address */
221*217ec208SDavid C Somayajulu 	if (!ecore_db_rec_sanity(p_dev, db_addr, db_data))
2229efd0ba7SDavid C Somayajulu 		return ECORE_INVAL;
2239efd0ba7SDavid C Somayajulu 
2249efd0ba7SDavid C Somayajulu 	/* obtain hwfn from doorbell address */
2259efd0ba7SDavid C Somayajulu 	p_hwfn = ecore_db_rec_find_hwfn(p_dev, db_addr);
2269efd0ba7SDavid C Somayajulu 
2279efd0ba7SDavid C Somayajulu 	/* protect the list */
2289efd0ba7SDavid C Somayajulu 	OSAL_SPIN_LOCK(&p_hwfn->db_recovery_info.lock);
2299efd0ba7SDavid C Somayajulu 	OSAL_LIST_FOR_EACH_ENTRY(db_entry,
2309efd0ba7SDavid C Somayajulu 				 &p_hwfn->db_recovery_info.list,
2319efd0ba7SDavid C Somayajulu 				 list_entry,
2329efd0ba7SDavid C Somayajulu 				 struct ecore_db_recovery_entry) {
2339efd0ba7SDavid C Somayajulu 		/* search according to db_data addr since db_addr is not unique (roce) */
2349efd0ba7SDavid C Somayajulu 		if (db_entry->db_data == db_data) {
2359efd0ba7SDavid C Somayajulu 			ecore_db_recovery_dp_entry(p_hwfn, db_entry, "Deleting");
2369efd0ba7SDavid C Somayajulu 			OSAL_LIST_REMOVE_ENTRY(&db_entry->list_entry,
2379efd0ba7SDavid C Somayajulu 					       &p_hwfn->db_recovery_info.list);
2389efd0ba7SDavid C Somayajulu 			rc = ECORE_SUCCESS;
2399efd0ba7SDavid C Somayajulu 			break;
2409efd0ba7SDavid C Somayajulu 		}
2419efd0ba7SDavid C Somayajulu 	}
2429efd0ba7SDavid C Somayajulu 
2439efd0ba7SDavid C Somayajulu 	OSAL_SPIN_UNLOCK(&p_hwfn->db_recovery_info.lock);
2449efd0ba7SDavid C Somayajulu 
2459efd0ba7SDavid C Somayajulu 	if (rc == ECORE_INVAL) {
246*217ec208SDavid C Somayajulu 		/*OSAL_WARN(true,*/
247*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
248*217ec208SDavid C Somayajulu 			  "Failed to find element in list. Key (db_data addr) was %p. db_addr was %p\n",
2499efd0ba7SDavid C Somayajulu 			  db_data, db_addr);
250*217ec208SDavid C Somayajulu 	} else
2519efd0ba7SDavid C Somayajulu 		OSAL_FREE(p_dev, db_entry);
2529efd0ba7SDavid C Somayajulu 
2539efd0ba7SDavid C Somayajulu 	return rc;
2549efd0ba7SDavid C Somayajulu }
2559efd0ba7SDavid C Somayajulu 
2569efd0ba7SDavid C Somayajulu /* initialize the doorbell recovery mechanism */
ecore_db_recovery_setup(struct ecore_hwfn * p_hwfn)257*217ec208SDavid C Somayajulu static enum _ecore_status_t ecore_db_recovery_setup(struct ecore_hwfn *p_hwfn)
2589efd0ba7SDavid C Somayajulu {
2599efd0ba7SDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ, "Setting up db recovery\n");
260*217ec208SDavid C Somayajulu 
261*217ec208SDavid C Somayajulu 	/* make sure db_size was set in p_dev */
262*217ec208SDavid C Somayajulu 	if (!p_hwfn->p_dev->db_size) {
263*217ec208SDavid C Somayajulu 		DP_ERR(p_hwfn->p_dev, "db_size not set\n");
264*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
265*217ec208SDavid C Somayajulu 	}
266*217ec208SDavid C Somayajulu 
2679efd0ba7SDavid C Somayajulu 	OSAL_LIST_INIT(&p_hwfn->db_recovery_info.list);
2689efd0ba7SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
269*217ec208SDavid C Somayajulu 	if (OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_hwfn->db_recovery_info.lock))
270*217ec208SDavid C Somayajulu 		return ECORE_NOMEM;
2719efd0ba7SDavid C Somayajulu #endif
2729efd0ba7SDavid C Somayajulu 	OSAL_SPIN_LOCK_INIT(&p_hwfn->db_recovery_info.lock);
2739efd0ba7SDavid C Somayajulu 	p_hwfn->db_recovery_info.db_recovery_counter = 0;
274*217ec208SDavid C Somayajulu 
275*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
2769efd0ba7SDavid C Somayajulu }
2779efd0ba7SDavid C Somayajulu 
2789efd0ba7SDavid C Somayajulu /* destroy the doorbell recovery mechanism */
ecore_db_recovery_teardown(struct ecore_hwfn * p_hwfn)2799efd0ba7SDavid C Somayajulu static void ecore_db_recovery_teardown(struct ecore_hwfn *p_hwfn)
2809efd0ba7SDavid C Somayajulu {
2819efd0ba7SDavid C Somayajulu 	struct ecore_db_recovery_entry *db_entry = OSAL_NULL;
2829efd0ba7SDavid C Somayajulu 
2839efd0ba7SDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ, "Tearing down db recovery\n");
2849efd0ba7SDavid C Somayajulu 	if (!OSAL_LIST_IS_EMPTY(&p_hwfn->db_recovery_info.list)) {
2859efd0ba7SDavid C Somayajulu 		DP_VERBOSE(p_hwfn, false, "Doorbell Recovery teardown found the doorbell recovery list was not empty (Expected in disorderly driver unload (e.g. recovery) otherwise this probably means some flow forgot to db_recovery_del). Prepare to purge doorbell recovery list...\n");
2869efd0ba7SDavid C Somayajulu 		while (!OSAL_LIST_IS_EMPTY(&p_hwfn->db_recovery_info.list)) {
2879efd0ba7SDavid C Somayajulu 			db_entry = OSAL_LIST_FIRST_ENTRY(&p_hwfn->db_recovery_info.list,
2889efd0ba7SDavid C Somayajulu 							 struct ecore_db_recovery_entry,
2899efd0ba7SDavid C Somayajulu 							 list_entry);
2909efd0ba7SDavid C Somayajulu 			ecore_db_recovery_dp_entry(p_hwfn, db_entry, "Purging");
2919efd0ba7SDavid C Somayajulu 			OSAL_LIST_REMOVE_ENTRY(&db_entry->list_entry,
2929efd0ba7SDavid C Somayajulu 					       &p_hwfn->db_recovery_info.list);
2939efd0ba7SDavid C Somayajulu 			OSAL_FREE(p_hwfn->p_dev, db_entry);
2949efd0ba7SDavid C Somayajulu 		}
2959efd0ba7SDavid C Somayajulu 	}
2969efd0ba7SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
2979efd0ba7SDavid C Somayajulu 	OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->db_recovery_info.lock);
2989efd0ba7SDavid C Somayajulu #endif
2999efd0ba7SDavid C Somayajulu 	p_hwfn->db_recovery_info.db_recovery_counter = 0;
3009efd0ba7SDavid C Somayajulu }
3019efd0ba7SDavid C Somayajulu 
3029efd0ba7SDavid C Somayajulu /* print the content of the doorbell recovery mechanism */
ecore_db_recovery_dp(struct ecore_hwfn * p_hwfn)3039efd0ba7SDavid C Somayajulu void ecore_db_recovery_dp(struct ecore_hwfn *p_hwfn)
3049efd0ba7SDavid C Somayajulu {
3059efd0ba7SDavid C Somayajulu 	struct ecore_db_recovery_entry *db_entry = OSAL_NULL;
3069efd0ba7SDavid C Somayajulu 
3079efd0ba7SDavid C Somayajulu 	DP_NOTICE(p_hwfn, false,
3089efd0ba7SDavid C Somayajulu 		  "Dispalying doorbell recovery database. Counter was %d\n",
3099efd0ba7SDavid C Somayajulu 		  p_hwfn->db_recovery_info.db_recovery_counter);
3109efd0ba7SDavid C Somayajulu 
3119efd0ba7SDavid C Somayajulu 	/* protect the list */
3129efd0ba7SDavid C Somayajulu 	OSAL_SPIN_LOCK(&p_hwfn->db_recovery_info.lock);
3139efd0ba7SDavid C Somayajulu 	OSAL_LIST_FOR_EACH_ENTRY(db_entry,
3149efd0ba7SDavid C Somayajulu 				 &p_hwfn->db_recovery_info.list,
3159efd0ba7SDavid C Somayajulu 				 list_entry,
3169efd0ba7SDavid C Somayajulu 				 struct ecore_db_recovery_entry) {
3179efd0ba7SDavid C Somayajulu 		ecore_db_recovery_dp_entry(p_hwfn, db_entry, "Printing");
3189efd0ba7SDavid C Somayajulu 	}
3199efd0ba7SDavid C Somayajulu 
3209efd0ba7SDavid C Somayajulu 	OSAL_SPIN_UNLOCK(&p_hwfn->db_recovery_info.lock);
3219efd0ba7SDavid C Somayajulu }
3229efd0ba7SDavid C Somayajulu 
3239efd0ba7SDavid C Somayajulu /* ring the doorbell of a single doorbell recovery entry */
ecore_db_recovery_ring(struct ecore_hwfn * p_hwfn,struct ecore_db_recovery_entry * db_entry,enum ecore_db_rec_exec db_exec)3249efd0ba7SDavid C Somayajulu static void ecore_db_recovery_ring(struct ecore_hwfn *p_hwfn,
3259efd0ba7SDavid C Somayajulu 			    struct ecore_db_recovery_entry *db_entry,
3269efd0ba7SDavid C Somayajulu 			    enum ecore_db_rec_exec db_exec)
3279efd0ba7SDavid C Somayajulu {
328*217ec208SDavid C Somayajulu 	if (db_exec != DB_REC_ONCE) {
3299efd0ba7SDavid C Somayajulu 		/* Print according to width */
3309efd0ba7SDavid C Somayajulu 		if (db_entry->db_width == DB_REC_WIDTH_32B)
331*217ec208SDavid C Somayajulu 			DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
332*217ec208SDavid C Somayajulu 				   "%s doorbell address %p data %x\n",
333*217ec208SDavid C Somayajulu 				   db_exec == DB_REC_DRY_RUN ?
334*217ec208SDavid C Somayajulu 				   "would have rung" : "ringing",
335*217ec208SDavid C Somayajulu 				   db_entry->db_addr,
336*217ec208SDavid C Somayajulu 				   *(u32 *)db_entry->db_data);
3379efd0ba7SDavid C Somayajulu 		else
338*217ec208SDavid C Somayajulu 			DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
339*217ec208SDavid C Somayajulu 				   "%s doorbell address %p data %llx\n",
340*217ec208SDavid C Somayajulu 				   db_exec == DB_REC_DRY_RUN ?
341*217ec208SDavid C Somayajulu 				   "would have rung" : "ringing",
342*217ec208SDavid C Somayajulu 				   db_entry->db_addr,
343*217ec208SDavid C Somayajulu 				   (unsigned long long)*(u64 *)(db_entry->db_data));
344*217ec208SDavid C Somayajulu 	}
3459efd0ba7SDavid C Somayajulu 
3469efd0ba7SDavid C Somayajulu 	/* Sanity */
347*217ec208SDavid C Somayajulu 	if (!ecore_db_rec_sanity(p_hwfn->p_dev, db_entry->db_addr,
348*217ec208SDavid C Somayajulu 				 db_entry->db_data))
3499efd0ba7SDavid C Somayajulu 		return;
3509efd0ba7SDavid C Somayajulu 
3519efd0ba7SDavid C Somayajulu 	/* Flush the write combined buffer. Since there are multiple doorbelling
3529efd0ba7SDavid C Somayajulu 	 * entities using the same address, if we don't flush, a transaction
3539efd0ba7SDavid C Somayajulu 	 * could be lost.
3549efd0ba7SDavid C Somayajulu 	 */
3559efd0ba7SDavid C Somayajulu 	OSAL_WMB(p_hwfn->p_dev);
3569efd0ba7SDavid C Somayajulu 
3579efd0ba7SDavid C Somayajulu 	/* Ring the doorbell */
358*217ec208SDavid C Somayajulu 	if (db_exec == DB_REC_REAL_DEAL || db_exec == DB_REC_ONCE) {
3599efd0ba7SDavid C Somayajulu 		if (db_entry->db_width == DB_REC_WIDTH_32B)
3609efd0ba7SDavid C Somayajulu 			DIRECT_REG_WR(p_hwfn, db_entry->db_addr, *(u32 *)(db_entry->db_data));
3619efd0ba7SDavid C Somayajulu 		else
3629efd0ba7SDavid C Somayajulu 			DIRECT_REG_WR64(p_hwfn, db_entry->db_addr, *(u64 *)(db_entry->db_data));
3639efd0ba7SDavid C Somayajulu 	}
3649efd0ba7SDavid C Somayajulu 
3659efd0ba7SDavid C Somayajulu 	/* Flush the write combined buffer. Next doorbell may come from a
3669efd0ba7SDavid C Somayajulu 	 * different entity to the same address...
3679efd0ba7SDavid C Somayajulu 	 */
3689efd0ba7SDavid C Somayajulu 	OSAL_WMB(p_hwfn->p_dev);
3699efd0ba7SDavid C Somayajulu }
3709efd0ba7SDavid C Somayajulu 
3719efd0ba7SDavid C Somayajulu /* traverse the doorbell recovery entry list and ring all the doorbells */
ecore_db_recovery_execute(struct ecore_hwfn * p_hwfn,enum ecore_db_rec_exec db_exec)3729efd0ba7SDavid C Somayajulu void ecore_db_recovery_execute(struct ecore_hwfn *p_hwfn,
3739efd0ba7SDavid C Somayajulu 			       enum ecore_db_rec_exec db_exec)
3749efd0ba7SDavid C Somayajulu {
3759efd0ba7SDavid C Somayajulu 	struct ecore_db_recovery_entry *db_entry = OSAL_NULL;
3769efd0ba7SDavid C Somayajulu 
377*217ec208SDavid C Somayajulu 	if (db_exec != DB_REC_ONCE) {
3789efd0ba7SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false, "Executing doorbell recovery. Counter was %d\n",
3799efd0ba7SDavid C Somayajulu 			  p_hwfn->db_recovery_info.db_recovery_counter);
3809efd0ba7SDavid C Somayajulu 
381*217ec208SDavid C Somayajulu 		/* track amount of times recovery was executed */
382*217ec208SDavid C Somayajulu 		p_hwfn->db_recovery_info.db_recovery_counter++;
383*217ec208SDavid C Somayajulu 	}
384*217ec208SDavid C Somayajulu 
3859efd0ba7SDavid C Somayajulu 	/* protect the list */
3869efd0ba7SDavid C Somayajulu 	OSAL_SPIN_LOCK(&p_hwfn->db_recovery_info.lock);
3879efd0ba7SDavid C Somayajulu 	OSAL_LIST_FOR_EACH_ENTRY(db_entry,
3889efd0ba7SDavid C Somayajulu 				 &p_hwfn->db_recovery_info.list,
3899efd0ba7SDavid C Somayajulu 				 list_entry,
390*217ec208SDavid C Somayajulu 				 struct ecore_db_recovery_entry) {
3919efd0ba7SDavid C Somayajulu 		ecore_db_recovery_ring(p_hwfn, db_entry, db_exec);
392*217ec208SDavid C Somayajulu 		if (db_exec == DB_REC_ONCE)
393*217ec208SDavid C Somayajulu 			break;
394*217ec208SDavid C Somayajulu 	}
3959efd0ba7SDavid C Somayajulu 
396*217ec208SDavid C Somayajulu 	OSAL_SPIN_UNLOCK(&p_hwfn->db_recovery_info.lock);
3979efd0ba7SDavid C Somayajulu }
3989efd0ba7SDavid C Somayajulu /******************** Doorbell Recovery end ****************/
3999efd0ba7SDavid C Somayajulu 
400*217ec208SDavid C Somayajulu /********************************** NIG LLH ***********************************/
401*217ec208SDavid C Somayajulu 
402*217ec208SDavid C Somayajulu enum ecore_llh_filter_type {
403*217ec208SDavid C Somayajulu 	ECORE_LLH_FILTER_TYPE_MAC,
404*217ec208SDavid C Somayajulu 	ECORE_LLH_FILTER_TYPE_PROTOCOL,
405*217ec208SDavid C Somayajulu };
406*217ec208SDavid C Somayajulu 
407*217ec208SDavid C Somayajulu struct ecore_llh_mac_filter {
408*217ec208SDavid C Somayajulu 	u8 addr[ETH_ALEN];
409*217ec208SDavid C Somayajulu };
410*217ec208SDavid C Somayajulu 
411*217ec208SDavid C Somayajulu struct ecore_llh_protocol_filter {
412*217ec208SDavid C Somayajulu 	enum ecore_llh_prot_filter_type_t type;
413*217ec208SDavid C Somayajulu 	u16 source_port_or_eth_type;
414*217ec208SDavid C Somayajulu 	u16 dest_port;
415*217ec208SDavid C Somayajulu };
416*217ec208SDavid C Somayajulu 
417*217ec208SDavid C Somayajulu union ecore_llh_filter {
418*217ec208SDavid C Somayajulu 	struct ecore_llh_mac_filter mac;
419*217ec208SDavid C Somayajulu 	struct ecore_llh_protocol_filter protocol;
420*217ec208SDavid C Somayajulu };
421*217ec208SDavid C Somayajulu 
422*217ec208SDavid C Somayajulu struct ecore_llh_filter_info {
423*217ec208SDavid C Somayajulu 	bool b_enabled;
424*217ec208SDavid C Somayajulu 	u32 ref_cnt;
425*217ec208SDavid C Somayajulu 	enum ecore_llh_filter_type type;
426*217ec208SDavid C Somayajulu 	union ecore_llh_filter filter;
427*217ec208SDavid C Somayajulu };
428*217ec208SDavid C Somayajulu 
429*217ec208SDavid C Somayajulu struct ecore_llh_info {
430*217ec208SDavid C Somayajulu 	/* Number of LLH filters banks */
431*217ec208SDavid C Somayajulu 	u8 num_ppfid;
432*217ec208SDavid C Somayajulu 
433*217ec208SDavid C Somayajulu #define MAX_NUM_PPFID	8
434*217ec208SDavid C Somayajulu 	u8 ppfid_array[MAX_NUM_PPFID];
435*217ec208SDavid C Somayajulu 
436*217ec208SDavid C Somayajulu 	/* Array of filters arrays:
437*217ec208SDavid C Somayajulu 	 * "num_ppfid" elements of filters banks, where each is an array of
438*217ec208SDavid C Somayajulu 	 * "NIG_REG_LLH_FUNC_FILTER_EN_SIZE" filters.
439*217ec208SDavid C Somayajulu 	 */
440*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_info **pp_filters;
441*217ec208SDavid C Somayajulu };
442*217ec208SDavid C Somayajulu 
ecore_llh_free(struct ecore_dev * p_dev)443*217ec208SDavid C Somayajulu static void ecore_llh_free(struct ecore_dev *p_dev)
444*217ec208SDavid C Somayajulu {
445*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
446*217ec208SDavid C Somayajulu 	u32 i;
447*217ec208SDavid C Somayajulu 
448*217ec208SDavid C Somayajulu 	if (p_llh_info != OSAL_NULL) {
449*217ec208SDavid C Somayajulu 		if (p_llh_info->pp_filters != OSAL_NULL) {
450*217ec208SDavid C Somayajulu 			for (i = 0; i < p_llh_info->num_ppfid; i++)
451*217ec208SDavid C Somayajulu 				OSAL_FREE(p_dev, p_llh_info->pp_filters[i]);
452*217ec208SDavid C Somayajulu 		}
453*217ec208SDavid C Somayajulu 
454*217ec208SDavid C Somayajulu 		OSAL_FREE(p_dev, p_llh_info->pp_filters);
455*217ec208SDavid C Somayajulu 	}
456*217ec208SDavid C Somayajulu 
457*217ec208SDavid C Somayajulu 	OSAL_FREE(p_dev, p_llh_info);
458*217ec208SDavid C Somayajulu 	p_dev->p_llh_info = OSAL_NULL;
459*217ec208SDavid C Somayajulu }
460*217ec208SDavid C Somayajulu 
ecore_llh_alloc(struct ecore_dev * p_dev)461*217ec208SDavid C Somayajulu static enum _ecore_status_t ecore_llh_alloc(struct ecore_dev *p_dev)
462*217ec208SDavid C Somayajulu {
463*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info;
464*217ec208SDavid C Somayajulu 	u32 size; u8 i;
465*217ec208SDavid C Somayajulu 
466*217ec208SDavid C Somayajulu 	p_llh_info = OSAL_ZALLOC(p_dev, GFP_KERNEL, sizeof(*p_llh_info));
467*217ec208SDavid C Somayajulu 	if (!p_llh_info)
468*217ec208SDavid C Somayajulu 		return ECORE_NOMEM;
469*217ec208SDavid C Somayajulu 	p_dev->p_llh_info = p_llh_info;
470*217ec208SDavid C Somayajulu 
471*217ec208SDavid C Somayajulu 	for (i = 0; i < MAX_NUM_PPFID; i++) {
472*217ec208SDavid C Somayajulu 		if (!(p_dev->ppfid_bitmap & (0x1 << i)))
473*217ec208SDavid C Somayajulu 			continue;
474*217ec208SDavid C Somayajulu 
475*217ec208SDavid C Somayajulu 		p_llh_info->ppfid_array[p_llh_info->num_ppfid] = i;
476*217ec208SDavid C Somayajulu 		DP_VERBOSE(p_dev, ECORE_MSG_SP, "ppfid_array[%d] = %hhd\n",
477*217ec208SDavid C Somayajulu 			   p_llh_info->num_ppfid, i);
478*217ec208SDavid C Somayajulu 		p_llh_info->num_ppfid++;
479*217ec208SDavid C Somayajulu 	}
480*217ec208SDavid C Somayajulu 
481*217ec208SDavid C Somayajulu 	size = p_llh_info->num_ppfid * sizeof(*p_llh_info->pp_filters);
482*217ec208SDavid C Somayajulu 	p_llh_info->pp_filters = OSAL_ZALLOC(p_dev, GFP_KERNEL, size);
483*217ec208SDavid C Somayajulu 	if (!p_llh_info->pp_filters)
484*217ec208SDavid C Somayajulu 		return ECORE_NOMEM;
485*217ec208SDavid C Somayajulu 
486*217ec208SDavid C Somayajulu 	size = NIG_REG_LLH_FUNC_FILTER_EN_SIZE *
487*217ec208SDavid C Somayajulu 	       sizeof(**p_llh_info->pp_filters);
488*217ec208SDavid C Somayajulu 	for (i = 0; i < p_llh_info->num_ppfid; i++) {
489*217ec208SDavid C Somayajulu 		p_llh_info->pp_filters[i] = OSAL_ZALLOC(p_dev, GFP_KERNEL,
490*217ec208SDavid C Somayajulu 							size);
491*217ec208SDavid C Somayajulu 		if (!p_llh_info->pp_filters[i])
492*217ec208SDavid C Somayajulu 			return ECORE_NOMEM;
493*217ec208SDavid C Somayajulu 	}
494*217ec208SDavid C Somayajulu 
495*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
496*217ec208SDavid C Somayajulu }
497*217ec208SDavid C Somayajulu 
ecore_llh_shadow_sanity(struct ecore_dev * p_dev,u8 ppfid,u8 filter_idx,const char * action)498*217ec208SDavid C Somayajulu static enum _ecore_status_t ecore_llh_shadow_sanity(struct ecore_dev *p_dev,
499*217ec208SDavid C Somayajulu 						    u8 ppfid, u8 filter_idx,
500*217ec208SDavid C Somayajulu 						    const char *action)
501*217ec208SDavid C Somayajulu {
502*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
503*217ec208SDavid C Somayajulu 
504*217ec208SDavid C Somayajulu 	if (ppfid >= p_llh_info->num_ppfid) {
505*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
506*217ec208SDavid C Somayajulu 			  "LLH shadow [%s]: using ppfid %d while only %d ppfids are available\n",
507*217ec208SDavid C Somayajulu 			  action, ppfid, p_llh_info->num_ppfid);
508*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
509*217ec208SDavid C Somayajulu 	}
510*217ec208SDavid C Somayajulu 
511*217ec208SDavid C Somayajulu 	if (filter_idx >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
512*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
513*217ec208SDavid C Somayajulu 			  "LLH shadow [%s]: using filter_idx %d while only %d filters are available\n",
514*217ec208SDavid C Somayajulu 			  action, filter_idx, NIG_REG_LLH_FUNC_FILTER_EN_SIZE);
515*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
516*217ec208SDavid C Somayajulu 	}
517*217ec208SDavid C Somayajulu 
518*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
519*217ec208SDavid C Somayajulu }
520*217ec208SDavid C Somayajulu 
521*217ec208SDavid C Somayajulu #define ECORE_LLH_INVALID_FILTER_IDX	0xff
522*217ec208SDavid C Somayajulu 
523*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_shadow_search_filter(struct ecore_dev * p_dev,u8 ppfid,union ecore_llh_filter * p_filter,u8 * p_filter_idx)524*217ec208SDavid C Somayajulu ecore_llh_shadow_search_filter(struct ecore_dev *p_dev, u8 ppfid,
525*217ec208SDavid C Somayajulu 			       union ecore_llh_filter *p_filter,
526*217ec208SDavid C Somayajulu 			       u8 *p_filter_idx)
527*217ec208SDavid C Somayajulu {
528*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
529*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_info *p_filters;
530*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
531*217ec208SDavid C Somayajulu 	u8 i;
532*217ec208SDavid C Somayajulu 
533*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_sanity(p_dev, ppfid, 0, "search");
534*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
535*217ec208SDavid C Somayajulu 		return rc;
536*217ec208SDavid C Somayajulu 
537*217ec208SDavid C Somayajulu 	*p_filter_idx = ECORE_LLH_INVALID_FILTER_IDX;
538*217ec208SDavid C Somayajulu 
539*217ec208SDavid C Somayajulu 	p_filters = p_llh_info->pp_filters[ppfid];
540*217ec208SDavid C Somayajulu 	for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
541*217ec208SDavid C Somayajulu 		if (!OSAL_MEMCMP(p_filter, &p_filters[i].filter,
542*217ec208SDavid C Somayajulu 				 sizeof(*p_filter))) {
543*217ec208SDavid C Somayajulu 			*p_filter_idx = i;
544*217ec208SDavid C Somayajulu 			break;
545*217ec208SDavid C Somayajulu 		}
546*217ec208SDavid C Somayajulu 	}
547*217ec208SDavid C Somayajulu 
548*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
549*217ec208SDavid C Somayajulu }
550*217ec208SDavid C Somayajulu 
551*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_shadow_get_free_idx(struct ecore_dev * p_dev,u8 ppfid,u8 * p_filter_idx)552*217ec208SDavid C Somayajulu ecore_llh_shadow_get_free_idx(struct ecore_dev *p_dev, u8 ppfid,
553*217ec208SDavid C Somayajulu 			      u8 *p_filter_idx)
554*217ec208SDavid C Somayajulu {
555*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
556*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_info *p_filters;
557*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
558*217ec208SDavid C Somayajulu 	u8 i;
559*217ec208SDavid C Somayajulu 
560*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_sanity(p_dev, ppfid, 0, "get_free_idx");
561*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
562*217ec208SDavid C Somayajulu 		return rc;
563*217ec208SDavid C Somayajulu 
564*217ec208SDavid C Somayajulu 	*p_filter_idx = ECORE_LLH_INVALID_FILTER_IDX;
565*217ec208SDavid C Somayajulu 
566*217ec208SDavid C Somayajulu 	p_filters = p_llh_info->pp_filters[ppfid];
567*217ec208SDavid C Somayajulu 	for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
568*217ec208SDavid C Somayajulu 		if (!p_filters[i].b_enabled) {
569*217ec208SDavid C Somayajulu 			*p_filter_idx = i;
570*217ec208SDavid C Somayajulu 			break;
571*217ec208SDavid C Somayajulu 		}
572*217ec208SDavid C Somayajulu 	}
573*217ec208SDavid C Somayajulu 
574*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
575*217ec208SDavid C Somayajulu }
576*217ec208SDavid C Somayajulu 
577*217ec208SDavid C Somayajulu static enum _ecore_status_t
__ecore_llh_shadow_add_filter(struct ecore_dev * p_dev,u8 ppfid,u8 filter_idx,enum ecore_llh_filter_type type,union ecore_llh_filter * p_filter,u32 * p_ref_cnt)578*217ec208SDavid C Somayajulu __ecore_llh_shadow_add_filter(struct ecore_dev *p_dev, u8 ppfid, u8 filter_idx,
579*217ec208SDavid C Somayajulu 			      enum ecore_llh_filter_type type,
580*217ec208SDavid C Somayajulu 			      union ecore_llh_filter *p_filter, u32 *p_ref_cnt)
581*217ec208SDavid C Somayajulu {
582*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
583*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_info *p_filters;
584*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
585*217ec208SDavid C Somayajulu 
586*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_sanity(p_dev, ppfid, filter_idx, "add");
587*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
588*217ec208SDavid C Somayajulu 		return rc;
589*217ec208SDavid C Somayajulu 
590*217ec208SDavid C Somayajulu 	p_filters = p_llh_info->pp_filters[ppfid];
591*217ec208SDavid C Somayajulu 	if (!p_filters[filter_idx].ref_cnt) {
592*217ec208SDavid C Somayajulu 		p_filters[filter_idx].b_enabled = true;
593*217ec208SDavid C Somayajulu 		p_filters[filter_idx].type = type;
594*217ec208SDavid C Somayajulu 		OSAL_MEMCPY(&p_filters[filter_idx].filter, p_filter,
595*217ec208SDavid C Somayajulu 			    sizeof(p_filters[filter_idx].filter));
596*217ec208SDavid C Somayajulu 	}
597*217ec208SDavid C Somayajulu 
598*217ec208SDavid C Somayajulu 	*p_ref_cnt = ++p_filters[filter_idx].ref_cnt;
599*217ec208SDavid C Somayajulu 
600*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
601*217ec208SDavid C Somayajulu }
602*217ec208SDavid C Somayajulu 
603*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_shadow_add_filter(struct ecore_dev * p_dev,u8 ppfid,enum ecore_llh_filter_type type,union ecore_llh_filter * p_filter,u8 * p_filter_idx,u32 * p_ref_cnt)604*217ec208SDavid C Somayajulu ecore_llh_shadow_add_filter(struct ecore_dev *p_dev, u8 ppfid,
605*217ec208SDavid C Somayajulu 			    enum ecore_llh_filter_type type,
606*217ec208SDavid C Somayajulu 			    union ecore_llh_filter *p_filter,
607*217ec208SDavid C Somayajulu 			    u8 *p_filter_idx, u32 *p_ref_cnt)
608*217ec208SDavid C Somayajulu {
609*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
610*217ec208SDavid C Somayajulu 
611*217ec208SDavid C Somayajulu 	/* Check if the same filter already exist */
612*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_search_filter(p_dev, ppfid, p_filter,
613*217ec208SDavid C Somayajulu 					    p_filter_idx);
614*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
615*217ec208SDavid C Somayajulu 		return rc;
616*217ec208SDavid C Somayajulu 
617*217ec208SDavid C Somayajulu 	/* Find a new entry in case of a new filter */
618*217ec208SDavid C Somayajulu 	if (*p_filter_idx == ECORE_LLH_INVALID_FILTER_IDX) {
619*217ec208SDavid C Somayajulu 		rc = ecore_llh_shadow_get_free_idx(p_dev, ppfid, p_filter_idx);
620*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
621*217ec208SDavid C Somayajulu 			return rc;
622*217ec208SDavid C Somayajulu 	}
623*217ec208SDavid C Somayajulu 
624*217ec208SDavid C Somayajulu 	/* No free entry was found */
625*217ec208SDavid C Somayajulu 	if (*p_filter_idx == ECORE_LLH_INVALID_FILTER_IDX) {
626*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
627*217ec208SDavid C Somayajulu 			  "Failed to find an empty LLH filter to utilize [ppfid %d]\n",
628*217ec208SDavid C Somayajulu 			  ppfid);
629*217ec208SDavid C Somayajulu 		return ECORE_NORESOURCES;
630*217ec208SDavid C Somayajulu 	}
631*217ec208SDavid C Somayajulu 
632*217ec208SDavid C Somayajulu 	return __ecore_llh_shadow_add_filter(p_dev, ppfid, *p_filter_idx, type,
633*217ec208SDavid C Somayajulu 					     p_filter, p_ref_cnt);
634*217ec208SDavid C Somayajulu }
635*217ec208SDavid C Somayajulu 
636*217ec208SDavid C Somayajulu static enum _ecore_status_t
__ecore_llh_shadow_remove_filter(struct ecore_dev * p_dev,u8 ppfid,u8 filter_idx,u32 * p_ref_cnt)637*217ec208SDavid C Somayajulu __ecore_llh_shadow_remove_filter(struct ecore_dev *p_dev, u8 ppfid,
638*217ec208SDavid C Somayajulu 				 u8 filter_idx, u32 *p_ref_cnt)
639*217ec208SDavid C Somayajulu {
640*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
641*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_info *p_filters;
642*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
643*217ec208SDavid C Somayajulu 
644*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_sanity(p_dev, ppfid, filter_idx, "remove");
645*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
646*217ec208SDavid C Somayajulu 		return rc;
647*217ec208SDavid C Somayajulu 
648*217ec208SDavid C Somayajulu 	p_filters = p_llh_info->pp_filters[ppfid];
649*217ec208SDavid C Somayajulu 	if (!p_filters[filter_idx].ref_cnt) {
650*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
651*217ec208SDavid C Somayajulu 			  "LLH shadow: trying to remove a filter with ref_cnt=0\n");
652*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
653*217ec208SDavid C Somayajulu 	}
654*217ec208SDavid C Somayajulu 
655*217ec208SDavid C Somayajulu 	*p_ref_cnt = --p_filters[filter_idx].ref_cnt;
656*217ec208SDavid C Somayajulu 	if (!p_filters[filter_idx].ref_cnt)
657*217ec208SDavid C Somayajulu 		OSAL_MEM_ZERO(&p_filters[filter_idx],
658*217ec208SDavid C Somayajulu 			      sizeof(p_filters[filter_idx]));
659*217ec208SDavid C Somayajulu 
660*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
661*217ec208SDavid C Somayajulu }
662*217ec208SDavid C Somayajulu 
663*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_shadow_remove_filter(struct ecore_dev * p_dev,u8 ppfid,union ecore_llh_filter * p_filter,u8 * p_filter_idx,u32 * p_ref_cnt)664*217ec208SDavid C Somayajulu ecore_llh_shadow_remove_filter(struct ecore_dev *p_dev, u8 ppfid,
665*217ec208SDavid C Somayajulu 			       union ecore_llh_filter *p_filter,
666*217ec208SDavid C Somayajulu 			       u8 *p_filter_idx, u32 *p_ref_cnt)
667*217ec208SDavid C Somayajulu {
668*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
669*217ec208SDavid C Somayajulu 
670*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_search_filter(p_dev, ppfid, p_filter,
671*217ec208SDavid C Somayajulu 					    p_filter_idx);
672*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
673*217ec208SDavid C Somayajulu 		return rc;
674*217ec208SDavid C Somayajulu 
675*217ec208SDavid C Somayajulu 	/* No matching filter was found */
676*217ec208SDavid C Somayajulu 	if (*p_filter_idx == ECORE_LLH_INVALID_FILTER_IDX) {
677*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
678*217ec208SDavid C Somayajulu 			  "Failed to find a filter in the LLH shadow\n");
679*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
680*217ec208SDavid C Somayajulu 	}
681*217ec208SDavid C Somayajulu 
682*217ec208SDavid C Somayajulu 	return __ecore_llh_shadow_remove_filter(p_dev, ppfid, *p_filter_idx,
683*217ec208SDavid C Somayajulu 						p_ref_cnt);
684*217ec208SDavid C Somayajulu }
685*217ec208SDavid C Somayajulu 
686*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_shadow_remove_all_filters(struct ecore_dev * p_dev,u8 ppfid)687*217ec208SDavid C Somayajulu ecore_llh_shadow_remove_all_filters(struct ecore_dev *p_dev, u8 ppfid)
688*217ec208SDavid C Somayajulu {
689*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
690*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_info *p_filters;
691*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
692*217ec208SDavid C Somayajulu 
693*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_sanity(p_dev, ppfid, 0, "remove_all");
694*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
695*217ec208SDavid C Somayajulu 		return rc;
696*217ec208SDavid C Somayajulu 
697*217ec208SDavid C Somayajulu 	p_filters = p_llh_info->pp_filters[ppfid];
698*217ec208SDavid C Somayajulu 	OSAL_MEM_ZERO(p_filters,
699*217ec208SDavid C Somayajulu 		      NIG_REG_LLH_FUNC_FILTER_EN_SIZE * sizeof(*p_filters));
700*217ec208SDavid C Somayajulu 
701*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
702*217ec208SDavid C Somayajulu }
703*217ec208SDavid C Somayajulu 
ecore_abs_ppfid(struct ecore_dev * p_dev,u8 rel_ppfid,u8 * p_abs_ppfid)704*217ec208SDavid C Somayajulu static enum _ecore_status_t ecore_abs_ppfid(struct ecore_dev *p_dev,
705*217ec208SDavid C Somayajulu 					    u8 rel_ppfid, u8 *p_abs_ppfid)
706*217ec208SDavid C Somayajulu {
707*217ec208SDavid C Somayajulu 	struct ecore_llh_info *p_llh_info = p_dev->p_llh_info;
708*217ec208SDavid C Somayajulu 
709*217ec208SDavid C Somayajulu 	if (rel_ppfid >= p_llh_info->num_ppfid) {
710*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
711*217ec208SDavid C Somayajulu 			  "rel_ppfid %d is not valid, available indices are 0..%hhd\n",
712*217ec208SDavid C Somayajulu 			  rel_ppfid, (u8)(p_llh_info->num_ppfid - 1));
713*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
714*217ec208SDavid C Somayajulu 	}
715*217ec208SDavid C Somayajulu 
716*217ec208SDavid C Somayajulu 	*p_abs_ppfid = p_llh_info->ppfid_array[rel_ppfid];
717*217ec208SDavid C Somayajulu 
718*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
719*217ec208SDavid C Somayajulu }
720*217ec208SDavid C Somayajulu 
721*217ec208SDavid C Somayajulu static enum _ecore_status_t
__ecore_llh_set_engine_affin(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)722*217ec208SDavid C Somayajulu __ecore_llh_set_engine_affin(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
723*217ec208SDavid C Somayajulu {
724*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
725*217ec208SDavid C Somayajulu 	enum ecore_eng eng;
726*217ec208SDavid C Somayajulu 	u8 ppfid;
727*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
728*217ec208SDavid C Somayajulu 
729*217ec208SDavid C Somayajulu 	rc = ecore_mcp_get_engine_config(p_hwfn, p_ptt);
730*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
731*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
732*217ec208SDavid C Somayajulu 			  "Failed to get the engine affinity configuration\n");
733*217ec208SDavid C Somayajulu 		return rc;
734*217ec208SDavid C Somayajulu 	}
735*217ec208SDavid C Somayajulu 
736*217ec208SDavid C Somayajulu 	/* RoCE PF is bound to a single engine */
737*217ec208SDavid C Somayajulu 	if (ECORE_IS_ROCE_PERSONALITY(p_hwfn)) {
738*217ec208SDavid C Somayajulu 		eng = p_dev->fir_affin ? ECORE_ENG1 : ECORE_ENG0;
739*217ec208SDavid C Somayajulu 		rc = ecore_llh_set_roce_affinity(p_dev, eng);
740*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
741*217ec208SDavid C Somayajulu 			DP_NOTICE(p_dev, false,
742*217ec208SDavid C Somayajulu 				  "Failed to set the RoCE engine affinity\n");
743*217ec208SDavid C Somayajulu 			return rc;
744*217ec208SDavid C Somayajulu 		}
745*217ec208SDavid C Somayajulu 
746*217ec208SDavid C Somayajulu 		DP_VERBOSE(p_dev, ECORE_MSG_SP,
747*217ec208SDavid C Somayajulu 			   "LLH: Set the engine affinity of RoCE packets as %d\n",
748*217ec208SDavid C Somayajulu 			   eng);
749*217ec208SDavid C Somayajulu 	}
750*217ec208SDavid C Somayajulu 
751*217ec208SDavid C Somayajulu 	/* Storage PF is bound to a single engine while L2 PF uses both */
752*217ec208SDavid C Somayajulu 	if (ECORE_IS_FCOE_PERSONALITY(p_hwfn) ||
753*217ec208SDavid C Somayajulu 	    ECORE_IS_ISCSI_PERSONALITY(p_hwfn))
754*217ec208SDavid C Somayajulu 		eng = p_dev->fir_affin ? ECORE_ENG1 : ECORE_ENG0;
755*217ec208SDavid C Somayajulu 	else /* L2_PERSONALITY */
756*217ec208SDavid C Somayajulu 		eng = ECORE_BOTH_ENG;
757*217ec208SDavid C Somayajulu 
758*217ec208SDavid C Somayajulu 	for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++) {
759*217ec208SDavid C Somayajulu 		rc = ecore_llh_set_ppfid_affinity(p_dev, ppfid, eng);
760*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
761*217ec208SDavid C Somayajulu 			DP_NOTICE(p_dev, false,
762*217ec208SDavid C Somayajulu 				  "Failed to set the engine affinity of ppfid %d\n",
763*217ec208SDavid C Somayajulu 				  ppfid);
764*217ec208SDavid C Somayajulu 			return rc;
765*217ec208SDavid C Somayajulu 		}
766*217ec208SDavid C Somayajulu 	}
767*217ec208SDavid C Somayajulu 
768*217ec208SDavid C Somayajulu 	DP_VERBOSE(p_dev, ECORE_MSG_SP,
769*217ec208SDavid C Somayajulu 		   "LLH: Set the engine affinity of non-RoCE packets as %d\n",
770*217ec208SDavid C Somayajulu 		   eng);
771*217ec208SDavid C Somayajulu 
772*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
773*217ec208SDavid C Somayajulu }
774*217ec208SDavid C Somayajulu 
775*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_set_engine_affin(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,bool avoid_eng_affin)776*217ec208SDavid C Somayajulu ecore_llh_set_engine_affin(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
777*217ec208SDavid C Somayajulu 			   bool avoid_eng_affin)
778*217ec208SDavid C Somayajulu {
779*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
780*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
781*217ec208SDavid C Somayajulu 
782*217ec208SDavid C Somayajulu 	/* Backwards compatible mode:
783*217ec208SDavid C Somayajulu 	 * - RoCE packets     - Use engine 0.
784*217ec208SDavid C Somayajulu 	 * - Non-RoCE packets - Use connection based classification for L2 PFs,
785*217ec208SDavid C Somayajulu 	 *                      and engine 0 otherwise.
786*217ec208SDavid C Somayajulu 	 */
787*217ec208SDavid C Somayajulu 	if (avoid_eng_affin) {
788*217ec208SDavid C Somayajulu 		enum ecore_eng eng;
789*217ec208SDavid C Somayajulu 		u8 ppfid;
790*217ec208SDavid C Somayajulu 
791*217ec208SDavid C Somayajulu 		if (ECORE_IS_ROCE_PERSONALITY(p_hwfn)) {
792*217ec208SDavid C Somayajulu 			eng = ECORE_ENG0;
793*217ec208SDavid C Somayajulu 			rc = ecore_llh_set_roce_affinity(p_dev, eng);
794*217ec208SDavid C Somayajulu 			if (rc != ECORE_SUCCESS) {
795*217ec208SDavid C Somayajulu 				DP_NOTICE(p_dev, false,
796*217ec208SDavid C Somayajulu 					  "Failed to set the RoCE engine affinity\n");
797*217ec208SDavid C Somayajulu 				return rc;
798*217ec208SDavid C Somayajulu 			}
799*217ec208SDavid C Somayajulu 
800*217ec208SDavid C Somayajulu 			DP_VERBOSE(p_dev, ECORE_MSG_SP,
801*217ec208SDavid C Somayajulu 				   "LLH [backwards compatible mode]: Set the engine affinity of RoCE packets as %d\n",
802*217ec208SDavid C Somayajulu 				   eng);
803*217ec208SDavid C Somayajulu 		}
804*217ec208SDavid C Somayajulu 
805*217ec208SDavid C Somayajulu 		eng = (ECORE_IS_FCOE_PERSONALITY(p_hwfn) ||
806*217ec208SDavid C Somayajulu 		       ECORE_IS_ISCSI_PERSONALITY(p_hwfn)) ? ECORE_ENG0
807*217ec208SDavid C Somayajulu 							   : ECORE_BOTH_ENG;
808*217ec208SDavid C Somayajulu 		for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++) {
809*217ec208SDavid C Somayajulu 			rc = ecore_llh_set_ppfid_affinity(p_dev, ppfid, eng);
810*217ec208SDavid C Somayajulu 			if (rc != ECORE_SUCCESS) {
811*217ec208SDavid C Somayajulu 				DP_NOTICE(p_dev, false,
812*217ec208SDavid C Somayajulu 					  "Failed to set the engine affinity of ppfid %d\n",
813*217ec208SDavid C Somayajulu 					  ppfid);
814*217ec208SDavid C Somayajulu 				return rc;
815*217ec208SDavid C Somayajulu 			}
816*217ec208SDavid C Somayajulu 		}
817*217ec208SDavid C Somayajulu 
818*217ec208SDavid C Somayajulu 		DP_VERBOSE(p_dev, ECORE_MSG_SP,
819*217ec208SDavid C Somayajulu 			   "LLH [backwards compatible mode]: Set the engine affinity of non-RoCE packets as %d\n",
820*217ec208SDavid C Somayajulu 			   eng);
821*217ec208SDavid C Somayajulu 
822*217ec208SDavid C Somayajulu 		return ECORE_SUCCESS;
823*217ec208SDavid C Somayajulu 	}
824*217ec208SDavid C Somayajulu 
825*217ec208SDavid C Somayajulu 	return __ecore_llh_set_engine_affin(p_hwfn, p_ptt);
826*217ec208SDavid C Somayajulu }
827*217ec208SDavid C Somayajulu 
ecore_llh_hw_init_pf(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,bool avoid_eng_affin)828*217ec208SDavid C Somayajulu static enum _ecore_status_t ecore_llh_hw_init_pf(struct ecore_hwfn *p_hwfn,
829*217ec208SDavid C Somayajulu 						 struct ecore_ptt *p_ptt,
830*217ec208SDavid C Somayajulu 						 bool avoid_eng_affin)
831*217ec208SDavid C Somayajulu {
832*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
833*217ec208SDavid C Somayajulu 	u8 ppfid, abs_ppfid;
834*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
835*217ec208SDavid C Somayajulu 
836*217ec208SDavid C Somayajulu 	for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++) {
837*217ec208SDavid C Somayajulu 		u32 addr;
838*217ec208SDavid C Somayajulu 
839*217ec208SDavid C Somayajulu 		rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
840*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
841*217ec208SDavid C Somayajulu 			return rc;
842*217ec208SDavid C Somayajulu 
843*217ec208SDavid C Somayajulu 		addr = NIG_REG_LLH_PPFID2PFID_TBL_0 + abs_ppfid * 0x4;
844*217ec208SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, addr, p_hwfn->rel_pf_id);
845*217ec208SDavid C Somayajulu 	}
846*217ec208SDavid C Somayajulu 
847*217ec208SDavid C Somayajulu 	if (OSAL_TEST_BIT(ECORE_MF_LLH_MAC_CLSS, &p_dev->mf_bits) &&
848*217ec208SDavid C Somayajulu 	    !ECORE_IS_FCOE_PERSONALITY(p_hwfn)) {
849*217ec208SDavid C Somayajulu 		rc = ecore_llh_add_mac_filter(p_dev, 0,
850*217ec208SDavid C Somayajulu 					      p_hwfn->hw_info.hw_mac_addr);
851*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
852*217ec208SDavid C Somayajulu 			DP_NOTICE(p_dev, false,
853*217ec208SDavid C Somayajulu 				  "Failed to add an LLH filter with the primary MAC\n");
854*217ec208SDavid C Somayajulu 	}
855*217ec208SDavid C Somayajulu 
856*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_dev)) {
857*217ec208SDavid C Somayajulu 		rc = ecore_llh_set_engine_affin(p_hwfn, p_ptt, avoid_eng_affin);
858*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
859*217ec208SDavid C Somayajulu 			return rc;
860*217ec208SDavid C Somayajulu 	}
861*217ec208SDavid C Somayajulu 
862*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
863*217ec208SDavid C Somayajulu }
864*217ec208SDavid C Somayajulu 
ecore_llh_get_num_ppfid(struct ecore_dev * p_dev)865*217ec208SDavid C Somayajulu u8 ecore_llh_get_num_ppfid(struct ecore_dev *p_dev)
866*217ec208SDavid C Somayajulu {
867*217ec208SDavid C Somayajulu 	return p_dev->p_llh_info->num_ppfid;
868*217ec208SDavid C Somayajulu }
869*217ec208SDavid C Somayajulu 
ecore_llh_get_l2_affinity_hint(struct ecore_dev * p_dev)870*217ec208SDavid C Somayajulu enum ecore_eng ecore_llh_get_l2_affinity_hint(struct ecore_dev *p_dev)
871*217ec208SDavid C Somayajulu {
872*217ec208SDavid C Somayajulu 	return p_dev->l2_affin_hint ? ECORE_ENG1 : ECORE_ENG0;
873*217ec208SDavid C Somayajulu }
874*217ec208SDavid C Somayajulu 
875*217ec208SDavid C Somayajulu /* TBD - should be removed when these definitions are available in reg_addr.h */
876*217ec208SDavid C Somayajulu #define NIG_REG_PPF_TO_ENGINE_SEL_ROCE_MASK		0x3
877*217ec208SDavid C Somayajulu #define NIG_REG_PPF_TO_ENGINE_SEL_ROCE_SHIFT		0
878*217ec208SDavid C Somayajulu #define NIG_REG_PPF_TO_ENGINE_SEL_NON_ROCE_MASK		0x3
879*217ec208SDavid C Somayajulu #define NIG_REG_PPF_TO_ENGINE_SEL_NON_ROCE_SHIFT	2
880*217ec208SDavid C Somayajulu 
ecore_llh_set_ppfid_affinity(struct ecore_dev * p_dev,u8 ppfid,enum ecore_eng eng)881*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_llh_set_ppfid_affinity(struct ecore_dev *p_dev,
882*217ec208SDavid C Somayajulu 						  u8 ppfid, enum ecore_eng eng)
883*217ec208SDavid C Somayajulu {
884*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
885*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
886*217ec208SDavid C Somayajulu 	u32 addr, val, eng_sel;
887*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
888*217ec208SDavid C Somayajulu 	u8 abs_ppfid;
889*217ec208SDavid C Somayajulu 
890*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
891*217ec208SDavid C Somayajulu 		return ECORE_AGAIN;
892*217ec208SDavid C Somayajulu 
893*217ec208SDavid C Somayajulu 	if (!ECORE_IS_CMT(p_dev))
894*217ec208SDavid C Somayajulu 		goto out;
895*217ec208SDavid C Somayajulu 
896*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
897*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
898*217ec208SDavid C Somayajulu 		goto out;
899*217ec208SDavid C Somayajulu 
900*217ec208SDavid C Somayajulu 	switch (eng) {
901*217ec208SDavid C Somayajulu 	case ECORE_ENG0:
902*217ec208SDavid C Somayajulu 		eng_sel = 0;
903*217ec208SDavid C Somayajulu 		break;
904*217ec208SDavid C Somayajulu 	case ECORE_ENG1:
905*217ec208SDavid C Somayajulu 		eng_sel = 1;
906*217ec208SDavid C Somayajulu 		break;
907*217ec208SDavid C Somayajulu 	case ECORE_BOTH_ENG:
908*217ec208SDavid C Somayajulu 		eng_sel = 2;
909*217ec208SDavid C Somayajulu 		break;
910*217ec208SDavid C Somayajulu 	default:
911*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
912*217ec208SDavid C Somayajulu 			  "Invalid affinity value for ppfid [%d]\n", eng);
913*217ec208SDavid C Somayajulu 		rc = ECORE_INVAL;
914*217ec208SDavid C Somayajulu 		goto out;
915*217ec208SDavid C Somayajulu 	}
916*217ec208SDavid C Somayajulu 
917*217ec208SDavid C Somayajulu 	addr = NIG_REG_PPF_TO_ENGINE_SEL + abs_ppfid * 0x4;
918*217ec208SDavid C Somayajulu 	val = ecore_rd(p_hwfn, p_ptt, addr);
919*217ec208SDavid C Somayajulu 	SET_FIELD(val, NIG_REG_PPF_TO_ENGINE_SEL_NON_ROCE, eng_sel);
920*217ec208SDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, addr, val);
921*217ec208SDavid C Somayajulu 
922*217ec208SDavid C Somayajulu 	/* The iWARP affinity is set as the affinity of ppfid 0 */
923*217ec208SDavid C Somayajulu 	if (!ppfid && ECORE_IS_IWARP_PERSONALITY(p_hwfn))
924*217ec208SDavid C Somayajulu 		p_dev->iwarp_affin = (eng == ECORE_ENG1) ? 1 : 0;
925*217ec208SDavid C Somayajulu out:
926*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
927*217ec208SDavid C Somayajulu 
928*217ec208SDavid C Somayajulu 	return rc;
929*217ec208SDavid C Somayajulu }
930*217ec208SDavid C Somayajulu 
ecore_llh_set_roce_affinity(struct ecore_dev * p_dev,enum ecore_eng eng)931*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_llh_set_roce_affinity(struct ecore_dev *p_dev,
932*217ec208SDavid C Somayajulu 						 enum ecore_eng eng)
933*217ec208SDavid C Somayajulu {
934*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
935*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
936*217ec208SDavid C Somayajulu 	u32 addr, val, eng_sel;
937*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
938*217ec208SDavid C Somayajulu 	u8 ppfid, abs_ppfid;
939*217ec208SDavid C Somayajulu 
940*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
941*217ec208SDavid C Somayajulu 		return ECORE_AGAIN;
942*217ec208SDavid C Somayajulu 
943*217ec208SDavid C Somayajulu 	if (!ECORE_IS_CMT(p_dev))
944*217ec208SDavid C Somayajulu 		goto out;
945*217ec208SDavid C Somayajulu 
946*217ec208SDavid C Somayajulu 	switch (eng) {
947*217ec208SDavid C Somayajulu 	case ECORE_ENG0:
948*217ec208SDavid C Somayajulu 		eng_sel = 0;
949*217ec208SDavid C Somayajulu 		break;
950*217ec208SDavid C Somayajulu 	case ECORE_ENG1:
951*217ec208SDavid C Somayajulu 		eng_sel = 1;
952*217ec208SDavid C Somayajulu 		break;
953*217ec208SDavid C Somayajulu 	case ECORE_BOTH_ENG:
954*217ec208SDavid C Somayajulu 		eng_sel = 2;
955*217ec208SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_ENG_CLS_ROCE_QP_SEL,
956*217ec208SDavid C Somayajulu 			 0xf /* QP bit 15 */);
957*217ec208SDavid C Somayajulu 		break;
958*217ec208SDavid C Somayajulu 	default:
959*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
960*217ec208SDavid C Somayajulu 			  "Invalid affinity value for RoCE [%d]\n", eng);
961*217ec208SDavid C Somayajulu 		rc = ECORE_INVAL;
962*217ec208SDavid C Somayajulu 		goto out;
963*217ec208SDavid C Somayajulu 	}
964*217ec208SDavid C Somayajulu 
965*217ec208SDavid C Somayajulu 	for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++) {
966*217ec208SDavid C Somayajulu 		rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
967*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
968*217ec208SDavid C Somayajulu 			goto out;
969*217ec208SDavid C Somayajulu 
970*217ec208SDavid C Somayajulu 		addr = NIG_REG_PPF_TO_ENGINE_SEL + abs_ppfid * 0x4;
971*217ec208SDavid C Somayajulu 		val = ecore_rd(p_hwfn, p_ptt, addr);
972*217ec208SDavid C Somayajulu 		SET_FIELD(val, NIG_REG_PPF_TO_ENGINE_SEL_ROCE, eng_sel);
973*217ec208SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, addr, val);
974*217ec208SDavid C Somayajulu 	}
975*217ec208SDavid C Somayajulu out:
976*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
977*217ec208SDavid C Somayajulu 
978*217ec208SDavid C Somayajulu 	return rc;
979*217ec208SDavid C Somayajulu }
980*217ec208SDavid C Somayajulu 
981*217ec208SDavid C Somayajulu struct ecore_llh_filter_e4_details {
982*217ec208SDavid C Somayajulu 	u64 value;
983*217ec208SDavid C Somayajulu 	u32 mode;
984*217ec208SDavid C Somayajulu 	u32 protocol_type;
985*217ec208SDavid C Somayajulu 	u32 hdr_sel;
986*217ec208SDavid C Somayajulu 	u32 enable;
987*217ec208SDavid C Somayajulu };
988*217ec208SDavid C Somayajulu 
989*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_access_filter_e4(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 abs_ppfid,u8 filter_idx,struct ecore_llh_filter_e4_details * p_details,bool b_write_access)990*217ec208SDavid C Somayajulu ecore_llh_access_filter_e4(struct ecore_hwfn *p_hwfn,
991*217ec208SDavid C Somayajulu 			   struct ecore_ptt *p_ptt, u8 abs_ppfid, u8 filter_idx,
992*217ec208SDavid C Somayajulu 			   struct ecore_llh_filter_e4_details *p_details,
993*217ec208SDavid C Somayajulu 			   bool b_write_access)
994*217ec208SDavid C Somayajulu {
995*217ec208SDavid C Somayajulu 	u8 pfid = ECORE_PFID_BY_PPFID(p_hwfn, abs_ppfid);
996*217ec208SDavid C Somayajulu 	struct ecore_dmae_params params;
997*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
998*217ec208SDavid C Somayajulu 	u32 addr;
999*217ec208SDavid C Somayajulu 
1000*217ec208SDavid C Somayajulu 	/* The NIG/LLH registers that are accessed in this function have only 16
1001*217ec208SDavid C Somayajulu 	 * rows which are exposed to a PF. I.e. only the 16 filters of its
1002*217ec208SDavid C Somayajulu 	 * default ppfid
1003*217ec208SDavid C Somayajulu 	 * Accessing filters of other ppfids requires pretending to other PFs,
1004*217ec208SDavid C Somayajulu 	 * and thus the usage of the ecore_ppfid_rd/wr() functions.
1005*217ec208SDavid C Somayajulu 	 */
1006*217ec208SDavid C Somayajulu 
1007*217ec208SDavid C Somayajulu 	/* Filter enable - should be done first when removing a filter */
1008*217ec208SDavid C Somayajulu 	if (b_write_access && !p_details->enable) {
1009*217ec208SDavid C Somayajulu 		addr = NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + filter_idx * 0x4;
1010*217ec208SDavid C Somayajulu 		ecore_ppfid_wr(p_hwfn, p_ptt, abs_ppfid, addr,
1011*217ec208SDavid C Somayajulu 			       p_details->enable);
1012*217ec208SDavid C Somayajulu 	}
1013*217ec208SDavid C Somayajulu 
1014*217ec208SDavid C Somayajulu 	/* Filter value */
1015*217ec208SDavid C Somayajulu 	addr = NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 + 2 * filter_idx * 0x4;
1016*217ec208SDavid C Somayajulu 	OSAL_MEMSET(&params, 0, sizeof(params));
1017*217ec208SDavid C Somayajulu 
1018*217ec208SDavid C Somayajulu 	if (b_write_access) {
1019*217ec208SDavid C Somayajulu 		params.flags = ECORE_DMAE_FLAG_PF_DST;
1020*217ec208SDavid C Somayajulu 		params.dst_pfid = pfid;
1021*217ec208SDavid C Somayajulu 		rc = ecore_dmae_host2grc(p_hwfn, p_ptt,
1022*217ec208SDavid C Somayajulu 					 (u64)(osal_uintptr_t)&p_details->value,
1023*217ec208SDavid C Somayajulu 					 addr, 2 /* size_in_dwords */, &params);
1024*217ec208SDavid C Somayajulu 	} else {
1025*217ec208SDavid C Somayajulu 		params.flags = ECORE_DMAE_FLAG_PF_SRC |
1026*217ec208SDavid C Somayajulu 			       ECORE_DMAE_FLAG_COMPLETION_DST;
1027*217ec208SDavid C Somayajulu 		params.src_pfid = pfid;
1028*217ec208SDavid C Somayajulu 		rc = ecore_dmae_grc2host(p_hwfn, p_ptt, addr,
1029*217ec208SDavid C Somayajulu 					 (u64)(osal_uintptr_t)&p_details->value,
1030*217ec208SDavid C Somayajulu 					 2 /* size_in_dwords */, &params);
1031*217ec208SDavid C Somayajulu 	}
1032*217ec208SDavid C Somayajulu 
1033*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1034*217ec208SDavid C Somayajulu 		return rc;
1035*217ec208SDavid C Somayajulu 
1036*217ec208SDavid C Somayajulu 	/* Filter mode */
1037*217ec208SDavid C Somayajulu 	addr = NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 + filter_idx * 0x4;
1038*217ec208SDavid C Somayajulu 	if (b_write_access)
1039*217ec208SDavid C Somayajulu 		ecore_ppfid_wr(p_hwfn, p_ptt, abs_ppfid, addr, p_details->mode);
1040*217ec208SDavid C Somayajulu 	else
1041*217ec208SDavid C Somayajulu 		p_details->mode = ecore_ppfid_rd(p_hwfn, p_ptt, abs_ppfid,
1042*217ec208SDavid C Somayajulu 						 addr);
1043*217ec208SDavid C Somayajulu 
1044*217ec208SDavid C Somayajulu 	/* Filter protocol type */
1045*217ec208SDavid C Somayajulu 	addr = NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 + filter_idx * 0x4;
1046*217ec208SDavid C Somayajulu 	if (b_write_access)
1047*217ec208SDavid C Somayajulu 		ecore_ppfid_wr(p_hwfn, p_ptt, abs_ppfid, addr,
1048*217ec208SDavid C Somayajulu 			       p_details->protocol_type);
1049*217ec208SDavid C Somayajulu 	else
1050*217ec208SDavid C Somayajulu 		p_details->protocol_type = ecore_ppfid_rd(p_hwfn, p_ptt,
1051*217ec208SDavid C Somayajulu 							  abs_ppfid, addr);
1052*217ec208SDavid C Somayajulu 
1053*217ec208SDavid C Somayajulu 	/* Filter header select */
1054*217ec208SDavid C Somayajulu 	addr = NIG_REG_LLH_FUNC_FILTER_HDR_SEL_BB_K2 + filter_idx * 0x4;
1055*217ec208SDavid C Somayajulu 	if (b_write_access)
1056*217ec208SDavid C Somayajulu 		ecore_ppfid_wr(p_hwfn, p_ptt, abs_ppfid, addr,
1057*217ec208SDavid C Somayajulu 			       p_details->hdr_sel);
1058*217ec208SDavid C Somayajulu 	else
1059*217ec208SDavid C Somayajulu 		p_details->hdr_sel = ecore_ppfid_rd(p_hwfn, p_ptt, abs_ppfid,
1060*217ec208SDavid C Somayajulu 						    addr);
1061*217ec208SDavid C Somayajulu 
1062*217ec208SDavid C Somayajulu 	/* Filter enable - should be done last when adding a filter */
1063*217ec208SDavid C Somayajulu 	if (!b_write_access || p_details->enable) {
1064*217ec208SDavid C Somayajulu 		addr = NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + filter_idx * 0x4;
1065*217ec208SDavid C Somayajulu 		if (b_write_access)
1066*217ec208SDavid C Somayajulu 			ecore_ppfid_wr(p_hwfn, p_ptt, abs_ppfid, addr,
1067*217ec208SDavid C Somayajulu 				       p_details->enable);
1068*217ec208SDavid C Somayajulu 		else
1069*217ec208SDavid C Somayajulu 			p_details->enable = ecore_ppfid_rd(p_hwfn, p_ptt,
1070*217ec208SDavid C Somayajulu 							   abs_ppfid, addr);
1071*217ec208SDavid C Somayajulu 	}
1072*217ec208SDavid C Somayajulu 
1073*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1074*217ec208SDavid C Somayajulu }
1075*217ec208SDavid C Somayajulu 
1076*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_add_filter_e4(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 abs_ppfid,u8 filter_idx,u8 filter_prot_type,u32 high,u32 low)1077*217ec208SDavid C Somayajulu ecore_llh_add_filter_e4(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1078*217ec208SDavid C Somayajulu 			u8 abs_ppfid, u8 filter_idx, u8 filter_prot_type,
1079*217ec208SDavid C Somayajulu 			u32 high, u32 low)
1080*217ec208SDavid C Somayajulu {
1081*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_e4_details filter_details;
1082*217ec208SDavid C Somayajulu 
1083*217ec208SDavid C Somayajulu 	filter_details.enable = 1;
1084*217ec208SDavid C Somayajulu 	filter_details.value = ((u64)high << 32) | low;
1085*217ec208SDavid C Somayajulu 	filter_details.hdr_sel = 0;
1086*217ec208SDavid C Somayajulu 	filter_details.protocol_type = filter_prot_type;
1087*217ec208SDavid C Somayajulu 	filter_details.mode = filter_prot_type ?
1088*217ec208SDavid C Somayajulu 			      1 : /* protocol-based classification */
1089*217ec208SDavid C Somayajulu 			      0;  /* MAC-address based classification */
1090*217ec208SDavid C Somayajulu 
1091*217ec208SDavid C Somayajulu 	return ecore_llh_access_filter_e4(p_hwfn, p_ptt, abs_ppfid, filter_idx,
1092*217ec208SDavid C Somayajulu 					  &filter_details,
1093*217ec208SDavid C Somayajulu 					  true /* write access */);
1094*217ec208SDavid C Somayajulu }
1095*217ec208SDavid C Somayajulu 
1096*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_remove_filter_e4(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 abs_ppfid,u8 filter_idx)1097*217ec208SDavid C Somayajulu ecore_llh_remove_filter_e4(struct ecore_hwfn *p_hwfn,
1098*217ec208SDavid C Somayajulu 			   struct ecore_ptt *p_ptt, u8 abs_ppfid, u8 filter_idx)
1099*217ec208SDavid C Somayajulu {
1100*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_e4_details filter_details;
1101*217ec208SDavid C Somayajulu 
1102*217ec208SDavid C Somayajulu 	OSAL_MEMSET(&filter_details, 0, sizeof(filter_details));
1103*217ec208SDavid C Somayajulu 
1104*217ec208SDavid C Somayajulu 	return ecore_llh_access_filter_e4(p_hwfn, p_ptt, abs_ppfid, filter_idx,
1105*217ec208SDavid C Somayajulu 					  &filter_details,
1106*217ec208SDavid C Somayajulu 					  true /* write access */);
1107*217ec208SDavid C Somayajulu }
1108*217ec208SDavid C Somayajulu 
1109*217ec208SDavid C Somayajulu /* OSAL_UNUSED is temporary used to avoid unused-parameter compilation warnings.
1110*217ec208SDavid C Somayajulu  * Should be removed when the function is implemented.
1111*217ec208SDavid C Somayajulu  */
1112*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_add_filter_e5(struct ecore_hwfn OSAL_UNUSED * p_hwfn,struct ecore_ptt OSAL_UNUSED * p_ptt,u8 OSAL_UNUSED abs_ppfid,u8 OSAL_UNUSED filter_idx,u8 OSAL_UNUSED filter_prot_type,u32 OSAL_UNUSED high,u32 OSAL_UNUSED low)1113*217ec208SDavid C Somayajulu ecore_llh_add_filter_e5(struct ecore_hwfn OSAL_UNUSED *p_hwfn,
1114*217ec208SDavid C Somayajulu 			struct ecore_ptt OSAL_UNUSED *p_ptt,
1115*217ec208SDavid C Somayajulu 			u8 OSAL_UNUSED abs_ppfid, u8 OSAL_UNUSED filter_idx,
1116*217ec208SDavid C Somayajulu 			u8 OSAL_UNUSED filter_prot_type, u32 OSAL_UNUSED high,
1117*217ec208SDavid C Somayajulu 			u32 OSAL_UNUSED low)
1118*217ec208SDavid C Somayajulu {
1119*217ec208SDavid C Somayajulu 	ECORE_E5_MISSING_CODE;
1120*217ec208SDavid C Somayajulu 
1121*217ec208SDavid C Somayajulu 	return ECORE_NOTIMPL;
1122*217ec208SDavid C Somayajulu }
1123*217ec208SDavid C Somayajulu 
1124*217ec208SDavid C Somayajulu /* OSAL_UNUSED is temporary used to avoid unused-parameter compilation warnings.
1125*217ec208SDavid C Somayajulu  * Should be removed when the function is implemented.
1126*217ec208SDavid C Somayajulu  */
1127*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_remove_filter_e5(struct ecore_hwfn OSAL_UNUSED * p_hwfn,struct ecore_ptt OSAL_UNUSED * p_ptt,u8 OSAL_UNUSED abs_ppfid,u8 OSAL_UNUSED filter_idx)1128*217ec208SDavid C Somayajulu ecore_llh_remove_filter_e5(struct ecore_hwfn OSAL_UNUSED *p_hwfn,
1129*217ec208SDavid C Somayajulu 			   struct ecore_ptt OSAL_UNUSED *p_ptt,
1130*217ec208SDavid C Somayajulu 			   u8 OSAL_UNUSED abs_ppfid,
1131*217ec208SDavid C Somayajulu 			   u8 OSAL_UNUSED filter_idx)
1132*217ec208SDavid C Somayajulu {
1133*217ec208SDavid C Somayajulu 	ECORE_E5_MISSING_CODE;
1134*217ec208SDavid C Somayajulu 
1135*217ec208SDavid C Somayajulu 	return ECORE_NOTIMPL;
1136*217ec208SDavid C Somayajulu }
1137*217ec208SDavid C Somayajulu 
1138*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_add_filter(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 abs_ppfid,u8 filter_idx,u8 filter_prot_type,u32 high,u32 low)1139*217ec208SDavid C Somayajulu ecore_llh_add_filter(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1140*217ec208SDavid C Somayajulu 		     u8 abs_ppfid, u8 filter_idx, u8 filter_prot_type, u32 high,
1141*217ec208SDavid C Somayajulu 		     u32 low)
1142*217ec208SDavid C Somayajulu {
1143*217ec208SDavid C Somayajulu 	if (ECORE_IS_E4(p_hwfn->p_dev))
1144*217ec208SDavid C Somayajulu 		return ecore_llh_add_filter_e4(p_hwfn, p_ptt, abs_ppfid,
1145*217ec208SDavid C Somayajulu 					       filter_idx, filter_prot_type,
1146*217ec208SDavid C Somayajulu 					       high, low);
1147*217ec208SDavid C Somayajulu 	else /* E5 */
1148*217ec208SDavid C Somayajulu 		return ecore_llh_add_filter_e5(p_hwfn, p_ptt, abs_ppfid,
1149*217ec208SDavid C Somayajulu 					       filter_idx, filter_prot_type,
1150*217ec208SDavid C Somayajulu 					       high, low);
1151*217ec208SDavid C Somayajulu }
1152*217ec208SDavid C Somayajulu 
1153*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_remove_filter(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 abs_ppfid,u8 filter_idx)1154*217ec208SDavid C Somayajulu ecore_llh_remove_filter(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1155*217ec208SDavid C Somayajulu 			u8 abs_ppfid, u8 filter_idx)
1156*217ec208SDavid C Somayajulu {
1157*217ec208SDavid C Somayajulu 	if (ECORE_IS_E4(p_hwfn->p_dev))
1158*217ec208SDavid C Somayajulu 		return ecore_llh_remove_filter_e4(p_hwfn, p_ptt, abs_ppfid,
1159*217ec208SDavid C Somayajulu 						  filter_idx);
1160*217ec208SDavid C Somayajulu 	else /* E5 */
1161*217ec208SDavid C Somayajulu 		return ecore_llh_remove_filter_e5(p_hwfn, p_ptt, abs_ppfid,
1162*217ec208SDavid C Somayajulu 						  filter_idx);
1163*217ec208SDavid C Somayajulu }
1164*217ec208SDavid C Somayajulu 
ecore_llh_add_mac_filter(struct ecore_dev * p_dev,u8 ppfid,u8 mac_addr[ETH_ALEN])1165*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_dev *p_dev, u8 ppfid,
1166*217ec208SDavid C Somayajulu 					      u8 mac_addr[ETH_ALEN])
1167*217ec208SDavid C Somayajulu {
1168*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
1169*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
1170*217ec208SDavid C Somayajulu 	union ecore_llh_filter filter;
1171*217ec208SDavid C Somayajulu 	u8 filter_idx, abs_ppfid;
1172*217ec208SDavid C Somayajulu 	u32 high, low, ref_cnt;
1173*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
1174*217ec208SDavid C Somayajulu 
1175*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
1176*217ec208SDavid C Somayajulu 		return ECORE_AGAIN;
1177*217ec208SDavid C Somayajulu 
1178*217ec208SDavid C Somayajulu 	if (!OSAL_TEST_BIT(ECORE_MF_LLH_MAC_CLSS, &p_dev->mf_bits))
1179*217ec208SDavid C Somayajulu 		goto out;
1180*217ec208SDavid C Somayajulu 
1181*217ec208SDavid C Somayajulu 	OSAL_MEM_ZERO(&filter, sizeof(filter));
1182*217ec208SDavid C Somayajulu 	OSAL_MEMCPY(filter.mac.addr, mac_addr, ETH_ALEN);
1183*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_add_filter(p_dev, ppfid,
1184*217ec208SDavid C Somayajulu 					 ECORE_LLH_FILTER_TYPE_MAC,
1185*217ec208SDavid C Somayajulu 					 &filter, &filter_idx, &ref_cnt);
1186*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1187*217ec208SDavid C Somayajulu 		goto err;
1188*217ec208SDavid C Somayajulu 
1189*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
1190*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1191*217ec208SDavid C Somayajulu 		goto err;
1192*217ec208SDavid C Somayajulu 
1193*217ec208SDavid C Somayajulu 	/* Configure the LLH only in case of a new the filter */
1194*217ec208SDavid C Somayajulu 	if (ref_cnt == 1) {
1195*217ec208SDavid C Somayajulu 		high = mac_addr[1] | (mac_addr[0] << 8);
1196*217ec208SDavid C Somayajulu 		low = mac_addr[5] | (mac_addr[4] << 8) | (mac_addr[3] << 16) |
1197*217ec208SDavid C Somayajulu 		      (mac_addr[2] << 24);
1198*217ec208SDavid C Somayajulu 		rc = ecore_llh_add_filter(p_hwfn, p_ptt, abs_ppfid, filter_idx,
1199*217ec208SDavid C Somayajulu 					  0, high, low);
1200*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1201*217ec208SDavid C Somayajulu 			goto err;
1202*217ec208SDavid C Somayajulu 	}
1203*217ec208SDavid C Somayajulu 
1204*217ec208SDavid C Somayajulu 	DP_VERBOSE(p_dev, ECORE_MSG_SP,
1205*217ec208SDavid C Somayajulu 		   "LLH: Added MAC filter [%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx] to ppfid %hhd [abs %hhd] at idx %hhd [ref_cnt %d]\n",
1206*217ec208SDavid C Somayajulu 		   mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
1207*217ec208SDavid C Somayajulu 		   mac_addr[4], mac_addr[5], ppfid, abs_ppfid, filter_idx,
1208*217ec208SDavid C Somayajulu 		   ref_cnt);
1209*217ec208SDavid C Somayajulu 
1210*217ec208SDavid C Somayajulu 	goto out;
1211*217ec208SDavid C Somayajulu 
1212*217ec208SDavid C Somayajulu err:
1213*217ec208SDavid C Somayajulu 	DP_NOTICE(p_dev, false,
1214*217ec208SDavid C Somayajulu 		  "LLH: Failed to add MAC filter [%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx] to ppfid %hhd\n",
1215*217ec208SDavid C Somayajulu 		  mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
1216*217ec208SDavid C Somayajulu 		  mac_addr[4], mac_addr[5], ppfid);
1217*217ec208SDavid C Somayajulu out:
1218*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
1219*217ec208SDavid C Somayajulu 
1220*217ec208SDavid C Somayajulu 	return rc;
1221*217ec208SDavid C Somayajulu }
1222*217ec208SDavid C Somayajulu 
1223*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_protocol_filter_stringify(struct ecore_dev * p_dev,enum ecore_llh_prot_filter_type_t type,u16 source_port_or_eth_type,u16 dest_port,u8 * str,osal_size_t str_len)1224*217ec208SDavid C Somayajulu ecore_llh_protocol_filter_stringify(struct ecore_dev *p_dev,
1225*217ec208SDavid C Somayajulu 				    enum ecore_llh_prot_filter_type_t type,
1226*217ec208SDavid C Somayajulu 				    u16 source_port_or_eth_type, u16 dest_port,
1227*217ec208SDavid C Somayajulu 				    u8 *str, osal_size_t str_len)
1228*217ec208SDavid C Somayajulu {
1229*217ec208SDavid C Somayajulu 	switch (type) {
1230*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_ETHERTYPE:
1231*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "Ethertype 0x%04x",
1232*217ec208SDavid C Somayajulu 			      source_port_or_eth_type);
1233*217ec208SDavid C Somayajulu 		break;
1234*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_TCP_SRC_PORT:
1235*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "TCP src port 0x%04x",
1236*217ec208SDavid C Somayajulu 			      source_port_or_eth_type);
1237*217ec208SDavid C Somayajulu 		break;
1238*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_UDP_SRC_PORT:
1239*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "UDP src port 0x%04x",
1240*217ec208SDavid C Somayajulu 			      source_port_or_eth_type);
1241*217ec208SDavid C Somayajulu 		break;
1242*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_TCP_DEST_PORT:
1243*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "TCP dst port 0x%04x", dest_port);
1244*217ec208SDavid C Somayajulu 		break;
1245*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_UDP_DEST_PORT:
1246*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "UDP dst port 0x%04x", dest_port);
1247*217ec208SDavid C Somayajulu 		break;
1248*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
1249*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "TCP src/dst ports 0x%04x/0x%04x",
1250*217ec208SDavid C Somayajulu 			      source_port_or_eth_type, dest_port);
1251*217ec208SDavid C Somayajulu 		break;
1252*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
1253*217ec208SDavid C Somayajulu 		OSAL_SNPRINTF(str, str_len, "UDP src/dst ports 0x%04x/0x%04x",
1254*217ec208SDavid C Somayajulu 			      source_port_or_eth_type, dest_port);
1255*217ec208SDavid C Somayajulu 		break;
1256*217ec208SDavid C Somayajulu 	default:
1257*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, true,
1258*217ec208SDavid C Somayajulu 			  "Non valid LLH protocol filter type %d\n", type);
1259*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
1260*217ec208SDavid C Somayajulu 	}
1261*217ec208SDavid C Somayajulu 
1262*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1263*217ec208SDavid C Somayajulu }
1264*217ec208SDavid C Somayajulu 
1265*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_protocol_filter_to_hilo(struct ecore_dev * p_dev,enum ecore_llh_prot_filter_type_t type,u16 source_port_or_eth_type,u16 dest_port,u32 * p_high,u32 * p_low)1266*217ec208SDavid C Somayajulu ecore_llh_protocol_filter_to_hilo(struct ecore_dev *p_dev,
1267*217ec208SDavid C Somayajulu 				  enum ecore_llh_prot_filter_type_t type,
1268*217ec208SDavid C Somayajulu 				  u16 source_port_or_eth_type, u16 dest_port,
1269*217ec208SDavid C Somayajulu 				  u32 *p_high, u32 *p_low)
1270*217ec208SDavid C Somayajulu {
1271*217ec208SDavid C Somayajulu 	*p_high = 0;
1272*217ec208SDavid C Somayajulu 	*p_low = 0;
1273*217ec208SDavid C Somayajulu 
1274*217ec208SDavid C Somayajulu 	switch (type) {
1275*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_ETHERTYPE:
1276*217ec208SDavid C Somayajulu 		*p_high = source_port_or_eth_type;
1277*217ec208SDavid C Somayajulu 		break;
1278*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_TCP_SRC_PORT:
1279*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_UDP_SRC_PORT:
1280*217ec208SDavid C Somayajulu 		*p_low = source_port_or_eth_type << 16;
1281*217ec208SDavid C Somayajulu 		break;
1282*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_TCP_DEST_PORT:
1283*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_UDP_DEST_PORT:
1284*217ec208SDavid C Somayajulu 		*p_low = dest_port;
1285*217ec208SDavid C Somayajulu 		break;
1286*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
1287*217ec208SDavid C Somayajulu 	case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
1288*217ec208SDavid C Somayajulu 		*p_low = (source_port_or_eth_type << 16) | dest_port;
1289*217ec208SDavid C Somayajulu 		break;
1290*217ec208SDavid C Somayajulu 	default:
1291*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, true,
1292*217ec208SDavid C Somayajulu 			  "Non valid LLH protocol filter type %d\n", type);
1293*217ec208SDavid C Somayajulu 		return ECORE_INVAL;
1294*217ec208SDavid C Somayajulu 	}
1295*217ec208SDavid C Somayajulu 
1296*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1297*217ec208SDavid C Somayajulu }
1298*217ec208SDavid C Somayajulu 
1299*217ec208SDavid C Somayajulu enum _ecore_status_t
ecore_llh_add_protocol_filter(struct ecore_dev * p_dev,u8 ppfid,enum ecore_llh_prot_filter_type_t type,u16 source_port_or_eth_type,u16 dest_port)1300*217ec208SDavid C Somayajulu ecore_llh_add_protocol_filter(struct ecore_dev *p_dev, u8 ppfid,
1301*217ec208SDavid C Somayajulu 			      enum ecore_llh_prot_filter_type_t type,
1302*217ec208SDavid C Somayajulu 			      u16 source_port_or_eth_type, u16 dest_port)
1303*217ec208SDavid C Somayajulu {
1304*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
1305*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
1306*217ec208SDavid C Somayajulu 	u8 filter_idx, abs_ppfid, str[32], type_bitmap;
1307*217ec208SDavid C Somayajulu 	union ecore_llh_filter filter;
1308*217ec208SDavid C Somayajulu 	u32 high, low, ref_cnt;
1309*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
1310*217ec208SDavid C Somayajulu 
1311*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
1312*217ec208SDavid C Somayajulu 		return ECORE_AGAIN;
1313*217ec208SDavid C Somayajulu 
1314*217ec208SDavid C Somayajulu 	if (!OSAL_TEST_BIT(ECORE_MF_LLH_PROTO_CLSS, &p_dev->mf_bits))
1315*217ec208SDavid C Somayajulu 		goto out;
1316*217ec208SDavid C Somayajulu 
1317*217ec208SDavid C Somayajulu 	rc = ecore_llh_protocol_filter_stringify(p_dev, type,
1318*217ec208SDavid C Somayajulu 						 source_port_or_eth_type,
1319*217ec208SDavid C Somayajulu 						 dest_port, str, sizeof(str));
1320*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1321*217ec208SDavid C Somayajulu 		goto err;
1322*217ec208SDavid C Somayajulu 
1323*217ec208SDavid C Somayajulu 	OSAL_MEM_ZERO(&filter, sizeof(filter));
1324*217ec208SDavid C Somayajulu 	filter.protocol.type = type;
1325*217ec208SDavid C Somayajulu 	filter.protocol.source_port_or_eth_type = source_port_or_eth_type;
1326*217ec208SDavid C Somayajulu 	filter.protocol.dest_port = dest_port;
1327*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_add_filter(p_dev, ppfid,
1328*217ec208SDavid C Somayajulu 					 ECORE_LLH_FILTER_TYPE_PROTOCOL,
1329*217ec208SDavid C Somayajulu 					 &filter, &filter_idx, &ref_cnt);
1330*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1331*217ec208SDavid C Somayajulu 		goto err;
1332*217ec208SDavid C Somayajulu 
1333*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
1334*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1335*217ec208SDavid C Somayajulu 		goto err;
1336*217ec208SDavid C Somayajulu 
1337*217ec208SDavid C Somayajulu 	/* Configure the LLH only in case of a new the filter */
1338*217ec208SDavid C Somayajulu 	if (ref_cnt == 1) {
1339*217ec208SDavid C Somayajulu 		rc = ecore_llh_protocol_filter_to_hilo(p_dev, type,
1340*217ec208SDavid C Somayajulu 						       source_port_or_eth_type,
1341*217ec208SDavid C Somayajulu 						       dest_port, &high, &low);
1342*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1343*217ec208SDavid C Somayajulu 			goto err;
1344*217ec208SDavid C Somayajulu 
1345*217ec208SDavid C Somayajulu 		type_bitmap = 0x1 << type;
1346*217ec208SDavid C Somayajulu 		rc = ecore_llh_add_filter(p_hwfn, p_ptt, abs_ppfid, filter_idx,
1347*217ec208SDavid C Somayajulu 					  type_bitmap, high, low);
1348*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1349*217ec208SDavid C Somayajulu 			goto err;
1350*217ec208SDavid C Somayajulu 	}
1351*217ec208SDavid C Somayajulu 
1352*217ec208SDavid C Somayajulu 	DP_VERBOSE(p_dev, ECORE_MSG_SP,
1353*217ec208SDavid C Somayajulu 		   "LLH: Added protocol filter [%s] to ppfid %hhd [abs %hhd] at idx %hhd [ref_cnt %d]\n",
1354*217ec208SDavid C Somayajulu 		   str, ppfid, abs_ppfid, filter_idx, ref_cnt);
1355*217ec208SDavid C Somayajulu 
1356*217ec208SDavid C Somayajulu 	goto out;
1357*217ec208SDavid C Somayajulu 
1358*217ec208SDavid C Somayajulu err:
1359*217ec208SDavid C Somayajulu 	DP_NOTICE(p_hwfn, false,
1360*217ec208SDavid C Somayajulu 		  "LLH: Failed to add protocol filter [%s] to ppfid %hhd\n",
1361*217ec208SDavid C Somayajulu 		  str, ppfid);
1362*217ec208SDavid C Somayajulu out:
1363*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
1364*217ec208SDavid C Somayajulu 
1365*217ec208SDavid C Somayajulu 	return rc;
1366*217ec208SDavid C Somayajulu }
1367*217ec208SDavid C Somayajulu 
ecore_llh_remove_mac_filter(struct ecore_dev * p_dev,u8 ppfid,u8 mac_addr[ETH_ALEN])1368*217ec208SDavid C Somayajulu void ecore_llh_remove_mac_filter(struct ecore_dev *p_dev, u8 ppfid,
1369*217ec208SDavid C Somayajulu 				 u8 mac_addr[ETH_ALEN])
1370*217ec208SDavid C Somayajulu {
1371*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
1372*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
1373*217ec208SDavid C Somayajulu 	union ecore_llh_filter filter;
1374*217ec208SDavid C Somayajulu 	u8 filter_idx, abs_ppfid;
1375*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
1376*217ec208SDavid C Somayajulu 	u32 ref_cnt;
1377*217ec208SDavid C Somayajulu 
1378*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
1379*217ec208SDavid C Somayajulu 		return;
1380*217ec208SDavid C Somayajulu 
1381*217ec208SDavid C Somayajulu 	if (!OSAL_TEST_BIT(ECORE_MF_LLH_MAC_CLSS, &p_dev->mf_bits))
1382*217ec208SDavid C Somayajulu 		goto out;
1383*217ec208SDavid C Somayajulu 
1384*217ec208SDavid C Somayajulu 	OSAL_MEM_ZERO(&filter, sizeof(filter));
1385*217ec208SDavid C Somayajulu 	OSAL_MEMCPY(filter.mac.addr, mac_addr, ETH_ALEN);
1386*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_remove_filter(p_dev, ppfid, &filter, &filter_idx,
1387*217ec208SDavid C Somayajulu 					    &ref_cnt);
1388*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1389*217ec208SDavid C Somayajulu 		goto err;
1390*217ec208SDavid C Somayajulu 
1391*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
1392*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1393*217ec208SDavid C Somayajulu 		goto err;
1394*217ec208SDavid C Somayajulu 
1395*217ec208SDavid C Somayajulu 	/* Remove from the LLH in case the filter is not in use */
1396*217ec208SDavid C Somayajulu 	if (!ref_cnt) {
1397*217ec208SDavid C Somayajulu 		rc = ecore_llh_remove_filter(p_hwfn, p_ptt, abs_ppfid,
1398*217ec208SDavid C Somayajulu 					     filter_idx);
1399*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1400*217ec208SDavid C Somayajulu 			goto err;
1401*217ec208SDavid C Somayajulu 	}
1402*217ec208SDavid C Somayajulu 
1403*217ec208SDavid C Somayajulu 	DP_VERBOSE(p_dev, ECORE_MSG_SP,
1404*217ec208SDavid C Somayajulu 		   "LLH: Removed MAC filter [%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx] from ppfid %hhd [abs %hhd] at idx %hhd [ref_cnt %d]\n",
1405*217ec208SDavid C Somayajulu 		   mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
1406*217ec208SDavid C Somayajulu 		   mac_addr[4], mac_addr[5], ppfid, abs_ppfid, filter_idx,
1407*217ec208SDavid C Somayajulu 		   ref_cnt);
1408*217ec208SDavid C Somayajulu 
1409*217ec208SDavid C Somayajulu 	goto out;
1410*217ec208SDavid C Somayajulu 
1411*217ec208SDavid C Somayajulu err:
1412*217ec208SDavid C Somayajulu 	DP_NOTICE(p_dev, false,
1413*217ec208SDavid C Somayajulu 		  "LLH: Failed to remove MAC filter [%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx] from ppfid %hhd\n",
1414*217ec208SDavid C Somayajulu 		  mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
1415*217ec208SDavid C Somayajulu 		  mac_addr[4], mac_addr[5], ppfid);
1416*217ec208SDavid C Somayajulu out:
1417*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
1418*217ec208SDavid C Somayajulu }
1419*217ec208SDavid C Somayajulu 
ecore_llh_remove_protocol_filter(struct ecore_dev * p_dev,u8 ppfid,enum ecore_llh_prot_filter_type_t type,u16 source_port_or_eth_type,u16 dest_port)1420*217ec208SDavid C Somayajulu void ecore_llh_remove_protocol_filter(struct ecore_dev *p_dev, u8 ppfid,
1421*217ec208SDavid C Somayajulu 				      enum ecore_llh_prot_filter_type_t type,
1422*217ec208SDavid C Somayajulu 				      u16 source_port_or_eth_type,
1423*217ec208SDavid C Somayajulu 				      u16 dest_port)
1424*217ec208SDavid C Somayajulu {
1425*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
1426*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
1427*217ec208SDavid C Somayajulu 	u8 filter_idx, abs_ppfid, str[32];
1428*217ec208SDavid C Somayajulu 	union ecore_llh_filter filter;
1429*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
1430*217ec208SDavid C Somayajulu 	u32 ref_cnt;
1431*217ec208SDavid C Somayajulu 
1432*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
1433*217ec208SDavid C Somayajulu 		return;
1434*217ec208SDavid C Somayajulu 
1435*217ec208SDavid C Somayajulu 	if (!OSAL_TEST_BIT(ECORE_MF_LLH_PROTO_CLSS, &p_dev->mf_bits))
1436*217ec208SDavid C Somayajulu 		goto out;
1437*217ec208SDavid C Somayajulu 
1438*217ec208SDavid C Somayajulu 	rc = ecore_llh_protocol_filter_stringify(p_dev, type,
1439*217ec208SDavid C Somayajulu 						 source_port_or_eth_type,
1440*217ec208SDavid C Somayajulu 						 dest_port, str, sizeof(str));
1441*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1442*217ec208SDavid C Somayajulu 		goto err;
1443*217ec208SDavid C Somayajulu 
1444*217ec208SDavid C Somayajulu 	OSAL_MEM_ZERO(&filter, sizeof(filter));
1445*217ec208SDavid C Somayajulu 	filter.protocol.type = type;
1446*217ec208SDavid C Somayajulu 	filter.protocol.source_port_or_eth_type = source_port_or_eth_type;
1447*217ec208SDavid C Somayajulu 	filter.protocol.dest_port = dest_port;
1448*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_remove_filter(p_dev, ppfid, &filter, &filter_idx,
1449*217ec208SDavid C Somayajulu 					    &ref_cnt);
1450*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1451*217ec208SDavid C Somayajulu 		goto err;
1452*217ec208SDavid C Somayajulu 
1453*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
1454*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1455*217ec208SDavid C Somayajulu 		goto err;
1456*217ec208SDavid C Somayajulu 
1457*217ec208SDavid C Somayajulu 	/* Remove from the LLH in case the filter is not in use */
1458*217ec208SDavid C Somayajulu 	if (!ref_cnt) {
1459*217ec208SDavid C Somayajulu 		rc = ecore_llh_remove_filter(p_hwfn, p_ptt, abs_ppfid,
1460*217ec208SDavid C Somayajulu 					     filter_idx);
1461*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1462*217ec208SDavid C Somayajulu 			goto err;
1463*217ec208SDavid C Somayajulu 	}
1464*217ec208SDavid C Somayajulu 
1465*217ec208SDavid C Somayajulu 	DP_VERBOSE(p_dev, ECORE_MSG_SP,
1466*217ec208SDavid C Somayajulu 		   "LLH: Removed protocol filter [%s] from ppfid %hhd [abs %hhd] at idx %hhd [ref_cnt %d]\n",
1467*217ec208SDavid C Somayajulu 		   str, ppfid, abs_ppfid, filter_idx, ref_cnt);
1468*217ec208SDavid C Somayajulu 
1469*217ec208SDavid C Somayajulu 	goto out;
1470*217ec208SDavid C Somayajulu 
1471*217ec208SDavid C Somayajulu err:
1472*217ec208SDavid C Somayajulu 	DP_NOTICE(p_dev, false,
1473*217ec208SDavid C Somayajulu 		  "LLH: Failed to remove protocol filter [%s] from ppfid %hhd\n",
1474*217ec208SDavid C Somayajulu 		  str, ppfid);
1475*217ec208SDavid C Somayajulu out:
1476*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
1477*217ec208SDavid C Somayajulu }
1478*217ec208SDavid C Somayajulu 
ecore_llh_clear_ppfid_filters(struct ecore_dev * p_dev,u8 ppfid)1479*217ec208SDavid C Somayajulu void ecore_llh_clear_ppfid_filters(struct ecore_dev *p_dev, u8 ppfid)
1480*217ec208SDavid C Somayajulu {
1481*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
1482*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
1483*217ec208SDavid C Somayajulu 	u8 filter_idx, abs_ppfid;
1484*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
1485*217ec208SDavid C Somayajulu 
1486*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
1487*217ec208SDavid C Somayajulu 		return;
1488*217ec208SDavid C Somayajulu 
1489*217ec208SDavid C Somayajulu 	if (!OSAL_TEST_BIT(ECORE_MF_LLH_PROTO_CLSS, &p_dev->mf_bits) &&
1490*217ec208SDavid C Somayajulu 	    !OSAL_TEST_BIT(ECORE_MF_LLH_MAC_CLSS, &p_dev->mf_bits))
1491*217ec208SDavid C Somayajulu 		goto out;
1492*217ec208SDavid C Somayajulu 
1493*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
1494*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1495*217ec208SDavid C Somayajulu 		goto out;
1496*217ec208SDavid C Somayajulu 
1497*217ec208SDavid C Somayajulu 	rc = ecore_llh_shadow_remove_all_filters(p_dev, ppfid);
1498*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1499*217ec208SDavid C Somayajulu 		goto out;
1500*217ec208SDavid C Somayajulu 
1501*217ec208SDavid C Somayajulu 	for (filter_idx = 0; filter_idx < NIG_REG_LLH_FUNC_FILTER_EN_SIZE;
1502*217ec208SDavid C Somayajulu 	     filter_idx++) {
1503*217ec208SDavid C Somayajulu 		if (ECORE_IS_E4(p_dev))
1504*217ec208SDavid C Somayajulu 			rc = ecore_llh_remove_filter_e4(p_hwfn, p_ptt,
1505*217ec208SDavid C Somayajulu 							abs_ppfid, filter_idx);
1506*217ec208SDavid C Somayajulu 		else /* E5 */
1507*217ec208SDavid C Somayajulu 			rc = ecore_llh_remove_filter_e5(p_hwfn, p_ptt,
1508*217ec208SDavid C Somayajulu 							abs_ppfid, filter_idx);
1509*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1510*217ec208SDavid C Somayajulu 			goto out;
1511*217ec208SDavid C Somayajulu 	}
1512*217ec208SDavid C Somayajulu out:
1513*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
1514*217ec208SDavid C Somayajulu }
1515*217ec208SDavid C Somayajulu 
ecore_llh_clear_all_filters(struct ecore_dev * p_dev)1516*217ec208SDavid C Somayajulu void ecore_llh_clear_all_filters(struct ecore_dev *p_dev)
1517*217ec208SDavid C Somayajulu {
1518*217ec208SDavid C Somayajulu 	u8 ppfid;
1519*217ec208SDavid C Somayajulu 
1520*217ec208SDavid C Somayajulu 	if (!OSAL_TEST_BIT(ECORE_MF_LLH_PROTO_CLSS, &p_dev->mf_bits) &&
1521*217ec208SDavid C Somayajulu 	    !OSAL_TEST_BIT(ECORE_MF_LLH_MAC_CLSS, &p_dev->mf_bits))
1522*217ec208SDavid C Somayajulu 		return;
1523*217ec208SDavid C Somayajulu 
1524*217ec208SDavid C Somayajulu 	for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++)
1525*217ec208SDavid C Somayajulu 		ecore_llh_clear_ppfid_filters(p_dev, ppfid);
1526*217ec208SDavid C Somayajulu }
1527*217ec208SDavid C Somayajulu 
ecore_all_ppfids_wr(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 addr,u32 val)1528*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_all_ppfids_wr(struct ecore_hwfn *p_hwfn,
1529*217ec208SDavid C Somayajulu 					 struct ecore_ptt *p_ptt, u32 addr,
1530*217ec208SDavid C Somayajulu 					 u32 val)
1531*217ec208SDavid C Somayajulu {
1532*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
1533*217ec208SDavid C Somayajulu 	u8 ppfid, abs_ppfid;
1534*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
1535*217ec208SDavid C Somayajulu 
1536*217ec208SDavid C Somayajulu 	for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++) {
1537*217ec208SDavid C Somayajulu 		rc = ecore_abs_ppfid(p_dev, ppfid, &abs_ppfid);
1538*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1539*217ec208SDavid C Somayajulu 			return rc;
1540*217ec208SDavid C Somayajulu 
1541*217ec208SDavid C Somayajulu 		ecore_ppfid_wr(p_hwfn, p_ptt, abs_ppfid, addr, val);
1542*217ec208SDavid C Somayajulu 	}
1543*217ec208SDavid C Somayajulu 
1544*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1545*217ec208SDavid C Somayajulu }
1546*217ec208SDavid C Somayajulu 
1547*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_dump_ppfid_e4(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 ppfid)1548*217ec208SDavid C Somayajulu ecore_llh_dump_ppfid_e4(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1549*217ec208SDavid C Somayajulu 			u8 ppfid)
1550*217ec208SDavid C Somayajulu {
1551*217ec208SDavid C Somayajulu 	struct ecore_llh_filter_e4_details filter_details;
1552*217ec208SDavid C Somayajulu 	u8 abs_ppfid, filter_idx;
1553*217ec208SDavid C Somayajulu 	u32 addr;
1554*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
1555*217ec208SDavid C Somayajulu 
1556*217ec208SDavid C Somayajulu 	rc = ecore_abs_ppfid(p_hwfn->p_dev, ppfid, &abs_ppfid);
1557*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
1558*217ec208SDavid C Somayajulu 		return rc;
1559*217ec208SDavid C Somayajulu 
1560*217ec208SDavid C Somayajulu 	addr = NIG_REG_PPF_TO_ENGINE_SEL + abs_ppfid * 0x4;
1561*217ec208SDavid C Somayajulu 	DP_NOTICE(p_hwfn, false,
1562*217ec208SDavid C Somayajulu 		  "[rel_pf_id %hhd, ppfid={rel %hhd, abs %hhd}, engine_sel 0x%x]\n",
1563*217ec208SDavid C Somayajulu 		  p_hwfn->rel_pf_id, ppfid, abs_ppfid,
1564*217ec208SDavid C Somayajulu 		  ecore_rd(p_hwfn, p_ptt, addr));
1565*217ec208SDavid C Somayajulu 
1566*217ec208SDavid C Somayajulu 	for (filter_idx = 0; filter_idx < NIG_REG_LLH_FUNC_FILTER_EN_SIZE;
1567*217ec208SDavid C Somayajulu 	     filter_idx++) {
1568*217ec208SDavid C Somayajulu 		OSAL_MEMSET(&filter_details, 0, sizeof(filter_details));
1569*217ec208SDavid C Somayajulu 		rc =  ecore_llh_access_filter_e4(p_hwfn, p_ptt, abs_ppfid,
1570*217ec208SDavid C Somayajulu 						 filter_idx, &filter_details,
1571*217ec208SDavid C Somayajulu 						 false /* read access */);
1572*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1573*217ec208SDavid C Somayajulu 			return rc;
1574*217ec208SDavid C Somayajulu 
1575*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
1576*217ec208SDavid C Somayajulu 			  "filter %2hhd: enable %d, value 0x%016llx, mode %d, protocol_type 0x%x, hdr_sel 0x%x\n",
1577*217ec208SDavid C Somayajulu 			  filter_idx, filter_details.enable,
1578*217ec208SDavid C Somayajulu 			  (unsigned long long)filter_details.value, filter_details.mode,
1579*217ec208SDavid C Somayajulu 			  filter_details.protocol_type, filter_details.hdr_sel);
1580*217ec208SDavid C Somayajulu 	}
1581*217ec208SDavid C Somayajulu 
1582*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1583*217ec208SDavid C Somayajulu }
1584*217ec208SDavid C Somayajulu 
1585*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_llh_dump_ppfid_e5(struct ecore_hwfn OSAL_UNUSED * p_hwfn,struct ecore_ptt OSAL_UNUSED * p_ptt,u8 OSAL_UNUSED ppfid)1586*217ec208SDavid C Somayajulu ecore_llh_dump_ppfid_e5(struct ecore_hwfn OSAL_UNUSED *p_hwfn,
1587*217ec208SDavid C Somayajulu 			struct ecore_ptt OSAL_UNUSED *p_ptt,
1588*217ec208SDavid C Somayajulu 			u8 OSAL_UNUSED ppfid)
1589*217ec208SDavid C Somayajulu {
1590*217ec208SDavid C Somayajulu 	ECORE_E5_MISSING_CODE;
1591*217ec208SDavid C Somayajulu 
1592*217ec208SDavid C Somayajulu 	return ECORE_NOTIMPL;
1593*217ec208SDavid C Somayajulu }
1594*217ec208SDavid C Somayajulu 
ecore_llh_dump_ppfid(struct ecore_dev * p_dev,u8 ppfid)1595*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_llh_dump_ppfid(struct ecore_dev *p_dev, u8 ppfid)
1596*217ec208SDavid C Somayajulu {
1597*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
1598*217ec208SDavid C Somayajulu 	struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
1599*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
1600*217ec208SDavid C Somayajulu 
1601*217ec208SDavid C Somayajulu 	if (p_ptt == OSAL_NULL)
1602*217ec208SDavid C Somayajulu 		return ECORE_AGAIN;
1603*217ec208SDavid C Somayajulu 
1604*217ec208SDavid C Somayajulu 	if (ECORE_IS_E4(p_dev))
1605*217ec208SDavid C Somayajulu 		rc = ecore_llh_dump_ppfid_e4(p_hwfn, p_ptt, ppfid);
1606*217ec208SDavid C Somayajulu 	else /* E5 */
1607*217ec208SDavid C Somayajulu 		rc = ecore_llh_dump_ppfid_e5(p_hwfn, p_ptt, ppfid);
1608*217ec208SDavid C Somayajulu 
1609*217ec208SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
1610*217ec208SDavid C Somayajulu 
1611*217ec208SDavid C Somayajulu 	return rc;
1612*217ec208SDavid C Somayajulu }
1613*217ec208SDavid C Somayajulu 
ecore_llh_dump_all(struct ecore_dev * p_dev)1614*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_llh_dump_all(struct ecore_dev *p_dev)
1615*217ec208SDavid C Somayajulu {
1616*217ec208SDavid C Somayajulu 	u8 ppfid;
1617*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
1618*217ec208SDavid C Somayajulu 
1619*217ec208SDavid C Somayajulu 	for (ppfid = 0; ppfid < p_dev->p_llh_info->num_ppfid; ppfid++) {
1620*217ec208SDavid C Somayajulu 		rc = ecore_llh_dump_ppfid(p_dev, ppfid);
1621*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
1622*217ec208SDavid C Somayajulu 			return rc;
1623*217ec208SDavid C Somayajulu 	}
1624*217ec208SDavid C Somayajulu 
1625*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1626*217ec208SDavid C Somayajulu }
1627*217ec208SDavid C Somayajulu 
1628*217ec208SDavid C Somayajulu /******************************* NIG LLH - End ********************************/
1629*217ec208SDavid C Somayajulu 
163011e25f0dSDavid C Somayajulu /* Configurable */
163111e25f0dSDavid C Somayajulu #define ECORE_MIN_DPIS		(4)  /* The minimal number of DPIs required to
163211e25f0dSDavid C Somayajulu 				      * load the driver. The number was
163311e25f0dSDavid C Somayajulu 				      * arbitrarily set.
163411e25f0dSDavid C Somayajulu 				      */
163511e25f0dSDavid C Somayajulu 
163611e25f0dSDavid C Somayajulu /* Derived */
16379efd0ba7SDavid C Somayajulu #define ECORE_MIN_PWM_REGION	(ECORE_WID_SIZE * ECORE_MIN_DPIS)
163811e25f0dSDavid C Somayajulu 
ecore_hw_bar_size(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum BAR_ID bar_id)16399efd0ba7SDavid C Somayajulu static u32 ecore_hw_bar_size(struct ecore_hwfn *p_hwfn,
16409efd0ba7SDavid C Somayajulu 			     struct ecore_ptt *p_ptt,
16419efd0ba7SDavid C Somayajulu 			     enum BAR_ID bar_id)
164211e25f0dSDavid C Somayajulu {
164311e25f0dSDavid C Somayajulu 	u32 bar_reg = (bar_id == BAR_ID_0 ?
164411e25f0dSDavid C Somayajulu 		       PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
164511e25f0dSDavid C Somayajulu 	u32 val;
164611e25f0dSDavid C Somayajulu 
1647*217ec208SDavid C Somayajulu 	if (IS_VF(p_hwfn->p_dev))
1648*217ec208SDavid C Somayajulu 		return ecore_vf_hw_bar_size(p_hwfn, bar_id);
164911e25f0dSDavid C Somayajulu 
16509efd0ba7SDavid C Somayajulu 	val = ecore_rd(p_hwfn, p_ptt, bar_reg);
165111e25f0dSDavid C Somayajulu 	if (val)
165211e25f0dSDavid C Somayajulu 		return 1 << (val + 15);
165311e25f0dSDavid C Somayajulu 
165411e25f0dSDavid C Somayajulu 	/* The above registers were updated in the past only in CMT mode. Since
165511e25f0dSDavid C Somayajulu 	 * they were found to be useful MFW started updating them from 8.7.7.0.
165611e25f0dSDavid C Somayajulu 	 * In older MFW versions they are set to 0 which means disabled.
165711e25f0dSDavid C Somayajulu 	 */
1658*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_hwfn->p_dev)) {
16599efd0ba7SDavid C Somayajulu 		DP_INFO(p_hwfn,
166011e25f0dSDavid C Somayajulu 			"BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
166111e25f0dSDavid C Somayajulu 		return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
166211e25f0dSDavid C Somayajulu 	} else {
16639efd0ba7SDavid C Somayajulu 		DP_INFO(p_hwfn,
166411e25f0dSDavid C Somayajulu 			"BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
166511e25f0dSDavid C Somayajulu 		return 512 * 1024;
166611e25f0dSDavid C Somayajulu 	}
166711e25f0dSDavid C Somayajulu }
166811e25f0dSDavid C Somayajulu 
ecore_init_dp(struct ecore_dev * p_dev,u32 dp_module,u8 dp_level,void * dp_ctx)166911e25f0dSDavid C Somayajulu void ecore_init_dp(struct ecore_dev	*p_dev,
167011e25f0dSDavid C Somayajulu 		   u32			dp_module,
167111e25f0dSDavid C Somayajulu 		   u8			dp_level,
167211e25f0dSDavid C Somayajulu 		   void		 *dp_ctx)
167311e25f0dSDavid C Somayajulu {
167411e25f0dSDavid C Somayajulu 	u32 i;
167511e25f0dSDavid C Somayajulu 
167611e25f0dSDavid C Somayajulu 	p_dev->dp_level = dp_level;
167711e25f0dSDavid C Somayajulu 	p_dev->dp_module = dp_module;
167811e25f0dSDavid C Somayajulu 	p_dev->dp_ctx = dp_ctx;
167911e25f0dSDavid C Somayajulu 	for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
168011e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
168111e25f0dSDavid C Somayajulu 
168211e25f0dSDavid C Somayajulu 		p_hwfn->dp_level = dp_level;
168311e25f0dSDavid C Somayajulu 		p_hwfn->dp_module = dp_module;
168411e25f0dSDavid C Somayajulu 		p_hwfn->dp_ctx = dp_ctx;
168511e25f0dSDavid C Somayajulu 	}
168611e25f0dSDavid C Somayajulu }
168711e25f0dSDavid C Somayajulu 
ecore_init_struct(struct ecore_dev * p_dev)1688*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_init_struct(struct ecore_dev *p_dev)
168911e25f0dSDavid C Somayajulu {
169011e25f0dSDavid C Somayajulu 	u8 i;
169111e25f0dSDavid C Somayajulu 
169211e25f0dSDavid C Somayajulu 	for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
169311e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
169411e25f0dSDavid C Somayajulu 
169511e25f0dSDavid C Somayajulu 		p_hwfn->p_dev = p_dev;
169611e25f0dSDavid C Somayajulu 		p_hwfn->my_id = i;
169711e25f0dSDavid C Somayajulu 		p_hwfn->b_active = false;
169811e25f0dSDavid C Somayajulu 
16999efd0ba7SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
1700*217ec208SDavid C Somayajulu 		if (OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_hwfn->dmae_info.lock))
1701*217ec208SDavid C Somayajulu 			goto handle_err;
17029efd0ba7SDavid C Somayajulu #endif
1703*217ec208SDavid C Somayajulu 		OSAL_SPIN_LOCK_INIT(&p_hwfn->dmae_info.lock);
170411e25f0dSDavid C Somayajulu 	}
170511e25f0dSDavid C Somayajulu 
170611e25f0dSDavid C Somayajulu 	/* hwfn 0 is always active */
170711e25f0dSDavid C Somayajulu 	p_dev->hwfns[0].b_active = true;
170811e25f0dSDavid C Somayajulu 
170911e25f0dSDavid C Somayajulu 	/* set the default cache alignment to 128 (may be overridden later) */
171011e25f0dSDavid C Somayajulu 	p_dev->cache_shift = 7;
1711*217ec208SDavid C Somayajulu 
1712*217ec208SDavid C Somayajulu 	p_dev->ilt_page_size = ECORE_DEFAULT_ILT_PAGE_SIZE;
1713*217ec208SDavid C Somayajulu 
1714*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
1715*217ec208SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
1716*217ec208SDavid C Somayajulu handle_err:
1717*217ec208SDavid C Somayajulu 	while (--i) {
1718*217ec208SDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = OSAL_NULL;
1719*217ec208SDavid C Somayajulu 
1720*217ec208SDavid C Somayajulu 		p_hwfn = &p_dev->hwfns[i];
1721*217ec208SDavid C Somayajulu 		OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->dmae_info.lock);
1722*217ec208SDavid C Somayajulu 	}
1723*217ec208SDavid C Somayajulu 	return ECORE_NOMEM;
1724*217ec208SDavid C Somayajulu #endif
172511e25f0dSDavid C Somayajulu }
172611e25f0dSDavid C Somayajulu 
ecore_qm_info_free(struct ecore_hwfn * p_hwfn)172711e25f0dSDavid C Somayajulu static void ecore_qm_info_free(struct ecore_hwfn *p_hwfn)
172811e25f0dSDavid C Somayajulu {
172911e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
173011e25f0dSDavid C Somayajulu 
173111e25f0dSDavid C Somayajulu 	OSAL_FREE(p_hwfn->p_dev, qm_info->qm_pq_params);
173211e25f0dSDavid C Somayajulu 	qm_info->qm_pq_params = OSAL_NULL;
173311e25f0dSDavid C Somayajulu 	OSAL_FREE(p_hwfn->p_dev, qm_info->qm_vport_params);
173411e25f0dSDavid C Somayajulu 	qm_info->qm_vport_params = OSAL_NULL;
173511e25f0dSDavid C Somayajulu 	OSAL_FREE(p_hwfn->p_dev, qm_info->qm_port_params);
173611e25f0dSDavid C Somayajulu 	qm_info->qm_port_params = OSAL_NULL;
173711e25f0dSDavid C Somayajulu 	OSAL_FREE(p_hwfn->p_dev, qm_info->wfq_data);
173811e25f0dSDavid C Somayajulu 	qm_info->wfq_data = OSAL_NULL;
173911e25f0dSDavid C Somayajulu }
174011e25f0dSDavid C Somayajulu 
ecore_resc_free(struct ecore_dev * p_dev)174111e25f0dSDavid C Somayajulu void ecore_resc_free(struct ecore_dev *p_dev)
174211e25f0dSDavid C Somayajulu {
174311e25f0dSDavid C Somayajulu 	int i;
174411e25f0dSDavid C Somayajulu 
174511e25f0dSDavid C Somayajulu 	if (IS_VF(p_dev)) {
174611e25f0dSDavid C Somayajulu 		for_each_hwfn(p_dev, i)
174711e25f0dSDavid C Somayajulu 			ecore_l2_free(&p_dev->hwfns[i]);
174811e25f0dSDavid C Somayajulu 		return;
174911e25f0dSDavid C Somayajulu 	}
175011e25f0dSDavid C Somayajulu 
175111e25f0dSDavid C Somayajulu 	OSAL_FREE(p_dev, p_dev->fw_data);
175211e25f0dSDavid C Somayajulu 	p_dev->fw_data = OSAL_NULL;
175311e25f0dSDavid C Somayajulu 
175411e25f0dSDavid C Somayajulu 	OSAL_FREE(p_dev, p_dev->reset_stats);
175511e25f0dSDavid C Somayajulu 	p_dev->reset_stats = OSAL_NULL;
175611e25f0dSDavid C Somayajulu 
1757*217ec208SDavid C Somayajulu 	ecore_llh_free(p_dev);
1758*217ec208SDavid C Somayajulu 
175911e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
176011e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
176111e25f0dSDavid C Somayajulu 
176211e25f0dSDavid C Somayajulu 		ecore_cxt_mngr_free(p_hwfn);
176311e25f0dSDavid C Somayajulu 		ecore_qm_info_free(p_hwfn);
176411e25f0dSDavid C Somayajulu 		ecore_spq_free(p_hwfn);
176511e25f0dSDavid C Somayajulu 		ecore_eq_free(p_hwfn);
176611e25f0dSDavid C Somayajulu 		ecore_consq_free(p_hwfn);
176711e25f0dSDavid C Somayajulu 		ecore_int_free(p_hwfn);
176811e25f0dSDavid C Somayajulu #ifdef CONFIG_ECORE_LL2
176911e25f0dSDavid C Somayajulu 		ecore_ll2_free(p_hwfn);
177011e25f0dSDavid C Somayajulu #endif
177111e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE)
177211e25f0dSDavid C Somayajulu 			ecore_fcoe_free(p_hwfn);
1773*217ec208SDavid C Somayajulu 
177411e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
177511e25f0dSDavid C Somayajulu 			ecore_iscsi_free(p_hwfn);
177611e25f0dSDavid C Somayajulu 			ecore_ooo_free(p_hwfn);
177711e25f0dSDavid C Somayajulu 		}
1778*217ec208SDavid C Somayajulu 
1779*217ec208SDavid C Somayajulu #ifdef CONFIG_ECORE_ROCE
1780*217ec208SDavid C Somayajulu 		if (ECORE_IS_RDMA_PERSONALITY(p_hwfn))
1781*217ec208SDavid C Somayajulu 			ecore_rdma_info_free(p_hwfn);
178211e25f0dSDavid C Somayajulu #endif
178311e25f0dSDavid C Somayajulu 		ecore_iov_free(p_hwfn);
178411e25f0dSDavid C Somayajulu 		ecore_l2_free(p_hwfn);
178511e25f0dSDavid C Somayajulu 		ecore_dmae_info_free(p_hwfn);
178611e25f0dSDavid C Somayajulu 		ecore_dcbx_info_free(p_hwfn);
178711e25f0dSDavid C Somayajulu 		/* @@@TBD Flush work-queue ?*/
17889efd0ba7SDavid C Somayajulu 
17899efd0ba7SDavid C Somayajulu 		/* destroy doorbell recovery mechanism */
17909efd0ba7SDavid C Somayajulu 		ecore_db_recovery_teardown(p_hwfn);
179111e25f0dSDavid C Somayajulu 	}
179211e25f0dSDavid C Somayajulu }
179311e25f0dSDavid C Somayajulu 
179411e25f0dSDavid C Somayajulu /******************** QM initialization *******************/
179511e25f0dSDavid C Somayajulu /* bitmaps for indicating active traffic classes. Special case for Arrowhead 4 port */
179611e25f0dSDavid C Somayajulu #define ACTIVE_TCS_BMAP 0x9f /* 0..3 actualy used, 4 serves OOO, 7 serves high priority stuff (e.g. DCQCN) */
179711e25f0dSDavid C Somayajulu #define ACTIVE_TCS_BMAP_4PORT_K2 0xf /* 0..3 actually used, OOO and high priority stuff all use 3 */
179811e25f0dSDavid C Somayajulu 
179911e25f0dSDavid C Somayajulu /* determines the physical queue flags for a given PF. */
ecore_get_pq_flags(struct ecore_hwfn * p_hwfn)180011e25f0dSDavid C Somayajulu static u32 ecore_get_pq_flags(struct ecore_hwfn *p_hwfn)
180111e25f0dSDavid C Somayajulu {
180211e25f0dSDavid C Somayajulu 	u32 flags;
180311e25f0dSDavid C Somayajulu 
180411e25f0dSDavid C Somayajulu 	/* common flags */
180511e25f0dSDavid C Somayajulu 	flags = PQ_FLAGS_LB;
180611e25f0dSDavid C Somayajulu 
180711e25f0dSDavid C Somayajulu 	/* feature flags */
180811e25f0dSDavid C Somayajulu 	if (IS_ECORE_SRIOV(p_hwfn->p_dev))
180911e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_VFS;
181011e25f0dSDavid C Somayajulu 	if (IS_ECORE_DCQCN(p_hwfn))
181111e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_RLS;
181211e25f0dSDavid C Somayajulu 
181311e25f0dSDavid C Somayajulu 	/* protocol flags */
181411e25f0dSDavid C Somayajulu 	switch (p_hwfn->hw_info.personality) {
181511e25f0dSDavid C Somayajulu 	case ECORE_PCI_ETH:
181611e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_MCOS;
181711e25f0dSDavid C Somayajulu 		break;
181811e25f0dSDavid C Somayajulu 	case ECORE_PCI_FCOE:
181911e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_OFLD;
182011e25f0dSDavid C Somayajulu 		break;
182111e25f0dSDavid C Somayajulu 	case ECORE_PCI_ISCSI:
182211e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
182311e25f0dSDavid C Somayajulu 		break;
182411e25f0dSDavid C Somayajulu 	case ECORE_PCI_ETH_ROCE:
182511e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD | PQ_FLAGS_LLT;
182611e25f0dSDavid C Somayajulu 		break;
182711e25f0dSDavid C Somayajulu 	case ECORE_PCI_ETH_IWARP:
182811e25f0dSDavid C Somayajulu 		flags |= PQ_FLAGS_MCOS | PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
182911e25f0dSDavid C Somayajulu 		break;
183011e25f0dSDavid C Somayajulu 	default:
183111e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "unknown personality %d\n", p_hwfn->hw_info.personality);
183211e25f0dSDavid C Somayajulu 		return 0;
183311e25f0dSDavid C Somayajulu 	}
183411e25f0dSDavid C Somayajulu 
183511e25f0dSDavid C Somayajulu 	return flags;
183611e25f0dSDavid C Somayajulu }
183711e25f0dSDavid C Somayajulu 
183811e25f0dSDavid C Somayajulu /* Getters for resource amounts necessary for qm initialization */
ecore_init_qm_get_num_tcs(struct ecore_hwfn * p_hwfn)183911e25f0dSDavid C Somayajulu u8 ecore_init_qm_get_num_tcs(struct ecore_hwfn *p_hwfn)
184011e25f0dSDavid C Somayajulu {
184111e25f0dSDavid C Somayajulu 	return p_hwfn->hw_info.num_hw_tc;
184211e25f0dSDavid C Somayajulu }
184311e25f0dSDavid C Somayajulu 
ecore_init_qm_get_num_vfs(struct ecore_hwfn * p_hwfn)184411e25f0dSDavid C Somayajulu u16 ecore_init_qm_get_num_vfs(struct ecore_hwfn *p_hwfn)
184511e25f0dSDavid C Somayajulu {
184611e25f0dSDavid C Somayajulu 	return IS_ECORE_SRIOV(p_hwfn->p_dev) ? p_hwfn->p_dev->p_iov_info->total_vfs : 0;
184711e25f0dSDavid C Somayajulu }
184811e25f0dSDavid C Somayajulu 
184911e25f0dSDavid C Somayajulu #define NUM_DEFAULT_RLS 1
185011e25f0dSDavid C Somayajulu 
ecore_init_qm_get_num_pf_rls(struct ecore_hwfn * p_hwfn)185111e25f0dSDavid C Somayajulu u16 ecore_init_qm_get_num_pf_rls(struct ecore_hwfn *p_hwfn)
185211e25f0dSDavid C Somayajulu {
185311e25f0dSDavid C Somayajulu 	u16 num_pf_rls, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
185411e25f0dSDavid C Somayajulu 
185511e25f0dSDavid C Somayajulu 	/* num RLs can't exceed resource amount of rls or vports or the dcqcn qps */
185611e25f0dSDavid C Somayajulu 	num_pf_rls = (u16)OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_RL),
185711e25f0dSDavid C Somayajulu 				     (u16)OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_VPORT),
185811e25f0dSDavid C Somayajulu 						     ROCE_DCQCN_RP_MAX_QPS));
185911e25f0dSDavid C Somayajulu 
186011e25f0dSDavid C Somayajulu 	/* make sure after we reserve the default and VF rls we'll have something left */
186111e25f0dSDavid C Somayajulu 	if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS) {
186211e25f0dSDavid C Somayajulu 		if (IS_ECORE_DCQCN(p_hwfn))
186311e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "no rate limiters left for PF rate limiting [num_pf_rls %d num_vfs %d]\n", num_pf_rls, num_vfs);
186411e25f0dSDavid C Somayajulu 		return 0;
186511e25f0dSDavid C Somayajulu 	}
186611e25f0dSDavid C Somayajulu 
186711e25f0dSDavid C Somayajulu 	/* subtract rls necessary for VFs and one default one for the PF */
186811e25f0dSDavid C Somayajulu 	num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
186911e25f0dSDavid C Somayajulu 
187011e25f0dSDavid C Somayajulu 	return num_pf_rls;
187111e25f0dSDavid C Somayajulu }
187211e25f0dSDavid C Somayajulu 
ecore_init_qm_get_num_vports(struct ecore_hwfn * p_hwfn)187311e25f0dSDavid C Somayajulu u16 ecore_init_qm_get_num_vports(struct ecore_hwfn *p_hwfn)
187411e25f0dSDavid C Somayajulu {
187511e25f0dSDavid C Somayajulu 	u32 pq_flags = ecore_get_pq_flags(p_hwfn);
187611e25f0dSDavid C Somayajulu 
187711e25f0dSDavid C Somayajulu 	/* all pqs share the same vport (hence the 1 below), except for vfs and pf_rl pqs */
187811e25f0dSDavid C Somayajulu 	return (!!(PQ_FLAGS_RLS & pq_flags)) * ecore_init_qm_get_num_pf_rls(p_hwfn) +
187911e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_VFS & pq_flags)) * ecore_init_qm_get_num_vfs(p_hwfn) + 1;
188011e25f0dSDavid C Somayajulu }
188111e25f0dSDavid C Somayajulu 
188211e25f0dSDavid C Somayajulu /* calc amount of PQs according to the requested flags */
ecore_init_qm_get_num_pqs(struct ecore_hwfn * p_hwfn)188311e25f0dSDavid C Somayajulu u16 ecore_init_qm_get_num_pqs(struct ecore_hwfn *p_hwfn)
188411e25f0dSDavid C Somayajulu {
188511e25f0dSDavid C Somayajulu 	u32 pq_flags = ecore_get_pq_flags(p_hwfn);
188611e25f0dSDavid C Somayajulu 
188711e25f0dSDavid C Somayajulu 	return (!!(PQ_FLAGS_RLS & pq_flags)) * ecore_init_qm_get_num_pf_rls(p_hwfn) +
188811e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_MCOS & pq_flags)) * ecore_init_qm_get_num_tcs(p_hwfn) +
188911e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_LB & pq_flags)) +
189011e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_OOO & pq_flags)) +
189111e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_ACK & pq_flags)) +
189211e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_OFLD & pq_flags)) +
189311e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_LLT & pq_flags)) +
189411e25f0dSDavid C Somayajulu 	       (!!(PQ_FLAGS_VFS & pq_flags)) * ecore_init_qm_get_num_vfs(p_hwfn);
189511e25f0dSDavid C Somayajulu }
189611e25f0dSDavid C Somayajulu 
189711e25f0dSDavid C Somayajulu /* initialize the top level QM params */
ecore_init_qm_params(struct ecore_hwfn * p_hwfn)189811e25f0dSDavid C Somayajulu static void ecore_init_qm_params(struct ecore_hwfn *p_hwfn)
189911e25f0dSDavid C Somayajulu {
190011e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
190111e25f0dSDavid C Somayajulu 	bool four_port;
190211e25f0dSDavid C Somayajulu 
190311e25f0dSDavid C Somayajulu 	/* pq and vport bases for this PF */
190411e25f0dSDavid C Somayajulu 	qm_info->start_pq = (u16)RESC_START(p_hwfn, ECORE_PQ);
190511e25f0dSDavid C Somayajulu 	qm_info->start_vport = (u8)RESC_START(p_hwfn, ECORE_VPORT);
190611e25f0dSDavid C Somayajulu 
190711e25f0dSDavid C Somayajulu 	/* rate limiting and weighted fair queueing are always enabled */
190811e25f0dSDavid C Somayajulu 	qm_info->vport_rl_en = 1;
190911e25f0dSDavid C Somayajulu 	qm_info->vport_wfq_en = 1;
191011e25f0dSDavid C Somayajulu 
191111e25f0dSDavid C Somayajulu 	/* TC config is different for AH 4 port */
19129efd0ba7SDavid C Somayajulu 	four_port = p_hwfn->p_dev->num_ports_in_engine == MAX_NUM_PORTS_K2;
191311e25f0dSDavid C Somayajulu 
191411e25f0dSDavid C Somayajulu 	/* in AH 4 port we have fewer TCs per port */
191511e25f0dSDavid C Somayajulu 	qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 : NUM_OF_PHYS_TCS;
191611e25f0dSDavid C Somayajulu 
191711e25f0dSDavid C Somayajulu 	/* unless MFW indicated otherwise, ooo_tc should be 3 for AH 4 port and 4 otherwise */
191811e25f0dSDavid C Somayajulu 	if (!qm_info->ooo_tc)
191911e25f0dSDavid C Somayajulu 		qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC : DCBX_TCP_OOO_TC;
192011e25f0dSDavid C Somayajulu }
192111e25f0dSDavid C Somayajulu 
192211e25f0dSDavid C Somayajulu /* initialize qm vport params */
ecore_init_qm_vport_params(struct ecore_hwfn * p_hwfn)192311e25f0dSDavid C Somayajulu static void ecore_init_qm_vport_params(struct ecore_hwfn *p_hwfn)
192411e25f0dSDavid C Somayajulu {
192511e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
192611e25f0dSDavid C Somayajulu 	u8 i;
192711e25f0dSDavid C Somayajulu 
192811e25f0dSDavid C Somayajulu 	/* all vports participate in weighted fair queueing */
192911e25f0dSDavid C Somayajulu 	for (i = 0; i < ecore_init_qm_get_num_vports(p_hwfn); i++)
193011e25f0dSDavid C Somayajulu 		qm_info->qm_vport_params[i].vport_wfq = 1;
193111e25f0dSDavid C Somayajulu }
193211e25f0dSDavid C Somayajulu 
193311e25f0dSDavid C Somayajulu /* initialize qm port params */
ecore_init_qm_port_params(struct ecore_hwfn * p_hwfn)193411e25f0dSDavid C Somayajulu static void ecore_init_qm_port_params(struct ecore_hwfn *p_hwfn)
193511e25f0dSDavid C Somayajulu {
193611e25f0dSDavid C Somayajulu 	/* Initialize qm port parameters */
19379efd0ba7SDavid C Somayajulu 	u8 i, active_phys_tcs, num_ports = p_hwfn->p_dev->num_ports_in_engine;
193811e25f0dSDavid C Somayajulu 
193911e25f0dSDavid C Somayajulu 	/* indicate how ooo and high pri traffic is dealt with */
194011e25f0dSDavid C Somayajulu 	active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
194111e25f0dSDavid C Somayajulu 		ACTIVE_TCS_BMAP_4PORT_K2 : ACTIVE_TCS_BMAP;
194211e25f0dSDavid C Somayajulu 
194311e25f0dSDavid C Somayajulu 	for (i = 0; i < num_ports; i++) {
194411e25f0dSDavid C Somayajulu 		struct init_qm_port_params *p_qm_port =
194511e25f0dSDavid C Somayajulu 			&p_hwfn->qm_info.qm_port_params[i];
194611e25f0dSDavid C Somayajulu 
194711e25f0dSDavid C Somayajulu 		p_qm_port->active = 1;
194811e25f0dSDavid C Somayajulu 		p_qm_port->active_phys_tcs = active_phys_tcs;
19499efd0ba7SDavid C Somayajulu 		p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES_E4 / num_ports;
195011e25f0dSDavid C Somayajulu 		p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
195111e25f0dSDavid C Somayajulu 	}
195211e25f0dSDavid C Somayajulu }
195311e25f0dSDavid C Somayajulu 
195411e25f0dSDavid C Somayajulu /* Reset the params which must be reset for qm init. QM init may be called as
195511e25f0dSDavid C Somayajulu  * a result of flows other than driver load (e.g. dcbx renegotiation). Other
195611e25f0dSDavid C Somayajulu  * params may be affected by the init but would simply recalculate to the same
195711e25f0dSDavid C Somayajulu  * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
195811e25f0dSDavid C Somayajulu  * affected as these amounts stay the same.
195911e25f0dSDavid C Somayajulu  */
ecore_init_qm_reset_params(struct ecore_hwfn * p_hwfn)196011e25f0dSDavid C Somayajulu static void ecore_init_qm_reset_params(struct ecore_hwfn *p_hwfn)
196111e25f0dSDavid C Somayajulu {
196211e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
196311e25f0dSDavid C Somayajulu 
196411e25f0dSDavid C Somayajulu 	qm_info->num_pqs = 0;
196511e25f0dSDavid C Somayajulu 	qm_info->num_vports = 0;
196611e25f0dSDavid C Somayajulu 	qm_info->num_pf_rls = 0;
196711e25f0dSDavid C Somayajulu 	qm_info->num_vf_pqs = 0;
196811e25f0dSDavid C Somayajulu 	qm_info->first_vf_pq = 0;
196911e25f0dSDavid C Somayajulu 	qm_info->first_mcos_pq = 0;
197011e25f0dSDavid C Somayajulu 	qm_info->first_rl_pq = 0;
197111e25f0dSDavid C Somayajulu }
197211e25f0dSDavid C Somayajulu 
ecore_init_qm_advance_vport(struct ecore_hwfn * p_hwfn)197311e25f0dSDavid C Somayajulu static void ecore_init_qm_advance_vport(struct ecore_hwfn *p_hwfn)
197411e25f0dSDavid C Somayajulu {
197511e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
197611e25f0dSDavid C Somayajulu 
197711e25f0dSDavid C Somayajulu 	qm_info->num_vports++;
197811e25f0dSDavid C Somayajulu 
197911e25f0dSDavid C Somayajulu 	if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
198011e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n", qm_info->num_vports, ecore_init_qm_get_num_vports(p_hwfn));
198111e25f0dSDavid C Somayajulu }
198211e25f0dSDavid C Somayajulu 
198311e25f0dSDavid C Somayajulu /* initialize a single pq and manage qm_info resources accounting.
198411e25f0dSDavid C Somayajulu  * The pq_init_flags param determines whether the PQ is rate limited (for VF or PF)
198511e25f0dSDavid C Somayajulu  * and whether a new vport is allocated to the pq or not (i.e. vport will be shared)
198611e25f0dSDavid C Somayajulu  */
198711e25f0dSDavid C Somayajulu 
198811e25f0dSDavid C Somayajulu /* flags for pq init */
198911e25f0dSDavid C Somayajulu #define PQ_INIT_SHARE_VPORT	(1 << 0)
199011e25f0dSDavid C Somayajulu #define PQ_INIT_PF_RL		(1 << 1)
199111e25f0dSDavid C Somayajulu #define PQ_INIT_VF_RL		(1 << 2)
199211e25f0dSDavid C Somayajulu 
199311e25f0dSDavid C Somayajulu /* defines for pq init */
199411e25f0dSDavid C Somayajulu #define PQ_INIT_DEFAULT_WRR_GROUP	1
199511e25f0dSDavid C Somayajulu #define PQ_INIT_DEFAULT_TC		0
199611e25f0dSDavid C Somayajulu #define PQ_INIT_OFLD_TC			(p_hwfn->hw_info.offload_tc)
199711e25f0dSDavid C Somayajulu 
ecore_init_qm_pq(struct ecore_hwfn * p_hwfn,struct ecore_qm_info * qm_info,u8 tc,u32 pq_init_flags)199811e25f0dSDavid C Somayajulu static void ecore_init_qm_pq(struct ecore_hwfn *p_hwfn,
199911e25f0dSDavid C Somayajulu 			     struct ecore_qm_info *qm_info,
200011e25f0dSDavid C Somayajulu 			     u8 tc, u32 pq_init_flags)
200111e25f0dSDavid C Somayajulu {
200211e25f0dSDavid C Somayajulu 	u16 pq_idx = qm_info->num_pqs, max_pq = ecore_init_qm_get_num_pqs(p_hwfn);
200311e25f0dSDavid C Somayajulu 
200411e25f0dSDavid C Somayajulu 	if (pq_idx > max_pq)
200511e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
200611e25f0dSDavid C Somayajulu 
200711e25f0dSDavid C Somayajulu 	/* init pq params */
200811e25f0dSDavid C Somayajulu 	qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport + qm_info->num_vports;
200911e25f0dSDavid C Somayajulu 	qm_info->qm_pq_params[pq_idx].tc_id = tc;
201011e25f0dSDavid C Somayajulu 	qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
201111e25f0dSDavid C Somayajulu 	qm_info->qm_pq_params[pq_idx].rl_valid =
201211e25f0dSDavid C Somayajulu 		(pq_init_flags & PQ_INIT_PF_RL || pq_init_flags & PQ_INIT_VF_RL);
201311e25f0dSDavid C Somayajulu 
201411e25f0dSDavid C Somayajulu 	/* qm params accounting */
201511e25f0dSDavid C Somayajulu 	qm_info->num_pqs++;
201611e25f0dSDavid C Somayajulu 	if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
201711e25f0dSDavid C Somayajulu 		qm_info->num_vports++;
201811e25f0dSDavid C Somayajulu 
201911e25f0dSDavid C Somayajulu 	if (pq_init_flags & PQ_INIT_PF_RL)
202011e25f0dSDavid C Somayajulu 		qm_info->num_pf_rls++;
202111e25f0dSDavid C Somayajulu 
202211e25f0dSDavid C Somayajulu 	if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
202311e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n", qm_info->num_vports, ecore_init_qm_get_num_vports(p_hwfn));
202411e25f0dSDavid C Somayajulu 
202511e25f0dSDavid C Somayajulu 	if (qm_info->num_pf_rls > ecore_init_qm_get_num_pf_rls(p_hwfn))
202611e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "rl overflow! qm_info->num_pf_rls %d, qm_init_get_num_pf_rls() %d\n", qm_info->num_pf_rls, ecore_init_qm_get_num_pf_rls(p_hwfn));
202711e25f0dSDavid C Somayajulu }
202811e25f0dSDavid C Somayajulu 
202911e25f0dSDavid C Somayajulu /* get pq index according to PQ_FLAGS */
ecore_init_qm_get_idx_from_flags(struct ecore_hwfn * p_hwfn,u32 pq_flags)203011e25f0dSDavid C Somayajulu static u16 *ecore_init_qm_get_idx_from_flags(struct ecore_hwfn *p_hwfn,
203111e25f0dSDavid C Somayajulu 					     u32 pq_flags)
203211e25f0dSDavid C Somayajulu {
203311e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
203411e25f0dSDavid C Somayajulu 
203511e25f0dSDavid C Somayajulu 	/* Can't have multiple flags set here */
203611e25f0dSDavid C Somayajulu 	if (OSAL_BITMAP_WEIGHT((unsigned long *)&pq_flags, sizeof(pq_flags)) > 1)
203711e25f0dSDavid C Somayajulu 		goto err;
203811e25f0dSDavid C Somayajulu 
203911e25f0dSDavid C Somayajulu 	switch (pq_flags) {
204011e25f0dSDavid C Somayajulu 	case PQ_FLAGS_RLS:
204111e25f0dSDavid C Somayajulu 		return &qm_info->first_rl_pq;
204211e25f0dSDavid C Somayajulu 	case PQ_FLAGS_MCOS:
204311e25f0dSDavid C Somayajulu 		return &qm_info->first_mcos_pq;
204411e25f0dSDavid C Somayajulu 	case PQ_FLAGS_LB:
204511e25f0dSDavid C Somayajulu 		return &qm_info->pure_lb_pq;
204611e25f0dSDavid C Somayajulu 	case PQ_FLAGS_OOO:
204711e25f0dSDavid C Somayajulu 		return &qm_info->ooo_pq;
204811e25f0dSDavid C Somayajulu 	case PQ_FLAGS_ACK:
204911e25f0dSDavid C Somayajulu 		return &qm_info->pure_ack_pq;
205011e25f0dSDavid C Somayajulu 	case PQ_FLAGS_OFLD:
205111e25f0dSDavid C Somayajulu 		return &qm_info->offload_pq;
205211e25f0dSDavid C Somayajulu 	case PQ_FLAGS_LLT:
205311e25f0dSDavid C Somayajulu 		return &qm_info->low_latency_pq;
205411e25f0dSDavid C Somayajulu 	case PQ_FLAGS_VFS:
205511e25f0dSDavid C Somayajulu 		return &qm_info->first_vf_pq;
205611e25f0dSDavid C Somayajulu 	default:
205711e25f0dSDavid C Somayajulu 		goto err;
205811e25f0dSDavid C Somayajulu 	}
205911e25f0dSDavid C Somayajulu 
206011e25f0dSDavid C Somayajulu err:
206111e25f0dSDavid C Somayajulu 	DP_ERR(p_hwfn, "BAD pq flags %d\n", pq_flags);
206211e25f0dSDavid C Somayajulu 	return OSAL_NULL;
206311e25f0dSDavid C Somayajulu }
206411e25f0dSDavid C Somayajulu 
206511e25f0dSDavid C Somayajulu /* save pq index in qm info */
ecore_init_qm_set_idx(struct ecore_hwfn * p_hwfn,u32 pq_flags,u16 pq_val)206611e25f0dSDavid C Somayajulu static void ecore_init_qm_set_idx(struct ecore_hwfn *p_hwfn,
206711e25f0dSDavid C Somayajulu 				  u32 pq_flags, u16 pq_val)
206811e25f0dSDavid C Somayajulu {
206911e25f0dSDavid C Somayajulu 	u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
207011e25f0dSDavid C Somayajulu 
207111e25f0dSDavid C Somayajulu 	*base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
207211e25f0dSDavid C Somayajulu }
207311e25f0dSDavid C Somayajulu 
207411e25f0dSDavid C Somayajulu /* get tx pq index, with the PQ TX base already set (ready for context init) */
ecore_get_cm_pq_idx(struct ecore_hwfn * p_hwfn,u32 pq_flags)207511e25f0dSDavid C Somayajulu u16 ecore_get_cm_pq_idx(struct ecore_hwfn *p_hwfn, u32 pq_flags)
207611e25f0dSDavid C Somayajulu {
207711e25f0dSDavid C Somayajulu 	u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
207811e25f0dSDavid C Somayajulu 
207911e25f0dSDavid C Somayajulu 	return *base_pq_idx + CM_TX_PQ_BASE;
208011e25f0dSDavid C Somayajulu }
208111e25f0dSDavid C Somayajulu 
ecore_get_cm_pq_idx_mcos(struct ecore_hwfn * p_hwfn,u8 tc)208211e25f0dSDavid C Somayajulu u16 ecore_get_cm_pq_idx_mcos(struct ecore_hwfn *p_hwfn, u8 tc)
208311e25f0dSDavid C Somayajulu {
208411e25f0dSDavid C Somayajulu 	u8 max_tc = ecore_init_qm_get_num_tcs(p_hwfn);
208511e25f0dSDavid C Somayajulu 
208611e25f0dSDavid C Somayajulu 	if (tc > max_tc)
208711e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
208811e25f0dSDavid C Somayajulu 
208911e25f0dSDavid C Somayajulu 	return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
209011e25f0dSDavid C Somayajulu }
209111e25f0dSDavid C Somayajulu 
ecore_get_cm_pq_idx_vf(struct ecore_hwfn * p_hwfn,u16 vf)209211e25f0dSDavid C Somayajulu u16 ecore_get_cm_pq_idx_vf(struct ecore_hwfn *p_hwfn, u16 vf)
209311e25f0dSDavid C Somayajulu {
209411e25f0dSDavid C Somayajulu 	u16 max_vf = ecore_init_qm_get_num_vfs(p_hwfn);
209511e25f0dSDavid C Somayajulu 
209611e25f0dSDavid C Somayajulu 	if (vf > max_vf)
209711e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
209811e25f0dSDavid C Somayajulu 
209911e25f0dSDavid C Somayajulu 	return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
210011e25f0dSDavid C Somayajulu }
210111e25f0dSDavid C Somayajulu 
ecore_get_cm_pq_idx_rl(struct ecore_hwfn * p_hwfn,u8 rl)210211e25f0dSDavid C Somayajulu u16 ecore_get_cm_pq_idx_rl(struct ecore_hwfn *p_hwfn, u8 rl)
210311e25f0dSDavid C Somayajulu {
210411e25f0dSDavid C Somayajulu 	u16 max_rl = ecore_init_qm_get_num_pf_rls(p_hwfn);
210511e25f0dSDavid C Somayajulu 
210611e25f0dSDavid C Somayajulu 	if (rl > max_rl)
210711e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "rl %d must be smaller than %d\n", rl, max_rl);
210811e25f0dSDavid C Somayajulu 
210911e25f0dSDavid C Somayajulu 	return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
211011e25f0dSDavid C Somayajulu }
211111e25f0dSDavid C Somayajulu 
211211e25f0dSDavid C Somayajulu /* Functions for creating specific types of pqs */
ecore_init_qm_lb_pq(struct ecore_hwfn * p_hwfn)211311e25f0dSDavid C Somayajulu static void ecore_init_qm_lb_pq(struct ecore_hwfn *p_hwfn)
211411e25f0dSDavid C Somayajulu {
211511e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
211611e25f0dSDavid C Somayajulu 
211711e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
211811e25f0dSDavid C Somayajulu 		return;
211911e25f0dSDavid C Somayajulu 
212011e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
212111e25f0dSDavid C Somayajulu 	ecore_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
212211e25f0dSDavid C Somayajulu }
212311e25f0dSDavid C Somayajulu 
ecore_init_qm_ooo_pq(struct ecore_hwfn * p_hwfn)212411e25f0dSDavid C Somayajulu static void ecore_init_qm_ooo_pq(struct ecore_hwfn *p_hwfn)
212511e25f0dSDavid C Somayajulu {
212611e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
212711e25f0dSDavid C Somayajulu 
212811e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
212911e25f0dSDavid C Somayajulu 		return;
213011e25f0dSDavid C Somayajulu 
213111e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
213211e25f0dSDavid C Somayajulu 	ecore_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
213311e25f0dSDavid C Somayajulu }
213411e25f0dSDavid C Somayajulu 
ecore_init_qm_pure_ack_pq(struct ecore_hwfn * p_hwfn)213511e25f0dSDavid C Somayajulu static void ecore_init_qm_pure_ack_pq(struct ecore_hwfn *p_hwfn)
213611e25f0dSDavid C Somayajulu {
213711e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
213811e25f0dSDavid C Somayajulu 
213911e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
214011e25f0dSDavid C Somayajulu 		return;
214111e25f0dSDavid C Somayajulu 
214211e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
214311e25f0dSDavid C Somayajulu 	ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
214411e25f0dSDavid C Somayajulu }
214511e25f0dSDavid C Somayajulu 
ecore_init_qm_offload_pq(struct ecore_hwfn * p_hwfn)214611e25f0dSDavid C Somayajulu static void ecore_init_qm_offload_pq(struct ecore_hwfn *p_hwfn)
214711e25f0dSDavid C Somayajulu {
214811e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
214911e25f0dSDavid C Somayajulu 
215011e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
215111e25f0dSDavid C Somayajulu 		return;
215211e25f0dSDavid C Somayajulu 
215311e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
215411e25f0dSDavid C Somayajulu 	ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
215511e25f0dSDavid C Somayajulu }
215611e25f0dSDavid C Somayajulu 
ecore_init_qm_low_latency_pq(struct ecore_hwfn * p_hwfn)215711e25f0dSDavid C Somayajulu static void ecore_init_qm_low_latency_pq(struct ecore_hwfn *p_hwfn)
215811e25f0dSDavid C Somayajulu {
215911e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
216011e25f0dSDavid C Somayajulu 
216111e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_LLT))
216211e25f0dSDavid C Somayajulu 		return;
216311e25f0dSDavid C Somayajulu 
216411e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_LLT, qm_info->num_pqs);
216511e25f0dSDavid C Somayajulu 	ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
216611e25f0dSDavid C Somayajulu }
216711e25f0dSDavid C Somayajulu 
ecore_init_qm_mcos_pqs(struct ecore_hwfn * p_hwfn)216811e25f0dSDavid C Somayajulu static void ecore_init_qm_mcos_pqs(struct ecore_hwfn *p_hwfn)
216911e25f0dSDavid C Somayajulu {
217011e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
217111e25f0dSDavid C Somayajulu 	u8 tc_idx;
217211e25f0dSDavid C Somayajulu 
217311e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
217411e25f0dSDavid C Somayajulu 		return;
217511e25f0dSDavid C Somayajulu 
217611e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
217711e25f0dSDavid C Somayajulu 	for (tc_idx = 0; tc_idx < ecore_init_qm_get_num_tcs(p_hwfn); tc_idx++)
217811e25f0dSDavid C Somayajulu 		ecore_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
217911e25f0dSDavid C Somayajulu }
218011e25f0dSDavid C Somayajulu 
ecore_init_qm_vf_pqs(struct ecore_hwfn * p_hwfn)218111e25f0dSDavid C Somayajulu static void ecore_init_qm_vf_pqs(struct ecore_hwfn *p_hwfn)
218211e25f0dSDavid C Somayajulu {
218311e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
218411e25f0dSDavid C Somayajulu 	u16 vf_idx, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
218511e25f0dSDavid C Somayajulu 
218611e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
218711e25f0dSDavid C Somayajulu 		return;
218811e25f0dSDavid C Somayajulu 
218911e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
219011e25f0dSDavid C Somayajulu 	qm_info->num_vf_pqs = num_vfs;
219111e25f0dSDavid C Somayajulu 	for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
219211e25f0dSDavid C Somayajulu 		ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_DEFAULT_TC, PQ_INIT_VF_RL);
219311e25f0dSDavid C Somayajulu }
219411e25f0dSDavid C Somayajulu 
ecore_init_qm_rl_pqs(struct ecore_hwfn * p_hwfn)219511e25f0dSDavid C Somayajulu static void ecore_init_qm_rl_pqs(struct ecore_hwfn *p_hwfn)
219611e25f0dSDavid C Somayajulu {
219711e25f0dSDavid C Somayajulu 	u16 pf_rls_idx, num_pf_rls = ecore_init_qm_get_num_pf_rls(p_hwfn);
219811e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
219911e25f0dSDavid C Somayajulu 
220011e25f0dSDavid C Somayajulu 	if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
220111e25f0dSDavid C Somayajulu 		return;
220211e25f0dSDavid C Somayajulu 
220311e25f0dSDavid C Somayajulu 	ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
220411e25f0dSDavid C Somayajulu 	for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
220511e25f0dSDavid C Somayajulu 		ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_PF_RL);
220611e25f0dSDavid C Somayajulu }
220711e25f0dSDavid C Somayajulu 
ecore_init_qm_pq_params(struct ecore_hwfn * p_hwfn)220811e25f0dSDavid C Somayajulu static void ecore_init_qm_pq_params(struct ecore_hwfn *p_hwfn)
220911e25f0dSDavid C Somayajulu {
221011e25f0dSDavid C Somayajulu 	/* rate limited pqs, must come first (FW assumption) */
221111e25f0dSDavid C Somayajulu 	ecore_init_qm_rl_pqs(p_hwfn);
221211e25f0dSDavid C Somayajulu 
221311e25f0dSDavid C Somayajulu 	/* pqs for multi cos */
221411e25f0dSDavid C Somayajulu 	ecore_init_qm_mcos_pqs(p_hwfn);
221511e25f0dSDavid C Somayajulu 
221611e25f0dSDavid C Somayajulu 	/* pure loopback pq */
221711e25f0dSDavid C Somayajulu 	ecore_init_qm_lb_pq(p_hwfn);
221811e25f0dSDavid C Somayajulu 
221911e25f0dSDavid C Somayajulu 	/* out of order pq */
222011e25f0dSDavid C Somayajulu 	ecore_init_qm_ooo_pq(p_hwfn);
222111e25f0dSDavid C Somayajulu 
222211e25f0dSDavid C Somayajulu 	/* pure ack pq */
222311e25f0dSDavid C Somayajulu 	ecore_init_qm_pure_ack_pq(p_hwfn);
222411e25f0dSDavid C Somayajulu 
222511e25f0dSDavid C Somayajulu 	/* pq for offloaded protocol */
222611e25f0dSDavid C Somayajulu 	ecore_init_qm_offload_pq(p_hwfn);
222711e25f0dSDavid C Somayajulu 
222811e25f0dSDavid C Somayajulu 	/* low latency pq */
222911e25f0dSDavid C Somayajulu 	ecore_init_qm_low_latency_pq(p_hwfn);
223011e25f0dSDavid C Somayajulu 
223111e25f0dSDavid C Somayajulu 	/* done sharing vports */
223211e25f0dSDavid C Somayajulu 	ecore_init_qm_advance_vport(p_hwfn);
223311e25f0dSDavid C Somayajulu 
223411e25f0dSDavid C Somayajulu 	/* pqs for vfs */
223511e25f0dSDavid C Somayajulu 	ecore_init_qm_vf_pqs(p_hwfn);
223611e25f0dSDavid C Somayajulu }
223711e25f0dSDavid C Somayajulu 
223811e25f0dSDavid C Somayajulu /* compare values of getters against resources amounts */
ecore_init_qm_sanity(struct ecore_hwfn * p_hwfn)223911e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_init_qm_sanity(struct ecore_hwfn *p_hwfn)
224011e25f0dSDavid C Somayajulu {
224111e25f0dSDavid C Somayajulu 	if (ecore_init_qm_get_num_vports(p_hwfn) > RESC_NUM(p_hwfn, ECORE_VPORT)) {
224211e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
224311e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
224411e25f0dSDavid C Somayajulu 	}
224511e25f0dSDavid C Somayajulu 
224611e25f0dSDavid C Somayajulu 	if (ecore_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, ECORE_PQ)) {
224711e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
224811e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
224911e25f0dSDavid C Somayajulu 	}
225011e25f0dSDavid C Somayajulu 
225111e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
225211e25f0dSDavid C Somayajulu }
225311e25f0dSDavid C Somayajulu 
225411e25f0dSDavid C Somayajulu /*
225511e25f0dSDavid C Somayajulu  * Function for verbose printing of the qm initialization results
225611e25f0dSDavid C Somayajulu  */
ecore_dp_init_qm_params(struct ecore_hwfn * p_hwfn)225711e25f0dSDavid C Somayajulu static void ecore_dp_init_qm_params(struct ecore_hwfn *p_hwfn)
225811e25f0dSDavid C Somayajulu {
225911e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
226011e25f0dSDavid C Somayajulu 	struct init_qm_vport_params *vport;
226111e25f0dSDavid C Somayajulu 	struct init_qm_port_params *port;
226211e25f0dSDavid C Somayajulu 	struct init_qm_pq_params *pq;
226311e25f0dSDavid C Somayajulu 	int i, tc;
226411e25f0dSDavid C Somayajulu 
226511e25f0dSDavid C Somayajulu 	/* top level params */
226611e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "qm init top level params: start_pq %d, start_vport %d, pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
226711e25f0dSDavid C Somayajulu 		   qm_info->start_pq, qm_info->start_vport, qm_info->pure_lb_pq, qm_info->offload_pq, qm_info->pure_ack_pq);
226811e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d, num_vports %d, max_phys_tcs_per_port %d\n",
226911e25f0dSDavid C Somayajulu 		   qm_info->ooo_pq, qm_info->first_vf_pq, qm_info->num_pqs, qm_info->num_vf_pqs, qm_info->num_vports, qm_info->max_phys_tcs_per_port);
227011e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d, pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
227111e25f0dSDavid C Somayajulu 		   qm_info->pf_rl_en, qm_info->pf_wfq_en, qm_info->vport_rl_en, qm_info->vport_wfq_en, qm_info->pf_wfq, qm_info->pf_rl, qm_info->num_pf_rls, ecore_get_pq_flags(p_hwfn));
227211e25f0dSDavid C Somayajulu 
227311e25f0dSDavid C Somayajulu 	/* port table */
22749efd0ba7SDavid C Somayajulu 	for (i = 0; i < p_hwfn->p_dev->num_ports_in_engine; i++) {
227511e25f0dSDavid C Somayajulu 		port = &(qm_info->qm_port_params[i]);
227611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "port idx %d, active %d, active_phys_tcs %d, num_pbf_cmd_lines %d, num_btb_blocks %d, reserved %d\n",
227711e25f0dSDavid C Somayajulu 			   i, port->active, port->active_phys_tcs, port->num_pbf_cmd_lines, port->num_btb_blocks, port->reserved);
227811e25f0dSDavid C Somayajulu 	}
227911e25f0dSDavid C Somayajulu 
228011e25f0dSDavid C Somayajulu 	/* vport table */
228111e25f0dSDavid C Somayajulu 	for (i = 0; i < qm_info->num_vports; i++) {
228211e25f0dSDavid C Somayajulu 		vport = &(qm_info->qm_vport_params[i]);
228311e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "vport idx %d, vport_rl %d, wfq %d, first_tx_pq_id [ ",
228411e25f0dSDavid C Somayajulu 			   qm_info->start_vport + i, vport->vport_rl, vport->vport_wfq);
228511e25f0dSDavid C Somayajulu 		for (tc = 0; tc < NUM_OF_TCS; tc++)
228611e25f0dSDavid C Somayajulu 			DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "%d ", vport->first_tx_pq_id[tc]);
228711e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "]\n");
228811e25f0dSDavid C Somayajulu 	}
228911e25f0dSDavid C Somayajulu 
229011e25f0dSDavid C Somayajulu 	/* pq table */
229111e25f0dSDavid C Somayajulu 	for (i = 0; i < qm_info->num_pqs; i++) {
229211e25f0dSDavid C Somayajulu 		pq = &(qm_info->qm_pq_params[i]);
229311e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "pq idx %d, vport_id %d, tc %d, wrr_grp %d, rl_valid %d\n",
229411e25f0dSDavid C Somayajulu 			   qm_info->start_pq + i, pq->vport_id, pq->tc_id, pq->wrr_group, pq->rl_valid);
229511e25f0dSDavid C Somayajulu 	}
229611e25f0dSDavid C Somayajulu }
229711e25f0dSDavid C Somayajulu 
ecore_init_qm_info(struct ecore_hwfn * p_hwfn)229811e25f0dSDavid C Somayajulu static void ecore_init_qm_info(struct ecore_hwfn *p_hwfn)
229911e25f0dSDavid C Somayajulu {
230011e25f0dSDavid C Somayajulu 	/* reset params required for init run */
230111e25f0dSDavid C Somayajulu 	ecore_init_qm_reset_params(p_hwfn);
230211e25f0dSDavid C Somayajulu 
230311e25f0dSDavid C Somayajulu 	/* init QM top level params */
230411e25f0dSDavid C Somayajulu 	ecore_init_qm_params(p_hwfn);
230511e25f0dSDavid C Somayajulu 
230611e25f0dSDavid C Somayajulu 	/* init QM port params */
230711e25f0dSDavid C Somayajulu 	ecore_init_qm_port_params(p_hwfn);
230811e25f0dSDavid C Somayajulu 
230911e25f0dSDavid C Somayajulu 	/* init QM vport params */
231011e25f0dSDavid C Somayajulu 	ecore_init_qm_vport_params(p_hwfn);
231111e25f0dSDavid C Somayajulu 
231211e25f0dSDavid C Somayajulu 	/* init QM physical queue params */
231311e25f0dSDavid C Somayajulu 	ecore_init_qm_pq_params(p_hwfn);
231411e25f0dSDavid C Somayajulu 
231511e25f0dSDavid C Somayajulu 	/* display all that init */
231611e25f0dSDavid C Somayajulu 	ecore_dp_init_qm_params(p_hwfn);
231711e25f0dSDavid C Somayajulu }
231811e25f0dSDavid C Somayajulu 
231911e25f0dSDavid C Somayajulu /* This function reconfigures the QM pf on the fly.
232011e25f0dSDavid C Somayajulu  * For this purpose we:
232111e25f0dSDavid C Somayajulu  * 1. reconfigure the QM database
232211e25f0dSDavid C Somayajulu  * 2. set new values to runtime array
232311e25f0dSDavid C Somayajulu  * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
232411e25f0dSDavid C Somayajulu  * 4. activate init tool in QM_PF stage
232511e25f0dSDavid C Somayajulu  * 5. send an sdm_qm_cmd through rbc interface to release the QM
232611e25f0dSDavid C Somayajulu  */
ecore_qm_reconf(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)232711e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_qm_reconf(struct ecore_hwfn *p_hwfn,
232811e25f0dSDavid C Somayajulu 				     struct ecore_ptt *p_ptt)
232911e25f0dSDavid C Somayajulu {
233011e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
233111e25f0dSDavid C Somayajulu 	bool b_rc;
233211e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
233311e25f0dSDavid C Somayajulu 
233411e25f0dSDavid C Somayajulu 	/* initialize ecore's qm data structure */
233511e25f0dSDavid C Somayajulu 	ecore_init_qm_info(p_hwfn);
233611e25f0dSDavid C Somayajulu 
233711e25f0dSDavid C Somayajulu 	/* stop PF's qm queues */
233811e25f0dSDavid C Somayajulu 	OSAL_SPIN_LOCK(&qm_lock);
233911e25f0dSDavid C Somayajulu 	b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
234011e25f0dSDavid C Somayajulu 				      qm_info->start_pq, qm_info->num_pqs);
234111e25f0dSDavid C Somayajulu 	OSAL_SPIN_UNLOCK(&qm_lock);
234211e25f0dSDavid C Somayajulu 	if (!b_rc)
234311e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
234411e25f0dSDavid C Somayajulu 
234511e25f0dSDavid C Somayajulu 	/* clear the QM_PF runtime phase leftovers from previous init */
234611e25f0dSDavid C Somayajulu 	ecore_init_clear_rt_data(p_hwfn);
234711e25f0dSDavid C Somayajulu 
234811e25f0dSDavid C Somayajulu 	/* prepare QM portion of runtime array */
2349*217ec208SDavid C Somayajulu 	ecore_qm_init_pf(p_hwfn, p_ptt, false);
235011e25f0dSDavid C Somayajulu 
235111e25f0dSDavid C Somayajulu 	/* activate init tool on runtime array */
235211e25f0dSDavid C Somayajulu 	rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
235311e25f0dSDavid C Somayajulu 			    p_hwfn->hw_info.hw_mode);
235411e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
235511e25f0dSDavid C Somayajulu 		return rc;
235611e25f0dSDavid C Somayajulu 
235711e25f0dSDavid C Somayajulu 	/* start PF's qm queues */
235811e25f0dSDavid C Somayajulu 	OSAL_SPIN_LOCK(&qm_lock);
235911e25f0dSDavid C Somayajulu 	b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
236011e25f0dSDavid C Somayajulu 				      qm_info->start_pq, qm_info->num_pqs);
236111e25f0dSDavid C Somayajulu 	OSAL_SPIN_UNLOCK(&qm_lock);
236211e25f0dSDavid C Somayajulu 	if (!b_rc)
236311e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
236411e25f0dSDavid C Somayajulu 
236511e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
236611e25f0dSDavid C Somayajulu }
236711e25f0dSDavid C Somayajulu 
ecore_alloc_qm_data(struct ecore_hwfn * p_hwfn)236811e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_alloc_qm_data(struct ecore_hwfn *p_hwfn)
236911e25f0dSDavid C Somayajulu {
237011e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
237111e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
237211e25f0dSDavid C Somayajulu 
237311e25f0dSDavid C Somayajulu 	rc = ecore_init_qm_sanity(p_hwfn);
237411e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
237511e25f0dSDavid C Somayajulu 		goto alloc_err;
237611e25f0dSDavid C Somayajulu 
237711e25f0dSDavid C Somayajulu 	qm_info->qm_pq_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
237811e25f0dSDavid C Somayajulu 					    sizeof(struct init_qm_pq_params) *
237911e25f0dSDavid C Somayajulu 					    ecore_init_qm_get_num_pqs(p_hwfn));
238011e25f0dSDavid C Somayajulu 	if (!qm_info->qm_pq_params)
238111e25f0dSDavid C Somayajulu 		goto alloc_err;
238211e25f0dSDavid C Somayajulu 
238311e25f0dSDavid C Somayajulu 	qm_info->qm_vport_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
238411e25f0dSDavid C Somayajulu 					       sizeof(struct init_qm_vport_params) *
238511e25f0dSDavid C Somayajulu 					       ecore_init_qm_get_num_vports(p_hwfn));
238611e25f0dSDavid C Somayajulu 	if (!qm_info->qm_vport_params)
238711e25f0dSDavid C Somayajulu 		goto alloc_err;
238811e25f0dSDavid C Somayajulu 
238911e25f0dSDavid C Somayajulu 	qm_info->qm_port_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
239011e25f0dSDavid C Somayajulu 					      sizeof(struct init_qm_port_params) *
23919efd0ba7SDavid C Somayajulu 					      p_hwfn->p_dev->num_ports_in_engine);
239211e25f0dSDavid C Somayajulu 	if (!qm_info->qm_port_params)
239311e25f0dSDavid C Somayajulu 		goto alloc_err;
239411e25f0dSDavid C Somayajulu 
239511e25f0dSDavid C Somayajulu 	qm_info->wfq_data = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
239611e25f0dSDavid C Somayajulu 					sizeof(struct ecore_wfq_data) *
239711e25f0dSDavid C Somayajulu 					ecore_init_qm_get_num_vports(p_hwfn));
239811e25f0dSDavid C Somayajulu 	if (!qm_info->wfq_data)
239911e25f0dSDavid C Somayajulu 		goto alloc_err;
240011e25f0dSDavid C Somayajulu 
240111e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
240211e25f0dSDavid C Somayajulu 
240311e25f0dSDavid C Somayajulu alloc_err:
240411e25f0dSDavid C Somayajulu 	DP_NOTICE(p_hwfn, false, "Failed to allocate memory for QM params\n");
240511e25f0dSDavid C Somayajulu 	ecore_qm_info_free(p_hwfn);
240611e25f0dSDavid C Somayajulu 	return ECORE_NOMEM;
240711e25f0dSDavid C Somayajulu }
240811e25f0dSDavid C Somayajulu /******************** End QM initialization ***************/
240911e25f0dSDavid C Somayajulu 
ecore_resc_alloc(struct ecore_dev * p_dev)241011e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev)
241111e25f0dSDavid C Somayajulu {
241211e25f0dSDavid C Somayajulu 	u32 rdma_tasks, excess_tasks;
241311e25f0dSDavid C Somayajulu 	u32 line_count;
24149efd0ba7SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
241511e25f0dSDavid C Somayajulu 	int i;
241611e25f0dSDavid C Somayajulu 
241711e25f0dSDavid C Somayajulu 	if (IS_VF(p_dev)) {
241811e25f0dSDavid C Somayajulu 		for_each_hwfn(p_dev, i) {
241911e25f0dSDavid C Somayajulu 			rc = ecore_l2_alloc(&p_dev->hwfns[i]);
242011e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS)
242111e25f0dSDavid C Somayajulu 				return rc;
242211e25f0dSDavid C Somayajulu 		}
242311e25f0dSDavid C Somayajulu 		return rc;
242411e25f0dSDavid C Somayajulu 	}
242511e25f0dSDavid C Somayajulu 
242611e25f0dSDavid C Somayajulu 	p_dev->fw_data = OSAL_ZALLOC(p_dev, GFP_KERNEL,
242711e25f0dSDavid C Somayajulu 				     sizeof(*p_dev->fw_data));
242811e25f0dSDavid C Somayajulu 	if (!p_dev->fw_data)
242911e25f0dSDavid C Somayajulu 		return ECORE_NOMEM;
243011e25f0dSDavid C Somayajulu 
243111e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
243211e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
243311e25f0dSDavid C Somayajulu 		u32 n_eqes, num_cons;
243411e25f0dSDavid C Somayajulu 
2435*217ec208SDavid C Somayajulu 		/* initialize the doorbell recovery mechanism */
2436*217ec208SDavid C Somayajulu 		rc = ecore_db_recovery_setup(p_hwfn);
2437*217ec208SDavid C Somayajulu 		if (rc)
2438*217ec208SDavid C Somayajulu 			goto alloc_err;
2439*217ec208SDavid C Somayajulu 
244011e25f0dSDavid C Somayajulu 		/* First allocate the context manager structure */
244111e25f0dSDavid C Somayajulu 		rc = ecore_cxt_mngr_alloc(p_hwfn);
244211e25f0dSDavid C Somayajulu 		if (rc)
244311e25f0dSDavid C Somayajulu 			goto alloc_err;
244411e25f0dSDavid C Somayajulu 
2445*217ec208SDavid C Somayajulu 		/* Set the HW cid/tid numbers (in the context manager)
244611e25f0dSDavid C Somayajulu 		 * Must be done prior to any further computations.
244711e25f0dSDavid C Somayajulu 		 */
244811e25f0dSDavid C Somayajulu 		rc = ecore_cxt_set_pf_params(p_hwfn, RDMA_MAX_TIDS);
244911e25f0dSDavid C Somayajulu 		if (rc)
245011e25f0dSDavid C Somayajulu 			goto alloc_err;
245111e25f0dSDavid C Somayajulu 
245211e25f0dSDavid C Somayajulu 		rc = ecore_alloc_qm_data(p_hwfn);
245311e25f0dSDavid C Somayajulu 		if (rc)
245411e25f0dSDavid C Somayajulu 			goto alloc_err;
245511e25f0dSDavid C Somayajulu 
245611e25f0dSDavid C Somayajulu 		/* init qm info */
245711e25f0dSDavid C Somayajulu 		ecore_init_qm_info(p_hwfn);
245811e25f0dSDavid C Somayajulu 
245911e25f0dSDavid C Somayajulu 		/* Compute the ILT client partition */
246011e25f0dSDavid C Somayajulu 		rc = ecore_cxt_cfg_ilt_compute(p_hwfn, &line_count);
246111e25f0dSDavid C Somayajulu 		if (rc) {
246211e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "too many ILT lines; re-computing with less lines\n");
246311e25f0dSDavid C Somayajulu 			/* In case there are not enough ILT lines we reduce the
246411e25f0dSDavid C Somayajulu 			 * number of RDMA tasks and re-compute.
246511e25f0dSDavid C Somayajulu 			 */
246611e25f0dSDavid C Somayajulu 			excess_tasks = ecore_cxt_cfg_ilt_compute_excess(
246711e25f0dSDavid C Somayajulu 					p_hwfn, line_count);
246811e25f0dSDavid C Somayajulu 			if (!excess_tasks)
246911e25f0dSDavid C Somayajulu 				goto alloc_err;
247011e25f0dSDavid C Somayajulu 
247111e25f0dSDavid C Somayajulu 			rdma_tasks = RDMA_MAX_TIDS - excess_tasks;
247211e25f0dSDavid C Somayajulu 			rc = ecore_cxt_set_pf_params(p_hwfn, rdma_tasks);
247311e25f0dSDavid C Somayajulu 			if (rc)
247411e25f0dSDavid C Somayajulu 				goto alloc_err;
247511e25f0dSDavid C Somayajulu 
247611e25f0dSDavid C Somayajulu 			rc = ecore_cxt_cfg_ilt_compute(p_hwfn, &line_count);
247711e25f0dSDavid C Somayajulu 			if (rc) {
247811e25f0dSDavid C Somayajulu 				DP_ERR(p_hwfn, "failed ILT compute. Requested too many lines: %u\n",
247911e25f0dSDavid C Somayajulu 				       line_count);
248011e25f0dSDavid C Somayajulu 
248111e25f0dSDavid C Somayajulu 				goto alloc_err;
248211e25f0dSDavid C Somayajulu 			}
248311e25f0dSDavid C Somayajulu 		}
248411e25f0dSDavid C Somayajulu 
248511e25f0dSDavid C Somayajulu 		/* CID map / ILT shadow table / T2
248611e25f0dSDavid C Somayajulu 		 * The talbes sizes are determined by the computations above
248711e25f0dSDavid C Somayajulu 		 */
248811e25f0dSDavid C Somayajulu 		rc = ecore_cxt_tables_alloc(p_hwfn);
248911e25f0dSDavid C Somayajulu 		if (rc)
249011e25f0dSDavid C Somayajulu 			goto alloc_err;
249111e25f0dSDavid C Somayajulu 
249211e25f0dSDavid C Somayajulu 		/* SPQ, must follow ILT because initializes SPQ context */
249311e25f0dSDavid C Somayajulu 		rc = ecore_spq_alloc(p_hwfn);
249411e25f0dSDavid C Somayajulu 		if (rc)
249511e25f0dSDavid C Somayajulu 			goto alloc_err;
249611e25f0dSDavid C Somayajulu 
249711e25f0dSDavid C Somayajulu 		/* SP status block allocation */
249811e25f0dSDavid C Somayajulu 		p_hwfn->p_dpc_ptt = ecore_get_reserved_ptt(p_hwfn,
249911e25f0dSDavid C Somayajulu 							   RESERVED_PTT_DPC);
250011e25f0dSDavid C Somayajulu 
250111e25f0dSDavid C Somayajulu 		rc = ecore_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
250211e25f0dSDavid C Somayajulu 		if (rc)
250311e25f0dSDavid C Somayajulu 			goto alloc_err;
250411e25f0dSDavid C Somayajulu 
250511e25f0dSDavid C Somayajulu 		rc = ecore_iov_alloc(p_hwfn);
250611e25f0dSDavid C Somayajulu 		if (rc)
250711e25f0dSDavid C Somayajulu 			goto alloc_err;
250811e25f0dSDavid C Somayajulu 
250911e25f0dSDavid C Somayajulu 		/* EQ */
251011e25f0dSDavid C Somayajulu 		n_eqes = ecore_chain_get_capacity(&p_hwfn->p_spq->chain);
251111e25f0dSDavid C Somayajulu 		if (ECORE_IS_RDMA_PERSONALITY(p_hwfn)) {
2512*217ec208SDavid C Somayajulu 			u32 n_srq = ecore_cxt_get_total_srq_count(p_hwfn);
2513*217ec208SDavid C Somayajulu 
251411e25f0dSDavid C Somayajulu 			/* Calculate the EQ size
251511e25f0dSDavid C Somayajulu 			 * ---------------------
251611e25f0dSDavid C Somayajulu 			 * Each ICID may generate up to one event at a time i.e.
251711e25f0dSDavid C Somayajulu 			 * the event must be handled/cleared before a new one
251811e25f0dSDavid C Somayajulu 			 * can be generated. We calculate the sum of events per
251911e25f0dSDavid C Somayajulu 			 * protocol and create an EQ deep enough to handle the
252011e25f0dSDavid C Somayajulu 			 * worst case:
252111e25f0dSDavid C Somayajulu 			 * - Core - according to SPQ.
252211e25f0dSDavid C Somayajulu 			 * - RoCE - per QP there are a couple of ICIDs, one
252311e25f0dSDavid C Somayajulu 			 *	  responder and one requester, each can
2524*217ec208SDavid C Somayajulu 			 *	  generate max 2 EQE (err+qp_destroyed) =>
2525*217ec208SDavid C Somayajulu 			 *	  n_eqes_qp = 4 * n_qp.
252611e25f0dSDavid C Somayajulu 			 *	  Each CQ can generate an EQE. There are 2 CQs
252711e25f0dSDavid C Somayajulu 			 *	  per QP => n_eqes_cq = 2 * n_qp.
2528*217ec208SDavid C Somayajulu 			 *	  Hence the RoCE total is 6 * n_qp or
2529*217ec208SDavid C Somayajulu 			 *	  3 * num_cons.
2530*217ec208SDavid C Somayajulu 			 *	  On top of that one eqe shoule be added for
2531*217ec208SDavid C Somayajulu 			 *	  each XRC SRQ and SRQ.
2532*217ec208SDavid C Somayajulu 			 * - iWARP - can generate three async per QP (error
2533*217ec208SDavid C Somayajulu 			 *	  detected and qp in error) and an
2534*217ec208SDavid C Somayajulu 			 	  additional error per CQ. 4* num_cons.
2535*217ec208SDavid C Somayajulu 			 	  On top of that one eqe shoule be added for
2536*217ec208SDavid C Somayajulu 			 *	  each SRQ and XRC SRQ.
253711e25f0dSDavid C Somayajulu 			 * - ENet - There can be up to two events per VF. One
253811e25f0dSDavid C Somayajulu 			 *	  for VF-PF channel and another for VF FLR
253911e25f0dSDavid C Somayajulu 			 *	  initial cleanup. The number of VFs is
254011e25f0dSDavid C Somayajulu 			 *	  bounded by MAX_NUM_VFS_BB, and is much
254111e25f0dSDavid C Somayajulu 			 *	  smaller than RoCE's so we avoid exact
254211e25f0dSDavid C Somayajulu 			 *	  calculation.
254311e25f0dSDavid C Somayajulu 			 */
254411e25f0dSDavid C Somayajulu 			if (p_hwfn->hw_info.personality == ECORE_PCI_ETH_ROCE) {
254511e25f0dSDavid C Somayajulu 				num_cons = ecore_cxt_get_proto_cid_count(
254611e25f0dSDavid C Somayajulu 					p_hwfn, PROTOCOLID_ROCE, OSAL_NULL);
2547*217ec208SDavid C Somayajulu 				num_cons *= 3;
254811e25f0dSDavid C Somayajulu 			} else {
254911e25f0dSDavid C Somayajulu 				num_cons = ecore_cxt_get_proto_cid_count(
255011e25f0dSDavid C Somayajulu 						p_hwfn, PROTOCOLID_IWARP,
255111e25f0dSDavid C Somayajulu 						OSAL_NULL);
2552*217ec208SDavid C Somayajulu 				num_cons *= 4;
255311e25f0dSDavid C Somayajulu 			}
2554*217ec208SDavid C Somayajulu 			n_eqes += num_cons + 2 * MAX_NUM_VFS_BB + n_srq;
255511e25f0dSDavid C Somayajulu 		} else if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
255611e25f0dSDavid C Somayajulu 			num_cons = ecore_cxt_get_proto_cid_count(
255711e25f0dSDavid C Somayajulu 					p_hwfn, PROTOCOLID_ISCSI, OSAL_NULL);
255811e25f0dSDavid C Somayajulu 			n_eqes += 2 * num_cons;
255911e25f0dSDavid C Somayajulu 		}
256011e25f0dSDavid C Somayajulu 
2561*217ec208SDavid C Somayajulu 		if (n_eqes > 0xFF00) {
2562*217ec208SDavid C Somayajulu 			DP_ERR(p_hwfn, "EQs maxing out at 0xFF00 elements\n");
2563*217ec208SDavid C Somayajulu 			n_eqes = 0xFF00;
256411e25f0dSDavid C Somayajulu 		}
256511e25f0dSDavid C Somayajulu 
256611e25f0dSDavid C Somayajulu 		rc = ecore_eq_alloc(p_hwfn, (u16)n_eqes);
256711e25f0dSDavid C Somayajulu 		if (rc)
256811e25f0dSDavid C Somayajulu 			goto alloc_err;
256911e25f0dSDavid C Somayajulu 
257011e25f0dSDavid C Somayajulu 		rc = ecore_consq_alloc(p_hwfn);
257111e25f0dSDavid C Somayajulu 		if (rc)
257211e25f0dSDavid C Somayajulu 			goto alloc_err;
257311e25f0dSDavid C Somayajulu 
257411e25f0dSDavid C Somayajulu 		rc = ecore_l2_alloc(p_hwfn);
257511e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
257611e25f0dSDavid C Somayajulu 			goto alloc_err;
257711e25f0dSDavid C Somayajulu 
257811e25f0dSDavid C Somayajulu #ifdef CONFIG_ECORE_LL2
257911e25f0dSDavid C Somayajulu 		if (p_hwfn->using_ll2) {
258011e25f0dSDavid C Somayajulu 			rc = ecore_ll2_alloc(p_hwfn);
258111e25f0dSDavid C Somayajulu 			if (rc)
258211e25f0dSDavid C Somayajulu 				goto alloc_err;
258311e25f0dSDavid C Somayajulu 		}
258411e25f0dSDavid C Somayajulu #endif
258511e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) {
258611e25f0dSDavid C Somayajulu 			rc = ecore_fcoe_alloc(p_hwfn);
258711e25f0dSDavid C Somayajulu 			if (rc)
258811e25f0dSDavid C Somayajulu 				goto alloc_err;
258911e25f0dSDavid C Somayajulu 		}
2590*217ec208SDavid C Somayajulu 
259111e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
259211e25f0dSDavid C Somayajulu 			rc = ecore_iscsi_alloc(p_hwfn);
259311e25f0dSDavid C Somayajulu 			if (rc)
259411e25f0dSDavid C Somayajulu 				goto alloc_err;
2595*217ec208SDavid C Somayajulu 
259611e25f0dSDavid C Somayajulu 			rc = ecore_ooo_alloc(p_hwfn);
259711e25f0dSDavid C Somayajulu 			if (rc)
259811e25f0dSDavid C Somayajulu 				goto alloc_err;
259911e25f0dSDavid C Somayajulu 		}
2600*217ec208SDavid C Somayajulu #ifdef CONFIG_ECORE_ROCE
2601*217ec208SDavid C Somayajulu 		if (ECORE_IS_RDMA_PERSONALITY(p_hwfn)) {
2602*217ec208SDavid C Somayajulu 			rc = ecore_rdma_info_alloc(p_hwfn);
2603*217ec208SDavid C Somayajulu 			if (rc)
2604*217ec208SDavid C Somayajulu 				goto alloc_err;
2605*217ec208SDavid C Somayajulu 		}
260611e25f0dSDavid C Somayajulu #endif
260711e25f0dSDavid C Somayajulu 
260811e25f0dSDavid C Somayajulu 		/* DMA info initialization */
260911e25f0dSDavid C Somayajulu 		rc = ecore_dmae_info_alloc(p_hwfn);
261011e25f0dSDavid C Somayajulu 		if (rc) {
2611*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
261211e25f0dSDavid C Somayajulu 				  "Failed to allocate memory for dmae_info structure\n");
261311e25f0dSDavid C Somayajulu 			goto alloc_err;
261411e25f0dSDavid C Somayajulu 		}
261511e25f0dSDavid C Somayajulu 
261611e25f0dSDavid C Somayajulu 		/* DCBX initialization */
261711e25f0dSDavid C Somayajulu 		rc = ecore_dcbx_info_alloc(p_hwfn);
261811e25f0dSDavid C Somayajulu 		if (rc) {
2619*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
262011e25f0dSDavid C Somayajulu 				  "Failed to allocate memory for dcbx structure\n");
262111e25f0dSDavid C Somayajulu 			goto alloc_err;
262211e25f0dSDavid C Somayajulu 		}
2623*217ec208SDavid C Somayajulu 	}
26249efd0ba7SDavid C Somayajulu 
2625*217ec208SDavid C Somayajulu 	rc = ecore_llh_alloc(p_dev);
2626*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS) {
2627*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
2628*217ec208SDavid C Somayajulu 			  "Failed to allocate memory for the llh_info structure\n");
2629*217ec208SDavid C Somayajulu 		goto alloc_err;
263011e25f0dSDavid C Somayajulu 	}
263111e25f0dSDavid C Somayajulu 
263211e25f0dSDavid C Somayajulu 	p_dev->reset_stats = OSAL_ZALLOC(p_dev, GFP_KERNEL,
263311e25f0dSDavid C Somayajulu 					 sizeof(*p_dev->reset_stats));
263411e25f0dSDavid C Somayajulu 	if (!p_dev->reset_stats) {
2635*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
263611e25f0dSDavid C Somayajulu 			  "Failed to allocate reset statistics\n");
263711e25f0dSDavid C Somayajulu 		goto alloc_no_mem;
263811e25f0dSDavid C Somayajulu 	}
263911e25f0dSDavid C Somayajulu 
264011e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
264111e25f0dSDavid C Somayajulu 
264211e25f0dSDavid C Somayajulu alloc_no_mem:
264311e25f0dSDavid C Somayajulu 	rc = ECORE_NOMEM;
264411e25f0dSDavid C Somayajulu alloc_err:
264511e25f0dSDavid C Somayajulu 	ecore_resc_free(p_dev);
264611e25f0dSDavid C Somayajulu 	return rc;
264711e25f0dSDavid C Somayajulu }
264811e25f0dSDavid C Somayajulu 
ecore_resc_setup(struct ecore_dev * p_dev)264911e25f0dSDavid C Somayajulu void ecore_resc_setup(struct ecore_dev *p_dev)
265011e25f0dSDavid C Somayajulu {
265111e25f0dSDavid C Somayajulu 	int i;
265211e25f0dSDavid C Somayajulu 
265311e25f0dSDavid C Somayajulu 	if (IS_VF(p_dev)) {
265411e25f0dSDavid C Somayajulu 		for_each_hwfn(p_dev, i)
265511e25f0dSDavid C Somayajulu 			ecore_l2_setup(&p_dev->hwfns[i]);
265611e25f0dSDavid C Somayajulu 		return;
265711e25f0dSDavid C Somayajulu 	}
265811e25f0dSDavid C Somayajulu 
265911e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
266011e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
266111e25f0dSDavid C Somayajulu 
266211e25f0dSDavid C Somayajulu 		ecore_cxt_mngr_setup(p_hwfn);
266311e25f0dSDavid C Somayajulu 		ecore_spq_setup(p_hwfn);
266411e25f0dSDavid C Somayajulu 		ecore_eq_setup(p_hwfn);
266511e25f0dSDavid C Somayajulu 		ecore_consq_setup(p_hwfn);
266611e25f0dSDavid C Somayajulu 
266711e25f0dSDavid C Somayajulu 		/* Read shadow of current MFW mailbox */
266811e25f0dSDavid C Somayajulu 		ecore_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
266911e25f0dSDavid C Somayajulu 		OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
267011e25f0dSDavid C Somayajulu 			    p_hwfn->mcp_info->mfw_mb_cur,
267111e25f0dSDavid C Somayajulu 			    p_hwfn->mcp_info->mfw_mb_length);
267211e25f0dSDavid C Somayajulu 
267311e25f0dSDavid C Somayajulu 		ecore_int_setup(p_hwfn, p_hwfn->p_main_ptt);
267411e25f0dSDavid C Somayajulu 
267511e25f0dSDavid C Somayajulu 		ecore_l2_setup(p_hwfn);
26769efd0ba7SDavid C Somayajulu 		ecore_iov_setup(p_hwfn);
267711e25f0dSDavid C Somayajulu #ifdef CONFIG_ECORE_LL2
267811e25f0dSDavid C Somayajulu 		if (p_hwfn->using_ll2)
267911e25f0dSDavid C Somayajulu 			ecore_ll2_setup(p_hwfn);
268011e25f0dSDavid C Somayajulu #endif
268111e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE)
268211e25f0dSDavid C Somayajulu 			ecore_fcoe_setup(p_hwfn);
2683*217ec208SDavid C Somayajulu 
268411e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
268511e25f0dSDavid C Somayajulu 			ecore_iscsi_setup(p_hwfn);
268611e25f0dSDavid C Somayajulu 			ecore_ooo_setup(p_hwfn);
268711e25f0dSDavid C Somayajulu 		}
268811e25f0dSDavid C Somayajulu 	}
268911e25f0dSDavid C Somayajulu }
269011e25f0dSDavid C Somayajulu 
269111e25f0dSDavid C Somayajulu #define FINAL_CLEANUP_POLL_CNT	(100)
269211e25f0dSDavid C Somayajulu #define FINAL_CLEANUP_POLL_TIME	(10)
ecore_final_cleanup(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 id,bool is_vf)269311e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
269411e25f0dSDavid C Somayajulu 					 struct ecore_ptt *p_ptt,
269511e25f0dSDavid C Somayajulu 					 u16 id, bool is_vf)
269611e25f0dSDavid C Somayajulu {
269711e25f0dSDavid C Somayajulu 	u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
269811e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_TIMEOUT;
269911e25f0dSDavid C Somayajulu 
270011e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
270111e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev) ||
270211e25f0dSDavid C Somayajulu 	    CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
270311e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn, "Skipping final cleanup for non-ASIC\n");
270411e25f0dSDavid C Somayajulu 		return ECORE_SUCCESS;
270511e25f0dSDavid C Somayajulu 	}
270611e25f0dSDavid C Somayajulu #endif
270711e25f0dSDavid C Somayajulu 
270811e25f0dSDavid C Somayajulu 	addr = GTT_BAR0_MAP_REG_USDM_RAM +
270911e25f0dSDavid C Somayajulu 	       USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
271011e25f0dSDavid C Somayajulu 
271111e25f0dSDavid C Somayajulu 	if (is_vf)
271211e25f0dSDavid C Somayajulu 		id += 0x10;
271311e25f0dSDavid C Somayajulu 
271411e25f0dSDavid C Somayajulu 	command |= X_FINAL_CLEANUP_AGG_INT <<
271511e25f0dSDavid C Somayajulu 		   SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
271611e25f0dSDavid C Somayajulu 	command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
271711e25f0dSDavid C Somayajulu 	command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
271811e25f0dSDavid C Somayajulu 	command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
271911e25f0dSDavid C Somayajulu 
272011e25f0dSDavid C Somayajulu 	/* Make sure notification is not set before initiating final cleanup */
272111e25f0dSDavid C Somayajulu 	if (REG_RD(p_hwfn, addr)) {
272211e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
272311e25f0dSDavid C Somayajulu 			  "Unexpected; Found final cleanup notification before initiating final cleanup\n");
272411e25f0dSDavid C Somayajulu 		REG_WR(p_hwfn, addr, 0);
272511e25f0dSDavid C Somayajulu 	}
272611e25f0dSDavid C Somayajulu 
272711e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2728*217ec208SDavid C Somayajulu 		   "Sending final cleanup for PFVF[%d] [Command %08x]\n",
272911e25f0dSDavid C Somayajulu 		   id, command);
273011e25f0dSDavid C Somayajulu 
273111e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
273211e25f0dSDavid C Somayajulu 
273311e25f0dSDavid C Somayajulu 	/* Poll until completion */
273411e25f0dSDavid C Somayajulu 	while (!REG_RD(p_hwfn, addr) && count--)
273511e25f0dSDavid C Somayajulu 		OSAL_MSLEEP(FINAL_CLEANUP_POLL_TIME);
273611e25f0dSDavid C Somayajulu 
273711e25f0dSDavid C Somayajulu 	if (REG_RD(p_hwfn, addr))
273811e25f0dSDavid C Somayajulu 		rc = ECORE_SUCCESS;
273911e25f0dSDavid C Somayajulu 	else
274011e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "Failed to receive FW final cleanup notification\n");
274111e25f0dSDavid C Somayajulu 
274211e25f0dSDavid C Somayajulu 	/* Cleanup afterwards */
274311e25f0dSDavid C Somayajulu 	REG_WR(p_hwfn, addr, 0);
274411e25f0dSDavid C Somayajulu 
274511e25f0dSDavid C Somayajulu 	return rc;
274611e25f0dSDavid C Somayajulu }
274711e25f0dSDavid C Somayajulu 
ecore_calc_hw_mode(struct ecore_hwfn * p_hwfn)274811e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_calc_hw_mode(struct ecore_hwfn *p_hwfn)
274911e25f0dSDavid C Somayajulu {
275011e25f0dSDavid C Somayajulu 	int hw_mode = 0;
275111e25f0dSDavid C Somayajulu 
275211e25f0dSDavid C Somayajulu 	if (ECORE_IS_BB_B0(p_hwfn->p_dev)) {
275311e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_BB;
275411e25f0dSDavid C Somayajulu 	} else if (ECORE_IS_AH(p_hwfn->p_dev)) {
275511e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_K2;
27569efd0ba7SDavid C Somayajulu 	} else if (ECORE_IS_E5(p_hwfn->p_dev)) {
27579efd0ba7SDavid C Somayajulu 		hw_mode |= 1 << MODE_E5;
275811e25f0dSDavid C Somayajulu 	} else {
275911e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "Unknown chip type %#x\n",
276011e25f0dSDavid C Somayajulu 			  p_hwfn->p_dev->type);
276111e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
276211e25f0dSDavid C Somayajulu 	}
276311e25f0dSDavid C Somayajulu 
276411e25f0dSDavid C Somayajulu 	/* Ports per engine is based on the values in CNIG_REG_NW_PORT_MODE*/
27659efd0ba7SDavid C Somayajulu 	switch (p_hwfn->p_dev->num_ports_in_engine) {
276611e25f0dSDavid C Somayajulu 	case 1:
276711e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
276811e25f0dSDavid C Somayajulu 		break;
276911e25f0dSDavid C Somayajulu 	case 2:
277011e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
277111e25f0dSDavid C Somayajulu 		break;
277211e25f0dSDavid C Somayajulu 	case 4:
277311e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
277411e25f0dSDavid C Somayajulu 		break;
277511e25f0dSDavid C Somayajulu 	default:
277611e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "num_ports_in_engine = %d not supported\n",
27779efd0ba7SDavid C Somayajulu 			  p_hwfn->p_dev->num_ports_in_engine);
277811e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
277911e25f0dSDavid C Somayajulu 	}
278011e25f0dSDavid C Somayajulu 
2781*217ec208SDavid C Somayajulu 	if (OSAL_TEST_BIT(ECORE_MF_OVLAN_CLSS,
2782*217ec208SDavid C Somayajulu 			  &p_hwfn->p_dev->mf_bits))
278311e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_MF_SD;
2784*217ec208SDavid C Somayajulu 	else
278511e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_MF_SI;
278611e25f0dSDavid C Somayajulu 
278711e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
278811e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
278911e25f0dSDavid C Somayajulu 		if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
279011e25f0dSDavid C Somayajulu 			hw_mode |= 1 << MODE_FPGA;
279111e25f0dSDavid C Somayajulu 		} else {
279211e25f0dSDavid C Somayajulu 			if (p_hwfn->p_dev->b_is_emul_full)
279311e25f0dSDavid C Somayajulu 				hw_mode |= 1 << MODE_EMUL_FULL;
279411e25f0dSDavid C Somayajulu 			else
279511e25f0dSDavid C Somayajulu 				hw_mode |= 1 << MODE_EMUL_REDUCED;
279611e25f0dSDavid C Somayajulu 		}
279711e25f0dSDavid C Somayajulu 	} else
279811e25f0dSDavid C Somayajulu #endif
279911e25f0dSDavid C Somayajulu 	hw_mode |= 1 << MODE_ASIC;
280011e25f0dSDavid C Somayajulu 
2801*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_hwfn->p_dev))
280211e25f0dSDavid C Somayajulu 		hw_mode |= 1 << MODE_100G;
280311e25f0dSDavid C Somayajulu 
280411e25f0dSDavid C Somayajulu 	p_hwfn->hw_info.hw_mode = hw_mode;
280511e25f0dSDavid C Somayajulu 
280611e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, (ECORE_MSG_PROBE | ECORE_MSG_IFUP),
280711e25f0dSDavid C Somayajulu 		   "Configuring function for hw_mode: 0x%08x\n",
280811e25f0dSDavid C Somayajulu 		   p_hwfn->hw_info.hw_mode);
280911e25f0dSDavid C Somayajulu 
281011e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
281111e25f0dSDavid C Somayajulu }
281211e25f0dSDavid C Somayajulu 
281311e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
281411e25f0dSDavid C Somayajulu /* MFW-replacement initializations for non-ASIC */
ecore_hw_init_chip(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)281511e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_hw_init_chip(struct ecore_hwfn *p_hwfn,
281611e25f0dSDavid C Somayajulu 					       struct ecore_ptt *p_ptt)
281711e25f0dSDavid C Somayajulu {
281811e25f0dSDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
281911e25f0dSDavid C Somayajulu 	u32 pl_hv = 1;
282011e25f0dSDavid C Somayajulu 	int i;
282111e25f0dSDavid C Somayajulu 
282211e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev)) {
282311e25f0dSDavid C Somayajulu 		if (ECORE_IS_AH(p_dev))
282411e25f0dSDavid C Somayajulu 			pl_hv |= 0x600;
282511e25f0dSDavid C Somayajulu 		else if (ECORE_IS_E5(p_dev))
282611e25f0dSDavid C Somayajulu 			ECORE_E5_MISSING_CODE;
282711e25f0dSDavid C Somayajulu 	}
282811e25f0dSDavid C Somayajulu 
282911e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV + 4, pl_hv);
283011e25f0dSDavid C Somayajulu 
283111e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev) &&
283211e25f0dSDavid C Somayajulu 	    (ECORE_IS_AH(p_dev) || ECORE_IS_E5(p_dev)))
283311e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV_2_K2_E5,
283411e25f0dSDavid C Somayajulu 			 0x3ffffff);
283511e25f0dSDavid C Somayajulu 
283611e25f0dSDavid C Somayajulu 	/* initialize port mode to 4x10G_E (10G with 4x10 SERDES) */
283711e25f0dSDavid C Somayajulu 	/* CNIG_REG_NW_PORT_MODE is same for A0 and B0 */
283811e25f0dSDavid C Somayajulu 	if (!CHIP_REV_IS_EMUL(p_dev) || ECORE_IS_BB(p_dev))
283911e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB, 4);
284011e25f0dSDavid C Somayajulu 
284111e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev)) {
284211e25f0dSDavid C Somayajulu 		if (ECORE_IS_AH(p_dev)) {
284311e25f0dSDavid C Somayajulu 			/* 2 for 4-port, 1 for 2-port, 0 for 1-port */
284411e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, MISC_REG_PORT_MODE,
28459efd0ba7SDavid C Somayajulu 				 (p_dev->num_ports_in_engine >> 1));
284611e25f0dSDavid C Somayajulu 
284711e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, MISC_REG_BLOCK_256B_EN,
28489efd0ba7SDavid C Somayajulu 				 p_dev->num_ports_in_engine == 4 ? 0 : 3);
284911e25f0dSDavid C Somayajulu 		} else if (ECORE_IS_E5(p_dev)) {
285011e25f0dSDavid C Somayajulu 			ECORE_E5_MISSING_CODE;
285111e25f0dSDavid C Somayajulu 		}
285211e25f0dSDavid C Somayajulu 
285311e25f0dSDavid C Somayajulu 		/* Poll on RBC */
285411e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_RBC_DONE, 1);
285511e25f0dSDavid C Somayajulu 		for (i = 0; i < 100; i++) {
285611e25f0dSDavid C Somayajulu 			OSAL_UDELAY(50);
285711e25f0dSDavid C Somayajulu 			if (ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_CFG_DONE) == 1)
285811e25f0dSDavid C Somayajulu 				break;
285911e25f0dSDavid C Somayajulu 		}
286011e25f0dSDavid C Somayajulu 		if (i == 100)
28619efd0ba7SDavid C Somayajulu 			DP_NOTICE(p_hwfn, true,
28629efd0ba7SDavid C Somayajulu 				  "RBC done failed to complete in PSWRQ2\n");
28639efd0ba7SDavid C Somayajulu 	}
286411e25f0dSDavid C Somayajulu 
286511e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
286611e25f0dSDavid C Somayajulu }
286711e25f0dSDavid C Somayajulu #endif
286811e25f0dSDavid C Somayajulu 
286911e25f0dSDavid C Somayajulu /* Init run time data for all PFs and their VFs on an engine.
287011e25f0dSDavid C Somayajulu  * TBD - for VFs - Once we have parent PF info for each VF in
287111e25f0dSDavid C Somayajulu  * shmem available as CAU requires knowledge of parent PF for each VF.
287211e25f0dSDavid C Somayajulu  */
ecore_init_cau_rt_data(struct ecore_dev * p_dev)287311e25f0dSDavid C Somayajulu static void ecore_init_cau_rt_data(struct ecore_dev *p_dev)
287411e25f0dSDavid C Somayajulu {
287511e25f0dSDavid C Somayajulu 	u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
287611e25f0dSDavid C Somayajulu 	int i, igu_sb_id;
287711e25f0dSDavid C Somayajulu 
287811e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
287911e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
288011e25f0dSDavid C Somayajulu 		struct ecore_igu_info *p_igu_info;
288111e25f0dSDavid C Somayajulu 		struct ecore_igu_block *p_block;
288211e25f0dSDavid C Somayajulu 		struct cau_sb_entry sb_entry;
288311e25f0dSDavid C Somayajulu 
288411e25f0dSDavid C Somayajulu 		p_igu_info = p_hwfn->hw_info.p_igu_info;
288511e25f0dSDavid C Somayajulu 
288611e25f0dSDavid C Somayajulu 		for (igu_sb_id = 0;
288711e25f0dSDavid C Somayajulu 		     igu_sb_id < ECORE_MAPPING_MEMORY_SIZE(p_dev);
288811e25f0dSDavid C Somayajulu 		     igu_sb_id++) {
288911e25f0dSDavid C Somayajulu 			p_block = &p_igu_info->entry[igu_sb_id];
289011e25f0dSDavid C Somayajulu 
289111e25f0dSDavid C Somayajulu 			if (!p_block->is_pf)
289211e25f0dSDavid C Somayajulu 				continue;
289311e25f0dSDavid C Somayajulu 
289411e25f0dSDavid C Somayajulu 			ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
289511e25f0dSDavid C Somayajulu 						p_block->function_id,
289611e25f0dSDavid C Somayajulu 						0, 0);
289711e25f0dSDavid C Somayajulu 			STORE_RT_REG_AGG(p_hwfn, offset + igu_sb_id * 2,
289811e25f0dSDavid C Somayajulu 					 sb_entry);
289911e25f0dSDavid C Somayajulu 		}
290011e25f0dSDavid C Somayajulu 	}
290111e25f0dSDavid C Somayajulu }
290211e25f0dSDavid C Somayajulu 
ecore_init_cache_line_size(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)290311e25f0dSDavid C Somayajulu static void ecore_init_cache_line_size(struct ecore_hwfn *p_hwfn,
290411e25f0dSDavid C Somayajulu 				       struct ecore_ptt *p_ptt)
290511e25f0dSDavid C Somayajulu {
290611e25f0dSDavid C Somayajulu 	u32 val, wr_mbs, cache_line_size;
290711e25f0dSDavid C Somayajulu 
290811e25f0dSDavid C Somayajulu 	val = ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_WR_MBS0);
290911e25f0dSDavid C Somayajulu 	switch (val) {
291011e25f0dSDavid C Somayajulu 	case 0:
291111e25f0dSDavid C Somayajulu 		wr_mbs = 128;
291211e25f0dSDavid C Somayajulu 		break;
291311e25f0dSDavid C Somayajulu 	case 1:
291411e25f0dSDavid C Somayajulu 		wr_mbs = 256;
291511e25f0dSDavid C Somayajulu 		break;
291611e25f0dSDavid C Somayajulu 	case 2:
291711e25f0dSDavid C Somayajulu 		wr_mbs = 512;
291811e25f0dSDavid C Somayajulu 		break;
291911e25f0dSDavid C Somayajulu 	default:
292011e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
292111e25f0dSDavid C Somayajulu 			"Unexpected value of PSWRQ2_REG_WR_MBS0 [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
292211e25f0dSDavid C Somayajulu 			val);
292311e25f0dSDavid C Somayajulu 		return;
292411e25f0dSDavid C Somayajulu 	}
292511e25f0dSDavid C Somayajulu 
292611e25f0dSDavid C Somayajulu 	cache_line_size = OSAL_MIN_T(u32, OSAL_CACHE_LINE_SIZE, wr_mbs);
292711e25f0dSDavid C Somayajulu 	switch (cache_line_size) {
292811e25f0dSDavid C Somayajulu 	case 32:
292911e25f0dSDavid C Somayajulu 		val = 0;
293011e25f0dSDavid C Somayajulu 		break;
293111e25f0dSDavid C Somayajulu 	case 64:
293211e25f0dSDavid C Somayajulu 		val = 1;
293311e25f0dSDavid C Somayajulu 		break;
293411e25f0dSDavid C Somayajulu 	case 128:
293511e25f0dSDavid C Somayajulu 		val = 2;
293611e25f0dSDavid C Somayajulu 		break;
293711e25f0dSDavid C Somayajulu 	case 256:
293811e25f0dSDavid C Somayajulu 		val = 3;
293911e25f0dSDavid C Somayajulu 		break;
294011e25f0dSDavid C Somayajulu 	default:
294111e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
294211e25f0dSDavid C Somayajulu 			"Unexpected value of cache line size [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
294311e25f0dSDavid C Somayajulu 			cache_line_size);
294411e25f0dSDavid C Somayajulu 	}
294511e25f0dSDavid C Somayajulu 
294611e25f0dSDavid C Somayajulu 	if (OSAL_CACHE_LINE_SIZE > wr_mbs)
294711e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
294811e25f0dSDavid C Somayajulu 			"The cache line size for padding is suboptimal for performance [OS cache line size 0x%x, wr mbs 0x%x]\n",
294911e25f0dSDavid C Somayajulu 			OSAL_CACHE_LINE_SIZE, wr_mbs);
295011e25f0dSDavid C Somayajulu 
295111e25f0dSDavid C Somayajulu 	STORE_RT_REG(p_hwfn, PGLUE_REG_B_CACHE_LINE_SIZE_RT_OFFSET, val);
29529efd0ba7SDavid C Somayajulu 	if (val > 0) {
29539efd0ba7SDavid C Somayajulu 		STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_WR_RT_OFFSET, val);
29549efd0ba7SDavid C Somayajulu 		STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_RD_RT_OFFSET, val);
29559efd0ba7SDavid C Somayajulu 	}
295611e25f0dSDavid C Somayajulu }
295711e25f0dSDavid C Somayajulu 
ecore_hw_init_common(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,int hw_mode)295811e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_hw_init_common(struct ecore_hwfn *p_hwfn,
295911e25f0dSDavid C Somayajulu 						 struct ecore_ptt *p_ptt,
296011e25f0dSDavid C Somayajulu 						 int hw_mode)
296111e25f0dSDavid C Somayajulu {
296211e25f0dSDavid C Somayajulu 	struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
296311e25f0dSDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
296411e25f0dSDavid C Somayajulu 	u8 vf_id, max_num_vfs;
296511e25f0dSDavid C Somayajulu 	u16 num_pfs, pf_id;
296611e25f0dSDavid C Somayajulu 	u32 concrete_fid;
296711e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc	= ECORE_SUCCESS;
296811e25f0dSDavid C Somayajulu 
296911e25f0dSDavid C Somayajulu 	ecore_init_cau_rt_data(p_dev);
297011e25f0dSDavid C Somayajulu 
297111e25f0dSDavid C Somayajulu 	/* Program GTT windows */
29729efd0ba7SDavid C Somayajulu 	ecore_gtt_init(p_hwfn, p_ptt);
297311e25f0dSDavid C Somayajulu 
297411e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
297511e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev)) {
29769efd0ba7SDavid C Somayajulu 		rc = ecore_hw_init_chip(p_hwfn, p_ptt);
297711e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
297811e25f0dSDavid C Somayajulu 			return rc;
297911e25f0dSDavid C Somayajulu 	}
298011e25f0dSDavid C Somayajulu #endif
298111e25f0dSDavid C Somayajulu 
298211e25f0dSDavid C Somayajulu 	if (p_hwfn->mcp_info) {
298311e25f0dSDavid C Somayajulu 		if (p_hwfn->mcp_info->func_info.bandwidth_max)
298411e25f0dSDavid C Somayajulu 			qm_info->pf_rl_en = 1;
298511e25f0dSDavid C Somayajulu 		if (p_hwfn->mcp_info->func_info.bandwidth_min)
298611e25f0dSDavid C Somayajulu 			qm_info->pf_wfq_en = 1;
298711e25f0dSDavid C Somayajulu 	}
298811e25f0dSDavid C Somayajulu 
298911e25f0dSDavid C Somayajulu 	ecore_qm_common_rt_init(p_hwfn,
29909efd0ba7SDavid C Somayajulu 				p_dev->num_ports_in_engine,
299111e25f0dSDavid C Somayajulu 				qm_info->max_phys_tcs_per_port,
299211e25f0dSDavid C Somayajulu 				qm_info->pf_rl_en, qm_info->pf_wfq_en,
299311e25f0dSDavid C Somayajulu 				qm_info->vport_rl_en, qm_info->vport_wfq_en,
299411e25f0dSDavid C Somayajulu 				qm_info->qm_port_params);
299511e25f0dSDavid C Somayajulu 
299611e25f0dSDavid C Somayajulu 	ecore_cxt_hw_init_common(p_hwfn);
299711e25f0dSDavid C Somayajulu 
299811e25f0dSDavid C Somayajulu 	ecore_init_cache_line_size(p_hwfn, p_ptt);
299911e25f0dSDavid C Somayajulu 
3000*217ec208SDavid C Somayajulu 	rc = ecore_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ECORE_PATH_ID(p_hwfn),
3001*217ec208SDavid C Somayajulu 			    hw_mode);
300211e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
300311e25f0dSDavid C Somayajulu 		return rc;
300411e25f0dSDavid C Somayajulu 
300511e25f0dSDavid C Somayajulu 	/* @@TBD MichalK - should add VALIDATE_VFID to init tool...
300611e25f0dSDavid C Somayajulu 	 * need to decide with which value, maybe runtime
300711e25f0dSDavid C Somayajulu 	 */
300811e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
300911e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
301011e25f0dSDavid C Somayajulu 
301111e25f0dSDavid C Somayajulu 	if (ECORE_IS_BB(p_dev)) {
301211e25f0dSDavid C Somayajulu 		/* Workaround clears ROCE search for all functions to prevent
3013*217ec208SDavid C Somayajulu 		 * involving non initialized function in processing ROCE packet.
301411e25f0dSDavid C Somayajulu 		 */
301511e25f0dSDavid C Somayajulu 		num_pfs = NUM_OF_ENG_PFS(p_dev);
301611e25f0dSDavid C Somayajulu 		for (pf_id = 0; pf_id < num_pfs; pf_id++) {
301711e25f0dSDavid C Somayajulu 			ecore_fid_pretend(p_hwfn, p_ptt, pf_id);
301811e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
301911e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
302011e25f0dSDavid C Somayajulu 		}
302111e25f0dSDavid C Somayajulu 		/* pretend to original PF */
302211e25f0dSDavid C Somayajulu 		ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
302311e25f0dSDavid C Somayajulu 	}
302411e25f0dSDavid C Somayajulu 
302511e25f0dSDavid C Somayajulu 	/* Workaround for avoiding CCFC execution error when getting packets
302611e25f0dSDavid C Somayajulu 	 * with CRC errors, and allowing instead the invoking of the FW error
302711e25f0dSDavid C Somayajulu 	 * handler.
302811e25f0dSDavid C Somayajulu 	 * This is not done inside the init tool since it currently can't
302911e25f0dSDavid C Somayajulu 	 * perform a pretending to VFs.
303011e25f0dSDavid C Somayajulu 	 */
303111e25f0dSDavid C Somayajulu 	max_num_vfs = ECORE_IS_AH(p_dev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
303211e25f0dSDavid C Somayajulu 	for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
303311e25f0dSDavid C Somayajulu 		concrete_fid = ecore_vfid_to_concrete(p_hwfn, vf_id);
303411e25f0dSDavid C Somayajulu 		ecore_fid_pretend(p_hwfn, p_ptt, (u16)concrete_fid);
303511e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
303611e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
303711e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
303811e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
303911e25f0dSDavid C Somayajulu 	}
304011e25f0dSDavid C Somayajulu 	/* pretend to original PF */
304111e25f0dSDavid C Somayajulu 	ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
304211e25f0dSDavid C Somayajulu 
304311e25f0dSDavid C Somayajulu 	return rc;
304411e25f0dSDavid C Somayajulu }
304511e25f0dSDavid C Somayajulu 
304611e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
304711e25f0dSDavid C Somayajulu #define MISC_REG_RESET_REG_2_XMAC_BIT (1<<4)
304811e25f0dSDavid C Somayajulu #define MISC_REG_RESET_REG_2_XMAC_SOFT_BIT (1<<5)
304911e25f0dSDavid C Somayajulu 
305011e25f0dSDavid C Somayajulu #define PMEG_IF_BYTE_COUNT	8
305111e25f0dSDavid C Somayajulu 
ecore_wr_nw_port(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 addr,u64 data,u8 reg_type,u8 port)305211e25f0dSDavid C Somayajulu static void ecore_wr_nw_port(struct ecore_hwfn	*p_hwfn,
305311e25f0dSDavid C Somayajulu 			     struct ecore_ptt	*p_ptt,
305411e25f0dSDavid C Somayajulu 			     u32		addr,
305511e25f0dSDavid C Somayajulu 			     u64		data,
305611e25f0dSDavid C Somayajulu 			     u8			reg_type,
305711e25f0dSDavid C Somayajulu 			     u8			port)
305811e25f0dSDavid C Somayajulu {
305911e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
306011e25f0dSDavid C Somayajulu 		   "CMD: %08x, ADDR: 0x%08x, DATA: %08x:%08x\n",
306111e25f0dSDavid C Somayajulu 		   ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) |
306211e25f0dSDavid C Somayajulu 		   (8 << PMEG_IF_BYTE_COUNT),
306311e25f0dSDavid C Somayajulu 		   (reg_type << 25) | (addr << 8) | port,
306411e25f0dSDavid C Somayajulu 		   (u32)((data >> 32) & 0xffffffff),
306511e25f0dSDavid C Somayajulu 		   (u32)(data & 0xffffffff));
306611e25f0dSDavid C Somayajulu 
306711e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB,
306811e25f0dSDavid C Somayajulu 		 (ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) &
306911e25f0dSDavid C Somayajulu 		  0xffff00fe) |
307011e25f0dSDavid C Somayajulu 		 (8 << PMEG_IF_BYTE_COUNT));
307111e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_ADDR_BB,
307211e25f0dSDavid C Somayajulu 		 (reg_type << 25) | (addr << 8) | port);
307311e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB, data & 0xffffffff);
307411e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB,
307511e25f0dSDavid C Somayajulu 		 (data >> 32) & 0xffffffff);
307611e25f0dSDavid C Somayajulu }
307711e25f0dSDavid C Somayajulu 
307811e25f0dSDavid C Somayajulu #define XLPORT_MODE_REG	(0x20a)
307911e25f0dSDavid C Somayajulu #define XLPORT_MAC_CONTROL (0x210)
308011e25f0dSDavid C Somayajulu #define XLPORT_FLOW_CONTROL_CONFIG (0x207)
308111e25f0dSDavid C Somayajulu #define XLPORT_ENABLE_REG (0x20b)
308211e25f0dSDavid C Somayajulu 
308311e25f0dSDavid C Somayajulu #define XLMAC_CTRL (0x600)
308411e25f0dSDavid C Somayajulu #define XLMAC_MODE (0x601)
308511e25f0dSDavid C Somayajulu #define XLMAC_RX_MAX_SIZE (0x608)
308611e25f0dSDavid C Somayajulu #define XLMAC_TX_CTRL (0x604)
308711e25f0dSDavid C Somayajulu #define XLMAC_PAUSE_CTRL (0x60d)
308811e25f0dSDavid C Somayajulu #define XLMAC_PFC_CTRL (0x60e)
308911e25f0dSDavid C Somayajulu 
ecore_emul_link_init_bb(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)309011e25f0dSDavid C Somayajulu static void ecore_emul_link_init_bb(struct ecore_hwfn *p_hwfn,
309111e25f0dSDavid C Somayajulu 				    struct ecore_ptt *p_ptt)
309211e25f0dSDavid C Somayajulu {
309311e25f0dSDavid C Somayajulu 	u8 loopback = 0, port = p_hwfn->port_id * 2;
309411e25f0dSDavid C Somayajulu 
309511e25f0dSDavid C Somayajulu 	DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
309611e25f0dSDavid C Somayajulu 
309711e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MODE_REG,
309811e25f0dSDavid C Somayajulu 			 (0x4 << 4) | 0x4, 1, port); /* XLPORT MAC MODE */ /* 0 Quad, 4 Single... */
309911e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MAC_CONTROL, 0, 1, port);
310011e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL,
310111e25f0dSDavid C Somayajulu 			 0x40, 0, port); /*XLMAC: SOFT RESET */
310211e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_MODE,
310311e25f0dSDavid C Somayajulu 			 0x40, 0, port); /*XLMAC: Port Speed >= 10Gbps */
310411e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_RX_MAX_SIZE,
310511e25f0dSDavid C Somayajulu 			 0x3fff, 0, port); /* XLMAC: Max Size */
310611e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_TX_CTRL,
310711e25f0dSDavid C Somayajulu 			 0x01000000800ULL | (0xa << 12) | ((u64)1 << 38),
310811e25f0dSDavid C Somayajulu 			 0, port);
310911e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PAUSE_CTRL,
311011e25f0dSDavid C Somayajulu 			 0x7c000, 0, port);
311111e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PFC_CTRL,
311211e25f0dSDavid C Somayajulu 			 0x30ffffc000ULL, 0, port);
311311e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x3 | (loopback << 2),
311411e25f0dSDavid C Somayajulu 			 0, port); /* XLMAC: TX_EN, RX_EN */
311511e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x1003 | (loopback << 2),
311611e25f0dSDavid C Somayajulu 			 0, port); /* XLMAC: TX_EN, RX_EN, SW_LINK_STATUS */
311711e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_FLOW_CONTROL_CONFIG,
311811e25f0dSDavid C Somayajulu 			 1, 0, port); /* Enabled Parallel PFC interface */
311911e25f0dSDavid C Somayajulu 	ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_ENABLE_REG,
312011e25f0dSDavid C Somayajulu 			 0xf, 1, port); /* XLPORT port enable */
312111e25f0dSDavid C Somayajulu }
312211e25f0dSDavid C Somayajulu 
ecore_emul_link_init_ah_e5(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)312311e25f0dSDavid C Somayajulu static void ecore_emul_link_init_ah_e5(struct ecore_hwfn *p_hwfn,
312411e25f0dSDavid C Somayajulu 				       struct ecore_ptt *p_ptt)
312511e25f0dSDavid C Somayajulu {
312611e25f0dSDavid C Somayajulu 	u8 port = p_hwfn->port_id;
312711e25f0dSDavid C Somayajulu 	u32 mac_base = NWM_REG_MAC0_K2_E5 + (port << 2) * NWM_REG_MAC0_SIZE;
312811e25f0dSDavid C Somayajulu 
312911e25f0dSDavid C Somayajulu 	DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
313011e25f0dSDavid C Somayajulu 
313111e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, CNIG_REG_NIG_PORT0_CONF_K2_E5 + (port << 2),
313211e25f0dSDavid C Somayajulu 		 (1 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_ENABLE_0_K2_E5_SHIFT) |
313311e25f0dSDavid C Somayajulu 		 (port <<
313411e25f0dSDavid C Somayajulu 		  CNIG_REG_NIG_PORT0_CONF_NIG_PORT_NWM_PORT_MAP_0_K2_E5_SHIFT) |
313511e25f0dSDavid C Somayajulu 		 (0 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_RATE_0_K2_E5_SHIFT));
313611e25f0dSDavid C Somayajulu 
313711e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_XIF_MODE_K2_E5,
313811e25f0dSDavid C Somayajulu 		 1 << ETH_MAC_REG_XIF_MODE_XGMII_K2_E5_SHIFT);
313911e25f0dSDavid C Somayajulu 
314011e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_FRM_LENGTH_K2_E5,
314111e25f0dSDavid C Somayajulu 		 9018 << ETH_MAC_REG_FRM_LENGTH_FRM_LENGTH_K2_E5_SHIFT);
314211e25f0dSDavid C Somayajulu 
314311e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_IPG_LENGTH_K2_E5,
314411e25f0dSDavid C Somayajulu 		 0xc << ETH_MAC_REG_TX_IPG_LENGTH_TXIPG_K2_E5_SHIFT);
314511e25f0dSDavid C Somayajulu 
314611e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_RX_FIFO_SECTIONS_K2_E5,
314711e25f0dSDavid C Somayajulu 		 8 << ETH_MAC_REG_RX_FIFO_SECTIONS_RX_SECTION_FULL_K2_E5_SHIFT);
314811e25f0dSDavid C Somayajulu 
314911e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_FIFO_SECTIONS_K2_E5,
315011e25f0dSDavid C Somayajulu 		 (0xA <<
315111e25f0dSDavid C Somayajulu 		  ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_EMPTY_K2_E5_SHIFT) |
315211e25f0dSDavid C Somayajulu 		 (8 <<
315311e25f0dSDavid C Somayajulu 		  ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_FULL_K2_E5_SHIFT));
315411e25f0dSDavid C Somayajulu 
315511e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_COMMAND_CONFIG_K2_E5,
315611e25f0dSDavid C Somayajulu 		 0xa853);
315711e25f0dSDavid C Somayajulu }
315811e25f0dSDavid C Somayajulu 
ecore_emul_link_init(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)315911e25f0dSDavid C Somayajulu static void ecore_emul_link_init(struct ecore_hwfn *p_hwfn,
316011e25f0dSDavid C Somayajulu 				 struct ecore_ptt *p_ptt)
316111e25f0dSDavid C Somayajulu {
316211e25f0dSDavid C Somayajulu 	if (ECORE_IS_AH(p_hwfn->p_dev) || ECORE_IS_E5(p_hwfn->p_dev))
316311e25f0dSDavid C Somayajulu 		ecore_emul_link_init_ah_e5(p_hwfn, p_ptt);
316411e25f0dSDavid C Somayajulu 	else /* BB */
316511e25f0dSDavid C Somayajulu 		ecore_emul_link_init_bb(p_hwfn, p_ptt);
316611e25f0dSDavid C Somayajulu 
316711e25f0dSDavid C Somayajulu 	return;
316811e25f0dSDavid C Somayajulu }
316911e25f0dSDavid C Somayajulu 
ecore_link_init_bb(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 port)317011e25f0dSDavid C Somayajulu static void ecore_link_init_bb(struct ecore_hwfn *p_hwfn,
317111e25f0dSDavid C Somayajulu 			       struct ecore_ptt *p_ptt,  u8 port)
317211e25f0dSDavid C Somayajulu {
317311e25f0dSDavid C Somayajulu 	int port_offset = port ? 0x800 : 0;
317411e25f0dSDavid C Somayajulu 	u32 xmac_rxctrl	= 0;
317511e25f0dSDavid C Somayajulu 
317611e25f0dSDavid C Somayajulu 	/* Reset of XMAC */
317711e25f0dSDavid C Somayajulu 	/* FIXME: move to common start */
317811e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2*sizeof(u32),
317911e25f0dSDavid C Somayajulu 		 MISC_REG_RESET_REG_2_XMAC_BIT); /* Clear */
318011e25f0dSDavid C Somayajulu 	OSAL_MSLEEP(1);
318111e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
318211e25f0dSDavid C Somayajulu 		 MISC_REG_RESET_REG_2_XMAC_BIT); /* Set */
318311e25f0dSDavid C Somayajulu 
318411e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_CORE_PORT_MODE_BB, 1);
318511e25f0dSDavid C Somayajulu 
318611e25f0dSDavid C Somayajulu 	/* Set the number of ports on the Warp Core to 10G */
318711e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_PHY_PORT_MODE_BB, 3);
318811e25f0dSDavid C Somayajulu 
318911e25f0dSDavid C Somayajulu 	/* Soft reset of XMAC */
319011e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
319111e25f0dSDavid C Somayajulu 		 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
319211e25f0dSDavid C Somayajulu 	OSAL_MSLEEP(1);
319311e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
319411e25f0dSDavid C Somayajulu 		 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
319511e25f0dSDavid C Somayajulu 
319611e25f0dSDavid C Somayajulu 	/* FIXME: move to common end */
319711e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
319811e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, XMAC_REG_MODE_BB + port_offset, 0x20);
319911e25f0dSDavid C Somayajulu 
320011e25f0dSDavid C Somayajulu 	/* Set Max packet size: initialize XMAC block register for port 0 */
320111e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_MAX_SIZE_BB + port_offset, 0x2710);
320211e25f0dSDavid C Somayajulu 
320311e25f0dSDavid C Somayajulu 	/* CRC append for Tx packets: init XMAC block register for port 1 */
320411e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, XMAC_REG_TX_CTRL_LO_BB + port_offset, 0xC800);
320511e25f0dSDavid C Somayajulu 
320611e25f0dSDavid C Somayajulu 	/* Enable TX and RX: initialize XMAC block register for port 1 */
320711e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, XMAC_REG_CTRL_BB + port_offset,
320811e25f0dSDavid C Somayajulu 		 XMAC_REG_CTRL_TX_EN_BB | XMAC_REG_CTRL_RX_EN_BB);
320911e25f0dSDavid C Somayajulu 	xmac_rxctrl = ecore_rd(p_hwfn, p_ptt,
321011e25f0dSDavid C Somayajulu 			       XMAC_REG_RX_CTRL_BB + port_offset);
321111e25f0dSDavid C Somayajulu 	xmac_rxctrl |= XMAC_REG_RX_CTRL_PROCESS_VARIABLE_PREAMBLE_BB;
321211e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_CTRL_BB + port_offset, xmac_rxctrl);
321311e25f0dSDavid C Somayajulu }
321411e25f0dSDavid C Somayajulu #endif
321511e25f0dSDavid C Somayajulu 
321611e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_hw_init_dpi_size(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 pwm_region_size,u32 n_cpus)321711e25f0dSDavid C Somayajulu ecore_hw_init_dpi_size(struct ecore_hwfn *p_hwfn,
321811e25f0dSDavid C Somayajulu 		       struct ecore_ptt *p_ptt,
321911e25f0dSDavid C Somayajulu 		       u32 pwm_region_size,
322011e25f0dSDavid C Somayajulu 		       u32 n_cpus)
322111e25f0dSDavid C Somayajulu {
3222*217ec208SDavid C Somayajulu 	u32 dpi_bit_shift, dpi_count, dpi_page_size;
322311e25f0dSDavid C Somayajulu 	u32 min_dpis;
3224*217ec208SDavid C Somayajulu 	u32 n_wids;
322511e25f0dSDavid C Somayajulu 
322611e25f0dSDavid C Somayajulu 	/* Calculate DPI size
322711e25f0dSDavid C Somayajulu 	 * ------------------
322811e25f0dSDavid C Somayajulu 	 * The PWM region contains Doorbell Pages. The first is reserverd for
322911e25f0dSDavid C Somayajulu 	 * the kernel for, e.g, L2. The others are free to be used by non-
323011e25f0dSDavid C Somayajulu 	 * trusted applications, typically from user space. Each page, called a
323111e25f0dSDavid C Somayajulu 	 * doorbell page is sectioned into windows that allow doorbells to be
323211e25f0dSDavid C Somayajulu 	 * issued in parallel by the kernel/application. The size of such a
323311e25f0dSDavid C Somayajulu 	 * window (a.k.a. WID) is 1kB.
323411e25f0dSDavid C Somayajulu 	 * Summary:
323511e25f0dSDavid C Somayajulu 	 *    1kB WID x N WIDS = DPI page size
323611e25f0dSDavid C Somayajulu 	 *    DPI page size x N DPIs = PWM region size
323711e25f0dSDavid C Somayajulu 	 * Notes:
323811e25f0dSDavid C Somayajulu 	 * The size of the DPI page size must be in multiples of OSAL_PAGE_SIZE
323911e25f0dSDavid C Somayajulu 	 * in order to ensure that two applications won't share the same page.
324011e25f0dSDavid C Somayajulu 	 * It also must contain at least one WID per CPU to allow parallelism.
324111e25f0dSDavid C Somayajulu 	 * It also must be a power of 2, since it is stored as a bit shift.
324211e25f0dSDavid C Somayajulu 	 *
324311e25f0dSDavid C Somayajulu 	 * The DPI page size is stored in a register as 'dpi_bit_shift' so that
324411e25f0dSDavid C Somayajulu 	 * 0 is 4kB, 1 is 8kB and etc. Hence the minimum size is 4,096
324511e25f0dSDavid C Somayajulu 	 * containing 4 WIDs.
324611e25f0dSDavid C Somayajulu 	 */
3247*217ec208SDavid C Somayajulu 	n_wids = OSAL_MAX_T(u32, ECORE_MIN_WIDS, n_cpus);
3248*217ec208SDavid C Somayajulu 	dpi_page_size = ECORE_WID_SIZE * OSAL_ROUNDUP_POW_OF_TWO(n_wids);
32499efd0ba7SDavid C Somayajulu 	dpi_page_size = (dpi_page_size + OSAL_PAGE_SIZE - 1) & ~(OSAL_PAGE_SIZE - 1);
325011e25f0dSDavid C Somayajulu 	dpi_bit_shift = OSAL_LOG2(dpi_page_size / 4096);
325111e25f0dSDavid C Somayajulu 	dpi_count = pwm_region_size / dpi_page_size;
325211e25f0dSDavid C Somayajulu 
325311e25f0dSDavid C Somayajulu 	min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
325411e25f0dSDavid C Somayajulu 	min_dpis = OSAL_MAX_T(u32, ECORE_MIN_DPIS, min_dpis);
325511e25f0dSDavid C Somayajulu 
325611e25f0dSDavid C Somayajulu 	/* Update hwfn */
325711e25f0dSDavid C Somayajulu 	p_hwfn->dpi_size = dpi_page_size;
325811e25f0dSDavid C Somayajulu 	p_hwfn->dpi_count = dpi_count;
325911e25f0dSDavid C Somayajulu 
326011e25f0dSDavid C Somayajulu 	/* Update registers */
326111e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
326211e25f0dSDavid C Somayajulu 
326311e25f0dSDavid C Somayajulu 	if (dpi_count < min_dpis)
326411e25f0dSDavid C Somayajulu 		return ECORE_NORESOURCES;
326511e25f0dSDavid C Somayajulu 
326611e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
326711e25f0dSDavid C Somayajulu }
326811e25f0dSDavid C Somayajulu 
326911e25f0dSDavid C Somayajulu enum ECORE_ROCE_EDPM_MODE {
327011e25f0dSDavid C Somayajulu 	ECORE_ROCE_EDPM_MODE_ENABLE	= 0,
327111e25f0dSDavid C Somayajulu 	ECORE_ROCE_EDPM_MODE_FORCE_ON	= 1,
327211e25f0dSDavid C Somayajulu 	ECORE_ROCE_EDPM_MODE_DISABLE	= 2,
327311e25f0dSDavid C Somayajulu };
327411e25f0dSDavid C Somayajulu 
327511e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_hw_init_pf_doorbell_bar(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)327611e25f0dSDavid C Somayajulu ecore_hw_init_pf_doorbell_bar(struct ecore_hwfn *p_hwfn,
327711e25f0dSDavid C Somayajulu 			      struct ecore_ptt *p_ptt)
327811e25f0dSDavid C Somayajulu {
3279*217ec208SDavid C Somayajulu 	struct ecore_rdma_pf_params *p_rdma_pf_params;
328011e25f0dSDavid C Somayajulu 	u32 pwm_regsize, norm_regsize;
328111e25f0dSDavid C Somayajulu 	u32 non_pwm_conn, min_addr_reg1;
328211e25f0dSDavid C Somayajulu 	u32 db_bar_size, n_cpus = 1;
328311e25f0dSDavid C Somayajulu 	u32 roce_edpm_mode;
328411e25f0dSDavid C Somayajulu 	u32 pf_dems_shift;
328511e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
328611e25f0dSDavid C Somayajulu 	u8 cond;
328711e25f0dSDavid C Somayajulu 
32889efd0ba7SDavid C Somayajulu 	db_bar_size = ecore_hw_bar_size(p_hwfn, p_ptt, BAR_ID_1);
3289*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_hwfn->p_dev))
329011e25f0dSDavid C Somayajulu 		db_bar_size /= 2;
329111e25f0dSDavid C Somayajulu 
329211e25f0dSDavid C Somayajulu 	/* Calculate doorbell regions
329311e25f0dSDavid C Somayajulu 	 * -----------------------------------
329411e25f0dSDavid C Somayajulu 	 * The doorbell BAR is made of two regions. The first is called normal
329511e25f0dSDavid C Somayajulu 	 * region and the second is called PWM region. In the normal region
329611e25f0dSDavid C Somayajulu 	 * each ICID has its own set of addresses so that writing to that
329711e25f0dSDavid C Somayajulu 	 * specific address identifies the ICID. In the Process Window Mode
329811e25f0dSDavid C Somayajulu 	 * region the ICID is given in the data written to the doorbell. The
329911e25f0dSDavid C Somayajulu 	 * above per PF register denotes the offset in the doorbell BAR in which
330011e25f0dSDavid C Somayajulu 	 * the PWM region begins.
330111e25f0dSDavid C Somayajulu 	 * The normal region has ECORE_PF_DEMS_SIZE bytes per ICID, that is per
330211e25f0dSDavid C Somayajulu 	 * non-PWM connection. The calculation below computes the total non-PWM
330311e25f0dSDavid C Somayajulu 	 * connections. The DORQ_REG_PF_MIN_ADDR_REG1 register is
330411e25f0dSDavid C Somayajulu 	 * in units of 4,096 bytes.
330511e25f0dSDavid C Somayajulu 	 */
330611e25f0dSDavid C Somayajulu 	non_pwm_conn = ecore_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
330711e25f0dSDavid C Somayajulu 		       ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
330811e25f0dSDavid C Somayajulu 						     OSAL_NULL) +
330911e25f0dSDavid C Somayajulu 		       ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
331011e25f0dSDavid C Somayajulu 						     OSAL_NULL);
33119efd0ba7SDavid C Somayajulu 	norm_regsize = ROUNDUP(ECORE_PF_DEMS_SIZE * non_pwm_conn, OSAL_PAGE_SIZE);
331211e25f0dSDavid C Somayajulu 	min_addr_reg1 = norm_regsize / 4096;
331311e25f0dSDavid C Somayajulu 	pwm_regsize = db_bar_size - norm_regsize;
331411e25f0dSDavid C Somayajulu 
331511e25f0dSDavid C Somayajulu 	/* Check that the normal and PWM sizes are valid */
331611e25f0dSDavid C Somayajulu 	if (db_bar_size < norm_regsize) {
3317*217ec208SDavid C Somayajulu 		DP_ERR(p_hwfn->p_dev,
3318*217ec208SDavid C Somayajulu 		       "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
3319*217ec208SDavid C Somayajulu 		       db_bar_size, norm_regsize);
332011e25f0dSDavid C Somayajulu 		return ECORE_NORESOURCES;
332111e25f0dSDavid C Somayajulu 	}
332211e25f0dSDavid C Somayajulu 	if (pwm_regsize < ECORE_MIN_PWM_REGION) {
3323*217ec208SDavid C Somayajulu 		DP_ERR(p_hwfn->p_dev,
3324*217ec208SDavid C Somayajulu 		       "PWM region size 0x%0x is too small. Should be at least 0x%0x (Doorbell BAR size is 0x%x and normal region size is 0x%0x)\n",
3325*217ec208SDavid C Somayajulu 		       pwm_regsize, ECORE_MIN_PWM_REGION, db_bar_size,
3326*217ec208SDavid C Somayajulu 		       norm_regsize);
332711e25f0dSDavid C Somayajulu 		return ECORE_NORESOURCES;
332811e25f0dSDavid C Somayajulu 	}
332911e25f0dSDavid C Somayajulu 
3330*217ec208SDavid C Somayajulu 	p_rdma_pf_params = &p_hwfn->pf_params.rdma_pf_params;
3331*217ec208SDavid C Somayajulu 
333211e25f0dSDavid C Somayajulu 	/* Calculate number of DPIs */
3333*217ec208SDavid C Somayajulu 	if (ECORE_IS_IWARP_PERSONALITY(p_hwfn))
3334*217ec208SDavid C Somayajulu 		p_rdma_pf_params->roce_edpm_mode =  ECORE_ROCE_EDPM_MODE_DISABLE;
3335*217ec208SDavid C Somayajulu 
3336*217ec208SDavid C Somayajulu 	if (p_rdma_pf_params->roce_edpm_mode <= ECORE_ROCE_EDPM_MODE_DISABLE) {
3337*217ec208SDavid C Somayajulu 		roce_edpm_mode = p_rdma_pf_params->roce_edpm_mode;
3338*217ec208SDavid C Somayajulu 	} else {
3339*217ec208SDavid C Somayajulu 		DP_ERR(p_hwfn->p_dev,
3340*217ec208SDavid C Somayajulu 		       "roce edpm mode was configured to an illegal value of %u. Resetting it to 0-Enable EDPM if BAR size is adequate\n",
3341*217ec208SDavid C Somayajulu 		       p_rdma_pf_params->roce_edpm_mode);
3342*217ec208SDavid C Somayajulu 		roce_edpm_mode = 0;
3343*217ec208SDavid C Somayajulu 	}
3344*217ec208SDavid C Somayajulu 
334511e25f0dSDavid C Somayajulu 	if ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE) ||
334611e25f0dSDavid C Somayajulu 	    ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_FORCE_ON))) {
334711e25f0dSDavid C Somayajulu 		/* Either EDPM is mandatory, or we are attempting to allocate a
334811e25f0dSDavid C Somayajulu 		 * WID per CPU.
334911e25f0dSDavid C Somayajulu 		 */
33509efd0ba7SDavid C Somayajulu 		n_cpus = OSAL_NUM_CPUS();
335111e25f0dSDavid C Somayajulu 		rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
335211e25f0dSDavid C Somayajulu 	}
335311e25f0dSDavid C Somayajulu 
335411e25f0dSDavid C Somayajulu 	cond = ((rc != ECORE_SUCCESS) &&
335511e25f0dSDavid C Somayajulu 		(roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE)) ||
335611e25f0dSDavid C Somayajulu 		(roce_edpm_mode == ECORE_ROCE_EDPM_MODE_DISABLE);
335711e25f0dSDavid C Somayajulu 	if (cond || p_hwfn->dcbx_no_edpm) {
335811e25f0dSDavid C Somayajulu 		/* Either EDPM is disabled from user configuration, or it is
335911e25f0dSDavid C Somayajulu 		 * disabled via DCBx, or it is not mandatory and we failed to
336011e25f0dSDavid C Somayajulu 		 * allocated a WID per CPU.
336111e25f0dSDavid C Somayajulu 		 */
336211e25f0dSDavid C Somayajulu 		n_cpus = 1;
336311e25f0dSDavid C Somayajulu 		rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
336411e25f0dSDavid C Somayajulu 
336511e25f0dSDavid C Somayajulu #ifdef CONFIG_ECORE_ROCE
336611e25f0dSDavid C Somayajulu 		/* If we entered this flow due to DCBX then the DPM register is
336711e25f0dSDavid C Somayajulu 		 * already configured.
336811e25f0dSDavid C Somayajulu 		 */
336911e25f0dSDavid C Somayajulu 		if (cond)
337011e25f0dSDavid C Somayajulu 			ecore_rdma_dpm_bar(p_hwfn, p_ptt);
337111e25f0dSDavid C Somayajulu #endif
337211e25f0dSDavid C Somayajulu 	}
337311e25f0dSDavid C Somayajulu 
337411e25f0dSDavid C Somayajulu 	p_hwfn->wid_count = (u16)n_cpus;
337511e25f0dSDavid C Somayajulu 
337611e25f0dSDavid C Somayajulu 	/* Check return codes from above calls */
337711e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS) {
33789efd0ba7SDavid C Somayajulu #ifndef LINUX_REMOVE
337911e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn,
3380*217ec208SDavid C Somayajulu 		       "Failed to allocate enough DPIs. Allocated %d but the current minimum is set to %d. You can reduce this minimum down to %d via user configuration min_dpis or by disabling EDPM via user configuration roce_edpm_mode\n",
3381*217ec208SDavid C Somayajulu 		       p_hwfn->dpi_count, p_rdma_pf_params->min_dpis,
338211e25f0dSDavid C Somayajulu 		       ECORE_MIN_DPIS);
33839efd0ba7SDavid C Somayajulu #else
33849efd0ba7SDavid C Somayajulu 		DP_ERR(p_hwfn,
3385*217ec208SDavid C Somayajulu 		       "Failed to allocate enough DPIs. Allocated %d but the current minimum is set to %d. You can reduce this minimum down to %d via the module parameter min_rdma_dpis or by disabling EDPM by setting the module parameter roce_edpm to 2\n",
3386*217ec208SDavid C Somayajulu 		       p_hwfn->dpi_count, p_rdma_pf_params->min_dpis,
33879efd0ba7SDavid C Somayajulu 		       ECORE_MIN_DPIS);
33889efd0ba7SDavid C Somayajulu #endif
3389*217ec208SDavid C Somayajulu 		DP_ERR(p_hwfn,
3390*217ec208SDavid C Somayajulu 		       "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s, page_size=%lu\n",
3391*217ec208SDavid C Somayajulu 		       norm_regsize, pwm_regsize, p_hwfn->dpi_size,
3392*217ec208SDavid C Somayajulu 		       p_hwfn->dpi_count,
3393*217ec208SDavid C Somayajulu 		       ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
3394*217ec208SDavid C Somayajulu 		       "disabled" : "enabled", (unsigned long)OSAL_PAGE_SIZE);
3395*217ec208SDavid C Somayajulu 
339611e25f0dSDavid C Somayajulu 		return ECORE_NORESOURCES;
339711e25f0dSDavid C Somayajulu 	}
339811e25f0dSDavid C Somayajulu 
3399*217ec208SDavid C Somayajulu 	DP_INFO(p_hwfn,
3400*217ec208SDavid C Somayajulu 		"doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s, page_size=%lu\n",
3401*217ec208SDavid C Somayajulu 		norm_regsize, pwm_regsize, p_hwfn->dpi_size, p_hwfn->dpi_count,
3402*217ec208SDavid C Somayajulu 		((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
3403*217ec208SDavid C Somayajulu 		"disabled" : "enabled", (unsigned long)OSAL_PAGE_SIZE);
3404*217ec208SDavid C Somayajulu 
340511e25f0dSDavid C Somayajulu 	/* Update hwfn */
340611e25f0dSDavid C Somayajulu 	p_hwfn->dpi_start_offset = norm_regsize; /* this is later used to
340711e25f0dSDavid C Somayajulu 						      * calculate the doorbell
340811e25f0dSDavid C Somayajulu 						      * address
340911e25f0dSDavid C Somayajulu 						      */
341011e25f0dSDavid C Somayajulu 
341111e25f0dSDavid C Somayajulu 	/* Update registers */
341211e25f0dSDavid C Somayajulu 	/* DEMS size is configured log2 of DWORDs, hence the division by 4 */
341311e25f0dSDavid C Somayajulu 	pf_dems_shift = OSAL_LOG2(ECORE_PF_DEMS_SIZE / 4);
341411e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
341511e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
341611e25f0dSDavid C Somayajulu 
341711e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
341811e25f0dSDavid C Somayajulu }
341911e25f0dSDavid C Somayajulu 
ecore_hw_init_port(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,int hw_mode)342011e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_hw_init_port(struct ecore_hwfn *p_hwfn,
342111e25f0dSDavid C Somayajulu 					       struct ecore_ptt *p_ptt,
342211e25f0dSDavid C Somayajulu 					       int hw_mode)
342311e25f0dSDavid C Somayajulu {
342411e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc	= ECORE_SUCCESS;
342511e25f0dSDavid C Somayajulu 
3426*217ec208SDavid C Somayajulu 	/* In CMT the gate should be cleared by the 2nd hwfn */
3427*217ec208SDavid C Somayajulu 	if (!ECORE_IS_CMT(p_hwfn->p_dev) || !IS_LEAD_HWFN(p_hwfn))
3428*217ec208SDavid C Somayajulu 		STORE_RT_REG(p_hwfn, NIG_REG_BRB_GATE_DNTFWD_PORT_RT_OFFSET, 0);
3429*217ec208SDavid C Somayajulu 
343011e25f0dSDavid C Somayajulu 	rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
343111e25f0dSDavid C Somayajulu 			    hw_mode);
343211e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
343311e25f0dSDavid C Somayajulu 		return rc;
34349efd0ba7SDavid C Somayajulu 
34359efd0ba7SDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_MASTER_WRITE_PAD_ENABLE, 0);
34369efd0ba7SDavid C Somayajulu 
343711e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
343811e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_ASIC(p_hwfn->p_dev))
343911e25f0dSDavid C Somayajulu 		return ECORE_SUCCESS;
344011e25f0dSDavid C Somayajulu 
344111e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
344211e25f0dSDavid C Somayajulu 		if (ECORE_IS_AH(p_hwfn->p_dev))
344311e25f0dSDavid C Somayajulu 			return ECORE_SUCCESS;
344411e25f0dSDavid C Somayajulu 		else if (ECORE_IS_BB(p_hwfn->p_dev))
344511e25f0dSDavid C Somayajulu 			ecore_link_init_bb(p_hwfn, p_ptt, p_hwfn->port_id);
344611e25f0dSDavid C Somayajulu 		else /* E5 */
344711e25f0dSDavid C Somayajulu 			ECORE_E5_MISSING_CODE;
344811e25f0dSDavid C Somayajulu 	} else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
3449*217ec208SDavid C Somayajulu 		if (ECORE_IS_CMT(p_hwfn->p_dev)) {
345011e25f0dSDavid C Somayajulu 			/* Activate OPTE in CMT */
345111e25f0dSDavid C Somayajulu 			u32 val;
345211e25f0dSDavid C Somayajulu 
345311e25f0dSDavid C Somayajulu 			val = ecore_rd(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV);
345411e25f0dSDavid C Somayajulu 			val |= 0x10;
345511e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV, val);
345611e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, MISC_REG_CLK_100G_MODE, 1);
345711e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, MISCS_REG_CLK_100G_MODE, 1);
345811e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, MISC_REG_OPTE_MODE, 1);
345911e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt,
346011e25f0dSDavid C Somayajulu 				 NIG_REG_LLH_ENG_CLS_TCP_4_TUPLE_SEARCH, 1);
346111e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt,
346211e25f0dSDavid C Somayajulu 				 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL, 0x55555555);
346311e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt,
346411e25f0dSDavid C Somayajulu 				 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL + 0x4,
346511e25f0dSDavid C Somayajulu 				 0x55555555);
346611e25f0dSDavid C Somayajulu 		}
346711e25f0dSDavid C Somayajulu 
346811e25f0dSDavid C Somayajulu 		ecore_emul_link_init(p_hwfn, p_ptt);
346911e25f0dSDavid C Somayajulu 	} else {
347011e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn->p_dev, "link is not being configured\n");
347111e25f0dSDavid C Somayajulu 	}
347211e25f0dSDavid C Somayajulu #endif
347311e25f0dSDavid C Somayajulu 
347411e25f0dSDavid C Somayajulu 	return rc;
347511e25f0dSDavid C Somayajulu }
347611e25f0dSDavid C Somayajulu 
3477*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_hw_init_pf(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,int hw_mode,struct ecore_hw_init_params * p_params)3478*217ec208SDavid C Somayajulu ecore_hw_init_pf(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3479*217ec208SDavid C Somayajulu 		 int hw_mode, struct ecore_hw_init_params *p_params)
348011e25f0dSDavid C Somayajulu {
348111e25f0dSDavid C Somayajulu 	u8 rel_pf_id = p_hwfn->rel_pf_id;
348211e25f0dSDavid C Somayajulu 	u32 prs_reg;
348311e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc	= ECORE_SUCCESS;
348411e25f0dSDavid C Somayajulu 	u16 ctrl;
348511e25f0dSDavid C Somayajulu 	int pos;
348611e25f0dSDavid C Somayajulu 
348711e25f0dSDavid C Somayajulu 	if (p_hwfn->mcp_info) {
348811e25f0dSDavid C Somayajulu 		struct ecore_mcp_function_info *p_info;
348911e25f0dSDavid C Somayajulu 
349011e25f0dSDavid C Somayajulu 		p_info = &p_hwfn->mcp_info->func_info;
349111e25f0dSDavid C Somayajulu 		if (p_info->bandwidth_min)
349211e25f0dSDavid C Somayajulu 			p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
349311e25f0dSDavid C Somayajulu 
349411e25f0dSDavid C Somayajulu 		/* Update rate limit once we'll actually have a link */
349511e25f0dSDavid C Somayajulu 		p_hwfn->qm_info.pf_rl = 100000;
349611e25f0dSDavid C Somayajulu 	}
34979efd0ba7SDavid C Somayajulu 	ecore_cxt_hw_init_pf(p_hwfn, p_ptt);
349811e25f0dSDavid C Somayajulu 
349911e25f0dSDavid C Somayajulu 	ecore_int_igu_init_rt(p_hwfn);
350011e25f0dSDavid C Somayajulu 
350111e25f0dSDavid C Somayajulu 	/* Set VLAN in NIG if needed */
350211e25f0dSDavid C Somayajulu 	if (hw_mode & (1 << MODE_MF_SD)) {
350311e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "Configuring LLH_FUNC_TAG\n");
350411e25f0dSDavid C Somayajulu 		STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
350511e25f0dSDavid C Somayajulu 		STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
350611e25f0dSDavid C Somayajulu 			     p_hwfn->hw_info.ovlan);
3507*217ec208SDavid C Somayajulu 
3508*217ec208SDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
3509*217ec208SDavid C Somayajulu 			   "Configuring LLH_FUNC_FILTER_HDR_SEL\n");
3510*217ec208SDavid C Somayajulu 		STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_FILTER_HDR_SEL_RT_OFFSET,
3511*217ec208SDavid C Somayajulu 			     1);
351211e25f0dSDavid C Somayajulu 	}
351311e25f0dSDavid C Somayajulu 
351411e25f0dSDavid C Somayajulu 	/* Enable classification by MAC if needed */
351511e25f0dSDavid C Somayajulu 	if (hw_mode & (1 << MODE_MF_SI)) {
351611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "Configuring TAGMAC_CLS_TYPE\n");
351711e25f0dSDavid C Somayajulu 		STORE_RT_REG(p_hwfn,
351811e25f0dSDavid C Somayajulu 			     NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
351911e25f0dSDavid C Somayajulu 	}
352011e25f0dSDavid C Somayajulu 
352111e25f0dSDavid C Somayajulu 	/* Protocl Configuration  - @@@TBD - should we set 0 otherwise?*/
352211e25f0dSDavid C Somayajulu 	STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
352311e25f0dSDavid C Somayajulu 		     (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) ? 1 : 0);
352411e25f0dSDavid C Somayajulu 	STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
352511e25f0dSDavid C Somayajulu 		     (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) ? 1 : 0);
352611e25f0dSDavid C Somayajulu 	STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
352711e25f0dSDavid C Somayajulu 
352811e25f0dSDavid C Somayajulu 	/* perform debug configuration when chip is out of reset */
352911e25f0dSDavid C Somayajulu 	OSAL_BEFORE_PF_START((void *)p_hwfn->p_dev, p_hwfn->my_id);
353011e25f0dSDavid C Somayajulu 
3531*217ec208SDavid C Somayajulu 	/* Sanity check before the PF init sequence that uses DMAE */
3532*217ec208SDavid C Somayajulu 	rc = ecore_dmae_sanity(p_hwfn, p_ptt, "pf_phase");
3533*217ec208SDavid C Somayajulu 	if (rc)
353411e25f0dSDavid C Somayajulu 		return rc;
353511e25f0dSDavid C Somayajulu 
353611e25f0dSDavid C Somayajulu 	/* PF Init sequence */
353711e25f0dSDavid C Somayajulu 	rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
353811e25f0dSDavid C Somayajulu 	if (rc)
353911e25f0dSDavid C Somayajulu 		return rc;
354011e25f0dSDavid C Somayajulu 
354111e25f0dSDavid C Somayajulu 	/* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
354211e25f0dSDavid C Somayajulu 	rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
354311e25f0dSDavid C Somayajulu 	if (rc)
354411e25f0dSDavid C Somayajulu 		return rc;
354511e25f0dSDavid C Somayajulu 
354611e25f0dSDavid C Somayajulu 	/* Pure runtime initializations - directly to the HW  */
354711e25f0dSDavid C Somayajulu 	ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
354811e25f0dSDavid C Somayajulu 
3549*217ec208SDavid C Somayajulu 	/* PCI relaxed ordering is generally beneficial for performance,
3550*217ec208SDavid C Somayajulu 	 * but can hurt performance or lead to instability on some setups.
3551*217ec208SDavid C Somayajulu 	 * If management FW is taking care of it go with that, otherwise
3552*217ec208SDavid C Somayajulu 	 * disable to be on the safe side.
355311e25f0dSDavid C Somayajulu 	 */
355411e25f0dSDavid C Somayajulu 	pos = OSAL_PCI_FIND_CAPABILITY(p_hwfn->p_dev, PCI_CAP_ID_EXP);
355511e25f0dSDavid C Somayajulu 	if (!pos) {
355611e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true,
355711e25f0dSDavid C Somayajulu 			  "Failed to find the PCI Express Capability structure in the PCI config space\n");
355811e25f0dSDavid C Somayajulu 		return ECORE_IO;
355911e25f0dSDavid C Somayajulu 	}
3560*217ec208SDavid C Somayajulu 
356111e25f0dSDavid C Somayajulu 	OSAL_PCI_READ_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, &ctrl);
3562*217ec208SDavid C Somayajulu 
3563*217ec208SDavid C Somayajulu 	if (p_params->pci_rlx_odr_mode == ECORE_ENABLE_RLX_ODR) {
3564*217ec208SDavid C Somayajulu 		ctrl |= PCI_EXP_DEVCTL_RELAX_EN;
3565*217ec208SDavid C Somayajulu 		OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev,
3566*217ec208SDavid C Somayajulu 					   pos + PCI_EXP_DEVCTL, ctrl);
3567*217ec208SDavid C Somayajulu 	} else if (p_params->pci_rlx_odr_mode == ECORE_DISABLE_RLX_ODR) {
356811e25f0dSDavid C Somayajulu 		ctrl &= ~PCI_EXP_DEVCTL_RELAX_EN;
3569*217ec208SDavid C Somayajulu 		OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev,
3570*217ec208SDavid C Somayajulu 					   pos + PCI_EXP_DEVCTL, ctrl);
3571*217ec208SDavid C Somayajulu 	} else if (ecore_mcp_rlx_odr_supported(p_hwfn)) {
3572*217ec208SDavid C Somayajulu 		DP_INFO(p_hwfn, "PCI relax ordering configured by MFW\n");
3573*217ec208SDavid C Somayajulu 	} else {
3574*217ec208SDavid C Somayajulu 		ctrl &= ~PCI_EXP_DEVCTL_RELAX_EN;
3575*217ec208SDavid C Somayajulu 		OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev,
3576*217ec208SDavid C Somayajulu 					   pos + PCI_EXP_DEVCTL, ctrl);
3577*217ec208SDavid C Somayajulu 	}
357811e25f0dSDavid C Somayajulu 
357911e25f0dSDavid C Somayajulu 	rc = ecore_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
358003b856d6SDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
3581*217ec208SDavid C Somayajulu 		return rc;
3582*217ec208SDavid C Somayajulu 
3583*217ec208SDavid C Somayajulu 	/* Use the leading hwfn since in CMT only NIG #0 is operational */
3584*217ec208SDavid C Somayajulu 	if (IS_LEAD_HWFN(p_hwfn)) {
3585*217ec208SDavid C Somayajulu 		rc = ecore_llh_hw_init_pf(p_hwfn, p_ptt,
3586*217ec208SDavid C Somayajulu 					  p_params->avoid_eng_affin);
3587*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
3588*217ec208SDavid C Somayajulu 			return rc;
358903b856d6SDavid C Somayajulu 	}
359003b856d6SDavid C Somayajulu 
3591*217ec208SDavid C Somayajulu 	if (p_params->b_hw_start) {
359211e25f0dSDavid C Somayajulu 		/* enable interrupts */
3593*217ec208SDavid C Somayajulu 		rc = ecore_int_igu_enable(p_hwfn, p_ptt, p_params->int_mode);
359411e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
359511e25f0dSDavid C Somayajulu 			return rc;
359611e25f0dSDavid C Somayajulu 
359711e25f0dSDavid C Somayajulu 		/* send function start command */
3598*217ec208SDavid C Somayajulu 		rc = ecore_sp_pf_start(p_hwfn, p_ptt, p_params->p_tunn,
3599*217ec208SDavid C Somayajulu 				       p_params->allow_npar_tx_switch);
360011e25f0dSDavid C Somayajulu 		if (rc) {
360111e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, true, "Function start ramrod failed\n");
3602*217ec208SDavid C Somayajulu 			return rc;
3603*217ec208SDavid C Somayajulu 		}
360411e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
360511e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
360611e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
360711e25f0dSDavid C Somayajulu 
360811e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE)
360911e25f0dSDavid C Somayajulu 		{
361011e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1,
361111e25f0dSDavid C Somayajulu 					(1 << 2));
361211e25f0dSDavid C Somayajulu 			ecore_wr(p_hwfn, p_ptt,
361311e25f0dSDavid C Somayajulu 					PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
361411e25f0dSDavid C Somayajulu 					0x100);
361511e25f0dSDavid C Somayajulu 		}
361611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
361711e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH registers after start PFn\n");
361811e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP);
361911e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
362011e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_TCP: %x\n", prs_reg);
362111e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP);
362211e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
362311e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_UDP: %x\n", prs_reg);
362411e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE);
362511e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
362611e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_FCOE: %x\n", prs_reg);
362711e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE);
362811e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
362911e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_ROCE: %x\n", prs_reg);
363011e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt,
363111e25f0dSDavid C Somayajulu 				PRS_REG_SEARCH_TCP_FIRST_FRAG);
363211e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
363311e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_TCP_FIRST_FRAG: %x\n",
363411e25f0dSDavid C Somayajulu 				prs_reg);
363511e25f0dSDavid C Somayajulu 		prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
363611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
363711e25f0dSDavid C Somayajulu 				"PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
363811e25f0dSDavid C Somayajulu 	}
3639*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
364011e25f0dSDavid C Somayajulu }
364111e25f0dSDavid C Somayajulu 
ecore_pglueb_set_pfid_enable(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,bool b_enable)3642*217ec208SDavid C Somayajulu enum _ecore_status_t ecore_pglueb_set_pfid_enable(struct ecore_hwfn *p_hwfn,
364311e25f0dSDavid C Somayajulu 						  struct ecore_ptt *p_ptt,
3644*217ec208SDavid C Somayajulu 						  bool b_enable)
364511e25f0dSDavid C Somayajulu {
3646*217ec208SDavid C Somayajulu 	u32 delay_idx = 0, val, set_val = b_enable ? 1 : 0;
364711e25f0dSDavid C Somayajulu 
3648*217ec208SDavid C Somayajulu 	/* Configure the PF's internal FID_enable for master transactions */
364911e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt,
365011e25f0dSDavid C Somayajulu 		 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
365111e25f0dSDavid C Somayajulu 
3652*217ec208SDavid C Somayajulu 	/* Wait until value is set - try for 1 second every 50us */
365311e25f0dSDavid C Somayajulu 	for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
365411e25f0dSDavid C Somayajulu 		val = ecore_rd(p_hwfn, p_ptt,
365511e25f0dSDavid C Somayajulu 			       PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
365611e25f0dSDavid C Somayajulu 		if (val == set_val)
365711e25f0dSDavid C Somayajulu 			break;
365811e25f0dSDavid C Somayajulu 
365911e25f0dSDavid C Somayajulu 		OSAL_UDELAY(50);
366011e25f0dSDavid C Somayajulu 	}
366111e25f0dSDavid C Somayajulu 
366211e25f0dSDavid C Somayajulu 	if (val != set_val) {
366311e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true,
366411e25f0dSDavid C Somayajulu 			  "PFID_ENABLE_MASTER wasn't changed after a second\n");
366511e25f0dSDavid C Somayajulu 		return ECORE_UNKNOWN_ERROR;
366611e25f0dSDavid C Somayajulu 	}
366711e25f0dSDavid C Somayajulu 
366811e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
366911e25f0dSDavid C Somayajulu }
367011e25f0dSDavid C Somayajulu 
ecore_reset_mb_shadow(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_main_ptt)367111e25f0dSDavid C Somayajulu static void ecore_reset_mb_shadow(struct ecore_hwfn *p_hwfn,
367211e25f0dSDavid C Somayajulu 			struct ecore_ptt *p_main_ptt)
367311e25f0dSDavid C Somayajulu {
367411e25f0dSDavid C Somayajulu 	/* Read shadow of current MFW mailbox */
367511e25f0dSDavid C Somayajulu 	ecore_mcp_read_mb(p_hwfn, p_main_ptt);
367611e25f0dSDavid C Somayajulu 	OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
367711e25f0dSDavid C Somayajulu 		    p_hwfn->mcp_info->mfw_mb_cur,
367811e25f0dSDavid C Somayajulu 		    p_hwfn->mcp_info->mfw_mb_length);
367911e25f0dSDavid C Somayajulu }
368011e25f0dSDavid C Somayajulu 
3681*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_fill_load_req_params(struct ecore_hwfn * p_hwfn,struct ecore_load_req_params * p_load_req,struct ecore_drv_load_params * p_drv_load)3682*217ec208SDavid C Somayajulu ecore_fill_load_req_params(struct ecore_hwfn *p_hwfn,
3683*217ec208SDavid C Somayajulu 			   struct ecore_load_req_params *p_load_req,
3684*217ec208SDavid C Somayajulu 			   struct ecore_drv_load_params *p_drv_load)
3685*217ec208SDavid C Somayajulu {
3686*217ec208SDavid C Somayajulu 	/* Make sure that if ecore-client didn't provide inputs, all the
3687*217ec208SDavid C Somayajulu 	 * expected defaults are indeed zero.
3688*217ec208SDavid C Somayajulu 	 */
3689*217ec208SDavid C Somayajulu 	OSAL_BUILD_BUG_ON(ECORE_DRV_ROLE_OS != 0);
3690*217ec208SDavid C Somayajulu 	OSAL_BUILD_BUG_ON(ECORE_LOAD_REQ_LOCK_TO_DEFAULT != 0);
3691*217ec208SDavid C Somayajulu 	OSAL_BUILD_BUG_ON(ECORE_OVERRIDE_FORCE_LOAD_NONE != 0);
3692*217ec208SDavid C Somayajulu 
3693*217ec208SDavid C Somayajulu 	OSAL_MEM_ZERO(p_load_req, sizeof(*p_load_req));
3694*217ec208SDavid C Somayajulu 
3695*217ec208SDavid C Somayajulu 	if (p_drv_load == OSAL_NULL)
3696*217ec208SDavid C Somayajulu 		goto out;
3697*217ec208SDavid C Somayajulu 
3698*217ec208SDavid C Somayajulu 	p_load_req->drv_role = p_drv_load->is_crash_kernel ?
3699*217ec208SDavid C Somayajulu 			       ECORE_DRV_ROLE_KDUMP :
3700*217ec208SDavid C Somayajulu 			       ECORE_DRV_ROLE_OS;
3701*217ec208SDavid C Somayajulu 	p_load_req->avoid_eng_reset = p_drv_load->avoid_eng_reset;
3702*217ec208SDavid C Somayajulu 	p_load_req->override_force_load = p_drv_load->override_force_load;
3703*217ec208SDavid C Somayajulu 
3704*217ec208SDavid C Somayajulu 	/* Old MFW versions don't support timeout values other than default and
3705*217ec208SDavid C Somayajulu 	 * none, so these values are replaced according to the fall-back action.
3706*217ec208SDavid C Somayajulu 	 */
3707*217ec208SDavid C Somayajulu 
3708*217ec208SDavid C Somayajulu 	if (p_drv_load->mfw_timeout_val == ECORE_LOAD_REQ_LOCK_TO_DEFAULT ||
3709*217ec208SDavid C Somayajulu 	    p_drv_load->mfw_timeout_val == ECORE_LOAD_REQ_LOCK_TO_NONE ||
3710*217ec208SDavid C Somayajulu 	    (p_hwfn->mcp_info->capabilities &
3711*217ec208SDavid C Somayajulu 	     FW_MB_PARAM_FEATURE_SUPPORT_DRV_LOAD_TO)) {
3712*217ec208SDavid C Somayajulu 		p_load_req->timeout_val = p_drv_load->mfw_timeout_val;
3713*217ec208SDavid C Somayajulu 		goto out;
3714*217ec208SDavid C Somayajulu 	}
3715*217ec208SDavid C Somayajulu 
3716*217ec208SDavid C Somayajulu 	switch (p_drv_load->mfw_timeout_fallback) {
3717*217ec208SDavid C Somayajulu 	case ECORE_TO_FALLBACK_TO_NONE:
3718*217ec208SDavid C Somayajulu 		p_load_req->timeout_val = ECORE_LOAD_REQ_LOCK_TO_NONE;
3719*217ec208SDavid C Somayajulu 		break;
3720*217ec208SDavid C Somayajulu 	case ECORE_TO_FALLBACK_TO_DEFAULT:
3721*217ec208SDavid C Somayajulu 		p_load_req->timeout_val = ECORE_LOAD_REQ_LOCK_TO_DEFAULT;
3722*217ec208SDavid C Somayajulu 		break;
3723*217ec208SDavid C Somayajulu 	case ECORE_TO_FALLBACK_FAIL_LOAD:
3724*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
3725*217ec208SDavid C Somayajulu 			  "Received %d as a value for MFW timeout while the MFW supports only default [%d] or none [%d]. Abort.\n",
3726*217ec208SDavid C Somayajulu 			  p_drv_load->mfw_timeout_val,
3727*217ec208SDavid C Somayajulu 			  ECORE_LOAD_REQ_LOCK_TO_DEFAULT,
3728*217ec208SDavid C Somayajulu 			  ECORE_LOAD_REQ_LOCK_TO_NONE);
3729*217ec208SDavid C Somayajulu 		return ECORE_ABORTED;
3730*217ec208SDavid C Somayajulu 	}
3731*217ec208SDavid C Somayajulu 
3732*217ec208SDavid C Somayajulu 	DP_INFO(p_hwfn,
3733*217ec208SDavid C Somayajulu 		"Modified the MFW timeout value from %d to %s [%d] due to lack of MFW support\n",
3734*217ec208SDavid C Somayajulu 		p_drv_load->mfw_timeout_val,
3735*217ec208SDavid C Somayajulu 		(p_load_req->timeout_val == ECORE_LOAD_REQ_LOCK_TO_DEFAULT) ?
3736*217ec208SDavid C Somayajulu 		"default" : "none",
3737*217ec208SDavid C Somayajulu 		p_load_req->timeout_val);
3738*217ec208SDavid C Somayajulu out:
3739*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
3740*217ec208SDavid C Somayajulu }
3741*217ec208SDavid C Somayajulu 
ecore_vf_start(struct ecore_hwfn * p_hwfn,struct ecore_hw_init_params * p_params)374211e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_vf_start(struct ecore_hwfn *p_hwfn,
374311e25f0dSDavid C Somayajulu 				    struct ecore_hw_init_params *p_params)
374411e25f0dSDavid C Somayajulu {
374511e25f0dSDavid C Somayajulu 	if (p_params->p_tunn) {
374611e25f0dSDavid C Somayajulu 		ecore_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
374711e25f0dSDavid C Somayajulu 		ecore_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
374811e25f0dSDavid C Somayajulu 	}
374911e25f0dSDavid C Somayajulu 
375011e25f0dSDavid C Somayajulu 	p_hwfn->b_int_enabled = 1;
375111e25f0dSDavid C Somayajulu 
375211e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
375311e25f0dSDavid C Somayajulu }
375411e25f0dSDavid C Somayajulu 
ecore_pglueb_clear_err(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)3755*217ec208SDavid C Somayajulu static void ecore_pglueb_clear_err(struct ecore_hwfn *p_hwfn,
3756*217ec208SDavid C Somayajulu 				   struct ecore_ptt *p_ptt)
375711e25f0dSDavid C Somayajulu {
3758*217ec208SDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
3759*217ec208SDavid C Somayajulu 		 1 << p_hwfn->abs_pf_id);
376011e25f0dSDavid C Somayajulu }
376111e25f0dSDavid C Somayajulu 
ecore_hw_init(struct ecore_dev * p_dev,struct ecore_hw_init_params * p_params)376211e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
376311e25f0dSDavid C Somayajulu 				   struct ecore_hw_init_params *p_params)
376411e25f0dSDavid C Somayajulu {
376511e25f0dSDavid C Somayajulu 	struct ecore_load_req_params load_req_params;
3766*217ec208SDavid C Somayajulu 	u32 load_code, resp, param, drv_mb_param;
376711e25f0dSDavid C Somayajulu 	bool b_default_mtu = true;
376811e25f0dSDavid C Somayajulu 	struct ecore_hwfn *p_hwfn;
3769*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS, cancel_load;
3770*217ec208SDavid C Somayajulu 	u16 ether_type;
377111e25f0dSDavid C Somayajulu 	int i;
377211e25f0dSDavid C Somayajulu 
3773*217ec208SDavid C Somayajulu 	if ((p_params->int_mode == ECORE_INT_MODE_MSI) && ECORE_IS_CMT(p_dev)) {
377411e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev, false,
377511e25f0dSDavid C Somayajulu 			  "MSI mode is not supported for CMT devices\n");
377611e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
377711e25f0dSDavid C Somayajulu 	}
377811e25f0dSDavid C Somayajulu 
377911e25f0dSDavid C Somayajulu 	if (IS_PF(p_dev)) {
378011e25f0dSDavid C Somayajulu 		rc = ecore_init_fw_data(p_dev, p_params->bin_fw_data);
378111e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
378211e25f0dSDavid C Somayajulu 			return rc;
378311e25f0dSDavid C Somayajulu 	}
378411e25f0dSDavid C Somayajulu 
378511e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
3786*217ec208SDavid C Somayajulu 		p_hwfn = &p_dev->hwfns[i];
378711e25f0dSDavid C Somayajulu 
378811e25f0dSDavid C Somayajulu 		/* If management didn't provide a default, set one of our own */
378911e25f0dSDavid C Somayajulu 		if (!p_hwfn->hw_info.mtu) {
379011e25f0dSDavid C Somayajulu 			p_hwfn->hw_info.mtu = 1500;
379111e25f0dSDavid C Somayajulu 			b_default_mtu = false;
379211e25f0dSDavid C Somayajulu 		}
379311e25f0dSDavid C Somayajulu 
379411e25f0dSDavid C Somayajulu 		if (IS_VF(p_dev)) {
379511e25f0dSDavid C Somayajulu 			ecore_vf_start(p_hwfn, p_params);
379611e25f0dSDavid C Somayajulu 			continue;
379711e25f0dSDavid C Somayajulu 		}
379811e25f0dSDavid C Somayajulu 
379911e25f0dSDavid C Somayajulu 		rc = ecore_calc_hw_mode(p_hwfn);
380011e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
380111e25f0dSDavid C Somayajulu 			return rc;
380211e25f0dSDavid C Somayajulu 
3803*217ec208SDavid C Somayajulu 		if (IS_PF(p_dev) && (OSAL_TEST_BIT(ECORE_MF_8021Q_TAGGING,
3804*217ec208SDavid C Somayajulu 						   &p_dev->mf_bits) ||
3805*217ec208SDavid C Somayajulu 				     OSAL_TEST_BIT(ECORE_MF_8021AD_TAGGING,
3806*217ec208SDavid C Somayajulu 						   &p_dev->mf_bits))) {
3807*217ec208SDavid C Somayajulu 			if (OSAL_TEST_BIT(ECORE_MF_8021Q_TAGGING,
3808*217ec208SDavid C Somayajulu 					  &p_dev->mf_bits))
3809*217ec208SDavid C Somayajulu 				ether_type = ETH_P_8021Q;
3810*217ec208SDavid C Somayajulu 			else
3811*217ec208SDavid C Somayajulu 				ether_type = ETH_P_8021AD;
3812*217ec208SDavid C Somayajulu 			STORE_RT_REG(p_hwfn, PRS_REG_TAG_ETHERTYPE_0_RT_OFFSET,
3813*217ec208SDavid C Somayajulu 				     ether_type);
3814*217ec208SDavid C Somayajulu 			STORE_RT_REG(p_hwfn, NIG_REG_TAG_ETHERTYPE_0_RT_OFFSET,
3815*217ec208SDavid C Somayajulu 				     ether_type);
3816*217ec208SDavid C Somayajulu 			STORE_RT_REG(p_hwfn, PBF_REG_TAG_ETHERTYPE_0_RT_OFFSET,
3817*217ec208SDavid C Somayajulu 				     ether_type);
3818*217ec208SDavid C Somayajulu 			STORE_RT_REG(p_hwfn, DORQ_REG_TAG1_ETHERTYPE_RT_OFFSET,
3819*217ec208SDavid C Somayajulu 				     ether_type);
3820*217ec208SDavid C Somayajulu 		}
3821*217ec208SDavid C Somayajulu 
3822*217ec208SDavid C Somayajulu 		rc = ecore_fill_load_req_params(p_hwfn, &load_req_params,
382311e25f0dSDavid C Somayajulu 						p_params->p_drv_load_params);
3824*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
3825*217ec208SDavid C Somayajulu 			return rc;
3826*217ec208SDavid C Somayajulu 
382711e25f0dSDavid C Somayajulu 		rc = ecore_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
382811e25f0dSDavid C Somayajulu 					&load_req_params);
382911e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
3830*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
383111e25f0dSDavid C Somayajulu 				  "Failed sending a LOAD_REQ command\n");
383211e25f0dSDavid C Somayajulu 			return rc;
383311e25f0dSDavid C Somayajulu 		}
383411e25f0dSDavid C Somayajulu 
383511e25f0dSDavid C Somayajulu 		load_code = load_req_params.load_code;
383611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
383711e25f0dSDavid C Somayajulu 			   "Load request was sent. Load code: 0x%x\n",
383811e25f0dSDavid C Somayajulu 			   load_code);
383911e25f0dSDavid C Somayajulu 
384011e25f0dSDavid C Somayajulu 		ecore_mcp_set_capabilities(p_hwfn, p_hwfn->p_main_ptt);
384111e25f0dSDavid C Somayajulu 
384211e25f0dSDavid C Somayajulu 		/* CQ75580:
3843*217ec208SDavid C Somayajulu 		 * When coming back from hibernate state, the registers from
384411e25f0dSDavid C Somayajulu 		 * which shadow is read initially are not initialized. It turns
384511e25f0dSDavid C Somayajulu 		 * out that these registers get initialized during the call to
384611e25f0dSDavid C Somayajulu 		 * ecore_mcp_load_req request. So we need to reread them here
384711e25f0dSDavid C Somayajulu 		 * to get the proper shadow register value.
384811e25f0dSDavid C Somayajulu 		 * Note: This is a workaround for the missing MFW
384911e25f0dSDavid C Somayajulu 		 * initialization. It may be removed once the implementation
385011e25f0dSDavid C Somayajulu 		 * is done.
385111e25f0dSDavid C Somayajulu 		 */
385211e25f0dSDavid C Somayajulu 		ecore_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
385311e25f0dSDavid C Somayajulu 
385411e25f0dSDavid C Somayajulu 		/* Only relevant for recovery:
385511e25f0dSDavid C Somayajulu 		 * Clear the indication after the LOAD_REQ command is responded
385611e25f0dSDavid C Somayajulu 		 * by the MFW.
385711e25f0dSDavid C Somayajulu 		 */
385811e25f0dSDavid C Somayajulu 		p_dev->recov_in_prog = false;
385911e25f0dSDavid C Somayajulu 
3860*217ec208SDavid C Somayajulu 		if (!qm_lock_ref_cnt) {
3861*217ec208SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
3862*217ec208SDavid C Somayajulu 			rc = OSAL_SPIN_LOCK_ALLOC(p_hwfn, &qm_lock);
3863*217ec208SDavid C Somayajulu 			if (rc) {
3864*217ec208SDavid C Somayajulu 				DP_ERR(p_hwfn, "qm_lock allocation failed\n");
3865*217ec208SDavid C Somayajulu 				goto qm_lock_fail;
386611e25f0dSDavid C Somayajulu 			}
3867*217ec208SDavid C Somayajulu #endif
3868*217ec208SDavid C Somayajulu 			OSAL_SPIN_LOCK_INIT(&qm_lock);
3869*217ec208SDavid C Somayajulu 		}
3870*217ec208SDavid C Somayajulu 		++qm_lock_ref_cnt;
3871*217ec208SDavid C Somayajulu 
3872*217ec208SDavid C Somayajulu 		/* Clean up chip from previous driver if such remains exist.
3873*217ec208SDavid C Somayajulu 		 * This is not needed when the PF is the first one on the
3874*217ec208SDavid C Somayajulu 		 * engine, since afterwards we are going to init the FW.
3875*217ec208SDavid C Somayajulu 		 */
3876*217ec208SDavid C Somayajulu 		if (load_code != FW_MSG_CODE_DRV_LOAD_ENGINE) {
3877*217ec208SDavid C Somayajulu 			rc = ecore_final_cleanup(p_hwfn, p_hwfn->p_main_ptt,
3878*217ec208SDavid C Somayajulu 						 p_hwfn->rel_pf_id, false);
3879*217ec208SDavid C Somayajulu 			if (rc != ECORE_SUCCESS) {
3880*217ec208SDavid C Somayajulu 				ecore_hw_err_notify(p_hwfn,
3881*217ec208SDavid C Somayajulu 						    ECORE_HW_ERR_RAMROD_FAIL);
3882*217ec208SDavid C Somayajulu 				goto load_err;
3883*217ec208SDavid C Somayajulu 			}
3884*217ec208SDavid C Somayajulu 		}
3885*217ec208SDavid C Somayajulu 
3886*217ec208SDavid C Somayajulu 		/* Log and clear previous pglue_b errors if such exist */
3887*217ec208SDavid C Somayajulu 		ecore_pglueb_rbc_attn_handler(p_hwfn, p_hwfn->p_main_ptt);
3888*217ec208SDavid C Somayajulu 
3889*217ec208SDavid C Somayajulu 		/* Enable the PF's internal FID_enable in the PXP */
3890*217ec208SDavid C Somayajulu 		rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_hwfn->p_main_ptt,
3891*217ec208SDavid C Somayajulu 						  true);
3892*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
3893*217ec208SDavid C Somayajulu 			goto load_err;
3894*217ec208SDavid C Somayajulu 
3895*217ec208SDavid C Somayajulu 		/* Clear the pglue_b was_error indication.
3896*217ec208SDavid C Somayajulu 		 * In E4 it must be done after the BME and the internal
3897*217ec208SDavid C Somayajulu 		 * FID_enable for the PF are set, since VDMs may cause the
3898*217ec208SDavid C Somayajulu 		 * indication to be set again.
3899*217ec208SDavid C Somayajulu 		 */
3900*217ec208SDavid C Somayajulu 		ecore_pglueb_clear_err(p_hwfn, p_hwfn->p_main_ptt);
390111e25f0dSDavid C Somayajulu 
390211e25f0dSDavid C Somayajulu 		switch (load_code) {
390311e25f0dSDavid C Somayajulu 		case FW_MSG_CODE_DRV_LOAD_ENGINE:
390411e25f0dSDavid C Somayajulu 			rc = ecore_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
390511e25f0dSDavid C Somayajulu 						  p_hwfn->hw_info.hw_mode);
390611e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS)
390711e25f0dSDavid C Somayajulu 				break;
390811e25f0dSDavid C Somayajulu 			/* Fall into */
390911e25f0dSDavid C Somayajulu 		case FW_MSG_CODE_DRV_LOAD_PORT:
391011e25f0dSDavid C Somayajulu 			rc = ecore_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
391111e25f0dSDavid C Somayajulu 						p_hwfn->hw_info.hw_mode);
391211e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS)
391311e25f0dSDavid C Somayajulu 				break;
391411e25f0dSDavid C Somayajulu 			/* Fall into */
391511e25f0dSDavid C Somayajulu 		case FW_MSG_CODE_DRV_LOAD_FUNCTION:
391611e25f0dSDavid C Somayajulu 			rc = ecore_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
391711e25f0dSDavid C Somayajulu 					      p_hwfn->hw_info.hw_mode,
3918*217ec208SDavid C Somayajulu 					      p_params);
391911e25f0dSDavid C Somayajulu 			break;
392011e25f0dSDavid C Somayajulu 		default:
392111e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
392211e25f0dSDavid C Somayajulu 				  "Unexpected load code [0x%08x]", load_code);
392311e25f0dSDavid C Somayajulu 			rc = ECORE_NOTIMPL;
392411e25f0dSDavid C Somayajulu 			break;
392511e25f0dSDavid C Somayajulu 		}
392611e25f0dSDavid C Somayajulu 
3927*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
3928*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
392911e25f0dSDavid C Somayajulu 				  "init phase failed for loadcode 0x%x (rc %d)\n",
393011e25f0dSDavid C Somayajulu 				  load_code, rc);
3931*217ec208SDavid C Somayajulu 			goto load_err;
393211e25f0dSDavid C Somayajulu 		}
393311e25f0dSDavid C Somayajulu 
3934*217ec208SDavid C Somayajulu 		rc = ecore_mcp_load_done(p_hwfn, p_hwfn->p_main_ptt);
3935*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
3936*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "Sending load done failed, rc = %d\n", rc);
3937*217ec208SDavid C Somayajulu 			if (rc == ECORE_NOMEM) {
393811e25f0dSDavid C Somayajulu 				DP_NOTICE(p_hwfn, false,
3939*217ec208SDavid C Somayajulu 					  "Sending load done was failed due to memory allocation failure\n");
3940*217ec208SDavid C Somayajulu 				goto load_err;
3941*217ec208SDavid C Somayajulu 			}
3942*217ec208SDavid C Somayajulu 			return rc;
3943*217ec208SDavid C Somayajulu 		}
394411e25f0dSDavid C Somayajulu 
394511e25f0dSDavid C Somayajulu 		/* send DCBX attention request command */
394611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
394711e25f0dSDavid C Somayajulu 			   "sending phony dcbx set command to trigger DCBx attention handling\n");
3948*217ec208SDavid C Somayajulu 		rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
394911e25f0dSDavid C Somayajulu 				   DRV_MSG_CODE_SET_DCBX,
3950*217ec208SDavid C Somayajulu 				   1 << DRV_MB_PARAM_DCBX_NOTIFY_OFFSET, &resp,
3951*217ec208SDavid C Somayajulu 				   &param);
3952*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
3953*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
395411e25f0dSDavid C Somayajulu 				  "Failed to send DCBX attention request\n");
3955*217ec208SDavid C Somayajulu 			return rc;
395611e25f0dSDavid C Somayajulu 		}
395711e25f0dSDavid C Somayajulu 
395811e25f0dSDavid C Somayajulu 		p_hwfn->hw_init_done = true;
395911e25f0dSDavid C Somayajulu 	}
396011e25f0dSDavid C Somayajulu 
396111e25f0dSDavid C Somayajulu 	if (IS_PF(p_dev)) {
3962*217ec208SDavid C Somayajulu 		/* Get pre-negotiated values for stag, bandwidth etc. */
3963*217ec208SDavid C Somayajulu 		p_hwfn = ECORE_LEADING_HWFN(p_dev);
3964*217ec208SDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
3965*217ec208SDavid C Somayajulu 			   "Sending GET_OEM_UPDATES command to trigger stag/bandwidth attention handling\n");
3966*217ec208SDavid C Somayajulu 		rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
3967*217ec208SDavid C Somayajulu 				   DRV_MSG_CODE_GET_OEM_UPDATES,
3968*217ec208SDavid C Somayajulu 				   1 << DRV_MB_PARAM_DUMMY_OEM_UPDATES_OFFSET,
3969*217ec208SDavid C Somayajulu 				   &resp, &param);
3970*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
3971*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
3972*217ec208SDavid C Somayajulu 				  "Failed to send GET_OEM_UPDATES attention request\n");
3973*217ec208SDavid C Somayajulu 	}
3974*217ec208SDavid C Somayajulu 
3975*217ec208SDavid C Somayajulu 	if (IS_PF(p_dev)) {
397611e25f0dSDavid C Somayajulu 		p_hwfn = ECORE_LEADING_HWFN(p_dev);
397711e25f0dSDavid C Somayajulu 		drv_mb_param = STORM_FW_VERSION;
397811e25f0dSDavid C Somayajulu 		rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
397911e25f0dSDavid C Somayajulu 				   DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
3980*217ec208SDavid C Somayajulu 				   drv_mb_param, &resp, &param);
398111e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
398211e25f0dSDavid C Somayajulu 			DP_INFO(p_hwfn, "Failed to update firmware version\n");
398311e25f0dSDavid C Somayajulu 
398411e25f0dSDavid C Somayajulu 		if (!b_default_mtu) {
398511e25f0dSDavid C Somayajulu 			rc = ecore_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
398611e25f0dSDavid C Somayajulu 						      p_hwfn->hw_info.mtu);
398711e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS)
398811e25f0dSDavid C Somayajulu 				DP_INFO(p_hwfn, "Failed to update default mtu\n");
398911e25f0dSDavid C Somayajulu 		}
399011e25f0dSDavid C Somayajulu 
399111e25f0dSDavid C Somayajulu 		rc = ecore_mcp_ov_update_driver_state(p_hwfn,
399211e25f0dSDavid C Somayajulu 						      p_hwfn->p_main_ptt,
399311e25f0dSDavid C Somayajulu 						      ECORE_OV_DRIVER_STATE_DISABLED);
399411e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
399511e25f0dSDavid C Somayajulu 			DP_INFO(p_hwfn, "Failed to update driver state\n");
399611e25f0dSDavid C Somayajulu 
399711e25f0dSDavid C Somayajulu 		rc = ecore_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt,
399811e25f0dSDavid C Somayajulu 						 ECORE_OV_ESWITCH_VEB);
399911e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
400011e25f0dSDavid C Somayajulu 			DP_INFO(p_hwfn, "Failed to update eswitch mode\n");
400111e25f0dSDavid C Somayajulu 	}
400211e25f0dSDavid C Somayajulu 
400311e25f0dSDavid C Somayajulu 	return rc;
4004*217ec208SDavid C Somayajulu 
4005*217ec208SDavid C Somayajulu load_err:
4006*217ec208SDavid C Somayajulu 	--qm_lock_ref_cnt;
4007*217ec208SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
4008*217ec208SDavid C Somayajulu 	if (!qm_lock_ref_cnt)
4009*217ec208SDavid C Somayajulu 		OSAL_SPIN_LOCK_DEALLOC(&qm_lock);
4010*217ec208SDavid C Somayajulu qm_lock_fail:
4011*217ec208SDavid C Somayajulu #endif
4012*217ec208SDavid C Somayajulu 	/* The MFW load lock should be released also when initialization fails.
4013*217ec208SDavid C Somayajulu 	 * If supported, use a cancel_load request to update the MFW with the
4014*217ec208SDavid C Somayajulu 	 * load failure.
4015*217ec208SDavid C Somayajulu 	 */
4016*217ec208SDavid C Somayajulu 	cancel_load = ecore_mcp_cancel_load_req(p_hwfn, p_hwfn->p_main_ptt);
4017*217ec208SDavid C Somayajulu 	if (cancel_load == ECORE_NOTIMPL) {
4018*217ec208SDavid C Somayajulu 		DP_INFO(p_hwfn,
4019*217ec208SDavid C Somayajulu 			"Send a load done request instead of cancel load\n");
4020*217ec208SDavid C Somayajulu 		ecore_mcp_load_done(p_hwfn, p_hwfn->p_main_ptt);
4021*217ec208SDavid C Somayajulu 	}
4022*217ec208SDavid C Somayajulu 	return rc;
402311e25f0dSDavid C Somayajulu }
402411e25f0dSDavid C Somayajulu 
402511e25f0dSDavid C Somayajulu #define ECORE_HW_STOP_RETRY_LIMIT	(10)
ecore_hw_timers_stop(struct ecore_dev * p_dev,struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)402611e25f0dSDavid C Somayajulu static void ecore_hw_timers_stop(struct ecore_dev *p_dev,
402711e25f0dSDavid C Somayajulu 				 struct ecore_hwfn *p_hwfn,
402811e25f0dSDavid C Somayajulu 				 struct ecore_ptt *p_ptt)
402911e25f0dSDavid C Somayajulu {
403011e25f0dSDavid C Somayajulu 	int i;
403111e25f0dSDavid C Somayajulu 
403211e25f0dSDavid C Somayajulu 	/* close timers */
403311e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
403411e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
403511e25f0dSDavid C Somayajulu 	for (i = 0;
403611e25f0dSDavid C Somayajulu 	     i < ECORE_HW_STOP_RETRY_LIMIT && !p_dev->recov_in_prog;
403711e25f0dSDavid C Somayajulu 	     i++) {
403811e25f0dSDavid C Somayajulu 		if ((!ecore_rd(p_hwfn, p_ptt,
403911e25f0dSDavid C Somayajulu 			       TM_REG_PF_SCAN_ACTIVE_CONN)) &&
404011e25f0dSDavid C Somayajulu 		    (!ecore_rd(p_hwfn, p_ptt,
404111e25f0dSDavid C Somayajulu 			       TM_REG_PF_SCAN_ACTIVE_TASK)))
404211e25f0dSDavid C Somayajulu 			break;
404311e25f0dSDavid C Somayajulu 
404411e25f0dSDavid C Somayajulu 		/* Dependent on number of connection/tasks, possibly
404511e25f0dSDavid C Somayajulu 		 * 1ms sleep is required between polls
404611e25f0dSDavid C Somayajulu 		 */
404711e25f0dSDavid C Somayajulu 		OSAL_MSLEEP(1);
404811e25f0dSDavid C Somayajulu 	}
404911e25f0dSDavid C Somayajulu 
405011e25f0dSDavid C Somayajulu 	if (i < ECORE_HW_STOP_RETRY_LIMIT)
405111e25f0dSDavid C Somayajulu 		return;
405211e25f0dSDavid C Somayajulu 
4053*217ec208SDavid C Somayajulu 	DP_NOTICE(p_hwfn, false,
405411e25f0dSDavid C Somayajulu 		  "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
405511e25f0dSDavid C Somayajulu 		  (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
405611e25f0dSDavid C Somayajulu 		  (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
405711e25f0dSDavid C Somayajulu }
405811e25f0dSDavid C Somayajulu 
ecore_hw_timers_stop_all(struct ecore_dev * p_dev)405911e25f0dSDavid C Somayajulu void ecore_hw_timers_stop_all(struct ecore_dev *p_dev)
406011e25f0dSDavid C Somayajulu {
406111e25f0dSDavid C Somayajulu 	int j;
406211e25f0dSDavid C Somayajulu 
406311e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, j) {
406411e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
406511e25f0dSDavid C Somayajulu 		struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
406611e25f0dSDavid C Somayajulu 
406711e25f0dSDavid C Somayajulu 		ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
406811e25f0dSDavid C Somayajulu 	}
406911e25f0dSDavid C Somayajulu }
407011e25f0dSDavid C Somayajulu 
ecore_verify_reg_val(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 addr,u32 expected_val)407111e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_verify_reg_val(struct ecore_hwfn *p_hwfn,
407211e25f0dSDavid C Somayajulu 						 struct ecore_ptt *p_ptt,
407311e25f0dSDavid C Somayajulu 						 u32 addr, u32 expected_val)
407411e25f0dSDavid C Somayajulu {
407511e25f0dSDavid C Somayajulu 	u32 val = ecore_rd(p_hwfn, p_ptt, addr);
407611e25f0dSDavid C Somayajulu 
407711e25f0dSDavid C Somayajulu 	if (val != expected_val) {
407811e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true,
407911e25f0dSDavid C Somayajulu 			  "Value at address 0x%08x is 0x%08x while the expected value is 0x%08x\n",
408011e25f0dSDavid C Somayajulu 			  addr, val, expected_val);
408111e25f0dSDavid C Somayajulu 		return ECORE_UNKNOWN_ERROR;
408211e25f0dSDavid C Somayajulu 	}
408311e25f0dSDavid C Somayajulu 
408411e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
408511e25f0dSDavid C Somayajulu }
408611e25f0dSDavid C Somayajulu 
ecore_hw_stop(struct ecore_dev * p_dev)408711e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev)
408811e25f0dSDavid C Somayajulu {
408911e25f0dSDavid C Somayajulu 	struct ecore_hwfn *p_hwfn;
409011e25f0dSDavid C Somayajulu 	struct ecore_ptt *p_ptt;
409111e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc, rc2 = ECORE_SUCCESS;
409211e25f0dSDavid C Somayajulu 	int j;
409311e25f0dSDavid C Somayajulu 
409411e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, j) {
409511e25f0dSDavid C Somayajulu 		p_hwfn = &p_dev->hwfns[j];
409611e25f0dSDavid C Somayajulu 		p_ptt = p_hwfn->p_main_ptt;
409711e25f0dSDavid C Somayajulu 
409811e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Stopping hw/fw\n");
409911e25f0dSDavid C Somayajulu 
410011e25f0dSDavid C Somayajulu 		if (IS_VF(p_dev)) {
410111e25f0dSDavid C Somayajulu 			ecore_vf_pf_int_cleanup(p_hwfn);
410211e25f0dSDavid C Somayajulu 			rc = ecore_vf_pf_reset(p_hwfn);
410311e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS) {
410411e25f0dSDavid C Somayajulu 				DP_NOTICE(p_hwfn, true,
410511e25f0dSDavid C Somayajulu 					  "ecore_vf_pf_reset failed. rc = %d.\n",
410611e25f0dSDavid C Somayajulu 					  rc);
410711e25f0dSDavid C Somayajulu 				rc2 = ECORE_UNKNOWN_ERROR;
410811e25f0dSDavid C Somayajulu 			}
410911e25f0dSDavid C Somayajulu 			continue;
411011e25f0dSDavid C Somayajulu 		}
411111e25f0dSDavid C Somayajulu 
411211e25f0dSDavid C Somayajulu 		/* mark the hw as uninitialized... */
411311e25f0dSDavid C Somayajulu 		p_hwfn->hw_init_done = false;
411411e25f0dSDavid C Somayajulu 
411511e25f0dSDavid C Somayajulu 		/* Send unload command to MCP */
411611e25f0dSDavid C Somayajulu 		if (!p_dev->recov_in_prog) {
411711e25f0dSDavid C Somayajulu 			rc = ecore_mcp_unload_req(p_hwfn, p_ptt);
411811e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS) {
4119*217ec208SDavid C Somayajulu 				DP_NOTICE(p_hwfn, false,
412011e25f0dSDavid C Somayajulu 					  "Failed sending a UNLOAD_REQ command. rc = %d.\n",
412111e25f0dSDavid C Somayajulu 					  rc);
412211e25f0dSDavid C Somayajulu 				rc2 = ECORE_UNKNOWN_ERROR;
412311e25f0dSDavid C Somayajulu 			}
412411e25f0dSDavid C Somayajulu 		}
412511e25f0dSDavid C Somayajulu 
412611e25f0dSDavid C Somayajulu 		OSAL_DPC_SYNC(p_hwfn);
412711e25f0dSDavid C Somayajulu 
412811e25f0dSDavid C Somayajulu 		/* After this point no MFW attentions are expected, e.g. prevent
412911e25f0dSDavid C Somayajulu 		 * race between pf stop and dcbx pf update.
413011e25f0dSDavid C Somayajulu 		 */
413111e25f0dSDavid C Somayajulu 
413211e25f0dSDavid C Somayajulu 		rc = ecore_sp_pf_stop(p_hwfn);
413311e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
4134*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
413511e25f0dSDavid C Somayajulu 				  "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
413611e25f0dSDavid C Somayajulu 				  rc);
413711e25f0dSDavid C Somayajulu 			rc2 = ECORE_UNKNOWN_ERROR;
413811e25f0dSDavid C Somayajulu 		}
413911e25f0dSDavid C Somayajulu 
414011e25f0dSDavid C Somayajulu 		/* perform debug action after PF stop was sent */
414111e25f0dSDavid C Somayajulu 		OSAL_AFTER_PF_STOP((void *)p_dev, p_hwfn->my_id);
414211e25f0dSDavid C Somayajulu 
414311e25f0dSDavid C Somayajulu 		/* close NIG to BRB gate */
414411e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt,
414511e25f0dSDavid C Somayajulu 			 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
414611e25f0dSDavid C Somayajulu 
414711e25f0dSDavid C Somayajulu 		/* close parser */
414811e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
414911e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
415011e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
415111e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
415211e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
415311e25f0dSDavid C Somayajulu 
415411e25f0dSDavid C Somayajulu 		/* @@@TBD - clean transmission queues (5.b) */
415511e25f0dSDavid C Somayajulu 		/* @@@TBD - clean BTB (5.c) */
415611e25f0dSDavid C Somayajulu 
415711e25f0dSDavid C Somayajulu 		ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
415811e25f0dSDavid C Somayajulu 
415911e25f0dSDavid C Somayajulu 		/* @@@TBD - verify DMAE requests are done (8) */
416011e25f0dSDavid C Somayajulu 
416111e25f0dSDavid C Somayajulu 		/* Disable Attention Generation */
416211e25f0dSDavid C Somayajulu 		ecore_int_igu_disable_int(p_hwfn, p_ptt);
416311e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
416411e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
416511e25f0dSDavid C Somayajulu 		ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
416611e25f0dSDavid C Somayajulu 		rc = ecore_int_igu_reset_cam_default(p_hwfn, p_ptt);
416711e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
416811e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, true,
416911e25f0dSDavid C Somayajulu 				  "Failed to return IGU CAM to default\n");
417011e25f0dSDavid C Somayajulu 			rc2 = ECORE_UNKNOWN_ERROR;
417111e25f0dSDavid C Somayajulu 		}
417211e25f0dSDavid C Somayajulu 
417311e25f0dSDavid C Somayajulu 		/* Need to wait 1ms to guarantee SBs are cleared */
417411e25f0dSDavid C Somayajulu 		OSAL_MSLEEP(1);
417511e25f0dSDavid C Somayajulu 
417611e25f0dSDavid C Somayajulu 		if (!p_dev->recov_in_prog) {
417711e25f0dSDavid C Somayajulu 			ecore_verify_reg_val(p_hwfn, p_ptt,
417811e25f0dSDavid C Somayajulu 					     QM_REG_USG_CNT_PF_TX, 0);
417911e25f0dSDavid C Somayajulu 			ecore_verify_reg_val(p_hwfn, p_ptt,
418011e25f0dSDavid C Somayajulu 					     QM_REG_USG_CNT_PF_OTHER, 0);
418111e25f0dSDavid C Somayajulu 			/* @@@TBD - assert on incorrect xCFC values (10.b) */
418211e25f0dSDavid C Somayajulu 		}
418311e25f0dSDavid C Somayajulu 
418411e25f0dSDavid C Somayajulu 		/* Disable PF in HW blocks */
418511e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
418611e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
418711e25f0dSDavid C Somayajulu 
4188*217ec208SDavid C Somayajulu 		if (IS_LEAD_HWFN(p_hwfn) &&
4189*217ec208SDavid C Somayajulu 		    OSAL_TEST_BIT(ECORE_MF_LLH_MAC_CLSS, &p_dev->mf_bits) &&
4190*217ec208SDavid C Somayajulu 		    !ECORE_IS_FCOE_PERSONALITY(p_hwfn))
4191*217ec208SDavid C Somayajulu 			ecore_llh_remove_mac_filter(p_dev, 0,
4192*217ec208SDavid C Somayajulu 						    p_hwfn->hw_info.hw_mac_addr);
4193*217ec208SDavid C Somayajulu 
4194*217ec208SDavid C Somayajulu 		--qm_lock_ref_cnt;
4195*217ec208SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
4196*217ec208SDavid C Somayajulu 		if (!qm_lock_ref_cnt)
4197*217ec208SDavid C Somayajulu 			OSAL_SPIN_LOCK_DEALLOC(&qm_lock);
4198*217ec208SDavid C Somayajulu #endif
4199*217ec208SDavid C Somayajulu 
420011e25f0dSDavid C Somayajulu 		if (!p_dev->recov_in_prog) {
4201*217ec208SDavid C Somayajulu 			rc = ecore_mcp_unload_done(p_hwfn, p_ptt);
4202*217ec208SDavid C Somayajulu 			if (rc == ECORE_NOMEM) {
4203*217ec208SDavid C Somayajulu 				DP_NOTICE(p_hwfn, false,
4204*217ec208SDavid C Somayajulu 					 "Failed sending an UNLOAD_DONE command due to a memory allocation failure. Resending.\n");
4205*217ec208SDavid C Somayajulu 				rc = ecore_mcp_unload_done(p_hwfn, p_ptt);
4206*217ec208SDavid C Somayajulu 			}
420711e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS) {
4208*217ec208SDavid C Somayajulu 				DP_NOTICE(p_hwfn, false,
420911e25f0dSDavid C Somayajulu 					  "Failed sending a UNLOAD_DONE command. rc = %d.\n",
421011e25f0dSDavid C Somayajulu 					  rc);
421111e25f0dSDavid C Somayajulu 				rc2 = ECORE_UNKNOWN_ERROR;
421211e25f0dSDavid C Somayajulu 			}
421311e25f0dSDavid C Somayajulu 		}
421411e25f0dSDavid C Somayajulu 	} /* hwfn loop */
421511e25f0dSDavid C Somayajulu 
4216*217ec208SDavid C Somayajulu 	if (IS_PF(p_dev) && !p_dev->recov_in_prog) {
421711e25f0dSDavid C Somayajulu 		p_hwfn = ECORE_LEADING_HWFN(p_dev);
421811e25f0dSDavid C Somayajulu 		p_ptt = ECORE_LEADING_HWFN(p_dev)->p_main_ptt;
421911e25f0dSDavid C Somayajulu 
4220*217ec208SDavid C Somayajulu 		 /* Clear the PF's internal FID_enable in the PXP.
4221*217ec208SDavid C Somayajulu 		  * In CMT this should only be done for first hw-function, and
4222*217ec208SDavid C Somayajulu 		  * only after all transactions have stopped for all active
4223*217ec208SDavid C Somayajulu 		  * hw-functions.
422411e25f0dSDavid C Somayajulu 		  */
4225*217ec208SDavid C Somayajulu 		rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_hwfn->p_main_ptt,
4226*217ec208SDavid C Somayajulu 						  false);
422711e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
422811e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, true,
4229*217ec208SDavid C Somayajulu 				  "ecore_pglueb_set_pfid_enable() failed. rc = %d.\n",
423011e25f0dSDavid C Somayajulu 				  rc);
423111e25f0dSDavid C Somayajulu 			rc2 = ECORE_UNKNOWN_ERROR;
423211e25f0dSDavid C Somayajulu 		}
423311e25f0dSDavid C Somayajulu 	}
423411e25f0dSDavid C Somayajulu 
423511e25f0dSDavid C Somayajulu 	return rc2;
423611e25f0dSDavid C Somayajulu }
423711e25f0dSDavid C Somayajulu 
ecore_hw_stop_fastpath(struct ecore_dev * p_dev)42389efd0ba7SDavid C Somayajulu enum _ecore_status_t ecore_hw_stop_fastpath(struct ecore_dev *p_dev)
423911e25f0dSDavid C Somayajulu {
424011e25f0dSDavid C Somayajulu 	int j;
424111e25f0dSDavid C Somayajulu 
424211e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, j) {
424311e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
42449efd0ba7SDavid C Somayajulu 		struct ecore_ptt *p_ptt;
424511e25f0dSDavid C Somayajulu 
424611e25f0dSDavid C Somayajulu 		if (IS_VF(p_dev)) {
424711e25f0dSDavid C Somayajulu 			ecore_vf_pf_int_cleanup(p_hwfn);
424811e25f0dSDavid C Somayajulu 			continue;
424911e25f0dSDavid C Somayajulu 		}
42509efd0ba7SDavid C Somayajulu 		p_ptt = ecore_ptt_acquire(p_hwfn);
42519efd0ba7SDavid C Somayajulu 		if (!p_ptt)
42529efd0ba7SDavid C Somayajulu 			return ECORE_AGAIN;
425311e25f0dSDavid C Somayajulu 
425411e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Shutting down the fastpath\n");
425511e25f0dSDavid C Somayajulu 
425611e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt,
425711e25f0dSDavid C Somayajulu 			 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
425811e25f0dSDavid C Somayajulu 
425911e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
426011e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
426111e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
426211e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
426311e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
426411e25f0dSDavid C Somayajulu 
426511e25f0dSDavid C Somayajulu 		/* @@@TBD - clean transmission queues (5.b) */
426611e25f0dSDavid C Somayajulu 		/* @@@TBD - clean BTB (5.c) */
426711e25f0dSDavid C Somayajulu 
426811e25f0dSDavid C Somayajulu 		/* @@@TBD - verify DMAE requests are done (8) */
426911e25f0dSDavid C Somayajulu 
427011e25f0dSDavid C Somayajulu 		ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
427111e25f0dSDavid C Somayajulu 		/* Need to wait 1ms to guarantee SBs are cleared */
427211e25f0dSDavid C Somayajulu 		OSAL_MSLEEP(1);
42739efd0ba7SDavid C Somayajulu 		ecore_ptt_release(p_hwfn, p_ptt);
427411e25f0dSDavid C Somayajulu 	}
427511e25f0dSDavid C Somayajulu 
42769efd0ba7SDavid C Somayajulu 	return ECORE_SUCCESS;
42779efd0ba7SDavid C Somayajulu }
42789efd0ba7SDavid C Somayajulu 
ecore_hw_start_fastpath(struct ecore_hwfn * p_hwfn)42799efd0ba7SDavid C Somayajulu enum _ecore_status_t ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn)
428011e25f0dSDavid C Somayajulu {
42819efd0ba7SDavid C Somayajulu 	struct ecore_ptt *p_ptt;
428211e25f0dSDavid C Somayajulu 
428311e25f0dSDavid C Somayajulu 	if (IS_VF(p_hwfn->p_dev))
42849efd0ba7SDavid C Somayajulu 		return ECORE_SUCCESS;
42859efd0ba7SDavid C Somayajulu 
42869efd0ba7SDavid C Somayajulu 	p_ptt = ecore_ptt_acquire(p_hwfn);
42879efd0ba7SDavid C Somayajulu 	if (!p_ptt)
42889efd0ba7SDavid C Somayajulu 		return ECORE_AGAIN;
428911e25f0dSDavid C Somayajulu 
429011e25f0dSDavid C Somayajulu 	/* If roce info is allocated it means roce is initialized and should
429111e25f0dSDavid C Somayajulu 	 * be enabled in searcher.
429211e25f0dSDavid C Somayajulu 	 */
4293*217ec208SDavid C Somayajulu 	if (p_hwfn->p_rdma_info &&
4294*217ec208SDavid C Somayajulu 	    p_hwfn->p_rdma_info->active &&
4295*217ec208SDavid C Somayajulu 	    p_hwfn->b_rdma_enabled_in_prs)
4296*217ec208SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0x1);
429711e25f0dSDavid C Somayajulu 
429811e25f0dSDavid C Somayajulu 	/* Re-open incoming traffic */
42999efd0ba7SDavid C Somayajulu 	ecore_wr(p_hwfn, p_ptt,
430011e25f0dSDavid C Somayajulu 		 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
43019efd0ba7SDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
43029efd0ba7SDavid C Somayajulu 
43039efd0ba7SDavid C Somayajulu 	return ECORE_SUCCESS;
430411e25f0dSDavid C Somayajulu }
430511e25f0dSDavid C Somayajulu 
ecore_set_nwuf_reg(struct ecore_dev * p_dev,u32 reg_idx,u32 pattern_size,u32 crc)43069efd0ba7SDavid C Somayajulu enum _ecore_status_t ecore_set_nwuf_reg(struct ecore_dev *p_dev, u32 reg_idx,
43079efd0ba7SDavid C Somayajulu 					u32 pattern_size, u32 crc)
430811e25f0dSDavid C Somayajulu {
4309*217ec208SDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
43109efd0ba7SDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
43119efd0ba7SDavid C Somayajulu 	struct ecore_ptt *p_ptt;
431211e25f0dSDavid C Somayajulu 	u32 reg_len = 0;
431311e25f0dSDavid C Somayajulu 	u32 reg_crc = 0;
431411e25f0dSDavid C Somayajulu 
4315*217ec208SDavid C Somayajulu 	p_ptt = ecore_ptt_acquire(p_hwfn);
43169efd0ba7SDavid C Somayajulu 	if (!p_ptt)
43179efd0ba7SDavid C Somayajulu 		return ECORE_AGAIN;
43189efd0ba7SDavid C Somayajulu 
431911e25f0dSDavid C Somayajulu 	/* Get length and CRC register offsets */
432011e25f0dSDavid C Somayajulu 	switch (reg_idx)
432111e25f0dSDavid C Somayajulu 	{
432211e25f0dSDavid C Somayajulu 	case 0:
432311e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_0_LEN_BB :
432411e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_0_LEN_K2_E5;
432511e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_0_CRC_BB :
432611e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_0_CRC_K2_E5;
432711e25f0dSDavid C Somayajulu 		break;
432811e25f0dSDavid C Somayajulu 	case 1:
432911e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_1_LEN_BB :
433011e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_1_LEN_K2_E5;
433111e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_1_CRC_BB :
433211e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_1_CRC_K2_E5;
433311e25f0dSDavid C Somayajulu 		break;
433411e25f0dSDavid C Somayajulu 	case 2:
433511e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_2_LEN_BB :
433611e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_2_LEN_K2_E5;
433711e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_2_CRC_BB :
433811e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_2_CRC_K2_E5;
433911e25f0dSDavid C Somayajulu 		break;
434011e25f0dSDavid C Somayajulu 	case 3:
434111e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_3_LEN_BB :
434211e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_3_LEN_K2_E5;
434311e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_3_CRC_BB :
434411e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_3_CRC_K2_E5;
434511e25f0dSDavid C Somayajulu 		break;
434611e25f0dSDavid C Somayajulu 	case 4:
434711e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_4_LEN_BB :
434811e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_4_LEN_K2_E5;
434911e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_4_CRC_BB :
435011e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_4_CRC_K2_E5;
435111e25f0dSDavid C Somayajulu 		break;
435211e25f0dSDavid C Somayajulu 	case 5:
435311e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_5_LEN_BB :
435411e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_5_LEN_K2_E5;
435511e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_5_CRC_BB :
435611e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_5_CRC_K2_E5;
435711e25f0dSDavid C Somayajulu 		break;
435811e25f0dSDavid C Somayajulu 	case 6:
435911e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_6_LEN_BB :
436011e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_6_LEN_K2_E5;
436111e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_6_CRC_BB :
436211e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_6_CRC_K2_E5;
436311e25f0dSDavid C Somayajulu 		break;
436411e25f0dSDavid C Somayajulu 	case 7:
436511e25f0dSDavid C Somayajulu 		reg_len = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_7_LEN_BB :
436611e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_7_LEN_K2_E5;
436711e25f0dSDavid C Somayajulu 		reg_crc = ECORE_IS_BB(p_dev) ? NIG_REG_ACPI_PAT_7_CRC_BB :
436811e25f0dSDavid C Somayajulu 				WOL_REG_ACPI_PAT_7_CRC_K2_E5;
436911e25f0dSDavid C Somayajulu 		break;
437011e25f0dSDavid C Somayajulu 	default:
43719efd0ba7SDavid C Somayajulu 		rc = ECORE_UNKNOWN_ERROR;
43729efd0ba7SDavid C Somayajulu 		goto out;
437311e25f0dSDavid C Somayajulu 	}
437411e25f0dSDavid C Somayajulu 
437511e25f0dSDavid C Somayajulu 	/* Allign pattern size to 4 */
437611e25f0dSDavid C Somayajulu 	while (pattern_size % 4)
437711e25f0dSDavid C Somayajulu 		pattern_size++;
437811e25f0dSDavid C Somayajulu 
4379*217ec208SDavid C Somayajulu 	/* Write pattern length and crc value */
4380*217ec208SDavid C Somayajulu 	if (ECORE_IS_BB(p_dev)) {
4381*217ec208SDavid C Somayajulu 		rc = ecore_all_ppfids_wr(p_hwfn, p_ptt, reg_len, pattern_size);
4382*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
4383*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
4384*217ec208SDavid C Somayajulu 				  "Failed to update the ACPI pattern length\n");
4385*217ec208SDavid C Somayajulu 			return rc;
4386*217ec208SDavid C Somayajulu 		}
4387*217ec208SDavid C Somayajulu 
4388*217ec208SDavid C Somayajulu 		rc = ecore_all_ppfids_wr(p_hwfn, p_ptt, reg_crc, crc);
4389*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
4390*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
4391*217ec208SDavid C Somayajulu 				  "Failed to update the ACPI pattern crc value\n");
4392*217ec208SDavid C Somayajulu 			return rc;
4393*217ec208SDavid C Somayajulu 		}
4394*217ec208SDavid C Somayajulu 	} else {
4395*217ec208SDavid C Somayajulu 		ecore_mcp_wol_wr(p_hwfn, p_ptt, reg_len, pattern_size);
4396*217ec208SDavid C Somayajulu 		ecore_mcp_wol_wr(p_hwfn, p_ptt, reg_crc, crc);
4397*217ec208SDavid C Somayajulu 	}
439811e25f0dSDavid C Somayajulu 
439911e25f0dSDavid C Somayajulu 	DP_INFO(p_dev,
440011e25f0dSDavid C Somayajulu 		"ecore_set_nwuf_reg: idx[%d] reg_crc[0x%x=0x%08x] "
440111e25f0dSDavid C Somayajulu 		"reg_len[0x%x=0x%x]\n",
440211e25f0dSDavid C Somayajulu 		reg_idx, reg_crc, crc, reg_len, pattern_size);
44039efd0ba7SDavid C Somayajulu out:
4404*217ec208SDavid C Somayajulu 	 ecore_ptt_release(p_hwfn, p_ptt);
440511e25f0dSDavid C Somayajulu 
44069efd0ba7SDavid C Somayajulu 	return rc;
440711e25f0dSDavid C Somayajulu }
440811e25f0dSDavid C Somayajulu 
ecore_wol_buffer_clear(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)44099efd0ba7SDavid C Somayajulu void ecore_wol_buffer_clear(struct ecore_hwfn *p_hwfn,
44109efd0ba7SDavid C Somayajulu 			    struct ecore_ptt *p_ptt)
441111e25f0dSDavid C Somayajulu {
441211e25f0dSDavid C Somayajulu 	const u32 wake_buffer_clear_offset =
44139efd0ba7SDavid C Somayajulu 		ECORE_IS_BB(p_hwfn->p_dev) ?
441411e25f0dSDavid C Somayajulu 		NIG_REG_WAKE_BUFFER_CLEAR_BB : WOL_REG_WAKE_BUFFER_CLEAR_K2_E5;
441511e25f0dSDavid C Somayajulu 
44169efd0ba7SDavid C Somayajulu 	DP_INFO(p_hwfn->p_dev,
441711e25f0dSDavid C Somayajulu 		"ecore_wol_buffer_clear: reset "
441811e25f0dSDavid C Somayajulu 		"REG_WAKE_BUFFER_CLEAR offset=0x%08x\n",
441911e25f0dSDavid C Somayajulu 		wake_buffer_clear_offset);
442011e25f0dSDavid C Somayajulu 
4421*217ec208SDavid C Somayajulu 	if (ECORE_IS_BB(p_hwfn->p_dev)) {
4422*217ec208SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, wake_buffer_clear_offset, 1);
4423*217ec208SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, wake_buffer_clear_offset, 0);
4424*217ec208SDavid C Somayajulu 	} else {
4425*217ec208SDavid C Somayajulu 		ecore_mcp_wol_wr(p_hwfn, p_ptt, wake_buffer_clear_offset, 1);
4426*217ec208SDavid C Somayajulu 		ecore_mcp_wol_wr(p_hwfn, p_ptt, wake_buffer_clear_offset, 0);
4427*217ec208SDavid C Somayajulu 	}
442811e25f0dSDavid C Somayajulu }
442911e25f0dSDavid C Somayajulu 
ecore_get_wake_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_wake_info * wake_info)44309efd0ba7SDavid C Somayajulu enum _ecore_status_t ecore_get_wake_info(struct ecore_hwfn *p_hwfn,
44319efd0ba7SDavid C Somayajulu 					 struct ecore_ptt *p_ptt,
443211e25f0dSDavid C Somayajulu 					 struct ecore_wake_info *wake_info)
443311e25f0dSDavid C Somayajulu {
44349efd0ba7SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
443511e25f0dSDavid C Somayajulu 	u32 *buf = OSAL_NULL;
443611e25f0dSDavid C Somayajulu 	u32 i    = 0;
443711e25f0dSDavid C Somayajulu 	const u32 reg_wake_buffer_offest =
443811e25f0dSDavid C Somayajulu 		ECORE_IS_BB(p_dev) ? NIG_REG_WAKE_BUFFER_BB :
443911e25f0dSDavid C Somayajulu 			WOL_REG_WAKE_BUFFER_K2_E5;
444011e25f0dSDavid C Somayajulu 
44419efd0ba7SDavid C Somayajulu 	wake_info->wk_info    = ecore_rd(p_hwfn, p_ptt,
444211e25f0dSDavid C Somayajulu 				ECORE_IS_BB(p_dev) ? NIG_REG_WAKE_INFO_BB :
444311e25f0dSDavid C Somayajulu 				WOL_REG_WAKE_INFO_K2_E5);
44449efd0ba7SDavid C Somayajulu 	wake_info->wk_details = ecore_rd(p_hwfn, p_ptt,
444511e25f0dSDavid C Somayajulu 				ECORE_IS_BB(p_dev) ? NIG_REG_WAKE_DETAILS_BB :
444611e25f0dSDavid C Somayajulu 				WOL_REG_WAKE_DETAILS_K2_E5);
44479efd0ba7SDavid C Somayajulu 	wake_info->wk_pkt_len = ecore_rd(p_hwfn, p_ptt,
444811e25f0dSDavid C Somayajulu 				ECORE_IS_BB(p_dev) ? NIG_REG_WAKE_PKT_LEN_BB :
444911e25f0dSDavid C Somayajulu 				WOL_REG_WAKE_PKT_LEN_K2_E5);
445011e25f0dSDavid C Somayajulu 
445111e25f0dSDavid C Somayajulu 	DP_INFO(p_dev,
445211e25f0dSDavid C Somayajulu 		"ecore_get_wake_info: REG_WAKE_INFO=0x%08x "
445311e25f0dSDavid C Somayajulu 		"REG_WAKE_DETAILS=0x%08x "
445411e25f0dSDavid C Somayajulu 		"REG_WAKE_PKT_LEN=0x%08x\n",
445511e25f0dSDavid C Somayajulu 		wake_info->wk_info,
445611e25f0dSDavid C Somayajulu 		wake_info->wk_details,
445711e25f0dSDavid C Somayajulu 		wake_info->wk_pkt_len);
445811e25f0dSDavid C Somayajulu 
445911e25f0dSDavid C Somayajulu 	buf = (u32 *)wake_info->wk_buffer;
446011e25f0dSDavid C Somayajulu 
446111e25f0dSDavid C Somayajulu 	for (i = 0; i < (wake_info->wk_pkt_len / sizeof(u32)); i++)
446211e25f0dSDavid C Somayajulu 	{
446311e25f0dSDavid C Somayajulu 		if ((i*sizeof(u32)) >=  sizeof(wake_info->wk_buffer))
446411e25f0dSDavid C Somayajulu 		{
446511e25f0dSDavid C Somayajulu 			DP_INFO(p_dev,
446611e25f0dSDavid C Somayajulu 				"ecore_get_wake_info: i index to 0 high=%d\n",
446711e25f0dSDavid C Somayajulu 				 i);
446811e25f0dSDavid C Somayajulu 			break;
446911e25f0dSDavid C Somayajulu 		}
44709efd0ba7SDavid C Somayajulu 		buf[i] = ecore_rd(p_hwfn, p_ptt,
447111e25f0dSDavid C Somayajulu 				  reg_wake_buffer_offest + (i * sizeof(u32)));
447211e25f0dSDavid C Somayajulu 		DP_INFO(p_dev, "ecore_get_wake_info: wk_buffer[%u]: 0x%08x\n",
447311e25f0dSDavid C Somayajulu 			i, buf[i]);
447411e25f0dSDavid C Somayajulu 	}
447511e25f0dSDavid C Somayajulu 
44769efd0ba7SDavid C Somayajulu 	ecore_wol_buffer_clear(p_hwfn, p_ptt);
447711e25f0dSDavid C Somayajulu 
447811e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
447911e25f0dSDavid C Somayajulu }
448011e25f0dSDavid C Somayajulu 
448111e25f0dSDavid C Somayajulu /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
ecore_hw_hwfn_free(struct ecore_hwfn * p_hwfn)448211e25f0dSDavid C Somayajulu static void ecore_hw_hwfn_free(struct ecore_hwfn *p_hwfn)
448311e25f0dSDavid C Somayajulu {
448411e25f0dSDavid C Somayajulu 	ecore_ptt_pool_free(p_hwfn);
448511e25f0dSDavid C Somayajulu 	OSAL_FREE(p_hwfn->p_dev, p_hwfn->hw_info.p_igu_info);
448611e25f0dSDavid C Somayajulu 	p_hwfn->hw_info.p_igu_info = OSAL_NULL;
448711e25f0dSDavid C Somayajulu }
448811e25f0dSDavid C Somayajulu 
448911e25f0dSDavid C Somayajulu /* Setup bar access */
ecore_hw_hwfn_prepare(struct ecore_hwfn * p_hwfn)449011e25f0dSDavid C Somayajulu static void ecore_hw_hwfn_prepare(struct ecore_hwfn *p_hwfn)
449111e25f0dSDavid C Somayajulu {
449211e25f0dSDavid C Somayajulu 	/* clear indirect access */
449311e25f0dSDavid C Somayajulu 	if (ECORE_IS_AH(p_hwfn->p_dev) || ECORE_IS_E5(p_hwfn->p_dev)) {
449411e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
449511e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_E8_F0_K2_E5, 0);
449611e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
449711e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_EC_F0_K2_E5, 0);
449811e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
449911e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_F0_F0_K2_E5, 0);
450011e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
450111e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_F4_F0_K2_E5, 0);
450211e25f0dSDavid C Somayajulu 	} else {
450311e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
450411e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
450511e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
450611e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
450711e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
450811e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
450911e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
451011e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
451111e25f0dSDavid C Somayajulu 	}
451211e25f0dSDavid C Somayajulu 
4513*217ec208SDavid C Somayajulu 	/* Clean previous pglue_b errors if such exist */
4514*217ec208SDavid C Somayajulu 	ecore_pglueb_clear_err(p_hwfn, p_hwfn->p_main_ptt);
451511e25f0dSDavid C Somayajulu 
451611e25f0dSDavid C Somayajulu 	/* enable internal target-read */
451711e25f0dSDavid C Somayajulu 	ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
451811e25f0dSDavid C Somayajulu 		 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
451911e25f0dSDavid C Somayajulu }
452011e25f0dSDavid C Somayajulu 
get_function_id(struct ecore_hwfn * p_hwfn)452111e25f0dSDavid C Somayajulu static void get_function_id(struct ecore_hwfn *p_hwfn)
452211e25f0dSDavid C Somayajulu {
452311e25f0dSDavid C Somayajulu 	/* ME Register */
452411e25f0dSDavid C Somayajulu 	p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
452511e25f0dSDavid C Somayajulu 						  PXP_PF_ME_OPAQUE_ADDR);
452611e25f0dSDavid C Somayajulu 
452711e25f0dSDavid C Somayajulu 	p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
452811e25f0dSDavid C Somayajulu 
452911e25f0dSDavid C Somayajulu 	/* Bits 16-19 from the ME registers are the pf_num */
453011e25f0dSDavid C Somayajulu 	p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
453111e25f0dSDavid C Somayajulu 	p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
453211e25f0dSDavid C Somayajulu 				      PXP_CONCRETE_FID_PFID);
453311e25f0dSDavid C Somayajulu 	p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
453411e25f0dSDavid C Somayajulu 				    PXP_CONCRETE_FID_PORT);
453511e25f0dSDavid C Somayajulu 
453611e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
453711e25f0dSDavid C Somayajulu 		   "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
453811e25f0dSDavid C Somayajulu 		   p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
453911e25f0dSDavid C Somayajulu }
454011e25f0dSDavid C Somayajulu 
ecore_hw_set_feat(struct ecore_hwfn * p_hwfn)454111e25f0dSDavid C Somayajulu void ecore_hw_set_feat(struct ecore_hwfn *p_hwfn)
454211e25f0dSDavid C Somayajulu {
454311e25f0dSDavid C Somayajulu 	u32 *feat_num = p_hwfn->hw_info.feat_num;
454411e25f0dSDavid C Somayajulu 	struct ecore_sb_cnt_info sb_cnt;
454511e25f0dSDavid C Somayajulu 	u32 non_l2_sbs = 0;
454611e25f0dSDavid C Somayajulu 
454711e25f0dSDavid C Somayajulu 	OSAL_MEM_ZERO(&sb_cnt, sizeof(sb_cnt));
454811e25f0dSDavid C Somayajulu 	ecore_int_get_num_sbs(p_hwfn, &sb_cnt);
454911e25f0dSDavid C Somayajulu 
455011e25f0dSDavid C Somayajulu #ifdef CONFIG_ECORE_ROCE
455111e25f0dSDavid C Somayajulu 	/* Roce CNQ require each: 1 status block. 1 CNQ, we divide the
455211e25f0dSDavid C Somayajulu 	 * status blocks equally between L2 / RoCE but with consideration as
455311e25f0dSDavid C Somayajulu 	 * to how many l2 queues / cnqs we have
455411e25f0dSDavid C Somayajulu 	 */
455511e25f0dSDavid C Somayajulu 	if (ECORE_IS_RDMA_PERSONALITY(p_hwfn)) {
4556*217ec208SDavid C Somayajulu #ifndef __EXTRACT__LINUX__THROW__
455711e25f0dSDavid C Somayajulu 		u32 max_cnqs;
4558*217ec208SDavid C Somayajulu #endif
455911e25f0dSDavid C Somayajulu 
456011e25f0dSDavid C Somayajulu 		feat_num[ECORE_RDMA_CNQ] =
456111e25f0dSDavid C Somayajulu 			OSAL_MIN_T(u32,
456211e25f0dSDavid C Somayajulu 				   sb_cnt.cnt / 2,
456311e25f0dSDavid C Somayajulu 				   RESC_NUM(p_hwfn, ECORE_RDMA_CNQ_RAM));
456411e25f0dSDavid C Somayajulu 
4565*217ec208SDavid C Somayajulu #ifndef __EXTRACT__LINUX__THROW__
456611e25f0dSDavid C Somayajulu 		/* Upper layer might require less */
456711e25f0dSDavid C Somayajulu 		max_cnqs = (u32)p_hwfn->pf_params.rdma_pf_params.max_cnqs;
456811e25f0dSDavid C Somayajulu 		if (max_cnqs) {
456911e25f0dSDavid C Somayajulu 			if (max_cnqs == ECORE_RDMA_PF_PARAMS_CNQS_NONE)
457011e25f0dSDavid C Somayajulu 				max_cnqs = 0;
457111e25f0dSDavid C Somayajulu 			feat_num[ECORE_RDMA_CNQ] =
457211e25f0dSDavid C Somayajulu 				OSAL_MIN_T(u32,
457311e25f0dSDavid C Somayajulu 					   feat_num[ECORE_RDMA_CNQ],
457411e25f0dSDavid C Somayajulu 					   max_cnqs);
457511e25f0dSDavid C Somayajulu 		}
4576*217ec208SDavid C Somayajulu #endif
457711e25f0dSDavid C Somayajulu 
457811e25f0dSDavid C Somayajulu 		non_l2_sbs = feat_num[ECORE_RDMA_CNQ];
457911e25f0dSDavid C Somayajulu 	}
458011e25f0dSDavid C Somayajulu #endif
458111e25f0dSDavid C Somayajulu 
458211e25f0dSDavid C Somayajulu 	/* L2 Queues require each: 1 status block. 1 L2 queue */
458311e25f0dSDavid C Somayajulu 	if (ECORE_IS_L2_PERSONALITY(p_hwfn)) {
458411e25f0dSDavid C Somayajulu 		/* Start by allocating VF queues, then PF's */
458511e25f0dSDavid C Somayajulu 		feat_num[ECORE_VF_L2_QUE] =
458611e25f0dSDavid C Somayajulu 			OSAL_MIN_T(u32,
458711e25f0dSDavid C Somayajulu 				   RESC_NUM(p_hwfn, ECORE_L2_QUEUE),
458811e25f0dSDavid C Somayajulu 				   sb_cnt.iov_cnt);
458911e25f0dSDavid C Somayajulu 		feat_num[ECORE_PF_L2_QUE] =
459011e25f0dSDavid C Somayajulu 			OSAL_MIN_T(u32,
459111e25f0dSDavid C Somayajulu 				   sb_cnt.cnt - non_l2_sbs,
459211e25f0dSDavid C Somayajulu 				   RESC_NUM(p_hwfn, ECORE_L2_QUEUE) -
459311e25f0dSDavid C Somayajulu 				   FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE));
459411e25f0dSDavid C Somayajulu 	}
459511e25f0dSDavid C Somayajulu 
459611e25f0dSDavid C Somayajulu 	if (ECORE_IS_FCOE_PERSONALITY(p_hwfn))
459711e25f0dSDavid C Somayajulu 		feat_num[ECORE_FCOE_CQ] =
459811e25f0dSDavid C Somayajulu 			OSAL_MIN_T(u32, sb_cnt.cnt, RESC_NUM(p_hwfn,
459911e25f0dSDavid C Somayajulu 							     ECORE_CMDQS_CQS));
460011e25f0dSDavid C Somayajulu 
460111e25f0dSDavid C Somayajulu 	if (ECORE_IS_ISCSI_PERSONALITY(p_hwfn))
460211e25f0dSDavid C Somayajulu 		feat_num[ECORE_ISCSI_CQ] =
460311e25f0dSDavid C Somayajulu 			OSAL_MIN_T(u32, sb_cnt.cnt, RESC_NUM(p_hwfn,
460411e25f0dSDavid C Somayajulu 							     ECORE_CMDQS_CQS));
460511e25f0dSDavid C Somayajulu 
460611e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
460711e25f0dSDavid C Somayajulu 		   "#PF_L2_QUEUE=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d #FCOE_CQ=%d #ISCSI_CQ=%d #SB=%d\n",
460811e25f0dSDavid C Somayajulu 		   (int)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE),
460911e25f0dSDavid C Somayajulu 		   (int)FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE),
461011e25f0dSDavid C Somayajulu 		   (int)FEAT_NUM(p_hwfn, ECORE_RDMA_CNQ),
461111e25f0dSDavid C Somayajulu 		   (int)FEAT_NUM(p_hwfn, ECORE_FCOE_CQ),
461211e25f0dSDavid C Somayajulu 		   (int)FEAT_NUM(p_hwfn, ECORE_ISCSI_CQ),
461311e25f0dSDavid C Somayajulu 		   (int)sb_cnt.cnt);
461411e25f0dSDavid C Somayajulu }
461511e25f0dSDavid C Somayajulu 
ecore_hw_get_resc_name(enum ecore_resources res_id)461611e25f0dSDavid C Somayajulu const char *ecore_hw_get_resc_name(enum ecore_resources res_id)
461711e25f0dSDavid C Somayajulu {
461811e25f0dSDavid C Somayajulu 	switch (res_id) {
461911e25f0dSDavid C Somayajulu 	case ECORE_L2_QUEUE:
462011e25f0dSDavid C Somayajulu 		return "L2_QUEUE";
462111e25f0dSDavid C Somayajulu 	case ECORE_VPORT:
462211e25f0dSDavid C Somayajulu 		return "VPORT";
462311e25f0dSDavid C Somayajulu 	case ECORE_RSS_ENG:
462411e25f0dSDavid C Somayajulu 		return "RSS_ENG";
462511e25f0dSDavid C Somayajulu 	case ECORE_PQ:
462611e25f0dSDavid C Somayajulu 		return "PQ";
462711e25f0dSDavid C Somayajulu 	case ECORE_RL:
462811e25f0dSDavid C Somayajulu 		return "RL";
462911e25f0dSDavid C Somayajulu 	case ECORE_MAC:
463011e25f0dSDavid C Somayajulu 		return "MAC";
463111e25f0dSDavid C Somayajulu 	case ECORE_VLAN:
463211e25f0dSDavid C Somayajulu 		return "VLAN";
463311e25f0dSDavid C Somayajulu 	case ECORE_RDMA_CNQ_RAM:
463411e25f0dSDavid C Somayajulu 		return "RDMA_CNQ_RAM";
463511e25f0dSDavid C Somayajulu 	case ECORE_ILT:
463611e25f0dSDavid C Somayajulu 		return "ILT";
463711e25f0dSDavid C Somayajulu 	case ECORE_LL2_QUEUE:
463811e25f0dSDavid C Somayajulu 		return "LL2_QUEUE";
463911e25f0dSDavid C Somayajulu 	case ECORE_CMDQS_CQS:
464011e25f0dSDavid C Somayajulu 		return "CMDQS_CQS";
464111e25f0dSDavid C Somayajulu 	case ECORE_RDMA_STATS_QUEUE:
464211e25f0dSDavid C Somayajulu 		return "RDMA_STATS_QUEUE";
464311e25f0dSDavid C Somayajulu 	case ECORE_BDQ:
464411e25f0dSDavid C Somayajulu 		return "BDQ";
464511e25f0dSDavid C Somayajulu 	case ECORE_SB:
464611e25f0dSDavid C Somayajulu 		return "SB";
464711e25f0dSDavid C Somayajulu 	default:
464811e25f0dSDavid C Somayajulu 		return "UNKNOWN_RESOURCE";
464911e25f0dSDavid C Somayajulu 	}
465011e25f0dSDavid C Somayajulu }
465111e25f0dSDavid C Somayajulu 
465211e25f0dSDavid C Somayajulu static enum _ecore_status_t
__ecore_hw_set_soft_resc_size(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_resources res_id,u32 resc_max_val,u32 * p_mcp_resp)465311e25f0dSDavid C Somayajulu __ecore_hw_set_soft_resc_size(struct ecore_hwfn *p_hwfn,
46549efd0ba7SDavid C Somayajulu 			      struct ecore_ptt *p_ptt,
46559efd0ba7SDavid C Somayajulu 			      enum ecore_resources res_id,
46569efd0ba7SDavid C Somayajulu 			      u32 resc_max_val,
465711e25f0dSDavid C Somayajulu 			      u32 *p_mcp_resp)
465811e25f0dSDavid C Somayajulu {
465911e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
466011e25f0dSDavid C Somayajulu 
46619efd0ba7SDavid C Somayajulu 	rc = ecore_mcp_set_resc_max_val(p_hwfn, p_ptt, res_id,
466211e25f0dSDavid C Somayajulu 					resc_max_val, p_mcp_resp);
466311e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS) {
4664*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
466511e25f0dSDavid C Somayajulu 			  "MFW response failure for a max value setting of resource %d [%s]\n",
466611e25f0dSDavid C Somayajulu 			  res_id, ecore_hw_get_resc_name(res_id));
466711e25f0dSDavid C Somayajulu 		return rc;
466811e25f0dSDavid C Somayajulu 	}
466911e25f0dSDavid C Somayajulu 
467011e25f0dSDavid C Somayajulu 	if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
467111e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
467211e25f0dSDavid C Somayajulu 			"Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
467311e25f0dSDavid C Somayajulu 			res_id, ecore_hw_get_resc_name(res_id), *p_mcp_resp);
467411e25f0dSDavid C Somayajulu 
467511e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
467611e25f0dSDavid C Somayajulu }
467711e25f0dSDavid C Somayajulu 
467811e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_hw_set_soft_resc_size(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)46799efd0ba7SDavid C Somayajulu ecore_hw_set_soft_resc_size(struct ecore_hwfn *p_hwfn,
46809efd0ba7SDavid C Somayajulu 			    struct ecore_ptt *p_ptt)
468111e25f0dSDavid C Somayajulu {
468211e25f0dSDavid C Somayajulu 	bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
468311e25f0dSDavid C Somayajulu 	u32 resc_max_val, mcp_resp;
468411e25f0dSDavid C Somayajulu 	u8 res_id;
468511e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
468611e25f0dSDavid C Somayajulu 
468711e25f0dSDavid C Somayajulu 	for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
468811e25f0dSDavid C Somayajulu 		switch (res_id) {
468911e25f0dSDavid C Somayajulu 		case ECORE_LL2_QUEUE:
469011e25f0dSDavid C Somayajulu 			resc_max_val = MAX_NUM_LL2_RX_QUEUES;
469111e25f0dSDavid C Somayajulu 			break;
469211e25f0dSDavid C Somayajulu 		case ECORE_RDMA_CNQ_RAM:
469311e25f0dSDavid C Somayajulu 			/* No need for a case for ECORE_CMDQS_CQS since
469411e25f0dSDavid C Somayajulu 			 * CNQ/CMDQS are the same resource.
469511e25f0dSDavid C Somayajulu 			 */
4696*217ec208SDavid C Somayajulu 			resc_max_val = NUM_OF_GLOBAL_QUEUES;
469711e25f0dSDavid C Somayajulu 			break;
469811e25f0dSDavid C Somayajulu 		case ECORE_RDMA_STATS_QUEUE:
469911e25f0dSDavid C Somayajulu 			resc_max_val = b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2
470011e25f0dSDavid C Somayajulu 					    : RDMA_NUM_STATISTIC_COUNTERS_BB;
470111e25f0dSDavid C Somayajulu 			break;
470211e25f0dSDavid C Somayajulu 		case ECORE_BDQ:
470311e25f0dSDavid C Somayajulu 			resc_max_val = BDQ_NUM_RESOURCES;
470411e25f0dSDavid C Somayajulu 			break;
470511e25f0dSDavid C Somayajulu 		default:
470611e25f0dSDavid C Somayajulu 			continue;
470711e25f0dSDavid C Somayajulu 		}
470811e25f0dSDavid C Somayajulu 
47099efd0ba7SDavid C Somayajulu 		rc = __ecore_hw_set_soft_resc_size(p_hwfn, p_ptt, res_id,
471011e25f0dSDavid C Somayajulu 						   resc_max_val, &mcp_resp);
471111e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
471211e25f0dSDavid C Somayajulu 			return rc;
471311e25f0dSDavid C Somayajulu 
471411e25f0dSDavid C Somayajulu 		/* There's no point to continue to the next resource if the
471511e25f0dSDavid C Somayajulu 		 * command is not supported by the MFW.
471611e25f0dSDavid C Somayajulu 		 * We do continue if the command is supported but the resource
471711e25f0dSDavid C Somayajulu 		 * is unknown to the MFW. Such a resource will be later
471811e25f0dSDavid C Somayajulu 		 * configured with the default allocation values.
471911e25f0dSDavid C Somayajulu 		 */
472011e25f0dSDavid C Somayajulu 		if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
472111e25f0dSDavid C Somayajulu 			return ECORE_NOTIMPL;
472211e25f0dSDavid C Somayajulu 	}
472311e25f0dSDavid C Somayajulu 
472411e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
472511e25f0dSDavid C Somayajulu }
472611e25f0dSDavid C Somayajulu 
472711e25f0dSDavid C Somayajulu static
ecore_hw_get_dflt_resc(struct ecore_hwfn * p_hwfn,enum ecore_resources res_id,u32 * p_resc_num,u32 * p_resc_start)472811e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_hw_get_dflt_resc(struct ecore_hwfn *p_hwfn,
472911e25f0dSDavid C Somayajulu 					    enum ecore_resources res_id,
473011e25f0dSDavid C Somayajulu 					    u32 *p_resc_num, u32 *p_resc_start)
473111e25f0dSDavid C Somayajulu {
473211e25f0dSDavid C Somayajulu 	u8 num_funcs = p_hwfn->num_funcs_on_engine;
473311e25f0dSDavid C Somayajulu 	bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
473411e25f0dSDavid C Somayajulu 
473511e25f0dSDavid C Somayajulu 	switch (res_id) {
473611e25f0dSDavid C Somayajulu 	case ECORE_L2_QUEUE:
473711e25f0dSDavid C Somayajulu 		*p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
473811e25f0dSDavid C Somayajulu 				      MAX_NUM_L2_QUEUES_BB) / num_funcs;
473911e25f0dSDavid C Somayajulu 		break;
474011e25f0dSDavid C Somayajulu 	case ECORE_VPORT:
474111e25f0dSDavid C Somayajulu 		*p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
474211e25f0dSDavid C Somayajulu 				      MAX_NUM_VPORTS_BB) / num_funcs;
474311e25f0dSDavid C Somayajulu 		break;
474411e25f0dSDavid C Somayajulu 	case ECORE_RSS_ENG:
474511e25f0dSDavid C Somayajulu 		*p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
474611e25f0dSDavid C Somayajulu 				      ETH_RSS_ENGINE_NUM_BB) / num_funcs;
474711e25f0dSDavid C Somayajulu 		break;
474811e25f0dSDavid C Somayajulu 	case ECORE_PQ:
474911e25f0dSDavid C Somayajulu 		*p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
475011e25f0dSDavid C Somayajulu 				      MAX_QM_TX_QUEUES_BB) / num_funcs;
475111e25f0dSDavid C Somayajulu 		*p_resc_num &= ~0x7; /* The granularity of the PQs is 8 */
475211e25f0dSDavid C Somayajulu 		break;
475311e25f0dSDavid C Somayajulu 	case ECORE_RL:
475411e25f0dSDavid C Somayajulu 		*p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
475511e25f0dSDavid C Somayajulu 		break;
475611e25f0dSDavid C Somayajulu 	case ECORE_MAC:
475711e25f0dSDavid C Somayajulu 	case ECORE_VLAN:
475811e25f0dSDavid C Somayajulu 		/* Each VFC resource can accommodate both a MAC and a VLAN */
475911e25f0dSDavid C Somayajulu 		*p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
476011e25f0dSDavid C Somayajulu 		break;
476111e25f0dSDavid C Somayajulu 	case ECORE_ILT:
476211e25f0dSDavid C Somayajulu 		*p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
476311e25f0dSDavid C Somayajulu 				      PXP_NUM_ILT_RECORDS_BB) / num_funcs;
476411e25f0dSDavid C Somayajulu 		break;
476511e25f0dSDavid C Somayajulu 	case ECORE_LL2_QUEUE:
476611e25f0dSDavid C Somayajulu 		*p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
476711e25f0dSDavid C Somayajulu 		break;
476811e25f0dSDavid C Somayajulu 	case ECORE_RDMA_CNQ_RAM:
476911e25f0dSDavid C Somayajulu 	case ECORE_CMDQS_CQS:
477011e25f0dSDavid C Somayajulu 		/* CNQ/CMDQS are the same resource */
4771*217ec208SDavid C Somayajulu 		*p_resc_num = NUM_OF_GLOBAL_QUEUES / num_funcs;
477211e25f0dSDavid C Somayajulu 		break;
477311e25f0dSDavid C Somayajulu 	case ECORE_RDMA_STATS_QUEUE:
477411e25f0dSDavid C Somayajulu 		*p_resc_num = (b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2 :
477511e25f0dSDavid C Somayajulu 				      RDMA_NUM_STATISTIC_COUNTERS_BB) /
477611e25f0dSDavid C Somayajulu 			      num_funcs;
477711e25f0dSDavid C Somayajulu 		break;
477811e25f0dSDavid C Somayajulu 	case ECORE_BDQ:
477911e25f0dSDavid C Somayajulu 		if (p_hwfn->hw_info.personality != ECORE_PCI_ISCSI &&
478011e25f0dSDavid C Somayajulu 		    p_hwfn->hw_info.personality != ECORE_PCI_FCOE)
478111e25f0dSDavid C Somayajulu 			*p_resc_num = 0;
478211e25f0dSDavid C Somayajulu 		else
478311e25f0dSDavid C Somayajulu 			*p_resc_num = 1;
478411e25f0dSDavid C Somayajulu 		break;
478511e25f0dSDavid C Somayajulu 	case ECORE_SB:
478611e25f0dSDavid C Somayajulu 		/* Since we want its value to reflect whether MFW supports
478711e25f0dSDavid C Somayajulu 		 * the new scheme, have a default of 0.
478811e25f0dSDavid C Somayajulu 		 */
478911e25f0dSDavid C Somayajulu 		*p_resc_num = 0;
479011e25f0dSDavid C Somayajulu 		break;
479111e25f0dSDavid C Somayajulu 	default:
479211e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
479311e25f0dSDavid C Somayajulu 	}
479411e25f0dSDavid C Somayajulu 
479511e25f0dSDavid C Somayajulu 	switch (res_id) {
479611e25f0dSDavid C Somayajulu 	case ECORE_BDQ:
479711e25f0dSDavid C Somayajulu 		if (!*p_resc_num)
479811e25f0dSDavid C Somayajulu 			*p_resc_start = 0;
47999efd0ba7SDavid C Somayajulu 		else if (p_hwfn->p_dev->num_ports_in_engine == 4)
480011e25f0dSDavid C Somayajulu 			*p_resc_start = p_hwfn->port_id;
480111e25f0dSDavid C Somayajulu 		else if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI)
480211e25f0dSDavid C Somayajulu 			*p_resc_start = p_hwfn->port_id;
480311e25f0dSDavid C Somayajulu 		else if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE)
480411e25f0dSDavid C Somayajulu 			*p_resc_start = p_hwfn->port_id + 2;
480511e25f0dSDavid C Somayajulu 		break;
480611e25f0dSDavid C Somayajulu 	default:
480711e25f0dSDavid C Somayajulu 		*p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
480811e25f0dSDavid C Somayajulu 		break;
480911e25f0dSDavid C Somayajulu 	}
481011e25f0dSDavid C Somayajulu 
481111e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
481211e25f0dSDavid C Somayajulu }
481311e25f0dSDavid C Somayajulu 
481411e25f0dSDavid C Somayajulu static enum _ecore_status_t
__ecore_hw_set_resc_info(struct ecore_hwfn * p_hwfn,enum ecore_resources res_id,bool drv_resc_alloc)481511e25f0dSDavid C Somayajulu __ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn, enum ecore_resources res_id,
481611e25f0dSDavid C Somayajulu 			 bool drv_resc_alloc)
481711e25f0dSDavid C Somayajulu {
481811e25f0dSDavid C Somayajulu 	u32 dflt_resc_num = 0, dflt_resc_start = 0;
481911e25f0dSDavid C Somayajulu 	u32 mcp_resp, *p_resc_num, *p_resc_start;
482011e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
482111e25f0dSDavid C Somayajulu 
482211e25f0dSDavid C Somayajulu 	p_resc_num = &RESC_NUM(p_hwfn, res_id);
482311e25f0dSDavid C Somayajulu 	p_resc_start = &RESC_START(p_hwfn, res_id);
482411e25f0dSDavid C Somayajulu 
482511e25f0dSDavid C Somayajulu 	rc = ecore_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
482611e25f0dSDavid C Somayajulu 				    &dflt_resc_start);
482711e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS) {
482811e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn,
482911e25f0dSDavid C Somayajulu 		       "Failed to get default amount for resource %d [%s]\n",
483011e25f0dSDavid C Somayajulu 			res_id, ecore_hw_get_resc_name(res_id));
483111e25f0dSDavid C Somayajulu 		return rc;
483211e25f0dSDavid C Somayajulu 	}
483311e25f0dSDavid C Somayajulu 
483411e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
483511e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
483611e25f0dSDavid C Somayajulu 		*p_resc_num = dflt_resc_num;
483711e25f0dSDavid C Somayajulu 		*p_resc_start = dflt_resc_start;
483811e25f0dSDavid C Somayajulu 		goto out;
483911e25f0dSDavid C Somayajulu 	}
484011e25f0dSDavid C Somayajulu #endif
484111e25f0dSDavid C Somayajulu 
484211e25f0dSDavid C Somayajulu 	rc = ecore_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
484311e25f0dSDavid C Somayajulu 				     &mcp_resp, p_resc_num, p_resc_start);
484411e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS) {
4845*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
484611e25f0dSDavid C Somayajulu 			  "MFW response failure for an allocation request for resource %d [%s]\n",
484711e25f0dSDavid C Somayajulu 			  res_id, ecore_hw_get_resc_name(res_id));
484811e25f0dSDavid C Somayajulu 		return rc;
484911e25f0dSDavid C Somayajulu 	}
485011e25f0dSDavid C Somayajulu 
485111e25f0dSDavid C Somayajulu 	/* Default driver values are applied in the following cases:
485211e25f0dSDavid C Somayajulu 	 * - The resource allocation MB command is not supported by the MFW
485311e25f0dSDavid C Somayajulu 	 * - There is an internal error in the MFW while processing the request
485411e25f0dSDavid C Somayajulu 	 * - The resource ID is unknown to the MFW
485511e25f0dSDavid C Somayajulu 	 */
485611e25f0dSDavid C Somayajulu 	if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
485711e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
485811e25f0dSDavid C Somayajulu 			"Failed to receive allocation info for resource %d [%s]. mcp_resp = 0x%x. Applying default values [%d,%d].\n",
485911e25f0dSDavid C Somayajulu 			res_id, ecore_hw_get_resc_name(res_id), mcp_resp,
486011e25f0dSDavid C Somayajulu 			dflt_resc_num, dflt_resc_start);
486111e25f0dSDavid C Somayajulu 		*p_resc_num = dflt_resc_num;
486211e25f0dSDavid C Somayajulu 		*p_resc_start = dflt_resc_start;
486311e25f0dSDavid C Somayajulu 		goto out;
486411e25f0dSDavid C Somayajulu 	}
486511e25f0dSDavid C Somayajulu 
486611e25f0dSDavid C Somayajulu 	if ((*p_resc_num != dflt_resc_num ||
486711e25f0dSDavid C Somayajulu 	     *p_resc_start != dflt_resc_start) &&
486811e25f0dSDavid C Somayajulu 	    res_id != ECORE_SB) {
486911e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
487011e25f0dSDavid C Somayajulu 			"MFW allocation for resource %d [%s] differs from default values [%d,%d vs. %d,%d]%s\n",
487111e25f0dSDavid C Somayajulu 			res_id, ecore_hw_get_resc_name(res_id), *p_resc_num,
487211e25f0dSDavid C Somayajulu 			*p_resc_start, dflt_resc_num, dflt_resc_start,
487311e25f0dSDavid C Somayajulu 			drv_resc_alloc ? " - Applying default values" : "");
487411e25f0dSDavid C Somayajulu 		if (drv_resc_alloc) {
487511e25f0dSDavid C Somayajulu 			*p_resc_num = dflt_resc_num;
487611e25f0dSDavid C Somayajulu 			*p_resc_start = dflt_resc_start;
487711e25f0dSDavid C Somayajulu 		}
487811e25f0dSDavid C Somayajulu 	}
487911e25f0dSDavid C Somayajulu out:
488011e25f0dSDavid C Somayajulu 	/* PQs have to divide by 8 [that's the HW granularity].
488111e25f0dSDavid C Somayajulu 	 * Reduce number so it would fit.
488211e25f0dSDavid C Somayajulu 	 */
488311e25f0dSDavid C Somayajulu 	if ((res_id == ECORE_PQ) &&
488411e25f0dSDavid C Somayajulu 	    ((*p_resc_num % 8) || (*p_resc_start % 8))) {
488511e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
488611e25f0dSDavid C Somayajulu 			"PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n",
488711e25f0dSDavid C Somayajulu 			*p_resc_num, (*p_resc_num) & ~0x7,
488811e25f0dSDavid C Somayajulu 			*p_resc_start, (*p_resc_start) & ~0x7);
488911e25f0dSDavid C Somayajulu 		*p_resc_num &= ~0x7;
489011e25f0dSDavid C Somayajulu 		*p_resc_start &= ~0x7;
489111e25f0dSDavid C Somayajulu 	}
489211e25f0dSDavid C Somayajulu 
489311e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
489411e25f0dSDavid C Somayajulu }
489511e25f0dSDavid C Somayajulu 
ecore_hw_set_resc_info(struct ecore_hwfn * p_hwfn,bool drv_resc_alloc)489611e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn,
489711e25f0dSDavid C Somayajulu 						   bool drv_resc_alloc)
489811e25f0dSDavid C Somayajulu {
489911e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
490011e25f0dSDavid C Somayajulu 	u8 res_id;
490111e25f0dSDavid C Somayajulu 
490211e25f0dSDavid C Somayajulu 	for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
490311e25f0dSDavid C Somayajulu 		rc = __ecore_hw_set_resc_info(p_hwfn, res_id, drv_resc_alloc);
490411e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
490511e25f0dSDavid C Somayajulu 			return rc;
490611e25f0dSDavid C Somayajulu 	}
490711e25f0dSDavid C Somayajulu 
490811e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
490911e25f0dSDavid C Somayajulu }
491011e25f0dSDavid C Somayajulu 
ecore_hw_get_ppfid_bitmap(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)4911*217ec208SDavid C Somayajulu static enum _ecore_status_t ecore_hw_get_ppfid_bitmap(struct ecore_hwfn *p_hwfn,
4912*217ec208SDavid C Somayajulu 						      struct ecore_ptt *p_ptt)
4913*217ec208SDavid C Somayajulu {
4914*217ec208SDavid C Somayajulu 	u8 native_ppfid_idx = ECORE_PPFID_BY_PFID(p_hwfn);
4915*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
4916*217ec208SDavid C Somayajulu 	enum _ecore_status_t rc;
4917*217ec208SDavid C Somayajulu 
4918*217ec208SDavid C Somayajulu 	rc = ecore_mcp_get_ppfid_bitmap(p_hwfn, p_ptt);
4919*217ec208SDavid C Somayajulu 	if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL)
4920*217ec208SDavid C Somayajulu 		return rc;
4921*217ec208SDavid C Somayajulu 	else if (rc == ECORE_NOTIMPL)
4922*217ec208SDavid C Somayajulu 		p_dev->ppfid_bitmap = 0x1 << native_ppfid_idx;
4923*217ec208SDavid C Somayajulu 
4924*217ec208SDavid C Somayajulu 	if (!(p_dev->ppfid_bitmap & (0x1 << native_ppfid_idx))) {
4925*217ec208SDavid C Somayajulu 		DP_INFO(p_hwfn,
4926*217ec208SDavid C Somayajulu 			"Fix the PPFID bitmap to inculde the native PPFID [native_ppfid_idx %hhd, orig_bitmap 0x%hhx]\n",
4927*217ec208SDavid C Somayajulu 			native_ppfid_idx, p_dev->ppfid_bitmap);
4928*217ec208SDavid C Somayajulu 		p_dev->ppfid_bitmap = 0x1 << native_ppfid_idx;
4929*217ec208SDavid C Somayajulu 	}
4930*217ec208SDavid C Somayajulu 
4931*217ec208SDavid C Somayajulu 	return ECORE_SUCCESS;
4932*217ec208SDavid C Somayajulu }
4933*217ec208SDavid C Somayajulu 
ecore_hw_get_resc(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,bool drv_resc_alloc)493411e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_hw_get_resc(struct ecore_hwfn *p_hwfn,
49359efd0ba7SDavid C Somayajulu 					      struct ecore_ptt *p_ptt,
493611e25f0dSDavid C Somayajulu 					      bool drv_resc_alloc)
493711e25f0dSDavid C Somayajulu {
493811e25f0dSDavid C Somayajulu 	struct ecore_resc_unlock_params resc_unlock_params;
493911e25f0dSDavid C Somayajulu 	struct ecore_resc_lock_params resc_lock_params;
494011e25f0dSDavid C Somayajulu 	bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
494111e25f0dSDavid C Somayajulu 	u8 res_id;
494211e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
494311e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
494411e25f0dSDavid C Somayajulu 	u32 *resc_start = p_hwfn->hw_info.resc_start;
494511e25f0dSDavid C Somayajulu 	u32 *resc_num = p_hwfn->hw_info.resc_num;
494611e25f0dSDavid C Somayajulu 	/* For AH, an equal share of the ILT lines between the maximal number of
494711e25f0dSDavid C Somayajulu 	 * PFs is not enough for RoCE. This would be solved by the future
494811e25f0dSDavid C Somayajulu 	 * resource allocation scheme, but isn't currently present for
494911e25f0dSDavid C Somayajulu 	 * FPGA/emulation. For now we keep a number that is sufficient for RoCE
495011e25f0dSDavid C Somayajulu 	 * to work - the BB number of ILT lines divided by its max PFs number.
495111e25f0dSDavid C Somayajulu 	 */
495211e25f0dSDavid C Somayajulu 	u32 roce_min_ilt_lines = PXP_NUM_ILT_RECORDS_BB / MAX_NUM_PFS_BB;
495311e25f0dSDavid C Somayajulu #endif
495411e25f0dSDavid C Somayajulu 
495511e25f0dSDavid C Somayajulu 	/* Setting the max values of the soft resources and the following
495611e25f0dSDavid C Somayajulu 	 * resources allocation queries should be atomic. Since several PFs can
495711e25f0dSDavid C Somayajulu 	 * run in parallel - a resource lock is needed.
495811e25f0dSDavid C Somayajulu 	 * If either the resource lock or resource set value commands are not
495911e25f0dSDavid C Somayajulu 	 * supported - skip the the max values setting, release the lock if
496011e25f0dSDavid C Somayajulu 	 * needed, and proceed to the queries. Other failures, including a
496111e25f0dSDavid C Somayajulu 	 * failure to acquire the lock, will cause this function to fail.
496211e25f0dSDavid C Somayajulu 	 * Old drivers that don't acquire the lock can run in parallel, and
496311e25f0dSDavid C Somayajulu 	 * their allocation values won't be affected by the updated max values.
496411e25f0dSDavid C Somayajulu 	 */
4965*217ec208SDavid C Somayajulu 
49669efd0ba7SDavid C Somayajulu 	ecore_mcp_resc_lock_default_init(&resc_lock_params, &resc_unlock_params,
49679efd0ba7SDavid C Somayajulu 					 ECORE_RESC_LOCK_RESC_ALLOC, false);
496811e25f0dSDavid C Somayajulu 
4969*217ec208SDavid C Somayajulu 	/* Changes on top of the default values to accommodate parallel attempts
4970*217ec208SDavid C Somayajulu 	 * of several PFs.
4971*217ec208SDavid C Somayajulu 	 * [10 x 10 msec by default ==> 20 x 50 msec]
4972*217ec208SDavid C Somayajulu 	 */
4973*217ec208SDavid C Somayajulu 	resc_lock_params.retry_num *= 2;
4974*217ec208SDavid C Somayajulu 	resc_lock_params.retry_interval *= 5;
4975*217ec208SDavid C Somayajulu 
49769efd0ba7SDavid C Somayajulu 	rc = ecore_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
497711e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
497811e25f0dSDavid C Somayajulu 		return rc;
497911e25f0dSDavid C Somayajulu 	} else if (rc == ECORE_NOTIMPL) {
498011e25f0dSDavid C Somayajulu 		DP_INFO(p_hwfn,
498111e25f0dSDavid C Somayajulu 			"Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
498211e25f0dSDavid C Somayajulu 	} else if (rc == ECORE_SUCCESS && !resc_lock_params.b_granted) {
498311e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
498411e25f0dSDavid C Somayajulu 			  "Failed to acquire the resource lock for the resource allocation commands\n");
498511e25f0dSDavid C Somayajulu 		return ECORE_BUSY;
498611e25f0dSDavid C Somayajulu 	} else {
49879efd0ba7SDavid C Somayajulu 		rc = ecore_hw_set_soft_resc_size(p_hwfn, p_ptt);
498811e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
498911e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
499011e25f0dSDavid C Somayajulu 				  "Failed to set the max values of the soft resources\n");
499111e25f0dSDavid C Somayajulu 			goto unlock_and_exit;
499211e25f0dSDavid C Somayajulu 		} else if (rc == ECORE_NOTIMPL) {
499311e25f0dSDavid C Somayajulu 			DP_INFO(p_hwfn,
499411e25f0dSDavid C Somayajulu 				"Skip the max values setting of the soft resources since it is not supported by the MFW\n");
49959efd0ba7SDavid C Somayajulu 			rc = ecore_mcp_resc_unlock(p_hwfn, p_ptt,
499611e25f0dSDavid C Somayajulu 						   &resc_unlock_params);
499711e25f0dSDavid C Somayajulu 			if (rc != ECORE_SUCCESS)
499811e25f0dSDavid C Somayajulu 				DP_INFO(p_hwfn,
499911e25f0dSDavid C Somayajulu 					"Failed to release the resource lock for the resource allocation commands\n");
500011e25f0dSDavid C Somayajulu 		}
500111e25f0dSDavid C Somayajulu 	}
500211e25f0dSDavid C Somayajulu 
500311e25f0dSDavid C Somayajulu 	rc = ecore_hw_set_resc_info(p_hwfn, drv_resc_alloc);
500411e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
500511e25f0dSDavid C Somayajulu 		goto unlock_and_exit;
500611e25f0dSDavid C Somayajulu 
500711e25f0dSDavid C Somayajulu 	if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
50089efd0ba7SDavid C Somayajulu 		rc = ecore_mcp_resc_unlock(p_hwfn, p_ptt,
500911e25f0dSDavid C Somayajulu 					   &resc_unlock_params);
501011e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
501111e25f0dSDavid C Somayajulu 			DP_INFO(p_hwfn,
501211e25f0dSDavid C Somayajulu 				"Failed to release the resource lock for the resource allocation commands\n");
501311e25f0dSDavid C Somayajulu 	}
501411e25f0dSDavid C Somayajulu 
5015*217ec208SDavid C Somayajulu 	/* PPFID bitmap */
5016*217ec208SDavid C Somayajulu 	if (IS_LEAD_HWFN(p_hwfn)) {
5017*217ec208SDavid C Somayajulu 		rc = ecore_hw_get_ppfid_bitmap(p_hwfn, p_ptt);
5018*217ec208SDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
5019*217ec208SDavid C Somayajulu 			return rc;
5020*217ec208SDavid C Somayajulu 	}
5021*217ec208SDavid C Somayajulu 
502211e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
502311e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
502411e25f0dSDavid C Somayajulu 		/* Reduced build contains less PQs */
502511e25f0dSDavid C Somayajulu 		if (!(p_hwfn->p_dev->b_is_emul_full)) {
502611e25f0dSDavid C Somayajulu 			resc_num[ECORE_PQ] = 32;
502711e25f0dSDavid C Somayajulu 			resc_start[ECORE_PQ] = resc_num[ECORE_PQ] *
502811e25f0dSDavid C Somayajulu 					       p_hwfn->enabled_func_idx;
502911e25f0dSDavid C Somayajulu 		}
503011e25f0dSDavid C Somayajulu 
503111e25f0dSDavid C Somayajulu 		/* For AH emulation, since we have a possible maximal number of
503211e25f0dSDavid C Somayajulu 		 * 16 enabled PFs, in case there are not enough ILT lines -
503311e25f0dSDavid C Somayajulu 		 * allocate only first PF as RoCE and have all the other ETH
503411e25f0dSDavid C Somayajulu 		 * only with less ILT lines.
503511e25f0dSDavid C Somayajulu 		 */
503611e25f0dSDavid C Somayajulu 		if (!p_hwfn->rel_pf_id && p_hwfn->p_dev->b_is_emul_full)
503711e25f0dSDavid C Somayajulu 			resc_num[ECORE_ILT] = OSAL_MAX_T(u32,
503811e25f0dSDavid C Somayajulu 							 resc_num[ECORE_ILT],
503911e25f0dSDavid C Somayajulu 							 roce_min_ilt_lines);
504011e25f0dSDavid C Somayajulu 	}
504111e25f0dSDavid C Somayajulu 
504211e25f0dSDavid C Somayajulu 	/* Correct the common ILT calculation if PF0 has more */
504311e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_SLOW(p_hwfn->p_dev) &&
504411e25f0dSDavid C Somayajulu 	    p_hwfn->p_dev->b_is_emul_full &&
504511e25f0dSDavid C Somayajulu 	    p_hwfn->rel_pf_id &&
504611e25f0dSDavid C Somayajulu 	    resc_num[ECORE_ILT] < roce_min_ilt_lines)
504711e25f0dSDavid C Somayajulu 		resc_start[ECORE_ILT] += roce_min_ilt_lines -
504811e25f0dSDavid C Somayajulu 					 resc_num[ECORE_ILT];
504911e25f0dSDavid C Somayajulu #endif
505011e25f0dSDavid C Somayajulu 
505111e25f0dSDavid C Somayajulu 	/* Sanity for ILT */
505211e25f0dSDavid C Somayajulu 	if ((b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
505311e25f0dSDavid C Somayajulu 	    (!b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
505411e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "Can't assign ILT pages [%08x,...,%08x]\n",
505511e25f0dSDavid C Somayajulu 			  RESC_START(p_hwfn, ECORE_ILT),
505611e25f0dSDavid C Somayajulu 			  RESC_END(p_hwfn, ECORE_ILT) - 1);
505711e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
505811e25f0dSDavid C Somayajulu 	}
505911e25f0dSDavid C Somayajulu 
506011e25f0dSDavid C Somayajulu 	/* This will also learn the number of SBs from MFW */
50619efd0ba7SDavid C Somayajulu 	if (ecore_int_igu_reset_cam(p_hwfn, p_ptt))
506211e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
506311e25f0dSDavid C Somayajulu 
506411e25f0dSDavid C Somayajulu 	ecore_hw_set_feat(p_hwfn);
506511e25f0dSDavid C Somayajulu 
506611e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
506711e25f0dSDavid C Somayajulu 		   "The numbers for each resource are:\n");
506811e25f0dSDavid C Somayajulu 	for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++)
506911e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE, "%s = %d start = %d\n",
507011e25f0dSDavid C Somayajulu 			   ecore_hw_get_resc_name(res_id),
507111e25f0dSDavid C Somayajulu 			   RESC_NUM(p_hwfn, res_id),
507211e25f0dSDavid C Somayajulu 			   RESC_START(p_hwfn, res_id));
507311e25f0dSDavid C Somayajulu 
507411e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
507511e25f0dSDavid C Somayajulu 
507611e25f0dSDavid C Somayajulu unlock_and_exit:
507711e25f0dSDavid C Somayajulu 	if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
50789efd0ba7SDavid C Somayajulu 		ecore_mcp_resc_unlock(p_hwfn, p_ptt,
507911e25f0dSDavid C Somayajulu 				      &resc_unlock_params);
508011e25f0dSDavid C Somayajulu 	return rc;
508111e25f0dSDavid C Somayajulu }
508211e25f0dSDavid C Somayajulu 
508311e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_hw_get_nvm_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_hw_prepare_params * p_params)508411e25f0dSDavid C Somayajulu ecore_hw_get_nvm_info(struct ecore_hwfn *p_hwfn,
508511e25f0dSDavid C Somayajulu 		      struct ecore_ptt *p_ptt,
508611e25f0dSDavid C Somayajulu 		      struct ecore_hw_prepare_params *p_params)
508711e25f0dSDavid C Somayajulu {
508811e25f0dSDavid C Somayajulu 	u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
5089*217ec208SDavid C Somayajulu 	u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
509011e25f0dSDavid C Somayajulu 	struct ecore_mcp_link_capabilities *p_caps;
509111e25f0dSDavid C Somayajulu 	struct ecore_mcp_link_params *link;
509211e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
5093*217ec208SDavid C Somayajulu 	u32 dcbx_mode;  /* __LINUX__THROW__ */
509411e25f0dSDavid C Somayajulu 
509511e25f0dSDavid C Somayajulu 	/* Read global nvm_cfg address */
509611e25f0dSDavid C Somayajulu 	nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
509711e25f0dSDavid C Somayajulu 
509811e25f0dSDavid C Somayajulu 	/* Verify MCP has initialized it */
509911e25f0dSDavid C Somayajulu 	if (!nvm_cfg_addr) {
510011e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
510111e25f0dSDavid C Somayajulu 		if (p_params->b_relaxed_probe)
510211e25f0dSDavid C Somayajulu 			p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_NVM;
510311e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
510411e25f0dSDavid C Somayajulu 	}
510511e25f0dSDavid C Somayajulu 
510611e25f0dSDavid C Somayajulu 	/* Read nvm_cfg1  (Notice this is just offset, and not offsize (TBD) */
510711e25f0dSDavid C Somayajulu 	nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
510811e25f0dSDavid C Somayajulu 
510911e25f0dSDavid C Somayajulu 	addr = MCP_REG_SCRATCH  + nvm_cfg1_offset +
511011e25f0dSDavid C Somayajulu 		   OFFSETOF(struct nvm_cfg1, glob) +
511111e25f0dSDavid C Somayajulu 		   OFFSETOF(struct nvm_cfg1_glob, core_cfg);
511211e25f0dSDavid C Somayajulu 
511311e25f0dSDavid C Somayajulu 	core_cfg = ecore_rd(p_hwfn, p_ptt, addr);
511411e25f0dSDavid C Somayajulu 
511511e25f0dSDavid C Somayajulu 	switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
511611e25f0dSDavid C Somayajulu 		NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
511711e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
511811e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X40G;
511911e25f0dSDavid C Somayajulu 		break;
512011e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
512111e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X50G;
512211e25f0dSDavid C Somayajulu 		break;
512311e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
512411e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X100G;
512511e25f0dSDavid C Somayajulu 		break;
512611e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
512711e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_F;
512811e25f0dSDavid C Somayajulu 		break;
512911e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
513011e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_E;
513111e25f0dSDavid C Somayajulu 		break;
513211e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
513311e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X20G;
513411e25f0dSDavid C Somayajulu 		break;
513511e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
513611e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X40G;
513711e25f0dSDavid C Somayajulu 		break;
513811e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
513911e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X25G;
514011e25f0dSDavid C Somayajulu 		break;
514111e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
514211e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X10G;
514311e25f0dSDavid C Somayajulu 		break;
514411e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
514511e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X25G;
514611e25f0dSDavid C Somayajulu 		break;
514711e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
514811e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X25G;
514911e25f0dSDavid C Somayajulu 		break;
515011e25f0dSDavid C Somayajulu 	default:
515111e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "Unknown port mode in 0x%08x\n",
515211e25f0dSDavid C Somayajulu 			  core_cfg);
515311e25f0dSDavid C Somayajulu 		break;
515411e25f0dSDavid C Somayajulu 	}
515511e25f0dSDavid C Somayajulu 
5156*217ec208SDavid C Somayajulu #ifndef __EXTRACT__LINUX__THROW__
515711e25f0dSDavid C Somayajulu 	/* Read DCBX configuration */
515811e25f0dSDavid C Somayajulu 	port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
515911e25f0dSDavid C Somayajulu 			OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
516011e25f0dSDavid C Somayajulu 	dcbx_mode = ecore_rd(p_hwfn, p_ptt,
516111e25f0dSDavid C Somayajulu 			     port_cfg_addr +
516211e25f0dSDavid C Somayajulu 			     OFFSETOF(struct nvm_cfg1_port, generic_cont0));
516311e25f0dSDavid C Somayajulu 	dcbx_mode = (dcbx_mode & NVM_CFG1_PORT_DCBX_MODE_MASK)
516411e25f0dSDavid C Somayajulu 		>> NVM_CFG1_PORT_DCBX_MODE_OFFSET;
516511e25f0dSDavid C Somayajulu 	switch (dcbx_mode) {
516611e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DCBX_MODE_DYNAMIC:
516711e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DYNAMIC;
516811e25f0dSDavid C Somayajulu 		break;
516911e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DCBX_MODE_CEE:
517011e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_CEE;
517111e25f0dSDavid C Somayajulu 		break;
517211e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DCBX_MODE_IEEE:
517311e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_IEEE;
517411e25f0dSDavid C Somayajulu 		break;
517511e25f0dSDavid C Somayajulu 	default:
517611e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DISABLED;
517711e25f0dSDavid C Somayajulu 	}
5178*217ec208SDavid C Somayajulu #endif
517911e25f0dSDavid C Somayajulu 
518011e25f0dSDavid C Somayajulu 	/* Read default link configuration */
518111e25f0dSDavid C Somayajulu 	link = &p_hwfn->mcp_info->link_input;
518211e25f0dSDavid C Somayajulu 	p_caps = &p_hwfn->mcp_info->link_capabilities;
518311e25f0dSDavid C Somayajulu 	port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
518411e25f0dSDavid C Somayajulu 			OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
518511e25f0dSDavid C Somayajulu 	link_temp = ecore_rd(p_hwfn, p_ptt,
518611e25f0dSDavid C Somayajulu 			     port_cfg_addr +
518711e25f0dSDavid C Somayajulu 			     OFFSETOF(struct nvm_cfg1_port, speed_cap_mask));
518811e25f0dSDavid C Somayajulu 	link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
518911e25f0dSDavid C Somayajulu 	link->speed.advertised_speeds = link_temp;
519011e25f0dSDavid C Somayajulu 	p_caps->speed_capabilities = link->speed.advertised_speeds;
519111e25f0dSDavid C Somayajulu 
519211e25f0dSDavid C Somayajulu 	link_temp = ecore_rd(p_hwfn, p_ptt,
519311e25f0dSDavid C Somayajulu 				 port_cfg_addr +
519411e25f0dSDavid C Somayajulu 				 OFFSETOF(struct nvm_cfg1_port, link_settings));
519511e25f0dSDavid C Somayajulu 	switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
519611e25f0dSDavid C Somayajulu 		NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
519711e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
519811e25f0dSDavid C Somayajulu 		link->speed.autoneg = true;
519911e25f0dSDavid C Somayajulu 		break;
520011e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
520111e25f0dSDavid C Somayajulu 		link->speed.forced_speed = 1000;
520211e25f0dSDavid C Somayajulu 		break;
520311e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
520411e25f0dSDavid C Somayajulu 		link->speed.forced_speed = 10000;
520511e25f0dSDavid C Somayajulu 		break;
5206*217ec208SDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_20G:
5207*217ec208SDavid C Somayajulu 		link->speed.forced_speed = 20000;
5208*217ec208SDavid C Somayajulu 		break;
520911e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
521011e25f0dSDavid C Somayajulu 		link->speed.forced_speed = 25000;
521111e25f0dSDavid C Somayajulu 		break;
521211e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
521311e25f0dSDavid C Somayajulu 		link->speed.forced_speed = 40000;
521411e25f0dSDavid C Somayajulu 		break;
521511e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
521611e25f0dSDavid C Somayajulu 		link->speed.forced_speed = 50000;
521711e25f0dSDavid C Somayajulu 		break;
521811e25f0dSDavid C Somayajulu 	case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
521911e25f0dSDavid C Somayajulu 		link->speed.forced_speed = 100000;
522011e25f0dSDavid C Somayajulu 		break;
522111e25f0dSDavid C Somayajulu 	default:
522211e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "Unknown Speed in 0x%08x\n",
522311e25f0dSDavid C Somayajulu 			  link_temp);
522411e25f0dSDavid C Somayajulu 	}
522511e25f0dSDavid C Somayajulu 
5226*217ec208SDavid C Somayajulu 	p_caps->default_speed = link->speed.forced_speed; /* __LINUX__THROW__ */
522711e25f0dSDavid C Somayajulu 	p_caps->default_speed_autoneg = link->speed.autoneg;
522811e25f0dSDavid C Somayajulu 
522911e25f0dSDavid C Somayajulu 	link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
523011e25f0dSDavid C Somayajulu 	link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
523111e25f0dSDavid C Somayajulu 	link->pause.autoneg = !!(link_temp &
523211e25f0dSDavid C Somayajulu 				 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
523311e25f0dSDavid C Somayajulu 	link->pause.forced_rx = !!(link_temp &
523411e25f0dSDavid C Somayajulu 				   NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
523511e25f0dSDavid C Somayajulu 	link->pause.forced_tx = !!(link_temp &
523611e25f0dSDavid C Somayajulu 				   NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
523711e25f0dSDavid C Somayajulu 	link->loopback_mode = 0;
523811e25f0dSDavid C Somayajulu 
523911e25f0dSDavid C Somayajulu 	if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) {
524011e25f0dSDavid C Somayajulu 		link_temp = ecore_rd(p_hwfn, p_ptt, port_cfg_addr +
524111e25f0dSDavid C Somayajulu 				     OFFSETOF(struct nvm_cfg1_port, ext_phy));
524211e25f0dSDavid C Somayajulu 		link_temp &= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_MASK;
524311e25f0dSDavid C Somayajulu 		link_temp >>= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_OFFSET;
524411e25f0dSDavid C Somayajulu 		p_caps->default_eee = ECORE_MCP_EEE_ENABLED;
524511e25f0dSDavid C Somayajulu 		link->eee.enable = true;
524611e25f0dSDavid C Somayajulu 		switch (link_temp) {
524711e25f0dSDavid C Somayajulu 		case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_DISABLED:
524811e25f0dSDavid C Somayajulu 			p_caps->default_eee = ECORE_MCP_EEE_DISABLED;
524911e25f0dSDavid C Somayajulu 			link->eee.enable = false;
525011e25f0dSDavid C Somayajulu 			break;
525111e25f0dSDavid C Somayajulu 		case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_BALANCED:
525211e25f0dSDavid C Somayajulu 			p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_BALANCED_TIME;
525311e25f0dSDavid C Somayajulu 			break;
525411e25f0dSDavid C Somayajulu 		case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_AGGRESSIVE:
525511e25f0dSDavid C Somayajulu 			p_caps->eee_lpi_timer =
525611e25f0dSDavid C Somayajulu 				EEE_TX_TIMER_USEC_AGGRESSIVE_TIME;
525711e25f0dSDavid C Somayajulu 			break;
525811e25f0dSDavid C Somayajulu 		case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_LOW_LATENCY:
525911e25f0dSDavid C Somayajulu 			p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_LATENCY_TIME;
526011e25f0dSDavid C Somayajulu 			break;
526111e25f0dSDavid C Somayajulu 		}
5262*217ec208SDavid C Somayajulu 
526311e25f0dSDavid C Somayajulu 		link->eee.tx_lpi_timer = p_caps->eee_lpi_timer;
526411e25f0dSDavid C Somayajulu 		link->eee.tx_lpi_enable = link->eee.enable;
5265*217ec208SDavid C Somayajulu 		link->eee.adv_caps = ECORE_EEE_1G_ADV | ECORE_EEE_10G_ADV;
526611e25f0dSDavid C Somayajulu 	} else {
526711e25f0dSDavid C Somayajulu 		p_caps->default_eee = ECORE_MCP_EEE_UNSUPPORTED;
526811e25f0dSDavid C Somayajulu 	}
526911e25f0dSDavid C Somayajulu 
527011e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
527111e25f0dSDavid C Somayajulu 		   "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x EEE: %02x [%08x usec]\n",
527211e25f0dSDavid C Somayajulu 		   link->speed.forced_speed, link->speed.advertised_speeds,
527311e25f0dSDavid C Somayajulu 		   link->speed.autoneg, link->pause.autoneg,
527411e25f0dSDavid C Somayajulu 		   p_caps->default_eee, p_caps->eee_lpi_timer);
527511e25f0dSDavid C Somayajulu 
527611e25f0dSDavid C Somayajulu 	/* Read Multi-function information from shmem */
527711e25f0dSDavid C Somayajulu 	addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
527811e25f0dSDavid C Somayajulu 		   OFFSETOF(struct nvm_cfg1, glob) +
527911e25f0dSDavid C Somayajulu 		   OFFSETOF(struct nvm_cfg1_glob, generic_cont0);
528011e25f0dSDavid C Somayajulu 
528111e25f0dSDavid C Somayajulu 	generic_cont0 = ecore_rd(p_hwfn, p_ptt, addr);
528211e25f0dSDavid C Somayajulu 
528311e25f0dSDavid C Somayajulu 	mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
528411e25f0dSDavid C Somayajulu 		  NVM_CFG1_GLOB_MF_MODE_OFFSET;
528511e25f0dSDavid C Somayajulu 
528611e25f0dSDavid C Somayajulu 	switch (mf_mode) {
528711e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
5288*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits = 1 << ECORE_MF_OVLAN_CLSS;
5289*217ec208SDavid C Somayajulu 		break;
5290*217ec208SDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_UFP:
5291*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits = 1 << ECORE_MF_OVLAN_CLSS |
5292*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_LLH_PROTO_CLSS |
5293*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_UFP_SPECIFIC |
5294*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_8021Q_TAGGING;
5295*217ec208SDavid C Somayajulu 		break;
5296*217ec208SDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_BD:
5297*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits = 1 << ECORE_MF_OVLAN_CLSS |
5298*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_LLH_PROTO_CLSS |
5299*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_8021AD_TAGGING;
5300*217ec208SDavid C Somayajulu 		break;
5301*217ec208SDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
5302*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits = 1 << ECORE_MF_LLH_MAC_CLSS |
5303*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_LLH_PROTO_CLSS |
5304*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_LL2_NON_UNICAST |
5305*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_INTER_PF_SWITCH |
5306*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_DISABLE_ARFS;
5307*217ec208SDavid C Somayajulu 		break;
5308*217ec208SDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
5309*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits = 1 << ECORE_MF_LLH_MAC_CLSS |
5310*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_LLH_PROTO_CLSS |
5311*217ec208SDavid C Somayajulu 					 1 << ECORE_MF_LL2_NON_UNICAST;
5312*217ec208SDavid C Somayajulu 		if (ECORE_IS_BB(p_hwfn->p_dev))
5313*217ec208SDavid C Somayajulu 			p_hwfn->p_dev->mf_bits |= 1 << ECORE_MF_NEED_DEF_PF;
5314*217ec208SDavid C Somayajulu 		break;
5315*217ec208SDavid C Somayajulu 	}
5316*217ec208SDavid C Somayajulu 	DP_INFO(p_hwfn, "Multi function mode is 0x%lx\n",
5317*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits);
5318*217ec208SDavid C Somayajulu 
5319*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_hwfn->p_dev))
5320*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_bits |= (1 << ECORE_MF_DISABLE_ARFS);
5321*217ec208SDavid C Somayajulu 
5322*217ec208SDavid C Somayajulu #ifndef __EXTRACT__LINUX__THROW__
5323*217ec208SDavid C Somayajulu 	/* It's funny since we have another switch, but it's easier
5324*217ec208SDavid C Somayajulu 	 * to throw this away in linux this way. Long term, it might be
5325*217ec208SDavid C Somayajulu 	 * better to have have getters for needed ECORE_MF_* fields,
5326*217ec208SDavid C Somayajulu 	 * convert client code and eliminate this.
5327*217ec208SDavid C Somayajulu 	 */
5328*217ec208SDavid C Somayajulu 	switch (mf_mode) {
5329*217ec208SDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
533011e25f0dSDavid C Somayajulu 		p_hwfn->p_dev->mf_mode = ECORE_MF_OVLAN;
533111e25f0dSDavid C Somayajulu 		break;
533211e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
533311e25f0dSDavid C Somayajulu 		p_hwfn->p_dev->mf_mode = ECORE_MF_NPAR;
533411e25f0dSDavid C Somayajulu 		break;
533511e25f0dSDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
533611e25f0dSDavid C Somayajulu 		p_hwfn->p_dev->mf_mode = ECORE_MF_DEFAULT;
533711e25f0dSDavid C Somayajulu 		break;
5338*217ec208SDavid C Somayajulu 	case NVM_CFG1_GLOB_MF_MODE_UFP:
5339*217ec208SDavid C Somayajulu 		p_hwfn->p_dev->mf_mode = ECORE_MF_UFP;
5340*217ec208SDavid C Somayajulu 		break;
534111e25f0dSDavid C Somayajulu 	}
5342*217ec208SDavid C Somayajulu #endif
534311e25f0dSDavid C Somayajulu 
534411e25f0dSDavid C Somayajulu 	/* Read Multi-function information from shmem */
534511e25f0dSDavid C Somayajulu 	addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
534611e25f0dSDavid C Somayajulu 		   OFFSETOF(struct nvm_cfg1, glob) +
534711e25f0dSDavid C Somayajulu 		   OFFSETOF(struct nvm_cfg1_glob, device_capabilities);
534811e25f0dSDavid C Somayajulu 
534911e25f0dSDavid C Somayajulu 	device_capabilities = ecore_rd(p_hwfn, p_ptt, addr);
535011e25f0dSDavid C Somayajulu 	if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
535111e25f0dSDavid C Somayajulu 		OSAL_SET_BIT(ECORE_DEV_CAP_ETH,
535211e25f0dSDavid C Somayajulu 				 &p_hwfn->hw_info.device_capabilities);
535311e25f0dSDavid C Somayajulu 	if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
535411e25f0dSDavid C Somayajulu 		OSAL_SET_BIT(ECORE_DEV_CAP_FCOE,
535511e25f0dSDavid C Somayajulu 				 &p_hwfn->hw_info.device_capabilities);
535611e25f0dSDavid C Somayajulu 	if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
535711e25f0dSDavid C Somayajulu 		OSAL_SET_BIT(ECORE_DEV_CAP_ISCSI,
535811e25f0dSDavid C Somayajulu 				 &p_hwfn->hw_info.device_capabilities);
535911e25f0dSDavid C Somayajulu 	if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
536011e25f0dSDavid C Somayajulu 		OSAL_SET_BIT(ECORE_DEV_CAP_ROCE,
536111e25f0dSDavid C Somayajulu 				 &p_hwfn->hw_info.device_capabilities);
536211e25f0dSDavid C Somayajulu 	if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_IWARP)
536311e25f0dSDavid C Somayajulu 		OSAL_SET_BIT(ECORE_DEV_CAP_IWARP,
536411e25f0dSDavid C Somayajulu 				 &p_hwfn->hw_info.device_capabilities);
536511e25f0dSDavid C Somayajulu 
536611e25f0dSDavid C Somayajulu 	rc = ecore_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
536711e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
536811e25f0dSDavid C Somayajulu 		rc = ECORE_SUCCESS;
536911e25f0dSDavid C Somayajulu 		p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
537011e25f0dSDavid C Somayajulu 	}
537111e25f0dSDavid C Somayajulu 
537211e25f0dSDavid C Somayajulu 	return rc;
537311e25f0dSDavid C Somayajulu }
537411e25f0dSDavid C Somayajulu 
ecore_get_num_funcs(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)537511e25f0dSDavid C Somayajulu static void ecore_get_num_funcs(struct ecore_hwfn *p_hwfn,
537611e25f0dSDavid C Somayajulu 				struct ecore_ptt *p_ptt)
537711e25f0dSDavid C Somayajulu {
537811e25f0dSDavid C Somayajulu 	u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
537911e25f0dSDavid C Somayajulu 	u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
538011e25f0dSDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
538111e25f0dSDavid C Somayajulu 
538211e25f0dSDavid C Somayajulu 	num_funcs = ECORE_IS_AH(p_dev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
538311e25f0dSDavid C Somayajulu 
538411e25f0dSDavid C Somayajulu 	/* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
538511e25f0dSDavid C Somayajulu 	 * in the other bits are selected.
538611e25f0dSDavid C Somayajulu 	 * Bits 1-15 are for functions 1-15, respectively, and their value is
538711e25f0dSDavid C Somayajulu 	 * '0' only for enabled functions (function 0 always exists and
538811e25f0dSDavid C Somayajulu 	 * enabled).
538911e25f0dSDavid C Somayajulu 	 * In case of CMT in BB, only the "even" functions are enabled, and thus
539011e25f0dSDavid C Somayajulu 	 * the number of functions for both hwfns is learnt from the same bits.
539111e25f0dSDavid C Somayajulu 	 */
5392*217ec208SDavid C Somayajulu 	reg_function_hide = ecore_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
539311e25f0dSDavid C Somayajulu 
539411e25f0dSDavid C Somayajulu 	if (reg_function_hide & 0x1) {
539511e25f0dSDavid C Somayajulu 		if (ECORE_IS_BB(p_dev)) {
5396*217ec208SDavid C Somayajulu 			if (ECORE_PATH_ID(p_hwfn) && !ECORE_IS_CMT(p_dev)) {
539711e25f0dSDavid C Somayajulu 				num_funcs = 0;
539811e25f0dSDavid C Somayajulu 				eng_mask = 0xaaaa;
539911e25f0dSDavid C Somayajulu 			} else {
540011e25f0dSDavid C Somayajulu 				num_funcs = 1;
540111e25f0dSDavid C Somayajulu 				eng_mask = 0x5554;
540211e25f0dSDavid C Somayajulu 			}
540311e25f0dSDavid C Somayajulu 		} else {
540411e25f0dSDavid C Somayajulu 			num_funcs = 1;
540511e25f0dSDavid C Somayajulu 			eng_mask = 0xfffe;
540611e25f0dSDavid C Somayajulu 		}
540711e25f0dSDavid C Somayajulu 
540811e25f0dSDavid C Somayajulu 		/* Get the number of the enabled functions on the engine */
540911e25f0dSDavid C Somayajulu 		tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
541011e25f0dSDavid C Somayajulu 		while (tmp) {
541111e25f0dSDavid C Somayajulu 			if (tmp & 0x1)
541211e25f0dSDavid C Somayajulu 				num_funcs++;
541311e25f0dSDavid C Somayajulu 			tmp >>= 0x1;
541411e25f0dSDavid C Somayajulu 		}
541511e25f0dSDavid C Somayajulu 
541611e25f0dSDavid C Somayajulu 		/* Get the PF index within the enabled functions */
541711e25f0dSDavid C Somayajulu 		low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
541811e25f0dSDavid C Somayajulu 		tmp = reg_function_hide & eng_mask & low_pfs_mask;
541911e25f0dSDavid C Somayajulu 		while (tmp) {
542011e25f0dSDavid C Somayajulu 			if (tmp & 0x1)
542111e25f0dSDavid C Somayajulu 				enabled_func_idx--;
542211e25f0dSDavid C Somayajulu 			tmp >>= 0x1;
542311e25f0dSDavid C Somayajulu 		}
542411e25f0dSDavid C Somayajulu 	}
542511e25f0dSDavid C Somayajulu 
542611e25f0dSDavid C Somayajulu 	p_hwfn->num_funcs_on_engine = num_funcs;
542711e25f0dSDavid C Somayajulu 	p_hwfn->enabled_func_idx = enabled_func_idx;
542811e25f0dSDavid C Somayajulu 
542911e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
543011e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_FPGA(p_dev)) {
543111e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
543211e25f0dSDavid C Somayajulu 			  "FPGA: Limit number of PFs to 4 [would affect resource allocation, needed for IOV]\n");
543311e25f0dSDavid C Somayajulu 		p_hwfn->num_funcs_on_engine = 4;
543411e25f0dSDavid C Somayajulu 	}
543511e25f0dSDavid C Somayajulu #endif
543611e25f0dSDavid C Somayajulu 
543711e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
543811e25f0dSDavid C Somayajulu 		   "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
543911e25f0dSDavid C Somayajulu 		   p_hwfn->rel_pf_id, p_hwfn->abs_pf_id,
544011e25f0dSDavid C Somayajulu 		   p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
544111e25f0dSDavid C Somayajulu }
544211e25f0dSDavid C Somayajulu 
ecore_hw_info_port_num_bb(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)544311e25f0dSDavid C Somayajulu static void ecore_hw_info_port_num_bb(struct ecore_hwfn *p_hwfn,
544411e25f0dSDavid C Somayajulu 				      struct ecore_ptt *p_ptt)
544511e25f0dSDavid C Somayajulu {
5446*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
544711e25f0dSDavid C Somayajulu 	u32 port_mode;
544811e25f0dSDavid C Somayajulu 
544911e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
545011e25f0dSDavid C Somayajulu 	/* Read the port mode */
5451*217ec208SDavid C Somayajulu 	if (CHIP_REV_IS_FPGA(p_dev))
545211e25f0dSDavid C Somayajulu 		port_mode = 4;
5453*217ec208SDavid C Somayajulu 	else if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_CMT(p_dev))
545411e25f0dSDavid C Somayajulu 		/* In CMT on emulation, assume 1 port */
545511e25f0dSDavid C Somayajulu 		port_mode = 1;
545611e25f0dSDavid C Somayajulu 	else
545711e25f0dSDavid C Somayajulu #endif
545811e25f0dSDavid C Somayajulu 	port_mode = ecore_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
545911e25f0dSDavid C Somayajulu 
546011e25f0dSDavid C Somayajulu 	if (port_mode < 3) {
5461*217ec208SDavid C Somayajulu 		p_dev->num_ports_in_engine = 1;
546211e25f0dSDavid C Somayajulu 	} else if (port_mode <= 5) {
5463*217ec208SDavid C Somayajulu 		p_dev->num_ports_in_engine = 2;
546411e25f0dSDavid C Somayajulu 	} else {
546511e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "PORT MODE: %d not supported\n",
5466*217ec208SDavid C Somayajulu 			  p_dev->num_ports_in_engine);
546711e25f0dSDavid C Somayajulu 
54689efd0ba7SDavid C Somayajulu 		/* Default num_ports_in_engine to something */
5469*217ec208SDavid C Somayajulu 		p_dev->num_ports_in_engine = 1;
547011e25f0dSDavid C Somayajulu 	}
547111e25f0dSDavid C Somayajulu }
547211e25f0dSDavid C Somayajulu 
ecore_hw_info_port_num_ah_e5(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)547311e25f0dSDavid C Somayajulu static void ecore_hw_info_port_num_ah_e5(struct ecore_hwfn *p_hwfn,
547411e25f0dSDavid C Somayajulu 					 struct ecore_ptt *p_ptt)
547511e25f0dSDavid C Somayajulu {
5476*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
547711e25f0dSDavid C Somayajulu 	u32 port;
547811e25f0dSDavid C Somayajulu 	int i;
547911e25f0dSDavid C Somayajulu 
5480*217ec208SDavid C Somayajulu 	p_dev->num_ports_in_engine = 0;
548111e25f0dSDavid C Somayajulu 
548211e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
5483*217ec208SDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev)) {
54849efd0ba7SDavid C Somayajulu 		port = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
548511e25f0dSDavid C Somayajulu 		switch ((port & 0xf000) >> 12) {
548611e25f0dSDavid C Somayajulu 		case 1:
5487*217ec208SDavid C Somayajulu 			p_dev->num_ports_in_engine = 1;
548811e25f0dSDavid C Somayajulu 			break;
548911e25f0dSDavid C Somayajulu 		case 3:
5490*217ec208SDavid C Somayajulu 			p_dev->num_ports_in_engine = 2;
549111e25f0dSDavid C Somayajulu 			break;
549211e25f0dSDavid C Somayajulu 		case 0xf:
5493*217ec208SDavid C Somayajulu 			p_dev->num_ports_in_engine = 4;
549411e25f0dSDavid C Somayajulu 			break;
549511e25f0dSDavid C Somayajulu 		default:
549611e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
549711e25f0dSDavid C Somayajulu 				  "Unknown port mode in ECO_RESERVED %08x\n",
549811e25f0dSDavid C Somayajulu 				  port);
549911e25f0dSDavid C Somayajulu 		}
550011e25f0dSDavid C Somayajulu 	} else
550111e25f0dSDavid C Somayajulu #endif
550211e25f0dSDavid C Somayajulu 	for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
550311e25f0dSDavid C Somayajulu 		port = ecore_rd(p_hwfn, p_ptt,
550411e25f0dSDavid C Somayajulu 				CNIG_REG_NIG_PORT0_CONF_K2_E5 + (i * 4));
550511e25f0dSDavid C Somayajulu 		if (port & 1)
5506*217ec208SDavid C Somayajulu 			p_dev->num_ports_in_engine++;
55079efd0ba7SDavid C Somayajulu 	}
55089efd0ba7SDavid C Somayajulu 
5509*217ec208SDavid C Somayajulu 	if (!p_dev->num_ports_in_engine) {
55109efd0ba7SDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "All NIG ports are inactive\n");
55119efd0ba7SDavid C Somayajulu 
55129efd0ba7SDavid C Somayajulu 		/* Default num_ports_in_engine to something */
5513*217ec208SDavid C Somayajulu 		p_dev->num_ports_in_engine = 1;
551411e25f0dSDavid C Somayajulu 	}
551511e25f0dSDavid C Somayajulu }
551611e25f0dSDavid C Somayajulu 
ecore_hw_info_port_num(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)551711e25f0dSDavid C Somayajulu static void ecore_hw_info_port_num(struct ecore_hwfn *p_hwfn,
551811e25f0dSDavid C Somayajulu 				   struct ecore_ptt *p_ptt)
551911e25f0dSDavid C Somayajulu {
5520*217ec208SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
5521*217ec208SDavid C Somayajulu 
5522*217ec208SDavid C Somayajulu 	/* Determine the number of ports per engine */
5523*217ec208SDavid C Somayajulu 	if (ECORE_IS_BB(p_dev))
552411e25f0dSDavid C Somayajulu 		ecore_hw_info_port_num_bb(p_hwfn, p_ptt);
552511e25f0dSDavid C Somayajulu 	else
552611e25f0dSDavid C Somayajulu 		ecore_hw_info_port_num_ah_e5(p_hwfn, p_ptt);
5527*217ec208SDavid C Somayajulu 
5528*217ec208SDavid C Somayajulu 	/* Get the total number of ports of the device */
5529*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_dev)) {
5530*217ec208SDavid C Somayajulu 		/* In CMT there is always only one port */
5531*217ec208SDavid C Somayajulu 		p_dev->num_ports = 1;
5532*217ec208SDavid C Somayajulu #ifndef ASIC_ONLY
5533*217ec208SDavid C Somayajulu 	} else if (CHIP_REV_IS_EMUL(p_dev) || CHIP_REV_IS_TEDIBEAR(p_dev)) {
5534*217ec208SDavid C Somayajulu 		p_dev->num_ports = p_dev->num_ports_in_engine *
5535*217ec208SDavid C Somayajulu 				   ecore_device_num_engines(p_dev);
5536*217ec208SDavid C Somayajulu #endif
5537*217ec208SDavid C Somayajulu 	} else {
5538*217ec208SDavid C Somayajulu 		u32 addr, global_offsize, global_addr;
5539*217ec208SDavid C Somayajulu 
5540*217ec208SDavid C Somayajulu 		addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
5541*217ec208SDavid C Somayajulu 					    PUBLIC_GLOBAL);
5542*217ec208SDavid C Somayajulu 		global_offsize = ecore_rd(p_hwfn, p_ptt, addr);
5543*217ec208SDavid C Somayajulu 		global_addr = SECTION_ADDR(global_offsize, 0);
5544*217ec208SDavid C Somayajulu 		addr = global_addr + OFFSETOF(struct public_global, max_ports);
5545*217ec208SDavid C Somayajulu 		p_dev->num_ports = (u8)ecore_rd(p_hwfn, p_ptt, addr);
5546*217ec208SDavid C Somayajulu 	}
5547*217ec208SDavid C Somayajulu }
5548*217ec208SDavid C Somayajulu 
ecore_mcp_get_eee_caps(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)5549*217ec208SDavid C Somayajulu static void ecore_mcp_get_eee_caps(struct ecore_hwfn *p_hwfn,
5550*217ec208SDavid C Somayajulu 				   struct ecore_ptt *p_ptt)
5551*217ec208SDavid C Somayajulu {
5552*217ec208SDavid C Somayajulu 	struct ecore_mcp_link_capabilities *p_caps;
5553*217ec208SDavid C Somayajulu 	u32 eee_status;
5554*217ec208SDavid C Somayajulu 
5555*217ec208SDavid C Somayajulu 	p_caps = &p_hwfn->mcp_info->link_capabilities;
5556*217ec208SDavid C Somayajulu 	if (p_caps->default_eee == ECORE_MCP_EEE_UNSUPPORTED)
5557*217ec208SDavid C Somayajulu 		return;
5558*217ec208SDavid C Somayajulu 
5559*217ec208SDavid C Somayajulu 	p_caps->eee_speed_caps = 0;
5560*217ec208SDavid C Somayajulu 	eee_status = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
5561*217ec208SDavid C Somayajulu 			      OFFSETOF(struct public_port, eee_status));
5562*217ec208SDavid C Somayajulu 	eee_status = (eee_status & EEE_SUPPORTED_SPEED_MASK) >>
5563*217ec208SDavid C Somayajulu 			EEE_SUPPORTED_SPEED_OFFSET;
5564*217ec208SDavid C Somayajulu 	if (eee_status & EEE_1G_SUPPORTED)
5565*217ec208SDavid C Somayajulu 		p_caps->eee_speed_caps |= ECORE_EEE_1G_ADV;
5566*217ec208SDavid C Somayajulu 	if (eee_status & EEE_10G_ADV)
5567*217ec208SDavid C Somayajulu 		p_caps->eee_speed_caps |= ECORE_EEE_10G_ADV;
556811e25f0dSDavid C Somayajulu }
556911e25f0dSDavid C Somayajulu 
557011e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_get_hw_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_pci_personality personality,struct ecore_hw_prepare_params * p_params)557111e25f0dSDavid C Somayajulu ecore_get_hw_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
557211e25f0dSDavid C Somayajulu 		  enum ecore_pci_personality personality,
557311e25f0dSDavid C Somayajulu 		  struct ecore_hw_prepare_params *p_params)
557411e25f0dSDavid C Somayajulu {
557511e25f0dSDavid C Somayajulu 	bool drv_resc_alloc = p_params->drv_resc_alloc;
557611e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
557711e25f0dSDavid C Somayajulu 
557811e25f0dSDavid C Somayajulu 	/* Since all information is common, only first hwfns should do this */
557911e25f0dSDavid C Somayajulu 	if (IS_LEAD_HWFN(p_hwfn)) {
558011e25f0dSDavid C Somayajulu 		rc = ecore_iov_hw_info(p_hwfn);
558111e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
558211e25f0dSDavid C Somayajulu 			if (p_params->b_relaxed_probe)
558311e25f0dSDavid C Somayajulu 				p_params->p_relaxed_res =
558411e25f0dSDavid C Somayajulu 						ECORE_HW_PREPARE_BAD_IOV;
558511e25f0dSDavid C Somayajulu 			else
558611e25f0dSDavid C Somayajulu 				return rc;
558711e25f0dSDavid C Somayajulu 		}
558811e25f0dSDavid C Somayajulu 	}
558911e25f0dSDavid C Somayajulu 
5590*217ec208SDavid C Somayajulu 	if (IS_LEAD_HWFN(p_hwfn))
559111e25f0dSDavid C Somayajulu 		ecore_hw_info_port_num(p_hwfn, p_ptt);
559211e25f0dSDavid C Somayajulu 
559311e25f0dSDavid C Somayajulu 	ecore_mcp_get_capabilities(p_hwfn, p_ptt);
559411e25f0dSDavid C Somayajulu 
559511e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
559611e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_ASIC(p_hwfn->p_dev)) {
559711e25f0dSDavid C Somayajulu #endif
559811e25f0dSDavid C Somayajulu 	rc = ecore_hw_get_nvm_info(p_hwfn, p_ptt, p_params);
559911e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
560011e25f0dSDavid C Somayajulu 		return rc;
560111e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
560211e25f0dSDavid C Somayajulu 	}
560311e25f0dSDavid C Somayajulu #endif
560411e25f0dSDavid C Somayajulu 
560511e25f0dSDavid C Somayajulu 	rc = ecore_int_igu_read_cam(p_hwfn, p_ptt);
560611e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS) {
560711e25f0dSDavid C Somayajulu 		if (p_params->b_relaxed_probe)
560811e25f0dSDavid C Somayajulu 			p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_IGU;
560911e25f0dSDavid C Somayajulu 		else
561011e25f0dSDavid C Somayajulu 			return rc;
561111e25f0dSDavid C Somayajulu 	}
561211e25f0dSDavid C Somayajulu 
561311e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
561411e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_ASIC(p_hwfn->p_dev) && ecore_mcp_is_init(p_hwfn)) {
561511e25f0dSDavid C Somayajulu #endif
561611e25f0dSDavid C Somayajulu 	OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr,
561711e25f0dSDavid C Somayajulu 		    p_hwfn->mcp_info->func_info.mac, ETH_ALEN);
561811e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
561911e25f0dSDavid C Somayajulu 	} else {
562011e25f0dSDavid C Somayajulu 		static u8 mcp_hw_mac[6] = {0, 2, 3, 4, 5, 6};
562111e25f0dSDavid C Somayajulu 
562211e25f0dSDavid C Somayajulu 		OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr, mcp_hw_mac, ETH_ALEN);
562311e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.hw_mac_addr[5] = p_hwfn->abs_pf_id;
562411e25f0dSDavid C Somayajulu 	}
562511e25f0dSDavid C Somayajulu #endif
562611e25f0dSDavid C Somayajulu 
562711e25f0dSDavid C Somayajulu 	if (ecore_mcp_is_init(p_hwfn)) {
562811e25f0dSDavid C Somayajulu 		if (p_hwfn->mcp_info->func_info.ovlan != ECORE_MCP_VLAN_UNSET)
562911e25f0dSDavid C Somayajulu 			p_hwfn->hw_info.ovlan =
563011e25f0dSDavid C Somayajulu 				p_hwfn->mcp_info->func_info.ovlan;
563111e25f0dSDavid C Somayajulu 
563211e25f0dSDavid C Somayajulu 		ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
5633*217ec208SDavid C Somayajulu 
5634*217ec208SDavid C Somayajulu 		ecore_mcp_get_eee_caps(p_hwfn, p_ptt);
5635*217ec208SDavid C Somayajulu 
5636*217ec208SDavid C Somayajulu 		ecore_mcp_read_ufp_config(p_hwfn, p_ptt);
563711e25f0dSDavid C Somayajulu 	}
563811e25f0dSDavid C Somayajulu 
563911e25f0dSDavid C Somayajulu 	if (personality != ECORE_PCI_DEFAULT) {
564011e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.personality = personality;
564111e25f0dSDavid C Somayajulu 	} else if (ecore_mcp_is_init(p_hwfn)) {
564211e25f0dSDavid C Somayajulu 		enum ecore_pci_personality protocol;
564311e25f0dSDavid C Somayajulu 
564411e25f0dSDavid C Somayajulu 		protocol = p_hwfn->mcp_info->func_info.protocol;
564511e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.personality = protocol;
564611e25f0dSDavid C Somayajulu 	}
564711e25f0dSDavid C Somayajulu 
564811e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
564911e25f0dSDavid C Somayajulu 	/* To overcome ILT lack for emulation, until at least until we'll have
565011e25f0dSDavid C Somayajulu 	 * a definite answer from system about it, allow only PF0 to be RoCE.
565111e25f0dSDavid C Somayajulu 	 */
565211e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev)) {
565311e25f0dSDavid C Somayajulu 		if (!p_hwfn->rel_pf_id)
565411e25f0dSDavid C Somayajulu 			p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
565511e25f0dSDavid C Somayajulu 		else
565611e25f0dSDavid C Somayajulu 			p_hwfn->hw_info.personality = ECORE_PCI_ETH;
565711e25f0dSDavid C Somayajulu 	}
565811e25f0dSDavid C Somayajulu #endif
565911e25f0dSDavid C Somayajulu 
566011e25f0dSDavid C Somayajulu 	/* although in BB some constellations may support more than 4 tcs,
566111e25f0dSDavid C Somayajulu 	 * that can result in performance penalty in some cases. 4
566211e25f0dSDavid C Somayajulu 	 * represents a good tradeoff between performance and flexibility.
566311e25f0dSDavid C Somayajulu 	 */
566411e25f0dSDavid C Somayajulu 	p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
566511e25f0dSDavid C Somayajulu 
566611e25f0dSDavid C Somayajulu 	/* start out with a single active tc. This can be increased either
566711e25f0dSDavid C Somayajulu 	 * by dcbx negotiation or by upper layer driver
566811e25f0dSDavid C Somayajulu 	 */
566911e25f0dSDavid C Somayajulu 	p_hwfn->hw_info.num_active_tc = 1;
567011e25f0dSDavid C Somayajulu 
567111e25f0dSDavid C Somayajulu 	ecore_get_num_funcs(p_hwfn, p_ptt);
567211e25f0dSDavid C Somayajulu 
567311e25f0dSDavid C Somayajulu 	if (ecore_mcp_is_init(p_hwfn))
567411e25f0dSDavid C Somayajulu 		p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
567511e25f0dSDavid C Somayajulu 
567611e25f0dSDavid C Somayajulu 	/* In case of forcing the driver's default resource allocation, calling
567711e25f0dSDavid C Somayajulu 	 * ecore_hw_get_resc() should come after initializing the personality
567811e25f0dSDavid C Somayajulu 	 * and after getting the number of functions, since the calculation of
567911e25f0dSDavid C Somayajulu 	 * the resources/features depends on them.
568011e25f0dSDavid C Somayajulu 	 * This order is not harmful if not forcing.
568111e25f0dSDavid C Somayajulu 	 */
56829efd0ba7SDavid C Somayajulu 	rc = ecore_hw_get_resc(p_hwfn, p_ptt, drv_resc_alloc);
568311e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
568411e25f0dSDavid C Somayajulu 		rc = ECORE_SUCCESS;
568511e25f0dSDavid C Somayajulu 		p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
568611e25f0dSDavid C Somayajulu 	}
568711e25f0dSDavid C Somayajulu 
568811e25f0dSDavid C Somayajulu 	return rc;
568911e25f0dSDavid C Somayajulu }
569011e25f0dSDavid C Somayajulu 
5691*217ec208SDavid C Somayajulu #define ECORE_MAX_DEVICE_NAME_LEN	(8)
5692*217ec208SDavid C Somayajulu 
ecore_get_dev_name(struct ecore_dev * p_dev,u8 * name,u8 max_chars)5693*217ec208SDavid C Somayajulu void ecore_get_dev_name(struct ecore_dev *p_dev, u8 *name, u8 max_chars)
5694*217ec208SDavid C Somayajulu {
5695*217ec208SDavid C Somayajulu 	u8 n;
5696*217ec208SDavid C Somayajulu 
5697*217ec208SDavid C Somayajulu 	n = OSAL_MIN_T(u8, max_chars, ECORE_MAX_DEVICE_NAME_LEN);
5698*217ec208SDavid C Somayajulu 	OSAL_SNPRINTF(name, n, "%s %c%d", ECORE_IS_BB(p_dev) ? "BB" : "AH",
5699*217ec208SDavid C Somayajulu 		      'A' + p_dev->chip_rev, (int)p_dev->chip_metal);
5700*217ec208SDavid C Somayajulu }
5701*217ec208SDavid C Somayajulu 
ecore_get_dev_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)57029efd0ba7SDavid C Somayajulu static enum _ecore_status_t ecore_get_dev_info(struct ecore_hwfn *p_hwfn,
57039efd0ba7SDavid C Somayajulu 					       struct ecore_ptt *p_ptt)
570411e25f0dSDavid C Somayajulu {
57059efd0ba7SDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
570611e25f0dSDavid C Somayajulu 	u16 device_id_mask;
570711e25f0dSDavid C Somayajulu 	u32 tmp;
570811e25f0dSDavid C Somayajulu 
570911e25f0dSDavid C Somayajulu 	/* Read Vendor Id / Device Id */
571011e25f0dSDavid C Somayajulu 	OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_VENDOR_ID_OFFSET,
571111e25f0dSDavid C Somayajulu 				  &p_dev->vendor_id);
571211e25f0dSDavid C Somayajulu 	OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_DEVICE_ID_OFFSET,
571311e25f0dSDavid C Somayajulu 				  &p_dev->device_id);
571411e25f0dSDavid C Somayajulu 
571511e25f0dSDavid C Somayajulu 	/* Determine type */
571611e25f0dSDavid C Somayajulu 	device_id_mask = p_dev->device_id & ECORE_DEV_ID_MASK;
571711e25f0dSDavid C Somayajulu 	switch (device_id_mask) {
571811e25f0dSDavid C Somayajulu 	case ECORE_DEV_ID_MASK_BB:
571911e25f0dSDavid C Somayajulu 		p_dev->type = ECORE_DEV_TYPE_BB;
572011e25f0dSDavid C Somayajulu 		break;
572111e25f0dSDavid C Somayajulu 	case ECORE_DEV_ID_MASK_AH:
572211e25f0dSDavid C Somayajulu 		p_dev->type = ECORE_DEV_TYPE_AH;
572311e25f0dSDavid C Somayajulu 		break;
57249efd0ba7SDavid C Somayajulu 	case ECORE_DEV_ID_MASK_E5:
57259efd0ba7SDavid C Somayajulu 		p_dev->type = ECORE_DEV_TYPE_E5;
57269efd0ba7SDavid C Somayajulu 		break;
572711e25f0dSDavid C Somayajulu 	default:
572811e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "Unknown device id 0x%x\n",
572911e25f0dSDavid C Somayajulu 			  p_dev->device_id);
573011e25f0dSDavid C Somayajulu 		return ECORE_ABORTED;
573111e25f0dSDavid C Somayajulu 	}
573211e25f0dSDavid C Somayajulu 
5733*217ec208SDavid C Somayajulu 	tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_NUM);
5734*217ec208SDavid C Somayajulu 	p_dev->chip_num = (u16)GET_FIELD(tmp, CHIP_NUM);
5735*217ec208SDavid C Somayajulu 	tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
5736*217ec208SDavid C Somayajulu 	p_dev->chip_rev = (u8)GET_FIELD(tmp, CHIP_REV);
573711e25f0dSDavid C Somayajulu 
573811e25f0dSDavid C Somayajulu 	/* Learn number of HW-functions */
57399efd0ba7SDavid C Somayajulu 	tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
574011e25f0dSDavid C Somayajulu 
574111e25f0dSDavid C Somayajulu 	if (tmp & (1 << p_hwfn->rel_pf_id)) {
574211e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev->hwfns, false, "device in CMT mode\n");
574311e25f0dSDavid C Somayajulu 		p_dev->num_hwfns = 2;
574411e25f0dSDavid C Somayajulu 	} else {
574511e25f0dSDavid C Somayajulu 		p_dev->num_hwfns = 1;
574611e25f0dSDavid C Somayajulu 	}
574711e25f0dSDavid C Somayajulu 
574811e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
574911e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev)) {
575011e25f0dSDavid C Somayajulu 		/* For some reason we have problems with this register
575111e25f0dSDavid C Somayajulu 		 * in B0 emulation; Simply assume no CMT
575211e25f0dSDavid C Somayajulu 		 */
575311e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev->hwfns, false, "device on emul - assume no CMT\n");
575411e25f0dSDavid C Somayajulu 		p_dev->num_hwfns = 1;
575511e25f0dSDavid C Somayajulu 	}
575611e25f0dSDavid C Somayajulu #endif
575711e25f0dSDavid C Somayajulu 
5758*217ec208SDavid C Somayajulu 	tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_TEST_REG);
5759*217ec208SDavid C Somayajulu 	p_dev->chip_bond_id = (u8)GET_FIELD(tmp, CHIP_BOND_ID);
5760*217ec208SDavid C Somayajulu 	tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
5761*217ec208SDavid C Somayajulu 	p_dev->chip_metal = (u8)GET_FIELD(tmp, CHIP_METAL);
5762*217ec208SDavid C Somayajulu 
576311e25f0dSDavid C Somayajulu 	DP_INFO(p_dev->hwfns,
5764*217ec208SDavid C Somayajulu 		"Chip details - %s %c%d, Num: %04x Rev: %02x Bond id: %02x Metal: %02x\n",
576511e25f0dSDavid C Somayajulu 		ECORE_IS_BB(p_dev) ? "BB" : "AH",
576611e25f0dSDavid C Somayajulu 		'A' + p_dev->chip_rev, (int)p_dev->chip_metal,
576711e25f0dSDavid C Somayajulu 		p_dev->chip_num, p_dev->chip_rev, p_dev->chip_bond_id,
576811e25f0dSDavid C Somayajulu 		p_dev->chip_metal);
576911e25f0dSDavid C Somayajulu 
5770*217ec208SDavid C Somayajulu 	if (ECORE_IS_BB_A0(p_dev)) {
577111e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev->hwfns, false,
577211e25f0dSDavid C Somayajulu 			  "The chip type/rev (BB A0) is not supported!\n");
577311e25f0dSDavid C Somayajulu 		return ECORE_ABORTED;
577411e25f0dSDavid C Somayajulu 	}
577511e25f0dSDavid C Somayajulu 
577611e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
577711e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_AH(p_dev))
57789efd0ba7SDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, MISCS_REG_PLL_MAIN_CTRL_4, 0x1);
577911e25f0dSDavid C Somayajulu 
578011e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_EMUL(p_dev)) {
57819efd0ba7SDavid C Somayajulu 		tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
578211e25f0dSDavid C Somayajulu 		if (tmp & (1 << 29)) {
578311e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "Emulation: Running on a FULL build\n");
578411e25f0dSDavid C Somayajulu 			p_dev->b_is_emul_full = true;
578511e25f0dSDavid C Somayajulu 		} else {
578611e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "Emulation: Running on a REDUCED build\n");
578711e25f0dSDavid C Somayajulu 		}
578811e25f0dSDavid C Somayajulu 	}
578911e25f0dSDavid C Somayajulu #endif
579011e25f0dSDavid C Somayajulu 
579111e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
579211e25f0dSDavid C Somayajulu }
579311e25f0dSDavid C Somayajulu 
5794*217ec208SDavid C Somayajulu #ifndef LINUX_REMOVE
ecore_hw_hibernate_prepare(struct ecore_dev * p_dev)579511e25f0dSDavid C Somayajulu void ecore_hw_hibernate_prepare(struct ecore_dev *p_dev)
579611e25f0dSDavid C Somayajulu {
579711e25f0dSDavid C Somayajulu 	int j;
579811e25f0dSDavid C Somayajulu 
579911e25f0dSDavid C Somayajulu 	if (IS_VF(p_dev))
580011e25f0dSDavid C Somayajulu 		return;
580111e25f0dSDavid C Somayajulu 
580211e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, j) {
580311e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
580411e25f0dSDavid C Somayajulu 
580511e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Mark hw/fw uninitialized\n");
580611e25f0dSDavid C Somayajulu 
580711e25f0dSDavid C Somayajulu 		p_hwfn->hw_init_done = false;
580811e25f0dSDavid C Somayajulu 
580911e25f0dSDavid C Somayajulu 		ecore_ptt_invalidate(p_hwfn);
581011e25f0dSDavid C Somayajulu 	}
581111e25f0dSDavid C Somayajulu }
581211e25f0dSDavid C Somayajulu 
ecore_hw_hibernate_resume(struct ecore_dev * p_dev)581311e25f0dSDavid C Somayajulu void ecore_hw_hibernate_resume(struct ecore_dev *p_dev)
581411e25f0dSDavid C Somayajulu {
581511e25f0dSDavid C Somayajulu 	int j = 0;
581611e25f0dSDavid C Somayajulu 
581711e25f0dSDavid C Somayajulu 	if (IS_VF(p_dev))
581811e25f0dSDavid C Somayajulu 		return;
581911e25f0dSDavid C Somayajulu 
582011e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, j) {
582111e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
582211e25f0dSDavid C Somayajulu 		struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
582311e25f0dSDavid C Somayajulu 
582411e25f0dSDavid C Somayajulu 		ecore_hw_hwfn_prepare(p_hwfn);
582511e25f0dSDavid C Somayajulu 
582611e25f0dSDavid C Somayajulu 		if (!p_ptt)
5827*217ec208SDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "ptt acquire failed\n");
582811e25f0dSDavid C Somayajulu 		else {
582911e25f0dSDavid C Somayajulu 			ecore_load_mcp_offsets(p_hwfn, p_ptt);
583011e25f0dSDavid C Somayajulu 			ecore_ptt_release(p_hwfn, p_ptt);
583111e25f0dSDavid C Somayajulu 		}
583211e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP, "Reinitialized hw after low power state\n");
583311e25f0dSDavid C Somayajulu 	}
583411e25f0dSDavid C Somayajulu }
583511e25f0dSDavid C Somayajulu 
5836*217ec208SDavid C Somayajulu #endif
5837*217ec208SDavid C Somayajulu 
5838*217ec208SDavid C Somayajulu static enum _ecore_status_t
ecore_hw_prepare_single(struct ecore_hwfn * p_hwfn,void OSAL_IOMEM * p_regview,void OSAL_IOMEM * p_doorbells,u64 db_phys_addr,struct ecore_hw_prepare_params * p_params)5839*217ec208SDavid C Somayajulu ecore_hw_prepare_single(struct ecore_hwfn *p_hwfn, void OSAL_IOMEM *p_regview,
5840*217ec208SDavid C Somayajulu 			void OSAL_IOMEM *p_doorbells, u64 db_phys_addr,
584111e25f0dSDavid C Somayajulu 			struct ecore_hw_prepare_params *p_params)
584211e25f0dSDavid C Somayajulu {
584311e25f0dSDavid C Somayajulu 	struct ecore_mdump_retain_data mdump_retain;
584411e25f0dSDavid C Somayajulu 	struct ecore_dev *p_dev = p_hwfn->p_dev;
584511e25f0dSDavid C Somayajulu 	struct ecore_mdump_info mdump_info;
584611e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
584711e25f0dSDavid C Somayajulu 
584811e25f0dSDavid C Somayajulu 	/* Split PCI bars evenly between hwfns */
584911e25f0dSDavid C Somayajulu 	p_hwfn->regview = p_regview;
585011e25f0dSDavid C Somayajulu 	p_hwfn->doorbells = p_doorbells;
5851*217ec208SDavid C Somayajulu 	p_hwfn->db_phys_addr = db_phys_addr;
5852*217ec208SDavid C Somayajulu 
5853*217ec208SDavid C Somayajulu #ifndef LINUX_REMOVE
5854*217ec208SDavid C Somayajulu        p_hwfn->reg_offset = (u8 *)p_hwfn->regview - (u8 *)p_hwfn->p_dev->regview;
5855*217ec208SDavid C Somayajulu        p_hwfn->db_offset = (u8 *)p_hwfn->doorbells - (u8 *)p_hwfn->p_dev->doorbells;
5856*217ec208SDavid C Somayajulu #endif
585711e25f0dSDavid C Somayajulu 
585811e25f0dSDavid C Somayajulu 	if (IS_VF(p_dev))
585911e25f0dSDavid C Somayajulu 		return ecore_vf_hw_prepare(p_hwfn);
586011e25f0dSDavid C Somayajulu 
586111e25f0dSDavid C Somayajulu 	/* Validate that chip access is feasible */
586211e25f0dSDavid C Somayajulu 	if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
586311e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "Reading the ME register returns all Fs; Preventing further chip access\n");
586411e25f0dSDavid C Somayajulu 		if (p_params->b_relaxed_probe)
586511e25f0dSDavid C Somayajulu 			p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_ME;
586611e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
586711e25f0dSDavid C Somayajulu 	}
586811e25f0dSDavid C Somayajulu 
586911e25f0dSDavid C Somayajulu 	get_function_id(p_hwfn);
587011e25f0dSDavid C Somayajulu 
587111e25f0dSDavid C Somayajulu 	/* Allocate PTT pool */
587211e25f0dSDavid C Somayajulu 	rc = ecore_ptt_pool_alloc(p_hwfn);
587311e25f0dSDavid C Somayajulu 	if (rc) {
5874*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false, "Failed to prepare hwfn's hw\n");
587511e25f0dSDavid C Somayajulu 		if (p_params->b_relaxed_probe)
587611e25f0dSDavid C Somayajulu 			p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
587711e25f0dSDavid C Somayajulu 		goto err0;
587811e25f0dSDavid C Somayajulu 	}
587911e25f0dSDavid C Somayajulu 
588011e25f0dSDavid C Somayajulu 	/* Allocate the main PTT */
588111e25f0dSDavid C Somayajulu 	p_hwfn->p_main_ptt = ecore_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
588211e25f0dSDavid C Somayajulu 
588311e25f0dSDavid C Somayajulu 	/* First hwfn learns basic information, e.g., number of hwfns */
588411e25f0dSDavid C Somayajulu 	if (!p_hwfn->my_id) {
58859efd0ba7SDavid C Somayajulu 		rc = ecore_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
588611e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
588711e25f0dSDavid C Somayajulu 			if (p_params->b_relaxed_probe)
588811e25f0dSDavid C Somayajulu 				p_params->p_relaxed_res =
588911e25f0dSDavid C Somayajulu 					ECORE_HW_PREPARE_FAILED_DEV;
589011e25f0dSDavid C Somayajulu 			goto err1;
589111e25f0dSDavid C Somayajulu 		}
589211e25f0dSDavid C Somayajulu 	}
589311e25f0dSDavid C Somayajulu 
589411e25f0dSDavid C Somayajulu 	ecore_hw_hwfn_prepare(p_hwfn);
589511e25f0dSDavid C Somayajulu 
589611e25f0dSDavid C Somayajulu 	/* Initialize MCP structure */
589711e25f0dSDavid C Somayajulu 	rc = ecore_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
589811e25f0dSDavid C Somayajulu 	if (rc) {
5899*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false, "Failed initializing mcp command\n");
590011e25f0dSDavid C Somayajulu 		if (p_params->b_relaxed_probe)
590111e25f0dSDavid C Somayajulu 			p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
590211e25f0dSDavid C Somayajulu 		goto err1;
590311e25f0dSDavid C Somayajulu 	}
590411e25f0dSDavid C Somayajulu 
590511e25f0dSDavid C Somayajulu 	/* Read the device configuration information from the HW and SHMEM */
590611e25f0dSDavid C Somayajulu 	rc = ecore_get_hw_info(p_hwfn, p_hwfn->p_main_ptt,
590711e25f0dSDavid C Somayajulu 			       p_params->personality, p_params);
590811e25f0dSDavid C Somayajulu 	if (rc) {
5909*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false, "Failed to get HW information\n");
591011e25f0dSDavid C Somayajulu 		goto err2;
591111e25f0dSDavid C Somayajulu 	}
591211e25f0dSDavid C Somayajulu 
591311e25f0dSDavid C Somayajulu 	/* Sending a mailbox to the MFW should be after ecore_get_hw_info() is
591411e25f0dSDavid C Somayajulu 	 * called, since among others it sets the ports number in an engine.
591511e25f0dSDavid C Somayajulu 	 */
5916*217ec208SDavid C Somayajulu 	if (p_params->initiate_pf_flr && IS_LEAD_HWFN(p_hwfn) &&
591711e25f0dSDavid C Somayajulu 	    !p_dev->recov_in_prog) {
591811e25f0dSDavid C Somayajulu 		rc = ecore_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
591911e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
592011e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false, "Failed to initiate PF FLR\n");
592111e25f0dSDavid C Somayajulu 	}
592211e25f0dSDavid C Somayajulu 
592311e25f0dSDavid C Somayajulu 	/* Check if mdump logs/data are present and update the epoch value */
5924*217ec208SDavid C Somayajulu 	if (IS_LEAD_HWFN(p_hwfn)) {
5925*217ec208SDavid C Somayajulu #ifndef ASIC_ONLY
5926*217ec208SDavid C Somayajulu 		if (!CHIP_REV_IS_EMUL(p_dev)) {
5927*217ec208SDavid C Somayajulu #endif
592811e25f0dSDavid C Somayajulu 		rc = ecore_mcp_mdump_get_info(p_hwfn, p_hwfn->p_main_ptt,
592911e25f0dSDavid C Somayajulu 					      &mdump_info);
593011e25f0dSDavid C Somayajulu 		if (rc == ECORE_SUCCESS && mdump_info.num_of_logs)
593111e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
593211e25f0dSDavid C Somayajulu 				  "* * * IMPORTANT - HW ERROR register dump captured by device * * *\n");
593311e25f0dSDavid C Somayajulu 
593411e25f0dSDavid C Somayajulu 		rc = ecore_mcp_mdump_get_retain(p_hwfn, p_hwfn->p_main_ptt,
593511e25f0dSDavid C Somayajulu 						&mdump_retain);
593611e25f0dSDavid C Somayajulu 		if (rc == ECORE_SUCCESS && mdump_retain.valid)
593711e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
593811e25f0dSDavid C Somayajulu 				  "mdump retained data: epoch 0x%08x, pf 0x%x, status 0x%08x\n",
593911e25f0dSDavid C Somayajulu 				  mdump_retain.epoch, mdump_retain.pf,
594011e25f0dSDavid C Somayajulu 				  mdump_retain.status);
594111e25f0dSDavid C Somayajulu 
594211e25f0dSDavid C Somayajulu 		ecore_mcp_mdump_set_values(p_hwfn, p_hwfn->p_main_ptt,
594311e25f0dSDavid C Somayajulu 					   p_params->epoch);
5944*217ec208SDavid C Somayajulu #ifndef ASIC_ONLY
5945*217ec208SDavid C Somayajulu 		}
5946*217ec208SDavid C Somayajulu #endif
594711e25f0dSDavid C Somayajulu 	}
594811e25f0dSDavid C Somayajulu 
594911e25f0dSDavid C Somayajulu 	/* Allocate the init RT array and initialize the init-ops engine */
595011e25f0dSDavid C Somayajulu 	rc = ecore_init_alloc(p_hwfn);
595111e25f0dSDavid C Somayajulu 	if (rc) {
5952*217ec208SDavid C Somayajulu 		DP_NOTICE(p_hwfn, false, "Failed to allocate the init array\n");
595311e25f0dSDavid C Somayajulu 		if (p_params->b_relaxed_probe)
595411e25f0dSDavid C Somayajulu 			p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
595511e25f0dSDavid C Somayajulu 		goto err2;
595611e25f0dSDavid C Somayajulu 	}
595711e25f0dSDavid C Somayajulu 
595811e25f0dSDavid C Somayajulu #ifndef ASIC_ONLY
595911e25f0dSDavid C Somayajulu 	if (CHIP_REV_IS_FPGA(p_dev)) {
596011e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
596111e25f0dSDavid C Somayajulu 			  "FPGA: workaround; Prevent DMAE parities\n");
596211e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PCIE_REG_PRTY_MASK_K2_E5,
596311e25f0dSDavid C Somayajulu 			 7);
596411e25f0dSDavid C Somayajulu 
596511e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
596611e25f0dSDavid C Somayajulu 			  "FPGA: workaround: Set VF bar0 size\n");
596711e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
596811e25f0dSDavid C Somayajulu 			 PGLUE_B_REG_VF_BAR0_SIZE_K2_E5, 4);
596911e25f0dSDavid C Somayajulu 	}
597011e25f0dSDavid C Somayajulu #endif
597111e25f0dSDavid C Somayajulu 
597211e25f0dSDavid C Somayajulu 	return rc;
597311e25f0dSDavid C Somayajulu err2:
597411e25f0dSDavid C Somayajulu 	if (IS_LEAD_HWFN(p_hwfn))
597511e25f0dSDavid C Somayajulu 		ecore_iov_free_hw_info(p_dev);
597611e25f0dSDavid C Somayajulu 	ecore_mcp_free(p_hwfn);
597711e25f0dSDavid C Somayajulu err1:
597811e25f0dSDavid C Somayajulu 	ecore_hw_hwfn_free(p_hwfn);
597911e25f0dSDavid C Somayajulu err0:
598011e25f0dSDavid C Somayajulu 	return rc;
598111e25f0dSDavid C Somayajulu }
598211e25f0dSDavid C Somayajulu 
ecore_hw_prepare(struct ecore_dev * p_dev,struct ecore_hw_prepare_params * p_params)598311e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
598411e25f0dSDavid C Somayajulu 				      struct ecore_hw_prepare_params *p_params)
598511e25f0dSDavid C Somayajulu {
598611e25f0dSDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
598711e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
598811e25f0dSDavid C Somayajulu 
598911e25f0dSDavid C Somayajulu 	p_dev->chk_reg_fifo = p_params->chk_reg_fifo;
599011e25f0dSDavid C Somayajulu 	p_dev->allow_mdump = p_params->allow_mdump;
599111e25f0dSDavid C Somayajulu 
599211e25f0dSDavid C Somayajulu 	if (p_params->b_relaxed_probe)
599311e25f0dSDavid C Somayajulu 		p_params->p_relaxed_res = ECORE_HW_PREPARE_SUCCESS;
599411e25f0dSDavid C Somayajulu 
599511e25f0dSDavid C Somayajulu 	/* Store the precompiled init data ptrs */
599611e25f0dSDavid C Somayajulu 	if (IS_PF(p_dev))
599711e25f0dSDavid C Somayajulu 		ecore_init_iro_array(p_dev);
599811e25f0dSDavid C Somayajulu 
599911e25f0dSDavid C Somayajulu 	/* Initialize the first hwfn - will learn number of hwfns */
6000*217ec208SDavid C Somayajulu 	rc = ecore_hw_prepare_single(p_hwfn, p_dev->regview,
6001*217ec208SDavid C Somayajulu 				     p_dev->doorbells, p_dev->db_phys_addr,
6002*217ec208SDavid C Somayajulu 				     p_params);
600311e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
600411e25f0dSDavid C Somayajulu 		return rc;
600511e25f0dSDavid C Somayajulu 
600611e25f0dSDavid C Somayajulu 	p_params->personality = p_hwfn->hw_info.personality;
600711e25f0dSDavid C Somayajulu 
600811e25f0dSDavid C Somayajulu 	/* initilalize 2nd hwfn if necessary */
6009*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_dev)) {
601011e25f0dSDavid C Somayajulu 		void OSAL_IOMEM *p_regview, *p_doorbell;
601111e25f0dSDavid C Somayajulu 		u8 OSAL_IOMEM *addr;
6012*217ec208SDavid C Somayajulu 		u64 db_phys_addr;
6013*217ec208SDavid C Somayajulu 		u32 offset;
601411e25f0dSDavid C Somayajulu 
601511e25f0dSDavid C Somayajulu 		/* adjust bar offset for second engine */
6016*217ec208SDavid C Somayajulu 		offset = ecore_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
60179efd0ba7SDavid C Somayajulu 					   BAR_ID_0) / 2;
6018*217ec208SDavid C Somayajulu 		addr = (u8 OSAL_IOMEM *)p_dev->regview + offset;
601911e25f0dSDavid C Somayajulu 		p_regview = (void OSAL_IOMEM *)addr;
602011e25f0dSDavid C Somayajulu 
6021*217ec208SDavid C Somayajulu 		offset = ecore_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
60229efd0ba7SDavid C Somayajulu 					   BAR_ID_1) / 2;
6023*217ec208SDavid C Somayajulu 		addr = (u8 OSAL_IOMEM *)p_dev->doorbells + offset;
602411e25f0dSDavid C Somayajulu 		p_doorbell = (void OSAL_IOMEM *)addr;
6025*217ec208SDavid C Somayajulu 		db_phys_addr = p_dev->db_phys_addr + offset;
602611e25f0dSDavid C Somayajulu 
602711e25f0dSDavid C Somayajulu 		/* prepare second hw function */
602811e25f0dSDavid C Somayajulu 		rc = ecore_hw_prepare_single(&p_dev->hwfns[1], p_regview,
6029*217ec208SDavid C Somayajulu 					     p_doorbell, db_phys_addr,
6030*217ec208SDavid C Somayajulu 					     p_params);
603111e25f0dSDavid C Somayajulu 
603211e25f0dSDavid C Somayajulu 		/* in case of error, need to free the previously
603311e25f0dSDavid C Somayajulu 		 * initiliazed hwfn 0.
603411e25f0dSDavid C Somayajulu 		 */
603511e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
603611e25f0dSDavid C Somayajulu 			if (p_params->b_relaxed_probe)
603711e25f0dSDavid C Somayajulu 				p_params->p_relaxed_res =
603811e25f0dSDavid C Somayajulu 						ECORE_HW_PREPARE_FAILED_ENG2;
603911e25f0dSDavid C Somayajulu 
604011e25f0dSDavid C Somayajulu 			if (IS_PF(p_dev)) {
604111e25f0dSDavid C Somayajulu 				ecore_init_free(p_hwfn);
604211e25f0dSDavid C Somayajulu 				ecore_mcp_free(p_hwfn);
604311e25f0dSDavid C Somayajulu 				ecore_hw_hwfn_free(p_hwfn);
604411e25f0dSDavid C Somayajulu 			} else {
6045*217ec208SDavid C Somayajulu 				DP_NOTICE(p_dev, false, "What do we need to free when VF hwfn1 init fails\n");
604611e25f0dSDavid C Somayajulu 			}
604711e25f0dSDavid C Somayajulu 			return rc;
604811e25f0dSDavid C Somayajulu 		}
604911e25f0dSDavid C Somayajulu 	}
605011e25f0dSDavid C Somayajulu 
605111e25f0dSDavid C Somayajulu 	return rc;
605211e25f0dSDavid C Somayajulu }
605311e25f0dSDavid C Somayajulu 
ecore_hw_remove(struct ecore_dev * p_dev)605411e25f0dSDavid C Somayajulu void ecore_hw_remove(struct ecore_dev *p_dev)
605511e25f0dSDavid C Somayajulu {
605611e25f0dSDavid C Somayajulu 	struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
605711e25f0dSDavid C Somayajulu 	int i;
605811e25f0dSDavid C Somayajulu 
605911e25f0dSDavid C Somayajulu 	if (IS_PF(p_dev))
606011e25f0dSDavid C Somayajulu 		ecore_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
606111e25f0dSDavid C Somayajulu 						 ECORE_OV_DRIVER_STATE_NOT_LOADED);
606211e25f0dSDavid C Somayajulu 
606311e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
606411e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
606511e25f0dSDavid C Somayajulu 
606611e25f0dSDavid C Somayajulu 		if (IS_VF(p_dev)) {
606711e25f0dSDavid C Somayajulu 			ecore_vf_pf_release(p_hwfn);
606811e25f0dSDavid C Somayajulu 			continue;
606911e25f0dSDavid C Somayajulu 		}
607011e25f0dSDavid C Somayajulu 
607111e25f0dSDavid C Somayajulu 		ecore_init_free(p_hwfn);
607211e25f0dSDavid C Somayajulu 		ecore_hw_hwfn_free(p_hwfn);
607311e25f0dSDavid C Somayajulu 		ecore_mcp_free(p_hwfn);
607411e25f0dSDavid C Somayajulu 
60759efd0ba7SDavid C Somayajulu #ifdef CONFIG_ECORE_LOCK_ALLOC
6076*217ec208SDavid C Somayajulu 		OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->dmae_info.lock);
60779efd0ba7SDavid C Somayajulu #endif
607811e25f0dSDavid C Somayajulu 	}
607911e25f0dSDavid C Somayajulu 
608011e25f0dSDavid C Somayajulu 	ecore_iov_free_hw_info(p_dev);
608111e25f0dSDavid C Somayajulu }
608211e25f0dSDavid C Somayajulu 
ecore_chain_free_next_ptr(struct ecore_dev * p_dev,struct ecore_chain * p_chain)608311e25f0dSDavid C Somayajulu static void ecore_chain_free_next_ptr(struct ecore_dev *p_dev,
608411e25f0dSDavid C Somayajulu 				      struct ecore_chain *p_chain)
608511e25f0dSDavid C Somayajulu {
608611e25f0dSDavid C Somayajulu 	void *p_virt = p_chain->p_virt_addr, *p_virt_next = OSAL_NULL;
608711e25f0dSDavid C Somayajulu 	dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
608811e25f0dSDavid C Somayajulu 	struct ecore_chain_next *p_next;
608911e25f0dSDavid C Somayajulu 	u32 size, i;
609011e25f0dSDavid C Somayajulu 
609111e25f0dSDavid C Somayajulu 	if (!p_virt)
609211e25f0dSDavid C Somayajulu 		return;
609311e25f0dSDavid C Somayajulu 
609411e25f0dSDavid C Somayajulu 	size = p_chain->elem_size * p_chain->usable_per_page;
609511e25f0dSDavid C Somayajulu 
609611e25f0dSDavid C Somayajulu 	for (i = 0; i < p_chain->page_cnt; i++) {
609711e25f0dSDavid C Somayajulu 		if (!p_virt)
609811e25f0dSDavid C Somayajulu 			break;
609911e25f0dSDavid C Somayajulu 
610011e25f0dSDavid C Somayajulu 		p_next = (struct ecore_chain_next *)((u8 *)p_virt + size);
610111e25f0dSDavid C Somayajulu 		p_virt_next = p_next->next_virt;
610211e25f0dSDavid C Somayajulu 		p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
610311e25f0dSDavid C Somayajulu 
610411e25f0dSDavid C Somayajulu 		OSAL_DMA_FREE_COHERENT(p_dev, p_virt, p_phys,
610511e25f0dSDavid C Somayajulu 				       ECORE_CHAIN_PAGE_SIZE);
610611e25f0dSDavid C Somayajulu 
610711e25f0dSDavid C Somayajulu 		p_virt = p_virt_next;
610811e25f0dSDavid C Somayajulu 		p_phys = p_phys_next;
610911e25f0dSDavid C Somayajulu 	}
611011e25f0dSDavid C Somayajulu }
611111e25f0dSDavid C Somayajulu 
ecore_chain_free_single(struct ecore_dev * p_dev,struct ecore_chain * p_chain)611211e25f0dSDavid C Somayajulu static void ecore_chain_free_single(struct ecore_dev *p_dev,
611311e25f0dSDavid C Somayajulu 				    struct ecore_chain *p_chain)
611411e25f0dSDavid C Somayajulu {
611511e25f0dSDavid C Somayajulu 	if (!p_chain->p_virt_addr)
611611e25f0dSDavid C Somayajulu 		return;
611711e25f0dSDavid C Somayajulu 
611811e25f0dSDavid C Somayajulu 	OSAL_DMA_FREE_COHERENT(p_dev, p_chain->p_virt_addr,
611911e25f0dSDavid C Somayajulu 			       p_chain->p_phys_addr, ECORE_CHAIN_PAGE_SIZE);
612011e25f0dSDavid C Somayajulu }
612111e25f0dSDavid C Somayajulu 
ecore_chain_free_pbl(struct ecore_dev * p_dev,struct ecore_chain * p_chain)612211e25f0dSDavid C Somayajulu static void ecore_chain_free_pbl(struct ecore_dev *p_dev,
612311e25f0dSDavid C Somayajulu 				 struct ecore_chain *p_chain)
612411e25f0dSDavid C Somayajulu {
612511e25f0dSDavid C Somayajulu 	void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
612611e25f0dSDavid C Somayajulu 	u8 *p_pbl_virt = (u8 *)p_chain->pbl_sp.p_virt_table;
612711e25f0dSDavid C Somayajulu 	u32 page_cnt = p_chain->page_cnt, i, pbl_size;
612811e25f0dSDavid C Somayajulu 
612911e25f0dSDavid C Somayajulu 	if (!pp_virt_addr_tbl)
613011e25f0dSDavid C Somayajulu 		return;
613111e25f0dSDavid C Somayajulu 
613211e25f0dSDavid C Somayajulu 	if (!p_pbl_virt)
613311e25f0dSDavid C Somayajulu 		goto out;
613411e25f0dSDavid C Somayajulu 
613511e25f0dSDavid C Somayajulu 	for (i = 0; i < page_cnt; i++) {
613611e25f0dSDavid C Somayajulu 		if (!pp_virt_addr_tbl[i])
613711e25f0dSDavid C Somayajulu 			break;
613811e25f0dSDavid C Somayajulu 
613911e25f0dSDavid C Somayajulu 		OSAL_DMA_FREE_COHERENT(p_dev, pp_virt_addr_tbl[i],
614011e25f0dSDavid C Somayajulu 				       *(dma_addr_t *)p_pbl_virt,
614111e25f0dSDavid C Somayajulu 				       ECORE_CHAIN_PAGE_SIZE);
614211e25f0dSDavid C Somayajulu 
614311e25f0dSDavid C Somayajulu 		p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
614411e25f0dSDavid C Somayajulu 	}
614511e25f0dSDavid C Somayajulu 
614611e25f0dSDavid C Somayajulu 	pbl_size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
614711e25f0dSDavid C Somayajulu 
614811e25f0dSDavid C Somayajulu 	if (!p_chain->b_external_pbl) {
614911e25f0dSDavid C Somayajulu 		OSAL_DMA_FREE_COHERENT(p_dev, p_chain->pbl_sp.p_virt_table,
615011e25f0dSDavid C Somayajulu 				       p_chain->pbl_sp.p_phys_table, pbl_size);
615111e25f0dSDavid C Somayajulu 	}
615211e25f0dSDavid C Somayajulu out:
615311e25f0dSDavid C Somayajulu 	OSAL_VFREE(p_dev, p_chain->pbl.pp_virt_addr_tbl);
615411e25f0dSDavid C Somayajulu 	p_chain->pbl.pp_virt_addr_tbl = OSAL_NULL;
615511e25f0dSDavid C Somayajulu }
615611e25f0dSDavid C Somayajulu 
ecore_chain_free(struct ecore_dev * p_dev,struct ecore_chain * p_chain)615711e25f0dSDavid C Somayajulu void ecore_chain_free(struct ecore_dev *p_dev,
615811e25f0dSDavid C Somayajulu 		      struct ecore_chain *p_chain)
615911e25f0dSDavid C Somayajulu {
616011e25f0dSDavid C Somayajulu 	switch (p_chain->mode) {
616111e25f0dSDavid C Somayajulu 	case ECORE_CHAIN_MODE_NEXT_PTR:
616211e25f0dSDavid C Somayajulu 		ecore_chain_free_next_ptr(p_dev, p_chain);
616311e25f0dSDavid C Somayajulu 		break;
616411e25f0dSDavid C Somayajulu 	case ECORE_CHAIN_MODE_SINGLE:
616511e25f0dSDavid C Somayajulu 		ecore_chain_free_single(p_dev, p_chain);
616611e25f0dSDavid C Somayajulu 		break;
616711e25f0dSDavid C Somayajulu 	case ECORE_CHAIN_MODE_PBL:
616811e25f0dSDavid C Somayajulu 		ecore_chain_free_pbl(p_dev, p_chain);
616911e25f0dSDavid C Somayajulu 		break;
617011e25f0dSDavid C Somayajulu 	}
617111e25f0dSDavid C Somayajulu }
617211e25f0dSDavid C Somayajulu 
617311e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_chain_alloc_sanity_check(struct ecore_dev * p_dev,enum ecore_chain_cnt_type cnt_type,osal_size_t elem_size,u32 page_cnt)617411e25f0dSDavid C Somayajulu ecore_chain_alloc_sanity_check(struct ecore_dev *p_dev,
617511e25f0dSDavid C Somayajulu 			       enum ecore_chain_cnt_type cnt_type,
617611e25f0dSDavid C Somayajulu 			       osal_size_t elem_size, u32 page_cnt)
617711e25f0dSDavid C Somayajulu {
617811e25f0dSDavid C Somayajulu 	u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
617911e25f0dSDavid C Somayajulu 
618011e25f0dSDavid C Somayajulu 	/* The actual chain size can be larger than the maximal possible value
618111e25f0dSDavid C Somayajulu 	 * after rounding up the requested elements number to pages, and after
618211e25f0dSDavid C Somayajulu 	 * taking into acount the unusuable elements (next-ptr elements).
618311e25f0dSDavid C Somayajulu 	 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
618411e25f0dSDavid C Somayajulu 	 * size/capacity fields are of a u32 type.
618511e25f0dSDavid C Somayajulu 	 */
618611e25f0dSDavid C Somayajulu 	if ((cnt_type == ECORE_CHAIN_CNT_TYPE_U16 &&
618711e25f0dSDavid C Somayajulu 	     chain_size > ((u32)ECORE_U16_MAX + 1)) ||
618811e25f0dSDavid C Somayajulu 	    (cnt_type == ECORE_CHAIN_CNT_TYPE_U32 &&
618911e25f0dSDavid C Somayajulu 	     chain_size > ECORE_U32_MAX)) {
619011e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev, true,
619111e25f0dSDavid C Somayajulu 			  "The actual chain size (0x%llx) is larger than the maximal possible value\n",
619211e25f0dSDavid C Somayajulu 			  (unsigned long long)chain_size);
619311e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
619411e25f0dSDavid C Somayajulu 	}
619511e25f0dSDavid C Somayajulu 
619611e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
619711e25f0dSDavid C Somayajulu }
619811e25f0dSDavid C Somayajulu 
619911e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_chain_alloc_next_ptr(struct ecore_dev * p_dev,struct ecore_chain * p_chain)620011e25f0dSDavid C Somayajulu ecore_chain_alloc_next_ptr(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
620111e25f0dSDavid C Somayajulu {
620211e25f0dSDavid C Somayajulu 	void *p_virt = OSAL_NULL, *p_virt_prev = OSAL_NULL;
620311e25f0dSDavid C Somayajulu 	dma_addr_t p_phys = 0;
620411e25f0dSDavid C Somayajulu 	u32 i;
620511e25f0dSDavid C Somayajulu 
620611e25f0dSDavid C Somayajulu 	for (i = 0; i < p_chain->page_cnt; i++) {
620711e25f0dSDavid C Somayajulu 		p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
620811e25f0dSDavid C Somayajulu 						 ECORE_CHAIN_PAGE_SIZE);
620911e25f0dSDavid C Somayajulu 		if (!p_virt) {
6210*217ec208SDavid C Somayajulu 			DP_NOTICE(p_dev, false,
621111e25f0dSDavid C Somayajulu 				  "Failed to allocate chain memory\n");
621211e25f0dSDavid C Somayajulu 			return ECORE_NOMEM;
621311e25f0dSDavid C Somayajulu 		}
621411e25f0dSDavid C Somayajulu 
621511e25f0dSDavid C Somayajulu 		if (i == 0) {
621611e25f0dSDavid C Somayajulu 			ecore_chain_init_mem(p_chain, p_virt, p_phys);
621711e25f0dSDavid C Somayajulu 			ecore_chain_reset(p_chain);
621811e25f0dSDavid C Somayajulu 		} else {
621911e25f0dSDavid C Somayajulu 			ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
622011e25f0dSDavid C Somayajulu 						       p_virt, p_phys);
622111e25f0dSDavid C Somayajulu 		}
622211e25f0dSDavid C Somayajulu 
622311e25f0dSDavid C Somayajulu 		p_virt_prev = p_virt;
622411e25f0dSDavid C Somayajulu 	}
622511e25f0dSDavid C Somayajulu 	/* Last page's next element should point to the beginning of the
622611e25f0dSDavid C Somayajulu 	 * chain.
622711e25f0dSDavid C Somayajulu 	 */
622811e25f0dSDavid C Somayajulu 	ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
622911e25f0dSDavid C Somayajulu 				       p_chain->p_virt_addr,
623011e25f0dSDavid C Somayajulu 				       p_chain->p_phys_addr);
623111e25f0dSDavid C Somayajulu 
623211e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
623311e25f0dSDavid C Somayajulu }
623411e25f0dSDavid C Somayajulu 
623511e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_chain_alloc_single(struct ecore_dev * p_dev,struct ecore_chain * p_chain)623611e25f0dSDavid C Somayajulu ecore_chain_alloc_single(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
623711e25f0dSDavid C Somayajulu {
623811e25f0dSDavid C Somayajulu 	dma_addr_t p_phys = 0;
623911e25f0dSDavid C Somayajulu 	void *p_virt = OSAL_NULL;
624011e25f0dSDavid C Somayajulu 
624111e25f0dSDavid C Somayajulu 	p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys, ECORE_CHAIN_PAGE_SIZE);
624211e25f0dSDavid C Somayajulu 	if (!p_virt) {
6243*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false, "Failed to allocate chain memory\n");
624411e25f0dSDavid C Somayajulu 		return ECORE_NOMEM;
624511e25f0dSDavid C Somayajulu 	}
624611e25f0dSDavid C Somayajulu 
624711e25f0dSDavid C Somayajulu 	ecore_chain_init_mem(p_chain, p_virt, p_phys);
624811e25f0dSDavid C Somayajulu 	ecore_chain_reset(p_chain);
624911e25f0dSDavid C Somayajulu 
625011e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
625111e25f0dSDavid C Somayajulu }
625211e25f0dSDavid C Somayajulu 
625311e25f0dSDavid C Somayajulu static enum _ecore_status_t
ecore_chain_alloc_pbl(struct ecore_dev * p_dev,struct ecore_chain * p_chain,struct ecore_chain_ext_pbl * ext_pbl)625411e25f0dSDavid C Somayajulu ecore_chain_alloc_pbl(struct ecore_dev *p_dev,
625511e25f0dSDavid C Somayajulu 		      struct ecore_chain *p_chain,
625611e25f0dSDavid C Somayajulu 		      struct ecore_chain_ext_pbl *ext_pbl)
625711e25f0dSDavid C Somayajulu {
625811e25f0dSDavid C Somayajulu 	u32 page_cnt = p_chain->page_cnt, size, i;
62599efd0ba7SDavid C Somayajulu 	dma_addr_t p_phys = 0, p_pbl_phys = 0;
62609efd0ba7SDavid C Somayajulu 	void **pp_virt_addr_tbl = OSAL_NULL;
62619efd0ba7SDavid C Somayajulu 	u8 *p_pbl_virt = OSAL_NULL;
62629efd0ba7SDavid C Somayajulu 	void *p_virt = OSAL_NULL;
626311e25f0dSDavid C Somayajulu 
626411e25f0dSDavid C Somayajulu 	size = page_cnt * sizeof(*pp_virt_addr_tbl);
626511e25f0dSDavid C Somayajulu 	pp_virt_addr_tbl = (void **)OSAL_VZALLOC(p_dev, size);
626611e25f0dSDavid C Somayajulu 	if (!pp_virt_addr_tbl) {
6267*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
626811e25f0dSDavid C Somayajulu 			  "Failed to allocate memory for the chain virtual addresses table\n");
626911e25f0dSDavid C Somayajulu 		return ECORE_NOMEM;
627011e25f0dSDavid C Somayajulu 	}
627111e25f0dSDavid C Somayajulu 
627211e25f0dSDavid C Somayajulu 	/* The allocation of the PBL table is done with its full size, since it
627311e25f0dSDavid C Somayajulu 	 * is expected to be successive.
627411e25f0dSDavid C Somayajulu 	 * ecore_chain_init_pbl_mem() is called even in a case of an allocation
627511e25f0dSDavid C Somayajulu 	 * failure, since pp_virt_addr_tbl was previously allocated, and it
627611e25f0dSDavid C Somayajulu 	 * should be saved to allow its freeing during the error flow.
627711e25f0dSDavid C Somayajulu 	 */
627811e25f0dSDavid C Somayajulu 	size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
627911e25f0dSDavid C Somayajulu 
628011e25f0dSDavid C Somayajulu 	if (ext_pbl == OSAL_NULL) {
628111e25f0dSDavid C Somayajulu 		p_pbl_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_pbl_phys, size);
628211e25f0dSDavid C Somayajulu 	} else {
628311e25f0dSDavid C Somayajulu 		p_pbl_virt = ext_pbl->p_pbl_virt;
628411e25f0dSDavid C Somayajulu 		p_pbl_phys = ext_pbl->p_pbl_phys;
628511e25f0dSDavid C Somayajulu 		p_chain->b_external_pbl = true;
628611e25f0dSDavid C Somayajulu 	}
628711e25f0dSDavid C Somayajulu 
628811e25f0dSDavid C Somayajulu 	ecore_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
628911e25f0dSDavid C Somayajulu 				 pp_virt_addr_tbl);
629011e25f0dSDavid C Somayajulu 	if (!p_pbl_virt) {
6291*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false, "Failed to allocate chain pbl memory\n");
629211e25f0dSDavid C Somayajulu 		return ECORE_NOMEM;
629311e25f0dSDavid C Somayajulu 	}
629411e25f0dSDavid C Somayajulu 
629511e25f0dSDavid C Somayajulu 	for (i = 0; i < page_cnt; i++) {
629611e25f0dSDavid C Somayajulu 		p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
629711e25f0dSDavid C Somayajulu 						 ECORE_CHAIN_PAGE_SIZE);
629811e25f0dSDavid C Somayajulu 		if (!p_virt) {
6299*217ec208SDavid C Somayajulu 			DP_NOTICE(p_dev, false,
630011e25f0dSDavid C Somayajulu 				  "Failed to allocate chain memory\n");
630111e25f0dSDavid C Somayajulu 			return ECORE_NOMEM;
630211e25f0dSDavid C Somayajulu 		}
630311e25f0dSDavid C Somayajulu 
630411e25f0dSDavid C Somayajulu 		if (i == 0) {
630511e25f0dSDavid C Somayajulu 			ecore_chain_init_mem(p_chain, p_virt, p_phys);
630611e25f0dSDavid C Somayajulu 			ecore_chain_reset(p_chain);
630711e25f0dSDavid C Somayajulu 		}
630811e25f0dSDavid C Somayajulu 
630911e25f0dSDavid C Somayajulu 		/* Fill the PBL table with the physical address of the page */
631011e25f0dSDavid C Somayajulu 		*(dma_addr_t *)p_pbl_virt = p_phys;
631111e25f0dSDavid C Somayajulu 		/* Keep the virtual address of the page */
631211e25f0dSDavid C Somayajulu 		p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
631311e25f0dSDavid C Somayajulu 
631411e25f0dSDavid C Somayajulu 		p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
631511e25f0dSDavid C Somayajulu 	}
631611e25f0dSDavid C Somayajulu 
631711e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
631811e25f0dSDavid C Somayajulu }
631911e25f0dSDavid C Somayajulu 
ecore_chain_alloc(struct ecore_dev * p_dev,enum ecore_chain_use_mode intended_use,enum ecore_chain_mode mode,enum ecore_chain_cnt_type cnt_type,u32 num_elems,osal_size_t elem_size,struct ecore_chain * p_chain,struct ecore_chain_ext_pbl * ext_pbl)632011e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_chain_alloc(struct ecore_dev *p_dev,
632111e25f0dSDavid C Somayajulu 				       enum ecore_chain_use_mode intended_use,
632211e25f0dSDavid C Somayajulu 				       enum ecore_chain_mode mode,
632311e25f0dSDavid C Somayajulu 				       enum ecore_chain_cnt_type cnt_type,
632411e25f0dSDavid C Somayajulu 				       u32 num_elems, osal_size_t elem_size,
632511e25f0dSDavid C Somayajulu 				       struct ecore_chain *p_chain,
632611e25f0dSDavid C Somayajulu 				       struct ecore_chain_ext_pbl *ext_pbl)
632711e25f0dSDavid C Somayajulu {
632811e25f0dSDavid C Somayajulu 	u32 page_cnt;
632911e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
633011e25f0dSDavid C Somayajulu 
633111e25f0dSDavid C Somayajulu 	if (mode == ECORE_CHAIN_MODE_SINGLE)
633211e25f0dSDavid C Somayajulu 		page_cnt = 1;
633311e25f0dSDavid C Somayajulu 	else
633411e25f0dSDavid C Somayajulu 		page_cnt = ECORE_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
633511e25f0dSDavid C Somayajulu 
633611e25f0dSDavid C Somayajulu 	rc = ecore_chain_alloc_sanity_check(p_dev, cnt_type, elem_size,
633711e25f0dSDavid C Somayajulu 					    page_cnt);
633811e25f0dSDavid C Somayajulu 	if (rc) {
6339*217ec208SDavid C Somayajulu 		DP_NOTICE(p_dev, false,
634011e25f0dSDavid C Somayajulu 			  "Cannot allocate a chain with the given arguments:\n"
634111e25f0dSDavid C Somayajulu 			  "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
634211e25f0dSDavid C Somayajulu 			  intended_use, mode, cnt_type, num_elems, elem_size);
634311e25f0dSDavid C Somayajulu 		return rc;
634411e25f0dSDavid C Somayajulu 	}
634511e25f0dSDavid C Somayajulu 
634611e25f0dSDavid C Somayajulu 	ecore_chain_init_params(p_chain, page_cnt, (u8)elem_size, intended_use,
634711e25f0dSDavid C Somayajulu 				mode, cnt_type, p_dev->dp_ctx);
634811e25f0dSDavid C Somayajulu 
634911e25f0dSDavid C Somayajulu 	switch (mode) {
635011e25f0dSDavid C Somayajulu 	case ECORE_CHAIN_MODE_NEXT_PTR:
635111e25f0dSDavid C Somayajulu 		rc = ecore_chain_alloc_next_ptr(p_dev, p_chain);
635211e25f0dSDavid C Somayajulu 		break;
635311e25f0dSDavid C Somayajulu 	case ECORE_CHAIN_MODE_SINGLE:
635411e25f0dSDavid C Somayajulu 		rc = ecore_chain_alloc_single(p_dev, p_chain);
635511e25f0dSDavid C Somayajulu 		break;
635611e25f0dSDavid C Somayajulu 	case ECORE_CHAIN_MODE_PBL:
635711e25f0dSDavid C Somayajulu 		rc = ecore_chain_alloc_pbl(p_dev, p_chain, ext_pbl);
635811e25f0dSDavid C Somayajulu 		break;
635911e25f0dSDavid C Somayajulu 	}
636011e25f0dSDavid C Somayajulu 	if (rc)
636111e25f0dSDavid C Somayajulu 		goto nomem;
636211e25f0dSDavid C Somayajulu 
636311e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
636411e25f0dSDavid C Somayajulu 
636511e25f0dSDavid C Somayajulu nomem:
636611e25f0dSDavid C Somayajulu 	ecore_chain_free(p_dev, p_chain);
636711e25f0dSDavid C Somayajulu 	return rc;
636811e25f0dSDavid C Somayajulu }
636911e25f0dSDavid C Somayajulu 
ecore_fw_l2_queue(struct ecore_hwfn * p_hwfn,u16 src_id,u16 * dst_id)637011e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
637111e25f0dSDavid C Somayajulu 				       u16 src_id, u16 *dst_id)
637211e25f0dSDavid C Somayajulu {
637311e25f0dSDavid C Somayajulu 	if (src_id >= RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
637411e25f0dSDavid C Somayajulu 		u16 min, max;
637511e25f0dSDavid C Somayajulu 
637611e25f0dSDavid C Somayajulu 		min = (u16)RESC_START(p_hwfn, ECORE_L2_QUEUE);
637711e25f0dSDavid C Somayajulu 		max = min + RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
637811e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
637911e25f0dSDavid C Somayajulu 			  src_id, min, max);
638011e25f0dSDavid C Somayajulu 
638111e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
638211e25f0dSDavid C Somayajulu 	}
638311e25f0dSDavid C Somayajulu 
638411e25f0dSDavid C Somayajulu 	*dst_id = RESC_START(p_hwfn, ECORE_L2_QUEUE) + src_id;
638511e25f0dSDavid C Somayajulu 
638611e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
638711e25f0dSDavid C Somayajulu }
638811e25f0dSDavid C Somayajulu 
ecore_fw_vport(struct ecore_hwfn * p_hwfn,u8 src_id,u8 * dst_id)638911e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
639011e25f0dSDavid C Somayajulu 				    u8 src_id, u8 *dst_id)
639111e25f0dSDavid C Somayajulu {
639211e25f0dSDavid C Somayajulu 	if (src_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
639311e25f0dSDavid C Somayajulu 		u8 min, max;
639411e25f0dSDavid C Somayajulu 
639511e25f0dSDavid C Somayajulu 		min = (u8)RESC_START(p_hwfn, ECORE_VPORT);
639611e25f0dSDavid C Somayajulu 		max = min + RESC_NUM(p_hwfn, ECORE_VPORT);
639711e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "vport id [%d] is not valid, available indices [%d - %d]\n",
639811e25f0dSDavid C Somayajulu 			  src_id, min, max);
639911e25f0dSDavid C Somayajulu 
640011e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
640111e25f0dSDavid C Somayajulu 	}
640211e25f0dSDavid C Somayajulu 
640311e25f0dSDavid C Somayajulu 	*dst_id = RESC_START(p_hwfn, ECORE_VPORT) + src_id;
640411e25f0dSDavid C Somayajulu 
640511e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
640611e25f0dSDavid C Somayajulu }
640711e25f0dSDavid C Somayajulu 
ecore_fw_rss_eng(struct ecore_hwfn * p_hwfn,u8 src_id,u8 * dst_id)640811e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
640911e25f0dSDavid C Somayajulu 				      u8 src_id, u8 *dst_id)
641011e25f0dSDavid C Somayajulu {
641111e25f0dSDavid C Somayajulu 	if (src_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG)) {
641211e25f0dSDavid C Somayajulu 		u8 min, max;
641311e25f0dSDavid C Somayajulu 
641411e25f0dSDavid C Somayajulu 		min = (u8)RESC_START(p_hwfn, ECORE_RSS_ENG);
641511e25f0dSDavid C Somayajulu 		max = min + RESC_NUM(p_hwfn, ECORE_RSS_ENG);
641611e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true, "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
641711e25f0dSDavid C Somayajulu 			  src_id, min, max);
641811e25f0dSDavid C Somayajulu 
641911e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
642011e25f0dSDavid C Somayajulu 	}
642111e25f0dSDavid C Somayajulu 
642211e25f0dSDavid C Somayajulu 	*dst_id = RESC_START(p_hwfn, ECORE_RSS_ENG) + src_id;
642311e25f0dSDavid C Somayajulu 
642411e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
642511e25f0dSDavid C Somayajulu }
642611e25f0dSDavid C Somayajulu 
642711e25f0dSDavid C Somayajulu enum _ecore_status_t
ecore_llh_set_function_as_default(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)642811e25f0dSDavid C Somayajulu ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
642911e25f0dSDavid C Somayajulu 				  struct ecore_ptt *p_ptt)
643011e25f0dSDavid C Somayajulu {
6431*217ec208SDavid C Somayajulu 	if (OSAL_TEST_BIT(ECORE_MF_NEED_DEF_PF, &p_hwfn->p_dev->mf_bits)) {
643211e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt,
643311e25f0dSDavid C Somayajulu 			 NIG_REG_LLH_TAGMAC_DEF_PF_VECTOR,
643411e25f0dSDavid C Somayajulu 			 1 << p_hwfn->abs_pf_id / 2);
643511e25f0dSDavid C Somayajulu 		ecore_wr(p_hwfn, p_ptt, PRS_REG_MSG_INFO, 0);
643611e25f0dSDavid C Somayajulu 		return ECORE_SUCCESS;
643711e25f0dSDavid C Somayajulu 	} else {
643811e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
643911e25f0dSDavid C Somayajulu 			  "This function can't be set as default\n");
644011e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
644111e25f0dSDavid C Somayajulu 	}
644211e25f0dSDavid C Somayajulu }
644311e25f0dSDavid C Somayajulu 
ecore_set_coalesce(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 hw_addr,void * p_eth_qzone,osal_size_t eth_qzone_size,u8 timeset)644411e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_set_coalesce(struct ecore_hwfn *p_hwfn,
644511e25f0dSDavid C Somayajulu 					       struct ecore_ptt *p_ptt,
644611e25f0dSDavid C Somayajulu 					       u32 hw_addr, void *p_eth_qzone,
644711e25f0dSDavid C Somayajulu 					       osal_size_t eth_qzone_size,
644811e25f0dSDavid C Somayajulu 					       u8 timeset)
644911e25f0dSDavid C Somayajulu {
645011e25f0dSDavid C Somayajulu 	struct coalescing_timeset *p_coal_timeset;
645111e25f0dSDavid C Somayajulu 
645211e25f0dSDavid C Somayajulu 	if (p_hwfn->p_dev->int_coalescing_mode != ECORE_COAL_MODE_ENABLE) {
645311e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, true,
645411e25f0dSDavid C Somayajulu 			  "Coalescing configuration not enabled\n");
645511e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
645611e25f0dSDavid C Somayajulu 	}
645711e25f0dSDavid C Somayajulu 
645811e25f0dSDavid C Somayajulu 	p_coal_timeset = p_eth_qzone;
645911e25f0dSDavid C Somayajulu 	OSAL_MEMSET(p_eth_qzone, 0, eth_qzone_size);
646011e25f0dSDavid C Somayajulu 	SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
646111e25f0dSDavid C Somayajulu 	SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
646211e25f0dSDavid C Somayajulu 	ecore_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
646311e25f0dSDavid C Somayajulu 
646411e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
646511e25f0dSDavid C Somayajulu }
646611e25f0dSDavid C Somayajulu 
ecore_set_queue_coalesce(struct ecore_hwfn * p_hwfn,u16 rx_coal,u16 tx_coal,void * p_handle)646711e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn,
646811e25f0dSDavid C Somayajulu 					      u16 rx_coal, u16 tx_coal,
646911e25f0dSDavid C Somayajulu 					      void *p_handle)
647011e25f0dSDavid C Somayajulu {
647111e25f0dSDavid C Somayajulu 	struct ecore_queue_cid *p_cid = (struct ecore_queue_cid *)p_handle;
647211e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc = ECORE_SUCCESS;
647311e25f0dSDavid C Somayajulu 	struct ecore_ptt *p_ptt;
647411e25f0dSDavid C Somayajulu 
647511e25f0dSDavid C Somayajulu 	/* TODO - Configuring a single queue's coalescing but
647611e25f0dSDavid C Somayajulu 	 * claiming all queues are abiding same configuration
647711e25f0dSDavid C Somayajulu 	 * for PF and VF both.
647811e25f0dSDavid C Somayajulu 	 */
647911e25f0dSDavid C Somayajulu 
648011e25f0dSDavid C Somayajulu #ifdef CONFIG_ECORE_SRIOV
648111e25f0dSDavid C Somayajulu 	if (IS_VF(p_hwfn->p_dev))
648211e25f0dSDavid C Somayajulu 		return ecore_vf_pf_set_coalesce(p_hwfn, rx_coal,
648311e25f0dSDavid C Somayajulu 						tx_coal, p_cid);
648411e25f0dSDavid C Somayajulu #endif /* #ifdef CONFIG_ECORE_SRIOV */
648511e25f0dSDavid C Somayajulu 
648611e25f0dSDavid C Somayajulu 	p_ptt = ecore_ptt_acquire(p_hwfn);
648711e25f0dSDavid C Somayajulu 	if (!p_ptt)
648811e25f0dSDavid C Somayajulu 		return ECORE_AGAIN;
648911e25f0dSDavid C Somayajulu 
649011e25f0dSDavid C Somayajulu 	if (rx_coal) {
649111e25f0dSDavid C Somayajulu 		rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
649211e25f0dSDavid C Somayajulu 		if (rc)
649311e25f0dSDavid C Somayajulu 			goto out;
649411e25f0dSDavid C Somayajulu 		p_hwfn->p_dev->rx_coalesce_usecs = rx_coal;
649511e25f0dSDavid C Somayajulu 	}
649611e25f0dSDavid C Somayajulu 
649711e25f0dSDavid C Somayajulu 	if (tx_coal) {
649811e25f0dSDavid C Somayajulu 		rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
649911e25f0dSDavid C Somayajulu 		if (rc)
650011e25f0dSDavid C Somayajulu 			goto out;
650111e25f0dSDavid C Somayajulu 		p_hwfn->p_dev->tx_coalesce_usecs = tx_coal;
650211e25f0dSDavid C Somayajulu 	}
650311e25f0dSDavid C Somayajulu out:
650411e25f0dSDavid C Somayajulu 	ecore_ptt_release(p_hwfn, p_ptt);
650511e25f0dSDavid C Somayajulu 
650611e25f0dSDavid C Somayajulu 	return rc;
650711e25f0dSDavid C Somayajulu }
650811e25f0dSDavid C Somayajulu 
ecore_set_rxq_coalesce(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 coalesce,struct ecore_queue_cid * p_cid)650911e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
651011e25f0dSDavid C Somayajulu 					    struct ecore_ptt *p_ptt,
651111e25f0dSDavid C Somayajulu 					    u16 coalesce,
651211e25f0dSDavid C Somayajulu 					    struct ecore_queue_cid *p_cid)
651311e25f0dSDavid C Somayajulu {
651411e25f0dSDavid C Somayajulu 	struct ustorm_eth_queue_zone eth_qzone;
651511e25f0dSDavid C Somayajulu 	u8 timeset, timer_res;
651611e25f0dSDavid C Somayajulu 	u32 address;
651711e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
651811e25f0dSDavid C Somayajulu 
651911e25f0dSDavid C Somayajulu 	/* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
652011e25f0dSDavid C Somayajulu 	if (coalesce <= 0x7F)
652111e25f0dSDavid C Somayajulu 		timer_res = 0;
652211e25f0dSDavid C Somayajulu 	else if (coalesce <= 0xFF)
652311e25f0dSDavid C Somayajulu 		timer_res = 1;
652411e25f0dSDavid C Somayajulu 	else if (coalesce <= 0x1FF)
652511e25f0dSDavid C Somayajulu 		timer_res = 2;
652611e25f0dSDavid C Somayajulu 	else {
652711e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
652811e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
652911e25f0dSDavid C Somayajulu 	}
653011e25f0dSDavid C Somayajulu 	timeset = (u8)(coalesce >> timer_res);
653111e25f0dSDavid C Somayajulu 
653211e25f0dSDavid C Somayajulu 	rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
653311e25f0dSDavid C Somayajulu 				     p_cid->sb_igu_id, false);
653411e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
653511e25f0dSDavid C Somayajulu 		goto out;
653611e25f0dSDavid C Somayajulu 
653711e25f0dSDavid C Somayajulu 	address = BAR0_MAP_REG_USDM_RAM +
653811e25f0dSDavid C Somayajulu 		  USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
653911e25f0dSDavid C Somayajulu 
654011e25f0dSDavid C Somayajulu 	rc = ecore_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
654111e25f0dSDavid C Somayajulu 				sizeof(struct ustorm_eth_queue_zone), timeset);
654211e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
654311e25f0dSDavid C Somayajulu 		goto out;
654411e25f0dSDavid C Somayajulu 
654511e25f0dSDavid C Somayajulu out:
654611e25f0dSDavid C Somayajulu 	return rc;
654711e25f0dSDavid C Somayajulu }
654811e25f0dSDavid C Somayajulu 
ecore_set_txq_coalesce(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 coalesce,struct ecore_queue_cid * p_cid)654911e25f0dSDavid C Somayajulu enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
655011e25f0dSDavid C Somayajulu 					    struct ecore_ptt *p_ptt,
655111e25f0dSDavid C Somayajulu 					    u16 coalesce,
655211e25f0dSDavid C Somayajulu 					    struct ecore_queue_cid *p_cid)
655311e25f0dSDavid C Somayajulu {
655411e25f0dSDavid C Somayajulu 	struct xstorm_eth_queue_zone eth_qzone;
655511e25f0dSDavid C Somayajulu 	u8 timeset, timer_res;
655611e25f0dSDavid C Somayajulu 	u32 address;
655711e25f0dSDavid C Somayajulu 	enum _ecore_status_t rc;
655811e25f0dSDavid C Somayajulu 
655911e25f0dSDavid C Somayajulu 	/* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
656011e25f0dSDavid C Somayajulu 	if (coalesce <= 0x7F)
656111e25f0dSDavid C Somayajulu 		timer_res = 0;
656211e25f0dSDavid C Somayajulu 	else if (coalesce <= 0xFF)
656311e25f0dSDavid C Somayajulu 		timer_res = 1;
656411e25f0dSDavid C Somayajulu 	else if (coalesce <= 0x1FF)
656511e25f0dSDavid C Somayajulu 		timer_res = 2;
656611e25f0dSDavid C Somayajulu 	else {
656711e25f0dSDavid C Somayajulu 		DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
656811e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
656911e25f0dSDavid C Somayajulu 	}
657011e25f0dSDavid C Somayajulu 	timeset = (u8)(coalesce >> timer_res);
657111e25f0dSDavid C Somayajulu 
657211e25f0dSDavid C Somayajulu 	rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
657311e25f0dSDavid C Somayajulu 				     p_cid->sb_igu_id, true);
657411e25f0dSDavid C Somayajulu 	if (rc != ECORE_SUCCESS)
657511e25f0dSDavid C Somayajulu 		goto out;
657611e25f0dSDavid C Somayajulu 
657711e25f0dSDavid C Somayajulu 	address = BAR0_MAP_REG_XSDM_RAM +
657811e25f0dSDavid C Somayajulu 		  XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
657911e25f0dSDavid C Somayajulu 
658011e25f0dSDavid C Somayajulu 	rc = ecore_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
658111e25f0dSDavid C Somayajulu 				sizeof(struct xstorm_eth_queue_zone), timeset);
658211e25f0dSDavid C Somayajulu out:
658311e25f0dSDavid C Somayajulu 	return rc;
658411e25f0dSDavid C Somayajulu }
658511e25f0dSDavid C Somayajulu 
658611e25f0dSDavid C Somayajulu /* Calculate final WFQ values for all vports and configure it.
658711e25f0dSDavid C Somayajulu  * After this configuration each vport must have
658811e25f0dSDavid C Somayajulu  * approx min rate =  vport_wfq * min_pf_rate / ECORE_WFQ_UNIT
658911e25f0dSDavid C Somayajulu  */
ecore_configure_wfq_for_all_vports(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 min_pf_rate)659011e25f0dSDavid C Somayajulu static void ecore_configure_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
659111e25f0dSDavid C Somayajulu 					       struct ecore_ptt *p_ptt,
659211e25f0dSDavid C Somayajulu 					       u32 min_pf_rate)
659311e25f0dSDavid C Somayajulu {
659411e25f0dSDavid C Somayajulu 	struct init_qm_vport_params *vport_params;
659511e25f0dSDavid C Somayajulu 	int i;
659611e25f0dSDavid C Somayajulu 
659711e25f0dSDavid C Somayajulu 	vport_params = p_hwfn->qm_info.qm_vport_params;
659811e25f0dSDavid C Somayajulu 
659911e25f0dSDavid C Somayajulu 	for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
660011e25f0dSDavid C Somayajulu 		u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
660111e25f0dSDavid C Somayajulu 
660211e25f0dSDavid C Somayajulu 		vport_params[i].vport_wfq = (wfq_speed * ECORE_WFQ_UNIT) /
660311e25f0dSDavid C Somayajulu 					    min_pf_rate;
660411e25f0dSDavid C Somayajulu 		ecore_init_vport_wfq(p_hwfn, p_ptt,
660511e25f0dSDavid C Somayajulu 				     vport_params[i].first_tx_pq_id,
660611e25f0dSDavid C Somayajulu 				     vport_params[i].vport_wfq);
660711e25f0dSDavid C Somayajulu 	}
660811e25f0dSDavid C Somayajulu }
660911e25f0dSDavid C Somayajulu 
ecore_init_wfq_default_param(struct ecore_hwfn * p_hwfn)66109efd0ba7SDavid C Somayajulu static void ecore_init_wfq_default_param(struct ecore_hwfn *p_hwfn)
661111e25f0dSDavid C Somayajulu 
661211e25f0dSDavid C Somayajulu {
661311e25f0dSDavid C Somayajulu 	int i;
661411e25f0dSDavid C Somayajulu 
661511e25f0dSDavid C Somayajulu 	for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
661611e25f0dSDavid C Somayajulu 		p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
661711e25f0dSDavid C Somayajulu }
661811e25f0dSDavid C Somayajulu 
ecore_disable_wfq_for_all_vports(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)661911e25f0dSDavid C Somayajulu static void ecore_disable_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
66209efd0ba7SDavid C Somayajulu 					     struct ecore_ptt *p_ptt)
662111e25f0dSDavid C Somayajulu {
662211e25f0dSDavid C Somayajulu 	struct init_qm_vport_params *vport_params;
662311e25f0dSDavid C Somayajulu 	int i;
662411e25f0dSDavid C Somayajulu 
662511e25f0dSDavid C Somayajulu 	vport_params = p_hwfn->qm_info.qm_vport_params;
662611e25f0dSDavid C Somayajulu 
662711e25f0dSDavid C Somayajulu 	for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
66289efd0ba7SDavid C Somayajulu 		ecore_init_wfq_default_param(p_hwfn);
662911e25f0dSDavid C Somayajulu 		ecore_init_vport_wfq(p_hwfn, p_ptt,
663011e25f0dSDavid C Somayajulu 				     vport_params[i].first_tx_pq_id,
663111e25f0dSDavid C Somayajulu 				     vport_params[i].vport_wfq);
663211e25f0dSDavid C Somayajulu 	}
663311e25f0dSDavid C Somayajulu }
663411e25f0dSDavid C Somayajulu 
663511e25f0dSDavid C Somayajulu /* This function performs several validations for WFQ
663611e25f0dSDavid C Somayajulu  * configuration and required min rate for a given vport
663711e25f0dSDavid C Somayajulu  * 1. req_rate must be greater than one percent of min_pf_rate.
663811e25f0dSDavid C Somayajulu  * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
663911e25f0dSDavid C Somayajulu  *    rates to get less than one percent of min_pf_rate.
664011e25f0dSDavid C Somayajulu  * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
664111e25f0dSDavid C Somayajulu  */
ecore_init_wfq_param(struct ecore_hwfn * p_hwfn,u16 vport_id,u32 req_rate,u32 min_pf_rate)664211e25f0dSDavid C Somayajulu static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
664311e25f0dSDavid C Somayajulu 						 u16 vport_id, u32 req_rate,
664411e25f0dSDavid C Somayajulu 						 u32 min_pf_rate)
664511e25f0dSDavid C Somayajulu {
664611e25f0dSDavid C Somayajulu 	u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
664711e25f0dSDavid C Somayajulu 	int non_requested_count = 0, req_count = 0, i, num_vports;
664811e25f0dSDavid C Somayajulu 
664911e25f0dSDavid C Somayajulu 	num_vports = p_hwfn->qm_info.num_vports;
665011e25f0dSDavid C Somayajulu 
665111e25f0dSDavid C Somayajulu 	/* Accounting for the vports which are configured for WFQ explicitly */
665211e25f0dSDavid C Somayajulu 	for (i = 0; i < num_vports; i++) {
665311e25f0dSDavid C Somayajulu 		u32 tmp_speed;
665411e25f0dSDavid C Somayajulu 
665511e25f0dSDavid C Somayajulu 		if ((i != vport_id) && p_hwfn->qm_info.wfq_data[i].configured) {
665611e25f0dSDavid C Somayajulu 			req_count++;
665711e25f0dSDavid C Somayajulu 			tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
665811e25f0dSDavid C Somayajulu 			total_req_min_rate += tmp_speed;
665911e25f0dSDavid C Somayajulu 		}
666011e25f0dSDavid C Somayajulu 	}
666111e25f0dSDavid C Somayajulu 
666211e25f0dSDavid C Somayajulu 	/* Include current vport data as well */
666311e25f0dSDavid C Somayajulu 	req_count++;
666411e25f0dSDavid C Somayajulu 	total_req_min_rate += req_rate;
666511e25f0dSDavid C Somayajulu 	non_requested_count = num_vports - req_count;
666611e25f0dSDavid C Somayajulu 
666711e25f0dSDavid C Somayajulu 	/* validate possible error cases */
666811e25f0dSDavid C Somayajulu 	if (req_rate < min_pf_rate / ECORE_WFQ_UNIT) {
666911e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
667011e25f0dSDavid C Somayajulu 			   "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
667111e25f0dSDavid C Somayajulu 			   vport_id, req_rate, min_pf_rate);
667211e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
667311e25f0dSDavid C Somayajulu 	}
667411e25f0dSDavid C Somayajulu 
667511e25f0dSDavid C Somayajulu 	/* TBD - for number of vports greater than 100 */
667611e25f0dSDavid C Somayajulu 	if (num_vports > ECORE_WFQ_UNIT) {
667711e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
667811e25f0dSDavid C Somayajulu 			   "Number of vports is greater than %d\n",
667911e25f0dSDavid C Somayajulu 			   ECORE_WFQ_UNIT);
668011e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
668111e25f0dSDavid C Somayajulu 	}
668211e25f0dSDavid C Somayajulu 
668311e25f0dSDavid C Somayajulu 	if (total_req_min_rate > min_pf_rate) {
668411e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
668511e25f0dSDavid C Somayajulu 			   "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
668611e25f0dSDavid C Somayajulu 			   total_req_min_rate, min_pf_rate);
668711e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
668811e25f0dSDavid C Somayajulu 	}
668911e25f0dSDavid C Somayajulu 
669011e25f0dSDavid C Somayajulu 	/* Data left for non requested vports */
669111e25f0dSDavid C Somayajulu 	total_left_rate = min_pf_rate - total_req_min_rate;
669211e25f0dSDavid C Somayajulu 	left_rate_per_vp = total_left_rate / non_requested_count;
669311e25f0dSDavid C Somayajulu 
669411e25f0dSDavid C Somayajulu 	/* validate if non requested get < 1% of min bw */
669511e25f0dSDavid C Somayajulu 	if (left_rate_per_vp < min_pf_rate / ECORE_WFQ_UNIT) {
669611e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
669711e25f0dSDavid C Somayajulu 			   "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
669811e25f0dSDavid C Somayajulu 			   left_rate_per_vp, min_pf_rate);
669911e25f0dSDavid C Somayajulu 		return ECORE_INVAL;
670011e25f0dSDavid C Somayajulu 	}
670111e25f0dSDavid C Somayajulu 
670211e25f0dSDavid C Somayajulu 	/* now req_rate for given vport passes all scenarios.
670311e25f0dSDavid C Somayajulu 	 * assign final wfq rates to all vports.
670411e25f0dSDavid C Somayajulu 	 */
670511e25f0dSDavid C Somayajulu 	p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
670611e25f0dSDavid C Somayajulu 	p_hwfn->qm_info.wfq_data[vport_id].configured = true;
670711e25f0dSDavid C Somayajulu 
670811e25f0dSDavid C Somayajulu 	for (i = 0; i < num_vports; i++) {
670911e25f0dSDavid C Somayajulu 		if (p_hwfn->qm_info.wfq_data[i].configured)
671011e25f0dSDavid C Somayajulu 			continue;
671111e25f0dSDavid C Somayajulu 
671211e25f0dSDavid C Somayajulu 		p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
671311e25f0dSDavid C Somayajulu 	}
671411e25f0dSDavid C Somayajulu 
671511e25f0dSDavid C Somayajulu 	return ECORE_SUCCESS;
671611e25f0dSDavid C Somayajulu }
671711e25f0dSDavid C Somayajulu 
__ecore_configure_vport_wfq(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 vp_id,u32 rate)671811e25f0dSDavid C Somayajulu static int __ecore_configure_vport_wfq(struct ecore_hwfn *p_hwfn,
671911e25f0dSDavid C Somayajulu 				       struct ecore_ptt *p_ptt,
672011e25f0dSDavid C Somayajulu 				       u16 vp_id, u32 rate)
672111e25f0dSDavid C Somayajulu {
672211e25f0dSDavid C Somayajulu 	struct ecore_mcp_link_state *p_link;
672311e25f0dSDavid C Somayajulu 	int rc = ECORE_SUCCESS;
672411e25f0dSDavid C Somayajulu 
672511e25f0dSDavid C Somayajulu 	p_link = &p_hwfn->p_dev->hwfns[0].mcp_info->link_output;
672611e25f0dSDavid C Somayajulu 
672711e25f0dSDavid C Somayajulu 	if (!p_link->min_pf_rate) {
672811e25f0dSDavid C Somayajulu 		p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
672911e25f0dSDavid C Somayajulu 		p_hwfn->qm_info.wfq_data[vp_id].configured = true;
673011e25f0dSDavid C Somayajulu 		return rc;
673111e25f0dSDavid C Somayajulu 	}
673211e25f0dSDavid C Somayajulu 
673311e25f0dSDavid C Somayajulu 	rc = ecore_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
673411e25f0dSDavid C Somayajulu 
673511e25f0dSDavid C Somayajulu 	if (rc == ECORE_SUCCESS)
673611e25f0dSDavid C Somayajulu 		ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt,
673711e25f0dSDavid C Somayajulu 						   p_link->min_pf_rate);
673811e25f0dSDavid C Somayajulu 	else
673911e25f0dSDavid C Somayajulu 		DP_NOTICE(p_hwfn, false,
674011e25f0dSDavid C Somayajulu 			  "Validation failed while configuring min rate\n");
674111e25f0dSDavid C Somayajulu 
674211e25f0dSDavid C Somayajulu 	return rc;
674311e25f0dSDavid C Somayajulu }
674411e25f0dSDavid C Somayajulu 
__ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 min_pf_rate)674511e25f0dSDavid C Somayajulu static int __ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn *p_hwfn,
674611e25f0dSDavid C Somayajulu 						   struct ecore_ptt *p_ptt,
674711e25f0dSDavid C Somayajulu 						   u32 min_pf_rate)
674811e25f0dSDavid C Somayajulu {
674911e25f0dSDavid C Somayajulu 	bool use_wfq = false;
675011e25f0dSDavid C Somayajulu 	int rc = ECORE_SUCCESS;
675111e25f0dSDavid C Somayajulu 	u16 i;
675211e25f0dSDavid C Somayajulu 
675311e25f0dSDavid C Somayajulu 	/* Validate all pre configured vports for wfq */
675411e25f0dSDavid C Somayajulu 	for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
675511e25f0dSDavid C Somayajulu 		u32 rate;
675611e25f0dSDavid C Somayajulu 
675711e25f0dSDavid C Somayajulu 		if (!p_hwfn->qm_info.wfq_data[i].configured)
675811e25f0dSDavid C Somayajulu 			continue;
675911e25f0dSDavid C Somayajulu 
676011e25f0dSDavid C Somayajulu 		rate = p_hwfn->qm_info.wfq_data[i].min_speed;
676111e25f0dSDavid C Somayajulu 		use_wfq = true;
676211e25f0dSDavid C Somayajulu 
676311e25f0dSDavid C Somayajulu 		rc = ecore_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
676411e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
676511e25f0dSDavid C Somayajulu 			DP_NOTICE(p_hwfn, false,
676611e25f0dSDavid C Somayajulu 				  "WFQ validation failed while configuring min rate\n");
676711e25f0dSDavid C Somayajulu 			break;
676811e25f0dSDavid C Somayajulu 		}
676911e25f0dSDavid C Somayajulu 	}
677011e25f0dSDavid C Somayajulu 
677111e25f0dSDavid C Somayajulu 	if (rc == ECORE_SUCCESS && use_wfq)
677211e25f0dSDavid C Somayajulu 		ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
677311e25f0dSDavid C Somayajulu 	else
67749efd0ba7SDavid C Somayajulu 		ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt);
677511e25f0dSDavid C Somayajulu 
677611e25f0dSDavid C Somayajulu 	return rc;
677711e25f0dSDavid C Somayajulu }
677811e25f0dSDavid C Somayajulu 
677911e25f0dSDavid C Somayajulu /* Main API for ecore clients to configure vport min rate.
678011e25f0dSDavid C Somayajulu  * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
678111e25f0dSDavid C Somayajulu  * rate - Speed in Mbps needs to be assigned to a given vport.
678211e25f0dSDavid C Somayajulu  */
ecore_configure_vport_wfq(struct ecore_dev * p_dev,u16 vp_id,u32 rate)678311e25f0dSDavid C Somayajulu int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate)
678411e25f0dSDavid C Somayajulu {
678511e25f0dSDavid C Somayajulu 	int i, rc = ECORE_INVAL;
678611e25f0dSDavid C Somayajulu 
678711e25f0dSDavid C Somayajulu 	/* TBD - for multiple hardware functions - that is 100 gig */
6788*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_dev)) {
678911e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev, false,
679011e25f0dSDavid C Somayajulu 			  "WFQ configuration is not supported for this device\n");
679111e25f0dSDavid C Somayajulu 		return rc;
679211e25f0dSDavid C Somayajulu 	}
679311e25f0dSDavid C Somayajulu 
679411e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
679511e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
679611e25f0dSDavid C Somayajulu 		struct ecore_ptt *p_ptt;
679711e25f0dSDavid C Somayajulu 
679811e25f0dSDavid C Somayajulu 		p_ptt = ecore_ptt_acquire(p_hwfn);
679911e25f0dSDavid C Somayajulu 		if (!p_ptt)
680011e25f0dSDavid C Somayajulu 			return ECORE_TIMEOUT;
680111e25f0dSDavid C Somayajulu 
680211e25f0dSDavid C Somayajulu 		rc = __ecore_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
680311e25f0dSDavid C Somayajulu 
680411e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
680511e25f0dSDavid C Somayajulu 			ecore_ptt_release(p_hwfn, p_ptt);
680611e25f0dSDavid C Somayajulu 			return rc;
680711e25f0dSDavid C Somayajulu 		}
680811e25f0dSDavid C Somayajulu 
680911e25f0dSDavid C Somayajulu 		ecore_ptt_release(p_hwfn, p_ptt);
681011e25f0dSDavid C Somayajulu 	}
681111e25f0dSDavid C Somayajulu 
681211e25f0dSDavid C Somayajulu 	return rc;
681311e25f0dSDavid C Somayajulu }
681411e25f0dSDavid C Somayajulu 
681511e25f0dSDavid C Somayajulu /* API to configure WFQ from mcp link change */
ecore_configure_vp_wfq_on_link_change(struct ecore_dev * p_dev,struct ecore_ptt * p_ptt,u32 min_pf_rate)681611e25f0dSDavid C Somayajulu void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
681711e25f0dSDavid C Somayajulu 					   struct ecore_ptt *p_ptt,
681811e25f0dSDavid C Somayajulu 					   u32 min_pf_rate)
681911e25f0dSDavid C Somayajulu {
682011e25f0dSDavid C Somayajulu 	int i;
682111e25f0dSDavid C Somayajulu 
682211e25f0dSDavid C Somayajulu 	/* TBD - for multiple hardware functions - that is 100 gig */
6823*217ec208SDavid C Somayajulu 	if (ECORE_IS_CMT(p_dev)) {
682411e25f0dSDavid C Somayajulu 		DP_VERBOSE(p_dev, ECORE_MSG_LINK,
682511e25f0dSDavid C Somayajulu 			   "WFQ configuration is not supported for this device\n");
682611e25f0dSDavid C Somayajulu 		return;
682711e25f0dSDavid C Somayajulu 	}
682811e25f0dSDavid C Somayajulu 
682911e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
683011e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
683111e25f0dSDavid C Somayajulu 
683211e25f0dSDavid C Somayajulu 		__ecore_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
683311e25f0dSDavid C Somayajulu 							min_pf_rate);
683411e25f0dSDavid C Somayajulu 	}
683511e25f0dSDavid C Somayajulu }
683611e25f0dSDavid C Somayajulu 
__ecore_configure_pf_max_bandwidth(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_link_state * p_link,u8 max_bw)683711e25f0dSDavid C Somayajulu int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
683811e25f0dSDavid C Somayajulu 				       struct ecore_ptt *p_ptt,
683911e25f0dSDavid C Somayajulu 				       struct ecore_mcp_link_state *p_link,
684011e25f0dSDavid C Somayajulu 				       u8 max_bw)
684111e25f0dSDavid C Somayajulu {
684211e25f0dSDavid C Somayajulu 	int rc = ECORE_SUCCESS;
684311e25f0dSDavid C Somayajulu 
684411e25f0dSDavid C Somayajulu 	p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
684511e25f0dSDavid C Somayajulu 
684611e25f0dSDavid C Somayajulu 	if (!p_link->line_speed && (max_bw != 100))
684711e25f0dSDavid C Somayajulu 		return rc;
684811e25f0dSDavid C Somayajulu 
684911e25f0dSDavid C Somayajulu 	p_link->speed = (p_link->line_speed * max_bw) / 100;
685011e25f0dSDavid C Somayajulu 	p_hwfn->qm_info.pf_rl = p_link->speed;
685111e25f0dSDavid C Somayajulu 
685211e25f0dSDavid C Somayajulu 	/* Since the limiter also affects Tx-switched traffic, we don't want it
685311e25f0dSDavid C Somayajulu 	 * to limit such traffic in case there's no actual limit.
685411e25f0dSDavid C Somayajulu 	 * In that case, set limit to imaginary high boundary.
685511e25f0dSDavid C Somayajulu 	 */
685611e25f0dSDavid C Somayajulu 	if (max_bw == 100)
685711e25f0dSDavid C Somayajulu 		p_hwfn->qm_info.pf_rl = 100000;
685811e25f0dSDavid C Somayajulu 
685911e25f0dSDavid C Somayajulu 	rc = ecore_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
686011e25f0dSDavid C Somayajulu 			      p_hwfn->qm_info.pf_rl);
686111e25f0dSDavid C Somayajulu 
686211e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
686311e25f0dSDavid C Somayajulu 		   "Configured MAX bandwidth to be %08x Mb/sec\n",
686411e25f0dSDavid C Somayajulu 		   p_link->speed);
686511e25f0dSDavid C Somayajulu 
686611e25f0dSDavid C Somayajulu 	return rc;
686711e25f0dSDavid C Somayajulu }
686811e25f0dSDavid C Somayajulu 
686911e25f0dSDavid C Somayajulu /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
ecore_configure_pf_max_bandwidth(struct ecore_dev * p_dev,u8 max_bw)687011e25f0dSDavid C Somayajulu int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw)
687111e25f0dSDavid C Somayajulu {
687211e25f0dSDavid C Somayajulu 	int i, rc = ECORE_INVAL;
687311e25f0dSDavid C Somayajulu 
687411e25f0dSDavid C Somayajulu 	if (max_bw < 1 || max_bw > 100) {
687511e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev, false, "PF max bw valid range is [1-100]\n");
687611e25f0dSDavid C Somayajulu 		return rc;
687711e25f0dSDavid C Somayajulu 	}
687811e25f0dSDavid C Somayajulu 
687911e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
688011e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
688111e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
688211e25f0dSDavid C Somayajulu 		struct ecore_mcp_link_state *p_link;
688311e25f0dSDavid C Somayajulu 		struct ecore_ptt *p_ptt;
688411e25f0dSDavid C Somayajulu 
688511e25f0dSDavid C Somayajulu 		p_link = &p_lead->mcp_info->link_output;
688611e25f0dSDavid C Somayajulu 
688711e25f0dSDavid C Somayajulu 		p_ptt = ecore_ptt_acquire(p_hwfn);
688811e25f0dSDavid C Somayajulu 		if (!p_ptt)
688911e25f0dSDavid C Somayajulu 			return ECORE_TIMEOUT;
689011e25f0dSDavid C Somayajulu 
689111e25f0dSDavid C Somayajulu 		rc = __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
689211e25f0dSDavid C Somayajulu 							p_link, max_bw);
689311e25f0dSDavid C Somayajulu 
689411e25f0dSDavid C Somayajulu 		ecore_ptt_release(p_hwfn, p_ptt);
689511e25f0dSDavid C Somayajulu 
689611e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS)
689711e25f0dSDavid C Somayajulu 			break;
689811e25f0dSDavid C Somayajulu 	}
689911e25f0dSDavid C Somayajulu 
690011e25f0dSDavid C Somayajulu 	return rc;
690111e25f0dSDavid C Somayajulu }
690211e25f0dSDavid C Somayajulu 
__ecore_configure_pf_min_bandwidth(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_link_state * p_link,u8 min_bw)690311e25f0dSDavid C Somayajulu int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
690411e25f0dSDavid C Somayajulu 				       struct ecore_ptt *p_ptt,
690511e25f0dSDavid C Somayajulu 				       struct ecore_mcp_link_state *p_link,
690611e25f0dSDavid C Somayajulu 				       u8 min_bw)
690711e25f0dSDavid C Somayajulu {
690811e25f0dSDavid C Somayajulu 	int rc = ECORE_SUCCESS;
690911e25f0dSDavid C Somayajulu 
691011e25f0dSDavid C Somayajulu 	p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
691111e25f0dSDavid C Somayajulu 	p_hwfn->qm_info.pf_wfq = min_bw;
691211e25f0dSDavid C Somayajulu 
691311e25f0dSDavid C Somayajulu 	if (!p_link->line_speed)
691411e25f0dSDavid C Somayajulu 		return rc;
691511e25f0dSDavid C Somayajulu 
691611e25f0dSDavid C Somayajulu 	p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
691711e25f0dSDavid C Somayajulu 
691811e25f0dSDavid C Somayajulu 	rc = ecore_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
691911e25f0dSDavid C Somayajulu 
692011e25f0dSDavid C Somayajulu 	DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
692111e25f0dSDavid C Somayajulu 		   "Configured MIN bandwidth to be %d Mb/sec\n",
692211e25f0dSDavid C Somayajulu 		   p_link->min_pf_rate);
692311e25f0dSDavid C Somayajulu 
692411e25f0dSDavid C Somayajulu 	return rc;
692511e25f0dSDavid C Somayajulu }
692611e25f0dSDavid C Somayajulu 
692711e25f0dSDavid C Somayajulu /* Main API to configure PF min bandwidth where bw range is [1-100] */
ecore_configure_pf_min_bandwidth(struct ecore_dev * p_dev,u8 min_bw)692811e25f0dSDavid C Somayajulu int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw)
692911e25f0dSDavid C Somayajulu {
693011e25f0dSDavid C Somayajulu 	int i, rc = ECORE_INVAL;
693111e25f0dSDavid C Somayajulu 
693211e25f0dSDavid C Somayajulu 	if (min_bw < 1 || min_bw > 100) {
693311e25f0dSDavid C Somayajulu 		DP_NOTICE(p_dev, false, "PF min bw valid range is [1-100]\n");
693411e25f0dSDavid C Somayajulu 		return rc;
693511e25f0dSDavid C Somayajulu 	}
693611e25f0dSDavid C Somayajulu 
693711e25f0dSDavid C Somayajulu 	for_each_hwfn(p_dev, i) {
693811e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
693911e25f0dSDavid C Somayajulu 		struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
694011e25f0dSDavid C Somayajulu 		struct ecore_mcp_link_state *p_link;
694111e25f0dSDavid C Somayajulu 		struct ecore_ptt *p_ptt;
694211e25f0dSDavid C Somayajulu 
694311e25f0dSDavid C Somayajulu 		p_link = &p_lead->mcp_info->link_output;
694411e25f0dSDavid C Somayajulu 
694511e25f0dSDavid C Somayajulu 		p_ptt = ecore_ptt_acquire(p_hwfn);
694611e25f0dSDavid C Somayajulu 		if (!p_ptt)
694711e25f0dSDavid C Somayajulu 			return ECORE_TIMEOUT;
694811e25f0dSDavid C Somayajulu 
694911e25f0dSDavid C Somayajulu 		rc = __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
695011e25f0dSDavid C Somayajulu 							p_link, min_bw);
695111e25f0dSDavid C Somayajulu 		if (rc != ECORE_SUCCESS) {
695211e25f0dSDavid C Somayajulu 			ecore_ptt_release(p_hwfn, p_ptt);
695311e25f0dSDavid C Somayajulu 			return rc;
695411e25f0dSDavid C Somayajulu 		}
695511e25f0dSDavid C Somayajulu 
695611e25f0dSDavid C Somayajulu 		if (p_link->min_pf_rate) {
695711e25f0dSDavid C Somayajulu 			u32 min_rate = p_link->min_pf_rate;
695811e25f0dSDavid C Somayajulu 
695911e25f0dSDavid C Somayajulu 			rc = __ecore_configure_vp_wfq_on_link_change(p_hwfn,
696011e25f0dSDavid C Somayajulu 								     p_ptt,
696111e25f0dSDavid C Somayajulu 								     min_rate);
696211e25f0dSDavid C Somayajulu 		}
696311e25f0dSDavid C Somayajulu 
696411e25f0dSDavid C Somayajulu 		ecore_ptt_release(p_hwfn, p_ptt);
696511e25f0dSDavid C Somayajulu 	}
696611e25f0dSDavid C Somayajulu 
696711e25f0dSDavid C Somayajulu 	return rc;
696811e25f0dSDavid C Somayajulu }
696911e25f0dSDavid C Somayajulu 
ecore_clean_wfq_db(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)697011e25f0dSDavid C Somayajulu void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
697111e25f0dSDavid C Somayajulu {
697211e25f0dSDavid C Somayajulu 	struct ecore_mcp_link_state *p_link;
697311e25f0dSDavid C Somayajulu 
697411e25f0dSDavid C Somayajulu 	p_link = &p_hwfn->mcp_info->link_output;
697511e25f0dSDavid C Somayajulu 
697611e25f0dSDavid C Somayajulu 	if (p_link->min_pf_rate)
69779efd0ba7SDavid C Somayajulu 		ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt);
697811e25f0dSDavid C Somayajulu 
697911e25f0dSDavid C Somayajulu 	OSAL_MEMSET(p_hwfn->qm_info.wfq_data, 0,
698011e25f0dSDavid C Somayajulu 		    sizeof(*p_hwfn->qm_info.wfq_data) *
698111e25f0dSDavid C Somayajulu 				p_hwfn->qm_info.num_vports);
698211e25f0dSDavid C Somayajulu }
698311e25f0dSDavid C Somayajulu 
ecore_device_num_engines(struct ecore_dev * p_dev)698411e25f0dSDavid C Somayajulu int ecore_device_num_engines(struct ecore_dev *p_dev)
698511e25f0dSDavid C Somayajulu {
698611e25f0dSDavid C Somayajulu 	return ECORE_IS_BB(p_dev) ? 2 : 1;
698711e25f0dSDavid C Somayajulu }
698811e25f0dSDavid C Somayajulu 
ecore_device_num_ports(struct ecore_dev * p_dev)698911e25f0dSDavid C Somayajulu int ecore_device_num_ports(struct ecore_dev *p_dev)
699011e25f0dSDavid C Somayajulu {
6991*217ec208SDavid C Somayajulu 	return p_dev->num_ports;
699211e25f0dSDavid C Somayajulu }
699311e25f0dSDavid C Somayajulu 
ecore_set_fw_mac_addr(__le16 * fw_msb,__le16 * fw_mid,__le16 * fw_lsb,u8 * mac)699411e25f0dSDavid C Somayajulu void ecore_set_fw_mac_addr(__le16 *fw_msb,
699511e25f0dSDavid C Somayajulu 			  __le16 *fw_mid,
699611e25f0dSDavid C Somayajulu 			  __le16 *fw_lsb,
699711e25f0dSDavid C Somayajulu 			  u8 *mac)
699811e25f0dSDavid C Somayajulu {
699911e25f0dSDavid C Somayajulu 	((u8 *)fw_msb)[0] = mac[1];
700011e25f0dSDavid C Somayajulu 	((u8 *)fw_msb)[1] = mac[0];
700111e25f0dSDavid C Somayajulu 	((u8 *)fw_mid)[0] = mac[3];
700211e25f0dSDavid C Somayajulu 	((u8 *)fw_mid)[1] = mac[2];
700311e25f0dSDavid C Somayajulu 	((u8 *)fw_lsb)[0] = mac[5];
700411e25f0dSDavid C Somayajulu 	((u8 *)fw_lsb)[1] = mac[4];
700511e25f0dSDavid C Somayajulu }
7006*217ec208SDavid C Somayajulu 
ecore_set_dev_access_enable(struct ecore_dev * p_dev,bool b_enable)7007*217ec208SDavid C Somayajulu void ecore_set_dev_access_enable(struct ecore_dev *p_dev, bool b_enable)
7008*217ec208SDavid C Somayajulu {
7009*217ec208SDavid C Somayajulu 	if (p_dev->recov_in_prog != !b_enable) {
7010*217ec208SDavid C Somayajulu 		DP_INFO(p_dev, "%s access to the device\n",
7011*217ec208SDavid C Somayajulu 			b_enable ?  "Enable" : "Disable");
7012*217ec208SDavid C Somayajulu 		p_dev->recov_in_prog = !b_enable;
7013*217ec208SDavid C Somayajulu 	}
7014*217ec208SDavid C Somayajulu }
7015*217ec208SDavid C Somayajulu 
7016*217ec208SDavid C Somayajulu #ifdef _NTDDK_
7017*217ec208SDavid C Somayajulu #pragma warning(pop)
7018*217ec208SDavid C Somayajulu #endif
7019