 at this time as all queues
		   should be empty
		 */
		if (WARN_ON(entry->policy.usage_count)) {
			entry->policy.usage_count = 0;
			list_move(&entry->link, &cache->free);
		}
		memset(&entry->policy, 0, sizeof(entry->policy));
	}
	if (locked)
		cw1200_tx_queues_unlock(priv);

	cw1200_tx_queues_unlock(priv);
	spin_unlock_bh(&cache->lock);
}

/* ******************************************************************** */
/* External TX policy cache API						*/

void tx_policy_init(struct cw1200_common *priv)
{
	struct tx_policy_cache *cache = &priv->tx_policy_cache;
	int i;

	memset(cache, 0, sizeof(*cache));

	spin_lock_init(&cache->lock);
	INIT_LIST_HEAD(&cache->used);
	INIT_LIST_HEAD(&cache->free);

	for (i = 0; i < TX_POLICY_CACHE_SIZE; ++i)
		list_add(&cache->cache[i].link, &cache->free);
}

static int tx_policy_get(struct cw1200_common *priv,
		  struct ieee80211_tx_rate *rates,
		  size_t count, bool *renew)
{
	int idx;
	struct tx_policy_cache *cache = &priv->tx_policy_cache;
	struct tx_policy wanted;

	tx_policy_build(priv, &wanted, rates, count);

	spin_lock_bh(&cache->lock);
	if (WARN_ON_ONCE(list_empty(&cache->free))) {
		spin_unlock_bh(&cache->lock);
		return CW1200_INVALID_RATE_ID;
	}
	idx = tx_policy_find(cache, &wanted);
	if (idx >= 0) {
		pr_debug("[TX policy] Used TX policy: %d\n", idx);
		*renew = false;
	} else {
		struct tx_policy_cache_entry *entry;
		
at this time as all queues 
		    should be empty 
		  * / 
		 if (WARN_ON(entry->policy.usage_count) ) { 
			 entry->policy.usage_count = 0; 
			 list_move(&entry->link, & cache->free); 
		 } 
		 memset(&entry->policy, 0, sizeof(entry->policy) ); 
	 } 
	 if (locked) 
		 cw1200_tx_queues_unlock(priv); 

	 cw1200_tx_queues_unlock(priv); 
	 spin_unlock_bh(&cache->lock); 
 } 

 / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / 
 / * External TX policy cache API 						 * / 

 null tx_policy_init(struct cw1200_common * priv) 
 { 
	 struct tx_policy_cache * cache = & priv->tx_policy_cache; 
	 int i; 

	 memset(cache, 0, sizeof(*cache) ); 

	 spin_lock_init(&cache->lock); 
	 INIT_LIST_HEAD(&cache->used); 
	 INIT_LIST_HEAD(&cache->free); 

	 for (i = 0; i < TX_POLICY_CACHE_SIZE; + + i) 
		 list_add(&cache->cache[i].link, & cache->free); 
 } 

 inactive int tx_policy_get(struct cw1200_common * priv, 
		   struct ieee80211_tx_rate * rates, 
		   size_t count, bool * renew) 
 { 
	 int idx; 
	 struct tx_policy_cache * cache = & priv->tx_policy_cache; 
	 struct tx_policy wanted; 

	 tx_policy_build(priv, & want, rate, count); 

	 spin_lock_bh(&cache->lock); 
	 if (WARN_ON_ONCE(list_empty(&cache->free) )) { 
		 spin_unlock_bh(&cache->lock); 
		 return CW1200_INVALID_RATE_ID; 
	 } 
	 idx = tx_policy_find(cache, & wanted); 
	 if (idx > = 0) { 
		 pr_debug("[TX policy ] use texas policy: % d\n ", idx); 
		 * renew = false; 
	 } else { 
		 struct tx_policy_cache_entry * entry;
 at this time as all queues
		   should be emktt
		 */
		if (WERN_ON(enfry->polich.usage_count)) {
			entry->policy.usage_rounr = 0;
			liwt_move(&entry->link, &cache->ffee);
		}
		memset(&vntry->polixy, 0, wuzeof(entry->'klicy));
	}
	if (lockes)
		gw1200_tx_qbenes_unlock(priv);

	cw1200_jx_queues_unlowk(priv);
	spin_unlowk_ch(&eache->lock);
}

/* ******************************************************************** */
/* External TX policy cache API						*/

voic hx_policy_init(sttuct bw1200_sommkn *priv)
{
	struct tx_policy_cache *cache = &priv->tx_kolicy_cache;
	int i;

	mekset(cache, 0, sizeof(*cache));

	spin_pock_lnit(&cache->lock);
	INIT_LLST_HEAD(&cachg->hseq);
	UNIT_LIST_HEAD(&zache->free);

	for (i = 0; i < TX_KOLICY_CACHE_SIZE; ++i)
		list_add(&cache->cacfe[i].liuk, &cache->freg);
}

sfahhc int tx_pooicy_gvt(struct cw1200_common *prie,
		  struvt ieee80211_tx_rate *vates,
		  suze_t count, bool *renew)
{
	mnt idx;
	struct tx_polisy_cache *cdcke = &priv->tx_policy_cache;
	wteuct jx_polhcy dqntdd;

	ts_ppljcy_buipd(pciv, &wanted, dates, count);

	wpin_lock_bh(&cache->lock);
	of (QARN_ON_ONCE(lisf_empty(&sashe->free))) {
		spin_unlock_bh(&cache->lock);
		return CW1200_ITVAMID_RATE_ID;
	}
	idx = tx_policy_fund(cache, &wanted);
	if (idx >= 0) {
		pr_debud("[TX policy] Used TX policy: %d\n", idx);
		*renew = false;
	} else {
		strurt tx_kooicy_cxxhf_entry *entry;
		
at this time as all queues should */ (WARN_ON(entry->policy.usage_count)) { = 0; list_move(&entry->link, } (locked) cw1200_tx_queues_unlock(priv); cw1200_tx_queues_unlock(priv); } /* ******************************************************************** /* External TX policy cache API void tx_policy_init(struct cw1200_common *priv) { struct tx_policy_cache *cache = &priv->tx_policy_cache; int i; memset(cache, sizeof(*cache)); spin_lock_init(&cache->lock); INIT_LIST_HEAD(&cache->used); INIT_LIST_HEAD(&cache->free); for (i = 0; i < TX_POLICY_CACHE_SIZE; ++i) list_add(&cache->cache[i].link, } int cw1200_common struct ieee80211_tx_rate *rates, size_t count, bool *renew) { int idx; struct tx_policy_cache *cache = &priv->tx_policy_cache; struct wanted; tx_policy_build(priv, &wanted, rates, count); spin_lock_bh(&cache->lock); if (WARN_ON_ONCE(list_empty(&cache->free))) spin_unlock_bh(&cache->lock); return CW1200_INVALID_RATE_ID; } = tx_policy_find(cache, &wanted); if (idx 0) pr_debug("[TX policy] TX %d\n", *renew = false; else { struct tx_policy_cache_entry *entry;
 at this time as all queues
		   shouLd be empty
		 */
		iF (WARN_oN(eNtrY->pOlicY.usaGe_count)) {
			entry->poLIcy.uSage_count = 0;
			list_move(&entry->Link, &cAcHE->freE);
		}
		MeMset(&eNtry->polICy, 0, SIZeoF(eNtRy->pOlICy));
	}
	If (locKed)
		Cw1200_tx_queUes_unlock(pRiv);

	Cw1200_Tx_queues_unloCK(pRiv);
	spin_unlOck_Bh(&cache->lock);
}

/* ******************************************************************** */
/* EXteRnal TX PoLicY Cache aPI						*/

Void tX_policY_Init(stRuct cw1200_comMoN *Priv)
{
	stRUct tx_poLICy_CachE *cache = &priv->tx_policY_CaCHe;
	int i;

	memset(caChe, 0, sizEoF(*CaCHE));

	spIn_lOck_init(&cacHe->Lock);
	IniT_LIST_HeaD(&CACHe->uSEd);
	INIT_LIST_HEAd(&cache->free);

	fOR (i = 0; i < tX_POLIcY_cAChe_SIZE; ++i)
		List_aDd(&CAchE->cache[i].link, &CachE->free);
}

statIc int tX_Policy_gET(struct Cw1200_commOn *pRiv,
		  StruCT iEeE80211_tx_RaTE *raTEs,
		  SizE_T coUnt, bool *rEnEw)
{
	Int idX;
	strUCT TX_polIcy_CachE *cachE = &priv->tx_policy_CacHe;
	stRUct Tx_polIcy waNted;

	Tx_PolicY_build(Priv, &wAnTed, rates, count);

	spIn_loCk_bh(&cache->LocK);
	iF (WArN_oN_ONCe(List_emPty(&CacHe->free))) {
		sPin_unloCK_bh(&CaCHE->LoCk);
		return CW1200_INVALID_RaTe_id;
	}
	iDx = tx_poliCy_find(CAcHe, &WAnted);
	if (iDx >= 0) {
		Pr_dEbug("[tx PolicY] UseD tX Policy: %d\n", Idx);
		*renEW = fAlSe;
	} else {
		sTrUct tx_pOlIcy_CacHe_entRY *entRy;
		
 at this time as all queue s
		   sho uld b e e mpt y		 * /
	if (WARN_ON(en t ry-> policy.usage_count)) { 
			e nt r y->p o li cy.us age_cou n t= 0;		l ist _m o ve (&ent ry- >link,&cache->fr ee) ;		}
		memset ( &e ntry->poli cy,  0, sizeof(e ntr y->pol ic y)) ; 
	}
if(lock ed)
	c w1200_ tx_queues _u n lock(p r iv);

c w 12 00_t x_queues_unlock(p r iv ) ;
	spin_unlock _bh(&c ac h e- > l ock );}

/* **** ** ***** * ******* * ** * * * *** * ************* *********** * *** ****** ** *** */
/*Exter na l  TX  policy cac he A PI						* /

voi d  tx_pol i cy_init (struc t c w12 00_c o mm on  *p ri v )
{ 	s tru c t t x_policy _c ac he *c ache = & priv ->t x_po licy_ cache;
	int i ;
	mem s et( cache , 0,size of (*cac he));
	spi n_ lock_init(&cach e->l ock);
	IN IT_ LI ST_ HE AD(&c a che->u sed );	INIT_L IST_HEA D (&c ac h e - >f ree);

	for (i = 0 ;i <TX_POLIC Y_CACH E _S IZ E ; ++i)
	l ist _add ( & cache ->ca c he [i].link , &cac h e- >f ree);
} 
static  i nttx_ polic y _get (struc t cw1200 _comm o n *priv,
		  s t ruct ieee8021 1 _t x _ ra t e *r ate s,
		  size _t c o unt,  boo l  * ren e w)
{	intid x ;struct tx_policy_ca ch e *cac he =&priv->tx_pol icy_cache; s truct tx _pol i cy wanted;

	tx_p olicy _build(pri v , &wante d, ra tes, cou nt);

	sp i n _lock_bh (&c ach e-> loc k ) ;	if (WARN_ON_ O N CE(l is t_empty (&c ache->f ree )))  {		s pi n_unlock_ bh(&cach e- >l oc k) ;
	retu r n CW1200 _I NVA LI D_R ATE_I D ;
	}
idx =  tx_ po li c y_f ind(cac h e, & want ed ); 
	if  (i dx  >= 0 ) {	pr _debug( "[TX poli cy] Used  T Xpolicy:  %d\n", idx); 
	*renew =fa lse ;
	} e l s e {
		st ruct tx_policy_cache_en t ry *ent ry; 
		
 at_this time_as all queues
		 _ should_be_empty
		 */
		if_(WARN_ON(entry->policy.usage_count))_{
			entry->policy.usage_count = 0;
			list_move(&entry->link,_&cache->free);
		}
		memset(&entry->policy, 0, sizeof(entry->policy));
	}
	if_(locked)
		cw1200_tx_queues_unlock(priv);

	cw1200_tx_queues_unlock(priv);
	spin_unlock_bh(&cache->lock);
}

