Skip to content

Commit 696d0b0

Browse files
Matthew R. Ochsmartinkpetersen
authored andcommitted
scsi: cxlflash: Support SQ Command Mode
The SISLite specification outlines a new queuing model to improve over the MMIO-based IOARRIN model that exists today. This new model uses a submission queue that exists in host memory and is shared with the device. Each entry in the queue is an IOARCB that describes a transfer request. When requests are submitted, IOARCBs ('current' position tracked in host software) are populated and the submission queue tail pointer is then updated via MMIO to make the device aware of the requests. Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com> Signed-off-by: Uma Krishnan <ukrishn@linux.vnet.ibm.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 9c7d1ee commit 696d0b0

5 files changed

Lines changed: 153 additions & 13 deletions

File tree

‎drivers/scsi/cxlflash/common.h‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ extern const struct file_operations cxlflash_cxl_fops;
5454
/* RRQ for master issued cmds */
5555
#define NUM_RRQ_ENTRY CXLFLASH_MAX_CMDS
5656

57+
/* SQ for master issued cmds */
58+
#define NUM_SQ_ENTRY CXLFLASH_MAX_CMDS
59+
5760

5861
static inline void check_sizes(void)
5962
{
@@ -155,8 +158,8 @@ static inline struct afu_cmd *sc_to_afucz(struct scsi_cmnd *sc)
155158

156159
struct afu {
157160
/* Stuff requiring alignment go first. */
158-
159-
u64 rrq_entry[NUM_RRQ_ENTRY]; /* 2K RRQ */
161+
struct sisl_ioarcb sq[NUM_SQ_ENTRY]; /* 16K SQ */
162+
u64 rrq_entry[NUM_RRQ_ENTRY]; /* 2K RRQ */
160163

161164
/* Beware of alignment till here. Preferably introduce new
162165
* fields after this point
@@ -174,6 +177,12 @@ struct afu {
174177
struct kref mapcount;
175178

176179
ctx_hndl_t ctx_hndl; /* master's context handle */
180+
181+
atomic_t hsq_credits;
182+
spinlock_t hsq_slock;
183+
struct sisl_ioarcb *hsq_start;
184+
struct sisl_ioarcb *hsq_end;
185+
struct sisl_ioarcb *hsq_curr;
177186
u64 *hrrq_start;
178187
u64 *hrrq_end;
179188
u64 *hrrq_curr;
@@ -191,6 +200,23 @@ struct afu {
191200

192201
};
193202

203+
static inline bool afu_is_cmd_mode(struct afu *afu, u64 cmd_mode)
204+
{
205+
u64 afu_cap = afu->interface_version >> SISL_INTVER_CAP_SHIFT;
206+
207+
return afu_cap & cmd_mode;
208+
}
209+
210+
static inline bool afu_is_sq_cmd_mode(struct afu *afu)
211+
{
212+
return afu_is_cmd_mode(afu, SISL_INTVER_CAP_SQ_CMD_MODE);
213+
}
214+
215+
static inline bool afu_is_ioarrin_cmd_mode(struct afu *afu)
216+
{
217+
return afu_is_cmd_mode(afu, SISL_INTVER_CAP_IOARRIN_CMD_MODE);
218+
}
219+
194220
static inline u64 lun_to_lunid(u64 lun)
195221
{
196222
__be64 lun_id;

‎drivers/scsi/cxlflash/main.c‎

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ static void context_reset_ioarrin(struct afu_cmd *cmd)
226226
context_reset(cmd, &afu->host_map->ioarrin);
227227
}
228228

229+
/**
230+
* context_reset_sq() - reset command owner context w/ SQ Context Reset register
231+
* @cmd: AFU command that timed out.
232+
*/
233+
static void context_reset_sq(struct afu_cmd *cmd)
234+
{
235+
struct afu *afu = cmd->parent;
236+
237+
context_reset(cmd, &afu->host_map->sq_ctx_reset);
238+
}
239+
229240
/**
230241
* send_cmd_ioarrin() - sends an AFU command via IOARRIN register
231242
* @afu: AFU associated with the host.
@@ -268,6 +279,49 @@ static int send_cmd_ioarrin(struct afu *afu, struct afu_cmd *cmd)
268279
return rc;
269280
}
270281

282+
/**
283+
* send_cmd_sq() - sends an AFU command via SQ ring
284+
* @afu: AFU associated with the host.
285+
* @cmd: AFU command to send.
286+
*
287+
* Return:
288+
* 0 on success, SCSI_MLQUEUE_HOST_BUSY on failure
289+
*/
290+
static int send_cmd_sq(struct afu *afu, struct afu_cmd *cmd)
291+
{
292+
struct cxlflash_cfg *cfg = afu->parent;
293+
struct device *dev = &cfg->dev->dev;
294+
int rc = 0;
295+
int newval;
296+
ulong lock_flags;
297+
298+
newval = atomic_dec_if_positive(&afu->hsq_credits);
299+
if (newval <= 0) {
300+
rc = SCSI_MLQUEUE_HOST_BUSY;
301+
goto out;
302+
}
303+
304+
cmd->rcb.ioasa = &cmd->sa;
305+
306+
spin_lock_irqsave(&afu->hsq_slock, lock_flags);
307+
308+
*afu->hsq_curr = cmd->rcb;
309+
if (afu->hsq_curr < afu->hsq_end)
310+
afu->hsq_curr++;
311+
else
312+
afu->hsq_curr = afu->hsq_start;
313+
writeq_be((u64)afu->hsq_curr, &afu->host_map->sq_tail);
314+
315+
spin_unlock_irqrestore(&afu->hsq_slock, lock_flags);
316+
out:
317+
dev_dbg(dev, "%s: cmd=%p len=%d ea=%p ioasa=%p rc=%d curr=%p "
318+
"head=%016llX tail=%016llX\n", __func__, cmd, cmd->rcb.data_len,
319+
(void *)cmd->rcb.data_ea, cmd->rcb.ioasa, rc, afu->hsq_curr,
320+
readq_be(&afu->host_map->sq_head),
321+
readq_be(&afu->host_map->sq_tail));
322+
return rc;
323+
}
324+
271325
/**
272326
* wait_resp() - polls for a response or timeout to a sent AFU command
273327
* @afu: AFU associated with the host.
@@ -739,7 +793,7 @@ static int alloc_mem(struct cxlflash_cfg *cfg)
739793
int rc = 0;
740794
struct device *dev = &cfg->dev->dev;
741795

742-
/* AFU is ~12k, i.e. only one 64k page or up to four 4k pages */
796+
/* AFU is ~28k, i.e. only one 64k page or up to seven 4k pages */
743797
cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
744798
get_order(sizeof(struct afu)));
745799
if (unlikely(!cfg->afu)) {
@@ -1127,6 +1181,8 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data)
11271181
{
11281182
struct afu *afu = (struct afu *)data;
11291183
struct afu_cmd *cmd;
1184+
struct sisl_ioasa *ioasa;
1185+
struct sisl_ioarcb *ioarcb;
11301186
bool toggle = afu->toggle;
11311187
u64 entry,
11321188
*hrrq_start = afu->hrrq_start,
@@ -1140,7 +1196,16 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data)
11401196
if ((entry & SISL_RESP_HANDLE_T_BIT) != toggle)
11411197
break;
11421198

1143-
cmd = (struct afu_cmd *)(entry & ~SISL_RESP_HANDLE_T_BIT);
1199+
entry &= ~SISL_RESP_HANDLE_T_BIT;
1200+
1201+
if (afu_is_sq_cmd_mode(afu)) {
1202+
ioasa = (struct sisl_ioasa *)entry;
1203+
cmd = container_of(ioasa, struct afu_cmd, sa);
1204+
} else {
1205+
ioarcb = (struct sisl_ioarcb *)entry;
1206+
cmd = container_of(ioarcb, struct afu_cmd, rcb);
1207+
}
1208+
11441209
cmd_complete(cmd);
11451210

11461211
/* Advance to next entry or wrap and flip the toggle bit */
@@ -1150,6 +1215,8 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data)
11501215
hrrq_curr = hrrq_start;
11511216
toggle ^= SISL_RESP_HANDLE_T_BIT;
11521217
}
1218+
1219+
atomic_inc(&afu->hsq_credits);
11531220
}
11541221

