aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/check-perf-trace.py
diff options
context:
space:
mode:
authorVille Syrjälä <ville.syrjala@linux.intel.com>2015-09-18 13:03:39 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-10-13 07:16:19 -0400
commit68d9753837db0e45dadd16a312d479adf3170b2c (patch)
tree14d867bfa6169bbed18710b2bfc970bff7b4d1c9 /tools/perf/scripts/python/check-perf-trace.py
parent699fc401da1c9cc8c6bda578ca3d6310924276a2 (diff)
drm/i915: Protect register macro arguments
Always put parens around macro argument evaluations. Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'tools/perf/scripts/python/check-perf-trace.py')
0 files changed, 0 insertions, 0 deletions
3945.c?id=51aa87beb9dff42ccc3612811e83d1ad98141e0b'>commitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-3945.c
blob: c44a303e62ed45c2bdc9ea9b77db020eb927c39c (plain) (tree)
1
2
3

                                                                               
                                                                   

















                                                                               
                                              





                                                                               
                       
                       


                              
                        



                            
                              

                          
 
                   
                        
                         
                    
                     
                       
                     
                        

                         
                             








                                                             


                                                                  








                                                                      
                                                                     



                                                                         







                                                                         

  
                                                      



                                      
                                                                      






                                                                              
                                                  
 






















































                                                                                
                                                    
                                                                          


                       

                                                                        

                                                                      
                                                                                     
                                            
                                                          
                                                

                                                                           
 
                


                                                                                    




                                                        



                                              
                                                       




                                                    
                           
                                                                    



                                                         
                                    



























                                                                




                                             
                                                         









                                                         
                                 
                                                                          
                                              


                                                              
                      
 






                         







                                                                        
                                                           

                                                           
                                                      
                                      
                                    






                                                                              
                                                                       
                                       
                                                             

         
                                                                

                                                        
                                             




                                           
                                                      
                                                              
 
                                                  


                                                      
                                                      
                                       


                                                                 
                 
 
                                                                              
                                                                              





                                                                   
                                                                  







                                                                             


                                                                       
 
                                                                

                                                                        
 
                                                                                      


                                                                           
                                                                 


                                                          
                                                                         



 





                                                                              
                                                                               





































                                                                             
 




























































                                                                              

                                                    
 
                                                  
 
                                                                            
                                                                  
                                                                              


                                                                     
                                               
 
                                                                                    

 




















                                                                     




                                                                                
                           







                                                                           
                                                            
                                                






                                                                           
                  

















                                                                    
                                   






















                                                                      

                                                                        

















                                                                      
                         


                                            
                                                 
                                        
                                                     
                                         
                                                       
                                         
                                                       

























                                                                            
                                                                         
                                                                            
                                                                              


                                                                   
                                                                     

                                                                          
                                                                              





                                                                    
                                                                  
 




                                                                 
                                                  


                                                                       
     
                                                                  
                                                




                                                                 
                                                                        
                                                           




                                                                           
                                                                          

                                                                       
                                                                             





                                                                       
 
                                                                  
                                                                 
                                                                     
 
                                                  
                                                                             

                                                              

                                           
                                       

                                                                

                                                                   
                                                               




                                                                   

                                                                          

                       
 
                                 
                   
                                                        

                       
 
                                          
                                            
                                                                             

                                                                           


                                                                    
                                               
                                                               
 
                                    

                               

 

                                              
                                                      
                                                              
 

                                             
                                                  


                                                                    

                                                                                   
                          
 

                                                           
                        
                                                                             



                                                                             

                                                          
 
                                                             





                                                                           
                                                   

                                                                          




                                                                   
                                                                                 


                       
 

                                                  
                                                              
 


                                                                   
 

                                                          
                                                                 
 
                                                                           

                                                           
                                                                 
                                                  
 

                                                                 
                                                                          

                             



                                                                      

         
                                                               

 


                                                                                

                  
                            
                                          

                    

                                                  


                                             

                                                                   

                                                       
                                                                         



                                          

                                                 









                                                                   
                                                                           


                               
                                                                             
 
                                                                      

                                                  



                                            
                          
                                                                     
                                       
                                                                
                                                                            
                       

         


                                     

                                                                           

                                                  


                                       

                                                                         


                                                                               

                                                                          
                                                                        


                         
                

 
   
                                                             

  




                                                                 
 
                                                                       
                                                                     




                            
                                       
                                                                                  
 
                                              
                                    

                                                                     
                                     

                                   







                                                                




                                       


                                                   
 





                                                                 









                                                                

                                    

                  
                               
                                                                             

                 
                                                  
 
                                                                            
                                                            

                                                                     

 

                                                             

                                 
                                          




                                                       
                                          


                                                              



                                                            
                                                     
                                                                  



                                         
                                                                           
 
                                      
                                                                 
                                                                      

                                                                      
 
                                                       

                                                                      
                 
                
                                                              


                                                               
                                                                              

                                                                        
 
                 

 
                                                                           
 
                                                                       
                                                                           

                                                       







                                                                              

                                             
                                                
 


                 
                                                  
 

                         
                                                    

                            
                                                        

                                   
                                                       
 



                                                                
 
                                                    
                                                      
 
                                                      






                                                                    
 








                                                        
                                                       



                              
                                      
 




                                         





                                    
                                                                          

                                                                 

                                                                           
                         
                                                                           






                                   
                                      


                  
 
  

                                                              

                                                                   
                                                  
 
                                     
 








                                                                                

                   
 

                                                     
                                                                              

                            
 

                                              




                                                                      
                                            
                                                   
                                                         
                                                             
                                                       
                                                                
                
                                                             
                                                       
                                                                

         
                                                            
                                                             
                                                       
                                                                
              
                                                               
 
                                                      
                                                                  
                                                       
                                                       
                                                                   
                
                                                                  
                                                       
                                                         
                                                                     

         
                                            
                                                       
                                                                        
                                                                       
                                                         
                
                                                                       
                                                         
                                                       
                                                                        


                                                   
                                                               
                                                                             
 
                                                               
                                                                             



                                              







                                                   
                                                                               
               

                          
                                                  


                                                                        
                                              
                         
                                                                         


                                       
                                                  
 
                                   


                                   


                                      
                                                 

          
                                                                     










                                            
                                             


                                           
                                                   



                       






                                                                      
 

                                     

 
                                                   
 
                   

                      
                                                  
                                                    

                              
                                                                          

                                                                        
                                                                              


                                      
                                      

 
   
                                      

                                                    
                                                                                




                                                         
                                                                    
   
                                                                   
 
                                                                    

 
                                                     
 
                                                   


   
                                         

                                                  
                                                                        
 
                                                                              

                        
                                                       


                                                      
                                                                                  

                                        
                                                            
                                                                                



                                                                                
                                                                    

















                                                                         
                                                      


                      
                                                                         



                                                               
                                                                                

                                       
                                                      
            
                                                                                


                                                                           
                                                                          


                         
                                                              












                                                                           
                                                                            































































































































































                                                            
                                                          











                                                           
                                                                       



                                                                               
                                                                                    
                                                                   
                                                                

                                              
                                                        







                                                                          
                                                                             



                                                                     
                                                    








                                                                            
                                                              










                                                                            
                                                                  








                                                                
                                                                      



                                                                   
                                                       
 
                        
                                                      
                                                   
                                                     

          
                                                                   
                                            
                                                  
                                                                               
                       

                                                                           
                                                                            



                                         
                                                                        




                                                                            

                                                   
                                                                 

                                                                  
                                                                     
 
                                                                                  

                                                             







                                                                  
                                                                     
 
                                                                                  




                                                               

         


                                                                        



   
                                                                       













                                                                              
                                                              
                                                              
 
                                                      





                                                              
                                                                              




                                                                     
                                                                        






















                                                                               
                                                                  

                                                                   
                                                                             
                                                                                       

                                                            
                                                                          








                                                                            
                                                                            




                                                                           
                                                                                

















                                                                   
                                                                







                                                                         
                                                                  
 
                                                
                                                                              








                                                                              




                                                         





                                                                              
                                                                     

                                
                                                                          
                           
                                                                              











                                                                             
                                                                              






                                                                      
                                                                                      




                                                                             
                                                                              
                                                                           





                                                                   
                                                        

 
                                                               
 
                                         



                     
                                               
                                                                           



                                                          
                                                                              
                                        








                                                                            
                                                                         




                                                                         
                                                                    





                                                    
                                               



                 


                                                         
                                  



                                                 
                                      






















                                                                                    

                                                     



                                                                            
                                             



                  











































































                                                                                  
                                               
                                           
















                                                                      
                                                                   











                                                                             
                         
                                               

                                           








                                                                             









                                                                         









                                                                             
                                                        

                                              
                                                      





                                                                   
                                               


                                           
                                                                                   

 
                                                                     
 
                                                                   
                                                                          









                                                         
                                                                       








                                                                             
                                                                 
                                                                              
 

                                                                              


















                                                                             
                                                                             




                                     
                                                                            



                                                                             
                                                                        


                                                                         
                                                                   
                                                                              


                                        
                                                            



                           
                                                  

































                                                                                
                                                                     


                       
                                                                              
                                                         
 
                                                                               



                                                                          
                                           


                                                                    
                                                                        













                                                                         
                                                                          





                                                                             
                                                                                   
                                             
                                                      




                                                                   
                                                      




                                                                    
                                                      



























                                                                              
                                                          
 
                                                
                                                    
                                                                              











                                                                         
                                                                   

                                             
                                                 









                                                                              
                                                                       

                                                                    
                                                                                      


                                                                               
                                                                              
                                                                     

                                             
                                                                              





                                                                            
                                                         










                                                                          
                                                                              


                                                                              
                                                                       







                                                                    
                                                                              
 
                                                                                  








                                                                               
                                                                          







                                                             
                                                                      


                                                                          
                                                                            

                                                                            


                                                                                   










                                                                             
                                                                                  
                                                                           






                                                                          
                                              

               
 

                                                         
                                                                   
                   
                                                      
 


                 
                                                                             
 

                               
                                                                     


                                                                             

                                                            
 
                                                          




                                                                   

                                                 
                                             



                 






                                                    


                                                             




                           
 

                                                                                












                                                                              

 


                                                                           
                                                              

                
                  
                                                                             
                                                                          


                                   
                                                                   


                                                                      
                                                                               



                         

                                                                    
 
 


                                                                           
                                                     
 
                                     
                                                    

                                      
                                                                 
 

                                                         

                                           
                                                                              
                                                        
                                                           

                                                                         

         

                                 
                                                                   

                                                             



                                                                            

                                                  

                                                                        

                                                  
                                                                
                                                                      

                      
                                 
                                                                     

                                                                    
 
                                                                          
                                              










                                                                               


                      
                           




                                                          
                                                                       





                                                       
                                                                         


                                           
                                     
                                                   
 

                                             
 




                                                                         
                                                                 


                               
                                               
                                                               
 
                                                              
                                                                      



                                                             
 
                                                               
                                                                           
 


                 
                                                             
                                                               
 
                                                    

                                
                                                                  

                                                         
                                                                

                                                                          
                                                    
                                                     








                                                                           



                                                                          
                                         
                                                 
 
                                                                 

 
                                                       
 
                                                          


                                                               
                                                          
 
                                                        


                                                           
                                                           
 
                                                           

 







                                                    
                                                   
















                                                                                
                                                               



                 


























                                                                                












































                                                                               
                                                 














                                                                            












                                                                    
               
                          



















                                                                              
                                                                                    









                                                                              


                 

                                              
                                           
                                             

  
                                         

                                                                  
                                             
                                       

                                                         

                                         
                                     
                                             
                                                   
          






                                                          

                                                       





                                                                      
                                                
                                                                 
                                                 
                              
                                       
                                                           
                                                        
                                                      





                                                                       

  

                                                       
                                                       
                                                   
                                             

  
                                           
                            
                              
                                     
                                

  
                                        
                         


                                               
                         

                                                 
                            
                                          
                                          


                                             

                                       
                               
                                 
                                                                    
                                                        
                                  
                                   

  
                                         
                          


                                               
                                   

                                                 
                            
                                          
                                          

                                       
                               
                                 
                                                                    
                                                        
                                  
                                   

  
                                                





                                                              


           
                                              
