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