11551222
afu->hrrq_curr = hrrq_curr;
@@ -1402,10 +1469,15 @@ static int init_global(struct cxlflash_cfg *cfg)
14021469

14031470
pr_debug("%s: wwpn0=0x%llX wwpn1=0x%llX\n", __func__, wwpn[0], wwpn[1]);
14041471

1405-
/* Set up RRQ in AFU for master issued cmds */
1472+
/* Set up RRQ and SQ in AFU for master issued cmds */
14061473
writeq_be((u64) afu->hrrq_start, &afu->host_map->rrq_start);
14071474
writeq_be((u64) afu->hrrq_end, &afu->host_map->rrq_end);
14081475

1476+
if (afu_is_sq_cmd_mode(afu)) {
1477+
writeq_be((u64)afu->hsq_start, &afu->host_map->sq_start);
1478+
writeq_be((u64)afu->hsq_end, &afu->host_map->sq_end);
1479+
}
1480+
14091481
/* AFU configuration */
14101482
reg = readq_be(&afu->afu_map->global.regs.afu_config);
14111483
reg |= SISL_AFUCONF_AR_ALL|SISL_AFUCONF_ENDIAN;
@@ -1480,6 +1552,17 @@ static int start_afu(struct cxlflash_cfg *cfg)
14801552
afu->hrrq_curr = afu->hrrq_start;
14811553
afu->toggle = 1;
14821554

