History

Merge branch 'ena-dynamic-queue-sizes'

Sameeh Jubran says: ==================== Support for dynamic queue size changes This patchset introduces the following: * add new admin command for supporting different queue size for Tx/Rx * add support for Tx/Rx queues size modification through ethtool * allow queues allocation backoff when low on memory * update driver version Difference from v2: * Dropped superfluous range checks which are already done in ethtool. [patch 5/7] * Dropped inline keyword from function. [patch 4/7] * Added a new patch which drops inline keyword all *.c files. [patch 6/7] Difference from v1: * Changed ena_update_queue_sizes() signature to use u32 instead of int type for the size arguments. [patch 5/7] ====================

David S. Miller committed 7 years ago

Commit e0ffbd32 parents f2dec9a dbbc6e67 files · +403 −143Browse files

Unified · Split

7 files
  1. drivers/net/ethernet/amazon/ena/ena_admin_defs.h +54 −2
  2. drivers/net/ethernet/amazon/ena/ena_com.c +51 −31
  3. drivers/net/ethernet/amazon/ena/ena_com.h +3 −0
  4. drivers/net/ethernet/amazon/ena/ena_eth_com.c +13 −13
  5. drivers/net/ethernet/amazon/ena/ena_ethtool.c +26 −6
  6. drivers/net/ethernet/amazon/ena/ena_netdev.c +232 −87
  7. drivers/net/ethernet/amazon/ena/ena_netdev.h +24 −4
