手机版
你好,游客 登录 注册
背景:
阅读新闻

网络设备驱动 和 DM9000 驱动程序分析

[日期:2012-05-27] 来源:Linux社区  作者:acanoe [字体:大 中 小]

3) 套接字 操作函数:

3.1) 分配

struct sk_buff *alloc_skb(unsigned int len, gfp_t priority);

struct sk_buff *dev_alloc_skb (unsigned int len);

3.2) 释放

  1. void kfree_skb ( struct sk_buff *skb);
  2. void dev_kfree_skb(struct sk_buff *skb); 

void dev_kfree_skb_irq (struct sk_buff  *skb);

void dev_kfree_skb_any (struct  sk_buff  *skb);

3.3) 变更

unsigned char *skb_put (struct sk_buff *skb, unsigned int len);

unsigned  char  *skb_push ( struct sk_buff *skb, unsigned int len);

static inline void skb_reserve (struct sk_buff *skb, int len);

4、 网络设备接口层

网络设备接口层的主要功能是为各种网络设备定义了统一、抽象的数据结构 net_device 结构体。定义在 include/linux/netdevice.h 中

4.1)以下仅仅对 net_device 结构体 的一些关键成员进行标注和说明:

  1. struct net_device {  
  2.   
  3.     /* 
  4.      * This is the first field of the "visible" part of this structure 
  5.      * (i.e. as seen by users in the "Space.c" file).  It is the name 
  6.      * of the interface. 
  7.      */  
  8.     char            name[IFNAMSIZ];          // 全局信息 ,网络设备名称   
  9.   
  10.     struct pm_qos_request_list pm_qos_req;  
  11.   
  12.     /* device name hash chain */  
  13.     struct hlist_node   name_hlist;  
  14.     /* snmp alias */  
  15.     char            *ifalias;  
  16.   
  17.     /* 
  18.      *  I/O specific fields 
  19.      *  FIXME: Merge these and struct ifmap into one 
  20.      */  
  21.     unsigned long       mem_end;    /* shared mem end   */ // 硬件信息, 共享内存起始地址   
  22.     unsigned long       mem_start;  /* shared mem start */ // 共享内存结束地址   
  23.     unsigned long       base_addr;  /* device I/O address   */ // 设备I/O 基地址   
  24.     unsigned int        irq;        /* device IRQ number    */ // 设备中断号   
  25.   
  26.     /* 
  27.      *  Some hardware also needs these fields, but they are not 
  28.      *  part of the usual set specified in Space.c. 
  29.      */  
  30.   
  31.     unsigned char       if_port;    /* Selectable AUI, TP,..*/ // 指定设备使用的端口   
  32.     unsigned char       dma;        /* DMA channel      */  
  33.   
  34.     unsigned long       state;  
  35.   
  36.     struct list_head    dev_list;  
  37.     struct list_head    napi_list;  
  38.     struct list_head    unreg_list;  
  39.   
  40.     /* Net device features */  
  41.     unsigned long       features;  
  42. #define NETIF_F_SG      1   /* Scatter/gather IO. */   
  43. #define NETIF_F_IP_CSUM     2   /* Can checksum TCP/UDP over IPv4. */   
  44. #define NETIF_F_NO_CSUM     4   /* Does not require checksum. F.e. loopack. */   
  45. #define NETIF_F_HW_CSUM     8   /* Can checksum all the packets. */   
  46. #define NETIF_F_IPV6_CSUM   16  /* Can checksum TCP/UDP over IPV6 */   
  47. #define NETIF_F_HIGHDMA     32  /* Can DMA to high memory. */   
  48. #define NETIF_F_FRAGLIST    64  /* Scatter/gather IO. */   
  49. #define NETIF_F_HW_VLAN_TX  128 /* Transmit VLAN hw acceleration */   
  50. #define NETIF_F_HW_VLAN_RX  256 /* Receive VLAN hw acceleration */   
  51. #define NETIF_F_HW_VLAN_FILTER  512 /* Receive filtering on VLAN */   
  52. #define NETIF_F_VLAN_CHALLENGED 1024    /* Device cannot handle VLAN packets */   
  53. #define NETIF_F_GSO     2048    /* Enable software GSO. */   
  54. #define NETIF_F_LLTX        4096    /* LockLess TX - deprecated. Please */   
  55.                     /* do not use LLTX in new drivers */  
  56. #define NETIF_F_NETNS_LOCAL 8192    /* Does not change network namespaces */   
  57. #define NETIF_F_GRO     16384   /* Generic receive offload */   
  58. #define NETIF_F_LRO     32768   /* large receive offload */   
  59.   
  60. /* the GSO_MASK reserves bits 16 through 23 */  
  61. #define NETIF_F_FCOE_CRC    (1 << 24) /* FCoE CRC32 */   
  62. #define NETIF_F_SCTP_CSUM   (1 << 25) /* SCTP checksum offload */   
  63. #define NETIF_F_FCOE_MTU    (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/   
  64. #define NETIF_F_NTUPLE      (1 << 27) /* N-tuple filters supported */   
  65. #define NETIF_F_RXHASH      (1 << 28) /* Receive hashing offload */   
  66.   
  67.     /* Segmentation offload features */  
  68. #define NETIF_F_GSO_SHIFT   16   
  69. #define NETIF_F_GSO_MASK    0x00ff0000   
  70. #define NETIF_F_TSO     (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT)   
  71. #define NETIF_F_UFO     (SKB_GSO_UDP << NETIF_F_GSO_SHIFT)   
  72. #define NETIF_F_GSO_ROBUST  (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)   
  73. #define NETIF_F_TSO_ECN     (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT)   
  74. #define NETIF_F_TSO6        (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)   
  75. #define NETIF_F_FSO     (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)   
  76.   
  77.     /* List of features with software fallbacks. */  
  78. #define NETIF_F_GSO_SOFTWARE    (NETIF_F_TSO | NETIF_F_TSO_ECN | \   
  79.                  NETIF_F_TSO6 | NETIF_F_UFO)  
  80.   
  81.   
  82. #define NETIF_F_GEN_CSUM    (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)   
  83. #define NETIF_F_V4_CSUM     (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)   
  84. #define NETIF_F_V6_CSUM     (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)   
  85. #define NETIF_F_ALL_CSUM    (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)   
  86.   
  87.     /* 
  88.      * If one device supports one of these features, then enable them 
  89.      * for all in netdev_increment_features. 
  90.      */  
  91. #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \   
  92.                  NETIF_F_SG | NETIF_F_HIGHDMA |     \  
  93.                  NETIF_F_FRAGLIST)  
  94.   
  95.     /* Interface index. Unique device identifier    */  
  96.     int         ifindex;  
  97.     int         iflink;  
  98.   
  99.     struct net_device_stats stats;  
  100.   
  101. #ifdef CONFIG_WIRELESS_EXT   
  102.     /* List of functions to handle Wireless Extensions (instead of ioctl). 
  103.      * See <net/iw_handler.h> for details. Jean II */  
  104.     const struct iw_handler_def *   wireless_handlers;  
  105.     /* Instance data managed by the core of Wireless Extensions. */  
  106.     struct iw_public_data * wireless_data;  
  107. #endif   
  108.     /* Management operations */  
  109.     const struct net_device_ops *netdev_ops;  
  110.     const struct ethtool_ops *ethtool_ops;  
  111.   
  112.     /* Hardware header description */  
  113.     const struct header_ops *header_ops;  
  114.   
  115.     unsigned int        flags;  /* interface flags (a la BSD)   */  
  116.     unsigned short      gflags;  
  117.         unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */  
  118.     unsigned short      padded; /* How much padding added by alloc_netdev() */  
  119.   
  120.     unsigned char       operstate; /* RFC2863 operstate */  
  121.     unsigned char       link_mode; /* mapping policy to operstate */  
  122.   
  123.     unsigned int        mtu;    /* interface MTU value      */         // 最大传输单元   
  124.     unsigned short      type;   /* interface hardware type  */         // 接口的硬件类型   
  125.     unsigned short      hard_header_len;    /* hardware hdr length  */ // 硬件报文头长度   
  126.   
  127.     /* extra head- and tailroom the hardware may need, but not in all cases 
  128.      * can this be guaranteed, especially tailroom. Some cases also use 
  129.      * LL_MAX_HEADER instead to allocate the skb. 
  130.      */  
  131.     unsigned short      needed_headroom;  
  132.     unsigned short      needed_tailroom;  
  133.   
  134.     struct net_device   *master; /* Pointer to master device of a group, 
  135.                       * which this device is member of. 
  136.                       */  
  137.   
  138.     /* Interface address info. */  
  139.     unsigned char       perm_addr[MAX_ADDR_LEN]; /* permanent hw address */  
  140.     unsigned char       addr_assign_type; /* hw address assignment type */  
  141.     unsigned char       addr_len;   /* hardware address length  */  
  142.     unsigned short          dev_id;     /* for shared network cards */  
  143.   
  144.     spinlock_t      addr_list_lock;  
  145.     struct netdev_hw_addr_list  uc; /* Unicast mac addresses */  
  146.     struct netdev_hw_addr_list  mc; /* Multicast mac addresses */  
  147.     int         uc_promisc;  
  148.     unsigned int        promiscuity;  
  149.     unsigned int        allmulti;  
  150.   
  151.   
  152.     /* Protocol specific pointers */  
  153.       
  154. #ifdef CONFIG_NET_DSA   
  155.     void            *dsa_ptr;   /* dsa specific data */  
  156. #endif   
  157.     void            *atalk_ptr; /* AppleTalk link   */  
  158.     void            *ip_ptr;    /* IPv4 specific data   */  
  159.     void                    *dn_ptr;        /* DECnet specific data */  
  160.     void                    *ip6_ptr;       /* IPv6 specific data */  
  161.     void            *ec_ptr;    /* Econet specific data */  
  162.     void            *ax25_ptr;  /* AX.25 specific data */  
  163.     struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data, 
  164.                            assign before registering */  
  165.   
  166. /* 
  167.  * Cache line mostly used on receive path (including eth_type_trans()) 
  168.  */  
  169.     unsigned long       last_rx;    /* Time of last Rx  */  
  170.     /* Interface address info used in eth_type_trans() */  
  171.     unsigned char       *dev_addr;  /* hw address, (before bcast 
  172.                            because most packets are 
  173.                            unicast) */  
  174.   
  175.     struct netdev_hw_addr_list  dev_addrs; /* list of device 
  176.                               hw addresses */  
  177.   
  178.     unsigned char       broadcast[MAX_ADDR_LEN];    /* hw bcast add */  // 广播地址   
  179.   
  180. #ifdef CONFIG_RPS   
  181.     struct kset     *queues_kset;  
  182.   
  183.     struct netdev_rx_queue  *_rx;  
  184.   
  185.     /* Number of RX queues allocated at alloc_netdev_mq() time  */  
  186.     unsigned int        num_rx_queues;  
  187. #endif   
  188.   
  189.     struct netdev_queue rx_queue;  
  190.     rx_handler_func_t   *rx_handler;  
  191.     void            *rx_handler_data;  
  192.   
  193.     struct netdev_queue *_tx ____cacheline_aligned_in_smp;  
  194.   
  195.     /* Number of TX queues allocated at alloc_netdev_mq() time  */  
  196.     unsigned int        num_tx_queues;  
  197.   
  198.     /* Number of TX queues currently active in device  */  
  199.     unsigned int        real_num_tx_queues;  
  200.   
  201.     /* root qdisc from userspace point of view */  
  202.     struct Qdisc        *qdisc;  
  203.   
  204.     unsigned long       tx_queue_len;   /* Max frames per queue allowed */  
  205.     spinlock_t      tx_global_lock;  
  206. /* 
  207.  * One part is mostly used on xmit path (device) 
  208.  */  
  209.     /* These may be needed for future network-power-down code. */  
  210.   
  211.     /* 
  212.      * trans_start here is expensive for high speed devices on SMP, 
  213.      * please use netdev_queue->trans_start instead. 
  214.      */  
  215.     unsigned long       trans_start;    /* Time (in jiffies) of last Tx */  
  216.   
  217.     int         watchdog_timeo; /* used by dev_watchdog() */  
  218.     struct timer_list   watchdog_timer;  
  219.   
  220.     /* Number of references to this device */  
  221.     atomic_t        refcnt ____cacheline_aligned_in_smp;  
  222.   
  223.     /* delayed register/unregister */  
  224.     struct list_head    todo_list;  
  225.     /* device index hash chain */  
  226.     struct hlist_node   index_hlist;  
  227.   
  228.     struct list_head    link_watch_list;  
  229.   
  230.     /* register/unregister state machine */  
  231.     enum { NETREG_UNINITIALIZED=0,  
  232.            NETREG_REGISTERED,   /* completed register_netdevice */  
  233.            NETREG_UNREGISTERING,    /* called unregister_netdevice */  
  234.            NETREG_UNREGISTERED, /* completed unregister todo */  
  235.            NETREG_RELEASED,     /* called free_netdev */  
  236.            NETREG_DUMMY,        /* dummy device for NAPI poll */  
  237.     } reg_state:16;  
  238.   
  239.     enum {  
  240.         RTNL_LINK_INITIALIZED,  
  241.         RTNL_LINK_INITIALIZING,  
  242.     } rtnl_link_state:16;  
  243.   
  244.     /* Called from unregister, can be used to call free_netdev */  
  245.     void (*destructor)(struct net_device *dev);  
  246.   
  247. #ifdef CONFIG_NETPOLL   
  248.     struct netpoll_info *npinfo;  
  249. #endif   
  250.   
  251. #ifdef CONFIG_NET_NS   
  252.     /* Network namespace this network device is inside */  
  253.     struct net      *nd_net;  
  254. #endif   
  255.   
  256.     /* mid-layer private */  
  257.     void            *ml_priv;  
  258.   
  259.     /* GARP */  
  260.     struct garp_port    *garp_port;  
  261.   
  262.     /* class/net/name entry */  
  263.     struct device       dev;  
  264.     /* space for optional device, statistics, and wireless sysfs groups */  
  265.     const struct attribute_group *sysfs_groups[4];  
  266.   
  267.     /* rtnetlink link ops */  
  268.     const struct rtnl_link_ops *rtnl_link_ops;  
  269.   
  270.     /* VLAN feature mask */  
  271.     unsigned long vlan_features;  
  272.   
  273.     /* for setting kernel sock attribute on TCP connection setup */  
  274. #define GSO_MAX_SIZE        65536   
  275.     unsigned int        gso_max_size;  
  276.   
  277. #ifdef CONFIG_DCB   
  278.     /* Data Center Bridging netlink ops */  
  279.     const struct dcbnl_rtnl_ops *dcbnl_ops;  
  280. #endif   
  281.   
  282. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)   
  283.     /* max exchange id for FCoE LRO by ddp */  
  284.     unsigned int        fcoe_ddp_xid;  
  285. #endif   
  286.     /* n-tuple filter list attached to this device */  
  287.     struct ethtool_rx_ntuple_list ethtool_ntuple_list;  
  288.   
  289.     /* phy device may attach itself for hardware timestamping */  
  290.     struct phy_device *phydev;  
  291. };  
linux
相关资讯       Linux驱动开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款