aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDawid Gorecki <dgr@semihalf.com>2022-06-10 09:18:08 +0000
committerMarcin Wojtas <mw@FreeBSD.org>2022-06-30 15:31:37 +0000
commit90232d18ca4f7a5a3073a8279a9b9d3228df5f87 (patch)
tree38f59b6f81a8be18d25996c8ca0e95292c901f53 /sys
parenta9c39b031fe89a6414174e3db82da6548d7fff0f (diff)
downloadsrc-90232d18ca4f7a5a3073a8279a9b9d3228df5f87.tar.gz
src-90232d18ca4f7a5a3073a8279a9b9d3228df5f87.zip
ena: Prevent LLQ initialization when membar isn't exposed
The ena_com_config_dev_mode() function performs many LLQ related calculations and sends an admin command to configure LLQ in the device. All the LLQ related operations are unnecessary if the driver fails to find LLQ memory bar. Move LLQ memory bar allocation to separate helper function ena_map_llq_mem_bar and execute this function before LLQ configuration. If the LLQ memory bar cannot be allocated, then LLQ configuration is skipped. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/ena/ena.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c
index 4527d2e2f298..b8c9efb288ea 100644
--- a/sys/dev/ena/ena.c
+++ b/sys/dev/ena/ena.c
@@ -155,6 +155,7 @@ static int ena_setup_ifnet(device_t, struct ena_adapter *,
static int ena_enable_wc(device_t, struct resource *);
static int ena_set_queues_placement_policy(device_t, struct ena_com_dev *,
struct ena_admin_feature_llq_desc *, struct ena_llq_configurations *);
+static int ena_map_llq_mem_bar(device_t, struct ena_com_dev *);
static uint32_t ena_calc_max_io_queue_num(device_t, struct ena_com_dev *,
struct ena_com_dev_get_features_ctx *);
static int ena_calc_io_queue_size(struct ena_calc_queue_size_ctx *);
@@ -2571,8 +2572,7 @@ ena_set_queues_placement_policy(device_t pdev, struct ena_com_dev *ena_dev,
struct ena_admin_feature_llq_desc *llq,
struct ena_llq_configurations *llq_default_configurations)
{
- struct ena_adapter *adapter = device_get_softc(pdev);
- int rc, rid;
+ int rc;
uint32_t llq_feature_mask;
llq_feature_mask = 1 << ENA_ADMIN_LLQ;
@@ -2583,17 +2583,28 @@ ena_set_queues_placement_policy(device_t pdev, struct ena_com_dev *ena_dev,
return (0);
}
+ if (ena_dev->mem_bar == NULL) {
+ ena_log(pdev, WARN,
+ "LLQ is advertised as supported but device doesn't expose mem bar.\n");
+ ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
+ return (0);
+ }
+
rc = ena_com_config_dev_mode(ena_dev, llq, llq_default_configurations);
if (unlikely(rc != 0)) {
ena_log(pdev, WARN, "Failed to configure the device mode. "
"Fallback to host mode policy.\n");
ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
- return (0);
}
- /* Nothing to config, exit */
- if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
- return (0);
+ return (0);
+}
+
+static int
+ena_map_llq_mem_bar(device_t pdev, struct ena_com_dev *ena_dev)
+{
+ struct ena_adapter *adapter = device_get_softc(pdev);
+ int rc, rid;
/* Try to allocate resources for LLQ bar */
rid = PCIR_BAR(ENA_MEM_BAR);
@@ -3595,6 +3606,12 @@ ena_attach(device_t pdev)
set_default_llq_configurations(&llq_config, &get_feat_ctx.llq);
+ rc = ena_map_llq_mem_bar(pdev, ena_dev);
+ if (unlikely(rc != 0)) {
+ ena_log(pdev, ERR, "failed to map ENA mem bar");
+ goto err_com_free;
+ }
+
rc = ena_set_queues_placement_policy(pdev, ena_dev, &get_feat_ctx.llq,
&llq_config);
if (unlikely(rc != 0)) {