aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorAlex Chiang <achiang@hp.com>2009-03-31 11:23:36 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-06-11 15:04:11 -0400
commit867556fe740d0d29a05fce99d2d960625077ed45 (patch)
tree7e8887ec31f59ea43c147e31290281640947f35c /drivers/pci
parent04225fe7e6877493765b9cfa3092524e21e020d7 (diff)
PCI Hotplug: cpqphp: refactor cpqhp_probe
Apply DeMorgan's theorem: if ((pdev->revision > 2) || (vendor_id == PCI_VENDOR_ID_INTEL)) turns into if ((pdev->revision <= 2) && (vendor_id != PCI_VENDOR_ID_INTEL)) Now we can bail out early from the function if the controller is not supported. This allows us to un-indent the remainder of the function quite a bit and make it much more readable. Fix up some extra braces, and un-indent the 'case' labels in the switch statement as per CodingStyle. No functional change. Signed-off-by: Alex Chiang <achiang@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c382
1 files changed, 185 insertions, 197 deletions
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 195c8c9b33e0..857e466df71d 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -887,214 +887,202 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
887 * For Intel, each SSID bit identifies a PHP capability. 887 * For Intel, each SSID bit identifies a PHP capability.
888 * Also Intel HPC's may have RID=0. 888 * Also Intel HPC's may have RID=0.
889 */ 889 */
890 if ((pdev->revision > 2) || (vendor_id == PCI_VENDOR_ID_INTEL)) { 890 if ((pdev->revision <= 2) && (vendor_id != PCI_VENDOR_ID_INTEL)) {
891 /* TODO: This code can be made to support non-Compaq or Intel 891 err(msg_HPC_not_supported);
892 * subsystem IDs 892 return -ENODEV;
893 */ 893 }
894 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid); 894
895 if (rc) { 895 /* TODO: This code can be made to support non-Compaq or Intel
896 err("%s : pci_read_config_word failed\n", __func__); 896 * subsystem IDs
897 goto err_disable_device; 897 */
898 } 898 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid);
899 dbg("Subsystem Vendor ID: %x\n", subsystem_vid); 899 if (rc) {
900 if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) { 900 err("%s : pci_read_config_word failed\n", __func__);
901 err(msg_HPC_non_compaq_or_intel); 901 goto err_disable_device;
902 rc = -ENODEV; 902 }
903 goto err_disable_device; 903 dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
904 } 904 if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
905 err(msg_HPC_non_compaq_or_intel);
906 rc = -ENODEV;
907 goto err_disable_device;
908 }
909
910 ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
911 if (!ctrl) {
912 err("%s : out of memory\n", __func__);
913 rc = -ENOMEM;
914 goto err_disable_device;
915 }
905 916
906 ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL); 917 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
907 if (!ctrl) { 918 if (rc) {
908 err("%s : out of memory\n", __func__); 919 err("%s : pci_read_config_word failed\n", __func__);
909 rc = -ENOMEM; 920 goto err_free_ctrl;
910 goto err_disable_device; 921 }
922
923 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
924
925 /* Set Vendor ID, so it can be accessed later from other
926 * functions
927 */
928 ctrl->vendor_id = vendor_id;
929
930 switch (subsystem_vid) {
931 case PCI_VENDOR_ID_COMPAQ:
932 if (pdev->revision >= 0x13) { /* CIOBX */
933 ctrl->push_flag = 1;
934 ctrl->slot_switch_type = 1;
935 ctrl->push_button = 1;
936 ctrl->pci_config_space = 1;
937 ctrl->defeature_PHP = 1;
938 ctrl->pcix_support = 1;
939 ctrl->pcix_speed_capability = 1;
940 pci_read_config_byte(pdev, 0x41, &bus_cap);
941 if (bus_cap & 0x80) {
942 dbg("bus max supports 133MHz PCI-X\n");
943 ctrl->speed_capability = PCI_SPEED_133MHz_PCIX;
944 break;
945 }
946 if (bus_cap & 0x40) {
947 dbg("bus max supports 100MHz PCI-X\n");
948 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
949 break;
950 }
951 if (bus_cap & 20) {
952 dbg("bus max supports 66MHz PCI-X\n");
953 ctrl->speed_capability = PCI_SPEED_66MHz_PCIX;
954 break;
955 }
956 if (bus_cap & 10) {
957 dbg("bus max supports 66MHz PCI\n");
958 ctrl->speed_capability = PCI_SPEED_66MHz;
959 break;
960 }
961
962 break;
911 } 963 }
912 964
913 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid); 965 switch (subsystem_deviceid) {
914 if (rc) { 966 case PCI_SUB_HPC_ID:
915 err("%s : pci_read_config_word failed\n", __func__); 967 /* Original 6500/7000 implementation */
968 ctrl->slot_switch_type = 1;
969 ctrl->speed_capability = PCI_SPEED_33MHz;
970 ctrl->push_button = 0;
971 ctrl->pci_config_space = 1;
972 ctrl->defeature_PHP = 1;
973 ctrl->pcix_support = 0;
974 ctrl->pcix_speed_capability = 0;
975 break;
976 case PCI_SUB_HPC_ID2:
977 /* First Pushbutton implementation */
978 ctrl->push_flag = 1;
979 ctrl->slot_switch_type = 1;
980 ctrl->speed_capability = PCI_SPEED_33MHz;
981 ctrl->push_button = 1;
982 ctrl->pci_config_space = 1;
983 ctrl->defeature_PHP = 1;
984 ctrl->pcix_support = 0;
985 ctrl->pcix_speed_capability = 0;
986 break;
987 case PCI_SUB_HPC_ID_INTC:
988 /* Third party (6500/7000) */
989 ctrl->slot_switch_type = 1;
990 ctrl->speed_capability = PCI_SPEED_33MHz;
991 ctrl->push_button = 0;
992 ctrl->pci_config_space = 1;
993 ctrl->defeature_PHP = 1;
994 ctrl->pcix_support = 0;
995 ctrl->pcix_speed_capability = 0;
996 break;
997 case PCI_SUB_HPC_ID3:
998 /* First 66 Mhz implementation */
999 ctrl->push_flag = 1;
1000 ctrl->slot_switch_type = 1;
1001 ctrl->speed_capability = PCI_SPEED_66MHz;
1002 ctrl->push_button = 1;
1003 ctrl->pci_config_space = 1;
1004 ctrl->defeature_PHP = 1;
1005 ctrl->pcix_support = 0;
1006 ctrl->pcix_speed_capability = 0;
1007 break;
1008 case PCI_SUB_HPC_ID4:
1009 /* First PCI-X implementation, 100MHz */
1010 ctrl->push_flag = 1;
1011 ctrl->slot_switch_type = 1;
1012 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
1013 ctrl->push_button = 1;
1014 ctrl->pci_config_space = 1;
1015 ctrl->defeature_PHP = 1;
1016 ctrl->pcix_support = 1;
1017 ctrl->pcix_speed_capability = 0;
1018 break;
1019 default:
1020 err(msg_HPC_not_supported);
1021 rc = -ENODEV;
916 goto err_free_ctrl; 1022 goto err_free_ctrl;
917 } 1023 }
1024 break;
918 1025
919 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid); 1026 case PCI_VENDOR_ID_INTEL:
1027 /* Check for speed capability (0=33, 1=66) */
1028 if (subsystem_deviceid & 0x0001)
1029 ctrl->speed_capability = PCI_SPEED_66MHz;
1030 else
1031 ctrl->speed_capability = PCI_SPEED_33MHz;
920 1032
921 /* Set Vendor ID, so it can be accessed later from other 1033 /* Check for push button */
922 * functions 1034 if (subsystem_deviceid & 0x0002)
923 */ 1035 ctrl->push_button = 0;
924 ctrl->vendor_id = vendor_id; 1036 else
925 1037 ctrl->push_button = 1;
926 switch (subsystem_vid) {
927 case PCI_VENDOR_ID_COMPAQ:
928 if (pdev->revision >= 0x13) { /* CIOBX */
929 ctrl->push_flag = 1;
930 ctrl->slot_switch_type = 1;
931 ctrl->push_button = 1;
932 ctrl->pci_config_space = 1;
933 ctrl->defeature_PHP = 1;
934 ctrl->pcix_support = 1;
935 ctrl->pcix_speed_capability = 1;
936 pci_read_config_byte(pdev, 0x41, &bus_cap);
937 if (bus_cap & 0x80) {
938 dbg("bus max supports 133MHz PCI-X\n");
939 ctrl->speed_capability = PCI_SPEED_133MHz_PCIX;
940 break;
941 }
942 if (bus_cap & 0x40) {
943 dbg("bus max supports 100MHz PCI-X\n");
944 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
945 break;
946 }
947 if (bus_cap & 20) {
948 dbg("bus max supports 66MHz PCI-X\n");
949 ctrl->speed_capability = PCI_SPEED_66MHz_PCIX;
950 break;
951 }
952 if (bus_cap & 10) {
953 dbg("bus max supports 66MHz PCI\n");
954 ctrl->speed_capability = PCI_SPEED_66MHz;
955 break;
956 }
957
958 break;
959 }
960
961 switch (subsystem_deviceid) {
962 case PCI_SUB_HPC_ID:
963 /* Original 6500/7000 implementation */
964 ctrl->slot_switch_type = 1;
965 ctrl->speed_capability = PCI_SPEED_33MHz;
966 ctrl->push_button = 0;
967 ctrl->pci_config_space = 1;
968 ctrl->defeature_PHP = 1;
969 ctrl->pcix_support = 0;
970 ctrl->pcix_speed_capability = 0;
971 break;
972 case PCI_SUB_HPC_ID2:
973 /* First Pushbutton implementation */
974 ctrl->push_flag = 1;
975 ctrl->slot_switch_type = 1;
976 ctrl->speed_capability = PCI_SPEED_33MHz;
977 ctrl->push_button = 1;
978 ctrl->pci_config_space = 1;
979 ctrl->defeature_PHP = 1;
980 ctrl->pcix_support = 0;
981 ctrl->pcix_speed_capability = 0;
982 break;
983 case PCI_SUB_HPC_ID_INTC:
984 /* Third party (6500/7000) */
985 ctrl->slot_switch_type = 1;
986 ctrl->speed_capability = PCI_SPEED_33MHz;
987 ctrl->push_button = 0;
988 ctrl->pci_config_space = 1;
989 ctrl->defeature_PHP = 1;
990 ctrl->pcix_support = 0;
991 ctrl->pcix_speed_capability = 0;
992 break;
993 case PCI_SUB_HPC_ID3:
994 /* First 66 Mhz implementation */
995 ctrl->push_flag = 1;
996 ctrl->slot_switch_type = 1;
997 ctrl->speed_capability = PCI_SPEED_66MHz;
998 ctrl->push_button = 1;
999 ctrl->pci_config_space = 1;
1000 ctrl->defeature_PHP = 1;
1001 ctrl->pcix_support = 0;
1002 ctrl->pcix_speed_capability = 0;
1003 break;
1004 case PCI_SUB_HPC_ID4:
1005 /* First PCI-X implementation, 100MHz */
1006 ctrl->push_flag = 1;
1007 ctrl->slot_switch_type = 1;
1008 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
1009 ctrl->push_button = 1;
1010 ctrl->pci_config_space = 1;
1011 ctrl->defeature_PHP = 1;
1012 ctrl->pcix_support = 1;
1013 ctrl->pcix_speed_capability = 0;
1014 break;
1015 default:
1016 err(msg_HPC_not_supported);
1017 rc = -ENODEV;
1018 goto err_free_ctrl;
1019 }
1020 break;
1021 1038
1022 case PCI_VENDOR_ID_INTEL: 1039 /* Check for slot switch type (0=mechanical, 1=not mechanical) */
1023 /* Check for speed capability (0=33, 1=66) */ 1040 if (subsystem_deviceid & 0x0004)
1024 if (subsystem_deviceid & 0x0001) { 1041 ctrl->slot_switch_type = 0;
1025 ctrl->speed_capability = PCI_SPEED_66MHz; 1042 else
1026 } else { 1043 ctrl->slot_switch_type = 1;
1027 ctrl->speed_capability = PCI_SPEED_33MHz; 1044
1028 } 1045 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
1029 1046 if (subsystem_deviceid & 0x0008)
1030 /* Check for push button */ 1047 ctrl->defeature_PHP = 1; /* PHP supported */
1031 if (subsystem_deviceid & 0x0002) { 1048 else
1032 /* no push button */ 1049 ctrl->defeature_PHP = 0; /* PHP not supported */
1033 ctrl->push_button = 0; 1050
1034 } else { 1051 /* Alternate Base Address Register Interface
1035 /* push button supported */ 1052 * (0=not supported, 1=supported)
1036 ctrl->push_button = 1; 1053 */
1037 } 1054 if (subsystem_deviceid & 0x0010)
1038 1055 ctrl->alternate_base_address = 1;
1039 /* Check for slot switch type (0=mechanical, 1=not mechanical) */ 1056 else
1040 if (subsystem_deviceid & 0x0004) { 1057 ctrl->alternate_base_address = 0;
1041 /* no switch */
1042 ctrl->slot_switch_type = 0;
1043 } else {
1044 /* switch */
1045 ctrl->slot_switch_type = 1;
1046 }
1047
1048 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
1049 if (subsystem_deviceid & 0x0008) {
1050 ctrl->defeature_PHP = 1; /* PHP supported */
1051 } else {
1052 ctrl->defeature_PHP = 0; /* PHP not supported */
1053 }
1054
1055 /* Alternate Base Address Register Interface (0=not supported, 1=supported) */
1056 if (subsystem_deviceid & 0x0010) {
1057 ctrl->alternate_base_address = 1; /* supported */
1058 } else {
1059 ctrl->alternate_base_address = 0; /* not supported */
1060 }
1061
1062 /* PCI Config Space Index (0=not supported, 1=supported) */
1063 if (subsystem_deviceid & 0x0020) {
1064 ctrl->pci_config_space = 1; /* supported */
1065 } else {
1066 ctrl->pci_config_space = 0; /* not supported */
1067 }
1068
1069 /* PCI-X support */
1070 if (subsystem_deviceid & 0x0080) {
1071 /* PCI-X capable */
1072 ctrl->pcix_support = 1;
1073 /* Frequency of operation in PCI-X mode */
1074 if (subsystem_deviceid & 0x0040) {
1075 /* 133MHz PCI-X if bit 7 is 1 */
1076 ctrl->pcix_speed_capability = 1;
1077 } else {
1078 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
1079 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
1080 ctrl->pcix_speed_capability = 0;
1081 }
1082 } else {
1083 /* Conventional PCI */
1084 ctrl->pcix_support = 0;
1085 ctrl->pcix_speed_capability = 0;
1086 }
1087 break;
1088 1058
1089 default: 1059 /* PCI Config Space Index (0=not supported, 1=supported) */
1090 err(msg_HPC_not_supported); 1060 if (subsystem_deviceid & 0x0020)
1091 rc = -ENODEV; 1061 ctrl->pci_config_space = 1;
1092 goto err_free_ctrl; 1062 else
1063 ctrl->pci_config_space = 0;
1064
1065 /* PCI-X support */
1066 if (subsystem_deviceid & 0x0080) {
1067 ctrl->pcix_support = 1;
1068 if (subsystem_deviceid & 0x0040)
1069 /* 133MHz PCI-X if bit 7 is 1 */
1070 ctrl->pcix_speed_capability = 1;
1071 else
1072 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
1073 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
1074 ctrl->pcix_speed_capability = 0;
1075 } else {
1076 /* Conventional PCI */
1077 ctrl->pcix_support = 0;
1078 ctrl->pcix_speed_capability = 0;
1093 } 1079 }
1080 break;
1094 1081
1095 } else { 1082 default:
1096 err(msg_HPC_not_supported); 1083 err(msg_HPC_not_supported);
1097 return -ENODEV; 1084 rc = -ENODEV;
1085 goto err_free_ctrl;
1098 } 1086 }
1099 1087
1100 /* Tell the user that we found one. */ 1088 /* Tell the user that we found one. */
@@ -1164,7 +1152,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1164 goto err_free_mem_region; 1152 goto err_free_mem_region;
1165 } 1153 }
1166 1154
1167 // Check for 66Mhz operation 1155 /* Check for 66Mhz operation */
1168 ctrl->speed = get_controller_speed(ctrl); 1156 ctrl->speed = get_controller_speed(ctrl);
1169 1157
1170 1158