/******************************************************************************
 *
 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 * The full GNU General Public License is included in this distribution in the
 * file called LICENSE.
 *
 * Contact Information:
 *  Intel Linux Wireless <ilw@linux.intel.com>
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *
 *****************************************************************************/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/pci.h>
#include <linux/dma-mapping.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/wireless.h>
#include <linux/firmware.h>
#include <linux/etherdevice.h>
#include <asm/unaligned.h>
#include <net/mac80211.h>

#include "iwl-fh.h"
#include "iwl-3945-fh.h"
#include "iwl-commands.h"
#include "iwl-sta.h"
#include "iwl-3945.h"
#include "iwl-eeprom.h"
#include "iwl-core.h"
#include "iwl-helpers.h"
#include "iwl-led.h"
#include "iwl-3945-led.h"
#include "iwl-3945-debugfs.h"

#define IWL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np)    \
	[IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP,   \
				    IWL_RATE_##r##M_IEEE,   \
				    IWL_RATE_##ip##M_INDEX, \
				    IWL_RATE_##in##M_INDEX, \
				    IWL_RATE_##rp##M_INDEX, \
				    IWL_RATE_##rn##M_INDEX, \
				    IWL_RATE_##pp##M_INDEX, \
				    IWL_RATE_##np##M_INDEX, \
				    IWL_RATE_##r##M_INDEX_TABLE, \
				    IWL_RATE_##ip##M_INDEX_TABLE }

/*
 * Parameter order:
 *   rate, prev rate, next rate, prev tgg rate, next tgg rate
 *
 * If there isn't a valid next or previous rate then INV is used which
 * maps to IWL_RATE_INVALID
 *
 */
const struct iwl3945_rate_info iwl3945_rates[IWL_RATE_COUNT_3945] = {
	IWL_DECLARE_RATE_INFO(1, INV, 2, INV, 2, INV, 2),    /*  1mbps */
	IWL_DECLARE_RATE_INFO(2, 1, 5, 1, 5, 1, 5),          /*  2mbps */
	IWL_DECLARE_RATE_INFO(5, 2, 6, 2, 11, 2, 11),        /*5.5mbps */
	IWL_DECLARE_RATE_INFO(11, 9, 12, 5, 12, 5, 18),      /* 11mbps */
	IWL_DECLARE_RATE_INFO(6, 5, 9, 5, 11, 5, 11),        /*  6mbps */
	IWL_DECLARE_RATE_INFO(9, 6, 11, 5, 11, 5, 11),       /*  9mbps */
	IWL_DECLARE_RATE_INFO(12, 11, 18, 11, 18, 11, 18),   /* 12mbps */
	IWL_DECLARE_RATE_INFO(18, 12, 24, 12, 24, 11, 24),   /* 18mbps */
	IWL_DECLARE_RATE_INFO(24, 18, 36, 18, 36, 18, 36),   /* 24mbps */
	IWL_DECLARE_RATE_INFO(36, 24, 48, 24, 48, 24, 48),   /* 36mbps */
	IWL_DECLARE_RATE_INFO(48, 36, 54, 36, 54, 36, 54),   /* 48mbps */
	IWL_DECLARE_RATE_INFO(54, 48, INV, 48, INV, 48, INV),/* 54mbps */
};

/* 1 = enable the iwl3945_disable_events() function */
#define IWL_EVT_DISABLE (0)
#define IWL_EVT_DISABLE_SIZE (1532/32)

/**
 * iwl3945_disable_events - Disable selected events in uCode event log
 *
 * Disable an event by writing "1"s into "disable"
 *   bitmap in SRAM.  Bit position corresponds to Event # (id/type).
 *   Default values of 0 enable uCode events to be logged.
 * Use for only special debugging.  This function is just a placeholder as-is,
 *   you'll need to provide the special bits! ...
 *   ... and set IWL_EVT_DISABLE to 1. */
void iwl3945_disable_events(struct iwl_priv *priv)
{
	int i;
	u32 base;		/* SRAM address of event log header */
	u32 disable_ptr;	/* SRAM address of event-disable bitmap array */
	u32 array_size;		/* # of u32 entries in array */
	u32 evt_disable[IWL_EVT_DISABLE_SIZE] = {
		0x00000000,	/*   31 -    0  Event id numbers */
		0x00000000,	/*   63 -   32 */
		0x00000000,	/*   95 -   64 */
		0x00000000,	/*  127 -   96 */
		0x00000000,	/*  159 -  128 */
		0x00000000,	/*  191 -  160 */
		0x00000000,	/*  223 -  192 */
		0x00000000,	/*  255 -  224 */
		0x00000000,	/*  287 -  256 */
		0x00000000,	/*  319 -  288 */
		0x00000000,	/*  351 -  320 */
		0x00000000,	/*  383 -  352 */
		0x00000000,	/*  415 -  384 */
		0x00000000,	/*  447 -  416 */
		0x00000000,	/*  479 -  448 */
		0x00000000,	/*  511 -  480 */
		0x00000000,	/*  543 -  512 */
		0x00000000,	/*  575 -  544 */
		0x00000000,	/*  607 -  576 */
		0x00000000,	/*  639 -  608 */
		0x00000000,	/*  671 -  640 */
		0x00000000,	/*  703 -  672 */
		0x00000000,	/*  735 -  704 */
		0x00000000,	/*  767 -  736 */
		0x00000000,	/*  799 -  768 */
		0x00000000,	/*  831 -  800 */
		0x00000000,	/*  863 -  832 */
		0x00000000,	/*  895 -  864 */
		0x00000000,	/*  927 -  896 */
		0x00000000,	/*  959 -  928 */
		0x00000000,	/*  991 -  960 */
		0x00000000,	/* 1023 -  992 */
		0x00000000,	/* 1055 - 1024 */
		0x00000000,	/* 1087 - 1056 */
		0x00000000,	/* 1119 - 1088 */
		0x00000000,	/* 1151 - 1120 */
		0x00000000,	/* 1183 - 1152 */
		0x00000000,	/* 1215 - 1184 */
		0x00000000,	/* 1247 - 1216 */
		0x00000000,	/* 1279 - 1248 */
		0x00000000,	/* 1311 - 1280 */
		0x00000000,	/* 1343 - 1312 */
		0x00000000,	/* 1375 - 1344 */
		0x00000000,	/* 1407 - 1376 */
		0x00000000,	/* 1439 - 1408 */
		0x00000000,	/* 1471 - 1440 */
		0x00000000,	/* 1503 - 1472 */
	};

	base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
	if (!iwl3945_hw_valid_rtc_data_addr(base)) {
		IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
		return;
	}

	disable_ptr = iwl_read_targ_mem(priv, base + (4 * sizeof(u32)));
	array_size = iwl_read_targ_mem(priv, base + (5 * sizeof(u32)));

	if (IWL_EVT_DISABLE && (array_size == IWL_EVT_DISABLE_SIZE)) {
		IWL_DEBUG_INFO(priv, "Disabling selected uCode log events at 0x%x\n",
			       disable_ptr);
		for (i = 0; i < IWL_EVT_DISABLE_SIZE; i++)
			iwl_write_targ_mem(priv,
					   disable_ptr + (i * sizeof(u32)),
					   evt_disable[i]);

	} else {
		IWL_DEBUG_INFO(priv, "Selected uCode log events may be disabled\n");
		IWL_DEBUG_INFO(priv, "  by writing \"1\"s into disable bitmap\n");
		IWL_DEBUG_INFO(priv, "  in SRAM at 0x%x, size %d u32s\n",
			       disable_ptr, array_size);
	}

}

static int iwl3945_hwrate_to_plcp_idx(u8 plcp)
{
	int idx;

	for (idx = 0; idx < IWL_RATE_COUNT_3945; idx++)
		if (iwl3945_rates[idx].plcp == plcp)
			return idx;
	return -1;
}

#ifdef CONFIG_IWLWIFI_DEBUG
#define TX_STATUS_ENTRY(x) case TX_3945_STATUS_FAIL_ ## x: return #x

static const char *iwl3945_get_tx_fail_reason(u32 status)
{
	switch (status & TX_STATUS_MSK) {
	case TX_3945_STATUS_SUCCESS:
		return "SUCCESS";
		TX_STATUS_ENTRY(SHORT_LIMIT);
		TX_STATUS_ENTRY(LONG_LIMIT);
		TX_STATUS_ENTRY(FIFO_UNDERRUN);
		TX_STATUS_ENTRY(MGMNT_ABORT);
		TX_STATUS_ENTRY(NEXT_FRAG);
		TX_STATUS_ENTRY(LIFE_EXPIRE);
		TX_STATUS_ENTRY(DEST_PS);
		TX_STATUS_ENTRY(ABORTED);
		TX_STATUS_ENTRY(BT_RETRY);
		TX_STATUS_ENTRY(STA_INVALID);
		TX_STATUS_ENTRY(FRAG_DROPPED);
		TX_STATUS_ENTRY(TID_DISABLE);
		TX_STATUS_ENTRY(FRAME_FLUSHED);
		TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
		TX_STATUS_ENTRY(TX_LOCKED);
		TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
	}

	return "UNKNOWN";
}
#else
static inline const char *iwl3945_get_tx_fail_reason(u32 status)
{
	return "";
}
#endif

/*
 * get ieee prev rate from rate scale table.
 * for A and B mode we need to overright prev
 * value
 */
int iwl3945_rs_next_rate(struct iwl_priv *priv, int rate)
{
	int next_rate = iwl3945_get_prev_ieee_rate(rate);

	switch (priv->band) {
	case IEEE80211_BAND_5GHZ:
		if (rate == IWL_RATE_12M_INDEX)
			next_rate = IWL_RATE_9M_INDEX;
		else if (rate == IWL_RATE_6M_INDEX)
			next_rate = IWL_RATE_6M_INDEX;
		break;
	case IEEE80211_BAND_2GHZ:
		if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) &&
		    iwl_is_associated(priv)) {
			if (rate == IWL_RATE_11M_INDEX)
				next_rate = IWL_RATE_5M_INDEX;
		}
		break;

	default:
		break;
	}

	return next_rate;
}