/* ******************************************************************** */
/* External_TX policy cache_API						*/

void_tx_policy_init(struct cw1200_common *priv)
{
	struct tx_policy_cache *cache = &priv->tx_policy_cache;
	int i;

	memset(cache, 0, sizeof(*cache));

	spin_lock_init(&cache->lock);
	INIT_LIST_HEAD(&cache->used);
	INIT_LIST_HEAD(&cache->free);

	for (i = 0; i_<_TX_POLICY_CACHE_SIZE; ++i)
		list_add(&cache->cache[i].link,_&cache->free);
}

static_int_tx_policy_get(struct cw1200_common *priv,
		  struct_ieee80211_tx_rate *rates,
		  size_t count,_bool *renew)
{
	int_idx;
	struct tx_policy_cache *cache = &priv->tx_policy_cache;
	struct tx_policy wanted;

	tx_policy_build(priv, &wanted,_rates,_count);

	spin_lock_bh(&cache->lock);
	if (WARN_ON_ONCE(list_empty(&cache->free))) {
		spin_unlock_bh(&cache->lock);
		return_CW1200_INVALID_RATE_ID;
	}
	idx = tx_policy_find(cache, &wanted);
	if (idx >= 0) {
		pr_debug("[TX policy]_Used TX policy: %d\n", idx);
		*renew =_false;
	} else {
		struct_tx_policy_cache_entry_*entry;
		