iPXE
mlx_nvconfig_defaults.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Mellanox Technologies Ltd.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 FILE_LICENCE( GPL2_OR_LATER);
00021 
00022 #include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig.h"
00023 #include "../../include/public/mlx_memory.h"
00024 #include "../../include/public/mlx_bail.h"
00025 #include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h"
00026 
00027 struct tlv_default {
00028         mlx_uint16 tlv_type;
00029         mlx_size data_size;
00030         mlx_status (*set_defaults)( IN void *data, IN int status,
00031                         OUT void *def_struct);
00032 };
00033 
00034 #define TlvDefaultEntry( _tlv_type, _data_size, _set_defaults) { \
00035   .tlv_type = _tlv_type,                     \
00036   .data_size = sizeof ( _data_size ),                   \
00037   .set_defaults = _set_defaults,                  \
00038   }
00039 
00040 static
00041 mlx_status
00042 nvconfig_get_boot_default_conf(
00043                 IN void *data,
00044                 IN int status,
00045                 OUT void *def_struct
00046                 )
00047 {
00048         union mlx_nvconfig_nic_boot_conf *nic_boot_conf =
00049                         (union mlx_nvconfig_nic_boot_conf *) data;
00050         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00051                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00052 
00053         /* boot_option_rom_en is deprecated - enabled always */
00054         port_conf_def->boot_option_rom_en = DEFAULT_OPTION_ROM_EN;
00055 
00056         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00057                         "TLV not found. Using hard-coded defaults ");
00058         port_conf_def->boot_vlan = nic_boot_conf->vlan_id;
00059         port_conf_def->boot_protocol = nic_boot_conf->legacy_boot_prot;
00060         port_conf_def->boot_retry_count = nic_boot_conf->boot_retry_count;
00061         port_conf_def->boot_vlan_en = nic_boot_conf->en_vlan;
00062 
00063         return MLX_SUCCESS;
00064 
00065 nvdata_access_err:
00066         port_conf_def->boot_vlan = DEFAULT_BOOT_VLAN;
00067         port_conf_def->boot_protocol = DEFAULT_BOOT_PROTOCOL;
00068 
00069         return status;
00070 }
00071 
00072 static
00073 mlx_status
00074 nvconfig_get_boot_ext_default_conf(
00075                 IN void *data,
00076                 IN int status,
00077                 OUT void *def_struct
00078                 )
00079 {
00080         union mlx_nvconfig_nic_boot_ext_conf *nic_boot_ext_conf =
00081                         (union mlx_nvconfig_nic_boot_ext_conf *) data;
00082         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00083                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00084 
00085         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00086                         "TLV not found. Using hard-coded defaults ");
00087         port_conf_def->linkup_timeout = nic_boot_ext_conf->linkup_timeout;
00088         port_conf_def->ip_ver = nic_boot_ext_conf->ip_ver;
00089         port_conf_def->undi_network_wait_to = nic_boot_ext_conf->undi_network_wait_to;
00090         return MLX_SUCCESS;
00091 
00092 nvdata_access_err:
00093         port_conf_def->linkup_timeout = DEFAULT_BOOT_LINK_UP_TO;
00094         port_conf_def->ip_ver = DEFAULT_BOOT_IP_VER;
00095         port_conf_def->undi_network_wait_to = DEFAULT_BOOT_UNDI_NETWORK_WAIT_TO;
00096         return status;
00097 }
00098 
00099 static
00100 mlx_status
00101 nvconfig_get_iscsi_init_dhcp_default_conf(
00102                 IN void *data,
00103                 IN int status,
00104                 OUT void *def_struct
00105                 )
00106 {
00107         union mlx_nvconfig_iscsi_init_dhcp_conf *iscsi_init_dhcp_conf =
00108                         (union mlx_nvconfig_iscsi_init_dhcp_conf *) data;
00109         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00110                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00111 
00112         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00113                         "TLV not found. Using hard-coded defaults ");
00114         port_conf_def->iscsi_dhcp_params_en = iscsi_init_dhcp_conf->dhcp_iscsi_en;
00115         port_conf_def->iscsi_ipv4_dhcp_en = iscsi_init_dhcp_conf->ipv4_dhcp_en;
00116 
00117         return MLX_SUCCESS;
00118 
00119 nvdata_access_err:
00120         port_conf_def->iscsi_dhcp_params_en = DEFAULT_ISCSI_DHCP_PARAM_EN;
00121         port_conf_def->iscsi_ipv4_dhcp_en = DEFAULT_ISCSI_IPV4_DHCP_EN;
00122 
00123         return status;
00124 }
00125 
00126 static
00127 mlx_status
00128 nvconfig_get_ib_boot_default_conf(
00129                 IN void *data,
00130                 IN int status,
00131                 OUT void *def_struct
00132                 )
00133 {
00134         union mlx_nvconfig_nic_ib_boot_conf *ib_boot_conf =
00135                         (union mlx_nvconfig_nic_ib_boot_conf *) data;
00136         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00137                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00138 
00139         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00140                         "nvconfig_nvdata_default_access failed ");
00141         port_conf_def->boot_pkey = ib_boot_conf->boot_pkey;
00142 
00143 nvdata_access_err:
00144         return status;
00145 }
00146 
00147 static
00148 mlx_status
00149 nvconfig_get_wol_default_conf(
00150                 IN void *data,
00151                 IN int status,
00152                 OUT void *def_struct
00153                 )
00154 {
00155         union mlx_nvconfig_wol_conf *wol_conf = (union mlx_nvconfig_wol_conf *) data;
00156         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00157                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00158 
00159         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00160                         "nvconfig_nvdata_default_access failed ");
00161         port_conf_def->en_wol_magic = wol_conf->en_wol_magic;
00162 
00163 nvdata_access_err:
00164         return status;
00165 }
00166 
00167 static
00168 mlx_status
00169 nvconfig_get_iscsi_gen_default_conf(
00170                 IN void *data,
00171                 IN int status,
00172                 OUT void *def_struct)
00173 {
00174         union mlx_nvconfig_iscsi_general *iscsi_gen =
00175                         (union mlx_nvconfig_iscsi_general *) data;
00176         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00177                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00178 
00179         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00180                         "nvconfig_nvdata_default_access failed ");
00181         port_conf_def->iscsi_boot_to_target = iscsi_gen->boot_to_target;
00182         port_conf_def->iscsi_vlan_en = iscsi_gen->vlan_en;
00183         port_conf_def->iscsi_tcp_timestamps_en = iscsi_gen->tcp_timestamps_en;
00184         port_conf_def->iscsi_chap_mutual_auth_en = iscsi_gen->chap_mutual_auth_en;
00185         port_conf_def->iscsi_chap_auth_en = iscsi_gen->chap_auth_en;
00186         port_conf_def->iscsi_lun_busy_retry_count = iscsi_gen->lun_busy_retry_count;
00187         port_conf_def->iscsi_link_up_delay_time = iscsi_gen->link_up_delay_time;
00188         port_conf_def->iscsi_drive_num = iscsi_gen->drive_num;
00189 
00190         return MLX_SUCCESS;
00191 
00192 nvdata_access_err:
00193         port_conf_def->iscsi_drive_num = DEFAULT_ISCSI_DRIVE_NUM;
00194         return status;
00195 }
00196 
00197 static
00198 mlx_status
00199 nvconfig_get_ib_dhcp_default_conf(
00200                 IN void *data,
00201                 IN int status,
00202                 OUT void *def_struct
00203                 )
00204 {
00205         union mlx_nvconfig_ib_dhcp_conf *ib_dhcp =
00206                         (union mlx_nvconfig_ib_dhcp_conf *) data;
00207         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00208                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00209 
00210         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00211                         "nvconfig_nvdata_default_access failed ");
00212         port_conf_def->client_identifier = ib_dhcp->client_identifier;
00213         port_conf_def->mac_admin_bit = ib_dhcp->mac_admin_bit;
00214 
00215 nvdata_access_err:
00216         return status;
00217 }
00218 
00219 static
00220 mlx_status
00221 nvconfig_get_ocsd_ocbb_default_conf( IN void *data,
00222                 IN int status, OUT void *def_struct) {
00223         union mlx_nvconfig_ocsd_ocbb_conf *ocsd_ocbb =
00224                         (union mlx_nvconfig_ocsd_ocbb_conf *) data;
00225         struct mlx_nvconfig_conf_defaults *conf_def =
00226                         (struct mlx_nvconfig_conf_defaults *) def_struct;
00227 
00228         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00229                         "TLV not found. Using hard-coded defaults ");
00230         conf_def->ocsd_ocbb_en = ocsd_ocbb->ocsd_ocbb_en;
00231 
00232         return MLX_SUCCESS;
00233 
00234 nvdata_access_err:
00235         conf_def->ocsd_ocbb_en = DEFAULT_OCSD_OCBB_EN;
00236 
00237         return status;
00238 }
00239 
00240 static
00241 mlx_status
00242 nvconfig_get_vpi_link_default_conf(
00243                 IN void *data,
00244                 IN int status,
00245                 OUT void *def_struct
00246                 )
00247 {
00248         union mlx_nvconfig_vpi_link_conf *vpi_link =
00249                         (union mlx_nvconfig_vpi_link_conf *) data;
00250         struct mlx_nvconfig_port_conf_defaults *port_conf_def =
00251                         (struct mlx_nvconfig_port_conf_defaults *) def_struct;
00252 
00253         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00254                         "nvconfig_nvdata_default_access failed ");
00255         port_conf_def->network_link_type = vpi_link->network_link_type;
00256         port_conf_def->default_link_type = vpi_link->default_link_type;
00257 
00258 nvdata_access_err:
00259         return status;
00260 }
00261 
00262 static
00263 mlx_status
00264 nvconfig_get_rom_banner_to_default_conf(
00265                 IN void *data,
00266                 IN int status,
00267                 OUT void *def_struct
00268                 )
00269 {
00270         union mlx_nvconfig_rom_banner_timeout_conf *rom_banner_timeout_conf =
00271                         (union mlx_nvconfig_rom_banner_timeout_conf *) data;
00272         struct mlx_nvconfig_conf_defaults *conf_def =
00273                         (struct mlx_nvconfig_conf_defaults *) def_struct;
00274 
00275         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00276                         "TLV not found. Using hard-coded defaults ");
00277         conf_def->flexboot_menu_to = rom_banner_timeout_conf->rom_banner_to;
00278 
00279         return MLX_SUCCESS;
00280 
00281 nvdata_access_err:
00282         conf_def->flexboot_menu_to = DEFAULT_FLEXBOOT_MENU_TO;
00283 
00284         return status;
00285 }
00286 
00287 static
00288 mlx_status
00289 nvconfig_get_nv_virt_caps_default_conf(
00290                 IN void *data,
00291                 IN int status,
00292                 OUT void *def_struct
00293                 )
00294 {
00295         union mlx_nvconfig_virt_caps *nv_virt_caps =
00296                         (union mlx_nvconfig_virt_caps *) data;
00297         struct mlx_nvconfig_conf_defaults *conf_def =
00298                         (struct mlx_nvconfig_conf_defaults *) def_struct;
00299 
00300         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00301                         "TLV not found. Using hard-coded defaults ");
00302         conf_def->max_vfs = nv_virt_caps->max_vfs_per_pf;
00303 
00304         return MLX_SUCCESS;
00305 
00306 nvdata_access_err:
00307         conf_def->max_vfs = DEFAULT_MAX_VFS;
00308 
00309         return status;
00310 }
00311 
00312 static
00313 mlx_status
00314 nvconfig_get_nv_virt_default_conf(
00315                 IN void *data,
00316                 IN int status,
00317                 OUT void *def_struct
00318                 )
00319 {
00320         union mlx_nvconfig_virt_conf *nv_virt_conf =
00321                         (union mlx_nvconfig_virt_conf *) data;
00322         struct mlx_nvconfig_conf_defaults *conf_def =
00323                         (struct mlx_nvconfig_conf_defaults *) def_struct;
00324 
00325         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00326                         "nvconfig_nvdata_default_access failed ");
00327         conf_def->total_vfs = nv_virt_conf->num_of_vfs;
00328         conf_def->sriov_en = nv_virt_conf->virt_mode;
00329 
00330 nvdata_access_err:
00331         return status;
00332 }
00333 
00334 static
00335 mlx_status
00336 nvconfig_get_rom_cap_default_conf( IN void *data,
00337                 IN int status, OUT void *def_struct) {
00338         union mlx_nvconfig_rom_cap_conf *rom_cap_conf =
00339                         (union mlx_nvconfig_rom_cap_conf *) data;
00340         struct mlx_nvconfig_conf_defaults *conf_def =
00341                         (struct mlx_nvconfig_conf_defaults *) def_struct;
00342 
00343         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00344                         "TLV not found. Using hard-coded defaults ");
00345         conf_def->boot_ip_ver_en = rom_cap_conf->boot_ip_ver_en;
00346 
00347         return MLX_SUCCESS;
00348 
00349 nvdata_access_err:
00350         rom_cap_conf->boot_ip_ver_en = DEFAULT_BOOT_IP_VERSION_EN;
00351 
00352         return status;
00353 }
00354 
00355 static struct tlv_default tlv_port_defaults[] = {
00356         TlvDefaultEntry(BOOT_SETTINGS_TYPE, union mlx_nvconfig_nic_boot_conf, &nvconfig_get_boot_default_conf),
00357         TlvDefaultEntry(BOOT_SETTINGS_EXT_TYPE, union mlx_nvconfig_nic_boot_ext_conf, &nvconfig_get_boot_ext_default_conf),
00358         TlvDefaultEntry(ISCSI_INITIATOR_DHCP_CONF_TYPE, union mlx_nvconfig_iscsi_init_dhcp_conf, &nvconfig_get_iscsi_init_dhcp_default_conf),
00359         TlvDefaultEntry(IB_BOOT_SETTING_TYPE, union mlx_nvconfig_nic_ib_boot_conf, &nvconfig_get_ib_boot_default_conf),
00360         TlvDefaultEntry(WAKE_ON_LAN_TYPE, union mlx_nvconfig_wol_conf, &nvconfig_get_wol_default_conf),
00361         TlvDefaultEntry(ISCSI_GENERAL_SETTINGS_TYPE, union mlx_nvconfig_iscsi_general, &nvconfig_get_iscsi_gen_default_conf),
00362         TlvDefaultEntry(IB_DHCP_SETTINGS_TYPE, union mlx_nvconfig_ib_dhcp_conf, &nvconfig_get_ib_dhcp_default_conf),
00363         TlvDefaultEntry(VPI_LINK_TYPE, union mlx_nvconfig_vpi_link_conf, &nvconfig_get_vpi_link_default_conf),
00364 };
00365 
00366 static struct tlv_default tlv_general_defaults[] = {
00367         TlvDefaultEntry(BANNER_TO_TYPE, union mlx_nvconfig_rom_banner_timeout_conf, &nvconfig_get_rom_banner_to_default_conf),
00368         TlvDefaultEntry(GLOPAL_PCI_CAPS_TYPE, union mlx_nvconfig_virt_caps, &nvconfig_get_nv_virt_caps_default_conf),
00369         TlvDefaultEntry(GLOPAL_PCI_SETTINGS_TYPE, union mlx_nvconfig_virt_conf, &nvconfig_get_nv_virt_default_conf),
00370         TlvDefaultEntry(OCSD_OCBB_TYPE, union mlx_nvconfig_ocsd_ocbb_conf, &nvconfig_get_ocsd_ocbb_default_conf),
00371         TlvDefaultEntry(NV_ROM_CAP_TYPE, union mlx_nvconfig_rom_cap_conf, &nvconfig_get_rom_cap_default_conf),
00372 };
00373 
00374 static
00375 mlx_status
00376 nvconfig_nvdata_default_access(
00377                 IN mlx_utils *utils,
00378                 IN mlx_uint8 port,
00379                 IN mlx_uint16 tlv_type,
00380                 IN mlx_size data_size,
00381                 OUT mlx_void *data
00382                 )
00383 {
00384         mlx_status status = MLX_SUCCESS;
00385         mlx_uint32 index;
00386         mlx_uint8 version = 0;
00387 
00388         status = nvconfig_nvdata_access(utils, port, tlv_type, REG_ACCESS_READ,
00389                         data_size, TLV_ACCESS_DEFAULT_EN, 0,
00390                         &version, data);
00391         MLX_CHECK_STATUS(NULL, status, nvdata_access_err,
00392                                 "nvconfig_nvdata_access failed ");
00393         for (index = 0; index * 4 < data_size; index++) {
00394                 mlx_memory_be32_to_cpu(utils, (((mlx_uint32 *) data)[index]),
00395                                 ((mlx_uint32 *) data) + index);
00396         }
00397 
00398 nvdata_access_err:
00399         return status;
00400 }
00401 
00402 static
00403 mlx_status
00404 nvconfig_nvdata_read_default_value(
00405                 IN mlx_utils *utils,
00406                 IN mlx_uint8 modifier,
00407                 IN struct tlv_default *def,
00408                 OUT void *def_struct
00409                 )
00410 {
00411         mlx_status status = MLX_SUCCESS;
00412         void *data = NULL;
00413 
00414         status = mlx_memory_zalloc(utils, def->data_size,&data);
00415         MLX_CHECK_STATUS(utils, status, memory_err,
00416                                 "mlx_memory_zalloc failed ");
00417         status = nvconfig_nvdata_default_access(utils, modifier, def->tlv_type,
00418                         def->data_size, data);
00419         def->set_defaults(data, status, def_struct);
00420         mlx_memory_free(utils, &data);
00421 
00422 memory_err:
00423         return status;
00424 }
00425 
00426 static
00427 void
00428 nvconfig_nvdata_read_default_values(
00429                 IN mlx_utils *utils,
00430                 IN mlx_uint8 modifier,
00431                 IN struct tlv_default defaults_table[],
00432                 IN mlx_uint8 defaults_table_size,
00433                 OUT void *def_strct
00434                 )
00435 {
00436         struct tlv_default *defs;
00437         unsigned int i;
00438 
00439         for (i = 0; i < defaults_table_size; i++) {
00440                 defs = &defaults_table[i];
00441                 nvconfig_nvdata_read_default_value(utils, modifier, defs, def_strct);
00442         }
00443 }
00444 
00445 mlx_status
00446 nvconfig_read_port_default_values(
00447                 IN mlx_utils *utils,
00448                 IN mlx_uint8 port,
00449                 OUT struct mlx_nvconfig_port_conf_defaults *port_conf_def
00450                 )
00451 {
00452         mlx_status status = MLX_SUCCESS;
00453 
00454         if (utils == NULL || port_conf_def == NULL) {
00455                 status = MLX_INVALID_PARAMETER;
00456                 MLX_DEBUG_ERROR(utils,"bad params.");
00457                 goto bad_param;
00458         }
00459         mlx_memory_set(utils, port_conf_def, 0, sizeof(*port_conf_def));
00460         nvconfig_nvdata_read_default_values(utils, port, tlv_port_defaults,
00461                                 (sizeof(tlv_port_defaults)/sizeof(tlv_port_defaults[0])),
00462                                 port_conf_def);
00463 
00464 bad_param:
00465         return status;
00466 }
00467 
00468 mlx_status
00469 nvconfig_read_general_default_values(
00470                 IN mlx_utils *utils,
00471                 OUT struct mlx_nvconfig_conf_defaults *conf_def
00472                 )
00473 {
00474         mlx_status status = MLX_SUCCESS;
00475 
00476         if (utils == NULL || conf_def == NULL) {
00477                 status = MLX_INVALID_PARAMETER;
00478                 MLX_DEBUG_ERROR(utils,"bad params.");
00479                 goto bad_param;
00480         }
00481         mlx_memory_set(utils, conf_def, 0, sizeof(*conf_def));
00482         nvconfig_nvdata_read_default_values(utils, 0, tlv_general_defaults,
00483                         (sizeof(tlv_general_defaults)/sizeof(tlv_general_defaults[0])),
00484                         conf_def);
00485 
00486 bad_param:
00487         return status;
00488 }
00489 
00490 mlx_status
00491 nvconfig_read_rom_ini_values(
00492                 IN mlx_utils *utils,
00493                 OUT struct mlx_nvcofnig_romini *rom_ini
00494                 )
00495 {
00496         mlx_status status = MLX_SUCCESS;
00497         mlx_uint8 version = 0;
00498         mlx_uint32 index;
00499 
00500         if (utils == NULL || rom_ini == NULL) {
00501                 status = MLX_INVALID_PARAMETER;
00502                 MLX_DEBUG_ERROR(utils,"bad params.");
00503                 goto bad_param;
00504         }
00505         mlx_memory_set(utils, rom_ini, 0, sizeof(*rom_ini));
00506 
00507         status = nvconfig_nvdata_access(utils, 0, GLOBAL_ROM_INI_TYPE, REG_ACCESS_READ,
00508                         sizeof(*rom_ini), TLV_ACCESS_DEFAULT_DIS, 0,
00509                         &version, rom_ini);
00510         MLX_CHECK_STATUS(NULL, status, bad_param,
00511                                 "nvconfig_nvdata_access failed ");
00512         for (index = 0; index * 4 < sizeof(*rom_ini); index++) {
00513                 mlx_memory_be32_to_cpu(utils, (((mlx_uint32 *) rom_ini)[index]),
00514                                 ((mlx_uint32 *) rom_ini) + index);
00515         }
00516 
00517 bad_param:
00518         return status;
00519 }