svn commit: r368756 - head/contrib/jemalloc/src
Author: mw Date: Fri Dec 18 10:09:21 2020 New Revision: 368756 URL: https://svnweb.freebsd.org/changeset/base/368756 Log: Fix abort in jemalloc extent coalescing. Fix error in extent_try_coalesce_impl(), which could cause abort to happen when trying to coalesce extents backwards. The error could happen because of how extent_before_get() function works. This function gets address of previous extent, by subtracting page size from current extent address. If current extent is located at PAGE_SIZE offset, this address resolved to 0x. An assertion in rtree_leaf_elm_lookup then caused the running program to abort. This problem was discovered when trying to build world on 32-bit machines with ASLR and PIE enabled. The problem was encountered on armv7 and i386 machines, but most likely other 32-bit architectures are affected as well. While this patch fixes one problem with buildworld on 32-bit platforms with ASLR, the build still fails, however it happens much later and due to lack of memory. The change is aligned with accepted fix in the upstream Jemalloc repository (https://github.com/jemalloc/jemalloc/pull/1973). As it doesn't apply on top of Jemalloc tree, its updated version was eventually merged: https://github.com/jemalloc/jemalloc/pull/2003 PR: 249937 Submitted by: Dawid Gorecki Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D27025 Modified: head/contrib/jemalloc/src/extent.c Modified: head/contrib/jemalloc/src/extent.c == --- head/contrib/jemalloc/src/extent.c Fri Dec 18 10:08:11 2020 (r368755) +++ head/contrib/jemalloc/src/extent.c Fri Dec 18 10:09:21 2020 (r368756) @@ -1641,8 +1641,11 @@ extent_try_coalesce_impl(tsdn_t *tsdn, arena_t *arena, } /* Try to coalesce backward. */ - extent_t *prev = extent_lock_from_addr(tsdn, rtree_ctx, - extent_before_get(extent), inactive_only); + extent_t *prev = NULL; + if (extent_before_get(extent) != NULL) { + prev = extent_lock_from_addr(tsdn, rtree_ctx, + extent_before_get(extent), inactive_only); + } if (prev != NULL) { bool can_coalesce = extent_can_coalesce(arena, extents, extent, prev); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r367805 - head/sys/dev/ena
Author: mw Date: Wed Nov 18 15:25:38 2020 New Revision: 367805 URL: https://svnweb.freebsd.org/changeset/base/367805 Log: Update ENA driver version to v2.3.0 The v2.3.0 introduces new ena_com layer, ENI metrics updates and SPDX license tags. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27120 Modified: head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Wed Nov 18 15:23:43 2020(r367804) +++ head/sys/dev/ena/ena.h Wed Nov 18 15:25:38 2020(r367805) @@ -40,7 +40,7 @@ #include "ena-com/ena_eth_com.h" #define DRV_MODULE_VER_MAJOR 2 -#define DRV_MODULE_VER_MINOR 2 +#define DRV_MODULE_VER_MINOR 3 #define DRV_MODULE_VER_SUBMINOR 0 #define DRV_MODULE_NAME"ena" ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r367803 - head/sys/dev/ena
Author: mw Date: Wed Nov 18 15:20:01 2020 New Revision: 367803 URL: https://svnweb.freebsd.org/changeset/base/367803 Log: Rename descriptions of the supported ENA devices Some of the PCI ID were described as ENA with LLQ support - it's not fully accurate and because of that, their names were changed. Instead of LLQ, use RSERV0 for the description of those devices. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27119 Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Wed Nov 18 15:17:55 2020(r367802) +++ head/sys/dev/ena/ena.c Wed Nov 18 15:20:01 2020(r367803) @@ -179,9 +179,9 @@ static char ena_version[] = DEVICE_NAME DRV_MODULE_NAM static ena_vendor_info_t ena_vendor_info_array[] = { { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF, 0}, -{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_PF, 0}, +{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF_RSERV0, 0}, { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_VF, 0}, -{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_VF, 0}, +{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_VF_RSERV0, 0}, /* Last entry */ { 0, 0, 0 } }; Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Wed Nov 18 15:17:55 2020(r367802) +++ head/sys/dev/ena/ena.h Wed Nov 18 15:20:01 2020(r367803) @@ -150,10 +150,10 @@ */ #definePCI_VENDOR_ID_AMAZON0x1d0f -#definePCI_DEV_ID_ENA_PF 0x0ec2 -#definePCI_DEV_ID_ENA_LLQ_PF 0x1ec2 -#definePCI_DEV_ID_ENA_VF 0xec20 -#definePCI_DEV_ID_ENA_LLQ_VF 0xec21 +#definePCI_DEV_ID_ENA_PF 0x0ec2 +#definePCI_DEV_ID_ENA_PF_RSERV00x1ec2 +#definePCI_DEV_ID_ENA_VF 0xec20 +#definePCI_DEV_ID_ENA_VF_RSERV00xec21 /* * Flags indicating current ENA driver state ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r367802 - head/sys/dev/ena
Author: mw Date: Wed Nov 18 15:17:55 2020 New Revision: 367802 URL: https://svnweb.freebsd.org/changeset/base/367802 Log: Add ENI metrics for the ENA driver The new HAL allows the driver to read extra ENI stats. Exact meaning of each of them can be found in base/ena_defs/ena_admin_defs.h file and structure ena_admin_eni_stats. Those stats are being updated inside of the timer service, which is executed every second. ENI metrics are turned off by default. They can be enabled, using the sysctl node: dev.ena.X.eni_metrics.update_delay 0 value in this node means that the update is turned off. Other values determine how many seconds must pass, before ENI metrics will be updated. They can be acquired, using sysctl: sysctl dev.ena.X.eni_metrics Where X stands for the interface number. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27118 Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Wed Nov 18 15:07:34 2020(r367801) +++ head/sys/dev/ena/ena.c Wed Nov 18 15:17:55 2020(r367802) @@ -172,6 +172,7 @@ static int ena_enable_msix_and_set_admin_interrupts(st static void ena_update_on_link_change(void *, struct ena_admin_aenq_entry *); static voidunimplemented_aenq_handler(void *, struct ena_admin_aenq_entry *); +static int ena_copy_eni_metrics(struct ena_adapter *); static voidena_timer_service(void *); static char ena_version[] = DEVICE_NAME DRV_MODULE_NAME " v" DRV_MODULE_VERSION; @@ -3215,6 +3216,44 @@ static void ena_update_hints(struct ena_adapter *adapt } } +/** + * ena_copy_eni_metrics - Get and copy ENI metrics from the HW. + * @adapter: ENA device adapter + * + * Returns 0 on success, EOPNOTSUPP if current HW doesn't support those metrics + * and other error codes on failure. + * + * This function can possibly cause a race with other calls to the admin queue. + * Because of that, the caller should either lock this function or make sure + * that there is no race in the current context. + */ +static int +ena_copy_eni_metrics(struct ena_adapter *adapter) +{ + static bool print_once = true; + int rc; + + rc = ena_com_get_eni_stats(adapter->ena_dev, &adapter->eni_metrics); + + if (rc != 0) { + if (rc == ENA_COM_UNSUPPORTED) { + if (print_once) { + device_printf(adapter->pdev, + "Retrieving ENI metrics is not supported.\n"); + print_once = false; + } else { + ena_trace(NULL, ENA_DBG, + "Retrieving ENI metrics is not supported.\n"); + } + } else { + device_printf(adapter->pdev, + "Failed to get ENI metrics: %d\n", rc); + } + } + + return (rc); +} + static void ena_timer_service(void *data) { @@ -3229,6 +3268,38 @@ ena_timer_service(void *data) check_for_missing_completions(adapter); check_for_empty_rx_ring(adapter); + + /* +* User controller update of the ENI metrics. +* If the delay was set to 0, then the stats shouldn't be updated at +* all. +* Otherwise, wait 'eni_metrics_sample_interval' seconds, before +* updating stats. +* As timer service is executed every second, it's enough to increment +* appropriate counter each time the timer service is executed. +*/ + if ((adapter->eni_metrics_sample_interval != 0) && + (++adapter->eni_metrics_sample_interval_cnt >= +adapter->eni_metrics_sample_interval)) { + /* +* There is no race with other admin queue calls, as: +* - Timer service runs after interface is up, so all +* configuration calls to the admin queue are finished. +* - After interface is up, the driver doesn't use (at least +* for now) other functions writing to the admin queue. +* +* It may change in the future, so in that situation, the lock +* will be needed. ENA_LOCK_*() cannot be used for that purpose, +* as callout ena_timer_service is protected by them. It could +* lead to the deadlock if callout_drain() would hold the lock +* before ena_copy_eni_metrics() was executed. It's advised to +* use separate lock in that situation which will be used only +* for the admin queue. +*/ +
svn commit: r367801 - in head: share/man/man4 sys/dev/ena sys/modules/ena
Author: mw Date: Wed Nov 18 15:07:34 2020 New Revision: 367801 URL: https://svnweb.freebsd.org/changeset/base/367801 Log: Add SPDX license tag to the ENA driver files Refering to guide: https://wiki.freebsd.org/SPDX the SPDX tag should not replace the standard license text, however it should be added over the standard license text to make the automation easier. Because of that, the old license was kept, but the SPDX tag was added on top of every ENA driver file. Submited by:Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27117 Modified: head/share/man/man4/ena.4 head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_datapath.h head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_netmap.h head/sys/dev/ena/ena_sysctl.c head/sys/dev/ena/ena_sysctl.h head/sys/modules/ena/Makefile Modified: head/share/man/man4/ena.4 == --- head/share/man/man4/ena.4 Wed Nov 18 15:02:12 2020(r367800) +++ head/share/man/man4/ena.4 Wed Nov 18 15:07:34 2020(r367801) @@ -1,4 +1,6 @@ -.\" Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates. +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Wed Nov 18 15:02:12 2020(r367800) +++ head/sys/dev/ena/ena.c Wed Nov 18 15:07:34 2020(r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Wed Nov 18 15:02:12 2020(r367800) +++ head/sys/dev/ena/ena.h Wed Nov 18 15:07:34 2020(r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena_datapath.c == --- head/sys/dev/ena/ena_datapath.c Wed Nov 18 15:02:12 2020 (r367800) +++ head/sys/dev/ena/ena_datapath.c Wed Nov 18 15:07:34 2020 (r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena_datapath.h == --- head/sys/dev/ena/ena_datapath.h Wed Nov 18 15:02:12 2020 (r367800) +++ head/sys/dev/ena/ena_datapath.h Wed Nov 18 15:07:34 2020 (r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena_netmap.c == --- head/sys/dev/ena/ena_netmap.c Wed Nov 18 15:02:12 2020 (r367800) +++ head/sys/dev/ena/ena_netmap.c Wed Nov 18 15:07:34 2020 (r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena_netmap.h == --- head/sys/dev/ena/ena_netmap.h Wed Nov 18 15:02:12 2020 (r367800) +++ head/sys/dev/ena/ena_netmap.h Wed Nov 18 15:07:34 2020 (r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena_sysctl.c == --- head/sys/dev/ena/ena_sysctl.c Wed Nov 18 15:02:12 2020 (r367800) +++ head/sys/dev/ena/ena_sysctl.c Wed Nov 18 15:07:34 2020 (r367801) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. Modified: head/sys/dev/ena/ena_sysctl.h == --- head/sys/dev/ena/ena_sysctl.h Wed Nov 18 15:02:12 2020 (r367800) +++ head/sys/dev/ena/ena_sysctl.h Wed Nov 18 15:07:34 2020 (r367801) @@ -1,5
svn commit: r367800 - head/sys/dev/ena
Author: mw Date: Wed Nov 18 15:02:12 2020 New Revision: 367800 URL: https://svnweb.freebsd.org/changeset/base/367800 Log: Add Rx offsets support for the ENA driver For the first descriptor in a chain the data may start at an offset. It is optional feature of some devices, so the driver must ack that it supports it. The data pointer of the mbuf is simply shifted by the given value. Submitted by: Maciej Bielski Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27116 Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena_datapath.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Wed Nov 18 14:59:22 2020(r367799) +++ head/sys/dev/ena/ena.c Wed Nov 18 15:02:12 2020(r367800) @@ -2797,6 +2797,8 @@ ena_config_host_info(struct ena_com_dev *ena_dev, devi (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) | (DRV_MODULE_VER_SUBMINOR << ENA_ADMIN_HOST_INFO_SUB_MINOR_SHIFT); host_info->num_cpus = mp_ncpus; + host_info->driver_supported_features = + ENA_ADMIN_HOST_INFO_RX_OFFSET_MASK; rc = ena_com_set_host_attributes(ena_dev); if (unlikely(rc != 0)) { Modified: head/sys/dev/ena/ena_datapath.c == --- head/sys/dev/ena/ena_datapath.c Wed Nov 18 14:59:22 2020 (r367799) +++ head/sys/dev/ena/ena_datapath.c Wed Nov 18 15:02:12 2020 (r367800) @@ -431,6 +431,10 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r mbuf->m_flags |= M_PKTHDR; mbuf->m_pkthdr.len = len; mbuf->m_len = len; + // Only for the first segment the data starts at specific offset + mbuf->m_data = mtodo(mbuf, ena_rx_ctx->pkt_offset); + ena_trace(NULL, ENA_DBG | ENA_RXPTH, + "Mbuf data offset=%u\n", ena_rx_ctx->pkt_offset); mbuf->m_pkthdr.rcvif = rx_ring->que->adapter->ifp; /* Fill mbuf with hash key and it's interpretation for optimization */ @@ -575,6 +579,8 @@ ena_rx_cleanup(struct ena_ring *rx_ring) ena_rx_ctx.ena_bufs = rx_ring->ena_bufs; ena_rx_ctx.max_bufs = adapter->max_rx_sgl_size; ena_rx_ctx.descs = 0; + ena_rx_ctx.pkt_offset = 0; + bus_dmamap_sync(io_cq->cdesc_addr.mem_handle.tag, io_cq->cdesc_addr.mem_handle.map, BUS_DMASYNC_POSTREAD); rc = ena_com_rx_pkt(io_cq, io_sq, &ena_rx_ctx); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r367799 - in head/sys: contrib/ena-com contrib/ena-com/ena_defs dev/ena
Author: mw Date: Wed Nov 18 14:59:22 2020 New Revision: 367799 URL: https://svnweb.freebsd.org/changeset/base/367799 Log: Adjust ENA driver files to latest ena-com changes * Use the new API of ena_trace_* * Fix typo syndrom --> syndrome * Remove validation of the Rx req ID (already performed in the ena-com) * Remove usage of deprecated ENA_ASSERT macro Submitted by: Ido Segev Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27115 Modified: head/sys/contrib/ena-com/ena_com.c head/sys/contrib/ena-com/ena_com.h head/sys/contrib/ena-com/ena_defs/ena_admin_defs.h head/sys/contrib/ena-com/ena_defs/ena_common_defs.h head/sys/contrib/ena-com/ena_defs/ena_eth_io_defs.h head/sys/contrib/ena-com/ena_defs/ena_gen_info.h head/sys/contrib/ena-com/ena_defs/ena_regs_defs.h head/sys/contrib/ena-com/ena_eth_com.c head/sys/contrib/ena-com/ena_eth_com.h head/sys/contrib/ena-com/ena_plat.h head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_netmap.c Directory Properties: head/sys/contrib/ena-com/ (props changed) Modified: head/sys/contrib/ena-com/ena_com.c == --- head/sys/contrib/ena-com/ena_com.c Wed Nov 18 14:55:49 2020 (r367798) +++ head/sys/contrib/ena-com/ena_com.c Wed Nov 18 14:59:22 2020 (r367799) @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. @@ -70,9 +70,9 @@ #define ENA_REGS_ADMIN_INTR_MASK 1 -#define ENA_MIN_POLL_US 100 +#define ENA_MIN_ADMIN_POLL_US 100 -#define ENA_MAX_POLL_US 5000 +#define ENA_MAX_ADMIN_POLL_US 5000 /*/ /*/ @@ -106,7 +106,7 @@ static int ena_com_mem_addr_set(struct ena_com_dev *en dma_addr_t addr) { if ((addr & GENMASK_ULL(ena_dev->dma_addr_bits - 1, 0)) != addr) { - ena_trc_err("dma address has more bits that the device supports\n"); + ena_trc_err(ena_dev, "DMA address has more bits that the device supports\n"); return ENA_COM_INVAL; } @@ -116,16 +116,17 @@ static int ena_com_mem_addr_set(struct ena_com_dev *en return 0; } -static int ena_com_admin_init_sq(struct ena_com_admin_queue *queue) +static int ena_com_admin_init_sq(struct ena_com_admin_queue *admin_queue) { - struct ena_com_admin_sq *sq = &queue->sq; - u16 size = ADMIN_SQ_SIZE(queue->q_depth); + struct ena_com_dev *ena_dev = admin_queue->ena_dev; + struct ena_com_admin_sq *sq = &admin_queue->sq; + u16 size = ADMIN_SQ_SIZE(admin_queue->q_depth); - ENA_MEM_ALLOC_COHERENT(queue->q_dmadev, size, sq->entries, sq->dma_addr, + ENA_MEM_ALLOC_COHERENT(admin_queue->q_dmadev, size, sq->entries, sq->dma_addr, sq->mem_handle); if (!sq->entries) { - ena_trc_err("memory allocation failed\n"); + ena_trc_err(ena_dev, "Memory allocation failed\n"); return ENA_COM_NO_MEM; } @@ -138,16 +139,17 @@ static int ena_com_admin_init_sq(struct ena_com_admin_ return 0; } -static int ena_com_admin_init_cq(struct ena_com_admin_queue *queue) +static int ena_com_admin_init_cq(struct ena_com_admin_queue *admin_queue) { - struct ena_com_admin_cq *cq = &queue->cq; - u16 size = ADMIN_CQ_SIZE(queue->q_depth); + struct ena_com_dev *ena_dev = admin_queue->ena_dev; + struct ena_com_admin_cq *cq = &admin_queue->cq; + u16 size = ADMIN_CQ_SIZE(admin_queue->q_depth); - ENA_MEM_ALLOC_COHERENT(queue->q_dmadev, size, cq->entries, cq->dma_addr, + ENA_MEM_ALLOC_COHERENT(admin_queue->q_dmadev, size, cq->entries, cq->dma_addr, cq->mem_handle); if (!cq->entries) { - ena_trc_err("memory allocation failed\n"); + ena_trc_err(ena_dev, "Memory allocation failed\n"); return ENA_COM_NO_MEM; } @@ -157,22 +159,22 @@ static int ena_com_admin_init_cq(struct ena_com_admin_ return 0; } -static int ena_com_admin_init_aenq(struct ena_com_dev *dev, +static int ena_com_admin_init_aenq(struct ena_com_dev *ena_dev, struct ena_aenq_handlers *aenq_handlers) { - struct ena_com_aenq *aenq = &dev->aenq; + struct ena_com_aenq *aenq = &ena_dev->aenq; u32 addr_low, addr_high, aenq_caps; u16 size; - dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH; + ena_dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH; size = ADMIN_AENQ_SIZE(ENA_ASYNC_Q
svn commit: r367795 - in head/sys: contrib/ena-com dev/ena
Author: mw Date: Wed Nov 18 14:50:12 2020 New Revision: 367795 URL: https://svnweb.freebsd.org/changeset/base/367795 Log: Fix completion descriptors alignment for the ENA The latest generation hardware requires IO CQ (completion queue) descriptors memory to be aligned to a 4K. It needs that feature for the best performance. Allocating unaligned descriptors will have a big performance impact as the packet processing in a HW won't be optimized properly. For that purpose adjust ena_dma_alloc() to support it. It's a critical fix, especially for the arm64 EC2 instances. Submitted by: Ido Segev Obtained from: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27114 Modified: head/sys/contrib/ena-com/ena_com.c head/sys/contrib/ena-com/ena_com.h head/sys/contrib/ena-com/ena_plat.h head/sys/dev/ena/ena.c Directory Properties: head/sys/contrib/ena-com/ (props changed) Modified: head/sys/contrib/ena-com/ena_com.c == --- head/sys/contrib/ena-com/ena_com.c Wed Nov 18 14:32:48 2020 (r367794) +++ head/sys/contrib/ena-com/ena_com.c Wed Nov 18 14:50:12 2020 (r367795) @@ -449,19 +449,21 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_ size = io_cq->cdesc_entry_size_in_bytes * io_cq->q_depth; io_cq->bus = ena_dev->bus; - ENA_MEM_ALLOC_COHERENT_NODE(ena_dev->dmadev, - size, - io_cq->cdesc_addr.virt_addr, - io_cq->cdesc_addr.phys_addr, - io_cq->cdesc_addr.mem_handle, - ctx->numa_node, - prev_node); + ENA_MEM_ALLOC_COHERENT_NODE_ALIGNED(ena_dev->dmadev, + size, + io_cq->cdesc_addr.virt_addr, + io_cq->cdesc_addr.phys_addr, + io_cq->cdesc_addr.mem_handle, + ctx->numa_node, + prev_node, + ENA_CDESC_RING_SIZE_ALIGNMENT); if (!io_cq->cdesc_addr.virt_addr) { - ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, - size, - io_cq->cdesc_addr.virt_addr, - io_cq->cdesc_addr.phys_addr, - io_cq->cdesc_addr.mem_handle); + ENA_MEM_ALLOC_COHERENT_ALIGNED(ena_dev->dmadev, + size, + io_cq->cdesc_addr.virt_addr, + io_cq->cdesc_addr.phys_addr, + io_cq->cdesc_addr.mem_handle, + ENA_CDESC_RING_SIZE_ALIGNMENT); } if (!io_cq->cdesc_addr.virt_addr) { Modified: head/sys/contrib/ena-com/ena_com.h == --- head/sys/contrib/ena-com/ena_com.h Wed Nov 18 14:32:48 2020 (r367794) +++ head/sys/contrib/ena-com/ena_com.h Wed Nov 18 14:50:12 2020 (r367795) @@ -51,6 +51,8 @@ #define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry)) #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry)) +#define ENA_CDESC_RING_SIZE_ALIGNMENT (1 << 12) /* 4K */ + /*/ /*/ /* ENA adaptive interrupt moderation settings */ Modified: head/sys/contrib/ena-com/ena_plat.h == --- head/sys/contrib/ena-com/ena_plat.h Wed Nov 18 14:32:48 2020 (r367794) +++ head/sys/contrib/ena-com/ena_plat.h Wed Nov 18 14:50:12 2020 (r367795) @@ -106,6 +106,8 @@ extern struct ena_bus_space ebs; #define ENA_ADMQ (1 << 8) /* Detailed info about admin queue. */ #define ENA_NETMAP (1 << 9) /* Detailed info about netmap. */ +#define DEFAULT_ALLOC_ALIGNMENT8 + extern int ena_log_level; #define ena_trace_raw(level, fmt, args...) \ @@ -285,7 +287,7 @@ typedef uint64_t ena_time_t; void ena_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nseg, int error); intena_dma_alloc(device_t dmadev, bus_size_t size, ena_mem_handle_t *dma, -int mapflags); +int mapflags, bus_size_t alignment); static inline uint32_t ena_reg_read32(struct ena_bus *bus, bus_size_t offset) @@ -313,19 +315,29 @@ ena_reg_read32(struct ena_bus *bus, bus_size_t offset) (void)(size);
Re: svn commit: r366106 - head/sys/arm64/arm64
Hi, With this commit SDHCI fails to allocate a bounce buffer for SDMA (sdhci_dma_alloc() routine). The same behavior was observed on LS1046A and Armada 7k8k. Example log: sdhci_xenon0: mem 0x78-0x7802ff irq 38 on simplebus3 getaddr: error 27 sdhci_xenon0-slot0: Can't load DMA memory for SDMA device_attach: sdhci_xenon0 attach returned 6 I debugged it a bit: * bus_dmamap_load returns EFBIG (error = 27) * The tag is created with an alignment to 128k (https://github.com/freebsd/freebsd/blob/master/sys/dev/sdhci/sdhci.c#L752) * When I set the alignment to anything =< PAGE_SIZE it works again: --- a/sys/dev/sdhci/sdhci.c +++ b/sys/dev/sdhci/sdhci.c @@ -749,7 +749,7 @@ sdhci_dma_alloc(struct sdhci_slot *slot) * forming the actual address of data, requiring the SDMA buffer to * be aligned to the SDMA boundary. */ - err = bus_dma_tag_create(bus_get_dma_tag(slot->bus), slot->sdma_bbufsz, + err = bus_dma_tag_create(bus_get_dma_tag(slot->bus), PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, slot->sdma_bbufsz, 1, slot->sdma_bbufsz, BUS_DMA_ALLOCNOW, NULL, NULL, &slot->dmatag); I don't know if it's a valid fix though given a comment in code above (Linux however aligns DMA buffer to 512). Comments appreciated. Any reason why the huge alignment value worked before the r366106 and now it is problematic? Best regards, Marcin czw., 24 wrz 2020 o 09:17 Andrew Turner napisał(a): > > Author: andrew > Date: Thu Sep 24 07:17:05 2020 > New Revision: 366106 > URL: https://svnweb.freebsd.org/changeset/base/366106 > > Log: > Bounce in more cases in the arm64 busdma > > We need to use a bounce buffer when the memory we are operating on is not > aligned to a cacheline, and not aligned to the maps alignment. > > The former is to stop other threads from dirtying the cacheline while we > are performing DMA operations with it. The latter is to check memory > passed in by a driver is correctly aligned for the device. > > Reviewed by: mmel > Sponsored by: Innovate UK > Differential Revision:https://reviews.freebsd.org/D26496 > > Modified: > head/sys/arm64/arm64/busdma_bounce.c > > Modified: head/sys/arm64/arm64/busdma_bounce.c > == > --- head/sys/arm64/arm64/busdma_bounce.cThu Sep 24 07:13:13 2020 > (r366105) > +++ head/sys/arm64/arm64/busdma_bounce.cThu Sep 24 07:17:05 2020 > (r366106) > @@ -139,6 +139,7 @@ struct bus_dmamap { > u_int flags; > #defineDMAMAP_COHERENT (1 << 0) > #defineDMAMAP_FROM_DMAMEM (1 << 1) > +#defineDMAMAP_MBUF (1 << 2) > int sync_count; > struct sync_listslist[]; > }; > @@ -155,8 +156,8 @@ static bus_addr_t add_bounce_page(bus_dma_tag_t dmat, > vm_offset_t vaddr, bus_addr_t addr, bus_size_t size); > static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage); > int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); > -static bool _bus_dmamap_pagesneeded(bus_dma_tag_t dmat, vm_paddr_t buf, > -bus_size_t buflen, int *pagesneeded); > +static bool _bus_dmamap_pagesneeded(bus_dma_tag_t dmat, bus_dmamap_t map, > +vm_paddr_t buf, bus_size_t buflen, int *pagesneeded); > static void _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, > pmap_t pmap, void *buf, bus_size_t buflen, int flags); > static void _bus_dmamap_count_phys(bus_dma_tag_t dmat, bus_dmamap_t map, > @@ -164,20 +165,70 @@ static void _bus_dmamap_count_phys(bus_dma_tag_t dmat, > static int _bus_dmamap_reserve_pages(bus_dma_tag_t dmat, bus_dmamap_t map, > int flags); > > +/* > + * Return true if the DMA should bounce because the start or end does not > fall > + * on a cacheline boundary (which would require a partial cacheline flush). > + * COHERENT memory doesn't trigger cacheline flushes. Memory allocated by > + * bus_dmamem_alloc() is always aligned to cacheline boundaries, and there's > a > + * strict rule that such memory cannot be accessed by the CPU while DMA is in > + * progress (or by multiple DMA engines at once), so that it's always safe > to do > + * full cacheline flushes even if that affects memory outside the range of a > + * given DMA operation that doesn't involve the full allocated buffer. If > we're > + * mapping an mbuf, that follows the same rules as a buffer we allocated. > + */ > static bool > -might_bounce(bus_dma_tag_t dmat) > +cacheline_bounce(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t paddr, > +bus_size_t size) > { > > +#defineDMAMAP_CACHELINE_FLAGS > \ > +(DMAMAP_FROM_DMAMEM | DMAMAP_COHERENT | DMAMAP_MBUF) > + if ((dmat->bounce_flags & BF_COHERENT) != 0) > + return (false); > + if (map != NULL && (map->flags & DMAMAP_CACHE
svn commit: r366759 - head/sys/netipsec
Author: mw Date: Fri Oct 16 11:27:01 2020 New Revision: 366759 URL: https://svnweb.freebsd.org/changeset/base/366759 Log: Trigger soft lifetime expiration on sequence number This patch adds 80% of UINT32_MAX limit on sequence number. When sequence number reaches limit kernel sends SADB_EXPIRE message to IKE daemon which is responsible to perform rekeying. Submitted by: Patryk Duda Reviewed by:ae Differential revision: https://reviews.freebsd.org/D22370 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/netipsec/key.c Modified: head/sys/netipsec/key.c == --- head/sys/netipsec/key.c Fri Oct 16 11:25:45 2020(r366758) +++ head/sys/netipsec/key.c Fri Oct 16 11:27:01 2020(r366759) @@ -101,6 +101,7 @@ #define FULLMASK 0xff #define_BITS(bytes)((bytes) << 3) +#defineUINT32_80PCT0x /* * Note on SA reference counting: * - SAs that are not in DEAD state will have (total external reference + 1) @@ -4536,7 +4537,11 @@ key_flush_sad(time_t now) (sav->lft_s->usetime != 0 && sav->firstused && now - sav->firstused > sav->lft_s->usetime) || (sav->lft_s->bytes != 0 && counter_u64_fetch( - sav->lft_c_bytes) > sav->lft_s->bytes))) { + sav->lft_c_bytes) > sav->lft_s->bytes) || + (!(sav->flags & SADB_X_SAFLAGS_ESN) && + (sav->replay != NULL) && ( + (sav->replay->count > UINT32_80PCT) || + (sav->replay->last > UINT32_80PCT) { SECASVAR_UNLOCK(sav); SAV_ADDREF(sav); LIST_INSERT_HEAD(&sexpireq, sav, drainq); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r366758 - head/sys/netipsec
Author: mw Date: Fri Oct 16 11:25:45 2020 New Revision: 366758 URL: https://svnweb.freebsd.org/changeset/base/366758 Log: Add support for IPsec ESN and pass relevant information to crypto layer Implement support for including IPsec ESN (Extended Sequence Number) to both encrypt and authenticate mode (eg. AES-CBC and SHA256) and combined mode (eg. AES-GCM). Both ESP and AH protocols are updated. Additionally pass relevant information about ESN to crypto layer. For the ETA mode the ESN is stored in separate crp_esn buffer because the high-order 32 bits of the sequence number are appended after the Next Header (RFC 4303). For the AEAD modes the high-order 32 bits of the sequence number [e.g. RFC 4106, Chapter 5 AAD Construction] are included as part of crp_aad (SPI + ESN (32 high order bits) + Seq nr (32 low order bits)). Submitted by: Grzegorz Jaszczyk Patryk Duda Reviewed by:jhb, gnn Differential revision: https://reviews.freebsd.org/D22369 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/netipsec/keydb.h head/sys/netipsec/xform_ah.c head/sys/netipsec/xform_esp.c Modified: head/sys/netipsec/keydb.h == --- head/sys/netipsec/keydb.h Fri Oct 16 11:24:12 2020(r366757) +++ head/sys/netipsec/keydb.h Fri Oct 16 11:25:45 2020(r366758) @@ -197,6 +197,8 @@ struct secasvar { #defineSAV_ISCTR(_sav) ((_sav)->alg_enc == SADB_X_EALG_AESCTR) #define SAV_ISCTRORGCM(_sav) (SAV_ISCTR((_sav)) || SAV_ISGCM((_sav))) +#defineIPSEC_SEQH_SHIFT32 + /* Replay prevention, protected by SECASVAR_LOCK: * (m) locked by mtx * (c) read only except during creation / free Modified: head/sys/netipsec/xform_ah.c == --- head/sys/netipsec/xform_ah.cFri Oct 16 11:24:12 2020 (r366757) +++ head/sys/netipsec/xform_ah.cFri Oct 16 11:25:45 2020 (r366758) @@ -236,6 +236,10 @@ ah_init(struct secasvar *sav, struct xformsw *xsp) memset(&csp, 0, sizeof(csp)); csp.csp_mode = CSP_MODE_DIGEST; + + if (sav->flags & SADB_X_SAFLAGS_ESN) + csp.csp_flags |= CSP_F_ESN; + error = ah_init0(sav, xsp, &csp); return error ? error : crypto_newsession(&sav->tdb_cryptoid, &csp, V_crypto_support); @@ -654,6 +658,12 @@ ah_input(struct mbuf *m, struct secasvar *sav, int ski crp->crp_callback = ah_input_cb; crp->crp_opaque = xd; + if (sav->flags & SADB_X_SAFLAGS_ESN && + sav->replay != NULL && sav->replay->wsize != 0) { + seqh = htonl(seqh); + memcpy(crp->crp_esn, &seqh, sizeof(seqh)); + } + /* These are passed as-is to the callback. */ xd->sav = sav; xd->nxt = hl; @@ -834,6 +844,7 @@ ah_output(struct mbuf *m, struct secpolicy *sp, struct uint16_t iplen; int error, rplen, authsize, ahsize, maxpacketsize, roff; uint8_t prot; + uint32_t seqh; IPSEC_ASSERT(sav != NULL, ("null SA")); ahx = sav->tdb_authalgxform; @@ -1030,6 +1041,11 @@ ah_output(struct mbuf *m, struct secpolicy *sp, struct crypto_use_mbuf(crp, m); crp->crp_callback = ah_output_cb; crp->crp_opaque = xd; + + if (sav->flags & SADB_X_SAFLAGS_ESN && sav->replay != NULL) { + seqh = htonl((uint32_t)(sav->replay->count >> IPSEC_SEQH_SHIFT)); + memcpy(crp->crp_esn, &seqh, sizeof(seqh)); + } /* These are passed as-is to the callback. */ xd->sp = sp; Modified: head/sys/netipsec/xform_esp.c == --- head/sys/netipsec/xform_esp.c Fri Oct 16 11:24:12 2020 (r366757) +++ head/sys/netipsec/xform_esp.c Fri Oct 16 11:25:45 2020 (r366758) @@ -80,6 +80,8 @@ #include #include +#define SPI_SIZE 4 + VNET_DEFINE(int, esp_enable) = 1; VNET_DEFINE_STATIC(int, esp_ctr_compatibility) = 1; #define V_esp_ctr_compatibility VNET(esp_ctr_compatibility) @@ -219,9 +221,13 @@ esp_init(struct secasvar *sav, struct xformsw *xsp) return EINVAL; } csp.csp_mode = CSP_MODE_AEAD; - } else if (sav->alg_auth != 0) + if (sav->flags & SADB_X_SAFLAGS_ESN) + csp.csp_flags |= CSP_F_SEPARATE_AAD; + } else if (sav->alg_auth != 0) { csp.csp_mode = CSP_MODE_ETA; - else + if (sav->flags & SADB_X_SAFLAGS_ESN) + csp.csp_flags |= CSP_F_ESN; + } else csp.csp_mode = CSP_MODE_CIPHER; /* Initialize crypto session. */ @@ -263,6 +269,7 @@ esp_input(struct mbuf *m, struct secasvar *sav, int sk crypto
svn commit: r366757 - head/sys/netipsec
Author: mw Date: Fri Oct 16 11:24:12 2020 New Revision: 366757 URL: https://svnweb.freebsd.org/changeset/base/366757 Log: Implement anti-replay algorithm with ESN support As RFC 4304 describes there is anti-replay algorithm responsibility to provide appropriate value of Extended Sequence Number. This patch introduces anti-replay algorithm with ESN support based on RFC 4304, however to avoid performance regressions window implementation was based on RFC 6479, which was already implemented in FreeBSD. To keep things clean and improve code readability, implementation of window is kept in seperate functions. Submitted by: Grzegorz Jaszczyk Patryk Duda Reviewed by:jhb Differential revision: https://reviews.freebsd.org/D22367 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/netipsec/ipsec.c head/sys/netipsec/ipsec.h head/sys/netipsec/key_debug.c head/sys/netipsec/keydb.h head/sys/netipsec/xform_ah.c head/sys/netipsec/xform_esp.c Modified: head/sys/netipsec/ipsec.c == --- head/sys/netipsec/ipsec.c Fri Oct 16 11:23:30 2020(r366756) +++ head/sys/netipsec/ipsec.c Fri Oct 16 11:24:12 2020(r366757) @@ -1173,7 +1173,67 @@ ipsec_hdrsiz_inpcb(struct inpcb *inp) return (sz); } + +#define IPSEC_BITMAP_INDEX_MASK(w) (w - 1) +#define IPSEC_REDUNDANT_BIT_SHIFTS 5 +#define IPSEC_REDUNDANT_BITS (1 << IPSEC_REDUNDANT_BIT_SHIFTS) +#define IPSEC_BITMAP_LOC_MASK (IPSEC_REDUNDANT_BITS - 1) + /* + * Functions below are responsible for checking and updating bitmap. + * These are used to separate ipsec_chkreplay() and ipsec_updatereplay() + * from window implementation + * + * Based on RFC 6479. Blocks are 32 bits unsigned integers + */ + +static inline int +check_window(const struct secreplay *replay, uint64_t seq) +{ + int index, bit_location; + + bit_location = seq & IPSEC_BITMAP_LOC_MASK; + index = (seq >> IPSEC_REDUNDANT_BIT_SHIFTS) + & IPSEC_BITMAP_INDEX_MASK(replay->bitmap_size); + + /* This packet already seen? */ + return ((replay->bitmap)[index] & (1 << bit_location)); +} + +static inline void +advance_window(const struct secreplay *replay, uint64_t seq) +{ + int i; + uint64_t index, index_cur, diff; + + index_cur = replay->last >> IPSEC_REDUNDANT_BIT_SHIFTS; + index = seq >> IPSEC_REDUNDANT_BIT_SHIFTS; + diff = index - index_cur; + + if (diff > replay->bitmap_size) { + /* something unusual in this case */ + diff = replay->bitmap_size; + } + + for (i = 0; i < diff; i++) { + replay->bitmap[(i + index_cur + 1) + & IPSEC_BITMAP_INDEX_MASK(replay->bitmap_size)] = 0; + } +} + +static inline void +set_window(const struct secreplay *replay, uint64_t seq) +{ + int index, bit_location; + + bit_location = seq & IPSEC_BITMAP_LOC_MASK; + index = (seq >> IPSEC_REDUNDANT_BIT_SHIFTS) + & IPSEC_BITMAP_INDEX_MASK(replay->bitmap_size); + + replay->bitmap[index] |= (1 << bit_location); +} + +/* * Check the variable replay window. * ipsec_chkreplay() performs replay check before ICV verification. * ipsec_updatereplay() updates replay bitmap. This must be called after @@ -1181,20 +1241,17 @@ ipsec_hdrsiz_inpcb(struct inpcb *inp) * beforehand). * 0 (zero) is returned if packet disallowed, 1 if packet permitted. * - * Based on RFC 6479. Blocks are 32 bits unsigned integers + * Based on RFC 4303 */ -#define IPSEC_BITMAP_INDEX_MASK(w) (w - 1) -#define IPSEC_REDUNDANT_BIT_SHIFTS 5 -#define IPSEC_REDUNDANT_BITS (1 << IPSEC_REDUNDANT_BIT_SHIFTS) -#define IPSEC_BITMAP_LOC_MASK (IPSEC_REDUNDANT_BITS - 1) - int -ipsec_chkreplay(uint32_t seq, struct secasvar *sav) +ipsec_chkreplay(uint32_t seq, uint32_t *seqhigh, struct secasvar *sav) { - const struct secreplay *replay; - uint32_t wsizeb;/* Constant: window size. */ - int index, bit_location; + char buf[128]; + struct secreplay *replay; + uint32_t window; + uint32_t tl, th, bl; + uint32_t seqh; IPSEC_ASSERT(sav != NULL, ("Null SA")); IPSEC_ASSERT(sav->replay != NULL, ("Null replay state")); @@ -1205,36 +1262,96 @@ ipsec_chkreplay(uint32_t seq, struct secasvar *sav) if (replay->wsize == 0) return (1); - /* Constant. */ - wsizeb = replay->wsize << 3; - - /* Sequence number of 0 is invalid. */ - if (seq == 0) + /* Zero sequence number is not allowed. */ + if (seq == 0 && replay->last == 0) return (0); - /* First time is always okay. */ - if (replay->count == 0) - return (1); + window = replay->wsize << 3;
svn commit: r366755 - head/sys/net
Author: mw Date: Fri Oct 16 11:22:29 2020 New Revision: 366755 URL: https://svnweb.freebsd.org/changeset/base/366755 Log: Add SADB_SAFLAGS_ESN flag This flag is going to be used by IKE daemon to signal if Extended Sequence Number feature is going to be used. Value for this flag was taken from OpenBSD source code https://github.com/openbsd/src/commit/6b4cbaf181c6b60701d9fb888fd0e7a4333eecbd Submitted by: Patryk Duda Reviewed by:ae Differential revision: https://reviews.freebsd.org/D22366 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/net/pfkeyv2.h Modified: head/sys/net/pfkeyv2.h == --- head/sys/net/pfkeyv2.h Fri Oct 16 11:21:56 2020(r366754) +++ head/sys/net/pfkeyv2.h Fri Oct 16 11:22:29 2020(r366755) @@ -348,6 +348,8 @@ _Static_assert(sizeof(struct sadb_x_sa_replay) == 8, " #define SADB_SASTATE_MAX 3 #define SADB_SAFLAGS_PFS 1 +/* SADB_X_SAFLAGS_ESN was defined in sys/net/pfkeyv2.h in OpenBSD sources */ +#define SADB_X_SAFLAGS_ESN0x400 /* * Though some of these numbers (both _AALG and _EALG) appear to be ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r366754 - head/sys/crypto/aesni
Author: mw Date: Fri Oct 16 11:21:56 2020 New Revision: 366754 URL: https://svnweb.freebsd.org/changeset/base/366754 Log: Add support for ESN in AES-NI crypto driver This patch adds support for IPsec ESN (Extended Sequence Numbers) in encrypt and authenticate mode (eg. AES-CBC and SHA256) and combined mode (eg. AES-GCM). For the encrypt and authenticate mode the ESN is stored in separate crp_esn buffer because the high-order 32 bits of the sequence number are appended after the Next Header (RFC 4303). For the combined modes the high-order 32 bits of the sequence number [e.g. RFC 4106, Chapter 5 AAD Construction] are part of crp_aad (prepared by netipsec layer in case of ESN support enabled), therefore non visible diff around combined modes. Submitted by: Grzegorz Jaszczyk Patryk Duda Reviewed by:jhb Differential revision: https://reviews.freebsd.org/D22365 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/crypto/aesni/aesni.c Modified: head/sys/crypto/aesni/aesni.c == --- head/sys/crypto/aesni/aesni.c Fri Oct 16 11:18:13 2020 (r366753) +++ head/sys/crypto/aesni/aesni.c Fri Oct 16 11:21:56 2020 (r366754) @@ -249,14 +249,15 @@ aesni_cipher_supported(struct aesni_softc *sc, } } +#define SUPPORTED_SES (CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD | CSP_F_ESN) + static int aesni_probesession(device_t dev, const struct crypto_session_params *csp) { struct aesni_softc *sc; sc = device_get_softc(dev); - if ((csp->csp_flags & ~(CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD)) != - 0) + if ((csp->csp_flags & ~(SUPPORTED_SES)) != 0) return (EINVAL); switch (csp->csp_mode) { case CSP_MODE_DIGEST: @@ -864,6 +865,10 @@ aesni_cipher_mac(struct aesni_session *ses, struct cry else crypto_apply(crp, crp->crp_payload_start, crp->crp_payload_length, ses->hash_update, &sctx); + + if (csp->csp_flags & CSP_F_ESN) + ses->hash_update(&sctx, crp->crp_esn, 4); + ses->hash_finalize(res, &sctx); /* Outer hash: (K ^ OPAD) || inner hash */ ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r366753 - head/sys/opencrypto
Author: mw Date: Fri Oct 16 11:18:13 2020 New Revision: 366753 URL: https://svnweb.freebsd.org/changeset/base/366753 Log: Add support for ESN in cryptosoft This patch adds support for IPsec ESN (Extended Sequence Numbers) in encrypt and authenticate mode (eg. AES-CBC and SHA256) and combined mode (eg. AES-GCM). For encrypt and authenticate mode the ESN is stored in separate crp_esn buffer because the high-order 32 bits of the sequence number are appended after the Next Header (RFC 4303). For combined modes the high-order 32 bits of the sequence number [e.g. RFC 4106, Chapter 5 AAD Construction] are part of crp_aad (prepared by netipsec layer in case of ESN support enabled), therefore non visible diff around combined modes. Submitted by: Grzegorz Jaszczyk Patryk Duda Reviewed by:jhb Differential revision: https://reviews.freebsd.org/D22364 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/opencrypto/cryptosoft.c Modified: head/sys/opencrypto/cryptosoft.c == --- head/sys/opencrypto/cryptosoft.cFri Oct 16 11:06:33 2020 (r366752) +++ head/sys/opencrypto/cryptosoft.cFri Oct 16 11:18:13 2020 (r366753) @@ -327,8 +327,8 @@ swcr_authcompute(struct swcr_session *ses, struct cryp axf = sw->sw_axf; + csp = crypto_get_params(crp->crp_session); if (crp->crp_auth_key != NULL) { - csp = crypto_get_params(crp->crp_session); swcr_authprepare(axf, sw, crp->crp_auth_key, csp->csp_auth_klen); } @@ -354,6 +354,9 @@ swcr_authcompute(struct swcr_session *ses, struct cryp if (err) goto out; + if (csp->csp_flags & CSP_F_ESN) + axf->Update(&ctx, crp->crp_esn, 4); + axf->Final(aalg, &ctx); if (sw->sw_octx != NULL) { bcopy(sw->sw_octx, &ctx, axf->ctxsize); @@ -1235,12 +1238,12 @@ swcr_cipher_supported(const struct crypto_session_para return (true); } +#define SUPPORTED_SES (CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD | CSP_F_ESN) + static int swcr_probesession(device_t dev, const struct crypto_session_params *csp) { - - if ((csp->csp_flags & ~(CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD)) != - 0) + if ((csp->csp_flags & ~(SUPPORTED_SES)) != 0) return (EINVAL); switch (csp->csp_mode) { case CSP_MODE_COMPRESS: ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r366752 - in head: share/man/man9 sys/opencrypto
Author: mw Date: Fri Oct 16 11:06:33 2020 New Revision: 366752 URL: https://svnweb.freebsd.org/changeset/base/366752 Log: Prepare crypto framework for IPsec ESN support This permits requests (netipsec ESP and AH protocol) to provide the IPsec ESN (Extended Sequence Numbers) in a separate buffer. As with separate output buffer and separate AAD buffer not all drivers support this feature. Consumer must request use of this feature via new session flag. Submitted by: Grzegorz Jaszczyk Patryk Duda Reviewed by:jhb Differential revision: https://reviews.freebsd.org/D24838 Obtained from: Semihalf Sponsored by: Stormshield Modified: head/share/man/man9/crypto_request.9 head/share/man/man9/crypto_session.9 head/sys/opencrypto/crypto.c head/sys/opencrypto/cryptodev.h Modified: head/share/man/man9/crypto_request.9 == --- head/share/man/man9/crypto_request.9Fri Oct 16 11:01:21 2020 (r366751) +++ head/share/man/man9/crypto_request.9Fri Oct 16 11:06:33 2020 (r366752) @@ -302,6 +302,24 @@ as a single buffer pointed to by In either case, .Fa crp_aad_length always indicates the amount of AAD in bytes. +.Ss Request ESN +IPsec requests may optionally include Extended Sequence Numbers (ESN). +ESN may either be supplied in +.Fa crp_esn +or as part of the AAD pointed to by +.Fa crp_aad . +.Pp +If the ESN is stored in +.Fa crp_esn , +.Dv CSP_F_ESN +should be set in +.Fa csp_flags . +This use case is dedicated for encrypt and authenticate mode, since the +high-order 32 bits of the sequence number are appended after the Next Header +(RFC 4303). +.Pp +AEAD modes supply the ESN in a separate AAD buffer (see e.g. RFC 4106, Chapter 5 +AAD Construction). .Ss Request IV and/or Nonce Some cryptographic operations require an IV or nonce as an input. An IV may be stored either in the IV region of the data buffer or in Modified: head/share/man/man9/crypto_session.9 == --- head/share/man/man9/crypto_session.9Fri Oct 16 11:01:21 2020 (r366751) +++ head/share/man/man9/crypto_session.9Fri Oct 16 11:06:33 2020 (r366752) @@ -201,6 +201,15 @@ Sessions with this flag set permit requests with AAD p a region of the input buffer or in a single, virtually-contiguous buffer. Sessions without this flag only permit requests with AAD passed in as a region in the input buffer. +.It Dv CSP_F_ESN +Support requests that use a separate buffer for IPsec ESN (Extended Sequence +Numbers). +.Pp +Sessions with this flag set permit requests with IPsec ESN passed in special +buffer. +It is required for IPsec ESN support of encrypt and authenticate mode where +the high-order 32 bits of the sequence number are appended after the Next +Header (RFC 4303). .El .It Fa csp_ivlen If either the cipher or authentication algorithms require an explicit Modified: head/sys/opencrypto/crypto.c == --- head/sys/opencrypto/crypto.cFri Oct 16 11:01:21 2020 (r366751) +++ head/sys/opencrypto/crypto.cFri Oct 16 11:06:33 2020 (r366752) @@ -743,6 +743,8 @@ alg_is_aead(int alg) return (alg_type(alg) == ALG_AEAD); } +#define SUPPORTED_SES (CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD | CSP_F_ESN) + /* Various sanity checks on crypto session parameters. */ static bool check_csp(const struct crypto_session_params *csp) @@ -750,8 +752,7 @@ check_csp(const struct crypto_session_params *csp) struct auth_hash *axf; /* Mode-independent checks. */ - if ((csp->csp_flags & ~(CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD)) != - 0) + if ((csp->csp_flags & ~(SUPPORTED_SES)) != 0) return (false); if (csp->csp_ivlen < 0 || csp->csp_cipher_klen < 0 || csp->csp_auth_klen < 0 || csp->csp_auth_mlen < 0) Modified: head/sys/opencrypto/cryptodev.h == --- head/sys/opencrypto/cryptodev.h Fri Oct 16 11:01:21 2020 (r366751) +++ head/sys/opencrypto/cryptodev.h Fri Oct 16 11:06:33 2020 (r366752) @@ -377,6 +377,7 @@ struct crypto_session_params { #defineCSP_F_SEPARATE_OUTPUT 0x0001 /* Requests can use separate output */ #defineCSP_F_SEPARATE_AAD 0x0002 /* Requests can use separate AAD */ +#define CSP_F_ESN 0x0004 /* Requests can use seperate ESN field */ int csp_ivlen; /* IV length in bytes. */ @@ -485,6 +486,8 @@ struct cryptop { void*crp_aad; /* AAD buffer. */ int crp_aad_start; /* Location of AAD. */ int crp_aad_length; /* 0 => no AAD. */ + uint8_t
Re: svn commit: r365054 - in head/sys: conf dev/sdhci
Hi Justin, Thanks for your input. Please see inline. wt., 1 wrz 2020 o 23:30 Justin Hibbits napisał(a): > > Sep 1, 2020 11:17:35 Marcin Wojtas : > > > Author: mw > > Date: Tue Sep 1 16:17:21 2020 > > New Revision: 365054 > > URL: https://svnweb.freebsd.org/changeset/base/365054 > > > > Log: > > Introduce the SDHCI driver for NXP QorIQ Layerscape SoCs > > > > Implement support for an eSDHC controller found in NXP QorIQ Layerscape > > SoCs. > > > > This driver has been tested with NXP LS1046A and LX2160A (Honeycomb board), > > which is incompatible with the existing sdhci_fsl driver (aiming at older > > chips from this family). As such, it is not intended as replacement for > > the old driver, but rather serves as an improved alternative for SoCs that > > support it. > > It comes with support for both PIO and Single DMA modes and samples the > > clock from the extres clk API. > > How is it incompatible? > > > > > Submitted by: Artur Rojek > > Reviewed by: manu, mmel, kibab > > Obtained from: Semihalf > > Sponsored by: Alstom Group > > Differential Revision: https://reviews.freebsd.org/D26153 > > > > Added: > > head/sys/dev/sdhci/sdhci_fsl_fdt.c (contents, props changed) > > The name choice here is odd, given there is already fsl_sdhci.c > > > Modified: > > head/sys/conf/files > > > > Modified: head/sys/conf/files > > == > > --- head/sys/conf/files Tue Sep 1 16:13:09 2020 (r365053) > > +++ head/sys/conf/files Tue Sep 1 16:17:21 2020 (r365054) > > @@ -3058,6 +3058,7 @@ dev/scc/scc_dev_z8530.c optional scc > > dev/sdhci/sdhci.coptional sdhci > > dev/sdhci/sdhci_fdt.coptional sdhci fdt > > dev/sdhci/sdhci_fdt_gpio.c optional sdhci fdt gpio > > +dev/sdhci/sdhci_fsl_fdt.c optional sdhci fdt gpio > > dev/sdhci/sdhci_if.m optional sdhci > > dev/sdhci/sdhci_acpi.c optional sdhci acpi > > dev/sdhci/sdhci_pci.coptional sdhci pci > > > > Added: head/sys/dev/sdhci/sdhci_fsl_fdt.c > > == > > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > > +++ head/sys/dev/sdhci/sdhci_fsl_fdt.c Tue Sep 1 16:17:21 2020 (r365054) > > @@ -0,0 +1,680 @@ > > +/*- > > + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > > + * > > + * Copyright (c) 2020 Alstom Group. > > + * Copyright (c) 2020 Semihalf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + *notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + *notice, this list of conditions and the following disclaimer in the > > + *documentation and/or other materials provided with the distribution. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > > PURPOSE > > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > > CONSEQUENTIAL > > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, > > STRICT > > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY > > WAY > > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > > + * SUCH DAMAGE. > > + */ > > + > > +/* eSDHC controller driver for NXP QorIQ Layerscape SoCs. */ > > + > > +#include > > +__FBSDID("$FreeBSD$"); > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "mmcbr_if.h" > > +#include "sdhci_if.h" > >
Re: svn commit: r365054 - in head/sys: conf dev/sdhci
Hi Hans, śr., 2 wrz 2020 o 12:47 Hans Petter Selasky napisał(a): > > Does this patch fix the problem: > > Index: sys/conf/files > === > --- sys/conf/files (revision 365234) > +++ sys/conf/files (working copy) > @@ -3058,7 +3058,7 @@ > dev/sdhci/sdhci.c optional sdhci > dev/sdhci/sdhci_fdt.c optional sdhci fdt > dev/sdhci/sdhci_fdt_gpio.coptional sdhci fdt gpio > -dev/sdhci/sdhci_fsl_fdt.c optional sdhci fdt gpio > +dev/sdhci/sdhci_fsl_fdt.c optional ext_resources sdhci fdt gpio > dev/sdhci/sdhci_if.m optional sdhci > dev/sdhci/sdhci_acpi.coptional sdhci acpi > dev/sdhci/sdhci_pci.c optional sdhci pci > Yes, it does - I found out that you already submitted a patch during the svn commit (thank you). I only added extra option requested by Andrew (SOC_NXP_LS) - I'll wait with this until resolving discussion with Justin. Best regards, Marcin ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r365054 - in head/sys: conf dev/sdhci
wt., 1 wrz 2020 o 22:37 Mateusz Guzik napisał(a): > This commit breaks numerous kernels, e.g. _.arm.RPI-B: > > In file included from /usr/src/sys/dev/sdhci/sdhci_fsl_fdt.c:45: > /usr/src/sys/dev/extres/clk/clk.h:37:10: fatal error: 'clknode_if.h' > file not found > #include "clknode_if.h" > > Unfortunately yes, fixing it. > On 9/1/20, Marcin Wojtas wrote: > > Author: mw > > Date: Tue Sep 1 16:17:21 2020 > > New Revision: 365054 > > URL: https://svnweb.freebsd.org/changeset/base/365054 > > > > Log: > > Introduce the SDHCI driver for NXP QorIQ Layerscape SoCs > > > > Implement support for an eSDHC controller found in NXP QorIQ Layerscape > > SoCs. > > > > This driver has been tested with NXP LS1046A and LX2160A (Honeycomb > > board), > > which is incompatible with the existing sdhci_fsl driver (aiming at > older > > chips from this family). As such, it is not intended as replacement for > > the old driver, but rather serves as an improved alternative for SoCs > > that > > support it. > > It comes with support for both PIO and Single DMA modes and samples the > > clock from the extres clk API. > > > > Submitted by: Artur Rojek > > Reviewed by: manu, mmel, kibab > > Obtained from: Semihalf > > Sponsored by: Alstom Group > > Differential Revision: https://reviews.freebsd.org/D26153 > > > > Added: > > head/sys/dev/sdhci/sdhci_fsl_fdt.c (contents, props changed) > > Modified: > > head/sys/conf/files > > > > Modified: head/sys/conf/files > > > == > > --- head/sys/conf/files Tue Sep 1 16:13:09 2020(r365053) > > +++ head/sys/conf/files Tue Sep 1 16:17:21 2020(r365054) > > @@ -3058,6 +3058,7 @@ dev/scc/scc_dev_z8530.c optional scc > > dev/sdhci/sdhci.coptional sdhci > > dev/sdhci/sdhci_fdt.coptional sdhci fdt > > dev/sdhci/sdhci_fdt_gpio.c optional sdhci fdt gpio > > +dev/sdhci/sdhci_fsl_fdt.coptional sdhci fdt gpio > > dev/sdhci/sdhci_if.m optional sdhci > > dev/sdhci/sdhci_acpi.c optional sdhci acpi > > dev/sdhci/sdhci_pci.coptional sdhci pci > > > > Added: head/sys/dev/sdhci/sdhci_fsl_fdt.c > > > == > > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > > +++ head/sys/dev/sdhci/sdhci_fsl_fdt.cTue Sep 1 16:17:21 2020 > (r365054) > > @@ -0,0 +1,680 @@ > > +/*- > > + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > > + * > > + * Copyright (c) 2020 Alstom Group. > > + * Copyright (c) 2020 Semihalf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + *notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + *notice, this list of conditions and the following disclaimer in > the > > + *documentation and/or other materials provided with the > distribution. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' > AND > > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > > PURPOSE > > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE > LIABLE > > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > > CONSEQUENTIAL > > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE > GOODS > > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, > > STRICT > > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY > > WAY > > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY > OF > > + * SUCH DAMAGE. > > + */ > > + > > +/* eSDHC controller driver for NXP QorIQ Layerscape SoCs. */ > > + > > +#include > > +__FBSDID("$FreeBSD$"); > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include
svn commit: r365054 - in head/sys: conf dev/sdhci
Author: mw Date: Tue Sep 1 16:17:21 2020 New Revision: 365054 URL: https://svnweb.freebsd.org/changeset/base/365054 Log: Introduce the SDHCI driver for NXP QorIQ Layerscape SoCs Implement support for an eSDHC controller found in NXP QorIQ Layerscape SoCs. This driver has been tested with NXP LS1046A and LX2160A (Honeycomb board), which is incompatible with the existing sdhci_fsl driver (aiming at older chips from this family). As such, it is not intended as replacement for the old driver, but rather serves as an improved alternative for SoCs that support it. It comes with support for both PIO and Single DMA modes and samples the clock from the extres clk API. Submitted by: Artur Rojek Reviewed by: manu, mmel, kibab Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D26153 Added: head/sys/dev/sdhci/sdhci_fsl_fdt.c (contents, props changed) Modified: head/sys/conf/files Modified: head/sys/conf/files == --- head/sys/conf/files Tue Sep 1 16:13:09 2020(r365053) +++ head/sys/conf/files Tue Sep 1 16:17:21 2020(r365054) @@ -3058,6 +3058,7 @@ dev/scc/scc_dev_z8530.c optional scc dev/sdhci/sdhci.c optional sdhci dev/sdhci/sdhci_fdt.c optional sdhci fdt dev/sdhci/sdhci_fdt_gpio.c optional sdhci fdt gpio +dev/sdhci/sdhci_fsl_fdt.c optional sdhci fdt gpio dev/sdhci/sdhci_if.m optional sdhci dev/sdhci/sdhci_acpi.c optional sdhci acpi dev/sdhci/sdhci_pci.c optional sdhci pci Added: head/sys/dev/sdhci/sdhci_fsl_fdt.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/sdhci/sdhci_fsl_fdt.c Tue Sep 1 16:17:21 2020 (r365054) @@ -0,0 +1,680 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* eSDHC controller driver for NXP QorIQ Layerscape SoCs. */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "mmcbr_if.h" +#include "sdhci_if.h" + +#defineRD4 (sc->read) +#defineWR4 (sc->write) + +#defineSDHCI_FSL_PRES_STATE0x24 +#defineSDHCI_FSL_PRES_SDSTB(1 << 3) +#defineSDHCI_FSL_PRES_COMPAT_MASK 0x000f0f07 + +#defineSDHCI_FSL_PROT_CTRL 0x28 +#defineSDHCI_FSL_PROT_CTRL_WIDTH_1BIT (0 << 1) +#defineSDHCI_FSL_PROT_CTRL_WIDTH_4BIT (1 << 1) +#defineSDHCI_FSL_PROT_CTRL_WIDTH_8BIT (2 << 1) +#defineSDHCI_FSL_PROT_CTRL_WIDTH_MASK (3 << 1) +#defineSDHCI_FSL_PROT_CTRL_BYTE_SWAP (0 << 4) +#defineSDHCI_FSL_PROT_CTRL_BYTE_NATIVE (2 << 4) +#defineSDHCI_FSL_PROT_CTRL_BYTE_MASK (3 << 4) +#defineSDHCI_FSL_PROT_CTRL_DMA_MASK(3 << 8) + +#defineSDHCI_FSL_SYS_CTRL 0x2c +#defineSDHCI_FSL_CLK_IPGEN (1 << 0) +#defineSDHCI_FSL_CLK_SDCLKEN (1 << 3) +#defineSDHCI_FSL_CLK_DIVIDER_MASK 0x00f0 +#defineSDHCI_FSL_CLK_DIVIDER_SHIFT 4 +#defineSDHCI_FSL_CLK_PRESCALE_MASK 0xff00 +#defineSDHCI_FSL_CLK_PRESCALE_SHIFT8 + +#defineSDHCI_FSL_WTMK_LVL 0x44 +#defineSDHCI_FSL_WTMK_RD_512B (0 << 0) +#defineSDHCI_FSL_WTMK
svn commit: r363759 - head/sys/dev/neta
Author: mw Date: Sat Aug 1 09:40:19 2020 New Revision: 363759 URL: https://svnweb.freebsd.org/changeset/base/363759 Log: Fix TX csum handling in if_mvneta The mvneta device requires MVNETA_TX_CMD_L4_CHECKSUM_NONE bit to be set in the tx descriptor is checksum not required. However, mvneta_tx_set_csumflag() is not setting this flag currently, causing the hardware to randomly corrupt IP header during transmission. This affects injected IPv4 packets that skips kernel IP stack processing (e.g. DHCP), as well as all IPv6 packets, since the driver currently does not offload csum for IPv6. The fix is to remove all the early return paths from mvneta_tx_set_csumflag() which do not set the MVNETA_TX_CMD_L4_CHECKSUM_NONE flag. PR: 248306 Submitted by: Mike Cui Reported by: Mike Cui Modified: head/sys/dev/neta/if_mvneta.c Modified: head/sys/dev/neta/if_mvneta.c == --- head/sys/dev/neta/if_mvneta.c Sat Aug 1 09:06:16 2020 (r363758) +++ head/sys/dev/neta/if_mvneta.c Sat Aug 1 09:40:19 2020 (r363759) @@ -2828,18 +2828,15 @@ mvneta_tx_set_csumflag(struct ifnet *ifp, csum_flags = ifp->if_hwassist & m->m_pkthdr.csum_flags; eh = mtod(m, struct ether_header *); - if (csum_flags == 0) - return; - switch (ntohs(eh->ether_type)) { case ETHERTYPE_IP: ipoff = ETHER_HDR_LEN; break; - case ETHERTYPE_IPV6: - return; case ETHERTYPE_VLAN: ipoff = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; break; + default: + csum_flags = 0; } if (__predict_true(csum_flags & (CSUM_IP|CSUM_IP_TCP|CSUM_IP_UDP))) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r363638 - head/sys/conf
Author: mw Date: Tue Jul 28 10:08:07 2020 New Revision: 363638 URL: https://svnweb.freebsd.org/changeset/base/363638 Log: Fix ENA build when integrated into kernel Provide missing rules for ena_datapath.c and ena_netmap.c, which prevented the ENA driver from building. This issue was showing up only when building the driver statically into the kernel. PR: 248116 Submitted by: Artur Rojek MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D25796 Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/conf/files Modified: head/sys/conf/files == --- head/sys/conf/files Tue Jul 28 09:46:58 2020(r363637) +++ head/sys/conf/files Tue Jul 28 10:08:07 2020(r363638) @@ -1641,6 +1641,10 @@ dev/e1000/e1000_osdep.c optional em \ dev/et/if_et.c optional et dev/ena/ena.c optional ena \ compile-with "${NORMAL_C} -I$S/contrib" +dev/ena/ena_datapath.c optional ena \ + compile-with "${NORMAL_C} -I$S/contrib" +dev/ena/ena_netmap.c optional ena \ + compile-with "${NORMAL_C} -I$S/contrib" dev/ena/ena_sysctl.c optional ena \ compile-with "${NORMAL_C} -I$S/contrib" contrib/ena-com/ena_com.c optional ena ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r362574 - head/sys/dev/uart
Author: mw Date: Wed Jun 24 12:15:27 2020 New Revision: 362574 URL: https://svnweb.freebsd.org/changeset/base/362574 Log: Fix AccessWidth and BitWidth parsing in SPCR table The ACPI Specification defines a Generic Address Structure (GAS), which is used to describe UART controller register layout in the SPCR table. The driver responsible for parsing it (uart_cpu_acpi) wrongly associates the Access Size field to the uart_bas's regshft and the register BitWidth to the regiowidth - according to the definitions it should be opposite. This problem remained hidden most likely because the majority of platforms use 32-bit registers (BitWidth) which are accessed with the according size (Dword). However on Marvell Armada 8k / Cn913x platforms, the 32-bit registers should be accessed with Byte granulity, which unveiled the issue. This patch fixes above by proper values assignment and slightly improved parsing. Note that handling of the AccessWidth set to EFI_ACPI_6_0_UNDEFINED is needed to work around a buggy SPCR table on EC2 x86 "bare metal" instances. Reviewed by: manu, imp, cperciva, greg_unrelenting.technology Obtained from: Semihalf MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D25373 Modified: head/sys/dev/uart/uart_cpu_acpi.c Modified: head/sys/dev/uart/uart_cpu_acpi.c == --- head/sys/dev/uart/uart_cpu_acpi.c Wed Jun 24 07:25:54 2020 (r362573) +++ head/sys/dev/uart/uart_cpu_acpi.c Wed Jun 24 12:15:27 2020 (r362574) @@ -120,11 +120,46 @@ uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *d (int)spcr->SerialPort.SpaceId); goto out; } - if (spcr->SerialPort.AccessWidth == 0) + switch (spcr->SerialPort.AccessWidth) { + case 0: /* EFI_ACPI_6_0_UNDEFINED */ + /* FALLTHROUGH */ + case 1: /* EFI_ACPI_6_0_BYTE */ + di->bas.regiowidth = 1; + break; + case 2: /* EFI_ACPI_6_0_WORD */ + di->bas.regiowidth = 2; + break; + case 3: /* EFI_ACPI_6_0_DWORD */ + di->bas.regiowidth = 4; + break; + case 4: /* EFI_ACPI_6_0_QWORD */ + di->bas.regiowidth = 8; + break; + default: + printf("UART unsupported access width: %d!\n", + (int)spcr->SerialPort.AccessWidth); + goto out; + } + switch (spcr->SerialPort.BitWidth) { + case 0: + /* FALLTHROUGH */ + case 8: di->bas.regshft = 0; - else - di->bas.regshft = spcr->SerialPort.AccessWidth - 1; - di->bas.regiowidth = spcr->SerialPort.BitWidth / 8; + break; + case 16: + di->bas.regshft = 1; + break; + case 32: + di->bas.regshft = 2; + break; + case 64: + di->bas.regshft = 3; + break; + default: + printf("UART unsupported bit width: %d!\n", + (int)spcr->SerialPort.BitWidth); + goto out; + } switch (spcr->BaudRate) { case 0: /* Special value; means "keep current value unchanged". */ ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361583 - head/sys/crypto/aesni
Author: mw Date: Thu May 28 09:13:20 2020 New Revision: 361583 URL: https://svnweb.freebsd.org/changeset/base/361583 Log: Change return types of hash update functions in SHA-NI r359374 introduced crypto_apply function which takes as argument a function pointer that is expected to return an int, however aesni hash update functions return void. Because of that the function pointer passed was simply cast with its return value changed. This resulted in undefined behavior, in particular when mbuf is used, (ipsec) m_apply checks return value of function pointer passed to it and in our case bogusly fails after calculating hash of the first mbuf in chain. Fix it by changing signatures of sha update routines in aesni and dropping the casts. Submitted by: Kornel Duleba Reviewed by: jhb, cem Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D25030 Modified: head/sys/crypto/aesni/aesni.c head/sys/crypto/aesni/aesni.h Modified: head/sys/crypto/aesni/aesni.c == --- head/sys/crypto/aesni/aesni.c Thu May 28 08:41:18 2020 (r361582) +++ head/sys/crypto/aesni/aesni.c Thu May 28 09:13:20 2020 (r361583) @@ -386,8 +386,8 @@ DRIVER_MODULE(aesni, nexus, aesni_driver, aesni_devcla MODULE_VERSION(aesni, 1); MODULE_DEPEND(aesni, crypto, 1, 1, 1); -static void -intel_sha1_update(void *vctx, const void *vdata, u_int datalen) +static int +intel_sha1_update(void *vctx, void *vdata, u_int datalen) { struct sha1_ctxt *ctx = vctx; const char *data = vdata; @@ -419,6 +419,8 @@ intel_sha1_update(void *vctx, const void *vdata, u_int intel_sha1_step(ctx->h.b32, (void *)ctx->m.b8, 1); off += copysiz; } + + return (0); } static void @@ -433,8 +435,8 @@ SHA1_Finalize_fn(void *digest, void *ctx) sha1_result(ctx, digest); } -static void -intel_sha256_update(void *vctx, const void *vdata, u_int len) +static int +intel_sha256_update(void *vctx, void *vdata, u_int len) { SHA256_CTX *ctx = vctx; uint64_t bitlen; @@ -454,7 +456,7 @@ intel_sha256_update(void *vctx, const void *vdata, u_i /* Handle the case where we don't need to perform any transforms */ if (len < 64 - r) { memcpy(&ctx->buf[r], src, len); - return; + return (0); } /* Finish the current block */ @@ -473,6 +475,8 @@ intel_sha256_update(void *vctx, const void *vdata, u_i /* Copy left over data into buffer */ memcpy(ctx->buf, src, len); + + return (0); } static void @@ -844,20 +848,16 @@ aesni_cipher_mac(struct aesni_session *ses, struct cry ses->hash_update(&sctx, hmac_key, sizeof(hmac_key)); crypto_apply(crp, crp->crp_aad_start, crp->crp_aad_length, - __DECONST(int (*)(void *, void *, u_int), ses->hash_update), - &sctx); + ses->hash_update, &sctx); if (CRYPTO_HAS_OUTPUT_BUFFER(crp) && CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) crypto_apply_buf(&crp->crp_obuf, crp->crp_payload_output_start, crp->crp_payload_length, - __DECONST(int (*)(void *, void *, u_int), - ses->hash_update), &sctx); + ses->hash_update, &sctx); else crypto_apply(crp, crp->crp_payload_start, - crp->crp_payload_length, - __DECONST(int (*)(void *, void *, u_int), - ses->hash_update), &sctx); + crp->crp_payload_length, ses->hash_update, &sctx); ses->hash_finalize(res, &sctx); /* Outer hash: (K ^ OPAD) || inner hash */ @@ -873,20 +873,17 @@ aesni_cipher_mac(struct aesni_session *ses, struct cry ses->hash_init(&sctx); crypto_apply(crp, crp->crp_aad_start, crp->crp_aad_length, - __DECONST(int (*)(void *, void *, u_int), ses->hash_update), - &sctx); + ses->hash_update, &sctx); if (CRYPTO_HAS_OUTPUT_BUFFER(crp) && CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) crypto_apply_buf(&crp->crp_obuf, crp->crp_payload_output_start, crp->crp_payload_length, - __DECONST(int (*)(void *, void *, u_int), - ses->hash_update), &sctx); + ses->hash_update, &sctx); else crypto_apply(crp, crp->crp_payload_start, crp->crp_payload_length, - __
svn commit: r361530 - head/sys/dev/ena
Author: mw Date: Tue May 26 16:11:46 2020 New Revision: 361530 URL: https://svnweb.freebsd.org/changeset/base/361530 Log: Update ENA driver version to v2.2.0 Driver version upgrade is connected with support for the new device fetures, like Tx drops reporting or disabling meta caching. Moreover, the driver configuration from the sysctl was reworked to provide safer and better flow for configuring: * number of IO queues (new feature), * drbr size on Tx, * Rx queue size. Moreover, a lot of minor bug fixes and improvements were added. Copyright date in the license of the modified files in this release was updated to 2020. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_datapath.h head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_netmap.h head/sys/dev/ena/ena_sysctl.c head/sys/dev/ena/ena_sysctl.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 16:05:42 2020(r361529) +++ head/sys/dev/ena/ena.c Tue May 26 16:11:46 2020(r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 16:05:42 2020(r361529) +++ head/sys/dev/ena/ena.h Tue May 26 16:11:46 2020(r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,8 +40,8 @@ #include "ena-com/ena_eth_com.h" #define DRV_MODULE_VER_MAJOR 2 -#define DRV_MODULE_VER_MINOR 1 -#define DRV_MODULE_VER_SUBMINOR 2 +#define DRV_MODULE_VER_MINOR 2 +#define DRV_MODULE_VER_SUBMINOR 0 #define DRV_MODULE_NAME"ena" Modified: head/sys/dev/ena/ena_datapath.c == --- head/sys/dev/ena/ena_datapath.c Tue May 26 16:05:42 2020 (r361529) +++ head/sys/dev/ena/ena_datapath.c Tue May 26 16:11:46 2020 (r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena_datapath.h == --- head/sys/dev/ena/ena_datapath.h Tue May 26 16:05:42 2020 (r361529) +++ head/sys/dev/ena/ena_datapath.h Tue May 26 16:11:46 2020 (r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena_netmap.c == --- head/sys/dev/ena/ena_netmap.c Tue May 26 16:05:42 2020 (r361529) +++ head/sys/dev/ena/ena_netmap.c Tue May 26 16:11:46 2020 (r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena_netmap.h == --- head/sys/dev/ena/ena_netmap.h Tue May 26 16:05:42 2020 (r361529) +++ head/sys/dev/ena/ena_netmap.h Tue May 26 16:11:46 2020 (r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena_sysctl.c == --- head/sys/dev/ena/ena_sysctl.c Tue May 26 16:05:42 2020 (r361529) +++ head/sys/dev/ena/ena_sysctl.c Tue May 26 16:11:46 2020 (r361530) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com,
svn commit: r361529 - head/sys/dev/ena
Author: mw Date: Tue May 26 16:05:42 2020 New Revision: 361529 URL: https://svnweb.freebsd.org/changeset/base/361529 Log: Refactor ena_tx_map_mbuf() function There is no guarantee from bus_dmamap_load_mbuf_sg() for matching mbuf chain segments to dma physical segments. This patch ensure correctly mapping to LLQ header and DMA segments. Submitted by: Ido Segev Obtained from: Amazon, Inc. Modified: head/sys/dev/ena/ena_datapath.c Modified: head/sys/dev/ena/ena_datapath.c == --- head/sys/dev/ena/ena_datapath.c Tue May 26 16:02:10 2020 (r361528) +++ head/sys/dev/ena/ena_datapath.c Tue May 26 16:05:42 2020 (r361529) @@ -812,9 +812,8 @@ ena_tx_map_mbuf(struct ena_ring *tx_ring, struct ena_t struct ena_com_buf *ena_buf; bus_dma_segment_t segs[ENA_BUS_DMA_SEGS]; size_t iseg = 0; - uint32_t mbuf_head_len, frag_len; - uint16_t push_len = 0; - uint16_t delta = 0; + uint32_t mbuf_head_len; + uint16_t offset; int rc, nsegs; mbuf_head_len = mbuf->m_len; @@ -833,7 +832,6 @@ ena_tx_map_mbuf(struct ena_ring *tx_ring, struct ena_t goto dma_error; } - if (tx_ring->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) { /* * When the device is LLQ mode, the driver will copy @@ -845,44 +843,48 @@ ena_tx_map_mbuf(struct ena_ring *tx_ring, struct ena_t * First check if header fits in the mbuf. If not, copy it to * separate buffer that will be holding linearized data. */ - push_len = min_t(uint32_t, mbuf->m_pkthdr.len, - tx_ring->tx_max_header_size); - *header_len = push_len; + *header_len = min_t(uint32_t, mbuf->m_pkthdr.len, tx_ring->tx_max_header_size); + /* If header is in linear space, just point into mbuf's data. */ - if (likely(push_len <= mbuf_head_len)) { + if (likely(*header_len <= mbuf_head_len)) { *push_hdr = mbuf->m_data; /* * Otherwise, copy whole portion of header from multiple mbufs * to intermediate buffer. */ } else { - m_copydata(mbuf, 0, push_len, - tx_ring->push_buf_intermediate_buf); + m_copydata(mbuf, 0, *header_len, tx_ring->push_buf_intermediate_buf); *push_hdr = tx_ring->push_buf_intermediate_buf; counter_u64_add(tx_ring->tx_stats.llq_buffer_copy, 1); - delta = push_len - mbuf_head_len; } ena_trace(ENA_DBG | ENA_TXPTH, "mbuf: %p header_buf->vaddr: %p push_len: %d\n", - mbuf, *push_hdr, push_len); + mbuf, *push_hdr, *header_len); - /* - * If header was in linear memory space, map for the dma rest of the data - * in the first mbuf of the mbuf chain. - */ - if (mbuf_head_len > push_len) { - ena_buf->paddr = segs[iseg].ds_addr + push_len; - ena_buf->len = segs[iseg].ds_len - push_len; - ena_buf++; - tx_info->num_of_bufs++; + /* If packet is fitted in LLQ header, no need for DMA segments. */ + if (mbuf->m_pkthdr.len <= tx_ring->tx_max_header_size) { + return (0); + } else { + offset = tx_ring->tx_max_header_size; + /* +* As Header part is mapped to LLQ header, we can skip it and just +* map the residuum of the mbuf to DMA Segments. +*/ + while (offset > 0) { + if (offset >= segs[iseg].ds_len) { + offset -= segs[iseg].ds_len; + } else { + ena_buf->paddr = segs[iseg].ds_addr + offset; + ena_buf->len = segs[iseg].ds_len - offset; + ena_buf++; + tx_info->num_of_bufs++; + offset = 0; + } + iseg++; + } } - /* -* Advance the seg index as either the 1st mbuf was mapped or is -* a part of push_hdr. -*/ - iseg++; } else { *push_hdr = NULL; /* @@ -893,41 +895,6 @@ ena_tx_map_mbuf(struct ena_ring *tx_ring, struct ena_t
svn commit: r361528 - head/sys/dev/ena
Author: mw Date: Tue May 26 16:02:10 2020 New Revision: 361528 URL: https://svnweb.freebsd.org/changeset/base/361528 Log: Fix double-free bug within ena_detach() There is ena_free_all_io_rings_resources() called twice on device detach: ena_detach(): ena_destroy_device(): /* First call */ ena_free_all_io_rings_resources() /* Second call */ ena_free_all_io_rings_resources() The double-free causes panic() on kldunload, for example. As the ena_destroy_device() is also called by ena_reset_task() it is better to stay unchanged. Thus, remove the "Second call" of the function. Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 16:00:30 2020(r361527) +++ head/sys/dev/ena/ena.c Tue May 26 16:02:10 2020(r361528) @@ -3695,8 +3695,6 @@ ena_detach(device_t pdev) netmap_detach(adapter->ifp); #endif /* DEV_NETMAP */ - ena_free_all_io_rings_resources(adapter); - ena_free_counters((counter_u64_t *)&adapter->hw_stats, sizeof(struct ena_hw_stats)); ena_free_counters((counter_u64_t *)&adapter->dev_stats, ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361527 - head/sys/dev/ena
Author: mw Date: Tue May 26 16:00:30 2020 New Revision: 361527 URL: https://svnweb.freebsd.org/changeset/base/361527 Log: Allow disabling meta caching for ENA Tx path Determined by a flag passed from the device. No metadata is set within ena_tx_csum when caching is disabled. Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:58:48 2020(r361526) +++ head/sys/dev/ena/ena.c Tue May 26 16:00:30 2020(r361527) @@ -3519,6 +3519,11 @@ ena_attach(device_t pdev) goto err_com_free; } + if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) + adapter->disable_meta_caching = + !!(get_feat_ctx.llq.accel_mode.u.get.supported_flags & + BIT(ENA_ADMIN_DISABLE_META_CACHING)); + adapter->keep_alive_timestamp = getsbinuptime(); adapter->tx_offload_cap = get_feat_ctx.offload.tx; Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 15:58:48 2020(r361526) +++ head/sys/dev/ena/ena.h Tue May 26 16:00:30 2020(r361527) @@ -461,6 +461,7 @@ struct ena_adapter { sbintime_t missing_tx_timeout; uint32_t missing_tx_max_queues; uint32_t missing_tx_threshold; + bool disable_meta_caching; /* Statistics */ struct ena_stats_dev dev_stats; Modified: head/sys/dev/ena/ena_datapath.c == --- head/sys/dev/ena/ena_datapath.c Tue May 26 15:58:48 2020 (r361526) +++ head/sys/dev/ena/ena_datapath.c Tue May 26 16:00:30 2020 (r361527) @@ -49,7 +49,7 @@ static struct mbuf* ena_rx_mbuf(struct ena_ring *, str struct ena_com_rx_ctx *, uint16_t *); static inline void ena_rx_checksum(struct ena_ring *, struct ena_com_rx_ctx *, struct mbuf *); -static voidena_tx_csum(struct ena_com_tx_ctx *, struct mbuf *); +static voidena_tx_csum(struct ena_com_tx_ctx *, struct mbuf *, bool); static int ena_check_and_collapse_mbuf(struct ena_ring *tx_ring, struct mbuf **mbuf); static int ena_xmit_mbuf(struct ena_ring *, struct mbuf **); @@ -675,7 +675,8 @@ error: } static void -ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct mbuf *mbuf) +ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct mbuf *mbuf, +bool disable_meta_caching) { struct ena_com_tx_meta *ena_meta; struct ether_vlan_header *eh; @@ -703,7 +704,12 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct offload = true; if (!offload) { - ena_tx_ctx->meta_valid = 0; + if (disable_meta_caching) { + memset(ena_meta, 0, sizeof(*ena_meta)); + ena_tx_ctx->meta_valid = 1; + } else { + ena_tx_ctx->meta_valid = 0; + } return; } @@ -989,7 +995,7 @@ ena_xmit_mbuf(struct ena_ring *tx_ring, struct mbuf ** ena_tx_ctx.header_len = header_len; /* Set flags and meta data */ - ena_tx_csum(&ena_tx_ctx, *mbuf); + ena_tx_csum(&ena_tx_ctx, *mbuf, adapter->disable_meta_caching); if (tx_ring->acum_pkts == DB_THRESHOLD || ena_com_is_doorbell_needed(tx_ring->ena_com_io_sq, &ena_tx_ctx)) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361526 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:58:48 2020 New Revision: 361526 URL: https://svnweb.freebsd.org/changeset/base/361526 Log: Create ENA IO queues with optional backoff If requested size of IO queues is not supported try to decrease it until finding the highest value that can be satisfied. Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:57:02 2020(r361525) +++ head/sys/dev/ena/ena.c Tue May 26 15:58:48 2020(r361526) @@ -408,13 +408,9 @@ ena_init_io_rings_basic(struct ena_adapter *adapter) ena_init_io_rings_common(adapter, rxr, i); /* TX specific ring state */ - txr->ring_size = adapter->tx_ring_size; txr->tx_max_header_size = ena_dev->tx_max_header_size; txr->tx_mem_queue_type = ena_dev->tx_mem_queue_type; - /* RX specific ring state */ - rxr->ring_size = adapter->rx_ring_size; - que = &adapter->que[i]; que->adapter = adapter; que->id = i; @@ -1193,10 +1189,10 @@ ena_update_queue_size(struct ena_adapter *adapter, uin ENA_LOCK_LOCK(adapter); - old_tx_size = adapter->tx_ring_size; - old_rx_size = adapter->rx_ring_size; - adapter->tx_ring_size = new_tx_size; - adapter->rx_ring_size = new_rx_size; + old_tx_size = adapter->requested_tx_ring_size; + old_rx_size = adapter->requested_rx_ring_size; + adapter->requested_tx_ring_size = new_tx_size; + adapter->requested_rx_ring_size = new_rx_size; dev_was_up = ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter); ena_down(adapter); @@ -1211,8 +1207,8 @@ ena_update_queue_size(struct ena_adapter *adapter, uin new_tx_size, new_rx_size, old_tx_size, old_rx_size); /* Revert old size. */ - adapter->tx_ring_size = old_tx_size; - adapter->rx_ring_size = old_rx_size; + adapter->requested_tx_ring_size = old_tx_size; + adapter->requested_rx_ring_size = old_rx_size; ena_init_io_rings_basic(adapter); /* And try again. */ @@ -1455,7 +1451,7 @@ ena_create_io_queues(struct ena_adapter *adapter) ena_qid = ENA_IO_TXQ_IDX(i); ctx.mem_queue_type = ena_dev->tx_mem_queue_type; ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_TX; - ctx.queue_size = adapter->tx_ring_size; + ctx.queue_size = adapter->requested_tx_ring_size; ctx.msix_vector = msix_vector; ctx.qid = ena_qid; rc = ena_com_create_io_queue(ena_dev, &ctx); @@ -1483,7 +1479,7 @@ ena_create_io_queues(struct ena_adapter *adapter) ena_qid = ENA_IO_RXQ_IDX(i); ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST; ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_RX; - ctx.queue_size = adapter->rx_ring_size; + ctx.queue_size = adapter->requested_rx_ring_size; ctx.msix_vector = msix_vector; ctx.qid = ena_qid; rc = ena_com_create_io_queue(ena_dev, &ctx); @@ -1975,6 +1971,104 @@ ena_up_complete(struct ena_adapter *adapter) return (0); } +static void +set_io_rings_size(struct ena_adapter *adapter, int new_tx_size, +int new_rx_size) +{ + int i; + + for (i = 0; i < adapter->num_io_queues; i++) { + adapter->tx_ring[i].ring_size = new_tx_size; + adapter->rx_ring[i].ring_size = new_rx_size; + } +} + +static int +create_queues_with_size_backoff(struct ena_adapter *adapter) +{ + int rc; + uint32_t cur_rx_ring_size, cur_tx_ring_size; + uint32_t new_rx_ring_size, new_tx_ring_size; + + /* +* Current queue sizes might be set to smaller than the requested +* ones due to past queue allocation failures. +*/ + set_io_rings_size(adapter, adapter->requested_tx_ring_size, + adapter->requested_rx_ring_size); + + while (1) { + /* Allocate transmit descriptors */ + rc = ena_setup_all_tx_resources(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "err_setup_tx\n"); + goto err_setup_tx; + } + + /* Allocate receive descriptors */ + rc = ena_setup_all_rx_resources(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "err_setup_rx\n"); + goto err_setup_
svn commit: r361525 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:57:02 2020 New Revision: 361525 URL: https://svnweb.freebsd.org/changeset/base/361525 Log: Add sysctl node for ENA IO queues number adjustment By default, in ena_attach() the driver attempts to acquire ena_adapter::max_num_io_queues MSI-X vectors for the purpose of IO queues, however this is not guaranteed. The number of vectors acquired depends also on system resources availability. Regardless of that, enable the number of effectively used IO queues to be further limited through the sysctl node. Example: Assumming that there are 8 IO queues configured by default, the command $ sysctl dev.ena.0.io_queues_nb=4 will reduce the number of available IO queues to 4. Similarly, the value can be also increased up to maximum supported value. A value higher than maximum supported number of IO queues is ignored. Zero is ignored too. Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:54:32 2020(r361524) +++ head/sys/dev/ena/ena.c Tue May 26 15:57:02 2020(r361525) @@ -1239,6 +1239,61 @@ ena_update_queue_size(struct ena_adapter *adapter, uin } static void +ena_update_io_rings(struct ena_adapter *adapter, uint32_t num) +{ + ena_free_all_io_rings_resources(adapter); + /* Force indirection table to be reinitialized */ + ena_com_rss_destroy(adapter->ena_dev); + + adapter->num_io_queues = num; + ena_init_io_rings(adapter); +} + +/* Caller should sanitize new_num */ +int +ena_update_io_queue_nb(struct ena_adapter *adapter, uint32_t new_num) +{ + uint32_t old_num; + int rc = 0; + bool dev_was_up; + + ENA_LOCK_LOCK(adapter); + + dev_was_up = ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter); + old_num = adapter->num_io_queues; + ena_down(adapter); + + ena_update_io_rings(adapter, new_num); + + if (dev_was_up) { + rc = ena_up(adapter); + if (unlikely(rc != 0)) { + device_printf(adapter->pdev, + "Failed to configure device with %u IO queues. " + "Reverting to previous value: %u\n", + new_num, old_num); + + ena_update_io_rings(adapter, old_num); + + rc = ena_up(adapter); + if (unlikely(rc != 0)) { + device_printf(adapter->pdev, + "Failed to revert to previous setup IO " + "queues. Triggering device reset.\n"); + ENA_FLAG_SET_ATOMIC( + ENA_FLAG_DEV_UP_BEFORE_RESET, adapter); + ena_trigger_reset(adapter, + ENA_REGS_RESET_OS_TRIGGER); + } + } + } + + ENA_LOCK_UNLOCK(adapter); + + return (rc); +} + +static void ena_free_rx_bufs(struct ena_adapter *adapter, unsigned int qid) { struct ena_ring *rx_ring = &adapter->rx_ring[qid]; @@ -1865,6 +1920,18 @@ ena_rss_configure(struct ena_adapter *adapter) struct ena_com_dev *ena_dev = adapter->ena_dev; int rc; + /* In case the RSS table was destroyed */ + if (!ena_dev->rss.tbl_log_size) { + rc = ena_rss_init_default(adapter); + if (unlikely((rc != 0) && (rc != EOPNOTSUPP))) { + device_printf(adapter->pdev, + "WARNING: RSS was not properly re-initialized," + " it will affect bandwidth\n"); + ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_RSS_ACTIVE, adapter); + return (rc); + } + } + /* Set indirect table */ rc = ena_com_indirect_table_set(ena_dev); if (unlikely((rc != 0) && (rc != EOPNOTSUPP))) @@ -1890,8 +1957,11 @@ ena_up_complete(struct ena_adapter *adapter) if (likely(ENA_FLAG_ISSET(ENA_FLAG_RSS_ACTIVE, adapter))) { rc = ena_rss_configure(adapter); - if (rc != 0) + if (rc != 0) { + device_printf(adapter->pdev, + "Failed to configure RSS\n"); return (rc); + } } rc = ena_change_mtu(adapter->ifp, adapter->ifp->if_mtu); Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 15:54:32 2020(r361524) +++ head/sys/dev/ena/ena.h Tue May 26 15:57:02 2020(r361525) @@ -501,6 +501,7 @@ int ena_updat
svn commit: r361524 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:54:32 2020 New Revision: 361524 URL: https://svnweb.freebsd.org/changeset/base/361524 Log: Fix assumptions about number of IO queues in the ENA Make the ena_adapter::num_io_queues a number of effectively used IO queues. While the ena_adapter::max_num_io_queues is an upper-bound specified by the HW, the ena_adapter::num_io_queues may be lower than that, depending on runtime system resources availability. On reset, there are called ena_destroy_device() and then ena_restore_device(). The latter calls, in turn, ena_enable_msix(), which will attempt to re-acquire ena_adapter::max_num_io_queues of MSIX vectors again. Thus, the value of ena_adapter::num_io_queues may be different before and after reset. For this reason, free the IO rings structures (drbr, counters) in ena_destroy_device() and allocate again in ena_restore_device(). Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:50:30 2020(r361523) +++ head/sys/dev/ena/ena.c Tue May 26 15:54:32 2020(r361524) @@ -1562,7 +1562,6 @@ ena_enable_msix(struct ena_adapter *adapter) } device_printf(dev, "Enable only %d MSI-x (out of %d), reduce " "the number of queues\n", msix_vecs, msix_req); - adapter->num_io_queues = msix_vecs - ENA_ADMIN_MSIX_VEC; } adapter->msix_vecs = msix_vecs; @@ -3116,6 +3115,15 @@ ena_destroy_device(struct ena_adapter *adapter, bool g ena_disable_msix(adapter); + /* +* IO rings resources should be freed because `ena_restore_device()` +* calls (not directly) `ena_enable_msix()`, which re-allocates MSIX +* vectors. The amount of MSIX vectors after destroy-restore may be +* different than before. Therefore, IO rings resources should be +* established from scratch each time. +*/ + ena_free_all_io_rings_resources(adapter); + ena_com_abort_admin_commands(ena_dev); ena_com_wait_for_abort_completion(ena_dev); @@ -3192,6 +3200,18 @@ ena_restore_device(struct ena_adapter *adapter) goto err_device_destroy; } + /* +* Effective value of used MSIX vectors should be the same as before +* `ena_destroy_device()`, if possible, or closest to it if less vectors +* are available. +*/ + if ((adapter->msix_vecs - ENA_ADMIN_MSIX_VEC) < adapter->num_io_queues) + adapter->num_io_queues = + adapter->msix_vecs - ENA_ADMIN_MSIX_VEC; + + /* Re-initialize rings basic information */ + ena_init_io_rings(adapter); + /* If the interface was up before the reset bring it up */ if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter)) { rc = ena_up(adapter); @@ -3379,7 +3399,6 @@ ena_attach(device_t pdev) adapter->max_rx_sgl_size = calc_queue_ctx.max_rx_sgl_size; adapter->max_num_io_queues = max_num_io_queues; - adapter->num_io_queues = max_num_io_queues; adapter->buf_ring_size = ENA_DEFAULT_BUF_RING_SIZE; @@ -3400,15 +3419,26 @@ ena_attach(device_t pdev) goto err_tx_tag_free; } - /* initialize rings basic information */ - ena_init_io_rings(adapter); - + /* +* The amount of requested MSIX vectors is equal to +* adapter::max_num_io_queues (see `ena_enable_msix()`), plus a constant +* number of admin queue interrupts. The former is initially determined +* by HW capabilities (see `ena_calc_max_io_queue_num())` but may not be +* achieved if there are not enough system resources. By default, the +* number of effectively used IO queues is the same but later on it can +* be limited by the user using sysctl interface. +*/ rc = ena_enable_msix_and_set_admin_interrupts(adapter); if (unlikely(rc != 0)) { device_printf(pdev, "Failed to enable and set the admin interrupts\n"); goto err_io_free; } + /* By default all of allocated MSIX vectors are actively used */ + adapter->num_io_queues = adapter->msix_vecs - ENA_ADMIN_MSIX_VEC; + + /* initialize rings basic information */ + ena_init_io_rings(adapter); /* setup network interface */ rc = ena_setup_ifnet(pdev, adapter, &get_feat_ctx); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361519 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:45:54 2020 New Revision: 361519 URL: https://svnweb.freebsd.org/changeset/base/361519 Log: Mark the ENA driver as epoch ready Recent changes to the epoch requires driver to notify that they knows epoch in order to prevent input packet function to enter epoch each time the packet is received. ENA is using NET_TASK for handling Rx, so it's entering epoch automatically whenever this task is being executed. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:44:08 2020(r361518) +++ head/sys/dev/ena/ena.c Tue May 26 15:45:54 2020(r361519) @@ -2116,7 +2116,8 @@ ena_setup_ifnet(device_t pdev, struct ena_adapter *ada if_setdev(ifp, pdev); if_setsoftc(ifp, adapter); - if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); + if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST | + IFF_KNOWSEPOCH); if_setinitfn(ifp, ena_init); if_settransmitfn(ifp, ena_mq_start); if_setqflushfn(ifp, ena_qflush); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361523 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:50:30 2020 New Revision: 361523 URL: https://svnweb.freebsd.org/changeset/base/361523 Log: Rework ENA Tx buffer ring size reconfiguration This method has been aligned with the way how the Rx queue size is being updated - so it's now done synchronously instead of resetting the device. Moreover, the input parameter is now being validated if it's a power of 2. Without this, it can cause kernel panic. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:48:27 2020(r361522) +++ head/sys/dev/ena/ena.c Tue May 26 15:50:30 2020(r361523) @@ -1135,6 +1135,55 @@ ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t } int +ena_update_buf_ring_size(struct ena_adapter *adapter, +uint32_t new_buf_ring_size) +{ + uint32_t old_buf_ring_size; + int rc = 0; + bool dev_was_up; + + ENA_LOCK_LOCK(adapter); + + old_buf_ring_size = adapter->buf_ring_size; + adapter->buf_ring_size = new_buf_ring_size; + + dev_was_up = ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter); + ena_down(adapter); + + /* Reconfigure buf ring for all Tx rings. */ + ena_free_all_io_rings_resources(adapter); + ena_init_io_rings_advanced(adapter); + if (dev_was_up) { + /* +* If ena_up() fails, it's not because of recent buf_ring size +* changes. Because of that, we just want to revert old drbr +* value and trigger the reset because something else had to +* go wrong. +*/ + rc = ena_up(adapter); + if (unlikely(rc != 0)) { + device_printf(adapter->pdev, + "Failed to configure device after setting new drbr size: %u. Reverting old value: %u and triggering the reset\n", + new_buf_ring_size, old_buf_ring_size); + + /* Revert old size and trigger the reset */ + adapter->buf_ring_size = old_buf_ring_size; + ena_free_all_io_rings_resources(adapter); + ena_init_io_rings_advanced(adapter); + + ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, + adapter); + ena_trigger_reset(adapter, ENA_REGS_RESET_OS_TRIGGER); + + } + } + + ENA_LOCK_UNLOCK(adapter); + + return (rc); +} + +int ena_update_queue_size(struct ena_adapter *adapter, uint32_t new_tx_size, uint32_t new_rx_size) { Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 15:48:27 2020(r361522) +++ head/sys/dev/ena/ena.h Tue May 26 15:50:30 2020(r361523) @@ -426,7 +426,7 @@ struct ena_adapter { uint32_t tx_offload_cap; - uint16_t buf_ring_size; + uint32_t buf_ring_size; /* RSS*/ uint8_t rss_ind_tbl[ENA_RX_RSS_TABLE_SIZE]; @@ -497,6 +497,8 @@ voidena_down(struct ena_adapter *adapter); intena_restore_device(struct ena_adapter *adapter); void ena_destroy_device(struct ena_adapter *adapter, bool graceful); intena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t num); +intena_update_buf_ring_size(struct ena_adapter *adapter, +uint32_t new_buf_ring_size); intena_update_queue_size(struct ena_adapter *adapter, uint32_t new_tx_size, uint32_t new_rx_size); Modified: head/sys/dev/ena/ena_sysctl.c == --- head/sys/dev/ena/ena_sysctl.c Tue May 26 15:48:27 2020 (r361522) +++ head/sys/dev/ena/ena_sysctl.c Tue May 26 15:50:30 2020 (r361523) @@ -307,8 +307,9 @@ ena_sysctl_add_tuneables(struct ena_adapter *adapter) /* Tuneable number of buffers in the buf-ring (drbr) */ SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "buf_ring_size", - CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, - ena_sysctl_buf_ring_size, "I", "Size of the bufring"); + CTLTYPE_U32 | CTLFLAG_RW | CTLFLAG_MPSAFE, adapter, 0, + ena_sysctl_buf_ring_size, "I", + "Size of the Tx buffer ring (drbr)."); /* Tuneable number of the Rx ring size */ SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rx_queue_size", @@ -322,31 +323,38 @@ static int ena_sysctl_buf_ring_size(SYSCTL_HANDLER_ARGS) { struct ena_adapter *adapter = arg1; - int val; + uint32_t val; int error; val = 0; - error = sysctl_wire_old_buffer(req, sizeof(int)); + error =
svn commit: r361521 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:48:06 2020 New Revision: 361521 URL: https://svnweb.freebsd.org/changeset/base/361521 Log: Rework ENA Rx queue size configuration This patch reworks how the Rx queue size is being reconfigured and how the information from the device is being processed. Reconfiguration of the queues and reset of the device in order to make the changes alive isn't the best approach. It can be done synchronously and it will let to pass information if the reconfiguration was successful to the user. It now is done in the ena_update_queue_size() function. To avoid reallocation of the ring buffer, statistic counters and the reinitialization of the mutexes when only new size has to be assigned, the io queues initialization function has been split into 2 stages: basic, which is just copying appropriate fields and the advanced, which allocates and inits more advanced structures for the IO rings. Moreover, now the max allowed Rx and Tx ring size is being kept statically in the adapter and the size of the variables holding those values has been changed to uint32_t everywhere. Information about IO queues size is now being logged in the up routine instead of the attach. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:46:18 2020(r361520) +++ head/sys/dev/ena/ena.c Tue May 26 15:48:06 2020(r361521) @@ -96,6 +96,8 @@ static inline void ena_free_counters(counter_u64_t *, static inline void ena_reset_counters(counter_u64_t *, int); static voidena_init_io_rings_common(struct ena_adapter *, struct ena_ring *, uint16_t); +static voidena_init_io_rings_basic(struct ena_adapter *); +static voidena_init_io_rings_advanced(struct ena_adapter *); static voidena_init_io_rings(struct ena_adapter *); static voidena_free_io_ring_resources(struct ena_adapter *, unsigned int); static voidena_free_all_io_rings_resources(struct ena_adapter *); @@ -151,12 +153,9 @@ static int ena_setup_ifnet(device_t, struct ena_adapte static int ena_enable_wc(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_calc_io_queue_num(struct ena_adapter *, +static uint32_tena_calc_max_io_queue_num(device_t, struct ena_com_dev *, struct ena_com_dev_get_features_ctx *); -static int ena_calc_queue_size(struct ena_adapter *, -struct ena_calc_queue_size_ctx *); -static int ena_handle_updated_queues(struct ena_adapter *, -struct ena_com_dev_get_features_ctx *); +static int ena_calc_io_queue_size(struct ena_calc_queue_size_ctx *); static int ena_rss_init_default(struct ena_adapter *); static voidena_rss_init_default_deferred(void *); static voidena_config_host_info(struct ena_com_dev *, device_t); @@ -388,11 +387,10 @@ ena_init_io_rings_common(struct ena_adapter *adapter, ring->ena_dev = adapter->ena_dev; ring->first_interrupt = false; ring->no_interrupt_event_cnt = 0; - ring->rx_mbuf_sz = ena_mbuf_sz; } static void -ena_init_io_rings(struct ena_adapter *adapter) +ena_init_io_rings_basic(struct ena_adapter *adapter) { struct ena_com_dev *ena_dev; struct ena_ring *txr, *rxr; @@ -401,7 +399,7 @@ ena_init_io_rings(struct ena_adapter *adapter) ena_dev = adapter->ena_dev; - for (i = 0; i < adapter->num_queues; i++) { + for (i = 0; i < adapter->num_io_queues; i++) { txr = &adapter->tx_ring[i]; rxr = &adapter->rx_ring[i]; @@ -414,19 +412,43 @@ ena_init_io_rings(struct ena_adapter *adapter) txr->tx_max_header_size = ena_dev->tx_max_header_size; txr->tx_mem_queue_type = ena_dev->tx_mem_queue_type; + /* RX specific ring state */ + rxr->ring_size = adapter->rx_ring_size; + + que = &adapter->que[i]; + que->adapter = adapter; + que->id = i; + que->tx_ring = txr; + que->rx_ring = rxr; + + txr->que = que; + rxr->que = que; + + rxr->empty_rx_queue = 0; + rxr->rx_mbuf_sz = ena_mbuf_sz; + } +} + +static void +ena_init_io_rings_advanced(struct ena_adapter *adapter) +{ + struct ena_ring *txr, *rxr; + int i; + + for (i = 0; i < adapter->num_io_queues; i++) { + txr = &adapter->tx_ring[i]; + rxr = &adapter->rx_ring[i]; + /* Allocate a buf ring */ txr-
svn commit: r361518 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:44:08 2020 New Revision: 361518 URL: https://svnweb.freebsd.org/changeset/base/361518 Log: Improve indentation in ena_up() and ena_down() If the conditional check for ENA_FLAG_DEV_UP is negated, the body of the function can have smaller indentation and it makes the code cleaner. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:41:53 2020(r361517) +++ head/sys/dev/ena/ena.c Tue May 26 15:44:08 2020(r361518) @@ -1788,71 +1788,72 @@ ena_up(struct ena_adapter *adapter) return (ENXIO); } - if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) { - device_printf(adapter->pdev, "device is going UP\n"); + if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) + return (0); - /* setup interrupts for IO queues */ - rc = ena_setup_io_intr(adapter); - if (unlikely(rc != 0)) { - ena_trace(ENA_ALERT, "error setting up IO interrupt\n"); - goto error; - } - rc = ena_request_io_irq(adapter); - if (unlikely(rc != 0)) { - ena_trace(ENA_ALERT, "err_req_irq\n"); - goto error; - } + device_printf(adapter->pdev, "device is going UP\n"); - /* allocate transmit descriptors */ - rc = ena_setup_all_tx_resources(adapter); - if (unlikely(rc != 0)) { - ena_trace(ENA_ALERT, "err_setup_tx\n"); - goto err_setup_tx; - } + /* setup interrupts for IO queues */ + rc = ena_setup_io_intr(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "error setting up IO interrupt\n"); + goto error; + } + rc = ena_request_io_irq(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "err_req_irq\n"); + goto error; + } - /* allocate receive descriptors */ - rc = ena_setup_all_rx_resources(adapter); - if (unlikely(rc != 0)) { - ena_trace(ENA_ALERT, "err_setup_rx\n"); - goto err_setup_rx; - } + /* allocate transmit descriptors */ + rc = ena_setup_all_tx_resources(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "err_setup_tx\n"); + goto err_setup_tx; + } - /* create IO queues for Rx & Tx */ - rc = ena_create_io_queues(adapter); - if (unlikely(rc != 0)) { - ena_trace(ENA_ALERT, - "create IO queues failed\n"); - goto err_io_que; - } + /* allocate receive descriptors */ + rc = ena_setup_all_rx_resources(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "err_setup_rx\n"); + goto err_setup_rx; + } - if (ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter)) - if_link_state_change(adapter->ifp, LINK_STATE_UP); + /* create IO queues for Rx & Tx */ + rc = ena_create_io_queues(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, + "create IO queues failed\n"); + goto err_io_que; + } - rc = ena_up_complete(adapter); - if (unlikely(rc != 0)) - goto err_up_complete; + if (ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter)) + if_link_state_change(adapter->ifp, LINK_STATE_UP); - counter_u64_add(adapter->dev_stats.interface_up, 1); + rc = ena_up_complete(adapter); + if (unlikely(rc != 0)) + goto err_up_complete; - ena_update_hwassist(adapter); + counter_u64_add(adapter->dev_stats.interface_up, 1); - if_setdrvflagbits(adapter->ifp, IFF_DRV_RUNNING, - IFF_DRV_OACTIVE); + ena_update_hwassist(adapter); - /* Activate timer service only if the device is running. -* If this flag is not set, it means that the driver is being -* reset and timer service will be activated afterwards. -*/ - if (ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter)) { - callout_reset_sbt(&adapter->timer_service, SBT_1S, - SBT_1S, ena_timer_service, (void *)adapter, 0); - } + if_setdrvflagbits(adapter->ifp, IFF_DRV_RUNNING, + IFF_DRV_OACTIVE); - ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV
svn commit: r361517 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:41:53 2020 New Revision: 361517 URL: https://svnweb.freebsd.org/changeset/base/361517 Log: Expose argument names for non static ENA driver functions As functions which are declared in the header files are intended to be the interface and are going to be used by other files, it's better to include argument names in the definition, so the caller won't have to check the .c file in order to check their meaning and order. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.h head/sys/dev/ena/ena_netmap.h head/sys/dev/ena/ena_sysctl.h Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 15:39:41 2020(r361516) +++ head/sys/dev/ena/ena.h Tue May 26 15:41:53 2020(r361517) @@ -483,11 +483,11 @@ static inline int ena_mbuf_count(struct mbuf *mbuf) return count; } -intena_up(struct ena_adapter *); -void ena_down(struct ena_adapter *); -intena_restore_device(struct ena_adapter *); -void ena_destroy_device(struct ena_adapter *, bool); -intena_refill_rx_bufs(struct ena_ring *, uint32_t); +intena_up(struct ena_adapter *adapter); +void ena_down(struct ena_adapter *adapter); +intena_restore_device(struct ena_adapter *adapter); +void ena_destroy_device(struct ena_adapter *adapter, bool graceful); +intena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t num); static inline void ena_trigger_reset(struct ena_adapter *adapter, Modified: head/sys/dev/ena/ena_datapath.h == --- head/sys/dev/ena/ena_datapath.h Tue May 26 15:39:41 2020 (r361516) +++ head/sys/dev/ena/ena_datapath.h Tue May 26 15:41:53 2020 (r361517) @@ -34,9 +34,9 @@ #ifndef ENA_TXRX_H #define ENA_TXRX_H -void ena_cleanup(void *, int); -void ena_qflush(if_t); -intena_mq_start(if_t, struct mbuf *); -void ena_deferred_mq_start(void *, int); +void ena_cleanup(void *arg, int pending); +void ena_qflush(if_t ifp); +intena_mq_start(if_t ifp, struct mbuf *m); +void ena_deferred_mq_start(void *arg, int pending); #endif /* ENA_TXRX_H */ Modified: head/sys/dev/ena/ena_netmap.h == --- head/sys/dev/ena/ena_netmap.h Tue May 26 15:39:41 2020 (r361516) +++ head/sys/dev/ena/ena_netmap.h Tue May 26 15:41:53 2020 (r361517) @@ -46,15 +46,15 @@ #include #include -intena_netmap_attach(struct ena_adapter *); -intena_netmap_alloc_rx_slot(struct ena_adapter *, struct ena_ring *, -struct ena_rx_buffer *); -void ena_netmap_free_rx_slot(struct ena_adapter *, struct ena_ring *, -struct ena_rx_buffer *); -bool ena_rx_ring_in_netmap(struct ena_adapter *, int); -bool ena_tx_ring_in_netmap(struct ena_adapter *, int); -void ena_netmap_reset_rx_ring(struct ena_adapter *, int); -void ena_netmap_reset_tx_ring(struct ena_adapter *, int); -void ena_netmap_unload(struct ena_adapter *, bus_dmamap_t); +intena_netmap_attach(struct ena_adapter *adapter); +intena_netmap_alloc_rx_slot(struct ena_adapter *adapter, +struct ena_ring *rx_ring, struct ena_rx_buffer *rx_info); +void ena_netmap_free_rx_slot(struct ena_adapter *adapter, +struct ena_ring *rx_ring, struct ena_rx_buffer *rx_info); +bool ena_rx_ring_in_netmap(struct ena_adapter *adapter, int qid); +bool ena_tx_ring_in_netmap(struct ena_adapter *adapter, int qid); +void ena_netmap_reset_rx_ring(struct ena_adapter *adapter, int qid); +void ena_netmap_reset_tx_ring(struct ena_adapter *adapter, int qid); +void ena_netmap_unload(struct ena_adapter *adapter, bus_dmamap_t map); #endif /* _ENA_NETMAP_H_ */ Modified: head/sys/dev/ena/ena_sysctl.h == --- head/sys/dev/ena/ena_sysctl.h Tue May 26 15:39:41 2020 (r361516) +++ head/sys/dev/ena/ena_sysctl.h Tue May 26 15:41:53 2020 (r361517) @@ -39,7 +39,7 @@ #include "ena.h" -void ena_sysctl_add_nodes(struct ena_adapter *); +void ena_sysctl_add_nodes(struct ena_adapter *adapter); extern int ena_enable_9k_mbufs; #define ena_mbuf_sz (ena_enable_9k_mbufs ? MJUM9BYTES : MJUMPAGESIZE) ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361516 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:39:41 2020 New Revision: 361516 URL: https://svnweb.freebsd.org/changeset/base/361516 Log: Use single global lock in the ENA driver Currently, the driver had 2 global locks - one was sx lock used for up/down synchronization and the second one was mutex, which was used for link configuration and timer service callout. It is better to have single lock for that. We cannot use mutex, as it can sleep and cause witness errors in up/down configuration, so sx lock seems to be the only choice. Callout cannot use sx lock, but the timer service is MP safe, so we just need to avoid race between ena_down() and ena_detach(). It can be avoided by acquiring sx lock. Simple macros were added that are encapsulating implementation of the lock and makes the code cleaner. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_netmap.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:37:55 2020(r361515) +++ head/sys/dev/ena/ena.c Tue May 26 15:39:41 2020(r361516) @@ -1907,13 +1907,13 @@ ena_media_status(if_t ifp, struct ifmediareq *ifmr) struct ena_adapter *adapter = if_getsoftc(ifp); ena_trace(ENA_DBG, "enter\n"); - mtx_lock(&adapter->global_mtx); + ENA_LOCK_LOCK(adapter); ifmr->ifm_status = IFM_AVALID; ifmr->ifm_active = IFM_ETHER; if (!ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter)) { - mtx_unlock(&adapter->global_mtx); + ENA_LOCK_UNLOCK(adapter); ena_trace(ENA_INFO, "Link is down\n"); return; } @@ -1921,7 +1921,7 @@ ena_media_status(if_t ifp, struct ifmediareq *ifmr) ifmr->ifm_status |= IFM_ACTIVE; ifmr->ifm_active |= IFM_UNKNOWN | IFM_FDX; - mtx_unlock(&adapter->global_mtx); + ENA_LOCK_UNLOCK(adapter); } static void @@ -1930,9 +1930,9 @@ ena_init(void *arg) struct ena_adapter *adapter = (struct ena_adapter *)arg; if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) { - sx_xlock(&adapter->ioctl_sx); + ENA_LOCK_LOCK(adapter); ena_up(adapter); - sx_unlock(&adapter->ioctl_sx); + ENA_LOCK_UNLOCK(adapter); } } @@ -1954,13 +1954,13 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) case SIOCSIFMTU: if (ifp->if_mtu == ifr->ifr_mtu) break; - sx_xlock(&adapter->ioctl_sx); + ENA_LOCK_LOCK(adapter); ena_down(adapter); ena_change_mtu(ifp, ifr->ifr_mtu); rc = ena_up(adapter); - sx_unlock(&adapter->ioctl_sx); + ENA_LOCK_UNLOCK(adapter); break; case SIOCSIFFLAGS: @@ -1972,15 +1972,15 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) "ioctl promisc/allmulti\n"); } } else { - sx_xlock(&adapter->ioctl_sx); + ENA_LOCK_LOCK(adapter); rc = ena_up(adapter); - sx_unlock(&adapter->ioctl_sx); + ENA_LOCK_UNLOCK(adapter); } } else { if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0) { - sx_xlock(&adapter->ioctl_sx); + ENA_LOCK_LOCK(adapter); ena_down(adapter); - sx_unlock(&adapter->ioctl_sx); + ENA_LOCK_UNLOCK(adapter); } } break; @@ -2005,10 +2005,10 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) if ((reinit != 0) && ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0)) { - sx_xlock(&adapter->ioctl_sx); + ENA_LOCK_LOCK(adapter); ena_down(adapter); rc = ena_up(adapter); - sx_unlock(&adapter->ioctl_sx); + ENA_LOCK_UNLOCK(adapter); } } @@ -3180,10 +3180,10 @@ ena_reset_task(void *arg, int pending) return; } - sx_xlock(&adapter->ioctl_sx); + ENA_LOCK_LOCK(adapter); ena_destroy_device(adapter, false); ena_restore_device(adapter); - sx_unlock(&adapter->ioctl_sx); + ENA_LOCK_UNLOCK(adapter); } /** @@ -3212,11 +3212,13 @@ ena_attach(device_t pdev) ad
svn commit: r361515 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:37:55 2020 New Revision: 361515 URL: https://svnweb.freebsd.org/changeset/base/361515 Log: Add trigger reset function in the ENA driver As the reset triggering is no longer a simple macro that was just setting appropriate flag, the new function for triggering reset was added. It improves code readability a lot, as we are avoiding additional indentation. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_netmap.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:35:22 2020(r361514) +++ head/sys/dev/ena/ena.c Tue May 26 15:37:55 2020(r361515) @@ -2742,10 +2742,7 @@ static void check_for_missing_keep_alive(struct ena_ad device_printf(adapter->pdev, "Keep alive watchdog timeout.\n"); counter_u64_add(adapter->dev_stats.wd_expired, 1); - if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { - adapter->reset_reason = ENA_REGS_RESET_KEEP_ALIVE_TO; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); - } + ena_trigger_reset(adapter, ENA_REGS_RESET_KEEP_ALIVE_TO); } } @@ -2757,10 +2754,7 @@ static void check_for_admin_com_state(struct ena_adapt device_printf(adapter->pdev, "ENA admin queue is not in running state!\n"); counter_u64_add(adapter->dev_stats.admin_q_pause, 1); - if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { - adapter->reset_reason = ENA_REGS_RESET_ADMIN_TO; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); - } + ena_trigger_reset(adapter, ENA_REGS_RESET_ADMIN_TO); } } @@ -2779,10 +2773,7 @@ check_for_rx_interrupt_queue(struct ena_adapter *adapt if (rx_ring->no_interrupt_event_cnt == ENA_MAX_NO_INTERRUPT_ITERATIONS) { device_printf(adapter->pdev, "Potential MSIX issue on Rx side " "Queue = %d. Reset the device\n", rx_ring->qid); - if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { - adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); - } + ena_trigger_reset(adapter, ENA_REGS_RESET_MISS_INTERRUPT); return (EIO); } @@ -2820,13 +2811,8 @@ check_missing_comp_in_tx_queue(struct ena_adapter *ada device_printf(adapter->pdev, "Potential MSIX issue on Tx side Queue = %d. " "Reset the device\n", tx_ring->qid); - if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, - adapter))) { - adapter->reset_reason = - ENA_REGS_RESET_MISS_INTERRUPT; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, - adapter); - } + ena_trigger_reset(adapter, + ENA_REGS_RESET_MISS_INTERRUPT); return (EIO); } @@ -2848,10 +2834,7 @@ check_missing_comp_in_tx_queue(struct ena_adapter *ada "The number of lost tx completion is above the threshold " "(%d > %d). Reset the device\n", missed_tx, adapter->missing_tx_threshold); - if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { - adapter->reset_reason = ENA_REGS_RESET_MISS_TX_CMPL; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); - } + ena_trigger_reset(adapter, ENA_REGS_RESET_MISS_TX_CMPL); rc = EIO; } Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 15:35:22 2020(r361514) +++ head/sys/dev/ena/ena.h Tue May 26 15:37:55 2020(r361515) @@ -484,6 +484,16 @@ intena_restore_device(struct ena_adapter *); void ena_destroy_device(struct ena_adapter *, bool); intena_refill_rx_bufs(struct ena_ring *, uint32_t); +static inline void +ena_trigger_reset(struct ena_adapter *adapter, +enum ena_regs_reset_reason_types reset_reason) +{ + if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { + adapter->reset_reason = reset_reason; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + } +} + stati
svn commit: r361514 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:35:22 2020 New Revision: 361514 URL: https://svnweb.freebsd.org/changeset/base/361514 Log: Provide ENA driver version in a sysctl node Usage example: $ sysctl hw.ena.driver_version Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena_sysctl.c == --- head/sys/dev/ena/ena_sysctl.c Tue May 26 15:33:43 2020 (r361513) +++ head/sys/dev/ena/ena_sysctl.c Tue May 26 15:35:22 2020 (r361514) @@ -48,6 +48,9 @@ int ena_log_level = ENA_ALERT | ENA_WARNING; SYSCTL_INT(_hw_ena, OID_AUTO, log_level, CTLFLAG_RWTUN, &ena_log_level, 0, "Logging level indicating verbosity of the logs"); +SYSCTL_CONST_STRING(_hw_ena, OID_AUTO, driver_version, CTLFLAG_RD, +DRV_MODULE_VERSION, "ENA driver version"); + /* * Use 9k mbufs for the Rx buffers. Default to 0 (use page size mbufs instead). * Using 9k mbufs in low memory conditions might cause allocation to take a lot ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361513 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:33:43 2020 New Revision: 361513 URL: https://svnweb.freebsd.org/changeset/base/361513 Log: Remove unused argument from static function in ena.c The function ena_enable_msix_and_set_admin_interrupts takes two arguments while the second is not used and so can be spared. This is a static function, only ena.c is affected. Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:31:28 2020(r361512) +++ head/sys/dev/ena/ena.c Tue May 26 15:33:43 2020(r361513) @@ -164,8 +164,7 @@ static int ena_attach(device_t); static int ena_detach(device_t); static int ena_device_init(struct ena_adapter *, device_t, struct ena_com_dev_get_features_ctx *, int *); -static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *, -int); +static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *); static void ena_update_on_link_change(void *, struct ena_admin_aenq_entry *); static voidunimplemented_aenq_handler(void *, struct ena_admin_aenq_entry *); @@ -2672,8 +2671,7 @@ err_mmio_read_less: return (rc); } -static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *adapter, -int io_vectors) +static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *adapter) { struct ena_com_dev *ena_dev = adapter->ena_dev; int rc; @@ -3136,8 +3134,7 @@ ena_restore_device(struct ena_adapter *adapter) if (ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter)) if_link_state_change(ifp, LINK_STATE_UP); - rc = ena_enable_msix_and_set_admin_interrupts(adapter, - adapter->num_queues); + rc = ena_enable_msix_and_set_admin_interrupts(adapter); if (rc != 0) { device_printf(dev, "Enable MSI-X failed\n"); goto err_device_destroy; @@ -3365,7 +3362,7 @@ ena_attach(device_t pdev) calc_queue_ctx.tx_queue_size); ena_init_io_rings(adapter); - rc = ena_enable_msix_and_set_admin_interrupts(adapter, io_queue_num); + rc = ena_enable_msix_and_set_admin_interrupts(adapter); if (unlikely(rc != 0)) { device_printf(pdev, "Failed to enable and set the admin interrupts\n"); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361512 - head/sys/dev/ena
Author: mw Date: Tue May 26 15:31:28 2020 New Revision: 361512 URL: https://svnweb.freebsd.org/changeset/base/361512 Log: Enable Tx drops reporting in the ENA driver Tx drops statistics are fetched from HW every ena_keepalive_wd() call and are observable using one of the commands: * sysctl dev.ena.0.hw_stats.tx_drops * netstat -I ena0 -d Submitted by: Maciej Bielski Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Tue May 26 15:29:19 2020(r361511) +++ head/sys/dev/ena/ena.c Tue May 26 15:31:28 2020(r361512) @@ -1888,6 +1888,8 @@ ena_get_counter(if_t ifp, ift_counter cnt) return (counter_u64_fetch(stats->tx_bytes)); case IFCOUNTER_IQDROPS: return (counter_u64_fetch(stats->rx_drops)); + case IFCOUNTER_OQDROPS: + return (counter_u64_fetch(stats->tx_drops)); default: return (if_get_counter_default(ifp, cnt)); } @@ -2710,12 +2712,16 @@ static void ena_keep_alive_wd(void *adapter_data, struct ena_admin_aenq_keep_alive_desc *desc; sbintime_t stime; uint64_t rx_drops; + uint64_t tx_drops; desc = (struct ena_admin_aenq_keep_alive_desc *)aenq_e; rx_drops = ((uint64_t)desc->rx_drops_high << 32) | desc->rx_drops_low; + tx_drops = ((uint64_t)desc->tx_drops_high << 32) | desc->tx_drops_low; counter_u64_zero(adapter->hw_stats.rx_drops); counter_u64_add(adapter->hw_stats.rx_drops, rx_drops); + counter_u64_zero(adapter->hw_stats.tx_drops); + counter_u64_add(adapter->hw_stats.tx_drops, tx_drops); stime = getsbinuptime(); atomic_store_rel_64(&adapter->keep_alive_timestamp, stime); Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Tue May 26 15:29:19 2020(r361511) +++ head/sys/dev/ena/ena.h Tue May 26 15:31:28 2020(r361512) @@ -380,6 +380,7 @@ struct ena_hw_stats { counter_u64_t tx_bytes; counter_u64_t rx_drops; + counter_u64_t tx_drops; }; /* Board specific private data structure */ Modified: head/sys/dev/ena/ena_sysctl.c == --- head/sys/dev/ena/ena_sysctl.c Tue May 26 15:29:19 2020 (r361511) +++ head/sys/dev/ena/ena_sysctl.c Tue May 26 15:31:28 2020 (r361512) @@ -267,6 +267,8 @@ ena_sysctl_add_stats(struct ena_adapter *adapter) &hw_stats->tx_bytes, "Bytes transmitted"); SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_drops", CTLFLAG_RD, &hw_stats->rx_drops, "Receive packet drops"); + SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "tx_drops", CTLFLAG_RD, + &hw_stats->tx_drops, "Transmit packet drops"); /* ENA Admin queue stats */ admin_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "admin_stats", ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361511 - in head/sys: contrib/ena-com contrib/ena-com/ena_defs dev/ena
Author: mw Date: Tue May 26 15:29:19 2020 New Revision: 361511 URL: https://svnweb.freebsd.org/changeset/base/361511 Log: Adjust ENA driver to the new HAL * Removed adaptive interrupt moderation (not suported on FreeBSD). * Use ena_com_free_q_entries instead of ena_com_free_desc. * Don't use ENA_MEM_FREE outside of the ena_com. * Don't use barriers before calling doorbells as it's already done in the HAL. * Add function that generates random RSS key, common for all driver's interfaces. * Change admin stats sysctls to U64. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/contrib/ena-com/ena_com.c head/sys/contrib/ena-com/ena_com.h head/sys/contrib/ena-com/ena_defs/ena_admin_defs.h head/sys/contrib/ena-com/ena_defs/ena_common_defs.h head/sys/contrib/ena-com/ena_defs/ena_eth_io_defs.h head/sys/contrib/ena-com/ena_defs/ena_gen_info.h head/sys/contrib/ena-com/ena_defs/ena_regs_defs.h head/sys/contrib/ena-com/ena_eth_com.c head/sys/contrib/ena-com/ena_eth_com.h head/sys/contrib/ena-com/ena_plat.h head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_sysctl.c Directory Properties: head/sys/contrib/ena-com/ (props changed) Modified: head/sys/contrib/ena-com/ena_com.c == --- head/sys/contrib/ena-com/ena_com.c Tue May 26 15:12:09 2020 (r361510) +++ head/sys/contrib/ena-com/ena_com.c Tue May 26 15:29:19 2020 (r361511) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -70,8 +70,10 @@ #define ENA_REGS_ADMIN_INTR_MASK 1 -#define ENA_POLL_MS5 +#define ENA_MIN_POLL_US 100 +#define ENA_MAX_POLL_US 5000 + /*/ /*/ /*/ @@ -99,7 +101,7 @@ struct ena_com_stats_ctx { struct ena_admin_acq_get_stats_resp get_resp; }; -static inline int ena_com_mem_addr_set(struct ena_com_dev *ena_dev, +static int ena_com_mem_addr_set(struct ena_com_dev *ena_dev, struct ena_common_mem_addr *ena_addr, dma_addr_t addr) { @@ -200,7 +202,7 @@ static int ena_com_admin_init_aenq(struct ena_com_dev return 0; } -static inline void comp_ctxt_release(struct ena_com_admin_queue *queue, +static void comp_ctxt_release(struct ena_com_admin_queue *queue, struct ena_comp_ctx *comp_ctx) { comp_ctx->occupied = false; @@ -216,6 +218,11 @@ static struct ena_comp_ctx *get_comp_ctxt(struct ena_c return NULL; } + if (unlikely(!queue->comp_ctx)) { + ena_trc_err("Completion context is NULL\n"); + return NULL; + } + if (unlikely(queue->comp_ctx[command_id].occupied && capture)) { ena_trc_err("Completion context is occupied\n"); return NULL; @@ -289,7 +296,7 @@ static struct ena_comp_ctx *__ena_com_submit_admin_cmd return comp_ctx; } -static inline int ena_com_init_comp_ctxt(struct ena_com_admin_queue *queue) +static int ena_com_init_comp_ctxt(struct ena_com_admin_queue *queue) { size_t size = queue->q_depth * sizeof(struct ena_comp_ctx); struct ena_comp_ctx *comp_ctx; @@ -409,6 +416,8 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_ 0x0, io_sq->llq_info.desc_list_entry_size); io_sq->llq_buf_ctrl.descs_left_in_line = io_sq->llq_info.descs_num_before_header; + io_sq->disable_meta_caching = + io_sq->llq_info.disable_meta_caching; if (io_sq->llq_info.max_entries_in_tx_burst > 0) io_sq->entries_in_tx_burst_left = @@ -534,12 +543,9 @@ static int ena_com_comp_status_to_errno(u8 comp_status if (unlikely(comp_status != 0)) ena_trc_err("admin command failed[%u]\n", comp_status); - if (unlikely(comp_status > ENA_ADMIN_UNKNOWN_ERROR)) - return ENA_COM_INVAL; - switch (comp_status) { case ENA_ADMIN_SUCCESS: - return 0; + return ENA_COM_OK; case ENA_ADMIN_RESOURCE_ALLOCATION_FAILURE: return ENA_COM_NO_MEM; case ENA_ADMIN_UNSUPPORTED_OPCODE: @@ -551,24 +557,32 @@ static int ena_com_comp_status_to_errno(u8 comp_status return ENA_COM_INVAL; } - return 0; + return ENA
svn commit: r361507 - head/sys/netipsec
Author: mw Date: Tue May 26 14:16:26 2020 New Revision: 361507 URL: https://svnweb.freebsd.org/changeset/base/361507 Log: Fix AES-CTR compatibility issue in ipsec r361390 decreased blocksize of AES-CTR from 16 to 1. Because of that ESP payload is no longer aligned to 16 bytes before being encrypted and sent. This is a good change since RFC3686 specifies that the last block doesn't need to be aligned. Since FreeBSD before r361390 couldn't decrypt partial blocks encrypted with AES-CTR we need to enforce 16 byte alignment in order to preserve compatibility. Add a sysctl(on by default) to control it. Submitted by: Kornel Duleba Reviewed by: jhb Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D24999 Modified: head/sys/netipsec/xform_esp.c Modified: head/sys/netipsec/xform_esp.c == --- head/sys/netipsec/xform_esp.c Tue May 26 14:10:53 2020 (r361506) +++ head/sys/netipsec/xform_esp.c Tue May 26 14:16:26 2020 (r361507) @@ -80,6 +80,8 @@ #include VNET_DEFINE(int, esp_enable) = 1; +VNET_DEFINE_STATIC(int, esp_ctr_compatibility) = 1; +#define V_esp_ctr_compatibility VNET(esp_ctr_compatibility) VNET_PCPUSTAT_DEFINE(struct espstat, espstat); VNET_PCPUSTAT_SYSINIT(espstat); @@ -90,6 +92,9 @@ VNET_PCPUSTAT_SYSUNINIT(espstat); SYSCTL_DECL(_net_inet_esp); SYSCTL_INT(_net_inet_esp, OID_AUTO, esp_enable, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(esp_enable), 0, ""); +SYSCTL_INT(_net_inet_esp, OID_AUTO, ctr_compatibility, +CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(esp_ctr_compatibility), 0, +"Align AES-CTR encrypted transmitted frames to blocksize"); SYSCTL_VNET_PCPUSTAT(_net_inet_esp, IPSECCTL_STATS, stats, struct espstat, espstat, "ESP statistics (struct espstat, netipsec/esp_var.h"); @@ -652,8 +657,14 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struc rlen = m->m_pkthdr.len - skip; /* Raw payload length. */ /* * RFC4303 2.4 Requires 4 byte alignment. +* Old versions of FreeBSD can't decrypt partial blocks encrypted +* with AES-CTR. Align payload to native_blocksize (16 bytes) +* in order to preserve compatibility. */ - blks = MAX(4, espx->blocksize); /* Cipher blocksize */ + if (SAV_ISCTR(sav) && V_esp_ctr_compatibility) + blks = MAX(4, espx->native_blocksize); /* Cipher blocksize */ + else + blks = MAX(4, espx->blocksize); /* XXX clamp padding length a la KAME??? */ padding = ((blks - ((rlen + 2) % blks)) % blks) + 2; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361506 - head/sys/arm/mv
Author: mw Date: Tue May 26 14:10:53 2020 New Revision: 361506 URL: https://svnweb.freebsd.org/changeset/base/361506 Log: Restore XHCI operation on Armada 38x r347343 split generic xhci driver into three files. Include generic_xhci_fdt.c when building kernel for Armada SoCs. This brings back XHCI support on these platforms and also others, which use GENERIC config. Submitted by: Kornel Duleba Obtained from: Semihalf MFC after: 1 week Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D24944 Modified: head/sys/arm/mv/files.arm7 Modified: head/sys/arm/mv/files.arm7 == --- head/sys/arm/mv/files.arm7 Tue May 26 14:06:07 2020(r361505) +++ head/sys/arm/mv/files.arm7 Tue May 26 14:10:53 2020(r361506) @@ -34,4 +34,5 @@ dev/uart/uart_dev_ns8250.coptionaluart dev/uart/uart_dev_snps.c optionaluart dev/usb/controller/ehci_mv.c optionalehci dev/usb/controller/generic_xhci.c optionalxhci +dev/usb/controller/generic_xhci_fdt.c optionalxhci dev/ahci/ahci_mv_fdt.c optionalahci ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r361460 - in head/sys: arm64/conf arm64/qoriq conf
Hi Justin, pon., 25 maj 2020 o 18:18 Justin Hibbits napisał(a): > > Hi Marcin, > > On Mon, 25 May 2020 14:55:37 +0000 (UTC) > Marcin Wojtas wrote: > > > Author: mw > > Date: Mon May 25 14:55:37 2020 > > New Revision: 361460 > > URL: https://svnweb.freebsd.org/changeset/base/361460 > > > > Log: > > Add GPIO support for QorIQ boards. > > > > This patch adds a GPIO controller support targeted for NXP LS1046A > > SoC. The driver implements the following features: > >* setting direction of each pin (IN or OUT) > >* setting the mode of output pins (PUSHPULL or OPENDRAIN) > >* setting the state of each output pin (1 or 0) > >* reading the state of each input pin (1 or 0) > > > > Submitted by: Kamil Koczurek > > Dawid Gorecki > > Reviewed by: manu > > Obtained from: Semihalf > > Sponsored by: Alstom Group > > Differential Revision: https://reviews.freebsd.org/D24353 > > > > Added: > > head/sys/arm64/qoriq/ls1046_gpio.c (contents, props changed) > > Modified: > > head/sys/arm64/conf/GENERIC > > head/sys/conf/files.arm64 > > > > Modified: head/sys/arm64/conf/GENERIC > > == > > --- head/sys/arm64/conf/GENERIC Mon May 25 14:45:18 > > 2020 (r361459) +++ head/sys/arm64/conf/GENERIC Mon May > > 25 14:55:37 2020 (r361460) @@ -248,6 +248,7 @@ device > > gpio device gpioled > > device fdt_pinctrl > > device gpioregulator > > +device ls1046_gpio # LS1046A GPIO controller > > device mv_gpio # Marvell GPIO > > controller device mvebu_pinctrl # Marvell > > Pinmux Controller device rk_gpio # > > RockChip GPIO Controller > > > > Added: head/sys/arm64/qoriq/ls1046_gpio.c > > == > > --- /dev/null 00:00:00 1970 (empty, because file is > > newly added) +++ head/sys/arm64/qoriq/ls1046_gpio.c Mon May 25 > > 14:55:37 2020 (r361460) @@ -0,0 +1,586 @@ > > +/*- > > + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD > > + * > > + * Copyright (c) 2020 Alstom Group. > > + * Copyright (c) 2020 Semihalf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + *notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above > > copyright > > + *notice, this list of conditions and the following disclaimer > > in the > > + *documentation and/or other materials provided with the > > distribution. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS > > IS'' AND > > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, > > THE > > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > > PARTICULAR PURPOSE > > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE > > LIABLE > > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > > CONSEQUENTIAL > > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE > > GOODS > > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS > > INTERRUPTION) > > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN > > CONTRACT, STRICT > > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN > > ANY WAY > > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE > > POSSIBILITY OF > > + * SUCH DAMAGE. > > + */ > > + > > +#include > > +__FBSDID("$FreeBSD$"); > > + > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > + > > +#include "gpio_if.h" > > + > > +/* constants */ > > +enum { > > + DIRECTION = 0x0, > > + OPEN_DRAIN = 0x4, > > + DATA = 0x8, > > + INT_EV = 0xC, > > + INT_MASK = 0x10, > > + INT_CTRL = 0x14 > > +}; > > This looks a lot like the GPIO module whose driver is in > sys/powerpc/mpc85xx/qoriq_gpio.c. Is there any difference in hardware? > If not, can you merge this driver with that, if there's anything to > merge, to reduce duplication? > Thanks, will check. Best regards, Marcin ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r361464 - in head/sys: conf dev/ahci
Author: mw Date: Mon May 25 16:00:08 2020 New Revision: 361464 URL: https://svnweb.freebsd.org/changeset/base/361464 Log: Introduce a driver for NXP LS1046A SoC AHCI. Implement support for AHCI controller found in NXP QorIQ Layerscape SoCs. Submitted by: Artur Rojek Reviewed by: manu Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24466 Added: head/sys/dev/ahci/ahci_fsl_fdt.c (contents, props changed) Modified: head/sys/conf/files.arm64 Modified: head/sys/conf/files.arm64 == --- head/sys/conf/files.arm64 Mon May 25 15:40:02 2020(r361463) +++ head/sys/conf/files.arm64 Mon May 25 16:00:08 2020(r361464) @@ -232,6 +232,7 @@ dev/acpica/acpi_if.moptionalacpi dev/acpica/acpi_pci_link.c optionalacpi pci dev/acpica/acpi_pcib.c optionalacpi pci dev/acpica/acpi_pxm.c optionalacpi +dev/ahci/ahci_fsl_fdt.coptionalSOC_NXP_LS ahci fdt dev/ahci/ahci_generic.coptionalahci dev/altera/dwc/if_dwc_socfpga.coptionalfdt dwc_socfpga dev/axgbe/if_axgbe.c optionalaxgbe Added: head/sys/dev/ahci/ahci_fsl_fdt.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/ahci/ahci_fsl_fdt.cMon May 25 16:00:08 2020 (r361464) @@ -0,0 +1,287 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group + * Copyright (c) 2020 Semihalf + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* AHCI controller driver for NXP QorIQ Layerscape SoCs. */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#defineAHCI_FSL_REG_PHY1 0xa8 +#defineAHCI_FSL_REG_PHY2 0xac +#defineAHCI_FSL_REG_PHY3 0xb0 +#defineAHCI_FSL_REG_PHY4 0xb4 +#defineAHCI_FSL_REG_PHY5 0xb8 +#defineAHCI_FSL_REG_PTC0xc8 + +#defineAHCI_FSL_REG_PHY1_TTA_MASK 0x0001 +#defineAHCI_FSL_REG_PHY1_SNM (1 << 17) +#defineAHCI_FSL_REG_PHY1_SNR (1 << 18) +#defineAHCI_FSL_REG_PHY1_FPR (1 << 20) +#defineAHCI_FSL_REG_PHY1_PBPS_LBP 0 +#defineAHCI_FSL_REG_PHY1_PBPS_LFTP (0x01 << 21) +#defineAHCI_FSL_REG_PHY1_PBPS_MFTP (0x02 << 21) +#defineAHCI_FSL_REG_PHY1_PBPS_HFTP (0x03 << 21) +#defineAHCI_FSL_REG_PHY1_PBPS_PRBS (0x04 << 21) +#defineAHCI_FSL_REG_PHY1_PBPS_BIST (0x05 << 21) +#defineAHCI_FSL_REG_PHY1_PBPE (1 << 24) +#defineAHCI_FSL_REG_PHY1_PBCE (1 << 25) +#defineAHCI_FSL_REG_PHY1_PBPNA (1 << 26) +#defineAHCI_FSL_REG_PHY1_STB (1 << 27) +#defineAHCI_FSL_REG_PHY1_PSSO (1 << 28) +#defineAHCI_FSL_REG_PHY1_PSS (1 << 29) +#defineAHCI_FSL_REG_PHY1_ERSN (1 << 30) +#defineAHCI_FSL_REG_PHY1_ESDF (1 << 31) + +#defineAHCI_FSL_REG_PHY_MASK 0xff + +#defineAHCI_FSL_PHY2_CIBGMN_SHIFT 0 +#defineAHCI_FSL_PHY2_CIBGMX_SHIFT 8 +#defineAHCI_FSL_PHY2_CIBGN_SHIFT 16 +#defineAHCI_FSL_PHY2_CINMP_SHIFT 24 + +#defineAHCI_FSL_PHY3_CWBGMN_SHIFT 0 +#defineAHCI_FSL_PHY3_CWBGMX_SHIFT
svn commit: r361463 - in head/sys: conf dev/iicbus/rtc modules/i2c modules/i2c/rx8803
Author: mw Date: Mon May 25 15:40:02 2020 New Revision: 361463 URL: https://svnweb.freebsd.org/changeset/base/361463 Log: Introduce support for Epson RX-8803 RTC. This patch introduces support for Epson RX-8803 RTC controller accessible over I2C bus. It has a resolution of 1 sec. Support for interrupt based alarm was not implemented. Submitted by: Kornel Duleba Reviewed by: manu Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24364 Added: head/sys/dev/iicbus/rtc/ head/sys/dev/iicbus/rtc/rx8803.c (contents, props changed) head/sys/modules/i2c/rx8803/ head/sys/modules/i2c/rx8803/Makefile (contents, props changed) Modified: head/sys/conf/files head/sys/modules/i2c/Makefile Modified: head/sys/conf/files == --- head/sys/conf/files Mon May 25 15:31:43 2020(r361462) +++ head/sys/conf/files Mon May 25 15:40:02 2020(r361463) @@ -1804,6 +1804,7 @@ dev/iicbus/mux/ltc430x.c optional ltc430x dev/iicbus/nxprtc.coptional nxprtc | pcf8563 dev/iicbus/ofw_iicbus.coptional fdt iicbus dev/iicbus/rtc8583.c optional rtc8583 +dev/iicbus/rtc/rx8803.coptional rx8803 iicbus fdt dev/iicbus/s35390a.c optional s35390a dev/iicbus/sy8106a.c optional sy8106a ext_resources fdt dev/iicbus/gpio/tca6416.c optional tca6416 fdt Added: head/sys/dev/iicbus/rtc/rx8803.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/iicbus/rtc/rx8803.cMon May 25 15:40:02 2020 (r361463) @@ -0,0 +1,246 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "clock_if.h" +#include "iicbus_if.h" + +#defineBIT(x) (1 << (x)) + +#define RX8803_TIME0x0 +#define RX8803_FLAGS 0xE +#define RX8803_CTRL0xF + +#define RX8803_FLAGS_V1F BIT(0) +#define RX8803_FLAGS_V2F BIT(1) + +#define RX8803_CTRL_DISABLEBIT(0) + +#define HALF_OF_SEC_NS 5 +#define MAX_WRITE_LEN 16 + +struct rx8803_time { + uint8_t sec; + uint8_t min; + uint8_t hour; + uint8_t dow; + uint8_t day; + uint8_t mon; + uint8_t year; +}; + +static int rx8803_probe(device_t dev); +static int rx8803_attach(device_t dev); +static int rx8803_detach(device_t dev); + +static int rx8803_gettime(device_t dev, struct timespec *ts); +static int rx8803_settime(device_t dev, struct timespec *ts); + +static int rx8803_check_status(device_t dev); + +static int +rx8803_check_status(device_t dev) +{ + uint8_t flags; + int rc; + + rc = iicdev_readfrom(dev, RX8803_FLAGS, &flags, 1, IIC_WAIT); + if (rc != 0) + return (rc); + + if (flags & RX8803_FLAGS_V2F) { + device_printf(dev, "Low voltage flag set, date is incorrect\n"); + return (ENXIO); + } + + return (0); +} + +static int +rx8803_gettime(device_t dev, struct timespec *ts) +{ + struct rx8803_time data; + struct bcd_clocktime bcd; + int rc; + + rc = rx8803_check_status(dev); + if (rc != 0) + return (rc); + + rc = iicdev_readfrom(dev, + RX8803_TIME, + &data, sizeof(struct rx8803_time), +
svn commit: r361462 - in head/sys: conf dev/iicbus/gpio modules/i2c modules/i2c/tca6416
Author: mw Date: Mon May 25 15:31:43 2020 New Revision: 361462 URL: https://svnweb.freebsd.org/changeset/base/361462 Log: Add TCA6416 GPIO expander support. Add basic TCA6416 GPIO expander support over I2C bus. The driver handles enabling and disabling pins, setting pin mode to IN and OUT and toggling the pins. External interrupts are not supported. Submitted by: Dawid Gorecki Reviewed by: manu, mmel Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24363 Added: head/sys/dev/iicbus/gpio/ head/sys/dev/iicbus/gpio/tca6416.c (contents, props changed) head/sys/modules/i2c/tca6416/ head/sys/modules/i2c/tca6416/Makefile (contents, props changed) Modified: head/sys/conf/files head/sys/modules/i2c/Makefile Modified: head/sys/conf/files == --- head/sys/conf/files Mon May 25 15:21:38 2020(r361461) +++ head/sys/conf/files Mon May 25 15:31:43 2020(r361462) @@ -1806,6 +1806,7 @@ dev/iicbus/ofw_iicbus.c optional fdt iicbus dev/iicbus/rtc8583.c optional rtc8583 dev/iicbus/s35390a.c optional s35390a dev/iicbus/sy8106a.c optional sy8106a ext_resources fdt +dev/iicbus/gpio/tca6416.c optional tca6416 fdt dev/iir/iir.c optional iir dev/iir/iir_ctrl.c optional iir dev/iir/iir_pci.c optional iir pci Added: head/sys/dev/iicbus/gpio/tca6416.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/iicbus/gpio/tca6416.c Mon May 25 15:31:43 2020 (r361462) @@ -0,0 +1,534 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Driver for TI TCA6416 I2C GPIO expander module. + * + * This driver only supports basic functionality + * (interrupt handling and polarity inversion were omitted). + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +#include "gpio_if.h" + +/* Base addresses of registers. LSB omitted. */ +#defineIN_PORT_REG 0x00 +#defineOUT_PORT_REG0x02 +#definePOLARITY_INV_REG0x04 +#defineCONF_REG0x06 + +#defineNUM_PINS16 +#definePINS_PER_REG8 +#definePIN_CAPS\ + (GPIO_PIN_OUTPUT | GPIO_PIN_INPUT \ + | GPIO_PIN_PUSHPULL | GPIO_PIN_INVIN) + +#ifdef DEBUG +#definedbg_dev_printf(dev, fmt, args...) \ + device_printf(dev, fmt, ##args) +#else +#definedbg_dev_printf(dev, fmt, args...) +#endif + +#defineTCA6416_BIT_FROM_PIN(pin) (pin % PINS_PER_REG) +#defineTCA6416_REG_ADDR(pin, baseaddr) (baseaddr | (pin / PINS_PER_REG)) + +struct tca6416_softc { + device_tdev; + device_tbusdev; + struct mtx mtx; + uint32_taddr; +}; + +static int tca6416_read(device_t, uint8_t, uint8_t*); +static int tca6416_write(device_t, uint8_t, uint8_t); +static int tca6416_probe(device_t); +static int tca6416_attach(device_t); +static int tca6416_detach(device_t); +static device_t tca6416_get_bus(device_t); +static int tca6416_pin_max(device_t, int*); +static int tca6416_pin_getcaps(device_t, uint32_t, uint32_t*); +static int tca6416_pin_getflags(device_t, uint32_t, u
svn commit: r361461 - in head/sys: arm/freescale/vybrid arm64/conf conf
Author: mw Date: Mon May 25 15:21:38 2020 New Revision: 361461 URL: https://svnweb.freebsd.org/changeset/base/361461 Log: Introduce VF610 I2C controller support. NXP LS1046A contains I2C controller compatible with Vybrid VF610. Existing Vybrid MVF600 driver can be used to support it. For that purpose declare driver as ofw_iicbus and add methods associated with ofw_iicbus. For VF610 add dynamic clock prescaler calculation using clock information from clock driver and clock frequency requested in device tree. On the occasion add detach function and add additional error handling in i2c_attach function. Submitted by: Dawid Gorecki Reviewed by: manu Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24361 Modified: head/sys/arm/freescale/vybrid/vf_i2c.c head/sys/arm64/conf/GENERIC head/sys/conf/files.arm64 Modified: head/sys/arm/freescale/vybrid/vf_i2c.c == --- head/sys/arm/freescale/vybrid/vf_i2c.c Mon May 25 14:55:37 2020 (r361460) +++ head/sys/arm/freescale/vybrid/vf_i2c.c Mon May 25 15:21:38 2020 (r361461) @@ -57,6 +57,10 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef EXT_RESOURCES +#include +#endif + #include #include #include @@ -93,20 +97,35 @@ __FBSDID("$FreeBSD$"); #define vf_i2c_dbg(_sc, fmt, args...) #endif +#defineHW_UNKNOWN 0x00 +#defineHW_MVF600 0x01 +#defineHW_VF6100x02 + static int i2c_repeated_start(device_t, u_char, int); static int i2c_start(device_t, u_char, int); static int i2c_stop(device_t); static int i2c_reset(device_t, u_char, u_char, u_char *); static int i2c_read(device_t, char *, int, int *, int, int); static int i2c_write(device_t, const char *, int, int *, int); +static phandle_t i2c_get_node(device_t, device_t); +struct i2c_div_type { + uint32_t reg_val; + uint32_t div; +}; + struct i2c_softc { struct resource *res[2]; bus_space_tag_t bst; bus_space_handle_t bsh; +#ifdef EXT_RESOURCES + clk_t clock; + uint32_tfreq; +#endif device_tdev; device_tiicbus; struct mtx mutex; + uintptr_t hwtype; }; static struct resource_spec i2c_spec[] = { @@ -115,6 +134,29 @@ static struct resource_spec i2c_spec[] = { { -1, 0 } }; +#ifdef EXT_RESOURCES +static struct i2c_div_type vf610_div_table[] = { + { 0x00, 20 }, { 0x01, 22 }, { 0x02, 24 }, { 0x03, 26 }, + { 0x04, 28 }, { 0x05, 30 }, { 0x09, 32 }, { 0x06, 34 }, + { 0x0A, 36 }, { 0x0B, 40 }, { 0x0C, 44 }, { 0x0D, 48 }, + { 0x0E, 56 }, { 0x12, 64 }, { 0x13, 72 }, { 0x14, 80 }, + { 0x15, 88 }, { 0x19, 96 }, { 0x16, 104 }, { 0x1A, 112 }, + { 0x17, 128 }, { 0x1D, 160 }, { 0x1E, 192 }, { 0x22, 224 }, + { 0x1F, 240 }, { 0x23, 256 }, { 0x24, 288 }, { 0x25, 320 }, + { 0x26, 384 }, { 0x2A, 448 }, { 0x27, 480 }, { 0x2B, 512 }, + { 0x2C, 576 }, { 0x2D, 640 }, { 0x2E, 768 }, { 0x32, 896 }, + { 0x2F, 960 }, { 0x33, 1024 }, { 0x34, 1152 }, { 0x35, 1280 }, + { 0x36, 1536 }, { 0x3A, 1792 }, { 0x37, 1920 }, { 0x3B, 2048 }, + { 0x3C, 2304 }, { 0x3D, 2560 }, { 0x3E, 3072 }, { 0x3F, 3840 } +}; +#endif + +static const struct ofw_compat_data i2c_compat_data[] = { + {"fsl,mvf600-i2c", HW_MVF600}, + {"fsl,vf610-i2c", HW_VF610}, + {NULL, HW_UNKNOWN} +}; + static int i2c_probe(device_t dev) { @@ -122,7 +164,7 @@ i2c_probe(device_t dev) if (!ofw_bus_status_okay(dev)) return (ENXIO); - if (!ofw_bus_is_compatible(dev, "fsl,mvf600-i2c")) + if (!ofw_bus_search_compatible(dev, i2c_compat_data)->ocd_data) return (ENXIO); device_set_desc(dev, "Vybrid Family Inter-Integrated Circuit (I2C)"); @@ -133,13 +175,35 @@ static int i2c_attach(device_t dev) { struct i2c_softc *sc; +#ifdef EXT_RESOURCES + phandle_t node; +#endif + int error; sc = device_get_softc(dev); sc->dev = dev; + sc->hwtype = ofw_bus_search_compatible(dev, i2c_compat_data)->ocd_data; +#ifdef EXT_RESOURCES + node = ofw_bus_get_node(dev); + error = clk_get_by_ofw_index(dev, node, 0, &sc->clock); + if (error != 0) { + sc->freq = 0; + device_printf(dev, "Parent clock not found.\n"); + } else { + if (OF_hasprop(node, "clock-frequency")) + OF_getencprop(node, "clock-frequency", &sc->freq, + sizeof(sc->freq)); + else + sc->freq = 10; + } +#endif + mtx_init(&sc->mutex, device_get_nameunit(dev), "I2C", MTX_DEF); - if (bus_alloc_resources(dev, i2c_spec, s
svn commit: r361460 - in head/sys: arm64/conf arm64/qoriq conf
Author: mw Date: Mon May 25 14:55:37 2020 New Revision: 361460 URL: https://svnweb.freebsd.org/changeset/base/361460 Log: Add GPIO support for QorIQ boards. This patch adds a GPIO controller support targeted for NXP LS1046A SoC. The driver implements the following features: * setting direction of each pin (IN or OUT) * setting the mode of output pins (PUSHPULL or OPENDRAIN) * setting the state of each output pin (1 or 0) * reading the state of each input pin (1 or 0) Submitted by: Kamil Koczurek Dawid Gorecki Reviewed by: manu Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24353 Added: head/sys/arm64/qoriq/ls1046_gpio.c (contents, props changed) Modified: head/sys/arm64/conf/GENERIC head/sys/conf/files.arm64 Modified: head/sys/arm64/conf/GENERIC == --- head/sys/arm64/conf/GENERIC Mon May 25 14:45:18 2020(r361459) +++ head/sys/arm64/conf/GENERIC Mon May 25 14:55:37 2020(r361460) @@ -248,6 +248,7 @@ device gpio device gpioled device fdt_pinctrl device gpioregulator +device ls1046_gpio # LS1046A GPIO controller device mv_gpio # Marvell GPIO controller device mvebu_pinctrl # Marvell Pinmux Controller device rk_gpio # RockChip GPIO Controller Added: head/sys/arm64/qoriq/ls1046_gpio.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm64/qoriq/ls1046_gpio.c Mon May 25 14:55:37 2020 (r361460) @@ -0,0 +1,586 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "gpio_if.h" + +/* constants */ +enum { + DIRECTION = 0x0, + OPEN_DRAIN = 0x4, + DATA = 0x8, + INT_EV = 0xC, + INT_MASK = 0x10, + INT_CTRL = 0x14 +}; + +#definePIN_COUNT 32 +#defineDEFAULT_CAPS\ + (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ + GPIO_PIN_OPENDRAIN | GPIO_PIN_PUSHPULL) +#defineGPIO(n) (1 << (31 - (n))) + +struct gpio_res { + int mem_rid; + struct resource *mem_res; +}; + +/* software context */ +struct gpio_softc { + device_t dev; + device_t busdev; + struct gpio_resres; + struct gpio_pinsetup[PIN_COUNT]; + struct mtx mutex; +}; + +#defineQORIQ_GPIO_LOCK(_sc) mtx_lock_spin(&(_sc)->mutex) +#defineQORIQ_GPIO_UNLOCK(_sc)mtx_unlock_spin(&(_sc)->mutex) +#defineQORIQ_GPIO_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mutex, MA_OWNED) + +/* prototypes */ +/* helpers */ +static int qoriq_make_gpio_res(device_t, struct gpio_res*); +static uint32_t qoriq_gpio_reg_read(device_t, uint32_t); +static void qoriq_gpio_reg_write(device_t, uint32_t, uint32_t); +static void qoriq_gpio_reg_set(device_t, uint32_t, uint32_t); +static void qoriq_gpio_reg_clear(device_t, uint32_t, uint32_t); +static void qoriq_gpio_out_en(device_t, uint32_t, uint8_t); +static void qoriq_gpio_value_set(device_t, uint32_t, uint8_t); +static uint32_t qoriq_gpio_value_get(device_t, uint32_t); +static void qoriq_gpio_open_drain_set(device_t, uint32_t, uint8_t); +static int qoriq_gpio_configure(device_t, uint32_t, uint32_t
svn commit: r361459 - in head/sys: arm64/conf arm64/qoriq/clk conf
Author: mw Date: Mon May 25 14:45:18 2020 New Revision: 361459 URL: https://svnweb.freebsd.org/changeset/base/361459 Log: Add LS1046A clockgen driver. Driver provides probe and attach functions for LS1046A clockgen and passes configuration information to QorIQ clockgen class. It may be used as a reference implementation for different QorIQ clockgen devices. Submitted by: Dawid Gorecki Reviewed by: mmel, manu Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24352 Added: head/sys/arm64/qoriq/clk/ls1046a_clkgen.c (contents, props changed) Modified: head/sys/arm64/conf/GENERIC head/sys/conf/files.arm64 head/sys/conf/options.arm64 Modified: head/sys/arm64/conf/GENERIC == --- head/sys/arm64/conf/GENERIC Mon May 25 14:31:32 2020(r361458) +++ head/sys/arm64/conf/GENERIC Mon May 25 14:45:18 2020(r361459) @@ -118,6 +118,7 @@ options SOC_INTEL_STRATIX10 optionsSOC_BRCM_BCM2837 optionsSOC_BRCM_BCM2838 optionsSOC_MARVELL_8K +optionsSOC_NXP_LS optionsSOC_ROCKCHIP_RK3328 optionsSOC_ROCKCHIP_RK3399 optionsSOC_XILINX_ZYNQ Added: head/sys/arm64/qoriq/clk/ls1046a_clkgen.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm64/qoriq/clk/ls1046a_clkgen.c Mon May 25 14:45:18 2020 (r361459) @@ -0,0 +1,255 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +#include + +static uint8_t ls1046a_pltfrm_pll_divs[] = { + 2, 4, 0 +}; + +static struct qoriq_clk_pll_def ls1046a_pltfrm_pll = { + .clkdef = { + .name = "ls1046a_platform_pll", + .id = QORIQ_CLK_ID(QORIQ_TYPE_PLATFORM_PLL, 0), + .flags = 0 + }, + .offset = 0xC00, + .shift = 1, + .mask = 0x7E, + .dividers = ls1046a_pltfrm_pll_divs, + .flags = 0 +}; + +static const uint8_t ls1046a_cga1_pll_divs[] = { + 2, 3, 4, 0 +}; + +static struct qoriq_clk_pll_def ls1046a_cga1_pll = { + .clkdef = { + .name = "ls1046a_cga_pll1", + .id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 0), + .flags = 0 + }, + .offset = 0x800, + .shift = 1, + .mask = 0x1FE, + .dividers = ls1046a_cga1_pll_divs, + .flags = QORIQ_CLK_PLL_HAS_KILL_BIT +}; + +static struct qoriq_clk_pll_def ls1046a_cga2_pll = { + .clkdef = { + .name = "ls1046a_cga_pll2", + .id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 20), + .flags = 0 + }, + .offset = 0x820, + .shift = 1, + .mask = 0x1FE, + .dividers = ls1046a_cga1_pll_divs, + .flags = QORIQ_CLK_PLL_HAS_KILL_BIT +}; + +static struct qoriq_clk_pll_def *ls1046a_cga_plls[] = { + &ls1046a_cga1_pll, + &ls1046a_cga2_pll +}; + +static const char *ls1046a_cmux0_parent_names[] = { + "ls1046a_cga_pll1", + NULL, + "ls1046a_cga_pll1_div2", + NULL, + "ls1046a_cga_pll2", + NULL, + "ls1046a_cga_pll2_div2" +}; + +static struct clk_mux_def ls1046a_cmux0 = { + .clkdef = { + .name = "ls1046a_cmux0", + .id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 0), + .parent_names
svn commit: r361458 - in head/sys/arm64/qoriq: . clk
Author: mw Date: Mon May 25 14:31:32 2020 New Revision: 361458 URL: https://svnweb.freebsd.org/changeset/base/361458 Log: Add QorIQ platform clockgen driver. This patch adds classes and functions that can be used with various NXP QorIQ Layerscape SoCs. As for the clock topology - there is single platform PLL, which supplies clocks for the peripheral bus and additional PLLs for CPU cores. There can be multiple core PLLs (For example - LS1046A has two PLLs - CGAPLL1 and CGAPLL2). Each PLL has fixed dividers on output. The core PLLs are not accessible from dts. This is a preparation patch for NXP LS1046A SoC support. Submitted by: Dawid Gorecki Reviewed by: mmel Obtained from: Semihalf Sponsored by: Alstom Group Differential Revision: https://reviews.freebsd.org/D24351 Added: head/sys/arm64/qoriq/ head/sys/arm64/qoriq/clk/ head/sys/arm64/qoriq/clk/qoriq_clk_pll.c (contents, props changed) head/sys/arm64/qoriq/clk/qoriq_clk_pll.h (contents, props changed) head/sys/arm64/qoriq/clk/qoriq_clkgen.c (contents, props changed) head/sys/arm64/qoriq/clk/qoriq_clkgen.h (contents, props changed) Added: head/sys/arm64/qoriq/clk/qoriq_clk_pll.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm64/qoriq/clk/qoriq_clk_pll.cMon May 25 14:31:32 2020 (r361458) @@ -0,0 +1,152 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include +#include + +#include + +#include "clkdev_if.h" + +struct qoriq_clk_pll_softc { + bus_addr_t offset; + + uint32_tmask; + uint32_tshift; + + uint32_tflags; +}; + +#defineWR4(_clk, offset, val) \ + CLKDEV_WRITE_4(clknode_get_device(_clk), offset, val) +#defineRD4(_clk, offset, val) \ + CLKDEV_READ_4(clknode_get_device(_clk), offset, val) +#defineDEVICE_LOCK(_clk) \ + CLKDEV_DEVICE_LOCK(clknode_get_device(_clk)) +#defineDEVICE_UNLOCK(_clk) \ + CLKDEV_DEVICE_UNLOCK(clknode_get_device(_clk)) + +#defineQORIQ_PLL_KILL_BIT (1 << 31) + +static int +qoriq_clk_pll_init(struct clknode *clk, device_t dev) +{ + + clknode_init_parent_idx(clk, 0); + + return (0); +} + +static int +qoriq_clk_pll_recalc_freq(struct clknode *clk, uint64_t *freq) +{ + struct qoriq_clk_pll_softc *sc; + uint32_t mul; + + sc = clknode_get_softc(clk); + + RD4(clk, sc->offset, &mul); + + if (sc->flags & QORIQ_CLK_PLL_HAS_KILL_BIT && mul & QORIQ_PLL_KILL_BIT) + return (0); + + mul &= sc->mask; + mul >>= sc->shift; + + *freq = *freq * mul; + + return (0); +} + +static clknode_method_t qoriq_clk_pll_clknode_methods[] = { + CLKNODEMETHOD(clknode_init, qoriq_clk_pll_init), + CLKNODEMETHOD(clknode_recalc_freq, qoriq_clk_pll_recalc_freq), + + CLKNODEMETHOD_END +}; + +DEFINE_CLASS_1(qoriq_clk_pll_clknode, qoriq_clk_pll_clknode_class, +qoriq_clk_pll_clknode_methods, sizeof(struct qoriq_clk_pll_softc), +clknode_class); + +int +qoriq_clk_pll_register(struct clkdom *clkdom, +const struct qoriq_clk_pll_def *clkdef) +{ + char namebuf[QORIQ_CLK_NAME_MAX_LEN]; + struct qoriq_clk_pll_softc *sc; + struct clk_fixed_def def; +
svn commit: r360777 - head/sys/dev/ena
Author: mw Date: Thu May 7 11:28:39 2020 New Revision: 360777 URL: https://svnweb.freebsd.org/changeset/base/360777 Log: Optimize ENA Rx refill for low memory conditions Sometimes, especially when there is not much memory in the system left, allocating mbuf jumbo clusters (like 9KB or 16KB) can take a lot of time and it is not guaranteed that it'll succeed. In that situation, the fallback will work, but if the refill needs to take a place for a lot of descriptors at once, the time spent in m_getjcl looking for memory can cause system unresponsiveness due to high priority of the Rx task. This can also lead to driver reset, because Tx cleanup routine is being blocked and timer service could detect that Tx packets aren't cleaned up. The reset routine can further create another unresponsiveness - Rx rings are being refilled there, so m_getjcl will again burn the CPU. This was causing NVMe driver timeouts and resets, because network driver is having higher priority. Instead of 16KB jumbo clusters for the Rx buffers, 9KB clusters are enough - ENA MTU is being set to 9K anyway, so it's very unlikely that more space than 9KB will be needed. However, 9KB jumbo clusters can still cause issues, so by default the page size mbuf cluster will be used for the Rx descriptors. This can have a small (~2%) impact on the throughput of the device, so to restore original behavior, one must change sysctl "hw.ena.enable_9k_mbufs" to "1" in "/boot/loader.conf" file. As a part of this patch (important fix), the version of the driver was updated to v2.1.2. Submitted by: cperciva Reviewed by:Michal Krawczyk Reviewed by:Ido Segev Reviewed by:Guy Tzalik MFC after: 3 days PR: 225791, 234838, 235856, 236989, 243531 Differential Revision: https://reviews.freebsd.org/D24546 Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c head/sys/dev/ena/ena_sysctl.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 7 10:46:02 2020(r360776) +++ head/sys/dev/ena/ena.c Thu May 7 11:28:39 2020(r360777) @@ -368,6 +368,7 @@ ena_init_io_rings_common(struct ena_adapter *adapter, ring->ena_dev = adapter->ena_dev; ring->first_interrupt = false; ring->no_interrupt_event_cnt = 0; + ring->rx_mbuf_sz = ena_mbuf_sz; } static void @@ -508,9 +509,9 @@ ena_setup_rx_dma_tag(struct ena_adapter *adapter) ENA_DMA_BIT_MASK(adapter->dma_width), /* lowaddr of excl window */ BUS_SPACE_MAXADDR,/* highaddr of excl window */ NULL, NULL, /* filter, filterarg */ - MJUM16BYTES, /* maxsize */ + ena_mbuf_sz, /* maxsize */ adapter->max_rx_sgl_size, /* nsegments */ - MJUM16BYTES, /* maxsegsize */ + ena_mbuf_sz, /* maxsegsize */ 0,/* flags */ NULL, /* lockfunc*/ NULL, /* lockarg */ @@ -963,7 +964,8 @@ ena_alloc_rx_mbuf(struct ena_adapter *adapter, return (0); /* Get mbuf using UMA allocator */ - rx_info->mbuf = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUM16BYTES); + rx_info->mbuf = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, + rx_ring->rx_mbuf_sz); if (unlikely(rx_info->mbuf == NULL)) { counter_u64_add(rx_ring->rx_stats.mjum_alloc_fail, 1); @@ -974,7 +976,7 @@ ena_alloc_rx_mbuf(struct ena_adapter *adapter, } mlen = MCLBYTES; } else { - mlen = MJUM16BYTES; + mlen = rx_ring->rx_mbuf_sz; } /* Set mbuf length*/ rx_info->mbuf->m_pkthdr.len = rx_info->mbuf->m_len = mlen; Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Thu May 7 10:46:02 2020(r360776) +++ head/sys/dev/ena/ena.h Thu May 7 11:28:39 2020(r360777) @@ -41,7 +41,7 @@ #define DRV_MODULE_VER_MAJOR 2 #define DRV_MODULE_VER_MINOR 1 -#define DRV_MODULE_VER_SUBMINOR 1 +#define DRV_MODULE_VER_SUBMINOR 2 #define DRV_MODULE_NAME"ena" @@ -307,8 +307,13 @@ struct ena_ring { /* Determines if device will use LLQ or normal mode for TX */ enum ena_admin_placement_policy_type tx_mem_queue_type; - /* The maximum length the driver can push to the device (For LLQ) */ - uint8_t tx_max_header_size; + union {
svn commit: r359667 - in head/sys: dev/hwpmc sys
Author: mw Date: Mon Apr 6 19:45:26 2020 New Revision: 359667 URL: https://svnweb.freebsd.org/changeset/base/359667 Log: Add hwpmc support for Intel Atom Goldmont microarchitecture Recognize new micro-architecture in hwpmc_intel driver. Based on Intel document 325462-071US. Tested with tools/test/hwpmc/pmctest.py on Atom E3930 SoC. Submitted by: Dawid Gorecki Reviewed by: kib Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D24310 Modified: head/sys/dev/hwpmc/hwpmc_intel.c head/sys/sys/pmc.h Modified: head/sys/dev/hwpmc/hwpmc_intel.c == --- head/sys/dev/hwpmc/hwpmc_intel.cMon Apr 6 18:52:40 2020 (r359666) +++ head/sys/dev/hwpmc/hwpmc_intel.cMon Apr 6 19:45:26 2020 (r359667) @@ -203,6 +203,10 @@ pmc_intel_initialize(void) cputype = PMC_CPU_INTEL_ATOM_SILVERMONT; nclasses = 3; break; + case 0x5C: /* Per Intel document 325462-071US 10/2019. */ + cputype = PMC_CPU_INTEL_ATOM_GOLDMONT; + nclasses = 3; + break; } break; } @@ -230,6 +234,7 @@ pmc_intel_initialize(void) */ case PMC_CPU_INTEL_ATOM: case PMC_CPU_INTEL_ATOM_SILVERMONT: + case PMC_CPU_INTEL_ATOM_GOLDMONT: case PMC_CPU_INTEL_BROADWELL: case PMC_CPU_INTEL_BROADWELL_XEON: case PMC_CPU_INTEL_SKYLAKE_XEON: @@ -293,6 +298,7 @@ pmc_intel_finalize(struct pmc_mdep *md) switch (md->pmd_cputype) { case PMC_CPU_INTEL_ATOM: case PMC_CPU_INTEL_ATOM_SILVERMONT: + case PMC_CPU_INTEL_ATOM_GOLDMONT: case PMC_CPU_INTEL_BROADWELL: case PMC_CPU_INTEL_BROADWELL_XEON: case PMC_CPU_INTEL_SKYLAKE_XEON: Modified: head/sys/sys/pmc.h == --- head/sys/sys/pmc.h Mon Apr 6 18:52:40 2020(r359666) +++ head/sys/sys/pmc.h Mon Apr 6 19:45:26 2020(r359667) @@ -110,6 +110,7 @@ extern char pmc_cpuid[PMC_CPUID_LEN]; __PMC_CPU(INTEL_BROADWELL_XEON, 0x97, "Intel Broadwell Xeon") \ __PMC_CPU(INTEL_SKYLAKE, 0x98, "Intel Skylake") \ __PMC_CPU(INTEL_SKYLAKE_XEON, 0x99, "Intel Skylake Xeon") \ + __PMC_CPU(INTEL_ATOM_GOLDMONT, 0x9A, "Intel Atom Goldmont") \ __PMC_CPU(INTEL_XSCALE, 0x100, "Intel XScale") \ __PMC_CPU(MIPS_24K, 0x200, "MIPS 24K") \ __PMC_CPU(MIPS_OCTEON, 0x201, "Cavium Octeon")\ ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r358289 - head/sys/dev/ena
Author: mw Date: Mon Feb 24 15:35:31 2020 New Revision: 358289 URL: https://svnweb.freebsd.org/changeset/base/358289 Log: Rework and simplify Tx DMA mapping in ENA Driver working in LLQ mode in some cases can send only few last segments of the mbuf using DMA engine, and the rest of them are sent to the device using direct PCI transaction. To map the only necessary data, two DMA maps were used. That solution was very rough and was causing a bug - if both maps were used (head_map and seg_map), there was a race in between two flows on two queues and the device was receiving corrupted data which could be further received on the other host if the Tx cksum offload was enabled. As it's ok to map whole mbuf and then send to the device only needed segments, the design was simplified to use only single DMA map. The driver version was updated to v2.1.1 as it's important bug fix. Submitted by: Michal Krawczyk Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Mon Feb 24 12:35:58 2020(r358288) +++ head/sys/dev/ena/ena.c Mon Feb 24 15:35:31 2020(r358289) @@ -558,15 +558,10 @@ ena_release_all_tx_dmamap(struct ena_ring *tx_ring) } } #endif /* DEV_NETMAP */ - if (tx_info->map_head != NULL) { - bus_dmamap_destroy(tx_tag, tx_info->map_head); - tx_info->map_head = NULL; + if (tx_info->dmamap != NULL) { + bus_dmamap_destroy(tx_tag, tx_info->dmamap); + tx_info->dmamap = NULL; } - - if (tx_info->map_seg != NULL) { - bus_dmamap_destroy(tx_tag, tx_info->map_seg); - tx_info->map_seg = NULL; - } } } @@ -627,25 +622,14 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in /* ... and create the buffer DMA maps */ for (i = 0; i < tx_ring->ring_size; i++) { err = bus_dmamap_create(adapter->tx_buf_tag, 0, - &tx_ring->tx_buffer_info[i].map_head); + &tx_ring->tx_buffer_info[i].dmamap); if (unlikely(err != 0)) { ena_trace(ENA_ALERT, - "Unable to create Tx DMA map_head for buffer %d\n", + "Unable to create Tx DMA map for buffer %d\n", i); goto err_map_release; } - tx_ring->tx_buffer_info[i].seg_mapped = false; - err = bus_dmamap_create(adapter->tx_buf_tag, 0, - &tx_ring->tx_buffer_info[i].map_seg); - if (unlikely(err != 0)) { - ena_trace(ENA_ALERT, - "Unable to create Tx DMA map_seg for buffer %d\n", - i); - goto err_map_release; - } - tx_ring->tx_buffer_info[i].head_mapped = false; - #ifdef DEV_NETMAP if (adapter->ifp->if_capenable & IFCAP_NETMAP) { map = tx_ring->tx_buffer_info[i].nm_info.map_seg; @@ -720,28 +704,13 @@ ena_free_tx_resources(struct ena_adapter *adapter, int /* Free buffer DMA maps, */ for (int i = 0; i < tx_ring->ring_size; i++) { - if (tx_ring->tx_buffer_info[i].head_mapped == true) { - bus_dmamap_sync(adapter->tx_buf_tag, - tx_ring->tx_buffer_info[i].map_head, - BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(adapter->tx_buf_tag, - tx_ring->tx_buffer_info[i].map_head); - tx_ring->tx_buffer_info[i].head_mapped = false; - } + bus_dmamap_sync(adapter->tx_buf_tag, + tx_ring->tx_buffer_info[i].dmamap, BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(adapter->tx_buf_tag, + tx_ring->tx_buffer_info[i].dmamap); bus_dmamap_destroy(adapter->tx_buf_tag, - tx_ring->tx_buffer_info[i].map_head); + tx_ring->tx_buffer_info[i].dmamap); - if (tx_ring->tx_buffer_info[i].seg_mapped == true) { - bus_dmamap_sync(adapter->tx_buf_tag, - tx_ring->tx_buffer_info[i].map_seg, - BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(adapter->tx_buf_tag, - tx_ring->tx_buffer_info[i].map_seg); - tx_ring->tx_buffer_info[i].seg_mapped = false; - } - bus_dmamap_destroy(a
svn commit: r357676 - head/sys/dev/neta
Author: mw Date: Sat Feb 8 13:33:47 2020 New Revision: 357676 URL: https://svnweb.freebsd.org/changeset/base/357676 Log: Implement jumbo frame support in mvneta driver This patch introduces processing of the frames up to 9kB by the mvneta driver. Some versions of this NIC limit TX checksum offloading, depending on the frame size, so add appropriate handling of this feature. Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D23225 Modified: head/sys/dev/neta/if_mvneta.c head/sys/dev/neta/if_mvneta_fdt.c head/sys/dev/neta/if_mvnetavar.h Modified: head/sys/dev/neta/if_mvneta.c == --- head/sys/dev/neta/if_mvneta.c Sat Feb 8 13:25:39 2020 (r357675) +++ head/sys/dev/neta/if_mvneta.c Sat Feb 8 13:33:47 2020 (r357676) @@ -483,9 +483,9 @@ mvneta_dma_create(struct mvneta_softc *sc) BUS_SPACE_MAXADDR_32BIT,/* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ NULL, NULL, /* filtfunc, filtfuncarg */ - MVNETA_PACKET_SIZE, /* maxsize */ + MVNETA_MAX_FRAME, /* maxsize */ MVNETA_TX_SEGLIMIT, /* nsegments */ - MVNETA_PACKET_SIZE, /* maxsegsz */ + MVNETA_MAX_FRAME, /* maxsegsz */ BUS_DMA_ALLOCNOW, /* flags */ NULL, NULL, /* lockfunc, lockfuncarg */ &sc->txmbuf_dtag); @@ -533,8 +533,8 @@ mvneta_dma_create(struct mvneta_softc *sc) BUS_SPACE_MAXADDR_32BIT,/* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ NULL, NULL, /* filtfunc, filtfuncarg */ - MVNETA_PACKET_SIZE, 1, /* maxsize, nsegments */ - MVNETA_PACKET_SIZE, /* maxsegsz */ + MVNETA_MAX_FRAME, 1,/* maxsize, nsegments */ + MVNETA_MAX_FRAME, /* maxsegsz */ 0, /* flags */ NULL, NULL, /* lockfunc, lockfuncarg */ &sc->rxbuf_dtag); /* dmat */ @@ -674,6 +674,8 @@ mvneta_attach(device_t self) ifp->if_hwassist = CSUM_IP | CSUM_TCP | CSUM_UDP; + sc->rx_frame_size = MCLBYTES; /* ether_ifattach() always sets normal mtu */ + /* * Device DMA Buffer allocation. * Handles resource deallocation in case of failure. @@ -1158,7 +1160,7 @@ mvneta_initreg(struct ifnet *ifp) /* Port MAC Control set 0 */ reg = MVNETA_PMACC0_MUSTSET; /* must write 0x1 */ reg &= ~MVNETA_PMACC0_PORTEN; /* port is still disabled */ - reg |= MVNETA_PMACC0_FRAMESIZELIMIT(MVNETA_MAX_FRAME); + reg |= MVNETA_PMACC0_FRAMESIZELIMIT(ifp->if_mtu + MVNETA_ETHER_SIZE); MVNETA_WRITE(sc, MVNETA_PMACC0, reg); /* Port MAC Control set 2 */ @@ -1525,7 +1527,7 @@ mvneta_rx_queue_init(struct ifnet *ifp, int q) MVNETA_WRITE(sc, MVNETA_PRXDQA(q), rx->desc_pa); /* Rx buffer size and descriptor ring size */ - reg = MVNETA_PRXDQS_BUFFERSIZE(MVNETA_PACKET_SIZE >> 3); + reg = MVNETA_PRXDQS_BUFFERSIZE(sc->rx_frame_size >> 3); reg |= MVNETA_PRXDQS_DESCRIPTORSQUEUESIZE(MVNETA_RX_RING_CNT); MVNETA_WRITE(sc, MVNETA_PRXDQS(q), reg); #ifdef MVNETA_KTR @@ -2103,7 +2105,7 @@ mvneta_ioctl(struct ifnet *ifp, u_long cmd, caddr_t da mvneta_sc_unlock(sc); break; case SIOCSIFCAP: - if (ifp->if_mtu > MVNETA_MAX_CSUM_MTU && + if (ifp->if_mtu > sc->tx_csum_limit && ifr->ifr_reqcap & IFCAP_TXCSUM) ifr->ifr_reqcap &= ~IFCAP_TXCSUM; mask = ifp->if_capenable ^ ifr->ifr_reqcap; @@ -2157,7 +2159,12 @@ mvneta_ioctl(struct ifnet *ifp, u_long cmd, caddr_t da } else { ifp->if_mtu = ifr->ifr_mtu; mvneta_sc_lock(sc); - if (ifp->if_mtu > MVNETA_MAX_CSUM_MTU) { + if (ifp->if_mtu + MVNETA_ETHER_SIZE <= MCLBYTES) { + sc->rx_frame_size = MCLBYTES; + } else { + sc->rx_frame_size = MJUM9BYTES; + } + if (ifp->if_mtu > sc->tx_csum_limit) { ifp->if_capenable &= ~IFCAP_TXCSUM; ifp->if_hwassist = 0; } else { @@ -2167,8 +2174,25 @@ mvneta_ioctl(struct ifnet *ifp, u_long cmd, caddr_t da } if (ifp->if_drv_flags & IFF_DRV_RUNNING) { -
svn commit: r357675 - head/sys/dev/neta
Author: mw Date: Sat Feb 8 13:25:39 2020 New Revision: 357675 URL: https://svnweb.freebsd.org/changeset/base/357675 Log: Destroy RX DMA tag on detach in mvneta driver This patch fixes deinitialization sequence of the mvneta driver by adding missing bus_dma_tag_destroy call. Submitted by: Kornel Duleba Obtained from: Semihalf MFC after: 1 week Sponsored by: Stormshield Modified: head/sys/dev/neta/if_mvneta.c Modified: head/sys/dev/neta/if_mvneta.c == --- head/sys/dev/neta/if_mvneta.c Fri Feb 7 22:45:09 2020 (r357674) +++ head/sys/dev/neta/if_mvneta.c Sat Feb 8 13:25:39 2020 (r357675) @@ -874,6 +874,8 @@ mvneta_detach(device_t dev) bus_dma_tag_destroy(sc->rx_dtag); if (sc->txmbuf_dtag != NULL) bus_dma_tag_destroy(sc->txmbuf_dtag); + if (sc->rxbuf_dtag != NULL) + bus_dma_tag_destroy(sc->rxbuf_dtag); bus_release_resources(dev, res_spec, sc->res); return (0); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r354218 - head/sys/dev/ena
Hi John, Sure, will be happy to test. Please let me know and cc m...@semihalf.com. Best regards, Marcin pt., 1 lis 2019 o 01:04 John Baldwin napisał(a): > On 10/31/19 8:38 AM, Marcin Wojtas wrote: > > Author: mw > > Date: Thu Oct 31 15:38:17 2019 > > New Revision: 354218 > > URL: https://svnweb.freebsd.org/changeset/base/354218 > > > > Log: > > Add WC support for arm64 in the ENA driver > > > > As the pmamp_change_attr() is public on arm64 since r351131, it can be > > used on the arm64 to map memory range as with the write combined > > attribute. > > > > It requires the driver to use generic VM_MEMATTR_WRITE_COMBINING flag > > instead of the x86 specific PAT_WRITE_COMBINING. > > > > Differential Revision: https://reviews.freebsd.org/D21931 > > Submitted by: Michal Krawczyk > > Obtained from: Semihalf > > Sponsored by: Amazon, Inc. > > This isn't the right API for this, but the right API isn't ready yet on > arm64. I have a patch to add bus_map_resource support on all platforms > that I'm working on testing, and that will be the right way to request > this in the future once it lands. > > -- > -- > John Baldwin > ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r354225 - head/sys/dev/ena
Author: mw Date: Thu Oct 31 16:03:43 2019 New Revision: 354225 URL: https://svnweb.freebsd.org/changeset/base/354225 Log: Update ENA version to v2.1.0 In this release the netmap support was introduced. Moreover, it is also now possible to use the LLQ mode of the driver on the arm64 AWS instances (A1 type). Differential Revision: https://reviews.freebsd.org/D21938 Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Thu Oct 31 16:02:42 2019(r354224) +++ head/sys/dev/ena/ena.h Thu Oct 31 16:03:43 2019(r354225) @@ -40,7 +40,7 @@ #include "ena-com/ena_eth_com.h" #define DRV_MODULE_VER_MAJOR 2 -#define DRV_MODULE_VER_MINOR 0 +#define DRV_MODULE_VER_MINOR 1 #define DRV_MODULE_VER_SUBMINOR 0 #define DRV_MODULE_NAME"ena" ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r354224 - head/sys/dev/ena
Author: mw Date: Thu Oct 31 16:02:42 2019 New Revision: 354224 URL: https://svnweb.freebsd.org/changeset/base/354224 Log: Add support for ENA NETMAP partial initialization In NETMAP mode not all queues need to be allocated to NETMAP. Some of them could be left to the kernel. Configuration is managed by the flags nr_mode and nr_pending_mode provided per each NETMAP kring. ENA driver checks those flags and perform proper rings initialization. Differential Revision: https://reviews.freebsd.org/D21937 Submitted by: Rafal Kozik Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_netmap.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu Oct 31 15:59:29 2019(r354223) +++ head/sys/dev/ena/ena.c Thu Oct 31 16:02:42 2019(r354224) @@ -1087,7 +1087,7 @@ ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t req_id = rx_ring->free_rx_ids[next_to_use]; rx_info = &rx_ring->rx_buffer_info[req_id]; #ifdef DEV_NETMAP - if (adapter->ifp->if_capenable & IFCAP_NETMAP) + if (ena_rx_ring_in_netmap(adapter, rx_ring->qid)) rc = ena_netmap_alloc_rx_slot(adapter, rx_ring, rx_info); else #endif /* DEV_NETMAP */ Modified: head/sys/dev/ena/ena_netmap.c == --- head/sys/dev/ena/ena_netmap.c Thu Oct 31 15:59:29 2019 (r354223) +++ head/sys/dev/ena/ena_netmap.c Thu Oct 31 16:02:42 2019 (r354224) @@ -206,6 +206,8 @@ ena_netmap_free_rx_slot(struct ena_adapter *adapter, BUS_DMASYNC_POSTREAD); netmap_unload_map(na, adapter->rx_buf_tag, rx_info->map); + KASSERT(kring->ring == NULL, ("Netmap Rx ring is NULL\n")); + slot = &kring->ring->slot[nm_i]; ENA_ASSERT(slot->buf_idx == 0, "Overwrite slot buf\n"); @@ -216,18 +218,54 @@ ena_netmap_free_rx_slot(struct ena_adapter *adapter, kring->nr_hwcur = nm_i; } +static bool +ena_ring_in_netmap(struct ena_adapter *adapter, int qid, enum txrx x) +{ + struct netmap_adapter *na; + struct netmap_kring *kring; + + if (adapter->ifp->if_capenable & IFCAP_NETMAP) { + na = NA(adapter->ifp); + kring = (x == NR_RX) ? na->rx_rings[qid] : na->tx_rings[qid]; + if (kring->nr_mode == NKR_NETMAP_ON) + return true; + } + return false; +} + +bool +ena_tx_ring_in_netmap(struct ena_adapter *adapter, int qid) +{ + return ena_ring_in_netmap(adapter, qid, NR_TX); +} + +bool +ena_rx_ring_in_netmap(struct ena_adapter *adapter, int qid) +{ + return ena_ring_in_netmap(adapter, qid, NR_RX); +} + +static void +ena_netmap_reset_ring(struct ena_adapter *adapter, int qid, enum txrx x) +{ + if (!ena_ring_in_netmap(adapter, qid, x)) + return; + + netmap_reset(NA(adapter->ifp), x, qid, 0); + ena_trace(ENA_NETMAP, "%s ring %d is in netmap mode\n", + (x == NR_TX) ? "Tx" : "Rx", qid); +} + void ena_netmap_reset_rx_ring(struct ena_adapter *adapter, int qid) { - if (adapter->ifp->if_capenable & IFCAP_NETMAP) - netmap_reset(NA(adapter->ifp), NR_RX, qid, 0); + ena_netmap_reset_ring(adapter, qid, NR_RX); } void ena_netmap_reset_tx_ring(struct ena_adapter *adapter, int qid) { - if (adapter->ifp->if_capenable & IFCAP_NETMAP) - netmap_reset(NA(adapter->ifp), NR_TX, qid, 0); + ena_netmap_reset_ring(adapter, qid, NR_TX); } static int @@ -235,7 +273,9 @@ ena_netmap_reg(struct netmap_adapter *na, int onoff) { struct ifnet *ifp = na->ifp; struct ena_adapter* adapter = ifp->if_softc; - int rc; + struct netmap_kring *kring; + enum txrx t; + int rc, i; sx_xlock(&adapter->ioctl_sx); ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); @@ -243,10 +283,26 @@ ena_netmap_reg(struct netmap_adapter *na, int onoff) if (onoff) { ena_trace(ENA_NETMAP, "netmap on\n"); + for_rx_tx(t) { + for (i = 0; i <= nma_get_nrings(na, t); i++) { + kring = NMR(na, t)[i]; + if (nm_kring_pending_on(kring)) { + kring->nr_mode = NKR_NETMAP_ON; + } + } + } nm_set_native_flags(na); } else { ena_trace(ENA_NETMAP, "netmap off\n"); nm_clear_native_flags(na); + for_rx_tx(t) { + for (i = 0; i <= nma_get_nrings(na, t); i++) { + kring = NMR(na, t)[i]; +
svn commit: r354222 - head/sys/dev/ena
Author: mw Date: Thu Oct 31 15:57:44 2019 New Revision: 354222 URL: https://svnweb.freebsd.org/changeset/base/354222 Log: Add support for ENA NETMAP Rx Most of code used for Rx ring initialization could be reused in NETMAP. Reset of NETMAP ring and new alloc method was added. Driver decides if use kernels mbufs or NETMAPs slots based on IFCAP_NETMAP flag. It allows to reuse ena_refill_rx_bufs, which provides proper handling of Rx out of order completion. ena_netmap_alloc_rx_slot takes exactly the same arguments as ena_alloc_rx_mbuf, but instead of allocating one mbuf it takes one slot from NETMAP ring. Based on queue id proper netmap_ring is found. As NETMAP provides the "partial opening" feature not all of the rings are avaiable. Not used points to invalid ring. If there is available slot, it is taken from the ring. Its buffer is mapped to DMA and its index is stored in ena_rx_buffer field in ena_rx_buffer structure. Then ena_buf is filled with addresses and ring state is updated. Cleanup is handled by ena_netmap_free_rx_slot. It unmaps DMA and returns buffer to ring. As we could not return more bufs than we have taken and we should not override occupied slots, buf_index should be 0. It is being checked by assertion. ena_netmap_rxsync callback puts received packets back to NETMAP ring and passes them to user space by updating ring pointers. First it fills ena_netmap_ctx. Then it performs two actions: * ena_netmap_rx_frames moves received frames from NIC to NETMAP ring, * ena_netmap_rx_cleanup fills NIC ring with slots released by userspace app. In case of Rx error that could be handled by NIC driver (for example by performing reset) rx sync should return 0. ena_netmap_rx_frames first checks if NETMAP ring is in consistent state and then in the loop receives new frames. When all available frames are taken nr_hwtail is updated. Receiving one frame is handled by ena_netmap_rx_frame. If no error occurrs, each Descriptor is loaded by ena_netmap_rx_load_desc function. If packets take more than one segments NS_MOREFRAG flag must be set in all, but not last slot. In case of wrong req_id packet is removed from NETMAP ring. If packet is successful received counters are updated. Refiling of NIC ring is performed by ena_netmap_rx_cleanup function. It calculates number of available slots and call ena_refill_rx_bufs with proper number. Differential Revision: https://reviews.freebsd.org/D21935 Submitted by: Rafal Kozik Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_datapath.c head/sys/dev/ena/ena_netmap.c head/sys/dev/ena/ena_netmap.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu Oct 31 15:51:18 2019(r354221) +++ head/sys/dev/ena/ena.c Thu Oct 31 15:57:44 2019(r354222) @@ -764,6 +764,11 @@ ena_setup_rx_resources(struct ena_adapter *adapter, un size = sizeof(struct ena_rx_buffer) * rx_ring->ring_size; +#ifdef DEV_NETMAP + ena_netmap_reset_rx_ring(adapter, qid); + rx_ring->initialized = false; +#endif /* DEV_NETMAP */ + /* * Alloc extra element so in rx path * we can always prefetch rx_info + 1 @@ -1008,8 +1013,12 @@ ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t req_id = rx_ring->free_rx_ids[next_to_use]; rx_info = &rx_ring->rx_buffer_info[req_id]; - - rc = ena_alloc_rx_mbuf(adapter, rx_ring, rx_info); +#ifdef DEV_NETMAP + if (adapter->ifp->if_capenable & IFCAP_NETMAP) + rc = ena_netmap_alloc_rx_slot(adapter, rx_ring, rx_info); + else +#endif /* DEV_NETMAP */ + rc = ena_alloc_rx_mbuf(adapter, rx_ring, rx_info); if (unlikely(rc != 0)) { ena_trace(ENA_WARNING, "failed to alloc buffer for rx queue %d\n", @@ -1054,6 +1063,14 @@ ena_free_rx_bufs(struct ena_adapter *adapter, unsigned if (rx_info->mbuf != NULL) ena_free_rx_mbuf(adapter, rx_ring, rx_info); +#ifdef DEV_NETMAP + if (((if_getflags(adapter->ifp) & IFF_DYING) == 0) && + (adapter->ifp->if_capenable & IFCAP_NETMAP)) { + if (rx_info->netmap_buf_idx != 0) + ena_netmap_free_rx_slot(adapter, rx_ring, + rx_info); + } +#endif /* DEV_NETMAP */ } } @@ -1072,10 +1089,12 @@ ena_refill_all_rx_bufs(struct ena_adapter *adapter) rx_ring = &adapter->rx_ring[i]; bufs_num = rx_ring->ring_size - 1; rc = ena_refill_rx_bufs(rx_ring, bufs_num); -
svn commit: r354221 - in head/sys: contrib/ena-com dev/ena modules/ena
Author: mw Date: Thu Oct 31 15:51:18 2019 New Revision: 354221 URL: https://svnweb.freebsd.org/changeset/base/354221 Log: Introduce NETMAP support in ENA Mock implementation of NETMAP routines is located in ena_netmap.c/.h files. All code is protected under the DEV_NETMAP macro. Makefile was updated with files and flag. As ENA driver provide own implementations of (un)likely it must be undefined before including NETMAP headers. ena_netmap_attach function is called on the end of NIC attach. It fills structure with NIC configuration and callbacks. Then provides it to netmap_attach. Similarly netmap_detach is called during ena_detach. Three callbacks are used. nm_register is implemented by ena_netmap_reg. It is called when user space application open or close NIC in NETMAP mode. Current action is recognized based on onoff parameter: true means on and false off. As NICs rings need to be reconfigured ena_down and ena_up are reused. When user space application wants to receive new packets from NIC nm_rxsync is called, and when there are new packets ready for Tx nm_txsync is called. Differential Revision: https://reviews.freebsd.org/D21934 Submitted by: Rafal Kozik Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Added: head/sys/dev/ena/ena_netmap.c (contents, props changed) head/sys/dev/ena/ena_netmap.h (contents, props changed) Modified: head/sys/contrib/ena-com/ena_plat.h head/sys/dev/ena/ena.c head/sys/modules/ena/Makefile Modified: head/sys/contrib/ena-com/ena_plat.h == --- head/sys/contrib/ena-com/ena_plat.h Thu Oct 31 15:44:26 2019 (r354220) +++ head/sys/contrib/ena-com/ena_plat.h Thu Oct 31 15:51:18 2019 (r354221) @@ -103,6 +103,7 @@ extern struct ena_bus_space ebs; #define ENA_RSC(1 << 6) /* Goes with TXPTH or RXPTH, free/alloc res. */ #define ENA_IOQ(1 << 7) /* Detailed info about IO queues.*/ #define ENA_ADMQ (1 << 8) /* Detailed info about admin queue. */ +#define ENA_NETMAP (1 << 9) /* Detailed info about netmap. */ extern int ena_log_level; Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu Oct 31 15:44:26 2019(r354220) +++ head/sys/dev/ena/ena.c Thu Oct 31 15:51:18 2019(r354221) @@ -80,6 +80,10 @@ __FBSDID("$FreeBSD$"); #include "ena.h" #include "ena_sysctl.h" +#ifdef DEV_NETMAP +#include "ena_netmap.h" +#endif /* DEV_NETMAP */ + /* * Function prototypes */ @@ -3317,12 +3321,24 @@ ena_attach(device_t pdev) sizeof(struct ena_hw_stats)); ena_sysctl_add_nodes(adapter); +#ifdef DEV_NETMAP + rc = ena_netmap_attach(adapter); + if (rc != 0) { + device_printf(pdev, "netmap attach failed: %d\n", rc); + goto err_detach; + } +#endif /* DEV_NETMAP */ + /* Tell the stack that the interface is not active */ if_setdrvflagbits(adapter->ifp, IFF_DRV_OACTIVE, IFF_DRV_RUNNING); ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter); return (0); +#ifdef DEV_NETMAP +err_detach: + ether_ifdetach(adapter->ifp); +#endif /* DEV_NETMAP */ err_msix_free: ena_com_dev_reset(adapter->ena_dev, ENA_REGS_RESET_INIT_ERR); ena_free_mgmnt_irq(adapter); @@ -3378,6 +3394,10 @@ ena_detach(device_t pdev) ena_destroy_device(adapter, true); sx_unlock(&adapter->ioctl_sx); +#ifdef DEV_NETMAP + netmap_detach(adapter->ifp); +#endif /* DEV_NETMAP */ + ena_free_all_io_rings_resources(adapter); ena_free_counters((counter_u64_t *)&adapter->hw_stats, @@ -3518,5 +3538,8 @@ MODULE_PNP_INFO("U16:vendor;U16:device", pci, ena, ena nitems(ena_vendor_info_array) - 1); MODULE_DEPEND(ena, pci, 1, 1, 1); MODULE_DEPEND(ena, ether, 1, 1, 1); +#ifdef DEV_NETMAP +MODULE_DEPEND(ena, netmap, 1, 1, 1); +#endif /* DEV_NETMAP */ /*/ Added: head/sys/dev/ena/ena_netmap.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/ena/ena_netmap.c Thu Oct 31 15:51:18 2019 (r354221) @@ -0,0 +1,111 @@ +/*- + * BSD LICENSE + * + * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer.
svn commit: r354220 - in head/sys: dev/ena modules/ena
Author: mw Date: Thu Oct 31 15:44:26 2019 New Revision: 354220 URL: https://svnweb.freebsd.org/changeset/base/354220 Log: Split Rx/Tx from initialization code in ENA driver Move Rx/Tx routines to separate file. Some functions: * ena_restore_device, * ena_destroy_device, * ena_up, * ena_down, * ena_refill_rx_bufs could be reused in upcoming netmap code in the driver. To make it possible, they were moved to ena.h header. Differential Revision: https://reviews.freebsd.org/D21933 Submitted by: Rafal Kozik Obtained from: Semihalf Sponsored by: Amazon, Inc. Added: head/sys/dev/ena/ena_datapath.c (contents, props changed) head/sys/dev/ena/ena_datapath.h (contents, props changed) Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/modules/ena/Makefile Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu Oct 31 15:39:54 2019(r354219) +++ head/sys/dev/ena/ena.c Thu Oct 31 15:44:26 2019(r354220) @@ -76,6 +76,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include "ena_datapath.h" #include "ena.h" #include "ena_sysctl.h" @@ -102,7 +103,6 @@ static int ena_setup_tx_resources(struct ena_adapter * static voidena_free_tx_resources(struct ena_adapter *, int); static int ena_setup_all_tx_resources(struct ena_adapter *); static voidena_free_all_tx_resources(struct ena_adapter *); -static inline int validate_rx_req_id(struct ena_ring *, uint16_t); static int ena_setup_rx_resources(struct ena_adapter *, unsigned int); static voidena_free_rx_resources(struct ena_adapter *, unsigned int); static int ena_setup_all_rx_resources(struct ena_adapter *); @@ -111,7 +111,6 @@ static inline int ena_alloc_rx_mbuf(struct ena_adapter struct ena_rx_buffer *); static voidena_free_rx_mbuf(struct ena_adapter *, struct ena_ring *, struct ena_rx_buffer *); -static int ena_refill_rx_bufs(struct ena_ring *, uint32_t); static voidena_free_rx_bufs(struct ena_adapter *, unsigned int); static voidena_refill_all_rx_bufs(struct ena_adapter *); static voidena_free_all_rx_bufs(struct ena_adapter *); @@ -121,16 +120,6 @@ static voidena_destroy_all_tx_queues(struct ena_adapt static voidena_destroy_all_rx_queues(struct ena_adapter *); static voidena_destroy_all_io_queues(struct ena_adapter *); static int ena_create_io_queues(struct ena_adapter *); -static int ena_tx_cleanup(struct ena_ring *); -static int ena_rx_cleanup(struct ena_ring *); -static inline int validate_tx_req_id(struct ena_ring *, uint16_t); -static voidena_rx_hash_mbuf(struct ena_ring *, struct ena_com_rx_ctx *, -struct mbuf *); -static struct mbuf* ena_rx_mbuf(struct ena_ring *, struct ena_com_rx_buf_info *, -struct ena_com_rx_ctx *, uint16_t *); -static inline void ena_rx_checksum(struct ena_ring *, struct ena_com_rx_ctx *, -struct mbuf *); -static voidena_cleanup(void *arg, int pending); static int ena_handle_msix(void *); static int ena_enable_msix(struct ena_adapter *); static voidena_setup_mgmnt_intr(struct ena_adapter *); @@ -144,8 +133,6 @@ static void ena_disable_msix(struct ena_adapter *); static voidena_unmask_all_io_irqs(struct ena_adapter *); static int ena_rss_configure(struct ena_adapter *); static int ena_up_complete(struct ena_adapter *); -static int ena_up(struct ena_adapter *); -static voidena_down(struct ena_adapter *); static uint64_tena_get_counter(if_t, ift_counter); static int ena_media_change(if_t); static voidena_media_status(if_t, struct ifmediareq *); @@ -156,15 +143,6 @@ static voidena_update_host_info(struct ena_admin_host static voidena_update_hwassist(struct ena_adapter *); static int ena_setup_ifnet(device_t, struct ena_adapter *, struct ena_com_dev_get_features_ctx *); -static voidena_tx_csum(struct ena_com_tx_ctx *, struct mbuf *); -static int ena_check_and_collapse_mbuf(struct ena_ring *tx_ring, -struct mbuf **mbuf); -static voidena_dmamap_llq(void *, bus_dma_segment_t *, int, int); -static int ena_xmit_mbuf(struct ena_ring *, struct mbuf **); -static voidena_start_xmit(struct ena_ring *); -static int ena_mq_start(if_t, struct mbuf *); -static voidena_deferred_mq_start(void *, int); -static voidena_qflush(if_t); static int ena_enable_wc(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 *); @@ -766,25 +744,6 @@ ena_free_all_tx_resources(struct ena_adapter *adapter) ena_free_tx_resources(adapter, i); } -static inline int -validate_rx_req_id(struct ena_ring *rx_ring, uint16_t req_id) -{ - if (likely(req_id < rx_ring->ring_size)) - return (0); - - device_printf(rx_ring->ada
svn commit: r354219 - head/sys/dev/ena
Author: mw Date: Thu Oct 31 15:39:54 2019 New Revision: 354219 URL: https://svnweb.freebsd.org/changeset/base/354219 Log: Fix ENA keep-alive timeout due to prolonged reset When the ENA_FLAG_DEVICE_RUNNING flag is disabled, the AENQ handlers aren't executed. To fix that, the watchdog timestamp should be updated just before enabling the watchdog. Timer service was always being enabled, even if the device wasn't up before the reset. That shouldn't happen, as the timer service is being executed only for working interface. Differential Revision: https://reviews.freebsd.org/D21932 Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu Oct 31 15:38:17 2019(r354218) +++ head/sys/dev/ena/ena.c Thu Oct 31 15:39:54 2019(r354219) @@ -2350,8 +2350,14 @@ ena_up(struct ena_adapter *adapter) if_setdrvflagbits(adapter->ifp, IFF_DRV_RUNNING, IFF_DRV_OACTIVE); - callout_reset_sbt(&adapter->timer_service, SBT_1S, SBT_1S, - ena_timer_service, (void *)adapter, 0); + /* Activate timer service only if the device is running. +* If this flag is not set, it means that the driver is being +* reset and timer service will be activated afterwards. +*/ + if (ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter)) { + callout_reset_sbt(&adapter->timer_service, SBT_1S, + SBT_1S, ena_timer_service, (void *)adapter, 0); + } ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP, adapter); @@ -4222,9 +4228,20 @@ ena_restore_device(struct ena_adapter *adapter) } } + /* Indicate that device is running again and ready to work */ ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter); - callout_reset_sbt(&adapter->timer_service, SBT_1S, SBT_1S, - ena_timer_service, (void *)adapter, 0); + + if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter)) { + /* +* As the AENQ handlers weren't executed during reset because +* the flag ENA_FLAG_DEVICE_RUNNING was turned off, the +* timestamp must be updated again That will prevent next reset +* caused by missing keep alive. +*/ + adapter->keep_alive_timestamp = getsbinuptime(); + callout_reset_sbt(&adapter->timer_service, SBT_1S, SBT_1S, + ena_timer_service, (void *)adapter, 0); + } device_printf(dev, "Device reset completed successfully, Driver info: %s\n", ena_version); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r354218 - head/sys/dev/ena
Author: mw Date: Thu Oct 31 15:38:17 2019 New Revision: 354218 URL: https://svnweb.freebsd.org/changeset/base/354218 Log: Add WC support for arm64 in the ENA driver As the pmamp_change_attr() is public on arm64 since r351131, it can be used on the arm64 to map memory range as with the write combined attribute. It requires the driver to use generic VM_MEMATTR_WRITE_COMBINING flag instead of the x86 specific PAT_WRITE_COMBINING. Differential Revision: https://reviews.freebsd.org/D21931 Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu Oct 31 15:16:10 2019(r354217) +++ head/sys/dev/ena/ena.c Thu Oct 31 15:38:17 2019(r354218) @@ -3309,7 +3309,7 @@ ena_calc_io_queue_num(struct ena_adapter *adapter, static int ena_enable_wc(struct resource *res) { -#if defined(__i386) || defined(__amd64) +#if defined(__i386) || defined(__amd64) || defined(__aarch64__) vm_offset_t va; vm_size_t len; int rc; @@ -3317,7 +3317,7 @@ ena_enable_wc(struct resource *res) va = (vm_offset_t)rman_get_virtual(res); len = rman_get_size(res); /* Enable write combining */ - rc = pmap_change_attr(va, len, PAT_WRITE_COMBINING); + rc = pmap_change_attr(va, len, VM_MEMATTR_WRITE_COMBINING); if (unlikely(rc != 0)) { ena_trace(ENA_ALERT, "pmap_change_attr failed, %d\n", rc); return (rc); @@ -4352,14 +4352,6 @@ ena_attach(device_t pdev) set_default_llq_configurations(&llq_config); -#if defined(__arm__) || defined(__aarch64__) - /* -* Force LLQ disable, as the driver is not supporting WC enablement -* on the ARM architecture. Using LLQ without WC would affect -* performance in a negative way. -*/ - ena_dev->supported_features &= ~(1 << ENA_ADMIN_LLQ); -#endif rc = ena_set_queues_placement_policy(pdev, ena_dev, &get_feat_ctx.llq, &llq_config); if (unlikely(rc != 0)) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r354217 - head/sys/arm64/arm64
Author: mw Date: Thu Oct 31 15:16:10 2019 New Revision: 354217 URL: https://svnweb.freebsd.org/changeset/base/354217 Log: Fix pmap_change_attr() on arm64 to allow KV addresses Altough in the comment above the pmap_change_attr() it was mentioned that VA could be in KV or DMAP memory space. However, pmap_change_attr_locked() was accepting only the values inside the DMAP memory range. To fix that, the condition check was changed so also the va inside the KV memory range would be accepted. The sample use case that wasn't supported is the PCI Device that has the BAR which should me mapped with the Write Combine attribute - for example BAR2 of the ENA network controller on the A1 instances on AWS. Tested on A1 AWS instance and changed ENA BAR2 mapped resource to be write-combined memory region. Differential Revision: https://reviews.freebsd.org/D22055 MFC after: 2 weeks Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/arm64/arm64/pmap.c Modified: head/sys/arm64/arm64/pmap.c == --- head/sys/arm64/arm64/pmap.c Thu Oct 31 14:49:30 2019(r354216) +++ head/sys/arm64/arm64/pmap.c Thu Oct 31 15:16:10 2019(r354217) @@ -5291,7 +5291,8 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size offset = va & PAGE_MASK; size = round_page(offset + size); - if (!VIRT_IN_DMAP(base)) + if (!VIRT_IN_DMAP(base) && + !(base >= VM_MIN_KERNEL_ADDRESS && base < VM_MAX_KERNEL_ADDRESS)) return (EINVAL); for (tmpva = base; tmpva < base + size; ) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r346259 - head/sys/dev/tpm
Author: mw Date: Tue Apr 16 02:28:35 2019 New Revision: 346259 URL: https://svnweb.freebsd.org/changeset/base/346259 Log: tpm: Prevent session hijack Check caller thread id before allowing to read the buffer to make sure that it can only be accessed by the thread that did the associated write to the TPM. Submitted by: Kornel Duleba Reviewed by: delphij Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D19713 Modified: head/sys/dev/tpm/tpm20.c head/sys/dev/tpm/tpm20.h Modified: head/sys/dev/tpm/tpm20.c == --- head/sys/dev/tpm/tpm20.cTue Apr 16 02:12:38 2019(r346258) +++ head/sys/dev/tpm/tpm20.cTue Apr 16 02:28:35 2019(r346259) @@ -77,6 +77,10 @@ tpm20_read(struct cdev *dev, struct uio *uio, int flag callout_stop(&sc->discard_buffer_callout); sx_xlock(&sc->dev_lock); + if (sc->owner_tid != uio->uio_td->td_tid) { + sx_xunlock(&sc->dev_lock); + return (EPERM); + } bytes_to_transfer = MIN(sc->pending_data_length, uio->uio_resid); if (bytes_to_transfer > 0) { @@ -128,9 +132,11 @@ tpm20_write(struct cdev *dev, struct uio *uio, int fla result = sc->transmit(sc, byte_count); - if (result == 0) + if (result == 0) { callout_reset(&sc->discard_buffer_callout, TPM_READ_TIMEOUT / tick, tpm20_discard_buffer, sc); + sc->owner_tid = uio->uio_td->td_tid; + } sx_xunlock(&sc->dev_lock); return (result); Modified: head/sys/dev/tpm/tpm20.h == --- head/sys/dev/tpm/tpm20.hTue Apr 16 02:12:38 2019(r346258) +++ head/sys/dev/tpm/tpm20.hTue Apr 16 02:28:35 2019(r346259) @@ -120,6 +120,7 @@ struct tpm_sc { uint8_t *buf; size_t pending_data_length; + lwpid_t owner_tid; struct callout discard_buffer_callout; #ifdef TPM_HARVEST ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r346261 - head/sys/dev/tpm
Author: mw Date: Tue Apr 16 02:46:21 2019 New Revision: 346261 URL: https://svnweb.freebsd.org/changeset/base/346261 Log: Improve tpm20 style No functional changes to the code are applied. Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Modified: head/sys/dev/tpm/tpm20.c head/sys/dev/tpm/tpm20.h head/sys/dev/tpm/tpm_crb.c head/sys/dev/tpm/tpm_tis.c Modified: head/sys/dev/tpm/tpm20.c == --- head/sys/dev/tpm/tpm20.cTue Apr 16 02:38:39 2019(r346260) +++ head/sys/dev/tpm/tpm20.cTue Apr 16 02:46:21 2019(r346261) @@ -142,7 +142,8 @@ tpm20_write(struct cdev *dev, struct uio *uio, int fla return (result); } -static void tpm20_discard_buffer(void *arg) +static void +tpm20_discard_buffer(void *arg) { struct tpm_sc *sc; @@ -304,9 +305,10 @@ tpm20_save_state(device_t dev, bool suspend) { struct tpm_sc *sc; uint8_t save_cmd[] = { - 0x80, 0x01, /* TPM_ST_NO_SESSIONS tag*/ + 0x80, 0x01, /* TPM_ST_NO_SESSIONS tag*/ 0x00, 0x00, 0x00, 0x0C, /* cmd length */ - 0x00, 0x00, 0x01, 0x45, 0x00, 0x00 /* cmd TPM_CC_Shutdown */ + 0x00, 0x00, 0x01, 0x45, /* cmd TPM_CC_Shutdown */ + 0x00, 0x00 /* TPM_SU_STATE */ }; sc = device_get_softc(dev); @@ -315,7 +317,7 @@ tpm20_save_state(device_t dev, bool suspend) * Inform the TPM whether we are going to suspend or reboot/shutdown. */ if (suspend) - save_cmd[11] = 1; /* TPM_SU_STATE */ + save_cmd[11] = 1; /* TPM_SU_STATE */ if (sc == NULL || sc->buf == NULL) return (0); Modified: head/sys/dev/tpm/tpm20.h == --- head/sys/dev/tpm/tpm20.hTue Apr 16 02:38:39 2019(r346260) +++ head/sys/dev/tpm/tpm20.hTue Apr 16 02:46:21 2019(r346261) @@ -26,7 +26,7 @@ */ #ifndef _TPM20_H_ -#define _TPM20_H_ +#define_TPM20_H_ #include __FBSDID("$FreeBSD$"); @@ -60,46 +60,46 @@ __FBSDID("$FreeBSD$"); #defineBIT(x) (1 << (x)) /* Timeouts in us */ -#defineTPM_TIMEOUT_A 75 -#defineTPM_TIMEOUT_B 200 -#defineTPM_TIMEOUT_C 20 -#defineTPM_TIMEOUT_D 3 +#defineTPM_TIMEOUT_A 75 +#defineTPM_TIMEOUT_B 200 +#defineTPM_TIMEOUT_C 20 +#defineTPM_TIMEOUT_D 3 /* * Generating RSA key pair takes ~(10-20s), which is significantly longer than * any timeout defined in spec. Because of that we need a new one. */ -#defineTPM_TIMEOUT_LONG4000 +#defineTPM_TIMEOUT_LONG4000 /* List of commands that require TPM_TIMEOUT_LONG time to complete */ -#defineTPM_CC_CreatePrimary0x0131 +#defineTPM_CC_CreatePrimary0x0131 #defineTPM_CC_Create 0x0153 #defineTPM_CC_CreateLoaded 0x0191 /* List of commands that require only TPM_TIMEOUT_C time to complete */ -#define TPM_CC_SequenceComplete0x013e -#define TPM_CC_Startup 0x0144 -#define TPM_CC_SequenceUpdate 0x015c -#define TPM_CC_GetCapability 0x017a -#define TPM_CC_PCR_Extend 0x0182 -#define TPM_CC_EventSequenceComplete 0x0185 -#define TPM_CC_HashSequenceStart 0x0186 +#defineTPM_CC_SequenceComplete 0x013e +#defineTPM_CC_Startup 0x0144 +#defineTPM_CC_SequenceUpdate 0x015c +#defineTPM_CC_GetCapability0x017a +#defineTPM_CC_PCR_Extend 0x0182 +#defineTPM_CC_EventSequenceComplete0x0185 +#defineTPM_CC_HashSequenceStart0x0186 /* Timeout before data in read buffer is discarded */ -#defineTPM_READ_TIMEOUT50 +#defineTPM_READ_TIMEOUT50 -#defineTPM_BUFSIZE 0x1000 +#defineTPM_BUFSIZE 0x1000 -#defineTPM_HEADER_SIZE 10 +#defineTPM_HEADER_SIZE 10 -#defineTPM_CDEV_NAME "tpm0" -#defineTPM_CDEV_PERM_FLAG 0600 +#defineTPM_CDEV_NAME "tpm0" +#defineTPM_CDEV_PERM_FLAG 0600 -#define TPM2_START_METHOD_ACPI 2 -#define TPM2_START_METHOD_TIS 6 -#define TPM2_START_METHOD_CRB 7 -#define TPM2_START_METHOD_CRB_ACPI 8 +#defineTPM2_START_METHOD_ACPI 2 +#defineTPM2_START_METHOD_TIS
svn commit: r345842 - head/sys/dev/tpm
Author: mw Date: Wed Apr 3 08:22:58 2019 New Revision: 345842 URL: https://svnweb.freebsd.org/changeset/base/345842 Log: Add a cv_wait to the TPM2.0 harvesting function Harvesting has to compete for the TPM chip with userspace. Before this change the callout could hijack an unread buffer causing a userspace call to the TPM to fail. Submitted by: Kornel Duleba Reviewed by: delphij Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D19712 Modified: head/sys/dev/tpm/tpm20.c Modified: head/sys/dev/tpm/tpm20.c == --- head/sys/dev/tpm/tpm20.cWed Apr 3 08:18:18 2019(r345841) +++ head/sys/dev/tpm/tpm20.cWed Apr 3 08:22:58 2019(r345842) @@ -263,6 +263,8 @@ tpm20_harvest(void *arg) sc = arg; sx_xlock(&sc->dev_lock); + while (sc->pending_data_length != 0) + cv_wait(&sc->buf_cv, &sc->dev_lock); memcpy(sc->buf, cmd, sizeof(cmd)); result = sc->transmit(sc, sizeof(cmd)); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r345830 - in head: lib/libsecureboot lib/libsecureboot/h share/mk stand stand/common sys/conf sys/security/mac_veriexec_parser tools/build/options
Author: mw Date: Wed Apr 3 03:57:37 2019 New Revision: 345830 URL: https://svnweb.freebsd.org/changeset/base/345830 Log: Create kernel module to parse Veriexec manifest based on envs The current approach of injecting manifest into mac_veriexec is to verify the integrity of it in userspace (veriexec (8)) and pass its entries into kernel using a char device (/dev/veriexec). This requires verifying root partition integrity in loader, for example by using memory disk and checking its hash. Otherwise if rootfs is compromised an attacker could inject their own data. This patch introduces an option to parse manifest in kernel based on envs. The loader sets manifest path and digest. EVENTHANDLER is used to launch the module right after the rootfs is mounted. It has to be done this way, since one might want to verify integrity of the init file. This means that manifest is required to be present on the root partition. Note that the envs have to be set right before boot to make sure that no one can spoof them. Submitted by: Kornel Duleba Reviewed by: sjg Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D19281 Added: head/lib/libsecureboot/pass_manifest.c (contents, props changed) head/sys/security/mac_veriexec_parser/ head/sys/security/mac_veriexec_parser/mac_veriexec_parser.c (contents, props changed) head/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST (contents, props changed) Modified: head/lib/libsecureboot/Makefile.libsa.inc head/lib/libsecureboot/h/verify_file.h head/lib/libsecureboot/libsecureboot-priv.h head/lib/libsecureboot/verify_file.c head/share/mk/src.opts.mk head/stand/common/boot.c head/stand/common/module.c head/stand/loader.mk head/sys/conf/files Modified: head/lib/libsecureboot/Makefile.libsa.inc == --- head/lib/libsecureboot/Makefile.libsa.inc Wed Apr 3 03:54:30 2019 (r345829) +++ head/lib/libsecureboot/Makefile.libsa.inc Wed Apr 3 03:57:37 2019 (r345830) @@ -29,6 +29,11 @@ CFLAGS+= \ -I${SRCTOP}/stand/efi/include/${MACHINE} .endif +.if ${MK_LOADER_VERIEXEC_PASS_MANIFEST} == "yes" +SRCS+= \ + pass_manifest.c +.endif + # this is the list of paths (relative to a file # that we need to verify) used to find a signed manifest. # the signature extensions in VE_SIGNATURE_EXT_LIST Modified: head/lib/libsecureboot/h/verify_file.h == --- head/lib/libsecureboot/h/verify_file.h Wed Apr 3 03:54:30 2019 (r345829) +++ head/lib/libsecureboot/h/verify_file.h Wed Apr 3 03:57:37 2019 (r345830) @@ -32,6 +32,7 @@ #define VE_WANT 1/* we want this verified */ #define VE_MUST 2/* this must be verified */ +#define VE_NOT_CHECKED -42 #define VE_VERIFIED 1/* all good */ #define VE_UNVERIFIED_OK 0 /* not verified but that's ok */ #define VE_NOT_VERIFYING 2 /* we are not verifying */ @@ -42,6 +43,8 @@ voidve_debug_set(int); int ve_status_get(int); voidve_efi_init(void); int load_manifest(const char *, const char *, const char *, struct stat *); +int pass_manifest(const char *, const char *); +int pass_manifest_export_envs(void); int verify_file(int, const char *, off_t, int); voidverify_pcr_export(void); Modified: head/lib/libsecureboot/libsecureboot-priv.h == --- head/lib/libsecureboot/libsecureboot-priv.h Wed Apr 3 03:54:30 2019 (r345829) +++ head/lib/libsecureboot/libsecureboot-priv.h Wed Apr 3 03:57:37 2019 (r345830) @@ -31,6 +31,8 @@ /* public api */ #include "libsecureboot.h" +struct stat; + typedef struct { unsigned char *data; size_t hash_size; @@ -49,6 +51,9 @@ int verify_rsa_digest(br_rsa_public_key *pkey, const unsigned char *hash_oid, unsigned char *mdata, size_t mlen, unsigned char *sdata, size_t slen); + +int is_verified(struct stat *stp); +void add_verify_status(struct stat *stp, int status); int openpgp_self_tests(void); Added: head/lib/libsecureboot/pass_manifest.c == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libsecureboot/pass_manifest.c Wed Apr 3 03:57:37 2019 (r345830) @@ -0,0 +1,152 @@ +/*- + * Copyright (c) 2019 Stormshield. + * Copyright (c) 2019 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. +
svn commit: r350761 - in head/stand: efi/loader i386/loader
Author: mw Date: Thu Aug 8 17:03:30 2019 New Revision: 350761 URL: https://svnweb.freebsd.org/changeset/base/350761 Log: Verify files loaded in chain command. The chain command can be used to chain load another binary. If veriexec is enabled we should verify it first. Note that on EFI systems the verification was already done through firmware, assuming that Secure Boot was enabled there. Submitted by: Kornel Duleba Reviewed by: sjg MFC after: 1 week Obtained from: Semihalf Differential Revision: https://reviews.freebsd.org/D20952 Modified: head/stand/efi/loader/main.c head/stand/i386/loader/chain.c Modified: head/stand/efi/loader/main.c == --- head/stand/efi/loader/main.cThu Aug 8 16:54:22 2019 (r350760) +++ head/stand/efi/loader/main.cThu Aug 8 17:03:30 2019 (r350761) @@ -1440,6 +1440,14 @@ command_chain(int argc, char *argv[]) return (CMD_ERROR); } +#ifdef LOADER_VERIEXEC + if (verify_file(fd, name, 0, VE_MUST) < 0) { + sprintf(command_errbuf, "can't verify: %s", name); + close(fd); + return (CMD_ERROR); + } +#endif + if (fstat(fd, &st) < -1) { command_errmsg = "stat failed"; close(fd); Modified: head/stand/i386/loader/chain.c == --- head/stand/i386/loader/chain.c Thu Aug 8 16:54:22 2019 (r350760) +++ head/stand/i386/loader/chain.c Thu Aug 8 17:03:30 2019 (r350761) @@ -75,6 +75,14 @@ command_chain(int argc, char *argv[]) return (CMD_ERROR); } +#ifdef LOADER_VERIEXEC + if (verify_file(fd, argv[1], 0, VE_MUST) < 0) { + sprintf(command_errbuf, "can't verify: %s", argv[1]); + close(fd); + return (CMD_ERROR); + } +#endif + len = strlen(argv[1]); if (argv[1][len-1] != ':') { if (fstat(fd, &st) == -1) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r350759 - head/sys/security/mac_veriexec_parser
Author: mw Date: Thu Aug 8 16:51:49 2019 New Revision: 350759 URL: https://svnweb.freebsd.org/changeset/base/350759 Log: Fix mac_veriexec_parser build after r347938 In r347938 the definition of mac_veriexec_metadata_add_file so adjust the argument list accordingly. Submitted by: Kornel Duleba Modified: head/sys/security/mac_veriexec_parser/mac_veriexec_parser.c Modified: head/sys/security/mac_veriexec_parser/mac_veriexec_parser.c == --- head/sys/security/mac_veriexec_parser/mac_veriexec_parser.c Thu Aug 8 16:48:19 2019(r350758) +++ head/sys/security/mac_veriexec_parser/mac_veriexec_parser.c Thu Aug 8 16:51:49 2019(r350759) @@ -364,7 +364,9 @@ parse_entry(char *entry, char *prefix) rc = mac_veriexec_metadata_add_file( is_exec == 0, va.va_fsid, va.va_fileid, va.va_gen, - digest, flags, fp_type, 1); + digest, + NULL, 0, + flags, fp_type, 1); mtx_unlock(&ve_mutex); out: ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348416 - in head/sys: dev/ena modules/ena
Author: mw Date: Thu May 30 13:52:32 2019 New Revision: 348416 URL: https://svnweb.freebsd.org/changeset/base/348416 Log: Update ENA version to v2.0.0 ENAv2 introduces many new features, bug fixes and improvements. Main new features are LLQ (Low Latency Queues) and independent queues reconfiguration using sysctl commands. The year in copyright notice was updated to 2019. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c head/sys/dev/ena/ena_sysctl.h head/sys/modules/ena/Makefile Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:51:11 2019(r348415) +++ head/sys/dev/ena/ena.c Thu May 30 13:52:32 2019(r348416) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Thu May 30 13:51:11 2019(r348415) +++ head/sys/dev/ena/ena.h Thu May 30 13:52:32 2019(r348416) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,9 +39,9 @@ #include "ena-com/ena_com.h" #include "ena-com/ena_eth_com.h" -#define DRV_MODULE_VER_MAJOR 0 -#define DRV_MODULE_VER_MINOR 8 -#define DRV_MODULE_VER_SUBMINOR 4 +#define DRV_MODULE_VER_MAJOR 2 +#define DRV_MODULE_VER_MINOR 0 +#define DRV_MODULE_VER_SUBMINOR 0 #define DRV_MODULE_NAME"ena" Modified: head/sys/dev/ena/ena_sysctl.c == --- head/sys/dev/ena/ena_sysctl.c Thu May 30 13:51:11 2019 (r348415) +++ head/sys/dev/ena/ena_sysctl.c Thu May 30 13:52:32 2019 (r348416) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/dev/ena/ena_sysctl.h == --- head/sys/dev/ena/ena_sysctl.h Thu May 30 13:51:11 2019 (r348415) +++ head/sys/dev/ena/ena_sysctl.h Thu May 30 13:52:32 2019 (r348416) @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. * All rights reserved. * * Redistribution and use in source and binary forms, with or without Modified: head/sys/modules/ena/Makefile == --- head/sys/modules/ena/Makefile Thu May 30 13:51:11 2019 (r348415) +++ head/sys/modules/ena/Makefile Thu May 30 13:52:32 2019 (r348416) @@ -1,7 +1,7 @@ # # BSD LICENSE # -# Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates. +# Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. # All rights reserved. # # Redistribution and use in source and binary forms, with or without ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348414 - head/share/man/man4
Author: mw Date: Thu May 30 13:50:45 2019 New Revision: 348414 URL: https://svnweb.freebsd.org/changeset/base/348414 Log: Fix ENA manual issues The issues were pointed in community review: https://reviews.freebsd.org/D10427#inline-67587 Also, fix other issues found by the igor tool. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/share/man/man4/ena.4 Modified: head/share/man/man4/ena.4 == --- head/share/man/man4/ena.4 Thu May 30 13:45:41 2019(r348413) +++ head/share/man/man4/ena.4 Thu May 30 13:50:45 2019(r348414) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 04, 2017 +.Dd August 16, 2017 .Dt ENA 4 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd "FreeBSD kernel driver for Elastic Network Adapter (ENA) family" .Sh SYNOPSIS To compile this driver into the kernel, -place the following line in your +place the following line in the kernel configuration file: .Bd -ragged -offset indent .Cd "device ena" @@ -59,8 +59,9 @@ The driver supports a range of ENA devices, is link-sp (i.e., the same driver is used for 10GbE, 25GbE, 40GbE, etc.), and has a negotiated and extendable feature set. .Pp -Some ENA devices support SR-IOV. This driver is used for both the -SR-IOV Physical Function (PF) and Virtual Function (VF) devices. +Some ENA devices support SR-IOV. +This driver is used for both the SR-IOV Physical Function (PF) and Virtual +Function (VF) devices. .Pp The ENA devices enable high speed and low overhead network traffic processing by providing multiple Tx/Rx queue pairs (the maximum number @@ -82,8 +83,8 @@ to recover in a manner transparent to the application, debug logs. .Pp Some of the ENA devices support a working mode called Low-latency -Queue (LLQ), which saves several more microseconds. This feature will -be implemented for driver in future releases. +Queue (LLQ), which saves several more microseconds. +This feature will be implemented for driver in future releases. .Sh HARDWARE Supported PCI vendor ID/device IDs: .Pp @@ -105,19 +106,23 @@ Supported PCI vendor ID/device IDs: Error occurred during initialization of the mmio register read request. .It ena%d: Can not reset device .Pp -Device could not be reset; device may not be responding or is already -during reset. +Device could not be reset. +.br +Device may not be responding or is already during reset. .It ena%d: device version is too low .Pp -Version of the controller is too low and it is not supported by the driver. +Version of the controller is too old and it is not supported by the driver. .It ena%d: Invalid dma width value %d .Pp -The controller is able to request dma transcation width. Device stopped -responding or it demanded invalid value. +The controller is able to request dma transaction width. +.br +Device stopped responding or it demanded invalid value. .It ena%d: Can not initialize ena admin queue with device .Pp -Initialization of the Admin Queue failed; device may not be responding or there -was a problem with initialization of the resources. +Initialization of the Admin Queue failed. +.br +Device may not be responding or there was a problem with initialization of +the resources. .It ena%d: Cannot get attribute for ena device rc: %d .Pp Failed to get attributes of the device from the controller. @@ -141,11 +146,14 @@ Errors occurred when trying to configure AENQ groups. .It ena%d: could not allocate irq vector: %d .It ena%d: Unable to allocate bus resource: registers .Pp -Resource allocation failed when initializing the device; driver will not -be attached. +Resource allocation failed when initializing the device. +.br +Driver will not be attached. .It ena%d: ENA device init failed (err: %d) .Pp -Device initialization failed; driver will not be attached. +Device initialization failed. +.br +Driver will not be attached. .It ena%d: could not activate irq vector: %d .Pp Error occurred when trying to activate interrupt vectors for Admin Queue. @@ -157,13 +165,16 @@ Error occurred when trying to register Admin Queue int Error occurred during configuration of the Admin Queue interrupts. .It ena%d: Enable MSI-X failed .Pp -Configuration of the MSI-X for Admin Queue failed; there could be lack -of resources or interrupts could not have been configured; driver will -not be attached. +Configuration of the MSI-X for Admin Queue failed. +.br +There could be lack of resources or interrupts could not have been configured. +.br +Driver will not be attached. .It ena%d: VLAN is in use, detach first .Pp -VLANs are being used when trying to detach the driver; VLANs should be detached -first and then detach routine should be called again. +VLANs are being used when trying to detach the driver. +.br +VLANs must be detached first and then detach routine have to be called again. .It ena%d: Unmapped RX DMA tag associations .It ena%d: Unmapped TX DMA t
svn commit: r348413 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:45:41 2019 New Revision: 348413 URL: https://svnweb.freebsd.org/changeset/base/348413 Log: Improve ENA reset handling For easier debugging, the reset is being triggered and the reset reason is being set only in case it is done for the first time. Such approach will ensure that the first reset reason is not going to be overwritten and will make it easier for debugging. Also, add a reset trigger upon invalid Tx requested ID. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:42:52 2019(r348412) +++ head/sys/dev/ena/ena.c Thu May 30 13:45:41 2019(r348413) @@ -777,8 +777,10 @@ validate_rx_req_id(struct ena_ring *rx_ring, uint16_t counter_u64_add(rx_ring->rx_stats.bad_req_id, 1); /* Trigger device reset */ - rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, rx_ring->adapter); + if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, rx_ring->adapter))) { + rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, rx_ring->adapter); + } return (EFAULT); } @@ -1242,6 +1244,10 @@ validate_tx_req_id(struct ena_ring *tx_ring, uint16_t device_printf(adapter->pdev, "Invalid req_id: %hu\n", req_id); counter_u64_add(tx_ring->tx_stats.bad_req_id, 1); + /* Trigger device reset */ + adapter->reset_reason = ENA_REGS_RESET_INV_TX_REQ_ID; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + return (EFAULT); } @@ -1799,8 +1805,10 @@ error: counter_u64_add(rx_ring->rx_stats.bad_desc_num, 1); /* Too many desc from the device. Trigger reset */ - adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { + adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + } return (0); } @@ -3806,8 +3814,10 @@ static void check_for_missing_keep_alive(struct ena_ad device_printf(adapter->pdev, "Keep alive watchdog timeout.\n"); counter_u64_add(adapter->dev_stats.wd_expired, 1); - adapter->reset_reason = ENA_REGS_RESET_KEEP_ALIVE_TO; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { + adapter->reset_reason = ENA_REGS_RESET_KEEP_ALIVE_TO; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + } } } @@ -3819,8 +3829,10 @@ static void check_for_admin_com_state(struct ena_adapt device_printf(adapter->pdev, "ENA admin queue is not in running state!\n"); counter_u64_add(adapter->dev_stats.admin_q_pause, 1); - adapter->reset_reason = ENA_REGS_RESET_ADMIN_TO; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { + adapter->reset_reason = ENA_REGS_RESET_ADMIN_TO; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + } } } @@ -3838,9 +3850,11 @@ check_for_rx_interrupt_queue(struct ena_adapter *adapt if (rx_ring->no_interrupt_event_cnt == ENA_MAX_NO_INTERRUPT_ITERATIONS) { device_printf(adapter->pdev, "Potential MSIX issue on Rx side " - "Queue = %d. Reset the device\n", rx_ring->qid); - adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + "Queue = %d. Reset the device\n", rx_ring->qid); + if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { + adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + } return (EIO); } @@ -3878,8 +3892,13 @@ check_missing_comp_in_tx_queue(struct ena_adapter *ada device_printf(adapter->pdev, "Potential MSIX issue on Tx side Queue = %d. " "Reset the device\n", tx_ring->qid); - adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; - ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + if (likely(!ENA_FLAG_ISSET(
svn commit: r348412 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:42:52 2019 New Revision: 348412 URL: https://svnweb.freebsd.org/changeset/base/348412 Log: Fix NULL pointer dereference in ena_up() If the call to ena_up() in ena_restore_device() fails, next usage of `ifconfig up` will cause NULL pointer dereference. This patch adds additional checks to prevent that. Submitted by: Rafal Kozik Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:41:39 2019(r348411) +++ head/sys/dev/ena/ena.c Thu May 30 13:42:52 2019(r348412) @@ -134,7 +134,7 @@ static void ena_cleanup(void *arg, int pending); static int ena_handle_msix(void *); static int ena_enable_msix(struct ena_adapter *); static voidena_setup_mgmnt_intr(struct ena_adapter *); -static voidena_setup_io_intr(struct ena_adapter *); +static int ena_setup_io_intr(struct ena_adapter *); static int ena_request_mgmnt_irq(struct ena_adapter *); static int ena_request_io_irq(struct ena_adapter *); static voidena_free_mgmnt_irq(struct ena_adapter *); @@ -1969,12 +1969,15 @@ ena_setup_mgmnt_intr(struct ena_adapter *adapter) adapter->msix_entries[ENA_MGMNT_IRQ_IDX].vector; } -static void +static int ena_setup_io_intr(struct ena_adapter *adapter) { static int last_bind_cpu = -1; int irq_idx; + if (adapter->msix_entries == NULL) + return (EINVAL); + for (int i = 0; i < adapter->num_queues; i++) { irq_idx = ENA_IO_IRQ_IDX(i); @@ -1997,6 +2000,8 @@ ena_setup_io_intr(struct ena_adapter *adapter) last_bind_cpu; last_bind_cpu = CPU_NEXT(last_bind_cpu); } + + return (0); } static int @@ -2290,11 +2295,15 @@ ena_up(struct ena_adapter *adapter) device_printf(adapter->pdev, "device is going UP\n"); /* setup interrupts for IO queues */ - ena_setup_io_intr(adapter); + rc = ena_setup_io_intr(adapter); + if (unlikely(rc != 0)) { + ena_trace(ENA_ALERT, "error setting up IO interrupt\n"); + goto error; + } rc = ena_request_io_irq(adapter); if (unlikely(rc != 0)) { ena_trace(ENA_ALERT, "err_req_irq\n"); - goto err_req_irq; + goto error; } /* allocate transmit descriptors */ @@ -2351,7 +2360,7 @@ err_setup_rx: ena_free_all_tx_resources(adapter); err_setup_tx: ena_free_io_irq(adapter); -err_req_irq: +error: return (rc); } ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348411 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:41:39 2019 New Revision: 348411 URL: https://svnweb.freebsd.org/changeset/base/348411 Log: Unify new line characters in the ENA driver Some messages were missing new line character and traces were not having unified behavior. To fix that, each trace and printout should add new line character at the end of each string - that should improve readability. Submitted by: Rafal Kozik Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:40:51 2019(r348410) +++ head/sys/dev/ena/ena.c Thu May 30 13:41:39 2019(r348411) @@ -308,7 +308,7 @@ ena_probe(device_t dev) while (ent->vendor_id != 0) { if ((pci_vendor_id == ent->vendor_id) && (pci_device_id == ent->device_id)) { - ena_trace(ENA_DBG, "vendor=%x device=%x ", + ena_trace(ENA_DBG, "vendor=%x device=%x\n", pci_vendor_id, pci_device_id); sprintf(adapter_name, DEVICE_DESC); @@ -969,7 +969,7 @@ ena_alloc_rx_mbuf(struct ena_adapter *adapter, /* Map packets for DMA */ ena_trace(ENA_DBG | ENA_RSC | ENA_RXPTH, - "Using tag %p for buffers' DMA mapping, mbuf %p len: %d", + "Using tag %p for buffers' DMA mapping, mbuf %p len: %d\n", adapter->rx_buf_tag,rx_info->mbuf, rx_info->mbuf->m_len); error = bus_dmamap_load_mbuf_sg(adapter->rx_buf_tag, rx_info->map, rx_info->mbuf, segs, &nsegs, BUS_DMA_NOWAIT); @@ -1030,7 +1030,7 @@ ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t uint32_t i; int rc; - ena_trace(ENA_DBG | ENA_RXPTH | ENA_RSC, "refill qid: %d", + ena_trace(ENA_DBG | ENA_RXPTH | ENA_RSC, "refill qid: %d\n", rx_ring->qid); next_to_use = rx_ring->next_to_use; @@ -1039,7 +1039,7 @@ ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t struct ena_rx_buffer *rx_info; ena_trace(ENA_DBG | ENA_RXPTH | ENA_RSC, - "RX buffer - next to use: %d", next_to_use); + "RX buffer - next to use: %d\n", next_to_use); req_id = rx_ring->free_rx_ids[next_to_use]; rx_info = &rx_ring->rx_buffer_info[req_id]; @@ -1143,12 +1143,12 @@ ena_free_tx_bufs(struct ena_adapter *adapter, unsigned if (print_once) { device_printf(adapter->pdev, - "free uncompleted tx mbuf qid %d idx 0x%x", + "free uncompleted tx mbuf qid %d idx 0x%x\n", qid, i); print_once = false; } else { ena_trace(ENA_DBG, - "free uncompleted tx mbuf qid %d idx 0x%x", + "free uncompleted tx mbuf qid %d idx 0x%x\n", qid, i); } @@ -1404,7 +1404,7 @@ ena_tx_cleanup(struct ena_ring *tx_ring) tx_info->seg_mapped = false; } - ena_trace(ENA_DBG | ENA_TXPTH, "tx: q %d mbuf %p completed", + ena_trace(ENA_DBG | ENA_TXPTH, "tx: q %d mbuf %p completed\n", tx_ring->qid, mbuf); m_freem(mbuf); @@ -1429,7 +1429,7 @@ ena_tx_cleanup(struct ena_ring *tx_ring) work_done = TX_BUDGET - budget; - ena_trace(ENA_DBG | ENA_TXPTH, "tx: q %d done. total pkts: %d", + ena_trace(ENA_DBG | ENA_TXPTH, "tx: q %d done. total pkts: %d\n", tx_ring->qid, work_done); /* If there is still something to commit update ring state */ @@ -1551,7 +1551,7 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r return (NULL); } - ena_trace(ENA_DBG | ENA_RXPTH, "rx_info %p, mbuf %p, paddr %jx", + ena_trace(ENA_DBG | ENA_RXPTH, "rx_info %p, mbuf %p, paddr %jx\n", rx_info, rx_info->mbuf, (uintmax_t)rx_info->ena_buf.paddr); bus_dmamap_sync(adapter->rx_buf_tag, rx_info->map, @@ -1565,7 +1565,7 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r /* Fill mbuf with hash key and it's interpretation for optimization */ ena_rx_hash_mbuf(rx_ring, ena_rx_ctx, mbuf); - ena_trace(ENA_DBG | ENA_RXPTH, "rx mbuf 0x%p, flags=0x%x, len: %d", + ena_trace(ENA_DBG | ENA_RXPTH, "rx mbuf 0x%p, flags=0x%x, len: %d\n", mbuf, mbuf->m_flags, mbuf->m_pkthdr.len); /* DMA address is not needed anymore, unmap it */ @@ -1615,12 +1615,12 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r BUS_DMASYNC_POSTREAD); if (unlikely(m_append(mbuf, len, rx_info->mbuf->m_data) == 0)) {
svn commit: r348410 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:40:51 2019 New Revision: 348410 URL: https://svnweb.freebsd.org/changeset/base/348410 Log: Fix Tx offloads for fragmented pkt headers in ENA If the headers of the packets are split into multiple segments of the mbuf chain, the previous version of ena_tx_csum which was assuming, that all segments will lay in the first mbuf, will eventually fail to map the headers properties to meta descriptor. That will cause Tx checksum offload to do not work and was leading to memory corruption. It could even cause the crash of the system. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:39:25 2019(r348409) +++ head/sys/dev/ena/ena.c Thu May 30 13:40:51 2019(r348410) @@ -2683,6 +2683,7 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct { struct ena_com_tx_meta *ena_meta; struct ether_vlan_header *eh; + struct mbuf *mbuf_next; u32 mss; bool offload; uint16_t etype; @@ -2690,6 +2691,7 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct struct ip *ip; int iphlen; struct tcphdr *th; + int offset; offload = false; ena_meta = &ena_tx_ctx->ena_meta; @@ -2719,9 +2721,12 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct ehdrlen = ETHER_HDR_LEN; } - ip = (struct ip *)(mbuf->m_data + ehdrlen); + mbuf_next = m_getptr(mbuf, ehdrlen, &offset); + ip = (struct ip *)(mtodo(mbuf_next, offset)); iphlen = ip->ip_hl << 2; - th = (struct tcphdr *)((caddr_t)ip + iphlen); + + mbuf_next = m_getptr(mbuf, iphlen + ehdrlen, &offset); + th = (struct tcphdr *)(mtodo(mbuf_next, offset)); if ((mbuf->m_pkthdr.csum_flags & CSUM_IP) != 0) { ena_tx_ctx->l3_csum_enable = 1; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348409 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:39:25 2019 New Revision: 348409 URL: https://svnweb.freebsd.org/changeset/base/348409 Log: Split ENA reset routine into restore and destroy stages For alignment with Linux driver and better handling ena_detach(), the reset is now calling ena_device_restore() and ena_device_destroy(). The ena_device_destroy() is also being called on ena_detach(), so the code will be more readable. The watchdog is now being activated after reset only, if it was active before. There were added additional checks to ensure, that there is no race with the link state change AENQ handler. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:37:15 2019(r348408) +++ head/sys/dev/ena/ena.c Thu May 30 13:39:25 2019(r348409) @@ -2286,11 +2286,6 @@ ena_up(struct ena_adapter *adapter) return (ENXIO); } - if (unlikely(!ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter))) { - device_printf(adapter->pdev, "device is not running!\n"); - return (ENXIO); - } - if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) { device_printf(adapter->pdev, "device is going UP\n"); @@ -4066,87 +4061,172 @@ ena_timer_service(void *data) } static void -ena_reset_task(void *arg, int pending) +ena_destroy_device(struct ena_adapter *adapter, bool graceful) { - struct ena_com_dev_get_features_ctx get_feat_ctx; - struct ena_adapter *adapter = (struct ena_adapter *)arg; + if_t ifp = adapter->ifp; struct ena_com_dev *ena_dev = adapter->ena_dev; bool dev_up; - int rc; - if (unlikely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { - device_printf(adapter->pdev, - "device reset scheduled but trigger_reset is off\n"); + if (!ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter)) return; - } - sx_xlock(&adapter->ioctl_sx); + if_link_state_change(ifp, LINK_STATE_DOWN); callout_drain(&adapter->timer_service); dev_up = ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter); + if (dev_up) + ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter); + else + ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter); - ena_com_set_admin_running_state(ena_dev, false); - ena_down(adapter); + if (!graceful) + ena_com_set_admin_running_state(ena_dev, false); + + if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) + ena_down(adapter); + + /* +* Stop the device from sending AENQ events (if the device was up, and +* the trigger reset was on, ena_down already performs device reset) +*/ + if (!(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter) && dev_up)) + ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason); + ena_free_mgmnt_irq(adapter); + ena_disable_msix(adapter); + ena_com_abort_admin_commands(ena_dev); + ena_com_wait_for_abort_completion(ena_dev); + ena_com_admin_destroy(ena_dev); + ena_com_mmio_reg_read_request_destroy(ena_dev); adapter->reset_reason = ENA_REGS_RESET_NORMAL; + ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); + ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter); +} - /* Finished destroy part. Restart the device */ - rc = ena_device_init(adapter, adapter->pdev, &get_feat_ctx, - &adapter->wd_active); - if (unlikely(rc != 0)) { +static int +ena_device_validate_params(struct ena_adapter *adapter, +struct ena_com_dev_get_features_ctx *get_feat_ctx) +{ + + if (memcmp(get_feat_ctx->dev_attr.mac_addr, adapter->mac_addr, + ETHER_ADDR_LEN) != 0) { device_printf(adapter->pdev, - "ENA device init failed! (err: %d)\n", rc); - goto err_dev_free; + "Error, mac address are different\n"); + return (EINVAL); } + if (get_feat_ctx->dev_attr.max_mtu < if_getmtu(adapter->ifp)) { + device_printf(adapter->pdev, + "Error, device max mtu is smaller than ifp MTU\n"); + return (EINVAL); + } + + return 0; +} + +static int +ena_restore_device(struct ena_adapter *adapter) +{ + struct ena_com_dev_get_features_ctx get_feat_ctx; + struct ena_com_dev *ena_dev = adapter->ena_dev; + if_t ifp = adapter->ifp; + device_t dev = adapter->pdev; + int wd_active; + int rc; + + ENA_FLAG_SET_ATOMIC(ENA_FLAG_ONGOING_RESET, adapter); + + rc = ena_device_init(adapter, dev, &get_feat_ctx, &w
svn commit: r348408 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:37:15 2019 New Revision: 348408 URL: https://svnweb.freebsd.org/changeset/base/348408 Log: Use bitfield for storing global ENA device states As the ENA can have multiple states turned on/off, it is more convenient to store them in single bitfield instead of multiple boolean variables. The bitset FreeBSD API was used for the bitfield implementation, as it provides flexible structure together with API which also supports atomic bitfield operations. For better readability basic macros from API were wrapped into custom ENA_FLAG_* macros, which are filling up common parameters for all calls. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:35:43 2019(r348407) +++ head/sys/dev/ena/ena.c Thu May 30 13:37:15 2019(r348408) @@ -778,7 +778,7 @@ validate_rx_req_id(struct ena_ring *rx_ring, uint16_t /* Trigger device reset */ rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; - rx_ring->adapter->trigger_reset = true; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, rx_ring->adapter); return (EFAULT); } @@ -1471,7 +1471,7 @@ ena_rx_hash_mbuf(struct ena_ring *rx_ring, struct ena_ { struct ena_adapter *adapter = rx_ring->adapter; - if (likely(adapter->rss_support)) { + if (likely(ENA_FLAG_ISSET(ENA_FLAG_RSS_ACTIVE, adapter))) { mbuf->m_pkthdr.flowid = ena_rx_ctx->hash; if (ena_rx_ctx->frag && @@ -1800,7 +1800,7 @@ error: /* Too many desc from the device. Trigger reset */ adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; - adapter->trigger_reset = true; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); return (0); } @@ -1821,7 +1821,7 @@ ena_intr_msix_mgmnt(void *arg) struct ena_adapter *adapter = (struct ena_adapter *)arg; ena_com_admin_q_comp_intr_handler(adapter->ena_dev); - if (likely(adapter->running)) + if (likely(ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter))) ena_com_aenq_intr_handler(adapter->ena_dev, arg); } @@ -1897,6 +1897,11 @@ ena_enable_msix(struct ena_adapter *adapter) int msix_vecs, msix_req; int i, rc = 0; + if (ENA_FLAG_ISSET(ENA_FLAG_MSIX_ENABLED, adapter)) { + device_printf(dev, "Error, MSI-X is already enabled\n"); + return (EINVAL); + } + /* Reserved the max msix vectors we might need */ msix_vecs = ENA_MAX_MSIX_VEC(adapter->num_queues); @@ -1936,7 +1941,7 @@ ena_enable_msix(struct ena_adapter *adapter) } adapter->msix_vecs = msix_vecs; - adapter->msix_enabled = true; + ENA_FLAG_SET_ATOMIC(ENA_FLAG_MSIX_ENABLED, adapter); return (0); @@ -2046,7 +2051,7 @@ ena_request_io_irq(struct ena_adapter *adapter) unsigned long flags = 0; int rc = 0, i, rcc; - if (unlikely(adapter->msix_enabled == 0)) { + if (unlikely(!ENA_FLAG_ISSET(ENA_FLAG_MSIX_ENABLED, adapter))) { device_printf(adapter->pdev, "failed to request I/O IRQ: MSI-X is not enabled\n"); return (EINVAL); @@ -2196,10 +2201,14 @@ static void ena_disable_msix(struct ena_adapter *adapter) { - pci_release_msi(adapter->pdev); + if (ENA_FLAG_ISSET(ENA_FLAG_MSIX_ENABLED, adapter)) { + ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_MSIX_ENABLED, adapter); + pci_release_msi(adapter->pdev); + } adapter->msix_vecs = 0; - free(adapter->msix_entries, M_DEVBUF); + if (adapter->msix_entries != NULL) + free(adapter->msix_entries, M_DEVBUF); adapter->msix_entries = NULL; } @@ -2250,7 +2259,7 @@ ena_up_complete(struct ena_adapter *adapter) { int rc; - if (likely(adapter->rss_support)) { + if (likely(ENA_FLAG_ISSET(ENA_FLAG_RSS_ACTIVE, adapter))) { rc = ena_rss_configure(adapter); if (rc != 0) return (rc); @@ -2277,12 +2286,12 @@ ena_up(struct ena_adapter *adapter) return (ENXIO); } - if (unlikely(!adapter->running)) { + if (unlikely(!ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter))) { device_printf(adapter->pdev, "device is not running!\n"); return (ENXIO); } - if (!adapter->up) { + if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) { device_printf(adapter->pdev, "device is going UP\n"); /* setup interrupts for IO queues */ @@ -2315,7 +2324,7 @@ ena_up(struct ena_adapter *adapter) goto err_io_
svn commit: r348407 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:35:43 2019 New Revision: 348407 URL: https://svnweb.freebsd.org/changeset/base/348407 Log: Fix error handling when ENA reset fails Before the patch, error handling was not releasing all resources and was not issuing device reset if the reset task failed. That could cause memory leak and fault of the device. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:35:02 2019(r348406) +++ head/sys/dev/ena/ena.c Thu May 30 13:35:43 2019(r348407) @@ -4130,7 +4130,11 @@ err_msix_free: ena_free_mgmnt_irq(adapter); ena_disable_msix(adapter); err_com_free: + ena_com_abort_admin_commands(ena_dev); + ena_com_wait_for_abort_completion(ena_dev); ena_com_admin_destroy(ena_dev); + ena_com_mmio_reg_read_request_destroy(ena_dev); + ena_com_dev_reset(ena_dev, ENA_REGS_RESET_DRIVER_INVALID_STATE); err_dev_free: device_printf(adapter->pdev, "ENA reset failed!\n"); adapter->running = false; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348406 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:35:02 2019 New Revision: 348406 URL: https://svnweb.freebsd.org/changeset/base/348406 Log: Fill bdf field of the host_info structure in ENA The host info bdf field is the abbreviation for the bus, device, function of the PCI on which the device is being attached to. Now the driver is filling information about that using FreeBSD RID resource. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:33:31 2019(r348405) +++ head/sys/dev/ena/ena.c Thu May 30 13:35:02 2019(r348406) @@ -176,7 +176,7 @@ static int ena_handle_updated_queues(struct ena_adapte struct ena_com_dev_get_features_ctx *); static int ena_rss_init_default(struct ena_adapter *); static voidena_rss_init_default_deferred(void *); -static voidena_config_host_info(struct ena_com_dev *); +static voidena_config_host_info(struct ena_com_dev *, device_t); static int ena_attach(device_t); static int ena_detach(device_t); static int ena_device_init(struct ena_adapter *, device_t, @@ -3579,9 +3579,10 @@ ena_rss_init_default_deferred(void *arg) SYSINIT(ena_rss_init, SI_SUB_KICK_SCHEDULER, SI_ORDER_SECOND, ena_rss_init_default_deferred, NULL); static void -ena_config_host_info(struct ena_com_dev *ena_dev) +ena_config_host_info(struct ena_com_dev *ena_dev, device_t dev) { struct ena_admin_host_info *host_info; + uintptr_t rid; int rc; /* Allocate only the host info */ @@ -3593,6 +3594,8 @@ ena_config_host_info(struct ena_com_dev *ena_dev) host_info = ena_dev->host_attr.host_info; + if (pci_get_id(dev, PCI_ID_RID, &rid) == 0) + host_info->bdf = rid; host_info->os_type = ENA_ADMIN_OS_FREEBSD; host_info->kernel_ver = osreldate; @@ -3681,7 +3684,7 @@ ena_device_init(struct ena_adapter *adapter, device_t */ ena_com_set_admin_polling_mode(ena_dev, true); - ena_config_host_info(ena_dev); + ena_config_host_info(ena_dev, pdev); /* Get Device Attributes */ rc = ena_com_get_dev_attr_feat(ena_dev, get_feat_ctx); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348405 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:33:31 2019 New Revision: 348405 URL: https://svnweb.freebsd.org/changeset/base/348405 Log: Add additional doorbells on ENA Tx path The new ENA HAL is introducing API, which can determine on Tx path if the doorbell is needed. That way, it can tell the driver, that it should call an doorbell. The old threshold value wasn't removed, as not all HW is supporting this feature - so it was reworked to also work with the new API. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:31:35 2019(r348404) +++ head/sys/dev/ena/ena.c Thu May 30 13:33:31 2019(r348405) @@ -590,6 +590,7 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in tx_ring->next_to_use = 0; tx_ring->next_to_clean = 0; + tx_ring->acum_pkts = 0; /* Make sure that drbr is empty */ ENA_RING_MTX_LOCK(tx_ring); @@ -3007,6 +3008,18 @@ ena_xmit_mbuf(struct ena_ring *tx_ring, struct mbuf ** /* Set flags and meta data */ ena_tx_csum(&ena_tx_ctx, *mbuf); + + if (tx_ring->acum_pkts == DB_THRESHOLD || + ena_com_is_doorbell_needed(tx_ring->ena_com_io_sq, &ena_tx_ctx)) { + ena_trace(ENA_DBG | ENA_TXPTH, + "llq tx max burst size of queue %d achieved, writing doorbell to send burst\n", + tx_ring->que->id); + wmb(); + ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq); + counter_u64_add(tx_ring->tx_stats.doorbells, 1); + tx_ring->acum_pkts = 0; + } + /* Prepare the packet's descriptors and send them to device */ rc = ena_com_prepare_tx(io_sq, &ena_tx_ctx, &nb_hw_desc); if (unlikely(rc != 0)) { @@ -3096,7 +3109,6 @@ ena_start_xmit(struct ena_ring *tx_ring) struct ena_adapter *adapter = tx_ring->adapter; struct ena_com_io_sq* io_sq; int ena_qid; - int acum_pkts = 0; int ret = 0; if (unlikely((if_getdrvflags(adapter->ifp) & IFF_DRV_RUNNING) == 0)) @@ -3137,25 +3149,17 @@ ena_start_xmit(struct ena_ring *tx_ring) IFF_DRV_RUNNING) == 0)) return; - acum_pkts++; + tx_ring->acum_pkts++; BPF_MTAP(adapter->ifp, mbuf); - - if (unlikely(acum_pkts == DB_THRESHOLD)) { - acum_pkts = 0; - wmb(); - /* Trigger the dma engine */ - ena_com_write_sq_doorbell(io_sq); - counter_u64_add(tx_ring->tx_stats.doorbells, 1); - } - } - if (likely(acum_pkts != 0)) { + if (likely(tx_ring->acum_pkts != 0)) { wmb(); /* Trigger the dma engine */ ena_com_write_sq_doorbell(io_sq); counter_u64_add(tx_ring->tx_stats.doorbells, 1); + tx_ring->acum_pkts = 0; } if (unlikely(!tx_ring->running)) Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Thu May 30 13:31:35 2019(r348404) +++ head/sys/dev/ena/ena.h Thu May 30 13:33:31 2019(r348405) @@ -319,6 +319,9 @@ struct ena_ring { bool running; }; + /* How many packets are sent in one Tx loop, used for doorbells */ + uint32_t acum_pkts; + /* Used for LLQ */ uint8_t *push_buf_intermediate_buf; } __aligned(CACHE_LINE_SIZE); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348404 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:31:35 2019 New Revision: 348404 URL: https://svnweb.freebsd.org/changeset/base/348404 Log: Limit maximum size of Rx refill threshold in ENA The Rx ring size can be as high as 8k. Because of that we want to limit the cleanup threshold by maximum value of 256. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:30:52 2019(r348403) +++ head/sys/dev/ena/ena.c Thu May 30 13:31:35 2019(r348404) @@ -1781,7 +1781,9 @@ ena_rx_cleanup(struct ena_ring *rx_ring) rx_ring->next_to_clean = next_to_clean; refill_required = ena_com_free_desc(io_sq); - refill_threshold = rx_ring->ring_size / ENA_RX_REFILL_THRESH_DIVIDER; + refill_threshold = min_t(int, + rx_ring->ring_size / ENA_RX_REFILL_THRESH_DIVIDER, + ENA_RX_REFILL_THRESH_PACKET); if (refill_required > refill_threshold) { ena_com_update_dev_comp_head(rx_ring->ena_com_io_cq); Modified: head/sys/dev/ena/ena.h == --- head/sys/dev/ena/ena.h Thu May 30 13:30:52 2019(r348403) +++ head/sys/dev/ena/ena.h Thu May 30 13:31:35 2019(r348404) @@ -70,7 +70,12 @@ #defineENA_DEFAULT_RING_SIZE 1024 +/* + * Refill Rx queue when number of required descriptors is above + * QUEUE_SIZE / ENA_RX_REFILL_THRESH_DIVIDER or ENA_RX_REFILL_THRESH_PACKET + */ #defineENA_RX_REFILL_THRESH_DIVIDER8 +#defineENA_RX_REFILL_THRESH_PACKET 256 #defineENA_IRQNAME_SIZE40 ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348403 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:30:52 2019 New Revision: 348403 URL: https://svnweb.freebsd.org/changeset/base/348403 Log: Add support for the LLQv2 and WC in ENA LLQ (Low Latency Queue) is the feature, that allows pushing header directly to the device through PCI before even DMA is triggered. It reduces latency, because device can start preparing packet before payload is sent through DMA. To speed up sending data through PCI, the Write Combining is enabled, which allows hardware to buffer data before sending them on the PCI - it allows to reduce number of PCI IO operations. ENAv2 is using special descriptor for the negotiation of the LLQ. Currently, only the default configuration is supported. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:29:24 2019(r348402) +++ head/sys/dev/ena/ena.c Thu May 30 13:30:52 2019(r348403) @@ -73,6 +73,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + #include "ena.h" #include "ena_sysctl.h" @@ -81,7 +84,6 @@ __FBSDID("$FreeBSD$"); */ static int ena_probe(device_t); static voidena_intr_msix_mgmnt(void *); -static int ena_allocate_pci_resources(struct ena_adapter*); static voidena_free_pci_resources(struct ena_adapter *); static int ena_change_mtu(if_t, int); static inline void ena_alloc_counters(counter_u64_t *, int); @@ -157,11 +159,15 @@ static intena_setup_ifnet(device_t, struct ena_adapte static voidena_tx_csum(struct ena_com_tx_ctx *, struct mbuf *); static int ena_check_and_collapse_mbuf(struct ena_ring *tx_ring, struct mbuf **mbuf); +static voidena_dmamap_llq(void *, bus_dma_segment_t *, int, int); static int ena_xmit_mbuf(struct ena_ring *, struct mbuf **); static voidena_start_xmit(struct ena_ring *); static int ena_mq_start(if_t, struct mbuf *); static voidena_deferred_mq_start(void *, int); static voidena_qflush(if_t); +static int ena_enable_wc(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_calc_io_queue_num(struct ena_adapter *, struct ena_com_dev_get_features_ctx *); static int ena_calc_queue_size(struct ena_adapter *, @@ -271,25 +277,6 @@ fail_tag: return (error); } -static int -ena_allocate_pci_resources(struct ena_adapter* adapter) -{ - device_t pdev = adapter->pdev; - int rid; - - rid = PCIR_BAR(ENA_REG_BAR); - adapter->memory = NULL; - adapter->registers = bus_alloc_resource_any(pdev, SYS_RES_MEMORY, - &rid, RF_ACTIVE); - if (unlikely(adapter->registers == NULL)) { - device_printf(pdev, "Unable to allocate bus resource: " - "registers\n"); - return (ENXIO); - } - - return (0); -} - static void ena_free_pci_resources(struct ena_adapter *adapter) { @@ -587,6 +574,12 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in if (unlikely(tx_ring->free_tx_ids == NULL)) goto err_buf_info_free; + size = tx_ring->tx_max_header_size; + tx_ring->push_buf_intermediate_buf = malloc(size, M_DEVBUF, + M_NOWAIT | M_ZERO); + if (unlikely(tx_ring->push_buf_intermediate_buf == NULL)) + goto err_tx_ids_free; + /* Req id stack for TX OOO completions */ for (i = 0; i < tx_ring->ring_size; i++) tx_ring->free_tx_ids[i] = i; @@ -606,12 +599,24 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in /* ... and create the buffer DMA maps */ for (i = 0; i < tx_ring->ring_size; i++) { err = bus_dmamap_create(adapter->tx_buf_tag, 0, - &tx_ring->tx_buffer_info[i].map); + &tx_ring->tx_buffer_info[i].map_head); if (unlikely(err != 0)) { ena_trace(ENA_ALERT, -"Unable to create Tx DMA map for buffer %d\n", i); + "Unable to create Tx DMA map_head for buffer %d\n", + i); goto err_buf_info_unmap; } + tx_ring->tx_buffer_info[i].seg_mapped = false; + + err = bus_dmamap_create(adapter->tx_buf_tag, 0, + &tx_ring->tx_buffer_info[i].map_seg); + if (unlikely(err != 0)) { + ena_trace(ENA_ALERT, + "Unable to create Tx DMA map_seg for buffer %d\n", + i); +
svn commit: r348402 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:29:24 2019 New Revision: 348402 URL: https://svnweb.freebsd.org/changeset/base/348402 Log: Lock optimization in ENA Handle IO interrupts using filter routine. That way, the main cleanup task could be moved to the separate thread using taskqueue. The deferred Rx cleanup task was removed, and now the cleanup task is begin called instead. That way, the Rx lock could be removed. In addition, Queue management (wake up and stop TX ring) was added, so the TX cleanup task can be performed mostly lockless. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:28:03 2019(r348401) +++ head/sys/dev/ena/ena.c Thu May 30 13:29:24 2019(r348402) @@ -120,7 +120,6 @@ static void ena_destroy_all_rx_queues(struct ena_adapt static voidena_destroy_all_io_queues(struct ena_adapter *); static int ena_create_io_queues(struct ena_adapter *); static int ena_tx_cleanup(struct ena_ring *); -static voidena_deferred_rx_cleanup(void *, int); static int ena_rx_cleanup(struct ena_ring *); static inline int validate_tx_req_id(struct ena_ring *, uint16_t); static voidena_rx_hash_mbuf(struct ena_ring *, struct ena_com_rx_ctx *, @@ -129,7 +128,8 @@ static struct mbuf* ena_rx_mbuf(struct ena_ring *, str struct ena_com_rx_ctx *, uint16_t *); static inline void ena_rx_checksum(struct ena_ring *, struct ena_com_rx_ctx *, struct mbuf *); -static voidena_handle_msix(void *); +static voidena_cleanup(void *arg, int pending); +static int ena_handle_msix(void *); static int ena_enable_msix(struct ena_adapter *); static voidena_setup_mgmnt_intr(struct ena_adapter *); static voidena_setup_io_intr(struct ena_adapter *); @@ -450,7 +450,6 @@ ena_init_io_rings(struct ena_adapter *adapter) device_get_nameunit(adapter->pdev), i); mtx_init(&txr->ring_mtx, txr->mtx_name, NULL, MTX_DEF); - mtx_init(&rxr->ring_mtx, rxr->mtx_name, NULL, MTX_DEF); que = &adapter->que[i]; que->adapter = adapter; @@ -481,7 +480,6 @@ ena_free_io_ring_resources(struct ena_adapter *adapter ENA_RING_MTX_UNLOCK(txr); mtx_destroy(&txr->ring_mtx); - mtx_destroy(&rxr->ring_mtx); } static void @@ -627,6 +625,8 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in goto err_buf_info_unmap; } + tx_ring->running = true; + taskqueue_start_threads(&tx_ring->enqueue_tq, 1, PI_NET, "%s txeq %d", device_get_nameunit(adapter->pdev), que->cpu); @@ -811,14 +811,6 @@ ena_setup_rx_resources(struct ena_adapter *adapter, un } } - /* Allocate taskqueues */ - TASK_INIT(&rx_ring->cmpl_task, 0, ena_deferred_rx_cleanup, rx_ring); - rx_ring->cmpl_tq = taskqueue_create_fast("ena RX completion", M_WAITOK, - taskqueue_thread_enqueue, &rx_ring->cmpl_tq); - - taskqueue_start_threads(&rx_ring->cmpl_tq, 1, PI_NET, - "%s rx_ring cmpl %d", device_get_nameunit(adapter->pdev), que->cpu); - return (0); err_buf_info_unmap: @@ -846,11 +838,6 @@ ena_free_rx_resources(struct ena_adapter *adapter, uns { struct ena_ring *rx_ring = &adapter->rx_ring[qid]; - while (taskqueue_cancel(rx_ring->cmpl_tq, &rx_ring->cmpl_task, NULL) != 0) - taskqueue_drain(rx_ring->cmpl_tq, &rx_ring->cmpl_task); - - taskqueue_free(rx_ring->cmpl_tq); - /* Free buffer DMA maps, */ for (int i = 0; i < rx_ring->ring_size; i++) { bus_dmamap_sync(adapter->rx_buf_tag, @@ -1176,6 +1163,18 @@ ena_destroy_all_rx_queues(struct ena_adapter *adapter) static void ena_destroy_all_io_queues(struct ena_adapter *adapter) { + struct ena_que *queue; + int i; + + for (i = 0; i < adapter->num_queues; i++) { + queue = &adapter->que[i]; + while (taskqueue_cancel(queue->cleanup_tq, + &queue->cleanup_task, NULL)) + taskqueue_drain(queue->cleanup_tq, + &queue->cleanup_task); + taskqueue_free(queue->cleanup_tq); + } + ena_destroy_all_tx_queues(adapter); ena_destroy_all_rx_queues(adapter); } @@ -1206,6 +1205,7 @@ ena_create_io_queues(struct ena_adapter *adapter) struct ena_com_dev *ena_dev = adapter->ena_dev; struct ena_com_create_io_ctx ctx; struct ena_ring *ring; + struct ena_que *queue; uint16_t ena_qid; uint32_t msix_vector; int rc, i; @@ -1267,6 +1267,18 @@ ena_create_io_queues(struct ena_adapter *adapter) } } +
svn commit: r348401 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:28:03 2019 New Revision: 348401 URL: https://svnweb.freebsd.org/changeset/base/348401 Log: Add tuneable drbr ring size and hw queues depth for ENA The driver now supports per adapter tuning of buffer ring size and HW Rx ring size. It can be achieved using sysctl node dev.ena.X. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h head/sys/dev/ena/ena_sysctl.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:26:18 2019(r348400) +++ head/sys/dev/ena/ena.c Thu May 30 13:28:03 2019(r348401) @@ -164,8 +164,10 @@ static voidena_deferred_mq_start(void *, int); static voidena_qflush(if_t); static int ena_calc_io_queue_num(struct ena_adapter *, struct ena_com_dev_get_features_ctx *); -static int ena_calc_queue_size(struct ena_adapter *, uint16_t *, -uint16_t *, struct ena_com_dev_get_features_ctx *); +static int ena_calc_queue_size(struct ena_adapter *, +struct ena_calc_queue_size_ctx *); +static int ena_handle_updated_queues(struct ena_adapter *, +struct ena_com_dev_get_features_ctx *); static int ena_rss_init_default(struct ena_adapter *); static voidena_rss_init_default_deferred(void *); static voidena_config_host_info(struct ena_com_dev *); @@ -182,22 +184,6 @@ static voidena_timer_service(void *); static char ena_version[] = DEVICE_NAME DRV_MODULE_NAME " v" DRV_MODULE_VERSION; -static SYSCTL_NODE(_hw, OID_AUTO, ena, CTLFLAG_RD, 0, "ENA driver parameters"); - -/* - * Tuneable number of buffers in the buf-ring (drbr) - */ -static int ena_buf_ring_size = 4096; -SYSCTL_INT(_hw_ena, OID_AUTO, buf_ring_size, CTLFLAG_RWTUN, -&ena_buf_ring_size, 0, "Size of the bufring"); - -/* - * Logging level for changing verbosity of the output - */ -int ena_log_level = ENA_ALERT | ENA_WARNING; -SYSCTL_INT(_hw_ena, OID_AUTO, log_level, CTLFLAG_RWTUN, -&ena_log_level, 0, "Logging level indicating verbosity of the logs"); - static ena_vendor_info_t ena_vendor_info_array[] = { { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF, 0}, { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_PF, 0}, @@ -440,7 +426,8 @@ ena_init_io_rings(struct ena_adapter *adapter) ena_com_get_nonadaptive_moderation_interval_tx(ena_dev); /* Allocate a buf ring */ - txr->br = buf_ring_alloc(ena_buf_ring_size, M_DEVBUF, + txr->buf_ring_size = adapter->buf_ring_size; + txr->br = buf_ring_alloc(txr->buf_ring_size, M_DEVBUF, M_WAITOK, &txr->ring_mtx); /* Alloc TX statistics. */ @@ -3008,11 +2995,25 @@ static int ena_calc_io_queue_num(struct ena_adapter *adapter, struct ena_com_dev_get_features_ctx *get_feat_ctx) { + struct ena_com_dev *ena_dev = adapter->ena_dev; int io_sq_num, io_cq_num, io_queue_num; - io_sq_num = get_feat_ctx->max_queues.max_sq_num; - io_cq_num = get_feat_ctx->max_queues.max_cq_num; + /* Regular queues capabilities */ + if (ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) { + struct ena_admin_queue_ext_feature_fields *max_queue_ext = + &get_feat_ctx->max_queue_ext.max_queue_ext; + io_sq_num = max_queue_ext->max_rx_sq_num; + io_sq_num = min_t(int, io_sq_num, max_queue_ext->max_tx_sq_num); + io_cq_num = max_queue_ext->max_rx_cq_num; + io_cq_num = min_t(int, io_cq_num, max_queue_ext->max_tx_cq_num); + } else { + struct ena_admin_queue_feature_desc *max_queues = + &get_feat_ctx->max_queues; + io_sq_num = max_queues->max_sq_num; + io_cq_num = max_queues->max_cq_num; + } + io_queue_num = min_t(int, mp_ncpus, ENA_MAX_NUM_IO_QUEUES); io_queue_num = min_t(int, io_queue_num, io_sq_num); io_queue_num = min_t(int, io_queue_num, io_cq_num); @@ -3024,42 +3025,119 @@ ena_calc_io_queue_num(struct ena_adapter *adapter, } static int -ena_calc_queue_size(struct ena_adapter *adapter, uint16_t *max_tx_sgl_size, -uint16_t *max_rx_sgl_size, struct ena_com_dev_get_features_ctx *feat) +ena_calc_queue_size(struct ena_adapter *adapter, +struct ena_calc_queue_size_ctx *ctx) { - uint32_t queue_size = ENA_DEFAULT_RING_SIZE; - uint32_t v; - uint32_t q; + uint32_t tx_queue_size = ENA_DEFAULT_RING_SIZE; + uint32_t rx_queue_size = adapter->rx_ring_size; - queue_size = min_t(uint32_t, queue_size, - feat->max_queues.max_cq_depth); - queue_size = min_t(uint32_t, queue_size, - feat->max_queues.max_sq_depth); + if (ctx->ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) { +
svn commit: r348400 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:26:18 2019 New Revision: 348400 URL: https://svnweb.freebsd.org/changeset/base/348400 Log: Fix error in validate_tx_req_id() in ENA If the requested ID was out of range, the tx_info structure was NULL and the function was trying to access the field of the NULL object. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:24:47 2019(r348399) +++ head/sys/dev/ena/ena.c Thu May 30 13:26:18 2019(r348400) @@ -1203,14 +1203,11 @@ validate_tx_req_id(struct ena_ring *tx_ring, uint16_t tx_info = &tx_ring->tx_buffer_info[req_id]; if (tx_info->mbuf != NULL) return (0); - } - - if (tx_info->mbuf == NULL) device_printf(adapter->pdev, "tx_info doesn't have valid mbuf\n"); - else - device_printf(adapter->pdev, "Invalid req_id: %hu\n", req_id); + } + device_printf(adapter->pdev, "Invalid req_id: %hu\n", req_id); counter_u64_add(tx_ring->tx_stats.bad_req_id, 1); return (EFAULT); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348399 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:24:47 2019 New Revision: 348399 URL: https://svnweb.freebsd.org/changeset/base/348399 Log: Change attach order to prevent crash upon failure in ENA The if_detach was causing crash if the MSI-x configuration in the attach failed. To prevent this issue, the ifnet is being configured at the end of the attach function. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:22:53 2019(r348398) +++ head/sys/dev/ena/ena.c Thu May 30 13:24:47 2019(r348399) @@ -3819,18 +3819,18 @@ ena_attach(device_t pdev) device_printf(pdev, "initalize %d io queues\n", io_queue_num); ena_init_io_rings(adapter); - /* setup network interface */ - rc = ena_setup_ifnet(pdev, adapter, &get_feat_ctx); + rc = ena_enable_msix_and_set_admin_interrupts(adapter, io_queue_num); if (unlikely(rc != 0)) { - device_printf(pdev, "Error with network interface setup\n"); + device_printf(pdev, + "Failed to enable and set the admin interrupts\n"); goto err_io_free; } - rc = ena_enable_msix_and_set_admin_interrupts(adapter, io_queue_num); + /* setup network interface */ + rc = ena_setup_ifnet(pdev, adapter, &get_feat_ctx); if (unlikely(rc != 0)) { - device_printf(pdev, - "Failed to enable and set the admin interrupts\n"); - goto err_ifp_free; + device_printf(pdev, "Error with network interface setup\n"); + goto err_msix_free; } /* Initialize reset task queue */ @@ -3853,9 +3853,10 @@ ena_attach(device_t pdev) adapter->running = true; return (0); -err_ifp_free: - if_detach(adapter->ifp); - if_free(adapter->ifp); +err_msix_free: + ena_com_dev_reset(adapter->ena_dev, ENA_REGS_RESET_INIT_ERR); + ena_free_mgmnt_irq(adapter); + ena_disable_msix(adapter); err_io_free: ena_free_all_io_rings_resources(adapter); ena_free_rx_dma_tag(adapter); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348398 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:22:53 2019 New Revision: 348398 URL: https://svnweb.freebsd.org/changeset/base/348398 Log: Change order of ifp release on ENA detach In rare case, when the ifconfig is called just before kldunload, it is possible, that ena_up routine will be called after queue locks are released. To prevent that, ifp is detached before the last ena_down is called and further, the ifp is freed at the end of the function. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:22:12 2019(r348397) +++ head/sys/dev/ena/ena.c Thu May 30 13:22:53 2019(r348398) @@ -3893,6 +3893,8 @@ ena_detach(device_t pdev) return (EBUSY); } + ether_ifdetach(adapter->ifp); + /* Free reset task and callout */ callout_drain(&adapter->timer_service); while (taskqueue_cancel(adapter->reset_tq, &adapter->reset_task, NULL)) @@ -3903,11 +3905,6 @@ ena_detach(device_t pdev) ena_down(adapter); sx_unlock(&adapter->ioctl_sx); - if (adapter->ifp != NULL) { - ether_ifdetach(adapter->ifp); - if_free(adapter->ifp); - } - ena_free_all_io_rings_resources(adapter); ena_free_counters((counter_u64_t *)&adapter->hw_stats, @@ -3948,6 +3945,8 @@ ena_detach(device_t pdev) mtx_destroy(&adapter->global_mtx); sx_destroy(&adapter->ioctl_sx); + + if_free(adapter->ifp); if (ena_dev->bus != NULL) free(ena_dev->bus, M_DEVBUF); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348397 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:22:12 2019 New Revision: 348397 URL: https://svnweb.freebsd.org/changeset/base/348397 Log: Check for number of MSI-x upon partial allocation in ENA The ENA driver needs at least 2 MSI-x - one for admin queue, and one for IO queues pair. If there were not enough resources to allocate more than one MSI-x, the device should not be attached. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:20:42 2019(r348396) +++ head/sys/dev/ena/ena.c Thu May 30 13:22:12 2019(r348397) @@ -1865,6 +1865,14 @@ ena_enable_msix(struct ena_adapter *adapter) } if (msix_vecs != msix_req) { + if (msix_vecs == ENA_ADMIN_MSIX_VEC) { + device_printf(dev, + "Not enough number of MSI-x allocated: %d\n", + msix_vecs); + pci_release_msi(dev); + rc = ENOSPC; + goto err_msix_free; + } device_printf(dev, "Enable only %d MSI-x (out of %d), reduce " "the number of queues\n", msix_vecs, msix_req); adapter->num_queues = msix_vecs - ENA_ADMIN_MSIX_VEC; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348396 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:20:42 2019 New Revision: 348396 URL: https://svnweb.freebsd.org/changeset/base/348396 Log: Set error value when allocation of IO irq fails in ENA bus_alloc_resource_any() is not returning error value in case of an error. If the function call fails, the error value was not passed to the ena_up() function. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:19:32 2019(r348395) +++ head/sys/dev/ena/ena.c Thu May 30 13:20:42 2019(r348396) @@ -1998,6 +1998,7 @@ ena_request_io_irq(struct ena_adapter *adapter) irq->res = bus_alloc_resource_any(adapter->pdev, SYS_RES_IRQ, &irq->vector, flags); if (unlikely(irq->res == NULL)) { + rc = ENOMEM; device_printf(adapter->pdev, "could not allocate " "irq vector: %d\n", irq->vector); goto err; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348394 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:18:23 2019 New Revision: 348394 URL: https://svnweb.freebsd.org/changeset/base/348394 Log: Fix DMA synchronization in the ENA driver Tx and Rx paths The DMA in FreeBSD requires explicit synchronization. ENA driver was only doing PREREAD and PREWRITE synchronizations. Missing bus_dmamap_sync() calls were added. It is also required to synchronize DMA engine before unloading DMA map. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:16:56 2019(r348393) +++ head/sys/dev/ena/ena.c Thu May 30 13:18:23 2019(r348394) @@ -268,6 +268,9 @@ ena_dma_alloc(device_t dmadev, bus_size_t size, goto fail_map_load; } + bus_dmamap_sync(dma->tag, dma->map, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); + return (0); fail_map_load: @@ -678,12 +681,14 @@ ena_free_tx_resources(struct ena_adapter *adapter, int /* Free buffer DMA maps, */ for (int i = 0; i < tx_ring->ring_size; i++) { - m_freem(tx_ring->tx_buffer_info[i].mbuf); - tx_ring->tx_buffer_info[i].mbuf = NULL; + bus_dmamap_sync(adapter->tx_buf_tag, + tx_ring->tx_buffer_info[i].map, BUS_DMASYNC_POSTWRITE); bus_dmamap_unload(adapter->tx_buf_tag, tx_ring->tx_buffer_info[i].map); bus_dmamap_destroy(adapter->tx_buf_tag, tx_ring->tx_buffer_info[i].map); + m_freem(tx_ring->tx_buffer_info[i].mbuf); + tx_ring->tx_buffer_info[i].mbuf = NULL; } ENA_RING_MTX_UNLOCK(tx_ring); @@ -859,6 +864,8 @@ ena_free_rx_resources(struct ena_adapter *adapter, uns /* Free buffer DMA maps, */ for (int i = 0; i < rx_ring->ring_size; i++) { + bus_dmamap_sync(adapter->rx_buf_tag, + rx_ring->rx_buffer_info[i].map, BUS_DMASYNC_POSTREAD); m_freem(rx_ring->rx_buffer_info[i].mbuf); rx_ring->rx_buffer_info[i].mbuf = NULL; bus_dmamap_unload(adapter->rx_buf_tag, @@ -993,6 +1000,8 @@ ena_free_rx_mbuf(struct ena_adapter *adapter, struct e return; } + bus_dmamap_sync(adapter->rx_buf_tag, rx_info->map, + BUS_DMASYNC_POSTREAD); bus_dmamap_unload(adapter->rx_buf_tag, rx_info->map); m_freem(rx_info->mbuf); rx_info->mbuf = NULL; @@ -1134,6 +1143,8 @@ ena_free_tx_bufs(struct ena_adapter *adapter, unsigned qid, i); } + bus_dmamap_sync(adapter->tx_buf_tag, tx_info->map, + BUS_DMASYNC_POSTWRITE); bus_dmamap_unload(adapter->tx_buf_tag, tx_info->map); m_free(tx_info->mbuf); tx_info->mbuf = NULL; @@ -1334,6 +1345,8 @@ ena_tx_cleanup(struct ena_ring *tx_ring) if (likely(tx_info->num_of_bufs != 0)) { /* Map is no longer required */ + bus_dmamap_sync(adapter->tx_buf_tag, tx_info->map, + BUS_DMASYNC_POSTWRITE); bus_dmamap_unload(adapter->tx_buf_tag, tx_info->map); } @@ -1467,6 +1480,8 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r ena_trace(ENA_DBG | ENA_RXPTH, "rx_info %p, mbuf %p, paddr %jx", rx_info, rx_info->mbuf, (uintmax_t)rx_info->ena_buf.paddr); + bus_dmamap_sync(adapter->rx_buf_tag, rx_info->map, + BUS_DMASYNC_POSTREAD); mbuf = rx_info->mbuf; mbuf->m_flags |= M_PKTHDR; mbuf->m_pkthdr.len = len; @@ -1522,6 +1537,8 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r return (NULL); } + bus_dmamap_sync(adapter->rx_buf_tag, rx_info->map, + BUS_DMASYNC_POSTREAD); if (unlikely(m_append(mbuf, len, rx_info->mbuf->m_data) == 0)) { counter_u64_add(rx_ring->rx_stats.mbuf_alloc_fail, 1); ena_trace(ENA_WARNING, "Failed to append Rx mbuf %p", @@ -1632,6 +1649,8 @@ ena_rx_cleanup(struct ena_ring *rx_ring) ena_rx_ctx.ena_bufs = rx_ring->ena_bufs; ena_rx_ctx.max_bufs = adapter->max_rx_sgl_size; ena_rx_ctx.descs = 0; + bus_dmamap_sync(io_cq->cdesc_addr.mem_handle.tag, + io_cq->cdesc_addr.mem_handle.map, BUS_DMASYNC_POSTREAD); rc = ena_com_rx_pkt(io_cq, io_sq, &ena_rx_ctx); if (unlikely(rc != 0)) @@ -1648,7 +1667,8 @@ ena_rx_cleanup(struct ena_ring *rx_ring) /* Receive mbuf from the ring */ mbuf = ena_rx_mbuf(rx_ring, rx_ring-
svn commit: r348395 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:19:32 2019 New Revision: 348395 URL: https://svnweb.freebsd.org/changeset/base/348395 Log: Set vaddr and paddr as NULL when DMA alloc fails in ENA To prevent errors from assigning values from the DMA structure in case of an error, zero the vaddr and paddr values upon failure. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:18:23 2019(r348394) +++ head/sys/dev/ena/ena.c Thu May 30 13:19:32 2019(r348395) @@ -279,6 +279,8 @@ fail_map_create: bus_dma_tag_destroy(dma->tag); fail_tag: dma->tag = NULL; + dma->vaddr = NULL; + dma->paddr = 0; return (error); } ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348393 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:16:56 2019 New Revision: 348393 URL: https://svnweb.freebsd.org/changeset/base/348393 Log: Check for missing MSI-x and Tx completions in ENA If the first MSI-x won't be executed, then the timer service will detect that and trigger device reset. The checking for missing Tx completion was reworked, so it will also check for missing interrupts. Checking number of missing Tx completions can be performed after loop, instead of checking it every iteration. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c head/sys/dev/ena/ena.h Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:15:38 2019(r348392) +++ head/sys/dev/ena/ena.c Thu May 30 13:16:56 2019(r348393) @@ -405,6 +405,8 @@ ena_init_io_rings_common(struct ena_adapter *adapter, ring->qid = qid; ring->adapter = adapter; ring->ena_dev = adapter->ena_dev; + ring->first_interrupt = false; + ring->no_interrupt_event_cnt = 0; } static void @@ -1773,6 +1775,9 @@ ena_handle_msix(void *arg) ena_qid = ENA_IO_TXQ_IDX(qid); io_cq = &adapter->ena_dev->io_cq_queues[ena_qid]; + tx_ring->first_interrupt = true; + rx_ring->first_interrupt = true; + for (i = 0; i < CLEAN_BUDGET; ++i) { /* * If lock cannot be acquired, then deferred cleanup task was @@ -3329,13 +3334,37 @@ static void check_for_admin_com_state(struct ena_adapt } static int -check_missing_comp_in_queue(struct ena_adapter *adapter, +check_for_rx_interrupt_queue(struct ena_adapter *adapter, +struct ena_ring *rx_ring) +{ + if (likely(rx_ring->first_interrupt)) + return (0); + + if (ena_com_cq_empty(rx_ring->ena_com_io_cq)) + return (0); + + rx_ring->no_interrupt_event_cnt++; + + if (rx_ring->no_interrupt_event_cnt == ENA_MAX_NO_INTERRUPT_ITERATIONS) { + device_printf(adapter->pdev, "Potential MSIX issue on Rx side " + "Queue = %d. Reset the device\n", rx_ring->qid); + adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; + adapter->trigger_reset = true; + return (EIO); + } + + return (0); +} + +static int +check_missing_comp_in_tx_queue(struct ena_adapter *adapter, struct ena_ring *tx_ring) { struct bintime curtime, time; struct ena_tx_buffer *tx_buf; + sbintime_t time_offset; uint32_t missed_tx = 0; - int i; + int i, rc = 0; getbinuptime(&curtime); @@ -3347,9 +3376,24 @@ check_missing_comp_in_queue(struct ena_adapter *adapte time = curtime; bintime_sub(&time, &tx_buf->timestamp); + time_offset = bttosbt(time); + if (unlikely(!tx_ring->first_interrupt && + time_offset > 2 * adapter->missing_tx_timeout)) { + /* +* If after graceful period interrupt is still not +* received, we schedule a reset. +*/ + device_printf(adapter->pdev, + "Potential MSIX issue on Tx side Queue = %d. " + "Reset the device\n", tx_ring->qid); + adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; + adapter->trigger_reset = true; + return (EIO); + } + /* Check again if packet is still waiting */ - if (unlikely(bttosbt(time) > adapter->missing_tx_timeout)) { + if (unlikely(time_offset > adapter->missing_tx_timeout)) { if (!tx_buf->print_once) ena_trace(ENA_WARNING, "Found a Tx that wasn't " @@ -3358,24 +3402,22 @@ check_missing_comp_in_queue(struct ena_adapter *adapte tx_buf->print_once = true; missed_tx++; - counter_u64_add(tx_ring->tx_stats.missing_tx_comp, 1); - - if (unlikely(missed_tx > - adapter->missing_tx_threshold)) { - device_printf(adapter->pdev, - "The number of lost tx completion " - "is above the threshold (%d > %d). " - "Reset the device\n", - missed_tx, adapter->missing_tx_threshold); - adapter->reset_reason = - ENA_REGS_RESET_MISS_TX_CMPL; - adapter->trigger_reset = true; - return (EIO); - } }
svn commit: r348392 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:15:38 2019 New Revision: 348392 URL: https://svnweb.freebsd.org/changeset/base/348392 Log: Fill number of CPUs field on ENA host_info structure The new ena_com allows the number of CPUs to be passed to the device in the host info structure as a hint. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:14:58 2019(r348391) +++ head/sys/dev/ena/ena.c Thu May 30 13:15:38 2019(r348392) @@ -3130,6 +3130,7 @@ ena_config_host_info(struct ena_com_dev *ena_dev) (DRV_MODULE_VER_MAJOR) | (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) | (DRV_MODULE_VER_SUBMINOR << ENA_ADMIN_HOST_INFO_SUB_MINOR_SHIFT); + host_info->num_cpus = mp_ncpus; rc = ena_com_set_host_attributes(ena_dev); if (unlikely(rc != 0)) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348391 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:14:58 2019 New Revision: 348391 URL: https://svnweb.freebsd.org/changeset/base/348391 Log: Print ENA Tx error conditionally Information about Tx error should be only displayed, if packet preparation failed due to error other than out of memory. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:13:15 2019(r348390) +++ head/sys/dev/ena/ena.c Thu May 30 13:14:58 2019(r348391) @@ -2786,7 +2786,13 @@ ena_xmit_mbuf(struct ena_ring *tx_ring, struct mbuf ** /* Prepare the packet's descriptors and send them to device */ rc = ena_com_prepare_tx(io_sq, &ena_tx_ctx, &nb_hw_desc); if (unlikely(rc != 0)) { - ena_trace(ENA_DBG | ENA_TXPTH, "failed to prepare tx bufs\n"); + if (likely(rc == ENA_COM_NO_MEM)) { + ena_trace(ENA_DBG | ENA_TXPTH, + "tx ring[%d] if out of space\n", tx_ring->que->id); + } else { + device_printf(adapter->pdev, + "failed to prepare tx bufs\n"); + } counter_u64_add(tx_ring->tx_stats.prepare_ctx_err, 1); goto dma_error; } ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348390 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:13:15 2019 New Revision: 348390 URL: https://svnweb.freebsd.org/changeset/base/348390 Log: Trigger reset in ENA if there are too many Rx descriptors Whenever the driver will receive too many descriptors from the device, it should trigger the device reset, as it is indicating that the device is in invalid state. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:12:14 2019(r348389) +++ head/sys/dev/ena/ena.c Thu May 30 13:13:15 2019(r348390) @@ -1717,7 +1717,12 @@ ena_rx_cleanup(struct ena_ring *rx_ring) error: counter_u64_add(rx_ring->rx_stats.bad_desc_num, 1); - return (RX_BUDGET - budget); + + /* Too many desc from the device. Trigger reset */ + adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; + adapter->trigger_reset = true; + + return (0); } /* ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r348389 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:12:14 2019 New Revision: 348389 URL: https://svnweb.freebsd.org/changeset/base/348389 Log: Remove RSS support in ENA Receive Side Scaling is optional feature that could be enabled in kernel configuration by defining flag RSS. Kernel uses hash to store and find protocol control block which is stored in hash tables. Kernel and NIC hash functions must be consistent. Otherwise case lookup fails. To achieve this kernel provides API to set proper hash key to NIC. As it is not possible to change key for virtual ENA NIC, this driver cannot support RSS function. ENA is designed to work in virtual environments so supporting hardware version of this card is unnecessary. Submitted by: Rafal Kozik Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:09:53 2019(r348388) +++ head/sys/dev/ena/ena.c Thu May 30 13:12:14 2019(r348389) @@ -59,11 +59,9 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include @@ -585,9 +583,6 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in struct ena_que *que = &adapter->que[qid]; struct ena_ring *tx_ring = que->tx_ring; int size, i, err; -#ifdef RSS - cpuset_t cpu_mask; -#endif size = sizeof(struct ena_tx_buffer) * tx_ring->ring_size; @@ -638,16 +633,8 @@ ena_setup_tx_resources(struct ena_adapter *adapter, in goto err_buf_info_unmap; } - /* RSS set cpu for thread */ -#ifdef RSS - CPU_SETOF(que->cpu, &cpu_mask); - taskqueue_start_threads_cpuset(&tx_ring->enqueue_tq, 1, PI_NET, - &cpu_mask, "%s tx_ring enq (bucket %d)", - device_get_nameunit(adapter->pdev), que->cpu); -#else /* RSS */ taskqueue_start_threads(&tx_ring->enqueue_tq, 1, PI_NET, "%s txeq %d", device_get_nameunit(adapter->pdev), que->cpu); -#endif /* RSS */ return (0); @@ -780,9 +767,6 @@ ena_setup_rx_resources(struct ena_adapter *adapter, un struct ena_que *que = &adapter->que[qid]; struct ena_ring *rx_ring = que->rx_ring; int size, err, i; -#ifdef RSS - cpuset_t cpu_mask; -#endif size = sizeof(struct ena_rx_buffer) * rx_ring->ring_size; @@ -836,16 +820,8 @@ ena_setup_rx_resources(struct ena_adapter *adapter, un rx_ring->cmpl_tq = taskqueue_create_fast("ena RX completion", M_WAITOK, taskqueue_thread_enqueue, &rx_ring->cmpl_tq); - /* RSS set cpu for thread */ -#ifdef RSS - CPU_SETOF(que->cpu, &cpu_mask); - taskqueue_start_threads_cpuset(&rx_ring->cmpl_tq, 1, PI_NET, &cpu_mask, - "%s rx_ring cmpl (bucket %d)", - device_get_nameunit(adapter->pdev), que->cpu); -#else taskqueue_start_threads(&rx_ring->cmpl_tq, 1, PI_NET, "%s rx_ring cmpl %d", device_get_nameunit(adapter->pdev), que->cpu); -#endif return (0); @@ -1908,12 +1884,9 @@ ena_setup_io_intr(struct ena_adapter *adapter) adapter->msix_entries[irq_idx].vector; ena_trace(ENA_INFO | ENA_IOQ, "ena_setup_io_intr vector: %d\n", adapter->msix_entries[irq_idx].vector); -#ifdef RSS - adapter->que[i].cpu = adapter->irq_tbl[irq_idx].cpu = - rss_getcpu(i % rss_getnumbuckets()); -#else + /* -* We still want to bind rings to the corresponding cpu +* We want to bind rings to the corresponding cpu * using something similar to the RSS round-robin technique. */ if (unlikely(last_bind_cpu < 0)) @@ -1921,7 +1894,6 @@ ena_setup_io_intr(struct ena_adapter *adapter) adapter->que[i].cpu = adapter->irq_tbl[irq_idx].cpu = last_bind_cpu; last_bind_cpu = CPU_NEXT(last_bind_cpu); -#endif } } @@ -2010,13 +1982,8 @@ ena_request_io_irq(struct ena_adapter *adapter) } irq->requested = true; -#ifdef RSS - ena_trace(ENA_INFO, "queue %d - RSS bucket %d\n", - i - ENA_IO_IRQ_FIRST_IDX, irq->cpu); -#else ena_trace(ENA_INFO, "queue %d - cpu %d\n", i - ENA_IO_IRQ_FIRST_IDX, irq->cpu); -#endif } return (rc); @@ -2952,16 +2919,7 @@ ena_mq_start(if_t ifp, struct mbuf *m) * It should improve performance. */ if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) { -#ifdef RSS - if (rss_hash2bucket(m->m_pkthdr.flowid, - M_HASHTYPE_GET(m), &i) == 0) { - i = i % adapter->num_queues; - - } else -#endif - { - i =
svn commit: r348388 - head/sys/dev/ena
Author: mw Date: Thu May 30 13:09:53 2019 New Revision: 348388 URL: https://svnweb.freebsd.org/changeset/base/348388 Log: Add notification AENQ handler for ENA Notification AENQ handler is responsible for handling requests from ENA device. Missing Tx threshold, Tx timeout and keep alive timeout can be set using hints from the aenq descriptor which can be delivered in the ENA admin notification. The queue suspending and resuming tasks are not supported by the driver. Submitted by: Michal Krawczyk Obtained from: Semihalf Sponsored by: Amazon, Inc. Modified: head/sys/dev/ena/ena.c Modified: head/sys/dev/ena/ena.c == --- head/sys/dev/ena/ena.c Thu May 30 13:08:00 2019(r348387) +++ head/sys/dev/ena/ena.c Thu May 30 13:09:53 2019(r348388) @@ -3257,6 +3257,7 @@ ena_device_init(struct ena_adapter *adapter, device_t aenq_groups = BIT(ENA_ADMIN_LINK_CHANGE) | BIT(ENA_ADMIN_FATAL_ERROR) | BIT(ENA_ADMIN_WARNING) | + BIT(ENA_ADMIN_NOTIFICATION) | BIT(ENA_ADMIN_KEEP_ALIVE); aenq_groups &= get_feat_ctx->aenq.supported_groups; @@ -3338,7 +3339,7 @@ static void check_for_missing_keep_alive(struct ena_ad if (adapter->wd_active == 0) return; - if (likely(adapter->keep_alive_timeout == 0)) + if (adapter->keep_alive_timeout == ENA_HW_HINTS_NO_TIMEOUT) return; timestamp = atomic_load_acq_64(&adapter->keep_alive_timestamp); @@ -3436,7 +3437,7 @@ check_for_missing_tx_completions(struct ena_adapter *a if (adapter->trigger_reset) return; - if (adapter->missing_tx_timeout == 0) + if (adapter->missing_tx_timeout == ENA_HW_HINTS_NO_TIMEOUT) return; budget = adapter->missing_tx_max_queues; @@ -3506,6 +3507,42 @@ check_for_empty_rx_ring(struct ena_adapter *adapter) } } +static void ena_update_hints(struct ena_adapter *adapter, +struct ena_admin_ena_hw_hints *hints) +{ + struct ena_com_dev *ena_dev = adapter->ena_dev; + + if (hints->admin_completion_tx_timeout) + ena_dev->admin_queue.completion_timeout = + hints->admin_completion_tx_timeout * 1000; + + if (hints->mmio_read_timeout) + /* convert to usec */ + ena_dev->mmio_read.reg_read_to = + hints->mmio_read_timeout * 1000; + + if (hints->missed_tx_completion_count_threshold_to_reset) + adapter->missing_tx_threshold = + hints->missed_tx_completion_count_threshold_to_reset; + + if (hints->missing_tx_completion_timeout) { + if (hints->missing_tx_completion_timeout == +ENA_HW_HINTS_NO_TIMEOUT) + adapter->missing_tx_timeout = ENA_HW_HINTS_NO_TIMEOUT; + else + adapter->missing_tx_timeout = + SBT_1MS * hints->missing_tx_completion_timeout; + } + + if (hints->driver_watchdog_timeout) { + if (hints->driver_watchdog_timeout == ENA_HW_HINTS_NO_TIMEOUT) + adapter->keep_alive_timeout = ENA_HW_HINTS_NO_TIMEOUT; + else + adapter->keep_alive_timeout = + SBT_1MS * hints->driver_watchdog_timeout; + } +} + static void ena_timer_service(void *data) { @@ -3915,6 +3952,29 @@ ena_update_on_link_change(void *adapter_data, adapter->link_status = status; } +static void ena_notification(void *adapter_data, +struct ena_admin_aenq_entry *aenq_e) +{ + struct ena_adapter *adapter = (struct ena_adapter *)adapter_data; + struct ena_admin_ena_hw_hints *hints; + + ENA_WARN(aenq_e->aenq_common_desc.group != ENA_ADMIN_NOTIFICATION, + "Invalid group(%x) expected %x\n", aenq_e->aenq_common_desc.group, + ENA_ADMIN_NOTIFICATION); + + switch (aenq_e->aenq_common_desc.syndrom) { + case ENA_ADMIN_UPDATE_HINTS: + hints = + (struct ena_admin_ena_hw_hints *)(&aenq_e->inline_data_w4); + ena_update_hints(adapter, hints); + break; + default: + device_printf(adapter->pdev, + "Invalid aenq notification link state %d\n", + aenq_e->aenq_common_desc.syndrom); + } +} + /** * This handler will called for unknown event group or unimplemented handlers **/ @@ -3931,6 +3991,7 @@ unimplemented_aenq_handler(void *adapter_data, static struct ena_aenq_handlers aenq_handlers = { .handlers = { [ENA_ADMIN_LINK_CHANGE] = ena_update_on_link_change, + [ENA_ADMIN_NOTIFICATION] = ena_notification, [ENA_ADMIN_KEEP_ALIVE] = ena_keep_alive_wd, }, .unimplemented_handler = unimplemented_aenq