18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-1.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2002, 2009 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 68c2ecf20Sopenharmony_ci * Cornelia Huck (cornelia.huck@de.ibm.com) 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#include <linux/export.h> 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/errno.h> 118c2ecf20Sopenharmony_ci#include <linux/slab.h> 128c2ecf20Sopenharmony_ci#include <linux/list.h> 138c2ecf20Sopenharmony_ci#include <linux/device.h> 148c2ecf20Sopenharmony_ci#include <linux/delay.h> 158c2ecf20Sopenharmony_ci#include <linux/completion.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <asm/ccwdev.h> 188c2ecf20Sopenharmony_ci#include <asm/idals.h> 198c2ecf20Sopenharmony_ci#include <asm/chpid.h> 208c2ecf20Sopenharmony_ci#include <asm/fcx.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include "cio.h" 238c2ecf20Sopenharmony_ci#include "cio_debug.h" 248c2ecf20Sopenharmony_ci#include "css.h" 258c2ecf20Sopenharmony_ci#include "chsc.h" 268c2ecf20Sopenharmony_ci#include "device.h" 278c2ecf20Sopenharmony_ci#include "chp.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/** 308c2ecf20Sopenharmony_ci * ccw_device_set_options_mask() - set some options and unset the rest 318c2ecf20Sopenharmony_ci * @cdev: device for which the options are to be set 328c2ecf20Sopenharmony_ci * @flags: options to be set 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * All flags specified in @flags are set, all flags not specified in @flags 358c2ecf20Sopenharmony_ci * are cleared. 368c2ecf20Sopenharmony_ci * Returns: 378c2ecf20Sopenharmony_ci * %0 on success, -%EINVAL on an invalid flag combination. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ciint ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci /* 428c2ecf20Sopenharmony_ci * The flag usage is mutal exclusive ... 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ci if ((flags & CCWDEV_EARLY_NOTIFICATION) && 458c2ecf20Sopenharmony_ci (flags & CCWDEV_REPORT_ALL)) 468c2ecf20Sopenharmony_ci return -EINVAL; 478c2ecf20Sopenharmony_ci cdev->private->options.fast = (flags & CCWDEV_EARLY_NOTIFICATION) != 0; 488c2ecf20Sopenharmony_ci cdev->private->options.repall = (flags & CCWDEV_REPORT_ALL) != 0; 498c2ecf20Sopenharmony_ci cdev->private->options.pgroup = (flags & CCWDEV_DO_PATHGROUP) != 0; 508c2ecf20Sopenharmony_ci cdev->private->options.force = (flags & CCWDEV_ALLOW_FORCE) != 0; 518c2ecf20Sopenharmony_ci cdev->private->options.mpath = (flags & CCWDEV_DO_MULTIPATH) != 0; 528c2ecf20Sopenharmony_ci return 0; 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/** 568c2ecf20Sopenharmony_ci * ccw_device_set_options() - set some options 578c2ecf20Sopenharmony_ci * @cdev: device for which the options are to be set 588c2ecf20Sopenharmony_ci * @flags: options to be set 598c2ecf20Sopenharmony_ci * 608c2ecf20Sopenharmony_ci * All flags specified in @flags are set, the remainder is left untouched. 618c2ecf20Sopenharmony_ci * Returns: 628c2ecf20Sopenharmony_ci * %0 on success, -%EINVAL if an invalid flag combination would ensue. 638c2ecf20Sopenharmony_ci */ 648c2ecf20Sopenharmony_ciint ccw_device_set_options(struct ccw_device *cdev, unsigned long flags) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci /* 678c2ecf20Sopenharmony_ci * The flag usage is mutal exclusive ... 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_ci if (((flags & CCWDEV_EARLY_NOTIFICATION) && 708c2ecf20Sopenharmony_ci (flags & CCWDEV_REPORT_ALL)) || 718c2ecf20Sopenharmony_ci ((flags & CCWDEV_EARLY_NOTIFICATION) && 728c2ecf20Sopenharmony_ci cdev->private->options.repall) || 738c2ecf20Sopenharmony_ci ((flags & CCWDEV_REPORT_ALL) && 748c2ecf20Sopenharmony_ci cdev->private->options.fast)) 758c2ecf20Sopenharmony_ci return -EINVAL; 768c2ecf20Sopenharmony_ci cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0; 778c2ecf20Sopenharmony_ci cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0; 788c2ecf20Sopenharmony_ci cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0; 798c2ecf20Sopenharmony_ci cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0; 808c2ecf20Sopenharmony_ci cdev->private->options.mpath |= (flags & CCWDEV_DO_MULTIPATH) != 0; 818c2ecf20Sopenharmony_ci return 0; 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/** 858c2ecf20Sopenharmony_ci * ccw_device_clear_options() - clear some options 868c2ecf20Sopenharmony_ci * @cdev: device for which the options are to be cleared 878c2ecf20Sopenharmony_ci * @flags: options to be cleared 888c2ecf20Sopenharmony_ci * 898c2ecf20Sopenharmony_ci * All flags specified in @flags are cleared, the remainder is left untouched. 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_civoid ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0; 948c2ecf20Sopenharmony_ci cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0; 958c2ecf20Sopenharmony_ci cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0; 968c2ecf20Sopenharmony_ci cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0; 978c2ecf20Sopenharmony_ci cdev->private->options.mpath &= (flags & CCWDEV_DO_MULTIPATH) == 0; 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/** 1018c2ecf20Sopenharmony_ci * ccw_device_is_pathgroup() - determine if paths to this device are grouped 1028c2ecf20Sopenharmony_ci * @cdev: ccw device 1038c2ecf20Sopenharmony_ci * 1048c2ecf20Sopenharmony_ci * Return non-zero if there is a path group, zero otherwise. 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_ciint ccw_device_is_pathgroup(struct ccw_device *cdev) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci return cdev->private->flags.pgroup; 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_is_pathgroup); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/** 1138c2ecf20Sopenharmony_ci * ccw_device_is_multipath() - determine if device is operating in multipath mode 1148c2ecf20Sopenharmony_ci * @cdev: ccw device 1158c2ecf20Sopenharmony_ci * 1168c2ecf20Sopenharmony_ci * Return non-zero if device is operating in multipath mode, zero otherwise. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ciint ccw_device_is_multipath(struct ccw_device *cdev) 1198c2ecf20Sopenharmony_ci{ 1208c2ecf20Sopenharmony_ci return cdev->private->flags.mpath; 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_is_multipath); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/** 1258c2ecf20Sopenharmony_ci * ccw_device_clear() - terminate I/O request processing 1268c2ecf20Sopenharmony_ci * @cdev: target ccw device 1278c2ecf20Sopenharmony_ci * @intparm: interruption parameter to be returned upon conclusion of csch 1288c2ecf20Sopenharmony_ci * 1298c2ecf20Sopenharmony_ci * ccw_device_clear() calls csch on @cdev's subchannel. 1308c2ecf20Sopenharmony_ci * Returns: 1318c2ecf20Sopenharmony_ci * %0 on success, 1328c2ecf20Sopenharmony_ci * -%ENODEV on device not operational, 1338c2ecf20Sopenharmony_ci * -%EINVAL on invalid device state. 1348c2ecf20Sopenharmony_ci * Context: 1358c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ciint ccw_device_clear(struct ccw_device *cdev, unsigned long intparm) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci struct subchannel *sch; 1408c2ecf20Sopenharmony_ci int ret; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci if (!cdev || !cdev->dev.parent) 1438c2ecf20Sopenharmony_ci return -ENODEV; 1448c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 1458c2ecf20Sopenharmony_ci if (!sch->schib.pmcw.ena) 1468c2ecf20Sopenharmony_ci return -EINVAL; 1478c2ecf20Sopenharmony_ci if (cdev->private->state == DEV_STATE_NOT_OPER) 1488c2ecf20Sopenharmony_ci return -ENODEV; 1498c2ecf20Sopenharmony_ci if (cdev->private->state != DEV_STATE_ONLINE && 1508c2ecf20Sopenharmony_ci cdev->private->state != DEV_STATE_W4SENSE) 1518c2ecf20Sopenharmony_ci return -EINVAL; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci ret = cio_clear(sch); 1548c2ecf20Sopenharmony_ci if (ret == 0) 1558c2ecf20Sopenharmony_ci cdev->private->intparm = intparm; 1568c2ecf20Sopenharmony_ci return ret; 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/** 1608c2ecf20Sopenharmony_ci * ccw_device_start_timeout_key() - start a s390 channel program with timeout and key 1618c2ecf20Sopenharmony_ci * @cdev: target ccw device 1628c2ecf20Sopenharmony_ci * @cpa: logical start address of channel program 1638c2ecf20Sopenharmony_ci * @intparm: user specific interruption parameter; will be presented back to 1648c2ecf20Sopenharmony_ci * @cdev's interrupt handler. Allows a device driver to associate 1658c2ecf20Sopenharmony_ci * the interrupt with a particular I/O request. 1668c2ecf20Sopenharmony_ci * @lpm: defines the channel path to be used for a specific I/O request. A 1678c2ecf20Sopenharmony_ci * value of 0 will make cio use the opm. 1688c2ecf20Sopenharmony_ci * @key: storage key to be used for the I/O 1698c2ecf20Sopenharmony_ci * @flags: additional flags; defines the action to be performed for I/O 1708c2ecf20Sopenharmony_ci * processing. 1718c2ecf20Sopenharmony_ci * @expires: timeout value in jiffies 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * Start a S/390 channel program. When the interrupt arrives, the 1748c2ecf20Sopenharmony_ci * IRQ handler is called, either immediately, delayed (dev-end missing, 1758c2ecf20Sopenharmony_ci * or sense required) or never (no IRQ handler registered). 1768c2ecf20Sopenharmony_ci * This function notifies the device driver if the channel program has not 1778c2ecf20Sopenharmony_ci * completed during the time specified by @expires. If a timeout occurs, the 1788c2ecf20Sopenharmony_ci * channel program is terminated via xsch, hsch or csch, and the device's 1798c2ecf20Sopenharmony_ci * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT). 1808c2ecf20Sopenharmony_ci * The interruption handler will echo back the @intparm specified here, unless 1818c2ecf20Sopenharmony_ci * another interruption parameter is specified by a subsequent invocation of 1828c2ecf20Sopenharmony_ci * ccw_device_halt() or ccw_device_clear(). 1838c2ecf20Sopenharmony_ci * Returns: 1848c2ecf20Sopenharmony_ci * %0, if the operation was successful; 1858c2ecf20Sopenharmony_ci * -%EBUSY, if the device is busy, or status pending; 1868c2ecf20Sopenharmony_ci * -%EACCES, if no path specified in @lpm is operational; 1878c2ecf20Sopenharmony_ci * -%ENODEV, if the device is not operational. 1888c2ecf20Sopenharmony_ci * Context: 1898c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 1908c2ecf20Sopenharmony_ci */ 1918c2ecf20Sopenharmony_ciint ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa, 1928c2ecf20Sopenharmony_ci unsigned long intparm, __u8 lpm, __u8 key, 1938c2ecf20Sopenharmony_ci unsigned long flags, int expires) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci struct subchannel *sch; 1968c2ecf20Sopenharmony_ci int ret; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci if (!cdev || !cdev->dev.parent) 1998c2ecf20Sopenharmony_ci return -ENODEV; 2008c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 2018c2ecf20Sopenharmony_ci if (!sch->schib.pmcw.ena) 2028c2ecf20Sopenharmony_ci return -EINVAL; 2038c2ecf20Sopenharmony_ci if (cdev->private->state == DEV_STATE_NOT_OPER) 2048c2ecf20Sopenharmony_ci return -ENODEV; 2058c2ecf20Sopenharmony_ci if (cdev->private->state == DEV_STATE_VERIFY) { 2068c2ecf20Sopenharmony_ci /* Remember to fake irb when finished. */ 2078c2ecf20Sopenharmony_ci if (!cdev->private->flags.fake_irb) { 2088c2ecf20Sopenharmony_ci cdev->private->flags.fake_irb = FAKE_CMD_IRB; 2098c2ecf20Sopenharmony_ci cdev->private->intparm = intparm; 2108c2ecf20Sopenharmony_ci return 0; 2118c2ecf20Sopenharmony_ci } else 2128c2ecf20Sopenharmony_ci /* There's already a fake I/O around. */ 2138c2ecf20Sopenharmony_ci return -EBUSY; 2148c2ecf20Sopenharmony_ci } 2158c2ecf20Sopenharmony_ci if (cdev->private->state != DEV_STATE_ONLINE || 2168c2ecf20Sopenharmony_ci ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) && 2178c2ecf20Sopenharmony_ci !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) || 2188c2ecf20Sopenharmony_ci cdev->private->flags.doverify) 2198c2ecf20Sopenharmony_ci return -EBUSY; 2208c2ecf20Sopenharmony_ci ret = cio_set_options (sch, flags); 2218c2ecf20Sopenharmony_ci if (ret) 2228c2ecf20Sopenharmony_ci return ret; 2238c2ecf20Sopenharmony_ci /* Adjust requested path mask to exclude unusable paths. */ 2248c2ecf20Sopenharmony_ci if (lpm) { 2258c2ecf20Sopenharmony_ci lpm &= sch->lpm; 2268c2ecf20Sopenharmony_ci if (lpm == 0) 2278c2ecf20Sopenharmony_ci return -EACCES; 2288c2ecf20Sopenharmony_ci } 2298c2ecf20Sopenharmony_ci ret = cio_start_key (sch, cpa, lpm, key); 2308c2ecf20Sopenharmony_ci switch (ret) { 2318c2ecf20Sopenharmony_ci case 0: 2328c2ecf20Sopenharmony_ci cdev->private->intparm = intparm; 2338c2ecf20Sopenharmony_ci if (expires) 2348c2ecf20Sopenharmony_ci ccw_device_set_timeout(cdev, expires); 2358c2ecf20Sopenharmony_ci break; 2368c2ecf20Sopenharmony_ci case -EACCES: 2378c2ecf20Sopenharmony_ci case -ENODEV: 2388c2ecf20Sopenharmony_ci dev_fsm_event(cdev, DEV_EVENT_VERIFY); 2398c2ecf20Sopenharmony_ci break; 2408c2ecf20Sopenharmony_ci } 2418c2ecf20Sopenharmony_ci return ret; 2428c2ecf20Sopenharmony_ci} 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/** 2458c2ecf20Sopenharmony_ci * ccw_device_start_key() - start a s390 channel program with key 2468c2ecf20Sopenharmony_ci * @cdev: target ccw device 2478c2ecf20Sopenharmony_ci * @cpa: logical start address of channel program 2488c2ecf20Sopenharmony_ci * @intparm: user specific interruption parameter; will be presented back to 2498c2ecf20Sopenharmony_ci * @cdev's interrupt handler. Allows a device driver to associate 2508c2ecf20Sopenharmony_ci * the interrupt with a particular I/O request. 2518c2ecf20Sopenharmony_ci * @lpm: defines the channel path to be used for a specific I/O request. A 2528c2ecf20Sopenharmony_ci * value of 0 will make cio use the opm. 2538c2ecf20Sopenharmony_ci * @key: storage key to be used for the I/O 2548c2ecf20Sopenharmony_ci * @flags: additional flags; defines the action to be performed for I/O 2558c2ecf20Sopenharmony_ci * processing. 2568c2ecf20Sopenharmony_ci * 2578c2ecf20Sopenharmony_ci * Start a S/390 channel program. When the interrupt arrives, the 2588c2ecf20Sopenharmony_ci * IRQ handler is called, either immediately, delayed (dev-end missing, 2598c2ecf20Sopenharmony_ci * or sense required) or never (no IRQ handler registered). 2608c2ecf20Sopenharmony_ci * The interruption handler will echo back the @intparm specified here, unless 2618c2ecf20Sopenharmony_ci * another interruption parameter is specified by a subsequent invocation of 2628c2ecf20Sopenharmony_ci * ccw_device_halt() or ccw_device_clear(). 2638c2ecf20Sopenharmony_ci * Returns: 2648c2ecf20Sopenharmony_ci * %0, if the operation was successful; 2658c2ecf20Sopenharmony_ci * -%EBUSY, if the device is busy, or status pending; 2668c2ecf20Sopenharmony_ci * -%EACCES, if no path specified in @lpm is operational; 2678c2ecf20Sopenharmony_ci * -%ENODEV, if the device is not operational. 2688c2ecf20Sopenharmony_ci * Context: 2698c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 2708c2ecf20Sopenharmony_ci */ 2718c2ecf20Sopenharmony_ciint ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa, 2728c2ecf20Sopenharmony_ci unsigned long intparm, __u8 lpm, __u8 key, 2738c2ecf20Sopenharmony_ci unsigned long flags) 2748c2ecf20Sopenharmony_ci{ 2758c2ecf20Sopenharmony_ci return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm, key, 2768c2ecf20Sopenharmony_ci flags, 0); 2778c2ecf20Sopenharmony_ci} 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci/** 2808c2ecf20Sopenharmony_ci * ccw_device_start() - start a s390 channel program 2818c2ecf20Sopenharmony_ci * @cdev: target ccw device 2828c2ecf20Sopenharmony_ci * @cpa: logical start address of channel program 2838c2ecf20Sopenharmony_ci * @intparm: user specific interruption parameter; will be presented back to 2848c2ecf20Sopenharmony_ci * @cdev's interrupt handler. Allows a device driver to associate 2858c2ecf20Sopenharmony_ci * the interrupt with a particular I/O request. 2868c2ecf20Sopenharmony_ci * @lpm: defines the channel path to be used for a specific I/O request. A 2878c2ecf20Sopenharmony_ci * value of 0 will make cio use the opm. 2888c2ecf20Sopenharmony_ci * @flags: additional flags; defines the action to be performed for I/O 2898c2ecf20Sopenharmony_ci * processing. 2908c2ecf20Sopenharmony_ci * 2918c2ecf20Sopenharmony_ci * Start a S/390 channel program. When the interrupt arrives, the 2928c2ecf20Sopenharmony_ci * IRQ handler is called, either immediately, delayed (dev-end missing, 2938c2ecf20Sopenharmony_ci * or sense required) or never (no IRQ handler registered). 2948c2ecf20Sopenharmony_ci * The interruption handler will echo back the @intparm specified here, unless 2958c2ecf20Sopenharmony_ci * another interruption parameter is specified by a subsequent invocation of 2968c2ecf20Sopenharmony_ci * ccw_device_halt() or ccw_device_clear(). 2978c2ecf20Sopenharmony_ci * Returns: 2988c2ecf20Sopenharmony_ci * %0, if the operation was successful; 2998c2ecf20Sopenharmony_ci * -%EBUSY, if the device is busy, or status pending; 3008c2ecf20Sopenharmony_ci * -%EACCES, if no path specified in @lpm is operational; 3018c2ecf20Sopenharmony_ci * -%ENODEV, if the device is not operational. 3028c2ecf20Sopenharmony_ci * Context: 3038c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 3048c2ecf20Sopenharmony_ci */ 3058c2ecf20Sopenharmony_ciint ccw_device_start(struct ccw_device *cdev, struct ccw1 *cpa, 3068c2ecf20Sopenharmony_ci unsigned long intparm, __u8 lpm, unsigned long flags) 3078c2ecf20Sopenharmony_ci{ 3088c2ecf20Sopenharmony_ci return ccw_device_start_key(cdev, cpa, intparm, lpm, 3098c2ecf20Sopenharmony_ci PAGE_DEFAULT_KEY, flags); 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci/** 3138c2ecf20Sopenharmony_ci * ccw_device_start_timeout() - start a s390 channel program with timeout 3148c2ecf20Sopenharmony_ci * @cdev: target ccw device 3158c2ecf20Sopenharmony_ci * @cpa: logical start address of channel program 3168c2ecf20Sopenharmony_ci * @intparm: user specific interruption parameter; will be presented back to 3178c2ecf20Sopenharmony_ci * @cdev's interrupt handler. Allows a device driver to associate 3188c2ecf20Sopenharmony_ci * the interrupt with a particular I/O request. 3198c2ecf20Sopenharmony_ci * @lpm: defines the channel path to be used for a specific I/O request. A 3208c2ecf20Sopenharmony_ci * value of 0 will make cio use the opm. 3218c2ecf20Sopenharmony_ci * @flags: additional flags; defines the action to be performed for I/O 3228c2ecf20Sopenharmony_ci * processing. 3238c2ecf20Sopenharmony_ci * @expires: timeout value in jiffies 3248c2ecf20Sopenharmony_ci * 3258c2ecf20Sopenharmony_ci * Start a S/390 channel program. When the interrupt arrives, the 3268c2ecf20Sopenharmony_ci * IRQ handler is called, either immediately, delayed (dev-end missing, 3278c2ecf20Sopenharmony_ci * or sense required) or never (no IRQ handler registered). 3288c2ecf20Sopenharmony_ci * This function notifies the device driver if the channel program has not 3298c2ecf20Sopenharmony_ci * completed during the time specified by @expires. If a timeout occurs, the 3308c2ecf20Sopenharmony_ci * channel program is terminated via xsch, hsch or csch, and the device's 3318c2ecf20Sopenharmony_ci * interrupt handler will be called with an irb containing ERR_PTR(-%ETIMEDOUT). 3328c2ecf20Sopenharmony_ci * The interruption handler will echo back the @intparm specified here, unless 3338c2ecf20Sopenharmony_ci * another interruption parameter is specified by a subsequent invocation of 3348c2ecf20Sopenharmony_ci * ccw_device_halt() or ccw_device_clear(). 3358c2ecf20Sopenharmony_ci * Returns: 3368c2ecf20Sopenharmony_ci * %0, if the operation was successful; 3378c2ecf20Sopenharmony_ci * -%EBUSY, if the device is busy, or status pending; 3388c2ecf20Sopenharmony_ci * -%EACCES, if no path specified in @lpm is operational; 3398c2ecf20Sopenharmony_ci * -%ENODEV, if the device is not operational. 3408c2ecf20Sopenharmony_ci * Context: 3418c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 3428c2ecf20Sopenharmony_ci */ 3438c2ecf20Sopenharmony_ciint ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa, 3448c2ecf20Sopenharmony_ci unsigned long intparm, __u8 lpm, 3458c2ecf20Sopenharmony_ci unsigned long flags, int expires) 3468c2ecf20Sopenharmony_ci{ 3478c2ecf20Sopenharmony_ci return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm, 3488c2ecf20Sopenharmony_ci PAGE_DEFAULT_KEY, flags, 3498c2ecf20Sopenharmony_ci expires); 3508c2ecf20Sopenharmony_ci} 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci/** 3548c2ecf20Sopenharmony_ci * ccw_device_halt() - halt I/O request processing 3558c2ecf20Sopenharmony_ci * @cdev: target ccw device 3568c2ecf20Sopenharmony_ci * @intparm: interruption parameter to be returned upon conclusion of hsch 3578c2ecf20Sopenharmony_ci * 3588c2ecf20Sopenharmony_ci * ccw_device_halt() calls hsch on @cdev's subchannel. 3598c2ecf20Sopenharmony_ci * The interruption handler will echo back the @intparm specified here, unless 3608c2ecf20Sopenharmony_ci * another interruption parameter is specified by a subsequent invocation of 3618c2ecf20Sopenharmony_ci * ccw_device_clear(). 3628c2ecf20Sopenharmony_ci * Returns: 3638c2ecf20Sopenharmony_ci * %0 on success, 3648c2ecf20Sopenharmony_ci * -%ENODEV on device not operational, 3658c2ecf20Sopenharmony_ci * -%EINVAL on invalid device state, 3668c2ecf20Sopenharmony_ci * -%EBUSY on device busy or interrupt pending. 3678c2ecf20Sopenharmony_ci * Context: 3688c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 3698c2ecf20Sopenharmony_ci */ 3708c2ecf20Sopenharmony_ciint ccw_device_halt(struct ccw_device *cdev, unsigned long intparm) 3718c2ecf20Sopenharmony_ci{ 3728c2ecf20Sopenharmony_ci struct subchannel *sch; 3738c2ecf20Sopenharmony_ci int ret; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci if (!cdev || !cdev->dev.parent) 3768c2ecf20Sopenharmony_ci return -ENODEV; 3778c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 3788c2ecf20Sopenharmony_ci if (!sch->schib.pmcw.ena) 3798c2ecf20Sopenharmony_ci return -EINVAL; 3808c2ecf20Sopenharmony_ci if (cdev->private->state == DEV_STATE_NOT_OPER) 3818c2ecf20Sopenharmony_ci return -ENODEV; 3828c2ecf20Sopenharmony_ci if (cdev->private->state != DEV_STATE_ONLINE && 3838c2ecf20Sopenharmony_ci cdev->private->state != DEV_STATE_W4SENSE) 3848c2ecf20Sopenharmony_ci return -EINVAL; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci ret = cio_halt(sch); 3878c2ecf20Sopenharmony_ci if (ret == 0) 3888c2ecf20Sopenharmony_ci cdev->private->intparm = intparm; 3898c2ecf20Sopenharmony_ci return ret; 3908c2ecf20Sopenharmony_ci} 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci/** 3938c2ecf20Sopenharmony_ci * ccw_device_resume() - resume channel program execution 3948c2ecf20Sopenharmony_ci * @cdev: target ccw device 3958c2ecf20Sopenharmony_ci * 3968c2ecf20Sopenharmony_ci * ccw_device_resume() calls rsch on @cdev's subchannel. 3978c2ecf20Sopenharmony_ci * Returns: 3988c2ecf20Sopenharmony_ci * %0 on success, 3998c2ecf20Sopenharmony_ci * -%ENODEV on device not operational, 4008c2ecf20Sopenharmony_ci * -%EINVAL on invalid device state, 4018c2ecf20Sopenharmony_ci * -%EBUSY on device busy or interrupt pending. 4028c2ecf20Sopenharmony_ci * Context: 4038c2ecf20Sopenharmony_ci * Interrupts disabled, ccw device lock held 4048c2ecf20Sopenharmony_ci */ 4058c2ecf20Sopenharmony_ciint ccw_device_resume(struct ccw_device *cdev) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci struct subchannel *sch; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci if (!cdev || !cdev->dev.parent) 4108c2ecf20Sopenharmony_ci return -ENODEV; 4118c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 4128c2ecf20Sopenharmony_ci if (!sch->schib.pmcw.ena) 4138c2ecf20Sopenharmony_ci return -EINVAL; 4148c2ecf20Sopenharmony_ci if (cdev->private->state == DEV_STATE_NOT_OPER) 4158c2ecf20Sopenharmony_ci return -ENODEV; 4168c2ecf20Sopenharmony_ci if (cdev->private->state != DEV_STATE_ONLINE || 4178c2ecf20Sopenharmony_ci !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED)) 4188c2ecf20Sopenharmony_ci return -EINVAL; 4198c2ecf20Sopenharmony_ci return cio_resume(sch); 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci/** 4238c2ecf20Sopenharmony_ci * ccw_device_get_ciw() - Search for CIW command in extended sense data. 4248c2ecf20Sopenharmony_ci * @cdev: ccw device to inspect 4258c2ecf20Sopenharmony_ci * @ct: command type to look for 4268c2ecf20Sopenharmony_ci * 4278c2ecf20Sopenharmony_ci * During SenseID, command information words (CIWs) describing special 4288c2ecf20Sopenharmony_ci * commands available to the device may have been stored in the extended 4298c2ecf20Sopenharmony_ci * sense data. This function searches for CIWs of a specified command 4308c2ecf20Sopenharmony_ci * type in the extended sense data. 4318c2ecf20Sopenharmony_ci * Returns: 4328c2ecf20Sopenharmony_ci * %NULL if no extended sense data has been stored or if no CIW of the 4338c2ecf20Sopenharmony_ci * specified command type could be found, 4348c2ecf20Sopenharmony_ci * else a pointer to the CIW of the specified command type. 4358c2ecf20Sopenharmony_ci */ 4368c2ecf20Sopenharmony_cistruct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci int ciw_cnt; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci if (cdev->private->flags.esid == 0) 4418c2ecf20Sopenharmony_ci return NULL; 4428c2ecf20Sopenharmony_ci for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++) 4438c2ecf20Sopenharmony_ci if (cdev->private->dma_area->senseid.ciw[ciw_cnt].ct == ct) 4448c2ecf20Sopenharmony_ci return cdev->private->dma_area->senseid.ciw + ciw_cnt; 4458c2ecf20Sopenharmony_ci return NULL; 4468c2ecf20Sopenharmony_ci} 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci/** 4498c2ecf20Sopenharmony_ci * ccw_device_get_path_mask() - get currently available paths 4508c2ecf20Sopenharmony_ci * @cdev: ccw device to be queried 4518c2ecf20Sopenharmony_ci * Returns: 4528c2ecf20Sopenharmony_ci * %0 if no subchannel for the device is available, 4538c2ecf20Sopenharmony_ci * else the mask of currently available paths for the ccw device's subchannel. 4548c2ecf20Sopenharmony_ci */ 4558c2ecf20Sopenharmony_ci__u8 ccw_device_get_path_mask(struct ccw_device *cdev) 4568c2ecf20Sopenharmony_ci{ 4578c2ecf20Sopenharmony_ci struct subchannel *sch; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci if (!cdev->dev.parent) 4608c2ecf20Sopenharmony_ci return 0; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 4638c2ecf20Sopenharmony_ci return sch->lpm; 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci/** 4678c2ecf20Sopenharmony_ci * ccw_device_get_chp_desc() - return newly allocated channel-path descriptor 4688c2ecf20Sopenharmony_ci * @cdev: device to obtain the descriptor for 4698c2ecf20Sopenharmony_ci * @chp_idx: index of the channel path 4708c2ecf20Sopenharmony_ci * 4718c2ecf20Sopenharmony_ci * On success return a newly allocated copy of the channel-path description 4728c2ecf20Sopenharmony_ci * data associated with the given channel path. Return %NULL on error. 4738c2ecf20Sopenharmony_ci */ 4748c2ecf20Sopenharmony_cistruct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *cdev, 4758c2ecf20Sopenharmony_ci int chp_idx) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci struct subchannel *sch; 4788c2ecf20Sopenharmony_ci struct chp_id chpid; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 4818c2ecf20Sopenharmony_ci chp_id_init(&chpid); 4828c2ecf20Sopenharmony_ci chpid.id = sch->schib.pmcw.chpid[chp_idx]; 4838c2ecf20Sopenharmony_ci return chp_get_chp_desc(chpid); 4848c2ecf20Sopenharmony_ci} 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci/** 4878c2ecf20Sopenharmony_ci * ccw_device_get_util_str() - return newly allocated utility strings 4888c2ecf20Sopenharmony_ci * @cdev: device to obtain the utility strings for 4898c2ecf20Sopenharmony_ci * @chp_idx: index of the channel path 4908c2ecf20Sopenharmony_ci * 4918c2ecf20Sopenharmony_ci * On success return a newly allocated copy of the utility strings 4928c2ecf20Sopenharmony_ci * associated with the given channel path. Return %NULL on error. 4938c2ecf20Sopenharmony_ci */ 4948c2ecf20Sopenharmony_ciu8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx) 4958c2ecf20Sopenharmony_ci{ 4968c2ecf20Sopenharmony_ci struct subchannel *sch = to_subchannel(cdev->dev.parent); 4978c2ecf20Sopenharmony_ci struct channel_path *chp; 4988c2ecf20Sopenharmony_ci struct chp_id chpid; 4998c2ecf20Sopenharmony_ci u8 *util_str; 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci chp_id_init(&chpid); 5028c2ecf20Sopenharmony_ci chpid.id = sch->schib.pmcw.chpid[chp_idx]; 5038c2ecf20Sopenharmony_ci chp = chpid_to_chp(chpid); 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci util_str = kmalloc(sizeof(chp->desc_fmt3.util_str), GFP_KERNEL); 5068c2ecf20Sopenharmony_ci if (!util_str) 5078c2ecf20Sopenharmony_ci return NULL; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci mutex_lock(&chp->lock); 5108c2ecf20Sopenharmony_ci memcpy(util_str, chp->desc_fmt3.util_str, sizeof(chp->desc_fmt3.util_str)); 5118c2ecf20Sopenharmony_ci mutex_unlock(&chp->lock); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci return util_str; 5148c2ecf20Sopenharmony_ci} 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci/** 5178c2ecf20Sopenharmony_ci * ccw_device_get_id() - obtain a ccw device id 5188c2ecf20Sopenharmony_ci * @cdev: device to obtain the id for 5198c2ecf20Sopenharmony_ci * @dev_id: where to fill in the values 5208c2ecf20Sopenharmony_ci */ 5218c2ecf20Sopenharmony_civoid ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci *dev_id = cdev->private->dev_id; 5248c2ecf20Sopenharmony_ci} 5258c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_get_id); 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci/** 5288c2ecf20Sopenharmony_ci * ccw_device_tm_start_timeout_key() - perform start function 5298c2ecf20Sopenharmony_ci * @cdev: ccw device on which to perform the start function 5308c2ecf20Sopenharmony_ci * @tcw: transport-command word to be started 5318c2ecf20Sopenharmony_ci * @intparm: user defined parameter to be passed to the interrupt handler 5328c2ecf20Sopenharmony_ci * @lpm: mask of paths to use 5338c2ecf20Sopenharmony_ci * @key: storage key to use for storage access 5348c2ecf20Sopenharmony_ci * @expires: time span in jiffies after which to abort request 5358c2ecf20Sopenharmony_ci * 5368c2ecf20Sopenharmony_ci * Start the tcw on the given ccw device. Return zero on success, non-zero 5378c2ecf20Sopenharmony_ci * otherwise. 5388c2ecf20Sopenharmony_ci */ 5398c2ecf20Sopenharmony_ciint ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw, 5408c2ecf20Sopenharmony_ci unsigned long intparm, u8 lpm, u8 key, 5418c2ecf20Sopenharmony_ci int expires) 5428c2ecf20Sopenharmony_ci{ 5438c2ecf20Sopenharmony_ci struct subchannel *sch; 5448c2ecf20Sopenharmony_ci int rc; 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci sch = to_subchannel(cdev->dev.parent); 5478c2ecf20Sopenharmony_ci if (!sch->schib.pmcw.ena) 5488c2ecf20Sopenharmony_ci return -EINVAL; 5498c2ecf20Sopenharmony_ci if (cdev->private->state == DEV_STATE_VERIFY) { 5508c2ecf20Sopenharmony_ci /* Remember to fake irb when finished. */ 5518c2ecf20Sopenharmony_ci if (!cdev->private->flags.fake_irb) { 5528c2ecf20Sopenharmony_ci cdev->private->flags.fake_irb = FAKE_TM_IRB; 5538c2ecf20Sopenharmony_ci cdev->private->intparm = intparm; 5548c2ecf20Sopenharmony_ci return 0; 5558c2ecf20Sopenharmony_ci } else 5568c2ecf20Sopenharmony_ci /* There's already a fake I/O around. */ 5578c2ecf20Sopenharmony_ci return -EBUSY; 5588c2ecf20Sopenharmony_ci } 5598c2ecf20Sopenharmony_ci if (cdev->private->state != DEV_STATE_ONLINE) 5608c2ecf20Sopenharmony_ci return -EIO; 5618c2ecf20Sopenharmony_ci /* Adjust requested path mask to exclude unusable paths. */ 5628c2ecf20Sopenharmony_ci if (lpm) { 5638c2ecf20Sopenharmony_ci lpm &= sch->lpm; 5648c2ecf20Sopenharmony_ci if (lpm == 0) 5658c2ecf20Sopenharmony_ci return -EACCES; 5668c2ecf20Sopenharmony_ci } 5678c2ecf20Sopenharmony_ci rc = cio_tm_start_key(sch, tcw, lpm, key); 5688c2ecf20Sopenharmony_ci if (rc == 0) { 5698c2ecf20Sopenharmony_ci cdev->private->intparm = intparm; 5708c2ecf20Sopenharmony_ci if (expires) 5718c2ecf20Sopenharmony_ci ccw_device_set_timeout(cdev, expires); 5728c2ecf20Sopenharmony_ci } 5738c2ecf20Sopenharmony_ci return rc; 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_tm_start_timeout_key); 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci/** 5788c2ecf20Sopenharmony_ci * ccw_device_tm_start_key() - perform start function 5798c2ecf20Sopenharmony_ci * @cdev: ccw device on which to perform the start function 5808c2ecf20Sopenharmony_ci * @tcw: transport-command word to be started 5818c2ecf20Sopenharmony_ci * @intparm: user defined parameter to be passed to the interrupt handler 5828c2ecf20Sopenharmony_ci * @lpm: mask of paths to use 5838c2ecf20Sopenharmony_ci * @key: storage key to use for storage access 5848c2ecf20Sopenharmony_ci * 5858c2ecf20Sopenharmony_ci * Start the tcw on the given ccw device. Return zero on success, non-zero 5868c2ecf20Sopenharmony_ci * otherwise. 5878c2ecf20Sopenharmony_ci */ 5888c2ecf20Sopenharmony_ciint ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw, 5898c2ecf20Sopenharmony_ci unsigned long intparm, u8 lpm, u8 key) 5908c2ecf20Sopenharmony_ci{ 5918c2ecf20Sopenharmony_ci return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm, key, 0); 5928c2ecf20Sopenharmony_ci} 5938c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_tm_start_key); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci/** 5968c2ecf20Sopenharmony_ci * ccw_device_tm_start() - perform start function 5978c2ecf20Sopenharmony_ci * @cdev: ccw device on which to perform the start function 5988c2ecf20Sopenharmony_ci * @tcw: transport-command word to be started 5998c2ecf20Sopenharmony_ci * @intparm: user defined parameter to be passed to the interrupt handler 6008c2ecf20Sopenharmony_ci * @lpm: mask of paths to use 6018c2ecf20Sopenharmony_ci * 6028c2ecf20Sopenharmony_ci * Start the tcw on the given ccw device. Return zero on success, non-zero 6038c2ecf20Sopenharmony_ci * otherwise. 6048c2ecf20Sopenharmony_ci */ 6058c2ecf20Sopenharmony_ciint ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw, 6068c2ecf20Sopenharmony_ci unsigned long intparm, u8 lpm) 6078c2ecf20Sopenharmony_ci{ 6088c2ecf20Sopenharmony_ci return ccw_device_tm_start_key(cdev, tcw, intparm, lpm, 6098c2ecf20Sopenharmony_ci PAGE_DEFAULT_KEY); 6108c2ecf20Sopenharmony_ci} 6118c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_tm_start); 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci/** 6148c2ecf20Sopenharmony_ci * ccw_device_tm_start_timeout() - perform start function 6158c2ecf20Sopenharmony_ci * @cdev: ccw device on which to perform the start function 6168c2ecf20Sopenharmony_ci * @tcw: transport-command word to be started 6178c2ecf20Sopenharmony_ci * @intparm: user defined parameter to be passed to the interrupt handler 6188c2ecf20Sopenharmony_ci * @lpm: mask of paths to use 6198c2ecf20Sopenharmony_ci * @expires: time span in jiffies after which to abort request 6208c2ecf20Sopenharmony_ci * 6218c2ecf20Sopenharmony_ci * Start the tcw on the given ccw device. Return zero on success, non-zero 6228c2ecf20Sopenharmony_ci * otherwise. 6238c2ecf20Sopenharmony_ci */ 6248c2ecf20Sopenharmony_ciint ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw, 6258c2ecf20Sopenharmony_ci unsigned long intparm, u8 lpm, int expires) 6268c2ecf20Sopenharmony_ci{ 6278c2ecf20Sopenharmony_ci return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm, 6288c2ecf20Sopenharmony_ci PAGE_DEFAULT_KEY, expires); 6298c2ecf20Sopenharmony_ci} 6308c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_tm_start_timeout); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci/** 6338c2ecf20Sopenharmony_ci * ccw_device_get_mdc() - accumulate max data count 6348c2ecf20Sopenharmony_ci * @cdev: ccw device for which the max data count is accumulated 6358c2ecf20Sopenharmony_ci * @mask: mask of paths to use 6368c2ecf20Sopenharmony_ci * 6378c2ecf20Sopenharmony_ci * Return the number of 64K-bytes blocks all paths at least support 6388c2ecf20Sopenharmony_ci * for a transport command. Return value 0 indicates failure. 6398c2ecf20Sopenharmony_ci */ 6408c2ecf20Sopenharmony_ciint ccw_device_get_mdc(struct ccw_device *cdev, u8 mask) 6418c2ecf20Sopenharmony_ci{ 6428c2ecf20Sopenharmony_ci struct subchannel *sch = to_subchannel(cdev->dev.parent); 6438c2ecf20Sopenharmony_ci struct channel_path *chp; 6448c2ecf20Sopenharmony_ci struct chp_id chpid; 6458c2ecf20Sopenharmony_ci int mdc = 0, i; 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci /* Adjust requested path mask to excluded varied off paths. */ 6488c2ecf20Sopenharmony_ci if (mask) 6498c2ecf20Sopenharmony_ci mask &= sch->lpm; 6508c2ecf20Sopenharmony_ci else 6518c2ecf20Sopenharmony_ci mask = sch->lpm; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci chp_id_init(&chpid); 6548c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) { 6558c2ecf20Sopenharmony_ci if (!(mask & (0x80 >> i))) 6568c2ecf20Sopenharmony_ci continue; 6578c2ecf20Sopenharmony_ci chpid.id = sch->schib.pmcw.chpid[i]; 6588c2ecf20Sopenharmony_ci chp = chpid_to_chp(chpid); 6598c2ecf20Sopenharmony_ci if (!chp) 6608c2ecf20Sopenharmony_ci continue; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci mutex_lock(&chp->lock); 6638c2ecf20Sopenharmony_ci if (!chp->desc_fmt1.f) { 6648c2ecf20Sopenharmony_ci mutex_unlock(&chp->lock); 6658c2ecf20Sopenharmony_ci return 0; 6668c2ecf20Sopenharmony_ci } 6678c2ecf20Sopenharmony_ci if (!chp->desc_fmt1.r) 6688c2ecf20Sopenharmony_ci mdc = 1; 6698c2ecf20Sopenharmony_ci mdc = mdc ? min_t(int, mdc, chp->desc_fmt1.mdc) : 6708c2ecf20Sopenharmony_ci chp->desc_fmt1.mdc; 6718c2ecf20Sopenharmony_ci mutex_unlock(&chp->lock); 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci return mdc; 6758c2ecf20Sopenharmony_ci} 6768c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_get_mdc); 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci/** 6798c2ecf20Sopenharmony_ci * ccw_device_tm_intrg() - perform interrogate function 6808c2ecf20Sopenharmony_ci * @cdev: ccw device on which to perform the interrogate function 6818c2ecf20Sopenharmony_ci * 6828c2ecf20Sopenharmony_ci * Perform an interrogate function on the given ccw device. Return zero on 6838c2ecf20Sopenharmony_ci * success, non-zero otherwise. 6848c2ecf20Sopenharmony_ci */ 6858c2ecf20Sopenharmony_ciint ccw_device_tm_intrg(struct ccw_device *cdev) 6868c2ecf20Sopenharmony_ci{ 6878c2ecf20Sopenharmony_ci struct subchannel *sch = to_subchannel(cdev->dev.parent); 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci if (!sch->schib.pmcw.ena) 6908c2ecf20Sopenharmony_ci return -EINVAL; 6918c2ecf20Sopenharmony_ci if (cdev->private->state != DEV_STATE_ONLINE) 6928c2ecf20Sopenharmony_ci return -EIO; 6938c2ecf20Sopenharmony_ci if (!scsw_is_tm(&sch->schib.scsw) || 6948c2ecf20Sopenharmony_ci !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_START_PEND)) 6958c2ecf20Sopenharmony_ci return -EINVAL; 6968c2ecf20Sopenharmony_ci return cio_tm_intrg(sch); 6978c2ecf20Sopenharmony_ci} 6988c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_tm_intrg); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci/** 7018c2ecf20Sopenharmony_ci * ccw_device_get_schid() - obtain a subchannel id 7028c2ecf20Sopenharmony_ci * @cdev: device to obtain the id for 7038c2ecf20Sopenharmony_ci * @schid: where to fill in the values 7048c2ecf20Sopenharmony_ci */ 7058c2ecf20Sopenharmony_civoid ccw_device_get_schid(struct ccw_device *cdev, struct subchannel_id *schid) 7068c2ecf20Sopenharmony_ci{ 7078c2ecf20Sopenharmony_ci struct subchannel *sch = to_subchannel(cdev->dev.parent); 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci *schid = sch->schid; 7108c2ecf20Sopenharmony_ci} 7118c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_schid); 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci/** 7148c2ecf20Sopenharmony_ci * ccw_device_pnso() - Perform Network-Subchannel Operation 7158c2ecf20Sopenharmony_ci * @cdev: device on which PNSO is performed 7168c2ecf20Sopenharmony_ci * @pnso_area: request and response block for the operation 7178c2ecf20Sopenharmony_ci * @oc: Operation Code 7188c2ecf20Sopenharmony_ci * @resume_token: resume token for multiblock response 7198c2ecf20Sopenharmony_ci * @cnc: Boolean change-notification control 7208c2ecf20Sopenharmony_ci * 7218c2ecf20Sopenharmony_ci * pnso_area must be allocated by the caller with get_zeroed_page(GFP_KERNEL) 7228c2ecf20Sopenharmony_ci * 7238c2ecf20Sopenharmony_ci * Returns 0 on success. 7248c2ecf20Sopenharmony_ci */ 7258c2ecf20Sopenharmony_ciint ccw_device_pnso(struct ccw_device *cdev, 7268c2ecf20Sopenharmony_ci struct chsc_pnso_area *pnso_area, u8 oc, 7278c2ecf20Sopenharmony_ci struct chsc_pnso_resume_token resume_token, int cnc) 7288c2ecf20Sopenharmony_ci{ 7298c2ecf20Sopenharmony_ci struct subchannel_id schid; 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci ccw_device_get_schid(cdev, &schid); 7328c2ecf20Sopenharmony_ci return chsc_pnso(schid, pnso_area, oc, resume_token, cnc); 7338c2ecf20Sopenharmony_ci} 7348c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_pnso); 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci/** 7378c2ecf20Sopenharmony_ci * ccw_device_get_cssid() - obtain Channel Subsystem ID 7388c2ecf20Sopenharmony_ci * @cdev: device to obtain the CSSID for 7398c2ecf20Sopenharmony_ci * @cssid: The resulting Channel Subsystem ID 7408c2ecf20Sopenharmony_ci */ 7418c2ecf20Sopenharmony_ciint ccw_device_get_cssid(struct ccw_device *cdev, u8 *cssid) 7428c2ecf20Sopenharmony_ci{ 7438c2ecf20Sopenharmony_ci struct device *sch_dev = cdev->dev.parent; 7448c2ecf20Sopenharmony_ci struct channel_subsystem *css = to_css(sch_dev->parent); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci if (css->id_valid) 7478c2ecf20Sopenharmony_ci *cssid = css->cssid; 7488c2ecf20Sopenharmony_ci return css->id_valid ? 0 : -ENODEV; 7498c2ecf20Sopenharmony_ci} 7508c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_cssid); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci/** 7538c2ecf20Sopenharmony_ci * ccw_device_get_iid() - obtain MIF-image ID 7548c2ecf20Sopenharmony_ci * @cdev: device to obtain the MIF-image ID for 7558c2ecf20Sopenharmony_ci * @iid: The resulting MIF-image ID 7568c2ecf20Sopenharmony_ci */ 7578c2ecf20Sopenharmony_ciint ccw_device_get_iid(struct ccw_device *cdev, u8 *iid) 7588c2ecf20Sopenharmony_ci{ 7598c2ecf20Sopenharmony_ci struct device *sch_dev = cdev->dev.parent; 7608c2ecf20Sopenharmony_ci struct channel_subsystem *css = to_css(sch_dev->parent); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci if (css->id_valid) 7638c2ecf20Sopenharmony_ci *iid = css->iid; 7648c2ecf20Sopenharmony_ci return css->id_valid ? 0 : -ENODEV; 7658c2ecf20Sopenharmony_ci} 7668c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_iid); 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci/** 7698c2ecf20Sopenharmony_ci * ccw_device_get_chpid() - obtain Channel Path ID 7708c2ecf20Sopenharmony_ci * @cdev: device to obtain the Channel Path ID for 7718c2ecf20Sopenharmony_ci * @chp_idx: Index of the channel path 7728c2ecf20Sopenharmony_ci * @chpid: The resulting Channel Path ID 7738c2ecf20Sopenharmony_ci */ 7748c2ecf20Sopenharmony_ciint ccw_device_get_chpid(struct ccw_device *cdev, int chp_idx, u8 *chpid) 7758c2ecf20Sopenharmony_ci{ 7768c2ecf20Sopenharmony_ci struct subchannel *sch = to_subchannel(cdev->dev.parent); 7778c2ecf20Sopenharmony_ci int mask; 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci if ((chp_idx < 0) || (chp_idx > 7)) 7808c2ecf20Sopenharmony_ci return -EINVAL; 7818c2ecf20Sopenharmony_ci mask = 0x80 >> chp_idx; 7828c2ecf20Sopenharmony_ci if (!(sch->schib.pmcw.pim & mask)) 7838c2ecf20Sopenharmony_ci return -ENODEV; 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci *chpid = sch->schib.pmcw.chpid[chp_idx]; 7868c2ecf20Sopenharmony_ci return 0; 7878c2ecf20Sopenharmony_ci} 7888c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_chpid); 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci/** 7918c2ecf20Sopenharmony_ci * ccw_device_get_chid() - obtain Channel ID associated with specified CHPID 7928c2ecf20Sopenharmony_ci * @cdev: device to obtain the Channel ID for 7938c2ecf20Sopenharmony_ci * @chp_idx: Index of the channel path 7948c2ecf20Sopenharmony_ci * @chid: The resulting Channel ID 7958c2ecf20Sopenharmony_ci */ 7968c2ecf20Sopenharmony_ciint ccw_device_get_chid(struct ccw_device *cdev, int chp_idx, u16 *chid) 7978c2ecf20Sopenharmony_ci{ 7988c2ecf20Sopenharmony_ci struct chp_id cssid_chpid; 7998c2ecf20Sopenharmony_ci struct channel_path *chp; 8008c2ecf20Sopenharmony_ci int rc; 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci chp_id_init(&cssid_chpid); 8038c2ecf20Sopenharmony_ci rc = ccw_device_get_chpid(cdev, chp_idx, &cssid_chpid.id); 8048c2ecf20Sopenharmony_ci if (rc) 8058c2ecf20Sopenharmony_ci return rc; 8068c2ecf20Sopenharmony_ci chp = chpid_to_chp(cssid_chpid); 8078c2ecf20Sopenharmony_ci if (!chp) 8088c2ecf20Sopenharmony_ci return -ENODEV; 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci mutex_lock(&chp->lock); 8118c2ecf20Sopenharmony_ci if (chp->desc_fmt1.flags & 0x10) 8128c2ecf20Sopenharmony_ci *chid = chp->desc_fmt1.chid; 8138c2ecf20Sopenharmony_ci else 8148c2ecf20Sopenharmony_ci rc = -ENODEV; 8158c2ecf20Sopenharmony_ci mutex_unlock(&chp->lock); 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci return rc; 8188c2ecf20Sopenharmony_ci} 8198c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_chid); 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci/* 8228c2ecf20Sopenharmony_ci * Allocate zeroed dma coherent 31 bit addressable memory using 8238c2ecf20Sopenharmony_ci * the subchannels dma pool. Maximal size of allocation supported 8248c2ecf20Sopenharmony_ci * is PAGE_SIZE. 8258c2ecf20Sopenharmony_ci */ 8268c2ecf20Sopenharmony_civoid *ccw_device_dma_zalloc(struct ccw_device *cdev, size_t size) 8278c2ecf20Sopenharmony_ci{ 8288c2ecf20Sopenharmony_ci void *addr; 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci if (!get_device(&cdev->dev)) 8318c2ecf20Sopenharmony_ci return NULL; 8328c2ecf20Sopenharmony_ci addr = cio_gp_dma_zalloc(cdev->private->dma_pool, &cdev->dev, size); 8338c2ecf20Sopenharmony_ci if (IS_ERR_OR_NULL(addr)) 8348c2ecf20Sopenharmony_ci put_device(&cdev->dev); 8358c2ecf20Sopenharmony_ci return addr; 8368c2ecf20Sopenharmony_ci} 8378c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_dma_zalloc); 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_civoid ccw_device_dma_free(struct ccw_device *cdev, void *cpu_addr, size_t size) 8408c2ecf20Sopenharmony_ci{ 8418c2ecf20Sopenharmony_ci if (!cpu_addr) 8428c2ecf20Sopenharmony_ci return; 8438c2ecf20Sopenharmony_ci cio_gp_dma_free(cdev->private->dma_pool, cpu_addr, size); 8448c2ecf20Sopenharmony_ci put_device(&cdev->dev); 8458c2ecf20Sopenharmony_ci} 8468c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_dma_free); 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_set_options_mask); 8498c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_set_options); 8508c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_clear_options); 8518c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_clear); 8528c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_halt); 8538c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_resume); 8548c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_start_timeout); 8558c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_start); 8568c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_start_timeout_key); 8578c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_start_key); 8588c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_get_ciw); 8598c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ccw_device_get_path_mask); 8608c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_chp_desc); 8618c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_get_util_str); 862