|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
| 2 | +// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | + |
| 4 | +#include <linux/kernel.h> |
| 5 | +#include "en/params.h" |
| 6 | +#include "en/health.h" |
| 7 | +#include "lib/eq.h" |
| 8 | +#include "en/dcbnl.h" |
| 9 | +#include "en_accel/ipsec.h" |
| 10 | +#include "en_accel/en_accel.h" |
| 11 | +#include "en/trap.h" |
| 12 | +#include "en/monitor_stats.h" |
| 13 | +#include "en/hv_vhca_stats.h" |
| 14 | +#include "en_rep.h" |
| 15 | +#include "en.h" |
| 16 | + |
| 17 | +static int mgmt_pf_async_event(struct notifier_block *nb, unsigned long event, void *data) |
| 18 | +{ |
| 19 | + struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv, events_nb); |
| 20 | + struct mlx5_eqe *eqe = data; |
| 21 | + |
| 22 | + if (event != MLX5_EVENT_TYPE_PORT_CHANGE) |
| 23 | + return NOTIFY_DONE; |
| 24 | + |
| 25 | + switch (eqe->sub_type) { |
| 26 | + case MLX5_PORT_CHANGE_SUBTYPE_DOWN: |
| 27 | + case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE: |
| 28 | + queue_work(priv->wq, &priv->update_carrier_work); |
| 29 | + break; |
| 30 | + default: |
| 31 | + return NOTIFY_DONE; |
| 32 | + } |
| 33 | + |
| 34 | + return NOTIFY_OK; |
| 35 | +} |
| 36 | + |
| 37 | +static void mlx5e_mgmt_pf_enable_async_events(struct mlx5e_priv *priv) |
| 38 | +{ |
| 39 | + priv->events_nb.notifier_call = mgmt_pf_async_event; |
| 40 | + mlx5_notifier_register(priv->mdev, &priv->events_nb); |
| 41 | +} |
| 42 | + |
| 43 | +static void mlx5e_disable_mgmt_pf_async_events(struct mlx5e_priv *priv) |
| 44 | +{ |
| 45 | + mlx5_notifier_unregister(priv->mdev, &priv->events_nb); |
| 46 | +} |
| 47 | + |
| 48 | +static void mlx5e_modify_mgmt_pf_admin_state(struct mlx5_core_dev *mdev, |
| 49 | + enum mlx5_port_status state) |
| 50 | +{ |
| 51 | + struct mlx5_eswitch *esw = mdev->priv.eswitch; |
| 52 | + int vport_admin_state; |
| 53 | + |
| 54 | + mlx5_set_port_admin_status(mdev, state); |
| 55 | + |
| 56 | + if (state == MLX5_PORT_UP) |
| 57 | + vport_admin_state = MLX5_VPORT_ADMIN_STATE_AUTO; |
| 58 | + else |
| 59 | + vport_admin_state = MLX5_VPORT_ADMIN_STATE_DOWN; |
| 60 | + |
| 61 | + mlx5_eswitch_set_vport_state(esw, MLX5_VPORT_UPLINK, vport_admin_state); |
| 62 | +} |
| 63 | + |
| 64 | +static void mlx5e_build_mgmt_pf_nic_params(struct mlx5e_priv *priv, u16 mtu) |
| 65 | +{ |
| 66 | + struct mlx5e_params *params = &priv->channels.params; |
| 67 | + struct mlx5_core_dev *mdev = priv->mdev; |
| 68 | + u8 rx_cq_period_mode; |
| 69 | + |
| 70 | + params->sw_mtu = mtu; |
| 71 | + params->hard_mtu = MLX5E_ETH_HARD_MTU; |
| 72 | + params->num_channels = 1; |
| 73 | + |
| 74 | + /* SQ */ |
| 75 | + params->log_sq_size = is_kdump_kernel() ? |
| 76 | + MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE : |
| 77 | + MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE; |
| 78 | + MLX5E_SET_PFLAG(params, MLX5E_PFLAG_SKB_TX_MPWQE, mlx5e_tx_mpwqe_supported(mdev)); |
| 79 | + |
| 80 | + MLX5E_SET_PFLAG(params, MLX5E_PFLAG_RX_NO_CSUM_COMPLETE, false); |
| 81 | + |
| 82 | + /* RQ */ |
| 83 | + mlx5e_build_rq_params(mdev, params); |
| 84 | + |
| 85 | + /* CQ moderation params */ |
| 86 | + rx_cq_period_mode = MLX5_CAP_GEN(mdev, cq_period_start_from_cqe) ? |
| 87 | + MLX5_CQ_PERIOD_MODE_START_FROM_CQE : |
| 88 | + MLX5_CQ_PERIOD_MODE_START_FROM_EQE; |
| 89 | + params->rx_dim_enabled = MLX5_CAP_GEN(mdev, cq_moderation); |
| 90 | + params->tx_dim_enabled = MLX5_CAP_GEN(mdev, cq_moderation); |
| 91 | + mlx5e_set_rx_cq_mode_params(params, rx_cq_period_mode); |
| 92 | + mlx5e_set_tx_cq_mode_params(params, MLX5_CQ_PERIOD_MODE_START_FROM_EQE); |
| 93 | + |
| 94 | + /* TX inline */ |
| 95 | + mlx5_query_min_inline(mdev, ¶ms->tx_min_inline_mode); |
| 96 | +} |
| 97 | + |
| 98 | +static int mlx5e_mgmt_pf_init(struct mlx5_core_dev *mdev, |
| 99 | + struct net_device *netdev) |
| 100 | +{ |
| 101 | + struct mlx5e_priv *priv = netdev_priv(netdev); |
| 102 | + struct mlx5e_flow_steering *fs; |
| 103 | + int err; |
| 104 | + |
| 105 | + mlx5e_build_mgmt_pf_nic_params(priv, netdev->mtu); |
| 106 | + |
| 107 | + mlx5e_timestamp_init(priv); |
| 108 | + |
| 109 | + fs = mlx5e_fs_init(priv->profile, mdev, |
| 110 | + !test_bit(MLX5E_STATE_DESTROYING, &priv->state), |
| 111 | + priv->dfs_root); |
| 112 | + if (!fs) { |
| 113 | + err = -ENOMEM; |
| 114 | + mlx5_core_err(mdev, "FS initialization failed, %d\n", err); |
| 115 | + return err; |
| 116 | + } |
| 117 | + priv->fs = fs; |
| 118 | + |
| 119 | + mlx5e_health_create_reporters(priv); |
| 120 | + |
| 121 | + return 0; |
| 122 | +} |
| 123 | + |
| 124 | +static void mlx5e_mgmt_pf_cleanup(struct mlx5e_priv *priv) |
| 125 | +{ |
| 126 | + mlx5e_health_destroy_reporters(priv); |
| 127 | + mlx5e_fs_cleanup(priv->fs); |
| 128 | + priv->fs = NULL; |
| 129 | +} |
| 130 | + |
| 131 | +static int mlx5e_mgmt_pf_init_rx(struct mlx5e_priv *priv) |
| 132 | +{ |
| 133 | + struct mlx5_core_dev *mdev = priv->mdev; |
| 134 | + int err; |
| 135 | + |
| 136 | + priv->rx_res = mlx5e_rx_res_create(mdev, 0, priv->max_nch, priv->drop_rq.rqn, |
| 137 | + &priv->channels.params.packet_merge, |
| 138 | + priv->channels.params.num_channels); |
| 139 | + if (!priv->rx_res) |
| 140 | + return -ENOMEM; |
| 141 | + |
| 142 | + mlx5e_create_q_counters(priv); |
| 143 | + |
| 144 | + err = mlx5e_open_drop_rq(priv, &priv->drop_rq); |
| 145 | + if (err) { |
| 146 | + mlx5_core_err(mdev, "open drop rq failed, %d\n", err); |
| 147 | + goto err_destroy_q_counters; |
| 148 | + } |
| 149 | + |
| 150 | + err = mlx5e_create_flow_steering(priv->fs, priv->rx_res, priv->profile, |
| 151 | + priv->netdev); |
| 152 | + if (err) { |
| 153 | + mlx5_core_warn(mdev, "create flow steering failed, %d\n", err); |
| 154 | + goto err_destroy_rx_res; |
| 155 | + } |
| 156 | + |
| 157 | + return 0; |
| 158 | + |
| 159 | +err_destroy_rx_res: |
| 160 | + mlx5e_rx_res_destroy(priv->rx_res); |
| 161 | + priv->rx_res = NULL; |
| 162 | + mlx5e_close_drop_rq(&priv->drop_rq); |
| 163 | +err_destroy_q_counters: |
| 164 | + mlx5e_destroy_q_counters(priv); |
| 165 | + return err; |
| 166 | +} |
| 167 | + |
| 168 | +static void mlx5e_mgmt_pf_cleanup_rx(struct mlx5e_priv *priv) |
| 169 | +{ |
| 170 | + mlx5e_destroy_flow_steering(priv->fs, !!(priv->netdev->hw_features & NETIF_F_NTUPLE), |
| 171 | + priv->profile); |
| 172 | + mlx5e_rx_res_destroy(priv->rx_res); |
| 173 | + priv->rx_res = NULL; |
| 174 | + mlx5e_close_drop_rq(&priv->drop_rq); |
| 175 | + mlx5e_destroy_q_counters(priv); |
| 176 | +} |
| 177 | + |
| 178 | +static int mlx5e_mgmt_pf_init_tx(struct mlx5e_priv *priv) |
| 179 | +{ |
| 180 | + return 0; |
| 181 | +} |
| 182 | + |
| 183 | +static void mlx5e_mgmt_pf_cleanup_tx(struct mlx5e_priv *priv) |
| 184 | +{ |
| 185 | +} |
| 186 | + |
| 187 | +static void mlx5e_mgmt_pf_enable(struct mlx5e_priv *priv) |
| 188 | +{ |
| 189 | + struct net_device *netdev = priv->netdev; |
| 190 | + struct mlx5_core_dev *mdev = priv->mdev; |
| 191 | + |
| 192 | + mlx5e_fs_init_l2_addr(priv->fs, netdev); |
| 193 | + |
| 194 | + /* Marking the link as currently not needed by the Driver */ |
| 195 | + if (!netif_running(netdev)) |
| 196 | + mlx5e_modify_mgmt_pf_admin_state(mdev, MLX5_PORT_DOWN); |
| 197 | + |
| 198 | + mlx5e_set_netdev_mtu_boundaries(priv); |
| 199 | + mlx5e_set_dev_port_mtu(priv); |
| 200 | + |
| 201 | + mlx5e_mgmt_pf_enable_async_events(priv); |
| 202 | + if (mlx5e_monitor_counter_supported(priv)) |
| 203 | + mlx5e_monitor_counter_init(priv); |
| 204 | + |
| 205 | + mlx5e_hv_vhca_stats_create(priv); |
| 206 | + if (netdev->reg_state != NETREG_REGISTERED) |
| 207 | + return; |
| 208 | + mlx5e_dcbnl_init_app(priv); |
| 209 | + |
| 210 | + mlx5e_nic_set_rx_mode(priv); |
| 211 | + |
| 212 | + rtnl_lock(); |
| 213 | + if (netif_running(netdev)) |
| 214 | + mlx5e_open(netdev); |
| 215 | + udp_tunnel_nic_reset_ntf(priv->netdev); |
| 216 | + netif_device_attach(netdev); |
| 217 | + rtnl_unlock(); |
| 218 | +} |
| 219 | + |
| 220 | +static void mlx5e_mgmt_pf_disable(struct mlx5e_priv *priv) |
| 221 | +{ |
| 222 | + if (priv->netdev->reg_state == NETREG_REGISTERED) |
| 223 | + mlx5e_dcbnl_delete_app(priv); |
| 224 | + |
| 225 | + rtnl_lock(); |
| 226 | + if (netif_running(priv->netdev)) |
| 227 | + mlx5e_close(priv->netdev); |
| 228 | + netif_device_detach(priv->netdev); |
| 229 | + rtnl_unlock(); |
| 230 | + |
| 231 | + mlx5e_nic_set_rx_mode(priv); |
| 232 | + |
| 233 | + mlx5e_hv_vhca_stats_destroy(priv); |
| 234 | + if (mlx5e_monitor_counter_supported(priv)) |
| 235 | + mlx5e_monitor_counter_cleanup(priv); |
| 236 | + |
| 237 | + mlx5e_disable_mgmt_pf_async_events(priv); |
| 238 | + mlx5e_ipsec_cleanup(priv); |
| 239 | +} |
| 240 | + |
| 241 | +static int mlx5e_mgmt_pf_update_rx(struct mlx5e_priv *priv) |
| 242 | +{ |
| 243 | + return mlx5e_refresh_tirs(priv, false, false); |
| 244 | +} |
| 245 | + |
| 246 | +static int mlx5e_mgmt_pf_max_nch_limit(struct mlx5_core_dev *mdev) |
| 247 | +{ |
| 248 | + return 1; |
| 249 | +} |
| 250 | + |
| 251 | +const struct mlx5e_profile mlx5e_mgmt_pf_nic_profile = { |
| 252 | + .init = mlx5e_mgmt_pf_init, |
| 253 | + .cleanup = mlx5e_mgmt_pf_cleanup, |
| 254 | + .init_rx = mlx5e_mgmt_pf_init_rx, |
| 255 | + .cleanup_rx = mlx5e_mgmt_pf_cleanup_rx, |
| 256 | + .init_tx = mlx5e_mgmt_pf_init_tx, |
| 257 | + .cleanup_tx = mlx5e_mgmt_pf_cleanup_tx, |
| 258 | + .enable = mlx5e_mgmt_pf_enable, |
| 259 | + .disable = mlx5e_mgmt_pf_disable, |
| 260 | + .update_rx = mlx5e_mgmt_pf_update_rx, |
| 261 | + .update_stats = mlx5e_stats_update_ndo_stats, |
| 262 | + .update_carrier = mlx5e_update_carrier, |
| 263 | + .rx_handlers = &mlx5e_rx_handlers_nic, |
| 264 | + .max_tc = 1, |
| 265 | + .max_nch_limit = mlx5e_mgmt_pf_max_nch_limit, |
| 266 | + .stats_grps = mlx5e_nic_stats_grps, |
| 267 | + .stats_grps_num = mlx5e_nic_stats_grps_num |
| 268 | +}; |
0 commit comments