1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2019-2021 Xilinx, Inc. 4 * Copyright(c) 2017-2019 Solarflare Communications Inc. 5 * 6 * This software was jointly developed between OKTET Labs (under contract 7 * for Solarflare) and Solarflare Communications, Inc. 8 */ 9 10 #ifndef _SFC_DP_H 11 #define _SFC_DP_H 12 13 #include <stdbool.h> 14 #include <sys/queue.h> 15 16 #include <rte_pci.h> 17 18 #include "sfc_log.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #define SFC_DIV_ROUND_UP(a, b) \ 25 __extension__ ({ \ 26 typeof(a) _a = (a); \ 27 typeof(b) _b = (b); \ 28 \ 29 (_a + (_b - 1)) / _b; \ 30 }) 31 32 /** 33 * Datapath exception handler to be provided by the control path. 34 */ 35 typedef void (sfc_dp_exception_t)(void *ctrl); 36 37 enum sfc_dp_type { 38 SFC_DP_RX = 0, /**< Receive datapath */ 39 SFC_DP_TX, /**< Transmit datapath */ 40 }; 41 42 43 /** Datapath queue run-time information */ 44 struct sfc_dp_queue { 45 uint16_t port_id; 46 uint16_t queue_id; 47 struct rte_pci_addr pci_addr; 48 }; 49 50 void sfc_dp_queue_init(struct sfc_dp_queue *dpq, 51 uint16_t port_id, uint16_t queue_id, 52 const struct rte_pci_addr *pci_addr); 53 54 /* Maximum datapath log level to be included in build. */ 55 #ifndef SFC_DP_LOG_LEVEL 56 #define SFC_DP_LOG_LEVEL RTE_LOG_NOTICE 57 #endif 58 59 /* 60 * Helper macro to define datapath logging macros and have uniform 61 * logging. 62 */ 63 #define SFC_DP_LOG(dp_name, level, dpq, ...) \ 64 do { \ 65 const struct sfc_dp_queue *_dpq = (dpq); \ 66 const struct rte_pci_addr *_addr = &(_dpq)->pci_addr; \ 67 \ 68 if (RTE_LOG_ ## level > SFC_DP_LOG_LEVEL) \ 69 break; \ 70 SFC_GENERIC_LOG(level, \ 71 RTE_FMT("%s " PCI_PRI_FMT \ 72 " #%" PRIu16 ".%" PRIu16 ": " \ 73 RTE_FMT_HEAD(__VA_ARGS__ ,), \ 74 dp_name, \ 75 _addr->domain, _addr->bus, \ 76 _addr->devid, _addr->function, \ 77 _dpq->port_id, _dpq->queue_id, \ 78 RTE_FMT_TAIL(__VA_ARGS__,))); \ 79 } while (0) 80 81 82 /** Datapath definition */ 83 struct sfc_dp { 84 TAILQ_ENTRY(sfc_dp) links; 85 const char *name; 86 enum sfc_dp_type type; 87 /* Mask of required hardware/firmware capabilities */ 88 unsigned int hw_fw_caps; 89 #define SFC_DP_HW_FW_CAP_EF10 0x1 90 #define SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER 0x2 91 #define SFC_DP_HW_FW_CAP_RX_EFX 0x4 92 #define SFC_DP_HW_FW_CAP_TX_EFX 0x8 93 #define SFC_DP_HW_FW_CAP_EF100 0x10 94 }; 95 96 /** List of datapath variants */ 97 TAILQ_HEAD(sfc_dp_list, sfc_dp); 98 99 /* Check if available HW/FW capabilities are sufficient for the datapath */ 100 static inline bool 101 sfc_dp_match_hw_fw_caps(const struct sfc_dp *dp, unsigned int avail_caps) 102 { 103 return (dp->hw_fw_caps & avail_caps) == dp->hw_fw_caps; 104 } 105 106 struct sfc_dp *sfc_dp_find_by_name(struct sfc_dp_list *head, 107 enum sfc_dp_type type, const char *name); 108 struct sfc_dp *sfc_dp_find_by_caps(struct sfc_dp_list *head, 109 enum sfc_dp_type type, 110 unsigned int avail_caps); 111 int sfc_dp_register(struct sfc_dp_list *head, struct sfc_dp *entry); 112 113 #ifdef __cplusplus 114 } 115 #endif 116 #endif /* _SFC_DP_H */ 117