iPXE
mlx_nvconfig_defaults.c
Go to the documentation of this file.
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 {
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
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 =
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 */
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
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 =
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  port_conf_def->undi_network_wait_to = nic_boot_ext_conf->undi_network_wait_to;
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;
96  return status;
97 }
98 
99 static
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 =
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:
122 
123  return status;
124 }
125 
126 static
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 =
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
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
170  IN void *data,
171  IN int status,
172  OUT void *def_struct)
173 {
174  union mlx_nvconfig_iscsi_general *iscsi_gen =
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  port_conf_def->iscsi_drive_num = iscsi_gen->drive_num;
189 
190  return MLX_SUCCESS;
191 
192 nvdata_access_err:
193  port_conf_def->iscsi_drive_num = DEFAULT_ISCSI_DRIVE_NUM;
194  return status;
195 }
196 
197 static
200  IN void *data,
201  IN int status,
202  OUT void *def_struct
203  )
204 {
205  union mlx_nvconfig_ib_dhcp_conf *ib_dhcp =
207  struct mlx_nvconfig_port_conf_defaults *port_conf_def =
208  (struct mlx_nvconfig_port_conf_defaults *) def_struct;
209 
210  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
211  "nvconfig_nvdata_default_access failed ");
212  port_conf_def->client_identifier = ib_dhcp->client_identifier;
213  port_conf_def->mac_admin_bit = ib_dhcp->mac_admin_bit;
214 
215 nvdata_access_err:
216  return status;
217 }
218 
219 static
222  IN int status, OUT void *def_struct) {
223  union mlx_nvconfig_ocsd_ocbb_conf *ocsd_ocbb =
225  struct mlx_nvconfig_conf_defaults *conf_def =
226  (struct mlx_nvconfig_conf_defaults *) def_struct;
227 
228  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
229  "TLV not found. Using hard-coded defaults ");
230  conf_def->ocsd_ocbb_en = ocsd_ocbb->ocsd_ocbb_en;
231 
232  return MLX_SUCCESS;
233 
234 nvdata_access_err:
236 
237  return status;
238 }
239 
240 static
243  IN void *data,
244  IN int status,
245  OUT void *def_struct
246  )
247 {
248  union mlx_nvconfig_vpi_link_conf *vpi_link =
250  struct mlx_nvconfig_port_conf_defaults *port_conf_def =
251  (struct mlx_nvconfig_port_conf_defaults *) def_struct;
252 
253  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
254  "nvconfig_nvdata_default_access failed ");
255  port_conf_def->network_link_type = vpi_link->network_link_type;
256  port_conf_def->default_link_type = vpi_link->default_link_type;
257 
258 nvdata_access_err:
259  return status;
260 }
261 
262 static
265  IN void *data,
266  IN int status,
267  OUT void *def_struct
268  )
269 {
270  union mlx_nvconfig_rom_banner_timeout_conf *rom_banner_timeout_conf =
272  struct mlx_nvconfig_conf_defaults *conf_def =
273  (struct mlx_nvconfig_conf_defaults *) def_struct;
274 
275  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
276  "TLV not found. Using hard-coded defaults ");
277  conf_def->flexboot_menu_to = rom_banner_timeout_conf->rom_banner_to;
278 
279  return MLX_SUCCESS;
280 
281 nvdata_access_err:
283 
284  return status;
285 }
286 
287 static
290  IN void *data,
291  IN int status,
292  OUT void *def_struct
293  )
294 {
295  union mlx_nvconfig_virt_caps *nv_virt_caps =
296  (union mlx_nvconfig_virt_caps *) data;
297  struct mlx_nvconfig_conf_defaults *conf_def =
298  (struct mlx_nvconfig_conf_defaults *) def_struct;
299 
300  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
301  "TLV not found. Using hard-coded defaults ");
302  conf_def->max_vfs = nv_virt_caps->max_vfs_per_pf;
303 
304  return MLX_SUCCESS;
305 
306 nvdata_access_err:
307  conf_def->max_vfs = DEFAULT_MAX_VFS;
308 
309  return status;
310 }
311 
312 static
315  IN void *data,
316  IN int status,
317  OUT void *def_struct
318  )
319 {
320  union mlx_nvconfig_virt_conf *nv_virt_conf =
321  (union mlx_nvconfig_virt_conf *) data;
322  struct mlx_nvconfig_conf_defaults *conf_def =
323  (struct mlx_nvconfig_conf_defaults *) def_struct;
324 
325  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
326  "nvconfig_nvdata_default_access failed ");
327  conf_def->total_vfs = nv_virt_conf->num_of_vfs;
328  conf_def->sriov_en = nv_virt_conf->virt_mode;
329 
330 nvdata_access_err:
331  return status;
332 }
333 
334 static
337  IN int status, OUT void *def_struct) {
338  union mlx_nvconfig_rom_cap_conf *rom_cap_conf =
340  struct mlx_nvconfig_conf_defaults *conf_def =
341  (struct mlx_nvconfig_conf_defaults *) def_struct;
342 
343  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
344  "TLV not found. Using hard-coded defaults ");
345  conf_def->boot_ip_ver_en = rom_cap_conf->boot_ip_ver_en;
346 
347  return MLX_SUCCESS;
348 
349 nvdata_access_err:
351 
352  return status;
353 }
354 
355 static struct tlv_default tlv_port_defaults[] = {
364 };
365 
372 };
373 
374 static
377  IN mlx_utils *utils,
378  IN mlx_uint8 port,
381  OUT mlx_void *data
382  )
383 {
386  mlx_uint8 version = 0;
387 
390  &version, data);
391  MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
392  "nvconfig_nvdata_access failed ");
393  for (index = 0; index * 4 < data_size; index++) {
395  ((mlx_uint32 *) data) + index);
396  }
397 
398 nvdata_access_err:
399  return status;
400 }
401 
402 static
405  IN mlx_utils *utils,
406  IN mlx_uint8 modifier,
407  IN struct tlv_default *def,
408  OUT void *def_struct
409  )
410 {
412  void *data = NULL;
413 
414  status = mlx_memory_zalloc(utils, def->data_size,&data);
415  MLX_CHECK_STATUS(utils, status, memory_err,
416  "mlx_memory_zalloc failed ");
417  status = nvconfig_nvdata_default_access(utils, modifier, def->tlv_type,
418  def->data_size, data);
419  def->set_defaults(data, status, def_struct);
420  mlx_memory_free(utils, &data);
421 
422 memory_err:
423  return status;
424 }
425 
426 static
427 void
429  IN mlx_utils *utils,
430  IN mlx_uint8 modifier,
431  IN struct tlv_default defaults_table[],
432  IN mlx_uint8 defaults_table_size,
433  OUT void *def_strct
434  )
435 {
436  struct tlv_default *defs;
437  unsigned int i;
438 
439  for (i = 0; i < defaults_table_size; i++) {
440  defs = &defaults_table[i];
441  nvconfig_nvdata_read_default_value(utils, modifier, defs, def_strct);
442  }
443 }
444 
447  IN mlx_utils *utils,
448  IN mlx_uint8 port,
449  OUT struct mlx_nvconfig_port_conf_defaults *port_conf_def
450  )
451 {
453 
454  if (utils == NULL || port_conf_def == NULL) {
456  MLX_DEBUG_ERROR(utils,"bad params.");
457  goto bad_param;
458  }
459  mlx_memory_set(utils, port_conf_def, 0, sizeof(*port_conf_def));
461  (sizeof(tlv_port_defaults)/sizeof(tlv_port_defaults[0])),
462  port_conf_def);
463 
464 bad_param:
465  return status;
466 }
467 
470  IN mlx_utils *utils,
471  OUT struct mlx_nvconfig_conf_defaults *conf_def
472  )
473 {
475 
476  if (utils == NULL || conf_def == NULL) {
478  MLX_DEBUG_ERROR(utils,"bad params.");
479  goto bad_param;
480  }
481  mlx_memory_set(utils, conf_def, 0, sizeof(*conf_def));
483  (sizeof(tlv_general_defaults)/sizeof(tlv_general_defaults[0])),
484  conf_def);
485 
486 bad_param:
487  return status;
488 }
489 
492  IN mlx_utils *utils,
493  OUT struct mlx_nvcofnig_romini *rom_ini
494  )
495 {
497  mlx_uint8 version = 0;
499 
500  if (utils == NULL || rom_ini == NULL) {
502  MLX_DEBUG_ERROR(utils,"bad params.");
503  goto bad_param;
504  }
505  mlx_memory_set(utils, rom_ini, 0, sizeof(*rom_ini));
506 
508  sizeof(*rom_ini), TLV_ACCESS_DEFAULT_DIS, 0,
509  &version, rom_ini);
510  MLX_CHECK_STATUS(NULL, status, bad_param,
511  "nvconfig_nvdata_access failed ");
512  for (index = 0; index * 4 < sizeof(*rom_ini); index++) {
513  mlx_memory_be32_to_cpu(utils, (((mlx_uint32 *) rom_ini)[index]),
514  ((mlx_uint32 *) rom_ini) + index);
515  }
516 
517 bad_param:
518  return status;
519 }
static mlx_status nvconfig_get_rom_banner_to_default_conf(IN void *data, IN int status, OUT void *def_struct)
static mlx_status nvconfig_get_iscsi_init_dhcp_default_conf(IN void *data, IN int status, OUT void *def_struct)
static mlx_status nvconfig_nvdata_default_access(IN mlx_utils *utils, IN mlx_uint8 port, IN mlx_uint16 tlv_type, IN mlx_size data_size, OUT mlx_void *data)
#define MLX_INVALID_PARAMETER
#define DEFAULT_OPTION_ROM_EN
#define DEFAULT_ISCSI_DHCP_PARAM_EN
static struct tlv_default tlv_port_defaults[]
static mlx_status nvconfig_get_boot_default_conf(IN void *data, IN int status, OUT void *def_struct)
static mlx_status nvconfig_get_iscsi_gen_default_conf(IN void *data, IN int status, OUT void *def_struct)
long index
Definition: bigint.h:62
#define DEFAULT_BOOT_IP_VERSION_EN
mlx_status(* set_defaults)(IN void *data, IN int status, OUT void *def_struct)
#define DEFAULT_BOOT_IP_VER
static void nvconfig_nvdata_read_default_values(IN mlx_utils *utils, IN mlx_uint8 modifier, IN struct tlv_default defaults_table[], IN mlx_uint8 defaults_table_size, OUT void *def_strct)
mlx_status nvconfig_read_port_default_values(IN mlx_utils *utils, IN mlx_uint8 port, OUT struct mlx_nvconfig_port_conf_defaults *port_conf_def)
uint32_t mlx_uint32
mlx_status mlx_memory_free(IN mlx_utils *utils, IN mlx_void **ptr)
Definition: mlx_memory.c:63
mlx_status mlx_memory_set(IN mlx_utils *utils, IN mlx_void *block, IN mlx_int32 value, IN mlx_size size)
Definition: mlx_memory.c:171
u8 port
Port number.
Definition: CIB_PRM.h:31
u32 version
Driver version.
Definition: ath9k_hw.c:1983
#define OUT
Definition: mlx_utils.h:29
static mlx_status nvconfig_get_vpi_link_default_conf(IN void *data, IN int status, OUT void *def_struct)
static mlx_status nvconfig_get_ib_boot_default_conf(IN void *data, IN int status, OUT void *def_struct)
#define DEFAULT_BOOT_UNDI_NETWORK_WAIT_TO
#define DEFAULT_ISCSI_IPV4_DHCP_EN
#define MLX_SUCCESS
static mlx_status nvconfig_get_wol_default_conf(IN void *data, IN int status, OUT void *def_struct)
static mlx_status nvconfig_nvdata_read_default_value(IN mlx_utils *utils, IN mlx_uint8 modifier, IN struct tlv_default *def, OUT void *def_struct)
mlx_status nvconfig_read_rom_ini_values(IN mlx_utils *utils, OUT struct mlx_nvcofnig_romini *rom_ini)
mlx_status nvconfig_read_general_default_values(IN mlx_utils *utils, OUT struct mlx_nvconfig_conf_defaults *conf_def)
size_t mlx_size
static mlx_status nvconfig_get_rom_cap_default_conf(IN void *data, IN int status, OUT void *def_struct)
static mlx_status nvconfig_get_nv_virt_caps_default_conf(IN void *data, IN int status, OUT void *def_struct)
uint16_t mlx_uint16
uint8_t status
Status.
Definition: ena.h:16
void mlx_void
#define IN
Definition: mlx_utils.h:28
#define TlvDefaultEntry(_tlv_type, _data_size, _set_defaults)
uint8_t mlx_uint8
static mlx_status nvconfig_get_nv_virt_default_conf(IN void *data, IN int status, OUT void *def_struct)
mlx_status mlx_memory_zalloc(IN mlx_utils *utils, IN mlx_size size, OUT mlx_void **ptr)
Definition: mlx_memory.c:45
#define DEFAULT_BOOT_VLAN
FILE_LICENCE(GPL2_OR_LATER)
static mlx_status nvconfig_get_ocsd_ocbb_default_conf(IN void *data, IN int status, OUT void *def_struct)
#define MLX_DEBUG_ERROR(...)
Definition: mlx_logging.h:29
static mlx_status nvconfig_get_boot_ext_default_conf(IN void *data, IN int status, OUT void *def_struct)
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define DEFAULT_FLEXBOOT_MENU_TO
#define DEFAULT_MAX_VFS
int mlx_status
mlx_status mlx_memory_be32_to_cpu(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
Definition: mlx_memory.c:224
#define DEFAULT_ISCSI_DRIVE_NUM
static struct tlv_default tlv_general_defaults[]
#define MLX_CHECK_STATUS(id, status, label, message)
Definition: mlx_bail.h:37
#define DEFAULT_BOOT_LINK_UP_TO
static mlx_status nvconfig_get_ib_dhcp_default_conf(IN void *data, IN int status, OUT void *def_struct)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define DEFAULT_OCSD_OCBB_EN
mlx_status nvconfig_nvdata_access(IN mlx_utils *utils, IN mlx_uint8 port, IN mlx_uint16 tlv_type, IN REG_ACCESS_OPT opt, IN mlx_size data_size, IN NV_DEFAULT_OPT def_en, IN NVDA_WRITER_ID writer_id, IN OUT mlx_uint8 *version, IN OUT mlx_void *data)
Definition: mlx_nvconfig.c:235
#define DEFAULT_BOOT_PROTOCOL