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 int zfcp_ccw_suspend(struct ccw_device
*cdev
)
19 struct zfcp_adapter
*adapter
= dev_get_drvdata(&cdev
->dev
);
21 down(&zfcp_data
.config_sema
);
23 zfcp_erp_adapter_shutdown(adapter
, 0, "ccsusp1", NULL
);
24 zfcp_erp_wait(adapter
);
26 up(&zfcp_data
.config_sema
);
31 static int zfcp_ccw_activate(struct ccw_device
*cdev
)
34 struct zfcp_adapter
*adapter
= dev_get_drvdata(&cdev
->dev
);
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
,
40 zfcp_erp_wait(adapter
);
41 flush_work(&adapter
->scan_work
);
46 static 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
) },
51 MODULE_DEVICE_TABLE(ccw
, zfcp_ccw_device_id
);
54 * zfcp_ccw_priv_sch - check if subchannel is privileged
55 * @adapter: Adapter/Subchannel to check
57 int zfcp_ccw_priv_sch(struct zfcp_adapter
*adapter
)
59 return adapter
->ccw_device
->id
.dev_model
== ZFCP_MODEL_PRIV
;
63 * zfcp_ccw_probe - probe function of zfcp driver
64 * @ccw_device: pointer to belonging ccw device
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.
72 static int zfcp_ccw_probe(struct ccw_device
*ccw_device
)
76 down(&zfcp_data
.config_sema
);
77 if (zfcp_adapter_enqueue(ccw_device
)) {
78 dev_err(&ccw_device
->dev
,
79 "Setting up data structures for the "
80 "FCP adapter failed\n");
83 up(&zfcp_data
.config_sema
);
88 * zfcp_ccw_remove - remove function of zfcp driver
89 * @ccw_device: pointer to belonging ccw device
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.
96 static void 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
;
101 LIST_HEAD(unit_remove_lh
);
102 LIST_HEAD(port_remove_lh
);
104 ccw_device_set_offline(ccw_device
);
105 down(&zfcp_data
.config_sema
);
106 adapter
= dev_get_drvdata(&ccw_device
->dev
);
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
, &unit_remove_lh
);
112 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
,
115 list_move(&port
->list
, &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
, &port_remove_lh
, list
) {
122 list_for_each_entry_safe(unit
, u
, &unit_remove_lh
, list
) {
124 scsi_remove_device(unit
->device
);
125 zfcp_unit_dequeue(unit
);
127 zfcp_port_dequeue(port
);
129 wait_event(adapter
->remove_wq
, atomic_read(&adapter
->refcount
) == 0);
130 zfcp_adapter_dequeue(adapter
);
132 up(&zfcp_data
.config_sema
);
136 * zfcp_ccw_set_online - set_online function of zfcp driver
137 * @ccw_device: pointer to belonging ccw device
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).
144 static int zfcp_ccw_set_online(struct ccw_device
*ccw_device
)
146 struct zfcp_adapter
*adapter
;
149 down(&zfcp_data
.config_sema
);
150 adapter
= dev_get_drvdata(&ccw_device
->dev
);
152 retval
= zfcp_erp_thread_setup(adapter
);
156 /* initialize request counter */
157 BUG_ON(!zfcp_reqlist_isempty(adapter
));
160 zfcp_erp_modify_adapter_status(adapter
, "ccsonl1", NULL
,
161 ZFCP_STATUS_COMMON_RUNNING
, ZFCP_SET
);
162 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
,
164 zfcp_erp_wait(adapter
);
165 up(&zfcp_data
.config_sema
);
166 flush_work(&adapter
->scan_work
);
170 up(&zfcp_data
.config_sema
);
175 * zfcp_ccw_set_offline - set_offline function of zfcp driver
176 * @ccw_device: pointer to belonging ccw device
178 * This function gets called by the common i/o layer and sets an adapter
179 * into state offline.
181 static int zfcp_ccw_set_offline(struct ccw_device
*ccw_device
)
183 struct zfcp_adapter
*adapter
;
185 down(&zfcp_data
.config_sema
);
186 adapter
= dev_get_drvdata(&ccw_device
->dev
);
187 zfcp_erp_adapter_shutdown(adapter
, 0, "ccsoff1", NULL
);
188 zfcp_erp_wait(adapter
);
189 zfcp_erp_thread_kill(adapter
);
190 up(&zfcp_data
.config_sema
);
195 * zfcp_ccw_notify - ccw notify function
196 * @ccw_device: pointer to belonging ccw device
197 * @event: indicates if adapter was detached or attached
199 * This function gets called by the common i/o layer if an adapter has gone
202 static int zfcp_ccw_notify(struct ccw_device
*ccw_device
, int event
)
204 struct zfcp_adapter
*adapter
= dev_get_drvdata(&ccw_device
->dev
);
208 dev_warn(&adapter
->ccw_device
->dev
,
209 "The FCP device has been detached\n");
210 zfcp_erp_adapter_shutdown(adapter
, 0, "ccnoti1", NULL
);
213 dev_warn(&adapter
->ccw_device
->dev
,
214 "The CHPID for the FCP device is offline\n");
215 zfcp_erp_adapter_shutdown(adapter
, 0, "ccnoti2", NULL
);
218 dev_info(&adapter
->ccw_device
->dev
,
219 "The FCP device is operational again\n");
220 zfcp_erp_modify_adapter_status(adapter
, "ccnoti3", NULL
,
221 ZFCP_STATUS_COMMON_RUNNING
,
223 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
,
227 dev_warn(&adapter
->ccw_device
->dev
, "The FCP device "
228 "did not respond within the specified time\n");
229 zfcp_erp_adapter_shutdown(adapter
, 0, "ccnoti5", NULL
);
236 * zfcp_ccw_shutdown - handle shutdown from cio
237 * @cdev: device for adapter to shutdown.
239 static void zfcp_ccw_shutdown(struct ccw_device
*cdev
)
241 struct zfcp_adapter
*adapter
;
243 down(&zfcp_data
.config_sema
);
244 adapter
= dev_get_drvdata(&cdev
->dev
);
245 zfcp_erp_adapter_shutdown(adapter
, 0, "ccshut1", NULL
);
246 zfcp_erp_wait(adapter
);
247 up(&zfcp_data
.config_sema
);
250 static struct ccw_driver zfcp_ccw_driver
= {
251 .owner
= THIS_MODULE
,
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
,
260 .freeze
= zfcp_ccw_suspend
,
261 .thaw
= zfcp_ccw_activate
,
262 .restore
= zfcp_ccw_activate
,
266 * zfcp_ccw_register - ccw register function
268 * Registers the driver at the common i/o layer. This function will be called
269 * at module load time/system start.
271 int __init
zfcp_ccw_register(void)
273 return ccw_driver_register(&zfcp_ccw_driver
);
277 * zfcp_get_adapter_by_busid - find zfcp_adapter struct
278 * @busid: bus id string of zfcp adapter to find
280 struct zfcp_adapter
*zfcp_get_adapter_by_busid(char *busid
)
282 struct ccw_device
*ccw_device
;
283 struct zfcp_adapter
*adapter
= NULL
;
285 ccw_device
= get_ccwdev_by_busid(&zfcp_ccw_driver
, busid
);
287 adapter
= dev_get_drvdata(&ccw_device
->dev
);
288 put_device(&ccw_device
->dev
);