net/mlx5: support adding MAC address on Windows
[dpdk.git] / drivers / net / mlx5 / windows / mlx5_os.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #include <errno.h>
6 #include <stdalign.h>
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10
11 #include <rte_windows.h>
12
13 #include <mlx5_glue.h>
14 #include <mlx5_devx_cmds.h>
15 #include <mlx5_common.h>
16 #include <mlx5_common_mp.h>
17 #include <mlx5_common_mr.h>
18 #include <mlx5_malloc.h>
19
20 #include "mlx5_defs.h"
21 #include "mlx5.h"
22 #include "mlx5_common_os.h"
23 #include "mlx5_utils.h"
24 #include "mlx5_rxtx.h"
25 #include "mlx5_autoconf.h"
26 #include "mlx5_mr.h"
27 #include "mlx5_flow.h"
28
29 /**
30  * Get mlx5 device attributes.
31  *
32  * @param ctx
33  *   Pointer to device context.
34  *
35  * @param device_attr
36  *   Pointer to mlx5 device attributes.
37  *
38  * @return
39  *   0 on success, non zero error number otherwise
40  */
41 int
42 mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr)
43 {
44         struct mlx5_context *mlx5_ctx;
45         struct mlx5_hca_attr hca_attr;
46         void *pv_iseg = NULL;
47         u32 cb_iseg = 0;
48         int err = 0;
49
50         if (!ctx)
51                 return -EINVAL;
52         mlx5_ctx = (struct mlx5_context *)ctx;
53         memset(device_attr, 0, sizeof(*device_attr));
54         err = mlx5_devx_cmd_query_hca_attr(mlx5_ctx, &hca_attr);
55         if (err) {
56                 DRV_LOG(ERR, "Failed to get device hca_cap");
57                 return err;
58         }
59         device_attr->max_cq = 1 << hca_attr.log_max_cq;
60         device_attr->max_qp = 1 << hca_attr.log_max_qp;
61         device_attr->max_qp_wr = 1 << hca_attr.log_max_qp_sz;
62         device_attr->max_cqe = 1 << hca_attr.log_max_cq_sz;
63         device_attr->max_mr = 1 << hca_attr.log_max_mrw_sz;
64         device_attr->max_pd = 1 << hca_attr.log_max_pd;
65         device_attr->max_srq = 1 << hca_attr.log_max_srq;
66         device_attr->max_srq_wr = 1 << hca_attr.log_max_srq_sz;
67         if (hca_attr.rss_ind_tbl_cap) {
68                 device_attr->max_rwq_indirection_table_size =
69                         1 << hca_attr.rss_ind_tbl_cap;
70         }
71         pv_iseg = mlx5_glue->query_hca_iseg(mlx5_ctx, &cb_iseg);
72         if (pv_iseg == NULL) {
73                 DRV_LOG(ERR, "Failed to get device hca_iseg");
74                 return errno;
75         }
76         if (!err) {
77                 snprintf(device_attr->fw_ver, 64, "%x.%x.%04x",
78                         MLX5_GET(initial_seg, pv_iseg, fw_rev_major),
79                         MLX5_GET(initial_seg, pv_iseg, fw_rev_minor),
80                         MLX5_GET(initial_seg, pv_iseg, fw_rev_subminor));
81         }
82         return err;
83 }
84
85 /**
86  * Set the completion channel file descriptor interrupt as non-blocking.
87  * Currently it has no support under Windows.
88  *
89  * @param[in] rxq_obj
90  *   Pointer to RQ channel object, which includes the channel fd
91  *
92  * @param[out] fd
93  *   The file descriptor (representing the intetrrupt) used in this channel.
94  *
95  * @return
96  *   0 on successfully setting the fd to non-blocking, non-zero otherwise.
97  */
98 int
99 mlx5_os_set_nonblock_channel_fd(int fd)
100 {
101         (void)fd;
102         DRV_LOG(WARNING, "%s: is not supported", __func__);
103         return -ENOTSUP;
104 }
105
106 /**
107  * This function should share events between multiple ports of single IB
108  * device.  Currently it has no support under Windows.
109  *
110  * @param sh
111  *   Pointer to mlx5_dev_ctx_shared object.
112  */
113 void
114 mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
115 {
116         (void)sh;
117         DRV_LOG(WARNING, "%s: is not supported", __func__);
118 }
119
120 /**
121  * This function should share events between multiple ports of single IB
122  * device.  Currently it has no support under Windows.
123  *
124  * @param dev
125  *   Pointer to mlx5_dev_ctx_shared object.
126  */
127 void
128 mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)
129 {
130         (void)sh;
131         DRV_LOG(WARNING, "%s: is not supported", __func__);
132 }
133
134 /**
135  * Read statistics by a named counter.
136  *
137  * @param[in] priv
138  *   Pointer to the private device data structure.
139  * @param[in] ctr_name
140  *   Pointer to the name of the statistic counter to read
141  * @param[out] stat
142  *   Pointer to read statistic value.
143  * @return
144  *   0 on success and stat is valud, 1 if failed to read the value
145  *   rte_errno is set.
146  *
147  */
148 int
149 mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name,
150                       uint64_t *stat)
151 {
152         RTE_SET_USED(priv);
153         RTE_SET_USED(ctr_name);
154         RTE_SET_USED(stat);
155         DRV_LOG(WARNING, "%s: is not supported", __func__);
156         return -ENOTSUP;
157 }
158
159 /**
160  * Flush device MAC addresses
161  * Currently it has no support under Windows.
162  *
163  * @param dev
164  *   Pointer to Ethernet device structure.
165  *
166  */
167 void
168 mlx5_os_mac_addr_flush(struct rte_eth_dev *dev)
169 {
170         (void)dev;
171         DRV_LOG(WARNING, "%s: is not supported", __func__);
172 }
173
174 /**
175  * Remove a MAC address from device
176  * Currently it has no support under Windows.
177  *
178  * @param dev
179  *   Pointer to Ethernet device structure.
180  * @param index
181  *   MAC address index.
182  */
183 void
184 mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
185 {
186         (void)dev;
187         (void)(index);
188         DRV_LOG(WARNING, "%s: is not supported", __func__);
189 }
190
191 /**
192  * Adds a MAC address to the device
193  * Currently it has no support under Windows.
194  *
195  * @param dev
196  *   Pointer to Ethernet device structure.
197  * @param mac_addr
198  *   MAC address to register.
199  * @param index
200  *   MAC address index.
201  *
202  * @return
203  *   0 on success, a negative errno value otherwise
204  */
205 int
206 mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
207                      uint32_t index)
208 {
209         (void)index;
210         struct rte_ether_addr lmac;
211
212         if (mlx5_get_mac(dev, &lmac.addr_bytes)) {
213                 DRV_LOG(ERR,
214                         "port %u cannot get MAC address, is mlx5_en"
215                         " loaded? (errno: %s)",
216                         dev->data->port_id, strerror(rte_errno));
217                 return rte_errno;
218         }
219         if (!rte_is_same_ether_addr(&lmac, mac)) {
220                 DRV_LOG(ERR,
221                         "adding new mac address to device is unsupported");
222                 return -ENOTSUP;
223         }
224         return 0;
225 }
226
227 /**
228  * Modify a VF MAC address
229  * Currently it has no support under Windows.
230  *
231  * @param priv
232  *   Pointer to device private data.
233  * @param mac_addr
234  *   MAC address to modify into.
235  * @param iface_idx
236  *   Net device interface index
237  * @param vf_index
238  *   VF index
239  *
240  * @return
241  *   0 on success, a negative errno value otherwise
242  */
243 int
244 mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv,
245                            unsigned int iface_idx,
246                            struct rte_ether_addr *mac_addr,
247                            int vf_index)
248 {
249         (void)priv;
250         (void)iface_idx;
251         (void)mac_addr;
252         (void)vf_index;
253         DRV_LOG(WARNING, "%s: is not supported", __func__);
254         return -ENOTSUP;
255 }
256
257 /**
258  * Set device promiscuous mode
259  * Currently it has no support under Windows.
260  *
261  * @param dev
262  *   Pointer to Ethernet device structure.
263  * @param enable
264  *   0 - promiscuous is disabled, otherwise - enabled
265  *
266  * @return
267  *   0 on success, a negative error value otherwise
268  */
269 int
270 mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable)
271 {
272         (void)dev;
273         (void)enable;
274         DRV_LOG(WARNING, "%s: is not supported", __func__);
275         return -ENOTSUP;
276 }
277
278 /**
279  * Set device allmulti mode
280  *
281  * @param dev
282  *   Pointer to Ethernet device structure.
283  * @param enable
284  *   0 - all multicase is disabled, otherwise - enabled
285  *
286  * @return
287  *   0 on success, a negative error value otherwise
288  */
289 int
290 mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable)
291 {
292         (void)dev;
293         (void)enable;
294         DRV_LOG(WARNING, "%s: is not supported", __func__);
295         return -ENOTSUP;
296 }
297
298 const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {0};