30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/pci.h>
39 #define SLOT_33MHZ 0x0000001f
40 #define SLOT_66MHZ_PCIX 0x00001f00
41 #define SLOT_100MHZ_PCIX 0x001f0000
42 #define SLOT_133MHZ_PCIX 0x1f000000
45 #define SLOT_66MHZ 0x0000001f
46 #define SLOT_66MHZ_PCIX_266 0x00000f00
47 #define SLOT_100MHZ_PCIX_266 0x0000f000
48 #define SLOT_133MHZ_PCIX_266 0x000f0000
49 #define SLOT_66MHZ_PCIX_533 0x00f00000
50 #define SLOT_100MHZ_PCIX_533 0x0f000000
51 #define SLOT_133MHZ_PCIX_533 0xf0000000
54 #define SLOT_NUM 0x0000001F
55 #define FIRST_DEV_NUM 0x00001F00
56 #define PSN 0x07FF0000
57 #define UPDOWN 0x20000000
58 #define MRLSENSOR 0x40000000
59 #define ATTN_BUTTON 0x80000000
64 #define CMD_INTR_PENDING (1 << 0)
65 #define SLOT_INTR_PENDING(i) (1 << (i + 1))
70 #define GLOBAL_INTR_MASK (1 << 0)
71 #define GLOBAL_SERR_MASK (1 << 1)
72 #define COMMAND_INTR_MASK (1 << 2)
73 #define ARBITER_SERR_MASK (1 << 3)
74 #define COMMAND_DETECTED (1 << 16)
75 #define ARBITER_DETECTED (1 << 17)
76 #define SERR_INTR_RSVDZ_MASK 0xfffc0000
81 #define SLOT_REG(i) (SLOT1 + (4 * i))
83 #define SLOT_STATE_SHIFT (0)
84 #define SLOT_STATE_MASK (3 << 0)
85 #define SLOT_STATE_PWRONLY (1)
86 #define SLOT_STATE_ENABLED (2)
87 #define SLOT_STATE_DISABLED (3)
88 #define PWR_LED_STATE_SHIFT (2)
89 #define PWR_LED_STATE_MASK (3 << 2)
90 #define ATN_LED_STATE_SHIFT (4)
91 #define ATN_LED_STATE_MASK (3 << 4)
92 #define ATN_LED_STATE_ON (1)
93 #define ATN_LED_STATE_BLINK (2)
94 #define ATN_LED_STATE_OFF (3)
95 #define POWER_FAULT (1 << 6)
96 #define ATN_BUTTON (1 << 7)
97 #define MRL_SENSOR (1 << 8)
98 #define MHZ66_CAP (1 << 9)
99 #define PRSNT_SHIFT (10)
100 #define PRSNT_MASK (3 << 10)
101 #define PCIX_CAP_SHIFT (12)
102 #define PCIX_CAP_MASK_PI1 (3 << 12)
103 #define PCIX_CAP_MASK_PI2 (7 << 12)
104 #define PRSNT_CHANGE_DETECTED (1 << 16)
105 #define ISO_PFAULT_DETECTED (1 << 17)
106 #define BUTTON_PRESS_DETECTED (1 << 18)
107 #define MRL_CHANGE_DETECTED (1 << 19)
108 #define CON_PFAULT_DETECTED (1 << 20)
109 #define PRSNT_CHANGE_INTR_MASK (1 << 24)
110 #define ISO_PFAULT_INTR_MASK (1 << 25)
111 #define BUTTON_PRESS_INTR_MASK (1 << 26)
112 #define MRL_CHANGE_INTR_MASK (1 << 27)
113 #define CON_PFAULT_INTR_MASK (1 << 28)
114 #define MRL_CHANGE_SERR_MASK (1 << 29)
115 #define CON_PFAULT_SERR_MASK (1 << 30)
116 #define SLOT_REG_RSVDZ_MASK ((1 << 15) | (7 << 21))
129 #define SET_SLOT_PWR 0x01
130 #define SET_SLOT_ENABLE 0x02
131 #define SET_SLOT_DISABLE 0x03
132 #define SET_PWR_ON 0x04
133 #define SET_PWR_BLINK 0x08
134 #define SET_PWR_OFF 0x0c
135 #define SET_ATTN_ON 0x10
136 #define SET_ATTN_BLINK 0x20
137 #define SET_ATTN_OFF 0x30
138 #define SETA_PCI_33MHZ 0x40
139 #define SETA_PCI_66MHZ 0x41
140 #define SETA_PCIX_66MHZ 0x42
141 #define SETA_PCIX_100MHZ 0x43
142 #define SETA_PCIX_133MHZ 0x44
143 #define SETA_RESERVED1 0x45
144 #define SETA_RESERVED2 0x46
145 #define SETA_RESERVED3 0x47
146 #define SET_PWR_ONLY_ALL 0x48
147 #define SET_ENABLE_ALL 0x49
148 #define SETB_PCI_33MHZ 0x50
149 #define SETB_PCI_66MHZ 0x51
150 #define SETB_PCIX_66MHZ_PM 0x52
151 #define SETB_PCIX_100MHZ_PM 0x53
152 #define SETB_PCIX_133MHZ_PM 0x54
153 #define SETB_PCIX_66MHZ_EM 0x55
154 #define SETB_PCIX_100MHZ_EM 0x56
155 #define SETB_PCIX_133MHZ_EM 0x57
156 #define SETB_PCIX_66MHZ_266 0x58
157 #define SETB_PCIX_100MHZ_266 0x59
158 #define SETB_PCIX_133MHZ_266 0x5a
159 #define SETB_PCIX_66MHZ_533 0x5b
160 #define SETB_PCIX_100MHZ_533 0x5c
161 #define SETB_PCIX_133MHZ_533 0x5d
162 #define SETB_RESERVED1 0x5e
163 #define SETB_RESERVED2 0x5f
168 #define SWITCH_OPEN 0x1
169 #define INVALID_CMD 0x2
170 #define INVALID_SPEED_MODE 0x4
175 #define DWORD_SELECT 0x2
176 #define DWORD_DATA 0x4
179 #define SLOT_EVENT_LATCH 0x2
180 #define SLOT_SERR_INT_MASK 0x3
223 rc = pci_write_config_byte(pdev, cap_offset +
DWORD_SELECT, index);
226 return pci_read_config_dword(pdev, cap_offset +
DWORD_DATA, value);
232 static void int_poll_timeout(
unsigned long data)
249 static void start_int_poll_timer(
struct controller *ctrl,
int sec)
252 if ((sec <= 0) || (sec > 60))
255 ctrl->
poll_timer.function = &int_poll_timeout;
261 static inline int is_ctrl_busy(
struct controller *ctrl)
264 return cmd_status & 0x1;
271 static inline int shpc_poll_ctrl_busy(
struct controller *ctrl)
275 if (!is_ctrl_busy(ctrl))
279 for (i = 0; i < 10; i++) {
281 if (!is_ctrl_busy(ctrl))
288 static inline int shpc_wait_cmd(
struct controller *ctrl)
295 rc = shpc_poll_ctrl_busy(ctrl);
298 !is_ctrl_busy(ctrl), timeout);
299 if (!rc && is_ctrl_busy(ctrl)) {
301 ctrl_err(ctrl,
"Command not completed in 1000 msec\n");
304 ctrl_info(ctrl,
"Command was interrupted by a signal\n");
319 if (!shpc_poll_ctrl_busy(ctrl)) {
321 ctrl_err(ctrl,
"Controller is still busy after 1 sec\n");
327 temp_word = (t_slot << 8) | (cmd & 0xFF);
328 ctrl_dbg(ctrl,
"%s: t_slot %x cmd %x\n", __func__, t_slot, cmd);
333 shpc_writew(ctrl,
CMD, temp_word);
338 retval = shpc_wait_cmd(slot->
ctrl);
342 cmd_status = hpc_check_cmd_status(slot->
ctrl);
345 "Failed to issued command 0x%x (error code = %d)\n",
354 static int hpc_check_cmd_status(
struct controller *ctrl)
359 switch (cmd_status >> 1) {
369 ctrl_err(ctrl,
"Invalid HPC command!\n");
373 ctrl_err(ctrl,
"Invalid bus speed/mode!\n");
383 static int hpc_get_attention_status(
struct slot *slot,
u8 *
status)
407 static int hpc_get_power_status(
struct slot * slot,
u8 *status)
432 static int hpc_get_latch_status(
struct slot *slot,
u8 *status)
442 static int hpc_get_adapter_status(
struct slot *slot,
u8 *status)
448 *status = (state != 0x3) ? 1 : 0;
453 static int hpc_get_prog_int(
struct slot *slot,
u8 *prog_int)
462 static int hpc_get_adapter_speed(
struct slot *slot,
enum pci_bus_speed *value)
470 if ((retval = hpc_get_prog_int(slot, &pi)))
484 ctrl_dbg(ctrl,
"%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
485 __func__, slot_reg, pcix_cap, m66_cap);
510 ctrl_dbg(ctrl,
"Adapter speed = %d\n", *value);
514 static int hpc_get_mode1_ECC_cap(
struct slot *slot,
u8 *
mode)
522 *mode = (sec_bus_status & 0x0100) >> 8;
527 ctrl_dbg(ctrl,
"Mode 1 ECC cap = %d\n", *mode);
531 static int hpc_query_power_fault(
struct slot * slot)
540 static int hpc_set_attention_status(
struct slot *slot,
u8 value)
558 return shpc_write_cmd(slot, slot->
hp_slot, slot_cmd);
562 static void hpc_set_green_led_on(
struct slot *slot)
567 static void hpc_set_green_led_off(
struct slot *slot)
572 static void hpc_set_green_led_blink(
struct slot *slot)
577 static void hpc_release_ctlr(
struct controller *ctrl)
580 u32 slot_reg, serr_int;
586 slot_reg = shpc_readl(ctrl,
SLOT_REG(i));
592 shpc_writel(ctrl,
SLOT_REG(i), slot_reg);
617 static int hpc_power_on_slot(
struct slot * slot)
623 ctrl_err(slot->
ctrl,
"%s: Write command failed!\n", __func__);
628 static int hpc_slot_enable(
struct slot * slot)
633 retval = shpc_write_cmd(slot, slot->
hp_slot,
636 ctrl_err(slot->
ctrl,
"%s: Write command failed!\n", __func__);
641 static int hpc_slot_disable(
struct slot * slot)
646 retval = shpc_write_cmd(slot, slot->
hp_slot,
649 ctrl_err(slot->
ctrl,
"%s: Write command failed!\n", __func__);
654 static int shpc_get_cur_bus_speed(
struct controller *ctrl)
661 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
663 if ((pi == 1) && (speed_mode > 4)) {
668 switch (speed_mode) {
718 dbg(
"Current bus speed = %d\n", bus_speed);
723 static int hpc_set_bus_speed_mode(
struct slot * slot,
enum pci_bus_speed value)
780 retval = shpc_write_cmd(slot, 0, cmd);
782 ctrl_err(ctrl,
"%s: Write command failed!\n", __func__);
784 shpc_get_cur_bus_speed(ctrl);
796 intr_loc = shpc_readl(ctrl,
INTR_LOC);
800 ctrl_dbg(ctrl,
"%s: intr_loc = %x\n", __func__, intr_loc);
812 intr_loc2 = shpc_readl(ctrl,
INTR_LOC);
813 ctrl_dbg(ctrl,
"%s: intr_loc2 = %x\n", __func__, intr_loc2);
829 if (!(intr_loc & ~CMD_INTR_PENDING))
832 for (hp_slot = 0; hp_slot < ctrl->
num_slots; hp_slot++) {
837 slot_reg = shpc_readl(ctrl,
SLOT_REG(hp_slot));
838 ctrl_dbg(ctrl,
"Slot %x with intr, slot register = %x\n",
855 shpc_writel(ctrl,
SLOT_REG(hp_slot), slot_reg);
868 static int shpc_get_max_bus_speed(
struct controller *ctrl)
908 ctrl_dbg(ctrl,
"Max bus speed = %d\n", bus_speed);
913 static struct hpc_ops shpchp_hpc_ops = {
914 .power_on_slot = hpc_power_on_slot,
915 .slot_enable = hpc_slot_enable,
916 .slot_disable = hpc_slot_disable,
917 .set_bus_speed_mode = hpc_set_bus_speed_mode,
918 .set_attention_status = hpc_set_attention_status,
919 .get_power_status = hpc_get_power_status,
920 .get_attention_status = hpc_get_attention_status,
921 .get_latch_status = hpc_get_latch_status,
922 .get_adapter_status = hpc_get_adapter_status,
924 .get_adapter_speed = hpc_get_adapter_speed,
925 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
926 .get_prog_int = hpc_get_prog_int,
928 .query_power_fault = hpc_query_power_fault,
929 .green_led_on = hpc_set_green_led_on,
930 .green_led_off = hpc_set_green_led_off,
931 .green_led_blink = hpc_set_green_led_blink,
933 .release_ctlr = hpc_release_ctlr,
940 u32 shpc_base_offset;
945 ctrl_dbg(ctrl,
"Hotplug Controller:\n");
955 ctrl_err(ctrl,
"Cannot find PCI capability\n");
960 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
962 ctrl_err(ctrl,
"Cannot read base_offset\n");
966 rc = shpc_indirect_read(ctrl, 3, &tempdword);
968 ctrl_err(ctrl,
"Cannot read slot config\n");
975 rc = shpc_indirect_read(ctrl, i, &tempdword);
978 "Cannot read creg (index = %d)\n", i);
981 ctrl_dbg(ctrl,
" offset %d: value %x\n", i, tempdword);
989 ctrl_info(ctrl,
"HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
995 ctrl_err(ctrl,
"pci_enable_device failed\n");
1000 ctrl_err(ctrl,
"Cannot reserve MMIO region\n");
1007 ctrl_err(ctrl,
"Cannot remap MMIO region %lx @ %lx\n",
1021 ctrl->
hpc_ops = &shpchp_hpc_ops;
1032 ctrl_dbg(ctrl,
"SERR_INTR_ENABLE = %x\n", tempdword);
1038 ctrl_dbg(ctrl,
"SERR_INTR_ENABLE = %x\n", tempdword);
1043 for (hp_slot = 0; hp_slot < ctrl->
num_slots; hp_slot++) {
1044 slot_reg = shpc_readl(ctrl,
SLOT_REG(hp_slot));
1045 ctrl_dbg(ctrl,
"Default Logical Slot Register %d value %x\n",
1052 shpc_writel(ctrl,
SLOT_REG(hp_slot), slot_reg);
1058 start_int_poll_timer(ctrl, 10);
1061 rc = pci_enable_msi(pdev);
1064 "Can't get msi for the hotplug controller\n");
1066 "Use INTx for the hotplug controller\n");
1071 ctrl_dbg(ctrl,
"request_irq %d (returns %d)\n",
1074 ctrl_err(ctrl,
"Can't get irq %d for the hotplug "
1075 "controller\n", ctrl->
pci_dev->irq);
1079 ctrl_dbg(ctrl,
"HPC at %s irq=%x\n", pci_name(pdev), pdev->
irq);
1081 shpc_get_max_bus_speed(ctrl);
1082 shpc_get_cur_bus_speed(ctrl);
1087 for (hp_slot = 0; hp_slot < ctrl->
num_slots; hp_slot++) {
1088 slot_reg = shpc_readl(ctrl,
SLOT_REG(hp_slot));
1089 ctrl_dbg(ctrl,
"Default Logical Slot Register %d value %x\n",
1094 shpc_writel(ctrl,
SLOT_REG(hp_slot), slot_reg);
1103 ctrl_dbg(ctrl,
"SERR_INTR_ENABLE = %x\n", tempdword);