aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/net/ethernet/freescale/fec_main.c
blob: 05c1899f6628990e14e167e338fcc435c2ecea52 (plain) (tree)
1
2
3
4
5
6
                                    



                                                             
                                                                     








                                                                            

                                                           

                                                               
                                                
  
                                                        

   


                         
                             




                            



                              


                     
                    


                       


                            

                      
                      
                        
                                  
                       
                      
                      


                            
                          
                         
                                     
                          
                                   
                           
                            
 
                           
 
                
 
                                                        
                                                            
 

                             

                                                                    






                                          
                                         
 

                                                  
                                          


                                    
                                    

                                                                           

                                    
                                                                         
            
                                    
                                                                          

                                                                            
            
                                    
                                                                        
                                                                               

                                                                          
            
                                     
                                                                       
            


                                                                               
                                                                        
                                                                             
                                                                            
            


                                                                               


                                                                            
            

                              
  
                                           
 
                   
                                                  

                                                  
                  
                   
                   
                   





                                                                            
                                                                            
                                                                              
                                                                              
                                                                              



                                    


                                                      
 
                         







                                                                     

                                  


                                        
                                  


                         
                         
 
                                                                             


                                                                      
   
                                                           
                                  
 


                                        
                                      

                                                                  


                                               
  
                                                                               


                                                                       
                                                                                

                                                                              




                                               

                                         
                                   
                                         
                                         
                                         
                                   



                                                  


                                        
 
                                              
 

                           
 

                                   


                                                  
 

                                   





                                                                      
                                                                         
 

                   



                                                                     
                                                                        
 
 



                                                                     
                                                                        

 

                                                         
 
                                                                              

 
                                                                       


                    

                                                                              
 
                                                                    

 
                                               



                                    
                                           
                             

 









                                                               


                                                         


                                       



                                                       
                               
                           
 
            
                                                          
                              
                                                       
                                                         


                                                       
                                               
                                                           
                        
                                      

 




                                                                             









                                                                 

                                       




                                                                         
                       


                                                            
 
                                                         
                                          





                                                 
                           
                      
                        
              
 

                                                          
                                                           

                                                
                                                   

                                                             
                                                                        












                                                                            
                                                            
                                                                        


                                                                             
                                                              

                 
                                                      
 
                                                             
                                                                
                                                             

                                                                         
 
                                                               


                                                               


                                                                         




                                                                               

                                                         



                                                                      
                                                   

         
                   
                  
                          
                                    
                                                           

                                                                                 
         
                                
 
 

                                                                                

                                                         


                                                 
                        



                                 
                         
 
                                                         






                                                                    

                                                         
                                       


                                    
                                     
                          
                       
                                           
                                    
 
                                                  
                            
                                  
 
                                                     
                                                        
                                                     

                                                                 
 
                                                       

                                                     
 


                                                                               




                                                                       
 
                       
                                                                        



                                                                
                                            
                 








                                                                    

                                               
 


                                                                   
 
                                                                           
                                         
                                                                       
 
                                                    
                                                                
 



                                                                     
                                                      
         
 
                                                          
                              
                                    
 



                                                                               
 


                                                                         
                                                     
                                           
 
                                                                                
                                                        
 

                              
                                                                         
                       

              
                          
 
                                        
                                           
 
                 

 
          



                                                                              

                                                         
                                                                             

                                 
                        
 
                                           
                                    
 
                                                     
 
                                                     
                                                     

                                                          
 
                                                       


                                                

                                                                          
                                       
                                    
                                                                       


                                      

                                              
 
                              
                                                    
                                                                


                                                                     
                                                      







                                                            
                                                                      

         
                                           




                 


                                                                      

                                                         
                                                                  
                                                                             




                                 
                                           


                                                     

                                                             
                                                       
                                                     

                                                                  
 
                                                       











                                                                               

                                                

                              
                                                    
                                                                


                                                                     
                                                      

         
                                           



                 


                                                                  



                                                                  
                                          



                               
                                                                        


















                                                                       
                                                             



                                                                             
                                                              
                                                                         
                                                                           






                                                               

                                                                     



                                                                          







                                                                        
                                                           


                              
                                    
 
                              
                          

                                        
                                                   




                                                   












                                                                 


                                       

                



                                              
                            
                                                              
            
                                                              

                           
 
                                                         

                                                   



                            




                                                        

                                       

                            
                       
 


                                                                
                                   
 
                                                         
 

                                                                               
                                                                             
                            
                                                              
                                                                   


                                                 
                                                           
                                                        
 
                                           




                                                  

                                   
 
                                                         
                                                                               
                                                      





                                                                                



                                                                     
                                                           
                                                                   


                                                 
                                                           
                                                        
                                    
         
 
 





                                                           
                                                                

 





                                                         
 

                                                  
                                                                   
                                                                       
 




                                                          
 

                                                  
                                                                   




                                                            
         
 
 








                                                         
                                                         





                                                                     

 



                                                                      
   
           
                                    
 
                                                         
                

                                          
                                      
 



                                                                
                                              




                                                 
 



                                                               




                                                     
 
                                              
                                                  
 

                               
                                   
 

                                   
 
                             
                                              
                               

                                                     

                                    

                                                    
 


                                                         
                          
                                               
                                                 

                                        
                                                           
                                             



                                                 
                                                             
         
      
 



                                                             
                                               

                                                          
 
                                        



                                                                          

                                                                       
                                          
                    
                                           
 
                                     

                                                              
                                                  
                                                                  



                                                   

                     
                                                         
                                 







                                                                    
                                                              
                           

                                                                              
                                                                            

                                                                  


                                                             
                 

         
 
                          


                                                          
                                                    

                                      
                                                                    









                                                                    
                                   
 
                                              
 






                                                  
                                               





                                                        

                                  
 
                    

                                                     

      
                                                                  
                                             
                                     
 


                                                 
                                                  



                                                                



                                           





                                                         
                                                                       
                                                                 
                





                                                                               
                                                                                       

         



                                                                







                                                                
                






                                                                                  
         
                                                         

                                                                             

                                                           
                                                 

                                                          



           



                                                         

                       

                                
                                             

 
                                                           

                                      
                                                                             
                                              
 




                                                                
                                               

                                         
         
                      


           














                                                            
                                                        

                                      
                            
                              
                             

                                       
                          
                             
 
                                






                                                 
 
                                      
                                                   
 

                                                         
                      
                                                              
                                              

                              
                                                             
 
                                            
                                             





                                                                        

                                      
 
                                       
                                                             

                                                                  
                                                
                                                                       
                                                                  
                                                                         
                                                               
                                                                        
                                                                
                                                                   
                                                             
                                                                       
                                                                
                        
                                                 
                                                         

                 

                                                                              
                                                                
                                                                           
 
                                                                                     

                                                         
 


                                                                           
                                            
                                                 
 
                                                                           
                                       
         



                                                                          
                                    
 
                                                                                
                                                           
 
                                                                              
                   
                                                 
                                                                         

                                                                   
                 
         
 
                                                   
                                 

                                                   












                                                                             

 









                                                                                     

                                                                                                                                         








                                                                             
                                                                          










                                                          

                                                               

                                                                   



                                                                  




                       
                                                                         



                                                                   
          
                                                                    
 
                                                         
                                       
                            
                              

                                        

                        
                                 


                                         
                          
                             
                                                               
 

                          
      

                                                
 


                                                                        
                          
 
                                                                            
 



                                           
                                                            
 
                                       
                                          
                                                                             

                                                                            
                                                






                                                                     
                                                                  
                                                               

                                                                               
                         
                                                                       
                                                            


                                                                      

                                                
 
                                                 
                                         
                                                        
                                                
 
                                                             
                                            
 



                                                                       

                                                                               





                                                                             

                                                                        






                                                                            
 


                                                   




                                                       







                                                                  

                                                                      



                                                                              

                                                
 
                                                                           
                                                 

                 
                                                          
 

                                                        
                                                                      



                                                               
                                                                                  



                                                                      
                         
                 
 




                                                                  
 


                                                  

                                                                                  




                                                                                      
                 
 


                                                            
 

                                           
 


                                                                           
                                                                     


                                           




                                                                      
 
                                                     
                                                           
 



                                                                              
                                                   
         
                          

                            
 







                                                                       


                                             
                                                                         




                                                           
         
                            

 





                                                                      
                                        
                                         



                                         
 
                                        
                                         



                                         



                    







                                                         
                                                  
                                                  
                                                 
 
                                                          
                                  
 

                                                         
                                                                     

                                                    
         
 



                                          


                   


                                                                 
                                                         

                 
                                         
 

                          
                            
                                               



                                                                
 
                                                                               
                                                
 
                                                         
                                                                            
                                              
 







                                                              






                                                                 
                                         


                                                            
 
          
                                                    






                                                            
                                                           



          
                                                 

                                        



                                                                           
                                  

         




                                                                         
                                                                            
                                         

                                                                            


                       
                                              
 

                                         
                                                                                

 
                                                                               
 


              
                                                         
 
                                                         
                                                  
                              
 







                                                                          
                                 
                                                  

                                          
 

                                                           
                                          
                 






                                                                 
                                    
                                                 
                                               
                                          
                                                       
                                                 
                                                
                 

                                

                                                 
                                       

                                                 
                                                  

                                          
         
 


                                          
 
                                                                          
 
                                                 
                                             
                                

                                                       

                                       
                    
                           
 
                                           
 



























                                                                                
                             

                                                               


                                                      


                                                                
                                                               

                                 
         
 






                                                            
 
 

                                                                           
 
                                                 
                                             
                                

                                                

                                       
                    
                           

                        
 
                                           
 























                                                                                
                              

                                                               



                                                   


                                                                
                                                                
                                  
         
 
    



                                        
 
 





                                                                    

                                                            
                                   
 
                                   
                                                        
                                                               

                                                                  
                                                    



                                                          
                 



                                                       

                                                         
                
                                                         

                                                        
                                                            


                                                          
                                                    


                 



                                                    


                                                         



                   
                                                      
 
                                                         
                                          


                                           
                                 
 



                                                                  

                                                                       
                                       
                 


                                                                     
                                                                                


                                         
                                                                                

                              
 

                                                                                            
                                                                         






                                                                            

         
                              
                                                              
                                        
         
 
                                              
                                               
                                                 

                                                                           
                          
                                               
      
         
            
                                                
 

                             
 
                                   
 
                 

 
                                                          
 
                                            

                                                             
                                 
                         
                                
 
          
                                                        













                                                                          
                                                                       
                                            





                                                    

         

                                                                      




                                                                          
           
                                                                      
                                             


                                   
                                                                            




















                                                                              
                                                         
 



                                       

         


                                                  

                                                            


                                          
                                                               
                                                      
                          
                
                                          
 

                  
                               
                                                

                                            
                 
 



                                   

 
                                                             
 

                                                 

                                           

 
                                                         
                                                              
 
                                                         
 



                                                                              

 














                                                                                
                                                                                  
                                                             
                                           





























                                                                                
                                           




















                                                                            

                                                  


                                                                    






                                                                  



                                                




























                                                                          

                          














                                                                         
                          

                               











                                                                               

                                                                         



                                        
                                             
         
                                  
                                         
                                       
                                  
                                               
                                         
                                        
         



                 

































































                                                    

                                                                     
                                                                 




                                                        










                                                                              
                                                         























                                                                    
 














                                                                      




                                                                        



                                                                       
                                   
 














                                                                    

                           





















                                                                                 





                                                     





                                                                           
 
                                                    














                                                                           
                                             

                           
                                                    


                                                
                                                                                 



                                                
                                                                                




                                                                 
                                                                               




                                                                 
                                                                               


























                                                           





































                                                                   





































                                                                                    
                                                        
                                                       

                                                        
                                                         
                                                      

                                                        
                    

                                                          
                                                       
                                                             

                                                          
                                                       

                                                       

                                                   

                                                                 
  
 
                                                                             
 
                                                         
                                                 
 
                                 
                               
 


                               





                                                     
 
                                              

 
                                                          
 
                                                         
                       

                             

                                       



                                                  

                                                         



                                                                 
                                                                                
                                                                                    


                                                                  
                                                                   

                 
 

                                                  
                                                         



                                                 
                                           
                 
         
 
 








                                                                     
                                                          
                                                                              




                                                             
                                        
                                                
                                        
















                                                         

                                                                          


                                                           
                                                                         
 
                                                                   
                                                                            





                                                           
         








                                                                     

                                                                          





                                  

 

                                                                       
 
                                                         
                       

                             
                                       
 
                                   

                                                 
                                                                 

                                       
 
                                                         
                                           
                                       
                 
 
                                        
                                                             


                                                                           
                                                                     

                 
                                                           


                                          
                                                   
                                                
                 
 













                                                                       

                                                 

                                                                            
                                       
 

                                                   
 

                                                                           
                                                                     

                 
                                                           


                                          
                                                   
                                                

                 



                                    

 














                                                          
          
                                      
 
                                                         
                
                         
 
                                                   
                    

                           
                                                         

                                              
                                
 










                                                                               


                                                                     
 
                                           
                
                                    
 


                                             
                                                              
                                       

                                        
 





                                                                             


                                              
                                
                                

                                        


                                                            
                 




                                         


                                                    

                                                       


          
                                       
 
                                                         
 
                               
 


                                         
                               
         
 
                                     
 


                                                

                                            
                                         
                                                       


                                                    
                                    
 


                 









                                                                         
                                                           
 
                                                       
 
                                                         
                                  
                              
                           
                                                 
 
                                        


                                                    

                       
 



                                            
                                         








                                                                       
                                                
                                           
                                                          
                                                             
 
                                                             
                                                                    
                   
                                                            
 



                                                      
         


                                                              

 
                                   
          
                                                     
 
                                                         

                                  




                                                                      
 







                                                                          

                                                                      
                                         
                                                                     
                                          
                 

 
                                 

                                                     




                                                                           
                                                       













                                                             
                                                                          












                                                                 
         






                                                                
 
                                                                



                                                               
                                    
                                                 

                                           

                                                               




                 



                                                      
                                                     


                                                      
                                                 


                                                      
                                                   

  







                                                                  

                                                    
   
    
                                                 
 
                                                         
                                 
                          
                    
                       


                                                                      
                
 
                                            
                                                






                            






                                                                           
                                   
 
                                                                              
 
                                                     

                                                                         
                        


                               
                                      
                          

                                                                      
 
                                                       
                                                  








                                                                  
                                                                              


                                                                              


                                                  








                                                                  
                                                                              


                                                                              
         
 
 
                                                                       


                                                  
 
                                                            
                                                                             
 
                                             

                                                          
 
                                               

                                                      

                                                                      
                                                                             

                                                        
 
                                              



                                     

                                           
                          
 



                                                    
 


                 
                
                                                      

                           
                                 
                                         


                                                   
                         
 
                                                                    
                                                                
                                

                         
                                                                



                                           
 




                                                                                
                                                                         
 
                                                          
                                                                               
                                     
                  
                                                                                
                           
         





                                                              
                                                         
 








                                                           
                 

                     
                                                      




                                                             
                 


                      



                                                                              






                                               
                                                              
 
                                                              

                                                          

                                                                             




                                                          

                                                                             





                            












                                                              
          


                                       
                                        
                                  

                                
                                         
                          
                                                              

                      

                         
 

                                                             
                                 
                                                                   
                                                                        

                               




                                         
 




                                                        
                           


                                       
                          
                                                         
                                             
                                                          
      
 


                                                    
                                                           




                                        
                         
                               
 

                                         




                                                                           


                                                          











                                                                     

                                                             
                                                     




                                                                    
                                               

         


                                                       

                                






                                                       

                                                       




                                                                 

                                        





                                                                
                                                                 

                                                       
                                    
                                        
         
 
                                              


                                


                                               


                                               
 
                                                                      

                                                     




                                                                             
                



                                                             
                                    

         

                                                                          
                                            


                                          


                                  
 
                                             
                            
                                            




                                  
                                       
                                                                 
                                                                       

                                                        
                              


                                        
                                                                           
                                                            
                        
                                        

                                  

         
                                         



                                      

                                                          
                                         
                                                  
 



                                     


                                                      


                                                                             
                                              
                                                                



                                               


                 

                                 
           
            
                           

                                                
             
                                          
                                       
                 


                                            
               
                                         
           

                                                 
                              

                 





                          
          



                                                             
                                                   




                                              
 
                                                
                           
                                
                                 

                                                
 

                                                 
                                   
                          
 




                                            


                 
                                                         
 
                                                       
                                                         
 
                    
                                  

                                                               
                                       

                                         
                                          

                                         
                                                 

                                                                       
         

                      
                                                                   

                                                





                                                                               


                 
                                                        
 
                                                       
                                                         
                                                                       
                
                
 
                                                                     



                                                     
 
                    
                                  




                                                      









                                                                         
                                  
                                       
                                          
                                         
                                        
                                        
         
                      
 
                 
 
           


                                                

 




                                                                 
                                            








                                                                
                
 











                                               





                                                                         
 

                                            
                                      
                                      
                                             
          
                                
                            
                                 

  
                                   
 
                                     
                      
// SPDX-License-Identifier: GPL-2.0+
/*
 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
 *
 * Right now, I am very wasteful with the buffers.  I allocate memory
 * pages and then divide them into 2K frame buffers.  This way I know I
 * have buffers large enough to hold one frame within one buffer descriptor.
 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
 * will be much more memory efficient and will easily handle lots of
 * small packets.
 *
 * Much better multiple PHY support by Magnus Damm.
 * Copyright (c) 2000 Ericsson Radio Systems AB.
 *
 * Support for FEC controller of ColdFire processors.
 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
 *
 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
 * Copyright (c) 2004-2006 Macq Electronique SA.
 *
 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/pm_runtime.h>
#include <linux/ptrace.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <net/ip.h>
#include <net/tso.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/clk.h>
#include <linux/crc32.h>
#include <linux/platform_device.h>
#include <linux/mdio.h>
#include <linux/phy.h>
#include <linux/fec.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/regulator/consumer.h>
#include <linux/if_vlan.h>
#include <linux/pinctrl/consumer.h>
#include <linux/prefetch.h>
#include <soc/imx/cpuidle.h>

#include <asm/cacheflush.h>

#include "fec.h"

static void set_multicast_list(struct net_device *ndev);
static void fec_enet_itr_coal_init(struct net_device *ndev);

#define DRIVER_NAME	"fec"

#define FEC_ENET_GET_QUQUE(_x) ((_x == 0) ? 1 : ((_x == 1) ? 2 : 0))

/* Pause frame feild and FIFO threshold */
#define FEC_ENET_FCE	(1 << 5)
#define FEC_ENET_RSEM_V	0x84
#define FEC_ENET_RSFL_V	16
#define FEC_ENET_RAEM_V	0x8
#define FEC_ENET_RAFL_V	0x8
#define FEC_ENET_OPD_V	0xFFF0
#define FEC_MDIO_PM_TIMEOUT  100 /* ms */

