History

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.

Matthew R. Ochs committed 9 years ago

Commit 696d0b01 parent 9c7d1ee5 files · +153 −13Browse files

Unified · Split

5 files
  1. drivers/scsi/cxlflash/common.h +28 −2
  2. drivers/scsi/cxlflash/main.c +93 −5
  3. drivers/scsi/cxlflash/sislite.h +18 −1
  4. drivers/scsi/cxlflash/superpipe.c +13 −5
  5. include/uapi/scsi/cxlflash_ioctl.h +1 −0
drivers/scsi/cxlflash/common.h+28−2
@@ -54,6 +54,9 @@ extern const struct file_operations cxlflash_cxl_fops; · 53 unmodified lines
54/* RRQ for master issued cmds */54/* RRQ for master issued cmds */
55#define NUM_RRQ_ENTRY CXLFLASH_MAX_CMDS55#define NUM_RRQ_ENTRY CXLFLASH_MAX_CMDS
56 56
57/* SQ for master issued cmds */
58#define NUM_SQ_ENTRY CXLFLASH_MAX_CMDS
59
57 60
58static inline void check_sizes(void)61static inline void check_sizes(void)
59{62{
@@ -155,8 +158,8 @@ static inline struct afu_cmd *sc_to_afucz(struct scsi_cmnd *sc) · 95 unmodified lines
155 158
156struct afu {159struct afu {
157 /* Stuff requiring alignment go first. */160 /* Stuff requiring alignment go first. */
158 161 struct sisl_ioarcb sq[NUM_SQ_ENTRY]; /* 16K SQ */
159 u64 rrq_entry[NUM_RRQ_ENTRY]; /* 2K RRQ */162 u64 rrq_entry[NUM_RRQ_ENTRY]; /* 2K RRQ */
160 163
161 /* Beware of alignment till here. Preferably introduce new164 /* Beware of alignment till here. Preferably introduce new
162 * fields after this point165 * fields after this point
@@ -174,6 +177,12 @@ struct afu { · 11 unmodified lines
174 struct kref mapcount;177 struct kref mapcount;
175 178
176 ctx_hndl_t ctx_hndl; /* master's context handle */179 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;
177 u64 *hrrq_start;186 u64 *hrrq_start;
178 u64 *hrrq_end;187 u64 *hrrq_end;
179 u64 *hrrq_curr;188 u64 *hrrq_curr;
@@ -191,6 +200,23 @@ struct afu { · 11 unmodified lines
191 200
192};201};
193 202
203static 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
210static 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
215static 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
194static inline u64 lun_to_lunid(u64 lun)220static inline u64 lun_to_lunid(u64 lun)
195{221{
196 __be64 lun_id;222 __be64 lun_id;
drivers/scsi/cxlflash/main.c+93−5
@@ -226,6 +226,17 @@ static void context_reset_ioarrin(struct afu_cmd *cmd) · 225 unmodified lines
226 context_reset(cmd, &afu->host_map->ioarrin);226 context_reset(cmd, &afu->host_map->ioarrin);
227}227}
228 228
229/**
230 * context_reset_sq() - reset command owner context w/ SQ Context Reset register
231 * @cmd: AFU command that timed out.
232 */
233static 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
229/**240/**
230 * send_cmd_ioarrin() - sends an AFU command via IOARRIN register241 * send_cmd_ioarrin() - sends an AFU command via IOARRIN register
231 * @afu: AFU associated with the host.242 * @afu: AFU associated with the host.
@@ -268,6 +279,49 @@ out: · 36 unmodified lines
268 return rc;279 return rc;
269}280}
270 281
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 */
290static 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);
316out:
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
271/**325/**
272 * wait_resp() - polls for a response or timeout to a sent AFU command326 * wait_resp() - polls for a response or timeout to a sent AFU command
273 * @afu: AFU associated with the host.327 * @afu: AFU associated with the host.
@@ -739,7 +793,7 @@ static int alloc_mem(struct cxlflash_cfg *cfg) · 465 unmodified lines
739 int rc = 0;793 int rc = 0;
740 struct device *dev = &cfg->dev->dev;794 struct device *dev = &cfg->dev->dev;
741 795
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 */
743 cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,797 cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
744 get_order(sizeof(struct afu)));798 get_order(sizeof(struct afu)));
745 if (unlikely(!cfg->afu)) {799 if (unlikely(!cfg->afu)) {
@@ -1127,6 +1181,8 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data) · 381 unmodified lines
1127{1181{
1128 struct afu *afu = (struct afu *)data;1182 struct afu *afu = (struct afu *)data;
1129 struct afu_cmd *cmd;1183 struct afu_cmd *cmd;
1184 struct sisl_ioasa *ioasa;
1185 struct sisl_ioarcb *ioarcb;
1130 bool toggle = afu->toggle;1186 bool toggle = afu->toggle;
1131 u64 entry,1187 u64 entry,
1132 *hrrq_start = afu->hrrq_start,1188 *hrrq_start = afu->hrrq_start,
@@ -1140,7 +1196,16 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data) · 7 unmodified lines
1140 if ((entry & SISL_RESP_HANDLE_T_BIT) != toggle)1196 if ((entry & SISL_RESP_HANDLE_T_BIT) != toggle)
1141 break;1197 break;
1142 1198
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
1144 cmd_complete(cmd);1209 cmd_complete(cmd);
1145 1210
1146 /* Advance to next entry or wrap and flip the toggle bit */1211 /* 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) · 3 unmodified lines
1150 hrrq_curr = hrrq_start;1215 hrrq_curr = hrrq_start;
1151 toggle ^= SISL_RESP_HANDLE_T_BIT;1216 toggle ^= SISL_RESP_HANDLE_T_BIT;
1152 }1217 }
1218
1219 atomic_inc(&afu->hsq_credits);
1153 }1220 }
1154 1221
1155 afu->hrrq_curr = hrrq_curr;1222 afu->hrrq_curr = hrrq_curr;
@@ -1402,10 +1469,15 @@ static int init_global(struct cxlflash_cfg *cfg) · 246 unmodified lines
1402 1469
1403 pr_debug("%s: wwpn0=0x%llX wwpn1=0x%llX\n", __func__, wwpn[0], wwpn[1]);1470 pr_debug("%s: wwpn0=0x%llX wwpn1=0x%llX\n", __func__, wwpn[0], wwpn[1]);
1404 1471
1405 /* Set up RRQ in AFU for master issued cmds */1472 /* Set up RRQ and SQ in AFU for master issued cmds */
1406 writeq_be((u64) afu->hrrq_start, &afu->host_map->rrq_start);1473 writeq_be((u64) afu->hrrq_start, &afu->host_map->rrq_start);
1407 writeq_be((u64) afu->hrrq_end, &afu->host_map->rrq_end);1474 writeq_be((u64) afu->hrrq_end, &afu->host_map->rrq_end);
1408 1475
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
1409 /* AFU configuration */1481 /* AFU configuration */
1410 reg = readq_be(&afu->afu_map->global.regs.afu_config);1482 reg = readq_be(&afu->afu_map->global.regs.afu_config);
1411 reg |= SISL_AFUCONF_AR_ALL|SISL_AFUCONF_ENDIAN;1483 reg |= SISL_AFUCONF_AR_ALL|SISL_AFUCONF_ENDIAN;
@@ -1480,6 +1552,17 @@ static int start_afu(struct cxlflash_cfg *cfg) · 68 unmodified lines
1480 afu->hrrq_curr = afu->hrrq_start;1552 afu->hrrq_curr = afu->hrrq_start;
1481 afu->toggle = 1;1553 afu->toggle = 1;
1482 1554
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
1483 rc = init_global(cfg);1566 rc = init_global(cfg);
1484 1567
1485 pr_debug("%s: returning rc=%d\n", __func__, rc);1568 pr_debug("%s: returning rc=%d\n", __func__, rc);
@@ -1641,8 +1724,13 @@ static int init_afu(struct cxlflash_cfg *cfg) · 155 unmodified lines
1641 goto err2;1724 goto err2;
1642 }1725 }
1643 1726
1644 afu->send_cmd = send_cmd_ioarrin;1727 if (afu_is_sq_cmd_mode(afu)) {
1645 afu->context_reset = context_reset_ioarrin;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 }
1646 1734
1647 pr_debug("%s: afu version %s, interface version 0x%llX\n", __func__,1735 pr_debug("%s: afu version %s, interface version 0x%llX\n", __func__,
1648 afu->version, afu->interface_version);1736 afu->version, afu->interface_version);
drivers/scsi/cxlflash/sislite.h+18−1
@@ -72,7 +72,10 @@ struct sisl_ioarcb { · 71 unmodified lines
72 u16 timeout; /* in units specified by req_flags */72 u16 timeout; /* in units specified by req_flags */
73 u32 rsvd1;73 u32 rsvd1;
74 u8 cdb[16]; /* must be in big endian */74 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 };
76} __packed;79} __packed;
77 80
78struct sisl_rc {81struct sisl_rc {
@@ -260,6 +263,11 @@ struct sisl_host_map { · 181 unmodified lines
260 __be64 cmd_room;263 __be64 cmd_room;
261 __be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */264 __be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */
262 __be64 mbox_w; /* restricted use */265 __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) */
263};271};
264 272
265/* per context provisioning & control MMIO */273/* per context provisioning & control MMIO */
@@ -348,6 +356,15 @@ struct sisl_global_regs { · 82 unmodified lines
348 __be64 rsvd[0xf8];356 __be64 rsvd[0xf8];
349 __le64 afu_version;357 __le64 afu_version;
350 __be64 interface_version;358 __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
351};368};
352 369
353#define CXLFLASH_NUM_FC_PORTS 2370#define CXLFLASH_NUM_FC_PORTS 2
drivers/scsi/cxlflash/superpipe.c+13−5
@@ -1287,6 +1287,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 1286 unmodified lines
1287 int rc = 0;1287 int rc = 0;
1288 u32 perms;1288 u32 perms;
1289 int ctxid = -1;1289 int ctxid = -1;
1290 u64 flags = 0UL;
1290 u64 rctxid = 0UL;1291 u64 rctxid = 0UL;
1291 struct file *file = NULL;1292 struct file *file = NULL;
1292 1293
@@ -1426,10 +1427,11 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 133 unmodified lines
1426 1427
1427out_attach:1428out_attach:
1428 if (fd != -1)1429 if (fd != -1)
1429 attach->hdr.return_flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD;1430 flags |= DK_CXLFLASH_APP_CLOSE_ADAP_FD;
1430 else1431 if (afu_is_sq_cmd_mode(afu))
1431 attach->hdr.return_flags = 0;1432 flags |= DK_CXLFLASH_CONTEXT_SQ_CMD_MODE;
1432 1433
1434 attach->hdr.return_flags = flags;
1433 attach->context_id = ctxi->ctxid;1435 attach->context_id = ctxi->ctxid;
1434 attach->block_size = gli->blk_len;1436 attach->block_size = gli->blk_len;
1435 attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea);1437 attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
@@ -1617,6 +1619,7 @@ static int cxlflash_afu_recover(struct scsi_device *sdev, · 181 unmodified lines
1617 struct afu *afu = cfg->afu;1619 struct afu *afu = cfg->afu;
1618 struct ctx_info *ctxi = NULL;1620 struct ctx_info *ctxi = NULL;
1619 struct mutex *mutex = &cfg->ctx_recovery_mutex;1621 struct mutex *mutex = &cfg->ctx_recovery_mutex;
1622 u64 flags;
1620 u64 ctxid = DECODE_CTXID(recover->context_id),1623 u64 ctxid = DECODE_CTXID(recover->context_id),
1621 rctxid = recover->context_id;1624 rctxid = recover->context_id;
1622 long reg;1625 long reg;
@@ -1672,11 +1675,16 @@ retry_recover: · 49 unmodified lines
1672 }1675 }
1673 1676
1674 ctxi->err_recovery_active = false;1677 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;
1675 recover->context_id = ctxi->ctxid;1685 recover->context_id = ctxi->ctxid;
1676 recover->adap_fd = new_adap_fd;1686 recover->adap_fd = new_adap_fd;
1677 recover->mmio_size = sizeof(afu->afu_map->hosts[0].harea);1687 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;
1680 goto out;1688 goto out;
1681 }1689 }
1682 1690
include/uapi/scsi/cxlflash_ioctl.h+1−0
@@ -40,6 +40,7 @@ struct dk_cxlflash_hdr { · 39 unmodified lines
40 */40 */
41#define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL41#define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL
42#define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL42#define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL
43#define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL
43 44
44/*45/*
45 * General Notes:46 * General Notes:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t