blob: d8f4f1241b56a9880798723821581755f721391e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Accardi8cf4c192005-08-16 15:16:10 -070026 * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/types.h>
Tim Schmielaude259682006-01-08 01:02:05 -080033#include <linux/signal.h>
34#include <linux/jiffies.h>
35#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/pci.h>
Andrew Morton5d1b8c92005-11-13 16:06:39 -080037#include <linux/interrupt.h>
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "../pci.h"
40#include "pciehp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#ifdef DEBUG
42#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
43#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
44#define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */
45#define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */
46#define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT)
47#define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE)
48/* Redefine this flagword to set debug level */
49#define DEBUG_LEVEL DBG_K_STANDARD
50
51#define DEFINE_DBG_BUFFER char __dbg_str_buf[256];
52
53#define DBG_PRINT( dbg_flags, args... ) \
54 do { \
55 if ( DEBUG_LEVEL & ( dbg_flags ) ) \
56 { \
57 int len; \
58 len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \
59 __FILE__, __LINE__, __FUNCTION__ ); \
60 sprintf( __dbg_str_buf + len, args ); \
61 printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \
62 } \
63 } while (0)
64
65#define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]");
66#define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]");
67#else
68#define DEFINE_DBG_BUFFER
69#define DBG_ENTER_ROUTINE
70#define DBG_LEAVE_ROUTINE
71#endif /* DEBUG */
72
73struct ctrl_reg {
74 u8 cap_id;
75 u8 nxt_ptr;
76 u16 cap_reg;
77 u32 dev_cap;
78 u16 dev_ctrl;
79 u16 dev_status;
80 u32 lnk_cap;
81 u16 lnk_ctrl;
82 u16 lnk_status;
83 u32 slot_cap;
84 u16 slot_ctrl;
85 u16 slot_status;
86 u16 root_ctrl;
87 u16 rsvp;
88 u32 root_status;
89} __attribute__ ((packed));
90
91/* offsets to the controller registers based on the above structure layout */
92enum ctrl_offsets {
93 PCIECAPID = offsetof(struct ctrl_reg, cap_id),
94 NXTCAPPTR = offsetof(struct ctrl_reg, nxt_ptr),
95 CAPREG = offsetof(struct ctrl_reg, cap_reg),
96 DEVCAP = offsetof(struct ctrl_reg, dev_cap),
97 DEVCTRL = offsetof(struct ctrl_reg, dev_ctrl),
98 DEVSTATUS = offsetof(struct ctrl_reg, dev_status),
99 LNKCAP = offsetof(struct ctrl_reg, lnk_cap),
100 LNKCTRL = offsetof(struct ctrl_reg, lnk_ctrl),
101 LNKSTATUS = offsetof(struct ctrl_reg, lnk_status),
102 SLOTCAP = offsetof(struct ctrl_reg, slot_cap),
103 SLOTCTRL = offsetof(struct ctrl_reg, slot_ctrl),
104 SLOTSTATUS = offsetof(struct ctrl_reg, slot_status),
105 ROOTCTRL = offsetof(struct ctrl_reg, root_ctrl),
106 ROOTSTATUS = offsetof(struct ctrl_reg, root_status),
107};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800109static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value)
110{
111 struct pci_dev *dev = ctrl->pci_dev;
112 return pci_read_config_word(dev, ctrl->cap_base + reg, value);
113}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800115static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value)
116{
117 struct pci_dev *dev = ctrl->pci_dev;
118 return pci_read_config_dword(dev, ctrl->cap_base + reg, value);
119}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800121static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value)
122{
123 struct pci_dev *dev = ctrl->pci_dev;
124 return pci_write_config_word(dev, ctrl->cap_base + reg, value);
125}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800127static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
128{
129 struct pci_dev *dev = ctrl->pci_dev;
130 return pci_write_config_dword(dev, ctrl->cap_base + reg, value);
131}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
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 Torvalds1da177e2005-04-16 15:20:36 -0700214static spinlock_t hpc_event_lock;
215
216DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217static int ctlr_seq_num = 0; /* Controller sequence # */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800219static irqreturn_t pcie_isr(int irq, void *dev_id);
220static void start_int_poll_timer(struct controller *ctrl, int sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222/* This is the interrupt polling timeout function. */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800223static void int_poll_timeout(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800225 struct controller *ctrl = (struct controller *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 DBG_ENTER_ROUTINE
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 /* Poll for interrupt events. regs == NULL => polling */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800230 pcie_isr(0, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800232 init_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (!pciehp_poll_time)
234 pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
235
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800236 start_int_poll_timer(ctrl, pciehp_poll_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239/* This function starts the interrupt polling timer. */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800240static void start_int_poll_timer(struct controller *ctrl, int sec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800242 /* Clamp to sane value */
243 if ((sec <= 0) || (sec > 60))
244 sec = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800246 ctrl->poll_timer.function = &int_poll_timeout;
247 ctrl->poll_timer.data = (unsigned long)ctrl;
248 ctrl->poll_timer.expires = jiffies + sec * HZ;
249 add_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252static int pcie_write_cmd(struct slot *slot, u16 cmd)
253{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800254 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 int retval = 0;
256 u16 slot_status;
257
258 DBG_ENTER_ROUTINE
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800259
260 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800262 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
263 return retval;
264 }
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) {
267 /* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue
268 the next command according to spec. Just print out the error message */
269 dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__);
270 }
271
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800272 retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800274 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return retval;
276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 DBG_LEAVE_ROUTINE
279 return retval;
280}
281
282static int hpc_check_lnk_status(struct controller *ctrl)
283{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 u16 lnk_status;
285 int retval = 0;
286
287 DBG_ENTER_ROUTINE
288
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800289 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800291 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return retval;
293 }
294
295 dbg("%s: lnk_status = %x\n", __FUNCTION__, lnk_status);
296 if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) ||
297 !(lnk_status & NEG_LINK_WD)) {
298 err("%s : Link Training Error occurs \n", __FUNCTION__);
299 retval = -1;
300 return retval;
301 }
302
303 DBG_LEAVE_ROUTINE
304 return retval;
305}
306
307
308static int hpc_get_attention_status(struct slot *slot, u8 *status)
309{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800310 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 u16 slot_ctrl;
312 u8 atten_led_state;
313 int retval = 0;
314
315 DBG_ENTER_ROUTINE
316
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800317 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800319 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return retval;
321 }
322
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800323 dbg("%s: SLOTCTRL %x, value read %x\n",
324 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6;
327
328 switch (atten_led_state) {
329 case 0:
330 *status = 0xFF; /* Reserved */
331 break;
332 case 1:
333 *status = 1; /* On */
334 break;
335 case 2:
336 *status = 2; /* Blink */
337 break;
338 case 3:
339 *status = 0; /* Off */
340 break;
341 default:
342 *status = 0xFF;
343 break;
344 }
345
346 DBG_LEAVE_ROUTINE
347 return 0;
348}
349
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800350static int hpc_get_power_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800352 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 u16 slot_ctrl;
354 u8 pwr_state;
355 int retval = 0;
356
357 DBG_ENTER_ROUTINE
358
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800359 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800361 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return retval;
363 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800364 dbg("%s: SLOTCTRL %x value read %x\n",
365 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 pwr_state = (slot_ctrl & PWR_CTRL) >> 10;
368
369 switch (pwr_state) {
370 case 0:
371 *status = 1;
372 break;
373 case 1:
374 *status = 0;
375 break;
376 default:
377 *status = 0xFF;
378 break;
379 }
380
381 DBG_LEAVE_ROUTINE
382 return retval;
383}
384
385
386static int hpc_get_latch_status(struct slot *slot, u8 *status)
387{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800388 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 u16 slot_status;
390 int retval = 0;
391
392 DBG_ENTER_ROUTINE
393
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800394 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800396 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return retval;
398 }
399
400 *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1;
401
402 DBG_LEAVE_ROUTINE
403 return 0;
404}
405
406static int hpc_get_adapter_status(struct slot *slot, u8 *status)
407{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800408 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 u16 slot_status;
410 u8 card_state;
411 int retval = 0;
412
413 DBG_ENTER_ROUTINE
414
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800415 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800417 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return retval;
419 }
420 card_state = (u8)((slot_status & PRSN_STATE) >> 6);
421 *status = (card_state == 1) ? 1 : 0;
422
423 DBG_LEAVE_ROUTINE
424 return 0;
425}
426
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800427static int hpc_query_power_fault(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800429 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 u16 slot_status;
431 u8 pwr_fault;
432 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 DBG_ENTER_ROUTINE
435
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800436 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800438 err("%s: Cannot check for power fault\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 return retval;
440 }
441 pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 DBG_LEAVE_ROUTINE
rajesh.shah@intel.com8239def2005-10-31 16:20:13 -0800444 return pwr_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445}
446
447static int hpc_set_attention_status(struct slot *slot, u8 value)
448{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800449 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 u16 slot_cmd = 0;
451 u16 slot_ctrl;
452 int rc = 0;
453
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800454 DBG_ENTER_ROUTINE
455
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800456 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800458 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return rc;
460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 switch (value) {
463 case 0 : /* turn off */
464 slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x00C0;
465 break;
466 case 1: /* turn on */
467 slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x0040;
468 break;
469 case 2: /* turn blink */
470 slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x0080;
471 break;
472 default:
473 return -1;
474 }
475 if (!pciehp_poll_mode)
476 slot_cmd = slot_cmd | HP_INTR_ENABLE;
477
478 pcie_write_cmd(slot, slot_cmd);
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800479 dbg("%s: SLOTCTRL %x write cmd %x\n",
480 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800482 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return rc;
484}
485
486
487static void hpc_set_green_led_on(struct slot *slot)
488{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800489 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 u16 slot_cmd;
491 u16 slot_ctrl;
492 int rc = 0;
493
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800494 DBG_ENTER_ROUTINE
495
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800496 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800498 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 return;
500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0100;
502 if (!pciehp_poll_mode)
503 slot_cmd = slot_cmd | HP_INTR_ENABLE;
504
505 pcie_write_cmd(slot, slot_cmd);
506
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800507 dbg("%s: SLOTCTRL %x write cmd %x\n",
508 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800509 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 return;
511}
512
513static void hpc_set_green_led_off(struct slot *slot)
514{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800515 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 u16 slot_cmd;
517 u16 slot_ctrl;
518 int rc = 0;
519
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800520 DBG_ENTER_ROUTINE
521
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800522 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800524 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 return;
526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0300;
529
530 if (!pciehp_poll_mode)
531 slot_cmd = slot_cmd | HP_INTR_ENABLE;
532 pcie_write_cmd(slot, slot_cmd);
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800533 dbg("%s: SLOTCTRL %x write cmd %x\n",
534 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800536 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return;
538}
539
540static void hpc_set_green_led_blink(struct slot *slot)
541{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800542 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 u16 slot_cmd;
544 u16 slot_ctrl;
545 int rc = 0;
546
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800547 DBG_ENTER_ROUTINE
548
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800549 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800551 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 return;
553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0200;
556
557 if (!pciehp_poll_mode)
558 slot_cmd = slot_cmd | HP_INTR_ENABLE;
559 pcie_write_cmd(slot, slot_cmd);
560
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800561 dbg("%s: SLOTCTRL %x write cmd %x\n",
562 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800563 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 return;
565}
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567static void hpc_release_ctlr(struct controller *ctrl)
568{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 DBG_ENTER_ROUTINE
570
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800571 if (pciehp_poll_mode)
572 del_timer(&ctrl->poll_timer);
573 else
574 free_irq(ctrl->pci_dev->irq, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579static int hpc_power_on_slot(struct slot * slot)
580{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800581 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 u16 slot_cmd;
Rajesh Shah5a49f202005-11-23 15:44:54 -0800583 u16 slot_ctrl, slot_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 int retval = 0;
585
586 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Rajesh Shah5a49f202005-11-23 15:44:54 -0800590 /* Clear sticky power-fault bit from previous power failures */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800591 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800593 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
594 return retval;
595 }
596 slot_status &= PWR_FAULT_DETECTED;
597 if (slot_status) {
598 retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status);
599 if (retval) {
600 err("%s: Cannot write to SLOTSTATUS register\n",
601 __FUNCTION__);
602 return retval;
603 }
604 }
605
606 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
607 if (retval) {
608 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 return retval;
610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 slot_cmd = (slot_ctrl & ~PWR_CTRL) | POWER_ON;
613
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800614 /* Enable detection that we turned off at slot power-off time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (!pciehp_poll_mode)
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800616 slot_cmd = slot_cmd |
617 PWR_FAULT_DETECT_ENABLE |
618 MRL_DETECT_ENABLE |
619 PRSN_DETECT_ENABLE |
620 HP_INTR_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 retval = pcie_write_cmd(slot, slot_cmd);
623
624 if (retval) {
625 err("%s: Write %x command failed!\n", __FUNCTION__, slot_cmd);
626 return -1;
627 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800628 dbg("%s: SLOTCTRL %x write cmd %x\n",
629 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 DBG_LEAVE_ROUTINE
632
633 return retval;
634}
635
636static int hpc_power_off_slot(struct slot * slot)
637{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800638 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 u16 slot_cmd;
640 u16 slot_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 int retval = 0;
642
643 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800647 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800649 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 return retval;
651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 slot_cmd = (slot_ctrl & ~PWR_CTRL) | POWER_OFF;
654
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800655 /*
656 * If we get MRL or presence detect interrupts now, the isr
657 * will notice the sticky power-fault bit too and issue power
658 * indicator change commands. This will lead to an endless loop
659 * of command completions, since the power-fault bit remains on
660 * till the slot is powered on again.
661 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 if (!pciehp_poll_mode)
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800663 slot_cmd = (slot_cmd &
664 ~PWR_FAULT_DETECT_ENABLE &
665 ~MRL_DETECT_ENABLE &
666 ~PRSN_DETECT_ENABLE) | HP_INTR_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 retval = pcie_write_cmd(slot, slot_cmd);
669
670 if (retval) {
671 err("%s: Write command failed!\n", __FUNCTION__);
672 return -1;
673 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800674 dbg("%s: SLOTCTRL %x write cmd %x\n",
675 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 DBG_LEAVE_ROUTINE
678
679 return retval;
680}
681
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800682static irqreturn_t pcie_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800684 struct controller *ctrl = (struct controller *)dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 u16 slot_status, intr_detect, intr_loc;
686 u16 temp_word;
687 int hp_slot = 0; /* only 1 slot per PCI Express port */
688 int rc = 0;
689
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800690 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800692 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 return IRQ_NONE;
694 }
695
696 intr_detect = ( ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED | MRL_SENS_CHANGED |
697 PRSN_DETECT_CHANGED | CMD_COMPLETED );
698
699 intr_loc = slot_status & intr_detect;
700
701 /* Check to see if it was our interrupt */
702 if ( !intr_loc )
703 return IRQ_NONE;
704
705 dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc);
706 /* Mask Hot-plug Interrupt Enable */
707 if (!pciehp_poll_mode) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800708 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800710 err("%s: Cannot read SLOT_CTRL register\n",
711 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 return IRQ_NONE;
713 }
714
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800715 dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n",
716 __FUNCTION__, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800718 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
719 if (rc) {
720 err("%s: Cannot write to SLOTCTRL register\n",
721 __FUNCTION__);
722 return IRQ_NONE;
723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800725 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800727 err("%s: Cannot read SLOT_STATUS register\n",
728 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return IRQ_NONE;
730 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800731 dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n",
732 __FUNCTION__, slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 /* Clear command complete interrupt caused by this write */
735 temp_word = 0x1f;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800736 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800738 err("%s: Cannot write to SLOTSTATUS register\n",
739 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return IRQ_NONE;
741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743
744 if (intr_loc & CMD_COMPLETED) {
745 /*
746 * Command Complete Interrupt Pending
747 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 wake_up_interruptible(&ctrl->queue);
749 }
750
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800751 if (intr_loc & MRL_SENS_CHANGED)
752 pciehp_handle_switch_change(hp_slot, ctrl);
753
754 if (intr_loc & ATTN_BUTTN_PRESSED)
755 pciehp_handle_attention_button(hp_slot, ctrl);
756
757 if (intr_loc & PRSN_DETECT_CHANGED)
758 pciehp_handle_presence_change(hp_slot, ctrl);
759
760 if (intr_loc & PWR_FAULT_DETECTED)
761 pciehp_handle_power_fault(hp_slot, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /* Clear all events after serving them */
764 temp_word = 0x1F;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800765 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800767 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 return IRQ_NONE;
769 }
770 /* Unmask Hot-plug Interrupt Enable */
771 if (!pciehp_poll_mode) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800772 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800774 err("%s: Cannot read SLOTCTRL register\n",
775 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 return IRQ_NONE;
777 }
778
779 dbg("%s: Unmask Hot-plug Interrupt Enable\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
781
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800782 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800784 err("%s: Cannot write to SLOTCTRL register\n",
785 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 return IRQ_NONE;
787 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800788
789 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800791 err("%s: Cannot read SLOT_STATUS register\n",
792 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 return IRQ_NONE;
794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 /* Clear command complete interrupt caused by this write */
797 temp_word = 0x1F;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800798 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800800 err("%s: Cannot write to SLOTSTATUS failed\n",
801 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return IRQ_NONE;
803 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800804 dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n",
805 __FUNCTION__, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
807
808 return IRQ_HANDLED;
809}
810
811static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value)
812{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800813 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 enum pcie_link_speed lnk_speed;
815 u32 lnk_cap;
816 int retval = 0;
817
818 DBG_ENTER_ROUTINE
819
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800820 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800822 err("%s: Cannot read LNKCAP register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 return retval;
824 }
825
826 switch (lnk_cap & 0x000F) {
827 case 1:
828 lnk_speed = PCIE_2PT5GB;
829 break;
830 default:
831 lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
832 break;
833 }
834
835 *value = lnk_speed;
836 dbg("Max link speed = %d\n", lnk_speed);
837 DBG_LEAVE_ROUTINE
838 return retval;
839}
840
841static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value)
842{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800843 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 enum pcie_link_width lnk_wdth;
845 u32 lnk_cap;
846 int retval = 0;
847
848 DBG_ENTER_ROUTINE
849
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800850 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800852 err("%s: Cannot read LNKCAP register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 return retval;
854 }
855
856 switch ((lnk_cap & 0x03F0) >> 4){
857 case 0:
858 lnk_wdth = PCIE_LNK_WIDTH_RESRV;
859 break;
860 case 1:
861 lnk_wdth = PCIE_LNK_X1;
862 break;
863 case 2:
864 lnk_wdth = PCIE_LNK_X2;
865 break;
866 case 4:
867 lnk_wdth = PCIE_LNK_X4;
868 break;
869 case 8:
870 lnk_wdth = PCIE_LNK_X8;
871 break;
872 case 12:
873 lnk_wdth = PCIE_LNK_X12;
874 break;
875 case 16:
876 lnk_wdth = PCIE_LNK_X16;
877 break;
878 case 32:
879 lnk_wdth = PCIE_LNK_X32;
880 break;
881 default:
882 lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
883 break;
884 }
885
886 *value = lnk_wdth;
887 dbg("Max link width = %d\n", lnk_wdth);
888 DBG_LEAVE_ROUTINE
889 return retval;
890}
891
892static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value)
893{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800894 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN;
896 int retval = 0;
897 u16 lnk_status;
898
899 DBG_ENTER_ROUTINE
900
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800901 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800903 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 return retval;
905 }
906
907 switch (lnk_status & 0x0F) {
908 case 1:
909 lnk_speed = PCIE_2PT5GB;
910 break;
911 default:
912 lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
913 break;
914 }
915
916 *value = lnk_speed;
917 dbg("Current link speed = %d\n", lnk_speed);
918 DBG_LEAVE_ROUTINE
919 return retval;
920}
921
922static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value)
923{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800924 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
926 int retval = 0;
927 u16 lnk_status;
928
929 DBG_ENTER_ROUTINE
930
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800931 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800933 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 return retval;
935 }
936
937 switch ((lnk_status & 0x03F0) >> 4){
938 case 0:
939 lnk_wdth = PCIE_LNK_WIDTH_RESRV;
940 break;
941 case 1:
942 lnk_wdth = PCIE_LNK_X1;
943 break;
944 case 2:
945 lnk_wdth = PCIE_LNK_X2;
946 break;
947 case 4:
948 lnk_wdth = PCIE_LNK_X4;
949 break;
950 case 8:
951 lnk_wdth = PCIE_LNK_X8;
952 break;
953 case 12:
954 lnk_wdth = PCIE_LNK_X12;
955 break;
956 case 16:
957 lnk_wdth = PCIE_LNK_X16;
958 break;
959 case 32:
960 lnk_wdth = PCIE_LNK_X32;
961 break;
962 default:
963 lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
964 break;
965 }
966
967 *value = lnk_wdth;
968 dbg("Current link width = %d\n", lnk_wdth);
969 DBG_LEAVE_ROUTINE
970 return retval;
971}
972
973static struct hpc_ops pciehp_hpc_ops = {
974 .power_on_slot = hpc_power_on_slot,
975 .power_off_slot = hpc_power_off_slot,
976 .set_attention_status = hpc_set_attention_status,
977 .get_power_status = hpc_get_power_status,
978 .get_attention_status = hpc_get_attention_status,
979 .get_latch_status = hpc_get_latch_status,
980 .get_adapter_status = hpc_get_adapter_status,
981
982 .get_max_bus_speed = hpc_get_max_lnk_speed,
983 .get_cur_bus_speed = hpc_get_cur_lnk_speed,
984 .get_max_lnk_width = hpc_get_max_lnk_width,
985 .get_cur_lnk_width = hpc_get_cur_lnk_width,
986
987 .query_power_fault = hpc_query_power_fault,
988 .green_led_on = hpc_set_green_led_on,
989 .green_led_off = hpc_set_green_led_off,
990 .green_led_blink = hpc_set_green_led_blink,
991
992 .release_ctlr = hpc_release_ctlr,
993 .check_lnk_status = hpc_check_lnk_status,
994};
995
Kristen Accardi783c49f2006-03-03 10:16:05 -0800996#ifdef CONFIG_ACPI
997int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
998{
999 acpi_status status;
1000 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
1001 struct pci_dev *pdev = dev;
1002 struct pci_bus *parent;
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001003 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
Kristen Accardi783c49f2006-03-03 10:16:05 -08001004
1005 /*
1006 * Per PCI firmware specification, we should run the ACPI _OSC
1007 * method to get control of hotplug hardware before using it.
1008 * If an _OSC is missing, we look for an OSHP to do the same thing.
1009 * To handle different BIOS behavior, we look for _OSC and OSHP
1010 * within the scope of the hotplug controller and its parents, upto
1011 * the host bridge under which this controller exists.
1012 */
1013 while (!handle) {
1014 /*
1015 * This hotplug controller was not listed in the ACPI name
1016 * space at all. Try to get acpi handle of parent pci bus.
1017 */
1018 if (!pdev || !pdev->bus->parent)
1019 break;
1020 parent = pdev->bus->parent;
1021 dbg("Could not find %s in acpi namespace, trying parent\n",
1022 pci_name(pdev));
1023 if (!parent->self)
1024 /* Parent must be a host bridge */
1025 handle = acpi_get_pci_rootbridge_handle(
1026 pci_domain_nr(parent),
1027 parent->number);
1028 else
1029 handle = DEVICE_ACPI_HANDLE(
1030 &(parent->self->dev));
1031 pdev = parent->self;
1032 }
1033
1034 while (handle) {
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001035 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
1036 dbg("Trying to get hotplug control for %s \n",
1037 (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -08001038 status = pci_osc_control_set(handle,
1039 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1040 if (status == AE_NOT_FOUND)
1041 status = acpi_run_oshp(handle);
1042 if (ACPI_SUCCESS(status)) {
1043 dbg("Gained control for hotplug HW for pci %s (%s)\n",
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001044 pci_name(dev), (char *)string.pointer);
Kristen Accardi81b26bc2006-04-18 14:36:43 -07001045 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -08001046 return 0;
1047 }
1048 if (acpi_root_bridge(handle))
1049 break;
1050 chandle = handle;
1051 status = acpi_get_parent(chandle, &handle);
1052 if (ACPI_FAILURE(status))
1053 break;
1054 }
1055
1056 err("Cannot get control of hotplug hardware for pci %s\n",
1057 pci_name(dev));
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001058
Kristen Accardi81b26bc2006-04-18 14:36:43 -07001059 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -08001060 return -1;
1061}
1062#endif
1063
1064
1065
rajesh.shah@intel.comed6cbcf2005-10-31 16:20:09 -08001066int pcie_init(struct controller * ctrl, struct pcie_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 int rc;
1069 static int first = 1;
1070 u16 temp_word;
1071 u16 cap_reg;
1072 u16 intr_enable = 0;
1073 u32 slot_cap;
Kenji Kaneshige75e13172006-12-21 17:01:08 -08001074 int cap_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 u16 slot_status, slot_ctrl;
1076 struct pci_dev *pdev;
1077
1078 DBG_ENTER_ROUTINE
1079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 pdev = dev->port;
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001081 ctrl->pci_dev = pdev; /* save pci_dev in context */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -08001083 dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n",
1084 __FUNCTION__, pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) {
1087 dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__);
1088 goto abort_free_ctlr;
1089 }
1090
Dely Sy8b245e42005-05-06 17:19:09 -07001091 ctrl->cap_base = cap_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Kenji Kaneshige75e13172006-12-21 17:01:08 -08001093 dbg("%s: pcie_cap_base %x\n", __FUNCTION__, cap_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001095 rc = pciehp_readw(ctrl, CAPREG, &cap_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001097 err("%s: Cannot read CAPREG register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 goto abort_free_ctlr;
1099 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001100 dbg("%s: CAPREG offset %x cap_reg %x\n",
1101 __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Dely Sy8b245e42005-05-06 17:19:09 -07001103 if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040)
1104 && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 dbg("%s : This is not a root port or the port is not connected to a slot\n", __FUNCTION__);
1106 goto abort_free_ctlr;
1107 }
1108
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001109 rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001111 err("%s: Cannot read SLOTCAP register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 goto abort_free_ctlr;
1113 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001114 dbg("%s: SLOTCAP offset %x slot_cap %x\n",
1115 __FUNCTION__, ctrl->cap_base + SLOTCAP, slot_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 if (!(slot_cap & HP_CAP)) {
1118 dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__);
1119 goto abort_free_ctlr;
1120 }
1121 /* For debugging purpose */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001122 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001124 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 goto abort_free_ctlr;
1126 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001127 dbg("%s: SLOTSTATUS offset %x slot_status %x\n",
1128 __FUNCTION__, ctrl->cap_base + SLOTSTATUS, slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001130 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001132 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 goto abort_free_ctlr;
1134 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001135 dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n",
1136 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 if (first) {
1139 spin_lock_init(&hpc_event_lock);
1140 first = 0;
1141 }
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)
1144 if (pci_resource_len(pdev, rc) > 0)
Greg Kroah-Hartman1396a8c2006-06-12 15:14:29 -07001145 dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc,
1146 (unsigned long long)pci_resource_start(pdev, rc),
1147 (unsigned long long)pci_resource_len(pdev, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device,
1150 pdev->subsystem_vendor, pdev->subsystem_device);
1151
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001152 mutex_init(&ctrl->crit_sect);
Kenji Kaneshigedd5619c2006-09-22 10:17:29 -07001153 mutex_init(&ctrl->ctrl_lock);
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 /* setup wait queue */
1156 init_waitqueue_head(&ctrl->queue);
1157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /* return PCI Controller Info */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001159 ctrl->slot_device_offset = 0;
1160 ctrl->num_slots = 1;
1161 ctrl->first_slot = slot_cap >> 19;
1162 ctrl->ctrlcap = slot_cap & 0x0000007f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 /* Mask Hot-plug Interrupt Enable */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001165 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001167 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 goto abort_free_ctlr;
1169 }
1170
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001171 dbg("%s: SLOTCTRL %x value read %x\n",
1172 __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00;
1174
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001175 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001177 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 goto abort_free_ctlr;
1179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001181 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001183 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 goto abort_free_ctlr;
1185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 temp_word = 0x1F; /* Clear all events */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001188 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001190 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 goto abort_free_ctlr;
1192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001194 if (pciehp_poll_mode) {
1195 /* Install interrupt polling timer. Start with 10 sec delay */
1196 init_timer(&ctrl->poll_timer);
1197 start_int_poll_timer(ctrl, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 } else {
1199 /* Installs the interrupt handler */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001200 rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED,
1201 MY_NAME, (void *)ctrl);
1202 dbg("%s: request_irq %d for hpc%d (returns %d)\n",
1203 __FUNCTION__, ctrl->pci_dev->irq, ctlr_seq_num, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (rc) {
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001205 err("Can't get irq %d for the hotplug controller\n",
1206 ctrl->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 goto abort_free_ctlr;
1208 }
1209 }
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -08001210 dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number,
1211 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq);
1212
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001213 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001215 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001216 goto abort_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 intr_enable = intr_enable | PRSN_DETECT_ENABLE;
1220
1221 if (ATTN_BUTTN(slot_cap))
1222 intr_enable = intr_enable | ATTN_BUTTN_ENABLE;
1223
1224 if (POWER_CTRL(slot_cap))
1225 intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE;
1226
1227 if (MRL_SENS(slot_cap))
1228 intr_enable = intr_enable | MRL_DETECT_ENABLE;
1229
1230 temp_word = (temp_word & ~intr_enable) | intr_enable;
1231
1232 if (pciehp_poll_mode) {
1233 temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0;
1234 } else {
1235 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
1236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238 /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001239 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001241 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001242 goto abort_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001244 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001246 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001247 goto abort_disable_intr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 temp_word = 0x1F; /* Clear all events */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001251 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001253 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001254 goto abort_disable_intr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
rajesh.shah@intel.coma3a45ec2005-10-31 16:20:12 -08001257 if (pciehp_force) {
1258 dbg("Bypassing BIOS check for pciehp use on %s\n",
1259 pci_name(ctrl->pci_dev));
1260 } else {
Rajesh Shah6560aa52005-11-07 13:37:36 -08001261 rc = pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev);
rajesh.shah@intel.coma3a45ec2005-10-31 16:20:12 -08001262 if (rc)
Jan Beulich9c64f972006-05-09 00:50:31 -07001263 goto abort_disable_intr;
rajesh.shah@intel.coma3a45ec2005-10-31 16:20:12 -08001264 }
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -08001265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 ctlr_seq_num++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 ctrl->hpc_ops = &pciehp_hpc_ops;
1268
1269 DBG_LEAVE_ROUTINE
1270 return 0;
1271
1272 /* We end up here for the many possible ways to fail this API. */
Jan Beulich9c64f972006-05-09 00:50:31 -07001273abort_disable_intr:
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001274 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Jan Beulich9c64f972006-05-09 00:50:31 -07001275 if (!rc) {
1276 temp_word &= ~(intr_enable | HP_INTR_ENABLE);
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001277 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Jan Beulich9c64f972006-05-09 00:50:31 -07001278 }
1279 if (rc)
1280 err("%s : disabling interrupts failed\n", __FUNCTION__);
1281
1282abort_free_irq:
1283 if (pciehp_poll_mode)
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001284 del_timer_sync(&ctrl->poll_timer);
Jan Beulich9c64f972006-05-09 00:50:31 -07001285 else
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001286 free_irq(ctrl->pci_dev->irq, ctrl);
Jan Beulich9c64f972006-05-09 00:50:31 -07001287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288abort_free_ctlr:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 DBG_LEAVE_ROUTINE
1290 return -1;
1291}