blob: d96c687aee9373fe7638fa61bb88e335b58b65ea [file] [log] [blame]
Markus Lidelf10378f2005-06-23 22:02:16 -07001/*
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>
17#include <linux/i2o.h>
18
19#define OSM_NAME "bus-osm"
Markus Lidel2e1973a2006-01-06 00:19:32 -080020#define OSM_VERSION "1.317"
Markus Lidelf10378f2005-06-23 22:02:16 -070021#define OSM_DESCRIPTION "I2O Bus Adapter OSM"
22
23static struct i2o_driver i2o_bus_driver;
24
25/* Bus OSM class handling definition */
26static 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 */
40static int i2o_bus_scan(struct i2o_device *dev)
41{
Markus Lidela1a5ea72006-01-06 00:19:29 -080042 struct i2o_message *msg;
Markus Lidelf10378f2005-06-23 22:02:16 -070043
Markus Lidela1a5ea72006-01-06 00:19:29 -080044 msg = i2o_msg_get_wait(dev->iop, I2O_TIMEOUT_MESSAGE_GET);
45 if (IS_ERR(msg))
Markus Lidelf10378f2005-06-23 22:02:16 -070046 return -ETIMEDOUT;
47
Markus Lidela1a5ea72006-01-06 00:19:29 -080048 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 Lidelf10378f2005-06-23 22:02:16 -070052
Markus Lidela1a5ea72006-01-06 00:19:29 -080053 return i2o_msg_post_wait(dev->iop, msg, 60);
Markus Lidelf10378f2005-06-23 22:02:16 -070054};
55
56/**
57 * i2o_bus_store_scan - Scan the I2O Bus Adapter
58 * @d: device which should be scanned
59 *
60 * Returns count.
61 */
Markus Lidela1a5ea72006-01-06 00:19:29 -080062static ssize_t i2o_bus_store_scan(struct device *d,
63 struct device_attribute *attr,
64 const char *buf, size_t count)
Markus Lidelf10378f2005-06-23 22:02:16 -070065{
66 struct i2o_device *i2o_dev = to_i2o_device(d);
67 int rc;
68
69 if ((rc = i2o_bus_scan(i2o_dev)))
70 osm_warn("bus scan failed %d\n", rc);
71
72 return count;
73}
74
75/* Bus Adapter OSM device attributes */
76static DEVICE_ATTR(scan, S_IWUSR, NULL, i2o_bus_store_scan);
77
78/**
79 * i2o_bus_probe - verify if dev is a I2O Bus Adapter device and install it
80 * @dev: device to verify if it is a I2O Bus Adapter device
81 *
82 * Because we want all Bus Adapters always return 0.
Jeff Garzik6b5f2962006-10-17 00:10:22 -070083 * Except when we fail. Then we are sad.
Markus Lidelf10378f2005-06-23 22:02:16 -070084 *
Jeff Garzik6b5f2962006-10-17 00:10:22 -070085 * Returns 0, except when we fail to excel.
Markus Lidelf10378f2005-06-23 22:02:16 -070086 */
87static int i2o_bus_probe(struct device *dev)
88{
89 struct i2o_device *i2o_dev = to_i2o_device(get_device(dev));
Jeff Garzik6b5f2962006-10-17 00:10:22 -070090 int rc;
Markus Lidelf10378f2005-06-23 22:02:16 -070091
Jeff Garzik6b5f2962006-10-17 00:10:22 -070092 rc = device_create_file(dev, &dev_attr_scan);
93 if (rc)
94 goto err_out;
Markus Lidelf10378f2005-06-23 22:02:16 -070095
96 osm_info("device added (TID: %03x)\n", i2o_dev->lct_data.tid);
97
98 return 0;
Jeff Garzik6b5f2962006-10-17 00:10:22 -070099
100err_out:
101 put_device(dev);
102 return rc;
Markus Lidelf10378f2005-06-23 22:02:16 -0700103};
104
105/**
106 * i2o_bus_remove - remove the I2O Bus Adapter device from the system again
107 * @dev: I2O Bus Adapter device which should be removed
108 *
109 * Always returns 0.
110 */
111static int i2o_bus_remove(struct device *dev)
112{
113 struct i2o_device *i2o_dev = to_i2o_device(dev);
114
115 device_remove_file(dev, &dev_attr_scan);
116
117 put_device(dev);
118
119 osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);
120
121 return 0;
122};
123
124/* Bus Adapter OSM driver struct */
125static struct i2o_driver i2o_bus_driver = {
126 .name = OSM_NAME,
127 .classes = i2o_bus_class_id,
128 .driver = {
129 .probe = i2o_bus_probe,
130 .remove = i2o_bus_remove,
131 },
132};
133
134/**
135 * i2o_bus_init - Bus Adapter OSM initialization function
136 *
137 * Only register the Bus Adapter OSM in the I2O core.
138 *
139 * Returns 0 on success or negative error code on failure.
140 */
141static int __init i2o_bus_init(void)
142{
143 int rc;
144
145 printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
146
147 /* Register Bus Adapter OSM into I2O core */
148 rc = i2o_driver_register(&i2o_bus_driver);
149 if (rc) {
150 osm_err("Could not register Bus Adapter OSM\n");
151 return rc;
152 }
153
154 return 0;
155};
156
157/**
158 * i2o_bus_exit - Bus Adapter OSM exit function
159 *
160 * Unregisters Bus Adapter OSM from I2O core.
161 */
162static void __exit i2o_bus_exit(void)
163{
164 i2o_driver_unregister(&i2o_bus_driver);
165};
166
167MODULE_AUTHOR("Markus Lidel <Markus.Lidel@shadowconnect.com>");
168MODULE_LICENSE("GPL");
169MODULE_DESCRIPTION(OSM_DESCRIPTION);
170MODULE_VERSION(OSM_VERSION);
171
172module_init(i2o_bus_init);
173module_exit(i2o_bus_exit);