diff options
Diffstat (limited to 'drivers/pci/hotplug/ibmphp_hpc.c')
| -rw-r--r-- | drivers/pci/hotplug/ibmphp_hpc.c | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c index c31e7bf3450..a936022956e 100644 --- a/drivers/pci/hotplug/ibmphp_hpc.c +++ b/drivers/pci/hotplug/ibmphp_hpc.c @@ -35,6 +35,7 @@ #include <linux/init.h> #include <linux/mutex.h> #include <linux/sched.h> +#include <linux/semaphore.h> #include <linux/kthread.h> #include "ibmphp.h" @@ -129,14 +130,14 @@ static int hpc_wait_ctlr_notworking (int, struct controller *, void __iomem *, u *---------------------------------------------------------------------*/ void __init ibmphp_hpc_initvars (void) { - debug ("%s - Entry\n", __FUNCTION__); + debug ("%s - Entry\n", __func__); mutex_init(&sem_hpcaccess); - init_MUTEX (&semOperations); - init_MUTEX_LOCKED (&sem_exit); + sema_init(&semOperations, 1); + sema_init(&sem_exit, 0); to_debug = 0; - debug ("%s - Exit\n", __FUNCTION__); + debug ("%s - Exit\n", __func__); } /*---------------------------------------------------------------------- @@ -154,7 +155,7 @@ static u8 i2c_ctrl_read (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 unsigned long ultemp; unsigned long data; // actual data HILO format - debug_polling ("%s - Entry WPGBbar[%p] index[%x] \n", __FUNCTION__, WPGBbar, index); + debug_polling ("%s - Entry WPGBbar[%p] index[%x] \n", __func__, WPGBbar, index); //-------------------------------------------------------------------- // READ - step 1 @@ -213,7 +214,7 @@ static u8 i2c_ctrl_read (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 i--; } if (i == 0) { - debug ("%s - Error : WPG timeout\n", __FUNCTION__); + debug ("%s - Error : WPG timeout\n", __func__); return HPC_ERROR; } //-------------------------------------------------------------------- @@ -241,7 +242,7 @@ static u8 i2c_ctrl_read (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 status = (u8) data; - debug_polling ("%s - Exit index[%x] status[%x]\n", __FUNCTION__, index, status); + debug_polling ("%s - Exit index[%x] status[%x]\n", __func__, index, status); return (status); } @@ -257,12 +258,12 @@ static u8 i2c_ctrl_write (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 { u8 rc; void __iomem *wpg_addr; // base addr + offset - unsigned long wpg_data; // data to/from WPG LOHI format + unsigned long wpg_data; // data to/from WPG LOHI format unsigned long ultemp; unsigned long data; // actual data HILO format int i; - debug_polling ("%s - Entry WPGBbar[%p] index[%x] cmd[%x]\n", __FUNCTION__, WPGBbar, index, cmd); + debug_polling ("%s - Entry WPGBbar[%p] index[%x] cmd[%x]\n", __func__, WPGBbar, index, cmd); rc = 0; //-------------------------------------------------------------------- @@ -324,7 +325,7 @@ static u8 i2c_ctrl_write (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 i--; } if (i == 0) { - debug ("%s - Exit Error:WPG timeout\n", __FUNCTION__); + debug ("%s - Exit Error:WPG timeout\n", __func__); rc = HPC_ERROR; } @@ -345,12 +346,12 @@ static u8 i2c_ctrl_write (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 rc = HPC_ERROR; } - debug_polling ("%s Exit rc[%x]\n", __FUNCTION__, rc); + debug_polling ("%s Exit rc[%x]\n", __func__, rc); return (rc); } //------------------------------------------------------------ -// Read from ISA type HPC +// Read from ISA type HPC //------------------------------------------------------------ static u8 isa_ctrl_read (struct controller *ctlr_ptr, u8 offset) { @@ -371,7 +372,7 @@ static void isa_ctrl_write (struct controller *ctlr_ptr, u8 offset, u8 data) { u16 start_address; u16 port_address; - + start_address = ctlr_ptr->u.isa_ctlr.io_start; port_address = start_address + (u16) offset; outb (data, port_address); @@ -532,7 +533,7 @@ static u8 hpc_readcmdtoindex (u8 cmd, u8 index) * * Return 0 or error codes *---------------------------------------------------------------------*/ -int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) +int ibmphp_hpc_readslot (struct slot *pslot, u8 cmd, u8 *pstatus) { void __iomem *wpg_bbar = NULL; struct controller *ctlr_ptr; @@ -541,12 +542,12 @@ int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) int rc = 0; int busindex; - debug_polling ("%s - Entry pslot[%p] cmd[%x] pstatus[%p]\n", __FUNCTION__, pslot, cmd, pstatus); + debug_polling ("%s - Entry pslot[%p] cmd[%x] pstatus[%p]\n", __func__, pslot, cmd, pstatus); if ((pslot == NULL) || ((pstatus == NULL) && (cmd != READ_ALLSTAT) && (cmd != READ_BUSSTATUS))) { rc = -EINVAL; - err ("%s - Error invalid pointer, rc[%d]\n", __FUNCTION__, rc); + err ("%s - Error invalid pointer, rc[%d]\n", __func__, rc); return rc; } @@ -554,7 +555,7 @@ int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) busindex = ibmphp_get_bus_index (pslot->bus); if (busindex < 0) { rc = -EINVAL; - err ("%s - Exit Error:invalid bus, rc[%d]\n", __FUNCTION__, rc); + err ("%s - Exit Error:invalid bus, rc[%d]\n", __func__, rc); return rc; } else index = (u8) busindex; @@ -565,7 +566,7 @@ int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) if (index == HPC_ERROR) { rc = -EINVAL; - err ("%s - Exit Error:invalid index, rc[%d]\n", __FUNCTION__, rc); + err ("%s - Exit Error:invalid index, rc[%d]\n", __func__, rc); return rc; } @@ -641,7 +642,7 @@ int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) ctrl_read (ctlr_ptr, wpg_bbar, index + WPG_1ST_EXTSLOT_INDEX); } else { - err ("%s - Error ctrl_read failed\n", __FUNCTION__); + err ("%s - Error ctrl_read failed\n", __func__); rc = -EINVAL; break; } @@ -655,14 +656,14 @@ int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) //-------------------------------------------------------------------- // cleanup //-------------------------------------------------------------------- - + // remove physical to logical address mapping if ((ctlr_ptr->ctlr_type == 2) || (ctlr_ptr->ctlr_type == 4)) iounmap (wpg_bbar); - + free_hpc_access (); - debug_polling ("%s - Exit rc[%d]\n", __FUNCTION__, rc); + debug_polling ("%s - Exit rc[%d]\n", __func__, rc); return rc; } @@ -671,7 +672,7 @@ int ibmphp_hpc_readslot (struct slot * pslot, u8 cmd, u8 * pstatus) * * Action: issue a WRITE command to HPC *---------------------------------------------------------------------*/ -int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) +int ibmphp_hpc_writeslot (struct slot *pslot, u8 cmd) { void __iomem *wpg_bbar = NULL; struct controller *ctlr_ptr; @@ -681,10 +682,10 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) int rc = 0; int timeout; - debug_polling ("%s - Entry pslot[%p] cmd[%x]\n", __FUNCTION__, pslot, cmd); + debug_polling ("%s - Entry pslot[%p] cmd[%x]\n", __func__, pslot, cmd); if (pslot == NULL) { rc = -EINVAL; - err ("%s - Error Exit rc[%d]\n", __FUNCTION__, rc); + err ("%s - Error Exit rc[%d]\n", __func__, rc); return rc; } @@ -694,7 +695,7 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) busindex = ibmphp_get_bus_index (pslot->bus); if (busindex < 0) { rc = -EINVAL; - err ("%s - Exit Error:invalid bus, rc[%d]\n", __FUNCTION__, rc); + err ("%s - Exit Error:invalid bus, rc[%d]\n", __func__, rc); return rc; } else index = (u8) busindex; @@ -705,7 +706,7 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) if (index == HPC_ERROR) { rc = -EINVAL; - err ("%s - Error Exit rc[%d]\n", __FUNCTION__, rc); + err ("%s - Error Exit rc[%d]\n", __func__, rc); return rc; } @@ -719,7 +720,7 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) if ((ctlr_ptr->ctlr_type == 2) || (ctlr_ptr->ctlr_type == 4)) { wpg_bbar = ioremap (ctlr_ptr->u.wpeg_ctlr.wpegbbar, WPG_I2C_IOREMAP_SIZE); - debug ("%s - ctlr id[%x] physical[%lx] logical[%lx] i2c[%x]\n", __FUNCTION__, + debug ("%s - ctlr id[%x] physical[%lx] logical[%lx] i2c[%x]\n", __func__, ctlr_ptr->ctlr_id, (ulong) (ctlr_ptr->u.wpeg_ctlr.wpegbbar), (ulong) wpg_bbar, ctlr_ptr->u.wpeg_ctlr.i2c_addr); } @@ -750,7 +751,7 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) msleep(1000); if (timeout < 1) { done = 1; - err ("%s - Error command complete timeout\n", __FUNCTION__); + err ("%s - Error command complete timeout\n", __func__); rc = -EFAULT; } else timeout--; @@ -765,7 +766,7 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd) iounmap (wpg_bbar); free_hpc_access (); - debug_polling ("%s - Exit rc[%d]\n", __FUNCTION__, rc); + debug_polling ("%s - Exit rc[%d]\n", __func__, rc); return rc; } @@ -803,10 +804,10 @@ void ibmphp_lock_operations (void) *---------------------------------------------------------------------*/ void ibmphp_unlock_operations (void) { - debug ("%s - Entry\n", __FUNCTION__); + debug ("%s - Entry\n", __func__); up (&semOperations); to_debug = 0; - debug ("%s - Exit\n", __FUNCTION__); + debug ("%s - Exit\n", __func__); } /*---------------------------------------------------------------------- @@ -827,14 +828,14 @@ static int poll_hpc(void *data) int poll_count = 0; u8 ctrl_count = 0x00; - debug ("%s - Entry\n", __FUNCTION__); + debug ("%s - Entry\n", __func__); while (!kthread_should_stop()) { /* try to get the lock to do some kind of hardware access */ down (&semOperations); switch (poll_state) { - case POLL_LATCH_REGISTER: + case POLL_LATCH_REGISTER: oldlatchlow = curlatchlow; ctrl_count = 0x00; list_for_each (pslotlist, &ibmphp_slot_head) { @@ -890,24 +891,25 @@ static int poll_hpc(void *data) msleep(POLL_INTERVAL_SEC * 1000); if (kthread_should_stop()) - break; - + goto out_sleep; + down (&semOperations); - + if (poll_count >= POLL_LATCH_CNT) { poll_count = 0; poll_state = POLL_SLOTS; } else poll_state = POLL_LATCH_REGISTER; break; - } + } /* give up the hardware semaphore */ up (&semOperations); /* sleep for a short time just for good measure */ +out_sleep: msleep(100); } up (&sem_exit); - debug ("%s - Exit\n", __FUNCTION__); + debug ("%s - Exit\n", __func__); return 0; } @@ -956,7 +958,7 @@ static int process_changeinstatus (struct slot *pslot, struct slot *poldslot) // bit 5 - HPC_SLOT_PWRGD if ((pslot->status & 0x20) != (poldslot->status & 0x20)) // OFF -> ON: ignore, ON -> OFF: disable slot - if ((poldslot->status & 0x20) && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status))) + if ((poldslot->status & 0x20) && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status))) disable = 1; // bit 6 - HPC_SLOT_BUS_SPEED @@ -978,7 +980,7 @@ static int process_changeinstatus (struct slot *pslot, struct slot *poldslot) pslot->status &= ~HPC_SLOT_POWER; } } - // CLOSE -> OPEN + // CLOSE -> OPEN else if ((SLOT_PWRGD (poldslot->status) == HPC_SLOT_PWRGD_GOOD) && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status))) { disable = 1; @@ -999,7 +1001,7 @@ static int process_changeinstatus (struct slot *pslot, struct slot *poldslot) ibmphp_update_slot_info (pslot); } - debug ("%s - Exit rc[%d] disable[%x] update[%x]\n", __FUNCTION__, rc, disable, update); + debug ("%s - Exit rc[%d] disable[%x] update[%x]\n", __func__, rc, disable, update); return rc; } @@ -1021,7 +1023,7 @@ static int process_changeinlatch (u8 old, u8 new, struct controller *ctrl) u8 mask; int rc = 0; - debug ("%s - Entry old[%x], new[%x]\n", __FUNCTION__, old, new); + debug ("%s - Entry old[%x], new[%x]\n", __func__, old, new); // bit 0 reserved, 0 is LSB, check bit 1-6 for 6 slots for (i = ctrl->starting_slot_num; i <= ctrl->ending_slot_num; i++) { @@ -1031,15 +1033,15 @@ static int process_changeinlatch (u8 old, u8 new, struct controller *ctrl) if (pslot) { memcpy ((void *) &myslot, (void *) pslot, sizeof (struct slot)); rc = ibmphp_hpc_readslot (pslot, READ_ALLSTAT, NULL); - debug ("%s - call process_changeinstatus for slot[%d]\n", __FUNCTION__, i); + debug ("%s - call process_changeinstatus for slot[%d]\n", __func__, i); process_changeinstatus (pslot, &myslot); } else { rc = -EINVAL; - err ("%s - Error bad pointer for slot[%d]\n", __FUNCTION__, i); + err ("%s - Error bad pointer for slot[%d]\n", __func__, i); } } } - debug ("%s - Exit rc[%d]\n", __FUNCTION__, rc); + debug ("%s - Exit rc[%d]\n", __func__, rc); return rc; } @@ -1050,11 +1052,11 @@ static int process_changeinlatch (u8 old, u8 new, struct controller *ctrl) *---------------------------------------------------------------------*/ int __init ibmphp_hpc_start_poll_thread (void) { - debug ("%s - Entry\n", __FUNCTION__); + debug ("%s - Entry\n", __func__); ibmphp_poll_thread = kthread_run(poll_hpc, NULL, "hpc_poll"); if (IS_ERR(ibmphp_poll_thread)) { - err ("%s - Error, thread not started\n", __FUNCTION__); + err ("%s - Error, thread not started\n", __func__); return PTR_ERR(ibmphp_poll_thread); } return 0; @@ -1067,13 +1069,13 @@ int __init ibmphp_hpc_start_poll_thread (void) *---------------------------------------------------------------------*/ void __exit ibmphp_hpc_stop_poll_thread (void) { - debug ("%s - Entry\n", __FUNCTION__); + debug ("%s - Entry\n", __func__); kthread_stop(ibmphp_poll_thread); debug ("before locking operations \n"); ibmphp_lock_operations (); debug ("after locking operations \n"); - + // wait for poll thread to exit debug ("before sem_exit down \n"); down (&sem_exit); @@ -1088,7 +1090,7 @@ void __exit ibmphp_hpc_stop_poll_thread (void) up (&sem_exit); debug ("after sem exit up\n"); - debug ("%s - Exit\n", __FUNCTION__); + debug ("%s - Exit\n", __func__); } /*---------------------------------------------------------------------- @@ -1100,7 +1102,7 @@ void __exit ibmphp_hpc_stop_poll_thread (void) * Value: *---------------------------------------------------------------------*/ static int hpc_wait_ctlr_notworking (int timeout, struct controller *ctlr_ptr, void __iomem *wpg_bbar, - u8 * pstatus) + u8 *pstatus) { int rc = 0; u8 done = 0; |
