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