drivers/net/ethernet/amazon/ena/ena_admin_defs.h+54−2
@@ -64,6 +64,7 @@ enum ena_admin_aq_feature_id { · 63 unmodified lines
6464 ENA_ADMIN_LLQ = 4,
6565 ENA_ADMIN_EXTRA_PROPERTIES_STRINGS = 5,
6666 ENA_ADMIN_EXTRA_PROPERTIES_FLAGS = 6,
67+ ENA_ADMIN_MAX_QUEUES_EXT = 7,
6768 ENA_ADMIN_RSS_HASH_FUNCTION = 10,
6869 ENA_ADMIN_STATELESS_OFFLOAD_CONFIG = 11,
6970 ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG = 12,
@@ -425,7 +426,13 @@ struct ena_admin_get_set_feature_common_desc { · 355 unmodified lines
425426 /* as appears in ena_admin_aq_feature_id */
426427 u8 feature_id;
427428
428− u16 reserved16;
429+ /* The driver specifies the max feature version it supports and the
430+ * device responds with the currently supported feature version. The
431+ * field is zero based
432+ */
433+ u8 feature_version;
434+
435+ u8 reserved8;
429436 };
430437
431438 struct ena_admin_device_attr_feature_desc {
@@ -535,6 +542,34 @@ struct ena_admin_feature_llq_desc { · 103 unmodified lines
535542 u32 max_tx_burst_size;
536543 };
537544
545+struct ena_admin_queue_ext_feature_fields {
546+ u32 max_tx_sq_num;
547+
548+ u32 max_tx_cq_num;
549+
550+ u32 max_rx_sq_num;
551+
552+ u32 max_rx_cq_num;
553+
554+ u32 max_tx_sq_depth;
555+
556+ u32 max_tx_cq_depth;
557+
558+ u32 max_rx_sq_depth;
559+
560+ u32 max_rx_cq_depth;
561+
562+ u32 max_tx_header_size;
563+
564+ /* Maximum Descriptors number, including meta descriptor, allowed for
565+ * a single Tx packet
566+ */
567+ u16 max_per_packet_tx_descs;
568+
569+ /* Maximum Descriptors number allowed for a single Rx packet */
570+ u16 max_per_packet_rx_descs;
571+};
572+
538573 struct ena_admin_queue_feature_desc {
539574 u32 max_sq_num;
540575
@@ -849,6 +884,19 @@ struct ena_admin_get_feat_cmd { · 308 unmodified lines
849884 u32 raw[11];
850885 };
851886
887+struct ena_admin_queue_ext_feature_desc {
888+ /* version */
889+ u8 version;
890+
891+ u8 reserved1[3];
892+
893+ union {
894+ struct ena_admin_queue_ext_feature_fields max_queue_ext;
895+
896+ u32 raw[10];
897+ };
898+};
899+
852900 struct ena_admin_get_feat_resp {
853901 struct ena_admin_acq_common_desc acq_common_desc;
854902
@@ -861,6 +909,8 @@ struct ena_admin_get_feat_resp { · 6 unmodified lines
861909
862910 struct ena_admin_queue_feature_desc max_queue;
863911
912+ struct ena_admin_queue_ext_feature_desc max_queue_ext;
913+
864914 struct ena_admin_feature_aenq_desc aenq;
865915
866916 struct ena_admin_get_feature_link_desc link;
@@ -929,7 +979,9 @@ struct ena_admin_aenq_common_desc { · 62 unmodified lines
929979
930980 u16 syndrom;
931981
932− /* 0 : phase */
982+ /* 0 : phase
983+ * 7:1 : reserved - MBZ
984+ */
933985 u8 flags;
934986
935987 u8 reserved1[3];
drivers/net/ethernet/amazon/ena/ena_com.c+51−31
@@ -91,7 +91,7 @@ struct ena_com_stats_ctx { · 90 unmodified lines
9191 struct ena_admin_acq_get_stats_resp get_resp;
9292 };
9393
94−static inline int ena_com_mem_addr_set(struct ena_com_dev *ena_dev,
94+static int ena_com_mem_addr_set(struct ena_com_dev *ena_dev,
9595 struct ena_common_mem_addr *ena_addr,
9696 dma_addr_t addr)
9797 {
@@ -190,7 +190,7 @@ static int ena_com_admin_init_aenq(struct ena_com_dev *dev, · 92 unmodified lines
190190 return 0;
191191 }
192192
193−static inline void comp_ctxt_release(struct ena_com_admin_queue *queue,
193+static void comp_ctxt_release(struct ena_com_admin_queue *queue,
194194 struct ena_comp_ctx *comp_ctx)
195195 {
196196 comp_ctx->occupied = false;
@@ -277,7 +277,7 @@ static struct ena_comp_ctx *__ena_com_submit_admin_cmd(struct ena_com_admin_queu · 80 unmodified lines
277277 return comp_ctx;
278278 }
279279
280−static inline int ena_com_init_comp_ctxt(struct ena_com_admin_queue *queue)
280+static int ena_com_init_comp_ctxt(struct ena_com_admin_queue *queue)
281281 {
282282 size_t size = queue->q_depth * sizeof(struct ena_comp_ctx);
283283 struct ena_comp_ctx *comp_ctx;
@@ -978,7 +978,8 @@ static int ena_com_get_feature_ex(struct ena_com_dev *ena_dev, · 694 unmodified lines
978978 struct ena_admin_get_feat_resp *get_resp,
979979 enum ena_admin_aq_feature_id feature_id,
980980 dma_addr_t control_buf_dma_addr,
981− u32 control_buff_size)
981+ u32 control_buff_size,
982+ u8 feature_ver)
982983 {
983984 struct ena_com_admin_queue *admin_queue;
984985 struct ena_admin_get_feat_cmd get_cmd;
@@ -1009,7 +1010,7 @@ static int ena_com_get_feature_ex(struct ena_com_dev *ena_dev, · 24 unmodified lines
10091010 }
10101011
10111012 get_cmd.control_buffer.length = control_buff_size;
1012−
1013+ get_cmd.feat_common.feature_version = feature_ver;
10131014 get_cmd.feat_common.feature_id = feature_id;
10141015
10151016 ret = ena_com_execute_admin_command(admin_queue,
@@ -1029,13 +1030,15 @@ static int ena_com_get_feature_ex(struct ena_com_dev *ena_dev, · 13 unmodified lines
10291030
10301031 static int ena_com_get_feature(struct ena_com_dev *ena_dev,
10311032 struct ena_admin_get_feat_resp *get_resp,
1032− enum ena_admin_aq_feature_id feature_id)
1033+ enum ena_admin_aq_feature_id feature_id,
1034+ u8 feature_ver)
10331035 {
10341036 return ena_com_get_feature_ex(ena_dev,
10351037 get_resp,
10361038 feature_id,
10371039 0,
1038− 0);
1040+ 0,
1041+ feature_ver);
10391042 }
10401043
10411044 static int ena_com_hash_key_allocate(struct ena_com_dev *ena_dev)
@@ -1095,7 +1098,7 @@ static int ena_com_indirect_table_allocate(struct ena_com_dev *ena_dev, · 53 unmodified lines
10951098 int ret;
10961099
10971100 ret = ena_com_get_feature(ena_dev, &get_resp,
1098− ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
1101+ ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG, 0);
10991102 if (unlikely(ret))
11001103 return ret;
11011104
@@ -1515,7 +1518,7 @@ int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag) · 413 unmodified lines
15151518 struct ena_admin_get_feat_resp get_resp;
15161519 int ret;
15171520
1518− ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_AENQ_CONFIG);
1521+ ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_AENQ_CONFIG, 0);
15191522 if (ret) {
15201523 pr_info("Can't get aenq configuration\n");
15211524 return ret;
@@ -1890,7 +1893,7 @@ void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid) · 368 unmodified lines
18901893 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
18911894 struct ena_admin_get_feat_resp *resp)
18921895 {
1893− return ena_com_get_feature(ena_dev, resp, ENA_ADMIN_LINK_CONFIG);
1896+ return ena_com_get_feature(ena_dev, resp, ENA_ADMIN_LINK_CONFIG, 0);
18941897 }
18951898
18961899 int ena_com_extra_properties_strings_init(struct ena_com_dev *ena_dev)
@@ -1916,7 +1919,7 @@ int ena_com_extra_properties_strings_init(struct ena_com_dev *ena_dev) · 19 unmodified lines
19161919 rc = ena_com_get_feature_ex(ena_dev, &resp,
19171920 ENA_ADMIN_EXTRA_PROPERTIES_STRINGS,
19181921 extra_properties_strings->dma_addr,
1919− extra_properties_strings->size);
1922+ extra_properties_strings->size, 0);
19201923 if (rc) {
19211924 pr_debug("Failed to get extra properties strings\n");
19221925 goto err;
@@ -1946,7 +1949,7 @@ int ena_com_get_extra_properties_flags(struct ena_com_dev *ena_dev, · 23 unmodified lines
19461949 struct ena_admin_get_feat_resp *resp)
19471950 {
19481951 return ena_com_get_feature(ena_dev, resp,
1949− ENA_ADMIN_EXTRA_PROPERTIES_FLAGS);
1952+ ENA_ADMIN_EXTRA_PROPERTIES_FLAGS, 0);
19501953 }
19511954
19521955 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
@@ -1956,7 +1959,7 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, · 3 unmodified lines
19561959 int rc;
19571960
19581961 rc = ena_com_get_feature(ena_dev, &get_resp,
1959− ENA_ADMIN_DEVICE_ATTRIBUTES);
1962+ ENA_ADMIN_DEVICE_ATTRIBUTES, 0);
19601963 if (rc)
19611964 return rc;
19621965
@@ -1964,17 +1967,34 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, · 1 unmodified line
19641967 sizeof(get_resp.u.dev_attr));
19651968 ena_dev->supported_features = get_resp.u.dev_attr.supported_features;
19661969
1967− rc = ena_com_get_feature(ena_dev, &get_resp,
1968− ENA_ADMIN_MAX_QUEUES_NUM);
1969− if (rc)
1970− return rc;
1970+ if (ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) {
1971+ rc = ena_com_get_feature(ena_dev, &get_resp,
1972+ ENA_ADMIN_MAX_QUEUES_EXT,
1973+ ENA_FEATURE_MAX_QUEUE_EXT_VER);
1974+ if (rc)
1975+ return rc;
19711976
1972− memcpy(&get_feat_ctx->max_queues, &get_resp.u.max_queue,
1973− sizeof(get_resp.u.max_queue));
1974− ena_dev->tx_max_header_size = get_resp.u.max_queue.max_header_size;
1977+ if (get_resp.u.max_queue_ext.version != ENA_FEATURE_MAX_QUEUE_EXT_VER)
1978+ return -EINVAL;
1979+
1980+ memcpy(&get_feat_ctx->max_queue_ext, &get_resp.u.max_queue_ext,
1981+ sizeof(get_resp.u.max_queue_ext));
1982+ ena_dev->tx_max_header_size =
1983+ get_resp.u.max_queue_ext.max_queue_ext.max_tx_header_size;
1984+ } else {
1985+ rc = ena_com_get_feature(ena_dev, &get_resp,
1986+ ENA_ADMIN_MAX_QUEUES_NUM, 0);
1987+ memcpy(&get_feat_ctx->max_queues, &get_resp.u.max_queue,
1988+ sizeof(get_resp.u.max_queue));
1989+ ena_dev->tx_max_header_size =
1990+ get_resp.u.max_queue.max_header_size;
1991+
1992+ if (rc)
1993+ return rc;
1994+ }
19751995
19761996 rc = ena_com_get_feature(ena_dev, &get_resp,
1977− ENA_ADMIN_AENQ_CONFIG);
1997+ ENA_ADMIN_AENQ_CONFIG, 0);
19781998 if (rc)
19791999 return rc;
19802000
@@ -1982,7 +2002,7 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, · 1 unmodified line
19822002 sizeof(get_resp.u.aenq));
19832003
19842004 rc = ena_com_get_feature(ena_dev, &get_resp,
1985− ENA_ADMIN_STATELESS_OFFLOAD_CONFIG);
2005+ ENA_ADMIN_STATELESS_OFFLOAD_CONFIG, 0);
19862006 if (rc)
19872007 return rc;
19882008
@@ -1992,7 +2012,7 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, · 3 unmodified lines
19922012 /* Driver hints isn't mandatory admin command. So in case the
19932013 * command isn't supported set driver hints to 0
19942014 */
1995− rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_HW_HINTS);
2015+ rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_HW_HINTS, 0);
19962016
19972017 if (!rc)
19982018 memcpy(&get_feat_ctx->hw_hints, &get_resp.u.hw_hints,
@@ -2003,7 +2023,7 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, · 4 unmodified lines
20032023 else
20042024 return rc;
20052025
2006− rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_LLQ);
2026+ rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_LLQ, 0);
20072027 if (!rc)
20082028 memcpy(&get_feat_ctx->llq, &get_resp.u.llq,
20092029 sizeof(get_resp.u.llq));
@@ -2240,7 +2260,7 @@ int ena_com_get_offload_settings(struct ena_com_dev *ena_dev, · 230 unmodified lines
22402260 struct ena_admin_get_feat_resp resp;
22412261
22422262 ret = ena_com_get_feature(ena_dev, &resp,
2243− ENA_ADMIN_STATELESS_OFFLOAD_CONFIG);
2263+ ENA_ADMIN_STATELESS_OFFLOAD_CONFIG, 0);
22442264 if (unlikely(ret)) {
22452265 pr_err("Failed to get offload capabilities %d\n", ret);
22462266 return ret;
@@ -2269,7 +2289,7 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev) · 22 unmodified lines
22692289
22702290 /* Validate hash function is supported */
22712291 ret = ena_com_get_feature(ena_dev, &get_resp,
2272− ENA_ADMIN_RSS_HASH_FUNCTION);
2292+ ENA_ADMIN_RSS_HASH_FUNCTION, 0);
22732293 if (unlikely(ret))
22742294 return ret;
22752295
@@ -2329,7 +2349,7 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev, · 53 unmodified lines
23292349 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
23302350 ENA_ADMIN_RSS_HASH_FUNCTION,
23312351 rss->hash_key_dma_addr,
2332− sizeof(*rss->hash_key));
2352+ sizeof(*rss->hash_key), 0);
23332353 if (unlikely(rc))
23342354 return rc;
23352355
@@ -2381,7 +2401,7 @@ int ena_com_get_hash_function(struct ena_com_dev *ena_dev, · 45 unmodified lines
23812401 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
23822402 ENA_ADMIN_RSS_HASH_FUNCTION,
23832403 rss->hash_key_dma_addr,
2384− sizeof(*rss->hash_key));
2404+ sizeof(*rss->hash_key), 0);
23852405 if (unlikely(rc))
23862406 return rc;
23872407
@@ -2406,7 +2426,7 @@ int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev, · 18 unmodified lines
24062426 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
24072427 ENA_ADMIN_RSS_HASH_INPUT,
24082428 rss->hash_ctrl_dma_addr,
2409− sizeof(*rss->hash_ctrl));
2429+ sizeof(*rss->hash_ctrl), 0);
24102430 if (unlikely(rc))
24112431 return rc;
24122432
@@ -2642,7 +2662,7 @@ int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl) · 229 unmodified lines
26422662 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
26432663 ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG,
26442664 rss->rss_ind_tbl_dma_addr,
2645− tbl_size);
2665+ tbl_size, 0);
26462666 if (unlikely(rc))
26472667 return rc;
26482668
@@ -2857,7 +2877,7 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev) · 208 unmodified lines
28572877 int rc;
28582878
28592879 rc = ena_com_get_feature(ena_dev, &get_resp,
2860− ENA_ADMIN_INTERRUPT_MODERATION);
2880+ ENA_ADMIN_INTERRUPT_MODERATION, 0);
28612881
28622882 if (rc) {
28632883 if (rc == -EOPNOTSUPP) {
drivers/net/ethernet/amazon/ena/ena_com.h+3−0
@@ -101,6 +101,8 @@ · 100 unmodified lines
101101
102102 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
103103
104+#define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
105+
104106 enum ena_intr_moder_level {
105107 ENA_INTR_MODER_LOWEST = 0,
106108 ENA_INTR_MODER_LOW,
@@ -389,6 +391,7 @@ struct ena_com_dev { · 282 unmodified lines
389391
390392 struct ena_com_dev_get_features_ctx {
391393 struct ena_admin_queue_feature_desc max_queues;
394+ struct ena_admin_queue_ext_feature_desc max_queue_ext;
392395 struct ena_admin_device_attr_feature_desc dev_attr;
393396 struct ena_admin_feature_aenq_desc aenq;
394397 struct ena_admin_feature_offload_desc offload;
drivers/net/ethernet/amazon/ena/ena_eth_com.c+13−13
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232
3333 #include "ena_eth_com.h"
3434
35−static inline struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc(
35+static struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc(
3636 struct ena_com_io_cq *io_cq)
3737 {
3838 struct ena_eth_io_rx_cdesc_base *cdesc;
@@ -59,7 +59,7 @@ static inline struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc( · 20 unmodified lines
5959 return cdesc;
6060 }
6161
62−static inline void *get_sq_desc_regular_queue(struct ena_com_io_sq *io_sq)
62+static void *get_sq_desc_regular_queue(struct ena_com_io_sq *io_sq)
6363 {
6464 u16 tail_masked;
6565 u32 offset;
@@ -71,7 +71,7 @@ static inline void *get_sq_desc_regular_queue(struct ena_com_io_sq *io_sq) · 5 unmodified lines
7171 return (void *)((uintptr_t)io_sq->desc_addr.virt_addr + offset);
7272 }
7373
74−static inline int ena_com_write_bounce_buffer_to_dev(struct ena_com_io_sq *io_sq,
74+static int ena_com_write_bounce_buffer_to_dev(struct ena_com_io_sq *io_sq,
7575 u8 *bounce_buffer)
7676 {
7777 struct ena_com_llq_info *llq_info = &io_sq->llq_info;
@@ -111,7 +111,7 @@ static inline int ena_com_write_bounce_buffer_to_dev(struct ena_com_io_sq *io_sq · 33 unmodified lines
111111 return 0;
112112 }
113113
114−static inline int ena_com_write_header_to_bounce(struct ena_com_io_sq *io_sq,
114+static int ena_com_write_header_to_bounce(struct ena_com_io_sq *io_sq,
115115 u8 *header_src,
116116 u16 header_len)
117117 {
@@ -142,7 +142,7 @@ static inline int ena_com_write_header_to_bounce(struct ena_com_io_sq *io_sq, · 24 unmodified lines
142142 return 0;
143143 }
144144
145−static inline void *get_sq_desc_llq(struct ena_com_io_sq *io_sq)
145+static void *get_sq_desc_llq(struct ena_com_io_sq *io_sq)
146146 {
147147 struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
148148 u8 *bounce_buffer;
@@ -162,7 +162,7 @@ static inline void *get_sq_desc_llq(struct ena_com_io_sq *io_sq) · 13 unmodified lines
162162 return sq_desc;
163163 }
164164
165−static inline int ena_com_close_bounce_buffer(struct ena_com_io_sq *io_sq)
165+static int ena_com_close_bounce_buffer(struct ena_com_io_sq *io_sq)
166166 {
167167 struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
168168 struct ena_com_llq_info *llq_info = &io_sq->llq_info;
@@ -189,7 +189,7 @@ static inline int ena_com_close_bounce_buffer(struct ena_com_io_sq *io_sq) · 20 unmodified lines
189189 return 0;
190190 }
191191
192−static inline void *get_sq_desc(struct ena_com_io_sq *io_sq)
192+static void *get_sq_desc(struct ena_com_io_sq *io_sq)
193193 {
194194 if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
195195 return get_sq_desc_llq(io_sq);
@@ -197,7 +197,7 @@ static inline void *get_sq_desc(struct ena_com_io_sq *io_sq) · 1 unmodified line
197197 return get_sq_desc_regular_queue(io_sq);
198198 }
199199
200−static inline int ena_com_sq_update_llq_tail(struct ena_com_io_sq *io_sq)
200+static int ena_com_sq_update_llq_tail(struct ena_com_io_sq *io_sq)
201201 {
202202 struct ena_com_llq_pkt_ctrl *pkt_ctrl = &io_sq->llq_buf_ctrl;
203203 struct ena_com_llq_info *llq_info = &io_sq->llq_info;
@@ -225,7 +225,7 @@ static inline int ena_com_sq_update_llq_tail(struct ena_com_io_sq *io_sq) · 21 unmodified lines
225225 return 0;
226226 }
227227
228−static inline int ena_com_sq_update_tail(struct ena_com_io_sq *io_sq)
228+static int ena_com_sq_update_tail(struct ena_com_io_sq *io_sq)
229229 {
230230 if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
231231 return ena_com_sq_update_llq_tail(io_sq);
@@ -239,7 +239,7 @@ static inline int ena_com_sq_update_tail(struct ena_com_io_sq *io_sq) · 7 unmodified lines
239239 return 0;
240240 }
241241
242−static inline struct ena_eth_io_rx_cdesc_base *
242+static struct ena_eth_io_rx_cdesc_base *
243243 ena_com_rx_cdesc_idx_to_ptr(struct ena_com_io_cq *io_cq, u16 idx)
244244 {
245245 idx &= (io_cq->q_depth - 1);
@@ -248,7 +248,7 @@ static inline struct ena_eth_io_rx_cdesc_base * · 2 unmodified lines
248248 idx * io_cq->cdesc_entry_size_in_bytes);
249249 }
250250
251−static inline u16 ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
251+static u16 ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
252252 u16 *first_cdesc_idx)
253253 {
254254 struct ena_eth_io_rx_cdesc_base *cdesc;
@@ -285,7 +285,7 @@ static inline u16 ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq, · 30 unmodified lines
285285 return count;
286286 }
287287
288−static inline int ena_com_create_and_store_tx_meta_desc(struct ena_com_io_sq *io_sq,
288+static int ena_com_create_and_store_tx_meta_desc(struct ena_com_io_sq *io_sq,
289289 struct ena_com_tx_ctx *ena_tx_ctx)
290290 {
291291 struct ena_eth_io_tx_meta_desc *meta_desc = NULL;
@@ -334,7 +334,7 @@ static inline int ena_com_create_and_store_tx_meta_desc(struct ena_com_io_sq *io · 42 unmodified lines
334334 return ena_com_sq_update_tail(io_sq);
335335 }
336336
337−static inline void ena_com_rx_set_flags(struct ena_com_rx_ctx *ena_rx_ctx,
337+static void ena_com_rx_set_flags(struct ena_com_rx_ctx *ena_rx_ctx,
338338 struct ena_eth_io_rx_cdesc_base *cdesc)
339339 {
340340 ena_rx_ctx->l3_proto = cdesc->status &
drivers/net/ethernet/amazon/ena/ena_ethtool.c+26−6
@@ -486,13 +486,32 @@ static void ena_get_ringparam(struct net_device *netdev, · 485 unmodified lines
486486 struct ethtool_ringparam *ring)
487487 {
488488 struct ena_adapter *adapter = netdev_priv(netdev);
489− struct ena_ring *tx_ring = &adapter->tx_ring[0];
490− struct ena_ring *rx_ring = &adapter->rx_ring[0];
491489
492− ring->rx_max_pending = rx_ring->ring_size;
493− ring->tx_max_pending = tx_ring->ring_size;
494− ring->rx_pending = rx_ring->ring_size;
495− ring->tx_pending = tx_ring->ring_size;
490+ ring->tx_max_pending = adapter->max_tx_ring_size;
491+ ring->rx_max_pending = adapter->max_rx_ring_size;
492+ ring->tx_pending = adapter->tx_ring[0].ring_size;
493+ ring->rx_pending = adapter->rx_ring[0].ring_size;
494+}
495+
496+static int ena_set_ringparam(struct net_device *netdev,
497+ struct ethtool_ringparam *ring)
498+{
499+ struct ena_adapter *adapter = netdev_priv(netdev);
500+ u32 new_tx_size, new_rx_size;
501+
502+ new_tx_size = ring->tx_pending < ENA_MIN_RING_SIZE ?
503+ ENA_MIN_RING_SIZE : ring->tx_pending;
504+ new_tx_size = rounddown_pow_of_two(new_tx_size);
505+
506+ new_rx_size = ring->rx_pending < ENA_MIN_RING_SIZE ?
507+ ENA_MIN_RING_SIZE : ring->rx_pending;
508+ new_rx_size = rounddown_pow_of_two(new_rx_size);
509+
510+ if (new_tx_size == adapter->requested_tx_ring_size &&
511+ new_rx_size == adapter->requested_rx_ring_size)
512+ return 0;
513+
514+ return ena_update_queue_sizes(adapter, new_tx_size, new_rx_size);
496515 }
497516
498517 static u32 ena_flow_hash_to_flow_type(u16 hash_fields)
@@ -860,6 +879,7 @@ static const struct ethtool_ops ena_ethtool_ops = { · 361 unmodified lines
860879 .get_coalesce = ena_get_coalesce,
861880 .set_coalesce = ena_set_coalesce,
862881 .get_ringparam = ena_get_ringparam,
882+ .set_ringparam = ena_set_ringparam,
863883 .get_sset_count = ena_get_sset_count,
864884 .get_strings = ena_get_strings,
865885 .get_ethtool_stats = ena_get_ethtool_stats,
drivers/net/ethernet/amazon/ena/ena_netdev.c+232−87
@@ -182,7 +182,7 @@ static void ena_init_io_rings(struct ena_adapter *adapter) · 181 unmodified lines
182182 ena_init_io_rings_common(adapter, rxr, i);
183183
184184 /* TX specific ring state */
185− txr->ring_size = adapter->tx_ring_size;
185+ txr->ring_size = adapter->requested_tx_ring_size;
186186 txr->tx_max_header_size = ena_dev->tx_max_header_size;
187187 txr->tx_mem_queue_type = ena_dev->tx_mem_queue_type;
188188 txr->sgl_size = adapter->max_tx_sgl_size;
@@ -190,7 +190,7 @@ static void ena_init_io_rings(struct ena_adapter *adapter) · 1 unmodified line
190190 ena_com_get_nonadaptive_moderation_interval_tx(ena_dev);
191191
192192 /* RX specific ring state */
193− rxr->ring_size = adapter->rx_ring_size;
193+ rxr->ring_size = adapter->requested_rx_ring_size;
194194 rxr->rx_copybreak = adapter->rx_copybreak;
195195 rxr->sgl_size = adapter->max_rx_sgl_size;
196196 rxr->smoothed_interval =
@@ -326,7 +326,7 @@ static void ena_free_all_io_tx_resources(struct ena_adapter *adapter) · 129 unmodified lines
326326 ena_free_tx_resources(adapter, i);
327327 }
328328
329−static inline int validate_rx_req_id(struct ena_ring *rx_ring, u16 req_id)
329+static int validate_rx_req_id(struct ena_ring *rx_ring, u16 req_id)
330330 {
331331 if (likely(req_id < rx_ring->ring_size))
332332 return 0;
@@ -460,7 +460,7 @@ static void ena_free_all_io_rx_resources(struct ena_adapter *adapter) · 127 unmodified lines
460460 ena_free_rx_resources(adapter, i);
461461 }
462462
463−static inline int ena_alloc_rx_page(struct ena_ring *rx_ring,
463+static int ena_alloc_rx_page(struct ena_ring *rx_ring,
464464 struct ena_rx_buffer *rx_info, gfp_t gfp)
465465 {
466466 struct ena_com_buf *ena_buf;
@@ -594,7 +594,6 @@ static void ena_free_rx_bufs(struct ena_adapter *adapter, · 127 unmodified lines
594594
595595 /* ena_refill_all_rx_bufs - allocate all queues Rx buffers
596596 * @adapter: board private structure
597− *
598597 */
599598 static void ena_refill_all_rx_bufs(struct ena_adapter *adapter)
600599 {
@@ -621,7 +620,7 @@ static void ena_free_all_rx_bufs(struct ena_adapter *adapter) · 20 unmodified lines
621620 ena_free_rx_bufs(adapter, i);
622621 }
623622
624−static inline void ena_unmap_tx_skb(struct ena_ring *tx_ring,
623+static void ena_unmap_tx_skb(struct ena_ring *tx_ring,
625624 struct ena_tx_buffer *tx_info)
626625 {
627626 struct ena_com_buf *ena_buf;
@@ -956,7 +955,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, · 328 unmodified lines
956955 * @ena_rx_ctx: received packet context/metadata
957956 * @skb: skb currently being received and modified
958957 */
959−static inline void ena_rx_checksum(struct ena_ring *rx_ring,
958+static void ena_rx_checksum(struct ena_ring *rx_ring,
960959 struct ena_com_rx_ctx *ena_rx_ctx,
961960 struct sk_buff *skb)
962961 {
@@ -1156,7 +1155,7 @@ error: · 193 unmodified lines
11561155 return 0;
11571156 }
11581157
1159−inline void ena_adjust_intr_moderation(struct ena_ring *rx_ring,
1158+void ena_adjust_intr_moderation(struct ena_ring *rx_ring,
11601159 struct ena_ring *tx_ring)
11611160 {
11621161 /* We apply adaptive moderation on Rx path only.
@@ -1175,7 +1174,7 @@ inline void ena_adjust_intr_moderation(struct ena_ring *rx_ring, · 12 unmodified lines
11751174 rx_ring->per_napi_bytes = 0;
11761175 }
11771176
1178−static inline void ena_unmask_interrupt(struct ena_ring *tx_ring,
1177+static void ena_unmask_interrupt(struct ena_ring *tx_ring,
11791178 struct ena_ring *rx_ring)
11801179 {
11811180 struct ena_eth_io_intr_reg intr_reg;
@@ -1195,7 +1194,7 @@ static inline void ena_unmask_interrupt(struct ena_ring *tx_ring, · 13 unmodified lines
11951194 ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
11961195 }
11971196
1198−static inline void ena_update_ring_numa_node(struct ena_ring *tx_ring,
1197+static void ena_update_ring_numa_node(struct ena_ring *tx_ring,
11991198 struct ena_ring *rx_ring)
12001199 {
12011200 int cpu = get_cpu();
@@ -1638,7 +1637,7 @@ static int ena_create_io_tx_queue(struct ena_adapter *adapter, int qid) · 436 unmodified lines
16381637 ctx.qid = ena_qid;
16391638 ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
16401639 ctx.msix_vector = msix_vector;
1641− ctx.queue_size = adapter->tx_ring_size;
1640+ ctx.queue_size = tx_ring->ring_size;
16421641 ctx.numa_node = cpu_to_node(tx_ring->cpu);
16431642
16441643 rc = ena_com_create_io_queue(ena_dev, &ctx);
@@ -1705,7 +1704,7 @@ static int ena_create_io_rx_queue(struct ena_adapter *adapter, int qid) · 60 unmodified lines
17051704 ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_RX;
17061705 ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
17071706 ctx.msix_vector = msix_vector;
1708− ctx.queue_size = adapter->rx_ring_size;
1707+ ctx.queue_size = rx_ring->ring_size;
17091708 ctx.numa_node = cpu_to_node(rx_ring->cpu);
17101709
17111710 rc = ena_com_create_io_queue(ena_dev, &ctx);
@@ -1752,6 +1751,112 @@ create_err: · 40 unmodified lines
17521751 return rc;
17531752 }
17541753
1754+static void set_io_rings_size(struct ena_adapter *adapter,
1755+ int new_tx_size, int new_rx_size)
1756+{
1757+ int i;
1758+
1759+ for (i = 0; i < adapter->num_queues; i++) {
1760+ adapter->tx_ring[i].ring_size = new_tx_size;
1761+ adapter->rx_ring[i].ring_size = new_rx_size;
1762+ }
1763+}
1764+
1765+/* This function allows queue allocation to backoff when the system is
1766+ * low on memory. If there is not enough memory to allocate io queues
1767+ * the driver will try to allocate smaller queues.
1768+ *
1769+ * The backoff algorithm is as follows:
1770+ * 1. Try to allocate TX and RX and if successful.
1771+ * 1.1. return success
1772+ *
1773+ * 2. Divide by 2 the size of the larger of RX and TX queues (or both if their size is the same).
1774+ *
1775+ * 3. If TX or RX is smaller than 256
1776+ * 3.1. return failure.
1777+ * 4. else
1778+ * 4.1. go back to 1.
1779+ */
1780+static int create_queues_with_size_backoff(struct ena_adapter *adapter)
1781+{
1782+ int rc, cur_rx_ring_size, cur_tx_ring_size;
1783+ int new_rx_ring_size, new_tx_ring_size;
1784+
1785+ /* current queue sizes might be set to smaller than the requested
1786+ * ones due to past queue allocation failures.
1787+ */
1788+ set_io_rings_size(adapter, adapter->requested_tx_ring_size,
1789+ adapter->requested_rx_ring_size);
1790+
1791+ while (1) {
1792+ rc = ena_setup_all_tx_resources(adapter);
1793+ if (rc)
1794+ goto err_setup_tx;
1795+
1796+ rc = ena_create_all_io_tx_queues(adapter);
1797+ if (rc)
1798+ goto err_create_tx_queues;
1799+
1800+ rc = ena_setup_all_rx_resources(adapter);
1801+ if (rc)
1802+ goto err_setup_rx;
1803+
1804+ rc = ena_create_all_io_rx_queues(adapter);
1805+ if (rc)
1806+ goto err_create_rx_queues;
1807+
1808+ return 0;
1809+
1810+err_create_rx_queues:
1811+ ena_free_all_io_rx_resources(adapter);
1812+err_setup_rx:
1813+ ena_destroy_all_tx_queues(adapter);
1814+err_create_tx_queues:
1815+ ena_free_all_io_tx_resources(adapter);
1816+err_setup_tx:
1817+ if (rc != -ENOMEM) {
1818+ netif_err(adapter, ifup, adapter->netdev,
1819+ "Queue creation failed with error code %d\n",
1820+ rc);
1821+ return rc;
1822+ }
1823+
1824+ cur_tx_ring_size = adapter->tx_ring[0].ring_size;
1825+ cur_rx_ring_size = adapter->rx_ring[0].ring_size;
1826+
1827+ netif_err(adapter, ifup, adapter->netdev,
1828+ "Not enough memory to create queues with sizes TX=%d, RX=%d\n",
1829+ cur_tx_ring_size, cur_rx_ring_size);
1830+
1831+ new_tx_ring_size = cur_tx_ring_size;
1832+ new_rx_ring_size = cur_rx_ring_size;
1833+
1834+ /* Decrease the size of the larger queue, or
1835+ * decrease both if they are the same size.
1836+ */
1837+ if (cur_rx_ring_size <= cur_tx_ring_size)
1838+ new_tx_ring_size = cur_tx_ring_size / 2;
1839+ if (cur_rx_ring_size >= cur_tx_ring_size)
1840+ new_rx_ring_size = cur_rx_ring_size / 2;
1841+
1842+ if (cur_tx_ring_size < ENA_MIN_RING_SIZE ||
1843+ cur_rx_ring_size < ENA_MIN_RING_SIZE) {
1844+ netif_err(adapter, ifup, adapter->netdev,
1845+ "Queue creation failed with the smallest possible queue size of %d for both queues. Not retrying with smaller queues\n",
1846+ ENA_MIN_RING_SIZE);
1847+ return rc;
1848+ }
1849+
1850+ netif_err(adapter, ifup, adapter->netdev,
1851+ "Retrying queue creation with sizes TX=%d, RX=%d\n",
1852+ new_tx_ring_size,
1853+ new_rx_ring_size);
1854+
1855+ set_io_rings_size(adapter, new_tx_ring_size,
1856+ new_rx_ring_size);
1857+ }
1858+}
1859+
17551860 static int ena_up(struct ena_adapter *adapter)
17561861 {
17571862 int rc, i;
@@ -1771,25 +1876,9 @@ static int ena_up(struct ena_adapter *adapter) · 13 unmodified lines
17711876 if (rc)
17721877 goto err_req_irq;
17731878
1774− /* allocate transmit descriptors */
1775− rc = ena_setup_all_tx_resources(adapter);
1776− if (rc)
1777− goto err_setup_tx;
1778−
1779− /* allocate receive descriptors */
1780− rc = ena_setup_all_rx_resources(adapter);
1781− if (rc)
1782− goto err_setup_rx;
1783−
1784− /* Create TX queues */
1785− rc = ena_create_all_io_tx_queues(adapter);
1879+ rc = create_queues_with_size_backoff(adapter);
17861880 if (rc)
1787− goto err_create_tx_queues;
1788−
1789− /* Create RX queues */
1790− rc = ena_create_all_io_rx_queues(adapter);
1791− if (rc)
1792− goto err_create_rx_queues;
1881+ goto err_create_queues_with_backoff;
17931882
17941883 rc = ena_up_complete(adapter);
17951884 if (rc)
@@ -1818,14 +1907,11 @@ static int ena_up(struct ena_adapter *adapter) · 22 unmodified lines
18181907 return rc;
18191908
18201909 err_up:
1821− ena_destroy_all_rx_queues(adapter);
1822−err_create_rx_queues:
18231910 ena_destroy_all_tx_queues(adapter);
1824−err_create_tx_queues:
1825− ena_free_all_io_rx_resources(adapter);
1826−err_setup_rx:
18271911 ena_free_all_io_tx_resources(adapter);
1828−err_setup_tx:
1912+ ena_destroy_all_rx_queues(adapter);
1913+ ena_free_all_io_rx_resources(adapter);
1914+err_create_queues_with_backoff:
18291915 ena_free_io_irq(adapter);
18301916 err_req_irq:
18311917 ena_del_napi(adapter);
@@ -1945,6 +2031,20 @@ static int ena_close(struct net_device *netdev) · 113 unmodified lines
19452031 return 0;
19462032 }
19472033
2034+int ena_update_queue_sizes(struct ena_adapter *adapter,
2035+ u32 new_tx_size,
2036+ u32 new_rx_size)
2037+{
2038+ bool dev_up;
2039+
2040+ dev_up = test_bit(ENA_FLAG_DEV_UP, &adapter->flags);
2041+ ena_close(adapter->netdev);
2042+ adapter->requested_tx_ring_size = new_tx_size;
2043+ adapter->requested_rx_ring_size = new_rx_size;
2044+ ena_init_io_rings(adapter);
2045+ return dev_up ? ena_up(adapter) : 0;
2046+}
2047+
19482048 static void ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct sk_buff *skb)
19492049 {
19502050 u32 mss = skb_shinfo(skb)->gso_size;
@@ -2465,13 +2565,6 @@ static int ena_device_validate_params(struct ena_adapter *adapter, · 514 unmodified lines
24652565 return -EINVAL;
24662566 }
24672567
2468− if ((get_feat_ctx->max_queues.max_cq_num < adapter->num_queues) ||
2469− (get_feat_ctx->max_queues.max_sq_num < adapter->num_queues)) {
2470− netif_err(adapter, drv, netdev,
2471− "Error, device doesn't support enough queues\n");
2472− return -EINVAL;
2473− }
2474−
24752568 if (get_feat_ctx->dev_attr.max_mtu < netdev->mtu) {
24762569 netif_err(adapter, drv, netdev,
24772570 "Error, device max mtu is smaller than netdev MTU\n");
@@ -3045,18 +3138,32 @@ static int ena_calc_io_queue_num(struct pci_dev *pdev, · 567 unmodified lines
30453138 struct ena_com_dev *ena_dev,
30463139 struct ena_com_dev_get_features_ctx *get_feat_ctx)
30473140 {
3048− int io_sq_num, io_queue_num;
3141+ int io_tx_sq_num, io_tx_cq_num, io_rx_num, io_queue_num;
3142+
3143+ if (ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) {
3144+ struct ena_admin_queue_ext_feature_fields *max_queue_ext =
3145+ &get_feat_ctx->max_queue_ext.max_queue_ext;
3146+ io_rx_num = min_t(int, max_queue_ext->max_rx_sq_num,
3147+ max_queue_ext->max_rx_cq_num);
3148+
3149+ io_tx_sq_num = max_queue_ext->max_tx_sq_num;
3150+ io_tx_cq_num = max_queue_ext->max_tx_cq_num;
3151+ } else {
3152+ struct ena_admin_queue_feature_desc *max_queues =
3153+ &get_feat_ctx->max_queues;
3154+ io_tx_sq_num = max_queues->max_sq_num;
3155+ io_tx_cq_num = max_queues->max_cq_num;
3156+ io_rx_num = min_t(int, io_tx_sq_num, io_tx_cq_num);
3157+ }
30493158
3050− /* In case of LLQ use the llq number in the get feature cmd */
3159+ /* In case of LLQ use the llq fields for the tx SQ/CQ */
30513160 if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
3052− io_sq_num = get_feat_ctx->llq.max_llq_num;
3053− else
3054− io_sq_num = get_feat_ctx->max_queues.max_sq_num;
3161+ io_tx_sq_num = get_feat_ctx->llq.max_llq_num;
30553162
30563163 io_queue_num = min_t(int, num_online_cpus(), ENA_MAX_NUM_IO_QUEUES);
3057− io_queue_num = min_t(int, io_queue_num, io_sq_num);
3058− io_queue_num = min_t(int, io_queue_num,
3059− get_feat_ctx->max_queues.max_cq_num);
3164+ io_queue_num = min_t(int, io_queue_num, io_rx_num);
3165+ io_queue_num = min_t(int, io_queue_num, io_tx_sq_num);
3166+ io_queue_num = min_t(int, io_queue_num, io_tx_cq_num);
30603167 /* 1 IRQ for for mgmnt and 1 IRQs for each IO direction */
30613168 io_queue_num = min_t(int, io_queue_num, pci_msix_vec_count(pdev) - 1);
30623169 if (unlikely(!io_queue_num)) {
@@ -3230,7 +3337,7 @@ static void ena_release_bars(struct ena_com_dev *ena_dev, struct pci_dev *pdev) · 167 unmodified lines
32303337 pci_release_selected_regions(pdev, release_bars);
32313338 }
32323339
3233−static inline void set_default_llq_configurations(struct ena_llq_configurations *llq_config)
3340+static void set_default_llq_configurations(struct ena_llq_configurations *llq_config)
32343341 {
32353342 llq_config->llq_header_location = ENA_ADMIN_INLINE_HEADER;
32363343 llq_config->llq_ring_entry_size = ENA_ADMIN_LIST_ENTRY_SIZE_128B;
@@ -3239,36 +3346,70 @@ static inline void set_default_llq_configurations(struct ena_llq_configurations · 2 unmodified lines
32393346 llq_config->llq_ring_entry_size_value = 128;
32403347 }
32413348
3242−static int ena_calc_queue_size(struct pci_dev *pdev,
3243− struct ena_com_dev *ena_dev,
3244− u16 *max_tx_sgl_size,
3245− u16 *max_rx_sgl_size,
3246− struct ena_com_dev_get_features_ctx *get_feat_ctx)
3349+static int ena_calc_queue_size(struct ena_calc_queue_size_ctx *ctx)
32473350 {
3248− u32 queue_size = ENA_DEFAULT_RING_SIZE;
3351+ struct ena_admin_feature_llq_desc *llq = &ctx->get_feat_ctx->llq;
3352+ struct ena_com_dev *ena_dev = ctx->ena_dev;
3353+ u32 tx_queue_size = ENA_DEFAULT_RING_SIZE;
3354+ u32 rx_queue_size = ENA_DEFAULT_RING_SIZE;
3355+ u32 max_tx_queue_size;
3356+ u32 max_rx_queue_size;
32493357
3250− queue_size = min_t(u32, queue_size,
3251− get_feat_ctx->max_queues.max_cq_depth);
3252− queue_size = min_t(u32, queue_size,
3253− get_feat_ctx->max_queues.max_sq_depth);
3358+ if (ctx->ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) {
3359+ struct ena_admin_queue_ext_feature_fields *max_queue_ext =
3360+ &ctx->get_feat_ctx->max_queue_ext.max_queue_ext;
3361+ max_rx_queue_size = min_t(u32, max_queue_ext->max_rx_cq_depth,
3362+ max_queue_ext->max_rx_sq_depth);
3363+ max_tx_queue_size = max_queue_ext->max_tx_cq_depth;
32543364
3255− if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
3256− queue_size = min_t(u32, queue_size,
3257− get_feat_ctx->llq.max_llq_depth);
3365+ if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
3366+ max_tx_queue_size = min_t(u32, max_tx_queue_size,
3367+ llq->max_llq_depth);
3368+ else
3369+ max_tx_queue_size = min_t(u32, max_tx_queue_size,
3370+ max_queue_ext->max_tx_sq_depth);
32583371
3259− queue_size = rounddown_pow_of_two(queue_size);
3372+ ctx->max_tx_sgl_size = min_t(u16, ENA_PKT_MAX_BUFS,
3373+ max_queue_ext->max_per_packet_tx_descs);
3374+ ctx->max_rx_sgl_size = min_t(u16, ENA_PKT_MAX_BUFS,
3375+ max_queue_ext->max_per_packet_rx_descs);
3376+ } else {
3377+ struct ena_admin_queue_feature_desc *max_queues =
3378+ &ctx->get_feat_ctx->max_queues;
3379+ max_rx_queue_size = min_t(u32, max_queues->max_cq_depth,
3380+ max_queues->max_sq_depth);
3381+ max_tx_queue_size = max_queues->max_cq_depth;
3382+
3383+ if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
3384+ max_tx_queue_size = min_t(u32, max_tx_queue_size,
3385+ llq->max_llq_depth);
3386+ else
3387+ max_tx_queue_size = min_t(u32, max_tx_queue_size,
3388+ max_queues->max_sq_depth);
32603389
3261− if (unlikely(!queue_size)) {
3262− dev_err(&pdev->dev, "Invalid queue size\n");
3263− return -EFAULT;
3390+ ctx->max_tx_sgl_size = min_t(u16, ENA_PKT_MAX_BUFS,
3391+ max_queues->max_packet_tx_descs);
3392+ ctx->max_rx_sgl_size = min_t(u16, ENA_PKT_MAX_BUFS,
3393+ max_queues->max_packet_rx_descs);
32643394 }
32653395
3266− *max_tx_sgl_size = min_t(u16, ENA_PKT_MAX_BUFS,
3267− get_feat_ctx->max_queues.max_packet_tx_descs);
3268− *max_rx_sgl_size = min_t(u16, ENA_PKT_MAX_BUFS,
3269− get_feat_ctx->max_queues.max_packet_rx_descs);
3396+ max_tx_queue_size = rounddown_pow_of_two(max_tx_queue_size);
3397+ max_rx_queue_size = rounddown_pow_of_two(max_rx_queue_size);
3398+
3399+ tx_queue_size = clamp_val(tx_queue_size, ENA_MIN_RING_SIZE,
3400+ max_tx_queue_size);
3401+ rx_queue_size = clamp_val(rx_queue_size, ENA_MIN_RING_SIZE,
3402+ max_rx_queue_size);
32703403
3271− return queue_size;
3404+ tx_queue_size = rounddown_pow_of_two(tx_queue_size);
3405+ rx_queue_size = rounddown_pow_of_two(rx_queue_size);
3406+
3407+ ctx->max_tx_queue_size = max_tx_queue_size;
3408+ ctx->max_rx_queue_size = max_rx_queue_size;
3409+ ctx->tx_queue_size = tx_queue_size;
3410+ ctx->rx_queue_size = rx_queue_size;
3411+
3412+ return 0;
32723413 }
32733414
32743415 /* ena_probe - Device Initialization Routine
@@ -3284,6 +3425,7 @@ static int ena_calc_queue_size(struct pci_dev *pdev, · 9 unmodified lines
32843425 static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
32853426 {
32863427 struct ena_com_dev_get_features_ctx get_feat_ctx;
3428+ struct ena_calc_queue_size_ctx calc_queue_ctx = { 0 };
32873429 struct ena_llq_configurations llq_config;
32883430 struct ena_com_dev *ena_dev = NULL;
32893431 struct ena_adapter *adapter;
@@ -3291,9 +3433,6 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · 1 unmodified line
32913433 struct net_device *netdev;
32923434 static int adapters_found;
32933435 char *queue_type_str;
3294− u16 tx_sgl_size = 0;
3295− u16 rx_sgl_size = 0;
3296− int queue_size;
32973436 bool wd_state;
32983437
32993438 dev_dbg(&pdev->dev, "%s\n", __func__);
@@ -3350,20 +3489,25 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · 50 unmodified lines
33503489 goto err_device_destroy;
33513490 }
33523491
3492+ calc_queue_ctx.ena_dev = ena_dev;
3493+ calc_queue_ctx.get_feat_ctx = &get_feat_ctx;
3494+ calc_queue_ctx.pdev = pdev;
3495+
33533496 /* initial Tx interrupt delay, Assumes 1 usec granularity.
33543497 * Updated during device initialization with the real granularity
33553498 */
33563499 ena_dev->intr_moder_tx_interval = ENA_INTR_INITIAL_TX_INTERVAL_USECS;
33573500 io_queue_num = ena_calc_io_queue_num(pdev, ena_dev, &get_feat_ctx);
3358− queue_size = ena_calc_queue_size(pdev, ena_dev, &tx_sgl_size,
3359− &rx_sgl_size, &get_feat_ctx);
3360− if ((queue_size <= 0) || (io_queue_num <= 0)) {
3501+ rc = ena_calc_queue_size(&calc_queue_ctx);
3502+ if (rc || io_queue_num <= 0) {
33613503 rc = -EFAULT;
33623504 goto err_device_destroy;
33633505 }
33643506
3365− dev_info(&pdev->dev, "creating %d io queues. queue size: %d. LLQ is %s\n",
3366− io_queue_num, queue_size,
3507+ dev_info(&pdev->dev, "creating %d io queues. rx queue size: %d tx queue size. %d LLQ is %s\n",
3508+ io_queue_num,
3509+ calc_queue_ctx.rx_queue_size,
3510+ calc_queue_ctx.tx_queue_size,
33673511 (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) ?
33683512 "ENABLED" : "DISABLED");
33693513
@@ -3389,11 +3533,12 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · 19 unmodified lines
33893533 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
33903534 adapter->reset_reason = ENA_REGS_RESET_NORMAL;
33913535
3392− adapter->tx_ring_size = queue_size;
3393− adapter->rx_ring_size = queue_size;
3394−
3395− adapter->max_tx_sgl_size = tx_sgl_size;
3396− adapter->max_rx_sgl_size = rx_sgl_size;
3536+ adapter->requested_tx_ring_size = calc_queue_ctx.tx_queue_size;
3537+ adapter->requested_rx_ring_size = calc_queue_ctx.rx_queue_size;
3538+ adapter->max_tx_ring_size = calc_queue_ctx.max_tx_queue_size;
3539+ adapter->max_rx_ring_size = calc_queue_ctx.max_rx_queue_size;
3540+ adapter->max_tx_sgl_size = calc_queue_ctx.max_tx_sgl_size;
3541+ adapter->max_rx_sgl_size = calc_queue_ctx.max_rx_sgl_size;
33973542
33983543 adapter->num_queues = io_queue_num;
33993544 adapter->last_monitored_tx_qid = 0;
drivers/net/ethernet/amazon/ena/ena_netdev.h+24−4
@@ -44,8 +44,8 @@ · 43 unmodified lines
4444 #include "ena_eth_com.h"
4545
4646 #define DRV_MODULE_VER_MAJOR 2
47−#define DRV_MODULE_VER_MINOR 0
48−#define DRV_MODULE_VER_SUBMINOR 3
47+#define DRV_MODULE_VER_MINOR 1
48+#define DRV_MODULE_VER_SUBMINOR 0
4949
5050 #define DRV_MODULE_NAME "ena"
5151 #ifndef DRV_MODULE_VERSION
@@ -79,6 +79,7 @@ · 27 unmodified lines
7979 #define ENA_BAR_MASK (BIT(ENA_REG_BAR) | BIT(ENA_MEM_BAR))
8080
8181 #define ENA_DEFAULT_RING_SIZE (1024)
82+#define ENA_MIN_RING_SIZE (256)
8283
8384 #define ENA_TX_WAKEUP_THRESH (MAX_SKB_FRAGS + 2)
8485 #define ENA_DEFAULT_RX_COPYBREAK (256 - NET_IP_ALIGN)
@@ -154,6 +155,18 @@ struct ena_napi { · 69 unmodified lines
154155 u32 qid;
155156 };
156157
158+struct ena_calc_queue_size_ctx {
159+ struct ena_com_dev_get_features_ctx *get_feat_ctx;
160+ struct ena_com_dev *ena_dev;
161+ struct pci_dev *pdev;
162+ u16 tx_queue_size;
163+ u16 rx_queue_size;
164+ u16 max_tx_queue_size;
165+ u16 max_rx_queue_size;
166+ u16 max_tx_sgl_size;
167+ u16 max_rx_sgl_size;
168+};
169+
157170 struct ena_tx_buffer {
158171 struct sk_buff *skb;
159172 /* num of ena desc for this specific skb
@@ -319,8 +332,11 @@ struct ena_adapter { · 159 unmodified lines
319332 u32 tx_usecs, rx_usecs; /* interrupt moderation */
320333 u32 tx_frames, rx_frames; /* interrupt moderation */
321334
322− u32 tx_ring_size;
323− u32 rx_ring_size;
335+ u32 requested_tx_ring_size;
336+ u32 requested_rx_ring_size;
337+
338+ u32 max_tx_ring_size;
339+ u32 max_rx_ring_size;
324340
325341 u32 msg_enable;
326342
@@ -372,6 +388,10 @@ void ena_dump_stats_to_dmesg(struct ena_adapter *adapter); · 45 unmodified lines
372388
373389 void ena_dump_stats_to_buf(struct ena_adapter *adapter, u8 *buf);
374390
391+int ena_update_queue_sizes(struct ena_adapter *adapter,
392+ u32 new_tx_size,
393+ u32 new_rx_size);
394+
375395 int ena_get_sset_count(struct net_device *netdev, int sset);
376396
377397 #endif /* !(ENA_H) */