xref: /dpdk/drivers/net/mlx5/windows/mlx5_ethdev_os.c (revision 6fbd73709ee4be325194a0455e654c541c1285a6)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4 #include <stdio.h>
5 
6 #include <rte_errno.h>
7 #include <rte_ether.h>
8 #include <rte_ethdev_driver.h>
9 #include <rte_interrupts.h>
10 
11 #include <mlx5_glue.h>
12 #include <mlx5_devx_cmds.h>
13 #include <mlx5_common.h>
14 #include <mlx5_win_ext.h>
15 #include <mlx5_malloc.h>
16 #include <mlx5.h>
17 
18 /**
19  * Get MAC address by querying netdevice.
20  *
21  * @param[in] dev
22  *   Pointer to Ethernet device.
23  * @param[out] mac
24  *   MAC address output buffer.
25  *
26  * @return
27  *   0 on success, a negative errno value otherwise and rte_errno is set.
28  */
29 int
30 mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN])
31 {
32 	struct mlx5_priv *priv;
33 	mlx5_context_st *context_obj;
34 
35 	if (!dev) {
36 		rte_errno = EINVAL;
37 		return -rte_errno;
38 	}
39 	priv = dev->data->dev_private;
40 	context_obj = (mlx5_context_st *)priv->sh->ctx;
41 	memcpy(mac, context_obj->mlx5_dev.eth_mac, RTE_ETHER_ADDR_LEN);
42 	return 0;
43 }
44 
45 /**
46  * Set device MTU.
47  *
48  * @param dev
49  *   Pointer to Ethernet device.
50  * @param mtu
51  *   MTU value to set.
52  *
53  * @return
54  *   0 on success, a negative errno value otherwise and rte_errno is set.
55  */
56 int
57 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
58 {
59 	RTE_SET_USED(dev);
60 	RTE_SET_USED(mtu);
61 	return -ENOTSUP;
62 }
63 
64 /*
65  * Unregister callback handler safely. The handler may be active
66  * while we are trying to unregister it, in this case code -EAGAIN
67  * is returned by rte_intr_callback_unregister(). This routine checks
68  * the return code and tries to unregister handler again.
69  *
70  * @param handle
71  *   interrupt handle
72  * @param cb_fn
73  *   pointer to callback routine
74  * @cb_arg
75  *   opaque callback parameter
76  */
77 void
78 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
79 			      rte_intr_callback_fn cb_fn, void *cb_arg)
80 {
81 	RTE_SET_USED(handle);
82 	RTE_SET_USED(cb_fn);
83 	RTE_SET_USED(cb_arg);
84 }
85 
86 /**
87  * DPDK callback to get flow control status.
88  *
89  * @param dev
90  *   Pointer to Ethernet device structure.
91  * @param[out] fc_conf
92  *   Flow control output buffer.
93  *
94  * @return
95  *   0 on success, a negative errno value otherwise and rte_errno is set.
96  */
97 int
98 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
99 {
100 	RTE_SET_USED(dev);
101 	RTE_SET_USED(fc_conf);
102 	return -ENOTSUP;
103 }
104 
105 /**
106  * DPDK callback to modify flow control parameters.
107  *
108  * @param dev
109  *   Pointer to Ethernet device structure.
110  * @param[in] fc_conf
111  *   Flow control parameters.
112  *
113  * @return
114  *   0 on success, a negative errno value otherwise and rte_errno is set.
115  */
116 int
117 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
118 {
119 	RTE_SET_USED(dev);
120 	RTE_SET_USED(fc_conf);
121 	return -ENOTSUP;
122 }
123 
124 /**
125  * Query the number of statistics provided by ETHTOOL.
126  *
127  * @param dev
128  *   Pointer to Ethernet device.
129  *
130  * @return
131  *   Number of statistics on success, negative errno value otherwise and
132  *   rte_errno is set.
133  */
134 int
135 mlx5_os_get_stats_n(struct rte_eth_dev *dev)
136 {
137 	RTE_SET_USED(dev);
138 	return -ENOTSUP;
139 }
140 
141 /**
142  * Init the structures to read device counters.
143  *
144  * @param dev
145  *   Pointer to Ethernet device.
146  */
147 void
148 mlx5_os_stats_init(struct rte_eth_dev *dev)
149 {
150 	RTE_SET_USED(dev);
151 }
152 
153 /**
154  * Read device counters table.
155  *
156  * @param dev
157  *   Pointer to Ethernet device.
158  * @param[out] stats
159  *   Counters table output buffer.
160  *
161  * @return
162  *   0 on success and stats is filled, negative errno value otherwise and
163  *   rte_errno is set.
164  */
165 int
166 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
167 {
168 	RTE_SET_USED(dev);
169 	RTE_SET_USED(stats);
170 	return -ENOTSUP;
171 }
172 
173 /**
174  * DPDK callback to retrieve physical link information.
175  *
176  * @param dev
177  *   Pointer to Ethernet device structure.
178  * @param wait_to_complete
179  *   Wait for request completion.
180  *
181  * @return
182  *   0 if link status was not updated, positive if it was, a negative errno
183  *   value otherwise and rte_errno is set.
184  */
185 int
186 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
187 {
188 	RTE_SET_USED(wait_to_complete);
189 	struct mlx5_priv *priv;
190 	mlx5_context_st *context_obj;
191 	struct rte_eth_link dev_link;
192 	int ret;
193 
194 	ret = 0;
195 	if (!dev) {
196 		rte_errno = EINVAL;
197 		return -rte_errno;
198 	}
199 	priv = dev->data->dev_private;
200 	context_obj = (mlx5_context_st *)priv->sh->ctx;
201 	dev_link.link_speed = context_obj->mlx5_dev.link_speed / (1024 * 1024);
202 	dev_link.link_status =
203 	      (context_obj->mlx5_dev.link_state == 1 && !mlx5_is_removed(dev))
204 	      ? 1 : 0;
205 	dev_link.link_duplex = 1;
206 	if (dev->data->dev_link.link_speed != dev_link.link_speed ||
207 	    dev->data->dev_link.link_duplex != dev_link.link_duplex ||
208 	    dev->data->dev_link.link_autoneg != dev_link.link_autoneg ||
209 	    dev->data->dev_link.link_status != dev_link.link_status)
210 		ret = 1;
211 	else
212 		ret = 0;
213 	dev->data->dev_link = dev_link;
214 	return ret;
215 }
216 
217 /**
218  * DPDK callback to bring the link DOWN.
219  *
220  * @param dev
221  *   Pointer to Ethernet device structure.
222  *
223  * @return
224  *   0 on success, a negative errno value otherwise
225  */
226 int
227 mlx5_set_link_down(struct rte_eth_dev *dev)
228 {
229 	RTE_SET_USED(dev);
230 	return -ENOTSUP;
231 }
232 
233 /**
234  * DPDK callback to bring the link UP.
235  *
236  * @param dev
237  *   Pointer to Ethernet device structure.
238  *
239  * @return
240  *   0 on success, a negative errno value otherwise
241  */
242 int
243 mlx5_set_link_up(struct rte_eth_dev *dev)
244 {
245 	RTE_SET_USED(dev);
246 	return -ENOTSUP;
247 }
248 
249 /**
250  * DPDK callback to retrieve plug-in module EEPROM information (type and size).
251  *
252  * @param dev
253  *   Pointer to Ethernet device structure.
254  * @param[out] modinfo
255  *   Storage for plug-in module EEPROM information.
256  *
257  * @return
258  *   0 on success, a negative errno value otherwise and rte_errno is set.
259  */
260 int
261 mlx5_get_module_info(struct rte_eth_dev *dev,
262 		     struct rte_eth_dev_module_info *modinfo)
263 {
264 	RTE_SET_USED(dev);
265 	RTE_SET_USED(modinfo);
266 	return -ENOTSUP;
267 }
268 
269 /**
270  * DPDK callback to retrieve plug-in module EEPROM data.
271  *
272  * @param dev
273  *   Pointer to Ethernet device structure.
274  * @param[out] info
275  *   Storage for plug-in module EEPROM data.
276  *
277  * @return
278  *   0 on success, a negative errno value otherwise and rte_errno is set.
279  */
280 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
281 			   struct rte_dev_eeprom_info *info)
282 {
283 	RTE_SET_USED(dev);
284 	RTE_SET_USED(info);
285 	return -ENOTSUP;
286 }
287