12246cbc2SShay Agroskin /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 21738cd3eSNetanel Belgazal /* 32246cbc2SShay Agroskin * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved. 41738cd3eSNetanel Belgazal */ 51738cd3eSNetanel Belgazal 61738cd3eSNetanel Belgazal #ifndef ENA_H 71738cd3eSNetanel Belgazal #define ENA_H 81738cd3eSNetanel Belgazal 91738cd3eSNetanel Belgazal #include <linux/bitops.h> 10282faf61SArthur Kiyanovski #include <linux/dim.h> 111738cd3eSNetanel Belgazal #include <linux/etherdevice.h> 12838c93dcSSameeh Jubran #include <linux/if_vlan.h> 131738cd3eSNetanel Belgazal #include <linux/inetdevice.h> 141738cd3eSNetanel Belgazal #include <linux/interrupt.h> 151738cd3eSNetanel Belgazal #include <linux/netdevice.h> 161738cd3eSNetanel Belgazal #include <linux/skbuff.h> 171738cd3eSNetanel Belgazal 181738cd3eSNetanel Belgazal #include "ena_com.h" 191738cd3eSNetanel Belgazal #include "ena_eth_com.h" 201738cd3eSNetanel Belgazal 2192040c6dSArthur Kiyanovski #define DRV_MODULE_GEN_MAJOR 2 2292040c6dSArthur Kiyanovski #define DRV_MODULE_GEN_MINOR 1 2392040c6dSArthur Kiyanovski #define DRV_MODULE_GEN_SUBMINOR 0 2492040c6dSArthur Kiyanovski 251738cd3eSNetanel Belgazal #define DRV_MODULE_NAME "ena" 2692040c6dSArthur Kiyanovski 271738cd3eSNetanel Belgazal #define DEVICE_NAME "Elastic Network Adapter (ENA)" 281738cd3eSNetanel Belgazal 291738cd3eSNetanel Belgazal /* 1 for AENQ + ADMIN */ 3006443684SNetanel Belgazal #define ENA_ADMIN_MSIX_VEC 1 3106443684SNetanel Belgazal #define ENA_MAX_MSIX_VEC(io_queues) (ENA_ADMIN_MSIX_VEC + (io_queues)) 3206443684SNetanel Belgazal 33bd791175SArthur Kiyanovski /* The ENA buffer length fields is 16 bit long. So when PAGE_SIZE == 64kB the 34bd791175SArthur Kiyanovski * driver passes 0. 35bd791175SArthur Kiyanovski * Since the max packet size the ENA handles is ~9kB limit the buffer length to 36bd791175SArthur Kiyanovski * 16kB. 37bd791175SArthur Kiyanovski */ 38bd791175SArthur Kiyanovski #if PAGE_SIZE > SZ_16K 39caec6619SGavin Shan #define ENA_PAGE_SIZE (_AC(SZ_16K, UL)) 40bd791175SArthur Kiyanovski #else 41bd791175SArthur Kiyanovski #define ENA_PAGE_SIZE PAGE_SIZE 42bd791175SArthur Kiyanovski #endif 43bd791175SArthur Kiyanovski 4406443684SNetanel Belgazal #define ENA_MIN_MSIX_VEC 2 451738cd3eSNetanel Belgazal 461738cd3eSNetanel Belgazal #define ENA_REG_BAR 0 471738cd3eSNetanel Belgazal #define ENA_MEM_BAR 2 481738cd3eSNetanel Belgazal #define ENA_BAR_MASK (BIT(ENA_REG_BAR) | BIT(ENA_MEM_BAR)) 491738cd3eSNetanel Belgazal 501738cd3eSNetanel Belgazal #define ENA_DEFAULT_RING_SIZE (1024) 5113ca32a6SSameeh Jubran #define ENA_MIN_RING_SIZE (256) 5213ca32a6SSameeh Jubran 532413ea97SSameeh Jubran #define ENA_MIN_NUM_IO_QUEUES (1) 542413ea97SSameeh Jubran 551738cd3eSNetanel Belgazal #define ENA_TX_WAKEUP_THRESH (MAX_SKB_FRAGS + 2) 5687731f0cSArthur Kiyanovski #define ENA_DEFAULT_RX_COPYBREAK (256 - NET_IP_ALIGN) 571738cd3eSNetanel Belgazal 581738cd3eSNetanel Belgazal #define ENA_MIN_MTU 128 591738cd3eSNetanel Belgazal 601738cd3eSNetanel Belgazal #define ENA_NAME_MAX_LEN 20 611738cd3eSNetanel Belgazal #define ENA_IRQNAME_SIZE 40 621738cd3eSNetanel Belgazal 631738cd3eSNetanel Belgazal #define ENA_PKT_MAX_BUFS 19 641738cd3eSNetanel Belgazal 651738cd3eSNetanel Belgazal #define ENA_RX_RSS_TABLE_LOG_SIZE 7 661738cd3eSNetanel Belgazal #define ENA_RX_RSS_TABLE_SIZE (1 << ENA_RX_RSS_TABLE_LOG_SIZE) 671738cd3eSNetanel Belgazal 681738cd3eSNetanel Belgazal /* The number of tx packet completions that will be handled each NAPI poll 691738cd3eSNetanel Belgazal * cycle is ring_size / ENA_TX_POLL_BUDGET_DIVIDER. 701738cd3eSNetanel Belgazal */ 711738cd3eSNetanel Belgazal #define ENA_TX_POLL_BUDGET_DIVIDER 4 721738cd3eSNetanel Belgazal 730574bb80SArthur Kiyanovski /* Refill Rx queue when number of required descriptors is above 740574bb80SArthur Kiyanovski * QUEUE_SIZE / ENA_RX_REFILL_THRESH_DIVIDER or ENA_RX_REFILL_THRESH_PACKET 751738cd3eSNetanel Belgazal */ 761738cd3eSNetanel Belgazal #define ENA_RX_REFILL_THRESH_DIVIDER 8 770574bb80SArthur Kiyanovski #define ENA_RX_REFILL_THRESH_PACKET 256 781738cd3eSNetanel Belgazal 791738cd3eSNetanel Belgazal /* Number of queues to check for missing queues per timer service */ 801738cd3eSNetanel Belgazal #define ENA_MONITORED_TX_QUEUES 4 811738cd3eSNetanel Belgazal /* Max timeout packets before device reset */ 827102a18aSNetanel Belgazal #define MAX_NUM_OF_TIMEOUTED_PACKETS 128 831738cd3eSNetanel Belgazal 841738cd3eSNetanel Belgazal #define ENA_TX_RING_IDX_NEXT(idx, ring_size) (((idx) + 1) & ((ring_size) - 1)) 851738cd3eSNetanel Belgazal 861738cd3eSNetanel Belgazal #define ENA_RX_RING_IDX_NEXT(idx, ring_size) (((idx) + 1) & ((ring_size) - 1)) 871738cd3eSNetanel Belgazal #define ENA_RX_RING_IDX_ADD(idx, n, ring_size) \ 881738cd3eSNetanel Belgazal (((idx) + (n)) & ((ring_size) - 1)) 891738cd3eSNetanel Belgazal 901738cd3eSNetanel Belgazal #define ENA_IO_TXQ_IDX(q) (2 * (q)) 911738cd3eSNetanel Belgazal #define ENA_IO_RXQ_IDX(q) (2 * (q) + 1) 9292569fd2SArthur Kiyanovski #define ENA_IO_TXQ_IDX_TO_COMBINED_IDX(q) ((q) / 2) 9392569fd2SArthur Kiyanovski #define ENA_IO_RXQ_IDX_TO_COMBINED_IDX(q) (((q) - 1) / 2) 941738cd3eSNetanel Belgazal 951738cd3eSNetanel Belgazal #define ENA_MGMNT_IRQ_IDX 0 961738cd3eSNetanel Belgazal #define ENA_IO_IRQ_FIRST_IDX 1 971738cd3eSNetanel Belgazal #define ENA_IO_IRQ_IDX(q) (ENA_IO_IRQ_FIRST_IDX + (q)) 981738cd3eSNetanel Belgazal 994bb7f4cfSArthur Kiyanovski #define ENA_ADMIN_POLL_DELAY_US 100 1004bb7f4cfSArthur Kiyanovski 1011738cd3eSNetanel Belgazal /* ENA device should send keep alive msg every 1 sec. 1027102a18aSNetanel Belgazal * We wait for 6 sec just to be on the safe side. 1031738cd3eSNetanel Belgazal */ 1047102a18aSNetanel Belgazal #define ENA_DEVICE_KALIVE_TIMEOUT (6 * HZ) 1058510e1a3SNetanel Belgazal #define ENA_MAX_NO_INTERRUPT_ITERATIONS 3 1061738cd3eSNetanel Belgazal 1071738cd3eSNetanel Belgazal #define ENA_MMIO_DISABLE_REG_READ BIT(0) 1081738cd3eSNetanel Belgazal 109838c93dcSSameeh Jubran /* The max MTU size is configured to be the ethernet frame size without 110838c93dcSSameeh Jubran * the overhead of the ethernet header, which can have a VLAN header, and 111838c93dcSSameeh Jubran * a frame check sequence (FCS). 112838c93dcSSameeh Jubran * The buffer size we share with the device is defined to be ENA_PAGE_SIZE 113838c93dcSSameeh Jubran */ 114838c93dcSSameeh Jubran 115838c93dcSSameeh Jubran #define ENA_XDP_MAX_MTU (ENA_PAGE_SIZE - ETH_HLEN - ETH_FCS_LEN - \ 11608fc1cfdSJesper Dangaard Brouer VLAN_HLEN - XDP_PACKET_HEADROOM - \ 11708fc1cfdSJesper Dangaard Brouer SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) 118838c93dcSSameeh Jubran 119548c4940SSameeh Jubran #define ENA_IS_XDP_INDEX(adapter, index) (((index) >= (adapter)->xdp_first_ring) && \ 120548c4940SSameeh Jubran ((index) < (adapter)->xdp_first_ring + (adapter)->xdp_num_queues)) 121548c4940SSameeh Jubran 1221738cd3eSNetanel Belgazal struct ena_irq { 1231738cd3eSNetanel Belgazal irq_handler_t handler; 1241738cd3eSNetanel Belgazal void *data; 1251738cd3eSNetanel Belgazal int cpu; 1261738cd3eSNetanel Belgazal u32 vector; 1271738cd3eSNetanel Belgazal cpumask_t affinity_hint_mask; 1281738cd3eSNetanel Belgazal char name[ENA_IRQNAME_SIZE]; 1291738cd3eSNetanel Belgazal }; 1301738cd3eSNetanel Belgazal 1311738cd3eSNetanel Belgazal struct ena_napi { 132e4ac382eSShay Agroskin u8 first_interrupt ____cacheline_aligned; 133e4ac382eSShay Agroskin u8 interrupts_masked; 134e4ac382eSShay Agroskin struct napi_struct napi; 1351738cd3eSNetanel Belgazal struct ena_ring *tx_ring; 1361738cd3eSNetanel Belgazal struct ena_ring *rx_ring; 137548c4940SSameeh Jubran struct ena_ring *xdp_ring; 1381738cd3eSNetanel Belgazal u32 qid; 139282faf61SArthur Kiyanovski struct dim dim; 1401738cd3eSNetanel Belgazal }; 1411738cd3eSNetanel Belgazal 14231aa9857SSameeh Jubran struct ena_calc_queue_size_ctx { 14331aa9857SSameeh Jubran struct ena_com_dev_get_features_ctx *get_feat_ctx; 14431aa9857SSameeh Jubran struct ena_com_dev *ena_dev; 14531aa9857SSameeh Jubran struct pci_dev *pdev; 146736ce3f4SSameeh Jubran u32 tx_queue_size; 147736ce3f4SSameeh Jubran u32 rx_queue_size; 148736ce3f4SSameeh Jubran u32 max_tx_queue_size; 149736ce3f4SSameeh Jubran u32 max_rx_queue_size; 15031aa9857SSameeh Jubran u16 max_tx_sgl_size; 15131aa9857SSameeh Jubran u16 max_rx_sgl_size; 15231aa9857SSameeh Jubran }; 15331aa9857SSameeh Jubran 1541738cd3eSNetanel Belgazal struct ena_tx_buffer { 1551738cd3eSNetanel Belgazal struct sk_buff *skb; 1561738cd3eSNetanel Belgazal /* num of ena desc for this specific skb 1571738cd3eSNetanel Belgazal * (includes data desc and metadata desc) 1581738cd3eSNetanel Belgazal */ 1591738cd3eSNetanel Belgazal u32 tx_descs; 1601738cd3eSNetanel Belgazal /* num of buffers used by this skb */ 1611738cd3eSNetanel Belgazal u32 num_of_bufs; 162800c55cbSNetanel Belgazal 163548c4940SSameeh Jubran /* XDP buffer structure which is used for sending packets in 164548c4940SSameeh Jubran * the xdp queues 165548c4940SSameeh Jubran */ 166548c4940SSameeh Jubran struct xdp_frame *xdpf; 167548c4940SSameeh Jubran 16838005ca8SArthur Kiyanovski /* Indicate if bufs[0] map the linear data of the skb. */ 16938005ca8SArthur Kiyanovski u8 map_linear_data; 17038005ca8SArthur Kiyanovski 171800c55cbSNetanel Belgazal /* Used for detect missing tx packets to limit the number of prints */ 172800c55cbSNetanel Belgazal u32 print_once; 173800c55cbSNetanel Belgazal /* Save the last jiffies to detect missing tx packets 174800c55cbSNetanel Belgazal * 175800c55cbSNetanel Belgazal * sets to non zero value on ena_start_xmit and set to zero on 176800c55cbSNetanel Belgazal * napi and timer_Service_routine. 177800c55cbSNetanel Belgazal * 178800c55cbSNetanel Belgazal * while this value is not protected by lock, 179800c55cbSNetanel Belgazal * a given packet is not expected to be handled by ena_start_xmit 180800c55cbSNetanel Belgazal * and by napi/timer_service at the same time. 181800c55cbSNetanel Belgazal */ 1821738cd3eSNetanel Belgazal unsigned long last_jiffies; 1831738cd3eSNetanel Belgazal struct ena_com_buf bufs[ENA_PKT_MAX_BUFS]; 1841738cd3eSNetanel Belgazal } ____cacheline_aligned; 1851738cd3eSNetanel Belgazal 1861738cd3eSNetanel Belgazal struct ena_rx_buffer { 1871738cd3eSNetanel Belgazal struct sk_buff *skb; 1881738cd3eSNetanel Belgazal struct page *page; 1891738cd3eSNetanel Belgazal u32 page_offset; 1901738cd3eSNetanel Belgazal struct ena_com_buf ena_buf; 1911738cd3eSNetanel Belgazal } ____cacheline_aligned; 1921738cd3eSNetanel Belgazal 1931738cd3eSNetanel Belgazal struct ena_stats_tx { 1941738cd3eSNetanel Belgazal u64 cnt; 1951738cd3eSNetanel Belgazal u64 bytes; 1961738cd3eSNetanel Belgazal u64 queue_stop; 1971738cd3eSNetanel Belgazal u64 prepare_ctx_err; 1981738cd3eSNetanel Belgazal u64 queue_wakeup; 1991738cd3eSNetanel Belgazal u64 dma_mapping_err; 2001738cd3eSNetanel Belgazal u64 linearize; 2011738cd3eSNetanel Belgazal u64 linearize_failed; 2021738cd3eSNetanel Belgazal u64 napi_comp; 2031738cd3eSNetanel Belgazal u64 tx_poll; 2041738cd3eSNetanel Belgazal u64 doorbells; 2051738cd3eSNetanel Belgazal u64 bad_req_id; 20638005ca8SArthur Kiyanovski u64 llq_buffer_copy; 20711095fdbSNetanel Belgazal u64 missed_tx; 208d4a8b3bbSSameeh Jubran u64 unmask_interrupt; 209*0ee251cdSShay Agroskin u64 last_napi_jiffies; 2101738cd3eSNetanel Belgazal }; 2111738cd3eSNetanel Belgazal 2121738cd3eSNetanel Belgazal struct ena_stats_rx { 2131738cd3eSNetanel Belgazal u64 cnt; 2141738cd3eSNetanel Belgazal u64 bytes; 215d2eecc6eSSameeh Jubran u64 rx_copybreak_pkt; 216d2eecc6eSSameeh Jubran u64 csum_good; 2171738cd3eSNetanel Belgazal u64 refil_partial; 2181738cd3eSNetanel Belgazal u64 bad_csum; 2191738cd3eSNetanel Belgazal u64 page_alloc_fail; 2201738cd3eSNetanel Belgazal u64 skb_alloc_fail; 2211738cd3eSNetanel Belgazal u64 dma_mapping_err; 2221738cd3eSNetanel Belgazal u64 bad_desc_num; 223ad974baeSNetanel Belgazal u64 bad_req_id; 224a3af7c18SNetanel Belgazal u64 empty_rx_ring; 225cb36bb36SArthur Kiyanovski u64 csum_unchecked; 2264cd28b21SSameeh Jubran u64 xdp_aborted; 2274cd28b21SSameeh Jubran u64 xdp_drop; 2284cd28b21SSameeh Jubran u64 xdp_pass; 2294cd28b21SSameeh Jubran u64 xdp_tx; 2304cd28b21SSameeh Jubran u64 xdp_invalid; 231a318c70aSShay Agroskin u64 xdp_redirect; 2321738cd3eSNetanel Belgazal }; 2331738cd3eSNetanel Belgazal 2341738cd3eSNetanel Belgazal struct ena_ring { 235ad974baeSNetanel Belgazal /* Holds the empty requests for TX/RX 236ad974baeSNetanel Belgazal * out of order completions 237ad974baeSNetanel Belgazal */ 238f9172498SSameeh Jubran u16 *free_ids; 239ad974baeSNetanel Belgazal 2401738cd3eSNetanel Belgazal union { 2411738cd3eSNetanel Belgazal struct ena_tx_buffer *tx_buffer_info; 2421738cd3eSNetanel Belgazal struct ena_rx_buffer *rx_buffer_info; 2431738cd3eSNetanel Belgazal }; 2441738cd3eSNetanel Belgazal 2451738cd3eSNetanel Belgazal /* cache ptr to avoid using the adapter */ 2461738cd3eSNetanel Belgazal struct device *dev; 2471738cd3eSNetanel Belgazal struct pci_dev *pdev; 2481738cd3eSNetanel Belgazal struct napi_struct *napi; 2491738cd3eSNetanel Belgazal struct net_device *netdev; 2501738cd3eSNetanel Belgazal struct ena_com_dev *ena_dev; 2511738cd3eSNetanel Belgazal struct ena_adapter *adapter; 2521738cd3eSNetanel Belgazal struct ena_com_io_cq *ena_com_io_cq; 2531738cd3eSNetanel Belgazal struct ena_com_io_sq *ena_com_io_sq; 254838c93dcSSameeh Jubran struct bpf_prog *xdp_bpf_prog; 255838c93dcSSameeh Jubran struct xdp_rxq_info xdp_rxq; 256f1a25589SShay Agroskin spinlock_t xdp_tx_lock; /* synchronize XDP TX/Redirect traffic */ 257e4ac382eSShay Agroskin /* Used for rx queues only to point to the xdp tx ring, to 258e4ac382eSShay Agroskin * which traffic should be redirected from this rx ring. 259e4ac382eSShay Agroskin */ 260e4ac382eSShay Agroskin struct ena_ring *xdp_ring; 2611738cd3eSNetanel Belgazal 2621738cd3eSNetanel Belgazal u16 next_to_use; 2631738cd3eSNetanel Belgazal u16 next_to_clean; 2641738cd3eSNetanel Belgazal u16 rx_copybreak; 265838c93dcSSameeh Jubran u16 rx_headroom; 2661738cd3eSNetanel Belgazal u16 qid; 2671738cd3eSNetanel Belgazal u16 mtu; 2681738cd3eSNetanel Belgazal u16 sgl_size; 2691738cd3eSNetanel Belgazal 2701738cd3eSNetanel Belgazal /* The maximum header length the device can handle */ 2711738cd3eSNetanel Belgazal u8 tx_max_header_size; 2721738cd3eSNetanel Belgazal 2730e3a3f6dSArthur Kiyanovski bool disable_meta_caching; 2748510e1a3SNetanel Belgazal u16 no_interrupt_event_cnt; 2758510e1a3SNetanel Belgazal 2761738cd3eSNetanel Belgazal /* cpu for TPH */ 2771738cd3eSNetanel Belgazal int cpu; 2781738cd3eSNetanel Belgazal /* number of tx/rx_buffer_info's entries */ 2791738cd3eSNetanel Belgazal int ring_size; 2801738cd3eSNetanel Belgazal 2811738cd3eSNetanel Belgazal enum ena_admin_placement_policy_type tx_mem_queue_type; 2821738cd3eSNetanel Belgazal 2831738cd3eSNetanel Belgazal struct ena_com_rx_buf_info ena_bufs[ENA_PKT_MAX_BUFS]; 2841738cd3eSNetanel Belgazal u32 smoothed_interval; 2851738cd3eSNetanel Belgazal u32 per_napi_packets; 286282faf61SArthur Kiyanovski u16 non_empty_napi_events; 2871738cd3eSNetanel Belgazal struct u64_stats_sync syncp; 2881738cd3eSNetanel Belgazal union { 2891738cd3eSNetanel Belgazal struct ena_stats_tx tx_stats; 2901738cd3eSNetanel Belgazal struct ena_stats_rx rx_stats; 2911738cd3eSNetanel Belgazal }; 29238005ca8SArthur Kiyanovski 29338005ca8SArthur Kiyanovski u8 *push_buf_intermediate_buf; 294a3af7c18SNetanel Belgazal int empty_rx_queue; 2951738cd3eSNetanel Belgazal } ____cacheline_aligned; 2961738cd3eSNetanel Belgazal 2971738cd3eSNetanel Belgazal struct ena_stats_dev { 2981738cd3eSNetanel Belgazal u64 tx_timeout; 2998c5c7abdSNetanel Belgazal u64 suspend; 3008c5c7abdSNetanel Belgazal u64 resume; 3011738cd3eSNetanel Belgazal u64 wd_expired; 3021738cd3eSNetanel Belgazal u64 interface_up; 3031738cd3eSNetanel Belgazal u64 interface_down; 3041738cd3eSNetanel Belgazal u64 admin_q_pause; 305d81db240SNetanel Belgazal u64 rx_drops; 3065c665f8cSSameeh Jubran u64 tx_drops; 3071738cd3eSNetanel Belgazal }; 3081738cd3eSNetanel Belgazal 3091738cd3eSNetanel Belgazal enum ena_flags_t { 3101738cd3eSNetanel Belgazal ENA_FLAG_DEVICE_RUNNING, 3111738cd3eSNetanel Belgazal ENA_FLAG_DEV_UP, 3121738cd3eSNetanel Belgazal ENA_FLAG_LINK_UP, 31306443684SNetanel Belgazal ENA_FLAG_MSIX_ENABLED, 314d18e4f68SNetanel Belgazal ENA_FLAG_TRIGGER_RESET, 315d18e4f68SNetanel Belgazal ENA_FLAG_ONGOING_RESET 3161738cd3eSNetanel Belgazal }; 3171738cd3eSNetanel Belgazal 3181738cd3eSNetanel Belgazal /* adapter specific private data structure */ 3191738cd3eSNetanel Belgazal struct ena_adapter { 3201738cd3eSNetanel Belgazal struct ena_com_dev *ena_dev; 3211738cd3eSNetanel Belgazal /* OS defined structs */ 3221738cd3eSNetanel Belgazal struct net_device *netdev; 3231738cd3eSNetanel Belgazal struct pci_dev *pdev; 3241738cd3eSNetanel Belgazal 3251738cd3eSNetanel Belgazal /* rx packets that shorter that this len will be copied to the skb 3261738cd3eSNetanel Belgazal * header 3271738cd3eSNetanel Belgazal */ 3281738cd3eSNetanel Belgazal u32 rx_copybreak; 3291738cd3eSNetanel Belgazal u32 max_mtu; 3301738cd3eSNetanel Belgazal 331736ce3f4SSameeh Jubran u32 num_io_queues; 332736ce3f4SSameeh Jubran u32 max_num_io_queues; 3331738cd3eSNetanel Belgazal 3341738cd3eSNetanel Belgazal int msix_vecs; 3351738cd3eSNetanel Belgazal 33682ef30f1SNetanel Belgazal u32 missing_tx_completion_threshold; 33782ef30f1SNetanel Belgazal 33813ca32a6SSameeh Jubran u32 requested_tx_ring_size; 33913ca32a6SSameeh Jubran u32 requested_rx_ring_size; 3401738cd3eSNetanel Belgazal 34131aa9857SSameeh Jubran u32 max_tx_ring_size; 34231aa9857SSameeh Jubran u32 max_rx_ring_size; 34331aa9857SSameeh Jubran 3441738cd3eSNetanel Belgazal u32 msg_enable; 3451738cd3eSNetanel Belgazal 3461738cd3eSNetanel Belgazal u16 max_tx_sgl_size; 3471738cd3eSNetanel Belgazal u16 max_rx_sgl_size; 3481738cd3eSNetanel Belgazal 3491738cd3eSNetanel Belgazal u8 mac_addr[ETH_ALEN]; 3501738cd3eSNetanel Belgazal 35182ef30f1SNetanel Belgazal unsigned long keep_alive_timeout; 35282ef30f1SNetanel Belgazal unsigned long missing_tx_completion_to; 35382ef30f1SNetanel Belgazal 3541738cd3eSNetanel Belgazal char name[ENA_NAME_MAX_LEN]; 3551738cd3eSNetanel Belgazal 3561738cd3eSNetanel Belgazal unsigned long flags; 3571738cd3eSNetanel Belgazal /* TX */ 3581738cd3eSNetanel Belgazal struct ena_ring tx_ring[ENA_MAX_NUM_IO_QUEUES] 3591738cd3eSNetanel Belgazal ____cacheline_aligned_in_smp; 3601738cd3eSNetanel Belgazal 3611738cd3eSNetanel Belgazal /* RX */ 3621738cd3eSNetanel Belgazal struct ena_ring rx_ring[ENA_MAX_NUM_IO_QUEUES] 3631738cd3eSNetanel Belgazal ____cacheline_aligned_in_smp; 3641738cd3eSNetanel Belgazal 3651738cd3eSNetanel Belgazal struct ena_napi ena_napi[ENA_MAX_NUM_IO_QUEUES]; 3661738cd3eSNetanel Belgazal 3671738cd3eSNetanel Belgazal struct ena_irq irq_tbl[ENA_MAX_MSIX_VEC(ENA_MAX_NUM_IO_QUEUES)]; 3681738cd3eSNetanel Belgazal 3691738cd3eSNetanel Belgazal /* timer service */ 3701738cd3eSNetanel Belgazal struct work_struct reset_task; 3711738cd3eSNetanel Belgazal struct timer_list timer_service; 3721738cd3eSNetanel Belgazal 3731738cd3eSNetanel Belgazal bool wd_state; 3748c5c7abdSNetanel Belgazal bool dev_up_before_reset; 3750e3a3f6dSArthur Kiyanovski bool disable_meta_caching; 3761738cd3eSNetanel Belgazal unsigned long last_keep_alive_jiffies; 3771738cd3eSNetanel Belgazal 3781738cd3eSNetanel Belgazal struct u64_stats_sync syncp; 3791738cd3eSNetanel Belgazal struct ena_stats_dev dev_stats; 380713865daSSameeh Jubran struct ena_admin_eni_stats eni_stats; 381713865daSSameeh Jubran bool eni_stats_supported; 3821738cd3eSNetanel Belgazal 3831738cd3eSNetanel Belgazal /* last queue index that was checked for uncompleted tx packets */ 3841738cd3eSNetanel Belgazal u32 last_monitored_tx_qid; 385e2eed0e3SNetanel Belgazal 386e2eed0e3SNetanel Belgazal enum ena_regs_reset_reason_types reset_reason; 387838c93dcSSameeh Jubran 388838c93dcSSameeh Jubran struct bpf_prog *xdp_bpf_prog; 389548c4940SSameeh Jubran u32 xdp_first_ring; 390548c4940SSameeh Jubran u32 xdp_num_queues; 3911738cd3eSNetanel Belgazal }; 3921738cd3eSNetanel Belgazal 3931738cd3eSNetanel Belgazal void ena_set_ethtool_ops(struct net_device *netdev); 3941738cd3eSNetanel Belgazal 3951738cd3eSNetanel Belgazal void ena_dump_stats_to_dmesg(struct ena_adapter *adapter); 3961738cd3eSNetanel Belgazal 3971738cd3eSNetanel Belgazal void ena_dump_stats_to_buf(struct ena_adapter *adapter, u8 *buf); 3981738cd3eSNetanel Belgazal 399713865daSSameeh Jubran int ena_update_hw_stats(struct ena_adapter *adapter); 400713865daSSameeh Jubran 401eece4d2aSSameeh Jubran int ena_update_queue_sizes(struct ena_adapter *adapter, 402eece4d2aSSameeh Jubran u32 new_tx_size, 403eece4d2aSSameeh Jubran u32 new_rx_size); 404838c93dcSSameeh Jubran 4052413ea97SSameeh Jubran int ena_update_queue_count(struct ena_adapter *adapter, u32 new_channel_count); 406eece4d2aSSameeh Jubran 4071738cd3eSNetanel Belgazal int ena_get_sset_count(struct net_device *netdev, int sset); 4081738cd3eSNetanel Belgazal 409548c4940SSameeh Jubran enum ena_xdp_errors_t { 410548c4940SSameeh Jubran ENA_XDP_ALLOWED = 0, 411548c4940SSameeh Jubran ENA_XDP_CURRENT_MTU_TOO_LARGE, 412548c4940SSameeh Jubran ENA_XDP_NO_ENOUGH_QUEUES, 413548c4940SSameeh Jubran }; 414548c4940SSameeh Jubran 415838c93dcSSameeh Jubran static inline bool ena_xdp_present(struct ena_adapter *adapter) 416838c93dcSSameeh Jubran { 417838c93dcSSameeh Jubran return !!adapter->xdp_bpf_prog; 418838c93dcSSameeh Jubran } 419838c93dcSSameeh Jubran 420838c93dcSSameeh Jubran static inline bool ena_xdp_present_ring(struct ena_ring *ring) 421838c93dcSSameeh Jubran { 422838c93dcSSameeh Jubran return !!ring->xdp_bpf_prog; 423838c93dcSSameeh Jubran } 424838c93dcSSameeh Jubran 4251e584739SShay Agroskin static inline bool ena_xdp_legal_queue_count(struct ena_adapter *adapter, 426548c4940SSameeh Jubran u32 queues) 427838c93dcSSameeh Jubran { 428548c4940SSameeh Jubran return 2 * queues <= adapter->max_num_io_queues; 429548c4940SSameeh Jubran } 430548c4940SSameeh Jubran 431548c4940SSameeh Jubran static inline enum ena_xdp_errors_t ena_xdp_allowed(struct ena_adapter *adapter) 432548c4940SSameeh Jubran { 433548c4940SSameeh Jubran enum ena_xdp_errors_t rc = ENA_XDP_ALLOWED; 434548c4940SSameeh Jubran 435548c4940SSameeh Jubran if (adapter->netdev->mtu > ENA_XDP_MAX_MTU) 436548c4940SSameeh Jubran rc = ENA_XDP_CURRENT_MTU_TOO_LARGE; 437548c4940SSameeh Jubran else if (!ena_xdp_legal_queue_count(adapter, adapter->num_io_queues)) 438548c4940SSameeh Jubran rc = ENA_XDP_NO_ENOUGH_QUEUES; 439548c4940SSameeh Jubran 440548c4940SSameeh Jubran return rc; 441838c93dcSSameeh Jubran } 442838c93dcSSameeh Jubran 4431738cd3eSNetanel Belgazal #endif /* !(ENA_H) */ 444