Skip to content

Commit 76714d4

Browse files
committed
mctpd: add AssignBridgeStatic method
Add AssignBridgeStatic method to assign static EID with bridge pool allocation. Tested: ``` root@bmc:~# busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/interfaces/mcu1u2u1u4u1 au.com.codeconstruct.MCTP.BusOwner1 AssignBridgeStatic ayyyy 0 30 5 31 yisb 30 1 "/au/com/codeconstruct/mctp1/networks/1/endpoints/30" true root@bmc:~# busctl introspect au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1/endpoints/30 NAME TYPE SIGNATURE RESULT/VALUE FLAGS au.com.codeconstruct.MCTP.Bridge1 interface - - - .PoolEnd property y 35 const .PoolStart property y 31 const au.com.codeconstruct.MCTP.Endpoint1 interface - - - .Recover method - - - .Remove method - - - .SetMTU method u - - .Connectivity property s "Available" emits-change org.freedesktop.DBus.Introspectable interface - - - .Introspect method - s - org.freedesktop.DBus.Peer interface - - - .GetMachineId method - s - .Ping method - - - org.freedesktop.DBus.Properties interface - - - .Get method ss v - .GetAll method s a{sv} - .Set method ssv - - .PropertiesChanged signal sa{sv}as - - xyz.openbmc_project.Common.UUID interface - - - .UUID property s "8b7e3d86-5fa5-298c-a9d6-a2d5d4baa6fa" const xyz.openbmc_project.MCTP.Endpoint interface - - - .EID property y 30 const .NetworkId property u 1 const .SupportedMessageTypes property ay 4 1 5 126 127 const .VendorDefinedMessageTypes property a(yvq) 0 const ```
1 parent 890f81d commit 76714d4

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

docs/mctpd.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ This call will fail if the endpoint already has an EID, and that EID is
203203
different from `static-EID`, or if `static-EID` is already assigned to another
204204
endpoint.
205205

206+
#### `.AssignBridgeStatic`: `ayy``yisb`
207+
208+
Similar to AssignEndpointStatic, but takes an additional pool-size and
209+
pool-start-EID argument:
210+
211+
```
212+
AssignBridgeStatic <hwaddr> <static-EID> <pool-size> <pool-start-EID>
213+
```
214+
215+
`<pool-size>`: The number of EIDs to be allocated to the bridge's EID pool.
216+
217+
`<pool-start-EID>`: The starting EID for the range of EIDs being allocated.
218+
219+
This method performs a static assignment with bridge EID pool allocation.
220+
206221
#### `.LearnEndpoint`: `ay``yisb`
207222

208223
Like SetupEndpoint but will not assign EIDs, will only query endpoints for a

src/mctpd.c

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,91 @@ static int endpoint_assign_eid(struct ctx *ctx, sd_bus_error *berr,
23782378
return 0;
23792379
}
23802380

2381+
static int endpoint_assign_bridge_static_eid(
2382+
struct ctx *ctx, sd_bus_error *berr,
2383+
const dest_phys *dest, struct peer **ret_peer,
2384+
mctp_eid_t static_eid, mctp_eid_t pool_start, uint8_t pool_size)
2385+
{
2386+
struct net *n = NULL;
2387+
struct peer *peer = NULL;
2388+
uint8_t req_pool_size;
2389+
uint32_t net;
2390+
int rc;
2391+
2392+
net = mctp_nl_net_byindex(ctx->nl, dest->ifindex);
2393+
if (!net) {
2394+
bug_warn("No net known for ifindex %d", dest->ifindex);
2395+
return -EPROTO;
2396+
}
2397+
2398+
n = lookup_net(ctx, net);
2399+
if (!n) {
2400+
bug_warn("Unknown net %d", net);
2401+
return -EPROTO;
2402+
}
2403+
2404+
rc = add_peer(ctx, dest, static_eid, net, &peer, false);
2405+
if (rc < 0)
2406+
return rc;
2407+
2408+
peer->pool_size = pool_size;
2409+
if (peer->pool_size)
2410+
peer->pool_start = pool_start;
2411+
2412+
add_peer_route(peer);
2413+
2414+
rc = endpoint_send_set_endpoint_id(peer, &static_eid, &req_pool_size);
2415+
if (rc == -ECONNREFUSED)
2416+
sd_bus_error_setf(
2417+
berr, SD_BUS_ERROR_FAILED,
2418+
"Endpoint returned failure to Set Endpoint ID");
2419+
2420+
if (rc < 0) {
2421+
// we have not yet created the pool route, reset here so that
2422+
// remove_peer() does not attempt to remove it
2423+
peer->pool_size = 0;
2424+
peer->pool_start = 0;
2425+
remove_peer(peer);
2426+
return rc;
2427+
}
2428+
2429+
if (req_pool_size > peer->pool_size) {
2430+
warnx("EID %d: requested pool size (%d) > pool size available (%d), limiting.",
2431+
peer->eid, req_pool_size, peer->pool_size);
2432+
} else {
2433+
// peer will likely have requested less than the available range
2434+
peer->pool_size = req_pool_size;
2435+
}
2436+
2437+
if (!peer->pool_size)
2438+
peer->pool_start = 0;
2439+
2440+
if (static_eid != peer->eid) {
2441+
// avoid allocation for any different EID in response
2442+
warnx("Mismatch of requested from received EID, resetting the pool");
2443+
peer->pool_size = 0;
2444+
peer->pool_start = 0;
2445+
rc = change_peer_eid(peer, static_eid);
2446+
if (rc == -EEXIST) {
2447+
sd_bus_error_setf(
2448+
berr, SD_BUS_ERROR_FAILED,
2449+
"Endpoint requested EID %d instead of assigned %d, already used",
2450+
static_eid, peer->eid);
2451+
}
2452+
if (rc < 0) {
2453+
remove_peer(peer);
2454+
return rc;
2455+
}
2456+
}
2457+
2458+
rc = setup_added_peer(peer);
2459+
if (rc < 0)
2460+
return rc;
2461+
*ret_peer = peer;
2462+
2463+
return 0;
2464+
}
2465+
23812466
/* Populates a sd_bus_error based on mctpd's convention for error codes.
23822467
* Does nothing if berr is already set.
23832468
*/
@@ -3071,6 +3156,93 @@ static int method_assign_endpoint_static(sd_bus_message *call, void *data,
30713156
return rc;
30723157
}
30733158

