Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PCI Express PCI Hot Plug Driver |
| 3 | * |
| 4 | * Copyright (C) 1995,2001 Compaq Computer Corporation |
| 5 | * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) |
| 6 | * Copyright (C) 2001 IBM Corp. |
| 7 | * Copyright (C) 2003-2004 Intel Corporation |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 19 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 20 | * details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
Kristen Accardi | 8cf4c19 | 2005-08-16 15:16:10 -0700 | [diff] [blame] | 26 | * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/types.h> |
Tim Schmielau | de25968 | 2006-01-08 01:02:05 -0800 | [diff] [blame] | 33 | #include <linux/signal.h> |
| 34 | #include <linux/jiffies.h> |
| 35 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/pci.h> |
Andrew Morton | 5d1b8c9 | 2005-11-13 16:06:39 -0800 | [diff] [blame] | 37 | #include <linux/interrupt.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "../pci.h" |
| 40 | #include "pciehp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #ifdef DEBUG |
| 42 | #define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */ |
| 43 | #define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */ |
| 44 | #define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */ |
| 45 | #define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */ |
| 46 | #define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT) |
| 47 | #define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE) |
| 48 | /* Redefine this flagword to set debug level */ |
| 49 | #define DEBUG_LEVEL DBG_K_STANDARD |
| 50 | |
| 51 | #define DEFINE_DBG_BUFFER char __dbg_str_buf[256]; |
| 52 | |
| 53 | #define DBG_PRINT( dbg_flags, args... ) \ |
| 54 | do { \ |
| 55 | if ( DEBUG_LEVEL & ( dbg_flags ) ) \ |
| 56 | { \ |
| 57 | int len; \ |
| 58 | len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \ |
| 59 | __FILE__, __LINE__, __FUNCTION__ ); \ |
| 60 | sprintf( __dbg_str_buf + len, args ); \ |
| 61 | printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \ |
| 62 | } \ |
| 63 | } while (0) |
| 64 | |
| 65 | #define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]"); |
| 66 | #define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]"); |
| 67 | #else |
| 68 | #define DEFINE_DBG_BUFFER |
| 69 | #define DBG_ENTER_ROUTINE |
| 70 | #define DBG_LEAVE_ROUTINE |
| 71 | #endif /* DEBUG */ |
| 72 | |
| 73 | struct ctrl_reg { |
| 74 | u8 cap_id; |
| 75 | u8 nxt_ptr; |
| 76 | u16 cap_reg; |
| 77 | u32 dev_cap; |
| 78 | u16 dev_ctrl; |
| 79 | u16 dev_status; |
| 80 | u32 lnk_cap; |
| 81 | u16 lnk_ctrl; |
| 82 | u16 lnk_status; |
| 83 | u32 slot_cap; |
| 84 | u16 slot_ctrl; |
| 85 | u16 slot_status; |
| 86 | u16 root_ctrl; |
| 87 | u16 rsvp; |
| 88 | u32 root_status; |
| 89 | } __attribute__ ((packed)); |
| 90 | |
| 91 | /* offsets to the controller registers based on the above structure layout */ |
| 92 | enum ctrl_offsets { |
| 93 | PCIECAPID = offsetof(struct ctrl_reg, cap_id), |
| 94 | NXTCAPPTR = offsetof(struct ctrl_reg, nxt_ptr), |
| 95 | CAPREG = offsetof(struct ctrl_reg, cap_reg), |
| 96 | DEVCAP = offsetof(struct ctrl_reg, dev_cap), |
| 97 | DEVCTRL = offsetof(struct ctrl_reg, dev_ctrl), |
| 98 | DEVSTATUS = offsetof(struct ctrl_reg, dev_status), |
| 99 | LNKCAP = offsetof(struct ctrl_reg, lnk_cap), |
| 100 | LNKCTRL = offsetof(struct ctrl_reg, lnk_ctrl), |
| 101 | LNKSTATUS = offsetof(struct ctrl_reg, lnk_status), |
| 102 | SLOTCAP = offsetof(struct ctrl_reg, slot_cap), |
| 103 | SLOTCTRL = offsetof(struct ctrl_reg, slot_ctrl), |
| 104 | SLOTSTATUS = offsetof(struct ctrl_reg, slot_status), |
| 105 | ROOTCTRL = offsetof(struct ctrl_reg, root_ctrl), |
| 106 | ROOTSTATUS = offsetof(struct ctrl_reg, root_status), |
| 107 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 109 | static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value) |
| 110 | { |
| 111 | struct pci_dev *dev = ctrl->pci_dev; |
| 112 | return pci_read_config_word(dev, ctrl->cap_base + reg, value); |
| 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 115 | static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value) |
| 116 | { |
| 117 | struct pci_dev *dev = ctrl->pci_dev; |
| 118 | return pci_read_config_dword(dev, ctrl->cap_base + reg, value); |
| 119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 121 | static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value) |
| 122 | { |
| 123 | struct pci_dev *dev = ctrl->pci_dev; |
| 124 | return pci_write_config_word(dev, ctrl->cap_base + reg, value); |
| 125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 127 | static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value) |
| 128 | { |
| 129 | struct pci_dev *dev = ctrl->pci_dev; |
| 130 | return pci_write_config_dword(dev, ctrl->cap_base + reg, value); |
| 131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* Field definitions in PCI Express Capabilities Register */ |
| 134 | #define CAP_VER 0x000F |
| 135 | #define DEV_PORT_TYPE 0x00F0 |
| 136 | #define SLOT_IMPL 0x0100 |
| 137 | #define MSG_NUM 0x3E00 |
| 138 | |
| 139 | /* Device or Port Type */ |
| 140 | #define NAT_ENDPT 0x00 |
| 141 | #define LEG_ENDPT 0x01 |
| 142 | #define ROOT_PORT 0x04 |
| 143 | #define UP_STREAM 0x05 |
| 144 | #define DN_STREAM 0x06 |
| 145 | #define PCIE_PCI_BRDG 0x07 |
| 146 | #define PCI_PCIE_BRDG 0x10 |
| 147 | |
| 148 | /* Field definitions in Device Capabilities Register */ |
| 149 | #define DATTN_BUTTN_PRSN 0x1000 |
| 150 | #define DATTN_LED_PRSN 0x2000 |
| 151 | #define DPWR_LED_PRSN 0x4000 |
| 152 | |
| 153 | /* Field definitions in Link Capabilities Register */ |
| 154 | #define MAX_LNK_SPEED 0x000F |
| 155 | #define MAX_LNK_WIDTH 0x03F0 |
| 156 | |
| 157 | /* Link Width Encoding */ |
| 158 | #define LNK_X1 0x01 |
| 159 | #define LNK_X2 0x02 |
| 160 | #define LNK_X4 0x04 |
| 161 | #define LNK_X8 0x08 |
| 162 | #define LNK_X12 0x0C |
| 163 | #define LNK_X16 0x10 |
| 164 | #define LNK_X32 0x20 |
| 165 | |
| 166 | /*Field definitions of Link Status Register */ |
| 167 | #define LNK_SPEED 0x000F |
| 168 | #define NEG_LINK_WD 0x03F0 |
| 169 | #define LNK_TRN_ERR 0x0400 |
| 170 | #define LNK_TRN 0x0800 |
| 171 | #define SLOT_CLK_CONF 0x1000 |
| 172 | |
| 173 | /* Field definitions in Slot Capabilities Register */ |
| 174 | #define ATTN_BUTTN_PRSN 0x00000001 |
| 175 | #define PWR_CTRL_PRSN 0x00000002 |
| 176 | #define MRL_SENS_PRSN 0x00000004 |
| 177 | #define ATTN_LED_PRSN 0x00000008 |
| 178 | #define PWR_LED_PRSN 0x00000010 |
| 179 | #define HP_SUPR_RM_SUP 0x00000020 |
| 180 | #define HP_CAP 0x00000040 |
| 181 | #define SLOT_PWR_VALUE 0x000003F8 |
| 182 | #define SLOT_PWR_LIMIT 0x00000C00 |
| 183 | #define PSN 0xFFF80000 /* PSN: Physical Slot Number */ |
| 184 | |
| 185 | /* Field definitions in Slot Control Register */ |
| 186 | #define ATTN_BUTTN_ENABLE 0x0001 |
| 187 | #define PWR_FAULT_DETECT_ENABLE 0x0002 |
| 188 | #define MRL_DETECT_ENABLE 0x0004 |
| 189 | #define PRSN_DETECT_ENABLE 0x0008 |
| 190 | #define CMD_CMPL_INTR_ENABLE 0x0010 |
| 191 | #define HP_INTR_ENABLE 0x0020 |
| 192 | #define ATTN_LED_CTRL 0x00C0 |
| 193 | #define PWR_LED_CTRL 0x0300 |
| 194 | #define PWR_CTRL 0x0400 |
| 195 | |
| 196 | /* Attention indicator and Power indicator states */ |
| 197 | #define LED_ON 0x01 |
| 198 | #define LED_BLINK 0x10 |
| 199 | #define LED_OFF 0x11 |
| 200 | |
| 201 | /* Power Control Command */ |
| 202 | #define POWER_ON 0 |
| 203 | #define POWER_OFF 0x0400 |
| 204 | |
| 205 | /* Field definitions in Slot Status Register */ |
| 206 | #define ATTN_BUTTN_PRESSED 0x0001 |
| 207 | #define PWR_FAULT_DETECTED 0x0002 |
| 208 | #define MRL_SENS_CHANGED 0x0004 |
| 209 | #define PRSN_DETECT_CHANGED 0x0008 |
| 210 | #define CMD_COMPLETED 0x0010 |
| 211 | #define MRL_STATE 0x0020 |
| 212 | #define PRSN_STATE 0x0040 |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static spinlock_t hpc_event_lock; |
| 215 | |
| 216 | DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | static int ctlr_seq_num = 0; /* Controller sequence # */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 219 | static irqreturn_t pcie_isr(int irq, void *dev_id); |
| 220 | static void start_int_poll_timer(struct controller *ctrl, int sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* This is the interrupt polling timeout function. */ |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 223 | static void int_poll_timeout(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 225 | struct controller *ctrl = (struct controller *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | DBG_ENTER_ROUTINE |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | /* Poll for interrupt events. regs == NULL => polling */ |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 230 | pcie_isr(0, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 232 | init_timer(&ctrl->poll_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (!pciehp_poll_time) |
| 234 | pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ |
| 235 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 236 | start_int_poll_timer(ctrl, pciehp_poll_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | /* This function starts the interrupt polling timer. */ |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 240 | static void start_int_poll_timer(struct controller *ctrl, int sec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 242 | /* Clamp to sane value */ |
| 243 | if ((sec <= 0) || (sec > 60)) |
| 244 | sec = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 246 | ctrl->poll_timer.function = &int_poll_timeout; |
| 247 | ctrl->poll_timer.data = (unsigned long)ctrl; |
| 248 | ctrl->poll_timer.expires = jiffies + sec * HZ; |
| 249 | add_timer(&ctrl->poll_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static int pcie_write_cmd(struct slot *slot, u16 cmd) |
| 253 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 254 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | int retval = 0; |
| 256 | u16 slot_status; |
| 257 | |
| 258 | DBG_ENTER_ROUTINE |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 259 | |
| 260 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 262 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
| 263 | return retval; |
| 264 | } |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { |
| 267 | /* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue |
| 268 | the next command according to spec. Just print out the error message */ |
| 269 | dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__); |
| 270 | } |
| 271 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 272 | retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 274 | err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | return retval; |
| 276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | DBG_LEAVE_ROUTINE |
| 279 | return retval; |
| 280 | } |
| 281 | |
| 282 | static int hpc_check_lnk_status(struct controller *ctrl) |
| 283 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | u16 lnk_status; |
| 285 | int retval = 0; |
| 286 | |
| 287 | DBG_ENTER_ROUTINE |
| 288 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 289 | retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 291 | err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | return retval; |
| 293 | } |
| 294 | |
| 295 | dbg("%s: lnk_status = %x\n", __FUNCTION__, lnk_status); |
| 296 | if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) || |
| 297 | !(lnk_status & NEG_LINK_WD)) { |
| 298 | err("%s : Link Training Error occurs \n", __FUNCTION__); |
| 299 | retval = -1; |
| 300 | return retval; |
| 301 | } |
| 302 | |
| 303 | DBG_LEAVE_ROUTINE |
| 304 | return retval; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | static int hpc_get_attention_status(struct slot *slot, u8 *status) |
| 309 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 310 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | u16 slot_ctrl; |
| 312 | u8 atten_led_state; |
| 313 | int retval = 0; |
| 314 | |
| 315 | DBG_ENTER_ROUTINE |
| 316 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 317 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 319 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return retval; |
| 321 | } |
| 322 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 323 | dbg("%s: SLOTCTRL %x, value read %x\n", |
| 324 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6; |
| 327 | |
| 328 | switch (atten_led_state) { |
| 329 | case 0: |
| 330 | *status = 0xFF; /* Reserved */ |
| 331 | break; |
| 332 | case 1: |
| 333 | *status = 1; /* On */ |
| 334 | break; |
| 335 | case 2: |
| 336 | *status = 2; /* Blink */ |
| 337 | break; |
| 338 | case 3: |
| 339 | *status = 0; /* Off */ |
| 340 | break; |
| 341 | default: |
| 342 | *status = 0xFF; |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | DBG_LEAVE_ROUTINE |
| 347 | return 0; |
| 348 | } |
| 349 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 350 | static int hpc_get_power_status(struct slot *slot, u8 *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 352 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | u16 slot_ctrl; |
| 354 | u8 pwr_state; |
| 355 | int retval = 0; |
| 356 | |
| 357 | DBG_ENTER_ROUTINE |
| 358 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 359 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 361 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return retval; |
| 363 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 364 | dbg("%s: SLOTCTRL %x value read %x\n", |
| 365 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | pwr_state = (slot_ctrl & PWR_CTRL) >> 10; |
| 368 | |
| 369 | switch (pwr_state) { |
| 370 | case 0: |
| 371 | *status = 1; |
| 372 | break; |
| 373 | case 1: |
| 374 | *status = 0; |
| 375 | break; |
| 376 | default: |
| 377 | *status = 0xFF; |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | DBG_LEAVE_ROUTINE |
| 382 | return retval; |
| 383 | } |
| 384 | |
| 385 | |
| 386 | static int hpc_get_latch_status(struct slot *slot, u8 *status) |
| 387 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 388 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | u16 slot_status; |
| 390 | int retval = 0; |
| 391 | |
| 392 | DBG_ENTER_ROUTINE |
| 393 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 394 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 396 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | return retval; |
| 398 | } |
| 399 | |
| 400 | *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1; |
| 401 | |
| 402 | DBG_LEAVE_ROUTINE |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static int hpc_get_adapter_status(struct slot *slot, u8 *status) |
| 407 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 408 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | u16 slot_status; |
| 410 | u8 card_state; |
| 411 | int retval = 0; |
| 412 | |
| 413 | DBG_ENTER_ROUTINE |
| 414 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 415 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 417 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | return retval; |
| 419 | } |
| 420 | card_state = (u8)((slot_status & PRSN_STATE) >> 6); |
| 421 | *status = (card_state == 1) ? 1 : 0; |
| 422 | |
| 423 | DBG_LEAVE_ROUTINE |
| 424 | return 0; |
| 425 | } |
| 426 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 427 | static int hpc_query_power_fault(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 429 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | u16 slot_status; |
| 431 | u8 pwr_fault; |
| 432 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | DBG_ENTER_ROUTINE |
| 435 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 436 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 438 | err("%s: Cannot check for power fault\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | return retval; |
| 440 | } |
| 441 | pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | DBG_LEAVE_ROUTINE |
rajesh.shah@intel.com | 8239def | 2005-10-31 16:20:13 -0800 | [diff] [blame] | 444 | return pwr_fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static int hpc_set_attention_status(struct slot *slot, u8 value) |
| 448 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 449 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | u16 slot_cmd = 0; |
| 451 | u16 slot_ctrl; |
| 452 | int rc = 0; |
| 453 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 454 | DBG_ENTER_ROUTINE |
| 455 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 456 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 458 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return rc; |
| 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | switch (value) { |
| 463 | case 0 : /* turn off */ |
| 464 | slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x00C0; |
| 465 | break; |
| 466 | case 1: /* turn on */ |
| 467 | slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x0040; |
| 468 | break; |
| 469 | case 2: /* turn blink */ |
| 470 | slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x0080; |
| 471 | break; |
| 472 | default: |
| 473 | return -1; |
| 474 | } |
| 475 | if (!pciehp_poll_mode) |
| 476 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
| 477 | |
| 478 | pcie_write_cmd(slot, slot_cmd); |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 479 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
| 480 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 482 | DBG_LEAVE_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return rc; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | static void hpc_set_green_led_on(struct slot *slot) |
| 488 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 489 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | u16 slot_cmd; |
| 491 | u16 slot_ctrl; |
| 492 | int rc = 0; |
| 493 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 494 | DBG_ENTER_ROUTINE |
| 495 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 496 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 498 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | return; |
| 500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0100; |
| 502 | if (!pciehp_poll_mode) |
| 503 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
| 504 | |
| 505 | pcie_write_cmd(slot, slot_cmd); |
| 506 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 507 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
| 508 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 509 | DBG_LEAVE_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | return; |
| 511 | } |
| 512 | |
| 513 | static void hpc_set_green_led_off(struct slot *slot) |
| 514 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 515 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | u16 slot_cmd; |
| 517 | u16 slot_ctrl; |
| 518 | int rc = 0; |
| 519 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 520 | DBG_ENTER_ROUTINE |
| 521 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 522 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 524 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return; |
| 526 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
| 528 | slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0300; |
| 529 | |
| 530 | if (!pciehp_poll_mode) |
| 531 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
| 532 | pcie_write_cmd(slot, slot_cmd); |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 533 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
| 534 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 536 | DBG_LEAVE_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return; |
| 538 | } |
| 539 | |
| 540 | static void hpc_set_green_led_blink(struct slot *slot) |
| 541 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 542 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | u16 slot_cmd; |
| 544 | u16 slot_ctrl; |
| 545 | int rc = 0; |
| 546 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 547 | DBG_ENTER_ROUTINE |
| 548 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 549 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 551 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return; |
| 553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0200; |
| 556 | |
| 557 | if (!pciehp_poll_mode) |
| 558 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
| 559 | pcie_write_cmd(slot, slot_cmd); |
| 560 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 561 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
| 562 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 563 | DBG_LEAVE_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | return; |
| 565 | } |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | static void hpc_release_ctlr(struct controller *ctrl) |
| 568 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | DBG_ENTER_ROUTINE |
| 570 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 571 | if (pciehp_poll_mode) |
| 572 | del_timer(&ctrl->poll_timer); |
| 573 | else |
| 574 | free_irq(ctrl->pci_dev->irq, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | DBG_LEAVE_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static int hpc_power_on_slot(struct slot * slot) |
| 580 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 581 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | u16 slot_cmd; |
Rajesh Shah | 5a49f20 | 2005-11-23 15:44:54 -0800 | [diff] [blame] | 583 | u16 slot_ctrl, slot_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | int retval = 0; |
| 585 | |
| 586 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Rajesh Shah | 5a49f20 | 2005-11-23 15:44:54 -0800 | [diff] [blame] | 590 | /* Clear sticky power-fault bit from previous power failures */ |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 591 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 593 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
| 594 | return retval; |
| 595 | } |
| 596 | slot_status &= PWR_FAULT_DETECTED; |
| 597 | if (slot_status) { |
| 598 | retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status); |
| 599 | if (retval) { |
| 600 | err("%s: Cannot write to SLOTSTATUS register\n", |
| 601 | __FUNCTION__); |
| 602 | return retval; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
| 607 | if (retval) { |
| 608 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return retval; |
| 610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | slot_cmd = (slot_ctrl & ~PWR_CTRL) | POWER_ON; |
| 613 | |
Thomas Schaefer | c7ab337 | 2005-12-08 11:55:57 -0800 | [diff] [blame] | 614 | /* Enable detection that we turned off at slot power-off time */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | if (!pciehp_poll_mode) |
Thomas Schaefer | c7ab337 | 2005-12-08 11:55:57 -0800 | [diff] [blame] | 616 | slot_cmd = slot_cmd | |
| 617 | PWR_FAULT_DETECT_ENABLE | |
| 618 | MRL_DETECT_ENABLE | |
| 619 | PRSN_DETECT_ENABLE | |
| 620 | HP_INTR_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | retval = pcie_write_cmd(slot, slot_cmd); |
| 623 | |
| 624 | if (retval) { |
| 625 | err("%s: Write %x command failed!\n", __FUNCTION__, slot_cmd); |
| 626 | return -1; |
| 627 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 628 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
| 629 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | DBG_LEAVE_ROUTINE |
| 632 | |
| 633 | return retval; |
| 634 | } |
| 635 | |
| 636 | static int hpc_power_off_slot(struct slot * slot) |
| 637 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 638 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | u16 slot_cmd; |
| 640 | u16 slot_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | int retval = 0; |
| 642 | |
| 643 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 647 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 649 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | return retval; |
| 651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | slot_cmd = (slot_ctrl & ~PWR_CTRL) | POWER_OFF; |
| 654 | |
Thomas Schaefer | c7ab337 | 2005-12-08 11:55:57 -0800 | [diff] [blame] | 655 | /* |
| 656 | * If we get MRL or presence detect interrupts now, the isr |
| 657 | * will notice the sticky power-fault bit too and issue power |
| 658 | * indicator change commands. This will lead to an endless loop |
| 659 | * of command completions, since the power-fault bit remains on |
| 660 | * till the slot is powered on again. |
| 661 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (!pciehp_poll_mode) |
Thomas Schaefer | c7ab337 | 2005-12-08 11:55:57 -0800 | [diff] [blame] | 663 | slot_cmd = (slot_cmd & |
| 664 | ~PWR_FAULT_DETECT_ENABLE & |
| 665 | ~MRL_DETECT_ENABLE & |
| 666 | ~PRSN_DETECT_ENABLE) | HP_INTR_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | retval = pcie_write_cmd(slot, slot_cmd); |
| 669 | |
| 670 | if (retval) { |
| 671 | err("%s: Write command failed!\n", __FUNCTION__); |
| 672 | return -1; |
| 673 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 674 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
| 675 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
| 677 | DBG_LEAVE_ROUTINE |
| 678 | |
| 679 | return retval; |
| 680 | } |
| 681 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 682 | static irqreturn_t pcie_isr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 684 | struct controller *ctrl = (struct controller *)dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | u16 slot_status, intr_detect, intr_loc; |
| 686 | u16 temp_word; |
| 687 | int hp_slot = 0; /* only 1 slot per PCI Express port */ |
| 688 | int rc = 0; |
| 689 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 690 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 692 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | return IRQ_NONE; |
| 694 | } |
| 695 | |
| 696 | intr_detect = ( ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED | MRL_SENS_CHANGED | |
| 697 | PRSN_DETECT_CHANGED | CMD_COMPLETED ); |
| 698 | |
| 699 | intr_loc = slot_status & intr_detect; |
| 700 | |
| 701 | /* Check to see if it was our interrupt */ |
| 702 | if ( !intr_loc ) |
| 703 | return IRQ_NONE; |
| 704 | |
| 705 | dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc); |
| 706 | /* Mask Hot-plug Interrupt Enable */ |
| 707 | if (!pciehp_poll_mode) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 708 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 710 | err("%s: Cannot read SLOT_CTRL register\n", |
| 711 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | return IRQ_NONE; |
| 713 | } |
| 714 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 715 | dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n", |
| 716 | __FUNCTION__, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 718 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
| 719 | if (rc) { |
| 720 | err("%s: Cannot write to SLOTCTRL register\n", |
| 721 | __FUNCTION__); |
| 722 | return IRQ_NONE; |
| 723 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 725 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 727 | err("%s: Cannot read SLOT_STATUS register\n", |
| 728 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | return IRQ_NONE; |
| 730 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 731 | dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n", |
| 732 | __FUNCTION__, slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | /* Clear command complete interrupt caused by this write */ |
| 735 | temp_word = 0x1f; |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 736 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 738 | err("%s: Cannot write to SLOTSTATUS register\n", |
| 739 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | return IRQ_NONE; |
| 741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | if (intr_loc & CMD_COMPLETED) { |
| 745 | /* |
| 746 | * Command Complete Interrupt Pending |
| 747 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | wake_up_interruptible(&ctrl->queue); |
| 749 | } |
| 750 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 751 | if (intr_loc & MRL_SENS_CHANGED) |
| 752 | pciehp_handle_switch_change(hp_slot, ctrl); |
| 753 | |
| 754 | if (intr_loc & ATTN_BUTTN_PRESSED) |
| 755 | pciehp_handle_attention_button(hp_slot, ctrl); |
| 756 | |
| 757 | if (intr_loc & PRSN_DETECT_CHANGED) |
| 758 | pciehp_handle_presence_change(hp_slot, ctrl); |
| 759 | |
| 760 | if (intr_loc & PWR_FAULT_DETECTED) |
| 761 | pciehp_handle_power_fault(hp_slot, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
| 763 | /* Clear all events after serving them */ |
| 764 | temp_word = 0x1F; |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 765 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 767 | err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | return IRQ_NONE; |
| 769 | } |
| 770 | /* Unmask Hot-plug Interrupt Enable */ |
| 771 | if (!pciehp_poll_mode) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 772 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 774 | err("%s: Cannot read SLOTCTRL register\n", |
| 775 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return IRQ_NONE; |
| 777 | } |
| 778 | |
| 779 | dbg("%s: Unmask Hot-plug Interrupt Enable\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; |
| 781 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 782 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 784 | err("%s: Cannot write to SLOTCTRL register\n", |
| 785 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return IRQ_NONE; |
| 787 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 788 | |
| 789 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 791 | err("%s: Cannot read SLOT_STATUS register\n", |
| 792 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | return IRQ_NONE; |
| 794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* Clear command complete interrupt caused by this write */ |
| 797 | temp_word = 0x1F; |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 798 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 800 | err("%s: Cannot write to SLOTSTATUS failed\n", |
| 801 | __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | return IRQ_NONE; |
| 803 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 804 | dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n", |
| 805 | __FUNCTION__, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | return IRQ_HANDLED; |
| 809 | } |
| 810 | |
| 811 | static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value) |
| 812 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 813 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | enum pcie_link_speed lnk_speed; |
| 815 | u32 lnk_cap; |
| 816 | int retval = 0; |
| 817 | |
| 818 | DBG_ENTER_ROUTINE |
| 819 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 820 | retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 822 | err("%s: Cannot read LNKCAP register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | return retval; |
| 824 | } |
| 825 | |
| 826 | switch (lnk_cap & 0x000F) { |
| 827 | case 1: |
| 828 | lnk_speed = PCIE_2PT5GB; |
| 829 | break; |
| 830 | default: |
| 831 | lnk_speed = PCIE_LNK_SPEED_UNKNOWN; |
| 832 | break; |
| 833 | } |
| 834 | |
| 835 | *value = lnk_speed; |
| 836 | dbg("Max link speed = %d\n", lnk_speed); |
| 837 | DBG_LEAVE_ROUTINE |
| 838 | return retval; |
| 839 | } |
| 840 | |
| 841 | static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value) |
| 842 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 843 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | enum pcie_link_width lnk_wdth; |
| 845 | u32 lnk_cap; |
| 846 | int retval = 0; |
| 847 | |
| 848 | DBG_ENTER_ROUTINE |
| 849 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 850 | retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 852 | err("%s: Cannot read LNKCAP register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | return retval; |
| 854 | } |
| 855 | |
| 856 | switch ((lnk_cap & 0x03F0) >> 4){ |
| 857 | case 0: |
| 858 | lnk_wdth = PCIE_LNK_WIDTH_RESRV; |
| 859 | break; |
| 860 | case 1: |
| 861 | lnk_wdth = PCIE_LNK_X1; |
| 862 | break; |
| 863 | case 2: |
| 864 | lnk_wdth = PCIE_LNK_X2; |
| 865 | break; |
| 866 | case 4: |
| 867 | lnk_wdth = PCIE_LNK_X4; |
| 868 | break; |
| 869 | case 8: |
| 870 | lnk_wdth = PCIE_LNK_X8; |
| 871 | break; |
| 872 | case 12: |
| 873 | lnk_wdth = PCIE_LNK_X12; |
| 874 | break; |
| 875 | case 16: |
| 876 | lnk_wdth = PCIE_LNK_X16; |
| 877 | break; |
| 878 | case 32: |
| 879 | lnk_wdth = PCIE_LNK_X32; |
| 880 | break; |
| 881 | default: |
| 882 | lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; |
| 883 | break; |
| 884 | } |
| 885 | |
| 886 | *value = lnk_wdth; |
| 887 | dbg("Max link width = %d\n", lnk_wdth); |
| 888 | DBG_LEAVE_ROUTINE |
| 889 | return retval; |
| 890 | } |
| 891 | |
| 892 | static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value) |
| 893 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 894 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN; |
| 896 | int retval = 0; |
| 897 | u16 lnk_status; |
| 898 | |
| 899 | DBG_ENTER_ROUTINE |
| 900 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 901 | retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 903 | err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | return retval; |
| 905 | } |
| 906 | |
| 907 | switch (lnk_status & 0x0F) { |
| 908 | case 1: |
| 909 | lnk_speed = PCIE_2PT5GB; |
| 910 | break; |
| 911 | default: |
| 912 | lnk_speed = PCIE_LNK_SPEED_UNKNOWN; |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | *value = lnk_speed; |
| 917 | dbg("Current link speed = %d\n", lnk_speed); |
| 918 | DBG_LEAVE_ROUTINE |
| 919 | return retval; |
| 920 | } |
| 921 | |
| 922 | static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value) |
| 923 | { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 924 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; |
| 926 | int retval = 0; |
| 927 | u16 lnk_status; |
| 928 | |
| 929 | DBG_ENTER_ROUTINE |
| 930 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 931 | retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | if (retval) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 933 | err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | return retval; |
| 935 | } |
| 936 | |
| 937 | switch ((lnk_status & 0x03F0) >> 4){ |
| 938 | case 0: |
| 939 | lnk_wdth = PCIE_LNK_WIDTH_RESRV; |
| 940 | break; |
| 941 | case 1: |
| 942 | lnk_wdth = PCIE_LNK_X1; |
| 943 | break; |
| 944 | case 2: |
| 945 | lnk_wdth = PCIE_LNK_X2; |
| 946 | break; |
| 947 | case 4: |
| 948 | lnk_wdth = PCIE_LNK_X4; |
| 949 | break; |
| 950 | case 8: |
| 951 | lnk_wdth = PCIE_LNK_X8; |
| 952 | break; |
| 953 | case 12: |
| 954 | lnk_wdth = PCIE_LNK_X12; |
| 955 | break; |
| 956 | case 16: |
| 957 | lnk_wdth = PCIE_LNK_X16; |
| 958 | break; |
| 959 | case 32: |
| 960 | lnk_wdth = PCIE_LNK_X32; |
| 961 | break; |
| 962 | default: |
| 963 | lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; |
| 964 | break; |
| 965 | } |
| 966 | |
| 967 | *value = lnk_wdth; |
| 968 | dbg("Current link width = %d\n", lnk_wdth); |
| 969 | DBG_LEAVE_ROUTINE |
| 970 | return retval; |
| 971 | } |
| 972 | |
| 973 | static struct hpc_ops pciehp_hpc_ops = { |
| 974 | .power_on_slot = hpc_power_on_slot, |
| 975 | .power_off_slot = hpc_power_off_slot, |
| 976 | .set_attention_status = hpc_set_attention_status, |
| 977 | .get_power_status = hpc_get_power_status, |
| 978 | .get_attention_status = hpc_get_attention_status, |
| 979 | .get_latch_status = hpc_get_latch_status, |
| 980 | .get_adapter_status = hpc_get_adapter_status, |
| 981 | |
| 982 | .get_max_bus_speed = hpc_get_max_lnk_speed, |
| 983 | .get_cur_bus_speed = hpc_get_cur_lnk_speed, |
| 984 | .get_max_lnk_width = hpc_get_max_lnk_width, |
| 985 | .get_cur_lnk_width = hpc_get_cur_lnk_width, |
| 986 | |
| 987 | .query_power_fault = hpc_query_power_fault, |
| 988 | .green_led_on = hpc_set_green_led_on, |
| 989 | .green_led_off = hpc_set_green_led_off, |
| 990 | .green_led_blink = hpc_set_green_led_blink, |
| 991 | |
| 992 | .release_ctlr = hpc_release_ctlr, |
| 993 | .check_lnk_status = hpc_check_lnk_status, |
| 994 | }; |
| 995 | |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 996 | #ifdef CONFIG_ACPI |
| 997 | int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev) |
| 998 | { |
| 999 | acpi_status status; |
| 1000 | acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); |
| 1001 | struct pci_dev *pdev = dev; |
| 1002 | struct pci_bus *parent; |
MUNEDA Takahiro | b2e6e3b | 2006-03-17 09:18:39 +0900 | [diff] [blame] | 1003 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1004 | |
| 1005 | /* |
| 1006 | * Per PCI firmware specification, we should run the ACPI _OSC |
| 1007 | * method to get control of hotplug hardware before using it. |
| 1008 | * If an _OSC is missing, we look for an OSHP to do the same thing. |
| 1009 | * To handle different BIOS behavior, we look for _OSC and OSHP |
| 1010 | * within the scope of the hotplug controller and its parents, upto |
| 1011 | * the host bridge under which this controller exists. |
| 1012 | */ |
| 1013 | while (!handle) { |
| 1014 | /* |
| 1015 | * This hotplug controller was not listed in the ACPI name |
| 1016 | * space at all. Try to get acpi handle of parent pci bus. |
| 1017 | */ |
| 1018 | if (!pdev || !pdev->bus->parent) |
| 1019 | break; |
| 1020 | parent = pdev->bus->parent; |
| 1021 | dbg("Could not find %s in acpi namespace, trying parent\n", |
| 1022 | pci_name(pdev)); |
| 1023 | if (!parent->self) |
| 1024 | /* Parent must be a host bridge */ |
| 1025 | handle = acpi_get_pci_rootbridge_handle( |
| 1026 | pci_domain_nr(parent), |
| 1027 | parent->number); |
| 1028 | else |
| 1029 | handle = DEVICE_ACPI_HANDLE( |
| 1030 | &(parent->self->dev)); |
| 1031 | pdev = parent->self; |
| 1032 | } |
| 1033 | |
| 1034 | while (handle) { |
MUNEDA Takahiro | b2e6e3b | 2006-03-17 09:18:39 +0900 | [diff] [blame] | 1035 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); |
| 1036 | dbg("Trying to get hotplug control for %s \n", |
| 1037 | (char *)string.pointer); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1038 | status = pci_osc_control_set(handle, |
| 1039 | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL); |
| 1040 | if (status == AE_NOT_FOUND) |
| 1041 | status = acpi_run_oshp(handle); |
| 1042 | if (ACPI_SUCCESS(status)) { |
| 1043 | dbg("Gained control for hotplug HW for pci %s (%s)\n", |
MUNEDA Takahiro | b2e6e3b | 2006-03-17 09:18:39 +0900 | [diff] [blame] | 1044 | pci_name(dev), (char *)string.pointer); |
Kristen Accardi | 81b26bc | 2006-04-18 14:36:43 -0700 | [diff] [blame] | 1045 | kfree(string.pointer); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1046 | return 0; |
| 1047 | } |
| 1048 | if (acpi_root_bridge(handle)) |
| 1049 | break; |
| 1050 | chandle = handle; |
| 1051 | status = acpi_get_parent(chandle, &handle); |
| 1052 | if (ACPI_FAILURE(status)) |
| 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | err("Cannot get control of hotplug hardware for pci %s\n", |
| 1057 | pci_name(dev)); |
MUNEDA Takahiro | b2e6e3b | 2006-03-17 09:18:39 +0900 | [diff] [blame] | 1058 | |
Kristen Accardi | 81b26bc | 2006-04-18 14:36:43 -0700 | [diff] [blame] | 1059 | kfree(string.pointer); |
Kristen Accardi | 783c49f | 2006-03-03 10:16:05 -0800 | [diff] [blame] | 1060 | return -1; |
| 1061 | } |
| 1062 | #endif |
| 1063 | |
| 1064 | |
| 1065 | |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 1066 | int pcie_init(struct controller * ctrl, struct pcie_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | int rc; |
| 1069 | static int first = 1; |
| 1070 | u16 temp_word; |
| 1071 | u16 cap_reg; |
| 1072 | u16 intr_enable = 0; |
| 1073 | u32 slot_cap; |
Kenji Kaneshige | 75e1317 | 2006-12-21 17:01:08 -0800 | [diff] [blame^] | 1074 | int cap_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | u16 slot_status, slot_ctrl; |
| 1076 | struct pci_dev *pdev; |
| 1077 | |
| 1078 | DBG_ENTER_ROUTINE |
| 1079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | pdev = dev->port; |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1081 | ctrl->pci_dev = pdev; /* save pci_dev in context */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 1083 | dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n", |
| 1084 | __FUNCTION__, pdev->vendor, pdev->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) { |
| 1087 | dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__); |
| 1088 | goto abort_free_ctlr; |
| 1089 | } |
| 1090 | |
Dely Sy | 8b245e4 | 2005-05-06 17:19:09 -0700 | [diff] [blame] | 1091 | ctrl->cap_base = cap_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Kenji Kaneshige | 75e1317 | 2006-12-21 17:01:08 -0800 | [diff] [blame^] | 1093 | dbg("%s: pcie_cap_base %x\n", __FUNCTION__, cap_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1095 | rc = pciehp_readw(ctrl, CAPREG, &cap_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1097 | err("%s: Cannot read CAPREG register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | goto abort_free_ctlr; |
| 1099 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1100 | dbg("%s: CAPREG offset %x cap_reg %x\n", |
| 1101 | __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
Dely Sy | 8b245e4 | 2005-05-06 17:19:09 -0700 | [diff] [blame] | 1103 | if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040) |
| 1104 | && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | dbg("%s : This is not a root port or the port is not connected to a slot\n", __FUNCTION__); |
| 1106 | goto abort_free_ctlr; |
| 1107 | } |
| 1108 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1109 | rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1111 | err("%s: Cannot read SLOTCAP register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | goto abort_free_ctlr; |
| 1113 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1114 | dbg("%s: SLOTCAP offset %x slot_cap %x\n", |
| 1115 | __FUNCTION__, ctrl->cap_base + SLOTCAP, slot_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
| 1117 | if (!(slot_cap & HP_CAP)) { |
| 1118 | dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__); |
| 1119 | goto abort_free_ctlr; |
| 1120 | } |
| 1121 | /* For debugging purpose */ |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1122 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1124 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | goto abort_free_ctlr; |
| 1126 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1127 | dbg("%s: SLOTSTATUS offset %x slot_status %x\n", |
| 1128 | __FUNCTION__, ctrl->cap_base + SLOTSTATUS, slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1130 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1132 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | goto abort_free_ctlr; |
| 1134 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1135 | dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n", |
| 1136 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | if (first) { |
| 1139 | spin_lock_init(&hpc_event_lock); |
| 1140 | first = 0; |
| 1141 | } |
| 1142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++) |
| 1144 | if (pci_resource_len(pdev, rc) > 0) |
Greg Kroah-Hartman | 1396a8c | 2006-06-12 15:14:29 -0700 | [diff] [blame] | 1145 | dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc, |
| 1146 | (unsigned long long)pci_resource_start(pdev, rc), |
| 1147 | (unsigned long long)pci_resource_len(pdev, rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
| 1149 | info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, |
| 1150 | pdev->subsystem_vendor, pdev->subsystem_device); |
| 1151 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1152 | mutex_init(&ctrl->crit_sect); |
Kenji Kaneshige | dd5619c | 2006-09-22 10:17:29 -0700 | [diff] [blame] | 1153 | mutex_init(&ctrl->ctrl_lock); |
| 1154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | /* setup wait queue */ |
| 1156 | init_waitqueue_head(&ctrl->queue); |
| 1157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | /* return PCI Controller Info */ |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1159 | ctrl->slot_device_offset = 0; |
| 1160 | ctrl->num_slots = 1; |
| 1161 | ctrl->first_slot = slot_cap >> 19; |
| 1162 | ctrl->ctrlcap = slot_cap & 0x0000007f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | |
| 1164 | /* Mask Hot-plug Interrupt Enable */ |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1165 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1167 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | goto abort_free_ctlr; |
| 1169 | } |
| 1170 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1171 | dbg("%s: SLOTCTRL %x value read %x\n", |
| 1172 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; |
| 1174 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1175 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1177 | err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | goto abort_free_ctlr; |
| 1179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1181 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1183 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | goto abort_free_ctlr; |
| 1185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | temp_word = 0x1F; /* Clear all events */ |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1188 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1190 | err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | goto abort_free_ctlr; |
| 1192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1194 | if (pciehp_poll_mode) { |
| 1195 | /* Install interrupt polling timer. Start with 10 sec delay */ |
| 1196 | init_timer(&ctrl->poll_timer); |
| 1197 | start_int_poll_timer(ctrl, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | } else { |
| 1199 | /* Installs the interrupt handler */ |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1200 | rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED, |
| 1201 | MY_NAME, (void *)ctrl); |
| 1202 | dbg("%s: request_irq %d for hpc%d (returns %d)\n", |
| 1203 | __FUNCTION__, ctrl->pci_dev->irq, ctlr_seq_num, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | if (rc) { |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1205 | err("Can't get irq %d for the hotplug controller\n", |
| 1206 | ctrl->pci_dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | goto abort_free_ctlr; |
| 1208 | } |
| 1209 | } |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 1210 | dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number, |
| 1211 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq); |
| 1212 | |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1213 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1215 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1216 | goto abort_free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
| 1219 | intr_enable = intr_enable | PRSN_DETECT_ENABLE; |
| 1220 | |
| 1221 | if (ATTN_BUTTN(slot_cap)) |
| 1222 | intr_enable = intr_enable | ATTN_BUTTN_ENABLE; |
| 1223 | |
| 1224 | if (POWER_CTRL(slot_cap)) |
| 1225 | intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE; |
| 1226 | |
| 1227 | if (MRL_SENS(slot_cap)) |
| 1228 | intr_enable = intr_enable | MRL_DETECT_ENABLE; |
| 1229 | |
| 1230 | temp_word = (temp_word & ~intr_enable) | intr_enable; |
| 1231 | |
| 1232 | if (pciehp_poll_mode) { |
| 1233 | temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0; |
| 1234 | } else { |
| 1235 | temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; |
| 1236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
| 1238 | /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */ |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1239 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1241 | err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1242 | goto abort_free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | } |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1244 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1246 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1247 | goto abort_disable_intr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | |
| 1250 | temp_word = 0x1F; /* Clear all events */ |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1251 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | if (rc) { |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1253 | err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1254 | goto abort_disable_intr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 1257 | if (pciehp_force) { |
| 1258 | dbg("Bypassing BIOS check for pciehp use on %s\n", |
| 1259 | pci_name(ctrl->pci_dev)); |
| 1260 | } else { |
Rajesh Shah | 6560aa5 | 2005-11-07 13:37:36 -0800 | [diff] [blame] | 1261 | rc = pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev); |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 1262 | if (rc) |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1263 | goto abort_disable_intr; |
rajesh.shah@intel.com | a3a45ec | 2005-10-31 16:20:12 -0800 | [diff] [blame] | 1264 | } |
rajesh.shah@intel.com | a8a2be9 | 2005-10-31 16:20:07 -0800 | [diff] [blame] | 1265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | ctlr_seq_num++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | ctrl->hpc_ops = &pciehp_hpc_ops; |
| 1268 | |
| 1269 | DBG_LEAVE_ROUTINE |
| 1270 | return 0; |
| 1271 | |
| 1272 | /* We end up here for the many possible ways to fail this API. */ |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1273 | abort_disable_intr: |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1274 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1275 | if (!rc) { |
| 1276 | temp_word &= ~(intr_enable | HP_INTR_ENABLE); |
Kenji Kaneshige | a0f018d | 2006-12-21 17:01:06 -0800 | [diff] [blame] | 1277 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1278 | } |
| 1279 | if (rc) |
| 1280 | err("%s : disabling interrupts failed\n", __FUNCTION__); |
| 1281 | |
| 1282 | abort_free_irq: |
| 1283 | if (pciehp_poll_mode) |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1284 | del_timer_sync(&ctrl->poll_timer); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1285 | else |
Kenji Kaneshige | 48fe391 | 2006-12-21 17:01:04 -0800 | [diff] [blame] | 1286 | free_irq(ctrl->pci_dev->irq, ctrl); |
Jan Beulich | 9c64f97 | 2006-05-09 00:50:31 -0700 | [diff] [blame] | 1287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | abort_free_ctlr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | DBG_LEAVE_ROUTINE |
| 1290 | return -1; |
| 1291 | } |