Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *   S/390 common I/O routines -- channel subsystem call
0004  *
0005  *    Copyright IBM Corp. 1999,2012
0006  *    Author(s): Ingo Adlung (adlung@de.ibm.com)
0007  *       Cornelia Huck (cornelia.huck@de.ibm.com)
0008  *       Arnd Bergmann (arndb@de.ibm.com)
0009  */
0010 
0011 #define KMSG_COMPONENT "cio"
0012 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0013 
0014 #include <linux/module.h>
0015 #include <linux/slab.h>
0016 #include <linux/init.h>
0017 #include <linux/device.h>
0018 #include <linux/mutex.h>
0019 #include <linux/pci.h>
0020 
0021 #include <asm/cio.h>
0022 #include <asm/chpid.h>
0023 #include <asm/chsc.h>
0024 #include <asm/crw.h>
0025 #include <asm/isc.h>
0026 #include <asm/ebcdic.h>
0027 #include <asm/ap.h>
0028 
0029 #include "css.h"
0030 #include "cio.h"
0031 #include "cio_debug.h"
0032 #include "ioasm.h"
0033 #include "chp.h"
0034 #include "chsc.h"
0035 
0036 static void *sei_page;
0037 static void *chsc_page;
0038 static DEFINE_SPINLOCK(chsc_page_lock);
0039 
0040 #define SEI_VF_FLA  0xc0 /* VF flag for Full Link Address */
0041 #define SEI_RS_CHPID    0x4  /* 4 in RS field indicates CHPID */
0042 
0043 /**
0044  * chsc_error_from_response() - convert a chsc response to an error
0045  * @response: chsc response code
0046  *
0047  * Returns an appropriate Linux error code for @response.
0048  */
0049 int chsc_error_from_response(int response)
0050 {
0051     switch (response) {
0052     case 0x0001:
0053         return 0;
0054     case 0x0002:
0055     case 0x0003:
0056     case 0x0006:
0057     case 0x0007:
0058     case 0x0008:
0059     case 0x000a:
0060     case 0x0104:
0061         return -EINVAL;
0062     case 0x0004:
0063     case 0x0106:        /* "Wrong Channel Parm" for the op 0x003d */
0064         return -EOPNOTSUPP;
0065     case 0x000b:
0066     case 0x0107:        /* "Channel busy" for the op 0x003d */
0067         return -EBUSY;
0068     case 0x0100:
0069     case 0x0102:
0070         return -ENOMEM;
0071     case 0x0108:        /* "HW limit exceeded" for the op 0x003d */
0072         return -EUSERS;
0073     default:
0074         return -EIO;
0075     }
0076 }
0077 EXPORT_SYMBOL_GPL(chsc_error_from_response);
0078 
0079 struct chsc_ssd_area {
0080     struct chsc_header request;
0081     u16 :10;
0082     u16 ssid:2;
0083     u16 :4;
0084     u16 f_sch;    /* first subchannel */
0085     u16 :16;
0086     u16 l_sch;    /* last subchannel */
0087     u32 :32;
0088     struct chsc_header response;
0089     u32 :32;
0090     u8 sch_valid : 1;
0091     u8 dev_valid : 1;
0092     u8 st        : 3; /* subchannel type */
0093     u8 zeroes    : 3;
0094     u8  unit_addr;    /* unit address */
0095     u16 devno;    /* device number */
0096     u8 path_mask;
0097     u8 fla_valid_mask;
0098     u16 sch;      /* subchannel */
0099     u8 chpid[8];      /* chpids 0-7 */
0100     u16 fla[8];   /* full link addresses 0-7 */
0101 } __packed __aligned(PAGE_SIZE);
0102 
0103 int chsc_get_ssd_info(struct subchannel_id schid, struct chsc_ssd_info *ssd)
0104 {
0105     struct chsc_ssd_area *ssd_area;
0106     unsigned long flags;
0107     int ccode;
0108     int ret;
0109     int i;
0110     int mask;
0111 
0112     spin_lock_irqsave(&chsc_page_lock, flags);
0113     memset(chsc_page, 0, PAGE_SIZE);
0114     ssd_area = chsc_page;
0115     ssd_area->request.length = 0x0010;
0116     ssd_area->request.code = 0x0004;
0117     ssd_area->ssid = schid.ssid;
0118     ssd_area->f_sch = schid.sch_no;
0119     ssd_area->l_sch = schid.sch_no;
0120 
0121     ccode = chsc(ssd_area);
0122     /* Check response. */
0123     if (ccode > 0) {
0124         ret = (ccode == 3) ? -ENODEV : -EBUSY;
0125         goto out;
0126     }
0127     ret = chsc_error_from_response(ssd_area->response.code);
0128     if (ret != 0) {
0129         CIO_MSG_EVENT(2, "chsc: ssd failed for 0.%x.%04x (rc=%04x)\n",
0130                   schid.ssid, schid.sch_no,
0131                   ssd_area->response.code);
0132         goto out;
0133     }
0134     if (!ssd_area->sch_valid) {
0135         ret = -ENODEV;
0136         goto out;
0137     }
0138     /* Copy data */
0139     ret = 0;
0140     memset(ssd, 0, sizeof(struct chsc_ssd_info));
0141     if ((ssd_area->st != SUBCHANNEL_TYPE_IO) &&
0142         (ssd_area->st != SUBCHANNEL_TYPE_MSG))
0143         goto out;
0144     ssd->path_mask = ssd_area->path_mask;
0145     ssd->fla_valid_mask = ssd_area->fla_valid_mask;
0146     for (i = 0; i < 8; i++) {
0147         mask = 0x80 >> i;
0148         if (ssd_area->path_mask & mask) {
0149             chp_id_init(&ssd->chpid[i]);
0150             ssd->chpid[i].id = ssd_area->chpid[i];
0151         }
0152         if (ssd_area->fla_valid_mask & mask)
0153             ssd->fla[i] = ssd_area->fla[i];
0154     }
0155 out:
0156     spin_unlock_irqrestore(&chsc_page_lock, flags);
0157     return ret;
0158 }
0159 
0160 /**
0161  * chsc_ssqd() - store subchannel QDIO data (SSQD)
0162  * @schid: id of the subchannel on which SSQD is performed
0163  * @ssqd: request and response block for SSQD
0164  *
0165  * Returns 0 on success.
0166  */
0167 int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd)
0168 {
0169     memset(ssqd, 0, sizeof(*ssqd));
0170     ssqd->request.length = 0x0010;
0171     ssqd->request.code = 0x0024;
0172     ssqd->first_sch = schid.sch_no;
0173     ssqd->last_sch = schid.sch_no;
0174     ssqd->ssid = schid.ssid;
0175 
0176     if (chsc(ssqd))
0177         return -EIO;
0178 
0179     return chsc_error_from_response(ssqd->response.code);
0180 }
0181 EXPORT_SYMBOL_GPL(chsc_ssqd);
0182 
0183 /**
0184  * chsc_sadc() - set adapter device controls (SADC)
0185  * @schid: id of the subchannel on which SADC is performed
0186  * @scssc: request and response block for SADC
0187  * @summary_indicator_addr: summary indicator address
0188  * @subchannel_indicator_addr: subchannel indicator address
0189  * @isc: Interruption Subclass for this subchannel
0190  *
0191  * Returns 0 on success.
0192  */
0193 int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
0194           u64 summary_indicator_addr, u64 subchannel_indicator_addr, u8 isc)
0195 {
0196     memset(scssc, 0, sizeof(*scssc));
0197     scssc->request.length = 0x0fe0;
0198     scssc->request.code = 0x0021;
0199     scssc->operation_code = 0;
0200 
0201     scssc->summary_indicator_addr = summary_indicator_addr;
0202     scssc->subchannel_indicator_addr = subchannel_indicator_addr;
0203 
0204     scssc->ks = PAGE_DEFAULT_KEY >> 4;
0205     scssc->kc = PAGE_DEFAULT_KEY >> 4;
0206     scssc->isc = isc;
0207     scssc->schid = schid;
0208 
0209     /* enable the time delay disablement facility */
0210     if (css_general_characteristics.aif_tdd)
0211         scssc->word_with_d_bit = 0x10000000;
0212 
0213     if (chsc(scssc))
0214         return -EIO;
0215 
0216     return chsc_error_from_response(scssc->response.code);
0217 }
0218 EXPORT_SYMBOL_GPL(chsc_sadc);
0219 
0220 static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
0221 {
0222     spin_lock_irq(sch->lock);
0223     if (sch->driver && sch->driver->chp_event)
0224         if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
0225             goto out_unreg;
0226     spin_unlock_irq(sch->lock);
0227     return 0;
0228 
0229 out_unreg:
0230     sch->lpm = 0;
0231     spin_unlock_irq(sch->lock);
0232     css_schedule_eval(sch->schid);
0233     return 0;
0234 }
0235 
0236 void chsc_chp_offline(struct chp_id chpid)
0237 {
0238     struct channel_path *chp = chpid_to_chp(chpid);
0239     struct chp_link link;
0240     char dbf_txt[15];
0241 
0242     sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
0243     CIO_TRACE_EVENT(2, dbf_txt);
0244 
0245     if (chp_get_status(chpid) <= 0)
0246         return;
0247     memset(&link, 0, sizeof(struct chp_link));
0248     link.chpid = chpid;
0249     /* Wait until previous actions have settled. */
0250     css_wait_for_slow_path();
0251 
0252     mutex_lock(&chp->lock);
0253     chp_update_desc(chp);
0254     mutex_unlock(&chp->lock);
0255 
0256     for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
0257 }
0258 
0259 static int __s390_process_res_acc(struct subchannel *sch, void *data)
0260 {
0261     spin_lock_irq(sch->lock);
0262     if (sch->driver && sch->driver->chp_event)
0263         sch->driver->chp_event(sch, data, CHP_ONLINE);
0264     spin_unlock_irq(sch->lock);
0265 
0266     return 0;
0267 }
0268 
0269 static void s390_process_res_acc(struct chp_link *link)
0270 {
0271     char dbf_txt[15];
0272 
0273     sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
0274         link->chpid.id);
0275     CIO_TRACE_EVENT( 2, dbf_txt);
0276     if (link->fla != 0) {
0277         sprintf(dbf_txt, "fla%x", link->fla);
0278         CIO_TRACE_EVENT( 2, dbf_txt);
0279     }
0280     /* Wait until previous actions have settled. */
0281     css_wait_for_slow_path();
0282     /*
0283      * I/O resources may have become accessible.
0284      * Scan through all subchannels that may be concerned and
0285      * do a validation on those.
0286      * The more information we have (info), the less scanning
0287      * will we have to do.
0288      */
0289     for_each_subchannel_staged(__s390_process_res_acc, NULL, link);
0290     css_schedule_reprobe();
0291 }
0292 
0293 static int process_fces_event(struct subchannel *sch, void *data)
0294 {
0295     spin_lock_irq(sch->lock);
0296     if (sch->driver && sch->driver->chp_event)
0297         sch->driver->chp_event(sch, data, CHP_FCES_EVENT);
0298     spin_unlock_irq(sch->lock);
0299     return 0;
0300 }
0301 
0302 struct chsc_sei_nt0_area {
0303     u8  flags;
0304     u8  vf;             /* validity flags */
0305     u8  rs;             /* reporting source */
0306     u8  cc;             /* content code */
0307     u16 fla;            /* full link address */
0308     u16 rsid;           /* reporting source id */
0309     u32 reserved1;
0310     u32 reserved2;
0311     /* ccdf has to be big enough for a link-incident record */
0312     u8  ccdf[PAGE_SIZE - 24 - 16];  /* content-code dependent field */
0313 } __packed;
0314 
0315 struct chsc_sei_nt2_area {
0316     u8  flags;          /* p and v bit */
0317     u8  reserved1;
0318     u8  reserved2;
0319     u8  cc;             /* content code */
0320     u32 reserved3[13];
0321     u8  ccdf[PAGE_SIZE - 24 - 56];  /* content-code dependent field */
0322 } __packed;
0323 
0324 #define CHSC_SEI_NT0    (1ULL << 63)
0325 #define CHSC_SEI_NT2    (1ULL << 61)
0326 
0327 struct chsc_sei {
0328     struct chsc_header request;
0329     u32 reserved1;
0330     u64 ntsm;           /* notification type mask */
0331     struct chsc_header response;
0332     u32 :24;
0333     u8 nt;
0334     union {
0335         struct chsc_sei_nt0_area nt0_area;
0336         struct chsc_sei_nt2_area nt2_area;
0337         u8 nt_area[PAGE_SIZE - 24];
0338     } u;
0339 } __packed __aligned(PAGE_SIZE);
0340 
0341 /*
0342  * Link Incident Record as defined in SA22-7202, "ESCON I/O Interface"
0343  */
0344 
0345 #define LIR_IQ_CLASS_INFO       0
0346 #define LIR_IQ_CLASS_DEGRADED       1
0347 #define LIR_IQ_CLASS_NOT_OPERATIONAL    2
0348 
0349 struct lir {
0350     struct {
0351         u32 null:1;
0352         u32 reserved:3;
0353         u32 class:2;
0354         u32 reserved2:2;
0355     } __packed iq;
0356     u32 ic:8;
0357     u32 reserved:16;
0358     struct node_descriptor incident_node;
0359     struct node_descriptor attached_node;
0360     u8 reserved2[32];
0361 } __packed;
0362 
0363 #define PARAMS_LEN  10  /* PARAMS=xx,xxxxxx */
0364 #define NODEID_LEN  35  /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
0365 
0366 /* Copy EBCIDC text, convert to ASCII and optionally add delimiter. */
0367 static char *store_ebcdic(char *dest, const char *src, unsigned long len,
0368               char delim)
0369 {
0370     memcpy(dest, src, len);
0371     EBCASC(dest, len);
0372 
0373     if (delim)
0374         dest[len++] = delim;
0375 
0376     return dest + len;
0377 }
0378 
0379 static void chsc_link_from_sei(struct chp_link *link,
0380                 struct chsc_sei_nt0_area *sei_area)
0381 {
0382     if ((sei_area->vf & SEI_VF_FLA) != 0) {
0383         link->fla   = sei_area->fla;
0384         link->fla_mask  = ((sei_area->vf & SEI_VF_FLA) == SEI_VF_FLA) ?
0385                             0xffff : 0xff00;
0386     }
0387 }
0388 
0389 /* Format node ID and parameters for output in LIR log message. */
0390 static void format_node_data(char *params, char *id, struct node_descriptor *nd)
0391 {
0392     memset(params, 0, PARAMS_LEN);
0393     memset(id, 0, NODEID_LEN);
0394 
0395     if (nd->validity != ND_VALIDITY_VALID) {
0396         strncpy(params, "n/a", PARAMS_LEN - 1);
0397         strncpy(id, "n/a", NODEID_LEN - 1);
0398         return;
0399     }
0400 
0401     /* PARAMS=xx,xxxxxx */
0402     snprintf(params, PARAMS_LEN, "%02x,%06x", nd->byte0, nd->params);
0403     /* NODEID=tttttt/mdl,mmm.ppssssssssssss,xxxx */
0404     id = store_ebcdic(id, nd->type, sizeof(nd->type), '/');
0405     id = store_ebcdic(id, nd->model, sizeof(nd->model), ',');
0406     id = store_ebcdic(id, nd->manufacturer, sizeof(nd->manufacturer), '.');
0407     id = store_ebcdic(id, nd->plant, sizeof(nd->plant), 0);
0408     id = store_ebcdic(id, nd->seq, sizeof(nd->seq), ',');
0409     sprintf(id, "%04X", nd->tag);
0410 }
0411 
0412 static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
0413 {
0414     struct lir *lir = (struct lir *) &sei_area->ccdf;
0415     char iuparams[PARAMS_LEN], iunodeid[NODEID_LEN], auparams[PARAMS_LEN],
0416          aunodeid[NODEID_LEN];
0417 
0418     CIO_CRW_EVENT(4, "chsc: link incident (rs=%02x, rs_id=%04x, iq=%02x)\n",
0419               sei_area->rs, sei_area->rsid, sei_area->ccdf[0]);
0420 
0421     /* Ignore NULL Link Incident Records. */
0422     if (lir->iq.null)
0423         return;
0424 
0425     /* Inform user that a link requires maintenance actions because it has
0426      * become degraded or not operational. Note that this log message is
0427      * the primary intention behind a Link Incident Record. */
0428 
0429     format_node_data(iuparams, iunodeid, &lir->incident_node);
0430     format_node_data(auparams, aunodeid, &lir->attached_node);
0431 
0432     switch (lir->iq.class) {
0433     case LIR_IQ_CLASS_DEGRADED:
0434         pr_warn("Link degraded: RS=%02x RSID=%04x IC=%02x "
0435             "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
0436             sei_area->rs, sei_area->rsid, lir->ic, iuparams,
0437             iunodeid, auparams, aunodeid);
0438         break;
0439     case LIR_IQ_CLASS_NOT_OPERATIONAL:
0440         pr_err("Link stopped: RS=%02x RSID=%04x IC=%02x "
0441                "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
0442                sei_area->rs, sei_area->rsid, lir->ic, iuparams,
0443                iunodeid, auparams, aunodeid);
0444         break;
0445     default:
0446         break;
0447     }
0448 }
0449 
0450 static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
0451 {
0452     struct channel_path *chp;
0453     struct chp_link link;
0454     struct chp_id chpid;
0455     int status;
0456 
0457     CIO_CRW_EVENT(4, "chsc: resource accessibility event (rs=%02x, "
0458               "rs_id=%04x)\n", sei_area->rs, sei_area->rsid);
0459     if (sei_area->rs != 4)
0460         return;
0461     chp_id_init(&chpid);
0462     chpid.id = sei_area->rsid;
0463     /* allocate a new channel path structure, if needed */
0464     status = chp_get_status(chpid);
0465     if (!status)
0466         return;
0467 
0468     if (status < 0) {
0469         chp_new(chpid);
0470     } else {
0471         chp = chpid_to_chp(chpid);
0472         mutex_lock(&chp->lock);
0473         chp_update_desc(chp);
0474         mutex_unlock(&chp->lock);
0475     }
0476     memset(&link, 0, sizeof(struct chp_link));
0477     link.chpid = chpid;
0478     chsc_link_from_sei(&link, sei_area);
0479     s390_process_res_acc(&link);
0480 }
0481 
0482 static void chsc_process_sei_chp_avail(struct chsc_sei_nt0_area *sei_area)
0483 {
0484     struct channel_path *chp;
0485     struct chp_id chpid;
0486     u8 *data;
0487     int num;
0488 
0489     CIO_CRW_EVENT(4, "chsc: channel path availability information\n");
0490     if (sei_area->rs != 0)
0491         return;
0492     data = sei_area->ccdf;
0493     chp_id_init(&chpid);
0494     for (num = 0; num <= __MAX_CHPID; num++) {
0495         if (!chp_test_bit(data, num))
0496             continue;
0497         chpid.id = num;
0498 
0499         CIO_CRW_EVENT(4, "Update information for channel path "
0500                   "%x.%02x\n", chpid.cssid, chpid.id);
0501         chp = chpid_to_chp(chpid);
0502         if (!chp) {
0503             chp_new(chpid);
0504             continue;
0505         }
0506         mutex_lock(&chp->lock);
0507         chp_update_desc(chp);
0508         mutex_unlock(&chp->lock);
0509     }
0510 }
0511 
0512 struct chp_config_data {
0513     u8 map[32];
0514     u8 op;
0515     u8 pc;
0516 };
0517 
0518 static void chsc_process_sei_chp_config(struct chsc_sei_nt0_area *sei_area)
0519 {
0520     struct chp_config_data *data;
0521     struct chp_id chpid;
0522     int num;
0523     char *events[3] = {"configure", "deconfigure", "cancel deconfigure"};
0524 
0525     CIO_CRW_EVENT(4, "chsc: channel-path-configuration notification\n");
0526     if (sei_area->rs != 0)
0527         return;
0528     data = (struct chp_config_data *) &(sei_area->ccdf);
0529     chp_id_init(&chpid);
0530     for (num = 0; num <= __MAX_CHPID; num++) {
0531         if (!chp_test_bit(data->map, num))
0532             continue;
0533         chpid.id = num;
0534         pr_notice("Processing %s for channel path %x.%02x\n",
0535               events[data->op], chpid.cssid, chpid.id);
0536         switch (data->op) {
0537         case 0:
0538             chp_cfg_schedule(chpid, 1);
0539             break;
0540         case 1:
0541             chp_cfg_schedule(chpid, 0);
0542             break;
0543         case 2:
0544             chp_cfg_cancel_deconfigure(chpid);
0545             break;
0546         }
0547     }
0548 }
0549 
0550 static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
0551 {
0552     int ret;
0553 
0554     CIO_CRW_EVENT(4, "chsc: scm change notification\n");
0555     if (sei_area->rs != 7)
0556         return;
0557 
0558     ret = scm_update_information();
0559     if (ret)
0560         CIO_CRW_EVENT(0, "chsc: updating change notification"
0561                   " failed (rc=%d).\n", ret);
0562 }
0563 
0564 static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
0565 {
0566     int ret;
0567 
0568     CIO_CRW_EVENT(4, "chsc: scm available information\n");
0569     if (sei_area->rs != 7)
0570         return;
0571 
0572     ret = scm_process_availability_information();
0573     if (ret)
0574         CIO_CRW_EVENT(0, "chsc: process availability information"
0575                   " failed (rc=%d).\n", ret);
0576 }
0577 
0578 static void chsc_process_sei_ap_cfg_chg(struct chsc_sei_nt0_area *sei_area)
0579 {
0580     CIO_CRW_EVENT(3, "chsc: ap config changed\n");
0581     if (sei_area->rs != 5)
0582         return;
0583 
0584     ap_bus_cfg_chg();
0585 }
0586 
0587 static void chsc_process_sei_fces_event(struct chsc_sei_nt0_area *sei_area)
0588 {
0589     struct chp_link link;
0590     struct chp_id chpid;
0591     struct channel_path *chp;
0592 
0593     CIO_CRW_EVENT(4,
0594     "chsc: FCES status notification (rs=%02x, rs_id=%04x, FCES-status=%x)\n",
0595         sei_area->rs, sei_area->rsid, sei_area->ccdf[0]);
0596 
0597     if (sei_area->rs != SEI_RS_CHPID)
0598         return;
0599     chp_id_init(&chpid);
0600     chpid.id = sei_area->rsid;
0601 
0602     /* Ignore the event on unknown/invalid chp */
0603     chp = chpid_to_chp(chpid);
0604     if (!chp)
0605         return;
0606 
0607     memset(&link, 0, sizeof(struct chp_link));
0608     link.chpid = chpid;
0609     chsc_link_from_sei(&link, sei_area);
0610 
0611     for_each_subchannel_staged(process_fces_event, NULL, &link);
0612 }
0613 
0614 static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
0615 {
0616     switch (sei_area->cc) {
0617     case 1:
0618         zpci_event_error(sei_area->ccdf);
0619         break;
0620     case 2:
0621         zpci_event_availability(sei_area->ccdf);
0622         break;
0623     default:
0624         CIO_CRW_EVENT(2, "chsc: sei nt2 unhandled cc=%d\n",
0625                   sei_area->cc);
0626         break;
0627     }
0628 }
0629 
0630 static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
0631 {
0632     /* which kind of information was stored? */
0633     switch (sei_area->cc) {
0634     case 1: /* link incident*/
0635         chsc_process_sei_link_incident(sei_area);
0636         break;
0637     case 2: /* i/o resource accessibility */
0638         chsc_process_sei_res_acc(sei_area);
0639         break;
0640     case 3: /* ap config changed */
0641         chsc_process_sei_ap_cfg_chg(sei_area);
0642         break;
0643     case 7: /* channel-path-availability information */
0644         chsc_process_sei_chp_avail(sei_area);
0645         break;
0646     case 8: /* channel-path-configuration notification */
0647         chsc_process_sei_chp_config(sei_area);
0648         break;
0649     case 12: /* scm change notification */
0650         chsc_process_sei_scm_change(sei_area);
0651         break;
0652     case 14: /* scm available notification */
0653         chsc_process_sei_scm_avail(sei_area);
0654         break;
0655     case 15: /* FCES event notification */
0656         chsc_process_sei_fces_event(sei_area);
0657         break;
0658     default: /* other stuff */
0659         CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
0660                   sei_area->cc);
0661         break;
0662     }
0663 
0664     /* Check if we might have lost some information. */
0665     if (sei_area->flags & 0x40) {
0666         CIO_CRW_EVENT(2, "chsc: event overflow\n");
0667         css_schedule_eval_all();
0668     }
0669 }
0670 
0671 static void chsc_process_event_information(struct chsc_sei *sei, u64 ntsm)
0672 {
0673     static int ntsm_unsupported;
0674 
0675     while (true) {
0676         memset(sei, 0, sizeof(*sei));
0677         sei->request.length = 0x0010;
0678         sei->request.code = 0x000e;
0679         if (!ntsm_unsupported)
0680             sei->ntsm = ntsm;
0681 
0682         if (chsc(sei))
0683             break;
0684 
0685         if (sei->response.code != 0x0001) {
0686             CIO_CRW_EVENT(2, "chsc: sei failed (rc=%04x, ntsm=%llx)\n",
0687                       sei->response.code, sei->ntsm);
0688 
0689             if (sei->response.code == 3 && sei->ntsm) {
0690                 /* Fallback for old firmware. */
0691                 ntsm_unsupported = 1;
0692                 continue;
0693             }
0694             break;
0695         }
0696 
0697         CIO_CRW_EVENT(2, "chsc: sei successful (nt=%d)\n", sei->nt);
0698         switch (sei->nt) {
0699         case 0:
0700             chsc_process_sei_nt0(&sei->u.nt0_area);
0701             break;
0702         case 2:
0703             chsc_process_sei_nt2(&sei->u.nt2_area);
0704             break;
0705         default:
0706             CIO_CRW_EVENT(2, "chsc: unhandled nt: %d\n", sei->nt);
0707             break;
0708         }
0709 
0710         if (!(sei->u.nt0_area.flags & 0x80))
0711             break;
0712     }
0713 }
0714 
0715 /*
0716  * Handle channel subsystem related CRWs.
0717  * Use store event information to find out what's going on.
0718  *
0719  * Note: Access to sei_page is serialized through machine check handler
0720  * thread, so no need for locking.
0721  */
0722 static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
0723 {
0724     struct chsc_sei *sei = sei_page;
0725 
0726     if (overflow) {
0727         css_schedule_eval_all();
0728         return;
0729     }
0730     CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
0731               "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
0732               crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
0733               crw0->erc, crw0->rsid);
0734 
0735     CIO_TRACE_EVENT(2, "prcss");
0736     chsc_process_event_information(sei, CHSC_SEI_NT0 | CHSC_SEI_NT2);
0737 }
0738 
0739 void chsc_chp_online(struct chp_id chpid)
0740 {
0741     struct channel_path *chp = chpid_to_chp(chpid);
0742     struct chp_link link;
0743     char dbf_txt[15];
0744 
0745     sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
0746     CIO_TRACE_EVENT(2, dbf_txt);
0747 
0748     if (chp_get_status(chpid) != 0) {
0749         memset(&link, 0, sizeof(struct chp_link));
0750         link.chpid = chpid;
0751         /* Wait until previous actions have settled. */
0752         css_wait_for_slow_path();
0753 
0754         mutex_lock(&chp->lock);
0755         chp_update_desc(chp);
0756         mutex_unlock(&chp->lock);
0757 
0758         for_each_subchannel_staged(__s390_process_res_acc, NULL,
0759                        &link);
0760         css_schedule_reprobe();
0761     }
0762 }
0763 
0764 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
0765                      struct chp_id chpid, int on)
0766 {
0767     unsigned long flags;
0768     struct chp_link link;
0769 
0770     memset(&link, 0, sizeof(struct chp_link));
0771     link.chpid = chpid;
0772     spin_lock_irqsave(sch->lock, flags);
0773     if (sch->driver && sch->driver->chp_event)
0774         sch->driver->chp_event(sch, &link,
0775                        on ? CHP_VARY_ON : CHP_VARY_OFF);
0776     spin_unlock_irqrestore(sch->lock, flags);
0777 }
0778 
0779 static int s390_subchannel_vary_chpid_off(struct subchannel *sch, void *data)
0780 {
0781     struct chp_id *chpid = data;
0782 
0783     __s390_subchannel_vary_chpid(sch, *chpid, 0);
0784     return 0;
0785 }
0786 
0787 static int s390_subchannel_vary_chpid_on(struct subchannel *sch, void *data)
0788 {
0789     struct chp_id *chpid = data;
0790 
0791     __s390_subchannel_vary_chpid(sch, *chpid, 1);
0792     return 0;
0793 }
0794 
0795 /**
0796  * chsc_chp_vary - propagate channel-path vary operation to subchannels
0797  * @chpid: channl-path ID
0798  * @on: non-zero for vary online, zero for vary offline
0799  */
0800 int chsc_chp_vary(struct chp_id chpid, int on)
0801 {
0802     struct channel_path *chp = chpid_to_chp(chpid);
0803 
0804     /*
0805      * Redo PathVerification on the devices the chpid connects to
0806      */
0807     if (on) {
0808         /* Try to update the channel path description. */
0809         chp_update_desc(chp);
0810         for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
0811                        NULL, &chpid);
0812         css_schedule_reprobe();
0813     } else
0814         for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
0815                        NULL, &chpid);
0816 
0817     return 0;
0818 }
0819 
0820 static void
0821 chsc_remove_cmg_attr(struct channel_subsystem *css)
0822 {
0823     int i;
0824 
0825     for (i = 0; i <= __MAX_CHPID; i++) {
0826         if (!css->chps[i])
0827             continue;
0828         chp_remove_cmg_attr(css->chps[i]);
0829     }
0830 }
0831 
0832 static int
0833 chsc_add_cmg_attr(struct channel_subsystem *css)
0834 {
0835     int i, ret;
0836 
0837     ret = 0;
0838     for (i = 0; i <= __MAX_CHPID; i++) {
0839         if (!css->chps[i])
0840             continue;
0841         ret = chp_add_cmg_attr(css->chps[i]);
0842         if (ret)
0843             goto cleanup;
0844     }
0845     return ret;
0846 cleanup:
0847     for (--i; i >= 0; i--) {
0848         if (!css->chps[i])
0849             continue;
0850         chp_remove_cmg_attr(css->chps[i]);
0851     }
0852     return ret;
0853 }
0854 
0855 int __chsc_do_secm(struct channel_subsystem *css, int enable)
0856 {
0857     struct {
0858         struct chsc_header request;
0859         u32 operation_code : 2;
0860         u32 : 30;
0861         u32 key : 4;
0862         u32 : 28;
0863         u32 zeroes1;
0864         u32 cub_addr1;
0865         u32 zeroes2;
0866         u32 cub_addr2;
0867         u32 reserved[13];
0868         struct chsc_header response;
0869         u32 status : 8;
0870         u32 : 4;
0871         u32 fmt : 4;
0872         u32 : 16;
0873     } *secm_area;
0874     unsigned long flags;
0875     int ret, ccode;
0876 
0877     spin_lock_irqsave(&chsc_page_lock, flags);
0878     memset(chsc_page, 0, PAGE_SIZE);
0879     secm_area = chsc_page;
0880     secm_area->request.length = 0x0050;
0881     secm_area->request.code = 0x0016;
0882 
0883     secm_area->key = PAGE_DEFAULT_KEY >> 4;
0884     secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
0885     secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
0886 
0887     secm_area->operation_code = enable ? 0 : 1;
0888 
0889     ccode = chsc(secm_area);
0890     if (ccode > 0) {
0891         ret = (ccode == 3) ? -ENODEV : -EBUSY;
0892         goto out;
0893     }
0894 
0895     switch (secm_area->response.code) {
0896     case 0x0102:
0897     case 0x0103:
0898         ret = -EINVAL;
0899         break;
0900     default:
0901         ret = chsc_error_from_response(secm_area->response.code);
0902     }
0903     if (ret != 0)
0904         CIO_CRW_EVENT(2, "chsc: secm failed (rc=%04x)\n",
0905                   secm_area->response.code);
0906 out:
0907     spin_unlock_irqrestore(&chsc_page_lock, flags);
0908     return ret;
0909 }
0910 
0911 int
0912 chsc_secm(struct channel_subsystem *css, int enable)
0913 {
0914     int ret;
0915 
0916     if (enable && !css->cm_enabled) {
0917         css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
0918         css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
0919         if (!css->cub_addr1 || !css->cub_addr2) {
0920             free_page((unsigned long)css->cub_addr1);
0921             free_page((unsigned long)css->cub_addr2);
0922             return -ENOMEM;
0923         }
0924     }
0925     ret = __chsc_do_secm(css, enable);
0926     if (!ret) {
0927         css->cm_enabled = enable;
0928         if (css->cm_enabled) {
0929             ret = chsc_add_cmg_attr(css);
0930             if (ret) {
0931                 __chsc_do_secm(css, 0);
0932                 css->cm_enabled = 0;
0933             }
0934         } else
0935             chsc_remove_cmg_attr(css);
0936     }
0937     if (!css->cm_enabled) {
0938         free_page((unsigned long)css->cub_addr1);
0939         free_page((unsigned long)css->cub_addr2);
0940     }
0941     return ret;
0942 }
0943 
0944 int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
0945                      int c, int m, void *page)
0946 {
0947     struct chsc_scpd *scpd_area;
0948     int ccode, ret;
0949 
0950     if ((rfmt == 1 || rfmt == 0) && c == 1 &&
0951         !css_general_characteristics.fcs)
0952         return -EINVAL;
0953     if ((rfmt == 2) && !css_general_characteristics.cib)
0954         return -EINVAL;
0955     if ((rfmt == 3) && !css_general_characteristics.util_str)
0956         return -EINVAL;
0957 
0958     memset(page, 0, PAGE_SIZE);
0959     scpd_area = page;
0960     scpd_area->request.length = 0x0010;
0961     scpd_area->request.code = 0x0002;
0962     scpd_area->cssid = chpid.cssid;
0963     scpd_area->first_chpid = chpid.id;
0964     scpd_area->last_chpid = chpid.id;
0965     scpd_area->m = m;
0966     scpd_area->c = c;
0967     scpd_area->fmt = fmt;
0968     scpd_area->rfmt = rfmt;
0969 
0970     ccode = chsc(scpd_area);
0971     if (ccode > 0)
0972         return (ccode == 3) ? -ENODEV : -EBUSY;
0973 
0974     ret = chsc_error_from_response(scpd_area->response.code);
0975     if (ret)
0976         CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
0977                   scpd_area->response.code);
0978     return ret;
0979 }
0980 EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
0981 
0982 #define chsc_det_chp_desc(FMT, c)                   \
0983 int chsc_determine_fmt##FMT##_channel_path_desc(            \
0984     struct chp_id chpid, struct channel_path_desc_fmt##FMT *desc)   \
0985 {                                   \
0986     struct chsc_scpd *scpd_area;                    \
0987     unsigned long flags;                        \
0988     int ret;                            \
0989                                     \
0990     spin_lock_irqsave(&chsc_page_lock, flags);          \
0991     scpd_area = chsc_page;                      \
0992     ret = chsc_determine_channel_path_desc(chpid, 0, FMT, c, 0, \
0993                            scpd_area);      \
0994     if (ret)                            \
0995         goto out;                       \
0996                                     \
0997     memcpy(desc, scpd_area->data, sizeof(*desc));           \
0998 out:                                    \
0999     spin_unlock_irqrestore(&chsc_page_lock, flags);         \
1000     return ret;                         \
1001 }
1002 
1003 chsc_det_chp_desc(0, 0)
1004 chsc_det_chp_desc(1, 1)
1005 chsc_det_chp_desc(3, 0)
1006 
1007 static void
1008 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
1009               struct cmg_chars *chars)
1010 {
1011     int i, mask;
1012 
1013     for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
1014         mask = 0x80 >> (i + 3);
1015         if (cmcv & mask)
1016             chp->cmg_chars.values[i] = chars->values[i];
1017         else
1018             chp->cmg_chars.values[i] = 0;
1019     }
1020 }
1021 
1022 int chsc_get_channel_measurement_chars(struct channel_path *chp)
1023 {
1024     unsigned long flags;
1025     int ccode, ret;
1026 
1027     struct {
1028         struct chsc_header request;
1029         u32 : 24;
1030         u32 first_chpid : 8;
1031         u32 : 24;
1032         u32 last_chpid : 8;
1033         u32 zeroes1;
1034         struct chsc_header response;
1035         u32 zeroes2;
1036         u32 not_valid : 1;
1037         u32 shared : 1;
1038         u32 : 22;
1039         u32 chpid : 8;
1040         u32 cmcv : 5;
1041         u32 : 11;
1042         u32 cmgq : 8;
1043         u32 cmg : 8;
1044         u32 zeroes3;
1045         u32 data[NR_MEASUREMENT_CHARS];
1046     } *scmc_area;
1047 
1048     chp->shared = -1;
1049     chp->cmg = -1;
1050 
1051     if (!css_chsc_characteristics.scmc || !css_chsc_characteristics.secm)
1052         return -EINVAL;
1053 
1054     spin_lock_irqsave(&chsc_page_lock, flags);
1055     memset(chsc_page, 0, PAGE_SIZE);
1056     scmc_area = chsc_page;
1057     scmc_area->request.length = 0x0010;
1058     scmc_area->request.code = 0x0022;
1059     scmc_area->first_chpid = chp->chpid.id;
1060     scmc_area->last_chpid = chp->chpid.id;
1061 
1062     ccode = chsc(scmc_area);
1063     if (ccode > 0) {
1064         ret = (ccode == 3) ? -ENODEV : -EBUSY;
1065         goto out;
1066     }
1067 
1068     ret = chsc_error_from_response(scmc_area->response.code);
1069     if (ret) {
1070         CIO_CRW_EVENT(2, "chsc: scmc failed (rc=%04x)\n",
1071                   scmc_area->response.code);
1072         goto out;
1073     }
1074     if (scmc_area->not_valid)
1075         goto out;
1076 
1077     chp->cmg = scmc_area->cmg;
1078     chp->shared = scmc_area->shared;
1079     if (chp->cmg != 2 && chp->cmg != 3) {
1080         /* No cmg-dependent data. */
1081         goto out;
1082     }
1083     chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1084                   (struct cmg_chars *) &scmc_area->data);
1085 out:
1086     spin_unlock_irqrestore(&chsc_page_lock, flags);
1087     return ret;
1088 }
1089 
1090 int __init chsc_init(void)
1091 {
1092     int ret;
1093 
1094     sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1095     chsc_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1096     if (!sei_page || !chsc_page) {
1097         ret = -ENOMEM;
1098         goto out_err;
1099     }
1100     ret = crw_register_handler(CRW_RSC_CSS, chsc_process_crw);
1101     if (ret)
1102         goto out_err;
1103     return ret;
1104 out_err:
1105     free_page((unsigned long)chsc_page);
1106     free_page((unsigned long)sei_page);
1107     return ret;
1108 }
1109 
1110 void __init chsc_init_cleanup(void)
1111 {
1112     crw_unregister_handler(CRW_RSC_CSS);
1113     free_page((unsigned long)chsc_page);
1114     free_page((unsigned long)sei_page);
1115 }
1116 
1117 int __chsc_enable_facility(struct chsc_sda_area *sda_area, int operation_code)
1118 {
1119     int ret;
1120 
1121     sda_area->request.length = 0x0400;
1122     sda_area->request.code = 0x0031;
1123     sda_area->operation_code = operation_code;
1124 
1125     ret = chsc(sda_area);
1126     if (ret > 0) {
1127         ret = (ret == 3) ? -ENODEV : -EBUSY;
1128         goto out;
1129     }
1130 
1131     switch (sda_area->response.code) {
1132     case 0x0101:
1133         ret = -EOPNOTSUPP;
1134         break;
1135     default:
1136         ret = chsc_error_from_response(sda_area->response.code);
1137     }
1138 out:
1139     return ret;
1140 }
1141 
1142 int chsc_enable_facility(int operation_code)
1143 {
1144     struct chsc_sda_area *sda_area;
1145     unsigned long flags;
1146     int ret;
1147 
1148     spin_lock_irqsave(&chsc_page_lock, flags);
1149     memset(chsc_page, 0, PAGE_SIZE);
1150     sda_area = chsc_page;
1151 
1152     ret = __chsc_enable_facility(sda_area, operation_code);
1153     if (ret != 0)
1154         CIO_CRW_EVENT(2, "chsc: sda (oc=%x) failed (rc=%04x)\n",
1155                   operation_code, sda_area->response.code);
1156 
1157     spin_unlock_irqrestore(&chsc_page_lock, flags);
1158     return ret;
1159 }
1160 
1161 int __init chsc_get_cssid_iid(int idx, u8 *cssid, u8 *iid)
1162 {
1163     struct {
1164         struct chsc_header request;
1165         u8 atype;
1166         u32 : 24;
1167         u32 reserved1[6];
1168         struct chsc_header response;
1169         u32 reserved2[3];
1170         struct {
1171             u8 cssid;
1172             u8 iid;
1173             u32 : 16;
1174         } list[0];
1175     } *sdcal_area;
1176     int ret;
1177 
1178     spin_lock_irq(&chsc_page_lock);
1179     memset(chsc_page, 0, PAGE_SIZE);
1180     sdcal_area = chsc_page;
1181     sdcal_area->request.length = 0x0020;
1182     sdcal_area->request.code = 0x0034;
1183     sdcal_area->atype = 4;
1184 
1185     ret = chsc(sdcal_area);
1186     if (ret) {
1187         ret = (ret == 3) ? -ENODEV : -EBUSY;
1188         goto exit;
1189     }
1190 
1191     ret = chsc_error_from_response(sdcal_area->response.code);
1192     if (ret) {
1193         CIO_CRW_EVENT(2, "chsc: sdcal failed (rc=%04x)\n",
1194                   sdcal_area->response.code);
1195         goto exit;
1196     }
1197 
1198     if ((addr_t) &sdcal_area->list[idx] <
1199         (addr_t) &sdcal_area->response + sdcal_area->response.length) {
1200         *cssid = sdcal_area->list[idx].cssid;
1201         *iid = sdcal_area->list[idx].iid;
1202     }
1203     else
1204         ret = -ENODEV;
1205 exit:
1206     spin_unlock_irq(&chsc_page_lock);
1207     return ret;
1208 }
1209 
1210 struct css_general_char css_general_characteristics;
1211 struct css_chsc_char css_chsc_characteristics;
1212 
1213 int __init
1214 chsc_determine_css_characteristics(void)
1215 {
1216     unsigned long flags;
1217     int result;
1218     struct {
1219         struct chsc_header request;
1220         u32 reserved1;
1221         u32 reserved2;
1222         u32 reserved3;
1223         struct chsc_header response;
1224         u32 reserved4;
1225         u32 general_char[510];
1226         u32 chsc_char[508];
1227     } *scsc_area;
1228 
1229     spin_lock_irqsave(&chsc_page_lock, flags);
1230     memset(chsc_page, 0, PAGE_SIZE);
1231     scsc_area = chsc_page;
1232     scsc_area->request.length = 0x0010;
1233     scsc_area->request.code = 0x0010;
1234 
1235     result = chsc(scsc_area);
1236     if (result) {
1237         result = (result == 3) ? -ENODEV : -EBUSY;
1238         goto exit;
1239     }
1240 
1241     result = chsc_error_from_response(scsc_area->response.code);
1242     if (result == 0) {
1243         memcpy(&css_general_characteristics, scsc_area->general_char,
1244                sizeof(css_general_characteristics));
1245         memcpy(&css_chsc_characteristics, scsc_area->chsc_char,
1246                sizeof(css_chsc_characteristics));
1247     } else
1248         CIO_CRW_EVENT(2, "chsc: scsc failed (rc=%04x)\n",
1249                   scsc_area->response.code);
1250 exit:
1251     spin_unlock_irqrestore(&chsc_page_lock, flags);
1252     return result;
1253 }
1254 
1255 EXPORT_SYMBOL_GPL(css_general_characteristics);
1256 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
1257 
1258 int chsc_sstpc(void *page, unsigned int op, u16 ctrl, long *clock_delta)
1259 {
1260     struct {
1261         struct chsc_header request;
1262         unsigned int rsvd0;
1263         unsigned int op : 8;
1264         unsigned int rsvd1 : 8;
1265         unsigned int ctrl : 16;
1266         unsigned int rsvd2[5];
1267         struct chsc_header response;
1268         unsigned int rsvd3[3];
1269         s64 clock_delta;
1270         unsigned int rsvd4[2];
1271     } *rr;
1272     int rc;
1273 
1274     memset(page, 0, PAGE_SIZE);
1275     rr = page;
1276     rr->request.length = 0x0020;
1277     rr->request.code = 0x0033;
1278     rr->op = op;
1279     rr->ctrl = ctrl;
1280     rc = chsc(rr);
1281     if (rc)
1282         return -EIO;
1283     rc = (rr->response.code == 0x0001) ? 0 : -EIO;
1284     if (clock_delta)
1285         *clock_delta = rr->clock_delta;
1286     return rc;
1287 }
1288 
1289 int chsc_sstpi(void *page, void *result, size_t size)
1290 {
1291     struct {
1292         struct chsc_header request;
1293         unsigned int rsvd0[3];
1294         struct chsc_header response;
1295         char data[];
1296     } *rr;
1297     int rc;
1298 
1299     memset(page, 0, PAGE_SIZE);
1300     rr = page;
1301     rr->request.length = 0x0010;
1302     rr->request.code = 0x0038;
1303     rc = chsc(rr);
1304     if (rc)
1305         return -EIO;
1306     memcpy(result, &rr->data, size);
1307     return (rr->response.code == 0x0001) ? 0 : -EIO;
1308 }
1309 
1310 int chsc_stzi(void *page, void *result, size_t size)
1311 {
1312     struct {
1313         struct chsc_header request;
1314         unsigned int rsvd0[3];
1315         struct chsc_header response;
1316         char data[];
1317     } *rr;
1318     int rc;
1319 
1320     memset(page, 0, PAGE_SIZE);
1321     rr = page;
1322     rr->request.length = 0x0010;
1323     rr->request.code = 0x003e;
1324     rc = chsc(rr);
1325     if (rc)
1326         return -EIO;
1327     memcpy(result, &rr->data, size);
1328     return (rr->response.code == 0x0001) ? 0 : -EIO;
1329 }
1330 
1331 int chsc_siosl(struct subchannel_id schid)
1332 {
1333     struct {
1334         struct chsc_header request;
1335         u32 word1;
1336         struct subchannel_id sid;
1337         u32 word3;
1338         struct chsc_header response;
1339         u32 word[11];
1340     } *siosl_area;
1341     unsigned long flags;
1342     int ccode;
1343     int rc;
1344 
1345     spin_lock_irqsave(&chsc_page_lock, flags);
1346     memset(chsc_page, 0, PAGE_SIZE);
1347     siosl_area = chsc_page;
1348     siosl_area->request.length = 0x0010;
1349     siosl_area->request.code = 0x0046;
1350     siosl_area->word1 = 0x80000000;
1351     siosl_area->sid = schid;
1352 
1353     ccode = chsc(siosl_area);
1354     if (ccode > 0) {
1355         if (ccode == 3)
1356             rc = -ENODEV;
1357         else
1358             rc = -EBUSY;
1359         CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1360                   schid.ssid, schid.sch_no, ccode);
1361         goto out;
1362     }
1363     rc = chsc_error_from_response(siosl_area->response.code);
1364     if (rc)
1365         CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1366                   schid.ssid, schid.sch_no,
1367                   siosl_area->response.code);
1368     else
1369         CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1370                   schid.ssid, schid.sch_no);
1371 out:
1372     spin_unlock_irqrestore(&chsc_page_lock, flags);
1373     return rc;
1374 }
1375 EXPORT_SYMBOL_GPL(chsc_siosl);
1376 
1377 /**
1378  * chsc_scm_info() - store SCM information (SSI)
1379  * @scm_area: request and response block for SSI
1380  * @token: continuation token
1381  *
1382  * Returns 0 on success.
1383  */
1384 int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token)
1385 {
1386     int ccode, ret;
1387 
1388     memset(scm_area, 0, sizeof(*scm_area));
1389     scm_area->request.length = 0x0020;
1390     scm_area->request.code = 0x004C;
1391     scm_area->reqtok = token;
1392 
1393     ccode = chsc(scm_area);
1394     if (ccode > 0) {
1395         ret = (ccode == 3) ? -ENODEV : -EBUSY;
1396         goto out;
1397     }
1398     ret = chsc_error_from_response(scm_area->response.code);
1399     if (ret != 0)
1400         CIO_MSG_EVENT(2, "chsc: scm info failed (rc=%04x)\n",
1401                   scm_area->response.code);
1402 out:
1403     return ret;
1404 }
1405 EXPORT_SYMBOL_GPL(chsc_scm_info);
1406 
1407 /**
1408  * chsc_pnso() - Perform Network-Subchannel Operation
1409  * @schid:      id of the subchannel on which PNSO is performed
1410  * @pnso_area:      request and response block for the operation
1411  * @oc:         Operation Code
1412  * @resume_token:   resume token for multiblock response
1413  * @cnc:        Boolean change-notification control
1414  *
1415  * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL)
1416  *
1417  * Returns 0 on success.
1418  */
1419 int chsc_pnso(struct subchannel_id schid, struct chsc_pnso_area *pnso_area,
1420           u8 oc, struct chsc_pnso_resume_token resume_token, int cnc)
1421 {
1422     memset(pnso_area, 0, sizeof(*pnso_area));
1423     pnso_area->request.length = 0x0030;
1424     pnso_area->request.code = 0x003d; /* network-subchannel operation */
1425     pnso_area->m       = schid.m;
1426     pnso_area->ssid  = schid.ssid;
1427     pnso_area->sch   = schid.sch_no;
1428     pnso_area->cssid = schid.cssid;
1429     pnso_area->oc    = oc;
1430     pnso_area->resume_token = resume_token;
1431     pnso_area->n       = (cnc != 0);
1432     if (chsc(pnso_area))
1433         return -EIO;
1434     return chsc_error_from_response(pnso_area->response.code);
1435 }
1436 
1437 int chsc_sgib(u32 origin)
1438 {
1439     struct {
1440         struct chsc_header request;
1441         u16 op;
1442         u8  reserved01[2];
1443         u8  reserved02:4;
1444         u8  fmt:4;
1445         u8  reserved03[7];
1446         /* operation data area begin */
1447         u8  reserved04[4];
1448         u32 gib_origin;
1449         u8  reserved05[10];
1450         u8  aix;
1451         u8  reserved06[4029];
1452         struct chsc_header response;
1453         u8  reserved07[4];
1454     } *sgib_area;
1455     int ret;
1456 
1457     spin_lock_irq(&chsc_page_lock);
1458     memset(chsc_page, 0, PAGE_SIZE);
1459     sgib_area = chsc_page;
1460     sgib_area->request.length = 0x0fe0;
1461     sgib_area->request.code = 0x0021;
1462     sgib_area->op = 0x1;
1463     sgib_area->gib_origin = origin;
1464 
1465     ret = chsc(sgib_area);
1466     if (ret == 0)
1467         ret = chsc_error_from_response(sgib_area->response.code);
1468     spin_unlock_irq(&chsc_page_lock);
1469 
1470     return ret;
1471 }
1472 EXPORT_SYMBOL_GPL(chsc_sgib);
1473 
1474 #define SCUD_REQ_LEN    0x10 /* SCUD request block length */
1475 #define SCUD_REQ_CMD    0x4b /* SCUD Command Code */
1476 
1477 struct chse_cudb {
1478     u16 flags:8;
1479     u16 chp_valid:8;
1480     u16 cu;
1481     u32 esm_valid:8;
1482     u32:24;
1483     u8 chpid[8];
1484     u32:32;
1485     u32:32;
1486     u8 esm[8];
1487     u32 efla[8];
1488 } __packed;
1489 
1490 struct chsc_scud {
1491     struct chsc_header request;
1492     u16:4;
1493     u16 fmt:4;
1494     u16 cssid:8;
1495     u16 first_cu;
1496     u16:16;
1497     u16 last_cu;
1498     u32:32;
1499     struct chsc_header response;
1500     u16:4;
1501     u16 fmt_resp:4;
1502     u32:24;
1503     struct chse_cudb cudb[];
1504 } __packed;
1505 
1506 /**
1507  * chsc_scud() - Store control-unit description.
1508  * @cu:     number of the control-unit
1509  * @esm:    8 1-byte endpoint security mode values
1510  * @esm_valid:  validity mask for @esm
1511  *
1512  * Interface to retrieve information about the endpoint security
1513  * modes for up to 8 paths of a control unit.
1514  *
1515  * Returns 0 on success.
1516  */
1517 int chsc_scud(u16 cu, u64 *esm, u8 *esm_valid)
1518 {
1519     struct chsc_scud *scud = chsc_page;
1520     int ret;
1521 
1522     spin_lock_irq(&chsc_page_lock);
1523     memset(chsc_page, 0, PAGE_SIZE);
1524     scud->request.length = SCUD_REQ_LEN;
1525     scud->request.code = SCUD_REQ_CMD;
1526     scud->fmt = 0;
1527     scud->cssid = 0;
1528     scud->first_cu = cu;
1529     scud->last_cu = cu;
1530 
1531     ret = chsc(scud);
1532     if (!ret)
1533         ret = chsc_error_from_response(scud->response.code);
1534 
1535     if (!ret && (scud->response.length <= 8 || scud->fmt_resp != 0
1536             || !(scud->cudb[0].flags & 0x80)
1537             || scud->cudb[0].cu != cu)) {
1538 
1539         CIO_MSG_EVENT(2, "chsc: scud failed rc=%04x, L2=%04x "
1540             "FMT=%04x, cudb.flags=%02x, cudb.cu=%04x",
1541             scud->response.code, scud->response.length,
1542             scud->fmt_resp, scud->cudb[0].flags, scud->cudb[0].cu);
1543         ret = -EINVAL;
1544     }
1545 
1546     if (ret)
1547         goto out;
1548 
1549     memcpy(esm, scud->cudb[0].esm, sizeof(*esm));
1550     *esm_valid = scud->cudb[0].esm_valid;
1551 out:
1552     spin_unlock_irq(&chsc_page_lock);
1553     return ret;
1554 }
1555 EXPORT_SYMBOL_GPL(chsc_scud);