static struct platform_device_id fec_devtype[] = {
	{
		/* keep it for coldfire */
		.name = DRIVER_NAME,
		.driver_data = 0,
	}, {
		.name = "imx25-fec",
		.driver_data = FEC_QUIRK_USE_GASKET | FEC_QUIRK_MIB_CLEAR |
			       FEC_QUIRK_HAS_FRREG,
	}, {
		.name = "imx27-fec",
		.driver_data = FEC_QUIRK_MIB_CLEAR | FEC_QUIRK_HAS_FRREG,
	}, {
		.name = "imx28-fec",
		.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME |
				FEC_QUIRK_SINGLE_MDIO | FEC_QUIRK_HAS_RACC |
				FEC_QUIRK_HAS_FRREG,
	}, {
		.name = "imx6q-fec",
		.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
				FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
				FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR006358 |
				FEC_QUIRK_HAS_RACC,
	}, {
		.name = "mvf600-fec",
		.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_RACC,
	}, {
		.name = "imx6sx-fec",
		.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
				FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
				FEC_QUIRK_HAS_VLAN | FEC_QUIRK_HAS_AVB |
				FEC_QUIRK_ERR007885 | FEC_QUIRK_BUG_CAPTURE |
				FEC_QUIRK_HAS_RACC | FEC_QUIRK_HAS_COALESCE,
	}, {
		.name = "imx6ul-fec",
		.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
				FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
				FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR007885 |
				FEC_QUIRK_BUG_CAPTURE | FEC_QUIRK_HAS_RACC |
				FEC_QUIRK_HAS_COALESCE,
	}, {
		/* sentinel */
	}
};
MODULE_DEVICE_TABLE(platform, fec_devtype);

