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