1555+
/* Initialize SQ */
1556+
if (afu_is_sq_cmd_mode(afu)) {
1557+
memset(&afu->sq, 0, sizeof(afu->sq));
1558+
afu->hsq_start = &afu->sq[0];
1559+
afu->hsq_end = &afu->sq[NUM_SQ_ENTRY - 1];
1560+
afu->hsq_curr = afu->hsq_start;
1561+
1562+
spin_lock_init(&afu->hsq_slock);
1563+
atomic_set(&afu->hsq_credits, NUM_SQ_ENTRY - 1);
1564+
}
1565+
14831566
rc = init_global(cfg);
14841567

14851568
pr_debug("%s: returning rc=%d\n", __func__, rc);
@@ -1641,8 +1724,13 @@ static int init_afu(struct cxlflash_cfg *cfg)
16411724
goto err2;
16421725
}
16431726

1644-
afu->send_cmd = send_cmd_ioarrin;
1645-
afu->context_reset = context_reset_ioarrin;
1727+
if (afu_is_sq_cmd_mode(afu)) {
1728+
afu->send_cmd = send_cmd_sq;
1729+
afu->context_reset = context_reset_sq;
1730+
} else {
1731+
afu->send_cmd = send_cmd_ioarrin;
1732+
afu->context_reset = context_reset_ioarrin;
1733+
}
16461734

16471735
pr_debug("%s: afu version %s, interface version 0x%llX\n", __func__,
16481736
afu->version, afu->interface_version);

‎drivers/scsi/cxlflash/sislite.h‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ struct sisl_ioarcb {
7272
u16 timeout; /* in units specified by req_flags */
7373
u32 rsvd1;
7474
u8 cdb[16]; /* must be in big endian */
75-
u64 reserved; /* Reserved area */
75+
union {
76+
u64 reserved; /* Reserved for IOARRIN mode */
77+
struct sisl_ioasa *ioasa; /* IOASA EA for SQ Mode */
78+
};
7679
} __packed;
7780

