aboutsummaryrefslogtreecommitdiff
path: root/drivers/message/i2o/iop.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/message/i2o/iop.c')
-rw-r--r--drivers/message/i2o/iop.c566
1 files changed, 279 insertions, 287 deletions
diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
index 50c8cedf7a2..42f8b810d6e 100644
--- a/drivers/message/i2o/iop.c
+++ b/drivers/message/i2o/iop.c
@@ -28,8 +28,10 @@
#include <linux/module.h>
#include <linux/i2o.h>
#include <linux/delay.h>
+#include "core.h"
-#define OSM_VERSION "$Rev$"
+#define OSM_NAME "i2o"
+#define OSM_VERSION "1.288"
#define OSM_DESCRIPTION "I2O subsystem"
/* global I2O controller list */
@@ -43,20 +45,6 @@ static struct i2o_dma i2o_systab;
static int i2o_hrt_get(struct i2o_controller *c);
-/* Module internal functions from other sources */
-extern struct i2o_driver i2o_exec_driver;
-extern int i2o_exec_lct_get(struct i2o_controller *);
-extern void i2o_device_remove(struct i2o_device *);
-
-extern int __init i2o_driver_init(void);
-extern void __exit i2o_driver_exit(void);
-extern int __init i2o_exec_init(void);
-extern void __exit i2o_exec_exit(void);
-extern int __init i2o_pci_init(void);
-extern void __exit i2o_pci_exit(void);
-extern int i2o_device_init(void);
-extern void i2o_device_exit(void);
-
/**
* i2o_msg_nop - Returns a message which is not used
* @c: I2O controller from which the message was created
@@ -68,7 +56,7 @@ extern void i2o_device_exit(void);
*/
void i2o_msg_nop(struct i2o_controller *c, u32 m)
{
- struct i2o_message __iomem *msg = c->in_queue.virt + m;
+ struct i2o_message __iomem *msg = i2o_msg_in_to_virt(c, m);
writel(THREE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
writel(I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | ADAPTER_TID,
@@ -92,16 +80,16 @@ void i2o_msg_nop(struct i2o_controller *c, u32 m)
* address from the read port (see the i2o spec). If no message is
* available returns I2O_QUEUE_EMPTY and msg is leaved untouched.
*/
-u32 i2o_msg_get_wait(struct i2o_controller *c, struct i2o_message __iomem **msg,
- int wait)
+u32 i2o_msg_get_wait(struct i2o_controller *c,
+ struct i2o_message __iomem ** msg, int wait)
{
unsigned long timeout = jiffies + wait * HZ;
u32 m;
while ((m = i2o_msg_get(c, msg)) == I2O_QUEUE_EMPTY) {
if (time_after(jiffies, timeout)) {
- pr_debug("%s: Timeout waiting for message frame.\n",
- c->name);
+ osm_debug("%s: Timeout waiting for message frame.\n",
+ c->name);
return I2O_QUEUE_EMPTY;
}
set_current_state(TASK_UNINTERRUPTIBLE);
@@ -129,13 +117,13 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
unsigned long flags;
if (!ptr)
- printk(KERN_ERR "%s: couldn't add NULL pointer to context list!"
- "\n", c->name);
+ osm_err("%s: couldn't add NULL pointer to context list!\n",
+ c->name);
entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
if (!entry) {
- printk(KERN_ERR "%s: Could not allocate memory for context "
- "list element\n", c->name);
+ osm_err("%s: Could not allocate memory for context list element"
+ "\n", c->name);
return 0;
}
@@ -154,7 +142,7 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
spin_unlock_irqrestore(&c->context_list_lock, flags);
- pr_debug("%s: Add context to list %p -> %d\n", c->name, ptr, context);
+ osm_debug("%s: Add context to list %p -> %d\n", c->name, ptr, context);
return entry->context;
};
@@ -186,11 +174,11 @@ u32 i2o_cntxt_list_remove(struct i2o_controller * c, void *ptr)
spin_unlock_irqrestore(&c->context_list_lock, flags);
if (!context)
- printk(KERN_WARNING "%s: Could not remove nonexistent ptr "
- "%p\n", c->name, ptr);
+ osm_warn("%s: Could not remove nonexistent ptr %p\n", c->name,
+ ptr);
- pr_debug("%s: remove ptr from context list %d -> %p\n", c->name,
- context, ptr);
+ osm_debug("%s: remove ptr from context list %d -> %p\n", c->name,
+ context, ptr);
return context;
};
@@ -220,11 +208,10 @@ void *i2o_cntxt_list_get(struct i2o_controller *c, u32 context)
spin_unlock_irqrestore(&c->context_list_lock, flags);
if (!ptr)
- printk(KERN_WARNING "%s: context id %d not found\n", c->name,
- context);
+ osm_warn("%s: context id %d not found\n", c->name, context);
- pr_debug("%s: get ptr from context list %d -> %p\n", c->name, context,
- ptr);
+ osm_debug("%s: get ptr from context list %d -> %p\n", c->name, context,
+ ptr);
return ptr;
};
@@ -252,11 +239,11 @@ u32 i2o_cntxt_list_get_ptr(struct i2o_controller * c, void *ptr)
spin_unlock_irqrestore(&c->context_list_lock, flags);
if (!context)
- printk(KERN_WARNING "%s: Could not find nonexistent ptr "
- "%p\n", c->name, ptr);
+ osm_warn("%s: Could not find nonexistent ptr %p\n", c->name,
+ ptr);
- pr_debug("%s: get context id from context list %p -> %d\n", c->name,
- ptr, context);
+ osm_debug("%s: get context id from context list %p -> %d\n", c->name,
+ ptr, context);
return context;
};
@@ -336,10 +323,9 @@ static int i2o_iop_quiesce(struct i2o_controller *c)
/* Long timeout needed for quiesce if lots of devices */
if ((rc = i2o_msg_post_wait(c, m, 240)))
- printk(KERN_INFO "%s: Unable to quiesce (status=%#x).\n",
- c->name, -rc);
+ osm_info("%s: Unable to quiesce (status=%#x).\n", c->name, -rc);
else
- pr_debug("%s: Quiesced.\n", c->name);
+ osm_debug("%s: Quiesced.\n", c->name);
i2o_status_get(c); // Entered READY state
@@ -377,10 +363,9 @@ static int i2o_iop_enable(struct i2o_controller *c)
/* How long of a timeout do we need? */
if ((rc = i2o_msg_post_wait(c, m, 240)))
- printk(KERN_ERR "%s: Could not enable (status=%#x).\n",
- c->name, -rc);
+ osm_err("%s: Could not enable (status=%#x).\n", c->name, -rc);
else
- pr_debug("%s: Enabled.\n", c->name);
+ osm_debug("%s: Enabled.\n", c->name);
i2o_status_get(c); // entered OPERATIONAL state
@@ -444,20 +429,78 @@ static int i2o_iop_clear(struct i2o_controller *c)
&msg->u.head[1]);
if ((rc = i2o_msg_post_wait(c, m, 30)))
- printk(KERN_INFO "%s: Unable to clear (status=%#x).\n",
- c->name, -rc);
+ osm_info("%s: Unable to clear (status=%#x).\n", c->name, -rc);
else
- pr_debug("%s: Cleared.\n", c->name);
+ osm_debug("%s: Cleared.\n", c->name);
/* Enable all IOPs */
i2o_iop_enable_all();
- i2o_status_get(c);
-
return rc;
}
/**
+ * i2o_iop_init_outbound_queue - setup the outbound message queue
+ * @c: I2O controller
+ *
+ * Clear and (re)initialize IOP's outbound queue and post the message
+ * frames to the IOP.
+ *
+ * Returns 0 on success or a negative errno code on failure.
+ */
+static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
+{
+ volatile u8 *status = c->status.virt;
+ u32 m;
+ struct i2o_message __iomem *msg;
+ ulong timeout;
+ int i;
+
+ osm_debug("%s: Initializing Outbound Queue...\n", c->name);
+
+ memset(c->status.virt, 0, 4);
+
+ m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
+ if (m == I2O_QUEUE_EMPTY)
+ return -ETIMEDOUT;
+
+ writel(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6, &msg->u.head[0]);
+ writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID,
+ &msg->u.head[1]);
+ writel(i2o_exec_driver.context, &msg->u.s.icntxt);
+ writel(0x00000000, &msg->u.s.tcntxt);
+ writel(PAGE_SIZE, &msg->body[0]);
+ /* Outbound msg frame size in words and Initcode */
+ writel(I2O_OUTBOUND_MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]);
+ writel(0xd0000004, &msg->body[2]);
+ writel(i2o_dma_low(c->status.phys), &msg->body[3]);
+ writel(i2o_dma_high(c->status.phys), &msg->body[4]);
+
+ i2o_msg_post(c, m);
+
+ timeout = jiffies + I2O_TIMEOUT_INIT_OUTBOUND_QUEUE * HZ;
+ while (*status <= I2O_CMD_IN_PROGRESS) {
+ if (time_after(jiffies, timeout)) {
+ osm_warn("%s: Timeout Initializing\n", c->name);
+ return -ETIMEDOUT;
+ }
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ schedule_timeout(1);
+ }
+
+ m = c->out_queue.phys;
+
+ /* Post frames */
+ for (i = 0; i < I2O_MAX_OUTBOUND_MSG_FRAMES; i++) {
+ i2o_flush_reply(c, m);
+ udelay(1); /* Promise */
+ m += I2O_OUTBOUND_MSG_FRAME_SIZE * sizeof(u32);
+ }
+
+ return 0;
+}
+
+/**
* i2o_iop_reset - reset an I2O controller
* @c: controller to reset
*
@@ -468,20 +511,20 @@ static int i2o_iop_clear(struct i2o_controller *c)
*/
static int i2o_iop_reset(struct i2o_controller *c)
{
- u8 *status = c->status.virt;
+ volatile u8 *status = c->status.virt;
struct i2o_message __iomem *msg;
u32 m;
unsigned long timeout;
i2o_status_block *sb = c->status_block.virt;
int rc = 0;
- pr_debug("%s: Resetting controller\n", c->name);
+ osm_debug("%s: Resetting controller\n", c->name);
m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
if (m == I2O_QUEUE_EMPTY)
return -ETIMEDOUT;
- memset(status, 0, 8);
+ memset(c->status_block.virt, 0, 8);
/* Quiesce all IOPs first */
i2o_iop_quiesce_all();
@@ -493,49 +536,43 @@ static int i2o_iop_reset(struct i2o_controller *c)
writel(0, &msg->u.s.tcntxt); //FIXME: use reasonable transaction context
writel(0, &msg->body[0]);
writel(0, &msg->body[1]);
- writel(i2o_ptr_low((void *)c->status.phys), &msg->body[2]);
- writel(i2o_ptr_high((void *)c->status.phys), &msg->body[3]);
+ writel(i2o_dma_low(c->status.phys), &msg->body[2]);
+ writel(i2o_dma_high(c->status.phys), &msg->body[3]);
i2o_msg_post(c, m);
/* Wait for a reply */
timeout = jiffies + I2O_TIMEOUT_RESET * HZ;
while (!*status) {
- if (time_after(jiffies, timeout)) {
- printk(KERN_ERR "%s: IOP reset timeout.\n", c->name);
- rc = -ETIMEDOUT;
- goto exit;
- }
-
- /* Promise bug */
- if (status[1] || status[4]) {
- *status = 0;
+ if (time_after(jiffies, timeout))
break;
- }
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
-
- rmb();
}
- if (*status == I2O_CMD_IN_PROGRESS) {
+ switch (*status) {
+ case I2O_CMD_REJECTED:
+ osm_warn("%s: IOP reset rejected\n", c->name);
+ rc = -EPERM;
+ break;
+
+ case I2O_CMD_IN_PROGRESS:
/*
* Once the reset is sent, the IOP goes into the INIT state
- * which is indeterminate. We need to wait until the IOP
- * has rebooted before we can let the system talk to
- * it. We read the inbound Free_List until a message is
- * available. If we can't read one in the given ammount of
- * time, we assume the IOP could not reboot properly.
+ * which is indeterminate. We need to wait until the IOP has
+ * rebooted before we can let the system talk to it. We read
+ * the inbound Free_List until a message is available. If we
+ * can't read one in the given ammount of time, we assume the
+ * IOP could not reboot properly.
*/
- pr_debug("%s: Reset in progress, waiting for reboot...\n",
- c->name);
+ osm_debug("%s: Reset in progress, waiting for reboot...\n",
+ c->name);
m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
while (m == I2O_QUEUE_EMPTY) {
if (time_after(jiffies, timeout)) {
- printk(KERN_ERR "%s: IOP reset timeout.\n",
- c->name);
+ osm_err("%s: IOP reset timeout.\n", c->name);
rc = -ETIMEDOUT;
goto exit;
}
@@ -545,19 +582,26 @@ static int i2o_iop_reset(struct i2o_controller *c)
m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
}
i2o_msg_nop(c, m);
- }
- /* from here all quiesce commands are safe */
- c->no_quiesce = 0;
+ /* from here all quiesce commands are safe */
+ c->no_quiesce = 0;
- /* If IopReset was rejected or didn't perform reset, try IopClear */
- i2o_status_get(c);
- if (*status == I2O_CMD_REJECTED || sb->iop_state != ADAPTER_STATE_RESET) {
- printk(KERN_WARNING "%s: Reset rejected, trying to clear\n",
- c->name);
- i2o_iop_clear(c);
- } else
- pr_debug("%s: Reset completed.\n", c->name);
+ /* verify if controller is in state RESET */
+ i2o_status_get(c);
+
+ if (!c->promise && (sb->iop_state != ADAPTER_STATE_RESET))
+ osm_warn("%s: reset completed, but adapter not in RESET"
+ " state.\n", c->name);
+ else
+ osm_debug("%s: reset completed.\n", c->name);
+
+ break;
+
+ default:
+ osm_err("%s: IOP reset timeout.\n", c->name);
+ rc = -ETIMEDOUT;
+ break;
+ }
exit:
/* Enable all IOPs */
@@ -567,88 +611,6 @@ static int i2o_iop_reset(struct i2o_controller *c)
};
/**
- * i2o_iop_init_outbound_queue - setup the outbound message queue
- * @c: I2O controller
- *
- * Clear and (re)initialize IOP's outbound queue and post the message
- * frames to the IOP.
- *
- * Returns 0 on success or a negative errno code on failure.
- */
-static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
-{
- u8 *status = c->status.virt;
- u32 m;
- struct i2o_message __iomem *msg;
- ulong timeout;
- int i;
-
- pr_debug("%s: Initializing Outbound Queue...\n", c->name);
-
- memset(status, 0, 4);
-
- m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
- if (m == I2O_QUEUE_EMPTY)
- return -ETIMEDOUT;
-
- writel(EIGHT_WORD_MSG_SIZE | TRL_OFFSET_6, &msg->u.head[0]);
- writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID,
- &msg->u.head[1]);
- writel(i2o_exec_driver.context, &msg->u.s.icntxt);
- writel(0x0106, &msg->u.s.tcntxt); /* FIXME: why 0x0106, maybe in
- Spec? */
- writel(PAGE_SIZE, &msg->body[0]);
- writel(MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); /* Outbound msg frame
- size in words and Initcode */
- writel(0xd0000004, &msg->body[2]);
- writel(i2o_ptr_low((void *)c->status.phys), &msg->body[3]);
- writel(i2o_ptr_high((void *)c->status.phys), &msg->body[4]);
-
- i2o_msg_post(c, m);
-
- timeout = jiffies + I2O_TIMEOUT_INIT_OUTBOUND_QUEUE * HZ;
- while (*status <= I2O_CMD_IN_PROGRESS) {
- if (time_after(jiffies, timeout)) {
- printk(KERN_WARNING "%s: Timeout Initializing\n",
- c->name);
- return -ETIMEDOUT;
- }
- set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_timeout(1);
-
- rmb();
- }
-
- m = c->out_queue.phys;
-
- /* Post frames */
- for (i = 0; i < NMBR_MSG_FRAMES; i++) {
- i2o_flush_reply(c, m);
- udelay(1); /* Promise */
- m += MSG_FRAME_SIZE * 4;
- }
-
- return 0;
-}
-
-/**
- * i2o_iop_send_nop - send a core NOP message
- * @c: controller
- *
- * Send a no-operation message with a reply set to cause no
- * action either. Needed for bringing up promise controllers.
- */
-static int i2o_iop_send_nop(struct i2o_controller *c)
-{
- struct i2o_message __iomem *msg;
- u32 m = i2o_msg_get_wait(c, &msg, HZ);
- if (m == I2O_QUEUE_EMPTY)
- return -ETIMEDOUT;
- i2o_msg_nop(c, m);
- return 0;
-}
-
-/**
* i2o_iop_activate - Bring controller up to HOLD
* @c: controller
*
@@ -659,78 +621,62 @@ static int i2o_iop_send_nop(struct i2o_controller *c)
*/
static int i2o_iop_activate(struct i2o_controller *c)
{
- struct pci_dev *i960 = NULL;
i2o_status_block *sb = c->status_block.virt;
int rc;
-
- if (c->promise) {
- /* Beat up the hardware first of all */
- i960 =
- pci_find_slot(c->pdev->bus->number,
- PCI_DEVFN(PCI_SLOT(c->pdev->devfn), 0));
- if (i960)
- pci_write_config_word(i960, 0x42, 0);
-
- /* Follow this sequence precisely or the controller
- ceases to perform useful functions until reboot */
- if ((rc = i2o_iop_send_nop(c)))
- return rc;
-
- if ((rc = i2o_iop_reset(c)))
- return rc;
- }
+ int state;
/* In INIT state, Wait Inbound Q to initialize (in i2o_status_get) */
/* In READY state, Get status */
rc = i2o_status_get(c);
if (rc) {
- printk(KERN_INFO "%s: Unable to obtain status, "
- "attempting a reset.\n", c->name);
- if (i2o_iop_reset(c))
+ osm_info("%s: Unable to obtain status, attempting a reset.\n",
+ c->name);
+ rc = i2o_iop_reset(c);
+ if (rc)
return rc;
}
if (sb->i2o_version > I2OVER15) {
- printk(KERN_ERR "%s: Not running version 1.5 of the I2O "
- "Specification.\n", c->name);
+ osm_err("%s: Not running version 1.5 of the I2O Specification."
+ "\n", c->name);
return -ENODEV;
}
switch (sb->iop_state) {
case ADAPTER_STATE_FAULTED:
- printk(KERN_CRIT "%s: hardware fault\n", c->name);
- return -ENODEV;
+ osm_err("%s: hardware fault\n", c->name);
+ return -EFAULT;
case ADAPTER_STATE_READY:
case ADAPTER_STATE_OPERATIONAL:
case ADAPTER_STATE_HOLD:
case ADAPTER_STATE_FAILED:
- pr_debug("%s: already running, trying to reset...\n", c->name);
- if (i2o_iop_reset(c))
- return -ENODEV;
+ osm_debug("%s: already running, trying to reset...\n", c->name);
+ rc = i2o_iop_reset(c);
+ if (rc)
+ return rc;
}
+ /* preserve state */
+ state = sb->iop_state;
+
rc = i2o_iop_init_outbound_queue(c);
if (rc)
return rc;
- if (c->promise) {
- if ((rc = i2o_iop_send_nop(c)))
- return rc;
+ /* if adapter was not in RESET state clear now */
+ if (state != ADAPTER_STATE_RESET)
+ i2o_iop_clear(c);
- if ((rc = i2o_status_get(c)))
- return rc;
+ i2o_status_get(c);
- if (i960)
- pci_write_config_word(i960, 0x42, 0x3FF);
+ if (sb->iop_state != ADAPTER_STATE_HOLD) {
+ osm_err("%s: failed to bring IOP into HOLD state\n", c->name);
+ return -EIO;
}
- /* In HOLD state */
-
- rc = i2o_hrt_get(c);
-
- return rc;
+ return i2o_hrt_get(c);
};
/**
@@ -756,20 +702,18 @@ static int i2o_iop_systab_set(struct i2o_controller *c)
res->flags = IORESOURCE_MEM;
res->start = 0;
res->end = 0;
- printk(KERN_INFO "%s: requires private memory resources.\n",
- c->name);
+ osm_info("%s: requires private memory resources.\n", c->name);
root = pci_find_parent_resource(c->pdev, res);
if (root == NULL)
- printk(KERN_WARNING "%s: Can't find parent resource!\n",
- c->name);
+ osm_warn("%s: Can't find parent resource!\n", c->name);
if (root && allocate_resource(root, res, sb->desired_mem_size, sb->desired_mem_size, sb->desired_mem_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
NULL, NULL) >= 0) {
c->mem_alloc = 1;
sb->current_mem_size = 1 + res->end - res->start;
sb->current_mem_base = res->start;
- printk(KERN_INFO "%s: allocated %ld bytes of PCI memory"
- " at 0x%08lX.\n", c->name,
- 1 + res->end - res->start, res->start);
+ osm_info("%s: allocated %ld bytes of PCI memory at "
+ "0x%08lX.\n", c->name,
+ 1 + res->end - res->start, res->start);
}
}
@@ -779,20 +723,18 @@ static int i2o_iop_systab_set(struct i2o_controller *c)
res->flags = IORESOURCE_IO;
res->start = 0;
res->end = 0;
- printk(KERN_INFO "%s: requires private memory resources.\n",
- c->name);
+ osm_info("%s: requires private memory resources.\n", c->name);
root = pci_find_parent_resource(c->pdev, res);
if (root == NULL)
- printk(KERN_WARNING "%s: Can't find parent resource!\n",
- c->name);
+ osm_warn("%s: Can't find parent resource!\n", c->name);
if (root && allocate_resource(root, res, sb->desired_io_size, sb->desired_io_size, sb->desired_io_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
NULL, NULL) >= 0) {
c->io_alloc = 1;
sb->current_io_size = 1 + res->end - res->start;
sb->current_mem_base = res->start;
- printk(KERN_INFO "%s: allocated %ld bytes of PCI I/O at"
- " 0x%08lX.\n", c->name,
- 1 + res->end - res->start, res->start);
+ osm_info("%s: allocated %ld bytes of PCI I/O at 0x%08lX"
+ ".\n", c->name, 1 + res->end - res->start,
+ res->start);
}
}
@@ -836,10 +778,10 @@ static int i2o_iop_systab_set(struct i2o_controller *c)
PCI_DMA_TODEVICE);
if (rc < 0)
- printk(KERN_ERR "%s: Unable to set SysTab (status=%#x).\n",
- c->name, -rc);
+ osm_err("%s: Unable to set SysTab (status=%#x).\n", c->name,
+ -rc);
else
- pr_debug("%s: SysTab set.\n", c->name);
+ osm_debug("%s: SysTab set.\n", c->name);
i2o_status_get(c); // Entered READY state
@@ -863,7 +805,7 @@ static int i2o_iop_online(struct i2o_controller *c)
return rc;
/* In READY state */
- pr_debug("%s: Attempting to enable...\n", c->name);
+ osm_debug("%s: Attempting to enable...\n", c->name);
rc = i2o_iop_enable(c);
if (rc)
return rc;
@@ -882,7 +824,7 @@ void i2o_iop_remove(struct i2o_controller *c)
{
struct i2o_device *dev, *tmp;
- pr_debug("%s: deleting controller\n", c->name);
+ osm_debug("%s: deleting controller\n", c->name);
i2o_driver_notify_controller_remove_all(c);
@@ -891,8 +833,12 @@ void i2o_iop_remove(struct i2o_controller *c)
list_for_each_entry_safe(dev, tmp, &c->devices, list)
i2o_device_remove(dev);
+ device_del(&c->device);
+
/* Ask the IOP to switch to RESET state */
i2o_iop_reset(c);
+
+ put_device(&c->device);
}
/**
@@ -927,8 +873,7 @@ static int i2o_systab_build(void)
systab = i2o_systab.virt = kmalloc(i2o_systab.len, GFP_KERNEL);
if (!systab) {
- printk(KERN_ERR "i2o: unable to allocate memory for System "
- "Table\n");
+ osm_err("unable to allocate memory for System Table\n");
return -ENOMEM;
}
memset(systab, 0, i2o_systab.len);
@@ -940,8 +885,8 @@ static int i2o_systab_build(void)
i2o_status_block *sb;
if (count >= num_controllers) {
- printk(KERN_ERR "i2o: controller added while building "
- "system table\n");
+ osm_err("controller added while building system table"
+ "\n");
break;
}
@@ -955,9 +900,8 @@ static int i2o_systab_build(void)
* it is techninically not part of the I2O subsystem...
*/
if (unlikely(i2o_status_get(c))) {
- printk(KERN_ERR "%s: Deleting b/c could not get status"
- " while attempting to build system table\n",
- c->name);
+ osm_err("%s: Deleting b/c could not get status while "
+ "attempting to build system table\n", c->name);
i2o_iop_remove(c);
continue; // try the next one
}
@@ -971,8 +915,10 @@ static int i2o_systab_build(void)
systab->iops[count].frame_size = sb->inbound_frame_size;
systab->iops[count].last_changed = change_ind;
systab->iops[count].iop_capabilities = sb->iop_capabilities;
- systab->iops[count].inbound_low = i2o_ptr_low(c->post_port);
- systab->iops[count].inbound_high = i2o_ptr_high(c->post_port);
+ systab->iops[count].inbound_low =
+ i2o_dma_low(c->base.phys + I2O_IN_PORT);
+ systab->iops[count].inbound_high =
+ i2o_dma_high(c->base.phys + I2O_IN_PORT);
count++;
}
@@ -1010,11 +956,11 @@ int i2o_status_get(struct i2o_controller *c)
{
struct i2o_message __iomem *msg;
u32 m;
- u8 *status_block;
+ volatile u8 *status_block;
unsigned long timeout;
status_block = (u8 *) c->status_block.virt;
- memset(status_block, 0, sizeof(i2o_status_block));
+ memset(c->status_block.virt, 0, sizeof(i2o_status_block));
m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
if (m == I2O_QUEUE_EMPTY)
@@ -1027,8 +973,8 @@ int i2o_status_get(struct i2o_controller *c)
writel(0, &msg->u.s.tcntxt); // FIXME: use resonable transaction context
writel(0, &msg->body[0]);
writel(0, &msg->body[1]);
- writel(i2o_ptr_low((void *)c->status_block.phys), &msg->body[2]);
- writel(i2o_ptr_high((void *)c->status_block.phys), &msg->body[3]);
+ writel(i2o_dma_low(c->status_block.phys), &msg->body[2]);
+ writel(i2o_dma_high(c->status_block.phys), &msg->body[3]);
writel(sizeof(i2o_status_block), &msg->body[4]); /* always 88 bytes */
i2o_msg_post(c, m);
@@ -1037,14 +983,12 @@ int i2o_status_get(struct i2o_controller *c)
timeout = jiffies + I2O_TIMEOUT_STATUS_GET * HZ;
while (status_block[87] != 0xFF) {
if (time_after(jiffies, timeout)) {
- printk(KERN_ERR "%s: Get status timeout.\n", c->name);
+ osm_err("%s: Get status timeout.\n", c->name);
return -ETIMEDOUT;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
-
- rmb();
}
#ifdef DEBUG
@@ -1088,8 +1032,8 @@ static int i2o_hrt_get(struct i2o_controller *c)
rc = i2o_msg_post_wait_mem(c, m, 20, &c->hrt);
if (rc < 0) {
- printk(KERN_ERR "%s: Unable to get HRT (status=%#x)\n",
- c->name, -rc);
+ osm_err("%s: Unable to get HRT (status=%#x)\n", c->name,
+ -rc);
return rc;
}
@@ -1103,13 +1047,41 @@ static int i2o_hrt_get(struct i2o_controller *c)
return i2o_parse_hrt(c);
}
- printk(KERN_ERR "%s: Unable to get HRT after %d tries, giving up\n",
- c->name, I2O_HRT_GET_TRIES);
+ osm_err("%s: Unable to get HRT after %d tries, giving up\n", c->name,
+ I2O_HRT_GET_TRIES);
return -EBUSY;
}
/**
+ * i2o_iop_free - Free the i2o_controller struct
+ * @c: I2O controller to free
+ */
+void i2o_iop_free(struct i2o_controller *c)
+{
+ kfree(c);
+};
+
+/**
+ * i2o_iop_release - release the memory for a I2O controller
+ * @dev: I2O controller which should be released
+ *
+ * Release the allocated memory. This function is called if refcount of
+ * device reaches 0 automatically.
+ */
+static void i2o_iop_release(struct device *dev)
+{
+ struct i2o_controller *c = to_i2o_controller(dev);
+
+ i2o_iop_free(c);
+};
+
+/* I2O controller class */
+static struct class i2o_controller_class = {
+ .name = "i2o_controller",
+};
+
+/**
* i2o_iop_alloc - Allocate and initialize a i2o_controller struct
*
* Allocate the necessary memory for a i2o_controller struct and
@@ -1125,8 +1097,8 @@ struct i2o_controller *i2o_iop_alloc(void)
c = kmalloc(sizeof(*c), GFP_KERNEL);
if (!c) {
- printk(KERN_ERR "i2o: Insufficient memory to allocate a I2O "
- "controller.\n");
+ osm_err("i2o: Insufficient memory to allocate a I2O controller."
+ "\n");
return ERR_PTR(-ENOMEM);
}
memset(c, 0, sizeof(*c));
@@ -1137,6 +1109,16 @@ struct i2o_controller *i2o_iop_alloc(void)
c->unit = unit++;
sprintf(c->name, "iop%d", c->unit);
+ device_initialize(&c->device);
+ class_device_initialize(&c->classdev);
+
+ c->device.release = &i2o_iop_release;
+ c->classdev.class = &i2o_controller_class;
+ c->classdev.dev = &c->device;
+
+ snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit);
+ snprintf(c->classdev.class_id, BUS_ID_SIZE, "iop%d", c->unit);
+
#if BITS_PER_LONG == 64
spin_lock_init(&c->context_list_lock);
atomic_set(&c->context_list_counter, 0);
@@ -1147,15 +1129,6 @@ struct i2o_controller *i2o_iop_alloc(void)
};
/**
- * i2o_iop_free - Free the i2o_controller struct
- * @c: I2O controller to free
- */
-void i2o_iop_free(struct i2o_controller *c)
-{
- kfree(c);
-};
-
-/**
* i2o_iop_add - Initialize the I2O controller and add him to the I2O core
* @c: controller
*
@@ -1168,45 +1141,58 @@ int i2o_iop_add(struct i2o_controller *c)
{
int rc;
- printk(KERN_INFO "%s: Activating I2O controller...\n", c->name);
- printk(KERN_INFO "%s: This may take a few minutes if there are many "
- "devices\n", c->name);
+ if ((rc = device_add(&c->device))) {
+ osm_err("%s: could not add controller\n", c->name);
+ goto iop_reset;
+ }
- if ((rc = i2o_iop_activate(c))) {
- printk(KERN_ERR "%s: could not activate controller\n",
- c->name);
- i2o_iop_reset(c);
- return rc;
+ if ((rc = class_device_add(&c->classdev))) {
+ osm_err("%s: could not add controller class\n", c->name);
+ goto device_del;
}
- pr_debug("%s: building sys table...\n", c->name);
+ osm_info("%s: Activating I2O controller...\n", c->name);
+ osm_info("%s: This may take a few minutes if there are many devices\n",
+ c->name);
- if ((rc = i2o_systab_build())) {
- i2o_iop_reset(c);
- return rc;
+ if ((rc = i2o_iop_activate(c))) {
+ osm_err("%s: could not activate controller\n", c->name);
+ goto class_del;
}
- pr_debug("%s: online controller...\n", c->name);
+ osm_debug("%s: building sys table...\n", c->name);
- if ((rc = i2o_iop_online(c))) {
- i2o_iop_reset(c);
- return rc;
- }
+ if ((rc = i2o_systab_build()))
+ goto class_del;
- pr_debug("%s: getting LCT...\n", c->name);
+ osm_debug("%s: online controller...\n", c->name);
- if ((rc = i2o_exec_lct_get(c))) {
- i2o_iop_reset(c);
- return rc;
- }
+ if ((rc = i2o_iop_online(c)))
+ goto class_del;
+
+ osm_debug("%s: getting LCT...\n", c->name);
+
+ if ((rc = i2o_exec_lct_get(c)))
+ goto class_del;
list_add(&c->list, &i2o_controllers);
i2o_driver_notify_controller_add_all(c);
- printk(KERN_INFO "%s: Controller added\n", c->name);
+ osm_info("%s: Controller added\n", c->name);
return 0;
+
+ class_del:
+ class_device_del(&c->classdev);
+
+ device_del:
+ device_del(&c->device);
+
+ iop_reset:
+ i2o_iop_reset(c);
+
+ return rc;
};
/**
@@ -1264,16 +1250,18 @@ static int __init i2o_iop_init(void)
if (rc)
goto exit;
- rc = i2o_driver_init();
- if (rc)
+ if ((rc = class_register(&i2o_controller_class))) {
+ osm_err("can't register class i2o_controller\n");
goto device_exit;
+ }
- rc = i2o_exec_init();
- if (rc)
+ if ((rc = i2o_driver_init()))
+ goto class_exit;
+
+ if ((rc = i2o_exec_init()))
goto driver_exit;
- rc = i2o_pci_init();
- if (rc < 0)
+ if ((rc = i2o_pci_init()))
goto exec_exit;
return 0;
@@ -1284,6 +1272,9 @@ static int __init i2o_iop_init(void)
driver_exit:
i2o_driver_exit();
+ class_exit:
+ class_unregister(&i2o_controller_class);
+
device_exit:
i2o_device_exit();
@@ -1301,6 +1292,7 @@ static void __exit i2o_iop_exit(void)
i2o_pci_exit();
i2o_exec_exit();
i2o_driver_exit();
+ class_unregister(&i2o_controller_class);
i2o_device_exit();
};