LCOV - code coverage report
Current view: top level - drivers/net/failsafe - failsafe_ether.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 310 0.0 %
Date: 2026-12-01 19:01:22 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 233 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2017 6WIND S.A.
       3                 :            :  * Copyright 2017 Mellanox Technologies, Ltd
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <unistd.h>
       7                 :            : 
       8                 :            : #include <rte_flow.h>
       9                 :            : #include <rte_flow_driver.h>
      10                 :            : #include <rte_cycles.h>
      11                 :            : 
      12                 :            : #include "failsafe_private.h"
      13                 :            : 
      14                 :            : /** Print a message out of a flow error. */
      15                 :            : static int
      16                 :          0 : fs_flow_complain(struct rte_flow_error *error)
      17                 :            : {
      18                 :            :         static const char *const errstrlist[] = {
      19                 :            :                 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
      20                 :            :                 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
      21                 :            :                 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
      22                 :            :                 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
      23                 :            :                 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
      24                 :            :                 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
      25                 :            :                 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
      26                 :            :                 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
      27                 :            :                 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
      28                 :            :                 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
      29                 :            :                 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
      30                 :            :                 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
      31                 :            :         };
      32                 :            :         const char *errstr;
      33                 :            :         char buf[32];
      34                 :          0 :         int err = rte_errno;
      35                 :            : 
      36         [ #  # ]:          0 :         if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
      37         [ #  # ]:          0 :                         !errstrlist[error->type])
      38                 :            :                 errstr = "unknown type";
      39                 :            :         else
      40                 :            :                 errstr = errstrlist[error->type];
      41   [ #  #  #  # ]:          0 :         ERROR("Caught error type %d (%s): %s%s",
      42                 :            :                 error->type, errstr,
      43                 :            :                 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
      44                 :            :                                 error->cause), buf) : "",
      45                 :            :                 error->message ? error->message : "(no stated reason)");
      46                 :          0 :         return -err;
      47                 :            : }
      48                 :            : 
      49                 :            : static int
      50                 :          0 : eth_dev_flow_isolate_set(struct rte_eth_dev *dev,
      51                 :            :                          struct sub_device *sdev)
      52                 :            : {
      53                 :            :         struct rte_flow_error ferror;
      54                 :            :         int ret;
      55                 :            : 
      56         [ #  # ]:          0 :         if (!PRIV(dev)->flow_isolated) {
      57                 :          0 :                 DEBUG("Flow isolation already disabled");
      58                 :            :         } else {
      59                 :          0 :                 DEBUG("Enabling flow isolation");
      60                 :          0 :                 ret = rte_flow_isolate(PORT_ID(sdev),
      61                 :          0 :                                        PRIV(dev)->flow_isolated,
      62                 :            :                                        &ferror);
      63         [ #  # ]:          0 :                 if (ret) {
      64                 :          0 :                         fs_flow_complain(&ferror);
      65                 :          0 :                         return ret;
      66                 :            :                 }
      67                 :            :         }
      68                 :            :         return 0;
      69                 :            : }
      70                 :            : 
      71                 :            : static int
      72                 :          0 : fs_eth_dev_conf_apply(struct rte_eth_dev *dev,
      73                 :            :                 struct sub_device *sdev)
      74                 :            : {
      75                 :            :         struct rte_eth_dev *edev;
      76                 :            :         struct rte_vlan_filter_conf *vfc1;
      77                 :            :         struct rte_vlan_filter_conf *vfc2;
      78                 :            :         struct rte_flow *flow;
      79                 :            :         struct rte_flow_error ferror;
      80                 :            :         uint32_t i;
      81                 :            :         int ret;
      82                 :            : 
      83         [ #  # ]:          0 :         edev = ETH(sdev);
      84                 :            :         /* RX queue setup */
      85         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
      86                 :            :                 struct rxq *rxq;
      87                 :            : 
      88                 :          0 :                 rxq = dev->data->rx_queues[i];
      89                 :          0 :                 ret = rte_eth_rx_queue_setup(PORT_ID(sdev), i,
      90                 :          0 :                                 rxq->info.nb_desc, rxq->socket_id,
      91                 :          0 :                                 &rxq->info.conf, rxq->info.mp);
      92         [ #  # ]:          0 :                 if (ret) {
      93                 :          0 :                         ERROR("rx_queue_setup failed");
      94                 :          0 :                         return ret;
      95                 :            :                 }
      96                 :            :         }
      97                 :            :         /* TX queue setup */
      98         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
      99                 :            :                 struct txq *txq;
     100                 :            : 
     101                 :          0 :                 txq = dev->data->tx_queues[i];
     102                 :          0 :                 ret = rte_eth_tx_queue_setup(PORT_ID(sdev), i,
     103                 :          0 :                                 txq->info.nb_desc, txq->socket_id,
     104                 :          0 :                                 &txq->info.conf);
     105         [ #  # ]:          0 :                 if (ret) {
     106                 :          0 :                         ERROR("tx_queue_setup failed");
     107                 :          0 :                         return ret;
     108                 :            :                 }
     109                 :            :         }
     110                 :            :         /* dev_link.link_status */
     111                 :          0 :         if (dev->data->dev_link.link_status !=
     112         [ #  # ]:          0 :             edev->data->dev_link.link_status) {
     113                 :          0 :                 DEBUG("Configuring link_status");
     114         [ #  # ]:          0 :                 if (dev->data->dev_link.link_status)
     115                 :          0 :                         ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
     116                 :            :                 else
     117                 :          0 :                         ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
     118         [ #  # ]:          0 :                 if (ret == -ENOTSUP) {
     119                 :            :                         /* The sub-device link follows its physical state. */
     120                 :          0 :                         DEBUG("link_status control not supported");
     121                 :            :                         ret = 0;
     122         [ #  # ]:          0 :                 } else if (ret) {
     123                 :          0 :                         ERROR("Failed to apply link_status");
     124                 :          0 :                         return ret;
     125                 :            :                 }
     126                 :            :         } else {
     127                 :          0 :                 DEBUG("link_status already set");
     128                 :            :         }
     129                 :            :         /* promiscuous */
     130         [ #  # ]:          0 :         if (dev->data->promiscuous != edev->data->promiscuous) {
     131                 :          0 :                 DEBUG("Configuring promiscuous");
     132         [ #  # ]:          0 :                 if (dev->data->promiscuous)
     133                 :          0 :                         ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
     134                 :            :                 else
     135                 :          0 :                         ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
     136         [ #  # ]:          0 :                 if (ret != 0) {
     137                 :          0 :                         ERROR("Failed to apply promiscuous mode");
     138                 :          0 :                         return ret;
     139                 :            :                 }
     140                 :            :         } else {
     141                 :          0 :                 DEBUG("promiscuous already set");
     142                 :            :         }
     143                 :            :         /* all_multicast */
     144         [ #  # ]:          0 :         if (dev->data->all_multicast != edev->data->all_multicast) {
     145                 :          0 :                 DEBUG("Configuring all_multicast");
     146         [ #  # ]:          0 :                 if (dev->data->all_multicast)
     147                 :          0 :                         ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
     148                 :            :                 else
     149                 :          0 :                         ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
     150         [ #  # ]:          0 :                 if (ret != 0) {
     151                 :          0 :                         ERROR("Failed to apply allmulticast mode");
     152                 :          0 :                         return ret;
     153                 :            :                 }
     154                 :            :         } else {
     155                 :          0 :                 DEBUG("all_multicast already set");
     156                 :            :         }
     157                 :            :         /* MTU */
     158         [ #  # ]:          0 :         if (dev->data->mtu != edev->data->mtu) {
     159                 :          0 :                 DEBUG("Configuring MTU");
     160                 :          0 :                 ret = rte_eth_dev_set_mtu(PORT_ID(sdev), dev->data->mtu);
     161         [ #  # ]:          0 :                 if (ret) {
     162                 :          0 :                         ERROR("Failed to apply MTU");
     163                 :          0 :                         return ret;
     164                 :            :                 }
     165                 :            :         } else {
     166                 :          0 :                 DEBUG("MTU already set");
     167                 :            :         }
     168                 :            :         /* default MAC */
     169                 :          0 :         DEBUG("Configuring default MAC address");
     170                 :          0 :         ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev),
     171                 :          0 :                         &dev->data->mac_addrs[0]);
     172         [ #  # ]:          0 :         if (ret) {
     173                 :          0 :                 ERROR("Setting default MAC address failed");
     174                 :          0 :                 return ret;
     175                 :            :         }
     176                 :            :         /* additional MAC */
     177         [ #  # ]:          0 :         if (PRIV(dev)->nb_mac_addr > 1)
     178         [ #  # ]:          0 :                 DEBUG("Configure additional MAC address%s",
     179                 :            :                         (PRIV(dev)->nb_mac_addr > 2 ? "es" : ""));
     180         [ #  # ]:          0 :         for (i = 1; i < PRIV(dev)->nb_mac_addr; i++) {
     181                 :            :                 struct rte_ether_addr *ea;
     182                 :            : 
     183         [ #  # ]:          0 :                 ea = &dev->data->mac_addrs[i];
     184                 :            :                 /* Removed addresses leave a zeroed slot. */
     185         [ #  # ]:          0 :                 if (rte_is_zero_ether_addr(ea))
     186                 :          0 :                         continue;
     187                 :          0 :                 ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), ea,
     188                 :            :                                 PRIV(dev)->mac_addr_pool[i]);
     189         [ #  # ]:          0 :                 if (ret) {
     190                 :            :                         char ea_fmt[RTE_ETHER_ADDR_FMT_SIZE];
     191                 :            : 
     192                 :          0 :                         rte_ether_format_addr(ea_fmt,
     193                 :            :                                         RTE_ETHER_ADDR_FMT_SIZE, ea);
     194                 :          0 :                         ERROR("Adding MAC address %s failed", ea_fmt);
     195                 :            :                         return ret;
     196                 :            :                 }
     197                 :            :         }
     198                 :            :         /*
     199                 :            :          * Propagate multicast MAC addresses to sub-devices,
     200                 :            :          * if non zero number of addresses is set.
     201                 :            :          * The condition is required to avoid breakage of failsafe
     202                 :            :          * for sub-devices which do not support the operation
     203                 :            :          * if the feature is really not used.
     204                 :            :          */
     205         [ #  # ]:          0 :         if (PRIV(dev)->nb_mcast_addr > 0) {
     206                 :          0 :                 DEBUG("Configuring multicast MAC addresses");
     207                 :          0 :                 ret = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
     208                 :            :                                                    PRIV(dev)->mcast_addrs,
     209                 :          0 :                                                    PRIV(dev)->nb_mcast_addr);
     210         [ #  # ]:          0 :                 if (ret) {
     211                 :          0 :                         ERROR("Failed to apply multicast MAC addresses");
     212                 :          0 :                         return ret;
     213                 :            :                 }
     214                 :            :         }
     215                 :            :         /* VLAN filter */
     216                 :          0 :         vfc1 = &dev->data->vlan_filter_conf;
     217                 :          0 :         vfc2 = &edev->data->vlan_filter_conf;
     218         [ #  # ]:          0 :         if (memcmp(vfc1, vfc2, sizeof(struct rte_vlan_filter_conf))) {
     219                 :            :                 uint64_t vbit;
     220                 :            :                 uint64_t ids;
     221                 :            :                 size_t i;
     222                 :            :                 uint16_t vlan_id;
     223                 :            : 
     224                 :          0 :                 DEBUG("Configuring VLAN filter");
     225         [ #  # ]:          0 :                 for (i = 0; i < RTE_DIM(vfc1->ids); i++) {
     226         [ #  # ]:          0 :                         if (vfc1->ids[i] == 0)
     227                 :          0 :                                 continue;
     228                 :            :                         ids = vfc1->ids[i];
     229         [ #  # ]:          0 :                         while (ids) {
     230                 :          0 :                                 vlan_id = 64 * i;
     231                 :            :                                 /* count trailing zeroes */
     232                 :          0 :                                 vbit = ~ids & (ids - 1);
     233                 :            :                                 /* clear least significant bit set */
     234                 :          0 :                                 ids ^= (ids ^ (ids - 1)) ^ vbit;
     235         [ #  # ]:          0 :                                 for (; vbit; vlan_id++)
     236                 :          0 :                                         vbit >>= 1;
     237                 :          0 :                                 ret = rte_eth_dev_vlan_filter(
     238                 :          0 :                                         PORT_ID(sdev), vlan_id, 1);
     239         [ #  # ]:          0 :                                 if (ret) {
     240                 :          0 :                                         ERROR("Failed to apply VLAN filter %hu",
     241                 :            :                                                 vlan_id);
     242                 :          0 :                                         return ret;
     243                 :            :                                 }
     244                 :            :                         }
     245                 :            :                 }
     246                 :            :         } else {
     247                 :          0 :                 DEBUG("VLAN filter already set");
     248                 :            :         }
     249                 :            :         /* rte_flow */
     250         [ #  # ]:          0 :         if (TAILQ_EMPTY(&PRIV(dev)->flow_list)) {
     251                 :          0 :                 DEBUG("rte_flow already set");
     252                 :            :         } else {
     253                 :          0 :                 DEBUG("Resetting rte_flow configuration");
     254                 :          0 :                 ret = rte_flow_flush(PORT_ID(sdev), &ferror);
     255         [ #  # ]:          0 :                 if (ret) {
     256                 :          0 :                         fs_flow_complain(&ferror);
     257                 :          0 :                         return ret;
     258                 :            :                 }
     259                 :            :                 i = 0;
     260                 :          0 :                 rte_errno = 0;
     261                 :          0 :                 DEBUG("Configuring rte_flow");
     262         [ #  # ]:          0 :                 TAILQ_FOREACH(flow, &PRIV(dev)->flow_list, next) {
     263                 :          0 :                         DEBUG("Creating flow #%" PRIu32, i++);
     264                 :          0 :                         flow->flows[SUB_ID(sdev)] =
     265                 :          0 :                                 rte_flow_create(PORT_ID(sdev),
     266                 :          0 :                                                 flow->rule.attr,
     267                 :          0 :                                                 flow->rule.pattern,
     268                 :          0 :                                                 flow->rule.actions,
     269                 :            :                                                 &ferror);
     270                 :          0 :                         ret = rte_errno;
     271         [ #  # ]:          0 :                         if (ret)
     272                 :            :                                 break;
     273                 :            :                 }
     274         [ #  # ]:          0 :                 if (ret) {
     275                 :          0 :                         fs_flow_complain(&ferror);
     276                 :          0 :                         return ret;
     277                 :            :                 }
     278                 :            :         }
     279                 :            :         return 0;
     280                 :            : }
     281                 :            : 
     282                 :            : static void
     283                 :          0 : fs_dev_remove(struct sub_device *sdev)
     284                 :            : {
     285                 :            :         int ret;
     286                 :            : 
     287         [ #  # ]:          0 :         if (sdev == NULL)
     288                 :            :                 return;
     289   [ #  #  #  #  :          0 :         switch (sdev->state) {
                      # ]
     290                 :          0 :         case DEV_STARTED:
     291                 :          0 :                 failsafe_rx_intr_uninstall_subdevice(sdev);
     292                 :          0 :                 ret = rte_eth_dev_stop(PORT_ID(sdev));
     293         [ #  # ]:          0 :                 if (ret < 0)
     294                 :          0 :                         ERROR("Failed to stop sub-device %u", SUB_ID(sdev));
     295                 :          0 :                 sdev->state = DEV_ACTIVE;
     296                 :            :                 /* fallthrough */
     297                 :          0 :         case DEV_ACTIVE:
     298                 :          0 :                 failsafe_eth_dev_unregister_callbacks(sdev);
     299                 :          0 :                 ret = rte_eth_dev_close(PORT_ID(sdev));
     300         [ #  # ]:          0 :                 if (ret < 0) {
     301                 :          0 :                         ERROR("Port close failed for sub-device %u",
     302                 :            :                               PORT_ID(sdev));
     303                 :            :                 }
     304                 :          0 :                 sdev->state = DEV_PROBED;
     305                 :            :                 /* fallthrough */
     306                 :          0 :         case DEV_PROBED:
     307                 :          0 :                 ret = rte_dev_remove(sdev->dev);
     308         [ #  # ]:          0 :                 if (ret < 0)
     309                 :          0 :                         ERROR("Bus detach failed for sub_device %u",
     310                 :            :                               SUB_ID(sdev));
     311                 :            :                 sdev->state = DEV_PARSED;
     312                 :            :                 /* fallthrough */
     313                 :          0 :         case DEV_PARSED:
     314                 :            :         case DEV_UNDEFINED:
     315                 :          0 :                 sdev->state = DEV_UNDEFINED;
     316                 :          0 :                 sdev->sdev_port_id = RTE_MAX_ETHPORTS;
     317                 :            :                 /* the end */
     318                 :          0 :                 break;
     319                 :            :         }
     320                 :          0 :         sdev->remove = 0;
     321                 :          0 :         failsafe_hotplug_alarm_install(fs_dev(sdev));
     322                 :            : }
     323                 :            : 
     324                 :            : static void
     325                 :          0 : fs_dev_stats_save(struct sub_device *sdev)
     326                 :            : {
     327                 :            :         struct rte_eth_stats stats;
     328                 :            :         int err;
     329                 :            : 
     330                 :            :         /* Attempt to read current stats. */
     331                 :          0 :         err = rte_eth_stats_get(PORT_ID(sdev), &stats);
     332         [ #  # ]:          0 :         if (err) {
     333                 :          0 :                 uint64_t timestamp = sdev->stats_snapshot.timestamp;
     334                 :            : 
     335                 :          0 :                 WARN("Could not access latest statistics from sub-device %d.",
     336                 :            :                          SUB_ID(sdev));
     337         [ #  # ]:          0 :                 if (timestamp != 0)
     338                 :          0 :                         WARN("Using latest snapshot taken before %"PRIu64" seconds.",
     339                 :            :                                  (rte_rdtsc() - timestamp) / rte_get_tsc_hz());
     340                 :            :         }
     341         [ #  # ]:          0 :         failsafe_stats_increment
     342                 :          0 :                 (&PRIV(fs_dev(sdev))->stats_accumulator,
     343                 :            :                 err ? &sdev->stats_snapshot.stats : &stats);
     344                 :          0 :         memset(&sdev->stats_snapshot, 0, sizeof(sdev->stats_snapshot));
     345                 :          0 : }
     346                 :            : 
     347                 :            : static inline int
     348                 :          0 : fs_rxtx_clean(struct sub_device *sdev)
     349                 :            : {
     350                 :            :         uint16_t i;
     351                 :            : 
     352   [ #  #  #  # ]:          0 :         for (i = 0; i < ETH(sdev)->data->nb_rx_queues; i++)
     353         [ #  # ]:          0 :                 if (FS_ATOMIC_RX(sdev, i))
     354                 :            :                         return 0;
     355   [ #  #  #  # ]:          0 :         for (i = 0; i < ETH(sdev)->data->nb_tx_queues; i++)
     356         [ #  # ]:          0 :                 if (FS_ATOMIC_TX(sdev, i))
     357                 :            :                         return 0;
     358                 :            :         return 1;
     359                 :            : }
     360                 :            : 
     361                 :            : void
     362                 :          0 : failsafe_eth_dev_unregister_callbacks(struct sub_device *sdev)
     363                 :            : {
     364                 :            :         int ret;
     365                 :            : 
     366         [ #  # ]:          0 :         if (sdev == NULL)
     367                 :            :                 return;
     368         [ #  # ]:          0 :         if (sdev->rmv_callback) {
     369                 :          0 :                 ret = rte_eth_dev_callback_unregister(PORT_ID(sdev),
     370                 :            :                                                 RTE_ETH_EVENT_INTR_RMV,
     371                 :            :                                                 failsafe_eth_rmv_event_callback,
     372                 :            :                                                 sdev);
     373         [ #  # ]:          0 :                 if (ret)
     374                 :          0 :                         WARN("Failed to unregister RMV callback for sub_device"
     375                 :            :                              " %d", SUB_ID(sdev));
     376                 :          0 :                 sdev->rmv_callback = 0;
     377                 :            :         }
     378         [ #  # ]:          0 :         if (sdev->lsc_callback) {
     379                 :          0 :                 ret = rte_eth_dev_callback_unregister(PORT_ID(sdev),
     380                 :            :                                                 RTE_ETH_EVENT_INTR_LSC,
     381                 :            :                                                 failsafe_eth_lsc_event_callback,
     382                 :            :                                                 sdev);
     383         [ #  # ]:          0 :                 if (ret)
     384                 :          0 :                         WARN("Failed to unregister LSC callback for sub_device"
     385                 :            :                              " %d", SUB_ID(sdev));
     386                 :          0 :                 sdev->lsc_callback = 0;
     387                 :            :         }
     388                 :            :         /*
     389                 :            :          * The bus device-event callback is registered by the primary only
     390                 :            :          * (hotplug is handled there). sub_device is shared memory, so in a
     391                 :            :          * secondary the flag reads as set and sdev->dev holds the primary's
     392                 :            :          * pointer; dereferencing it (rte_dev_name) would crash. Skip it.
     393                 :            :          */
     394   [ #  #  #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
     395                 :            :             sdev->dev_event_callback) {
     396                 :          0 :                 ret = rte_dev_event_callback_unregister(rte_dev_name(sdev->dev),
     397                 :            :                                                 failsafe_dev_event_callback,
     398                 :            :                                                 sdev);
     399         [ #  # ]:          0 :                 if (ret < 0)
     400                 :          0 :                         WARN("Failed to unregister device event callback for"
     401                 :            :                              " sub_device %d", SUB_ID(sdev));
     402                 :          0 :                 sdev->dev_event_callback = 0;
     403                 :            :         }
     404                 :            : }
     405                 :            : 
     406                 :            : void
     407         [ #  # ]:          0 : failsafe_dev_remove(struct rte_eth_dev *dev)
     408                 :            : {
     409                 :            :         struct sub_device *sdev;
     410                 :            :         uint8_t i;
     411                 :            : 
     412   [ #  #  #  # ]:          0 :         FOREACH_SUBDEV(sdev, i, dev) {
     413         [ #  # ]:          0 :                 if (!sdev->remove)
     414                 :          0 :                         continue;
     415                 :            : 
     416                 :            :                 /* Active devices must have finished their burst and
     417                 :            :                  * their stats must be saved.
     418                 :            :                  */
     419   [ #  #  #  # ]:          0 :                 if (sdev->state >= DEV_ACTIVE &&
     420                 :          0 :                     fs_rxtx_clean(sdev) == 0)
     421                 :          0 :                         continue;
     422         [ #  # ]:          0 :                 if (fs_lock(dev, 1) != 0)
     423                 :            :                         return;
     424         [ #  # ]:          0 :                 if (sdev->state >= DEV_ACTIVE)
     425                 :          0 :                         fs_dev_stats_save(sdev);
     426                 :          0 :                 fs_dev_remove(sdev);
     427                 :          0 :                 fs_unlock(dev, 1);
     428                 :            :         }
     429                 :            : }
     430                 :            : 
     431                 :            : static int
     432                 :          0 : failsafe_eth_dev_rx_queues_sync(struct rte_eth_dev *dev)
     433                 :            : {
     434                 :            :         struct rxq *rxq;
     435                 :            :         int ret;
     436                 :            :         uint16_t i;
     437                 :            : 
     438         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
     439                 :          0 :                 rxq = dev->data->rx_queues[i];
     440                 :            : 
     441         [ #  # ]:          0 :                 if (rxq->info.conf.rx_deferred_start &&
     442         [ #  # ]:          0 :                     dev->data->rx_queue_state[i] ==
     443                 :            :                                                 RTE_ETH_QUEUE_STATE_STARTED) {
     444                 :            :                         /*
     445                 :            :                          * The subdevice Rx queue does not launch on device
     446                 :            :                          * start if deferred start flag is set. It needs to be
     447                 :            :                          * started manually in case an appropriate failsafe Rx
     448                 :            :                          * queue has been started earlier.
     449                 :            :                          */
     450                 :          0 :                         ret = dev->dev_ops->rx_queue_start(dev, i);
     451         [ #  # ]:          0 :                         if (ret) {
     452                 :          0 :                                 ERROR("Could not synchronize Rx queue %d", i);
     453                 :          0 :                                 return ret;
     454                 :            :                         }
     455         [ #  # ]:          0 :                 } else if (dev->data->rx_queue_state[i] ==
     456                 :            :                                                 RTE_ETH_QUEUE_STATE_STOPPED) {
     457                 :            :                         /*
     458                 :            :                          * The subdevice Rx queue needs to be stopped manually
     459                 :            :                          * in case an appropriate failsafe Rx queue has been
     460                 :            :                          * stopped earlier.
     461                 :            :                          */
     462                 :          0 :                         ret = dev->dev_ops->rx_queue_stop(dev, i);
     463         [ #  # ]:          0 :                         if (ret) {
     464                 :          0 :                                 ERROR("Could not synchronize Rx queue %d", i);
     465                 :          0 :                                 return ret;
     466                 :            :                         }
     467                 :            :                 }
     468                 :            :         }
     469                 :            :         return 0;
     470                 :            : }
     471                 :            : 
     472                 :            : static int
     473                 :          0 : failsafe_eth_dev_tx_queues_sync(struct rte_eth_dev *dev)
     474                 :            : {
     475                 :            :         struct txq *txq;
     476                 :            :         int ret;
     477                 :            :         uint16_t i;
     478                 :            : 
     479         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
     480                 :          0 :                 txq = dev->data->tx_queues[i];
     481                 :            : 
     482         [ #  # ]:          0 :                 if (txq->info.conf.tx_deferred_start &&
     483         [ #  # ]:          0 :                     dev->data->tx_queue_state[i] ==
     484                 :            :                                                 RTE_ETH_QUEUE_STATE_STARTED) {
     485                 :            :                         /*
     486                 :            :                          * The subdevice Tx queue does not launch on device
     487                 :            :                          * start if deferred start flag is set. It needs to be
     488                 :            :                          * started manually in case an appropriate failsafe Tx
     489                 :            :                          * queue has been started earlier.
     490                 :            :                          */
     491                 :          0 :                         ret = dev->dev_ops->tx_queue_start(dev, i);
     492         [ #  # ]:          0 :                         if (ret) {
     493                 :          0 :                                 ERROR("Could not synchronize Tx queue %d", i);
     494                 :          0 :                                 return ret;
     495                 :            :                         }
     496         [ #  # ]:          0 :                 } else if (dev->data->tx_queue_state[i] ==
     497                 :            :                                                 RTE_ETH_QUEUE_STATE_STOPPED) {
     498                 :            :                         /*
     499                 :            :                          * The subdevice Tx queue needs to be stopped manually
     500                 :            :                          * in case an appropriate failsafe Tx queue has been
     501                 :            :                          * stopped earlier.
     502                 :            :                          */
     503                 :          0 :                         ret = dev->dev_ops->tx_queue_stop(dev, i);
     504         [ #  # ]:          0 :                         if (ret) {
     505                 :          0 :                                 ERROR("Could not synchronize Tx queue %d", i);
     506                 :          0 :                                 return ret;
     507                 :            :                         }
     508                 :            :                 }
     509                 :            :         }
     510                 :            :         return 0;
     511                 :            : }
     512                 :            : 
     513                 :            : int
     514                 :          0 : failsafe_eth_dev_state_sync(struct rte_eth_dev *dev)
     515                 :            : {
     516                 :            :         struct sub_device *sdev;
     517                 :            :         uint32_t inactive;
     518                 :            :         int ret;
     519                 :            :         uint8_t i;
     520                 :            : 
     521         [ #  # ]:          0 :         if (PRIV(dev)->state < DEV_PARSED)
     522                 :            :                 return 0;
     523                 :            : 
     524                 :          0 :         ret = failsafe_args_parse_subs(dev);
     525         [ #  # ]:          0 :         if (ret)
     526                 :          0 :                 goto err_remove;
     527                 :            : 
     528         [ #  # ]:          0 :         if (PRIV(dev)->state < DEV_PROBED)
     529                 :            :                 return 0;
     530                 :          0 :         ret = failsafe_eal_init(dev);
     531         [ #  # ]:          0 :         if (ret)
     532                 :          0 :                 goto err_remove;
     533         [ #  # ]:          0 :         if (PRIV(dev)->state < DEV_ACTIVE)
     534                 :            :                 return 0;
     535                 :            :         inactive = 0;
     536   [ #  #  #  # ]:          0 :         FOREACH_SUBDEV(sdev, i, dev) {
     537         [ #  # ]:          0 :                 if (sdev->state == DEV_PROBED) {
     538                 :          0 :                         inactive |= UINT32_C(1) << i;
     539                 :          0 :                         ret = eth_dev_flow_isolate_set(dev, sdev);
     540         [ #  # ]:          0 :                         if (ret) {
     541                 :          0 :                                 ERROR("Could not apply configuration to sub_device %d",
     542                 :            :                                       i);
     543                 :          0 :                                 goto err_remove;
     544                 :            :                         }
     545                 :            :                 }
     546                 :            :         }
     547                 :          0 :         ret = dev->dev_ops->dev_configure(dev);
     548         [ #  # ]:          0 :         if (ret)
     549                 :          0 :                 goto err_remove;
     550   [ #  #  #  # ]:          0 :         FOREACH_SUBDEV(sdev, i, dev) {
     551         [ #  # ]:          0 :                 if (inactive & (UINT32_C(1) << i)) {
     552                 :          0 :                         ret = fs_eth_dev_conf_apply(dev, sdev);
     553         [ #  # ]:          0 :                         if (ret) {
     554                 :          0 :                                 ERROR("Could not apply configuration to sub_device %d",
     555                 :            :                                       i);
     556                 :          0 :                                 goto err_remove;
     557                 :            :                         }
     558                 :            :                 }
     559                 :            :         }
     560                 :            :         /*
     561                 :            :          * If new devices have been configured, check if
     562                 :            :          * the link state has changed.
     563                 :            :          */
     564         [ #  # ]:          0 :         if (inactive)
     565                 :          0 :                 dev->dev_ops->link_update(dev, 1);
     566         [ #  # ]:          0 :         if (PRIV(dev)->state < DEV_STARTED)
     567                 :            :                 return 0;
     568                 :          0 :         ret = dev->dev_ops->dev_start(dev);
     569         [ #  # ]:          0 :         if (ret)
     570                 :          0 :                 goto err_remove;
     571                 :          0 :         ret = failsafe_eth_dev_rx_queues_sync(dev);
     572         [ #  # ]:          0 :         if (ret)
     573                 :          0 :                 goto err_remove;
     574                 :          0 :         ret = failsafe_eth_dev_tx_queues_sync(dev);
     575         [ #  # ]:          0 :         if (ret)
     576                 :          0 :                 goto err_remove;
     577                 :            :         return 0;
     578         [ #  # ]:          0 : err_remove:
     579   [ #  #  #  # ]:          0 :         FOREACH_SUBDEV(sdev, i, dev)
     580         [ #  # ]:          0 :                 if (sdev->state != PRIV(dev)->state)
     581                 :          0 :                         sdev->remove = 1;
     582                 :            :         return ret;
     583                 :            : }
     584                 :            : 
     585                 :            : void
     586                 :          0 : failsafe_stats_increment(struct rte_eth_stats *to, struct rte_eth_stats *from)
     587                 :            : {
     588                 :            :         RTE_ASSERT(to != NULL && from != NULL);
     589                 :          0 :         to->ipackets += from->ipackets;
     590                 :          0 :         to->opackets += from->opackets;
     591                 :          0 :         to->ibytes += from->ibytes;
     592                 :          0 :         to->obytes += from->obytes;
     593                 :          0 :         to->imissed += from->imissed;
     594                 :          0 :         to->ierrors += from->ierrors;
     595                 :          0 :         to->oerrors += from->oerrors;
     596                 :          0 :         to->rx_nombuf += from->rx_nombuf;
     597                 :          0 : }
     598                 :            : 
     599                 :            : int
     600                 :          0 : failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused,
     601                 :            :                                 enum rte_eth_event_type event __rte_unused,
     602                 :            :                                 void *cb_arg, void *out __rte_unused)
     603                 :            : {
     604                 :            :         struct sub_device *sdev = cb_arg;
     605                 :            : 
     606         [ #  # ]:          0 :         if (fs_lock(fs_dev(sdev), 0) != 0)
     607                 :            :                 return -1;
     608                 :            :         /* Switch as soon as possible tx_dev. */
     609                 :          0 :         fs_switch_dev(fs_dev(sdev), sdev);
     610                 :            :         /*
     611                 :            :          * Async removal, the sub-PMD will try to unregister
     612                 :            :          * the callback at the source of the current thread context.
     613                 :            :          */
     614                 :          0 :         sdev->remove = 1;
     615                 :          0 :         fs_unlock(fs_dev(sdev), 0);
     616                 :          0 :         return 0;
     617                 :            : }
     618                 :            : 
     619                 :            : void
     620                 :          0 : failsafe_dev_event_callback(const char *device_name __rte_unused,
     621                 :            :                             enum rte_dev_event_type type,
     622                 :            :                             void *cb_arg)
     623                 :            : {
     624         [ #  # ]:          0 :         if (type == RTE_DEV_EVENT_REMOVE)
     625                 :          0 :                 failsafe_eth_rmv_event_callback(0, RTE_ETH_EVENT_INTR_RMV,
     626                 :            :                                                 cb_arg, NULL);
     627                 :          0 : }
     628                 :            : 
     629                 :            : int
     630                 :          0 : failsafe_eth_lsc_event_callback(uint16_t port_id __rte_unused,
     631                 :            :                                 enum rte_eth_event_type event __rte_unused,
     632                 :            :                                 void *cb_arg, void *out __rte_unused)
     633                 :            : {
     634                 :            :         struct rte_eth_dev *dev = cb_arg;
     635                 :            :         int ret;
     636                 :            : 
     637                 :          0 :         ret = dev->dev_ops->link_update(dev, 0);
     638                 :            :         /* We must pass on the LSC event */
     639         [ #  # ]:          0 :         if (ret)
     640                 :          0 :                 return rte_eth_dev_callback_process(dev,
     641                 :            :                                                     RTE_ETH_EVENT_INTR_LSC,
     642                 :            :                                                     NULL);
     643                 :            :         else
     644                 :            :                 return 0;
     645                 :            : }
     646                 :            : 
     647                 :            : /* Take sub-device ownership before it becomes exposed to the application. */
     648                 :            : int
     649                 :          0 : failsafe_eth_new_event_callback(uint16_t port_id,
     650                 :            :                                 enum rte_eth_event_type event __rte_unused,
     651                 :            :                                 void *cb_arg, void *out __rte_unused)
     652                 :            : {
     653                 :            :         struct rte_eth_dev *fs_dev = cb_arg;
     654                 :            :         struct sub_device *sdev;
     655                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
     656                 :            :         uint8_t i;
     657                 :            : 
     658         [ #  # ]:          0 :         FOREACH_SUBDEV_STATE(sdev, i, fs_dev, DEV_PARSED) {
     659         [ #  # ]:          0 :                 if (sdev->state >= DEV_PROBED)
     660                 :          0 :                         continue;
     661         [ #  # ]:          0 :                 if (dev->device == NULL) {
     662                 :          0 :                         WARN("Trying to probe malformed device %s.",
     663                 :            :                              sdev->devargs.name);
     664                 :          0 :                         continue;
     665                 :            :                 }
     666         [ #  # ]:          0 :                 if (strcmp(sdev->devargs.name, dev->device->name) != 0)
     667                 :          0 :                         continue;
     668                 :          0 :                 rte_eth_dev_owner_set(port_id, &PRIV(fs_dev)->my_owner);
     669                 :            :                 /* The actual owner will be checked after the port probing. */
     670                 :          0 :                 break;
     671                 :            :         }
     672                 :          0 :         return 0;
     673                 :            : }

Generated by: LCOV version 1.14