4 * Registration and callback for the s390 common I/O layer.
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #define ZFCP_MODEL_PRIV 0x4
16 static struct ccw_device_id zfcp_ccw_device_id[] = {
17 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
18 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, ZFCP_MODEL_PRIV) },
21 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
24 * zfcp_ccw_priv_sch - check if subchannel is privileged
25 * @adapter: Adapter/Subchannel to check
27 int zfcp_ccw_priv_sch(struct zfcp_adapter *adapter)
29 return adapter->ccw_device->id.dev_model == ZFCP_MODEL_PRIV;
33 * zfcp_ccw_probe - probe function of zfcp driver
34 * @ccw_device: pointer to belonging ccw device
36 * This function gets called by the common i/o layer and sets up the initial
37 * data structures for each fcp adapter, which was detected by the system.
38 * Also the sysfs files for this adapter will be created by this function.
39 * In addition the nameserver port will be added to the ports of the adapter
40 * and its sysfs representation will be created too.
42 static int zfcp_ccw_probe(struct ccw_device *ccw_device)
46 down(&zfcp_data.config_sema);
47 if (zfcp_adapter_enqueue(ccw_device)) {
48 dev_err(&ccw_device->dev,
49 "Setting up data structures for the "
50 "FCP adapter failed\n");
53 up(&zfcp_data.config_sema);
58 * zfcp_ccw_remove - remove function of zfcp driver
59 * @ccw_device: pointer to belonging ccw device
61 * This function gets called by the common i/o layer and removes an adapter
62 * from the system. Task of this function is to get rid of all units and
63 * ports that belong to this adapter. And in addition all resources of this
64 * adapter will be freed too.
66 static void zfcp_ccw_remove(struct ccw_device *ccw_device)
68 struct zfcp_adapter *adapter;
69 struct zfcp_port *port, *p;
70 struct zfcp_unit *unit, *u;
71 LIST_HEAD(unit_remove_lh);
72 LIST_HEAD(port_remove_lh);
74 ccw_device_set_offline(ccw_device);
75 down(&zfcp_data.config_sema);
76 adapter = dev_get_drvdata(&ccw_device->dev);
78 write_lock_irq(&zfcp_data.config_lock);
79 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
80 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
81 list_move(&unit->list, &unit_remove_lh);
82 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
85 list_move(&port->list, &port_remove_lh);
86 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
88 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
89 write_unlock_irq(&zfcp_data.config_lock);
91 list_for_each_entry_safe(port, p, &port_remove_lh, list) {
92 list_for_each_entry_safe(unit, u, &unit_remove_lh, list) {
94 scsi_remove_device(unit->device);
95 zfcp_unit_dequeue(unit);
97 zfcp_port_dequeue(port);
99 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
100 zfcp_adapter_dequeue(adapter);
102 up(&zfcp_data.config_sema);
106 * zfcp_ccw_set_online - set_online function of zfcp driver
107 * @ccw_device: pointer to belonging ccw device
109 * This function gets called by the common i/o layer and sets an adapter
110 * into state online. Setting an fcp device online means that it will be
111 * registered with the SCSI stack, that the QDIO queues will be set up
112 * and that the adapter will be opened (asynchronously).
114 static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
116 struct zfcp_adapter *adapter;
119 down(&zfcp_data.config_sema);
120 adapter = dev_get_drvdata(&ccw_device->dev);
122 retval = zfcp_erp_thread_setup(adapter);
126 /* initialize request counter */
127 BUG_ON(!zfcp_reqlist_isempty(adapter));
130 zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
131 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
132 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
134 zfcp_erp_wait(adapter);
135 up(&zfcp_data.config_sema);
136 flush_work(&adapter->scan_work);
140 up(&zfcp_data.config_sema);
145 * zfcp_ccw_set_offline - set_offline 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 offline.
151 static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
153 struct zfcp_adapter *adapter;
155 down(&zfcp_data.config_sema);
156 adapter = dev_get_drvdata(&ccw_device->dev);
157 zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL);
158 zfcp_erp_wait(adapter);
159 zfcp_erp_thread_kill(adapter);
160 up(&zfcp_data.config_sema);
165 * zfcp_ccw_notify - ccw notify function
166 * @ccw_device: pointer to belonging ccw device
167 * @event: indicates if adapter was detached or attached
169 * This function gets called by the common i/o layer if an adapter has gone
172 static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
174 struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
178 dev_warn(&adapter->ccw_device->dev,
179 "The FCP device has been detached\n");
180 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL);
183 dev_warn(&adapter->ccw_device->dev,
184 "The CHPID for the FCP device is offline\n");
185 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL);
188 dev_info(&adapter->ccw_device->dev,
189 "The FCP device is operational again\n");
190 zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL,
191 ZFCP_STATUS_COMMON_RUNNING,
193 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
197 dev_warn(&adapter->ccw_device->dev, "The FCP device "
198 "did not respond within the specified time\n");
199 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL);
206 * zfcp_ccw_shutdown - handle shutdown from cio
207 * @cdev: device for adapter to shutdown.
209 static void zfcp_ccw_shutdown(struct ccw_device *cdev)
211 struct zfcp_adapter *adapter;
213 down(&zfcp_data.config_sema);
214 adapter = dev_get_drvdata(&cdev->dev);
215 zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL);
216 zfcp_erp_wait(adapter);
217 up(&zfcp_data.config_sema);
220 static struct ccw_driver zfcp_ccw_driver = {
221 .owner = THIS_MODULE,
223 .ids = zfcp_ccw_device_id,
224 .probe = zfcp_ccw_probe,
225 .remove = zfcp_ccw_remove,
226 .set_online = zfcp_ccw_set_online,
227 .set_offline = zfcp_ccw_set_offline,
228 .notify = zfcp_ccw_notify,
229 .shutdown = zfcp_ccw_shutdown,
233 * zfcp_ccw_register - ccw register function
235 * Registers the driver at the common i/o layer. This function will be called
236 * at module load time/system start.
238 int __init zfcp_ccw_register(void)
240 return ccw_driver_register(&zfcp_ccw_driver);
244 * zfcp_get_adapter_by_busid - find zfcp_adapter struct
245 * @busid: bus id string of zfcp adapter to find
247 struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid)
249 struct ccw_device *ccw_device;
250 struct zfcp_adapter *adapter = NULL;
252 ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
254 adapter = dev_get_drvdata(&ccw_device->dev);
255 put_device(&ccw_device->dev);