blob: d9da5c42ccbe6ca617bf4f304f0f9ecb1c058ef2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Christof Schmittfa04c282008-06-10 18:20:56 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmittfa04c282008-06-10 18:20:56 +02004 * Registration and callback for the s390 common I/O layer.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Swen Schillig6d1a27f2009-03-02 13:09:11 +01006 * Copyright IBM Corporation 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "zfcp_ext.h"
13
Christof Schmitt6fcf41d2009-05-15 13:18:21 +020014#define ZFCP_MODEL_PRIV 0x4
15
Martin Petermanndaa70fa2009-06-16 10:30:34 +020016static int zfcp_ccw_suspend(struct ccw_device *cdev)
17
18{
19 struct zfcp_adapter *adapter = dev_get_drvdata(&cdev->dev);
20
21 down(&zfcp_data.config_sema);
22
23 zfcp_erp_adapter_shutdown(adapter, 0, "ccsusp1", NULL);
24 zfcp_erp_wait(adapter);
25
26 up(&zfcp_data.config_sema);
27
28 return 0;
29}
30
31static int zfcp_ccw_activate(struct ccw_device *cdev)
32
33{
34 struct zfcp_adapter *adapter = dev_get_drvdata(&cdev->dev);
35
36 zfcp_erp_modify_adapter_status(adapter, "ccresu1", NULL,
37 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
38 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
39 "ccresu2", NULL);
40 zfcp_erp_wait(adapter);
41 flush_work(&adapter->scan_work);
42
43 return 0;
44}
45
Christof Schmitt6fcf41d2009-05-15 13:18:21 +020046static struct ccw_device_id zfcp_ccw_device_id[] = {
47 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
48 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, ZFCP_MODEL_PRIV) },
49 {},
50};
51MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
52
53/**
54 * zfcp_ccw_priv_sch - check if subchannel is privileged
55 * @adapter: Adapter/Subchannel to check
56 */
57int zfcp_ccw_priv_sch(struct zfcp_adapter *adapter)
58{
59 return adapter->ccw_device->id.dev_model == ZFCP_MODEL_PRIV;
60}
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/**
63 * zfcp_ccw_probe - probe function of zfcp driver
64 * @ccw_device: pointer to belonging ccw device
65 *
66 * This function gets called by the common i/o layer and sets up the initial
67 * data structures for each fcp adapter, which was detected by the system.
68 * Also the sysfs files for this adapter will be created by this function.
69 * In addition the nameserver port will be added to the ports of the adapter
70 * and its sysfs representation will be created too.
71 */
Christof Schmittfa04c282008-06-10 18:20:56 +020072static int zfcp_ccw_probe(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 int retval = 0;
75
76 down(&zfcp_data.config_sema);
Swen Schillig317e6b62008-07-02 10:56:37 +020077 if (zfcp_adapter_enqueue(ccw_device)) {
Christof Schmittfa04c282008-06-10 18:20:56 +020078 dev_err(&ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020079 "Setting up data structures for the "
80 "FCP adapter failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 retval = -EINVAL;
Christof Schmittfa04c282008-06-10 18:20:56 +020082 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 up(&zfcp_data.config_sema);
84 return retval;
85}
86
87/**
88 * zfcp_ccw_remove - remove function of zfcp driver
89 * @ccw_device: pointer to belonging ccw device
90 *
91 * This function gets called by the common i/o layer and removes an adapter
92 * from the system. Task of this function is to get rid of all units and
93 * ports that belong to this adapter. And in addition all resources of this
94 * adapter will be freed too.
95 */
Christof Schmittfa04c282008-06-10 18:20:56 +020096static void zfcp_ccw_remove(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 struct zfcp_adapter *adapter;
99 struct zfcp_port *port, *p;
100 struct zfcp_unit *unit, *u;
Christof Schmitt04062892008-10-01 12:42:20 +0200101 LIST_HEAD(unit_remove_lh);
102 LIST_HEAD(port_remove_lh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 ccw_device_set_offline(ccw_device);
105 down(&zfcp_data.config_sema);
106 adapter = dev_get_drvdata(&ccw_device->dev);
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 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) {
Christof Schmitt04062892008-10-01 12:42:20 +0200111 list_move(&unit->list, &unit_remove_lh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
113 &unit->status);
114 }
Christof Schmitt04062892008-10-01 12:42:20 +0200115 list_move(&port->list, &port_remove_lh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
117 }
118 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
119 write_unlock_irq(&zfcp_data.config_lock);
120
Christof Schmitt04062892008-10-01 12:42:20 +0200121 list_for_each_entry_safe(port, p, &port_remove_lh, list) {
122 list_for_each_entry_safe(unit, u, &unit_remove_lh, list) {
Christof Schmitt86f8a1b2009-03-02 13:08:55 +0100123 if (unit->device)
Christof Schmitte39c8872007-11-05 12:37:46 +0100124 scsi_remove_device(unit->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 zfcp_unit_dequeue(unit);
126 }
127 zfcp_port_dequeue(port);
128 }
Swen Schillig44cc76f2008-10-01 12:42:16 +0200129 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 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 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200144static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 struct zfcp_adapter *adapter;
147 int retval;
148
149 down(&zfcp_data.config_sema);
150 adapter = dev_get_drvdata(&ccw_device->dev);
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 retval = zfcp_erp_thread_setup(adapter);
Christof Schmittfa04c282008-06-10 18:20:56 +0200153 if (retval)
Christof Schmittff17a292007-08-28 09:31:41 +0200154 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200156 /* initialize request counter */
157 BUG_ON(!zfcp_reqlist_isempty(adapter));
158 adapter->req_no = 0;
159
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100160 zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
Martin Peschke698ec0162008-03-27 14:22:02 +0100161 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100162 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
163 "ccsonl2", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 zfcp_erp_wait(adapter);
Christof Schmitt77fd9492008-11-04 16:35:10 +0100165 up(&zfcp_data.config_sema);
166 flush_work(&adapter->scan_work);
167 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 out:
170 up(&zfcp_data.config_sema);
171 return retval;
172}
173
174/**
175 * zfcp_ccw_set_offline - set_offline function of zfcp driver
176 * @ccw_device: pointer to belonging ccw device
177 *
178 * This function gets called by the common i/o layer and sets an adapter
Michael Loehr9f287452007-05-09 11:01:24 +0200179 * into state offline.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200181static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
183 struct zfcp_adapter *adapter;
184
185 down(&zfcp_data.config_sema);
186 adapter = dev_get_drvdata(&ccw_device->dev);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100187 zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 zfcp_erp_wait(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 zfcp_erp_thread_kill(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 up(&zfcp_data.config_sema);
191 return 0;
192}
193
194/**
Christof Schmittfa04c282008-06-10 18:20:56 +0200195 * zfcp_ccw_notify - ccw notify function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 * @ccw_device: pointer to belonging ccw device
197 * @event: indicates if adapter was detached or attached
198 *
199 * This function gets called by the common i/o layer if an adapter has gone
200 * or reappeared.
201 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200202static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Christof Schmittf48bf7f2008-08-21 13:43:34 +0200204 struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 switch (event) {
207 case CIO_GONE:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200208 dev_warn(&adapter->ccw_device->dev,
209 "The FCP device has been detached\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100210 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 break;
212 case CIO_NO_PATH:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200213 dev_warn(&adapter->ccw_device->dev,
214 "The CHPID for the FCP device is offline\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100215 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217 case CIO_OPER:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200218 dev_info(&adapter->ccw_device->dev,
219 "The FCP device is operational again\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100220 zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 ZFCP_STATUS_COMMON_RUNNING,
222 ZFCP_SET);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200223 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100224 "ccnoti4", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 break;
Sebastian Ott47593bf2009-03-31 19:16:05 +0200226 case CIO_BOXED:
Christof Schmitt955a2152009-05-15 13:18:15 +0200227 dev_warn(&adapter->ccw_device->dev, "The FCP device "
228 "did not respond within the specified time\n");
Sebastian Ott47593bf2009-03-31 19:16:05 +0200229 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL);
230 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return 1;
233}
234
235/**
Christof Schmittfa04c282008-06-10 18:20:56 +0200236 * zfcp_ccw_shutdown - handle shutdown from cio
237 * @cdev: device for adapter to shutdown.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200239static void zfcp_ccw_shutdown(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 struct zfcp_adapter *adapter;
242
243 down(&zfcp_data.config_sema);
Cornelia Huck958974fb2007-10-12 16:11:21 +0200244 adapter = dev_get_drvdata(&cdev->dev);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100245 zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 zfcp_erp_wait(adapter);
247 up(&zfcp_data.config_sema);
248}
249
Christof Schmittfa04c282008-06-10 18:20:56 +0200250static struct ccw_driver zfcp_ccw_driver = {
251 .owner = THIS_MODULE,
252 .name = "zfcp",
253 .ids = zfcp_ccw_device_id,
254 .probe = zfcp_ccw_probe,
255 .remove = zfcp_ccw_remove,
256 .set_online = zfcp_ccw_set_online,
257 .set_offline = zfcp_ccw_set_offline,
258 .notify = zfcp_ccw_notify,
259 .shutdown = zfcp_ccw_shutdown,
Martin Petermanndaa70fa2009-06-16 10:30:34 +0200260 .freeze = zfcp_ccw_suspend,
261 .thaw = zfcp_ccw_activate,
262 .restore = zfcp_ccw_activate,
Christof Schmittfa04c282008-06-10 18:20:56 +0200263};
264
265/**
266 * zfcp_ccw_register - ccw register function
267 *
268 * Registers the driver at the common i/o layer. This function will be called
269 * at module load time/system start.
270 */
271int __init zfcp_ccw_register(void)
272{
273 return ccw_driver_register(&zfcp_ccw_driver);
274}
Swen Schilliga1b449d2008-10-01 12:42:19 +0200275
276/**
277 * zfcp_get_adapter_by_busid - find zfcp_adapter struct
278 * @busid: bus id string of zfcp adapter to find
279 */
280struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid)
281{
282 struct ccw_device *ccw_device;
283 struct zfcp_adapter *adapter = NULL;
284
285 ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
286 if (ccw_device) {
287 adapter = dev_get_drvdata(&ccw_device->dev);
288 put_device(&ccw_device->dev);
289 }
290 return adapter;
291}