Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa04c281 | 2 | * zfcp device driver |
1da177e4 | 3 | * |
fa04c281 | 4 | * Registration and callback for the s390 common I/O layer. |
1da177e4 | 5 | * |
6d1a27f6 | 6 | * Copyright IBM Corporation 2002, 2009 |
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 | 24 | static 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 | 48 | static 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) { | |
86f8a1b4 | 75 | if (unit->device) |
e39c8877 | 76 | scsi_remove_device(unit->device); |
1da177e4 LT |
77 | zfcp_unit_dequeue(unit); |
78 | } | |
79 | zfcp_port_dequeue(port); | |
80 | } | |
44cc76f2 | 81 | wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0); |
1da177e4 LT |
82 | zfcp_adapter_dequeue(adapter); |
83 | ||
84 | up(&zfcp_data.config_sema); | |
85 | } | |
86 | ||
87 | /** | |
88 | * zfcp_ccw_set_online - set_online 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 sets an adapter | |
92 | * into state online. Setting an fcp device online means that it will be | |
93 | * registered with the SCSI stack, that the QDIO queues will be set up | |
94 | * and that the adapter will be opened (asynchronously). | |
95 | */ | |
fa04c281 | 96 | static int zfcp_ccw_set_online(struct ccw_device *ccw_device) |
1da177e4 LT |
97 | { |
98 | struct zfcp_adapter *adapter; | |
99 | int retval; | |
100 | ||
101 | down(&zfcp_data.config_sema); | |
102 | adapter = dev_get_drvdata(&ccw_device->dev); | |
103 | ||
1da177e4 | 104 | retval = zfcp_erp_thread_setup(adapter); |
fa04c281 | 105 | if (retval) |
ff17a29d | 106 | goto out; |
1da177e4 | 107 | |
fea9d6c7 VS |
108 | /* initialize request counter */ |
109 | BUG_ON(!zfcp_reqlist_isempty(adapter)); | |
110 | adapter->req_no = 0; | |
111 | ||
5ffd51a5 | 112 | zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL, |
698ec016 | 113 | ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET); |
5ffd51a5 SS |
114 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
115 | "ccsonl2", NULL); | |
1da177e4 | 116 | zfcp_erp_wait(adapter); |
77fd9494 CS |
117 | up(&zfcp_data.config_sema); |
118 | flush_work(&adapter->scan_work); | |
119 | return 0; | |
1da177e4 | 120 | |
1da177e4 LT |
121 | 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 | |
9f28745a | 131 | * into state offline. |
1da177e4 | 132 | */ |
fa04c281 | 133 | static int zfcp_ccw_set_offline(struct ccw_device *ccw_device) |
1da177e4 LT |
134 | { |
135 | struct zfcp_adapter *adapter; | |
136 | ||
137 | down(&zfcp_data.config_sema); | |
138 | adapter = dev_get_drvdata(&ccw_device->dev); | |
5ffd51a5 | 139 | zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL); |
1da177e4 | 140 | zfcp_erp_wait(adapter); |
1da177e4 | 141 | zfcp_erp_thread_kill(adapter); |
1da177e4 LT |
142 | up(&zfcp_data.config_sema); |
143 | return 0; | |
144 | } | |
145 | ||
146 | /** | |
fa04c281 | 147 | * zfcp_ccw_notify - ccw notify function |
1da177e4 LT |
148 | * @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 | */ | |
fa04c281 | 154 | static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event) |
1da177e4 | 155 | { |
f48bf7fb | 156 | struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev); |
1da177e4 | 157 | |
1da177e4 LT |
158 | switch (event) { |
159 | case CIO_GONE: | |
ff3b24fa CS |
160 | dev_warn(&adapter->ccw_device->dev, |
161 | "The FCP device has been detached\n"); | |
5ffd51a5 | 162 | zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL); |
1da177e4 LT |
163 | break; |
164 | case CIO_NO_PATH: | |
ff3b24fa CS |
165 | dev_warn(&adapter->ccw_device->dev, |
166 | "The CHPID for the FCP device is offline\n"); | |
5ffd51a5 | 167 | zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL); |
1da177e4 LT |
168 | break; |
169 | case CIO_OPER: | |
ff3b24fa CS |
170 | dev_info(&adapter->ccw_device->dev, |
171 | "The FCP device is operational again\n"); | |
5ffd51a5 | 172 | zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL, |
1da177e4 LT |
173 | ZFCP_STATUS_COMMON_RUNNING, |
174 | ZFCP_SET); | |
1f6f7129 | 175 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
5ffd51a5 | 176 | "ccnoti4", NULL); |
1da177e4 | 177 | break; |
47593bfa | 178 | case CIO_BOXED: |
955a2155 CS |
179 | dev_warn(&adapter->ccw_device->dev, "The FCP device " |
180 | "did not respond within the specified time\n"); | |
47593bfa SO |
181 | zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL); |
182 | break; | |
1da177e4 | 183 | } |
1da177e4 LT |
184 | return 1; |
185 | } | |
186 | ||
187 | /** | |
fa04c281 CS |
188 | * zfcp_ccw_shutdown - handle shutdown from cio |
189 | * @cdev: device for adapter to shutdown. | |
1da177e4 | 190 | */ |
fa04c281 | 191 | static void zfcp_ccw_shutdown(struct ccw_device *cdev) |
1da177e4 LT |
192 | { |
193 | struct zfcp_adapter *adapter; | |
194 | ||
195 | down(&zfcp_data.config_sema); | |
958974fb | 196 | adapter = dev_get_drvdata(&cdev->dev); |
5ffd51a5 | 197 | zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL); |
1da177e4 LT |
198 | zfcp_erp_wait(adapter); |
199 | up(&zfcp_data.config_sema); | |
200 | } | |
201 | ||
fa04c281 CS |
202 | static struct ccw_device_id zfcp_ccw_device_id[] = { |
203 | { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) }, | |
204 | { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */ | |
205 | {}, | |
206 | }; | |
207 | ||
208 | MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id); | |
209 | ||
210 | static struct ccw_driver zfcp_ccw_driver = { | |
211 | .owner = THIS_MODULE, | |
212 | .name = "zfcp", | |
213 | .ids = zfcp_ccw_device_id, | |
214 | .probe = zfcp_ccw_probe, | |
215 | .remove = zfcp_ccw_remove, | |
216 | .set_online = zfcp_ccw_set_online, | |
217 | .set_offline = zfcp_ccw_set_offline, | |
218 | .notify = zfcp_ccw_notify, | |
219 | .shutdown = zfcp_ccw_shutdown, | |
220 | }; | |
221 | ||
222 | /** | |
223 | * zfcp_ccw_register - ccw register function | |
224 | * | |
225 | * Registers the driver at the common i/o layer. This function will be called | |
226 | * at module load time/system start. | |
227 | */ | |
228 | int __init zfcp_ccw_register(void) | |
229 | { | |
230 | return ccw_driver_register(&zfcp_ccw_driver); | |
231 | } | |
a1b449de SS |
232 | |
233 | /** | |
234 | * zfcp_get_adapter_by_busid - find zfcp_adapter struct | |
235 | * @busid: bus id string of zfcp adapter to find | |
236 | */ | |
237 | struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid) | |
238 | { | |
239 | struct ccw_device *ccw_device; | |
240 | struct zfcp_adapter *adapter = NULL; | |
241 | ||
242 | ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid); | |
243 | if (ccw_device) { | |
244 | adapter = dev_get_drvdata(&ccw_device->dev); | |
245 | put_device(&ccw_device->dev); | |
246 | } | |
247 | return adapter; | |
248 | } |