|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, Mellanox Technologies. All rights reserved. |
| 3 | + * |
| 4 | + * This software is available to you under a choice of one of two |
| 5 | + * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | + * General Public License (GPL) Version 2, available from the file |
| 7 | + * COPYING in the main directory of this source tree, or the |
| 8 | + * OpenIB.org BSD license below: |
| 9 | + * |
| 10 | + * Redistribution and use in source and binary forms, with or |
| 11 | + * without modification, are permitted provided that the following |
| 12 | + * conditions are met: |
| 13 | + * |
| 14 | + * - Redistributions of source code must retain the above |
| 15 | + * copyright notice, this list of conditions and the following |
| 16 | + * disclaimer. |
| 17 | + * |
| 18 | + * - Redistributions in binary form must reproduce the above |
| 19 | + * copyright notice, this list of conditions and the following |
| 20 | + * disclaimer in the documentation and/or other materials |
| 21 | + * provided with the distribution. |
| 22 | + * |
| 23 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | + * SOFTWARE. |
| 31 | + */ |
| 32 | + |
| 33 | +#include <linux/mlx5/fs.h> |
| 34 | +#include "en.h" |
| 35 | +#include "ipoib.h" |
| 36 | + |
| 37 | +/* IPoIB mlx5 netdev profile */ |
| 38 | + |
| 39 | +/* Called directly after IPoIB netdevice was created to initialize SW structs */ |
| 40 | +static void mlx5i_init(struct mlx5_core_dev *mdev, |
| 41 | + struct net_device *netdev, |
| 42 | + const struct mlx5e_profile *profile, |
| 43 | + void *ppriv) |
| 44 | +{ |
| 45 | + struct mlx5e_priv *priv = mlx5i_epriv(netdev); |
| 46 | + |
| 47 | + priv->ppriv = ppriv; |
| 48 | + /* TODO: init netdev and mlx5e_params here */ |
| 49 | +} |
| 50 | + |
| 51 | +/* Called directly before IPoIB netdevice is destroyed to cleanup SW structs */ |
| 52 | +static void mlx5i_cleanup(struct mlx5e_priv *priv) |
| 53 | +{ |
| 54 | + /* Do nothing .. */ |
| 55 | +} |
| 56 | + |
| 57 | +static int mlx5i_init_tx(struct mlx5e_priv *priv) |
| 58 | +{ |
| 59 | + /* TODO: Create IPoIB underlay QP */ |
| 60 | + /* TODO: create IPoIB TX HW TIS */ |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | +static void mlx5i_cleanup_tx(struct mlx5e_priv *priv) |
| 65 | +{ |
| 66 | +} |
| 67 | + |
| 68 | +static int mlx5i_init_rx(struct mlx5e_priv *priv) |
| 69 | +{ |
| 70 | + /* TODO: create IPoIB RX HW steering contexts */ |
| 71 | + return 0; |
| 72 | +} |
| 73 | + |
| 74 | +static void mlx5i_cleanup_rx(struct mlx5e_priv *priv) |
| 75 | +{ |
| 76 | +} |
| 77 | + |
| 78 | +static const struct mlx5e_profile mlx5i_nic_profile = { |
| 79 | + .init = mlx5i_init, |
| 80 | + .cleanup = mlx5i_cleanup, |
| 81 | + .init_tx = mlx5i_init_tx, |
| 82 | + .cleanup_tx = mlx5i_cleanup_tx, |
| 83 | + .init_rx = mlx5i_init_rx, |
| 84 | + .cleanup_rx = mlx5i_cleanup_rx, |
| 85 | + .enable = NULL, /* mlx5i_enable */ |
| 86 | + .disable = NULL, /* mlx5i_disable */ |
| 87 | + .update_stats = NULL, /* mlx5i_update_stats */ |
| 88 | + .max_nch = mlx5e_get_max_num_channels, |
| 89 | + .max_tc = MLX5I_MAX_NUM_TC, |
| 90 | +}; |
| 91 | + |
| 92 | +/* IPoIB RDMA netdev callbacks */ |
| 93 | + |
| 94 | +static int mlx5i_check_required_hca_cap(struct mlx5_core_dev *mdev) |
| 95 | +{ |
| 96 | + if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_IB) |
| 97 | + return -EOPNOTSUPP; |
| 98 | + |
| 99 | + if (!MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads)) { |
| 100 | + mlx5_core_warn(mdev, "IPoIB enhanced offloads are not supported\n"); |
| 101 | + return -ENOTSUPP; |
| 102 | + } |
| 103 | + |
| 104 | + return 0; |
| 105 | +} |
| 106 | + |
| 107 | +struct net_device *mlx5_rdma_netdev_alloc(struct mlx5_core_dev *mdev, |
| 108 | + struct ib_device *ibdev, |
| 109 | + const char *name, |
| 110 | + void (*setup)(struct net_device *)) |
| 111 | +{ |
| 112 | + const struct mlx5e_profile *profile = &mlx5i_nic_profile; |
| 113 | + int nch = profile->max_nch(mdev); |
| 114 | + struct net_device *netdev; |
| 115 | + struct mlx5i_priv *ipriv; |
| 116 | + struct mlx5e_priv *epriv; |
| 117 | + int err; |
| 118 | + |
| 119 | + if (mlx5i_check_required_hca_cap(mdev)) { |
| 120 | + mlx5_core_warn(mdev, "Accelerated mode is not supported\n"); |
| 121 | + return ERR_PTR(-EOPNOTSUPP); |
| 122 | + } |
| 123 | + |
| 124 | + /* This function should only be called once per mdev */ |
| 125 | + err = mlx5e_create_mdev_resources(mdev); |
| 126 | + if (err) |
| 127 | + return NULL; |
| 128 | + |
| 129 | + netdev = alloc_netdev_mqs(sizeof(struct mlx5i_priv) + sizeof(struct mlx5e_priv), |
| 130 | + name, NET_NAME_UNKNOWN, |
| 131 | + setup, |
| 132 | + nch * MLX5E_MAX_NUM_TC, |
| 133 | + nch); |
| 134 | + if (!netdev) { |
| 135 | + mlx5_core_warn(mdev, "alloc_netdev_mqs failed\n"); |
| 136 | + goto free_mdev_resources; |
| 137 | + } |
| 138 | + |
| 139 | + ipriv = netdev_priv(netdev); |
| 140 | + epriv = mlx5i_epriv(netdev); |
| 141 | + |
| 142 | + epriv->wq = create_singlethread_workqueue("mlx5i"); |
| 143 | + if (!epriv->wq) |
| 144 | + goto err_free_netdev; |
| 145 | + |
| 146 | + profile->init(mdev, netdev, profile, ipriv); |
| 147 | + |
| 148 | + mlx5e_attach_netdev(epriv); |
| 149 | + netif_carrier_off(netdev); |
| 150 | + |
| 151 | + /* TODO: set rdma_netdev func pointers |
| 152 | + * rn = &ipriv->rn; |
| 153 | + * rn->hca = ibdev; |
| 154 | + * rn->send = mlx5i_xmit; |
| 155 | + * rn->attach_mcast = mlx5i_attach_mcast; |
| 156 | + * rn->detach_mcast = mlx5i_detach_mcast; |
| 157 | + */ |
| 158 | + return netdev; |
| 159 | + |
| 160 | +free_mdev_resources: |
| 161 | + mlx5e_destroy_mdev_resources(mdev); |
| 162 | +err_free_netdev: |
| 163 | + free_netdev(netdev); |
| 164 | + return NULL; |
| 165 | +} |
| 166 | +EXPORT_SYMBOL(mlx5_rdma_netdev_alloc); |
| 167 | + |
| 168 | +void mlx5_rdma_netdev_free(struct net_device *netdev) |
| 169 | +{ |
| 170 | + struct mlx5e_priv *priv = mlx5i_epriv(netdev); |
| 171 | + const struct mlx5e_profile *profile = priv->profile; |
| 172 | + |
| 173 | + mlx5e_detach_netdev(priv); |
| 174 | + profile->cleanup(priv); |
| 175 | + destroy_workqueue(priv->wq); |
| 176 | + free_netdev(netdev); |
| 177 | + |
| 178 | + mlx5e_destroy_mdev_resources(priv->mdev); |
| 179 | +} |
| 180 | +EXPORT_SYMBOL(mlx5_rdma_netdev_free); |
| 181 | + |
0 commit comments