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