Branch data Line data Source code
1 : : /*
2 : : * SPDX-License-Identifier: BSD-3-Clause
3 : : * Copyright(c) 2023 Napatech A/S
4 : : */
5 : :
6 : : #include "nt_service.h"
7 : : #include "ntlog.h"
8 : : #include "nthw_fpga.h"
9 : : #include "ntnic_mod_reg.h"
10 : :
11 : : /*
12 : : * Global variables shared by NT adapter types
13 : : */
14 : :
15 : 0 : static int nt4ga_adapter_show_info(struct adapter_info_s *p_adapter_info, FILE *pfh)
16 : : {
17 : 0 : const char *const p_dev_name = p_adapter_info->p_dev_name;
18 : 0 : const char *const p_adapter_id_str = p_adapter_info->mp_adapter_id_str;
19 : : fpga_info_t *p_fpga_info = &p_adapter_info->fpga_info;
20 : : hw_info_t *p_hw_info = &p_adapter_info->hw_info;
21 : : mcu_info_t *mcu_info = &p_adapter_info->fpga_info.mcu_info;
22 : : char a_pci_ident_str[32];
23 : :
24 : 0 : snprintf(a_pci_ident_str, sizeof(a_pci_ident_str), PCIIDENT_PRINT_STR,
25 : 0 : PCIIDENT_TO_DOMAIN(p_fpga_info->pciident),
26 : 0 : PCIIDENT_TO_BUSNR(p_fpga_info->pciident),
27 : 0 : PCIIDENT_TO_DEVNR(p_fpga_info->pciident),
28 [ # # ]: 0 : PCIIDENT_TO_FUNCNR(p_fpga_info->pciident));
29 : :
30 [ # # ]: 0 : fprintf(pfh, "%s: DeviceName: %s\n", p_adapter_id_str, (p_dev_name ? p_dev_name : "NA"));
31 : : fprintf(pfh, "%s: PCI Details:\n", p_adapter_id_str);
32 : 0 : fprintf(pfh, "%s: %s: %08X: %04X:%04X %04X:%04X\n", p_adapter_id_str, a_pci_ident_str,
33 : 0 : p_fpga_info->pciident, p_hw_info->pci_vendor_id, p_hw_info->pci_device_id,
34 : 0 : p_hw_info->pci_sub_vendor_id, p_hw_info->pci_sub_device_id);
35 : : fprintf(pfh, "%s: FPGA Details:\n", p_adapter_id_str);
36 : 0 : fprintf(pfh, "%s: %03d-%04d-%02d-%02d [%016" PRIX64 "] (%08X)\n", p_adapter_id_str,
37 : : p_fpga_info->n_fpga_type_id, p_fpga_info->n_fpga_prod_id,
38 : : p_fpga_info->n_fpga_ver_id, p_fpga_info->n_fpga_rev_id, p_fpga_info->n_fpga_ident,
39 : : p_fpga_info->n_fpga_build_time);
40 : 0 : fprintf(pfh, "%s: FpgaDebugMode=0x%x\n", p_adapter_id_str, p_fpga_info->n_fpga_debug_mode);
41 : 0 : fprintf(pfh, "%s: Nims=%d PhyPorts=%d PhyQuads=%d RxPorts=%d TxPorts=%d\n",
42 : : p_adapter_id_str, p_fpga_info->n_nims, p_fpga_info->n_phy_ports,
43 : : p_fpga_info->n_phy_quads, p_fpga_info->n_rx_ports, p_fpga_info->n_tx_ports);
44 : 0 : fprintf(pfh, "%s: Hw=0x%02X_rev%d: %s\n", p_adapter_id_str, p_hw_info->hw_platform_id,
45 : 0 : p_fpga_info->nthw_hw_info.hw_id, p_fpga_info->nthw_hw_info.hw_plat_id_str);
46 : : fprintf(pfh, "%s: MCU Details:\n", p_adapter_id_str);
47 : 0 : fprintf(pfh, "%s: HasMcu=%d McuType=%d McuDramSize=%d\n", p_adapter_id_str,
48 : 0 : mcu_info->mb_has_mcu, mcu_info->mn_mcu_type, mcu_info->mn_mcu_dram_size);
49 : :
50 : 0 : return 0;
51 : : }
52 : :
53 : 0 : static int nt4ga_adapter_init(struct adapter_info_s *p_adapter_info)
54 : : {
55 : 0 : const struct flow_filter_ops *flow_filter_ops = nthw_get_flow_filter_ops();
56 : :
57 [ # # ]: 0 : if (flow_filter_ops == NULL)
58 : 0 : NT_LOG(ERR, NTNIC, "%s: flow_filter module uninitialized", __func__);
59 : :
60 : 0 : char *const p_dev_name = malloc(24);
61 : 0 : char *const p_adapter_id_str = malloc(24);
62 : 0 : fpga_info_t *fpga_info = &p_adapter_info->fpga_info;
63 : : hw_info_t *p_hw_info = &p_adapter_info->hw_info;
64 : :
65 : : RTE_ASSERT(fpga_info);
66 : :
67 : : /*
68 : : * IMPORTANT: Most variables cannot be determined before nthw fpga model is instantiated
69 : : * (nthw_fpga_init())
70 : : */
71 : : int res = -1;
72 : : nthw_fpga_t *p_fpga = NULL;
73 : :
74 : 0 : p_hw_info->n_nthw_adapter_id = nthw_platform_get_adapter_id(p_hw_info->pci_device_id);
75 : :
76 : 0 : fpga_info->n_nthw_adapter_id = p_hw_info->n_nthw_adapter_id;
77 : : /* ref: DN-0060 section 9 */
78 : 0 : p_hw_info->hw_product_type = p_hw_info->pci_device_id & 0x000f;
79 : : /* ref: DN-0060 section 9 */
80 : 0 : p_hw_info->hw_platform_id = (p_hw_info->pci_device_id >> 4) & 0x00ff;
81 : : /* ref: DN-0060 section 9 */
82 : 0 : p_hw_info->hw_reserved1 = (p_hw_info->pci_device_id >> 12) & 0x000f;
83 : :
84 : 0 : p_adapter_info->p_dev_name = p_dev_name;
85 : :
86 [ # # ]: 0 : if (p_dev_name) {
87 : 0 : snprintf(p_dev_name, 24, PCIIDENT_PRINT_STR,
88 : 0 : PCIIDENT_TO_DOMAIN(p_adapter_info->fpga_info.pciident),
89 : 0 : PCIIDENT_TO_BUSNR(p_adapter_info->fpga_info.pciident),
90 : 0 : PCIIDENT_TO_DEVNR(p_adapter_info->fpga_info.pciident),
91 : 0 : PCIIDENT_TO_FUNCNR(p_adapter_info->fpga_info.pciident));
92 : 0 : NT_LOG(DBG, NTNIC, "%s: (0x%08X)", p_dev_name,
93 : : p_adapter_info->fpga_info.pciident);
94 : : }
95 : :
96 : 0 : p_adapter_info->mp_adapter_id_str = p_adapter_id_str;
97 : :
98 : 0 : p_adapter_info->fpga_info.mp_adapter_id_str = p_adapter_id_str;
99 : :
100 [ # # ]: 0 : if (p_adapter_id_str) {
101 : 0 : snprintf(p_adapter_id_str, 24, "PCI:" PCIIDENT_PRINT_STR,
102 : 0 : PCIIDENT_TO_DOMAIN(p_adapter_info->fpga_info.pciident),
103 : 0 : PCIIDENT_TO_BUSNR(p_adapter_info->fpga_info.pciident),
104 : 0 : PCIIDENT_TO_DEVNR(p_adapter_info->fpga_info.pciident),
105 [ # # ]: 0 : PCIIDENT_TO_FUNCNR(p_adapter_info->fpga_info.pciident));
106 [ # # ]: 0 : NT_LOG(DBG, NTNIC, "%s: %s", p_adapter_id_str, p_dev_name ? p_dev_name : "NA");
107 : : }
108 : :
109 : : {
110 : : int i;
111 : :
112 [ # # ]: 0 : for (i = 0; i < (int)ARRAY_SIZE(p_adapter_info->mp_port_id_str); i++) {
113 : 0 : char *p = malloc(32);
114 : :
115 [ # # ]: 0 : if (p) {
116 [ # # ]: 0 : snprintf(p, 32, "%s:intf_%d",
117 : : (p_adapter_id_str ? p_adapter_id_str : "NA"), i);
118 : : }
119 : :
120 : 0 : p_adapter_info->mp_port_id_str[i] = p;
121 : : }
122 : : }
123 : :
124 : 0 : res = nthw_fpga_init(&p_adapter_info->fpga_info);
125 : :
126 [ # # ]: 0 : if (res) {
127 [ # # # # ]: 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: %s: FPGA=%04d res=x%08X",
128 : : p_adapter_id_str ? p_adapter_id_str : "NA",
129 : : p_dev_name ? p_dev_name : "NA", fpga_info->n_fpga_prod_id, res);
130 : 0 : return res;
131 : : }
132 : :
133 : : RTE_ASSERT(fpga_info->n_phy_ports >= 1);
134 : : RTE_ASSERT(fpga_info->n_nims >= 1);
135 : :
136 : 0 : p_fpga = fpga_info->mp_fpga;
137 : : RTE_ASSERT(p_fpga);
138 : :
139 : : /* Nt4ga Init Filter */
140 : : nt4ga_filter_t *p_filter = &p_adapter_info->nt4ga_filter;
141 : :
142 [ # # ]: 0 : if (flow_filter_ops != NULL) {
143 : 0 : res = flow_filter_ops->nthw_flow_filter_init(p_fpga, &p_filter->mp_flow_device,
144 : : p_adapter_info->adapter_no);
145 : :
146 [ # # ]: 0 : if (res != 0) {
147 : 0 : NT_LOG(ERR, NTNIC, "%s: Cannot initialize filter", p_adapter_id_str);
148 : 0 : return res;
149 : : }
150 : : }
151 : :
152 : : {
153 : : int i;
154 : : const struct link_ops_s *link_ops = NULL;
155 : : RTE_ASSERT(fpga_info->n_fpga_prod_id > 0);
156 : :
157 [ # # ]: 0 : for (i = 0; i < NUM_ADAPTER_PORTS_MAX; i++) {
158 : : /* Disable all ports. Must be enabled later */
159 : 0 : p_adapter_info->nt4ga_link.port_action[i].port_disable = true;
160 : : }
161 : :
162 [ # # # ]: 0 : switch (fpga_info->n_fpga_prod_id) {
163 : : /* NT200A01: 2x100G (Xilinx) */
164 : 0 : case 9563: /* NT200A02 (Cap) */
165 : 0 : link_ops = nthw_get_100g_link_ops();
166 : :
167 [ # # ]: 0 : if (link_ops == NULL) {
168 : 0 : NT_LOG(ERR, NTNIC, "NT200A02 100G link module uninitialized");
169 : : res = -1;
170 : : break;
171 : : }
172 : :
173 : 0 : res = link_ops->link_init(p_adapter_info, p_fpga);
174 : 0 : break;
175 : 0 : case 9569: /* NT400D11 (Intel Agilex FPGA) */
176 : : case 9574: /* NT400D13 (Intel Agilex FPGA) */
177 : 0 : link_ops = nthw_get_agx_100g_link_ops();
178 [ # # ]: 0 : if (link_ops == NULL) {
179 : 0 : NT_LOG(ERR, NTNIC, "NT400Dxx 100G link module uninitialized");
180 : : res = -1;
181 : : break;
182 : : }
183 : 0 : res = link_ops->link_init(p_adapter_info, p_fpga);
184 : 0 : break;
185 : :
186 : 0 : default:
187 : 0 : NT_LOG(ERR, NTNIC, "Unsupported FPGA product: %04d",
188 : : fpga_info->n_fpga_prod_id);
189 : : res = -1;
190 : : break;
191 : : }
192 : :
193 [ # # ]: 0 : if (res) {
194 : 0 : NT_LOG_DBGX(ERR, NTNIC, "%s: %s: FPGA=%04d res=x%08X",
195 : : p_adapter_id_str, p_dev_name,
196 : : fpga_info->n_fpga_prod_id, res);
197 : 0 : return res;
198 : : }
199 : : }
200 : :
201 : 0 : const struct nt4ga_stat_ops *nt4ga_stat_ops = nthw_get_nt4ga_stat_ops();
202 : :
203 [ # # ]: 0 : if (nt4ga_stat_ops != NULL) {
204 : : /* Nt4ga Stat init/setup */
205 : 0 : res = nt4ga_stat_ops->nt4ga_stat_init(p_adapter_info);
206 : :
207 [ # # ]: 0 : if (res != 0) {
208 : 0 : NT_LOG(ERR, NTNIC, "%s: Cannot initialize the statistics module",
209 : : p_adapter_id_str);
210 : 0 : return res;
211 : : }
212 : :
213 : 0 : res = nt4ga_stat_ops->nt4ga_stat_setup(p_adapter_info);
214 : :
215 [ # # ]: 0 : if (res != 0) {
216 : 0 : NT_LOG(ERR, NTNIC, "%s: Cannot setup the statistics module",
217 : : p_adapter_id_str);
218 : 0 : return res;
219 : : }
220 : : }
221 : :
222 : : return 0;
223 : : }
224 : :
225 : 0 : static int nt4ga_adapter_deinit(struct adapter_info_s *p_adapter_info)
226 : : {
227 : 0 : const struct flow_filter_ops *flow_filter_ops = nthw_get_flow_filter_ops();
228 : :
229 [ # # ]: 0 : if (flow_filter_ops == NULL)
230 : 0 : NT_LOG(ERR, NTNIC, "%s: flow_filter module uninitialized", __func__);
231 : :
232 : : fpga_info_t *fpga_info = &p_adapter_info->fpga_info;
233 : : int i;
234 : : int res = -1;
235 : :
236 : 0 : nthw_service_del(RTE_NTNIC_SERVICE_ADAPTER_MON);
237 : :
238 : : /* Nt4ga Deinit Filter */
239 : : nt4ga_filter_t *p_filter = &p_adapter_info->nt4ga_filter;
240 : :
241 [ # # ]: 0 : if (flow_filter_ops != NULL) {
242 : 0 : res = flow_filter_ops->nthw_flow_filter_done(p_filter->mp_flow_device);
243 : :
244 [ # # ]: 0 : if (res != 0) {
245 : 0 : NT_LOG(ERR, NTNIC, "Cannot deinitialize filter");
246 : 0 : return res;
247 : : }
248 : : }
249 : :
250 : 0 : nthw_fpga_shutdown(&p_adapter_info->fpga_info);
251 : :
252 : : /* Rac rab reset flip flop */
253 : 0 : res = nthw_rac_rab_reset(fpga_info->mp_nthw_rac);
254 : :
255 : : /* Free adapter port ident strings */
256 [ # # ]: 0 : for (i = 0; i < fpga_info->n_phy_ports; i++) {
257 [ # # ]: 0 : if (p_adapter_info->mp_port_id_str[i]) {
258 : 0 : free(p_adapter_info->mp_port_id_str[i]);
259 : 0 : p_adapter_info->mp_port_id_str[i] = NULL;
260 : : }
261 : : }
262 : :
263 : : /* Free adapter ident string */
264 [ # # ]: 0 : if (p_adapter_info->mp_adapter_id_str) {
265 : 0 : free(p_adapter_info->mp_adapter_id_str);
266 : 0 : p_adapter_info->mp_adapter_id_str = NULL;
267 : : }
268 : :
269 : : /* Free devname ident string */
270 [ # # ]: 0 : if (p_adapter_info->p_dev_name) {
271 : 0 : free(p_adapter_info->p_dev_name);
272 : 0 : p_adapter_info->p_dev_name = NULL;
273 : : }
274 : :
275 : : return res;
276 : : }
277 : :
278 : : static const struct adapter_ops ops = {
279 : : .init = nt4ga_adapter_init,
280 : : .deinit = nt4ga_adapter_deinit,
281 : :
282 : : .show_info = nt4ga_adapter_show_info,
283 : : };
284 : :
285 : 0 : void nthw_adapter_init(void)
286 : : {
287 : 0 : nthw_reg_adapter_ops(&ops);
288 : 0 : }
|