Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] I2O: second code cleanup of sparse warnings and unneeded syncronization

Changes:
- Added header "core.h" for i2o_core.ko internal definitions
- More sparse fixes
- Changed display of TID's in sysfs attributes from XXX to 0xXXX
- Use the right functions for accessing I/O and normal memory
- Removed error handling of SCSI device errors and let the SCSI layer
take care of it
- Added new device / removed device handling to SCSI-OSM
- Make status access volatile
- Cleaned up activation of I2O controller
- Removed unnecessary wmb() and rmb() calls
- Use own struct i2o_io for I/O memory instead of struct i2o_dma

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>

authored by

Markus Lidel and committed by
Linus Torvalds
9e87545f b2aaee33

+276 -359
+55
drivers/message/i2o/core.h
··· 1 + /* 2 + * I2O core internal declarations 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 + /* Exec-OSM */ 17 + extern struct bus_type i2o_bus_type; 18 + 19 + extern struct i2o_driver i2o_exec_driver; 20 + extern int i2o_exec_lct_get(struct i2o_controller *); 21 + 22 + extern int __init i2o_exec_init(void); 23 + extern void __exit i2o_exec_exit(void); 24 + 25 + /* driver */ 26 + extern int i2o_driver_dispatch(struct i2o_controller *, u32); 27 + 28 + extern int __init i2o_driver_init(void); 29 + extern void __exit i2o_driver_exit(void); 30 + 31 + /* PCI */ 32 + extern int __init i2o_pci_init(void); 33 + extern void __exit i2o_pci_exit(void); 34 + 35 + /* device */ 36 + extern void i2o_device_remove(struct i2o_device *); 37 + extern int i2o_device_parse_lct(struct i2o_controller *); 38 + 39 + extern int i2o_device_init(void); 40 + extern void i2o_device_exit(void); 41 + 42 + /* IOP */ 43 + extern struct i2o_controller *i2o_iop_alloc(void); 44 + extern void i2o_iop_free(struct i2o_controller *); 45 + 46 + extern int i2o_iop_add(struct i2o_controller *); 47 + extern void i2o_iop_remove(struct i2o_controller *); 48 + 49 + /* control registers relative to c->base */ 50 + #define I2O_IRQ_STATUS 0x30 51 + #define I2O_IRQ_MASK 0x34 52 + #define I2O_IN_PORT 0x40 53 + #define I2O_OUT_PORT 0x44 54 + 55 + #define I2O_IRQ_OUTBOUND_POST 0x00000008
-3
drivers/message/i2o/debug.c
··· 4 4 #include <linux/pci.h> 5 5 #include <linux/i2o.h> 6 6 7 - extern struct i2o_driver **i2o_drivers; 8 - extern unsigned int i2o_max_drivers; 9 7 static void i2o_report_util_cmd(u8 cmd); 10 8 static void i2o_report_exec_cmd(u8 cmd); 11 9 static void i2o_report_fail_status(u8 req_status, u32 * msg); ··· 21 23 u8 cmd = (msg[1] >> 24) & 0xFF; 22 24 u8 req_status = (msg[4] >> 24) & 0xFF; 23 25 u16 detailed_status = msg[4] & 0xFFFF; 24 - //struct i2o_driver *h = i2o_drivers[msg[2] & (i2o_max_drivers-1)]; 25 26 26 27 if (cmd == I2O_CMD_UTIL_EVT_REGISTER) 27 28 return; // No status in this reply
+13 -9
drivers/message/i2o/device.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/i2o.h> 18 18 #include <linux/delay.h> 19 - 20 - /* Exec OSM functions */ 21 - extern struct bus_type i2o_bus_type; 19 + #include "core.h" 22 20 23 21 /** 24 22 * i2o_device_issue_claim - claim or release a device ··· 291 293 } 292 294 293 295 if (lct->table_size * 4 > c->dlct.len) { 294 - memcpy_fromio(c->lct, c->dlct.virt, c->dlct.len); 296 + memcpy(c->lct, c->dlct.virt, c->dlct.len); 295 297 up(&c->lct_lock); 296 298 return -EAGAIN; 297 299 } 298 300 299 - memcpy_fromio(c->lct, c->dlct.virt, lct->table_size * 4); 301 + memcpy(c->lct, c->dlct.virt, lct->table_size * 4); 300 302 301 303 lct = c->lct; 302 304 ··· 351 353 { 352 354 struct i2o_device *dev = to_i2o_device(cd->dev); 353 355 354 - sprintf(buf, "%03x\n", dev->lct_data.class_id); 356 + sprintf(buf, "0x%03x\n", dev->lct_data.class_id); 355 357 return strlen(buf) + 1; 356 358 }; 357 359 ··· 366 368 { 367 369 struct i2o_device *dev = to_i2o_device(cd->dev); 368 370 369 - sprintf(buf, "%03x\n", dev->lct_data.tid); 371 + sprintf(buf, "0x%03x\n", dev->lct_data.tid); 370 372 return strlen(buf) + 1; 371 373 }; 372 374 ··· 488 490 if (rc == -ETIMEDOUT) 489 491 return rc; 490 492 491 - memcpy_fromio(reslist, res.virt, res.len); 493 + memcpy(reslist, res.virt, res.len); 492 494 i2o_dma_free(dev, &res); 493 495 494 496 /* Query failed */ ··· 530 532 void *buf, int buflen) 531 533 { 532 534 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field }; 533 - u8 resblk[8 + buflen]; /* 8 bytes for header */ 535 + u8 *resblk; /* 8 bytes for header */ 534 536 int size; 535 537 536 538 if (field == -1) /* whole group */ 537 539 opblk[4] = -1; 538 540 541 + resblk = kmalloc(buflen + 8, GFP_KERNEL | GFP_ATOMIC); 542 + if (!resblk) 543 + return -ENOMEM; 544 + 539 545 size = i2o_parm_issue(i2o_dev, I2O_CMD_UTIL_PARAMS_GET, opblk, 540 546 sizeof(opblk), resblk, buflen + 8); 541 547 542 548 memcpy(buf, resblk + 8, buflen); /* cut off header */ 549 + 550 + kfree(resblk); 543 551 544 552 if (size > buflen) 545 553 return buflen;
+10 -14
drivers/message/i2o/driver.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/rwsem.h> 19 19 #include <linux/i2o.h> 20 + #include "core.h" 20 21 21 22 #define OSM_NAME "i2o" 22 23 23 24 /* max_drivers - Maximum I2O drivers (OSMs) which could be registered */ 24 - unsigned int i2o_max_drivers = I2O_MAX_DRIVERS; 25 + static unsigned int i2o_max_drivers = I2O_MAX_DRIVERS; 25 26 module_param_named(max_drivers, i2o_max_drivers, uint, 0); 26 27 MODULE_PARM_DESC(max_drivers, "maximum number of OSM's to support"); 27 28 ··· 180 179 int i2o_driver_dispatch(struct i2o_controller *c, u32 m) 181 180 { 182 181 struct i2o_driver *drv; 183 - struct i2o_message __iomem *msg = i2o_msg_out_to_virt(c, m); 184 - u32 context; 182 + struct i2o_message *msg = i2o_msg_out_to_virt(c, m); 183 + u32 context = le32_to_cpu(msg->u.s.icntxt); 185 184 unsigned long flags; 186 - 187 - if(unlikely(!msg)) 188 - return -EIO; 189 - 190 - context = readl(&msg->u.s.icntxt); 191 185 192 186 if (unlikely(context >= i2o_max_drivers)) { 193 187 osm_warn("%s: Spurious reply to unknown driver %d\n", c->name, ··· 200 204 return -EIO; 201 205 } 202 206 203 - if ((readl(&msg->u.head[1]) >> 24) == I2O_CMD_UTIL_EVT_REGISTER) { 207 + if ((le32_to_cpu(msg->u.head[1]) >> 24) == I2O_CMD_UTIL_EVT_REGISTER) { 204 208 struct i2o_device *dev, *tmp; 205 209 struct i2o_event *evt; 206 210 u16 size; 207 - u16 tid = readl(&msg->u.head[1]) & 0xfff; 211 + u16 tid = le32_to_cpu(msg->u.head[1]) & 0xfff; 208 212 209 213 osm_debug("event received from device %d\n", tid); 210 214 ··· 212 216 return -EIO; 213 217 214 218 /* cut of header from message size (in 32-bit words) */ 215 - size = (readl(&msg->u.head[0]) >> 16) - 5; 219 + size = (le32_to_cpu(msg->u.head[0]) >> 16) - 5; 216 220 217 221 evt = kmalloc(size * 4 + sizeof(*evt), GFP_ATOMIC | __GFP_ZERO); 218 222 if (!evt) 219 223 return -ENOMEM; 220 224 221 225 evt->size = size; 222 - evt->tcntxt = readl(&msg->u.s.tcntxt); 223 - evt->event_indicator = readl(&msg->body[0]); 224 - memcpy_fromio(&evt->tcntxt, &msg->u.s.tcntxt, size * 4); 226 + evt->tcntxt = le32_to_cpu(msg->u.s.tcntxt); 227 + evt->event_indicator = le32_to_cpu(msg->body[0]); 228 + memcpy(&evt->tcntxt, &msg->u.s.tcntxt, size * 4); 225 229 226 230 list_for_each_entry_safe(dev, tmp, &c->devices, list) 227 231 if (dev->lct_data.tid == tid) {
+12 -15
drivers/message/i2o/exec-osm.c
··· 30 30 #include <linux/module.h> 31 31 #include <linux/i2o.h> 32 32 #include <linux/delay.h> 33 + #include "core.h" 33 34 34 35 #define OSM_NAME "exec-osm" 35 36 36 37 struct i2o_driver i2o_exec_driver; 37 38 38 39 static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind); 39 - 40 - /* Module internal functions from other sources */ 41 - extern int i2o_device_parse_lct(struct i2o_controller *); 42 40 43 41 /* global wait list for POST WAIT */ 44 42 static LIST_HEAD(i2o_exec_wait_list); ··· 48 50 u32 tcntxt; /* transaction context from reply */ 49 51 int complete; /* 1 if reply received otherwise 0 */ 50 52 u32 m; /* message id */ 51 - struct i2o_message __iomem *msg; /* pointer to the reply message */ 53 + struct i2o_message *msg; /* pointer to the reply message */ 52 54 struct list_head list; /* node in global wait list */ 53 55 }; 54 56 ··· 160 162 barrier(); 161 163 162 164 if (wait->complete) { 163 - rc = readl(&wait->msg->body[0]) >> 24; 165 + rc = le32_to_cpu(wait->msg->body[0]) >> 24; 164 166 i2o_flush_reply(c, wait->m); 165 167 i2o_exec_wait_free(wait); 166 168 } else { ··· 200 202 * message must also be given back to the controller. 201 203 */ 202 204 static int i2o_msg_post_wait_complete(struct i2o_controller *c, u32 m, 203 - struct i2o_message __iomem *msg, 204 - u32 context) 205 + struct i2o_message *msg, u32 context) 205 206 { 206 207 struct i2o_exec_wait *wait, *tmp; 207 208 unsigned long flags; ··· 375 378 * code on failure and if the reply should be flushed. 376 379 */ 377 380 static int i2o_exec_reply(struct i2o_controller *c, u32 m, 378 - struct i2o_message __iomem *msg) 381 + struct i2o_message *msg) 379 382 { 380 383 u32 context; 381 384 382 - if (readl(&msg->u.head[0]) & MSG_FAIL) { 385 + if (le32_to_cpu(msg->u.head[0]) & MSG_FAIL) { 383 386 /* 384 387 * If Fail bit is set we must take the transaction context of 385 388 * the preserved message to find the right request again. ··· 387 390 struct i2o_message __iomem *pmsg; 388 391 u32 pm; 389 392 390 - pm = readl(&msg->body[3]); 393 + pm = le32_to_cpu(msg->body[3]); 391 394 392 395 pmsg = i2o_msg_in_to_virt(c, pm); 393 396 ··· 398 401 /* Release the preserved msg */ 399 402 i2o_msg_nop(c, pm); 400 403 } else 401 - context = readl(&msg->u.s.tcntxt); 404 + context = le32_to_cpu(msg->u.s.tcntxt); 402 405 403 406 if (context & 0x80000000) 404 407 return i2o_msg_post_wait_complete(c, m, msg, context); 405 408 406 - if ((readl(&msg->u.head[1]) >> 24) == I2O_CMD_LCT_NOTIFY) { 409 + if ((le32_to_cpu(msg->u.head[1]) >> 24) == I2O_CMD_LCT_NOTIFY) { 407 410 struct work_struct *work; 408 411 409 412 pr_debug("%s: LCT notify received\n", c->name); ··· 439 442 */ 440 443 static void i2o_exec_event(struct i2o_event *evt) 441 444 { 442 - if(likely(evt->i2o_dev)) 443 - osm_info("Event received from device: %d\n", 444 - evt->i2o_dev->lct_data.tid); 445 + if (likely(evt->i2o_dev)) 446 + osm_debug("Event received from device: %d\n", 447 + evt->i2o_dev->lct_data.tid); 445 448 kfree(evt); 446 449 }; 447 450
+2 -2
drivers/message/i2o/i2o_block.c
··· 62 62 #include "i2o_block.h" 63 63 64 64 #define OSM_NAME "block-osm" 65 - #define OSM_VERSION "$Rev$" 65 + #define OSM_VERSION "1.287" 66 66 #define OSM_DESCRIPTION "I2O Block Device OSM" 67 67 68 68 static struct i2o_driver i2o_block_driver; ··· 537 537 538 538 static void i2o_block_event(struct i2o_event *evt) 539 539 { 540 - osm_info("event received\n"); 540 + osm_debug("event received\n"); 541 541 kfree(evt); 542 542 }; 543 543
+5 -3
drivers/message/i2o/i2o_config.c
··· 36 36 37 37 #include <asm/uaccess.h> 38 38 39 + #define SG_TABLESIZE 30 40 + 39 41 extern int i2o_parm_issue(struct i2o_device *, int, void *, int, void *, int); 40 42 41 43 static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd, ··· 665 663 goto sg_list_cleanup; 666 664 667 665 if (sg_offset) { 668 - u32 msg[MSG_FRAME_SIZE]; 666 + u32 msg[I2O_OUTBOUND_MSG_FRAME_SIZE]; 669 667 /* Copy back the Scatter Gather buffers back to user space */ 670 668 u32 j; 671 669 // TODO 64bit fix ··· 673 671 int sg_size; 674 672 675 673 // re-acquire the original message to handle correctly the sg copy operation 676 - memset(&msg, 0, MSG_FRAME_SIZE * 4); 674 + memset(&msg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4); 677 675 // get user msg size in u32s 678 676 if (get_user(size, &user_msg[0])) { 679 677 rcode = -EFAULT; ··· 904 902 int sg_size; 905 903 906 904 // re-acquire the original message to handle correctly the sg copy operation 907 - memset(&msg, 0, MSG_FRAME_SIZE * 4); 905 + memset(&msg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4); 908 906 // get user msg size in u32s 909 907 if (get_user(size, &user_msg[0])) { 910 908 rcode = -EFAULT;
+66 -138
drivers/message/i2o/i2o_scsi.c
··· 40 40 * Fix the resource management problems. 41 41 */ 42 42 43 - #define DEBUG 1 44 43 #include <linux/module.h> 45 44 #include <linux/kernel.h> 46 45 #include <linux/types.h> ··· 337 338 struct i2o_message *msg) 338 339 { 339 340 struct scsi_cmnd *cmd; 341 + u32 error; 340 342 struct device *dev; 341 - u8 as, ds, st; 342 343 343 344 cmd = i2o_cntxt_list_get(c, le32_to_cpu(msg->u.s.tcntxt)); 344 - 345 - if (msg->u.head[0] & (1 << 13)) { 346 - struct i2o_message __iomem *pmsg; /* preserved message */ 347 - u32 pm; 348 - int err = DID_ERROR; 349 - 350 - pm = le32_to_cpu(msg->body[3]); 351 - 352 - pmsg = i2o_msg_in_to_virt(c, pm); 353 - 354 - osm_err("IOP fail.\n"); 355 - osm_err("From %d To %d Cmd %d.\n", 356 - (msg->u.head[1] >> 12) & 0xFFF, 357 - msg->u.head[1] & 0xFFF, msg->u.head[1] >> 24); 358 - osm_err("Failure Code %d.\n", msg->body[0] >> 24); 359 - if (msg->body[0] & (1 << 16)) 360 - osm_err("Format error.\n"); 361 - if (msg->body[0] & (1 << 17)) 362 - osm_err("Path error.\n"); 363 - if (msg->body[0] & (1 << 18)) 364 - osm_err("Path State.\n"); 365 - if (msg->body[0] & (1 << 18)) 366 - { 367 - osm_err("Congestion.\n"); 368 - err = DID_BUS_BUSY; 369 - } 370 - 371 - osm_debug("Failing message is %p.\n", pmsg); 372 - 373 - cmd = i2o_cntxt_list_get(c, readl(&pmsg->u.s.tcntxt)); 374 - if (!cmd) 375 - return 1; 376 - 377 - cmd->result = err << 16; 378 - cmd->scsi_done(cmd); 379 - 380 - /* Now flush the message by making it a NOP */ 381 - i2o_msg_nop(c, pm); 382 - 383 - return 1; 345 + if (unlikely(!cmd)) { 346 + osm_err("NULL reply received!\n"); 347 + return -1; 384 348 } 385 349 386 350 /* 387 351 * Low byte is device status, next is adapter status, 388 352 * (then one byte reserved), then request status. 389 353 */ 390 - ds = (u8) le32_to_cpu(msg->body[0]); 391 - as = (u8) (le32_to_cpu(msg->body[0]) >> 8); 392 - st = (u8) (le32_to_cpu(msg->body[0]) >> 24); 393 - 394 - /* 395 - * Is this a control request coming back - eg an abort ? 396 - */ 397 - 398 - if (!cmd) { 399 - if (st) 400 - osm_warn("SCSI abort: %08X", le32_to_cpu(msg->body[0])); 401 - osm_info("SCSI abort completed.\n"); 402 - return -EFAULT; 403 - } 354 + error = le32_to_cpu(msg->body[0]); 404 355 405 356 osm_debug("Completed %ld\n", cmd->serial_number); 406 357 407 - if (st) { 408 - u32 count, error; 409 - /* An error has occurred */ 358 + cmd->result = error & 0xff; 359 + /* 360 + * if DeviceStatus is not SCSI_SUCCESS copy over the sense data and let 361 + * the SCSI layer handle the error 362 + */ 363 + if (cmd->result) 364 + memcpy(cmd->sense_buffer, &msg->body[3], 365 + min(sizeof(cmd->sense_buffer), (size_t) 40)); 410 366 411 - switch (st) { 412 - case 0x06: 413 - count = le32_to_cpu(msg->body[1]); 414 - if (count < cmd->underflow) { 415 - int i; 416 - 417 - osm_err("SCSI underflow 0x%08X 0x%08X\n", count, 418 - cmd->underflow); 419 - osm_debug("Cmd: "); 420 - for (i = 0; i < 15; i++) 421 - pr_debug("%02X ", cmd->cmnd[i]); 422 - pr_debug(".\n"); 423 - cmd->result = (DID_ERROR << 16); 424 - } 425 - break; 426 - 427 - default: 428 - error = le32_to_cpu(msg->body[0]); 429 - 430 - osm_err("SCSI error %08x\n", error); 431 - 432 - if ((error & 0xff) == 0x02 /*CHECK_CONDITION */ ) { 433 - int i; 434 - u32 len = sizeof(cmd->sense_buffer); 435 - len = (len > 40) ? 40 : len; 436 - // Copy over the sense data 437 - memcpy(cmd->sense_buffer, (void *)&msg->body[3], 438 - len); 439 - for (i = 0; i <= len; i++) 440 - osm_info("%02x\n", 441 - cmd->sense_buffer[i]); 442 - if (cmd->sense_buffer[0] == 0x70 443 - && cmd->sense_buffer[2] == DATA_PROTECT) { 444 - /* This is to handle an array failed */ 445 - cmd->result = (DID_TIME_OUT << 16); 446 - printk(KERN_WARNING "%s: SCSI Data " 447 - "Protect-Device (%d,%d,%d) " 448 - "hba_status=0x%x, dev_status=" 449 - "0x%x, cmd=0x%x\n", c->name, 450 - (u32) cmd->device->channel, 451 - (u32) cmd->device->id, 452 - (u32) cmd->device->lun, 453 - (error >> 8) & 0xff, 454 - error & 0xff, cmd->cmnd[0]); 455 - } else 456 - cmd->result = (DID_ERROR << 16); 457 - 458 - break; 459 - } 460 - 461 - switch (as) { 462 - case 0x0E: 463 - /* SCSI Reset */ 464 - cmd->result = DID_RESET << 16; 465 - break; 466 - 467 - case 0x0F: 468 - cmd->result = DID_PARITY << 16; 469 - break; 470 - 471 - default: 472 - cmd->result = DID_ERROR << 16; 473 - break; 474 - } 475 - 476 - break; 477 - } 478 - 479 - cmd->scsi_done(cmd); 480 - return 1; 481 - } 482 - 483 - cmd->result = DID_OK << 16 | ds; 367 + /* only output error code if AdapterStatus is not HBA_SUCCESS */ 368 + if ((error >> 8) & 0xff) 369 + osm_err("SCSI error %08x\n", error); 484 370 485 371 dev = &c->pdev->dev; 486 372 if (cmd->use_sg) 487 - dma_unmap_sg(dev, (struct scatterlist *)cmd->buffer, 488 - cmd->use_sg, cmd->sc_data_direction); 489 - else if (cmd->request_bufflen) 490 - dma_unmap_single(dev, (dma_addr_t) ((long)cmd->SCp.ptr), 491 - cmd->request_bufflen, cmd->sc_data_direction); 373 + dma_unmap_sg(dev, cmd->request_buffer, cmd->use_sg, 374 + cmd->sc_data_direction); 375 + else if (cmd->SCp.dma_handle) 376 + dma_unmap_single(dev, cmd->SCp.dma_handle, cmd->request_bufflen, 377 + cmd->sc_data_direction); 492 378 493 379 cmd->scsi_done(cmd); 494 380 495 381 return 1; 382 + }; 383 + 384 + /** 385 + * i2o_scsi_notify_device_add - Retrieve notifications of added devices 386 + * @i2o_dev: the I2O device which was added 387 + * 388 + * If a I2O device is added we catch the notification, because I2O classes 389 + * other then SCSI peripheral will not be received through 390 + * i2o_scsi_probe(). 391 + */ 392 + static void i2o_scsi_notify_device_add(struct i2o_device *i2o_dev) 393 + { 394 + switch (i2o_dev->lct_data.class_id) { 395 + case I2O_CLASS_EXECUTIVE: 396 + case I2O_CLASS_RANDOM_BLOCK_STORAGE: 397 + i2o_scsi_probe(&i2o_dev->device); 398 + break; 399 + 400 + default: 401 + break; 402 + } 403 + }; 404 + 405 + /** 406 + * i2o_scsi_notify_device_remove - Retrieve notifications of removed 407 + * devices 408 + * @i2o_dev: the I2O device which was removed 409 + * 410 + * If a I2O device is removed, we catch the notification to remove the 411 + * corresponding SCSI device. 412 + */ 413 + static void i2o_scsi_notify_device_remove(struct i2o_device *i2o_dev) 414 + { 415 + switch (i2o_dev->lct_data.class_id) { 416 + case I2O_CLASS_EXECUTIVE: 417 + case I2O_CLASS_RANDOM_BLOCK_STORAGE: 418 + i2o_scsi_remove(&i2o_dev->device); 419 + break; 420 + 421 + default: 422 + break; 423 + } 496 424 }; 497 425 498 426 /** ··· 480 554 .name = OSM_NAME, 481 555 .reply = i2o_scsi_reply, 482 556 .classes = i2o_scsi_class_id, 557 + .notify_device_add = i2o_scsi_notify_device_add, 558 + .notify_device_remove = i2o_scsi_notify_device_remove, 483 559 .notify_controller_add = i2o_scsi_notify_controller_add, 484 560 .notify_controller_remove = i2o_scsi_notify_controller_remove, 485 561 .driver = { ··· 640 712 */ 641 713 642 714 /* Attach tags to the devices */ 643 - /* 715 + /* FIXME: implement 644 716 if(SCpnt->device->tagged_supported) { 645 717 if(SCpnt->tag == HEAD_OF_QUEUE_TAG) 646 718 scsi_flags |= 0x01000000;
+68 -60
drivers/message/i2o/iop.c
··· 28 28 #include <linux/module.h> 29 29 #include <linux/i2o.h> 30 30 #include <linux/delay.h> 31 + #include "core.h" 31 32 32 - #define OSM_VERSION "$Rev$" 33 + #define OSM_NAME "i2o" 34 + #define OSM_VERSION "1.288" 33 35 #define OSM_DESCRIPTION "I2O subsystem" 34 36 35 37 /* global I2O controller list */ ··· 44 42 static struct i2o_dma i2o_systab; 45 43 46 44 static int i2o_hrt_get(struct i2o_controller *c); 47 - 48 - /* Module internal functions from other sources */ 49 - extern struct i2o_driver i2o_exec_driver; 50 - extern int i2o_exec_lct_get(struct i2o_controller *); 51 - extern void i2o_device_remove(struct i2o_device *); 52 - 53 - extern int __init i2o_driver_init(void); 54 - extern void __exit i2o_driver_exit(void); 55 - extern int __init i2o_exec_init(void); 56 - extern void __exit i2o_exec_exit(void); 57 - extern int __init i2o_pci_init(void); 58 - extern void __exit i2o_pci_exit(void); 59 - extern int i2o_device_init(void); 60 - extern void i2o_device_exit(void); 61 45 62 46 /** 63 47 * i2o_msg_nop - Returns a message which is not used ··· 80 92 * address from the read port (see the i2o spec). If no message is 81 93 * available returns I2O_QUEUE_EMPTY and msg is leaved untouched. 82 94 */ 83 - u32 i2o_msg_get_wait(struct i2o_controller *c, struct i2o_message __iomem **msg, 84 - int wait) 95 + u32 i2o_msg_get_wait(struct i2o_controller *c, 96 + struct i2o_message __iomem ** msg, int wait) 85 97 { 86 98 unsigned long timeout = jiffies + wait * HZ; 87 99 u32 m; 88 100 89 101 while ((m = i2o_msg_get(c, msg)) == I2O_QUEUE_EMPTY) { 90 102 if (time_after(jiffies, timeout)) { 91 - pr_debug("%s: Timeout waiting for message frame.\n", 92 - c->name); 103 + osm_debug("%s: Timeout waiting for message frame.\n", 104 + c->name); 93 105 return I2O_QUEUE_EMPTY; 94 106 } 95 107 set_current_state(TASK_UNINTERRUPTIBLE); ··· 454 466 */ 455 467 static int i2o_iop_init_outbound_queue(struct i2o_controller *c) 456 468 { 457 - u8 *status = c->status.virt; 469 + volatile u8 *status = c->status.virt; 458 470 u32 m; 459 471 struct i2o_message __iomem *msg; 460 472 ulong timeout; ··· 462 474 463 475 osm_debug("%s: Initializing Outbound Queue...\n", c->name); 464 476 465 - memset(status, 0, 4); 477 + memset(c->status.virt, 0, 4); 466 478 467 479 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); 468 480 if (m == I2O_QUEUE_EMPTY) 469 481 return -ETIMEDOUT; 470 482 471 - writel(EIGHT_WORD_MSG_SIZE | TRL_OFFSET_6, &msg->u.head[0]); 483 + writel(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6, &msg->u.head[0]); 472 484 writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID, 473 485 &msg->u.head[1]); 474 486 writel(i2o_exec_driver.context, &msg->u.s.icntxt); 475 - writel(0x0106, &msg->u.s.tcntxt); /* FIXME: why 0x0106, maybe in 476 - Spec? */ 487 + writel(0x00000000, &msg->u.s.tcntxt); 477 488 writel(PAGE_SIZE, &msg->body[0]); 478 489 /* Outbound msg frame size in words and Initcode */ 479 - writel(MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); 490 + writel(I2O_OUTBOUND_MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); 480 491 writel(0xd0000004, &msg->body[2]); 481 492 writel(i2o_dma_low(c->status.phys), &msg->body[3]); 482 493 writel(i2o_dma_high(c->status.phys), &msg->body[4]); ··· 490 503 } 491 504 set_current_state(TASK_UNINTERRUPTIBLE); 492 505 schedule_timeout(1); 493 - 494 - rmb(); 495 506 } 496 507 497 508 m = c->out_queue.phys; 498 509 499 510 /* Post frames */ 500 - for (i = 0; i < NMBR_MSG_FRAMES; i++) { 511 + for (i = 0; i < I2O_MAX_OUTBOUND_MSG_FRAMES; i++) { 501 512 i2o_flush_reply(c, m); 502 513 udelay(1); /* Promise */ 503 - m += MSG_FRAME_SIZE * 4; 514 + m += I2O_OUTBOUND_MSG_FRAME_SIZE * sizeof(u32); 504 515 } 505 516 506 517 return 0; ··· 515 530 */ 516 531 static int i2o_iop_reset(struct i2o_controller *c) 517 532 { 518 - u8 *status = c->status.virt; 533 + volatile u8 *status = c->status.virt; 519 534 struct i2o_message __iomem *msg; 520 535 u32 m; 521 536 unsigned long timeout; 522 537 i2o_status_block *sb = c->status_block.virt; 523 538 int rc = 0; 524 539 525 - pr_debug("%s: Resetting controller\n", c->name); 540 + osm_debug("%s: Resetting controller\n", c->name); 526 541 527 542 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); 528 543 if (m == I2O_QUEUE_EMPTY) 529 544 return -ETIMEDOUT; 530 545 531 - memset(status, 0, 8); 546 + memset(c->status_block.virt, 0, 8); 532 547 533 548 /* Quiesce all IOPs first */ 534 549 i2o_iop_quiesce_all(); ··· 553 568 554 569 set_current_state(TASK_UNINTERRUPTIBLE); 555 570 schedule_timeout(1); 556 - 557 - rmb(); 558 571 } 559 572 560 573 switch (*status) { ··· 967 984 { 968 985 struct i2o_message __iomem *msg; 969 986 u32 m; 970 - u8 *status_block; 987 + volatile u8 *status_block; 971 988 unsigned long timeout; 972 989 973 990 status_block = (u8 *) c->status_block.virt; 974 - memset(status_block, 0, sizeof(i2o_status_block)); 991 + memset(c->status_block.virt, 0, sizeof(i2o_status_block)); 975 992 976 993 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET); 977 994 if (m == I2O_QUEUE_EMPTY) ··· 1000 1017 1001 1018 set_current_state(TASK_UNINTERRUPTIBLE); 1002 1019 schedule_timeout(1); 1003 - 1004 - rmb(); 1005 1020 } 1006 1021 1007 1022 #ifdef DEBUG ··· 1088 1107 i2o_iop_free(c); 1089 1108 }; 1090 1109 1110 + /* I2O controller class */ 1111 + static struct class i2o_controller_class = { 1112 + .name = "i2o_controller", 1113 + }; 1114 + 1091 1115 /** 1092 1116 * i2o_iop_alloc - Allocate and initialize a i2o_controller struct 1093 1117 * ··· 1122 1136 sprintf(c->name, "iop%d", c->unit); 1123 1137 1124 1138 device_initialize(&c->device); 1139 + class_device_initialize(&c->classdev); 1140 + 1125 1141 c->device.release = &i2o_iop_release; 1142 + c->classdev.class = &i2o_controller_class; 1143 + c->classdev.dev = &c->device; 1144 + 1126 1145 snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit); 1146 + snprintf(c->classdev.class_id, BUS_ID_SIZE, "iop%d", c->unit); 1127 1147 1128 1148 #if BITS_PER_LONG == 64 1129 1149 spin_lock_init(&c->context_list_lock); ··· 1153 1161 { 1154 1162 int rc; 1155 1163 1156 - if((rc = device_add(&c->device))) { 1157 - printk(KERN_ERR "%s: could not register controller\n", c->name); 1164 + if ((rc = device_add(&c->device))) { 1165 + osm_err("%s: could not add controller\n", c->name); 1158 1166 goto iop_reset; 1159 1167 } 1160 1168 1161 - printk(KERN_INFO "%s: Activating I2O controller...\n", c->name); 1162 - printk(KERN_INFO "%s: This may take a few minutes if there are many " 1163 - "devices\n", c->name); 1169 + if ((rc = class_device_add(&c->classdev))) { 1170 + osm_err("%s: could not add controller class\n", c->name); 1171 + goto device_del; 1172 + } 1173 + 1174 + osm_info("%s: Activating I2O controller...\n", c->name); 1175 + osm_info("%s: This may take a few minutes if there are many devices\n", 1176 + c->name); 1164 1177 1165 1178 if ((rc = i2o_iop_activate(c))) { 1166 - printk(KERN_ERR "%s: could not activate controller\n", 1167 - c->name); 1168 - goto iop_reset; 1179 + osm_err("%s: could not activate controller\n", c->name); 1180 + goto class_del; 1169 1181 } 1170 1182 1171 - pr_debug("%s: building sys table...\n", c->name); 1183 + osm_debug("%s: building sys table...\n", c->name); 1172 1184 1173 1185 if ((rc = i2o_systab_build())) 1174 - goto iop_reset; 1186 + goto class_del; 1175 1187 1176 - pr_debug("%s: online controller...\n", c->name); 1188 + osm_debug("%s: online controller...\n", c->name); 1177 1189 1178 1190 if ((rc = i2o_iop_online(c))) 1179 - goto iop_reset; 1191 + goto class_del; 1180 1192 1181 - pr_debug("%s: getting LCT...\n", c->name); 1193 + osm_debug("%s: getting LCT...\n", c->name); 1182 1194 1183 1195 if ((rc = i2o_exec_lct_get(c))) 1184 - goto iop_reset; 1196 + goto class_del; 1185 1197 1186 1198 list_add(&c->list, &i2o_controllers); 1187 1199 1188 1200 i2o_driver_notify_controller_add_all(c); 1189 1201 1190 - printk(KERN_INFO "%s: Controller added\n", c->name); 1202 + osm_info("%s: Controller added\n", c->name); 1191 1203 1192 1204 return 0; 1193 1205 1194 - iop_reset: 1206 + class_del: 1207 + class_device_del(&c->classdev); 1208 + 1209 + device_del: 1210 + device_del(&c->device); 1211 + 1212 + iop_reset: 1195 1213 i2o_iop_reset(c); 1196 1214 1197 1215 return rc; ··· 1262 1260 if (rc) 1263 1261 goto exit; 1264 1262 1265 - rc = i2o_driver_init(); 1266 - if (rc) 1263 + if ((rc = class_register(&i2o_controller_class))) { 1264 + osm_err("can't register class i2o_controller\n"); 1267 1265 goto device_exit; 1266 + } 1268 1267 1269 - rc = i2o_exec_init(); 1270 - if (rc) 1268 + if ((rc = i2o_driver_init())) 1269 + goto class_exit; 1270 + 1271 + if ((rc = i2o_exec_init())) 1271 1272 goto driver_exit; 1272 1273 1273 - rc = i2o_pci_init(); 1274 - if (rc < 0) 1274 + if ((rc = i2o_pci_init())) 1275 1275 goto exec_exit; 1276 1276 1277 1277 return 0; ··· 1283 1279 1284 1280 driver_exit: 1285 1281 i2o_driver_exit(); 1282 + 1283 + class_exit: 1284 + class_unregister(&i2o_controller_class); 1286 1285 1287 1286 device_exit: 1288 1287 i2o_device_exit(); ··· 1304 1297 i2o_pci_exit(); 1305 1298 i2o_exec_exit(); 1306 1299 i2o_driver_exit(); 1300 + class_unregister(&i2o_controller_class); 1307 1301 i2o_device_exit(); 1308 1302 }; 1309 1303
+3 -18
drivers/message/i2o/pci.c
··· 30 30 #include <linux/pci.h> 31 31 #include <linux/interrupt.h> 32 32 #include <linux/i2o.h> 33 - 34 - /* Module internal functions from other sources */ 35 - extern struct i2o_controller *i2o_iop_alloc(void); 36 - extern void i2o_iop_free(struct i2o_controller *); 37 - 38 - extern int i2o_iop_add(struct i2o_controller *); 39 - extern void i2o_iop_remove(struct i2o_controller *); 40 - 41 - extern int i2o_driver_dispatch(struct i2o_controller *, u32); 33 + #include "core.h" 42 34 43 35 /* PCI device id table for all I2O controllers */ 44 36 static struct pci_device_id __devinitdata i2o_pci_ids[] = { ··· 240 248 struct pci_dev *pdev = c->pdev; 241 249 int rc; 242 250 243 - wmb(); 244 251 writel(0xffffffff, c->irq_mask); 245 - wmb(); 246 252 247 253 if (pdev->irq) { 248 254 rc = request_irq(pdev->irq, i2o_pci_interrupt, SA_SHIRQ, ··· 253 263 } 254 264 255 265 writel(0x00000000, c->irq_mask); 256 - wmb(); 257 266 258 267 printk(KERN_INFO "%s: Installed at IRQ %d\n", c->name, pdev->irq); 259 268 ··· 267 278 */ 268 279 static void i2o_pci_irq_disable(struct i2o_controller *c) 269 280 { 270 - wmb(); 271 281 writel(0xffffffff, c->irq_mask); 272 - wmb(); 273 282 274 283 if (c->pdev->irq > 0) 275 284 free_irq(c->pdev->irq, c); ··· 393 406 if ((rc = i2o_iop_add(c))) 394 407 goto uninstall; 395 408 409 + get_device(&c->device); 410 + 396 411 if (i960) 397 412 pci_write_config_word(i960, 0x42, 0x03ff); 398 - 399 - get_device(&c->device); 400 413 401 414 return 0; 402 415 ··· 465 478 { 466 479 pci_unregister_driver(&i2o_pci_driver); 467 480 }; 468 - 469 - EXPORT_SYMBOL(i2o_dma_realloc); 470 481 MODULE_DEVICE_TABLE(pci, i2o_pci_ids);
+11 -12
include/linux/i2o-dev.h
··· 33 33 #endif /* __KERNEL__ */ 34 34 35 35 /* 36 - * Software module types 37 - */ 38 - #define I2O_SOFTWARE_MODULE_IRTOS 0x11 39 - #define I2O_SOFTWARE_MODULE_IOP_PRIVATE 0x22 40 - #define I2O_SOFTWARE_MODULE_IOP_CONFIG 0x23 41 - 42 - /* 43 - * Vendors 44 - */ 45 - #define I2O_VENDOR_DPT 0x001b 46 - 47 - /* 48 36 * I2O Control IOCTLs and structures 49 37 */ 50 38 #define I2O_MAGIC_NUMBER 'i' ··· 402 414 #define ADAPTER_STATE_FAILED 0x10 403 415 #define ADAPTER_STATE_FAULTED 0x11 404 416 417 + /* 418 + * Software module types 419 + */ 420 + #define I2O_SOFTWARE_MODULE_IRTOS 0x11 421 + #define I2O_SOFTWARE_MODULE_IOP_PRIVATE 0x22 422 + #define I2O_SOFTWARE_MODULE_IOP_CONFIG 0x23 423 + 424 + /* 425 + * Vendors 426 + */ 427 + #define I2O_VENDOR_DPT 0x001b 405 428 406 429 /* 407 430 * DPT / Adaptec specific values for i2o_sg_io_hdr flags.
+31 -85
include/linux/i2o.h
··· 119 119 }; 120 120 121 121 /* 122 - * Contains all information which are necessary for DMA operations 122 + * Contains DMA mapped address information 123 123 */ 124 124 struct i2o_dma { 125 125 void *virt; 126 126 dma_addr_t phys; 127 - u32 len; 127 + size_t len; 128 + }; 129 + 130 + /* 131 + * Contains IO mapped address information 132 + */ 133 + struct i2o_io { 134 + void __iomem *virt; 135 + unsigned long phys; 136 + unsigned long len; 128 137 }; 129 138 130 139 /* ··· 182 173 struct semaphore lct_lock; /* Lock for LCT updates */ 183 174 struct i2o_dma status_block; /* IOP status block */ 184 175 185 - struct i2o_dma base; /* controller messaging unit */ 186 - struct i2o_dma in_queue; /* inbound message queue Host->IOP */ 176 + struct i2o_io base; /* controller messaging unit */ 177 + struct i2o_io in_queue; /* inbound message queue Host->IOP */ 187 178 struct i2o_dma out_queue; /* outbound message queue IOP->Host */ 188 179 189 180 unsigned int battery:1; /* Has a battery backup */ ··· 194 185 struct resource mem_resource; /* Mem resource allocated to the IOP */ 195 186 196 187 struct device device; 188 + struct class_device classdev; /* I2O controller class */ 197 189 struct i2o_device *exec; /* Executive */ 198 190 #if BITS_PER_LONG == 64 199 191 spinlock_t context_list_lock; /* lock for context_list */ ··· 245 235 extern struct list_head i2o_controllers; 246 236 247 237 /* Message functions */ 248 - static inline u32 i2o_msg_get(struct i2o_controller *, struct i2o_message __iomem **); 249 - extern u32 i2o_msg_get_wait(struct i2o_controller *, struct i2o_message __iomem **, 250 - int); 238 + static inline u32 i2o_msg_get(struct i2o_controller *, 239 + struct i2o_message __iomem **); 240 + extern u32 i2o_msg_get_wait(struct i2o_controller *, 241 + struct i2o_message __iomem **, int); 251 242 static inline void i2o_msg_post(struct i2o_controller *, u32); 252 243 static inline int i2o_msg_post_wait(struct i2o_controller *, u32, 253 244 unsigned long); ··· 649 638 * available returns I2O_QUEUE_EMPTY and msg is leaved untouched. 650 639 */ 651 640 static inline u32 i2o_msg_get(struct i2o_controller *c, 652 - struct i2o_message __iomem **msg) 641 + struct i2o_message __iomem ** msg) 653 642 { 654 643 u32 m = readl(c->in_port); 655 644 656 - if (m != I2O_QUEUE_EMPTY) { 645 + if (m != I2O_QUEUE_EMPTY) 657 646 *msg = c->in_queue.virt + m; 658 - rmb(); 659 - } 660 647 661 648 return m; 662 649 }; ··· 668 659 */ 669 660 static inline void i2o_msg_post(struct i2o_controller *c, u32 m) 670 661 { 671 - wmb(); 672 662 writel(m, c->in_port); 673 663 }; 674 664 ··· 714 706 * work for sender side messages as they are ioremap objects 715 707 * provided by the I2O controller. 716 708 */ 717 - static inline struct i2o_message __iomem *i2o_msg_out_to_virt(struct 718 - i2o_controller *c, 719 - u32 m) 709 + static inline struct i2o_message *i2o_msg_out_to_virt(struct i2o_controller *c, 710 + u32 m) 720 711 { 721 - if (unlikely 722 - (m < c->out_queue.phys 723 - || m >= c->out_queue.phys + c->out_queue.len)) 724 - return NULL; 712 + BUG_ON(m < c->out_queue.phys 713 + || m >= c->out_queue.phys + c->out_queue.len); 725 714 726 715 return c->out_queue.virt + (m - c->out_queue.phys); 727 716 }; ··· 734 729 * work for receive side messages as they are kmalloc objects 735 730 * in a different pool. 736 731 */ 737 - static inline struct i2o_message __iomem *i2o_msg_in_to_virt(struct i2o_controller *c, 738 - u32 m) 732 + static inline struct i2o_message __iomem *i2o_msg_in_to_virt(struct 733 + i2o_controller *c, 734 + u32 m) 739 735 { 740 736 return c->in_queue.virt + m; 741 - }; 742 - 743 - /** 744 - * i2o_dma_alloc - Allocate DMA memory 745 - * @dev: struct device pointer to the PCI device of the I2O controller 746 - * @addr: i2o_dma struct which should get the DMA buffer 747 - * @len: length of the new DMA memory 748 - * @gfp_mask: GFP mask 749 - * 750 - * Allocate a coherent DMA memory and write the pointers into addr. 751 - * 752 - * Returns 0 on success or -ENOMEM on failure. 753 - */ 754 - static inline int i2o_dma_alloc(struct device *dev, struct i2o_dma *addr, 755 - size_t len, unsigned int gfp_mask) 756 - { 757 - struct pci_dev *pdev = to_pci_dev(dev); 758 - int dma_64 = 0; 759 - 760 - if ((sizeof(dma_addr_t) > 4) && (pdev->dma_mask == DMA_64BIT_MASK)) { 761 - dma_64 = 1; 762 - if(pci_set_dma_mask(pdev, DMA_32BIT_MASK)) 763 - return -ENOMEM; 764 - } 765 - 766 - addr->virt = dma_alloc_coherent(dev, len, &addr->phys, gfp_mask); 767 - 768 - if ((sizeof(dma_addr_t) > 4) && dma_64) 769 - if(pci_set_dma_mask(pdev, DMA_64BIT_MASK)) 770 - printk(KERN_WARNING "i2o: unable to set 64-bit DMA"); 771 - 772 - if (!addr->virt) 773 - return -ENOMEM; 774 - 775 - memset(addr->virt, 0, len); 776 - addr->len = len; 777 - 778 - return 0; 779 - }; 780 - 781 - /** 782 - * i2o_dma_free - Free DMA memory 783 - * @dev: struct device pointer to the PCI device of the I2O controller 784 - * @addr: i2o_dma struct which contains the DMA buffer 785 - * 786 - * Free a coherent DMA memory and set virtual address of addr to NULL. 787 - */ 788 - static inline void i2o_dma_free(struct device *dev, struct i2o_dma *addr) 789 - { 790 - if (addr->virt) { 791 - if (addr->phys) 792 - dma_free_coherent(dev, addr->len, addr->virt, 793 - addr->phys); 794 - else 795 - kfree(addr->virt); 796 - addr->virt = NULL; 797 - } 798 737 }; 799 738 800 739 /* ··· 1090 1141 #define ELEVEN_WORD_MSG_SIZE 0x000B0000 1091 1142 #define I2O_MESSAGE_SIZE(x) ((x)<<16) 1092 1143 1093 - /* Special TID Assignments */ 1094 - 1144 + /* special TID assignments */ 1095 1145 #define ADAPTER_TID 0 1096 1146 #define HOST_TID 1 1097 1147 1098 - #define MSG_FRAME_SIZE 128 /* i2o_scsi assumes >= 32 */ 1099 - #define SG_TABLESIZE 30 1100 - #define NMBR_MSG_FRAMES 128 1101 - 1102 - #define MSG_POOL_SIZE (MSG_FRAME_SIZE*NMBR_MSG_FRAMES*sizeof(u32)) 1148 + /* outbound queue defines */ 1149 + #define I2O_MAX_OUTBOUND_MSG_FRAMES 128 1150 + #define I2O_OUTBOUND_MSG_FRAME_SIZE 128 /* in 32-bit words */ 1103 1151 1104 1152 #define I2O_POST_WAIT_OK 0 1105 1153 #define I2O_POST_WAIT_TIMEOUT -ETIMEDOUT