device.c revision 25b7bb5838ab81b68a9de72df577103d8b4aba3c
1/* 2 * drivers/s390/cio/device.c 3 * bus driver for ccw devices 4 * 5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, 6 * IBM Corporation 7 * Author(s): Arnd Bergmann (arndb@de.ibm.com) 8 * Cornelia Huck (cornelia.huck@de.ibm.com) 9 * Martin Schwidefsky (schwidefsky@de.ibm.com) 10 */ 11#include <linux/module.h> 12#include <linux/init.h> 13#include <linux/spinlock.h> 14#include <linux/errno.h> 15#include <linux/err.h> 16#include <linux/slab.h> 17#include <linux/list.h> 18#include <linux/device.h> 19#include <linux/workqueue.h> 20 21#include <asm/ccwdev.h> 22#include <asm/cio.h> 23#include <asm/param.h> /* HZ */ 24#include <asm/cmb.h> 25 26#include "cio.h" 27#include "cio_debug.h" 28#include "css.h" 29#include "device.h" 30#include "ioasm.h" 31 32/******************* bus type handling ***********************/ 33 34/* The Linux driver model distinguishes between a bus type and 35 * the bus itself. Of course we only have one channel 36 * subsystem driver and one channel system per machine, but 37 * we still use the abstraction. T.R. says it's a good idea. */ 38static int 39ccw_bus_match (struct device * dev, struct device_driver * drv) 40{ 41 struct ccw_device *cdev = to_ccwdev(dev); 42 struct ccw_driver *cdrv = to_ccwdrv(drv); 43 const struct ccw_device_id *ids = cdrv->ids, *found; 44 45 if (!ids) 46 return 0; 47 48 found = ccw_device_id_match(ids, &cdev->id); 49 if (!found) 50 return 0; 51 52 cdev->id.driver_info = found->driver_info; 53 54 return 1; 55} 56 57/* Store modalias string delimited by prefix/suffix string into buffer with 58 * specified size. Return length of resulting string (excluding trailing '\0') 59 * even if string doesn't fit buffer (snprintf semantics). */ 60static int snprint_alias(char *buf, size_t size, 61 struct ccw_device_id *id, const char *suffix) 62{ 63 int len; 64 65 len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model); 66 if (len > size) 67 return len; 68 buf += len; 69 size -= len; 70 71 if (id->dev_type != 0) 72 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type, 73 id->dev_model, suffix); 74 else 75 len += snprintf(buf, size, "dtdm%s", suffix); 76 77 return len; 78} 79 80/* Set up environment variables for ccw device uevent. Return 0 on success, 81 * non-zero otherwise. */ 82static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env) 83{ 84 struct ccw_device *cdev = to_ccwdev(dev); 85 struct ccw_device_id *id = &(cdev->id); 86 int ret; 87 char modalias_buf[30]; 88 89 /* CU_TYPE= */ 90 ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type); 91 if (ret) 92 return ret; 93 94 /* CU_MODEL= */ 95 ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model); 96 if (ret) 97 return ret; 98 99 /* The next two can be zero, that's ok for us */ 100 /* DEV_TYPE= */ 101 ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type); 102 if (ret) 103 return ret; 104 105 /* DEV_MODEL= */ 106 ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model); 107 if (ret) 108 return ret; 109 110 /* MODALIAS= */ 111 snprint_alias(modalias_buf, sizeof(modalias_buf), id, ""); 112 ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf); 113 return ret; 114} 115 116struct bus_type ccw_bus_type; 117 118static void io_subchannel_irq(struct subchannel *); 119static int io_subchannel_probe(struct subchannel *); 120static int io_subchannel_remove(struct subchannel *); 121static int io_subchannel_notify(struct subchannel *, int); 122static void io_subchannel_verify(struct subchannel *); 123static void io_subchannel_ioterm(struct subchannel *); 124static void io_subchannel_shutdown(struct subchannel *); 125 126static struct css_driver io_subchannel_driver = { 127 .subchannel_type = SUBCHANNEL_TYPE_IO, 128 .name = "io_subchannel", 129 .irq = io_subchannel_irq, 130 .notify = io_subchannel_notify, 131 .verify = io_subchannel_verify, 132 .termination = io_subchannel_ioterm, 133 .probe = io_subchannel_probe, 134 .remove = io_subchannel_remove, 135 .shutdown = io_subchannel_shutdown, 136}; 137 138struct workqueue_struct *ccw_device_work; 139struct workqueue_struct *ccw_device_notify_work; 140wait_queue_head_t ccw_device_init_wq; 141atomic_t ccw_device_init_count; 142 143static int __init 144init_ccw_bus_type (void) 145{ 146 int ret; 147 148 init_waitqueue_head(&ccw_device_init_wq); 149 atomic_set(&ccw_device_init_count, 0); 150 151 ccw_device_work = create_singlethread_workqueue("cio"); 152 if (!ccw_device_work) 153 return -ENOMEM; /* FIXME: better errno ? */ 154 ccw_device_notify_work = create_singlethread_workqueue("cio_notify"); 155 if (!ccw_device_notify_work) { 156 ret = -ENOMEM; /* FIXME: better errno ? */ 157 goto out_err; 158 } 159 slow_path_wq = create_singlethread_workqueue("kslowcrw"); 160 if (!slow_path_wq) { 161 ret = -ENOMEM; /* FIXME: better errno ? */ 162 goto out_err; 163 } 164 if ((ret = bus_register (&ccw_bus_type))) 165 goto out_err; 166 167 ret = css_driver_register(&io_subchannel_driver); 168 if (ret) 169 goto out_err; 170 171 wait_event(ccw_device_init_wq, 172 atomic_read(&ccw_device_init_count) == 0); 173 flush_workqueue(ccw_device_work); 174 return 0; 175out_err: 176 if (ccw_device_work) 177 destroy_workqueue(ccw_device_work); 178 if (ccw_device_notify_work) 179 destroy_workqueue(ccw_device_notify_work); 180 if (slow_path_wq) 181 destroy_workqueue(slow_path_wq); 182 return ret; 183} 184 185static void __exit 186cleanup_ccw_bus_type (void) 187{ 188 css_driver_unregister(&io_subchannel_driver); 189 bus_unregister(&ccw_bus_type); 190 destroy_workqueue(ccw_device_notify_work); 191 destroy_workqueue(ccw_device_work); 192} 193 194subsys_initcall(init_ccw_bus_type); 195module_exit(cleanup_ccw_bus_type); 196 197/************************ device handling **************************/ 198 199/* 200 * A ccw_device has some interfaces in sysfs in addition to the 201 * standard ones. 202 * The following entries are designed to export the information which 203 * resided in 2.4 in /proc/subchannels. Subchannel and device number 204 * are obvious, so they don't have an entry :) 205 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree? 206 */ 207static ssize_t 208chpids_show (struct device * dev, struct device_attribute *attr, char * buf) 209{ 210 struct subchannel *sch = to_subchannel(dev); 211 struct chsc_ssd_info *ssd = &sch->ssd_info; 212 ssize_t ret = 0; 213 int chp; 214 int mask; 215 216 for (chp = 0; chp < 8; chp++) { 217 mask = 0x80 >> chp; 218 if (ssd->path_mask & mask) 219 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id); 220 else 221 ret += sprintf(buf + ret, "00 "); 222 } 223 ret += sprintf (buf+ret, "\n"); 224 return min((ssize_t)PAGE_SIZE, ret); 225} 226 227static ssize_t 228pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf) 229{ 230 struct subchannel *sch = to_subchannel(dev); 231 struct pmcw *pmcw = &sch->schib.pmcw; 232 233 return sprintf (buf, "%02x %02x %02x\n", 234 pmcw->pim, pmcw->pam, pmcw->pom); 235} 236 237static ssize_t 238devtype_show (struct device *dev, struct device_attribute *attr, char *buf) 239{ 240 struct ccw_device *cdev = to_ccwdev(dev); 241 struct ccw_device_id *id = &(cdev->id); 242 243 if (id->dev_type != 0) 244 return sprintf(buf, "%04x/%02x\n", 245 id->dev_type, id->dev_model); 246 else 247 return sprintf(buf, "n/a\n"); 248} 249 250static ssize_t 251cutype_show (struct device *dev, struct device_attribute *attr, char *buf) 252{ 253 struct ccw_device *cdev = to_ccwdev(dev); 254 struct ccw_device_id *id = &(cdev->id); 255 256 return sprintf(buf, "%04x/%02x\n", 257 id->cu_type, id->cu_model); 258} 259 260static ssize_t 261modalias_show (struct device *dev, struct device_attribute *attr, char *buf) 262{ 263 struct ccw_device *cdev = to_ccwdev(dev); 264 struct ccw_device_id *id = &(cdev->id); 265 int len; 266 267 len = snprint_alias(buf, PAGE_SIZE, id, "\n"); 268 269 return len > PAGE_SIZE ? PAGE_SIZE : len; 270} 271 272static ssize_t 273online_show (struct device *dev, struct device_attribute *attr, char *buf) 274{ 275 struct ccw_device *cdev = to_ccwdev(dev); 276 277 return sprintf(buf, cdev->online ? "1\n" : "0\n"); 278} 279 280int ccw_device_is_orphan(struct ccw_device *cdev) 281{ 282 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent)); 283} 284 285static void ccw_device_unregister(struct ccw_device *cdev) 286{ 287 if (test_and_clear_bit(1, &cdev->private->registered)) 288 device_del(&cdev->dev); 289} 290 291static void ccw_device_remove_orphan_cb(struct device *dev) 292{ 293 struct ccw_device *cdev = to_ccwdev(dev); 294 295 ccw_device_unregister(cdev); 296 put_device(&cdev->dev); 297} 298 299static void ccw_device_remove_sch_cb(struct device *dev) 300{ 301 struct subchannel *sch; 302 303 sch = to_subchannel(dev); 304 css_sch_device_unregister(sch); 305 /* Reset intparm to zeroes. */ 306 sch->schib.pmcw.intparm = 0; 307 cio_modify(sch); 308 put_device(&sch->dev); 309} 310 311static void 312ccw_device_remove_disconnected(struct ccw_device *cdev) 313{ 314 unsigned long flags; 315 int rc; 316 317 /* 318 * Forced offline in disconnected state means 319 * 'throw away device'. 320 */ 321 if (ccw_device_is_orphan(cdev)) { 322 /* 323 * Deregister ccw device. 324 * Unfortunately, we cannot do this directly from the 325 * attribute method. 326 */ 327 spin_lock_irqsave(cdev->ccwlock, flags); 328 cdev->private->state = DEV_STATE_NOT_OPER; 329 spin_unlock_irqrestore(cdev->ccwlock, flags); 330 rc = device_schedule_callback(&cdev->dev, 331 ccw_device_remove_orphan_cb); 332 if (rc) 333 CIO_MSG_EVENT(2, "Couldn't unregister orphan " 334 "0.%x.%04x\n", 335 cdev->private->dev_id.ssid, 336 cdev->private->dev_id.devno); 337 return; 338 } 339 /* Deregister subchannel, which will kill the ccw device. */ 340 rc = device_schedule_callback(cdev->dev.parent, 341 ccw_device_remove_sch_cb); 342 if (rc) 343 CIO_MSG_EVENT(2, "Couldn't unregister disconnected device " 344 "0.%x.%04x\n", 345 cdev->private->dev_id.ssid, 346 cdev->private->dev_id.devno); 347} 348 349/** 350 * ccw_device_set_offline() - disable a ccw device for I/O 351 * @cdev: target ccw device 352 * 353 * This function calls the driver's set_offline() function for @cdev, if 354 * given, and then disables @cdev. 355 * Returns: 356 * %0 on success and a negative error value on failure. 357 * Context: 358 * enabled, ccw device lock not held 359 */ 360int ccw_device_set_offline(struct ccw_device *cdev) 361{ 362 int ret; 363 364 if (!cdev) 365 return -ENODEV; 366 if (!cdev->online || !cdev->drv) 367 return -EINVAL; 368 369 if (cdev->drv->set_offline) { 370 ret = cdev->drv->set_offline(cdev); 371 if (ret != 0) 372 return ret; 373 } 374 cdev->online = 0; 375 spin_lock_irq(cdev->ccwlock); 376 ret = ccw_device_offline(cdev); 377 if (ret == -ENODEV) { 378 if (cdev->private->state != DEV_STATE_NOT_OPER) { 379 cdev->private->state = DEV_STATE_OFFLINE; 380 dev_fsm_event(cdev, DEV_EVENT_NOTOPER); 381 } 382 spin_unlock_irq(cdev->ccwlock); 383 return ret; 384 } 385 spin_unlock_irq(cdev->ccwlock); 386 if (ret == 0) 387 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 388 else { 389 CIO_MSG_EVENT(2, "ccw_device_offline returned %d, " 390 "device 0.%x.%04x\n", 391 ret, cdev->private->dev_id.ssid, 392 cdev->private->dev_id.devno); 393 cdev->online = 1; 394 } 395 return ret; 396} 397 398/** 399 * ccw_device_set_online() - enable a ccw device for I/O 400 * @cdev: target ccw device 401 * 402 * This function first enables @cdev and then calls the driver's set_online() 403 * function for @cdev, if given. If set_online() returns an error, @cdev is 404 * disabled again. 405 * Returns: 406 * %0 on success and a negative error value on failure. 407 * Context: 408 * enabled, ccw device lock not held 409 */ 410int ccw_device_set_online(struct ccw_device *cdev) 411{ 412 int ret; 413 414 if (!cdev) 415 return -ENODEV; 416 if (cdev->online || !cdev->drv) 417 return -EINVAL; 418 419 spin_lock_irq(cdev->ccwlock); 420 ret = ccw_device_online(cdev); 421 spin_unlock_irq(cdev->ccwlock); 422 if (ret == 0) 423 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 424 else { 425 CIO_MSG_EVENT(2, "ccw_device_online returned %d, " 426 "device 0.%x.%04x\n", 427 ret, cdev->private->dev_id.ssid, 428 cdev->private->dev_id.devno); 429 return ret; 430 } 431 if (cdev->private->state != DEV_STATE_ONLINE) 432 return -ENODEV; 433 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) { 434 cdev->online = 1; 435 return 0; 436 } 437 spin_lock_irq(cdev->ccwlock); 438 ret = ccw_device_offline(cdev); 439 spin_unlock_irq(cdev->ccwlock); 440 if (ret == 0) 441 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 442 else 443 CIO_MSG_EVENT(2, "ccw_device_offline returned %d, " 444 "device 0.%x.%04x\n", 445 ret, cdev->private->dev_id.ssid, 446 cdev->private->dev_id.devno); 447 return (ret == 0) ? -ENODEV : ret; 448} 449 450static void online_store_handle_offline(struct ccw_device *cdev) 451{ 452 if (cdev->private->state == DEV_STATE_DISCONNECTED) 453 ccw_device_remove_disconnected(cdev); 454 else if (cdev->drv && cdev->drv->set_offline) 455 ccw_device_set_offline(cdev); 456} 457 458static int online_store_recog_and_online(struct ccw_device *cdev) 459{ 460 int ret; 461 462 /* Do device recognition, if needed. */ 463 if (cdev->id.cu_type == 0) { 464 ret = ccw_device_recognition(cdev); 465 if (ret) { 466 CIO_MSG_EVENT(0, "Couldn't start recognition " 467 "for device 0.%x.%04x (ret=%d)\n", 468 cdev->private->dev_id.ssid, 469 cdev->private->dev_id.devno, ret); 470 return ret; 471 } 472 wait_event(cdev->private->wait_q, 473 cdev->private->flags.recog_done); 474 } 475 if (cdev->drv && cdev->drv->set_online) 476 ccw_device_set_online(cdev); 477 return 0; 478} 479static void online_store_handle_online(struct ccw_device *cdev, int force) 480{ 481 int ret; 482 483 ret = online_store_recog_and_online(cdev); 484 if (ret) 485 return; 486 if (force && cdev->private->state == DEV_STATE_BOXED) { 487 ret = ccw_device_stlck(cdev); 488 if (ret) { 489 dev_warn(&cdev->dev, 490 "ccw_device_stlck returned %d!\n", ret); 491 return; 492 } 493 if (cdev->id.cu_type == 0) 494 cdev->private->state = DEV_STATE_NOT_OPER; 495 online_store_recog_and_online(cdev); 496 } 497 498} 499 500static ssize_t online_store (struct device *dev, struct device_attribute *attr, 501 const char *buf, size_t count) 502{ 503 struct ccw_device *cdev = to_ccwdev(dev); 504 int i, force; 505 char *tmp; 506 507 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) 508 return -EAGAIN; 509 510 if (cdev->drv && !try_module_get(cdev->drv->owner)) { 511 atomic_set(&cdev->private->onoff, 0); 512 return -EINVAL; 513 } 514 if (!strncmp(buf, "force\n", count)) { 515 force = 1; 516 i = 1; 517 } else { 518 force = 0; 519 i = simple_strtoul(buf, &tmp, 16); 520 } 521 522 switch (i) { 523 case 0: 524 online_store_handle_offline(cdev); 525 break; 526 case 1: 527 online_store_handle_online(cdev, force); 528 break; 529 default: 530 count = -EINVAL; 531 } 532 if (cdev->drv) 533 module_put(cdev->drv->owner); 534 atomic_set(&cdev->private->onoff, 0); 535 return count; 536} 537 538static ssize_t 539available_show (struct device *dev, struct device_attribute *attr, char *buf) 540{ 541 struct ccw_device *cdev = to_ccwdev(dev); 542 struct subchannel *sch; 543 544 if (ccw_device_is_orphan(cdev)) 545 return sprintf(buf, "no device\n"); 546 switch (cdev->private->state) { 547 case DEV_STATE_BOXED: 548 return sprintf(buf, "boxed\n"); 549 case DEV_STATE_DISCONNECTED: 550 case DEV_STATE_DISCONNECTED_SENSE_ID: 551 case DEV_STATE_NOT_OPER: 552 sch = to_subchannel(dev->parent); 553 if (!sch->lpm) 554 return sprintf(buf, "no path\n"); 555 else 556 return sprintf(buf, "no device\n"); 557 default: 558 /* All other states considered fine. */ 559 return sprintf(buf, "good\n"); 560 } 561} 562 563static DEVICE_ATTR(chpids, 0444, chpids_show, NULL); 564static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); 565static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); 566static DEVICE_ATTR(cutype, 0444, cutype_show, NULL); 567static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); 568static DEVICE_ATTR(online, 0644, online_show, online_store); 569extern struct device_attribute dev_attr_cmb_enable; 570static DEVICE_ATTR(availability, 0444, available_show, NULL); 571 572static struct attribute * subch_attrs[] = { 573 &dev_attr_chpids.attr, 574 &dev_attr_pimpampom.attr, 575 NULL, 576}; 577 578static struct attribute_group subch_attr_group = { 579 .attrs = subch_attrs, 580}; 581 582struct attribute_group *subch_attr_groups[] = { 583 &subch_attr_group, 584 NULL, 585}; 586 587static struct attribute * ccwdev_attrs[] = { 588 &dev_attr_devtype.attr, 589 &dev_attr_cutype.attr, 590 &dev_attr_modalias.attr, 591 &dev_attr_online.attr, 592 &dev_attr_cmb_enable.attr, 593 &dev_attr_availability.attr, 594 NULL, 595}; 596 597static struct attribute_group ccwdev_attr_group = { 598 .attrs = ccwdev_attrs, 599}; 600 601static struct attribute_group *ccwdev_attr_groups[] = { 602 &ccwdev_attr_group, 603 NULL, 604}; 605 606/* this is a simple abstraction for device_register that sets the 607 * correct bus type and adds the bus specific files */ 608static int ccw_device_register(struct ccw_device *cdev) 609{ 610 struct device *dev = &cdev->dev; 611 int ret; 612 613 dev->bus = &ccw_bus_type; 614 615 if ((ret = device_add(dev))) 616 return ret; 617 618 set_bit(1, &cdev->private->registered); 619 return ret; 620} 621 622struct match_data { 623 struct ccw_dev_id dev_id; 624 struct ccw_device * sibling; 625}; 626 627static int 628match_devno(struct device * dev, void * data) 629{ 630 struct match_data * d = data; 631 struct ccw_device * cdev; 632 633 cdev = to_ccwdev(dev); 634 if ((cdev->private->state == DEV_STATE_DISCONNECTED) && 635 !ccw_device_is_orphan(cdev) && 636 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) && 637 (cdev != d->sibling)) 638 return 1; 639 return 0; 640} 641 642static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id, 643 struct ccw_device *sibling) 644{ 645 struct device *dev; 646 struct match_data data; 647 648 data.dev_id = *dev_id; 649 data.sibling = sibling; 650 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno); 651 652 return dev ? to_ccwdev(dev) : NULL; 653} 654 655static int match_orphan(struct device *dev, void *data) 656{ 657 struct ccw_dev_id *dev_id; 658 struct ccw_device *cdev; 659 660 dev_id = data; 661 cdev = to_ccwdev(dev); 662 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); 663} 664 665static struct ccw_device * 666get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css, 667 struct ccw_dev_id *dev_id) 668{ 669 struct device *dev; 670 671 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id, 672 match_orphan); 673 674 return dev ? to_ccwdev(dev) : NULL; 675} 676 677static void 678ccw_device_add_changed(struct work_struct *work) 679{ 680 struct ccw_device_private *priv; 681 struct ccw_device *cdev; 682 683 priv = container_of(work, struct ccw_device_private, kick_work); 684 cdev = priv->cdev; 685 if (device_add(&cdev->dev)) { 686 put_device(&cdev->dev); 687 return; 688 } 689 set_bit(1, &cdev->private->registered); 690} 691 692void ccw_device_do_unreg_rereg(struct work_struct *work) 693{ 694 struct ccw_device_private *priv; 695 struct ccw_device *cdev; 696 struct subchannel *sch; 697 698 priv = container_of(work, struct ccw_device_private, kick_work); 699 cdev = priv->cdev; 700 sch = to_subchannel(cdev->dev.parent); 701 702 ccw_device_unregister(cdev); 703 PREPARE_WORK(&cdev->private->kick_work, 704 ccw_device_add_changed); 705 queue_work(ccw_device_work, &cdev->private->kick_work); 706} 707 708static void 709ccw_device_release(struct device *dev) 710{ 711 struct ccw_device *cdev; 712 713 cdev = to_ccwdev(dev); 714 kfree(cdev->private); 715 kfree(cdev); 716} 717 718static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) 719{ 720 struct ccw_device *cdev; 721 722 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 723 if (cdev) { 724 cdev->private = kzalloc(sizeof(struct ccw_device_private), 725 GFP_KERNEL | GFP_DMA); 726 if (cdev->private) 727 return cdev; 728 } 729 kfree(cdev); 730 return ERR_PTR(-ENOMEM); 731} 732 733static int io_subchannel_initialize_dev(struct subchannel *sch, 734 struct ccw_device *cdev) 735{ 736 cdev->private->cdev = cdev; 737 atomic_set(&cdev->private->onoff, 0); 738 cdev->dev.parent = &sch->dev; 739 cdev->dev.release = ccw_device_release; 740 INIT_WORK(&cdev->private->kick_work, NULL); 741 cdev->dev.groups = ccwdev_attr_groups; 742 /* Do first half of device_register. */ 743 device_initialize(&cdev->dev); 744 if (!get_device(&sch->dev)) { 745 if (cdev->dev.release) 746 cdev->dev.release(&cdev->dev); 747 return -ENODEV; 748 } 749 return 0; 750} 751 752static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch) 753{ 754 struct ccw_device *cdev; 755 int ret; 756 757 cdev = io_subchannel_allocate_dev(sch); 758 if (!IS_ERR(cdev)) { 759 ret = io_subchannel_initialize_dev(sch, cdev); 760 if (ret) { 761 kfree(cdev); 762 cdev = ERR_PTR(ret); 763 } 764 } 765 return cdev; 766} 767 768static int io_subchannel_recog(struct ccw_device *, struct subchannel *); 769 770static void sch_attach_device(struct subchannel *sch, 771 struct ccw_device *cdev) 772{ 773 css_update_ssd_info(sch); 774 spin_lock_irq(sch->lock); 775 sch->dev.driver_data = cdev; 776 cdev->private->schid = sch->schid; 777 cdev->ccwlock = sch->lock; 778 device_trigger_reprobe(sch); 779 spin_unlock_irq(sch->lock); 780} 781 782static void sch_attach_disconnected_device(struct subchannel *sch, 783 struct ccw_device *cdev) 784{ 785 struct subchannel *other_sch; 786 int ret; 787 788 other_sch = to_subchannel(get_device(cdev->dev.parent)); 789 ret = device_move(&cdev->dev, &sch->dev); 790 if (ret) { 791 CIO_MSG_EVENT(2, "Moving disconnected device 0.%x.%04x failed " 792 "(ret=%d)!\n", cdev->private->dev_id.ssid, 793 cdev->private->dev_id.devno, ret); 794 put_device(&other_sch->dev); 795 return; 796 } 797 other_sch->dev.driver_data = NULL; 798 /* No need to keep a subchannel without ccw device around. */ 799 css_sch_device_unregister(other_sch); 800 put_device(&other_sch->dev); 801 sch_attach_device(sch, cdev); 802} 803 804static void sch_attach_orphaned_device(struct subchannel *sch, 805 struct ccw_device *cdev) 806{ 807 int ret; 808 809 /* Try to move the ccw device to its new subchannel. */ 810 ret = device_move(&cdev->dev, &sch->dev); 811 if (ret) { 812 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " 813 "failed (ret=%d)!\n", 814 cdev->private->dev_id.ssid, 815 cdev->private->dev_id.devno, ret); 816 return; 817 } 818 sch_attach_device(sch, cdev); 819} 820 821static void sch_create_and_recog_new_device(struct subchannel *sch) 822{ 823 struct ccw_device *cdev; 824 825 /* Need to allocate a new ccw device. */ 826 cdev = io_subchannel_create_ccwdev(sch); 827 if (IS_ERR(cdev)) { 828 /* OK, we did everything we could... */ 829 css_sch_device_unregister(sch); 830 return; 831 } 832 spin_lock_irq(sch->lock); 833 sch->dev.driver_data = cdev; 834 spin_unlock_irq(sch->lock); 835 /* Start recognition for the new ccw device. */ 836 if (io_subchannel_recog(cdev, sch)) { 837 spin_lock_irq(sch->lock); 838 sch->dev.driver_data = NULL; 839 spin_unlock_irq(sch->lock); 840 if (cdev->dev.release) 841 cdev->dev.release(&cdev->dev); 842 css_sch_device_unregister(sch); 843 } 844} 845 846 847void ccw_device_move_to_orphanage(struct work_struct *work) 848{ 849 struct ccw_device_private *priv; 850 struct ccw_device *cdev; 851 struct ccw_device *replacing_cdev; 852 struct subchannel *sch; 853 int ret; 854 struct channel_subsystem *css; 855 struct ccw_dev_id dev_id; 856 857 priv = container_of(work, struct ccw_device_private, kick_work); 858 cdev = priv->cdev; 859 sch = to_subchannel(cdev->dev.parent); 860 css = to_css(sch->dev.parent); 861 dev_id.devno = sch->schib.pmcw.dev; 862 dev_id.ssid = sch->schid.ssid; 863 864 /* 865 * Move the orphaned ccw device to the orphanage so the replacing 866 * ccw device can take its place on the subchannel. 867 */ 868 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev); 869 if (ret) { 870 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " 871 "(ret=%d)!\n", cdev->private->dev_id.ssid, 872 cdev->private->dev_id.devno, ret); 873 return; 874 } 875 cdev->ccwlock = css->pseudo_subchannel->lock; 876 /* 877 * Search for the replacing ccw device 878 * - among the disconnected devices 879 * - in the orphanage 880 */ 881 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev); 882 if (replacing_cdev) { 883 sch_attach_disconnected_device(sch, replacing_cdev); 884 return; 885 } 886 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id); 887 if (replacing_cdev) { 888 sch_attach_orphaned_device(sch, replacing_cdev); 889 return; 890 } 891 sch_create_and_recog_new_device(sch); 892} 893 894/* 895 * Register recognized device. 896 */ 897static void 898io_subchannel_register(struct work_struct *work) 899{ 900 struct ccw_device_private *priv; 901 struct ccw_device *cdev; 902 struct subchannel *sch; 903 int ret; 904 unsigned long flags; 905 906 priv = container_of(work, struct ccw_device_private, kick_work); 907 cdev = priv->cdev; 908 sch = to_subchannel(cdev->dev.parent); 909 css_update_ssd_info(sch); 910 /* 911 * io_subchannel_register() will also be called after device 912 * recognition has been done for a boxed device (which will already 913 * be registered). We need to reprobe since we may now have sense id 914 * information. 915 */ 916 if (klist_node_attached(&cdev->dev.knode_parent)) { 917 if (!cdev->drv) { 918 ret = device_reprobe(&cdev->dev); 919 if (ret) 920 /* We can't do much here. */ 921 CIO_MSG_EVENT(2, "device_reprobe() returned" 922 " %d for 0.%x.%04x\n", ret, 923 cdev->private->dev_id.ssid, 924 cdev->private->dev_id.devno); 925 } 926 goto out; 927 } 928 /* 929 * Now we know this subchannel will stay, we can throw 930 * our delayed uevent. 931 */ 932 sch->dev.uevent_suppress = 0; 933 kobject_uevent(&sch->dev.kobj, KOBJ_ADD); 934 /* make it known to the system */ 935 ret = ccw_device_register(cdev); 936 if (ret) { 937 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n", 938 cdev->private->dev_id.ssid, 939 cdev->private->dev_id.devno, ret); 940 put_device(&cdev->dev); 941 spin_lock_irqsave(sch->lock, flags); 942 sch->dev.driver_data = NULL; 943 spin_unlock_irqrestore(sch->lock, flags); 944 kfree (cdev->private); 945 kfree (cdev); 946 put_device(&sch->dev); 947 if (atomic_dec_and_test(&ccw_device_init_count)) 948 wake_up(&ccw_device_init_wq); 949 return; 950 } 951 put_device(&cdev->dev); 952out: 953 cdev->private->flags.recog_done = 1; 954 put_device(&sch->dev); 955 wake_up(&cdev->private->wait_q); 956 if (atomic_dec_and_test(&ccw_device_init_count)) 957 wake_up(&ccw_device_init_wq); 958} 959 960static void ccw_device_call_sch_unregister(struct work_struct *work) 961{ 962 struct ccw_device_private *priv; 963 struct ccw_device *cdev; 964 struct subchannel *sch; 965 966 priv = container_of(work, struct ccw_device_private, kick_work); 967 cdev = priv->cdev; 968 sch = to_subchannel(cdev->dev.parent); 969 css_sch_device_unregister(sch); 970 /* Reset intparm to zeroes. */ 971 sch->schib.pmcw.intparm = 0; 972 cio_modify(sch); 973 put_device(&cdev->dev); 974 put_device(&sch->dev); 975} 976 977/* 978 * subchannel recognition done. Called from the state machine. 979 */ 980void 981io_subchannel_recog_done(struct ccw_device *cdev) 982{ 983 struct subchannel *sch; 984 985 if (css_init_done == 0) { 986 cdev->private->flags.recog_done = 1; 987 return; 988 } 989 switch (cdev->private->state) { 990 case DEV_STATE_NOT_OPER: 991 cdev->private->flags.recog_done = 1; 992 /* Remove device found not operational. */ 993 if (!get_device(&cdev->dev)) 994 break; 995 sch = to_subchannel(cdev->dev.parent); 996 PREPARE_WORK(&cdev->private->kick_work, 997 ccw_device_call_sch_unregister); 998 queue_work(slow_path_wq, &cdev->private->kick_work); 999 if (atomic_dec_and_test(&ccw_device_init_count)) 1000 wake_up(&ccw_device_init_wq); 1001 break; 1002 case DEV_STATE_BOXED: 1003 /* Device did not respond in time. */ 1004 case DEV_STATE_OFFLINE: 1005 /* 1006 * We can't register the device in interrupt context so 1007 * we schedule a work item. 1008 */ 1009 if (!get_device(&cdev->dev)) 1010 break; 1011 PREPARE_WORK(&cdev->private->kick_work, 1012 io_subchannel_register); 1013 queue_work(slow_path_wq, &cdev->private->kick_work); 1014 break; 1015 } 1016} 1017 1018static int 1019io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) 1020{ 1021 int rc; 1022 struct ccw_device_private *priv; 1023 1024 sch->dev.driver_data = cdev; 1025 sch->driver = &io_subchannel_driver; 1026 cdev->ccwlock = sch->lock; 1027 1028 /* Init private data. */ 1029 priv = cdev->private; 1030 priv->dev_id.devno = sch->schib.pmcw.dev; 1031 priv->dev_id.ssid = sch->schid.ssid; 1032 priv->schid = sch->schid; 1033 priv->state = DEV_STATE_NOT_OPER; 1034 INIT_LIST_HEAD(&priv->cmb_list); 1035 init_waitqueue_head(&priv->wait_q); 1036 init_timer(&priv->timer); 1037 1038 /* Set an initial name for the device. */ 1039 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", 1040 sch->schid.ssid, sch->schib.pmcw.dev); 1041 1042 /* Increase counter of devices currently in recognition. */ 1043 atomic_inc(&ccw_device_init_count); 1044 1045 /* Start async. device sensing. */ 1046 spin_lock_irq(sch->lock); 1047 rc = ccw_device_recognition(cdev); 1048 spin_unlock_irq(sch->lock); 1049 if (rc) { 1050 if (atomic_dec_and_test(&ccw_device_init_count)) 1051 wake_up(&ccw_device_init_wq); 1052 } 1053 return rc; 1054} 1055 1056static void ccw_device_move_to_sch(struct work_struct *work) 1057{ 1058 struct ccw_device_private *priv; 1059 int rc; 1060 struct subchannel *sch; 1061 struct ccw_device *cdev; 1062 struct subchannel *former_parent; 1063 1064 priv = container_of(work, struct ccw_device_private, kick_work); 1065 sch = priv->sch; 1066 cdev = priv->cdev; 1067 former_parent = ccw_device_is_orphan(cdev) ? 1068 NULL : to_subchannel(get_device(cdev->dev.parent)); 1069 mutex_lock(&sch->reg_mutex); 1070 /* Try to move the ccw device to its new subchannel. */ 1071 rc = device_move(&cdev->dev, &sch->dev); 1072 mutex_unlock(&sch->reg_mutex); 1073 if (rc) { 1074 CIO_MSG_EVENT(2, "Moving device 0.%x.%04x to subchannel " 1075 "0.%x.%04x failed (ret=%d)!\n", 1076 cdev->private->dev_id.ssid, 1077 cdev->private->dev_id.devno, sch->schid.ssid, 1078 sch->schid.sch_no, rc); 1079 css_sch_device_unregister(sch); 1080 goto out; 1081 } 1082 if (former_parent) { 1083 spin_lock_irq(former_parent->lock); 1084 former_parent->dev.driver_data = NULL; 1085 spin_unlock_irq(former_parent->lock); 1086 css_sch_device_unregister(former_parent); 1087 /* Reset intparm to zeroes. */ 1088 former_parent->schib.pmcw.intparm = 0; 1089 cio_modify(former_parent); 1090 } 1091 sch_attach_device(sch, cdev); 1092out: 1093 if (former_parent) 1094 put_device(&former_parent->dev); 1095 put_device(&cdev->dev); 1096} 1097 1098static void io_subchannel_irq(struct subchannel *sch) 1099{ 1100 struct ccw_device *cdev; 1101 1102 cdev = sch->dev.driver_data; 1103 1104 CIO_TRACE_EVENT(3, "IRQ"); 1105 CIO_TRACE_EVENT(3, sch->dev.bus_id); 1106 if (cdev) 1107 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT); 1108} 1109 1110static int 1111io_subchannel_probe (struct subchannel *sch) 1112{ 1113 struct ccw_device *cdev; 1114 int rc; 1115 unsigned long flags; 1116 struct ccw_dev_id dev_id; 1117 1118 if (sch->dev.driver_data) { 1119 /* 1120 * This subchannel already has an associated ccw_device. 1121 * Register it and exit. This happens for all early 1122 * device, e.g. the console. 1123 */ 1124 cdev = sch->dev.driver_data; 1125 cdev->dev.groups = ccwdev_attr_groups; 1126 device_initialize(&cdev->dev); 1127 ccw_device_register(cdev); 1128 /* 1129 * Check if the device is already online. If it is 1130 * the reference count needs to be corrected 1131 * (see ccw_device_online and css_init_done for the 1132 * ugly details). 1133 */ 1134 if (cdev->private->state != DEV_STATE_NOT_OPER && 1135 cdev->private->state != DEV_STATE_OFFLINE && 1136 cdev->private->state != DEV_STATE_BOXED) 1137 get_device(&cdev->dev); 1138 return 0; 1139 } 1140 /* 1141 * First check if a fitting device may be found amongst the 1142 * disconnected devices or in the orphanage. 1143 */ 1144 dev_id.devno = sch->schib.pmcw.dev; 1145 dev_id.ssid = sch->schid.ssid; 1146 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); 1147 if (!cdev) 1148 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), 1149 &dev_id); 1150 if (cdev) { 1151 /* 1152 * Schedule moving the device until when we have a registered 1153 * subchannel to move to and succeed the probe. We can 1154 * unregister later again, when the probe is through. 1155 */ 1156 cdev->private->sch = sch; 1157 PREPARE_WORK(&cdev->private->kick_work, 1158 ccw_device_move_to_sch); 1159 queue_work(slow_path_wq, &cdev->private->kick_work); 1160 return 0; 1161 } 1162 cdev = io_subchannel_create_ccwdev(sch); 1163 if (IS_ERR(cdev)) 1164 return PTR_ERR(cdev); 1165 1166 rc = io_subchannel_recog(cdev, sch); 1167 if (rc) { 1168 spin_lock_irqsave(sch->lock, flags); 1169 sch->dev.driver_data = NULL; 1170 spin_unlock_irqrestore(sch->lock, flags); 1171 if (cdev->dev.release) 1172 cdev->dev.release(&cdev->dev); 1173 } 1174 1175 return rc; 1176} 1177 1178static int 1179io_subchannel_remove (struct subchannel *sch) 1180{ 1181 struct ccw_device *cdev; 1182 unsigned long flags; 1183 1184 if (!sch->dev.driver_data) 1185 return 0; 1186 cdev = sch->dev.driver_data; 1187 /* Set ccw device to not operational and drop reference. */ 1188 spin_lock_irqsave(cdev->ccwlock, flags); 1189 sch->dev.driver_data = NULL; 1190 cdev->private->state = DEV_STATE_NOT_OPER; 1191 spin_unlock_irqrestore(cdev->ccwlock, flags); 1192 ccw_device_unregister(cdev); 1193 put_device(&cdev->dev); 1194 return 0; 1195} 1196 1197static int io_subchannel_notify(struct subchannel *sch, int event) 1198{ 1199 struct ccw_device *cdev; 1200 1201 cdev = sch->dev.driver_data; 1202 if (!cdev) 1203 return 0; 1204 if (!cdev->drv) 1205 return 0; 1206 if (!cdev->online) 1207 return 0; 1208 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0; 1209} 1210 1211static void io_subchannel_verify(struct subchannel *sch) 1212{ 1213 struct ccw_device *cdev; 1214 1215 cdev = sch->dev.driver_data; 1216 if (cdev) 1217 dev_fsm_event(cdev, DEV_EVENT_VERIFY); 1218} 1219 1220static void io_subchannel_ioterm(struct subchannel *sch) 1221{ 1222 struct ccw_device *cdev; 1223 1224 cdev = sch->dev.driver_data; 1225 if (!cdev) 1226 return; 1227 /* Internal I/O will be retried by the interrupt handler. */ 1228 if (cdev->private->flags.intretry) 1229 return; 1230 cdev->private->state = DEV_STATE_CLEAR_VERIFY; 1231 if (cdev->handler) 1232 cdev->handler(cdev, cdev->private->intparm, 1233 ERR_PTR(-EIO)); 1234} 1235 1236static void 1237io_subchannel_shutdown(struct subchannel *sch) 1238{ 1239 struct ccw_device *cdev; 1240 int ret; 1241 1242 cdev = sch->dev.driver_data; 1243 1244 if (cio_is_console(sch->schid)) 1245 return; 1246 if (!sch->schib.pmcw.ena) 1247 /* Nothing to do. */ 1248 return; 1249 ret = cio_disable_subchannel(sch); 1250 if (ret != -EBUSY) 1251 /* Subchannel is disabled, we're done. */ 1252 return; 1253 cdev->private->state = DEV_STATE_QUIESCE; 1254 if (cdev->handler) 1255 cdev->handler(cdev, cdev->private->intparm, 1256 ERR_PTR(-EIO)); 1257 ret = ccw_device_cancel_halt_clear(cdev); 1258 if (ret == -EBUSY) { 1259 ccw_device_set_timeout(cdev, HZ/10); 1260 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 1261 } 1262 cio_disable_subchannel(sch); 1263} 1264 1265#ifdef CONFIG_CCW_CONSOLE 1266static struct ccw_device console_cdev; 1267static struct ccw_device_private console_private; 1268static int console_cdev_in_use; 1269 1270static DEFINE_SPINLOCK(ccw_console_lock); 1271 1272spinlock_t * cio_get_console_lock(void) 1273{ 1274 return &ccw_console_lock; 1275} 1276 1277static int 1278ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch) 1279{ 1280 int rc; 1281 1282 /* Initialize the ccw_device structure. */ 1283 cdev->dev.parent= &sch->dev; 1284 rc = io_subchannel_recog(cdev, sch); 1285 if (rc) 1286 return rc; 1287 1288 /* Now wait for the async. recognition to come to an end. */ 1289 spin_lock_irq(cdev->ccwlock); 1290 while (!dev_fsm_final_state(cdev)) 1291 wait_cons_dev(); 1292 rc = -EIO; 1293 if (cdev->private->state != DEV_STATE_OFFLINE) 1294 goto out_unlock; 1295 ccw_device_online(cdev); 1296 while (!dev_fsm_final_state(cdev)) 1297 wait_cons_dev(); 1298 if (cdev->private->state != DEV_STATE_ONLINE) 1299 goto out_unlock; 1300 rc = 0; 1301out_unlock: 1302 spin_unlock_irq(cdev->ccwlock); 1303 return 0; 1304} 1305 1306struct ccw_device * 1307ccw_device_probe_console(void) 1308{ 1309 struct subchannel *sch; 1310 int ret; 1311 1312 if (xchg(&console_cdev_in_use, 1) != 0) 1313 return ERR_PTR(-EBUSY); 1314 sch = cio_probe_console(); 1315 if (IS_ERR(sch)) { 1316 console_cdev_in_use = 0; 1317 return (void *) sch; 1318 } 1319 memset(&console_cdev, 0, sizeof(struct ccw_device)); 1320 memset(&console_private, 0, sizeof(struct ccw_device_private)); 1321 console_cdev.private = &console_private; 1322 console_private.cdev = &console_cdev; 1323 ret = ccw_device_console_enable(&console_cdev, sch); 1324 if (ret) { 1325 cio_release_console(); 1326 console_cdev_in_use = 0; 1327 return ERR_PTR(ret); 1328 } 1329 console_cdev.online = 1; 1330 return &console_cdev; 1331} 1332#endif 1333 1334/* 1335 * get ccw_device matching the busid, but only if owned by cdrv 1336 */ 1337static int 1338__ccwdev_check_busid(struct device *dev, void *id) 1339{ 1340 char *bus_id; 1341 1342 bus_id = id; 1343 1344 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0); 1345} 1346 1347 1348/** 1349 * get_ccwdev_by_busid() - obtain device from a bus id 1350 * @cdrv: driver the device is owned by 1351 * @bus_id: bus id of the device to be searched 1352 * 1353 * This function searches all devices owned by @cdrv for a device with a bus 1354 * id matching @bus_id. 1355 * Returns: 1356 * If a match is found, its reference count of the found device is increased 1357 * and it is returned; else %NULL is returned. 1358 */ 1359struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, 1360 const char *bus_id) 1361{ 1362 struct device *dev; 1363 struct device_driver *drv; 1364 1365 drv = get_driver(&cdrv->driver); 1366 if (!drv) 1367 return NULL; 1368 1369 dev = driver_find_device(drv, NULL, (void *)bus_id, 1370 __ccwdev_check_busid); 1371 put_driver(drv); 1372 1373 return dev ? to_ccwdev(dev) : NULL; 1374} 1375 1376/************************** device driver handling ************************/ 1377 1378/* This is the implementation of the ccw_driver class. The probe, remove 1379 * and release methods are initially very similar to the device_driver 1380 * implementations, with the difference that they have ccw_device 1381 * arguments. 1382 * 1383 * A ccw driver also contains the information that is needed for 1384 * device matching. 1385 */ 1386static int 1387ccw_device_probe (struct device *dev) 1388{ 1389 struct ccw_device *cdev = to_ccwdev(dev); 1390 struct ccw_driver *cdrv = to_ccwdrv(dev->driver); 1391 int ret; 1392 1393 cdev->drv = cdrv; /* to let the driver call _set_online */ 1394 1395 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; 1396 1397 if (ret) { 1398 cdev->drv = NULL; 1399 return ret; 1400 } 1401 1402 return 0; 1403} 1404 1405static int 1406ccw_device_remove (struct device *dev) 1407{ 1408 struct ccw_device *cdev = to_ccwdev(dev); 1409 struct ccw_driver *cdrv = cdev->drv; 1410 int ret; 1411 1412 if (cdrv->remove) 1413 cdrv->remove(cdev); 1414 if (cdev->online) { 1415 cdev->online = 0; 1416 spin_lock_irq(cdev->ccwlock); 1417 ret = ccw_device_offline(cdev); 1418 spin_unlock_irq(cdev->ccwlock); 1419 if (ret == 0) 1420 wait_event(cdev->private->wait_q, 1421 dev_fsm_final_state(cdev)); 1422 else 1423 //FIXME: we can't fail! 1424 CIO_MSG_EVENT(2, "ccw_device_offline returned %d, " 1425 "device 0.%x.%04x\n", 1426 ret, cdev->private->dev_id.ssid, 1427 cdev->private->dev_id.devno); 1428 } 1429 ccw_device_set_timeout(cdev, 0); 1430 cdev->drv = NULL; 1431 return 0; 1432} 1433 1434static void ccw_device_shutdown(struct device *dev) 1435{ 1436 struct ccw_device *cdev; 1437 1438 cdev = to_ccwdev(dev); 1439 if (cdev->drv && cdev->drv->shutdown) 1440 cdev->drv->shutdown(cdev); 1441 disable_cmf(cdev); 1442} 1443 1444struct bus_type ccw_bus_type = { 1445 .name = "ccw", 1446 .match = ccw_bus_match, 1447 .uevent = ccw_uevent, 1448 .probe = ccw_device_probe, 1449 .remove = ccw_device_remove, 1450 .shutdown = ccw_device_shutdown, 1451}; 1452 1453/** 1454 * ccw_driver_register() - register a ccw driver 1455 * @cdriver: driver to be registered 1456 * 1457 * This function is mainly a wrapper around driver_register(). 1458 * Returns: 1459 * %0 on success and a negative error value on failure. 1460 */ 1461int ccw_driver_register(struct ccw_driver *cdriver) 1462{ 1463 struct device_driver *drv = &cdriver->driver; 1464 1465 drv->bus = &ccw_bus_type; 1466 drv->name = cdriver->name; 1467 1468 return driver_register(drv); 1469} 1470 1471/** 1472 * ccw_driver_unregister() - deregister a ccw driver 1473 * @cdriver: driver to be deregistered 1474 * 1475 * This function is mainly a wrapper around driver_unregister(). 1476 */ 1477void ccw_driver_unregister(struct ccw_driver *cdriver) 1478{ 1479 driver_unregister(&cdriver->driver); 1480} 1481 1482/* Helper func for qdio. */ 1483struct subchannel_id 1484ccw_device_get_subchannel_id(struct ccw_device *cdev) 1485{ 1486 struct subchannel *sch; 1487 1488 sch = to_subchannel(cdev->dev.parent); 1489 return sch->schid; 1490} 1491 1492MODULE_LICENSE("GPL"); 1493EXPORT_SYMBOL(ccw_device_set_online); 1494EXPORT_SYMBOL(ccw_device_set_offline); 1495EXPORT_SYMBOL(ccw_driver_register); 1496EXPORT_SYMBOL(ccw_driver_unregister); 1497EXPORT_SYMBOL(get_ccwdev_by_busid); 1498EXPORT_SYMBOL(ccw_bus_type); 1499EXPORT_SYMBOL(ccw_device_work); 1500EXPORT_SYMBOL(ccw_device_notify_work); 1501EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); 1502