blob: 0e1a42f7a4b568006df99c3e9a70a81d550c9b8b [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 *
Christof Schmittfa04c282008-06-10 18:20:56 +02006 * Copyright IBM Corporation 2002, 2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "zfcp_ext.h"
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011/**
12 * zfcp_ccw_probe - probe function of zfcp driver
13 * @ccw_device: pointer to belonging ccw device
14 *
15 * This function gets called by the common i/o layer and sets up the initial
16 * data structures for each fcp adapter, which was detected by the system.
17 * Also the sysfs files for this adapter will be created by this function.
18 * In addition the nameserver port will be added to the ports of the adapter
19 * and its sysfs representation will be created too.
20 */
Christof Schmittfa04c282008-06-10 18:20:56 +020021static int zfcp_ccw_probe(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 int retval = 0;
24
25 down(&zfcp_data.config_sema);
Swen Schillig317e6b62008-07-02 10:56:37 +020026 if (zfcp_adapter_enqueue(ccw_device)) {
Christof Schmittfa04c282008-06-10 18:20:56 +020027 dev_err(&ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020028 "Setting up data structures for the "
29 "FCP adapter failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 retval = -EINVAL;
Christof Schmittfa04c282008-06-10 18:20:56 +020031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 up(&zfcp_data.config_sema);
33 return retval;
34}
35
36/**
37 * zfcp_ccw_remove - remove function of zfcp driver
38 * @ccw_device: pointer to belonging ccw device
39 *
40 * This function gets called by the common i/o layer and removes an adapter
41 * from the system. Task of this function is to get rid of all units and
42 * ports that belong to this adapter. And in addition all resources of this
43 * adapter will be freed too.
44 */
Christof Schmittfa04c282008-06-10 18:20:56 +020045static void zfcp_ccw_remove(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 struct zfcp_adapter *adapter;
48 struct zfcp_port *port, *p;
49 struct zfcp_unit *unit, *u;
50
51 ccw_device_set_offline(ccw_device);
52 down(&zfcp_data.config_sema);
53 adapter = dev_get_drvdata(&ccw_device->dev);
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 write_lock_irq(&zfcp_data.config_lock);
56 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
57 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
58 list_move(&unit->list, &port->unit_remove_lh);
59 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
60 &unit->status);
61 }
62 list_move(&port->list, &adapter->port_remove_lh);
63 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
64 }
65 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
66 write_unlock_irq(&zfcp_data.config_lock);
67
68 list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
69 list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
Swen Schillig44cc76f2008-10-01 12:42:16 +020070 if (atomic_read(&unit->status) &
71 ZFCP_STATUS_UNIT_REGISTERED)
Christof Schmitte39c8872007-11-05 12:37:46 +010072 scsi_remove_device(unit->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 zfcp_unit_dequeue(unit);
74 }
75 zfcp_port_dequeue(port);
76 }
Swen Schillig44cc76f2008-10-01 12:42:16 +020077 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 zfcp_adapter_dequeue(adapter);
79
80 up(&zfcp_data.config_sema);
81}
82
83/**
84 * zfcp_ccw_set_online - set_online function of zfcp driver
85 * @ccw_device: pointer to belonging ccw device
86 *
87 * This function gets called by the common i/o layer and sets an adapter
88 * into state online. Setting an fcp device online means that it will be
89 * registered with the SCSI stack, that the QDIO queues will be set up
90 * and that the adapter will be opened (asynchronously).
91 */
Christof Schmittfa04c282008-06-10 18:20:56 +020092static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 struct zfcp_adapter *adapter;
95 int retval;
96
97 down(&zfcp_data.config_sema);
98 adapter = dev_get_drvdata(&ccw_device->dev);
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 retval = zfcp_erp_thread_setup(adapter);
Christof Schmittfa04c282008-06-10 18:20:56 +0200101 if (retval)
Christof Schmittff17a292007-08-28 09:31:41 +0200102 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 retval = zfcp_adapter_scsi_register(adapter);
105 if (retval)
106 goto out_scsi_register;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200107
108 /* initialize request counter */
109 BUG_ON(!zfcp_reqlist_isempty(adapter));
110 adapter->req_no = 0;
111
Martin Peschke1f6f7122008-04-18 12:51:55 +0200112 zfcp_erp_modify_adapter_status(adapter, 10, NULL,
Martin Peschke698ec0162008-03-27 14:22:02 +0100113 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200114 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 85,
115 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 zfcp_erp_wait(adapter);
117 goto out;
118
119 out_scsi_register:
120 zfcp_erp_thread_kill(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 out:
122 up(&zfcp_data.config_sema);
123 return retval;
124}
125
126/**
127 * zfcp_ccw_set_offline - set_offline function of zfcp driver
128 * @ccw_device: pointer to belonging ccw device
129 *
130 * This function gets called by the common i/o layer and sets an adapter
Michael Loehr9f287452007-05-09 11:01:24 +0200131 * into state offline.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200133static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 struct zfcp_adapter *adapter;
136
137 down(&zfcp_data.config_sema);
138 adapter = dev_get_drvdata(&ccw_device->dev);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200139 zfcp_erp_adapter_shutdown(adapter, 0, 86, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 zfcp_erp_wait(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 zfcp_erp_thread_kill(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 up(&zfcp_data.config_sema);
143 return 0;
144}
145
146/**
Christof Schmittfa04c282008-06-10 18:20:56 +0200147 * zfcp_ccw_notify - ccw notify function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 * @ccw_device: pointer to belonging ccw device
149 * @event: indicates if adapter was detached or attached
150 *
151 * This function gets called by the common i/o layer if an adapter has gone
152 * or reappeared.
153 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200154static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Christof Schmittf48bf7f2008-08-21 13:43:34 +0200156 struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 switch (event) {
159 case CIO_GONE:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200160 dev_warn(&adapter->ccw_device->dev,
161 "The FCP device has been detached\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +0200162 zfcp_erp_adapter_shutdown(adapter, 0, 87, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 break;
164 case CIO_NO_PATH:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200165 dev_warn(&adapter->ccw_device->dev,
166 "The CHPID for the FCP device is offline\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +0200167 zfcp_erp_adapter_shutdown(adapter, 0, 88, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 break;
169 case CIO_OPER:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200170 dev_info(&adapter->ccw_device->dev,
171 "The FCP device is operational again\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +0200172 zfcp_erp_modify_adapter_status(adapter, 11, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 ZFCP_STATUS_COMMON_RUNNING,
174 ZFCP_SET);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200175 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
176 89, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 break;
178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return 1;
180}
181
182/**
Christof Schmittfa04c282008-06-10 18:20:56 +0200183 * zfcp_ccw_shutdown - handle shutdown from cio
184 * @cdev: device for adapter to shutdown.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 */
Christof Schmittfa04c282008-06-10 18:20:56 +0200186static void zfcp_ccw_shutdown(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 struct zfcp_adapter *adapter;
189
190 down(&zfcp_data.config_sema);
Cornelia Huck958974fb2007-10-12 16:11:21 +0200191 adapter = dev_get_drvdata(&cdev->dev);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200192 zfcp_erp_adapter_shutdown(adapter, 0, 90, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 zfcp_erp_wait(adapter);
194 up(&zfcp_data.config_sema);
195}
196
Christof Schmittfa04c282008-06-10 18:20:56 +0200197static struct ccw_device_id zfcp_ccw_device_id[] = {
198 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
199 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */
200 {},
201};
202
203MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
204
205static struct ccw_driver zfcp_ccw_driver = {
206 .owner = THIS_MODULE,
207 .name = "zfcp",
208 .ids = zfcp_ccw_device_id,
209 .probe = zfcp_ccw_probe,
210 .remove = zfcp_ccw_remove,
211 .set_online = zfcp_ccw_set_online,
212 .set_offline = zfcp_ccw_set_offline,
213 .notify = zfcp_ccw_notify,
214 .shutdown = zfcp_ccw_shutdown,
215};
216
217/**
218 * zfcp_ccw_register - ccw register function
219 *
220 * Registers the driver at the common i/o layer. This function will be called
221 * at module load time/system start.
222 */
223int __init zfcp_ccw_register(void)
224{
225 return ccw_driver_register(&zfcp_ccw_driver);
226}