Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 4 | * Registration and callback for the s390 common I/O layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Swen Schillig | 6d1a27f | 2009-03-02 13:09:11 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "zfcp" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "zfcp_ext.h" |
| 13 | |
Christof Schmitt | 6fcf41d | 2009-05-15 13:18:21 +0200 | [diff] [blame^] | 14 | #define ZFCP_MODEL_PRIV 0x4 |
| 15 | |
| 16 | static struct ccw_device_id zfcp_ccw_device_id[] = { |
| 17 | { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) }, |
| 18 | { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, ZFCP_MODEL_PRIV) }, |
| 19 | {}, |
| 20 | }; |
| 21 | MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id); |
| 22 | |
| 23 | /** |
| 24 | * zfcp_ccw_priv_sch - check if subchannel is privileged |
| 25 | * @adapter: Adapter/Subchannel to check |
| 26 | */ |
| 27 | int zfcp_ccw_priv_sch(struct zfcp_adapter *adapter) |
| 28 | { |
| 29 | return adapter->ccw_device->id.dev_model == ZFCP_MODEL_PRIV; |
| 30 | } |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | /** |
| 33 | * zfcp_ccw_probe - probe function of zfcp driver |
| 34 | * @ccw_device: pointer to belonging ccw device |
| 35 | * |
| 36 | * This function gets called by the common i/o layer and sets up the initial |
| 37 | * data structures for each fcp adapter, which was detected by the system. |
| 38 | * Also the sysfs files for this adapter will be created by this function. |
| 39 | * In addition the nameserver port will be added to the ports of the adapter |
| 40 | * and its sysfs representation will be created too. |
| 41 | */ |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 42 | static int zfcp_ccw_probe(struct ccw_device *ccw_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | int retval = 0; |
| 45 | |
| 46 | down(&zfcp_data.config_sema); |
Swen Schillig | 317e6b6 | 2008-07-02 10:56:37 +0200 | [diff] [blame] | 47 | if (zfcp_adapter_enqueue(ccw_device)) { |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 48 | dev_err(&ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 49 | "Setting up data structures for the " |
| 50 | "FCP adapter failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | retval = -EINVAL; |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 52 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | up(&zfcp_data.config_sema); |
| 54 | return retval; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * zfcp_ccw_remove - remove function of zfcp driver |
| 59 | * @ccw_device: pointer to belonging ccw device |
| 60 | * |
| 61 | * This function gets called by the common i/o layer and removes an adapter |
| 62 | * from the system. Task of this function is to get rid of all units and |
| 63 | * ports that belong to this adapter. And in addition all resources of this |
| 64 | * adapter will be freed too. |
| 65 | */ |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 66 | static void zfcp_ccw_remove(struct ccw_device *ccw_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | struct zfcp_adapter *adapter; |
| 69 | struct zfcp_port *port, *p; |
| 70 | struct zfcp_unit *unit, *u; |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 71 | LIST_HEAD(unit_remove_lh); |
| 72 | LIST_HEAD(port_remove_lh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | ccw_device_set_offline(ccw_device); |
| 75 | down(&zfcp_data.config_sema); |
| 76 | adapter = dev_get_drvdata(&ccw_device->dev); |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | write_lock_irq(&zfcp_data.config_lock); |
| 79 | list_for_each_entry_safe(port, p, &adapter->port_list_head, list) { |
| 80 | list_for_each_entry_safe(unit, u, &port->unit_list_head, list) { |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 81 | list_move(&unit->list, &unit_remove_lh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, |
| 83 | &unit->status); |
| 84 | } |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 85 | list_move(&port->list, &port_remove_lh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); |
| 87 | } |
| 88 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); |
| 89 | write_unlock_irq(&zfcp_data.config_lock); |
| 90 | |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 91 | list_for_each_entry_safe(port, p, &port_remove_lh, list) { |
| 92 | list_for_each_entry_safe(unit, u, &unit_remove_lh, list) { |
Christof Schmitt | 86f8a1b | 2009-03-02 13:08:55 +0100 | [diff] [blame] | 93 | if (unit->device) |
Christof Schmitt | e39c887 | 2007-11-05 12:37:46 +0100 | [diff] [blame] | 94 | scsi_remove_device(unit->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | zfcp_unit_dequeue(unit); |
| 96 | } |
| 97 | zfcp_port_dequeue(port); |
| 98 | } |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 99 | wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | zfcp_adapter_dequeue(adapter); |
| 101 | |
| 102 | up(&zfcp_data.config_sema); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * zfcp_ccw_set_online - set_online function of zfcp driver |
| 107 | * @ccw_device: pointer to belonging ccw device |
| 108 | * |
| 109 | * This function gets called by the common i/o layer and sets an adapter |
| 110 | * into state online. Setting an fcp device online means that it will be |
| 111 | * registered with the SCSI stack, that the QDIO queues will be set up |
| 112 | * and that the adapter will be opened (asynchronously). |
| 113 | */ |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 114 | static int zfcp_ccw_set_online(struct ccw_device *ccw_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | struct zfcp_adapter *adapter; |
| 117 | int retval; |
| 118 | |
| 119 | down(&zfcp_data.config_sema); |
| 120 | adapter = dev_get_drvdata(&ccw_device->dev); |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | retval = zfcp_erp_thread_setup(adapter); |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 123 | if (retval) |
Christof Schmitt | ff17a29 | 2007-08-28 09:31:41 +0200 | [diff] [blame] | 124 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 126 | /* initialize request counter */ |
| 127 | BUG_ON(!zfcp_reqlist_isempty(adapter)); |
| 128 | adapter->req_no = 0; |
| 129 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 130 | zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL, |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 131 | ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 132 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
| 133 | "ccsonl2", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | zfcp_erp_wait(adapter); |
Christof Schmitt | 77fd949 | 2008-11-04 16:35:10 +0100 | [diff] [blame] | 135 | up(&zfcp_data.config_sema); |
| 136 | flush_work(&adapter->scan_work); |
| 137 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | out: |
| 140 | up(&zfcp_data.config_sema); |
| 141 | return retval; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * zfcp_ccw_set_offline - set_offline function of zfcp driver |
| 146 | * @ccw_device: pointer to belonging ccw device |
| 147 | * |
| 148 | * This function gets called by the common i/o layer and sets an adapter |
Michael Loehr | 9f28745 | 2007-05-09 11:01:24 +0200 | [diff] [blame] | 149 | * into state offline. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | */ |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 151 | static int zfcp_ccw_set_offline(struct ccw_device *ccw_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | struct zfcp_adapter *adapter; |
| 154 | |
| 155 | down(&zfcp_data.config_sema); |
| 156 | adapter = dev_get_drvdata(&ccw_device->dev); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 157 | zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | zfcp_erp_wait(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | zfcp_erp_thread_kill(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | up(&zfcp_data.config_sema); |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /** |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 165 | * zfcp_ccw_notify - ccw notify function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * @ccw_device: pointer to belonging ccw device |
| 167 | * @event: indicates if adapter was detached or attached |
| 168 | * |
| 169 | * This function gets called by the common i/o layer if an adapter has gone |
| 170 | * or reappeared. |
| 171 | */ |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 172 | static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Christof Schmitt | f48bf7f | 2008-08-21 13:43:34 +0200 | [diff] [blame] | 174 | struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | switch (event) { |
| 177 | case CIO_GONE: |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 178 | dev_warn(&adapter->ccw_device->dev, |
| 179 | "The FCP device has been detached\n"); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 180 | zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | break; |
| 182 | case CIO_NO_PATH: |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 183 | dev_warn(&adapter->ccw_device->dev, |
| 184 | "The CHPID for the FCP device is offline\n"); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 185 | zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | break; |
| 187 | case CIO_OPER: |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 188 | dev_info(&adapter->ccw_device->dev, |
| 189 | "The FCP device is operational again\n"); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 190 | zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | ZFCP_STATUS_COMMON_RUNNING, |
| 192 | ZFCP_SET); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 193 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 194 | "ccnoti4", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | break; |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 196 | case CIO_BOXED: |
Christof Schmitt | 955a215 | 2009-05-15 13:18:15 +0200 | [diff] [blame] | 197 | dev_warn(&adapter->ccw_device->dev, "The FCP device " |
| 198 | "did not respond within the specified time\n"); |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 199 | zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL); |
| 200 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | /** |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 206 | * zfcp_ccw_shutdown - handle shutdown from cio |
| 207 | * @cdev: device for adapter to shutdown. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | */ |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 209 | static void zfcp_ccw_shutdown(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | struct zfcp_adapter *adapter; |
| 212 | |
| 213 | down(&zfcp_data.config_sema); |
Cornelia Huck | 958974f | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 214 | adapter = dev_get_drvdata(&cdev->dev); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 215 | zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | zfcp_erp_wait(adapter); |
| 217 | up(&zfcp_data.config_sema); |
| 218 | } |
| 219 | |
Christof Schmitt | fa04c28 | 2008-06-10 18:20:56 +0200 | [diff] [blame] | 220 | static struct ccw_driver zfcp_ccw_driver = { |
| 221 | .owner = THIS_MODULE, |
| 222 | .name = "zfcp", |
| 223 | .ids = zfcp_ccw_device_id, |
| 224 | .probe = zfcp_ccw_probe, |
| 225 | .remove = zfcp_ccw_remove, |
| 226 | .set_online = zfcp_ccw_set_online, |
| 227 | .set_offline = zfcp_ccw_set_offline, |
| 228 | .notify = zfcp_ccw_notify, |
| 229 | .shutdown = zfcp_ccw_shutdown, |
| 230 | }; |
| 231 | |
| 232 | /** |
| 233 | * zfcp_ccw_register - ccw register function |
| 234 | * |
| 235 | * Registers the driver at the common i/o layer. This function will be called |
| 236 | * at module load time/system start. |
| 237 | */ |
| 238 | int __init zfcp_ccw_register(void) |
| 239 | { |
| 240 | return ccw_driver_register(&zfcp_ccw_driver); |
| 241 | } |
Swen Schillig | a1b449d | 2008-10-01 12:42:19 +0200 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * zfcp_get_adapter_by_busid - find zfcp_adapter struct |
| 245 | * @busid: bus id string of zfcp adapter to find |
| 246 | */ |
| 247 | struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid) |
| 248 | { |
| 249 | struct ccw_device *ccw_device; |
| 250 | struct zfcp_adapter *adapter = NULL; |
| 251 | |
| 252 | ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid); |
| 253 | if (ccw_device) { |
| 254 | adapter = dev_get_drvdata(&ccw_device->dev); |
| 255 | put_device(&ccw_device->dev); |
| 256 | } |
| 257 | return adapter; |
| 258 | } |