Skip to content

Commit 73e2567

Browse files
author
Khang Nguyen
committed
mctpd: Send Discovery Notify on Endpoint role set
Implement the first step of partial discovery, which is notifying the bus owner of our presence on the bus. Tested: Discovery Notify message is sent when setting role on interface. Jul 15 08:33:42 evb-endpoint mctpd[3322]: mctpd: read_message got from sockaddr_mctp_ext eid 8 net 1 type 0x00 if 2 hw len 2 0x80:08 len 3 Jul 15 08:33:42 evb-endpoint mctpd[3322]: mctpd: Failure completion code 0x05 from physaddr if 2 hw len 2 0x00:00 Jul 15 08:33:42 evb-endpoint mctpd[3322]: mctpd: Warning: discovery notify on interface 'mctppcie0' failed: Connection refused (My Root Complex does not handle Discovery Notify message yet, but can confirm that the message is sent) Signed-off-by: Khang Nguyen Duy <khangng@amperecomputing.com>
1 parent 64f4f53 commit 73e2567

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
5. mctpd: New test infrastructure for control procotol messaging to mctpd
1616
6. mctpd: Add a configuration file facility, defaulting to /etc/mctpd.conf.
1717
7. mctpd: Add mctp/interfaces/<name> D-Bus object
18+
8. mctpd: Send Discovery Notify on Endpoint role set
1819

1920
### Changed
2021

src/mctpd.c

+57-2
Original file line numberDiff line numberDiff line change
@@ -2895,6 +2895,48 @@ static int bus_link_get_prop(sd_bus *bus,
28952895
return rc;
28962896
}
28972897

2898+
static int notify_discovery(ctx *ctx, int ifindex)
2899+
{
2900+
int rc = 0;
2901+
dest_phys desti = { 0 }, *dest = &desti;
2902+
struct mctp_ctrl_cmd_discovery_notify req = { 0 };
2903+
struct mctp_ctrl_resp_discovery_notify *resp;
2904+
uint8_t *buf;
2905+
size_t buf_size;
2906+
struct sockaddr_mctp_ext resp_addr;
2907+
2908+
dest->ifindex = ifindex;
2909+
mctp_nl_ifaddr_byindex(ctx->nl, dest->ifindex, &dest->hwaddr_len);
2910+
memset(dest->hwaddr, 0, sizeof dest->hwaddr);
2911+
2912+
req.ctrl_hdr.command_code = MCTP_CTRL_CMD_DISCOVERY_NOTIFY;
2913+
req.ctrl_hdr.rq_dgram_inst = RQDI_REQ;
2914+
2915+
rc = endpoint_query_phys(ctx, dest, MCTP_CTRL_HDR_MSG_TYPE, &req,
2916+
sizeof(req), &buf, &buf_size, &resp_addr);
2917+
if (rc < 0)
2918+
goto free_buf;
2919+
2920+
if (buf_size != sizeof(*resp)) {
2921+
warnx("%s: wrong reply length %zu bytes. dest %s", __func__,
2922+
buf_size, dest_phys_tostr(dest));
2923+
rc = -ENOMSG;
2924+
goto free_buf;
2925+
}
2926+
resp = (void *)buf;
2927+
2928+
if (resp->completion_code != 0) {
2929+
// TODO: make this a debug message?
2930+
warnx("Failure completion code 0x%02x from %s",
2931+
resp->completion_code, dest_phys_tostr(dest));
2932+
rc = -ECONNREFUSED;
2933+
goto free_buf;
2934+
}
2935+
free_buf:
2936+
free(buf);
2937+
return rc;
2938+
}
2939+
28982940
static int bus_link_set_prop(sd_bus *bus,
28992941
const char *path, const char *interface, const char *property,
29002942
sd_bus_message *value, void *userdata, sd_bus_error *berr)
@@ -2906,6 +2948,7 @@ static int bus_link_set_prop(sd_bus *bus,
29062948
link_userdata *lmUserData;
29072949
int rc;
29082950
struct role role;
2951+
int ifindex;
29092952

29102953
if (!is_interfaces_path(path)) {
29112954
sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
@@ -2921,11 +2964,13 @@ static int bus_link_set_prop(sd_bus *bus,
29212964
goto out;
29222965
}
29232966

2924-
lmUserData = mctp_nl_get_link_userdata_byname(ctx->nl, link_name);
2925-
if (!lmUserData) {
2967+
ifindex = mctp_nl_ifindex_byname(ctx->nl, link_name);
2968+
if (!ifindex) {
29262969
rc = -ENOENT;
29272970
goto out;
29282971
}
2972+
lmUserData = mctp_nl_get_link_userdata(ctx->nl, ifindex);
2973+
assert(lmUserData);
29292974

29302975
if (strcmp(property, "Role") != 0) {
29312976
printf("Unknown property '%s' for %s iface %s\n", property, path, interface);
@@ -2956,6 +3001,16 @@ static int bus_link_set_prop(sd_bus *bus,
29563001
}
29573002
lmUserData->role = role.role;
29583003

3004+
// Announce on the bus we are endpoint, print warning and ignore error if failed
3005+
if (lmUserData->role == ENDPOINT_ROLE_ENDPOINT) {
3006+
rc = notify_discovery(ctx, ifindex);
3007+
if (rc) {
3008+
warnx("Warning: discovery notify on interface '%s' failed: %s", link_name,
3009+
strerror(-rc));
3010+
rc = 0;
3011+
}
3012+
}
3013+
29593014
out:
29603015
set_berr(ctx, rc, berr);
29613016
return rc;

0 commit comments

Comments
 (0)