Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
3 : : */
4 : :
5 : : #include <rte_string_fns.h>
6 : : #include <ethdev_pci.h>
7 : : #include <ctype.h>
8 : : #include <sys/types.h>
9 : : #include <sys/stat.h>
10 : : #include <unistd.h>
11 : : #include <rte_tailq.h>
12 : : #include <rte_version.h>
13 : : #include <bus_pci_driver.h>
14 : : #include <dev_driver.h>
15 : : #include <ethdev_driver.h>
16 : : #include <rte_ethdev.h>
17 : : #include <rte_alarm.h>
18 : : #include <rte_dev_info.h>
19 : : #include <rte_pci.h>
20 : : #include <rte_mbuf_dyn.h>
21 : : #include <rte_cycles.h>
22 : : #include <rte_eal_paging.h>
23 : :
24 : : #include "sxe2_ethdev.h"
25 : : #include "sxe2_drv_cmd.h"
26 : : #include "sxe2_cmd_chnl.h"
27 : : #include "sxe2_tx.h"
28 : : #include "sxe2_rx.h"
29 : : #include "sxe2_txrx.h"
30 : : #include "sxe2_common.h"
31 : : #include "sxe2_common_log.h"
32 : : #include "sxe2_host_regs.h"
33 : : #include "sxe2_ioctl_chnl_func.h"
34 : :
35 : : #define SXE2_PCI_VENDOR_ID_1 0x1ff2
36 : : #define SXE2_PCI_DEVICE_ID_PF_1 0x10b1
37 : : #define SXE2_PCI_DEVICE_ID_VF_1 0x10b2
38 : :
39 : : #define SXE2_PCI_VENDOR_ID_2 0x1d94
40 : : #define SXE2_PCI_DEVICE_ID_PF_2 0x1260
41 : : #define SXE2_PCI_DEVICE_ID_VF_2 0x126f
42 : :
43 : : #define SXE2_PCI_DEVICE_ID_PF_3 0x10b3
44 : : #define SXE2_PCI_DEVICE_ID_VF_3 0x10b4
45 : :
46 : : #define SXE2_PCI_VENDOR_ID_206F 0x206f
47 : :
48 : : static const struct rte_pci_id pci_id_sxe2_tbl[] = {
49 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_1, SXE2_PCI_DEVICE_ID_PF_1)},
50 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_1, SXE2_PCI_DEVICE_ID_VF_1)},
51 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_2, SXE2_PCI_DEVICE_ID_PF_2)},
52 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_2, SXE2_PCI_DEVICE_ID_VF_2)},
53 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_1, SXE2_PCI_DEVICE_ID_PF_3)},
54 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_1, SXE2_PCI_DEVICE_ID_VF_3)},
55 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_206F, SXE2_PCI_DEVICE_ID_PF_1)},
56 : : { RTE_PCI_DEVICE(SXE2_PCI_VENDOR_ID_206F, SXE2_PCI_DEVICE_ID_VF_1)},
57 : : { .vendor_id = 0, },
58 : : };
59 : :
60 : : static struct sxe2_pci_map_addr_info sxe2_net_map_addr_info_pf[SXE2_PCI_MAP_RES_MAX_COUNT] = {
61 : : [SXE2_PCI_MAP_RES_INVALID] = {.addr_base = 0,
62 : : .bar_idx = 0,
63 : : .reg_width = 0},
64 : : [SXE2_PCI_MAP_RES_DOORBELL_TX] = {.addr_base = SXE2_TXQ_LEGACY_DBLL(0),
65 : : .bar_idx = 0,
66 : : .reg_width = 4},
67 : : [SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL] = {.addr_base = SXE2_RXQ_TAIL(0),
68 : : .bar_idx = 0,
69 : : .reg_width = 4},
70 : : [SXE2_PCI_MAP_RES_IRQ_DYN] = {.addr_base = SXE2_VF_DYN_CTL(0),
71 : : .bar_idx = 0,
72 : : .reg_width = 4},
73 : : [SXE2_PCI_MAP_RES_IRQ_ITR] = {.addr_base = SXE2_VF_INT_ITR(0, 0),
74 : : .bar_idx = 0,
75 : : .reg_width = 4},
76 : : [SXE2_PCI_MAP_RES_IRQ_MSIX] = {.addr_base = SXE2_BAR4_MSIX_CTL(0),
77 : : .bar_idx = 4,
78 : : .reg_width = 10},
79 : : };
80 : :
81 : 0 : static int32_t sxe2_dev_configure(struct rte_eth_dev *dev)
82 : : {
83 : 0 : int32_t ret = 0;
84 : 0 : PMD_INIT_FUNC_TRACE();
85 : :
86 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
87 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
88 : :
89 : 0 : return ret;
90 : : }
91 : :
92 : 0 : static int32_t sxe2_dev_stop(struct rte_eth_dev *dev)
93 : : {
94 : 0 : int32_t ret = 0;
95 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
96 : 0 : PMD_INIT_FUNC_TRACE();
97 : :
98 [ # # ]: 0 : if (adapter->started == 0)
99 : 0 : goto l_end;
100 : :
101 : 0 : sxe2_txqs_all_stop(dev);
102 : 0 : sxe2_rxqs_all_stop(dev);
103 : :
104 : 0 : dev->data->dev_started = 0;
105 : 0 : adapter->started = 0;
106 : 0 : l_end:
107 : 0 : return ret;
108 : : }
109 : :
110 : 0 : static int32_t sxe2_dev_start(struct rte_eth_dev *dev)
111 : : {
112 : 0 : int32_t ret = 0;
113 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
114 : 0 : PMD_INIT_FUNC_TRACE();
115 : :
116 : 0 : ret = sxe2_queues_init(dev);
117 [ # # ]: 0 : if (ret) {
118 : 0 : PMD_LOG_ERR(INIT, "Failed to init queues.");
119 : 0 : goto l_end;
120 : : }
121 : :
122 : 0 : sxe2_rx_mode_func_set(dev);
123 : 0 : sxe2_tx_mode_func_set(dev);
124 : :
125 : 0 : ret = sxe2_queues_start(dev);
126 [ # # ]: 0 : if (ret) {
127 : 0 : PMD_LOG_ERR(INIT, "enable queues failed");
128 : 0 : goto l_end;
129 : : }
130 : :
131 : 0 : dev->data->dev_started = 1;
132 : 0 : adapter->started = 1;
133 : 0 : goto l_end;
134 : :
135 : 0 : l_end:
136 : 0 : return ret;
137 : : }
138 : :
139 : 0 : static int32_t sxe2_dev_close(struct rte_eth_dev *dev)
140 : : {
141 : 0 : (void)sxe2_dev_stop(dev);
142 : 0 : (void)sxe2_queues_release(dev);
143 : 0 : sxe2_vsi_uninit(dev);
144 : 0 : sxe2_dev_pci_map_uinit(dev);
145 : :
146 : 0 : return 0;
147 : : }
148 : :
149 : 0 : static int32_t sxe2_dev_infos_get(struct rte_eth_dev *dev,
150 : : struct rte_eth_dev_info *dev_info)
151 : : {
152 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
153 : 0 : struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
154 : :
155 : 0 : dev_info->max_rx_queues = vsi->rxqs.q_cnt;
156 : 0 : dev_info->max_tx_queues = vsi->txqs.q_cnt;
157 : 0 : dev_info->min_rx_bufsize = SXE2_MIN_BUF_SIZE;
158 : 0 : dev_info->max_rx_pktlen = SXE2_FRAME_SIZE_MAX;
159 : 0 : dev_info->max_lro_pkt_size = SXE2_FRAME_SIZE_MAX * SXE2_RX_LRO_DESC_MAX_NUM;
160 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - SXE2_ETH_OVERHEAD;
161 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
162 : :
163 : 0 : dev_info->rx_offload_capa =
164 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
165 : : RTE_ETH_RX_OFFLOAD_SCATTER |
166 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
167 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
168 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
169 : : RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |
170 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
171 : : RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT |
172 : : RTE_ETH_RX_OFFLOAD_TCP_LRO;
173 : :
174 : 0 : dev_info->tx_offload_capa =
175 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
176 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE |
177 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
178 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
179 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
180 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
181 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
182 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
183 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
184 : : RTE_ETH_TX_OFFLOAD_UDP_TSO |
185 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
186 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
187 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
188 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO;
189 : :
190 : 0 : dev_info->rx_queue_offload_capa =
191 : : RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT |
192 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
193 : : RTE_ETH_RX_OFFLOAD_SCATTER |
194 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
195 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
196 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
197 : : RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |
198 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
199 : : RTE_ETH_RX_OFFLOAD_TCP_LRO;
200 : 0 : dev_info->tx_queue_offload_capa =
201 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE |
202 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
203 : : RTE_ETH_TX_OFFLOAD_UDP_TSO |
204 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
205 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
206 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
207 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
208 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
209 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
210 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
211 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
212 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
213 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
214 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO;
215 : :
216 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
217 : : .rx_thresh = {
218 : : .pthresh = SXE2_DEFAULT_RX_PTHRESH,
219 : : .hthresh = SXE2_DEFAULT_RX_HTHRESH,
220 : : .wthresh = SXE2_DEFAULT_RX_WTHRESH,
221 : : },
222 : : .rx_free_thresh = SXE2_DEFAULT_RX_FREE_THRESH,
223 : : .rx_drop_en = 0,
224 : : .offloads = 0,
225 : : };
226 : :
227 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
228 : : .tx_thresh = {
229 : : .pthresh = SXE2_DEFAULT_TX_PTHRESH,
230 : : .hthresh = SXE2_DEFAULT_TX_HTHRESH,
231 : : .wthresh = SXE2_DEFAULT_TX_WTHRESH,
232 : : },
233 : : .tx_free_thresh = SXE2_DEFAULT_TX_FREE_THRESH,
234 : : .tx_rs_thresh = SXE2_DEFAULT_TX_RSBIT_THRESH,
235 : : .offloads = 0,
236 : : };
237 : :
238 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
239 : : .nb_max = SXE2_MAX_RING_DESC,
240 : : .nb_min = SXE2_MIN_RING_DESC,
241 : : .nb_align = SXE2_ALIGN,
242 : : };
243 : :
244 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
245 : : .nb_max = SXE2_MAX_RING_DESC,
246 : : .nb_min = SXE2_MIN_RING_DESC,
247 : : .nb_align = SXE2_ALIGN,
248 : : .nb_mtu_seg_max = SXE2_TX_MTU_SEG_MAX,
249 : : .nb_seg_max = SXE2_MAX_RING_DESC,
250 : : };
251 : :
252 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_25G |
253 : : RTE_ETH_LINK_SPEED_50G | RTE_ETH_LINK_SPEED_100G;
254 : :
255 : 0 : dev_info->default_rxportconf.burst_size = SXE2_RX_MAX_BURST;
256 : 0 : dev_info->default_txportconf.burst_size = SXE2_TX_MAX_BURST;
257 : 0 : dev_info->default_rxportconf.nb_queues = 1;
258 : 0 : dev_info->default_txportconf.nb_queues = 1;
259 : 0 : dev_info->default_rxportconf.ring_size = SXE2_RING_SIZE_MIN;
260 : 0 : dev_info->default_txportconf.ring_size = SXE2_RING_SIZE_MIN;
261 : :
262 : 0 : dev_info->rx_seg_capa.max_nseg = SXE2_RX_MAX_NSEG;
263 : :
264 : 0 : dev_info->rx_seg_capa.multi_pools = true;
265 : :
266 : 0 : dev_info->rx_seg_capa.offset_allowed = false;
267 : :
268 : 0 : dev_info->rx_seg_capa.offset_align_log2 = false;
269 : :
270 : 0 : return 0;
271 : : }
272 : :
273 : : static const struct eth_dev_ops sxe2_eth_dev_ops = {
274 : : .dev_configure = sxe2_dev_configure,
275 : : .dev_start = sxe2_dev_start,
276 : : .dev_stop = sxe2_dev_stop,
277 : : .dev_close = sxe2_dev_close,
278 : : .dev_infos_get = sxe2_dev_infos_get,
279 : :
280 : : .rx_queue_start = sxe2_rx_queue_start,
281 : : .rx_queue_stop = sxe2_rx_queue_stop,
282 : : .tx_queue_start = sxe2_tx_queue_start,
283 : : .tx_queue_stop = sxe2_tx_queue_stop,
284 : : .rx_queue_setup = sxe2_rx_queue_setup,
285 : : .rx_queue_release = sxe2_rx_queue_release,
286 : : .tx_queue_setup = sxe2_tx_queue_setup,
287 : : .tx_queue_release = sxe2_tx_queue_release,
288 : :
289 : : .rxq_info_get = sxe2_rx_queue_info_get,
290 : : .txq_info_get = sxe2_tx_queue_info_get,
291 : : .rx_burst_mode_get = sxe2_rx_burst_mode_get,
292 : : .tx_burst_mode_get = sxe2_tx_burst_mode_get,
293 : : .tx_done_cleanup = sxe2_tx_done_cleanup,
294 : : };
295 : :
296 : 0 : struct sxe2_pci_map_bar_info *sxe2_dev_get_bar_info(struct sxe2_adapter *adapter,
297 : : enum sxe2_pci_map_resource res_type)
298 : : {
299 : 0 : struct sxe2_pci_map_context *map_ctxt = &adapter->map_ctxt;
300 : 0 : struct sxe2_pci_map_bar_info *bar_info = NULL;
301 : 0 : uint8_t bar_idx = SXE2_PCI_MAP_BAR_INVALID;
302 : 0 : uint8_t i;
303 : :
304 : 0 : bar_idx = map_ctxt->addr_info[res_type].bar_idx;
305 [ # # ]: 0 : if (bar_idx == SXE2_PCI_MAP_BAR_INVALID) {
306 : 0 : PMD_DEV_LOG_ERR(adapter, INIT, "Invalid bar index with resource type %d", res_type);
307 : 0 : goto l_end;
308 : : }
309 : :
310 [ # # ]: 0 : for (i = 0; i < map_ctxt->bar_cnt; i++) {
311 [ # # ]: 0 : if (bar_idx == map_ctxt->bar_info[i].bar_idx) {
312 : : bar_info = &map_ctxt->bar_info[i];
313 : : break;
314 : : }
315 : : }
316 : :
317 : 0 : l_end:
318 : 0 : return bar_info;
319 : : }
320 : :
321 : 0 : void *sxe2_pci_map_addr_get(struct sxe2_adapter *adapter,
322 : : enum sxe2_pci_map_resource res_type,
323 : : uint16_t idx_in_func)
324 : : {
325 : 0 : struct sxe2_pci_map_context *map_ctxt = &adapter->map_ctxt;
326 : 0 : struct sxe2_pci_map_segment_info *seg_info = NULL;
327 : 0 : struct sxe2_pci_map_bar_info *bar_info = NULL;
328 : 0 : void *addr = NULL;
329 : 0 : uintptr_t calc_addr = 0;
330 : 0 : uint8_t reg_width = 0;
331 : 0 : uint8_t i = 0;
332 : :
333 : 0 : bar_info = sxe2_dev_get_bar_info(adapter, res_type);
334 [ # # ]: 0 : if (bar_info == NULL) {
335 : 0 : PMD_DEV_LOG_WARN(adapter, INIT, "Failed to get bar info, res_type=[%d]",
336 : : res_type);
337 : 0 : goto l_end;
338 : : }
339 : 0 : seg_info = bar_info->seg_info;
340 : :
341 : 0 : reg_width = map_ctxt->addr_info[res_type].reg_width;
342 [ # # ]: 0 : if (reg_width == 0) {
343 : 0 : PMD_DEV_LOG_WARN(adapter, INIT, "Invalid reg width with resource type %d",
344 : : res_type);
345 : 0 : goto l_end;
346 : : }
347 : :
348 [ # # ]: 0 : for (i = 0; i < bar_info->map_cnt; i++) {
349 : 0 : seg_info = &bar_info->seg_info[i];
350 [ # # ]: 0 : if (res_type == seg_info->type) {
351 : 0 : calc_addr = (uintptr_t)seg_info->addr;
352 : 0 : calc_addr += (uintptr_t)seg_info->page_inner_offset;
353 : 0 : calc_addr += (uintptr_t)reg_width * (uintptr_t)idx_in_func;
354 : 0 : addr = (void *)calc_addr;
355 : 0 : goto l_end;
356 : : }
357 : : }
358 : :
359 : 0 : l_end:
360 : 0 : return addr;
361 : : }
362 : :
363 : 0 : static void sxe2_drv_dev_caps_set(struct sxe2_adapter *adapter,
364 : : struct sxe2_drv_dev_caps_resp *dev_caps)
365 : : {
366 : 0 : adapter->port_idx = dev_caps->port_idx;
367 : :
368 : 0 : adapter->cap_flags = 0;
369 : :
370 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_L2)
371 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_L2;
372 : :
373 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_VLAN)
374 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_VLAN;
375 : :
376 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_RSS)
377 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_RSS;
378 : :
379 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_IPSEC)
380 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_IPSEC;
381 : :
382 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_FNAV)
383 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_FNAV;
384 : :
385 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_TM)
386 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_TM;
387 : :
388 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_PTP)
389 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_PTP;
390 : :
391 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_Q_MAP)
392 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_Q_MAP;
393 : :
394 [ # # ]: 0 : if (dev_caps->cap_flags & SXE2_DEV_CAPS_OFFLOAD_FC_STATE)
395 : 0 : adapter->cap_flags |= SXE2_DEV_CAPS_OFFLOAD_FC_STATE;
396 : 0 : }
397 : :
398 : 0 : static int32_t sxe2_func_caps_get(struct sxe2_adapter *adapter)
399 : : {
400 : 0 : int32_t ret = -1;
401 : 0 : struct sxe2_drv_dev_caps_resp dev_caps = {0};
402 : :
403 : 0 : ret = sxe2_drv_dev_caps_get(adapter, &dev_caps);
404 [ # # ]: 0 : if (ret)
405 : 0 : goto l_end;
406 : :
407 : 0 : adapter->dev_type = dev_caps.dev_type;
408 : :
409 : 0 : sxe2_drv_dev_caps_set(adapter, &dev_caps);
410 : :
411 : 0 : sxe2_sw_queue_ctx_hw_cap_set(adapter, &dev_caps.queue_caps);
412 : :
413 : 0 : sxe2_sw_vsi_ctx_hw_cap_set(adapter, &dev_caps.vsi_caps);
414 : :
415 : 0 : l_end:
416 : 0 : return ret;
417 : : }
418 : :
419 : 0 : static int32_t sxe2_dev_caps_get(struct sxe2_adapter *adapter)
420 : : {
421 : 0 : int32_t ret = -1;
422 : :
423 : 0 : ret = sxe2_func_caps_get(adapter);
424 [ # # ]: 0 : if (ret)
425 : 0 : PMD_LOG_ERR(INIT, "get function caps failed, ret=%d", ret);
426 : :
427 : 0 : return ret;
428 : : }
429 : :
430 : 0 : int32_t sxe2_dev_pci_seg_map(struct sxe2_adapter *adapter,
431 : : enum sxe2_pci_map_resource res_type,
432 : : uint64_t org_len,
433 : : uint64_t org_offset)
434 : : {
435 : 0 : struct sxe2_pci_map_bar_info *bar_info = NULL;
436 : 0 : struct sxe2_pci_map_segment_info *seg_info = NULL;
437 : 0 : void *map_addr = NULL;
438 : 0 : int32_t ret = 0;
439 : 0 : size_t page_size = 0;
440 : 0 : size_t aligned_len = 0;
441 : 0 : size_t page_inner_offset = 0;
442 : 0 : off_t aligned_offset = 0;
443 : 0 : uint8_t i = 0;
444 : :
445 [ # # ]: 0 : if (org_len == 0) {
446 : 0 : PMD_DEV_LOG_ERR(adapter, INIT, "Invalid length, ori_len = 0");
447 : 0 : ret = -EFAULT;
448 : 0 : goto l_end;
449 : : }
450 : :
451 : 0 : bar_info = sxe2_dev_get_bar_info(adapter, res_type);
452 [ # # ]: 0 : if (!bar_info) {
453 : 0 : PMD_LOG_ERR(INIT, "Failed to get bar info, res_type=[%d]", res_type);
454 : 0 : ret = -EFAULT;
455 : 0 : goto l_end;
456 : : }
457 : 0 : seg_info = bar_info->seg_info;
458 : :
459 : 0 : page_size = rte_mem_page_size();
460 : :
461 : 0 : aligned_offset = RTE_ALIGN_FLOOR(org_offset, page_size);
462 : 0 : page_inner_offset = org_offset - aligned_offset;
463 : 0 : aligned_len = RTE_ALIGN(page_inner_offset + org_len, page_size);
464 : :
465 : 0 : map_addr = sxe2_drv_dev_mmap(adapter->cdev, bar_info->bar_idx,
466 : : aligned_len, aligned_offset);
467 [ # # ]: 0 : if (!map_addr) {
468 : 0 : PMD_LOG_ERR(INIT, "Failed to mmap BAR space, type=%d, len=%" PRIu64
469 : : ", offset=%" PRIu64 ", page_size=%zu",
470 : : res_type, org_len, org_offset, page_size);
471 : 0 : ret = -EFAULT;
472 : 0 : goto l_end;
473 : : }
474 : :
475 [ # # ]: 0 : for (i = 0; i < bar_info->map_cnt; i++) {
476 [ # # ]: 0 : if (seg_info[i].type != SXE2_PCI_MAP_RES_INVALID)
477 : 0 : continue;
478 : 0 : seg_info[i].type = res_type;
479 : 0 : seg_info[i].addr = map_addr;
480 : 0 : seg_info[i].page_inner_offset = page_inner_offset;
481 : 0 : seg_info[i].len = aligned_len;
482 : 0 : break;
483 : : }
484 [ # # ]: 0 : if (i == bar_info->map_cnt) {
485 : 0 : PMD_LOG_ERR(INIT, "No memory to save resource, res_type=%d", res_type);
486 : 0 : ret = -ENOMEM;
487 : 0 : sxe2_drv_dev_munmap(adapter->cdev, map_addr, aligned_len);
488 : 0 : goto l_end;
489 : : }
490 : :
491 : 0 : l_end:
492 : 0 : return ret;
493 : : }
494 : :
495 : 0 : static int32_t sxe2_hw_init(struct rte_eth_dev *dev)
496 : : {
497 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
498 : 0 : int32_t ret = -1;
499 : :
500 : 0 : PMD_INIT_FUNC_TRACE();
501 : :
502 : 0 : ret = sxe2_dev_caps_get(adapter);
503 [ # # ]: 0 : if (ret)
504 : 0 : PMD_LOG_ERR(INIT, "Failed to get device caps, ret=[%d]", ret);
505 : :
506 : 0 : return ret;
507 : : }
508 : :
509 : 0 : int32_t sxe2_dev_pci_res_seg_map(struct sxe2_adapter *adapter,
510 : : uint32_t res_type,
511 : : uint32_t item_cnt,
512 : : uint32_t item_base)
513 : : {
514 : 0 : struct sxe2_pci_map_addr_info *addr_info = NULL;
515 : 0 : int32_t ret = 0;
516 : :
517 : 0 : addr_info = &adapter->map_ctxt.addr_info[res_type];
518 [ # # # # ]: 0 : if (!addr_info || addr_info->bar_idx == SXE2_PCI_MAP_BAR_INVALID) {
519 : 0 : PMD_DEV_LOG_ERR(adapter, INIT, "Invalid bar index with resource type %d", res_type);
520 : 0 : ret = -EFAULT;
521 : 0 : goto l_end;
522 : : }
523 : :
524 : 0 : ret = sxe2_dev_pci_seg_map(adapter, res_type, item_cnt * addr_info->reg_width,
525 : 0 : addr_info->addr_base + item_base * addr_info->reg_width);
526 [ # # ]: 0 : if (ret != 0) {
527 : 0 : PMD_DEV_LOG_ERR(adapter, INIT, "Failed to map resource, res_type=%d", res_type);
528 : 0 : goto l_end;
529 : : }
530 : 0 : l_end:
531 : 0 : return ret;
532 : : }
533 : :
534 : 0 : void sxe2_dev_pci_seg_unmap(struct sxe2_adapter *adapter, uint32_t res_type)
535 : : {
536 : 0 : struct sxe2_pci_map_bar_info *bar_info = NULL;
537 : 0 : struct sxe2_pci_map_segment_info *seg_info = NULL;
538 : 0 : uint32_t i = 0;
539 : :
540 : 0 : bar_info = sxe2_dev_get_bar_info(adapter, res_type);
541 [ # # ]: 0 : if (bar_info == NULL) {
542 : 0 : PMD_DEV_LOG_WARN(adapter, INIT, "Failed to get bar info, res_type=[%d]", res_type);
543 : 0 : goto l_end;
544 : : }
545 : 0 : seg_info = bar_info->seg_info;
546 : :
547 [ # # ]: 0 : for (i = 0; i < bar_info->map_cnt; i++) {
548 [ # # ]: 0 : if (res_type == seg_info[i].type) {
549 : 0 : (void)sxe2_drv_dev_munmap(adapter->cdev, seg_info[i].addr,
550 : : seg_info[i].len);
551 : 0 : memset(&seg_info[i], 0, sizeof(struct sxe2_pci_map_segment_info));
552 : : break;
553 : : }
554 : : }
555 : :
556 : 0 : l_end:
557 : 0 : return;
558 : : }
559 : :
560 : 0 : static int32_t sxe2_dev_info_init(struct rte_eth_dev *dev)
561 : : {
562 : 0 : struct sxe2_adapter *adapter =
563 : 0 : SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
564 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
565 : 0 : struct sxe2_dev_info *dev_info = &adapter->dev_info;
566 : 0 : struct sxe2_drv_dev_info_resp dev_info_resp = {0};
567 : 0 : struct sxe2_drv_dev_fw_info_resp dev_fw_info_resp = {0};
568 : 0 : int32_t ret = 0;
569 : :
570 : 0 : dev_info->pci.bus_devid = pci_dev->addr.devid;
571 : 0 : dev_info->pci.bus_function = pci_dev->addr.function;
572 : :
573 : 0 : ret = sxe2_drv_dev_info_get(adapter, &dev_info_resp);
574 [ # # ]: 0 : if (ret) {
575 : 0 : PMD_LOG_ERR(INIT, "Failed to get device info, ret=[%d]", ret);
576 : 0 : goto l_end;
577 : : }
578 : 0 : dev_info->pci.serial_number = dev_info_resp.dsn;
579 : :
580 : 0 : ret = sxe2_drv_dev_fw_info_get(adapter, &dev_fw_info_resp);
581 [ # # ]: 0 : if (ret) {
582 : 0 : PMD_LOG_ERR(INIT, "Failed to get device fw info, ret=[%d]", ret);
583 : 0 : goto l_end;
584 : : }
585 : 0 : dev_info->fw.build_id = dev_fw_info_resp.build_id;
586 : 0 : dev_info->fw.fix_version_id = dev_fw_info_resp.fix_version_id;
587 : 0 : dev_info->fw.sub_version_id = dev_fw_info_resp.sub_version_id;
588 : 0 : dev_info->fw.main_version_id = dev_fw_info_resp.main_version_id;
589 : :
590 [ # # ]: 0 : if (rte_is_valid_assigned_ether_addr((struct rte_ether_addr *)dev_info_resp.mac_addr))
591 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)dev_info_resp.mac_addr,
592 : 0 : (struct rte_ether_addr *)dev_info->mac.perm_addr);
593 : : else
594 : 0 : rte_eth_random_addr(dev_info->mac.perm_addr);
595 : :
596 : 0 : l_end:
597 : 0 : return ret;
598 : : }
599 : :
600 : 0 : int32_t sxe2_dev_pci_map_init(struct rte_eth_dev *dev)
601 : : {
602 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
603 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
604 : 0 : struct sxe2_pci_map_context *map_ctxt = &adapter->map_ctxt;
605 : 0 : struct sxe2_pci_map_bar_info *bar_info = NULL;
606 : 0 : struct sxe2_pci_map_segment_info *seg_info = NULL;
607 : 0 : uint16_t txq_cnt = adapter->q_ctxt.qp_cnt_assign;
608 : 0 : uint16_t txq_base = adapter->q_ctxt.base_idx_in_pf;
609 : 0 : uint16_t rxq_cnt = adapter->q_ctxt.qp_cnt_assign;
610 : 0 : uint16_t irq_cnt = adapter->irq_ctxt.max_cnt_hw;
611 : 0 : uint16_t irq_base = adapter->irq_ctxt.base_idx_in_func;
612 : 0 : uint16_t rxq_base = adapter->q_ctxt.base_idx_in_pf;
613 : 0 : int32_t ret = 0;
614 : :
615 : 0 : PMD_INIT_FUNC_TRACE();
616 : :
617 : 0 : adapter->dev_info.dev_data = dev->data;
618 : :
619 [ # # ]: 0 : if (!pci_dev->mem_resource[0].phys_addr) {
620 : 0 : PMD_LOG_ERR(INIT, "Physical address not scanned");
621 : 0 : ret = -ENXIO;
622 : 0 : goto l_end;
623 : : }
624 : :
625 : 0 : map_ctxt->bar_cnt = 2;
626 : :
627 : 0 : bar_info = rte_zmalloc(NULL, sizeof(*bar_info) * map_ctxt->bar_cnt, 0);
628 [ # # ]: 0 : if (!bar_info) {
629 : 0 : PMD_LOG_ERR(INIT, "Failed to alloc bar_info");
630 : 0 : ret = -ENOMEM;
631 : 0 : goto l_end;
632 : : }
633 : 0 : bar_info[0].bar_idx = 0;
634 : 0 : bar_info[0].map_cnt = SXE2_PCI_MAP_RES_MAX_COUNT;
635 : 0 : seg_info = rte_zmalloc(NULL, sizeof(*seg_info) * bar_info[0].map_cnt, 0);
636 [ # # ]: 0 : if (!seg_info) {
637 : 0 : PMD_LOG_ERR(INIT, "Failed to alloc seg_info");
638 : 0 : ret = -ENOMEM;
639 : 0 : goto l_free_bar;
640 : : }
641 : :
642 : 0 : bar_info[0].seg_info = seg_info;
643 : :
644 : 0 : bar_info[1].bar_idx = 4;
645 : 0 : bar_info[1].map_cnt = SXE2_PCI_MAP_RES_MAX_COUNT;
646 : 0 : seg_info = rte_zmalloc(NULL, sizeof(*seg_info) * bar_info[1].map_cnt, 0);
647 [ # # ]: 0 : if (!seg_info) {
648 : 0 : PMD_LOG_ERR(INIT, "Failed to alloc seg_info");
649 : 0 : ret = -ENOMEM;
650 : 0 : goto l_free_seg0;
651 : : }
652 : :
653 : 0 : bar_info[1].seg_info = seg_info;
654 : 0 : map_ctxt->bar_info = bar_info;
655 : :
656 : 0 : map_ctxt->addr_info = sxe2_net_map_addr_info_pf;
657 : :
658 : 0 : ret = sxe2_dev_pci_res_seg_map(adapter, SXE2_PCI_MAP_RES_DOORBELL_TX,
659 : : txq_cnt, txq_base);
660 [ # # ]: 0 : if (ret) {
661 : 0 : PMD_LOG_ERR(INIT, "Failed to map txq doorbell addr, ret=%d", ret);
662 : 0 : goto l_free_seg1;
663 : : }
664 : :
665 : 0 : ret = sxe2_dev_pci_res_seg_map(adapter, SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL,
666 : : rxq_cnt, rxq_base);
667 [ # # ]: 0 : if (ret) {
668 : 0 : PMD_LOG_ERR(INIT, "Failed to map rxq tail doorbell addr, ret=%d", ret);
669 : 0 : goto l_free_txq;
670 : : }
671 : :
672 : 0 : ret = sxe2_dev_pci_res_seg_map(adapter, SXE2_PCI_MAP_RES_IRQ_DYN,
673 : : irq_cnt, irq_base);
674 [ # # ]: 0 : if (ret) {
675 : 0 : PMD_LOG_ERR(INIT, "Failed to map irq dyn addr, ret=%d", ret);
676 : 0 : goto l_free_rxq_tail;
677 : : }
678 : :
679 : 0 : ret = sxe2_dev_pci_res_seg_map(adapter, SXE2_PCI_MAP_RES_IRQ_ITR,
680 : : irq_cnt, irq_base);
681 [ # # ]: 0 : if (ret) {
682 : 0 : PMD_LOG_ERR(INIT, "Failed to map irq itr addr, ret=%d", ret);
683 : 0 : goto l_free_irq_dyn;
684 : : }
685 : :
686 : 0 : ret = sxe2_dev_pci_res_seg_map(adapter, SXE2_PCI_MAP_RES_IRQ_MSIX,
687 : : irq_cnt, irq_base);
688 [ # # ]: 0 : if (ret) {
689 : 0 : PMD_LOG_ERR(INIT, "Failed to map irq msix addr, ret=%d", ret);
690 : 0 : goto l_free_irq_itr;
691 : : }
692 : 0 : goto l_end;
693 : :
694 : 0 : l_free_irq_itr:
695 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_ITR);
696 : 0 : l_free_irq_dyn:
697 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_DYN);
698 : 0 : l_free_rxq_tail:
699 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL);
700 : 0 : l_free_txq:
701 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_DOORBELL_TX);
702 : 0 : l_free_seg1:
703 [ # # ]: 0 : if (bar_info[1].seg_info) {
704 : 0 : rte_free(bar_info[1].seg_info);
705 : 0 : bar_info[1].seg_info = NULL;
706 : : }
707 : 0 : l_free_seg0:
708 [ # # ]: 0 : if (bar_info[0].seg_info) {
709 : 0 : rte_free(bar_info[0].seg_info);
710 : 0 : bar_info[0].seg_info = NULL;
711 : : }
712 : 0 : l_free_bar:
713 : 0 : if (bar_info) {
714 : 0 : rte_free(bar_info);
715 : 0 : bar_info = NULL;
716 : : }
717 : 0 : l_end:
718 : 0 : return ret;
719 : : }
720 : :
721 : 0 : void sxe2_dev_pci_map_uinit(struct rte_eth_dev *dev)
722 : : {
723 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
724 : 0 : struct sxe2_pci_map_context *map_ctxt = &adapter->map_ctxt;
725 : 0 : struct sxe2_pci_map_bar_info *bar_info = NULL;
726 : 0 : uint8_t i = 0;
727 : :
728 : 0 : PMD_INIT_FUNC_TRACE();
729 : :
730 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL);
731 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_DOORBELL_TX);
732 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_DYN);
733 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_ITR);
734 : 0 : (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_MSIX);
735 : :
736 [ # # ]: 0 : if (map_ctxt != NULL && map_ctxt->bar_info != NULL) {
737 [ # # ]: 0 : for (i = 0; i < map_ctxt->bar_cnt; i++) {
738 : 0 : bar_info = &map_ctxt->bar_info[i];
739 [ # # # # ]: 0 : if (bar_info != NULL && bar_info->seg_info != NULL) {
740 : 0 : rte_free(bar_info->seg_info);
741 : 0 : bar_info->seg_info = NULL;
742 : : }
743 : : }
744 : 0 : rte_free(map_ctxt->bar_info);
745 : 0 : map_ctxt->bar_info = NULL;
746 : : }
747 : :
748 : 0 : adapter->dev_info.dev_data = NULL;
749 : 0 : }
750 : :
751 : 0 : static int32_t sxe2_dev_init(struct rte_eth_dev *dev,
752 : : struct sxe2_dev_kvargs_info *kvargs __rte_unused)
753 : : {
754 : 0 : int32_t ret = 0;
755 : :
756 : 0 : PMD_INIT_FUNC_TRACE();
757 : :
758 : 0 : sxe2_set_common_function(dev);
759 : :
760 : 0 : dev->dev_ops = &sxe2_eth_dev_ops;
761 : :
762 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
763 : 0 : sxe2_rx_mode_func_set(dev);
764 : 0 : sxe2_tx_mode_func_set(dev);
765 : 0 : goto l_end;
766 : : }
767 : :
768 : 0 : ret = sxe2_hw_init(dev);
769 [ # # ]: 0 : if (ret) {
770 : 0 : PMD_LOG_ERR(INIT, "Failed to initialize hw, ret=[%d]", ret);
771 : 0 : goto l_end;
772 : : }
773 : :
774 : 0 : ret = sxe2_dev_pci_map_init(dev);
775 [ # # ]: 0 : if (ret) {
776 : 0 : PMD_LOG_ERR(INIT, "Failed to pci addr map, ret=[%d]", ret);
777 : 0 : goto l_end;
778 : : }
779 : :
780 : 0 : ret = sxe2_vsi_init(dev);
781 [ # # ]: 0 : if (ret) {
782 : 0 : PMD_LOG_ERR(INIT, "create main vsi failed, ret=%d", ret);
783 : 0 : goto init_vsi_err;
784 : : }
785 : :
786 : 0 : ret = sxe2_dev_info_init(dev);
787 [ # # ]: 0 : if (ret) {
788 : 0 : PMD_LOG_ERR(INIT, "Failed to get device info, ret=[%d]", ret);
789 : 0 : goto init_dev_info_err;
790 : : }
791 : :
792 : 0 : goto l_end;
793 : :
794 : 0 : init_dev_info_err:
795 : 0 : sxe2_vsi_uninit(dev);
796 : 0 : init_vsi_err:
797 : 0 : l_end:
798 : 0 : return ret;
799 : : }
800 : :
801 : 0 : static int32_t sxe2_dev_uninit(struct rte_eth_dev *dev)
802 : : {
803 : 0 : int32_t ret = 0;
804 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
805 : 0 : goto l_end;
806 : :
807 : 0 : ret = sxe2_dev_close(dev);
808 [ # # ]: 0 : if (ret) {
809 : 0 : PMD_LOG_ERR(INIT, "Sxe2 dev close failed, ret=%d", ret);
810 : 0 : goto l_end;
811 : : }
812 : :
813 : 0 : l_end:
814 : 0 : return ret;
815 : : }
816 : :
817 : 0 : static int32_t sxe2_eth_pmd_remove(struct sxe2_common_device *cdev)
818 : : {
819 : 0 : struct rte_eth_dev *eth_dev;
820 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev);
821 : 0 : int32_t ret = 0;
822 : :
823 : 0 : eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
824 [ # # ]: 0 : if (!eth_dev) {
825 : 0 : PMD_LOG_INFO(INIT, "Sxe2 dev allocated failed");
826 : 0 : goto l_end;
827 : : }
828 : :
829 : 0 : ret = sxe2_dev_uninit(eth_dev);
830 [ # # ]: 0 : if (ret) {
831 : 0 : PMD_LOG_ERR(INIT, "Sxe2 dev uninit failed, ret=%d", ret);
832 : 0 : goto l_end;
833 : : }
834 : 0 : (void)rte_eth_dev_release_port(eth_dev);
835 : :
836 : 0 : l_end:
837 : 0 : return ret;
838 : : }
839 : :
840 : 0 : static int32_t sxe2_eth_pmd_probe_pf(struct sxe2_common_device *cdev,
841 : : struct rte_eth_devargs *req_eth_da __rte_unused,
842 : : uint16_t owner_id __rte_unused,
843 : : struct sxe2_dev_kvargs_info *kvargs)
844 : : {
845 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev);
846 : 0 : struct rte_eth_dev *eth_dev = NULL;
847 : 0 : struct sxe2_adapter *adapter = NULL;
848 : 0 : int32_t ret = 0;
849 : :
850 : 0 : if (!cdev) {
851 : : ret = -EINVAL;
852 : : goto l_end;
853 : : }
854 : :
855 : 0 : eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct sxe2_adapter));
856 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
857 [ # # ]: 0 : if (eth_dev == NULL) {
858 : 0 : PMD_LOG_ERR(INIT, "Can not allocate ethdev");
859 : 0 : ret = -ENOMEM;
860 : 0 : goto l_end;
861 : : }
862 : : } else {
863 [ # # ]: 0 : if (!eth_dev) {
864 : 0 : PMD_LOG_DEBUG(INIT, "Can not attach secondary ethdev");
865 : 0 : ret = -EINVAL;
866 : 0 : goto l_end;
867 : : }
868 : : }
869 : :
870 : 0 : adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(eth_dev);
871 : 0 : adapter->dev_port_id = eth_dev->data->port_id;
872 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
873 : 0 : adapter->cdev = cdev;
874 : :
875 : 0 : ret = sxe2_dev_init(eth_dev, kvargs);
876 [ # # ]: 0 : if (ret != 0) {
877 : 0 : PMD_DEV_LOG_ERR(adapter, INIT, "Sxe2 dev init failed, ret=%d", ret);
878 : 0 : goto l_release_port;
879 : : }
880 : :
881 : 0 : rte_eth_dev_probing_finish(eth_dev);
882 : 0 : PMD_DEV_LOG_DEBUG(adapter, INIT, "Sxe2 eth pmd probe successful!");
883 : 0 : goto l_end;
884 : :
885 : 0 : l_release_port:
886 : 0 : (void)rte_eth_dev_release_port(eth_dev);
887 : 0 : l_end:
888 : 0 : return ret;
889 : : }
890 : :
891 : 0 : static int32_t sxe2_parse_eth_devargs(struct rte_device *dev,
892 : : struct rte_eth_devargs *eth_da)
893 : : {
894 : 0 : int ret = 0;
895 : :
896 [ # # ]: 0 : if (dev->devargs == NULL)
897 : : return 0;
898 : :
899 [ # # ]: 0 : memset(eth_da, 0, sizeof(*eth_da));
900 : :
901 [ # # ]: 0 : if (dev->devargs->cls_str) {
902 : 0 : ret = rte_eth_devargs_parse(dev->devargs->cls_str,
903 : : eth_da,
904 : : 1);
905 [ # # ]: 0 : if (ret) {
906 : 0 : PMD_LOG_ERR(INIT, "Failed to parse device arguments: %s",
907 : : dev->devargs->cls_str);
908 : 0 : return -rte_errno;
909 : : }
910 : : }
911 : :
912 [ # # # # ]: 0 : if (eth_da->type == RTE_ETH_REPRESENTOR_NONE && dev->devargs->args) {
913 : 0 : ret = rte_eth_devargs_parse(dev->devargs->args,
914 : : eth_da,
915 : : 1);
916 [ # # ]: 0 : if (ret) {
917 : 0 : PMD_LOG_ERR(INIT, "Failed to parse device arguments: %s",
918 : : dev->devargs->args);
919 : 0 : return -rte_errno;
920 : : }
921 : : }
922 : :
923 : : return 0;
924 : : }
925 : :
926 : 0 : static int32_t sxe2_eth_pmd_probe(struct sxe2_common_device *cdev,
927 : : struct sxe2_dev_kvargs_info *kvargs)
928 : : {
929 : 0 : struct rte_eth_devargs eth_da = { .nb_ports = 0 };
930 : 0 : int32_t ret = 0;
931 : :
932 : 0 : ret = sxe2_parse_eth_devargs(cdev->dev, ð_da);
933 [ # # ]: 0 : if (ret != 0) {
934 : 0 : ret = -EINVAL;
935 : 0 : goto l_end;
936 : : }
937 : :
938 : 0 : ret = sxe2_eth_pmd_probe_pf(cdev, ð_da, 0, kvargs);
939 : :
940 : 0 : l_end:
941 : 0 : return ret;
942 : : }
943 : :
944 : : static struct sxe2_class_driver sxe2_eth_pmd = {
945 : : .drv_class = SXE2_CLASS_TYPE_ETH,
946 : : .name = "SXE2_ETH_PMD_DRIVER_NAME",
947 : : .probe = sxe2_eth_pmd_probe,
948 : : .remove = sxe2_eth_pmd_remove,
949 : : .id_table = pci_id_sxe2_tbl,
950 : : .intr_lsc = 1,
951 : : .intr_rmv = 1,
952 : : };
953 : :
954 : 286 : RTE_INIT(rte_sxe2_pmd_init)
955 : : {
956 : 286 : sxe2_common_init();
957 : 286 : sxe2_class_driver_register(&sxe2_eth_pmd);
958 : 286 : }
959 : :
960 : : RTE_PMD_EXPORT_NAME(net_sxe2);
961 : : RTE_PMD_REGISTER_PCI_TABLE(net_sxe2, pci_id_sxe2_tbl);
962 : : RTE_PMD_REGISTER_KMOD_DEP(net_sxe2, "* sxe2");
963 : :
964 [ - + ]: 286 : RTE_LOG_REGISTER_SUFFIX(sxe2_log_init, init, NOTICE);
965 [ - + ]: 286 : RTE_LOG_REGISTER_SUFFIX(sxe2_log_driver, driver, NOTICE);
966 [ - + ]: 286 : RTE_LOG_REGISTER_SUFFIX(sxe2_log_rx, rx, NOTICE);
967 [ - + ]: 286 : RTE_LOG_REGISTER_SUFFIX(sxe2_log_tx, tx, NOTICE);
968 [ - + ]: 286 : RTE_LOG_REGISTER_SUFFIX(sxe2_log_hw, hw, NOTICE);
|