@@ -60,10 +60,6 @@ DEFINE_SPINLOCK(zcrypt_list_lock);
60
60
LIST_HEAD (zcrypt_card_list );
61
61
62
62
static atomic_t zcrypt_open_count = ATOMIC_INIT (0 );
63
- static atomic_t zcrypt_rescan_count = ATOMIC_INIT (0 );
64
-
65
- atomic_t zcrypt_rescan_req = ATOMIC_INIT (0 );
66
- EXPORT_SYMBOL (zcrypt_rescan_req );
67
63
68
64
static LIST_HEAD (zcrypt_ops_list );
69
65
@@ -72,20 +68,15 @@ debug_info_t *zcrypt_dbf_info;
72
68
73
69
/*
74
70
* Process a rescan of the transport layer.
75
- *
76
- * Returns 1, if the rescan has been processed, otherwise 0.
71
+ * Runs a synchronous AP bus rescan.
72
+ * Returns true if something has changed (for example the
73
+ * bus scan has found and build up new devices) and it is
74
+ * worth to do a retry. Otherwise false is returned meaning
75
+ * no changes on the AP bus level.
77
76
*/
78
- static inline int zcrypt_process_rescan (void )
79
- {
80
- if (atomic_read (& zcrypt_rescan_req )) {
81
- atomic_set (& zcrypt_rescan_req , 0 );
82
- atomic_inc (& zcrypt_rescan_count );
83
- ap_bus_force_rescan ();
84
- ZCRYPT_DBF_INFO ("%s rescan count=%07d\n" , __func__ ,
85
- atomic_inc_return (& zcrypt_rescan_count ));
86
- return 1 ;
87
- }
88
- return 0 ;
77
+ static inline bool zcrypt_process_rescan (void )
78
+ {
79
+ return ap_bus_force_rescan ();
89
80
}
90
81
91
82
void zcrypt_msgtype_register (struct zcrypt_ops * zops )
@@ -1481,16 +1472,13 @@ static int icarsamodexpo_ioctl(struct ap_perms *perms, unsigned long arg)
1481
1472
1482
1473
do {
1483
1474
rc = zcrypt_rsa_modexpo (perms , & tr , & mex );
1484
- if (rc == - EAGAIN )
1485
- tr .again_counter ++ ;
1486
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1487
- /* on failure: retry once again after a requested rescan */
1488
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1475
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1476
+
1477
+ /* on ENODEV failure: retry once again after a requested rescan */
1478
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1489
1479
do {
1490
1480
rc = zcrypt_rsa_modexpo (perms , & tr , & mex );
1491
- if (rc == - EAGAIN )
1492
- tr .again_counter ++ ;
1493
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1481
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1494
1482
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1495
1483
rc = - EIO ;
1496
1484
if (rc ) {
@@ -1513,16 +1501,13 @@ static int icarsacrt_ioctl(struct ap_perms *perms, unsigned long arg)
1513
1501
1514
1502
do {
1515
1503
rc = zcrypt_rsa_crt (perms , & tr , & crt );
1516
- if (rc == - EAGAIN )
1517
- tr .again_counter ++ ;
1518
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1519
- /* on failure: retry once again after a requested rescan */
1520
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1504
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1505
+
1506
+ /* on ENODEV failure: retry once again after a requested rescan */
1507
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1521
1508
do {
1522
1509
rc = zcrypt_rsa_crt (perms , & tr , & crt );
1523
- if (rc == - EAGAIN )
1524
- tr .again_counter ++ ;
1525
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1510
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1526
1511
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1527
1512
rc = - EIO ;
1528
1513
if (rc ) {
@@ -1545,16 +1530,13 @@ static int zsecsendcprb_ioctl(struct ap_perms *perms, unsigned long arg)
1545
1530
1546
1531
do {
1547
1532
rc = _zcrypt_send_cprb (true, perms , & tr , & xcrb );
1548
- if (rc == - EAGAIN )
1549
- tr .again_counter ++ ;
1550
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1551
- /* on failure: retry once again after a requested rescan */
1552
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1533
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1534
+
1535
+ /* on ENODEV failure: retry once again after a requested rescan */
1536
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1553
1537
do {
1554
1538
rc = _zcrypt_send_cprb (true, perms , & tr , & xcrb );
1555
- if (rc == - EAGAIN )
1556
- tr .again_counter ++ ;
1557
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1539
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1558
1540
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1559
1541
rc = - EIO ;
1560
1542
if (rc )
@@ -1578,16 +1560,13 @@ static int zsendep11cprb_ioctl(struct ap_perms *perms, unsigned long arg)
1578
1560
1579
1561
do {
1580
1562
rc = _zcrypt_send_ep11_cprb (true, perms , & tr , & xcrb );
1581
- if (rc == - EAGAIN )
1582
- tr .again_counter ++ ;
1583
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1584
- /* on failure: retry once again after a requested rescan */
1585
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1563
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1564
+
1565
+ /* on ENODEV failure: retry once again after a requested rescan */
1566
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1586
1567
do {
1587
1568
rc = _zcrypt_send_ep11_cprb (true, perms , & tr , & xcrb );
1588
- if (rc == - EAGAIN )
1589
- tr .again_counter ++ ;
1590
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1569
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1591
1570
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1592
1571
rc = - EIO ;
1593
1572
if (rc )
@@ -1758,16 +1737,13 @@ static long trans_modexpo32(struct ap_perms *perms, struct file *filp,
1758
1737
mex64 .n_modulus = compat_ptr (mex32 .n_modulus );
1759
1738
do {
1760
1739
rc = zcrypt_rsa_modexpo (perms , & tr , & mex64 );
1761
- if (rc == - EAGAIN )
1762
- tr .again_counter ++ ;
1763
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1764
- /* on failure: retry once again after a requested rescan */
1765
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1740
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1741
+
1742
+ /* on ENODEV failure: retry once again after a requested rescan */
1743
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1766
1744
do {
1767
1745
rc = zcrypt_rsa_modexpo (perms , & tr , & mex64 );
1768
- if (rc == - EAGAIN )
1769
- tr .again_counter ++ ;
1770
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1746
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1771
1747
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1772
1748
rc = - EIO ;
1773
1749
if (rc )
@@ -1811,16 +1787,13 @@ static long trans_modexpo_crt32(struct ap_perms *perms, struct file *filp,
1811
1787
crt64 .u_mult_inv = compat_ptr (crt32 .u_mult_inv );
1812
1788
do {
1813
1789
rc = zcrypt_rsa_crt (perms , & tr , & crt64 );
1814
- if (rc == - EAGAIN )
1815
- tr .again_counter ++ ;
1816
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1817
- /* on failure: retry once again after a requested rescan */
1818
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1790
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1791
+
1792
+ /* on ENODEV failure: retry once again after a requested rescan */
1793
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1819
1794
do {
1820
1795
rc = zcrypt_rsa_crt (perms , & tr , & crt64 );
1821
- if (rc == - EAGAIN )
1822
- tr .again_counter ++ ;
1823
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1796
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1824
1797
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1825
1798
rc = - EIO ;
1826
1799
if (rc )
@@ -1883,16 +1856,13 @@ static long trans_xcrb32(struct ap_perms *perms, struct file *filp,
1883
1856
xcrb64 .status = xcrb32 .status ;
1884
1857
do {
1885
1858
rc = _zcrypt_send_cprb (true, perms , & tr , & xcrb64 );
1886
- if (rc == - EAGAIN )
1887
- tr .again_counter ++ ;
1888
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1889
- /* on failure: retry once again after a requested rescan */
1890
- if ((rc == - ENODEV ) && (zcrypt_process_rescan ()))
1859
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1860
+
1861
+ /* on ENODEV failure: retry once again after a requested rescan */
1862
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1891
1863
do {
1892
1864
rc = _zcrypt_send_cprb (true, perms , & tr , & xcrb64 );
1893
- if (rc == - EAGAIN )
1894
- tr .again_counter ++ ;
1895
- } while (rc == - EAGAIN && tr .again_counter < TRACK_AGAIN_MAX );
1865
+ } while (rc == - EAGAIN && ++ tr .again_counter < TRACK_AGAIN_MAX );
1896
1866
if (rc == - EAGAIN && tr .again_counter >= TRACK_AGAIN_MAX )
1897
1867
rc = - EIO ;
1898
1868
xcrb32 .reply_control_blk_length = xcrb64 .reply_control_blk_length ;
@@ -1964,8 +1934,8 @@ static int zcrypt_rng_data_read(struct hwrng *rng, u32 *data)
1964
1934
*/
1965
1935
if (zcrypt_rng_buffer_index == 0 ) {
1966
1936
rc = zcrypt_rng ((char * )zcrypt_rng_buffer );
1967
- /* on failure: retry once again after a requested rescan */
1968
- if (( rc == - ENODEV ) && ( zcrypt_process_rescan () ))
1937
+ /* on ENODEV failure: retry once again after an AP bus rescan */
1938
+ if (rc == - ENODEV && zcrypt_process_rescan ())
1969
1939
rc = zcrypt_rng ((char * )zcrypt_rng_buffer );
1970
1940
if (rc < 0 )
1971
1941
return - EIO ;
@@ -2027,7 +1997,7 @@ void zcrypt_rng_device_remove(void)
2027
1997
* an asynchronous job. This function waits until these initial jobs
2028
1998
* are done and so the zcrypt api should be ready to serve crypto
2029
1999
* requests - if there are resources available. The function uses an
2030
- * internal timeout of 60s . The very first caller will either wait for
2000
+ * internal timeout of 30s . The very first caller will either wait for
2031
2001
* ap bus bindings complete or the timeout happens. This state will be
2032
2002
* remembered for further callers which will only be blocked until a
2033
2003
* decision is made (timeout or bindings complete).
@@ -2047,7 +2017,7 @@ int zcrypt_wait_api_operational(void)
2047
2017
case 0 :
2048
2018
/* initial state, invoke wait for the ap bus complete */
2049
2019
rc = ap_wait_apqn_bindings_complete (
2050
- msecs_to_jiffies (60 * 1000 ));
2020
+ msecs_to_jiffies (ZCRYPT_WAIT_BINDINGS_COMPLETE_MS ));
2051
2021
switch (rc ) {
2052
2022
case 0 :
2053
2023
/* ap bus bindings are complete */
0 commit comments