enum imx_fec_type {
	IMX25_FEC = 1,	/* runs on i.mx25/50/53 */
	IMX27_FEC,	/* runs on i.mx27/35/51 */
	IMX28_FEC,
	IMX6Q_FEC,
	MVF600_FEC,
	IMX6SX_FEC,
	IMX6UL_FEC,
};

static const struct of_device_id fec_dt_ids[] = {
	{ .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], },
	{ .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
	{ .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
	{ .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], },
	{ .compatible = "fsl,mvf600-fec", .data = &fec_devtype[MVF600_FEC], },
	{ .compatible = "fsl,imx6sx-fec", .data = &fec_devtype[IMX6SX_FEC], },
	{ .compatible = "fsl,imx6ul-fec", .data = &fec_devtype[IMX6UL_FEC], },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, fec_dt_ids);

static unsigned char macaddr[ETH_ALEN];
module_param_array(macaddr, byte, NULL, 0);
MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");

#if defined(CONFIG_M5272)
/*
 * Some hardware gets it MAC address out of local flash memory.
 * if this is non-zero then assume it is the address to get MAC from.
 */
#if defined(CONFIG_NETtel)
#define	FEC_FLASHMAC	0xf0006006
#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
#define	FEC_FLASHMAC	0xf0006000
#elif defined(CONFIG_CANCam)
#define	FEC_FLASHMAC	0xf0020000
#elif defined (CONFIG_M5272C3)
#define	FEC_FLASHMAC	(0xffe04000 + 4)
#elif defined(CONFIG_MOD5272)
#define FEC_FLASHMAC	0xffc0406b
#else
#define	FEC_FLASHMAC	0
#endif
#endif /* CONFIG_M5272 */

