JJJ:net_device分配:alloc_netdev

4099 #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
4100     alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)



9135 /**
9136  * alloc_netdev_mqs - allocate network device
9137  * @sizeof_priv: size of private data to allocate space for
9138  * @name: device name format string
9139  * @name_assign_type: origin of device name
9140  * @setup: callback to initialize device
9141  * @txqs: the number of TX subqueues to allocate
9142  * @rxqs: the number of RX subqueues to allocate
9143  *
9144  * Allocates a struct net_device with private data area for driver use
9145  * and performs basic initialization.  Also allocates subqueue structs
9146  * for each queue on the device.
9147  */
9148 struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
9149         unsigned char name_assign_type,
9150         void (*setup)(struct net_device *),
9151         unsigned int txqs, unsigned int rxqs)
9152 {
9153     struct net_device *dev;
9154     unsigned int alloc_size;
9155     struct net_device *p;
9156
9157     BUG_ON(strlen(name) >= sizeof(dev->name));
9158
9159     if (txqs < 1) {
9160         pr_err("alloc_netdev: Unable to allocate device with zero queues\n");
9161         return NULL;
9162     }
9163
9164     if (rxqs < 1) {
9165         pr_err("alloc_netdev: Unable to allocate device with zero RX queues\n");
9166         return NULL;
9167     }
9168
9169     alloc_size = sizeof(struct net_device);
9170     if (sizeof_priv) {
9171         /* ensure 32-byte alignment of private area */
9172         alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
9173         alloc_size += sizeof_priv;
9174     }
9175     /* ensure 32-byte alignment of whole construct */
9176     alloc_size += NETDEV_ALIGN - 1;
9177
9178     p = kvzalloc(alloc_size, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
9179     if (!p)
9180         return NULL;
9181
9182     dev = PTR_ALIGN(p, NETDEV_ALIGN);
9183     dev->padded = (char *)dev - (char *)p; // 注释:unsigned short类型,为了字节对齐而指针前移的位移量
9184
9185     dev->pcpu_refcnt = alloc_percpu(int);
9186     if (!dev->pcpu_refcnt)
9187         goto free_dev;
9188
9189     if (dev_addr_init(dev))
9190         goto free_pcpu;
9191
9192     dev_mc_init(dev);
9193     dev_uc_init(dev);
9194
9195     dev_net_set(dev, &init_net);
9196
9197     dev->gso_max_size = GSO_MAX_SIZE;
9198     dev->gso_max_segs = GSO_MAX_SEGS;
9199     dev->upper_level = 1;
9200     dev->lower_level = 1;
9201
9202     INIT_LIST_HEAD(&dev->napi_list);
9203     INIT_LIST_HEAD(&dev->unreg_list);
9204     INIT_LIST_HEAD(&dev->close_list);
9205     INIT_LIST_HEAD(&dev->link_watch_list);
9206     INIT_LIST_HEAD(&dev->adj_list.upper);
9207     INIT_LIST_HEAD(&dev->adj_list.lower);
9208     INIT_LIST_HEAD(&dev->ptype_all);
9209     INIT_LIST_HEAD(&dev->ptype_specific);
9210 #ifdef CONFIG_NET_SCHED
9211     hash_init(dev->qdisc_hash);
9212 #endif
9213     dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM; 
	// IFF_XMIT_DST_RELEASE:它指示内核在数据包发送完成后可以自动释放skb(socket缓冲区)中存储的目的地址引用。
	// 这意味着网络设备驱动在完成传输后不必手动管理skb目的地引用的释放操作。
	// IFF_XMIT_DST_RELEASE_PERM:永久性地启用skb目的地址引用在发送后自动释放的功能。
	// 所有通过它的数据包在发送后都会自动清理其skb中的dst_entry。IFF_XMIT_DST_RELEASE not taking into account underlying stacked devices

9214     setup(dev);
9215
9216     if (!dev->tx_queue_len) {
9217         dev->priv_flags |= IFF_NO_QUEUE;
9218         dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
9219     }
9220
9221     dev->num_tx_queues = txqs; 		此处为1
9222     dev->real_num_tx_queues = txqs; 	此处为1
9223     if (netif_alloc_netdev_queues(dev)) 初始化tx queue
9224         goto free_all;
9225
9226     dev->num_rx_queues = rxqs;
9227     dev->real_num_rx_queues = rxqs;
9228     if (netif_alloc_rx_queues(dev))   初始化rx queue
9229         goto free_all;
9230
9231     strcpy(dev->name, name);
9232     dev->name_assign_type = name_assign_type;
9233     dev->group = INIT_NETDEV_GROUP;
9234     if (!dev->ethtool_ops)
9235         dev->ethtool_ops = &default_ethtool_ops;
9236
9237     nf_hook_ingress_init(dev);
9238
9239     return dev;
9240
9241 free_all:
9242     free_netdev(dev);
9243     return NULL;
9244
9245 free_pcpu:
9246     free_percpu(dev->pcpu_refcnt);
9247 free_dev:
9248     netdev_freemem(dev);
9249     return NULL;
9250 }


只初始化了tx queue
8611 static int netif_alloc_netdev_queues(struct net_device *dev)
8612 {
8613     unsigned int count = dev->num_tx_queues;
8614     struct netdev_queue *tx;
8615     size_t sz = count * sizeof(*tx);
8616
8617     if (count < 1 || count > 0xffff)
8618         return -EINVAL;
8619
8620     tx = kvzalloc(sz, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
8621     if (!tx)
8622         return -ENOMEM;
8623
8624     dev->_tx = tx;
8625
8626     netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL); 依次执行netdev_init_one_queue
8627     spin_lock_init(&dev->tx_global_lock);
8628
8629     return 0;
8630 }



2145 static inline void netdev_for_each_tx_queue(struct net_device *dev,
2146                         void (*f)(struct net_device *,
2147                               struct netdev_queue *,
2148                               void *),
2149                         void *arg)
2150 {
2151     unsigned int i;
2152
2153     for (i = 0; i < dev->num_tx_queues; i++)
2154         f(dev, &dev->_tx[i], arg);
2155 }


没啥好说的
8592 static void netdev_init_one_queue(struct net_device *dev,
8593                   struct netdev_queue *queue, void *_unused)
8594 {
8595     /* Initialize queue lock */
8596     spin_lock_init(&queue->_xmit_lock);
8597     netdev_set_xmit_lockdep_class(&queue->_xmit_lock, dev->type);
8598     queue->xmit_lock_owner = -1;
8599     netdev_queue_numa_node_write(queue, NUMA_NO_NODE);
8600     queue->dev = dev;
8601 #ifdef CONFIG_BQL
8602     dql_init(&queue->dql, HZ);
8603 #endif
8604 }


初始化rx queue,xdp相关的以后再看吧
8544 static int netif_alloc_rx_queues(struct net_device *dev)
8545 {
8546     unsigned int i, count = dev->num_rx_queues;
8547     struct netdev_rx_queue *rx;
8548     size_t sz = count * sizeof(*rx);
8549     int err = 0;
8550
8551     BUG_ON(count < 1);
8552
8553     rx = kvzalloc(sz, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
8554     if (!rx)
8555         return -ENOMEM;
8556
8557     dev->_rx = rx;
8558
8559     for (i = 0; i < count; i++) {
8560         rx[i].dev = dev;
8561
8562         /* XDP RX-queue setup */
8563         err = xdp_rxq_info_reg(&rx[i].xdp_rxq, dev, i);
8564         if (err < 0)
8565             goto err_rxq_info;
8566     }
8567     return 0;
8568
8569 err_rxq_info:
8570     /* Rollback successful reg's and free other resources */
8571     while (i--)
8572         xdp_rxq_info_unreg(&rx[i].xdp_rxq);
8573     kvfree(dev->_rx);
8574     dev->_rx = NULL;
8575     return err;
8576 }
8577




352 /**
353  *  dev_addr_init - Init device address list
354  *  @dev: device
355  *
356  *  Init device address list and create the first element,
357  *  used by ->dev_addr.
358  *
359  *  The caller must hold the rtnl_mutex.
360  */
361 int dev_addr_init(struct net_device *dev)
362 {
363     unsigned char addr[MAX_ADDR_LEN]; //32
364     struct netdev_hw_addr *ha;
365     int err;
366
367     /* rtnl_mutex must be held here */
368
369     __hw_addr_init(&dev->dev_addrs);
370     memset(addr, 0, sizeof(addr));
371     err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr),
372                 NETDEV_HW_ADDR_T_LAN);
373     if (!err) {
374         /*
375          * Get the first (previously created) address from the list
376          * and set dev_addr pointer to this location.
377          */
378         ha = list_first_entry(&dev->dev_addrs.list,
379                       struct netdev_hw_addr, list);
380         dev->dev_addr = ha->addr;
381     }
382     return err;
383 }


