1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2015 6WIND S.A. 3 * Copyright 2015 Mellanox Technologies, Ltd 4 */ 5 6 #include <stddef.h> 7 #include <errno.h> 8 #include <string.h> 9 10 #include <rte_ethdev_driver.h> 11 12 #include <mlx5_glue.h> 13 #include "mlx5.h" 14 #include "mlx5_rxtx.h" 15 #include "mlx5_utils.h" 16 17 /** 18 * DPDK callback to enable promiscuous mode. 19 * 20 * @param dev 21 * Pointer to Ethernet device structure. 22 * 23 * @return 24 * 0 on success, a negative errno value otherwise and rte_errno is set. 25 */ 26 int 27 mlx5_promiscuous_enable(struct rte_eth_dev *dev) 28 { 29 struct mlx5_priv *priv = dev->data->dev_private; 30 int ret; 31 32 dev->data->promiscuous = 1; 33 if (priv->isolated) { 34 DRV_LOG(WARNING, 35 "port %u cannot enable promiscuous mode" 36 " in flow isolation mode", 37 dev->data->port_id); 38 return 0; 39 } 40 if (priv->config.vf) { 41 ret = mlx5_os_set_promisc(dev, 1); 42 if (ret) 43 return ret; 44 } 45 ret = mlx5_traffic_restart(dev); 46 if (ret) 47 DRV_LOG(ERR, "port %u cannot enable promiscuous mode: %s", 48 dev->data->port_id, strerror(rte_errno)); 49 50 /* 51 * rte_eth_dev_promiscuous_enable() rollback 52 * dev->data->promiscuous in the case of failure. 53 */ 54 return ret; 55 } 56 57 /** 58 * DPDK callback to disable promiscuous mode. 59 * 60 * @param dev 61 * Pointer to Ethernet device structure. 62 * 63 * @return 64 * 0 on success, a negative errno value otherwise and rte_errno is set. 65 */ 66 int 67 mlx5_promiscuous_disable(struct rte_eth_dev *dev) 68 { 69 struct mlx5_priv *priv = dev->data->dev_private; 70 int ret; 71 72 dev->data->promiscuous = 0; 73 if (priv->config.vf) { 74 ret = mlx5_os_set_promisc(dev, 0); 75 if (ret) 76 return ret; 77 } 78 ret = mlx5_traffic_restart(dev); 79 if (ret) 80 DRV_LOG(ERR, "port %u cannot disable promiscuous mode: %s", 81 dev->data->port_id, strerror(rte_errno)); 82 83 /* 84 * rte_eth_dev_promiscuous_disable() rollback 85 * dev->data->promiscuous in the case of failure. 86 */ 87 return ret; 88 } 89 90 /** 91 * DPDK callback to enable allmulti mode. 92 * 93 * @param dev 94 * Pointer to Ethernet device structure. 95 * 96 * @return 97 * 0 on success, a negative errno value otherwise and rte_errno is set. 98 */ 99 int 100 mlx5_allmulticast_enable(struct rte_eth_dev *dev) 101 { 102 struct mlx5_priv *priv = dev->data->dev_private; 103 int ret; 104 105 dev->data->all_multicast = 1; 106 if (priv->isolated) { 107 DRV_LOG(WARNING, 108 "port %u cannot enable allmulticast mode" 109 " in flow isolation mode", 110 dev->data->port_id); 111 return 0; 112 } 113 if (priv->config.vf) { 114 ret = mlx5_os_set_allmulti(dev, 1); 115 if (ret) 116 goto error; 117 } 118 ret = mlx5_traffic_restart(dev); 119 if (ret) 120 DRV_LOG(ERR, "port %u cannot enable allmulicast mode: %s", 121 dev->data->port_id, strerror(rte_errno)); 122 error: 123 /* 124 * rte_eth_allmulticast_enable() rollback 125 * dev->data->all_multicast in the case of failure. 126 */ 127 return ret; 128 } 129 130 /** 131 * DPDK callback to disable allmulti mode. 132 * 133 * @param dev 134 * Pointer to Ethernet device structure. 135 * 136 * @return 137 * 0 on success, a negative errno value otherwise and rte_errno is set. 138 */ 139 int 140 mlx5_allmulticast_disable(struct rte_eth_dev *dev) 141 { 142 struct mlx5_priv *priv = dev->data->dev_private; 143 int ret; 144 145 dev->data->all_multicast = 0; 146 if (priv->config.vf) { 147 ret = mlx5_os_set_allmulti(dev, 0); 148 if (ret) 149 goto error; 150 } 151 ret = mlx5_traffic_restart(dev); 152 if (ret) 153 DRV_LOG(ERR, "port %u cannot disable allmulicast mode: %s", 154 dev->data->port_id, strerror(rte_errno)); 155 error: 156 /* 157 * rte_eth_allmulticast_disable() rollback 158 * dev->data->all_multicast in the case of failure. 159 */ 160 return ret; 161 } 162