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