Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * zfcp device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Registration and callback for the s390 common I/O layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright IBM Corp. 2002, 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define KMSG_COMPONENT "zfcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "zfcp_ext.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "zfcp_reqlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define ZFCP_MODEL_PRIV 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static DEFINE_SPINLOCK(zfcp_ccw_adapter_ref_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct zfcp_adapter *zfcp_ccw_adapter_by_cdev(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct zfcp_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	spin_lock_irqsave(&zfcp_ccw_adapter_ref_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	adapter = dev_get_drvdata(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		kref_get(&adapter->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	spin_unlock_irqrestore(&zfcp_ccw_adapter_ref_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	return adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) void zfcp_ccw_adapter_put(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	spin_lock_irqsave(&zfcp_ccw_adapter_ref_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	kref_put(&adapter->ref, zfcp_adapter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	spin_unlock_irqrestore(&zfcp_ccw_adapter_ref_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * zfcp_ccw_activate - activate adapter and wait for it to finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @clear: Status flags to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @tag: s390dbf trace record tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int zfcp_ccw_activate(struct ccw_device *cdev, int clear, char *tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	zfcp_erp_clear_adapter_status(adapter, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * We want to scan ports here, with some random backoff and without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 * rate limit. Recovery has already scheduled a port scan for us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 * but with both random delay and rate limit. Nevertheless we get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 * what we want here by flushing the scheduled work after sleeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 * an equivalent random time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * Let the port scan random delay elapse first. If recovery finishes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * up to that point in time, that would be perfect for both recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * and port scan. If not, i.e. recovery takes ages, there was no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * point in waiting a random delay on top of the time consumed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	msleep(zfcp_fc_port_scan_backoff());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	flush_delayed_work(&adapter->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static struct ccw_device_id zfcp_ccw_device_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	{ CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	{ CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, ZFCP_MODEL_PRIV) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * zfcp_ccw_probe - probe function of zfcp driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * This function gets called by the common i/o layer for each FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * device found on the current system. This is only a stub to make cio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * work: To only allocate adapter resources for devices actually used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * the allocation is deferred to the first call to ccw_set_online.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int zfcp_ccw_probe(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * zfcp_ccw_remove - remove function of zfcp driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * This function gets called by the common i/o layer and removes an adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * from the system. Task of this function is to get rid of all units and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * ports that belong to this adapter. And in addition all resources of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * adapter will be freed too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void zfcp_ccw_remove(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct zfcp_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct zfcp_port *port, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct zfcp_unit *unit, *u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	LIST_HEAD(unit_remove_lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	LIST_HEAD(port_remove_lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ccw_device_set_offline(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	write_lock_irq(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	list_for_each_entry(port, &adapter->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		write_lock(&port->unit_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		list_splice_init(&port->unit_list, &unit_remove_lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		write_unlock(&port->unit_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	list_splice_init(&adapter->port_list, &port_remove_lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	write_unlock_irq(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	zfcp_ccw_adapter_put(adapter); /* put from zfcp_ccw_adapter_by_cdev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	list_for_each_entry_safe(unit, u, &unit_remove_lh, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		device_unregister(&unit->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	list_for_each_entry_safe(port, p, &port_remove_lh, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		device_unregister(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	zfcp_adapter_unregister(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * zfcp_ccw_set_online - set_online function of zfcp driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * This function gets called by the common i/o layer and sets an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * adapter into state online.  The first call will allocate all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * adapter resources that will be retained until the device is removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * via zfcp_ccw_remove.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * Setting an fcp device online means that it will be registered with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * the SCSI stack, that the QDIO queues will be set up and that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * adapter will be opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int zfcp_ccw_set_online(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!adapter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		adapter = zfcp_adapter_enqueue(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (IS_ERR(adapter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			dev_err(&cdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				"Setting up data structures for the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				"FCP adapter failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			return PTR_ERR(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		kref_get(&adapter->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* initialize request counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	BUG_ON(!zfcp_reqlist_isempty(adapter->req_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	adapter->req_no = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	zfcp_ccw_activate(cdev, 0, "ccsonl1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * We want to scan ports here, always, with some random delay and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * without rate limit - basically what zfcp_ccw_activate() has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 * achieved for us. Not quite! That port scan depended on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 * !no_auto_port_rescan. So let's cover the no_auto_port_rescan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * case here to make sure a port scan is done unconditionally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * Since zfcp_ccw_activate() has waited the desired random time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * we can immediately schedule and flush a port scan for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * remaining cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	zfcp_fc_inverse_conditional_port_scan(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	flush_delayed_work(&adapter->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * zfcp_ccw_offline_sync - shut down adapter and wait for it to finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * @set: Status flags to set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * @tag: s390dbf trace record tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * This function gets called by the common i/o layer and sets an adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * into state offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int zfcp_ccw_offline_sync(struct ccw_device *cdev, int set, char *tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	zfcp_erp_set_adapter_status(adapter, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	zfcp_erp_adapter_shutdown(adapter, 0, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * zfcp_ccw_set_offline - set_offline function of zfcp driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * This function gets called by the common i/o layer and sets an adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * into state offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int zfcp_ccw_set_offline(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return zfcp_ccw_offline_sync(cdev, 0, "ccsoff1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * zfcp_ccw_notify - ccw notify function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * @cdev: pointer to belonging ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @event: indicates if adapter was detached or attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * This function gets called by the common i/o layer if an adapter has gone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * or reappeared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int zfcp_ccw_notify(struct ccw_device *cdev, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	case CIO_GONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		    ZFCP_STATUS_ADAPTER_SUSPENDED) { /* notification ignore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			zfcp_dbf_hba_basic("ccnigo1", adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		dev_warn(&cdev->dev, "The FCP device has been detached\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	case CIO_NO_PATH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		dev_warn(&cdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			 "The CHPID for the FCP device is offline\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	case CIO_OPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		    ZFCP_STATUS_ADAPTER_SUSPENDED) { /* notification ignore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			zfcp_dbf_hba_basic("ccniop1", adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		dev_info(&cdev->dev, "The FCP device is operational again\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		zfcp_erp_set_adapter_status(adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 					    ZFCP_STATUS_COMMON_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 					"ccnoti4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	case CIO_BOXED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		dev_warn(&cdev->dev, "The FCP device did not respond within "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				     "the specified time\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * zfcp_ccw_shutdown - handle shutdown from cio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * @cdev: device for adapter to shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static void zfcp_ccw_shutdown(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	zfcp_erp_thread_kill(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int zfcp_ccw_suspend(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	zfcp_ccw_offline_sync(cdev, ZFCP_STATUS_ADAPTER_SUSPENDED, "ccsusp1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int zfcp_ccw_thaw(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/* trace records for thaw and final shutdown during suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	   can only be found in system dump until the end of suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	   but not after resume because it's based on the memory image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	   right after the very first suspend (freeze) callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	zfcp_ccw_activate(cdev, 0, "ccthaw1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static int zfcp_ccw_resume(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	zfcp_ccw_activate(cdev, ZFCP_STATUS_ADAPTER_SUSPENDED, "ccresu1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct ccw_driver zfcp_ccw_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		.owner	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		.name	= "zfcp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.ids         = zfcp_ccw_device_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.probe       = zfcp_ccw_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.remove      = zfcp_ccw_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.set_online  = zfcp_ccw_set_online,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.set_offline = zfcp_ccw_set_offline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.notify      = zfcp_ccw_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	.shutdown    = zfcp_ccw_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	.freeze      = zfcp_ccw_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	.thaw	     = zfcp_ccw_thaw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	.restore     = zfcp_ccw_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };