Skip to content

Commit 408cf83

Browse files
committed
Merge branch 'ena-new-features-and-improvements'
Netanel Belgazal says: ==================== net: update ena ethernet driver to version 1.2.0 This patchset contains some new features/improvements that were added to the ENA driver to increase its robustness and are based on experience of wide ENA deployment. Change log: V2: * Remove patch that add inline to C-file static function (contradict coding style). * Remove patch that moves MTU parameter validation in ena_change_mtu() instead of using the network stack. * Use upper_32_bits()/lower_32_bits() instead of casting. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 926f38e + 8523899 commit 408cf83

8 files changed

Lines changed: 399 additions & 113 deletions

File tree

‎drivers/net/ethernet/amazon/ena/ena_admin_defs.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ enum ena_admin_aq_feature_id {
7070

7171
ENA_ADMIN_MAX_QUEUES_NUM = 2,
7272

73+
ENA_ADMIN_HW_HINTS = 3,
74+
7375
ENA_ADMIN_RSS_HASH_FUNCTION = 10,
7476

7577
ENA_ADMIN_STATELESS_OFFLOAD_CONFIG = 11,
@@ -749,6 +751,31 @@ struct ena_admin_feature_rss_ind_table {
749751
struct ena_admin_rss_ind_table_entry inline_entry;
750752
};
751753

754+
/* When hint value is 0, driver should use it's own predefined value */
755+
struct ena_admin_ena_hw_hints {
756+
/* value in ms */
757+
u16 mmio_read_timeout;
758+
759+
/* value in ms */
760+
u16 driver_watchdog_timeout;
761+
762+
/* Per packet tx completion timeout. value in ms */
763+
u16 missing_tx_completion_timeout;
764+
765+
u16 missed_tx_completion_count_threshold_to_reset;
766+
767+
/* value in ms */
768+
u16 admin_completion_tx_timeout;
769+
770+
u16 netdev_wd_timeout;
771+
772+
u16 max_tx_sgl_size;
773+
774+
u16 max_rx_sgl_size;
775+
776+
u16 reserved[8];
777+
};
778+
752779
struct ena_admin_get_feat_cmd {
753780
struct ena_admin_aq_common_desc aq_common_descriptor;
754781

@@ -782,6 +809,8 @@ struct ena_admin_get_feat_resp {
782809
struct ena_admin_feature_rss_ind_table ind_table;
783810

784811
struct ena_admin_feature_intr_moder_desc intr_moderation;
812+
813+
struct ena_admin_ena_hw_hints hw_hints;
785814
} u;
786815
};
787816

@@ -857,6 +886,8 @@ enum ena_admin_aenq_notification_syndrom {
857886
ENA_ADMIN_SUSPEND = 0,
858887

859888
ENA_ADMIN_RESUME = 1,
889+
890+
ENA_ADMIN_UPDATE_HINTS = 2,
860891
};
861892

862893
struct ena_admin_aenq_entry {

‎drivers/net/ethernet/amazon/ena/ena_com.c‎

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ static inline int ena_com_mem_addr_set(struct ena_com_dev *ena_dev,
9999
return -EINVAL;
100100
}
101101

102-
ena_addr->mem_addr_low = (u32)addr;
103-
ena_addr->mem_addr_high = (u64)addr >> 32;
102+
ena_addr->mem_addr_low = lower_32_bits(addr);
103+
ena_addr->mem_addr_high = (u16)upper_32_bits(addr);
104104

105105
return 0;
106106
}
@@ -329,7 +329,7 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_dev,
329329
size_t size;
330330
int dev_node = 0;
331331

332-
memset(&io_sq->desc_addr, 0x0, sizeof(struct ena_com_io_desc_addr));
332+
memset(&io_sq->desc_addr, 0x0, sizeof(io_sq->desc_addr));
333333

334334
io_sq->desc_entry_size =
335335
(io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) ?
@@ -383,7 +383,7 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_dev,
383383
size_t size;
384384
int prev_node = 0;
385385

386-
memset(&io_cq->cdesc_addr, 0x0, sizeof(struct ena_com_io_desc_addr));
386+
memset(&io_cq->cdesc_addr, 0x0, sizeof(io_cq->cdesc_addr));
387387

388388
/* Use the basic completion descriptor for Rx */
389389
io_cq->cdesc_entry_size_in_bytes =
@@ -494,7 +494,7 @@ static int ena_com_comp_status_to_errno(u8 comp_status)
494494
case ENA_ADMIN_RESOURCE_ALLOCATION_FAILURE:
495495
return -ENOMEM;
496496
case ENA_ADMIN_UNSUPPORTED_OPCODE:
497-
return -EPERM;
497+
return -EOPNOTSUPP;
498498
case ENA_ADMIN_BAD_OPCODE:
499499
case ENA_ADMIN_MALFORMED_REQUEST:
500500
case ENA_ADMIN_ILLEGAL_PARAMETER:
@@ -511,7 +511,7 @@ static int ena_com_wait_and_process_admin_cq_polling(struct ena_comp_ctx *comp_c
511511
unsigned long flags, timeout;
512512
int ret;
513513

514-
timeout = jiffies + ADMIN_CMD_TIMEOUT_US;
514+
timeout = jiffies + usecs_to_jiffies(admin_queue->completion_timeout);
515515

516516
while (1) {
517517
spin_lock_irqsave(&admin_queue->q_lock, flags);
@@ -561,7 +561,8 @@ static int ena_com_wait_and_process_admin_cq_interrupts(struct ena_comp_ctx *com
561561
int ret;
562562

563563
wait_for_completion_timeout(&comp_ctx->wait_event,
564-
usecs_to_jiffies(ADMIN_CMD_TIMEOUT_US));
564+
usecs_to_jiffies(
565+
admin_queue->completion_timeout));
565566

566567
/* In case the command wasn't completed find out the root cause.
567568
* There might be 2 kinds of errors
@@ -601,12 +602,15 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev *ena_dev, u16 offset)
601602
struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read;
602603
volatile struct ena_admin_ena_mmio_req_read_less_resp *read_resp =
603604
mmio_read->read_resp;
604-
u32 mmio_read_reg, ret;
605+
u32 mmio_read_reg, ret, i;
605606
unsigned long flags;
606-
int i;
607+
u32 timeout = mmio_read->reg_read_to;
607608

608609
might_sleep();
609610

611+
if (timeout == 0)
612+
timeout = ENA_REG_READ_TIMEOUT;
613+
610614
/* If readless is disabled, perform regular read */
611615
if (!mmio_read->readless_supported)
612616
return readl(ena_dev->reg_bar + offset);
@@ -627,14 +631,14 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev *ena_dev, u16 offset)
627631

628632
writel(mmio_read_reg, ena_dev->reg_bar + ENA_REGS_MMIO_REG_READ_OFF);
629633

630-
for (i = 0; i < ENA_REG_READ_TIMEOUT; i++) {
634+
for (i = 0; i < timeout; i++) {
631635
if (read_resp->req_id == mmio_read->seq_num)
632636
break;
633637

634638
udelay(1);
635639
}
636640

637-
if (unlikely(i == ENA_REG_READ_TIMEOUT)) {
641+
if (unlikely(i == timeout)) {
638642
pr_err("reading reg failed for timeout. expected: req id[%hu] offset[%hu] actual: req id[%hu] offset[%hu]\n",
639643
mmio_read->seq_num, offset, read_resp->req_id,
640644
read_resp->reg_off);
@@ -681,7 +685,7 @@ static int ena_com_destroy_io_sq(struct ena_com_dev *ena_dev,
681685
u8 direction;
682686
int ret;
683687

684-
memset(&destroy_cmd, 0x0, sizeof(struct ena_admin_aq_destroy_sq_cmd));
688+
memset(&destroy_cmd, 0x0, sizeof(destroy_cmd));
685689

686690
if (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX)
687691
direction = ENA_ADMIN_SQ_DIRECTION_TX;
@@ -786,7 +790,7 @@ static int ena_com_get_feature_ex(struct ena_com_dev *ena_dev,
786790

787791
if (!ena_com_check_supported_feature_id(ena_dev, feature_id)) {
788792
pr_debug("Feature %d isn't supported\n", feature_id);
789-
return -EPERM;
793+
return -EOPNOTSUPP;
790794
}
791795

792796
memset(&get_cmd, 0x0, sizeof(get_cmd));
@@ -963,7 +967,7 @@ static int ena_com_create_io_sq(struct ena_com_dev *ena_dev,
963967
u8 direction;
964968
int ret;
965969

966-
memset(&create_cmd, 0x0, sizeof(struct ena_admin_aq_create_sq_cmd));
970+
memset(&create_cmd, 0x0, sizeof(create_cmd));
967971

968972
create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_SQ;
969973

@@ -1155,7 +1159,7 @@ int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
11551159
struct ena_admin_acq_create_cq_resp_desc cmd_completion;
11561160
int ret;
11571161

1158-
memset(&create_cmd, 0x0, sizeof(struct ena_admin_aq_create_cq_cmd));
1162+
memset(&create_cmd, 0x0, sizeof(create_cmd));
11591163

11601164
create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_CQ;
11611165

@@ -1263,7 +1267,7 @@ int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
12631267
struct ena_admin_acq_destroy_cq_resp_desc destroy_resp;
12641268
int ret;
12651269

1266-
memset(&destroy_cmd, 0x0, sizeof(struct ena_admin_aq_destroy_sq_cmd));
1270+
memset(&destroy_cmd, 0x0, sizeof(destroy_cmd));
12671271

12681272
destroy_cmd.cq_idx = io_cq->idx;
12691273
destroy_cmd.aq_common_descriptor.opcode = ENA_ADMIN_DESTROY_CQ;
@@ -1324,7 +1328,7 @@ int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag)
13241328
if ((get_resp.u.aenq.supported_groups & groups_flag) != groups_flag) {
13251329
pr_warn("Trying to set unsupported aenq events. supported flag: %x asked flag: %x\n",
13261330
get_resp.u.aenq.supported_groups, groups_flag);
1327-
return -EPERM;
1331+
return -EOPNOTSUPP;
13281332
}
13291333

13301334
memset(&cmd, 0x0, sizeof(cmd));
@@ -1619,8 +1623,8 @@ int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
16191623
io_sq = &ena_dev->io_sq_queues[ctx->qid];
16201624
io_cq = &ena_dev->io_cq_queues[ctx->qid];
16211625

1622-
memset(io_sq, 0x0, sizeof(struct ena_com_io_sq));
1623-
memset(io_cq, 0x0, sizeof(struct ena_com_io_cq));
1626+
memset(io_sq, 0x0, sizeof(*io_sq));
1627+
memset(io_cq, 0x0, sizeof(*io_cq));
16241628

16251629
/* Init CQ */
16261630
io_cq->q_depth = ctx->queue_size;
@@ -1730,6 +1734,20 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
17301734
memcpy(&get_feat_ctx->offload, &get_resp.u.offload,
17311735
sizeof(get_resp.u.offload));
17321736

1737+
/* Driver hints isn't mandatory admin command. So in case the
1738+
* command isn't supported set driver hints to 0
1739+
*/
1740+
rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_HW_HINTS);
1741+
1742+
if (!rc)
1743+
memcpy(&get_feat_ctx->hw_hints, &get_resp.u.hw_hints,
1744+
sizeof(get_resp.u.hw_hints));
1745+
else if (rc == -EOPNOTSUPP)
1746+
memset(&get_feat_ctx->hw_hints, 0x0,
1747+
sizeof(get_feat_ctx->hw_hints));
1748+
else
1749+
return rc;
1750+
17331751
return 0;
17341752
}
17351753

@@ -1807,7 +1825,8 @@ void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data)
18071825
writel((u32)aenq->head, dev->reg_bar + ENA_REGS_AENQ_HEAD_DB_OFF);
18081826
}
18091827

1810-
int ena_com_dev_reset(struct ena_com_dev *ena_dev)
1828+
int ena_com_dev_reset(struct ena_com_dev *ena_dev,
1829+
enum ena_regs_reset_reason_types reset_reason)
18111830
{
18121831
u32 stat, timeout, cap, reset_val;
18131832
int rc;
@@ -1835,6 +1854,8 @@ int ena_com_dev_reset(struct ena_com_dev *ena_dev)
18351854

18361855
/* start reset */
18371856
reset_val = ENA_REGS_DEV_CTL_DEV_RESET_MASK;
1857+
reset_val |= (reset_reason << ENA_REGS_DEV_CTL_RESET_REASON_SHIFT) &
1858+
ENA_REGS_DEV_CTL_RESET_REASON_MASK;
18381859
writel(reset_val, ena_dev->reg_bar + ENA_REGS_DEV_CTL_OFF);
18391860

18401861
/* Write again the MMIO read request address */
@@ -1855,6 +1876,14 @@ int ena_com_dev_reset(struct ena_com_dev *ena_dev)
18551876
return rc;
18561877
}
18571878

1879+
timeout = (cap & ENA_REGS_CAPS_ADMIN_CMD_TO_MASK) >>
1880+
ENA_REGS_CAPS_ADMIN_CMD_TO_SHIFT;
1881+
if (timeout)
1882+
/* the resolution of timeout reg is 100ms */
1883+
ena_dev->admin_queue.completion_timeout = timeout * 100000;
1884+
else
1885+
ena_dev->admin_queue.completion_timeout = ADMIN_CMD_TIMEOUT_US;
1886+
18581887
return 0;
18591888
}
18601889

@@ -1909,7 +1938,7 @@ int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu)
19091938

19101939
if (!ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_MTU)) {
19111940
pr_debug("Feature %d isn't supported\n", ENA_ADMIN_MTU);
1912-
return -EPERM;
1941+
return -EOPNOTSUPP;
19131942
}
19141943

