if (preFwOps() == FLINT_FAILED) {
return FLINT_FAILED;
}
-
- if (!askUser("reset non-volatile configuration?")) {
+ 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(resetCfgCbFunc)){
+ if (!_fwOps->FwResetNvData()){
printf(" Failed!\n");
reportErr(true, FLINT_RESET_CFG_ERROR, _fwOps->err());
return FLINT_FAILED;
#define WOL_P2_MASK 0x4
#define VPI_P1_MASK 0x8
#define VPI_P2_MASK 0x10
-#define BAR_SZ_MASK 0x20
#define TOOL_CAP_BITS_ADDR 0xc0
#define MAX_VFS_ADDR 0x38
-#define MAX_BAR_SZ_ADDR 0xc8
#define DEFAULT_BAR_SZ_ADDR 0x48
// for debug:
return (_wolMagicEn == 0 || _wolMagicEn == 1 );
}
-/*
- * BarSzParams Implementation
- */
-
-void MlxCfgOps::BarSzParams::setParam(mlxCfgParam paramType, u_int32_t val)
-{
- if ((paramType == Mcp_Log_Bar_Size) ) {
- _logBarSz = val;
- }
-}
-
-u_int32_t MlxCfgOps::BarSzParams::getParam(mlxCfgParam paramType)
-{
- if (paramType == Mcp_Log_Bar_Size) {
- return _logBarSz;
- }
- return MLXCFG_UNKNOWN;
-}
-
-McStatus MlxCfgOps::BarSzParams::getFromDev(mfile* mf)
-{
- if (_updated) {
- return MCE_SUCCESS;
- }
- McStatus rc;
- // prep tlv
- u_int8_t buff[tools_bar_size_size()];
- struct tools_bar_size barSzTlv;
- memset(buff, 0, tools_bar_size_size());
- memset(&barSzTlv, 0, sizeof(struct tools_bar_size));
- // pack it
- tools_bar_size_pack(&barSzTlv, buff);
- // send it
- rc = mnvaCom(mf, buff, tools_bar_size_size(), tlvType, REG_ACCESS_METHOD_GET, 0);
- // check rc
- if (rc) {
- return rc;
- }
- // unpack and update
- tools_bar_size_unpack(&barSzTlv, buff);
- _logBarSz = _logBarSz == MLXCFG_UNKNOWN ? barSzTlv.log_uar_bar_size : _logBarSz ;
- _updated = true;
-
- return MCE_SUCCESS;
-}
-
-McStatus MlxCfgOps::BarSzParams::setOnDev(mfile* mf)
-{
- McStatus rc;
- if (_logBarSz == MLXCFG_UNKNOWN) {
- rc = getFromDev(mf);
- if (rc) {
- if (rc == MCE_RES_NOT_AVAIL) {
- return MCE_INCOMPLETE_PARAMS;
- }
- return rc;
- }
- }
- if (!isLegal()) {
- return MCE_BAD_PARAM_VAL;
- }
-
- // prep tlv
- u_int8_t buff[tools_bar_size_size()];
- struct tools_bar_size barSzTlv;
-
- memset(buff, 0, tools_bar_size_size());
- memset(&barSzTlv, 0, sizeof(struct tools_bar_size));
-
- barSzTlv.log_uar_bar_size= _logBarSz;
- // pack it
- tools_bar_size_pack(&barSzTlv, buff);
- // send it
- rc = mnvaCom(mf, buff, tools_bar_size_size(), tlvType, REG_ACCESS_METHOD_SET, 0);
- // check rc
- if (rc) {
- return rc;
- }
- _updated = false;
- return MCE_SUCCESS;
-}
-
-McStatus MlxCfgOps::BarSzParams::updateBarSzInfo(mfile* mf)
-{
- u_int64_t data = 0;
- int rc = tools_cmdif_query_dev_cap(mf, MAX_BAR_SZ_ADDR, &data);
- if (rc) {
- return translateRc((MError)rc);
- }
- _maxLogBarSz = (u_int32_t)(data & 0xffffffff);
- _currLogBarSz = (u_int32_t)(data >> 32);
- //printf("-D- vec 0x%lx max %d curr %d\n", data, maxBarSz, currBarSz);
- return MCE_SUCCESS;
-}
-
-bool MlxCfgOps::BarSzParams::isLegal(mfile* mf)
-{
- (void)mf;
- return (_logBarSz < _maxLogBarSz );
-}
-
/*
* VpiParams Implementation
*/
-
void MlxCfgOps::VpiParams::setParam(mlxCfgParam paramType, u_int32_t val)
{
if ((paramType == Mcp_Link_Type_P1 && _port == 1 ) || (paramType == Mcp_Link_Type_P2 && _port == 2) ) {
_cfgList[Mct_Wol_P2] = new WolParams(2);
_cfgList[Mct_Vpi_P1] = new VpiParams(1);
_cfgList[Mct_Vpi_P2] = new VpiParams(2);
- _cfgList[Mct_Bar_Size] = new BarSzParams();
return;
}
return rc;
}
}
-
- // get max/current bar size
- if (supportsCfg(Mct_Bar_Size)) {
- McStatus rc = static_cast<BarSzParams*>(_cfgList[Mct_Bar_Size])->updateBarSzInfo(_mf);
- if (rc) {
- return rc;
- }
- }
return MCE_SUCCESS;
}
if (!isLegal(cfg)) {
return false;
}
- if (cfg == Mct_Bar_Size || cfg == Mct_Vpi_P1 || cfg == Mct_Vpi_P2) { // dont enable these just yet, no FW support
- return false;
- }
return _suppVec & cfgSuppMask[cfg];
}
return (cfg >= Mcp_Sriov_En && cfg < Mcp_Last) ;
}
-u_int64_t MlxCfgOps::cfgSuppMask[Mct_Last] = {SRIOV_MASK, WOL_P1_MASK, WOL_P2_MASK , VPI_P1_MASK, VPI_P2_MASK, BAR_SZ_MASK};
+u_int64_t MlxCfgOps::cfgSuppMask[Mct_Last] = {SRIOV_MASK, WOL_P1_MASK, WOL_P2_MASK , VPI_P1_MASK, VPI_P2_MASK};
mlxCfgType MlxCfgOps::cfgParam2Type(mlxCfgParam param)
{
return Mct_Vpi_P1;
case Mcp_Link_Type_P2 :
return Mct_Vpi_P2;
- case Mcp_Log_Bar_Size :
- return Mct_Bar_Size;
default :
return Mct_Last;
}
#define WOL_TYPE 0x10
#define SRIOV_TYPE 0x11
#define VPI_TYPE 0x12
-#define BAR_SIZE_TYPE 0x13
Mct_Wol_P2,
Mct_Vpi_P1,
Mct_Vpi_P2,
- Mct_Bar_Size,
Mct_Last
} mlxCfgType;
Mcp_Wol_Magic_En_P2,
Mcp_Link_Type_P1,
Mcp_Link_Type_P2,
- Mcp_Log_Bar_Size,
Mcp_Last
} mlxCfgParam;
u_int32_t _linkType;
};
- class BarSzParams : public CfgParams
- {
- public:
- BarSzParams() : CfgParams(Mct_Bar_Size, BAR_SIZE_TYPE) ,_maxLogBarSz(1), _currLogBarSz(1), _logBarSz(MLXCFG_UNKNOWN) {}
- ~BarSzParams() {};
-
- virtual void setParam(mlxCfgParam paramType, u_int32_t val);
- virtual u_int32_t getParam(mlxCfgParam paramType);
-
- virtual McStatus getFromDev(mfile* mf);
- virtual McStatus setOnDev(mfile* mf);
-
- McStatus updateBarSzInfo(mfile* mf);
-
- private:
- virtual bool isLegal(mfile* mf=NULL);
- u_int32_t _maxLogBarSz;
- u_int32_t _currLogBarSz;
- u_int32_t _logBarSz;
-
- };
-
-
McStatus openComChk();
McStatus supportsToolsHCR();
bool isLegal(mlxCfgType cfg);
* SOFTWARE.
*/
-
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
printf(IDENT2"WOL_PORT2\t\t: WOL_MAGIC_EN_P2=<1|0>\n");
printf(IDENT2"VPI_SETTINGS_PORT1\t: LINK_TYPE_P1=<1|2|3> , 1=Infiniband 2=Ethernet 3=VPI(auto-sense).\n");
printf(IDENT2"VPI_SETTINGS_PORT2\t: LINK_TYPE_P2=<1|2|3>\n");
- printf(IDENT2"BAR_SIZE\t\t: LOG_BAR_SIZE=<Base_2_log_in_mb> , example: for 8Mb bar size set LOG_BAR_SIZE=3\n");
printf("\n");
printf(IDENT"Examples:\n");
printf(IDENT2"%-35s: %s\n", "To query current Configuration", MLXCFG_NAME" -d "MST_DEV_EXAMPLE" query");
* SOFTWARE.
*/
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
fatal_error_in_progress = 1;
signal (signum, SIG_DFL);
- printf("\n Received signal %d.\n", signum);
+ printf("\n Received signal %d. \n", signum);
fflush(stdout);
+
raise(signum);
}
#endif
std::string MlxCfgParams::param2str[Mcp_Last]= {"SRIOV_EN", "NUM_OF_VFS", "WOL_MAGIC_EN_P1", "WOL_MAGIC_EN_P2",\
- "LINK_TYPE_P1", "LINK_TYPE_P2", "LOG_BAR_SIZE"};
+ "LINK_TYPE_P1", "LINK_TYPE_P2"};
u_int32_t MlxCfgParams::getParamVal(mlxCfgParam p)
{
ansbuff[0] = '\0';
fflush(stdout);
//fgets(ansbuff, 30, stdin);
- int cnt = fscanf(stdin, "%30s", ansbuff);
- (void)cnt; // avoid errors
-
+ int rc=fscanf(stdin, "%30s", ansbuff);
+ (void)rc; // avoid warnings
if ( strcasecmp(ansbuff, "y") &&
strcasecmp(ansbuff, "yes")) {
* SOFTWARE.
*/
-
#ifndef MLXCFG_UI_H_
#define MLXCFG_UI_H_
case II_ConfigArea: {
// configuration area should always exsist
- _fs2ImgInfo.ext_info.config_sectors = __be32_to_cpu(*(p + 1));;
- _fs2ImgInfo.ext_info.config_pad = __be32_to_cpu(*(p + 2));;
+ _fs2ImgInfo.ext_info.config_sectors = __be32_to_cpu(*(p + 1));
+ _fs2ImgInfo.ext_info.config_pad = __be32_to_cpu(*(p + 2));
+ if (tagSize > 0x8){//fw_log_sector_size is also found
+ _fs2ImgInfo.fw_sector_size = (1 << __be32_to_cpu(*(p + 3))) * 1024;// the base value is 1kb i.e 1024
+ }
}
break;
}
#define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
+#define CX_DFLT_SECTOR_SIZE 0x10000
+#define SX_DFLT_SECTOR_SIZE 0x1000
+#define MAX_CONFIG_AREA_SIZE 0x10000
-bool Fs2Operations::GetMaxImageSize(u_int32_t flash_size, bool image_is_fs, u_int32_t imgConfigSectors,\
- u_int32_t &max_image_size)
+u_int32_t Fs2Operations::getDefaultSectorSz()
{
- //printf("-D- flash_info->configAddr1 = %#x, image_info->configAddr1 = %#x\n", flash_info->configAddr1, image_info->configAddr1);
- //printf("-D- flash_info->configSize = %#x, _ignore_config_section = %#x, image_info->configExists = %#x\n", flash_info->configSize, _ignore_config_section,
- // image_info->configExists);
- // max_image_size = (image_is_fs) ? flash_size / 2 : flash_size;
-/*
- if (!ignore_config_section && flash_info->imageOk && (image_info->isConfigurable || flash_info->isConfigurable)) {
- // Configurable image and there is a configuration burnt in the flash
- if (image_info->isFailsafe) { // failsafe image
- max_image_size = (flash_size / 2) - flash_info->configSize;
- } else { // non-faislafe image
- // Get the minimum config addr
- max_image_size = flash_info->configAddr2;
- }
- } else {
- // Non-configurable image or the user asked to ignore the configuration section
- }
-*/
-
+ // for ConnectX family default sector size is 64kb else 4kb
+ // all of this mess is because the sector_size written in the INI doesnt always correspond to the actual flash sector_size
+ // and as for the calculation of the maximal image size we want to be synced with the FW or take worst case scenario.
+ // we need this method as we only started collecting the fw_sector_size from MFT-3.6.0 so if the image was generated with
+ // an older mlxburn the fw_sector_size wount be available
+ u_int32_t devid = _ioAccess->get_dev_id();
+ switch (devid) {
+ case CX_HW_ID:
+ case CX3_HW_ID:
+ case CX3_PRO_HW_ID:
+ return CX_DFLT_SECTOR_SIZE;
+ default:
+ return SX_DFLT_SECTOR_SIZE;
+ }
+ // we shouldnt reach here
+ return 0;
+}
- // Non-configurable image or the user asked to ignore the configuration section
+bool Fs2Operations::GetMaxImageSize(u_int32_t flash_size, bool image_is_fs, u_int32_t imgConfigSectors, u_int32_t imgFwSectorSz,\
+ u_int32_t &max_image_size)
+{
+ /*
u_int32_t sector_size = _ioAccess->get_sector_size();
u_int32_t config_sectors = MY_MAX(imgConfigSectors, _fs2ImgInfo.ext_info.config_sectors);
if (image_is_fs) {
// For non FS image, there's an optional offset + 2 consecutive config areas
max_image_size = flash_size - (config_sectors * 2 + _fs2ImgInfo.ext_info.config_pad) * sector_size;
}
-
+ */
+ /* new methodology:
+ * a. for CX2/CX3/PRO: in case fw_sector_size is present reserve : num_of_config_sectors * fw_sector_size
+ * b. for CX2/CX3/PRO: in case sector_size isnt present assume sector size is 64kb and reserve: num_of_config_sectors * 64k
+ * c. for SwitchX: in case fw_sector_size is present reserve : ( num_of_config_sectors + config_padd) * fw_sector_size
+ * d. for SwitchX: in case sector_size isnt present assume sector size is 4kb and reserve: ( num_of_config_sectors + config_padd) *4k
+ * ** on ALL cases we will impose the limitation of reserving at most 64kb to the NV configuration.
+ * ** config_pad might be != 0 on SwitchX only.
+ * ** To Orenks knowledge there arent any SwitchX with flashes that dont support 4kb.
+ */
+ u_int32_t sector_size = (imgFwSectorSz != 0 || _fs2ImgInfo.fw_sector_size != 0) ?\
+ MY_MAX(imgFwSectorSz, _fs2ImgInfo.fw_sector_size) : getDefaultSectorSz();
+ u_int32_t config_sectors = MY_MAX(imgConfigSectors, _fs2ImgInfo.ext_info.config_sectors);
+ u_int32_t areaToReserve = config_sectors * sector_size;
+ // we dont want to exceed 64kb of reserved space
+ areaToReserve = areaToReserve > MAX_CONFIG_AREA_SIZE ? MAX_CONFIG_AREA_SIZE : areaToReserve;
+ //printf("-D- sector_size: 0x%x, config_sectors: %d, areaToReserve: 0x%x, config_pad: %d\n"
+ //, sector_size, config_sectors, areaToReserve, _fs2ImgInfo.ext_info.config_pad);
+ if (image_is_fs) {
+ // why do we take config padding of the image info of the device and not the image to be burnt or the maximum between them??
+ max_image_size = (flash_size / 2) - (areaToReserve + (_fs2ImgInfo.ext_info.config_pad * sector_size));
+ } else {
+ // For non FS image, there's an optional offset + 2 consecutive config areas
+ max_image_size = flash_size - (areaToReserve * 2 + _fs2ImgInfo.ext_info.config_pad*sector_size);
+ }
return true;
}
u_int32_t max_image_size;
if (!GetMaxImageSize(f->get_size(), imageOps._fwImgInfo.ext_info.is_failsafe,\
- imageOps._fs2ImgInfo.ext_info.config_sectors, max_image_size)) {
+ imageOps._fs2ImgInfo.ext_info.config_sectors, imageOps._fs2ImgInfo.fw_sector_size, max_image_size)) {
return false;
}
//printf("-D- max image size : %d, image_size : %d\n",max_image_size, imageOps._fwImgInfo.ext_info.image_size);
}
-bool Fs2Operations::FwResetNvData(ProgressCallBack progressFunc)
+bool Fs2Operations::FwResetNvData()
{
- (void)progressFunc;
if (!_ioAccess->is_flash()) {
return errmsg("Cannot perform operation on Image");
u_int32_t devId = _ioAccess->get_dev_id();
if ( devId != CX3_HW_ID && devId != CX3_PRO_HW_ID ) {
// TODO: Indicate the device name.
- return errmsg("Unsupported device type %d", _fwImgInfo.ext_info.dev_type);
+ return errmsg("Unsupported device type(%d). Can only perform operation on CX3/CX3-PRO ", _fwImgInfo.ext_info.dev_type);
}
- // find configuration section base addr = (flash size - (config_sectors + config_pad)*sector_size)
+ if (_fs2ImgInfo.fw_sector_size == 0) {// if fw was generated with old mft i.e without the fw_sector_size than we dont allow this operation
+ return errmsg("Firmware was generated with old MFT, please use MFT-3.6.0 or above");
+ }
- u_int32_t sectorSize = _ioAccess->get_sector_size();
- u_int32_t AvailFlashSize = _fwImgInfo.actuallyFailsafe ? (_ioAccess->get_size()/2) : _ioAccess->get_size();
+ // find configuration section base addr = (flash size - (config_sectors + config_pad)*64k)
+
+ u_int32_t availFlashSize = _fwImgInfo.actuallyFailsafe ? (_ioAccess->get_size()/2) : _ioAccess->get_size();
+ u_int32_t fwSectorSz = _fs2ImgInfo.fw_sector_size != 0 ? _fs2ImgInfo.fw_sector_size : getDefaultSectorSz();
+ u_int32_t reservedArea = _fs2ImgInfo.ext_info.config_sectors * fwSectorSz;
+ reservedArea = reservedArea > MAX_CONFIG_AREA_SIZE ? MAX_CONFIG_AREA_SIZE : reservedArea;
u_int32_t configBaseAddr;
if (_fwImgInfo.actuallyFailsafe) {
- configBaseAddr = AvailFlashSize - ((_fs2ImgInfo.ext_info.config_sectors + _fs2ImgInfo.ext_info.config_pad) * sectorSize);
+ configBaseAddr = availFlashSize - (reservedArea + _fs2ImgInfo.ext_info.config_pad * fwSectorSz) ;
} else {
// For non FS image, there's an optional offset + 2 consecutive config areas
- configBaseAddr = AvailFlashSize - (_fs2ImgInfo.ext_info.config_sectors * 2 + _fs2ImgInfo.ext_info.config_pad) * sectorSize;
+ configBaseAddr = availFlashSize - (reservedArea* 2 + (_fs2ImgInfo.ext_info.config_pad * fwSectorSz));
}
//printf("-D- config_sectors:0x%x config_pads: 0x%x , sector_size:0x%x, configBaseAddr:0x%x, flashSize:0x%x\n",
- // _fs2ImgInfo.ext_info.config_sectors, _fs2ImgInfo.ext_info.config_pad, _ioAccess->get_sector_size(),configBaseAddr, AvailFlashSize);
+ //_fs2ImgInfo.ext_info.config_sectors, _fs2ImgInfo.ext_info.config_pad, fwSectorSz,configBaseAddr, availFlashSize);
- //erase addresses : configBaseAddr-AvailFlashSize
- for (u_int32_t eraseAddr=configBaseAddr; eraseAddr<AvailFlashSize; eraseAddr+=sectorSize ) {
+ //erase addresses : [configBaseAddr..AvailFlashSize]
+ u_int32_t sectorSize = _ioAccess->get_sector_size();
+ u_int32_t configEndAddr = availFlashSize - (_fs2ImgInfo.ext_info.config_pad * fwSectorSz);
+ for (u_int32_t eraseAddr=configBaseAddr; eraseAddr < configEndAddr; eraseAddr+=sectorSize ) {
if (!((Flash*)_ioAccess)->erase_sector(eraseAddr)) {
return errmsg("failed to erase configuration address: 0x%x. %s", eraseAddr, _ioAccess->err());
}
virtual bool FwSetVPD(char* vpdFileStr, PrintCallBack callBackFunc=(PrintCallBack)NULL);
virtual bool FwSetAccessKey(hw_key_t userKey, ProgressCallBack progressFunc=(ProgressCallBack)NULL);
virtual bool FwShiftDevData(PrintCallBack progressFunc=(PrintCallBack)NULL);
- virtual bool FwResetNvData(ProgressCallBack progressFunc=(ProgressCallBack)NULL);
+ virtual bool FwResetNvData();
virtual bool FwGetSection (u_int32_t sectType, std::vector<u_int8_t>& sectInfo);
bool isConfigurable;
u_int32_t infoSectPtr;
u_int32_t guidPtr;
+ u_int32_t fw_sector_size;
};
bool checkGen(u_int32_t beg,u_int32_t offs, u_int32_t& next, const char *pref, VerifyCallBack verifyCallBackFunc = (VerifyCallBack)NULL);
bool ParseInfoSect(u_int8_t* buff, u_int32_t byteSize);
bool Fs2IntQuery(bool readRom = true, bool isStripedImage=false);
- bool GetMaxImageSize(u_int32_t flash_size, bool image_is_fs, u_int32_t imgConfigSectors, u_int32_t &max_image_size);
+ u_int32_t getDefaultSectorSz();
+ bool GetMaxImageSize(u_int32_t flash_size, bool image_is_fs, u_int32_t imgConfigSectors, u_int32_t imgFwSectorSz, u_int32_t &max_image_size);
bool UpdateFullImageCRC(u_int32_t* buff, u_int32_t size, bool blank_guids);
bool Fs2FailSafeBurn(Fs2Operations &imageOps, bool allow_nofs, const char* pre_message,
ProgressCallBack progressFunc);
return errmsg("Set access key not supported.");
}
-bool Fs3Operations::FwResetNvData(ProgressCallBack progressFunc)
+bool Fs3Operations::FwResetNvData()
{
- (void)progressFunc;
return errmsg("Unsupported Device, can only reset configuration on a CX3/3-PRO device.");
/*
// future support for cx4
virtual bool FwSetVSD(char* vsdStr, ProgressCallBack progressFunc=(ProgressCallBack)NULL, PrintCallBack printFunc=(PrintCallBack)NULL);
virtual bool FwSetVPD(char* vpdFileStr, PrintCallBack callBackFunc=(PrintCallBack)NULL);
virtual bool FwSetAccessKey(hw_key_t userKey, ProgressCallBack progressFunc=(ProgressCallBack)NULL);
- virtual bool FwResetNvData(ProgressCallBack progressFunc=(ProgressCallBack)NULL);
+ virtual bool FwResetNvData();
virtual bool FwShiftDevData(PrintCallBack progressFunc=(PrintCallBack)NULL);
virtual bool FwSetVPD(char* vpdFileStr, PrintCallBack callBackFunc=(PrintCallBack)NULL) = 0;
virtual bool FwSetAccessKey(hw_key_t userKey, ProgressCallBack progressFunc=(ProgressCallBack)NULL) = 0;
virtual bool FwGetSection (u_int32_t sectType, std::vector<u_int8_t>& sectInfo)= 0;
- virtual bool FwResetNvData(ProgressCallBack progressFunc=(ProgressCallBack)NULL) = 0;
+ virtual bool FwResetNvData() = 0;
virtual bool FwShiftDevData(PrintCallBack progressFunc=(PrintCallBack)NULL) = 0;
void FwCleanUp();
if (dir->d_name[0] == '.') {
continue;
}
- sprintf(fname, "/sys/bus/pci/devices/%s/vendor", dir->d_name);
sz = strlen(dir->d_name);
+ if (sz > 4 && strcmp(dir->d_name + sz - 4, "00.0")) {
+ // Skip virtual functions
+ continue;
+ }
+ sprintf(fname, "/sys/bus/pci/devices/%s/vendor", dir->d_name);
f = fopen(fname, "r");
if (f == NULL) {
ndevs = -2;