| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  drivers/s390/cio/css.c | 
 | 3 |  *  driver for channel subsystem | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * | 
 | 5 |  *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, | 
 | 6 |  *			 IBM Corporation | 
 | 7 |  *    Author(s): Arnd Bergmann (arndb@de.ibm.com) | 
| Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 8 |  *		 Cornelia Huck (cornelia.huck@de.ibm.com) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  */ | 
 | 10 | #include <linux/module.h> | 
 | 11 | #include <linux/init.h> | 
 | 12 | #include <linux/device.h> | 
 | 13 | #include <linux/slab.h> | 
 | 14 | #include <linux/errno.h> | 
 | 15 | #include <linux/list.h> | 
 | 16 |  | 
 | 17 | #include "css.h" | 
 | 18 | #include "cio.h" | 
 | 19 | #include "cio_debug.h" | 
 | 20 | #include "ioasm.h" | 
 | 21 | #include "chsc.h" | 
| Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 22 | #include "device.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | int need_rescan = 0; | 
 | 25 | int css_init_done = 0; | 
| Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 26 | static int need_reprobe = 0; | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 27 | static int max_ssid = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 |  | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 29 | struct channel_subsystem *css[__MAX_CSSID + 1]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 31 | int css_characteristics_avail = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 |  | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 33 | inline int | 
 | 34 | for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data) | 
 | 35 | { | 
 | 36 | 	struct subchannel_id schid; | 
 | 37 | 	int ret; | 
 | 38 |  | 
 | 39 | 	init_subchannel_id(&schid); | 
 | 40 | 	ret = -ENODEV; | 
 | 41 | 	do { | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 42 | 		do { | 
 | 43 | 			ret = fn(schid, data); | 
 | 44 | 			if (ret) | 
 | 45 | 				break; | 
 | 46 | 		} while (schid.sch_no++ < __MAX_SUBCHANNEL); | 
 | 47 | 		schid.sch_no = 0; | 
 | 48 | 	} while (schid.ssid++ < max_ssid); | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 49 | 	return ret; | 
 | 50 | } | 
 | 51 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static struct subchannel * | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 53 | css_alloc_subchannel(struct subchannel_id schid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { | 
 | 55 | 	struct subchannel *sch; | 
 | 56 | 	int ret; | 
 | 57 |  | 
 | 58 | 	sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA); | 
 | 59 | 	if (sch == NULL) | 
 | 60 | 		return ERR_PTR(-ENOMEM); | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 61 | 	ret = cio_validate_subchannel (sch, schid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | 	if (ret < 0) { | 
 | 63 | 		kfree(sch); | 
 | 64 | 		return ERR_PTR(ret); | 
 | 65 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
 | 67 | 	if (sch->st != SUBCHANNEL_TYPE_IO) { | 
 | 68 | 		/* For now we ignore all non-io subchannels. */ | 
 | 69 | 		kfree(sch); | 
 | 70 | 		return ERR_PTR(-EINVAL); | 
 | 71 | 	} | 
 | 72 |  | 
 | 73 | 	/*  | 
 | 74 | 	 * Set intparm to subchannel address. | 
 | 75 | 	 * This is fine even on 64bit since the subchannel is always located | 
 | 76 | 	 * under 2G. | 
 | 77 | 	 */ | 
 | 78 | 	sch->schib.pmcw.intparm = (__u32)(unsigned long)sch; | 
 | 79 | 	ret = cio_modify(sch); | 
 | 80 | 	if (ret) { | 
 | 81 | 		kfree(sch); | 
 | 82 | 		return ERR_PTR(ret); | 
 | 83 | 	} | 
 | 84 | 	return sch; | 
 | 85 | } | 
 | 86 |  | 
 | 87 | static void | 
 | 88 | css_free_subchannel(struct subchannel *sch) | 
 | 89 | { | 
 | 90 | 	if (sch) { | 
 | 91 | 		/* Reset intparm to zeroes. */ | 
 | 92 | 		sch->schib.pmcw.intparm = 0; | 
 | 93 | 		cio_modify(sch); | 
 | 94 | 		kfree(sch); | 
 | 95 | 	} | 
 | 96 | 	 | 
 | 97 | } | 
 | 98 |  | 
 | 99 | static void | 
 | 100 | css_subchannel_release(struct device *dev) | 
 | 101 | { | 
 | 102 | 	struct subchannel *sch; | 
 | 103 |  | 
 | 104 | 	sch = to_subchannel(dev); | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 105 | 	if (!cio_is_console(sch->schid)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | 		kfree(sch); | 
 | 107 | } | 
 | 108 |  | 
 | 109 | extern int css_get_ssd_info(struct subchannel *sch); | 
 | 110 |  | 
| Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 111 |  | 
 | 112 | int css_sch_device_register(struct subchannel *sch) | 
 | 113 | { | 
 | 114 | 	int ret; | 
 | 115 |  | 
 | 116 | 	mutex_lock(&sch->reg_mutex); | 
 | 117 | 	ret = device_register(&sch->dev); | 
 | 118 | 	mutex_unlock(&sch->reg_mutex); | 
 | 119 | 	return ret; | 
 | 120 | } | 
 | 121 |  | 
 | 122 | void css_sch_device_unregister(struct subchannel *sch) | 
 | 123 | { | 
 | 124 | 	mutex_lock(&sch->reg_mutex); | 
 | 125 | 	device_unregister(&sch->dev); | 
 | 126 | 	mutex_unlock(&sch->reg_mutex); | 
 | 127 | } | 
 | 128 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | static int | 
 | 130 | css_register_subchannel(struct subchannel *sch) | 
 | 131 | { | 
 | 132 | 	int ret; | 
 | 133 |  | 
 | 134 | 	/* Initialize the subchannel structure */ | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 135 | 	sch->dev.parent = &css[0]->device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | 	sch->dev.bus = &css_bus_type; | 
 | 137 | 	sch->dev.release = &css_subchannel_release; | 
 | 138 | 	 | 
 | 139 | 	/* make it known to the system */ | 
| Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 140 | 	ret = css_sch_device_register(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | 	if (ret) | 
 | 142 | 		printk (KERN_WARNING "%s: could not register %s\n", | 
 | 143 | 			__func__, sch->dev.bus_id); | 
 | 144 | 	else | 
 | 145 | 		css_get_ssd_info(sch); | 
 | 146 | 	return ret; | 
 | 147 | } | 
 | 148 |  | 
 | 149 | int | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 150 | css_probe_device(struct subchannel_id schid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { | 
 | 152 | 	int ret; | 
 | 153 | 	struct subchannel *sch; | 
 | 154 |  | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 155 | 	sch = css_alloc_subchannel(schid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | 	if (IS_ERR(sch)) | 
 | 157 | 		return PTR_ERR(sch); | 
 | 158 | 	ret = css_register_subchannel(sch); | 
 | 159 | 	if (ret) | 
 | 160 | 		css_free_subchannel(sch); | 
 | 161 | 	return ret; | 
 | 162 | } | 
 | 163 |  | 
| Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 164 | static int | 
 | 165 | check_subchannel(struct device * dev, void * data) | 
 | 166 | { | 
 | 167 | 	struct subchannel *sch; | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 168 | 	struct subchannel_id *schid = data; | 
| Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 169 |  | 
 | 170 | 	sch = to_subchannel(dev); | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 171 | 	return schid_equal(&sch->schid, schid); | 
| Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 172 | } | 
 | 173 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | struct subchannel * | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 175 | get_subchannel_by_schid(struct subchannel_id schid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | 	struct device *dev; | 
 | 178 |  | 
| Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 179 | 	dev = bus_find_device(&css_bus_type, NULL, | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 180 | 			      (void *)&schid, check_subchannel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
| Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 182 | 	return dev ? to_subchannel(dev) : NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } | 
 | 184 |  | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 185 | static inline int css_get_subchannel_status(struct subchannel *sch) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { | 
 | 187 | 	struct schib schib; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 |  | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 189 | 	if (stsch(sch->schid, &schib) || !schib.pmcw.dnv) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | 		return CIO_GONE; | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 191 | 	if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | 		return CIO_REVALIDATE; | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 193 | 	if (!sch->lpm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | 		return CIO_NO_PATH; | 
 | 195 | 	return CIO_OPER; | 
 | 196 | } | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 197 |  | 
 | 198 | static int css_evaluate_known_subchannel(struct subchannel *sch, int slow) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { | 
 | 200 | 	int event, ret, disc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | 	unsigned long flags; | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 202 | 	enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 |  | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 204 | 	spin_lock_irqsave(&sch->lock, flags); | 
 | 205 | 	disc = device_is_disconnected(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | 	if (disc && slow) { | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 207 | 		/* Disconnected devices are evaluated directly only.*/ | 
 | 208 | 		spin_unlock_irqrestore(&sch->lock, flags); | 
 | 209 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | 	} | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 211 | 	/* No interrupt after machine check - kill pending timers. */ | 
 | 212 | 	device_kill_pending_timer(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | 	if (!disc && !slow) { | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 214 | 		/* Non-disconnected devices are evaluated on the slow path. */ | 
 | 215 | 		spin_unlock_irqrestore(&sch->lock, flags); | 
 | 216 | 		return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | 	} | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 218 | 	event = css_get_subchannel_status(sch); | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 219 | 	CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n", | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 220 | 		      sch->schid.ssid, sch->schid.sch_no, event, | 
 | 221 | 		      disc ? "disconnected" : "normal", | 
 | 222 | 		      slow ? "slow" : "fast"); | 
 | 223 | 	/* Analyze subchannel status. */ | 
 | 224 | 	action = NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | 	switch (event) { | 
 | 226 | 	case CIO_NO_PATH: | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 227 | 		if (disc) { | 
 | 228 | 			/* Check if paths have become available. */ | 
 | 229 | 			action = REPROBE; | 
 | 230 | 			break; | 
 | 231 | 		} | 
 | 232 | 		/* fall through */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | 	case CIO_GONE: | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 234 | 		/* Prevent unwanted effects when opening lock. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | 		cio_disable_subchannel(sch); | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 236 | 		device_set_disconnected(sch); | 
 | 237 | 		/* Ask driver what to do with device. */ | 
 | 238 | 		action = UNREGISTER; | 
 | 239 | 		if (sch->driver && sch->driver->notify) { | 
 | 240 | 			spin_unlock_irqrestore(&sch->lock, flags); | 
 | 241 | 			ret = sch->driver->notify(&sch->dev, event); | 
 | 242 | 			spin_lock_irqsave(&sch->lock, flags); | 
 | 243 | 			if (ret) | 
 | 244 | 				action = NONE; | 
 | 245 | 		} | 
 | 246 | 		break; | 
 | 247 | 	case CIO_REVALIDATE: | 
 | 248 | 		/* Device will be removed, so no notify necessary. */ | 
 | 249 | 		if (disc) | 
 | 250 | 			/* Reprobe because immediate unregister might block. */ | 
 | 251 | 			action = REPROBE; | 
 | 252 | 		else | 
 | 253 | 			action = UNREGISTER_PROBE; | 
 | 254 | 		break; | 
 | 255 | 	case CIO_OPER: | 
 | 256 | 		if (disc) | 
 | 257 | 			/* Get device operational again. */ | 
 | 258 | 			action = REPROBE; | 
 | 259 | 		break; | 
 | 260 | 	} | 
 | 261 | 	/* Perform action. */ | 
 | 262 | 	ret = 0; | 
 | 263 | 	switch (action) { | 
 | 264 | 	case UNREGISTER: | 
 | 265 | 	case UNREGISTER_PROBE: | 
 | 266 | 		/* Unregister device (will use subchannel lock). */ | 
 | 267 | 		spin_unlock_irqrestore(&sch->lock, flags); | 
| Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 268 | 		css_sch_device_unregister(sch); | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 269 | 		spin_lock_irqsave(&sch->lock, flags); | 
 | 270 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 		/* Reset intparm to zeroes. */ | 
 | 272 | 		sch->schib.pmcw.intparm = 0; | 
 | 273 | 		cio_modify(sch); | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 274 |  | 
 | 275 | 		/* Probe if necessary. */ | 
 | 276 | 		if (action == UNREGISTER_PROBE) | 
 | 277 | 			ret = css_probe_device(sch->schid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | 		break; | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 279 | 	case REPROBE: | 
 | 280 | 		device_trigger_reprobe(sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | 		break; | 
 | 282 | 	default: | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 283 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | 	} | 
| Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 285 | 	spin_unlock_irqrestore(&sch->lock, flags); | 
 | 286 |  | 
 | 287 | 	return ret; | 
 | 288 | } | 
 | 289 |  | 
 | 290 | static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow) | 
 | 291 | { | 
 | 292 | 	struct schib schib; | 
 | 293 |  | 
 | 294 | 	if (!slow) { | 
 | 295 | 		/* Will be done on the slow path. */ | 
 | 296 | 		return -EAGAIN; | 
 | 297 | 	} | 
 | 298 | 	if (stsch(schid, &schib) || !schib.pmcw.dnv) { | 
 | 299 | 		/* Unusable - ignore. */ | 
 | 300 | 		return 0; | 
 | 301 | 	} | 
 | 302 | 	CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, " | 
 | 303 | 			 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER); | 
 | 304 |  | 
 | 305 | 	return css_probe_device(schid); | 
 | 306 | } | 
 | 307 |  | 
 | 308 | static int css_evaluate_subchannel(struct subchannel_id schid, int slow) | 
 | 309 | { | 
 | 310 | 	struct subchannel *sch; | 
 | 311 | 	int ret; | 
 | 312 |  | 
 | 313 | 	sch = get_subchannel_by_schid(schid); | 
 | 314 | 	if (sch) { | 
 | 315 | 		ret = css_evaluate_known_subchannel(sch, slow); | 
 | 316 | 		put_device(&sch->dev); | 
 | 317 | 	} else | 
 | 318 | 		ret = css_evaluate_new_subchannel(schid, slow); | 
 | 319 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | 	return ret; | 
 | 321 | } | 
 | 322 |  | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 323 | static int | 
 | 324 | css_rescan_devices(struct subchannel_id schid, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 326 | 	return css_evaluate_subchannel(schid, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } | 
 | 328 |  | 
 | 329 | struct slow_subchannel { | 
 | 330 | 	struct list_head slow_list; | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 331 | 	struct subchannel_id schid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | }; | 
 | 333 |  | 
 | 334 | static LIST_HEAD(slow_subchannels_head); | 
 | 335 | static DEFINE_SPINLOCK(slow_subchannel_lock); | 
 | 336 |  | 
 | 337 | static void | 
 | 338 | css_trigger_slow_path(void) | 
 | 339 | { | 
 | 340 | 	CIO_TRACE_EVENT(4, "slowpath"); | 
 | 341 |  | 
 | 342 | 	if (need_rescan) { | 
 | 343 | 		need_rescan = 0; | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 344 | 		for_each_subchannel(css_rescan_devices, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | 		return; | 
 | 346 | 	} | 
 | 347 |  | 
 | 348 | 	spin_lock_irq(&slow_subchannel_lock); | 
 | 349 | 	while (!list_empty(&slow_subchannels_head)) { | 
 | 350 | 		struct slow_subchannel *slow_sch = | 
 | 351 | 			list_entry(slow_subchannels_head.next, | 
 | 352 | 				   struct slow_subchannel, slow_list); | 
 | 353 |  | 
 | 354 | 		list_del_init(slow_subchannels_head.next); | 
 | 355 | 		spin_unlock_irq(&slow_subchannel_lock); | 
 | 356 | 		css_evaluate_subchannel(slow_sch->schid, 1); | 
 | 357 | 		spin_lock_irq(&slow_subchannel_lock); | 
 | 358 | 		kfree(slow_sch); | 
 | 359 | 	} | 
 | 360 | 	spin_unlock_irq(&slow_subchannel_lock); | 
 | 361 | } | 
 | 362 |  | 
 | 363 | typedef void (*workfunc)(void *); | 
 | 364 | DECLARE_WORK(slow_path_work, (workfunc)css_trigger_slow_path, NULL); | 
 | 365 | struct workqueue_struct *slow_path_wq; | 
 | 366 |  | 
| Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 367 | /* Reprobe subchannel if unregistered. */ | 
 | 368 | static int reprobe_subchannel(struct subchannel_id schid, void *data) | 
 | 369 | { | 
 | 370 | 	struct subchannel *sch; | 
 | 371 | 	int ret; | 
 | 372 |  | 
 | 373 | 	CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n", | 
 | 374 | 		  schid.ssid, schid.sch_no); | 
 | 375 | 	if (need_reprobe) | 
 | 376 | 		return -EAGAIN; | 
 | 377 |  | 
 | 378 | 	sch = get_subchannel_by_schid(schid); | 
 | 379 | 	if (sch) { | 
 | 380 | 		/* Already known. */ | 
 | 381 | 		put_device(&sch->dev); | 
 | 382 | 		return 0; | 
 | 383 | 	} | 
 | 384 |  | 
 | 385 | 	ret = css_probe_device(schid); | 
 | 386 | 	switch (ret) { | 
 | 387 | 	case 0: | 
 | 388 | 		break; | 
 | 389 | 	case -ENXIO: | 
 | 390 | 	case -ENOMEM: | 
 | 391 | 		/* These should abort looping */ | 
 | 392 | 		break; | 
 | 393 | 	default: | 
 | 394 | 		ret = 0; | 
 | 395 | 	} | 
 | 396 |  | 
 | 397 | 	return ret; | 
 | 398 | } | 
 | 399 |  | 
 | 400 | /* Work function used to reprobe all unregistered subchannels. */ | 
 | 401 | static void reprobe_all(void *data) | 
 | 402 | { | 
 | 403 | 	int ret; | 
 | 404 |  | 
 | 405 | 	CIO_MSG_EVENT(2, "reprobe start\n"); | 
 | 406 |  | 
 | 407 | 	need_reprobe = 0; | 
 | 408 | 	/* Make sure initial subchannel scan is done. */ | 
 | 409 | 	wait_event(ccw_device_init_wq, | 
 | 410 | 		   atomic_read(&ccw_device_init_count) == 0); | 
 | 411 | 	ret = for_each_subchannel(reprobe_subchannel, NULL); | 
 | 412 |  | 
 | 413 | 	CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret, | 
 | 414 | 		      need_reprobe); | 
 | 415 | } | 
 | 416 |  | 
 | 417 | DECLARE_WORK(css_reprobe_work, reprobe_all, NULL); | 
 | 418 |  | 
 | 419 | /* Schedule reprobing of all unregistered subchannels. */ | 
 | 420 | void css_schedule_reprobe(void) | 
 | 421 | { | 
 | 422 | 	need_reprobe = 1; | 
 | 423 | 	queue_work(ccw_device_work, &css_reprobe_work); | 
 | 424 | } | 
 | 425 |  | 
 | 426 | EXPORT_SYMBOL_GPL(css_schedule_reprobe); | 
 | 427 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* | 
 | 429 |  * Rescan for new devices. FIXME: This is slow. | 
 | 430 |  * This function is called when we have lost CRWs due to overflows and we have | 
 | 431 |  * to do subchannel housekeeping. | 
 | 432 |  */ | 
 | 433 | void | 
 | 434 | css_reiterate_subchannels(void) | 
 | 435 | { | 
 | 436 | 	css_clear_subchannel_slow_list(); | 
 | 437 | 	need_rescan = 1; | 
 | 438 | } | 
 | 439 |  | 
 | 440 | /* | 
 | 441 |  * Called from the machine check handler for subchannel report words. | 
 | 442 |  */ | 
 | 443 | int | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 444 | css_process_crw(int rsid1, int rsid2) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { | 
 | 446 | 	int ret; | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 447 | 	struct subchannel_id mchk_schid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |  | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 449 | 	CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n", | 
 | 450 | 		      rsid1, rsid2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 |  | 
 | 452 | 	if (need_rescan) | 
 | 453 | 		/* We need to iterate all subchannels anyway. */ | 
 | 454 | 		return -EAGAIN; | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 455 |  | 
 | 456 | 	init_subchannel_id(&mchk_schid); | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 457 | 	mchk_schid.sch_no = rsid1; | 
 | 458 | 	if (rsid2 != 0) | 
 | 459 | 		mchk_schid.ssid = (rsid2 >> 8) & 3; | 
 | 460 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | 	/*  | 
 | 462 | 	 * Since we are always presented with IPI in the CRW, we have to | 
 | 463 | 	 * use stsch() to find out if the subchannel in question has come | 
 | 464 | 	 * or gone. | 
 | 465 | 	 */ | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 466 | 	ret = css_evaluate_subchannel(mchk_schid, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | 	if (ret == -EAGAIN) { | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 468 | 		if (css_enqueue_subchannel_slow(mchk_schid)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | 			css_clear_subchannel_slow_list(); | 
 | 470 | 			need_rescan = 1; | 
 | 471 | 		} | 
 | 472 | 	} | 
 | 473 | 	return ret; | 
 | 474 | } | 
 | 475 |  | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 476 | static int __init | 
 | 477 | __init_channel_subsystem(struct subchannel_id schid, void *data) | 
 | 478 | { | 
 | 479 | 	struct subchannel *sch; | 
 | 480 | 	int ret; | 
 | 481 |  | 
 | 482 | 	if (cio_is_console(schid)) | 
 | 483 | 		sch = cio_get_console_subchannel(); | 
 | 484 | 	else { | 
 | 485 | 		sch = css_alloc_subchannel(schid); | 
 | 486 | 		if (IS_ERR(sch)) | 
 | 487 | 			ret = PTR_ERR(sch); | 
 | 488 | 		else | 
 | 489 | 			ret = 0; | 
 | 490 | 		switch (ret) { | 
 | 491 | 		case 0: | 
 | 492 | 			break; | 
 | 493 | 		case -ENOMEM: | 
 | 494 | 			panic("Out of memory in init_channel_subsystem\n"); | 
 | 495 | 		/* -ENXIO: no more subchannels. */ | 
 | 496 | 		case -ENXIO: | 
 | 497 | 			return ret; | 
| Greg Smith | e843e28 | 2006-03-14 19:50:17 -0800 | [diff] [blame] | 498 | 		/* -EIO: this subchannel set not supported. */ | 
 | 499 | 		case -EIO: | 
 | 500 | 			return ret; | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 501 | 		default: | 
 | 502 | 			return 0; | 
 | 503 | 		} | 
 | 504 | 	} | 
 | 505 | 	/* | 
 | 506 | 	 * We register ALL valid subchannels in ioinfo, even those | 
 | 507 | 	 * that have been present before init_channel_subsystem. | 
 | 508 | 	 * These subchannels can't have been registered yet (kmalloc | 
 | 509 | 	 * not working) so we do it now. This is true e.g. for the | 
 | 510 | 	 * console subchannel. | 
 | 511 | 	 */ | 
 | 512 | 	css_register_subchannel(sch); | 
 | 513 | 	return 0; | 
 | 514 | } | 
 | 515 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | static void __init | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 517 | css_generate_pgid(struct channel_subsystem *css, u32 tod_high) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 519 | 	if (css_characteristics_avail && css_general_characteristics.mcss) { | 
 | 520 | 		css->global_pgid.pgid_high.ext_cssid.version = 0x80; | 
 | 521 | 		css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid; | 
 | 522 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | #ifdef CONFIG_SMP | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 524 | 		css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | #else | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 526 | 		css->global_pgid.pgid_high.cpu_addr = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | #endif | 
 | 528 | 	} | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 529 | 	css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident; | 
 | 530 | 	css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine; | 
 | 531 | 	css->global_pgid.tod_high = tod_high; | 
 | 532 |  | 
 | 533 | } | 
 | 534 |  | 
| Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 535 | static void | 
 | 536 | channel_subsystem_release(struct device *dev) | 
 | 537 | { | 
 | 538 | 	struct channel_subsystem *css; | 
 | 539 |  | 
 | 540 | 	css = to_css(dev); | 
| Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 541 | 	mutex_destroy(&css->mutex); | 
| Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 542 | 	kfree(css); | 
 | 543 | } | 
 | 544 |  | 
| Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 545 | static ssize_t | 
 | 546 | css_cm_enable_show(struct device *dev, struct device_attribute *attr, | 
 | 547 | 		   char *buf) | 
 | 548 | { | 
 | 549 | 	struct channel_subsystem *css = to_css(dev); | 
 | 550 |  | 
 | 551 | 	if (!css) | 
 | 552 | 		return 0; | 
 | 553 | 	return sprintf(buf, "%x\n", css->cm_enabled); | 
 | 554 | } | 
 | 555 |  | 
 | 556 | static ssize_t | 
 | 557 | css_cm_enable_store(struct device *dev, struct device_attribute *attr, | 
 | 558 | 		    const char *buf, size_t count) | 
 | 559 | { | 
 | 560 | 	struct channel_subsystem *css = to_css(dev); | 
 | 561 | 	int ret; | 
 | 562 |  | 
 | 563 | 	switch (buf[0]) { | 
 | 564 | 	case '0': | 
 | 565 | 		ret = css->cm_enabled ? chsc_secm(css, 0) : 0; | 
 | 566 | 		break; | 
 | 567 | 	case '1': | 
 | 568 | 		ret = css->cm_enabled ? 0 : chsc_secm(css, 1); | 
 | 569 | 		break; | 
 | 570 | 	default: | 
 | 571 | 		ret = -EINVAL; | 
 | 572 | 	} | 
 | 573 | 	return ret < 0 ? ret : count; | 
 | 574 | } | 
 | 575 |  | 
 | 576 | static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store); | 
 | 577 |  | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 578 | static inline void __init | 
 | 579 | setup_css(int nr) | 
 | 580 | { | 
 | 581 | 	u32 tod_high; | 
 | 582 |  | 
 | 583 | 	memset(css[nr], 0, sizeof(struct channel_subsystem)); | 
| Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 584 | 	mutex_init(&css[nr]->mutex); | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 585 | 	css[nr]->valid = 1; | 
 | 586 | 	css[nr]->cssid = nr; | 
 | 587 | 	sprintf(css[nr]->device.bus_id, "css%x", nr); | 
| Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 588 | 	css[nr]->device.release = channel_subsystem_release; | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 589 | 	tod_high = (u32) (get_clock() >> 32); | 
 | 590 | 	css_generate_pgid(css[nr], tod_high); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } | 
 | 592 |  | 
 | 593 | /* | 
 | 594 |  * Now that the driver core is running, we can setup our channel subsystem. | 
 | 595 |  * The struct subchannel's are created during probing (except for the | 
 | 596 |  * static console subchannel). | 
 | 597 |  */ | 
 | 598 | static int __init | 
 | 599 | init_channel_subsystem (void) | 
 | 600 | { | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 601 | 	int ret, i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 |  | 
 | 603 | 	if (chsc_determine_css_characteristics() == 0) | 
 | 604 | 		css_characteristics_avail = 1; | 
 | 605 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 	if ((ret = bus_register(&css_bus_type))) | 
 | 607 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 |  | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 609 | 	/* Try to enable MSS. */ | 
 | 610 | 	ret = chsc_enable_facility(CHSC_SDA_OC_MSS); | 
 | 611 | 	switch (ret) { | 
 | 612 | 	case 0: /* Success. */ | 
 | 613 | 		max_ssid = __MAX_SSID; | 
 | 614 | 		break; | 
 | 615 | 	case -ENOMEM: | 
 | 616 | 		goto out_bus; | 
 | 617 | 	default: | 
 | 618 | 		max_ssid = 0; | 
 | 619 | 	} | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 620 | 	/* Setup css structure. */ | 
 | 621 | 	for (i = 0; i <= __MAX_CSSID; i++) { | 
 | 622 | 		css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL); | 
 | 623 | 		if (!css[i]) { | 
 | 624 | 			ret = -ENOMEM; | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 625 | 			goto out_unregister; | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 626 | 		} | 
 | 627 | 		setup_css(i); | 
 | 628 | 		ret = device_register(&css[i]->device); | 
 | 629 | 		if (ret) | 
 | 630 | 			goto out_free; | 
| Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 631 | 		if (css_characteristics_avail && | 
 | 632 | 		    css_chsc_characteristics.secm) { | 
 | 633 | 			ret = device_create_file(&css[i]->device, | 
 | 634 | 						 &dev_attr_cm_enable); | 
 | 635 | 			if (ret) | 
 | 636 | 				goto out_device; | 
 | 637 | 		} | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 638 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | 	css_init_done = 1; | 
 | 640 |  | 
 | 641 | 	ctl_set_bit(6, 28); | 
 | 642 |  | 
| Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 643 | 	for_each_subchannel(__init_channel_subsystem, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | 	return 0; | 
| Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 645 | out_device: | 
 | 646 | 	device_unregister(&css[i]->device); | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 647 | out_free: | 
 | 648 | 	kfree(css[i]); | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 649 | out_unregister: | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 650 | 	while (i > 0) { | 
 | 651 | 		i--; | 
| Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 652 | 		if (css_characteristics_avail && css_chsc_characteristics.secm) | 
 | 653 | 			device_remove_file(&css[i]->device, | 
 | 654 | 					   &dev_attr_cm_enable); | 
| Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 655 | 		device_unregister(&css[i]->device); | 
 | 656 | 	} | 
| Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 657 | out_bus: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | 	bus_unregister(&css_bus_type); | 
 | 659 | out: | 
 | 660 | 	return ret; | 
 | 661 | } | 
 | 662 |  | 
 | 663 | /* | 
 | 664 |  * find a driver for a subchannel. They identify by the subchannel | 
 | 665 |  * type with the exception that the console subchannel driver has its own | 
 | 666 |  * subchannel type although the device is an i/o subchannel | 
 | 667 |  */ | 
 | 668 | static int | 
 | 669 | css_bus_match (struct device *dev, struct device_driver *drv) | 
 | 670 | { | 
 | 671 | 	struct subchannel *sch = container_of (dev, struct subchannel, dev); | 
 | 672 | 	struct css_driver *driver = container_of (drv, struct css_driver, drv); | 
 | 673 |  | 
 | 674 | 	if (sch->st == driver->subchannel_type) | 
 | 675 | 		return 1; | 
 | 676 |  | 
 | 677 | 	return 0; | 
 | 678 | } | 
 | 679 |  | 
| Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 680 | static int | 
 | 681 | css_probe (struct device *dev) | 
 | 682 | { | 
 | 683 | 	struct subchannel *sch; | 
 | 684 |  | 
 | 685 | 	sch = to_subchannel(dev); | 
 | 686 | 	sch->driver = container_of (dev->driver, struct css_driver, drv); | 
 | 687 | 	return (sch->driver->probe ? sch->driver->probe(sch) : 0); | 
 | 688 | } | 
 | 689 |  | 
 | 690 | static int | 
 | 691 | css_remove (struct device *dev) | 
 | 692 | { | 
 | 693 | 	struct subchannel *sch; | 
 | 694 |  | 
 | 695 | 	sch = to_subchannel(dev); | 
 | 696 | 	return (sch->driver->remove ? sch->driver->remove(sch) : 0); | 
 | 697 | } | 
 | 698 |  | 
 | 699 | static void | 
 | 700 | css_shutdown (struct device *dev) | 
 | 701 | { | 
 | 702 | 	struct subchannel *sch; | 
 | 703 |  | 
 | 704 | 	sch = to_subchannel(dev); | 
 | 705 | 	if (sch->driver->shutdown) | 
 | 706 | 		sch->driver->shutdown(sch); | 
 | 707 | } | 
 | 708 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | struct bus_type css_bus_type = { | 
| Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 710 | 	.name     = "css", | 
 | 711 | 	.match    = css_bus_match, | 
 | 712 | 	.probe    = css_probe, | 
 | 713 | 	.remove   = css_remove, | 
 | 714 | 	.shutdown = css_shutdown, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | }; | 
 | 716 |  | 
 | 717 | subsys_initcall(init_channel_subsystem); | 
 | 718 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | int | 
| Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 720 | css_enqueue_subchannel_slow(struct subchannel_id schid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { | 
 | 722 | 	struct slow_subchannel *new_slow_sch; | 
 | 723 | 	unsigned long flags; | 
 | 724 |  | 
| Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 725 | 	new_slow_sch = kzalloc(sizeof(struct slow_subchannel), GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | 	if (!new_slow_sch) | 
 | 727 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | 	new_slow_sch->schid = schid; | 
 | 729 | 	spin_lock_irqsave(&slow_subchannel_lock, flags); | 
 | 730 | 	list_add_tail(&new_slow_sch->slow_list, &slow_subchannels_head); | 
 | 731 | 	spin_unlock_irqrestore(&slow_subchannel_lock, flags); | 
 | 732 | 	return 0; | 
 | 733 | } | 
 | 734 |  | 
 | 735 | void | 
 | 736 | css_clear_subchannel_slow_list(void) | 
 | 737 | { | 
 | 738 | 	unsigned long flags; | 
 | 739 |  | 
 | 740 | 	spin_lock_irqsave(&slow_subchannel_lock, flags); | 
 | 741 | 	while (!list_empty(&slow_subchannels_head)) { | 
 | 742 | 		struct slow_subchannel *slow_sch = | 
 | 743 | 			list_entry(slow_subchannels_head.next, | 
 | 744 | 				   struct slow_subchannel, slow_list); | 
 | 745 |  | 
 | 746 | 		list_del_init(slow_subchannels_head.next); | 
 | 747 | 		kfree(slow_sch); | 
 | 748 | 	} | 
 | 749 | 	spin_unlock_irqrestore(&slow_subchannel_lock, flags); | 
 | 750 | } | 
 | 751 |  | 
 | 752 |  | 
 | 753 |  | 
 | 754 | int | 
 | 755 | css_slow_subchannels_exist(void) | 
 | 756 | { | 
 | 757 | 	return (!list_empty(&slow_subchannels_head)); | 
 | 758 | } | 
 | 759 |  | 
 | 760 | MODULE_LICENSE("GPL"); | 
 | 761 | EXPORT_SYMBOL(css_bus_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | EXPORT_SYMBOL_GPL(css_characteristics_avail); |