/**
 * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
 *
 * When FW advances 'R' index, all entries between old and new 'R' index
 * need to be reclaimed. As result, some free space forms. If there is
 * enough free space (> low mark), wake the stack that feeds us.
 */
static void iwl3945_tx_queue_reclaim(struct iwl_priv *priv,
				     int txq_id, int index)
{
	struct iwl_tx_queue *txq = &priv->txq[txq_id];
	struct iwl_queue *q = &txq->q;
	struct iwl_tx_info *tx_info;

	BUG_ON(txq_id == IWL_CMD_QUEUE_NUM);

	for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
		q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {

		tx_info = &txq->txb[txq->q.read_ptr];
		ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0]);
		tx_info->skb[0] = NULL;
		priv->cfg->ops->lib->txq_free_tfd(priv, txq);
	}

	if (iwl_queue_space(q) > q->low_mark && (txq_id >= 0) &&
			(txq_id != IWL_CMD_QUEUE_NUM) &&
			priv->mac80211_registered)
		iwl_wake_queue(priv, txq_id);
}

/**
 * iwl3945_rx_reply_tx - Handle Tx response
 */
static void iwl3945_rx_reply_tx(struct iwl_priv *priv,
				struct iwl_rx_mem_buffer *rxb)
{
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	u16 sequence = le16_to_cpu(pkt->hdr.sequence);
	int txq_id = SEQ_TO_QUEUE(sequence);
	int index = SEQ_TO_INDEX(sequence);
	struct iwl_tx_queue *txq = &priv->txq[txq_id];
	struct ieee80211_tx_info *info;
	struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
	u32  status = le32_to_cpu(tx_resp->status);
	int rate_idx;
	int fail;