19151944
memset(&cmd, 0x0, sizeof(cmd));
@@ -1963,7 +1992,7 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev)
19631992
ENA_ADMIN_RSS_HASH_FUNCTION)) {
19641993
pr_debug("Feature %d isn't supported\n",
19651994
ENA_ADMIN_RSS_HASH_FUNCTION);
1966-
return -EPERM;
1995+
return -EOPNOTSUPP;
19671996
}
19681997

19691998
/* Validate hash function is supported */
@@ -1975,7 +2004,7 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev)
19752004
if (get_resp.u.flow_hash_func.supported_func & (1 << rss->hash_func)) {
19762005
pr_err("Func hash %d isn't supported by device, abort\n",
19772006
rss->hash_func);
1978-
return -EPERM;
2007+
return -EOPNOTSUPP;
19792008
}
19802009

19812010
memset(&cmd, 0x0, sizeof(cmd));
@@ -2034,7 +2063,7 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
20342063

20352064
if (!((1 << func) & get_resp.u.flow_hash_func.supported_func)) {
20362065
pr_err("Flow hash function %d isn't supported\n", func);
2037-
return -EPERM;
2066+
return -EOPNOTSUPP;
20382067
}
20392068

20402069
switch (func) {
@@ -2127,7 +2156,7 @@ int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev)
21272156
ENA_ADMIN_RSS_HASH_INPUT)) {
21282157
pr_debug("Feature %d isn't supported\n",
21292158
ENA_ADMIN_RSS_HASH_INPUT);
2130-
return -EPERM;
2159+
return -EOPNOTSUPP;
21312160
}
21322161

