Skip to content

Commit

Permalink
[PATCH] I2O: first code cleanup of spare warnings and unused functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Markus Lidel authored and Linus Torvalds committed Jun 24, 2005
1 parent 61fbfa8 commit f88e119
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 336 deletions.
9 changes: 4 additions & 5 deletions drivers/message/i2o/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ int i2o_device_parse_lct(struct i2o_controller *c)

down(&c->lct_lock);

if (c->lct)
kfree(c->lct);
kfree(c->lct);

lct = c->dlct.virt;

Expand Down Expand Up @@ -447,8 +446,8 @@ static struct class_interface i2o_device_class_interface = {
* ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
*/

int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist,
int oplen, void *reslist, int reslen)
static int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist,
int oplen, void *reslist, int reslen)
{
struct i2o_message __iomem *msg;
u32 m;
Expand Down Expand Up @@ -540,7 +539,7 @@ int i2o_parm_field_get(struct i2o_device *i2o_dev, int group, int field,
opblk[4] = -1;

size = i2o_parm_issue(i2o_dev, I2O_CMD_UTIL_PARAMS_GET, opblk,
sizeof(opblk), resblk, sizeof(resblk));
sizeof(opblk), resblk, buflen + 8);

memcpy(buf, resblk + 8, buflen); /* cut off header */

Expand Down
46 changes: 24 additions & 22 deletions drivers/message/i2o/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <linux/rwsem.h>
#include <linux/i2o.h>

#define OSM_NAME "core"
#define OSM_NAME "i2o"

/* max_drivers - Maximum I2O drivers (OSMs) which could be registered */
unsigned int i2o_max_drivers = I2O_MAX_DRIVERS;
Expand Down Expand Up @@ -78,17 +78,16 @@ int i2o_driver_register(struct i2o_driver *drv)
int rc = 0;
unsigned long flags;

pr_debug("i2o: Register driver %s\n", drv->name);
osm_debug("Register driver %s\n", drv->name);

if (drv->event) {
drv->event_queue = create_workqueue(drv->name);
if (!drv->event_queue) {
printk(KERN_ERR "i2o: Could not initialize event queue "
"for driver %s\n", drv->name);
osm_err("Could not initialize event queue for driver "
"%s\n", drv->name);
return -EFAULT;
}
pr_debug("i2o: Event queue initialized for driver %s\n",
drv->name);
osm_debug("Event queue initialized for driver %s\n", drv->name);
} else
drv->event_queue = NULL;

Expand All @@ -99,8 +98,8 @@ int i2o_driver_register(struct i2o_driver *drv)

for (i = 0; i2o_drivers[i]; i++)
if (i >= i2o_max_drivers) {
printk(KERN_ERR "i2o: too many drivers registered, "
"increase max_drivers\n");
osm_err("too many drivers registered, increase "
"max_drivers\n");
spin_unlock_irqrestore(&i2o_drivers_lock, flags);
return -EFAULT;
}
Expand All @@ -110,8 +109,7 @@ int i2o_driver_register(struct i2o_driver *drv)

spin_unlock_irqrestore(&i2o_drivers_lock, flags);

pr_debug("i2o: driver %s gets context id %d\n", drv->name,
drv->context);
osm_debug("driver %s gets context id %d\n", drv->name, drv->context);

list_for_each_entry(c, &i2o_controllers, list) {
struct i2o_device *i2o_dev;
Expand Down Expand Up @@ -141,7 +139,7 @@ void i2o_driver_unregister(struct i2o_driver *drv)
struct i2o_controller *c;
unsigned long flags;

pr_debug("i2o: unregister driver %s\n", drv->name);
osm_debug("unregister driver %s\n", drv->name);

driver_unregister(&drv->driver);

Expand All @@ -161,7 +159,7 @@ void i2o_driver_unregister(struct i2o_driver *drv)
if (drv->event_queue) {
destroy_workqueue(drv->event_queue);
drv->event_queue = NULL;
pr_debug("i2o: event queue removed for %s\n", drv->name);
osm_debug("event queue removed for %s\n", drv->name);
}
};

Expand All @@ -178,15 +176,15 @@ void i2o_driver_unregister(struct i2o_driver *drv)
* on success and if the message should be flushed afterwords. Returns
* negative error code on failure (the message will be flushed too).
*/
int i2o_driver_dispatch(struct i2o_controller *c, u32 m,
struct i2o_message __iomem *msg)
int i2o_driver_dispatch(struct i2o_controller *c, u32 m)
{
struct i2o_driver *drv;
struct i2o_message __iomem *msg = i2o_msg_out_to_virt(c, m);
u32 context = readl(&msg->u.s.icntxt);

if (unlikely(context >= i2o_max_drivers)) {
printk(KERN_WARNING "%s: Spurious reply to unknown driver "
"%d\n", c->name, readl(&msg->u.s.icntxt));
osm_warn("%s: Spurious reply to unknown driver %d\n", c->name,
context);
return -EIO;
}

Expand All @@ -195,7 +193,8 @@ int i2o_driver_dispatch(struct i2o_controller *c, u32 m,
spin_unlock(&i2o_drivers_lock);

if (unlikely(!drv)) {
osm_warn("Spurious reply to unknown driver %d\n", context);
osm_warn("%s: Spurious reply to unknown driver %d\n", c->name,
context);
return -EIO;
}

Expand All @@ -207,6 +206,9 @@ int i2o_driver_dispatch(struct i2o_controller *c, u32 m,

osm_debug("event received from device %d\n", tid);

if (!drv->event)
return -EIO;

/* cut of header from message size (in 32-bit words) */
size = (readl(&msg->u.head[0]) >> 16) - 5;

Expand All @@ -231,8 +233,8 @@ int i2o_driver_dispatch(struct i2o_controller *c, u32 m,
}

if (unlikely(!drv->reply)) {
pr_debug("%s: Reply to driver %s, but no reply function"
" defined!\n", c->name, drv->name);
osm_debug("%s: Reply to driver %s, but no reply function"
" defined!\n", c->name, drv->name);
return -EIO;
}

Expand Down Expand Up @@ -333,11 +335,11 @@ int __init i2o_driver_init(void)
if ((i2o_max_drivers < 2) || (i2o_max_drivers > 64) ||
((i2o_max_drivers ^ (i2o_max_drivers - 1)) !=
(2 * i2o_max_drivers - 1))) {
printk(KERN_WARNING "i2o: max_drivers set to %d, but must be "
">=2 and <= 64 and a power of 2\n", i2o_max_drivers);
osm_warn("max_drivers set to %d, but must be >=2 and <= 64 and "
"a power of 2\n", i2o_max_drivers);
i2o_max_drivers = I2O_MAX_DRIVERS;
}
printk(KERN_INFO "i2o: max drivers = %d\n", i2o_max_drivers);
osm_info("max drivers = %d\n", i2o_max_drivers);

i2o_drivers =
kmalloc(i2o_max_drivers * sizeof(*i2o_drivers), GFP_KERNEL);
Expand Down
47 changes: 26 additions & 21 deletions drivers/message/i2o/exec-osm.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ static void i2o_exec_wait_free(struct i2o_exec_wait *wait)
* buffer must not be freed. Instead the event completion will free them
* for you. In all other cases the buffer are your problem.
*
* Returns 0 on success or negative error code on failure.
* Returns 0 on success, negative error code on timeout or positive error
* code from reply.
*/
int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
timeout, struct i2o_dma *dma)
{
DECLARE_WAIT_QUEUE_HEAD(wq);
struct i2o_exec_wait *wait;
static u32 tcntxt = 0x80000000;
struct i2o_message __iomem *msg = c->in_queue.virt + m;
struct i2o_message __iomem *msg = i2o_msg_in_to_virt(c, m);
int rc = 0;

wait = i2o_exec_wait_alloc();
Expand Down Expand Up @@ -161,8 +162,7 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
barrier();

if (wait->complete) {
if (readl(&wait->msg->body[0]) >> 24)
rc = readl(&wait->msg->body[0]) & 0xff;
rc = readl(&wait->msg->body[0]) >> 24;
i2o_flush_reply(c, wait->m);
i2o_exec_wait_free(wait);
} else {
Expand All @@ -187,6 +187,7 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
* @c: I2O controller which answers
* @m: message id
* @msg: pointer to the I2O reply message
* @context: transaction context of request
*
* This function is called in interrupt context only. If the reply reached
* before the timeout, the i2o_exec_wait struct is filled with the message
Expand All @@ -201,14 +202,12 @@ int i2o_msg_post_wait_mem(struct i2o_controller *c, u32 m, unsigned long
* message must also be given back to the controller.
*/
static int i2o_msg_post_wait_complete(struct i2o_controller *c, u32 m,
struct i2o_message __iomem *msg)
struct i2o_message __iomem *msg,
u32 context)
{
struct i2o_exec_wait *wait, *tmp;
static spinlock_t lock = SPIN_LOCK_UNLOCKED;
int rc = 1;
u32 context;

context = readl(&msg->u.s.tcntxt);

/*
* We need to search through the i2o_exec_wait_list to see if the given
Expand Down Expand Up @@ -251,7 +250,7 @@ static int i2o_msg_post_wait_complete(struct i2o_controller *c, u32 m,

spin_unlock(&lock);

pr_debug("%s: Bogus reply in POST WAIT (tr-context: %08x)!\n", c->name,
osm_warn("%s: Bogus reply in POST WAIT (tr-context: %08x)!\n", c->name,
context);

return -1;
Expand Down Expand Up @@ -321,29 +320,35 @@ static void i2o_exec_lct_modified(struct i2o_controller *c)
* code on failure and if the reply should be flushed.
*/
static int i2o_exec_reply(struct i2o_controller *c, u32 m,
struct i2o_message *msg)
struct i2o_message __iomem *msg)
{
if (le32_to_cpu(msg->u.head[0]) & MSG_FAIL) { // Fail bit is set
struct i2o_message __iomem *pmsg; /* preserved message */
u32 context;

if (readl(&msg->u.head[0]) & MSG_FAIL) {
/*
* If Fail bit is set we must take the transaction context of
* the preserved message to find the right request again.
*/
struct i2o_message __iomem *pmsg;
u32 pm;

pm = le32_to_cpu(msg->body[3]);
pm = readl(&msg->body[3]);

pmsg = i2o_msg_in_to_virt(c, pm);

i2o_report_status(KERN_INFO, "i2o_core", msg);

/* Release the preserved msg by resubmitting it as a NOP */
i2o_msg_nop(c, pm);
context = readl(&pmsg->u.s.tcntxt);

/* If reply to i2o_post_wait failed, return causes a timeout */
return -1;
}
/* Release the preserved msg */
i2o_msg_nop(c, pm);
} else
context = readl(&msg->u.s.tcntxt);

if (le32_to_cpu(msg->u.s.tcntxt) & 0x80000000)
return i2o_msg_post_wait_complete(c, m, msg);
if (context & 0x80000000)
return i2o_msg_post_wait_complete(c, m, msg, context);

if ((le32_to_cpu(msg->u.head[1]) >> 24) == I2O_CMD_LCT_NOTIFY) {
if ((readl(&msg->u.head[1]) >> 24) == I2O_CMD_LCT_NOTIFY) {
struct work_struct *work;

pr_debug("%s: LCT notify received\n", c->name);
Expand Down
Loading

0 comments on commit f88e119

Please sign in to comment.