	if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
		IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
			  "is out of range [0-%d] %d %d\n", txq_id,
			  index, txq->q.n_bd, txq->q.write_ptr,
			  txq->q.read_ptr);
		return;
	}

	info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
	ieee80211_tx_info_clear_status(info);

	/* Fill the MRR chain with some info about on-chip retransmissions */
	rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate);
	if (info->band == IEEE80211_BAND_5GHZ)
		rate_idx -= IWL_FIRST_OFDM_RATE;

	fail = tx_resp->failure_frame;

	info->status.rates[0].idx = rate_idx;
	info->status.rates[0].count = fail + 1; /* add final attempt */

	/* tx_status->rts_retry_count = tx_resp->failure_rts; */
	info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
				IEEE80211_TX_STAT_ACK : 0;

	IWL_DEBUG_TX(priv, "Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
			txq_id, iwl3945_get_tx_fail_reason(status), status,
			tx_resp->rate, tx_resp->failure_frame);

	IWL_DEBUG_TX_REPLY(priv, "Tx queue reclaim %d\n", index);
	iwl3945_tx_queue_reclaim(priv, txq_id, index);

	if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
		IWL_ERR(priv, "TODO:  Implement Tx ABORT REQUIRED!!!\n");
}



/*****************************************************************************
 *
 * Intel PRO/Wireless 3945ABG/BG Network Connection
 *
 *  RX handler implementations
 *
 *****************************************************************************/
