Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright(c) 1999 - 2006 Intel Corporation. */
0003 
0004 /* Linux PRO/1000 Ethernet Driver main header file */
0005 
0006 #ifndef _E1000_H_
0007 #define _E1000_H_
0008 
0009 #include <linux/stddef.h>
0010 #include <linux/module.h>
0011 #include <linux/types.h>
0012 #include <asm/byteorder.h>
0013 #include <linux/mm.h>
0014 #include <linux/errno.h>
0015 #include <linux/ioport.h>
0016 #include <linux/pci.h>
0017 #include <linux/kernel.h>
0018 #include <linux/netdevice.h>
0019 #include <linux/etherdevice.h>
0020 #include <linux/skbuff.h>
0021 #include <linux/delay.h>
0022 #include <linux/timer.h>
0023 #include <linux/slab.h>
0024 #include <linux/vmalloc.h>
0025 #include <linux/interrupt.h>
0026 #include <linux/string.h>
0027 #include <linux/pagemap.h>
0028 #include <linux/dma-mapping.h>
0029 #include <linux/bitops.h>
0030 #include <asm/io.h>
0031 #include <asm/irq.h>
0032 #include <linux/capability.h>
0033 #include <linux/in.h>
0034 #include <linux/ip.h>
0035 #include <linux/ipv6.h>
0036 #include <linux/tcp.h>
0037 #include <linux/udp.h>
0038 #include <net/pkt_sched.h>
0039 #include <linux/list.h>
0040 #include <linux/reboot.h>
0041 #include <net/checksum.h>
0042 #include <linux/mii.h>
0043 #include <linux/ethtool.h>
0044 #include <linux/if_vlan.h>
0045 
0046 #define BAR_0       0
0047 #define BAR_1       1
0048 
0049 #define INTEL_E1000_ETHERNET_DEVICE(device_id) {\
0050     PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
0051 
0052 struct e1000_adapter;
0053 
0054 #include "e1000_hw.h"
0055 
0056 #define E1000_MAX_INTR          10
0057 
0058 /*
0059  * Count for polling __E1000_RESET condition every 10-20msec.
0060  */
0061 #define E1000_CHECK_RESET_COUNT 50
0062 
0063 /* TX/RX descriptor defines */
0064 #define E1000_DEFAULT_TXD       256
0065 #define E1000_MAX_TXD           256
0066 #define E1000_MIN_TXD           48
0067 #define E1000_MAX_82544_TXD     4096
0068 
0069 #define E1000_DEFAULT_RXD       256
0070 #define E1000_MAX_RXD           256
0071 #define E1000_MIN_RXD           48
0072 #define E1000_MAX_82544_RXD     4096
0073 
0074 #define E1000_MIN_ITR_USECS     10 /* 100000 irq/sec */
0075 #define E1000_MAX_ITR_USECS     10000 /* 100    irq/sec */
0076 
0077 /* this is the size past which hardware will drop packets when setting LPE=0 */
0078 #define MAXIMUM_ETHERNET_VLAN_SIZE  1522
0079 
0080 /* Supported Rx Buffer Sizes */
0081 #define E1000_RXBUFFER_128      128    /* Used for packet split */
0082 #define E1000_RXBUFFER_256      256    /* Used for packet split */
0083 #define E1000_RXBUFFER_512      512
0084 #define E1000_RXBUFFER_1024     1024
0085 #define E1000_RXBUFFER_2048     2048
0086 #define E1000_RXBUFFER_4096     4096
0087 #define E1000_RXBUFFER_8192     8192
0088 #define E1000_RXBUFFER_16384        16384
0089 
0090 /* SmartSpeed delimiters */
0091 #define E1000_SMARTSPEED_DOWNSHIFT  3
0092 #define E1000_SMARTSPEED_MAX        15
0093 
0094 /* Packet Buffer allocations */
0095 #define E1000_PBA_BYTES_SHIFT       0xA
0096 #define E1000_TX_HEAD_ADDR_SHIFT    7
0097 #define E1000_PBA_TX_MASK       0xFFFF0000
0098 
0099 /* Flow Control Watermarks */
0100 #define E1000_FC_HIGH_DIFF  0x1638 /* High: 5688 bytes below Rx FIFO size */
0101 #define E1000_FC_LOW_DIFF   0x1640 /* Low:  5696 bytes below Rx FIFO size */
0102 
0103 #define E1000_FC_PAUSE_TIME 0xFFFF /* pause for the max or until send xon */
0104 
0105 /* How many Tx Descriptors do we need to call netif_wake_queue ? */
0106 #define E1000_TX_QUEUE_WAKE 16
0107 /* How many Rx Buffers do we bundle into one write to the hardware ? */
0108 #define E1000_RX_BUFFER_WRITE   16 /* Must be power of 2 */
0109 
0110 #define AUTO_ALL_MODES      0
0111 #define E1000_EEPROM_82544_APM  0x0004
0112 #define E1000_EEPROM_APME   0x0400
0113 
0114 #ifndef E1000_MASTER_SLAVE
0115 /* Switch to override PHY master/slave setting */
0116 #define E1000_MASTER_SLAVE  e1000_ms_hw_default
0117 #endif
0118 
0119 #define E1000_MNG_VLAN_NONE (-1)
0120 
0121 /* wrapper around a pointer to a socket buffer,
0122  * so a DMA handle can be stored along with the buffer
0123  */
0124 struct e1000_tx_buffer {
0125     struct sk_buff *skb;
0126     dma_addr_t dma;
0127     unsigned long time_stamp;
0128     u16 length;
0129     u16 next_to_watch;
0130     bool mapped_as_page;
0131     unsigned short segs;
0132     unsigned int bytecount;
0133 };
0134 
0135 struct e1000_rx_buffer {
0136     union {
0137         struct page *page; /* jumbo: alloc_page */
0138         u8 *data; /* else, netdev_alloc_frag */
0139     } rxbuf;
0140     dma_addr_t dma;
0141 };
0142 
0143 struct e1000_tx_ring {
0144     /* pointer to the descriptor ring memory */
0145     void *desc;
0146     /* physical address of the descriptor ring */
0147     dma_addr_t dma;
0148     /* length of descriptor ring in bytes */
0149     unsigned int size;
0150     /* number of descriptors in the ring */
0151     unsigned int count;
0152     /* next descriptor to associate a buffer with */
0153     unsigned int next_to_use;
0154     /* next descriptor to check for DD status bit */
0155     unsigned int next_to_clean;
0156     /* array of buffer information structs */
0157     struct e1000_tx_buffer *buffer_info;
0158 
0159     u16 tdh;
0160     u16 tdt;
0161     bool last_tx_tso;
0162 };
0163 
0164 struct e1000_rx_ring {
0165     /* pointer to the descriptor ring memory */
0166     void *desc;
0167     /* physical address of the descriptor ring */
0168     dma_addr_t dma;
0169     /* length of descriptor ring in bytes */
0170     unsigned int size;
0171     /* number of descriptors in the ring */
0172     unsigned int count;
0173     /* next descriptor to associate a buffer with */
0174     unsigned int next_to_use;
0175     /* next descriptor to check for DD status bit */
0176     unsigned int next_to_clean;
0177     /* array of buffer information structs */
0178     struct e1000_rx_buffer *buffer_info;
0179     struct sk_buff *rx_skb_top;
0180 
0181     /* cpu for rx queue */
0182     int cpu;
0183 
0184     u16 rdh;
0185     u16 rdt;
0186 };
0187 
0188 #define E1000_DESC_UNUSED(R)                        \
0189 ({                                  \
0190     unsigned int clean = smp_load_acquire(&(R)->next_to_clean); \
0191     unsigned int use = READ_ONCE((R)->next_to_use);         \
0192     (clean > use ? 0 : (R)->count) + clean - use - 1;       \
0193 })
0194 
0195 #define E1000_RX_DESC_EXT(R, i)                     \
0196     (&(((union e1000_rx_desc_extended *)((R).desc))[i]))
0197 #define E1000_GET_DESC(R, i, type)  (&(((struct type *)((R).desc))[i]))
0198 #define E1000_RX_DESC(R, i)     E1000_GET_DESC(R, i, e1000_rx_desc)
0199 #define E1000_TX_DESC(R, i)     E1000_GET_DESC(R, i, e1000_tx_desc)
0200 #define E1000_CONTEXT_DESC(R, i)    E1000_GET_DESC(R, i, e1000_context_desc)
0201 
0202 /* board specific private data structure */
0203 
0204 struct e1000_adapter {
0205     unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
0206     u16 mng_vlan_id;
0207     u32 bd_number;
0208     u32 rx_buffer_len;
0209     u32 wol;
0210     u32 smartspeed;
0211     u32 en_mng_pt;
0212     u16 link_speed;
0213     u16 link_duplex;
0214     spinlock_t stats_lock;
0215     unsigned int total_tx_bytes;
0216     unsigned int total_tx_packets;
0217     unsigned int total_rx_bytes;
0218     unsigned int total_rx_packets;
0219     /* Interrupt Throttle Rate */
0220     u32 itr;
0221     u32 itr_setting;
0222     u16 tx_itr;
0223     u16 rx_itr;
0224 
0225     u8 fc_autoneg;
0226 
0227     /* TX */
0228     struct e1000_tx_ring *tx_ring;      /* One per active queue */
0229     unsigned int restart_queue;
0230     u32 txd_cmd;
0231     u32 tx_int_delay;
0232     u32 tx_abs_int_delay;
0233     u32 gotcl;
0234     u64 gotcl_old;
0235     u64 tpt_old;
0236     u64 colc_old;
0237     u32 tx_timeout_count;
0238     u32 tx_fifo_head;
0239     u32 tx_head_addr;
0240     u32 tx_fifo_size;
0241     u8  tx_timeout_factor;
0242     atomic_t tx_fifo_stall;
0243     bool pcix_82544;
0244     bool detect_tx_hung;
0245     bool dump_buffers;
0246 
0247     /* RX */
0248     bool (*clean_rx)(struct e1000_adapter *adapter,
0249              struct e1000_rx_ring *rx_ring,
0250              int *work_done, int work_to_do);
0251     void (*alloc_rx_buf)(struct e1000_adapter *adapter,
0252                  struct e1000_rx_ring *rx_ring,
0253                  int cleaned_count);
0254     struct e1000_rx_ring *rx_ring;      /* One per active queue */
0255     struct napi_struct napi;
0256 
0257     int num_tx_queues;
0258     int num_rx_queues;
0259 
0260     u64 hw_csum_err;
0261     u64 hw_csum_good;
0262     u32 alloc_rx_buff_failed;
0263     u32 rx_int_delay;
0264     u32 rx_abs_int_delay;
0265     bool rx_csum;
0266     u32 gorcl;
0267     u64 gorcl_old;
0268 
0269     /* OS defined structs */
0270     struct net_device *netdev;
0271     struct pci_dev *pdev;
0272 
0273     /* structs defined in e1000_hw.h */
0274     struct e1000_hw hw;
0275     struct e1000_hw_stats stats;
0276     struct e1000_phy_info phy_info;
0277     struct e1000_phy_stats phy_stats;
0278 
0279     u32 test_icr;
0280     struct e1000_tx_ring test_tx_ring;
0281     struct e1000_rx_ring test_rx_ring;
0282 
0283     int msg_enable;
0284 
0285     /* to not mess up cache alignment, always add to the bottom */
0286     bool tso_force;
0287     bool smart_power_down;  /* phy smart power down */
0288     bool quad_port_a;
0289     unsigned long flags;
0290     u32 eeprom_wol;
0291 
0292     /* for ioport free */
0293     int bars;
0294     int need_ioport;
0295 
0296     bool discarding;
0297 
0298     struct work_struct reset_task;
0299     struct delayed_work watchdog_task;
0300     struct delayed_work fifo_stall_task;
0301     struct delayed_work phy_info_task;
0302 };
0303 
0304 enum e1000_state_t {
0305     __E1000_TESTING,
0306     __E1000_RESETTING,
0307     __E1000_DOWN,
0308     __E1000_DISABLED
0309 };
0310 
0311 #undef pr_fmt
0312 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0313 
0314 struct net_device *e1000_get_hw_dev(struct e1000_hw *hw);
0315 #define e_dbg(format, arg...) \
0316     netdev_dbg(e1000_get_hw_dev(hw), format, ## arg)
0317 #define e_err(msglvl, format, arg...) \
0318     netif_err(adapter, msglvl, adapter->netdev, format, ## arg)
0319 #define e_info(msglvl, format, arg...) \
0320     netif_info(adapter, msglvl, adapter->netdev, format, ## arg)
0321 #define e_warn(msglvl, format, arg...) \
0322     netif_warn(adapter, msglvl, adapter->netdev, format, ## arg)
0323 #define e_notice(msglvl, format, arg...) \
0324     netif_notice(adapter, msglvl, adapter->netdev, format, ## arg)
0325 #define e_dev_info(format, arg...) \
0326     dev_info(&adapter->pdev->dev, format, ## arg)
0327 #define e_dev_warn(format, arg...) \
0328     dev_warn(&adapter->pdev->dev, format, ## arg)
0329 #define e_dev_err(format, arg...) \
0330     dev_err(&adapter->pdev->dev, format, ## arg)
0331 
0332 extern char e1000_driver_name[];
0333 
0334 int e1000_open(struct net_device *netdev);
0335 int e1000_close(struct net_device *netdev);
0336 int e1000_up(struct e1000_adapter *adapter);
0337 void e1000_down(struct e1000_adapter *adapter);
0338 void e1000_reinit_locked(struct e1000_adapter *adapter);
0339 void e1000_reset(struct e1000_adapter *adapter);
0340 int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx);
0341 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
0342 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
0343 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
0344 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
0345 void e1000_update_stats(struct e1000_adapter *adapter);
0346 bool e1000_has_link(struct e1000_adapter *adapter);
0347 void e1000_power_up_phy(struct e1000_adapter *);
0348 void e1000_set_ethtool_ops(struct net_device *netdev);
0349 void e1000_check_options(struct e1000_adapter *adapter);
0350 char *e1000_get_hw_dev_name(struct e1000_hw *hw);
0351 
0352 #endif /* _E1000_H_ */