blob: 98eee63f3ec5f024f33a67b1f167831752a55d4d [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};
108static int pcie_cap_base = 0; /* Base of the PCI Express capability item structure */
109
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800110static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value)
111{
112 struct pci_dev *dev = ctrl->pci_dev;
113 return pci_read_config_word(dev, ctrl->cap_base + reg, value);
114}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800116static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value)
117{
118 struct pci_dev *dev = ctrl->pci_dev;
119 return pci_read_config_dword(dev, ctrl->cap_base + reg, value);
120}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800122static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value)
123{
124 struct pci_dev *dev = ctrl->pci_dev;
125 return pci_write_config_word(dev, ctrl->cap_base + reg, value);
126}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800128static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
129{
130 struct pci_dev *dev = ctrl->pci_dev;
131 return pci_write_config_dword(dev, ctrl->cap_base + reg, value);
132}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* Field definitions in PCI Express Capabilities Register */
135#define CAP_VER 0x000F
136#define DEV_PORT_TYPE 0x00F0
137#define SLOT_IMPL 0x0100
138#define MSG_NUM 0x3E00
139
140/* Device or Port Type */
141#define NAT_ENDPT 0x00
142#define LEG_ENDPT 0x01
143#define ROOT_PORT 0x04
144#define UP_STREAM 0x05
145#define DN_STREAM 0x06
146#define PCIE_PCI_BRDG 0x07
147#define PCI_PCIE_BRDG 0x10
148
149/* Field definitions in Device Capabilities Register */
150#define DATTN_BUTTN_PRSN 0x1000
151#define DATTN_LED_PRSN 0x2000
152#define DPWR_LED_PRSN 0x4000
153
154/* Field definitions in Link Capabilities Register */
155#define MAX_LNK_SPEED 0x000F
156#define MAX_LNK_WIDTH 0x03F0
157
158/* Link Width Encoding */
159#define LNK_X1 0x01
160#define LNK_X2 0x02
161#define LNK_X4 0x04
162#define LNK_X8 0x08
163#define LNK_X12 0x0C
164#define LNK_X16 0x10
165#define LNK_X32 0x20
166
167/*Field definitions of Link Status Register */
168#define LNK_SPEED 0x000F
169#define NEG_LINK_WD 0x03F0
170#define LNK_TRN_ERR 0x0400
171#define LNK_TRN 0x0800
172#define SLOT_CLK_CONF 0x1000
173
174/* Field definitions in Slot Capabilities Register */
175#define ATTN_BUTTN_PRSN 0x00000001
176#define PWR_CTRL_PRSN 0x00000002
177#define MRL_SENS_PRSN 0x00000004
178#define ATTN_LED_PRSN 0x00000008
179#define PWR_LED_PRSN 0x00000010
180#define HP_SUPR_RM_SUP 0x00000020
181#define HP_CAP 0x00000040
182#define SLOT_PWR_VALUE 0x000003F8
183#define SLOT_PWR_LIMIT 0x00000C00
184#define PSN 0xFFF80000 /* PSN: Physical Slot Number */
185
186/* Field definitions in Slot Control Register */
187#define ATTN_BUTTN_ENABLE 0x0001
188#define PWR_FAULT_DETECT_ENABLE 0x0002
189#define MRL_DETECT_ENABLE 0x0004
190#define PRSN_DETECT_ENABLE 0x0008
191#define CMD_CMPL_INTR_ENABLE 0x0010
192#define HP_INTR_ENABLE 0x0020
193#define ATTN_LED_CTRL 0x00C0
194#define PWR_LED_CTRL 0x0300
195#define PWR_CTRL 0x0400
196
197/* Attention indicator and Power indicator states */
198#define LED_ON 0x01
199#define LED_BLINK 0x10
200#define LED_OFF 0x11
201
202/* Power Control Command */
203#define POWER_ON 0
204#define POWER_OFF 0x0400
205
206/* Field definitions in Slot Status Register */
207#define ATTN_BUTTN_PRESSED 0x0001
208#define PWR_FAULT_DETECTED 0x0002
209#define MRL_SENS_CHANGED 0x0004
210#define PRSN_DETECT_CHANGED 0x0008
211#define CMD_COMPLETED 0x0010
212#define MRL_STATE 0x0020
213#define PRSN_STATE 0x0040
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static spinlock_t hpc_event_lock;
216
217DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static int ctlr_seq_num = 0; /* Controller sequence # */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800220static irqreturn_t pcie_isr(int irq, void *dev_id);
221static void start_int_poll_timer(struct controller *ctrl, int sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223/* This is the interrupt polling timeout function. */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800224static void int_poll_timeout(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800226 struct controller *ctrl = (struct controller *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 DBG_ENTER_ROUTINE
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 /* Poll for interrupt events. regs == NULL => polling */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800231 pcie_isr(0, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800233 init_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 if (!pciehp_poll_time)
235 pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
236
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800237 start_int_poll_timer(ctrl, pciehp_poll_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
240/* This function starts the interrupt polling timer. */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800241static void start_int_poll_timer(struct controller *ctrl, int sec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800243 /* Clamp to sane value */
244 if ((sec <= 0) || (sec > 60))
245 sec = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800247 ctrl->poll_timer.function = &int_poll_timeout;
248 ctrl->poll_timer.data = (unsigned long)ctrl;
249 ctrl->poll_timer.expires = jiffies + sec * HZ;
250 add_timer(&ctrl->poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
253static int pcie_write_cmd(struct slot *slot, u16 cmd)
254{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800255 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 int retval = 0;
257 u16 slot_status;
258
259 DBG_ENTER_ROUTINE
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800260
261 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800263 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
264 return retval;
265 }
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) {
268 /* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue
269 the next command according to spec. Just print out the error message */
270 dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__);
271 }
272
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800273 retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800275 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return retval;
277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 DBG_LEAVE_ROUTINE
280 return retval;
281}
282
283static int hpc_check_lnk_status(struct controller *ctrl)
284{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 u16 lnk_status;
286 int retval = 0;
287
288 DBG_ENTER_ROUTINE
289
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800290 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800292 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return retval;
294 }
295
296 dbg("%s: lnk_status = %x\n", __FUNCTION__, lnk_status);
297 if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) ||
298 !(lnk_status & NEG_LINK_WD)) {
299 err("%s : Link Training Error occurs \n", __FUNCTION__);
300 retval = -1;
301 return retval;
302 }
303
304 DBG_LEAVE_ROUTINE
305 return retval;
306}
307
308
309static int hpc_get_attention_status(struct slot *slot, u8 *status)
310{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800311 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 u16 slot_ctrl;
313 u8 atten_led_state;
314 int retval = 0;
315
316 DBG_ENTER_ROUTINE
317
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800318 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800320 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 return retval;
322 }
323
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800324 dbg("%s: SLOTCTRL %x, value read %x\n",
325 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6;
328
329 switch (atten_led_state) {
330 case 0:
331 *status = 0xFF; /* Reserved */
332 break;
333 case 1:
334 *status = 1; /* On */
335 break;
336 case 2:
337 *status = 2; /* Blink */
338 break;
339 case 3:
340 *status = 0; /* Off */
341 break;
342 default:
343 *status = 0xFF;
344 break;
345 }
346
347 DBG_LEAVE_ROUTINE
348 return 0;
349}
350
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800351static int hpc_get_power_status(struct slot *slot, u8 *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800353 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 u16 slot_ctrl;
355 u8 pwr_state;
356 int retval = 0;
357
358 DBG_ENTER_ROUTINE
359
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800360 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800362 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return retval;
364 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800365 dbg("%s: SLOTCTRL %x value read %x\n",
366 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 pwr_state = (slot_ctrl & PWR_CTRL) >> 10;
369
370 switch (pwr_state) {
371 case 0:
372 *status = 1;
373 break;
374 case 1:
375 *status = 0;
376 break;
377 default:
378 *status = 0xFF;
379 break;
380 }
381
382 DBG_LEAVE_ROUTINE
383 return retval;
384}
385
386
387static int hpc_get_latch_status(struct slot *slot, u8 *status)
388{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800389 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 u16 slot_status;
391 int retval = 0;
392
393 DBG_ENTER_ROUTINE
394
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800395 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800397 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return retval;
399 }
400
401 *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1;
402
403 DBG_LEAVE_ROUTINE
404 return 0;
405}
406
407static int hpc_get_adapter_status(struct slot *slot, u8 *status)
408{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800409 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 u16 slot_status;
411 u8 card_state;
412 int retval = 0;
413
414 DBG_ENTER_ROUTINE
415
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800416 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800418 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return retval;
420 }
421 card_state = (u8)((slot_status & PRSN_STATE) >> 6);
422 *status = (card_state == 1) ? 1 : 0;
423
424 DBG_LEAVE_ROUTINE
425 return 0;
426}
427
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800428static int hpc_query_power_fault(struct slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800430 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 u16 slot_status;
432 u8 pwr_fault;
433 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 DBG_ENTER_ROUTINE
436
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800437 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800439 err("%s: Cannot check for power fault\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return retval;
441 }
442 pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 DBG_LEAVE_ROUTINE
rajesh.shah@intel.com8239def2005-10-31 16:20:13 -0800445 return pwr_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
448static int hpc_set_attention_status(struct slot *slot, u8 value)
449{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800450 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 u16 slot_cmd = 0;
452 u16 slot_ctrl;
453 int rc = 0;
454
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800455 DBG_ENTER_ROUTINE
456
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800457 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800459 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return rc;
461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 switch (value) {
464 case 0 : /* turn off */
465 slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x00C0;
466 break;
467 case 1: /* turn on */
468 slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x0040;
469 break;
470 case 2: /* turn blink */
471 slot_cmd = (slot_ctrl & ~ATTN_LED_CTRL) | 0x0080;
472 break;
473 default:
474 return -1;
475 }
476 if (!pciehp_poll_mode)
477 slot_cmd = slot_cmd | HP_INTR_ENABLE;
478
479 pcie_write_cmd(slot, slot_cmd);
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800480 dbg("%s: SLOTCTRL %x write cmd %x\n",
481 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800483 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 return rc;
485}
486
487
488static void hpc_set_green_led_on(struct slot *slot)
489{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800490 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 u16 slot_cmd;
492 u16 slot_ctrl;
493 int rc = 0;
494
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800495 DBG_ENTER_ROUTINE
496
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800497 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800499 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 return;
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0100;
503 if (!pciehp_poll_mode)
504 slot_cmd = slot_cmd | HP_INTR_ENABLE;
505
506 pcie_write_cmd(slot, slot_cmd);
507
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800508 dbg("%s: SLOTCTRL %x write cmd %x\n",
509 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800510 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 return;
512}
513
514static void hpc_set_green_led_off(struct slot *slot)
515{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800516 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 u16 slot_cmd;
518 u16 slot_ctrl;
519 int rc = 0;
520
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800521 DBG_ENTER_ROUTINE
522
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800523 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800525 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return;
527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0300;
530
531 if (!pciehp_poll_mode)
532 slot_cmd = slot_cmd | HP_INTR_ENABLE;
533 pcie_write_cmd(slot, slot_cmd);
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800534 dbg("%s: SLOTCTRL %x write cmd %x\n",
535 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800537 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return;
539}
540
541static void hpc_set_green_led_blink(struct slot *slot)
542{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800543 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 u16 slot_cmd;
545 u16 slot_ctrl;
546 int rc = 0;
547
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800548 DBG_ENTER_ROUTINE
549
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800550 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800552 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return;
554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0200;
557
558 if (!pciehp_poll_mode)
559 slot_cmd = slot_cmd | HP_INTR_ENABLE;
560 pcie_write_cmd(slot, slot_cmd);
561
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800562 dbg("%s: SLOTCTRL %x write cmd %x\n",
563 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -0800564 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return;
566}
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568static void hpc_release_ctlr(struct controller *ctrl)
569{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 DBG_ENTER_ROUTINE
571
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800572 if (pciehp_poll_mode)
573 del_timer(&ctrl->poll_timer);
574 else
575 free_irq(ctrl->pci_dev->irq, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
580static int hpc_power_on_slot(struct slot * slot)
581{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800582 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 u16 slot_cmd;
Rajesh Shah5a49f202005-11-23 15:44:54 -0800584 u16 slot_ctrl, slot_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 int retval = 0;
586
587 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Rajesh Shah5a49f202005-11-23 15:44:54 -0800591 /* Clear sticky power-fault bit from previous power failures */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800592 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800594 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
595 return retval;
596 }
597 slot_status &= PWR_FAULT_DETECTED;
598 if (slot_status) {
599 retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status);
600 if (retval) {
601 err("%s: Cannot write to SLOTSTATUS register\n",
602 __FUNCTION__);
603 return retval;
604 }
605 }
606
607 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
608 if (retval) {
609 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 return retval;
611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 slot_cmd = (slot_ctrl & ~PWR_CTRL) | POWER_ON;
614
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800615 /* Enable detection that we turned off at slot power-off time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 if (!pciehp_poll_mode)
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800617 slot_cmd = slot_cmd |
618 PWR_FAULT_DETECT_ENABLE |
619 MRL_DETECT_ENABLE |
620 PRSN_DETECT_ENABLE |
621 HP_INTR_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 retval = pcie_write_cmd(slot, slot_cmd);
624
625 if (retval) {
626 err("%s: Write %x command failed!\n", __FUNCTION__, slot_cmd);
627 return -1;
628 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800629 dbg("%s: SLOTCTRL %x write cmd %x\n",
630 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 DBG_LEAVE_ROUTINE
633
634 return retval;
635}
636
637static int hpc_power_off_slot(struct slot * slot)
638{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800639 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 u16 slot_cmd;
641 u16 slot_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 int retval = 0;
643
644 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800648 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800650 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 return retval;
652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 slot_cmd = (slot_ctrl & ~PWR_CTRL) | POWER_OFF;
655
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800656 /*
657 * If we get MRL or presence detect interrupts now, the isr
658 * will notice the sticky power-fault bit too and issue power
659 * indicator change commands. This will lead to an endless loop
660 * of command completions, since the power-fault bit remains on
661 * till the slot is powered on again.
662 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 if (!pciehp_poll_mode)
Thomas Schaeferc7ab3372005-12-08 11:55:57 -0800664 slot_cmd = (slot_cmd &
665 ~PWR_FAULT_DETECT_ENABLE &
666 ~MRL_DETECT_ENABLE &
667 ~PRSN_DETECT_ENABLE) | HP_INTR_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 retval = pcie_write_cmd(slot, slot_cmd);
670
671 if (retval) {
672 err("%s: Write command failed!\n", __FUNCTION__);
673 return -1;
674 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800675 dbg("%s: SLOTCTRL %x write cmd %x\n",
676 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 DBG_LEAVE_ROUTINE
679
680 return retval;
681}
682
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800683static irqreturn_t pcie_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800685 struct controller *ctrl = (struct controller *)dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 u16 slot_status, intr_detect, intr_loc;
687 u16 temp_word;
688 int hp_slot = 0; /* only 1 slot per PCI Express port */
689 int rc = 0;
690
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800691 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800693 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 return IRQ_NONE;
695 }
696
697 intr_detect = ( ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED | MRL_SENS_CHANGED |
698 PRSN_DETECT_CHANGED | CMD_COMPLETED );
699
700 intr_loc = slot_status & intr_detect;
701
702 /* Check to see if it was our interrupt */
703 if ( !intr_loc )
704 return IRQ_NONE;
705
706 dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc);
707 /* Mask Hot-plug Interrupt Enable */
708 if (!pciehp_poll_mode) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800709 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800711 err("%s: Cannot read SLOT_CTRL register\n",
712 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 return IRQ_NONE;
714 }
715
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800716 dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n",
717 __FUNCTION__, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800719 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
720 if (rc) {
721 err("%s: Cannot write to SLOTCTRL register\n",
722 __FUNCTION__);
723 return IRQ_NONE;
724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800726 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800728 err("%s: Cannot read SLOT_STATUS register\n",
729 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 return IRQ_NONE;
731 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800732 dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n",
733 __FUNCTION__, slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 /* Clear command complete interrupt caused by this write */
736 temp_word = 0x1f;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800737 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800739 err("%s: Cannot write to SLOTSTATUS register\n",
740 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return IRQ_NONE;
742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744
745 if (intr_loc & CMD_COMPLETED) {
746 /*
747 * Command Complete Interrupt Pending
748 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 wake_up_interruptible(&ctrl->queue);
750 }
751
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800752 if (intr_loc & MRL_SENS_CHANGED)
753 pciehp_handle_switch_change(hp_slot, ctrl);
754
755 if (intr_loc & ATTN_BUTTN_PRESSED)
756 pciehp_handle_attention_button(hp_slot, ctrl);
757
758 if (intr_loc & PRSN_DETECT_CHANGED)
759 pciehp_handle_presence_change(hp_slot, ctrl);
760
761 if (intr_loc & PWR_FAULT_DETECTED)
762 pciehp_handle_power_fault(hp_slot, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 /* Clear all events after serving them */
765 temp_word = 0x1F;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800766 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800768 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 return IRQ_NONE;
770 }
771 /* Unmask Hot-plug Interrupt Enable */
772 if (!pciehp_poll_mode) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800773 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800775 err("%s: Cannot read SLOTCTRL register\n",
776 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 return IRQ_NONE;
778 }
779
780 dbg("%s: Unmask Hot-plug Interrupt Enable\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
782
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800783 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800785 err("%s: Cannot write to SLOTCTRL register\n",
786 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return IRQ_NONE;
788 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800789
790 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800792 err("%s: Cannot read SLOT_STATUS register\n",
793 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 return IRQ_NONE;
795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 /* Clear command complete interrupt caused by this write */
798 temp_word = 0x1F;
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800799 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800801 err("%s: Cannot write to SLOTSTATUS failed\n",
802 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return IRQ_NONE;
804 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800805 dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n",
806 __FUNCTION__, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 return IRQ_HANDLED;
810}
811
812static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value)
813{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800814 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 enum pcie_link_speed lnk_speed;
816 u32 lnk_cap;
817 int retval = 0;
818
819 DBG_ENTER_ROUTINE
820
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800821 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800823 err("%s: Cannot read LNKCAP register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return retval;
825 }
826
827 switch (lnk_cap & 0x000F) {
828 case 1:
829 lnk_speed = PCIE_2PT5GB;
830 break;
831 default:
832 lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
833 break;
834 }
835
836 *value = lnk_speed;
837 dbg("Max link speed = %d\n", lnk_speed);
838 DBG_LEAVE_ROUTINE
839 return retval;
840}
841
842static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value)
843{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800844 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 enum pcie_link_width lnk_wdth;
846 u32 lnk_cap;
847 int retval = 0;
848
849 DBG_ENTER_ROUTINE
850
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800851 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800853 err("%s: Cannot read LNKCAP register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return retval;
855 }
856
857 switch ((lnk_cap & 0x03F0) >> 4){
858 case 0:
859 lnk_wdth = PCIE_LNK_WIDTH_RESRV;
860 break;
861 case 1:
862 lnk_wdth = PCIE_LNK_X1;
863 break;
864 case 2:
865 lnk_wdth = PCIE_LNK_X2;
866 break;
867 case 4:
868 lnk_wdth = PCIE_LNK_X4;
869 break;
870 case 8:
871 lnk_wdth = PCIE_LNK_X8;
872 break;
873 case 12:
874 lnk_wdth = PCIE_LNK_X12;
875 break;
876 case 16:
877 lnk_wdth = PCIE_LNK_X16;
878 break;
879 case 32:
880 lnk_wdth = PCIE_LNK_X32;
881 break;
882 default:
883 lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
884 break;
885 }
886
887 *value = lnk_wdth;
888 dbg("Max link width = %d\n", lnk_wdth);
889 DBG_LEAVE_ROUTINE
890 return retval;
891}
892
893static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value)
894{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800895 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN;
897 int retval = 0;
898 u16 lnk_status;
899
900 DBG_ENTER_ROUTINE
901
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800902 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800904 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 return retval;
906 }
907
908 switch (lnk_status & 0x0F) {
909 case 1:
910 lnk_speed = PCIE_2PT5GB;
911 break;
912 default:
913 lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
914 break;
915 }
916
917 *value = lnk_speed;
918 dbg("Current link speed = %d\n", lnk_speed);
919 DBG_LEAVE_ROUTINE
920 return retval;
921}
922
923static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value)
924{
Kenji Kaneshige48fe3912006-12-21 17:01:04 -0800925 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
927 int retval = 0;
928 u16 lnk_status;
929
930 DBG_ENTER_ROUTINE
931
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800932 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 if (retval) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -0800934 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return retval;
936 }
937
938 switch ((lnk_status & 0x03F0) >> 4){
939 case 0:
940 lnk_wdth = PCIE_LNK_WIDTH_RESRV;
941 break;
942 case 1:
943 lnk_wdth = PCIE_LNK_X1;
944 break;
945 case 2:
946 lnk_wdth = PCIE_LNK_X2;
947 break;
948 case 4:
949 lnk_wdth = PCIE_LNK_X4;
950 break;
951 case 8:
952 lnk_wdth = PCIE_LNK_X8;
953 break;
954 case 12:
955 lnk_wdth = PCIE_LNK_X12;
956 break;
957 case 16:
958 lnk_wdth = PCIE_LNK_X16;
959 break;
960 case 32:
961 lnk_wdth = PCIE_LNK_X32;
962 break;
963 default:
964 lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
965 break;
966 }
967
968 *value = lnk_wdth;
969 dbg("Current link width = %d\n", lnk_wdth);
970 DBG_LEAVE_ROUTINE
971 return retval;
972}
973
974static struct hpc_ops pciehp_hpc_ops = {
975 .power_on_slot = hpc_power_on_slot,
976 .power_off_slot = hpc_power_off_slot,
977 .set_attention_status = hpc_set_attention_status,
978 .get_power_status = hpc_get_power_status,
979 .get_attention_status = hpc_get_attention_status,
980 .get_latch_status = hpc_get_latch_status,
981 .get_adapter_status = hpc_get_adapter_status,
982
983 .get_max_bus_speed = hpc_get_max_lnk_speed,
984 .get_cur_bus_speed = hpc_get_cur_lnk_speed,
985 .get_max_lnk_width = hpc_get_max_lnk_width,
986 .get_cur_lnk_width = hpc_get_cur_lnk_width,
987
988 .query_power_fault = hpc_query_power_fault,
989 .green_led_on = hpc_set_green_led_on,
990 .green_led_off = hpc_set_green_led_off,
991 .green_led_blink = hpc_set_green_led_blink,
992
993 .release_ctlr = hpc_release_ctlr,
994 .check_lnk_status = hpc_check_lnk_status,
995};
996
Kristen Accardi783c49f2006-03-03 10:16:05 -0800997#ifdef CONFIG_ACPI
998int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
999{
1000 acpi_status status;
1001 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
1002 struct pci_dev *pdev = dev;
1003 struct pci_bus *parent;
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001004 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
Kristen Accardi783c49f2006-03-03 10:16:05 -08001005
1006 /*
1007 * Per PCI firmware specification, we should run the ACPI _OSC
1008 * method to get control of hotplug hardware before using it.
1009 * If an _OSC is missing, we look for an OSHP to do the same thing.
1010 * To handle different BIOS behavior, we look for _OSC and OSHP
1011 * within the scope of the hotplug controller and its parents, upto
1012 * the host bridge under which this controller exists.
1013 */
1014 while (!handle) {
1015 /*
1016 * This hotplug controller was not listed in the ACPI name
1017 * space at all. Try to get acpi handle of parent pci bus.
1018 */
1019 if (!pdev || !pdev->bus->parent)
1020 break;
1021 parent = pdev->bus->parent;
1022 dbg("Could not find %s in acpi namespace, trying parent\n",
1023 pci_name(pdev));
1024 if (!parent->self)
1025 /* Parent must be a host bridge */
1026 handle = acpi_get_pci_rootbridge_handle(
1027 pci_domain_nr(parent),
1028 parent->number);
1029 else
1030 handle = DEVICE_ACPI_HANDLE(
1031 &(parent->self->dev));
1032 pdev = parent->self;
1033 }
1034
1035 while (handle) {
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001036 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
1037 dbg("Trying to get hotplug control for %s \n",
1038 (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -08001039 status = pci_osc_control_set(handle,
1040 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1041 if (status == AE_NOT_FOUND)
1042 status = acpi_run_oshp(handle);
1043 if (ACPI_SUCCESS(status)) {
1044 dbg("Gained control for hotplug HW for pci %s (%s)\n",
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001045 pci_name(dev), (char *)string.pointer);
Kristen Accardi81b26bc2006-04-18 14:36:43 -07001046 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -08001047 return 0;
1048 }
1049 if (acpi_root_bridge(handle))
1050 break;
1051 chandle = handle;
1052 status = acpi_get_parent(chandle, &handle);
1053 if (ACPI_FAILURE(status))
1054 break;
1055 }
1056
1057 err("Cannot get control of hotplug hardware for pci %s\n",
1058 pci_name(dev));
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +09001059
Kristen Accardi81b26bc2006-04-18 14:36:43 -07001060 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -08001061 return -1;
1062}
1063#endif
1064
1065
1066
rajesh.shah@intel.comed6cbcf2005-10-31 16:20:09 -08001067int pcie_init(struct controller * ctrl, struct pcie_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 int rc;
1070 static int first = 1;
1071 u16 temp_word;
1072 u16 cap_reg;
1073 u16 intr_enable = 0;
1074 u32 slot_cap;
1075 int cap_base, saved_cap_base;
1076 u16 slot_status, slot_ctrl;
1077 struct pci_dev *pdev;
1078
1079 DBG_ENTER_ROUTINE
1080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 pdev = dev->port;
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001082 ctrl->pci_dev = pdev; /* save pci_dev in context */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -08001084 dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n",
1085 __FUNCTION__, pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 saved_cap_base = pcie_cap_base;
1088
1089 if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) {
1090 dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__);
1091 goto abort_free_ctlr;
1092 }
1093
Dely Sy8b245e42005-05-06 17:19:09 -07001094 ctrl->cap_base = cap_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 dbg("%s: pcie_cap_base %x\n", __FUNCTION__, pcie_cap_base);
1097
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001098 rc = pciehp_readw(ctrl, CAPREG, &cap_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001100 err("%s: Cannot read CAPREG register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 goto abort_free_ctlr;
1102 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001103 dbg("%s: CAPREG offset %x cap_reg %x\n",
1104 __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Dely Sy8b245e42005-05-06 17:19:09 -07001106 if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040)
1107 && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 dbg("%s : This is not a root port or the port is not connected to a slot\n", __FUNCTION__);
1109 goto abort_free_ctlr;
1110 }
1111
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001112 rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001114 err("%s: Cannot read SLOTCAP register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 goto abort_free_ctlr;
1116 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001117 dbg("%s: SLOTCAP offset %x slot_cap %x\n",
1118 __FUNCTION__, ctrl->cap_base + SLOTCAP, slot_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120 if (!(slot_cap & HP_CAP)) {
1121 dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__);
1122 goto abort_free_ctlr;
1123 }
1124 /* For debugging purpose */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001125 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001127 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 goto abort_free_ctlr;
1129 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001130 dbg("%s: SLOTSTATUS offset %x slot_status %x\n",
1131 __FUNCTION__, ctrl->cap_base + SLOTSTATUS, slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001133 rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001135 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 goto abort_free_ctlr;
1137 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001138 dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n",
1139 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 if (first) {
1142 spin_lock_init(&hpc_event_lock);
1143 first = 0;
1144 }
1145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)
1147 if (pci_resource_len(pdev, rc) > 0)
Greg Kroah-Hartman1396a8c2006-06-12 15:14:29 -07001148 dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc,
1149 (unsigned long long)pci_resource_start(pdev, rc),
1150 (unsigned long long)pci_resource_len(pdev, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device,
1153 pdev->subsystem_vendor, pdev->subsystem_device);
1154
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001155 mutex_init(&ctrl->crit_sect);
Kenji Kaneshigedd5619c2006-09-22 10:17:29 -07001156 mutex_init(&ctrl->ctrl_lock);
1157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /* setup wait queue */
1159 init_waitqueue_head(&ctrl->queue);
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 /* return PCI Controller Info */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001162 ctrl->slot_device_offset = 0;
1163 ctrl->num_slots = 1;
1164 ctrl->first_slot = slot_cap >> 19;
1165 ctrl->ctrlcap = slot_cap & 0x0000007f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 /* Mask Hot-plug Interrupt Enable */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001168 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001170 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 goto abort_free_ctlr;
1172 }
1173
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001174 dbg("%s: SLOTCTRL %x value read %x\n",
1175 __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00;
1177
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001178 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001180 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 goto abort_free_ctlr;
1182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001184 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001186 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 goto abort_free_ctlr;
1188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 temp_word = 0x1F; /* Clear all events */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001191 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001193 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 goto abort_free_ctlr;
1195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001197 if (pciehp_poll_mode) {
1198 /* Install interrupt polling timer. Start with 10 sec delay */
1199 init_timer(&ctrl->poll_timer);
1200 start_int_poll_timer(ctrl, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 } else {
1202 /* Installs the interrupt handler */
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001203 rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED,
1204 MY_NAME, (void *)ctrl);
1205 dbg("%s: request_irq %d for hpc%d (returns %d)\n",
1206 __FUNCTION__, ctrl->pci_dev->irq, ctlr_seq_num, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (rc) {
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001208 err("Can't get irq %d for the hotplug controller\n",
1209 ctrl->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 goto abort_free_ctlr;
1211 }
1212 }
rajesh.shah@intel.com1a9ed1b2005-10-31 16:20:10 -08001213 dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number,
1214 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq);
1215
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001216 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001218 err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001219 goto abort_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 intr_enable = intr_enable | PRSN_DETECT_ENABLE;
1223
1224 if (ATTN_BUTTN(slot_cap))
1225 intr_enable = intr_enable | ATTN_BUTTN_ENABLE;
1226
1227 if (POWER_CTRL(slot_cap))
1228 intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE;
1229
1230 if (MRL_SENS(slot_cap))
1231 intr_enable = intr_enable | MRL_DETECT_ENABLE;
1232
1233 temp_word = (temp_word & ~intr_enable) | intr_enable;
1234
1235 if (pciehp_poll_mode) {
1236 temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0;
1237 } else {
1238 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
1239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001242 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001244 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001245 goto abort_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 }
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001247 rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001249 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001250 goto abort_disable_intr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 temp_word = 0x1F; /* Clear all events */
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001254 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 if (rc) {
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001256 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
Jan Beulich9c64f972006-05-09 00:50:31 -07001257 goto abort_disable_intr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
rajesh.shah@intel.coma3a45ec2005-10-31 16:20:12 -08001260 if (pciehp_force) {
1261 dbg("Bypassing BIOS check for pciehp use on %s\n",
1262 pci_name(ctrl->pci_dev));
1263 } else {
Rajesh Shah6560aa52005-11-07 13:37:36 -08001264 rc = pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev);
rajesh.shah@intel.coma3a45ec2005-10-31 16:20:12 -08001265 if (rc)
Jan Beulich9c64f972006-05-09 00:50:31 -07001266 goto abort_disable_intr;
rajesh.shah@intel.coma3a45ec2005-10-31 16:20:12 -08001267 }
rajesh.shah@intel.coma8a2be92005-10-31 16:20:07 -08001268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 ctlr_seq_num++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 ctrl->hpc_ops = &pciehp_hpc_ops;
1271
1272 DBG_LEAVE_ROUTINE
1273 return 0;
1274
1275 /* We end up here for the many possible ways to fail this API. */
Jan Beulich9c64f972006-05-09 00:50:31 -07001276abort_disable_intr:
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001277 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
Jan Beulich9c64f972006-05-09 00:50:31 -07001278 if (!rc) {
1279 temp_word &= ~(intr_enable | HP_INTR_ENABLE);
Kenji Kaneshigea0f018d2006-12-21 17:01:06 -08001280 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
Jan Beulich9c64f972006-05-09 00:50:31 -07001281 }
1282 if (rc)
1283 err("%s : disabling interrupts failed\n", __FUNCTION__);
1284
1285abort_free_irq:
1286 if (pciehp_poll_mode)
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001287 del_timer_sync(&ctrl->poll_timer);
Jan Beulich9c64f972006-05-09 00:50:31 -07001288 else
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001289 free_irq(ctrl->pci_dev->irq, ctrl);
Jan Beulich9c64f972006-05-09 00:50:31 -07001290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291abort_free_ctlr:
1292 pcie_cap_base = saved_cap_base;
Kenji Kaneshige48fe3912006-12-21 17:01:04 -08001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 DBG_LEAVE_ROUTINE
1295 return -1;
1296}