#ifdef CONFIG_IWLWIFI_DEBUG
/*
 *  based on the assumption of all statistics counter are in DWORD
 *  FIXME: This function is for debugging, do not deal with
 *  the case of counters roll-over.
 */
static void iwl3945_accumulative_statistics(struct iwl_priv *priv,
					    __le32 *stats)
{
	int i;
	__le32 *prev_stats;
	u32 *accum_stats;
	u32 *delta, *max_delta;

	prev_stats = (__le32 *)&priv->_3945.statistics;
	accum_stats = (u32 *)&priv->_3945.accum_statistics;
	delta = (u32 *)&priv->_3945.delta_statistics;
	max_delta = (u32 *)&priv->_3945.max_delta;

	for (i = sizeof(__le32); i < sizeof(struct iwl3945_notif_statistics);
	     i += sizeof(__le32), stats++, prev_stats++, delta++,
	     max_delta++, accum_stats++) {
		if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
			*delta = (le32_to_cpu(*stats) -
				le32_to_cpu(*prev_stats));
			*accum_stats += *delta;
			if (*delta > *max_delta)
				*max_delta = *delta;
		}
	}

	/* reset accumulative statistics for "no-counter" type statistics */
	priv->_3945.accum_statistics.general.temperature =
		priv->_3945.statistics.general.temperature;
	priv->_3945.accum_statistics.general.ttl_timestamp =
		priv->_3945.statistics.general.ttl_timestamp;
}
#endif

/**
 * iwl3945_good_plcp_health - checks for plcp error.
 *
 * When the plcp error is exceeding the thresholds, reset the radio
 * to improve the throughput.
 */
static bool iwl3945_good_plcp_health(struct iwl_priv *priv,
				struct iwl_rx_packet *pkt)
{
	bool rc = true;
	struct iwl3945_notif_statistics current_stat;
	int combined_plcp_delta;
	unsigned int plcp_msec;
	unsigned long plcp_received_jiffies;

	memcpy(&current_stat, pkt->u.raw, sizeof(struct
			iwl3945_notif_statistics));
	/*
	 * check for plcp_err and trigger radio reset if it exceeds
	 * the plcp error threshold plcp_delta.
	 */
	plcp_received_jiffies = jiffies;
	plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
					(long) priv->plcp_jiffies);
	priv->plcp_jiffies = plcp_received_jiffies;
	/*
	 * check to make sure plcp_msec is not 0 to prevent division
	 * by zero.
	 */
	if (plcp_msec) {
		combined_plcp_delta =
			(le32_to_cpu(current_stat.rx.ofdm.plcp_err) -
			le32_to_cpu(priv->_3945.statistics.rx.ofdm.plcp_err));

		if ((combined_plcp_delta > 0) &&
			((combined_plcp_delta * 100) / plcp_msec) >
			priv->cfg->plcp_delta_threshold) {
			/*
			 * if plcp_err exceed the threshold, the following
			 * data is printed in csv format:
			 *    Text: plcp_err exceeded %d,
			 *    Received ofdm.plcp_err,
			 *    Current ofdm.plcp_err,
			 *    combined_plcp_delta,
			 *    plcp_msec
			 */
			IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
				"%u, %d, %u mSecs\n",
				priv->cfg->plcp_delta_threshold,
				le32_to_cpu(current_stat.rx.ofdm.plcp_err),
				combined_plcp_delta, plcp_msec);
			/*
			 * Reset the RF radio due to the high plcp
			 * error rate
			 */
			rc = false;
		}
	}
	return rc;
}

