Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Bus Adapter OSM |
| 3 | * |
| 4 | * Copyright (C) 2005 Markus Lidel <Markus.Lidel@shadowconnect.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | * |
| 11 | * Fixes/additions: |
| 12 | * Markus Lidel <Markus.Lidel@shadowconnect.com> |
| 13 | * initial version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
Alan Cox | 2cbf7fe | 2015-02-03 13:18:55 +0000 | [diff] [blame] | 17 | #include "i2o.h" |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 18 | |
| 19 | #define OSM_NAME "bus-osm" |
Markus Lidel | 2e1973a | 2006-01-06 00:19:32 -0800 | [diff] [blame] | 20 | #define OSM_VERSION "1.317" |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 21 | #define OSM_DESCRIPTION "I2O Bus Adapter OSM" |
| 22 | |
| 23 | static struct i2o_driver i2o_bus_driver; |
| 24 | |
| 25 | /* Bus OSM class handling definition */ |
| 26 | static struct i2o_class_id i2o_bus_class_id[] = { |
| 27 | {I2O_CLASS_BUS_ADAPTER}, |
| 28 | {I2O_CLASS_END} |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * i2o_bus_scan - Scan the bus for new devices |
| 33 | * @dev: I2O device of the bus, which should be scanned |
| 34 | * |
| 35 | * Scans the bus dev for new / removed devices. After the scan a new LCT |
| 36 | * will be fetched automatically. |
| 37 | * |
| 38 | * Returns 0 on success or negative error code on failure. |
| 39 | */ |
| 40 | static int i2o_bus_scan(struct i2o_device *dev) |
| 41 | { |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 42 | struct i2o_message *msg; |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 43 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 44 | msg = i2o_msg_get_wait(dev->iop, I2O_TIMEOUT_MESSAGE_GET); |
| 45 | if (IS_ERR(msg)) |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 46 | return -ETIMEDOUT; |
| 47 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 48 | msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0); |
| 49 | msg->u.head[1] = |
| 50 | cpu_to_le32(I2O_CMD_BUS_SCAN << 24 | HOST_TID << 12 | dev->lct_data. |
| 51 | tid); |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 52 | |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 53 | return i2o_msg_post_wait(dev->iop, msg, 60); |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * i2o_bus_store_scan - Scan the I2O Bus Adapter |
| 58 | * @d: device which should be scanned |
Randy Dunlap | d9489fb | 2006-12-06 20:38:43 -0800 | [diff] [blame] | 59 | * @attr: device_attribute |
| 60 | * @buf: output buffer |
| 61 | * @count: buffer size |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 62 | * |
| 63 | * Returns count. |
| 64 | */ |
Markus Lidel | a1a5ea7 | 2006-01-06 00:19:29 -0800 | [diff] [blame] | 65 | static ssize_t i2o_bus_store_scan(struct device *d, |
| 66 | struct device_attribute *attr, |
| 67 | const char *buf, size_t count) |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 68 | { |
| 69 | struct i2o_device *i2o_dev = to_i2o_device(d); |
| 70 | int rc; |
| 71 | |
Somya Anand | 68f4b73 | 2015-03-13 22:53:11 +0530 | [diff] [blame^] | 72 | rc = i2o_bus_scan(i2o_dev); |
| 73 | if (rc) |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 74 | osm_warn("bus scan failed %d\n", rc); |
| 75 | |
| 76 | return count; |
| 77 | } |
| 78 | |
| 79 | /* Bus Adapter OSM device attributes */ |
| 80 | static DEVICE_ATTR(scan, S_IWUSR, NULL, i2o_bus_store_scan); |
| 81 | |
| 82 | /** |
| 83 | * i2o_bus_probe - verify if dev is a I2O Bus Adapter device and install it |
| 84 | * @dev: device to verify if it is a I2O Bus Adapter device |
| 85 | * |
| 86 | * Because we want all Bus Adapters always return 0. |
Jeff Garzik | 6b5f296 | 2006-10-17 00:10:22 -0700 | [diff] [blame] | 87 | * Except when we fail. Then we are sad. |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 88 | * |
Jeff Garzik | 6b5f296 | 2006-10-17 00:10:22 -0700 | [diff] [blame] | 89 | * Returns 0, except when we fail to excel. |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 90 | */ |
| 91 | static int i2o_bus_probe(struct device *dev) |
| 92 | { |
| 93 | struct i2o_device *i2o_dev = to_i2o_device(get_device(dev)); |
Jeff Garzik | 6b5f296 | 2006-10-17 00:10:22 -0700 | [diff] [blame] | 94 | int rc; |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 95 | |
Jeff Garzik | 6b5f296 | 2006-10-17 00:10:22 -0700 | [diff] [blame] | 96 | rc = device_create_file(dev, &dev_attr_scan); |
| 97 | if (rc) |
| 98 | goto err_out; |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 99 | |
| 100 | osm_info("device added (TID: %03x)\n", i2o_dev->lct_data.tid); |
| 101 | |
| 102 | return 0; |
Jeff Garzik | 6b5f296 | 2006-10-17 00:10:22 -0700 | [diff] [blame] | 103 | |
| 104 | err_out: |
| 105 | put_device(dev); |
| 106 | return rc; |
Markus Lidel | f10378f | 2005-06-23 22:02:16 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | /** |
| 110 | * i2o_bus_remove - remove the I2O Bus Adapter device from the system again |
| 111 | * @dev: I2O Bus Adapter device which should be removed |
| 112 | * |
| 113 | * Always returns 0. |
| 114 | */ |
| 115 | static int i2o_bus_remove(struct device *dev) |
| 116 | { |
| 117 | struct i2o_device *i2o_dev = to_i2o_device(dev); |
| 118 | |
| 119 | device_remove_file(dev, &dev_attr_scan); |
| 120 | |
| 121 | put_device(dev); |
| 122 | |
| 123 | osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid); |
| 124 | |
| 125 | return 0; |
| 126 | }; |
| 127 | |
| 128 | /* Bus Adapter OSM driver struct */ |
| 129 | static struct i2o_driver i2o_bus_driver = { |
| 130 | .name = OSM_NAME, |
| 131 | .classes = i2o_bus_class_id, |
| 132 | .driver = { |
| 133 | .probe = i2o_bus_probe, |
| 134 | .remove = i2o_bus_remove, |
| 135 | }, |
| 136 | }; |
| 137 | |
| 138 | /** |
| 139 | * i2o_bus_init - Bus Adapter OSM initialization function |
| 140 | * |
| 141 | * Only register the Bus Adapter OSM in the I2O core. |
| 142 | * |
| 143 | * Returns 0 on success or negative error code on failure. |
| 144 | */ |
| 145 | static int __init i2o_bus_init(void) |
| 146 | { |
| 147 | int rc; |
| 148 | |
| 149 | printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n"); |
| 150 | |
| 151 | /* Register Bus Adapter OSM into I2O core */ |
| 152 | rc = i2o_driver_register(&i2o_bus_driver); |
| 153 | if (rc) { |
| 154 | osm_err("Could not register Bus Adapter OSM\n"); |
| 155 | return rc; |
| 156 | } |
| 157 | |
| 158 | return 0; |
| 159 | }; |
| 160 | |
| 161 | /** |
| 162 | * i2o_bus_exit - Bus Adapter OSM exit function |
| 163 | * |
| 164 | * Unregisters Bus Adapter OSM from I2O core. |
| 165 | */ |
| 166 | static void __exit i2o_bus_exit(void) |
| 167 | { |
| 168 | i2o_driver_unregister(&i2o_bus_driver); |
| 169 | }; |
| 170 | |
| 171 | MODULE_AUTHOR("Markus Lidel <Markus.Lidel@shadowconnect.com>"); |
| 172 | MODULE_LICENSE("GPL"); |
| 173 | MODULE_DESCRIPTION(OSM_DESCRIPTION); |
| 174 | MODULE_VERSION(OSM_VERSION); |
| 175 | |
| 176 | module_init(i2o_bus_init); |
| 177 | module_exit(i2o_bus_exit); |