3159+
static int method_assign_bridge_static(sd_bus_message *call, void *data,
3160+
sd_bus_error *berr)
3161+
{
3162+
dest_phys desti, *dest = &desti;
3163+
const char *peer_path = NULL;
3164+
struct peer *peer = NULL;
3165+
struct link *link = data;
3166+
struct ctx *ctx = link->ctx;
3167+
uint8_t eid;
3168+
uint8_t pool_size;
3169+
uint8_t pool_start;
3170+
int rc;
3171+
3172+
dest->ifindex = link->ifindex;
3173+
if (dest->ifindex <= 0)
3174+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
3175+
"Unknown MCTP interface");
3176+
3177+
rc = message_read_hwaddr(call, dest);
3178+
if (rc < 0)
3179+
goto err;
3180+
3181+
rc = sd_bus_message_read(call, "y", &eid);
3182+
if (rc < 0)
3183+
goto err;
3184+
3185+
rc = sd_bus_message_read(call, "y", &pool_size);
3186+
if (rc < 0)
3187+
goto err;
3188+
3189+
rc = sd_bus_message_read(call, "y", &pool_start);
3190+
if (rc < 0)
3191+
goto err;
3192+
3193+
rc = validate_dest_phys(ctx, dest);
3194+
if (rc < 0)
3195+
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
3196+
"Bad physaddr");
3197+
3198+
peer = find_peer_by_phys(ctx, dest);
3199+
if (peer) {
3200+
if (peer->eid != eid) {
3201+
return sd_bus_error_setf(
3202+
berr, SD_BUS_ERROR_INVALID_ARGS,
3203+
"Already assigned a different EID");
3204+
}
3205+
3206+
// Return existing record.
3207+
peer_path = path_from_peer(peer);
3208+
if (!peer_path)
3209+
goto err;
3210+
3211+
return sd_bus_reply_method_return(call, "yisb", peer->eid,
3212+
peer->net, peer_path, 0);
3213+
} else {
3214+
uint32_t netid;
3215+
3216+
// is the requested EID already in use? if so, reject
3217+
netid = mctp_nl_net_byindex(ctx->nl, dest->ifindex);
3218+
peer = find_peer_by_addr(ctx, eid, netid);
3219+
if (peer) {
3220+
return sd_bus_error_setf(berr,
3221+
SD_BUS_ERROR_INVALID_ARGS,
3222+
"Address in use");
3223+
}
3224+
}
3225+
3226+
rc = endpoint_assign_bridge_static_eid(ctx, berr, dest, &peer, eid,
3227+
pool_start, pool_size);
3228+
if (rc < 0) {
3229+
goto err;
3230+
}
3231+
3232+
peer_path = path_from_peer(peer);
3233+
if (!peer_path)
3234+
goto err;
3235+
3236+
if (peer->pool_size > 0)
3237+
endpoint_allocate_eids(peer);
3238+
3239+
return sd_bus_reply_method_return(call, "yisb", peer->eid, peer->net,
3240+
peer_path, 1);
3241+
err:
3242+
set_berr(ctx, rc, berr);
3243+
return rc;
3244+
}
3245+
30743246
static int method_learn_endpoint(sd_bus_message *call, void *data,
30753247
sd_bus_error *berr)
30763248
{
@@ -4056,6 +4228,20 @@ static const sd_bus_vtable bus_link_owner_vtable[] = {
40564228
method_assign_endpoint_static,
40574229
0),
40584230

4231+
SD_BUS_METHOD_WITH_NAMES("AssignBridgeStatic",
4232+
"ayyyy",
4233+
SD_BUS_PARAM(physaddr)
4234+
SD_BUS_PARAM(eid)
4235+
SD_BUS_PARAM(poolsize)
4236+
SD_BUS_PARAM(poolstart),
4237+
"yisb",
4238+
SD_BUS_PARAM(eid)
4239+
SD_BUS_PARAM(net)
4240+
SD_BUS_PARAM(path)
4241+
SD_BUS_PARAM(new),
4242+
method_assign_bridge_static,
4243+
0),
4244+
40594245
SD_BUS_METHOD_WITH_NAMES("LearnEndpoint",
40604246
"ay",
40614247
SD_BUS_PARAM(physaddr),

0 commit comments

Comments
 (0)