/* The FEC stores dest/src/type/vlan, data, and checksum for receive packets.
 *
 * 2048 byte skbufs are allocated. However, alignment requirements
 * varies between FEC variants. Worst case is 64, so round down by 64.
 */
#define PKT_MAXBUF_SIZE		(round_down(2048 - 64, 64))
#define PKT_MINBUF_SIZE		64

/* FEC receive acceleration */
#define FEC_RACC_IPDIS		(1 << 1)
#define FEC_RACC_PRODIS		(1 << 2)
#define FEC_RACC_SHIFT16	BIT(7)
#define FEC_RACC_OPTIONS	(FEC_RACC_IPDIS | FEC_RACC_PRODIS)

/* MIB Control Register */
#define FEC_MIB_CTRLSTAT_DISABLE	BIT(31)

/*
 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
 * size bits. Other FEC hardware does not, so we need to take that into
 * account when setting it.
 */
#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
    defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM) || \
    defined(CONFIG_ARM64)
#define	OPT_FRAME_SIZE	(PKT_MAXBUF_SIZE << 16)
#else
#define	OPT_FRAME_SIZE	0
#endif

/* FEC MII MMFR bits definition */
#define FEC_MMFR_ST		(1 << 30)
#define FEC_MMFR_ST_C45		(0)
#define FEC_MMFR_OP_READ	(2 << 28)
#define FEC_MMFR_OP_READ_C45	(3 << 28)
#define FEC_MMFR_OP_WRITE	(1 << 28)
#define FEC_MMFR_OP_ADDR_WRITE	(0)
#define FEC_MMFR_PA(v)		((v & 0x1f) << 23)
#define FEC_MMFR_RA(v)		((v & 0x1f) << 18)
#define FEC_MMFR_TA		(2 << 16)
#define FEC_MMFR_DATA(v)	(v & 0xffff)
/* FEC ECR bits definition */
#define FEC_ECR_MAGICEN		(1 << 2)
#define FEC_ECR_SLEEP		(1 << 3)

