]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
s390/zcrypt: Introduce QACT support for AP bus devices.
authorHarald Freudenberger <freude@linux.vnet.ibm.com>
Mon, 16 Oct 2017 10:28:35 +0000 (12:28 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 23 Oct 2017 07:07:14 +0000 (09:07 +0200)
This patch introduces a new ap_qact() function which
exploits the PQAP(QACT) subfunction. QACT is a new
interface to Query the Ap Compatilibity Type based
on a given AP qid, type, mode and version.

Based on this new function the AP bus scan code is
slightly reworked to use this new interface for
querying the compatible type for each new AP queue
device detected. So new and unknown devices can
get automatically mapped to a compatible type and
handled without the need for toleration patches
for every new hardware.

The currently highest known hardware is CEX6S.
With this patch a possible successor can get
queried for a combatible type known by the device
driver without the need for an toleration patch.

Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/crypto/ap_asm.h
drivers/s390/crypto/ap_bus.c
drivers/s390/crypto/ap_bus.h
drivers/s390/crypto/ap_card.c
drivers/s390/crypto/ap_queue.c

index cd350345b3d25885c6cce02d8f357f387bdfbcc1..0c0c02f26f5be29d10ab3be4bc99c72eb8a6bef7 100644 (file)
@@ -116,6 +116,49 @@ static inline int ap_qci(void *config)
        return reg1;
 }
 
+/*
+ * struct ap_qact_ap_info - used together with the
+ * ap_aqic() function to provide a convenient way
+ * to handle the ap info needed by the qact function.
+ */
+struct ap_qact_ap_info {
+       unsigned int _res1   : 3;
+       unsigned int mode    : 3;
+       unsigned int _res2   : 26;
+       unsigned int cat     : 8;
+       unsigned int _res3   : 8;
+       unsigned char ver[2];
+};
+
+/**
+ * ap_qact(): Query AP combatibility type.
+ * @qid: The AP queue number
+ * @apinfo: On input the info about the AP queue (content of GR1
+ *         according to the AR). On output the alternate AP queue
+ *         info provided by the qact function in GR2 is stored in.
+ *
+ * Returns AP queue status. Check response_code field for failures.
+ */
+static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit,
+                                            struct ap_qact_ap_info *apinfo)
+{
+       register unsigned long reg0 asm ("0") = qid | (5UL << 24)
+               | ((ifbit & 0x01) << 22);
+       register struct ap_qact_ap_info reg1_in asm ("1") = *apinfo;
+       register struct ap_queue_status reg1_out asm ("1");
+       register unsigned long reg2_in asm ("2") = 0;
+       register struct ap_qact_ap_info reg2_out asm ("2");
+
+       asm volatile(
+               ".long 0xb2af0000"              /* PQAP(QACT) */
+               : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out),
+                 "+d" (reg2_in), "=d" (reg2_out)
+               :
+               : "cc");
+       *apinfo = reg2_out;
+       return reg1_out;
+}
+
 /**
  * ap_nqap(): Send message to adjunct processor queue.
  * @qid: The AP queue number
index 5f0be20402726d7f6b9c0d4816cf32580077eb09..0c1c48c476b77cabb146f7d485552e4dddf6d9f3 100644 (file)
@@ -176,6 +176,18 @@ static int ap_apft_available(void)
        return test_facility(15);
 }
 
+/*
+ * ap_qact_available(): Test if the PQAP(QACT) subfunction is available.
+ *
+ * Returns 1 if the QACT subfunction is available.
+ */
+static inline int ap_qact_available(void)
+{
+       if (ap_configuration)
+               return ap_configuration->qact;
+       return 0;
+}
+
 /**
  * ap_test_queue(): Test adjunct processor queue.
  * @qid: The AP queue number
@@ -987,6 +999,47 @@ static int ap_select_domain(void)
        return -ENODEV;
 }
 
+/*
+ * This function checks the type and returns either 0 for not
+ * supported or the highest compatible type value (which may
+ * include the input type value).
+ */
+static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
+{
+       int comp_type = 0;
+
+       /* < CEX2A is not supported */
+       if (rawtype < AP_DEVICE_TYPE_CEX2A)
+               return 0;
+       /* up to CEX6 known and fully supported */
+       if (rawtype <= AP_DEVICE_TYPE_CEX6)
+               return rawtype;
+       /*
+        * unknown new type > CEX6, check for compatibility
+        * to the highest known and supported type which is
+        * currently CEX6 with the help of the QACT function.
+        */
+       if (ap_qact_available()) {
+               struct ap_queue_status status;
+               struct ap_qact_ap_info apinfo = {0};
+
+               apinfo.mode = (func >> 26) & 0x07;
+               apinfo.cat = AP_DEVICE_TYPE_CEX6;
+               status = ap_qact(qid, 0, &apinfo);
+               if (status.response_code == AP_RESPONSE_NORMAL
+                   && apinfo.cat >= AP_DEVICE_TYPE_CEX2A
+                   && apinfo.cat <= AP_DEVICE_TYPE_CEX6)
+                       comp_type = apinfo.cat;
+       }
+       if (!comp_type)
+               AP_DBF(DBF_WARN, "queue=%02x.%04x unable to map type %d\n",
+                      AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
+       else if (comp_type != rawtype)
+               AP_DBF(DBF_INFO, "queue=%02x.%04x map type %d to %d\n",
+                      AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype, comp_type);
+       return comp_type;
+}
+
 /*
  * helper function to be used with bus_find_dev
  * matches for the card device with the given id
@@ -1014,8 +1067,8 @@ static void ap_scan_bus(struct work_struct *unused)
        struct ap_card *ac;
        struct device *dev;
        ap_qid_t qid;
-       int depth = 0, type = 0;
-       unsigned int functions = 0;
+       int comp_type, depth = 0, type = 0;
+       unsigned int func = 0;
        int rc, id, dom, borked, domains, defdomdevs = 0;
 
        AP_DBF(DBF_DEBUG, "ap_scan_bus running\n");
@@ -1066,12 +1119,12 @@ static void ap_scan_bus(struct work_struct *unused)
                                }
                                continue;
                        }
-                       rc = ap_query_queue(qid, &depth, &type, &functions);
+                       rc = ap_query_queue(qid, &depth, &type, &func);
                        if (dev) {
                                spin_lock_bh(&aq->lock);
                                if (rc == -ENODEV ||
                                    /* adapter reconfiguration */
-                                   (ac && ac->functions != functions))
+                                   (ac && ac->functions != func))
                                        aq->state = AP_STATE_BORKED;
                                borked = aq->state == AP_STATE_BORKED;
                                spin_unlock_bh(&aq->lock);
