/*-
* BSD LICENSE
*
* Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: head/sys/dev/ena/ena.h 333450 2018-05-10 09:06:21Z mw $
*
*/
#define TX_COMMIT 32
/*
* TX budget for cleaning. It should be half of the RX budget to reduce amount
* of TCP retransmissions.
*/
#define TX_BUDGET 128
/* RX cleanup budget. -1 stands for infinity. */
#define RX_BUDGET 256
/*
* How many times we can repeat cleanup in the io irq handling routine if the
* RX or TX budget was depleted.
*/
#define CLEAN_BUDGET 8
struct ena_tx_buffer {
struct mbuf *mbuf;
/* # of ena desc for this specific mbuf
* (includes data desc and metadata desc) */
unsigned int tx_descs;
/* # of buffers used by this mbuf */
unsigned int num_of_bufs;
bus_dmamap_t map;
/* Used to detect missing tx packets */
struct bintime timestamp;
bool print_once;
/*
* Locking notes:
* + For TX, a field in ena_ring is protected by ring_mtx (a spin mutex).
* - protect them only when I/F is up.
* - when I/F is down or attaching, detaching, no need to protect them.
* + For RX, a field "stopping" is protected by ring_mtx (a spin mutex).
* - other fields in ena_ring are not protected.
* + a fields in ena_adapter is protected by global_mtx (a adaptive mutex).
*
* + a field marked "stable" is unlocked.
* + a field marked "atomic" is unlocked,
* but must use atomic ops to read/write.
*
* Lock order:
* + global_mtx -> ring_mtx
*/
struct ena_ring {
/* Holds the empty requests for TX/RX out of order completions */
union {
uint16_t *free_tx_ids;
uint16_t *free_rx_ids;
};
struct ena_com_dev *ena_dev;
struct ena_adapter *adapter;
struct ena_com_io_cq *ena_com_io_cq;
struct ena_com_io_sq *ena_com_io_sq;
uint16_t qid;
/* Determines if device will use LLQ or normal mode for TX */
enum ena_admin_placement_policy_type tx_mem_queue_type;
/* The maximum length the driver can push to the device (For LLQ) */
uint8_t tx_max_header_size;
/*
* Fields used for Adaptive Interrupt Modulation - to be implemented in
* the future releases
*/
uint32_t smoothed_interval;
enum ena_intr_moder_level moder_tbl_idx;
union {
struct ena_tx_buffer *tx_buffer_info; /* context of tx packet */
struct ena_rx_buffer *rx_buffer_info; /* context of rx packet */
};
int ring_size; /* number of tx/rx_buffer_info's entries */
pcq_t *br; /* only for TX */
kmutex_t ring_mtx;
char mtx_name[16];
union {
struct {
struct work enqueue_task;
struct workqueue *enqueue_tq;
};
struct {
struct work cleanup_task;
struct workqueue *cleanup_tq;
};
};
u_int task_pending; /* atomic */
bool stopping;
union {
struct ena_stats_tx tx_stats;
struct ena_stats_rx rx_stats;
};