324 void __hw_addr_init(struct netdev_hw_addr_list *list)
325 {
326     INIT_LIST_HEAD(&list->list);
327     list->count = 0;
328 }


 84 static int __hw_addr_add(struct netdev_hw_addr_list *list,
 85              const unsigned char *addr, int addr_len,
 86              unsigned char addr_type)
 87 {
 88     return __hw_addr_add_ex(list, addr, addr_len, addr_type, false, false,
 89                 0);
 90 }


 49 static int __hw_addr_add_ex(struct netdev_hw_addr_list *list,
 50                 const unsigned char *addr, int addr_len,
 51                 unsigned char addr_type, bool global, bool sync,
 52                 int sync_count)
 53 {
 54     struct netdev_hw_addr *ha;
 55
 56     if (addr_len > MAX_ADDR_LEN)
 57         return -EINVAL;
 58
 59     list_for_each_entry(ha, &list->list, list) {
 60         if (ha->type == addr_type &&
 61             !memcmp(ha->addr, addr, addr_len)) {
 62             if (global) {
 63                 /* check if addr is already used as global */
 64                 if (ha->global_use)
 65                     return 0;
 66                 else
 67                     ha->global_use = true;
 68             }
 69             if (sync) {
 70                 if (ha->synced && sync_count)
 71                     return -EEXIST;
 72                 else
 73                     ha->synced++;
 74             }
 75             ha->refcount++;
 76             return 0;
 77         }
 78     }
 79
 80     return __hw_addr_create_ex(list, addr, addr_len, addr_type, global,
 81                    sync);
 82 }



