Blame view

drivers/s390/block/dasd_alias.c 29.4 KB
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
1
2
3
4
5
6
  /*
   * PAV alias management for the DASD ECKD discipline
   *
   * Copyright IBM Corporation, 2007
   * Author(s): Stefan Weinhuber <wein@de.ibm.com>
   */
ca99dab01   Stefan Haberland   [S390] dasd: fix ...
7
  #define KMSG_COMPONENT "dasd-eckd"
fc19f381b   Stefan Haberland   [S390] dasd: mess...
8

8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
9
  #include <linux/list.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
10
  #include <linux/slab.h>
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  #include <asm/ebcdic.h>
  #include "dasd_int.h"
  #include "dasd_eckd.h"
  
  #ifdef PRINTK_HEADER
  #undef PRINTK_HEADER
  #endif				/* PRINTK_HEADER */
  #define PRINTK_HEADER "dasd(eckd):"
  
  
  /*
   * General concept of alias management:
   * - PAV and DASD alias management is specific to the eckd discipline.
   * - A device is connected to an lcu as long as the device exists.
   *   dasd_alias_make_device_known_to_lcu will be called wenn the
   *   device is checked by the eckd discipline and
   *   dasd_alias_disconnect_device_from_lcu will be called
   *   before the device is deleted.
   * - The dasd_alias_add_device / dasd_alias_remove_device
   *   functions mark the point when a device is 'ready for service'.
   * - A summary unit check is a rare occasion, but it is mandatory to
   *   support it. It requires some complex recovery actions before the
   *   devices can be used again (see dasd_alias_handle_summary_unit_check).
   * - dasd_alias_get_start_dev will find an alias device that can be used
   *   instead of the base device and does some (very simple) load balancing.
   *   This is the function that gets called for each I/O, so when improving
   *   something, this function should get faster or better, the rest has just
   *   to be correct.
   */
  
  
  static void summary_unit_check_handling_work(struct work_struct *);
  static void lcu_update_work(struct work_struct *);
  static int _schedule_lcu_update(struct alias_lcu *, struct dasd_device *);
  
  static struct alias_root aliastree = {
  	.serverlist = LIST_HEAD_INIT(aliastree.serverlist),
  	.lock = __SPIN_LOCK_UNLOCKED(aliastree.lock),
  };
  
  static struct alias_server *_find_server(struct dasd_uid *uid)
  {
  	struct alias_server *pos;
  	list_for_each_entry(pos, &aliastree.serverlist, server) {
  		if (!strncmp(pos->uid.vendor, uid->vendor,
  			     sizeof(uid->vendor))
  		    && !strncmp(pos->uid.serial, uid->serial,
  				sizeof(uid->serial)))
  			return pos;
  	};
  	return NULL;
  }
  
  static struct alias_lcu *_find_lcu(struct alias_server *server,
  				   struct dasd_uid *uid)
  {
  	struct alias_lcu *pos;
  	list_for_each_entry(pos, &server->lculist, lcu) {
  		if (pos->uid.ssid == uid->ssid)
  			return pos;
  	};
  	return NULL;
  }
  
  static struct alias_pav_group *_find_group(struct alias_lcu *lcu,
  					   struct dasd_uid *uid)
  {
  	struct alias_pav_group *pos;
  	__u8 search_unit_addr;
  
  	/* for hyper pav there is only one group */
  	if (lcu->pav == HYPER_PAV) {
  		if (list_empty(&lcu->grouplist))
  			return NULL;
  		else
  			return list_first_entry(&lcu->grouplist,
  						struct alias_pav_group, group);
  	}
  
  	/* for base pav we have to find the group that matches the base */
  	if (uid->type == UA_BASE_DEVICE)
  		search_unit_addr = uid->real_unit_addr;
  	else
  		search_unit_addr = uid->base_unit_addr;
  	list_for_each_entry(pos, &lcu->grouplist, group) {
4abb08c24   Stefan Weinhuber   [S390] dasd: Add ...
96
97
  		if (pos->uid.base_unit_addr == search_unit_addr &&
  		    !strncmp(pos->uid.vduit, uid->vduit, sizeof(uid->vduit)))
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  			return pos;
  	};
  	return NULL;
  }
  
  static struct alias_server *_allocate_server(struct dasd_uid *uid)
  {
  	struct alias_server *server;
  
  	server = kzalloc(sizeof(*server), GFP_KERNEL);
  	if (!server)
  		return ERR_PTR(-ENOMEM);
  	memcpy(server->uid.vendor, uid->vendor, sizeof(uid->vendor));
  	memcpy(server->uid.serial, uid->serial, sizeof(uid->serial));
  	INIT_LIST_HEAD(&server->server);
  	INIT_LIST_HEAD(&server->lculist);
  	return server;
  }
  
  static void _free_server(struct alias_server *server)
  {
  	kfree(server);
  }
  
  static struct alias_lcu *_allocate_lcu(struct dasd_uid *uid)
  {
  	struct alias_lcu *lcu;
  
  	lcu = kzalloc(sizeof(*lcu), GFP_KERNEL);
  	if (!lcu)
  		return ERR_PTR(-ENOMEM);
  	lcu->uac = kzalloc(sizeof(*(lcu->uac)), GFP_KERNEL | GFP_DMA);
  	if (!lcu->uac)
  		goto out_err1;
  	lcu->rsu_cqr = kzalloc(sizeof(*lcu->rsu_cqr), GFP_KERNEL | GFP_DMA);
  	if (!lcu->rsu_cqr)
  		goto out_err2;
  	lcu->rsu_cqr->cpaddr = kzalloc(sizeof(struct ccw1),
  				       GFP_KERNEL | GFP_DMA);
  	if (!lcu->rsu_cqr->cpaddr)
  		goto out_err3;
  	lcu->rsu_cqr->data = kzalloc(16, GFP_KERNEL | GFP_DMA);
  	if (!lcu->rsu_cqr->data)
  		goto out_err4;
  
  	memcpy(lcu->uid.vendor, uid->vendor, sizeof(uid->vendor));
  	memcpy(lcu->uid.serial, uid->serial, sizeof(uid->serial));
  	lcu->uid.ssid = uid->ssid;
  	lcu->pav = NO_PAV;
  	lcu->flags = NEED_UAC_UPDATE | UPDATE_PENDING;
  	INIT_LIST_HEAD(&lcu->lcu);
  	INIT_LIST_HEAD(&lcu->inactive_devices);
  	INIT_LIST_HEAD(&lcu->active_devices);
  	INIT_LIST_HEAD(&lcu->grouplist);
  	INIT_WORK(&lcu->suc_data.worker, summary_unit_check_handling_work);
  	INIT_DELAYED_WORK(&lcu->ruac_data.dwork, lcu_update_work);
  	spin_lock_init(&lcu->lock);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
155
  	init_completion(&lcu->lcu_setup);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  	return lcu;
  
  out_err4:
  	kfree(lcu->rsu_cqr->cpaddr);
  out_err3:
  	kfree(lcu->rsu_cqr);
  out_err2:
  	kfree(lcu->uac);
  out_err1:
  	kfree(lcu);
  	return ERR_PTR(-ENOMEM);
  }
  
  static void _free_lcu(struct alias_lcu *lcu)
  {
  	kfree(lcu->rsu_cqr->data);
  	kfree(lcu->rsu_cqr->cpaddr);
  	kfree(lcu->rsu_cqr);
  	kfree(lcu->uac);
  	kfree(lcu);
  }
  
  /*
   * This is the function that will allocate all the server and lcu data,
   * so this function must be called first for a new device.
   * If the return value is 1, the lcu was already known before, if it
   * is 0, this is a new lcu.
   * Negative return code indicates that something went wrong (e.g. -ENOMEM)
   */
  int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
  {
  	struct dasd_eckd_private *private;
  	unsigned long flags;
  	struct alias_server *server, *newserver;
  	struct alias_lcu *lcu, *newlcu;
  	int is_lcu_known;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
192
  	struct dasd_uid uid;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
193
194
  
  	private = (struct dasd_eckd_private *) device->private;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
195
196
  
  	device->discipline->get_uid(device, &uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
197
198
  	spin_lock_irqsave(&aliastree.lock, flags);
  	is_lcu_known = 1;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
199
  	server = _find_server(&uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
200
201
  	if (!server) {
  		spin_unlock_irqrestore(&aliastree.lock, flags);
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
202
  		newserver = _allocate_server(&uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
203
204
205
  		if (IS_ERR(newserver))
  			return PTR_ERR(newserver);
  		spin_lock_irqsave(&aliastree.lock, flags);
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
206
  		server = _find_server(&uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
207
208
209
210
211
212
213
214
215
  		if (!server) {
  			list_add(&newserver->server, &aliastree.serverlist);
  			server = newserver;
  			is_lcu_known = 0;
  		} else {
  			/* someone was faster */
  			_free_server(newserver);
  		}
  	}
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
216
  	lcu = _find_lcu(server, &uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
217
218
  	if (!lcu) {
  		spin_unlock_irqrestore(&aliastree.lock, flags);
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
219
  		newlcu = _allocate_lcu(&uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
220
  		if (IS_ERR(newlcu))
6d53cfe59   Roel Kluin   [S390] dasd: PTR_...
221
  			return PTR_ERR(newlcu);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
222
  		spin_lock_irqsave(&aliastree.lock, flags);
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
223
  		lcu = _find_lcu(server, &uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
  		if (!lcu) {
  			list_add(&newlcu->lcu, &server->lculist);
  			lcu = newlcu;
  			is_lcu_known = 0;
  		} else {
  			/* someone was faster */
  			_free_lcu(newlcu);
  		}
  		is_lcu_known = 0;
  	}
  	spin_lock(&lcu->lock);
  	list_add(&device->alias_list, &lcu->inactive_devices);
  	private->lcu = lcu;
  	spin_unlock(&lcu->lock);
  	spin_unlock_irqrestore(&aliastree.lock, flags);
  
  	return is_lcu_known;
  }
  
  /*
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
244
245
246
247
248
249
250
251
252
253
   * The first device to be registered on an LCU will have to do
   * some additional setup steps to configure that LCU on the
   * storage server. All further devices should wait with their
   * initialization until the first device is done.
   * To synchronize this work, the first device will call
   * dasd_alias_lcu_setup_complete when it is done, and all
   * other devices will wait for it with dasd_alias_wait_for_lcu_setup.
   */
  void dasd_alias_lcu_setup_complete(struct dasd_device *device)
  {
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
254
255
256
  	unsigned long flags;
  	struct alias_server *server;
  	struct alias_lcu *lcu;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
257
  	struct dasd_uid uid;
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
258

2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
259
  	device->discipline->get_uid(device, &uid);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
260
261
  	lcu = NULL;
  	spin_lock_irqsave(&aliastree.lock, flags);
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
262
  	server = _find_server(&uid);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
263
  	if (server)
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
264
  		lcu = _find_lcu(server, &uid);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
265
266
267
268
  	spin_unlock_irqrestore(&aliastree.lock, flags);
  	if (!lcu) {
  		DBF_EVENT_DEVID(DBF_ERR, device->cdev,
  				"could not find lcu for %04x %02x",
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
269
  				uid.ssid, uid.real_unit_addr);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
270
271
272
273
274
275
276
277
  		WARN_ON(1);
  		return;
  	}
  	complete_all(&lcu->lcu_setup);
  }
  
  void dasd_alias_wait_for_lcu_setup(struct dasd_device *device)
  {
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
278
279
280
  	unsigned long flags;
  	struct alias_server *server;
  	struct alias_lcu *lcu;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
281
  	struct dasd_uid uid;
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
282

2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
283
  	device->discipline->get_uid(device, &uid);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
284
285
  	lcu = NULL;
  	spin_lock_irqsave(&aliastree.lock, flags);
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
286
  	server = _find_server(&uid);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
287
  	if (server)
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
288
  		lcu = _find_lcu(server, &uid);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
289
290
291
292
  	spin_unlock_irqrestore(&aliastree.lock, flags);
  	if (!lcu) {
  		DBF_EVENT_DEVID(DBF_ERR, device->cdev,
  				"could not find lcu for %04x %02x",
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
293
  				uid.ssid, uid.real_unit_addr);
f4ac1d025   Stefan Weinhuber   [S390] dasd: let ...
294
295
296
297
298
299
300
  		WARN_ON(1);
  		return;
  	}
  	wait_for_completion(&lcu->lcu_setup);
  }
  
  /*
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
301
302
303
304
305
306
307
308
309
310
311
   * This function removes a device from the scope of alias management.
   * The complicated part is to make sure that it is not in use by
   * any of the workers. If necessary cancel the work.
   */
  void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
  {
  	struct dasd_eckd_private *private;
  	unsigned long flags;
  	struct alias_lcu *lcu;
  	struct alias_server *server;
  	int was_pending;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
312
  	struct dasd_uid uid;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
313
314
315
  
  	private = (struct dasd_eckd_private *) device->private;
  	lcu = private->lcu;
f602f6d69   Stefan Haberland   [S390] dasd: prev...
316
317
318
  	/* nothing to do if already disconnected */
  	if (!lcu)
  		return;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
319
  	device->discipline->get_uid(device, &uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
  	spin_lock_irqsave(&lcu->lock, flags);
  	list_del_init(&device->alias_list);
  	/* make sure that the workers don't use this device */
  	if (device == lcu->suc_data.device) {
  		spin_unlock_irqrestore(&lcu->lock, flags);
  		cancel_work_sync(&lcu->suc_data.worker);
  		spin_lock_irqsave(&lcu->lock, flags);
  		if (device == lcu->suc_data.device)
  			lcu->suc_data.device = NULL;
  	}
  	was_pending = 0;
  	if (device == lcu->ruac_data.device) {
  		spin_unlock_irqrestore(&lcu->lock, flags);
  		was_pending = 1;
  		cancel_delayed_work_sync(&lcu->ruac_data.dwork);
  		spin_lock_irqsave(&lcu->lock, flags);
  		if (device == lcu->ruac_data.device)
  			lcu->ruac_data.device = NULL;
  	}
  	private->lcu = NULL;
  	spin_unlock_irqrestore(&lcu->lock, flags);
  
  	spin_lock_irqsave(&aliastree.lock, flags);
  	spin_lock(&lcu->lock);
  	if (list_empty(&lcu->grouplist) &&
  	    list_empty(&lcu->active_devices) &&
  	    list_empty(&lcu->inactive_devices)) {
  		list_del(&lcu->lcu);
  		spin_unlock(&lcu->lock);
  		_free_lcu(lcu);
  		lcu = NULL;
  	} else {
  		if (was_pending)
  			_schedule_lcu_update(lcu, NULL);
  		spin_unlock(&lcu->lock);
  	}
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
356
  	server = _find_server(&uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
357
358
359
360
361
362
363
364
365
366
367
368
  	if (server && list_empty(&server->lculist)) {
  		list_del(&server->server);
  		_free_server(server);
  	}
  	spin_unlock_irqrestore(&aliastree.lock, flags);
  }
  
  /*
   * This function assumes that the unit address configuration stored
   * in the lcu is up to date and will update the device uid before
   * adding it to a pav group.
   */
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
369

8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
370
  static int _add_device_to_lcu(struct alias_lcu *lcu,
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
371
372
  			      struct dasd_device *device,
  			      struct dasd_device *pos)
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
373
374
375
376
  {
  
  	struct dasd_eckd_private *private;
  	struct alias_pav_group *group;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
377
378
  	struct dasd_uid uid;
  	unsigned long flags;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
379
380
  
  	private = (struct dasd_eckd_private *) device->private;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
381
382
383
384
385
386
387
388
389
390
391
392
  
  	/* only lock if not already locked */
  	if (device != pos)
  		spin_lock_irqsave_nested(get_ccwdev_lock(device->cdev), flags,
  					 CDEV_NESTED_SECOND);
  	private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
  	private->uid.base_unit_addr =
  		lcu->uac->unit[private->uid.real_unit_addr].base_ua;
  	uid = private->uid;
  
  	if (device != pos)
  		spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
393
394
395
396
397
398
  
  	/* if we have no PAV anyway, we don't need to bother with PAV groups */
  	if (lcu->pav == NO_PAV) {
  		list_move(&device->alias_list, &lcu->active_devices);
  		return 0;
  	}
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
399
  	group = _find_group(lcu, &uid);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
400
401
402
403
  	if (!group) {
  		group = kzalloc(sizeof(*group), GFP_ATOMIC);
  		if (!group)
  			return -ENOMEM;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
404
405
406
407
408
  		memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor));
  		memcpy(group->uid.serial, uid.serial, sizeof(uid.serial));
  		group->uid.ssid = uid.ssid;
  		if (uid.type == UA_BASE_DEVICE)
  			group->uid.base_unit_addr = uid.real_unit_addr;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
409
  		else
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
410
411
  			group->uid.base_unit_addr = uid.base_unit_addr;
  		memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
412
413
414
415
416
  		INIT_LIST_HEAD(&group->group);
  		INIT_LIST_HEAD(&group->baselist);
  		INIT_LIST_HEAD(&group->aliaslist);
  		list_add(&group->group, &lcu->grouplist);
  	}
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
417
  	if (uid.type == UA_BASE_DEVICE)
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
  		list_move(&device->alias_list, &group->baselist);
  	else
  		list_move(&device->alias_list, &group->aliaslist);
  	private->pavgroup = group;
  	return 0;
  };
  
  static void _remove_device_from_lcu(struct alias_lcu *lcu,
  				    struct dasd_device *device)
  {
  	struct dasd_eckd_private *private;
  	struct alias_pav_group *group;
  
  	private = (struct dasd_eckd_private *) device->private;
  	list_move(&device->alias_list, &lcu->inactive_devices);
  	group = private->pavgroup;
  	if (!group)
  		return;
  	private->pavgroup = NULL;
  	if (list_empty(&group->baselist) && list_empty(&group->aliaslist)) {
  		list_del(&group->group);
  		kfree(group);
  		return;
  	}
  	if (group->next == device)
  		group->next = NULL;
  };
  
  static int read_unit_address_configuration(struct dasd_device *device,
  					   struct alias_lcu *lcu)
  {
  	struct dasd_psf_prssd_data *prssdp;
  	struct dasd_ccw_req *cqr;
  	struct ccw1 *ccw;
  	int rc;
  	unsigned long flags;
68b781fe1   Stefan Haberland   [S390] dasd: opti...
454
  	cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */	+ 1 /* RSSD */,
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
  				   (sizeof(struct dasd_psf_prssd_data)),
  				   device);
  	if (IS_ERR(cqr))
  		return PTR_ERR(cqr);
  	cqr->startdev = device;
  	cqr->memdev = device;
  	clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  	cqr->retries = 10;
  	cqr->expires = 20 * HZ;
  
  	/* Prepare for Read Subsystem Data */
  	prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  	memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  	prssdp->order = PSF_ORDER_PRSSD;
  	prssdp->suborder = 0x0e;	/* Read unit address configuration */
  	/* all other bytes of prssdp must be zero */
  
  	ccw = cqr->cpaddr;
  	ccw->cmd_code = DASD_ECKD_CCW_PSF;
  	ccw->count = sizeof(struct dasd_psf_prssd_data);
  	ccw->flags |= CCW_FLAG_CC;
  	ccw->cda = (__u32)(addr_t) prssdp;
  
  	/* Read Subsystem Data - feature codes */
  	memset(lcu->uac, 0, sizeof(*(lcu->uac)));
  
  	ccw++;
  	ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  	ccw->count = sizeof(*(lcu->uac));
  	ccw->cda = (__u32)(addr_t) lcu->uac;
  
  	cqr->buildclk = get_clock();
  	cqr->status = DASD_CQR_FILLED;
  
  	/* need to unset flag here to detect race with summary unit check */
  	spin_lock_irqsave(&lcu->lock, flags);
  	lcu->flags &= ~NEED_UAC_UPDATE;
  	spin_unlock_irqrestore(&lcu->lock, flags);
  
  	do {
  		rc = dasd_sleep_on(cqr);
  	} while (rc && (cqr->retries > 0));
  	if (rc) {
  		spin_lock_irqsave(&lcu->lock, flags);
  		lcu->flags |= NEED_UAC_UPDATE;
  		spin_unlock_irqrestore(&lcu->lock, flags);
  	}
  	dasd_kfree_request(cqr, cqr->memdev);
  	return rc;
  }
  
  static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
  {
  	unsigned long flags;
  	struct alias_pav_group *pavgroup, *tempgroup;
  	struct dasd_device *device, *tempdev;
  	int i, rc;
  	struct dasd_eckd_private *private;
  
  	spin_lock_irqsave(&lcu->lock, flags);
  	list_for_each_entry_safe(pavgroup, tempgroup, &lcu->grouplist, group) {
  		list_for_each_entry_safe(device, tempdev, &pavgroup->baselist,
  					 alias_list) {
  			list_move(&device->alias_list, &lcu->active_devices);
  			private = (struct dasd_eckd_private *) device->private;
  			private->pavgroup = NULL;
  		}
  		list_for_each_entry_safe(device, tempdev, &pavgroup->aliaslist,
  					 alias_list) {
  			list_move(&device->alias_list, &lcu->active_devices);
  			private = (struct dasd_eckd_private *) device->private;
  			private->pavgroup = NULL;
  		}
  		list_del(&pavgroup->group);
  		kfree(pavgroup);
  	}
  	spin_unlock_irqrestore(&lcu->lock, flags);
  
  	rc = read_unit_address_configuration(refdev, lcu);
  	if (rc)
  		return rc;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
536
537
538
539
  	/* need to take cdev lock before lcu lock */
  	spin_lock_irqsave_nested(get_ccwdev_lock(refdev->cdev), flags,
  				 CDEV_NESTED_FIRST);
  	spin_lock(&lcu->lock);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
  	lcu->pav = NO_PAV;
  	for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
  		switch (lcu->uac->unit[i].ua_type) {
  		case UA_BASE_PAV_ALIAS:
  			lcu->pav = BASE_PAV;
  			break;
  		case UA_HYPER_PAV_ALIAS:
  			lcu->pav = HYPER_PAV;
  			break;
  		}
  		if (lcu->pav != NO_PAV)
  			break;
  	}
  
  	list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
  				 alias_list) {
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
556
  		_add_device_to_lcu(lcu, device, refdev);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
557
  	}
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
558
559
  	spin_unlock(&lcu->lock);
  	spin_unlock_irqrestore(get_ccwdev_lock(refdev->cdev), flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
  	return 0;
  }
  
  static void lcu_update_work(struct work_struct *work)
  {
  	struct alias_lcu *lcu;
  	struct read_uac_work_data *ruac_data;
  	struct dasd_device *device;
  	unsigned long flags;
  	int rc;
  
  	ruac_data = container_of(work, struct read_uac_work_data, dwork.work);
  	lcu = container_of(ruac_data, struct alias_lcu, ruac_data);
  	device = ruac_data->device;
  	rc = _lcu_update(device, lcu);
  	/*
  	 * Need to check flags again, as there could have been another
  	 * prepare_update or a new device a new device while we were still
  	 * processing the data
  	 */
  	spin_lock_irqsave(&lcu->lock, flags);
  	if (rc || (lcu->flags & NEED_UAC_UPDATE)) {
fc19f381b   Stefan Haberland   [S390] dasd: mess...
582
  		DBF_DEV_EVENT(DBF_WARNING, device, "could not update"
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
  			    " alias data in lcu (rc = %d), retry later", rc);
  		schedule_delayed_work(&lcu->ruac_data.dwork, 30*HZ);
  	} else {
  		lcu->ruac_data.device = NULL;
  		lcu->flags &= ~UPDATE_PENDING;
  	}
  	spin_unlock_irqrestore(&lcu->lock, flags);
  }
  
  static int _schedule_lcu_update(struct alias_lcu *lcu,
  				struct dasd_device *device)
  {
  	struct dasd_device *usedev = NULL;
  	struct alias_pav_group *group;
  
  	lcu->flags |= NEED_UAC_UPDATE;
  	if (lcu->ruac_data.device) {
  		/* already scheduled or running */
  		return 0;
  	}
  	if (device && !list_empty(&device->alias_list))
  		usedev = device;
  
  	if (!usedev && !list_empty(&lcu->grouplist)) {
  		group = list_first_entry(&lcu->grouplist,
  					 struct alias_pav_group, group);
  		if (!list_empty(&group->baselist))
  			usedev = list_first_entry(&group->baselist,
  						  struct dasd_device,
  						  alias_list);
  		else if (!list_empty(&group->aliaslist))
  			usedev = list_first_entry(&group->aliaslist,
  						  struct dasd_device,
  						  alias_list);
  	}
  	if (!usedev && !list_empty(&lcu->active_devices)) {
  		usedev = list_first_entry(&lcu->active_devices,
  					  struct dasd_device, alias_list);
  	}
  	/*
  	 * if we haven't found a proper device yet, give up for now, the next
  	 * device that will be set active will trigger an lcu update
  	 */
  	if (!usedev)
  		return -EINVAL;
  	lcu->ruac_data.device = usedev;
  	schedule_delayed_work(&lcu->ruac_data.dwork, 0);
  	return 0;
  }
  
  int dasd_alias_add_device(struct dasd_device *device)
  {
  	struct dasd_eckd_private *private;
  	struct alias_lcu *lcu;
  	unsigned long flags;
  	int rc;
  
  	private = (struct dasd_eckd_private *) device->private;
  	lcu = private->lcu;
  	rc = 0;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
643
644
645
646
  
  	/* need to take cdev lock before lcu lock */
  	spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  	spin_lock(&lcu->lock);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
647
  	if (!(lcu->flags & UPDATE_PENDING)) {
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
648
  		rc = _add_device_to_lcu(lcu, device, device);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
649
650
651
652
653
654
655
  		if (rc)
  			lcu->flags |= UPDATE_PENDING;
  	}
  	if (lcu->flags & UPDATE_PENDING) {
  		list_move(&device->alias_list, &lcu->active_devices);
  		_schedule_lcu_update(lcu, device);
  	}
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
656
657
  	spin_unlock(&lcu->lock);
  	spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
658
659
  	return rc;
  }
501183f2e   Stefan Haberland   [S390] dasd: add ...
660
661
662
663
664
665
666
  int dasd_alias_update_add_device(struct dasd_device *device)
  {
  	struct dasd_eckd_private *private;
  	private = (struct dasd_eckd_private *) device->private;
  	private->lcu->flags |= UPDATE_PENDING;
  	return dasd_alias_add_device(device);
  }
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
667
668
669
670
671
672
673
674
  int dasd_alias_remove_device(struct dasd_device *device)
  {
  	struct dasd_eckd_private *private;
  	struct alias_lcu *lcu;
  	unsigned long flags;
  
  	private = (struct dasd_eckd_private *) device->private;
  	lcu = private->lcu;
f602f6d69   Stefan Haberland   [S390] dasd: prev...
675
676
677
  	/* nothing to do if already removed */
  	if (!lcu)
  		return 0;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  	spin_lock_irqsave(&lcu->lock, flags);
  	_remove_device_from_lcu(lcu, device);
  	spin_unlock_irqrestore(&lcu->lock, flags);
  	return 0;
  }
  
  struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
  {
  
  	struct dasd_device *alias_device;
  	struct alias_pav_group *group;
  	struct alias_lcu *lcu;
  	struct dasd_eckd_private *private, *alias_priv;
  	unsigned long flags;
  
  	private = (struct dasd_eckd_private *) base_device->private;
  	group = private->pavgroup;
  	lcu = private->lcu;
  	if (!group || !lcu)
  		return NULL;
  	if (lcu->pav == NO_PAV ||
  	    lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
  		return NULL;
b38f27e84   Stefan Haberland   [S390] dasd: fix ...
701
702
703
704
705
706
707
708
709
710
711
  	if (unlikely(!(private->features.feature[8] & 0x01))) {
  		/*
  		 * PAV enabled but prefix not, very unlikely
  		 * seems to be a lost pathgroup
  		 * use base device to do IO
  		 */
  		DBF_DEV_EVENT(DBF_ERR, base_device, "%s",
  			      "Prefix not enabled with PAV enabled
  ");
  		return NULL;
  	}
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
  
  	spin_lock_irqsave(&lcu->lock, flags);
  	alias_device = group->next;
  	if (!alias_device) {
  		if (list_empty(&group->aliaslist)) {
  			spin_unlock_irqrestore(&lcu->lock, flags);
  			return NULL;
  		} else {
  			alias_device = list_first_entry(&group->aliaslist,
  							struct dasd_device,
  							alias_list);
  		}
  	}
  	if (list_is_last(&alias_device->alias_list, &group->aliaslist))
  		group->next = list_first_entry(&group->aliaslist,
  					       struct dasd_device, alias_list);
  	else
  		group->next = list_first_entry(&alias_device->alias_list,
  					       struct dasd_device, alias_list);
  	spin_unlock_irqrestore(&lcu->lock, flags);
  	alias_priv = (struct dasd_eckd_private *) alias_device->private;
  	if ((alias_priv->count < private->count) && !alias_device->stopped)
  		return alias_device;
  	else
  		return NULL;
  }
  
  /*
   * Summary unit check handling depends on the way alias devices
   * are handled so it is done here rather then in dasd_eckd.c
   */
  static int reset_summary_unit_check(struct alias_lcu *lcu,
  				    struct dasd_device *device,
  				    char reason)
  {
  	struct dasd_ccw_req *cqr;
  	int rc = 0;
f3eb5384c   Stefan Weinhuber   [S390] dasd: add ...
749
  	struct ccw1 *ccw;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
750
751
752
753
  
  	cqr = lcu->rsu_cqr;
  	strncpy((char *) &cqr->magic, "ECKD", 4);
  	ASCEBC((char *) &cqr->magic, 4);
f3eb5384c   Stefan Weinhuber   [S390] dasd: add ...
754
755
756
757
758
  	ccw = cqr->cpaddr;
  	ccw->cmd_code = DASD_ECKD_CCW_RSCK;
  	ccw->flags = 0 ;
  	ccw->count = 16;
  	ccw->cda = (__u32)(addr_t) cqr->data;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
  	((char *)cqr->data)[0] = reason;
  
  	clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  	cqr->retries = 255;	/* set retry counter to enable basic ERP */
  	cqr->startdev = device;
  	cqr->memdev = device;
  	cqr->block = NULL;
  	cqr->expires = 5 * HZ;
  	cqr->buildclk = get_clock();
  	cqr->status = DASD_CQR_FILLED;
  
  	rc = dasd_sleep_on_immediatly(cqr);
  	return rc;
  }
  
  static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
  {
  	struct alias_pav_group *pavgroup;
  	struct dasd_device *device;
  	struct dasd_eckd_private *private;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
779
  	unsigned long flags;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
780
781
782
783
  
  	/* active and inactive list can contain alias as well as base devices */
  	list_for_each_entry(device, &lcu->active_devices, alias_list) {
  		private = (struct dasd_eckd_private *) device->private;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
784
785
786
787
  		spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  		if (private->uid.type != UA_BASE_DEVICE) {
  			spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
  					       flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
788
  			continue;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
789
790
  		}
  		spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
791
792
793
794
795
  		dasd_schedule_block_bh(device->block);
  		dasd_schedule_device_bh(device);
  	}
  	list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
  		private = (struct dasd_eckd_private *) device->private;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
796
797
798
799
  		spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  		if (private->uid.type != UA_BASE_DEVICE) {
  			spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
  					       flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
800
  			continue;
2dedf0d9e   Stefan Haberland   [S390] dasd: remo...
801
802
  		}
  		spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
  		dasd_schedule_block_bh(device->block);
  		dasd_schedule_device_bh(device);
  	}
  	list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  		list_for_each_entry(device, &pavgroup->baselist, alias_list) {
  			dasd_schedule_block_bh(device->block);
  			dasd_schedule_device_bh(device);
  		}
  	}
  }
  
  static void flush_all_alias_devices_on_lcu(struct alias_lcu *lcu)
  {
  	struct alias_pav_group *pavgroup;
  	struct dasd_device *device, *temp;
  	struct dasd_eckd_private *private;
  	int rc;
  	unsigned long flags;
  	LIST_HEAD(active);
  
  	/*
  	 * Problem here ist that dasd_flush_device_queue may wait
  	 * for termination of a request to complete. We can't keep
  	 * the lcu lock during that time, so we must assume that
  	 * the lists may have changed.
  	 * Idea: first gather all active alias devices in a separate list,
  	 * then flush the first element of this list unlocked, and afterwards
  	 * check if it is still on the list before moving it to the
  	 * active_devices list.
  	 */
  
  	spin_lock_irqsave(&lcu->lock, flags);
  	list_for_each_entry_safe(device, temp, &lcu->active_devices,
  				 alias_list) {
  		private = (struct dasd_eckd_private *) device->private;
  		if (private->uid.type == UA_BASE_DEVICE)
  			continue;
  		list_move(&device->alias_list, &active);
  	}
  
  	list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  		list_splice_init(&pavgroup->aliaslist, &active);
  	}
  	while (!list_empty(&active)) {
  		device = list_first_entry(&active, struct dasd_device,
  					  alias_list);
  		spin_unlock_irqrestore(&lcu->lock, flags);
  		rc = dasd_flush_device_queue(device);
  		spin_lock_irqsave(&lcu->lock, flags);
  		/*
  		 * only move device around if it wasn't moved away while we
  		 * were waiting for the flush
  		 */
  		if (device == list_first_entry(&active,
  					       struct dasd_device, alias_list))
  			list_move(&device->alias_list, &lcu->active_devices);
  	}
  	spin_unlock_irqrestore(&lcu->lock, flags);
  }
a806170e2   Heiko Carstens   [S390] Fix a lot ...
862
863
864
865
866
  static void __stop_device_on_lcu(struct dasd_device *device,
  				 struct dasd_device *pos)
  {
  	/* If pos == device then device is already locked! */
  	if (pos == device) {
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
867
  		dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
a806170e2   Heiko Carstens   [S390] Fix a lot ...
868
869
870
  		return;
  	}
  	spin_lock(get_ccwdev_lock(pos->cdev));
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
871
  	dasd_device_set_stop_bits(pos, DASD_STOPPED_SU);
a806170e2   Heiko Carstens   [S390] Fix a lot ...
872
873
  	spin_unlock(get_ccwdev_lock(pos->cdev));
  }
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
874
875
876
877
878
879
880
881
882
  /*
   * This function is called in interrupt context, so the
   * cdev lock for device is already locked!
   */
  static void _stop_all_devices_on_lcu(struct alias_lcu *lcu,
  				     struct dasd_device *device)
  {
  	struct alias_pav_group *pavgroup;
  	struct dasd_device *pos;
a806170e2   Heiko Carstens   [S390] Fix a lot ...
883
884
885
886
  	list_for_each_entry(pos, &lcu->active_devices, alias_list)
  		__stop_device_on_lcu(device, pos);
  	list_for_each_entry(pos, &lcu->inactive_devices, alias_list)
  		__stop_device_on_lcu(device, pos);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
887
  	list_for_each_entry(pavgroup, &lcu->grouplist, group) {
a806170e2   Heiko Carstens   [S390] Fix a lot ...
888
889
890
891
  		list_for_each_entry(pos, &pavgroup->baselist, alias_list)
  			__stop_device_on_lcu(device, pos);
  		list_for_each_entry(pos, &pavgroup->aliaslist, alias_list)
  			__stop_device_on_lcu(device, pos);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
892
893
894
895
896
897
898
899
900
901
902
  	}
  }
  
  static void _unstop_all_devices_on_lcu(struct alias_lcu *lcu)
  {
  	struct alias_pav_group *pavgroup;
  	struct dasd_device *device;
  	unsigned long flags;
  
  	list_for_each_entry(device, &lcu->active_devices, alias_list) {
  		spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
903
  		dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
904
905
906
907
908
  		spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  	}
  
  	list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
  		spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
909
  		dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
910
911
912
913
914
915
  		spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  	}
  
  	list_for_each_entry(pavgroup, &lcu->grouplist, group) {
  		list_for_each_entry(device, &pavgroup->baselist, alias_list) {
  			spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
916
  			dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
917
918
919
920
921
  			spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
  					       flags);
  		}
  		list_for_each_entry(device, &pavgroup->aliaslist, alias_list) {
  			spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
922
  			dasd_device_remove_stop_bits(device, DASD_STOPPED_SU);
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
  			spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
  					       flags);
  		}
  	}
  }
  
  static void summary_unit_check_handling_work(struct work_struct *work)
  {
  	struct alias_lcu *lcu;
  	struct summary_unit_check_work_data *suc_data;
  	unsigned long flags;
  	struct dasd_device *device;
  
  	suc_data = container_of(work, struct summary_unit_check_work_data,
  				worker);
  	lcu = container_of(suc_data, struct alias_lcu, suc_data);
  	device = suc_data->device;
  
  	/* 1. flush alias devices */
  	flush_all_alias_devices_on_lcu(lcu);
  
  	/* 2. reset summary unit check */
  	spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
eb6e199be   Stefan Weinhuber   [S390] dasd: impr...
946
947
  	dasd_device_remove_stop_bits(device,
  				     (DASD_STOPPED_SU | DASD_STOPPED_PENDING));
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
  	spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  	reset_summary_unit_check(lcu, device, suc_data->reason);
  
  	spin_lock_irqsave(&lcu->lock, flags);
  	_unstop_all_devices_on_lcu(lcu);
  	_restart_all_base_devices_on_lcu(lcu);
  	/* 3. read new alias configuration */
  	_schedule_lcu_update(lcu, device);
  	lcu->suc_data.device = NULL;
  	spin_unlock_irqrestore(&lcu->lock, flags);
  }
  
  /*
   * note: this will be called from int handler context (cdev locked)
   */
  void dasd_alias_handle_summary_unit_check(struct dasd_device *device,
  					  struct irb *irb)
  {
  	struct alias_lcu *lcu;
  	char reason;
  	struct dasd_eckd_private *private;
f3eb5384c   Stefan Weinhuber   [S390] dasd: add ...
969
  	char *sense;
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
970
971
  
  	private = (struct dasd_eckd_private *) device->private;
f3eb5384c   Stefan Weinhuber   [S390] dasd: add ...
972
973
974
975
976
977
978
979
980
981
982
  	sense = dasd_get_sense(irb);
  	if (sense) {
  		reason = sense[8];
  		DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
  			    "eckd handle summary unit check: reason", reason);
  	} else {
  		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  			    "eckd handle summary unit check:"
  			    " no reason code available");
  		return;
  	}
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
983
984
985
  
  	lcu = private->lcu;
  	if (!lcu) {
fc19f381b   Stefan Haberland   [S390] dasd: mess...
986
  		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
987
988
989
990
991
992
993
994
995
996
997
998
  			    "device not ready to handle summary"
  			    " unit check (no lcu structure)");
  		return;
  	}
  	spin_lock(&lcu->lock);
  	_stop_all_devices_on_lcu(lcu, device);
  	/* prepare for lcu_update */
  	private->lcu->flags |= NEED_UAC_UPDATE | UPDATE_PENDING;
  	/* If this device is about to be removed just return and wait for
  	 * the next interrupt on a different device
  	 */
  	if (list_empty(&device->alias_list)) {
fc19f381b   Stefan Haberland   [S390] dasd: mess...
999
  		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
1000
1001
1002
1003
1004
1005
1006
  			    "device is in offline processing,"
  			    " don't do summary unit check handling");
  		spin_unlock(&lcu->lock);
  		return;
  	}
  	if (lcu->suc_data.device) {
  		/* already scheduled or running */
fc19f381b   Stefan Haberland   [S390] dasd: mess...
1007
  		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
8e09f2157   Stefan Weinhuber   [S390] dasd: add ...
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
  			    "previous instance of summary unit check worker"
  			    " still pending");
  		spin_unlock(&lcu->lock);
  		return ;
  	}
  	lcu->suc_data.reason = reason;
  	lcu->suc_data.device = device;
  	spin_unlock(&lcu->lock);
  	schedule_work(&lcu->suc_data.worker);
  };