21332162
memset(&cmd, 0x0, sizeof(cmd));
@@ -2208,7 +2237,7 @@ int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev)
22082237
pr_err("hash control doesn't support all the desire configuration. proto %x supported %x selected %x\n",
22092238
i, hash_ctrl->supported_fields[i].fields,
22102239
hash_ctrl->selected_fields[i].fields);
2211-
return -EPERM;
2240+
return -EOPNOTSUPP;
22122241
}
22132242
}
22142243

@@ -2286,7 +2315,7 @@ int ena_com_indirect_table_set(struct ena_com_dev *ena_dev)
22862315
ena_dev, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG)) {
22872316
pr_debug("Feature %d isn't supported\n",
22882317
ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
2289-
return -EPERM;
2318+
return -EOPNOTSUPP;
22902319
}
22912320

22922321
ret = ena_com_ind_tbl_convert_to_device(ena_dev);
@@ -2553,7 +2582,7 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev)
25532582
ENA_ADMIN_INTERRUPT_MODERATION);
25542583

25552584
if (rc) {
2556-
if (rc == -EPERM) {
2585+
if (rc == -EOPNOTSUPP) {
25572586
pr_debug("Feature %d isn't supported\n",
25582587
ENA_ADMIN_INTERRUPT_MODERATION);
25592588
rc = 0;

‎drivers/net/ethernet/amazon/ena/ena_com.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
#define ENA_INTR_MODER_LEVEL_STRIDE 2
9898
#define ENA_INTR_BYTE_COUNT_NOT_SUPPORTED 0xFFFFFF
9999

100+
#define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
101+
100102
enum ena_intr_moder_level {
101103
ENA_INTR_MODER_LOWEST = 0,
102104
ENA_INTR_MODER_LOW,
@@ -232,7 +234,9 @@ struct ena_com_stats_admin {
232234
struct ena_com_admin_queue {
233235
void *q_dmadev;
234236
spinlock_t q_lock; /* spinlock for the admin queue */
237+
235238
struct ena_comp_ctx *comp_ctx;
239+
u32 completion_timeout;
236240
u16 q_depth;
237241
struct ena_com_admin_cq cq;
238242
struct ena_com_admin_sq sq;
@@ -267,6 +271,7 @@ struct ena_com_aenq {
267271
struct ena_com_mmio_read {
268272
struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
269273
dma_addr_t read_resp_dma_addr;
274+
u32 reg_read_to; /* in us */
270275
u16 seq_num;
271276
bool readless_supported;
272277
/* spin lock to ensure a single outstanding read */
@@ -336,6 +341,7 @@ struct ena_com_dev_get_features_ctx {
336341
struct ena_admin_device_attr_feature_desc dev_attr;
337342
struct ena_admin_feature_aenq_desc aenq;
338343
struct ena_admin_feature_offload_desc offload;
344+
struct ena_admin_ena_hw_hints hw_hints;
339345
};
340346

341347
struct ena_com_create_io_ctx {
@@ -414,10 +420,12 @@ void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
414420

415421
/* ena_com_dev_reset - Perform device FLR to the device.
416422
* @ena_dev: ENA communication layer struct
423+
* @reset_reason: Specify what is the trigger for the reset in case of an error.
417424
*
418425
* @return - 0 on success, negative value on failure.
419426
*/
420-
int ena_com_dev_reset(struct ena_com_dev *ena_dev);
427+
int ena_com_dev_reset(struct ena_com_dev *ena_dev,
428+
enum ena_regs_reset_reason_types reset_reason);
421429

422430
/* ena_com_create_io_queue - Create io queue.
423431
* @ena_dev: ENA communication layer struct

0 commit comments

Comments
 (0)