新建一个struct netdev_hw_addr对象并把它链入到dev->dev_addrs
 19 /*
 20  * General list handling functions
 21  */
 22
 23 static int __hw_addr_create_ex(struct netdev_hw_addr_list *list,
 24                    const unsigned char *addr, int addr_len,
 25                    unsigned char addr_type, bool global,
 26                    bool sync)
 27 {
 28     struct netdev_hw_addr *ha;
 29     int alloc_size;
 30
 31     alloc_size = sizeof(*ha);
 32     if (alloc_size < L1_CACHE_BYTES)
 33         alloc_size = L1_CACHE_BYTES;
 34     ha = kmalloc(alloc_size, GFP_ATOMIC);
 35     if (!ha)
 36         return -ENOMEM;
 37     memcpy(ha->addr, addr, addr_len);
 38     ha->type = addr_type;
 39     ha->refcount = 1;
 40     ha->global_use = global;
 41     ha->synced = sync ? 1 : 0;
 42     ha->sync_cnt = 0;
 43     list_add_tail_rcu(&ha->list, &list->list);
 44     list->count++;
 45
 46     return 0;
 47 }




====


 210 #define NETDEV_HW_ADDR_T_LAN        1
 211 #define NETDEV_HW_ADDR_T_SAN        2
 212 #define NETDEV_HW_ADDR_T_SLAVE      3
 213 #define NETDEV_HW_ADDR_T_UNICAST    4
 214 #define NETDEV_HW_ADDR_T_MULTICAST  5


NETDEV_HW_ADDR_T_LAN:通常指局域网(Local Area Network)硬件地址,也就是常说的MAC地址,
						它是用来唯一标识网络接口卡在局域网内的物理地址。

NETDEV_HW_ADDR_T_SAN:存储区域网络(Storage Area Network)硬件地址,可能是指用于SAN环境中的特定类型的硬件地址,
					例如某些专有存储网络协议中用于识别存储设备的地址。

NETDEV_HW_ADDR_T_SLAVE:这个类型可能指的是某种从属设备或通道的硬件地址,
						例如在网络聚合(Link Aggregation Control Protocol, LACP)配置中,
						一个从属端口可能会有一个相应的从属硬件地址。

NETDEV_HW_ADDR_T_UNICAST:单播硬件地址,即上述提到的常规意义上的MAC地址,它被设计用来一对一通信,
							确保帧只发送给具有匹配MAC地址的目标设备。

NETDEV_HW_ADDR_T_MULTICAST:组播硬件地址,这种地址允许一个源设备向一组具有相同组播地址的多个目标设备同时发送数据包。


 206 struct netdev_hw_addr {
 207     struct list_head    list;
 208     unsigned char       addr[MAX_ADDR_LEN];
 209     unsigned char       type;
 210 #define NETDEV_HW_ADDR_T_LAN        1
 211 #define NETDEV_HW_ADDR_T_SAN        2
 212 #define NETDEV_HW_ADDR_T_SLAVE      3
 213 #define NETDEV_HW_ADDR_T_UNICAST    4
 214 #define NETDEV_HW_ADDR_T_MULTICAST  5
 215     bool            global_use;
 216     int         sync_cnt;
 217     int         refcount;
 218     int         synced;
 219     struct rcu_head     rcu_head;
 220 };






 222 struct netdev_hw_addr_list {
 223     struct list_head    list;
 224     int         count;
 225 };



