@@ -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 );
0 commit comments