aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/failed-syscalls-by-pid.py
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2013-04-23 14:26:15 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-04-23 14:26:15 -0400
commit5cc50fc858a5ab37dc2744d72d7ffed96f23afd8 (patch)
treef39ccc97c9945f08f82081f5330cdf44dec7cea2 /tools/perf/scripts/python/failed-syscalls-by-pid.py
parent5d4dcae70628bf00ed11c09837a6fb6d4d920bb4 (diff)
parentd74bf3fa8e85f8f80738d93396d8aab3871eae1e (diff)
Merge remote-tracking branch 'asoc/topic/ux500' into asoc-next
Diffstat (limited to 'tools/perf/scripts/python/failed-syscalls-by-pid.py')
0 files changed, 0 insertions, 0 deletions
93152656848901f9'/>
path: root/drivers/net/virtio_net.c
blob: b0a85d0387962b6ce2394637f9ae6dbbac5f6684 (plain) (tree)
1
                                 



















                                                                            
                          



                              
                          
                       
 


                                     



                               
                           
                                                            
                           
 
                                        
 
                     
                                   
                                          

                                
                            



                                                              


                                                     


                                                                              


                                                                

                                             



                                                     

  




                                                     
                            

  









                                                                             
                                                                    
 
                                              

 




                                                                  
 
                         
 



                                                                          

 



                                                                       
                
                                                      


                                                                   



                                         
                                                
 
                                                  
 

                                          
 
                                                               
                                  

 

                                                                
 












                                                          
 






                                                                       
 
                               
 



                                                                          
 
                                
 






                                                        
 
                                
 

                       
 



                                            
 

                       
 




                                                      
 

                                     
 

                   
 













                                                                          
 





                                                                        
                 















                                                                            
 








                                                                       
 







                                                         
                                                

                                             
                 




                                                         
         
 
                                
                                       


                                        
                                                           
                                          


                                                                
                                       

         



                                                                
                                                           
                                   
                                                                      


                                                                  








                                                                             
                                                                     


                                       
                                                               

                                                                     
                                                              
















                                                                           


                           
                                                                

                            
                                 
                
 


                                                                 
 
                                     
 
                                
                                                          
 
                                                      
 
                                                                      

                                   
 

                   
 

                                                              



                                         
                                                               





                                                     
                 
                                                                          
 



                                                             
 






                                     


                                                                              
 
                                                       
                                                
                                                                  


                                             
                                                                                




                                              

 
                                                                    
 
                          
                
 


                                   
 
                                                              
 
                                                                       

                                     
 

                   
 




                                                             
 






                                                             
 
                              
                                   

                              
                          
                          


                                        
                    

 
                                                

                                                  
                                                                       
                                            
                                             
                                           
         

 






                                                                  
                                                     







                                                                     


                                                                                
                  



                                       


                                                                         


                           



                                                              
 

                                
                                    

                                                                     
                                                             
                                              
                                   
                 




                        
                                                               

                            
                                      


                                                                         
                                                    
                                            
                                                     
                                       
         
                       

 
                                                                 
 
                                                     
                                                                         
 
                                                                
 
                                                 


                                                                          
                

                                                               


                              

                                                              
                                                              
                                                                     
                                                                   
                                                                     
                                                                 
                                                                   

                              
                                                                
                                                                    
                

                                                            

         
                                  


                                              
                                                                    
            
                                                                  
 


                                                                        

 
                                                                          

                                                   
                     



                                                                       
 
                             











                                                                     
         
                                       
 















                                                                          
         

                            

 









                                                                   


                                                                                



                 








                                                   



                                                   
                               


                                                                              

                                                                            
                                            
                                                     
                                           
         


                 







                                                                           
                                                                   


                                        
              
 


                                                                     









                                                

                                                              

                                                               
                                                                       












                                                                             


                                                   


                                


                 










                                                                 


                                                       
                                 
                             
                                             
                                  
                     
                     

                  




                                                                           

                                                      
 
                                                   


                                                             
                                            


                                                                       
                                                     


                                                              
                                            

                                                                        
 
                                        
                                        
                                                        


                                                                   




                                                                          

                             
                                                                         
                                     
              
                                        
                                                                    

                                    
                                                                      

                                                   
                                                        
 
                                     
              

                                                                    

                                    
                                                                      






                                                                         

 
                                                                    



                                                   
                                            





                                                                        
                                                                     



                                                   
                                            





                                                                         
                                                       

                                           
                                      
                                      
                                        

  










                                                                  




                                                     
                                                       
                                                   
                                                  

                                                         




                                               


































                                                                         


                                                    

                                



                                                                           






                                                                        
                                          
                                        
                                                   


                                                 
                                                                  

                                                                             
                                                                        


                                                                  
                                                                    
                                                                            
                                                     
                                                                            
                                                      
                                                                           
                                                         
                                                                           
                                                     


                                                                           
                                                         


                                                                          
              



                                                    
                                                                  

                        
                        
                         
                                                    

                                                        
 
                                                                             


                                                                

                                       


                                                             





                                                                          
                          
 

                         
 
                                                                 
                                 


                                                                         

         


                                                                    
                              
         

                                                       
                                      






                                                                    

                                          
                              
 
                                                               

                 

                               
                                              

                                    




                         



                                                     





                                                                  











                                                                  
                                                                
 
                                             
 


                                      
 
                                   
                                              

                                                                
                             
 

                                        


                                                            
                             






                                             
                                  

                                                   
                                                                              
                                                                                
                                                       
                                                                          
                                                     

  
                                                 

                                                   




                                                    
                                                 



                            
                                                          



                             
                                                     






                                            
/* A network driver using virtio.
 *
 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
//#define DEBUG
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/module.h>
#include <linux/virtio.h>
#include <linux/virtio_net.h>
#include <linux/scatterlist.h>
#include <linux/if_vlan.h>
#include <linux/slab.h>

static int napi_weight = 128;
module_param(napi_weight, int, 0444);

static int csum = 1, gso = 1;
module_param(csum, bool, 0444);
module_param(gso, bool, 0444);

/* FIXME: MTU in config. */
#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN	128

#define VIRTNET_SEND_COMMAND_SG_MAX    2

struct virtnet_info {
	struct virtio_device *vdev;
	struct virtqueue *rvq, *svq, *cvq;
	struct net_device *dev;
	struct napi_struct napi;
	unsigned int status;

	/* Number of input buffers, and max we've ever had. */
	unsigned int num, max;

	/* I like... big packets and I cannot lie! */
	bool big_packets;

	/* Host will merge rx buffers for big packets (shake it! shake it!) */
	bool mergeable_rx_bufs;

	/* Work struct for refilling if we run low on memory. */
	struct delayed_work refill;

	/* Chain pages by the private ptr. */
	struct page *pages;

	/* fragments + linear part + virtio header */
	struct scatterlist rx_sg[MAX_SKB_FRAGS + 2];
	struct scatterlist tx_sg[MAX_SKB_FRAGS + 2];
};

struct skb_vnet_hdr {
	union {
		struct virtio_net_hdr hdr;
		struct virtio_net_hdr_mrg_rxbuf mhdr;
	};
	unsigned int num_sg;
};

struct padded_vnet_hdr {
	struct virtio_net_hdr hdr;
	/*
	 * virtio_net_hdr should be in a separated sg buffer because of a
	 * QEMU bug, and data sg buffer shares same page with this header sg.
	 * This padding makes next sg 16 byte aligned after virtio_net_hdr.
	 */
	char padding[6];
};

static inline struct skb_vnet_hdr *skb_vnet_hdr(struct sk_buff *skb)
{
	return (struct skb_vnet_hdr *)skb->cb;
}

