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

pciehp: Clean up pcie_init()

Clean up pciehp_ini(). This patch is trying to

- Remove redundant capablity checks that were already done in PCIe
port bus driver.
- Separate the code only for debugging and make debug information
easier to read.
- Make the entire code easier to read and understand what it is doing.

Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

authored by

Kenji Kaneshige and committed by
Jesse Barnes
2aeeef11 d84be093

+90 -112
+90 -112
drivers/pci/hotplug/pciehp_hpc.c
··· 221 221 add_timer(&ctrl->poll_timer); 222 222 } 223 223 224 + static inline int pciehp_request_irq(struct controller *ctrl) 225 + { 226 + int retval, irq = ctrl->pci_dev->irq; 227 + 228 + /* Install interrupt polling timer. Start with 10 sec delay */ 229 + if (pciehp_poll_mode) { 230 + init_timer(&ctrl->poll_timer); 231 + start_int_poll_timer(ctrl, 10); 232 + return 0; 233 + } 234 + 235 + /* Installs the interrupt handler */ 236 + retval = request_irq(irq, pcie_isr, IRQF_SHARED, MY_NAME, ctrl); 237 + if (retval) 238 + err("Cannot get irq %d for the hotplug controller\n", irq); 239 + return retval; 240 + } 241 + 242 + static inline void pciehp_free_irq(struct controller *ctrl) 243 + { 244 + if (pciehp_poll_mode) 245 + del_timer_sync(&ctrl->poll_timer); 246 + else 247 + free_irq(ctrl->pci_dev->irq, ctrl); 248 + } 249 + 224 250 static inline int pcie_wait_cmd(struct controller *ctrl) 225 251 { 226 252 int retval = 0; ··· 567 541 if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) 568 542 err("%s: Cannot mask hotplut interrupt enable\n", __func__); 569 543 570 - if (pciehp_poll_mode) 571 - del_timer(&ctrl->poll_timer); 572 - else 573 - free_irq(ctrl->pci_dev->irq, ctrl); 544 + /* Free interrupt handler or interrupt polling timer */ 545 + pciehp_free_irq(ctrl); 574 546 575 547 /* 576 548 * If this is the last controller to be released, destroy the ··· 1081 1057 return -1; 1082 1058 } 1083 1059 1060 + static inline void dbg_ctrl(struct controller *ctrl) 1061 + { 1062 + int i; 1063 + u16 reg16; 1064 + struct pci_dev *pdev = ctrl->pci_dev; 1065 + 1066 + if (!pciehp_debug) 1067 + return; 1068 + 1069 + dbg("Hotplug Controller:\n"); 1070 + dbg(" Seg/Bus/Dev/Func/IRQ : %s IRQ %d\n", pci_name(pdev), pdev->irq); 1071 + dbg(" Vendor ID : 0x%04x\n", pdev->vendor); 1072 + dbg(" Device ID : 0x%04x\n", pdev->device); 1073 + dbg(" Subsystem ID : 0x%04x\n", pdev->subsystem_device); 1074 + dbg(" Subsystem Vendor ID : 0x%04x\n", pdev->subsystem_vendor); 1075 + dbg(" PCIe Cap offset : 0x%02x\n", ctrl->cap_base); 1076 + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 1077 + if (!pci_resource_len(pdev, i)) 1078 + continue; 1079 + dbg(" PCI resource [%d] : 0x%llx@0x%llx\n", i, 1080 + (unsigned long long)pci_resource_len(pdev, i), 1081 + (unsigned long long)pci_resource_start(pdev, i)); 1082 + } 1083 + dbg("Slot Capabilities : 0x%08x\n", ctrl->slot_cap); 1084 + dbg(" Physical Slot Number : %d\n", ctrl->first_slot); 1085 + dbg(" Attention Button : %3s\n", ATTN_BUTTN(ctrl) ? "yes" : "no"); 1086 + dbg(" Power Controller : %3s\n", POWER_CTRL(ctrl) ? "yes" : "no"); 1087 + dbg(" MRL Sensor : %3s\n", MRL_SENS(ctrl) ? "yes" : "no"); 1088 + dbg(" Attention Indicator : %3s\n", ATTN_LED(ctrl) ? "yes" : "no"); 1089 + dbg(" Power Indicator : %3s\n", PWR_LED(ctrl) ? "yes" : "no"); 1090 + dbg(" Hot-Plug Surprise : %3s\n", HP_SUPR_RM(ctrl) ? "yes" : "no"); 1091 + dbg(" EMI Present : %3s\n", EMI(ctrl) ? "yes" : "no"); 1092 + pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1093 + dbg("Slot Status : 0x%04x\n", reg16); 1094 + pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1095 + dbg("Slot Control : 0x%04x\n", reg16); 1096 + } 1097 + 1084 1098 int pcie_init(struct controller *ctrl, struct pcie_device *dev) 1085 1099 { 1086 - int rc; 1087 - u16 cap_reg; 1088 1100 u32 slot_cap; 1089 - int cap_base; 1090 - u16 slot_status, slot_ctrl; 1091 - struct pci_dev *pdev; 1101 + struct pci_dev *pdev = dev->port; 1092 1102 1093 - pdev = dev->port; 1094 - ctrl->pci_dev = pdev; /* save pci_dev in context */ 1095 - 1096 - dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n", 1097 - __func__, pdev->vendor, pdev->device); 1098 - 1099 - cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); 1100 - if (cap_base == 0) { 1101 - dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __func__); 1103 + ctrl->pci_dev = pdev; 1104 + ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); 1105 + if (!ctrl->cap_base) { 1106 + err("%s: Cannot find PCI Express capability\n", __func__); 1102 1107 goto abort; 1103 1108 } 1104 - 1105 - ctrl->cap_base = cap_base; 1106 - 1107 - dbg("%s: pcie_cap_base %x\n", __func__, cap_base); 1108 - 1109 - rc = pciehp_readw(ctrl, CAPREG, &cap_reg); 1110 - if (rc) { 1111 - err("%s: Cannot read CAPREG register\n", __func__); 1112 - goto abort; 1113 - } 1114 - dbg("%s: CAPREG offset %x cap_reg %x\n", 1115 - __func__, ctrl->cap_base + CAPREG, cap_reg); 1116 - 1117 - if (((cap_reg & SLOT_IMPL) == 0) || 1118 - (((cap_reg & DEV_PORT_TYPE) != 0x0040) 1119 - && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { 1120 - dbg("%s : This is not a root port or the port is not " 1121 - "connected to a slot\n", __func__); 1122 - goto abort; 1123 - } 1124 - 1125 - rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); 1126 - if (rc) { 1109 + if (pciehp_readl(ctrl, SLOTCAP, &slot_cap)) { 1127 1110 err("%s: Cannot read SLOTCAP register\n", __func__); 1128 1111 goto abort; 1129 1112 } 1130 - dbg("%s: SLOTCAP offset %x slot_cap %x\n", 1131 - __func__, ctrl->cap_base + SLOTCAP, slot_cap); 1132 1113 1133 - if (!(slot_cap & HP_CAP)) { 1134 - dbg("%s : This slot is not hot-plug capable\n", __func__); 1135 - goto abort; 1136 - } 1137 - /* For debugging purpose */ 1138 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1139 - if (rc) { 1140 - err("%s: Cannot read SLOTSTATUS register\n", __func__); 1141 - goto abort; 1142 - } 1143 - dbg("%s: SLOTSTATUS offset %x slot_status %x\n", 1144 - __func__, ctrl->cap_base + SLOTSTATUS, slot_status); 1145 - 1146 - rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 1147 - if (rc) { 1148 - err("%s: Cannot read SLOTCTRL register\n", __func__); 1149 - goto abort; 1150 - } 1151 - dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n", 1152 - __func__, ctrl->cap_base + SLOTCTRL, slot_ctrl); 1153 - 1154 - for (rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++) 1155 - if (pci_resource_len(pdev, rc) > 0) 1156 - dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc, 1157 - (unsigned long long)pci_resource_start(pdev, rc), 1158 - (unsigned long long)pci_resource_len(pdev, rc)); 1114 + ctrl->slot_cap = slot_cap; 1115 + ctrl->first_slot = slot_cap >> 19; 1116 + ctrl->slot_device_offset = 0; 1117 + ctrl->num_slots = 1; 1118 + ctrl->hpc_ops = &pciehp_hpc_ops; 1119 + mutex_init(&ctrl->crit_sect); 1120 + mutex_init(&ctrl->ctrl_lock); 1121 + init_waitqueue_head(&ctrl->queue); 1122 + dbg_ctrl(ctrl); 1159 1123 1160 1124 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", 1161 1125 pdev->vendor, pdev->device, 1162 1126 pdev->subsystem_vendor, pdev->subsystem_device); 1163 1127 1164 - mutex_init(&ctrl->crit_sect); 1165 - mutex_init(&ctrl->ctrl_lock); 1166 - 1167 - /* setup wait queue */ 1168 - init_waitqueue_head(&ctrl->queue); 1169 - 1170 - /* return PCI Controller Info */ 1171 - ctrl->slot_device_offset = 0; 1172 - ctrl->num_slots = 1; 1173 - ctrl->first_slot = slot_cap >> 19; 1174 - ctrl->slot_cap = slot_cap; 1175 - 1176 - rc = pcie_init_hardware_part1(ctrl, dev); 1177 - if (rc) 1128 + if (pcie_init_hardware_part1(ctrl, dev)) 1178 1129 goto abort; 1179 1130 1180 - if (pciehp_poll_mode) { 1181 - /* Install interrupt polling timer. Start with 10 sec delay */ 1182 - init_timer(&ctrl->poll_timer); 1183 - start_int_poll_timer(ctrl, 10); 1184 - } else { 1185 - /* Installs the interrupt handler */ 1186 - rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED, 1187 - MY_NAME, (void *)ctrl); 1188 - dbg("%s: request_irq %d for hpc%d (returns %d)\n", 1189 - __func__, ctrl->pci_dev->irq, 1190 - atomic_read(&pciehp_num_controllers), rc); 1191 - if (rc) { 1192 - err("Can't get irq %d for the hotplug controller\n", 1193 - ctrl->pci_dev->irq); 1194 - goto abort; 1195 - } 1196 - } 1197 - dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number, 1198 - PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq); 1131 + if (pciehp_request_irq(ctrl)) 1132 + goto abort; 1199 1133 1200 1134 /* 1201 1135 * If this is the first controller to be initialized, ··· 1162 1180 if (atomic_add_return(1, &pciehp_num_controllers) == 1) { 1163 1181 pciehp_wq = create_singlethread_workqueue("pciehpd"); 1164 1182 if (!pciehp_wq) { 1165 - rc = -ENOMEM; 1166 1183 goto abort_free_irq; 1167 1184 } 1168 1185 } 1169 1186 1170 - rc = pcie_init_hardware_part2(ctrl, dev); 1171 - if (rc == 0) { 1172 - ctrl->hpc_ops = &pciehp_hpc_ops; 1173 - return 0; 1174 - } 1187 + if (pcie_init_hardware_part2(ctrl, dev)) 1188 + goto abort_free_irq; 1189 + 1190 + return 0; 1191 + 1175 1192 abort_free_irq: 1176 - if (pciehp_poll_mode) 1177 - del_timer_sync(&ctrl->poll_timer); 1178 - else 1179 - free_irq(ctrl->pci_dev->irq, ctrl); 1193 + pciehp_free_irq(ctrl); 1180 1194 abort: 1181 1195 return -1; 1182 1196 }