aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ena/ena_netmap.c
Commit message (Collapse)AuthorAgeFilesLines
* ena: Clear NS_MOREFRAG flag for last netmap slotOsama Abboud2024-10-151-1/+1
| | | | | | | | | | | | | | | | | | When processing packets within the rx-flow ena_netmap_rx_load_desc doesn't know the number of descriptors, so it sets NS_MOREFRAG to all the slots to indicate that there are more fragments for this packet. The code calls ena_netmap_rx_load_desc() for every descriptor in this packet to map the relevant buffer into the netmap shared memory. After ena_netmap_rx_load_desc() calls, we need to unset the NS_MOREFRAG for the last fragment to indicate that this is the last fragment, so we explicitly turn off NS_MOREFRAG flag. Current code overrides all other flags and sets NS_BUF_CHANGED. This patch unsets the relevant flag only. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Handle wrap around for prefetch in netmapOsama Abboud2024-10-151-3/+3
| | | | | | | | | | | | | Netmap index wraps around based on the number of netmap kernel ring slots. Currently the driver prefetches the next slot using nm_i + 1 which may be wrong since it does not handle wrap around. This patch fixes that by using the kernel API for fetching the next netmap index. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Properly unmap last socket chain in netmapOsama Abboud2024-10-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In case ena_com_prepare_tx() fails within the netmap tx flow, the driver will unmap the last socket chain. Currently, the driver unmaps the wrong socket within ena_netmap_unmap_last_socket_chain(). Illustration of the flow: 1- ena_netmap_tx_frames() 2- ena_netmap_tx_frame() 3- ena_netmap_tx_map_slots() 3.1- Map slot 3.2- Advance to the next socket 4- ena_com_prepare_tx() 4.1- ena_com_prepare_tx() fails 5- ena_netmap_unmap_last_socket_chain() In step 5, where the driver unmaps the socket, the netmap index already points at the next entry, meaning we're unmapping the wrong socket in case ena_com_prepare_tx() fails. In order to fix that, the driver should first update the netmap index to point at the previous entry and only then update the socket parameters. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Add reset reason for corrupted RX cdescsOsama Abboud2024-10-151-0/+2
| | | | | | | | | | | RX completion descriptors may sometimes contain errors due to corruption. Upon identifying such a case, the driver will trigger a reset with an explicit reset reason ENA_REGS_RESET_RX_DESCRIPTOR_MALFORMED. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Add reset reason for corrupted TX cdescsOsama Abboud2024-10-151-24/+14
| | | | | | | | | | | TX completion descriptors may sometimes contain errors due to corruption. Upon identifying such a case, the driver will trigger a reset with an explicit reset reason ENA_REGS_RESET_TX_DESCRIPTOR_MALFORMED. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Update license signatures to 2024Osama Abboud2024-10-151-1/+1
| | | | | | | | This commit updates all the license signatures to 2024. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Update the license dating to 2023Osama Abboud2023-12-281-1/+1
| | | | | | | | | Some of the files are using outdated linceses. Update the license to be 2023. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Remove CQ tail pointer update APIOsama Abboud2023-12-281-1/+0
| | | | | | | | | This commit removes the usage of this API from the freebsd driver since the relevant functionality is not supported by the device. Approved by: cperciva (mentor) MFC after: 2 weeks Sponsored by: Amazon, Inc.
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Mechanically convert ena(4) to DrvAPIJustin Hibbits2023-01-131-5/+5
| | | | | Reviewed by: mw Differential Revision: https://reviews.freebsd.org/D37837
* ena: Fix invalid KASSERT test in netmap codeMichal Krawczyk2022-06-301-1/+1
| | | | | | | | | The KASSERT was originally added to ensure that the netmap Rx ring is not NULL, however, it was checking for the opposite. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Align names of constantsDawid Gorecki2022-06-301-1/+1
| | | | | | | | | | Most of the constants in ena.h file were prefixed with ENA_*, while others did not have this prefix. Align the constants by prefixing the remaining constants with ENA. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Fix styling issuesDawid Gorecki2022-06-301-77/+63
| | | | | | | | Align code style with FreeBSD style(9) guidelines. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Extend debug prints for invalid req_id resetsDawid Gorecki2022-06-301-1/+2
| | | | | | | | | Print information about qid if req_id is invalid. Add information about qid and req_id if mbuf is invalid. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Add ena_ring_tx_doorbell() functionDawid Gorecki2022-06-301-8/+3
| | | | | | | | Add ena_ring_tx_doorbell function to remove code duplication. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Remove unused variable.John Baldwin2022-04-061-2/+0
|
* ena: Share ena_global_lock between driver instancesArtur Rojek2021-09-011-2/+2
| | | | | | | | | | | | | | | | | In order to use `ena_global_lock` in sysctl context, it must be kept outside the driver instance's software context, as sysctls can be called before attach and after detach, leading to lock use before sx_init and after sx_destroy otherwise. Solve this issue by turning `ena_global_lock` into a file scope variable, shared between all instances of the driver and associated sysctl context, and in turn initialized/destroyed in dedicated SYSINIT/SYSUNINIT functions. As a side effect, this change also fixes existing race in the reset routine, when simultaneously accessing sysctl exposed properties. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Disable meta descriptor caching for netmapArtur Rojek2021-09-011-0/+1
| | | | | | | | | | | | | If LLQ is being used, `ena_tx_ctx.meta_valid` must stay enabled. This fixes netmap support on latest generation ENA HW and aligns it with the core driver behavior. As netmap doesn't support any csum offloads, the `adapter->disable_meta_caching` value can be simply passed to the HW. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* ena: Trigger reset on ena_com_prepare_tx failureArtur Rojek2021-09-011-0/+2
| | | | | | | | | All ena_com_prepare_tx errors other than ENA_COM_NO_MEM are fatal and require device reset. Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc.
* Merge tag 'vendor/ena-com/2.4.0'Marcin Wojtas2021-06-241-34/+39
| | | | | | | | | | | | | Update the driver in order not to break its compilation and make use of the new ENA logging system Migrate platform code to the new logging system provided by ena_com layer. Make ENA_INFO the new default log level. Remove all explicit use of `device_printf`, all new logs requiring one of the log macros to be used.
* Add SPDX license tag to the ENA driver filesMarcin Wojtas2020-11-181-1/+1
| | | | | | | | | | | | | | | | | | 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 <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27117 Notes: svn path=/head/; revision=367801
* Adjust ENA driver files to latest ena-com changesMarcin Wojtas2020-11-181-28/+31
| | | | | | | | | | | | | | | | | * 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 <idose@amazon.com> Submitted by: Michal Krawczyk <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27115 Notes: svn path=/head/; revision=367799
* Update ENA driver version to v2.2.0Marcin Wojtas2020-05-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | 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 <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=361530
* Create ENA IO queues with optional backoffMarcin Wojtas2020-05-261-2/+2
| | | | | | | | | | | | 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 <mba@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=361526
* Rework ENA Rx queue size configurationMarcin Wojtas2020-05-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=361521
* Use single global lock in the ENA driverMarcin Wojtas2020-05-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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 <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=361516
* Add trigger reset function in the ENA driverMarcin Wojtas2020-05-261-4/+3
| | | | | | | | | | | | | | 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 <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=361515
* Adjust ENA driver to the new HALMarcin Wojtas2020-05-261-2/+0
| | | | | | | | | | | | | | | | | | * 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 <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=361511
* Add support for ENA NETMAP partial initializationMarcin Wojtas2019-10-311-5/+61
| | | | | | | | | | | | | | | | | 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 <rk@semihalf.com> Michal Krawczyk <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=354224
* Add support for ENA NETMAP TxMarcin Wojtas2019-10-311-1/+600
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two new tables are added to ena_tx_buffer structure: * netmap_map_seg stores DMA mapping structures, * netmap_buf_idx stores buff indexes taken from the slots. When Tx resources are being set, the new mapping structures are created and netmap Tx rings are being reset. When Tx resources are being released, used netmap bufs are unmapped from DMA and then mapping structures are destroyed. When Tx interrupt occurrs, ena_netmap_tx_irq is called. ena_netmap_txsync callback signalizes that there are new packets which should be transmitted. First, it fills ena_netmap_ctx. Then it performs two actions: * ena_netmap_tx_frames moves packets from netmap ring to NIC, * ena_netmap_tx_cleanup restores buffers from NIC and gives them back to the userspace app. 0 is returned in case of Tx error that could be handled by the driver. ena_netmap_tx_frames checks if there are packets ready for transmission. Then, for each of them, ena_netmap_tx_frame is called. If error occurs, transmitting is stopped, but if the error was cause due to HW ring being full, information about that is not propagated to the userspace app. When all packets are ready, doorbell is written to NIC and netmap ring state is updated. Parsing of one packet is done by the ena_netmap_tx_frame function. First, it checks if number of slots does not exceed NIC limit. Invalid packets are being dropped and the error is propagated to the upper layer. As each netmap buffer has equal size, which is typically greater then 2KiB, there shouldn't be any packets which contain too many slots. Then, the ena_com_tx_ctx structure is being filled. As netmap does not support any hardware offloads, ena_com_tx_meta structure is set to zero. After that, ena_netmap_map_slots maps all memory slots for DMA. If the device works in the LLQ mode, the push header is being determined by checking if the header fits within the first socket. If so, the portion of data is being copied directly from the slot. In other case, the data is copied to the intermediate buffer. First slots are treated the same as as the others, because DMA mapping has no impact on LLQ mode. Index of each netmap buffer is taken from slot and stored in netmap_buf_idx array. In case of mapping error, memory is unmapped and packets are put back to the netmap ring. ena_netmap_tx_cleanup performs out of order cleanup of sent buffers. First, req_id is taken and is validated. As validate_tx_req_id from ena.c is specific to kernels mbuf, another implementation is provided. Each req_id is cleaned up by ena_netmap_tx_clean_one function. Buffers are being unmaped from DMA and put back to netmap ring. In the end, state of netmap and NIC rings are being updated. Differential Revision: https://reviews.freebsd.org/D21936 Submitted by: Rafal Kozik <rk@semihalf.com> Michal Krawczyk <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=354223
* Add support for ENA NETMAP RxMarcin Wojtas2019-10-311-1/+330
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <rk@semihalf.com> Michal Krawczyk <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=354222
* Introduce NETMAP support in ENAMarcin Wojtas2019-10-311-0/+111
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 <rk@semihalf.com> Michal Krawczyk <mk@semihalf.com> Obtained from: Semihalf Sponsored by: Amazon, Inc. Notes: svn path=/head/; revision=354221