#define FEC_MII_TIMEOUT		30000 /* us */

/* Transmitter timeout */
#define TX_TIMEOUT (2 * HZ)

#define FEC_PAUSE_FLAG_AUTONEG	0x1
#define FEC_PAUSE_FLAG_ENABLE	0x2
#define FEC_WOL_HAS_MAGIC_PACKET	(0x1 << 0)
#define FEC_WOL_FLAG_ENABLE		(0x1 << 1)
#define FEC_WOL_FLAG_SLEEP_ON		(0x1 << 2)

#define COPYBREAK_DEFAULT	256

/* Max number of allowed TCP segments for software TSO */
#define FEC_MAX_TSO_SEGS	100
#define FEC_MAX_SKB_DESCS	(FEC_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)

#define IS_TSO_HEADER(txq, addr) \
	((addr >= txq->tso_hdrs_dma) && \
	(addr < txq->tso_hdrs_dma + txq->bd.ring_size * TSO_HEADER_SIZE))

static int mii_cnt;

static struct bufdesc *fec_enet_get_nextdesc(struct bufdesc *bdp,
					     struct bufdesc_prop *bd)
{
	return (bdp >= bd->last) ? bd->base
			: (struct bufdesc *)(((void *)bdp) + bd->dsize);
}

static struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp,
					     struct bufdesc_prop *bd)
{
	return (bdp <= bd->base) ? bd->last
			: (struct bufdesc *)(((void *)bdp) - bd->dsize);
}

static int fec_enet_get_bd_index(struct bufdesc *bdp,
				 struct bufdesc_prop *bd)
{
	return ((const char *)bdp - (const char *)bd->base) >> bd->dsize_log2;
}

static int fec_enet_get_free_txdesc_num(struct fec_enet_priv_tx_q *txq)
{
	int entries;

	entries = (((const char *)txq->dirty_tx -
			(const char *)txq->bd.cur) >> txq->bd.dsize_log2) - 1;

	return entries >= 0 ? entries : entries + txq->bd.ring_size;
}

static void swap_buffer(void *bufaddr, int len)
{
	int i;
	unsigned int *buf = bufaddr;

	for (i = 0; i < len; i += 4, buf++)
		swab32s(buf);
}

static void swap_buffer2(void *dst_buf, void *src_buf, int len)
{
	int i;
	unsigned int *src = src_buf;
	unsigned int *dst = dst_buf;

	for (i = 0; i