[S390] convert zfcp printks to pr_xxx macros.
[deliverable/linux.git] / drivers / s390 / scsi / zfcp_ccw.c
CommitLineData
1da177e4 1/*
fa04c281 2 * zfcp device driver
1da177e4 3 *
fa04c281 4 * Registration and callback for the s390 common I/O layer.
1da177e4 5 *
fa04c281 6 * Copyright IBM Corporation 2002, 2008
1da177e4
LT
7 */
8
ecf39d42
CS
9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
1da177e4
LT
12#include "zfcp_ext.h"
13
1da177e4
LT
14/**
15 * zfcp_ccw_probe - probe function of zfcp driver
16 * @ccw_device: pointer to belonging ccw device
17 *
18 * This function gets called by the common i/o layer and sets up the initial
19 * data structures for each fcp adapter, which was detected by the system.
20 * Also the sysfs files for this adapter will be created by this function.
21 * In addition the nameserver port will be added to the ports of the adapter
22 * and its sysfs representation will be created too.
23 */
fa04c281 24static int zfcp_ccw_probe(struct ccw_device *ccw_device)
1da177e4 25{
1da177e4
LT
26 int retval = 0;
27
28 down(&zfcp_data.config_sema);
317e6b65 29 if (zfcp_adapter_enqueue(ccw_device)) {
fa04c281 30 dev_err(&ccw_device->dev,
ff3b24fa
CS
31 "Setting up data structures for the "
32 "FCP adapter failed\n");
1da177e4 33 retval = -EINVAL;
fa04c281 34 }
1da177e4
LT
35 up(&zfcp_data.config_sema);
36 return retval;
37}
38
39/**
40 * zfcp_ccw_remove - remove function of zfcp driver
41 * @ccw_device: pointer to belonging ccw device
42 *
43 * This function gets called by the common i/o layer and removes an adapter
44 * from the system. Task of this function is to get rid of all units and
45 * ports that belong to this adapter. And in addition all resources of this
46 * adapter will be freed too.
47 */
fa04c281 48static void zfcp_ccw_remove(struct ccw_device *ccw_device)
1da177e4
LT
49{
50 struct zfcp_adapter *adapter;
51 struct zfcp_port *port, *p;
52 struct zfcp_unit *unit, *u;
0406289e
CS
53 LIST_HEAD(unit_remove_lh);
54 LIST_HEAD(port_remove_lh);
1da177e4
LT
55
56 ccw_device_set_offline(ccw_device);
57 down(&zfcp_data.config_sema);
58 adapter = dev_get_drvdata(&ccw_device->dev);
59
1da177e4
LT
60 write_lock_irq(&zfcp_data.config_lock);
61 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
62 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
0406289e 63 list_move(&unit->list, &unit_remove_lh);
1da177e4
LT
64 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
65 &unit->status);
66 }
0406289e 67 list_move(&port->list, &port_remove_lh);
1da177e4
LT
68 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
69 }
70 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
71 write_unlock_irq(&zfcp_data.config_lock);
72
0406289e
CS
73 list_for_each_entry_safe(port, p, &port_remove_lh, list) {
74 list_for_each_entry_safe(unit, u, &unit_remove_lh, list) {
44cc76f2
SS
75 if (atomic_read(&unit->status) &
76 ZFCP_STATUS_UNIT_REGISTERED)
e39c8877 77 scsi_remove_device(unit->device);
1da177e4
LT
78 zfcp_unit_dequeue(unit);
79 }
80 zfcp_port_dequeue(port);
81 }
44cc76f2 82 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
1da177e4
LT
83 zfcp_adapter_dequeue(adapter);
84
85 up(&zfcp_data.config_sema);
86}
87
88/**
89 * zfcp_ccw_set_online - set_online 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 sets an adapter
93 * into state online. Setting an fcp device online means that it will be
94 * registered with the SCSI stack, that the QDIO queues will be set up
95 * and that the adapter will be opened (asynchronously).
96 */
fa04c281 97static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
1da177e4
LT
98{
99 struct zfcp_adapter *adapter;
100 int retval;
101
102 down(&zfcp_data.config_sema);
103 adapter = dev_get_drvdata(&ccw_device->dev);
104
1da177e4 105 retval = zfcp_erp_thread_setup(adapter);
fa04c281 106 if (retval)
ff17a29d 107 goto out;
1da177e4
LT
108
109 retval = zfcp_adapter_scsi_register(adapter);
110 if (retval)
111 goto out_scsi_register;
fea9d6c7
VS
112
113 /* initialize request counter */
114 BUG_ON(!zfcp_reqlist_isempty(adapter));
115 adapter->req_no = 0;
116
1f6f7129 117 zfcp_erp_modify_adapter_status(adapter, 10, NULL,
698ec016 118 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
1f6f7129
MP
119 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 85,
120 NULL);
1da177e4 121 zfcp_erp_wait(adapter);
77fd9494
CS
122 up(&zfcp_data.config_sema);
123 flush_work(&adapter->scan_work);
124 return 0;
1da177e4
LT
125
126 out_scsi_register:
127 zfcp_erp_thread_kill(adapter);
1da177e4
LT
128 out:
129 up(&zfcp_data.config_sema);
130 return retval;
131}
132
133/**
134 * zfcp_ccw_set_offline - set_offline function of zfcp driver
135 * @ccw_device: pointer to belonging ccw device
136 *
137 * This function gets called by the common i/o layer and sets an adapter
9f28745a 138 * into state offline.
1da177e4 139 */
fa04c281 140static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
1da177e4
LT
141{
142 struct zfcp_adapter *adapter;
143
144 down(&zfcp_data.config_sema);
145 adapter = dev_get_drvdata(&ccw_device->dev);
1f6f7129 146 zfcp_erp_adapter_shutdown(adapter, 0, 86, NULL);
1da177e4 147 zfcp_erp_wait(adapter);
1da177e4 148 zfcp_erp_thread_kill(adapter);
1da177e4
LT
149 up(&zfcp_data.config_sema);
150 return 0;
151}
152
153/**
fa04c281 154 * zfcp_ccw_notify - ccw notify function
1da177e4
LT
155 * @ccw_device: pointer to belonging ccw device
156 * @event: indicates if adapter was detached or attached
157 *
158 * This function gets called by the common i/o layer if an adapter has gone
159 * or reappeared.
160 */
fa04c281 161static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
1da177e4 162{
f48bf7fb 163 struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
1da177e4 164
1da177e4
LT
165 switch (event) {
166 case CIO_GONE:
ff3b24fa
CS
167 dev_warn(&adapter->ccw_device->dev,
168 "The FCP device has been detached\n");
1f6f7129 169 zfcp_erp_adapter_shutdown(adapter, 0, 87, NULL);
1da177e4
LT
170 break;
171 case CIO_NO_PATH:
ff3b24fa
CS
172 dev_warn(&adapter->ccw_device->dev,
173 "The CHPID for the FCP device is offline\n");
1f6f7129 174 zfcp_erp_adapter_shutdown(adapter, 0, 88, NULL);
1da177e4
LT
175 break;
176 case CIO_OPER:
ff3b24fa
CS
177 dev_info(&adapter->ccw_device->dev,
178 "The FCP device is operational again\n");
1f6f7129 179 zfcp_erp_modify_adapter_status(adapter, 11, NULL,
1da177e4
LT
180 ZFCP_STATUS_COMMON_RUNNING,
181 ZFCP_SET);
1f6f7129
MP
182 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
183 89, NULL);
1da177e4
LT
184 break;
185 }
1da177e4
LT
186 return 1;
187}
188
189/**
fa04c281
CS
190 * zfcp_ccw_shutdown - handle shutdown from cio
191 * @cdev: device for adapter to shutdown.
1da177e4 192 */
fa04c281 193static void zfcp_ccw_shutdown(struct ccw_device *cdev)
1da177e4
LT
194{
195 struct zfcp_adapter *adapter;
196
197 down(&zfcp_data.config_sema);
958974fb 198 adapter = dev_get_drvdata(&cdev->dev);
1f6f7129 199 zfcp_erp_adapter_shutdown(adapter, 0, 90, NULL);
1da177e4
LT
200 zfcp_erp_wait(adapter);
201 up(&zfcp_data.config_sema);
202}
203
fa04c281
CS
204static struct ccw_device_id zfcp_ccw_device_id[] = {
205 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
206 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */
207 {},
208};
209
210MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
211
212static struct ccw_driver zfcp_ccw_driver = {
213 .owner = THIS_MODULE,
214 .name = "zfcp",
215 .ids = zfcp_ccw_device_id,
216 .probe = zfcp_ccw_probe,
217 .remove = zfcp_ccw_remove,
218 .set_online = zfcp_ccw_set_online,
219 .set_offline = zfcp_ccw_set_offline,
220 .notify = zfcp_ccw_notify,
221 .shutdown = zfcp_ccw_shutdown,
222};
223
224/**
225 * zfcp_ccw_register - ccw register function
226 *
227 * Registers the driver at the common i/o layer. This function will be called
228 * at module load time/system start.
229 */
230int __init zfcp_ccw_register(void)
231{
232 return ccw_driver_register(&zfcp_ccw_driver);
233}
a1b449de
SS
234
235/**
236 * zfcp_get_adapter_by_busid - find zfcp_adapter struct
237 * @busid: bus id string of zfcp adapter to find
238 */
239struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid)
240{
241 struct ccw_device *ccw_device;
242 struct zfcp_adapter *adapter = NULL;
243
244 ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
245 if (ccw_device) {
246 adapter = dev_get_drvdata(&ccw_device->dev);
247 put_device(&ccw_device->dev);
248 }
249 return adapter;
250}
This page took 0.403853 seconds and 5 git commands to generate.