/*1* Bus Adapter OSM2*3* Copyright (C) 2005 Markus Lidel <[email protected]>4*5* This program is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License as published by the7* Free Software Foundation; either version 2 of the License, or (at your8* option) any later version.9*10* Fixes/additions:11* Markus Lidel <[email protected]>12* initial version.13*/1415#include <linux/module.h>16#include <linux/i2o.h>1718#define OSM_NAME "bus-osm"19#define OSM_VERSION "1.317"20#define OSM_DESCRIPTION "I2O Bus Adapter OSM"2122static struct i2o_driver i2o_bus_driver;2324/* Bus OSM class handling definition */25static struct i2o_class_id i2o_bus_class_id[] = {26{I2O_CLASS_BUS_ADAPTER},27{I2O_CLASS_END}28};2930/**31* i2o_bus_scan - Scan the bus for new devices32* @dev: I2O device of the bus, which should be scanned33*34* Scans the bus dev for new / removed devices. After the scan a new LCT35* will be fetched automatically.36*37* Returns 0 on success or negative error code on failure.38*/39static int i2o_bus_scan(struct i2o_device *dev)40{41struct i2o_message *msg;4243msg = i2o_msg_get_wait(dev->iop, I2O_TIMEOUT_MESSAGE_GET);44if (IS_ERR(msg))45return -ETIMEDOUT;4647msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0);48msg->u.head[1] =49cpu_to_le32(I2O_CMD_BUS_SCAN << 24 | HOST_TID << 12 | dev->lct_data.50tid);5152return i2o_msg_post_wait(dev->iop, msg, 60);53};5455/**56* i2o_bus_store_scan - Scan the I2O Bus Adapter57* @d: device which should be scanned58* @attr: device_attribute59* @buf: output buffer60* @count: buffer size61*62* Returns count.63*/64static ssize_t i2o_bus_store_scan(struct device *d,65struct device_attribute *attr,66const char *buf, size_t count)67{68struct i2o_device *i2o_dev = to_i2o_device(d);69int rc;7071if ((rc = i2o_bus_scan(i2o_dev)))72osm_warn("bus scan failed %d\n", rc);7374return count;75}7677/* Bus Adapter OSM device attributes */78static DEVICE_ATTR(scan, S_IWUSR, NULL, i2o_bus_store_scan);7980/**81* i2o_bus_probe - verify if dev is a I2O Bus Adapter device and install it82* @dev: device to verify if it is a I2O Bus Adapter device83*84* Because we want all Bus Adapters always return 0.85* Except when we fail. Then we are sad.86*87* Returns 0, except when we fail to excel.88*/89static int i2o_bus_probe(struct device *dev)90{91struct i2o_device *i2o_dev = to_i2o_device(get_device(dev));92int rc;9394rc = device_create_file(dev, &dev_attr_scan);95if (rc)96goto err_out;9798osm_info("device added (TID: %03x)\n", i2o_dev->lct_data.tid);99100return 0;101102err_out:103put_device(dev);104return rc;105};106107/**108* i2o_bus_remove - remove the I2O Bus Adapter device from the system again109* @dev: I2O Bus Adapter device which should be removed110*111* Always returns 0.112*/113static int i2o_bus_remove(struct device *dev)114{115struct i2o_device *i2o_dev = to_i2o_device(dev);116117device_remove_file(dev, &dev_attr_scan);118119put_device(dev);120121osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);122123return 0;124};125126/* Bus Adapter OSM driver struct */127static struct i2o_driver i2o_bus_driver = {128.name = OSM_NAME,129.classes = i2o_bus_class_id,130.driver = {131.probe = i2o_bus_probe,132.remove = i2o_bus_remove,133},134};135136/**137* i2o_bus_init - Bus Adapter OSM initialization function138*139* Only register the Bus Adapter OSM in the I2O core.140*141* Returns 0 on success or negative error code on failure.142*/143static int __init i2o_bus_init(void)144{145int rc;146147printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");148149/* Register Bus Adapter OSM into I2O core */150rc = i2o_driver_register(&i2o_bus_driver);151if (rc) {152osm_err("Could not register Bus Adapter OSM\n");153return rc;154}155156return 0;157};158159/**160* i2o_bus_exit - Bus Adapter OSM exit function161*162* Unregisters Bus Adapter OSM from I2O core.163*/164static void __exit i2o_bus_exit(void)165{166i2o_driver_unregister(&i2o_bus_driver);167};168169MODULE_AUTHOR("Markus Lidel <[email protected]>");170MODULE_LICENSE("GPL");171MODULE_DESCRIPTION(OSM_DESCRIPTION);172MODULE_VERSION(OSM_VERSION);173174module_init(i2o_bus_init);175module_exit(i2o_bus_exit);176177178