2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
26 static int zfcp_ccw_probe(struct ccw_device *);
27 static void zfcp_ccw_remove(struct ccw_device *);
28 static int zfcp_ccw_set_online(struct ccw_device *);
29 static int zfcp_ccw_set_offline(struct ccw_device *);
30 static int zfcp_ccw_notify(struct ccw_device *, int);
31 static void zfcp_ccw_shutdown(struct ccw_device *);
33 static struct ccw_device_id zfcp_ccw_device_id[] = {
34 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
35 ZFCP_CONTROL_UNIT_MODEL,
38 {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
39 ZFCP_CONTROL_UNIT_MODEL,
41 ZFCP_DEVICE_MODEL_PRIV)},
45 static struct ccw_driver zfcp_ccw_driver = {
48 .ids = zfcp_ccw_device_id,
49 .probe = zfcp_ccw_probe,
50 .remove = zfcp_ccw_remove,
51 .set_online = zfcp_ccw_set_online,
52 .set_offline = zfcp_ccw_set_offline,
53 .notify = zfcp_ccw_notify,
54 .shutdown = zfcp_ccw_shutdown,
57 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
60 * zfcp_ccw_probe - probe function of zfcp driver
61 * @ccw_device: pointer to belonging ccw device
63 * This function gets called by the common i/o layer and sets up the initial
64 * data structures for each fcp adapter, which was detected by the system.
65 * Also the sysfs files for this adapter will be created by this function.
66 * In addition the nameserver port will be added to the ports of the adapter
67 * and its sysfs representation will be created too.
70 zfcp_ccw_probe(struct ccw_device *ccw_device)
72 struct zfcp_adapter *adapter;
75 down(&zfcp_data.config_sema);
76 adapter = zfcp_adapter_enqueue(ccw_device);
80 ZFCP_LOG_DEBUG("Probed adapter %s\n",
81 zfcp_get_busid_by_adapter(adapter));
82 up(&zfcp_data.config_sema);
87 * zfcp_ccw_remove - remove function of zfcp driver
88 * @ccw_device: pointer to belonging ccw device
90 * This function gets called by the common i/o layer and removes an adapter
91 * from the system. Task of this function is to get rid of all units and
92 * ports that belong to this adapter. And in addition all resources of this
93 * adapter will be freed too.
96 zfcp_ccw_remove(struct ccw_device *ccw_device)
98 struct zfcp_adapter *adapter;
99 struct zfcp_port *port, *p;
100 struct zfcp_unit *unit, *u;
102 ccw_device_set_offline(ccw_device);
103 down(&zfcp_data.config_sema);
104 adapter = dev_get_drvdata(&ccw_device->dev);
106 ZFCP_LOG_DEBUG("Removing adapter %s\n",
107 zfcp_get_busid_by_adapter(adapter));
108 write_lock_irq(&zfcp_data.config_lock);
109 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
110 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
111 list_move(&unit->list, &port->unit_remove_lh);
112 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
115 list_move(&port->list, &adapter->port_remove_lh);
116 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
118 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
119 write_unlock_irq(&zfcp_data.config_lock);
121 list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
122 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
123 zfcp_unit_dequeue(unit);
125 zfcp_port_dequeue(port);
127 zfcp_adapter_wait(adapter);
128 zfcp_adapter_dequeue(adapter);
130 up(&zfcp_data.config_sema);
134 * zfcp_ccw_set_online - set_online function of zfcp driver
135 * @ccw_device: pointer to belonging ccw device
137 * This function gets called by the common i/o layer and sets an adapter
138 * into state online. Setting an fcp device online means that it will be
139 * registered with the SCSI stack, that the QDIO queues will be set up
140 * and that the adapter will be opened (asynchronously).
143 zfcp_ccw_set_online(struct ccw_device *ccw_device)
145 struct zfcp_adapter *adapter;
148 down(&zfcp_data.config_sema);
149 adapter = dev_get_drvdata(&ccw_device->dev);
151 retval = zfcp_erp_thread_setup(adapter);
153 ZFCP_LOG_INFO("error: start of error recovery thread for "
154 "adapter %s failed\n",
155 zfcp_get_busid_by_adapter(adapter));
159 retval = zfcp_adapter_scsi_register(adapter);
161 goto out_scsi_register;
163 /* initialize request counter */
164 BUG_ON(!zfcp_reqlist_isempty(adapter));
167 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
169 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
170 zfcp_erp_wait(adapter);
174 zfcp_erp_thread_kill(adapter);
176 up(&zfcp_data.config_sema);
181 * zfcp_ccw_set_offline - set_offline function of zfcp driver
182 * @ccw_device: pointer to belonging ccw device
184 * This function gets called by the common i/o layer and sets an adapter
185 * into state offline.
188 zfcp_ccw_set_offline(struct ccw_device *ccw_device)
190 struct zfcp_adapter *adapter;
192 down(&zfcp_data.config_sema);
193 adapter = dev_get_drvdata(&ccw_device->dev);
194 zfcp_erp_adapter_shutdown(adapter, 0);
195 zfcp_erp_wait(adapter);
196 zfcp_erp_thread_kill(adapter);
197 up(&zfcp_data.config_sema);
203 * @ccw_device: pointer to belonging ccw device
204 * @event: indicates if adapter was detached or attached
206 * This function gets called by the common i/o layer if an adapter has gone
210 zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
212 struct zfcp_adapter *adapter;
214 down(&zfcp_data.config_sema);
215 adapter = dev_get_drvdata(&ccw_device->dev);
218 ZFCP_LOG_NORMAL("adapter %s: device gone\n",
219 zfcp_get_busid_by_adapter(adapter));
220 debug_text_event(adapter->erp_dbf,1,"dev_gone");
221 zfcp_erp_adapter_shutdown(adapter, 0);
224 ZFCP_LOG_NORMAL("adapter %s: no path\n",
225 zfcp_get_busid_by_adapter(adapter));
226 debug_text_event(adapter->erp_dbf,1,"no_path");
227 zfcp_erp_adapter_shutdown(adapter, 0);
230 ZFCP_LOG_NORMAL("adapter %s: operational again\n",
231 zfcp_get_busid_by_adapter(adapter));
232 debug_text_event(adapter->erp_dbf,1,"dev_oper");
233 zfcp_erp_modify_adapter_status(adapter,
234 ZFCP_STATUS_COMMON_RUNNING,
236 zfcp_erp_adapter_reopen(adapter,
237 ZFCP_STATUS_COMMON_ERP_FAILED);
240 zfcp_erp_wait(adapter);
241 up(&zfcp_data.config_sema);
246 * zfcp_ccw_register - ccw register function
248 * Registers the driver at the common i/o layer. This function will be called
249 * at module load time/system start.
252 zfcp_ccw_register(void)
256 retval = ccw_driver_register(&zfcp_ccw_driver);
259 retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
261 ccw_driver_unregister(&zfcp_ccw_driver);
267 * zfcp_ccw_shutdown - gets called on reboot/shutdown
269 * Makes sure that QDIO queues are down when the system gets stopped.
272 zfcp_ccw_shutdown(struct ccw_device *cdev)
274 struct zfcp_adapter *adapter;
276 down(&zfcp_data.config_sema);
277 adapter = dev_get_drvdata(&cdev->dev);
278 zfcp_erp_adapter_shutdown(adapter, 0);
279 zfcp_erp_wait(adapter);
280 up(&zfcp_data.config_sema);