[golan] Add Connect-IB, ConnectX-4 and ConnectX-4 Lx (Infiniband) support
[ipxe.git] / src / drivers / infiniband / mlx_utils / mlx_lib / mlx_nvconfig / mlx_nvconfig_defaults.c
1 /*
2 * Copyright (C) 2015 Mellanox Technologies Ltd.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 FILE_LICENCE( GPL2_OR_LATER);
21
22 #include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig.h"
23 #include "../../include/public/mlx_memory.h"
24 #include "../../include/public/mlx_bail.h"
25 #include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h"
26
27 struct tlv_default {
28 mlx_uint16 tlv_type;
29 mlx_size data_size;
30 mlx_status (*set_defaults)( IN void *data, IN int status,
31 OUT void *def_struct);
32 };
33
34 #define TlvDefaultEntry( _tlv_type, _data_size, _set_defaults) { \
35 .tlv_type = _tlv_type, \
36 .data_size = sizeof ( _data_size ), \
37 .set_defaults = _set_defaults, \
38 }
39
40 static
41 mlx_status
42 nvconfig_get_boot_default_conf(
43 IN void *data,
44 IN int status,
45 OUT void *def_struct
46 )
47 {
48 union mlx_nvconfig_nic_boot_conf *nic_boot_conf =
49 (union mlx_nvconfig_nic_boot_conf *) data;
50 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
51 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
52
53 /* boot_option_rom_en is deprecated - enabled always */
54 port_conf_def->boot_option_rom_en = DEFAULT_OPTION_ROM_EN;
55
56 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
57 "TLV not found. Using hard-coded defaults ");
58 port_conf_def->boot_vlan = nic_boot_conf->vlan_id;
59 port_conf_def->boot_protocol = nic_boot_conf->legacy_boot_prot;
60 port_conf_def->boot_retry_count = nic_boot_conf->boot_retry_count;
61 port_conf_def->boot_vlan_en = nic_boot_conf->en_vlan;
62
63 return MLX_SUCCESS;
64
65 nvdata_access_err:
66 port_conf_def->boot_vlan = DEFAULT_BOOT_VLAN;
67 port_conf_def->boot_protocol = DEFAULT_BOOT_PROTOCOL;
68
69 return status;
70 }
71
72 static
73 mlx_status
74 nvconfig_get_boot_ext_default_conf(
75 IN void *data,
76 IN int status,
77 OUT void *def_struct
78 )
79 {
80 union mlx_nvconfig_nic_boot_ext_conf *nic_boot_ext_conf =
81 (union mlx_nvconfig_nic_boot_ext_conf *) data;
82 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
83 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
84
85 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
86 "TLV not found. Using hard-coded defaults ");
87 port_conf_def->linkup_timeout = nic_boot_ext_conf->linkup_timeout;
88 port_conf_def->ip_ver = nic_boot_ext_conf->ip_ver;
89
90 return MLX_SUCCESS;
91
92 nvdata_access_err:
93 port_conf_def->linkup_timeout = DEFAULT_BOOT_LINK_UP_TO;
94 port_conf_def->ip_ver = DEFAULT_BOOT_IP_VER;
95
96 return status;
97 }
98
99 static
100 mlx_status
101 nvconfig_get_iscsi_init_dhcp_default_conf(
102 IN void *data,
103 IN int status,
104 OUT void *def_struct
105 )
106 {
107 union mlx_nvconfig_iscsi_init_dhcp_conf *iscsi_init_dhcp_conf =
108 (union mlx_nvconfig_iscsi_init_dhcp_conf *) data;
109 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
110 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
111
112 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
113 "TLV not found. Using hard-coded defaults ");
114 port_conf_def->iscsi_dhcp_params_en = iscsi_init_dhcp_conf->dhcp_iscsi_en;
115 port_conf_def->iscsi_ipv4_dhcp_en = iscsi_init_dhcp_conf->ipv4_dhcp_en;
116
117 return MLX_SUCCESS;
118
119 nvdata_access_err:
120 port_conf_def->iscsi_dhcp_params_en = DEFAULT_ISCSI_DHCP_PARAM_EN;
121 port_conf_def->iscsi_ipv4_dhcp_en = DEFAULT_ISCSI_IPV4_DHCP_EN;
122
123 return status;
124 }
125
126 static
127 mlx_status
128 nvconfig_get_ib_boot_default_conf(
129 IN void *data,
130 IN int status,
131 OUT void *def_struct
132 )
133 {
134 union mlx_nvconfig_nic_ib_boot_conf *ib_boot_conf =
135 (union mlx_nvconfig_nic_ib_boot_conf *) data;
136 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
137 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
138
139 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
140 "nvconfig_nvdata_default_access failed ");
141 port_conf_def->boot_pkey = ib_boot_conf->boot_pkey;
142
143 nvdata_access_err:
144 return status;
145 }
146
147 static
148 mlx_status
149 nvconfig_get_wol_default_conf(
150 IN void *data,
151 IN int status,
152 OUT void *def_struct
153 )
154 {
155 union mlx_nvconfig_wol_conf *wol_conf = (union mlx_nvconfig_wol_conf *) data;
156 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
157 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
158
159 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
160 "nvconfig_nvdata_default_access failed ");
161 port_conf_def->en_wol_magic = wol_conf->en_wol_magic;
162
163 nvdata_access_err:
164 return status;
165 }
166
167 static
168 mlx_status
169 nvconfig_get_iscsi_gen_default_conf(
170 IN void *data,
171 IN int status,
172 OUT void *def_struct)
173 {
174 union mlx_nvconfig_iscsi_general *iscsi_gen =
175 (union mlx_nvconfig_iscsi_general *) data;
176 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
177 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
178
179 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
180 "nvconfig_nvdata_default_access failed ");
181 port_conf_def->iscsi_boot_to_target = iscsi_gen->boot_to_target;
182 port_conf_def->iscsi_vlan_en = iscsi_gen->vlan_en;
183 port_conf_def->iscsi_tcp_timestamps_en = iscsi_gen->tcp_timestamps_en;
184 port_conf_def->iscsi_chap_mutual_auth_en = iscsi_gen->chap_mutual_auth_en;
185 port_conf_def->iscsi_chap_auth_en = iscsi_gen->chap_auth_en;
186 port_conf_def->iscsi_lun_busy_retry_count = iscsi_gen->lun_busy_retry_count;
187 port_conf_def->iscsi_link_up_delay_time = iscsi_gen->link_up_delay_time;
188
189 nvdata_access_err:
190 return status;
191 }
192
193 static
194 mlx_status
195 nvconfig_get_ib_dhcp_default_conf(
196 IN void *data,
197 IN int status,
198 OUT void *def_struct
199 )
200 {
201 union mlx_nvconfig_ib_dhcp_conf *ib_dhcp =
202 (union mlx_nvconfig_ib_dhcp_conf *) data;
203 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
204 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
205
206 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
207 "nvconfig_nvdata_default_access failed ");
208 port_conf_def->client_identifier = ib_dhcp->client_identifier;
209 port_conf_def->mac_admin_bit = ib_dhcp->mac_admin_bit;
210
211 nvdata_access_err:
212 return status;
213 }
214
215 static
216 mlx_status
217 nvconfig_get_ocsd_ocbb_default_conf( IN void *data,
218 IN int status, OUT void *def_struct) {
219 union mlx_nvconfig_ocsd_ocbb_conf *ocsd_ocbb =
220 (union mlx_nvconfig_ocsd_ocbb_conf *) data;
221 struct mlx_nvconfig_conf_defaults *conf_def =
222 (struct mlx_nvconfig_conf_defaults *) def_struct;
223
224 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
225 "TLV not found. Using hard-coded defaults ");
226 conf_def->ocsd_ocbb_en = ocsd_ocbb->ocsd_ocbb_en;
227
228 return MLX_SUCCESS;
229
230 nvdata_access_err:
231 conf_def->ocsd_ocbb_en = DEFAULT_OCSD_OCBB_EN;
232
233 return status;
234 }
235
236 static
237 mlx_status
238 nvconfig_get_vpi_link_default_conf(
239 IN void *data,
240 IN int status,
241 OUT void *def_struct
242 )
243 {
244 union mlx_nvconfig_vpi_link_conf *vpi_link =
245 (union mlx_nvconfig_vpi_link_conf *) data;
246 struct mlx_nvconfig_port_conf_defaults *port_conf_def =
247 (struct mlx_nvconfig_port_conf_defaults *) def_struct;
248
249 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
250 "nvconfig_nvdata_default_access failed ");
251 port_conf_def->network_link_type = vpi_link->network_link_type;
252 port_conf_def->default_link_type = vpi_link->default_link_type;
253
254 nvdata_access_err:
255 return status;
256 }
257
258 static
259 mlx_status
260 nvconfig_get_rom_banner_to_default_conf(
261 IN void *data,
262 IN int status,
263 OUT void *def_struct
264 )
265 {
266 union mlx_nvconfig_rom_banner_timeout_conf *rom_banner_timeout_conf =
267 (union mlx_nvconfig_rom_banner_timeout_conf *) data;
268 struct mlx_nvconfig_conf_defaults *conf_def =
269 (struct mlx_nvconfig_conf_defaults *) def_struct;
270
271 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
272 "TLV not found. Using hard-coded defaults ");
273 conf_def->flexboot_menu_to = rom_banner_timeout_conf->rom_banner_to;
274
275 return MLX_SUCCESS;
276
277 nvdata_access_err:
278 conf_def->flexboot_menu_to = DEFAULT_FLEXBOOT_MENU_TO;
279
280 return status;
281 }
282
283 static
284 mlx_status
285 nvconfig_get_nv_virt_caps_default_conf(
286 IN void *data,
287 IN int status,
288 OUT void *def_struct
289 )
290 {
291 union mlx_nvconfig_virt_caps *nv_virt_caps =
292 (union mlx_nvconfig_virt_caps *) data;
293 struct mlx_nvconfig_conf_defaults *conf_def =
294 (struct mlx_nvconfig_conf_defaults *) def_struct;
295
296 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
297 "TLV not found. Using hard-coded defaults ");
298 conf_def->max_vfs = nv_virt_caps->max_vfs_per_pf;
299
300 return MLX_SUCCESS;
301
302 nvdata_access_err:
303 conf_def->max_vfs = DEFAULT_MAX_VFS;
304
305 return status;
306 }
307
308 static
309 mlx_status
310 nvconfig_get_nv_virt_default_conf(
311 IN void *data,
312 IN int status,
313 OUT void *def_struct
314 )
315 {
316 union mlx_nvconfig_virt_conf *nv_virt_conf =
317 (union mlx_nvconfig_virt_conf *) data;
318 struct mlx_nvconfig_conf_defaults *conf_def =
319 (struct mlx_nvconfig_conf_defaults *) def_struct;
320
321 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
322 "nvconfig_nvdata_default_access failed ");
323 conf_def->total_vfs = nv_virt_conf->num_of_vfs;
324 conf_def->sriov_en = nv_virt_conf->virt_mode;
325
326 nvdata_access_err:
327 return status;
328 }
329
330 static struct tlv_default tlv_port_defaults[] = {
331 TlvDefaultEntry(BOOT_SETTINGS_TYPE, union mlx_nvconfig_nic_boot_conf, &nvconfig_get_boot_default_conf),
332 TlvDefaultEntry(BOOT_SETTINGS_EXT_TYPE, union mlx_nvconfig_nic_boot_ext_conf, &nvconfig_get_boot_ext_default_conf),
333 TlvDefaultEntry(ISCSI_INITIATOR_DHCP_CONF_TYPE, union mlx_nvconfig_iscsi_init_dhcp_conf, &nvconfig_get_iscsi_init_dhcp_default_conf),
334 TlvDefaultEntry(IB_BOOT_SETTING_TYPE, union mlx_nvconfig_nic_ib_boot_conf, &nvconfig_get_ib_boot_default_conf),
335 TlvDefaultEntry(WAKE_ON_LAN_TYPE, union mlx_nvconfig_wol_conf, &nvconfig_get_wol_default_conf),
336 TlvDefaultEntry(ISCSI_GENERAL_SETTINGS_TYPE, union mlx_nvconfig_iscsi_general, &nvconfig_get_iscsi_gen_default_conf),
337 TlvDefaultEntry(IB_DHCP_SETTINGS_TYPE, union mlx_nvconfig_ib_dhcp_conf, &nvconfig_get_ib_dhcp_default_conf),
338 TlvDefaultEntry(VPI_LINK_TYPE, union mlx_nvconfig_vpi_link_conf, &nvconfig_get_vpi_link_default_conf),
339 };
340
341 static struct tlv_default tlv_general_defaults[] = {
342 TlvDefaultEntry(BANNER_TO_TYPE, union mlx_nvconfig_rom_banner_timeout_conf, &nvconfig_get_rom_banner_to_default_conf),
343 TlvDefaultEntry(GLOPAL_PCI_CAPS_TYPE, union mlx_nvconfig_virt_caps, &nvconfig_get_nv_virt_caps_default_conf),
344 TlvDefaultEntry(GLOPAL_PCI_SETTINGS_TYPE, union mlx_nvconfig_virt_conf, &nvconfig_get_nv_virt_default_conf),
345 TlvDefaultEntry(OCSD_OCBB_TYPE, union mlx_nvconfig_ocsd_ocbb_conf, &nvconfig_get_ocsd_ocbb_default_conf),
346 };
347
348 static
349 mlx_status
350 nvconfig_nvdata_default_access(
351 IN mlx_utils *utils,
352 IN mlx_uint8 port,
353 IN mlx_uint16 tlv_type,
354 IN mlx_size data_size,
355 OUT mlx_void *data
356 )
357 {
358 mlx_status status = MLX_SUCCESS;
359 mlx_uint32 index;
360 mlx_uint8 version = 0;
361
362 status = nvconfig_nvdata_access(utils, port, tlv_type, REG_ACCESS_READ,
363 data_size, TLV_ACCESS_DEFAULT_EN, &version, data);
364 MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
365 "nvconfig_nvdata_access failed ");
366 for (index = 0; index * 4 < data_size; index++) {
367 mlx_memory_be32_to_cpu(utils, (((mlx_uint32 *) data)[index]),
368 ((mlx_uint32 *) data) + index);
369 }
370
371 nvdata_access_err:
372 return status;
373 }
374
375 static
376 mlx_status
377 nvconfig_nvdata_read_default_value(
378 IN mlx_utils *utils,
379 IN mlx_uint8 modifier,
380 IN struct tlv_default *def,
381 OUT void *def_struct
382 )
383 {
384 mlx_status status = MLX_SUCCESS;
385 void *data = NULL;
386
387 status = mlx_memory_zalloc(utils, def->data_size,&data);
388 MLX_CHECK_STATUS(utils, status, memory_err,
389 "mlx_memory_zalloc failed ");
390 status = nvconfig_nvdata_default_access(utils, modifier, def->tlv_type,
391 def->data_size, data);
392 def->set_defaults(data, status, def_struct);
393 mlx_memory_free(utils, &data);
394
395 memory_err:
396 return status;
397 }
398
399 static
400 void
401 nvconfig_nvdata_read_default_values(
402 IN mlx_utils *utils,
403 IN mlx_uint8 modifier,
404 IN struct tlv_default defaults_table[],
405 IN mlx_uint8 defaults_table_size,
406 OUT void *def_strct
407 )
408 {
409 struct tlv_default *defs;
410 unsigned int i;
411
412 for (i = 0; i < defaults_table_size; i++) {
413 defs = &defaults_table[i];
414 nvconfig_nvdata_read_default_value(utils, modifier, defs, def_strct);
415 }
416 }
417
418 mlx_status
419 nvconfig_read_port_default_values(
420 IN mlx_utils *utils,
421 IN mlx_uint8 port,
422 OUT struct mlx_nvconfig_port_conf_defaults *port_conf_def
423 )
424 {
425 mlx_status status = MLX_SUCCESS;
426
427 if (utils == NULL || port_conf_def == NULL) {
428 status = MLX_INVALID_PARAMETER;
429 MLX_DEBUG_ERROR(utils,"bad params.");
430 goto bad_param;
431 }
432 mlx_memory_set(utils, port_conf_def, 0, sizeof(*port_conf_def));
433 nvconfig_nvdata_read_default_values(utils, port, tlv_port_defaults,
434 (sizeof(tlv_port_defaults)/sizeof(tlv_port_defaults[0])),
435 port_conf_def);
436
437 bad_param:
438 return status;
439 }
440
441 mlx_status
442 nvconfig_read_general_default_values(
443 IN mlx_utils *utils,
444 OUT struct mlx_nvconfig_conf_defaults *conf_def
445 )
446 {
447 mlx_status status = MLX_SUCCESS;
448
449 if (utils == NULL || conf_def == NULL) {
450 status = MLX_INVALID_PARAMETER;
451 MLX_DEBUG_ERROR(utils,"bad params.");
452 goto bad_param;
453 }
454 mlx_memory_set(utils, conf_def, 0, sizeof(*conf_def));
455 nvconfig_nvdata_read_default_values(utils, 0, tlv_general_defaults,
456 (sizeof(tlv_general_defaults)/sizeof(tlv_general_defaults[0])),
457 conf_def);
458
459 bad_param:
460 return status;
461 }
462
463 mlx_status
464 nvconfig_read_rom_ini_values(
465 IN mlx_utils *utils,
466 OUT struct mlx_nvcofnig_romini *rom_ini
467 )
468 {
469 mlx_status status = MLX_SUCCESS;
470
471 if (utils == NULL || rom_ini == NULL) {
472 status = MLX_INVALID_PARAMETER;
473 MLX_DEBUG_ERROR(utils,"bad params.");
474 goto bad_param;
475 }
476 mlx_memory_set(utils, rom_ini, 0, sizeof(*rom_ini));
477
478 status = nvconfig_nvdata_default_access(utils, 0, GLOBAL_ROM_INI_TYPE,
479 sizeof(*rom_ini), rom_ini);
480 bad_param:
481 return status;
482 }