LCOV - code coverage report
Current view: top level - drivers/net/enetc - enetc_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 388 0.5 %
Date: 2026-08-01 17:54:00 Functions: 2 34 5.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 109 0.9 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2018-2026 NXP
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdbool.h>
       6                 :            : #include <rte_random.h>
       7                 :            : #include <dpaax_iova_table.h>
       8                 :            : 
       9                 :            : #include "enetc_logs.h"
      10                 :            : #include "enetc.h"
      11                 :            : 
      12                 :            : static int
      13                 :          0 : enetc_dev_start(struct rte_eth_dev *dev)
      14                 :            : {
      15                 :            :         struct enetc_eth_hw *hw =
      16                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
      17                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
      18                 :            :         uint32_t val;
      19                 :            :         uint16_t i;
      20                 :            : 
      21                 :          0 :         PMD_INIT_FUNC_TRACE();
      22         [ #  # ]:          0 :         if (hw->device_id == ENETC_DEV_ID_VF)
      23                 :            :                 return 0;
      24                 :            : 
      25                 :          0 :         val = enetc_port_rd(enetc_hw, ENETC_PM0_CMD_CFG);
      26                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PM0_CMD_CFG,
      27                 :            :                       val | ENETC_PM0_TX_EN | ENETC_PM0_RX_EN);
      28                 :            : 
      29                 :            :         /* Enable port */
      30                 :          0 :         val = enetc_port_rd(enetc_hw, ENETC_PMR);
      31                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PMR, val | ENETC_PMR_EN);
      32                 :            : 
      33                 :            :         /* set auto-speed for RGMII */
      34         [ #  # ]:          0 :         if (enetc_port_rd(enetc_hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG) {
      35                 :          0 :                 enetc_port_wr(enetc_hw, ENETC_PM0_IF_MODE,
      36                 :            :                               ENETC_PM0_IFM_RGAUTO);
      37                 :          0 :                 enetc_port_wr(enetc_hw, ENETC_PM1_IF_MODE,
      38                 :            :                               ENETC_PM0_IFM_RGAUTO);
      39                 :            :         }
      40         [ #  # ]:          0 :         if (enetc_global_rd(enetc_hw,
      41                 :            :                             ENETC_G_EPFBLPR(1)) == ENETC_G_EPFBLPR1_XGMII) {
      42                 :          0 :                 enetc_port_wr(enetc_hw, ENETC_PM0_IF_MODE,
      43                 :            :                               ENETC_PM0_IFM_XGMII);
      44                 :          0 :                 enetc_port_wr(enetc_hw, ENETC_PM1_IF_MODE,
      45                 :            :                               ENETC_PM0_IFM_XGMII);
      46                 :            :         }
      47                 :            : 
      48         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
      49                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
      50         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
      51                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
      52                 :            : 
      53                 :            :         return 0;
      54                 :            : }
      55                 :            : 
      56                 :            : static int
      57                 :          0 : enetc_dev_stop(struct rte_eth_dev *dev)
      58                 :            : {
      59                 :            :         struct enetc_eth_hw *hw =
      60                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
      61                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
      62                 :            :         uint32_t val;
      63                 :            :         uint16_t i;
      64                 :            : 
      65                 :          0 :         PMD_INIT_FUNC_TRACE();
      66                 :          0 :         dev->data->dev_started = 0;
      67         [ #  # ]:          0 :         if (hw->device_id == ENETC_DEV_ID_VF)
      68                 :            :                 return 0;
      69                 :            : 
      70                 :            :         /* Disable port */
      71                 :          0 :         val = enetc_port_rd(enetc_hw, ENETC_PMR);
      72                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PMR, val & (~ENETC_PMR_EN));
      73                 :            : 
      74                 :          0 :         val = enetc_port_rd(enetc_hw, ENETC_PM0_CMD_CFG);
      75                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PM0_CMD_CFG,
      76                 :            :                       val & (~(ENETC_PM0_TX_EN | ENETC_PM0_RX_EN)));
      77                 :            : 
      78         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
      79                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
      80         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
      81                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
      82                 :            : 
      83                 :            :         return 0;
      84                 :            : }
      85                 :            : 
      86                 :            : static const uint32_t *
      87                 :          0 : enetc_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
      88                 :            :                            size_t *no_of_elements)
      89                 :            : {
      90                 :            :         static const uint32_t ptypes[] = {
      91                 :            :                 RTE_PTYPE_L2_ETHER,
      92                 :            :                 RTE_PTYPE_L3_IPV4,
      93                 :            :                 RTE_PTYPE_L3_IPV6,
      94                 :            :                 RTE_PTYPE_L4_TCP,
      95                 :            :                 RTE_PTYPE_L4_UDP,
      96                 :            :                 RTE_PTYPE_L4_SCTP,
      97                 :            :                 RTE_PTYPE_L4_ICMP,
      98                 :            :                 RTE_PTYPE_TUNNEL_ESP
      99                 :            :         };
     100                 :            : 
     101                 :          0 :         *no_of_elements = RTE_DIM(ptypes);
     102                 :          0 :         return ptypes;
     103                 :            : }
     104                 :            : 
     105                 :            : /* return 0 means link status changed, -1 means not changed */
     106                 :            : static int
     107                 :          0 : enetc_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
     108                 :            : {
     109                 :            :         struct enetc_eth_hw *hw =
     110                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     111                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     112                 :            :         struct rte_eth_link link;
     113                 :            :         uint32_t status;
     114                 :            : 
     115                 :          0 :         PMD_INIT_FUNC_TRACE();
     116                 :            : 
     117                 :            :         memset(&link, 0, sizeof(link));
     118                 :            : 
     119                 :          0 :         status = enetc_port_rd(enetc_hw, ENETC_PM0_STATUS);
     120                 :            : 
     121         [ #  # ]:          0 :         if (status & ENETC_LINK_MODE)
     122                 :          0 :                 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
     123                 :            :         else
     124                 :          0 :                 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
     125                 :            : 
     126         [ #  # ]:          0 :         if (status & ENETC_LINK_STATUS)
     127                 :          0 :                 link.link_status = RTE_ETH_LINK_UP;
     128                 :            :         else
     129                 :          0 :                 link.link_status = RTE_ETH_LINK_DOWN;
     130                 :            : 
     131      [ #  #  # ]:          0 :         switch (status & ENETC_LINK_SPEED_MASK) {
     132                 :          0 :         case ENETC_LINK_SPEED_1G:
     133                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_1G;
     134                 :          0 :                 break;
     135                 :            : 
     136                 :          0 :         case ENETC_LINK_SPEED_100M:
     137                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_100M;
     138                 :          0 :                 break;
     139                 :            : 
     140                 :          0 :         default:
     141                 :            :         case ENETC_LINK_SPEED_10M:
     142                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_10M;
     143                 :            :         }
     144                 :            : 
     145                 :          0 :         return rte_eth_linkstatus_set(dev, &link);
     146                 :            : }
     147                 :            : 
     148                 :            : void
     149                 :          0 : enetc_print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
     150                 :            : {
     151                 :            :         char buf[RTE_ETHER_ADDR_FMT_SIZE];
     152                 :            : 
     153                 :          0 :         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
     154                 :          0 :         ENETC_PMD_NOTICE("%s%s", name, buf);
     155                 :          0 : }
     156                 :            : 
     157                 :            : static int
     158                 :          0 : enetc_hardware_init(struct enetc_eth_hw *hw)
     159                 :            : {
     160                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     161                 :          0 :         uint32_t *mac = (uint32_t *)hw->mac.addr;
     162                 :            :         uint32_t high_mac = 0;
     163                 :            :         uint16_t low_mac = 0;
     164                 :            : 
     165                 :          0 :         PMD_INIT_FUNC_TRACE();
     166                 :            :         /* Calculating and storing the base HW addresses */
     167                 :          0 :         hw->hw.port = (void *)((size_t)hw->hw.reg + ENETC_PORT_BASE);
     168                 :          0 :         hw->hw.global = (void *)((size_t)hw->hw.reg + ENETC_GLOBAL_BASE);
     169                 :            : 
     170                 :            :         /* WA for Rx lock-up HW erratum */
     171                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PM0_RX_FIFO, 1);
     172                 :            : 
     173                 :            :         /* set ENETC transaction flags to coherent, don't allocate.
     174                 :            :          * BD writes merge with surrounding cache line data, frame data writes
     175                 :            :          * overwrite cache line.
     176                 :            :          */
     177                 :          0 :         enetc_wr(enetc_hw, ENETC_SICAR0, ENETC_SICAR0_COHERENT);
     178                 :            : 
     179                 :            :         /* Enabling Station Interface */
     180                 :          0 :         enetc_wr(enetc_hw, ENETC_SIMR, ENETC_SIMR_EN);
     181                 :            : 
     182                 :            : 
     183         [ #  # ]:          0 :         if (hw->device_id == ENETC_DEV_ID_VF) {
     184                 :          0 :                 *mac = (uint32_t)enetc_rd(enetc_hw, ENETC_SIPMAR0);
     185                 :            :                 high_mac = (uint32_t)*mac;
     186                 :            :                 mac++;
     187                 :          0 :                 *mac = (uint32_t)enetc_rd(enetc_hw, ENETC_SIPMAR1);
     188                 :          0 :                 low_mac = (uint16_t)*mac;
     189                 :            :         } else {
     190                 :          0 :                 *mac = (uint32_t)enetc_port_rd(enetc_hw, ENETC_PSIPMAR0(0));
     191                 :            :                 high_mac = (uint32_t)*mac;
     192                 :            :                 mac++;
     193                 :          0 :                 *mac = (uint16_t)enetc_port_rd(enetc_hw, ENETC_PSIPMAR1(0));
     194                 :            :                 low_mac = (uint16_t)*mac;
     195                 :            :         }
     196                 :            : 
     197         [ #  # ]:          0 :         if ((high_mac | low_mac) == 0) {
     198                 :          0 :                 ENETC_PMD_NOTICE("MAC is not available for this SI, "
     199                 :            :                                 "set random MAC");
     200                 :          0 :                 rte_eth_random_addr(hw->mac.addr);
     201                 :          0 :                 high_mac = *(uint32_t *)hw->mac.addr;
     202                 :          0 :                 low_mac = *(uint16_t *)(hw->mac.addr + 4);
     203         [ #  # ]:          0 :                 if (hw->device_id == ENETC_DEV_ID_VF) {
     204                 :          0 :                         enetc_wr(enetc_hw, ENETC_SIPMAR0, high_mac);
     205                 :          0 :                         enetc_wr(enetc_hw, ENETC_SIPMAR1, low_mac);
     206                 :            :                 } else {
     207                 :          0 :                         enetc_port_wr(enetc_hw, ENETC_PSIPMAR0(0), high_mac);
     208                 :          0 :                         enetc_port_wr(enetc_hw, ENETC_PSIPMAR1(0), low_mac);
     209                 :            :                 }
     210                 :          0 :                 enetc_print_ethaddr("New address: ",
     211                 :            :                               (const struct rte_ether_addr *)hw->mac.addr);
     212                 :            :         }
     213                 :            : 
     214                 :          0 :         return 0;
     215                 :            : }
     216                 :            : 
     217                 :            : static int
     218                 :          0 : enetc_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
     219                 :            :                     struct rte_eth_dev_info *dev_info)
     220                 :            : {
     221                 :          0 :         PMD_INIT_FUNC_TRACE();
     222                 :          0 :         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
     223                 :            :                 .nb_max = MAX_BD_COUNT,
     224                 :            :                 .nb_min = MIN_BD_COUNT,
     225                 :            :                 .nb_align = BD_ALIGN,
     226                 :            :         };
     227                 :          0 :         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
     228                 :            :                 .nb_max = MAX_BD_COUNT,
     229                 :            :                 .nb_min = MIN_BD_COUNT,
     230                 :            :                 .nb_align = BD_ALIGN,
     231                 :            :         };
     232                 :          0 :         dev_info->max_rx_queues = MAX_RX_RINGS;
     233                 :          0 :         dev_info->max_tx_queues = MAX_TX_RINGS;
     234                 :          0 :         dev_info->max_rx_pktlen = ENETC_MAC_MAXFRM_SIZE;
     235                 :          0 :         dev_info->rx_offload_capa =
     236                 :            :                 (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
     237                 :            :                  RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
     238                 :            :                  RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
     239                 :            :                  RTE_ETH_RX_OFFLOAD_KEEP_CRC);
     240                 :            : 
     241                 :          0 :         return 0;
     242                 :            : }
     243                 :            : 
     244                 :            : static int
     245                 :          0 : enetc_alloc_txbdr(struct enetc_bdr *txr, uint16_t nb_desc)
     246                 :            : {
     247                 :            :         int size;
     248                 :            : 
     249                 :          0 :         size = nb_desc * sizeof(struct enetc_swbd);
     250                 :          0 :         txr->q_swbd = rte_malloc(NULL, size, ENETC_BD_RING_ALIGN);
     251         [ #  # ]:          0 :         if (txr->q_swbd == NULL)
     252                 :            :                 return -ENOMEM;
     253                 :            : 
     254                 :          0 :         size = nb_desc * sizeof(struct enetc_tx_bd);
     255                 :          0 :         txr->bd_base = rte_malloc(NULL, size, ENETC_BD_RING_ALIGN);
     256         [ #  # ]:          0 :         if (txr->bd_base == NULL) {
     257                 :          0 :                 rte_free(txr->q_swbd);
     258                 :          0 :                 txr->q_swbd = NULL;
     259                 :          0 :                 return -ENOMEM;
     260                 :            :         }
     261                 :            : 
     262                 :          0 :         txr->bd_count = nb_desc;
     263                 :          0 :         txr->next_to_clean = 0;
     264                 :          0 :         txr->next_to_use = 0;
     265                 :            : 
     266                 :          0 :         return 0;
     267                 :            : }
     268                 :            : 
     269                 :            : static void
     270                 :            : enetc_free_bdr(struct enetc_bdr *rxr)
     271                 :            : {
     272                 :          0 :         rte_free(rxr->q_swbd);
     273                 :          0 :         rte_free(rxr->bd_base);
     274                 :          0 :         rxr->q_swbd = NULL;
     275                 :          0 :         rxr->bd_base = NULL;
     276                 :            : }
     277                 :            : 
     278                 :            : static void
     279                 :          0 : enetc_setup_txbdr(struct enetc_hw *hw, struct enetc_bdr *tx_ring)
     280                 :            : {
     281                 :          0 :         int idx = tx_ring->index;
     282                 :            :         phys_addr_t bd_address;
     283                 :            : 
     284                 :            :         bd_address = (phys_addr_t)
     285                 :          0 :                      rte_mem_virt2iova((const void *)tx_ring->bd_base);
     286                 :          0 :         enetc_txbdr_wr(hw, idx, ENETC_TBBAR0,
     287                 :            :                        lower_32_bits((uint64_t)bd_address));
     288                 :          0 :         enetc_txbdr_wr(hw, idx, ENETC_TBBAR1,
     289                 :            :                        upper_32_bits((uint64_t)bd_address));
     290                 :          0 :         enetc_txbdr_wr(hw, idx, ENETC_TBLENR,
     291                 :            :                        ENETC_RTBLENR_LEN(tx_ring->bd_count));
     292                 :            : 
     293                 :          0 :         enetc_txbdr_wr(hw, idx, ENETC_TBCIR, 0);
     294                 :          0 :         enetc_txbdr_wr(hw, idx, ENETC_TBCISR, 0);
     295                 :          0 :         tx_ring->tcir = (void *)((size_t)hw->reg +
     296                 :            :                         ENETC_BDR(TX, idx, ENETC_TBCIR));
     297                 :          0 :         tx_ring->tcisr = (void *)((size_t)hw->reg +
     298                 :            :                          ENETC_BDR(TX, idx, ENETC_TBCISR));
     299                 :          0 : }
     300                 :            : 
     301                 :            : static int
     302                 :          0 : enetc_tx_queue_setup(struct rte_eth_dev *dev,
     303                 :            :                      uint16_t queue_idx,
     304                 :            :                      uint16_t nb_desc,
     305                 :            :                      unsigned int socket_id __rte_unused,
     306                 :            :                      const struct rte_eth_txconf *tx_conf)
     307                 :            : {
     308                 :            :         int err = 0;
     309                 :            :         struct enetc_bdr *tx_ring;
     310                 :          0 :         struct rte_eth_dev_data *data = dev->data;
     311                 :          0 :         struct enetc_eth_adapter *priv =
     312                 :            :                         ENETC_DEV_PRIVATE(data->dev_private);
     313                 :            : 
     314                 :          0 :         PMD_INIT_FUNC_TRACE();
     315         [ #  # ]:          0 :         if (nb_desc > MAX_BD_COUNT)
     316                 :            :                 return -1;
     317                 :            : 
     318                 :          0 :         tx_ring = rte_zmalloc(NULL, sizeof(struct enetc_bdr), 0);
     319         [ #  # ]:          0 :         if (tx_ring == NULL) {
     320                 :          0 :                 ENETC_PMD_ERR("Failed to allocate TX ring memory");
     321                 :            :                 err = -ENOMEM;
     322                 :          0 :                 return -1;
     323                 :            :         }
     324                 :            : 
     325                 :          0 :         err = enetc_alloc_txbdr(tx_ring, nb_desc);
     326         [ #  # ]:          0 :         if (err)
     327                 :          0 :                 goto fail;
     328                 :            : 
     329                 :          0 :         tx_ring->index = queue_idx;
     330                 :          0 :         tx_ring->ndev = dev;
     331                 :          0 :         enetc_setup_txbdr(&priv->hw.hw, tx_ring);
     332                 :          0 :         data->tx_queues[queue_idx] = tx_ring;
     333                 :            : 
     334         [ #  # ]:          0 :         if (!tx_conf->tx_deferred_start) {
     335                 :            :                 /* enable ring */
     336                 :          0 :                 enetc_txbdr_wr(&priv->hw.hw, tx_ring->index,
     337                 :            :                                ENETC_TBMR, ENETC_TBMR_EN);
     338                 :          0 :                 dev->data->tx_queue_state[tx_ring->index] =
     339                 :            :                                RTE_ETH_QUEUE_STATE_STARTED;
     340                 :            :         } else {
     341                 :          0 :                 dev->data->tx_queue_state[tx_ring->index] =
     342                 :            :                                RTE_ETH_QUEUE_STATE_STOPPED;
     343                 :            :         }
     344                 :            : 
     345                 :            :         return 0;
     346                 :            : fail:
     347                 :          0 :         rte_free(tx_ring);
     348                 :            : 
     349                 :          0 :         return err;
     350                 :            : }
     351                 :            : 
     352                 :            : static void
     353                 :          0 : enetc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
     354                 :            : {
     355                 :          0 :         void *txq = dev->data->tx_queues[qid];
     356                 :            : 
     357         [ #  # ]:          0 :         if (txq == NULL)
     358                 :            :                 return;
     359                 :            : 
     360                 :            :         struct enetc_bdr *tx_ring = (struct enetc_bdr *)txq;
     361                 :            :         struct enetc_eth_hw *eth_hw =
     362                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(tx_ring->ndev->data->dev_private);
     363                 :            :         struct enetc_hw *hw;
     364                 :            :         struct enetc_swbd *tx_swbd;
     365                 :            :         int i;
     366                 :            :         uint32_t val;
     367                 :            : 
     368                 :            :         /* Disable the ring */
     369                 :            :         hw = &eth_hw->hw;
     370                 :          0 :         val = enetc_txbdr_rd(hw, tx_ring->index, ENETC_TBMR);
     371                 :          0 :         val &= (~ENETC_TBMR_EN);
     372                 :          0 :         enetc_txbdr_wr(hw, tx_ring->index, ENETC_TBMR, val);
     373                 :            : 
     374                 :            :         /* clean the ring*/
     375                 :          0 :         i = tx_ring->next_to_clean;
     376                 :          0 :         tx_swbd = &tx_ring->q_swbd[i];
     377         [ #  # ]:          0 :         while (tx_swbd->buffer_addr != NULL) {
     378                 :          0 :                 rte_pktmbuf_free(tx_swbd->buffer_addr);
     379                 :          0 :                 tx_swbd->buffer_addr = NULL;
     380                 :          0 :                 tx_swbd++;
     381                 :          0 :                 i++;
     382         [ #  # ]:          0 :                 if (unlikely(i == tx_ring->bd_count)) {
     383                 :            :                         i = 0;
     384                 :          0 :                         tx_swbd = &tx_ring->q_swbd[i];
     385                 :            :                 }
     386                 :            :         }
     387                 :            : 
     388                 :            :         enetc_free_bdr(tx_ring);
     389                 :          0 :         rte_free(tx_ring);
     390                 :            : }
     391                 :            : 
     392                 :            : static int
     393                 :          0 : enetc_alloc_rxbdr(struct enetc_bdr *rxr,
     394                 :            :                   uint16_t nb_rx_desc)
     395                 :            : {
     396                 :            :         int size;
     397                 :            : 
     398                 :          0 :         size = nb_rx_desc * sizeof(struct enetc_swbd);
     399                 :          0 :         rxr->q_swbd = rte_malloc(NULL, size, ENETC_BD_RING_ALIGN);
     400         [ #  # ]:          0 :         if (rxr->q_swbd == NULL)
     401                 :            :                 return -ENOMEM;
     402                 :            : 
     403                 :          0 :         size = nb_rx_desc * sizeof(union enetc_rx_bd);
     404                 :          0 :         rxr->bd_base = rte_malloc(NULL, size, ENETC_BD_RING_ALIGN);
     405         [ #  # ]:          0 :         if (rxr->bd_base == NULL) {
     406                 :          0 :                 rte_free(rxr->q_swbd);
     407                 :          0 :                 rxr->q_swbd = NULL;
     408                 :          0 :                 return -ENOMEM;
     409                 :            :         }
     410                 :            : 
     411                 :          0 :         rxr->bd_count = nb_rx_desc;
     412                 :          0 :         rxr->next_to_clean = 0;
     413                 :          0 :         rxr->next_to_use = 0;
     414                 :          0 :         rxr->next_to_alloc = 0;
     415                 :            : 
     416                 :          0 :         return 0;
     417                 :            : }
     418                 :            : 
     419                 :            : static void
     420                 :          0 : enetc_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring,
     421                 :            :                   struct rte_mempool *mb_pool)
     422                 :            : {
     423                 :          0 :         int idx = rx_ring->index;
     424                 :            :         uint16_t buf_size;
     425                 :            :         phys_addr_t bd_address;
     426                 :            : 
     427                 :            :         bd_address = (phys_addr_t)
     428                 :          0 :                      rte_mem_virt2iova((const void *)rx_ring->bd_base);
     429                 :          0 :         enetc_rxbdr_wr(hw, idx, ENETC_RBBAR0,
     430                 :            :                        lower_32_bits((uint64_t)bd_address));
     431                 :          0 :         enetc_rxbdr_wr(hw, idx, ENETC_RBBAR1,
     432                 :            :                        upper_32_bits((uint64_t)bd_address));
     433                 :          0 :         enetc_rxbdr_wr(hw, idx, ENETC_RBLENR,
     434                 :            :                        ENETC_RTBLENR_LEN(rx_ring->bd_count));
     435                 :            : 
     436                 :          0 :         rx_ring->mb_pool = mb_pool;
     437                 :          0 :         rx_ring->rcir = (void *)((size_t)hw->reg +
     438         [ #  # ]:          0 :                         ENETC_BDR(RX, idx, ENETC_RBCIR));
     439                 :          0 :         enetc_refill_rx_ring(rx_ring, (enetc_bd_unused(rx_ring)));
     440         [ #  # ]:          0 :         buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rx_ring->mb_pool) -
     441                 :            :                    RTE_PKTMBUF_HEADROOM);
     442                 :          0 :         enetc_rxbdr_wr(hw, idx, ENETC_RBBSR, buf_size);
     443                 :          0 :         enetc_rxbdr_wr(hw, idx, ENETC_RBPIR, 0);
     444                 :          0 : }
     445                 :            : 
     446                 :            : static int
     447                 :          0 : enetc_rx_queue_setup(struct rte_eth_dev *dev,
     448                 :            :                      uint16_t rx_queue_id,
     449                 :            :                      uint16_t nb_rx_desc,
     450                 :            :                      unsigned int socket_id __rte_unused,
     451                 :            :                      const struct rte_eth_rxconf *rx_conf,
     452                 :            :                      struct rte_mempool *mb_pool)
     453                 :            : {
     454                 :            :         int err = 0;
     455                 :            :         struct enetc_bdr *rx_ring;
     456                 :          0 :         struct rte_eth_dev_data *data =  dev->data;
     457                 :          0 :         struct enetc_eth_adapter *adapter =
     458                 :            :                         ENETC_DEV_PRIVATE(data->dev_private);
     459                 :          0 :         uint64_t rx_offloads = data->dev_conf.rxmode.offloads;
     460                 :            : 
     461                 :          0 :         PMD_INIT_FUNC_TRACE();
     462         [ #  # ]:          0 :         if (nb_rx_desc > MAX_BD_COUNT)
     463                 :            :                 return -1;
     464                 :            : 
     465                 :          0 :         rx_ring = rte_zmalloc(NULL, sizeof(struct enetc_bdr), 0);
     466         [ #  # ]:          0 :         if (rx_ring == NULL) {
     467                 :          0 :                 ENETC_PMD_ERR("Failed to allocate RX ring memory");
     468                 :            :                 err = -ENOMEM;
     469                 :          0 :                 return err;
     470                 :            :         }
     471                 :            : 
     472                 :          0 :         err = enetc_alloc_rxbdr(rx_ring, nb_rx_desc);
     473         [ #  # ]:          0 :         if (err)
     474                 :          0 :                 goto fail;
     475                 :            : 
     476                 :          0 :         rx_ring->index = rx_queue_id;
     477                 :          0 :         rx_ring->ndev = dev;
     478                 :          0 :         enetc_setup_rxbdr(&adapter->hw.hw, rx_ring, mb_pool);
     479                 :          0 :         data->rx_queues[rx_queue_id] = rx_ring;
     480                 :            : 
     481         [ #  # ]:          0 :         if (!rx_conf->rx_deferred_start) {
     482                 :            :                 /* enable ring */
     483                 :          0 :                 enetc_rxbdr_wr(&adapter->hw.hw, rx_ring->index, ENETC_RBMR,
     484                 :            :                                ENETC_RBMR_EN);
     485                 :          0 :                 dev->data->rx_queue_state[rx_ring->index] =
     486                 :            :                                RTE_ETH_QUEUE_STATE_STARTED;
     487                 :            :         } else {
     488                 :          0 :                 dev->data->rx_queue_state[rx_ring->index] =
     489                 :            :                                RTE_ETH_QUEUE_STATE_STOPPED;
     490                 :            :         }
     491                 :            : 
     492                 :          0 :         rx_ring->crc_len = (uint8_t)((rx_offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) ?
     493                 :            :                                      RTE_ETHER_CRC_LEN : 0);
     494                 :            : 
     495                 :          0 :         return 0;
     496                 :            : fail:
     497                 :          0 :         rte_free(rx_ring);
     498                 :            : 
     499                 :          0 :         return err;
     500                 :            : }
     501                 :            : 
     502                 :            : static void
     503                 :          0 : enetc_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
     504                 :            : {
     505                 :          0 :         void *rxq = dev->data->rx_queues[qid];
     506                 :            : 
     507         [ #  # ]:          0 :         if (rxq == NULL)
     508                 :            :                 return;
     509                 :            : 
     510                 :            :         struct enetc_bdr *rx_ring = (struct enetc_bdr *)rxq;
     511                 :            :         struct enetc_eth_hw *eth_hw =
     512                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(rx_ring->ndev->data->dev_private);
     513                 :            :         struct enetc_swbd *q_swbd;
     514                 :            :         struct enetc_hw *hw;
     515                 :            :         uint32_t val;
     516                 :            :         int i;
     517                 :            : 
     518                 :            :         /* Disable the ring */
     519                 :            :         hw = &eth_hw->hw;
     520                 :          0 :         val = enetc_rxbdr_rd(hw, rx_ring->index, ENETC_RBMR);
     521                 :          0 :         val &= (~ENETC_RBMR_EN);
     522                 :          0 :         enetc_rxbdr_wr(hw, rx_ring->index, ENETC_RBMR, val);
     523                 :            : 
     524                 :            :         /* Clean the ring */
     525                 :          0 :         i = rx_ring->next_to_clean;
     526                 :          0 :         q_swbd = &rx_ring->q_swbd[i];
     527         [ #  # ]:          0 :         while (i != rx_ring->next_to_use) {
     528                 :          0 :                 rte_pktmbuf_free(q_swbd->buffer_addr);
     529                 :          0 :                 q_swbd->buffer_addr = NULL;
     530                 :          0 :                 q_swbd++;
     531                 :          0 :                 i++;
     532         [ #  # ]:          0 :                 if (unlikely(i == rx_ring->bd_count)) {
     533                 :            :                         i = 0;
     534                 :          0 :                         q_swbd = &rx_ring->q_swbd[i];
     535                 :            :                 }
     536                 :            :         }
     537                 :            : 
     538                 :            :         enetc_free_bdr(rx_ring);
     539                 :          0 :         rte_free(rx_ring);
     540                 :            : }
     541                 :            : 
     542                 :            : static
     543                 :          0 : int enetc_stats_get(struct rte_eth_dev *dev,
     544                 :            :                     struct rte_eth_stats *stats,
     545                 :            :                     struct eth_queue_stats *qstats __rte_unused)
     546                 :            : {
     547                 :            :         struct enetc_eth_hw *hw =
     548                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     549                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     550                 :            : 
     551                 :            :         /* Total received packets, bad + good, if we want to get counters of
     552                 :            :          * only good received packets then use ENETC_PM0_RFRM,
     553                 :            :          * ENETC_PM0_TFRM registers.
     554                 :            :          */
     555                 :          0 :         stats->ipackets = enetc_port_rd(enetc_hw, ENETC_PM0_RPKT);
     556                 :          0 :         stats->opackets = enetc_port_rd(enetc_hw, ENETC_PM0_TPKT);
     557                 :          0 :         stats->ibytes =  enetc_port_rd(enetc_hw, ENETC_PM0_REOCT);
     558                 :          0 :         stats->obytes = enetc_port_rd(enetc_hw, ENETC_PM0_TEOCT);
     559                 :            :         /* Dropped + Truncated packets, use ENETC_PM0_RDRNTP for without
     560                 :            :          * truncated packets
     561                 :            :          */
     562                 :          0 :         stats->imissed = enetc_port_rd(enetc_hw, ENETC_PM0_RDRP);
     563                 :          0 :         stats->ierrors = enetc_port_rd(enetc_hw, ENETC_PM0_RERR);
     564                 :          0 :         stats->oerrors = enetc_port_rd(enetc_hw, ENETC_PM0_TERR);
     565                 :            : 
     566                 :          0 :         return 0;
     567                 :            : }
     568                 :            : 
     569                 :            : static int
     570                 :          0 : enetc_stats_reset(struct rte_eth_dev *dev)
     571                 :            : {
     572                 :            :         struct enetc_eth_hw *hw =
     573                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     574                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     575                 :            : 
     576                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PM0_STAT_CONFIG, ENETC_CLEAR_STATS);
     577                 :            : 
     578                 :          0 :         return 0;
     579                 :            : }
     580                 :            : 
     581                 :            : static int
     582                 :          0 : enetc_dev_close(struct rte_eth_dev *dev)
     583                 :            : {
     584                 :            :         uint16_t i;
     585                 :            :         int ret;
     586                 :            : 
     587                 :          0 :         PMD_INIT_FUNC_TRACE();
     588         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     589                 :            :                 return 0;
     590                 :            : 
     591                 :          0 :         ret = enetc_dev_stop(dev);
     592                 :            : 
     593         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
     594                 :          0 :                 enetc_rx_queue_release(dev, i);
     595                 :          0 :                 dev->data->rx_queues[i] = NULL;
     596                 :            :         }
     597                 :          0 :         dev->data->nb_rx_queues = 0;
     598                 :            : 
     599         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
     600                 :          0 :                 enetc_tx_queue_release(dev, i);
     601                 :          0 :                 dev->data->tx_queues[i] = NULL;
     602                 :            :         }
     603                 :          0 :         dev->data->nb_tx_queues = 0;
     604                 :            : 
     605         [ #  # ]:          0 :         if (rte_eal_iova_mode() == RTE_IOVA_PA)
     606                 :          0 :                 dpaax_iova_table_depopulate();
     607                 :            : 
     608                 :            :         return ret;
     609                 :            : }
     610                 :            : 
     611                 :            : static int
     612                 :          0 : enetc_promiscuous_enable(struct rte_eth_dev *dev)
     613                 :            : {
     614                 :            :         struct enetc_eth_hw *hw =
     615                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     616                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     617                 :            :         uint32_t psipmr = 0;
     618                 :            : 
     619                 :          0 :         psipmr = enetc_port_rd(enetc_hw, ENETC_PSIPMR);
     620                 :            : 
     621                 :            :         /* Setting to enable promiscuous mode*/
     622                 :          0 :         psipmr |= ENETC_PSIPMR_SET_UP(0) | ENETC_PSIPMR_SET_MP(0);
     623                 :            : 
     624                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PSIPMR, psipmr);
     625                 :            : 
     626                 :          0 :         return 0;
     627                 :            : }
     628                 :            : 
     629                 :            : static int
     630                 :          0 : enetc_promiscuous_disable(struct rte_eth_dev *dev)
     631                 :            : {
     632                 :            :         struct enetc_eth_hw *hw =
     633                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     634                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     635                 :            :         uint32_t psipmr = 0;
     636                 :            : 
     637                 :            :         /* Setting to disable promiscuous mode for SI0*/
     638                 :          0 :         psipmr = enetc_port_rd(enetc_hw, ENETC_PSIPMR);
     639                 :          0 :         psipmr &= (~ENETC_PSIPMR_SET_UP(0));
     640                 :            : 
     641         [ #  # ]:          0 :         if (dev->data->all_multicast == 0)
     642                 :          0 :                 psipmr &= (~ENETC_PSIPMR_SET_MP(0));
     643                 :            : 
     644                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PSIPMR, psipmr);
     645                 :            : 
     646                 :          0 :         return 0;
     647                 :            : }
     648                 :            : 
     649                 :            : static int
     650                 :          0 : enetc_allmulticast_enable(struct rte_eth_dev *dev)
     651                 :            : {
     652                 :            :         struct enetc_eth_hw *hw =
     653                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     654                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     655                 :            :         uint32_t psipmr = 0;
     656                 :            : 
     657                 :          0 :         psipmr = enetc_port_rd(enetc_hw, ENETC_PSIPMR);
     658                 :            : 
     659                 :            :         /* Setting to enable allmulticast mode for SI0*/
     660                 :          0 :         psipmr |= ENETC_PSIPMR_SET_MP(0);
     661                 :            : 
     662                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PSIPMR, psipmr);
     663                 :            : 
     664                 :          0 :         return 0;
     665                 :            : }
     666                 :            : 
     667                 :            : static int
     668                 :          0 : enetc_allmulticast_disable(struct rte_eth_dev *dev)
     669                 :            : {
     670                 :            :         struct enetc_eth_hw *hw =
     671                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     672                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     673                 :            :         uint32_t psipmr = 0;
     674                 :            : 
     675         [ #  # ]:          0 :         if (dev->data->promiscuous == 1)
     676                 :            :                 return 0; /* must remain in all_multicast mode */
     677                 :            : 
     678                 :            :         /* Setting to disable all multicast mode for SI0*/
     679                 :          0 :         psipmr = enetc_port_rd(enetc_hw, ENETC_PSIPMR) &
     680                 :            :                                ~(ENETC_PSIPMR_SET_MP(0));
     681                 :            : 
     682                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PSIPMR, psipmr);
     683                 :            : 
     684                 :          0 :         return 0;
     685                 :            : }
     686                 :            : 
     687                 :            : static int
     688                 :          0 : enetc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
     689                 :            : {
     690                 :            :         struct enetc_eth_hw *hw =
     691                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     692                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     693                 :          0 :         uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
     694                 :            : 
     695                 :            :         /*
     696                 :            :          * Refuse mtu that requires the support of scattered packets
     697                 :            :          * when this feature has not been enabled before.
     698                 :            :          */
     699         [ #  # ]:          0 :         if (dev->data->min_rx_buf_size &&
     700         [ #  # ]:          0 :                 !dev->data->scattered_rx && frame_size >
     701         [ #  # ]:          0 :                 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
     702                 :          0 :                 ENETC_PMD_ERR("SG not enabled, will not fit in one buffer");
     703                 :          0 :                 return -EINVAL;
     704                 :            :         }
     705                 :            : 
     706                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PTCMSDUR(0), ENETC_MAC_MAXFRM_SIZE);
     707                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PTXMBAR, 2 * ENETC_MAC_MAXFRM_SIZE);
     708                 :            : 
     709                 :            :         /*setting the MTU*/
     710                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PM0_MAXFRM, ENETC_SET_MAXFRM(frame_size) |
     711                 :            :                       ENETC_SET_TX_MTU(ENETC_MAC_MAXFRM_SIZE));
     712                 :            : 
     713                 :          0 :         return 0;
     714                 :            : }
     715                 :            : 
     716                 :            : static int
     717                 :          0 : enetc_dev_configure(struct rte_eth_dev *dev)
     718                 :            : {
     719                 :            :         struct enetc_eth_hw *hw =
     720                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     721                 :            :         struct enetc_hw *enetc_hw = &hw->hw;
     722                 :            :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     723                 :          0 :         uint64_t rx_offloads = eth_conf->rxmode.offloads;
     724                 :            :         uint32_t checksum = L3_CKSUM | L4_CKSUM;
     725                 :            :         uint32_t max_len;
     726                 :            : 
     727                 :          0 :         PMD_INIT_FUNC_TRACE();
     728                 :            : 
     729                 :          0 :         max_len = dev->data->dev_conf.rxmode.mtu + RTE_ETHER_HDR_LEN +
     730                 :            :                 RTE_ETHER_CRC_LEN;
     731                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PM0_MAXFRM, ENETC_SET_MAXFRM(max_len));
     732                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PTCMSDUR(0), ENETC_MAC_MAXFRM_SIZE);
     733                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PTXMBAR, 2 * ENETC_MAC_MAXFRM_SIZE);
     734                 :            : 
     735         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
     736                 :            :                 int config;
     737                 :            : 
     738                 :          0 :                 config = enetc_port_rd(enetc_hw, ENETC_PM0_CMD_CFG);
     739                 :          0 :                 config |= ENETC_PM0_CRC;
     740                 :          0 :                 enetc_port_wr(enetc_hw, ENETC_PM0_CMD_CFG, config);
     741                 :            :         }
     742                 :            : 
     743         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
     744                 :            :                 checksum &= ~L3_CKSUM;
     745                 :            : 
     746         [ #  # ]:          0 :         if (rx_offloads & (RTE_ETH_RX_OFFLOAD_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_TCP_CKSUM))
     747                 :          0 :                 checksum &= ~L4_CKSUM;
     748                 :            : 
     749                 :          0 :         enetc_port_wr(enetc_hw, ENETC_PAR_PORT_CFG, checksum);
     750                 :            : 
     751                 :            : 
     752                 :          0 :         return 0;
     753                 :            : }
     754                 :            : 
     755                 :            : static int
     756                 :          0 : enetc_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
     757                 :            : {
     758                 :          0 :         struct enetc_eth_adapter *priv =
     759                 :          0 :                         ENETC_DEV_PRIVATE(dev->data->dev_private);
     760                 :            :         struct enetc_bdr *rx_ring;
     761                 :            :         uint32_t rx_data;
     762                 :            : 
     763                 :          0 :         rx_ring = dev->data->rx_queues[qidx];
     764         [ #  # ]:          0 :         if (dev->data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED) {
     765                 :          0 :                 rx_data = enetc_rxbdr_rd(&priv->hw.hw, rx_ring->index,
     766                 :            :                                          ENETC_RBMR);
     767                 :          0 :                 rx_data = rx_data | ENETC_RBMR_EN;
     768                 :          0 :                 enetc_rxbdr_wr(&priv->hw.hw, rx_ring->index, ENETC_RBMR,
     769                 :            :                                rx_data);
     770                 :          0 :                 dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
     771                 :            :         }
     772                 :            : 
     773                 :          0 :         return 0;
     774                 :            : }
     775                 :            : 
     776                 :            : static int
     777                 :          0 : enetc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
     778                 :            : {
     779                 :          0 :         struct enetc_eth_adapter *priv =
     780                 :          0 :                         ENETC_DEV_PRIVATE(dev->data->dev_private);
     781                 :            :         struct enetc_bdr *rx_ring;
     782                 :            :         uint32_t rx_data;
     783                 :            : 
     784                 :          0 :         rx_ring = dev->data->rx_queues[qidx];
     785         [ #  # ]:          0 :         if (dev->data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED) {
     786                 :          0 :                 rx_data = enetc_rxbdr_rd(&priv->hw.hw, rx_ring->index,
     787                 :            :                                          ENETC_RBMR);
     788                 :          0 :                 rx_data = rx_data & (~ENETC_RBMR_EN);
     789                 :          0 :                 enetc_rxbdr_wr(&priv->hw.hw, rx_ring->index, ENETC_RBMR,
     790                 :            :                                rx_data);
     791                 :          0 :                 dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
     792                 :            :         }
     793                 :            : 
     794                 :          0 :         return 0;
     795                 :            : }
     796                 :            : 
     797                 :            : static int
     798                 :          0 : enetc_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
     799                 :            : {
     800                 :          0 :         struct enetc_eth_adapter *priv =
     801                 :          0 :                         ENETC_DEV_PRIVATE(dev->data->dev_private);
     802                 :            :         struct enetc_bdr *tx_ring;
     803                 :            :         uint32_t tx_data;
     804                 :            : 
     805                 :          0 :         tx_ring = dev->data->tx_queues[qidx];
     806         [ #  # ]:          0 :         if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED) {
     807                 :          0 :                 tx_data = enetc_txbdr_rd(&priv->hw.hw, tx_ring->index,
     808                 :            :                                          ENETC_TBMR);
     809                 :          0 :                 tx_data = tx_data | ENETC_TBMR_EN;
     810                 :          0 :                 enetc_txbdr_wr(&priv->hw.hw, tx_ring->index, ENETC_TBMR,
     811                 :            :                                tx_data);
     812                 :          0 :                 dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
     813                 :            :         }
     814                 :            : 
     815                 :          0 :         return 0;
     816                 :            : }
     817                 :            : 
     818                 :            : static int
     819                 :          0 : enetc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
     820                 :            : {
     821                 :          0 :         struct enetc_eth_adapter *priv =
     822                 :          0 :                         ENETC_DEV_PRIVATE(dev->data->dev_private);
     823                 :            :         struct enetc_bdr *tx_ring;
     824                 :            :         uint32_t tx_data;
     825                 :            : 
     826                 :          0 :         tx_ring = dev->data->tx_queues[qidx];
     827         [ #  # ]:          0 :         if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED) {
     828                 :          0 :                 tx_data = enetc_txbdr_rd(&priv->hw.hw, tx_ring->index,
     829                 :            :                                          ENETC_TBMR);
     830                 :          0 :                 tx_data = tx_data & (~ENETC_TBMR_EN);
     831                 :          0 :                 enetc_txbdr_wr(&priv->hw.hw, tx_ring->index, ENETC_TBMR,
     832                 :            :                                tx_data);
     833                 :          0 :                 dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
     834                 :            :         }
     835                 :            : 
     836                 :          0 :         return 0;
     837                 :            : }
     838                 :            : 
     839                 :            : /*
     840                 :            :  * The set of PCI devices this driver supports
     841                 :            :  */
     842                 :            : static const struct rte_pci_id pci_id_enetc_map[] = {
     843                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, ENETC_DEV_ID) },
     844                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, ENETC_DEV_ID_VF) },
     845                 :            :         { .vendor_id = 0, /* sentinel */ },
     846                 :            : };
     847                 :            : 
     848                 :            : /* Features supported by this driver */
     849                 :            : static const struct eth_dev_ops enetc_ops = {
     850                 :            :         .dev_configure        = enetc_dev_configure,
     851                 :            :         .dev_start            = enetc_dev_start,
     852                 :            :         .dev_stop             = enetc_dev_stop,
     853                 :            :         .dev_close            = enetc_dev_close,
     854                 :            :         .link_update          = enetc_link_update,
     855                 :            :         .stats_get            = enetc_stats_get,
     856                 :            :         .stats_reset          = enetc_stats_reset,
     857                 :            :         .promiscuous_enable   = enetc_promiscuous_enable,
     858                 :            :         .promiscuous_disable  = enetc_promiscuous_disable,
     859                 :            :         .allmulticast_enable  = enetc_allmulticast_enable,
     860                 :            :         .allmulticast_disable = enetc_allmulticast_disable,
     861                 :            :         .dev_infos_get        = enetc_dev_infos_get,
     862                 :            :         .mtu_set              = enetc_mtu_set,
     863                 :            :         .rx_queue_setup       = enetc_rx_queue_setup,
     864                 :            :         .rx_queue_start       = enetc_rx_queue_start,
     865                 :            :         .rx_queue_stop        = enetc_rx_queue_stop,
     866                 :            :         .rx_queue_release     = enetc_rx_queue_release,
     867                 :            :         .tx_queue_setup       = enetc_tx_queue_setup,
     868                 :            :         .tx_queue_start       = enetc_tx_queue_start,
     869                 :            :         .tx_queue_stop        = enetc_tx_queue_stop,
     870                 :            :         .tx_queue_release     = enetc_tx_queue_release,
     871                 :            :         .dev_supported_ptypes_get = enetc_supported_ptypes_get,
     872                 :            : };
     873                 :            : 
     874                 :            : /**
     875                 :            :  * Initialisation of the enetc device
     876                 :            :  *
     877                 :            :  * @param eth_dev
     878                 :            :  *   - Pointer to the structure rte_eth_dev
     879                 :            :  *
     880                 :            :  * @return
     881                 :            :  *   - On success, zero.
     882                 :            :  *   - On failure, negative value.
     883                 :            :  */
     884                 :            : static int
     885                 :          0 : enetc_dev_init(struct rte_eth_dev *eth_dev)
     886                 :            : {
     887                 :            :         int error = 0;
     888                 :          0 :         struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
     889                 :          0 :         struct enetc_eth_hw *hw =
     890                 :          0 :                 ENETC_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     891                 :            : 
     892                 :          0 :         PMD_INIT_FUNC_TRACE();
     893                 :          0 :         eth_dev->dev_ops = &enetc_ops;
     894                 :          0 :         eth_dev->rx_pkt_burst = &enetc_recv_pkts;
     895                 :          0 :         eth_dev->tx_pkt_burst = &enetc_xmit_pkts;
     896                 :            : 
     897                 :            :         /* Retrieving and storing the HW base address of device */
     898                 :          0 :         hw->hw.reg = (void *)pci_dev->mem_resource[0].addr;
     899                 :          0 :         hw->device_id = pci_dev->id.device_id;
     900                 :            : 
     901                 :          0 :         error = enetc_hardware_init(hw);
     902         [ #  # ]:          0 :         if (error != 0) {
     903                 :          0 :                 ENETC_PMD_ERR("Hardware initialization failed");
     904                 :          0 :                 return -1;
     905                 :            :         }
     906                 :            : 
     907                 :            :         /* Allocate memory for storing MAC addresses */
     908                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("enetc_eth",
     909                 :            :                                         RTE_ETHER_ADDR_LEN, 0);
     910         [ #  # ]:          0 :         if (!eth_dev->data->mac_addrs) {
     911                 :          0 :                 ENETC_PMD_ERR("Failed to allocate %d bytes needed to "
     912                 :            :                               "store MAC addresses",
     913                 :            :                               RTE_ETHER_ADDR_LEN * 1);
     914                 :            :                 error = -ENOMEM;
     915                 :          0 :                 return -1;
     916                 :            :         }
     917                 :            : 
     918                 :            :         /* Copy the permanent MAC address */
     919                 :            :         rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
     920                 :            :                         &eth_dev->data->mac_addrs[0]);
     921                 :            : 
     922                 :            :         /* Set MTU */
     923                 :          0 :         enetc_port_wr(&hw->hw, ENETC_PM0_MAXFRM,
     924                 :            :                       ENETC_SET_MAXFRM(RTE_ETHER_MAX_LEN));
     925                 :          0 :         eth_dev->data->mtu = RTE_ETHER_MAX_LEN - RTE_ETHER_HDR_LEN -
     926                 :            :                 RTE_ETHER_CRC_LEN;
     927                 :            : 
     928         [ #  # ]:          0 :         if (rte_eal_iova_mode() == RTE_IOVA_PA)
     929                 :          0 :                 dpaax_iova_table_populate();
     930                 :            : 
     931                 :          0 :         ENETC_PMD_DEBUG("port_id %d vendorID=0x%x deviceID=0x%x",
     932                 :            :                         eth_dev->data->port_id, pci_dev->id.vendor_id,
     933                 :            :                         pci_dev->id.device_id);
     934                 :          0 :         return 0;
     935                 :            : }
     936                 :            : 
     937                 :            : static int
     938                 :          0 : enetc_dev_uninit(struct rte_eth_dev *eth_dev)
     939                 :            : {
     940                 :          0 :         PMD_INIT_FUNC_TRACE();
     941                 :            : 
     942                 :          0 :         return enetc_dev_close(eth_dev);
     943                 :            : }
     944                 :            : 
     945                 :            : static int
     946                 :          0 : enetc_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
     947                 :            :                            struct rte_pci_device *pci_dev)
     948                 :            : {
     949                 :          0 :         return rte_eth_dev_pci_generic_probe(pci_dev,
     950                 :            :                                              sizeof(struct enetc_eth_adapter),
     951                 :            :                                              enetc_dev_init);
     952                 :            : }
     953                 :            : 
     954                 :            : static int
     955                 :          0 : enetc_pci_remove(struct rte_pci_device *pci_dev)
     956                 :            : {
     957                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, enetc_dev_uninit);
     958                 :            : }
     959                 :            : 
     960                 :            : static struct rte_pci_driver rte_enetc_pmd = {
     961                 :            :         .id_table = pci_id_enetc_map,
     962                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
     963                 :            :         .probe = enetc_pci_probe,
     964                 :            :         .remove = enetc_pci_remove,
     965                 :            : };
     966                 :            : 
     967                 :        303 : RTE_PMD_REGISTER_PCI(net_enetc, rte_enetc_pmd);
     968                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_enetc, pci_id_enetc_map);
     969                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_enetc, "* vfio-pci");
     970         [ -  + ]:        303 : RTE_LOG_REGISTER_DEFAULT(enetc_logtype_pmd, NOTICE);

Generated by: LCOV version 1.14