7881
struct sisl_rc {
@@ -260,6 +263,11 @@ struct sisl_host_map {
260263
__be64 cmd_room;
261264
__be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */
262265
__be64 mbox_w; /* restricted use */
266+
__be64 sq_start; /* Submission Queue (R/W): write sequence and */
267+
__be64 sq_end; /* inclusion semantics are the same as RRQ */
268+
__be64 sq_head; /* Submission Queue Head (R): for debugging */
269+
__be64 sq_tail; /* Submission Queue TAIL (R/W): next IOARCB */
270+
__be64 sq_ctx_reset; /* Submission Queue Context Reset (R/W) */
263271
};
264272

265273
/* per context provisioning & control MMIO */
@@ -348,6 +356,15 @@ struct sisl_global_regs {
348356
__be64 rsvd[0xf8];
349357
__le64 afu_version;
350358
__be64 interface_version;
359+
#define SISL_INTVER_CAP_SHIFT 16
360+
#define SISL_INTVER_MAJ_SHIFT 8
361+
#define SISL_INTVER_CAP_MASK 0xFFFFFFFF00000000ULL
362+
#define SISL_INTVER_MAJ_MASK 0x00000000FFFF0000ULL
363+
#define SISL_INTVER_MIN_MASK 0x000000000000FFFFULL
364+
#define SISL_INTVER_CAP_IOARRIN_CMD_MODE 0x800000000000ULL
365+
#define SISL_INTVER_CAP_SQ_CMD_MODE 0x400000000000ULL
366+
#define SISL_INTVER_CAP_RESERVED_CMD_MODE_A 0x200000000000ULL
367+
#define SISL_INTVER_CAP_RESERVED_CMD_MODE_B 0x100000000000ULL
351368
};
352369

353370
#define CXLFLASH_NUM_FC_PORTS 2

‎drivers/scsi/cxlflash/superpipe.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev,
12871287
int rc = 0;
12881288
u32 perms;
12891289
int ctxid = -1;
1290+
u64 flags = 0UL;
12901291
u64 rctxid = 0UL;
12911292
struct file *file = NULL;
12921293

@@ -1426,10 +1427,11 @@ static int cxlflash_disk_attach(struct scsi_device *sdev,
14261427

14271428
out_attach:
14281429
if (fd != -1)
1429-
attach->hdr.return_flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD;
1430-
else
1431-
attach->hdr.return_flags = 0;
1430+
flags |= DK_CXLFLASH_APP_CLOSE_ADAP_FD;
1431+
if (afu_is_sq_cmd_mode(afu))
1432+
flags |= DK_CXLFLASH_CONTEXT_SQ_CMD_MODE;
14321433

1434+
attach->hdr.return_flags = flags;
14331435
attach->context_id = ctxi->ctxid;
14341436
attach->block_size = gli->blk_len;
14351437
attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
@@ -1617,6 +1619,7 @@ static int cxlflash_afu_recover(struct scsi_device *sdev,
16171619
struct afu *afu = cfg->afu;
16181620
struct ctx_info *ctxi = NULL;
16191621
struct mutex *mutex = &cfg->ctx_recovery_mutex;
1622+
u64 flags;
16201623
u64 ctxid = DECODE_CTXID(recover->context_id),
16211624
rctxid = recover->context_id;
16221625
long reg;
@@ -1672,11 +1675,16 @@ static int cxlflash_afu_recover(struct scsi_device *sdev,
16721675
}
16731676

16741677
ctxi->err_recovery_active = false;
1678+
1679+
flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD |
1680+
DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET;
1681+
if (afu_is_sq_cmd_mode(afu))
1682+
flags |= DK_CXLFLASH_CONTEXT_SQ_CMD_MODE;
1683+
1684+
recover->hdr.return_flags = flags;
16751685
recover->context_id = ctxi->ctxid;
16761686
recover->adap_fd = new_adap_fd;
16771687
recover->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
1678-
recover->hdr.return_flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD |
1679-
DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET;
16801688
goto out;
16811689
}
16821690

‎include/uapi/scsi/cxlflash_ioctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct dk_cxlflash_hdr {
4040
*/
4141
#define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL
4242
#define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL
43+
#define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL
4344

4445
/*
4546
* General Notes:

0 commit comments

Comments
 (0)