Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Standard 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> |
Andrew Morton | d4d28dd | 2005-11-13 16:06:40 -0800 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "shpchp.h" |
| 37 | |
| 38 | #ifdef DEBUG |
| 39 | #define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */ |
| 40 | #define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */ |
| 41 | #define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */ |
| 42 | #define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */ |
| 43 | #define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT) |
| 44 | #define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE) |
| 45 | /* Redefine this flagword to set debug level */ |
| 46 | #define DEBUG_LEVEL DBG_K_STANDARD |
| 47 | |
| 48 | #define DEFINE_DBG_BUFFER char __dbg_str_buf[256]; |
| 49 | |
| 50 | #define DBG_PRINT( dbg_flags, args... ) \ |
| 51 | do { \ |
| 52 | if ( DEBUG_LEVEL & ( dbg_flags ) ) \ |
| 53 | { \ |
| 54 | int len; \ |
| 55 | len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \ |
| 56 | __FILE__, __LINE__, __FUNCTION__ ); \ |
| 57 | sprintf( __dbg_str_buf + len, args ); \ |
| 58 | printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \ |
| 59 | } \ |
| 60 | } while (0) |
| 61 | |
| 62 | #define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]"); |
| 63 | #define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]"); |
| 64 | #else |
| 65 | #define DEFINE_DBG_BUFFER |
| 66 | #define DBG_ENTER_ROUTINE |
| 67 | #define DBG_LEAVE_ROUTINE |
| 68 | #endif /* DEBUG */ |
| 69 | |
| 70 | /* Slot Available Register I field definition */ |
| 71 | #define SLOT_33MHZ 0x0000001f |
| 72 | #define SLOT_66MHZ_PCIX 0x00001f00 |
| 73 | #define SLOT_100MHZ_PCIX 0x001f0000 |
| 74 | #define SLOT_133MHZ_PCIX 0x1f000000 |
| 75 | |
| 76 | /* Slot Available Register II field definition */ |
| 77 | #define SLOT_66MHZ 0x0000001f |
| 78 | #define SLOT_66MHZ_PCIX_266 0x00000f00 |
| 79 | #define SLOT_100MHZ_PCIX_266 0x0000f000 |
| 80 | #define SLOT_133MHZ_PCIX_266 0x000f0000 |
| 81 | #define SLOT_66MHZ_PCIX_533 0x00f00000 |
| 82 | #define SLOT_100MHZ_PCIX_533 0x0f000000 |
| 83 | #define SLOT_133MHZ_PCIX_533 0xf0000000 |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* Slot Configuration */ |
| 86 | #define SLOT_NUM 0x0000001F |
| 87 | #define FIRST_DEV_NUM 0x00001F00 |
| 88 | #define PSN 0x07FF0000 |
| 89 | #define UPDOWN 0x20000000 |
| 90 | #define MRLSENSOR 0x40000000 |
| 91 | #define ATTN_BUTTON 0x80000000 |
| 92 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 93 | /* |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 94 | * Interrupt Locator Register definitions |
| 95 | */ |
| 96 | #define CMD_INTR_PENDING (1 << 0) |
| 97 | #define SLOT_INTR_PENDING(i) (1 << (i + 1)) |
| 98 | |
| 99 | /* |
Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 100 | * Controller SERR-INT Register |
| 101 | */ |
| 102 | #define GLOBAL_INTR_MASK (1 << 0) |
| 103 | #define GLOBAL_SERR_MASK (1 << 1) |
| 104 | #define COMMAND_INTR_MASK (1 << 2) |
| 105 | #define ARBITER_SERR_MASK (1 << 3) |
| 106 | #define COMMAND_DETECTED (1 << 16) |
| 107 | #define ARBITER_DETECTED (1 << 17) |
| 108 | #define SERR_INTR_RSVDZ_MASK 0xfffc0000 |
| 109 | |
| 110 | /* |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 111 | * Logical Slot Register definitions |
| 112 | */ |
| 113 | #define SLOT_REG(i) (SLOT1 + (4 * i)) |
| 114 | |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 115 | #define SLOT_STATE_SHIFT (0) |
| 116 | #define SLOT_STATE_MASK (3 << 0) |
| 117 | #define SLOT_STATE_PWRONLY (1) |
| 118 | #define SLOT_STATE_ENABLED (2) |
| 119 | #define SLOT_STATE_DISABLED (3) |
| 120 | #define PWR_LED_STATE_SHIFT (2) |
| 121 | #define PWR_LED_STATE_MASK (3 << 2) |
| 122 | #define ATN_LED_STATE_SHIFT (4) |
| 123 | #define ATN_LED_STATE_MASK (3 << 4) |
| 124 | #define ATN_LED_STATE_ON (1) |
| 125 | #define ATN_LED_STATE_BLINK (2) |
| 126 | #define ATN_LED_STATE_OFF (3) |
| 127 | #define POWER_FAULT (1 << 6) |
| 128 | #define ATN_BUTTON (1 << 7) |
| 129 | #define MRL_SENSOR (1 << 8) |
| 130 | #define MHZ66_CAP (1 << 9) |
| 131 | #define PRSNT_SHIFT (10) |
| 132 | #define PRSNT_MASK (3 << 10) |
| 133 | #define PCIX_CAP_SHIFT (12) |
| 134 | #define PCIX_CAP_MASK_PI1 (3 << 12) |
| 135 | #define PCIX_CAP_MASK_PI2 (7 << 12) |
| 136 | #define PRSNT_CHANGE_DETECTED (1 << 16) |
| 137 | #define ISO_PFAULT_DETECTED (1 << 17) |
| 138 | #define BUTTON_PRESS_DETECTED (1 << 18) |
| 139 | #define MRL_CHANGE_DETECTED (1 << 19) |
| 140 | #define CON_PFAULT_DETECTED (1 << 20) |
| 141 | #define PRSNT_CHANGE_INTR_MASK (1 << 24) |
| 142 | #define ISO_PFAULT_INTR_MASK (1 << 25) |
| 143 | #define BUTTON_PRESS_INTR_MASK (1 << 26) |
| 144 | #define MRL_CHANGE_INTR_MASK (1 << 27) |
| 145 | #define CON_PFAULT_INTR_MASK (1 << 28) |
| 146 | #define MRL_CHANGE_SERR_MASK (1 << 29) |
| 147 | #define CON_PFAULT_SERR_MASK (1 << 30) |
| 148 | #define SLOT_REG_RSVDZ_MASK (1 << 15) | (7 << 21) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | /* SHPC 'write' operations/commands */ |
| 151 | |
| 152 | /* Slot operation - 0x00h to 0x3Fh */ |
| 153 | |
| 154 | #define NO_CHANGE 0x00 |
| 155 | |
| 156 | /* Slot state - Bits 0 & 1 of controller command register */ |
| 157 | #define SET_SLOT_PWR 0x01 |
| 158 | #define SET_SLOT_ENABLE 0x02 |
| 159 | #define SET_SLOT_DISABLE 0x03 |
| 160 | |
| 161 | /* Power indicator state - Bits 2 & 3 of controller command register*/ |
| 162 | #define SET_PWR_ON 0x04 |
| 163 | #define SET_PWR_BLINK 0x08 |
| 164 | #define SET_PWR_OFF 0x0C |
| 165 | |
| 166 | /* Attention indicator state - Bits 4 & 5 of controller command register*/ |
| 167 | #define SET_ATTN_ON 0x010 |
| 168 | #define SET_ATTN_BLINK 0x020 |
| 169 | #define SET_ATTN_OFF 0x030 |
| 170 | |
| 171 | /* Set bus speed/mode A - 0x40h to 0x47h */ |
| 172 | #define SETA_PCI_33MHZ 0x40 |
| 173 | #define SETA_PCI_66MHZ 0x41 |
| 174 | #define SETA_PCIX_66MHZ 0x42 |
| 175 | #define SETA_PCIX_100MHZ 0x43 |
| 176 | #define SETA_PCIX_133MHZ 0x44 |
| 177 | #define RESERV_1 0x45 |
| 178 | #define RESERV_2 0x46 |
| 179 | #define RESERV_3 0x47 |
| 180 | |
| 181 | /* Set bus speed/mode B - 0x50h to 0x5fh */ |
| 182 | #define SETB_PCI_33MHZ 0x50 |
| 183 | #define SETB_PCI_66MHZ 0x51 |
| 184 | #define SETB_PCIX_66MHZ_PM 0x52 |
| 185 | #define SETB_PCIX_100MHZ_PM 0x53 |
| 186 | #define SETB_PCIX_133MHZ_PM 0x54 |
| 187 | #define SETB_PCIX_66MHZ_EM 0x55 |
| 188 | #define SETB_PCIX_100MHZ_EM 0x56 |
| 189 | #define SETB_PCIX_133MHZ_EM 0x57 |
| 190 | #define SETB_PCIX_66MHZ_266 0x58 |
| 191 | #define SETB_PCIX_100MHZ_266 0x59 |
| 192 | #define SETB_PCIX_133MHZ_266 0x5a |
| 193 | #define SETB_PCIX_66MHZ_533 0x5b |
| 194 | #define SETB_PCIX_100MHZ_533 0x5c |
| 195 | #define SETB_PCIX_133MHZ_533 0x5d |
| 196 | |
| 197 | |
| 198 | /* Power-on all slots - 0x48h */ |
| 199 | #define SET_PWR_ON_ALL 0x48 |
| 200 | |
| 201 | /* Enable all slots - 0x49h */ |
| 202 | #define SET_ENABLE_ALL 0x49 |
| 203 | |
| 204 | /* SHPC controller command error code */ |
| 205 | #define SWITCH_OPEN 0x1 |
| 206 | #define INVALID_CMD 0x2 |
| 207 | #define INVALID_SPEED_MODE 0x4 |
| 208 | |
| 209 | /* For accessing SHPC Working Register Set */ |
| 210 | #define DWORD_SELECT 0x2 |
| 211 | #define DWORD_DATA 0x4 |
| 212 | #define BASE_OFFSET 0x0 |
| 213 | |
| 214 | /* Field Offset in Logical Slot Register - byte boundary */ |
| 215 | #define SLOT_EVENT_LATCH 0x2 |
| 216 | #define SLOT_SERR_INT_MASK 0x3 |
| 217 | |
| 218 | static spinlock_t hpc_event_lock; |
| 219 | |
| 220 | DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ |
| 221 | static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */ |
| 222 | static int ctlr_seq_num = 0; /* Controller sequenc # */ |
| 223 | static spinlock_t list_lock; |
| 224 | |
Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 225 | static atomic_t shpchp_num_controllers = ATOMIC_INIT(0); |
| 226 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 227 | static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 230 | static int hpc_check_cmd_status(struct controller *ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 232 | static inline u8 shpc_readb(struct controller *ctrl, int reg) |
| 233 | { |
| 234 | return readb(ctrl->hpc_ctlr_handle->creg + reg); |
| 235 | } |
| 236 | |
| 237 | static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val) |
| 238 | { |
| 239 | writeb(val, ctrl->hpc_ctlr_handle->creg + reg); |
| 240 | } |
| 241 | |
| 242 | static inline u16 shpc_readw(struct controller *ctrl, int reg) |
| 243 | { |
| 244 | return readw(ctrl->hpc_ctlr_handle->creg + reg); |
| 245 | } |
| 246 | |
| 247 | static inline void shpc_writew(struct controller *ctrl, int reg, u16 val) |
| 248 | { |
| 249 | writew(val, ctrl->hpc_ctlr_handle->creg + reg); |
| 250 | } |
| 251 | |
| 252 | static inline u32 shpc_readl(struct controller *ctrl, int reg) |
| 253 | { |
| 254 | return readl(ctrl->hpc_ctlr_handle->creg + reg); |
| 255 | } |
| 256 | |
| 257 | static inline void shpc_writel(struct controller *ctrl, int reg, u32 val) |
| 258 | { |
| 259 | writel(val, ctrl->hpc_ctlr_handle->creg + reg); |
| 260 | } |
| 261 | |
| 262 | static inline int shpc_indirect_read(struct controller *ctrl, int index, |
| 263 | u32 *value) |
| 264 | { |
| 265 | int rc; |
| 266 | u32 cap_offset = ctrl->cap_offset; |
| 267 | struct pci_dev *pdev = ctrl->pci_dev; |
| 268 | |
| 269 | rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index); |
| 270 | if (rc) |
| 271 | return rc; |
| 272 | return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value); |
| 273 | } |
| 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* This is the interrupt polling timeout function. */ |
| 276 | static void int_poll_timeout(unsigned long lphp_ctlr) |
| 277 | { |
| 278 | struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr; |
| 279 | |
| 280 | DBG_ENTER_ROUTINE |
| 281 | |
| 282 | if ( !php_ctlr ) { |
| 283 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | /* Poll for interrupt events. regs == NULL => polling */ |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 288 | shpc_isr(0, php_ctlr->callback_instance_id, NULL ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | init_timer(&php_ctlr->int_poll_timer); |
| 291 | if (!shpchp_poll_time) |
| 292 | shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ |
| 293 | |
| 294 | start_int_poll_timer(php_ctlr, shpchp_poll_time); |
| 295 | |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | /* This function starts the interrupt polling timer. */ |
| 300 | static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds) |
| 301 | { |
| 302 | if (!php_ctlr) { |
| 303 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | if ( ( seconds <= 0 ) || ( seconds > 60 ) ) |
| 308 | seconds = 2; /* Clamp to sane value */ |
| 309 | |
| 310 | php_ctlr->int_poll_timer.function = &int_poll_timeout; |
| 311 | php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */ |
| 312 | php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ; |
| 313 | add_timer(&php_ctlr->int_poll_timer); |
| 314 | |
| 315 | return; |
| 316 | } |
| 317 | |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 318 | static inline int shpc_wait_cmd(struct controller *ctrl) |
| 319 | { |
| 320 | int retval = 0; |
| 321 | unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000; |
| 322 | unsigned long timeout = msecs_to_jiffies(timeout_msec); |
| 323 | int rc = wait_event_interruptible_timeout(ctrl->queue, |
| 324 | !ctrl->cmd_busy, timeout); |
| 325 | if (!rc) { |
| 326 | retval = -EIO; |
| 327 | err("Command not completed in %d msec\n", timeout_msec); |
| 328 | } else if (rc < 0) { |
| 329 | retval = -EINTR; |
| 330 | info("Command was interrupted by a signal\n"); |
| 331 | } |
| 332 | ctrl->cmd_busy = 0; |
| 333 | |
| 334 | return retval; |
| 335 | } |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) |
| 338 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 339 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | u16 cmd_status; |
| 341 | int retval = 0; |
| 342 | u16 temp_word; |
| 343 | int i; |
| 344 | |
| 345 | DBG_ENTER_ROUTINE |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 346 | |
| 347 | mutex_lock(&slot->ctrl->cmd_lock); |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | for (i = 0; i < 10; i++) { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 350 | cmd_status = shpc_readw(ctrl, CMD_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | if (!(cmd_status & 0x1)) |
| 353 | break; |
| 354 | /* Check every 0.1 sec for a total of 1 sec*/ |
| 355 | msleep(100); |
| 356 | } |
| 357 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 358 | cmd_status = shpc_readw(ctrl, CMD_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | if (cmd_status & 0x1) { |
| 361 | /* After 1 sec and and the controller is still busy */ |
| 362 | err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 363 | retval = -EBUSY; |
| 364 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | ++t_slot; |
| 368 | temp_word = (t_slot << 8) | (cmd & 0xFF); |
| 369 | dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd); |
| 370 | |
| 371 | /* To make sure the Controller Busy bit is 0 before we send out the |
| 372 | * command. |
| 373 | */ |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 374 | slot->ctrl->cmd_busy = 1; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 375 | shpc_writew(ctrl, CMD, temp_word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 377 | /* |
| 378 | * Wait for command completion. |
| 379 | */ |
| 380 | retval = shpc_wait_cmd(slot->ctrl); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 381 | if (retval) |
| 382 | goto out; |
| 383 | |
| 384 | cmd_status = hpc_check_cmd_status(slot->ctrl); |
| 385 | if (cmd_status) { |
| 386 | err("%s: Failed to issued command 0x%x (error code = %d)\n", |
| 387 | __FUNCTION__, cmd, cmd_status); |
| 388 | retval = -EIO; |
| 389 | } |
| 390 | out: |
| 391 | mutex_unlock(&slot->ctrl->cmd_lock); |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | DBG_LEAVE_ROUTINE |
| 394 | return retval; |
| 395 | } |
| 396 | |
| 397 | static int hpc_check_cmd_status(struct controller *ctrl) |
| 398 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | u16 cmd_status; |
| 400 | int retval = 0; |
| 401 | |
| 402 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 404 | cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | switch (cmd_status >> 1) { |
| 407 | case 0: |
| 408 | retval = 0; |
| 409 | break; |
| 410 | case 1: |
| 411 | retval = SWITCH_OPEN; |
| 412 | err("%s: Switch opened!\n", __FUNCTION__); |
| 413 | break; |
| 414 | case 2: |
| 415 | retval = INVALID_CMD; |
| 416 | err("%s: Invalid HPC command!\n", __FUNCTION__); |
| 417 | break; |
| 418 | case 4: |
| 419 | retval = INVALID_SPEED_MODE; |
| 420 | err("%s: Invalid bus speed/mode!\n", __FUNCTION__); |
| 421 | break; |
| 422 | default: |
| 423 | retval = cmd_status; |
| 424 | } |
| 425 | |
| 426 | DBG_LEAVE_ROUTINE |
| 427 | return retval; |
| 428 | } |
| 429 | |
| 430 | |
| 431 | static int hpc_get_attention_status(struct slot *slot, u8 *status) |
| 432 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 433 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | u32 slot_reg; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 435 | u8 state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | DBG_ENTER_ROUTINE |
| 438 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 439 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 440 | state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 442 | switch (state) { |
| 443 | case ATN_LED_STATE_ON: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | *status = 1; /* On */ |
| 445 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 446 | case ATN_LED_STATE_BLINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | *status = 2; /* Blink */ |
| 448 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 449 | case ATN_LED_STATE_OFF: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | *status = 0; /* Off */ |
| 451 | break; |
| 452 | default: |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 453 | *status = 0xFF; /* Reserved */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | |
| 457 | DBG_LEAVE_ROUTINE |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int hpc_get_power_status(struct slot * slot, u8 *status) |
| 462 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 463 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | u32 slot_reg; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 465 | u8 state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | DBG_ENTER_ROUTINE |
| 468 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 469 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 470 | state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 472 | switch (state) { |
| 473 | case SLOT_STATE_PWRONLY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | *status = 2; /* Powered only */ |
| 475 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 476 | case SLOT_STATE_ENABLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | *status = 1; /* Enabled */ |
| 478 | break; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 479 | case SLOT_STATE_DISABLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | *status = 0; /* Disabled */ |
| 481 | break; |
| 482 | default: |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 483 | *status = 0xFF; /* Reserved */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | break; |
| 485 | } |
| 486 | |
| 487 | DBG_LEAVE_ROUTINE |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 488 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | |
| 492 | static int hpc_get_latch_status(struct slot *slot, u8 *status) |
| 493 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 494 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | u32 slot_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | DBG_ENTER_ROUTINE |
| 498 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 499 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 500 | *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | DBG_LEAVE_ROUTINE |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static int hpc_get_adapter_status(struct slot *slot, u8 *status) |
| 507 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 508 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | u32 slot_reg; |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 510 | u8 state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | DBG_ENTER_ROUTINE |
| 513 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 514 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 515 | state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT; |
| 516 | *status = (state != 0x3) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | DBG_LEAVE_ROUTINE |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static int hpc_get_prog_int(struct slot *slot, u8 *prog_int) |
| 523 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 524 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 528 | *prog_int = shpc_readb(ctrl, PROG_INTERFACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | DBG_LEAVE_ROUTINE |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value) |
| 535 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | int retval = 0; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 537 | struct controller *ctrl = slot->ctrl; |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 538 | u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 539 | u8 m66_cap = !!(slot_reg & MHZ66_CAP); |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 540 | u8 pi, pcix_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | DBG_ENTER_ROUTINE |
| 543 | |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 544 | if ((retval = hpc_get_prog_int(slot, &pi))) |
| 545 | return retval; |
| 546 | |
| 547 | switch (pi) { |
| 548 | case 1: |
| 549 | pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT; |
| 550 | break; |
| 551 | case 2: |
| 552 | pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT; |
| 553 | break; |
| 554 | default: |
| 555 | return -ENODEV; |
| 556 | } |
| 557 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 558 | dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n", |
| 559 | __FUNCTION__, slot_reg, pcix_cap, m66_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 561 | switch (pcix_cap) { |
| 562 | case 0x0: |
| 563 | *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz; |
| 564 | break; |
| 565 | case 0x1: |
| 566 | *value = PCI_SPEED_66MHz_PCIX; |
| 567 | break; |
| 568 | case 0x3: |
| 569 | *value = PCI_SPEED_133MHz_PCIX; |
| 570 | break; |
| 571 | case 0x4: |
| 572 | *value = PCI_SPEED_133MHz_PCIX_266; |
| 573 | break; |
| 574 | case 0x5: |
| 575 | *value = PCI_SPEED_133MHz_PCIX_533; |
| 576 | break; |
| 577 | case 0x2: |
| 578 | default: |
| 579 | *value = PCI_SPEED_UNKNOWN; |
| 580 | retval = -ENODEV; |
| 581 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | dbg("Adapter speed = %d\n", *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | DBG_LEAVE_ROUTINE |
| 586 | return retval; |
| 587 | } |
| 588 | |
| 589 | static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode) |
| 590 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 591 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | u16 sec_bus_status; |
| 593 | u8 pi; |
| 594 | int retval = 0; |
| 595 | |
| 596 | DBG_ENTER_ROUTINE |
| 597 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 598 | pi = shpc_readb(ctrl, PROG_INTERFACE); |
| 599 | sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | if (pi == 2) { |
Kenji Kaneshige | 87d6c55 | 2005-11-24 11:35:05 +0900 | [diff] [blame] | 602 | *mode = (sec_bus_status & 0x0100) >> 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } else { |
| 604 | retval = -1; |
| 605 | } |
| 606 | |
| 607 | dbg("Mode 1 ECC cap = %d\n", *mode); |
| 608 | |
| 609 | DBG_LEAVE_ROUTINE |
| 610 | return retval; |
| 611 | } |
| 612 | |
| 613 | static int hpc_query_power_fault(struct slot * slot) |
| 614 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 615 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | u32 slot_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | DBG_ENTER_ROUTINE |
| 619 | |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 620 | slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | DBG_LEAVE_ROUTINE |
| 623 | /* Note: Logic 0 => fault */ |
Kenji Kaneshige | 5858759 | 2006-05-02 11:10:37 +0900 | [diff] [blame] | 624 | return !(slot_reg & POWER_FAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static int hpc_set_attention_status(struct slot *slot, u8 value) |
| 628 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | u8 slot_cmd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | switch (value) { |
| 632 | case 0 : |
| 633 | slot_cmd = 0x30; /* OFF */ |
| 634 | break; |
| 635 | case 1: |
| 636 | slot_cmd = 0x10; /* ON */ |
| 637 | break; |
| 638 | case 2: |
| 639 | slot_cmd = 0x20; /* BLINK */ |
| 640 | break; |
| 641 | default: |
| 642 | return -1; |
| 643 | } |
| 644 | |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 645 | return shpc_write_cmd(slot, slot->hp_slot, slot_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | |
| 649 | static void hpc_set_green_led_on(struct slot *slot) |
| 650 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 651 | shpc_write_cmd(slot, slot->hp_slot, 0x04); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static void hpc_set_green_led_off(struct slot *slot) |
| 655 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 656 | shpc_write_cmd(slot, slot->hp_slot, 0x0c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static void hpc_set_green_led_blink(struct slot *slot) |
| 660 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 661 | shpc_write_cmd(slot, slot->hp_slot, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | int shpc_get_ctlr_slot_config(struct controller *ctrl, |
| 665 | int *num_ctlr_slots, /* number of slots in this HPC */ |
| 666 | int *first_device_num, /* PCI dev num of the first slot in this SHPC */ |
| 667 | int *physical_slot_num, /* phy slot num of the first slot in this SHPC */ |
| 668 | int *updown, /* physical_slot_num increament: 1 or -1 */ |
| 669 | int *flags) |
| 670 | { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 671 | u32 slot_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
| 673 | DBG_ENTER_ROUTINE |
| 674 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 675 | slot_config = shpc_readl(ctrl, SLOT_CONFIG); |
| 676 | *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8; |
| 677 | *num_ctlr_slots = slot_config & SLOT_NUM; |
| 678 | *physical_slot_num = (slot_config & PSN) >> 16; |
| 679 | *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | DBG_LEAVE_ROUTINE |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | static void hpc_release_ctlr(struct controller *ctrl) |
| 688 | { |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 689 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | struct php_ctlr_state_s *p, *p_prev; |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 691 | int i; |
Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 692 | u32 slot_reg, serr_int; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | DBG_ENTER_ROUTINE |
| 695 | |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 696 | /* |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 697 | * Mask event interrupts and SERRs of all slots |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 698 | */ |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 699 | for (i = 0; i < ctrl->num_slots; i++) { |
| 700 | slot_reg = shpc_readl(ctrl, SLOT_REG(i)); |
| 701 | slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | |
| 702 | BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | |
| 703 | CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK | |
| 704 | CON_PFAULT_SERR_MASK); |
| 705 | slot_reg &= ~SLOT_REG_RSVDZ_MASK; |
| 706 | shpc_writel(ctrl, SLOT_REG(i), slot_reg); |
| 707 | } |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 708 | |
| 709 | cleanup_slots(ctrl); |
| 710 | |
Kenji Kaneshige | d49f2c4 | 2006-05-03 23:34:17 +0900 | [diff] [blame] | 711 | /* |
| 712 | * Mask SERR and System Interrut generation |
| 713 | */ |
| 714 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 715 | serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK | |
| 716 | COMMAND_INTR_MASK | ARBITER_SERR_MASK); |
| 717 | serr_int &= ~SERR_INTR_RSVDZ_MASK; |
| 718 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
| 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | if (shpchp_poll_mode) { |
| 721 | del_timer(&php_ctlr->int_poll_timer); |
| 722 | } else { |
| 723 | if (php_ctlr->irq) { |
| 724 | free_irq(php_ctlr->irq, ctrl); |
| 725 | php_ctlr->irq = 0; |
| 726 | pci_disable_msi(php_ctlr->pci_dev); |
| 727 | } |
| 728 | } |
Kenji Kaneshige | f7391f5 | 2006-02-21 15:45:45 -0800 | [diff] [blame] | 729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | if (php_ctlr->pci_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | iounmap(php_ctlr->creg); |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 732 | release_mem_region(ctrl->mmio_base, ctrl->mmio_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | php_ctlr->pci_dev = NULL; |
| 734 | } |
| 735 | |
| 736 | spin_lock(&list_lock); |
| 737 | p = php_ctlr_list_head; |
| 738 | p_prev = NULL; |
| 739 | while (p) { |
| 740 | if (p == php_ctlr) { |
| 741 | if (p_prev) |
| 742 | p_prev->pnext = p->pnext; |
| 743 | else |
| 744 | php_ctlr_list_head = p->pnext; |
| 745 | break; |
| 746 | } else { |
| 747 | p_prev = p; |
| 748 | p = p->pnext; |
| 749 | } |
| 750 | } |
| 751 | spin_unlock(&list_lock); |
| 752 | |
| 753 | kfree(php_ctlr); |
| 754 | |
Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 755 | /* |
| 756 | * If this is the last controller to be released, destroy the |
| 757 | * shpchpd work queue |
| 758 | */ |
| 759 | if (atomic_dec_and_test(&shpchp_num_controllers)) |
| 760 | destroy_workqueue(shpchp_wq); |
| 761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | DBG_LEAVE_ROUTINE |
| 763 | |
| 764 | } |
| 765 | |
| 766 | static int hpc_power_on_slot(struct slot * slot) |
| 767 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 768 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | DBG_ENTER_ROUTINE |
| 771 | |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 772 | retval = shpc_write_cmd(slot, slot->hp_slot, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | if (retval) { |
| 774 | err("%s: Write command failed!\n", __FUNCTION__); |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 775 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | DBG_LEAVE_ROUTINE |
| 779 | |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 780 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | static int hpc_slot_enable(struct slot * slot) |
| 784 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 785 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | DBG_ENTER_ROUTINE |
| 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /* 3A => Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */ |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 790 | retval = shpc_write_cmd(slot, slot->hp_slot, 0x3a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | if (retval) { |
| 792 | err("%s: Write command failed!\n", __FUNCTION__); |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 793 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | DBG_LEAVE_ROUTINE |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 797 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | static int hpc_slot_disable(struct slot * slot) |
| 801 | { |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 802 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | DBG_ENTER_ROUTINE |
| 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | /* 1F => Slot - Disable, Power Indicator - Off, Attention Indicator - On */ |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 807 | retval = shpc_write_cmd(slot, slot->hp_slot, 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (retval) { |
| 809 | err("%s: Write command failed!\n", __FUNCTION__); |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 810 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | DBG_LEAVE_ROUTINE |
Kenji Kaneshige | d4fbf60 | 2006-05-12 11:05:59 +0900 | [diff] [blame] | 814 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) |
| 818 | { |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 819 | int retval; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 820 | struct controller *ctrl = slot->ctrl; |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 821 | u8 pi, cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | DBG_ENTER_ROUTINE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 825 | pi = shpc_readb(ctrl, PROG_INTERFACE); |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 826 | if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX)) |
| 827 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 829 | switch (value) { |
| 830 | case PCI_SPEED_33MHz: |
| 831 | cmd = SETA_PCI_33MHZ; |
| 832 | break; |
| 833 | case PCI_SPEED_66MHz: |
| 834 | cmd = SETA_PCI_66MHZ; |
| 835 | break; |
| 836 | case PCI_SPEED_66MHz_PCIX: |
| 837 | cmd = SETA_PCIX_66MHZ; |
| 838 | break; |
| 839 | case PCI_SPEED_100MHz_PCIX: |
| 840 | cmd = SETA_PCIX_100MHZ; |
| 841 | break; |
| 842 | case PCI_SPEED_133MHz_PCIX: |
| 843 | cmd = SETA_PCIX_133MHZ; |
| 844 | break; |
| 845 | case PCI_SPEED_66MHz_PCIX_ECC: |
| 846 | cmd = SETB_PCIX_66MHZ_EM; |
| 847 | break; |
| 848 | case PCI_SPEED_100MHz_PCIX_ECC: |
| 849 | cmd = SETB_PCIX_100MHZ_EM; |
| 850 | break; |
| 851 | case PCI_SPEED_133MHz_PCIX_ECC: |
| 852 | cmd = SETB_PCIX_133MHZ_EM; |
| 853 | break; |
| 854 | case PCI_SPEED_66MHz_PCIX_266: |
| 855 | cmd = SETB_PCIX_66MHZ_266; |
| 856 | break; |
| 857 | case PCI_SPEED_100MHz_PCIX_266: |
| 858 | cmd = SETB_PCIX_100MHZ_266; |
| 859 | break; |
| 860 | case PCI_SPEED_133MHz_PCIX_266: |
| 861 | cmd = SETB_PCIX_133MHZ_266; |
| 862 | break; |
| 863 | case PCI_SPEED_66MHz_PCIX_533: |
| 864 | cmd = SETB_PCIX_66MHZ_533; |
| 865 | break; |
| 866 | case PCI_SPEED_100MHz_PCIX_533: |
| 867 | cmd = SETB_PCIX_100MHZ_533; |
| 868 | break; |
| 869 | case PCI_SPEED_133MHz_PCIX_533: |
| 870 | cmd = SETB_PCIX_133MHZ_533; |
| 871 | break; |
| 872 | default: |
| 873 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 875 | |
| 876 | retval = shpc_write_cmd(slot, 0, cmd); |
| 877 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | err("%s: Write command failed!\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
| 880 | DBG_LEAVE_ROUTINE |
| 881 | return retval; |
| 882 | } |
| 883 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 884 | static irqreturn_t shpc_isr(int irq, void *dev_id, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | { |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 886 | struct controller *ctrl = (struct controller *)dev_id; |
| 887 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; |
| 888 | u32 serr_int, slot_reg, intr_loc, intr_loc2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | int hp_slot; |
| 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | /* Check to see if it was our interrupt */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 892 | intr_loc = shpc_readl(ctrl, INTR_LOC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | if (!intr_loc) |
| 894 | return IRQ_NONE; |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); |
| 897 | |
| 898 | if(!shpchp_poll_mode) { |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 899 | /* |
| 900 | * Mask Global Interrupt Mask - see implementation |
| 901 | * note on p. 139 of SHPC spec rev 1.0 |
| 902 | */ |
| 903 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 904 | serr_int |= GLOBAL_INTR_MASK; |
| 905 | serr_int &= ~SERR_INTR_RSVDZ_MASK; |
| 906 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 908 | intr_loc2 = shpc_readl(ctrl, INTR_LOC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); |
| 910 | } |
| 911 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 912 | if (intr_loc & CMD_INTR_PENDING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | /* |
| 914 | * Command Complete Interrupt Pending |
Kenji Kaneshige | f467f61 | 2005-11-24 11:39:29 +0900 | [diff] [blame] | 915 | * RO only - clear by writing 1 to the Command Completion |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | * Detect bit in Controller SERR-INT register |
| 917 | */ |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 918 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 919 | serr_int &= ~SERR_INTR_RSVDZ_MASK; |
| 920 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
| 921 | |
Kenji Kaneshige | bd62e27 | 2005-11-25 12:28:53 +0900 | [diff] [blame] | 922 | ctrl->cmd_busy = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | wake_up_interruptible(&ctrl->queue); |
| 924 | } |
| 925 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 926 | if (!(intr_loc & ~CMD_INTR_PENDING)) |
Kenji Kaneshige | e4e7304 | 2006-01-26 10:05:57 +0900 | [diff] [blame] | 927 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 930 | /* To find out which slot has interrupt pending */ |
| 931 | if (!(intr_loc & SLOT_INTR_PENDING(hp_slot))) |
| 932 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 934 | slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); |
| 935 | dbg("%s: Slot %x with intr, slot register = %x\n", |
| 936 | __FUNCTION__, hp_slot, slot_reg); |
| 937 | |
| 938 | if (slot_reg & MRL_CHANGE_DETECTED) |
| 939 | php_ctlr->switch_change_callback( |
| 940 | hp_slot, php_ctlr->callback_instance_id); |
| 941 | |
| 942 | if (slot_reg & BUTTON_PRESS_DETECTED) |
| 943 | php_ctlr->attention_button_callback( |
| 944 | hp_slot, php_ctlr->callback_instance_id); |
| 945 | |
| 946 | if (slot_reg & PRSNT_CHANGE_DETECTED) |
| 947 | php_ctlr->presence_change_callback( |
| 948 | hp_slot , php_ctlr->callback_instance_id); |
| 949 | |
| 950 | if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)) |
| 951 | php_ctlr->power_fault_callback( |
| 952 | hp_slot, php_ctlr->callback_instance_id); |
| 953 | |
| 954 | /* Clear all slot events */ |
| 955 | slot_reg &= ~SLOT_REG_RSVDZ_MASK; |
| 956 | shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } |
Kenji Kaneshige | e4e7304 | 2006-01-26 10:05:57 +0900 | [diff] [blame] | 958 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | if (!shpchp_poll_mode) { |
| 960 | /* Unmask Global Interrupt Mask */ |
Kenji Kaneshige | c4cecc1 | 2006-05-12 11:10:56 +0900 | [diff] [blame^] | 961 | serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE); |
| 962 | serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK); |
| 963 | shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | return IRQ_HANDLED; |
| 967 | } |
| 968 | |
| 969 | static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value) |
| 970 | { |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 971 | int retval = 0; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 972 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 974 | u8 pi = shpc_readb(ctrl, PROG_INTERFACE); |
| 975 | u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1); |
| 976 | u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | DBG_ENTER_ROUTINE |
| 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | if (pi == 2) { |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 981 | if (slot_avail2 & SLOT_133MHZ_PCIX_533) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 982 | bus_speed = PCI_SPEED_133MHz_PCIX_533; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 983 | else if (slot_avail2 & SLOT_100MHZ_PCIX_533) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 984 | bus_speed = PCI_SPEED_100MHz_PCIX_533; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 985 | else if (slot_avail2 & SLOT_66MHZ_PCIX_533) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 986 | bus_speed = PCI_SPEED_66MHz_PCIX_533; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 987 | else if (slot_avail2 & SLOT_133MHZ_PCIX_266) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 988 | bus_speed = PCI_SPEED_133MHz_PCIX_266; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 989 | else if (slot_avail2 & SLOT_100MHZ_PCIX_266) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 990 | bus_speed = PCI_SPEED_100MHz_PCIX_266; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 991 | else if (slot_avail2 & SLOT_66MHZ_PCIX_266) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 992 | bus_speed = PCI_SPEED_66MHz_PCIX_266; |
| 993 | } |
| 994 | |
| 995 | if (bus_speed == PCI_SPEED_UNKNOWN) { |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 996 | if (slot_avail1 & SLOT_133MHZ_PCIX) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 997 | bus_speed = PCI_SPEED_133MHz_PCIX; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 998 | else if (slot_avail1 & SLOT_100MHZ_PCIX) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 999 | bus_speed = PCI_SPEED_100MHz_PCIX; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 1000 | else if (slot_avail1 & SLOT_66MHZ_PCIX) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1001 | bus_speed = PCI_SPEED_66MHz_PCIX; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 1002 | else if (slot_avail2 & SLOT_66MHZ) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1003 | bus_speed = PCI_SPEED_66MHz; |
Kenji Kaneshige | 6558b6a | 2005-11-24 13:44:01 +0900 | [diff] [blame] | 1004 | else if (slot_avail1 & SLOT_33MHZ) |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1005 | bus_speed = PCI_SPEED_33MHz; |
| 1006 | else |
| 1007 | retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | *value = bus_speed; |
| 1011 | dbg("Max bus speed = %d\n", bus_speed); |
| 1012 | DBG_LEAVE_ROUTINE |
| 1013 | return retval; |
| 1014 | } |
| 1015 | |
| 1016 | static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value) |
| 1017 | { |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1018 | int retval = 0; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1019 | struct controller *ctrl = slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1021 | u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG); |
| 1022 | u8 pi = shpc_readb(ctrl, PROG_INTERFACE); |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1023 | u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | DBG_ENTER_ROUTINE |
| 1026 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1027 | if ((pi == 1) && (speed_mode > 4)) { |
| 1028 | *value = PCI_SPEED_UNKNOWN; |
| 1029 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Kenji Kaneshige | 0afabe9 | 2006-03-01 14:55:11 +0900 | [diff] [blame] | 1032 | switch (speed_mode) { |
| 1033 | case 0x0: |
| 1034 | *value = PCI_SPEED_33MHz; |
| 1035 | break; |
| 1036 | case 0x1: |
| 1037 | *value = PCI_SPEED_66MHz; |
| 1038 | break; |
| 1039 | case 0x2: |
| 1040 | *value = PCI_SPEED_66MHz_PCIX; |
| 1041 | break; |
| 1042 | case 0x3: |
| 1043 | *value = PCI_SPEED_100MHz_PCIX; |
| 1044 | break; |
| 1045 | case 0x4: |
| 1046 | *value = PCI_SPEED_133MHz_PCIX; |
| 1047 | break; |
| 1048 | case 0x5: |
| 1049 | *value = PCI_SPEED_66MHz_PCIX_ECC; |
| 1050 | break; |
| 1051 | case 0x6: |
| 1052 | *value = PCI_SPEED_100MHz_PCIX_ECC; |
| 1053 | break; |
| 1054 | case 0x7: |
| 1055 | *value = PCI_SPEED_133MHz_PCIX_ECC; |
| 1056 | break; |
| 1057 | case 0x8: |
| 1058 | *value = PCI_SPEED_66MHz_PCIX_266; |
| 1059 | break; |
| 1060 | case 0x9: |
| 1061 | *value = PCI_SPEED_100MHz_PCIX_266; |
| 1062 | break; |
| 1063 | case 0xa: |
| 1064 | *value = PCI_SPEED_133MHz_PCIX_266; |
| 1065 | break; |
| 1066 | case 0xb: |
| 1067 | *value = PCI_SPEED_66MHz_PCIX_533; |
| 1068 | break; |
| 1069 | case 0xc: |
| 1070 | *value = PCI_SPEED_100MHz_PCIX_533; |
| 1071 | break; |
| 1072 | case 0xd: |
| 1073 | *value = PCI_SPEED_133MHz_PCIX_533; |
| 1074 | break; |
| 1075 | default: |
| 1076 | *value = PCI_SPEED_UNKNOWN; |
| 1077 | retval = -ENODEV; |
| 1078 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | dbg("Current bus speed = %d\n", bus_speed); |
| 1082 | DBG_LEAVE_ROUTINE |
| 1083 | return retval; |
| 1084 | } |
| 1085 | |
| 1086 | static struct hpc_ops shpchp_hpc_ops = { |
| 1087 | .power_on_slot = hpc_power_on_slot, |
| 1088 | .slot_enable = hpc_slot_enable, |
| 1089 | .slot_disable = hpc_slot_disable, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | .set_bus_speed_mode = hpc_set_bus_speed_mode, |
| 1091 | .set_attention_status = hpc_set_attention_status, |
| 1092 | .get_power_status = hpc_get_power_status, |
| 1093 | .get_attention_status = hpc_get_attention_status, |
| 1094 | .get_latch_status = hpc_get_latch_status, |
| 1095 | .get_adapter_status = hpc_get_adapter_status, |
| 1096 | |
| 1097 | .get_max_bus_speed = hpc_get_max_bus_speed, |
| 1098 | .get_cur_bus_speed = hpc_get_cur_bus_speed, |
| 1099 | .get_adapter_speed = hpc_get_adapter_speed, |
| 1100 | .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap, |
| 1101 | .get_prog_int = hpc_get_prog_int, |
| 1102 | |
| 1103 | .query_power_fault = hpc_query_power_fault, |
| 1104 | .green_led_on = hpc_set_green_led_on, |
| 1105 | .green_led_off = hpc_set_green_led_off, |
| 1106 | .green_led_blink = hpc_set_green_led_blink, |
| 1107 | |
| 1108 | .release_ctlr = hpc_release_ctlr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | }; |
| 1110 | |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 1111 | int shpc_init(struct controller * ctrl, struct pci_dev * pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | { |
| 1113 | struct php_ctlr_state_s *php_ctlr, *p; |
| 1114 | void *instance_id = ctrl; |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1115 | int rc, num_slots = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | u8 hp_slot; |
| 1117 | static int first = 1; |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1118 | u32 shpc_base_offset; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1119 | u32 tempdword, slot_reg, slot_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | u8 i; |
| 1121 | |
| 1122 | DBG_ENTER_ROUTINE |
| 1123 | |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1124 | ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ |
| 1125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | spin_lock_init(&list_lock); |
Kenji Kaneshige | 57c95c0 | 2006-01-26 10:02:41 +0900 | [diff] [blame] | 1127 | php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
| 1129 | if (!php_ctlr) { /* allocate controller state data */ |
| 1130 | err("%s: HPC controller memory allocation error!\n", __FUNCTION__); |
| 1131 | goto abort; |
| 1132 | } |
| 1133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | php_ctlr->pci_dev = pdev; /* save pci_dev in context */ |
| 1135 | |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 1136 | if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == |
| 1137 | PCI_DEVICE_ID_AMD_GOLAM_7450)) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1138 | /* amd shpc driver doesn't use Base Offset; assume 0 */ |
| 1139 | ctrl->mmio_base = pci_resource_start(pdev, 0); |
| 1140 | ctrl->mmio_size = pci_resource_len(pdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | } else { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1142 | ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC); |
| 1143 | if (!ctrl->cap_offset) { |
| 1144 | err("%s : cap_offset == 0\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | goto abort_free_ctlr; |
| 1146 | } |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1147 | dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset); |
| 1148 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1149 | rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | if (rc) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1151 | err("%s: cannot read base_offset\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | goto abort_free_ctlr; |
| 1153 | } |
| 1154 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1155 | rc = shpc_indirect_read(ctrl, 3, &tempdword); |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1156 | if (rc) { |
| 1157 | err("%s: cannot read slot config\n", __FUNCTION__); |
| 1158 | goto abort_free_ctlr; |
| 1159 | } |
| 1160 | num_slots = tempdword & SLOT_NUM; |
| 1161 | dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots); |
| 1162 | |
| 1163 | for (i = 0; i < 9 + num_slots; i++) { |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1164 | rc = shpc_indirect_read(ctrl, i, &tempdword); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | if (rc) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1166 | err("%s: cannot read creg (index = %d)\n", |
| 1167 | __FUNCTION__, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | goto abort_free_ctlr; |
| 1169 | } |
rajesh.shah@intel.com | 7c8942f | 2005-10-13 12:05:43 -0700 | [diff] [blame] | 1170 | dbg("%s: offset %d: value %x\n", __FUNCTION__,i, |
| 1171 | tempdword); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1173 | |
| 1174 | ctrl->mmio_base = |
| 1175 | pci_resource_start(pdev, 0) + shpc_base_offset; |
| 1176 | ctrl->mmio_size = 0x24 + 0x4 * num_slots; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | if (first) { |
| 1180 | spin_lock_init(&hpc_event_lock); |
| 1181 | first = 0; |
| 1182 | } |
| 1183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, |
| 1185 | pdev->subsystem_device); |
| 1186 | |
| 1187 | if (pci_enable_device(pdev)) |
| 1188 | goto abort_free_ctlr; |
| 1189 | |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1190 | if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | err("%s: cannot reserve MMIO region\n", __FUNCTION__); |
| 1192 | goto abort_free_ctlr; |
| 1193 | } |
| 1194 | |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1195 | php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | if (!php_ctlr->creg) { |
Kenji Kaneshige | 0455986 | 2005-11-24 11:36:59 +0900 | [diff] [blame] | 1197 | err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, |
| 1198 | ctrl->mmio_size, ctrl->mmio_base); |
| 1199 | release_mem_region(ctrl->mmio_base, ctrl->mmio_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | goto abort_free_ctlr; |
| 1201 | } |
| 1202 | dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1204 | mutex_init(&ctrl->crit_sect); |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 1205 | mutex_init(&ctrl->cmd_lock); |
| 1206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | /* Setup wait queue */ |
| 1208 | init_waitqueue_head(&ctrl->queue); |
| 1209 | |
| 1210 | /* Find the IRQ */ |
| 1211 | php_ctlr->irq = pdev->irq; |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 1212 | php_ctlr->attention_button_callback = shpchp_handle_attention_button, |
| 1213 | php_ctlr->switch_change_callback = shpchp_handle_switch_change; |
| 1214 | php_ctlr->presence_change_callback = shpchp_handle_presence_change; |
| 1215 | php_ctlr->power_fault_callback = shpchp_handle_power_fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | php_ctlr->callback_instance_id = instance_id; |
| 1217 | |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1218 | ctrl->hpc_ctlr_handle = php_ctlr; |
| 1219 | ctrl->hpc_ops = &shpchp_hpc_ops; |
| 1220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | /* Return PCI Controller Info */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1222 | slot_config = shpc_readl(ctrl, SLOT_CONFIG); |
| 1223 | php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8; |
| 1224 | php_ctlr->num_slots = slot_config & SLOT_NUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset); |
| 1226 | dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots); |
| 1227 | |
| 1228 | /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1229 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); |
Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 1231 | tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK | |
| 1232 | COMMAND_INTR_MASK | ARBITER_SERR_MASK); |
| 1233 | tempdword &= ~SERR_INTR_RSVDZ_MASK; |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1234 | shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); |
| 1235 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); |
| 1237 | |
| 1238 | /* Mask the MRL sensor SERR Mask of individual slot in |
| 1239 | * Slot SERR-INT Mask & clear all the existing event if any |
| 1240 | */ |
| 1241 | for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 1242 | slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, |
| 1244 | hp_slot, slot_reg); |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1245 | slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | |
| 1246 | BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | |
| 1247 | CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK | |
| 1248 | CON_PFAULT_SERR_MASK); |
| 1249 | slot_reg &= ~SLOT_REG_RSVDZ_MASK; |
| 1250 | shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | if (shpchp_poll_mode) {/* Install interrupt polling code */ |
| 1254 | /* Install and start the interrupt polling timer */ |
| 1255 | init_timer(&php_ctlr->int_poll_timer); |
| 1256 | start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */ |
| 1257 | } else { |
| 1258 | /* Installs the interrupt handler */ |
| 1259 | rc = pci_enable_msi(pdev); |
| 1260 | if (rc) { |
| 1261 | info("Can't get msi for the hotplug controller\n"); |
| 1262 | info("Use INTx for the hotplug controller\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | } else |
| 1264 | php_ctlr->irq = pdev->irq; |
| 1265 | |
| 1266 | rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl); |
| 1267 | dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc); |
| 1268 | if (rc) { |
| 1269 | err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); |
| 1270 | goto abort_free_ctlr; |
| 1271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | } |
rajesh.shah@intel.com | 7c8942f | 2005-10-13 12:05:43 -0700 | [diff] [blame] | 1273 | dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__, |
| 1274 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
| 1275 | PCI_FUNC(pdev->devfn), pdev->irq); |
rajesh.shah@intel.com | 424600f | 2005-10-13 12:05:38 -0700 | [diff] [blame] | 1276 | get_hp_hw_control_from_firmware(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
| 1278 | /* Add this HPC instance into the HPC list */ |
| 1279 | spin_lock(&list_lock); |
| 1280 | if (php_ctlr_list_head == 0) { |
| 1281 | php_ctlr_list_head = php_ctlr; |
| 1282 | p = php_ctlr_list_head; |
| 1283 | p->pnext = NULL; |
| 1284 | } else { |
| 1285 | p = php_ctlr_list_head; |
| 1286 | |
| 1287 | while (p->pnext) |
| 1288 | p = p->pnext; |
| 1289 | |
| 1290 | p->pnext = php_ctlr; |
| 1291 | } |
| 1292 | spin_unlock(&list_lock); |
| 1293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | ctlr_seq_num++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1296 | /* |
Kenji Kaneshige | 82d5f4a | 2006-05-03 23:42:04 +0900 | [diff] [blame] | 1297 | * If this is the first controller to be initialized, |
| 1298 | * initialize the shpchpd work queue |
| 1299 | */ |
| 1300 | if (atomic_add_return(1, &shpchp_num_controllers) == 1) { |
| 1301 | shpchp_wq = create_singlethread_workqueue("shpchpd"); |
| 1302 | if (!shpchp_wq) |
| 1303 | return -ENOMEM; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1307 | * Unmask all event interrupts of all slots |
| 1308 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { |
Kenji Kaneshige | 2b34da7 | 2006-05-02 11:09:42 +0900 | [diff] [blame] | 1310 | slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, |
| 1312 | hp_slot, slot_reg); |
Kenji Kaneshige | 795eb5c | 2006-05-02 11:11:54 +0900 | [diff] [blame] | 1313 | slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK | |
| 1314 | BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK | |
| 1315 | CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK); |
| 1316 | shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | if (!shpchp_poll_mode) { |
| 1319 | /* Unmask all general input interrupts and SERR */ |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1320 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Kenji Kaneshige | e713872 | 2006-05-02 11:12:37 +0900 | [diff] [blame] | 1321 | tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK | |
| 1322 | SERR_INTR_RSVDZ_MASK); |
Kenji Kaneshige | 75d97c5 | 2006-05-02 11:08:42 +0900 | [diff] [blame] | 1323 | shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword); |
| 1324 | tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); |
| 1326 | } |
| 1327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | DBG_LEAVE_ROUTINE |
| 1329 | return 0; |
| 1330 | |
| 1331 | /* We end up here for the many possible ways to fail this API. */ |
| 1332 | abort_free_ctlr: |
| 1333 | kfree(php_ctlr); |
| 1334 | abort: |
| 1335 | DBG_LEAVE_ROUTINE |
| 1336 | return -1; |
| 1337 | } |