void iwl3945_hw_rx_statistics(struct iwl_priv *priv,
		struct iwl_rx_mem_buffer *rxb)
{
	struct iwl_rx_packet *pkt = rxb_addr(rxb);

	IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
		     (int)sizeof(struct iwl3945_notif_statistics),
		     le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
#ifdef CONFIG_IWLWIFI_DEBUG
	iwl3945_accumulative_statistics(priv, (__le32 *)&pkt->u.raw);
#endif
	iwl_recover_from_statistics(priv, pkt);

	memcpy(&priv->_3945.statistics, pkt->u.raw, sizeof(priv->_3945.statistics));
}

void iwl3945_reply_statistics(struct iwl_priv *priv,
			      struct iwl_rx_mem_buffer *rxb)
{
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	__le32 *flag = (__le32 *)&pkt->u.raw;

	if (le32_to_cpu(*flag) & UCODE_STATISTICS_CLEAR_MSK) {
#ifdef CONFIG_IWLWIFI_DEBUG
		memset(&priv->_3945.accum_statistics, 0,
			sizeof(struct iwl3945_notif_statistics));
		memset(&priv->_3945.delta_statistics, 0,
			sizeof(struct iwl3945_notif_statistics));
		memset(&priv->_3945.max_delta, 0,
			sizeof(struct iwl3945_notif_statistics));
#endif
		IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
	}
	iwl3945_hw_rx_statistics(priv, rxb);
}


/******************************************************************************
 *
 * Misc. internal state and helper functions
 *
 ******************************************************************************/
#ifdef CONFIG_IWLWIFI_DEBUG

/**
 * iwl3945_report_frame - dump frame to syslog during debug sessions
 *
 * You may hack this function to show different aspects of received frames,
 * including selective frame dumps.
 * group100 parameter selects whether to show 1 out of 100 good frames.
 */
static void _iwl3945_dbg_report_frame(struct iwl_priv *priv,
		      struct iwl_rx_packet *pkt,
		      struct ieee80211_hdr *header, int group100)
{
	u32 to_us;
	u32 print_summary = 0;
	u32 print_dump = 0;	/* set to 1 to dump all frames' contents */
	u32 hundred = 0;
	u32 dataframe = 0;
	__le16 fc;
	u16 seq_ctl;
	u16 channel;
	u16 phy_flags;
	u16 length;
	u16 status;
	u16 bcn_tmr;
	u32 tsf_low;
	u64 tsf;
	u8 rssi;
	u8 agc;
	u16 sig_avg;
	u16 noise_diff;
	struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
	struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
	struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
	u8 *data = IWL_RX_DATA(pkt);

	/* MAC header */
	fc = header->frame_control;
	seq_ctl = le16_to_cpu(header->seq_ctrl);

	/* metadata */
	channel = le16_to_cpu(rx_hdr->channel);
	phy_flags = le16_to_cpu(rx_hdr->phy_flags);
	length = le16_to_cpu(rx_hdr->len);

	/* end-of-frame status and timestamp */
	status = le32_to_cpu(rx_end->status);
	bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
	tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
	tsf = le64_to_cpu(rx_end->timestamp);

	/* signal statistics */
	rssi = rx_stats->rssi;
	agc = rx_stats->agc;
	sig_avg = le16_to_cpu(rx_stats->sig_avg);
	noise_diff = le16_to_cpu(rx_stats->noise_diff);

	to_us = !compare_ether_addr(header->addr1, priv->mac_addr);

	/* if data frame is to us and all is good,
	 *   (optionally) print summary for only 1 out of every 100 */
	if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
	    cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
		dataframe = 1;
		if (!group100)
			print_summary = 1;	/* print each frame */
		else if (priv->framecnt_to_us < 100) {
			priv->framecnt_to_us++;
			print_summary = 0;
		} else {
			priv->framecnt_to_us = 0;
			print_summary = 1;
			hundred = 1;
		}
	} else {
		/* print summary for all other frames */
		print_summary = 1;
	}

	if (print_summary) {
		char *title;
		int rate;

		if (hundred)
			title = "100Frames";
		else if (ieee80211_has_retry(fc))
			title = "Retry";
		else if (ieee80211_is_assoc_resp(fc))
			title = "AscRsp";
		else if (ieee80211_is_reassoc_resp(fc))
			title = "RasRsp";
		else if (ieee80211_is_probe_resp(fc)) {
			title = "PrbRsp";
			print_dump = 1;	/* dump frame contents */
		} else if (ieee80211_is_beacon(fc)) {
			title = "Beacon";
			print_dump = 1;	/* dump frame contents */
		} else if (ieee80211_is_atim(fc))
			title = "ATIM";
		else if (ieee80211_is_auth(fc))
			title = "Auth";
		else if (ieee80211_is_deauth(fc))
			title = "DeAuth";
		else if (ieee80211_is_disassoc(fc))
			title = "DisAssoc";
		else
			title = "Frame";

		rate = iwl3945_hwrate_to_plcp_idx(rx_hdr->rate);
		if (rate == -1)
			rate = 0;
		else
			rate = iwl3945_rates[rate].ieee / 2;

		/* print frame summary.
		 * MAC addresses show just the last byte (for brevity),
		 *    but you can hack it to show more, if you'd like to. */
		if (dataframe)
			IWL_DEBUG_RX(priv, "%s: mhd=0x%04x, dst=0x%02x, "
				     "len=%u, rssi=%d, chnl=%d, rate=%d,\n",
				     title, le16_to_cpu(fc), header->addr1[5],
				     length, rssi, channel, rate);
		else {
			/* src/dst addresses assume managed mode */
			IWL_DEBUG_RX(priv, "%s: 0x%04x, dst=0x%02x, "
				     "src=0x%02x, rssi=%u, tim=%lu usec, "
				     "phy=0x%02x, chnl=%d\n",
				     title, le16_to_cpu(fc), header->addr1[5],
				     header->addr3[5], rssi,
				     tsf_low - priv->scan_start_tsf,
				     phy_flags, channel);
		}
	}
	if (print_dump)
		iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
}

