113f3ef11SPatrick Venture# My First Sensors 213f3ef11SPatrick Venture 313f3ef11SPatrick VentureThis document is meant to bring you from nothing to using Entity-Manager with 413f3ef11SPatrick VentureDbus-Sensors to populate a plug-in card's sensor values on dbus. Once the sensor 5fa8ee87eSPatrick Williamsvalues are on dbus, they can be read via IPMI or Redfish (doing so is beyond the 6fa8ee87eSPatrick Williamsscope of this guide). 713f3ef11SPatrick Venture 8fa8ee87eSPatrick WilliamsFor the sake of this example, let's pretend there is a PCIe card that exposes an 9fa8ee87eSPatrick Williams24c02 eeprom and a tmp441 sensor. The PCIe slots are behind an smbus mux on the 10fa8ee87eSPatrick Williamsmotherboard and are in a device-tree such as this: 1113f3ef11SPatrick Venture 12ec1137d5SPatrick Williams```dts 1313f3ef11SPatrick Venturealiases { 1413f3ef11SPatrick Venture i2c16 = &i2c_pe0; 1513f3ef11SPatrick Venture i2c17 = &i2c_pe1; 1613f3ef11SPatrick Venture i2c18 = &i2c_pe2; 1713f3ef11SPatrick Venture i2c19 = &i2c_pe3; 1813f3ef11SPatrick Venture}; 1913f3ef11SPatrick Venture 2013f3ef11SPatrick Venture... 2113f3ef11SPatrick Venture 2213f3ef11SPatrick Venture&i2c1 { 2313f3ef11SPatrick Venture status = "okay"; 2413f3ef11SPatrick Venture i2c-switch@71 { 2513f3ef11SPatrick Venture compatible = "nxp,pca9546"; 2613f3ef11SPatrick Venture reg = <0x71>; 2713f3ef11SPatrick Venture #address-cells = <1>; 2813f3ef11SPatrick Venture #size-cells = <0>; 2913f3ef11SPatrick Venture i2c-mux-idle-disconnect; 3013f3ef11SPatrick Venture 3113f3ef11SPatrick Venture i2c_pe0: i2c@0 { 3213f3ef11SPatrick Venture #address-cells = <1>; 3313f3ef11SPatrick Venture #size-cells = <0>; 3413f3ef11SPatrick Venture reg = <0>; 3513f3ef11SPatrick Venture }; 3613f3ef11SPatrick Venture i2c_pe1: i2c@1 { 3713f3ef11SPatrick Venture #address-cells = <1>; 3813f3ef11SPatrick Venture #size-cells = <0>; 3913f3ef11SPatrick Venture reg = <1>; 4013f3ef11SPatrick Venture }; 4113f3ef11SPatrick Venture i2c_pe2: i2c@2 { 4213f3ef11SPatrick Venture #address-cells = <1>; 4313f3ef11SPatrick Venture #size-cells = <0>; 4413f3ef11SPatrick Venture reg = <2>; 4513f3ef11SPatrick Venture }; 4613f3ef11SPatrick Venture i2c_pe3: i2c@3 { 4713f3ef11SPatrick Venture #address-cells = <1>; 4813f3ef11SPatrick Venture #size-cells = <0>; 4913f3ef11SPatrick Venture reg = <3>; 5013f3ef11SPatrick Venture }; 5113f3ef11SPatrick Venture }; 5213f3ef11SPatrick Venture}; 5313f3ef11SPatrick Venture``` 5413f3ef11SPatrick Venture 5513f3ef11SPatrick VentureThe first daemon of interest that will run is the FruDevice portion of 56fa8ee87eSPatrick WilliamsEntity-Manager. The exact layout of a FRU is beyond the scope of this guide, but 57fa8ee87eSPatrick Williamsassume the PCIe card's eeprom holds the following information: 5813f3ef11SPatrick Venture 59ec1137d5SPatrick Williams```text 6013f3ef11SPatrick VentureProduct: 6113f3ef11SPatrick Venture MANUFACTURER "Awesome" 6213f3ef11SPatrick Venture PART_NUMBER "12345" 6313f3ef11SPatrick Venture PRODUCT_NAME "Super Great" 6413f3ef11SPatrick Venture SERIAL_NUMBER "12312490840" 6513f3ef11SPatrick Venture``` 6613f3ef11SPatrick Venture 6713f3ef11SPatrick VentureThe FruDevice daemon will walk all i2c buses and attempt to find FRU contents at 6813f3ef11SPatrick Ventureresponsive smbus addresses. When if finds a FRU it will parse the contents and 6913f3ef11SPatrick Venturepublish them to dbus keying off the most prominent name field. In this case, it 7013f3ef11SPatrick Venturefound two of the cards. One at bus 18 and the other at 19. 7113f3ef11SPatrick Venture 7213f3ef11SPatrick VentureThe dbus tree for this will look like: ``` 7313f3ef11SPatrick Venture 74ec1137d5SPatrick Williams```sh 7513f3ef11SPatrick Venture~# busctl tree --no-pager xyz.openbmc_project.FruDevice 7613f3ef11SPatrick Venture`-/xyz 7713f3ef11SPatrick Venture `-/xyz/openbmc_project 7813f3ef11SPatrick Venture `-/xyz/openbmc_project/FruDevice 7913f3ef11SPatrick Venture |-/xyz/openbmc_project/FruDevice/Super_Great 8013f3ef11SPatrick Venture |-/xyz/openbmc_project/FruDevice/Super_Great_0 8113f3ef11SPatrick Venture``` 8213f3ef11SPatrick Venture 8313f3ef11SPatrick VentureThe dbus path for each instance is unimportant beyond needing to be unique. 8413f3ef11SPatrick VentureDigging into one of these FRUs we see: 8513f3ef11SPatrick Venture 86ec1137d5SPatrick Williams```sh 8713f3ef11SPatrick Venture~# busctl introspect --no-pager xyz.openbmc_project.FruDevice \ 8813f3ef11SPatrick Venture /xyz/openbmc_project/FruDevice/Super_Great 8913f3ef11SPatrick Venture 9013f3ef11SPatrick VentureNAME TYPE SIGNATURE RESULT/VALUE FLAGS 9113f3ef11SPatrick Ventureorg.freedesktop.DBus.Introspectable interface - - - 9213f3ef11SPatrick Venture.Introspect method - s - 9313f3ef11SPatrick Ventureorg.freedesktop.DBus.Peer interface - - - 9413f3ef11SPatrick Venture.GetMachineId method - s - 9513f3ef11SPatrick Venture.Ping method - - - 9613f3ef11SPatrick Ventureorg.freedesktop.DBus.Properties interface - - - 9713f3ef11SPatrick Venture.Get method ss v - 9813f3ef11SPatrick Venture.GetAll method s a{sv} - 9913f3ef11SPatrick Venture.Set method ssv - - 10013f3ef11SPatrick Venture.PropertiesChanged signal sa{sv}as - - 10113f3ef11SPatrick Venturexyz.openbmc_project.FruDevice interface - - - 10213f3ef11SPatrick Venture.ADDRESS property u 80 emits-change 10313f3ef11SPatrick Venture.BUS property u 18 emits-change 10413f3ef11SPatrick Venture.Common_Format_Version property s "1" emits-change 10513f3ef11SPatrick Venture.PRODUCT_ASSET_TAG property s "--" emits-change 10613f3ef11SPatrick Venture.PRODUCT_FRU_VERSION_ID property s "??????" emits-change 10713f3ef11SPatrick Venture.PRODUCT_LANGUAGE_CODE property s "0" emits-change 10813f3ef11SPatrick Venture.PRODUCT_MANUFACTURER property s "Awesome" emits-change 10913f3ef11SPatrick Venture.PRODUCT_PART_NUMBER property s "12345" emits-change 11013f3ef11SPatrick Venture.PRODUCT_PRODUCT_NAME property s "Super Great" emits-change 11113f3ef11SPatrick Venture.PRODUCT_SERIAL_NUMBER property s "12312490840" emits-change 11213f3ef11SPatrick Venture.PRODUCT_VERSION property s "0A" emits-change 11313f3ef11SPatrick Venture``` 11413f3ef11SPatrick Venture 11513f3ef11SPatrick VentureOk, now you can find the cards, but what about the temperature sensors on each 11613f3ef11SPatrick Ventureof them? Entity-Manager provides a very powerful mechanism for querying various 11713f3ef11SPatrick Ventureinformation, but our goal is simple. If we find the card, we want to add the 11813f3ef11SPatrick Venturedevice to the system and tell dbus-sensors that there is a hwmon temperature 11913f3ef11SPatrick Venturesensor available. 12013f3ef11SPatrick Venture 12113f3ef11SPatrick VentureWe start with a simple hardware profile. We know that if the card's bus is 12213f3ef11SPatrick Ventureidentified we know the address of the temperature sensor is 0x4c. 12313f3ef11SPatrick Venture 124ec1137d5SPatrick Williams```json 12513f3ef11SPatrick Venture{ 12613f3ef11SPatrick Venture "Exposes": [ 12713f3ef11SPatrick Venture { 12813f3ef11SPatrick Venture "Address": "$address", 12913f3ef11SPatrick Venture "Bus": "$bus", 13013f3ef11SPatrick Venture "Name": "$bus great eeprom", 131f64d4397SHao Jiang "Type": "EEPROM_24C02" 13213f3ef11SPatrick Venture }, 13313f3ef11SPatrick Venture { 13413f3ef11SPatrick Venture "Address": "0x4c", 13513f3ef11SPatrick Venture "Bus": "$bus", 13613f3ef11SPatrick Venture "Name": "$bus great local", 13713f3ef11SPatrick Venture "Name1": "$bus great ext", 13813f3ef11SPatrick Venture "Type": "TMP441" 13913f3ef11SPatrick Venture } 14013f3ef11SPatrick Venture ], 14113f3ef11SPatrick Venture "Name": "$bus Great Card", 14213f3ef11SPatrick Venture "Probe": "xyz.openbmc_project.FruDevice({'PRODUCT_PRODUCT_NAME': 'Super Great'})", 14313f3ef11SPatrick Venture "Type": "Board" 14413f3ef11SPatrick Venture} 14513f3ef11SPatrick Venture``` 14613f3ef11SPatrick Venture 14713f3ef11SPatrick VentureThere's a lot going on in the above hardware profile, and they can become 14813f3ef11SPatrick Ventureconsiderably more complex. Firstly, let's start with the `Probe` field. This is 14913f3ef11SPatrick Venturea way of defining under what circumstances this hardware profile is applied. In 15013f3ef11SPatrick Venturethis case, we want the hardware profile to be applied when a Fru is found with 15113f3ef11SPatrick Venturethe field `PRODUCT_PRODUCT_NAME` holding the value `Super Great`. In our system, 15213f3ef11SPatrick Venturethis will match twice. When the probe has matched the information from that 15313f3ef11SPatrick Venturedevice is then swapped into the hardware profile via the templated variables, 15413f3ef11SPatrick Venturesuch as `$bus` or `$address`. We then shift our focus to the `Exposes` field. 15513f3ef11SPatrick VentureThis lists the entities that are added when this hardware profile is loaded. The 15613f3ef11SPatrick Venturefield is optional and there is a wide variety of entities that can be added this 15713f3ef11SPatrick Ventureway. 15813f3ef11SPatrick Venture 15913f3ef11SPatrick VentureIn our example we only care about the eeprom and the temperature sensor. The 16013f3ef11SPatrick Venture`Type` field is checked against a device export map and if it matches a known 161f64d4397SHao Jiangdevice, it'll attempt to install the device. Be noticed that dbus only allows an 162f64d4397SHao Jianginterface name as an dot delimited string with each truncated substring starting 163f64d4397SHao Jiangwith alphabets(a-z, A-Z). So the Type is intensionally renamed as EEPROM_24C02. 164f64d4397SHao JiangIt is safe to do so since Entity manager types are not required to be 1:1 with 165f64d4397SHao JiangLinux types. 16613f3ef11SPatrick Venture 16713f3ef11SPatrick VentureFor the card found on bus 18: 16813f3ef11SPatrick Venture 169ec1137d5SPatrick Williams```sh 170*3f60faa5SPeter Delevoryasecho "24c02 0x50" > /sys/bus/i2c/devices/i2c-18/new_device 171*3f60faa5SPeter Delevoryasecho "tmp441 0x4c" > /sys/bus/i2c/devices/i2c-18/new_device 17213f3ef11SPatrick Venture``` 17313f3ef11SPatrick Venture 17413f3ef11SPatrick VentureBeyond this, it also publishes to dbus a configuration: 17513f3ef11SPatrick Venture 176ec1137d5SPatrick Williams```sh 17713f3ef11SPatrick Venture~# busctl tree --no-pager xyz.openbmc_project.EntityManager 17813f3ef11SPatrick Venture`-/xyz 17913f3ef11SPatrick Venture `-/xyz/openbmc_project 18013f3ef11SPatrick Venture |-/xyz/openbmc_project/EntityManager 18113f3ef11SPatrick Venture `-/xyz/openbmc_project/inventory 18213f3ef11SPatrick Venture `-/xyz/openbmc_project/inventory/system 18313f3ef11SPatrick Venture `-/xyz/openbmc_project/inventory/system/board 18413f3ef11SPatrick Venture |-/xyz/openbmc_project/inventory/system/board/18_Great_Card 18513f3ef11SPatrick Venture | |-/xyz/openbmc_project/inventory/system/board/18_Great_Card/18_great_local 18613f3ef11SPatrick Venture |-/xyz/openbmc_project/inventory/system/board/19_Great_Card 18713f3ef11SPatrick Venture | |-/xyz/openbmc_project/inventory/system/board/19_Great_Card/19_great_local 18813f3ef11SPatrick Venture 18913f3ef11SPatrick Venture~# busctl introspect --no-pager xyz.openbmc_project.EntityManager \ 19013f3ef11SPatrick Venture /xyz/openbmc_project/inventory/system/board/18_Great_Card/18_great_local 19113f3ef11SPatrick Venture 19213f3ef11SPatrick VentureNAME TYPE SIGNATURE RESULT/VALUE FLAGS 19313f3ef11SPatrick Ventureorg.freedesktop.DBus.Introspectable interface - - - 19413f3ef11SPatrick Venture.Introspect method - s - 19513f3ef11SPatrick Ventureorg.freedesktop.DBus.Peer interface - - - 19613f3ef11SPatrick Venture.GetMachineId method - s - 19713f3ef11SPatrick Venture.Ping method - - - 19813f3ef11SPatrick Ventureorg.freedesktop.DBus.Properties interface - - - 19913f3ef11SPatrick Venture.Get method ss v - 20013f3ef11SPatrick Venture.GetAll method s a{sv} - 20113f3ef11SPatrick Venture.Set method ssv - - 20213f3ef11SPatrick Venture.PropertiesChanged signal sa{sv}as - - 20313f3ef11SPatrick Venturexyz.openbmc_project.Configuration.TMP441 interface - - - 20413f3ef11SPatrick Venture.Address property t 76 emits-change 20513f3ef11SPatrick Venture.Bus property t 18 emits-change 20613f3ef11SPatrick Venture.Name property s "18 great local" emits-change 20713f3ef11SPatrick Venture.Name1 property s "18 great ext" emits-change 20813f3ef11SPatrick Venture.Type property s "TMP441" emits-change 20913f3ef11SPatrick Venture``` 21013f3ef11SPatrick Venture 21113f3ef11SPatrick VentureThe dbus-sensors suite of daemons each run searching for a specific type of 21213f3ef11SPatrick Venturesensor. In this case the hwmon temperature sensor daemon will recognize the 21313f3ef11SPatrick Ventureconfiguration interface: `xyz.openbmc_project.Configuration.TMP441`. 21413f3ef11SPatrick Venture 21513f3ef11SPatrick VentureIt will look up the device on i2c and see there is a hwmon instance, and map 21613f3ef11SPatrick Venture`temp1_input` to `Name` and since there is also `Name1` it'll map `temp2_input`. 21713f3ef11SPatrick Venture 218ec1137d5SPatrick Williams```sh 219ee70147aSAndrew Jeffery~# busctl tree --no-pager xyz.openbmc_project.HwmonTempSensor 22013f3ef11SPatrick Venture`-/xyz 22113f3ef11SPatrick Venture `-/xyz/openbmc_project 22213f3ef11SPatrick Venture `-/xyz/openbmc_project/sensors 22313f3ef11SPatrick Venture `-/xyz/openbmc_project/sensors/temperature 22413f3ef11SPatrick Venture |-/xyz/openbmc_project/sensors/temperature/18_great_local 22513f3ef11SPatrick Venture |-/xyz/openbmc_project/sensors/temperature/18_great_ext 22613f3ef11SPatrick Venture |-/xyz/openbmc_project/sensors/temperature/19_great_local 22713f3ef11SPatrick Venture |-/xyz/openbmc_project/sensors/temperature/19_great_ext 22813f3ef11SPatrick Venture 22913f3ef11SPatrick Venture~# busctl introspect --no-pager xyz.openbmc_project.HwmonTempSensor \ 23013f3ef11SPatrick Venture /xyz/openbmc_project/sensors/temperature/18_great_local 23113f3ef11SPatrick Venture 23213f3ef11SPatrick VentureNAME TYPE SIGNATURE RESULT/VALUE FLAGS 23313f3ef11SPatrick Ventureorg.freedesktop.DBus.Introspectable interface - - - 23413f3ef11SPatrick Venture.Introspect method - s - 23513f3ef11SPatrick Ventureorg.freedesktop.DBus.Peer interface - - - 23613f3ef11SPatrick Venture.GetMachineId method - s - 23713f3ef11SPatrick Venture.Ping method - - - 23813f3ef11SPatrick Ventureorg.freedesktop.DBus.Properties interface - - - 23913f3ef11SPatrick Venture.Get method ss v - 24013f3ef11SPatrick Venture.GetAll method s a{sv} - 24113f3ef11SPatrick Venture.Set method ssv - - 24213f3ef11SPatrick Venture.PropertiesChanged signal sa{sv}as - - 24313f3ef11SPatrick Ventureorg.openbmc.Associations interface - - - 24413f3ef11SPatrick Venture.associations property a(sss) 1 "chassis" "all_sensors" "/xyz/openb... emits-change 24513f3ef11SPatrick Venturexyz.openbmc_project.Sensor.Value interface - - - 24613f3ef11SPatrick Venture.MaxValue property d 127 emits-change 24713f3ef11SPatrick Venture.MinValue property d -128 emits-change 24813f3ef11SPatrick Venture.Value property d 31.938 emits-change writable 24913f3ef11SPatrick Venture 25013f3ef11SPatrick Venture``` 25113f3ef11SPatrick Venture 25213f3ef11SPatrick VentureThere you are! You now have the two sensors from the two card instances on dbus. 25313f3ef11SPatrick Venture 254aacf742aSAndrew JefferyThis can be more complex, for instance if your card has a mux you can add it to 255fa8ee87eSPatrick Williamsthe configuration, which will trigger FruDevice to scan those new buses for more 256fa8ee87eSPatrick Williamsdevices. 257