2 * linux/drivers/s390/scsi/zfcp_ccw.c
4 * FCP adapter driver for IBM eServer zSeries
6 * CCW driver related routines
8 * (C) Copyright IBM Corp. 2003, 2004
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define ZFCP_CCW_C_REVISION "$Revision: 1.55 $"
33 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35 static int zfcp_ccw_probe(struct ccw_device *);
36 static void zfcp_ccw_remove(struct ccw_device *);
37 static int zfcp_ccw_set_online(struct ccw_device *);
38 static int zfcp_ccw_set_offline(struct ccw_device *);
39 static int zfcp_ccw_notify(struct ccw_device *, int);
41 static struct ccw_device_id zfcp_ccw_device_id[] = {
42 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
43 ZFCP_CONTROL_UNIT_MODEL,
46 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
47 ZFCP_CONTROL_UNIT_MODEL,
49 ZFCP_DEVICE_MODEL_PRIV)},
53 static struct ccw_driver zfcp_ccw_driver = {
56 .ids = zfcp_ccw_device_id,
57 .probe = zfcp_ccw_probe,
58 .remove = zfcp_ccw_remove,
59 .set_online = zfcp_ccw_set_online,
60 .set_offline = zfcp_ccw_set_offline,
61 .notify = zfcp_ccw_notify,
64 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
67 * zfcp_ccw_probe - probe function of zfcp driver
68 * @ccw_device: pointer to belonging ccw device
70 * This function gets called by the common i/o layer and sets up the initial
71 * data structures for each fcp adapter, which was detected by the system.
72 * Also the sysfs files for this adapter will be created by this function.
73 * In addition the nameserver port will be added to the ports of the adapter
74 * and its sysfs representation will be created too.
77 zfcp_ccw_probe(struct ccw_device *ccw_device)
79 struct zfcp_adapter *adapter;
82 down(&zfcp_data.config_sema);
83 adapter = zfcp_adapter_enqueue(ccw_device);
87 ZFCP_LOG_DEBUG("Probed adapter %s\n",
88 zfcp_get_busid_by_adapter(adapter));
89 up(&zfcp_data.config_sema);
94 * zfcp_ccw_remove - remove function of zfcp driver
95 * @ccw_device: pointer to belonging ccw device
97 * This function gets called by the common i/o layer and removes an adapter
98 * from the system. Task of this function is to get rid of all units and
99 * ports that belong to this adapter. And in addition all resources of this
100 * adapter will be freed too.
103 zfcp_ccw_remove(struct ccw_device *ccw_device)
105 struct zfcp_adapter *adapter;
106 struct zfcp_port *port, *p;
107 struct zfcp_unit *unit, *u;
109 ccw_device_set_offline(ccw_device);
110 down(&zfcp_data.config_sema);
111 adapter = dev_get_drvdata(&ccw_device->dev);
113 ZFCP_LOG_DEBUG("Removing adapter %s\n",
114 zfcp_get_busid_by_adapter(adapter));
115 write_lock_irq(&zfcp_data.config_lock);
116 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
117 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
118 list_move(&unit->list, &port->unit_remove_lh);
119 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
122 list_move(&port->list, &adapter->port_remove_lh);
123 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
125 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
126 write_unlock_irq(&zfcp_data.config_lock);
128 list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
129 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
130 zfcp_unit_dequeue(unit);
132 zfcp_port_dequeue(port);
134 zfcp_adapter_wait(adapter);
135 zfcp_adapter_dequeue(adapter);
137 up(&zfcp_data.config_sema);
141 * zfcp_ccw_set_online - set_online function of zfcp driver
142 * @ccw_device: pointer to belonging ccw device
144 * This function gets called by the common i/o layer and sets an adapter
145 * into state online. Setting an fcp device online means that it will be
146 * registered with the SCSI stack, that the QDIO queues will be set up
147 * and that the adapter will be opened (asynchronously).
150 zfcp_ccw_set_online(struct ccw_device *ccw_device)
152 struct zfcp_adapter *adapter;
155 down(&zfcp_data.config_sema);
156 adapter = dev_get_drvdata(&ccw_device->dev);
158 retval = zfcp_adapter_debug_register(adapter);
161 retval = zfcp_erp_thread_setup(adapter);
163 ZFCP_LOG_INFO("error: start of error recovery thread for "
164 "adapter %s failed\n",
165 zfcp_get_busid_by_adapter(adapter));
169 retval = zfcp_adapter_scsi_register(adapter);
171 goto out_scsi_register;
172 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
174 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
175 zfcp_erp_wait(adapter);
179 zfcp_erp_thread_kill(adapter);
181 zfcp_adapter_debug_unregister(adapter);
183 up(&zfcp_data.config_sema);
188 * zfcp_ccw_set_offline - set_offline function of zfcp driver
189 * @ccw_device: pointer to belonging ccw device
191 * This function gets called by the common i/o layer and sets an adapter
192 * into state offline. Setting an fcp device offline means that it will be
193 * unregistered from the SCSI stack and that the adapter will be shut down
197 zfcp_ccw_set_offline(struct ccw_device *ccw_device)
199 struct zfcp_adapter *adapter;
201 down(&zfcp_data.config_sema);
202 adapter = dev_get_drvdata(&ccw_device->dev);
203 zfcp_erp_adapter_shutdown(adapter, 0);
204 zfcp_erp_wait(adapter);
205 zfcp_adapter_scsi_unregister(adapter);
206 zfcp_erp_thread_kill(adapter);
207 zfcp_adapter_debug_unregister(adapter);
208 up(&zfcp_data.config_sema);
214 * @ccw_device: pointer to belonging ccw device
215 * @event: indicates if adapter was detached or attached
217 * This function gets called by the common i/o layer if an adapter has gone
221 zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
223 struct zfcp_adapter *adapter;
225 down(&zfcp_data.config_sema);
226 adapter = dev_get_drvdata(&ccw_device->dev);
229 ZFCP_LOG_NORMAL("adapter %s: device gone\n",
230 zfcp_get_busid_by_adapter(adapter));
231 debug_text_event(adapter->erp_dbf,1,"dev_gone");
232 zfcp_erp_adapter_shutdown(adapter, 0);
235 ZFCP_LOG_NORMAL("adapter %s: no path\n",
236 zfcp_get_busid_by_adapter(adapter));
237 debug_text_event(adapter->erp_dbf,1,"no_path");
238 zfcp_erp_adapter_shutdown(adapter, 0);
241 ZFCP_LOG_NORMAL("adapter %s: operational again\n",
242 zfcp_get_busid_by_adapter(adapter));
243 debug_text_event(adapter->erp_dbf,1,"dev_oper");
244 zfcp_erp_modify_adapter_status(adapter,
245 ZFCP_STATUS_COMMON_RUNNING,
247 zfcp_erp_adapter_reopen(adapter,
248 ZFCP_STATUS_COMMON_ERP_FAILED);
251 zfcp_erp_wait(adapter);
252 up(&zfcp_data.config_sema);
257 * zfcp_ccw_register - ccw register function
259 * Registers the driver at the common i/o layer. This function will be called
260 * at module load time/system start.
263 zfcp_ccw_register(void)
267 retval = ccw_driver_register(&zfcp_ccw_driver);
270 retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
272 ccw_driver_unregister(&zfcp_ccw_driver);
278 * zfcp_ccw_unregister - ccw unregister function
280 * Unregisters the driver from common i/o layer. Function will be called at
281 * module unload/system shutdown.
284 zfcp_ccw_unregister(void)
286 zfcp_sysfs_driver_remove_files(&zfcp_ccw_driver.driver);
287 ccw_driver_unregister(&zfcp_ccw_driver);