static void iwl3945_dbg_report_frame(struct iwl_priv *priv,
		      struct iwl_rx_packet *pkt,
		      struct ieee80211_hdr *header, int group100)
{
	if (iwl_get_debug_level(priv) & IWL_DL_RX)
		_iwl3945_dbg_report_frame(priv, pkt, header, group100);
}

#else
static inline void iwl3945_dbg_report_frame(struct iwl_priv *priv,
		      struct iwl_rx_packet *pkt,
		      struct ieee80211_hdr *header, int group100)
{
}
#endif

/* This is necessary only for a number of statistics, see the caller. */
static int iwl3945_is_network_packet(struct iwl_priv *priv,
		struct ieee80211_hdr *header)
{
	/* Filter incoming packets to determine if they are targeted toward
	 * this network, discarding packets coming from ourselves */
	switch (priv->iw_mode) {
	case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source    | BSSID */
		/* packets to our IBSS update information */
		return !compare_ether_addr(header->addr3, priv->bssid);
	case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
		/* packets to our IBSS update information */
		return !compare_ether_addr(header->addr2, priv->bssid);
	default:
		return 1;
	}
}

static void iwl3945_pass_packet_to_mac80211(struct iwl_priv *priv,
				   struct iwl_rx_mem_buffer *rxb,
				   struct ieee80211_rx_status *stats)
{
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);
	struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
	struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
	u16 len = le16_to_cpu(rx_hdr->len);
	struct sk_buff *skb;
	__le16 fc = hdr->frame_control;

	/* We received data from the HW, so stop the watchdog */
	if (unlikely(len + IWL39_RX_FRAME_SIZE >
		     PAGE_SIZE << priv->hw_params.rx_page_order)) {
		IWL_DEBUG_DROP(priv, "Corruption detected!\n");
		return;
	}

	/* We only process data packets if the interface is open */
	if (unlikely(!priv->is_open)) {
		IWL_DEBUG_DROP_LIMIT(priv,
			"Dropping packet while interface is not open.\n");
		return;
	}

	skb = dev_alloc_skb(128);
	if (!skb) {
		IWL_ERR(priv, "dev_alloc_skb failed\n");
		return;
	}

	if (!iwl3945_mod_params.sw_crypto)
		iwl_set_decrypted_flag(priv,
				       (struct ieee80211_hdr *)rxb_addr(rxb),
				       le32_to_cpu(rx_end->status), stats);

	skb_add_rx_frag(skb, 0, rxb->page,
			(void *)rx_hdr->payload - (void *)pkt, len);

	iwl_update_stats(priv, false, fc, len);
	memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));

	ieee80211_rx(priv->hw, skb);
	priv->alloc_rxb_page--;
	rxb->page = NULL;
}

#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)

static void iwl3945_rx_reply_rx(struct iwl_priv *priv,
				struct iwl_rx_mem_buffer *rxb)
{
	struct ieee80211_hdr *header;
	struct ieee80211_rx_status rx_status;
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
	struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
	struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
	u16 rx_stats_sig_avg __maybe_unused = le16_to_cpu(rx_stats->sig_avg);
	u16 rx_stats_noise_diff __maybe_unused = le16_to_cpu(rx_stats->noise_diff);
	u8 network_packet;

	rx_status.flag = 0;
	rx_status.mactime = le64_to_cpu(rx_end->timestamp);
	rx_status.freq =
		ieee80211_channel_to_frequency(le16_to_cpu(rx_hdr->channel));
	rx_status.band = (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
				IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;

	rx_status.rate_idx = iwl3945_hwrate_to_plcp_idx(rx_hdr->rate);
	if (rx_status.band == IEEE80211_BAND_5GHZ)
		rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;

	rx_status.antenna = (le16_to_cpu(rx_hdr->phy_flags) &
					RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;

	/* set the preamble flag if appropriate */
	if (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
		rx_status.flag |= RX_FLAG_SHORTPRE;

	if ((unlikely(rx_stats->phy_count > 20))) {
		IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
				rx_stats->phy_count);
		return;
	}

	if (!(rx_end->status & RX_RES_STATUS_NO_CRC32_ERROR)
	    || !(rx_end->status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
		IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", rx_end->status);
		return;
	}



	/* Convert 3945's rssi indicator to dBm */
	rx_status.signal = rx_stats->rssi - IWL39_RSSI_OFFSET;

	IWL_DEBUG_STATS(priv, "Rssi %d sig_avg %d noise_diff %d\n",
			rx_status.signal, rx_stats_sig_avg,
			rx_stats_noise_diff);

	header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);

	network_packet = iwl3945_is_network_packet(priv, header);

	IWL_DEBUG_STATS_LIMIT(priv, "[%c] %d RSSI:%d Signal:%u, Rate:%u\n",
			      network_packet ? '*' : ' ',
			      le16_to_cpu(rx_hdr->channel),
			      rx_status.signal, rx_status.signal,
			      rx_status.rate_idx);

	/* Set "1" to report good data frames in groups of 100 */
	iwl3945_dbg_report_frame(priv, pkt, header, 1);
	iwl_dbg_log_rx_data_frame(priv, le16_to_cpu(rx_hdr->len), header);

	if (network_packet) {
		priv->_3945.last_beacon_time =
			le32_to_cpu(rx_end->beacon_timestamp);
		priv->_3945.last_tsf = le64_to_cpu(rx_end->timestamp);
		priv->_3945.last_rx_rssi = rx_status.signal;
	}

	iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
}

int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
				     struct iwl_tx_queue *txq,
				     dma_addr_t addr, u16 len, u8 reset, u8 pad)
{
	int count;
	struct iwl_queue *q;
	struct iwl3945_tfd *tfd, *tfd_tmp;

	q = &txq->q;
	tfd_tmp = (struct iwl3945_tfd *)txq->tfds;
	tfd = &tfd_tmp[q->write_ptr];

	if (reset)
		memset(tfd, 0, sizeof(*tfd));

	count = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));

	if ((count >= NUM_TFD_CHUNKS) || (count < 0)) {
		IWL_ERR(priv, "Error can not send more than %d chunks\n",
			  NUM_TFD_CHUNKS);
		return -EINVAL;
	}

	tfd->tbs[count].addr = cpu_to_le32(addr);
	tfd->tbs[count].len = cpu_to_le32(len);

	count++;

	tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(count) |
					 TFD_CTL_PAD_SET(pad));

	return 0;
}

