Skip to content

Commit b03a7f5

Browse files
Ian Munsiempe
authored andcommitted
cxl: Refactor cxl_load_segment() and find_free_sste()
This moves the segment table hash calculation from cxl_load_segment() into find_free_sste() since that is the only place it is actually used. Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 5100a9d commit b03a7f5

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

‎drivers/misc/cxl/fault.c‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,42 @@
2121

2222
#include "cxl.h"
2323

24-
static struct cxl_sste* find_free_sste(struct cxl_sste *primary_group,
25-
unsigned int *lru)
24+
/* This finds a free SSTE for the given SLB */
25+
static struct cxl_sste* find_free_sste(struct cxl_context *ctx,
26+
struct copro_slb *slb)
2627
{
28+
struct cxl_sste *primary, *sste;
29+
unsigned int mask = (ctx->sst_size >> 7) - 1; /* SSTP0[SegTableSize] */
2730
unsigned int entry;
28-
struct cxl_sste *sste, *group = primary_group;
31+
unsigned int hash;
32+
33+
if (slb->vsid & SLB_VSID_B_1T)
34+
hash = (slb->esid >> SID_SHIFT_1T) & mask;
35+
else /* 256M */
36+
hash = (slb->esid >> SID_SHIFT) & mask;
2937

30-
for (entry = 0; entry < 8; entry++) {
31-
sste = group + entry;
38+
primary = ctx->sstp + (hash << 3);
39+
40+
for (entry = 0, sste = primary; entry < 8; entry++, sste++) {
3241
if (!(be64_to_cpu(sste->esid_data) & SLB_ESID_V))
3342
return sste;
3443
}
44+
3545
/* Nothing free, select an entry to cast out */
36-
sste = primary_group + *lru;
37-
*lru = (*lru + 1) & 0x7;
46+
sste = primary + ctx->sst_lru;
47+
ctx->sst_lru = (ctx->sst_lru + 1) & 0x7;
3848

3949
return sste;
4050
}
4151

4252
static void cxl_load_segment(struct cxl_context *ctx, struct copro_slb *slb)
4353
{
4454
/* mask is the group index, we search primary and secondary here. */
45-
unsigned int mask = (ctx->sst_size >> 7)-1; /* SSTP0[SegTableSize] */
4655
struct cxl_sste *sste;
47-
unsigned int hash;
4856
unsigned long flags;
4957

50-
51-
if (slb->vsid & SLB_VSID_B_1T)
52-
hash = (slb->esid >> SID_SHIFT_1T) & mask;
53-
else /* 256M */
54-
hash = (slb->esid >> SID_SHIFT) & mask;
55-
5658
spin_lock_irqsave(&ctx->sste_lock, flags);
57-
sste = find_free_sste(ctx->sstp + (hash << 3), &ctx->sst_lru);
59+
sste = find_free_sste(ctx, slb);
5860

5961
pr_devel("CXL Populating SST[%li]: %#llx %#llx\n",
6062
sste - ctx->sstp, slb->vsid, slb->esid);

0 commit comments

Comments
 (0)