📄 shpchp_ctrl.c
字号:
if (next == bridge) { shpchp_slot_list[bridge->bus] = bridge->next; kfree(bridge); return(0); } while ((next->next != bridge) && (next->next != NULL)) { next = next->next; } if (next->next == bridge) { next->next = bridge->next; kfree(bridge); return(0); } else return(2);}/** * shpchp_slot_find - Looks for a node by bus, and device, multiple functions accessed * @bus: bus to find * @device: device to find * @index: is 0 for first function found, 1 for the second... * * Returns pointer to the node if successful, %NULL otherwise. */struct pci_func *shpchp_slot_find(u8 bus, u8 device, u8 index){ int found = -1; struct pci_func *func; func = shpchp_slot_list[bus]; if ((func == NULL) || ((func->device == device) && (index == 0))) return(func); if (func->device == device) found++; while (func->next != NULL) { func = func->next; if (func->device == device) found++; if (found == index) return(func); } return(NULL);}static int is_bridge(struct pci_func * func){ /* Check the header type */ if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01) return 1; else return 0;}/* The following routines constitute the bulk of the hotplug controller logic *//** * board_added - Called after a board has been added to the system. * * Turns power on for the board * Configures board * */static u32 board_added(struct pci_func * func, struct controller * ctrl){ u8 hp_slot, slot; u8 slots_not_empty = 0; int index; u32 temp_register = 0xFFFFFFFF; u32 retval, rc = 0; struct pci_func *new_func = NULL; struct pci_func *t_func = NULL; struct slot *p_slot, *pslot; struct resource_lists res_lists; enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed; u8 pi, mode; p_slot = shpchp_find_slot(ctrl, func->device); hp_slot = func->device - ctrl->slot_device_offset; dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot); /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); /* Power on slot without connecting to bus */ rc = p_slot->hpc_ops->power_on_slot(p_slot); if (rc) { err("%s: Failed to power on slot\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return -1; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Failed to power on slot, error code(%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return -1; } rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed); /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */ /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */ /* 0xd = PCI-X 133 Mhz 533 */ /* This encoding is different from the one used in cur_bus_speed & */ /* max_bus_speed */ if (rc || adapter_speed == PCI_SPEED_UNKNOWN) { err("%s: Can't get adapter speed or bus mode mismatch\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bus_speed); if (rc || bus_speed == PCI_SPEED_UNKNOWN) { err("%s: Can't get bus operation speed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed); if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) { err("%s: Can't get max bus operation speed\n", __FUNCTION__); max_bus_speed = bus_speed; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi); if (rc) { err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__); pi = 1; } if (pi == 2) { for ( slot = 0; slot < ctrl->num_slots; slot++) { if (slot != hp_slot) { pslot = shpchp_find_slot(ctrl, slot + ctrl->slot_device_offset); t_func = shpchp_slot_find(pslot->bus, pslot->device, 0); slots_not_empty |= t_func->is_a_board; } } switch (adapter_speed) { case PCI_SPEED_133MHz_PCIX_533: case PCI_SPEED_133MHz_PCIX_266: if ((( bus_speed < 0xa ) || (bus_speed < 0xd)) && (max_bus_speed > bus_speed) && ((max_bus_speed <= 0xa) || (max_bus_speed <= 0xd)) && (!slots_not_empty)) { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } break; case PCI_SPEED_133MHz_PCIX_ECC: case PCI_SPEED_133MHz_PCIX: rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode); if (rc) { err("%s: PI is 1 \n", __FUNCTION__); return WRONG_BUS_FREQUENCY; } if (mode) { /* Bus - Mode 1 ECC */ if (bus_speed > 0x7) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } if ((bus_speed < 0x7) && (max_bus_speed <= 0x7) && (bus_speed < max_bus_speed) && (!slots_not_empty)) { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } } else { if (bus_speed > 0x4) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } if ((bus_speed < 0x4) && (max_bus_speed <= 0x4) && (bus_speed < max_bus_speed) && (!slots_not_empty)) { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } } break; case PCI_SPEED_66MHz_PCIX_ECC: case PCI_SPEED_66MHz_PCIX: rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode); if (rc) { err("%s: PI is 1 \n", __FUNCTION__); return WRONG_BUS_FREQUENCY; } if (mode) { /* Bus - Mode 1 ECC */ if (bus_speed > 0x5) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } if ((bus_speed < 0x5) && (max_bus_speed <= 0x5) && (bus_speed < max_bus_speed) && (!slots_not_empty)) { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } } else { if (bus_speed > 0x2) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } if ((bus_speed < 0x2) && (max_bus_speed <= 0x2) && (bus_speed < max_bus_speed) && (!slots_not_empty)) { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } } break; case PCI_SPEED_66MHz: if (bus_speed > 0x1) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } if (bus_speed == 0x1) ; if ((bus_speed == 0x0) && ( max_bus_speed == 0x1)) { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } break; case PCI_SPEED_33MHz: if (bus_speed > 0x0) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } break; default: err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } } else { /* if adpater_speed == bus_speed, nothing to do here */ if (adapter_speed != bus_speed) { for ( slot = 0; slot < ctrl->num_slots; slot++) { if (slot != hp_slot) { pslot = shpchp_find_slot(ctrl, slot + ctrl->slot_device_offset); t_func = shpchp_slot_find(pslot->bus, pslot->device, 0); slots_not_empty |= t_func->is_a_board; } } if (slots_not_empty != 0) { /* Other slots on the same bus are occupied */ if ( adapter_speed < bus_speed ) { err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); return WRONG_BUS_FREQUENCY; } /* Do nothing if adapter_speed >= bus_speed */ } } if ((adapter_speed != bus_speed) && (slots_not_empty == 0)) { /* Other slots on the same bus are empty */ rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed); if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) { err("%s: Can't get max bus operation speed\n", __FUNCTION__); max_bus_speed = bus_speed; } if (max_bus_speed == bus_speed) { /* if adapter_speed >= bus_speed, do nothing */ if (adapter_speed < bus_speed) { /* * Try to lower bus speed to accommodate the adapter if other slots * on the same controller are empty */ /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, adapter_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc); up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } } else { /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); /* max_bus_speed != bus_speed. Note: max_bus_speed should be > than bus_speed */ if (adapter_speed < max_bus_speed) rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, adapter_speed); else rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, max_bus_speed); if (rc) { err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); /* Done with exclusive hardware access */ up(&ctrl->crit_sect); return WRONG_BUS_FREQUENCY; } /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); rc = p_slot->hpc_ops->check_cmd_status(ctrl); if (rc) { err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", __FUNCTION__); err("%s: Error code (%d)\n", __FUNCTION__, rc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -