1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
/*
* Copyright (C) Jan 2019 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 <sstream>
#include "mlxreg_lib.h"
#include "cmdif/icmd_cif_open.h"
#ifndef MST_UL
#include <tools_layouts/adb_dbs.h>
#endif
#include <tools_layouts/prm_adb_db.h>
#include <common/tools_utils.h>
#include <mlxreg_exception.h>
#define REG_ACCESS_UNION_NODE "access_reg_summary"
using namespace mlxreg;
const int MlxRegLib::RETRIES_COUNT = 3;
const int MlxRegLib::SLEEP_INTERVAL = 100;
MlxRegLib::MlxRegLib(mfile *mf, string extAdbFile, bool isExternal)
{
_mf = mf;
_isExternal = isExternal;
try {
if (_isExternal && extAdbFile == "") {
dm_dev_id_t devID = getDevId();
extAdbFile = PrmAdbDB::getDefaultDBName(dm_dev_is_switch(devID));
}
initAdb(extAdbFile);
} catch (MlxRegException& adbInitExp) {
if (_adb) {
delete _adb;
}
throw adbInitExp;
}
string unionNode = REG_ACCESS_UNION_NODE;
string rootNode = unionNode + "_selector";
if (_isExternal) {
rootNode = rootNode + "_ext";
}
_regAccessRootNode = _adb->createLayout(rootNode);
if (!_regAccessRootNode) {
throw MlxRegException("No supported access registers found");
}
_regAccessUnionNode = _regAccessRootNode->getChildByPath(unionNode);
if (!_regAccessUnionNode) {
throw MlxRegException("No supported access registers found");
}
if (!_regAccessUnionNode->isUnion()) {
throw MlxRegException("No supported access registers found");
}
try
{
_regAccessMap = _regAccessUnionNode->unionSelector->getEnumMap();
}
catch (AdbException& exp)
{
throw MlxRegException("Failed to extract registers info. %s", exp.what());
}
// Set error map
std::map<int, std::string> errmap;
errmap[MRLS_SUCCESS] = "Success";
errmap[MRLS_GENERAL] = "General error";
updateErrCodes(errmap);
}
/************************************
* Function: ~MlxRegLib
************************************/
MlxRegLib::~MlxRegLib()
{
if (_regAccessRootNode) {
delete _regAccessRootNode;
}
if (_adb) {
delete _adb;
}
}
dm_dev_id_t MlxRegLib::getDevId()
{
return getDevId(_mf);
}
dm_dev_id_t MlxRegLib::getDevId(mfile *mf)
{
dm_dev_id_t devID = DeviceUnknown;
u_int32_t hwDevID = 0;
u_int32_t hwChipRev = 0;
if (dm_get_device_id(mf, &devID, &hwDevID, &hwChipRev)) {
throw MlxRegException("Failed to read device ID");
}
return devID;
}
bool MlxRegLib::isDeviceSupported(mfile *mf)
{
dm_dev_id_t devID = getDevId(mf);
return devID != DeviceConnectX2 && devID != DeviceConnectX3 && devID != DeviceConnectX3Pro && devID != DeviceSwitchX;
}
void MlxRegLib::initAdb(string extAdbFile)
{
_adb = new Adb();
if (extAdbFile != "") {
if (!_adb->load(extAdbFile, false, NULL, false)) {
throw MlxRegException("Failure in loading Adabe file. %s", _adb->getLastError().c_str());
}
} else {
throw MlxRegException("No Adabe was provided, please provide Adabe file to continue");
}
}
/************************************
* Function: findAdbNode
************************************/
AdbInstance* MlxRegLib::findAdbNode(string name)
{
if (_regAccessMap.find(name) == _regAccessMap.end()) {
throw MlxRegException("Can't find access register name: %s", name.c_str());
}
return _regAccessUnionNode->getUnionSelectedNodeName(name);
}
/************************************
* Function: showRegister
************************************/
MlxRegLibStatus MlxRegLib::showRegister(string regName, std::vector<AdbInstance*> &fields)
{
AdbInstance *adbNode = findAdbNode(regName);
fields = adbNode->getLeafFields();
return MRLS_SUCCESS;
}
/************************************
* Function: showRegisters
************************************/
MlxRegLibStatus MlxRegLib::showRegisters(std::vector<string> ®s)
{
for (std::map<string, u_int64_t>::iterator it = _regAccessMap.begin(); it != _regAccessMap.end(); ++it) {
regs.push_back(it->first);
}
return MRLS_SUCCESS;
}
/************************************
* Function: sendMaccessReg
************************************/
int MlxRegLib::sendMaccessReg(u_int16_t regId, int method, std::vector<u_int32_t> &data)
{
int status;
int rc;
std::vector<u_int32_t> temp_data;
copy(data.begin(), data.end(), back_inserter(temp_data));
int i = RETRIES_COUNT;
do {
rc = maccess_reg(_mf,
regId,
(maccess_reg_method_t)method,
(u_int32_t*)&data[0],
(sizeof(u_int32_t) * data.size()),
(sizeof(u_int32_t) * data.size()),
(sizeof(u_int32_t) * data.size()),
&status);
if ((rc != ME_ICMD_STATUS_IFC_BUSY &&
status != ME_REG_ACCESS_BAD_PARAM) ||
!(_mf->flags & MDEVS_REM)) {
break;
}
data.clear();
copy(temp_data.begin(), temp_data.end(), back_inserter(data));
msleep(SLEEP_INTERVAL);
} while(i-->0);
temp_data.clear();
return rc;
}
/************************************
* Function: sendRegister
************************************/
MlxRegLibStatus MlxRegLib::sendRegister(string regName, int method, std::vector<u_int32_t> &data)
{
u_int16_t regId = (u_int16_t)_regAccessMap.find(regName)->second;
int rc;
rc = sendMaccessReg(regId, method, data);
if (rc) {
throw MlxRegException("Failed to send access register: %s", m_err2str((MError)rc));
}
return MRLS_SUCCESS;
}
/************************************
* Function: sendRegister
************************************/
MlxRegLibStatus MlxRegLib::sendRegister(u_int16_t regId, int method, std::vector<u_int32_t> &data)
{
int rc;
rc = sendMaccessReg(regId, method, data);
if (rc) {
throw MlxRegException("Failed send access register: %s", m_err2str((MError)rc));
}
return MRLS_SUCCESS;
}
/************************************
* Function: getLastErrMsg
************************************/
string MlxRegLib::getLastErrMsg()
{
std::stringstream sstm;
int lastErrCode = getLastErrCode();
string errCodeStr = err2Str(lastErrCode);
string errStr = err();
sstm << errCodeStr;
if (errStr != errCodeStr) {
sstm << ": " << errStr;
}
return sstm.str();
}
/************************************
* Function: isRegSizeSupported
************************************/
bool MlxRegLib::isRegSizeSupported(string regName)
{
AdbInstance *adbNode = _regAccessUnionNode->getUnionSelectedNodeName(regName);
return (((adbNode->size >> 3) <= (u_int32_t)mget_max_reg_size(_mf, MACCESS_REG_METHOD_SET)) ||
((adbNode->size >> 3) <= (u_int32_t)mget_max_reg_size(_mf, MACCESS_REG_METHOD_GET)));
}
/************************************
* Function: isAccessRegisterSupported
************************************/
void MlxRegLib::isAccessRegisterSupported(mfile *mf)
{
int status;
struct icmd_hca_icmd_query_cap_general icmd_cap;
int i = RETRIES_COUNT;
do {
memset(&icmd_cap, 0, sizeof(icmd_cap));
status = get_icmd_query_cap(mf, &icmd_cap);
if(!(status || icmd_cap.allow_icmd_access_reg_on_all_registers == 0))
break;
msleep(SLEEP_INTERVAL);
} while (i-- > 0);
if (status || icmd_cap.allow_icmd_access_reg_on_all_registers == 0) {
throw MlxRegException("FW burnt on device does not support generic access register");
}
}
/************************************
* Function: isAccessRegisterGMPSupported
************************************/
bool MlxRegLib::isAccessRegisterGMPSupported(maccess_reg_method_t reg_method)
{
return (bool)(supports_reg_access_gmp(_mf, reg_method));
}
/************************************
* Function: isIBDevice
************************************/
bool MlxRegLib::isIBDevice()
{
return (bool)(_mf->flags & MDEVS_IB);
}
|