LCOV - code coverage report
Current view: top level - drivers/net/enetc - enetc.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 4 0.0 %
Date: 2025-11-01 17:50:34 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 10 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2018-2019,2024 NXP
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _ENETC_H_
       6                 :            : #define _ENETC_H_
       7                 :            : 
       8                 :            : #include <rte_time.h>
       9                 :            : #include <ethdev_pci.h>
      10                 :            : 
      11                 :            : #include "compat.h"
      12                 :            : #include "base/enetc_hw.h"
      13                 :            : #include "base/enetc4_hw.h"
      14                 :            : #include "enetc_logs.h"
      15                 :            : #include "ntmp.h"
      16                 :            : 
      17                 :            : #define PCI_VENDOR_ID_FREESCALE 0x1957
      18                 :            : 
      19                 :            : /* Max TX rings per ENETC. */
      20                 :            : #define MAX_TX_RINGS    2
      21                 :            : 
      22                 :            : /* Max RX rings per ENTEC. */
      23                 :            : #define MAX_RX_RINGS    1
      24                 :            : 
      25                 :            : /* Max BD counts per Ring. */
      26                 :            : #define MAX_BD_COUNT   64000
      27                 :            : /* Min BD counts per Ring. */
      28                 :            : #define MIN_BD_COUNT   32
      29                 :            : /* BD ALIGN */
      30                 :            : #define BD_ALIGN       8
      31                 :            : 
      32                 :            : /* minimum frame size supported */
      33                 :            : #define ENETC_MAC_MINFRM_SIZE   68
      34                 :            : /* maximum frame size supported */
      35                 :            : #define ENETC_MAC_MAXFRM_SIZE   9600
      36                 :            : 
      37                 :            : /* The max frame size with default MTU */
      38                 :            : #define ENETC_ETH_MAX_LEN (RTE_ETHER_MTU + \
      39                 :            :                 RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)
      40                 :            : 
      41                 :            : /* eth name size */
      42                 :            : #define ENETC_ETH_NAMESIZE      20
      43                 :            : 
      44                 :            : #define ENETC_DEFAULT_MSG_SIZE  1024    /* max size */
      45                 :            : 
      46                 :            : /* Message length is in multiple of 32 bytes */
      47                 :            : #define ENETC_VSI_PSI_MSG_SIZE  32
      48                 :            : 
      49                 :            : /* size for marking hugepage non-cacheable */
      50                 :            : #define SIZE_2MB        0x200000
      51                 :            : 
      52                 :            : #define ENETC_TXBD(BDR, i) (&(((struct enetc_tx_bd *)((BDR).bd_base))[i]))
      53                 :            : #define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
      54                 :            : 
      55                 :            : #define ENETC4_MBUF_F_TX_IP_IPV4 (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_IPV4)
      56                 :            : #define ENETC4_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM | \
      57                 :            :                                     RTE_MBUF_F_TX_TCP_CKSUM | \
      58                 :            :                                     RTE_MBUF_F_TX_UDP_CKSUM)
      59                 :            : 
      60                 :            : #define ENETC_CBD(R, i) (&(((struct enetc_cbd *)((R).bd_base))[i]))
      61                 :            : #define ENETC_CBDR_TIMEOUT      1000 /* In multiple of ENETC_CBDR_DELAY */
      62                 :            : #define ENETC_CBDR_DELAY        100 /* usecs */
      63                 :            : #define ENETC_CBDR_SIZE         64
      64                 :            : #define ENETC_CBDR_ALIGN        128
      65                 :            : 
      66                 :            : /* supported RSS */
      67                 :            : #define ENETC_RSS_OFFLOAD_ALL ( \
      68                 :            :         RTE_ETH_RSS_IP | \
      69                 :            :         RTE_ETH_RSS_UDP | \
      70                 :            :         RTE_ETH_RSS_TCP)
      71                 :            : 
      72                 :            : struct enetc_swbd {
      73                 :            :         struct rte_mbuf *buffer_addr;
      74                 :            : };
      75                 :            : 
      76                 :            : struct enetc_bdr {
      77                 :            :         void *bd_base;                  /* points to Rx or Tx BD ring */
      78                 :            :         struct enetc_swbd *q_swbd;
      79                 :            :         union {
      80                 :            :                 void *tcir;
      81                 :            :                 void *rcir;
      82                 :            :         };
      83                 :            :         int bd_count; /* # of BDs */
      84                 :            :         int next_to_use;
      85                 :            :         int next_to_clean;
      86                 :            :         uint16_t index;
      87                 :            :         uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */
      88                 :            :         union {
      89                 :            :                 void *tcisr; /* Tx */
      90                 :            :                 int next_to_alloc; /* Rx */
      91                 :            :         };
      92                 :            :         struct rte_mempool *mb_pool;   /* mbuf pool to populate RX ring. */
      93                 :            :         struct rte_eth_dev *ndev;
      94                 :            :         uint64_t ierrors;
      95                 :            :         uint8_t rx_deferred_start;
      96                 :            :         uint8_t tx_deferred_start;
      97                 :            : };
      98                 :            : 
      99                 :            : struct enetc_eth_hw {
     100                 :            :         struct rte_eth_dev *ndev;
     101                 :            :         struct enetc_hw hw;
     102                 :            :         uint16_t device_id;
     103                 :            :         uint16_t vendor_id;
     104                 :            :         uint8_t revision_id;
     105                 :            :         struct enetc_eth_mac_info mac;
     106                 :            :         struct netc_cbdr cbdr;
     107                 :            :         uint32_t num_rss;
     108                 :            :         uint32_t max_rx_queues;
     109                 :            :         uint32_t max_tx_queues;
     110                 :            : };
     111                 :            : 
     112                 :            : /*
     113                 :            :  * Structure to store private data for each driver instance (for each port).
     114                 :            :  */
     115                 :            : struct enetc_eth_adapter {
     116                 :            :         struct rte_eth_dev *ndev;
     117                 :            :         struct enetc_eth_hw hw;
     118                 :            : };
     119                 :            : 
     120                 :            : #define ENETC_DEV_PRIVATE(adapter) \
     121                 :            :         ((struct enetc_eth_adapter *)adapter)
     122                 :            : 
     123                 :            : #define ENETC_DEV_PRIVATE_TO_HW(adapter) \
     124                 :            :         (&((struct enetc_eth_adapter *)adapter)->hw)
     125                 :            : 
     126                 :            : #define ENETC_DEV_PRIVATE_TO_STATS(adapter) \
     127                 :            :         (&((struct enetc_eth_adapter *)adapter)->stats)
     128                 :            : 
     129                 :            : #define ENETC_DEV_PRIVATE_TO_INTR(adapter) \
     130                 :            :         (&((struct enetc_eth_adapter *)adapter)->intr)
     131                 :            : 
     132                 :            : /* Class ID for PSI-TO-VSI messages */
     133                 :            : #define ENETC_MSG_CLASS_ID_CMD_SUCCESS          0x1
     134                 :            : #define ENETC_MSG_CLASS_ID_PERMISSION_DENY      0x2
     135                 :            : #define ENETC_MSG_CLASS_ID_CMD_NOT_SUPPORT      0x3
     136                 :            : #define ENETC_MSG_CLASS_ID_PSI_BUSY             0x4
     137                 :            : #define ENETC_MSG_CLASS_ID_CRC_ERROR            0x5
     138                 :            : #define ENETC_MSG_CLASS_ID_PROTO_NOT_SUPPORT    0x6
     139                 :            : #define ENETC_MSG_CLASS_ID_INVALID_MSG_LEN      0x7
     140                 :            : #define ENETC_MSG_CLASS_ID_CMD_TIMEOUT          0x8
     141                 :            : #define ENETC_MSG_CLASS_ID_CMD_DEFERED          0xf
     142                 :            : 
     143                 :            : #define ENETC_PROMISC_DISABLE                   0x41
     144                 :            : #define ENETC_PROMISC_ENABLE                    0x43
     145                 :            : #define ENETC_ALLMULTI_PROMISC_DIS              0x81
     146                 :            : #define ENETC_ALLMULTI_PROMISC_EN               0x83
     147                 :            : 
     148                 :            : #define ENETC_PROMISC_VLAN_DISABLE              0x1
     149                 :            : #define ENETC_PROMISC_VLAN_ENABLE               0x3
     150                 :            : 
     151                 :            : /* Enum for class IDs */
     152                 :            : enum enetc_msg_cmd_class_id {
     153                 :            :         ENETC_CLASS_ID_MAC_FILTER = 0x20,
     154                 :            :         ENETC_CLASS_ID_VLAN_FILTER = 0x21,
     155                 :            :         ENETC_CLASS_ID_LINK_STATUS = 0x80,
     156                 :            :         ENETC_CLASS_ID_LINK_SPEED = 0x81
     157                 :            : };
     158                 :            : 
     159                 :            : /* Enum for command IDs */
     160                 :            : enum enetc_msg_cmd_id {
     161                 :            :         ENETC_CMD_ID_SET_PRIMARY_MAC = 0,
     162                 :            :         ENETC_MSG_ADD_EXACT_MAC_ENTRIES = 1,
     163                 :            :         ENETC_CMD_ID_SET_MAC_PROMISCUOUS = 5,
     164                 :            :         ENETC_MSG_ADD_EXACT_VLAN_ENTRIES = 0,
     165                 :            :         ENETC_MSG_REMOVE_EXACT_VLAN_ENTRIES = 1,
     166                 :            :         ENETC_CMD_ID_SET_VLAN_PROMISCUOUS = 4,
     167                 :            :         ENETC_CMD_ID_GET_LINK_STATUS = 0,
     168                 :            :         ENETC_CMD_ID_REGISTER_LINK_NOTIF = 1,
     169                 :            :         ENETC_CMD_ID_UNREGISTER_LINK_NOTIF = 2,
     170                 :            :         ENETC_CMD_ID_GET_LINK_SPEED = 0
     171                 :            : };
     172                 :            : 
     173                 :            : enum mac_addr_status {
     174                 :            :         ENETC_INVALID_MAC_ADDR = 0x0,
     175                 :            :         ENETC_DUPLICATE_MAC_ADDR = 0X1,
     176                 :            :         ENETC_MAC_ADDR_NOT_FOUND = 0X2,
     177                 :            :         ENETC_MAC_FILTER_NO_RESOURCE = 0x3
     178                 :            : };
     179                 :            : 
     180                 :            : enum vlan_status {
     181                 :            :         ENETC_INVALID_VLAN_ENTRY = 0x0,
     182                 :            :         ENETC_DUPLICATE_VLAN_ENTRY = 0X1,
     183                 :            :         ENETC_VLAN_ENTRY_NOT_FOUND = 0x2,
     184                 :            :         ENETC_VLAN_NO_RESOURCE = 0x3
     185                 :            : };
     186                 :            : 
     187                 :            : enum link_status {
     188                 :            :         ENETC_LINK_UP = 0x0,
     189                 :            :         ENETC_LINK_DOWN = 0x1
     190                 :            : };
     191                 :            : 
     192                 :            : enum speed {
     193                 :            :         ENETC_SPEED_UNKNOWN = 0x0,
     194                 :            :         ENETC_SPEED_10_HALF_DUPLEX = 0x1,
     195                 :            :         ENETC_SPEED_10_FULL_DUPLEX = 0x2,
     196                 :            :         ENETC_SPEED_100_HALF_DUPLEX = 0x3,
     197                 :            :         ENETC_SPEED_100_FULL_DUPLEX = 0x4,
     198                 :            :         ENETC_SPEED_1000 = 0x5,
     199                 :            :         ENETC_SPEED_2500 = 0x6,
     200                 :            :         ENETC_SPEED_5000 = 0x7,
     201                 :            :         ENETC_SPEED_10G = 0x8,
     202                 :            :         ENETC_SPEED_25G = 0x9,
     203                 :            :         ENETC_SPEED_50G = 0xA,
     204                 :            :         ENETC_SPEED_100G = 0xB,
     205                 :            :         ENETC_SPEED_NOT_SUPPORTED = 0xF
     206                 :            : };
     207                 :            : 
     208                 :            : /* PSI-VSI command header format */
     209                 :            : struct enetc_msg_cmd_header {
     210                 :            :         uint16_t csum;          /* INET_CHECKSUM */
     211                 :            :         uint8_t class_id;       /* Command class type */
     212                 :            :         uint8_t cmd_id;         /* Denotes the specific required action */
     213                 :            :         uint8_t proto_ver;      /* Supported VSI-PSI command protocol version */
     214                 :            :         uint8_t len;            /* Extended message body length */
     215                 :            :         uint8_t reserved_1;
     216                 :            :         uint8_t cookie; /* Control command execution asynchronously on PSI side */
     217                 :            :         uint64_t reserved_2;
     218                 :            : };
     219                 :            : 
     220                 :            : /* VF-PF set primary MAC address message format */
     221                 :            : struct enetc_msg_cmd_set_primary_mac {
     222                 :            :         struct enetc_msg_cmd_header header;
     223                 :            :         uint8_t count;  /* number of MAC addresses */
     224                 :            :         uint8_t reserved_1;
     225                 :            :         uint16_t reserved_2;
     226                 :            :         struct rte_ether_addr addr;
     227                 :            : };
     228                 :            : 
     229                 :            : struct enetc_msg_cmd_set_promisc {
     230                 :            :         struct enetc_msg_cmd_header header;
     231                 :            :         uint8_t op_type;
     232                 :            : };
     233                 :            : 
     234                 :            : struct enetc_msg_cmd_get_link_status {
     235                 :            :         struct enetc_msg_cmd_header header;
     236                 :            : };
     237                 :            : 
     238                 :            : struct enetc_msg_cmd_get_link_speed {
     239                 :            :         struct enetc_msg_cmd_header header;
     240                 :            : };
     241                 :            : 
     242                 :            : struct enetc_msg_cmd_set_vlan_promisc {
     243                 :            :         struct enetc_msg_cmd_header header;
     244                 :            :         uint8_t op;
     245                 :            :         uint8_t reserved;
     246                 :            : };
     247                 :            : 
     248                 :            : struct enetc_msg_vlan_exact_filter {
     249                 :            :         struct enetc_msg_cmd_header header;
     250                 :            :         uint8_t vlan_count;
     251                 :            :         uint8_t reserved_1;
     252                 :            :         uint16_t reserved_2;
     253                 :            :         uint16_t vlan_id;
     254                 :            :         uint8_t tpid;
     255                 :            :         uint8_t reserved2;
     256                 :            : };
     257                 :            : 
     258                 :            : struct enetc_psi_reply_msg {
     259                 :            :         uint8_t class_id;
     260                 :            :         uint8_t status;
     261                 :            : };
     262                 :            : 
     263                 :            : /* msg size encoding: default and max msg value of 1024B encoded as 0 */
     264                 :            : static inline uint32_t enetc_vsi_set_msize(uint32_t size)
     265                 :            : {
     266         [ #  # ]:          0 :         return size < ENETC_DEFAULT_MSG_SIZE ? size >> 5 : 0;
     267                 :            : }
     268                 :            : 
     269                 :            : /*
     270                 :            :  * ENETC4 function prototypes
     271                 :            :  */
     272                 :            : int enetc4_pci_remove(struct rte_pci_device *pci_dev);
     273                 :            : int enetc4_dev_configure(struct rte_eth_dev *dev);
     274                 :            : int enetc4_dev_close(struct rte_eth_dev *dev);
     275                 :            : int enetc4_dev_infos_get(struct rte_eth_dev *dev,
     276                 :            :                          struct rte_eth_dev_info *dev_info);
     277                 :            : int enetc4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
     278                 :            :                           uint16_t nb_rx_desc, unsigned int socket_id __rte_unused,
     279                 :            :                           const struct rte_eth_rxconf *rx_conf,
     280                 :            :                           struct rte_mempool *mb_pool);
     281                 :            : int enetc4_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx);
     282                 :            : int enetc4_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx);
     283                 :            : void enetc4_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
     284                 :            : int enetc4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
     285                 :            :                           uint16_t nb_desc, unsigned int socket_id __rte_unused,
     286                 :            :                           const struct rte_eth_txconf *tx_conf);
     287                 :            : int enetc4_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx);
     288                 :            : int enetc4_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx);
     289                 :            : void enetc4_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
     290                 :            : const uint32_t *enetc4_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
     291                 :            :                         size_t *no_of_elements);
     292                 :            : 
     293                 :            : /*
     294                 :            :  * enetc4_vf function prototype
     295                 :            :  */
     296                 :            : int enetc4_vf_dev_stop(struct rte_eth_dev *dev);
     297                 :            : int enetc4_vf_dev_intr(struct rte_eth_dev *eth_dev, bool enable);
     298                 :            : 
     299                 :            : /*
     300                 :            :  * RX/TX ENETC function prototypes
     301                 :            :  */
     302                 :            : uint16_t enetc_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts,
     303                 :            :                 uint16_t nb_pkts);
     304                 :            : uint16_t enetc_xmit_pkts_nc(void *txq, struct rte_mbuf **tx_pkts,
     305                 :            :                 uint16_t nb_pkts);
     306                 :            : uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts,
     307                 :            :                 uint16_t nb_pkts);
     308                 :            : uint16_t enetc_recv_pkts_nc(void *rxq, struct rte_mbuf **rx_pkts,
     309                 :            :                 uint16_t nb_pkts);
     310                 :            : 
     311                 :            : int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt);
     312                 :            : void enetc4_dev_hw_init(struct rte_eth_dev *eth_dev);
     313                 :            : void enetc_print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr);
     314                 :            : 
     315                 :            : static inline int
     316                 :            : enetc_bd_unused(struct enetc_bdr *bdr)
     317                 :            : {
     318   [ #  #  #  #  :          0 :         if (bdr->next_to_clean > bdr->next_to_use)
             #  #  #  # ]
     319                 :          0 :                 return bdr->next_to_clean - bdr->next_to_use - 1;
     320                 :            : 
     321                 :          0 :         return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1;
     322                 :            : }
     323                 :            : 
     324                 :            : /* CBDR prototypes */
     325                 :            : int enetc4_setup_cbdr(struct rte_eth_dev *dev, struct enetc_hw *hw,
     326                 :            :                         int bd_count, struct netc_cbdr *cbdr);
     327                 :            : void enetc_free_cbdr(struct netc_cbdr *cbdr);
     328                 :            : int enetc_ntmp_rsst_query_or_update_entry(struct netc_cbdr *cbdr, uint32_t *table,
     329                 :            :                         int count, bool query);
     330                 :            : 
     331                 :            : #endif /* _ENETC_H_ */

Generated by: LCOV version 1.14