@@ -1087,11 +1140,14 @@ static void ap_scan_bus(struct work_struct *unused)
                        }
                        if (rc)
                                continue;
-                       /* new queue device needed */
+                       /* a new queue device is needed, check out comp type */
+                       comp_type = ap_get_compatible_type(qid, type, func);
+                       if (!comp_type)
+                               continue;
+                       /* maybe a card device needs to be created first */
                        if (!ac) {
-                               /* but first create the card device */
-                               ac = ap_card_create(id, depth,
-                                                   type, functions);
+                               ac = ap_card_create(id, depth, type,
+                                                   comp_type, func);
                                if (!ac)
                                        continue;
                                ac->ap_dev.device.bus = &ap_bus_type;
@@ -1109,7 +1165,7 @@ static void ap_scan_bus(struct work_struct *unused)
                                get_device(&ac->ap_dev.device);
                        }
                        /* now create the new queue device */
-                       aq = ap_queue_create(qid, type);
+                       aq = ap_queue_create(qid, comp_type);
                        if (!aq)
                                continue;
                        aq->card = ac;
index 754cf2223cfbdde3f8312acc868e8aadae998851..3a0e19d87e7cebf295dca38e22910430440f5435 100644 (file)
@@ -250,8 +250,8 @@ void ap_queue_remove(struct ap_queue *aq);
 void ap_queue_suspend(struct ap_device *ap_dev);
 void ap_queue_resume(struct ap_device *ap_dev);
 
-struct ap_card *ap_card_create(int id, int queue_depth, int device_type,
-                              unsigned int device_functions);
+struct ap_card *ap_card_create(int id, int queue_depth, int raw_device_type,
+                              int comp_device_type, unsigned int functions);
 
 int ap_module_init(void);
 void ap_module_exit(void);
index e8300630e1978ad25cd98b4e3e1ec89095eca2b2..428623fa517e0cc5816e7147a317e8e13664aa7b 100644 (file)
@@ -170,19 +170,20 @@ static void ap_card_device_release(struct device *dev)
        kfree(ac);
 }
 
-struct ap_card *ap_card_create(int id, int queue_depth, int device_type,
-                              unsigned int functions)
+struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
+                              int comp_type, unsigned int functions)
 {
        struct ap_card *ac;
 
        ac = kzalloc(sizeof(*ac), GFP_KERNEL);
        if (!ac)
                return NULL;
+       INIT_LIST_HEAD(&ac->list);
        INIT_LIST_HEAD(&ac->queues);
        ac->ap_dev.device.release = ap_card_device_release;
        ac->ap_dev.device.type = &ap_card_type;
-       ac->ap_dev.device_type = device_type;
-       ac->raw_hwtype = device_type;
+       ac->ap_dev.device_type = comp_type;
+       ac->raw_hwtype = raw_type;
        ac->queue_depth = queue_depth;
        ac->functions = functions;
        ac->id = id;
index d15903926f461fa72a35bcc039c2501d5ed3f3ae..6f3fcc959796c76303a1a811944228fb51937766 100644 (file)
@@ -630,6 +630,7 @@ struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type)
        aq->state = AP_STATE_RESET_START;
        aq->interrupt = AP_INTR_DISABLED;
        spin_lock_init(&aq->lock);
+       INIT_LIST_HEAD(&aq->list);
        INIT_LIST_HEAD(&aq->pendingq);
        INIT_LIST_HEAD(&aq->requestq);
        setup_timer(&aq->timeout, ap_request_timeout, (unsigned long) aq);