xref: /linux/drivers/s390/cio/css.c (revision 32a92f8c89326985e05dce8b22d3f0aa07a3e1bd)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * driver for channel subsystem
4  *
5  * Copyright IBM Corp. 2002, 2010
6  *
7  * Author(s): Arnd Bergmann (arndb@de.ibm.com)
8  *	      Cornelia Huck (cornelia.huck@de.ibm.com)
9  */
10 
11 #define pr_fmt(fmt) "cio: " fmt
12 
13 #include <linux/export.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/list.h>
19 #include <linux/reboot.h>
20 #include <linux/proc_fs.h>
21 #include <linux/genalloc.h>
22 #include <linux/dma-mapping.h>
23 #include <asm/isc.h>
24 #include <asm/crw.h>
25 
26 #include "css.h"
27 #include "cio.h"
28 #include "blacklist.h"
29 #include "cio_debug.h"
30 #include "ioasm.h"
31 #include "chsc.h"
32 #include "device.h"
33 #include "idset.h"
34 #include "chp.h"
35 
36 int css_init_done = 0;
37 int max_ssid;
38 
39 #define MAX_CSS_IDX 0
40 struct channel_subsystem *channel_subsystems[MAX_CSS_IDX + 1];
41 static const struct bus_type css_bus_type;
42 
43 int
44 for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
45 {
46 	struct subchannel_id schid;
47 	int ret;
48 
49 	init_subchannel_id(&schid);
50 	do {
51 		do {
52 			ret = fn(schid, data);
53 			if (ret)
54 				break;
55 		} while (schid.sch_no++ < __MAX_SUBCHANNEL);
56 		schid.sch_no = 0;
57 	} while (schid.ssid++ < max_ssid);
58 	return ret;
59 }
60 
61 struct cb_data {
62 	void *data;
63 	struct idset *set;
64 	int (*fn_known_sch)(struct subchannel *, void *);
65 	int (*fn_unknown_sch)(struct subchannel_id, void *);
66 };
67 
68 static int call_fn_known_sch(struct device *dev, void *data)
69 {
70 	struct subchannel *sch = to_subchannel(dev);
71 	struct cb_data *cb = data;
72 	int rc = 0;
73 
74 	if (cb->set)
75 		idset_sch_del(cb->set, sch->schid);
76 	if (cb->fn_known_sch)
77 		rc = cb->fn_known_sch(sch, cb->data);
78 	return rc;
79 }
80 
81 static int call_fn_unknown_sch(struct subchannel_id schid, void *data)
82 {
83 	struct cb_data *cb = data;
84 	int rc = 0;
85 
86 	if (idset_sch_contains(cb->set, schid))
87 		rc = cb->fn_unknown_sch(schid, cb->data);
88 	return rc;
89 }
90 
91 static int call_fn_all_sch(struct subchannel_id schid, void *data)
92 {
93 	struct cb_data *cb = data;
94 	struct subchannel *sch;
95 	int rc = 0;
96 
97 	sch = get_subchannel_by_schid(schid);
98 	if (sch) {
99 		if (cb->fn_known_sch)
100 			rc = cb->fn_known_sch(sch, cb->data);
101 		put_device(&sch->dev);
102 	} else {
103 		if (cb->fn_unknown_sch)
104 			rc = cb->fn_unknown_sch(schid, cb->data);
105 	}
106 
107 	return rc;
108 }
109 
110 int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
111 			       int (*fn_unknown)(struct subchannel_id,
112 			       void *), void *data)
113 {
114 	struct cb_data cb;
115 	int rc;
116 
117 	cb.data = data;
118 	cb.fn_known_sch = fn_known;
119 	cb.fn_unknown_sch = fn_unknown;
120 
121 	if (fn_known && !fn_unknown) {
122 		/* Skip idset allocation in case of known-only loop. */
123 		cb.set = NULL;
124 		return bus_for_each_dev(&css_bus_type, NULL, &cb,
125 					call_fn_known_sch);
126 	}
127 
128 	cb.set = idset_sch_new();
129 	if (!cb.set)
130 		/* fall back to brute force scanning in case of oom */
131 		return for_each_subchannel(call_fn_all_sch, &cb);
132 
133 	idset_fill(cb.set);
134 
135 	/* Process registered subchannels. */
136 	rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch);
137 	if (rc)
138 		goto out;
139 	/* Process unregistered subchannels. */
140 	if (fn_unknown)
141 		rc = for_each_subchannel(call_fn_unknown_sch, &cb);
142 out:
143 	idset_free(cb.set);
144 
145 	return rc;
146 }
147 
148 static void css_sch_todo(struct work_struct *work);
149 
150 static void css_sch_create_locks(struct subchannel *sch)
151 {
152 	spin_lock_init(&sch->lock);
153 	mutex_init(&sch->reg_mutex);
154 }
155 
156 static void css_subchannel_release(struct device *dev)
157 {
158 	struct subchannel *sch = to_subchannel(dev);
159 
160 	sch->config.intparm = 0;
161 	cio_commit_config(sch);
162 	kfree(sch->driver_override);
163 	kfree(sch);
164 }
165 
166 static int css_validate_subchannel(struct subchannel_id schid,
167 				   struct schib *schib)
168 {
169 	int err;
170 
171 	switch (schib->pmcw.st) {
172 	case SUBCHANNEL_TYPE_IO:
173 	case SUBCHANNEL_TYPE_MSG:
174 		if (!css_sch_is_valid(schib))
175 			err = -ENODEV;
176 		else if (is_blacklisted(schid.ssid, schib->pmcw.dev)) {
177 			CIO_MSG_EVENT(6, "Blacklisted device detected "
178 				      "at devno %04X, subchannel set %x\n",
179 				      schib->pmcw.dev, schid.ssid);
180 			err = -ENODEV;
181 		} else
182 			err = 0;
183 		break;
184 	default:
185 		err = 0;
186 	}
187 	if (err)
188 		goto out;
189 
190 	CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
191 		      schid.ssid, schid.sch_no, schib->pmcw.st);
192 out:
193 	return err;
194 }
195 
196 struct subchannel *css_alloc_subchannel(struct subchannel_id schid,
197 					struct schib *schib)
198 {
199 	struct subchannel *sch;
200 	int ret;
201 
202 	ret = css_validate_subchannel(schid, schib);
203 	if (ret < 0)
204 		return ERR_PTR(ret);
205 
206 	sch = kzalloc_obj(*sch, GFP_KERNEL | GFP_DMA);
207 	if (!sch)
208 		return ERR_PTR(-ENOMEM);
209 
210 	sch->schid = schid;
211 	sch->schib = *schib;
212 	sch->st = schib->pmcw.st;
213 
214 	css_sch_create_locks(sch);
215 
216 	INIT_WORK(&sch->todo_work, css_sch_todo);
217 	sch->dev.release = &css_subchannel_release;
218 	sch->dev.dma_mask = &sch->dma_mask;
219 	device_initialize(&sch->dev);
220 	/*
221 	 * The physical addresses for some of the dma structures that can
222 	 * belong to a subchannel need to fit 31 bit width (e.g. ccw).
223 	 */
224 	ret = dma_set_coherent_mask(&sch->dev, DMA_BIT_MASK(31));
225 	if (ret)
226 		goto err;
227 	/*
228 	 * But we don't have such restrictions imposed on the stuff that
229 	 * is handled by the streaming API.
230 	 */
231 	ret = dma_set_mask(&sch->dev, DMA_BIT_MASK(64));
232 	if (ret)
233 		goto err;
234 
235 	return sch;
236 
237 err:
238 	put_device(&sch->dev);
239 	return ERR_PTR(ret);
240 }
241 
242 static int css_sch_device_register(struct subchannel *sch)
243 {
244 	int ret;
245 
246 	mutex_lock(&sch->reg_mutex);
247 	dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid,
248 		     sch->schid.sch_no);
249 	ret = device_add(&sch->dev);
250 	mutex_unlock(&sch->reg_mutex);
251 	return ret;
252 }
253 
254 /**
255  * css_sch_device_unregister - unregister a subchannel
256  * @sch: subchannel to be unregistered
257  */
258 void css_sch_device_unregister(struct subchannel *sch)
259 {
260 	mutex_lock(&sch->reg_mutex);
261 	if (device_is_registered(&sch->dev))
262 		device_unregister(&sch->dev);
263 	mutex_unlock(&sch->reg_mutex);
264 }
265 EXPORT_SYMBOL_GPL(css_sch_device_unregister);
266 
267 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
268 {
269 	int i;
270 	int mask;
271 
272 	memset(ssd, 0, sizeof(struct chsc_ssd_info));
273 	ssd->path_mask = pmcw->pim;
274 	for (i = 0; i < 8; i++) {
275 		mask = 0x80 >> i;
276 		if (pmcw->pim & mask) {
277 			chp_id_init(&ssd->chpid[i]);
278 			ssd->chpid[i].id = pmcw->chpid[i];
279 		}
280 	}
281 }
282 
283 static void ssd_register_chpids(struct chsc_ssd_info *ssd)
284 {
285 	int i;
286 	int mask;
287 
288 	for (i = 0; i < 8; i++) {
289 		mask = 0x80 >> i;
290 		if (ssd->path_mask & mask)
291 			chp_new(ssd->chpid[i]);
292 	}
293 }
294 
295 void css_update_ssd_info(struct subchannel *sch)
296 {
297 	int ret;
298 
299 	ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
300 	if (ret)
301 		ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
302 
303 	ssd_register_chpids(&sch->ssd_info);
304 }
305 
306 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
307 			 char *buf)
308 {
309 	struct subchannel *sch = to_subchannel(dev);
310 
311 	return sysfs_emit(buf, "%01x\n", sch->st);
312 }
313 
314 static DEVICE_ATTR_RO(type);
315 
316 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
317 			     char *buf)
318 {
319 	struct subchannel *sch = to_subchannel(dev);
320 
321 	return sysfs_emit(buf, "css:t%01X\n", sch->st);
322 }
323 
324 static DEVICE_ATTR_RO(modalias);
325 
326 static ssize_t driver_override_store(struct device *dev,
327 				     struct device_attribute *attr,
328 				     const char *buf, size_t count)
329 {
330 	struct subchannel *sch = to_subchannel(dev);
331 	int ret;
332 
333 	ret = driver_set_override(dev, &sch->driver_override, buf, count);
334 	if (ret)
335 		return ret;
336 
337 	return count;
338 }
339 
340 static ssize_t driver_override_show(struct device *dev,
341 				    struct device_attribute *attr, char *buf)
342 {
343 	struct subchannel *sch = to_subchannel(dev);
344 	ssize_t len;
345 
346 	device_lock(dev);
347 	len = sysfs_emit(buf, "%s\n", sch->driver_override);
348 	device_unlock(dev);
349 	return len;
350 }
351 static DEVICE_ATTR_RW(driver_override);
352 
353 static struct attribute *subch_attrs[] = {
354 	&dev_attr_type.attr,
355 	&dev_attr_modalias.attr,
356 	&dev_attr_driver_override.attr,
357 	NULL,
358 };
359 
360 static struct attribute_group subch_attr_group = {
361 	.attrs = subch_attrs,
362 };
363 
364 static const struct attribute_group *default_subch_attr_groups[] = {
365 	&subch_attr_group,
366 	NULL,
367 };
368 
369 static ssize_t chpids_show(struct device *dev,
370 			   struct device_attribute *attr,
371 			   char *buf)
372 {
373 	struct subchannel *sch = to_subchannel(dev);
374 	struct chsc_ssd_info *ssd = &sch->ssd_info;
375 	ssize_t ret = 0;
376 	int mask;
377 	int chp;
378 
379 	for (chp = 0; chp < 8; chp++) {
380 		mask = 0x80 >> chp;
381 		if (ssd->path_mask & mask)
382 			ret += sysfs_emit_at(buf, ret, "%02x ", ssd->chpid[chp].id);
383 		else
384 			ret += sysfs_emit_at(buf, ret, "00 ");
385 	}
386 	ret += sysfs_emit_at(buf, ret, "\n");
387 	return ret;
388 }
389 static DEVICE_ATTR_RO(chpids);
390 
391 static ssize_t pimpampom_show(struct device *dev,
392 			      struct device_attribute *attr,
393 			      char *buf)
394 {
395 	struct subchannel *sch = to_subchannel(dev);
396 	struct pmcw *pmcw = &sch->schib.pmcw;
397 
398 	return sysfs_emit(buf, "%02x %02x %02x\n",
399 			  pmcw->pim, pmcw->pam, pmcw->pom);
400 }
401 static DEVICE_ATTR_RO(pimpampom);
402 
403 static ssize_t dev_busid_show(struct device *dev,
404 			      struct device_attribute *attr,
405 			      char *buf)
406 {
407 	struct subchannel *sch = to_subchannel(dev);
408 	struct pmcw *pmcw = &sch->schib.pmcw;
409 
410 	if ((pmcw->st == SUBCHANNEL_TYPE_IO && pmcw->dnv) ||
411 	    (pmcw->st == SUBCHANNEL_TYPE_MSG && pmcw->w))
412 		return sysfs_emit(buf, "0.%x.%04x\n", sch->schid.ssid,
413 				  pmcw->dev);
414 	else
415 		return sysfs_emit(buf, "none\n");
416 }
417 static DEVICE_ATTR_RO(dev_busid);
418 
419 static struct attribute *io_subchannel_type_attrs[] = {
420 	&dev_attr_chpids.attr,
421 	&dev_attr_pimpampom.attr,
422 	&dev_attr_dev_busid.attr,
423 	NULL,
424 };
425 ATTRIBUTE_GROUPS(io_subchannel_type);
426 
427 static const struct device_type io_subchannel_type = {
428 	.groups = io_subchannel_type_groups,
429 };
430 
431 int css_register_subchannel(struct subchannel *sch)
432 {
433 	int ret;
434 
435 	/* Initialize the subchannel structure */
436 	sch->dev.parent = &channel_subsystems[0]->device;
437 	sch->dev.bus = &css_bus_type;
438 	sch->dev.groups = default_subch_attr_groups;
439 
440 	if (sch->st == SUBCHANNEL_TYPE_IO)
441 		sch->dev.type = &io_subchannel_type;
442 
443 	css_update_ssd_info(sch);
444 	/* make it known to the system */
445 	ret = css_sch_device_register(sch);
446 	if (ret) {
447 		CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
448 			      sch->schid.ssid, sch->schid.sch_no, ret);
449 		return ret;
450 	}
451 	return ret;
452 }
453 
454 static int css_probe_device(struct subchannel_id schid, struct schib *schib)
455 {
456 	struct subchannel *sch;
457 	int ret;
458 
459 	sch = css_alloc_subchannel(schid, schib);
460 	if (IS_ERR(sch))
461 		return PTR_ERR(sch);
462 
463 	ret = css_register_subchannel(sch);
464 	if (ret)
465 		put_device(&sch->dev);
466 
467 	return ret;
468 }
469 
470 static int
471 check_subchannel(struct device *dev, const void *data)
472 {
473 	struct subchannel *sch;
474 	struct subchannel_id *schid = (void *)data;
475 
476 	sch = to_subchannel(dev);
477 	return schid_equal(&sch->schid, schid);
478 }
479 
480 struct subchannel *
481 get_subchannel_by_schid(struct subchannel_id schid)
482 {
483 	struct device *dev;
484 
485 	dev = bus_find_device(&css_bus_type, NULL,
486 			      &schid, check_subchannel);
487 
488 	return dev ? to_subchannel(dev) : NULL;
489 }
490 
491 /**
492  * css_sch_is_valid() - check if a subchannel is valid
493  * @schib: subchannel information block for the subchannel
494  */
495 int css_sch_is_valid(struct schib *schib)
496 {
497 	if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
498 		return 0;
499 	if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
500 		return 0;
501 	return 1;
502 }
503 EXPORT_SYMBOL_GPL(css_sch_is_valid);
504 
505 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
506 {
507 	struct schib schib;
508 	int ccode;
509 
510 	if (!slow) {
511 		/* Will be done on the slow path. */
512 		return -EAGAIN;
513 	}
514 	/*
515 	 * The first subchannel that is not-operational (ccode==3)
516 	 * indicates that there aren't any more devices available.
517 	 * If stsch gets an exception, it means the current subchannel set
518 	 * is not valid.
519 	 */
520 	ccode = stsch(schid, &schib);
521 	if (ccode)
522 		return (ccode == 3) ? -ENXIO : ccode;
523 
524 	return css_probe_device(schid, &schib);
525 }
526 
527 static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
528 {
529 	int ret = 0;
530 
531 	if (sch->driver) {
532 		if (sch->driver->sch_event)
533 			ret = sch->driver->sch_event(sch, slow);
534 		else
535 			dev_dbg(&sch->dev,
536 				"Got subchannel machine check but "
537 				"no sch_event handler provided.\n");
538 	}
539 	if (ret != 0 && ret != -EAGAIN) {
540 		CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n",
541 			      sch->schid.ssid, sch->schid.sch_no, ret);
542 	}
543 	return ret;
544 }
545 
546 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
547 {
548 	struct subchannel *sch;
549 	int ret;
550 
551 	sch = get_subchannel_by_schid(schid);
552 	if (sch) {
553 		ret = css_evaluate_known_subchannel(sch, slow);
554 		put_device(&sch->dev);
555 	} else
556 		ret = css_evaluate_new_subchannel(schid, slow);
557 	if (ret == -EAGAIN)
558 		css_schedule_eval(schid);
559 }
560 
561 /**
562  * css_sched_sch_todo - schedule a subchannel operation
563  * @sch: subchannel
564  * @todo: todo
565  *
566  * Schedule the operation identified by @todo to be performed on the slow path
567  * workqueue. Do nothing if another operation with higher priority is already
568  * scheduled. Needs to be called with subchannel lock held.
569  */
570 void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo)
571 {
572 	CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n",
573 		      sch->schid.ssid, sch->schid.sch_no, todo);
574 	if (sch->todo >= todo)
575 		return;
576 	/* Get workqueue ref. */
577 	if (!get_device(&sch->dev))
578 		return;
579 	sch->todo = todo;
580 	if (!queue_work(cio_work_q, &sch->todo_work)) {
581 		/* Already queued, release workqueue ref. */
582 		put_device(&sch->dev);
583 	}
584 }
585 EXPORT_SYMBOL_GPL(css_sched_sch_todo);
586 
587 static void css_sch_todo(struct work_struct *work)
588 {
589 	struct subchannel *sch;
590 	enum sch_todo todo;
591 	int ret;
592 
593 	sch = container_of(work, struct subchannel, todo_work);
594 	/* Find out todo. */
595 	spin_lock_irq(&sch->lock);
596 	todo = sch->todo;
597 	CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch->schid.ssid,
598 		      sch->schid.sch_no, todo);
599 	sch->todo = SCH_TODO_NOTHING;
600 	spin_unlock_irq(&sch->lock);
601 	/* Perform todo. */
602 	switch (todo) {
603 	case SCH_TODO_NOTHING:
604 		break;
605 	case SCH_TODO_EVAL:
606 		ret = css_evaluate_known_subchannel(sch, 1);
607 		if (ret == -EAGAIN) {
608 			spin_lock_irq(&sch->lock);
609 			css_sched_sch_todo(sch, todo);
610 			spin_unlock_irq(&sch->lock);
611 		}
612 		break;
613 	case SCH_TODO_UNREG:
614 		css_sch_device_unregister(sch);
615 		break;
616 	}
617 	/* Release workqueue ref. */
618 	put_device(&sch->dev);
619 }
620 
621 static struct idset *slow_subchannel_set;
622 static DEFINE_SPINLOCK(slow_subchannel_lock);
623 static DECLARE_WAIT_QUEUE_HEAD(css_eval_wq);
624 static atomic_t css_eval_scheduled;
625 
626 static int __init slow_subchannel_init(void)
627 {
628 	atomic_set(&css_eval_scheduled, 0);
629 	slow_subchannel_set = idset_sch_new();
630 	if (!slow_subchannel_set) {
631 		CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
632 		return -ENOMEM;
633 	}
634 	return 0;
635 }
636 
637 static int slow_eval_known_fn(struct subchannel *sch, void *data)
638 {
639 	int eval;
640 	int rc;
641 
642 	spin_lock_irq(&slow_subchannel_lock);
643 	eval = idset_sch_contains(slow_subchannel_set, sch->schid);
644 	idset_sch_del(slow_subchannel_set, sch->schid);
645 	spin_unlock_irq(&slow_subchannel_lock);
646 	if (eval) {
647 		rc = css_evaluate_known_subchannel(sch, 1);
648 		if (rc == -EAGAIN)
649 			css_schedule_eval(sch->schid);
650 		/*
651 		 * The loop might take long time for platforms with lots of
652 		 * known devices. Allow scheduling here.
653 		 */
654 		cond_resched();
655 	}
656 	return 0;
657 }
658 
659 static int slow_eval_unknown_fn(struct subchannel_id schid, void *data)
660 {
661 	int eval;
662 	int rc = 0;
663 
664 	spin_lock_irq(&slow_subchannel_lock);
665 	eval = idset_sch_contains(slow_subchannel_set, schid);
666 	idset_sch_del(slow_subchannel_set, schid);
667 	spin_unlock_irq(&slow_subchannel_lock);
668 	if (eval) {
669 		rc = css_evaluate_new_subchannel(schid, 1);
670 		switch (rc) {
671 		case -EAGAIN:
672 			css_schedule_eval(schid);
673 			rc = 0;
674 			break;
675 		case -ENXIO:
676 		case -ENOMEM:
677 		case -EIO:
678 			/* These should abort looping */
679 			spin_lock_irq(&slow_subchannel_lock);
680 			idset_sch_del_subseq(slow_subchannel_set, schid);
681 			spin_unlock_irq(&slow_subchannel_lock);
682 			break;
683 		default:
684 			rc = 0;
685 		}
686 		/* Allow scheduling here since the containing loop might
687 		 * take a while.  */
688 		cond_resched();
689 	}
690 	return rc;
691 }
692 
693 static void css_slow_path_func(struct work_struct *unused)
694 {
695 	unsigned long flags;
696 
697 	CIO_TRACE_EVENT(4, "slowpath");
698 	for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn,
699 				   NULL);
700 	spin_lock_irqsave(&slow_subchannel_lock, flags);
701 	if (idset_is_empty(slow_subchannel_set)) {
702 		atomic_set(&css_eval_scheduled, 0);
703 		wake_up(&css_eval_wq);
704 	}
705 	spin_unlock_irqrestore(&slow_subchannel_lock, flags);
706 }
707 
708 static DECLARE_DELAYED_WORK(slow_path_work, css_slow_path_func);
709 struct workqueue_struct *cio_work_q;
710 
711 void css_schedule_eval(struct subchannel_id schid)
712 {
713 	unsigned long flags;
714 
715 	spin_lock_irqsave(&slow_subchannel_lock, flags);
716 	idset_sch_add(slow_subchannel_set, schid);
717 	atomic_set(&css_eval_scheduled, 1);
718 	queue_delayed_work(cio_work_q, &slow_path_work, 0);
719 	spin_unlock_irqrestore(&slow_subchannel_lock, flags);
720 }
721 
722 void css_schedule_eval_all(void)
723 {
724 	unsigned long flags;
725 
726 	spin_lock_irqsave(&slow_subchannel_lock, flags);
727 	idset_fill(slow_subchannel_set);
728 	atomic_set(&css_eval_scheduled, 1);
729 	queue_delayed_work(cio_work_q, &slow_path_work, 0);
730 	spin_unlock_irqrestore(&slow_subchannel_lock, flags);
731 }
732 
733 static int __unset_validpath(struct device *dev, void *data)
734 {
735 	struct idset *set = data;
736 	struct subchannel *sch = to_subchannel(dev);
737 	struct pmcw *pmcw = &sch->schib.pmcw;
738 
739 	/* Here we want to make sure that we are considering only those subchannels
740 	 * which do not have an operational device attached to it. This can be found
741 	 * with the help of PAM and POM values of pmcw. OPM provides the information
742 	 * about any path which is currently vary-off, so that we should not consider.
743 	 */
744 	if (sch->st == SUBCHANNEL_TYPE_IO &&
745 	    (sch->opm & pmcw->pam & pmcw->pom))
746 		idset_sch_del(set, sch->schid);
747 
748 	return 0;
749 }
750 
751 static int __unset_online(struct device *dev, void *data)
752 {
753 	struct idset *set = data;
754 	struct subchannel *sch = to_subchannel(dev);
755 
756 	if (sch->st == SUBCHANNEL_TYPE_IO && sch->config.ena)
757 		idset_sch_del(set, sch->schid);
758 
759 	return 0;
760 }
761 
762 void css_schedule_eval_cond(enum css_eval_cond cond, unsigned long delay)
763 {
764 	unsigned long flags;
765 	struct idset *set;
766 
767 	/* Find unregistered subchannels. */
768 	set = idset_sch_new();
769 	if (!set) {
770 		/* Fallback. */
771 		css_schedule_eval_all();
772 		return;
773 	}
774 	idset_fill(set);
775 	switch (cond) {
776 	case CSS_EVAL_NO_PATH:
777 		bus_for_each_dev(&css_bus_type, NULL, set, __unset_validpath);
778 		break;
779 	case CSS_EVAL_NOT_ONLINE:
780 		bus_for_each_dev(&css_bus_type, NULL, set, __unset_online);
781 		break;
782 	default:
783 		break;
784 	}
785 
786 	/* Apply to slow_subchannel_set. */
787 	spin_lock_irqsave(&slow_subchannel_lock, flags);
788 	idset_add_set(slow_subchannel_set, set);
789 	atomic_set(&css_eval_scheduled, 1);
790 	queue_delayed_work(cio_work_q, &slow_path_work, delay);
791 	spin_unlock_irqrestore(&slow_subchannel_lock, flags);
792 	idset_free(set);
793 }
794 
795 void css_wait_for_slow_path(void)
796 {
797 	flush_workqueue(cio_work_q);
798 }
799 
800 /* Schedule reprobing of all subchannels with no valid operational path. */
801 void css_schedule_reprobe(void)
802 {
803 	/* Schedule with a delay to allow merging of subsequent calls. */
804 	css_schedule_eval_cond(CSS_EVAL_NO_PATH, 1 * HZ);
805 }
806 EXPORT_SYMBOL_GPL(css_schedule_reprobe);
807 
808 /*
809  * Called from the machine check handler for subchannel report words.
810  */
811 static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
812 {
813 	struct subchannel_id mchk_schid;
814 	struct subchannel *sch;
815 
816 	if (overflow) {
817 		css_schedule_eval_all();
818 		return;
819 	}
820 	CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
821 		      "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
822 		      crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
823 		      crw0->erc, crw0->rsid);
824 	if (crw1)
825 		CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
826 			      "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
827 			      crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
828 			      crw1->anc, crw1->erc, crw1->rsid);
829 	init_subchannel_id(&mchk_schid);
830 	mchk_schid.sch_no = crw0->rsid;
831 	if (crw1)
832 		mchk_schid.ssid = (crw1->rsid >> 4) & 3;
833 
834 	if (crw0->erc == CRW_ERC_PMOD) {
835 		sch = get_subchannel_by_schid(mchk_schid);
836 		if (sch) {
837 			css_update_ssd_info(sch);
838 			put_device(&sch->dev);
839 		}
840 	}
841 	/*
842 	 * Since we are always presented with IPI in the CRW, we have to
843 	 * use stsch() to find out if the subchannel in question has come
844 	 * or gone.
845 	 */
846 	css_evaluate_subchannel(mchk_schid, 0);
847 }
848 
849 static void __init
850 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
851 {
852 	struct cpuid cpu_id;
853 
854 	if (css_general_characteristics.mcss) {
855 		css->global_pgid.pgid_high.ext_cssid.version = 0x80;
856 		css->global_pgid.pgid_high.ext_cssid.cssid =
857 			css->id_valid ? css->cssid : 0;
858 	} else {
859 		css->global_pgid.pgid_high.cpu_addr = stap();
860 	}
861 	get_cpu_id(&cpu_id);
862 	css->global_pgid.cpu_id = cpu_id.ident;
863 	css->global_pgid.cpu_model = cpu_id.machine;
864 	css->global_pgid.tod_high = tod_high;
865 }
866 
867 static void channel_subsystem_release(struct device *dev)
868 {
869 	struct channel_subsystem *css = to_css(dev);
870 
871 	mutex_destroy(&css->mutex);
872 	kfree(css);
873 }
874 
875 static ssize_t real_cssid_show(struct device *dev, struct device_attribute *a,
876 			       char *buf)
877 {
878 	struct channel_subsystem *css = to_css(dev);
879 
880 	if (!css->id_valid)
881 		return -EINVAL;
882 
883 	return sysfs_emit(buf, "%x\n", css->cssid);
884 }
885 static DEVICE_ATTR_RO(real_cssid);
886 
887 static ssize_t rescan_store(struct device *dev, struct device_attribute *a,
888 			    const char *buf, size_t count)
889 {
890 	CIO_TRACE_EVENT(4, "usr-rescan");
891 
892 	css_schedule_eval_all();
893 	css_complete_work();
894 
895 	return count;
896 }
897 static DEVICE_ATTR_WO(rescan);
898 
899 static ssize_t cm_enable_show(struct device *dev, struct device_attribute *a,
900 			      char *buf)
901 {
902 	struct channel_subsystem *css = to_css(dev);
903 	int ret;
904 
905 	mutex_lock(&css->mutex);
906 	ret = sysfs_emit(buf, "%x\n", css->cm_enabled);
907 	mutex_unlock(&css->mutex);
908 	return ret;
909 }
910 
911 static ssize_t cm_enable_store(struct device *dev, struct device_attribute *a,
912 			       const char *buf, size_t count)
913 {
914 	struct channel_subsystem *css = to_css(dev);
915 	unsigned long val;
916 	int ret;
917 
918 	ret = kstrtoul(buf, 16, &val);
919 	if (ret)
920 		return ret;
921 	mutex_lock(&css->mutex);
922 	switch (val) {
923 	case 0:
924 		ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
925 		break;
926 	case 1:
927 		ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
928 		break;
929 	default:
930 		ret = -EINVAL;
931 	}
932 	mutex_unlock(&css->mutex);
933 	return ret < 0 ? ret : count;
934 }
935 static DEVICE_ATTR_RW(cm_enable);
936 
937 static umode_t cm_enable_mode(struct kobject *kobj, struct attribute *attr,
938 			      int index)
939 {
940 	return css_chsc_characteristics.secm ? attr->mode : 0;
941 }
942 
943 static struct attribute *cssdev_attrs[] = {
944 	&dev_attr_real_cssid.attr,
945 	&dev_attr_rescan.attr,
946 	NULL,
947 };
948 
949 static struct attribute_group cssdev_attr_group = {
950 	.attrs = cssdev_attrs,
951 };
952 
953 static struct attribute *cssdev_cm_attrs[] = {
954 	&dev_attr_cm_enable.attr,
955 	NULL,
956 };
957 
958 static struct attribute_group cssdev_cm_attr_group = {
959 	.attrs = cssdev_cm_attrs,
960 	.is_visible = cm_enable_mode,
961 };
962 
963 static const struct attribute_group *cssdev_attr_groups[] = {
964 	&cssdev_attr_group,
965 	&cssdev_cm_attr_group,
966 	NULL,
967 };
968 
969 static int __init setup_css(int nr)
970 {
971 	struct channel_subsystem *css;
972 	int ret;
973 
974 	css = kzalloc_obj(*css);
975 	if (!css)
976 		return -ENOMEM;
977 
978 	channel_subsystems[nr] = css;
979 	dev_set_name(&css->device, "css%x", nr);
980 	css->device.groups = cssdev_attr_groups;
981 	css->device.release = channel_subsystem_release;
982 	/*
983 	 * We currently allocate notifier bits with this (using
984 	 * css->device as the device argument with the DMA API)
985 	 * and are fine with 64 bit addresses.
986 	 */
987 	ret = dma_coerce_mask_and_coherent(&css->device, DMA_BIT_MASK(64));
988 	if (ret) {
989 		kfree(css);
990 		goto out_err;
991 	}
992 
993 	mutex_init(&css->mutex);
994 	ret = chsc_get_cssid_iid(nr, &css->cssid, &css->iid);
995 	if (!ret) {
996 		css->id_valid = true;
997 		pr_info("Partition identifier %01x.%01x\n", css->cssid,
998 			css->iid);
999 	}
1000 	css_generate_pgid(css, (u32) (get_tod_clock() >> 32));
1001 
1002 	ret = device_register(&css->device);
1003 	if (ret) {
1004 		put_device(&css->device);
1005 		goto out_err;
1006 	}
1007 
1008 	css->pseudo_subchannel = kzalloc_obj(*css->pseudo_subchannel);
1009 	if (!css->pseudo_subchannel) {
1010 		device_unregister(&css->device);
1011 		ret = -ENOMEM;
1012 		goto out_err;
1013 	}
1014 
1015 	css->pseudo_subchannel->dev.parent = &css->device;
1016 	css->pseudo_subchannel->dev.release = css_subchannel_release;
1017 	mutex_init(&css->pseudo_subchannel->reg_mutex);
1018 	css_sch_create_locks(css->pseudo_subchannel);
1019 
1020 	dev_set_name(&css->pseudo_subchannel->dev, "defunct");
1021 	ret = device_register(&css->pseudo_subchannel->dev);
1022 	if (ret) {
1023 		put_device(&css->pseudo_subchannel->dev);
1024 		device_unregister(&css->device);
1025 		goto out_err;
1026 	}
1027 
1028 	return ret;
1029 out_err:
1030 	channel_subsystems[nr] = NULL;
1031 	return ret;
1032 }
1033 
1034 static int css_reboot_event(struct notifier_block *this,
1035 			    unsigned long event,
1036 			    void *ptr)
1037 {
1038 	struct channel_subsystem *css;
1039 	int ret;
1040 
1041 	ret = NOTIFY_DONE;
1042 	for_each_css(css) {
1043 		mutex_lock(&css->mutex);
1044 		if (css->cm_enabled)
1045 			if (chsc_secm(css, 0))
1046 				ret = NOTIFY_BAD;
1047 		mutex_unlock(&css->mutex);
1048 	}
1049 
1050 	return ret;
1051 }
1052 
1053 static struct notifier_block css_reboot_notifier = {
1054 	.notifier_call = css_reboot_event,
1055 };
1056 
1057 #define  CIO_DMA_GFP (GFP_KERNEL | __GFP_ZERO)
1058 static struct gen_pool *cio_dma_pool;
1059 
1060 /* Currently cio supports only a single css */
1061 struct device *cio_get_dma_css_dev(void)
1062 {
1063 	return &channel_subsystems[0]->device;
1064 }
1065 
1066 struct gen_pool *cio_gp_dma_create(struct device *dma_dev, int nr_pages)
1067 {
1068 	struct gen_pool *gp_dma;
1069 	void *cpu_addr;
1070 	dma_addr_t dma_addr;
1071 	int i;
1072 
1073 	gp_dma = gen_pool_create(3, -1);
1074 	if (!gp_dma)
1075 		return NULL;
1076 	for (i = 0; i < nr_pages; ++i) {
1077 		cpu_addr = dma_alloc_coherent(dma_dev, PAGE_SIZE, &dma_addr,
1078 					      CIO_DMA_GFP);
1079 		if (!cpu_addr)
1080 			return gp_dma;
1081 		gen_pool_add_virt(gp_dma, (unsigned long) cpu_addr,
1082 				  dma_addr, PAGE_SIZE, -1);
1083 	}
1084 	return gp_dma;
1085 }
1086 
1087 static void __gp_dma_free_dma(struct gen_pool *pool,
1088 			      struct gen_pool_chunk *chunk, void *data)
1089 {
1090 	size_t chunk_size = chunk->end_addr - chunk->start_addr + 1;
1091 
1092 	dma_free_coherent((struct device *) data, chunk_size,
1093 			 (void *) chunk->start_addr,
1094 			 (dma_addr_t) chunk->phys_addr);
1095 }
1096 
1097 void cio_gp_dma_destroy(struct gen_pool *gp_dma, struct device *dma_dev)
1098 {
1099 	if (!gp_dma)
1100 		return;
1101 	/* this is quite ugly but no better idea */
1102 	gen_pool_for_each_chunk(gp_dma, __gp_dma_free_dma, dma_dev);
1103 	gen_pool_destroy(gp_dma);
1104 }
1105 
1106 static int cio_dma_pool_init(void)
1107 {
1108 	/* No need to free up the resources: compiled in */
1109 	cio_dma_pool = cio_gp_dma_create(cio_get_dma_css_dev(), 1);
1110 	if (!cio_dma_pool)
1111 		return -ENOMEM;
1112 	return 0;
1113 }
1114 
1115 void *__cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,
1116 			  size_t size, dma32_t *dma_handle)
1117 {
1118 	dma_addr_t dma_addr;
1119 	size_t chunk_size;
1120 	void *addr;
1121 
1122 	if (!gp_dma)
1123 		return NULL;
1124 	addr = gen_pool_dma_alloc(gp_dma, size, &dma_addr);
1125 	while (!addr) {
1126 		chunk_size = round_up(size, PAGE_SIZE);
1127 		addr = dma_alloc_coherent(dma_dev, chunk_size, &dma_addr, CIO_DMA_GFP);
1128 		if (!addr)
1129 			return NULL;
1130 		gen_pool_add_virt(gp_dma, (unsigned long)addr, dma_addr, chunk_size, -1);
1131 		addr = gen_pool_dma_alloc(gp_dma, size, dma_handle ? &dma_addr : NULL);
1132 	}
1133 	if (dma_handle)
1134 		*dma_handle = (__force dma32_t)dma_addr;
1135 	return addr;
1136 }
1137 
1138 void *cio_gp_dma_zalloc(struct gen_pool *gp_dma, struct device *dma_dev,
1139 			size_t size)
1140 {
1141 	return __cio_gp_dma_zalloc(gp_dma, dma_dev, size, NULL);
1142 }
1143 
1144 void cio_gp_dma_free(struct gen_pool *gp_dma, void *cpu_addr, size_t size)
1145 {
1146 	if (!cpu_addr)
1147 		return;
1148 	memset(cpu_addr, 0, size);
1149 	gen_pool_free(gp_dma, (unsigned long) cpu_addr, size);
1150 }
1151 
1152 /*
1153  * Allocate dma memory from the css global pool. Intended for memory not
1154  * specific to any single device within the css. The allocated memory
1155  * is not guaranteed to be 31-bit addressable.
1156  *
1157  * Caution: Not suitable for early stuff like console.
1158  */
1159 void *cio_dma_zalloc(size_t size)
1160 {
1161 	return cio_gp_dma_zalloc(cio_dma_pool, cio_get_dma_css_dev(), size);
1162 }
1163 
1164 void cio_dma_free(void *cpu_addr, size_t size)
1165 {
1166 	cio_gp_dma_free(cio_dma_pool, cpu_addr, size);
1167 }
1168 
1169 /*
1170  * Now that the driver core is running, we can setup our channel subsystem.
1171  * The struct subchannel's are created during probing.
1172  */
1173 static int __init css_bus_init(void)
1174 {
1175 	int ret, i;
1176 
1177 	ret = chsc_init();
1178 	if (ret)
1179 		return ret;
1180 
1181 	chsc_determine_css_characteristics();
1182 	/* Try to enable MSS. */
1183 	ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
1184 	if (ret)
1185 		max_ssid = 0;
1186 	else /* Success. */
1187 		max_ssid = __MAX_SSID;
1188 
1189 	ret = slow_subchannel_init();
1190 	if (ret)
1191 		goto out;
1192 
1193 	ret = crw_register_handler(CRW_RSC_SCH, css_process_crw);
1194 	if (ret)
1195 		goto out;
1196 
1197 	if ((ret = bus_register(&css_bus_type)))
1198 		goto out;
1199 
1200 	/* Setup css structure. */
1201 	for (i = 0; i <= MAX_CSS_IDX; i++) {
1202 		ret = setup_css(i);
1203 		if (ret)
1204 			goto out_unregister;
1205 	}
1206 	ret = register_reboot_notifier(&css_reboot_notifier);
1207 	if (ret)
1208 		goto out_unregister;
1209 	ret = cio_dma_pool_init();
1210 	if (ret)
1211 		goto out_unregister_rn;
1212 	airq_init();
1213 	css_init_done = 1;
1214 
1215 	/* Enable default isc for I/O subchannels. */
1216 	isc_register(IO_SCH_ISC);
1217 
1218 	return 0;
1219 out_unregister_rn:
1220 	unregister_reboot_notifier(&css_reboot_notifier);
1221 out_unregister:
1222 	while (i-- > 0) {
1223 		struct channel_subsystem *css = channel_subsystems[i];
1224 		device_unregister(&css->pseudo_subchannel->dev);
1225 		device_unregister(&css->device);
1226 	}
1227 	bus_unregister(&css_bus_type);
1228 out:
1229 	crw_unregister_handler(CRW_RSC_SCH);
1230 	idset_free(slow_subchannel_set);
1231 	chsc_init_cleanup();
1232 	pr_alert("The CSS device driver initialization failed with "
1233 		 "errno=%d\n", ret);
1234 	return ret;
1235 }
1236 
1237 static void __init css_bus_cleanup(void)
1238 {
1239 	struct channel_subsystem *css;
1240 
1241 	for_each_css(css) {
1242 		device_unregister(&css->pseudo_subchannel->dev);
1243 		device_unregister(&css->device);
1244 	}
1245 	bus_unregister(&css_bus_type);
1246 	crw_unregister_handler(CRW_RSC_SCH);
1247 	idset_free(slow_subchannel_set);
1248 	chsc_init_cleanup();
1249 	isc_unregister(IO_SCH_ISC);
1250 }
1251 
1252 static int __init channel_subsystem_init(void)
1253 {
1254 	int ret;
1255 
1256 	ret = css_bus_init();
1257 	if (ret)
1258 		return ret;
1259 	cio_work_q = create_singlethread_workqueue("cio");
1260 	if (!cio_work_q) {
1261 		ret = -ENOMEM;
1262 		goto out_bus;
1263 	}
1264 	ret = io_subchannel_init();
1265 	if (ret)
1266 		goto out_wq;
1267 
1268 	/* Register subchannels which are already in use. */
1269 	cio_register_early_subchannels();
1270 	/* Start initial subchannel evaluation. */
1271 	css_schedule_eval_all();
1272 
1273 	return ret;
1274 out_wq:
1275 	destroy_workqueue(cio_work_q);
1276 out_bus:
1277 	css_bus_cleanup();
1278 	return ret;
1279 }
1280 subsys_initcall(channel_subsystem_init);
1281 
1282 static int css_settle(struct device_driver *drv, void *unused)
1283 {
1284 	struct css_driver *cssdrv = to_cssdriver(drv);
1285 
1286 	if (cssdrv->settle)
1287 		return cssdrv->settle();
1288 	return 0;
1289 }
1290 
1291 int css_complete_work(void)
1292 {
1293 	int ret;
1294 
1295 	/* Wait for the evaluation of subchannels to finish. */
1296 	ret = wait_event_interruptible(css_eval_wq,
1297 				       atomic_read(&css_eval_scheduled) == 0);
1298 	if (ret)
1299 		return -EINTR;
1300 	flush_workqueue(cio_work_q);
1301 	/* Wait for the subchannel type specific initialization to finish */
1302 	return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle);
1303 }
1304 
1305 
1306 /*
1307  * Wait for the initialization of devices to finish, to make sure we are
1308  * done with our setup if the search for the root device starts.
1309  */
1310 static int __init channel_subsystem_init_sync(void)
1311 {
1312 	css_complete_work();
1313 	return 0;
1314 }
1315 subsys_initcall_sync(channel_subsystem_init_sync);
1316 
1317 #ifdef CONFIG_PROC_FS
1318 static ssize_t cio_settle_write(struct file *file, const char __user *buf,
1319 				size_t count, loff_t *ppos)
1320 {
1321 	int ret;
1322 
1323 	/* Handle pending CRW's. */
1324 	crw_wait_for_channel_report();
1325 	ret = css_complete_work();
1326 
1327 	return ret ? ret : count;
1328 }
1329 
1330 static const struct proc_ops cio_settle_proc_ops = {
1331 	.proc_open	= nonseekable_open,
1332 	.proc_write	= cio_settle_write,
1333 };
1334 
1335 static int __init cio_settle_init(void)
1336 {
1337 	struct proc_dir_entry *entry;
1338 
1339 	entry = proc_create("cio_settle", S_IWUSR, NULL, &cio_settle_proc_ops);
1340 	if (!entry)
1341 		return -ENOMEM;
1342 	return 0;
1343 }
1344 device_initcall(cio_settle_init);
1345 #endif /*CONFIG_PROC_FS*/
1346 
1347 int sch_is_pseudo_sch(struct subchannel *sch)
1348 {
1349 	if (!sch->dev.parent)
1350 		return 0;
1351 	return sch == to_css(sch->dev.parent)->pseudo_subchannel;
1352 }
1353 
1354 static int css_bus_match(struct device *dev, const struct device_driver *drv)
1355 {
1356 	struct subchannel *sch = to_subchannel(dev);
1357 	const struct css_driver *driver = to_cssdriver(drv);
1358 	struct css_device_id *id;
1359 
1360 	/* When driver_override is set, only bind to the matching driver */
1361 	if (sch->driver_override && strcmp(sch->driver_override, drv->name))
1362 		return 0;
1363 
1364 	for (id = driver->subchannel_type; id->match_flags; id++) {
1365 		if (sch->st == id->type)
1366 			return 1;
1367 	}
1368 
1369 	return 0;
1370 }
1371 
1372 static int css_probe(struct device *dev)
1373 {
1374 	struct subchannel *sch;
1375 	int ret;
1376 
1377 	sch = to_subchannel(dev);
1378 	sch->driver = to_cssdriver(dev->driver);
1379 	ret = sch->driver->probe ? sch->driver->probe(sch) : 0;
1380 	if (ret)
1381 		sch->driver = NULL;
1382 	return ret;
1383 }
1384 
1385 static void css_remove(struct device *dev)
1386 {
1387 	struct subchannel *sch;
1388 
1389 	sch = to_subchannel(dev);
1390 	if (sch->driver->remove)
1391 		sch->driver->remove(sch);
1392 	sch->driver = NULL;
1393 }
1394 
1395 static void css_shutdown(struct device *dev)
1396 {
1397 	struct subchannel *sch;
1398 
1399 	sch = to_subchannel(dev);
1400 	if (sch->driver && sch->driver->shutdown)
1401 		sch->driver->shutdown(sch);
1402 }
1403 
1404 static int css_uevent(const struct device *dev, struct kobj_uevent_env *env)
1405 {
1406 	const struct subchannel *sch = to_subchannel(dev);
1407 	int ret;
1408 
1409 	ret = add_uevent_var(env, "ST=%01X", sch->st);
1410 	if (ret)
1411 		return ret;
1412 	ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
1413 	return ret;
1414 }
1415 
1416 static const struct bus_type css_bus_type = {
1417 	.name     = "css",
1418 	.match    = css_bus_match,
1419 	.probe    = css_probe,
1420 	.remove   = css_remove,
1421 	.shutdown = css_shutdown,
1422 	.uevent   = css_uevent,
1423 };
1424 
1425 /**
1426  * css_driver_register - register a css driver
1427  * @cdrv: css driver to register
1428  *
1429  * This is mainly a wrapper around driver_register that sets name
1430  * and bus_type in the embedded struct device_driver correctly.
1431  */
1432 int css_driver_register(struct css_driver *cdrv)
1433 {
1434 	cdrv->drv.bus = &css_bus_type;
1435 	return driver_register(&cdrv->drv);
1436 }
1437 EXPORT_SYMBOL_GPL(css_driver_register);
1438 
1439 /**
1440  * css_driver_unregister - unregister a css driver
1441  * @cdrv: css driver to unregister
1442  *
1443  * This is a wrapper around driver_unregister.
1444  */
1445 void css_driver_unregister(struct css_driver *cdrv)
1446 {
1447 	driver_unregister(&cdrv->drv);
1448 }
1449 EXPORT_SYMBOL_GPL(css_driver_unregister);
1450