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)  * Module interface and handling of zfcp data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright IBM Corp. 2002, 2020
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Driver authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *            Martin Peschke (originator of the driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *            Raimund Schroeder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *            Aron Zeh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *            Wolfgang Taphorn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *            Stefan Bader
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *            Heiko Carstens (kernel 2.6 port of the driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *            Andreas Herrmann
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *            Maxim Shchetynin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *            Volker Sameske
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *            Ralph Wuerthner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *            Michael Loehr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *            Swen Schillig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *            Christof Schmitt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *            Martin Petermann
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *            Sven Schuetz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *            Steffen Maier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *	      Benjamin Block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define KMSG_COMPONENT "zfcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "zfcp_ext.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "zfcp_fc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "zfcp_reqlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include "zfcp_diag.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define ZFCP_BUS_ID_SIZE	20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) MODULE_AUTHOR("IBM Deutschland Entwicklung GmbH - linux390@de.ibm.com");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) MODULE_DESCRIPTION("FCP HBA driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static char *init_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) module_param_named(device, init_device, charp, 0400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) MODULE_PARM_DESC(device, "specify initial device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static struct kmem_cache * __init zfcp_cache_hw_align(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 						      unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct ccw_device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct zfcp_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	cdev = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (!cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (ccw_device_set_online(cdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		goto out_ccw_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	adapter = zfcp_ccw_adapter_by_cdev(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (!adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto out_ccw_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	port = zfcp_get_port_by_wwpn(adapter, wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		goto out_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	flush_work(&port->rport_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	zfcp_unit_add(port, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) out_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) out_ccw_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	put_device(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return;
^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) static void __init zfcp_init_device_setup(char *devstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	char *token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	char *str, *str_saved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	char busid[ZFCP_BUS_ID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u64 wwpn, lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	/* duplicate devstr and keep the original for sysfs presentation*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	str_saved = kstrdup(devstr, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	str = str_saved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	token = strsep(&str, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	strlcpy(busid, token, ZFCP_BUS_ID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	token = strsep(&str, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (!token || kstrtoull(token, 0, (unsigned long long *) &wwpn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	token = strsep(&str, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (!token || kstrtoull(token, 0, (unsigned long long *) &lun))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	kfree(str_saved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	zfcp_init_device_configure(busid, wwpn, lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	kfree(str_saved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	pr_err("%s is not a valid SCSI device\n", devstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int __init zfcp_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (zfcp_experimental_dix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		pr_warn("DIX is enabled. It is experimental and might cause problems\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	zfcp_fsf_qtcb_cache = zfcp_cache_hw_align("zfcp_fsf_qtcb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 						  sizeof(struct fsf_qtcb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (!zfcp_fsf_qtcb_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		goto out_qtcb_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	zfcp_fc_req_cache = zfcp_cache_hw_align("zfcp_fc_req",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 						sizeof(struct zfcp_fc_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (!zfcp_fc_req_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		goto out_fc_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	zfcp_scsi_transport_template =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		fc_attach_transport(&zfcp_transport_functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!zfcp_scsi_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		goto out_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	scsi_transport_reserve_device(zfcp_scsi_transport_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				      sizeof(struct zfcp_scsi_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	retval = ccw_driver_register(&zfcp_ccw_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		pr_err("The zfcp device driver could not register with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		       "the common I/O layer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto out_ccw_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (init_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		zfcp_init_device_setup(init_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) out_ccw_register:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	fc_release_transport(zfcp_scsi_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) out_transport:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	kmem_cache_destroy(zfcp_fc_req_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) out_fc_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	kmem_cache_destroy(zfcp_fsf_qtcb_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) out_qtcb_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) module_init(zfcp_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static void __exit zfcp_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ccw_driver_unregister(&zfcp_ccw_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	fc_release_transport(zfcp_scsi_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	kmem_cache_destroy(zfcp_fc_req_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	kmem_cache_destroy(zfcp_fsf_qtcb_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) module_exit(zfcp_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * zfcp_get_port_by_wwpn - find port in port list of adapter by wwpn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * @adapter: pointer to adapter to search for port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @wwpn: wwpn to search for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * Returns: pointer to zfcp_port or NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 					u64 wwpn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	read_lock_irqsave(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (port->wwpn == wwpn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			if (!get_device(&port->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				port = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			read_unlock_irqrestore(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			return port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	read_unlock_irqrestore(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	adapter->pool.erp_req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!adapter->pool.erp_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	adapter->pool.gid_pn_req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!adapter->pool.gid_pn_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	adapter->pool.scsi_req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!adapter->pool.scsi_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	adapter->pool.scsi_abort =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		mempool_create_kmalloc_pool(1, sizeof(struct zfcp_fsf_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (!adapter->pool.scsi_abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	adapter->pool.status_read_req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		mempool_create_kmalloc_pool(FSF_STATUS_READS_RECOM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					    sizeof(struct zfcp_fsf_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (!adapter->pool.status_read_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	adapter->pool.qtcb_pool =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		mempool_create_slab_pool(4, zfcp_fsf_qtcb_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!adapter->pool.qtcb_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	BUILD_BUG_ON(sizeof(struct fsf_status_read_buffer) > PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	adapter->pool.sr_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		mempool_create_page_pool(FSF_STATUS_READS_RECOM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (!adapter->pool.sr_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	adapter->pool.gid_pn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		mempool_create_slab_pool(1, zfcp_fc_req_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!adapter->pool.gid_pn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	mempool_destroy(adapter->pool.erp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	mempool_destroy(adapter->pool.scsi_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	mempool_destroy(adapter->pool.scsi_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	mempool_destroy(adapter->pool.qtcb_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	mempool_destroy(adapter->pool.status_read_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	mempool_destroy(adapter->pool.sr_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	mempool_destroy(adapter->pool.gid_pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * zfcp_status_read_refill - refill the long running status_read_requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @adapter: ptr to struct zfcp_adapter for which the buffers should be refilled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * * 0 on success meaning at least one status read is pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * * 1 if posting failed and not a single status read buffer is pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  *     also triggers adapter reopen recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int zfcp_status_read_refill(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	while (atomic_add_unless(&adapter->stat_miss, -1, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (zfcp_fsf_status_read(adapter->qdio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			atomic_inc(&adapter->stat_miss); /* undo add -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			if (atomic_read(&adapter->stat_miss) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			    adapter->stat_read_buf_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				zfcp_erp_adapter_reopen(adapter, 0, "axsref1");
^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) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static void _zfcp_status_read_scheduler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	zfcp_status_read_refill(container_of(work, struct zfcp_adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 					     stat_work));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static void zfcp_print_sl(struct seq_file *m, struct service_level *sl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct zfcp_adapter *adapter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		container_of(sl, struct zfcp_adapter, service_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	seq_printf(m, "zfcp: %s microcode level %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		   dev_name(&adapter->ccw_device->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		   adapter->fsf_lic_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int zfcp_setup_adapter_work_queue(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	char name[TASK_COMM_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	snprintf(name, sizeof(name), "zfcp_q_%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		 dev_name(&adapter->ccw_device->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	adapter->work_queue = alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (adapter->work_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static void zfcp_destroy_adapter_work_queue(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (adapter->work_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		destroy_workqueue(adapter->work_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	adapter->work_queue = NULL;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * zfcp_adapter_enqueue - enqueue a new adapter to the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * @ccw_device: pointer to the struct cc_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * Returns:	struct zfcp_adapter*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * Enqueues an adapter at the end of the adapter list in the driver data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * All adapter internal structures are set up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * Proc-fs entries are also created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct zfcp_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (!get_device(&ccw_device->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	adapter = kzalloc(sizeof(struct zfcp_adapter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (!adapter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		put_device(&ccw_device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	kref_init(&adapter->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	ccw_device->handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	adapter->ccw_device = ccw_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	INIT_DELAYED_WORK(&adapter->scan_work, zfcp_fc_scan_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	INIT_WORK(&adapter->ns_up_work, zfcp_fc_sym_name_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	adapter->next_port_scan = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	adapter->erp_action.adapter = adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	if (zfcp_diag_adapter_setup(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (zfcp_qdio_setup(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (zfcp_allocate_low_mem_buffers(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	adapter->req_list = zfcp_reqlist_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (!adapter->req_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (zfcp_dbf_adapter_register(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (zfcp_setup_adapter_work_queue(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (zfcp_fc_gs_setup(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	rwlock_init(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	INIT_LIST_HEAD(&adapter->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	INIT_LIST_HEAD(&adapter->events.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	INIT_WORK(&adapter->events.work, zfcp_fc_post_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	spin_lock_init(&adapter->events.list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	init_waitqueue_head(&adapter->erp_ready_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	init_waitqueue_head(&adapter->erp_done_wqh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	INIT_LIST_HEAD(&adapter->erp_ready_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	INIT_LIST_HEAD(&adapter->erp_running_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	rwlock_init(&adapter->erp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	rwlock_init(&adapter->abort_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (zfcp_erp_thread_setup(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	adapter->service_level.seq_print = zfcp_print_sl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	dev_set_drvdata(&ccw_device->dev, adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (sysfs_create_group(&ccw_device->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			       &zfcp_sysfs_adapter_attrs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (zfcp_diag_sysfs_setup(adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	/* report size limit per scatter-gather segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	adapter->ccw_device->dev.dma_parms = &adapter->dma_parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	adapter->stat_read_buf_num = FSF_STATUS_READS_RECOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	return adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	zfcp_adapter_unregister(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) void zfcp_adapter_unregister(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	struct ccw_device *cdev = adapter->ccw_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	cancel_delayed_work_sync(&adapter->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	cancel_work_sync(&adapter->stat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	cancel_work_sync(&adapter->ns_up_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	zfcp_destroy_adapter_work_queue(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	zfcp_fc_wka_ports_force_offline(adapter->gs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	zfcp_scsi_adapter_unregister(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	zfcp_diag_sysfs_destroy(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	zfcp_erp_thread_kill(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	zfcp_dbf_adapter_unregister(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	zfcp_qdio_destroy(adapter->qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	zfcp_ccw_adapter_put(adapter); /* final put to release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * zfcp_adapter_release - remove the adapter from the resource list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * @ref: pointer to struct kref
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * locks:	adapter list write lock is assumed to be held by caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) void zfcp_adapter_release(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct zfcp_adapter *adapter = container_of(ref, struct zfcp_adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 						    ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct ccw_device *cdev = adapter->ccw_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	dev_set_drvdata(&adapter->ccw_device->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	zfcp_fc_gs_destroy(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	zfcp_free_low_mem_buffers(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	zfcp_diag_adapter_free(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	kfree(adapter->req_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	kfree(adapter->fc_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	kfree(adapter->stats_reset_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	kfree(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	put_device(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static void zfcp_port_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	zfcp_ccw_adapter_put(port->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	kfree(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * zfcp_port_enqueue - enqueue port to port list of adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * @adapter: adapter where remote port is added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  * @wwpn: WWPN of the remote port to be enqueued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  * @status: initial status for the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  * @d_id: destination id of the remote port to be enqueued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  * Returns: pointer to enqueued port on success, ERR_PTR on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  * All port internal structures are set up and the sysfs entry is generated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  * d_id is used to enqueue ports with a well known address like the Directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  * Service for nameserver lookup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 				     u32 status, u32 d_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	kref_get(&adapter->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	port = zfcp_get_port_by_wwpn(adapter, wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		retval = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	rwlock_init(&port->unit_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	INIT_LIST_HEAD(&port->unit_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	atomic_set(&port->units, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	INIT_WORK(&port->gid_pn_work, zfcp_fc_port_did_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	INIT_WORK(&port->test_link_work, zfcp_fc_link_test_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	INIT_WORK(&port->rport_work, zfcp_scsi_rport_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	port->adapter = adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	port->d_id = d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	port->wwpn = wwpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	port->rport_task = RPORT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	port->dev.parent = &adapter->ccw_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	port->dev.groups = zfcp_port_attr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	port->dev.release = zfcp_port_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	port->erp_action.adapter = adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	port->erp_action.port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (dev_set_name(&port->dev, "0x%016llx", (unsigned long long)wwpn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		kfree(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	if (device_register(&port->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	write_lock_irq(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	list_add_tail(&port->list, &adapter->port_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	write_unlock_irq(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	atomic_or(status | ZFCP_STATUS_COMMON_RUNNING, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	return port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	zfcp_ccw_adapter_put(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	return ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }