Skip to content

Commit 238125d

Browse files
author
Khang Nguyen
committed
mctpd: Add NotifyDiscovery D-Bus method
This method sends a Discovery Notify to the PCIe Root Complex. Tested: busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp \ au.com.CodeConstruct.MCTP NotifyDiscovery s mctppcie0 should work. However, the message may take a long time to return so the timeout may need to be increased. This is to be investigated. Signed-off-by: Khang Nguyen <[email protected]>
1 parent a591ad8 commit 238125d

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

docs/mctpd.md

+23
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ Like SetupEndpoint but will not assign EIDs, will only query endpoints for a cur
5151
The `new` return value is set to `false` for an already known endpoint, or `true` when an
5252
endpoint's EID is newly discovered.
5353

54+
## `.NotifyDiscovery`
55+
56+
This method is used to trigger the MCTP over PCIe-VDM discovery process on a
57+
PCIe-VDM interface.
58+
59+
This method sends a Discovery Notify message to the Root Complex on the PCIe bus
60+
with null EID, null physical address and Route-To-Root-Complex PCIe-VDM routing
61+
type.
62+
63+
This method should only be used when `mctpd` is running on an endpoint.
64+
65+
`NotifyDiscovery <interface name>`
66+
67+
`<interface name>` is an PCIe-VDM interface such as `mctppcie0`.
68+
69+
70+
Example:
71+
72+
```shell
73+
busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp \
74+
au.com.CodeConstruct.MCTP NotifyDiscovery s mctppcie0
75+
```
76+
5477
## Endpoint Methods
5578

5679
Each endpoint object has methods to configure it, with `au.com.CodeConstruct.MCTP.Endpoint`

src/mctpd.c

+68
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,66 @@ static int method_learn_endpoint(sd_bus_message *call, void *data, sd_bus_error
18321832
return rc;
18331833
}
18341834

1835+
static int method_notify_discovery(sd_bus_message *call, void *data,
1836+
sd_bus_error *berr)
1837+
{
1838+
int rc;
1839+
const char *ifname = NULL;
1840+
dest_phys desti = { 0 }, *dest = &desti;
1841+
ctx *ctx = data;
1842+
struct mctp_ctrl_cmd_discovery_notify req = { 0 };
1843+
struct mctp_ctrl_resp_discovery_notify *resp;
1844+
uint8_t *buf;
1845+
size_t buf_size;
1846+
struct sockaddr_mctp_ext resp_addr;
1847+
1848+
rc = sd_bus_message_read(call, "s", &ifname);
1849+
if (rc < 0)
1850+
goto err;
1851+
1852+
dest->hwaddr_len = 2;
1853+
dest->ifindex = mctp_nl_ifindex_byname(ctx->nl, ifname);
1854+
if (dest->ifindex <= 0)
1855+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
1856+
"Unknown MCTP ifname '%s'", ifname);
1857+
1858+
rc = validate_dest_phys(ctx, dest);
1859+
if (rc < 0)
1860+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
1861+
"Bad physaddr");
1862+
1863+
req.ctrl_hdr.command_code = MCTP_CTRL_CMD_DISCOVERY_NOTIFY;
1864+
req.ctrl_hdr.rq_dgram_inst = RQDI_REQ;
1865+
1866+
rc = endpoint_query_phys(ctx, dest, MCTP_CTRL_HDR_MSG_TYPE, &req,
1867+
sizeof(req), &buf, &buf_size, &resp_addr);
1868+
if (rc < 0)
1869+
goto free_buf;
1870+
1871+
if (buf_size != sizeof(*resp)) {
1872+
warnx("%s: wrong reply length %zu bytes. dest %s", __func__,
1873+
buf_size, dest_phys_tostr(dest));
1874+
rc = -ENOMSG;
1875+
goto free_buf;
1876+
}
1877+
resp = (void *)buf;
1878+
1879+
if (resp->completion_code != 0) {
1880+
// TODO: make this a debug message?
1881+
warnx("Failure completion code 0x%02x from %s",
1882+
resp->completion_code, dest_phys_tostr(dest));
1883+
rc = -ECONNREFUSED;
1884+
goto free_buf;
1885+
}
1886+
free(buf);
1887+
return sd_bus_reply_method_return(call, "");
1888+
free_buf:
1889+
free(buf);
1890+
err:
1891+
set_berr(ctx, rc, berr);
1892+
return rc;
1893+
}
1894+
18351895
// Query various properties of a peer.
18361896
// To be called when a new peer is discovered/assigned, once an EID is known
18371897
// and routable.
@@ -2274,6 +2334,14 @@ static const sd_bus_vtable bus_mctpd_vtable[] = {
22742334
SD_BUS_PARAM(found),
22752335
method_learn_endpoint,
22762336
0),
2337+
2338+
SD_BUS_METHOD_WITH_NAMES("NotifyDiscovery",
2339+
"s",
2340+
SD_BUS_PARAM(ifname),
2341+
"",,
2342+
method_notify_discovery,
2343+
0),
2344+
22772345
SD_BUS_VTABLE_END,
22782346

22792347
};

0 commit comments

Comments
 (0)