Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/zcrypt: handle checkstopped cards with new state

A crypto card may be in checkstopped state. With this
patch this is handled as a new state in the ap card and
ap queue structs. There is also a new card sysfs attribute

/sys/devices/ap/cardxx/chkstop

and a new queue sysfs attribute

/sys/devices/ap/cardxx/xx.yyyy/chkstop

displaying the checkstop state of the card or queue. Please
note that the queue's checkstop state is only a copy of the
card's checkstop state but makes maintenance much easier.

The checkstop state expressed here is the result of an
RC 0x04 (CHECKSTOP) during an AP command, mostly the
PQAP(TAPQ) command which is 'testing' the queue.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Jürgen Christ <jchrist@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

authored by

Harald Freudenberger and committed by
Vasily Gorbik
a7e701db 985214af

+105 -30
+63 -15
drivers/s390/crypto/ap_bus.c
··· 323 323 * false otherwise. 324 324 */ 325 325 static bool ap_queue_info(ap_qid_t qid, int *q_type, unsigned int *q_fac, 326 - int *q_depth, int *q_ml, bool *q_decfg) 326 + int *q_depth, int *q_ml, bool *q_decfg, bool *q_cstop) 327 327 { 328 328 struct ap_queue_status status; 329 329 union { ··· 366 366 *q_depth = tapq_info.tapq_gr2.qd; 367 367 *q_ml = tapq_info.tapq_gr2.ml; 368 368 *q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED; 369 + *q_cstop = status.response_code == AP_RESPONSE_CHECKSTOPPED; 369 370 switch (*q_type) { 370 371 /* For CEX2 and CEX3 the available functions 371 372 * are not reflected by the facilities bits. ··· 1711 1710 */ 1712 1711 static inline void ap_scan_domains(struct ap_card *ac) 1713 1712 { 1714 - bool decfg; 1713 + bool decfg, chkstop; 1715 1714 ap_qid_t qid; 1716 1715 unsigned int func; 1717 1716 struct device *dev; ··· 1740 1739 continue; 1741 1740 } 1742 1741 /* domain is valid, get info from this APQN */ 1743 - if (!ap_queue_info(qid, &type, &func, &depth, &ml, &decfg)) { 1742 + if (!ap_queue_info(qid, &type, &func, &depth, 1743 + &ml, &decfg, &chkstop)) { 1744 1744 if (aq) { 1745 1745 AP_DBF_INFO("%s(%d,%d) queue_info() failed, rm queue dev\n", 1746 1746 __func__, ac->id, dom); ··· 1760 1758 } 1761 1759 aq->card = ac; 1762 1760 aq->config = !decfg; 1761 + aq->chkstop = chkstop; 1763 1762 dev = &aq->ap_dev.device; 1764 1763 dev->bus = &ap_bus_type; 1765 1764 dev->parent = &ac->ap_dev.device; ··· 1777 1774 if (decfg) 1778 1775 AP_DBF_INFO("%s(%d,%d) new (decfg) queue dev created\n", 1779 1776 __func__, ac->id, dom); 1777 + else if (chkstop) 1778 + AP_DBF_INFO("%s(%d,%d) new (chkstop) queue dev created\n", 1779 + __func__, ac->id, dom); 1780 1780 else 1781 1781 AP_DBF_INFO("%s(%d,%d) new queue dev created\n", 1782 1782 __func__, ac->id, dom); 1783 1783 goto put_dev_and_continue; 1784 1784 } 1785 - /* Check config state on the already existing queue device */ 1785 + /* handle state changes on already existing queue device */ 1786 1786 spin_lock_bh(&aq->lock); 1787 + /* checkstop state */ 1788 + if (chkstop && !aq->chkstop) { 1789 + /* checkstop on */ 1790 + aq->chkstop = true; 1791 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { 1792 + aq->dev_state = AP_DEV_STATE_ERROR; 1793 + aq->last_err_rc = AP_RESPONSE_CHECKSTOPPED; 1794 + } 1795 + spin_unlock_bh(&aq->lock); 1796 + AP_DBF_DBG("%s(%d,%d) queue dev checkstop on\n", 1797 + __func__, ac->id, dom); 1798 + /* 'receive' pending messages with -EAGAIN */ 1799 + ap_flush_queue(aq); 1800 + goto put_dev_and_continue; 1801 + } else if (!chkstop && aq->chkstop) { 1802 + /* checkstop off */ 1803 + aq->chkstop = false; 1804 + if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { 1805 + aq->dev_state = AP_DEV_STATE_OPERATING; 1806 + aq->sm_state = AP_SM_STATE_RESET_START; 1807 + } 1808 + spin_unlock_bh(&aq->lock); 1809 + AP_DBF_DBG("%s(%d,%d) queue dev checkstop off\n", 1810 + __func__, ac->id, dom); 1811 + goto put_dev_and_continue; 1812 + } 1813 + /* config state change */ 1787 1814 if (decfg && aq->config) { 1788 1815 /* config off this queue device */ 1789 1816 aq->config = false; ··· 1822 1789 aq->last_err_rc = AP_RESPONSE_DECONFIGURED; 1823 1790 } 1824 1791 spin_unlock_bh(&aq->lock); 1825 - AP_DBF_INFO("%s(%d,%d) queue dev config off\n", 1826 - __func__, ac->id, dom); 1792 + AP_DBF_DBG("%s(%d,%d) queue dev config off\n", 1793 + __func__, ac->id, dom); 1827 1794 ap_send_config_uevent(&aq->ap_dev, aq->config); 1828 1795 /* 'receive' pending messages with -EAGAIN */ 1829 1796 ap_flush_queue(aq); 1830 1797 goto put_dev_and_continue; 1831 - } 1832 - if (!decfg && !aq->config) { 1798 + } else if (!decfg && !aq->config) { 1833 1799 /* config on this queue device */ 1834 1800 aq->config = true; 1835 1801 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) { ··· 1836 1804 aq->sm_state = AP_SM_STATE_RESET_START; 1837 1805 } 1838 1806 spin_unlock_bh(&aq->lock); 1839 - AP_DBF_INFO("%s(%d,%d) queue dev config on\n", 1840 - __func__, ac->id, dom); 1807 + AP_DBF_DBG("%s(%d,%d) queue dev config on\n", 1808 + __func__, ac->id, dom); 1841 1809 ap_send_config_uevent(&aq->ap_dev, aq->config); 1842 1810 goto put_dev_and_continue; 1843 1811 } ··· 1864 1832 */ 1865 1833 static inline void ap_scan_adapter(int ap) 1866 1834 { 1867 - bool decfg; 1835 + bool decfg, chkstop; 1868 1836 ap_qid_t qid; 1869 1837 unsigned int func; 1870 1838 struct device *dev; ··· 1898 1866 for (dom = 0; dom <= ap_max_domain_id; dom++) 1899 1867 if (ap_test_config_usage_domain(dom)) { 1900 1868 qid = AP_MKQID(ap, dom); 1901 - if (ap_queue_info(qid, &type, &func, 1902 - &depth, &ml, &decfg)) 1869 + if (ap_queue_info(qid, &type, &func, &depth, 1870 + &ml, &decfg, &chkstop)) 1903 1871 break; 1904 1872 } 1905 1873 if (dom > ap_max_domain_id) { ··· 1944 1912 put_device(dev); 1945 1913 ac = NULL; 1946 1914 } else { 1915 + /* handle checkstop state change */ 1916 + if (chkstop && !ac->chkstop) { 1917 + /* checkstop on */ 1918 + ac->chkstop = true; 1919 + AP_DBF_INFO("%s(%d) card dev checkstop on\n", 1920 + __func__, ap); 1921 + } else if (!chkstop && ac->chkstop) { 1922 + /* checkstop off */ 1923 + ac->chkstop = false; 1924 + AP_DBF_INFO("%s(%d) card dev checkstop off\n", 1925 + __func__, ap); 1926 + } 1927 + /* handle config state change */ 1947 1928 if (decfg && ac->config) { 1948 1929 ac->config = false; 1949 1930 AP_DBF_INFO("%s(%d) card dev config off\n", 1950 1931 __func__, ap); 1951 1932 ap_send_config_uevent(&ac->ap_dev, ac->config); 1952 - } 1953 - if (!decfg && !ac->config) { 1933 + } else if (!decfg && !ac->config) { 1954 1934 ac->config = true; 1955 1935 AP_DBF_INFO("%s(%d) card dev config on\n", 1956 1936 __func__, ap); ··· 1986 1942 return; 1987 1943 } 1988 1944 ac->config = !decfg; 1945 + ac->chkstop = chkstop; 1989 1946 dev = &ac->ap_dev.device; 1990 1947 dev->bus = &ap_bus_type; 1991 1948 dev->parent = ap_root_device; ··· 2010 1965 get_device(dev); 2011 1966 if (decfg) 2012 1967 AP_DBF_INFO("%s(%d) new (decfg) card dev type=%d func=0x%08x created\n", 1968 + __func__, ap, type, func); 1969 + else if (chkstop) 1970 + AP_DBF_INFO("%s(%d) new (chkstop) card dev type=%d func=0x%08x created\n", 2013 1971 __func__, ap, type, func); 2014 1972 else 2015 1973 AP_DBF_INFO("%s(%d) new card dev type=%d func=0x%08x created\n",
+2
drivers/s390/crypto/ap_bus.h
··· 179 179 int id; /* AP card number. */ 180 180 unsigned int maxmsgsize; /* AP msg limit for this card */ 181 181 bool config; /* configured state */ 182 + bool chkstop; /* checkstop state */ 182 183 atomic64_t total_request_count; /* # requests ever for this AP device.*/ 183 184 }; 184 185 ··· 192 191 spinlock_t lock; /* Per device lock. */ 193 192 enum ap_dev_state dev_state; /* queue device state */ 194 193 bool config; /* configured state */ 194 + bool chkstop; /* checkstop state */ 195 195 ap_qid_t qid; /* AP queue id. */ 196 196 bool interrupt; /* indicate if interrupts are enabled */ 197 197 int queue_count; /* # messages currently on AP queue. */
+11
drivers/s390/crypto/ap_card.c
··· 174 174 175 175 static DEVICE_ATTR_RW(config); 176 176 177 + static ssize_t chkstop_show(struct device *dev, 178 + struct device_attribute *attr, char *buf) 179 + { 180 + struct ap_card *ac = to_ap_card(dev); 181 + 182 + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->chkstop ? 1 : 0); 183 + } 184 + 185 + static DEVICE_ATTR_RO(chkstop); 186 + 177 187 static ssize_t max_msg_size_show(struct device *dev, 178 188 struct device_attribute *attr, char *buf) 179 189 { ··· 204 194 &dev_attr_pendingq_count.attr, 205 195 &dev_attr_modalias.attr, 206 196 &dev_attr_config.attr, 197 + &dev_attr_chkstop.attr, 207 198 &dev_attr_max_msg_size.attr, 208 199 NULL 209 200 };
+17 -1
drivers/s390/crypto/ap_queue.c
··· 455 455 456 456 enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event) 457 457 { 458 - if (aq->config && aq->dev_state > AP_DEV_STATE_UNINITIATED) 458 + if (aq->config && !aq->chkstop && 459 + aq->dev_state > AP_DEV_STATE_UNINITIATED) 459 460 return ap_jumptable[aq->sm_state][event](aq); 460 461 else 461 462 return AP_SM_WAIT_NONE; ··· 616 615 617 616 static DEVICE_ATTR_RO(config); 618 617 618 + static ssize_t chkstop_show(struct device *dev, 619 + struct device_attribute *attr, char *buf) 620 + { 621 + struct ap_queue *aq = to_ap_queue(dev); 622 + int rc; 623 + 624 + spin_lock_bh(&aq->lock); 625 + rc = scnprintf(buf, PAGE_SIZE, "%d\n", aq->chkstop ? 1 : 0); 626 + spin_unlock_bh(&aq->lock); 627 + return rc; 628 + } 629 + 630 + static DEVICE_ATTR_RO(chkstop); 631 + 619 632 #ifdef CONFIG_ZCRYPT_DEBUG 620 633 static ssize_t states_show(struct device *dev, 621 634 struct device_attribute *attr, char *buf) ··· 744 729 &dev_attr_reset.attr, 745 730 &dev_attr_interrupt.attr, 746 731 &dev_attr_config.attr, 732 + &dev_attr_chkstop.attr, 747 733 #ifdef CONFIG_ZCRYPT_DEBUG 748 734 &dev_attr_states.attr, 749 735 &dev_attr_last_err_rc.attr,
+12 -14
drivers/s390/crypto/zcrypt_api.c
··· 671 671 spin_lock(&zcrypt_list_lock); 672 672 for_each_zcrypt_card(zc) { 673 673 /* Check for useable accelarator or CCA card */ 674 - if (!zc->online || !zc->card->config || 674 + if (!zc->online || !zc->card->config || zc->card->chkstop || 675 675 !(zc->card->functions & 0x18000000)) 676 676 continue; 677 677 /* Check for size limits */ ··· 692 692 for_each_zcrypt_queue(zq, zc) { 693 693 /* check if device is useable and eligible */ 694 694 if (!zq->online || !zq->ops->rsa_modexpo || 695 - !zq->queue->config) 695 + !zq->queue->config || zq->queue->chkstop) 696 696 continue; 697 697 /* check if device node has admission for this queue */ 698 698 if (!zcrypt_check_queue(perms, ··· 781 781 spin_lock(&zcrypt_list_lock); 782 782 for_each_zcrypt_card(zc) { 783 783 /* Check for useable accelarator or CCA card */ 784 - if (!zc->online || !zc->card->config || 784 + if (!zc->online || !zc->card->config || zc->card->chkstop || 785 785 !(zc->card->functions & 0x18000000)) 786 786 continue; 787 787 /* Check for size limits */ ··· 802 802 for_each_zcrypt_queue(zq, zc) { 803 803 /* check if device is useable and eligible */ 804 804 if (!zq->online || !zq->ops->rsa_modexpo_crt || 805 - !zq->queue->config) 805 + !zq->queue->config || zq->queue->chkstop) 806 806 continue; 807 807 /* check if device node has admission for this queue */ 808 808 if (!zcrypt_check_queue(perms, ··· 895 895 spin_lock(&zcrypt_list_lock); 896 896 for_each_zcrypt_card(zc) { 897 897 /* Check for useable CCA card */ 898 - if (!zc->online || !zc->card->config || 898 + if (!zc->online || !zc->card->config || zc->card->chkstop || 899 899 !(zc->card->functions & 0x10000000)) 900 900 continue; 901 901 /* Check for user selected CCA card */ ··· 918 918 continue; 919 919 for_each_zcrypt_queue(zq, zc) { 920 920 /* check for device useable and eligible */ 921 - if (!zq->online || 922 - !zq->ops->send_cprb || 923 - !zq->queue->config || 921 + if (!zq->online || !zq->ops->send_cprb || 922 + !zq->queue->config || zq->queue->chkstop || 924 923 (tdom != AUTOSEL_DOM && 925 924 tdom != AP_QID_QUEUE(zq->queue->qid))) 926 925 continue; ··· 1067 1068 spin_lock(&zcrypt_list_lock); 1068 1069 for_each_zcrypt_card(zc) { 1069 1070 /* Check for useable EP11 card */ 1070 - if (!zc->online || !zc->card->config || 1071 + if (!zc->online || !zc->card->config || zc->card->chkstop || 1071 1072 !(zc->card->functions & 0x04000000)) 1072 1073 continue; 1073 1074 /* Check for user selected EP11 card */ ··· 1090 1091 continue; 1091 1092 for_each_zcrypt_queue(zq, zc) { 1092 1093 /* check if device is useable and eligible */ 1093 - if (!zq->online || 1094 - !zq->ops->send_ep11_cprb || 1095 - !zq->queue->config || 1094 + if (!zq->online || !zq->ops->send_ep11_cprb || 1095 + !zq->queue->config || zq->queue->chkstop || 1096 1096 (targets && 1097 1097 !is_desired_ep11_queue(zq->queue->qid, 1098 1098 target_num, targets))) ··· 1180 1182 spin_lock(&zcrypt_list_lock); 1181 1183 for_each_zcrypt_card(zc) { 1182 1184 /* Check for useable CCA card */ 1183 - if (!zc->online || !zc->card->config || 1185 + if (!zc->online || !zc->card->config || zc->card->chkstop || 1184 1186 !(zc->card->functions & 0x10000000)) 1185 1187 continue; 1186 1188 /* get weight index of the card device */ ··· 1190 1192 for_each_zcrypt_queue(zq, zc) { 1191 1193 /* check if device is useable and eligible */ 1192 1194 if (!zq->online || !zq->ops->rng || 1193 - !zq->queue->config) 1195 + !zq->queue->config || zq->queue->chkstop) 1194 1196 continue; 1195 1197 if (!zcrypt_queue_compare(zq, pref_zq, wgt, pref_wgt)) 1196 1198 continue;