Lines Matching full:ctrl

169 static void start_int_poll_timer(struct controller *ctrl, int sec);
170 static int hpc_check_cmd_status(struct controller *ctrl);
172 static inline u8 shpc_readb(struct controller *ctrl, int reg) in shpc_readb() argument
174 return readb(ctrl->creg + reg); in shpc_readb()
177 static inline u16 shpc_readw(struct controller *ctrl, int reg) in shpc_readw() argument
179 return readw(ctrl->creg + reg); in shpc_readw()
182 static inline void shpc_writew(struct controller *ctrl, int reg, u16 val) in shpc_writew() argument
184 writew(val, ctrl->creg + reg); in shpc_writew()
187 static inline u32 shpc_readl(struct controller *ctrl, int reg) in shpc_readl() argument
189 return readl(ctrl->creg + reg); in shpc_readl()
192 static inline void shpc_writel(struct controller *ctrl, int reg, u32 val) in shpc_writel() argument
194 writel(val, ctrl->creg + reg); in shpc_writel()
197 static inline int shpc_indirect_read(struct controller *ctrl, int index, in shpc_indirect_read() argument
201 u32 cap_offset = ctrl->cap_offset; in shpc_indirect_read()
202 struct pci_dev *pdev = ctrl->pci_dev; in shpc_indirect_read()
215 struct controller *ctrl = from_timer(ctrl, t, poll_timer); in int_poll_timeout() local
218 shpc_isr(0, ctrl); in int_poll_timeout()
223 start_int_poll_timer(ctrl, shpchp_poll_time); in int_poll_timeout()
229 static void start_int_poll_timer(struct controller *ctrl, int sec) in start_int_poll_timer() argument
235 ctrl->poll_timer.expires = jiffies + sec * HZ; in start_int_poll_timer()
236 add_timer(&ctrl->poll_timer); in start_int_poll_timer()
239 static inline int is_ctrl_busy(struct controller *ctrl) in is_ctrl_busy() argument
241 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS); in is_ctrl_busy()
249 static inline int shpc_poll_ctrl_busy(struct controller *ctrl) in shpc_poll_ctrl_busy() argument
253 if (!is_ctrl_busy(ctrl)) in shpc_poll_ctrl_busy()
259 if (!is_ctrl_busy(ctrl)) in shpc_poll_ctrl_busy()
266 static inline int shpc_wait_cmd(struct controller *ctrl) in shpc_wait_cmd() argument
273 rc = shpc_poll_ctrl_busy(ctrl); in shpc_wait_cmd()
275 rc = wait_event_interruptible_timeout(ctrl->queue, in shpc_wait_cmd()
276 !is_ctrl_busy(ctrl), timeout); in shpc_wait_cmd()
277 if (!rc && is_ctrl_busy(ctrl)) { in shpc_wait_cmd()
279 ctrl_err(ctrl, "Command not completed in 1000 msec\n"); in shpc_wait_cmd()
282 ctrl_info(ctrl, "Command was interrupted by a signal\n"); in shpc_wait_cmd()
290 struct controller *ctrl = slot->ctrl; in shpc_write_cmd() local
295 mutex_lock(&slot->ctrl->cmd_lock); in shpc_write_cmd()
297 if (!shpc_poll_ctrl_busy(ctrl)) { in shpc_write_cmd()
299 ctrl_err(ctrl, "Controller is still busy after 1 sec\n"); in shpc_write_cmd()
306 ctrl_dbg(ctrl, "%s: t_slot %x cmd %x\n", __func__, t_slot, cmd); in shpc_write_cmd()
311 shpc_writew(ctrl, CMD, temp_word); in shpc_write_cmd()
316 retval = shpc_wait_cmd(slot->ctrl); in shpc_write_cmd()
320 cmd_status = hpc_check_cmd_status(slot->ctrl); in shpc_write_cmd()
322 ctrl_err(ctrl, "Failed to issued command 0x%x (error code = %d)\n", in shpc_write_cmd()
327 mutex_unlock(&slot->ctrl->cmd_lock); in shpc_write_cmd()
331 static int hpc_check_cmd_status(struct controller *ctrl) in hpc_check_cmd_status() argument
334 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F; in hpc_check_cmd_status()
342 ctrl_err(ctrl, "Switch opened!\n"); in hpc_check_cmd_status()
346 ctrl_err(ctrl, "Invalid HPC command!\n"); in hpc_check_cmd_status()
350 ctrl_err(ctrl, "Invalid bus speed/mode!\n"); in hpc_check_cmd_status()
362 struct controller *ctrl = slot->ctrl; in hpc_get_attention_status() local
363 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); in hpc_get_attention_status()
386 struct controller *ctrl = slot->ctrl; in hpc_get_power_status() local
387 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); in hpc_get_power_status()
411 struct controller *ctrl = slot->ctrl; in hpc_get_latch_status() local
412 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); in hpc_get_latch_status()
421 struct controller *ctrl = slot->ctrl; in hpc_get_adapter_status() local
422 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); in hpc_get_adapter_status()
432 struct controller *ctrl = slot->ctrl; in hpc_get_prog_int() local
434 *prog_int = shpc_readb(ctrl, PROG_INTERFACE); in hpc_get_prog_int()
442 struct controller *ctrl = slot->ctrl; in hpc_get_adapter_speed() local
443 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); in hpc_get_adapter_speed()
462 ctrl_dbg(ctrl, "%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n", in hpc_get_adapter_speed()
488 ctrl_dbg(ctrl, "Adapter speed = %d\n", *value); in hpc_get_adapter_speed()
494 struct controller *ctrl = slot->ctrl; in hpc_query_power_fault() local
495 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); in hpc_query_power_fault()
538 static void hpc_release_ctlr(struct controller *ctrl) in hpc_release_ctlr() argument
546 for (i = 0; i < ctrl->num_slots; i++) { in hpc_release_ctlr()
547 slot_reg = shpc_readl(ctrl, SLOT_REG(i)); in hpc_release_ctlr()
553 shpc_writel(ctrl, SLOT_REG(i), slot_reg); in hpc_release_ctlr()
556 cleanup_slots(ctrl); in hpc_release_ctlr()
561 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); in hpc_release_ctlr()
565 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); in hpc_release_ctlr()
568 del_timer(&ctrl->poll_timer); in hpc_release_ctlr()
570 free_irq(ctrl->pci_dev->irq, ctrl); in hpc_release_ctlr()
571 pci_disable_msi(ctrl->pci_dev); in hpc_release_ctlr()
574 iounmap(ctrl->creg); in hpc_release_ctlr()
575 release_mem_region(ctrl->mmio_base, ctrl->mmio_size); in hpc_release_ctlr()
584 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__); in hpc_power_on_slot()
597 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__); in hpc_slot_enable()
610 ctrl_err(slot->ctrl, "%s: Write command failed!\n", __func__); in hpc_slot_disable()
615 static int shpc_get_cur_bus_speed(struct controller *ctrl) in shpc_get_cur_bus_speed() argument
618 struct pci_bus *bus = ctrl->pci_dev->subordinate; in shpc_get_cur_bus_speed()
620 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG); in shpc_get_cur_bus_speed()
621 u8 pi = shpc_readb(ctrl, PROG_INTERFACE); in shpc_get_cur_bus_speed()
687 struct controller *ctrl = slot->ctrl; in hpc_set_bus_speed_mode() local
690 pi = shpc_readb(ctrl, PROG_INTERFACE); in hpc_set_bus_speed_mode()
743 ctrl_err(ctrl, "%s: Write command failed!\n", __func__); in hpc_set_bus_speed_mode()
745 shpc_get_cur_bus_speed(ctrl); in hpc_set_bus_speed_mode()
752 struct controller *ctrl = (struct controller *)dev_id; in shpc_isr() local
757 intr_loc = shpc_readl(ctrl, INTR_LOC); in shpc_isr()
761 ctrl_dbg(ctrl, "%s: intr_loc = %x\n", __func__, intr_loc); in shpc_isr()
768 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_isr()
771 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); in shpc_isr()
773 intr_loc2 = shpc_readl(ctrl, INTR_LOC); in shpc_isr()
774 ctrl_dbg(ctrl, "%s: intr_loc2 = %x\n", __func__, intr_loc2); in shpc_isr()
783 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_isr()
785 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); in shpc_isr()
787 wake_up_interruptible(&ctrl->queue); in shpc_isr()
793 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { in shpc_isr()
798 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); in shpc_isr()
799 ctrl_dbg(ctrl, "Slot %x with intr, slot register = %x\n", in shpc_isr()
803 shpchp_handle_switch_change(hp_slot, ctrl); in shpc_isr()
806 shpchp_handle_attention_button(hp_slot, ctrl); in shpc_isr()
809 shpchp_handle_presence_change(hp_slot, ctrl); in shpc_isr()
812 shpchp_handle_power_fault(hp_slot, ctrl); in shpc_isr()
816 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); in shpc_isr()
821 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_isr()
823 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); in shpc_isr()
829 static int shpc_get_max_bus_speed(struct controller *ctrl) in shpc_get_max_bus_speed() argument
832 struct pci_bus *bus = ctrl->pci_dev->subordinate; in shpc_get_max_bus_speed()
834 u8 pi = shpc_readb(ctrl, PROG_INTERFACE); in shpc_get_max_bus_speed()
835 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1); in shpc_get_max_bus_speed()
836 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2); in shpc_get_max_bus_speed()
869 ctrl_dbg(ctrl, "Max bus speed = %d\n", bus_speed); in shpc_get_max_bus_speed()
896 int shpc_init(struct controller *ctrl, struct pci_dev *pdev) in shpc_init() argument
904 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ in shpc_init()
905 ctrl_dbg(ctrl, "Hotplug Controller:\n"); in shpc_init()
910 ctrl->mmio_base = pci_resource_start(pdev, 0); in shpc_init()
911 ctrl->mmio_size = pci_resource_len(pdev, 0); in shpc_init()
913 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC); in shpc_init()
914 if (!ctrl->cap_offset) { in shpc_init()
915 ctrl_err(ctrl, "Cannot find PCI capability\n"); in shpc_init()
918 ctrl_dbg(ctrl, " cap_offset = %x\n", ctrl->cap_offset); in shpc_init()
920 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset); in shpc_init()
922 ctrl_err(ctrl, "Cannot read base_offset\n"); in shpc_init()
926 rc = shpc_indirect_read(ctrl, 3, &tempdword); in shpc_init()
928 ctrl_err(ctrl, "Cannot read slot config\n"); in shpc_init()
932 ctrl_dbg(ctrl, " num_slots (indirect) %x\n", num_slots); in shpc_init()
935 rc = shpc_indirect_read(ctrl, i, &tempdword); in shpc_init()
937 ctrl_err(ctrl, "Cannot read creg (index = %d)\n", in shpc_init()
941 ctrl_dbg(ctrl, " offset %d: value %x\n", i, tempdword); in shpc_init()
944 ctrl->mmio_base = in shpc_init()
946 ctrl->mmio_size = 0x24 + 0x4 * num_slots; in shpc_init()
949 ctrl_info(ctrl, "HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", in shpc_init()
955 ctrl_err(ctrl, "pci_enable_device failed\n"); in shpc_init()
959 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { in shpc_init()
960 ctrl_err(ctrl, "Cannot reserve MMIO region\n"); in shpc_init()
965 ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size); in shpc_init()
966 if (!ctrl->creg) { in shpc_init()
967 ctrl_err(ctrl, "Cannot remap MMIO region %lx @ %lx\n", in shpc_init()
968 ctrl->mmio_size, ctrl->mmio_base); in shpc_init()
969 release_mem_region(ctrl->mmio_base, ctrl->mmio_size); in shpc_init()
973 ctrl_dbg(ctrl, "ctrl->creg %p\n", ctrl->creg); in shpc_init()
975 mutex_init(&ctrl->crit_sect); in shpc_init()
976 mutex_init(&ctrl->cmd_lock); in shpc_init()
979 init_waitqueue_head(&ctrl->queue); in shpc_init()
981 ctrl->hpc_ops = &shpchp_hpc_ops; in shpc_init()
984 slot_config = shpc_readl(ctrl, SLOT_CONFIG); in shpc_init()
985 ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8; in shpc_init()
986 ctrl->num_slots = slot_config & SLOT_NUM; in shpc_init()
987 ctrl->first_slot = (slot_config & PSN) >> 16; in shpc_init()
988 ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1; in shpc_init()
991 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_init()
992 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword); in shpc_init()
996 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); in shpc_init()
997 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_init()
998 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword); in shpc_init()
1003 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { in shpc_init()
1004 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); in shpc_init()
1005 ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n", in shpc_init()
1012 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); in shpc_init()
1017 timer_setup(&ctrl->poll_timer, int_poll_timeout, 0); in shpc_init()
1018 start_int_poll_timer(ctrl, 10); in shpc_init()
1023 ctrl_info(ctrl, "Can't get msi for the hotplug controller\n"); in shpc_init()
1024 ctrl_info(ctrl, "Use INTx for the hotplug controller\n"); in shpc_init()
1029 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED, in shpc_init()
1030 MY_NAME, (void *)ctrl); in shpc_init()
1031 ctrl_dbg(ctrl, "request_irq %d (returns %d)\n", in shpc_init()
1032 ctrl->pci_dev->irq, rc); in shpc_init()
1034 ctrl_err(ctrl, "Can't get irq %d for the hotplug controller\n", in shpc_init()
1035 ctrl->pci_dev->irq); in shpc_init()
1039 ctrl_dbg(ctrl, "HPC at %s irq=%x\n", pci_name(pdev), pdev->irq); in shpc_init()
1041 shpc_get_max_bus_speed(ctrl); in shpc_init()
1042 shpc_get_cur_bus_speed(ctrl); in shpc_init()
1047 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { in shpc_init()
1048 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); in shpc_init()
1049 ctrl_dbg(ctrl, "Default Logical Slot Register %d value %x\n", in shpc_init()
1054 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); in shpc_init()
1058 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_init()
1061 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); in shpc_init()
1062 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); in shpc_init()
1063 ctrl_dbg(ctrl, "SERR_INTR_ENABLE = %x\n", tempdword); in shpc_init()
1070 iounmap(ctrl->creg); in shpc_init()