@@ -566,7 +566,7 @@ static void stop_afu(struct cxlflash_cfg *cfg)
566
566
ssleep (1 );
567
567
568
568
if (afu_is_irqpoll_enabled (afu )) {
569
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
569
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
570
570
hwq = get_hwq (afu , i );
571
571
572
572
irq_poll_disable (& hwq -> irqpoll );
@@ -676,13 +676,13 @@ static void term_afu(struct cxlflash_cfg *cfg)
676
676
* 2) Unmap the problem state area
677
677
* 3) Stop each master context
678
678
*/
679
- for (k = CXLFLASH_NUM_HWQS - 1 ; k >= 0 ; k -- )
679
+ for (k = cfg -> afu -> num_hwqs - 1 ; k >= 0 ; k -- )
680
680
term_intr (cfg , UNMAP_THREE , k );
681
681
682
682
if (cfg -> afu )
683
683
stop_afu (cfg );
684
684
685
- for (k = CXLFLASH_NUM_HWQS - 1 ; k >= 0 ; k -- )
685
+ for (k = cfg -> afu -> num_hwqs - 1 ; k >= 0 ; k -- )
686
686
term_mc (cfg , k );
687
687
688
688
dev_dbg (dev , "%s: returning\n" , __func__ );
@@ -823,6 +823,7 @@ static int alloc_mem(struct cxlflash_cfg *cfg)
823
823
goto out ;
824
824
}
825
825
cfg -> afu -> parent = cfg ;
826
+ cfg -> afu -> desired_hwqs = CXLFLASH_DEF_HWQS ;
826
827
cfg -> afu -> afu_map = NULL ;
827
828
out :
828
829
return rc ;
@@ -1116,7 +1117,7 @@ static void afu_err_intr_init(struct afu *afu)
1116
1117
/* IOARRIN yet), so there is nothing to clear. */
1117
1118
1118
1119
/* set LISN#, it is always sent to the context that wrote IOARRIN */
1119
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1120
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1120
1121
hwq = get_hwq (afu , i );
1121
1122
1122
1123
writeq_be (SISL_MSI_SYNC_ERROR , & hwq -> host_map -> ctx_ctrl );
@@ -1551,7 +1552,7 @@ static void init_pcr(struct cxlflash_cfg *cfg)
1551
1552
}
1552
1553
1553
1554
/* Copy frequently used fields into hwq */
1554
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1555
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1555
1556
hwq = get_hwq (afu , i );
1556
1557
1557
1558
hwq -> ctx_hndl = (u16 ) cxl_process_element (hwq -> ctx );
@@ -1586,7 +1587,7 @@ static int init_global(struct cxlflash_cfg *cfg)
1586
1587
}
1587
1588
1588
1589
/* Set up RRQ and SQ in HWQ for master issued cmds */
1589
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1590
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1590
1591
hwq = get_hwq (afu , i );
1591
1592
hmap = hwq -> host_map ;
1592
1593
@@ -1640,7 +1641,7 @@ static int init_global(struct cxlflash_cfg *cfg)
1640
1641
/* Set up master's own CTX_CAP to allow real mode, host translation */
1641
1642
/* tables, afu cmds and read/write GSCSI cmds. */
1642
1643
/* First, unlock ctx_cap write by reading mbox */
1643
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1644
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1644
1645
hwq = get_hwq (afu , i );
1645
1646
1646
1647
(void )readq_be (& hwq -> ctrl_map -> mbox_r ); /* unlock ctx_cap */
@@ -1670,7 +1671,7 @@ static int start_afu(struct cxlflash_cfg *cfg)
1670
1671
init_pcr (cfg );
1671
1672
1672
1673
/* Initialize each HWQ */
1673
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1674
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1674
1675
hwq = get_hwq (afu , i );
1675
1676
1676
1677
/* After an AFU reset, RRQ entries are stale, clear them */
@@ -1888,7 +1889,8 @@ static int init_afu(struct cxlflash_cfg *cfg)
1888
1889
1889
1890
cxl_perst_reloads_same_image (cfg -> cxl_afu , true);
1890
1891
1891
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1892
+ afu -> num_hwqs = afu -> desired_hwqs ;
1893
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1892
1894
rc = init_mc (cfg , i );
1893
1895
if (rc ) {
1894
1896
dev_err (dev , "%s: init_mc failed rc=%d index=%d\n" ,
@@ -1939,7 +1941,7 @@ static int init_afu(struct cxlflash_cfg *cfg)
1939
1941
}
1940
1942
1941
1943
afu_err_intr_init (cfg -> afu );
1942
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
1944
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
1943
1945
hwq = get_hwq (afu , i );
1944
1946
1945
1947
spin_lock_init (& hwq -> rrin_slock );
@@ -1953,7 +1955,7 @@ static int init_afu(struct cxlflash_cfg *cfg)
1953
1955
return rc ;
1954
1956
1955
1957
err1 :
1956
- for (i = CXLFLASH_NUM_HWQS - 1 ; i >= 0 ; i -- ) {
1958
+ for (i = afu -> num_hwqs - 1 ; i >= 0 ; i -- ) {
1957
1959
term_intr (cfg , UNMAP_THREE , i );
1958
1960
term_mc (cfg , i );
1959
1961
}
@@ -2550,7 +2552,7 @@ static ssize_t irqpoll_weight_store(struct device *dev,
2550
2552
}
2551
2553
2552
2554
if (afu_is_irqpoll_enabled (afu )) {
2553
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
2555
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
2554
2556
hwq = get_hwq (afu , i );
2555
2557
2556
2558
irq_poll_disable (& hwq -> irqpoll );
@@ -2560,7 +2562,7 @@ static ssize_t irqpoll_weight_store(struct device *dev,
2560
2562
afu -> irqpoll_weight = weight ;
2561
2563
2562
2564
if (weight > 0 ) {
2563
- for (i = 0 ; i < CXLFLASH_NUM_HWQS ; i ++ ) {
2565
+ for (i = 0 ; i < afu -> num_hwqs ; i ++ ) {
2564
2566
hwq = get_hwq (afu , i );
2565
2567
2566
2568
irq_poll_init (& hwq -> irqpoll , weight , cxlflash_irqpoll );
@@ -2570,6 +2572,88 @@ static ssize_t irqpoll_weight_store(struct device *dev,
2570
2572
return count ;
2571
2573
}
2572
2574
2575
+ /**
2576
+ * num_hwqs_show() - presents the number of hardware queues for the host
2577
+ * @dev: Generic device associated with the host.
2578
+ * @attr: Device attribute representing the number of hardware queues.
2579
+ * @buf: Buffer of length PAGE_SIZE to report back the number of hardware
2580
+ * queues in ASCII.
2581
+ *
2582
+ * Return: The size of the ASCII string returned in @buf.
2583
+ */
2584
+ static ssize_t num_hwqs_show (struct device * dev ,
2585
+ struct device_attribute * attr , char * buf )
2586
+ {
2587
+ struct cxlflash_cfg * cfg = shost_priv (class_to_shost (dev ));
2588
+ struct afu * afu = cfg -> afu ;
2589
+
2590
+ return scnprintf (buf , PAGE_SIZE , "%u\n" , afu -> num_hwqs );
2591
+ }
2592
+
2593
+ /**
2594
+ * num_hwqs_store() - sets the number of hardware queues for the host
2595
+ * @dev: Generic device associated with the host.
2596
+ * @attr: Device attribute representing the number of hardware queues.
2597
+ * @buf: Buffer of length PAGE_SIZE containing the number of hardware
2598
+ * queues in ASCII.
2599
+ * @count: Length of data resizing in @buf.
2600
+ *
2601
+ * n > 0: num_hwqs = n
2602
+ * n = 0: num_hwqs = num_online_cpus()
2603
+ * n < 0: num_online_cpus() / abs(n)
2604
+ *
2605
+ * Return: The size of the ASCII string returned in @buf.
2606
+ */
2607
+ static ssize_t num_hwqs_store (struct device * dev ,
2608
+ struct device_attribute * attr ,
2609
+ const char * buf , size_t count )
2610
+ {
2611
+ struct cxlflash_cfg * cfg = shost_priv (class_to_shost (dev ));
2612
+ struct afu * afu = cfg -> afu ;
2613
+ int rc ;
2614
+ int nhwqs , num_hwqs ;
2615
+
2616
+ rc = kstrtoint (buf , 10 , & nhwqs );
2617
+ if (rc )
2618
+ return - EINVAL ;
2619
+
2620
+ if (nhwqs >= 1 )
2621
+ num_hwqs = nhwqs ;
2622
+ else if (nhwqs == 0 )
2623
+ num_hwqs = num_online_cpus ();
2624
+ else
2625
+ num_hwqs = num_online_cpus () / abs (nhwqs );
2626
+
2627
+ afu -> desired_hwqs = min (num_hwqs , CXLFLASH_MAX_HWQS );
2628
+ WARN_ON_ONCE (afu -> desired_hwqs == 0 );
2629
+
2630
+ retry :
2631
+ switch (cfg -> state ) {
2632
+ case STATE_NORMAL :
2633
+ cfg -> state = STATE_RESET ;
2634
+ drain_ioctls (cfg );
2635
+ cxlflash_mark_contexts_error (cfg );
2636
+ rc = afu_reset (cfg );
2637
+ if (rc )
2638
+ cfg -> state = STATE_FAILTERM ;
2639
+ else
2640
+ cfg -> state = STATE_NORMAL ;
2641
+ wake_up_all (& cfg -> reset_waitq );
2642
+ break ;
2643
+ case STATE_RESET :
2644
+ wait_event (cfg -> reset_waitq , cfg -> state != STATE_RESET );
2645
+ if (cfg -> state == STATE_NORMAL )
2646
+ goto retry ;
2647
+ default :
2648
+ /* Ideally should not happen */
2649
+ dev_err (dev , "%s: Device is not ready, state=%d\n" ,
2650
+ __func__ , cfg -> state );
2651
+ break ;
2652
+ }
2653
+
2654
+ return count ;
2655
+ }
2656
+
2573
2657
/**
2574
2658
* mode_show() - presents the current mode of the device
2575
2659
* @dev: Generic device associated with the device.
@@ -2601,6 +2685,7 @@ static DEVICE_ATTR_RO(port1_lun_table);
2601
2685
static DEVICE_ATTR_RO (port2_lun_table );
2602
2686
static DEVICE_ATTR_RO (port3_lun_table );
2603
2687
static DEVICE_ATTR_RW (irqpoll_weight );
2688
+ static DEVICE_ATTR_RW (num_hwqs );
2604
2689
2605
2690
static struct device_attribute * cxlflash_host_attrs [] = {
2606
2691
& dev_attr_port0 ,
@@ -2614,6 +2699,7 @@ static struct device_attribute *cxlflash_host_attrs[] = {
2614
2699
& dev_attr_port2_lun_table ,
2615
2700
& dev_attr_port3_lun_table ,
2616
2701
& dev_attr_irqpoll_weight ,
2702
+ & dev_attr_num_hwqs ,
2617
2703
NULL
2618
2704
};
2619
2705
0 commit comments