initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / s390 / scsi / zfcp_ccw.c
blob001d8067ca95903ecd3ff94863ae632f2b95ca61
1 /*
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
10 * Authors:
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)
17 * any later version.
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.56 $"
31 #include "zfcp_ext.h"
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);
40 static void zfcp_ccw_shutdown(struct device *);
42 static struct ccw_device_id zfcp_ccw_device_id[] = {
43 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
44 ZFCP_CONTROL_UNIT_MODEL,
45 ZFCP_DEVICE_TYPE,
46 ZFCP_DEVICE_MODEL)},
47 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
48 ZFCP_CONTROL_UNIT_MODEL,
49 ZFCP_DEVICE_TYPE,
50 ZFCP_DEVICE_MODEL_PRIV)},
51 {},
54 static struct ccw_driver zfcp_ccw_driver = {
55 .owner = THIS_MODULE,
56 .name = ZFCP_NAME,
57 .ids = zfcp_ccw_device_id,
58 .probe = zfcp_ccw_probe,
59 .remove = zfcp_ccw_remove,
60 .set_online = zfcp_ccw_set_online,
61 .set_offline = zfcp_ccw_set_offline,
62 .notify = zfcp_ccw_notify,
63 .driver = {
64 .shutdown = zfcp_ccw_shutdown,
68 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
70 /**
71 * zfcp_ccw_probe - probe function of zfcp driver
72 * @ccw_device: pointer to belonging ccw device
74 * This function gets called by the common i/o layer and sets up the initial
75 * data structures for each fcp adapter, which was detected by the system.
76 * Also the sysfs files for this adapter will be created by this function.
77 * In addition the nameserver port will be added to the ports of the adapter
78 * and its sysfs representation will be created too.
80 static int
81 zfcp_ccw_probe(struct ccw_device *ccw_device)
83 struct zfcp_adapter *adapter;
84 int retval = 0;
86 down(&zfcp_data.config_sema);
87 adapter = zfcp_adapter_enqueue(ccw_device);
88 if (!adapter)
89 retval = -EINVAL;
90 else
91 ZFCP_LOG_DEBUG("Probed adapter %s\n",
92 zfcp_get_busid_by_adapter(adapter));
93 up(&zfcp_data.config_sema);
94 return retval;
97 /**
98 * zfcp_ccw_remove - remove function of zfcp driver
99 * @ccw_device: pointer to belonging ccw device
101 * This function gets called by the common i/o layer and removes an adapter
102 * from the system. Task of this function is to get rid of all units and
103 * ports that belong to this adapter. And in addition all resources of this
104 * adapter will be freed too.
106 static void
107 zfcp_ccw_remove(struct ccw_device *ccw_device)
109 struct zfcp_adapter *adapter;
110 struct zfcp_port *port, *p;
111 struct zfcp_unit *unit, *u;
113 ccw_device_set_offline(ccw_device);
114 down(&zfcp_data.config_sema);
115 adapter = dev_get_drvdata(&ccw_device->dev);
117 ZFCP_LOG_DEBUG("Removing adapter %s\n",
118 zfcp_get_busid_by_adapter(adapter));
119 write_lock_irq(&zfcp_data.config_lock);
120 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
121 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
122 list_move(&unit->list, &port->unit_remove_lh);
123 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
124 &unit->status);
126 list_move(&port->list, &adapter->port_remove_lh);
127 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
129 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
130 write_unlock_irq(&zfcp_data.config_lock);
132 list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
133 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
134 zfcp_unit_dequeue(unit);
136 zfcp_port_dequeue(port);
138 zfcp_adapter_wait(adapter);
139 zfcp_adapter_dequeue(adapter);
141 up(&zfcp_data.config_sema);
145 * zfcp_ccw_set_online - set_online function of zfcp driver
146 * @ccw_device: pointer to belonging ccw device
148 * This function gets called by the common i/o layer and sets an adapter
149 * into state online. Setting an fcp device online means that it will be
150 * registered with the SCSI stack, that the QDIO queues will be set up
151 * and that the adapter will be opened (asynchronously).
153 static int
154 zfcp_ccw_set_online(struct ccw_device *ccw_device)
156 struct zfcp_adapter *adapter;
157 int retval;
159 down(&zfcp_data.config_sema);
160 adapter = dev_get_drvdata(&ccw_device->dev);
162 retval = zfcp_adapter_debug_register(adapter);
163 if (retval)
164 goto out;
165 retval = zfcp_erp_thread_setup(adapter);
166 if (retval) {
167 ZFCP_LOG_INFO("error: start of error recovery thread for "
168 "adapter %s failed\n",
169 zfcp_get_busid_by_adapter(adapter));
170 goto out_erp_thread;
173 retval = zfcp_adapter_scsi_register(adapter);
174 if (retval)
175 goto out_scsi_register;
176 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
177 ZFCP_SET);
178 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
179 zfcp_erp_wait(adapter);
180 goto out;
182 out_scsi_register:
183 zfcp_erp_thread_kill(adapter);
184 out_erp_thread:
185 zfcp_adapter_debug_unregister(adapter);
186 out:
187 up(&zfcp_data.config_sema);
188 return retval;
192 * zfcp_ccw_set_offline - set_offline function of zfcp driver
193 * @ccw_device: pointer to belonging ccw device
195 * This function gets called by the common i/o layer and sets an adapter
196 * into state offline. Setting an fcp device offline means that it will be
197 * unregistered from the SCSI stack and that the adapter will be shut down
198 * asynchronously.
200 static int
201 zfcp_ccw_set_offline(struct ccw_device *ccw_device)
203 struct zfcp_adapter *adapter;
205 down(&zfcp_data.config_sema);
206 adapter = dev_get_drvdata(&ccw_device->dev);
207 zfcp_erp_adapter_shutdown(adapter, 0);
208 zfcp_erp_wait(adapter);
209 zfcp_adapter_scsi_unregister(adapter);
210 zfcp_erp_thread_kill(adapter);
211 zfcp_adapter_debug_unregister(adapter);
212 up(&zfcp_data.config_sema);
213 return 0;
217 * zfcp_ccw_notify
218 * @ccw_device: pointer to belonging ccw device
219 * @event: indicates if adapter was detached or attached
221 * This function gets called by the common i/o layer if an adapter has gone
222 * or reappeared.
224 static int
225 zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
227 struct zfcp_adapter *adapter;
229 down(&zfcp_data.config_sema);
230 adapter = dev_get_drvdata(&ccw_device->dev);
231 switch (event) {
232 case CIO_GONE:
233 ZFCP_LOG_NORMAL("adapter %s: device gone\n",
234 zfcp_get_busid_by_adapter(adapter));
235 debug_text_event(adapter->erp_dbf,1,"dev_gone");
236 zfcp_erp_adapter_shutdown(adapter, 0);
237 break;
238 case CIO_NO_PATH:
239 ZFCP_LOG_NORMAL("adapter %s: no path\n",
240 zfcp_get_busid_by_adapter(adapter));
241 debug_text_event(adapter->erp_dbf,1,"no_path");
242 zfcp_erp_adapter_shutdown(adapter, 0);
243 break;
244 case CIO_OPER:
245 ZFCP_LOG_NORMAL("adapter %s: operational again\n",
246 zfcp_get_busid_by_adapter(adapter));
247 debug_text_event(adapter->erp_dbf,1,"dev_oper");
248 zfcp_erp_modify_adapter_status(adapter,
249 ZFCP_STATUS_COMMON_RUNNING,
250 ZFCP_SET);
251 zfcp_erp_adapter_reopen(adapter,
252 ZFCP_STATUS_COMMON_ERP_FAILED);
253 break;
255 zfcp_erp_wait(adapter);
256 up(&zfcp_data.config_sema);
257 return 1;
261 * zfcp_ccw_register - ccw register function
263 * Registers the driver at the common i/o layer. This function will be called
264 * at module load time/system start.
266 int __init
267 zfcp_ccw_register(void)
269 int retval;
271 retval = ccw_driver_register(&zfcp_ccw_driver);
272 if (retval)
273 goto out;
274 retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
275 if (retval)
276 ccw_driver_unregister(&zfcp_ccw_driver);
277 out:
278 return retval;
282 * zfcp_ccw_unregister - ccw unregister function
284 * Unregisters the driver from common i/o layer. Function will be called at
285 * module unload/system shutdown.
287 void __exit
288 zfcp_ccw_unregister(void)
290 zfcp_sysfs_driver_remove_files(&zfcp_ccw_driver.driver);
291 ccw_driver_unregister(&zfcp_ccw_driver);
295 * zfcp_ccw_shutdown - gets called on reboot/shutdown
297 * Makes sure that QDIO queues are down when the system gets stopped.
299 static void
300 zfcp_ccw_shutdown(struct device *dev)
302 struct zfcp_adapter *adapter;
304 adapter = dev_get_drvdata(dev);
305 zfcp_erp_adapter_shutdown(adapter, 0);
306 zfcp_erp_wait(adapter);
309 #undef ZFCP_LOG_AREA