aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/message
diff options
context:
space:
mode:
authorMarkus Lidel <Markus.Lidel@shadowconnect.com>2005-06-24 01:02:14 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-24 03:05:28 -0400
commitf88e119c4b824a5017456fa094950d0f4092d96c (patch)
tree7a0fea02c195732e299a576fd22fd439fbc38bdd /drivers/message
parent61fbfa8129c1771061a0e9f47747854293081c5b (diff)
[PATCH] I2O: first code cleanup of spare warnings and unused functions
Changes: - Removed unnecessary checking of NULL before calling kfree() - Make some functions static - Changed pr_debug() into osm_debug() - Use i2o_msg_in_to_virt() for getting a pointer to the message frame - Cleaned up some comments - Changed some le32_to_cpu() into readl() where necessary - Make error messages of OSM's look the same - Cleaned up error handling in i2o_block_end_request() - Removed unused error handling of failed messages in Block-OSM, which are not allowed by the I2O spec - Corrected the blocksize detection in i2o_block - Added hrt and lct sysfs-attribute to controller - Call done() function in SCSI-OSM after freeing DMA buffers - Removed unneeded variable for message size calculation in i2o_scsi_queuecommand() - Make some changes to remove sparse warnings - Reordered some functions - Cleaned up controller initialization - Replaced some magic numbers by defines - Removed unnecessary dma_sync_single_for_cpu() call on coherent DMA - Removed some unused fields in i2o_controller and removed some unused functions Signed-off-by: Markus Lidel <Markus.Lidel@shadowconnect.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/message')
-rw-r--r--drivers/message/i2o/device.c9
-rw-r--r--drivers/message/i2o/driver.c46
-rw-r--r--drivers/message/i2o/exec-osm.c47
-rw-r--r--drivers/message/i2o/i2o_block.c211
-rw-r--r--drivers/message/i2o/i2o_block.h2
-rw-r--r--drivers/message/i2o/i2o_config.c118
-rw-r--r--drivers/message/i2o/i2o_scsi.c31
-rw-r--r--drivers/message/i2o/iop.c87
-rw-r--r--drivers/message/i2o/pci.c67
9 files changed, 340 insertions, 278 deletions
diff --git a/drivers/message/i2o/device.c b/drivers/message/i2o/device.c
index 280627ae6cf7..f1b7eb63d54b 100644
--- a/drivers/message/i2o/device.c
+++ b/drivers/message/i2o/device.c
@@ -282,8 +282,7 @@ int i2o_device_parse_lct(struct i2o_controller *c)
282 282
283 down(&c->lct_lock); 283 down(&c->lct_lock);
284 284
285 if (c->lct) 285 kfree(c->lct);
286 kfree(c->lct);
287 286
288 lct = c->dlct.virt; 287 lct = c->dlct.virt;
289 288
@@ -447,8 +446,8 @@ static struct class_interface i2o_device_class_interface = {
447 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize. 446 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
448 */ 447 */
449 448
450int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist, 449static int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist,
451 int oplen, void *reslist, int reslen) 450 int oplen, void *reslist, int reslen)
452{ 451{
453 struct i2o_message __iomem *msg; 452 struct i2o_message __iomem *msg;
454 u32 m; 453 u32 m;
@@ -540,7 +539,7 @@ int i2o_parm_field_get(struct i2o_device *i2o_dev, int group, int field,
540 opblk[4] = -1; 539 opblk[4] = -1;
541 540
542 size = i2o_parm_issue(i2o_dev, I2O_CMD_UTIL_PARAMS_GET, opblk, 541 size = i2o_parm_issue(i2o_dev, I2O_CMD_UTIL_PARAMS_GET, opblk,
543 sizeof(opblk), resblk, sizeof(resblk)); 542 sizeof(opblk), resblk, buflen + 8);
544 543
545 memcpy(buf, resblk + 8, buflen); /* cut off header */ 544 memcpy(buf, resblk + 8, buflen); /* cut off header */
546 545
diff --git a/drivers/message/i2o/driver.c b/drivers/message/i2o/driver.c
index c71e68f70e7d..bebdd509b5d8 100644
--- a/drivers/message/i2o/driver.c
+++ b/drivers/message/i2o/driver.c
@@ -18,7 +18,7 @@
18#include <linux/rwsem.h> 18#include <linux/rwsem.h>
19#include <linux/i2o.h> 19#include <linux/i2o.h>
20 20
21#define OSM_NAME "core" 21#define OSM_NAME "i2o"
22 22
23/* max_drivers - Maximum I2O drivers (OSMs) which could be registered */ 23/* max_drivers - Maximum I2O drivers (OSMs) which could be registered */
24unsigned int i2o_max_drivers = I2O_MAX_DRIVERS; 24unsigned int i2o_max_drivers = I2O_MAX_DRIVERS;
@@ -78,17 +78,16 @@ int i2o_driver_register(struct i2o_driver *drv)
78 int rc = 0; 78 int rc = 0;
79 unsigned long flags; 79 unsigned long flags;
80 80
81 pr_debug("i2o: Register driver %s\n", drv->name); 81 osm_debug("Register driver %s\n", drv->name);
82 82
83 if (drv->event) { 83 if (drv->event) {
84 drv->event_queue = create_workqueue(drv->name); 84 drv->event_queue = create_workqueue(drv->name);
85 if (!drv->event_queue) { 85 if (!drv->event_queue) {
86 printk(KERN_ERR "i2o: Could not initialize event queue " 86 osm_err("Could not initialize event queue for driver "
87 "for driver %s\n", drv->name); 87 "%s\n", drv->name);
88 return -EFAULT; 88 return -EFAULT;
89 } 89 }
90 pr_debug("i2o: Event queue initialized for driver %s\n", 90 osm_debug("Event queue initialized for driver %s\n", drv->name);
91 drv->name);
92 } else 91 } else
93 drv->event_queue = NULL; 92 drv->event_queue = NULL;
94 93
@@ -99,8 +98,8 @@ int i2o_driver_register(struct i2o_driver *drv)
99 98
100 for (i = 0; i2o_drivers[i]; i++) 99 for (i = 0; i2o_drivers[i]; i++)
101 if (i >= i2o_max_drivers) { 100 if (i >= i2o_max_drivers) {
102 printk(KERN_ERR "i2o: too many drivers registered, " 101 osm_err("too many drivers registered, increase "
103 "increase max_drivers\n"); 102 "max_drivers\n");
104 spin_unlock_irqrestore(&i2o_drivers_lock, flags); 103 spin_unlock_irqrestore(&i2o_drivers_lock, flags);
105 return -EFAULT; 104 return -EFAULT;
106 } 105 }
@@ -110,8 +109,7 @@ int i2o_driver_register(struct i2o_driver *drv)
110 109
111 spin_unlock_irqrestore(&i2o_drivers_lock, flags); 110 spin_unlock_irqrestore(&i2o_drivers_lock, flags);
112 111
113 pr_debug("i2o: driver %s gets context id %d\n", drv->name, 112 osm_debug("driver %s gets context id %d\n", drv->name, drv->context);
114 drv->context);
115 113
116 list_for_each_entry(c, &i2o_controllers, list) { 114 list_for_each_entry(c, &i2o_controllers, list) {
117 struct i2o_device *i2o_dev; 115 struct i2o_device *i2o_dev;
@@ -141,7 +139,7 @@ void i2o_driver_unregister(struct i2o_driver *drv)
141 struct i2o_controller *c; 139 struct i2o_controller *c;
142 unsigned long flags; 140 unsigned long flags;
143 141
144 pr_debug("i2o: unregister driver %s\n", drv->name); 142 osm_debug("unregister driver %s\n", drv->name);
145 143
146 driver_unregister(&drv->driver); 144 driver_unregister(&drv->driver);
147 145
@@ -161,7 +159,7 @@ void i2o_driver_unregister(struct i2o_driver *drv)
161 if (drv->event_queue) { 159 if (drv->event_queue) {
162 destroy_workqueue(drv->event_queue); 160 destroy_workqueue(drv->event_queue);
163 drv->event_queue = NULL; 161 drv->event_queue = NULL;
164 pr_debug("i2o: event queue removed for %s\n", drv->name); 162 osm_debug("event queue removed for %s\n", drv->name);
165 } 163 }
166}; 164};
167 165
@@ -178,15 +176,15 @@ void i2o_driver_unregister(struct i2o_driver *drv)
178 * on success and if the message should be flushed afterwords. Returns 176 * on success and if the message should be flushed afterwords. Returns
179 * negative error code on failure (the message will be flushed too). 177 * negative error code on failure (the message will be flushed too).
180 */ 178 */
181int i2o_driver_dispatch(struct i2o_controller *c, u32 m, 179int i2o_driver_dispatch(struct i2o_controller *c, u32 m)
182 struct i2o_message __iomem *msg)
183{ 180{
184 struct i2o_driver *drv; 181 struct i2o_driver *drv;
182 struct i2o_message __iomem *msg = i2o_msg_out_to_virt(c, m);
185 u32 context = readl(&msg->u.s.icntxt); 183 u32 context = readl(&msg->u.s.icntxt);
186 184
187 if (unlikely(context >= i2o_max_drivers)) { 185 if (unlikely(context >= i2o_max_drivers)) {
188 printk(KERN_WARNING "%s: Spurious reply to unknown driver " 186 osm_warn("%s: Spurious reply to unknown driver %d\n", c->name,
189 "%d\n", c->name, readl(&msg->u.s.icntxt)); 187 context);
190 return -EIO; 188 return -EIO;
191 } 189 }
192 190
@@ -195,7 +193,8 @@ int i2o_driver_dispatch(struct i2o_controller *c, u32 m,
195 spin_unlock(&i2o_drivers_lock); 193 spin_unlock(&i2o_drivers_lock);
196 194
197 if (unlikely(!drv)) { 195 if (unlikely(!drv)) {
198 osm_warn("Spurious reply to unknown driver %d\n", context); 196 osm_warn("%s: Spurious reply to unknown driver %d\n", c->name,
197 context);
199 return -EIO; 198 return -EIO;
200 } 199 }
201 200
@@ -207,6 +206,9 @@ int i2o_driver_dispatch(struct i2o_controller *c, u32 m,
207 206
208 osm_debug("event received from device %d\n", tid); 207 osm_debug("event received from device %d\n", tid);
209 208
209 if (!drv->event)
210 return -EIO;
211
210 /* cut of header from message size (in 32-bit words) */ 212 /* cut of header from message size (in 32-bit words) */
211 size = (readl(&msg->u.head[0]) >> 16) - 5; 213 size = (readl(&msg->u.head[0]) >> 16) - 5;
212 214
@@ -231,8 +233,8 @@ int i2o_driver_dispatch(struct i2o_controller *c, u32 m,
231 } 233 }
232 234
233 if (unlikely(!drv->reply)) { 235 if (unlikely(!drv->reply)) {
234 pr_debug("%s: Reply to driver %s, but no reply function" 236 osm_debug("%s: Reply to driver %s, but no reply function"
235 " defined!\n", c->name, drv->name); 237 " defined!\n", c->name, drv->name);
236 return -EIO; 238 return -EIO;
237 } 239 }
238 240
@@ -333,11 +335,11 @@ int __init i2o_driver_init(void)
333 if ((i2o_max_drivers < 2) || (i2o_max_drivers > 64) || 335 if ((i2o_max_drivers < 2) || (i2o_max_drivers > 64) ||
334 ((i2o_max_drivers ^ (i2o_max_drivers - 1)) != 336 ((i2o_max_drivers ^ (i2o_max_drivers - 1)) !=
335 (2 * i2o_max_drivers - 1))) { 337 (2 * i2o_max_drivers - 1))) {
336 printk(KERN_WARNING "i2o: max_drivers set to %d, but must be " 338 osm_warn("max_drivers set to %d, but must be >=2 and <= 64 and "
337 ">=2 and <= 64 and a power of 2\n", i2o_max_drivers); 339 "a power of 2\n", i2o_max_drivers);
338 i2o_max_drivers = I2O_MAX_DRIVERS; 340 i2o_max_drivers = I2O_MAX_DRIVERS;
339 } 341 }
340 printk(KERN_INFO "i2o: max drivers = %d\n", i2o_max_drivers); 342 osm_info("max drivers = %d\n", i2o_max_drivers);
341 343
342 i2o_drivers = 344 i2o_drivers =
343 kmalloc(i2o_max_drivers * sizeof(*i2o_drivers), GFP_KERNEL); 345 kmalloc(i2o_max_drivers * sizeof(*i2o_drivers), GFP_KERNEL);
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index 1e28e886f1ca..5581344fbba6 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -108,7 +108,8 @@ static void i2o_exec_wait_free(struct i2o_exec_wait *wait)
108 * buffer must not be freed. Instead the event completion will free them 108 * buffer must not be freed. Instead the event completion will free them
109 * for you. In all other cases the buffer are your problem. 109 * for you. In all other cases the buffer are your problem.
110 * 110 *
111 * Returns 0 on success or negative error code on failure. 111 * Returns 0 on success, negative error code on timeout or positive error
112 * code from reply.
112 */ 113 */
113int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long 114int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
114 timeout, struct i2o_dma *dma) 115 timeout, struct i2o_dma *dma)
@@ -116,7 +117,7 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
116 DECLARE_WAIT_QUEUE_HEAD(wq); 117 DECLARE_WAIT_QUEUE_HEAD(wq);
117 struct i2o_exec_wait *wait; 118 struct i2o_exec_wait *wait;
118 static u32 tcntxt = 0x80000000; 119 static u32 tcntxt = 0x80000000;
119 struct i2o_message __iomem *msg = c->in_queue.virt + m; 120 struct i2o_message __iomem *msg = i2o_msg_in_to_virt(c, m);
120 int rc = 0; 121 int rc = 0;
121 122
122 wait = i2o_exec_wait_alloc(); 123 wait = i2o_exec_wait_alloc();
@@ -161,8 +162,7 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
161 barrier(); 162 barrier();
162 163
163 if (wait->complete) { 164 if (wait->complete) {
164 if (readl(&wait->msg->body[0]) >> 24) 165 rc = readl(&wait->msg->body[0]) >> 24;
165 rc = readl(&wait->msg->body[0]) & 0xff;
166 i2o_flush_reply(c, wait->m); 166 i2o_flush_reply(c, wait->m);
167 i2o_exec_wait_free(wait); 167 i2o_exec_wait_free(wait);
168 } else { 168 } else {
@@ -187,6 +187,7 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
187 * @c: I2O controller which answers 187 * @c: I2O controller which answers
188 * @m: message id 188 * @m: message id
189 * @msg: pointer to the I2O reply message 189 * @msg: pointer to the I2O reply message
190 * @context: transaction context of request
190 * 191 *
191 * This function is called in interrupt context only. If the reply reached 192 * This function is called in interrupt context only. If the reply reached
192 * before the timeout, the i2o_exec_wait struct is filled with the message 193 * before the timeout, the i2o_exec_wait struct is filled with the message
@@ -201,14 +202,12 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
201 * message must also be given back to the controller. 202 * message must also be given back to the controller.
202 */ 203 */
203static int i2o_msg_post_wait_complete(struct i2o_controller *c, u32 m, 204static int i2o_msg_post_wait_complete(struct i2o_controller *c, u32 m,
204 struct i2o_message __iomem *msg) 205 struct i2o_message __iomem *msg,
206 u32 context)
205{ 207{
206 struct i2o_exec_wait *wait, *tmp; 208 struct i2o_exec_wait *wait, *tmp;
207 static spinlock_t lock = SPIN_LOCK_UNLOCKED; 209 static spinlock_t lock = SPIN_LOCK_UNLOCKED;
208 int rc = 1; 210 int rc = 1;
209 u32 context;
210
211 context = readl(&msg->u.s.tcntxt);
212 211
213 /* 212 /*
214 * We need to search through the i2o_exec_wait_list to see if the given 213 * We need to search through the i2o_exec_wait_list to see if the given
@@ -251,7 +250,7 @@ static int i2o_msg_post_wait_complete(struct i2o_controller *c, u32 m,
251 250
252 spin_unlock(&lock); 251 spin_unlock(&lock);
253 252
254 pr_debug("%s: Bogus reply in POST WAIT (tr-context: %08x)!\n", c->name, 253 osm_warn("%s: Bogus reply in POST WAIT (tr-context: %08x)!\n", c->name,
255 context); 254 context);
256 255
257 return -1; 256 return -1;
@@ -321,29 +320,35 @@ static void i2o_exec_lct_modified(struct i2o_controller *c)
321 * code on failure and if the reply should be flushed. 320 * code on failure and if the reply should be flushed.
322 */ 321 */
323static int i2o_exec_reply(struct i2o_controller *c, u32 m, 322static int i2o_exec_reply(struct i2o_controller *c, u32 m,
324 struct i2o_message *msg) 323 struct i2o_message __iomem *msg)
325{ 324{
326 if (le32_to_cpu(msg->u.head[0]) & MSG_FAIL) { // Fail bit is set 325 u32 context;
327 struct i2o_message __iomem *pmsg; /* preserved message */ 326
327 if (readl(&msg->u.head[0]) & MSG_FAIL) {
328 /*
329 * If Fail bit is set we must take the transaction context of
330 * the preserved message to find the right request again.
331 */
332 struct i2o_message __iomem *pmsg;
328 u32 pm; 333 u32 pm;
329 334
330 pm = le32_to_cpu(msg->body[3]); 335 pm = readl(&msg->body[3]);
331 336
332 pmsg = i2o_msg_in_to_virt(c, pm); 337 pmsg = i2o_msg_in_to_virt(c, pm);
333 338
334 i2o_report_status(KERN_INFO, "i2o_core", msg); 339 i2o_report_status(KERN_INFO, "i2o_core", msg);
335 340
336 /* Release the preserved msg by resubmitting it as a NOP */ 341 context = readl(&pmsg->u.s.tcntxt);
337 i2o_msg_nop(c, pm);
338 342
339 /* If reply to i2o_post_wait failed, return causes a timeout */ 343 /* Release the preserved msg */
340 return -1; 344 i2o_msg_nop(c, pm);
341 } 345 } else
346 context = readl(&msg->u.s.tcntxt);
342 347
343 if (le32_to_cpu(msg->u.s.tcntxt) & 0x80000000) 348 if (context & 0x80000000)
344 return i2o_msg_post_wait_complete(c, m, msg); 349 return i2o_msg_post_wait_complete(c, m, msg, context);
345 350
346 if ((le32_to_cpu(msg->u.head[1]) >> 24) == I2O_CMD_LCT_NOTIFY) { 351 if ((readl(&msg->u.head[1]) >> 24) == I2O_CMD_LCT_NOTIFY) {
347 struct work_struct *work; 352 struct work_struct *work;
348 353
349 pr_debug("%s: LCT notify received\n", c->name); 354 pr_debug("%s: LCT notify received\n", c->name);
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index 4830b7759061..e69421e36ac5 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -104,7 +104,8 @@ static int i2o_block_remove(struct device *dev)
104 struct i2o_device *i2o_dev = to_i2o_device(dev); 104 struct i2o_device *i2o_dev = to_i2o_device(dev);
105 struct i2o_block_device *i2o_blk_dev = dev_get_drvdata(dev); 105 struct i2o_block_device *i2o_blk_dev = dev_get_drvdata(dev);
106 106
107 osm_info("Device removed %s\n", i2o_blk_dev->gd->disk_name); 107 osm_info("device removed (TID: %03x): %s\n", i2o_dev->lct_data.tid,
108 i2o_blk_dev->gd->disk_name);
108 109
109 i2o_event_register(i2o_dev, &i2o_block_driver, 0, 0); 110 i2o_event_register(i2o_dev, &i2o_block_driver, 0, 0);
110 111
@@ -400,71 +401,62 @@ static void i2o_block_delayed_request_fn(void *delayed_request)
400}; 401};
401 402
402/** 403/**
403 * i2o_block_reply - Block OSM reply handler. 404 * i2o_block_end_request - Post-processing of completed commands
404 * @c: I2O controller from which the message arrives 405 * @req: request which should be completed
405 * @m: message id of reply 406 * @uptodate: 1 for success, 0 for I/O error, < 0 for specific error
406 * qmsg: the actuall I2O message reply 407 * @nr_bytes: number of bytes to complete
407 * 408 *
408 * This function gets all the message replies. 409 * Mark the request as complete. The lock must not be held when entering.
409 * 410 *
410 */ 411 */
411static int i2o_block_reply(struct i2o_controller *c, u32 m, 412static void i2o_block_end_request(struct request *req, int uptodate,
412 struct i2o_message *msg) 413 int nr_bytes)
413{ 414{
414 struct i2o_block_request *ireq; 415 struct i2o_block_request *ireq = req->special;
415 struct request *req; 416 struct i2o_block_device *dev = ireq->i2o_blk_dev;
416 struct i2o_block_device *dev; 417 request_queue_t *q = dev->gd->queue;
417 struct request_queue *q;
418 u8 st;
419 unsigned long flags; 418 unsigned long flags;
420 419
421 /* FAILed message */ 420 if (end_that_request_chunk(req, uptodate, nr_bytes)) {
422 if (unlikely(le32_to_cpu(msg->u.head[0]) & (1 << 13))) { 421 int leftover = (req->hard_nr_sectors << 9);
423 struct i2o_message *pmsg;
424 u32 pm;
425
426 /*
427 * FAILed message from controller
428 * We increment the error count and abort it
429 *
430 * In theory this will never happen. The I2O block class
431 * specification states that block devices never return
432 * FAILs but instead use the REQ status field...but
433 * better be on the safe side since no one really follows
434 * the spec to the book :)
435 */
436 pm = le32_to_cpu(msg->body[3]);
437 pmsg = i2o_msg_in_to_virt(c, pm);
438 422
439 req = i2o_cntxt_list_get(c, le32_to_cpu(pmsg->u.s.tcntxt)); 423 if (blk_pc_request(req))
440 if (unlikely(!req)) { 424 leftover = req->data_len;
441 osm_err("NULL reply received!\n");
442 return -1;
443 }
444 425
445 ireq = req->special; 426 if (end_io_error(uptodate))
446 dev = ireq->i2o_blk_dev; 427 end_that_request_chunk(req, 0, leftover);
447 q = dev->gd->queue; 428 }
448 429
449 req->errors++; 430 add_disk_randomness(req->rq_disk);
450 431
451 spin_lock_irqsave(q->queue_lock, flags); 432 spin_lock_irqsave(q->queue_lock, flags);
452 433
453 while (end_that_request_chunk(req, !req->errors, 434 end_that_request_last(req);
454 le32_to_cpu(pmsg->body[1]))) ; 435 dev->open_queue_depth--;
455 end_that_request_last(req); 436 list_del(&ireq->queue);
456 437
457 dev->open_queue_depth--; 438 blk_start_queue(q);
458 list_del(&ireq->queue);
459 blk_start_queue(q);
460 439
461 spin_unlock_irqrestore(q->queue_lock, flags); 440 spin_unlock_irqrestore(q->queue_lock, flags);
462 441
463 /* Now flush the message by making it a NOP */ 442 i2o_block_sglist_free(ireq);
464 i2o_msg_nop(c, pm); 443 i2o_block_request_free(ireq);
444};
465 445
466 return -1; 446/**
467 } 447 * i2o_block_reply - Block OSM reply handler.
448 * @c: I2O controller from which the message arrives
449 * @m: message id of reply
450 * qmsg: the actuall I2O message reply
451 *
452 * This function gets all the message replies.
453 *
454 */
455static int i2o_block_reply(struct i2o_controller *c, u32 m,
456 struct i2o_message *msg)
457{
458 struct request *req;
459 int uptodate = 1;
468 460
469 req = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt)); 461 req = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt));
470 if (unlikely(!req)) { 462 if (unlikely(!req)) {
@@ -472,61 +464,13 @@ static int i2o_block_reply(struct i2o_controller *c, u32 m,
472 return -1; 464 return -1;
473 } 465 }
474 466
475 ireq = req->special;
476 dev = ireq->i2o_blk_dev;
477 q = dev->gd->queue;
478
479 if (unlikely(!dev->i2o_dev)) {
480 /*
481 * This is HACK, but Intel Integrated RAID allows user
482 * to delete a volume that is claimed, locked, and in use
483 * by the OS. We have to check for a reply from a
484 * non-existent device and flag it as an error or the system
485 * goes kaput...
486 */
487 req->errors++;
488 osm_warn("Data transfer to deleted device!\n");
489 spin_lock_irqsave(q->queue_lock, flags);
490 while (end_that_request_chunk
491 (req, !req->errors, le32_to_cpu(msg->body[1]))) ;
492 end_that_request_last(req);
493
494 dev->open_queue_depth--;
495 list_del(&ireq->queue);
496 blk_start_queue(q);
497
498 spin_unlock_irqrestore(q->queue_lock, flags);
499 return -1;
500 }
501
502 /* 467 /*
503 * Lets see what is cooking. We stuffed the 468 * Lets see what is cooking. We stuffed the
504 * request in the context. 469 * request in the context.
505 */ 470 */
506 471
507 st = le32_to_cpu(msg->body[0]) >> 24; 472 if ((le32_to_cpu(msg->body[0]) >> 24) != 0) {
508 473 u32 status = le32_to_cpu(msg->body[0]);
509 if (st != 0) {
510 int err;
511 char *bsa_errors[] = {
512 "Success",
513 "Media Error",
514 "Failure communicating to device",
515 "Device Failure",
516 "Device is not ready",
517 "Media not present",
518 "Media is locked by another user",
519 "Media has failed",
520 "Failure communicating to device",
521 "Device bus failure",
522 "Device is locked by another user",
523 "Device is write protected",
524 "Device has reset",
525 "Volume has changed, waiting for acknowledgement"
526 };
527
528 err = le32_to_cpu(msg->body[0]) & 0xffff;
529
530 /* 474 /*
531 * Device not ready means two things. One is that the 475 * Device not ready means two things. One is that the
532 * the thing went offline (but not a removal media) 476 * the thing went offline (but not a removal media)
@@ -539,40 +483,23 @@ static int i2o_block_reply(struct i2o_controller *c, u32 m,
539 * Don't stick a supertrak100 into cache aggressive modes 483 * Don't stick a supertrak100 into cache aggressive modes
540 */ 484 */
541 485
542 osm_err("block-osm: /dev/%s error: %s", dev->gd->disk_name, 486 osm_err("%03x error status: %02x, detailed status: %04x\n",
543 bsa_errors[le32_to_cpu(msg->body[0]) & 0xffff]); 487 (le32_to_cpu(msg->u.head[1]) >> 12 & 0xfff),
544 if (le32_to_cpu(msg->body[0]) & 0x00ff0000) 488 status >> 24, status & 0xffff);
545 printk(KERN_ERR " - DDM attempted %d retries",
546 (le32_to_cpu(msg->body[0]) >> 16) & 0x00ff);
547 printk(KERN_ERR ".\n");
548 req->errors++;
549 } else
550 req->errors = 0;
551
552 if (!end_that_request_chunk
553 (req, !req->errors, le32_to_cpu(msg->body[1]))) {
554 add_disk_randomness(req->rq_disk);
555 spin_lock_irqsave(q->queue_lock, flags);
556 489
557 end_that_request_last(req); 490 req->errors++;
558 491
559 dev->open_queue_depth--; 492 uptodate = 0;
560 list_del(&ireq->queue); 493 }
561 blk_start_queue(q);
562 494
563 spin_unlock_irqrestore(q->queue_lock, flags); 495 i2o_block_end_request(req, uptodate, le32_to_cpu(msg->body[1]));
564
565 i2o_block_sglist_free(ireq);
566 i2o_block_request_free(ireq);
567 } else
568 osm_err("still remaining chunks\n");
569 496
570 return 1; 497 return 1;
571}; 498};
572 499
573static void i2o_block_event(struct i2o_event *evt) 500static void i2o_block_event(struct i2o_event *evt)
574{ 501{
575 osm_info("block-osm: event received\n"); 502 osm_info("event received\n");
576 kfree(evt); 503 kfree(evt);
577}; 504};
578 505
@@ -875,9 +802,7 @@ static int i2o_block_transfer(struct request *req)
875 sg++; 802 sg++;
876 } 803 }
877 804
878 writel(I2O_MESSAGE_SIZE 805 writel(I2O_MESSAGE_SIZE(mptr - &msg->u.head[0]) | SGL_OFFSET_8,
879 (((unsigned long)mptr -
880 (unsigned long)&msg->u.head[0]) >> 2) | SGL_OFFSET_8,
881 &msg->u.head[0]); 806 &msg->u.head[0]);
882 807
883 list_add_tail(&ireq->queue, &dev->open_queue); 808 list_add_tail(&ireq->queue, &dev->open_queue);
@@ -1048,7 +973,6 @@ static int i2o_block_probe(struct device *dev)
1048 int rc; 973 int rc;
1049 u64 size; 974 u64 size;
1050 u32 blocksize; 975 u32 blocksize;
1051 u16 power;
1052 u32 flags, status; 976 u32 flags, status;
1053 int segments; 977 int segments;
1054 978
@@ -1058,8 +982,6 @@ static int i2o_block_probe(struct device *dev)
1058 return -ENODEV; 982 return -ENODEV;
1059 } 983 }
1060 984
1061 osm_info("New device detected (TID: %03x)\n", i2o_dev->lct_data.tid);
1062
1063 if (i2o_device_claim(i2o_dev)) { 985 if (i2o_device_claim(i2o_dev)) {
1064 osm_warn("Unable to claim device. Installation aborted\n"); 986 osm_warn("Unable to claim device. Installation aborted\n");
1065 rc = -EFAULT; 987 rc = -EFAULT;
@@ -1111,15 +1033,21 @@ static int i2o_block_probe(struct device *dev)
1111 * Ask for the current media data. If that isn't supported 1033 * Ask for the current media data. If that isn't supported
1112 * then we ask for the device capacity data 1034 * then we ask for the device capacity data
1113 */ 1035 */
1114 if (i2o_parm_field_get(i2o_dev, 0x0004, 1, &blocksize, 4) != 0 1036 if (!i2o_parm_field_get(i2o_dev, 0x0004, 0, &size, 8))
1115 || i2o_parm_field_get(i2o_dev, 0x0004, 0, &size, 8) != 0) { 1037 if (!i2o_parm_field_get(i2o_dev, 0x0000, 4, &size, 8)) {
1116 i2o_parm_field_get(i2o_dev, 0x0000, 3, &blocksize, 4); 1038 osm_warn("could not get size of %s\n", gd->disk_name);
1117 i2o_parm_field_get(i2o_dev, 0x0000, 4, &size, 8); 1039 size = 0;
1118 } 1040 }
1119 osm_debug("blocksize = %d\n", blocksize);
1120 1041
1121 if (i2o_parm_field_get(i2o_dev, 0x0000, 2, &power, 2)) 1042 if (!i2o_parm_field_get(i2o_dev, 0x0004, 1, &blocksize, 4))
1122 power = 0; 1043 if (!i2o_parm_field_get(i2o_dev, 0x0000, 3, &blocksize, 4)) {
1044 osm_warn("unable to get blocksize of %s\n",
1045 gd->disk_name);
1046 blocksize = 0;
1047 }
1048
1049 if (!i2o_parm_field_get(i2o_dev, 0x0000, 2, &i2o_blk_dev->power, 2))
1050 i2o_blk_dev->power = 0;
1123 i2o_parm_field_get(i2o_dev, 0x0000, 5, &flags, 4); 1051 i2o_parm_field_get(i2o_dev, 0x0000, 5, &flags, 4);
1124 i2o_parm_field_get(i2o_dev, 0x0000, 6, &status, 4); 1052 i2o_parm_field_get(i2o_dev, 0x0000, 6, &status, 4);
1125 1053
@@ -1131,6 +1059,9 @@ static int i2o_block_probe(struct device *dev)
1131 1059
1132 unit++; 1060 unit++;
1133 1061
1062 osm_info("device added (TID: %03x): %s\n", i2o_dev->lct_data.tid,
1063 i2o_blk_dev->gd->disk_name);
1064
1134 return 0; 1065 return 0;
1135 1066
1136 claim_release: 1067 claim_release:
diff --git a/drivers/message/i2o/i2o_block.h b/drivers/message/i2o/i2o_block.h
index ddd9a15679c0..712111ffa638 100644
--- a/drivers/message/i2o/i2o_block.h
+++ b/drivers/message/i2o/i2o_block.h
@@ -74,7 +74,7 @@ struct i2o_block_device {
74 int rcache; /* read cache flags */ 74 int rcache; /* read cache flags */
75 int wcache; /* write cache flags */ 75 int wcache; /* write cache flags */
76 int flags; 76 int flags;
77 int power; /* power state */ 77 u16 power; /* power state */
78 int media_change_flag; /* media changed flag */ 78 int media_change_flag; /* media changed flag */
79}; 79};
80 80
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 46d373287a30..383e89a5c9f0 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -80,13 +80,123 @@ struct i2o_cfg_info {
80static struct i2o_cfg_info *open_files = NULL; 80static struct i2o_cfg_info *open_files = NULL;
81static ulong i2o_cfg_info_id = 0; 81static ulong i2o_cfg_info_id = 0;
82 82
83/* 83/**
84 * Each of these describes an i2o message handler. They are 84 * i2o_config_read_hrt - Returns the HRT of the controller
85 * multiplexed by the i2o_core code 85 * @kob: kernel object handle
86 * @buf: buffer into which the HRT should be copied
87 * @off: file offset
88 * @count: number of bytes to read
89 *
90 * Put @count bytes starting at @off into @buf from the HRT of the I2O
91 * controller corresponding to @kobj.
92 *
93 * Returns number of bytes copied into buffer.
94 */
95static ssize_t i2o_config_read_hrt(struct kobject *kobj, char *buf,
96 loff_t offset, size_t count)
97{
98 struct i2o_controller *c = to_i2o_controller(container_of(kobj,
99 struct device,
100 kobj));
101 i2o_hrt *hrt = c->hrt.virt;
102
103 u32 size = (hrt->num_entries * hrt->entry_len + 2) * 4;
104
105 if(offset > size)
106 return 0;
107
108 if(offset + count > size)
109 count = size - offset;
110
111 memcpy(buf, (u8 *) hrt + offset, count);
112
113 return count;
114};
115
116/**
117 * i2o_config_read_lct - Returns the LCT of the controller
118 * @kob: kernel object handle
119 * @buf: buffer into which the LCT should be copied
120 * @off: file offset
121 * @count: number of bytes to read
122 *
123 * Put @count bytes starting at @off into @buf from the LCT of the I2O
124 * controller corresponding to @kobj.
125 *
126 * Returns number of bytes copied into buffer.
127 */
128static ssize_t i2o_config_read_lct(struct kobject *kobj, char *buf,
129 loff_t offset, size_t count)
130{
131 struct i2o_controller *c = to_i2o_controller(container_of(kobj,
132 struct device,
133 kobj));
134 u32 size = c->lct->table_size * 4;
135
136 if(offset > size)
137 return 0;
138
139 if(offset + count > size)
140 count = size - offset;
141
142 memcpy(buf, (u8 *) c->lct + offset, count);
143
144 return count;
145};
146
147/* attribute for HRT in sysfs */
148static struct bin_attribute i2o_config_hrt_attr = {
149 .attr = {
150 .name = "hrt",
151 .mode = S_IRUGO,
152 .owner = THIS_MODULE
153 },
154 .size = 0,
155 .read = i2o_config_read_hrt
156};
157
158/* attribute for LCT in sysfs */
159static struct bin_attribute i2o_config_lct_attr = {
160 .attr = {
161 .name = "lct",
162 .mode = S_IRUGO,
163 .owner = THIS_MODULE
164 },
165 .size = 0,
166 .read = i2o_config_read_lct
167};
168
169/**
170 * i2o_config_notify_controller_add - Notify of added controller
171 * @c: the controller which was added
172 *
173 * If a I2O controller is added, we catch the notification to add sysfs
174 * entries.
175 */
176static void i2o_config_notify_controller_add(struct i2o_controller *c)
177{
178 sysfs_create_bin_file(&(c->device.kobj), &i2o_config_hrt_attr);
179 sysfs_create_bin_file(&(c->device.kobj), &i2o_config_lct_attr);
180};
181
182/**
183 * i2o_config_notify_controller_remove - Notify of removed controller
184 * @c: the controller which was removed
185 *
186 * If a I2O controller is removed, we catch the notification to remove the
187 * sysfs entries.
86 */ 188 */
189static void i2o_config_notify_controller_remove(struct i2o_controller *c)
190{
191 sysfs_remove_bin_file(&c->device.kobj, &i2o_config_lct_attr);
192 sysfs_remove_bin_file(&c->device.kobj, &i2o_config_hrt_attr);
193};
87 194
195/* Config OSM driver struct */
88static struct i2o_driver i2o_config_driver = { 196static struct i2o_driver i2o_config_driver = {
89 .name = OSM_NAME 197 .name = OSM_NAME,
198 .notify_controller_add = i2o_config_notify_controller_add,
199 .notify_controller_remove = i2o_config_notify_controller_remove
90}; 200};
91 201
92static int i2o_cfg_getiops(unsigned long arg) 202static int i2o_cfg_getiops(unsigned long arg)
diff --git a/drivers/message/i2o/i2o_scsi.c b/drivers/message/i2o/i2o_scsi.c
index af40f1c1ec77..812c29ec86d3 100644
--- a/drivers/message/i2o/i2o_scsi.c
+++ b/drivers/message/i2o/i2o_scsi.c
@@ -40,6 +40,7 @@
40 * Fix the resource management problems. 40 * Fix the resource management problems.
41 */ 41 */
42 42
43#define DEBUG 1
43#include <linux/module.h> 44#include <linux/module.h>
44#include <linux/kernel.h> 45#include <linux/kernel.h>
45#include <linux/types.h> 46#include <linux/types.h>
@@ -179,6 +180,8 @@ static int i2o_scsi_remove(struct device *dev)
179 struct i2o_scsi_host *i2o_shost; 180 struct i2o_scsi_host *i2o_shost;
180 struct scsi_device *scsi_dev; 181 struct scsi_device *scsi_dev;
181 182
183 osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);
184
182 i2o_shost = i2o_scsi_get_host(c); 185 i2o_shost = i2o_scsi_get_host(c);
183 186
184 shost_for_each_device(scsi_dev, i2o_shost->scsi_host) 187 shost_for_each_device(scsi_dev, i2o_shost->scsi_host)
@@ -262,8 +265,8 @@ static int i2o_scsi_probe(struct device *dev)
262 return -EFAULT; 265 return -EFAULT;
263 } 266 }
264 267
265 osm_debug("added new SCSI device %03x (cannel: %d, id: %d, lun: %d)\n", 268 osm_info("device added (TID: %03x) channel: %d, id: %d, lun: %d\n",
266 i2o_dev->lct_data.tid, channel, id, (unsigned int)lun); 269 i2o_dev->lct_data.tid, channel, id, (unsigned int)lun);
267 270
268 return 0; 271 return 0;
269}; 272};
@@ -439,8 +442,6 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
439 442
440 cmd->result = DID_OK << 16 | ds; 443 cmd->result = DID_OK << 16 | ds;
441 444
442 cmd->scsi_done(cmd);
443
444 dev = &c->pdev->dev; 445 dev = &c->pdev->dev;
445 if (cmd->use_sg) 446 if (cmd->use_sg)
446 dma_unmap_sg(dev, (struct scatterlist *)cmd->buffer, 447 dma_unmap_sg(dev, (struct scatterlist *)cmd->buffer,
@@ -449,6 +450,8 @@ static int i2o_scsi_reply(struct i2o_controller *c, u32 m,
449 dma_unmap_single(dev, (dma_addr_t) ((long)cmd->SCp.ptr), 450 dma_unmap_single(dev, (dma_addr_t) ((long)cmd->SCp.ptr),
450 cmd->request_bufflen, cmd->sc_data_direction); 451 cmd->request_bufflen, cmd->sc_data_direction);
451 452
453 cmd->scsi_done(cmd);
454
452 return 1; 455 return 1;
453}; 456};
454 457
@@ -502,7 +505,7 @@ static void i2o_scsi_notify_controller_remove(struct i2o_controller *c)
502 505
503 scsi_remove_host(i2o_shost->scsi_host); 506 scsi_remove_host(i2o_shost->scsi_host);
504 scsi_host_put(i2o_shost->scsi_host); 507 scsi_host_put(i2o_shost->scsi_host);
505 pr_info("I2O SCSI host removed\n"); 508 osm_debug("I2O SCSI host removed\n");
506}; 509};
507 510
508/* SCSI OSM driver struct */ 511/* SCSI OSM driver struct */
@@ -545,7 +548,7 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
545 u32 scsi_flags, sg_flags; 548 u32 scsi_flags, sg_flags;
546 u32 __iomem *mptr; 549 u32 __iomem *mptr;
547 u32 __iomem *lenptr; 550 u32 __iomem *lenptr;
548 u32 len, reqlen; 551 u32 len;
549 int i; 552 int i;
550 553
551 /* 554 /*
@@ -580,12 +583,12 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
580 if (m == I2O_QUEUE_EMPTY) 583 if (m == I2O_QUEUE_EMPTY)
581 return SCSI_MLQUEUE_HOST_BUSY; 584 return SCSI_MLQUEUE_HOST_BUSY;
582 585
586 mptr = &msg->body[0];
587
583 /* 588 /*
584 * Put together a scsi execscb message 589 * Put together a scsi execscb message
585 */ 590 */
586 591
587 len = SCpnt->request_bufflen;
588
589 switch (SCpnt->sc_data_direction) { 592 switch (SCpnt->sc_data_direction) {
590 case PCI_DMA_NONE: 593 case PCI_DMA_NONE:
591 scsi_flags = 0x00000000; // DATA NO XFER 594 scsi_flags = 0x00000000; // DATA NO XFER
@@ -637,17 +640,13 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
637 */ 640 */
638 641
639 /* Direction, disconnect ok, tag, CDBLen */ 642 /* Direction, disconnect ok, tag, CDBLen */
640 writel(scsi_flags | 0x20200000 | SCpnt->cmd_len, &msg->body[0]); 643 writel(scsi_flags | 0x20200000 | SCpnt->cmd_len, mptr ++);
641
642 mptr = &msg->body[1];
643 644
644 /* Write SCSI command into the message - always 16 byte block */ 645 /* Write SCSI command into the message - always 16 byte block */
645 memcpy_toio(mptr, SCpnt->cmnd, 16); 646 memcpy_toio(mptr, SCpnt->cmnd, 16);
646 mptr += 4; 647 mptr += 4;
647 lenptr = mptr++; /* Remember me - fill in when we know */ 648 lenptr = mptr++; /* Remember me - fill in when we know */
648 649
649 reqlen = 12; // SINGLE SGE
650
651 /* Now fill in the SGList and command */ 650 /* Now fill in the SGList and command */
652 if (SCpnt->use_sg) { 651 if (SCpnt->use_sg) {
653 struct scatterlist *sg; 652 struct scatterlist *sg;
@@ -671,7 +670,6 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
671 sg++; 670 sg++;
672 } 671 }
673 672
674 reqlen = mptr - &msg->u.head[0];
675 writel(len, lenptr); 673 writel(len, lenptr);
676 } else { 674 } else {
677 len = SCpnt->request_bufflen; 675 len = SCpnt->request_bufflen;
@@ -691,12 +689,11 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
691 sg_flags |= 0xC0000000; 689 sg_flags |= 0xC0000000;
692 writel(sg_flags | SCpnt->request_bufflen, mptr++); 690 writel(sg_flags | SCpnt->request_bufflen, mptr++);
693 writel(dma_addr, mptr++); 691 writel(dma_addr, mptr++);
694 } else 692 }
695 reqlen = 9;
696 } 693 }
697 694
698 /* Stick the headers on */ 695 /* Stick the headers on */
699 writel(reqlen << 16 | SGL_OFFSET_10, &msg->u.head[0]); 696 writel((mptr - &msg->u.head[0]) << 16 | SGL_OFFSET_10, &msg->u.head[0]);
700 697
701 /* Queue the message */ 698 /* Queue the message */
702 i2o_msg_post(c, m); 699 i2o_msg_post(c, m);
diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
index 50c8cedf7a2d..62b0d8bed186 100644
--- a/drivers/message/i2o/iop.c
+++ b/drivers/message/i2o/iop.c
@@ -68,7 +68,7 @@ extern void i2o_device_exit(void);
68 */ 68 */
69void i2o_msg_nop(struct i2o_controller *c, u32 m) 69void i2o_msg_nop(struct i2o_controller *c, u32 m)
70{ 70{
71 struct i2o_message __iomem *msg = c->in_queue.virt + m; 71 struct i2o_message __iomem *msg = i2o_msg_in_to_virt(c, m);
72 72
73 writel(THREE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]); 73 writel(THREE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
74 writel(I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | ADAPTER_TID, 74 writel(I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | ADAPTER_TID,
@@ -452,8 +452,6 @@ static int i2o_iop_clear(struct i2o_controller *c)
452 /* Enable all IOPs */ 452 /* Enable all IOPs */
453 i2o_iop_enable_all(); 453 i2o_iop_enable_all();
454 454
455 i2o_status_get(c);
456
457 return rc; 455 return rc;
458} 456}
459 457
@@ -591,12 +589,11 @@ static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
591 if (m == I2O_QUEUE_EMPTY) 589 if (m == I2O_QUEUE_EMPTY)
592 return -ETIMEDOUT; 590 return -ETIMEDOUT;
593 591
594 writel(EIGHT_WORD_MSG_SIZE | TRL_OFFSET_6, &msg->u.head[0]); 592 writel(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6, &msg->u.head[0]);
595 writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID, 593 writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID,
596 &msg->u.head[1]); 594 &msg->u.head[1]);
597 writel(i2o_exec_driver.context, &msg->u.s.icntxt); 595 writel(i2o_exec_driver.context, &msg->u.s.icntxt);
598 writel(0x0106, &msg->u.s.tcntxt); /* FIXME: why 0x0106, maybe in 596 writel(0x00000000, &msg->u.s.tcntxt);
599 Spec? */
600 writel(PAGE_SIZE, &msg->body[0]); 597 writel(PAGE_SIZE, &msg->body[0]);
601 writel(MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); /* Outbound msg frame 598 writel(MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); /* Outbound msg frame
602 size in words and Initcode */ 599 size in words and Initcode */
@@ -891,8 +888,12 @@ void i2o_iop_remove(struct i2o_controller *c)
891 list_for_each_entry_safe(dev, tmp, &c->devices, list) 888 list_for_each_entry_safe(dev, tmp, &c->devices, list)
892 i2o_device_remove(dev); 889 i2o_device_remove(dev);
893 890
891 device_del(&c->device);
892
894 /* Ask the IOP to switch to RESET state */ 893 /* Ask the IOP to switch to RESET state */
895 i2o_iop_reset(c); 894 i2o_iop_reset(c);
895
896 put_device(&c->device);
896} 897}
897 898
898/** 899/**
@@ -971,8 +972,10 @@ static int i2o_systab_build(void)
971 systab->iops[count].frame_size = sb->inbound_frame_size; 972 systab->iops[count].frame_size = sb->inbound_frame_size;
972 systab->iops[count].last_changed = change_ind; 973 systab->iops[count].last_changed = change_ind;
973 systab->iops[count].iop_capabilities = sb->iop_capabilities; 974 systab->iops[count].iop_capabilities = sb->iop_capabilities;
974 systab->iops[count].inbound_low = i2o_ptr_low(c->post_port); 975 systab->iops[count].inbound_low =
975 systab->iops[count].inbound_high = i2o_ptr_high(c->post_port); 976 i2o_dma_low(c->base.phys + I2O_IN_PORT);
977 systab->iops[count].inbound_high =
978 i2o_dma_high(c->base.phys + I2O_IN_PORT);
976 979
977 count++; 980 count++;
978 } 981 }
@@ -1110,6 +1113,30 @@ static int i2o_hrt_get(struct i2o_controller *c)
1110} 1113}
1111 1114
1112/** 1115/**
1116 * i2o_iop_free - Free the i2o_controller struct
1117 * @c: I2O controller to free
1118 */
1119void i2o_iop_free(struct i2o_controller *c)
1120{
1121 kfree(c);
1122};
1123
1124
1125/**
1126 * i2o_iop_release - release the memory for a I2O controller
1127 * @dev: I2O controller which should be released
1128 *
1129 * Release the allocated memory. This function is called if refcount of
1130 * device reaches 0 automatically.
1131 */
1132static void i2o_iop_release(struct device *dev)
1133{
1134 struct i2o_controller *c = to_i2o_controller(dev);
1135
1136 i2o_iop_free(c);
1137};
1138
1139/**
1113 * i2o_iop_alloc - Allocate and initialize a i2o_controller struct 1140 * i2o_iop_alloc - Allocate and initialize a i2o_controller struct
1114 * 1141 *
1115 * Allocate the necessary memory for a i2o_controller struct and 1142 * Allocate the necessary memory for a i2o_controller struct and
@@ -1137,6 +1164,10 @@ struct i2o_controller *i2o_iop_alloc(void)
1137 c->unit = unit++; 1164 c->unit = unit++;
1138 sprintf(c->name, "iop%d", c->unit); 1165 sprintf(c->name, "iop%d", c->unit);
1139 1166
1167 device_initialize(&c->device);
1168 c->device.release = &i2o_iop_release;
1169 snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit);
1170
1140#if BITS_PER_LONG == 64 1171#if BITS_PER_LONG == 64
1141 spin_lock_init(&c->context_list_lock); 1172 spin_lock_init(&c->context_list_lock);
1142 atomic_set(&c->context_list_counter, 0); 1173 atomic_set(&c->context_list_counter, 0);
@@ -1147,15 +1178,6 @@ struct i2o_controller *i2o_iop_alloc(void)
1147}; 1178};
1148 1179
1149/** 1180/**
1150 * i2o_iop_free - Free the i2o_controller struct
1151 * @c: I2O controller to free
1152 */
1153void i2o_iop_free(struct i2o_controller *c)
1154{
1155 kfree(c);
1156};
1157
1158/**
1159 * i2o_iop_add - Initialize the I2O controller and add him to the I2O core 1181 * i2o_iop_add - Initialize the I2O controller and add him to the I2O core
1160 * @c: controller 1182 * @c: controller
1161 * 1183 *
@@ -1168,6 +1190,11 @@ int i2o_iop_add(struct i2o_controller *c)
1168{ 1190{
1169 int rc; 1191 int rc;
1170 1192
1193 if((rc = device_add(&c->device))) {
1194 printk(KERN_ERR "%s: could not register controller\n", c->name);
1195 goto iop_reset;
1196 }
1197
1171 printk(KERN_INFO "%s: Activating I2O controller...\n", c->name); 1198 printk(KERN_INFO "%s: Activating I2O controller...\n", c->name);
1172 printk(KERN_INFO "%s: This may take a few minutes if there are many " 1199 printk(KERN_INFO "%s: This may take a few minutes if there are many "
1173 "devices\n", c->name); 1200 "devices\n", c->name);
@@ -1175,30 +1202,23 @@ int i2o_iop_add(struct i2o_controller *c)
1175 if ((rc = i2o_iop_activate(c))) { 1202 if ((rc = i2o_iop_activate(c))) {
1176 printk(KERN_ERR "%s: could not activate controller\n", 1203 printk(KERN_ERR "%s: could not activate controller\n",
1177 c->name); 1204 c->name);
1178 i2o_iop_reset(c); 1205 goto iop_reset;
1179 return rc;
1180 } 1206 }
1181 1207
1182 pr_debug("%s: building sys table...\n", c->name); 1208 pr_debug("%s: building sys table...\n", c->name);
1183 1209
1184 if ((rc = i2o_systab_build())) { 1210 if ((rc = i2o_systab_build()))
1185 i2o_iop_reset(c); 1211 goto iop_reset;
1186 return rc;
1187 }
1188 1212
1189 pr_debug("%s: online controller...\n", c->name); 1213 pr_debug("%s: online controller...\n", c->name);
1190 1214
1191 if ((rc = i2o_iop_online(c))) { 1215 if ((rc = i2o_iop_online(c)))
1192 i2o_iop_reset(c); 1216 goto iop_reset;
1193 return rc;
1194 }
1195 1217
1196 pr_debug("%s: getting LCT...\n", c->name); 1218 pr_debug("%s: getting LCT...\n", c->name);
1197 1219
1198 if ((rc = i2o_exec_lct_get(c))) { 1220 if ((rc = i2o_exec_lct_get(c)))
1199 i2o_iop_reset(c); 1221 goto iop_reset;
1200 return rc;
1201 }
1202 1222
1203 list_add(&c->list, &i2o_controllers); 1223 list_add(&c->list, &i2o_controllers);
1204 1224
@@ -1207,6 +1227,11 @@ int i2o_iop_add(struct i2o_controller *c)
1207 printk(KERN_INFO "%s: Controller added\n", c->name); 1227 printk(KERN_INFO "%s: Controller added\n", c->name);
1208 1228
1209 return 0; 1229 return 0;
1230
1231iop_reset:
1232 i2o_iop_reset(c);
1233
1234 return rc;
1210}; 1235};
1211 1236
1212/** 1237/**
diff --git a/drivers/message/i2o/pci.c b/drivers/message/i2o/pci.c
index 579a8b7a2120..f33fd81f77a4 100644
--- a/drivers/message/i2o/pci.c
+++ b/drivers/message/i2o/pci.c
@@ -38,8 +38,7 @@ extern void i2o_iop_free(struct i2o_controller *);
38extern int i2o_iop_add(struct i2o_controller *); 38extern int i2o_iop_add(struct i2o_controller *);
39extern void i2o_iop_remove(struct i2o_controller *); 39extern void i2o_iop_remove(struct i2o_controller *);
40 40
41extern int i2o_driver_dispatch(struct i2o_controller *, u32, 41extern int i2o_driver_dispatch(struct i2o_controller *, u32);
42 struct i2o_message *);
43 42
44/* PCI device id table for all I2O controllers */ 43/* PCI device id table for all I2O controllers */
45static struct pci_device_id __devinitdata i2o_pci_ids[] = { 44static struct pci_device_id __devinitdata i2o_pci_ids[] = {
@@ -89,8 +88,7 @@ static void i2o_pci_free(struct i2o_controller *c)
89 88
90 i2o_dma_free(dev, &c->out_queue); 89 i2o_dma_free(dev, &c->out_queue);
91 i2o_dma_free(dev, &c->status_block); 90 i2o_dma_free(dev, &c->status_block);
92 if (c->lct) 91 kfree(c->lct);
93 kfree(c->lct);
94 i2o_dma_free(dev, &c->dlct); 92 i2o_dma_free(dev, &c->dlct);
95 i2o_dma_free(dev, &c->hrt); 93 i2o_dma_free(dev, &c->hrt);
96 i2o_dma_free(dev, &c->status); 94 i2o_dma_free(dev, &c->status);
@@ -187,9 +185,9 @@ static int __devinit i2o_pci_alloc(struct i2o_controller *c)
187 } else 185 } else
188 c->in_queue = c->base; 186 c->in_queue = c->base;
189 187
190 c->irq_mask = c->base.virt + 0x34; 188 c->irq_mask = c->base.virt + I2O_IRQ_MASK;
191 c->post_port = c->base.virt + 0x40; 189 c->in_port = c->base.virt + I2O_IN_PORT;
192 c->reply_port = c->base.virt + 0x44; 190 c->out_port = c->base.virt + I2O_OUT_PORT;
193 191
194 if (i2o_dma_alloc(dev, &c->status, 8, GFP_KERNEL)) { 192 if (i2o_dma_alloc(dev, &c->status, 8, GFP_KERNEL)) {
195 i2o_pci_free(c); 193 i2o_pci_free(c);
@@ -235,49 +233,34 @@ static irqreturn_t i2o_pci_interrupt(int irq, void *dev_id, struct pt_regs *r)
235{ 233{
236 struct i2o_controller *c = dev_id; 234 struct i2o_controller *c = dev_id;
237 struct device *dev = &c->pdev->dev; 235 struct device *dev = &c->pdev->dev;
238 struct i2o_message *m; 236 u32 mv = readl(c->out_port);
239 u32 mv;
240 237
241 /* 238 /*
242 * Old 960 steppings had a bug in the I2O unit that caused 239 * Old 960 steppings had a bug in the I2O unit that caused
243 * the queue to appear empty when it wasn't. 240 * the queue to appear empty when it wasn't.
244 */ 241 */
245 mv = I2O_REPLY_READ32(c);
246 if (mv == I2O_QUEUE_EMPTY) { 242 if (mv == I2O_QUEUE_EMPTY) {
247 mv = I2O_REPLY_READ32(c); 243 mv = readl(c->out_port);
248 if (unlikely(mv == I2O_QUEUE_EMPTY)) { 244 if (unlikely(mv == I2O_QUEUE_EMPTY))
249 return IRQ_NONE; 245 return IRQ_NONE;
250 } else 246 else
251 pr_debug("%s: 960 bug detected\n", c->name); 247 pr_debug("%s: 960 bug detected\n", c->name);
252 } 248 }
253 249
254 while (mv != I2O_QUEUE_EMPTY) { 250 while (mv != I2O_QUEUE_EMPTY) {
255 /*
256 * Map the message from the page frame map to kernel virtual.
257 * Because bus_to_virt is deprecated, we have calculate the
258 * location by ourself!
259 */
260 m = i2o_msg_out_to_virt(c, mv);
261
262 /*
263 * Ensure this message is seen coherently but cachably by
264 * the processor
265 */
266 dma_sync_single_for_cpu(dev, mv, MSG_FRAME_SIZE * 4,
267 PCI_DMA_FROMDEVICE);
268
269 /* dispatch it */ 251 /* dispatch it */
270 if (i2o_driver_dispatch(c, mv, m)) 252 if (i2o_driver_dispatch(c, mv))
271 /* flush it if result != 0 */ 253 /* flush it if result != 0 */
272 i2o_flush_reply(c, mv); 254 i2o_flush_reply(c, mv);
273 255
274 /* 256 /*
275 * That 960 bug again... 257 * That 960 bug again...
276 */ 258 */
277 mv = I2O_REPLY_READ32(c); 259 mv = readl(c->out_port);
278 if (mv == I2O_QUEUE_EMPTY) 260 if (mv == I2O_QUEUE_EMPTY)
279 mv = I2O_REPLY_READ32(c); 261 mv = readl(c->out_port);
280 } 262 }
263
281 return IRQ_HANDLED; 264 return IRQ_HANDLED;
282} 265}
283 266
@@ -294,7 +277,9 @@ static int i2o_pci_irq_enable(struct i2o_controller *c)
294 struct pci_dev *pdev = c->pdev; 277 struct pci_dev *pdev = c->pdev;
295 int rc; 278 int rc;
296 279
297 I2O_IRQ_WRITE32(c, 0xffffffff); 280 wmb();
281 writel(0xffffffff, c->irq_mask);
282 wmb();
298 283
299 if (pdev->irq) { 284 if (pdev->irq) {
300 rc = request_irq(pdev->irq, i2o_pci_interrupt, SA_SHIRQ, 285 rc = request_irq(pdev->irq, i2o_pci_interrupt, SA_SHIRQ,
@@ -306,7 +291,8 @@ static int i2o_pci_irq_enable(struct i2o_controller *c)
306 } 291 }
307 } 292 }
308 293
309 I2O_IRQ_WRITE32(c, 0x00000000); 294 writel(0x00000000, c->irq_mask);
295 wmb();
310 296
311 printk(KERN_INFO "%s: Installed at IRQ %d\n", c->name, pdev->irq); 297 printk(KERN_INFO "%s: Installed at IRQ %d\n", c->name, pdev->irq);
312 298
@@ -321,7 +307,9 @@ static int i2o_pci_irq_enable(struct i2o_controller *c)
321 */ 307 */
322static void i2o_pci_irq_disable(struct i2o_controller *c) 308static void i2o_pci_irq_disable(struct i2o_controller *c)
323{ 309{
324 I2O_IRQ_WRITE32(c, 0xffffffff); 310 wmb();
311 writel(0xffffffff, c->irq_mask);
312 wmb();
325 313
326 if (c->pdev->irq > 0) 314 if (c->pdev->irq > 0)
327 free_irq(c->pdev->irq, c); 315 free_irq(c->pdev->irq, c);
@@ -379,7 +367,7 @@ static int __devinit i2o_pci_probe(struct pci_dev *pdev,
379 pci_name(pdev)); 367 pci_name(pdev));
380 368
381 c->pdev = pdev; 369 c->pdev = pdev;
382 c->device = pdev->dev; 370 c->device.parent = get_device(&pdev->dev);
383 371
384 /* Cards that fall apart if you hit them with large I/O loads... */ 372 /* Cards that fall apart if you hit them with large I/O loads... */
385 if (pdev->vendor == PCI_VENDOR_ID_NCR && pdev->device == 0x0630) { 373 if (pdev->vendor == PCI_VENDOR_ID_NCR && pdev->device == 0x0630) {
@@ -428,6 +416,8 @@ static int __devinit i2o_pci_probe(struct pci_dev *pdev,
428 if (i960) 416 if (i960)
429 pci_write_config_word(i960, 0x42, 0x03ff); 417 pci_write_config_word(i960, 0x42, 0x03ff);
430 418
419 get_device(&c->device);
420
431 return 0; 421 return 0;
432 422
433 uninstall: 423 uninstall:
@@ -438,6 +428,7 @@ static int __devinit i2o_pci_probe(struct pci_dev *pdev,
438 428
439 free_controller: 429 free_controller:
440 i2o_iop_free(c); 430 i2o_iop_free(c);
431 put_device(c->device.parent);
441 432
442 disable: 433 disable:
443 pci_disable_device(pdev); 434 pci_disable_device(pdev);
@@ -461,15 +452,17 @@ static void __devexit i2o_pci_remove(struct pci_dev *pdev)
461 i2o_pci_irq_disable(c); 452 i2o_pci_irq_disable(c);
462 i2o_pci_free(c); 453 i2o_pci_free(c);
463 454
455 pci_disable_device(pdev);
456
464 printk(KERN_INFO "%s: Controller removed.\n", c->name); 457 printk(KERN_INFO "%s: Controller removed.\n", c->name);
465 458
466 i2o_iop_free(c); 459 put_device(c->device.parent);
467 pci_disable_device(pdev); 460 put_device(&c->device);
468}; 461};
469 462
470/* PCI driver for I2O controller */ 463/* PCI driver for I2O controller */
471static struct pci_driver i2o_pci_driver = { 464static struct pci_driver i2o_pci_driver = {
472 .name = "I2O controller", 465 .name = "PCI_I2O",
473 .id_table = i2o_pci_ids, 466 .id_table = i2o_pci_ids,
474 .probe = i2o_pci_probe, 467 .probe = i2o_pci_probe,
475 .remove = __devexit_p(i2o_pci_remove), 468 .remove = __devexit_p(i2o_pci_remove),