[SCSI] mpt fusion: removing Dell copyright
[linux-2.6] / drivers / s390 / scsi / zfcp_ccw.c
1 /*
2  * This file is part of the zfcp device driver for
3  * FCP adapters for IBM System z9 and zSeries.
4  *
5  * (C) Copyright IBM Corp. 2002, 2006
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
20  */
21
22 #include "zfcp_ext.h"
23
24 #define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_CONFIG
25
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 device *);
32
33 static struct ccw_device_id zfcp_ccw_device_id[] = {
34         {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
35                             ZFCP_CONTROL_UNIT_MODEL,
36                             ZFCP_DEVICE_TYPE,
37                             ZFCP_DEVICE_MODEL)},
38         {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
39                             ZFCP_CONTROL_UNIT_MODEL,
40                             ZFCP_DEVICE_TYPE,
41                             ZFCP_DEVICE_MODEL_PRIV)},
42         {},
43 };
44
45 static struct ccw_driver zfcp_ccw_driver = {
46         .owner       = THIS_MODULE,
47         .name        = ZFCP_NAME,
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         .driver      = {
55                 .shutdown = zfcp_ccw_shutdown,
56         },
57 };
58
59 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
60
61 /**
62  * zfcp_ccw_probe - probe function of zfcp driver
63  * @ccw_device: pointer to belonging ccw device
64  *
65  * This function gets called by the common i/o layer and sets up the initial
66  * data structures for each fcp adapter, which was detected by the system.
67  * Also the sysfs files for this adapter will be created by this function.
68  * In addition the nameserver port will be added to the ports of the adapter
69  * and its sysfs representation will be created too.
70  */
71 static int
72 zfcp_ccw_probe(struct ccw_device *ccw_device)
73 {
74         struct zfcp_adapter *adapter;
75         int retval = 0;
76
77         down(&zfcp_data.config_sema);
78         adapter = zfcp_adapter_enqueue(ccw_device);
79         if (!adapter)
80                 retval = -EINVAL;
81         else
82                 ZFCP_LOG_DEBUG("Probed adapter %s\n",
83                                zfcp_get_busid_by_adapter(adapter));
84         up(&zfcp_data.config_sema);
85         return retval;
86 }
87
88 /**
89  * zfcp_ccw_remove - remove function of zfcp driver
90  * @ccw_device: pointer to belonging ccw device
91  *
92  * This function gets called by the common i/o layer and removes an adapter
93  * from the system. Task of this function is to get rid of all units and
94  * ports that belong to this adapter. And in addition all resources of this
95  * adapter will be freed too.
96  */
97 static void
98 zfcp_ccw_remove(struct ccw_device *ccw_device)
99 {
100         struct zfcp_adapter *adapter;
101         struct zfcp_port *port, *p;
102         struct zfcp_unit *unit, *u;
103
104         ccw_device_set_offline(ccw_device);
105         down(&zfcp_data.config_sema);
106         adapter = dev_get_drvdata(&ccw_device->dev);
107
108         ZFCP_LOG_DEBUG("Removing adapter %s\n",
109                        zfcp_get_busid_by_adapter(adapter));
110         write_lock_irq(&zfcp_data.config_lock);
111         list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
112                 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
113                         list_move(&unit->list, &port->unit_remove_lh);
114                         atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
115                                         &unit->status);
116                 }
117                 list_move(&port->list, &adapter->port_remove_lh);
118                 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
119         }
120         atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
121         write_unlock_irq(&zfcp_data.config_lock);
122
123         list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
124                 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
125                         zfcp_unit_dequeue(unit);
126                 }
127                 zfcp_port_dequeue(port);
128         }
129         zfcp_adapter_wait(adapter);
130         zfcp_adapter_dequeue(adapter);
131
132         up(&zfcp_data.config_sema);
133 }
134
135 /**
136  * zfcp_ccw_set_online - set_online function of zfcp driver
137  * @ccw_device: pointer to belonging ccw device
138  *
139  * This function gets called by the common i/o layer and sets an adapter
140  * into state online. Setting an fcp device online means that it will be
141  * registered with the SCSI stack, that the QDIO queues will be set up
142  * and that the adapter will be opened (asynchronously).
143  */
144 static int
145 zfcp_ccw_set_online(struct ccw_device *ccw_device)
146 {
147         struct zfcp_adapter *adapter;
148         int retval;
149
150         down(&zfcp_data.config_sema);
151         adapter = dev_get_drvdata(&ccw_device->dev);
152
153         retval = zfcp_erp_thread_setup(adapter);
154         if (retval) {
155                 ZFCP_LOG_INFO("error: start of error recovery thread for "
156                               "adapter %s failed\n",
157                               zfcp_get_busid_by_adapter(adapter));
158                 goto out;
159         }
160
161         retval = zfcp_adapter_scsi_register(adapter);
162         if (retval)
163                 goto out_scsi_register;
164
165         /* initialize request counter */
166         BUG_ON(!zfcp_reqlist_isempty(adapter));
167         adapter->req_no = 0;
168
169         zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
170                                        ZFCP_SET);
171         zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
172         zfcp_erp_wait(adapter);
173         goto out;
174
175  out_scsi_register:
176         zfcp_erp_thread_kill(adapter);
177  out:
178         up(&zfcp_data.config_sema);
179         return retval;
180 }
181
182 /**
183  * zfcp_ccw_set_offline - set_offline function of zfcp driver
184  * @ccw_device: pointer to belonging ccw device
185  *
186  * This function gets called by the common i/o layer and sets an adapter
187  * into state offline.
188  */
189 static int
190 zfcp_ccw_set_offline(struct ccw_device *ccw_device)
191 {
192         struct zfcp_adapter *adapter;
193
194         down(&zfcp_data.config_sema);
195         adapter = dev_get_drvdata(&ccw_device->dev);
196         zfcp_erp_adapter_shutdown(adapter, 0);
197         zfcp_erp_wait(adapter);
198         zfcp_erp_thread_kill(adapter);
199         up(&zfcp_data.config_sema);
200         return 0;
201 }
202
203 /**
204  * zfcp_ccw_notify
205  * @ccw_device: pointer to belonging ccw device
206  * @event: indicates if adapter was detached or attached
207  *
208  * This function gets called by the common i/o layer if an adapter has gone
209  * or reappeared.
210  */
211 static int
212 zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
213 {
214         struct zfcp_adapter *adapter;
215
216         down(&zfcp_data.config_sema);
217         adapter = dev_get_drvdata(&ccw_device->dev);
218         switch (event) {
219         case CIO_GONE:
220                 ZFCP_LOG_NORMAL("adapter %s: device gone\n",
221                                 zfcp_get_busid_by_adapter(adapter));
222                 debug_text_event(adapter->erp_dbf,1,"dev_gone");
223                 zfcp_erp_adapter_shutdown(adapter, 0);
224                 break;
225         case CIO_NO_PATH:
226                 ZFCP_LOG_NORMAL("adapter %s: no path\n",
227                                 zfcp_get_busid_by_adapter(adapter));
228                 debug_text_event(adapter->erp_dbf,1,"no_path");
229                 zfcp_erp_adapter_shutdown(adapter, 0);
230                 break;
231         case CIO_OPER:
232                 ZFCP_LOG_NORMAL("adapter %s: operational again\n",
233                                 zfcp_get_busid_by_adapter(adapter));
234                 debug_text_event(adapter->erp_dbf,1,"dev_oper");
235                 zfcp_erp_modify_adapter_status(adapter,
236                                                ZFCP_STATUS_COMMON_RUNNING,
237                                                ZFCP_SET);
238                 zfcp_erp_adapter_reopen(adapter,
239                                         ZFCP_STATUS_COMMON_ERP_FAILED);
240                 break;
241         }
242         zfcp_erp_wait(adapter);
243         up(&zfcp_data.config_sema);
244         return 1;
245 }
246
247 /**
248  * zfcp_ccw_register - ccw register function
249  *
250  * Registers the driver at the common i/o layer. This function will be called
251  * at module load time/system start.
252  */
253 int __init
254 zfcp_ccw_register(void)
255 {
256         int retval;
257
258         retval = ccw_driver_register(&zfcp_ccw_driver);
259         if (retval)
260                 goto out;
261         retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
262         if (retval)
263                 ccw_driver_unregister(&zfcp_ccw_driver);
264  out:
265         return retval;
266 }
267
268 /**
269  * zfcp_ccw_shutdown - gets called on reboot/shutdown
270  *
271  * Makes sure that QDIO queues are down when the system gets stopped.
272  */
273 static void
274 zfcp_ccw_shutdown(struct device *dev)
275 {
276         struct zfcp_adapter *adapter;
277
278         down(&zfcp_data.config_sema);
279         adapter = dev_get_drvdata(dev);
280         zfcp_erp_adapter_shutdown(adapter, 0);
281         zfcp_erp_wait(adapter);
282         up(&zfcp_data.config_sema);
283 }
284
285 #undef ZFCP_LOG_AREA