/**
 * iwl3945_hw_txq_free_tfd - Free one TFD, those at index [txq->q.read_ptr]
 *
 * Does NOT advance any indexes
 */
void iwl3945_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
{
	struct iwl3945_tfd *tfd_tmp = (struct iwl3945_tfd *)txq->tfds;
	int index = txq->q.read_ptr;
	struct iwl3945_tfd *tfd = &tfd_tmp[index];
	struct pci_dev *dev = priv->pci_dev;
	int i;
	int counter;

	/* sanity check */
	counter = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
	if (counter > NUM_TFD_CHUNKS) {
		IWL_ERR(priv, "Too many chunks: %i\n", counter);
		/* @todo issue fatal error, it is quite serious situation */
		return;
	}

	/* Unmap tx_cmd */
	if (counter)
		pci_unmap_single(dev,
				pci_unmap_addr(&txq->meta[index], mapping),
				pci_unmap_len(&txq->meta[index], len),
				PCI_DMA_TODEVICE);

	/* unmap chunks if any */

	for (i = 1; i < counter; i++) {
		pci_unmap_single(dev, le32_to_cpu(tfd->tbs[i].addr),
			 le32_to_cpu(tfd->tbs[i].len), PCI_DMA_TODEVICE);
		if (txq->txb[txq->q.read_ptr].skb[0]) {
			struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[0];
			if (txq->txb[txq->q.read_ptr].skb[0]) {
				/* Can be called from interrupt context */
				dev_kfree_skb_any(skb);
				txq->txb[txq->q.read_ptr].skb[0] = NULL;
			}
		}
	}
	return ;
}

/**
 * iwl3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD:
 *
*/
void iwl3945_hw_build_tx_cmd_rate(struct iwl_priv *priv,
				  struct iwl_device_cmd *cmd,
				  struct ieee80211_tx_info *info,
				  struct ieee80211_hdr *hdr,
				  int sta_id, int tx_id)
{
	u16 hw_value = ieee80211_get_tx_rate(priv->hw, info)->hw_value;
	u16 rate_index = min(hw_value & 0xffff, IWL_RATE_COUNT_3945);
	u16 rate_mask;
	int rate;
	u8 rts_retry_limit;
	u8 data_retry_limit;
	__le32 tx_flags;
	__le16 fc = hdr->frame_control;
	struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;

	rate = iwl3945_rates[rate_index].plcp;
	tx_flags = tx_cmd->tx_flags;

	/* We need to figure out how to get the sta->supp_rates while
	 * in this running context */
	rate_mask = IWL_RATES_MASK;


	/* Set retry limit on DATA packets and Probe Responses*/
	if (ieee80211_is_probe_resp(fc))
		data_retry_limit = 3;
	else
		data_retry_limit = IWL_DEFAULT_TX_RETRY;
	tx_cmd->data_retry_limit = data_retry_limit;

	if (tx_id >= IWL_CMD_QUEUE_NUM)
		rts_retry_limit = 3;
	else
		rts_retry_limit = 7;

	if (data_retry_limit < rts_retry_limit)
		rts_retry_limit = data_retry_limit;
	tx_cmd->rts_retry_limit = rts_retry_limit;

	if (ieee80211_is_mgmt(fc)) {
		switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
		case cpu_to_le16(IEEE80211_STYPE_AUTH):
		case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
		case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
		case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
			if (tx_flags & TX_CMD_FLG_RTS_MSK) {
				tx_flags &= ~TX_CMD_FLG_RTS_MSK;
				tx_flags |= TX_CMD_FLG_CTS_MSK;
			}
			break;
		default:
			break;
		}
	}

	tx_cmd->rate = rate;
	tx_cmd->tx_flags = tx_flags;

	/* OFDM */
	tx_cmd->supp_rates[0] =
	   ((rate_mask & IWL_OFDM_RATES_MASK) >> IWL_FIRST_OFDM_RATE) & 0xFF;

	/* CCK */
	tx_cmd->supp_rates[1] = (rate_mask & 0xF);

	IWL_DEBUG_RATE(priv, "Tx sta id: %d, rate: %d (plcp), flags: 0x%4X "
		       "cck/ofdm mask: 0x%x/0x%x\n", sta_id,
		       tx_cmd->rate, le32_to_cpu(tx_cmd->tx_flags),
		       tx_cmd->supp_rates[1], tx_cmd->supp_rates[0]);
}

static u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id,
			   u16 tx_rate, u8 flags)
{
	unsigned long flags_spin;
	struct iwl_station_entry *station;

	if (sta_id == IWL_INVALID_STATION)
		return IWL_INVALID_STATION;

	spin_lock_irqsave(&priv->sta_lock, flags_spin);