/*
 * private is used to chain pages for big packets, put the whole
 * most recent used list in the beginning for reuse
 */
static void give_pages(struct virtnet_info *vi, struct page *page)
{
	struct page *end;

	/* Find end of list, sew whole thing into vi->pages. */
	for (end = page; end->private; end = (struct page *)end->private);
	end->private = (unsigned long)vi->pages;
	vi->pages = page;
}

static struct page *get_a_page(struct virtnet_info *vi, gfp_t gfp_mask)
{
	struct page *p = vi->pages;

	if (p) {
		vi->pages = (struct page *)p->private;
		/* clear private here, it is used to chain pages */
		p->private = 0;
	} else
		p = alloc_page(gfp_mask);
	return p;
}

static void skb_xmit_done(struct virtqueue *svq)
{
	struct virtnet_info *vi = svq->vdev->priv;

	/* Suppress further interrupts. */
	svq->vq_ops->disable_cb(svq);

	/* We were probably waiting for more output buffers. */
	netif_wake_queue(vi->dev);
}

static void set_skb_frag(struct sk_buff *skb, struct page *page,
			 unsigned int offset, unsigned int *len)
{
	int i = skb_shinfo(skb)->nr_frags;
	skb_frag_t *f;

	f = &skb_shinfo(skb)->frags[i];
	f->size = min((unsigned)PAGE_SIZE - offset, *len);
	f->page_offset = offset;
	f->page = page;

	skb->data_len += f->size;
	skb->len += f->size;
	skb_shinfo(skb)->nr_frags++;
	*len -= f->size;
}

static struct sk_buff *page_to_skb(struct virtnet_info *vi,
				   struct page *page, unsigned int len)
{
	struct sk_buff *skb;
	struct skb_vnet_hdr *hdr;
	unsigned int copy, hdr_len, offset;
	char *p;

	p = page_address(page);

	/* copy small packet so we can reuse these pages for small data */
	skb = netdev_alloc_skb_ip_align(vi->dev, GOOD_COPY_LEN);
	if (unlikely(!skb))
		return NULL;

	hdr = skb_vnet_hdr(skb);

	if (vi->mergeable_rx_bufs) {
		hdr_len = sizeof hdr->mhdr;
		offset = hdr_len;
	} else {
		hdr_len = sizeof hdr->hdr;
		offset = sizeof(struct padded_vnet_hdr);
	}

	memcpy(hdr, p, hdr_len);

	len -= hdr_len;
	p += offset;

	copy = len;
	if (copy > skb_tailroom(skb))
		copy = skb_tailroom(skb);
	memcpy(skb_put(skb, copy), p, copy);

	len -= copy;
	offset += copy;

	while (len) {
		set_skb_frag(skb, page, offset, &len);
		page = (struct page *)page->private;
		offset = 0;
	}

	if (page)
		give_pages(vi, page);

	return skb;
}

static int receive_mergeable(struct virtnet_info *vi, struct sk_buff *skb)
{
	struct skb_vnet_hdr *hdr = skb_vnet_hdr(skb);
	struct page *page;
	int num_buf, i, len;

	num_buf = hdr->mhdr.num_buffers;
	while (--num_buf) {
		i = skb_shinfo(skb)->nr_frags;
		if (i >= MAX_SKB_FRAGS) {
			pr_debug("%s: packet too long\n", skb->dev->name);
			skb->dev->stats.rx_length_errors++;
			return -EINVAL;
		}

		page = vi->rvq->vq_ops->get_buf(vi->rvq, &len);
		if (!page) {
			pr_debug("%s: rx error: %d buffers missing\n",
				 skb->dev->name, hdr->mhdr.num_buffers);
			skb->dev->stats.rx_length_errors++;
			return -EINVAL;
		}
		if (len > PAGE_SIZE)
			len = PAGE_SIZE;

		set_skb_frag(skb, page, 0, &len);