简介
本文以DPU卡和BF卡举例,介绍智能网卡的加载适配流程
智能网卡介绍
智能网卡(SmartNIC)是一种高级网络接口卡,其具有传统NIC的功能,并在此基础上集成了额外的处理能力,使之能够支持执行更加复杂的网络任务,从而减轻主机CPU的负担,提高网络效率和性能。
智能网卡分类
智能网卡分为两类SDI(Service Drive Infrastructure)卡和DPU (Data Processing Unit)卡:
- SDI卡目前有:SDI V3 Lite、SDI V3、SDI V3.5、SDI 5.0、SDI 5.1、SDI5.0.C、SDI5.0 Lite、SDI6.0
- DPU卡目前有:SP923D、SP923Q、SP923H、SP925D
- 本文介绍常见的BlueFiled - 2和BlueFiled - 3也属于DPU卡
1.BF卡加载适配
1.1 识别方式
通过e2p加载
1.2 代码适配
代码仓
vpd
在vendor/Mellanox/路径下创建对应的csr路径,路径下创建csr文件,csr文件以四元组信息命
![]()
csr配置
- 配置PCIeDevice对象:定义PCIe设备的基本属性和类型
关键属性:- DeviceName:设备名称
- FunctionClass:功能类型
- DeviceType:设备类型
- SlotType:槽位类型
- FunctionProtocol:协议类型
"PCIeDevice_1": {
"DeviceName": "PCIe Card $ (MT42822 BlueField-2)",
"FunctionClass": 2,
"Position": "",
"DiagnosticFault": 0,
"PredictiveFault": 0,
"LinkSpeedReduced": 0,
"DeviceType": 8,
"CorrectableError": 0,
"UncorrectableError": 0,
"FatalError": 0,
"GroupPosition": "PCIeDevice_${GroupPosition}",
"Container": "${Container}",
"SlotType": "FullLength",
"FunctionProtocol": "PCIe",
"FunctionType": "Physical",
"PCIeDeviceType": "MultiFunction"
},
- 配置PCIeCard对象:定义PCIe卡的基本信息和属性
关键属性:- Name:名称
- Description:描述
- VendorID:厂商ID
- DeviceID:设备ID
- SubVendorID:子厂商ID
- SubDeviceID:子设备ID
- Model:型号
"PCIeCard_1": {
"SlotID": "<=/PCIeDevice_1.SlotID",
"NodeID": "<=/PCIeDevice_1.SlotID |> string.format('PCIeCard%s',$1)",
"Name": "MBF2H332A-AENOT",
"BoardName": "MT42822 BlueField-2",
"Description": "MT42822 BlueField-2 integrated ConnectX-7 network controller",
"FunctionClass": 2,
"VendorID": 5555,
"DeviceID": 41686,
"SubVendorID": 5555,
"SubDeviceID": 96,
"PartNumber": "MBF2H332A-AENOT",
"Position": "<=/PCIeDevice_1.Position",
"LaneOwner": "<=/PCIeDevice_1.SocketID",
"FirmwareVersion": "<=/NetworkAdapter_1.FirmwareVersion",
"Manufacturer": "Mellanox",
"Health": "<=/Component_PCIeCard.Health",
"Model": "BF2",
"DeviceName": "<=/PCIeDevice_1.DeviceName",
"PcbVersion": "",
"Bus": "<=/PCIeDevice_1.Bus",
"Device": "<=/PCIeDevice_1.Device",
"Function": "<=/PCIeDevice_1.Function",
"DevBus": "<=/PCIeDevice_1.DevBus",
"DevDevice": "<=/PCIeDevice_1.DevDevice",
"DevFunction": "<=/PCIeDevice_1.DevFunction",
"SerialNumber": "<=/FruData_BF2.BoardSerialNumber |> expr(string.gsub($1, '%s+$','') )"
},
- 配置NetworkAdapter对象:定义网络适配器的功能和特性
关键属性:- Name:名称
- Description:描述
- Manufacturer:厂商
- NetworkPortCount:端口数量
- LinkSpeedCapability:链路支持速率
- LinkWidthCapability:链路支持带宽
"NetworkAdapter_1": {
"SystemID": 1,
"SlotNumber": "<=/PCIeDevice_1.SlotID",
"Name": "MBF2H332A-AENOT",
"Manufacturer": "Mellanox",
"Description": "2*25GE",
"Position": "<=/PCIeDevice_1.Position",
"DeviceLocator": "<=/PCIeDevice_1.DeviceName",
"Type": 3,
"Model": "BF2",
"ModelDescription": "2*25GE",
"ChipVendor": "Mellanox",
"ChipManufacturer": "<=/PCIeCard_1.Manufacturer",
"NetworkPortCount": 2,
"BoardName": "MT42822 BlueField-2",
"VendorID": "0x15b3",
"DeviceID": "0xa2d6",
"SubsystemVendorID": "0x15b3",
"SubsystemDeviceID": "0x0060",
"ComponentUniqueID": "",
"PCBVersion": "<=/PCIeCard_1.PcbVersion",
"FruId": 255,
"SupportedMctp": true, // 是否支持MCTP
"HotPluggable": false, // 是否支持热拔插
"ReadyToRemove": false,
"AttentionHotPlugState": 255,
"SocketId": "<=/PCIeDevice_1.SocketID",
"Bus": "<=/PCIeDevice_1.Bus",
"Device": "<=/PCIeDevice_1.Device",
"Function": "<=/PCIeDevice_1.Function",
"DevBus": "<=/PCIeDevice_1.DevBus",
"DevDevice": "<=/PCIeDevice_1.DevDevice",
"DevFunction": "<=/PCIeDevice_1.DevFunction",
"LinkSpeed": "",
"LinkSpeedCapability": "Gen5 (32.0GT/s)",
"LinkWidth": "",
"LinkWidthCapability": "X8",
"TemperatureCelsius": 0,
"TemperatureStatus": 0,
"BandwidthThresholdPercent": 100,
"ParentCardSlotId": 255,
"Health": "<=/Component_PCIeCard.Health",
"SerialNumber": "<=/PCIeCard_1.SerialNumber"
},
- 配置NetworkPort对象:定义网口对象属性和能力
关键属性:- PortID:端口ID
- NetDevFuncType:设备功能类型
- MediumType:介质类型
- SupportedLinkCapability:链路能力
"NetworkPort_1": {
"@Parent": "NetworkAdapter_1",
"SystemID": 1,
"PortID": 0,
"NetDevFuncType": 1,
"MediumType": "FiberOptic",
"SupportedLinkCapability": "25GE"
},
- 配置OpticalModule对象:定义光模块对象的属性
关键属性:- ChannelNum:端口ID
- Temp_UpperThresholdCritical:温度上限阈值
- LowerThresholdCritical:下限阈值
- UpperThresholdCritical:上限阈值
"OpticalModule_1": {
"@Parent": "NetworkPort_1",
"ChannelNum": 1,
"TemperatureCelsius": 0,
"PowerState": 0,
"Presence": 1,
"IsSupportedType": 0,
"Temp_UpperThresholdCritical": 125,
"FaultState": 0,
"SupplyVoltage": 0,
"LowerThresholdCritical": 0,
"UpperThresholdCritical": 0
},
- 配置Scanner_NICTemp对象:定义网卡温度扫描对象信息
"Chip_TempChip": {
"Address": 62,
"AddrWidth": 1,
"OffsetWidth": 1,
"WriteTmout": 100,
"ReadTmout": 100,
"HealthStatus": 0
},
"Scanner_NICTemp": {
"Chip": "#/Chip_TempChip",
"Size": 1,
"Offset": 1,
"Mask": 65535,
"Period": 1000,
"Type": 0,
"Debounce": "#/MidAvg_NICTemp"
},
- 配置ThresholdSensor_XXXX对象:定义阈值传感器信息
关键属性:- AssertMask:断言掩码
- DeassertMask:取消断言掩码
- UpperNoncritical:上限非临界值
- PositiveHysteresis:正向迟滞量
- NegativeHysteresis:负向迟滞量
"ThresholdSensor_Temp": {
"AssertMask": 128,
"DeassertMask": 28800,
"ReadingMask": 2056,
"Linearization": 0,
"M": 100,
"RBExp": 224,
"UpperNoncritical": 104,
"PositiveHysteresis": 2,
"NegativeHysteresis": 2
},
"ThresholdSensor_OpticalModuleTemp": {
"AssertMask": 128,
"DeassertMask": 28800,
"ReadingMask": 2056,
"Linearization": 0,
"M": 1,
"UpperNoncritical": 70,
"PositiveHysteresis": 2,
"NegativeHysteresis": 2
},
- 配置CoolingRequirement_X:定义散热需求的控制参数
关键属性:- RequirementId:需求ID
- MonitoringStatus:监控状态
- MonitoringValue:监控值
- FailedValue:失效调速值
- TargetTemperatureCelsius:目标温度
- MaxAllowedTemperatureCelsius:触发全速温度
- SmartCoolingTargetTemperature:智能调速目标温度
"CoolingRequirement_1_88": {
"RequirementId": "${Slot} |> expr((88 << 8) | $1)", // ID与上一行ID一致
"Description": "BF2网卡芯片调速",
"MonitoringStatus": "<=/Scanner_NICTemp.Status",
"MonitoringValue": "<=/Scanner_NICTemp.Value",
"FailedValue": 80,
"TargetTemperatureCelsius": 90,
"MaxAllowedTemperatureCelsius": 100,
"TargetTemperatureRangeCelsius": [],
"SmartCoolingTargetTemperature": [],
"CustomSupported": false,
"ActiveInStandby": true,
"CustomTargetTemperatureCelsius": 255,
"Enabled": "<=/CoolingRequirement_1_96.MonitoringStatus |> expr($1 == 0 ? true : false)",
"SensorName": "#/ThresholdSensor_Temp.SensorName"
},
配置调速策略还要在产品仓的psr中配置CoolingArea,其AreaId与CoolingRequirement的RequirementId一致:
关键属性:
+ AreaId:调速策略ID
+ FanIdxGroup:风扇序号列表
"CoolingArea_1_88": {
"AreaId": 88, // ID与上一行ID一致,与RequirementId一致
"RequirementIdx": 88, // ID与上一行ID一致
"PolicyIdxGroup": [],
"FanIdxGroup": [
1,
2,
3,
4
]
},
- 配置Event_XXXX告警和事件:定义告警和事件的上报规则
- csr配置
关键属性:- EventKeyId:事件标识ID
- Condition:告警门限值
- Hysteresis:迟滞量
"Event_OverTemp": {
"EventKeyId": "PCIeCard.PCIeCardOverTemp",
"Condition": "<=/ThresholdSensor_Temp.UpperNoncritical",
"Hysteresis": "<=/ThresholdSensor_Temp.PositiveHysteresis"
},
- soft csr配置
关键属性:- Reading:告警读数
- Condition:告警门限值
- OperatorId:判断符号:1:小于 2:小于等于 3:大于 4:大于等于 5:等于 6:不等于 7:上升沿0->1产生,1->0恢复 8:下降沿1->0产生,0->1恢复
- AdditionalInfo:第X个动态参数
- DescArgx:动态参数
"Event_OverTemp": {
"Reading": "<=/Scanner_NICTemp.Value |> expr(($1 >= 128) ? ($1 - 256) : $1)",
"@Default": {
"Condition": 105
},
"OperatorId": 4,
"Enabled": true,
"Component": "#/Component_PCIeCard",
"AdditionalInfo": "1",
"DescArg2": "#/Component_PCIeCard.Name",
"DescArg4": "#/Event_OverTemp.Reading",
"DescArg5": "#/ThresholdSensor_Temp.UpperNoncritical"
},
EventKeyId配置在vpd仓vendor/event_def.json中
关键属性:
+ EventCode:事件码
+ EventType:事件类型
+ LifeCycleId:事件生命周期
+ DeassertFlag:是否可以恢复
+ EventKeyId:事件标识ID
{
"EventCode": "0x08000003",
"ReportChannel": 65535,
"OldEventCode": "0x0147FFFF",
"EventType": 0,
"LifeCycleId": 1,
"DeassertFlag": 1,
"EventKeyId": "PCIeCard.PCIeCardOverTemp",
"SeverityId": 1,
"ActionId": 0,
"EventName": "PCIeCardOverTemp"
},
...
{
"Suggestion": {
"En": "1. Check for fan alarms.@#AB;2. Check the equipment room temperature.@#AB;3. Check for air inlet or outlet blockage.@#AB;4. Replace the PCIe card.",
"Zh": "1. 检查服务器是否存在风扇告警。@#AB;2. 检查机房环境温度是否已超出服务器设备运行环境要求。@#AB;3. 检查服务器进风口/出风口是否有异物堵塞。@#AB;4. 更换PCIe标卡。"
},
"EventKeyId": "PCIeCard.PCIeCardOverTemp",
"Description": {
"En": "The %1 %2 %3 temperature (%4 degrees C) exceeds the overtemperature threshold (%5 degrees C).",
"Zh": "The %1 %2 %3 temperature (%4 degrees C) exceeds the overtemperature threshold (%5 degrees C)."
},
"Influence": {
"En": "",
"Zh": ""
},
"Cause": {
"En": "",
"Zh": ""
}
},
csr加载
在产品仓对应的产品的profile.txt下,配置新增的csr文件,将csr打包到对应的版本,路径信息参考其他产品配置
1.3 ncsi协议介绍
BF系列卡当前以网卡的方式加载,卡侧信息需要通过ncsi协议读取
代码仓
network_adapter
在src/lualib/hardware_config路径下创建对应BF卡的lua文件,文件名与BF卡的NetworkAdapter对象中的Model属性一致,配置需注意
![]()
命令配置
properties = {
GetOSStatus = {
protocol = 'ncsi_mellanox',
action = 'on_schedule',
period_in_sec = 2,
request = {
channel_id = 0x1F,
cmd_mellanox = 0x00,
mellanox_cmd_id = 0x13,
parameter = 0x17,
extra_cmd = 0x00
},
response = function(data)
local r = bs.new([[<<
_:32,
os_status:8
>>]]):unpack(data, true)
return r.os_status
end
}
}
字段介绍
- properties:properties中配置接口/方法配置信息,接口包含protocol、action、request、response等信息;
- protocol:协议,当前支持ncsi_standard、ncsi_mellanox、ncsi_huawei协议,针对不同厂商的板卡选取对应的协议;
- action:行为,包含on_demand和on_schedule两种类型,on_demand表示仅读取一次,on_schedule表示每隔多久读取一次;
- period_in_sec:仅在action为on_schedule时需要配置且生效,表示循环读取是间隔的时长;
- request:请求,其中包含channel_id、package_id、cmd、parameter等信息,根据厂商提供的指导进行配置;
- response:响应,返回一个二进制,需要进行unpack,参考厂商提供的指导对二进制进行解析,获取返回;
2.DPU卡加载适配
2.1 识别方式
通过四元组加载
2.2 代码适配
DPU卡csr配置在私仓,需要开发者进行适配后打包到版本包中,以四元组对csr进行命名,BMC升级后,csr在/opt/bmc/sr路径下
csr配置
- 配置PCIeDevice对象:定义PCIe设备的基本属性和类型
关键属性:- DeviceName:设备名称
- FunctionClass:功能类型
- DeviceType:设备类型
- SlotType:槽位类型
- FunctionProtocol:协议类型
"PCIeDevice_1": {
"DeviceName": "PCIe Card $ (XXXX)",
"DeviceType": 8,
"FunctionClass": 11,
"DiagnosticFault": 0,
"PredictiveFault": 0,
"LinkSpeedReduced": 0,
"Container": "${Container}",
"GroupPosition": "PCIeDevice_${GroupPosition}",
"PCIeDeviceType": "MultiFunction",
"SlotType": "FullLength",
"FunctionProtocol": "PCIe",
"FunctionType": "Physical"
},
- 配置DPUCard对象:定义DPU卡对象的属性
关键属性:- Model:型号
- PCIeModel:PCIe型号
- Name:名称
- PartNumber:部件编号
- NICBoardName:NIC板名称
"DPUCard_1": {
"Model": "AAAA",
"PCIeModel": "BBBB",
"Name": "XXXX",
"BoardID": 239,
"BoardName": "AAAA",
"PartNumber": "CCCC",
"Description": "XXXX",
"M2SlotMaxCount": 2,
"NetworkAdapterMaxCount": 2,
"StorageIpAddr": "0.0.0.0",
"FunctionClass": 11,
"CPLDCount": 2,
"CPUBoardName": "AAAA",
"NICBoardName": "DDDD",
"SlotID": "<=/PCIeDevice_1.SlotID",
"NodeID": "<=/PCIeDevice_1.SlotID |> string.format('PCIeCard%s',$1)",
"Manufacturer": "Huawei",
"PcbVersion": "<=/Fru_DPUCard.PcbVersion",
"RefChip": "#/Chip_MCU",
"RefIdChip": "#/Chip_PcbId",
"Health": "<=/Component_DPUCard.Health;<=/Component_PCIeCard.Health;<=/Component_Cable.Health |> expr(($1 > 0 || $2 > 0 || $3 > 0) ? (($1 >= $2 && $1 >= $3) ? $1 : (($2 >= $1 && $2 >= $3) ? $2 : $3)) : 0)",
"HeartBeatLoss": 0,
"SystemLoadedStatus": 0,
"PowerState": "Off",
"SerialRecordConnect": [
{
"Source": "UART4 COM",
"Destination": "CARD COM",
"SrcSerial": 4,
"DestSerial": 21
}
],
"RefFrudata": "#/FruData_DPUCard",
"RefNetCard": "#/NetworkAdapter_1",
"LinkWidthCapability": "<=/NetworkAdapter_1.LinkWidthCapability",
"LinkSpeedCapability": "<=/NetworkAdapter_1.LinkSpeedCapability",
"LinkWidth": "<=/NetworkAdapter_1.LinkWidth",
"LinkSpeed": "<=/NetworkAdapter_1.LinkSpeed",
"VendorID": "#/NetworkAdapter_1.VendorID",
"DeviceID": "#/NetworkAdapter_1.DeviceID",
"SubVendorID": "#/NetworkAdapter_1.SubsystemVendorID",
"SubDeviceID": "#/NetworkAdapter_1.SubsystemDeviceID",
"Position": "<=/PCIeDevice_1.Position",
"LaneOwner": "<=/PCIeDevice_1.SocketID",
"DeviceName": "<=/PCIeDevice_1.DeviceName",
"SRVersion": "${DataVersion}",
"UID": "0123456789ABCDEFGH",
"SerialNumber": "<=/FruData_DPUCard.BoardSerialNumber",
"FirmwareVersion": "<=/NetworkAdapter_1.FirmwareVersion"
},
- 配置NetworkAdapter对象:定义网络适配器的功能和特性
关键属性:- Name:名称
- Description:描述
- Manufacturer:厂商
- NetworkPortCount:端口数量
- LinkSpeedCapability:链路支持速率
- LinkWidthCapability:链路支持带宽
"SystemID": 1,
"SlotNumber": "<=/PCIeDevice_1.SlotID",
"NodeID": "<=/PCIeDevice_1.SlotID |> string.format('PCIeCard%s',$1)",
"Name": "XXXX",
"Manufacturer": "Huawei",
"Description": "6*25GE",
"Position": "<=/PCIeDevice_1.Position",
"DeviceLocator": "<=/PCIeDevice_1.DeviceName",
"Type": 3,
"Model": "AAAA",
"ModelDescription": "6*25GE",
"ChipVendor": "Huawei",
"ChipManufacturer": "Huawei",
"NetworkPortCount": 6,
"BoardID": 239,
"VendorID": "0x19e5",
"DeviceID": "0x0224",
"SubsystemVendorID": "0x19e5",
"SubsystemDeviceID": "0x0356",
"ComponentUniqueID": "0123456789ABCDEFGH",
"PCBVersion": "<=/DPUCard_1.PcbVersion",
"@Default": {
"PCBVersion": ".A"
},
"FruId": "<=/FruData_DPUCard.FruId",
"SupportedMctp": true,
"SupportedLLDP": true,
"HotPluggable": false,
"ReadyToRemove": false,
"AttentionHotPlugState": 255,
"SocketId": "<=/PCIeDevice_1.SocketID",
"Bus": "<=/PCIeDevice_1.Bus",
"Device": "<=/PCIeDevice_1.Device",
"Function": "<=/PCIeDevice_1.Function",
"DevBus": "<=/PCIeDevice_1.DevBus",
"DevDevice": "<=/PCIeDevice_1.DevDevice",
"DevFunction": "<=/PCIeDevice_1.DevFunction",
"SpecialPcieCard": true,
"LinkWidthCapability": "N/A",
"LinkSpeedCapability": "N/A",
"LinkWidth": "N/A",
"LinkSpeed": "N/A",
"TemperatureCelsius": 0,
"TemperatureStatus": 0,
"ParentCardSlotId": "<=/PCIeDevice_1.SlotID",
"FaultState": 0,
"Health": "<=/Component_DPUCard.Health;<=/Component_PCIeCard.Health;<=/Component_Cable.Health |> expr(($1 > 0 || $2 > 0 || $3 > 0) ? (($1 >= $2 && $1 >= $3) ? $1 : (($2 >= $1 && $2 >= $3) ? $2 : $3)) : 0)",
"PfMacInfo":"<=/DPUCard_1.PfMacInfo"
},
- 配置NetworkPort_X对象定义网口对象属性和能力
关键属性:- PortID:端口ID
- NetDevFuncType:设备功能类型
- MediumType:介质类型
- SupportedLinkCapability:链路能力
"NetworkPort_1": {
"@Parent": "NetworkAdapter_1",
"SystemID": 1,
"PortID": 0,
"NetDevFuncType": 1,
"MediumType": "FiberOptic",
"SupportedLinkCapability": "25GE",
"WorkloadType" : 0
},
- 配置OpticalModule_X对象:定义光模块对象的属性
关键属性:- ChannelNum:端口ID
"OpticalModule_1": {
"@Parent": "NetworkPort_1",
"ChannelNum": 1
},
- 配置CoolingRequirement_X对象:定义散热需求的控制参数
关键属性:- RequirementId:需求ID
- MonitoringStatus:监控状态
- MonitoringValue:监控值
- FailedValue:失效调速值
- TargetTemperatureCelsius:目标温度
- MaxAllowedTemperatureCelsius:触发全速温度
"CoolingRequirement_1_1": {
"RequirementId": 1,
"Description": "计算板主芯片调速",
"MonitoringStatus": "<=/DPUCard_1.CPUTemperatureCelsius |> expr(($1 == 32767) ? 1 : 0)",
"MonitoringValue": "<=/DPUCard_1.CPUTemperatureCelsius |> expr(($1 == 0 || $1 > 200) ? 40 : ($1 & 255))",
"FailedValue": 80,
"TargetTemperatureCelsius": 90,
"MaxAllowedTemperatureCelsius": 100,
"ActiveInStandby": true
},
- 配置CoolingArea_X对象:定义散热风扇的控制参数
关键属性:- AreaId:调速策略ID
- FanIdxGroup:风扇序号列表
"CoolingArea_1_1": {
"AreaId": 1,
"RequirementIdx": 1,
"PolicyIdxGroup": [],
"FanIdxGroup": [
1,
2,
3,
4
]
},
- 配置Event告警和事件:定义告警和事件的上报规则
关键属性:- EventKeyId:事件标识ID
- Condition:告警门限值
- Hysteresis:迟滞量
- Reading:告警读数
- Condition:告警门限值
- OperatorId:判断符号:1:小于 2:小于等于 3:大于 4:大于等于 5:等于 6:不等于 7:上升沿0->1产生,1->0恢复 8:下降沿1->0产生,0->1恢复
- AdditionalInfo:第X个动态参数
- DescArgx:动态参数
"Event_PCIeCardPowerOn": {
"EventKeyId": "PCIeCard.PCIeCardOSBootUp",
"Reading": "<=/DPUCard_1.PowerState |> string.cmp($1, 'On') |> expr($1 ? 1 : 0)",
"ResumeEnable": 1,
"Condition": 1,
"OperatorId": 7,
"Hysteresis": 0,
"Enabled": true,
"AdditionalInfo": "2,4",
"DescArg1": "",
"DescArg2": "#/Component_DPUCard.Instance",
"DescArg3": "SP923H-VL",
"DescArg4": "system power-on success",
"Component": "#/Component_DPUCard"
},
csr加载
在产品仓对应的产品的profile.txt下,配置新增的csr文件,将csr打包到对应的版本,路径信息参考其他产品配置
2.3 smbus协议介绍
BMC通过smbus协议与mcu通信,获取DPU卡相关信息
代码仓
general_hardware
代码路径:src/lualib/protocol/std_smbus.lua
协议配置
以opcode 0x1005举例:
function std_smbus:GetSystemStatus(data)
local recv_data = self:_send_and_receive_request_in_frames({
lun = 0x80,
arg = 0x00,
opcode = 0x1005,
offset = 0x00,
length = #data,
data = data
}, 2)
return bs.new([[<<type,status>>]]):unpack(recv_data, true)
end
请求解析
| 字节顺序 | 参数字段 | 参数内容 |
|---|---|---|
| 1 | lun/flag | bit0 - bit6:保留; bit7 = 1:表示最后一帧; bit7 = 0:表示数据未写完; |
| 2 | request args | 0x00:v1版本,该参数无效,参数通过request data传递; other:使用此参数,配置内容为对应opcode的TLV定义的Type字段 |
| 3-4 | opcode | 操作命令字,不同的命令字有不同的功能和TLV定义 |
| 5-8 | offset | 0 |
| 9-12 | length | request data的长度 |
| 13-N | request data | 仅在request args为0的时候需要配置,配置内容为对应opcode的TLV定义的Type字段 |
响应解析
当前对于smbus协议的响应,在_send_and_receive_request_in_frames方法中已进行部分解析,将response data返回,用户只需要unpack response data即可
| 字节顺序 | 参数字段 | 参数内容 |
|---|---|---|
| 1-2 | error_code | 0:成功; 其他为错误码; |
| 3-4 | opcode | 操作命令字,与请求的操作命令字一致 |
| 5-8 | total_length | response长度 |
| 9-12 | length | 数据长度 |
| 13-N | response data | request args为0时,字段含义如下: BYTE[0]:运行状态1的Type, BYTE[1]:运行状态1的Value; request args非0时,BYTE[0]:request args对应TLV定义的Value字段 |