Skip to content

Commit 0ee2d97

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/region: Avoid duplicate call of cxl_port_pick_region_decoder()
Function cxl_port_pick_region_decoder() is called twice, in alloc_region_ref() and cxl_rr_alloc_decoder(). Both functions are subsequently called from cxl_port_attach_region(). Make the decoder a function argument to both which avoids a duplicate call of cxl_port_pick_region_decoder(). Now, cxl_rr_alloc_decoder() no longer allocates the decoder. Instead, the previously picked decoder is assigned to the region reference. Hence, rename the function to cxl_rr_assign_decoder(). Moving the call out of alloc_region_ref() also moves it out of the xa_for_each() loop in there. Now, cxld is determined no longer only for each auto-generated region, but now once for all regions regardless of auto-generated or not. This is fine as the cxld argument is needed for all regions in cxl_rr_assign_decoder() and an error would be returned otherwise anyway. So it is better to determine the decoder in front of all this and fail early if missing instead of running through all that code with multiple calls of cxl_port_pick_region_decoder(). Signed-off-by: Robert Richter <[email protected]> Reviewed-by: Gregory Price <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: "Fabio M. De Francesco" <[email protected]> Tested-by: Gregory Price <[email protected]> Acked-by: Dan Williams <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent a3a9687 commit 0ee2d97

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

drivers/cxl/core/region.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,8 @@ static bool auto_order_ok(struct cxl_port *port, struct cxl_region *cxlr_iter,
928928

929929
static struct cxl_region_ref *
930930
alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr,
931-
struct cxl_endpoint_decoder *cxled)
931+
struct cxl_endpoint_decoder *cxled,
932+
struct cxl_decoder *cxld)
932933
{
933934
struct cxl_region_params *p = &cxlr->params;
934935
struct cxl_region_ref *cxl_rr, *iter;
@@ -942,9 +943,6 @@ alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr,
942943
continue;
943944

944945
if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
945-
struct cxl_decoder *cxld;
946-
947-
cxld = cxl_port_pick_region_decoder(port, cxled, cxlr);
948946
if (auto_order_ok(port, iter->region, cxld))
949947
continue;
950948
}
@@ -1026,19 +1024,11 @@ static int cxl_rr_ep_add(struct cxl_region_ref *cxl_rr,
10261024
return 0;
10271025
}
10281026

1029-
static int cxl_rr_alloc_decoder(struct cxl_port *port, struct cxl_region *cxlr,
1030-
struct cxl_endpoint_decoder *cxled,
1031-
struct cxl_region_ref *cxl_rr)
1027+
static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,
1028+
struct cxl_endpoint_decoder *cxled,
1029+
struct cxl_region_ref *cxl_rr,
1030+
struct cxl_decoder *cxld)
10321031
{
1033-
struct cxl_decoder *cxld;
1034-
1035-
cxld = cxl_port_pick_region_decoder(port, cxled, cxlr);
1036-
if (!cxld) {
1037-
dev_dbg(&cxlr->dev, "%s: no decoder available\n",
1038-
dev_name(&port->dev));
1039-
return -EBUSY;
1040-
}
1041-
10421032
if (cxld->region) {
10431033
dev_dbg(&cxlr->dev, "%s: %s already attached to %s\n",
10441034
dev_name(&port->dev), dev_name(&cxld->dev),
@@ -1129,7 +1119,16 @@ static int cxl_port_attach_region(struct cxl_port *port,
11291119
nr_targets_inc = true;
11301120
}
11311121
} else {
1132-
cxl_rr = alloc_region_ref(port, cxlr, cxled);
1122+
struct cxl_decoder *cxld;
1123+
1124+
cxld = cxl_port_pick_region_decoder(port, cxled, cxlr);
1125+
if (!cxld) {
1126+
dev_dbg(&cxlr->dev, "%s: no decoder available\n",
1127+
dev_name(&port->dev));
1128+
return -EBUSY;
1129+
}
1130+
1131+
cxl_rr = alloc_region_ref(port, cxlr, cxled, cxld);
11331132
if (IS_ERR(cxl_rr)) {
11341133
dev_dbg(&cxlr->dev,
11351134
"%s: failed to allocate region reference\n",
@@ -1138,7 +1137,7 @@ static int cxl_port_attach_region(struct cxl_port *port,
11381137
}
11391138
nr_targets_inc = true;
11401139

1141-
rc = cxl_rr_alloc_decoder(port, cxlr, cxled, cxl_rr);
1140+
rc = cxl_rr_assign_decoder(port, cxlr, cxled, cxl_rr, cxld);
11421141
if (rc)
11431142
goto out_erase;
11441143
}

0 commit comments

Comments
 (0)