mctpd: Add VendorDefinedMessageTypes property#136
mctpd: Add VendorDefinedMessageTypes property#136msnidhin wants to merge 1 commit intoCodeConstruct:mainfrom
Conversation
fa05dfb to
dad0d6c
Compare
jk-ozlabs
left a comment
There was a problem hiding this comment.
Nice! This looks good, just a few changes/comments inline.
src/mctpd.c
Outdated
| goto out; | ||
|
|
||
| resp = (void *)buf; | ||
| if (resp->vendor_id_format != |
There was a problem hiding this comment.
Minor: Since we re-use resp->vendor_id_format a few times, and the length causes a lot of wrapping, I'd suggest using a temporary (say, fmt) for this.
| goto out; | ||
|
|
||
| /* Check for minimum length of PCIe VDM*/ | ||
| expect_size = sizeof(*resp); |
There was a problem hiding this comment.
This is a bit fragile given the somewhat quirky definition of struct mctp_ctrl_resp_get_vdm_support. We're really including spce for the IANA-format response (because the union will be the max size possible), but then relying on the later fields being absent from the struct, which coincidentally aligns with the correct size for a PCIe format.
We should fix that definition to not include format-specific data at all. In which case, a fixed value here might be more appropriate.
| peer->num_vdm_types++; | ||
|
|
||
| /* Use the next selector from the response. 0xFF indicates no more entries */ | ||
| req.vendor_id_set_selector = resp->vendor_id_set_selector; |
There was a problem hiding this comment.
Might be cleaner to do the 0xff check here, and rc = 0; break if it matches. Then your while loop can be unconditional, and the error cases can just break, rather than needing a goto between scopes.
src/mctpd.c
Outdated
| free(buf); | ||
| if (rc < 0) { | ||
| free(peer->vdm_types); | ||
| peer->vdm_types = NULL; |
There was a problem hiding this comment.
May be better to store these temporarily, and only update the peer-> members on success?
src/mctpd.c
Outdated
| } | ||
| } | ||
|
|
||
| for (unsigned int i = 0; supports_vdm && i < max_retries; i++) { |
There was a problem hiding this comment.
The intent would be more obvious with supports_vdm as an explicit conditional, rather than hiding it in the loop conditional.
| "a(yvu)", | ||
| bus_endpoint_get_prop, | ||
| 0, | ||
| SD_BUS_VTABLE_PROPERTY_CONST), |
There was a problem hiding this comment.
Please add to the dbus API spec (in docs/mctpd.md) too.
There was a problem hiding this comment.
Hi @jk-ozlabs
I see only
These objects host the interface xyz.openbmc_project.MCTP.Endpoint, as per [OpenBMC documentation](https://github.com/openbmc/phosphor-dbus-interfaces/tree/master/yaml/xyz/openbmc_project/MCTP).
in docs/mctpd.md
Do I need to add only this new property ?
There was a problem hiding this comment.
Ah, true. Don't worry about this then, I'll add docs for all properties in a separate change.
tests/test_mctpd.py
Outdated
| iface = mctpd.system.interfaces[0] | ||
| mctp = await mctpd_mctp_iface_obj(dbus, iface) | ||
|
|
||
| # Test 1: Invalid PCIe length |
There was a problem hiding this comment.
If these are different tests, please make them separate test functions. You can share the endpoint classes if that makes things easier.
tests/test_mctpd.py
Outdated
| """ Test that VendorDefinedMessageTypes property is queried and populated correctly """ | ||
| async def test_query_vdm_types(dbus, mctpd): | ||
| class VDMEndpoint(Endpoint): | ||
| async def handle_mctp_control(self, sock, addr, data): |
There was a problem hiding this comment.
This could go in the main Endpoint object, like the general type support, using a vdm_msg_types member as the data source.
|
Waiting for https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/86652 to finalize |
171d7fd to
a964b55
Compare
jk-ozlabs
left a comment
There was a problem hiding this comment.
Looking good for the new spec, but a couple of things inline.
tests/test_mctpd.py
Outdated
| assert ep_types == query_types | ||
|
|
||
|
|
||
| """ Test that VendorDefinedMessageTypes property is queried and populated correctly """ |
There was a problem hiding this comment.
Docstrings should go inside the function definition, as the first line.
Please check out the spacing requirements in PEP257 too - no space immediately within the quotes, and """ on its own line for multi-line docstrings.
(this is all part of the new checks, which had landed since your last push)
tests/test_mctpd.py
Outdated
| assert len(vdm_types) == 0 | ||
|
|
||
|
|
||
| """ Test VDM query with invalid PCIe length """ |
There was a problem hiding this comment.
We can probably deduce this from the function name. If you add a docstring, make it a little more explanatory (or drop if not needed)
tests/mctpenv/__init__.py
Outdated
| resp = resp + list(cur_vdm[1].to_bytes(4, 'big')) | ||
| else: | ||
| await sock.send(raddr, bytes(hdr + [0x02])) | ||
| return |
There was a problem hiding this comment.
I'd suggest handing this error case before constructing the response.
However, a value other than 0 or 1 would indicate an issue in the test suite, no?
src/mctpd.c
Outdated
| if (rc < 0) | ||
| return rc; | ||
|
|
||
| rc = sd_bus_message_append(reply, "u", |
There was a problem hiding this comment.
The new spec defines this as q, no?
src/mctpd.c
Outdated
| 0, | ||
| SD_BUS_VTABLE_PROPERTY_CONST), | ||
| SD_BUS_PROPERTY("VendorDefinedMessageTypes", | ||
| "a(yvu)", |
src/mctpd.c
Outdated
| if (supports_vdm) { | ||
| for (unsigned int i = 0; i < max_retries; i++) { | ||
| rc = query_get_peer_vdm_types(peer); | ||
| // Success |
There was a problem hiding this comment.
Probably don't need this comment.
| htobe16(cur_vdm->vendor_id.pcie); | ||
| vdm_pcie = (void *)(resp + 1); | ||
| resp_len = sizeof(*resp) + | ||
| sizeof(struct mctp_vdm_pcie_data); |
There was a problem hiding this comment.
Does this need wrapping? there seems to be a bit of short-wrapping in this patch.
There was a problem hiding this comment.
/usr/bin/clang-format --dry-run --Werror --color=1 -style=file -i /home/runner/work/mctp/mctp/src/mctpd.c
/home/runner/work/mctp/mctp/src/mctpd.c:1112:30: error: code should be clang-formatted [-Wclang-format-violations]
resp_len = sizeof(*resp) + sizeof(struct mctp_vdm_pcie_data);
^
FAILED: [code=1] meson-internal__clang-format-check
formatter gives wrapped line
src/mctpd.c
Outdated
| break; | ||
|
|
||
| /* Check for minimum length of PCIe VDM*/ | ||
| expect_size = sizeof(*resp) + sizeof(struct mctp_vdm_pcie_data); |
There was a problem hiding this comment.
Maybe just check for the base here, then apply the full expect_size check in the same place you are doing for PCIe (and that will allow you to handle the !PCIE_FORMAT && !IANA_FORMAT as an else-case there)
Implement Get VDM Support (0x06) control command to query vendor defined message capabilities from peers. Expose via D-Bus property a(yvq) containing format, vendor_id (PCIe 16-bit or IANA 32-bit), and command set. Includes positive test for both formats and negative tests for invalid responses (wrong lengths, invalid format, unsupported command). Signed-off-by: Nidhin MS <nidhin.ms@intel.com>
a7e5ece to
cb182be
Compare
Implement Get VDM Support (0x06) control command to query vendor defined message capabilities from peers. Expose via D-Bus property a(yvu) containing format, vendor_id (PCIe 16-bit or IANA 32-bit), and command set. Includes positive test for both formats and negative tests for invalid responses (wrong lengths, invalid format, unsupported command).