hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/ethernet/amazon/ena/ena_com.c
....@@ -1,33 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
12 /*
2
- * Copyright 2015 Amazon.com, Inc. or its affiliates.
3
- *
4
- * This software is available to you under a choice of one of two
5
- * licenses. You may choose to be licensed under the terms of the GNU
6
- * General Public License (GPL) Version 2, available from the file
7
- * COPYING in the main directory of this source tree, or the
8
- * BSD license below:
9
- *
10
- * Redistribution and use in source and binary forms, with or
11
- * without modification, are permitted provided that the following
12
- * conditions are met:
13
- *
14
- * - Redistributions of source code must retain the above
15
- * copyright notice, this list of conditions and the following
16
- * disclaimer.
17
- *
18
- * - Redistributions in binary form must reproduce the above
19
- * copyright notice, this list of conditions and the following
20
- * disclaimer in the documentation and/or other materials
21
- * provided with the distribution.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
3
+ * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved.
314 */
325
336 #include "ena_com.h"
....@@ -41,9 +14,6 @@
4114 #define ENA_ASYNC_QUEUE_DEPTH 16
4215 #define ENA_ADMIN_QUEUE_DEPTH 32
4316
44
-#define MIN_ENA_VER (((ENA_COMMON_SPEC_VERSION_MAJOR) << \
45
- ENA_REGS_VERSION_MAJOR_VERSION_SHIFT) \
46
- | (ENA_COMMON_SPEC_VERSION_MINOR))
4717
4818 #define ENA_CTRL_MAJOR 0
4919 #define ENA_CTRL_MINOR 0
....@@ -61,9 +31,15 @@
6131
6232 #define ENA_MMIO_READ_TIMEOUT 0xFFFFFFFF
6333
34
+#define ENA_COM_BOUNCE_BUFFER_CNTRL_CNT 4
35
+
6436 #define ENA_REGS_ADMIN_INTR_MASK 1
6537
66
-#define ENA_POLL_MS 5
38
+#define ENA_MAX_BACKOFF_DELAY_EXP 16U
39
+
40
+#define ENA_MIN_ADMIN_POLL_US 100
41
+
42
+#define ENA_MAX_ADMIN_POLL_US 5000
6743
6844 /*****************************************************************************/
6945 /*****************************************************************************/
....@@ -92,12 +68,12 @@
9268 struct ena_admin_acq_get_stats_resp get_resp;
9369 };
9470
95
-static inline int ena_com_mem_addr_set(struct ena_com_dev *ena_dev,
71
+static int ena_com_mem_addr_set(struct ena_com_dev *ena_dev,
9672 struct ena_common_mem_addr *ena_addr,
9773 dma_addr_t addr)
9874 {
9975 if ((addr & GENMASK_ULL(ena_dev->dma_addr_bits - 1, 0)) != addr) {
100
- pr_err("dma address has more bits that the device supports\n");
76
+ pr_err("DMA address has more bits that the device supports\n");
10177 return -EINVAL;
10278 }
10379
....@@ -107,16 +83,16 @@
10783 return 0;
10884 }
10985
110
-static int ena_com_admin_init_sq(struct ena_com_admin_queue *queue)
86
+static int ena_com_admin_init_sq(struct ena_com_admin_queue *admin_queue)
11187 {
112
- struct ena_com_admin_sq *sq = &queue->sq;
113
- u16 size = ADMIN_SQ_SIZE(queue->q_depth);
88
+ struct ena_com_admin_sq *sq = &admin_queue->sq;
89
+ u16 size = ADMIN_SQ_SIZE(admin_queue->q_depth);
11490
115
- sq->entries = dma_zalloc_coherent(queue->q_dmadev, size, &sq->dma_addr,
116
- GFP_KERNEL);
91
+ sq->entries = dma_alloc_coherent(admin_queue->q_dmadev, size,
92
+ &sq->dma_addr, GFP_KERNEL);
11793
11894 if (!sq->entries) {
119
- pr_err("memory allocation failed");
95
+ pr_err("Memory allocation failed\n");
12096 return -ENOMEM;
12197 }
12298
....@@ -129,16 +105,16 @@
129105 return 0;
130106 }
131107
132
-static int ena_com_admin_init_cq(struct ena_com_admin_queue *queue)
108
+static int ena_com_admin_init_cq(struct ena_com_admin_queue *admin_queue)
133109 {
134
- struct ena_com_admin_cq *cq = &queue->cq;
135
- u16 size = ADMIN_CQ_SIZE(queue->q_depth);
110
+ struct ena_com_admin_cq *cq = &admin_queue->cq;
111
+ u16 size = ADMIN_CQ_SIZE(admin_queue->q_depth);
136112
137
- cq->entries = dma_zalloc_coherent(queue->q_dmadev, size, &cq->dma_addr,
138
- GFP_KERNEL);
113
+ cq->entries = dma_alloc_coherent(admin_queue->q_dmadev, size,
114
+ &cq->dma_addr, GFP_KERNEL);
139115
140116 if (!cq->entries) {
141
- pr_err("memory allocation failed");
117
+ pr_err("Memory allocation failed\n");
142118 return -ENOMEM;
143119 }
144120
....@@ -148,20 +124,20 @@
148124 return 0;
149125 }
150126
151
-static int ena_com_admin_init_aenq(struct ena_com_dev *dev,
127
+static int ena_com_admin_init_aenq(struct ena_com_dev *ena_dev,
152128 struct ena_aenq_handlers *aenq_handlers)
153129 {
154
- struct ena_com_aenq *aenq = &dev->aenq;
130
+ struct ena_com_aenq *aenq = &ena_dev->aenq;
155131 u32 addr_low, addr_high, aenq_caps;
156132 u16 size;
157133
158
- dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH;
134
+ ena_dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH;
159135 size = ADMIN_AENQ_SIZE(ENA_ASYNC_QUEUE_DEPTH);
160
- aenq->entries = dma_zalloc_coherent(dev->dmadev, size, &aenq->dma_addr,
161
- GFP_KERNEL);
136
+ aenq->entries = dma_alloc_coherent(ena_dev->dmadev, size,
137
+ &aenq->dma_addr, GFP_KERNEL);
162138
163139 if (!aenq->entries) {
164
- pr_err("memory allocation failed");
140
+ pr_err("Memory allocation failed\n");
165141 return -ENOMEM;
166142 }
167143
....@@ -171,18 +147,18 @@
171147 addr_low = ENA_DMA_ADDR_TO_UINT32_LOW(aenq->dma_addr);
172148 addr_high = ENA_DMA_ADDR_TO_UINT32_HIGH(aenq->dma_addr);
173149
174
- writel(addr_low, dev->reg_bar + ENA_REGS_AENQ_BASE_LO_OFF);
175
- writel(addr_high, dev->reg_bar + ENA_REGS_AENQ_BASE_HI_OFF);
150
+ writel(addr_low, ena_dev->reg_bar + ENA_REGS_AENQ_BASE_LO_OFF);
151
+ writel(addr_high, ena_dev->reg_bar + ENA_REGS_AENQ_BASE_HI_OFF);
176152
177153 aenq_caps = 0;
178
- aenq_caps |= dev->aenq.q_depth & ENA_REGS_AENQ_CAPS_AENQ_DEPTH_MASK;
154
+ aenq_caps |= ena_dev->aenq.q_depth & ENA_REGS_AENQ_CAPS_AENQ_DEPTH_MASK;
179155 aenq_caps |= (sizeof(struct ena_admin_aenq_entry)
180156 << ENA_REGS_AENQ_CAPS_AENQ_ENTRY_SIZE_SHIFT) &
181157 ENA_REGS_AENQ_CAPS_AENQ_ENTRY_SIZE_MASK;
182
- writel(aenq_caps, dev->reg_bar + ENA_REGS_AENQ_CAPS_OFF);
158
+ writel(aenq_caps, ena_dev->reg_bar + ENA_REGS_AENQ_CAPS_OFF);
183159
184160 if (unlikely(!aenq_handlers)) {
185
- pr_err("aenq handlers pointer is NULL\n");
161
+ pr_err("AENQ handlers pointer is NULL\n");
186162 return -EINVAL;
187163 }
188164
....@@ -191,38 +167,38 @@
191167 return 0;
192168 }
193169
194
-static inline void comp_ctxt_release(struct ena_com_admin_queue *queue,
170
+static void comp_ctxt_release(struct ena_com_admin_queue *queue,
195171 struct ena_comp_ctx *comp_ctx)
196172 {
197173 comp_ctx->occupied = false;
198174 atomic_dec(&queue->outstanding_cmds);
199175 }
200176
201
-static struct ena_comp_ctx *get_comp_ctxt(struct ena_com_admin_queue *queue,
177
+static struct ena_comp_ctx *get_comp_ctxt(struct ena_com_admin_queue *admin_queue,
202178 u16 command_id, bool capture)
203179 {
204
- if (unlikely(!queue->comp_ctx)) {
180
+ if (unlikely(command_id >= admin_queue->q_depth)) {
181
+ pr_err("Command id is larger than the queue size. cmd_id: %u queue size %d\n",
182
+ command_id, admin_queue->q_depth);
183
+ return NULL;
184
+ }
185
+
186
+ if (unlikely(!admin_queue->comp_ctx)) {
205187 pr_err("Completion context is NULL\n");
206188 return NULL;
207189 }
208190
209
- if (unlikely(command_id >= queue->q_depth)) {
210
- pr_err("command id is larger than the queue size. cmd_id: %u queue size %d\n",
211
- command_id, queue->q_depth);
212
- return NULL;
213
- }
214
-
215
- if (unlikely(queue->comp_ctx[command_id].occupied && capture)) {
191
+ if (unlikely(admin_queue->comp_ctx[command_id].occupied && capture)) {
216192 pr_err("Completion context is occupied\n");
217193 return NULL;
218194 }
219195
220196 if (capture) {
221
- atomic_inc(&queue->outstanding_cmds);
222
- queue->comp_ctx[command_id].occupied = true;
197
+ atomic_inc(&admin_queue->outstanding_cmds);
198
+ admin_queue->comp_ctx[command_id].occupied = true;
223199 }
224200
225
- return &queue->comp_ctx[command_id];
201
+ return &admin_queue->comp_ctx[command_id];
226202 }
227203
228204 static struct ena_comp_ctx *__ena_com_submit_admin_cmd(struct ena_com_admin_queue *admin_queue,
....@@ -241,9 +217,9 @@
241217 tail_masked = admin_queue->sq.tail & queue_size_mask;
242218
243219 /* In case of queue FULL */
244
- cnt = atomic_read(&admin_queue->outstanding_cmds);
220
+ cnt = (u16)atomic_read(&admin_queue->outstanding_cmds);
245221 if (cnt >= admin_queue->q_depth) {
246
- pr_debug("admin queue is full.\n");
222
+ pr_debug("Admin queue is full.\n");
247223 admin_queue->stats.out_of_space++;
248224 return ERR_PTR(-ENOSPC);
249225 }
....@@ -283,20 +259,21 @@
283259 return comp_ctx;
284260 }
285261
286
-static inline int ena_com_init_comp_ctxt(struct ena_com_admin_queue *queue)
262
+static int ena_com_init_comp_ctxt(struct ena_com_admin_queue *admin_queue)
287263 {
288
- size_t size = queue->q_depth * sizeof(struct ena_comp_ctx);
264
+ size_t size = admin_queue->q_depth * sizeof(struct ena_comp_ctx);
289265 struct ena_comp_ctx *comp_ctx;
290266 u16 i;
291267
292
- queue->comp_ctx = devm_kzalloc(queue->q_dmadev, size, GFP_KERNEL);
293
- if (unlikely(!queue->comp_ctx)) {
294
- pr_err("memory allocation failed");
268
+ admin_queue->comp_ctx =
269
+ devm_kzalloc(admin_queue->q_dmadev, size, GFP_KERNEL);
270
+ if (unlikely(!admin_queue->comp_ctx)) {
271
+ pr_err("Memory allocation failed\n");
295272 return -ENOMEM;
296273 }
297274
298
- for (i = 0; i < queue->q_depth; i++) {
299
- comp_ctx = get_comp_ctxt(queue, i, false);
275
+ for (i = 0; i < admin_queue->q_depth; i++) {
276
+ comp_ctx = get_comp_ctxt(admin_queue, i, false);
300277 if (comp_ctx)
301278 init_completion(&comp_ctx->wait_event);
302279 }
....@@ -310,7 +287,7 @@
310287 struct ena_admin_acq_entry *comp,
311288 size_t comp_size_in_bytes)
312289 {
313
- unsigned long flags;
290
+ unsigned long flags = 0;
314291 struct ena_comp_ctx *comp_ctx;
315292
316293 spin_lock_irqsave(&admin_queue->q_lock, flags);
....@@ -338,7 +315,7 @@
338315
339316 memset(&io_sq->desc_addr, 0x0, sizeof(io_sq->desc_addr));
340317
341
- io_sq->dma_addr_bits = ena_dev->dma_addr_bits;
318
+ io_sq->dma_addr_bits = (u8)ena_dev->dma_addr_bits;
342319 io_sq->desc_entry_size =
343320 (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) ?
344321 sizeof(struct ena_eth_io_tx_desc) :
....@@ -350,31 +327,64 @@
350327 dev_node = dev_to_node(ena_dev->dmadev);
351328 set_dev_node(ena_dev->dmadev, ctx->numa_node);
352329 io_sq->desc_addr.virt_addr =
353
- dma_zalloc_coherent(ena_dev->dmadev, size,
354
- &io_sq->desc_addr.phys_addr,
355
- GFP_KERNEL);
330
+ dma_alloc_coherent(ena_dev->dmadev, size,
331
+ &io_sq->desc_addr.phys_addr,
332
+ GFP_KERNEL);
356333 set_dev_node(ena_dev->dmadev, dev_node);
357334 if (!io_sq->desc_addr.virt_addr) {
358335 io_sq->desc_addr.virt_addr =
359
- dma_zalloc_coherent(ena_dev->dmadev, size,
360
- &io_sq->desc_addr.phys_addr,
361
- GFP_KERNEL);
336
+ dma_alloc_coherent(ena_dev->dmadev, size,
337
+ &io_sq->desc_addr.phys_addr,
338
+ GFP_KERNEL);
362339 }
363
- } else {
364
- dev_node = dev_to_node(ena_dev->dmadev);
365
- set_dev_node(ena_dev->dmadev, ctx->numa_node);
366
- io_sq->desc_addr.virt_addr =
367
- devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL);
368
- set_dev_node(ena_dev->dmadev, dev_node);
340
+
369341 if (!io_sq->desc_addr.virt_addr) {
370
- io_sq->desc_addr.virt_addr =
371
- devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL);
342
+ pr_err("Memory allocation failed\n");
343
+ return -ENOMEM;
372344 }
373345 }
374346
375
- if (!io_sq->desc_addr.virt_addr) {
376
- pr_err("memory allocation failed");
377
- return -ENOMEM;
347
+ if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) {
348
+ /* Allocate bounce buffers */
349
+ io_sq->bounce_buf_ctrl.buffer_size =
350
+ ena_dev->llq_info.desc_list_entry_size;
351
+ io_sq->bounce_buf_ctrl.buffers_num =
352
+ ENA_COM_BOUNCE_BUFFER_CNTRL_CNT;
353
+ io_sq->bounce_buf_ctrl.next_to_use = 0;
354
+
355
+ size = io_sq->bounce_buf_ctrl.buffer_size *
356
+ io_sq->bounce_buf_ctrl.buffers_num;
357
+
358
+ dev_node = dev_to_node(ena_dev->dmadev);
359
+ set_dev_node(ena_dev->dmadev, ctx->numa_node);
360
+ io_sq->bounce_buf_ctrl.base_buffer =
361
+ devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL);
362
+ set_dev_node(ena_dev->dmadev, dev_node);
363
+ if (!io_sq->bounce_buf_ctrl.base_buffer)
364
+ io_sq->bounce_buf_ctrl.base_buffer =
365
+ devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL);
366
+
367
+ if (!io_sq->bounce_buf_ctrl.base_buffer) {
368
+ pr_err("Bounce buffer memory allocation failed\n");
369
+ return -ENOMEM;
370
+ }
371
+
372
+ memcpy(&io_sq->llq_info, &ena_dev->llq_info,
373
+ sizeof(io_sq->llq_info));
374
+
375
+ /* Initiate the first bounce buffer */
376
+ io_sq->llq_buf_ctrl.curr_bounce_buf =
377
+ ena_com_get_next_bounce_buffer(&io_sq->bounce_buf_ctrl);
378
+ memset(io_sq->llq_buf_ctrl.curr_bounce_buf,
379
+ 0x0, io_sq->llq_info.desc_list_entry_size);
380
+ io_sq->llq_buf_ctrl.descs_left_in_line =
381
+ io_sq->llq_info.descs_num_before_header;
382
+ io_sq->disable_meta_caching =
383
+ io_sq->llq_info.disable_meta_caching;
384
+
385
+ if (io_sq->llq_info.max_entries_in_tx_burst > 0)
386
+ io_sq->entries_in_tx_burst_left =
387
+ io_sq->llq_info.max_entries_in_tx_burst;
378388 }
379389
380390 io_sq->tail = 0;
....@@ -404,18 +414,18 @@
404414 prev_node = dev_to_node(ena_dev->dmadev);
405415 set_dev_node(ena_dev->dmadev, ctx->numa_node);
406416 io_cq->cdesc_addr.virt_addr =
407
- dma_zalloc_coherent(ena_dev->dmadev, size,
408
- &io_cq->cdesc_addr.phys_addr, GFP_KERNEL);
417
+ dma_alloc_coherent(ena_dev->dmadev, size,
418
+ &io_cq->cdesc_addr.phys_addr, GFP_KERNEL);
409419 set_dev_node(ena_dev->dmadev, prev_node);
410420 if (!io_cq->cdesc_addr.virt_addr) {
411421 io_cq->cdesc_addr.virt_addr =
412
- dma_zalloc_coherent(ena_dev->dmadev, size,
413
- &io_cq->cdesc_addr.phys_addr,
414
- GFP_KERNEL);
422
+ dma_alloc_coherent(ena_dev->dmadev, size,
423
+ &io_cq->cdesc_addr.phys_addr,
424
+ GFP_KERNEL);
415425 }
416426
417427 if (!io_cq->cdesc_addr.virt_addr) {
418
- pr_err("memory allocation failed");
428
+ pr_err("Memory allocation failed\n");
419429 return -ENOMEM;
420430 }
421431
....@@ -465,7 +475,7 @@
465475
466476 /* Go over all the completions */
467477 while ((READ_ONCE(cqe->acq_common_descriptor.flags) &
468
- ENA_ADMIN_ACQ_COMMON_DESC_PHASE_MASK) == phase) {
478
+ ENA_ADMIN_ACQ_COMMON_DESC_PHASE_MASK) == phase) {
469479 /* Do not read the rest of the completion entry before the
470480 * phase bit was validated
471481 */
....@@ -491,10 +501,7 @@
491501 static int ena_com_comp_status_to_errno(u8 comp_status)
492502 {
493503 if (unlikely(comp_status != 0))
494
- pr_err("admin command failed[%u]\n", comp_status);
495
-
496
- if (unlikely(comp_status > ENA_ADMIN_UNKNOWN_ERROR))
497
- return -EINVAL;
504
+ pr_err("Admin command failed[%u]\n", comp_status);
498505
499506 switch (comp_status) {
500507 case ENA_ADMIN_SUCCESS:
....@@ -508,16 +515,28 @@
508515 case ENA_ADMIN_ILLEGAL_PARAMETER:
509516 case ENA_ADMIN_UNKNOWN_ERROR:
510517 return -EINVAL;
518
+ case ENA_ADMIN_RESOURCE_BUSY:
519
+ return -EAGAIN;
511520 }
512521
513
- return 0;
522
+ return -EINVAL;
523
+}
524
+
525
+static void ena_delay_exponential_backoff_us(u32 exp, u32 delay_us)
526
+{
527
+ exp = min_t(u32, exp, ENA_MAX_BACKOFF_DELAY_EXP);
528
+ delay_us = max_t(u32, ENA_MIN_ADMIN_POLL_US, delay_us);
529
+ delay_us = min_t(u32, delay_us * (1U << exp), ENA_MAX_ADMIN_POLL_US);
530
+ usleep_range(delay_us, 2 * delay_us);
514531 }
515532
516533 static int ena_com_wait_and_process_admin_cq_polling(struct ena_comp_ctx *comp_ctx,
517534 struct ena_com_admin_queue *admin_queue)
518535 {
519
- unsigned long flags, timeout;
536
+ unsigned long flags = 0;
537
+ unsigned long timeout;
520538 int ret;
539
+ u32 exp = 0;
521540
522541 timeout = jiffies + usecs_to_jiffies(admin_queue->completion_timeout);
523542
....@@ -541,7 +560,8 @@
541560 goto err;
542561 }
543562
544
- msleep(ENA_POLL_MS);
563
+ ena_delay_exponential_backoff_us(exp++,
564
+ admin_queue->ena_dev->ena_min_poll_delay_us);
545565 }
546566
547567 if (unlikely(comp_ctx->status == ENA_CMD_ABORTED)) {
....@@ -562,10 +582,175 @@
562582 return ret;
563583 }
564584
585
+/*
586
+ * Set the LLQ configurations of the firmware
587
+ *
588
+ * The driver provides only the enabled feature values to the device,
589
+ * which in turn, checks if they are supported.
590
+ */
591
+static int ena_com_set_llq(struct ena_com_dev *ena_dev)
592
+{
593
+ struct ena_com_admin_queue *admin_queue;
594
+ struct ena_admin_set_feat_cmd cmd;
595
+ struct ena_admin_set_feat_resp resp;
596
+ struct ena_com_llq_info *llq_info = &ena_dev->llq_info;
597
+ int ret;
598
+
599
+ memset(&cmd, 0x0, sizeof(cmd));
600
+ admin_queue = &ena_dev->admin_queue;
601
+
602
+ cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE;
603
+ cmd.feat_common.feature_id = ENA_ADMIN_LLQ;
604
+
605
+ cmd.u.llq.header_location_ctrl_enabled = llq_info->header_location_ctrl;
606
+ cmd.u.llq.entry_size_ctrl_enabled = llq_info->desc_list_entry_size_ctrl;
607
+ cmd.u.llq.desc_num_before_header_enabled = llq_info->descs_num_before_header;
608
+ cmd.u.llq.descriptors_stride_ctrl_enabled = llq_info->desc_stride_ctrl;
609
+
610
+ cmd.u.llq.accel_mode.u.set.enabled_flags =
611
+ BIT(ENA_ADMIN_DISABLE_META_CACHING) |
612
+ BIT(ENA_ADMIN_LIMIT_TX_BURST);
613
+
614
+ ret = ena_com_execute_admin_command(admin_queue,
615
+ (struct ena_admin_aq_entry *)&cmd,
616
+ sizeof(cmd),
617
+ (struct ena_admin_acq_entry *)&resp,
618
+ sizeof(resp));
619
+
620
+ if (unlikely(ret))
621
+ pr_err("Failed to set LLQ configurations: %d\n", ret);
622
+
623
+ return ret;
624
+}
625
+
626
+static int ena_com_config_llq_info(struct ena_com_dev *ena_dev,
627
+ struct ena_admin_feature_llq_desc *llq_features,
628
+ struct ena_llq_configurations *llq_default_cfg)
629
+{
630
+ struct ena_com_llq_info *llq_info = &ena_dev->llq_info;
631
+ struct ena_admin_accel_mode_get llq_accel_mode_get;
632
+ u16 supported_feat;
633
+ int rc;
634
+
635
+ memset(llq_info, 0, sizeof(*llq_info));
636
+
637
+ supported_feat = llq_features->header_location_ctrl_supported;
638
+
639
+ if (likely(supported_feat & llq_default_cfg->llq_header_location)) {
640
+ llq_info->header_location_ctrl =
641
+ llq_default_cfg->llq_header_location;
642
+ } else {
643
+ pr_err("Invalid header location control, supported: 0x%x\n",
644
+ supported_feat);
645
+ return -EINVAL;
646
+ }
647
+
648
+ if (likely(llq_info->header_location_ctrl == ENA_ADMIN_INLINE_HEADER)) {
649
+ supported_feat = llq_features->descriptors_stride_ctrl_supported;
650
+ if (likely(supported_feat & llq_default_cfg->llq_stride_ctrl)) {
651
+ llq_info->desc_stride_ctrl = llq_default_cfg->llq_stride_ctrl;
652
+ } else {
653
+ if (supported_feat & ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY) {
654
+ llq_info->desc_stride_ctrl = ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY;
655
+ } else if (supported_feat & ENA_ADMIN_SINGLE_DESC_PER_ENTRY) {
656
+ llq_info->desc_stride_ctrl = ENA_ADMIN_SINGLE_DESC_PER_ENTRY;
657
+ } else {
658
+ pr_err("Invalid desc_stride_ctrl, supported: 0x%x\n",
659
+ supported_feat);
660
+ return -EINVAL;
661
+ }
662
+
663
+ pr_err("Default llq stride ctrl is not supported, performing fallback, default: 0x%x, supported: 0x%x, used: 0x%x\n",
664
+ llq_default_cfg->llq_stride_ctrl, supported_feat,
665
+ llq_info->desc_stride_ctrl);
666
+ }
667
+ } else {
668
+ llq_info->desc_stride_ctrl = 0;
669
+ }
670
+
671
+ supported_feat = llq_features->entry_size_ctrl_supported;
672
+ if (likely(supported_feat & llq_default_cfg->llq_ring_entry_size)) {
673
+ llq_info->desc_list_entry_size_ctrl = llq_default_cfg->llq_ring_entry_size;
674
+ llq_info->desc_list_entry_size = llq_default_cfg->llq_ring_entry_size_value;
675
+ } else {
676
+ if (supported_feat & ENA_ADMIN_LIST_ENTRY_SIZE_128B) {
677
+ llq_info->desc_list_entry_size_ctrl = ENA_ADMIN_LIST_ENTRY_SIZE_128B;
678
+ llq_info->desc_list_entry_size = 128;
679
+ } else if (supported_feat & ENA_ADMIN_LIST_ENTRY_SIZE_192B) {
680
+ llq_info->desc_list_entry_size_ctrl = ENA_ADMIN_LIST_ENTRY_SIZE_192B;
681
+ llq_info->desc_list_entry_size = 192;
682
+ } else if (supported_feat & ENA_ADMIN_LIST_ENTRY_SIZE_256B) {
683
+ llq_info->desc_list_entry_size_ctrl = ENA_ADMIN_LIST_ENTRY_SIZE_256B;
684
+ llq_info->desc_list_entry_size = 256;
685
+ } else {
686
+ pr_err("Invalid entry_size_ctrl, supported: 0x%x\n",
687
+ supported_feat);
688
+ return -EINVAL;
689
+ }
690
+
691
+ pr_err("Default llq ring entry size is not supported, performing fallback, default: 0x%x, supported: 0x%x, used: 0x%x\n",
692
+ llq_default_cfg->llq_ring_entry_size, supported_feat,
693
+ llq_info->desc_list_entry_size);
694
+ }
695
+ if (unlikely(llq_info->desc_list_entry_size & 0x7)) {
696
+ /* The desc list entry size should be whole multiply of 8
697
+ * This requirement comes from __iowrite64_copy()
698
+ */
699
+ pr_err("Illegal entry size %d\n", llq_info->desc_list_entry_size);
700
+ return -EINVAL;
701
+ }
702
+
703
+ if (llq_info->desc_stride_ctrl == ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY)
704
+ llq_info->descs_per_entry = llq_info->desc_list_entry_size /
705
+ sizeof(struct ena_eth_io_tx_desc);
706
+ else
707
+ llq_info->descs_per_entry = 1;
708
+
709
+ supported_feat = llq_features->desc_num_before_header_supported;
710
+ if (likely(supported_feat & llq_default_cfg->llq_num_decs_before_header)) {
711
+ llq_info->descs_num_before_header = llq_default_cfg->llq_num_decs_before_header;
712
+ } else {
713
+ if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_2) {
714
+ llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_2;
715
+ } else if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_1) {
716
+ llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_1;
717
+ } else if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_4) {
718
+ llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_4;
719
+ } else if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_8) {
720
+ llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_8;
721
+ } else {
722
+ pr_err("Invalid descs_num_before_header, supported: 0x%x\n",
723
+ supported_feat);
724
+ return -EINVAL;
725
+ }
726
+
727
+ pr_err("Default llq num descs before header is not supported, performing fallback, default: 0x%x, supported: 0x%x, used: 0x%x\n",
728
+ llq_default_cfg->llq_num_decs_before_header,
729
+ supported_feat, llq_info->descs_num_before_header);
730
+ }
731
+ /* Check for accelerated queue supported */
732
+ llq_accel_mode_get = llq_features->accel_mode.u.get;
733
+
734
+ llq_info->disable_meta_caching =
735
+ !!(llq_accel_mode_get.supported_flags &
736
+ BIT(ENA_ADMIN_DISABLE_META_CACHING));
737
+
738
+ if (llq_accel_mode_get.supported_flags & BIT(ENA_ADMIN_LIMIT_TX_BURST))
739
+ llq_info->max_entries_in_tx_burst =
740
+ llq_accel_mode_get.max_tx_burst_size /
741
+ llq_default_cfg->llq_ring_entry_size_value;
742
+
743
+ rc = ena_com_set_llq(ena_dev);
744
+ if (rc)
745
+ pr_err("Cannot set LLQ configuration: %d\n", rc);
746
+
747
+ return rc;
748
+}
749
+
565750 static int ena_com_wait_and_process_admin_cq_interrupts(struct ena_comp_ctx *comp_ctx,
566751 struct ena_com_admin_queue *admin_queue)
567752 {
568
- unsigned long flags;
753
+ unsigned long flags = 0;
569754 int ret;
570755
571756 wait_for_completion_timeout(&comp_ctx->wait_event,
....@@ -583,16 +768,26 @@
583768 admin_queue->stats.no_completion++;
584769 spin_unlock_irqrestore(&admin_queue->q_lock, flags);
585770
586
- if (comp_ctx->status == ENA_CMD_COMPLETED)
587
- pr_err("The ena device have completion but the driver didn't receive any MSI-X interrupt (cmd %d)\n",
588
- comp_ctx->cmd_opcode);
589
- else
590
- pr_err("The ena device doesn't send any completion for the admin cmd %d status %d\n",
771
+ if (comp_ctx->status == ENA_CMD_COMPLETED) {
772
+ pr_err("The ena device sent a completion but the driver didn't receive a MSI-X interrupt (cmd %d), autopolling mode is %s\n",
773
+ comp_ctx->cmd_opcode,
774
+ admin_queue->auto_polling ? "ON" : "OFF");
775
+ /* Check if fallback to polling is enabled */
776
+ if (admin_queue->auto_polling)
777
+ admin_queue->polling = true;
778
+ } else {
779
+ pr_err("The ena device didn't send a completion for the admin cmd %d status %d\n",
591780 comp_ctx->cmd_opcode, comp_ctx->status);
592
-
593
- admin_queue->running_state = false;
594
- ret = -ETIME;
595
- goto err;
781
+ }
782
+ /* Check if shifted to polling mode.
783
+ * This will happen if there is a completion without an interrupt
784
+ * and autopolling mode is enabled. Continuing normal execution in such case
785
+ */
786
+ if (!admin_queue->polling) {
787
+ admin_queue->running_state = false;
788
+ ret = -ETIME;
789
+ goto err;
790
+ }
596791 }
597792
598793 ret = ena_com_comp_status_to_errno(comp_ctx->comp_status);
....@@ -611,7 +806,7 @@
611806 volatile struct ena_admin_ena_mmio_req_read_less_resp *read_resp =
612807 mmio_read->read_resp;
613808 u32 mmio_read_reg, ret, i;
614
- unsigned long flags;
809
+ unsigned long flags = 0;
615810 u32 timeout = mmio_read->reg_read_to;
616811
617812 might_sleep();
....@@ -642,7 +837,7 @@
642837 }
643838
644839 if (unlikely(i == timeout)) {
645
- pr_err("reading reg failed for timeout. expected: req id[%hu] offset[%hu] actual: req id[%hu] offset[%hu]\n",
840
+ pr_err("Reading reg failed for timeout. expected: req id[%hu] offset[%hu] actual: req id[%hu] offset[%hu]\n",
646841 mmio_read->seq_num, offset, read_resp->req_id,
647842 read_resp->reg_off);
648843 ret = ENA_MMIO_READ_TIMEOUT;
....@@ -650,7 +845,7 @@
650845 }
651846
652847 if (read_resp->reg_off != offset) {
653
- pr_err("Read failure: wrong offset provided");
848
+ pr_err("Read failure: wrong offset provided\n");
654849 ret = ENA_MMIO_READ_TIMEOUT;
655850 } else {
656851 ret = read_resp->reg_val;
....@@ -709,7 +904,7 @@
709904 sizeof(destroy_resp));
710905
711906 if (unlikely(ret && (ret != -ENODEV)))
712
- pr_err("failed to destroy io sq error: %d\n", ret);
907
+ pr_err("Failed to destroy io sq error: %d\n", ret);
713908
714909 return ret;
715910 }
....@@ -733,26 +928,29 @@
733928 if (io_sq->desc_addr.virt_addr) {
734929 size = io_sq->desc_entry_size * io_sq->q_depth;
735930
736
- if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
737
- dma_free_coherent(ena_dev->dmadev, size,
738
- io_sq->desc_addr.virt_addr,
739
- io_sq->desc_addr.phys_addr);
740
- else
741
- devm_kfree(ena_dev->dmadev, io_sq->desc_addr.virt_addr);
931
+ dma_free_coherent(ena_dev->dmadev, size,
932
+ io_sq->desc_addr.virt_addr,
933
+ io_sq->desc_addr.phys_addr);
742934
743935 io_sq->desc_addr.virt_addr = NULL;
936
+ }
937
+
938
+ if (io_sq->bounce_buf_ctrl.base_buffer) {
939
+ devm_kfree(ena_dev->dmadev, io_sq->bounce_buf_ctrl.base_buffer);
940
+ io_sq->bounce_buf_ctrl.base_buffer = NULL;
744941 }
745942 }
746943
747944 static int wait_for_reset_state(struct ena_com_dev *ena_dev, u32 timeout,
748945 u16 exp_state)
749946 {
750
- u32 val, i;
947
+ u32 val, exp = 0;
948
+ unsigned long timeout_stamp;
751949
752
- /* Convert timeout from resolution of 100ms to ENA_POLL_MS */
753
- timeout = (timeout * 100) / ENA_POLL_MS;
950
+ /* Convert timeout from resolution of 100ms to us resolution. */
951
+ timeout_stamp = jiffies + usecs_to_jiffies(100 * 1000 * timeout);
754952
755
- for (i = 0; i < timeout; i++) {
953
+ while (1) {
756954 val = ena_com_reg_bar_read32(ena_dev, ENA_REGS_DEV_STS_OFF);
757955
758956 if (unlikely(val == ENA_MMIO_READ_TIMEOUT)) {
....@@ -764,10 +962,11 @@
764962 exp_state)
765963 return 0;
766964
767
- msleep(ENA_POLL_MS);
768
- }
965
+ if (time_is_before_jiffies(timeout_stamp))
966
+ return -ETIME;
769967
770
- return -ETIME;
968
+ ena_delay_exponential_backoff_us(exp++, ena_dev->ena_min_poll_delay_us);
969
+ }
771970 }
772971
773972 static bool ena_com_check_supported_feature_id(struct ena_com_dev *ena_dev,
....@@ -787,7 +986,8 @@
787986 struct ena_admin_get_feat_resp *get_resp,
788987 enum ena_admin_aq_feature_id feature_id,
789988 dma_addr_t control_buf_dma_addr,
790
- u32 control_buff_size)
989
+ u32 control_buff_size,
990
+ u8 feature_ver)
791991 {
792992 struct ena_com_admin_queue *admin_queue;
793993 struct ena_admin_get_feat_cmd get_cmd;
....@@ -813,12 +1013,12 @@
8131013 &get_cmd.control_buffer.address,
8141014 control_buf_dma_addr);
8151015 if (unlikely(ret)) {
816
- pr_err("memory address set failed\n");
1016
+ pr_err("Memory address set failed\n");
8171017 return ret;
8181018 }
8191019
8201020 get_cmd.control_buffer.length = control_buff_size;
821
-
1021
+ get_cmd.feat_common.feature_version = feature_ver;
8221022 get_cmd.feat_common.feature_id = feature_id;
8231023
8241024 ret = ena_com_execute_admin_command(admin_queue,
....@@ -838,13 +1038,20 @@
8381038
8391039 static int ena_com_get_feature(struct ena_com_dev *ena_dev,
8401040 struct ena_admin_get_feat_resp *get_resp,
841
- enum ena_admin_aq_feature_id feature_id)
1041
+ enum ena_admin_aq_feature_id feature_id,
1042
+ u8 feature_ver)
8421043 {
8431044 return ena_com_get_feature_ex(ena_dev,
8441045 get_resp,
8451046 feature_id,
8461047 0,
847
- 0);
1048
+ 0,
1049
+ feature_ver);
1050
+}
1051
+
1052
+int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev)
1053
+{
1054
+ return ena_dev->rss.hash_func;
8481055 }
8491056
8501057 static void ena_com_hash_key_fill_default_key(struct ena_com_dev *ena_dev)
....@@ -853,25 +1060,23 @@
8531060 (ena_dev->rss).hash_key;
8541061
8551062 netdev_rss_key_fill(&hash_key->key, sizeof(hash_key->key));
856
- /* The key is stored in the device in u32 array
857
- * as well as the API requires the key to be passed in this
858
- * format. Thus the size of our array should be divided by 4
1063
+ /* The key buffer is stored in the device in an array of
1064
+ * uint32 elements.
8591065 */
860
- hash_key->keys_num = sizeof(hash_key->key) / sizeof(u32);
861
-}
862
-
863
-int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev)
864
-{
865
- return ena_dev->rss.hash_func;
1066
+ hash_key->key_parts = ENA_ADMIN_RSS_KEY_PARTS;
8661067 }
8671068
8681069 static int ena_com_hash_key_allocate(struct ena_com_dev *ena_dev)
8691070 {
8701071 struct ena_rss *rss = &ena_dev->rss;
8711072
1073
+ if (!ena_com_check_supported_feature_id(ena_dev,
1074
+ ENA_ADMIN_RSS_HASH_FUNCTION))
1075
+ return -EOPNOTSUPP;
1076
+
8721077 rss->hash_key =
873
- dma_zalloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_key),
874
- &rss->hash_key_dma_addr, GFP_KERNEL);
1078
+ dma_alloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_key),
1079
+ &rss->hash_key_dma_addr, GFP_KERNEL);
8751080
8761081 if (unlikely(!rss->hash_key))
8771082 return -ENOMEM;
....@@ -894,8 +1099,8 @@
8941099 struct ena_rss *rss = &ena_dev->rss;
8951100
8961101 rss->hash_ctrl =
897
- dma_zalloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_ctrl),
898
- &rss->hash_ctrl_dma_addr, GFP_KERNEL);
1102
+ dma_alloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_ctrl),
1103
+ &rss->hash_ctrl_dma_addr, GFP_KERNEL);
8991104
9001105 if (unlikely(!rss->hash_ctrl))
9011106 return -ENOMEM;
....@@ -922,13 +1127,13 @@
9221127 int ret;
9231128
9241129 ret = ena_com_get_feature(ena_dev, &get_resp,
925
- ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
1130
+ ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG, 0);
9261131 if (unlikely(ret))
9271132 return ret;
9281133
9291134 if ((get_resp.u.ind_table.min_size > log_size) ||
9301135 (get_resp.u.ind_table.max_size < log_size)) {
931
- pr_err("indirect table size doesn't fit. requested size: %d while min is:%d and max %d\n",
1136
+ pr_err("Indirect table size doesn't fit. requested size: %d while min is:%d and max %d\n",
9321137 1 << log_size, 1 << get_resp.u.ind_table.min_size,
9331138 1 << get_resp.u.ind_table.max_size);
9341139 return -EINVAL;
....@@ -938,8 +1143,8 @@
9381143 sizeof(struct ena_admin_rss_ind_table_entry);
9391144
9401145 rss->rss_ind_tbl =
941
- dma_zalloc_coherent(ena_dev->dmadev, tbl_size,
942
- &rss->rss_ind_tbl_dma_addr, GFP_KERNEL);
1146
+ dma_alloc_coherent(ena_dev->dmadev, tbl_size,
1147
+ &rss->rss_ind_tbl_dma_addr, GFP_KERNEL);
9431148 if (unlikely(!rss->rss_ind_tbl))
9441149 goto mem_err1;
9451150
....@@ -1021,7 +1226,7 @@
10211226 &create_cmd.sq_ba,
10221227 io_sq->desc_addr.phys_addr);
10231228 if (unlikely(ret)) {
1024
- pr_err("memory address set failed\n");
1229
+ pr_err("Memory address set failed\n");
10251230 return ret;
10261231 }
10271232 }
....@@ -1050,7 +1255,7 @@
10501255 cmd_completion.llq_descriptors_offset);
10511256 }
10521257
1053
- pr_debug("created sq[%u], depth[%u]\n", io_sq->idx, io_sq->q_depth);
1258
+ pr_debug("Created sq[%u], depth[%u]\n", io_sq->idx, io_sq->q_depth);
10541259
10551260 return ret;
10561261 }
....@@ -1078,64 +1283,29 @@
10781283 return 0;
10791284 }
10801285
1081
-static int ena_com_ind_tbl_convert_from_device(struct ena_com_dev *ena_dev)
1082
-{
1083
- u16 dev_idx_to_host_tbl[ENA_TOTAL_NUM_QUEUES] = { (u16)-1 };
1084
- struct ena_rss *rss = &ena_dev->rss;
1085
- u8 idx;
1086
- u16 i;
1087
-
1088
- for (i = 0; i < ENA_TOTAL_NUM_QUEUES; i++)
1089
- dev_idx_to_host_tbl[ena_dev->io_sq_queues[i].idx] = i;
1090
-
1091
- for (i = 0; i < 1 << rss->tbl_log_size; i++) {
1092
- if (rss->rss_ind_tbl[i].cq_idx > ENA_TOTAL_NUM_QUEUES)
1093
- return -EINVAL;
1094
- idx = (u8)rss->rss_ind_tbl[i].cq_idx;
1095
-
1096
- if (dev_idx_to_host_tbl[idx] > ENA_TOTAL_NUM_QUEUES)
1097
- return -EINVAL;
1098
-
1099
- rss->host_rss_ind_tbl[i] = dev_idx_to_host_tbl[idx];
1100
- }
1101
-
1102
- return 0;
1103
-}
1104
-
1105
-static int ena_com_init_interrupt_moderation_table(struct ena_com_dev *ena_dev)
1106
-{
1107
- size_t size;
1108
-
1109
- size = sizeof(struct ena_intr_moder_entry) * ENA_INTR_MAX_NUM_OF_LEVELS;
1110
-
1111
- ena_dev->intr_moder_tbl =
1112
- devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL);
1113
- if (!ena_dev->intr_moder_tbl)
1114
- return -ENOMEM;
1115
-
1116
- ena_com_config_default_interrupt_moderation_table(ena_dev);
1117
-
1118
- return 0;
1119
-}
1120
-
11211286 static void ena_com_update_intr_delay_resolution(struct ena_com_dev *ena_dev,
11221287 u16 intr_delay_resolution)
11231288 {
1124
- struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl;
1125
- unsigned int i;
1289
+ u16 prev_intr_delay_resolution = ena_dev->intr_delay_resolution;
11261290
1127
- if (!intr_delay_resolution) {
1291
+ if (unlikely(!intr_delay_resolution)) {
11281292 pr_err("Illegal intr_delay_resolution provided. Going to use default 1 usec resolution\n");
1129
- intr_delay_resolution = 1;
1293
+ intr_delay_resolution = ENA_DEFAULT_INTR_DELAY_RESOLUTION;
11301294 }
1131
- ena_dev->intr_delay_resolution = intr_delay_resolution;
11321295
11331296 /* update Rx */
1134
- for (i = 0; i < ENA_INTR_MAX_NUM_OF_LEVELS; i++)
1135
- intr_moder_tbl[i].intr_moder_interval /= intr_delay_resolution;
1297
+ ena_dev->intr_moder_rx_interval =
1298
+ ena_dev->intr_moder_rx_interval *
1299
+ prev_intr_delay_resolution /
1300
+ intr_delay_resolution;
11361301
11371302 /* update Tx */
1138
- ena_dev->intr_moder_tx_interval /= intr_delay_resolution;
1303
+ ena_dev->intr_moder_tx_interval =
1304
+ ena_dev->intr_moder_tx_interval *
1305
+ prev_intr_delay_resolution /
1306
+ intr_delay_resolution;
1307
+
1308
+ ena_dev->intr_delay_resolution = intr_delay_resolution;
11391309 }
11401310
11411311 /*****************************************************************************/
....@@ -1198,7 +1368,7 @@
11981368 &create_cmd.cq_ba,
11991369 io_cq->cdesc_addr.phys_addr);
12001370 if (unlikely(ret)) {
1201
- pr_err("memory address set failed\n");
1371
+ pr_err("Memory address set failed\n");
12021372 return ret;
12031373 }
12041374
....@@ -1227,7 +1397,7 @@
12271397 (u32 __iomem *)((uintptr_t)ena_dev->reg_bar +
12281398 cmd_completion.numa_node_register_offset);
12291399
1230
- pr_debug("created cq[%u], depth[%u]\n", io_cq->idx, io_cq->q_depth);
1400
+ pr_debug("Created cq[%u], depth[%u]\n", io_cq->idx, io_cq->q_depth);
12311401
12321402 return ret;
12331403 }
....@@ -1271,12 +1441,14 @@
12711441 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev)
12721442 {
12731443 struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue;
1274
- unsigned long flags;
1444
+ unsigned long flags = 0;
1445
+ u32 exp = 0;
12751446
12761447 spin_lock_irqsave(&admin_queue->q_lock, flags);
12771448 while (atomic_read(&admin_queue->outstanding_cmds) != 0) {
12781449 spin_unlock_irqrestore(&admin_queue->q_lock, flags);
1279
- msleep(ENA_POLL_MS);
1450
+ ena_delay_exponential_backoff_us(exp++,
1451
+ ena_dev->ena_min_poll_delay_us);
12801452 spin_lock_irqsave(&admin_queue->q_lock, flags);
12811453 }
12821454 spin_unlock_irqrestore(&admin_queue->q_lock, flags);
....@@ -1315,7 +1487,7 @@
13151487 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state)
13161488 {
13171489 struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue;
1318
- unsigned long flags;
1490
+ unsigned long flags = 0;
13191491
13201492 spin_lock_irqsave(&admin_queue->q_lock, flags);
13211493 ena_dev->admin_queue.running_state = state;
....@@ -1342,14 +1514,14 @@
13421514 struct ena_admin_get_feat_resp get_resp;
13431515 int ret;
13441516
1345
- ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_AENQ_CONFIG);
1517
+ ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_AENQ_CONFIG, 0);
13461518 if (ret) {
13471519 pr_info("Can't get aenq configuration\n");
13481520 return ret;
13491521 }
13501522
13511523 if ((get_resp.u.aenq.supported_groups & groups_flag) != groups_flag) {
1352
- pr_warn("Trying to set unsupported aenq events. supported flag: %x asked flag: %x\n",
1524
+ pr_warn("Trying to set unsupported aenq events. supported flag: 0x%x asked flag: 0x%x\n",
13531525 get_resp.u.aenq.supported_groups, groups_flag);
13541526 return -EOPNOTSUPP;
13551527 }
....@@ -1418,17 +1590,12 @@
14181590 return -ETIME;
14191591 }
14201592
1421
- pr_info("ena device version: %d.%d\n",
1593
+ pr_info("ENA device version: %d.%d\n",
14221594 (ver & ENA_REGS_VERSION_MAJOR_VERSION_MASK) >>
14231595 ENA_REGS_VERSION_MAJOR_VERSION_SHIFT,
14241596 ver & ENA_REGS_VERSION_MINOR_VERSION_MASK);
14251597
1426
- if (ver < MIN_ENA_VER) {
1427
- pr_err("ENA version is lower than the minimal version the driver supports\n");
1428
- return -1;
1429
- }
1430
-
1431
- pr_info("ena controller version: %d.%d.%d implementation version %d\n",
1598
+ pr_info("ENA controller version: %d.%d.%d implementation version %d\n",
14321599 (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_MAJOR_VERSION_MASK) >>
14331600 ENA_REGS_CONTROLLER_VERSION_MAJOR_VERSION_SHIFT,
14341601 (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_MINOR_VERSION_MASK) >>
....@@ -1451,6 +1618,19 @@
14511618 return 0;
14521619 }
14531620
1621
+static void
1622
+ena_com_free_ena_admin_queue_comp_ctx(struct ena_com_dev *ena_dev,
1623
+ struct ena_com_admin_queue *admin_queue)
1624
+
1625
+{
1626
+ if (!admin_queue->comp_ctx)
1627
+ return;
1628
+
1629
+ devm_kfree(ena_dev->dmadev, admin_queue->comp_ctx);
1630
+
1631
+ admin_queue->comp_ctx = NULL;
1632
+}
1633
+
14541634 void ena_com_admin_destroy(struct ena_com_dev *ena_dev)
14551635 {
14561636 struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue;
....@@ -1459,9 +1639,8 @@
14591639 struct ena_com_aenq *aenq = &ena_dev->aenq;
14601640 u16 size;
14611641
1462
- if (admin_queue->comp_ctx)
1463
- devm_kfree(ena_dev->dmadev, admin_queue->comp_ctx);
1464
- admin_queue->comp_ctx = NULL;
1642
+ ena_com_free_ena_admin_queue_comp_ctx(ena_dev, admin_queue);
1643
+
14651644 size = ADMIN_SQ_SIZE(admin_queue->q_depth);
14661645 if (sq->entries)
14671646 dma_free_coherent(ena_dev->dmadev, size, sq->entries,
....@@ -1492,17 +1671,23 @@
14921671 ena_dev->admin_queue.polling = polling;
14931672 }
14941673
1674
+void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
1675
+ bool polling)
1676
+{
1677
+ ena_dev->admin_queue.auto_polling = polling;
1678
+}
1679
+
14951680 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev)
14961681 {
14971682 struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read;
14981683
14991684 spin_lock_init(&mmio_read->lock);
15001685 mmio_read->read_resp =
1501
- dma_zalloc_coherent(ena_dev->dmadev,
1502
- sizeof(*mmio_read->read_resp),
1503
- &mmio_read->read_resp_dma_addr, GFP_KERNEL);
1686
+ dma_alloc_coherent(ena_dev->dmadev,
1687
+ sizeof(*mmio_read->read_resp),
1688
+ &mmio_read->read_resp_dma_addr, GFP_KERNEL);
15041689 if (unlikely(!mmio_read->read_resp))
1505
- return -ENOMEM;
1690
+ goto err;
15061691
15071692 ena_com_mmio_reg_read_request_write_dev_addr(ena_dev);
15081693
....@@ -1511,6 +1696,10 @@
15111696 mmio_read->readless_supported = true;
15121697
15131698 return 0;
1699
+
1700
+err:
1701
+
1702
+ return -ENOMEM;
15141703 }
15151704
15161705 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev, bool readless_supported)
....@@ -1546,8 +1735,7 @@
15461735 }
15471736
15481737 int ena_com_admin_init(struct ena_com_dev *ena_dev,
1549
- struct ena_aenq_handlers *aenq_handlers,
1550
- bool init_spinlock)
1738
+ struct ena_aenq_handlers *aenq_handlers)
15511739 {
15521740 struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue;
15531741 u32 aq_caps, acq_caps, dev_sts, addr_low, addr_high;
....@@ -1573,8 +1761,7 @@
15731761
15741762 atomic_set(&admin_queue->outstanding_cmds, 0);
15751763
1576
- if (init_spinlock)
1577
- spin_lock_init(&admin_queue->q_lock);
1764
+ spin_lock_init(&admin_queue->q_lock);
15781765
15791766 ret = ena_com_init_comp_ctxt(admin_queue);
15801767 if (ret)
....@@ -1621,6 +1808,7 @@
16211808 if (ret)
16221809 goto error;
16231810
1811
+ admin_queue->ena_dev = ena_dev;
16241812 admin_queue->running_state = true;
16251813
16261814 return 0;
....@@ -1714,7 +1902,7 @@
17141902 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
17151903 struct ena_admin_get_feat_resp *resp)
17161904 {
1717
- return ena_com_get_feature(ena_dev, resp, ENA_ADMIN_LINK_CONFIG);
1905
+ return ena_com_get_feature(ena_dev, resp, ENA_ADMIN_LINK_CONFIG, 0);
17181906 }
17191907
17201908 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
....@@ -1724,25 +1912,43 @@
17241912 int rc;
17251913
17261914 rc = ena_com_get_feature(ena_dev, &get_resp,
1727
- ENA_ADMIN_DEVICE_ATTRIBUTES);
1915
+ ENA_ADMIN_DEVICE_ATTRIBUTES, 0);
17281916 if (rc)
17291917 return rc;
17301918
17311919 memcpy(&get_feat_ctx->dev_attr, &get_resp.u.dev_attr,
17321920 sizeof(get_resp.u.dev_attr));
1921
+
17331922 ena_dev->supported_features = get_resp.u.dev_attr.supported_features;
17341923
1735
- rc = ena_com_get_feature(ena_dev, &get_resp,
1736
- ENA_ADMIN_MAX_QUEUES_NUM);
1737
- if (rc)
1738
- return rc;
1924
+ if (ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) {
1925
+ rc = ena_com_get_feature(ena_dev, &get_resp,
1926
+ ENA_ADMIN_MAX_QUEUES_EXT,
1927
+ ENA_FEATURE_MAX_QUEUE_EXT_VER);
1928
+ if (rc)
1929
+ return rc;
17391930
1740
- memcpy(&get_feat_ctx->max_queues, &get_resp.u.max_queue,
1741
- sizeof(get_resp.u.max_queue));
1742
- ena_dev->tx_max_header_size = get_resp.u.max_queue.max_header_size;
1931
+ if (get_resp.u.max_queue_ext.version != ENA_FEATURE_MAX_QUEUE_EXT_VER)
1932
+ return -EINVAL;
1933
+
1934
+ memcpy(&get_feat_ctx->max_queue_ext, &get_resp.u.max_queue_ext,
1935
+ sizeof(get_resp.u.max_queue_ext));
1936
+ ena_dev->tx_max_header_size =
1937
+ get_resp.u.max_queue_ext.max_queue_ext.max_tx_header_size;
1938
+ } else {
1939
+ rc = ena_com_get_feature(ena_dev, &get_resp,
1940
+ ENA_ADMIN_MAX_QUEUES_NUM, 0);
1941
+ memcpy(&get_feat_ctx->max_queues, &get_resp.u.max_queue,
1942
+ sizeof(get_resp.u.max_queue));
1943
+ ena_dev->tx_max_header_size =
1944
+ get_resp.u.max_queue.max_header_size;
1945
+
1946
+ if (rc)
1947
+ return rc;
1948
+ }
17431949
17441950 rc = ena_com_get_feature(ena_dev, &get_resp,
1745
- ENA_ADMIN_AENQ_CONFIG);
1951
+ ENA_ADMIN_AENQ_CONFIG, 0);
17461952 if (rc)
17471953 return rc;
17481954
....@@ -1750,7 +1956,7 @@
17501956 sizeof(get_resp.u.aenq));
17511957
17521958 rc = ena_com_get_feature(ena_dev, &get_resp,
1753
- ENA_ADMIN_STATELESS_OFFLOAD_CONFIG);
1959
+ ENA_ADMIN_STATELESS_OFFLOAD_CONFIG, 0);
17541960 if (rc)
17551961 return rc;
17561962
....@@ -1760,7 +1966,7 @@
17601966 /* Driver hints isn't mandatory admin command. So in case the
17611967 * command isn't supported set driver hints to 0
17621968 */
1763
- rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_HW_HINTS);
1969
+ rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_HW_HINTS, 0);
17641970
17651971 if (!rc)
17661972 memcpy(&get_feat_ctx->hw_hints, &get_resp.u.hw_hints,
....@@ -1768,6 +1974,15 @@
17681974 else if (rc == -EOPNOTSUPP)
17691975 memset(&get_feat_ctx->hw_hints, 0x0,
17701976 sizeof(get_feat_ctx->hw_hints));
1977
+ else
1978
+ return rc;
1979
+
1980
+ rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_LLQ, 0);
1981
+ if (!rc)
1982
+ memcpy(&get_feat_ctx->llq, &get_resp.u.llq,
1983
+ sizeof(get_resp.u.llq));
1984
+ else if (rc == -EOPNOTSUPP)
1985
+ memset(&get_feat_ctx->llq, 0x0, sizeof(get_feat_ctx->llq));
17711986 else
17721987 return rc;
17731988
....@@ -1782,10 +1997,10 @@
17821997 /* ena_handle_specific_aenq_event:
17831998 * return the handler that is relevant to the specific event group
17841999 */
1785
-static ena_aenq_handler ena_com_get_specific_aenq_cb(struct ena_com_dev *dev,
2000
+static ena_aenq_handler ena_com_get_specific_aenq_cb(struct ena_com_dev *ena_dev,
17862001 u16 group)
17872002 {
1788
- struct ena_aenq_handlers *aenq_handlers = dev->aenq.aenq_handlers;
2003
+ struct ena_aenq_handlers *aenq_handlers = ena_dev->aenq.aenq_handlers;
17892004
17902005 if ((group < ENA_MAX_HANDLERS) && aenq_handlers->handlers[group])
17912006 return aenq_handlers->handlers[group];
....@@ -1797,11 +2012,12 @@
17972012 * handles the aenq incoming events.
17982013 * pop events from the queue and apply the specific handler
17992014 */
1800
-void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data)
2015
+void ena_com_aenq_intr_handler(struct ena_com_dev *ena_dev, void *data)
18012016 {
18022017 struct ena_admin_aenq_entry *aenq_e;
18032018 struct ena_admin_aenq_common_desc *aenq_common;
1804
- struct ena_com_aenq *aenq = &dev->aenq;
2019
+ struct ena_com_aenq *aenq = &ena_dev->aenq;
2020
+ u64 timestamp;
18052021 ena_aenq_handler handler_cb;
18062022 u16 masked_head, processed = 0;
18072023 u8 phase;
....@@ -1819,13 +2035,14 @@
18192035 */
18202036 dma_rmb();
18212037
1822
- pr_debug("AENQ! Group[%x] Syndrom[%x] timestamp: [%llus]\n",
1823
- aenq_common->group, aenq_common->syndrom,
1824
- (u64)aenq_common->timestamp_low +
1825
- ((u64)aenq_common->timestamp_high << 32));
2038
+ timestamp = (u64)aenq_common->timestamp_low |
2039
+ ((u64)aenq_common->timestamp_high << 32);
2040
+
2041
+ pr_debug("AENQ! Group[%x] Syndrome[%x] timestamp: [%llus]\n",
2042
+ aenq_common->group, aenq_common->syndrome, timestamp);
18262043
18272044 /* Handle specific event*/
1828
- handler_cb = ena_com_get_specific_aenq_cb(dev,
2045
+ handler_cb = ena_com_get_specific_aenq_cb(ena_dev,
18292046 aenq_common->group);
18302047 handler_cb(data, aenq_e); /* call the actual event handler*/
18312048
....@@ -1851,8 +2068,7 @@
18512068 /* write the aenq doorbell after all AENQ descriptors were read */
18522069 mb();
18532070 writel_relaxed((u32)aenq->head,
1854
- dev->reg_bar + ENA_REGS_AENQ_HEAD_DB_OFF);
1855
- mmiowb();
2071
+ ena_dev->reg_bar + ENA_REGS_AENQ_HEAD_DB_OFF);
18562072 }
18572073
18582074 int ena_com_dev_reset(struct ena_com_dev *ena_dev,
....@@ -1944,6 +2160,21 @@
19442160 return ret;
19452161 }
19462162
2163
+int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
2164
+ struct ena_admin_eni_stats *stats)
2165
+{
2166
+ struct ena_com_stats_ctx ctx;
2167
+ int ret;
2168
+
2169
+ memset(&ctx, 0x0, sizeof(ctx));
2170
+ ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_ENI);
2171
+ if (likely(ret == 0))
2172
+ memcpy(stats, &ctx.get_resp.u.eni_stats,
2173
+ sizeof(ctx.get_resp.u.eni_stats));
2174
+
2175
+ return ret;
2176
+}
2177
+
19472178 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
19482179 struct ena_admin_basic_stats *stats)
19492180 {
....@@ -1953,8 +2184,8 @@
19532184 memset(&ctx, 0x0, sizeof(ctx));
19542185 ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_BASIC);
19552186 if (likely(ret == 0))
1956
- memcpy(stats, &ctx.get_resp.basic_stats,
1957
- sizeof(ctx.get_resp.basic_stats));
2187
+ memcpy(stats, &ctx.get_resp.u.basic_stats,
2188
+ sizeof(ctx.get_resp.u.basic_stats));
19582189
19592190 return ret;
19602191 }
....@@ -1998,7 +2229,7 @@
19982229 struct ena_admin_get_feat_resp resp;
19992230
20002231 ret = ena_com_get_feature(ena_dev, &resp,
2001
- ENA_ADMIN_STATELESS_OFFLOAD_CONFIG);
2232
+ ENA_ADMIN_STATELESS_OFFLOAD_CONFIG, 0);
20022233 if (unlikely(ret)) {
20032234 pr_err("Failed to get offload capabilities %d\n", ret);
20042235 return ret;
....@@ -2027,7 +2258,7 @@
20272258
20282259 /* Validate hash function is supported */
20292260 ret = ena_com_get_feature(ena_dev, &get_resp,
2030
- ENA_ADMIN_RSS_HASH_FUNCTION);
2261
+ ENA_ADMIN_RSS_HASH_FUNCTION, 0);
20312262 if (unlikely(ret))
20322263 return ret;
20332264
....@@ -2050,7 +2281,7 @@
20502281 &cmd.control_buffer.address,
20512282 rss->hash_key_dma_addr);
20522283 if (unlikely(ret)) {
2053
- pr_err("memory address set failed\n");
2284
+ pr_err("Memory address set failed\n");
20542285 return ret;
20552286 }
20562287
....@@ -2074,11 +2305,13 @@
20742305 enum ena_admin_hash_functions func,
20752306 const u8 *key, u16 key_len, u32 init_val)
20762307 {
2077
- struct ena_rss *rss = &ena_dev->rss;
2308
+ struct ena_admin_feature_rss_flow_hash_control *hash_key;
20782309 struct ena_admin_get_feat_resp get_resp;
2079
- struct ena_admin_feature_rss_flow_hash_control *hash_key =
2080
- rss->hash_key;
2310
+ enum ena_admin_hash_functions old_func;
2311
+ struct ena_rss *rss = &ena_dev->rss;
20812312 int rc;
2313
+
2314
+ hash_key = rss->hash_key;
20822315
20832316 /* Make sure size is a mult of DWs */
20842317 if (unlikely(key_len & 0x3))
....@@ -2087,11 +2320,11 @@
20872320 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
20882321 ENA_ADMIN_RSS_HASH_FUNCTION,
20892322 rss->hash_key_dma_addr,
2090
- sizeof(*rss->hash_key));
2323
+ sizeof(*rss->hash_key), 0);
20912324 if (unlikely(rc))
20922325 return rc;
20932326
2094
- if (!((1 << func) & get_resp.u.flow_hash_func.supported_func)) {
2327
+ if (!(BIT(func) & get_resp.u.flow_hash_func.supported_func)) {
20952328 pr_err("Flow hash function %d isn't supported\n", func);
20962329 return -EOPNOTSUPP;
20972330 }
....@@ -2106,7 +2339,7 @@
21062339 }
21072340 memcpy(hash_key->key, key, key_len);
21082341 rss->hash_init_val = init_val;
2109
- hash_key->keys_num = key_len >> 2;
2342
+ hash_key->key_parts = key_len / sizeof(hash_key->key[0]);
21102343 }
21112344 break;
21122345 case ENA_ADMIN_CRC32:
....@@ -2117,24 +2350,22 @@
21172350 return -EINVAL;
21182351 }
21192352
2353
+ old_func = rss->hash_func;
21202354 rss->hash_func = func;
21212355 rc = ena_com_set_hash_function(ena_dev);
21222356
21232357 /* Restore the old function */
21242358 if (unlikely(rc))
2125
- ena_com_get_hash_function(ena_dev, NULL, NULL);
2359
+ rss->hash_func = old_func;
21262360
21272361 return rc;
21282362 }
21292363
21302364 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
2131
- enum ena_admin_hash_functions *func,
2132
- u8 *key)
2365
+ enum ena_admin_hash_functions *func)
21332366 {
21342367 struct ena_rss *rss = &ena_dev->rss;
21352368 struct ena_admin_get_feat_resp get_resp;
2136
- struct ena_admin_feature_rss_flow_hash_control *hash_key =
2137
- rss->hash_key;
21382369 int rc;
21392370
21402371 if (unlikely(!func))
....@@ -2143,7 +2374,7 @@
21432374 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
21442375 ENA_ADMIN_RSS_HASH_FUNCTION,
21452376 rss->hash_key_dma_addr,
2146
- sizeof(*rss->hash_key));
2377
+ sizeof(*rss->hash_key), 0);
21472378 if (unlikely(rc))
21482379 return rc;
21492380
....@@ -2154,8 +2385,17 @@
21542385
21552386 *func = rss->hash_func;
21562387
2388
+ return 0;
2389
+}
2390
+
2391
+int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key)
2392
+{
2393
+ struct ena_admin_feature_rss_flow_hash_control *hash_key =
2394
+ ena_dev->rss.hash_key;
2395
+
21572396 if (key)
2158
- memcpy(key, hash_key->key, (size_t)(hash_key->keys_num) << 2);
2397
+ memcpy(key, hash_key->key,
2398
+ (size_t)(hash_key->key_parts) * sizeof(hash_key->key[0]));
21592399
21602400 return 0;
21612401 }
....@@ -2171,7 +2411,7 @@
21712411 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
21722412 ENA_ADMIN_RSS_HASH_INPUT,
21732413 rss->hash_ctrl_dma_addr,
2174
- sizeof(*rss->hash_ctrl));
2414
+ sizeof(*rss->hash_ctrl), 0);
21752415 if (unlikely(rc))
21762416 return rc;
21772417
....@@ -2211,7 +2451,7 @@
22112451 &cmd.control_buffer.address,
22122452 rss->hash_ctrl_dma_addr);
22132453 if (unlikely(ret)) {
2214
- pr_err("memory address set failed\n");
2454
+ pr_err("Memory address set failed\n");
22152455 return ret;
22162456 }
22172457 cmd.control_buffer.length = sizeof(*hash_ctrl);
....@@ -2272,7 +2512,7 @@
22722512 available_fields = hash_ctrl->selected_fields[i].fields &
22732513 hash_ctrl->supported_fields[i].fields;
22742514 if (available_fields != hash_ctrl->selected_fields[i].fields) {
2275
- pr_err("hash control doesn't support all the desire configuration. proto %x supported %x selected %x\n",
2515
+ pr_err("Hash control doesn't support all the desire configuration. proto %x supported %x selected %x\n",
22762516 i, hash_ctrl->supported_fields[i].fields,
22772517 hash_ctrl->selected_fields[i].fields);
22782518 return -EOPNOTSUPP;
....@@ -2310,7 +2550,7 @@
23102550 /* Make sure all the fields are supported */
23112551 supported_fields = hash_ctrl->supported_fields[proto].fields;
23122552 if ((hash_fields & supported_fields) != hash_fields) {
2313
- pr_err("proto %d doesn't support the required fields %x. supports only: %x\n",
2553
+ pr_err("Proto %d doesn't support the required fields %x. supports only: %x\n",
23142554 proto, hash_fields, supported_fields);
23152555 }
23162556
....@@ -2350,9 +2590,9 @@
23502590 int ret;
23512591
23522592 if (!ena_com_check_supported_feature_id(
2353
- ena_dev, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG)) {
2593
+ ena_dev, ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG)) {
23542594 pr_debug("Feature %d isn't supported\n",
2355
- ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
2595
+ ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG);
23562596 return -EOPNOTSUPP;
23572597 }
23582598
....@@ -2367,7 +2607,7 @@
23672607 cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE;
23682608 cmd.aq_common_descriptor.flags =
23692609 ENA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK;
2370
- cmd.feat_common.feature_id = ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG;
2610
+ cmd.feat_common.feature_id = ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG;
23712611 cmd.u.ind_table.size = rss->tbl_log_size;
23722612 cmd.u.ind_table.inline_index = 0xFFFFFFFF;
23732613
....@@ -2375,7 +2615,7 @@
23752615 &cmd.control_buffer.address,
23762616 rss->rss_ind_tbl_dma_addr);
23772617 if (unlikely(ret)) {
2378
- pr_err("memory address set failed\n");
2618
+ pr_err("Memory address set failed\n");
23792619 return ret;
23802620 }
23812621
....@@ -2405,18 +2645,14 @@
24052645 sizeof(struct ena_admin_rss_ind_table_entry);
24062646
24072647 rc = ena_com_get_feature_ex(ena_dev, &get_resp,
2408
- ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG,
2648
+ ENA_ADMIN_RSS_INDIRECTION_TABLE_CONFIG,
24092649 rss->rss_ind_tbl_dma_addr,
2410
- tbl_size);
2650
+ tbl_size, 0);
24112651 if (unlikely(rc))
24122652 return rc;
24132653
24142654 if (!ind_tbl)
24152655 return 0;
2416
-
2417
- rc = ena_com_ind_tbl_convert_from_device(ena_dev);
2418
- if (unlikely(rc))
2419
- return rc;
24202656
24212657 for (i = 0; i < (1 << rss->tbl_log_size); i++)
24222658 ind_tbl[i] = rss->host_rss_ind_tbl[i];
....@@ -2434,11 +2670,15 @@
24342670 if (unlikely(rc))
24352671 goto err_indr_tbl;
24362672
2673
+ /* The following function might return unsupported in case the
2674
+ * device doesn't support setting the key / hash function. We can safely
2675
+ * ignore this error and have indirection table support only.
2676
+ */
24372677 rc = ena_com_hash_key_allocate(ena_dev);
2438
- if (unlikely(rc))
2678
+ if (likely(!rc))
2679
+ ena_com_hash_key_fill_default_key(ena_dev);
2680
+ else if (rc != -EOPNOTSUPP)
24392681 goto err_hash_key;
2440
-
2441
- ena_com_hash_key_fill_default_key(ena_dev);
24422682
24432683 rc = ena_com_hash_ctrl_init(ena_dev);
24442684 if (unlikely(rc))
....@@ -2469,10 +2709,14 @@
24692709 struct ena_host_attribute *host_attr = &ena_dev->host_attr;
24702710
24712711 host_attr->host_info =
2472
- dma_zalloc_coherent(ena_dev->dmadev, SZ_4K,
2473
- &host_attr->host_info_dma_addr, GFP_KERNEL);
2712
+ dma_alloc_coherent(ena_dev->dmadev, SZ_4K,
2713
+ &host_attr->host_info_dma_addr, GFP_KERNEL);
24742714 if (unlikely(!host_attr->host_info))
24752715 return -ENOMEM;
2716
+
2717
+ host_attr->host_info->ena_spec_version = ((ENA_COMMON_SPEC_VERSION_MAJOR <<
2718
+ ENA_REGS_VERSION_MAJOR_VERSION_SHIFT) |
2719
+ (ENA_COMMON_SPEC_VERSION_MINOR));
24762720
24772721 return 0;
24782722 }
....@@ -2483,8 +2727,8 @@
24832727 struct ena_host_attribute *host_attr = &ena_dev->host_attr;
24842728
24852729 host_attr->debug_area_virt_addr =
2486
- dma_zalloc_coherent(ena_dev->dmadev, debug_area_size,
2487
- &host_attr->debug_area_dma_addr, GFP_KERNEL);
2730
+ dma_alloc_coherent(ena_dev->dmadev, debug_area_size,
2731
+ &host_attr->debug_area_dma_addr, GFP_KERNEL);
24882732 if (unlikely(!host_attr->debug_area_virt_addr)) {
24892733 host_attr->debug_area_size = 0;
24902734 return -ENOMEM;
....@@ -2541,7 +2785,7 @@
25412785 &cmd.u.host_attr.debug_ba,
25422786 host_attr->debug_area_dma_addr);
25432787 if (unlikely(ret)) {
2544
- pr_err("memory address set failed\n");
2788
+ pr_err("Memory address set failed\n");
25452789 return ret;
25462790 }
25472791
....@@ -2549,7 +2793,7 @@
25492793 &cmd.u.host_attr.os_info_ba,
25502794 host_attr->host_info_dma_addr);
25512795 if (unlikely(ret)) {
2552
- pr_err("memory address set failed\n");
2796
+ pr_err("Memory address set failed\n");
25532797 return ret;
25542798 }
25552799
....@@ -2574,42 +2818,34 @@
25742818 ENA_ADMIN_INTERRUPT_MODERATION);
25752819 }
25762820
2577
-int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
2578
- u32 tx_coalesce_usecs)
2821
+static int ena_com_update_nonadaptive_moderation_interval(u32 coalesce_usecs,
2822
+ u32 intr_delay_resolution,
2823
+ u32 *intr_moder_interval)
25792824 {
2580
- if (!ena_dev->intr_delay_resolution) {
2825
+ if (!intr_delay_resolution) {
25812826 pr_err("Illegal interrupt delay granularity value\n");
25822827 return -EFAULT;
25832828 }
25842829
2585
- ena_dev->intr_moder_tx_interval = tx_coalesce_usecs /
2586
- ena_dev->intr_delay_resolution;
2830
+ *intr_moder_interval = coalesce_usecs / intr_delay_resolution;
25872831
25882832 return 0;
2833
+}
2834
+
2835
+int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
2836
+ u32 tx_coalesce_usecs)
2837
+{
2838
+ return ena_com_update_nonadaptive_moderation_interval(tx_coalesce_usecs,
2839
+ ena_dev->intr_delay_resolution,
2840
+ &ena_dev->intr_moder_tx_interval);
25892841 }
25902842
25912843 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
25922844 u32 rx_coalesce_usecs)
25932845 {
2594
- if (!ena_dev->intr_delay_resolution) {
2595
- pr_err("Illegal interrupt delay granularity value\n");
2596
- return -EFAULT;
2597
- }
2598
-
2599
- /* We use LOWEST entry of moderation table for storing
2600
- * nonadaptive interrupt coalescing values
2601
- */
2602
- ena_dev->intr_moder_tbl[ENA_INTR_MODER_LOWEST].intr_moder_interval =
2603
- rx_coalesce_usecs / ena_dev->intr_delay_resolution;
2604
-
2605
- return 0;
2606
-}
2607
-
2608
-void ena_com_destroy_interrupt_moderation(struct ena_com_dev *ena_dev)
2609
-{
2610
- if (ena_dev->intr_moder_tbl)
2611
- devm_kfree(ena_dev->dmadev, ena_dev->intr_moder_tbl);
2612
- ena_dev->intr_moder_tbl = NULL;
2846
+ return ena_com_update_nonadaptive_moderation_interval(rx_coalesce_usecs,
2847
+ ena_dev->intr_delay_resolution,
2848
+ &ena_dev->intr_moder_rx_interval);
26132849 }
26142850
26152851 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev)
....@@ -2619,7 +2855,7 @@
26192855 int rc;
26202856
26212857 rc = ena_com_get_feature(ena_dev, &get_resp,
2622
- ENA_ADMIN_INTERRUPT_MODERATION);
2858
+ ENA_ADMIN_INTERRUPT_MODERATION, 0);
26232859
26242860 if (rc) {
26252861 if (rc == -EOPNOTSUPP) {
....@@ -2636,62 +2872,14 @@
26362872 return rc;
26372873 }
26382874
2639
- rc = ena_com_init_interrupt_moderation_table(ena_dev);
2640
- if (rc)
2641
- goto err;
2642
-
26432875 /* if moderation is supported by device we set adaptive moderation */
26442876 delay_resolution = get_resp.u.intr_moderation.intr_delay_resolution;
26452877 ena_com_update_intr_delay_resolution(ena_dev, delay_resolution);
2646
- ena_com_enable_adaptive_moderation(ena_dev);
2878
+
2879
+ /* Disable adaptive moderation by default - can be enabled later */
2880
+ ena_com_disable_adaptive_moderation(ena_dev);
26472881
26482882 return 0;
2649
-err:
2650
- ena_com_destroy_interrupt_moderation(ena_dev);
2651
- return rc;
2652
-}
2653
-
2654
-void ena_com_config_default_interrupt_moderation_table(struct ena_com_dev *ena_dev)
2655
-{
2656
- struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl;
2657
-
2658
- if (!intr_moder_tbl)
2659
- return;
2660
-
2661
- intr_moder_tbl[ENA_INTR_MODER_LOWEST].intr_moder_interval =
2662
- ENA_INTR_LOWEST_USECS;
2663
- intr_moder_tbl[ENA_INTR_MODER_LOWEST].pkts_per_interval =
2664
- ENA_INTR_LOWEST_PKTS;
2665
- intr_moder_tbl[ENA_INTR_MODER_LOWEST].bytes_per_interval =
2666
- ENA_INTR_LOWEST_BYTES;
2667
-
2668
- intr_moder_tbl[ENA_INTR_MODER_LOW].intr_moder_interval =
2669
- ENA_INTR_LOW_USECS;
2670
- intr_moder_tbl[ENA_INTR_MODER_LOW].pkts_per_interval =
2671
- ENA_INTR_LOW_PKTS;
2672
- intr_moder_tbl[ENA_INTR_MODER_LOW].bytes_per_interval =
2673
- ENA_INTR_LOW_BYTES;
2674
-
2675
- intr_moder_tbl[ENA_INTR_MODER_MID].intr_moder_interval =
2676
- ENA_INTR_MID_USECS;
2677
- intr_moder_tbl[ENA_INTR_MODER_MID].pkts_per_interval =
2678
- ENA_INTR_MID_PKTS;
2679
- intr_moder_tbl[ENA_INTR_MODER_MID].bytes_per_interval =
2680
- ENA_INTR_MID_BYTES;
2681
-
2682
- intr_moder_tbl[ENA_INTR_MODER_HIGH].intr_moder_interval =
2683
- ENA_INTR_HIGH_USECS;
2684
- intr_moder_tbl[ENA_INTR_MODER_HIGH].pkts_per_interval =
2685
- ENA_INTR_HIGH_PKTS;
2686
- intr_moder_tbl[ENA_INTR_MODER_HIGH].bytes_per_interval =
2687
- ENA_INTR_HIGH_BYTES;
2688
-
2689
- intr_moder_tbl[ENA_INTR_MODER_HIGHEST].intr_moder_interval =
2690
- ENA_INTR_HIGHEST_USECS;
2691
- intr_moder_tbl[ENA_INTR_MODER_HIGHEST].pkts_per_interval =
2692
- ENA_INTR_HIGHEST_PKTS;
2693
- intr_moder_tbl[ENA_INTR_MODER_HIGHEST].bytes_per_interval =
2694
- ENA_INTR_HIGHEST_BYTES;
26952883 }
26962884
26972885 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev)
....@@ -2701,47 +2889,34 @@
27012889
27022890 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev)
27032891 {
2704
- struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl;
2892
+ return ena_dev->intr_moder_rx_interval;
2893
+}
27052894
2706
- if (intr_moder_tbl)
2707
- return intr_moder_tbl[ENA_INTR_MODER_LOWEST].intr_moder_interval;
2895
+int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
2896
+ struct ena_admin_feature_llq_desc *llq_features,
2897
+ struct ena_llq_configurations *llq_default_cfg)
2898
+{
2899
+ struct ena_com_llq_info *llq_info = &ena_dev->llq_info;
2900
+ int rc;
2901
+
2902
+ if (!llq_features->max_llq_num) {
2903
+ ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
2904
+ return 0;
2905
+ }
2906
+
2907
+ rc = ena_com_config_llq_info(ena_dev, llq_features, llq_default_cfg);
2908
+ if (rc)
2909
+ return rc;
2910
+
2911
+ ena_dev->tx_max_header_size = llq_info->desc_list_entry_size -
2912
+ (llq_info->descs_num_before_header * sizeof(struct ena_eth_io_tx_desc));
2913
+
2914
+ if (unlikely(ena_dev->tx_max_header_size == 0)) {
2915
+ pr_err("The size of the LLQ entry is smaller than needed\n");
2916
+ return -EINVAL;
2917
+ }
2918
+
2919
+ ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_DEV;
27082920
27092921 return 0;
2710
-}
2711
-
2712
-void ena_com_init_intr_moderation_entry(struct ena_com_dev *ena_dev,
2713
- enum ena_intr_moder_level level,
2714
- struct ena_intr_moder_entry *entry)
2715
-{
2716
- struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl;
2717
-
2718
- if (level >= ENA_INTR_MAX_NUM_OF_LEVELS)
2719
- return;
2720
-
2721
- intr_moder_tbl[level].intr_moder_interval = entry->intr_moder_interval;
2722
- if (ena_dev->intr_delay_resolution)
2723
- intr_moder_tbl[level].intr_moder_interval /=
2724
- ena_dev->intr_delay_resolution;
2725
- intr_moder_tbl[level].pkts_per_interval = entry->pkts_per_interval;
2726
-
2727
- /* use hardcoded value until ethtool supports bytecount parameter */
2728
- if (entry->bytes_per_interval != ENA_INTR_BYTE_COUNT_NOT_SUPPORTED)
2729
- intr_moder_tbl[level].bytes_per_interval = entry->bytes_per_interval;
2730
-}
2731
-
2732
-void ena_com_get_intr_moderation_entry(struct ena_com_dev *ena_dev,
2733
- enum ena_intr_moder_level level,
2734
- struct ena_intr_moder_entry *entry)
2735
-{
2736
- struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl;
2737
-
2738
- if (level >= ENA_INTR_MAX_NUM_OF_LEVELS)
2739
- return;
2740
-
2741
- entry->intr_moder_interval = intr_moder_tbl[level].intr_moder_interval;
2742
- if (ena_dev->intr_delay_resolution)
2743
- entry->intr_moder_interval *= ena_dev->intr_delay_resolution;
2744
- entry->pkts_per_interval =
2745
- intr_moder_tbl[level].pkts_per_interval;
2746
- entry->bytes_per_interval = intr_moder_tbl[level].bytes_per_interval;
27472922 }