From e27c40f30eda2d3e42e1f93197d6bdeff27f2d58 Mon Sep 17 00:00:00 2001 From: Adrian Chiris Date: Tue, 24 Oct 2017 21:48:58 +0300 Subject: [PATCH] Title: Deprecation of mstflint repository Description: mstflint repository has moved to github see README for additional details Issue:N/A --- COPYING | 378 - LICENSE | 30 - Makefile.am | 43 - README | 168 - autogen.sh | 13 - cmdif/Makefile.am | 44 - cmdif/icmd_cif_common.c | 136 - cmdif/icmd_cif_common.h | 101 - cmdif/icmd_cif_macros.h | 90 - cmdif/icmd_cif_open.c | 49 - cmdif/icmd_cif_open.h | 61 - cmdif/tools_cif.c | 141 - cmdif/tools_cif.h | 130 - cmdparser/Makefile.am | 40 - cmdparser/cmdparser.cpp | 478 - cmdparser/cmdparser.h | 153 - cmdparser/my_getopt.c | 1086 - cmdparser/my_getopt.h | 122 - common/Makefile.am | 36 - common/bit_slice.h | 64 - common/compatibility.h | 427 - common/tools_utils.h | 77 - common/tools_version.h | 88 - configure.ac | 91 - debian/changelog | 96 - debian/compat | 1 - debian/control | 16 - debian/copyright | 36 - debian/docs | 2 - debian/files | 1 - debian/mstflint.docs | 1 - debian/mstflint.substvars | 2 - debian/rules | 25 - debian/source/format | 1 - dev_mgt/Makefile.am | 46 - dev_mgt/tools_dev_types.c | 539 - dev_mgt/tools_dev_types.h | 169 - flint/Makefile.am | 78 - flint/cmd_line_parser.cpp | 925 - flint/err_msgs.h | 153 - flint/flint.cpp | 265 - flint/flint.h | 78 - flint/flint_params.cpp | 89 - flint/flint_params.h | 138 - flint/subcommands.cpp | 4355 ---- flint/subcommands.h | 547 - gitversion.sh | 7 - include/mtcr_ul/mtcr.h | 164 - include/mtcr_ul/mtcr_com_defs.h | 293 - include/mtcr_ul/mtcr_mf.h | 134 - man/mstconfig.1 | 249 - man/mstflint.1 | 965 - man/mstmcra.1 | 34 - man/mstmread.1 | 10 - man/mstmtserver.1 | 16 - man/mstmwrite.1 | 10 - man/mstregdump.1 | 23 - man/mstvpd.1 | 37 - mflash/Makefile.am | 45 - mflash/mflash.c | 3094 --- mflash/mflash.h | 186 - mflash/mflash_access_layer.c | 205 - mflash/mflash_access_layer.h | 50 - mflash/mflash_common_structs.h | 146 - mflash/mflash_pack_layer.c | 310 - mflash/mflash_pack_layer.h | 218 - mflash/mflash_types.h | 118 - mft_utils/Makefile.am | 44 - mft_utils/calc_hw_crc.c | 90 - mft_utils/calc_hw_crc.h | 48 - mft_utils/errmsg.cpp | 207 - mft_utils/errmsg.h | 120 - mft_utils/mft_sig_handler.c | 159 - mft_utils/mft_sig_handler.h | 94 - mft_utils/mlarge_buffer.cpp | 174 - mft_utils/mlarge_buffer.h | 80 - mlxconfig/Makefile.am | 61 - mlxconfig/mlxcfg_lib.cpp | 736 - mlxconfig/mlxcfg_lib.h | 113 - mlxconfig/mlxcfg_param_lib.cpp | 4283 ---- mlxconfig/mlxcfg_param_lib.h | 1227 - mlxconfig/mlxcfg_parser.cpp | 866 - mlxconfig/mlxcfg_status.h | 79 - mlxconfig/mlxcfg_ui.cpp | 763 - mlxconfig/mlxcfg_ui.h | 221 - mlxfwops/Makefile.am | 36 - mlxfwops/lib/Makefile.am | 65 - mlxfwops/lib/aux_tlv_ops.cpp | 545 - mlxfwops/lib/aux_tlv_ops.h | 165 - mlxfwops/lib/flint_base.cpp | 319 - mlxfwops/lib/flint_base.h | 569 - mlxfwops/lib/flint_io.cpp | 903 - mlxfwops/lib/flint_io.h | 375 - mlxfwops/lib/fs2_ops.cpp | 2103 -- mlxfwops/lib/fs2_ops.h | 181 - mlxfwops/lib/fs3_ops.cpp | 2566 -- mlxfwops/lib/fs3_ops.h | 242 - mlxfwops/lib/fw_ops.cpp | 1720 -- mlxfwops/lib/fw_ops.h | 427 - mlxfwops/lib/mlxfwops.cpp | 239 - mlxfwops/lib/mlxfwops.h | 98 - mlxfwops/lib/mlxfwops_com.h | 354 - mlxfwops/uefi_c/mft_uefi_common.h | 59 - mstdump/Makefile.am | 36 - mstdump/crd_lib/Makefile.am | 41 - mstdump/crd_lib/crdump.c | 684 - mstdump/crd_lib/crdump.h | 123 - mstdump/crd_main/Makefile.am | 44 - mstdump/crd_main/mstdump.c | 185 - mstdump/mstdump_dbs/ConnectIB.csv | 2270 -- mstdump/mstdump_dbs/ConnectX2.csv | 2335 -- mstdump/mstdump_dbs/ConnectX3.csv | 3599 --- mstdump/mstdump_dbs/ConnectX3Pro.csv | 3651 --- mstdump/mstdump_dbs/ConnectX4.csv | 3578 --- mstdump/mstdump_dbs/ConnectX4LX.csv | 3129 --- mstdump/mstdump_dbs/InfiniScaleIV.csv | 14584 ----------- mstdump/mstdump_dbs/Makefile.am | 34 - mstdump/mstdump_dbs/Spectrum.csv | 22368 ----------------- mstdump/mstdump_dbs/SwitchIB.csv | 13170 ---------- mstdump/mstdump_dbs/SwitchIB2.csv | 13081 ---------- mstdump/mstdump_dbs/SwitchX.csv | 10265 -------- mstflint.spec.in | 150 - mtcr_ul/Makefile.am | 56 - mtcr_ul/mtcr_ib.h | 60 - mtcr_ul/mtcr_ib_ofed.c | 1063 - mtcr_ul/mtcr_ib_res_mgt.c | 194 - mtcr_ul/mtcr_ib_res_mgt.h | 61 - mtcr_ul/mtcr_icmd_cif.h | 106 - mtcr_ul/mtcr_int_defs.h | 70 - mtcr_ul/mtcr_tools_cif.c | 550 - mtcr_ul/mtcr_tools_cif.h | 77 - mtcr_ul/mtcr_ul.c | 273 - mtcr_ul/mtcr_ul_com.c | 2506 -- mtcr_ul/mtcr_ul_com.h | 143 - mtcr_ul/mtcr_ul_icmd_cif.c | 519 - mtcr_ul/packets_common.c | 132 - mtcr_ul/packets_common.h | 196 - mtcr_ul/packets_layout.c | 112 - mtcr_ul/packets_layout.h | 96 - reg_access/Makefile.am | 48 - reg_access/reg_access.c | 313 - reg_access/reg_access.h | 82 - small_utils/Makefile.am | 54 - small_utils/hca_self_test.ofed | 900 - small_utils/hca_self_test.readme | 31 - small_utils/mcra.c | 410 - small_utils/mread.c | 87 - small_utils/mtserver.c | 718 - small_utils/mwrite.c | 88 - small_utils/tcp.c | 380 - small_utils/tcp.h | 109 - small_utils/vpd.c | 645 - tools_crypto/Makefile.am | 40 - tools_crypto/tools_md5.c | 39 - tools_crypto/tools_md5.h | 47 - tools_layouts/Makefile.am | 45 - tools_layouts/adb_to_c_utils.c | 386 - tools_layouts/adb_to_c_utils.h | 297 - tools_layouts/cibfw_layouts.c | 1540 -- tools_layouts/cibfw_layouts.h | 643 - tools_layouts/connectib_layouts.c | 214 - tools_layouts/connectib_layouts.h | 108 - tools_layouts/cx4fw_layouts.c | 552 - tools_layouts/cx4fw_layouts.h | 243 - tools_layouts/register_access_open_layouts.c | 402 - tools_layouts/register_access_open_layouts.h | 185 - tools_layouts/register_access_sib_layouts.c | 649 - tools_layouts/register_access_sib_layouts.h | 282 - tools_layouts/tools_open_layouts.c | 5658 ----- tools_layouts/tools_open_layouts.h | 2155 -- tools_res_mgmt/Makefile.am | 46 - tools_res_mgmt/tools_res_mgmt.c | 545 - tools_res_mgmt/tools_res_mgmt.h | 118 - tools_res_mgmt/tools_time.c | 56 - tools_res_mgmt/tools_time.h | 50 - 175 files changed, 155960 deletions(-) delete mode 100644 COPYING delete mode 100644 LICENSE delete mode 100644 Makefile.am delete mode 100755 autogen.sh delete mode 100644 cmdif/Makefile.am delete mode 100644 cmdif/icmd_cif_common.c delete mode 100644 cmdif/icmd_cif_common.h delete mode 100644 cmdif/icmd_cif_macros.h delete mode 100644 cmdif/icmd_cif_open.c delete mode 100644 cmdif/icmd_cif_open.h delete mode 100644 cmdif/tools_cif.c delete mode 100644 cmdif/tools_cif.h delete mode 100644 cmdparser/Makefile.am delete mode 100644 cmdparser/cmdparser.cpp delete mode 100644 cmdparser/cmdparser.h delete mode 100755 cmdparser/my_getopt.c delete mode 100755 cmdparser/my_getopt.h delete mode 100644 common/Makefile.am delete mode 100644 common/bit_slice.h delete mode 100644 common/compatibility.h delete mode 100755 common/tools_utils.h delete mode 100644 common/tools_version.h delete mode 100644 configure.ac delete mode 100644 debian/changelog delete mode 100644 debian/compat delete mode 100644 debian/control delete mode 100644 debian/copyright delete mode 100644 debian/docs delete mode 100644 debian/files delete mode 100644 debian/mstflint.docs delete mode 100644 debian/mstflint.substvars delete mode 100755 debian/rules delete mode 100644 debian/source/format delete mode 100644 dev_mgt/Makefile.am delete mode 100644 dev_mgt/tools_dev_types.c delete mode 100644 dev_mgt/tools_dev_types.h delete mode 100755 flint/Makefile.am delete mode 100644 flint/cmd_line_parser.cpp delete mode 100644 flint/err_msgs.h delete mode 100644 flint/flint.cpp delete mode 100644 flint/flint.h delete mode 100644 flint/flint_params.cpp delete mode 100644 flint/flint_params.h delete mode 100644 flint/subcommands.cpp delete mode 100644 flint/subcommands.h delete mode 100755 gitversion.sh delete mode 100644 include/mtcr_ul/mtcr.h delete mode 100644 include/mtcr_ul/mtcr_com_defs.h delete mode 100644 include/mtcr_ul/mtcr_mf.h delete mode 100644 man/mstconfig.1 delete mode 100644 man/mstflint.1 delete mode 100644 man/mstmcra.1 delete mode 100644 man/mstmread.1 delete mode 100644 man/mstmtserver.1 delete mode 100644 man/mstmwrite.1 delete mode 100644 man/mstregdump.1 delete mode 100644 man/mstvpd.1 delete mode 100644 mflash/Makefile.am delete mode 100644 mflash/mflash.c delete mode 100644 mflash/mflash.h delete mode 100755 mflash/mflash_access_layer.c delete mode 100755 mflash/mflash_access_layer.h delete mode 100644 mflash/mflash_common_structs.h delete mode 100755 mflash/mflash_pack_layer.c delete mode 100755 mflash/mflash_pack_layer.h delete mode 100644 mflash/mflash_types.h delete mode 100644 mft_utils/Makefile.am delete mode 100644 mft_utils/calc_hw_crc.c delete mode 100644 mft_utils/calc_hw_crc.h delete mode 100644 mft_utils/errmsg.cpp delete mode 100644 mft_utils/errmsg.h delete mode 100644 mft_utils/mft_sig_handler.c delete mode 100644 mft_utils/mft_sig_handler.h delete mode 100644 mft_utils/mlarge_buffer.cpp delete mode 100644 mft_utils/mlarge_buffer.h delete mode 100755 mlxconfig/Makefile.am delete mode 100644 mlxconfig/mlxcfg_lib.cpp delete mode 100644 mlxconfig/mlxcfg_lib.h delete mode 100644 mlxconfig/mlxcfg_param_lib.cpp delete mode 100644 mlxconfig/mlxcfg_param_lib.h delete mode 100644 mlxconfig/mlxcfg_parser.cpp delete mode 100644 mlxconfig/mlxcfg_status.h delete mode 100644 mlxconfig/mlxcfg_ui.cpp delete mode 100644 mlxconfig/mlxcfg_ui.h delete mode 100755 mlxfwops/Makefile.am delete mode 100755 mlxfwops/lib/Makefile.am delete mode 100644 mlxfwops/lib/aux_tlv_ops.cpp delete mode 100644 mlxfwops/lib/aux_tlv_ops.h delete mode 100755 mlxfwops/lib/flint_base.cpp delete mode 100755 mlxfwops/lib/flint_base.h delete mode 100755 mlxfwops/lib/flint_io.cpp delete mode 100755 mlxfwops/lib/flint_io.h delete mode 100644 mlxfwops/lib/fs2_ops.cpp delete mode 100644 mlxfwops/lib/fs2_ops.h delete mode 100644 mlxfwops/lib/fs3_ops.cpp delete mode 100644 mlxfwops/lib/fs3_ops.h delete mode 100644 mlxfwops/lib/fw_ops.cpp delete mode 100644 mlxfwops/lib/fw_ops.h delete mode 100755 mlxfwops/lib/mlxfwops.cpp delete mode 100755 mlxfwops/lib/mlxfwops.h delete mode 100644 mlxfwops/lib/mlxfwops_com.h delete mode 100644 mlxfwops/uefi_c/mft_uefi_common.h delete mode 100644 mstdump/Makefile.am delete mode 100755 mstdump/crd_lib/Makefile.am delete mode 100755 mstdump/crd_lib/crdump.c delete mode 100644 mstdump/crd_lib/crdump.h delete mode 100755 mstdump/crd_main/Makefile.am delete mode 100755 mstdump/crd_main/mstdump.c delete mode 100755 mstdump/mstdump_dbs/ConnectIB.csv delete mode 100755 mstdump/mstdump_dbs/ConnectX2.csv delete mode 100755 mstdump/mstdump_dbs/ConnectX3.csv delete mode 100755 mstdump/mstdump_dbs/ConnectX3Pro.csv delete mode 100644 mstdump/mstdump_dbs/ConnectX4.csv delete mode 100644 mstdump/mstdump_dbs/ConnectX4LX.csv delete mode 100755 mstdump/mstdump_dbs/InfiniScaleIV.csv delete mode 100644 mstdump/mstdump_dbs/Makefile.am delete mode 100644 mstdump/mstdump_dbs/Spectrum.csv delete mode 100644 mstdump/mstdump_dbs/SwitchIB.csv delete mode 100644 mstdump/mstdump_dbs/SwitchIB2.csv delete mode 100755 mstdump/mstdump_dbs/SwitchX.csv delete mode 100644 mstflint.spec.in delete mode 100644 mtcr_ul/Makefile.am delete mode 100644 mtcr_ul/mtcr_ib.h delete mode 100644 mtcr_ul/mtcr_ib_ofed.c delete mode 100644 mtcr_ul/mtcr_ib_res_mgt.c delete mode 100644 mtcr_ul/mtcr_ib_res_mgt.h delete mode 100644 mtcr_ul/mtcr_icmd_cif.h delete mode 100644 mtcr_ul/mtcr_int_defs.h delete mode 100644 mtcr_ul/mtcr_tools_cif.c delete mode 100644 mtcr_ul/mtcr_tools_cif.h delete mode 100644 mtcr_ul/mtcr_ul.c delete mode 100644 mtcr_ul/mtcr_ul_com.c delete mode 100644 mtcr_ul/mtcr_ul_com.h delete mode 100644 mtcr_ul/mtcr_ul_icmd_cif.c delete mode 100644 mtcr_ul/packets_common.c delete mode 100644 mtcr_ul/packets_common.h delete mode 100644 mtcr_ul/packets_layout.c delete mode 100644 mtcr_ul/packets_layout.h delete mode 100644 reg_access/Makefile.am delete mode 100644 reg_access/reg_access.c delete mode 100644 reg_access/reg_access.h delete mode 100644 small_utils/Makefile.am delete mode 100755 small_utils/hca_self_test.ofed delete mode 100755 small_utils/hca_self_test.readme delete mode 100644 small_utils/mcra.c delete mode 100644 small_utils/mread.c delete mode 100644 small_utils/mtserver.c delete mode 100644 small_utils/mwrite.c delete mode 100644 small_utils/tcp.c delete mode 100644 small_utils/tcp.h delete mode 100644 small_utils/vpd.c delete mode 100644 tools_crypto/Makefile.am delete mode 100644 tools_crypto/tools_md5.c delete mode 100644 tools_crypto/tools_md5.h delete mode 100644 tools_layouts/Makefile.am delete mode 100644 tools_layouts/adb_to_c_utils.c delete mode 100644 tools_layouts/adb_to_c_utils.h delete mode 100644 tools_layouts/cibfw_layouts.c delete mode 100644 tools_layouts/cibfw_layouts.h delete mode 100644 tools_layouts/connectib_layouts.c delete mode 100644 tools_layouts/connectib_layouts.h delete mode 100644 tools_layouts/cx4fw_layouts.c delete mode 100644 tools_layouts/cx4fw_layouts.h delete mode 100644 tools_layouts/register_access_open_layouts.c delete mode 100644 tools_layouts/register_access_open_layouts.h delete mode 100644 tools_layouts/register_access_sib_layouts.c delete mode 100644 tools_layouts/register_access_sib_layouts.h delete mode 100644 tools_layouts/tools_open_layouts.c delete mode 100644 tools_layouts/tools_open_layouts.h delete mode 100644 tools_res_mgmt/Makefile.am delete mode 100644 tools_res_mgmt/tools_res_mgmt.c delete mode 100644 tools_res_mgmt/tools_res_mgmt.h delete mode 100644 tools_res_mgmt/tools_time.c delete mode 100644 tools_res_mgmt/tools_time.h diff --git a/COPYING b/COPYING deleted file mode 100644 index 21ab96e..0000000 --- a/COPYING +++ /dev/null @@ -1,378 +0,0 @@ -This software is available to you under a choice of one of two licenses. -You may chose to be licensed under the terms of the the OpenIB.org BSD -license or the GNU General Public License (GPL) Version 2, both included -below. - -Copyright (c) 2002-2011 Mellanox Technologies LTD. All rights reserved. - -================================================================== - - OpenIB.org BSD license - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -================================================================== - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e208335..0000000 --- a/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ - Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - - This software is available to you under a choice of one of two - licenses. You may choose to be licensed under the terms of the GNU - General Public License (GPL) Version 2, available from the file - COPYING in the main directory of this source tree, or the - OpenIB.org BSD license below: - - Redistribution and use in source and binary forms, with or - without modification, are permitted provided that the following - conditions are met: - - - Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. - - - Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 2da1619..0000000 --- a/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -#-- -# Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -SUBDIRS = common mft_utils $(TOOLS_CRYPTO) tools_layouts mtcr_ul reg_access cmdif dev_mgt tools_res_mgmt mflash mlxconfig mlxfwops cmdparser flint small_utils mstdump - -man_MANS = man/mstflint.1 man/mstconfig.1 man/mstmcra.1 man/mstmread.1 man/mstmwrite.1 man/mstmtserver.1 man/mstregdump.1 man/mstvpd.1 - -EXTRA_DIST = \ - mstflint.spec \ - small_utils/hca_self_test.ofed \ - common/gitversion.h \ - debian \ - $(man_MANS) - diff --git a/README b/README index 8039f1a..4de08b9 100644 --- a/README +++ b/README @@ -3,176 +3,8 @@ Mellanox Technologies - www.mellanox.com MSTFLINT Package - Firmware Burning and Diagnostics Tools -1) Overview - This package contains a burning tool and diagnostic tools for Mellanox - manufactured HCA/NIC cards. It also provides access to the relevant source - code. Please see the file LICENSE for licensing details. - This package is based on a subset of the Mellanox Firmware Tools (MFT) package. - For a full documentation of the MFT package, please refer to the downloads page - in Mellanox web site. - ---------------------------------------------------------------------------- NOTE: mstflint git repository has moved to github (https://github.com/Mellanox/mstflint) openfabrics mstflint repository is no longer maintained. - - This burning tool should be used only with Mellanox-manufactured - HCA/NIC cards. Using it with cards manufactured by other vendors - may be harmful to the cards (due to different configurations). - Using the diagnostic tools is normally safe for all HCAs/NICs. ---------------------------------------------------------------------------- - -2) Package Contents - a) mstflint source code - b) mflash lib - This lib provides low level Flash access through Mellanox HCAs. - c) mtcr lib (implemented in mtcr.h file) - This lib enables access to HCA hardware registers. - d) mstregdump utility - This utility dumps hardware registers from Mellanox hardware - for later analysis by Mellanox. - e) mstvpd - This utility dumps the on-card VPD. - f) mstmcra - This debug utility reads/writes a to/from the device configuration register space. - g) mstconfig - This tool sets or queries non-volatile configurable options for Mellanox HCAs. - -3) Installation - a) Build the mstflint utility. This package is built using a standard - autotools method. - - Example: - > ./configure - > make - > make install - - - Run "configure --help" for custom configuration options. - - Typically, root privileges are required to run "make install" - -4) Hardware Access Device Names - The tools in this package require a device name in the command - line. The device name is the identifier of the target CA. - This section describes the device name formats and the HW access flow. - - a) The devices can be accessed by their PCI ID as displayed by lspci - (bus:dev.fn). - Example: - # List all Mellanox devices - > /sbin/lspci -d 15b3: - 02:00.0 Ethernet controller: Mellanox Technologies MT25448 [ConnectX EN 10GigE, PCIe 2.0 2.5GT/s] (rev a0) - - # Use mstflint tool to query the firmware on this device - > mstflint -d 02:00.0 q - - b) When the IB driver (mlx4 or mthca) is loaded, the devices can be accessed - by their IB device name. - Example: - # List the IB devices - > ibv_devinfo | grep hca_id - hca_id: mlx4_0 - - # Use mstvpd tool to dump the VPD of this device - > mstvpd mlx4_0 - - c) PCI configuration access - In examples a and b above, the device is accessed via PCI Memory Mapping. - The device can also be accessed by PCI configuration cycles. - PCI configuration access is slower and less safe than memory access -- - use it only if methods a and b above do not work. - - To force configuration access, use device names in the following format: - /proc/bus/pci// - - Example: - # List all Mellanox devices - > /sbin/lspci -d 15b3: - 02:00.0 Ethernet controller: Mellanox Technologies MT25448 [ConnectX EN 10GigE, PCIe 2.0 2.5GT/s] (rev a0) - - # Use mstregdump to dump HW registers, using PCI config cycles - > mstregdump /proc/bus/pci/02/00.0 > crdump.log - - Note: Typically, you will need root privileges for hardware access - - d) Accessing a multi-function device: - - In some configuration, the CA device identifies as a multi-function device on PCI. E.G.: - > /sbin/lspci -d 15b3: - 07:00.0 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.1 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.2 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.3 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.4 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.5 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.6 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - 07:00.7 Ethernet controller: Mellanox Technologies MT26468 [ConnectX EN 10GigE, PCIe 2.0 5GT/s] (rev b0) - - These multiple "logical" devices are actually a single physical device, so firmware update or "physical" - diagnostics should be run only on one of the functions. - - When the device driver is loaded, only the primary physical function of the device can be accessed. - In Linux that would typically be function 0. This function can be accessed using memory mapping, as - described in sub section a) above. E.G.: - > mstflint -d 07:00.0 q - - When the device driver is not loaded, all the functions can be accessed using configuration cycles, as - described in sub section c) above. It is recommended to use function 0 for FW update or diagnostics, E.G.: - > mstflint -d /proc/bus/pci/07/00.0 q - -5) Usage (mstflint): - Read mstflint usage. Enter "./mstflint -h" for a short help message, or - "./mstflint -hh" for a detailed help message. - - Obtaining firmware files: - If you purchased your card from Mellanox Technologies, please use the - Mellanox website (www.mellanox.com, under 'Firmware' downloads) to - download the firmware for your card. - If you purchased your card from a vendor other than Mellanox, get a - specific firmware configuration (INI) file from your HCA card vendor and - generate the binary image. - - Use mstflint to burn a device according to the burning instructions in - "mstflint -hh" and in Mellanox web site firmware page. - -6) Usage (mstregdump): - An internal register dump is displayed to the standard output. - Please store it in a file for analysis by Mellanox. - - Example: - > mstregdump mthca0 > dumpfile - -7) Usage (mstvpd): - A VPD dump is displayed to the standard output. - A list of keywords to dump can be supplied after the -- flag - to apply an output filter. - - Examples: - > mstvpd mlx4_0 - ID: Hawk Dual Port - PN: MNPH29C-XTR - EC: X2 - SN: MT1001X00749 - V0: PCIe Gen2 x8 - V1: N/A - YA: N/A - RW: - - > mstvpd mlx4_0 -- PN ID - PN: MNPH29C-XTR - ID: Hawk Dual Port - -8) Usage (mstconfig): - Read mstconfig usage. Enter "mstconfig -h" for a help message. - -9) Problem Reporting: - Please collect the following information when reporting issues: - - uname -a - cat /etc/issue - cat /proc/bus/pci/devices - mstflint -vv - lspci - mstflint -d 02:00.0 v - mstflint -d 02:00.0 q - mstvpd 02:00.0 - diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 6ba4a6f..0000000 --- a/autogen.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh - -# create config dir if not exist -test -d config || mkdir config - -sh gitversion.sh ./common/gitversion.h - -set -x -aclocal -I config -libtoolize --force --copy -autoheader -automake --foreign --add-missing --copy -autoconf diff --git a/cmdif/Makefile.am b/cmdif/Makefile.am deleted file mode 100644 index c6315d0..0000000 --- a/cmdif/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in - -USER_DIR = $(top_srcdir) -MTCR_DIR = $(USER_DIR)/include/mtcr_ul -TOOLS_LAYOUTS_DIR = $(USER_DIR)/tools_layouts -AM_CPPFLAGS = -I. -I../common -I../tools_layouts -I$(MTCR_DIR) -I.. -I$(USER_DIR)/mtcr_ul - -AM_CFLAGS = -W -Wall -Werror -g -MP -MD $(COMPILER_FPIC) -DCMDIF_EXPORTS -CMDIF_VERSION = 1 -noinst_LIBRARIES = libcmdif.a - -libcmdif_a_SOURCES = tools_cif.c tools_cif.h icmd_cif_common.c icmd_cif_common.h icmd_cif_open.c icmd_cif_open.h - diff --git a/cmdif/icmd_cif_common.c b/cmdif/icmd_cif_common.c deleted file mode 100644 index 75b2fbc..0000000 --- a/cmdif/icmd_cif_common.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include "icmd_cif_common.h" - -/* - * get_last_err - */ -char* gcif_get_last_err(){ - return "Deprecated: General Error"; -} - -/* - * gcif_err_str - */ -char* gcif_err_str(int rc) { - - switch(rc) { - case GCIF_STATUS_SUCCESS : - return "OK"; - case GCIF_STATUS_INVALID_OPCODE : - return "Invalid opcode"; - case GCIF_STATUS_INVALID_CMD : - return "Invalid cmd"; - case GCIF_STATUS_OPERATIONAL_ERROR : - return "Operational error"; - case GCIF_STATUS_CR_FAIL : - return "cr-space access failure"; - case GCIF_STATUS_BAD_OPCODE : - return "unsupported opcode was used"; - case GCIF_STATUS_SEMAPHORE_TO : - return "timed out while trying to take semaphore"; - case GCIF_STATUS_EXECUTE_TO : - return "timed out while waiting for command to execute"; - case GCIF_STATUS_IFC_BUSY : - return "command-interface is busy executing another command"; - case GCIF_STATUS_BAD_PARAMETERS : - return "bad parameter"; - case GCIF_STATUS_ICMD_NOT_READY: - return "command interface not ready"; - case GCIF_STATUS_BAD_PARAM: - return "command interface bad param"; - case GCIF_STATUS_UNSUPPORTED_ICMD_VERSION: - return "Unsupported icmd version"; - case GCIF_STATUS_UNKNOWN_STATUS: - return "Unknown ICMD Status."; - case GCIF_STATUS_GENERAL_ERROR : - return "General error"; - case GCIF_SIZE_EXCEEDS_LIMIT: - return "Size exceeds limit"; - case GCIF_ICMD_NOT_SUPPORTED: - return "icmd not supported"; - case GCIF_ICMD_INIT_FAILED: - return "icmd initialization failed"; - case GCIF_ICMD_BUSY: - return "icmd busy"; - default: - return "Unknown error"; - } -} - -/* - * convert_rc - */ - -int convert_rc(int rc) { - switch (rc) { - case ME_ICMD_STATUS_CR_FAIL: - return GCIF_STATUS_CR_FAIL; - case ME_ICMD_STATUS_SEMAPHORE_TO: - return GCIF_STATUS_SEMAPHORE_TO; - case ME_ICMD_STATUS_EXECUTE_TO: - return GCIF_STATUS_EXECUTE_TO; - case ME_ICMD_STATUS_IFC_BUSY: - return GCIF_STATUS_IFC_BUSY; - case ME_ICMD_STATUS_ICMD_NOT_READY: - return GCIF_STATUS_ICMD_NOT_READY; - case ME_ICMD_UNSUPPORTED_ICMD_VERSION: - return GCIF_STATUS_UNSUPPORTED_ICMD_VERSION; - case ME_ICMD_INVALID_OPCODE: - return GCIF_STATUS_INVALID_OPCODE; - case ME_ICMD_INVALID_CMD: - return GCIF_STATUS_INVALID_CMD; - case ME_ICMD_OPERATIONAL_ERROR: - return GCIF_STATUS_OPERATIONAL_ERROR; - case ME_ICMD_BAD_PARAM: - return GCIF_STATUS_BAD_PARAM; - case ME_ICMD_ICM_NOT_AVAIL: - return GCIF_STATUS_ICM_NOT_AVAIL; - case ME_ICMD_WRITE_PROTECT: - return GCIF_STATUS_WRITE_PROTECT; - case ME_ICMD_UNKNOWN_STATUS: - return GCIF_STATUS_UNKNOWN_STATUS; - case ME_ICMD_SIZE_EXCEEDS_LIMIT: - return GCIF_SIZE_EXCEEDS_LIMIT; - case ME_ICMD_NOT_SUPPORTED: - return GCIF_ICMD_NOT_SUPPORTED; - case ME_ICMD_INIT_FAILED: - return GCIF_ICMD_INIT_FAILED; - case ME_ICMD_BUSY: - return GCIF_ICMD_BUSY; - default: - break; - } - return GCIF_STATUS_GENERAL_ERROR; -} diff --git a/cmdif/icmd_cif_common.h b/cmdif/icmd_cif_common.h deleted file mode 100644 index bdc03c4..0000000 --- a/cmdif/icmd_cif_common.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _ICMD_COMMON_ -#define _ICMD_COMMON_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* --------- Typedefs & Constants ---------------------------------- */ - -/** - * Possible status values returned by the API functions. - * In some cases the status indicated in the cr-space may not fit - * any of the below enumeration values, in which case the raw status - * value will be returned. - **/ -enum { - GCIF_STATUS_SUCCESS = 0, - GCIF_STATUS_INVALID_OPCODE , - GCIF_STATUS_INVALID_CMD, - GCIF_STATUS_OPERATIONAL_ERROR, - GCIF_STATUS_BAD_PARAM, - GCIF_STATUS_CR_FAIL , // cr-space access failure - GCIF_STATUS_BAD_OPCODE, // unsupported opcode was used - GCIF_STATUS_SEMAPHORE_TO, // timed out while trying to take semaphore - GCIF_STATUS_EXECUTE_TO, // timed out while waiting for command to execute - GCIF_STATUS_IFC_BUSY, // command-interface is busy executing another command - GCIF_STATUS_BAD_PARAMETERS, - GCIF_STATUS_GENERAL_ERROR, - GCIF_STATUS_ICMD_NOT_READY, - GCIF_STATUS_UNSUPPORTED_ICMD_VERSION, - GCIF_STATUS_ICM_NOT_AVAIL, - GCIF_STATUS_WRITE_PROTECT, - GCIF_STATUS_NO_MEM, - GCIF_SIZE_EXCEEDS_LIMIT, - GCIF_ICMD_NOT_SUPPORTED, - GCIF_ICMD_INIT_FAILED, - GCIF_ICMD_BUSY, - GCIF_STATUS_UNKNOWN_STATUS -}; - -enum { - GET_FW_INFO = 0x8007, - FLASH_REG_ACCESS = 0x9001, -}; - - -enum { - RW_READ = 0x1, - RW_WRITE = 0x0 -}; - -/* --------- Functional API ---------------------------------------- */ - -/** - * Returns the last error message recorded by the library - **/ -char* gcif_get_last_err(); - -/** - * Returns the error message associated with the provided return code - **/ -char* gcif_err_str(int rc); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/cmdif/icmd_cif_macros.h b/cmdif/icmd_cif_macros.h deleted file mode 100644 index fa7f261..0000000 --- a/cmdif/icmd_cif_macros.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _ICMD_MACROS /* guard */ -#define _ICMD_MACROS - - -int convert_rc(int rc); - -#define IN -#define OUT -#define INOUT - -#ifdef _DEBUG_MODE -#define DBG_PRINTF(...) fprintf(stderr, __VA_ARGS__) -#else -#define DBG_PRINTF(...) -#endif - -/* - * SEND_ICMD_FLOW macro is designed for the most common icmd flow - * basically every command that simply packs a struct sends icmd and unpacks it should use - * this to save code. - * TODO: Adrianc- if needed separate struct_name to prefix+name in case we need to separate between different - * 5th gen icmd structures i.e connectib/switchib/connectx4 (use ## to paste them together in the macro) - */ -#define SEND_ICMD_FLOW_GENERIC(mf, op, struct_name, cmd_struct, should_pack, skip_write, pack_func, unpack_func)\ - int _rc;\ - int _cmd_size = struct_name##_size();\ - u_int8_t _data[_cmd_size];\ - memset(_data, 0, _cmd_size);\ - if (should_pack) {\ - pack_func(cmd_struct, _data);\ - }\ - _rc = icmd_send_command(mf, op, _data, _cmd_size, skip_write);\ - if (_rc) {\ - return convert_rc(_rc);\ - }\ - unpack_func(cmd_struct, _data);\ - return GCIF_STATUS_SUCCESS - -#define SEND_ICMD_FLOW(mf, op, struct_name, cmd_struct, should_pack, skip_write)\ - SEND_ICMD_FLOW_GENERIC(mf, op, struct_name, cmd_struct, should_pack, skip_write, struct_name##_pack, struct_name##_unpack) - -#define SEND_UNION_ICMD_FLOW(mf, op, struct_name, cmd_struct, should_pack, skip_write)\ - int _rc;\ - int _cmd_size = struct_name##_size();\ - u_int8_t _data[_cmd_size];\ - memset(_data, 0, _cmd_size);\ - if (should_pack) {\ - struct_name##_in_pack(&(cmd_struct->in), _data);\ - }\ - _rc = icmd_send_command(mf, op, _data, _cmd_size, skip_write);\ - if (_rc) {\ - return convert_rc(_rc);\ - }\ - struct_name##_unpack(cmd_struct, _data);\ - return GCIF_STATUS_SUCCESS - - -#endif diff --git a/cmdif/icmd_cif_open.c b/cmdif/icmd_cif_open.c deleted file mode 100644 index 84e8bb9..0000000 --- a/cmdif/icmd_cif_open.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#include "icmd_cif_common.h" -#include "icmd_cif_open.h" -#include "icmd_cif_macros.h" - - -/* - * gcif_get_fw_info - */ -int gcif_get_fw_info(mfile *mf, - OUT struct connectib_icmd_get_fw_info* fw_info) -{ - SEND_ICMD_FLOW(mf, GET_FW_INFO, connectib_icmd_get_fw_info, fw_info, 0, 1); -} diff --git a/cmdif/icmd_cif_open.h b/cmdif/icmd_cif_open.h deleted file mode 100644 index 79d9bfe..0000000 --- a/cmdif/icmd_cif_open.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _ICMD_OPEN_LIB /* guard */ -#define _ICMD_OPEN_LIB - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include "icmd_cif_common.h" - -#define IN -#define OUT -#define INOUT - - -int gcif_get_fw_info(mfile *mf, - OUT struct connectib_icmd_get_fw_info* fw_info); - -#undef IN -#undef OUT -#undef INOUT - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/cmdif/tools_cif.c b/cmdif/tools_cif.c deleted file mode 100644 index c6afc68..0000000 --- a/cmdif/tools_cif.c +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#include -#include - -#if !defined (__FreeBSD__) && !defined(UEFI_BUILD) -#include -#endif - -#include "tools_cif.h" - -#define TOOLS_HCR_MAX_MBOX 288 -#define QUERY_DEV_CAP_OP 0x3 -#define QUERY_DEF_PARAMS_OP 0x73 -#define HW_ACCESS_OP 0x60 - -#define QPC_READ_OP 0x67 -#define QPC_WRITE_OP 0x69 - -#define CHECK_RC(rc) \ - if (rc) return rc; - -#define BE32_TO_CPU(s, n) do { \ - u_int32_t i; \ - u_int32_t *p = (u_int32_t *)(s); \ - for (i=0; i<(n); i++,p++) \ - *p = __be32_to_cpu(*p); \ - } while(0) - -#if __BYTE_ORDER == __BIG_ENDIAN - -#define SWAP_DW_BE(uint64_num)\ - (((uint64_num) & 0xffffffffULL) << 32) | (((uint64_num) >> 32) & 0xffffffffULL) - -#else -#define SWAP_DW_BE(uint64_num) (uint64_num) -#endif - -//TODO: adrianc: if we find ourselves adding more and more commands consider using a macro to save code. -//TODO: adrianc: when library expands consider returning its own error code - -MError tcif_query_dev_cap(mfile *dev, u_int32_t offset, u_int64_t* data) -{ - int rc = tools_cmdif_send_mbox_command(dev, 0, QUERY_DEV_CAP_OP, 0, offset, (u_int32_t*)data, 8, 1); CHECK_RC(rc); - BE32_TO_CPU(data, 2); - *data = SWAP_DW_BE(*data); - return ME_OK; -} - - -MError tcif_query_global_def_params(mfile* dev, struct tools_open_query_def_params_global* global_params) -{ - u_int8_t data[TOOLS_OPEN_QUERY_DEF_PARAMS_GLOBAL_SIZE] = {0}; - int rc = tools_cmdif_send_mbox_command(dev, 0, QUERY_DEF_PARAMS_OP, 0, 0, data, sizeof(data), 0);CHECK_RC(rc); - tools_open_query_def_params_global_unpack(global_params, data); - return ME_OK; -} - - -MError tcif_query_per_port_def_params(mfile* dev, u_int8_t port, struct tools_open_query_def_params_per_port* port_params) -{ - u_int8_t data[TOOLS_OPEN_QUERY_DEF_PARAMS_PER_PORT_SIZE] = {0}; - int rc = tools_cmdif_send_mbox_command(dev, 0, QUERY_DEF_PARAMS_OP, port, 0, data, sizeof(data), 0);CHECK_RC(rc); - tools_open_query_def_params_per_port_unpack(port_params, data); - return ME_OK; -} - - -MError tcif_qpc_context_read(mfile* dev, u_int32_t qpn, u_int32_t source, u_int8_t* data, u_int32_t len) -{ - u_int32_t input_mod = 0; - input_mod = MERGE(input_mod, source, 24, 8); - input_mod = MERGE(input_mod, qpn , 0, 24); - int rc = tools_cmdif_send_mbox_command(dev, input_mod, QPC_READ_OP, 0, 0, data, len, 1); - CHECK_RC(rc); - return ME_OK; -} - - -MError tcif_qpc_context_write(mfile* dev, u_int32_t qpn, u_int32_t source, u_int8_t* data, u_int32_t len) -{ - u_int32_t input_mod = 0; - input_mod = MERGE(input_mod, source, 24, 8); - input_mod = MERGE(input_mod, qpn , 0, 24); - int rc = tools_cmdif_send_mbox_command(dev, input_mod, QPC_WRITE_OP, 0, 0, data, len, 0); - CHECK_RC(rc); - return ME_OK; -} - - -MError tcif_hw_access(mfile* dev, u_int64_t key, int lock_unlock) -{ - return tools_cmdif_send_inline_cmd(dev, key, NULL, 0, HW_ACCESS_OP, lock_unlock); -} -const char* tcif_err2str(MError rc) { - return m_err2str(rc); -} - - -MError tcif_cr_mbox_supported(mfile* dev) -{ -#if defined(__FreeBSD__) || defined(UEFI_BUILD) - (void)dev; - return ME_NOT_IMPLEMENTED; -#else - return tools_cmdif_is_cr_mbox_supported(dev); -#endif - -} diff --git a/cmdif/tools_cif.h b/cmdif/tools_cif.h deleted file mode 100644 index 6b636fa..0000000 --- a/cmdif/tools_cif.h +++ /dev/null @@ -1,130 +0,0 @@ -/* Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#ifndef TOOLS_CIF_H -#define TOOLS_CIF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - - -/** - * tcif_query_dev_cap: - * @param[in] dev A pointer to a device context. - * @param[in] offs offset in even dword to read from the DEV_CAP vector - * @param[out] data Quad-word read from the device capabilities vector from offset: offs - - * @return One of the MError* values, or a raw - **/ -MError tcif_query_dev_cap(mfile* dev, u_int32_t offs, u_int64_t* data); - -/** - * tcif_query_global_def_params: - * @param[in] dev A pointer to a device context. - * @param[in/out] global_params pointer to global params struct - - * @return One of the MError* values, or a raw - **/ -MError tcif_query_global_def_params(mfile* dev, struct tools_open_query_def_params_global* global_params); - -/** - * tcif_query_per_port_def_params: - * @param[in] dev A pointer to a device context. - * @param[in] port Port that the query will be performed on (1 or 2) - * @param[in/out] port_params Pointer to port params struct - - * @return One of the MError* values, or a raw - **/ -MError tcif_query_per_port_def_params(mfile* dev, u_int8_t port, struct tools_open_query_def_params_per_port* port_params); - -/** - * tcif_qpc_context_read: - * @param[in] dev A pointer to a device context. - * @param[in] qpn QP Number - * @param[in] source QP Source - * @param[in] data Data that was read - * - * @return One of the MError* values, or a raw - **/ -MError tcif_qpc_context_read(mfile* dev, u_int32_t qpn, u_int32_t source, u_int8_t* data, u_int32_t len); - -/** - * tcif_qpc_context_write: - * @param[in] dev A pointer to a device context. - * @param[in] qpn QP Number - * @param[in] source QP Source - * @param[in] data Data to be written - * - * @return One of the MError* values, or a raw - **/ -MError tcif_qpc_context_write(mfile* dev, u_int32_t qpn, u_int32_t source, u_int8_t* data, u_int32_t len); - - -/** - * tcif_hw_access: - * @param[in] dev A pointer to a device context. - * @param[in] key key with which we attempt to lock/unlock the cr-space (should be 0 for locking) - * @param[out] lock_unlock 1-lock , 0-unlock - - * @return One of the MError* values, or a raw - **/ -MError tcif_hw_access(mfile* dev, u_int64_t key, int lock_unlock); - -/** - * tcif_cr_mailbox_supported: - * @param[in] dev A pointer to a device context. - - * @return ME_OK - cr mailbox supported - * ME_SEM_LOCKED - tools HCR semaphore locked - * ME_CMDIF_NOT_SUPP - cr mailbox not supported - **/ -MError tcif_cr_mbox_supported(mfile* dev); - -/** - * tcif_err2str: - * @param[in] rc return code from one of the above functions - - * @return string describing the error occured. - **/ -const char* tcif_err2str(MError rc); - -#ifdef __cplusplus -} -#endif - -#endif /* TOOLS_CIF_H */ diff --git a/cmdparser/Makefile.am b/cmdparser/Makefile.am deleted file mode 100644 index 952a074..0000000 --- a/cmdparser/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in - -AM_CPPFLAGS = -W -g -MP -MD -fPIC - -noinst_LIBRARIES = libcmdparser.a - -libcmdparser_a_SOURCES = cmdparser.cpp my_getopt.c cmdparser.h my_getopt.h - diff --git a/cmdparser/cmdparser.cpp b/cmdparser/cmdparser.cpp deleted file mode 100644 index 0e38a05..0000000 --- a/cmdparser/cmdparser.cpp +++ /dev/null @@ -1,478 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#include -#include -#include -#include -#include -#include -#include "my_getopt.h" -#include "cmdparser.h" - - -/****************************************************/ -typedef vector < bool > vec_bool; - - -/****************************************************/ -/************class CommandLineRequester**************/ -/****************************************************/ -/* private methods */ -string CommandLineRequester::BuildOptStr(option_ifc_t &opt) -{ - string str; - - if (opt.option_short_name != ' ') { - str += "-"; - str += opt.option_short_name; - str += "|"; - } - str += "--"; - str += opt.option_name; - if (opt.option_value != "") { - str += " "; - str += opt.option_value; - } - return str; -} - - -/* public methods */ -#define OPT_STR_LEN 40 -#define OPT_DESC_LEN 40 -#define PREFIX_SPACE " " -#define PREFIX_SHORT_SPACE " " - - -string CommandLineRequester::GetUsageSynopsis(bool hidden_options) -{ - string str = ""; - string curr_str = PREFIX_SPACE; - - for (vec_option_t::iterator it = this->options.begin(); it != this->options.end(); ++it) { - if (hidden_options == false) { //display only not hidden options - if ((*it).hidden == true) { - continue; - } - } else { //display only hidden options - if ((*it).hidden == false) { - continue; - } - } - - curr_str += (*it).is_mandatory ? "<" : "["; - curr_str += this->BuildOptStr(*it); - curr_str += (*it).is_mandatory ? ">" : "]"; - if (curr_str.size() < OPT_STR_LEN) { - curr_str += " "; - } else { - str += curr_str; - str += "\n"; - curr_str = PREFIX_SPACE; - } - } - if (curr_str != PREFIX_SPACE) { - str += curr_str; - str += "\n"; - } - - if (str != "") { - str = PREFIX_SHORT_SPACE + this->name + "\n" + str; - } - - return str; -} - - -string CommandLineRequester::GetUsageDescription() -{ - if (this->description == "") - return ""; - string str = this->description; - - int prev_found = 0; - int found2 = str.find('\n', prev_found); - int found = str.find(" ", prev_found); - while (found != (int)string::npos) { - if ((found2 != (int)string::npos) && (found2 < found)) { - prev_found = found2; - } - if ((found - prev_found) > OPT_DESC_LEN + OPT_STR_LEN) { - prev_found = found + 1; - str.insert(found + 1, "\n"); - } - found2 = str.find('\n', found + 1); - found = str.find(" ", found + 1); - } - - prev_found = 0; - found = str.find('\n', prev_found); - while (found != (int)string::npos) { - str.insert(found + 1, PREFIX_SPACE); - prev_found = found + strlen(PREFIX_SPACE); - found = str.find('\n', prev_found); - } - - str = PREFIX_SPACE + str; - str = PREFIX_SHORT_SPACE + this->name + "\n" + str + "\n"; - - return str; -} - - -string CommandLineRequester::GetUsageOptions(bool hidden_options) -{ - string str = ""; - string opt_str, desc_str; - - for (vec_option_t::iterator it = this->options.begin(); it != this->options.end(); ++it) { - if (hidden_options == false) { //display only not hidden options - if ((*it).hidden == true) { - continue; - } - } else { //display only hidden options - if ((*it).hidden == false) { - continue; - } - } - - opt_str = PREFIX_SPACE; - opt_str += this->BuildOptStr(*it); - while (opt_str.size() < OPT_STR_LEN - 2) - opt_str += " "; - opt_str += ": "; - - desc_str = (*it).description; - int prev_found = 0; - int found2 = desc_str.find('\n', prev_found); - int found = desc_str.find(" ", prev_found); - while (found != (int)string::npos) { - if ((found2 != (int)string::npos) && (found2 < found)) { - prev_found = found2; - } - if ((found - prev_found + 1) > OPT_DESC_LEN) { - prev_found = found + 1; - desc_str.insert(found + 1, "\n"); - } - found2 = desc_str.find('\n', found + 1); - found = desc_str.find(" ", found + 1); - } - - prev_found = 0; - found = desc_str.find('\n', prev_found); - while (found != (int)string::npos) { - for (int i = 0; i < OPT_STR_LEN; ++i) - desc_str.insert(found + 1, " "); - prev_found = found + OPT_STR_LEN; - found = desc_str.find('\n', prev_found); - } - - str += opt_str; - str += desc_str; - str += "\n"; - } - - if (str != "") { - str = PREFIX_SHORT_SPACE + this->name + "\n" + str; - } - - return str; -} - - -/****************************************************/ -/**************class CommandLineParser***************/ -/****************************************************/ -/* private methods */ -void CommandLineParser::SetLastError(const char *fmt, ...) -{ - char buff[1024]; - va_list args; - - memset(buff, 0, sizeof(buff)); - va_start(args, fmt); - vsprintf(buff, fmt, args); - va_end(args); - - this->last_error.assign(buff); - return; -} - - -/* public methods */ -int CommandLineParser::AddRequester(CommandLineRequester *p_req) -{ - for (vec_option_t::iterator it = p_req->GetOptions().begin(); - it != p_req->GetOptions().end(); ++it) { - //long option must be valid - if ((*it).option_name == "") { - this->SetLastError("Requester \"%s\" has long option empty", - p_req->GetName().c_str()); - return 1; - } - - //check if long option already exists - map_str_p_command_line_req::iterator it2 = - this->long_opt_to_req_map.find((*it).option_name); - if (it2 != this->long_opt_to_req_map.end()) { - this->SetLastError("Option \"%s\" from requester \"%s\" " \ - "already exists in requester \"%s\"", - (*it).option_name.c_str(), - p_req->GetName().c_str(), - (*it2).second->GetName().c_str()); - return 1; - } - - //check if short option already exists - if ((*it).option_short_name != ' ') { //if space than no short option - map_char_str::iterator it2 = - this->short_opt_to_long_opt.find((*it).option_short_name); - if (it2 != this->short_opt_to_long_opt.end()) { - this->SetLastError("Option \'%c\' from requester \"%s\" " \ - "already exists in requester \"%s\"", - (*it).option_short_name, - p_req->GetName().c_str(), - this->long_opt_to_req_map[(*it2).second]->GetName().c_str()); - return 1; - } - } - } - - //finally add the requester - for (vec_option_t::iterator it = p_req->GetOptions().begin(); - it != p_req->GetOptions().end(); ++it) { - this->long_opt_to_req_map[(*it).option_name] = p_req; - if ((*it).option_short_name != ' ') //if space than no short option - this->short_opt_to_long_opt[(*it).option_short_name] = (*it).option_name; - } - this->p_requesters_list.push_back(p_req); - return 0; -} - - -string CommandLineParser::GetUsage(bool hidden_options) -{ - string res; - - //name - res = "NAME\n"; - res += PREFIX_SHORT_SPACE; - res += this->name; - res += "\n"; - - //synopsis - res += "SYNOPSIS\n"; - for (list_p_command_line_req::iterator it = this->p_requesters_list.begin(); - it != this->p_requesters_list.end(); ++it) { - res += (*it)->GetUsageSynopsis(hidden_options); - } - - //description - if (hidden_options == false) { - res += "DESCRIPTION\n"; - for (list_p_command_line_req::iterator it = this->p_requesters_list.begin(); - it != this->p_requesters_list.end(); ++it) { - res += (*it)->GetUsageDescription(); - } - } - - //options - res += "OPTIONS\n"; - for (list_p_command_line_req::iterator it = this->p_requesters_list.begin(); - it != this->p_requesters_list.end(); ++it) { - res += (*it)->GetUsageOptions(hidden_options); - } - return res; -} - - -ParseStatus CommandLineParser::ParseOptions(int argc, char **argv, - bool to_ignore_unknown_options, list_p_command_line_req *p_ignored_requesters_list) -{ - char **internal_argv; - struct option *options_arr = NULL; - string options_str = ""; - vec_bool returned_option_types_vec; - ParseStatus rc = PARSE_ERROR; - unsigned num_options = 0; - int option_type; - int option_index = 0; - unsigned i = 0; - - //allocate internal_argv - internal_argv = new char *[argc]; - if (!internal_argv) { - this->SetLastError("Fail to allocate internal argv for parsing"); - return PARSE_ERROR; - } - for (int j = 0; j < argc; ++j) { - internal_argv[j] = NULL; - } - for (int j = 0; j < argc; ++j) { - internal_argv[j] = new char[strlen(argv[j]) + 1]; - if (!internal_argv[j]) { - this->SetLastError("Fail to allocate internal argv[%u] for parsing", j); - rc = PARSE_ERROR; - goto argv_err_exit; - } - strcpy(internal_argv[j], argv[j]); - } - - //allocate long_options_arr - num_options = this->long_opt_to_req_map.size(); - options_arr = new struct option[num_options + 1]; - if (!options_arr) { - this->SetLastError("Fail to allocate long_options_arr"); - rc = PARSE_ERROR; - goto parse_exit; - } - memset(options_arr, 0, sizeof(struct option)*(num_options + 1)); - - /* - * fill options array and options string with - * getopt_long_only() formats - * also create vector of possible options type - * that can be return by getopt_long_only() - */ - i = 0; - for (list_p_command_line_req::iterator it = this->p_requesters_list.begin(); - it != this->p_requesters_list.end(); ++it) { - for (vec_option_t::iterator it2 = (*it)->GetOptions().begin(); - it2 != (*it)->GetOptions().end(); ++it2) { - options_str += (*it2).option_short_name; - options_arr[i].name = (*it2).option_name.c_str(); - if ((*it2).option_value != "") { - options_arr[i].has_arg = 1; - options_str += ":"; - } else { - options_arr[i].has_arg = 0; - } - options_arr[i].flag = 0; - if ((*it2).option_short_name != ' ') { - options_arr[i].val = (*it2).option_short_name; - } else { - options_arr[i].val = 0; - } - - if (returned_option_types_vec.empty() || (returned_option_types_vec.size() < (unsigned int)options_arr[i].val + 1)) - for (unsigned j = returned_option_types_vec.size(); j < (unsigned int)options_arr[i].val + 1; ++j) - returned_option_types_vec.push_back(false); - returned_option_types_vec[options_arr[i].val] = true; - //printf("%c %d ", options_arr[i].val, options_arr[i].val); - ++i; - } - } - - //finally parse all options - if (to_ignore_unknown_options == true) - tools_opterr = 0; - else - tools_opterr = 1; - tools_optind = 0; - - ParseStatus curr_result; - while ((option_type = tools_getopt_long_only(argc, internal_argv, options_str.c_str(), - options_arr, &option_index)) != -1) { - //printf("option_type=\'%c\'\n", option_type); - - string long_opt_name; - if (option_type == 0) { - long_opt_name = options_arr[option_index].name; - goto do_handle_option; - } else if (option_type == '?') { - if (to_ignore_unknown_options == true) - continue; - this->SetLastError("Bad input parameter"); - goto parse_exit; - } else if (returned_option_types_vec[option_type] == true) { - long_opt_name = this->short_opt_to_long_opt[option_type]; - goto do_handle_option; - } else { - this->SetLastError("getopt_long_only() returned character code 0%o", option_type); - goto parse_exit; - } - -do_handle_option: - CommandLineRequester *p_req = this->long_opt_to_req_map[long_opt_name]; - bool ignore_this_req = false; - if (p_ignored_requesters_list) - for (list_p_command_line_req::iterator it = p_ignored_requesters_list->begin(); - it != p_ignored_requesters_list->end(); ++it) { - if (p_req == (*it)) { - ignore_this_req = true; - break; - } - } - if (ignore_this_req == false) { - curr_result = p_req->HandleOption(long_opt_name, (tools_optarg == NULL) ? "" : tools_optarg); - if (curr_result) { - rc = curr_result; - this->SetLastError("Failed to handle option %s", long_opt_name.c_str()); - goto parse_exit; - } - } - continue; - } - - if (tools_optind < argc) { - while (tools_optind < argc) { - this->last_unknown_options += internal_argv[tools_optind]; - this->last_unknown_options += " "; - ++tools_optind; - } - /*if (this->last_unknown_options != "") //remove last space - this->last_unknown_options.erase(this->last_unknown_options.end() - 1, - this->last_unknown_options.end());*/ - if (to_ignore_unknown_options == false) { - string str = "Found some non-option ARGV-elements "; - str += this->last_unknown_options; - this->SetLastError(str.c_str()); - goto parse_exit; - } - } - - rc = PARSE_OK; -parse_exit: - for (int i = 0; i < argc; ++i) - delete [] internal_argv[i]; - delete [] internal_argv; - delete [] options_arr; - return rc; -argv_err_exit: - for (int i = 0; i < argc; ++i) - delete [] internal_argv[i]; - delete [] internal_argv; - return rc; -} - diff --git a/cmdparser/cmdparser.h b/cmdparser/cmdparser.h deleted file mode 100644 index 5501fac..0000000 --- a/cmdparser/cmdparser.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#ifndef _OPT_PARSER_H_ -#define _OPT_PARSER_H_ - - -#include -#include -#include -#include -#include -using namespace std; - - -/******************************************************/ -typedef enum -{ - //Returns: 0 - OK / 1 - parsing error / 2 - OK but need to exit / 3 - some other error - PARSE_OK = 0, - PARSE_ERROR = 1, - PARSE_OK_WITH_EXIT = 3, - PARSE_ERROR_SHOW_USAGE = 4 -} ParseStatus; - -typedef struct option_ifc { - string option_name; //must be valid - char option_short_name; //can be used as short option, if space than no short flag - string option_value; //if "" has no argument - string description; //will be display in usage - bool hidden; //if hidden than will not be diaplayed in regular usage - bool is_mandatory; -} option_ifc_t; - -typedef vector < struct option_ifc > vec_option_t; - - -class CommandLineRequester { -protected: - // members - vec_option_t options; - string name; - string description; - - // methods - string BuildOptStr(option_ifc_t &opt); - -public: - // methods - CommandLineRequester(string req_name) : name(req_name) {} - virtual ~CommandLineRequester() {} - - inline void AddOptions(option_ifc_t options[], int arr_size) { - for (int i = 0; i < arr_size; ++i) - this->options.push_back(options[i]); - } - inline void AddOptions(string option_name, - char option_short_name, - string option_value, - string description, - bool hidden = false, - bool is_mandatory = false) { - option_ifc_t opt; - opt.option_name = option_name; - opt.option_short_name = option_short_name; - opt.option_value = option_value; - opt.description = description; - opt.hidden = hidden; - opt.is_mandatory = is_mandatory; - this->options.push_back(opt); - } - inline void AddDescription(string desc) { this->description = desc; } - inline vec_option_t& GetOptions() { return this->options; } - inline string& GetName() { return this->name; } - - string GetUsageSynopsis(bool hidden_options = false); - string GetUsageDescription(); - string GetUsageOptions(bool hidden_options = false); - - virtual ParseStatus HandleOption(string name, string value) = 0; -}; - - -/******************************************************/ -typedef list < CommandLineRequester * > list_p_command_line_req; -typedef map < char, string > map_char_str; -typedef map < string, CommandLineRequester * > map_str_p_command_line_req; - - -class CommandLineParser { -private: - // members - list_p_command_line_req p_requesters_list; - map_char_str short_opt_to_long_opt; - map_str_p_command_line_req long_opt_to_req_map; - - string name; - string last_error; - string last_unknown_options; - - // methods - void SetLastError(const char *fmt, ...); - -public: - // methods - CommandLineParser(string parser_name) : - name(parser_name), last_error(""), last_unknown_options("") {} - ~CommandLineParser() {} - - inline const char * GetErrDesc() { return this->last_error.c_str(); } - inline const char * GetUnknownOptions() { return this->last_unknown_options.c_str(); } - - int AddRequester(CommandLineRequester *p_req); //if multiple option than fail - - ParseStatus ParseOptions(int argc, char **argv, - bool to_ignore_unknown_options = false, - list_p_command_line_req *p_ignored_requesters_list = NULL); - - string GetUsage(bool hidden_options = false); -}; - - -#endif /* not defined _OPT_PARSER_H_ */ diff --git a/cmdparser/my_getopt.c b/cmdparser/my_getopt.c deleted file mode 100755 index be6281d..0000000 --- a/cmdparser/my_getopt.c +++ /dev/null @@ -1,1086 +0,0 @@ - /* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97 - Free Software Foundation, Inc. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - - /* This tells Alpha OSF/1 not to define a getopt prototype in . - Ditto for AIX 3.2 and . */ - #ifndef _NO_PROTO - #define _NO_PROTO - #endif - - #ifdef HAVE_CONFIG_H - #include - #endif - - #if !defined (__STDC__) || !__STDC__ - /* This is a separate conditional since some stdc systems - reject `defined (const)'. */ - #ifndef const - #define const - #endif - #endif - - #include - - /* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - - #define GETOPT_INTERFACE_VERSION 2 - #if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 - #include - #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION - #define ELIDE_CODE - #endif - #endif - - - - /* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ - #ifdef __GNU_LIBRARY__ - /* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ - #include - #include - #endif /* GNU C library. */ - - #ifdef HAVE_STRING_H - # include /* strstr / strdup */ - #else - # ifdef HAVE_STRINGS_H - # include /* strstr / strdup */ - # endif - #endif - - #ifdef VMS - #include - #if HAVE_STRING_H - 0 - #include - #endif - #endif -#include - #ifndef _ - /* This is for other GNU distributions with internationalized messages. - When compiling libc, the _ macro is predefined. */ - #ifdef HAVE_LIBINTL_H - # include - # define _(msgid) gettext (msgid) - #else - # define _(msgid) (msgid) - #endif - #endif - - /* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - - #include "my_getopt.h" - - /* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - - char *tools_optarg = NULL; - - /* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `tools_optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - - /* 1003.2 says this must be 1 before any call. */ - int tools_optind = 1; - - /* Formerly, initialization of getopt depended on tools_optind==0, which - causes problems with re-calling getopt as programs generally don't - know that. */ - - int __getopt_initialized = 0; - - /* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - - static char *nextchar; - - /* Callers store zero here to inhibit the error message - for unrecognized options. */ - - int tools_opterr = 1; - - /* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - - int tools_optopt = '?'; - - /* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return -1 with `tools_optind' != ARGC. */ - - static enum - { - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER - } ordering; - - /* Value of POSIXLY_CORRECT environment variable. */ - static char *posixly_correct; - - #ifdef __GNU_LIBRARY__ - /* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ - #include - #define my_index strchr - #else - - /* Avoid depending on library functions or files - whose names are inconsistent. */ - - char *getenv (); - - static char * - my_index (str, chr) - const char *str; - int chr; - { - while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } - return 0; - } - - /* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. */ - #ifdef __GNUC__ - /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - That was relevant to code that was here before. */ - #if !defined (__STDC__) || !__STDC__ - /* gcc with -traditional declares the built-in strlen to return int, - and has done so at least since version 2.4.5. -- rms. */ - extern int strlen (const char *); - #endif /* not __STDC__ */ - #endif /* __GNUC__ */ - - #endif /* not __GNU_LIBRARY__ */ - - /* Handle permutation of arguments. */ - - /* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - - static int first_nonopt; - static int last_nonopt; - - #ifdef _LIBC - /* Bash 2.0 gives us an environment variable containing flags - indicating ARGV elements that should not be considered arguments. */ - - /* Defined in getopt_init.c */ - extern char *__getopt_nonoption_flags; - - static int nonoption_flags_max_len; - static int nonoption_flags_len; - - static int original_argc; - static char *const *original_argv; - - /* Make sure the environment variable bash 2.0 puts in the environment - is valid for the getopt call we must make sure that the ARGV passed - to getopt is that one passed to the process. */ - static void - __attribute__ ((unused)) - store_args_and_env (int argc, char *const *argv) - { - /* XXX This is no good solution. We should rather copy the args so - that we can compare them later. But we must not use malloc(3). */ - original_argc = argc; - original_argv = argv; - } - # ifdef text_set_element - text_set_element (__libc_subinit, store_args_and_env); - # endif /* text_set_element */ - - # define SWAP_FLAGS(ch1, ch2) \ - if (nonoption_flags_len > 0) \ - { \ - char __tmp = __getopt_nonoption_flags[ch1]; \ - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ - __getopt_nonoption_flags[ch2] = __tmp; \ - } - #else /* !_LIBC */ - # define SWAP_FLAGS(ch1, ch2) - #endif /* _LIBC */ - - /* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,tools_optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - - #if defined (__STDC__) && __STDC__ - static void exchange (char **); - #endif - - static void - exchange (argv) - char **argv; - { - int bottom = first_nonopt; - int middle = last_nonopt; - int top = tools_optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - - #ifdef _LIBC - /* First make sure the handling of the `__getopt_nonoption_flags' - string can work normally. Our top argument must be in the range - of the string. */ - if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) - { - /* We must extend the array. The user plays games with us and - presents new arguments. */ - char *new_str = malloc (top + 1); - if (new_str == NULL) - nonoption_flags_len = nonoption_flags_max_len = 0; - else - { - memset (__mempcpy (new_str, __getopt_nonoption_flags, - nonoption_flags_max_len), - '\0', top + 1 - nonoption_flags_max_len); - nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } - } - #endif - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (tools_optind - last_nonopt); - last_nonopt = tools_optind; - } - - /* Initialize the internal data when the first call is made. */ - - #if defined (__STDC__) && __STDC__ - static const char *_getopt_initialize (int, char *const *, const char *); - #endif - static const char * - _getopt_initialize (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; - { - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - // avoid compiler warnings - (void) argc; - (void) argv; - first_nonopt = last_nonopt = tools_optind; - - nextchar = NULL; - - posixly_correct = getenv ("POSIXLY_CORRECT"); - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (posixly_correct != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - - #ifdef _LIBC - if (posixly_correct == NULL - && argc == original_argc && argv == original_argv) - { - if (nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL - || __getopt_nonoption_flags[0] == '\0') - nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = nonoption_flags_max_len = strlen (orig_str); - if (nonoption_flags_max_len < argc) - nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - (char *) malloc (nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - nonoption_flags_max_len = -1; - else - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), - '\0', nonoption_flags_max_len - len); - } - } - nonoption_flags_len = nonoption_flags_max_len; - } - else - nonoption_flags_len = 0; - #endif - - return optstring; - } - - /* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `tools_optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns -1. - Then `tools_optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `tools_opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `tools_optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `tools_optarg', otherwise `tools_optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - - int - _getopt_internal (argc, argv, optstring, longopts, longind, long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; - { - tools_optarg = NULL; - - if (tools_optind == 0 || !__getopt_initialized) - { - if (tools_optind == 0) - tools_optind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = _getopt_initialize (argc, argv, optstring); - __getopt_initialized = 1; - } - - /* Test whether ARGV[tools_optind] points to a non-option argument. - Either it does not have option syntax, or there is an environment flag - from the shell indicating it is not an option. The later information - is only used when the used in the GNU libc. */ - #ifdef _LIBC - #define NONOPTION_P (argv[tools_optind][0] != '-' || argv[tools_optind][1] == '\0' \ - || (tools_optind < nonoption_flags_len \ - && __getopt_nonoption_flags[tools_optind] == '1')) - #else - #define NONOPTION_P (argv[tools_optind][0] != '-' || argv[tools_optind][1] == '\0') - #endif - - if (nextchar == NULL || *nextchar == '\0') - { - /* Advance to the next ARGV-element. */ - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ - if (last_nonopt > tools_optind) - last_nonopt = tools_optind; - if (first_nonopt > tools_optind) - first_nonopt = tools_optind; - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != tools_optind) - exchange ((char **) argv); - else if (last_nonopt != tools_optind) - first_nonopt = tools_optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (tools_optind < argc && NONOPTION_P) - tools_optind++; - last_nonopt = tools_optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (tools_optind != argc && !strcmp (argv[tools_optind], "--")) - { - tools_optind++; - - if (first_nonopt != last_nonopt && last_nonopt != tools_optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = tools_optind; - last_nonopt = argc; - - tools_optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (tools_optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - tools_optind = first_nonopt; - return -1; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - tools_optarg = argv[tools_optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - nextchar = (argv[tools_optind] + 1 - + (longopts != NULL && argv[tools_optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[tools_optind][1] == '-' - || (long_only && (argv[tools_optind][2] || !my_index (optstring, argv[tools_optind][1]))))) - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) - == (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (tools_opterr) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[tools_optind]); - nextchar += strlen (nextchar); - tools_optind++; - tools_optopt = 0; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - tools_optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - { - tools_optarg = nameend + 1; - } - else - { - if (tools_opterr) { - if (argv[tools_optind - 1][1] == '-') { - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[tools_optind - 1][0], pfound->name); - } - } - nextchar += strlen (nextchar); - - tools_optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (tools_optind < argc) - tools_optarg = argv[tools_optind++]; - else - { - if (tools_opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[tools_optind - 1]); - nextchar += strlen (nextchar); - tools_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[tools_optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (tools_opterr) - { - if (argv[tools_optind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[tools_optind][0], nextchar); - } - nextchar = (char *) ""; - tools_optind++; - tools_optopt = 0; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `tools_optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++tools_optind; - - if (temp == NULL || c == ':') - { - if (tools_opterr) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), - argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), - argv[0], c); - } - tools_optopt = c; - return '?'; - } - /* Convenience. Treat POSIX -W foo same as long option --foo */ - if (temp[0] == 'W' && temp[1] == ';') - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - tools_optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - tools_optind++; - } - else if (tools_optind == argc) - { - if (tools_opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - tools_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `tools_optind' once; - increment it again when taking next ARGV-elt as argument. */ - tools_optarg = argv[tools_optind++]; - - /* tools_optarg is now the argument, see if it's in the - table of longopts. */ - - for (nextchar = nameend = tools_optarg; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (tools_opterr) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[tools_optind]); - nextchar += strlen (nextchar); - tools_optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - tools_optarg = nameend + 1; - else - { - if (tools_opterr) - fprintf (stderr, _("\ - %s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (tools_optind < argc) - tools_optarg = argv[tools_optind++]; - else - { - if (tools_opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[tools_optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - tools_optarg = nextchar; - tools_optind++; - } - else - tools_optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - tools_optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - tools_optind++; - } - else if (tools_optind == argc) - { - if (tools_opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - tools_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `tools_optind' once; - increment it again when taking next ARGV-elt as argument. */ - tools_optarg = argv[tools_optind++]; - nextchar = NULL; - } - } - return c; - } - } - - int - tools_getopt (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; - { - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); - } - - int - tools_getopt_long (argc, argv, optstring, longopts, longindex) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longindex; - { - return _getopt_internal (argc, argv, optstring, - longopts, - longindex, - 0); - } - - - int - tools_getopt_long_only (argc, argv, optstring, longopts, longindex) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longindex; - { - return _getopt_internal (argc, argv, optstring, - longopts, - longindex, - 1); - } - - - #ifdef TEST - - /* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - - int - main (argc, argv) - int argc; - char **argv; - { - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = tools_optind ? tools_optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == -1) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", tools_optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (tools_optind < argc) - { - printf ("non-option ARGV-elements: "); - while (tools_optind < argc) - printf ("%s ", argv[tools_optind++]); - printf ("\n"); - } - - exit (0); - } - - #endif /* TEST */ - -int hello() -{ - return 1; -} diff --git a/cmdparser/my_getopt.h b/cmdparser/my_getopt.h deleted file mode 100755 index b470f81..0000000 --- a/cmdparser/my_getopt.h +++ /dev/null @@ -1,122 +0,0 @@ - /* Declarations for getopt. - Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - - #ifndef _TOOLS_GETOPT_H - #define _TOOLS_GETOPT_H - - #ifdef __cplusplus - extern "C" { - #endif - - /* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - - extern char *tools_optarg; - - /* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - - extern int tools_optind; - - /* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - - extern int tools_opterr; - - /* Set to an option character which was unrecognized. */ - - extern int tools_optopt; - - /* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - - struct option - { - #if defined (__STDC__) && __STDC__ - const char *name; - #else - char *name; - #endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; - }; - - /* Names for the values of the `has_arg' field of `struct option'. */ - - #define tools_no_argument 0 - #define tools_required_argument 1 - #define tools_optional_argument 2 - -int tools_getopt ( - int argc, - char *const *argv, - const char *shortopts); - -int tools_getopt_long ( - int argc, - char *const *argv, - const char *shortopts, - const struct option *longopts, - int *longind); - -int tools_getopt_long_only ( - int argc, - char *const *argv, - const char *shortopts, - const struct option *longopts, - int *longind); - - #ifdef __cplusplus - } - #endif - - #endif /* _TOOLS_GETOPT_H */ diff --git a/common/Makefile.am b/common/Makefile.am deleted file mode 100644 index 982c5aa..0000000 --- a/common/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in - -noinst_HEADERS=compatibility.h bit_slice.h tools_utils.h tools_utils.h tools_version.h - diff --git a/common/bit_slice.h b/common/bit_slice.h deleted file mode 100644 index f257c9b..0000000 --- a/common/bit_slice.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef BIT_SLICE_H -#define BIT_SLICE_H - -// BIT Slicing macros -#define ONES32(size) ((size)?(0xffffffff>>(32-(size))):0) -#define MASK32(offset,size) (ONES32(size)<<(offset)) - -#define EXTRACT_C(source,offset,size) ((((unsigned)(source))>>(offset)) & ONES32(size)) -#define EXTRACT(src,start,len) (((len)==32)?(src):EXTRACT_C(src,start,len)) -#define EXT(src,end,start) EXTRACT(src,start,end-start+1) - -#define MERGE_C(rsrc1,rsrc2,start,len) ((((rsrc2)<<(start)) & (MASK32((start),(len)))) | ((rsrc1) & (~MASK32((start),(len))))) -#define MERGE(rsrc1,rsrc2,start,len) (((len)==32)?(rsrc2):MERGE_C(rsrc1,rsrc2,start,len)) -#define INSERTF(src1, start1, src2, start2, len) MERGE((src1), EXTRACT((src2), (start2), (len)), (start1), (len)) - -#define ONES64(size) ((size)?(0xffffffffffffffffULL>>(64-(size))):0) -#define MASK64(offset,size) (ONES64(size)<<(offset)) - -#define EXTRACT_C64(source,offset,size) ((((unsigned long long)(source))>>(offset)) & ONES64(size)) -#define EXTRACT64(src,start,len) (((len)==64)?(src):EXTRACT_C64(src,start,len)) - -#define MERGE_C64(rsrc1,rsrc2,start,len) ((((u_int64_t)(rsrc2)<<(start)) & (MASK64((start),(len)))) | ((rsrc1) & (~MASK64((start),(len))))) -#define MERGE64(rsrc1,rsrc2,start,len) (((len)==64)?(rsrc2):MERGE_C64(rsrc1,rsrc2,start,len)) -#define INSERTF64(src1, start1, src2, start2, len) MERGE64((src1), EXTRACT64((src2), (start2), (len)), (start1), (len)) -#define EXT64(src,end,start) EXTRACT64(src,start,end-start+1) - -#ifndef __cplusplus -enum cpp_bool {false=0,true}; -typedef unsigned char bool; -#endif - -#endif diff --git a/common/compatibility.h b/common/compatibility.h deleted file mode 100644 index 8dc85e3..0000000 --- a/common/compatibility.h +++ /dev/null @@ -1,427 +0,0 @@ -/* - * Copyright (C) Jan 2006 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * compatibility.h - Miscellaneous systems compatibility issues - * - * Version: $Id: compatibility.h 3261 2007-01-28 14:59:53Z orenk $ - * - */ - -#ifndef COMPATIBILITY_H -#define COMPATIBILITY_H - -#include - -#if defined(__ia64__) || defined(__x86_64__) || defined(__PPC64__) - #define U64L "l" -#else - #define U64L "ll" -#endif - - -/* define macros to the architecture of the CPU */ -#if defined(__linux) || defined(__FreeBSD__) /* __linux || __FreeBSD__ */ -# if defined(__i386__) -# define ARCH_x86 -# elif defined(__x86_64__) -# define ARCH_x86_64 -# elif defined(__ia64__) -# define ARCH_ia64 -# elif defined(__PPC64__) -# define ARCH_ppc64 -# elif defined(__PPC__) -# define ARCH_ppc -# elif defined(__aarch64__) -# define ARCH_arm64 -# else -# error Unknown CPU architecture using the linux OS -# endif -#elif defined(__MINGW32__) || defined(__MINGW64__) /* Windows MINGW */ -# if defined(__MINGW32__) -# define ARCH_x86 -# elif defined(__MINGW64__) -# define ARCH_x86_64 -# else -# error Unknown CPU architecture using the windows-mingw OS -# endif -#elif defined(_WIN32) || defined(_WIN64) /* Windows */ -# if defined(_WIN32) -# define ARCH_x86 -# elif defined(_WIN64) -# define ARCH_x86_64 -# else -# error Unknown CPU architecture using the windows OS -# endif -#else /* Unknown */ -# error Unknown OS -#endif - -/* define macros for print fields */ -#define U32D_FMT "%u" -#define U32H_FMT "0x%08x" -#define UH_FMT "0x%x" -#define STR_FMT "%s" -#define U16H_FMT "0x%04x" -#define U8H_FMT "0x%02x" - -#if defined(ARCH_x86) || defined(ARCH_ppc) || defined(UEFI_BUILD) -# if defined(__MINGW32__) || defined(__MINGW64__) -# include -# define U64D_FMT "0x%"PRId64 -# define U64H_FMT "0x%"PRIx64 -# define U64H_FMT_GEN ""PRIx64 -# define U48H_FMT "0x%"PRIx64 -# define U64D_FMT_GEN ""PRId64 -# else -# define U64D_FMT "%llu" -# define U64H_FMT "0x%016llx" -# define U64H_FMT_GEN "llx" -# define U48H_FMT "0x%012llx" -# define U64D_FMT_GEN "llu" -# endif -#elif defined (ARCH_ia64) || defined(ARCH_x86_64) || defined(ARCH_ppc64) || defined(ARCH_arm64) -# define U64D_FMT "%lu" -# define U64H_FMT "0x%016lx" -# define U48H_FMT "0x%012lx" -# define U64H_FMT_GEN "lx" -# define U64D_FMT_GEN "lu" -#else -# error Unknown architecture -#endif /* ARCH */ - - -/* define msleep(x) - sleeps for x milliseconds */ -#if defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__) - #include - #include - #include - #define msleep(x) Sleep(x) -#else - #include - #define msleep(x) usleep(((unsigned long)x)*1000) -#endif - -/* - * Only for architectures which can't do swab by themselves - */ -#define ___my_swab16(x) \ -((u_int16_t)( \ - (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \ - (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) )) -#define ___my_swab32(x) \ -((u_int32_t)( \ - (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \ - (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \ - (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \ - (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) )) -#define ___my_swab64(x) \ -((u_int64_t)( \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \ - (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) )) - -/* - * Linux - */ -#if defined(linux) || defined(__FreeBSD__) -// #include - #include - #include - - #if defined (__FreeBSD__) - #include - #else - #include - #endif - - #undef __be64_to_cpu - #undef __be32_to_cpu - #undef __be16_to_cpu - #undef __cpu_to_be64 - #undef __cpu_to_be32 - #undef __cpu_to_be16 - #undef __le64_to_cpu - #undef __le32_to_cpu - #undef __le16_to_cpu - #undef __cpu_to_le64 - #undef __cpu_to_le32 - #undef __cpu_to_le16 - - #if __BYTE_ORDER == __LITTLE_ENDIAN - - #define __be64_to_cpu(x) ___my_swab64(x) - #define __be32_to_cpu(x) ___my_swab32(x) - #define __be16_to_cpu(x) ___my_swab16(x) - #define __cpu_to_be64(x) ___my_swab64(x) - #define __cpu_to_be32(x) ___my_swab32(x) - #define __cpu_to_be16(x) ___my_swab16(x) - #define __le64_to_cpu(x) (x) - #define __le32_to_cpu(x) (x) - #define __le16_to_cpu(x) (x) - #define __cpu_to_le64(x) (x) - #define __cpu_to_le32(x) (x) - #define __cpu_to_le16(x) (x) - - #elif __BYTE_ORDER == __BIG_ENDIAN - - #define __be64_to_cpu(x) (x) - #define __be32_to_cpu(x) (x) - #define __be16_to_cpu(x) (x) - #define __cpu_to_be64(x) (x) - #define __cpu_to_be32(x) (x) - #define __cpu_to_be16(x) (x) - #define __le64_to_cpu(x) ___my_swab64(x) - #define __le32_to_cpu(x) ___my_swab32(x) - #define __le16_to_cpu(x) ___my_swab16(x) - #define __cpu_to_le64(x) ___my_swab64(x) - #define __cpu_to_le32(x) ___my_swab32(x) - #define __cpu_to_le16(x) ___my_swab16(x) - - #endif // __BYTE_ORDER - -#endif - -/* - * Windows (CYGWIN) - */ -#if defined(__CYGWIN32__) - #include - #include - - #define __be64_to_cpu(x) ___my_swab64(x) - #define __be32_to_cpu(x) ___my_swab32(x) - #define __be16_to_cpu(x) ___my_swab16(x) - #define __cpu_to_be64(x) ___my_swab64(x) - #define __cpu_to_be32(x) ___my_swab32(x) - #define __cpu_to_be16(x) ___my_swab16(x) - #define __le64_to_cpu(x) (x) - #define __le32_to_cpu(x) (x) - #define __le16_to_cpu(x) (x) - #define __cpu_to_le64(x) (x) - #define __cpu_to_le32(x) (x) - #define __cpu_to_le16(x) (x) - -#endif - -/* - * Windows (DDK) - */ -#if defined(__WIN__) - #include - #include - #include - #include - - #define __LITTLE_ENDIAN 1234 - #define __BIG_ENDIAN 4321 - #define __BYTE_ORDER __LITTLE_ENDIAN - - #define __be64_to_cpu(x) ___my_swab64(x) - #define __be32_to_cpu(x) ___my_swab32(x) - #define __be16_to_cpu(x) ___my_swab16(x) - #define __cpu_to_be64(x) ___my_swab64(x) - #define __cpu_to_be32(x) ___my_swab32(x) - #define __cpu_to_be16(x) ___my_swab16(x) - #define __le64_to_cpu(x) (x) - #define __le32_to_cpu(x) (x) - #define __le16_to_cpu(x) (x) - #define __cpu_to_le64(x) (x) - #define __cpu_to_le32(x) (x) - #define __cpu_to_le16(x) (x) - - - #if defined(__MINGW32__) || defined(__MINGW64__) - #include - #ifndef MFT_TOOLS_VARS - #define MFT_TOOLS_VARS - typedef uint8_t u_int8_t; - typedef uint16_t u_int16_t; - typedef uint32_t u_int32_t; - typedef uint64_t u_int64_t; - #endif - #include // Get a define for strcasecmp - // #define usleep(x) Sleep((x + 999)/1000) - - #else - typedef unsigned __int8 u_int8_t; - typedef __int8 int8_t; - typedef unsigned __int16 u_int16_t; - typedef __int16 int16_t; - typedef unsigned __int32 u_int32_t; - typedef __int32 int32_t; - typedef unsigned __int64 u_int64_t; - typedef __int64 int64_t; - - #define strcasecmp _stricmp - #define strtoll _strtoi64 - #define strtoull _strtoui64 - #define strdup _strdup - - #endif - - #ifndef __WIN__ // TBD : investigate crash on win -inline - #endif - - #define COMP_CDECL __cdecl - #define COMP_OPEN ::_open - #define COMP_CLOSE ::_close - #define COMP_READ ::_read - #define COMP_FSTAT ::_fstat - - #ifndef __cplusplus - #define close _close - #endif - -typedef struct _stat Stat; - - #define PRIx64 "I64x" - #define PRIu64 "I64u" -/* - #ifdef __cplusplus -static inline int pread(int fd, void *buf, int count, u_int64_t offset) {return -1;} -static inline int pwrite(int fd, const void *buf, int count, u_int64_t offset) {return -1;} - #else -static inline int pread(int fd, void *buf, int count, u_int64_t offset) {return -1;} -static inline int pwrite(int fd, const void *buf, int count, u_int64_t offset) {return -1;} - #endif -*/ -#else - - #define COMP_CDECL - #define COMP_OPEN ::open - #define COMP_CLOSE ::close - #define COMP_READ ::read - #define COMP_FSTAT ::fstat - -typedef struct stat Stat; - - #include - #include - -#endif - - - -/* - * MAC (Darwin) - */ -#if defined(__APPLE_CC__) - #include - - #define __swab64(x) NXSwapLongLong(x) - #define __swab32(x) NXSwapLong(x) - #define __swab16(x) NXSwapShort(x) - #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x) - #define __be32_to_cpu(x) NXSwapBigLongToHost(x) - #define __be16_to_cpu(x) NXSwapBigShortToHost(x) - #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x) - #define __le32_to_cpu(x) NXSwapLittleLongToHost(x) - #define __le16_to_cpu(x) NXSwapLittleShortToHost(x) - #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x) - #define __cpu_to_be32(x) NXSwapHostLongToBig(x) - #define __cpu_to_be16(x) NXSwapHostShortToBig(x) - #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x) - #define __cpu_to_le32(x) NXSwapHostLongToLittle(x) - #define __cpu_to_le16(x) NXSwapHostShortToLittle(x) - - #define __LITTLE_ENDIAN 1234 - #define __BIG_ENDIAN 4321 - #define __PDP_ENDIAN 3412 - #define __BYTE_ORDER __BIG_ENDIAN -#endif - -/* - * Solaris - * ------- - */ -#if defined(__sparc__) - #include - #include - #include - - #define __be64_to_cpu(x) (x) - #define __be32_to_cpu(x) (x) - #define __be16_to_cpu(x) (x) - #define __cpu_to_be64(x) (x) - #define __cpu_to_be32(x) (x) - #define __cpu_to_be16(x) (x) - #define __le64_to_cpu(x) ___my_swab64(x) - #define __le32_to_cpu(x) ___my_swab32(x) - #define __le16_to_cpu(x) ___my_swab16(x) - #define __cpu_to_le64(x) ___my_swab64(x) - #define __cpu_to_le32(x) ___my_swab32(x) - #define __cpu_to_le16(x) ___my_swab16(x) - -typedef uint64_t u_int64_t; -typedef uint32_t u_int32_t; -typedef uint16_t u_int16_t; -typedef uint8_t u_int8_t; - -#endif - -// Convert BYTES - DWORDS with MEMCPY BE -#define BYTES_TO_DWORD_BE(dw_dest, byte_src) do { u_int32_t tmp;\ - memcpy(&tmp, byte_src, 4);\ - *(dw_dest) = __be32_to_cpu(tmp);\ - } while (0) - -#define DWORD_TO_BYTES_BE(bytes_dest, dw_src) do { u_int32_t tmp;\ - tmp = __cpu_to_be32(*(dw_src));\ - memcpy(bytes_dest, &tmp, 4);\ - } while (0) - -/* - * Old GCC - * ------- - */ -#if !defined(__WIN__) && defined(__cplusplus) && __GNUG__ < 3 - #include -#endif - -#define __STDC_FORMAT_MACROS -#if !defined(__WIN__) && !defined(UEFI_BUILD) - #include -#endif - -#if defined(__VMKERNEL_UW_VMKLINUX__) || defined(__VMKERNEL_UW_NATIVE__) - #define ROOT_PATH "/opt/mellanox/" -#else - #define ROOT_PATH "/" -#endif - -#endif - diff --git a/common/tools_utils.h b/common/tools_utils.h deleted file mode 100755 index 7fe1a59..0000000 --- a/common/tools_utils.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef TOOLS_UTILS_H -#define TOOLS_UTILS_H - -#include "compatibility.h" - -#define CPU_TO_BE32(x) __cpu_to_be32(x) -#define CPU_TO_LE32(x) __cpu_to_le32(x) -#define BE32_TO_CPU(x) __be32_to_cpu(x) -#define LE32_TO_CPU(x) __le32_to_cpu(x) -#define CPU_TO_BE16(x) __cpu_to_be16(x) -#define CPU_TO_LE16(x) __cpu_to_le16(x) -#define BE16_TO_CPU(x) __be16_to_cpu(x) -#define LE16_TO_CPU(x) __le16_to_cpu(x) -#define CPU_TO_BE64(x) __cpu_to_be64(x) -#define CPU_TO_LE64(x) __cpu_to_le64(x) -#define BE64_TO_CPU(x) __be64_to_cpu(x) -#define LE64_TO_CPU(x) __le64_to_cpu(x) - -#define FIELD_8_OF_BUFF(buf, offset) (*(u_int8_t*)((u_int8_t*)(buf) + (offset))) -#define FIELD_16_OF_BUFF(buf, offset) (*(u_int16_t*)((u_int8_t*)(buf) + (offset))) -#define FIELD_32_OF_BUFF(buf, offset) (*(u_int32_t*)((u_int8_t*)(buf) + (offset))) -#define FIELD_64_OF_BUFF(buf, offset) (*(u_int64_t*)((u_int8_t*)(buf) + (offset))) -#define BYTE_N(buf, n) FIELD_8_OF_BUFF((buf), (n)) -#define WORD_N(buf, n) FIELD_16_OF_BUFF((buf), (n) * 2) -#define DWORD_N(buf, n) FIELD_32_OF_BUFF((buf), (n) * 4) -#define QWORD_N(buf, n) FIELD_64_OF_BUFF((buf), (n) * 8) -#define QWORD_EXTRACT_DWORD_HI(qword) ((u_int64_t)(qword) >> 32) -#define QWORD_EXTRACT_DWORD_LO(qword) ((u_int64_t)(qword) & (u_int64_t)0xffffffff) -#define QWORD_INSERT_DWORD_HI(qword, dword) qword = ((qword & (u_int64_t)0xffffffff) | ((u_int64_t)dword << 32)) -#define QWORD_INSERT_DWORD_LO(qword, dword) qword = ((qword & (u_int64_t)0xffffffff00000000) | ((u_int64_t)dword)) -#define U32_TO_U64(dword1, dword2) ((((u_int64_t)(dword1)) << 32) | (((u_int64_t)(dword2)) & 0xffffffff)) - - -#define TOOLS_MAX(a,b) ((a) > (b) ? (a) : (b)) -#define TOOLS_MIN(a,b) ((a) < (b) ? (a) : (b)) -#define TOOLS_ARR_SZ(arr) (sizeof((arr))/sizeof((arr)[0])) - -/** - * Suppress compiler warning about unused variable. - */ -#define TOOLS_UNUSED(var) ((void)var) - - -#endif // TOOLS_UTILS_H - diff --git a/common/tools_version.h b/common/tools_version.h deleted file mode 100644 index e3a242f..0000000 --- a/common/tools_version.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -// -// Generic version for all tools -// -#ifndef TOOLS_VERSION_H -#define TOOLS_VERSION_H - - -#include -#include -#include - -// To be replaced by an external script: -#include "gitversion.h" -#ifndef TOOLS_GIT_SHA - #define TOOLS_GIT_SHA "6469M" -#endif - -#ifdef HAVE_CONFIG_H - #include - #ifndef MFT_VERSION_STR - #define MFT_VERSION_STR PACKAGE_STRING - #endif -#endif - -#ifndef MFT_VERSION_STR - #define MFT_VERSION_STR "mft V.V.V-R" -#endif - -static inline -int get_version_string(char* buf, int buf_size, const char* exe_name, const char* tool_version) { - int len = 0; - // "svn ci" updates the below line - - - if (tool_version == NULL || !strcmp(tool_version, "")) { - len = snprintf(buf, buf_size, "%s, ", exe_name); - } else { - len = snprintf(buf, buf_size, "%s %s, ", exe_name, tool_version); - } - // cut out first and last "$" from the SVN version string: - len += snprintf(buf + len, buf_size - len, "%s, built on %s, %s. Git SHA Hash: %s", - MFT_VERSION_STR, - __DATE__, - __TIME__, - TOOLS_GIT_SHA); - return len; -} - -static inline -void print_version_string(const char* exe_name, const char* tool_version) { - char buf[1024]; - get_version_string(buf, sizeof(buf), exe_name, tool_version); - printf("%s\n", buf); -} - -#endif // TOOLS_VERSION_H diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 8ef242c..0000000 --- a/configure.ac +++ /dev/null @@ -1,91 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. - -AC_INIT(mstflint, 4.4.0, adrianc@mellanox.co.il) - -AC_DEFINE_UNQUOTED([PROJECT], ["mstflint"], [Define the project name.]) -AC_SUBST([PROJECT]) - -AC_DEFINE_UNQUOTED([VERSION], ["4.4.0"], [Define the project version.]) -AC_SUBST([VERSION]) - -AC_CONFIG_AUX_DIR(config) -AC_CONFIG_SRCDIR([README]) -AM_INIT_AUTOMAKE - -dnl Checks for programs -AC_PROG_CC -AC_PROG_CXX -AM_PROG_AR -AC_PROG_LIBTOOL -AC_CONFIG_HEADERS( config.h ) - -dnl Checks for headers -AC_CHECK_HEADER(termios.h,[CXXFLAGS="${CXXFLAGS} -DHAVE_TERMIOS_H"]) - -TOOLS_CRYPTO="" - -AC_MSG_CHECKING(--enable-dc argument) -AC_ARG_ENABLE(dc, - [ --disable-dc Disable mstflint "dc" command. Eliminates zlib dependency], - [enable_dc=$enableval], - [enable_dc="yes"]) -AC_MSG_RESULT($enable_dc) -if test "$enable_dc" = "yes"; then - AC_CHECK_HEADER(zlib.h,,AC_MSG_ERROR([cannot find zlib.h . Use --disable-dc to remove this dependaency])) - AC_CHECK_LIB(z, uncompress,, AC_MSG_ERROR([cannot find zlib uncompress() function. Use --disable-dc to remove this dependaency])) -fi - -AM_CONDITIONAL(ENABLE_DC, [test "x$enable_dc" = "xyes"]) -AC_SUBST(ENABLE_DC) - -AC_MSG_CHECKING(--enable-inband argument) -AC_ARG_ENABLE(inband, - [ --disable-inband Disable inabnd access. Prevents FW updtes for Mellanox SwitchX and ConnectIB devices. Eliminates infiniband/mad.h dependency], - [enable_inband=$enableval], - [enable_inband="yes"]) -AC_MSG_RESULT($enable_inband) -if test "x$enable_inband" = "xyes"; then - AC_CHECK_HEADER(infiniband/mad.h,,AC_MSG_ERROR([cannot find infiniband/mad.h . Use --disable-inband to remove this dependaency])) -fi - -AM_CONDITIONAL(ENABLE_INBAND, [test "x$enable_inband" = "xyes"]) - -AC_MSG_CHECKING(--enable-cs argument) -AC_ARG_ENABLE(cs, - [ --enable-cs Enable mstflint "checksum" command, dependant of openssl library], - [enable_cs="yes"], - [enable_cs="no"]) -AC_MSG_RESULT($enable_cs) -if test "x$enable_cs" = "xyes"; then - AC_CHECK_HEADER(openssl/md5.h,,AC_MSG_ERROR([cannot find openssl/md5.h . remove --enable-openssl to remove this dependaency or install openssl])) - TOOLS_CRYPTO="tools_crypto" -fi -AC_SUBST(TOOLS_CRYPTO) -AM_CONDITIONAL(ENABLE_OPENSSL, [test "x$enable_cs" = "xyes"]) - -AC_ARG_ENABLE([static_libstdcpp], - AS_HELP_STRING([--enable-static-libstdcpp], [Enable link static to libstdc++])) - -AS_IF([test "x$enable_static_libstdcpp" = "xyes"], [ - CXXFLAGS="$CXXFLAGS -static-libstdc++" -]) - -AC_ARG_ENABLE([dynamic_ld], - AS_HELP_STRING([--enable-dynamic-ld], [Enable dynamic link to ld64.so])) - -AS_IF([test "x$enable_dynamic_ld" = "xyes"], [ - LDFLAGS="$LDFLAGS -Wl,--dynamic-linker=/lib64/ld64.so.2" -]) - -CFLAGS="$CFLAGS -Werror -DMST_UL" -CXXFLAGS="$CXXFLAGS -Werror -DMST_UL" - -AC_CONFIG_FILES( mstflint.spec ) - -AS_IF([test "x$enable_cs" = "xyes"], [ - AC_CONFIG_FILES(tools_crypto/Makefile) - ]) - -AC_OUTPUT( Makefile common/Makefile mft_utils/Makefile mtcr_ul/Makefile dev_mgt/Makefile tools_layouts/Makefile reg_access/Makefile \ - cmdif/Makefile tools_res_mgmt/Makefile mlxconfig/Makefile mflash/Makefile mlxfwops/Makefile mlxfwops/lib/Makefile cmdparser/Makefile flint/Makefile \ - small_utils/Makefile mstdump/Makefile mstdump/crd_lib/Makefile mstdump/crd_main/Makefile mstdump/mstdump_dbs/Makefile ) diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 2223ede..0000000 --- a/debian/changelog +++ /dev/null @@ -1,96 +0,0 @@ -mstflint (4.4.0-1) unstable; urgency=low - - * Updated from MFT-4.4.0 - - -- Adrian Chiris Tue, 24 May 2016 15:31:33 +0200 - - -mstflint (4.3.0-1) unstable; urgency=low - - * Updated from MFT-4.4.0 initial release - - -- Adrian Chiris Wed, 23 Mar 2016 15:31:33 +0200 - - -mstflint (4.3.0-1) unstable; urgency=low - - * Updated from MFT-4.3.0 - - -- Adrian Chiris Mon, 11 Jan 2016 15:31:33 +0200 - - -mstflint (4.1.0-1) unstable; urgency=low - - * Updated from MFT-4.1.0 - - -- Adrian Chiris Wed, 26 Aug 2015 15:31:33 +0200 - - -mstflint (4.0.1-1) unstable; urgency=low - - * Updated from MFT-4.0.1 - - -- Adrian Chiris Wed, 03 Jun 2015 13:38:33 +0200 - - -mstflint (4.0.0-1) unstable; urgency=low - - * Updated from MFT-4.0.0 - - -- Adrian Chiris Sun, 19 Apr 2015 16:17:33 +0200 - - -mstflint (4.0.0) unstable; urgency=low - - * Updated from MFT-4.0.0 initial release - - -- Adrian Chiris Thu, 5 Feb 2015 10:20:33 +0200 - - -mstflint (3.8.0) unstable; urgency=low - - * Updated from MFT-3.8.0 - - -- Adrian Chiris Mon, 17 Nov 2014 09:00:33 +0200 - - -mstflint (3.7.1) unstable; urgency=low - - * Updated from MFT-3.7.1 - - -- Adrian Chiris Mon, 12 Oct 2014 09:00:33 +0200 - - -mstflint (3.7.0) unstable; urgency=low - - * Updated from MFT-3.7.0 - - -- Adrian Chiris Mon, 28 Jul 2014 09:00:33 +0200 - - -mstflint (3.7.0) unstable; urgency=low - - * Updated from MFT-3.7.0 initial relese - - -- Adrian Chiris Sun, 3 Jun 2014 14:08:33 +0200 - - -mstflint (3.6.0) unstable; urgency=low - - * Updated from MFT-3.6.0 - - -- Adrian Chiris Thu, 3 Apr 2014 19:09:33 +0200 - - -mstflint (3.5.0) unstable; urgency=low - - * Updated from MFT-3.5.0 - - -- Omer Dagan Tue, 25 Dec 2013 16:49:33 +0200 - - -mstflint (3.0) unstable; urgency=low - - * Initial Debian release - - -- Omer Dagan Sun, 24 Jan 2013 16:49:33 +0200 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 45a4fb7..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -8 diff --git a/debian/control b/debian/control deleted file mode 100644 index 65bf6c3..0000000 --- a/debian/control +++ /dev/null @@ -1,16 +0,0 @@ -Source: mstflint -Section: net -Priority: extra -Maintainer: Gal Sivan -Build-Depends: debhelper (>= 8.0.0), autotools-dev -Standards-Version: 3.9.2 -Homepage: http://www.mellanox.com -#Vcs-Git: git://git.debian.org/collab-maint/mstflint.git -#Vcs-Browser: http://git.debian.org/?p=collab-maint/mstflint.git;a=summary - -Package: mstflint -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Mellanox firmware burning application - This package contains firmware update tool, vpd dump and register dump tools - for network adapters based on Mellanox Technologies chips. diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 0753136..0000000 --- a/debian/copyright +++ /dev/null @@ -1,36 +0,0 @@ -Format: http://dep.debian.net/deps/dep5 -Upstream-Name: mstflint -Source: - -Files: * -Copyright: - -License: - - - . - - -# If you want to use GPL v2 or later for the /debian/* files use -# the following clauses, or change it to suit. Delete these two lines -Files: debian/* -Copyright: 2012 Gal Sivan -License: GPL-2+ - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - . - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see - . - On Debian systems, the complete text of the GNU General - Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". - -# Please also look if there are files or directories which have a -# different copyright/license attached and list them here. diff --git a/debian/docs b/debian/docs deleted file mode 100644 index 52530c5..0000000 --- a/debian/docs +++ /dev/null @@ -1,2 +0,0 @@ -hca_self_test.readme -README diff --git a/debian/files b/debian/files deleted file mode 100644 index 1ab53c7..0000000 --- a/debian/files +++ /dev/null @@ -1 +0,0 @@ -mstflint_1.4mlnx4-1_amd64.deb net extra diff --git a/debian/mstflint.docs b/debian/mstflint.docs deleted file mode 100644 index e845566..0000000 --- a/debian/mstflint.docs +++ /dev/null @@ -1 +0,0 @@ -README diff --git a/debian/mstflint.substvars b/debian/mstflint.substvars deleted file mode 100644 index eaeca62..0000000 --- a/debian/mstflint.substvars +++ /dev/null @@ -1,2 +0,0 @@ -shlibs:Depends=libc6 (>= 2.14), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1), zlib1g (>= 1:1.1.4) -misc:Depends= diff --git a/debian/rules b/debian/rules deleted file mode 100755 index a578276..0000000 --- a/debian/rules +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. -# -# Modified to make a template file for a multi-binary package with separated -# build-arch and build-indep targets by Bill Allombert 2001 - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -# This has to be exported to make some magic below work. -export DH_OPTIONS -DEB_CONFIGURE_EXTRA_FLAGS ?= "" - - -%: - dh $@ - -override_dh_auto_configure: - dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS) diff --git a/debian/source/format b/debian/source/format deleted file mode 100644 index 163aaf8..0000000 --- a/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (quilt) diff --git a/dev_mgt/Makefile.am b/dev_mgt/Makefile.am deleted file mode 100644 index 147f7aa..0000000 --- a/dev_mgt/Makefile.am +++ /dev/null @@ -1,46 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in - -AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_srcdir)/common -I$(top_srcdir)/include/mtcr_ul - -AM_CFLAGS = -W -Wall -g -MP -MD -Wswitch-enum $(COMPILER_FPIC) -DMTCR_EXPORT -noinst_LIBRARIES = libdev_mgt.a - -libdev_mgt_a_SOURCES = \ - tools_dev_types.c \ - tools_dev_types.h \ - $(top_srcdir)/common/bit_slice.h \ - $(top_srcdir)/common/compatibility.h \ - $(top_srcdir)/common/tools_version.h - diff --git a/dev_mgt/tools_dev_types.c b/dev_mgt/tools_dev_types.c deleted file mode 100644 index eca37f9..0000000 --- a/dev_mgt/tools_dev_types.c +++ /dev/null @@ -1,539 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#include -#include -#include -#include -#include -#include "tools_dev_types.h" - -enum dm_dev_type { - DM_UNKNOWN = -1, - DM_HCA, - DM_SWITCH, - DM_BRIDGE, - DM_QSFP_CABLE, - DM_SFP_CABLE, -}; - -struct dev_info { - dm_dev_id_t dm_id; - u_int16_t hw_dev_id; - int hw_rev_id; /* -1 means all revisions match this record */ - int sw_dev_id; /* -1 means all hw ids match this record */ - const char* name; - int port_num; - enum dm_dev_type dev_type; -}; - -#define DEVID_ADDR 0xf0014 -#define CABLEID_ADDR 0x0 -#define SFP_51_ADDR 92 -#define SFP_51_PAGING_ADDR 64 - -#ifdef CABLES_SUPP -enum dm_dev_type getCableType(u_int8_t id) { - switch (id) { - case 0xd: - case 0x11: - case 0xe: - case 0xc: - return DM_QSFP_CABLE; - case 0x3: - return DM_SFP_CABLE; - default: - return DM_UNKNOWN; - } -} -#endif - -static struct dev_info g_devs_info[] = { - { - .dm_id = DeviceInfiniScaleIV, - .hw_dev_id = 0x01b3, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "InfiniScaleIV", - .port_num = 36, - .dev_type = DM_SWITCH - }, - { - .dm_id = DeviceSwitchX, - .hw_dev_id = 0x0245, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "SwitchX", - .port_num = 64, - .dev_type = DM_SWITCH - }, - { - .dm_id = DeviceConnectX2, - .hw_dev_id = 0x190, - .hw_rev_id = 0xb0, - .sw_dev_id = -1, - .name = "ConnectX2", - .port_num = 2, - .dev_type = DM_HCA - }, - - { - .dm_id = DeviceConnectX3, - .hw_dev_id = 0x1f5, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "ConnectX3", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceConnectIB, - .hw_dev_id = 0x1ff, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "ConnectIB", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceConnectX3Pro, - .hw_dev_id = 0x1f7, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "ConnectX3Pro", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceSwitchIB, - .hw_dev_id = 0x247, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "SwitchIB", - .port_num = 36, - .dev_type = DM_SWITCH - }, - { - .dm_id = DeviceSpectrum, - .hw_dev_id = 0x249, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "Spectrum", - .port_num = 64, - .dev_type = DM_SWITCH - }, - { - .dm_id = DeviceConnectX4, - .hw_dev_id = 0x209, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "ConnectX4", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceConnectX4LX, - .hw_dev_id = 0x20b, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "ConnectX4LX", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceConnectX5, - .hw_dev_id = 0x20d, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "ConnectX5", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceFPGA, - .hw_dev_id = 0x600, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "FPGA", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceFPGANewton, - .hw_dev_id = 0xfff, // Dummy device ID till we have official one - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "FPGA_NEWTON", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceSwitchIB2, - .hw_dev_id = 0x24b, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "SwitchIB2", - .port_num = 36, - .dev_type = DM_SWITCH - }, - { - .dm_id = DeviceCable, - .hw_dev_id = 0xffff, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "Cable", - .port_num = -1, - .dev_type = DM_QSFP_CABLE - }, - { - .dm_id = DeviceCableQSFP, - .hw_dev_id = 0xffff, - .hw_rev_id = 0, - .sw_dev_id = -1, - .name = "CableQSFP", - .port_num = -1, - .dev_type = DM_QSFP_CABLE - }, - { - .dm_id = DeviceCableQSFPaging, - .hw_dev_id = 0xffff, - .hw_rev_id = 1, - .sw_dev_id = -1, - .name = "CableQSFPaging", - .port_num = -1, - .dev_type = DM_QSFP_CABLE - }, - { - .dm_id = DeviceCableSFP, - .hw_dev_id = 0xffff, - .hw_rev_id = 1, - .sw_dev_id = -1, - .name = "CableSFP", - .port_num = -1, - .dev_type = DM_SFP_CABLE - }, - { - .dm_id = DeviceCableSFP51, - .hw_dev_id = 0xffff, - .hw_rev_id = 1, - .sw_dev_id = -1, - .name = "CableSFP51", - .port_num = -1, - .dev_type = DM_SFP_CABLE - }, - { - .dm_id = DeviceCableSFP51Paging, - .hw_dev_id = 0xffff, - .hw_rev_id = 1, - .sw_dev_id = -1, - .name = "CableSFP51Paging", - .port_num = -1, - .dev_type = DM_SFP_CABLE - }, - { - .dm_id = DeviceDummy, - .hw_dev_id = 0x1, - .hw_rev_id = -1, - .sw_dev_id = -1, - .name = "DummyDevice", - .port_num = 2, - .dev_type = DM_HCA - }, - { - .dm_id = DeviceUnknown, - .hw_dev_id = 0, - .hw_rev_id = 0, - .sw_dev_id = 0, - .name = "Unknown Device", - .port_num = -1, - .dev_type = DM_UNKNOWN - } -}; - -static const struct dev_info* get_entry(dm_dev_id_t type) -{ - const struct dev_info* p = g_devs_info; - while (p->dm_id != DeviceUnknown) { - if (type == p->dm_id) { - break; - } - p++; - } - return p; -} - -static const struct dev_info* get_entry_by_dev_rev_id(u_int32_t hw_dev_id, u_int32_t hw_rev_id) -{ - const struct dev_info* p = g_devs_info; - while (p->dm_id != DeviceUnknown) { - if (hw_dev_id == p->hw_dev_id) { - if ((p->hw_rev_id == -1) || ((int)hw_rev_id == p->hw_rev_id)) { - break; - } - } - p++; - } - return p; -} - -/** - * Returns 0 on success and 1 on failure. - */ -int dm_get_device_id(mfile* mf, - dm_dev_id_t* ptr_dm_dev_id, - u_int32_t* ptr_hw_dev_id, - u_int32_t* ptr_hw_rev) -{ - u_int32_t dword; - int rc; - u_int32_t dev_flags; - - //Special case: FPGA device: -#ifndef MST_UL - if (mf->tp == MST_FPGA) { - *ptr_dm_dev_id = DeviceFPGA; - *ptr_hw_dev_id = 0x600; - return 0; - } - if (mf->tp == MST_FPGA_NEWTON) { - *ptr_dm_dev_id = DeviceFPGANewton; - *ptr_hw_dev_id = 0xfff; - return 0; - } -#endif -#ifdef CABLES_SUPP - if (mf->tp == MST_CABLE) { - //printf("-D- Getting cable ID\n"); - if (mread4(mf, CABLEID_ADDR, &dword) != 4) - { - //printf("FATAL - crspace read (0x%x) failed: %s\n", DEVID_ADDR, strerror(errno)); - return 1; - } - dword = __cpu_to_le32(dword); // Cable pages are in LE - *ptr_hw_dev_id = 0xffff; - u_int8_t id = EXTRACT(dword, 0, 8); - enum dm_dev_type cbl_type = getCableType(id); - if (cbl_type == DM_QSFP_CABLE) { - // Get Byte 2 bit 2 ~ bit 18 - u_int8_t paging = EXTRACT(dword, 18, 1); - //printf("DWORD: %#x, paging: %d\n", dword, paging); - if (paging == 0) { - *ptr_dm_dev_id = DeviceCableQSFPaging; - } else { - *ptr_dm_dev_id = DeviceCableQSFP; - } - } else if (cbl_type == DM_SFP_CABLE) { - *ptr_dm_dev_id = DeviceCableSFP; - if (mread4(mf, SFP_51_ADDR, &dword) != 4) - { - //printf("FATAL - crspace read (0x%x) failed: %s\n", DEVID_ADDR, strerror(errno)); - return 1; - } - u_int8_t byte = EXTRACT(dword, 6, 1); //Byte 92 bit 6 - if (byte) { - *ptr_dm_dev_id = DeviceCableSFP51; - if (mread4(mf, SFP_51_PAGING_ADDR, &dword) != 4) - { - //printf("FATAL - crspace read (0x%x) failed: %s\n", DEVID_ADDR, strerror(errno)); - return 1; - } - byte = EXTRACT(dword, 4, 1); //Byte 64 bit 4 - if (byte) { - *ptr_dm_dev_id = DeviceCableSFP51Paging; - } - } - } else { - *ptr_dm_dev_id = DeviceUnknown; - } - return 0; - } -#endif - - - rc = mget_mdevs_flags(mf, &dev_flags); - if (rc) { - dev_flags = 0; - } - // get hw id - // Special case for MLNX OS getting dev_id using REG MGIR - if (dev_flags & MDEVS_MLNX_OS) { - reg_access_status_t rc; - struct register_access_sib_mgir mgir; - memset(&mgir, 0, sizeof(mgir)); - rc = reg_access_mgir(mf, REG_ACCESS_METHOD_GET, &mgir); - //printf("-D- RC[%s] -- REVID: %d -- DEVID: %d hw_dev_id: %d\n", m_err2str(rc), mgir.HWInfo.REVID, mgir.HWInfo.DEVID, mgir.HWInfo.hw_dev_id); - if (rc) { - dword = get_entry(DeviceSwitchX)->hw_dev_id; - *ptr_hw_rev = 0; - *ptr_hw_dev_id = get_entry(DeviceSwitchX)->hw_dev_id; - } else { - dword = mgir.HWInfo.hw_dev_id; - if (dword == 0) { - dword = get_entry(DeviceSwitchX)->hw_dev_id; - *ptr_hw_dev_id = get_entry(DeviceSwitchX)->hw_dev_id; - *ptr_hw_rev = mgir.HWInfo.REVID & 0xf; - } else { - *ptr_hw_dev_id = dword; - *ptr_hw_rev = 0; //WA: MGIR should have also hw_rev_id and then we can use it. - } - } - } else { - if (mread4(mf, DEVID_ADDR, &dword) != 4) - { - //printf("FATAL - crspace read (0x%x) failed: %s\n", DEVID_ADDR, strerror(errno)); - return 1; - } - - *ptr_hw_dev_id = EXTRACT(dword, 0, 16); - *ptr_hw_rev = EXTRACT(dword, 16, 8); - } - - *ptr_dm_dev_id = get_entry_by_dev_rev_id(*ptr_hw_dev_id, *ptr_hw_rev)->dm_id; - - if (*ptr_dm_dev_id == DeviceUnknown) { - - /* Dev id not matched in array */ - //printf("FATAL - Can't find devid id\n"); - return 1; // TODO - fix return vals. - } - return 0; -} - -int dm_get_device_id_offline(u_int32_t devid, - u_int32_t chip_rev, - dm_dev_id_t* ptr_dev_type) -{ - *ptr_dev_type = get_entry_by_dev_rev_id(devid, chip_rev)->dm_id; - return *ptr_dev_type == DeviceUnknown; -} - -const char* dm_dev_type2str(dm_dev_id_t type) -{ - return get_entry(type)->name; -} - -dm_dev_id_t dm_dev_str2type(const char* str) -{ - const struct dev_info* p = g_devs_info; - if (!str) { - return DeviceUnknown; - } - while (p->dm_id != DeviceUnknown) { - if (strcmp(str,p->name) == 0) { - return p->dm_id; - } - p++; - } - return DeviceUnknown; -} - -int dm_get_hw_ports_num(dm_dev_id_t type) -{ - return get_entry(type)->port_num; -} - -int dm_dev_is_hca(dm_dev_id_t type) { - return get_entry(type)->dev_type == DM_HCA; -} - -int dm_dev_is_switch(dm_dev_id_t type) -{ - return get_entry(type)->dev_type == DM_SWITCH; -} - -int dm_dev_is_bridge(dm_dev_id_t type) -{ - return get_entry(type)->dev_type == DM_BRIDGE; -} - -int dm_dev_is_cable(dm_dev_id_t type) -{ - return (get_entry(type)->dev_type == DM_QSFP_CABLE || get_entry(type)->dev_type == DM_SFP_CABLE); -} - -u_int32_t dm_get_hw_dev_id(dm_dev_id_t type) -{ - return get_entry(type)->hw_dev_id; -} - -u_int32_t dm_get_hw_rev_id(dm_dev_id_t type) -{ - return get_entry(type)->hw_rev_id; -} - -int dm_is_fpp_supported(dm_dev_id_t type) -{ - const struct dev_info* dp = get_entry(type); - if ( - dp->dm_id == DeviceConnectIB || - dp->dm_id == DeviceConnectX4 || - dp->dm_id == DeviceConnectX4LX || - dp->dm_id == DeviceConnectX5) { - return 1; - } else { - return 0; - } -} - -int dm_is_device_supported(dm_dev_id_t type) -{ - return get_entry(type)->dm_id != DeviceUnknown; -} - -int dm_is_livefish_mode(mfile* mf) -{ - if(!mf || !mf->dinfo) { - return 0; - } - dm_dev_id_t devid_t; - u_int32_t devid = 0; - u_int32_t revid = 0; - int rc = dm_get_device_id(mf, &devid_t, &devid, &revid); - if (rc) { - // Could not detrmine , by default is not livefish - return 0; - } - u_int32_t swid = mf->dinfo->pci.dev_id; - //printf("-D- swid: %#x, devid: %#x\n", swid, devid); - if (devid_t == DeviceConnectX2 || - devid_t == DeviceConnectX3 || - devid_t == DeviceConnectX3Pro || - devid_t == DeviceSwitchX ) { - return (devid == swid - 1); - } else { - return (devid == swid); - } - - return 0; -} - diff --git a/dev_mgt/tools_dev_types.h b/dev_mgt/tools_dev_types.h deleted file mode 100644 index 432dc4e..0000000 --- a/dev_mgt/tools_dev_types.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#ifndef TOOLS_DEV_TYPE_H -#define TOOLS_DEV_TYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -enum dm_dev_id -{ - DeviceUnknown = -1, //Dummy Device - Marker for indicating error. - DeviceStartMarker = 0, // Dummy Device - Marker for first device - // to let user iterate from DeviceStartMarker to DeviceEndMarker - // Note: Call dm_is_device_supported() to see if a device is supported by the lib. - - DeviceInfiniScale = 0, // UnSupported - DeviceInfiniHost, // UnSupported - DeviceInfiniHostIIIEx, // UnSupported - DeviceInfiniHostIIIEx_MF,// UnSupported - DeviceInfiniScaleIII, // UnSupported - DeviceInfiniHostIIILx, // UnSupported - DeviceConnectX, // UnSupported - DeviceConnectX2, - DeviceInfiniScaleIV, - DeviceBridgeX, // UnSupported - DeviceSwitchX, - DeviceConnectX3, - DeviceConnectIB, - DeviceConnectX3Pro, - DeviceSwitchIB, - DeviceSpectrum, - DeviceConnectX4, - DeviceConnectX4LX, - DeviceConnectX5, - DeviceFPGA, - DeviceSwitchIB2, - DeviceFPGANewton, - DeviceCable, - DeviceCableQSFP, - DeviceCableQSFPaging, - DeviceCableSFP, - DeviceCableSFP51, - DeviceCableSFP51Paging, - DeviceDummy, - - DeviceEndMarker // Dummy Device - Marker for indicating end of devices when iterating -}; - -typedef enum dm_dev_id dm_dev_id_t; - -/** - * Returns 0 on success and 1 on failure. - */ -int dm_get_device_id(mfile* mf, - dm_dev_id_t* ptr_dev_type, - u_int32_t* ptr_dev_id, - u_int32_t* ptr_chip_rev); - -/** - * Returns 0 on success and 1 on failure. - */ -int dm_get_device_id_offline(u_int32_t devid, - u_int32_t chip_rev, - dm_dev_id_t* ptr_dev_type); - - -/** - * Returns 1 if device is supported and 0 otherwise (library dependant) - */ -int dm_is_device_supported(dm_dev_id_t type); - - -/** - * Returns the device name as a "const char*" - */ -const char* dm_dev_type2str(dm_dev_id_t type); - -/** - * Returns the device id - */ -dm_dev_id_t dm_dev_str2type(const char* str); - -/** - * A predicate returning if the device is an hca - */ -int dm_dev_is_hca(dm_dev_id_t type); - -/** - * A predicate returning if the device is a switch - */ -int dm_dev_is_switch(dm_dev_id_t type); - -/** - * A predicate returning if the device is a bridge - */ -int dm_dev_is_bridge(dm_dev_id_t type); - -/** - * A predicate returning if the device is a Cable - */ -int dm_dev_is_cable(dm_dev_id_t type); - -/** - * Returns the max num of ports or -1 on error - */ -int dm_get_hw_ports_num(dm_dev_id_t type); - -/** - * Returns the HW device id of the givn device type or zero on failure. - */ -u_int32_t dm_get_hw_dev_id(dm_dev_id_t type); - -/** - * Returns the HW chip revision of the given device type or zero on failures, - * This is useful to distinguish between ConnectX2 and ConnectX. - */ -u_int32_t dm_get_hw_rev_id(dm_dev_id_t type); - -/** - * A predicate returning if the device supports Function Per Port - */ -int dm_is_fpp_supported(dm_dev_id_t type); - -/* - * A predicate returning if the device is in LiveFish mode - */ -int dm_is_livefish_mode(mfile* mf); - -#ifdef __cplusplus -} /* end of 'extern "C"' */ -#endif - -#endif // TOOLS_DEV_TYPE_H diff --git a/flint/Makefile.am b/flint/Makefile.am deleted file mode 100755 index d2cb8c5..0000000 --- a/flint/Makefile.am +++ /dev/null @@ -1,78 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or othint2_oem.er materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in -MTCR_DIR = $(top_srcdir)/mtcr_ul -MTCR_INC_DIR = $(top_srcdir)/include/mtcr_ul -MFLASH_DIR = $(top_srcdir)/mflash -COMMON_DIR = $(top_srcdir)/common -LAYOUTS_DIR = $(top_srcdir)/tools_layouts -MFT_UTILS_DIR = $(top_srcdir)/mft_utils -CMDIF_DIR = $(top_srcdir)/cmdif - -AM_CPPFLAGS = -I$(top_srcdir) -I$(srcdir) -I$(MTCR_DIR) -I$(MFLASH_DIR) -I$(COMMON_DIR) \ - -I$(LAYOUTS_DIR) -I$(MFT_UTILS_DIR) -I$(MTCR_INC_DIR) - -mstflint_CXXFLAGS = -Wall -W -g -MP -MD -pipe -DEXTERNAL -bin_PROGRAMS = mstflint - -mstflint_SOURCES = flint.cpp flint.h subcommands.cpp subcommands.h\ - flint_params.cpp flint_params.h cmd_line_parser.cpp err_msgs.h - -mstflint_LDADD = ../mlxfwops/lib/libmlxfwops.a \ - ../cmdparser/libcmdparser.a \ - ../mflash/libmflash.a \ - ../tools_res_mgmt/libtools_res_mgmt.a \ - $(CMDIF_DIR)/libcmdif.a \ - ../reg_access/libreg_access.a \ - ../dev_mgt/libdev_mgt.a \ - ../mtcr_ul/libmtcr_ul.a \ - ../tools_layouts/libtools_layouts.a \ - ../mft_utils/libmftutils.a\ - $(LIBSTD_CPP) -ldl - - -if ENABLE_DC -mstflint_LDADD += -lz -else -mstflint_CXXFLAGS += -DNO_ZLIB -endif - -if ENABLE_OPENSSL -mstflint_LDADD += $(top_srcdir)/tools_crypto/libtools_crypto.a -lcrypto -else -endif - -#get mst device examples and tool name from makefile -mstflint_CXXFLAGS+= -DFLINT_NAME=\"mstflint\" -DFLINT_DISPLAY_NAME=\"MstFlint\" -mstflint_CXXFLAGS += -DMST_DEV_EXAMPLE1=\"03:00.0\" -DMST_DEV_EXAMPLE2=\"mlx4_0\" -DMST_DEV_EXAMPLE3=\"03:00.0\" -DMST_DEV_EXAMPLE4=\"04:00.0\" - diff --git a/flint/cmd_line_parser.cpp b/flint/cmd_line_parser.cpp deleted file mode 100644 index 7167b4c..0000000 --- a/flint/cmd_line_parser.cpp +++ /dev/null @@ -1,925 +0,0 @@ -/* - * - * cmd_line_parser.cpp - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#include -#include -#include -// Flint includes -#include "flint.h" -#include -#include "mlxfwops/lib/flint_io.h" - -#ifndef FLINT_NAME - #ifdef __GNUC__ - #define FLINT_NAME "flint" - #else - #define FLINT_NAME "flint" - #endif -#endif - -using namespace std; - -/****************************** - * Data structures containing - * Meta data about subcommands - * and flags - ******************************/ -class SubCmdMetaData { -private: - class SubCmd { - public: - SubCmd(string s, string l, sub_cmd_t n): shortf(s), longf(l), cmdNum(n) {} - ~SubCmd(){} - string shortf; - string longf; - sub_cmd_t cmdNum; - }; - vector _sCmds; -public: - SubCmdMetaData(); - ~SubCmdMetaData(); - sub_cmd_t getCmdNum(string flag); -}; - -SubCmdMetaData::SubCmdMetaData() { - _sCmds.push_back(new SubCmd("b", "burn", SC_Burn)); - _sCmds.push_back(new SubCmd("q", "query", SC_Query)); - _sCmds.push_back(new SubCmd("v", "verify", SC_Verify)); - _sCmds.push_back(new SubCmd("", "swreset", SC_Swreset)); - _sCmds.push_back(new SubCmd("", "reset_cfg", SC_ResetCfg)); - _sCmds.push_back(new SubCmd("", "brom", SC_Brom)); - _sCmds.push_back(new SubCmd("", "drom", SC_Drom)); - _sCmds.push_back(new SubCmd("", "rrom", SC_Rrom)); - _sCmds.push_back(new SubCmd("", "qrom", SC_Qrom)); - _sCmds.push_back(new SubCmd("", "bb", SC_Bb)); - _sCmds.push_back(new SubCmd("", "sg", SC_Sg)); -#ifndef EXTERNAL - _sCmds.push_back(new SubCmd("", "smg", SC_Smg)); - _sCmds.push_back(new SubCmd("", "set_vpd", SC_Set_Vpd)); -#endif - _sCmds.push_back(new SubCmd("", "sv", SC_Sv)); - _sCmds.push_back(new SubCmd("", "ri", SC_Ri)); - _sCmds.push_back(new SubCmd("", "dc", SC_Dc)); - _sCmds.push_back(new SubCmd("", "dh", SC_Dh)); - _sCmds.push_back(new SubCmd("", "set_key", SC_Set_Key)); - _sCmds.push_back(new SubCmd("", "hw_access", SC_Hw_Access)); - _sCmds.push_back(new SubCmd("", "hw", SC_Hw)); - _sCmds.push_back(new SubCmd("e", "erase", SC_Erase)); - _sCmds.push_back(new SubCmd("", "rw", SC_Rw)); - _sCmds.push_back(new SubCmd("", "ww", SC_Ww)); - _sCmds.push_back(new SubCmd("", "wwne", SC_Wwne)); - _sCmds.push_back(new SubCmd("", "wbne", SC_Wbne)); - _sCmds.push_back(new SubCmd("", "wb", SC_Wb)); - _sCmds.push_back(new SubCmd("", "rb", SC_Rb)); - _sCmds.push_back(new SubCmd("", "clear_semaphore", SC_Clear_Sem)); - _sCmds.push_back(new SubCmd("", "fi", SC_Fix_Img)); - _sCmds.push_back(new SubCmd("cs", "checksum", SC_Check_Sum)); - _sCmds.push_back(new SubCmd("ts", "timestamp", SC_Time_Stamp)); - _sCmds.push_back(new SubCmd("ci", "cache_image", SC_Cache_Image)); -} - -SubCmdMetaData::~SubCmdMetaData() { - for (vector::iterator it= _sCmds.begin(); it != _sCmds.end(); ++it ) - { - delete *it; - } -} - -sub_cmd_t SubCmdMetaData::getCmdNum(string flag) -{ - for (vector::iterator it= _sCmds.begin(); it != _sCmds.end(); ++it ) - { - if (((*it)->shortf == flag) || ((*it)->longf == flag)) { - return (*it)->cmdNum; - } - } - return SC_No_Cmd; -} - - -class FlagMetaData { -private: - class Flag { - public: - Flag(string s, string l, int n): shortf(s), longf(l), argNum(n) {} - ~Flag(){} - string shortf; - string longf; - int argNum; - }; - vector _flags; -public: - FlagMetaData(); - ~FlagMetaData(); - int getNumOfArgs(string flag); -}; - -FlagMetaData::FlagMetaData() { - _flags.push_back(new Flag("d", "device", 1)); - _flags.push_back(new Flag("", "guid", 1)); - _flags.push_back(new Flag("", "guids", GUIDS)); - _flags.push_back(new Flag("", "mac", 1)); - _flags.push_back(new Flag("", "macs", MACS)); - _flags.push_back(new Flag("", "uid", 1)); - _flags.push_back(new Flag("", "blank_guids", 0)); - _flags.push_back(new Flag("", "clear_semaphore", 0)); - _flags.push_back(new Flag("h", "help", 0)); - _flags.push_back(new Flag("", "hh", 0)); - _flags.push_back(new Flag("i", "image", 1)); - _flags.push_back(new Flag("", "qq", 0)); - _flags.push_back(new Flag("", "nofs", 0)); - _flags.push_back(new Flag("", "allow_psid_change", 0)); - _flags.push_back(new Flag("", "allow_rom_change", 0)); - _flags.push_back(new Flag("", "override_cache_replacement", 0)); - _flags.push_back(new Flag("", "ocr", 0)); - _flags.push_back(new Flag("", "no_flash_verify", 0)); - _flags.push_back(new Flag("s", "silent", 0)); - _flags.push_back(new Flag("y", "yes", 0)); - _flags.push_back(new Flag("", "no", 0)); - _flags.push_back(new Flag("", "vsd", 1)); - _flags.push_back(new Flag("", "use_image_ps", 0)); - _flags.push_back(new Flag("", "use_image_guids", 0)); - _flags.push_back(new Flag("", "use_image_rom", 0)); - _flags.push_back(new Flag("", "ignore_dev_data", 0)); - _flags.push_back(new Flag("", "dual_image", 0)); - _flags.push_back(new Flag("", "striped_image", 0)); - _flags.push_back(new Flag("", "banks", 1)); - _flags.push_back(new Flag("", "log", 1)); - _flags.push_back(new Flag("", "flash_params", 1)); //its actually 3 but separated by comma so we refer to them as one - _flags.push_back(new Flag("v", "version", 0)); - _flags.push_back(new Flag("", "no_devid_check", 0)); - _flags.push_back(new Flag("", "use_fw", 0)); - _flags.push_back(new Flag("", "use_dev_img_info", 0)); -} - -FlagMetaData::~FlagMetaData() { - for (vector::iterator it= _flags.begin(); it != _flags.end(); ++it ) - { - delete *it; - } -} - -int FlagMetaData::getNumOfArgs(string flag) -{ - for (vector::iterator it= _flags.begin(); it != _flags.end(); ++it ) - { - if (((*it)->shortf == flag) || ((*it)->longf == flag)) { - return (*it)->argNum; - } - } - return -1; -} - -/******************** - * Helper Functions: - *******************/ - -// NOTE : number of parameters extracted in the container should be checked. -static void splitByDelimiters(std::vector& container, string str, const char* delimiters ) -{ - if (str.size() == 0 ) { - return; - } - char* cStr = strcpy(new char[str.size()+1], str.c_str()); - char* ptr; - ptr = strtok(cStr, delimiters); - - while (ptr != NULL) { - container.push_back(ptr); - ptr = strtok(NULL, delimiters); - } - delete[] cStr; - return; -} - -char* stripFlag(char* flag) { - char* strippedFlagStart = NULL; - if (flag[0] != '-') { // not a flag - return flag; - }; - if ((flag[0] == '-') && (flag[1] == '-')) - strippedFlagStart = &flag[2]; - else { - strippedFlagStart = &flag[1]; - } - return strippedFlagStart; -} - -int countArgs(string args) { - if (args.size() == 0) - return 0; - int count = 1; - for (string::iterator it = args.begin(); it < args.end(); ++it) { - if (*it == ',') - count++; - } - return count; -} - -bool verifyNumOfArgs(string name, string value) { - //HACK : we don't check device numOfArgs because image device format might contain "," - if ((name == "device") || (name == "d") ) { - return true; - } - if ((name == "image") || (name == "i") ) { - return true; - } - // Hack : VSD can be empty or contain "," so we shouldnt count its args - if (name == "vsd") { - return true; - } - - int expected = FlagMetaData().getNumOfArgs(name); - if (expected < 0) { - printf(FLINT_INVALID_FLAG_ERROR, name.c_str()); - return false; - } - //HACK : flash_params is 3 argument but given with comma separated instead of spaces like the rest - // so flag_arg_num gives a wrong value - - if (name == "flash_params") - expected = 3; - int actual = countArgs(value); - if (actual < expected) { - printf(FLINT_TOO_FEW_ARGS_ERROR,expected, actual); - return false; - } else if (actual > expected) { - printf(FLINT_TOO_MANY_ARGS_ERROR, expected, actual); - return false; - } - return true; -} - -bool strToNum(string str, u_int64_t& num, int base=0) -{ - char *endp; - char* numStr = strcpy(new char[str.size() + 1],str.c_str()); - num = strtoul(numStr, &endp, base); - if (*endp) { - delete[] numStr; - return false; - } - delete[] numStr; - return true; -} - -//this function is used in extracting both guids and macs from user -bool getGUIDFromStr(string str, guid_t& guid, string prefixErr="") -{ - char* endp; - u_int64_t g; - g = strtoull(str.c_str(), &endp, 16); - if (*endp || (g == 0xffffffffffffffffULL && errno == ERANGE)) { - if (prefixErr.size() == 0) { - printf("-E- Invalid Guid/Mac/Uid syntax (%s) %s \n", str.c_str(), errno ? strerror(errno) : "" ); - } else { - printf("%s\n", prefixErr.c_str()); - } - return false; - } - guid.h = (u_int32_t)(g >> 32); - guid.l = (u_int32_t)(g & 0xffffffff); - return true; -} - -guid_t incrGuid(guid_t baseGuid, unsigned int incrVal) -{ - u_int64_t g = baseGuid.h; - g = (g << 32) | baseGuid.l; - g += incrVal; - guid_t userGuid; - userGuid.h = (u_int32_t)(g >> 32); - userGuid.l = (u_int32_t)g; - return userGuid; -} - -guid_t GetBaseMac(guid_t baseGuid) -{ - guid_t baseMac; - baseMac.l = (baseGuid.l & 0x00ffffff) | ((baseGuid.h & 0xff00) << 16); - baseMac.h = baseGuid.h >> 16; - return baseMac; -} - -bool parseFlashParams(string params, flash_params_t& fp) -{ - // Step 1 split by "," - std::vector paramVec; - splitByDelimiters(paramVec, params, ","); - if (paramVec.size() != 3) { - return false; - } - // Step 2 extract params - fp.type_name = strcpy(new char[paramVec[0].length()+1], paramVec[0].c_str()); - if (!fp.type_name) { - return false; - } - u_int64_t tmp; - if (!strToNum(paramVec[1], tmp)) { - delete[] fp.type_name; - return false; - } - fp.log2size = (int)tmp; - if (!strToNum(paramVec[2], tmp)) { - delete[] fp.type_name; - return false; - } - fp.num_of_flashes = (int)tmp; - return true; -} - -/************************************ - *Implementation of the Command line - *Parsing part of the Flint class - ************************************/ - -#define FLASH_LIST_SZ 256 - -void Flint::initCmdParser() { - AddDescription("flint is a FW (firmware) burning and flash memory operations tool for\n" - "Mellanox Infiniband HCAs, Ethernet NIC cards, and switch devices."); - - AddOptions("device", - 'd', - "", - "Device flash is connected to.\n" - "Commands affected: all"); - - AddOptions("image", - 'i', - "", - "Binary image file.\n" - "Commands affected: burn, verify"); - - AddOptions("help", - 'h', - "", - "Prints this message and exits"); - - AddOptions("hh", - ' ', - "", - "Prints extended command help"); - - AddOptions("yes", - 'y', - "", - "Non interactive mode - assume answer\n" - "\"yes\" to all questions.\n" - "Commands affected: all"); - - AddOptions("no", - ' ', - "", - "Non interactive mode - assume answer\n" - "\"no\" to all questions.\n" - "Commands affected: all"); - - AddOptions("guid", - ' ', - "", - "GUID base value. 4 GUIDs\n" - "are automatically assigned to the following values:\n\n" - "guid -> node GUID\n" - "guid+1 -> port1\n" - "guid+2 -> port2\n" - "guid+3 -> system image GUID.\n\n" - "Note: port2 guid will be assigned even for a\n" - "single port HCA - The HCA ignores this value.\n\n" - "Commands affected: burn, sg"); - - AddOptions("guids", - ' ', - "", - "4 GUIDs must be specified here.\n" - "The specified GUIDs are assigned\n" - "to the following fields, respectively:\n" - "node, port1, port2 and system image GUID.\n\n" - "Note: port2 guid must be specified even for a\n" - "single port HCA - The HCA ignores this value.\n" - "It can be set to 0x0.\n\n" - "Commands affected: burn, sg"); - - AddOptions("mac", - ' ', - "", - "MAC address base value. 2 MACs\n" - "are automatically assigned to the\n" - "following values:\n\n" - "mac -> port1\n" - "mac+1 -> port2\n\n" - "Commands affected: burn, sg"); - - AddOptions("macs", - ' ', - "", - "2 MACs must be specified here.\n" - "The specified MACs are assigned\n" - "to port1, port2, respectively.\n" - "Commands affected: burn, sg\n\n" - "Note: -mac/-macs flags are applicable only for Mellanox\n" - "\tTechnologies ethernet products."); - - AddOptions("uid", - ' ', - "", - "ConnectIB/SwitchIB only. Derive and set the device UIDs (GUIDs, MACs, WWNs).\n" - "UIDs are derived from the given base UID according to Mellanox Methodology\n" - "Commands affected: burn, sg"); - - AddOptions("blank_guids", - ' ', - "", - "Burn the image with blank GUIDs and MACs (where\n" - "applicable). These values can be set later using\n" - "the \"sg\" command (see details below).\n\n" - "Commands affected: burn"); - - AddOptions("clear_semaphore", - ' ', - "", - "Force clear the flash semaphore on the device.\n" - "No command is allowed when this flag is used.\n" - "NOTE: May result in system instability or flash\n" - "\tcorruption if the device or another\n" - "\tapplication is currently using the flash.\n" - "\tExercise caution.\n"); - - AddOptions("qq", - ' ', - "", - "Run a quick query. When specified, flint will not perform full\n" - "image integrity checks during the query operation. This may shorten\n" - "execution time when running over slow interfaces (e.g., I2C, MTUSB-1).\n" - "Commands affected: burn, query"); - - AddOptions("nofs", - ' ', - "", - "Burn image in a non failsafe manner."); - - AddOptions("allow_psid_change", - ' ', - "", - "Allow burning a FW image with a different PSID (Parameter Set ID)than the\n" - "one currently on flash. Note that changing a PSID may cause the device to\n" - "malfunction. Use only if you know what you are doing"); - - AddOptions("allow_rom_change", - ' ', - "", - "Allow burning/removing a ROM to/from FW image when product version is present.\n" - "Use only if you know what you are doing"); - - AddOptions("override_cache_replacement", - ' ', - "", - "On SwitchX/ConnectIB devices:\n" - "Allow accessing the flash even if the cache replacement mode is enabled.\n" - "NOTE: This flag is intended for advanced users only.\n" - "\tRunning in this mode may cause the firmware to hang.\n"); - - AddOptions("no_flash_verify", - ' ', - "", - "Do not verify each write on the flash."); - - AddOptions("use_fw", - ' ', - "", - "Flash access will be done using FW (ConnectX-3/ConnectX-3Pro only)."); - - AddOptions("silent", - 's', - "", - "Do not print burn progress flyer.\n" - "Commands affected: burn"); - - AddOptions("vsd", - ' ', - "", - "Write this string, of up to 208 characters, to VSD when burn."); - - AddOptions("use_image_ps", - ' ', - "", - "Burn vsd as appears in the given image - do not keep existing VSD on flash.\n" - "Commands affected: burn"); - - AddOptions("use_image_guids", - ' ', - "", - "Burn (guids/macs) as appears in the given image.\n" - "Commands affected: burn"); - - AddOptions("use_image_rom", - ' ', - "", - "Do not save the ROM which exists in the device.\n" - "Commands affected: burn"); - - AddOptions("ignore_dev_data", - ' ', - "", - "Do not attempt to take device data sections from device(sections will be taken from the image. FS3 Only).\n" - "Commands affected: burn"); - - AddOptions("use_dev_img_info", - ' ', - "", - "preserve select image info fields from the device upon FW update (FS3 Only).\n" - "Commands affected: burn", - true); - - AddOptions("dual_image", - ' ', - "", - "Make the burn process burn two images on flash (previously default algorithm). Current" - "default failsafe burn process burns a single image (in alternating locations).\n" - "Commands affected: burn"); - - AddOptions("striped_image", - ' ', - "", - "Use this flag to indicate that the given image file is in a \"striped image\" format.\n" - "Commands affected: query verify"); - - AddOptions("banks", - ' ', - "", - "Set the number of attached flash devices (banks)"); - - AddOptions("log", - ' ', - "", - "Print the burning status to the specified log file"); - - char flashList[FLASH_LIST_SZ]; - char flashParDesc[FLASH_LIST_SZ*2]; - Flash::get_flash_list(flashList); - snprintf(flashParDesc, FLASH_LIST_SZ*2,"Use the given parameters to access the flash instead of reading them from the flash.\n"\ - "Supported parameters:\n"\ - "Type: The type of the flash, such as:%s.\n"\ - "log2size: The log2 of the flash size."\ - "num_of_flashes: the number of the flashes connected to the device.", flashList); - - - AddOptions("flash_params", - ' ', - "", flashParDesc); - - AddOptions("version", - 'v', - "", - "Version info."); - - AddOptions("no_devid_check", - ' ', - "", - "ignore device_id checks", true); - - AddOptions("ocr", - ' ', - "", - "another flag for override cache replacement", true); - - - _cmdParser.AddRequester(this); -} - -ParseStatus Flint::HandleOption(string name, string value) -{ - //TODO: consider verifying num of args inside each if statements that needs its arg num verified - // thus we will be able to get rid of the hacks inside the function in the expense of a longer code. - if (!(verifyNumOfArgs(name, value))) - return PARSE_ERROR; - - if (name == "device" || name == "d" ) - { - _flintParams.device_specified = true; - _flintParams.device = value; - } - else if (name == "help" || name == "h") - { - cout<< _cmdParser.GetUsage()<first == SC_ResetCfg) { - // hidden command so "forget" mentioning it - continue; - } - string str1 = " "+it->second->getFlagL()+((it->second->getFlagS() == "") ? (" ") : ("|"))+it->second->getFlagS()\ - +" "+it->second->getParam(); - string str2 = ": " + it->second->getDesc()+"\n"; - printf("%-44s %s", str1.c_str(), str2.c_str()); - } - cout<second->getFlagL()+((it->second->getFlagS() == "") ? (" ") : ("|"))+it->second->getFlagS()\ - +" "+it->second->getParam(); - string str2 = ": " + it->second->getDesc()+"\n"; - printf("%-40s %s", str1.c_str(), str2.c_str()); - } - cout<first == SC_ResetCfg) { - // hidden command so "forget" mentioning it - continue; - } - cout<<" Name:"<second->getName()<second->getExtDesc()<second->getFlagL()<<\ - ((it->second->getFlagS() == "") ? (" ") : ("|"))+it->second->getFlagS()\ - <<" "<second->getParam()<second->getParamExp()<second->getExample()<::iterator it=_flintParams.user_guids.begin();it != _flintParams.user_guids.end(); it++){ - // printf("%8.8x%8.8x\n",it->h,it->l); - // } - } else if (name == "guids") { - _flintParams.guids_specified = true; - std::vector strs; - splitByDelimiters(strs, value,","); - if (strs.size() != GUIDS) { - return PARSE_ERROR; - } - for (int i=0; i strs; - splitByDelimiters(strs, value,","); - if (strs.size() != MACS) { - return PARSE_ERROR; - } - for (int i=0; i= '0') && ((cha) <= '9')) - -ParseStatus Flint::parseCmdLine(int argc, char* argv[]) { - //Step1 separate between option section and cmd section - SubCmdMetaData subCmds; - FlagMetaData flags; - char **argvCmd = NULL; - char **argvOpt = NULL; - int argcCmd = 0, argcOpt = 0; - for (int i = (argc - 1); i > 0; i--) { - if ((subCmds.getCmdNum(argv[i])) != SC_No_Cmd) { // i.e we found a subcommand - argcOpt = i; - argvOpt = argv; - argcCmd = argc - i; - argvCmd = &argv[i]; - } - } - if (argcCmd == 0) { - //no subcommand found - argcOpt = argc; - argvOpt = argv; - } - //printf("-D- argcOpt:%d argvOpt:%s argcCmd:%d argvCmd:%s\n", argcOpt, argvOpt[0], argcCmd, argvCmd[0]); - //_cmdparser should deal with the case of no arguments in argv except the program. - //Step2 unite with comma multiple args in the options section - char* newArgv[argcOpt]; - int newArgc = 0; - int i = 1, j = 1, argStart = 1, argEnd = 1; - //first arg is the flint command we can copy as is - newArgv[0] = strcpy(new char[strlen(argvOpt[0]) + 1], argvOpt[0]); - while (i < argcOpt) { - if (argvOpt[i][0] == '-' && !IS_NUM(argvOpt[i][1])) //its a flag (and not a number) so we copy to new_argv as is - { - newArgv[j] = strcpy(new char[strlen(argvOpt[i]) + 1], - argvOpt[i]); - i++; - j++; - } else //its an argument - { - //find next flag if exsists - argStart = i; - argEnd = i; - int argsSize = 0; - while (argEnd < argcOpt && (argvOpt[argEnd][0] != '-' || IS_NUM(argvOpt[argEnd][1]))) { - argsSize += strlen(argvOpt[argEnd]) + 1; //for the comma - argEnd++; - } - i = argEnd; - //concatenate all the args with comma between them to a single string - newArgv[j] = new char[argsSize + 1]; - newArgv[j][0] = '\0'; - while (argStart < argEnd) { - if (argStart == argEnd - 1) { - //no need to add comma to the last arg - strcat(newArgv[j], argvOpt[argStart]); - } else { - strcat(newArgv[j], argvOpt[argStart]); - strcat(newArgv[j], ","); - } - argStart++; - } - j++; - } - } - newArgc = j; - - //Step3 set the command and its args in the FlintParams struct if present - ParseStatus rc; - if (argcCmd > 0) { - this->_flintParams.cmd = subCmds.getCmdNum(argvCmd[0]); - for (int i = 1; i < argcCmd; ++i) { - this->_flintParams.cmd_params.push_back(string(argvCmd[i])); - } - } else //no command found deal with either missing/invalid command - { - //find last flag - int lastFlagPos; - char* strippedFlag; - for (lastFlagPos = argc - 1; lastFlagPos > 0; lastFlagPos--) { - if (argv[lastFlagPos][0] == '-' && !IS_NUM(argv[lastFlagPos][1])) - break; - } - if (lastFlagPos == 0) { - cout << FLINT_NO_OPTIONS_FOUND_ERROR << endl; - rc = PARSE_ERROR; - goto clean_up; - } - strippedFlag = stripFlag(argv[lastFlagPos]); - //check how many args it needs - int numOfArgs = flags.getNumOfArgs(strippedFlag); - //if too many args return arg in pos num_of_args+1 as the invalid command. - if ((argc - 1 - lastFlagPos) > numOfArgs) { - printf(FLINT_INVALID_COMMAD_ERROR, argv[argc - 1]); - rc = PARSE_ERROR; - goto clean_up; - } - } - //Step5 parse option section using _cmdParser - rc = this->_cmdParser.ParseOptions(newArgc, newArgv); - // Step 6 Delete allocated memory - clean_up: for (int i = 0; i < newArgc; i++) { - delete[] newArgv[i]; - } - return rc; -} diff --git a/flint/err_msgs.h b/flint/err_msgs.h deleted file mode 100644 index 6f8bc18..0000000 --- a/flint/err_msgs.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * - * err_msgs.h - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - - -#ifndef __ERR_MSGS_H__ -#define __ERR_MSGS_H__ - -/********************** - * Flint Status Code - *********************/ - -typedef enum { - FLINT_SUCCESS = 0, - FLINT_FAILED = 1, - FLINT_BURN_ABORTED = 7 -}FlintStatus; - -/*********************** - * Flint Error Messages - **********************/ - -#define FLINT_CLEAR_SEM_CMD_ERROR "No command is allowed when -clear_semaphore flag is given.\n" -#define FLINT_COMMAND_FLAGS_ERROR "For %s command, Please specify %s.\n" -#define FLINT_PARSE_MEM_ERROR "Failed to allocate memory for parsing.\n " -#define FLINT_NO_OPTIONS_FOUND_ERROR "No options found. " -#define FLINT_INVALID_COMMAD_ERROR "Invalid command: %s\n" -#define FLINT_TOO_MANY_ARGS_ERROR "Too many arguments. Expected: %d , Received: %d\n" -#define FLINT_TOO_FEW_ARGS_ERROR "Too few arguments. Expected: %d , Received: %d\n" -#define FLINT_NO_COMMAND_ERROR "No command found." -#define FLINT_OPEN_FWOPS_DEVICE_ERROR "Cannot open Device: %s. %s\n" -#define FLINT_OPEN_FWOPS_IMAGE_ERROR "Cannot open Image: %s. %s\n" -#define FLINT_DEVICE_AND_IMAGE_ERROR "Please specify either Device or Image.\n" -#define FLINT_NO_DEVICE_ERROR "Please specify Device.\n" -#define FLINT_NO_IMAGE_ERROR "Please specify Image file.\n" -#define FLINT_MISSED_ARG_ERROR "Missed %s parameter after \"%s\" command.\n" -#define FLINT_CMD_ARGS_ERROR "Command \"%s\" requires %d arguments, but %d arguments were given\n" -#define FLINT_CMD_ARGS_ERROR2 "Command \"%s\" requires at most %d arguments, but %d arguments were given\n" -#define FLINT_CMD_ARGS_ERROR3 "Command \"%s\" requires at least %d arguments, but %d arguments were given\n" -#define FLINT_CMD_ARGS_ERROR4 "Command \"%s\" requires %d or %d arguments, but %d arguments were given\n" -#define FLINT_CMD_ARGS_ERROR5 "Command \"%s\" does not require arguments\n" -#define FLINT_INVALID_OPTION_ERROR "Unknown option \"%s\" for the \"%s\" command. you can use %s.\n" -#define FLINT_INVALID_FLAG_ERROR "Invalid switch \"%s\" is specified.\n" -#define FLINT_INVALID_FLAG_WITH_FLAG_ERROR "Cannot specify \"%s\" flag with \"%s\" flag.\n" -#define FLINT_INVALID_FLAG_WITHOUT_FLAG_ERROR "\"%s\" flag must be specified with \"%s\" flag.\n" -#define FLINT_INVALID_FLAG_WITH_CMD_ERROR "Cannot specify flag: %s with Command: %s\n" -#define FLINT_CMD_VERIFY_ERROR "FW image verification failed: %s. AN HCA DEVICE CAN NOT BOOT FROM THIS IMAGE.\n" -#define FLINT_FAILED_QUERY_ERROR "Failed to query %s: %s.%s\n" -#define FLINT_COMMAND_DEVICE_IMAGE_ERROR "Command \"%s\" requires both image and device to be specified.\n" -#define FLINT_COMMAND_DEVICE_ERROR "Command \"%s\" requires device, but an image file was given.\n" -#define FLINT_COMMAND_IMAGE_ERROR "Command \"%s\" requires an image file, but device was given.\n" -#define FLINT_COMMAND_DEVICE_ERROR2 "Command \"%s\" requires device, but both an image file and a device are given.\n" -#define FLINT_COMMAND_IMAGE_ERROR2 "Command \"%s\" requires an image, but both an image file and a device are given.\n" -#define FLINT_HW_SET_ARGS_ERROR "bad argument of hw set command : %s, it should be in the format PARAM_NAME=VALUE\n" -#define FLINT_HW_COMMAND_ERROR "HW %s failed. %s\n" -#define FLINT_SWRESET_ERROR "Software reset failed. %s\n" -#define FLINT_ERASE_SEC_ERROR "Erase sector failed. %s\n" -#define FLINT_INVALID_ADDR_ERROR "Invalid address \"%s\"\n" -#define FLINT_FLASH_READ_ERROR "Flash read failed. %s\n" -#define FLINT_FLASH_WRITE_ERROR "Flash write failed. %s\n" -#define FLINT_INVALID_DATA_ERROR "Invalid data \"%s\"\n" -#define FLINT_INVALID_SIZE_ERROR "Invalid size \"%s\", Length should be 4-bytes aligned.\n" -#define FLINT_INVALID_ARG_ERROR "Invalid argument \"%s\"\n" -#define FLINT_OPEN_FILE_ERROR "Cannot open %s: %s\n" -#define FLINT_WRITE_FILE_ERROR "Failed to write to %s: %s\n" -#define FLINT_IO_OPEN_ERROR "Failed to open %s: %s\n" -#define FLINT_IMAGE_READ_ERROR "Failed to read image. %s\n" -#define FLINT_READ_ERROR "Failed to read from %s. %s\n" -#define FLINT_WIN_NOT_SUPP_ERROR "Command \"%s\" is not supported in windows.\n" -#define FLINT_WIN_ONLY_SUPP_ERROR "Command \"%s\" is supported only in windows.\n" -#define FLINT_GEN_COMMAND_ERROR "Failed to execute command %s. %s\n" -#define FLINT_FS3_BB_ERROR "bb command is not supported anymore in FS3 image, please use b for burning FS3 image.\n" -#define FLINT_FS3_BURN_ERROR "Burning FS3 image failed: %s\n" -#define FLINT_FS2_BURN_ERROR "Burning FS2 image failed: %s\n" -#define FLINT_PSID_ERROR "PSID mismatch. The PSID on flash (%s) differs from the PSID in the given image (%s).\n" -#define FLINT_FS2_STRIPED_ERROR "The -striped_image cannot be used with the burn command\n" -#define FLINT_IMG_DEV_COMPAT_ERROR "The given device requires an %s image type, but the given image file does not contain an %s FW image\n" -#define FLINT_UNKNOWN_FW_TYPE_ERROR "Unknown Firmware Type.\n" -#define FLINT_READ_ROM_ERROR "Read ROM failed. %s\n" -#define FLINT_SG_GUID_ERROR "Cannot set GUIDs: %s\n" -#define FLINT_SG_UID_ERROR "Failed to set UID: %s\n" -#define FLINT_MFG_ERROR "Failed to set manufacture guids: %s\n" -#define FLINT_VSD_ERROR "Failed to set the VSD: %s\n" -#define FLINT_VPD_ERROR "Failed to set VPD: %s\n" -#define FLINT_SET_KEY_ERROR "Failed to set the HW access key: %s\n" -#define FLINT_RESET_CFG_ERROR "Failed to reset Configuration: %s\n" -#define FLINT_FIX_IMG_ERROR "Failed to fix device image: %s\n" -#define FLINT_DROM_ERROR "Remove ROM failed: %s\n" -#define FLINT_BROM_ERROR "Burn ROM failed: %s\n" -#define FLINT_DUMP_ERROR "Failed dumping %s : %s\n" -#define FLINT_ROM_QUERY_ERROR "Image file rom (%s) query failed. %s\n" -#define FLINT_WB_FILE_ERROR "failed to open file: %s. %s\n" -#define FLINT_WB_ERROR "write Block Failed. %s\n" -#define FLINT_NO_ZLIB_ERROR "Executable was compiled with \"dump files\" option disabled.\n" -#define FLINT_FLAG_WITH_FLAG_ERROR "\"%s\" flag must be specified with \"%s\" flag.\n" -#define FLINT_INVALID_PASSWORD "Invalid Password.\n" -#define FLINT_NO_GUID_MAC_FLAGS_ERROR "Can not set GUIDs/MACs: please run with -uid/-guid/-mac flag.\n" -#define FLINT_NO_UID_FLAG_ERROR "Can not set GUIDs/MACs: uid is not specified, please run with -uid flag.\n" -#define FLINT_CHECKSUM_ERROR "Failed to calculate checksum on %s: %s\n" -#define FLINT_CHECKSUM_MISSMATCH_ERROR "Given checksum: %s does not match the checksum calculated on device FW: %s.\n" -#define FLINT_CHECKSUM_PARSE_ERROR "Failed to parse given checksum.\n" -#define FLINT_CHECKSUM_LEN_ERROR "MD5 checksum should be exactly 16 bytes long.\n" -#define FLINT_CHECKSUM_HEX_ERROR "MD5 checksum should contain only hexadecimal digits.\n" -#define FLINT_CACHE_IMAGE_ERROR "Failed to issue image cache request to driver. %s. make sure Mellanox driver is loaded and working properly.\n" - -/************************** - * Flint Warning Messages - *************************/ -#define FLINT_QQ_WARRNING "-W- Running quick query - Skipping full image integrity checks.\n" -#define FLINT_NOT_MLNX_FW_WARNING "-W- Not a Mellanox FW image (vendor_id = 0x%04x). VSD and PSID are not displayed.\n" -#define FLINT_BLANK_GUIDS_WARNING "-W- GUIDs/MACs values and their CRC are not set.\n" -#define FLINT_MULTI_BIT_WARNING "Multicast bit (bit 40) is set." -#define FLINT_MORE_48_BITS_WARNING "More than 48 bits are used." -#define FLINT_BAD_MAC_ADRESS_WARNING "\n-W- Bad mac address ( %4.4x%8.8x ): %s\n" -#define FLINT_MAC_ENTRIES_WARNING "-W- Cannot get MAC address: Expecting %d entries in guid section, got %d. Probably an old FW image. Please update.\n" -#define FLINT_INTERRUPT_WARRNING "\n-W- An internal error occurred. This program cannot be interrupted.\n" -#define FLINT_SET_GUIDS_WARRNING "-W- GUIDs are already set, re-burning image with the new GUIDs ...\n" -#define FLINT_OCR_WARRNING "\n-W- Firmware flash cache access is enabled. Running in this mode may cause the firmware to hang.\n" -#endif diff --git a/flint/flint.cpp b/flint/flint.cpp deleted file mode 100644 index dedce9d..0000000 --- a/flint/flint.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/* - * - * flint.cpp - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#include -#include - -#include "flint.h" - -//Globals: -Flint* gFlint = NULL; -extern FILE* flint_log_fh; -//signal handler section - -#define BURN_INTERRUPTED 0x1234 - -void TerminationHandler(int signum); - -#ifdef __WIN__ -#include - -static BOOL CtrlHandler( DWORD fdwCtrlType ) -{ - switch( fdwCtrlType ) - { - // Handle the CTRL-C signal. - case CTRL_C_EVENT: - // CTRL-CLOSE: confirm that the user wants to exit. - case CTRL_CLOSE_EVENT: - // Pass other signals to the next handler. - case CTRL_BREAK_EVENT: - case CTRL_LOGOFF_EVENT: - case CTRL_SHUTDOWN_EVENT: - TerminationHandler(SIGINT); - return TRUE; - - default: - return FALSE; - } - } - -#endif - - -void TerminationHandler(int signum) -{ - static volatile sig_atomic_t fatal_error_in_progress = 0; - - if (fatal_error_in_progress) { - raise (signum); - } - fatal_error_in_progress = 1; - - signal (signum, SIG_DFL); - write_result_to_log(BURN_INTERRUPTED, ""); - close_log(); - if (gFlint != NULL) { - printf("\n Received signal %d. Cleaning up ...\n", signum); - fflush(stdout); - //sleep(1); // Legacy from the Old Flint - delete gFlint; - gFlint = NULL; - printf(" Done.\n"); - } - raise(signum); -} - - -void initHandler() -{ -#ifdef __WIN__ -#define SIGNAL_NUM 3 - int signalList[SIGNAL_NUM] = {SIGINT, SIGTERM, SIGABRT}; - SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, true ); -#else -#define SIGNAL_NUM 4 - int signalList[SIGNAL_NUM] = {SIGINT, SIGTERM, SIGPIPE, SIGHUP}; -#endif - - //set the signal handler - for (int i=0; i < SIGNAL_NUM ; i++) { - void (*prevFunc)(int); - prevFunc = signal(signalList[i],TerminationHandler); - if (prevFunc == SIG_ERR) { - printf("-E- failed to set signal Handler."); - exit(FLINT_FAILED); - } - } -} - -//End of signal handler section. - - -map_sub_cmd_t_to_subcommand Flint::initSubcommandMap() -{ - map_sub_cmd_t_to_subcommand cmdMap; - cmdMap[SC_Burn] = new BurnSubCommand(); - cmdMap[SC_Query] = new QuerySubCommand(); - cmdMap[SC_Verify] = new VerifySubCommand(); - cmdMap[SC_Swreset] = new SwResetSubCommand(); - cmdMap[SC_ResetCfg] = new ResetCfgSubCommand(); - cmdMap[SC_Brom] = new BromSubCommand(); - cmdMap[SC_Drom] = new DromSubCommand(); - cmdMap[SC_Rrom] = new RromSubCommand(); - cmdMap[SC_Qrom] = new RomQuerySubCommand(); - cmdMap[SC_Bb] = new BbSubCommand(); - cmdMap[SC_Sg] = new SgSubCommand(); -#ifndef EXTERNAL - cmdMap[SC_Smg] = new SmgSubCommand(); - cmdMap[SC_Set_Vpd] = new SetVpdSubCommand(); - cmdMap[SC_Fix_Img] = new FiSubCommand(); -#endif - cmdMap[SC_Sv] = new SvSubCommand(); - cmdMap[SC_Ri] = new RiSubCommand(); - cmdMap[SC_Dc] = new DcSubCommand(); - cmdMap[SC_Dh] = new DhSubCommand(); - cmdMap[SC_Set_Key] = new SetKeySubCommand(); - cmdMap[SC_Hw_Access] = new HwAccessSubCommand(); - cmdMap[SC_Hw] = new HwSubCommand(); - cmdMap[SC_Erase] = new EraseSubCommand(); - cmdMap[SC_Rw] = new RwSubCommand(); - cmdMap[SC_Ww] = new WwSubCommand(); - cmdMap[SC_Wwne] = new WwneSubCommand(); - cmdMap[SC_Wbne] = new WbneSubCommand(); - cmdMap[SC_Wb] = new WbSubCommand(); - cmdMap[SC_Rb] = new RbSubCommand(); - cmdMap[SC_Clear_Sem] = new ClearSemSubCommand(); - cmdMap[SC_Check_Sum] = new CheckSumSubCommand(); - cmdMap[SC_Time_Stamp] = new TimeStampSubCommand(); - cmdMap[SC_Cache_Image] = new CacheImageSubCommand(); - return cmdMap; -} - -void Flint::deInitSubcommandMap(map_sub_cmd_t_to_subcommand cmdMap) -{ - for (map_sub_cmd_t_to_subcommand::iterator it = cmdMap.begin(); it != cmdMap.end(); ++it) - delete it->second; -} - - -Flint::Flint(): - CommandLineRequester(FLINT_DISPLAY_NAME" [OPTIONS] [Parameters]"), - _flintParams(), - _cmdParser(FLINT_DISPLAY_NAME" - Flash Interface"), - _subcommands(initSubcommandMap()) -{ - initCmdParser(); -} - -Flint::~Flint() -{ - deInitSubcommandMap(_subcommands); - if (_flintParams.flash_params.type_name) { - delete[] _flintParams.flash_params.type_name; - } -} - -FlintStatus Flint::run(int argc, char* argv[]) -{ - //Step1 parse input - //There are some memory allocations parseCmdLine - ParseStatus status; - try { - status = this->parseCmdLine(argc, argv);; - } catch (exception& e) { - cout << "-E- " << e.what() << endl; - return FLINT_FAILED; - } - if (status == PARSE_OK_WITH_EXIT) { - return FLINT_SUCCESS; - } else if (status == PARSE_ERROR || status == PARSE_ERROR_SHOW_USAGE) { - if (string(_cmdParser.GetErrDesc()).length() > 0) { - cout << "-E- " << this->_cmdParser.GetErrDesc() << endl; - } - return FLINT_FAILED; - } - - if (_flintParams.cmd == SC_No_Cmd && !_flintParams.clear_semaphore) - { - cout << FLINT_NO_COMMAND_ERROR << endl; - return FLINT_FAILED; - } - if (_flintParams.clear_semaphore) { - if (_flintParams.cmd != SC_No_Cmd) { - printf(FLINT_CLEAR_SEM_CMD_ERROR); - return FLINT_FAILED; - } - _flintParams.cmd = SC_Clear_Sem; - } - - //TODO: adrianc: remove use_fw flag and this condition before MFT-4.1.0 - if (_flintParams.use_fw && _flintParams.override_cache_replacement) { - printf("-E- flags --use_fw and --override_cache_replacement/-ocr cannot be specified simultaneously"); - return FLINT_FAILED; - } - - // Step 2 save argv as a single cmd string in flint params for the log functionallity - for(int i=0; isetParams(_flintParams); - return _subcommands[_flintParams.cmd]->executeCommand(); -} - - -int main(int argc, char* argv[]) -{ - initHandler(); - try - { - gFlint = new Flint(); - FlintStatus rc = gFlint->run(argc, argv); - if (gFlint) { - delete gFlint; - gFlint = NULL; - } - return rc; - } - catch (std::exception& e) - { - cout<<"-E- "< -#include "flint_params.h" -#include "subcommands.h" -#include -#include "err_msgs.h" - -using namespace std; - -typedef map map_sub_cmd_t_to_subcommand; -typedef map map_string_to_string; -typedef map map_string_to_int; - -map_string_to_string initShortToLongFlagMap(); -map_string_to_int initLongFlagToNumOfArgsMap(); -void deInitSubcommandMap(map_sub_cmd_t_to_subcommand cmdMap); -map_sub_cmd_t_to_subcommand initSubcommandMap(); - -class Flint : public CommandLineRequester -{ -private: - FlintParams _flintParams; - CommandLineParser _cmdParser; - map_sub_cmd_t_to_subcommand _subcommands; - - //methods - map_sub_cmd_t_to_subcommand initSubcommandMap(); - void deInitSubcommandMap(map_sub_cmd_t_to_subcommand cmdMap); - -public: - Flint(); - ~Flint(); - void initCmdParser(); - virtual ParseStatus HandleOption(string name, string value); - ParseStatus parseCmdLine(int argc, char* argv[]); - FlintStatus run(int argc, char* argv[]); -}; -#endif diff --git a/flint/flint_params.cpp b/flint/flint_params.cpp deleted file mode 100644 index a89ba11..0000000 --- a/flint/flint_params.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * flint_params.cpp - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#include "flint_params.h" - -FlintParams::FlintParams() -{ - help = false; - version = false; - extended_help = false; - guids_specified = false; - guid_specified = false; - mac_specified = false; - macs_specified = false; - uid_specified = false; - device_specified = false; - blank_guids = false; - clear_semaphore = false; - quick_query = true; //should now be true by default - image_specified = false; - nofs = false; - allow_psid_change = false; - allow_rom_change = false; - override_cache_replacement = false; - use_fw = false; // access flash via FW on CX3/CX3Pro - no_flash_verify = false; - silent = false; - yes = false; - no = false; - vsd_specified = false; - use_image_ps = false; - use_image_guids = false; - use_image_rom = false; - dual_image = false; - striped_image = false; - ignore_dev_data = false; - banks_specified = false; - banks = -1; // must be -1 for mflash to get default num of flash - log_specified = false; - flash_params_specified = false; - flash_params.type_name = (char*)NULL; - no_devid_check = false; - cmd = SC_No_Cmd; - baseUid.h = 0; - baseUid.l = 0; - flash_params.num_of_flashes = 0; - flash_params.log2size = 0; - use_dev_img_info = false; -} - -FlintParams::~FlintParams() -{ - -} diff --git a/flint/flint_params.h b/flint/flint_params.h deleted file mode 100644 index 0a987a0..0000000 --- a/flint/flint_params.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * - * flint_params.h - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#ifndef __FLINTPARAMS__ -#define __FLINTPARAMS__ - -#include -#include -#include "mlxfwops/lib/mlxfwops_com.h" -#include "mflash/mflash.h" - -using namespace std; - -typedef enum { - SC_No_Cmd = 0, - SC_Burn, - SC_Query, - SC_Verify, - SC_Swreset, - SC_ResetCfg, - SC_Brom, - SC_Drom, - SC_Rrom, - SC_Bb, - SC_Sg, - SC_Smg, - SC_Set_Vpd, - SC_Sv, - SC_Ri, - SC_Dc, - SC_Dh, - SC_Set_Key, - SC_Hw_Access, - SC_Hw, - SC_Erase, - SC_Rw, - SC_Ww, - SC_Wwne, - SC_Wbne, - SC_Wb, - SC_Rb, - SC_Clear_Sem, - SC_Fix_Img, - SC_Qrom, - SC_Check_Sum, - SC_Time_Stamp, - SC_Cache_Image -} sub_cmd_t; - -class FlintParams { -public: - //add more params - FlintParams(); - ~FlintParams(); - bool device_specified; - string device; - bool guids_specified; - bool guid_specified; - std::vector user_guids; - bool mac_specified; - bool macs_specified; - std::vector user_macs; - bool uid_specified; - guid_t baseUid; - bool help; - bool version; - bool extended_help; - bool blank_guids; - bool clear_semaphore; - bool quick_query; - bool image_specified; - string image; - bool nofs; - bool allow_psid_change; - bool allow_rom_change; - bool override_cache_replacement; - bool use_fw; - bool no_flash_verify; - bool silent; - bool yes; - bool no; - bool vsd_specified; - string vsd; - bool use_image_ps; - bool use_image_guids; - bool use_image_rom; - bool dual_image; - bool striped_image; - bool ignore_dev_data; - bool banks_specified; - int banks; - bool log_specified; - string log; - bool flash_params_specified; - flash_params_t flash_params; - bool no_devid_check; - sub_cmd_t cmd; - vector cmd_params; - string fullCmd; - bool use_dev_img_info; -}; - -#endif diff --git a/flint/subcommands.cpp b/flint/subcommands.cpp deleted file mode 100644 index 71a9fbd..0000000 --- a/flint/subcommands.cpp +++ /dev/null @@ -1,4355 +0,0 @@ -/* - * - * subcommands.cpp - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifndef NO_ZLIB - #include -#endif - -#if !defined(__WIN__) && !defined(__DJGPP__) && !defined(UEFI_BUILD) && defined(HAVE_TERMIOS_H) - // used in mygetchar - #include -#endif - -#ifdef __WIN__ -#include -#include - -#include -#endif - -#include "subcommands.h" - -using namespace std; - -#define INDENT "\t\t\t\t\t\t" -#define INDENTEX "\t" - -/*********************************** - * Log file writing implementation -************************************/ - -//global log file header -FILE* flint_log_fh = NULL; - -#define BURN_INTERRUPTED 0x1234 - -void close_log() -{ - if (flint_log_fh != NULL) { - fclose(flint_log_fh); - flint_log_fh = NULL; - } - return; -} - -#define ARR_SIZE(arr) sizeof(arr)/sizeof(arr[0]) - -const char* month_2monstr (int month) { - static const char* month_2monstr_arr[] = { - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", - }; - int arr_size = (int)ARR_SIZE(month_2monstr_arr); - return month < arr_size ? month_2monstr_arr[month] : "???"; -} - -void print_time_to_log() -{ - time_t rawtime; - struct tm * timeinfo; - - if (flint_log_fh == NULL) { - return; - } - time ( &rawtime ); - timeinfo = localtime ( &rawtime ); - - fprintf(flint_log_fh, "%-3s %2d %02d:%02d:%02d ", month_2monstr(timeinfo->tm_mon), timeinfo->tm_mday, - timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); - return; -} - -int print_line_to_log(const char* format, ...) -{ - va_list args; - if (flint_log_fh == NULL) { - return 0; - } - print_time_to_log(); - va_start(args, format); - vfprintf(flint_log_fh, format, args); - va_end(args); - return 0; -} - -int write_cmd_to_log(string fullCmd , sub_cmd_t cmd, bool write) -{ - if (!write) { - return 0; - } - char pre_str[50]; - if (flint_log_fh == NULL) { - return 0; - } - if (cmd == SC_Brom) { - snprintf(pre_str, 50, "ROM"); - } else { - snprintf(pre_str, 50, "FW"); - } - print_time_to_log(); - fprintf(flint_log_fh, "Start %s burning: ", pre_str); - fprintf(flint_log_fh, "%s ", fullCmd.c_str()); - fprintf(flint_log_fh, "\n"); - return 0; -} - -int write_result_to_log(int is_failed, const char* err_msg, bool write) -{ - if (!write) { - return 0; - } - char msg[MAX_ERR_STR_LEN + 1] = {0}; - strncpy(msg, err_msg, MAX_ERR_STR_LEN); - if (is_failed == 0) { - print_line_to_log("Burn completed successfully\n"); - } else if (is_failed == BURN_INTERRUPTED) { - print_line_to_log("Burn interrupted by user\n"); - } else { - int msg_len = strlen(msg); - // cleanup the msg - for (int i = 0; i < msg_len; i++) { - if (msg[i] == '\n') { - if (i == msg_len - 1) { - msg[i] = '\0'; - } else { - msg[i] = ' '; - } - } - } - print_line_to_log("Burn failed: %s\n", msg); - } - return 0; -} -/******************* - * Static functions - ******************/ - -static bool str2Num(const char* str, u_int32_t& num) { - char* endp; - u_int32_t tempNum; - - if (!str) { - return false; - } - tempNum = strtoul(str, &endp, 0); - if (*endp) { - return false; - } - num = tempNum; - return true; -} - -/******************* - * Class: Subcommand - ******************/ - - -#define MAX_ERR_STR_LEN 1024 -#define PRE_ERR_MSG "-E-" - -bool SubCommand::isCmdSupportLog() { - // a subcommand supports Logging if: A & B where: - // A. it is either Burn, Burn Block or Burn ROM. - // B. log flag was given in the cmd line. - - switch (_cmdType) { - case SC_Burn: - case SC_Bb: - case SC_Brom: - return _flintParams.log_specified; - default: - return false; - } - return false; -} - -void SubCommand::reportErr(bool shouldPrint, const char *format, ...) -{ - va_list args; - - va_start(args, format); - - if (vsnprintf(_errBuff, FLINT_ERR_LEN, format, args) >= FLINT_ERR_LEN) { - strcpy(&_errBuff[FLINT_ERR_LEN - 5], "...\n"); - } - //print to the user and to the log if needed - if (shouldPrint) { - fprintf(stdout,PRE_ERR_MSG" %s",_errBuff); - } - write_result_to_log(FLINT_FAILED,_errBuff, isCmdSupportLog()); - va_end(args); - - return; -} - -bool SubCommand::writeToFile(string filePath, const std::vector& buff) { - FILE* fh; - if ((fh = fopen(filePath.c_str(), "wb")) == NULL) { - reportErr(true, FLINT_OPEN_FILE_ERROR, filePath.c_str(), strerror(errno)); - return false; - } - // Write - if (fwrite(&buff[0], 1, buff.size(), fh) != buff.size()) { - fclose(fh); - reportErr(true, FLINT_WRITE_FILE_ERROR, filePath.c_str(), strerror(errno)); - return false; - } - fclose(fh); - return true; -} - -void SubCommand::openLog() -{ - if (isCmdSupportLog()) { - flint_log_fh = fopen(_flintParams.log.c_str(), "a+"); - if (flint_log_fh == NULL) { - printf("-W- Failed to open log file \"%s\": %s. No logs will be saved\n", _flintParams.log.c_str() - , strerror(errno)); - } - write_cmd_to_log(_flintParams.fullCmd, _flintParams.cmd, _flintParams.log_specified); - } -} - -int SubCommand::verifyCbFunc(char* str) -{ - printf("%s", str); - return 0; -} - - -int SubCommand::CbCommon(int completion, char*preStr, char* endStr) -{ - if (completion < 100) { - printf("\r%s%03d%%", preStr, completion); - }else if (completion == 100) { - printf("\r%sOK \n", preStr); - } else {// printing endStr - if (endStr){ - printf("\r%s\n", endStr); - } - } - fflush(stdout); - return 0; -} - -// HACK: the endStr is printed when we reach 101% this is for backward compat with the original flint -// output. thus in subcommands that use these callbacks you will see we manually call them at the end with the 101 arg - -int SubCommand::burnCbFs3Func(int completion) -{ - char* message = (char*)"Burning FS3 FW image without signatures - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - -int SubCommand::burnCbFs2Func(int completion) -{ - char* message = (char*)"Burning FS2 FW image without signatures - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - -int SubCommand::bromCbFunc(int completion) -{ - char* message = (char*)"Burning ROM image - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - -int SubCommand::dromCbFunc(int completion) -{ - char* message = (char*)"Removing ROM image - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - -int SubCommand::resetCfgCbFunc(int completion) -{ - char* message = (char*)"Resetting NV configuration - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - - -int SubCommand::burnBCbFunc(int completion) -{ - return CbCommon(completion,(char*)""); -} - -int SubCommand::vsdCbFunc(int completion) -{ - char* message = (char*)"Setting the VSD - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - -int SubCommand::setKeyCbFunc(int completion) -{ - char* message = (char*)"Setting the HW Key - "; - char* endStr = (char*)"Restoring signature - OK"; - return CbCommon(completion, message, endStr); -} - -int SubCommand::wbCbFunc(int completion) -{ - char* message = (char*)"Writing Block: - "; - return CbCommon(completion, message, NULL); -} - -#define ERR_BUFF_SIZE 1024 -FlintStatus SubCommand:: openOps() -{ - char errBuff[ERR_BUFF_SIZE]; - errBuff[0] = '\0'; - if (_flintParams.device_specified) { - // fillup the fw_ops_params_t struct - FwOperations::fw_ops_params_t fwParams; - memset(&fwParams, 0 , sizeof(FwOperations::fw_ops_params_t)); - fwParams.errBuff = errBuff; - fwParams.errBuffSize = ERR_BUFF_SIZE; - fwParams.flashParams =_flintParams.flash_params_specified ? &_flintParams.flash_params : NULL; - fwParams.forceLock = _flintParams.clear_semaphore; - fwParams.hndlType = FHT_MST_DEV; - fwParams.ignoreCacheRep = _flintParams.override_cache_replacement ? 1 : 0; - fwParams.mstHndl = strcpy(new char[_flintParams.device.length()+1],_flintParams.device.c_str()); - fwParams.numOfBanks = _flintParams.banks; - fwParams.readOnly = false; - fwParams.noFlashVerify = _flintParams.no_flash_verify; - fwParams.cx3FwAccess = _flintParams.use_fw; - _fwOps = FwOperations::FwOperationsCreate(fwParams); - delete[] fwParams.mstHndl; - } - if (_flintParams.image_specified) { - _imgOps = FwOperations::FwOperationsCreate((void*)_flintParams.image.c_str(), NULL, NULL,\ - FHT_FW_FILE, errBuff, 1024); - } - if (_flintParams.device_specified && _fwOps == NULL) - { - reportErr(true, FLINT_OPEN_FWOPS_DEVICE_ERROR, _flintParams.device.c_str(), strlen(errBuff) != 0 ? errBuff : ""); - return FLINT_FAILED; - } - if (_flintParams.image_specified && _imgOps == NULL) - { - reportErr(true, FLINT_OPEN_FWOPS_IMAGE_ERROR, _flintParams.image.c_str(), strlen(errBuff) != 0 ? errBuff : ""); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - - - -FlintStatus SubCommand:: openIo() -{ - //TODO: consider adding a parameter for when image/device will be opened as "readOnly" in the open routine. - if (_flintParams.device_specified && _flintParams.image_specified) { - //should not arrive here as we verify params at each subcommand. - reportErr(true, FLINT_DEVICE_AND_IMAGE_ERROR); - return FLINT_FAILED; - } - if (_flintParams.device_specified) { - _io = new Flash; - if (!((Flash*)_io)->open(_flintParams.device.c_str(), _flintParams.clear_semaphore, false, _flintParams.banks, \ - _flintParams.flash_params_specified ? &_flintParams.flash_params : NULL, _flintParams.override_cache_replacement, true, _flintParams.use_fw)) { - // if we have Hw_Access command we dont fail straght away - if (_flintParams.cmd == SC_Hw_Access && ((Flash*)_io)->get_cr_space_locked()) { - return FLINT_SUCCESS; - } - reportErr(true, FLINT_IO_OPEN_ERROR, "Device", (_io)->err()); - delete _io; - _io = NULL; - return FLINT_FAILED; - } - // we have successfully opened a Flash Obj - //set no flash verify if needed (default =false) - ((Flash*)_io)->set_no_flash_verify(_flintParams.no_flash_verify); - } else if (_flintParams.image_specified) { - _io = new FImage; - if (!((FImage*)_io)->open(_flintParams.image.c_str())) { - reportErr(true, FLINT_IO_OPEN_ERROR, "Image", (_io)->err()); - delete _io; - _io = NULL; - return FLINT_FAILED; - } - } - return FLINT_SUCCESS; -} - -bool SubCommand::basicVerifyParams() -{ - if (!_flintParams.log_specified) { - char* logFile; - logFile = getenv(FLINT_LOG_ENV); - if (logFile) { - _flintParams.log = logFile; - _flintParams.log_specified = true; - } - } - //open log if needed - openLog(); - - if (_maxCmdParamNum == _minCmdParamNum && _maxCmdParamNum != -1 && (int)_flintParams.cmd_params.size() != _maxCmdParamNum) { - reportErr(true, FLINT_CMD_ARGS_ERROR, _name.c_str(), _maxCmdParamNum, _flintParams.cmd_params.size()); - return false; - } else if (_maxCmdParamNum != -1 && (int)_flintParams.cmd_params.size() > _maxCmdParamNum) { // _maxCmdParamNum == -1 means ignore this check - if (_maxCmdParamNum) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), _maxCmdParamNum, _flintParams.cmd_params.size()); - } else { - reportErr(true, FLINT_CMD_ARGS_ERROR5, _name.c_str()); - } - return false; - } else if (_minCmdParamNum != -1 && (int)_flintParams.cmd_params.size() < _minCmdParamNum) { // _minCmdParamNum == -1 means ignore this check - reportErr(true, FLINT_CMD_ARGS_ERROR3, _name.c_str(), _minCmdParamNum, _flintParams.cmd_params.size()); - return false; - } - - switch (_v) { - case Wtv_Img: - if ( _flintParams.device_specified == true) { - _flintParams.image_specified ? reportErr(true, FLINT_COMMAND_IMAGE_ERROR2,_name.c_str()) : - reportErr(true, FLINT_COMMAND_IMAGE_ERROR, _name.c_str()); - return false; - } - if ( _flintParams.image_specified == false ) { - reportErr(true, FLINT_NO_IMAGE_ERROR); - return false; - } - break; - case Wtv_Dev: - if ( _flintParams.image_specified == true) { - _flintParams.device_specified ? reportErr(true, FLINT_COMMAND_DEVICE_ERROR2,_name.c_str()) : - reportErr(true, FLINT_COMMAND_DEVICE_ERROR, _name.c_str()); - return false; - } - if ( _flintParams.device_specified == false ) { - reportErr(true, FLINT_NO_DEVICE_ERROR); - return false; - } - break; - case Wtv_Dev_And_Img: - if (( _flintParams.image_specified == false) || ( _flintParams.device_specified == false)) { - reportErr(true, FLINT_COMMAND_DEVICE_IMAGE_ERROR, _name.c_str()); - return false; - } - break; - case Wtv_Dev_Or_Img: - if ( _flintParams.image_specified == true && _flintParams.device_specified == true) { - reportErr(true, FLINT_DEVICE_AND_IMAGE_ERROR); - return false; - } - if ( _flintParams.device_specified == false && _flintParams.image_specified == false ) { - reportErr(true, FLINT_DEVICE_AND_IMAGE_ERROR); - return false; - } - break; - default: - reportErr(true, "Failed to verify parms(internal error)."); - return false; - } - - if (_flintParams.device_specified && _flintParams.striped_image) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "-device", "-striped_image"); - return false; - } - - if (_flintParams.override_cache_replacement) { - printf(FLINT_OCR_WARRNING); - } - return true; -} - -FlintStatus SubCommand::preFwOps() -{ - if (!basicVerifyParams()) { - return FLINT_FAILED; - } - if (!verifyParams()) { - return FLINT_FAILED; - } - return openOps(); -} - -FlintStatus SubCommand::preFwAccess() -{ - if (!basicVerifyParams()) { - return FLINT_FAILED; - } - if (!verifyParams()) { - return FLINT_FAILED; - } - return openIo(); -} - -SubCommand::~SubCommand() -{ - if (_fwOps != NULL) { - _fwOps->FwCleanUp(); - delete _fwOps; - } - if (_imgOps != NULL) { - _imgOps->FwCleanUp(); - delete _imgOps; - } - if (_io != NULL) { - _io->close(); - delete _io; - } - - -} - -bool SubCommand::getRomsInfo(FBase* io, roms_info_t& romsInfo) -{ - std::vector romSector; - romSector.clear(); - romSector.resize(io->get_size()); - if (!io->read(0, &romSector[0], io->get_size())) { - reportErr(true, FLINT_READ_ERROR,_flintParams.image.c_str(), io->err()); - return false; - } - FwOperations::RomInfo info(romSector, false); - info.ParseInfo(); - info.initRomsInfo(&romsInfo); - return true; -} - -bool SubCommand::getGUIDFromStr(string str, guid_t& guid, string prefixErr) -{ - char* endp; - u_int64_t g; - g = strtoull(str.c_str(), &endp, 16); - if (*endp || (g == 0xffffffffffffffffULL && errno == ERANGE)) { - if (prefixErr.size() == 0) { - reportErr(true, "Invalid GUID syntax (%s) %s \n", str.c_str(), errno ? strerror(errno) : "" ); - } else { - reportErr(true, "%s\n", prefixErr.c_str()); - } - return false; - } - guid.h = (u_int32_t)(g >> 32); - guid.l = (u_int32_t)(g & 0xffffffff); - return true; -} - - -#if !defined(__WIN__) && !defined(__DJGPP__) && !defined(UEFI_BUILD) && defined(HAVE_TERMIOS_H) -static int mygetch(void) -{ - struct termios oldt, - newt; - int ch; - tcgetattr( STDIN_FILENO, &oldt ); - newt = oldt; - newt.c_lflag &= ~( ICANON | ECHO ); - tcsetattr( STDIN_FILENO, TCSANOW, &newt ); - ch = getchar(); - tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); - return ch; -} - -bool SubCommand::getPasswordFromUser(const char *preStr, char buffer[MAX_PASSWORD_LEN+1]) -{ - char c; - int pos = 0; - - printf("%s: ", preStr); - do { - c = mygetch(); - - if( ((pos < MAX_PASSWORD_LEN)) && isprint(c) ) { - buffer[ pos++ ] = c; - printf("%c", '*'); - } else if( (c == 8 || c == 127) && pos ) { - buffer[ pos-- ] = '\0'; - printf("%s", "\b \b"); - } - - - } while( c != '\n' ); - printf("\n"); - buffer[pos] = '\0'; - return true; -} - -#else -bool SubCommand::getPasswordFromUser(const char *preStr, char buffer[MAX_PASSWORD_LEN+1]) -{ - static HANDLE stdinHndl = NULL; - DWORD numOfBytesRead = 0; - DWORD oldConsoleMode, consoleMode; - BOOL status = FALSE; - char ch; - int i; - - if (!stdinHndl) { - // adrianc: this might be problematic if called and stdout was alreading overriden use CIN$ instead - stdinHndl = GetStdHandle(STD_INPUT_HANDLE); - } - printf("%s:", preStr); - - // disable console echoing - if (!GetConsoleMode(stdinHndl, &oldConsoleMode)) { - reportErr(true, "Failed to get console mode.\n"); - return false; - } - - consoleMode = oldConsoleMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT); - - if (! SetConsoleMode(stdinHndl, consoleMode)) { - reportErr(true, "Failed to set console mode.\n"); - return 1; - } - // read chars from stdin and print * to stdout using putchar - for(i = 0; ; ) { - status = ReadFile(stdinHndl, &ch, sizeof(char), &numOfBytesRead, NULL); - if (!status || numOfBytesRead != sizeof(char) || ch == '\n' || ch == '\r' || i == (MAX_PASSWORD_LEN -1) ) { - // user finished giving the pw - if (!SetConsoleMode(stdinHndl, oldConsoleMode)) { - reportErr(true, "Failed to restore console mode.\n"); - return false; - } - if (!status || numOfBytesRead != sizeof(char)) { - reportErr(true, "Failed to get input from console.\n"); - return false; - } - break; - } - if (isalpha(ch) || isdigit(ch)) { - putchar('*'); - buffer[i++] = ch; - } else if (ch == '\b' && i){ - //delete last astrix and set correct position - printf("\b \b"); - i--; - } - } - buffer[i] = '\0'; - putchar('\n'); - return true; -} - -#endif - -// -// Asks user a yes/no question. -// Returns true if user chose Y, false if user chose N. -// - -bool SubCommand::askUser(const char *question, bool printAbrtMsg) { - if (question == NULL) { - printf("\n Do you want to continue ? (y/n) [n] : "); - } else { - printf("\n %s ? (y/n) [n] : ", question); - - } - - if (_flintParams.yes) - printf("y\n"); - else { - if (_flintParams.no) { - printf("n\n"); - reportErr(false, "-no flag is set\n"); - return false; - } - - fflush(stdout); - std::string answer; - std::getline(std::cin, answer); - //fgets(ansbuff, 30, stdin); - //if (!fscanf(stdin, "%[^\n]30s", ansbuff)) { - // return false; - //} - - if ( strcasecmp(answer.c_str(), "y") && - strcasecmp(answer.c_str(), "yes")) { - - if (printAbrtMsg) { - reportErr(true, "Aborted by user\n"); - } - return false; - } - } - return true; -} - -void SubCommand::displayOneExpRomInfo(const rom_info_t& info) { - - const char* typeStr = FwOperations::expRomType2Str(info.exp_rom_product_id); - if (info.exp_rom_product_id == 0xf) {// version id in this case is the freeStr that was moved to exp_rom_ver[0] in mlxfwops - printf("devid=%d version_id=%d type=%s ", info.exp_rom_dev_id,info.exp_rom_ver[0], typeStr); - } else { - if (typeStr) { - printf("type=%s ", typeStr); - } else { - printf("0x%x - Unknown ROM product ID\n", info.exp_rom_product_id); - return; - } - - printf("version=%d", info.exp_rom_ver[0]); - if (info.exp_rom_product_id >= 0x10) { - printf(".%d.%d", info.exp_rom_ver[1], info.exp_rom_ver[2]); - - if (info.exp_rom_dev_id != EXP_ROM_GEN_DEVID) { - // Do not display if 0 - ROM is the same for all device IDs - printf(" devid=%d", info.exp_rom_dev_id); - } - if (info.exp_rom_port) { - // Do not display if 0 - port independent - printf(" port=%d", info.exp_rom_port); - } - if (info.exp_rom_product_id != 0x12) { // on CLP(0x12) there is no meaning to protocol - switch (info.exp_rom_proto) { - case ER_IB: - printf(" proto=IB"); - break; - case ER_ETH: - printf(" proto=ETH"); - break; - case ER_VPI: - printf(" proto=VPI"); - break; - default: - break; - } - } - } - } - return; -} - - -void SubCommand::displayExpRomInfo(const roms_info_t& romsInfo, const char *preStr) -{ - int i; - int strLen = strlen(preStr); - - if (romsInfo.num_of_exp_rom > 0) { - for (i = 0; i < romsInfo.num_of_exp_rom; i++) { - // Print the pre string or spaces - if (i == 0) { - printf("%s", preStr); - } else { - int j; - for ( j = 0; j < strLen; j++) { - printf("%s", " "); - } - } - // Display a ROM info - displayOneExpRomInfo(romsInfo.rom_info[i]); - if (i != romsInfo.num_of_exp_rom - 1) { // Don't print new line after the info of the last ROM - printf("\n"); - } - } - if (romsInfo.exp_rom_warning) { - printf(" (-W- %s)", romsInfo.exp_rom_warning_msg); - } - printf("\n"); - } else { - printf("%s", preStr); - printf("N/A"); - if (romsInfo.exp_rom_err_msg_valid) { - printf(" (-E- %s)", romsInfo.exp_rom_err_msg); - } - printf("\n"); - } - return; -} - -bool SubCommand::printGuidLine(guid_t* new_guids, guid_t* old_guids, int guid_index) -{ - printf(GUID_FORMAT GUID_SPACES, new_guids[guid_index].h, new_guids[guid_index].l); - if (old_guids != NULL) { - printf(GUID_FORMAT, old_guids[guid_index].h, old_guids[guid_index].l); - }else { - printf(" N/A"); - } - printf("\n"); - return true; -} - -bool SubCommand::printMacLine(guid_t* new_guids, guid_t* old_guids, int mac_index) -{ - printf(" " MAC_FORMAT MAC_SPACES, new_guids[mac_index].h, new_guids[mac_index].l); - if (old_guids != NULL) { - printf(MAC_FORMAT, old_guids[mac_index].h, old_guids[mac_index].l); - } else { - printf(" N/A"); - } - printf("\n"); - return true; -} - -bool SubCommand::printGUIDsFunc(guid_t guids[GUIDS],guid_t macs[MACS], guid_t old_guids[GUIDS],\ - guid_t old_macs[MACS], bool print_guids, bool print_macs, int portNum, bool old_guid_fmt) { - - if (print_guids) { - printf(" Node GUID: "); - printGuidLine(guids,old_guids, 0); - if (portNum > 0) { - printf(" Port1 GUID: "); - printGuidLine(guids,old_guids, 1); - } - if (portNum > 1) { - printf(" Port2 GUID: "); - printGuidLine(guids,old_guids, 2); - } - if (!old_guid_fmt) { - printf(" Sys.Image GUID: "); - printGuidLine(guids,old_guids, 3); - } - } - - if (print_macs) { - printf(" Port1 MAC: "); - printMacLine(macs, old_macs, 0); - printf(" Port2 MAC: "); - printMacLine(macs, old_macs, 1); - } - return true; -} - -bool SubCommand::reportGuidChanges(guid_t* new_guids, guid_t* new_macs,\ - guid_t* old_guids, guid_t* old_macs, bool printGuids,\ - bool printMacs, int guidNum) -{ - //should be used ONLY on FS2 in current implementation - printf(" You are about to change the Guids/Macs/Uids on the %s:\n\n", _flintParams.device_specified ? "device" : "image"); - printf(" New Values " GUID_SPACES "Current Values\n"); - printGUIDsFunc(new_guids, new_macs, - old_guids, old_macs, - printGuids, - printMacs, - guidNum, - guidNum < GUIDS); - - if (!askUser()) - return false; - - return true; -} - -//used for dc and dh subcommands - -bool SubCommand::unzipDataFile (std::vector data, std::vector &newData, const char *sectionName) -{ -#ifndef NO_ZLIB - int rc; - if (data.empty()) { - reportErr(true, "%s section not found in the given image.", sectionName); - return false; - } - // restore endianess. - TOCPUn(&(data[0]), data.size()/4); - - // uncompress: - uLongf destLen = data.size(); - destLen *= 40; // Assuming this is the best compression ratio - vector dest(destLen); - - for (int i = 0; i < 32; i++) { - rc = uncompress((Bytef *)&(dest[0]), &destLen, - (const Bytef *)&(data[0]), data.size()); - if (rc != Z_BUF_ERROR) { - break; - } - destLen *= 2; - dest.resize(destLen); - } - - if (rc != Z_OK) { - reportErr(true, "Failed uncompressing FW configuration section. uncompress returns %d", rc); - return false; - } - // printf("%s", (char*)&(dest[0])); - - newData = dest; - newData[destLen] = 0; // Terminating NULL - newData.resize(destLen + 1); - return true; -#else - // avoid warnings - (void) data; - (void) newData; - (void) sectionName; - reportErr(true, FLINT_NO_ZLIB_ERROR); - return false; -#endif -} - -bool SubCommand::dumpFile(const char* confFile, std::vector& data, const char *sectionName) { - FILE* out; - vector dest; - - if (confFile == NULL) { - out = stdout; - } else { - out = fopen(confFile, "w"); - - if (out == NULL) { - reportErr(true, "Can not open file %s for write: %s.", confFile, strerror(errno)); - return false; - } - } - if (unzipDataFile(data, dest, sectionName) == false) { - return false; - } - fprintf(out, "%s", (char*)&(dest[0])); - - if (confFile != NULL) { - fclose(out); - } - return true; -} - -bool SubCommand::checkGuidsFlags (u_int16_t devType, u_int8_t fwType, - bool guidsSpecified, bool macsSpecified, bool uidSpecified, bool ibDev, bool ethDev) { - (void)ibDev; - if (guidsSpecified || macsSpecified || uidSpecified) { - if (uidSpecified && fwType != FIT_FS3) { - reportErr(true, "-uid flag is applicable only for FS3 FW Only.\n"); - return false; - } else if (fwType != FIT_FS2 && !ethDev && macsSpecified ) { - reportErr(true, "-mac(s) flag is not applicable for IB MT%d device.\n", devType); - return false; - } - } - return true; -} - -void SubCommand::printMissingGuidErr(bool ibDev, bool ethDev) -{ - const char* missingInfo; - const char* missingFlags; - - if (ibDev && ethDev) { - missingInfo = "GUIDs / MACs"; - missingFlags = "-guid(s) / -mac(s)"; - } else if (ibDev) { - missingInfo = "GUIDs"; - missingFlags = "-guid(s)"; - } else { - missingInfo = "MACs"; - missingFlags = "-mac(s)"; - } - - printf("Please specify %s (using command line flags %s ).\n", missingInfo, missingFlags); - return; -} - -bool SubCommand::extractValuesFromString(string valStr, u_int8_t values[2], string origArg) { - // check if we need to extract 2 values or 1 - u_int32_t tempNum0 = 0, tempNum1 = 0; - string tempNumStr; - if (valStr.find(',') != string::npos) { - std::stringstream ss((valStr.c_str())); - // get first value - if (!std::getline(ss, tempNumStr, ',')) { - reportErr(true, FLINT_INVALID_ARG_ERROR,origArg.c_str()); - return false; - } - if (!str2Num(tempNumStr.c_str(), tempNum0)) { - reportErr(true, FLINT_INVALID_ARG_ERROR, origArg.c_str()); - return false; - } - // get second value - if (!std::getline(ss, tempNumStr, ',')) { - reportErr(true, FLINT_INVALID_ARG_ERROR, origArg.c_str()); - return false; - } - if (!str2Num(tempNumStr.c_str(), tempNum1)) { - reportErr(true, FLINT_INVALID_ARG_ERROR, origArg.c_str()); - return false; - } - // make sure no other tokens are present - if (!(!std::getline(ss, tempNumStr, ','))) { - reportErr(true, FLINT_INVALID_ARG_ERROR, origArg.c_str()); - return false; - } - } else { - if (!str2Num(valStr.c_str(), tempNum0)) { - reportErr(true, FLINT_INVALID_ARG_ERROR, origArg.c_str()); - return false; - } - tempNum1 = tempNum0; - } - // perform checks - if (tempNum0 >= 255 || tempNum1 >= 255) { - reportErr(true, "Invalid argument values, values should be taken from the range [0..254]\n"); - return false; - } - values[0] = tempNum0; - values[1] = tempNum1; - return true; -} - -bool SubCommand::extractUIDArgs(std::vector& cmdArgs, u_int8_t numOfGuids[2], u_int8_t stepSize[2]){ - //extract num_of_guids and step_size from numGuidsStr, stepStr - string tag, valStr; - for (std::vector::iterator it = cmdArgs.begin(); it != cmdArgs.end(); it++) { - std::stringstream ss((it->c_str())); - // get the tag - if (!std::getline(ss, tag, '=')) { - reportErr(true, FLINT_INVALID_ARG_ERROR,it->c_str()); - return false; - } - // get the val - if (!std::getline(ss, valStr, '=')) { - reportErr(true, FLINT_INVALID_ARG_ERROR,it->c_str()); - return false; - } - // make sure no other tokens are present - if (!(!std::getline(ss, valStr, '='))) { - reportErr(true, FLINT_INVALID_ARG_ERROR,it->c_str()); - return false; - } - if (tag == "guids_num") { - if (!extractValuesFromString(valStr, numOfGuids, *it)) { - return false; - } - } else if (tag == "step_size") { - if (!extractValuesFromString(valStr, stepSize, *it)) { - return false; - } - } else { - reportErr(true, FLINT_INVALID_ARG_ERROR, it->c_str()); - return false; - } - } - return true; -} - -/*********************** - *Class: BurnSubCommand - **********************/ - -BurnSubCommand:: BurnSubCommand() -{ - _name = "burn"; - _desc = "Burn flash"; - _extendedDesc = "Burn flash \n" - INDENTEX "Performs failsafe FW update from a raw binary image."; - _flagLong = "burn"; - _flagShort = "b"; - _param = ""; - _paramExp = "None"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " -i image1.bin burn\n" - INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE2 " -guid 0x2c9000100d050 -i image1.bin b"; - _v = Wtv_Dev_And_Img; - _maxCmdParamNum = 0; - _cmdType = SC_Burn; - _fwType = 0; - _devQueryRes = 0; - memset(&_devInfo, 0, sizeof(_devInfo)); - memset(&_imgInfo, 0, sizeof(_imgInfo)); -} - -BurnSubCommand:: ~BurnSubCommand() -{ - closeLog(); - if (_burnParams.userVsd != NULL) { - delete[] _burnParams.userVsd; - } -} - -bool BurnSubCommand::verifyParams() -{ - if ((_flintParams.guid_specified || _flintParams.guids_specified) && (_flintParams.uid_specified)) { - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "either GUIDs / UID (using command line flags -guid(s) / -uid )"); - return false; - } - if ((_flintParams.mac_specified || _flintParams.macs_specified) && (_flintParams.uid_specified)) { - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "either MACs / UID (using command line flags -mac(s) / -uid )"); - return false; - } - bool GuidsFromUser = _flintParams.guid_specified || _flintParams.guids_specified ||\ - _flintParams.uid_specified || \ - _flintParams.mac_specified || _flintParams.macs_specified; - if (GuidsFromUser && _flintParams.use_image_guids) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR,"GUIDs/UIDs/MACs", "-use_image_guids"); - return false; - } - if ((GuidsFromUser || _flintParams.use_image_guids) && _flintParams.blank_guids) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, _flintParams.use_image_guids ? \ - "-use_image_guids" : "GUIDs/UIDs/MACs", "-blank_guids"); - return false; - } - if (_flintParams.guid_specified && _flintParams.guids_specified) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "-guids", "-guid" ); - return false; - } - if (_flintParams.mac_specified && _flintParams.macs_specified) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "-macs", "-mac" ); - return false; - } - if (_flintParams.use_image_ps && _flintParams.vsd_specified) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "-use_image_ps", "-vsd"); - return false; - } - if (_flintParams.ignore_dev_data && !_flintParams.nofs) { - reportErr(true, FLINT_INVALID_FLAG_WITHOUT_FLAG_ERROR, "-nofs", "-ignore_dev_data"); - return false; - } - return true; -} - -void BurnSubCommand::updateBurnParams() -{ - _burnParams.progressFunc = _flintParams.silent == true ? (ProgressCallBack)NULL :\ - _fwType == FIT_FS2? &burnCbFs2Func : &burnCbFs3Func; - _burnParams.userGuidsSpecified = _flintParams.guids_specified || _flintParams.guid_specified; - _burnParams.userMacsSpecified = _flintParams.macs_specified || _flintParams.mac_specified; - _burnParams.userUidSpecified = _flintParams.uid_specified; - _burnParams.vsdSpecified = _flintParams.vsd_specified; - _burnParams.blankGuids = _flintParams.blank_guids; - _burnParams.burnFailsafe = !_flintParams.nofs; - _burnParams.allowPsidChange = _flintParams.allow_psid_change; - _burnParams.useDevImgInfo = _flintParams.use_dev_img_info; - _burnParams.useImagePs = _flintParams.use_image_ps; - _burnParams.burnRomOptions = _flintParams.use_image_rom ? FwOperations::ExtBurnParams::BRO_ONLY_FROM_IMG \ - : FwOperations::ExtBurnParams::BRO_DEFAULT ; - _burnParams.useImageGuids = _flintParams.use_image_guids; - _burnParams.singleImageBurn = !_flintParams.dual_image; - _burnParams.noDevidCheck = _flintParams.no_devid_check; - _burnParams.useImgDevData = _flintParams.ignore_dev_data; - if (_burnParams.userGuidsSpecified) { - _burnParams.userUids = _flintParams.user_guids; - } - if (_burnParams.userUidSpecified) { - _burnParams.userUids.resize(0); - _burnParams.userUids.push_back(_flintParams.baseUid); - } - if (_burnParams.userMacsSpecified) { - if (!_burnParams.userGuidsSpecified) { - //we dont care about the first 4 values - _burnParams.userUids.resize(GUIDS); - } - _burnParams.userUids.push_back(_flintParams.user_macs[0]); - _burnParams.userUids.push_back(_flintParams.user_macs[1]); - } - if (_burnParams.vsdSpecified) { - _burnParams.userVsd = strcpy(new char[_flintParams.vsd.size()+1], _flintParams.vsd.c_str()); - } - //make sure its of max size and fill the rest with 0xffff - _burnParams.userUids.resize(MAX_GUIDS, (guid_t){0xffffffff,0xffffffff}); -} - -#define VERSION_FORMAT(minor) minor < 100 ? "%d.%d.%04d" : "%d.%04d.%04d" -bool BurnSubCommand::checkFwVersion() -{ - char curr_ver[124], new_ver[124]; - printf("\n"); - printf(" Current FW version on flash: "); - if (_devInfo.fw_info.fw_ver[0] != 0) { // i.e if we have a fw_version we assume this is != 0 - snprintf(curr_ver, 124, VERSION_FORMAT(_devInfo.fw_info.fw_ver[1]), _devInfo.fw_info.fw_ver[0], _devInfo.fw_info.fw_ver[1], _devInfo.fw_info.fw_ver[2]); - } else { - snprintf(curr_ver, 124, "N/A"); - } - printf("%s", curr_ver); printf("\n"); - - printf(" New FW version: "); - if (_imgInfo.fw_info.fw_ver[0] != 0) { - snprintf(new_ver, 124, VERSION_FORMAT(_imgInfo.fw_info.fw_ver[1]), _imgInfo.fw_info.fw_ver[0], _imgInfo.fw_info.fw_ver[1], _imgInfo.fw_info.fw_ver[2]); - } else { - snprintf(new_ver, 124, "N/A"); - } - printf("%s", new_ver); printf("\n"); - - if (_flintParams.log_specified) { - print_line_to_log("Current FW version on flash: %s, New FW version: %s\n", curr_ver, new_ver); - } - int verStatus; - - if (_devInfo.fw_info.fw_ver[0] != 0 && - _imgInfo.fw_info.fw_ver[0] != 0) { // nofs pitfall here - on nofs burn no fwver of device - verStatus = FwOperations::FwVerLessThan(_devInfo.fw_info.fw_ver, _imgInfo.fw_info.fw_ver); - if (verStatus == FVI_EQUAL || verStatus == FVI_GREATER) { - printf("\n Note: The new FW version is %s the current FW version on flash.\n", verStatus == FVI_EQUAL ? "the same as" : "older than"); - if (!askUser()) { - return false; - } - } - } - - printf("\n"); - _burnParams.ignoreVersionCheck = true; - return true; -} - -bool BurnSubCommand::checkPSID() -{ - if (strlen(_imgInfo.fw_info.psid) != 0 && strlen(_devInfo.fw_info.psid) != 0 && - strncmp( _imgInfo.fw_info.psid, _devInfo.fw_info.psid, PSID_LEN)) { - if (_flintParams.allow_psid_change) { - printf("\n You are about to replace current PSID on flash - \"%s\" with a different PSID - \"%s\".\n" - " Note: It is highly recommended not to change the PSID.\n", - _devInfo.fw_info.psid, _imgInfo.fw_info.psid); - if (! askUser()) { - return false; - } - } else { - printf("\n"); - reportErr(true, FLINT_PSID_ERROR, _devInfo.fw_info.psid, _imgInfo.fw_info.psid); - return false; - } - } - return true; -} - -FlintStatus BurnSubCommand::burnFs3() -{ - // Here we want to burn FS3 device so we check if the image is indeed FS3 image - if (_imgInfo.fw_type != FIT_FS3 && _imgInfo.fw_type != FIT_FS4) { - reportErr(true, FLINT_IMG_DEV_COMPAT_ERROR, "FS3", "FS3"); - return FLINT_FAILED; - } - // on FS3 burn we require query to pass - if (!_devQueryRes && _burnParams.burnFailsafe) { - reportErr(true, FLINT_FS3_BURN_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - //check FwVersion - if ( !checkFwVersion()) { - return FLINT_BURN_ABORTED; - } - // check Psid - if (_devQueryRes && !checkPSID()) { - return FLINT_FAILED; - } - // deal with rom - dealWithExpRom(); - bool getRomFromDev = ( _burnParams.burnRomOptions == FwOperations::ExtBurnParams::BRO_FROM_DEV_IF_EXIST); - if (!getRomFromDev && !checkMatchingExpRomDevId(_imgInfo)) { - printf("Image file ROM: FW is for device %d, but Exp-ROM is for device %d\n", _imgInfo.fw_info.dev_type,\ - _imgInfo.fw_info.roms_info.exp_rom_com_devid); - if (!askUser()) { - return FLINT_FAILED; - } - } - if (!_burnParams.burnFailsafe) { - printf("Burn process will not be failsafe. No checks will be performed.\n"); - if (_burnParams.useImgDevData) { - printf("ALL flash, including the device data sections will be overwritten.\n"); - } - printf("If this process fails, computer may remain in an inoperable state.\n"); - if (!askUser()) { - return FLINT_FAILED; - } - } - - if (!_fwOps->FwBurnAdvanced(_imgOps, _burnParams)) { - reportErr(true, FLINT_FS3_BURN_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - PRINT_PROGRESS(_burnParams.progressFunc, 101); - write_result_to_log(FLINT_SUCCESS, "", _flintParams.log_specified); - const char* resetRec = _fwOps->FwGetResetRecommandationStr(); - if (resetRec) { - printf("-I- %s\n", resetRec); - } - return FLINT_SUCCESS; -} - -FlintStatus BurnSubCommand::burnFs2() -{ - - if (_flintParams.striped_image) { - reportErr(true, FLINT_FS2_STRIPED_ERROR); - return FLINT_FAILED; - } - if (_imgInfo.fw_type != FIT_FS2) { - reportErr(true, FLINT_IMG_DEV_COMPAT_ERROR, "FS2", "FS2"); - return FLINT_FAILED; - } - - //CheckMatchingHwDevId is done in mlxfwops burn routine. - //CheckMatchingDevId is done in mlxfwops burn routine. - - dealWithExpRom(); - bool getRomFromDev = _burnParams.burnRomOptions == FwOperations::ExtBurnParams::BRO_FROM_DEV_IF_EXIST; - if (!getRomFromDev && !checkMatchingExpRomDevId(_imgInfo)) { - printf("Image file ROM: FW is for device %d, but Exp-ROM is for device %d\n", _imgInfo.fw_info.dev_type,\ - _imgInfo.fw_info.roms_info.exp_rom_com_devid); - if (!askUser()) { - return FLINT_FAILED; - } - } - - //deal with guids - if (!dealWithGuids()) { - return FLINT_FAILED; - } - - //deal with failsifity should be made in fwops as we dont know if image/device fw is failsafe - if (_burnParams.burnFailsafe & (!_imgInfo.fw_info.is_failsafe || !_devInfo.fw_info.is_failsafe)) { - - if ((!_imgInfo.fw_info.is_failsafe && !_devInfo.fw_info.is_failsafe)) { - // When both image and flash are non-failsafe, flint will burn in a non-failsafe mode - _burnParams.burnFailsafe = false; - } else { - // when only one of image and flash is non-failsafe, flint will fail with appropriate message - reportErr(true, "Failsafe burn failed: FW image in the %s is non failsafe.\n" - " you cannot burn a%s failsafe image over a%s failsafe image in a failsafe mode.\n" - " If you want to burn in non failsafe mode, use the \"-nofs\" switch.\n", - _imgInfo.fw_info.is_failsafe ? "flash" : "given file", _imgInfo.fw_info.is_failsafe? "" : " non",\ - _devInfo.fw_info.is_failsafe ? "" : " non"); - return FLINT_FAILED; - } - } - - //deal with vsd - if (!dealWithVSD()) { - return FLINT_FAILED; - } - - //check versions - if (!checkFwVersion()) { - return FLINT_BURN_ABORTED; - } - //check Psid - if (_devQueryRes && !checkPSID()) { - return FLINT_FAILED; - } - - // Warn if a fw which does not support config is burnt over fw that does support config - // The other way (new fw with config, old fw w/o config) is a normal update flow. - // Update: all fw should now support config sectors, so we just check any missmatch in the config pads - - - // Verify config offset. Should never be different between image and flash (unless changing PSID). - if (_imgInfo.fs2_info.config_pad != _devInfo.fs2_info.config_pad) { - printf("\n"); - printf("-W- Configuration section offset on flash (%u sectors) differs from the" - " Configuration section offset in the given image (%u sectors)." - " Current device configuration (if exists) will be deleted.\n", - _devInfo.fs2_info.config_pad, - _imgInfo.fs2_info.config_pad); - if (_burnParams.allowPsidChange) { - if (!askUser()) { - return FLINT_FAILED; - } - } else { - reportErr(true, "Use the '-allow_psid_change' flag to force this change.\n"); - return FLINT_FAILED; - } - } - - if (!_burnParams.burnFailsafe) { - printf("Burn process will not be failsafe. No checks will be performed.\n"); - printf("ALL flash, including the Invariant Sector will be overwritten.\n"); - printf("If this process fails, computer may remain in an inoperable state.\n"); - if (!askUser()) { - return FLINT_FAILED; - } - } - - //Finally we can burn - if (!_fwOps->FwBurnAdvanced(_imgOps, _burnParams)) - { - reportErr(true, FLINT_FS2_BURN_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - PRINT_PROGRESS(_burnParams.progressFunc, 101); - write_result_to_log(FLINT_SUCCESS, "", _flintParams.log_specified); - return FLINT_SUCCESS; -} - -bool BurnSubCommand::dealWithVSD() -{ - if (!(_burnParams.vsdSpecified || _burnParams.useImagePs) && !((strlen(_devInfo.fw_info.psid) != 0 \ - && _devInfo.fw_info.vsd_sect_found))) { - printf("\n"); - if (_burnParams.burnFailsafe) { - reportErr(true, "Can not extract VSD/PSID info from flash.\n" - " Can not burn in a failsafe mode. Please use \"-nofs\" flag to burn in a non failsafe mode.\n"); - return false; - } else { - printf("-W- Can not extract VSD/PSID info from flash.\n\n" - " To use a specific VSD, abort and re-burn specifying the\n" - " needed info (using command line flags -vsd / -use_image_ps).\n" - " You can also continue burn using blank VSD.\n"); - if (!askUser()) { - return false; - } - } - } - return true; -} - -bool BurnSubCommand::dealWithGuids() -{ - bool read_guids = true; - bool ib_dev; - bool eth_dev; - // Get the FW types - FwOperations::SetDevFlags(_imgInfo.fw_info.chip_type, _imgInfo.fw_info.dev_type, (fw_img_type)_imgInfo.fw_type, ib_dev, eth_dev); - //setDevFlags(_imgInfo, ib_dev, eth_dev); - - // Check if there is a need to read guids - if (_burnParams.useImageGuids || _burnParams.blankGuids - || (_burnParams.userGuidsSpecified && ib_dev) - || (_burnParams.userMacsSpecified)) { - read_guids = false; - } - // Check if the burnt FW is ok and readable in order to get the GUIDs later - if (read_guids && !_devQueryRes) { - //printMissingGuidErr(ib_dev, eth_dev); - if (_burnParams.burnFailsafe) { - reportErr(true, - "Can not extract GUIDs/MACs info from flash, %s\n" - " Can not burn in a failsafe mode.\n" - " If you want to burn in non failsafe mode, use the \"-nofs\" switch.\n", _fwOps->err()); - } else { - reportErr(true, "Can not extract GUIDs/MACs info from flash, %s", _fwOps->err()); - printMissingGuidErr(ib_dev, eth_dev); - } - return false; - } - // Check guids flag to ensure correct patching of guids in mlxfwops - bool is_guids_specified = _burnParams.userGuidsSpecified - || _burnParams.userMacsSpecified - || _burnParams.userUidSpecified; - if (is_guids_specified) { - if (!checkGuidsFlags( _imgInfo.fw_info.dev_type, _fwType,\ - _burnParams.userGuidsSpecified, _burnParams.userMacsSpecified, _burnParams.userUidSpecified, ib_dev, eth_dev)) { - return false; - } - } - //report guid changes if needed. and update the user_guids vector in _burnParams - if (is_guids_specified || _flintParams.use_image_guids) { - guid_t* new_guids = ( _burnParams.userGuidsSpecified || _burnParams.userUidSpecified )?\ - &_burnParams.userUids[0] : _devInfo.fs2_info.guids; - guid_t* new_macs = _burnParams.userMacsSpecified != 0 ? &_burnParams.userUids[GUIDS] : &_devInfo.fs2_info.guids[GUIDS]; - guid_t* old_guids = !_devQueryRes ? NULL : _devInfo.fs2_info.guids; - guid_t* old_macs = old_guids != NULL ? &old_guids[GUIDS] : NULL; - if (!is_guids_specified && _flintParams.use_image_guids) { - new_guids = _imgInfo.fs2_info.guids; - new_macs = &_imgInfo.fs2_info.guids[GUIDS]; - } - //printf("-D- l=%d, h=%d\n", new_macs->l, new_macs->h); - if (!reportGuidChanges(new_guids, new_macs, old_guids, old_macs, ib_dev,\ - eth_dev, _imgInfo.fs2_info.guid_num)) { - return false; - } - - } - return true; -} - -#define IS_HCA(chipType) \ - (((chipType) == CT_CONNECTX) || ((chipType) == CT_CONNECT_IB) || ((chipType) == CT_CONNECTX4) || ((chipType) == CT_CONNECTX4_LX) || ((chipType) == CT_CONNECTX5)) - -void BurnSubCommand::dealWithExpRom() -{ - bool getRomFromDev = false; - // Check exp rom: - bool fs2Cond = _fwType == FIT_FS2? (_devQueryRes && IS_HCA(_devInfo.fw_info.chip_type) && \ - (FwOperations::IsFwSupportingRomModify(_devInfo.fw_info.fw_ver) || (_imgInfo.fw_info.roms_info.num_of_exp_rom > 0))\ - && !_flintParams.use_image_rom && !strcmp(_devInfo.fw_info.product_ver,"") && !strcmp(_imgInfo.fw_info.product_ver, "")) : false; - - bool fs3Cond = _fwType == FIT_FS3 ? (_devQueryRes && IS_HCA(_devInfo.fw_info.chip_type) && \ - (FwOperations::IsFwSupportingRomModify(_devInfo.fw_info.fw_ver) || (_imgInfo.fw_info.roms_info.num_of_exp_rom > 0))\ - && !_flintParams.use_image_rom) && !strcmp(_devInfo.fw_info.product_ver,"") && !strcmp(_imgInfo.fw_info.product_ver, "") : false; - - bool cond = _fwType == FIT_FS2 ? fs2Cond : fs3Cond; - - if (cond) { - // Enter here when: - // The fw on the flash is OK (passed query, and it should pass verify in mlxfwops) && - // ( The device is connectx || connectib )&& - // The image fw supports modifying ROM OR it contains ROM &&. - // The user didn't ask to burn the image rom. && - // The fw on the flash doesn't contain product version - - if (_imgInfo.fw_info.roms_info.num_of_exp_rom > 0 && _devInfo.fw_info.roms_info.num_of_exp_rom > 0) { - printf("\n Note: Both the image file and the flash contain a ROM image.\n" - " Select \"yes\" to use the ROM from the given image file.\n" - " Select \"no\" to keep the existing ROM in the flash\n"); - - displayExpRomInfo(_devInfo.fw_info.roms_info, " Current ROM info on flash: "); - displayExpRomInfo(_imgInfo.fw_info.roms_info, " ROM info from image file : "); - if (!askUser("Use the ROM from the image file", false)) { - getRomFromDev = true; - } else { - getRomFromDev = false; - } - } else if (!(_imgInfo.fw_info.roms_info.num_of_exp_rom > 0) && _devInfo.fw_info.roms_info.num_of_exp_rom > 0) { - getRomFromDev = true; - } - } - if (getRomFromDev) { - _burnParams.burnRomOptions = FwOperations::ExtBurnParams::BRO_FROM_DEV_IF_EXIST; - } - return; -} - -bool BurnSubCommand::checkMatchingExpRomDevId(const fw_info_t& info) -{ - if ((info.fw_info.roms_info.num_of_exp_rom > 0) && (info.fw_info.dev_type) - && (info.fw_info.roms_info.exp_rom_com_devid != EXP_ROM_GEN_DEVID) \ - && (info.fw_info.roms_info.exp_rom_com_devid != MISS_MATCH_DEV_ID) - && (info.fw_info.dev_type != info.fw_info.roms_info.exp_rom_com_devid)) { - return false; - } - return true; -} - -FlintStatus BurnSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - //set fw type - _fwType = _fwOps->FwType(); - // query both image and device (deviceQuery can fail but we save rc) - _devQueryRes = _fwOps->FwQuery(&_devInfo); - if (!_imgOps->FwQuery(&_imgInfo)) - { - reportErr(true, FLINT_FAILED_QUERY_ERROR, "image", _flintParams.image.c_str(), _imgOps->err()); - return FLINT_FAILED; - } - //updateBurnParams with input given by user - updateBurnParams(); - if (_fwType == FIT_FS3 || _fwType == FIT_FS4) { - - return burnFs3();//CodeView: change the name of this function - } else if (_fwType == FIT_FS2) { - return burnFs2(); - } - // unknown fw type - reportErr(true, FLINT_UNKNOWN_FW_TYPE_ERROR); - return FLINT_FAILED; -} - -/*********************** - *Class: QuerySubCommand - **********************/ - -bool QuerySubCommand::verifyParams() -{ - if (_flintParams.cmd_params.size() > 1) - { - reportErr(true, FLINT_CMD_ARGS_ERROR,_name.c_str(), 1, (int)_flintParams.cmd_params.size()); - return false; - } - if ((_flintParams.cmd_params.size() == 1) && _flintParams.cmd_params[0] != "full") - { - reportErr(true, FLINT_INVALID_OPTION_ERROR, _flintParams.cmd_params[0].c_str(), _name.c_str(), "full"); - return false; - } - return true; -} - -bool QuerySubCommand::checkMac(u_int64_t mac, string& warrStr) { - if ((mac >> 40) & 0x1) { - - warrStr = FLINT_MULTI_BIT_WARNING; - return false; - } - - if (mac >> 48) { - warrStr = FLINT_MORE_48_BITS_WARNING; - return false; - } - - return true; -} - -bool QuerySubCommand::displayFs2Uids(const fw_info_t& fwInfo) -{ - const char* mac_indent = ""; - bool ibDev; - bool ethDev; - FwOperations::SetDevFlags(fwInfo.fw_info.chip_type, fwInfo.fw_info.dev_type, (fw_img_type)fwInfo.fw_type, ibDev, ethDev); - //setDevFlags(fwInfo, ibDev, ethDev); - int numPorts = 2; - if ((fwInfo.fw_info.chip_type == CT_IS4 || fwInfo.fw_info.chip_type == CT_SWITCHX)) { - numPorts = 0; - } - //we do not support cards with one port anymore. - - // GUIDS: - if (ibDev) { - //report("GUID Des: Node Port1 "); - printf("Description: Node "); - if (numPorts > 0) - printf("Port1 "); - if (numPorts > 1) - printf("Port2 "); - printf( "Sys image\n"); - - printf("GUIDs: "); - for (u_int32_t i=0; i < GUIDS; i++) { - if ((i == 1 && numPorts < 1) || - (i == 2 && numPorts < 2)) { - continue; - } - printf(GUID_FORMAT " ", fwInfo.fs2_info.guids[i].h, fwInfo.fs2_info.guids[i].l); - } - if (numPorts > 0) { - mac_indent = " "; - } - } - // MACS: - if (ethDev) { - if (fwInfo.fs2_info.guid_num == 6) { - if (!ibDev) { - printf("Description:%s Port1 Port2\n", mac_indent); - } else if (fwInfo.fw_info.chip_type == CT_SWITCHX) { - printf("\nDescription: Base Switch\n"); - } else { - printf("\n"); - } - printf("MACs: %s ", mac_indent); - for (u_int32_t i=GUIDS; i < 6; i++) { - printf(" " MAC_FORMAT , fwInfo.fs2_info.guids[i].h, fwInfo.fs2_info.guids[i].l); - } - - for (u_int32_t i=GUIDS; i < 6; i++) { - u_int64_t mac = (((u_int64_t)fwInfo.fs2_info.guids[i].h) << 32) | fwInfo.fs2_info.guids[i].l; - string warrStr; - if (!fwInfo.fs2_info.blank_guids && !checkMac(mac, warrStr)) { - if (i==GUIDS) printf("\n\n"); - printf(FLINT_BAD_MAC_ADRESS_WARNING, fwInfo.fs2_info.guids[i].h, fwInfo.fs2_info.guids[i].l, warrStr.c_str()); - } - } - } else { - printf(FLINT_MAC_ENTRIES_WARNING, 6, fwInfo.fs2_info.guid_num); - } - } - - printf("\n"); - return true; -} - -#define BASE_STR "Base" -#define PRINT_FS3_UID(uid1, str, printStep) \ - printf("%-16s %016" U64H_FMT_GEN " %d", str, uid1.uid, uid1.num_allocated);\ - if (printStep) {\ - printf(" %d", uid1.step);\ - }\ - printf("\n"); - -static inline void printFs3Uids(struct fs3_uid_entry uid, struct fs3_uid_entry orig_uid, string guidMac, bool printStep) -{ - string prefix = BASE_STR + string(" ") + guidMac + ":"; - PRINT_FS3_UID(uid, prefix.c_str(), printStep); - if (uid.uid != orig_uid.uid || uid.num_allocated != orig_uid.num_allocated || ( printStep && uid.step != orig_uid.step)) { - // Print MFG UIDs as well - prefix = "Orig " + prefix; - PRINT_FS3_UID(orig_uid, prefix.c_str(), printStep); - } -} - -bool QuerySubCommand::displayFs3Uids(const fw_info_t& fwInfo) -{ - if (fwInfo.fs3_info.fs3_uids_info.valid_field) { - // new GUIDs format - printf("Description: UID GuidsNumber\n"); - printFs3Uids(fwInfo.fs3_info.fs3_uids_info.cx4_uids.base_guid, fwInfo.fs3_info.orig_fs3_uids_info.cx4_uids.base_guid, "GUID", false); - printFs3Uids(fwInfo.fs3_info.fs3_uids_info.cx4_uids.base_mac, fwInfo.fs3_info.orig_fs3_uids_info.cx4_uids.base_mac, "MAC", false); - } else { - printf("Description: UID GuidsNumber Step\n"); - string firstGuid = (fwInfo.fw_info.chip_type != CT_SWITCH_IB) ? "GUID1" : "GUID"; - string firstMac = (fwInfo.fw_info.chip_type != CT_SWITCH_IB) ? "MAC1" : "MAC"; - - printFs3Uids(fwInfo.fs3_info.fs3_uids_info.cib_uids.guids[0], fwInfo.fs3_info.orig_fs3_uids_info.cib_uids.guids[0], firstGuid, true); - if (fwInfo.fw_info.chip_type != CT_SWITCH_IB) { - printFs3Uids(fwInfo.fs3_info.fs3_uids_info.cib_uids.guids[1], fwInfo.fs3_info.orig_fs3_uids_info.cib_uids.guids[1], "GUID2", true); - } - printFs3Uids(fwInfo.fs3_info.fs3_uids_info.cib_uids.macs[0], fwInfo.fs3_info.orig_fs3_uids_info.cib_uids.macs[0], firstMac, true); - if (fwInfo.fw_info.chip_type != CT_SWITCH_IB) { - printFs3Uids(fwInfo.fs3_info.fs3_uids_info.cib_uids.macs[1], fwInfo.fs3_info.orig_fs3_uids_info.cib_uids.macs[1], "MAC2", true); - } - } - return true; -} - - - -FlintStatus QuerySubCommand::printInfo(const fw_info_t& fwInfo, bool fullQuery) -{ - //char imageTypeStr[4] = {'\0', '\0', '\0', '\0'}; - bool isFs2 = (fwInfo.fw_type == FIT_FS2) ? true : false; - bool isFs3 = (fwInfo.fw_type == FIT_FS3) ? true : false; - bool isFs4 = (fwInfo.fw_type == FIT_FS4) ? true : false; - - /*switch(fwInfo.fw_type){ - case FIT_FS2: - snprintf(imageTypeStr, 4, "FS2"); - break; - case FIT_FS3: - snprintf(imageTypeStr, 4, "FS3"); - break; - case FIT_FS4: - snprintf(imageTypeStr, 4, "FS4"); - break; - }*/ - printf("Image type: %s\n", isFs2 ? "FS2" : (isFs3 ? "FS3" : isFs4 ? "FS4" : "Unknown")); - - if (fwInfo.fw_info.fw_ver[0] || fwInfo.fw_info.fw_ver[1] || fwInfo.fw_info.fw_ver[2]) { - char versionStr[64] = {0}; - snprintf(versionStr, 64, VERSION_FORMAT(fwInfo.fw_info.fw_ver[1]), fwInfo.fw_info.fw_ver[0], fwInfo.fw_info.fw_ver[1], - fwInfo.fw_info.fw_ver[2]); - printf("FW Version: %s\n", versionStr); - if ((fwInfo.fw_info.running_fw_ver[0] || fwInfo.fw_info.running_fw_ver[1] || fwInfo.fw_info.running_fw_ver[2]) && \ - (fwInfo.fw_info.running_fw_ver[0] != fwInfo.fw_info.fw_ver[0] || \ - fwInfo.fw_info.running_fw_ver[1] != fwInfo.fw_info.fw_ver[1] || \ - fwInfo.fw_info.running_fw_ver[2] != fwInfo.fw_info.fw_ver[2])) { - snprintf(versionStr, 64, VERSION_FORMAT(fwInfo.fw_info.running_fw_ver[1]), fwInfo.fw_info.running_fw_ver[0], fwInfo.fw_info.running_fw_ver[1], - fwInfo.fw_info.running_fw_ver[2]); - printf("FW Version(Running): %s\n", versionStr); - } - } - - if (fwInfo.fw_info.fw_rel_date[0] || fwInfo.fw_info.fw_rel_date[1] || fwInfo.fw_info.fw_rel_date[2]) { - printf("FW Release Date: %x.%x.%x\n", fwInfo.fw_info.fw_rel_date[0], fwInfo.fw_info.fw_rel_date[1],\ - fwInfo.fw_info.fw_rel_date[2]); - } - - if (fullQuery) { // there is no full query atm just quick query - if (fwInfo.fw_info.min_fit_ver[0] || fwInfo.fw_info.min_fit_ver[1]\ - || fwInfo.fw_info.min_fit_ver[2]||fwInfo.fw_info.min_fit_ver[3]) { - printf("Min FIT Version: %d.%d.%d.%d\n", fwInfo.fw_info.min_fit_ver[0],\ - fwInfo.fw_info.min_fit_ver[1], fwInfo.fw_info.min_fit_ver[2], fwInfo.fw_info.min_fit_ver[3]); - } - if ((fwInfo.fw_info.mic_ver[0] || fwInfo.fw_info.mic_ver[1] || fwInfo.fw_info.mic_ver[2])) { - printf("MIC Version: %d.%d.%d\n", fwInfo.fw_info.mic_ver[0],\ - fwInfo.fw_info.mic_ver[1], fwInfo.fw_info.mic_ver[2]); - } - if (isFs2) { - if (fwInfo.fs2_info.config_sectors) { - printf("Config Sectors: %d\n", fwInfo.fs2_info.config_sectors); - } - if (fwInfo.fs2_info.config_pad) { - printf("Config Pad: %d\n", fwInfo.fs2_info.config_pad); - } - if (strlen(fwInfo.fs2_info.prs_name)) { - printf("PRS Name: %s\n", fwInfo.fs2_info.prs_name); - } - } else { // FS3 - if (strlen(fwInfo.fs3_info.prs_name)) { - printf("PRS Name: %s\n", fwInfo.fs3_info.prs_name); - } - if (strlen(fwInfo.fs3_info.orig_prs_name)) { - printf("Orig PRS Name: %s\n", fwInfo.fs3_info.orig_prs_name); - } - if (strlen(fwInfo.fs3_info.name)) { - printf("Part Number: %s\n", fwInfo.fs3_info.name); - } - if (strlen(fwInfo.fs3_info.description)) { - printf("Description: %s\n", fwInfo.fs3_info.description); - } - } - } - - if (strlen(fwInfo.fw_info.product_ver)) { - printf("Product Version: %s\n", fwInfo.fw_info.product_ver); - } - - if (fwInfo.fw_info.roms_info.exp_rom_found) { - displayExpRomInfo(fwInfo.fw_info.roms_info, "Rom Info: "); - } - - if (isFs2) - { - printf("Device ID: %d\n", fwInfo.fw_info.dev_type); - } - - if (isFs2 && fwInfo.fs2_info.access_key_exists) { - printf("HW Access Key: "); - if (fwInfo.fs2_info.access_key_value.l || fwInfo.fs2_info.access_key_value.h) { - printf("Enabled\n"); - } else { - printf("Disabled\n"); - } - } - - if (!isFs2)/*i.e its fs3*/{ - if (!displayFs3Uids(fwInfo)) { - return FLINT_FAILED; - } - } else { - if (!displayFs2Uids(fwInfo)) { - return FLINT_FAILED; - } - } - - // VSD, PSID - if (!fwInfo.fw_info.vsd_vendor_id || fwInfo.fw_info.vsd_vendor_id == MELLANOX_VENDOR_ID) { - if (!isFs2) { - printf("Image VSD: %s\n", fwInfo.fs3_info.image_vsd); - printf("Device VSD: %s\n", fwInfo.fw_info.vsd); - printf("PSID: %s\n", fwInfo.fw_info.psid); - if (strncmp(fwInfo.fw_info.psid, fwInfo.fs3_info.orig_psid, 13) != 0) { - printf("Orig PSID: %s\n", fwInfo.fs3_info.orig_psid); - } - } else { - printf("VSD: %s\n", fwInfo.fw_info.vsd); - printf("PSID: %s\n", fwInfo.fw_info.psid); - } - } else { - printf(FLINT_NOT_MLNX_FW_WARNING, fwInfo.fw_info.vsd_vendor_id); - } - - if (isFs2 && fwInfo.fs2_info.blank_guids) { //blankGuids only exsists in FS2 image type in mlxfwops why? - printf(FLINT_BLANK_GUIDS_WARNING); - } - return FLINT_SUCCESS; -} - -QuerySubCommand:: QuerySubCommand() -{ - _name = "query"; - _desc = "Query misc. flash/firmware characteristics, use \"full\"\n" - INDENT"to get more information."; - _extendedDesc = "Query miscellaneous FW and flash parameters \n" - INDENTEX "Display FW Version, GUIDs, PSID, and other info"; - _flagLong = "query"; - _flagShort = "q"; - _param = "[full]"; - _paramExp = "None"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " query"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _cmdType = SC_Query; -} - -QuerySubCommand:: ~QuerySubCommand() -{ - -} - -FlintStatus QuerySubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - fw_info_t fwInfo; - FwOperations* ops; - bool fullQuery = false; - //check on what we are wroking - ops = (_flintParams.device_specified) ? _fwOps : _imgOps; - if (!ops->FwQuery(&fwInfo, true, _flintParams.striped_image)) - { - reportErr(true, FLINT_FAILED_QUERY_ERROR,_flintParams.device_specified? "Device" : "image", - _flintParams.device_specified? _flintParams.device.c_str() : _flintParams.image.c_str(), ops->err()); - return FLINT_FAILED; - } - //print fw_info nicely to the user - // we actually dont use "regular" query , just quick - //ORENK - no use to display quick query message to the user if we dont do it in any other way - if (_flintParams.cmd_params.size() == 1) { - fullQuery=true; - } - return printInfo(fwInfo, fullQuery); -} - -/*********************** - *Class: VerifySubCommand - ***********************/ -VerifySubCommand:: VerifySubCommand() -{ - _name = "verify"; - _desc = "Verify entire flash, use \"showitoc\" to see ITOC headers\n" - INDENT"in FS3 image only."; - _extendedDesc = "Verify entire flash."; - _flagLong = "verify"; - _flagShort = "v"; - _param = "[showitoc]"; - _paramExp = "None"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " v"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _cmdType = SC_Verify; -} - -VerifySubCommand:: ~VerifySubCommand() -{ - -} - -bool VerifySubCommand::verifyParams() -{ - - if (_flintParams.cmd_params.size() > 1) - { - reportErr(true, FLINT_CMD_ARGS_ERROR,_name.c_str(), 0, (int)_flintParams.cmd_params.size()); - return false; - } - if ((_flintParams.cmd_params.size() == 1) && _flintParams.cmd_params[0] != "showitoc") - { - reportErr(true, FLINT_INVALID_OPTION_ERROR, _flintParams.cmd_params[0].c_str(), _name.c_str(), "swhoitoc"); - return false; - } - - return true; -} - - - - -FlintStatus VerifySubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - FwOperations* ops; - bool showItoc = (_flintParams.cmd_params.size() == 1) ? true : false; - //check on what we are wroking - ops = (_flintParams.device_specified) ? _fwOps : _imgOps; - if (!ops->FwVerify(&verifyCbFunc, _flintParams.striped_image, showItoc)) { - printf("\n\n"); - reportErr(true, FLINT_CMD_VERIFY_ERROR, ops->err()); - - return FLINT_FAILED; - } - //get status of blank guids in fs2 only can either bring from FwVerify as another parameter. ask mohammad - if (ops->FwType() == FIT_FS2) { - fw_info_t fwInfo; - if (!ops->FwQuery(&fwInfo, true, _flintParams.striped_image)) { - printf("\n\n"); - reportErr(true, "Failed to get Guids status. %s\n", ops->err()); - return FLINT_FAILED; - } - if (fwInfo.fs2_info.blank_guids) { - printf("\n\n"); - reportErr(true, FLINT_CMD_VERIFY_ERROR, "BLANK GUIDS"); - return FLINT_FAILED; - } - } - printf("\n-I- FW image verification succeeded. Image is bootable.\n\n"); - return FLINT_SUCCESS; -} - -/*********************** - *Class: SwResetSubCommand - **********************/ -SwResetSubCommand:: SwResetSubCommand() { - _name = "swreset"; - _desc = "SW reset the target un-managed switch device. This command\n" - INDENT"is supported only in the In-Band access method."; - _extendedDesc = "SW reset the target un-managed switch device. This command\n" - INDENTEX "is supported only in the In-Band access method."; - _flagLong = "swreset"; - _flagShort = ""; - _param = ""; - _paramExp = "None"; - _example = "None"; - _v = Wtv_Dev; - _maxCmdParamNum = 0; - _cmdType = SC_Swreset; -} - -SwResetSubCommand:: ~SwResetSubCommand() { - -} - - -bool SwResetSubCommand::verifyParams() { - if (_flintParams.cmd_params.size() != 0) { - reportErr(true, FLINT_CMD_ARGS_ERROR,_name.c_str() , 0, (int)_flintParams.cmd_params.size()); - return false; - } - return true; -} - -FlintStatus SwResetSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - printf("-I- Resetting device %s ...\n", _flintParams.device.c_str()); - if (!_fwOps->FwSwReset()) { - reportErr(true, FLINT_SWRESET_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/*********************** - *Class: BromSubCommand - **********************/ -BromSubCommand:: BromSubCommand() -{ - _name = "brom"; - _desc = "Burn the specified ROM file on the flash."; - _extendedDesc = "Burn the specified exp-ROM on the flash."; - _flagLong = "brom"; - _flagShort = ""; - _param = ""; - _paramExp = "file: The exp-ROM file."; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " brom exp-rom.rom"; - _v = Wtv_Dev_Or_Img; - _cmdType = SC_Brom; - _maxCmdParamNum = 1; - _minCmdParamNum = 1; - memset(&_info, 0, sizeof(_info)); - memset(&_romsInfo, 0, sizeof(_romsInfo)); -} - -BromSubCommand:: ~BromSubCommand() -{ - closeLog(); - _fRom.close(); -} - - -bool BromSubCommand::getExpRomStrVer(roms_info_t& roms_info, char* version) { - if (roms_info.rom_info[0].exp_rom_product_id >= 0x10) { - sprintf(version, "%d.%d.%d", roms_info.rom_info[0].exp_rom_ver[0], roms_info.rom_info[0].exp_rom_ver[1], - roms_info.rom_info[0].exp_rom_ver[2]); - } else { - sprintf(version, "%d", roms_info.rom_info[0].exp_rom_ver[0]); - } - return true; -} - - -FlintStatus BromSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - - FwOperations *ops = _flintParams.device_specified ? _fwOps : _imgOps; - // query device - if (!ops->FwQuery(&_info)) { - reportErr(true, FLINT_FAILED_QUERY_ERROR, "Device", _flintParams.device.c_str(), - ops->err()); - return FLINT_FAILED; - } - // get roms info - if (!_fRom.open(_flintParams.cmd_params[0].c_str())) { - reportErr(true, FLINT_BROM_ERROR, _fRom.err()); - return FLINT_FAILED; - } - if (!getRomsInfo(&_fRom, _romsInfo)) { - return FLINT_FAILED; - } - //check devids - if ((_romsInfo.num_of_exp_rom > 0) && (_info.fw_info.dev_type) - && (_romsInfo.exp_rom_com_devid != EXP_ROM_GEN_DEVID) \ - && (_romsInfo.exp_rom_com_devid != MISS_MATCH_DEV_ID) - && (_info.fw_info.dev_type != _romsInfo.exp_rom_com_devid)) { - printf("-W- Image file ROM: FW is for device %d, but Exp-ROM is for device %d\n",\ - _info.fw_info.dev_type, _romsInfo.exp_rom_com_devid); - if (!askUser()) { - return FLINT_FAILED; - } - } - char romVer1[50], romVer2[50]; - printf("\n"); - const char *infoStr = " Current ROM info on flash: "; - const char *infoStr2 = " New ROM info: "; - if (_info.fw_info.roms_info.num_of_exp_rom > 0) { - displayExpRomInfo(_info.fw_info.roms_info, infoStr); - getExpRomStrVer(_info.fw_info.roms_info, romVer1); - } else { - printf("%s", infoStr); - snprintf(romVer1, 50, "N/A"); - printf("%s\n", romVer1); - } - displayExpRomInfo(_romsInfo, infoStr2); - getExpRomStrVer(_romsInfo, romVer2); - //add new line to space up before showing burn precentage - printf("\n"); - //print correct msg to log - if (_info.fw_info.roms_info.num_of_exp_rom != 0) { - print_line_to_log("Current ROM version on flash (1st ROM of %d): %s, New ROM version (1st ROM of %d): %s\n",\ - _info.fw_info.roms_info.num_of_exp_rom, romVer1, _romsInfo.num_of_exp_rom, romVer2); - } else { - print_line_to_log("Current ROM version on flash: %s, New ROM version(1st ROM of %d): %s\n",romVer1, _romsInfo.num_of_exp_rom, romVer2); - } - // burn the rom - printf("-I- Preparing to burn ROM ...\n"); - if (!ops->FwBurnRom(&_fRom, _flintParams.allow_rom_change, true, bromCbFunc)) { - reportErr(true, FLINT_BROM_ERROR, ops->err()); - return FLINT_FAILED; - } - bromCbFunc(101); - printf("\n"); - write_result_to_log(FLINT_SUCCESS, "", _flintParams.log_specified); - return FLINT_SUCCESS; -} - -/*********************** - *Class: Delete ROM - **********************/ -DromSubCommand:: DromSubCommand() -{ - _name = "drom"; - _desc = "Remove the ROM section from the flash."; - _extendedDesc = "Remove the exp-ROM from the flash if it is existing."; - _flagLong = "drom"; - _flagShort = ""; - _param = ""; - _paramExp = "None"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " drom"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 0; - _cmdType = SC_Drom; -} - -DromSubCommand:: ~DromSubCommand() -{ - -} - -bool DromSubCommand::verifyParams() -{ - if (_flintParams.cmd_params.size() != 0) { - reportErr(true, FLINT_CMD_ARGS_ERROR,_name.c_str() , 0, (int)_flintParams.cmd_params.size()); - return false; - } - return true; -} - -FlintStatus DromSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - // leave an empty line before printing from callback - FwOperations *ops = _flintParams.device_specified ? _fwOps : _imgOps; - - printf("\n"); - printf("-I- Preparing to remove ROM ...\n"); - if(!ops->FwDeleteRom(_flintParams.allow_rom_change, dromCbFunc)) { - reportErr(true, FLINT_DROM_ERROR, ops->err()); - return FLINT_FAILED; - } - dromCbFunc(101); - return FLINT_SUCCESS; -} -/*********************** - *Class: Read ROM - **********************/ -RromSubCommand:: RromSubCommand() -{ - _name = "rrom"; - _desc = "Read the ROM section from the flash."; - _extendedDesc = "Read the exp-ROM from the flash if it is existing."; - _flagLong = "rrom"; - _flagShort = ""; - _param = ""; - _paramExp = "file: filename to write the exp-ROM to."; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " rrom exp-rom.rom"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _minCmdParamNum = 1; - _cmdType = SC_Rrom; -} - -RromSubCommand:: ~RromSubCommand() -{ - -} - -bool RromSubCommand::verifyParams() -{ - FILE * file; - if ((file = fopen(_flintParams.cmd_params[0].c_str(), "r")) != NULL) { - fclose(file); - printf( - "\n-W- The given ROM file is existing, you are going to overwrite it.\n"); - if (!askUser()) { - return false; - } - } - return true; -} - -FlintStatus RromSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - //get the rom sector if present. - std::vector romSect; - FwOperations* ops = _flintParams.device_specified ? _fwOps : _imgOps; - if (!ops->FwReadRom(romSect)) { - reportErr(true, FLINT_READ_ROM_ERROR, ops->err()); - return FLINT_FAILED; - } - //TOCPUn(&(romSect[0]), romSect.size()/4); - if (!writeToFile(_flintParams.cmd_params[0], romSect)) { - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - - - -/*********************** - *Class: - **********************/ -BbSubCommand:: BbSubCommand() -{ - _name = "bb"; - _desc = "Burn Block - Burns the given image as is. No checks are done."; - _extendedDesc = "Burns entire flash verbatim from raw binary image. No checks are done on the flash or\n" - INDENTEX "on the given image file. No fields (such as VSD or Guids) are read from flash."; - _flagLong = "bb"; - _flagShort = ""; - _param = ""; - _paramExp = "None"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " -i image1.bin bb"; - _v = Wtv_Dev_And_Img; - _maxCmdParamNum = 0; - _cmdType = SC_Bb; -} - -BbSubCommand:: ~BbSubCommand() -{ - closeLog(); -} - -bool BbSubCommand:: verifyParams() -{ - if (_flintParams.cmd_params.size() != 0) { - reportErr(true, FLINT_CMD_ARGS_ERROR, _name.c_str(), 0, (int)(_flintParams.cmd_params.size())); - return false; - } - return true; -} - -FlintStatus BbSubCommand:: executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - if (_fwOps->FwType() == FIT_FS3) { - reportErr(true, FLINT_FS3_BB_ERROR); - return FLINT_FAILED; - } - - - printf("\n"); - printf("Block burn: The given image will be burnt as is. No fields (such\n"); - printf("as GUIDS,VSD) are taken from current image on flash.\n"); - printf("Burn process will not be failsafe. No checks will be performed.\n"); - printf("ALL flash, including the Invariant Sector will be overwritten.\n"); - printf("If this process fails, computer may remain in an inoperable state.\n"); - if (!askUser()) { - return FLINT_FAILED; - } - ProgressCallBack progressFunc = _flintParams.silent == true ? (ProgressCallBack)NULL : &burnBCbFunc; - if (!_fwOps->FwBurnBlock(_imgOps, progressFunc)) { - reportErr(true, "Non failsafe burn failed: %s\n", _fwOps->err()); - return FLINT_FAILED; - } - printf("\n"); - write_result_to_log(FLINT_SUCCESS, "", _flintParams.log_specified); - return FLINT_SUCCESS; -} - -/*********************** - *Class: - **********************/ -SgSubCommand:: SgSubCommand() -{ - _name = "sg"; - _desc = "Set GUIDs."; - _extendedDesc = "Set GUIDs/MACs/UIDs in the given device/image.\n" - INDENTEX "Use -guid(s), -mac(s) and -uid(s) flags to set the desired values.\n" - INDENTEX "- On pre-ConnectX devices, the sg command is used in production to apply GUIDs/MACs values\n" - INDENTEX "to cards that were pre-burnt with blank GUIDs. It is not meant for\n" - INDENTEX "use in field.\n" - INDENTEX "- On 4th generation devices, this command can operate on both image file and image on flash.\n" - INDENTEX "If the GUIDs/MACs/UIDs in the image on flash are non-blank,\n" - INDENTEX "flint will re-burn the current image using the given GUIDs/MACs/UIDs."; - _flagLong = "sg"; - _flagShort = ""; - _param = "[guids_num= step_size=] | [nocrc]"; - _paramExp = "nocrc: (optional) When specified the flint would not update\n" - INDENTEX "the full image crc after changing the guids\n" - INDENTEX "guids_num: (optional) number of GUIDs to be allocated per physical port (FS3 Only)\n" - INDENTEX "step_size: (optional) step size between GUIDs (FS3 Only)\n" - INDENTEX "Note: guids_num/step_size values can be specified per port or for both ports"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " -guid 0x0002c9000100d050 sg" - "\n" INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE4 " -guid 0x0002c9000100d050 -mac 0x0002c900d050 sg"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 2; - _cmdType = SC_Sg; - _ops = NULL; - memset(&_info, 0, sizeof(_info)); - memset(&_sgParams, 0, sizeof(_sgParams)); - memset(&(_sgParams.numOfGUIDsPP), 0xff, sizeof(_sgParams.numOfGUIDsPP)); - memset(&(_sgParams.stepSizePP), 0xff, sizeof(_sgParams.stepSizePP)); - _sgParams.usePPAttr = true; -} - -SgSubCommand:: ~SgSubCommand() -{ - -} - -bool SgSubCommand::verifyParams() -{ - if ((_flintParams.cmd_params.size() == 1 && _flintParams.cmd_params[0] != "nocrc")||\ - (_flintParams.cmd_params.size() == 2 && \ - !extractUIDArgs(_flintParams.cmd_params, _sgParams.numOfGUIDsPP, _sgParams.stepSizePP))) { - reportErr(true, "The sg parameter should be \"nocrc\", \"guids_num= step_size=\" or nothing\n"); - return false; - } - - if (_flintParams.cmd_params.size()> 2) { - reportErr(true, FLINT_CMD_ARGS_ERROR2,_name.c_str(), 1, (int)_flintParams.cmd_params.size()); - return false; - } - if (!(_flintParams.guid_specified || _flintParams.guids_specified ||\ - _flintParams.uid_specified || \ - _flintParams.mac_specified || _flintParams.macs_specified)){ - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "GUIDs / MACs / UID (using command line flags -guid(s) / -mac(s) / -uid )"); - return false; - } - if ((_flintParams.guid_specified || _flintParams.guids_specified) && (_flintParams.uid_specified)) { - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "either GUIDs / UIDs (using command line flags -guid(s) / -uid )"); - return false; - } - if ((_flintParams.mac_specified || _flintParams.macs_specified) && (_flintParams.uid_specified)) { - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "either MACs / UIDs (using command line flags -mac(s) / -uid )"); - return false; - } - if (_flintParams.guid_specified && _flintParams.guids_specified) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "-guids", "-guid" ); - return false; - } - if (_flintParams.mac_specified && _flintParams.macs_specified) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "-macs", "-mac" ); - return false; - } - - _sgParams.guidsSpecified = _flintParams.guid_specified || _flintParams.guids_specified; - _sgParams.macsSpecified = _flintParams.mac_specified || _flintParams.macs_specified; - _sgParams.uidSpecified = _flintParams.uid_specified; - _sgParams.updateCrc = !(_flintParams.cmd_params.size() == 1); - _sgParams.stripedImage = _flintParams.striped_image; - return true; -} - -void SgSubCommand::setUserGuidsAndMacs() -{ - // _sgParams.userGuids contains either guids and macs (or just guids) or just uids - // we are required to specifiy to mlxfwops a guid vector of MAX_GUIDS size regardless if user gives only guids - // or only macs or uids - if ( _sgParams.guidsSpecified) { - - _sgParams.userGuids = _flintParams.user_guids; - } - if (_sgParams.macsSpecified) { - if (!_sgParams.guidsSpecified) { - //it inits the guids with zeroes but mlxfwops will set them to 0xffff - //can set default init if needed - _sgParams.userGuids.resize(GUIDS); - } - _sgParams.userGuids.push_back(_flintParams.user_macs[0]); - _sgParams.userGuids.push_back(_flintParams.user_macs[1]); - } - if (_sgParams.uidSpecified) { - _sgParams.userGuids.resize(0); - _sgParams.userGuids.push_back(_flintParams.baseUid); - } - _sgParams.userGuids.resize(MAX_GUIDS); -} - -bool SgSubCommand::CheckSetGuidsFlags() -{ - bool ibDev; - bool ethDev; - FwOperations::SetDevFlags(_info.fw_info.chip_type, _info.fw_info.dev_type, (fw_img_type)_info.fw_type, ibDev, ethDev); - //setDevFlags(_info, ibDev,ethDev); - - if (_sgParams.macsSpecified || _sgParams.guidsSpecified || _sgParams.uidSpecified) { - if (!checkGuidsFlags(_info.fw_info.dev_type,_info.fw_type,\ - _sgParams.guidsSpecified, _sgParams.macsSpecified, _sgParams.uidSpecified, ibDev, ethDev)) { - return false; - } - } else { - printf("-E- "); - printMissingGuidErr(ibDev, ethDev); - printf("\n"); - return false; - } - - return true; -} - -FlintStatus SgSubCommand::sgFs2() -{ - //different behaviours for fs2 device with blank guids and fs2 device with guids or image - //different behaviour if isfailesafe or not - if (_flintParams.cmd_params.size() > 1) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 1, _flintParams.cmd_params.size()); - } - - if (_flintParams.device_specified && !_info.fs2_info.blank_guids) { - // 2- FS2 device with no blank Guids - printf(FLINT_SET_GUIDS_WARRNING); - } - - if (!CheckSetGuidsFlags()){ - return FLINT_FAILED; - } - - if (_flintParams.image_specified || !_info.fs2_info.blank_guids) { - //report guid changes - bool ethDev; - bool ibDev; - FwOperations::SetDevFlags(_info.fw_info.chip_type, _info.fw_info.dev_type, (fw_img_type)_info.fw_type, ibDev, ethDev); - //setDevFlags(_info, ibDev, ethDev); - //decide what are our new guids/macs - guid_t *new_guids = (_sgParams.guidsSpecified ||_sgParams.uidSpecified) ? & _sgParams.userGuids[0] : &_info.fs2_info.guids[0] ; - guid_t *new_macs = _sgParams.macsSpecified ? &_sgParams.userGuids[GUIDS] : &_info.fs2_info.guids[GUIDS] ; - - if (!reportGuidChanges(new_guids, new_macs, &_info.fs2_info.guids[0], &_info.fs2_info.guids[GUIDS], ibDev,\ - ethDev, _info.fs2_info.guid_num)){ - return FLINT_FAILED; - } - } - if (!_ops->FwSetGuids(_sgParams, &verifyCbFunc, &burnCbFs2Func)) { - reportErr(true, FLINT_SG_GUID_ERROR, _ops->err()); - return FLINT_FAILED; - } - burnCbFs2Func(101); - return FLINT_SUCCESS; -} - -FlintStatus SgSubCommand::sgFs3() -{ - if (!CheckSetGuidsFlags()){ - return FLINT_FAILED; - } - if (_flintParams.guids_specified || _flintParams.macs_specified) { - reportErr(true, FLINT_NO_GUID_MAC_FLAGS_ERROR); - return FLINT_FAILED; - } - - // TODO: create method that checks the flags for FS3/FS2 - if (_info.fw_info.chip_type == CT_CONNECT_IB || _info.fw_info.chip_type == CT_SWITCH_IB || _info.fw_info.chip_type == CT_SWITCH_IB2) { - if (!_flintParams.uid_specified) { - reportErr(true, FLINT_NO_UID_FLAG_ERROR); - return FLINT_FAILED; - } - // for connectib we just need the base guid so we put it in the first location. - _sgParams.userGuids.resize(1); - _sgParams.userGuids[0]= _flintParams.baseUid; - } else { - if (!_flintParams.uid_specified && !_flintParams.guid_specified && !_flintParams.mac_specified) { - reportErr(true, FLINT_NO_GUID_MAC_FLAGS_ERROR); - return FLINT_FAILED; - } - if (_flintParams.uid_specified) { - _sgParams.userGuids.resize(1); - _sgParams.userGuids[0]= _flintParams.baseUid; - } else { - // guids and/or macs were specified - _sgParams.userGuids.resize(2); - _sgParams.userGuids[0]= _sgParams.guidsSpecified ? _flintParams.user_guids[0] : (guid_t){0, 0}; - _sgParams.userGuids[1]= _sgParams.macsSpecified ? _flintParams.user_macs[0] : (guid_t){0, 0}; - } - } - - if (!_ops->FwSetGuids(_sgParams, &verifyCbFunc)) { - reportErr(true, FLINT_SG_UID_ERROR, _ops->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -FlintStatus SgSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - // query device - _ops = _flintParams.device_specified ? _fwOps : _imgOps; - bool stripedImage = _flintParams.striped_image && _flintParams.image_specified; - if (!_ops->FwQuery(&_info, true, stripedImage)) { - reportErr(true, FLINT_SG_GUID_ERROR, _ops->err()); - return FLINT_FAILED; - } - setUserGuidsAndMacs(); - if (_info.fw_type == FIT_FS2) { - return sgFs2(); - } - return sgFs3(); -} - -/***************************** - *Class: Set Manufacture GUIDs - *****************************/ -SmgSubCommand:: SmgSubCommand() -{ - _name = "smg"; - _desc = "Set manufacture GUIDs (For FS3 image only)."; - _extendedDesc = "Set manufacture GUID, Set manufacture GUIDs in the given FS3 image.\n" - INDENTEX "Use -uid flag to set the desired GUIDs, intended for production use only."; - _flagLong = "smg"; - _flagShort = ""; - _param = "[guids_num= step_size=]"; - _paramExp = "guids_num: (optional) number of GUIDs to be allocated per physical port\n" - INDENTEX "step_size: (optional) step size between GUIDs\n" - INDENTEX "Note: guids_num/step_size values can be specified per port or for both ports"; - _example = FLINT_NAME " -i fw_image.bin -uid 0x0002c9000100d050 smg" -#ifndef __WIN__ - "\n" INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE3 " -uid 0x0002c9000100d050 smg (should be used when device is idle)" -#endif - "\n" INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE4 " -guid 0x0002c9000100d050 -mac 0x0002c900d050 smg (should be used when device is idle)"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 2; - _cmdType = SC_Smg; - _ops = NULL; - memset(&_baseGuid, 0, sizeof(_baseGuid)); - memset(&_info, 0, sizeof(_info)); - memset(&(_baseGuid.num_of_guids_pp), 0xff, sizeof(_baseGuid.num_of_guids_pp)); - memset(&(_baseGuid.step_size_pp), 0xff, sizeof(_baseGuid.step_size_pp)); - _baseGuid.use_pp_attr = 1; -} - -SmgSubCommand:: ~SmgSubCommand() -{ - -} - -bool SmgSubCommand::verifyParams() -{ - if (!_flintParams.uid_specified && !_flintParams.guid_specified && !_flintParams.mac_specified) { - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "\"-uid or -guid/-mac\" flags"); - return false; - } - if (_flintParams.guids_specified) { - reportErr(true, FLINT_INVALID_OPTION_ERROR, "\"-guids\"", _name.c_str(), "\"-guid\""); - return false; - } - if (_flintParams.macs_specified) { - reportErr(true, FLINT_INVALID_OPTION_ERROR, "\"-macs\"", _name.c_str(), "\"-mac\""); - return false; - } - if (_flintParams.uid_specified && (_flintParams.guid_specified || _flintParams.mac_specified)) { - reportErr(true, FLINT_INVALID_FLAG_WITH_FLAG_ERROR, "\"-uid\"", "\"-guid\"/-mac\""); - return false; - } - - if (_flintParams.cmd_params.size() != 0 && _flintParams.cmd_params.size() != 2) { - reportErr(true, FLINT_CMD_ARGS_ERROR4, _name.c_str(), 0, 2, _flintParams.cmd_params.size()); - return false; - } - - if (_flintParams.cmd_params.size() == 2 &&\ - !extractUIDArgs(_flintParams.cmd_params, _baseGuid.num_of_guids_pp, _baseGuid.step_size_pp)) { - return false; - } - - if (_flintParams.uid_specified) { - _baseGuid.set_mac_from_guid = true; - } - - _baseGuid.base_guid_specified = _flintParams.uid_specified || _flintParams.guid_specified; - if (_baseGuid.base_guid_specified) { - _baseGuid.base_guid = _flintParams.uid_specified ? _flintParams.baseUid : _flintParams.user_guids[0]; - } - - _baseGuid.base_mac_specified = _flintParams.mac_specified; - if (_baseGuid.base_mac_specified) { - _baseGuid.base_mac = _flintParams.user_macs[0]; - } - //printf("-D-"GUID_FORMAT"\n", _baseGuid.h, _baseGuid.l); - return true; -} - -FlintStatus SmgSubCommand::executeCommand() -{ - if (preFwOps()) { - return FLINT_FAILED; - } - _ops = _flintParams.device_specified ? _fwOps : _imgOps; - //TODO: dispaly MFG guid changes - bool stripedImage = _flintParams.striped_image && _flintParams.image_specified; - if (!_ops->FwQuery(&_info, true, stripedImage)) { - reportErr(true, FLINT_MFG_ERROR, _ops->err()); - return FLINT_FAILED; - } - - if (_info.fw_info.chip_type == CT_CONNECT_IB || _info.fw_info.chip_type == CT_SWITCH_IB || _info.fw_info.chip_type == CT_SWITCH_IB2) { - if (!_flintParams.uid_specified) { - reportErr(true, "Can not set GUIDs/MACs: uid is not specified, please run with -uid flag.\n"); - return FLINT_FAILED; - } - } else { - if (!_flintParams.uid_specified && !_flintParams.guid_specified && !_flintParams.mac_specified ) { - reportErr(true, "Can not set GUIDs/MACs: GUIDs/MACs are not specified, please run with -uid/-guid/-mac flags.\n"); - return FLINT_FAILED; - } - } - - bool ret; - ret = _ops->FwSetMFG(_baseGuid, &verifyCbFunc); - if (!ret) { - reportErr(true, FLINT_MFG_ERROR, _ops->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/*********************** - *Class: Set Vpd Subcommand - **********************/ -SetVpdSubCommand:: SetVpdSubCommand() -{ - _name = "set vpd"; - _desc = "Set read-only VPD (For FS3 image only)."; - _extendedDesc = "Set Read-only VPD, Set VPD in the given FS3 image, intended for production use only."; - _flagLong = "set_vpd"; - _flagShort = ""; - _param = "[vpd file]"; - _paramExp = "vpd file: bin file containing the vpd data"; - _example = FLINT_NAME " -i fw_image.bin set_vpd vpd.bin" -#ifndef __WIN__ - "\n" INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE3 " -override_cache_replacement set_vpd vpd.bin (should be used when device is idle)" -#endif - ; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _minCmdParamNum = 1; - _cmdType = SC_Set_Vpd; -} - -SetVpdSubCommand:: ~SetVpdSubCommand() -{ - -} - -FlintStatus SetVpdSubCommand:: executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - FwOperations *ops = _flintParams.device_specified ? _fwOps : _imgOps; - if (!ops->FwSetVPD((char*)_flintParams.cmd_params[0].c_str(), &verifyCbFunc)) { - reportErr(true, FLINT_VPD_ERROR, ops->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/*********************** - *Class: Set VSD - **********************/ -SvSubCommand:: SvSubCommand() -{ - _name = "sv"; - _desc = "Set the VSD."; - _extendedDesc = "Set VSD in the given device/image.\n" - INDENTEX "Use -vsd flag to set the desired VSD string."; - _flagLong = "sv"; - _flagShort = ""; - _param = ""; - _paramExp = "None"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " -vsd VSD_STRING sv" -#ifndef __WIN__ - "\n" INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE3 " -vsd VSD_STRING -override_cache_replacement sv (should be used when device is idle)\n" -#endif - ; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 0; - _cmdType = SC_Sv; -} - -SvSubCommand:: ~SvSubCommand() -{ - -} - -bool SvSubCommand::verifyParams() -{ - if (!_flintParams.vsd_specified) { - reportErr(true, FLINT_COMMAND_FLAGS_ERROR, _name.c_str(), "\"-vsd\""); - return false; - } - // we verify that -vsd has a parameter in the cmd parser - - return true; -} - -FlintStatus SvSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - FwOperations* ops = _flintParams.device_specified ? _fwOps : _imgOps; - if (!ops->FwSetVSD((char*)_flintParams.vsd.c_str(), &vsdCbFunc, &verifyCbFunc)) { - reportErr(true, FLINT_VSD_ERROR, ops->err()); - return FLINT_FAILED; - } - - if (ops->FwType() == FIT_FS2) { - // print "restoring signature" on FS2 to be consistent with FS3 output - vsdCbFunc(101); - } - return FLINT_SUCCESS; -} - - - -/******************************* - *Class: Read Image SubCommand - ******************************/ -RiSubCommand:: RiSubCommand() -{ - _name = "ri"; - _desc = "Read the fw image on the flash."; - _extendedDesc = "Read the FW image from flash and write it to a file."; - _flagLong = "ri"; - _flagShort = ""; - _param = ""; - _paramExp = "file: filename to write the image to (raw binary)."; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " ri file.bin"; - _v = Wtv_Dev; - _maxCmdParamNum = 1; - _minCmdParamNum = 1; - _cmdType = SC_Ri; -} - -RiSubCommand:: ~RiSubCommand() -{ - -} - -FlintStatus RiSubCommand::executeCommand() { - //init fw operation object - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - // Check if we have permission to write to file - FILE* fh; - if ((fh = fopen(_flintParams.cmd_params[0].c_str(), "wb")) == NULL) { - reportErr(true, "Can not open %s: %s\n", _flintParams.cmd_params[0].c_str(), strerror(errno)); - return FLINT_FAILED; - } else { - fclose(fh); - } - u_int32_t imgSize; - //on first call we get the image size - if (!_fwOps->FwReadData(NULL, &imgSize)) { - reportErr(true, FLINT_IMAGE_READ_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - std::vector imgBuff(imgSize); - //on second call we fill it - if (!_fwOps->FwReadData((void*)(&imgBuff[0]),&imgSize)) { - reportErr(true, FLINT_IMAGE_READ_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - return writeImageToFile(_flintParams.cmd_params[0].c_str(), &(imgBuff[0]), imgSize ); -} - -FlintStatus RiSubCommand::writeImageToFile(const char *file_name, u_int8_t *data, u_int32_t length) -{ - FILE* fh; - if ((fh = fopen(file_name, "wb")) == NULL) { - reportErr(true, "Can not open %s: %s\n", file_name, strerror(errno)); - return FLINT_FAILED; - } - - // Write output - if (fwrite(data, 1, length, fh) != length) { - fclose(fh); - reportErr(true, "Failed to write to %s: %s\n", file_name, strerror(errno)); - return FLINT_FAILED; - } - fclose(fh); - return FLINT_SUCCESS; -} - -/*********************** - *Class: Dump Conf SubCommand - **********************/ -DcSubCommand:: DcSubCommand() { - _name = "dc"; - _desc = "Dump Configuration: print fw configuration file for the given image."; - _extendedDesc = "Print (to screen or to a file) the FW configuration text file used by the image generation process.\n" - INDENTEX "This command would fail if the image does not contain a FW configuration section. Existence of this\n" - INDENTEX "section depends on the version of the image generation tool."; - _flagLong = "dc"; - _flagShort = ""; - _param = "[out-file]"; - _paramExp = "file: (optional) filename to write the dumped configuration to. If not given, the data\n" - INDENTEX "is printed to screen"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " dc"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _cmdType = SC_Dc; -} - -DcSubCommand:: ~DcSubCommand() { - -} - -bool DcSubCommand::verifyParams() { - if (_flintParams.cmd_params.size() > 1) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 1, (int)_flintParams.cmd_params.size()); - return false; - } - return true; -} - -FlintStatus DcSubCommand::executeCommand() { - FwOperations* ops; - //init fw operation object - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - //check on what we are wroking - ops = (_flintParams.device_specified) ? _fwOps : _imgOps; - const char* file = _flintParams.cmd_params.size() == 1 ? _flintParams.cmd_params[0].c_str() : (const char*) NULL; - if (!ops->FwGetSection((ops->FwType() == FIT_FS2) ? (int)H_FW_CONF : (int)FS3_DBG_FW_INI, _sect, _flintParams.striped_image)) { - reportErr(true, FLINT_DUMP_ERROR, "Fw Configuration", ops->err()); - return FLINT_FAILED; - } - if (!dumpFile(file, _sect, "Fw Configuration")) { - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/*********************** - *Class:Dump Hash SubCommand - **********************/ -DhSubCommand:: DhSubCommand() -{ - _name = "dh"; - _desc = "Dump Hash: dump the hash if it is integrated in the FW image"; - _extendedDesc = "Print (to screen or to a file) the HASH text file used by the FW.\n" - INDENTEX "This command would fail if the image does not contain a Hash file."; - _flagLong = "dh"; - _flagShort = ""; - _param = "[out-file]"; - _paramExp = "file - (optional) filename to write the dumped tracer hash file to. If not given, the data\n" - INDENTEX "is printed to screen"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " dh hash.csv"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _cmdType = SC_Dh; -} - -DhSubCommand:: ~DhSubCommand() -{ - -} - -bool DhSubCommand::verifyParams() { - if (_flintParams.cmd_params.size() > 1) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 1, (int)_flintParams.cmd_params.size()); - return false; - } - return true; -} - -FlintStatus DhSubCommand::executeCommand() { - FwOperations* ops; - //init fw operation object - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - //check on what we are wroking - ops = (_flintParams.device_specified) ? _fwOps : _imgOps; - const char* file = _flintParams.cmd_params.size() == 1 ? _flintParams.cmd_params[0].c_str() : (const char*) NULL; - if (!ops->FwGetSection(H_HASH_FILE, _sect, _flintParams.striped_image)) { - reportErr(true, FLINT_DUMP_ERROR, "Hash file", ops->err()); - return FLINT_FAILED; - } - if (!dumpFile(file, _sect, "Fw Configuration")) { - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/*********************** - *Class:Set Key SubCommand - **********************/ -SetKeySubCommand:: SetKeySubCommand() -{ - _name = "set_key"; - _desc = "Set/Update the HW access key which is used to enable/disable access to HW.\n" - INDENT"The key can be provided in the command line or interactively typed after\n" - INDENT"the command is given\n" - INDENT"NOTE: The new key is activated only after the device is reset."; - _extendedDesc = "Set/Update the HW access key which is used to enable/disable access to HW."; - _flagLong = "set_key"; - _flagShort = ""; - _param = "[key]"; - _paramExp = "key: (optional) The new key you intend to set (in hex)."; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " set_key 1234deaf5678"; - _v = Wtv_Dev; - _maxCmdParamNum = 1; - _cmdType = SC_Set_Key; - _getKeyInter = false; - memset(&_userKey, 0, sizeof(_userKey)); -} - -SetKeySubCommand:: ~SetKeySubCommand() -{ - -} - -bool SetKeySubCommand::verifyParams() -{ - if (_flintParams.cmd_params.size() > 1 ) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 1, (int)_flintParams.cmd_params.size()); - return false; - } - _getKeyInter = (_flintParams.cmd_params.size() == 0); - return true; -} - -bool SetKeySubCommand::getKeyInteractively() -{ - char keyArr[MAX_PASSWORD_LEN+1] = {0}; - getPasswordFromUser("Enter Key ", keyArr ); - if (strlen(keyArr) == 0) { - reportErr(true, FLINT_INVALID_PASSWORD); - return false; - } - - if (!getGUIDFromStr(keyArr, _userKey,\ - "Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) { - return false; - } - // verify key - hw_key_t verKey; - getPasswordFromUser("Verify Key ", keyArr ); - if (!getGUIDFromStr(keyArr, verKey,\ - "Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) { - return false; - } - if (_userKey.h != verKey.h || _userKey.l != verKey.l) { - reportErr(true, FLINT_SET_KEY_ERROR, "The keys you entered did not match."); - return false; - } - return true; -} - -FlintStatus SetKeySubCommand::executeCommand () -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - - if (_getKeyInter) { - if (!getKeyInteractively()) { - return FLINT_FAILED; - } - } else { - if (!getGUIDFromStr(_flintParams.cmd_params[0], _userKey, \ - "Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) { - return FLINT_FAILED; - } - } - if (!_fwOps->FwSetAccessKey(_userKey, &setKeyCbFunc)) { - reportErr(true, FLINT_SET_KEY_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - setKeyCbFunc(101); - printf("\n-I- New key was updated successfully in the flash. "\ - "In order to activate the new key you should reboot or restart the driver.\n"); - - return FLINT_SUCCESS; -} - -/*********************** - *Class:HwAccess SubCommand - **********************/ -HwAccessSubCommand:: HwAccessSubCommand() -{ - _name = "hw_access"; - _desc = "Enable/disable the access to the HW.\n" - INDENT"The key can be provided in the command line or interactively typed after\n" - INDENT"the command is given"; - _extendedDesc = "Enable/disable the access to the HW."; - _flagLong = "hw_access"; - _flagShort = ""; - _param = " [key]"; - _paramExp = ": Specify if you intend to disable or enable the HW access.\n" - INDENTEX " You will be asked to type a key when you try to enable HW access.\n" - INDENTEX "key: (optional) The key you intend to use for enabling the HW access.\n" - INDENTEX " Key format consists of at most 16 Hexadecimal digits."; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " hw_access enable"; - _v = Wtv_Dev; - _maxCmdParamNum = 2; - _cmdType = SC_Hw_Access; -} - -HwAccessSubCommand:: ~HwAccessSubCommand() -{ - -} - -bool HwAccessSubCommand::verifyParams() -{ - if (_flintParams.cmd_params.size() == 0) { - reportErr(true, FLINT_MISSED_ARG_ERROR,"",_name.c_str()); - return false; - } - if (_flintParams.cmd_params.size() > 2) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 2, (int)_flintParams.cmd_params.size()); - return false; - } - if( _flintParams.cmd_params[0] != "enable" && _flintParams.cmd_params[0] != "disable") { - reportErr(true, FLINT_INVALID_OPTION_ERROR, _flintParams.cmd_params[0].c_str(), _name.c_str(), "enable or disable"); - return false; - } - return true; -} - -FlintStatus HwAccessSubCommand:: disableHwAccess() -{ - if (((Flash*)_io)->get_cr_space_locked()) { - printf("-I- HW access already disabled\n"); - } else { - if (!((Flash*)_io)->disable_hw_access()) { - printf(FLINT_GEN_COMMAND_ERROR, _name.c_str(), _io->err()); - return FLINT_FAILED; - } - } - return FLINT_SUCCESS; -} -FlintStatus HwAccessSubCommand:: enableHwAccess() -{ - u_int64_t key; - if (((Flash*)_io)->get_cr_space_locked() == 0) { - printf("-I- HW access already enabled\n"); - } else { - hw_key_t keyStruct; - //now we need to get the key from the user (either given in the parameters or we get it during runtime) - if (_flintParams.cmd_params.size() == 2) { - if (!getGUIDFromStr(_flintParams.cmd_params[1], keyStruct,\ - "Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) { - return FLINT_FAILED; - } - } else {//we need to get the key from user during runtime - char keyArr[MAX_PASSWORD_LEN+1]; - getPasswordFromUser("Enter Key ", keyArr ); - if (!getGUIDFromStr(keyArr, keyStruct,\ - "Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) { - return FLINT_FAILED; - } - } - key = ((u_int64_t)keyStruct.h << 32) | keyStruct.l; - if (!((Flash*)_io)->enable_hw_access(key)) { - reportErr(true, FLINT_GEN_COMMAND_ERROR, _name.c_str(), _io->err()); - return FLINT_FAILED; - } - } - return FLINT_SUCCESS; -} - -FlintStatus HwAccessSubCommand:: executeCommand() -{ - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - if (_flintParams.cmd_params[0] == "disable") { - return disableHwAccess(); - } - //else its enable hw access - return enableHwAccess(); -} - -/*********************** - *Class: Hw SubCommand - **********************/ -HwSubCommand:: HwSubCommand() -{ -#ifndef EXTERNAL - _name = "hw"; - _desc = "Set/query HW info and flash attributes."; - _extendedDesc = "Access HW info and flash attributes."; - _flagLong = "hw"; - _flagShort = ""; - _param = " [ATTR=VAL]"; - _paramExp = "query: query HW info\n" - INDENTEX "set [ATTR=VAL]: set flash attribure\n" - INDENTEX "Supported attributes:\n" - INDENTEX " QuadEn: can be 0 or 1\n" - INDENTEX " DummyCycles: can be [1..15]\n" - INDENTEX " Flash[0|1|2|3].WriteProtected can be:\n" - INDENTEX " ,<1|2|4|8|16|32|64>-"; - _example = "flint -d " MST_DEV_EXAMPLE1 " hw query\n" - INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE1 " hw set QuadEn=1\n" - INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE1 " hw set Flash1.WriteProtected=Top,1-SubSectors"; -#else - _name = "Hw"; - _desc = "Query HW info and flash attributes."; - _extendedDesc = "Query HW info and flash attributes."; - _flagLong = "hw"; - _flagShort = ""; - _param = "query"; - _paramExp = "query"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " hw query"; -#endif - _v = Wtv_Dev; - _maxCmdParamNum = 2; - _minCmdParamNum = 1; - _cmdType = SC_Hw; -} - -HwSubCommand:: ~HwSubCommand() -{ - -} - -bool HwSubCommand::verifyParams() { -#ifdef EXTERNAL - if (_flintParams.cmd_params.size() != 1) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 1, (int)_flintParams.cmd_params.size()); - return false; - } - - if (_flintParams.cmd_params[0] != "query"){ - reportErr(true, FLINT_INVALID_OPTION_ERROR, _flintParams.cmd_params[0].c_str(), _name.c_str(), "query"); - return false; - } -#else - if (_flintParams.cmd_params.size() > 2 || _flintParams.cmd_params.size() == 0) { - reportErr(true, FLINT_CMD_ARGS_ERROR2, _name.c_str(), 2, (int)_flintParams.cmd_params.size()); - return false; - } - if ((_flintParams.cmd_params[0] != "query") && (_flintParams.cmd_params[0] != "set")) { - reportErr(true, FLINT_INVALID_OPTION_ERROR, _flintParams.cmd_params[0].c_str(), _name.c_str(), "query or set"); - return false; - } - if ((_flintParams.cmd_params[0] == "set") && (_flintParams.cmd_params.size() != 2)) { - reportErr(true, FLINT_CMD_ARGS_ERROR, _name.c_str(),2 , (int)_flintParams.cmd_params.size()); - return false; - } -#endif - - return true; -} - -FlintStatus HwSubCommand::printAttr(const ext_flash_attr_t& attr) { - printf("HW Info:\n"); - printf(" HwDevId %d\n", attr.hw_dev_id); - printf(" HwRevId 0x%x\n", attr.rev_id); - - printf("Flash Info:\n"); - if (attr.type_str != NULL) { - // we don't print the flash type in old devices - printf(" Type %s\n", attr.type_str); - } - printf(" TotalSize 0x%x\n", attr.size); - printf(" Banks 0x%x\n", attr.banks_num); - printf(" SectorSize 0x%x\n", attr.sector_size ); - printf(" WriteBlockSize 0x%x\n", attr.block_write); - printf(" CmdSet 0x%x\n", attr.command_set); - - // Quad EN query - if (attr.quad_en_support) { - switch (attr.mf_get_quad_en_rc) { - case MFE_OK: - printf(" " QUAD_EN_PARAM " %d\n", attr.quad_en); - break; - case MFE_MISMATCH_PARAM: - printf("-E- There is a mismatch in the " QUAD_EN_PARAM " attribute between the flashes attached to the device\n"); - break; - case MFE_NOT_SUPPORTED_OPERATION: - break; - default: - printf("Failed to get " QUAD_EN_PARAM " attribute: %s (%s)",\ - errno == 0 ? "" : strerror(errno), mf_err2str(attr.mf_get_quad_en_rc)); - return FLINT_FAILED; - } - } - // Dummy Cycles query - if (attr.dummy_cycles_support) { - switch (attr.mf_get_dummy_cycles_rc) { - case MFE_OK: - printf(" " DUMMY_CYCLES_PARAM " %d\n", attr.dummy_cycles); - break; - case MFE_MISMATCH_PARAM: - printf("-E- There is a mismatch in the " DUMMY_CYCLES_PARAM " attribute between the flashes attached to the device\n"); - break; - case MFE_NOT_SUPPORTED_OPERATION: - break; - default: - printf("Failed to get " DUMMY_CYCLES_PARAM " attribute: %s (%s)",\ - errno == 0 ? "" : strerror(errno), mf_err2str(attr.mf_get_dummy_cycles_rc)); - return FLINT_FAILED; - } - } - // Flash write protected info query - if (attr.write_protect_support) { - int bank; - int rc; - for (bank = 0; bank < attr.banks_num; bank++) { - write_protect_info_t protect_info = attr.protect_info_array[bank]; - rc = attr.mf_get_write_protect_rc_array[bank]; - if (rc == MFE_OK) { - printf(" " FLASH_NAME "%d." WRITE_PROTECT " ", bank); - if (protect_info.sectors_num != 0) { - printf("%s,", (protect_info.is_bottom ? WP_BOTTOM_STR : WP_TOP_STR)); - printf("%d-", protect_info.sectors_num); - printf("%s\n", (protect_info.is_subsector ? WP_SUBSEC_STR : WP_SEC_STR)); - } else { - printf(WP_DISABLED_STR"\n"); - } - } else { - if (rc != MFE_NOT_SUPPORTED_OPERATION) { // We ignore the read when operation is not supported! - printf("Failed to get write_protected info: %s (%s)", errno == 0 ? "" : strerror(errno), mf_err2str(rc)); - return FLINT_FAILED; - } - } - } - } - return FLINT_SUCCESS; -} - -FlintStatus HwSubCommand::executeCommand() -{ - //init fw operation object - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - if (_flintParams.cmd_params[0] == "set") { - char* cmdParam = strcpy(new char[_flintParams.cmd_params[1].size() + 1], - _flintParams.cmd_params[1].c_str()); - char *paramName, *paramValStr; - paramName = strtok(cmdParam, "="); - paramValStr = strtok(NULL, "="); - //printf("-D- param_name = %s, param_val_str=%s, cmdParam=%s\n", paramName, paramValStr, cmdParam); - if (paramName == NULL || paramValStr == NULL) { - delete[] cmdParam; - reportErr(true, FLINT_HW_SET_ARGS_ERROR, _flintParams.cmd_params[1].c_str()); - return FLINT_FAILED; - } - if (!((Flash*) _io)->set_attr(paramName, paramValStr)) { - delete[] cmdParam; - reportErr(true, FLINT_HW_COMMAND_ERROR, "set", _io->err()); - return FLINT_FAILED; - } - printf("-I- %s parameter was set successfully\n", paramName); - delete[] cmdParam; - } else { - ext_flash_attr_t attr; - attr.type_str = (char*)NULL; - if (!((Flash*) _io)->get_attr(attr)) { - reportErr(true, FLINT_HW_COMMAND_ERROR, "query", _io->err()); - if (attr.type_str) { - delete[] attr.type_str; - } - return FLINT_FAILED; - } - FlintStatus rc = printAttr(attr); - //str is allocated in get_attr - if (attr.type_str) { - delete[] attr.type_str; - } - if (rc == FLINT_FAILED) { - return FLINT_FAILED; - } - - } - return FLINT_SUCCESS; -} - -/************************** - *Class: Erase SubCommand - *************************/ -EraseSubCommand:: EraseSubCommand() -{ - _name = "erase"; - _desc = "Erases sector."; - _extendedDesc = "Erases a sector that contains specified address."; - _flagLong = "erase"; - _flagShort = "e"; - _param = ""; - _paramExp = "addr - address of word in sector that you want to erase."; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " erase 0x10000"; - _v = Wtv_Dev; - _maxCmdParamNum = 1; - _minCmdParamNum = 1; - _cmdType = SC_Erase; -} - -EraseSubCommand:: ~EraseSubCommand() -{ - -} - -FlintStatus EraseSubCommand::executeCommand() { - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - u_int32_t addr; - char *addrStr = strcpy(new char[_flintParams.cmd_params[0].size() + 1], _flintParams.cmd_params[0].c_str()); - char *endp; - // Address of sector to erase - addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, _flintParams.cmd_params[0].c_str()); - delete[] addrStr; - return FLINT_FAILED; - } - delete[] addrStr; - // Erase - if (!((Flash*)_io)->erase_sector(addr)) { - reportErr(true, FLINT_ERASE_SEC_ERROR, _io->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/***************************** - *Class: Read Dword SubCommand - *****************************/ -RwSubCommand:: RwSubCommand() { - _name = "rw"; - _desc = "Read one dword from flash"; - _extendedDesc = "Read one dword from flash."; - _flagLong = "rw"; - _flagShort = ""; - _param = ""; - _paramExp = "addr - address of word to read"; - _example = "flint -d " MST_DEV_EXAMPLE1 " rw 0x20"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 1; - _minCmdParamNum = 1; - _cmdType = SC_Rw; -} - -RwSubCommand:: ~RwSubCommand() { - -} - -FlintStatus RwSubCommand::executeCommand() { - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - u_int32_t addr; - u_int32_t data; - char *addrStr = strcpy(new char[_flintParams.cmd_params[0].size() + 1], _flintParams.cmd_params[0].c_str()); - char *endp; - addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, _flintParams.cmd_params[0].c_str()); - delete[] addrStr; - return FLINT_FAILED; - } - delete[] addrStr; - if (_flintParams.device_specified ? !((Flash*)_io)->read(addr, &data)\ - : !((FImage*)_io)->read(addr, &data)) { - reportErr(true, FLINT_FLASH_READ_ERROR, _io->err()); - return FLINT_FAILED; - } - printf("0x%08x\n", (unsigned int)__cpu_to_be32(data)); - return FLINT_SUCCESS; -} - -/****************************** - *Class: Write Dword Subcommand - ******************************/ -WwSubCommand:: WwSubCommand() -{ - _name = "ww"; - _desc = "Write one dword to flash"; - _extendedDesc = "Write one dword to flash.\n" - INDENTEX "Note that the utility will read an entire flash sector,\n" - INDENTEX "modify one word and write the sector back. This may take\n" - INDENTEX "a few seconds."; - _flagLong = "ww"; - _flagShort = ""; - _param = " "; - _paramExp = "addr - address of word\n" - INDENTEX "data - value of word"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " ww 0x10008 0x5a445a44"; - _v = Wtv_Dev; - _maxCmdParamNum = 2; - _minCmdParamNum = 2; - _cmdType = SC_Ww; -} - -WwSubCommand:: ~WwSubCommand() -{ - -} - -FlintStatus WwSubCommand::executeCommand() { - //init fw operation object - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - u_int32_t addr; - u_int32_t data; - char *addrStr = strcpy(new char[_flintParams.cmd_params[0].size() + 1], _flintParams.cmd_params[0].c_str()); - char *dataStr = strcpy(new char[_flintParams.cmd_params[1].size() + 1], _flintParams.cmd_params[1].c_str()); - char *endp; - addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, _flintParams.cmd_params[0].c_str()); - delete[] addrStr; - delete[] dataStr; - return FLINT_FAILED; - } - data =strtoul(dataStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_DATA_ERROR, _flintParams.cmd_params[1].c_str()); - delete[] addrStr; - delete[] dataStr; - return FLINT_FAILED; - } - delete[] addrStr; - delete[] dataStr; - data = __cpu_to_be32(data); - if (!((Flash*)_io)->write(addr, data)) { - reportErr(true, FLINT_FLASH_WRITE_ERROR, _io->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} -/*************************************** - *Class: Write Dword No Erase SubCommand - ***************************************/ -WwneSubCommand:: WwneSubCommand() -{ - _name = "wwne"; - _desc = "Write one dword to flash without sector erase"; - _extendedDesc = "Write one dword to flash without sector erase.\n" - INDENTEX "Note that the result of operation is undefined and depends\n" - INDENTEX "on flash type. Usually \"bitwise AND\" (&) between specified\n" - INDENTEX "word and previous flash contents will be written to\n" - INDENTEX "specified address."; - _flagLong = "wwne"; - _flagShort = ""; - _param = " "; - _paramExp = "addr - address of word\n" - INDENTEX "data - value of word"; - _example = "flint -d " MST_DEV_EXAMPLE1 " wwne 0x10008 0x5a445a44"; - _v = Wtv_Dev; - _maxCmdParamNum = 2; - _minCmdParamNum = 2; - _cmdType = SC_Wwne; -} - -WwneSubCommand:: ~WwneSubCommand() -{ - -} - -FlintStatus WwneSubCommand::executeCommand() { - //init fw operation object - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - u_int32_t addr; - u_int32_t data; - char *addrStr = strcpy(new char[_flintParams.cmd_params[0].size() + 1], _flintParams.cmd_params[0].c_str()); - char *dataStr = strcpy(new char[_flintParams.cmd_params[1].size() + 1], _flintParams.cmd_params[1].c_str()); - char *endp; - addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, _flintParams.cmd_params[0].c_str()); - delete[] addrStr; - delete[] dataStr; - return FLINT_FAILED; - } - data =strtoul(dataStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_DATA_ERROR, _flintParams.cmd_params[1].c_str()); - delete[] addrStr; - delete[] dataStr; - return FLINT_FAILED; - } - delete[] addrStr; - delete[] dataStr; - data = __cpu_to_be32(data); - if (!((Flash*)_io)->write(addr, &data, 4, true)) { - reportErr(true, FLINT_FLASH_WRITE_ERROR, _io->err()); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/************************************** - *Class:Write Block SubCommand - **************************************/ -WbSubCommand:: WbSubCommand() { - _name = "wb"; - _desc = "Write a data block to flash."; - _extendedDesc = "Write a block of data to the flash."; - _flagLong = "wb"; - _flagShort = ""; - _param = " "; - _paramExp = "data-file - file that contains the data to be written\n" - INDENTEX "addr - address to write the block to\n"; - - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " wb myData.bin 0x0"; - _v = Wtv_Dev; - _maxCmdParamNum = 2; - _minCmdParamNum = 2; - _cmdType = SC_Wb; -} - -WbSubCommand:: ~WbSubCommand() { - -} - -bool WbSubCommand::extractData(const std::vector& cmdParams , u_int32_t* addr, std::vector& data) { - // get address - char *endp; - char* addrStr = strcpy(new char[cmdParams[1].size() + 1],cmdParams[1].c_str()); - *addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, cmdParams[1].c_str()); - delete[] addrStr; - return false; - } - delete[] addrStr; - // get data - FImage img; - if (!img.open(cmdParams[0].c_str())) { - reportErr(true, FLINT_WB_FILE_ERROR, cmdParams[0].c_str(), img.err()); - return false; - } - //copy data to vector - data.resize(img.getBufLength()); - memcpy(&data[0], img.getBuf(), img.getBufLength()); - - return true; -} - -FlintStatus WbSubCommand::executeCommand() { - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - u_int32_t addr; - std::vector data; - if (!extractData(_flintParams.cmd_params, &addr, data)) { - return FLINT_FAILED; - } - //printf("-D- writing to addr:0x%08x %lu bytes\n",addr , data.size()); - if (!_fwOps->FwWriteBlock(addr, data, wbCbFunc)) { - reportErr(true, FLINT_WB_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - wbCbFunc(101); - return FLINT_SUCCESS; -} - -/************************************** - *Class:Write Block No Erase SubCommand - **************************************/ -WbneSubCommand:: WbneSubCommand() { - _name = "wbne"; - _desc = "Write a data block to flash without sector erase."; - _extendedDesc = "Write a block of data to the flash without erasing."; - _flagLong = "wbne"; - _flagShort = ""; - _param = " "; - _paramExp = "addr - address of block\n" - INDENTEX "size - size of data to write in bytes\n" - INDENTEX "data - data to write - space separated dwords"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " wbne 0x10000 12 0x30000 0x76800 0x5a445a44"; - _v = Wtv_Dev; - _minCmdParamNum = 3; - _cmdType = SC_Wbne; -} - -WbneSubCommand:: ~WbneSubCommand() { - -} - -bool WbneSubCommand::writeBlock(u_int32_t addr, std::vector dataVec) { - //we should work only on flash. - //check if flash is big enough - if (addr + (dataVec.size()*4) > ((Flash*)_io)->get_size()) { - reportErr(true, "Writing %#x bytes from address %#x is out of flash limits (%#x bytes)\n", - (unsigned int)(dataVec.size()*4), (unsigned int)addr, (unsigned int)_io->get_size()); - return false; - } - if (!((Flash*)_io)->write(addr, &dataVec[0], (dataVec.size()*4), true)) { - reportErr(true, FLINT_FLASH_WRITE_ERROR,_io->err()); - return false; - } - return true; -} - -bool WbneSubCommand::extractData(const std::vector& cmdParams , u_int32_t* addr, std::vector& data) { - char *endp; - char* addrStr = strcpy(new char[cmdParams[0].size() + 1],cmdParams[0].c_str()); - *addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, cmdParams[0].c_str()); - delete[] addrStr; - return false; - } - delete[] addrStr; - char* sizeStr = strcpy(new char[cmdParams[1].size() + 1],cmdParams[1].c_str()); - u_int32_t size = strtoul(sizeStr, &endp, 0); - if (*endp || size % 4 || size/4 != (cmdParams.size()-2)) { - reportErr(true, FLINT_INVALID_SIZE_ERROR, sizeStr); - delete[] sizeStr; - return false; - } - delete[] sizeStr; - for (u_int32_t i = 2; i < cmdParams.size(); i++) { - char* dataStr = strcpy(new char[cmdParams[i].size() + 1],cmdParams[i].c_str()); - data.push_back(__cpu_to_be32(strtoul(dataStr, &endp, 0))); - if (*endp) { - reportErr(true, FLINT_INVALID_DATA_ERROR, dataStr); - delete[] dataStr; - return false; - } - delete[] dataStr; - } - return true; -} - -FlintStatus WbneSubCommand::executeCommand() { - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - u_int32_t addr; - std::vector data; - if (!extractData(_flintParams.cmd_params, &addr, data)) { - return FLINT_FAILED; - } - //printf("-D- writing to addr:0x%08x %lu bytes\n",addr , data.size()*4); - if (!writeBlock(addr, data)) { - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - -/*********************** - *Class: ReadBlock - **********************/ -RbSubCommand:: RbSubCommand() -{ - _name = "rb"; - _desc = "Read a data block from flash"; - _extendedDesc = "Read a data block from the flash and write it to a file or to screen."; - _flagLong = "rb"; - _flagShort = ""; - _param = " [out-file]"; - _paramExp = "addr - address of block\n" - INDENTEX "size - size of data to read in bytes\n" - INDENTEX "file - filename to write the block (raw binary). If not given, the data\n" - INDENTEX "is printed to screen"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " rb 0x10000 100 file.bin"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 3; - _minCmdParamNum = 2; - _cmdType = SC_Rb; -} - -RbSubCommand:: ~RbSubCommand() -{ - -} - -bool RbSubCommand::readBlock(u_int32_t addr, std::vector& buff, bool isFlash) { - //check if flash is big enough - if (addr + buff.size() > _io->get_size()) { - reportErr(true, "Reading %#x bytes from address %#x is out of flash limits (%#x bytes)\n", - (unsigned int)(buff.size()), (unsigned int)addr, (unsigned int)_io->get_size()); - return false; - } - //read from flash/image - if (isFlash ? !((Flash*)_io)->read(addr, &buff[0], buff.size()) :\ - !((FImage*)_io)->read(addr, &buff[0], buff.size())) { - reportErr(true, FLINT_IMAGE_READ_ERROR, _io->err()); - return false; - } - return true; -} - -bool RbSubCommand::printToScreen(const std::vector& buff) { - for (u_int32_t i=0; i < buff.size(); i+=4) { - u_int32_t word = *((u_int32_t*)(&buff[0] + i)); - word = __be32_to_cpu(word); - printf("0x%08x ", word); - } - printf("\n"); - return true; -} - -FlintStatus RbSubCommand::executeCommand() { - //init fw operation object - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - bool wTF = _flintParams.cmd_params.size() == 3 ? true : false; - //extract address and size to read from cmdline - u_int32_t addr; - u_int32_t size; - char *endp; - char* addrStr = strcpy(new char[_flintParams.cmd_params[0].size() + 1],_flintParams.cmd_params[0].c_str()); - addr = strtoul(addrStr, &endp, 0); - if (*endp) { - reportErr(true, FLINT_INVALID_ADDR_ERROR, _flintParams.cmd_params[0].c_str()); - delete[] addrStr; - return FLINT_FAILED; - } - delete[] addrStr; - char* sizeStr = strcpy(new char[_flintParams.cmd_params[1].size() + 1],_flintParams.cmd_params[1].c_str()); - size = strtoul(sizeStr, &endp, 0); - if (*endp || size % 4) { - reportErr(true, FLINT_INVALID_SIZE_ERROR, sizeStr); - delete[] sizeStr; - return FLINT_FAILED; - } - delete[] sizeStr; - //init byte vector and fill it with data - std::vector data(size); - if (!readBlock(addr, data, _flintParams.device_specified)) { - return FLINT_FAILED; - } - //print either to file or to screen - FlintStatus rc; - if (wTF) { - rc = writeToFile(_flintParams.cmd_params[2], data) == true ? FLINT_SUCCESS : FLINT_FAILED ; - } else { - rc = printToScreen(data) == true ? FLINT_SUCCESS : FLINT_FAILED ; - } - return rc; -} - -/*********************** - *Class: ClearSemaphore - **********************/ -ClearSemSubCommand:: ClearSemSubCommand() -{ - _name = "clear_semaphore"; - _desc = "Clear flash semaphore."; - _extendedDesc = "Clear flash semaphore."; - _flagLong = "clear_semaphore"; - _flagShort = ""; - _param = ""; - _paramExp = ""; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " -clear_semaphore"; - _v = Wtv_Dev; - _maxCmdParamNum = 0; - _cmdType = SC_Clear_Sem; -} - -ClearSemSubCommand:: ~ClearSemSubCommand() -{ - -} - -FlintStatus ClearSemSubCommand::executeCommand() -{ - _flintParams.clear_semaphore = true; - return preFwAccess(); -} - - -/*********************** - *Class: RomQuery - **********************/ -RomQuerySubCommand:: RomQuerySubCommand() -{ - _name = "qrom"; - _desc = "query ROM image."; - _extendedDesc = "query ROM image."; - _flagLong = "qrom"; - _flagShort = ""; - _param = ""; - _paramExp = ""; - _example = FLINT_NAME " -i ROM_image.bin qrom "; - _v = Wtv_Img; - _maxCmdParamNum = 0; - _cmdType = SC_Qrom; - memset(&_romsInfo, 0, sizeof(_romsInfo)); -} - -RomQuerySubCommand:: ~RomQuerySubCommand() -{ - -} - - -FlintStatus RomQuerySubCommand::executeCommand() -{ - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - - getRomsInfo(_io, _romsInfo); - if (_romsInfo.exp_rom_err_msg_valid != 0){ - reportErr(true, FLINT_ROM_QUERY_ERROR, _flintParams.image.c_str(), _romsInfo.exp_rom_err_msg); - return FLINT_FAILED; - } - displayExpRomInfo(_romsInfo , "Rom Info: "); - return FLINT_SUCCESS; - -} - -/*********************** - *Class: ResetCfg - **********************/ -ResetCfgSubCommand:: ResetCfgSubCommand() -{ - _name = "reset_cfg"; - _desc = "reset non-volatile configuration."; - _extendedDesc = "reset non-volatile configuration to their default value."; - _flagLong = "reset_cfg"; - _flagShort = "r"; - _param = ""; - _paramExp = ""; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " reset_cfg"; - _v = Wtv_Dev; - _maxCmdParamNum = 0; - _cmdType = SC_ResetCfg; -} - -ResetCfgSubCommand:: ~ResetCfgSubCommand() -{ - -} - - -FlintStatus ResetCfgSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - printf("-W- Resetting device configuration using Flint should be done as a last resort.\n"); - printf("-W- Please attempt to reset configuration via mlxconfig tool if possible.\n"); - printf("-W- Only proceed if you know what you are doing.\n"); - if (!askUser("reset non-volatile configuration")) { - return FLINT_FAILED; - } - - printf("Resetting..."); - if (!_fwOps->FwResetNvData()){ - printf(" Failed!\n"); - reportErr(true, FLINT_RESET_CFG_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - printf(" SUCCESS!\n"); - printf("\n-I- Configuration were successfully reset. reboot or restart the driver is required.\n"); - - return FLINT_SUCCESS; - -} - -/*********************** - *Class: FixImage - **********************/ -FiSubCommand:: FiSubCommand() -{ - _name = "fix image"; - _desc = "fix image on N25Q0XX flash."; - _extendedDesc = "fix image on N25Q0XX flash.(shifting all device data sectors)"; - _flagLong = "fi"; - _flagShort = ""; - _param = ""; - _paramExp = ""; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " fi"; - _v = Wtv_Dev; - _maxCmdParamNum = 0; - _cmdType = SC_Fix_Img; -} - -FiSubCommand:: ~FiSubCommand() -{ - -} - - -FlintStatus FiSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - - if (!askUser("Fix device fw?")) { - return FLINT_FAILED; - } - - if (!_fwOps->FwShiftDevData(&verifyCbFunc)){ - reportErr(true, FLINT_FIX_IMG_ERROR, _fwOps->err()); - return FLINT_FAILED; - } - printf("\n-I- Fw was successfully fixed. reboot or restart the driver is required.\n"); - return FLINT_SUCCESS; - -} - -/*********************** - *Class: CheckSum - **********************/ -CheckSumSubCommand:: CheckSumSubCommand() -{ - _name = "checksum"; - _desc = "perform MD5 checksum on FW."; - _extendedDesc = "perform an MD5 checksum on relevant(non-persistent between FW upgrades) data on device/image."; - _flagLong = "checksum"; - _flagShort = "cs"; - _param = ""; - _paramExp = ""; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " checksum"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 0; - _cmdType = SC_Check_Sum; - memset(_checkSum, 0, sizeof(_checkSum)); -} - -CheckSumSubCommand:: ~CheckSumSubCommand() -{ - -} - -bool CheckSumSubCommand::extractChecksumFromStr(string str, u_int8_t checkSum[16]) -{ - char ptr[2]; - int i = 15; - if (str.size() < 2) { - reportErr(true, FLINT_CHECKSUM_LEN_ERROR ); - return false; - } - if (!strncasecmp(str.c_str(), "0x", 2)) { - // str starts with 0x or 0X, remove prefix - str = &(str.c_str()[2]); - } - - if (str.size() != 32) { - reportErr(true, FLINT_CHECKSUM_LEN_ERROR ); - return false; - } - stringstream ss(str); - while (i >= 0) { - ss.read(ptr, 2); - if (!isxdigit(ptr[0]) || !isxdigit(ptr[1])) { - reportErr(true, FLINT_CHECKSUM_HEX_ERROR); - return false; - } - checkSum[i] = (u_int8_t)strtoul(ptr, NULL, 16); - if (!checkSum[i] && strncmp(ptr, "00", 2)) { - reportErr(true, FLINT_CHECKSUM_PARSE_ERROR); - return false; - } - i--; - } - return true; -} - -string CheckSumSubCommand::checkSum2Str(u_int8_t chksm[16]) -{ - stringstream ss; - for (int i=15; i >= 0; i--) { - char chunk[3]; - snprintf(chunk, 3, "%02x", chksm[i]); - ss << chunk; - } - string s = ss.str(); - return s; -} - -FlintStatus CheckSumSubCommand::executeCommand() -{ - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - FwOperations* ops = _fwOps ? _fwOps : _imgOps; - printf("-I- Calculating Checksum ...\n"); - if (!ops->FwCalcMD5(_checkSum)){ - reportErr(true, FLINT_CHECKSUM_ERROR, (_flintParams.device_specified ? "device" : "image"), ops->err()); - return FLINT_FAILED; - } - // just print it! - printf("Checksum: %s\n", checkSum2Str(_checkSum).c_str()); - return FLINT_SUCCESS; - -} - - -/*********************** - *Class: TimeStamp - **********************/ -TimeStampSubCommand:: TimeStampSubCommand() -{ - _name = "time stamp"; - _desc = "FW time stamping."; - _extendedDesc = "set/query/reset time stamp on device/image."; - _flagLong = "timestamp"; - _flagShort = "ts"; - _param = " [timestamp] [FW version]"; - _paramExp = "set [FW version] : set the specified timestamp. if set on device FW version must be specified\n" - INDENTEX " timestamp should comply with ISO 8601 format and provided with UTC timezone: YYYY-MM-DDThh:mm:ssZ\n" - INDENTEX "query : query device/image to view the timestamp\n" - INDENTEX "reset : reset the timestamp, remove the timestamp from device/image.\n"; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE4 " ts set 2015-12-24T14:52:33Z 14.12.1100\n" - INDENTEX FLINT_NAME " -d " MST_DEV_EXAMPLE4 " ts reset\n" - INDENTEX FLINT_NAME " -i ./fw4115.bin ts set\n" - INDENTEX FLINT_NAME " -i ./fw4115.bin ts query"; - _v = Wtv_Dev_Or_Img; - _maxCmdParamNum = 3; - _minCmdParamNum = 1; - _cmdType = SC_Time_Stamp; - memset(&_userFwVer, 0, sizeof(_userFwVer)); - memset(&_userTsEntry, 0, sizeof(_userTsEntry)); - _operation = TS_No_Command; - _ops = (FwOperations*)NULL; -} - -TimeStampSubCommand:: ~TimeStampSubCommand() -{ - -} -bool TimeStampSubCommand::parseFwVersion(string verStr) -{ - unsigned int major = 0; - unsigned int minor = 0; - unsigned int subminor = 0; - int count = sscanf(verStr.c_str(), "%02d.%02d.%04d", &major, &minor, &subminor); - if (count !=3) { - count = sscanf(verStr.c_str(), "%02d.%04d.%04d", &major, &minor, &subminor); - if (count != 3) { - reportErr(true, "Failed to parse FW version. expected format: MM.mm.ssss\n"); - return false; - } - } - _userFwVer.fw_ver_major = major; - _userFwVer.fw_ver_minor = minor; - _userFwVer.fw_ver_subminor = subminor; - //printf("-D- Fw version: %d.%d.%d\n", _userFwVer.fw_ver_major, _userFwVer.fw_ver_minor, _userFwVer.fw_ver_subminor); - return true; -} - -#define BCD2_TO_NUM(bcd)\ - ((((bcd) >> 4 & 0xf) * 10) + ((bcd) & 0xf)) - -#define BCD4_TO_NUM(bcd) \ - ((BCD2_TO_NUM((bcd) >> 8 & 0xff) * 100) + (BCD2_TO_NUM((bcd) & 0xff))) - -#define NUM2_TO_BCD(num) \ - ((((num) / 10) * 16) + ((num) % 10)) - -#define NUM4_TO_BCD(num) \ - ((NUM2_TO_BCD((num) / 100 ) * 256) + NUM2_TO_BCD((num) % 100 )) - -u_int8_t TimeStampSubCommand::getDaysInMonth(u_int16_t year, u_int8_t month) -{ - u_int8_t days = 0; - bool isLeapYear = year % 4 == 0; // evenly divisible by 4 - isLeapYear &= (year % 100 != 0) || (year % 400 == 0); // not evenly divided by 100 or evenly divisible by 400 - switch(month) { - case 2: - days = isLeapYear ? 29 : 28; - break; - case 4: - case 6: - case 9: - case 11: - days = 30; - break; - case 1: - case 3: - case 5: - case 7: - case 8: - case 10: - case 12: - days = 31; - break; - default: - break; - } - return days; -} - -void TimeStampSubCommand::getMachineUTCTime() -{ - time_t rawTime; - struct tm * timeInfo; - time ( &rawTime ); - timeInfo = gmtime ( &rawTime ); - - _userTsEntry.ts_year = NUM4_TO_BCD(timeInfo->tm_year + 1900); - _userTsEntry.ts_month = NUM2_TO_BCD(timeInfo->tm_mon + 1); - _userTsEntry.ts_day = NUM2_TO_BCD(timeInfo->tm_mday); - _userTsEntry.ts_hour = NUM2_TO_BCD(timeInfo->tm_hour); - _userTsEntry.ts_minutes = NUM2_TO_BCD(timeInfo->tm_min); - _userTsEntry.ts_seconds = NUM2_TO_BCD(timeInfo->tm_sec); - - //printf("-D- timestamp: %04x-%02x-%02xT%02x:%02x:%02x\n", _userTsEntry.ts_year, _userTsEntry.ts_month, - // _userTsEntry.ts_day, _userTsEntry.ts_hour, _userTsEntry.ts_minutes, _userTsEntry.ts_seconds); - return; -} - -bool TimeStampSubCommand::parseTimeStamp(string tsStr) -{ - unsigned int year = 0; - unsigned int month = 0; - unsigned int day = 0; - unsigned int hour = 0; - unsigned int minutes = 0; - unsigned int seconds = 0; - if (*tsStr.rbegin() != 'Z') { - reportErr(true, "Failed to parse timestamp: Timestamp timezone must be UTC. format should be: YYYY-MM-DDThh:mm:ssZ\n"); - return false; - } - // scan and store - int count = sscanf(tsStr.c_str(), "%04d-%02d-%02dT%02d:%02d:%02dZ", &year, &month, &day, &hour, &minutes, &seconds); - if (count !=6) { - reportErr(true, "Failed to parse timestamp: input should be compliant to the following ISO 8601 format: YYYY-MM-DDThh:mm:ssZ\n"); - return false; - } - // check time args - if ( month == 0 || month > 12) { - reportErr(true, "Failed to parse timestamp: illegal month value (%d)\n", month); - return false; - } - if (day > getDaysInMonth(year, month)) { - reportErr(true, "Failed to parse timestamp: illegal day value (%d)\n", day); - return false; - } - if ( hour > 23 || minutes > 59 || seconds > 59 ) { - reportErr(true, "Failed to parse timestamp: illegal time value (%02d:%02d:%02d)\n", hour, minutes, seconds); - return false; - } - // store as BCD - _userTsEntry.ts_year = NUM4_TO_BCD(year); - _userTsEntry.ts_month = NUM2_TO_BCD(month); - _userTsEntry.ts_day = NUM2_TO_BCD(day); - _userTsEntry.ts_hour = NUM2_TO_BCD(hour); - _userTsEntry.ts_minutes = NUM2_TO_BCD(minutes); - _userTsEntry.ts_seconds = NUM2_TO_BCD(seconds); - - //printf("-D- timestamp: %04x-%02x-%02xT%02x:%02x:%02x\n", _userTsEntry.ts_year, _userTsEntry.ts_month, - // _userTsEntry.ts_day, _userTsEntry.ts_hour, _userTsEntry.ts_minutes, _userTsEntry.ts_seconds); - return true; -} - -bool TimeStampSubCommand::verifyParams() -{ - if (_flintParams.cmd_params[0] == "query") { - if (_flintParams.cmd_params.size() > 1) { - reportErr(true, "query operation requires no arguments.\n"); - return false; - } - _operation = TimeStampSubCommand::TS_Query; - } else if (_flintParams.cmd_params[0] == "set") { - if (_flintParams.image_specified && _flintParams.cmd_params.size() > 2) { - reportErr(true, "too many arguments for set operation on image.\n"); - return false; - } else if (_flintParams.device_specified && _flintParams.cmd_params.size() != 3) { - reportErr(true, "set operation on device requires timestamp and FW version arguments.\n\n"); - return false; - } - _operation = TimeStampSubCommand::TS_Set; - // attempt to parse timestamp and fw version - if (_flintParams.image_specified && _flintParams.cmd_params.size() == 1) { - // take time from machine - getMachineUTCTime(); - } else if (!parseTimeStamp(_flintParams.cmd_params[1])) { - return false; - } - if (_flintParams.device_specified && !parseFwVersion(_flintParams.cmd_params[2])) { - return false; - } - } else if (_flintParams.cmd_params[0] == "reset") { - if (_flintParams.cmd_params.size() > 1) { - reportErr(true, "erase operation requires no arguments.\n"); - return false; - } - _operation = TimeStampSubCommand::TS_Reset; - } else { - reportErr(true, "Unknown operation, allowed operations: query/set/reset.\n"); - return false; - } - return true; -} - -void TimeStampSubCommand::printTsAndFwVer(string prefix, struct tools_open_ts_entry& tsEntry, struct tools_open_fw_version& fwVer) -{ - printf("%-24s: %04x-%02x-%02xT%02x:%02x:%02xZ %02d.%02d.%04d\n", prefix.c_str(), tsEntry.ts_year, tsEntry.ts_month, tsEntry.ts_day, - tsEntry.ts_hour, tsEntry.ts_minutes, tsEntry.ts_seconds, - fwVer.fw_ver_major, fwVer.fw_ver_minor, fwVer.fw_ver_subminor); -} - -bool TimeStampSubCommand::queryTs() -{ - struct tools_open_ts_entry tsEntry; - struct tools_open_fw_version fwVer; - memset(&tsEntry, 0, sizeof(tsEntry)); - memset(&fwVer, 0, sizeof(fwVer)); - // get and Print Current Running FW TS in case of device - if (_flintParams.device_specified) { - if (!_ops->FwQueryTimeStamp(tsEntry, fwVer, true)) { - printf("%-24s: N/A. %s\n", "Current timestamp", _ops->err()); - } else { - printTsAndFwVer("Current timestamp", tsEntry, fwVer); - } - } - // get and print next FW timestamp - if (!_ops->FwQueryTimeStamp(tsEntry, fwVer, false)) { - printf("%-24s: N/A. %s\n", "Next timestamp", _ops->err()); - } else { - printTsAndFwVer("Next timestamp", tsEntry, fwVer); - } - return true; -} - -bool TimeStampSubCommand::setTs() -{ - if (!_ops->FwSetTimeStamp(_userTsEntry, _userFwVer)) { - reportErr(false, "%s", _ops->err()); - return false; - } - return true; -} - -bool TimeStampSubCommand::resetTs() -{ - if (!_ops->FwResetTimeStamp()) { - reportErr(false, "%s", _ops->err()); - return false; - } - return true; -} - -FlintStatus TimeStampSubCommand::executeCommand() -{ - bool rc; - - if (preFwOps() == FLINT_FAILED) { - return FLINT_FAILED; - } - _ops = _flintParams.device_specified ? _fwOps : _imgOps; - (void)_ops; - switch (_operation) { - case TimeStampSubCommand::TS_Set: - rc = setTs(); - break; - case TimeStampSubCommand::TS_Query: - rc = queryTs(); - break; - case TimeStampSubCommand::TS_Reset: - rc = resetTs(); - break; - default: - // should not be reached - reportErr(true, "Failed to perform timestamp operation: Unknown Error\n"); - return FLINT_FAILED; - } - if (!rc) { - printf("-E- Failed to perform timestamp %s operation. %s\n", _flintParams.cmd_params[0].c_str(), _errBuff); - return FLINT_FAILED; - } - return FLINT_SUCCESS; -} - - -/*********************** - *Class: CacheImage - **********************/ -CacheImageSubCommand:: CacheImageSubCommand() -{ - _name = "cache image"; - _desc = "cache FW image(Windows only)."; - _extendedDesc = "cache the FW image using Mellanox driver to allow faster FW load time upon loading the driver(Windows only)."; - _flagLong = "cache_image"; - _flagShort = "ci"; - _param = ""; - _paramExp = ""; - _example = FLINT_NAME " -d " MST_DEV_EXAMPLE1 " cache_image"; - _v = Wtv_Dev; - _maxCmdParamNum = 0; - _minCmdParamNum = 0; - _cmdType = SC_Cache_Image; -} - -CacheImageSubCommand:: ~CacheImageSubCommand() -{ - -} - -FlintStatus CacheImageSubCommand:: executeCommand() -{ -#ifdef __WIN__ - int rc; - - if (preFwAccess() == FLINT_FAILED) { - return FLINT_FAILED; - } - rc = wdcif_send_image_cache_request(((Flash*)_io)->getMfileObj()); - if (rc) { - reportErr(true, FLINT_CACHE_IMAGE_ERROR, wdcif_err_str(rc)); - return FLINT_FAILED; - } - printf("\n-I- FW was successfully cached by driver.\n"); - return FLINT_SUCCESS; -#else - reportErr(true, FLINT_WIN_ONLY_SUPP_ERROR, _name.c_str()); - return FLINT_FAILED; -#endif -} diff --git a/flint/subcommands.h b/flint/subcommands.h deleted file mode 100644 index e066d24..0000000 --- a/flint/subcommands.h +++ /dev/null @@ -1,547 +0,0 @@ -/* - * - * subcommands.h - FLash INTerface - * - * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id$ - * - */ - -#ifndef __SUBCOMMANDS_H__ -#define __SUBCOMMANDS_H__ - -#define MAX_PASSWORD_LEN 256 - -#include - -#include - -#include "flint_params.h" -#include "mlxfwops/lib/fw_ops.h" -#include "err_msgs.h" -using namespace std; - -//we might need to close the log from the main program in case of interrupt -void close_log(); -void print_time_to_log(); -int print_line_to_log(const char* format, ...); -int write_cmd_to_log(char* av[], int ac, CommandType cmd, bool write=true); -int write_result_to_log(int is_failed, const char* err_msg, bool write=true); - -typedef enum what_to_ver { - Wtv_Img, - Wtv_Dev, - Wtv_Dev_And_Img, - Wtv_Dev_Or_Img, - Wtv_Uninitilized -} what_to_ver_t; -/*Subcommand classes:*/ - -#define FLINT_ERR_LEN 1024 - -class SubCommand -{ -protected: - FwOperations *_fwOps; - FwOperations *_imgOps; - FBase* _io; - what_to_ver_t _v; - int _maxCmdParamNum; - int _minCmdParamNum; - FlintParams _flintParams; - //info about the Subcommand - string _name; - string _desc; - string _extendedDesc; - string _flagLong; - string _flagShort; - string _param; - string _paramExp; - string _example; - char _errBuff[FLINT_ERR_LEN]; - sub_cmd_t _cmdType; - - - //Methods that are commonly used in the various subcommands: - //TODO: add middle classes and segregate as much of these common methods between these classes - - virtual bool verifyParams() {return true;}; - bool basicVerifyParams(); - FlintStatus openOps(); - FlintStatus openIo(); - virtual FlintStatus preFwOps(); - virtual FlintStatus preFwAccess(); - - bool getRomsInfo(FBase* io, roms_info_t& romsInfo); - void displayOneExpRomInfo(const rom_info_t& info); - void displayExpRomInfo(const roms_info_t& romsInfo, const char *preStr); - - static int verifyCbFunc(char* str); - static int CbCommon(int completion, char*preStr, char* endStr=NULL); - static int burnCbFs2Func(int completion); - static int burnCbFs3Func(int completion); - static int burnBCbFunc(int completion); - static int vsdCbFunc(int completion); - static int setKeyCbFunc(int completion); - static int bromCbFunc(int completion); - static int dromCbFunc(int completion); - static int wbCbFunc(int completion); - static int resetCfgCbFunc(int completion); - - bool printGuidLine(guid_t* new_guids, guid_t* old_guids, int guid_index); - bool printMacLine(guid_t* new_guids, guid_t* old_guids, int mac_index); - bool printGUIDsFunc(guid_t guids[GUIDS],guid_t macs[MACS], guid_t old_guids[GUIDS],\ - guid_t old_macs[MACS], bool print_guids, bool print_macs, int portNum, bool old_guid_fmt); - bool reportGuidChanges(guid_t* new_guids, guid_t* new_macs,\ - guid_t* old_guids, guid_t* old_macs, bool printGuids,\ - bool printMacs, int guidNum); - bool checkGuidsFlags(u_int16_t devType, u_int8_t fwType, - bool guidsSpecified, bool macsSpecified, bool uidSpecified, bool ibDev, bool ethDev); - void printMissingGuidErr(bool ibDev, bool ethDev); - - bool extractUIDArgs(std::vector& cmdArgs, u_int8_t numOfGuids[2], u_int8_t stepSize[2]); - bool extractValuesFromString(string valStr, u_int8_t values[2], string origArg); - bool getGUIDFromStr(string str, guid_t& guid, string prefixErr=""); - bool getPasswordFromUser(const char *preStr, char buffer[MAX_PASSWORD_LEN+1]); - bool askUser(const char* question=NULL, bool printAbrtMsg=true); - - bool isCmdSupportLog(); - void openLog(); - inline void closeLog() {close_log();} - //print errors to an err buff, log if needed and stdout - void reportErr(bool shouldPrint, const char *format, ...); - - bool writeToFile(string filePath, const std::vector& buff); - - bool dumpFile(const char* confFile, std::vector& data, const char *sectionName); - bool unzipDataFile (std::vector data, std::vector &newData, const char *sectionName); - - - -public: - SubCommand(): _fwOps(NULL), _imgOps(NULL), _io(NULL), _v(Wtv_Uninitilized), _maxCmdParamNum(-1), _minCmdParamNum(-1) - { - _cmdType = SC_No_Cmd; - memset(_errBuff, 0, sizeof(_errBuff)); - } - virtual ~SubCommand(); - virtual FlintStatus executeCommand() = 0; - inline void setParams(const FlintParams& flintParams) {_flintParams = flintParams;} - inline string& getName() {return this->_name;} - inline string& getDesc() {return this->_desc;} - inline string& getExtDesc() {return this->_extendedDesc;} - inline string& getFlagL() {return this->_flagLong;} - inline string& getFlagS() {return this->_flagShort;} - inline string& getParam() {return this->_param;} - inline string& getParamExp() {return this->_paramExp;} - inline string& getExample() {return this->_example;} -}; - -class BurnSubCommand : public SubCommand -{ -private: - u_int8_t _fwType; - fw_info_t _devInfo; - fw_info_t _imgInfo; - FwOperations::ExtBurnParams _burnParams; - bool _devQueryRes; - - FlintStatus burnFs3(); - FlintStatus burnFs2(); - bool checkFwVersion(); - bool checkPSID(); - void updateBurnParams(); - void dealWithExpRom(); - bool checkMatchingExpRomDevId(const fw_info_t& info); - bool dealWithGuids(); - bool dealWithVSD(); -public: - BurnSubCommand(); - ~BurnSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class QuerySubCommand : public SubCommand -{ -private: - FlintStatus printInfo(const fw_info_t& fwInfo, bool fullQuery); - bool displayFs3Uids(const fw_info_t& fwInfo); - bool displayFs2Uids(const fw_info_t& fwInfo); - bool checkMac(u_int64_t mac, string& warrStr); -public: - QuerySubCommand(); - ~QuerySubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class VerifySubCommand : public SubCommand -{ -private: - -public: - VerifySubCommand(); - ~VerifySubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class SwResetSubCommand : public SubCommand -{ -private: - -public: - SwResetSubCommand(); - ~SwResetSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class BromSubCommand : public SubCommand -{ -private: - fw_info_t _info; - roms_info_t _romsInfo; - FImage _fRom; -public: - BromSubCommand(); - ~BromSubCommand(); - inline FlintStatus executeCommand(); - bool getExpRomStrVer(roms_info_t& roms_info, char* version); -}; - -class DromSubCommand : public SubCommand -{ -public: - DromSubCommand(); - ~DromSubCommand(); - FlintStatus executeCommand(); - inline bool verifyParams(); -}; - -class RromSubCommand : public SubCommand -{ -private: - -public: - RromSubCommand(); - ~RromSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class BbSubCommand : public SubCommand -{ -private: - -public: - BbSubCommand(); - ~BbSubCommand(); - FlintStatus executeCommand(); - inline bool verifyParams(); -}; - -class SgSubCommand : public SubCommand -{ -private: - fw_info_t _info; - FwOperations* _ops; - FwOperations::sg_params_t _sgParams; - - FlintStatus sgFs2(); - FlintStatus sgFs3(); - void setUserGuidsAndMacs(); - bool CheckSetGuidsFlags(); -public: - SgSubCommand(); - ~SgSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class SmgSubCommand : public SubCommand -{ -private: - fs3_uid_t _baseGuid; - fw_info_t _info; - FwOperations* _ops; -public: - SmgSubCommand(); - ~SmgSubCommand(); - inline FlintStatus executeCommand(); - inline bool verifyParams(); -}; - -class SetVpdSubCommand : public SubCommand -{ -private: - -public: - SetVpdSubCommand(); - ~SetVpdSubCommand(); - FlintStatus executeCommand(); -}; - -class SvSubCommand : public SubCommand -{ -private: - -public: - SvSubCommand(); - ~SvSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; -class RiSubCommand : public SubCommand -{ -private: - FlintStatus writeImageToFile(const char *file_name, u_int8_t *data, u_int32_t length); -public: - RiSubCommand(); - ~RiSubCommand(); - FlintStatus executeCommand(); -}; - -class DcSubCommand : public SubCommand -{ -private: - std::vector _sect; -public: - DcSubCommand(); - ~DcSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; -class DhSubCommand : public SubCommand -{ -private: - std::vector _sect; -public: - DhSubCommand(); - ~DhSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class SetKeySubCommand : public SubCommand -{ -private: - hw_key_t _userKey; - bool _getKeyInter; - bool getKeyInteractively(); -public: - SetKeySubCommand(); - ~SetKeySubCommand(); - inline FlintStatus executeCommand(); - inline bool verifyParams(); -}; -class HwAccessSubCommand : public SubCommand -{ -private: - FlintStatus disableHwAccess(); - FlintStatus enableHwAccess(); -public: - HwAccessSubCommand(); - ~HwAccessSubCommand(); - FlintStatus executeCommand(); - bool verifyParams(); -}; - -class HwSubCommand : public SubCommand -{ -private: - FlintStatus printAttr(const ext_flash_attr_t& attr); -public: - HwSubCommand(); - ~HwSubCommand(); - inline FlintStatus executeCommand(); - inline bool verifyParams(); -}; -class EraseSubCommand : public SubCommand -{ -private: - -public: - EraseSubCommand(); - ~EraseSubCommand(); - inline FlintStatus executeCommand(); -}; -class RwSubCommand : public SubCommand -{ -private: - -public: - RwSubCommand(); - ~RwSubCommand(); - inline FlintStatus executeCommand(); -}; -class WwSubCommand : public SubCommand -{ -private: - -public: - WwSubCommand(); - ~WwSubCommand(); - inline FlintStatus executeCommand(); -}; - -class WwneSubCommand : public SubCommand -{ -private: - -public: - WwneSubCommand(); - ~WwneSubCommand(); - inline FlintStatus executeCommand(); -}; - -class WbSubCommand : public SubCommand -{ -private: - bool extractData(const std::vector& cmdParams , u_int32_t* addr, std::vector& data); -public: - WbSubCommand(); - ~WbSubCommand(); - FlintStatus executeCommand(); -}; - - -class WbneSubCommand : public SubCommand -{ -private: - bool extractData(const std::vector& cmdParams , u_int32_t* addr, std::vector& data); - bool writeBlock(u_int32_t addr, std::vector dataVec); -public: - WbneSubCommand(); - ~WbneSubCommand(); - FlintStatus executeCommand(); -}; - -class RbSubCommand : public SubCommand -{ -private: - bool printToScreen(const std::vector& buff); - bool readBlock(u_int32_t addr, std::vector& buff, bool isFlash); -public: - RbSubCommand(); - ~RbSubCommand(); - FlintStatus executeCommand(); -}; - -class ClearSemSubCommand : public SubCommand -{ -private: - -public: - ClearSemSubCommand(); - ~ClearSemSubCommand(); - FlintStatus executeCommand(); -}; - -class RomQuerySubCommand : public SubCommand -{ -private: - roms_info_t _romsInfo; -public: - RomQuerySubCommand(); - ~RomQuerySubCommand(); - FlintStatus executeCommand(); -}; - -class ResetCfgSubCommand : public SubCommand -{ -public: - ResetCfgSubCommand(); - ~ResetCfgSubCommand(); - FlintStatus executeCommand(); -}; - -class FiSubCommand : public SubCommand -{ -public: - FiSubCommand(); - ~FiSubCommand(); - FlintStatus executeCommand(); -}; - -class CheckSumSubCommand : public SubCommand -{ -public: - CheckSumSubCommand(); - ~CheckSumSubCommand(); - FlintStatus executeCommand(); -private: - bool extractChecksumFromStr(string str, u_int8_t checkSum[16]); - string checkSum2Str(u_int8_t checkSum[16]); - u_int8_t _checkSum[16]; -}; - -class TimeStampSubCommand : public SubCommand -{ -public: - TimeStampSubCommand(); - ~TimeStampSubCommand(); - FlintStatus executeCommand(); -private: - enum { - TS_No_Command, - TS_Query, - TS_Set, - TS_Reset - }; - - bool verifyParams(); - bool parseTimeStamp(string tsStr); - bool parseFwVersion(string verStr); - inline u_int8_t getDaysInMonth(u_int16_t year, u_int8_t month); - inline void printTsAndFwVer(string prefix, struct tools_open_ts_entry& tsEntry, struct tools_open_fw_version& fwVer); - void getMachineUTCTime(); - bool queryTs(); - bool setTs(); - bool resetTs(); - - int _operation; - FwOperations* _ops; - struct tools_open_ts_entry _userTsEntry; - struct tools_open_fw_version _userFwVer; -}; - -class CacheImageSubCommand : public SubCommand -{ -public: - CacheImageSubCommand(); - ~CacheImageSubCommand(); - FlintStatus executeCommand(); -}; - -#endif diff --git a/gitversion.sh b/gitversion.sh deleted file mode 100755 index 8fe67a4..0000000 --- a/gitversion.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if git rev-parse --short HEAD > gitversion.tmp -then - echo "#define TOOLS_GIT_SHA \"`tr -d '\n' < gitversion.tmp`\"" > $1 -fi -rm gitversion.tmp diff --git a/include/mtcr_ul/mtcr.h b/include/mtcr_ul/mtcr.h deleted file mode 100644 index 5306d0e..0000000 --- a/include/mtcr_ul/mtcr.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef MTCR_H -#define MTCR_H - - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "mtcr_com_defs.h" -#include "mtcr_mf.h" - -typedef enum mtcr_access_method { - MTCR_ACCESS_ERROR = MST_ERROR, - MTCR_ACCESS_MEMORY = MST_PCI, - MTCR_ACCESS_CONFIG = MST_PCICONF, - MTCR_ACCESS_INBAND = MST_IB -} mtcr_access_method_t; -/* - * Read 4 bytes, return number of succ. read bytes or -1 on failure - */ -int mread4(mfile *mf, unsigned int offset, u_int32_t *value); - -/* - * Write 4 bytes, return number of succ. written bytes or -1 on failure - */ -int mwrite4(mfile *mf, unsigned int offset, u_int32_t value); - - -int mread4_block (mfile *mf, unsigned int offset, u_int32_t* data, int byte_len); -int mwrite4_block (mfile *mf, unsigned int offset, u_int32_t* data, int byte_len); - -int msw_reset(mfile *mf); -int mhca_reset(mfile *mf); - -/* - * Get list of MST (Mellanox Software Tools) devices. - * Put all device names as null-terminated strings to buf. - * - * Return number of devices found or -1 if buf overflow - */ -int mdevices(char *buf, int len, int mask); - - -/* - * Get list of MST (Mellanox Software Tools) devices info records. - * Return a dynamic allocated array of dev_info records. - * len will be updated to hold the array length - * - */ -dev_info* mdevices_info(int mask, int* len); - -void mdevice_info_destroy(dev_info* dev_info, int len); -void mdevices_info_destroy(dev_info* dev_info, int len); - -int mget_mdevs_type(mfile *mf, u_int32_t *mtype); - -/* - * Open Mellanox Software tools (mst) driver. Device type==INFINIHOST - * Return valid mfile ptr or 0 on failure - */ -mfile *mopen(const char *name); - -mfile *mopend(const char *name, int type); - -mfile *mopen_fw_ctx(void* fw_cmd_context, void* fw_cmd_func, void* extra_data); - -mfile *mopen_adv(const char *name, MType mtype); - -/* - * Close Mellanox driver - * req. descriptor - */ -int mclose(mfile *mf); - -unsigned char mset_i2c_slave(mfile *mf, unsigned char new_i2c_slave); - -int mget_mdevs_flags(mfile *mf, u_int32_t *devs_flags); - -int maccess_reg_mad(mfile *mf, u_int8_t *data); - -int mos_reg_access(mfile *mf, int reg_access, void *reg_data, u_int32_t cmd_type); - -int maccess_reg_cmdif(mfile *mf, reg_access_t reg_access, void *reg_data, u_int32_t cmd_type); - -int maccess_reg(mfile *mf, - u_int16_t reg_id, - maccess_reg_method_t reg_method, - void* reg_data, - u_int32_t reg_size, - u_int32_t r_size_reg, // used when sending via icmd interface (how much data should be read back to the user) - u_int32_t w_size_reg, // used when sending via icmd interface (how much data should be written to the scratchpad) - // if you dont know what you are doing then r_size_reg = w_size_reg = your_register_size - int *reg_status); - -int icmd_send_command(mfile *mf, int opcode, void* data, int data_size, int skip_write); - -int icmd_clear_semaphore(mfile *mf); - - -int tools_cmdif_send_inline_cmd(mfile* mf, u_int64_t in_param, u_int64_t* out_param, - u_int32_t input_modifier, u_int16_t opcode, u_int8_t opcode_modifier); - -int tools_cmdif_send_mbox_command(mfile* mf, u_int32_t input_modifier, u_int16_t opcode, u_int8_t opcode_modifier, - int data_offs_in_mbox, void* data, int data_size, int skip_write); - -int tools_cmdif_unlock_semaphore(mfile *mf); - - -int mget_max_reg_size(mfile *mf); - -const char* m_err2str(MError status); - -int mread_buffer(mfile *mf, unsigned int offset, u_int8_t* data, int byte_len); -int mwrite_buffer(mfile *mf, unsigned int offset, u_int8_t* data, int byte_len); - -int mget_vsec_supp(mfile* mf); - -int mget_addr_space(mfile* mf); -int mset_addr_space(mfile* mf, int space); - -int mclear_pci_semaphore(const char* name); - -#ifdef __cplusplus -} -#endif - -#define DEV_MST_EXAMPLE1 "mlx4_0" -#define DEV_MST_EXAMPLE2 "03:00.0" - -#endif diff --git a/include/mtcr_ul/mtcr_com_defs.h b/include/mtcr_ul/mtcr_com_defs.h deleted file mode 100644 index 7aa3a38..0000000 --- a/include/mtcr_ul/mtcr_com_defs.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#ifndef _MTCR_COM_DEFS_H -#define _MTCR_COM_DEFS_H - -#ifdef __WIN__ - -#include -#include - -#ifdef MTCR_EXPORTS -#define MTCR_API __declspec(dllexport) -#else -#define MTCR_API __declspec(dllimport) -#endif - -typedef unsigned __int8 u_int8_t; -typedef __int8 int8_t; -typedef unsigned __int16 u_int16_t; -typedef __int16 int16_t; -typedef unsigned __int32 u_int32_t; -typedef __int32 int32_t; -typedef unsigned __int64 u_int64_t; -typedef __int64 int64_t; - -#if defined(_WIN64) - typedef __int64 MT_long_ptr_t; - typedef unsigned __int64 MT_ulong_ptr_t; -#else - typedef _W64 long MT_long_ptr_t; - typedef _W64 unsigned long MT_ulong_ptr_t; -#endif - -#elif defined(__DJGPP__) - - typedef unsigned char u_int8_t; - typedef char int8_t; - typedef unsigned short u_int16_t; - typedef short int16_t; - typedef unsigned int u_int32_t; - typedef long int32_t; - typedef unsigned long long u_int64_t; - typedef long long int64_t; - -#define bswap_32(x) ntohl(x) -#define MTCR_API - -#else /* UNIX */ - -#include -#define MTCR_API - -#endif - -//#ifndef USE_IB_MGT -typedef struct mib_private_t { - int dummy; -} MIB_Private; -//#else -//#include "mtcr_ib_private.h" -//#endif - -typedef enum MError { - ME_OK = 0, - ME_ERROR, - ME_BAD_PARAMS, - ME_CR_ERROR, - ME_NOT_IMPLEMENTED, - - ME_SEM_LOCKED, - ME_MEM_ERROR, - - ME_MAD_SEND_FAILED, - ME_UNKOWN_ACCESS_TYPE, - ME_UNSUPPORTED_DEVICE, - ME_REG_NOT_SUPPORTED, - - ME_PCI_READ_ERROR, - ME_PCI_WRITE_ERROR, - ME_PCI_SPACE_NOT_SUPPORTED, - ME_PCI_IFC_TOUT, - - ME_UNSUPPORTED_OPERATION, - ME_UNSUPPORTED_ACCESS_TYPE, - - // errors regarding REG_ACCESS - ME_REG_ACCESS_OK = 0, - ME_REG_ACCESS_BAD_STATUS_ERR = 0x100, - ME_REG_ACCESS_BAD_METHOD, - ME_REG_ACCESS_NOT_SUPPORTED, - ME_REG_ACCESS_DEV_BUSY, - ME_REG_ACCESS_VER_NOT_SUPP, - ME_REG_ACCESS_UNKNOWN_TLV, - ME_REG_ACCESS_REG_NOT_SUPP, - ME_REG_ACCESS_CLASS_NOT_SUPP, - ME_REG_ACCESS_METHOD_NOT_SUPP, - ME_REG_ACCESS_BAD_PARAM, - ME_REG_ACCESS_RES_NOT_AVLBL, - ME_REG_ACCESS_MSG_RECPT_ACK, - ME_REG_ACCESS_UNKNOWN_ERR, - ME_REG_ACCESS_SIZE_EXCCEEDS_LIMIT, - ME_REG_ACCESS_CONF_CORRUPT, - ME_REG_ACCESS_LEN_TOO_SMALL, - ME_REG_ACCESS_BAD_CONFIG, - ME_REG_ACCESS_ERASE_EXEEDED, - ME_REG_ACCESS_INTERNAL_ERROR, - - // errors regarding ICMD - ME_ICMD_STATUS_CR_FAIL = 0x200, // cr-space access failure - ME_ICMD_INVALID_OPCODE, - ME_ICMD_INVALID_CMD, - ME_ICMD_OPERATIONAL_ERROR, - ME_ICMD_BAD_PARAM, - ME_ICMD_BUSY, - ME_ICMD_INIT_FAILED, - ME_ICMD_NOT_SUPPORTED, - ME_ICMD_STATUS_SEMAPHORE_TO, // timed out while trying to take semaphore - ME_ICMD_STATUS_EXECUTE_TO, // timed out while waiting for command to execute - ME_ICMD_STATUS_IFC_BUSY, - ME_ICMD_STATUS_ICMD_NOT_READY, - ME_ICMD_UNSUPPORTED_ICMD_VERSION, - ME_ICMD_UNKNOWN_STATUS, - ME_ICMD_ICM_NOT_AVAIL, - ME_ICMD_WRITE_PROTECT, - ME_ICMD_SIZE_EXCEEDS_LIMIT, - - //errors regarding Tools CMDIF - ME_CMDIF_BUSY = 0x300, - ME_CMDIF_TOUT, - ME_CMDIF_BAD_STATUS, - ME_CMDIF_BAD_OP, - ME_CMDIF_NOT_SUPP, - ME_CMDIF_BAD_SYS, - ME_CMDIF_UNKN_TLV, - ME_CMDIF_RES_STATE, - ME_CMDIF_UNKN_STATUS, - - //errors regarding MAD IF - ME_MAD_BUSY = 0x400, - ME_MAD_REDIRECT, - ME_MAD_BAD_VER, - ME_MAD_METHOD_NOT_SUPP, - ME_MAD_METHOD_ATTR_COMB_NOT_SUPP, - ME_MAD_BAD_DATA, - ME_MAD_GENERAL_ERR, - - ME_LAST -} MError; - -// typedefs for UEFI -#ifdef UEFI_BUILD -#include -#endif -typedef enum MType_t { - MST_ERROR = 0x0, - MST_FPGA = 0x1, - MST_MLNXOS = 0x2, - MST_LPC = 0x4, - MST_PCI = 0x8, - MST_PCICONF = 0x10, - /*MST_CALBR,*/ - MST_USB = 0x20, - MST_IB = 0x40, - MST_IF = 0x80, - MST_PPC = 0x100, - MST_USB_DIMAX = 0x200, - MST_FWCTX = 0x400, - MST_REMOTE = 0x800, -#ifdef ENABLE_MST_DEV_I2C - MST_DEV_I2C = 0x1000, -#endif - // 0x2000 reserved - MST_FPGA_NEWTON = 0x4000, - MST_CABLE = 0x8000, - MST_DEFAULT = 0xffffffff & ~MST_FPGA & ~MST_CABLE -} MType; - -typedef enum DType_t { - MST_GAMLA, MST_TAVOR, MST_DIMM, MST_NOADDR -} DType; -#define MST_ANAFA2 MST_TAVOR -#define MST_EEPROM MST_GAMLA -typedef enum Mdevs_t { - MDEVS_GAMLA = 0x01, /* Each device that actually is a Gamla */ - MDEVS_I2CM = 0x02, /* Each device that can work as I2C master */ - MDEVS_MEM = 0x04, /* Each device that is a memory driver (vtop) */ - MDEVS_TAVOR_DDR = 0x08, /* Each device that maps to DDR */ - MDEVS_TAVOR_UAR = 0x10, /* Each device that maps to UAR */ - MDEVS_TAVOR_CR = 0x20, /* Each device that maps to CR */ - MDEVS_IF = 0x40, /* Standard device interface */ - MDEVS_REM = 0x80, /* Remote devices */ - MDEVS_PPC = 0x100, /* PPC devices */ - MDEVS_DEV_I2C = 0x200, /* Generic linux kernel i2c device */ - MDEVS_IB = 0x400, /* Cr access over IB Mads */ - MDEVS_MLNX_OS = 0x800, /* access by CmdIf in MlnxOS */ - MDEVS_FWCTX = 0x900, /* access by func/context (like UEFI) */ - MDEVS_LPC = 0x1000,/* Access LPC region */ - MDEVS_FPGA = 0x2000,/* Access LPC region */ - MDEVS_FPGA_NEWTON = 0x4000,/* Access LPC region */ - MDEVS_CABLE = 0x8000, - MDEVS_TAVOR = (MDEVS_TAVOR_DDR | MDEVS_TAVOR_UAR | MDEVS_TAVOR_CR), MDEVS_ALL = 0xffffffff -} Mdevs; - -typedef enum { - MACCESS_REG_METHOD_GET = 1, - MACCESS_REG_METHOD_SET = 2 -} maccess_reg_method_t; - -typedef enum { - AS_ICMD = 3, AS_CR_SPACE = 2, AS_SEMAPHORE = 0xa -} address_space_t; - -typedef struct dev_info_t { - Mdevs type; - char dev_name[512]; - int ul_mode; - - union { - struct { - u_int16_t domain; - u_int8_t bus; - u_int8_t dev; - u_int8_t func; - - u_int16_t dev_id; - u_int16_t vend_id; - u_int32_t class_id; - u_int16_t subsys_id; - u_int16_t subsys_vend_id; - - char cr_dev[512]; - char conf_dev[512]; - char** net_devs; // Null terminated array - char** ib_devs; // Null terminated array - char numa_node[4096]; // - } pci; - - struct { - u_int32_t mtusb_serial; - u_int32_t TBD; - } usb; - - struct { - u_int32_t TBD; - } ib; - - struct { - u_int32_t TBD; - } remote; - }; -} dev_info; - - -typedef enum { - RA_MFPA=0x9010, - RA_MFBA=0x9011, - RA_MFBE=0x9012, -} reg_access_t; - -typedef struct mfile_t mfile; - -#endif diff --git a/include/mtcr_ul/mtcr_mf.h b/include/mtcr_ul/mtcr_mf.h deleted file mode 100644 index d2e0e5b..0000000 --- a/include/mtcr_ul/mtcr_mf.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef __MTCR_MF__ -#define __MTCR_MF__ - -typedef struct icmd_params_t { - int icmd_opened; - int took_semaphore; - int ctrl_addr; - int cmd_addr; - u_int32_t max_cmd_size; - int semaphore_addr; - int static_cfg_not_done_addr; - int static_cfg_not_done_offs; - u_int32_t lock_key; - int ib_semaphore_lock_supported; -} icmd_params; - -typedef struct ctx_params_t { - void *fw_cmd_context; - void *fw_cmd_func; -} ctx_params; - -typedef struct io_region_t { - unsigned int start; - unsigned int end; -} io_region; - -typedef struct tools_hcr_params_t { - int supp_cr_mbox; // 1: mbox supported , -1: mbox not supported -} tools_hcr_params; - -typedef struct access_reg_params_t { - int max_reg_size; -} access_reg_params; - -typedef void (*f_mpci_change) (mfile *mf); - -/* All fields in follow structure are not supposed to be used */ -/* or modified by user programs. Except i2c_slave that may be */ -/* modified before each access to target I2C slave address */ -struct mfile_t { - MType tp; /* type of driver */ - MType res_tp; /* Will be used with HCR if need */ - DType dtype; /* target device to access to */ - DType itype; /* interface device to access via */ - int is_i2cm; /* use device as I2C master */ - int is_vm; /* if the machine is VM */ - int cr_access; /* If cr access is allowed in MLNXOS devices */ - unsigned char i2c_slave; - io_region* iorw_regions; /* For LPC devices */ - int regions_num; - char* dev_name; - int fd; - int res_fd; /* Will be used with HCR if need*/ - int sock; /* in not -1 - remote interface */ - void *ptr; - unsigned int map_size; - unsigned long long start_idx; - /************************ FPGA DDR3 *********************************/ - void *ddr3_ptr; - unsigned long long ddr3_start_idx; - unsigned int ddr3_map_size; - /********************************************************************/ - MIB_Private mib; /* Data for IB interface (if relevant) */ - void *ctx; - unsigned int i2c_RESERVED; /* Reserved for internal usage (i2c internal) */ - enum Mdevs_t flags; - u_int32_t connectx_wa_slot; /* apply connectx cr write workaround */ - int connectx_wa_last_op_write; - u_int32_t connectx_wa_stat; - u_int64_t connectx_wa_max_retries; - u_int64_t connectx_wa_num_of_writes; - u_int64_t connectx_wa_num_of_retry_writes; - int server_ver_major; - int server_ver_minor; - unsigned int proto_type; - dev_info* dinfo; - - //for ICMD access - icmd_params icmd; - // for UEFI - ctx_params context; - // for new pci capability - int old_mst; - int vsec_supp; - unsigned int vsec_addr; - int address_space; - int multifunction; - // for tools HCR access - tools_hcr_params hcr_params; - // for sending access registers - access_reg_params acc_reg_params; - // UL - void* ul_ctx; - // Dynamic libs Ctx - void* dl_context; - // Cables CTX - int is_cable; - void* cable_ctx; - f_mpci_change mpci_change; -}; - -#endif diff --git a/man/mstconfig.1 b/man/mstconfig.1 deleted file mode 100644 index 9c600af..0000000 --- a/man/mstconfig.1 +++ /dev/null @@ -1,249 +0,0 @@ -.TH MSTCONFIG "4.4.0" "" "" -.SH NAME -mstconfig -.IP -.SH SYNOPSIS: -.IP -mstconfig [\-d ] [\-y|\-e] |q[uery]|r[eset]> -.IP -.SH OPTIONS: -.TP -\fB\-d\fR|\-\-dev -: Perform operation for a specified mst device. -.TP -\fB\-f\fR|\-\-file -: raw configuration file. -.TP -\fB\-h\fR|\-\-help -: Display help message. -.TP -\fB\-hh\fR|\-\-full_help -: Display full help message. -.TP -\fB\-v\fR|\-\-version -: Display version info. -.TP -\fB\-e\fR|\-\-show_default -: Show default configurations. -.TP -\fB\-y\fR|\-\-yes -: Answer yes in prompt. -.IP -.SH COMMANDS: -.TP -clear_semaphore -: clear the tool semaphore. -.TP -q[uery] -: query current supported configurations. -.TP -r[eset] -: reset all configurations to their default value. -.TP -s[et] -: set configurations to a specific device. -.TP -set_raw -: set raw configuration file.(5th generation devices only.) -.IP -Supported Configurations: -.IP -\fBBoot Settings Extras:\fR These parameters are relevant only for servers using legacy BIOS PXE boot (flexboot). -.IP -IP_VER= -.IP -IP_VER_P1= -.IP -IP_VER_P2= -.IP -\fBExternal Ports:\fR -.IP -ALLOW_RD_COUNTERS= -.IP -PORT_OWNER= -.IP -\fBIB Dynamically Connect:\fR -.IP -DCR_LIFO_SIZE= -.IP -LOG_DCR_HASH_TABLE_SIZE= -.IP -\fBInfiniband Boot Settings:\fR -.IP -BOOT_PKEY_P1= -.IP -BOOT_PKEY_P2= -.IP -\fBInternal Settings:\fR -.IP -INT_LOG_MAX_PAYLOAD_SIZE=<4KB|Auto> -.IP -\fBPCI Settings:\fR -.IP -FPP_EN= -.IP -LOG_BAR_SIZE= -.IP -NUM_OF_VFS= -.IP -NUM_PF_MSIX= -.IP -NUM_VF_MSIX= -.IP -PF_LOG_BAR_SIZE= -.IP -SRIOV_EN= -.IP -VF_LOG_BAR_SIZE= -.IP -\fBPreboot Boot Settings:\fR Settings that control the legacy option ROM -.IP -BOOT_OPTION_ROM_EN_P1= -.IP -BOOT_OPTION_ROM_EN_P2= -.IP -BOOT_RETRY_CNT_P1=<0..7> -.IP -BOOT_RETRY_CNT_P2=<0..7> -.IP -BOOT_VLAN_EN_P1= -.IP -BOOT_VLAN_EN_P2= -.IP -BOOT_VLAN_P1= -.IP -BOOT_VLAN_P2= -.IP -LEGACY_BOOT_PROTOCOL_P1= -.IP -LEGACY_BOOT_PROTOCOL_P2= -.IP -\fBRoCE Congestion Control ECN:\fR -.IP -CLAMP_TGT_RATE_AFTER_TIME_INC_P1=<0|1> -.IP -CLAMP_TGT_RATE_AFTER_TIME_INC_P2=<0|1> -.IP -CLAMP_TGT_RATE_P1=<0|1> -.IP -CLAMP_TGT_RATE_P2=<0|1> -.IP -CNP_802P_PRIO_P1= -.IP -CNP_802P_PRIO_P2= -.IP -CNP_DSCP_P1=<0..7> -.IP -CNP_DSCP_P2=<0..7> -.IP -DCE_TCP_G_P1= -.IP -DCE_TCP_G_P2= -.IP -DCE_TCP_RTT_P1= -.IP -DCE_TCP_RTT_P2= -.IP -INITIAL_ALPHA_VALUE_P1= -.IP -INITIAL_ALPHA_VALUE_P2= -.IP -MIN_TIME_BETWEEN_CNPS_P1= -.IP -MIN_TIME_BETWEEN_CNPS_P2= -.IP -RATE_REDUCE_MONITOR_PERIOD_P1= -.IP -RATE_REDUCE_MONITOR_PERIOD_P2= -.IP -RATE_TO_SET_ON_FIRST_CNP_P1= -.IP -RATE_TO_SET_ON_FIRST_CNP_P2= -.IP -RPG_AI_RATE_P1= -.IP -RPG_AI_RATE_P2= -.IP -RPG_BYTE_RESET_P1= -.IP -RPG_BYTE_RESET_P2= -.IP -RPG_GD_P1=<0..15> -.IP -RPG_GD_P2=<0..15> -.IP -RPG_HAI_RATE_P1= -.IP -RPG_HAI_RATE_P2= -.IP -RPG_MAX_RATE_P1= -.IP -RPG_MAX_RATE_P2= -.IP -RPG_MIN_DEC_FAC_P1=<1..100> -.IP -RPG_MIN_DEC_FAC_P2=<1..100> -.IP -RPG_MIN_RATE_P1= -.IP -RPG_MIN_RATE_P2= -.IP -RPG_THRESHOLD_P1=<0..31> -.IP -RPG_THRESHOLD_P2=<0..31> -.IP -RPG_TIME_RESET_P1= -.IP -RPG_TIME_RESET_P2= -.IP -\fBRoCE Congestion Control Parameters:\fR -.IP -ROCE_CC_ALGORITHM_P1= -.IP -ROCE_CC_ALGORITHM_P2= -.IP -ROCE_CC_PRIO_MASK_P1=<0..255> -.IP -ROCE_CC_PRIO_MASK_P2=<0..255> -.IP -\fBRoCE V1.5 next protocol:\fR -.IP -ROCE_NEXT_PROTOCOL=<0..255> -.IP -\fBVPI Settings:\fR Control network link type -.IP -LINK_TYPE_P1= -.IP -LINK_TYPE_P2= -.IP -\fBWake On LAN:\R -.IP -WOL_MAGIC_EN= -.IP -WOL_MAGIC_EN_P1= -.IP -WOL_MAGIC_EN_P2= -.IP -.SH Examples: -.TP -To query current configuration -: mstconfig \fB\-d\fR \fI04:00.0\fP query -.TP -To set configuration -: mstconfig \fB\-d\fR \fI05:00.0\fP set SRIOV_EN=1 NUM_OF_VFS=16 WOL_MAGIC_EN_P1=1 -.TP -To set raw configuration -: mstconfig \fB\-d\fR \fI05:00.0\fP \fB\-f\fR conf_file set_raw -.TP -To reset configuration -: mstconfig \fB\-d\fR \fI04:00.0\fP reset -.IP -.SH Supported devices: -.IP -4th Generation devices: ConnectX3, ConnectX3\-Pro (FW 2.31.5000 and above). -.IP -5th Generation devices: ConnectIB, ConnectX4, ConnectX4\-LX. -.IP -.TP -\fBNote: query device to view supported configurations.\fR - diff --git a/man/mstflint.1 b/man/mstflint.1 deleted file mode 100644 index 4e87267..0000000 --- a/man/mstflint.1 +++ /dev/null @@ -1,965 +0,0 @@ -.\"Text automatically generated by txt2man -.TH mstflint 4.4.0 "May 2016" "" "" -.SH NAME -\fBmstflint \fP- Flash Interface -.SH SYNOPSIS -.nf -.fam C - \fBmstflint\fP [\fIOPTIONS\fP] [\fIParameters\fP] - [\fB-d\fP|\fB--device\fP ] [\fB--guid\fP ] - [\fB--guids\fP ] [\fB--mac\fP ] - [\fB--macs\fP ] [\fB--uid\fP ] - [\fB--blank_guids\fP] [\fB--clear_semaphore\fP] - [\fB-h\fP|\fB--help\fP] [\fB--hh\fP] [\fB-i\fP|\fB--image\fP ] - [\fB--qq\fP] [\fB--nofs\fP] [\fB--allow_psid_change\fP] [\fB--allow_rom_change\fP] - [\fB--override_cache_replacement\fP] [\fB--no_flash_verify\fP] - [\fB-s\fP|\fB--silent\fP] [\fB-y\fP|\fB--yes\fP] [\fB--no\fP] [\fB--vsd\fP ] - [\fB--use_image_ps\fP] [\fB--use_image_guids\fP] - [\fB--use_image_rom\fP] [\fB--dual_image\fP] [\fB--ignore_dev_data\fP] - [\fB--use_fw\fP] [\fB--striped_image\fP] [\fB--banks\fP ] - [\fB--log\fP ] [\fB--flash_params\fP ] - [\fB-v\fP|\fB--version\fP] -.fam T -.fi -.fam T -.fi -.SH DESCRIPTION -\fBmstflint\fP [\fIOPTIONS\fP] [\fIParameters\fP] -mstflint is a FW (firmware) burning and flash memory operations tool for -Mellanox Infiniband HCAs, Ethernet NIC cards, and switch devices. -.SH OPTIONS -\fBmstflint\fP [\fIOPTIONS\fP] [\fIParameters\fP] -.RS -.TP -.B -\fB-d\fP|\fB--device\fP -: Device flash is connected to. -Commands affected: all -.TP -.B -\fB--guid\fP -: GUID base value. 4 GUIDs -are automatically assigned to the following -values: -.RS -.TP -.B -guid --> node GUID -guid+1 -> port1 -guid+2 -> port2 -guid+3 -> system image GUID. -.PP -Note: port2 guid will be assigned even -for a -single port HCA - The HCA ignores this value. -.PP -Commands affected: burn, sg -.RE -.TP -.B -\fB--guids\fP -: 4 GUIDs must be specified here. -The specified GUIDs are assigned -to the following fields, respectively: -node, port1, port2 and system image GUID. -.RS -.PP -Note: port2 guid must be specified even -for a -single port HCA - The HCA ignores this value. -It can be set to 0x0. -.PP -Commands affected: burn, sg -.RE -.TP -.B -\fB--mac\fP -: MAC address base value. 2 MACs -are automatically assigned to the -following values: -.RS -.TP -.B -mac --> port1 -.TP -.B -mac+1 --> port2 -.PP -Commands affected: burn, sg -.RE -.TP -.B -\fB--macs\fP -: 2 MACs must be specified here. -The specified MACs are assigned -to port1, port2, respectively. -Commands affected: burn, sg -.RS -.PP -Note: \fB-mac\fP/\fB-macs\fP flags are applicable only -for Mellanox -Technologies ethernet products. -.RE -.TP -.B -\fB--uid\fP -: ConnectIB/SwitchIB only. Derive and set the device UIDs -(GUIDs, MACs). -UIDs are derived from the given base UID -according to Mellanox Methodology -Commands affected: burn, sg -.TP -.B -\fB--blank_guids\fP -: Burn the image with blank GUIDs and MACs -(where -applicable). These values can be -set later using -the "sg" command (see details below). -.RS -.PP -Commands affected: burn -.RE -.TP -.B -\fB--clear_semaphore\fP -: Force clear the flash semaphore on the device. -No command is allowed when this flag is -used. -NOTE: May result in system instability -or flash -corruption if the device or another -application is currently using the flash. -Exercise caution. -.TP -.B -\fB-h\fP|\fB--help\fP -: Prints this message and exits -.TP -.B -\fB--hh\fP -: Prints extended command help -.TP -.B -\fB-i\fP|\fB--image\fP -: Binary image file. -Commands affected: burn, verify -.TP -.B -\fB--qq\fP -: Run a quick query. When specified, mstflint -will not perform full -image integrity checks during the query -operation. This may shorten -execution time when running over slow interfaces -(e.g., I2C, MTUSB-1). -Commands affected: burn, query -.TP -.B -\fB--nofs\fP -: Burn image in a non failsafe manner. -.TP -.B -\fB--allow_psid_change\fP -: Allow burning a FW image with a different -PSID (Parameter Set ID)than the -one currently on flash. Note that changing -a PSID may cause the device to -malfunction. Use only if you know what you -are doing -.TP -.B -\fB--allow_rom_change\fP -: Allow burning/removing a ROM to/from FW image -when product version is present. -Use only if you know what you are doing -.TP -.B -\fB--override_cache_replacement\fP -: On SwitchX/ConnectIB devices: -Allow accessing the flash even if the cache -replacement mode is enabled. -NOTE: This flag is intended for advanced -users only. -Running in this mode may cause the firmware -to hang. -.TP -.B -\fB--no_flash_verify\fP -: Do not verify each write on the flash. -.TP -.B -\fB-s\fP|\fB--silent\fP -: Do not print burn progress flyer. -Commands affected: burn -.TP -.B -\fB-y\fP|\fB--yes\fP -: Non interactive mode - assume answer -"yes" to all questions. -Commands affected: all -.TP -.B -\fB--no\fP -: Non interactive mode - assume answer -"no" to all questions. -Commands affected: all -.TP -.B -\fB--vsd\fP -: Write this string, of up to 208 characters, -to VSD when burn. -.TP -.B -\fB--use_image_ps\fP -: Burn vsd as appears in the given image - -do not keep existing VSD on flash. -Commands affected: burn -.TP -.B -\fB--use_image_guids\fP -: Burn (guids/uids/macs) as appears in the -given image. -Commands affected: burn -.TP -.B -\fB--use_image_rom\fP -: Do not save the ROM which exists in the device. -Commands affected: burn -.TP -.B -\fB--ignore_dev_data\fP -: Do not attempt to take device data sections -from device(sections will be taken from the image. FS3 Only). -Commands affected: burn -.TP -.B -\fB--use_fw\fP -: Access to flash using FW (ConnectX3/ConnectX3Pro Device Only) -Commands affected: all -.TP -.B -\fB--dual_image\fP -: Make the burn process burn two images on -flash (previously default algorithm). Currentdefault -failsafe burn process burns a single image -(in alternating locations). -Commands affected: burn -.TP -.B -\fB--striped_image\fP -: Use this flag to indicate that the given -image file is in a "striped image" format. -Commands affected: query verify -.TP -.B -\fB--banks\fP -: Set the number of attached flash devices -(banks) -.TP -.B -\fB--log\fP -: Print the burning status to the specified -log file -\fB--flash_params\fP : Use the given parameters to access the flash -instead of reading them from the flash. -Supported parameters: -Type: The type of the flash, such as: M25PXxx, -M25Pxx, N25Q0XX, SST25VFxx, W25QxxBV, W25Xxx, -AT25DFxxx, S25FLXXXP. -log2size: The log2 of the flash size.num_of_flashes: -the number of the flashes connected to the -device. -.TP -.B -\fB-v\fP|\fB--version\fP -: Version info. -.RE -.RE -.PP -.SH -COMMANDS SUMMARY: -.RS -.TP -.B -burn|b -: Burn flash -.TP -.B -query|q [full] - : Query misc. flash/firmware characteristics, use "full" -to get more information. -.TP -.B -verify|v [showitoc] - : Verify entire flash, use "showitoc" to see ITOC headers -in FS3 image only. -.TP -.B -swreset - : SW reset the target un-managed switch device. This command -is supported only in the In-Band access method. -.TP -.B -brom - : Burn the specified ROM file on the flash. -.TP -.B -drom - : Remove the ROM section from the flash. -.TP -.B -rrom - : Read the ROM section from the flash. -.TP -.B -bb -: Burn Block - Burns the given image as is. No checks are done. -.TP -.B -sg -[guids_num= step_size=] -[nocrc] : Set GUIDs. - -.TP -.B -set_vpd -[vpd file] : Set read-only VPD (For FS3 image only). -.TP -.B -sv -: Set the VSD. -.TP -.B -ri - : Read the fw image on the flash. -.TP -.B -dc -[out-file] : Dump Configuration: print fw configuration file for the given image. -.TP -.B -dh -[out-file] : Dump Hash: dump the hash if it is integrated in the FW image -.TP -.B -set_key -[key] : Set/Update the HW access key which is used to enable/disable access to HW. -The key can be provided in the command line or interactively typed after -the command is given -NOTE: The new key is activated only after the device is reset. -.TP -.B -hw_access - [key] : Enable/disable the access to the HW. -The key can be provided in the command line or interactively typed after -the command is given -.TP -.B -hw - [ATTR=VAL] : Set/query HW info and flash attributes. -.TP -.B -erase|e -: Erases sector. -.TP -.B -rw - : Read one dword from flash -.TP -.B -ww - : Write one dword to flash -.TP -.B -wwne - : Write one dword to flash without sector erase -.TP -.B -wbne - : Write a data block to flash without sector erase. -.TP -.B -wb - : Write a data block to flash. -.TP -.B -rb - [out-file] : Read a data block from flash -.TP -.B -qrom - : query rom in a given image. - .TP -.B -checksum|cs - : perform MD5 checksum on FW. -.TP -.B -timestamp|ts [timestamp] [FW version] - : FW time stamping. -.RE -.PP - -.RE -.PP -.SH -COMMANDS DESCRIPTION: -.RS -.SS - -.TP -.B -\fIName\fP: burn -.IP -\fIDescription\fP: Burn flash. Performs failsafe FW update from a raw binary image. -.IP -\fICommand\fP: burn|b -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 \fB-i\fP image1.bin burn -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 \fB-guid\fP 0x2c9000100d050 \fB-i\fP image1.bin b - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: query -.IP -\fIDescription\fP: Query miscellaneous FW and flash parameters. -.IP -Display FW Version, GUIDs, PSID, and other info. -.IP -\fICommand\fP: query|q [full] -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 query - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: verify -.IP -\fIDescription\fP: Verify entire flash. -.IP -\fICommand\fP: verify|v [showitoc] -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 v - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: swreset -.IP -\fIDescription\fP: SW reset the target un-managed switch device. -.IP -This command is supported only in the In-Band access method. -.IP -\fICommand\fP: swreset -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: None - -."*************************************************************************************** -.RE -.TP -.B -\fIName\fP: brom -.IP -\fIDescription\fP: Burn the specified exp-ROM on the flash. -.IP -\fICommand\fP: brom -.IP -\fIParameters\fP: file: The exp-ROM file. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 brom exp-rom.rom - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: drom -.IP -\fIDescription\fP: Remove the exp-ROM from the flash if it is existing. -.IP -\fICommand\fP: drom -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 drom - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: rrom -.IP -\fIDescription\fP: Read the exp-ROM from the flash if it is existing. -.IP -\fICommand\fP: rrom -.IP -\fIParameters\fP: file: filename to write the exp-ROM to. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 rrom exp-rom.rom - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: bb -.IP -\fIDescription\fP: Burns entire flash verbatim from raw binary image. No checks are done on the flash or -.IP -on the given image file. No fields (such as VSD or Guids) are read from flash. -.IP -\fICommand\fP: bb -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 \fB-i\fP image1.bin bb - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: sg -.IP -\fIDescription\fP: Set GUIDs/MACs/UIDs in the given device/image. -.IP -Use \fB-guid\fP(s), \fB-mac\fP(s) and \fB-uid\fP(s) flags to set the desired values. -.IP -- On pre-ConnectX devices, the sg command is used in production to apply GUIDs/MACs values -.IP -to cards that were pre-burnt with blank GUIDs. It is not meant for use in field. -.IP -On 4th generation devices, this command can operate on both image file and image on flash. -.IP -If the GUIDs/MACs/UIDs in the image on flash are non-blank, -.IP -mstflint will re-burn the current image using the given GUIDs/MACs/UIDs. -.IP -\fICommand\fP: sg [guids_num= step_size=] | [nocrc] -.IP -\fIParameters\fP: -.IP -nocrc: (optional) When specified the mstflint would not update -.IP -the full image crc after changing the guids -.IP -num_of_guids: number of GUIDs to be allocated per physical port (FS3 Only) -.IP -step_size: step size between GUIDs (FS3 Only) -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 \fB-guid\fP 0x0002c9000100d050 sg -.IP \(bu 4 -mstflint -d 08:00.0 -guid 0x0002c9000100d050 -mac 0x0002c900d050 sg - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: set vpd -.IP -\fIDescription\fP: Set Read-only VPD, Set VPD in the given FS3 image. -.IP -\fICommand\fP: set_vpd [vpd file] -.IP -\fIParameters\fP: vpd file: bin file containing the vpd data -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-i\fP fw_image.bin set_vpd vpd.bin - -."*************************************************************************************** - -.RE -.TP -.b -\fIName\fP: sv -.IP -\fIDescription\fP: Set VSD in the given device/image. -.IP -Use \fB-vsd\fP flag to set the desired VSD string. -.IP -\fICommand\fP: sv -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 \fB-vsd\fP VSD_STRING sv - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: ri -.IP -\fIDescription\fP: Read the FW image from flash and write it to a file. -.IP -\fICommand\fP: ri -.IP -\fIParameters\fP: file: filename to write the image to (raw binary). -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 ri file.bin - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: dc -.IP -\fIDescription\fP:Print (to screen or to a file) the FW configuration text file used by the image generation process. -.IP -This command would fail if the image does not contain a FW configuration section. Existence of this -.IP -section depends on the version of the image generation tool. -.IP -\fICommand\fP: dc [out-file] -.IP -\fIParameters\fP: file: (optional) filename to write the dumped configuration to. If not given, the data is printed to screen. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 dc - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: dh -\fIDescription\fP: Print (to screen or to a file) the HASH text file used by the FW. -.IP -This command would fail if the image does not contain a Hash file. -.IP -\fICommand\fP: dh [out-file] -.IP -\fIParameters\fP: file - (optional) filename to write the dumped tracer hash file to. If not given, the data is printed to screen. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 dh hash.csv - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: set_key -.IP -\fIDescription\fP: Set/Update the HW access key which is used to enable/disable access to HW. -.IP -\fICommand\fP: set_key [key] -.IP -\fIParameters\fP: key: (optional) The new key you intend to set (in hex). -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 set_key 1234deaf5678 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: hw_access -.IP -\fIDescription\fP: Enable/disable the access to the HW. -.IP -\fICommand\fP: hw_access [key] -.IP -\fIParameters\fP: : Specify if you intend to disable or enable the HW access. -.IP -You will be asked to type a key when you try to enable HW access. -.IP -.B -key: (optional) The key you intend to use for enabling the HW access. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 hw_access enable - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: hw -.IP -\fIDescription\fP: Access HW info and flash attributes. -.IP -\fICommand\fP: hw [ATTR=VAL] -.IP -\fIParameters\fP: query: query HW info -.IP -set [ATTR=VAL]: set flash attribure -.IP -Supported attributes: -.IP -QuadEn: can be 0 or 1 -.IP -DummyCycles: can be [1..15] -.IP -Flash[0|1|2|3].WriteProtected can be: -.IP -,<1|2|4|8|16|32|64>- -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 hw query -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 hw set QuadEn=1 -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 hw set Flash1.WriteProtected=Top,1-SubSectors - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: erase -.IP -\fIDescription\fP: Erases a sector that contains specified address. -.IP -\fICommand\fP: erase|e -.IP -\fIParameters\fP: addr - address of word in sector that you want to erase. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 erase 0x10000 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: rw -.IP -\fIDescription\fP: Read one dword from flash. -.IP -\fICommand\fP: rw -.IP -\fIParameters\fP: addr - address of word to read -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 rw 0x20 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: ww -.IP -\fIDescription\fP: Write one dword to flash. -.IP -Note that the utility will read an entire flash sector, -.IP -modify one word and write the sector back. This may take a few seconds. -.IP -\fICommand\fP: ww -.IP -\fIParameters\fP: addr - address of word -.IP -data - value of word -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 ww 0x10008 0x5a445a44 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: wwne -.IP -\fIDescription\fP: Write one dword to flash without sector erase. -.IP -Note that the result of operation is undefined and depends -.IP -on flash type. Usually "bitwise AND" (&) between specified -.IP -word and previous flash contents will be written to specified address. -.IP -\fICommand\fP: wwne -.IP -\fIParameters\fP: -.IP -addr - address of word -.IP -data - value of word -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 wwne 0x10008 0x5a445a44 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: wbne -.IP -\fIDescription\fP: Write a block of data to the flash without erasing. -.IP -\fICommand\fP: wbne -.IP -\fIParameters\fP: addr - address of block -.IP -size - size of data to write in bytes -.IP -data - data to write - space separated dwords -.IP -Examples: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 wbne 0x10000 12 0x30000 0x76800 0x5a445a44 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: wb -.IP -\fIDescription\fP: Write a block of data to the flash. -.IP -\fICommand\fP: wb -.IP -\fIParameters\fP: data-file - file that contains the data to be written -.IP -addr - address to write the block to -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 wb myData.bin 0x0 - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: rb -.IP -\fIDescription\fP: -.IP -Read a data block from the flash and write it to a file or to screen. -.IP -\fICommand\fP: rb [out-file] -.IP -\fIParameters\fP: addr - address of block -.IP -size - size of data to read in bytes -.IP -file - filename to write the block (raw binary). If not given, the data is printed to screen. -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 rb 0x10000 100 file.bin - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: qrom -.IP -\fIDescription\fP: query rom in a given image. -.IP -\fI'Command\fP: qrom -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-i\fP fw_image.bin qrom -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: checksum -.IP -\fIDescription\fP: perform an MD5 checksum on relevant(non-persistent between FW upgrades) data on device/image. -.IP -\fI'Command\fP: checksum|cs -.IP -\fIParameters\fP: None -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 checksum - -."*************************************************************************************** - -.RE -.TP -.B -\fIName\fP: time stamp -.IP -\fIDescription\fP: set/query/reset time stamp on device/image. -.IP -\fI'Command\fP: timestamp|ts [timestamp] [FW version] -.IP -\fIParameters\fP: - set [FW version] : set the specified timestamp. if set on device FW version must be specified - timestamp should comply with ISO 8601 format and provided with UTC timezone: YYYY-MM-DDThh:mm:ssZ - query : query device/image to view the timestamp - reset : reset the timestamp, remove the timestamp from device/image. -.IP -\fIExamples\fP: -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 ts set 2015\-12\-24T14:52:33Z 14.12.1100 -.IP \(bu 4 -mstflint \fB-d\fP 04:00.0 ts reset -.IP \(bu 4 -mstflint \fB-i\fP ./fw4115.bin ts set -.IP \(bu 4 -mstflint \fB-i\fP ./fw4115.bin ts query - -.RE -Return values: -0 - Successful completion -1 - An error has occurred -7 - For burn command - FW already updated - burn was aborted. diff --git a/man/mstmcra.1 b/man/mstmcra.1 deleted file mode 100644 index d7a72e2..0000000 --- a/man/mstmcra.1 +++ /dev/null @@ -1,34 +0,0 @@ -.TH MSTMCRA "4.4.0" "" "" -.SH NAME -mstmcra -.IP -.SH SYNOPSIS: -.IP -Mellanox Configuration Registers Access tool - -mstmcra [-s ] [-a ] [-v] [-h] - :]|[,]> [data] - - If data is given, operation is write. Otherwise it is read. - If a bit range is given in the address (E.G.: 0xf0014.16:8): - For read - Only the requested bits are printed. - For write - Read-Modify-Write. Only the requested bits are changed. - If 'bytes number' is given in the address (E.G.: 0xf0014,16): - For read - Will read a block (its size is the given bytes number). - For write - User need to give list of dwrods to write, - number of dwords should be (bytes number/4). -.IP -.SH OPTIONS: -.TP -\fB-s\fR : I2C slave address. -.TP -\fB-a\fR : adb dump file, used for access by path. -.TP -\fB-h\fR : Print this help message. -.TP -\fB-v\fR : Display version info -.IP -.SH Environment Vairables: -.TP -ADB_DUMP : Holds the path to adb dump, used for access by path (can be overriden by "\-a"). -.TP diff --git a/man/mstmread.1 b/man/mstmread.1 deleted file mode 100644 index 5946cc1..0000000 --- a/man/mstmread.1 +++ /dev/null @@ -1,10 +0,0 @@ -.TH MSTMREAD "4.4.0" "" "" -.SH NAME -mstmread -.IP -.SH SYNOPSIS: -.IP -Mellanox Read Configuration Register Tool - -mstmread -.IP diff --git a/man/mstmtserver.1 b/man/mstmtserver.1 deleted file mode 100644 index bccd186..0000000 --- a/man/mstmtserver.1 +++ /dev/null @@ -1,16 +0,0 @@ -.TH MSTMTSERVER "4.4.0" "" "" -.SH NAME -mstmtserver -.IP -.SH SYNOPSIS: -.IP -mstmtserver [options] -.IP -.SH OPTIONS: -.TP -\fB-p\fR[ort] - Listen to specify port (default is 23108). -.TP -\fB-d\fR[ebug] - Print all socket traffic (for debuging only). -.TP -\fB-h\fR[elp] - Print help message. -.TP diff --git a/man/mstmwrite.1 b/man/mstmwrite.1 deleted file mode 100644 index 9a1464d..0000000 --- a/man/mstmwrite.1 +++ /dev/null @@ -1,10 +0,0 @@ -.TH MSTMWRITE "4.4.0" "" "" -.SH NAME -mstmwrite -.IP -.SH SYNOPSIS: -.IP -Mellanox Write Configuration Register Tool - -mstmread -.IP diff --git a/man/mstregdump.1 b/man/mstregdump.1 deleted file mode 100644 index bf29abd..0000000 --- a/man/mstregdump.1 +++ /dev/null @@ -1,23 +0,0 @@ -.TH MSTREGDUMP "4.4.0" "" "" -.SH NAME -mstregdump -.IP -.SH SYNOPSIS: -.IP -Mellanox mstdump utility, dumps device internal configuration data - -mstregdump [-full] [i2c-slave] [-v[ersion] [-h[elp]]] -.IP -.SH OPTIONS: -.TP -\fB-full\fR : Dump more expanded list of addresses - \fBNote\fR : be careful when using this flag, None safe addresses might be read. -.TP -\fB-h\fR : Print this help message. -.TP -\fB-v\fR : Display version info -.IP -.SH EXAMPLE: -.TP -mstregdump 04:00.0 -.TP diff --git a/man/mstvpd.1 b/man/mstvpd.1 deleted file mode 100644 index 2f69f81..0000000 --- a/man/mstvpd.1 +++ /dev/null @@ -1,37 +0,0 @@ -.TH MSTVPD "4.4.0" "" "" -.SH NAME -mstvpd -.IP -.SH SYNOPSIS: -.IP -Mellanox VPD read tool - -mstvpd [-m|-n] [-t ##] [\-- keyword ...] -.IP -.SH OPTIONS: -.TP -\fB-h\fR :Print this help. -.TP -\fB-v\fR :Print tool version. -.TP -\fB-m\fR :Dump raw VPD data to stdout. -.TP -\fB-n\fR :Do not validate check sum. -.TP -\fB-r\fR :Do not check and display the VPD_W tag in the vpd data. -.TP -\fB-t\fR ## :Time out after ## seconds. (Default is 30.) -.IP -.SH File: -.TP -The PCI id number of the HCA (for example, "2:00.0"), -.TP -the device name (such as "mlx4_0") -.TP -the absolute path to the device ("/sys/class/infiniband/mlx4_0/device") -.TP -or '-' to read VPD data from the standard input. -.IP -.SH Keyword(s): -.TP -Only display the requested information. (ID, PN, EC, SN, etc...) diff --git a/mflash/Makefile.am b/mflash/Makefile.am deleted file mode 100644 index 44ac7cc..0000000 --- a/mflash/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in -AM_CPPFLAGS = -I. -I$(top_srcdir)/include/mtcr_ul -I$(top_srcdir)/common -I$(top_srcdir)/tools_layouts -I$(top_srcdir)/reg_access \ - -I$(top_srcdir)/cmdif -I$(top_srcdir)/tools_res_mgmt - -AM_CFLAGS = -MD -pipe -Wall -W -DMST_UL -g ${MFLASH_INBAND_FLAG} - -noinst_LTLIBRARIES = libmflash.a - -libmflash_a_SOURCES = mflash.c mflash.h\ - mflash_pack_layer.c mflash_pack_layer.h mflash_access_layer.c mflash_access_layer.h\ - mflash_types.h mlash_common_structs.h - -noinst_HEADERS = mflash.h mflash_types.h mflash_common_structs.h diff --git a/mflash/mflash.c b/mflash/mflash.c deleted file mode 100644 index 299441c..0000000 --- a/mflash/mflash.c +++ /dev/null @@ -1,3094 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -#ifdef IRISC - -#define NULL 0 - -#else - -#include -#include -#include -#include - -#include -#include -#include - -#ifndef UEFI_BUILD -#include -#endif - -#include "mflash_pack_layer.h" -#include "mflash_access_layer.h" -#include "mflash.h" - -#define ICMD_MAX_BLOCK_WRITE 128 -#define INBAND_MAX_BLOCK_WRITE 32 - -#define ARR_SIZE(arr) sizeof(arr)/sizeof(arr[0]) - -#ifndef __WIN__ - -#if defined __DJGPP__ -// -// DJGPP - GCC PORT TO MS DOS -// -#include -#include - -#define bswap_32(x) ntohl(x) - -#endif // __DJGPP__ - -#define OP_NOT_SUPPORTED EOPNOTSUPP - -#else // __WIN__ - -// -// Windows (Under DDK) -// -#define OP_NOT_SUPPORTED EINVAL -#define usleep(x) Sleep(((x + 999)/1000)) - -#endif // __WIN__ -#endif - -#ifndef zero -#define zero 0 -#endif - -// Timer definitions (needed when polling flash semaphore in windows) -#ifndef __WIN__ -#define TIMER_INIT(...) -#define TIMER_STOP(...) -#define TIMER_PRINT(...) -#define TIMER_GET_DIFF(...) -#define TIMER_INIT_AND_START(...) -#define TIMER_STOP_GET_DIFF(...) -#define TIMER_CHECK(...) -#else -#include -#define TIMER_INIT()\ - SYSTEMTIME _start, _end;\ - int _diff_in_sec, _diff_in_ms;\ - (void)_diff_in_sec;\ - (void)_diff_in_ms -#define TIMER_START()\ - GetSystemTime(&_start) -#define TIMER_STOP()\ - GetSystemTime(&_end) -#define TIMER_PRINT(...)\ - _diff_in_sec = _end.wSecond - _start.wSecond;\ - _diff_in_ms = (_end.wMilliseconds - _start.wMilliseconds;\ - printf(__VA_ARGS__);\ - printf("it took %d sec %d and ms to run.\n", _diff_in_sec, _diff_in_ms) -#define TIMER_GET_DIFF(diff_in_sec, diff_in_ms)\ - diff_in_sec = _end.wSecond - _start.wSecond;\ - diff_in_ms = _end.wMilliseconds - _start.wMilliseconds -#define TIMER_INIT_AND_START()\ - TIMER_INIT();\ - TIMER_START() -#define TIMER_STOP_GET_DIFF(diff_in_sec, diff_in_ms)\ - TIMER_STOP();\ - TIMER_GET_DIFF(diff_in_sec, diff_in_ms) -#define TIMER_CHECK(max_sec, max_ms, action_on_tout)\ - TIMER_STOP();\ - _diff_in_sec = _end.wSecond - _start.wSecond;\ - _diff_in_ms = _end.wMilliseconds - _start.wMilliseconds;\ - if (_diff_in_sec >= max_sec && _diff_in_ms > max_ms) {\ - action_on_tout;\ - } -#endif - -// -// Mellanox Technologies LTD Devices naming/abbreviation convention in this file: -// -// ConnectX cntx -// ConnectIB cib - - -/* -* Low level operations -*/ - -/* Flash Functions: */ - -// This is an interface function when running in IRISC -int mf_open_fw(mflash* mfl, flash_params_t* flash_params, int num_of_banks); -int cntx_int_spi_get_status_data(mflash* mfl, u_int8_t op_type, u_int32_t* status, u_int8_t data_num); - -// forward decl: -int mfl_com_lock(mflash* mfl); -int release_semaphore(mflash* mfl, int ignore_writer_lock); - - -// NOTE: This macro returns ... not nice. -#define CHECK_RC(rc) do {if (rc) return rc;} while(0) -#define CHECK_RC_REL_SEM(mfl, rc) do {if (rc) {release_semaphore(mfl, 0); return rc;}} while(0) - -#define ARRSIZE(arr) (sizeof(arr)/sizeof(arr[0])) - -#ifdef ESS -#define MREAD4(offs, val) do {*val=READ_WORD(offs);} while (0) -#define MWRITE4(offs, val) do {WRITE_WORD(offs, val);} while (0) -#else -#define MREAD4(offs, val) do { if (mread4 (mfl->mf, offs, val) != 4) { \ - /*fprintf(stderr, "-E- Cr read (0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), strerror(errno), (u_int32_t)errno);*/ \ - return 2; } /*printf("-D- %s:%d mread4: offs = %#x, val = %#x\n", __FUNCTION__, __LINE__, offs, val);*/\ - } while (0) - -#define MWRITE4(offs, val) do { if (mwrite4(mfl->mf, offs, val) != 4) { \ - /*fprintf(stderr, "-E- Cr write (0x%08x, 0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), (u_int32_t)(val), strerror(errno), (u_int32_t)errno);*/ \ - return 2; } /*printf("-D- %s:%d mwrite4: offs = %#x, val = %#x\n", __FUNCTION__, __LINE__, offs, val);*/ \ - } while (0) -#endif - -// Constants: - -// General: -#define GPIO_DIR_L 0xf008c -#define GPIO_POL_L 0xf0094 -#define GPIO_MOD_L 0xf009c -#define GPIO_DAT_L 0xf0084 -#define GPIO_DATACLEAR_L 0xf00d4 -#define GPIO_DATASET_L 0xf00dc - -#define SEMAP63 0xf03fc - -// InfiniHost specific -#define IDLE 0 -#define READ4 (1<<29) -#define WRITE1 (2<<29) - -#define CR_FLASH 0xf01a4 -#define ADDR_MSK 0x7ffffUL -#define CMD_MASK 0xe0000000UL - -#define SST_STATUS_REG_VAL 0x80 -#define ATMEL_STATUS_REG_VAL 0x0 - -#define CPUMODE_MSK 0xc0000000UL -#define CPUMODE_SHIFT 30 -#define CPUMODE 0xf0150 - -#define IS4_HW_ID 0x1b3 -#define SWITCHX_HW_ID 0x245 -#define CONNECTX_HW_ID 0x190 -#define CX3_PRO_HW_ID 0x1F7 -#define CX3_HW_ID 0x1F5 -#define CX4_HW_ID 0x209 -#define CX4LX_HW_ID 0x20b -#define CX5_HW_ID 0x20d -#define CONNECT_IB_HW_ID 0x1FF -#define SWITCH_IB_HW_ID 0x247 -#define SPECTRUM_HW_ID 0x249 -#define SWITCH_IB2_HW_ID 0x24b - -/* - * Device IDs Macros: - */ - -#define IS_CONNECTX_4TH_GEN_FAMILY(dev_id) \ - (((dev_id) == CONNECTX_HW_ID) || ((dev_id) == CX3_HW_ID) || ((dev_id) == CX3_PRO_HW_ID)) -#define IS_IS4_FAMILY(dev_id) \ - (((dev_id) == IS4_HW_ID)) -#define IS_SX(dev_id) \ - ((dev_id) == SWITCHX_HW_ID) -#define IS_SIB(dev_id) \ - ((dev_id) == SWITCH_IB_HW_ID) -#define IS_SIB2(dev_id) \ - ((dev_id) == SWITCH_IB2_HW_ID) -#define IS_SEN(dev_id) \ - ((dev_id) == SPECTRUM_HW_ID) -#define IS_CONNECT_IB(dev_id) \ - ((dev_id) == CONNECT_IB_HW_ID) -#define IS_CONNECTX4(dev_id) \ - ((dev_id) == CX4_HW_ID) -#define IS_CONNECTX4LX(dev_id) \ - ((dev_id) == CX4LX_HW_ID) -#define IS_CONNECTX5(dev_id) \ - ((dev_id) == CX5_HW_ID) -#define HAS_TOOLS_CMDIF(dev_id) \ - ((((dev_id) == CX3_HW_ID) || ((dev_id) == CX3_PRO_HW_ID))) -#define HAS_ICMD_IF(dev_id) \ - ((IS_CONNECT_IB(dev_id)) || (IS_SIB(dev_id)) || (IS_CONNECTX4(dev_id)) || (IS_CONNECTX4LX(dev_id)) || (IS_SEN(dev_id)) || (IS_SIB2(dev_id)) || (IS_CONNECTX5(dev_id))) -#define IS_SWITCH(dev_id) \ - ((IS_IS4_FAMILY(dev_id)) || (IS_SX(dev_id)) || (IS_SIB(dev_id)) || (IS_SEN(dev_id)) || (IS_SIB2(dev_id))) -#define SUPPORTS_SW_RESET(devid)\ - (((devid) == IS4_HW_ID) || ((devid) == SWITCHX_HW_ID) || ((devid) == SWITCH_IB_HW_ID) || ((devid) == SWITCH_IB2_HW_ID)) - - -// Write/Erase delays -// ------------------ -// The below delays improve CPU utilization when doing long operations by -// sleeping instead of full throtle polling. -// Their values are set so they will not lenghen burn time (at least not by a meaningfull duration) -// and will save cpu. The delays are divided to an initial_delay, and then retry num_of_retries times waiting retry_delay. -// The initial delay is set according to the fastest flash we currently support (W25QxxBV). -// The retry_delay*num_of_retries is set according to the slowest flash maximum AC timing. -// -// To test there's no performance degradation by these delay: set DELAYS to 0 and RETRIES to infinity, and compare perf. - -enum FlashConstant { - // All time values are in usecs - WRITE_BLOCK_INIT_DELAY = 10, - WRITE_ADDITIONAL_BYTE_DELAY = 1, - WRITE_BLOCK_RETRY_DELAY = 10, - WRITE_BLOCK_RETRIES = 30000, - - ERASE_SUBSECTOR_INIT_DELAY = 20000, - ERASE_SUBSECTOR_RETRY_DELAY = 300, - ERASE_SUBSECTOR_RETRIES = 10000, - - FLASH_CMD_CNT = 5000, // Number of reads till flash cmd is zeroed - - GPIO_SEM_TRIES = 1024 , // Number of tries to obtain a GPIO sem. - - MAX_WRITE_BUFFER_SIZE = 256 // Max buffer size for buffer write devices -}; - - -enum IntelFlashCommand { - FC_ReadID = 0x90, - FC_Read = 0xFF, - FC_Erase = 0x20, - FC_Confirm = 0xD0, - FC_Clear = 0x50, - FC_Write = 0x40, - FC_LoadPB = 0xE0, - FC_PBWrite = 0x0C, - FC_Status = 0x70, - FC_Suspend = 0xB0, - FC_Resume = 0xD0, - FC_ReadESR = 0x71, - FC_QueryCFI = 0x98, - FC_SCSErase = 0x28, - FC_SCSWrite = 0xE8 -}; - -enum IntelFlashStatus { - FS_Ready = 0x80, - FS_Suspended = 0x40, - FS_Error = 0x3E, - FS_BlockError = 0x3F -}; - - -//static inline -static u_int32_t log2up (u_int32_t in) { - u_int32_t i; - for (i = 0; i < 32; i++) { - if (in <= (u_int32_t)(1 << i)) - break; - } - - return i; -} - -// ConnectX SPI interface: -int cntx_flash_init (mflash* mfl, flash_params_t* flash_params); -int cntx_flash_init_direct_access (mflash* mfl, flash_params_t* flash_params); - -int cntx_st_spi_reset (mflash* mfl); -int cntx_st_spi_erase_sect (mflash* mfl, u_int32_t addr); - -int cntx_st_spi_block_write_ex (mflash* mfl, - u_int32_t blk_addr, - u_int32_t blk_size, - u_int8_t* data, - u_int8_t is_first, - u_int8_t is_last, - u_int32_t total_size); - -int cntx_sst_spi_block_write_ex (mflash* mfl, - u_int32_t blk_addr, - u_int32_t blk_size, - u_int8_t* data); - - -int cntx_st_spi_block_read_ex (mflash* mfl, - u_int32_t blk_addr, - u_int32_t blk_size, - u_int8_t* data, - u_int8_t is_first, - u_int8_t is_last); - -int cntx_spi_get_type(mflash* mfl, u_int8_t op_type, u_int8_t *vendor, u_int8_t *type, u_int8_t *capacity); - -int cntx_spi_write_status_reg(mflash* mfl, u_int32_t status_reg, u_int8_t write_cmd, u_int8_t bytes_num); - -int spi_get_num_of_flashes(int prev_num_of_flashes); - -#ifndef UEFI_BUILD -static int trm2mfe_err(trm_sts rc); -#endif - -int my_memset(void* dst, u_int8_t data, u_int32_t len) { - u_int32_t i; - u_int8_t* bytes = (u_int8_t*)dst; - - for (i = 0; i < len; i++) { - bytes[i] = data; - } - - return 0; -} - -int my_memcpy(void* dst, void* src, u_int32_t len) { - u_int32_t i; - u_int8_t* dbytes = (u_int8_t*)dst; - u_int8_t* sbytes = (u_int8_t*)src; - - for (i = 0; i < len; i++) { - dbytes[i] = sbytes[i]; - } - - return 0; -} - -#if 0 // TODO: Currently the polling is in max throttle - no sleep is done -int usleep(u_int32_t usecs) { - u_int32_t i; - u_int32_t stub = 0; - // TODO: Some more intelegent /accurate way to do it, or remove T.Os completely. - u_int32_t loops = (usecs << 9); - for (i = 0; i < loops; i++) { - stub++; - } - - return stub; -} -#endif - -int write_chunks (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) { - int rc; - u_int8_t *p = (u_int8_t *)data; - - int all_ffs; - - // TODO - Check MAX_WRITE_BUFFER_SIZE against block_size in open (or here) - u_int8_t tmp_buff[MAX_WRITE_BUFFER_SIZE]; - - if (!mfl) { - return MFE_BAD_PARAMS; - } - - //printf("-D- write_chunks(addr=%x, size=%x)\n", addr, len); - - while (len) { - u_int32_t i; - u_int32_t prefix_pad_size = 0; - u_int32_t suffix_pad_size = 0; - - u_int32_t block_size = mfl->attr.block_write; - u_int32_t block_mask = ~(block_size - 1 ); - - u_int32_t block_addr = addr & block_mask; - u_int32_t data_size = block_size; - - u_int8_t* block_data = p; - - // - // To keep things simple, we always write full blocks. - // (there's an option to write partial buffer, but Intel reference code always - // writes full buffer, with pads if needed. I do the same ...) - // - // The First and last cycles (can be the same one) may not be block aligned. - // If this is the case, copy the block data to a 0xFF padded temp buffer (writing 0xFF - // does not effect the flash) - // - - prefix_pad_size = addr - block_addr; - - if ((addr & block_mask) == ((addr + len) & block_mask)) { - suffix_pad_size = block_size - ((addr + len) % block_size); - } - - if (suffix_pad_size || prefix_pad_size) { - my_memset(tmp_buff, 0xff, block_size); - - data_size -= prefix_pad_size; - data_size -= suffix_pad_size; - - my_memcpy(tmp_buff + prefix_pad_size, p , data_size); - - block_data = tmp_buff; - } else if (mfl->attr.page_write) { - // current write is aligned to block size, - // write data to next page, or to last full block (if we're in the last block in a page) - u_int32_t page_mask = ~(mfl->attr.page_write - 1); - u_int32_t next_page_addr = (addr + mfl->attr.page_write + 1) & page_mask; - u_int32_t size_to_page_boundary = next_page_addr - addr; - if (len > size_to_page_boundary) { - block_size = size_to_page_boundary; - } else { - block_size = len & block_mask; - } - data_size = block_size; - } - - // - // Check to see if there's something to do - // - all_ffs = 1; - for (i = 0; i < block_size ; i++) { - if (block_data[i] != 0xff) { - all_ffs = 0; - break; - } - } - - if (!all_ffs) { - rc = mfl->f_write_blk(mfl, block_addr, block_size, block_data); CHECK_RC(rc); - - if (mfl->opts[MFO_NO_VERIFY] == 0) { - u_int8_t verify_buffer[MAX_WRITE_BUFFER_SIZE]; - rc = mfl->f_reset(mfl); CHECK_RC(rc); - rc = mfl->f_read(mfl, addr, data_size, verify_buffer); CHECK_RC(rc); - // Verify data - for (i = 0 ; i < data_size ; i++) { - // printf("-D- Verify: addr = %#x, verify_buffer[%d] = %#x, block_data[%d] = %#x\n", - // addr, i, verify_buffer[i], i + prefix_pad_size, block_data[i + prefix_pad_size]); - if (verify_buffer[i] != block_data[i + prefix_pad_size]) { - //return _f.errmsg("Write verification failed. Addr %08x - exp:%02x act:%02x\n", - // addr + i, - // block_data[i + prefix_pad_size] , - // verify_buffer[i]); - return MFE_VERIFY_ERROR; - } - } - } - } - - // - // loop advance - // - - addr += data_size; - p += data_size; - len -= data_size; - } - - rc = mfl->f_reset(mfl); CHECK_RC(rc); - - return MFE_OK; -} - - -//////////////////////////////////////// -// -// ST SPI functions - common for InfiniHostIIILx and ConnectX -// -//////////////////////////////////////// -enum StFlashCommand { - SFC_SE = 0xD8, - SFC_SSE = 0x20, - SFC_PP = 0x02, - SFC_RDSR = 0x05, - SFC_RDSR2 = 0x35, - SFC_WREN = 0x06, - SFC_READ = 0x03, - SFC_FAST_READ = 0x3B, - SFC_QUAD_READ = 0x3B, - SFC_RES = 0xAB, - SFC_JEDEC = 0x9F, - SFC_RDNVR = 0xB5, - SFC_WRNVR = 0xB1, - SFC_WRSR = 0x01 -}; - -#define SST_FLASH_NAME "SST25VFxx" -#define WINBOND_NAME "W25QxxBV" -#define WINBOND_W25X "W25Xxx" -#define ATMEL_NAME "AT25DFxxx" -#define S25FLXXXP_NAME "S25FLXXXP" -#define S25FL116K_NAME "S25FL11xx" -#define MACRONIX_NAME "MX25L16xxx" - -typedef enum flash_vendor { - FV_ST = 0x20, - FV_SST = 0xbf, - FV_WINBOND = 0xef, - FV_ATMEL = 0x1f, - FV_S25FLXXXX = 0x01, - FV_MX25K16XXX = 0xc2, -} flash_vendor_t; - -typedef enum flash_memory_type { - FMT_ST_M25P = 0x20, - FMT_ST_M25PX = 0x71, - FMT_SST_25 = 0x25, - FMT_WINBOND = 0x40, - FMT_WINBOND_W25X = 0x30, - FMT_ATMEL = 0x2, - FMT_N25QXXX = 0xba, - FMT_S25FLXXXP = 0x02, - FMT_S25FL116K = 0x40, -} flash_memory_type_t; - -flash_info_t g_flash_info_arr[] = -{ - {"M25PXxx", FV_ST, FMT_ST_M25PX, MCS_STSPI, SFC_SSE, FSS_4KB, 1, 0, 0, 0, 0}, - {"M25Pxx", FV_ST, FMT_ST_M25P, MCS_STSPI, SFC_SE, FSS_64KB, 0, 0, 0, 0, 0}, - {"N25Q0XX", FV_ST, FMT_N25QXXX, MCS_STSPI, SFC_SSE, FSS_4KB, 1, 1, 1, 0, 1}, - {SST_FLASH_NAME, FV_SST, FMT_SST_25, MCS_SSTSPI, SFC_SE, FSS_64KB, 0, 0, 0, 0, 0}, - {WINBOND_NAME, FV_WINBOND, FMT_WINBOND, MCS_STSPI, SFC_SSE, FSS_4KB, 1, 1, 1, 1, 0}, - {WINBOND_W25X, FV_WINBOND, FMT_WINBOND_W25X, MCS_STSPI, SFC_SSE, FSS_4KB, 0, 0, 0, 0, 0}, - {ATMEL_NAME, FV_ATMEL, FMT_ATMEL, MCS_STSPI, SFC_SSE, FSS_4KB, 0, 0, 0, 0, 0}, - {S25FLXXXP_NAME, FV_S25FLXXXX, FMT_S25FLXXXP, MCS_STSPI, SFC_SE, FSS_64KB, 0, 0, 0, 0, 0}, - {S25FL116K_NAME, FV_S25FLXXXX, FMT_S25FL116K, MCS_STSPI, SFC_SSE, FSS_4KB, 1, 1, 1, 1, 0}, // this flash actually supports quad and write protect but we dont need it at this moment - {MACRONIX_NAME, FV_MX25K16XXX, FMT_ST_M25P, MCS_STSPI, SFC_SSE, FSS_4KB, 0, 0, 0, 0, 0}, // this flash actually supports write protection but we dont use it at this time -}; - -int cntx_sst_get_log2size(u_int8_t capacity, int* log2spi_size) -{ - switch (capacity) { - case 0x41: - *log2spi_size = 0x15; - break; - case 0x4A: - *log2spi_size = 0x16; - break; - case 0x8D: - *log2spi_size = 0x13; - break; - case 0x8E: - *log2spi_size = 0x14; - break; - default: - return MFE_UNSUPPORTED_FLASH_TOPOLOGY; - } - return 0; -} - -int get_log2size_by_capcity(unsigned type_index, u_int8_t capacity, int *log2size) { - - flash_info_t *flash_info = &g_flash_info_arr[type_index]; - - if (flash_info->type == FMT_SST_25 && flash_info->vendor == FV_SST) { - return cntx_sst_get_log2size(capacity, log2size); - } else { - *log2size = capacity; - } - return MFE_OK; -} - -int get_type_index_by_vendor_and_type(u_int8_t vendor, u_int8_t type, unsigned *type_index) -{ - unsigned i, arr_size; - arr_size = ARR_SIZE(g_flash_info_arr); - - for (i = 0; i < arr_size; i++) { - flash_info_t *flash_info = &g_flash_info_arr[i]; - if (flash_info->vendor == vendor && flash_info->type == type) { - *type_index = i; - return MFE_OK; - } - } - return MFE_UNSUPPORTED_FLASH_TYPE; -} - -void mf_flash_list(char *flash_arr) -{ - int i; - int arr_index = 0; - - int arr_size = ARR_SIZE(g_flash_info_arr); - for (i = 0; i < arr_size; i++) { - flash_info_t *flash_info = &g_flash_info_arr[i]; - int name_len = strlen(flash_info->name); - strcpy(&flash_arr[arr_index], flash_info->name); - arr_index += name_len; - if (i != arr_size - 1) { - flash_arr[arr_index++] = ','; - flash_arr[arr_index++] = ' '; - } - } - flash_arr[arr_index] = '\0'; - return; -} - -int get_type_index_by_name(const char *type_name, unsigned *type_index) -{ - unsigned i, arr_size; - arr_size = ARR_SIZE(g_flash_info_arr); - for (i = 0; i < arr_size; i++) { - flash_info_t *flash_info = &g_flash_info_arr[i]; - if (!strcmp(type_name, flash_info->name)) { - *type_index = i; - return MFE_OK; - } - } - printf("-E- The flash name \"%s\" is unknown\n.", type_name); - return MFE_UNSUPPORTED_FLASH_TYPE; -} - -int is_no_flash_detected(u_int8_t type, u_int8_t vendor, u_int8_t capacity) { - if ((type == 0xff && vendor == 0xff && capacity == 0xff) || - (type == 0x0 && vendor == 0x0 && capacity == 0x0)) { - return 1; - } - return 0; -} - -int get_flash_info_by_res(mflash* mfl, unsigned *type_index, int *log2size, u_int8_t *no_flash, unsigned char *es_p) -{ - int rc; - - - *no_flash = 0; - - rc = mfl->f_spi_status(mfl, SFC_RES, es_p); CHECK_RC(rc); - // printf("-D- get_flash_info_by_res: es = %#x\n", *es_p); - if ((*es_p >= 0x10 && *es_p < 0x17)) { - *log2size = *es_p + 1; - return get_type_index_by_vendor_and_type(FV_ST, FMT_ST_M25P, type_index); - } else if (*es_p == 0xff || *es_p == 0x0) { - *no_flash = 1; - } else { - return MFE_UNSUPPORTED_FLASH_TYPE; - } - return MFE_OK; -} - -int cntx_get_flash_info(mflash* mfl, flash_info_t *f_info, int *log2size, u_int8_t *no_flash) -{ - int rc; - u_int8_t type = 0, capacity = 0, vendor = 0, no_flash_res = 0, no_flash_rdid = 0; - unsigned char es = 0; - unsigned type_index = 0; - // Assume there is a flash. - *no_flash = 0; - - rc = cntx_spi_get_type(mfl, SFC_JEDEC, &vendor, &type, &capacity); CHECK_RC(rc); - no_flash_rdid = is_no_flash_detected(type, vendor, capacity); - // printf("-D- cntx_spi_get_type: rc: %#x, vendor=%#x, type=%#x, capacity=%#x\n", rc, vendor, type, capacity); - // printf("-D- rc = %d, no_flash_rdid = %d\n", rc, no_flash_rdid); - if (get_type_index_by_vendor_and_type(vendor, type, &type_index) == MFE_OK) { - // RDID Succeded. - // Get the capacity - if (get_log2size_by_capcity(type_index, capacity, log2size) != MFE_OK) { - printf("-E- SST SPI flash #%d (vendor: %#x, type: %#x, capacity:%#x) is not supported.\n", get_bank_int(mfl), vendor, - type, capacity); - rc = MFE_UNSUPPORTED_FLASH_TOPOLOGY; - } - rc = MFE_OK; - } else if (no_flash_rdid) { - // printf("-D- no support for rdid\n"); - // RDID Failed due to: - // 1- RDID is not supported but RES is - Old flashes. - // 2- There is no Flash - // 3- Flash is not supported - - // Trying RES - rc = get_flash_info_by_res(mfl, &type_index, log2size, &no_flash_res, &es); - if (rc == 0 && no_flash_res == 1) { - // RES Succeeded due to: no flash, unsupported flash or old flash. - *no_flash = 1; - // when no_flash_rdid == 0 then "1- RDID is not supported but RES is - Old flashes." - } - } else { - rc = MFE_UNSUPPORTED_FLASH_TYPE; - } - - if (rc == MFE_UNSUPPORTED_FLASH_TYPE) { - printf("-E- SPI flash #%d (vendor: %#x, memory type: %#x, es: %#x) is not supported.\n", get_bank_int(mfl), vendor, type, es); - } - // printf("-D- rc = %d, no_flash_res = %d, type_index = %d.\n", rc, no_flash_res, *type_index); - if (rc == MFE_OK && *no_flash == 0) { - memcpy(f_info, &g_flash_info_arr[type_index], sizeof(flash_info_t)); - } - return rc; -} - -int compare_flash_params(flash_params_t *flash_params, int bank_num, const char *type_name, int log2size) -{ - if (strcmp(flash_params->type_name, type_name) != 0) { - printf("-E- SPI flash #%d (type: %s)differs in type from SPI flash #%d(type: %s). " - "All flash devices must be of the same type.\n", - bank_num, type_name, bank_num - 1, flash_params->type_name); - return MFE_UNSUPPORTED_FLASH_TOPOLOGY; - } - if (flash_params->log2size != log2size){ - printf ("-E- SPI flash #%d (log2size: %#x) differs in size from SPI flash #%d (log2size: %#x). " - "All flash devices must be of the same size.\n", - bank_num, log2size, bank_num - 1, flash_params->log2size); - return MFE_UNSUPPORTED_FLASH_TOPOLOGY; - - } - return MFE_OK; -} - -int cntx_st_spi_get_status(mflash* mfl, u_int8_t op_type, u_int8_t* status) { - u_int32_t flash_data; - int rc; - - rc = cntx_int_spi_get_status_data(mfl, op_type, &flash_data, 1); CHECK_RC(rc); - *status = EXTRACT(flash_data, 0, 8); - return MFE_OK; -} - -int get_num_of_banks_int(mflash *mfl) { - int num; - if ( (mfl->opts[MFO_USER_BANKS_NUM] == 0) && (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] != ATBM_NO) && ((num = get_num_of_banks(mfl->mf)) != -1) ){ - return num; // if mfpa register is supported get the exact number of flash banks - } - return mfl->opts[MFO_NUM_OF_BANKS]; -} - -int get_flash_params(mflash* mfl, flash_params_t *flash_params, flash_info_t *flash_info) -{ - int num_of_flashes = get_num_of_banks_int(mfl); - int spi_sel, rc; - int params_were_set = 0; - flash_info_t tmp_flash_info; - memset(flash_params, 0, sizeof(flash_params_t)); - memset (flash_info, 0, sizeof(flash_info_t)); - memset (&tmp_flash_info, 0, sizeof(flash_info_t)); - - // if number of flash banks is zero exit with error - if (num_of_flashes == 0) { - return MFE_NO_FLASH_DETECTED; - } - - for (spi_sel = 0 ; spi_sel < num_of_flashes ; spi_sel++) { - int log2size; - u_int8_t no_flash = 0; - const char *type_name; - rc = set_bank(mfl, spi_sel); CHECK_RC(rc); - rc = mfl->f_get_info(mfl, &tmp_flash_info, &log2size, &no_flash); CHECK_RC(rc); - //printf("-D- spi_sel = %d, num_of_flashes = %d, rc = %d, no_flash = %d\n", spi_sel, num_of_flashes, rc, no_flash); - - if (no_flash == 1) { - // This bank is empty and also the following banks will be empty. - if (flash_params->num_of_flashes == 0) { - // if we haven't detected any 'supported' flash, return an error. - return MFE_NO_FLASH_DETECTED; - } - break; - } - - type_name = tmp_flash_info.name; - if (params_were_set == 0) { - flash_params->type_name = type_name; - flash_params->log2size = log2size; - memcpy(flash_info, &tmp_flash_info, sizeof(flash_info_t)); - params_were_set = 1; - } else { - rc = compare_flash_params(flash_params, spi_sel, type_name, log2size); CHECK_RC(rc); - } - // Init SST flash. - if (mfl->access_type == MFAT_MFILE) { - if (flash_info->vendor == FV_SST && flash_info->type == FMT_SST_25) { - rc = cntx_spi_write_status_reg(mfl, SST_STATUS_REG_VAL, SFC_WRSR, 1); CHECK_RC(rc); - } else if (flash_info->vendor == FV_ATMEL && flash_info->type == FMT_ATMEL) { - rc = cntx_spi_write_status_reg(mfl, ATMEL_STATUS_REG_VAL, SFC_WRSR, 1); CHECK_RC(rc); - } - } - - flash_params->num_of_flashes++; - } - return MFE_OK; -} - -int spi_fill_attr_from_params(mflash* mfl, flash_params_t* flash_params, flash_info_t *flash_info) -{ - mfl->attr.log2_bank_size = flash_params->log2size; - mfl->attr.bank_size = 1 << flash_params->log2size; - mfl->attr.size = mfl->attr.bank_size * flash_params->num_of_flashes; - mfl->attr.block_write = 16; // In SPI context, this is the transaction size. Max is 16. - // HACK: Use fw_sector size as the sector size only in CX3 family devices for now - // TODO: adrianc : this sould be in sx_get_flash_info_by_type() - if (HAS_TOOLS_CMDIF(mfl->attr.hw_dev_id)) { - flash_info->sector_size = mfl->attr.fw_flash_sector_sz ? mfl->attr.fw_flash_sector_sz : flash_info->sector_size; - } - mfl->attr.sector_size = flash_info->sector_size; - mfl->attr.support_sub_and_sector = flash_info->support_sub_and_sector; - mfl->attr.command_set = flash_info->command_set; - mfl->attr.erase_command = flash_info->erase_command; - mfl->attr.type_str = flash_info->name; - - mfl->attr.quad_en_support = flash_info->quad_en_support; - mfl->attr.dummy_cycles_support = flash_info->dummy_cycles_support; - - mfl->attr.write_protect_support = flash_info->write_protected_support; - mfl->attr.protect_sub_and_sector = flash_info->protect_sub_and_sector; - mfl->attr.banks_num = flash_params->num_of_flashes; - mfl->attr.vendor = flash_info->vendor; - mfl->attr.type = flash_info->type; - return MFE_OK; -} - -#define GET_FLASH_RETRY 2 -int st_spi_fill_attr(mflash* mfl, flash_params_t* flash_params) { - int rc; - flash_params_t *cur_flash_params, tmp_flash_params; - flash_info_t flash_info; - unsigned type_index; - - // printf("-D- st_spi_fill_attr: ignore_detect = %d, log2size = %#x.\n", mfl->ignore_flash_detect, mfl->user_attr.log2size); - if (flash_params == NULL) { - int i = 0; - // Get flash params from the flash itself - cur_flash_params = &tmp_flash_params; - - while (i < GET_FLASH_RETRY) { - rc = get_flash_params(mfl, cur_flash_params, &flash_info); - if (rc != MFE_NO_FLASH_DETECTED) { - break; - } - i++; - } - CHECK_RC(rc); - - } else { - // Get the flash params from the user. - rc = get_type_index_by_name(flash_params->type_name, &type_index); CHECK_RC(rc); - memcpy(&flash_info, &(g_flash_info_arr[type_index]), sizeof(flash_info_t)); - cur_flash_params = flash_params; - } - // Init the flash attr according to the flash parameters (which was wither given by the user or read from the flash) - rc = spi_fill_attr_from_params(mfl, cur_flash_params, &flash_info); CHECK_RC(rc); - // printf("-D- spi_size = %#x, log2spi_size = %#x, bank_size = %#x, flashes_num = %d\n", mfl->attr.size, mfl->attr.log2_bank_size, - // mfl->attr.bank_size, cur_flash_params->num_of_flashes); - return MFE_OK; -} - -int st_spi_wait_wip(mflash* mfl, u_int32_t init_delay_us, u_int32_t retry_delay_us, u_int32_t num_of_retries) { - - int rc; - u_int8_t status; - u_int32_t i; - - usleep(init_delay_us); - - for (i = 0; i < num_of_retries; ++i) { - rc = mfl->f_spi_status(mfl, SFC_RDSR, &status); CHECK_RC(rc); - if ((status & 1) == 0) { - return MFE_OK; - } - usleep(retry_delay_us); - } - - return MFE_WRITE_TIMEOUT; -} - -int read_chunks (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) { - - int rc; - u_int8_t *p = (u_int8_t *)data; - - if (!mfl) { - return MFE_BAD_PARAMS; - } - - // Note: - // Assuming read block is the same as write block size. - // This is true for current Mellanox devices SPI flash access implementation. - // Check for future devices. - u_int32_t block_size = mfl->attr.block_write; - u_int32_t block_mask; - - // TODO - Check MAX_WRITE_BUFFER_SIZE against block_size in open (or here) - u_int8_t tmp_buff[MAX_WRITE_BUFFER_SIZE]; - - block_mask = ~(block_size - 1); - - while (len) { - u_int32_t i; - u_int32_t prefix_pad_size = 0; - u_int32_t suffix_pad_size = 0; - - u_int32_t block_addr = addr & block_mask; - u_int32_t data_size = block_size; - - u_int8_t* block_data = p; - - // - // First and last cycles (can be the same one) may not be block aligned. - // Check the status, and copy data to a padded temp bufer if not alligned. - // (there's an option to write partial buffer, but Intel reference code always - // writes full buffer, with pads if needed. I do the dame ...) - // - - prefix_pad_size = addr - block_addr; - - if ((addr & block_mask) == ((addr + len) & block_mask)) { - suffix_pad_size = block_size - ((addr + len) % block_size); - } - - if (suffix_pad_size || prefix_pad_size) { - // block exceeds given buffer - read to a temp bufer and - // copy the required data to user's bufer. - data_size -= suffix_pad_size; - data_size -= prefix_pad_size; - block_data = tmp_buff; - } - rc = mfl->f_read_blk(mfl, block_addr, block_size, block_data); CHECK_RC(rc); - - if (suffix_pad_size || prefix_pad_size) { - for (i = 0; i < data_size; i++) { - p[i] = tmp_buff[prefix_pad_size + i]; - } - } - - // - // loop advance - // - - addr += data_size; - p += data_size; - len -= data_size; - } - - return MFE_OK; -} - -//////////////////////////////////////// -// -// InfiniHostIIILx spi access functions -// -//////////////////////////////////////// - - -// -// Relevant CR addresses, Bit offset and bit size -// - -enum CrConstans { - CR_FLASH_GW = 0xf0400, - CR_FLASH_ADDR = 0xf0404, - CR_FLASH_DATA = 0xf0408, - CR_FLASH_CS = 0xf0418, - - CR_GPIO_LOCK = 0xf00ec, - - BO_READ_OP = 0, - BO_ADDR_INCR = 1, - - BO_LPC_STOP = 3, - BO_SPI_NO_DATA = 4, - BO_SPI_NO_ADDR = 5, - BO_SPI_SPECIAL = 6, - - BO_MSIZE = 8, - BS_MSIZE = 3, - - BO_STATUS = 26, - BS_STATUS = 4, - - BO_BUSY = 30, - - BO_SPI_ADDR = 0, - BS_SPI_ADDR = 24, - - BO_SPI_CMD = 24, - BS_SPI_CMD = 8, - - BO_SPI_GPIO = 25, - BS_SPI_GPIO = 4 -}; - -int gw_wait_ready(mflash* mfl, const char* msg) { - u_int32_t gw_cmd; - u_int32_t cnt = 0; - (void)msg; // NOT USED FOR NOW - do { - // Timeout checks - if (++cnt > FLASH_CMD_CNT) { - //return errmsg("Flash gateway timeout: %s.", msg); - return MFE_TIMEOUT; - } - - MREAD4(CR_FLASH_GW, &gw_cmd); - - } while (EXTRACT(gw_cmd, BO_BUSY, 1)); - - return MFE_OK; -} - - -int empty_reset (mflash* mfl) { - (void)mfl; /* avoid compiler warning */ - return MFE_OK; -} - -////////////////////////////////////////// -// -// ConnectX functions implementation -// -////////////////////////////////////////// -enum CntxCrConstants{ - HCR_FLASH_CMD = 0xf0400, - HCR_FLASH_ADDR = 0xf0404, - - HCR_FLASH_DATA = 0xf0410, - - HBO_READ_OP = 0, - HBO_ADDR_AUTO_INC = 1, - HBO_CMD_PHASE = 2, - HBO_ADDR_PHASE = 3, - HBO_DATA_PHASE = 4, - HBO_CS_HOLD = 5, - - HBO_MSIZE = 8, - HBS_MSIZE = 3, - - HBO_CHIP_SELECT = 11, - HBS_CHIP_SELECT = 2, - - HBO_FLASH_ENABLE = 13, - - HBO_CMD = 16, - HBS_CMD = 8, - - HBO_BUSY = 30, - HBO_LOCK = 31, - - HBO_ADDR = 0, - HBS_ADDR = 24, - - - // GPIOs - HCR_GPIO_LOCK = 0xf0048, - HCR_GPIO_LOCK_VAL = 0xd42f, - - HCR_GPIO_DATA_OUT = 0xf0040, - HCR_GPIO_MODE0 = 0xf0050, - HCR_GPIO_MODE1 = 0xf004c, - - HBO_GPIO_CS = 25, - HBS_GPIO_CS = 4 -}; - -int empty_set_bank(mflash* mfl, u_int32_t bank) { - // NULL function - No actual work here - in ConnectX the curr_bank is written in the command word. - (void)mfl; // Avoid Compiler warning - (void)bank; // Avoid Compiler warning - return MFE_OK; -} - -int cntx_exec_cmd(mflash* mfl, u_int32_t gw_cmd, char* msg) { - if (!IS_CONNECTX_4TH_GEN_FAMILY(mfl->attr.hw_dev_id)) { - // for old devices lock bit is separate from the flash HW ifc - //for new devices need to make sure this bit remains locked when writing the dword - gw_cmd = MERGE(gw_cmd, 1, 31, 1); - } - gw_cmd = MERGE(gw_cmd, 1, HBO_BUSY, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_FLASH_ENABLE, 1); - gw_cmd = MERGE(gw_cmd, (u_int32_t)mfl->curr_bank, - HBO_CHIP_SELECT, HBS_CHIP_SELECT); - // printf("-D- cntx_exec_cmd: %s, gw_cmd = %#x\n", msg, gw_cmd); - MWRITE4(CR_FLASH_GW, gw_cmd); - return gw_wait_ready(mfl, msg); -} - -/* - * execute a flash GW command and get the output: data0...data3 from the flash interface - * - * mfl - pointer to an initilized mflash obj - * gw_cmd - the flash gateway command to execute - * buff - pointer to a buffer where the output data from the flash GW will be written to - * buff_dword_sz - size for buff in dwords - * addr - if != NULL *addr will be written to the addr bits of the flash GW. (for commands that read from flash) - * msg - optional string that describes the action for debug purposes, not used ATM however its recommended to put usefull - * data for future dubugabillity. - * return : MFE_OK (0) upon success or a value != 0 upon error accroding to mlfash error code. - */ -int cntx_exec_cmd_get(mflash* mfl, u_int32_t gw_cmd, u_int32_t* buff,int buff_dword_sz, u_int32_t* addr, char* msg) -{ - int rc; - if (!mfl ||!buff || !buff_dword_sz) { - return MFE_BAD_PARAMS; - } - - rc = mfl_com_lock(mfl); CHECK_RC(rc); - - // write GW addr if needed - if (addr) { - if (mwrite4(mfl->mf, HCR_FLASH_ADDR, *addr) != 4) { - release_semaphore(mfl, 0); - return MFE_CR_ERROR; - } - } - // execute gw command - rc = cntx_exec_cmd(mfl, gw_cmd, msg); CHECK_RC_REL_SEM(mfl, rc); - // copy data from CR-space to buff - if (mread4_block(mfl->mf, HCR_FLASH_DATA, buff, (buff_dword_sz << 2)) != (buff_dword_sz << 2 )) { - release_semaphore(mfl, 0); - return MFE_CR_ERROR; - } - //release semaphore - release_semaphore(mfl, 0); - return MFE_OK; -} - -/* - * Set input in: data0...data3 from the flash interface and execute a flash GW command - * - * mfl - pointer to an initilized mflash obj - * gw_cmd - the flash gateway command to execute - * buff - if != NULL pointer to a buffer to the input data for the flash GW. - * buff_dword_sz - size for buff in dwords - * addr - if != NULL *addr will be written to the addr bits of the flash GW. (for commands that write from flash) - * msg - optional string that describes the action for debug purposes, not used ATM however its recommended to put usefull - * data for future dubugabillity. - * return : MFE_OK (0) upon success or a value != 0 upon error accroding to mlfash error code. - */ -int cntx_exec_cmd_set(mflash* mfl, u_int32_t gw_cmd, u_int32_t* buff,int buff_dword_sz, u_int32_t* addr, char* msg) -{ - int rc; - if (!mfl) { - return MFE_BAD_PARAMS; - } - - rc = mfl_com_lock(mfl); CHECK_RC(rc); - - // write data from buff to CR-space - if (buff && buff_dword_sz) { - if (mwrite4_block(mfl->mf, HCR_FLASH_DATA, buff, (buff_dword_sz << 2)) != (buff_dword_sz << 2 )) { - release_semaphore(mfl, 0); - return MFE_CR_ERROR; - } - } - - // write GW addr if needed - if (addr) { - if (mwrite4(mfl->mf, HCR_FLASH_ADDR, *addr) != 4) { - release_semaphore(mfl, 0); - return MFE_CR_ERROR; - } - } - // execute gw command - rc = cntx_exec_cmd(mfl, gw_cmd, msg); CHECK_RC_REL_SEM(mfl, rc); - - //release semaphore - release_semaphore(mfl, 0); - return MFE_OK; -} - -int cntx_int_spi_get_status_data(mflash* mfl, u_int8_t op_type, u_int32_t* status, u_int8_t bytes_num) -{ - int rc; - - u_int32_t gw_cmd = 0; - u_int32_t flash_data = 0; - //TODO: adrianc: update msize from log2(bytes_num) - gw_cmd = MERGE(gw_cmd, 1, HBO_READ_OP, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_DATA_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 2, HBO_MSIZE, HBS_MSIZE); - - gw_cmd = MERGE(gw_cmd, op_type, HBO_CMD, HBS_CMD); - - if (bytes_num > 4) { - return MFE_BAD_PARAMS; - } - rc = cntx_exec_cmd_get(mfl, gw_cmd, &flash_data, 1, NULL, "Read id"); CHECK_RC(rc); - - // printf("-D- cntx_int_spi_get_status_data: op=%02x status=%08x\n", op_type, flash_data); - *status = (flash_data >> 8*(4 - bytes_num)); - return MFE_OK; -} - -int cntx_st_spi_write_enable(mflash* mfl) { - u_int32_t gw_cmd = 0; - int rc; - // Write enable: - gw_cmd = MERGE(gw_cmd, 1, HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, SFC_WREN, HBO_CMD, HBS_CMD); - - - rc = cntx_exec_cmd_set(mfl, gw_cmd, NULL, 0, NULL, "WREN command"); CHECK_RC(rc); - - //gw_cmd = MERGE(gw_cmd, 1 , HBO_CS_HOLD, 1); - - //MWRITE4(CR_FLASH_GW, gw_cmd); - - return MFE_OK; -} - -/* - * Consts needed to extract the needed data for the jedec ID - * from various flash types. - */ -enum { - JEDEC_ATMEL_CAPACITY_BITOFF = 16, - JEDEC_ATMEL_CAPACITY_BITLEN = 5, - JEDEC_ATMEL_TYPE_BITOFF = 21, - JEDEC_ATMEL_TYPE_BITLEN = 3, - - JEDEC_VENDOR_ID_BITOFF = 24, - JEDEC_VENDOR_ID_BITLEN = 8, - - JEDEC_CAPACITY_BITOFF = 8, - JEDEC_CAPACITY_BITLEN = 8, - - JEDEC_TYPE_BITOFF = 16, - JEDEC_TYPE_BITLEN = 8 -}; - - -int get_flash_info_for_atmel(u_int32_t jedec_id, u_int8_t* type, u_int8_t* capacity) -{ - u_int8_t tmp_cap; - - tmp_cap = EXTRACT(jedec_id, JEDEC_ATMEL_CAPACITY_BITOFF, JEDEC_ATMEL_CAPACITY_BITLEN); - *type = EXTRACT(jedec_id, JEDEC_ATMEL_TYPE_BITOFF, JEDEC_ATMEL_TYPE_BITLEN); - switch (tmp_cap) { - case 0x4: - *capacity = 0x13; - break; - case 0x5: - *capacity = 0x14; - break; - case 0x6: - *capacity = 0x15; - break; - case 0x7: - *capacity = 0x16; - break; - default: - return MFE_UNSUPPORTED_FLASH_TOPOLOGY; - } - - return MFE_OK; - -} -int get_info_from_jededc_id(u_int32_t jedec_id, u_int8_t *vendor, u_int8_t* type, u_int8_t* capacity) -{ - int rc; - *vendor = EXTRACT(jedec_id, JEDEC_VENDOR_ID_BITOFF, JEDEC_VENDOR_ID_BITLEN); - if (*vendor == FV_ATMEL) { - rc = get_flash_info_for_atmel(jedec_id, type, capacity); CHECK_RC(rc); - } else { - *type = EXTRACT(jedec_id, JEDEC_TYPE_BITOFF, JEDEC_TYPE_BITLEN); - *capacity = EXTRACT(jedec_id, JEDEC_CAPACITY_BITOFF, JEDEC_CAPACITY_BITLEN); - } - - return MFE_OK; -} - -int cntx_spi_get_type(mflash* mfl, u_int8_t op_type, u_int8_t *vendor, u_int8_t* type, u_int8_t* capacity) { - u_int32_t flash_data = 0; - int rc; - - rc = cntx_int_spi_get_status_data(mfl, op_type, &flash_data, 4); CHECK_RC(rc); - //printf("-D- jedec_info = %#x\n", flash_data); - // Get type and some other info from jededc_id - get_info_from_jededc_id(flash_data, vendor, type, capacity); - // printf("-D- cntx_spi_get_type: vendor = %#x, type = %#x, capacity = %#x\n", *vendor, *type, *capacity); - return MFE_OK; -} -int cntx_spi_write_status_reg(mflash* mfl, u_int32_t status_reg, u_int8_t write_cmd, u_int8_t bytes_num) -{ - int rc; - u_int32_t gw_cmd = 0; - // TODO: adrianc: add support for dynamic writes of power of 2 bytes_num not just 1,2 bytes - rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc); - gw_cmd = MERGE(gw_cmd, 1, HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_DATA_PHASE, 1); - - gw_cmd = MERGE(gw_cmd, write_cmd, HBO_CMD, HBS_CMD); - - if (bytes_num != 1 && bytes_num != 2) { - return MFE_NOT_SUPPORTED_OPERATION; - } - // push status reg to upper bytes - status_reg = status_reg << ((bytes_num==2) ? 16 : 24); - if (bytes_num == 2) { - gw_cmd = MERGE(gw_cmd, 1, HBO_MSIZE, 1); - } - rc = cntx_exec_cmd_set(mfl, gw_cmd, &status_reg, 1, NULL, "Write-Status-Register"); - // wait for flash to write the register - msleep(30); - return rc; -} - - - -int cntx_init_gpios(mflash* mfl) { - // - // Set Multi SPI CS to output and with value of 1 (inactive) - // Assuming 4 flashes. If there are less than 4 flashes and there's - // an access to a void flash, the access will fail. - // - - u_int32_t spi_en = 0xf; - - u_int32_t mode0; - u_int32_t mode1; - u_int32_t data; - - // Set 4 Chip selects to 1 - MREAD4(HCR_GPIO_DATA_OUT, &data); - data = MERGE(data, spi_en, BO_SPI_GPIO, BS_SPI_GPIO); - MWRITE4(HCR_GPIO_DATA_OUT, data); - - MREAD4(HCR_GPIO_MODE0, &mode0); - MREAD4(HCR_GPIO_MODE1, &mode1); - - // Set 4 Chip selects to outputs - if (EXTRACT(mode0, HBO_GPIO_CS, HBS_GPIO_CS) != spi_en || - EXTRACT(mode1, HBO_GPIO_CS, HBS_GPIO_CS) != 0 ) { - mode0 = MERGE(mode0, spi_en, BO_SPI_GPIO, BS_SPI_GPIO); - mode1 = MERGE(mode1, ~spi_en, BO_SPI_GPIO, BS_SPI_GPIO); - - // unlock gpio - MWRITE4(HCR_GPIO_LOCK , HCR_GPIO_LOCK_VAL); - - MWRITE4(HCR_GPIO_MODE0, mode0); - MWRITE4(HCR_GPIO_MODE1, mode1); - - // re-lock - MWRITE4(HCR_GPIO_LOCK , 0); - } - - return MFE_OK; -} - -#define MFLASH_ENV "MFLASH_BANKS" - -int spi_get_num_of_flashes(int prev_num_of_flashes) -{ - char* mflash_env; - int num; - - if (prev_num_of_flashes != -1) { - return prev_num_of_flashes; - } - - mflash_env = getenv(MFLASH_ENV); - if (mflash_env) { - num = atol(mflash_env); - // make sure the value makes sense - num = (num > 16 || num <= 0) ? -1 : num; - return num; - } - - return -1; -} - -int spi_update_num_of_banks(mflash* mfl, int prev_num_of_flashes) -{ - int num_of_banks; - - num_of_banks = spi_get_num_of_flashes(prev_num_of_flashes); - if (num_of_banks == -1) { - if (IS_SX(mfl->attr.hw_dev_id) || IS_SIB(mfl->attr.hw_dev_id) || IS_SEN(mfl->attr.hw_dev_id) || IS_SIB2(mfl->attr.hw_dev_id)) { - mfl->opts[MFO_NUM_OF_BANKS] = 2; - } else { - mfl->opts[MFO_NUM_OF_BANKS] = 1; - } - mfl->opts[MFO_USER_BANKS_NUM] = 0; - } else { - mfl->opts[MFO_NUM_OF_BANKS] = num_of_banks; - mfl->opts[MFO_USER_BANKS_NUM] = 1; - } - return MFE_OK; -} - - -int cntx_st_spi_reset (mflash* mfl) { - (void)mfl; - return MFE_OK; -} - -int cntx_st_spi_page_read (mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) { - int rc; - - u_int32_t last_blk_addr; - u_int32_t last_addr; - u_int8_t is_first = 1; - u_int8_t is_last = 0; - u_int8_t* p = data; - - if (addr & ((u_int32_t)mfl->attr.block_write - 1)) { - return MFE_BAD_ALIGN; - } - - if (size & ((u_int32_t)mfl->attr.block_write - 1)) { - return MFE_BAD_ALIGN; - } - - //printf("-D- cntx_st_spi_page_read(addr=%05x, u_int32_t size=%03x)\n", addr, size); - - last_addr = addr + size; - last_blk_addr = last_addr - mfl->attr.block_write; - - while (addr < last_addr) { - if (addr == last_blk_addr) { - is_last = 1; - } - - rc = cntx_st_spi_block_read_ex(mfl, addr, mfl->attr.block_write, p, is_first, is_last); CHECK_RC(rc); - - is_first = 0; - addr += mfl->attr.block_write; - p += mfl->attr.block_write; - } - - return MFE_OK; -} - -/* -int get_flash_offset(u_int32_t addr, int log2_bank_size, u_int32_t *flash_addr_p) -{ - *flash_addr_p = addr & ONES32(log2_bank_size); - return MFE_OK; -} -*/ - -int cntx_st_spi_block_read_ex (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data, u_int8_t is_first, u_int8_t is_last) { - int rc; - u_int32_t i; - u_int32_t gw_cmd = 0; - u_int32_t gw_addr = 0; - - //printf("-D- cntx_st_spi_block_read_ex(addr=%05x, u_int32_t size=%03x, first=%d, last=%d)\n", blk_addr, blk_size, (u_int32_t) is_first, (u_int32_t) is_last); - COM_CHECK_ALLIGN(blk_addr, blk_size); - - if (blk_size > (u_int32_t)mfl->attr.block_write || blk_size < 4) { - return MFE_BAD_PARAMS; - } - - rc = set_bank(mfl, blk_addr); CHECK_RC(rc); - - if (is_first) { - gw_cmd = MERGE(gw_cmd, 1 , HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1 , HBO_ADDR_PHASE, 1); - gw_cmd = MERGE(gw_cmd, SFC_READ , HBO_CMD, HBS_CMD); - - rc = get_flash_offset(blk_addr, mfl->attr.log2_bank_size, &gw_addr); CHECK_RC(rc); - } - //printf("-D- gw_addr = %#x, gw_cmd = %#x, blk_addr = %#x, mfl->attr.log2_bank_size = %#x\n", gw_addr, gw_cmd, blk_addr, mfl->attr.log2_bank_size); - if (!is_last) { - gw_cmd = MERGE(gw_cmd, 1 , HBO_CS_HOLD, 1); - } - - // Read the data block - gw_cmd = MERGE(gw_cmd, 1, HBO_READ_OP, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_DATA_PHASE, 1); - gw_cmd = MERGE(gw_cmd, log2up(blk_size), BO_MSIZE, BS_MSIZE); - - rc = cntx_exec_cmd_get(mfl, gw_cmd,(u_int32_t*)data, (blk_size >> 2), &gw_addr, "Read"); CHECK_RC(rc); - - ////if (mread_by_chunks(mfl->mf, HCR_FLASH_DATA, data, blk_size) != (int)blk_size) { - //if (mread4_block(mfl->mf, HCR_FLASH_DATA, (u_int32_t*)data, blk_size) != (int)blk_size) { - // return 2; - //fprintf(stderr, "-E- Cr read (0x%08x) failed: %s(%d)\n", HCR_FLASH_DATA, strerror(errno), (u_int32_t)errno); - //exit(2); - //} - - for (i = 0; i < blk_size ; i+= 4) { - *(u_int32_t*)(data + i) = __be32_to_cpu(*(u_int32_t*)(data + i)); - } - return MFE_OK; -} - -int cntx_st_spi_block_read (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) { - return cntx_st_spi_block_read_ex(mfl, blk_addr, blk_size, data, 1, 1); -} - -int cntx_st_spi_block_read_old (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) { - int rc; - u_int32_t offs; - u_int32_t gw_cmd = 0; - u_int32_t gw_addr = 0; - - COM_CHECK_ALLIGN(blk_addr, blk_size); - - if (blk_size > (u_int32_t)mfl->attr.block_write || blk_size < 4) { - return MFE_BAD_PARAMS; - } - - rc = set_bank(mfl, blk_addr); CHECK_RC(rc); - - // Read the data block - gw_cmd = MERGE(gw_cmd, 1, HBO_READ_OP, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_ADDR_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_DATA_PHASE, 1); - gw_cmd = MERGE(gw_cmd, log2up(blk_size), BO_MSIZE, BS_MSIZE); - gw_cmd = MERGE(gw_cmd, SFC_READ, HBO_CMD, HBS_CMD); - - gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size); - - rc = cntx_exec_cmd_get(mfl, gw_cmd, (u_int32_t*)data, (blk_size >> 2), &gw_addr, "Read"); CHECK_RC(rc); - - // Data: - for (offs = 0 ; offs < blk_size ; offs += 4) { - *((u_int32_t*)(data + offs))= __cpu_to_be32(*((u_int32_t*)(data + offs))); - } - - return MFE_OK; -} - - -int cntx_st_spi_page_write (mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) { - int rc; - - u_int32_t last_blk_addr; - u_int32_t last_addr; - u_int8_t is_first = 1; - u_int8_t is_last = 0; - u_int8_t* p = data; - - WRITE_CHECK_ALLIGN(addr, mfl->attr.block_write, size); - - last_addr = addr + size; - last_blk_addr = last_addr - mfl->attr.block_write; - - while (addr < last_addr) { - if (addr == last_blk_addr) { - is_last = 1; - } - rc = cntx_st_spi_block_write_ex(mfl, addr, mfl->attr.block_write, p, is_first, is_last, size); CHECK_RC(rc); - - is_first = 0; - addr += mfl->attr.block_write; - p += mfl->attr.block_write; - - } - - return MFE_OK; -} - -int cntx_sst_spi_byte_write (mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) { - int rc; - - u_int32_t last_addr; - u_int8_t* p = data; - - WRITE_CHECK_ALLIGN(addr, mfl->attr.block_write, size); - - last_addr = addr + size; - - while (addr < last_addr) { - rc = cntx_sst_spi_block_write_ex(mfl, addr, mfl->attr.block_write, p); CHECK_RC(rc); - addr++; - p++; - } - - return MFE_OK; -} - -int cntx_st_spi_block_write_ex (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data, u_int8_t is_first, u_int8_t is_last, u_int32_t total_size) { - int rc; - u_int32_t offs; - u_int32_t gw_cmd = 0; - u_int32_t gw_addr = 0; - u_int32_t buff[4]; - - if (blk_addr & ((u_int32_t)mfl->attr.block_write - 1 )) { - return MFE_BAD_ALIGN; - } - - // sanity check ??? remove ??? - if (blk_size != (u_int32_t)mfl->attr.block_write ) { - return MFE_BAD_PARAMS; - } - - rc = set_bank(mfl, blk_addr); CHECK_RC(rc); - - gw_cmd = MERGE(gw_cmd, 1 , HBO_DATA_PHASE, 1); - gw_cmd = MERGE(gw_cmd, log2up(blk_size), HBO_MSIZE, HBS_MSIZE); - - if (is_first) { - rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc); - - // Write the data block - gw_cmd = MERGE(gw_cmd, 1 , HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1 , HBO_ADDR_PHASE, 1); - gw_cmd = MERGE(gw_cmd, SFC_PP , HBO_CMD, HBS_CMD); - gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size); - //printf("-D- gw_addr = %#x, blk_addr = %#x\n", gw_addr, blk_addr); - } - - if (!is_last) { - gw_cmd = MERGE(gw_cmd, 1 , HBO_CS_HOLD, 1); - } - - // Data: - for (offs = 0 ; offs < blk_size ; offs += 4) { - u_int32_t word = zero; - - word = MERGE(word, data[offs + 0] , 24 , 8); - word = MERGE(word, data[offs + 1] , 16 , 8); - word = MERGE(word, data[offs + 2] , 8 , 8); - word = MERGE(word, data[offs + 3] , 0 , 8); - //MWRITE4(HCR_FLASH_DATA + offs, word ); - buff[offs/4] = word; - //printf("-D- word = %#x, %d\n", word, HBS_CMD); - } - - rc = cntx_exec_cmd_set(mfl, gw_cmd, buff, (blk_size >> 2), &gw_addr, "PP command"); CHECK_RC(rc); - - // - // Wait for end of write in flash (WriteInProgress = 0): - // - - if (is_last) { - rc = st_spi_wait_wip(mfl, WRITE_BLOCK_INIT_DELAY + WRITE_ADDITIONAL_BYTE_DELAY * total_size, WRITE_BLOCK_RETRY_DELAY, WRITE_BLOCK_RETRIES); CHECK_RC(rc); - } - - return MFE_OK; -} - -int cntx_sst_spi_block_write_ex (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) { - int rc; - u_int32_t gw_cmd = 0; - u_int32_t gw_addr = 0; - u_int32_t word = zero; - - // sanity check ??? remove ??? - if (blk_size != (u_int32_t)mfl->attr.block_write ) { - return MFE_BAD_PARAMS; - } - - rc = set_bank(mfl, blk_addr); CHECK_RC(rc); - - gw_cmd = MERGE(gw_cmd, 1 , HBO_DATA_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 0, HBO_MSIZE, HBS_MSIZE); - - rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc); - - // Write the data block - gw_cmd = MERGE(gw_cmd, 1 , HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1 , HBO_ADDR_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 0x02 , HBO_CMD, HBS_CMD); - - gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size); - - //gw_cmd = MERGE(gw_cmd, 1 , HBO_CS_HOLD, 1); - - word = MERGE(word, data[0] , 24 , 8); - - //printf("-D- data[0] = %#x, gw_addr = %#x, word = %#x, gw_cmd = %#x\n", data[0], gw_addr, word, gw_cmd); - - rc = cntx_exec_cmd_set(mfl, gw_cmd, &word, 1, &gw_addr, "PB command"); CHECK_RC(rc); - - rc = st_spi_wait_wip(mfl, 0, 0, 50000); CHECK_RC(rc); // Full throttle polling - no cpu optimization for this flash - - return MFE_OK; -} - - -int cntx_st_spi_block_write (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) { - return cntx_st_spi_block_write_ex(mfl, blk_addr, blk_size, data, 1, 1, blk_size); -} - -int cntx_st_spi_erase_sect(mflash* mfl, u_int32_t addr) { - int rc; - - u_int32_t gw_cmd = 0; - u_int32_t gw_addr = 0; - rc = set_bank(mfl, addr); CHECK_RC(rc); - - rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc); - - // Erase sector command: - gw_cmd = MERGE(gw_cmd, 1, HBO_CMD_PHASE, 1); - gw_cmd = MERGE(gw_cmd, 1, HBO_ADDR_PHASE, 1); - gw_cmd = MERGE(gw_cmd, mfl->attr.erase_command, HBO_CMD, HBS_CMD); - - gw_addr = addr & ONES32(mfl->attr.log2_bank_size); - - // printf("-D- cntx_st_spi_erase_sect: addr = %#x, gw_cmd = %#x.\n", addr, gw_cmd); - - rc = cntx_exec_cmd_set(mfl, gw_cmd, NULL, 0, &gw_addr, "ES"); CHECK_RC(rc); - - // Wait for erase completion - rc = st_spi_wait_wip(mfl, ERASE_SUBSECTOR_INIT_DELAY, ERASE_SUBSECTOR_RETRY_DELAY, ERASE_SUBSECTOR_RETRIES); CHECK_RC(rc); - - return MFE_OK; -} - - -f_mf_write get_write_blk_func(int command_set) -{ - if (command_set == MCS_STSPI) { - return cntx_st_spi_page_write; - } - return cntx_sst_spi_byte_write; -} - -int old_flash_lock(mflash* mfl, int lock_state) { - - // Obtain GPIO Semaphore - static u_int32_t cnt = 0; - u_int32_t word; - - // timeout at 5 seconds - TIMER_INIT_AND_START(); - - if (lock_state) { - do { - if (++cnt > GPIO_SEM_TRIES) { - cnt = 0; - //printf("-E- Can not obtain Flash semaphore"); - return MFE_SEM_LOCKED; - } - MREAD4(SEMAP63, &word); - if (word) { - msleep(1); - } - TIMER_CHECK(5, 0, cnt = 0; return MFE_SEM_LOCKED); - } while (word); - } else { - MWRITE4(SEMAP63, 0); - if (cnt > 1) { - // we are not alone... - msleep(1); - } - cnt = 0; - } - mfl->is_locked = (lock_state != 0); - return MFE_OK; -} - - -int cntx_flash_init_direct_access(mflash* mfl, flash_params_t* flash_params) { - int rc; - u_int32_t tmp; - - // Without too much details: - // When the ConnectX boots up without a valid FW , the PCIE link may be unstable. - // In that case, turn off the auto reset on link down, so we'll be able to burn the device. - MREAD4(0x41270, &tmp); - if (tmp > 0xfff00000) { - //we are in livefish. - u_int32_t tmp1; - MREAD4(0xf3834, &tmp1); - tmp1 = MERGE(tmp1, 2, 27, 2); - MWRITE4(0xf3834, tmp1); - - } - - //TODO: Enable page_read (slightly better perf) - //mfl->f_read = cntx_st_spi_page_read; - mfl->f_read = read_chunks; - mfl->f_read_blk = cntx_st_spi_block_read; - mfl->f_lock = old_flash_lock; // Flash lock has same address and functionality as in InfiniHost. - mfl->f_set_bank = empty_set_bank; - mfl->f_get_info = cntx_get_flash_info; - - //if (is_life_fish) { - // rc = cntx_init_gpios(mfl); CHECK_RC(rc); - //} - - mfl->f_spi_status = cntx_st_spi_get_status; - mfl->supp_sr_mod = 1; - - rc = st_spi_fill_attr(mfl, flash_params); CHECK_RC(rc); - - if (mfl->attr.command_set == MCS_STSPI || mfl->attr.command_set == MCS_SSTSPI) { - mfl->f_reset = empty_reset; // Null func - mfl->f_write_blk = get_write_blk_func(mfl->attr.command_set); - - mfl->attr.page_write = 256; - mfl->f_write = write_chunks; - mfl->f_erase_sect = cntx_st_spi_erase_sect; - } else { - return MFE_UNSUPPORTED_FLASH_TYPE; - } - - rc = mfl->f_reset(mfl); - - return MFE_OK; -} - -// InfiniScale 4 (IS4) functions: - -int is4_init_gpios(mflash* mfl) { - (void)mfl; - return MFE_NOT_IMPLEMENTED; -} - - -int is4_flash_lock(mflash* mfl, int lock_state) { - // Obtain GPIO Semaphore - static u_int32_t cnt = 0; - u_int32_t word; - u_int32_t lock_status = 0; - - // timeout at 5 seconds - TIMER_INIT_AND_START(); - - if (lock_state) { - do { - if (++cnt > GPIO_SEM_TRIES) { - cnt = 0; - //printf("-E- Can not obtain Flash semaphore"); - return MFE_SEM_LOCKED; - } - MREAD4(HCR_FLASH_CMD, &word); - lock_status = EXTRACT(word, HBO_LOCK, 1); - if (lock_status) { - msleep(1); - } - TIMER_CHECK(5, 0, cnt = 0; return MFE_SEM_LOCKED); - } while (lock_status); - } else { - MWRITE4(HCR_FLASH_CMD, 0); - if (cnt > 1) { - // we are not alone - msleep(1); - } - cnt = 0; - } - - mfl->is_locked = (lock_state != 0); - return MFE_OK; -} - -#define CACHE_REPLACEMNT_EN_ADDR 0xf0420 -int disable_cache_replacement(mflash *mfl) -{ - u_int32_t data; - MREAD4(CACHE_REPLACEMNT_EN_ADDR, &data); - data = MERGE(data, 0, 0, 1); // We put 0 in the first bit of the read data - MWRITE4(CACHE_REPLACEMNT_EN_ADDR, data); - - return 0; -} - -int restore_cache_replacemnt(mflash *mfl) -{ - u_int32_t data; - MREAD4(CACHE_REPLACEMNT_EN_ADDR, &data); - data = MERGE(data, 1, 0, 1); // We put 1 in the first bit of the read data - MWRITE4(CACHE_REPLACEMNT_EN_ADDR, data); - return MFE_OK; -} - -int connectib_flash_lock(mflash* mfl, int lock_state) -{ - int rc; - if (lock_state == 1) { // lock the flash - rc = is4_flash_lock(mfl, lock_state); CHECK_RC(rc); - rc = disable_cache_replacement(mfl); CHECK_RC(rc); - rc = gw_wait_ready(mfl, "WAIT TO BUSY"); CHECK_RC(rc); - } else { // unlock the flash - rc = restore_cache_replacemnt(mfl); CHECK_RC(rc); - rc = is4_flash_lock(mfl, lock_state); CHECK_RC(rc); - } - return MFE_OK; -} - -#define SX_CS_SUPPORT_ADDR 0xF0420 - -int sx_init_cs_support(mflash* mfl) { - if (IS_SX(mfl->attr.hw_dev_id)) { - u_int8_t cs_support_mask = 0; - u_int32_t data; - if (mfl->opts[MFO_USER_BANKS_NUM] == 0) { - // We assume we have only 2 flashes on SX - mfl->opts[MFO_NUM_OF_BANKS] = 2; - } - // Prepare the bit mask of the banks number - cs_support_mask = (1 << mfl->opts[MFO_NUM_OF_BANKS]) - 1; - - // Read Modify write the cs support field - MREAD4(SX_CS_SUPPORT_ADDR, &data); - data = MERGE(data, cs_support_mask, 0, 4); - MWRITE4(SX_CS_SUPPORT_ADDR, data); - } - return 0; -} - -#define HW_DEV_ID 0xf0014 -#define CACHE_REP_OFF 0xf0408 -#define CASHE_REP_CMD 0xf040c - -int check_cache_replacement_gaurd(mflash* mfl, u_int8_t *needs_cache_replacement) -{ - - *needs_cache_replacement = 0; - - // When we access via command interface, we assume there is a cache replacement! - if (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_MLNXOS_CMDIF) { - if (mfl->opts[MFO_IGNORE_CASHE_REP_GUARD]) { - // dont allow overidding cache replacement in mellanox OS env - return MFE_OCR_NOT_SUPPORTED; - } - *needs_cache_replacement = 1; - return MFE_OK; - } - - if (mfl->opts[MFO_IGNORE_CASHE_REP_GUARD] == 0) { - u_int32_t off, cmd, data; - - // Read the Cache replacement offset - MREAD4(CACHE_REP_OFF, &data); - off = EXTRACT(data, 0, 26); - // Read the Cache replacement cmd - MREAD4(CASHE_REP_CMD, &data); - cmd = EXTRACT(data, 16, 8); - // Check if the offset and cmd are zero in order to continue burning. - if (cmd != 0 || off != 0) { - *needs_cache_replacement = 1; - } - } else { - // Here we ignore the cache replacement check - // We need to execute a write in order to do any needed cache replacement - // Reset the HW ID which is read only register. - MWRITE4(HW_DEV_ID, 0); - } - - return MFE_OK; -} - -int mfl_com_lock(mflash* mfl) -{ - int rc; - // if we already locked the semaphore we dont want to re-lock it - if (mfl->is_locked && (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] != ATBM_INBAND || mfl->opts[MFO_IGNORE_CASHE_REP_GUARD] == 1)) { // on inband w/o ocr we need to extend the lock - return MFE_OK; - } - rc = mfl->f_lock(mfl, 1); - if (!mfl->opts[MFO_IGNORE_SEM_LOCK]) { - CHECK_RC(rc); - } else { - mfl->is_locked = 1; - } - return MFE_OK; -} - -int mf_release_semaphore(mflash* mfl) -{ - return release_semaphore(mfl, 1); -} - -int release_semaphore(mflash* mfl, int ignore_writer_lock) { - int rc; - if (mfl->is_locked && mfl->f_lock && (!mfl->writer_lock || ignore_writer_lock)) { - rc = mfl->f_lock(mfl, 0); CHECK_RC(rc); - } - return MFE_OK; -} - -// ConnectX and Is4 flash interfaces are identical (except lock function) -// Use same functions -// -// TODO: Unify fith ConnectX inif function - -int gen4_flash_init_com(mflash* mfl, flash_params_t* flash_params, u_int8_t init_cs_support) { - - int rc; - - //TODO: Enable page_read (slightly better perf) - //mfl->f_read = cntx_st_spi_page_read; - mfl->f_read = read_chunks; - mfl->f_read_blk = cntx_st_spi_block_read; - mfl->f_set_bank = empty_set_bank; - mfl->f_get_info = cntx_get_flash_info; - - - if (init_cs_support) { - // Update the chip_select_support according to the banks number of cs. - rc = sx_init_cs_support(mfl); CHECK_RC(rc); - } - mfl->f_spi_status = cntx_st_spi_get_status; - mfl->supp_sr_mod = 1; - - rc = st_spi_fill_attr(mfl, flash_params); CHECK_RC(rc); - - if (mfl->attr.command_set == MCS_STSPI || mfl->attr.command_set == MCS_SSTSPI) { - mfl->f_reset = empty_reset; // Null func - //mfl->f_write_blk = cntx_st_spi_block_write; - mfl->f_write_blk = get_write_blk_func(mfl->attr.command_set); - mfl->attr.page_write = 256; - mfl->f_write = write_chunks; - mfl->f_erase_sect = cntx_st_spi_erase_sect; - } else { - return MFE_UNSUPPORTED_FLASH_TYPE; - } - - rc = mfl->f_reset(mfl); - - return MFE_OK; - -} - -int is4_flash_init(mflash* mfl, flash_params_t* flash_params) -{ - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_NO; - mfl->f_lock = is4_flash_lock; - return gen4_flash_init_com(mfl, flash_params, 0); -} - -int sx_flash_init_direct_access(mflash* mfl, flash_params_t* flash_params) -{ - mfl->f_lock = is4_flash_lock; - return gen4_flash_init_com(mfl, flash_params, 1); -} - -int fifth_gen_init_direct_access(mflash* mfl, flash_params_t* flash_params) -{ - mfl->f_lock = connectib_flash_lock; - return gen4_flash_init_com(mfl, flash_params, 0); -} - -/* -typedef int (*f_sx_flash_lock) (mflash* mfl, int lock_state); -typedef int (*f_sx_erase_sect) (mflash* mfl, u_int32_t addr); -typedef int (*f_sx_block_access) (mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data); -typedef int (*f_sx_get_flash_info) (mflash* mfl, unsigned *type_index, int *log2size, u_int8_t *no_flash); -*/ - - -int sx_get_flash_info(mflash* mfl, flash_info_t* f_info, int *log2size, u_int8_t *no_flash) -{ - int rc; - int sem_rc; - sem_rc = mfl_com_lock(mfl); CHECK_RC(sem_rc); - rc = sx_get_flash_info_by_type(mfl, f_info, log2size, no_flash); - sem_rc = release_semaphore(mfl, 0); CHECK_RC(sem_rc); - return rc; -} - - -int sx_block_read(mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) -{ - int rc; - int sem_rc; - sem_rc = mfl_com_lock(mfl); CHECK_RC(sem_rc); - rc = sx_block_read_by_type(mfl, blk_addr, blk_size, data); - sem_rc = release_semaphore(mfl, 0); CHECK_RC(sem_rc); - return rc; -} - -int sx_block_write(mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) -{ - int rc; - int sem_rc; - sem_rc = mfl_com_lock(mfl); CHECK_RC(sem_rc); - rc = sx_block_write_by_type(mfl, addr, size, data); - sem_rc = release_semaphore(mfl, 0); CHECK_RC(sem_rc); - return rc; -} - -int sx_flash_lock(mflash* mfl, int lock_state) -{ - return sx_flash_lock_by_type(mfl, lock_state); -} - -int sx_erase_sect(mflash* mfl, u_int32_t addr) -{ - int rc; - int sem_rc; - sem_rc = mfl_com_lock(mfl); CHECK_RC(sem_rc); - rc = sx_erase_sect_by_type(mfl, addr, mfl->attr.sector_size); - sem_rc = release_semaphore(mfl, 0); CHECK_RC(sem_rc); - return rc; -} - - -int empty_get_status(mflash* mfl, u_int8_t op_type, u_int8_t* status) -{ - // Avoid warnings - (void)mfl; - (void)op_type; - (void)status; - - return MFE_NOT_SUPPORTED_OPERATION; -} - -#define MAX_BLOCK_SIZE(hw_dev_id)\ - (((hw_dev_id) == CX3_HW_ID || hw_dev_id == CX3_PRO_HW_ID) ? MAX_WRITE_BUFFER_SIZE : 128) - -static int update_max_write_size(mflash* mfl) -{ - u_int32_t max_reg_size = mget_max_reg_size(mfl->mf); - u_int32_t max_block_size = MAX_BLOCK_SIZE(mfl->attr.hw_dev_id); - if (!max_reg_size) { - return MFE_BAD_PARAMS; - } - max_reg_size = NEAREST_POW2(max_reg_size); - // limit maximal write to max_block_size - max_block_size = max_reg_size < max_block_size ? max_reg_size : max_block_size; - mfl->attr.block_write = max_block_size; - mfl->attr.page_write = max_block_size; - return ME_OK; -} - -// access flash via FW using Flash Access Registers (either by INBAND/ICMD/TOOLS_HCR) -int flash_init_inband_access(mflash* mfl, flash_params_t* flash_params) -{ - int rc; - - mfl->f_read = read_chunks; - mfl->f_write = write_chunks; - mfl->f_reset = empty_reset; - mfl->f_set_bank = empty_set_bank; - - - mfl->f_get_info = sx_get_flash_info; - mfl->f_lock = sx_flash_lock; - mfl->f_erase_sect = sx_erase_sect; - mfl->f_write_blk = sx_block_write; - mfl->f_read_blk = sx_block_read; - mfl->f_spi_status = empty_get_status; - - mfl->supp_sr_mod = 0; - - // Get the flash attribute - rc = st_spi_fill_attr(mfl, flash_params); CHECK_RC(rc); - update_max_write_size(mfl); CHECK_RC(rc); - return MFE_OK; -} - -int uefi_flash_init(mflash* mfl, flash_params_t* flash_params) -{ - int rc; - - mfl->f_read = read_chunks; - mfl->f_write = write_chunks; - mfl->f_reset = empty_reset; - mfl->f_set_bank = empty_set_bank; - - mfl->f_get_info = sx_get_flash_info; - mfl->f_lock = sx_flash_lock; - mfl->f_erase_sect = sx_erase_sect; - mfl->f_write_blk = sx_block_write; - mfl->f_read_blk = sx_block_read; - mfl->f_spi_status = empty_get_status; - - mfl->supp_sr_mod = 0; - - // Get the flash attribute - - rc = st_spi_fill_attr(mfl, flash_params); CHECK_RC(rc); - update_max_write_size(mfl); CHECK_RC(rc); - return MFE_OK; -} - - -int flash_init_fw_access(mflash* mfl, flash_params_t* flash_params) -{ - // This function checks the access type in order to select the access functions - - int rc; - if ( mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] != ATBM_NO) { - rc = flash_init_inband_access(mfl, flash_params); CHECK_RC(rc); - } else { - return MFE_DIRECT_FW_ACCESS_DISABLED; - } - - if (mfl->opts[MFO_IGNORE_SEM_LOCK]) { - rc = mfl->f_lock(mfl, 0); CHECK_RC(rc); - } - return MFE_OK; -} - -int sx_flash_init(mflash* mfl, flash_params_t* flash_params) -{ - int rc; - u_int8_t needs_cache_replacement; - - rc = check_cache_replacement_gaurd(mfl, &needs_cache_replacement); CHECK_RC(rc); - - if (needs_cache_replacement) { - rc = flash_init_fw_access(mfl, flash_params); CHECK_RC(rc); - } else { - rc = sx_flash_init_direct_access(mfl, flash_params); CHECK_RC(rc); - } - return MFE_OK; -} - - -int icmd_init(mflash *mfl) -{ - // Clear semaphore when asked to by flint or any tool using mflash - if (mfl->opts[MFO_IGNORE_SEM_LOCK]) { - if (icmd_clear_semaphore(mfl->mf) != ME_OK) { - return MFE_CR_ERROR; - } - } - return MFE_OK; -} - -int tools_cmdif_init(mflash *mfl) -{ - // Clear semaphore when asked to by flint or any tool using mflash - if (mfl->opts[MFO_IGNORE_SEM_LOCK]) { - if (tools_cmdif_unlock_semaphore(mfl->mf) != ME_OK) { - return MFE_CR_ERROR; - } - } - return MFE_OK; -} - -int fifth_gen_flash_init(mflash* mfl, flash_params_t* flash_params) -{ - int rc; - u_int8_t needs_cache_replacement; - - rc = check_cache_replacement_gaurd(mfl, &needs_cache_replacement); CHECK_RC(rc); - - if (needs_cache_replacement) { - if (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_ICMD) { - rc = icmd_init(mfl); CHECK_RC(rc); - } - rc = flash_init_fw_access(mfl, flash_params); CHECK_RC(rc); - } else { - rc = fifth_gen_init_direct_access(mfl, flash_params); CHECK_RC(rc); - } - return MFE_OK; -} - -int cntx_flash_init(mflash* mfl, flash_params_t* flash_params) -{ - int rc; - - if ( mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_TOOLS_CMDIF &&\ - mfl->opts[MFO_IGNORE_CASHE_REP_GUARD] == 0 &&\ - mfl->opts[MFO_CX3_FW_ACCESS_EN]) { - #ifdef UEFI_BUILD - // tools CMDIF not supported in UEFI - rc = ME_NOT_IMPLEMENTED; - #else - rc = tcif_cr_mbox_supported(mfl->mf); - #endif - // init with direct access if not supported - if (rc == ME_NOT_IMPLEMENTED || rc == ME_CMDIF_NOT_SUPP ) { - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_NO; - return cntx_flash_init_direct_access(mfl, flash_params); - } - if (rc == ME_SEM_LOCKED && !mfl->opts[MFO_IGNORE_SEM_LOCK]) { - return MFE_SEM_LOCKED; - } - rc = tools_cmdif_init(mfl); CHECK_RC(rc); - rc = flash_init_fw_access(mfl, flash_params); CHECK_RC(rc); - } else { - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_NO; - rc = cntx_flash_init_direct_access(mfl, flash_params); CHECK_RC(rc); - } - return MFE_OK; -} - -// -// Interface functions: -// - -#define CHECK_OUT_OF_RANGE(addr, len, size) {\ - if (addr > size || addr + len > size) {\ - return MFE_OUT_OF_RANGE;\ - }\ -} - -int mf_read (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) { - // printf("mfl->attr.size = %#x, addr = %#x, len = %d\n", mfl->attr.size, addr, len); - - CHECK_OUT_OF_RANGE(addr, len, mfl->attr.size); - //printf("-D- mf_read: addr: %#x, len: %d\n", addr, len); - return mfl->f_read(mfl, addr, len, data); -} - -int mf_write (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) { - CHECK_OUT_OF_RANGE(addr, len, mfl->attr.size); - // Locking semaphore for the entire existence of the mflash obj for write and erase only. - int rc = mfl_com_lock(mfl); CHECK_RC(rc); - mfl->writer_lock = 1; - return mfl->f_write(mfl, addr, len, data); -} - -static int erase_com(mflash* mfl, u_int32_t addr, unsigned int sector_size, int erase_cmd) -{ - int rc; - u_int32_t backup_sector_size; - int backup_erase_command; - if (addr >= mfl->attr.size) { - return MFE_OUT_OF_RANGE; - } - // Locking semaphore for the entire existence of the mflash obj for write and erase only. - rc = mfl_com_lock(mfl); CHECK_RC(rc); - mfl->writer_lock = 1; - backup_sector_size = mfl->attr.sector_size; - backup_erase_command = mfl->attr.erase_command; - mfl->attr.sector_size = sector_size; - mfl->attr.erase_command = erase_cmd; - rc = mfl->f_erase_sect(mfl, addr); - mfl->attr.sector_size = backup_sector_size; - mfl->attr.erase_command = backup_erase_command; - return rc; -} - -int mf_erase(mflash* mfl, u_int32_t addr) { - return erase_com(mfl, addr, mfl->attr.sector_size, mfl->attr.erase_command); -} - -int mf_erase_64k_sector(mflash* mfl, u_int32_t addr) { - if (!mfl->attr.support_sub_and_sector) { - return MFE_UNSUPPORTED_ERASE_OPERATION; - } - return erase_com(mfl, addr, FSS_64KB, SFC_SE); -} - -int mf_erase_4k_sector(mflash* mfl, u_int32_t addr) { - if (!mfl->attr.support_sub_and_sector) { - return MFE_UNSUPPORTED_ERASE_OPERATION; - } - return erase_com(mfl, addr, FSS_4KB, SFC_SSE); -} - -int mf_open_ignore_lock(mflash* mfl) { - mfl->opts[MFO_IGNORE_SEM_LOCK] = 1; - return mf_open_fw(mfl, NULL, -1); -} - -#define CR_LOCK_HW_ID 0xbad0cafe - -#ifndef MST_UL -#define IS_PCI_DEV(access_type) (access_type == MST_PCICONF || access_type == MST_PCI) -#else -#define IS_PCI_DEV(access_type) (access_type == MTCR_ACCESS_CONFIG || access_type == MTCR_ACCESS_MEMORY) -#endif - - - -int get_dev_info(mflash* mfl) -{ - u_int32_t dev_flags; - u_int32_t access_type; - int rc; - u_int32_t dev_id; - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_NO; - rc = mget_mdevs_flags(mfl->mf, &dev_flags); CHECK_RC(rc); - rc = mget_mdevs_type(mfl->mf, &access_type); CHECK_RC(rc); - - // get hw id - // Special case for MLNX OS getting dev_id using REG MGIR - if (dev_flags & MDEVS_MLNX_OS) { - #ifndef UEFI_BUILD - reg_access_status_t rc; - struct register_access_sib_mgir mgir; - memset(&mgir, 0, sizeof(mgir)); - rc = reg_access_mgir(mfl->mf, REG_ACCESS_METHOD_GET, &mgir); - //printf("-D- RC[%s] -- REVID: %d -- DEVID: %d hw_dev_id: %d\n", m_err2str(rc), mgir.HWInfo.REVID, mgir.HWInfo.DEVID, mgir.HWInfo.hw_dev_id); - if (rc) { - dev_id = SWITCHX_HW_ID; - mfl->attr.rev_id = 0; - mfl->attr.hw_dev_id = SWITCHX_HW_ID; - } else { - dev_id = mgir.HWInfo.hw_dev_id; - if (dev_id == 0) { - dev_id = SWITCHX_HW_ID; - mfl->attr.hw_dev_id = SWITCHX_HW_ID; - mfl->attr.rev_id = mgir.HWInfo.REVID & 0xf; - } else { - mfl->attr.hw_dev_id = dev_id; - mfl->attr.rev_id = 0; //WA: MGIR should have also hw_rev_id and then we can use it. - } - } - #else - // no MLNX_OS in UEFI, no mgir register in UEFI package - // we should never reach here - return MFE_UNKOWN_ACCESS_TYPE; - #endif - } else { - MREAD4(HW_DEV_ID, &dev_id); - if (dev_id == CR_LOCK_HW_ID) { - return MFE_LOCKED_CRSPACE; - } - mfl->attr.rev_id = (dev_id & 0xff0000) >> 16; - mfl->attr.hw_dev_id = dev_id & 0xffff; - } - - if (dev_flags & MDEVS_MLNX_OS) { - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_MLNXOS_CMDIF; - } else if (dev_flags & MDEVS_IB){ - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_INBAND; - } else { // not mlnxOS or IB device - check HW ID to determine Access type - if (HAS_ICMD_IF(mfl->attr.hw_dev_id)){ - if (mfl->opts[MFO_IGNORE_CASHE_REP_GUARD] == 0) { - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_ICMD; - } - } else if (HAS_TOOLS_CMDIF(mfl->attr.hw_dev_id) && (IS_PCI_DEV(access_type))) { - if (mfl->opts[MFO_IGNORE_CASHE_REP_GUARD] == 0) { - mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] = ATBM_TOOLS_CMDIF; - } - } - } - return MFE_OK; - -} -//Caller must zero the mflash struct before calling this func. -int mf_open_fw(mflash* mfl, flash_params_t* flash_params, int num_of_banks) -{ - int rc; - if (!mfl) { - return MFE_BAD_PARAMS; - } - rc = set_bank_int(mfl, -1); CHECK_RC(rc); - if (mfl->access_type == MFAT_MFILE ) { - rc = get_dev_info(mfl); CHECK_RC(rc); - -#ifndef UEFI_BUILD - trm_sts trm_rc; - trm_rc = trm_create(&(mfl->trm), mfl->mf); - if (trm_rc) { - return trm2mfe_err(trm_rc); - } -#endif - - mfl->opts[MFO_NUM_OF_BANKS] = spi_get_num_of_flashes(num_of_banks); - rc = spi_update_num_of_banks(mfl, num_of_banks);CHECK_RC(rc); - - if (IS_CONNECTX_4TH_GEN_FAMILY(mfl->attr.hw_dev_id)) { - rc = cntx_flash_init(mfl, flash_params); - } else if (IS_IS4_FAMILY(mfl->attr.hw_dev_id)) { - rc = is4_flash_init(mfl, flash_params); - } else if (IS_SX(mfl->attr.hw_dev_id)) { - rc = sx_flash_init(mfl, flash_params); - } else if (HAS_ICMD_IF(mfl->attr.hw_dev_id)) { - rc = fifth_gen_flash_init(mfl, flash_params); - } else if (mfl->attr.hw_dev_id == 0xffff) { - rc = MFE_HW_DEVID_ERROR; - } else { - rc = MFE_UNSUPPORTED_DEVICE; - } - CHECK_RC(rc); - } else if (mfl->access_type == MFAT_UEFI) { - mfl->opts[MFO_NUM_OF_BANKS] = 1; // We have only one flash in ConnectIB and ConnectX-3 - Need to specify it better! - rc = uefi_flash_init(mfl, flash_params); CHECK_RC(rc); - } else { - return MFE_UNKOWN_ACCESS_TYPE; - } - mfl->f_set_bank(mfl,0); - - return MFE_OK; -} - -int mf_opend_int (mflash** pmfl, void* access_dev, int num_of_banks, flash_params_t* flash_params, int ignore_cache_rep_guard, u_int8_t access_type, - void* dev_extra, int cx3_fw_access) { - int rc; - *pmfl = (mflash*)malloc(sizeof(mflash)); - if (!*pmfl) { - return MFE_NOMEM; - } - - memset(*pmfl, 0, sizeof(mflash)); - - (*pmfl)->opts[MFO_IGNORE_CASHE_REP_GUARD] = ignore_cache_rep_guard; - (*pmfl)->opts[MFO_CX3_FW_ACCESS_EN] = cx3_fw_access; - (*pmfl)->access_type = access_type; - - if (access_type == MFAT_MFILE) { - (*pmfl)->mf = (mfile*)access_dev; - } else if (access_type == MFAT_UEFI) { - // open mfile as uefi - if (!((*pmfl)->mf = mopen_fw_ctx(access_dev, ((uefi_dev_extra_t*)dev_extra)->fw_cmd_func,\ - ((uefi_dev_extra_t*)dev_extra)->dev_info)) ){ - return MFE_NOMEM; - } - // fill some device information - if (((uefi_dev_extra_t*)dev_extra)->dev_info) { - (*pmfl)->attr.hw_dev_id = ((uefi_dev_extra_t*)dev_extra)->dev_info->hw_dev_id; - (*pmfl)->attr.rev_id = ((uefi_dev_extra_t*)dev_extra)->dev_info->rev_id; - } - } - rc = mf_open_fw(*pmfl, flash_params, num_of_banks); - return rc; -} - - -int mf_opend (mflash** pmfl, struct mfile_t* mf, int num_of_banks, flash_params_t* flash_params, int ignore_cache_rep_guard) { - return mf_opend_int(pmfl, mf, num_of_banks, flash_params, ignore_cache_rep_guard, MFAT_MFILE, NULL, 0); -} - - -int mf_open_uefi(mflash** pmfl, uefi_Dev_t *uefi_dev, uefi_dev_extra_t* uefi_dev_extra) -{ - - return mf_opend_int(pmfl, (void*)uefi_dev, 4, NULL, 0, MFAT_UEFI, (void*)uefi_dev_extra, 0); -} - -int mf_open_int (mflash** pmfl, const char* dev, int num_of_banks, flash_params_t* flash_params, - int ignore_cache_rep_guard, int cx3_fw_access) -{ - mfile* mf; - - int rc; - - if (!dev) { - return MFE_BAD_PARAMS; - } - - mf = mopen(dev); - - if (!mf) { - return MFE_CR_ERROR; - } - - rc = mf_opend_int(pmfl, (struct mfile_t*) mf, num_of_banks, flash_params, ignore_cache_rep_guard, MFAT_MFILE, NULL, cx3_fw_access); - - if ((*pmfl)) { - (*pmfl)->opts[MFO_CLOSE_MF_ON_EXIT] = 1; - } - CHECK_RC(rc); - return MFE_OK; -} - -int mf_open_adv (mflash** pmfl, const char* dev, int num_of_banks, flash_params_t* flash_params, - int ignore_cache_rep_guard, int cx3_fw_access) { - return mf_open_int(pmfl, dev, num_of_banks, flash_params, ignore_cache_rep_guard, cx3_fw_access); -} - -int mf_open (mflash** pmfl, const char* dev, int num_of_banks, flash_params_t* flash_params, - int ignore_cache_rep_guard) { - return mf_open_int(pmfl, dev, num_of_banks, flash_params, ignore_cache_rep_guard, 0); -} - -void mf_close (mflash* mfl) { - if (!mfl) { - return; - } - - if (mfl->f_reset) { - mfl->f_reset(mfl); - } - - if (mfl->f_set_bank) { - (void)set_bank(mfl, 0); - } - // we release if we have writer_lock or not doesnt matter on close ... - release_semaphore(mfl, 1); - - if (mfl->mf && (mfl)->opts[MFO_CLOSE_MF_ON_EXIT]) { - mclose(mfl->mf); - } -#ifndef UEFI_BUILD - if (mfl->trm) { - trm_destroy(mfl->trm); - mfl->trm = (trm_ctx)NULL; - } -#endif - free(mfl); - return; -} - - -int mf_get_attr (mflash* mfl, flash_attr* attr) { - *attr = mfl->attr; - return MFE_OK; -} - -int mf_sw_reset (mflash* mfl) { - if (!SUPPORTS_SW_RESET(mfl->attr.hw_dev_id)) { - return MFE_UNSUPPORTED_DEVICE; - } - if (msw_reset(mfl->mf)) { - if (errno == EPERM) { - return MFE_CMD_SUPPORTED_INBAND_ONLY; - } else if (errno == OP_NOT_SUPPORTED) { - return MFE_MANAGED_SWITCH_NOT_SUPPORTED; - } else { - - return MFE_ERROR; - } - } - - return MFE_OK; -} - - -const char* mf_err2str (int err_code) { - - switch (err_code) { - case MFE_OK: - return "MFE_OK"; - case MFE_ERROR : - return "MFE_GENERAL_ERROR"; - case MFE_BAD_PARAMS: - return "MFE_BAD_PARAMS"; - case MFE_CR_ERROR : - return "MFE_CR_ERROR"; - case MFE_HW_DEVID_ERROR: - return "Read a corrupted device id (0xffff). Probably HW/PCI access problem."; - case MFE_INVAL: - return "MFE_INVAL"; - case MFE_NOT_IMPLEMENTED: - return "MFE_NOT_IMPLEMENTED"; - case MFE_UNSUPPORTED_FLASH_TOPOLOGY: - return "MFE_UNSUPPORTED_FLASH_TOPOLOGY"; - case MFE_UNSUPPORTED_FLASH_TYPE: - return "MFE_UNSUPPORTED_FLASH_TYPE"; - case MFE_CFI_FAILED: - return "MFE_CFI_FAILED"; - case MFE_TIMEOUT: - return "MFE_TIMEOUT"; - case MFE_ERASE_TIMEOUT: - return "MFE_ERASE_TIMEOUT"; - case MFE_WRITE_TIMEOUT: - return "MFE_WRITE_TIMEOUT"; - case MFE_ERASE_ERROR: - return "MFE_ERASE_ERROR"; - case MFE_WRITE_ERROR: - return "MFE_WRITE_ERROR"; - case MFE_BAD_ALIGN: - return "MFE_BAD_ALIGN"; - case MFE_SEM_LOCKED: - return "MFE_SEM_LOCKED"; - case MFE_VERIFY_ERROR: - return "MFE_VERIFY_ERROR"; - case MFE_NOMEM: - return "MFE_NOMEM"; - case MFE_OUT_OF_RANGE: - return "MFE_OUT_OF_RANGE"; - case MFE_CMD_SUPPORTED_INBAND_ONLY: - return "Command supported over IB interface only."; - case MFE_NO_FLASH_DETECTED: - return "MFE_NO_FLASH_DETECTED"; - case MFE_LOCKED_CRSPACE: - return "MFE_HW_ACCESS_DISABLED"; - case MFE_CMDIF_BAD_STATUS_ERR: - return "MFE_CMDIF_BAD_STATUS_ERR"; - case MFE_CMDIF_TIMEOUT_ERR: - return "MFE_CMDIF_TIMEOUT_ERR"; - case MFE_CMDIF_GO_BIT_BUSY: - return "MFE_CMDIF_GO_BIT_BUSY"; - case MFE_CMDIF_BAD_OP: - return "MFE_CMDIF_BAD_OP"; - case MFE_MISSING_KEY: - return "No key was set"; - case MFE_MISMATCH_KEY: - return "The given key is incorrect"; - case MFE_UNKNOWN_REG: - return "MFE_UNKNOWN_REG"; - case MFE_DIRECT_FW_ACCESS_DISABLED: - return "MFE_DIRECT_FW_ACCESS_DISABLED"; - case MFE_MANAGED_SWITCH_NOT_SUPPORTED: - return "MFE_MANAGED_SWITCH_NOT_SUPPORTED"; - case MFE_NOT_SUPPORTED_OPERATION: - return "MFE_NOT_SUPPORTED_OPERATION"; - case MFE_FLASH_NOT_EXIST: - return "MFE_FLASH_NOT_EXIST"; - case MFE_MISMATCH_PARAM: - return "MFE_MISMATCH_PARAM"; - case MFE_EXCEED_SUBSECTORS_MAX_NUM: - return "MFE_EXCEED_SUBSECTORS_MAX_NUM"; - case MFE_EXCEED_SECTORS_MAX_NUM: - return "MFE_EXCEED_SECTORS_MAX_NUM"; - case MFE_SECTORS_NUM_NOT_POWER_OF_TWO: - return "MFE_SECTORS_NUM_NOT_POWER_OF_TWO"; - case MFE_UNKOWN_ACCESS_TYPE: - return "MFE_UNKOWN_ACCESS_TYPE"; - case MFE_UNSUPPORTED_DEVICE: - return "MFE_UNSUPPORTED_DEVICE"; - case MFE_UNSUPPORTED_ERASE_OPERATION: - return "MFE_UNSUPPORTED_ERASE_OPERATION"; - case MFE_OLD_DEVICE_TYPE: - return "MFE_OLD_DEVICE_TYPE"; - case MFE_ICMD_INIT_FAILED: - return "MFE_ICMD_INIT_FAILED"; - case MFE_ICMD_NOT_SUPPORTED: - return "MFE_ICMD_NOT_SUPPORTED"; - case MFE_HW_ACCESS_NOT_SUPP: - return "Secure host mode is not enabled in this FW."; - case MFE_MAD_SEND_ERR: - return "MFE_MAD_SEND_ERR"; - case MFE_ICMD_BAD_PARAM: - return "MFE_ICMD_BAD_PARAM"; - case MFE_ICMD_INVALID_OPCODE: - return "MFE_ICMD_INVALID_OPCODE"; - case MFE_ICMD_INVALID_CMD: - return "MFE_ICMD_INVALID_CMD"; - case MFE_ICMD_OPERATIONAL_ERROR: - return "MFE_ICMD_OPERATIONAL_ERROR"; - case MFE_REG_ACCESS_BAD_METHOD: - return "MFE_REG_ACCESS_BAD_METHOD"; - case MFE_REG_ACCESS_NOT_SUPPORTED: - return "MFE_REG_ACCESS_NOT_SUPPORTED"; - case MFE_REG_ACCESS_DEV_BUSY: - return "MFE_REG_ACCESS_DEV_BUSY"; - case MFE_REG_ACCESS_VER_NOT_SUPP: - return "MFE_REG_ACCESS_VER_NOT_SUPP"; - case MFE_REG_ACCESS_UNKNOWN_TLV: - return "MFE_REG_ACCESS_UNKNOWN_TLV"; - case MFE_REG_ACCESS_REG_NOT_SUPP: - return "MFE_REG_ACCESS_REG_NOT_SUPP"; - case MFE_REG_ACCESS_CLASS_NOT_SUPP: - return "MFE_REG_ACCESS_CLASS_NOT_SUPP"; - case MFE_REG_ACCESS_METHOD_NOT_SUPP: - return "MFE_REG_ACCESS_METHOD_NOT_SUPP"; - case MFE_REG_ACCESS_BAD_PARAM: - return "MFE_REG_ACCESS_BAD_PARAM"; - case MFE_REG_ACCESS_RES_NOT_AVLBL: - return "MFE_REG_ACCESS_RESOURCE_NOT_AVAILABLE"; - case MFE_REG_ACCESS_MSG_RECPT_ACK: - return "MFE_REG_ACCESS_MSG_RECPT_ACK"; - case MFE_REG_ACCESS_UNKNOWN_ERR: - return "MFE_REG_ACCESS_UNKNOWN_ERR"; - case MFE_REG_ACCESS_SIZE_EXCCEEDS_LIMIT: - return "MFE_REG_ACCESS_SIZE_EXCCEEDS_LIMIT"; - case MFE_PCICONF: - return "Access to device should be through configuration cycles."; - case MFE_ILLEGAL_BANK_NUM: - return "MFE_ILLEGAL_BANK_NUM"; - case MFE_OCR_NOT_SUPPORTED: - return "Direct flash access is not supported."; - default: - return "Unknown error"; - } -} - -#ifndef UEFI_BUILD -int trm2mfe_err(trm_sts rc) -{ - switch (rc) { - case TRM_STS_DEV_NOT_SUPPORTED: - return MFE_UNSUPPORTED_DEVICE; - case TRM_STS_CR_ACCESS_ERR: - return MFE_CR_ERROR; - case TRM_STS_MEM_ERROR: - return MFE_NOMEM; - default: - return MFE_ERROR; - } -} -#endif - -int mf_set_opt (mflash* mfl, MfOpt opt, int val) { - if ((int)opt < 0 || opt >= MFO_LAST) { - return MFE_BAD_PARAMS; - } - mfl->opts[opt] = val; - return MFE_OK; -} - -int mf_get_opt (mflash* mfl, MfOpt opt, int *val) { - if ((int)opt < 0 || opt >= MFO_LAST) { - return MFE_BAD_PARAMS; - } - *val = mfl->opts[opt]; - return MFE_OK; -} - - -int mf_cr_read (mflash* mfl, u_int32_t cr_addr, u_int32_t* data) { - if (mread4(mfl->mf, cr_addr, data) != 4) { - return MFE_CR_ERROR; - } - return MFE_OK; -} -int mf_cr_write (mflash* mfl, u_int32_t cr_addr, u_int32_t data) { - if (mwrite4(mfl->mf, cr_addr, data) != 4) { - return MFE_CR_ERROR; - } - return MFE_OK; -} - -int mf_update_boot_addr(mflash* mfl, u_int32_t boot_addr) -{ - if (mfl->access_type != MFAT_UEFI && mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] != ATBM_MLNXOS_CMDIF) { - // the boot addr will be updated directly via cr-space - return mf_cr_write(mfl, BOOT_CR_SPACE_ADDR, ((boot_addr << 8) | 0x06)); - } - // the boot addr will be updated via reg - return mf_update_boot_addr_by_type(mfl, boot_addr); -} - -int mf_read_modify_status_winbond (mflash *mfl, u_int8_t bank_num, u_int8_t is_first_status_reg, u_int8_t param, u_int8_t offset, u_int8_t size) -{ - u_int8_t status1 = 0, status2 = 0, use_rdsr2 = 0; - u_int32_t status = 0; - u_int8_t bytes_to_write = 1; - int rc; - - rc = set_bank_int(mfl, bank_num); CHECK_RC(rc); - if ( (mfl->attr.vendor == FV_WINBOND && mfl->attr.type == FMT_WINBOND) || - (mfl->attr.vendor == FV_S25FLXXXX && mfl->attr.type == FMT_S25FL116K)) { - /* - * if we have 2 status registers, winbond are allowing us to write both of them - * in a single command WRSR status_reg1 located in MSB, status_reg2 after status_reg1 - */ - use_rdsr2 = 1; - } - - // Read register status - rc = mfl->f_spi_status(mfl, SFC_RDSR, &status1); CHECK_RC(rc); - if (use_rdsr2) { - rc = mfl->f_spi_status(mfl, SFC_RDSR2, &status2); CHECK_RC(rc); - status = MERGE(0, status2, 0, 8); - bytes_to_write = 2; - } - // Prepare the read status word - status = MERGE(status, status1, 8, 8); - // Modify the status according to the function arguments - status = MERGE(status, param, offset + is_first_status_reg * 8 , size); - // fix status register in case we dont need to write status register 2 - if (bytes_to_write == 1) { - status = status >> 8; - } - // Write register status - rc = cntx_spi_write_status_reg(mfl, status, SFC_WRSR, bytes_to_write); CHECK_RC(rc); - return MFE_OK; -} -#define QUAD_EN_OFFSET 1 -#define QUAD_EN_OFFSET_ST 3 -#define DUMMY_CYCLES_OFFSET_ST 12 - -int mf_read_modify_status_new(mflash *mfl, u_int8_t bank_num, u_int8_t read_cmd, u_int8_t write_cmd, u_int8_t val, - u_int8_t offset, u_int8_t size, u_int8_t bytes_num) -{ - int rc; - u_int32_t status = 0; - - rc = set_bank_int(mfl, bank_num); CHECK_RC(rc); - rc = cntx_int_spi_get_status_data(mfl, read_cmd, &status, bytes_num); CHECK_RC(rc); - status = MERGE(status, val, offset, size); - rc = cntx_spi_write_status_reg(mfl, status, write_cmd, bytes_num); CHECK_RC(rc); - return MFE_OK; -} - -int mf_get_param_int(mflash* mfl, u_int8_t *param_p, u_int8_t cmd, u_int8_t offset, u_int8_t bit_size,\ - u_int8_t bytes_num, u_int8_t enabled_val) -{ - u_int32_t status = 0, is_first = 1, bank; - int rc; - for (bank = 0; bank < mfl->attr.banks_num; bank++ ) { - u_int8_t curr_val; - rc = set_bank_int(mfl, bank); CHECK_RC(rc); - rc = cntx_int_spi_get_status_data(mfl, cmd, &status, bytes_num); CHECK_RC(rc); - - curr_val = EXTRACT(status, offset, bit_size); - if (bit_size == 1) { - curr_val = (curr_val == enabled_val); - } - - if (is_first) { - *param_p = curr_val; - is_first = 0; - } else { - if (*param_p != curr_val) { - return MFE_MISMATCH_PARAM; - } - } - } - return MFE_OK; -} - -int mf_set_dummy_cycles (mflash *mfl, u_int8_t num_of_cycles) -{ - if (!mfl || num_of_cycles < 1 || num_of_cycles > 15) { - return MFE_BAD_PARAMS; - } - int bank, rc; - if (!(mfl->attr.dummy_cycles_support && mfl->supp_sr_mod)) { - return MFE_NOT_SUPPORTED_OPERATION; - } - for (bank = 0; bank < mfl->attr.banks_num; bank++) { - rc = mf_read_modify_status_new(mfl, bank, SFC_RDNVR, SFC_WRNVR, num_of_cycles, DUMMY_CYCLES_OFFSET_ST, 4, 2); CHECK_RC(rc); - } - return MFE_OK; -} - -int mf_get_dummy_cycles(mflash* mfl, u_int8_t *dummy_cycles_p) -{ - if (!mfl || !dummy_cycles_p) { - return MFE_BAD_PARAMS; - } - if (!(mfl->attr.dummy_cycles_support && mfl->supp_sr_mod)) { - return MFE_NOT_SUPPORTED_OPERATION; - } - return mf_get_param_int(mfl, dummy_cycles_p, SFC_RDNVR, DUMMY_CYCLES_OFFSET_ST, 4, 2, 0); - return MFE_OK; -} - - - -int mf_set_quad_en (mflash *mfl, u_int8_t quad_en) -{ - if (!mfl) { - return MFE_BAD_PARAMS; - } - int bank, rc; - if (!(mfl->attr.quad_en_support && mfl->supp_sr_mod)) { - return MFE_NOT_SUPPORTED_OPERATION; - } - for (bank = 0; bank < mfl->attr.banks_num; bank++) { - if (mfl->attr.vendor == FV_WINBOND || mfl->attr.vendor == FV_S25FLXXXX) { - rc = mf_read_modify_status_winbond(mfl, bank, 0, quad_en, QUAD_EN_OFFSET, 1); CHECK_RC(rc); - } else if (mfl->attr.vendor == FV_ST) { - rc = mf_read_modify_status_new(mfl, bank, SFC_RDNVR, SFC_WRNVR, !quad_en, QUAD_EN_OFFSET_ST, 1, 2); CHECK_RC(rc); - } - } - return MFE_OK; -} - -int mf_get_quad_en(mflash* mfl, u_int8_t *quad_en_p) -{ - if (!mfl || !quad_en_p) { - return MFE_BAD_PARAMS; - } - if (!(mfl->attr.quad_en_support && mfl->supp_sr_mod)) { - return MFE_NOT_SUPPORTED_OPERATION; - } - - if (mfl->attr.vendor == FV_WINBOND || mfl->attr.vendor == FV_S25FLXXXX) { - return mf_get_param_int(mfl, quad_en_p, SFC_RDSR2, QUAD_EN_OFFSET, 1, 1, 1); - } else if (mfl->attr.vendor == FV_ST) { - return mf_get_param_int(mfl, quad_en_p, SFC_RDNVR, QUAD_EN_OFFSET_ST, 1, 2, 0); - } - return MFE_NOT_SUPPORTED_OPERATION; -} - -#define REG1_TB_OFFSET 5 -#define REG1_SEC_OFFSET 6 -#define REG1_BP_OFFSET 2 -#define REG1_BP_SIZE 3 -#define ONE_BIT_SIZE 1 - -#define WRITE_PROTECT_CHECKS(mfl, bank_num) { \ - if (!mfl->attr.write_protect_support) {\ - return MFE_NOT_SUPPORTED_OPERATION;\ - }\ - if (bank_num >= mfl->attr.banks_num) {\ - return MFE_FLASH_NOT_EXIST;\ - }\ -} -#define MAX_SUBSECTOR_NUM 8 -#define MAX_SECTORS_NUM 64 - -int mf_set_write_protect(mflash *mfl, u_int8_t bank_num, write_protect_info_t *protect_info) -{ - u_int8_t protect_mask = 0, log2_sect_num = 0; - u_int8_t sectors_num = protect_info->sectors_num; - - //printf("-D- mf_set_write_protect: bank_num = %#x, subsec: %#x, bottom: %#x, sectors_num=%#x\n", bank_num, - // protect_info->is_subsector, protect_info->is_bottom, protect_info->sectors_num); - - WRITE_PROTECT_CHECKS(mfl, bank_num); - if (((protect_info->sectors_num - 1) & protect_info->sectors_num) != 0) { - return MFE_SECTORS_NUM_NOT_POWER_OF_TWO; - } - if (protect_info->sectors_num > MAX_SECTORS_NUM) { - return MFE_EXCEED_SECTORS_MAX_NUM; - } - - if (mfl->attr.protect_sub_and_sector && protect_info->is_subsector) { - if (protect_info->sectors_num > MAX_SUBSECTOR_NUM) { - return MFE_EXCEED_SUBSECTORS_MAX_NUM; - } - } - - for (log2_sect_num = 0; log2_sect_num < 8; log2_sect_num++) { - if (sectors_num == 0) { - break; - } - sectors_num >>= 1; - // printf("-D- sectors_num = %d\n", sectors_num); - } - u_int8_t modify_size = 0; - - protect_mask = MERGE(protect_mask, log2_sect_num, 0, REG1_BP_SIZE); - modify_size += REG1_BP_SIZE; - - protect_mask = MERGE(protect_mask, protect_info->is_bottom, REG1_BP_SIZE, ONE_BIT_SIZE); - modify_size += ONE_BIT_SIZE; - if (mfl->attr.protect_sub_and_sector) { - protect_mask = MERGE(protect_mask, protect_info->is_subsector, REG1_BP_SIZE + ONE_BIT_SIZE, ONE_BIT_SIZE); - modify_size += ONE_BIT_SIZE; - } - return mf_read_modify_status_winbond(mfl, bank_num, 1, protect_mask, REG1_BP_OFFSET, modify_size); -} - -int mf_get_write_protect(mflash *mfl, u_int8_t bank_num, write_protect_info_t *protect_info) -{ - int rc; - u_int8_t status; - - WRITE_PROTECT_CHECKS(mfl, bank_num); - rc = set_bank_int(mfl, bank_num); CHECK_RC(rc); - rc = mfl->f_spi_status(mfl, SFC_RDSR, &status); CHECK_RC(rc); - protect_info->is_bottom = EXTRACT(status, REG1_TB_OFFSET, 1); - - if (mfl->attr.protect_sub_and_sector) { - protect_info->is_subsector = EXTRACT(status, REG1_SEC_OFFSET, 1); - } else { - protect_info->is_subsector = 0; - } - - protect_info->sectors_num = 1 << (EXTRACT(status, REG1_BP_OFFSET, REG1_BP_SIZE) - 1); - - return MFE_OK; -} - -int mf_enable_hw_access(mflash* mfl, u_int64_t key) -{ -#ifndef UEFI_BUILD - int rc; - rc = tcif_hw_access(mfl->mf, key, 0 /* Unlock */); - return (rc == ME_CMDIF_UNKN_TLV) ? MFE_MISMATCH_KEY : MError2MfError(rc); -#else - (void)mfl; - (void)key; - return MFE_NOT_SUPPORTED_OPERATION; -#endif -} - -int mf_disable_hw_access(mflash* mfl) -{ -#ifndef UEFI_BUILD - int rc; - // We need to release the semaphore because we will not have any access to semaphore after disabling the HW access - rc = release_semaphore(mfl, 1); CHECK_RC(rc); - rc = tcif_hw_access(mfl->mf, 0, 1 /* Lock */); - // translate to operation specific errors - switch (rc) { - case ME_CMDIF_UNKN_TLV: - rc = MFE_MISMATCH_KEY; - break; - case ME_CMDIF_BAD_OP: - rc = MFE_MISSING_KEY; - break; - default: - rc = MError2MfError(rc); - break; - } - return rc; -#else - (void)mfl; - return MFE_NOT_SUPPORTED_OPERATION; -#endif -} - -mfile* mf_get_mfile(mflash* mfl) -{ - return mfl->mf; -} - diff --git a/mflash/mflash.h b/mflash/mflash.h deleted file mode 100644 index f0b255a..0000000 --- a/mflash/mflash.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * - * mflash.h - Mellanox Technilogies LTD. Flash access lib heared file - * ================================================================== - * - * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Version: $Id: $ - * - */ -#ifndef MFLASH_H -#define MFLASH_H - -#include -#include -#include "mflash_types.h" -#include "mflash_common_structs.h" - -#include - -#ifdef __cplusplus -#define EXTERN_C_START extern "C" { -#define EXTERN_C_END } -#else -#define EXTERN_C_START -#define EXTERN_C_END -#endif - -EXTERN_C_START - -typedef enum MfCommandSet { - CS_INTEL = 1, - CS_AMD = 2, - - MCS_STSPI = 0x80, // This is not a "real" CFI command set - it's used as a "Meta" command set number. - MCS_SSTSPI = 0x81 -} MfCommandSet; - -typedef struct flash_params { - const char *type_name; - int log2size; - int num_of_flashes; -} flash_params_t; - -typedef struct write_protect_info { - u_int8_t is_subsector; - u_int8_t is_bottom; - u_int8_t sectors_num; -} write_protect_info_t; - -///////////////////////////////////////////// -// -// MFLASH INTERFACE FUNCTIONS -// -// Return value: -// All functions returns MfError enum values. -// -///////////////////////////////////////////// - -struct mfile_t; - - -// -// open/close functions: -// This lib is used pretty much like a C file: open it, use and close when done. -// -// mf_open(): Allocates and init the mflash object to be used with the other lib funcs. -// OUT: pmfl - The opened mflash struct is returned here. -// IN : dev - The string name of the crspace device to use. -// -// mf_opend(): Same as mf_open, but uses an already opened crspace device. -// -// mf_open_ignore_lock() : -// THIS FUNCTION IS NOT SAFE - -// It ignores the flash semaphore during flash init sequence. -// Use only after one of the above open() failed because of MFE_SEM_LOCKED -// and you are absolutely sure that the lock can be overridden (E.G. semaphore -// remained in locked state due to previous kill of the burning app). -// -// mf_close() : Deallocates mflash resources. -// Note: User should call mf_close() even if mf_open failed (and the returning mfl is not NULL) -// -int mf_open (mflash** pmfl, const char* dev, int num_of_banks, flash_params_t* flash_params, - int ignore_cache_rep_guard); -int mf_opend (mflash** pmfl, struct mfile_t* mf, int num_of_banks, flash_params_t* flash_params, - int ignore_cache_rep_guard); -int mf_open_adv (mflash** pmfl, const char* dev, int num_of_banks, flash_params_t* flash_params, - int ignore_cache_rep_guard, int cx3_fw_access); - -int mf_open_uefi(mflash** pmfl, uefi_Dev_t *uefi_dev, uefi_dev_extra_t* dev_extra); - -int mf_open_ignore_lock(mflash* mfl); -void mf_close (mflash* mfl); - -// -// Flash access functions: -// The data buffer should be pre-allocated by caller. The rest is quite self explanatory. . -// -int mf_read (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data); -int mf_write (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data); -// mf_erase performs an erase on the smallest block -int mf_erase(mflash* mfl, u_int32_t addr); -// adv erasing -int mf_erase_64k_sector(mflash* mfl, u_int32_t addr); -int mf_erase_4k_sector(mflash* mfl, u_int32_t addr); - -// swap between erasing 4KB or 64KB chunks (performance optimization) - - -// -// Crspace access through mflash: -// -int mf_cr_read (mflash* mfl, u_int32_t cr_addr, u_int32_t* data); -int mf_cr_write (mflash* mfl, u_int32_t cr_addr, u_int32_t data); - -int mf_update_boot_addr(mflash* mfl, u_int32_t boot_addr); -// Software reset the target device. Currently supported for InfiniScale4 switch via IB interface only. -int mf_sw_reset (mflash* mfl); -// -// mf_get_attr(): Returns the flash_attr struct -// -int mf_get_attr (mflash* mfl, flash_attr* attr); - -int mf_set_quad_en (mflash *mfl, u_int8_t quad_en); -int mf_get_quad_en (mflash *mfl, u_int8_t *quad_en); - -int mf_set_write_protect(mflash *mfl, u_int8_t bank_num, write_protect_info_t *protect_info); -int mf_get_write_protect(mflash *mfl, u_int8_t bank_num, write_protect_info_t *protect_info); - -int mf_set_dummy_cycles (mflash *mfl, u_int8_t num_of_cycles); -int mf_get_dummy_cycles (mflash *mfl, u_int8_t *num_of_cycles); - -// -// Set/Get for some options. -// -int mf_set_opt (mflash* mfl, MfOpt opt, int val); -int mf_get_opt (mflash* mfl, MfOpt opt, int *val); - -int mf_enable_hw_access(mflash* mfl, u_int64_t key); -int mf_disable_hw_access(mflash* mfl); -int mf_release_semaphore(mflash* mfl); - -// get mfile object -mfile* mf_get_mfile(mflash* mfl); - -// -// err code to string translation for printing. -// -const char* mf_err2str (int err_code); - -void mf_flash_list(char *flash_list); - -EXTERN_C_END - -#endif // MFLASH_H - - - diff --git a/mflash/mflash_access_layer.c b/mflash/mflash_access_layer.c deleted file mode 100755 index f5e6836..0000000 --- a/mflash/mflash_access_layer.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#include -#include - -#include "mflash_types.h" -#include "mflash_pack_layer.h" -#include "mflash_access_layer.h" - -extern flash_info_t g_flash_info_arr[]; - - // On windows we don't support cmdIf access! -int check_access_type(mflash* mfl) -//TODO: re-write in a more elegant way. -{ - if (mfl->access_type == MFAT_MFILE) { - switch (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE]) { - case ATBM_INBAND: - #ifdef NO_INBAND_ACCESS - return MFE_NOT_SUPPORTED_OPERATION; - #endif - #ifndef _WIN_ - case ATBM_MLNXOS_CMDIF: - #endif - case ATBM_ICMD: - case ATBM_TOOLS_CMDIF: - break; - default: - return MFE_UNKOWN_ACCESS_TYPE; - } - } else if (mfl->access_type == MFAT_UEFI) { - } else { - return MFE_UNKOWN_ACCESS_TYPE; - } - return MFE_OK; -} - - -int sx_get_flash_info_by_type(mflash* mfl, flash_info_t *f_info, int *log2size, u_int8_t *no_flash) -{ - int rc; - u_int8_t vendor, type, capacity; - u_int32_t jedec_id; - unsigned type_index = 0; - u_int8_t support_sub_and_sector = 0; - - - rc = check_access_type( mfl); CHECK_RC(rc); - rc = com_get_jedec(mfl->mf, get_bank_int(mfl), &jedec_id, &(mfl->attr.fw_flash_sector_sz), &support_sub_and_sector); CHECK_RC(rc); - //printf("-D- jedec_id = %#x\n", jedec_id); - rc = get_info_from_jededc_id(jedec_id, &vendor, &type, &capacity); CHECK_RC(rc); - // Return there is no flash when all the params are 0xff - if (vendor == 0xff && type == 0xff && capacity == 0xff) { - *no_flash = 1; - return MFE_OK; - } - rc = get_type_index_by_vendor_and_type(vendor, type, &type_index); CHECK_RC(rc); - rc = get_log2size_by_capcity(type_index, capacity, log2size); CHECK_RC(rc); - - memcpy(f_info, &(g_flash_info_arr[type_index]), sizeof(flash_info_t)); - f_info->support_sub_and_sector = support_sub_and_sector; - return MFE_OK; -} - -int sx_block_read_by_type(mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) -{ - int rc, bank; - u_int32_t flash_offset; - - if (blk_size > (u_int32_t)mfl->attr.block_write || blk_size < 4) { - return MFE_BAD_PARAMS; - } - rc = mfl_get_bank_info(mfl, blk_addr, &flash_offset, &bank); CHECK_RC(rc); - COM_CHECK_ALLIGN(flash_offset, blk_size); - - rc = check_access_type( mfl); CHECK_RC(rc); - rc = sx_st_block_access(mfl->mf, flash_offset, bank, blk_size, data, REG_ACCESS_METHOD_GET);CHECK_RC(rc); - - return MFE_OK; -} - -int sx_block_write_by_type(mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) -{ - int rc, bank; - u_int32_t flash_offset; - - WRITE_CHECK_ALLIGN(addr, mfl->attr.block_write, size); - - - rc = mfl_get_bank_info(mfl, addr, &flash_offset, &bank); CHECK_RC(rc); - COM_CHECK_ALLIGN(flash_offset, size); - - rc = check_access_type( mfl); CHECK_RC(rc); - rc = sx_st_block_access(mfl->mf, flash_offset, bank, size, data, REG_ACCESS_METHOD_SET);CHECK_RC(rc); - return MFE_OK; -} - -#define MAX_FLASH_PROG_SEM_RETRY_CNT 2048 -static int lock_flash_programing_sem(mflash* mfl) -{ -#ifndef UEFI_BUILD - int rc; - if (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_ICMD || mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_INBAND) { - rc = trm_lock(mfl->trm, TRM_RES_FLASH_PROGRAMING, MAX_FLASH_PROG_SEM_RETRY_CNT); - if (rc && rc != TRM_STS_RES_NOT_SUPPORTED) { - return MFE_SEM_LOCKED; - } - } else if (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_TOOLS_CMDIF) { - rc = trm_lock(mfl->trm, TRM_RES_HCR_FLASH_PROGRAMING, MAX_FLASH_PROG_SEM_RETRY_CNT); - if (rc && rc != TRM_STS_RES_NOT_SUPPORTED) { - return MFE_SEM_LOCKED; - } - } -#endif - return MFE_OK; -} - -static int unlock_flash_programing_sem(mflash* mfl) -{ -#ifndef UEFI_BUILD - int rc; - if (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_ICMD || mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_INBAND) { - rc = trm_unlock(mfl->trm, TRM_RES_FLASH_PROGRAMING); - if (rc && rc != TRM_STS_RES_NOT_SUPPORTED) { - return MFE_SEM_LOCKED; - } - } else if (mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_TOOLS_CMDIF) { - rc = trm_unlock(mfl->trm, TRM_RES_HCR_FLASH_PROGRAMING); - if (rc && rc != TRM_STS_RES_NOT_SUPPORTED) { - return MFE_SEM_LOCKED; - } - } -#endif - return MFE_OK; -} - -int sx_flash_lock_by_type(mflash* mfl, int lock_state) -{ - // burning through some FW interface , lock flash programing semaphore if possible - int rc; - if (lock_state) { - rc = lock_flash_programing_sem(mfl); - } else { - rc = unlock_flash_programing_sem(mfl); - } - if (rc == MFE_OK) { - mfl->is_locked = (lock_state != 0); - } - return rc; -} - -int sx_erase_sect_by_type(mflash* mfl, u_int32_t addr, u_int32_t erase_size) -{ - int rc, bank; - u_int32_t flash_addr; - - rc = mfl_get_bank_info(mfl, addr, &flash_addr, &bank); CHECK_RC(rc); - rc = check_access_type( mfl); CHECK_RC(rc); - rc = common_erase_sector(mfl->mf, flash_addr, bank, erase_size); CHECK_RC(rc); - return MFE_OK; -} - -int mf_update_boot_addr_by_type(mflash* mfl, u_int32_t boot_addr) -{ - int rc; - if (mfl->access_type == MFAT_UEFI || mfl->opts[MFO_FW_ACCESS_TYPE_BY_MFILE] == ATBM_MLNXOS_CMDIF) { - // No CR-Space access - use mfpa register - rc = run_mfpa_command(mfl->mf, REG_ACCESS_METHOD_SET, get_bank_int(mfl), boot_addr, NULL, NULL, NULL, NULL); CHECK_RC(rc); - } - return MFE_OK; -} diff --git a/mflash/mflash_access_layer.h b/mflash/mflash_access_layer.h deleted file mode 100755 index 622e79e..0000000 --- a/mflash/mflash_access_layer.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef MFLASH_ACCESS_LAYER_H_ -#define MFLASH_ACCESS_LAYER_H_ - -#include - -#include "mflash_common_structs.h" - -#define BOOT_CR_SPACE_ADDR 0xf0000 - -int sx_get_flash_info_by_type(mflash* mfl, flash_info_t* type_index, int *log2size, u_int8_t *no_flash); -int sx_block_read_by_type(mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data); -int sx_block_write_by_type(mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data); -int sx_flash_lock_by_type(mflash* mfl, int lock_state); -int sx_erase_sect_by_type(mflash* mfl, u_int32_t addr, u_int32_t erase_size); -int mf_update_boot_addr_by_type(mflash* mfl, u_int32_t boot_addr); - - -#endif /* MFLASH_ACCESS_LAYER_H_ */ diff --git a/mflash/mflash_common_structs.h b/mflash/mflash_common_structs.h deleted file mode 100644 index f03a089..0000000 --- a/mflash/mflash_common_structs.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef MFLASH_COMMON_STRUCTS_H -#define MFLASH_COMMON_STRUCTS_H - -typedef struct mflash mflash; - -typedef enum MfOpt { - MFO_NO_VERIFY = 0, - MFO_AMD_UNLOCK_BYPASS, - MFO_AMD_BYTE_MODE, - MFO_IGNORE_SEM_LOCK, - MFO_CLOSE_MF_ON_EXIT, - MFO_NUM_OF_BANKS, - MFO_IGNORE_CASHE_REP_GUARD, - MFO_USER_BANKS_NUM, - MFO_FW_ACCESS_TYPE_BY_MFILE, - MFO_SX_TYPE, - MFO_NEW_CACHE_REPLACEMENT_EN, - MFO_CX3_FW_ACCESS_EN, - MFO_LAST -} MfOpt; - -enum MfAccessType { - MFAT_MFILE = 0, - MFAT_UEFI, -}; - -///////////////////////////////////////////// -// -// Flash attributes struct -// -///////////////////////////////////////////// -typedef struct flash_attr { - const char *type_str; - // - // hw_dev_id hw dev id of the HCA. - // - u_int32_t hw_dev_id; - u_int32_t rev_id; - - // - // size: Total size (in bytes) of all flash devices connected to - // the device (forming a contigous address space) - // - u_int32_t size; - - // - // sector_size: Flash sector size (in bytes). - // Assuming a single sector size for the flash. - // - u_int32_t sector_size; - - int num_erase_blocks; // Number of sector defs. - - // - // bank_size: Different bank means a different chip sellect or gpio settings is needed when crossing - // this alignment. - // This may indicate a different flash device (for SPI flash in InfiniHostIIILx / ConnectX). - // Or GPIO change for parallel flash (in InfiniHostIII / InfiniHost) - // - int bank_size; - int log2_bank_size; - - // - // Command set (taken from CFI terminology) - // - int command_set; - - u_int8_t erase_command; - - // - // block_write - if block write is supported, holds the block size in bytes. 0 otherwise. - // The meaning of "block write" is not the same in parallel and serial flash. - // - int block_write; - - // - // page_write - if page write is supported, holds the page size in bytes. 0 otherwise. - // - int page_write; - - u_int8_t banks_num; - u_int8_t quad_en_support; - u_int8_t dummy_cycles_support; - u_int8_t write_protect_support; - u_int8_t protect_sub_and_sector; - u_int8_t vendor; - u_int8_t type; - // the flash sector size as seen by FW - u_int32_t fw_flash_sector_sz; - - u_int8_t support_sub_and_sector; // true if flash can work in both 64KB and 4KB sectors - - -} flash_attr; - -typedef struct flash_info { - const char *name; - u_int8_t vendor; - u_int8_t type; - int command_set; - int erase_command; - u_int32_t sector_size; - u_int8_t support_sub_and_sector; - u_int8_t quad_en_support; - u_int8_t write_protected_support; - u_int8_t protect_sub_and_sector; - u_int8_t dummy_cycles_support; -} flash_info_t; - - -#endif // MFLASH_COMMON_STRUCTS_H - - - diff --git a/mflash/mflash_pack_layer.c b/mflash/mflash_pack_layer.c deleted file mode 100755 index e9ecdb8..0000000 --- a/mflash/mflash_pack_layer.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#include "compatibility.h" -#include "bit_slice.h" -#include "mtcr.h" -#include "reg_access.h" - -#include "mflash_types.h" -#include "mflash_pack_layer.h" - -int sx_st_block_access(mfile *mf, u_int32_t flash_addr, u_int8_t bank, u_int32_t size, u_int8_t* data, - u_int8_t method) -{ - struct register_access_mfba mfba; - int rc; - int max_size = mget_max_reg_size(mf); - if (!max_size) { - return MFE_BAD_PARAMS; - } - // when writing max size is limited to the nearest power of 2 of the max_size - // while limiting it to 256 bytes - max_size = NEAREST_POW2(max_size); - - if (size > (u_int32_t)max_size) { - return MFE_BAD_PARAMS; - } - - // Init mfba - memset(&mfba, 0, sizeof(mfba)); - mfba.address = flash_addr; - mfba.fs = bank; - mfba.size = size; - - if (method == REG_ACCESS_METHOD_SET) { - u_int32_t i; - for (i = 0; i < size/4; i++) { - mfba.data[i] = __le32_to_cpu(*((u_int32_t*)&(data[4*i]))); - } - } - rc = reg_access_mfba (mf, (reg_access_method_t) method, &mfba); CHECK_RC(MError2MfError(rc)); - - // Get data from mfba - if (method == REG_ACCESS_METHOD_GET) { - u_int32_t i; - for (i = 0; i < size/4; i++) { - *((u_int32_t*)&(data[i*4]))= __cpu_to_le32(mfba.data[i]); - } - } - return MFE_OK; -} - - -int common_erase_sector(mfile *mf, u_int32_t addr, u_int8_t flash_bank, u_int32_t erase_size) -{ - struct register_access_mfbe mfbe; - if (addr & (erase_size-1)) { - return MFE_ERASE_ERROR; - } - memset(&mfbe, 0, sizeof(mfbe)); - mfbe.address = addr; - mfbe.fs = flash_bank; - if (erase_size == FSS_64KB) { - mfbe.bulk_64kb_erase = 1; - } - return MError2MfError(reg_access_mfbe (mf, REG_ACCESS_METHOD_SET, &mfbe)); -} - -int run_mfpa_command(mfile *mf, u_int8_t access_cmd, u_int8_t flash_bank, u_int32_t boot_address,\ - u_int32_t *jedec_p, int *num_of_banks, u_int32_t* fw_sector_size, u_int8_t* support_sub_and_sector) -{ - struct register_access_mfpa mfpa; - int rc; - - memset(&mfpa, 0, sizeof(mfpa)); - mfpa.fs = flash_bank; - - if (access_cmd == REG_ACCESS_METHOD_SET) { - mfpa.boot_address = boot_address; - } - rc = MError2MfError(reg_access_mfpa (mf, access_cmd, &mfpa)); - - if (rc && rc != MFE_REG_ACCESS_BAD_PARAM) { - // if rc is REG_ACCESS_BAD_PARAM it means we dont have that flash bank connected (no need to fail) - return rc; - } - - if (access_cmd == REG_ACCESS_METHOD_GET && jedec_p != NULL) { - // swap bytes as they are inverted - *jedec_p = ___my_swab32(mfpa.jedec_id); - // HACK: FW had a bug and returned the same jedec-ID even there was no flash, so when flash doesn't exist jedec will be modified to 0xffffffff - if (flash_bank >= mfpa.flash_num || rc == MFE_REG_ACCESS_BAD_PARAM) { - *jedec_p = 0xffffffff; - } - } - if (num_of_banks != NULL) { - *num_of_banks = mfpa.flash_num; - } - - if (fw_sector_size != NULL) { - if (mfpa.sector_size) { - *fw_sector_size = 1 << mfpa.sector_size; // 2^log2_sector_size_in_KB - // Hack: some CX3 FW has this number in KB, possible values : 4 or 64 - if (*fw_sector_size == 4 || *fw_sector_size == 64 ) { - *fw_sector_size *= 1024; - } - } else { - *fw_sector_size = 0; - } - } - - if (support_sub_and_sector != NULL) { - *support_sub_and_sector = mfpa.bulk_64kb_erase_en; - } - - return MFE_OK; -} - -int get_num_of_banks(mfile *mf) -{ - int num_of_banks; - int rc = run_mfpa_command(mf, REG_ACCESS_METHOD_GET, 0, 0, NULL, &num_of_banks, NULL, NULL); - if (rc) { - return -1; - } - return num_of_banks; -} - -int com_get_jedec(mfile *mf, u_int8_t flash_bank, u_int32_t *jedec_p, u_int32_t* fw_flash_sector_size, u_int8_t* supp_sub_and_sector) -{ - return run_mfpa_command(mf, REG_ACCESS_METHOD_GET, flash_bank, 0, jedec_p, NULL, fw_flash_sector_size, supp_sub_and_sector); -} - -/* - * getters and setters for mfl->curr_bank - * manily used to monitor values mfl->curr_bank recieves - * used for a verification hack to make sure facebook reset bug doesnt reproduce. - * (bug where accessing gpio of flash bank 4 caused system reboot) - */ -#define MFLASH_BANK_DEBUG "MFLASH_BANK_DEBUG" -int set_bank_int(mflash* mfl, int bank_num) { - const char* mflash_env; - int max_bank; - - // dont update curr_bank if not needed - if (mfl->curr_bank == bank_num) { - return ME_OK; - } - - mflash_env = getenv(MFLASH_BANK_DEBUG); - if (mflash_env) { - max_bank = atol(mflash_env); - if (bank_num > max_bank) { - printf("-E- there was an attempt to set the flash bank to: %d. max allowed value: %d\n", bank_num, max_bank); - return MFE_ILLEGAL_BANK_NUM; - } - } - mfl->curr_bank = bank_num; - return ME_OK; -} - -int get_bank_int(mflash* mfl) { - return mfl->curr_bank; -} - -int set_bank(mflash* mfl, u_int32_t addr) { - int bank = addr >> mfl->attr.log2_bank_size; - int rc; - - if (get_bank_int(mfl) != bank) { - rc = set_bank_int(mfl, bank); CHECK_RC(rc); - return mfl->f_set_bank(mfl, bank); - } - - return MFE_OK; -} - -int get_flash_offset(u_int32_t addr, int log2_bank_size, u_int32_t *flash_addr_p) -{ - *flash_addr_p = addr & ONES32(log2_bank_size); - return MFE_OK; -} - -int mfl_get_bank_info(mflash *mfl, u_int32_t addr, u_int32_t *flash_off_p, int *bank_p) -{ - int rc; - // Get the bank number - rc = set_bank(mfl, addr); CHECK_RC(rc); - *bank_p = get_bank_int(mfl); - // Get the offset in the flash - rc = get_flash_offset(addr, mfl->attr.log2_bank_size, flash_off_p); CHECK_RC(rc); - return MFE_OK; -} - -MfError MError2MfError(MError rc) { - switch(rc) { - case ME_OK: - return MFE_OK; - case ME_ERROR: - return MFE_ERROR; - case ME_BAD_PARAMS: - return MFE_BAD_PARAMS; - case ME_CR_ERROR: - return MFE_CR_ERROR; - case ME_NOT_IMPLEMENTED: - return MFE_NOT_IMPLEMENTED; - case ME_SEM_LOCKED: - return MFE_SEM_LOCKED; - case ME_MEM_ERROR: - return MFE_NOMEM; - case ME_MAD_SEND_FAILED: - return MFE_MAD_SEND_ERR; - case ME_UNKOWN_ACCESS_TYPE: - return MFE_UNKOWN_ACCESS_TYPE; - case ME_UNSUPPORTED_DEVICE: - return MFE_UNSUPPORTED_DEVICE; - case ME_ICMD_STATUS_CR_FAIL: - return MFE_CR_ERROR; - case ME_ICMD_STATUS_SEMAPHORE_TO: - return MFE_SEM_LOCKED; - case ME_ICMD_STATUS_EXECUTE_TO: - return MFE_CMDIF_TIMEOUT_ERR; - case ME_ICMD_STATUS_IFC_BUSY: - return MFE_CMDIF_TIMEOUT_ERR; - case ME_ICMD_STATUS_ICMD_NOT_READY: - return MFE_CMDIF_GO_BIT_BUSY; - case ME_ICMD_UNSUPPORTED_ICMD_VERSION: - return MFE_ICMD_NOT_SUPPORTED; - case ME_ICMD_NOT_SUPPORTED: - return MFE_ICMD_NOT_SUPPORTED; - case ME_ICMD_INVALID_OPCODE: - return MFE_ICMD_INVALID_OPCODE; - case ME_ICMD_INVALID_CMD: - return MFE_ICMD_INVALID_CMD; - case ME_ICMD_OPERATIONAL_ERROR: - return MFE_ICMD_OPERATIONAL_ERROR; - case ME_ICMD_BAD_PARAM: - return MFE_ICMD_BAD_PARAM; - case ME_ICMD_BUSY: - return MFE_CMDIF_TIMEOUT_ERR; - - case ME_REG_ACCESS_BAD_METHOD: - return MFE_REG_ACCESS_BAD_METHOD; - case ME_REG_ACCESS_NOT_SUPPORTED: - return MFE_REG_ACCESS_NOT_SUPPORTED; - case ME_REG_ACCESS_DEV_BUSY: - return MFE_REG_ACCESS_DEV_BUSY; - case ME_REG_ACCESS_VER_NOT_SUPP: - return MFE_REG_ACCESS_VER_NOT_SUPP; - case ME_REG_ACCESS_UNKNOWN_TLV: - return MFE_REG_ACCESS_UNKNOWN_TLV; - case ME_REG_ACCESS_REG_NOT_SUPP: - return MFE_REG_ACCESS_REG_NOT_SUPP; - case ME_REG_ACCESS_CLASS_NOT_SUPP: - return MFE_REG_ACCESS_CLASS_NOT_SUPP; - case ME_REG_ACCESS_METHOD_NOT_SUPP: - return MFE_REG_ACCESS_METHOD_NOT_SUPP; - case ME_REG_ACCESS_BAD_PARAM: - return MFE_REG_ACCESS_BAD_PARAM; - case ME_REG_ACCESS_RES_NOT_AVLBL: - return MFE_REG_ACCESS_RES_NOT_AVLBL; - case ME_REG_ACCESS_MSG_RECPT_ACK: - return MFE_REG_ACCESS_MSG_RECPT_ACK; - case ME_REG_ACCESS_UNKNOWN_ERR: - return MFE_REG_ACCESS_UNKNOWN_ERR; - case ME_REG_ACCESS_SIZE_EXCCEEDS_LIMIT: - return MFE_REG_ACCESS_SIZE_EXCCEEDS_LIMIT; - - case ME_CMDIF_UNKN_TLV: - return MFE_CMDIF_UNKN_TLV; - case ME_CMDIF_BAD_OP: - return MFE_CMDIF_BAD_OP; - default: - break; - } - return MFE_INVAL; -} diff --git a/mflash/mflash_pack_layer.h b/mflash/mflash_pack_layer.h deleted file mode 100755 index f36859c..0000000 --- a/mflash/mflash_pack_layer.h +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * mflash_inband.h - * - * Created on: Jul 6, 2011 - * Author: mohammad - */ - -#ifndef MFLASH_COMMON_H_ -#define MFLASH_COMMON_H_ - -#include "mflash_types.h" -#include "mflash_common_structs.h" - -#ifndef UEFI_BUILD -#include -#else -typedef void* trm_ctx; -#endif - -// TODO: use: (int)log2((float)num) -#define NEAREST_POW2(num)\ - (num) < (256) ? ((num) < (128) ? ((num) < (64) ? ((num) < (32) ? ((num) < (16) ? ((num) < (8) ? (4) : (8)): (16)): (32)): (64)): (128)): (256) - -#ifndef CHECK_RC - #define CHECK_RC(rc) do {if (rc) return rc;} while(0) -#endif - -#ifndef ARR_SIZE - #define ARR_SIZE(arr) sizeof(arr)/sizeof(arr[0]) -#endif - -#ifndef IRISC -#define MFLASH_ERR_STR_SIZE 1024 -#else -#define MFLASH_ERR_STR_SIZE 4 -#endif -typedef int (*f_mf_lock) (mflash* mfl, int lock_state); - -typedef int (*f_mf_set_bank) (mflash* mfl, u_int32_t bank); -typedef int (*f_mf_read) (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data); -typedef int (*f_mf_write) (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data); -typedef int (*f_mf_erase_sect)(mflash* mfl, u_int32_t addr); -typedef int (*f_mf_reset) (mflash* mfl); - -typedef int (*f_st_spi_status)(mflash* mfl, u_int8_t op_type, u_int8_t* status); -typedef int (*f_mf_get_info) (mflash* mfl, flash_info_t *f_info, int *log2size, u_int8_t *no_flash); -///////////////////////////////////////////// -// -// MFlash struct -// -///////////////////////////////////////////// -struct mflash { -#ifndef IRISC - mfile* mf; -#endif - - // Functions: - f_mf_lock f_lock; - - f_mf_set_bank f_set_bank; - f_mf_get_info f_get_info; - - f_mf_read f_read; - f_mf_write f_write; - f_mf_write f_write_blk; // write and write_block have the same signateure, but theyr'e not the same func ! - f_mf_read f_read_blk; // read and read_block have the same signateure, but theyr'e not the same func ! - f_mf_erase_sect f_erase_sect; - f_mf_reset f_reset; - - // Relevant for SPI flash (InfiniHostIIILx, ConnectX) only - f_st_spi_status f_spi_status; - // when set(1) we support modification of the flash status register - u_int8_t supp_sr_mod; - - int curr_bank; - int is_locked; - // if writer_lock is set, semaphore should be freed only in mf_close()/disable_hw_access() - int writer_lock; - - flash_attr attr; - - int opts[MFO_LAST]; - char last_err_str[MFLASH_ERR_STR_SIZE]; - - u_int8_t access_type; //0 = mfile , 1 = uefi - trm_ctx trm; - -}; - -enum AccessTypeByMfile{ - ATBM_NO = 0, - ATBM_INBAND, - ATBM_MLNXOS_CMDIF, - ATBM_ICMD, - ATBM_TOOLS_CMDIF, -}; - -/* -#ifndef __WIN__ - -#ifdef __FreeBSD__ -#define SWAPL(l) ntohl(l) -#include -#else // Linux -#include -#include - -#define SWAPL(l) bswap_32(l) -#endif - -#else - -#include -#include -#define SWAPL(l) ntohl(l) -#define __BYTE_ORDER __LITTLE_ENDIAN -*/ - -/* -#define __cpu_to_be32(val) SWAPL(val) // Win is only run on LE CPUS -#define inline __inline -#define __cpu_to_be32(val) SWAPL(val) // Win is only run on LE CPUS -*/ -//#endif - -/* -#ifndef __cpu_to_le32 - -#if __BYTE_ORDER == __LITTLE_ENDIAN - #define __cpu_to_le32(x) (x) -#elif __BYTE_ORDER == __BIG_ENDIAN - #define __cpu_to_le32(x) SWAPL(x) -#endif // __BYTE_ORDER - -#endif - -#ifndef __le32_to_cpu - #define __le32_to_cpu(x) __cpu_to_le32(x) -#endif -*/ - -#define WRITE_CHECK_ALLIGN(addr, block_write, size) {\ - if (addr & ((u_int32_t)block_write - 1)) {\ - return MFE_BAD_ALIGN;\ - }\ - if (size & ((u_int32_t)block_write - 1)) {\ - return MFE_BAD_ALIGN;\ - }\ -} - -#define COM_CHECK_ALLIGN(flash_addr, size) {\ - if (flash_addr & (size - 1 )) {\ - return MFE_BAD_ALIGN;\ - }\ -} - -//////////////////////////////////// SX FLASH functions //////////////////////////////////// - -typedef u_int32_t (*f_reg_pack) (void *data_to_pack, u_int8_t *packed_buffer); -typedef void (*f_reg_unpack) (void *unpacked_data, u_int8_t *buffer_to_unpack); -typedef void (*f_reg_dump) (void *data_to_print, FILE *out_port); - -int sx_st_block_access(mfile *mf, u_int32_t flash_addr, u_int8_t bank, u_int32_t size, u_int8_t* data,\ - u_int8_t method); - - -int common_erase_sector(mfile *mf, u_int32_t addr, u_int8_t flash_bank, u_int32_t erase_size); - -int run_mfpa_command(mfile *mf, u_int8_t access_cmd, u_int8_t flash_bank, u_int32_t boot_address,\ - u_int32_t *jedec_p, int *num_of_banks, u_int32_t* fw_flash_sector_sz, u_int8_t* supp_sub_and_sector); - -int com_get_jedec(mfile *mf, u_int8_t flash_bank, u_int32_t *jedec_p, u_int32_t* fw_flash_sector_sz, u_int8_t* supp_sub_and_sector); -int get_num_of_banks(mfile *mf); -int get_info_from_jededc_id(u_int32_t jededc_id, u_int8_t *vendor, u_int8_t* type, u_int8_t* capacity); -int get_type_index_by_vendor_and_type(u_int8_t vendor, u_int8_t type, unsigned *type_index); -int get_log2size_by_capcity(unsigned type_index, u_int8_t capacity, int *log2size); -int get_max_reg_size(mfile *mf); - -int set_bank(mflash* mfl, u_int32_t addr); -int set_bank_int(mflash* mfl, int bank_num); -int get_bank_int(mflash* mfl); -int get_flash_offset(u_int32_t addr, int log2_bank_size, u_int32_t *flash_addr_p); -int mfl_get_bank_info(mflash *mfl, u_int32_t addr, u_int32_t *flash_off_p, int *bank_p); -MfError MError2MfError(MError rc); - -#endif /* MFLASH_COMMON_H_ */ diff --git a/mflash/mflash_types.h b/mflash/mflash_types.h deleted file mode 100644 index f9ff938..0000000 --- a/mflash/mflash_types.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef MFLASH_TYPES_H -#define MFLASH_TYPES_H - -typedef enum { - FSS_4KB = 0x1000, - FSS_64KB = 0x10000 -} Flash_Sector_Size_t; - - -typedef enum MfError { - MFE_OK = 0, - MFE_ERROR, - MFE_BAD_PARAMS, - MFE_CR_ERROR, - MFE_HW_DEVID_ERROR, - MFE_INVAL, - MFE_NOT_IMPLEMENTED, - MFE_UNSUPPORTED_FLASH_TOPOLOGY, - MFE_UNSUPPORTED_FLASH_TYPE, - MFE_CFI_FAILED, - MFE_TIMEOUT, - MFE_ERASE_TIMEOUT, - MFE_WRITE_TIMEOUT, - MFE_ERASE_ERROR, - MFE_WRITE_ERROR, - MFE_BAD_ALIGN, - MFE_SEM_LOCKED, - MFE_VERIFY_ERROR, - MFE_NOMEM, - MFE_OUT_OF_RANGE, - MFE_CMD_SUPPORTED_INBAND_ONLY, - MFE_NO_FLASH_DETECTED, - MFE_LOCKED_CRSPACE, - MFE_CMDIF_BAD_STATUS_ERR, - MFE_CMDIF_TIMEOUT_ERR, - MFE_CMDIF_GO_BIT_BUSY, - MFE_CMDIF_UNKN_TLV, - MFE_CMDIF_BAD_OP, - MFE_MISMATCH_KEY, - MFE_MISSING_KEY, - MFE_UNKNOWN_REG, - MFE_DIRECT_FW_ACCESS_DISABLED, - MFE_MANAGED_SWITCH_NOT_SUPPORTED, - MFE_NOT_SUPPORTED_OPERATION, - MFE_FLASH_NOT_EXIST, - MFE_MISMATCH_PARAM, - MFE_EXCEED_SUBSECTORS_MAX_NUM, - MFE_EXCEED_SECTORS_MAX_NUM, - MFE_SECTORS_NUM_NOT_POWER_OF_TWO, - MFE_UNKOWN_ACCESS_TYPE, - MFE_UNSUPPORTED_DEVICE, - MFE_UNSUPPORTED_ERASE_OPERATION, - MFE_OLD_DEVICE_TYPE, - MFE_ICMD_INIT_FAILED, - MFE_ICMD_NOT_SUPPORTED, - MFE_HW_ACCESS_NOT_SUPP, - MFE_MAD_SEND_ERR, - MFE_ICMD_BAD_PARAM, - MFE_ICMD_INVALID_OPCODE, - MFE_ICMD_INVALID_CMD, - MFE_ICMD_OPERATIONAL_ERROR, - - MFE_REG_ACCESS_BAD_METHOD, - MFE_REG_ACCESS_NOT_SUPPORTED, - MFE_REG_ACCESS_DEV_BUSY, - MFE_REG_ACCESS_VER_NOT_SUPP, - MFE_REG_ACCESS_UNKNOWN_TLV, - MFE_REG_ACCESS_REG_NOT_SUPP, - MFE_REG_ACCESS_CLASS_NOT_SUPP, - MFE_REG_ACCESS_METHOD_NOT_SUPP, - MFE_REG_ACCESS_BAD_PARAM, - MFE_REG_ACCESS_RES_NOT_AVLBL, - MFE_REG_ACCESS_MSG_RECPT_ACK, - MFE_REG_ACCESS_UNKNOWN_ERR, - MFE_REG_ACCESS_SIZE_EXCCEEDS_LIMIT, - MFE_PCICONF, - MFE_ILLEGAL_BANK_NUM, - MFE_OCR_NOT_SUPPORTED, - - MFE_LAST -} MfError; - -#endif // MFLASH_TYPES_H - - - diff --git a/mft_utils/Makefile.am b/mft_utils/Makefile.am deleted file mode 100644 index 43df9fe..0000000 --- a/mft_utils/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in -USER_DIR = $(top_srcdir) -AM_CPPFLAGS = -I. -I$(USER_DIR)/common - -AM_CFLAGS = -MD -pipe -Wall -W -Werror - -noinst_HEADERS = mft_sig_handler.h errmsg.h - -noinst_LIBRARIES = libmftutils.a - -libmftutils_a_SOURCES = mft_sig_handler.c errmsg.cpp calc_hw_crc.c mlarge_buffer.cpp - diff --git a/mft_utils/calc_hw_crc.c b/mft_utils/calc_hw_crc.c deleted file mode 100644 index 115000d..0000000 --- a/mft_utils/calc_hw_crc.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "stdio.h" -#include "string.h" -#include - -#include "calc_hw_crc.h" - -u_int16_t crc16table2[256] = { - 0x0000, 0x1BA1, 0x3742, 0x2CE3, 0x6E84, 0x7525, 0x59C6, 0x4267, - 0xDD08, 0xC6A9, 0xEA4A, 0xF1EB, 0xB38C, 0xA82D, 0x84CE, 0x9F6F, - 0x1A01, 0x01A0, 0x2D43, 0x36E2, 0x7485, 0x6F24, 0x43C7, 0x5866, - 0xC709, 0xDCA8, 0xF04B, 0xEBEA, 0xA98D, 0xB22C, 0x9ECF, 0x856E, - 0x3402, 0x2FA3, 0x0340, 0x18E1, 0x5A86, 0x4127, 0x6DC4, 0x7665, - 0xE90A, 0xF2AB, 0xDE48, 0xC5E9, 0x878E, 0x9C2F, 0xB0CC, 0xAB6D, - 0x2E03, 0x35A2, 0x1941, 0x02E0, 0x4087, 0x5B26, 0x77C5, 0x6C64, - 0xF30B, 0xE8AA, 0xC449, 0xDFE8, 0x9D8F, 0x862E, 0xAACD, 0xB16C, - 0x6804, 0x73A5, 0x5F46, 0x44E7, 0x0680, 0x1D21, 0x31C2, 0x2A63, - 0xB50C, 0xAEAD, 0x824E, 0x99EF, 0xDB88, 0xC029, 0xECCA, 0xF76B, - 0x7205, 0x69A4, 0x4547, 0x5EE6, 0x1C81, 0x0720, 0x2BC3, 0x3062, - 0xAF0D, 0xB4AC, 0x984F, 0x83EE, 0xC189, 0xDA28, 0xF6CB, 0xED6A, - 0x5C06, 0x47A7, 0x6B44, 0x70E5, 0x3282, 0x2923, 0x05C0, 0x1E61, - 0x810E, 0x9AAF, 0xB64C, 0xADED, 0xEF8A, 0xF42B, 0xD8C8, 0xC369, - 0x4607, 0x5DA6, 0x7145, 0x6AE4, 0x2883, 0x3322, 0x1FC1, 0x0460, - 0x9B0F, 0x80AE, 0xAC4D, 0xB7EC, 0xF58B, 0xEE2A, 0xC2C9, 0xD968, - 0xD008, 0xCBA9, 0xE74A, 0xFCEB, 0xBE8C, 0xA52D, 0x89CE, 0x926F, - 0x0D00, 0x16A1, 0x3A42, 0x21E3, 0x6384, 0x7825, 0x54C6, 0x4F67, - 0xCA09, 0xD1A8, 0xFD4B, 0xE6EA, 0xA48D, 0xBF2C, 0x93CF, 0x886E, - 0x1701, 0x0CA0, 0x2043, 0x3BE2, 0x7985, 0x6224, 0x4EC7, 0x5566, - 0xE40A, 0xFFAB, 0xD348, 0xC8E9, 0x8A8E, 0x912F, 0xBDCC, 0xA66D, - 0x3902, 0x22A3, 0x0E40, 0x15E1, 0x5786, 0x4C27, 0x60C4, 0x7B65, - 0xFE0B, 0xE5AA, 0xC949, 0xD2E8, 0x908F, 0x8B2E, 0xA7CD, 0xBC6C, - 0x2303, 0x38A2, 0x1441, 0x0FE0, 0x4D87, 0x5626, 0x7AC5, 0x6164, - 0xB80C, 0xA3AD, 0x8F4E, 0x94EF, 0xD688, 0xCD29, 0xE1CA, 0xFA6B, - 0x6504, 0x7EA5, 0x5246, 0x49E7, 0x0B80, 0x1021, 0x3CC2, 0x2763, - 0xA20D, 0xB9AC, 0x954F, 0x8EEE, 0xCC89, 0xD728, 0xFBCB, 0xE06A, - 0x7F05, 0x64A4, 0x4847, 0x53E6, 0x1181, 0x0A20, 0x26C3, 0x3D62, - 0x8C0E, 0x97AF, 0xBB4C, 0xA0ED, 0xE28A, 0xF92B, 0xD5C8, 0xCE69, - 0x5106, 0x4AA7, 0x6644, 0x7DE5, 0x3F82, 0x2423, 0x08C0, 0x1361, - 0x960F, 0x8DAE, 0xA14D, 0xBAEC, 0xF88B, 0xE32A, 0xCFC9, 0xD468, - 0x4B07, 0x50A6, 0x7C45, 0x67E4, 0x2583, 0x3E22, 0x12C1, 0x0960}; - -u_int16_t calc_hw_crc(u_int8_t* d, int size) { - int i; - u_int8_t* data = (u_int8_t*) malloc(sizeof(u_int8_t) * size); - - memcpy(data, d, size); - data[0] = ~data[0]; - data[1] = ~data[1]; - - unsigned crc = 0xffff; - for (i = 0; i < size; i++) { - int table_index = ((crc ^ data[i]) & 0xff); - crc = ((crc >> 8) ^ crc16table2[table_index]); - }; - crc = ((crc << 8) & 0xff00) | ((crc >> 8) & 0xff); - - free(data); - return crc; -} diff --git a/mft_utils/calc_hw_crc.h b/mft_utils/calc_hw_crc.h deleted file mode 100644 index b1627ec..0000000 --- a/mft_utils/calc_hw_crc.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef MFT_CALC_HW_CRC -#define MFT_CALC_HW_CRC - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -u_int16_t calc_hw_crc(u_int8_t* data, int size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/mft_utils/errmsg.cpp b/mft_utils/errmsg.cpp deleted file mode 100644 index f386e76..0000000 --- a/mft_utils/errmsg.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include - -#include "errmsg.h" - -enum { - SUCCESS = 0, - FAILURE = 1 -}; - -ErrMsg::ErrMsg() { - _errMap[SUCCESS] = "SUCCESS"; - _errMap[FAILURE] = "FAILURE"; - _err = NULL; - _formatErr = NULL; - _lastErrCode = SUCCESS; -} - -ErrMsg::ErrMsg(std::map& errCodeMap) { - _errMap = errCodeMap; - _err = NULL; - _formatErr = NULL; - _lastErrCode = SUCCESS; -} - -const char* ErrMsg::getFormatErr(const char *prefix, ...) { - va_list args; - char* prevFormatErr = _formatErr; - va_start(args, prefix); - char* preStr = vprint(prefix, args); - int formatErrSz = strlen(_err) + strlen(preStr) + 10; - _formatErr = new char[formatErrSz]; - snprintf(_formatErr, formatErrSz, "-E- %s. %s", preStr, _err); - va_end(args); - delete[] prevFormatErr; - delete[] preStr; - return _formatErr; -} - -const char* ErrMsg::err2Str(int errCode) const { - std::map::const_iterator it; - if ( (it=_errMap.find(errCode)) == _errMap.end()) { - return "Unknown Error Code"; - } - return it->second.c_str(); -} - -char* ErrMsg::vprint(const char *format, va_list args) { - const int INIT_VAL = 1024; - int max_str, max_buf = INIT_VAL; - char *out_buf; - - while (1) { - out_buf = new char[max_buf]; - max_str = max_buf - 1; - - if (vsnprintf(out_buf, max_str, format, args) < max_str) { - return out_buf; - } - delete [] out_buf; - max_buf *= 2; - } -} - -int ErrMsg::errmsg(const char *format, ...) { - va_list args; - - char* prev_err = _err; - - va_start(args, format); - _err = vprint(format, args); - va_end(args); - - delete[] prev_err; - _lastErrCode = FAILURE; - return FAILURE; -} - -int ErrMsg::errmsg(int errCode, const char *format, ...) { - va_list args; - char* prev_err = _err; - - va_start(args, format); - _err = vprint(format, args); - va_end(args); - - delete[] prev_err; - _lastErrCode = errCode; - return errCode; -} - -int ErrMsg::errmsg(int errCode) { - char* prevErr = _err; - int errSz = strlen(err2Str(errCode)) + 1; - char* newError = new char[errSz]; - snprintf(newError, errSz, "%s", err2Str(errCode)); - _err = newError; - delete[] prevErr; - _lastErrCode = errCode; - return errCode; - -} -void ErrMsg::errmsgConcatCom(const char* format, va_list args, const char* suffix) { - char* prevErr = _err; - char* currError = vprint(format, args); - int errSz = strlen(currError) + strlen(suffix) + 10; - char* newError = new char[errSz]; - if (strlen(currError) == 0) { - snprintf(newError,errSz, "%s", suffix); - } else { - if (strlen(suffix) == 0) { - snprintf(newError,errSz, "%s", currError); - } else { - snprintf(newError,errSz, "%s. %s", currError, suffix); - } - } - _err = newError; - - delete[] prevErr; - delete[] currError; -} - -int ErrMsg::errmsgConcatMsg(int errCode, const ErrMsg& errMsgObj, const char *format, ...) { - va_list args; - va_start(args, format); - errmsgConcatCom(format, args, errMsgObj.err()); - va_end(args); - _lastErrCode = errCode; - return errCode; -} - -int ErrMsg::errmsgConcatMsg(const ErrMsg& errMsgObj, const char *format, ...) { - va_list args; - va_start(args, format); - errmsgConcatCom(format, args, errMsgObj.err()); - va_end(args); - _lastErrCode = FAILURE; - return FAILURE; -} - -int ErrMsg::errmsgConcatMsg(int errCode, const ErrMsg& errMsgObj) { - return errmsg(errCode, "%s", errMsgObj.err()); -} - -int ErrMsg::errmsgConcatMsg(const ErrMsg& errMsgObj) { - return errmsg("%s", errMsgObj.err()); -} - -int ErrMsg::errmsgConcatErrCd(int errCode, const ErrMsg& errMsgObj, const char *format, ...) { - va_list args; - va_start(args, format); - errMsgObj.getLastErrCode(); - errmsgConcatCom(format, args, errMsgObj.err2Str(errMsgObj.getLastErrCode())); - va_end(args); - _lastErrCode = errCode; - return errCode; -} - -int ErrMsg::errmsgConcatErrCd(int errCode, const ErrMsg& errMsgObj) { - return errmsg(errCode, "%s", errMsgObj.err2Str(errMsgObj.getLastErrCode())); -} - -int ErrMsg::errmsgConcatErrCd(const ErrMsg& errMsgObj) { - return errmsg("%s", errMsgObj.err2Str(errMsgObj.getLastErrCode())); -} - -void ErrMsg::err_clear(){ - delete [] _err; - delete [] _formatErr; - _err = NULL; - _formatErr = NULL; -} - - diff --git a/mft_utils/errmsg.h b/mft_utils/errmsg.h deleted file mode 100644 index 0f08cad..0000000 --- a/mft_utils/errmsg.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#ifndef ERRMSG_H_ -#define ERRMSG_H_ - -#include -#include - -/** - * ErrMsg Class Provides API for returning both error codes and error messages to the user app. - */ - -class ErrMsg { -public: - ErrMsg(); - ErrMsg(std::map& errCodeMap); - - ~ErrMsg() { err_clear();} - - const char* err() const { return _err;} - void updateErrCodes(std::map& errCodeMap) {_errMap = errCodeMap; return;} - - const char* getFormatErr(const char *prefix, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 2, 3))) -#endif - ; - - void err_clear(); - - int getLastErrCode() const {return _lastErrCode;} - - const char* err2Str(int errCode) const; - -protected: - char* vprint(const char *format, va_list args); - - int errmsg(const char *format, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 2, 3))) -#endif - ; - - int errmsg(int errCode, const char *format, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 3, 4))) -#endif - ; - - int errmsg(int errCode); - - - int errmsgConcatMsg(int errCode, const ErrMsg& errMsgObj, const char *format, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 4, 5))) -#endif - ; - - int errmsgConcatMsg(const ErrMsg& errMsgObj, const char *format, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 3, 4))) -#endif - ; - - int errmsgConcatMsg(int errCode, const ErrMsg& errMsgObj); - - int errmsgConcatMsg(const ErrMsg& errMsgObj); - - - int errmsgConcatErrCd(int errCode, const ErrMsg& errMsgObj, const char *format, ...) -#ifdef __GNUC__ - __attribute__ ((format (printf, 4, 5))) -#endif - ; - - int errmsgConcatErrCd(int errCode, const ErrMsg& errMsgObj); - - int errmsgConcatErrCd(const ErrMsg& errMsgObj); - -private: - void errmsgConcatCom(const char* format, va_list args, const char* suffix); - - std::map _errMap; - char* _err; - char* _formatErr; - int _lastErrCode; -}; - -#endif /* ERRMSG_H_ */ diff --git a/mft_utils/mft_sig_handler.c b/mft_utils/mft_sig_handler.c deleted file mode 100644 index 6f5c47c..0000000 --- a/mft_utils/mft_sig_handler.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include - -#include - -static int s_is_fired = 0; -static char* s_interrupt_message = NULL; - -//siganls to handle -#ifdef __WIN__ - static int signals_array[] = - {SIGINT}; -#else - static int signals_array[] = {SIGINT, SIGQUIT, SIGTERM}; -#endif - -static void (*prev_handlers[sizeof(signals_array)/sizeof(signals_array[0])])(int sig); - - - -static void my_termination_handler(int sig) -{ - s_is_fired = sig; // assuming signals recieved are always different then zero - if (s_interrupt_message) { - fprintf(stderr, "%s", s_interrupt_message); - } -} - -#ifdef __WIN__ -static BOOL CtrlHandler( DWORD fdwCtrlType ) -{ - switch( fdwCtrlType ) - { - // Handle the CTRL-C signal. - case CTRL_C_EVENT: - // CTRL-CLOSE: confirm that the user wants to exit. - case CTRL_CLOSE_EVENT: - // Pass other signals to the next handler. - case CTRL_BREAK_EVENT: - case CTRL_LOGOFF_EVENT: - case CTRL_SHUTDOWN_EVENT: - my_termination_handler(SIGINT); - return TRUE; - - default: - return FALSE; - } - } -#endif - -int mft_signal_set_handling(int is_on) -{ - unsigned int i; - -#ifdef __WIN__ - SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, is_on ); -#endif - static int first_on = 0; - static int is_on_counter = 0; - - if (is_on_counter == 0 && is_on == 0) { - //if we reach here it means previous handler is already set so there is no need to restore it once more. - return 0; - } - // incr/decr counter - if (is_on) { - is_on_counter += 1; - }else { - is_on_counter = is_on_counter > 0 ? is_on_counter -1 : is_on_counter; - } - - if (is_on == 1 && first_on == 0) { - /* first time we turned thin handler on so we save previous handlers in prev_handlers array */ - for (i = 0; i < sizeof(signals_array)/sizeof(signals_array[0]); i++) - { - prev_handlers[i] = signal(signals_array[i], my_termination_handler); - if (prev_handlers[i] == SIG_ERR) { - return -1; - } - } - first_on = 1; - return 0; - } - /* not the first time we turned on the signals */ - /* register term/kill signal handler */ - /* we need to call signal routine only when is_on_counter == 0 or 1 (more precisely when it goes from zero to one or visa versa )*/ - if ((is_on_counter == 0 && is_on == 0) || (is_on_counter == 1 && is_on == 1 )) { - for (i = 0; i < sizeof(signals_array)/sizeof(signals_array[0]); i++) - { - if (signal(signals_array[i], is_on_counter > 0 ? my_termination_handler : prev_handlers[i]) == SIG_ERR) { - return -1; - } - } - } - - return 0; -} - -int mft_signal_is_fired() { - return s_is_fired; -} - -void mft_signal_set_fired(int is_fired) -{ - s_is_fired = is_fired; -} - -void mft_signal_set_msg(char* msg) -{ - s_interrupt_message = msg; -} - -void mft_restore_and_raise() -{ - int sig; - sig = mft_signal_is_fired(); - if (sig) { - // reset recieved signal - mft_signal_set_fired(0); - // retore prev handler - mft_signal_set_handling(0); - //raise signal to let the previous handle deal with it. - raise(sig); - } - mft_signal_set_handling(0); - return; -} diff --git a/mft_utils/mft_sig_handler.h b/mft_utils/mft_sig_handler.h deleted file mode 100644 index 5ae7f1a..0000000 --- a/mft_utils/mft_sig_handler.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef MFT_SIG_HANDLER -#define MFT_SIG_HANDLER - -#ifdef __cplusplus -extern "C" { -#endif - - -/** @file - * mft_sig_hanndler - Generic signal handling API - * Re place the default sig handlers for user interrupts with a - * 'thin' handler that sets a flag and prints message to user - * (to stderr), and returns. - * - * This allows application to place this handler in the main - * loop and do a propper exit with cleanup on signal. - * - * NOTE: mft_sig_handler saves on first call to - * mft_signal_set_handling(1), the current handlers - * and restores them each time we turn the thin handler off - * thus the main program should not change its default signal - * handlers after their initial initilization. - */ - -/** - * @brief Start/Stop the thin handler - * @param [in] is_on: 1 - enable thin handler. 0 - restore - * previous handlers - * @return 0 on success, 1 otherwise. - */ -int mft_signal_set_handling(int is_on); - -/** - * @brief signal accepted indication - * @return N - signal N was accepted. 0 otherwise... - */ -int mft_signal_is_fired(); - -/** - * @brief set value for signal accepted indication. - * Can be used to clear signal - * @param [in] is_fired - */ -void mft_signal_set_fired(int is_fired); - -/** - * @brief Set teh message to be printed on signal - * @param [in] msg - the mesage or NULL if no message is to be - * printed. - */ -void mft_signal_set_msg(char* msg); - -/** - * @brief Deal with signals, if got signal - raise, otherwise restore it - */ -void mft_restore_and_raise(); -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/mft_utils/mlarge_buffer.cpp b/mft_utils/mlarge_buffer.cpp deleted file mode 100644 index 1dde732..0000000 --- a/mft_utils/mlarge_buffer.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * - * mlarge_buffer.cpp - * - * Created on: Mar 9, 2016 - * Author: adrianc - */ - -#include - -#include "mlarge_buffer.h" - - -#define MFT_MIN(x,y) ((x) < (y) ? (x) : (y)) -#define MFT_MAX(x,y) ((x) > (y) ? (x) : (y)) - -#ifdef _DEBUG_MODE -#define DBG_PRINTF(...) fprintf(stderr, __VA_ARGS__) -#else -#define DBG_PRINTF(...) -#endif - -MBufferUnit& operator <<(MBufferUnit& a, MBufferUnit& b) -{ - if (!a.intersects(b) ) { - return a; - } - u_int32_t newSize = MFT_MAX(a.offset() + a.size(), b.offset() + b.size()) - MFT_MIN(a.offset(), b.offset()); - u_int32_t newOffset = MFT_MIN(a.offset(), b.offset()); - std::vector newData(newSize, 0); - - // merge b onto a - u_int32_t relativeOffsInBuffer = a.offset() - newOffset; - memcpy(&newData[0] + relativeOffsInBuffer, &(a.data()[0]), a.size()); - relativeOffsInBuffer = b.offset() - newOffset; - memcpy(&newData[0] + relativeOffsInBuffer, &(b.data()[0]), b.size()); - a = MBufferUnit(newData, newOffset); - return a; -} - -MBufferUnit& MBufferUnit::operator=(const MBufferUnit& other) -{ - if (this != &other) { - this->_data = other._data; - this->_offset = other._offset; - } - return *this; -} - -bool MBufferUnit::intersects( const MBufferUnit& other) const -{ - if (this->offset() > (other.offset() + other.size()) || (this->offset() + this->size()) < other.offset() ) { - return false; - } - return true; -} - -void MlargeBuffer::add(const std::vector& data, u_int32_t offset) -{ - if (data.size() == 0) { - return; - } - DBG_PRINTF("-D- adding chunk: 0x%08x - 0x%08x (0x%08x)\n", offset, (unsigned)data.size() + offset, (unsigned)data.size()); - // create MBufferUnit - MBufferUnit bufferUnit(data, offset); - bool unitInserted = false; - bool unitIntersects = false; - unsigned intersecIdx = 0; - unsigned bSize = _bData.size(); - for (unsigned idx = 0; idx < bSize; idx++) { - if (unitIntersects) { - if (_bData[idx].intersects(_bData[intersecIdx])) { - // merge element in intersecIdx onto it - _bData[idx] << _bData[intersecIdx]; - _bData.erase(_bData.begin() + intersecIdx); - intersecIdx = --idx; - bSize--; - } else { - break; // done :) - } - }else if (bufferUnit.offset() + bufferUnit.size() <_bData[idx].offset()) {// check if we can insert before - _bData.insert(_bData.begin() + idx, bufferUnit); - unitInserted = true; - break; - } else if (bufferUnit.intersects(_bData[idx])) { - unitIntersects = true; - unitInserted = true; - _bData[idx] << bufferUnit; - intersecIdx = idx; - continue; - } - } - - if (!unitInserted) { - _bData.push_back(bufferUnit); - } - DBG_PRINTF("-D- bData size: %d\n", (int)_bData.size()); - -#ifdef _DEBUG_MODE - std::vector::iterator it = _bData.begin(); - for (; it != _bData.end(); it++) { - DBG_PRINTF("-D- chunk : 0x%08x - 0x%08x (0x%08x)\n", it->offset(), it->size() + it->offset(), it->size()); - } -#endif -} -void MlargeBuffer::add(const u_int8_t* data, u_int32_t offset, u_int32_t size) -{ - std::vector dataVec(data, data+size); - return add(dataVec, offset); -} - -u_int8_t MlargeBuffer::operator[] (const u_int32_t offset) -{ - u_int8_t data; - get(&data, offset, 1); - return data; -} -void MlargeBuffer::get(std::vector& data, u_int32_t offset, u_int32_t size) -{ - data.resize(size); - return get(&data[0], offset, size); -} - -void MlargeBuffer::get(u_int8_t* data, u_int32_t offset, u_int32_t size) -{ - DBG_PRINTF("-D- get request on offset: 0x%08x with size 0x%x\n", offset, size); - if (!data || size == 0) { - return; - } - memset(data, _defaultValue, size); - u_int8_t* ptr = data; - for (std::vector::iterator it = _bData.begin(); it != _bData.end(); it++) { - if (offset < (it->offset() + it->size()) && (offset + size) > it->offset()) { - // intersects with current MBufferUnit - u_int32_t offsetInBuffer = ((long int)it->offset() - (long int)offset) < 0 ? 0 : it->offset() - offset; - u_int32_t copySize = MFT_MIN(offset + size, it->offset() + it->size()) - MFT_MAX(offset, it->offset()); - u_int32_t offsetInData = ((long int)offset - (long int)it->offset()) < 0 ? 0 : offset - it->offset(); - DBG_PRINTF("-D- getting from chunk at offset 0x%08x , size: 0x%x\n", it->offset(), (unsigned)it->size() ); - DBG_PRINTF("-D- integrating at buffer offset : 0x%08x size: 0x%x, offset in data: 0x%08x\n", offsetInBuffer, copySize, offsetInData); - memcpy(ptr + offsetInBuffer, &(it->data())[0] + offsetInData , copySize); - } - } - return; -} diff --git a/mft_utils/mlarge_buffer.h b/mft_utils/mlarge_buffer.h deleted file mode 100644 index 335a46b..0000000 --- a/mft_utils/mlarge_buffer.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * - * mlarge_buffer.h - * - * Created on: Mar 9, 2016 - * Author: adrianc - */ - -#ifndef USER_MFT_UTILS_MLARGE_BUFFER_H_ -#define USER_MFT_UTILS_MLARGE_BUFFER_H_ - -#include - -#include - -class MBufferUnit { -public: - MBufferUnit(const std::vector& data, u_int32_t offset) : _data(data), _offset(offset) {} - u_int32_t size() const {return (u_int32_t)_data.size();} - u_int32_t offset() const {return _offset;} - std::vector& data() { return _data; } - u_int8_t& operator[] (const u_int32_t idx) { return _data[idx]; } - MBufferUnit& operator=(const MBufferUnit& other); - bool intersects( const MBufferUnit& other) const; -private: - std::vector _data; - u_int32_t _offset; -}; - -MBufferUnit& operator<<(MBufferUnit& a, MBufferUnit& b); - -/* - * Large buffer with minimal memory footprint - */ -class MlargeBuffer { -public: - MlargeBuffer(u_int8_t defaultVal = 0x0) : _defaultValue(defaultVal){} - void add(const std::vector& data, u_int32_t offset); - void add(const u_int8_t* data, u_int32_t offset, u_int32_t size); - u_int8_t operator[] (const u_int32_t offset); // for read only - void get(std::vector& data, u_int32_t offset, u_int32_t size); - void get(std::vector& data, u_int32_t size) {return get(data, 0, size);} - void get(u_int8_t* data, u_int32_t offset, u_int32_t size); - void get(u_int8_t* data, u_int32_t size) {return get(data, 0, size);} -private: - u_int8_t _defaultValue; - std::vector _bData; -}; - -#endif /* USER_MFT_UTILS_MLARGE_BUFFER_H_ */ diff --git a/mlxconfig/Makefile.am b/mlxconfig/Makefile.am deleted file mode 100755 index c9189aa..0000000 --- a/mlxconfig/Makefile.am +++ /dev/null @@ -1,61 +0,0 @@ -#-- -# Copyright (c) 2004-2010 Mellanox Technologies LTD. All rights reserved. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -#-- - -# Makefile.am -- Process this file with automake to produce Makefile.in -USER_DIR = $(top_srcdir) -MTCR_DIR = $(top_srcdir)/mtcr_ul -COMMON_DIR = $(top_srcdir)/common -LAYOUTS_DIR = $(top_srcdir)/tools_layouts -UTILS_DIR = $(top_srcdir)/mft_utils -DEV_MGT_DIR = $(top_srcdir)/dev_mgt -LAYOUTS_LIB = $(LAYOUTS_DIR)/libtools_layouts.a -UTILS_LIB = $(USER_DIR)/mft_utils/libmftutils.a -CMDIF_DIR = $(USER_DIR)/cmdif - - -AM_CPPFLAGS = -I. -I$(USER_DIR) -I$(top_srcdir)/include/mtcr_ul -I$(MTCR_DIR) -I$(COMMON_DIR) $(WIN64_INC)\ - -I $(LAYOUTS_DIR) -I $(UTILS_DIR) -I$(DEV_MGT_DIR) -I$(CMDIF_DIR) - -AM_CXXFLAGS = -Wall -W -g -MP -MD -pipe -bin_PROGRAMS = mstconfig - -mstconfig_LDADD = $(CMDIF_DIR)/libcmdif.a ../reg_access/libreg_access.a $(LAYOUTS_LIB) $(MTCR_DIR)/libmtcr_ul.a $(MLNXOS_PPC_LIBS) $(LIBSTD_CPP) $(UTILS_LIB) $(DEV_MGT_DIR)/libdev_mgt.a -ldl - -mstconfig_SOURCES = mlxcfg_status.h mlxcfg_ui.h mlxcfg_ui.cpp\ - mlxcfg_parser.cpp\ - mlxcfg_lib.h mlxcfg_lib.cpp\ - mlxcfg_param_lib.h mlxcfg_param_lib.cpp - -#get mst device examples and tool name from makefile -AM_CXXFLAGS += -DMLXCFG_NAME=\"mstconfig\" -AM_CXXFLAGS += -DMST_DEV_EXAMPLE=\"04:00.0\" -DMST_DEV_EXAMPLE2=\"05:00.0\" - diff --git a/mlxconfig/mlxcfg_lib.cpp b/mlxconfig/mlxcfg_lib.cpp deleted file mode 100644 index eb1d02e..0000000 --- a/mlxconfig/mlxcfg_lib.cpp +++ /dev/null @@ -1,736 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -/* - * mlxcfg_lib.cpp - * - * Created on: Feb 17, 2014 - * Author: adrianc - */ - -#include -#include -#include - -#include -#include -#include -#include -#include "mlxcfg_lib.h" - -using namespace std; - -/* - * Mask and offsets for working with the capability vector - * retrieved via query_dev_cap command. - */ - -#define TOOL_CAP_BITS_ADDR 0xc0 - -#define CHECK_RC(rc)\ - if (rc) return rc; -/* - * MlxCfgOps implementation - */ - -MlxCfgOps::MlxCfgOps() -{ - // init the ErrMsg Class - std::map errmap; - errmap[MCE_SUCCESS] = "Success"; - errmap[MCE_FAILED] = "General Failure"; - errmap[MCE_TLV_NOT_FOUND] = "Configuration not found"; - errmap[MCE_TLV_NOT_SUPP] = "Configuration TLV not supported"; - errmap[MCE_NVCFG_NOT_SUPP] = "Fw does not support NV access registers"; - errmap[MCE_TOOLS_HCR_NOT_SUPP] = "Unsupported FW (version 2.31.5000 or above required for CX3/PRO)"; - errmap[MCE_DRIVER_DOWN] = "Cannot perform operation, Driver might be down."; - errmap[MCE_UNSUPPORTED_DEVICE] = "Device not supported."; - errmap[MCE_UNSUPPORTED_CFG] = "Fw does not support configuration"; - errmap[MCE_BAD_PARAMS] = "Bad parameters"; - errmap[MCE_BAD_PARAM_VAL] = "Bad parameter value"; - errmap[MCE_DEV_BUSY] = "Device busy"; - errmap[MCE_UNKNOWN_TLV] = "Unknown TLV"; - errmap[MCE_REG_NOT_SUPP] = "Fw does not support NV access registers"; - errmap[MCE_METHOD_NOT_SUPP] = "Method not supported"; - errmap[MCE_RES_NOT_AVAIL] = "Resource not available"; - errmap[MCE_CONF_CORRUPT] = "Configuration is corrupted"; - errmap[MCE_TLV_LEN_TOO_SMALL] = "TLV length too small"; - errmap[MCE_BAD_CONFIG] = "Bad Configuration"; - errmap[MCE_ERASE_EXEEDED] = "Erase exceeded flash spec"; - errmap[MCE_BAD_OP] = "Bad Operation"; - errmap[MCE_BAD_STATUS] = "General Failure"; - errmap[MCE_CR_ERROR] = "CR-Error"; - errmap[MCE_NOT_IMPLEMENTED] = "Not implemented"; - errmap[MCE_INCOMPLETE_PARAMS] = "Failed to get missing configuration from device, please specify all the needed parameters"; - errmap[MCE_OPEN_DEVICE] = "Failed to open device"; - errmap[MCE_PCI] = "Access to device should be through PCI interface only"; - errmap[MCE_GET_DEFAULT_PARAMS] = "Failed to get default params"; - errmap[MCE_UNKNOWN_ERR] = "General Error"; - - updateErrCodes(errmap); - _mf = NULL; - _deviceId = DeviceUnknown; - _suppVec = 0; - _isFifthGen = false; - return; -} - -MlxCfgOps::~MlxCfgOps() -{ - if (_mf) { - mclose(_mf); - } - for(map::iterator it = _cfgList.begin(); it != _cfgList.end(); it++) { - delete it->second; - } - return; -} - -#define HW_ID_ADDR 0xf0014 -#define CX3_HW_ID 501 -#define CX3_PRO_HW_ID 503 - -int MlxCfgOps::supportsToolsHCR() -{ - // we also update the support vector - u_int32_t devId; - u_int32_t type = 0; - int rc; - - if (mread4(_mf, HW_ID_ADDR, &devId) != 4) { - return MCE_CR_ERROR; - } - switch (devId & 0xffff) { // check hw device id - case CX3_HW_ID : //Cx3 - case CX3_PRO_HW_ID : // Cx3-pro - // check if device is accessed via pci (thats the only supported method atm) - rc = mget_mdevs_type(_mf, &type); - #ifndef MST_UL - if (type != MST_PCICONF && type != MST_PCI) { - return errmsg(MCE_PCI); - } - #else - if (type != MTCR_ACCESS_CONFIG && type != MTCR_ACCESS_MEMORY) { - return errmsg(MCE_PCI); - } - #endif - // check if we support tools_hcr - rc = tcif_query_dev_cap(_mf, TOOL_CAP_BITS_ADDR, &_suppVec); - switch (rc) { - case ME_OK: - return MCE_SUCCESS; - case ME_CMDIF_BAD_SYS: - return errmsg(MCE_DRIVER_DOWN); - case ME_CMDIF_BAD_OP: - case ME_CMDIF_TOUT: - case ME_CMDIF_BUSY: - return errmsg(MCE_TOOLS_HCR_NOT_SUPP); - default: - return errmsg("general Error, %s", m_err2str((MError)rc)); - } - break; - default: - break; - } - return errmsg(MCE_UNSUPPORTED_DEVICE); -} - -static void dealWithSignal() -{ - int sig; - sig = mft_signal_is_fired(); - if (sig) { - // reset recieved signal - mft_signal_set_fired(0); - // retore prev handler - mft_signal_set_handling(0); - //raise signal to let the previous handle deal with it. - raise(sig); - } - mft_signal_set_handling(0); - return; -} - -int MlxCfgOps::supportsNVData() -{ - struct tools_open_nvqc nvqcTlv; - memset(&nvqcTlv, 0, sizeof(struct tools_open_nvqc)); - MError rc; - // "suspend" signals as we are going to take semaphores - mft_signal_set_handling(1); - rc = reg_access_nvqc(_mf, REG_ACCESS_METHOD_GET, &nvqcTlv); - dealWithSignal(); - if (rc == ME_REG_ACCESS_BAD_PARAM || rc == ME_REG_ACCESS_INTERNAL_ERROR) { - return errmsg(MCE_NVCFG_NOT_SUPP); - } - return MCE_SUCCESS; -} - -int MlxCfgOps::isDefaultSupported(bool &defaultSupported) -{ - struct tools_open_nvqgc nvqgcTlv; - - if(!_isFifthGen){ - defaultSupported = true; - return ME_OK; - } - - memset(&nvqgcTlv, 0, sizeof(struct tools_open_nvqgc)); - MError rc; - - mft_signal_set_handling(1); - rc = reg_access_nvqgc(_mf, REG_ACCESS_METHOD_GET, &nvqgcTlv); - dealWithSignal(); - if (rc == ME_REG_ACCESS_BAD_PARAM || rc == ME_REG_ACCESS_INTERNAL_ERROR) { - defaultSupported = 0; - return ME_OK; - } else if(rc == ME_OK){ - defaultSupported = nvqgcTlv.read_factory_settings_support; - return ME_OK; - } - return rc; -} - -int MlxCfgOps::openComChk() -{ - bool rc; - int ret; - u_int32_t type = 0; - // check if we support Tools HCR and update _suppVec - if (_isFifthGen) { - rc = mget_mdevs_type(_mf, &type); - #ifndef MST_UL - if (type != MST_PCICONF && type != MST_PCI) { - return errmsg(MCE_PCI); - } - #else - if (type != MTCR_ACCESS_CONFIG && type != MTCR_ACCESS_MEMORY) { - return errmsg(MCE_PCI); - } - #endif - rc = supportsNVData(); CHECK_RC(rc); - } else { - rc = supportsToolsHCR(); CHECK_RC(rc); - } - - // update cfg specific info. - // TODO: adrianc: when getting defaults for 4th gen , perform queryDefParams only once and pass struct to classes to avoid calling multiple times - for (std::map::iterator paramIt = _cfgList.begin(); paramIt != _cfgList.end(); paramIt++) { - paramIt->second->setDevCapVec(_suppVec); - if (paramIt->second->cfgSupported(_mf)) { - ret = paramIt->second->getDefaultParams(_mf); - if (ret && ret!= MCE_GET_DEFAULT_PARAMS && ret != MCE_NOT_IMPLEMENTED) { - return ret; - } - } - } - return MCE_SUCCESS; -} - -int MlxCfgOps::open(const char* devStr, bool forceClearSem) -{ - _mf = mopen(devStr); - if (_mf == NULL) { - return errmsg(MCE_OPEN_DEVICE); - } - - return opend(_mf , forceClearSem); -} - -int MlxCfgOps::opend(mfile* mf, bool forceClearSem) -{ - u_int32_t hwDevId, hwRevId; - if (!mf) { - return errmsg(MCE_BAD_PARAMS); - } - _mf = mf; - - if( dm_get_device_id(mf, &_deviceId, &hwDevId, &hwRevId) ) { - return errmsg("Failed to identify device."); - } - // check if device is supported: - switch(_deviceId) { - case DeviceConnectX3: - case DeviceConnectX3Pro: - _isFifthGen = false; - break; - case DeviceConnectIB: - case DeviceConnectX4: - case DeviceConnectX4LX: - _isFifthGen = true; - break; - default: - return errmsg(MCE_UNSUPPORTED_DEVICE); - } - - if(dm_is_livefish_mode(mf)) { - return errmsg("Device in Livefish mode is not supported."); - } - - // init _cfgList, _param2TypeMap - if (_isFifthGen) { - // Wake On LAN - _cfgList[Mct_Wol] = new WolParams5thGen(); - _param2TypeMap[Mcp_Wol_Magic_En] = Mct_Wol; - // Vpi Settings - _cfgList[Mct_Vpi_P1] = new VpiParams5thGen(1); - _cfgList[Mct_Vpi_P2] = new VpiParams5thGen(2); - _param2TypeMap[Mcp_Link_Type_P1] = Mct_Vpi_P1; - _param2TypeMap[Mcp_Link_Type_P2] = Mct_Vpi_P2; - // PCI settings - _cfgList[Mct_Pci] = new PciParams5thGen(); - _param2TypeMap[Mcp_Sriov_En] = Mct_Pci; - _param2TypeMap[Mcp_Num_Of_Vfs] = Mct_Pci; - _param2TypeMap[Mcp_Fpp_En] = Mct_Pci; - _param2TypeMap[Mcp_PF_Log_Bar_Size] = Mct_Pci; - _param2TypeMap[Mcp_VF_Log_Bar_Size] = Mct_Pci; - _param2TypeMap[Mcp_Num_Pf_Msix] = Mct_Pci; - _param2TypeMap[Mcp_Num_Vf_Msix] = Mct_Pci; - // TPT settings - _cfgList[Mct_Tpt] = new TptParams5thGen(); - _param2TypeMap[Mcp_Log_Tpt_Size] = Mct_Tpt; - // Infiniband DC settings - _cfgList[Mct_Dc] = new IBDCParams5thGen(); - _param2TypeMap[Mcp_Log_Dcr_Hash_Table_Size] = Mct_Dc; - _param2TypeMap[Mcp_Dcr_Lifo_Size] = Mct_Dc; - // RoCE v1.5 next protocol - _cfgList[Mct_RoCE_Next_Protocol] = new RoCENextProtocolParams5thGen(); - _param2TypeMap[Mcp_RoCE_Next_Protocol] = Mct_RoCE_Next_Protocol; - // RoCE CC parameters - _cfgList[Mct_RoCE_CC_P1] = new RoCECCParams5thGen(1); - _cfgList[Mct_RoCE_CC_P2] = new RoCECCParams5thGen(2); - _param2TypeMap[Mcp_RoCE_CC_Algorithm_P1] = Mct_RoCE_CC_P1; - _param2TypeMap[Mcp_RoCE_CC_Prio_Mask_P1] = Mct_RoCE_CC_P1; - _param2TypeMap[Mcp_RoCE_CC_Algorithm_P2] = Mct_RoCE_CC_P2; - _param2TypeMap[Mcp_RoCE_CC_Prio_Mask_P2] = Mct_RoCE_CC_P2; - // RoCE CC ECN parameters - _cfgList[Mct_RoCE_CC_Ecn_P1] = new RoCECCEcnParams5thGen(1); - _cfgList[Mct_RoCE_CC_Ecn_P2] = new RoCECCEcnParams5thGen(2); - _param2TypeMap[Mcp_Clamp_Tgt_Rate_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Clamp_Tgt_Rate_After_Time_Inc_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Time_Reset_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Byte_Reset_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Threshold_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Max_Rate_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Ai_Rate_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Hai_Rate_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Gd_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Min_Dec_Fac_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rpg_Min_Rate_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rate_To_Set_On_First_Cnp_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Dce_Tcp_G_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Dce_Tcp_Rtt_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Rate_Reduce_Monitor_Period_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Initial_Alpha_Value_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Min_Time_Between_Cnps_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Cnp_Dscp_P1] = Mct_RoCE_CC_Ecn_P1; - _param2TypeMap[Mcp_Cnp_802p_Prio_P1] = Mct_RoCE_CC_Ecn_P1; - - _param2TypeMap[Mcp_Clamp_Tgt_Rate_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Clamp_Tgt_Rate_After_Time_Inc_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Time_Reset_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Byte_Reset_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Threshold_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Max_Rate_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Ai_Rate_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Hai_Rate_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Gd_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Min_Dec_Fac_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rpg_Min_Rate_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rate_To_Set_On_First_Cnp_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Dce_Tcp_G_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Dce_Tcp_Rtt_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Rate_Reduce_Monitor_Period_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Initial_Alpha_Value_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Min_Time_Between_Cnps_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Cnp_Dscp_P2] = Mct_RoCE_CC_Ecn_P2; - _param2TypeMap[Mcp_Cnp_802p_Prio_P2] = Mct_RoCE_CC_Ecn_P2; - - _cfgList[Mct_External_Port] = new ExternalPort5thGen(); - _param2TypeMap[Mcp_Port_Owner] = Mct_External_Port; - _param2TypeMap[Mcp_Allow_Rd_Counters] = Mct_External_Port; - - _cfgList[Mct_Boot_Settings_Extras_5thGen] = new BootSettingsExtParams5thGen(); - _param2TypeMap[Mcp_Boot_Settings_Ext_IP_Ver] = Mct_Boot_Settings_Extras_5thGen; - - _cfgList[Mct_QoS_P1] = new QoS(1); - _cfgList[Mct_QoS_P2] = new QoS(2); - _param2TypeMap[Mcp_QoS_Num_of_TC_P1] = Mct_QoS_P1; - _param2TypeMap[Mcp_QoS_Num_of_VL_P1] = Mct_QoS_P1; - _param2TypeMap[Mcp_QoS_Num_of_TC_P2] = Mct_QoS_P2; - _param2TypeMap[Mcp_QoS_Num_of_VL_P2] = Mct_QoS_P2; - - _cfgList[Mct_LLDP_Client_Settings_P1] = new LLDPClientSettings(1); - _cfgList[Mct_LLDP_Client_Settings_P2] = new LLDPClientSettings(2); - _param2TypeMap[Mcp_LLDP_NB_RX_Mode_P1] = Mct_LLDP_Client_Settings_P1; - _param2TypeMap[Mcp_LLDP_NB_TX_Mode_P1] = Mct_LLDP_Client_Settings_P1; - _param2TypeMap[Mcp_LLDP_NB_DCBX_P1] = Mct_LLDP_Client_Settings_P1; - _param2TypeMap[Mcp_LLDP_NB_RX_Mode_P2] = Mct_LLDP_Client_Settings_P2; - _param2TypeMap[Mcp_LLDP_NB_TX_Mode_P2] = Mct_LLDP_Client_Settings_P2; - _param2TypeMap[Mcp_LLDP_NB_DCBX_P2] = Mct_LLDP_Client_Settings_P2; - - _cfgList[Mct_DCBX_P1] = new DCBX(1); - _cfgList[Mct_DCBX_P2] = new DCBX(2); - _param2TypeMap[Mcp_DCBX_IEEE_EN_P1] = Mct_DCBX_P1; - _param2TypeMap[Mcp_DCBX_CEE_EN_P1] = Mct_DCBX_P1; - _param2TypeMap[Mcp_DCBX_WILLING_P1] = Mct_DCBX_P1; - _param2TypeMap[Mcp_DCBX_IEEE_EN_P2] = Mct_DCBX_P2; - _param2TypeMap[Mcp_DCBX_CEE_EN_P2] = Mct_DCBX_P2; - _param2TypeMap[Mcp_DCBX_WILLING_P2] = Mct_DCBX_P2; - - } else { - // SR-IOV - _cfgList[Mct_Sriov] = new SriovParams4thGen(); - _param2TypeMap[Mcp_Sriov_En] = Mct_Sriov; - _param2TypeMap[Mcp_Num_Of_Vfs] = Mct_Sriov; - // Wake on LAN - _cfgList[Mct_Wol_P1] = new WolParams4thGen(1); - _cfgList[Mct_Wol_P2] = new WolParams4thGen(2); - _param2TypeMap[Mcp_Wol_Magic_En_P1] = Mct_Wol_P1; - _param2TypeMap[Mcp_Wol_Magic_En_P2] = Mct_Wol_P2; - // Vpi Settings - _cfgList[Mct_Vpi_P1] = new VpiParams4thGen(1); - _cfgList[Mct_Vpi_P2] = new VpiParams4thGen(2); - _param2TypeMap[Mcp_Link_Type_P1] = Mct_Vpi_P1; - _param2TypeMap[Mcp_Link_Type_P2] = Mct_Vpi_P2; - // BAR size - _cfgList[Mct_Bar_Size] = new BarSzParams4thGen(); - _param2TypeMap[Mcp_Log_Bar_Size] = Mct_Bar_Size; - // Infiniband Boot Settings - _cfgList[Mct_Boot_Settings_P1] = new InfinibandBootSettingsParams4thGen(1); - _cfgList[Mct_Boot_Settings_P2] = new InfinibandBootSettingsParams4thGen(2); - _param2TypeMap[Mcp_Boot_Pkey_P1] = Mct_Boot_Settings_P1; - _param2TypeMap[Mcp_Boot_Pkey_P2] = Mct_Boot_Settings_P2; - // Preboot Boot Settings - _cfgList[Mct_Preboot_Boot_Settings_P1] = new PrebootBootSettingsParams4thGen(1); - _cfgList[Mct_Preboot_Boot_Settings_P2] = new PrebootBootSettingsParams4thGen(2); - _param2TypeMap[Mcp_Boot_Option_Rom_En_P1] = Mct_Preboot_Boot_Settings_P1; - _param2TypeMap[Mcp_Boot_Vlan_En_P1] = Mct_Preboot_Boot_Settings_P1; - _param2TypeMap[Mcp_Boot_Retry_Cnt_P1] = Mct_Preboot_Boot_Settings_P1; - _param2TypeMap[Mcp_Legacy_Boot_Protocol_P1] = Mct_Preboot_Boot_Settings_P1; - _param2TypeMap[Mcp_Boot_Vlan_P1] = Mct_Preboot_Boot_Settings_P1; - - _param2TypeMap[Mcp_Boot_Option_Rom_En_P2] = Mct_Preboot_Boot_Settings_P2; - _param2TypeMap[Mcp_Boot_Vlan_En_P2] = Mct_Preboot_Boot_Settings_P2; - _param2TypeMap[Mcp_Boot_Retry_Cnt_P2] = Mct_Preboot_Boot_Settings_P2; - _param2TypeMap[Mcp_Legacy_Boot_Protocol_P2] = Mct_Preboot_Boot_Settings_P2; - _param2TypeMap[Mcp_Boot_Vlan_P2] = Mct_Preboot_Boot_Settings_P2; - - _cfgList[Mct_Boot_Settings_Extras_4thGen_P1] = new BootSettingsExtParams4thGen(1); - _cfgList[Mct_Boot_Settings_Extras_4thGen_P2] = new BootSettingsExtParams4thGen(2); - _param2TypeMap[Mcp_Boot_Settings_Ext_IP_Ver_P1] = Mct_Boot_Settings_Extras_4thGen_P1; - _param2TypeMap[Mcp_Boot_Settings_Ext_IP_Ver_P2] = Mct_Boot_Settings_Extras_4thGen_P2; - } - - - if (forceClearSem) { - int rc; - rc = _isFifthGen ? icmd_clear_semaphore(mf) : tools_cmdif_unlock_semaphore(_mf); - if (rc) { - return errmsg("Failed to unlock semaphore, %s.", m_err2str((MError)rc)); - } - } - return openComChk(); -} - -bool MlxCfgOps::supportsCfg(mlxCfgType cfg) -{ - if (!isLegal(cfg)) { - return false; - } - return _cfgList[cfg]->cfgSupported(_mf); -} - -bool MlxCfgOps::supportsParam(mlxCfgParam param) -{ - if (!isLegal(param)) { - return false; - } - - if (!isLegal(cfgParam2Type(param))) { - return false; - } - - return _cfgList[cfgParam2Type(param)]->cfgSupported(_mf, param); -} - -int MlxCfgOps::getCfg(mlxCfgParam cfgParam, u_int32_t& val, bool getDefault) -{ - if (!isLegal(cfgParam)) { - return MCE_BAD_PARAMS; - } - - if (!supportsParam(cfgParam)) { - return errmsg(MCE_UNSUPPORTED_CFG); - } - - if (getDefault) { - val = (_cfgList[cfgParam2Type(cfgParam)])->getDefaultParam(cfgParam); - } else { - int rc; - rc = _cfgList[cfgParam2Type(cfgParam)]->getFromDev(_mf); - if (rc) { - return errmsgConcatMsg(rc,*_cfgList[cfgParam2Type(cfgParam)]); - } - val = (_cfgList[cfgParam2Type(cfgParam)])->getParam(cfgParam); - } - return MCE_SUCCESS; -} - -int MlxCfgOps::getCfg(std::vector& infoVec) -{ - for (std::vector::iterator it = infoVec.begin() ; it != infoVec.end(); it++) { - int rc = getCfg(it->first,it->second); - if (rc) { - return rc; - } - } - return MCE_SUCCESS; -} - -int MlxCfgOps::setCfg(mlxCfgParam cfgParam, u_int32_t val) -{ - if (!isLegal(cfgParam)) { - return MCE_BAD_PARAMS; - } - - if (!supportsParam(cfgParam)) { - return errmsg(MCE_UNSUPPORTED_CFG); - } - - // get parameters from device if present - int rc = _cfgList[cfgParam2Type(cfgParam)]->getFromDev(_mf); - if (rc) { - return errmsgConcatMsg(rc, *_cfgList[cfgParam2Type(cfgParam)]); - } - _cfgList[cfgParam2Type(cfgParam)]->setParam(cfgParam, val); - rc = _cfgList[cfgParam2Type(cfgParam)]->setOnDev(_mf); - if (rc) { - return errmsgConcatMsg(rc, *_cfgList[cfgParam2Type(cfgParam)]); - } - return MCE_SUCCESS; -} - -int MlxCfgOps::setCfg(const std::vector& infoVec, mlxCfgParam& failedParam) -{ - // set params - std::set CfgToSet; - int rc; - - for (std::vector::const_iterator it = infoVec.begin() ; it != infoVec.end(); it++) { - if (!isLegal(it->first)) { - return MCE_BAD_PARAMS; - } - if (!supportsParam(it->first)) { - failedParam = it->first; - return errmsg(MCE_UNSUPPORTED_CFG); - } - // get configuration from device first (if preset) in case of multiple params per type - rc = _cfgList[cfgParam2Type(it->first)]->getFromDev(_mf); - if (rc) { - return errmsgConcatMsg(rc, *_cfgList[cfgParam2Type(it->first)]); - } - _cfgList[cfgParam2Type(it->first)]->setParam(it->first, it->second); - CfgToSet.insert(_cfgList[cfgParam2Type(it->first)]); - } - //set on device exit on first failure - for (std::set::iterator it = CfgToSet.begin() ; it != CfgToSet.end(); it++) { - rc = (*it)->setOnDev(_mf); - if (rc) { - return errmsgConcatMsg(rc, (**it)); - } - } - return MCE_SUCCESS; -} - -void MlxCfgOps::setIgnoreSoftLimits(bool val) -{ - for(std::map::iterator it = _cfgList.begin(); it != _cfgList.end(); it++) { - it->second->setIgnoreSoftLimits(val); - } - return; -} - -void MlxCfgOps::setIgnoreHardLimits(bool val) -{ - for(std::map::iterator it = _cfgList.begin(); it != _cfgList.end(); it++) { - it->second->setIgnoreHardLimits(val); - } - return; -} - -int MlxCfgOps::invalidateCfgs4thGen() -{ - struct tools_open_mnvia mnviaTlv; - u_int8_t buffer[TOOLS_OPEN_MNVIA_SIZE] = {0}; - int rc; - memset(&mnviaTlv, 0, sizeof(struct tools_open_mnvia)); - tools_open_mnvia_pack(&mnviaTlv, buffer); - mft_signal_set_handling(1); - rc = reg_access_mnvia(_mf, REG_ACCESS_METHOD_SET, &mnviaTlv); - dealWithSignal(); - return rc; -} - -int MlxCfgOps::invalidateCfgs5thGen() -{ - struct tools_open_nvia nviaTlv; - u_int8_t buffer[TOOLS_OPEN_NVIA_SIZE] = {0}; - int rc; - memset(&nviaTlv, 0, sizeof(struct tools_open_nvia)); - tools_open_nvia_pack(&nviaTlv, buffer); - mft_signal_set_handling(1); - rc = reg_access_nvia(_mf, REG_ACCESS_METHOD_SET, &nviaTlv); - dealWithSignal(); - return rc; -} - -int MlxCfgOps::invalidateCfgs() -{ - int rc; - if (_isFifthGen) { - rc = invalidateCfgs5thGen(); - } else { - rc = invalidateCfgs4thGen(); - } - if (rc) { - return errmsg("failed to invalidate configurations, %s.", m_err2str((MError)rc)); - } - return MCE_SUCCESS; -} - -int MlxCfgOps::backupCfgs(vector< pair< u_int32_t, vector > >& cfgsMap) -{ - int rc; - int status = 0; - u_int32_t ptr = 0; - struct tools_open_mnvgn mnvgnTlv; - do { - memset(&mnvgnTlv, 0, sizeof(struct tools_open_mnvgn)); - mnvgnTlv.nv_pointer = ptr; - mft_signal_set_handling(1); - rc = reg_access_mnvgn(_mf, REG_ACCESS_METHOD_GET, &mnvgnTlv, &status); - dealWithSignal(); - if (rc) { - if(status == ME_NOT_IMPLEMENTED) { - return errmsg("Firmware does not support backup command"); - } - return errmsg("failed to backup configurations, %s.", m_err2str((MError)rc)); - } - ptr = mnvgnTlv.nv_pointer; - if (ptr != 0) { - u_int32_t k = mnvgnTlv.nv_hdr.type.tlv_type_dw.tlv_type_dw; - vector v; - v.resize(TOOLS_OPEN_NV_HDR_FIFTH_GEN_SIZE + mnvgnTlv.nv_hdr.length); - //Copy header: - tools_open_nv_hdr_fifth_gen_pack(&mnvgnTlv.nv_hdr, v.data()); - //Copy data: - memcpy(v.data() + TOOLS_OPEN_NV_HDR_FIFTH_GEN_SIZE, - &mnvgnTlv.nv_data, - mnvgnTlv.nv_hdr.length); - cfgsMap.push_back(make_pair(k, v)); - } - } while (ptr != 0); - - return rc; -} - -bool MlxCfgOps::isLegal(mlxCfgType cfg) -{ - if (_cfgList.find(cfg) != _cfgList.end()) { - return true; - } - errmsg("illegal configuration"); - return false; -} - -bool MlxCfgOps::isLegal(mlxCfgParam cfg) -{ - if (cfg >= Mcp_Sriov_En && cfg < Mcp_Last) { - return true; - } - errmsg("illegal configuration parameter"); - return false; -} - - -const char* MlxCfgOps::loadConfigurationGetStr() -{ - int rc; - struct cibfw_register_mfrl mfrl; - memset(&mfrl, 0, sizeof(mfrl)); - if (_isFifthGen && (_deviceId == DeviceConnectX4 || _deviceId == DeviceConnectX4LX)) { - // send warm boot (bit 6) - mfrl.reset_level = 1 << 6; - mft_signal_set_handling(1); - rc = reg_access_mfrl(_mf,REG_ACCESS_METHOD_SET, &mfrl); - dealWithSignal(); - if (rc) { - return "Please power cycle machine to load new configurations."; - } - } - return "Please reboot machine to load new configurations."; -} - - -mlxCfgType MlxCfgOps::cfgParam2Type(mlxCfgParam param) -{ - if (_param2TypeMap.find(param) == _param2TypeMap.end()) { - return Mct_Last; - } - return _param2TypeMap[param]; -} - -int MlxCfgOps::setRawCfg(std::vector rawTlvVec) -{ - if (!_isFifthGen) { - return errmsg("Setting Raw Configuration is supported for " FIFTH_GENERATION_LIST " devices only."); - } - RawCfgParams5thGen rawTlv; - if (rawTlv.setRawData(rawTlvVec)) { - return errmsg("%s", rawTlv.err()); - } - - if (rawTlv.setOnDev(_mf)) { - return errmsg("%s", rawTlv.err()); - } - return MCE_SUCCESS; -} - -int MlxCfgOps::dumpRawCfg(std::vector rawTlvVec, std::string& tlvDump) -{ - RawCfgParams5thGen rawTlv; - if (rawTlv.setRawData(rawTlvVec)) { - return errmsg("%s", rawTlv.err()); - } - tlvDump = rawTlv.dumpTlv(); - return MCE_SUCCESS; -} diff --git a/mlxconfig/mlxcfg_lib.h b/mlxconfig/mlxcfg_lib.h deleted file mode 100644 index 169a1c8..0000000 --- a/mlxconfig/mlxcfg_lib.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -/* - * mlxcfg_lib.h - * - * Created on: Feb 17, 2014 - * Author: adrianc - */ - -#ifndef MLXCFG_LIB_H_ -#define MLXCFG_LIB_H_ - -#include -#include - -#include -#include -#include - -#include "mlxcfg_status.h" -#include "mlxcfg_param_lib.h" - -#define FIFTH_GENERATION_LIST "Connect-IB/Connect-X4/LX" -#define FOURTH_GENERATION_LIST "ConnectX3/Pro" - -class MlxCfgOps : public ErrMsg { -public: - MlxCfgOps(); - ~MlxCfgOps(); - int open(const char* devStr, bool forceClearSem=false); - int opend(mfile* mf, bool forceClearSem=false); - - // no need to close , this is done in destructor - - bool supportsCfg(mlxCfgType cfg); - bool supportsParam(mlxCfgParam param); - - int getCfg(mlxCfgParam cfgParam, u_int32_t& val, bool getDefault = false); - int getCfg(std::vector& infoVec); - - int setCfg(mlxCfgParam cfgParam, u_int32_t val); - int setCfg(const std::vector& infoVec, mlxCfgParam& cfgParam); - - int setRawCfg(std::vector rawTlvVec); - - int dumpRawCfg(std::vector rawTlvVec, std::string& tlvDump); - - int invalidateCfgs(); - - // Set/Un-Set ignore limits for all configurations - void setIgnoreSoftLimits(bool val); - void setIgnoreHardLimits(bool val); - - // Set/Un-Set Ignore limits per configuration - // Adrianc: TBD - - const char* loadConfigurationGetStr(); - - int isDefaultSupported(bool &defaultSupported); - - int backupCfgs(std::vector > >& cfgs); - -private: - int openComChk(); - int supportsToolsHCR(); - int supportsNVData(); - bool isLegal(mlxCfgType cfg); - bool isLegal(mlxCfgParam cfg); - - int invalidateCfgs4thGen(); - int invalidateCfgs5thGen(); - - mlxCfgType cfgParam2Type(mlxCfgParam param); - std::map _cfgList; // needs to be initialized in constructor and freed in destructor, will contain all the tools supported cfgs - std::map _param2TypeMap; - dm_dev_id_t _deviceId; - mfile* _mf; - u_int64_t _suppVec; - bool _isFifthGen; -}; - - - -#endif /* MLXCFG_LIB_H_ */ diff --git a/mlxconfig/mlxcfg_param_lib.cpp b/mlxconfig/mlxcfg_param_lib.cpp deleted file mode 100644 index 1028e67..0000000 --- a/mlxconfig/mlxcfg_param_lib.cpp +++ /dev/null @@ -1,4283 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -/* - * mlxcfg_param_lib.cpp - * - * Created on: Mar 22, 2015 - * Author: adrianc - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "mlxcfg_param_lib.h" -#include "mlxcfg_status.h" - -enum { - SRIOV_MASK = 0x1, - WOL_P1_MASK = 0x2, - WOL_P2_MASK = 0x4 , - VPI_P1_MASK = 0x8, - VPI_P2_MASK = 0x10, - BAR_SZ_MASK = 0x20 -}; - -// tlv classes: -enum { - CLASS_GLOBAL = 0x0, - CLASS_PHYS_PORT = 0x1, - CLASS_BMC = 0x2, - CLASS_PER_HOST = 0x3, - CLASS_ESWITCH = 0x4 -}; - -#define MAX_VFS_ADDR 0x38 -#define MAX_BAR_SZ_ADDR 0xc8 -#define DEFAULT_BAR_SZ_ADDR 0x48 - - -/* - * Debug print MACRO of the NV Tlvs: - */ -//#define _ENABLE_DEBUG_ -#ifdef _ENABLE_DEBUG_ -# define DEBUG_PRINT_SEND(data_struct, struct_name)\ - printf("-I- Data Sent:\n");\ - tools_open_##struct_name##_print(data_struct, stdout, 1) -# define DEBUG_PRINT_RECIEVE(data_struct, struct_name)\ - printf("-I- Data Received:\n");\ - tools_open_##struct_name##_print(data_struct, stdout, 1) -#else -# define DEBUG_PRINT_SEND(data_struct, struct_name) -# define DEBUG_PRINT_RECIEVE(data_struct, struct_name) -#endif - -#define CHECK_RC(rc)\ - if (rc) return rc; - -/* - * Macros for getting and settings a TLV - */ -// TODO: adrianc: add macro for nvqc tlv and use it in cfgSupported for 5th gen Tlvs - -/* - * Macros Below rely on the fact that the user has implemented within the parameter class: - * void updateClassAttrFromTlv(void*); - * void updateTLVFromClassAttr(void*); - * - * those method do what they imply: update the class internal memeber from TLV and via versa. - */ - -#define SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tlvStructName, tlvNameStr) \ - MError __mRc;\ - if (!(ignoreCheck) && !checkCfg()) {\ - return MCE_BAD_PARAMS;\ - }\ - int __tlvBuffSize = tlvStructName##_size();\ - u_int8_t __tlvBuff[__tlvBuffSize];\ - memset(__tlvBuff, 0, __tlvBuffSize);\ - struct tlvStructName __tlvStruct;\ - memset(&__tlvStruct, 0, sizeof(__tlvStruct));\ - __mRc = mnvaCom5thGen(mf, __tlvBuff, __tlvBuffSize, getTlvTypeBe(), REG_ACCESS_METHOD_GET);\ - if (__mRc && __mRc != ME_REG_ACCESS_RES_NOT_AVLBL) {\ - return errmsg("failed to set %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - tlvStructName##_unpack(&__tlvStruct, __tlvBuff);\ - updateTlvFromClassAttr((void*)&__tlvStruct);\ - tlvStructName##_pack(&__tlvStruct, __tlvBuff);\ - __mRc = mnvaCom5thGen(mf, __tlvBuff, __tlvBuffSize, getTlvTypeBe(), REG_ACCESS_METHOD_SET);\ - if (__mRc) {\ - return errmsg("failed to set %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - _updated = false;\ - return MCE_SUCCESS - -#define GET_DEFAULT_5TH_GEN(mf, tlvStructName, tlvNameStr) \ - MError __mRc;\ - int __tlvBuffSize = tlvStructName##_size();\ - u_int8_t __tlvBuff[__tlvBuffSize];\ - memset(__tlvBuff, 0, __tlvBuffSize);\ - struct tlvStructName __tlvStruct;\ - memset(&__tlvStruct, 0, sizeof(__tlvStruct));\ - __mRc = mnvaCom5thGen(mf, &__tlvBuff[0], __tlvBuffSize, getTlvTypeBe(), REG_ACCESS_METHOD_GET, true);\ - if (__mRc) {\ - if (__mRc == ME_REG_ACCESS_RES_NOT_AVLBL) {\ - return MCE_SUCCESS;\ - }\ - return errmsg("Failed to get %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - tlvStructName##_unpack(&__tlvStruct, &__tlvBuff[0]);\ - updateClassDefaultAttrFromTlv((void*)&__tlvStruct);\ - updateClassAttrFromDefaultParams();\ - return MCE_SUCCESS - -#define GET_FROM_DEV_5TH_GEN(mf, tlvStructName, tlvNameStr) \ - MError __mRc;\ - int __tlvBuffSize = tlvStructName##_size();\ - u_int8_t __tlvBuff[__tlvBuffSize];\ - memset(__tlvBuff, 0, __tlvBuffSize);\ - struct tlvStructName __tlvStruct;\ - memset(&__tlvStruct, 0, sizeof(__tlvStruct));\ - if (_updated) {\ - return MCE_SUCCESS;\ - }\ - __mRc = mnvaCom5thGen(mf, &__tlvBuff[0], __tlvBuffSize, getTlvTypeBe(), REG_ACCESS_METHOD_GET);\ - if (__mRc) {\ - if (__mRc == ME_REG_ACCESS_RES_NOT_AVLBL) {\ - return MCE_SUCCESS;\ - }\ - return errmsg("Failed to get %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - tlvStructName##_unpack(&__tlvStruct, &__tlvBuff[0]);\ - updateClassAttrFromTlv((void*)&__tlvStruct);\ - _updated = true;\ - return MCE_SUCCESS - -#define SET_ON_DEV_4TH_GEN(mf, ignoreCheck, tlvStructName, tlvNameStr, typeMod) \ - MError __mRc;\ - if (!(ignoreCheck) && !checkCfg()) {\ - return MCE_BAD_PARAMS;\ - }\ - int __tlvBuffSize = tlvStructName##_size();\ - u_int8_t __tlvBuff[__tlvBuffSize];\ - memset(__tlvBuff, 0, __tlvBuffSize);\ - struct tlvStructName __tlvStruct;\ - memset(&__tlvStruct, 0, sizeof(__tlvStruct));\ - __mRc = mnvaCom4thGen(mf, __tlvBuff, __tlvBuffSize, tlvTypeIdx, REG_ACCESS_METHOD_GET, typeMod);\ - if (__mRc && __mRc != ME_REG_ACCESS_RES_NOT_AVLBL) {\ - return errmsg("failed to set %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - tlvStructName##_unpack(&__tlvStruct, __tlvBuff);\ - updateTlvFromClassAttr((void*)&__tlvStruct);\ - tlvStructName##_pack(&__tlvStruct, __tlvBuff);\ - __mRc = mnvaCom4thGen(mf, __tlvBuff, __tlvBuffSize, tlvTypeIdx, REG_ACCESS_METHOD_SET, typeMod);\ - if (__mRc) {\ - return errmsg("failed to set %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - _updated = false;\ - return MCE_SUCCESS - -#define GET_FROM_DEV_4TH_GEN(mf, tlvStructName, tlvNameStr, typeMod) \ - MError __mRc;\ - int __tlvBuffSize = tlvStructName##_size();\ - u_int8_t __tlvBuff[__tlvBuffSize];\ - memset(__tlvBuff, 0, __tlvBuffSize);\ - struct tlvStructName __tlvStruct;\ - memset(&__tlvStruct, 0, sizeof(__tlvStruct));\ - if (_updated) {\ - return MCE_SUCCESS;\ - }\ - __mRc = mnvaCom4thGen(mf, &__tlvBuff[0], __tlvBuffSize, tlvTypeIdx, REG_ACCESS_METHOD_GET, typeMod);\ - if (__mRc) {\ - if (__mRc == ME_REG_ACCESS_RES_NOT_AVLBL) {\ - return MCE_SUCCESS;\ - }\ - return errmsg("Failed to get %s settings: %s", tlvNameStr, m_err2str(__mRc));\ - }\ - tlvStructName##_unpack(&__tlvStruct, &__tlvBuff[0]);\ - updateClassAttrFromTlv((void*)&__tlvStruct);\ - _updated = true;\ - return MCE_SUCCESS - - -static void dealWithSignal() -{ - int sig; - sig = mft_signal_is_fired(); - if (sig) { - // reset recieved signal - mft_signal_set_fired(0); - // retore prev handler - mft_signal_set_handling(0); - //raise signal to let the previous handle deal with it. - raise(sig); - } - mft_signal_set_handling(0); - return; -} - -/* - * Adrianc: TODO: create a SetTlv class and two child classess , for 4th/5th gen. - * each param class will have an instance of SetTlv class - */ - -MError mnvaCom4thGen(mfile* mf, u_int8_t* buff, u_int16_t len, u_int16_t tlvTypeIdx, reg_access_method_t method, u_int16_t typeMod) -{ - struct tools_open_mnva mnvaTlv; - memset(&mnvaTlv, 0, sizeof(struct tools_open_mnva)); - - mnvaTlv.nv_hdr.length = len >> 2; // length is in dwords - mnvaTlv.nv_hdr.type = tlvTypeIdx; - mnvaTlv.nv_hdr.type_mod = typeMod; - memcpy(mnvaTlv.data, buff, len); - MError rc; - // "suspend" signals as we are going to take semaphores - mft_signal_set_handling(1); - rc = reg_access_mnva(mf, method, &mnvaTlv); - dealWithSignal(); - if (rc) { - return rc; - } - memcpy(buff, mnvaTlv.data, len); - return ME_OK; -} - -MError mnvaCom5thGen(mfile* mf, u_int8_t* buff, u_int16_t len, u_int32_t tlvType, reg_access_method_t method, bool getDefault=false) -{ - struct tools_open_nvda mnvaTlv; - memset(&mnvaTlv, 0, sizeof(struct tools_open_nvda)); - - mnvaTlv.nv_hdr.length = len; - mnvaTlv.nv_hdr.rd_en = 0; - mnvaTlv.nv_hdr.over_en = 1; - if (getDefault) { - mnvaTlv.nv_hdr.default_ = 1; - } - // tlvType should be in the correct endianess - mnvaTlv.nv_hdr.type.tlv_type_dw.tlv_type_dw = __be32_to_cpu(tlvType); - memcpy(mnvaTlv.data, buff, len); - MError rc; - // "suspend" signals as we are going to take semaphores - mft_signal_set_handling(1); - DEBUG_PRINT_SEND(&mnvaTlv, nvda); - rc = reg_access_nvda(mf, method, &mnvaTlv); - DEBUG_PRINT_RECIEVE(&mnvaTlv, nvda); - dealWithSignal(); - if (rc) { - return rc; - } - memcpy(buff, mnvaTlv.data, len); - return ME_OK; -} - -MError nvqcCom5thGen(mfile* mf, u_int32_t tlvType, bool& suppRead, bool& suppWrite) -{ - struct tools_open_nvqc nvqcTlv; - memset(&nvqcTlv, 0, sizeof(struct tools_open_nvqc)); - - // tlvType should be in the correct endianess - nvqcTlv.type.tlv_type_dw.tlv_type_dw = __be32_to_cpu(tlvType); - MError rc; - // "suspend" signals as we are going to take semaphores - mft_signal_set_handling(1); - rc = reg_access_nvqc(mf, REG_ACCESS_METHOD_GET, &nvqcTlv); - dealWithSignal(); - if (rc) { - return rc; - } - suppRead = nvqcTlv.support_rd; - suppWrite = nvqcTlv.support_wr; - return ME_OK; -} - -/*************************** - * Class implementations : - ***************************/ - -/* - * RawCfgParams5thGen Class implementation - */ -RawCfgParams5thGen::RawCfgParams5thGen() { - memset(&_nvdaTlv, 0, sizeof(struct tools_open_nvda)); -} - -int RawCfgParams5thGen::setRawData(const std::vector& tlvBuff) { - if(tlvBuff.size() * 4 > TOOLS_OPEN_NVDA_SIZE){ - return errmsg(MCE_BAD_PARAM_VAL, "TLV size exceeds maximal limit. Maximum size is 0x%x bytes, actual length is 0x%x bytes", TOOLS_OPEN_NVDA_SIZE, (u_int32_t)(tlvBuff.size() * 4)); - } - _tlvBuff = tlvBuff; - memset(&_nvdaTlv, 0, sizeof(struct tools_open_nvda)); - std::vector tlvBuffBe = _tlvBuff; - tlvBuffBe.resize(TOOLS_OPEN_NVDA_SIZE >> 2); - memset(&tlvBuffBe[0], 0, TOOLS_OPEN_NVDA_SIZE); - tlvBuffBe.insert(tlvBuffBe.begin(), _tlvBuff.begin(), _tlvBuff.end()); - for (std::vector::iterator it = tlvBuffBe.begin(); it != tlvBuffBe.end(); it++ ) { - *it = __cpu_to_be32(*it); - } - tools_open_nvda_unpack(&_nvdaTlv, ((u_int8_t*)(&tlvBuffBe[0]))); - return verifyTlv(); -} - -int RawCfgParams5thGen::setOnDev(mfile* mf) { - int rc; - mft_signal_set_handling(1); - DEBUG_PRINT_SEND(&_nvdaTlv, nvda); - rc = reg_access_nvda(mf, REG_ACCESS_METHOD_SET, &_nvdaTlv); - DEBUG_PRINT_RECIEVE(&_nvdaTlv, nvda); - dealWithSignal(); - if (rc) { - return errmsg("Failed to set raw TLV: %s", m_err2str((MError)rc)); - } - return MCE_SUCCESS; -} - -std::string RawCfgParams5thGen::dumpTlv() { - char str[1024] = {0}; - snprintf(str, 1024, "Length: 0x%x\nVersion: %d\nOverrideEn: %d\nType: 0x%08x\nData: ", _nvdaTlv.nv_hdr.length,\ - _nvdaTlv.nv_hdr.version, _nvdaTlv.nv_hdr.over_en, _nvdaTlv.nv_hdr.type.tlv_type_dw.tlv_type_dw); - for (size_t i=3; i < _tlvBuff.size(); i++) { - char numStr[64] = {0}; - snprintf(numStr, 64, "0x%08x ", _tlvBuff[i]); - strcat(str, numStr); - } - strcat(str, "\n"); - return str; -} - -int RawCfgParams5thGen::verifyTlv() { - // check TLV length - int tlvLength = (_tlvBuff.size() - 3) << 2; - if (tlvLength != _nvdaTlv.nv_hdr.length) { - return errmsg(MCE_BAD_PARAM_VAL, "TLV size mismatch. reported length in TLV header: 0x%x. actual length: 0x%x", _nvdaTlv.nv_hdr.length, tlvLength); - } - return MCE_SUCCESS; -} - -/* - * CfgParams Class implementation : - */ - -CfgParams::CfgParams(mlxCfgType t, u_int32_t tlvT) { - // init the ErrMsg Class - std::map errmap; - errmap[MCE_SUCCESS] = "Success"; - errmap[MCE_FAILED] = "General Failure"; - errmap[MCE_BAD_PARAMS] = "Bad parameters"; - errmap[MCE_BAD_PARAM_VAL] = "Bad parameter value"; - errmap[MCE_BAD_STATUS] = "General Failure"; - errmap[MCE_GET_DEFAULT_PARAMS] = "Failed to get default params"; - - updateErrCodes(errmap); - type = t; - tlvTypeIdx = tlvT; - _updated = false; - _ignoreHardLimits = false; - _ignoreSoftLimits = false; - _devCapVec = 0; -} - -int CfgParams::getDefaultParams4thGen(mfile* mf, struct tools_open_query_def_params_global* global_params) -{ - mft_signal_set_handling(1); - MError rc = tcif_query_global_def_params(mf, global_params); - dealWithSignal(); - if (rc) { - return errmsg(MCE_BAD_STATUS, "Failed to get default parameters: %s", tcif_err2str(rc)); - } - return MCE_SUCCESS; -} - -int CfgParams::getDefaultParams4thGen(mfile* mf, int port, struct tools_open_query_def_params_per_port* port_params) -{ - mft_signal_set_handling(1); - MError rc = tcif_query_per_port_def_params(mf, port, port_params); - dealWithSignal(); - if (rc) { - return errmsg(MCE_BAD_STATUS, "Failed to get default parameters: %s", tcif_err2str(rc)); - } - return MCE_SUCCESS; -} - -int CfgParams::getDefaultAndFromDev(mfile* mf) -{ - int rc; - rc = getDefaultParams(mf); CHECK_RC(rc); - rc = getFromDev(mf); CHECK_RC(rc); - return MCE_SUCCESS; -} - -bool CfgParams::checkCfg(mfile* mf) -{ - if (!_ignoreHardLimits && !hardLimitCheck()) { - return false; - } - if (!_ignoreSoftLimits && !softLimitCheck(mf)) { - return false; - } - return true; -} - -bool CfgParams::softLimitCheck(mfile* mf) -{ - // by default not implemented - (void)mf; - return true; -} - -void CfgParams::setIgnoreSoftLimits(bool val) -{ - _ignoreSoftLimits = val; -} -void CfgParams::setIgnoreHardLimits(bool val) -{ - _ignoreHardLimits = val; -} - -/* - * BootSettingsExtParams Class implementation: - */ -bool BootSettingsExtParams::hardLimitCheck() -{ - if(_ipVer > 3) { - errmsg("illegal IP Ver parameter value. can be 0..3"); - return false; - } - return true; -} - -void BootSettingsExtParams::setParams(u_int32_t ipVer) -{ - _ipVer = ipVer; -} - -/* - * BootSettingsExtParams4thGen Class implementation: - */ - -u_int32_t BootSettingsExtParams4thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Boot_Settings_Ext_IP_Ver_P1 || - paramType == Mcp_Boot_Settings_Ext_IP_Ver_P2) { - return _ipVerDefault; - } - return MLXCFG_UNKNOWN; -} - -void BootSettingsExtParams4thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Boot_Settings_Ext_IP_Ver_P1 || - paramType == Mcp_Boot_Settings_Ext_IP_Ver_P2) { - _ipVer = val; - } -} - -u_int32_t BootSettingsExtParams4thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Boot_Settings_Ext_IP_Ver_P1 || - paramType == Mcp_Boot_Settings_Ext_IP_Ver_P2) { - return _ipVer; - } - return MLXCFG_UNKNOWN; -} - -bool BootSettingsExtParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)param; - struct tools_open_query_def_params_global params; - int rc; - rc = getDefaultParams4thGen(mf, ¶ms); - if (rc) { - return false; - } - return params.boot_ip_ver; -} - -int BootSettingsExtParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_per_port params; - int rc; - rc = getDefaultParams4thGen(mf, _port, ¶ms); - if (rc) { - return false; - } - _ipVerDefault = params.boot_ip_ver; - setParams(_ipVerDefault); - return MCE_SUCCESS; -} - -int BootSettingsExtParams4thGen::getFromDev(mfile* mf) -{ - if (_updated) { - return MCE_SUCCESS; - } - MError rc; - // prep tlv - u_int8_t buff[tools_open_sriov_size()]; - struct tools_open_boot_settings_ext bootSettingsExtTlv; - memset(buff, 0, tools_open_boot_settings_ext_size()); - memset(&bootSettingsExtTlv, 0, sizeof(struct tools_open_boot_settings_ext)); - // pack it - tools_open_boot_settings_ext_pack(&bootSettingsExtTlv, buff); - // send it - DEBUG_PRINT_SEND(&bootSettingsExtTlv, boot_settings_ext); - rc = mnvaCom4thGen(mf, buff, tools_open_boot_settings_ext_size(), tlvTypeIdx, REG_ACCESS_METHOD_GET, _port); - // check rc - DEBUG_PRINT_RECIEVE(&bootSettingsExtTlv, boot_settings_ext); - if (rc) {// when attempting to get a nv_cfg tlv from device ME_REG_ACCESS_RES_NOT_AVLBL means - no valid - // tlv found. i.e default configuration are on. - if (rc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg(MCE_BAD_STATUS, "Failed to get Boot Settings Extras configuration: %s", m_err2str(rc)); - } - // unpack and update - tools_open_boot_settings_ext_unpack(&bootSettingsExtTlv, buff); - setParams(bootSettingsExtTlv.ip_ver); - _updated = true; - - return MCE_SUCCESS; -} - -int BootSettingsExtParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - if (_ipVer == MLXCFG_UNKNOWN) { - return errmsg("%s please specify all parameters for Boot Settings Extras.", err() ? err() : ""); - } - if (!ignoreCheck && !checkCfg(mf)) { - return MCE_BAD_PARAMS; - } - - // prep tlv - MError ret; - u_int8_t buff[tools_open_boot_settings_ext_size()]; - struct tools_open_boot_settings_ext bootSettingsExtTlv; - - memset(buff, 0, tools_open_boot_settings_ext_size()); - memset(&bootSettingsExtTlv, 0, sizeof(struct tools_open_boot_settings_ext)); - bootSettingsExtTlv.ip_ver = _ipVer; - // pack it - tools_open_boot_settings_ext_pack(&bootSettingsExtTlv, buff); - // send it - ret = mnvaCom4thGen(mf, buff, tools_open_boot_settings_ext_size(), tlvTypeIdx, REG_ACCESS_METHOD_SET, _port); - // check rc - if (ret) { - return errmsg("failed to set Boot Settings Extras params: %s",m_err2str(ret)); - } - _updated = false; - return MCE_SUCCESS; -} - -/* - * BootSettingsExtParams5thGen Class implementation: - */ - -u_int32_t BootSettingsExtParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Boot_Settings_Ext_IP_Ver) { - return _ipVerDefault; - } - return MLXCFG_UNKNOWN; -} - -void BootSettingsExtParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Boot_Settings_Ext_IP_Ver) { - _ipVer = val; - } -} - -u_int32_t BootSettingsExtParams5thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Boot_Settings_Ext_IP_Ver) { - return _ipVer; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t BootSettingsExtParams5thGen::getBootSettingsExtCapabilitiesTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = BOOT_SETTINGS_EXTRAS_GEN5_CAP; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -bool BootSettingsExtParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - u_int8_t tlvCapBuff[TOOLS_OPEN_OPTION_ROM_CAPABILITY_SIZE] = {0}; - struct tools_open_option_rom_capability optionRomCapabilitesTlv; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getBootSettingsExtCapabilitiesTlvTypeBe(), suppRead, suppWrite); - if (rc) { - return false; - } - memset(&optionRomCapabilitesTlv, 0, sizeof(optionRomCapabilitesTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_OPTION_ROM_CAPABILITY_SIZE, getBootSettingsExtCapabilitiesTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return errmsg("Failed to get Boot Settings Ext capabilities parameter. %s", m_err2str(rc)); - } - tools_open_option_rom_capability_unpack(&optionRomCapabilitesTlv, tlvCapBuff); - return optionRomCapabilitesTlv.ip_ver; -} - -int BootSettingsExtParams5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_boot_settings_ext, "Boot Settings Ext"); -} - -void BootSettingsExtParams5thGen::updateClassAttrFromDefaultParams() -{ - setParams(_ipVerDefault); -} - -int BootSettingsExtParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_boot_settings_ext, "Boot Settings Ext"); -} - -u_int32_t BootSettingsExtParams5thGen::getTlvTypeBe() -{ - struct tools_open_per_host_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_PER_HOST; - type.param_idx = tlvTypeIdx; - type.function = 0; // currently support only host 0 (FW should fill this field with correct func) - type.host = 0; // currently support only host 0 (FW should fill this field with correct host) - tools_open_per_host_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void BootSettingsExtParams5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_boot_settings_ext* bootSettingsExt = (struct tools_open_boot_settings_ext*)tlv; - bootSettingsExt->ip_ver = _ipVer; - return; -} -void BootSettingsExtParams5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_boot_settings_ext* bootSettingsExt = (struct tools_open_boot_settings_ext*)tlv; - setParams(bootSettingsExt->ip_ver); - return; -} - -void BootSettingsExtParams5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_boot_settings_ext* bootSettingsExt = (struct tools_open_boot_settings_ext*)tlv; - _ipVerDefault = bootSettingsExt->ip_ver; - return; -} - -int BootSettingsExtParams5thGen::getDefaultParamsAux(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_boot_settings_ext, "Boot Settings Extras"); -} - -int BootSettingsExtParams5thGen::getDefaultParams(mfile* mf) -{ - int rc = getDefaultParamsAux(mf); - if(!rc || _ipVerDefault == MLXCFG_UNKNOWN){ - _ipVerDefault = 0; - setParams(_ipVerDefault); - } - return MCE_SUCCESS; -} - -/* - * SriovParams4thGen Class implementation: - */ - -void SriovParams4thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Sriov_En) { - _sriovEn = val; - } else if (paramType == Mcp_Num_Of_Vfs) { - _numOfVfs = val; - } -} - -u_int32_t SriovParams4thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Sriov_En) { - return _sriovEn; - } else if (paramType == Mcp_Num_Of_Vfs) { - return _numOfVfs; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t SriovParams4thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Sriov_En) { - return _sriovEnDefault; - } else if (paramType == Mcp_Num_Of_Vfs) { - return _numOfVfsDefault; - } - return MLXCFG_UNKNOWN; -} - -bool SriovParams4thGen::hardLimitCheck() -{ - if ((_numOfVfs > _maxVfs)) { - errmsg("Number of VFs exceeds limit (%d).", _maxVfs); - return false; - } - - if (_sriovEn != 0 && _sriovEn != 1) { - errmsg("illegal SRIOV_EN parameter value. (should be 0 or 1)"); - return false; - } - return true; -} - -/* - * SriovParam4thGen Class implementation - */ - -bool SriovParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)mf; - (void)param; - return _devCapVec & SRIOV_MASK; -} - -int SriovParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_global global_params; - int rc; - rc = updateMaxVfs(mf); CHECK_RC(rc); - rc = getDefaultParams4thGen(mf, &global_params); - if (rc == MCE_SUCCESS) { - _sriovEnDefault = global_params.sriov_en; - _numOfVfsDefault = global_params.num_vfs; - setParams(_sriovEnDefault, _numOfVfsDefault); - } else { - rc = MCE_GET_DEFAULT_PARAMS; - } - return rc; -} - -void SriovParams4thGen::setParams(u_int32_t sriovEn, u_int32_t numOfVfs) -{ - _sriovEn = sriovEn; - _numOfVfs = numOfVfs; -} - -int SriovParams4thGen::getFromDev(mfile* mf) -{ - if (_updated) { - return MCE_SUCCESS; - } - MError rc; - // prep tlv - u_int8_t buff[tools_open_sriov_size()]; - struct tools_open_sriov sriovTlv; - memset(buff, 0, tools_open_sriov_size()); - memset(&sriovTlv, 0, sizeof(struct tools_open_sriov)); - // pack it - tools_open_sriov_pack(&sriovTlv, buff); - // send it - DEBUG_PRINT_SEND(&sriovTlv, sriov); - rc = mnvaCom4thGen(mf, buff, tools_open_sriov_size(), tlvTypeIdx, REG_ACCESS_METHOD_GET, 0); - // check rc - DEBUG_PRINT_RECIEVE(&sriovTlv, sriov); - if (rc) {// when attempting to get a nv_cfg tlv from device ME_REG_ACCESS_RES_NOT_AVLBL means - no valid - // tlv found. i.e default configuration are on. - if (rc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg(MCE_BAD_STATUS, "Failed to get SRIOV configuration: %s", m_err2str(rc)); - } - // unpack and update - tools_open_sriov_unpack(&sriovTlv, buff); - setParams(sriovTlv.sriov_en, sriovTlv.total_vfs); - _updated = true; - - return MCE_SUCCESS; -} - -int SriovParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - if (_sriovEn == MLXCFG_UNKNOWN || _numOfVfs == MLXCFG_UNKNOWN) { - return errmsg("%s please specify all parameters for SRIOV.", err() ? err() : ""); - } - if (!ignoreCheck && !checkCfg(mf)) { - return MCE_BAD_PARAMS; - } - - // prep tlv - MError ret; - u_int8_t buff[tools_open_sriov_size()]; - struct tools_open_sriov sriovTlv; - - memset(buff, 0, tools_open_sriov_size()); - memset(&sriovTlv, 0, sizeof(struct tools_open_sriov)); - - sriovTlv.sriov_en = _sriovEn; - sriovTlv.total_vfs = _numOfVfs; - // pack it - tools_open_sriov_pack(&sriovTlv, buff); - // send it - ret = mnvaCom4thGen(mf, buff, tools_open_sriov_size(), tlvTypeIdx, REG_ACCESS_METHOD_SET, 0); - // check rc - if (ret) { - return errmsg("failed to set SRIOV params: %s",m_err2str(ret)); - } - _updated = false; - return MCE_SUCCESS; -} - -int SriovParams4thGen::updateMaxVfs(mfile* mf) -{ - u_int64_t data = 0; - int rc = tcif_query_dev_cap(mf, MAX_VFS_ADDR, &data); - if (rc) { - return errmsg("failed to query device capabilities: %s", m_err2str((MError)rc)); - } - _maxVfs = (u_int32_t)(data & 0xff); - if (_maxVfs == 0) { // defined in CX PRM , if max_func_idx=0 then all functions(128) are operational - _maxVfs = 128; - } - _maxVfs--; // remove 1 physical function - return MCE_SUCCESS; -} - -bool SriovParams4thGen::softLimitCheck(mfile* mf) -{ - u_int32_t barSz = 0; - BarSzParams4thGen barParams; - - if (!mf) { - return false; - } - - if (barParams.getDefaultAndFromDev(mf)) { - return false; - } - - if (_sriovEn == 0) { - return true; - } - - barSz = barParams.getParam(Mcp_Log_Bar_Size); - - if (barSz == MLXCFG_UNKNOWN) { - return errmsg("Failed to get the bar size from device"); - } - // this is the default log2 bar size , we require (numOfVfs+1)*(2^log_uar_bar) <= 512 or else the node might not boot - double TotalMem = (_numOfVfs + 1)*(1 << barSz); // 1 for physical func - - if ((TotalMem > 512)){ - unsigned int maxAlowedVfs =static_cast(512/(1 << barSz)) - 1; - errmsg("illegal SRIOV parameter value. Maximal number of VFs: %d", maxAlowedVfs < _maxVfs ? maxAlowedVfs : _maxVfs); - return false; - } - return true; -} - - -/* - * WolParams Class implementation : - */ - -bool WolParams::hardLimitCheck() -{ - if (_wolMagicEn == 0 || _wolMagicEn == 1 ) { - return true; - } - errmsg("illegal WOL parameter value. can be either 0 or 1."); - return false; -} - -void WolParams::setParams(u_int32_t wolMagicEn) -{ - _wolMagicEn = wolMagicEn; -} - -/* - * WolParams4thGen Class implementation : - */ - -void WolParams4thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ((paramType == Mcp_Wol_Magic_En_P1 && _port == 1) || (paramType == Mcp_Wol_Magic_En_P2 && _port == 2) ) { - _wolMagicEn = val; - } -} - -u_int32_t WolParams4thGen::getParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Wol_Magic_En_P1 && _port == 1) || (paramType == Mcp_Wol_Magic_En_P2 && _port == 2)) { - return _wolMagicEn; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t WolParams4thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Wol_Magic_En_P1 && _port == 1) || (paramType == Mcp_Wol_Magic_En_P2 && _port == 2)) { - return _wolMagicEnDefault; - } - return MLXCFG_UNKNOWN; -} - -bool WolParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)mf; - (void)param; - return ((_devCapVec & WOL_P1_MASK) && _port == 1) || ((_devCapVec & WOL_P2_MASK) && _port == 2 ); -} - -int WolParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_per_port port_params; - int rc = getDefaultParams4thGen(mf, _port , &port_params); - if (rc == MCE_SUCCESS) { - _wolMagicEnDefault = port_params.default_en_wol_magic; - setParams(_wolMagicEnDefault); - } else { - rc = MCE_GET_DEFAULT_PARAMS; - } - return rc; -} - -int WolParams4thGen::getFromDev(mfile* mf) -{ - if (_updated) { - return MCE_SUCCESS; - } - MError rc; - // prep tlv - u_int8_t buff[tools_open_wol_size()]; - struct tools_open_wol wolTlv; - memset(buff, 0, tools_open_wol_size()); - memset(&wolTlv, 0, sizeof(struct tools_open_wol)); - // pack it - tools_open_wol_pack(&wolTlv, buff); - // send it - rc = mnvaCom4thGen(mf, buff, tools_open_wol_size(), tlvTypeIdx, REG_ACCESS_METHOD_GET, _port); - // check rc - if (rc) { - if (rc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get WOL port%d configuration: %s", _port, m_err2str(rc)); - } - // unpack and update - tools_open_wol_unpack(&wolTlv, buff); - setParams(wolTlv.en_wol_magic); - _updated = true; - - return MCE_SUCCESS; -} - -int WolParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - if (_wolMagicEn == MLXCFG_UNKNOWN) { - return errmsg("%s please specify all the parameters for WOL.", err()? err() : ""); - } - if (!ignoreCheck && !checkCfg()) { - return MCE_BAD_PARAMS; - } - // prep tlv - MError ret; - u_int8_t buff[tools_open_wol_size()]; - struct tools_open_wol wolTlv; - - memset(buff, 0, tools_open_wol_size()); - memset(&wolTlv, 0, sizeof(struct tools_open_wol)); - - wolTlv.en_wol_magic= _wolMagicEn; - // pack it - tools_open_wol_pack(&wolTlv, buff); - // send it - ret = mnvaCom4thGen(mf, buff, tools_open_wol_size(), tlvTypeIdx, REG_ACCESS_METHOD_SET, _port); - // check rc - if (ret) { - return errmsg("failed to set WOL params for port%d: %s", _port, m_err2str(ret)); - } - _updated = false; - return MCE_SUCCESS; -} - -/* - * WolParams5thGen Class implementation : - */ - -void WolParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Wol_Magic_En ) { - _wolMagicEn = val; - } -} - -u_int32_t WolParams5thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Wol_Magic_En) { - return _wolMagicEn; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t WolParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Wol_Magic_En) { - return _wolMagicEnDefault; - } - return MLXCFG_UNKNOWN; -} - -bool WolParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get Wake On LAN parameter capabilities. %s", m_err2str(rc)); - return false; - } - return (suppRead && suppWrite); -} - -int WolParams5thGen::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_wol, "Wake On LAN"); -} - -void WolParams5thGen::updateClassAttrFromDefaultParams() -{ - setParams(_wolMagicEnDefault); -} - -int WolParams5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_wol, "Wake On LAN"); -} - -int WolParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_wol, "Wake On LAN"); -} - -u_int32_t WolParams5thGen::getTlvTypeBe() -{ - struct tools_open_per_host_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_PER_HOST; - type.param_idx = tlvTypeIdx; - type.function = 0; // currently support only host 0 (FW should fill this field with correct func) - type.host = 0; // currently support only host 0 (FW should fill this field with correct host) - tools_open_per_host_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void WolParams5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_wol* wolTlv = (struct tools_open_wol*)tlv; - wolTlv->en_wol_magic = _wolMagicEn; - return; -} -void WolParams5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_wol* wolTlv = (struct tools_open_wol*)tlv; - setParams(wolTlv->en_wol_magic); - return; -} - -void WolParams5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_wol* wolTlv = (struct tools_open_wol*)tlv; - _wolMagicEnDefault = wolTlv->en_wol_magic; - return; -} -/* - * BarSzParams Class implementation : - */ - - -void BarSzParams::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Log_Bar_Size) { - _logBarSz = val; - } -} - -u_int32_t BarSzParams::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Log_Bar_Size) { - return _logBarSz; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t BarSzParams::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Log_Bar_Size) { - return _logBarSzDefault; - } - return MLXCFG_UNKNOWN; -} - -bool BarSzParams::hardLimitCheck() -{ - if (_logBarSz > _maxLogBarSz ) { - errmsg("given bar size is too large, max allowed log2 bar size: 0x%x", _maxLogBarSz); - return false; - } - return true; -} - -void BarSzParams::setParams(u_int32_t logBarSz) -{ - _logBarSz = logBarSz; -} -/* - * BarSzParams4thGen Class implementation : - */ - -bool BarSzParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)mf; - (void)param; - return _devCapVec & BAR_SZ_MASK ; -} - -int BarSzParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_global global_params; - int rc = getDefaultParams4thGen(mf, &global_params); - if ((rc == MCE_SUCCESS) & 0) { //TODO: adrianc: remove the & 0 when FW displays thesee parameters correctly in QUERY_DEF_PARAMS command - _logBarSzDefault = global_params.uar_bar_size; - _maxLogBarSz = global_params.max_uar_bar_size; - setParams(_logBarSzDefault); - } else { - // attempt to take from query_dev_cap - rc = getDefaultBarSz(mf); - } - return rc; -} - -int BarSzParams4thGen::getDefaultBarSz(mfile* mf) -{ - u_int64_t data = 0; - MError rc = tcif_query_dev_cap(mf, MAX_BAR_SZ_ADDR, &data); - if (rc) { - return errmsg(MCE_BAD_STATUS,"Failed to query device capabilities. %s", tcif_err2str(rc)); - } - - _maxLogBarSz = EXTRACT64(data, 3, 6); - - rc = tcif_query_dev_cap(mf, DEFAULT_BAR_SZ_ADDR, &data); - if (rc) { - return errmsg(MCE_BAD_STATUS,"Failed to query device capabilities. %s", tcif_err2str(rc)); - } - - _logBarSzDefault = EXTRACT64(data, 16, 6) + 1; //adrianc: this field reports only half of the bar size (i.e without the blue flame) - setParams(_logBarSzDefault); - return MCE_SUCCESS; -} - -int BarSzParams4thGen::getFromDev(mfile* mf) -{ - if (_updated) { - return MCE_SUCCESS; - } - MError rc; - // prep tlv - u_int8_t buff[tools_open_bar_size_size()]; - struct tools_open_bar_size barSzTlv; - memset(buff, 0, tools_open_bar_size_size()); - memset(&barSzTlv, 0, sizeof(struct tools_open_bar_size)); - // pack it - tools_open_bar_size_pack(&barSzTlv, buff); - // send it - rc = mnvaCom4thGen(mf, buff, tools_open_bar_size_size(), tlvTypeIdx, REG_ACCESS_METHOD_GET, 0); - // check rc - if (rc) { - if (rc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get BAR size configuration: %s", m_err2str(rc)); - } - // unpack and update - tools_open_bar_size_unpack(&barSzTlv, buff); - setParams(barSzTlv.log_uar_bar_size); - _updated = true; - - return MCE_SUCCESS; -} - -int BarSzParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - if (_logBarSz == MLXCFG_UNKNOWN) { - return errmsg("%s please specify all the parameters for BAR size.", err() ? err() : ""); - } - - if (!ignoreCheck && !checkCfg(mf)) { - return MCE_BAD_PARAMS; - } - - // prep tlv - MError ret; - u_int8_t buff[tools_open_bar_size_size()]; - struct tools_open_bar_size barSzTlv; - - memset(buff, 0, tools_open_bar_size_size()); - memset(&barSzTlv, 0, sizeof(struct tools_open_bar_size)); - - barSzTlv.log_uar_bar_size= _logBarSz; - // pack it - tools_open_bar_size_pack(&barSzTlv, buff); - // send it - ret = mnvaCom4thGen(mf, buff, tools_open_bar_size_size(), tlvTypeIdx, REG_ACCESS_METHOD_SET, 0); - // check rc - if (ret) { - return errmsg("failed to set BAR size params: %s",m_err2str(ret)); - } - _updated = false; - return MCE_SUCCESS; -} - -bool BarSzParams4thGen::softLimitCheck(mfile* mf) -{ - u_int32_t numOfVfs = 0; - int sriovEn; - SriovParams4thGen sriovParams; - - if (!mf) { - return false; - } - - if (sriovParams.getDefaultAndFromDev(mf)) { - errmsg("Failed to get SRIOV parameters from device: %s", sriovParams.err()); - return false; - } - - numOfVfs = sriovParams.getParam(Mcp_Num_Of_Vfs); - sriovEn = sriovParams.getParam(Mcp_Sriov_En); - - if (numOfVfs== MLXCFG_UNKNOWN || numOfVfs == MLXCFG_UNKNOWN) { - errmsg("Illegal SRIOV parameters values"); - return false; - } - - if (sriovEn == 0) { - return true; - } - // this is the default log2 bar size , we require numOfVfs*(2^log_uar_bar) <= 512 or else the node might not boot - double TotalMem = (numOfVfs+1)*(1 << _logBarSz); - //printf("-D- num_of_vfs*2^(bar_sz+1) = %d*2^%ld = %d\n", _numOfVfs, data, (int)(_numOfVfs*(std::pow((double)2, (int)data)))); - //printf("-D- maxVfs(default set by fw) : %d\n", _maxVfs); - - if (TotalMem > 512){ - unsigned int maxAlowedLogBarSz =static_cast(log2((512/(numOfVfs + 1 )))); - errmsg("illegal Bar Size parameter value. Maximal allowed bar size: %d", maxAlowedLogBarSz < _maxLogBarSz ? maxAlowedLogBarSz : _maxLogBarSz); - return false; - } - return true; -} - - -/* - * VpiParams Class implementation : - */ - -int VpiParams::getFromDevComPre() -{ - // prep tlv - _tlvBuff.resize(TOOLS_OPEN_VPI_SETTINGS_SIZE); - memset(&_tlvBuff[0], 0, TOOLS_OPEN_VPI_SETTINGS_SIZE); - memset(&_vpiTlv, 0, sizeof(struct tools_open_vpi_settings)); - // pack it - tools_open_vpi_settings_pack(&_vpiTlv, &_tlvBuff[0]); - return MCE_SUCCESS; -} - -int VpiParams::getFromDevComPost(MError mnvaComRC) -{ - if (mnvaComRC) { - if (mnvaComRC == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get VPI port%d configuration: %s", _port, m_err2str(mnvaComRC)); - } - // unpack and update - tools_open_vpi_settings_unpack(&_vpiTlv, &_tlvBuff[0]); - setParams(_vpiTlv.network_link_type, _vpiTlv.default_link_type); - _updated = true; - return MCE_SUCCESS; - -} - -void VpiParams::setParams(u_int32_t linkType, u_int32_t defaultLinkType) -{ - _linkType = linkType; - _defaultLinkType = defaultLinkType; -} - -int VpiParams::setOnDevComPre(bool ignoreCheck) -{ - if (_linkType == MLXCFG_UNKNOWN || _defaultLinkType == MLXCFG_UNKNOWN) { - return errmsg("%s please specify all the parameters for VPI settings.", err() ? err() : ""); - } - if (!ignoreCheck && !checkCfg()) { - return MCE_BAD_PARAMS; - } - _tlvBuff.resize(TOOLS_OPEN_VPI_SETTINGS_SIZE); - memset(&_tlvBuff[0], 0, _tlvBuff.size()); - memset(&_vpiTlv, 0, sizeof(struct tools_open_vpi_settings)); - _vpiTlv.network_link_type = _linkType; - _vpiTlv.default_link_type = _defaultLinkType; - // pack it - tools_open_vpi_settings_pack(&_vpiTlv, &_tlvBuff[0]); - return MCE_SUCCESS; -} - -int VpiParams::setOnDevComPost(MError mnvaComRC) -{ - if (mnvaComRC) { - return errmsg("failed to set VPI port%d params: %s", _port, m_err2str(mnvaComRC)); - } - _updated = false; - return MCE_SUCCESS; -} - -/* - * VpiParams4thGen Class implementation : - */ -void VpiParams4thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) { - _linkType = val; - } -} - -u_int32_t VpiParams4thGen::getParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) { - return _linkType; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t VpiParams4thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) { - return _linkTypeDefault; - } - return MLXCFG_UNKNOWN; -} - -bool VpiParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)mf; - (void)param; - return ((_devCapVec & VPI_P1_MASK) && _port == 1) || ((_devCapVec & VPI_P2_MASK) && _port == 2); -} - -int VpiParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_per_port port_params; - _defaultLinkTypeDefault = 0; // not used for 4th gen devices , we give it a default value - int rc = getDefaultParams4thGen(mf, _port , &port_params); - if (rc) { - return MCE_GET_DEFAULT_PARAMS; - } - if (port_params.default_network_link_type) { - _linkTypeDefault = port_params.default_network_link_type; - } - setParams(_linkTypeDefault, _defaultLinkTypeDefault); - return MCE_SUCCESS; -} - -int VpiParams4thGen::getFromDev(mfile* mf) -{ - MError mRc; - int rc; - - if (_updated) { - return MCE_SUCCESS; - } - if((rc = getFromDevComPre())) { - return rc; - } - mRc = mnvaCom4thGen(mf, &_tlvBuff[0], TOOLS_OPEN_VPI_SETTINGS_SIZE, tlvTypeIdx, REG_ACCESS_METHOD_GET, _port); - return getFromDevComPost(mRc); -} - -int VpiParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - MError mRc; - int rc; - - if ((rc = setOnDevComPre(ignoreCheck))) { - return rc; - } - mRc = mnvaCom4thGen(mf, &_tlvBuff[0], TOOLS_OPEN_VPI_SETTINGS_SIZE, tlvTypeIdx, REG_ACCESS_METHOD_SET, _port); - return setOnDevComPost(mRc); -} - -bool VpiParams4thGen::hardLimitCheck() -{ - if (_linkType == 1 || _linkType == 2 || _linkType == 3 ) { - return true; - } - errmsg("illegal VPI link type (should be 1|2|3)."); - return false; -} - -/* - * VpiParams5thGen Class implementation : - */ -void VpiParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) { - _defaultLinkType = val; - } -} - -u_int32_t VpiParams5thGen::getParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) { - return _defaultLinkType; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t VpiParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) { - return _defaultLinkTypeDefault; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t VpiParams5thGen::getTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_PHYS_PORT; - type.param_idx = tlvTypeIdx; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -bool VpiParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - // get mtcr functions for this device (physical) - // compare with port - // send nvqc and check - (void)param; - MError rc; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get VPI params capabilities. %s", m_err2str(rc)); - return false; - } - return suppRead && suppWrite; -} - -int VpiParams5thGen::getDefaultParams(mfile* mf) -{ - MError mRc; - int rc; - - // if configuration is supported then network link type must be 3 - _linkTypeDefault = 3; - - if((rc = getFromDevComPre())) { - return rc; - } - - mRc = mnvaCom5thGen(mf, &_tlvBuff[0], TOOLS_OPEN_VPI_SETTINGS_SIZE, getTlvTypeBe(), REG_ACCESS_METHOD_GET, true); - - if (mRc) { - if (mRc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get VPI port%d configuration: %s", _port, m_err2str(mRc)); - } - - // unpack and update - tools_open_vpi_settings_unpack(&_vpiTlv, &_tlvBuff[0]); - _linkTypeDefault = _vpiTlv.network_link_type; - _defaultLinkTypeDefault = _vpiTlv.default_link_type; - setParams(_linkTypeDefault, _defaultLinkTypeDefault); - return MCE_SUCCESS; - -} - -int VpiParams5thGen::getFromDev(mfile* mf) -{ - MError mRc; - int rc; - - if (_updated) { - return MCE_SUCCESS; - } - if((rc = getFromDevComPre())) { - return rc; - } - mRc = mnvaCom5thGen(mf, &_tlvBuff[0], TOOLS_OPEN_VPI_SETTINGS_SIZE, getTlvTypeBe(), REG_ACCESS_METHOD_GET); - rc = getFromDevComPost(mRc); - - _updated = true; - - return rc; -} - -int VpiParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - MError mRc; - int rc; - - if ((rc = setOnDevComPre(ignoreCheck))) { - return rc; - } - mRc = mnvaCom5thGen(mf, &_tlvBuff[0], TOOLS_OPEN_VPI_SETTINGS_SIZE, getTlvTypeBe(), REG_ACCESS_METHOD_SET); - return setOnDevComPost(mRc); -} - -bool VpiParams5thGen::hardLimitCheck() -{ - if (_defaultLinkType == 1 || _defaultLinkType == 2 ) { - return true; - } - errmsg("illegal VPI link type (should be 1|2)."); - return false; -} - -/* - * PciParams5thGen Class implementation: - */ - -bool PciParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getPciCapabilitiesTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get PCI capabilities parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead) { - return false; - } - - if (getDefaultsAndCapabilities(mf) != MCE_SUCCESS) { - return false; - } - - rc = nvqcCom5thGen(mf, getPciSettingsTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get PCI settings parameter capabilities. %s", m_err2str(rc)); - return false; - } - - if (!(suppRead && suppWrite)) { - return false; - } - - switch(param) { - case Mcp_Sriov_En: - case Mcp_Num_Of_Vfs: - return _sriovSupported; - case Mcp_Fpp_En: - return _fppSupported; - case Mcp_Last: - return true; - case Mcp_PF_Log_Bar_Size: - return _pfLogBarSizeSuppored; - case Mcp_VF_Log_Bar_Size: - return _vfLogBarSizeSuppored; - case Mcp_Num_Pf_Msix: - return _numPfMsixSupported; - case Mcp_Num_Vf_Msix: - return _numVfMsixSupported; - default: - return false; - } -} - -void PciParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Sriov_En) { - _sriovEn = val; - _userSpecifiedSRIOV = true; - } else if (paramType == Mcp_Num_Of_Vfs) { - _numOfVfs = val; - _userSpecifiedSRIOV = true; - } else if (paramType == Mcp_Fpp_En) { - _fppEn = val; - _userSpecifiedFPP = true; - } else if(paramType == Mcp_PF_Log_Bar_Size) { - _pfLogBarSize = val; - _userSpecifiedPfLogBarSize = true; - } else if(paramType == Mcp_VF_Log_Bar_Size) { - _vfLogBarSize = val; - _userSpecifiedVfLogBarSize = true; - } else if(paramType == Mcp_Num_Pf_Msix) { - _numPfMsix = val; - _userSpecifiedNumPfMsix = true; - } else if(paramType == Mcp_Num_Vf_Msix) { - _numVfMsix = val; - _userSpecifiedNumVfMsix = true; - } -} - -u_int32_t PciParams5thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Sriov_En) { - return _sriovEn; - } else if (paramType == Mcp_Num_Of_Vfs) { - return _numOfVfs; - } else if (paramType == Mcp_Fpp_En) { - return _fppEn; - } else if(paramType == Mcp_PF_Log_Bar_Size) { - return _pfLogBarSize; - } else if(paramType == Mcp_VF_Log_Bar_Size) { - return _vfLogBarSize; - } else if(paramType == Mcp_Num_Pf_Msix) { - return _numPfMsix; - } else if(paramType == Mcp_Num_Vf_Msix) { - return _numVfMsix; - } - - return MLXCFG_UNKNOWN; -} - -u_int32_t PciParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Sriov_En) { - return _sriovEnDefault; - } else if (paramType == Mcp_Num_Of_Vfs) { - return _numOfVfsDefault; - } else if (paramType == Mcp_Fpp_En) { - return _fppEnDefault; - } else if(paramType == Mcp_PF_Log_Bar_Size) { - return _pfLogBarSizeDefault; - } else if(paramType == Mcp_VF_Log_Bar_Size) { - return _vfLogBarSizeDefault; - } else if(paramType == Mcp_Num_Pf_Msix) { - return _numPfMsixDefault; - } else if(paramType == Mcp_Num_Vf_Msix) { - return _numVfMsixDefault; - } - - return MLXCFG_UNKNOWN; -} - -int PciParams5thGen::getFromDev(mfile* mf) -{ - MError mRc; - u_int8_t tlvBuff[TOOLS_OPEN_PCI_CONFIGURATION_SIZE] = {0}; - struct tools_open_pci_configuration pciSettingsTlv; - memset(&pciSettingsTlv, 0, sizeof(pciSettingsTlv)); - - if (_updated) { - return MCE_SUCCESS; - } - mRc = mnvaCom5thGen(mf, &tlvBuff[0], TOOLS_OPEN_PCI_CONFIGURATION_SIZE, getPciSettingsTlvTypeBe(), REG_ACCESS_METHOD_GET); - - if (mRc) { - if (mRc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get PCI configuration: %s", m_err2str(mRc)); - } - // unpack and update - tools_open_pci_configuration_unpack(&pciSettingsTlv, &tlvBuff[0]); - if (pciSettingsTlv.sriov_valid) { - _sriovEn = pciSettingsTlv.sriov_en; - _numOfVfs = pciSettingsTlv.total_vfs; - } - if (pciSettingsTlv.fpp_valid) { - _fppEn = pciSettingsTlv.fpp_en; - } - if(pciSettingsTlv.pf_bar_size_valid) { - _pfLogBarSize = pciSettingsTlv.log_pf_uar_bar_size; - } - if(pciSettingsTlv.vf_bar_size_valid) { - _vfLogBarSize = pciSettingsTlv.log_vf_uar_bar_size; - } - if(pciSettingsTlv.num_pfs_valid){ - _numOfPfs = pciSettingsTlv.num_pfs; - _numOfPfsValid = true; - } - if(pciSettingsTlv.num_pfs_msix_valid){ - _numPfMsix = pciSettingsTlv.num_pf_msix; - } - if(pciSettingsTlv.num_vfs_msix_valid){ - _numVfMsix = pciSettingsTlv.num_vf_msix; - } - _updated = true; - - return MCE_SUCCESS; -} - -int PciParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - MError mRc; - - if (!ignoreCheck && !checkCfg()) { - return MCE_BAD_PARAMS; - } - // get Tlv modify it and set it - u_int8_t tlvBuff[TOOLS_OPEN_PCI_CONFIGURATION_SIZE] = {0}; - struct tools_open_pci_configuration pciSettingsTlv; - memset(&pciSettingsTlv, 0, sizeof(pciSettingsTlv)); - - mRc = mnvaCom5thGen(mf, tlvBuff, TOOLS_OPEN_PCI_CONFIGURATION_SIZE, getPciSettingsTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (mRc && mRc != ME_REG_ACCESS_RES_NOT_AVLBL) { - return errmsg("failed to set PCI settings: %s", m_err2str(mRc)); - } - tools_open_pci_configuration_unpack(&pciSettingsTlv, tlvBuff); - - if (_sriovSupported && _userSpecifiedSRIOV) { - if (_sriovEn == MLXCFG_UNKNOWN || _numOfVfs == MLXCFG_UNKNOWN) { - return errmsg("please specify all parameters for SRIOV."); - } - pciSettingsTlv.sriov_valid = 1; - pciSettingsTlv.sriov_en = _sriovEn; - pciSettingsTlv.total_vfs = _numOfVfs; - } - - if (_fppSupported && _userSpecifiedFPP) { - pciSettingsTlv.fpp_en = _fppEn; - pciSettingsTlv.fpp_valid = 1; - } - - if (_pfLogBarSizeSuppored && _userSpecifiedPfLogBarSize) { - pciSettingsTlv.log_pf_uar_bar_size = _pfLogBarSize; - pciSettingsTlv.pf_bar_size_valid = 1; - } - - if (_vfLogBarSizeSuppored && _userSpecifiedVfLogBarSize) { - pciSettingsTlv.log_vf_uar_bar_size = _vfLogBarSize; - pciSettingsTlv.vf_bar_size_valid = 1; - } - - if (pciSettingsTlv.sriov_en && !pciSettingsTlv.fpp_en) { - return errmsg("FPP should be enabled while SRIOV is enabled"); - } - - if(_numPfMsixSupported && _userSpecifiedNumPfMsix) { - pciSettingsTlv.num_pf_msix = _numPfMsix; - pciSettingsTlv.num_pfs_msix_valid = 1; - } - - if(_numVfMsixSupported && _userSpecifiedNumVfMsix) { - pciSettingsTlv.num_vf_msix = _numVfMsix; - pciSettingsTlv.num_vfs_msix_valid = 1; - } - // pack it - tools_open_pci_configuration_pack(&pciSettingsTlv, tlvBuff); - - mRc = mnvaCom5thGen(mf, tlvBuff, TOOLS_OPEN_PCI_CONFIGURATION_SIZE, getPciSettingsTlvTypeBe(), REG_ACCESS_METHOD_SET); - - if (mRc) { - return errmsg("failed to set PCI settings: %s", m_err2str(mRc)); - } - _updated = false; - - return MCE_SUCCESS; -} - -int PciParams5thGen::getDefaultParams(mfile* mf) -{ - int rc = getDefaultsAndCapabilities(mf); - - setParams( - _sriovEnDefault, - _numOfVfsDefault, - _fppEnDefault, - _pfLogBarSizeDefault, - _vfLogBarSizeDefault, - _numOfPfs, - _numPfMsixDefault, - _numVfMsixDefault); - - return rc; -} - -void PciParams5thGen::setParams(u_int32_t sriovEn, u_int32_t numOfVfs, u_int32_t fppEn, u_int32_t pfLogBarSize, - u_int32_t vfLogBarSize, u_int32_t numOfPfs, u_int32_t numPfMsix, u_int32_t numVfMsix) -{ - _sriovEn = sriovEn; - _numOfVfs = numOfVfs; - _fppEn = fppEn; - _pfLogBarSize = pfLogBarSize; - _vfLogBarSize = vfLogBarSize; - _numOfPfs = numOfPfs; - _numPfMsix = numPfMsix; - _numVfMsix = numVfMsix; -} - -int PciParams5thGen::getDefaultsAndCapabilities(mfile* mf) -{ - MError rc; - u_int8_t tlvCapBuff[TOOLS_OPEN_PCI_CAPABILITIES_SIZE] = {0}; - struct tools_open_pci_capabilities pciCapabilitesTlv; - memset(&pciCapabilitesTlv, 0, sizeof(pciCapabilitesTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_PCI_CAPABILITIES_SIZE, getPciCapabilitiesTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return errmsg("Failed to get PCI capabilities parameter. %s", m_err2str(rc)); - } - tools_open_pci_capabilities_unpack(&pciCapabilitesTlv, tlvCapBuff); - _sriovSupported = pciCapabilitesTlv.sriov_support; - _maxVfsPerPf = pciCapabilitesTlv.max_vfs_per_pf_valid ? pciCapabilitesTlv.max_vfs_per_pf : 0; - _fppSupported = pciCapabilitesTlv.fpp_support; - _pfLogBarSizeSuppored = pciCapabilitesTlv.pf_bar_size_supported; - _vfLogBarSizeSuppored = pciCapabilitesTlv.vf_bar_size_supported; - _numPfMsixSupported = pciCapabilitesTlv.num_pf_msix_supported; - _numVfMsixSupported = pciCapabilitesTlv.num_vf_msix_supported; - _maxLogPfBarSize = pciCapabilitesTlv.log_max_pf_uar_bar_size1; - _maxLogVfBarSize = pciCapabilitesTlv.log_max_vf_uar_bar_size; - _maxTotalBarValid = pciCapabilitesTlv.max_total_bar_valid; - _maxTotalBar = pciCapabilitesTlv.max_total_bar; - _maxNumPfMsix = pciCapabilitesTlv.max_num_pf_msix; - _maxNumVfMsix = pciCapabilitesTlv.max_num_vf_msix; - _maxTotalMsixValid = pciCapabilitesTlv.max_total_msix_valid; - _maxTotalMsix = pciCapabilitesTlv.max_total_msix; - - u_int8_t tlvBuff[TOOLS_OPEN_PCI_CONFIGURATION_SIZE] = {0}; - struct tools_open_pci_configuration pciSettingsTlv; - memset(&pciSettingsTlv, 0, sizeof(pciSettingsTlv)); - - rc = mnvaCom5thGen(mf, &tlvBuff[0], TOOLS_OPEN_PCI_CONFIGURATION_SIZE, getPciSettingsTlvTypeBe(), REG_ACCESS_METHOD_GET, true); - - if (rc) { - if (rc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get PCI configuration: %s", m_err2str(rc)); - } - // unpack and update - tools_open_pci_configuration_unpack(&pciSettingsTlv, &tlvBuff[0]); - if (pciSettingsTlv.sriov_valid) { - _sriovEnDefault = pciSettingsTlv.sriov_en; - _numOfVfsDefault = pciSettingsTlv.total_vfs; - } - if (pciSettingsTlv.fpp_valid) { - _fppEnDefault = pciSettingsTlv.fpp_en; - } - if(pciSettingsTlv.pf_bar_size_valid) { - _pfLogBarSizeDefault = pciSettingsTlv.log_pf_uar_bar_size; - } - if(pciSettingsTlv.vf_bar_size_valid) { - _vfLogBarSizeDefault = pciSettingsTlv.log_vf_uar_bar_size; - } - if(pciSettingsTlv.num_pfs_msix_valid) { - _numPfMsixDefault = pciSettingsTlv.num_pf_msix; - } - if(pciSettingsTlv.num_vfs_msix_valid) { - _numVfMsixDefault = pciSettingsTlv.num_vf_msix; - } - - return MCE_SUCCESS; -} - -u_int32_t PciParams5thGen::getPciSettingsTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = tlvTypeIdx; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -u_int32_t PciParams5thGen::getPciCapabilitiesTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = PCI_CAPABILITES_TYPE; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -bool PciParams5thGen::hardLimitCheck() -{ - if (_sriovSupported && _userSpecifiedSRIOV) { - if ((_numOfVfs > _maxVfsPerPf)) { - errmsg("Number of VFs exceeds limit (%d).", _maxVfsPerPf); - return false; - } - - if (_sriovEn != 0 && _sriovEn != 1) { - errmsg("Illegal SRIOV_EN parameter value. (should be 0 or 1)"); - return false; - } - } - - if (_fppSupported && _userSpecifiedFPP) { - if (_fppEn != 0 && _fppEn != 1) { - errmsg("Illegal FPP_EN parameter value. (should be 0 or 1)"); - return false; - } - } - - if (_pfLogBarSizeSuppored && _userSpecifiedPfLogBarSize) { - if (_pfLogBarSize > _maxLogPfBarSize) { - errmsg("Illegal PF_LOG_BAR_SIZE parameter value, Max allowed value is %d", _maxLogPfBarSize); - return false; - } - } - - if (_vfLogBarSizeSuppored && _userSpecifiedVfLogBarSize) { - if (_vfLogBarSize > _maxLogVfBarSize) { - errmsg("Illegal VF_LOG_BAR_SIZE parameter value, Max allowed value is %d", _maxLogVfBarSize); - return false; - } - } - - if(_numPfMsixSupported && _userSpecifiedNumPfMsix) { - if(_numPfMsix > _maxNumPfMsix) { - errmsg("Illegal NUM_PF_MSIX parameter value, Max allowed value is %d", _maxNumPfMsix); - return false; - } - } - - if(_numVfMsixSupported && _userSpecifiedNumVfMsix) { - if(_numVfMsix > _maxNumVfMsix) { - errmsg("Illegal NUM_VF_MSIX parameter value, Max allowed value is %d", _maxNumVfMsix); - return false; - } - } - - return true; -} - -//waiting for arch to correct the constraint formula -u_int32_t PciParams5thGen::calcNumOfVfs() -{ - if(_fppEn == 1){ - return (_maxTotalBar / _numOfPfs - (1 << _pfLogBarSize))/ (1 << _vfLogBarSize); - } else { - return (_maxTotalBar - (1 << _pfLogBarSize)) / (1 << _vfLogBarSize); - } -} - -u_int32_t PciParams5thGen::calcVfLogBarSize() -{ - if(_fppEn == 1){ - return static_cast(log2((_maxTotalBar / _numOfPfs - (1 << _pfLogBarSize)) / _numOfVfs)); - } else { - return static_cast(log2((_maxTotalBar - (1 << _pfLogBarSize)) / _numOfVfs)); - } -} - -u_int32_t PciParams5thGen::calcPfLogBarSize() -{ - if(_fppEn == 1){ - return static_cast(log2((_maxTotalBar / _numOfPfs - (1 << _vfLogBarSize) * _numOfVfs))); - } else { - return static_cast(log2((_maxTotalBar - (1 << _vfLogBarSize) * _numOfVfs))); - } -} - -u_int32_t PciParams5thGen::calcTotalBar() -{ - if(_fppEn == 1){ - return (_numOfPfs * ((1 << _pfLogBarSize) + (1 << _vfLogBarSize) * _numOfVfs)); - } else { - return ((1 << _pfLogBarSize) + (1 << _vfLogBarSize) * _numOfVfs); - } -} - -bool PciParams5thGen::softLimitCheck(mfile* mf) -{ - (void)mf; - if (_maxTotalBarValid == 1 && _maxTotalBar != 0 && _sriovEn == 1) { - if(_userSpecifiedSRIOV || _userSpecifiedPfLogBarSize || _userSpecifiedVfLogBarSize){ - if(_fppEn == 1){ - if(!_numOfPfsValid){ - errmsg("Cannot perform advanced calculations, cannot extract number of physical functions from Firmware."); - return false; - } - if(calcTotalBar() > _maxTotalBar) { - if(_userSpecifiedSRIOV) { - errmsg("Given the specified parameter: NUM_OF_VFS, the maximum allowed values is %d",calcNumOfVfs()); - } else if(_userSpecifiedVfLogBarSize) { - errmsg("Given the specified parameter: VF_Log_Bar_Size, the maximum allowed values is %d",calcVfLogBarSize()); - } else if(_userSpecifiedPfLogBarSize) { - errmsg("Given the specified parameter: PF_Log_Bar_Size, the maximum allowed values is %d",calcPfLogBarSize()); - } - return false; - } - } else { - if(calcTotalBar() > _maxTotalBar) { - if(_userSpecifiedSRIOV){ - errmsg("Given the specified parameter: NUM_OF_VFS, the maximum allowed values is %d",calcNumOfVfs()); - } else if(_userSpecifiedVfLogBarSize) { - errmsg("Given the specified parameter: VF_Log_Bar_Size, the maximum allowed values is %d",calcVfLogBarSize()); - } else if(_userSpecifiedPfLogBarSize) { - errmsg("Given the specified parameter: PF_Log_Bar_Size, the maximum allowed values is %d",calcPfLogBarSize()); - } - return false; - } - } - } - } - - if (_maxTotalMsixValid == 1) { - if (_userSpecifiedSRIOV || _userSpecifiedNumPfMsix || _userSpecifiedNumVfMsix) { - if (!_numOfPfsValid){ - errmsg("Cannot perform advanced calculations, cannot extract number of physical functions from Firmware."); - return false; - } - } - if ((_numOfPfs * (_numPfMsix + _numOfVfs * _numVfMsix)) > _maxTotalMsix){ - if(_userSpecifiedSRIOV){ - errmsg("Given the specified parameter: NUM_OF_VFS, the maximum allowed values is %d", - (((_maxTotalMsix / _numOfPfs) - _numPfMsix) / _numVfMsix)); - } else if(_userSpecifiedNumPfMsix){ - errmsg("Given the specified parameter: NUM_PF_MSIX, the maximum allowed values is %d", - ((_maxTotalMsix / _numOfPfs) - (_numOfVfs * _numVfMsix))); - } else if(_userSpecifiedNumVfMsix){ - errmsg("Given the specified parameter: NUM_VF_MSIX, the maximum allowed values is %d", - (((_maxTotalMsix / _numOfPfs) - _numPfMsix) /_numOfVfs)); - } - } - } - - return true; -} - - -/* - * TptParams5thGen Class implementation: - */ - -bool TptParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTptCapabilitiesTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get TPT capabilities parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead) { - return false; - } - - if (getDefaultsAndCapabilities(mf) != MCE_SUCCESS) { - return false; - } - - rc = nvqcCom5thGen(mf, getTptSettingsTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get TPT settings parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!(suppRead && suppWrite && _logMaxPayloadSizeSupported)) { - return false; - } - return true; -} - -void TptParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Log_Tpt_Size) { - _logMaxPayloadSize = val; - } -} - -u_int32_t TptParams5thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Log_Tpt_Size) { - return _logMaxPayloadSize; - } - - return MLXCFG_UNKNOWN; -} - -u_int32_t TptParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Log_Tpt_Size) { - return _logMaxPayloadSizeDefault; - } - - return MLXCFG_UNKNOWN; -} - -int TptParams5thGen::getFromDev(mfile* mf) -{ - MError mRc; - u_int8_t tlvBuff[TOOLS_OPEN_TPT_CONFIGURATION_SIZE] = {0}; - struct tools_open_tpt_configuration tptSettingsTlv; - memset(&tptSettingsTlv, 0, sizeof(tptSettingsTlv)); - - if (_updated) { - return MCE_SUCCESS; - } - - mRc = mnvaCom5thGen(mf, &tlvBuff[0], TOOLS_OPEN_TPT_CONFIGURATION_SIZE, getTptSettingsTlvTypeBe(), REG_ACCESS_METHOD_GET); - - if (mRc) { - if (mRc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get TPT configuration: %s", m_err2str(mRc)); - } - // unpack and update - tools_open_tpt_configuration_unpack(&tptSettingsTlv, &tlvBuff[0]); - _logMaxPayloadSize = tptSettingsTlv.log_max_payload_size; - - _updated = true; - - return MCE_SUCCESS; -} - -int TptParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - MError mRc; - - if (!ignoreCheck && !checkCfg()) { - return MCE_BAD_PARAMS; - } - // get Tlv modify it and set it - u_int8_t tlvBuff[TOOLS_OPEN_TPT_CONFIGURATION_SIZE] = {0}; - struct tools_open_tpt_configuration tptSettingsTlv; - memset(&tptSettingsTlv, 0, sizeof(tptSettingsTlv)); - - mRc = mnvaCom5thGen(mf, tlvBuff, TOOLS_OPEN_TPT_CONFIGURATION_SIZE, getTptSettingsTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (mRc && mRc != ME_REG_ACCESS_RES_NOT_AVLBL) { - return errmsg("failed to set TPT settings: %s", m_err2str(mRc)); - } - tools_open_tpt_configuration_unpack(&tptSettingsTlv, tlvBuff); - - tptSettingsTlv.log_max_payload_size = _logMaxPayloadSize; - - // pack it - tools_open_tpt_configuration_pack(&tptSettingsTlv, tlvBuff); - - mRc = mnvaCom5thGen(mf, tlvBuff, TOOLS_OPEN_TPT_CONFIGURATION_SIZE, getTptSettingsTlvTypeBe(), REG_ACCESS_METHOD_SET); - - if (mRc) { - return errmsg("failed to set TPT settings: %s", m_err2str(mRc)); - } - _updated = false; - - return MCE_SUCCESS; -} - -int TptParams5thGen::getDefaultParams(mfile* mf) -{ - int rc = getDefaultsAndCapabilities(mf); - setParams(_logMaxPayloadSizeDefault); - return rc; -} - -void TptParams5thGen::setParams(u_int32_t logMaxPayloadSize) -{ - _logMaxPayloadSize = logMaxPayloadSize; -} - -int TptParams5thGen::getDefaultsAndCapabilities(mfile* mf) -{ - MError rc; - u_int8_t tlvCapBuff[TOOLS_OPEN_TPT_CAPABILITIES_SIZE] = {0}; - struct tools_open_tpt_capabilities tptCapabilitesTlv; - memset(&tptCapabilitesTlv, 0, sizeof(tptCapabilitesTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_TPT_CAPABILITIES_SIZE, getTptCapabilitiesTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return errmsg("Failed to get TPT capabilities parameter. %s", m_err2str(rc)); - } - tools_open_tpt_capabilities_unpack(&tptCapabilitesTlv, tlvCapBuff); - _logMaxPayloadSizeSupported = tptCapabilitesTlv.log_max_payload_size_supported; - - u_int8_t tlvBuff[TOOLS_OPEN_TPT_CONFIGURATION_SIZE] = {0}; - struct tools_open_tpt_configuration tptSettingsTlv; - memset(&tptSettingsTlv, 0, sizeof(tptSettingsTlv)); - - rc = mnvaCom5thGen(mf, &tlvBuff[0], TOOLS_OPEN_TPT_CONFIGURATION_SIZE, getTptSettingsTlvTypeBe(), REG_ACCESS_METHOD_GET, true); - - if (rc) { - if (rc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get TPT default configuration: %s", m_err2str(rc)); - } - // unpack and update - tools_open_tpt_configuration_unpack(&tptSettingsTlv, &tlvBuff[0]); - _logMaxPayloadSizeDefault = tptSettingsTlv.log_max_payload_size; - - return MCE_SUCCESS; -} - -u_int32_t TptParams5thGen::getTptSettingsTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = tlvTypeIdx; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -u_int32_t TptParams5thGen::getTptCapabilitiesTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = TPT_CAPABILITES_TYPE; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -bool TptParams5thGen::hardLimitCheck() -{ - if (_logMaxPayloadSize != 0 && _logMaxPayloadSize != 12) { - errmsg("Illegal LOG_MAX_TPT_PAYLOAD_SIZE parameter value. (should be 0(auto) or 12(4KB))"); - return false; - } - return true; -} - -/* - * InfinibandBootSettingsParams4thGen Class implementation: - */ - -bool InfinibandBootSettingsParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)param; - struct tools_open_query_def_params_per_port portParams; - int rc; - rc = getDefaultParams4thGen(mf, _port, &portParams); - if (rc) { - return false; - } - return portParams.nv_config_infiniband_boot_settings; -} - -void InfinibandBootSettingsParams4thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ((paramType == Mcp_Boot_Pkey_P1 && _port == 1) || (paramType == Mcp_Boot_Pkey_P2 && _port == 2)) { - _bootPkey = val; - } -} - -u_int32_t InfinibandBootSettingsParams4thGen::getParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Boot_Pkey_P1 && _port == 1) || (paramType == Mcp_Boot_Pkey_P2 && _port == 2)) { - return _bootPkey; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t InfinibandBootSettingsParams4thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Boot_Pkey_P1 && _port == 1) || (paramType == Mcp_Boot_Pkey_P2 && _port == 2)) { - return _bootPkeyDefault; - } - return MLXCFG_UNKNOWN; -} - - -int InfinibandBootSettingsParams4thGen::getFromDev(mfile* mf) -{ - MError mRc; - u_int8_t tlvBuff[TOOLS_OPEN_INFINIBAND_BOOT_SETTINGS_SIZE] = {0}; - struct tools_open_infiniband_boot_settings bootSettingsTlv; - memset(&bootSettingsTlv, 0, sizeof(bootSettingsTlv)); - - if (_updated) { - return MCE_SUCCESS; - } - - mRc = mnvaCom4thGen(mf, &tlvBuff[0], TOOLS_OPEN_INFINIBAND_BOOT_SETTINGS_SIZE, tlvTypeIdx, REG_ACCESS_METHOD_GET, _port); - - if (mRc) { - if (mRc == ME_REG_ACCESS_RES_NOT_AVLBL) { - return MCE_SUCCESS; - } - return errmsg("Failed to get Infiniband Boot Settings: %s", m_err2str(mRc)); - } - // unpack and update - tools_open_infiniband_boot_settings_unpack(&bootSettingsTlv, &tlvBuff[0]); - _bootPkey = bootSettingsTlv.boot_pkey; - _updated = true; - - return MCE_SUCCESS; -} -int InfinibandBootSettingsParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - MError mRc; - - if (!ignoreCheck && !checkCfg()) { - return MCE_BAD_PARAMS; - } - // get Tlv modify it and set it - u_int8_t tlvBuff[TOOLS_OPEN_INFINIBAND_BOOT_SETTINGS_SIZE] = {0}; - struct tools_open_infiniband_boot_settings bootSettingsTlv; - memset(&bootSettingsTlv, 0, sizeof(bootSettingsTlv)); - - bootSettingsTlv.boot_pkey = _bootPkey; - - // pack it - tools_open_infiniband_boot_settings_pack(&bootSettingsTlv, tlvBuff); - - mRc = mnvaCom4thGen(mf, tlvBuff, TOOLS_OPEN_TPT_CONFIGURATION_SIZE, tlvTypeIdx, REG_ACCESS_METHOD_SET, _port); - - if (mRc) { - return errmsg("failed to set Infiniband Boot Settings: %s", m_err2str(mRc)); - } - _updated = false; - - return MCE_SUCCESS; -} - -int InfinibandBootSettingsParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_per_port portParams; - int rc; - rc = getDefaultParams4thGen(mf, _port, &portParams); - if (rc == MCE_SUCCESS) { - _bootPkeyDefault = portParams.default_boot_pkey; - setParams(_bootPkeyDefault); - } else { - rc = MCE_GET_DEFAULT_PARAMS; - } - return rc; -} - -void InfinibandBootSettingsParams4thGen::setParams(u_int32_t bootPkey) -{ - _bootPkey = bootPkey; -} - -bool InfinibandBootSettingsParams4thGen::hardLimitCheck() -{ - if (_bootPkey >= (1 << 16)) { - errmsg("Illegal BOOT_PKEY_P%d parameter value, valid values: [0..65535]", ((_port == 1) ? 1 : 2)); - return false; - } - return true; -} - -/* - * IBDCParams5thGen Class implementation: - */ - -bool IBDCParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getDcCapabilitiesTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get Infiniband DC capabilities parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead) { - return false; - } - - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get Infiniband DC Settings parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!(suppRead && suppWrite)) { - return false; - } - return true; -} - -void IBDCParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Log_Dcr_Hash_Table_Size) { - _logDcrHashTableSize = val; - } - if (paramType == Mcp_Dcr_Lifo_Size) { - _dcrLifoSize = val; - } -} - -u_int32_t IBDCParams5thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Log_Dcr_Hash_Table_Size) { - return _logDcrHashTableSize; - } - if (paramType == Mcp_Dcr_Lifo_Size) { - return _dcrLifoSize; - } - - return MLXCFG_UNKNOWN; -} - -u_int32_t IBDCParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Log_Dcr_Hash_Table_Size) { - return _logDcrHashTableSizeDefault; - } - if (paramType == Mcp_Dcr_Lifo_Size) { - return _dcrLifoSizeDefault; - } - - return MLXCFG_UNKNOWN; -} - -void IBDCParams5thGen::setParams(u_int32_t logDcrHashTableSize, u_int32_t dcrLifoSize) -{ - _logDcrHashTableSize = logDcrHashTableSize; - _dcrLifoSize = dcrLifoSize; -} - -void IBDCParams5thGen::updateClassAttrFromDefaultParams() -{ - setParams(_logDcrHashTableSizeDefault, - _dcrLifoSizeDefault); -} - -int IBDCParams5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_infiniband_dc_settings, "IB Dynamically Connected"); -} - -int IBDCParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_infiniband_dc_settings, "IB Dynamically Connected"); -} - -int IBDCParams5thGen::getDefaultParams(mfile* mf) -{ - return getDefaultsAndCapabilities(mf); -} - -int IBDCParams5thGen::getDefaultsAndCapabilities(mfile* mf) -{ - MError rc; - u_int8_t tlvCapBuff[TOOLS_OPEN_INFINIBAND_DC_CAPABILITIES_SIZE] = {0}; - struct tools_open_infiniband_dc_capabilities dcCapabilitesTlv; - memset(&dcCapabilitesTlv, 0, sizeof(dcCapabilitesTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_INFINIBAND_DC_CAPABILITIES_SIZE, getDcCapabilitiesTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return errmsg("Failed to get Infiniband DC capabilities parameter. %s", m_err2str(rc)); - } - tools_open_infiniband_dc_capabilities_unpack(&dcCapabilitesTlv, tlvCapBuff); - _minLogDcrHashTableSize = dcCapabilitesTlv.min_log_dcr_hash_table_size; - _maxLogDcrHashTableSize = dcCapabilitesTlv.max_log_dcr_hash_table_size; - _minDcrLifoSize = dcCapabilitesTlv.min_dcr_lifo_size; - _maxDcrLifoSize = dcCapabilitesTlv.max_dcr_lifo_size; - - GET_DEFAULT_5TH_GEN(mf, tools_open_infiniband_dc_settings, "IB Dynamically Connected"); -} - -u_int32_t IBDCParams5thGen::getTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = tlvTypeIdx; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -u_int32_t IBDCParams5thGen::getDcCapabilitiesTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = INFINIBAND_DC_CAPABILITIES_TYPE; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -bool IBDCParams5thGen::hardLimitCheck() -{ - if (_logDcrHashTableSize < _minLogDcrHashTableSize || _logDcrHashTableSize > _maxLogDcrHashTableSize) { - errmsg("Illegal LOG_DCR_HASH_TABLE_SIZE parameter value. (should be within the range [%d..%d])", _minLogDcrHashTableSize, _maxLogDcrHashTableSize); - return false; - } - if (_dcrLifoSize < _minDcrLifoSize || _dcrLifoSize > _maxDcrLifoSize) { - errmsg("Illegal DCR_LIFO_SIZE parameter value. (should be within the range [%d..%d])", _minDcrLifoSize, _maxDcrLifoSize); - return false; - } - return true; -} - -void IBDCParams5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_infiniband_dc_settings* ibDcTlv = (struct tools_open_infiniband_dc_settings*)tlv; - ibDcTlv->dcr_lifo_size = _dcrLifoSize; - ibDcTlv->log_dcr_hash_table_size = _logDcrHashTableSize; - return; -} - -void IBDCParams5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_infiniband_dc_settings* ibDcTlv = (struct tools_open_infiniband_dc_settings*)tlv; - _dcrLifoSize = ibDcTlv->dcr_lifo_size; - _logDcrHashTableSize = ibDcTlv->log_dcr_hash_table_size; - return; -} - -void IBDCParams5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_infiniband_dc_settings* ibDcTlv = (struct tools_open_infiniband_dc_settings*)tlv; - _dcrLifoSizeDefault = ibDcTlv->dcr_lifo_size; - _logDcrHashTableSizeDefault = ibDcTlv->log_dcr_hash_table_size; - return; -} - -/* - * RoCENextProtocolParams5thGen Class implementation - */ - - -bool RoCENextProtocolParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get RoCE next protocol parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - return true; -} - -void RoCENextProtocolParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ( paramType == Mcp_RoCE_Next_Protocol) { - _nextProtocol = val; - } - return; -} - -u_int32_t RoCENextProtocolParams5thGen::getParam(mlxCfgParam paramType) -{ - if ( paramType == Mcp_RoCE_Next_Protocol) { - return _nextProtocol; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t RoCENextProtocolParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ( paramType == Mcp_RoCE_Next_Protocol) { - return _nextProtocolDefault; - } - return MLXCFG_UNKNOWN; -} - -void RoCENextProtocolParams5thGen::setParams(u_int32_t nextProtocol) -{ - _nextProtocol = nextProtocol; -} - -void RoCENextProtocolParams5thGen::updateClassAttrFromDefaultParams() -{ - setParams(_nextProtocolDefault); -} - -int RoCENextProtocolParams5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_roce_v_1_5_next_protocol, "RoCE Next Protocol"); -} - -int RoCENextProtocolParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_roce_v_1_5_next_protocol, "RoCE Next Protocol"); -} - -int RoCENextProtocolParams5thGen::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_roce_v_1_5_next_protocol, "RoCE Next Protocol"); -} - -bool RoCENextProtocolParams5thGen::hardLimitCheck() -{ - if (_nextProtocol > 255) { - errmsg("Illegal ROCE_NEXT_PROTOCOL parameter value(0x%x), value should be in range [0..0xff]", _nextProtocol); - return false; - } - return true; -} - -u_int32_t RoCENextProtocolParams5thGen::getTlvTypeBe() -{ - struct tools_open_global_type type; - u_int32_t tlvType = 0; - - type.param_class = CLASS_GLOBAL; - type.param_idx = tlvTypeIdx; - tools_open_global_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void RoCENextProtocolParams5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_roce_v_1_5_next_protocol* roceNpTlv = (struct tools_open_roce_v_1_5_next_protocol*)tlv; - roceNpTlv->roce_over_ip_next_protocol = _nextProtocol; - return; -} - -void RoCENextProtocolParams5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_roce_v_1_5_next_protocol* roceNpTlv = (struct tools_open_roce_v_1_5_next_protocol*)tlv; - _nextProtocol = roceNpTlv->roce_over_ip_next_protocol; - return; -} - -void RoCENextProtocolParams5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_roce_v_1_5_next_protocol* roceNpTlv = (struct tools_open_roce_v_1_5_next_protocol*)tlv; - _nextProtocolDefault = roceNpTlv->roce_over_ip_next_protocol; - return; -} - -/* - * RoCECCParams5thGen Class implementation - */ - - -bool RoCECCParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get RoCE CC parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - return true; -} - -void RoCECCParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ( (paramType == Mcp_RoCE_CC_Algorithm_P1 && _port == 1) || (paramType == Mcp_RoCE_CC_Algorithm_P2 && _port == 2)) { - _roceCcAlgorithm = val; - } - if ( (paramType == Mcp_RoCE_CC_Prio_Mask_P1 && _port == 1) || (paramType == Mcp_RoCE_CC_Prio_Mask_P2 && _port == 2)) { - _roceCcPrioMask = val; - } - return; -} - -u_int32_t RoCECCParams5thGen::getParam(mlxCfgParam paramType) -{ - if ( (paramType == Mcp_RoCE_CC_Algorithm_P1 && _port == 1) || (paramType == Mcp_RoCE_CC_Algorithm_P2 && _port == 2)) { - return _roceCcAlgorithm; - } - if ( (paramType == Mcp_RoCE_CC_Prio_Mask_P1 && _port == 1) || (paramType == Mcp_RoCE_CC_Prio_Mask_P2 && _port == 2)) { - return _roceCcPrioMask; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t RoCECCParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ( (paramType == Mcp_RoCE_CC_Algorithm_P1 && _port == 1) || (paramType == Mcp_RoCE_CC_Algorithm_P2 && _port == 2)) { - return _roceCcAlgorithmDefault; - } - if ( (paramType == Mcp_RoCE_CC_Prio_Mask_P1 && _port == 1) || (paramType == Mcp_RoCE_CC_Prio_Mask_P2 && _port == 2)) { - return _roceCcPrioMaskDefault; - } - return MLXCFG_UNKNOWN; -} - -void RoCECCParams5thGen::setParams(u_int32_t roceCcAlgorithm, u_int32_t roceCcPrioMask) -{ - _roceCcAlgorithm = roceCcAlgorithm; - _roceCcPrioMask = roceCcPrioMask; -} - -void RoCECCParams5thGen::updateClassAttrFromDefaultParams() -{ - setParams( - _roceCcAlgorithmDefault, - _roceCcPrioMaskDefault); -} - -int RoCECCParams5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_roce_cc, "RoCE CC"); -} - -int RoCECCParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_roce_cc, "RoCE CC"); -} -int RoCECCParams5thGen::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_roce_cc, "RoCE CC"); -} - -bool RoCECCParams5thGen::hardLimitCheck() -{ - if (_roceCcAlgorithm > 1) { - errmsg("Illegal ROCE_CC_ALGORITHM_P%d parameter value(%d), value should be 0 for ECN or 1 for QCN", _port, _roceCcAlgorithm); - return false; - } - if (_roceCcPrioMask > 255) { - errmsg("Illegal ROCE_CC_PRIO_MASK_P%d parameter value(%#x), value should be within the range [0..0xff]", _port, _roceCcPrioMask); - return false; - } - return true; -} - -u_int32_t RoCECCParams5thGen::getTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = tlvTypeIdx; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void RoCECCParams5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_roce_cc* roceCcTlv = (struct tools_open_roce_cc*)tlv; - roceCcTlv->roce_cc_algorithm = _roceCcAlgorithm; - roceCcTlv->roce_cc_enable_priority = _roceCcPrioMask; - return; -} - -void RoCECCParams5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_roce_cc* roceCcTlv = (struct tools_open_roce_cc*)tlv; - _roceCcAlgorithm = roceCcTlv->roce_cc_algorithm; - _roceCcPrioMask = roceCcTlv->roce_cc_enable_priority; - return; -} - -void RoCECCParams5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_roce_cc* roceCcTlv = (struct tools_open_roce_cc*)tlv; - _roceCcAlgorithmDefault = roceCcTlv->roce_cc_algorithm; - _roceCcPrioMaskDefault = roceCcTlv->roce_cc_enable_priority; - return; -} - -/* - * RoCECCEcnParams5thGen Class implementation - */ - - -bool RoCECCEcnParams5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get RoCE CC ECN parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - return true; -} - -void RoCECCEcnParams5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - // TODO: adrianc move to MAP on large scale TLVs std::map for easier access, init in constructor according to port - if (_port == 1) { - switch (paramType) { - case Mcp_Clamp_Tgt_Rate_P1: - _clampTgtRate = val; - break; - case Mcp_Clamp_Tgt_Rate_After_Time_Inc_P1: - _clampTgtRateAfterTimeInc = val; - break; - case Mcp_Rpg_Time_Reset_P1: - _rpgTimeReset = val; - break; - case Mcp_Rpg_Byte_Reset_P1: - _rpgByteReset = val; - break; - case Mcp_Rpg_Threshold_P1: - _rpgThreshold = val; - break; - case Mcp_Rpg_Max_Rate_P1: - _rpgMaxRate = val; - break; - case Mcp_Rpg_Ai_Rate_P1: - _rpgAiRate = val; - break; - case Mcp_Rpg_Hai_Rate_P1: - _rpgHaiRate = val; - break; - case Mcp_Rpg_Gd_P1: - _rpgGd = val; - break; - case Mcp_Rpg_Min_Dec_Fac_P1: - _rpgMinDecFac = val; - break; - case Mcp_Rpg_Min_Rate_P1: - _rpgMinRate = val; - break; - case Mcp_Rate_To_Set_On_First_Cnp_P1: - _rateToSetOnFirstCnp = val; - break; - case Mcp_Dce_Tcp_G_P1: - _dceTcpG = val; - break; - case Mcp_Dce_Tcp_Rtt_P1: - _dceTcpRtt = val; - break; - case Mcp_Rate_Reduce_Monitor_Period_P1: - _rateReduceMonitorPeriod = val; - break; - case Mcp_Initial_Alpha_Value_P1: - _initialAlphaValue = val; - break; - case Mcp_Min_Time_Between_Cnps_P1: - _minTimeBetweenCnps = val; - break; - case Mcp_Cnp_Dscp_P1: - _cnpDscp = val; - break; - case Mcp_Cnp_802p_Prio_P1: - _cnp802pPrio = val; - break; - default: - break; - } - } else if (_port == 2) { - switch (paramType) { - case Mcp_Clamp_Tgt_Rate_P2: - _clampTgtRate = val; - break; - case Mcp_Clamp_Tgt_Rate_After_Time_Inc_P2: - _clampTgtRateAfterTimeInc = val; - break; - case Mcp_Rpg_Time_Reset_P2: - _rpgTimeReset = val; - break; - case Mcp_Rpg_Byte_Reset_P2: - _rpgByteReset = val; - break; - case Mcp_Rpg_Threshold_P2: - _rpgThreshold = val; - break; - case Mcp_Rpg_Max_Rate_P2: - _rpgMaxRate = val; - break; - case Mcp_Rpg_Ai_Rate_P2: - _rpgAiRate = val; - break; - case Mcp_Rpg_Hai_Rate_P2: - _rpgHaiRate = val; - break; - case Mcp_Rpg_Gd_P2: - _rpgGd = val; - break; - case Mcp_Rpg_Min_Dec_Fac_P2: - _rpgMinDecFac = val; - break; - case Mcp_Rpg_Min_Rate_P2: - _rpgMinRate = val; - break; - case Mcp_Rate_To_Set_On_First_Cnp_P2: - _rateToSetOnFirstCnp = val; - break; - case Mcp_Dce_Tcp_G_P2: - _dceTcpG = val; - break; - case Mcp_Dce_Tcp_Rtt_P2: - _dceTcpRtt = val; - break; - case Mcp_Rate_Reduce_Monitor_Period_P2: - _rateReduceMonitorPeriod = val; - break; - case Mcp_Initial_Alpha_Value_P2: - _initialAlphaValue = val; - break; - case Mcp_Min_Time_Between_Cnps_P2: - _minTimeBetweenCnps = val; - break; - case Mcp_Cnp_Dscp_P2: - _cnpDscp = val; - break; - case Mcp_Cnp_802p_Prio_P2: - _cnp802pPrio = val; - break; - default: - break; - } - } - return; -} - -u_int32_t RoCECCEcnParams5thGen::getParam(mlxCfgParam paramType) -{ - // adrianc: consider moving to MAP on large scale TLVs - if (_port == 1) { - switch (paramType) { - case Mcp_Clamp_Tgt_Rate_P1: - return _clampTgtRate; - case Mcp_Clamp_Tgt_Rate_After_Time_Inc_P1: - return _clampTgtRateAfterTimeInc; - case Mcp_Rpg_Time_Reset_P1: - return _rpgTimeReset; - case Mcp_Rpg_Byte_Reset_P1: - return _rpgByteReset; - case Mcp_Rpg_Threshold_P1: - return _rpgThreshold; - case Mcp_Rpg_Max_Rate_P1: - return _rpgMaxRate; - case Mcp_Rpg_Ai_Rate_P1: - return _rpgAiRate; - case Mcp_Rpg_Hai_Rate_P1: - return _rpgHaiRate; - case Mcp_Rpg_Gd_P1: - return _rpgGd; - case Mcp_Rpg_Min_Dec_Fac_P1: - return _rpgMinDecFac; - case Mcp_Rpg_Min_Rate_P1: - return _rpgMinRate; - case Mcp_Rate_To_Set_On_First_Cnp_P1: - return _rateToSetOnFirstCnp; - case Mcp_Dce_Tcp_G_P1: - return _dceTcpG; - case Mcp_Dce_Tcp_Rtt_P1: - return _dceTcpRtt; - case Mcp_Rate_Reduce_Monitor_Period_P1: - return _rateReduceMonitorPeriod; - case Mcp_Initial_Alpha_Value_P1: - return _initialAlphaValue; - case Mcp_Min_Time_Between_Cnps_P1: - return _minTimeBetweenCnps; - case Mcp_Cnp_Dscp_P1: - return _cnpDscp; - case Mcp_Cnp_802p_Prio_P1: - return _cnp802pPrio; - default: - break; - } - } else if (_port == 2) { - switch (paramType) { - case Mcp_Clamp_Tgt_Rate_P2: - return _clampTgtRate; - case Mcp_Clamp_Tgt_Rate_After_Time_Inc_P2: - return _clampTgtRateAfterTimeInc; - case Mcp_Rpg_Time_Reset_P2: - return _rpgTimeReset; - case Mcp_Rpg_Byte_Reset_P2: - return _rpgByteReset; - case Mcp_Rpg_Threshold_P2: - return _rpgThreshold; - case Mcp_Rpg_Max_Rate_P2: - return _rpgMaxRate; - case Mcp_Rpg_Ai_Rate_P2: - return _rpgAiRate; - case Mcp_Rpg_Hai_Rate_P2: - return _rpgHaiRate; - case Mcp_Rpg_Gd_P2: - return _rpgGd; - case Mcp_Rpg_Min_Dec_Fac_P2: - return _rpgMinDecFac; - case Mcp_Rpg_Min_Rate_P2: - return _rpgMinRate; - case Mcp_Rate_To_Set_On_First_Cnp_P2: - return _rateToSetOnFirstCnp; - case Mcp_Dce_Tcp_G_P2: - return _dceTcpG; - case Mcp_Dce_Tcp_Rtt_P2: - return _dceTcpRtt; - case Mcp_Rate_Reduce_Monitor_Period_P2: - return _rateReduceMonitorPeriod; - case Mcp_Initial_Alpha_Value_P2: - return _initialAlphaValue; - case Mcp_Min_Time_Between_Cnps_P2: - return _minTimeBetweenCnps; - case Mcp_Cnp_Dscp_P2: - return _cnpDscp; - case Mcp_Cnp_802p_Prio_P2: - return _cnp802pPrio; - default: - break; - } - } - return MLXCFG_UNKNOWN; -} - -u_int32_t RoCECCEcnParams5thGen::getDefaultParam(mlxCfgParam paramType) -{ - // adrianc: consider moving to MAP on large scale TLVs - if (_port == 1) { - switch (paramType) { - case Mcp_Clamp_Tgt_Rate_P1: - return _clampTgtRateDefault; - case Mcp_Clamp_Tgt_Rate_After_Time_Inc_P1: - return _clampTgtRateAfterTimeIncDefault; - case Mcp_Rpg_Time_Reset_P1: - return _rpgTimeResetDefault; - case Mcp_Rpg_Byte_Reset_P1: - return _rpgByteResetDefault; - case Mcp_Rpg_Threshold_P1: - return _rpgThresholdDefault; - case Mcp_Rpg_Max_Rate_P1: - return _rpgMaxRateDefault; - case Mcp_Rpg_Ai_Rate_P1: - return _rpgAiRateDefault; - case Mcp_Rpg_Hai_Rate_P1: - return _rpgHaiRateDefault; - case Mcp_Rpg_Gd_P1: - return _rpgGdDefault; - case Mcp_Rpg_Min_Dec_Fac_P1: - return _rpgMinDecFacDefault; - case Mcp_Rpg_Min_Rate_P1: - return _rpgMinRateDefault; - case Mcp_Rate_To_Set_On_First_Cnp_P1: - return _rateToSetOnFirstCnpDefault; - case Mcp_Dce_Tcp_G_P1: - return _dceTcpGDefault; - case Mcp_Dce_Tcp_Rtt_P1: - return _dceTcpRttDefault; - case Mcp_Rate_Reduce_Monitor_Period_P1: - return _rateReduceMonitorPeriodDefault; - case Mcp_Initial_Alpha_Value_P1: - return _initialAlphaValueDefault; - case Mcp_Min_Time_Between_Cnps_P1: - return _minTimeBetweenCnpsDefault; - case Mcp_Cnp_Dscp_P1: - return _cnpDscpDefault; - case Mcp_Cnp_802p_Prio_P1: - return _cnp802pPrioDefault; - default: - break; - } - } else if (_port == 2) { - switch (paramType) { - case Mcp_Clamp_Tgt_Rate_P2: - return _clampTgtRateDefault; - case Mcp_Clamp_Tgt_Rate_After_Time_Inc_P2: - return _clampTgtRateAfterTimeIncDefault; - case Mcp_Rpg_Time_Reset_P2: - return _rpgTimeResetDefault; - case Mcp_Rpg_Byte_Reset_P2: - return _rpgByteResetDefault; - case Mcp_Rpg_Threshold_P2: - return _rpgThresholdDefault; - case Mcp_Rpg_Max_Rate_P2: - return _rpgMaxRateDefault; - case Mcp_Rpg_Ai_Rate_P2: - return _rpgAiRateDefault; - case Mcp_Rpg_Hai_Rate_P2: - return _rpgHaiRateDefault; - case Mcp_Rpg_Gd_P2: - return _rpgGdDefault; - case Mcp_Rpg_Min_Dec_Fac_P2: - return _rpgMinDecFacDefault; - case Mcp_Rpg_Min_Rate_P2: - return _rpgMinRateDefault; - case Mcp_Rate_To_Set_On_First_Cnp_P2: - return _rateToSetOnFirstCnpDefault; - case Mcp_Dce_Tcp_G_P2: - return _dceTcpGDefault; - case Mcp_Dce_Tcp_Rtt_P2: - return _dceTcpRttDefault; - case Mcp_Rate_Reduce_Monitor_Period_P2: - return _rateReduceMonitorPeriodDefault; - case Mcp_Initial_Alpha_Value_P2: - return _initialAlphaValueDefault; - case Mcp_Min_Time_Between_Cnps_P2: - return _minTimeBetweenCnpsDefault; - case Mcp_Cnp_Dscp_P2: - return _cnpDscpDefault; - case Mcp_Cnp_802p_Prio_P2: - return _cnp802pPrioDefault; - default: - break; - } - } - return MLXCFG_UNKNOWN; -} - -void RoCECCEcnParams5thGen::setParams(u_int32_t clampTgtRate, u_int32_t clampTgtRateAfterTimeInc, u_int32_t rpgTimeReset, u_int32_t rpgByteReset, - u_int32_t rpgThreshold, u_int32_t rpgMaxRate, u_int32_t rpgAiRate, u_int32_t rpgHaiRate, - u_int32_t rpgGd, u_int32_t rpgMinDecFac, u_int32_t rpgMinRate, u_int32_t rateToSetOnFirstCnp, - u_int32_t dceTcpG, u_int32_t dceTcpRtt, u_int32_t rateReduceMonitorPeriod, u_int32_t initialAlphaValue, - u_int32_t minTimeBetweenCnps, u_int32_t cnpDscp, u_int32_t cnp802pPrio){ - _clampTgtRate = clampTgtRate; - _clampTgtRateAfterTimeInc = clampTgtRateAfterTimeInc; - _rpgTimeReset = rpgTimeReset; - _rpgByteReset = rpgByteReset; - _rpgThreshold = rpgThreshold; - _rpgMaxRate = rpgMaxRate; - _rpgAiRate = rpgAiRate; - _rpgHaiRate = rpgHaiRate; - _rpgGd = rpgGd; - _rpgMinDecFac = rpgMinDecFac; - _rpgMinRate = rpgMinRate; - _rateToSetOnFirstCnp = rateToSetOnFirstCnp; - _dceTcpG = dceTcpG; - _dceTcpRtt = dceTcpRtt; - _rateReduceMonitorPeriod = rateReduceMonitorPeriod; - _initialAlphaValue = initialAlphaValue; - _minTimeBetweenCnps = minTimeBetweenCnps; - _cnpDscp = cnpDscp; - _cnp802pPrio = cnp802pPrio; -} - -void RoCECCEcnParams5thGen::updateClassAttrFromDefaultParams() -{ - setParams(_clampTgtRateDefault,_clampTgtRateAfterTimeIncDefault, - _rpgTimeResetDefault, - _rpgByteResetDefault, - _rpgThresholdDefault, - _rpgMaxRateDefault, - _rpgAiRateDefault, - _rpgHaiRateDefault, - _rpgGdDefault, - _rpgMinDecFacDefault, - _rpgMinRateDefault, - _rateToSetOnFirstCnpDefault, - _dceTcpGDefault, - _dceTcpRttDefault, - _rateReduceMonitorPeriodDefault, - _initialAlphaValueDefault, - _minTimeBetweenCnpsDefault, - _cnpDscpDefault, - _cnp802pPrioDefault); -} - -int RoCECCEcnParams5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_roce_cc_ecn, "RoCE CC ECN"); -} - -int RoCECCEcnParams5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_roce_cc_ecn, "RoCE CC ECN"); -} -int RoCECCEcnParams5thGen::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_roce_cc_ecn, "RoCE CC ECN"); -} - -u_int32_t _dceTcpG; -u_int32_t _dceTcpRtt; -u_int32_t _rateReduceMonitorPeriod; -u_int32_t _initialAlphaValue; -u_int32_t _minTimeBetweenCnps; -u_int32_t _cnpDscp; -u_int32_t _cnp802pPrio; - -bool RoCECCEcnParams5thGen::hardLimitCheck() -{ - if (_clampTgtRate > 1) { - errmsg("Illegal CLAMP_TGT_RATE_P%d parameter value(%d), value should be 0 or 1", _port, _clampTgtRate); - return false; - } - - if (_clampTgtRateAfterTimeInc > 1) { - errmsg("Illegal CLAMP_TGT_RATE_AFTER_TIME_INC_P%d parameter value(%d), value should be 0 or 1", _port, _clampTgtRateAfterTimeInc); - return false; - } - - if ( _rpgTimeReset >= (1 << 17)) { - errmsg("Illegal RPG_TIME_RESET_P%d parameter value(%d), value should be [0..%d]", _port, _rpgTimeReset, (1 << 17) - 1); - return false; - } - - if (_rpgByteReset >= (1 << 15)) { - errmsg("Illegal RPG_BYTE_RESET_P%d parameter value(%d), value should be [0..%d]", _port, _rpgByteReset, (1 << 15) - 1); - return false; - } - - if (_rpgThreshold >= (1 << 5)) { - errmsg("Illegal RPG_THRESHOLD_P%d parameter value(%d), value should be [0..%d]", _port, _rpgThreshold, (1 << 5) - 1); - return false; - } - - if ( _rpgAiRate >= (1 << 17)) { - errmsg("Illegal RPG_AI_RATE_P%d parameter value(%d), value should be [0..%d]", _port, _rpgAiRate, (1 << 17) - 1); - return false; - } - - if ( _rpgHaiRate >= (1 << 17)) { - errmsg("Illegal RPG_HAI_RATE_P%d parameter value(%d), value should be [0..%d]", _port, _rpgHaiRate, (1 << 17) - 1); - return false; - } - - if (_rpgGd > 15) { - errmsg("Illegal RPG_GD_P%d parameters value(%d), value should be [0..%d]", _port, _rpgGd, 15); - return false; - } - - if (_rpgMinDecFac == 0 || _rpgMinDecFac > 100) { - errmsg("Illegal RPG_MIN_DEC_FAC_P%d parameters value(%d), value should be [1..100]", _port, _rpgMinDecFac); - return false; - } - - if (_rpgMinRate >= (1 << 17)) { - errmsg("Illegal RPG_MIN_RATE_P%d parameters value(%d), value should be [0..%d]", _port, _rpgMinRate, (1 << 17) - 1); - return false; - } - - if (_rateToSetOnFirstCnp >= (1 << 17)) { - errmsg("Illegal RATE_TO_SET_ON_FIRST_CNP_P%d parameters value(%d), value should be [0..%d]", _port, _rateToSetOnFirstCnp, (1 << 17) - 1); - return false; - } - - if (_dceTcpG == 0 || _dceTcpG >= (1 << 10)) { - errmsg("Illegal DCE_TCP_G_P%d parameters value(%d), value should be [1..%d]", _port, _dceTcpG, (1 << 10) - 1); - return false; - } - - if (_dceTcpRtt == 0 || _dceTcpRtt >= (1 << 17)) { - errmsg("Illegal DCE_TCP_RTT_P%d parameters value(%d), value should be [1..%d]", _port, _dceTcpRtt, (1 << 17) - 1); - return false; - } - - if (_rateReduceMonitorPeriod == 0 || _rateReduceMonitorPeriod >= (1 << 17)) { - errmsg("Illegal RATE_REDUCE_MONITOR_PERIOD_P%d parameters value(%d), value should be [1..%d]", _port, _rateReduceMonitorPeriod, (1 << 17) - 1); - return false; - } - - if (_initialAlphaValue >= (1 << 10)) { - errmsg("Illegal INITIAL_ALPHA_VALUE_P%d parameters value(%d), value should be [0..%d]", _port, _initialAlphaValue, (1 << 10) - 1); - return false; - } - - if (_minTimeBetweenCnps >= (1 << 17)) { - errmsg("Illegal MIN_TIME_BETWEEN_CNPS_P%d parameters value(%d), value should be [0..%d]", _port, _minTimeBetweenCnps, (1 << 17) - 1); - return false; - } - - if (_cnpDscp >= (1 << 6)) { - errmsg("Illegal CNP_DSCP_P%d parameters value(%d), value should be [0..%d]", _port, _cnpDscp, (1 << 6) - 1); - return false; - } - - if (_cnp802pPrio >= (1 << 3)) { - errmsg("Illegal CNP_802P_PRIO_P%d parameters value(%d), value should be [0..%d]", _port, _cnp802pPrio, (1 << 3) - 1); - return false; - } - return true; -} - -u_int32_t RoCECCEcnParams5thGen::getTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = tlvTypeIdx; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - - -void RoCECCEcnParams5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_roce_cc_ecn* roceCcEcnTlv = (struct tools_open_roce_cc_ecn*)tlv; - roceCcEcnTlv->clamp_tgt_rate = _clampTgtRate; - roceCcEcnTlv->clamp_tgt_rate_after_time_inc = _clampTgtRateAfterTimeInc; - roceCcEcnTlv->cnp_802p_prio = _cnp802pPrio; - roceCcEcnTlv->cnp_dscp = _cnpDscp; - roceCcEcnTlv->dce_tcp_g = _dceTcpG; - roceCcEcnTlv->dce_tcp_rtt = _dceTcpRtt; - roceCcEcnTlv->initial_alpha_value = _initialAlphaValue; - roceCcEcnTlv->min_time_between_cnps = _minTimeBetweenCnps; - roceCcEcnTlv->rate_reduce_monitor_period = _rateReduceMonitorPeriod; - roceCcEcnTlv->rate_to_set_on_first_cnp = _rateToSetOnFirstCnp; - roceCcEcnTlv->rpg_ai_rate = _rpgAiRate; - roceCcEcnTlv->rpg_byte_reset = _rpgByteReset; - roceCcEcnTlv->rpg_gd = _rpgGd; - roceCcEcnTlv->rpg_hai_rate = _rpgHaiRate; - roceCcEcnTlv->rpg_max_rate = _rpgMaxRate; - roceCcEcnTlv->rpg_min_dec_fac = _rpgMinDecFac; - roceCcEcnTlv->rpg_min_rate = _rpgMinRate; - roceCcEcnTlv->rpg_threshold = _rpgThreshold; - roceCcEcnTlv->rpg_time_reset = _rpgTimeReset; - return; -} - -void RoCECCEcnParams5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_roce_cc_ecn* roceCcEcnTlv = (struct tools_open_roce_cc_ecn*)tlv; - _clampTgtRate = roceCcEcnTlv->clamp_tgt_rate; - _clampTgtRateAfterTimeInc = roceCcEcnTlv->clamp_tgt_rate_after_time_inc; - _cnp802pPrio = roceCcEcnTlv->cnp_802p_prio; - _cnpDscp = roceCcEcnTlv->cnp_dscp; - _dceTcpG = roceCcEcnTlv->dce_tcp_g; - _dceTcpRtt = roceCcEcnTlv->dce_tcp_rtt; - _initialAlphaValue = roceCcEcnTlv->initial_alpha_value; - _minTimeBetweenCnps = roceCcEcnTlv->min_time_between_cnps; - _rateReduceMonitorPeriod = roceCcEcnTlv->rate_reduce_monitor_period; - _rateToSetOnFirstCnp = roceCcEcnTlv->rate_to_set_on_first_cnp; - _rpgAiRate = roceCcEcnTlv->rpg_ai_rate; - _rpgByteReset = roceCcEcnTlv->rpg_byte_reset; - _rpgGd = roceCcEcnTlv->rpg_gd; - _rpgHaiRate = roceCcEcnTlv->rpg_hai_rate; - _rpgMaxRate = roceCcEcnTlv->rpg_max_rate; - _rpgMinDecFac = roceCcEcnTlv->rpg_min_dec_fac; - _rpgMinRate = roceCcEcnTlv->rpg_min_rate; - _rpgThreshold = roceCcEcnTlv->rpg_threshold; - _rpgTimeReset = roceCcEcnTlv->rpg_time_reset; - return; -} - -void RoCECCEcnParams5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_roce_cc_ecn* roceCcEcnTlv = (struct tools_open_roce_cc_ecn*)tlv; - _clampTgtRateDefault = roceCcEcnTlv->clamp_tgt_rate; - _clampTgtRateAfterTimeIncDefault = roceCcEcnTlv->clamp_tgt_rate_after_time_inc; - _cnp802pPrioDefault = roceCcEcnTlv->cnp_802p_prio; - _cnpDscpDefault = roceCcEcnTlv->cnp_dscp; - _dceTcpGDefault = roceCcEcnTlv->dce_tcp_g; - _dceTcpRttDefault = roceCcEcnTlv->dce_tcp_rtt; - _initialAlphaValueDefault = roceCcEcnTlv->initial_alpha_value; - _minTimeBetweenCnpsDefault = roceCcEcnTlv->min_time_between_cnps; - _rateReduceMonitorPeriodDefault = roceCcEcnTlv->rate_reduce_monitor_period; - _rateToSetOnFirstCnpDefault = roceCcEcnTlv->rate_to_set_on_first_cnp; - _rpgAiRateDefault = roceCcEcnTlv->rpg_ai_rate; - _rpgByteResetDefault = roceCcEcnTlv->rpg_byte_reset; - _rpgGdDefault = roceCcEcnTlv->rpg_gd; - _rpgHaiRateDefault = roceCcEcnTlv->rpg_hai_rate; - _rpgMaxRateDefault = roceCcEcnTlv->rpg_max_rate; - _rpgMinDecFacDefault = roceCcEcnTlv->rpg_min_dec_fac; - _rpgMinRateDefault = roceCcEcnTlv->rpg_min_rate; - _rpgThresholdDefault = roceCcEcnTlv->rpg_threshold; - _rpgTimeResetDefault = roceCcEcnTlv->rpg_time_reset; - return; -} - -/* - * PrebootBootSettingsParams4thGen Class implementation: - */ - -bool PrebootBootSettingsParams4thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - (void)param; - struct tools_open_query_def_params_per_port portParams; - int rc; - rc = getDefaultParams4thGen(mf, _port, &portParams); - if (rc) { - return false; - } - return true; //portParams.nv_config_boot_parameters; <--BUG fw is not updating this bit, assume supported if query_def_params command passess -} - -void PrebootBootSettingsParams4thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if ((paramType == Mcp_Boot_Option_Rom_En_P1 && _port == 1) || (paramType == Mcp_Boot_Option_Rom_En_P2 && _port == 2)) { - _bootOptionRomEn = val; - } - - if ((paramType == Mcp_Boot_Vlan_En_P1 && _port == 1) || (paramType == Mcp_Boot_Vlan_En_P2 && _port == 2)) { - _bootVlanEn = val; - } - - if ((paramType == Mcp_Boot_Retry_Cnt_P1 && _port == 1) || (paramType == Mcp_Boot_Retry_Cnt_P2 && _port == 2)) { - _bootRetryCnt = val; - } - - if ((paramType == Mcp_Legacy_Boot_Protocol_P1 && _port == 1) || (paramType == Mcp_Legacy_Boot_Protocol_P2 && _port == 2)) { - _legacyBootProtocol = val; - } - - if ((paramType == Mcp_Boot_Vlan_P1 && _port == 1) || (paramType == Mcp_Boot_Vlan_P2 && _port == 2)) { - _bootVlan = val; - } -} - -u_int32_t PrebootBootSettingsParams4thGen::getParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Boot_Option_Rom_En_P1 && _port == 1) || (paramType == Mcp_Boot_Option_Rom_En_P2 && _port == 2)) { - return _bootOptionRomEn; - } - - if ((paramType == Mcp_Boot_Vlan_En_P1 && _port == 1) || (paramType == Mcp_Boot_Vlan_En_P2 && _port == 2)) { - return _bootVlanEn; - } - - if ((paramType == Mcp_Boot_Retry_Cnt_P1 && _port == 1) || (paramType == Mcp_Boot_Retry_Cnt_P2 && _port == 2)) { - return _bootRetryCnt; - } - - if ((paramType == Mcp_Legacy_Boot_Protocol_P1 && _port == 1) || (paramType == Mcp_Legacy_Boot_Protocol_P2 && _port == 2)) { - return _legacyBootProtocol; - } - - if ((paramType == Mcp_Boot_Vlan_P1 && _port == 1) || (paramType == Mcp_Boot_Vlan_P2 && _port == 2)) { - return _bootVlan; - } - - return MLXCFG_UNKNOWN; -} - -u_int32_t PrebootBootSettingsParams4thGen::getDefaultParam(mlxCfgParam paramType) -{ - if ((paramType == Mcp_Boot_Option_Rom_En_P1 && _port == 1) || (paramType == Mcp_Boot_Option_Rom_En_P2 && _port == 2)) { - return _bootOptionRomEnDefault; - } - - if ((paramType == Mcp_Boot_Vlan_En_P1 && _port == 1) || (paramType == Mcp_Boot_Vlan_En_P2 && _port == 2)) { - return _bootVlanEnDefault; - } - - if ((paramType == Mcp_Boot_Retry_Cnt_P1 && _port == 1) || (paramType == Mcp_Boot_Retry_Cnt_P2 && _port == 2)) { - return _bootRetryCntDefault; - } - - if ((paramType == Mcp_Legacy_Boot_Protocol_P1 && _port == 1) || (paramType == Mcp_Legacy_Boot_Protocol_P2 && _port == 2)) { - return _legacyBootProtocolDefault; - } - - if ((paramType == Mcp_Boot_Vlan_P1 && _port == 1) || (paramType == Mcp_Boot_Vlan_P2 && _port == 2)) { - return _bootVlanDefault; - } - - return MLXCFG_UNKNOWN; -} - -void PrebootBootSettingsParams4thGen::setParams(u_int32_t bootOptionRomEn, u_int32_t bootVlanEn, u_int32_t bootRetryCnt, - u_int32_t legacyBootProtocol, u_int32_t bootVlan) -{ - _bootOptionRomEn = bootOptionRomEn; - _bootVlanEn = bootVlanEn; - _bootRetryCnt = bootRetryCnt; - _legacyBootProtocol = legacyBootProtocol; - _bootVlan = bootVlan; -} - -void PrebootBootSettingsParams4thGen::updateClassAttrFromDefaultParams() -{ - setParams(_bootOptionRomEnDefault, _bootVlanEnDefault, _bootRetryCntDefault, - _legacyBootProtocolDefault, _bootVlanDefault); -} - -int PrebootBootSettingsParams4thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_4TH_GEN(mf, tools_open_preboot_boot_settings, "Preboot Boot Settings", _port); -} - -int PrebootBootSettingsParams4thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_4TH_GEN(mf, ignoreCheck, tools_open_preboot_boot_settings, "Preboot Boot Settings", _port); -} - -void PrebootBootSettingsParams4thGen::updateTlvFromClassAttr(void* tlv) -{ - - struct tools_open_preboot_boot_settings* prebootTlv = (struct tools_open_preboot_boot_settings*)tlv; - prebootTlv->boot_option_rom_en = _bootOptionRomEn; - prebootTlv->boot_vlan_en = _bootVlanEn; - prebootTlv->boot_retry_count = _bootRetryCnt; - prebootTlv->legacy_boot_protocol = _legacyBootProtocol; - prebootTlv->boot_vlan = _bootVlan; - -} - -void PrebootBootSettingsParams4thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_preboot_boot_settings* prebootTlv = (struct tools_open_preboot_boot_settings*)tlv; - _bootOptionRomEn = prebootTlv->boot_option_rom_en; - _bootVlanEn = prebootTlv->boot_vlan_en; - _bootRetryCnt = prebootTlv->boot_retry_count; - _legacyBootProtocol = prebootTlv->legacy_boot_protocol; - _bootVlan = prebootTlv->boot_vlan; -} - -void PrebootBootSettingsParams4thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_preboot_boot_settings* prebootTlv = (struct tools_open_preboot_boot_settings*)tlv; - _bootOptionRomEnDefault = prebootTlv->boot_option_rom_en; - _bootVlanEnDefault = prebootTlv->boot_vlan_en; - _bootRetryCntDefault = prebootTlv->boot_retry_count; - _legacyBootProtocolDefault = prebootTlv->legacy_boot_protocol; - _bootVlanDefault = prebootTlv->boot_vlan; -} - -int PrebootBootSettingsParams4thGen::getDefaultParams(mfile* mf) -{ - struct tools_open_query_def_params_per_port portParams; - int rc; - rc = getDefaultParams4thGen(mf, _port, &portParams); - if (rc == MCE_SUCCESS) { - _bootOptionRomEnDefault = portParams.default_boot_option_rom_en; - _bootVlanEnDefault = portParams.default_boot_vlan_en; - _bootRetryCntDefault = portParams.default_boot_retry_cnt; - _legacyBootProtocolDefault = portParams.default_boot_protocol; - _bootVlanDefault = portParams.default_boot_vlan; - updateClassAttrFromDefaultParams(); - } else { - rc = MCE_GET_DEFAULT_PARAMS; - } - return rc; -} - -bool PrebootBootSettingsParams4thGen::hardLimitCheck() -{ - if (_bootOptionRomEn > 1) { - errmsg("Illegal BOOT_OPTION_ROM_EN_P%d parameter value, valid values: 0 or 1", ((_port == 1) ? 1 : 2)); - return false; - } - if (_bootVlanEn > 1) { - errmsg("Illegal BOOT_VLAN_EN_P%d parameter value, valid values: 0 or 1", ((_port == 1) ? 1 : 2)); - return false; - } - if (_bootRetryCnt > 7) { - errmsg("Illegal BOOT_RETRY_CNT_P%d parameter value, valid values: [0..7]", ((_port == 1) ? 1 : 2)); - return false; - } - if (_legacyBootProtocol > 3) { - errmsg("Illegal LEGACY_BOOT_PROTOCOL_P%d parameter value, valid values: [0..3]", ((_port == 1) ? 1 : 2)); - return false; - } - if (_bootVlan >= (1 << 12)) { - errmsg("Illegal BOOT_VLAN_P%d parameter value, valid values: [0..4095]", ((_port == 1) ? 1 : 2)); - return false; - } - return true; -} - -/* - * ExternalPort5thGen Class implementation - */ - - -bool ExternalPort5thGen::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get External Port parameter capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - return true; -} - -void ExternalPort5thGen::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_Port_Owner) { - _portOwner = val; - } - if (paramType == Mcp_Allow_Rd_Counters) { - _allowRdCounters = val; - } - return; -} - -u_int32_t ExternalPort5thGen::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Port_Owner) { - return _portOwner; - } - if (paramType == Mcp_Allow_Rd_Counters) { - return _allowRdCounters; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t ExternalPort5thGen::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_Port_Owner) { - return _portOwnerDefault; - } - if (paramType == Mcp_Allow_Rd_Counters) { - return _allowRdCountersDefault; - } - return MLXCFG_UNKNOWN; -} - -void ExternalPort5thGen::setParams(u_int32_t portOwner, u_int32_t allowRdCounters) -{ - _portOwner = portOwner; - _allowRdCounters = allowRdCounters; -} - -void ExternalPort5thGen::updateClassAttrFromDefaultParams() -{ - setParams( - _portOwnerDefault, - _allowRdCounters); -} - -int ExternalPort5thGen::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_external_port, "External Port"); -} - -int ExternalPort5thGen::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_external_port, "External Port"); -} -int ExternalPort5thGen::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_external_port, "External Port"); -} - -bool ExternalPort5thGen::hardLimitCheck() -{ - if (_portOwner > 1) { - errmsg("Illegal PORT_OWNER parameter value(%d), value should be 0 or 1", _portOwner); - return false; - } - if (_allowRdCounters > 1) { - errmsg("Illegal ALLOW_RD_COUNTERS parameter value(%d), value should be 0 or 1", _allowRdCounters); - return false; - } - return true; -} - -u_int32_t ExternalPort5thGen::getTlvTypeBe() -{ - struct tools_open_per_host_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PER_HOST; - type.param_idx = tlvTypeIdx; - type.function = 0; - type.host = 0; - tools_open_per_host_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void ExternalPort5thGen::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_external_port* externalPortTlv = (struct tools_open_external_port*)tlv; - externalPortTlv->port_owner = _portOwner; - externalPortTlv->allow_rd_counters = _allowRdCounters; - return; -} - -void ExternalPort5thGen::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_external_port* externalPortTlv = (struct tools_open_external_port*)tlv; - _portOwner = externalPortTlv->port_owner; - _allowRdCounters = externalPortTlv->allow_rd_counters; - return; -} - -void ExternalPort5thGen::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_external_port* externalPortTlv = (struct tools_open_external_port*)tlv; - _portOwnerDefault = externalPortTlv->port_owner; - _allowRdCountersDefault = externalPortTlv->allow_rd_counters; - return; -} - -/* - * QoS Class implementation - */ - -bool QoS::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get QoS capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - - if (!getCap(mf)) { - return false; - } - - return true; -} - -void QoS::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_QoS_Num_of_TC_P1 || paramType == Mcp_QoS_Num_of_TC_P2) { - _numOfTC = val; - } - - if (paramType == Mcp_QoS_Num_of_VL_P1 || paramType == Mcp_QoS_Num_of_VL_P2) { - _numOfVL = val; - } - return; -} - -u_int32_t QoS::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_QoS_Num_of_TC_P1 || paramType == Mcp_QoS_Num_of_TC_P2) { - return _numOfTC; - } - if (paramType == Mcp_QoS_Num_of_VL_P1 || paramType == Mcp_QoS_Num_of_VL_P2) { - return _numOfVL; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t QoS::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_QoS_Num_of_TC_P1 || paramType == Mcp_QoS_Num_of_TC_P2) { - return _numOfTCDefault; - } - if (paramType == Mcp_QoS_Num_of_VL_P1 || paramType == Mcp_QoS_Num_of_VL_P2) { - return _numOfVLDefault; - } - return MLXCFG_UNKNOWN; -} - -void QoS::setParams(u_int32_t numOfTC, u_int32_t numOfVL) -{ - _numOfTC = numOfTC; - _numOfVL = numOfVL; -} - -void QoS::updateClassAttrFromDefaultParams() -{ - setParams( - _numOfTC, - _numOfVL); -} - -int QoS::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_qos, "QoS Conf"); -} - -int QoS::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_qos, "QoS Conf"); -} - -int QoS::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_qos, "QoS Conf"); -} - -bool QoS::getCap(mfile *mf) -{ - MError rc; - u_int8_t tlvCapBuff[TOOLS_OPEN_QOS_CAP_SIZE] = {0}; - struct tools_open_qos_cap qosCapTlv; - memset(&qosCapTlv, 0, sizeof(qosCapTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_QOS_CAP_SIZE, getQoSCapTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return false; - } - tools_open_qos_cap_unpack(&qosCapTlv, tlvCapBuff); - _maxNumOfTC = qosCapTlv.max_num_of_tc; - _maxNumOfVL = qosCapTlv.max_num_of_vl; - return true; -} - -bool QoS::hardLimitCheckAux(u_int32_t maxNumOfX, u_int32_t numOfX,const char *x) -{ - u_int32_t minVal; - u_int32_t maxVal; - // 0 and 8 have the same maxNumOfX meaning (they both indicate max 8 TCs which translates to the value 0) - minVal = (maxNumOfX == 0 || maxNumOfX >= 8) ? 0 : 1; - maxVal = (maxNumOfX == 0 || maxNumOfX == 8) ? 7 : maxNumOfX; - if ((numOfX < minVal) || numOfX > maxVal) { - errmsg("Illegal %s parameter value(%d), max allowed value is (%d), min allowed value is (%d)", - x, - numOfX, - maxVal, - minVal); - return false; - } - - return true; -} - -bool QoS::hardLimitCheck() -{ - if(!hardLimitCheckAux(_maxNumOfTC, _numOfTC, _port == 1 ? "NUM_OF_TC_P1" : "NUM_OF_TC_P2")) { - return false; - } - - if(_numOfVL < 1 || _numOfVL > _maxNumOfVL){ - errmsg("Illegal %s parameter value(%x), max allowed value is (%x), min allowed value is (%x)", - _port == 1 ? "NUM_OF_VL_P1" : "NUM_OF_VL_P2", - _numOfVL, - _maxNumOfVL, - 1); - return false; - } - - return true; -} - -u_int32_t QoS::getTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = tlvTypeIdx; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void QoS::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_qos* qosPortTlv = (struct tools_open_qos*)tlv; - qosPortTlv->num_of_tc = _numOfTC; - qosPortTlv->num_of_vl = _numOfVL; - return; -} - -void QoS::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_qos* qosPortTlv = (struct tools_open_qos*)tlv; - _numOfTC = qosPortTlv->num_of_tc; - _numOfVL = qosPortTlv->num_of_vl; - return; -} - -void QoS::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_qos* qosPortTlv = (struct tools_open_qos*)tlv; - _numOfTCDefault = qosPortTlv->num_of_tc; - _numOfVLDefault = qosPortTlv->num_of_vl; - return; -} - -u_int32_t QoS::getQoSCapTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = QOS_CAP; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - - -/* - * LLDP Client Settings Class implementation - */ - -bool LLDPClientSettings::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get LLDP Client Settings capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - - if (!getCap(mf)) { - return false; - } - - return true; -} - -void LLDPClientSettings::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_LLDP_NB_RX_Mode_P1|| paramType == Mcp_LLDP_NB_RX_Mode_P2) { - _userSpecifiedRx = true; - _lldpNbRxMode = val; - } - if (paramType == Mcp_LLDP_NB_TX_Mode_P1|| paramType == Mcp_LLDP_NB_TX_Mode_P2) { - _userSpecifiedTx = true; - _lldpNbTxMode = val; - } - if (paramType == Mcp_LLDP_NB_DCBX_P1|| paramType == Mcp_LLDP_NB_DCBX_P2) { - _userSpecifiedDcbx = true; - _lldpNbDcbx = val; - } - return; -} - -u_int32_t LLDPClientSettings::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_LLDP_NB_RX_Mode_P1|| paramType == Mcp_LLDP_NB_RX_Mode_P2) { - return _lldpNbRxMode; - } - if (paramType == Mcp_LLDP_NB_TX_Mode_P1|| paramType == Mcp_LLDP_NB_TX_Mode_P2) { - return _lldpNbTxMode; - } - if (paramType == Mcp_LLDP_NB_DCBX_P1|| paramType == Mcp_LLDP_NB_DCBX_P2) { - return _lldpNbDcbx; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t LLDPClientSettings::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_LLDP_NB_RX_Mode_P1|| paramType == Mcp_LLDP_NB_RX_Mode_P2) { - return _lldpNbRxModeDefault; - } - if (paramType == Mcp_LLDP_NB_TX_Mode_P1|| paramType == Mcp_LLDP_NB_TX_Mode_P2) { - return _lldpNbTxModeDefault; - } - if (paramType == Mcp_LLDP_NB_DCBX_P1|| paramType == Mcp_LLDP_NB_DCBX_P2) { - return _lldpNbDcbxDefault; - } - return MLXCFG_UNKNOWN; -} - -void LLDPClientSettings::setParams(u_int32_t lldpNbRxMode, u_int32_t lldpNbTxMode, u_int32_t lldpNbDcbx) -{ - _lldpNbRxMode = lldpNbRxMode; - _lldpNbTxMode = lldpNbTxMode; - _lldpNbDcbx = lldpNbDcbx; -} - -void LLDPClientSettings::updateClassAttrFromDefaultParams() -{ - setParams( - _lldpNbRxModeDefault, - _lldpNbTxModeDefault, - _lldpNbDcbxDefault); -} - -int LLDPClientSettings::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_lldp_client_settings, "LLDP Client Settings"); -} - -int LLDPClientSettings::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_lldp_client_settings, "LLDP Client Settings"); -} - -int LLDPClientSettings::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_lldp_client_settings, "LLDP Client Settings"); -} - -bool LLDPClientSettings::getCap(mfile *mf) -{ - MError rc; - u_int8_t tlvCapBuff[TOOLS_OPEN_LLDP_NB_CAP_SIZE] = {0}; - struct tools_open_lldp_nb_cap lldpNbCapTlv; - memset(&lldpNbCapTlv, 0, sizeof(lldpNbCapTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_LLDP_NB_CAP_SIZE, getLLDPNBCapTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return false; - } - tools_open_lldp_nb_cap_unpack(&lldpNbCapTlv, tlvCapBuff); - _lldpNbTxCap = lldpNbCapTlv.lldp_nb_tx_cap; - _lldpNbRxCap = lldpNbCapTlv.lldp_nb_rx_cap; - _lldpNbDcbxEn = lldpNbCapTlv.lldp_nb_dcbx_en; - return true; -} - -bool LLDPClientSettings::hardLimitCheck() -{ - if (_userSpecifiedRx && _lldpNbRxCap == 0) { - errmsg("The LLDP_NB_RX_MODE parameter cannot be set"); - return false; - } - - if (_lldpNbRxMode > _lldpNbRxCap) { - errmsg("Illegal LLDP_NB_RX_MODE parameter value(%d), max allowed value is (%d)", _lldpNbRxMode, _lldpNbRxCap); - return false; - } - - if (_userSpecifiedTx && _lldpNbTxCap == 0) { - errmsg("The LLDP_NB_TX_MODE parameter cannot be set"); - return false; - } - - if (_lldpNbTxMode > _lldpNbTxCap) { - errmsg("Illegal LLDP_NB_TX_MODE parameter value(%d), max allowed value is (%d)", _lldpNbTxMode, _lldpNbTxCap); - return false; - } - - if (_userSpecifiedDcbx && _lldpNbDcbxEn == 0) { - errmsg("LLDP_NB_RX_MODE parameter can not be set."); - return false; - } - - if (_lldpNbDcbx > 1) { - errmsg("Illegal LLDP_NB_RX_MODE parameter value(%d), value must be False(0) or True(1)", _lldpNbDcbx); - return false; - } - - return true; -} - -u_int32_t LLDPClientSettings::getTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = tlvTypeIdx; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void LLDPClientSettings::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_lldp_client_settings* lldpClientSettingsPortTlv = (struct tools_open_lldp_client_settings*)tlv; - lldpClientSettingsPortTlv->lldp_nb_dcbx = _lldpNbDcbx; - lldpClientSettingsPortTlv->lldp_nb_rx_mode = _lldpNbRxMode; - lldpClientSettingsPortTlv->lldp_nb_tx_mode = _lldpNbTxMode; - return; -} - -void LLDPClientSettings::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_lldp_client_settings* lldpClientSettingsPortTlv = (struct tools_open_lldp_client_settings*)tlv; - _lldpNbDcbx = lldpClientSettingsPortTlv->lldp_nb_dcbx; - _lldpNbRxMode = lldpClientSettingsPortTlv->lldp_nb_rx_mode; - _lldpNbTxMode = lldpClientSettingsPortTlv->lldp_nb_tx_mode; - return; -} - -void LLDPClientSettings::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_lldp_client_settings* lldpClientSettingsPortTlv = (struct tools_open_lldp_client_settings*)tlv; - _lldpNbDcbxDefault = lldpClientSettingsPortTlv->lldp_nb_dcbx; - _lldpNbRxModeDefault = lldpClientSettingsPortTlv->lldp_nb_rx_mode; - _lldpNbTxModeDefault = lldpClientSettingsPortTlv->lldp_nb_tx_mode; - return; -} - -u_int32_t LLDPClientSettings::getLLDPNBCapTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = LLDP_NB_CAPABILITIES_TYPE; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - - -/* - * LLDP NB DCBX Class implementation - */ - -bool DCBX::cfgSupported(mfile* mf, mlxCfgParam param) -{ - MError rc; - (void)param; - bool suppRead, suppWrite; - rc = nvqcCom5thGen(mf, getTlvTypeBe(), suppRead, suppWrite); - if (rc) { - errmsg("Failed to get LLDP NB DCBX capabilities. %s", m_err2str(rc)); - return false; - } - if (!suppRead || !suppWrite) { - return false; - } - - if (!getCap(mf)) { - return false; - } - - return true; -} - -void DCBX::setParam(mlxCfgParam paramType, u_int32_t val) -{ - if (paramType == Mcp_DCBX_IEEE_EN_P1|| paramType == Mcp_DCBX_IEEE_EN_P2) { - _ieee = val; - } - if (paramType == Mcp_DCBX_CEE_EN_P1|| paramType == Mcp_DCBX_CEE_EN_P2) { - _cee = val; - } - if (paramType == Mcp_DCBX_WILLING_P1|| paramType == Mcp_DCBX_WILLING_P2) { - _willing = val; - } - return; -} - -u_int32_t DCBX::getParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_DCBX_IEEE_EN_P1|| paramType == Mcp_DCBX_IEEE_EN_P2) { - return _ieee; - } - if (paramType == Mcp_DCBX_CEE_EN_P1|| paramType == Mcp_DCBX_CEE_EN_P2) { - return _cee; - } - if (paramType == Mcp_DCBX_WILLING_P1|| paramType == Mcp_DCBX_WILLING_P2) { - return _willing; - } - return MLXCFG_UNKNOWN; -} - -u_int32_t DCBX::getDefaultParam(mlxCfgParam paramType) -{ - if (paramType == Mcp_DCBX_IEEE_EN_P1|| paramType == Mcp_DCBX_IEEE_EN_P2) { - return _ieeeDefault; - } - if (paramType == Mcp_DCBX_CEE_EN_P1|| paramType == Mcp_DCBX_CEE_EN_P2) { - return _ceeDefault; - } - if (paramType == Mcp_DCBX_WILLING_P1|| paramType == Mcp_DCBX_WILLING_P2) { - return _willingDefault; - } - return MLXCFG_UNKNOWN; -} - -void DCBX::setParams(u_int32_t ieee, u_int32_t cee, u_int32_t willing) -{ - _ieee = ieee; - _cee = cee; - _willing = willing; -} - -void DCBX::updateClassAttrFromDefaultParams() -{ - setParams( - _ieeeDefault, - _ceeDefault, - _willingDefault); -} - -int DCBX::getFromDev(mfile* mf) -{ - GET_FROM_DEV_5TH_GEN(mf, tools_open_lldp_nb_dcbx, "LLDP NB DCBX"); -} - -int DCBX::setOnDev(mfile* mf, bool ignoreCheck) -{ - SET_ON_DEV_5TH_GEN(mf, ignoreCheck, tools_open_lldp_nb_dcbx, "LLDP NB DCBX"); -} - -int DCBX::getDefaultParams(mfile* mf) -{ - GET_DEFAULT_5TH_GEN(mf, tools_open_lldp_nb_dcbx, "LLDP NB DCBX"); -} - -bool DCBX::hardLimitCheck() -{ - if (_lldpNbDcbxEn == 0) { - errmsg("DCBX parameters cannot be set"); - return false; - } - if (_ieee > 1) { - errmsg("Illegal %s parameter value(%d)", _port == 1 ? - "DCBX_IEEE_P1" : "DCBX_IEEE_P2", _ieee); - return false; - } - if (_cee > 1) { - errmsg("Illegal %s parameter value(%d)", _port == 1 ? - "DCBX_CEE_P1" : "DCBX_CEE_P2", _cee); - return false; - } - if (_willing > 1) { - errmsg("Illegal %s parameter value(%d)", _port == 1 ? - "DCBX_WILLING_P1" : "DCBX_WILLING_P2", _willing); - return false; - } - return true; -} - -u_int32_t DCBX::getTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = tlvTypeIdx; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -u_int32_t DCBX::getLLDPNBCapTlvTypeBe() -{ - struct tools_open_per_port_type type; - u_int32_t tlvType = 0; - type.param_class = CLASS_PHYS_PORT; - type.param_idx = LLDP_NB_CAPABILITIES_TYPE; - type.port = _port; - tools_open_per_port_type_pack(&type, (u_int8_t*)&tlvType); - return tlvType; -} - -void DCBX::updateTlvFromClassAttr(void* tlv) -{ - struct tools_open_lldp_nb_dcbx* DCBXPortTlv = (struct tools_open_lldp_nb_dcbx*)tlv; - DCBXPortTlv->ieee_dcbx_en = _ieee; - DCBXPortTlv->cee_dcbx_en = _cee; - DCBXPortTlv->dcbx_willing = _willing; - return; -} - -void DCBX::updateClassAttrFromTlv(void* tlv) -{ - struct tools_open_lldp_nb_dcbx* lldpClientSettingsPortTlv = (struct tools_open_lldp_nb_dcbx*)tlv; - _ieee = lldpClientSettingsPortTlv->ieee_dcbx_en; - _cee = lldpClientSettingsPortTlv->cee_dcbx_en; - _willing = lldpClientSettingsPortTlv->dcbx_willing; - return; -} - -void DCBX::updateClassDefaultAttrFromTlv(void* tlv) -{ - struct tools_open_lldp_nb_dcbx* lldpClientSettingsPortTlv = (struct tools_open_lldp_nb_dcbx*)tlv; - _ieeeDefault = lldpClientSettingsPortTlv->ieee_dcbx_en; - _ceeDefault = lldpClientSettingsPortTlv->cee_dcbx_en; - _willingDefault = lldpClientSettingsPortTlv->dcbx_willing; - return; -} - -bool DCBX::getCap(mfile *mf) -{ - MError rc; - u_int8_t tlvCapBuff[TOOLS_OPEN_LLDP_NB_CAP_SIZE] = {0}; - struct tools_open_lldp_nb_cap lldpNbCapTlv; - memset(&lldpNbCapTlv, 0, sizeof(lldpNbCapTlv)); - rc = mnvaCom5thGen(mf, &tlvCapBuff[0], TOOLS_OPEN_LLDP_NB_CAP_SIZE, getLLDPNBCapTlvTypeBe(), REG_ACCESS_METHOD_GET); - if (rc) { - return false; - } - tools_open_lldp_nb_cap_unpack(&lldpNbCapTlv, tlvCapBuff); - _lldpNbDcbxEn = lldpNbCapTlv.lldp_nb_dcbx_en; - return true; -} diff --git a/mlxconfig/mlxcfg_param_lib.h b/mlxconfig/mlxcfg_param_lib.h deleted file mode 100644 index 7eeec44..0000000 --- a/mlxconfig/mlxcfg_param_lib.h +++ /dev/null @@ -1,1227 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -/* - * mlxcfg_param_lib.h - * - * Created on: Mar 22, 2015 - * Author: adrianc - */ - -#ifndef MLXCFG_PARAM_LIB_H_ -#define MLXCFG_PARAM_LIB_H_ - -#include -#include -#include - -#include -#include - -#define MLXCFG_UNKNOWN 0xffffffff - -#define WOL_TYPE 0x10 -#define SRIOV_TYPE 0x11 -#define VPI_TYPE 0x12 -#define BAR_SIZE_TYPE 0x13 -#define PCI_SETTINGS_TYPE 0x80 -#define PCI_CAPABILITES_TYPE 0x81 -#define TPT_SETTINGS_TYPE 0x82 -#define TPT_CAPABILITES_TYPE 0x83 -#define PREBOOT_BOOT_SETTINGS_TYPE 0x2021 -#define INFINIBAND_BOOT_SETTINGS_TYPE 0x2022 -#define INFINIBAND_DC_SETTINGS_TYPE 0x190 -#define INFINIBAND_DC_CAPABILITIES_TYPE 0x191 -#define PORT_BOOT_STATE_TYPE 0x84 -#define ROCE_NEXT_PROTOCOL_TYPE 0x10 -#define ROCE_CC_TYPE 0x107 -#define ROCE_CC_ECN_TYPE 0x108 -#define LLDP_CLIENT_SETTINGS_TYPE 0x10a -#define LLDP_NB_CAPABILITIES_TYPE 0x10b -#define EXTERNAL_PORT 0x192 -#define BOOT_SETTINGS_EXTRAS_GEN4 0x2001 -#define BOOT_SETTINGS_EXTRAS_GEN5 0x195 -#define BOOT_SETTINGS_EXTRAS_GEN5_CAP 0x101 -#define QOS 0x192 -#define QOS_CAP 0x193 -#define LLDP_NB_DCBX 0x18E - -typedef enum { - // SRIOV - Mct_Sriov = 0, - // Wake on LAN (4th gen) - Mct_Wol_P1, - Mct_Wol_P2, - // Wake on LAN (5th gen) - Mct_Wol, - // VPI settings - Mct_Vpi_P1, - Mct_Vpi_P2, - // BAR size (4th gen) - Mct_Bar_Size, - // PCI settings (5th gen) - Mct_Pci, - // TPT settings (5th gen) - Mct_Tpt, - // IB boot settings (4th gen) - Mct_Boot_Settings_P1, - Mct_Boot_Settings_P2, - // IB dynamically connected (5th gen) - Mct_Dc, - // RoCE v1.5 next protocol (5th gen) - Mct_RoCE_Next_Protocol, - // RoCE congestion control (5th gen) - Mct_RoCE_CC_P1, - Mct_RoCE_CC_P2, - // RoCE congestion control ECN (5th gen) - Mct_RoCE_CC_Ecn_P1, - Mct_RoCE_CC_Ecn_P2, - // Preboot Boot Settings (4th Gen) - Mct_Preboot_Boot_Settings_P1, - Mct_Preboot_Boot_Settings_P2, - Mct_External_Port, - //TODO: Boot Settings Extras - Mct_Boot_Settings_Extras_5thGen, - Mct_Boot_Settings_Extras_4thGen_P1, - Mct_Boot_Settings_Extras_4thGen_P2, - Mct_QoS_P1, - Mct_QoS_P2, - Mct_LLDP_Client_Settings_P1, - Mct_LLDP_Client_Settings_P2, - Mct_DCBX_P1, - Mct_DCBX_P2, - Mct_Last -} mlxCfgType; - -typedef enum { - // PCI settings - Mcp_Sriov_En = 0, - Mcp_Num_Of_Vfs, - Mcp_Fpp_En, - Mcp_PF_Log_Bar_Size, - Mcp_VF_Log_Bar_Size, - Mcp_Num_Pf_Msix, - Mcp_Num_Vf_Msix, - // Wake On LAN 4th Gen Port 1 - Mcp_Wol_Magic_En_P1, - // Wake On LAN 4th Gen Port 2 - Mcp_Wol_Magic_En_P2, - // Wake On LAN 5th Gen - Mcp_Wol_Magic_En, - // VPI settings Port 1 - Mcp_Link_Type_P1, - // VPI settings Port 2 - Mcp_Link_Type_P2, - // BAR size - Mcp_Log_Bar_Size, - // TPT settings - Mcp_Log_Tpt_Size, - // Boot Pkey Port 1 - Mcp_Boot_Pkey_P1, - // Boot Pkey Port 2 - Mcp_Boot_Pkey_P2, - // IB Dynamically connected - Mcp_Log_Dcr_Hash_Table_Size, - Mcp_Dcr_Lifo_Size, - // RoCE v1.5 Next protocol - Mcp_RoCE_Next_Protocol, - // RoCE Congestion Control Parameters Port 1 - Mcp_RoCE_CC_Algorithm_P1, - Mcp_RoCE_CC_Prio_Mask_P1, - // RoCE Congestion Control Parameters Port 2 - Mcp_RoCE_CC_Algorithm_P2, - Mcp_RoCE_CC_Prio_Mask_P2, - // RoCE Congestion Control ECN Port 1 - Mcp_Clamp_Tgt_Rate_P1, - Mcp_Clamp_Tgt_Rate_After_Time_Inc_P1, - Mcp_Rpg_Time_Reset_P1, - Mcp_Rpg_Byte_Reset_P1, - Mcp_Rpg_Threshold_P1, - Mcp_Rpg_Max_Rate_P1, - Mcp_Rpg_Ai_Rate_P1, - Mcp_Rpg_Hai_Rate_P1, - Mcp_Rpg_Gd_P1, - Mcp_Rpg_Min_Dec_Fac_P1, - Mcp_Rpg_Min_Rate_P1, - Mcp_Rate_To_Set_On_First_Cnp_P1, - Mcp_Dce_Tcp_G_P1, - Mcp_Dce_Tcp_Rtt_P1, - Mcp_Rate_Reduce_Monitor_Period_P1, - Mcp_Initial_Alpha_Value_P1, - Mcp_Min_Time_Between_Cnps_P1, - Mcp_Cnp_Dscp_P1, - Mcp_Cnp_802p_Prio_P1, - // RoCE Congestion Control ECN Port 2 - Mcp_Clamp_Tgt_Rate_P2, - Mcp_Clamp_Tgt_Rate_After_Time_Inc_P2, - Mcp_Rpg_Time_Reset_P2, - Mcp_Rpg_Byte_Reset_P2, - Mcp_Rpg_Threshold_P2, - Mcp_Rpg_Max_Rate_P2, - Mcp_Rpg_Ai_Rate_P2, - Mcp_Rpg_Hai_Rate_P2, - Mcp_Rpg_Gd_P2, - Mcp_Rpg_Min_Dec_Fac_P2, - Mcp_Rpg_Min_Rate_P2, - Mcp_Rate_To_Set_On_First_Cnp_P2, - Mcp_Dce_Tcp_G_P2, - Mcp_Dce_Tcp_Rtt_P2, - Mcp_Rate_Reduce_Monitor_Period_P2, - Mcp_Initial_Alpha_Value_P2, - Mcp_Min_Time_Between_Cnps_P2, - Mcp_Cnp_Dscp_P2, - Mcp_Cnp_802p_Prio_P2, - // Preboot Boot Settings Port 1 - Mcp_Boot_Option_Rom_En_P1, - Mcp_Boot_Vlan_En_P1, - Mcp_Boot_Retry_Cnt_P1, - Mcp_Legacy_Boot_Protocol_P1, - Mcp_Boot_Vlan_P1, - // Preboot Boot Settings Port 2 - Mcp_Boot_Option_Rom_En_P2, - Mcp_Boot_Vlan_En_P2, - Mcp_Boot_Retry_Cnt_P2, - Mcp_Legacy_Boot_Protocol_P2, - Mcp_Boot_Vlan_P2, - //External port - Mcp_Port_Owner, - Mcp_Allow_Rd_Counters, - //Boot Settings Ext - Mcp_Boot_Settings_Ext_IP_Ver, - Mcp_Boot_Settings_Ext_IP_Ver_P1, - Mcp_Boot_Settings_Ext_IP_Ver_P2, - Mcp_QoS_Num_of_TC_P1, - Mcp_QoS_Num_of_VL_P1, - Mcp_QoS_Num_of_TC_P2, - Mcp_QoS_Num_of_VL_P2, - Mcp_LLDP_NB_RX_Mode_P1, - Mcp_LLDP_NB_TX_Mode_P1, - Mcp_LLDP_NB_DCBX_P1, - Mcp_LLDP_NB_RX_Mode_P2, - Mcp_LLDP_NB_TX_Mode_P2, - Mcp_LLDP_NB_DCBX_P2, - Mcp_DCBX_IEEE_EN_P1, - Mcp_DCBX_CEE_EN_P1, - Mcp_DCBX_WILLING_P1, - Mcp_DCBX_IEEE_EN_P2, - Mcp_DCBX_CEE_EN_P2, - Mcp_DCBX_WILLING_P2, - Mcp_Last -} mlxCfgParam; - -typedef std::pair cfgInfo; - -/* - * Basic Param Class - */ - -/* Adrianc: add Initialize/Open pure method that will contain all needed initializations (configuration supported defaults capabilities etc...) -*/ - - -class RawCfgParams5thGen : public ErrMsg -{ -public: - RawCfgParams5thGen(); - ~RawCfgParams5thGen() {} - int setRawData(const std::vector& tlvBuff); - int setOnDev(mfile* mf); - std::string dumpTlv(); -private: - int verifyTlv(); - std::vector _tlvBuff; - struct tools_open_nvda _nvdaTlv; -}; - - -class CfgParams : public ErrMsg -{ -public: - CfgParams(mlxCfgType t=Mct_Last, u_int32_t tlvT=0); - virtual ~CfgParams() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last) = 0; - void setDevCapVec(u_int64_t v) {_devCapVec = v;} - - virtual void setParam(mlxCfgParam paramType, u_int32_t val) = 0; - virtual u_int32_t getParam(mlxCfgParam paramType) = 0; - virtual u_int32_t getDefaultParam(mlxCfgParam paramType) = 0; - - virtual int getDefaultAndFromDev(mfile* mf); - virtual int getFromDev(mfile* mf) = 0; - virtual int setOnDev(mfile* mf, bool ignoreCheck=false) = 0; - virtual int getDefaultParams(mfile* mf) = 0; - - void setIgnoreSoftLimits(bool val); - void setIgnoreHardLimits(bool val); - - mlxCfgType type; - u_int32_t tlvTypeIdx; -protected: - // param validadion methods, only checkCfg shuold be called - virtual bool checkCfg(mfile* mf=NULL); - virtual bool hardLimitCheck() = 0; - virtual bool softLimitCheck(mfile* mf=NULL); - - // get default parameters for configuration (4th gen) - int getDefaultParams4thGen(mfile* mf, struct tools_open_query_def_params_global* global_params); - int getDefaultParams4thGen(mfile* mf, int port, struct tools_open_query_def_params_per_port* port_params); - - virtual void updateTlvFromClassAttr(void* tlv) {(void)tlv; throw std::logic_error("Function Not Implemented");} - virtual void updateClassAttrFromTlv(void* tlv) {(void)tlv; throw std::logic_error("Function Not Implemented");} - virtual void updateClassDefaultAttrFromTlv(void* tlv) {(void)tlv; throw std::logic_error("Function Not Implemented");} - - u_int64_t _devCapVec; // relevant for 4th gen devices - bool _updated; // set true on get and false on set - bool _ignoreSoftLimits; // soft limits checks will not be performed for configuration - bool _ignoreHardLimits; // hard limits checks will not be performed -}; - -/* - * SRIOV param classes: - */ - -class SriovParams4thGen : public CfgParams -{ -public: - SriovParams4thGen() : CfgParams(Mct_Sriov, SRIOV_TYPE) , _sriovEn(MLXCFG_UNKNOWN), _numOfVfs(MLXCFG_UNKNOWN), - _sriovEnDefault(MLXCFG_UNKNOWN), _numOfVfsDefault(MLXCFG_UNKNOWN), _maxVfs(1) {} - ~SriovParams4thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - - virtual int updateMaxVfs(mfile* mf); - virtual bool softLimitCheck(mfile* mf=NULL); - void setParams(u_int32_t sriovEn, u_int32_t numOfVfs); - - u_int32_t _sriovEn; - u_int32_t _numOfVfs; - u_int32_t _sriovEnDefault; - u_int32_t _numOfVfsDefault; - u_int32_t _maxVfs; -}; - -/* - * Boot Settings Extras param classes: - */ - -class BootSettingsExtParams : public CfgParams -{ -public: - BootSettingsExtParams(mlxCfgType t, u_int32_t tlvT) : CfgParams(t, tlvT), _ipVer(MLXCFG_UNKNOWN), _ipVerDefault(MLXCFG_UNKNOWN){} - virtual ~BootSettingsExtParams() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last) = 0; - - virtual void setParam(mlxCfgParam paramType, u_int32_t val) = 0; - virtual u_int32_t getParam(mlxCfgParam paramType) = 0; - virtual u_int32_t getDefaultParam(mlxCfgParam paramType) = 0; - - virtual int getFromDev(mfile* mf) = 0; - virtual int setOnDev(mfile* mf, bool ignoreCheck=false) = 0; - virtual int getDefaultParams(mfile* mf)=0; - -protected: - bool hardLimitCheck(); - void setParams(u_int32_t _ipVer); - - u_int32_t _ipVer; - u_int32_t _ipVerDefault; -}; - -class BootSettingsExtParams4thGen : public BootSettingsExtParams -{ -public: - BootSettingsExtParams4thGen(int port) : BootSettingsExtParams((port == 1) ? Mct_Boot_Settings_Extras_4thGen_P1 : Mct_Boot_Settings_Extras_4thGen_P2, - BOOT_SETTINGS_EXTRAS_GEN4), - _port(port){} - ~BootSettingsExtParams4thGen() {} - - u_int32_t getDefaultParam(mlxCfgParam paramType); - void setParam(mlxCfgParam paramType, u_int32_t val); - u_int32_t getParam(mlxCfgParam paramType); - bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - int getDefaultParams(mfile* mf); - - int getFromDev(mfile* mf); - int setOnDev(mfile* mf, bool ignoreCheck=false); -private: - int _port; -}; - -class BootSettingsExtParams5thGen : public BootSettingsExtParams -{ -public: - BootSettingsExtParams5thGen() : BootSettingsExtParams(Mct_Boot_Settings_Extras_5thGen, BOOT_SETTINGS_EXTRAS_GEN5) {} - ~BootSettingsExtParams5thGen() {} - - u_int32_t getBootSettingsExtCapabilitiesTlvTypeBe(); - bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - u_int32_t getParam(mlxCfgParam paramType); - u_int32_t getDefaultParam(mlxCfgParam paramType); - void setParam(mlxCfgParam paramType, u_int32_t val); - int getFromDev(mfile* mf); - int setOnDev(mfile* mf, bool ignoreCheck=false); - void updateClassAttrFromDefaultParams(); - void updateTlvFromClassAttr(void* tlv); - void updateClassAttrFromTlv(void* tlv); - void updateClassDefaultAttrFromTlv(void* tlv); - u_int32_t getTlvTypeBe(); - int getDefaultParams(mfile* mf); - int getDefaultParamsAux(mfile* mf); -}; -/* - * WOL param classes: - */ - -class WolParams : public CfgParams -{ -public: - WolParams() : CfgParams(Mct_Last, WOL_TYPE), _wolMagicEn(MLXCFG_UNKNOWN), _wolMagicEnDefault(MLXCFG_UNKNOWN) {} - virtual ~WolParams() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last) = 0; - - virtual void setParam(mlxCfgParam paramType, u_int32_t val) = 0; - virtual u_int32_t getParam(mlxCfgParam paramType) = 0; - virtual u_int32_t getDefaultParam(mlxCfgParam paramType) = 0; - - virtual int getFromDev(mfile* mf) = 0; - virtual int setOnDev(mfile* mf, bool ignoreCheck=false) = 0; - virtual int getDefaultParams(mfile* mf) = 0; - -protected: - virtual bool hardLimitCheck(); - void setParams(u_int32_t wolMagicEn); - // Wake on magic packet (atm this is the only mode which is supported) - - u_int32_t _wolMagicEn; - u_int32_t _wolMagicEnDefault; -}; - -class WolParams4thGen : public WolParams -{ -public: - WolParams4thGen(int port) : WolParams(), _port(port) {type = _port == 1 ? Mct_Wol_P1 : Mct_Wol_P2;} - ~WolParams4thGen() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); -private: - int _port; -}; - -class WolParams5thGen : public WolParams -{ -public: - WolParams5thGen() : WolParams() {type = Mct_Wol;} - ~WolParams5thGen() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); -}; - - -/* - * VPI param classes: - */ - -class VpiParams : public CfgParams -{ -public: - VpiParams(int port) : CfgParams(port == 1 ? Mct_Vpi_P1 : Mct_Vpi_P2, VPI_TYPE), _port(port), _linkType(MLXCFG_UNKNOWN), _defaultLinkType(MLXCFG_UNKNOWN) - , _linkTypeDefault(MLXCFG_UNKNOWN), _defaultLinkTypeDefault(MLXCFG_UNKNOWN){ - _vpiTlv.default_link_type = 0; - _vpiTlv.network_link_type = 0; - } - ~VpiParams() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last) = 0; - - virtual int getFromDev(mfile* mf) = 0; - virtual int setOnDev(mfile* mf, bool ignoreCheck=false) = 0; - virtual int getDefaultParams(mfile* mf) = 0; - -protected: - int getFromDevComPre(); - int getFromDevComPost(MError mnvaComRC); - int setOnDevComPre(bool ignoreCheck); - int setOnDevComPost(MError mnvaComRC); - void setParams(u_int32_t _linkType, u_int32_t _defaultLinkType); - - int _port; - u_int32_t _linkType; - u_int32_t _defaultLinkType; - u_int32_t _linkTypeDefault; - u_int32_t _defaultLinkTypeDefault; - // FW TLV (used when actually setting/getting the TLV from FW) - std::vector _tlvBuff; - struct tools_open_vpi_settings _vpiTlv; - - -}; - -class VpiParams4thGen : public VpiParams -{ -public: - VpiParams4thGen(int port) : VpiParams(port){} - ~VpiParams4thGen() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - virtual bool hardLimitCheck(); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); -}; - -class VpiParams5thGen : public VpiParams -{ -public: - VpiParams5thGen(int port) : VpiParams(port){} - ~VpiParams5thGen() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - virtual bool hardLimitCheck(); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); -protected: - u_int32_t getTlvTypeBe(); -}; - -/* - * BAR size param classes: - */ - -class BarSzParams : public CfgParams -{ -public: - BarSzParams() : CfgParams(Mct_Bar_Size, BAR_SIZE_TYPE) ,_maxLogBarSz(1), _logBarSz(MLXCFG_UNKNOWN), _logBarSzDefault(MLXCFG_UNKNOWN) {} - ~BarSzParams() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last) = 0; - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf) = 0; - virtual int setOnDev(mfile* mf, bool ignoreCheck=false) = 0; - virtual int getDefaultParams(mfile* mf) = 0; - -protected: - virtual bool hardLimitCheck(); - virtual bool softLimitCheck(mfile* mf=NULL) = 0; - virtual int getDefaultBarSz(mfile* mf) = 0; - void setParams(u_int32_t logBarSz); - u_int32_t _maxLogBarSz; - u_int32_t _logBarSz; - u_int32_t _logBarSzDefault; - -}; - -class BarSzParams4thGen : public BarSzParams -{ -public: - BarSzParams4thGen() : BarSzParams() {} - ~BarSzParams4thGen() {} - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); -protected: - virtual bool softLimitCheck(mfile* mf=NULL); - virtual int getDefaultBarSz(mfile* mf); -}; - - -/* - * PCI parameters Class (5thGen devices only) - */ - -class PciParams5thGen : public CfgParams -{ -public: - PciParams5thGen() : CfgParams(Mct_Pci, PCI_SETTINGS_TYPE) , _sriovEn(MLXCFG_UNKNOWN), _numOfVfs(MLXCFG_UNKNOWN),\ - _fppEn(MLXCFG_UNKNOWN), _pfLogBarSize(MLXCFG_UNKNOWN), _vfLogBarSize(MLXCFG_UNKNOWN),\ - _numPfMsix(MLXCFG_UNKNOWN), _numVfMsix(MLXCFG_UNKNOWN), _sriovEnDefault(MLXCFG_UNKNOWN),\ - _numOfVfsDefault(MLXCFG_UNKNOWN), _fppEnDefault(MLXCFG_UNKNOWN), _pfLogBarSizeDefault(MLXCFG_UNKNOWN),\ - _vfLogBarSizeDefault(MLXCFG_UNKNOWN), _numPfMsixDefault(MLXCFG_UNKNOWN), _numVfMsixDefault(MLXCFG_UNKNOWN),\ - _numOfPfs(MLXCFG_UNKNOWN), _numOfPfsValid(0), _sriovSupported(false),_maxVfsPerPf(0),\ - _fppSupported(false), _pfLogBarSizeSuppored(false), _vfLogBarSizeSuppored(false),\ - _numPfMsixSupported(false), _numVfMsixSupported(false),_maxLogPfBarSize(0), _maxLogVfBarSize(0),\ - _maxTotalBarValid(0), _maxTotalBar(1), _maxNumPfMsix(0), _maxNumVfMsix(0),_maxTotalMsixValid(0),\ - _maxTotalMsix(0), _userSpecifiedSRIOV(false), _userSpecifiedFPP(false),_userSpecifiedPfLogBarSize(false),\ - _userSpecifiedVfLogBarSize(false),_userSpecifiedNumPfMsix(false),_userSpecifiedNumVfMsix(false){} - ~PciParams5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - virtual bool softLimitCheck(mfile* mf=NULL); - int getDefaultsAndCapabilities(mfile* mf); - u_int32_t getPciSettingsTlvTypeBe(); - u_int32_t getPciCapabilitiesTlvTypeBe(); - void setParams(u_int32_t sriovEn, u_int32_t numOfVfs, u_int32_t fppEn, u_int32_t pfLogBarSize, - u_int32_t vfLogBarSize, u_int32_t numOfPfs, u_int32_t numPfMsix, u_int32_t numVfMsix); - -private: - u_int32_t calcVfLogBarSize(); - u_int32_t calcPfLogBarSize(); - u_int32_t calcTotalBar(); - u_int32_t calcNumOfVfs(); - - u_int32_t _sriovEn; - u_int32_t _numOfVfs; - u_int32_t _fppEn; - u_int32_t _pfLogBarSize; - u_int32_t _vfLogBarSize; - u_int32_t _numPfMsix; - u_int32_t _numVfMsix; - - u_int32_t _sriovEnDefault; - u_int32_t _numOfVfsDefault; - u_int32_t _fppEnDefault; - u_int32_t _pfLogBarSizeDefault; - u_int32_t _vfLogBarSizeDefault; - u_int32_t _numPfMsixDefault; - u_int32_t _numVfMsixDefault; - - u_int32_t _numOfPfs; - u_int32_t _numOfPfsValid; - - - // defaults and capabilities - bool _sriovSupported; - u_int32_t _maxVfsPerPf; - bool _fppSupported; - bool _pfLogBarSizeSuppored; - bool _vfLogBarSizeSuppored; - bool _numPfMsixSupported; - bool _numVfMsixSupported; - u_int32_t _maxLogPfBarSize; - u_int32_t _maxLogVfBarSize; - u_int32_t _maxTotalBarValid; - u_int32_t _maxTotalBar; - u_int32_t _maxNumPfMsix; - u_int32_t _maxNumVfMsix; - u_int32_t _maxTotalMsixValid; - u_int32_t _maxTotalMsix; - - // class members used for indication - bool _userSpecifiedSRIOV; - bool _userSpecifiedFPP; - bool _userSpecifiedPfLogBarSize; - bool _userSpecifiedVfLogBarSize; - bool _userSpecifiedNumPfMsix; - bool _userSpecifiedNumVfMsix; - -}; - -/* - * TPT parameters Class (5thGen devices only) - */ - -class TptParams5thGen : public CfgParams -{ -public: - TptParams5thGen() : CfgParams(Mct_Tpt, TPT_SETTINGS_TYPE) , _logMaxPayloadSize(MLXCFG_UNKNOWN), - _logMaxPayloadSizeDefault(MLXCFG_UNKNOWN), _logMaxPayloadSizeSupported(false) - {} - ~TptParams5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - int getFromDev(mfile* mf, bool getDefault); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - int getDefaultsAndCapabilities(mfile* mf); - u_int32_t getTptSettingsTlvTypeBe(); - u_int32_t getTptCapabilitiesTlvTypeBe(); - void setParams(u_int32_t logMaxPayloadSize); - - u_int32_t _logMaxPayloadSize; - u_int32_t _logMaxPayloadSizeDefault; - - // defaults and capabilities - bool _logMaxPayloadSizeSupported; -}; - -/* - * Infiniband boot settings parameter Class (4thGen devices only) - */ -class InfinibandBootSettingsParams4thGen : public CfgParams -{ -public: - InfinibandBootSettingsParams4thGen(int port) : CfgParams((port == 1 ? Mct_Boot_Settings_P1 : Mct_Boot_Settings_P2), - INFINIBAND_BOOT_SETTINGS_TYPE) , _port(port), _bootPkey(MLXCFG_UNKNOWN), _bootPkeyDefault(MLXCFG_UNKNOWN) {} - ~InfinibandBootSettingsParams4thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - void setParams(u_int32_t bootPkey); - - int _port; - u_int32_t _bootPkey; - u_int32_t _bootPkeyDefault; - -}; - -/* - * Infiniband DC (Dynamically Connected) parameters Class (5thGen devices only) - */ - -class IBDCParams5thGen : public CfgParams -{ -public: - IBDCParams5thGen() : CfgParams(Mct_Dc, INFINIBAND_DC_SETTINGS_TYPE) , _logDcrHashTableSize(MLXCFG_UNKNOWN), _dcrLifoSize(MLXCFG_UNKNOWN), - _logDcrHashTableSizeDefault(MLXCFG_UNKNOWN), _dcrLifoSizeDefault(MLXCFG_UNKNOWN), _minLogDcrHashTableSize(0), - _maxLogDcrHashTableSize(0), _minDcrLifoSize(0), _maxDcrLifoSize(0){} - ~IBDCParams5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - int getFromDev(mfile* mf, bool getDefault); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - int getDefaultsAndCapabilities(mfile* mf); - u_int32_t getTlvTypeBe(); - u_int32_t getDcCapabilitiesTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t logDcrHashTableSize, u_int32_t dcrLifoSize); - - u_int32_t _logDcrHashTableSize; - u_int32_t _dcrLifoSize; - - u_int32_t _logDcrHashTableSizeDefault; - u_int32_t _dcrLifoSizeDefault; - - // defaults and capabilities - u_int32_t _minLogDcrHashTableSize; - u_int32_t _maxLogDcrHashTableSize; - u_int32_t _minDcrLifoSize; - u_int32_t _maxDcrLifoSize; -}; - -/* - * RoCE v1.5 next protocol Class (5thGen devices only) - */ - -class RoCENextProtocolParams5thGen : public CfgParams -{ -public: - RoCENextProtocolParams5thGen() : CfgParams(Mct_RoCE_Next_Protocol, ROCE_NEXT_PROTOCOL_TYPE) , _nextProtocol(MLXCFG_UNKNOWN) - , _nextProtocolDefault(MLXCFG_UNKNOWN){} - ~RoCENextProtocolParams5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t nextProtocol); - - u_int32_t _nextProtocol; - - u_int32_t _nextProtocolDefault; -}; - -/* - * RoCE CC parameters Class (5thGen devices only) - */ - -class RoCECCParams5thGen : public CfgParams -{ -public: - RoCECCParams5thGen(int port) : CfgParams((port == 1 ? Mct_RoCE_CC_P1 : Mct_RoCE_CC_P2), ROCE_CC_TYPE), - _port(port), _roceCcAlgorithm(MLXCFG_UNKNOWN), _roceCcPrioMask(MLXCFG_UNKNOWN) - , _roceCcAlgorithmDefault(MLXCFG_UNKNOWN), _roceCcPrioMaskDefault(MLXCFG_UNKNOWN){} - ~RoCECCParams5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t roceCcAlgorithm, u_int32_t roceCcPrioMask); - - int _port; - u_int32_t _roceCcAlgorithm; - u_int32_t _roceCcPrioMask; - - u_int32_t _roceCcAlgorithmDefault; - u_int32_t _roceCcPrioMaskDefault; -}; - -/* - * RoCE CC ECN parameters Class (5thGen devices only) - */ - -class RoCECCEcnParams5thGen : public CfgParams -{ -public: - RoCECCEcnParams5thGen(int port) : CfgParams((port == 1 ? Mct_RoCE_CC_Ecn_P1 : Mct_RoCE_CC_Ecn_P2), ROCE_CC_ECN_TYPE), - _port(port), _clampTgtRate(MLXCFG_UNKNOWN), _clampTgtRateAfterTimeInc(MLXCFG_UNKNOWN), - _rpgTimeReset(MLXCFG_UNKNOWN), _rpgByteReset(MLXCFG_UNKNOWN), _rpgThreshold(MLXCFG_UNKNOWN), - _rpgMaxRate(MLXCFG_UNKNOWN), _rpgAiRate(MLXCFG_UNKNOWN), _rpgHaiRate(MLXCFG_UNKNOWN), - _rpgGd(MLXCFG_UNKNOWN), _rpgMinDecFac(MLXCFG_UNKNOWN), _rpgMinRate(MLXCFG_UNKNOWN), - _rateToSetOnFirstCnp(MLXCFG_UNKNOWN), _dceTcpG(MLXCFG_UNKNOWN), _dceTcpRtt(MLXCFG_UNKNOWN), - _rateReduceMonitorPeriod(MLXCFG_UNKNOWN), _initialAlphaValue(MLXCFG_UNKNOWN), - _minTimeBetweenCnps(MLXCFG_UNKNOWN), _cnpDscp(MLXCFG_UNKNOWN), _cnp802pPrio(MLXCFG_UNKNOWN) - , _clampTgtRateDefault(MLXCFG_UNKNOWN), _clampTgtRateAfterTimeIncDefault(MLXCFG_UNKNOWN), - _rpgTimeResetDefault(MLXCFG_UNKNOWN), _rpgByteResetDefault(MLXCFG_UNKNOWN), _rpgThresholdDefault(MLXCFG_UNKNOWN), - _rpgMaxRateDefault(MLXCFG_UNKNOWN), _rpgAiRateDefault(MLXCFG_UNKNOWN), _rpgHaiRateDefault(MLXCFG_UNKNOWN), - _rpgGdDefault(MLXCFG_UNKNOWN), _rpgMinDecFacDefault(MLXCFG_UNKNOWN), _rpgMinRateDefault(MLXCFG_UNKNOWN), - _rateToSetOnFirstCnpDefault(MLXCFG_UNKNOWN), _dceTcpGDefault(MLXCFG_UNKNOWN), _dceTcpRttDefault(MLXCFG_UNKNOWN), - _rateReduceMonitorPeriodDefault(MLXCFG_UNKNOWN), _initialAlphaValueDefault(MLXCFG_UNKNOWN), - _minTimeBetweenCnpsDefault(MLXCFG_UNKNOWN), _cnpDscpDefault(MLXCFG_UNKNOWN), _cnp802pPrioDefault(MLXCFG_UNKNOWN){}; - ~RoCECCEcnParams5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t clampTgtRate, u_int32_t clampTgtRateAfterTimeInc, u_int32_t rpgTimeReset, u_int32_t rpgByteReset, - u_int32_t rpgThreshold, u_int32_t rpgMaxRate, u_int32_t rpgAiRate, u_int32_t rpgHaiRate, - u_int32_t rpgGd, u_int32_t rpgMinDecFac, u_int32_t rpgMinRate, u_int32_t rateToSetOnFirstCnp, - u_int32_t dceTcpG, u_int32_t dceTcpRtt, u_int32_t rateReduceMonitorPeriod, u_int32_t initialAlphaValue, - u_int32_t minTimeBetweenCnps, u_int32_t cnpDscp, u_int32_t cnp802pPrio); - - int _port; - - u_int32_t _clampTgtRate; - u_int32_t _clampTgtRateAfterTimeInc; - u_int32_t _rpgTimeReset; - u_int32_t _rpgByteReset; - u_int32_t _rpgThreshold; - u_int32_t _rpgMaxRate; - u_int32_t _rpgAiRate; - u_int32_t _rpgHaiRate; - u_int32_t _rpgGd; - u_int32_t _rpgMinDecFac; - u_int32_t _rpgMinRate; - u_int32_t _rateToSetOnFirstCnp; - u_int32_t _dceTcpG; - u_int32_t _dceTcpRtt; - u_int32_t _rateReduceMonitorPeriod; - u_int32_t _initialAlphaValue; - u_int32_t _minTimeBetweenCnps; - u_int32_t _cnpDscp; - u_int32_t _cnp802pPrio; - - u_int32_t _clampTgtRateDefault; - u_int32_t _clampTgtRateAfterTimeIncDefault; - u_int32_t _rpgTimeResetDefault; - u_int32_t _rpgByteResetDefault; - u_int32_t _rpgThresholdDefault; - u_int32_t _rpgMaxRateDefault; - u_int32_t _rpgAiRateDefault; - u_int32_t _rpgHaiRateDefault; - u_int32_t _rpgGdDefault; - u_int32_t _rpgMinDecFacDefault; - u_int32_t _rpgMinRateDefault; - u_int32_t _rateToSetOnFirstCnpDefault; - u_int32_t _dceTcpGDefault; - u_int32_t _dceTcpRttDefault; - u_int32_t _rateReduceMonitorPeriodDefault; - u_int32_t _initialAlphaValueDefault; - u_int32_t _minTimeBetweenCnpsDefault; - u_int32_t _cnpDscpDefault; - u_int32_t _cnp802pPrioDefault; -}; - - -/* - * Preboot Boot Settings Class (4thGen devices only) - */ - -class PrebootBootSettingsParams4thGen : public CfgParams -{ -public: - PrebootBootSettingsParams4thGen(int port) : CfgParams((port == 1 ? Mct_Preboot_Boot_Settings_P1 : Mct_Preboot_Boot_Settings_P2), PREBOOT_BOOT_SETTINGS_TYPE), - _bootOptionRomEn(MLXCFG_UNKNOWN), _bootVlanEn(MLXCFG_UNKNOWN), _bootRetryCnt(MLXCFG_UNKNOWN), - _legacyBootProtocol(MLXCFG_UNKNOWN), _bootVlan(MLXCFG_UNKNOWN), - _bootOptionRomEnDefault(MLXCFG_UNKNOWN), _bootVlanEnDefault(MLXCFG_UNKNOWN), _bootRetryCntDefault(MLXCFG_UNKNOWN), - _legacyBootProtocolDefault(MLXCFG_UNKNOWN), _bootVlanDefault(MLXCFG_UNKNOWN), - _port(port) {} - ~PrebootBootSettingsParams4thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t bootOptionRomEn, u_int32_t bootVlanEn, u_int32_t bootRetryCnt, - u_int32_t legacyBootProtocol, u_int32_t bootVlan); - - u_int32_t _bootOptionRomEn; - u_int32_t _bootVlanEn; - u_int32_t _bootRetryCnt; - u_int32_t _legacyBootProtocol; - u_int32_t _bootVlan; - - u_int32_t _bootOptionRomEnDefault; - u_int32_t _bootVlanEnDefault; - u_int32_t _bootRetryCntDefault; - u_int32_t _legacyBootProtocolDefault; - u_int32_t _bootVlanDefault; - - int _port; -}; - -/* - * ExternalPort5thGen parameters Class (5thGen devices only) - */ - -class ExternalPort5thGen : public CfgParams -{ -public: - ExternalPort5thGen() : CfgParams(Mct_External_Port, EXTERNAL_PORT), - _portOwner(MLXCFG_UNKNOWN), _allowRdCounters(MLXCFG_UNKNOWN), - _portOwnerDefault(MLXCFG_UNKNOWN), _allowRdCountersDefault(MLXCFG_UNKNOWN){} - ~ExternalPort5thGen() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t portOwner, u_int32_t allowRdCounters); - - u_int32_t _portOwner; - u_int32_t _allowRdCounters; - - u_int32_t _portOwnerDefault; - u_int32_t _allowRdCountersDefault; - -}; - -/* - * QoS parameters Class - */ - -class QoS : public CfgParams -{ -public: - QoS(int port) : CfgParams(port == 1 ? Mct_QoS_P1 : Mct_QoS_P2, QOS), - _port(port), _numOfTC(MLXCFG_UNKNOWN), _numOfVL(MLXCFG_UNKNOWN), - _numOfTCDefault(MLXCFG_UNKNOWN), _numOfVLDefault(MLXCFG_UNKNOWN), - _maxNumOfTC(MLXCFG_UNKNOWN), _maxNumOfVL(MLXCFG_UNKNOWN){} - ~QoS() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - bool getCap(mfile *mf); - u_int32_t getQoSCapTlvTypeBe(); - -protected: - bool hardLimitCheckAux(u_int32_t maxNumOfX, u_int32_t numOfX,const char *x); - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t numOfTCDefault, u_int32_t numOfVLDefault); - - int _port; - - u_int32_t _numOfTC; - u_int32_t _numOfVL; - - u_int32_t _numOfTCDefault; - u_int32_t _numOfVLDefault; - - u_int32_t _maxNumOfTC; - u_int32_t _maxNumOfVL; -}; - -/* - * LLDP Client Settings Class - */ - -class LLDPClientSettings : public CfgParams -{ -public: - LLDPClientSettings(int port) : CfgParams(port == 1 ? - Mct_LLDP_Client_Settings_P1 : Mct_LLDP_Client_Settings_P2, LLDP_CLIENT_SETTINGS_TYPE), - _port(port), _lldpNbTxMode(MLXCFG_UNKNOWN), _lldpNbRxMode(MLXCFG_UNKNOWN), _lldpNbDcbx(MLXCFG_UNKNOWN), - _userSpecifiedRx(false), _userSpecifiedTx(false), _userSpecifiedDcbx(false), - _lldpNbTxModeDefault(MLXCFG_UNKNOWN), _lldpNbRxModeDefault(MLXCFG_UNKNOWN), - _lldpNbDcbxDefault(MLXCFG_UNKNOWN), _lldpNbTxCap(MLXCFG_UNKNOWN), - _lldpNbRxCap(MLXCFG_UNKNOWN), _lldpNbDcbxEn(MLXCFG_UNKNOWN){} - ~LLDPClientSettings() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - bool getCap(mfile *mf); - u_int32_t getLLDPNBCapTlvTypeBe(); - -protected: - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t lldpNbRxMode, u_int32_t lldpNbTxMode, u_int32_t lldpNbDcbx); - - int _port; - - u_int32_t _lldpNbTxMode; - u_int32_t _lldpNbRxMode; - u_int32_t _lldpNbDcbx; - - bool _userSpecifiedRx; - bool _userSpecifiedTx; - bool _userSpecifiedDcbx; - - u_int32_t _lldpNbTxModeDefault; - u_int32_t _lldpNbRxModeDefault; - u_int32_t _lldpNbDcbxDefault; - - u_int32_t _lldpNbTxCap; - u_int32_t _lldpNbRxCap; - u_int32_t _lldpNbDcbxEn; -}; - -/* - * LLDP NB DCBX Class - */ - -class DCBX : public CfgParams -{ -public: - DCBX(int port) : CfgParams(port == 1 ? - Mct_DCBX_P1 : Mct_DCBX_P2, LLDP_NB_DCBX), - _port(port), _ieee(MLXCFG_UNKNOWN), _cee(MLXCFG_UNKNOWN), _willing(MLXCFG_UNKNOWN), - _lldpNbDcbxEn(MLXCFG_UNKNOWN), - _ieeeDefault(MLXCFG_UNKNOWN), _ceeDefault(MLXCFG_UNKNOWN), _willingDefault(MLXCFG_UNKNOWN){} - ~DCBX() {}; - - virtual bool cfgSupported(mfile* mf, mlxCfgParam param=Mcp_Last); - - virtual void setParam(mlxCfgParam paramType, u_int32_t val); - virtual u_int32_t getParam(mlxCfgParam paramType); - virtual u_int32_t getDefaultParam(mlxCfgParam paramType); - - virtual int getFromDev(mfile* mf); - virtual int setOnDev(mfile* mf, bool ignoreCheck=false); - virtual int getDefaultParams(mfile* mf); - -protected: - virtual bool hardLimitCheck(); - u_int32_t getTlvTypeBe(); - u_int32_t getLLDPNBCapTlvTypeBe(); - - virtual void updateTlvFromClassAttr(void* tlv); - virtual void updateClassAttrFromTlv(void* tlv); - virtual void updateClassDefaultAttrFromTlv(void* tlv); - void updateClassAttrFromDefaultParams(); - void setParams(u_int32_t lldpNbRxMode, u_int32_t lldpNbTxMode, u_int32_t lldpNbDcbx); - bool getCap(mfile* m); - - int _port; - - u_int32_t _ieee; - u_int32_t _cee; - u_int32_t _willing; - - u_int32_t _lldpNbDcbxEn; - - u_int32_t _ieeeDefault; - u_int32_t _ceeDefault; - u_int32_t _willingDefault; -}; -#endif /* MLXCFG_PARAM_LIB_H_ */ diff --git a/mlxconfig/mlxcfg_parser.cpp b/mlxconfig/mlxcfg_parser.cpp deleted file mode 100644 index d0681b1..0000000 --- a/mlxconfig/mlxcfg_parser.cpp +++ /dev/null @@ -1,866 +0,0 @@ -/* - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -#include -#include -#include -#include -#include -#include - -#include - -#include "mlxcfg_ui.h" - -using namespace std; - - -#define IDENT " " -#define IDENT2 IDENT IDENT -#define IDENT3 "\t\t" -#define IDENT4 IDENT2 IDENT - - - -static void printFlagLine(string flag_s, string flag_l, string param, string desc) -{ - printf(IDENT2"-%s|--%s", flag_s.c_str(), flag_l.c_str()); - if (param.length()) { - printf(" <%s>", param.c_str()); - } else if (flag_l.length() < 8){ - printf("\t"); - } - printf(IDENT3": %s\n", desc.c_str()); -} - -#ifdef MTCR_UL -#define DEVICE_NAME "device" -#else -#define DEVICE_NAME "mst device" -#endif - -void MlxCfg::printHelp() -{ - // print opening - printf(IDENT"NAME:\n" - IDENT2 MLXCFG_NAME "\n" - IDENT"SYNOPSIS:\n" - IDENT2 MLXCFG_NAME " [-d <%s> ] [-y|-e] |q[uery]|r[eset]|[ -f backup|set_raw]>\n", DEVICE_NAME); - - // print options - printf("\n"); - printf(IDENT"OPTIONS:\n"); - printFlagLine("d", "dev", "device", "Perform operation for a specified mst device."); - printFlagLine("f", "file", "conf_file", "raw configuration file."); - printFlagLine("h", "help", "", "Display help message."); - printFlagLine("v", "version", "", "Display version info."); - printFlagLine("e", "show_default", "", "Show default configurations."); - printFlagLine("y", "yes", "", "Answer yes in prompt."); - - //print commands - printf("\n"); - printf(IDENT"COMMANDS:\n"); - printf(IDENT2"%-24s : %s\n","clear_semaphore", "clear the tool semaphore."); - printf(IDENT2"%-24s : %s\n","q[uery]", "query current supported configurations."); - printf(IDENT2"%-24s : %s\n","r[eset]", "reset all configurations to their default value."); - printf(IDENT2"%-24s : %s\n","s[et]", "set configurations to a specific device."); - printf(IDENT2"%-24s : %s\n","set_raw", "set raw configuration file.(only " FIFTH_GENERATION_LIST ".)"); - printf(IDENT2"%-24s : %s\n","backup", "backup configurations to a file (only " FIFTH_GENERATION_LIST ".). Use set_raw command to restore file."); - - // print supported commands - printf("\n"); - printf(IDENT"Supported Configurations:\n"); - printf("\n"); - - _allInfo.printLongDesc(); - - // print usage examples - printf("\n"); - printf(IDENT"Examples:\n"); - printf(IDENT2"%-35s: %s\n", "To query current configuration", MLXCFG_NAME " -d " MST_DEV_EXAMPLE " query"); - printf(IDENT2"%-35s: %s\n", "To set configuration", MLXCFG_NAME " -d " MST_DEV_EXAMPLE " set SRIOV_EN=1 NUM_OF_VFS=16 WOL_MAGIC_EN_P1=1"); - printf(IDENT2"%-35s: %s\n", "To set raw configuration", MLXCFG_NAME " -d " MST_DEV_EXAMPLE2 " -f conf_file set_raw"); - printf(IDENT2"%-35s: %s\n", "To reset configuration", MLXCFG_NAME " -d " MST_DEV_EXAMPLE " reset"); - printf("\n"); - printf(IDENT"Supported devices:\n"); - printf(IDENT2"4th Generation devices: ConnectX3, ConnectX3-Pro (FW 2.31.5000 and above).\n"); - printf(IDENT2"5th Generation devices: ConnectIB, ConnectX4, ConnectX4-LX.\n"); - printf("\n"); - printf(IDENT"Note: query device to view supported configurations.\n"); - printf("\n"); -} - -void MlxCfg::printVersion() -{ - print_version_string(MLXCFG_NAME, ""); -} - -void MlxCfg::printUsage() { - printf("\n" IDENT "Usage:\n" - IDENT2 MLXCFG_NAME " [-d <%s> ] [-y|-e] |q[uery]|r[eset]|[ -f backup|set_raw]>\n\n", DEVICE_NAME); -} - -bool MlxCfg::tagExsists(mlxCfgParam tag) { - for (std::vector::iterator it = _mlxParams.params.begin() ; it != _mlxParams.params.end(); it++) { - if (it->first == tag) { - return true; - } - } - return false; -} - -mlxCfgStatus MlxCfg::processArg(string tag, u_int32_t val) -{ - int i; - std::vector::iterator it; - for ( i = (int)Mcp_Sriov_En ; i < (int)Mcp_Last ; i++) { - if (tag == MlxCfgParams::param2str[i]) { - if (tagExsists((mlxCfgParam)i)) { - return err(true, "Duplicate parameter, %s.", tag.c_str()); - } - _mlxParams.params.push_back(cfgInfo((mlxCfgParam)i, val)); - break; - } - } - if (i == Mcp_Last) { - return err(true, "Unknown Parameter: %s", tag.c_str()); - } - return MLX_CFG_OK; -} - - -static bool strToNum(string str, u_int32_t& num, int base=0) -{ - char *endp; - char* numStr = strcpy(new char[str.size() + 1],str.c_str()); - num = strtoul(numStr, &endp, base); - if (*endp) { - delete[] numStr; - return false; - } - delete[] numStr; - // check errno - if (errno == ERANGE) { - return false; - } - return true; -} - -mlxCfgStatus MlxCfg::extractCfgArgs(int argc, char* argv[]) -{ - int i = 0; - string tag; - string valstr; - u_int32_t val = 0; - mlxCfgParam param = Mcp_Last; - for (;i < argc;i++) { - char* ptr; - // get the tag - ptr = strtok(argv[i], "="); - if (!ptr) { - return err(true, "invalid Configuration argument %s", argv[i]); - } - tag = ptr; // hopefully its calling copy function. - // get the val - ptr = strtok(NULL, "="); - if (!ptr) { - return err(true, "invalid Configuration argument %s", argv[i]); - } - valstr = ptr; - if (strtok(NULL, "=")) { - return err(true, "Invalid Configuration argument %s", argv[i]); - } - - if(_allInfo.parseParam(tag, valstr, val, param)) { - if(param == Mcp_Last) { - return err(true, "Unknown Parameter: %s", tag.c_str()); - } else { - return err(true, "Failed to parse %s=%s", tag.c_str(), valstr.c_str()); - } - } - - if(tagExsists(param)) { - return err(true, "Duplicate parameter, %s.", tag.c_str()); - } - _mlxParams.params.push_back(cfgInfo((mlxCfgParam)param, val)); - } - return MLX_CFG_OK; -} - - - -mlxCfgStatus MlxCfg::parseArgs(int argc, char* argv[]) -{ - int i = 1; - for (; i