1563 /**
1564  *  struct net_device - The DEVICE structure.
1565  *
1566  *  Actually, this whole structure is a big mistake.  It mixes I/O
1567  *  data with strictly "high-level" data, and it has to know about
1568  *  almost every data structure used in the INET module.
1569  *
1570  *  @name:  This is the first field of the "visible" part of this structure
1571  *      (i.e. as seen by users in the "Space.c" file).  It is the name
1572  *      of the interface.
1573  *
1574  *  @name_hlist:    Device name hash chain, please keep it close to name[]
1575  *  @ifalias:   SNMP alias
1576  *  @mem_end:   Shared memory end
1577  *  @mem_start: Shared memory start
1578  *  @base_addr: Device I/O address
1579  *  @irq:       Device IRQ number
1580  *
1581  *  @state:     Generic network queuing layer state, see netdev_state_t
1582  *  @dev_list:  The global list of network devices
1583  *  @napi_list: List entry used for polling NAPI devices
1584  *  @unreg_list:    List entry  when we are unregistering the
1585  *          device; see the function unregister_netdev
1586  *  @close_list:    List entry used when we are closing the device
1587  *  @ptype_all:     Device-specific packet handlers for all protocols
1588  *  @ptype_specific: Device-specific, protocol-specific packet handlers
1589  *
1590  *  @adj_list:  Directly linked devices, like slaves for bonding
1591  *  @features:  Currently active device features
1592  *  @hw_features:   User-changeable features
1593  *
1594  *  @wanted_features:   User-requested features
1595  *  @vlan_features:     Mask of features inheritable by VLAN devices
1596  *
1597  *  @hw_enc_features:   Mask of features inherited by encapsulating devices
1598  *              This field indicates what encapsulation
1599  *              offloads the hardware is capable of doing,
1600  *              and drivers will need to set them appropriately.
1601  *
1602  *  @mpls_features: Mask of features inheritable by MPLS
1603  *
1604  *  @ifindex:   interface index
1605  *  @group:     The group the device belongs to
1606  *
1607  *  @stats:     Statistics struct, which was left as a legacy, use
1608  *          rtnl_link_stats64 instead
1609  *
1610  *  @rx_dropped:    Dropped packets by core network,
1611  *          do not use this in drivers
1612  *  @tx_dropped:    Dropped packets by core network,
1613  *          do not use this in drivers
1614  *  @rx_nohandler:  nohandler dropped packets by core network on
1615  *          inactive devices, do not use this in drivers
1616  *  @carrier_up_count:  Number of times the carrier has been up
1617  *  @carrier_down_count:    Number of times the carrier has been down
1618  *
1619  *  @wireless_handlers: List of functions to handle Wireless Extensions,
1620  *              instead of ioctl,
1621  *              see <net/iw_handler.h> for details.
1622  *  @wireless_data: Instance data managed by the core of wireless extensions
1623  *
1624  *  @netdev_ops:    Includes several pointers to callbacks,
1625  *          if one wants to override the ndo_*() functions
1626  *  @ethtool_ops:   Management operations
1627  *  @ndisc_ops: Includes callbacks for different IPv6 neighbour
1628  *          discovery handling. Necessary for e.g. 6LoWPAN.
1629  *  @header_ops:    Includes callbacks for creating,parsing,caching,etc
1630  *          of Layer 2 headers.
1631  *
1632  *  @flags:     Interface flags (a la BSD)
1633  *  @priv_flags:    Like 'flags' but invisible to userspace,
1634  *          see if.h for the definitions
1635  *  @gflags:    Global flags ( kept as legacy )
1636  *  @padded:    How much padding added by alloc_netdev()
1637  *  @operstate: RFC2863 operstate
1638  *  @link_mode: Mapping policy to operstate
1639  *  @if_port:   Selectable AUI, TP, ...
1640  *  @dma:       DMA channel
1641  *  @mtu:       Interface MTU value
1642  *  @min_mtu:   Interface Minimum MTU value
1643  *  @max_mtu:   Interface Maximum MTU value
1644  *  @type:      Interface hardware type
1645  *  @hard_header_len: Maximum hardware header length.
1646  *  @min_header_len:  Minimum hardware header length
1647  *
1648  *  @needed_headroom: Extra headroom the hardware may need, but not in all
1649  *            cases can this be guaranteed
1650  *  @needed_tailroom: Extra tailroom the hardware may need, but not in all
1651  *            cases can this be guaranteed. Some cases also use
1652  *            LL_MAX_HEADER instead to allocate the skb
1653  *
1654  *  interface address info:
1655  *
1656  *  @perm_addr:     Permanent hw address
1657  *  @addr_assign_type:  Hw address assignment type
1658  *  @addr_len:      Hardware address length
1659  *  @upper_level:       Maximum depth level of upper devices.
1660  *  @lower_level:       Maximum depth level of lower devices.
1661  *  @neigh_priv_len:    Used in neigh_alloc()
1662  *  @dev_id:        Used to differentiate devices that share
1663  *              the same link layer address
1664  *  @dev_port:      Used to differentiate devices that share
1665  *              the same function
1666  *  @addr_list_lock:    XXX: need comments on this one
1667  *  @uc_promisc:        Counter that indicates promiscuous mode
1668  *              has been enabled due to the need to listen to
1669  *              additional unicast addresses in a device that
1670  *              does not implement ndo_set_rx_mode()
1671  *  @uc:            unicast mac addresses
1672  *  @mc:            multicast mac addresses
1673  *  @dev_addrs:     list of device hw addresses
1674  *  @queues_kset:       Group of all Kobjects in the Tx and RX queues
1675  *  @promiscuity:       Number of times the NIC is told to work in
1676  *              promiscuous mode; if it becomes 0 the NIC will
1677  *              exit promiscuous mode
1678  *  @allmulti:      Counter, enables or disables allmulticast mode
1679  *
1680  *  @vlan_info: VLAN info
1681  *  @dsa_ptr:   dsa specific data
1682  *  @tipc_ptr:  TIPC specific data
1683  *  @atalk_ptr: AppleTalk link
1684  *  @ip_ptr:    IPv4 specific data
1685  *  @dn_ptr:    DECnet specific data
1686  *  @ip6_ptr:   IPv6 specific data
1687  *  @ax25_ptr:  AX.25 specific data
1688  *  @ieee80211_ptr: IEEE 802.11 specific data, assign before registering
1689  *
1690  *  @dev_addr:  Hw address (before bcast,
1691  *          because most packets are unicast)
1692  *
1693  *  @_rx:           Array of RX queues
1694  *  @num_rx_queues:     Number of RX queues
1695  *              allocated at register_netdev() time
1696  *  @real_num_rx_queues:    Number of RX queues currently active in device
1697  *
1698  *  @rx_handler:        handler for received packets
1699  *  @rx_handler_data:   XXX: need comments on this one
1700  *  @miniq_ingress:     ingress/clsact qdisc specific data for
1701  *              ingress processing
1702  *  @ingress_queue:     XXX: need comments on this one
1703  *  @broadcast:     hw bcast address
1704  *
1705  *  @rx_cpu_rmap:   CPU reverse-mapping for RX completion interrupts,
1706  *          indexed by RX queue number. Assigned by driver.
1707  *          This must only be set if the ndo_rx_flow_steer
1708  *          operation is defined
1709  *  @index_hlist:       Device index hash chain
1710  *
1711  *  @_tx:           Array of TX queues
1712  *  @num_tx_queues:     Number of TX queues allocated at alloc_netdev_mq() time
1713  *  @real_num_tx_queues:    Number of TX queues currently active in device
1714  *  @qdisc:         Root qdisc from userspace point of view
1715  *  @tx_queue_len:      Max frames per queue allowed
1716  *  @tx_global_lock:    XXX: need comments on this one
1717  *
1718  *  @xps_maps:  XXX: need comments on this one
1719  *  @miniq_egress:      clsact qdisc specific data for
1720  *              egress processing
1721  *  @watchdog_timeo:    Represents the timeout that is used by
1722  *              the watchdog (see dev_watchdog())
1723  *  @watchdog_timer:    List of timers
1724  *
1725  *  @pcpu_refcnt:       Number of references to this device
1726  *  @todo_list:     Delayed register/unregister
1727  *  @link_watch_list:   XXX: need comments on this one
1728  *
1729  *  @reg_state:     Register/unregister state machine
1730  *  @dismantle:     Device is going to be freed
1731  *  @rtnl_link_state:   This enum represents the phases of creating
1732  *              a new link
1733  *
1734  *  @needs_free_netdev: Should unregister perform free_netdev?
1735  *  @priv_destructor:   Called from unregister
1736  *  @npinfo:        XXX: need comments on this one
1737  *  @nd_net:        Network namespace this network device is inside
1738  *
1739  *  @ml_priv:   Mid-layer private
1740  *  @lstats:    Loopback statistics
1741  *  @tstats:    Tunnel statistics
1742  *  @dstats:    Dummy statistics
1743  *  @vstats:    Virtual ethernet statistics
1744  *
1745  *  @garp_port: GARP
1746  *  @mrp_port:  MRP
1747  *
1748  *  @dev:       Class/net/name entry
1749  *  @sysfs_groups:  Space for optional device, statistics and wireless
1750  *          sysfs groups
1751  *
1752  *  @sysfs_rx_queue_group:  Space for optional per-rx queue attributes
1753  *  @rtnl_link_ops: Rtnl_link_ops
1754  *
1755  *  @gso_max_size:  Maximum size of generic segmentation offload
1756  *  @gso_max_segs:  Maximum number of segments that can be passed to the
1757  *          NIC for GSO
1758  *
1759  *  @dcbnl_ops: Data Center Bridging netlink ops
1760  *  @num_tc:    Number of traffic classes in the net device
1761  *  @tc_to_txq: XXX: need comments on this one
1762  *  @prio_tc_map:   XXX: need comments on this one
1763  *
1764  *  @fcoe_ddp_xid:  Max exchange id for FCoE LRO by ddp
1765  *
1766  *  @priomap:   XXX: need comments on this one
1767  *  @phydev:    Physical device may attach itself
1768  *          for hardware timestamping
1769  *  @sfp_bus:   attached &struct sfp_bus structure.
1770  *
1771  *  @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
1772  *  @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
1773  *
1774  *  @proto_down:    protocol port state information can be sent to the
1775  *          switch driver and used to set the phys state of the
1776  *          switch port.
1777  *
1778  *  @wol_enabled:   Wake-on-LAN is enabled
1779  *
1780  *  FIXME: cleanup struct net_device such that network protocol info
1781  *  moves out.
1782  */
1783
1784 struct net_device {
1785     char            name[IFNAMSIZ];
1786     struct hlist_node   name_hlist;
1787     struct dev_ifalias  __rcu *ifalias;
1788     /*
1789      *  I/O specific fields
1790      *  FIXME: Merge these and struct ifmap into one
1791      */
1792     unsigned long       mem_end;
1793     unsigned long       mem_start;
1794     unsigned long       base_addr;
1795     int         irq;
1796
1797     /*
1798      *  Some hardware also needs these fields (state,dev_list,
1799      *  napi_list,unreg_list,close_list) but they are not
1800      *  part of the usual set specified in Space.c.
1801      */
1802
1803     unsigned long       state;
1804
1805     struct list_head    dev_list;
1806     struct list_head    napi_list;
1807     struct list_head    unreg_list;
1808     struct list_head    close_list;
1809     struct list_head    ptype_all;
1810     struct list_head    ptype_specific;
1811
1812     struct {
1813         struct list_head upper;
1814         struct list_head lower;
1815     } adj_list;
1816
1817     netdev_features_t   features;
1818     netdev_features_t   hw_features;
1819     netdev_features_t   wanted_features;
1820     netdev_features_t   vlan_features;
1821     netdev_features_t   hw_enc_features;
1822     netdev_features_t   mpls_features;
1823     netdev_features_t   gso_partial_features;
1824
1825     int         ifindex;
1826     int         group;
1827
1828     struct net_device_stats stats;
1829
1830     atomic_long_t       rx_dropped;
1831     atomic_long_t       tx_dropped;
1832     atomic_long_t       rx_nohandler;
1833
1834     /* Stats to monitor link on/off, flapping */
1835     atomic_t        carrier_up_count;
1836     atomic_t        carrier_down_count;
1837
1838 #ifdef CONFIG_WIRELESS_EXT
1839     const struct iw_handler_def *wireless_handlers;
1840     struct iw_public_data   *wireless_data;
1841 #endif
1842     const struct net_device_ops *netdev_ops;
1843     const struct ethtool_ops *ethtool_ops;
1844 #ifdef CONFIG_NET_SWITCHDEV
1845     const struct switchdev_ops *switchdev_ops;
1846 #endif
1847 #ifdef CONFIG_NET_L3_MASTER_DEV
1848     const struct l3mdev_ops *l3mdev_ops;
1849 #endif
1850 #if IS_ENABLED(CONFIG_IPV6)
1851     const struct ndisc_ops *ndisc_ops;
1852 #endif
1853
1854 #ifdef CONFIG_XFRM_OFFLOAD
1855     const struct xfrmdev_ops *xfrmdev_ops;
1856 #endif
1857
1858 #if IS_ENABLED(CONFIG_TLS_DEVICE)
1859     const struct tlsdev_ops *tlsdev_ops;
1860 #endif
1861
1862     const struct header_ops *header_ops;
1863
1864     unsigned int        flags;
1865     unsigned int        priv_flags;
1866
1867     unsigned short      gflags;
1868     unsigned short      padded;
1869
1870     unsigned char       operstate;
1871     unsigned char       link_mode;
1872
1873     unsigned char       if_port;
1874     unsigned char       dma;
1875
1876     /* Note : dev->mtu is often read without holding a lock.
1877      * Writers usually hold RTNL.
1878      * It is recommended to use READ_ONCE() to annotate the reads,
1879      * and to use WRITE_ONCE() to annotate the writes.
1880      */
1881     unsigned int        mtu;
1882     unsigned int        min_mtu;
1883     unsigned int        max_mtu;
1884     unsigned short      type;
1885     unsigned short      hard_header_len;
1886     unsigned char       min_header_len;
1887
1888     unsigned short      needed_headroom;
1889     unsigned short      needed_tailroom;
1890
1891     /* Interface address info. */
1892     unsigned char       perm_addr[MAX_ADDR_LEN];
1893     unsigned char       addr_assign_type;
1894     unsigned char       addr_len;
1895     unsigned char       upper_level;
1896     unsigned char       lower_level;
1897     unsigned short      neigh_priv_len;
1898     unsigned short          dev_id;
1899     unsigned short          dev_port;
1900     spinlock_t      addr_list_lock;
1901     unsigned char       name_assign_type;
1902     bool            uc_promisc;
1903     struct netdev_hw_addr_list  uc;
1904     struct netdev_hw_addr_list  mc;
1905     struct netdev_hw_addr_list  dev_addrs;
1906
1907 #ifdef CONFIG_SYSFS
1908     struct kset     *queues_kset;
1909 #endif
1910     unsigned int        promiscuity;
1911     unsigned int        allmulti;
1912
1913
1914     /* Protocol-specific pointers */
1915
1916 #if IS_ENABLED(CONFIG_VLAN_8021Q)
1917     struct vlan_info __rcu  *vlan_info;
1918 #endif
1919 #if IS_ENABLED(CONFIG_NET_DSA)
1920     struct dsa_port     *dsa_ptr;
1921 #endif
1922 #if IS_ENABLED(CONFIG_TIPC)
1923     struct tipc_bearer __rcu *tipc_ptr;
1924 #endif
1925 #if IS_ENABLED(CONFIG_IRDA) || IS_ENABLED(CONFIG_ATALK)
1926     void            *atalk_ptr;
1927 #endif
1928     struct in_device __rcu  *ip_ptr;
1929 #if IS_ENABLED(CONFIG_DECNET)
1930     struct dn_dev __rcu     *dn_ptr;
1931 #endif
1932     struct inet6_dev __rcu  *ip6_ptr;
1933 #if IS_ENABLED(CONFIG_AX25)
1934     void            *ax25_ptr;
1935 #endif
1936     struct wireless_dev *ieee80211_ptr;
1937     struct wpan_dev     *ieee802154_ptr;
1938 #if IS_ENABLED(CONFIG_MPLS_ROUTING)
1939     struct mpls_dev __rcu   *mpls_ptr;
1940 #endif
1941
1942 /*
1943  * Cache lines mostly used on receive path (including eth_type_trans())
1944  */
1945     /* Interface address info used in eth_type_trans() */
1946     unsigned char       *dev_addr;
1947
1948     struct netdev_rx_queue  *_rx;
1949     unsigned int        num_rx_queues;
1950     unsigned int        real_num_rx_queues;
1951
1952     struct bpf_prog __rcu   *xdp_prog;
1953     unsigned long       gro_flush_timeout;
1954     rx_handler_func_t __rcu *rx_handler;
1955     void __rcu      *rx_handler_data;
1956
1957 #ifdef CONFIG_NET_CLS_ACT
1958     struct mini_Qdisc __rcu *miniq_ingress;
1959 #endif
1960     struct netdev_queue __rcu *ingress_queue;
1961 #ifdef CONFIG_NETFILTER_INGRESS
1962     struct nf_hook_entries __rcu *nf_hooks_ingress;
1963 #endif
1964
1965     unsigned char       broadcast[MAX_ADDR_LEN];
1966 #ifdef CONFIG_RFS_ACCEL
1967     struct cpu_rmap     *rx_cpu_rmap;
1968 #endif
1969     struct hlist_node   index_hlist;
1970
1971 /*
1972  * Cache lines mostly used on transmit path
1973  */
1974     struct netdev_queue *_tx ____cacheline_aligned_in_smp;
1975     unsigned int        num_tx_queues;
1976     unsigned int        real_num_tx_queues;
1977     struct Qdisc        *qdisc;
1978 #ifdef CONFIG_NET_SCHED
1979     DECLARE_HASHTABLE   (qdisc_hash, 4);
1980 #endif
1981     unsigned int        tx_queue_len;
1982     spinlock_t      tx_global_lock;
1983     int         watchdog_timeo;
1984
1985 #ifdef CONFIG_XPS
1986     struct xps_dev_maps __rcu *xps_cpus_map;
1987     struct xps_dev_maps __rcu *xps_rxqs_map;
1988 #endif
1989 #ifdef CONFIG_NET_CLS_ACT
1990     struct mini_Qdisc __rcu *miniq_egress;
1991 #endif
1992
1993     /* These may be needed for future network-power-down code. */
1994     struct timer_list   watchdog_timer;
1995
1996     int __percpu        *pcpu_refcnt;
1997     struct list_head    todo_list;
1998
1999     struct list_head    link_watch_list;
2000
2001     enum { NETREG_UNINITIALIZED=0,
2002            NETREG_REGISTERED,   /* completed register_netdevice */
2003            NETREG_UNREGISTERING,    /* called unregister_netdevice */
2004            NETREG_UNREGISTERED, /* completed unregister todo */
2005            NETREG_RELEASED,     /* called free_netdev */
2006            NETREG_DUMMY,        /* dummy device for NAPI poll */
2007     } reg_state:8;
2008
2009     bool dismantle;
2010
2011     enum {
2012         RTNL_LINK_INITIALIZED,
2013         RTNL_LINK_INITIALIZING,
2014     } rtnl_link_state:16;
2015
2016     bool needs_free_netdev;
2017     void (*priv_destructor)(struct net_device *dev);
2018
2019 #ifdef CONFIG_NETPOLL
2020     struct netpoll_info __rcu   *npinfo;
2021 #endif
2022
2023     possible_net_t          nd_net;
2024
2025     /* mid-layer private */
2026     union {
2027         void                    *ml_priv;
2028         struct pcpu_lstats __percpu     *lstats;
2029         struct pcpu_sw_netstats __percpu    *tstats;
2030         struct pcpu_dstats __percpu     *dstats;
2031         struct pcpu_vstats __percpu     *vstats;
2032     };
2033
2034 #if IS_ENABLED(CONFIG_GARP)
2035     struct garp_port __rcu  *garp_port;
2036 #endif
2037 #if IS_ENABLED(CONFIG_MRP)
2038     struct mrp_port __rcu   *mrp_port;
2039 #endif
2040
2041     struct device       dev;
2042     const struct attribute_group *sysfs_groups[4];
2043     const struct attribute_group *sysfs_rx_queue_group;
2044
2045     const struct rtnl_link_ops *rtnl_link_ops;
2046
2047     /* for setting kernel sock attribute on TCP connection setup */
2048 #define GSO_MAX_SIZE        65536
2049     unsigned int        gso_max_size;
2050 #define GSO_MAX_SEGS        65535
2051     u16         gso_max_segs;
2052
2053 #ifdef CONFIG_DCB
2054     const struct dcbnl_rtnl_ops *dcbnl_ops;
2055 #endif
2056     s16         num_tc;
2057     struct netdev_tc_txq    tc_to_txq[TC_MAX_QUEUE];
2058     u8          prio_tc_map[TC_BITMASK + 1];
2059
2060 #if IS_ENABLED(CONFIG_FCOE)
2061     unsigned int        fcoe_ddp_xid;
2062 #endif
2063 #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
2064     struct netprio_map __rcu *priomap;
2065 #endif
2066     struct phy_device   *phydev;
2067     struct sfp_bus      *sfp_bus;
2068     struct lock_class_key   *qdisc_tx_busylock;
2069     struct lock_class_key   *qdisc_running_key;
2070     bool            proto_down;
2071     unsigned        wol_enabled:1;
2072
2073     ANDROID_KABI_RESERVE(1);
2074     ANDROID_KABI_RESERVE(2);
2075     ANDROID_KABI_RESERVE(3);
2076     ANDROID_KABI_RESERVE(4);
2077     ANDROID_KABI_RESERVE(5);
2078     ANDROID_KABI_RESERVE(6);
2079     ANDROID_KABI_RESERVE(7);
2080     ANDROID_KABI_RESERVE(8);
2081
2082 };

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值