blob: 83a5226ba9ed4918c4e46fb8f964aaf9a1b90922 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Standard PCI Hot Plug Driver
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
Kristen 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/pci.h>
Andrew Mortond4d28dd2005-11-13 16:06:40 -080034#include <linux/interrupt.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "shpchp.h"
37
38#ifdef DEBUG
39#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
40#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
41#define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */
42#define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */
43#define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT)
44#define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE)
45/* Redefine this flagword to set debug level */
46#define DEBUG_LEVEL DBG_K_STANDARD
47
48#define DEFINE_DBG_BUFFER char __dbg_str_buf[256];
49
50#define DBG_PRINT( dbg_flags, args... ) \
51 do { \
52 if ( DEBUG_LEVEL & ( dbg_flags ) ) \
53 { \
54 int len; \
55 len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \
56 __FILE__, __LINE__, __FUNCTION__ ); \
57 sprintf( __dbg_str_buf + len, args ); \
58 printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \
59 } \
60 } while (0)
61
62#define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]");
63#define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]");
64#else
65#define DEFINE_DBG_BUFFER
66#define DBG_ENTER_ROUTINE
67#define DBG_LEAVE_ROUTINE
68#endif /* DEBUG */
69
70/* Slot Available Register I field definition */
71#define SLOT_33MHZ 0x0000001f
72#define SLOT_66MHZ_PCIX 0x00001f00
73#define SLOT_100MHZ_PCIX 0x001f0000
74#define SLOT_133MHZ_PCIX 0x1f000000
75
76/* Slot Available Register II field definition */
77#define SLOT_66MHZ 0x0000001f
78#define SLOT_66MHZ_PCIX_266 0x00000f00
79#define SLOT_100MHZ_PCIX_266 0x0000f000
80#define SLOT_133MHZ_PCIX_266 0x000f0000
81#define SLOT_66MHZ_PCIX_533 0x00f00000
82#define SLOT_100MHZ_PCIX_533 0x0f000000
83#define SLOT_133MHZ_PCIX_533 0xf0000000
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* Slot Configuration */
86#define SLOT_NUM 0x0000001F
87#define FIRST_DEV_NUM 0x00001F00
88#define PSN 0x07FF0000
89#define UPDOWN 0x20000000
90#define MRLSENSOR 0x40000000
91#define ATTN_BUTTON 0x80000000
92
Kenji Kaneshige2b34da72006-05-02 11:09:42 +090093/*
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +090094 * Interrupt Locator Register definitions
95 */
96#define CMD_INTR_PENDING (1 << 0)
97#define SLOT_INTR_PENDING(i) (1 << (i + 1))
98
99/*
Kenji Kaneshigee7138722006-05-02 11:12:37 +0900100 * Controller SERR-INT Register
101 */
102#define GLOBAL_INTR_MASK (1 << 0)
103#define GLOBAL_SERR_MASK (1 << 1)
104#define COMMAND_INTR_MASK (1 << 2)
105#define ARBITER_SERR_MASK (1 << 3)
106#define COMMAND_DETECTED (1 << 16)
107#define ARBITER_DETECTED (1 << 17)
108#define SERR_INTR_RSVDZ_MASK 0xfffc0000
109
110/*
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900111 * Logical Slot Register definitions
112 */
113#define SLOT_REG(i) (SLOT1 + (4 * i))
114
Kenji Kaneshige58587592006-05-02 11:10:37 +0900115#define SLOT_STATE_SHIFT (0)
116#define SLOT_STATE_MASK (3 << 0)
117#define SLOT_STATE_PWRONLY (1)
118#define SLOT_STATE_ENABLED (2)
119#define SLOT_STATE_DISABLED (3)
120#define PWR_LED_STATE_SHIFT (2)
121#define PWR_LED_STATE_MASK (3 << 2)
122#define ATN_LED_STATE_SHIFT (4)
123#define ATN_LED_STATE_MASK (3 << 4)
124#define ATN_LED_STATE_ON (1)
125#define ATN_LED_STATE_BLINK (2)
126#define ATN_LED_STATE_OFF (3)
127#define POWER_FAULT (1 << 6)
128#define ATN_BUTTON (1 << 7)
129#define MRL_SENSOR (1 << 8)
130#define MHZ66_CAP (1 << 9)
131#define PRSNT_SHIFT (10)
132#define PRSNT_MASK (3 << 10)
133#define PCIX_CAP_SHIFT (12)
134#define PCIX_CAP_MASK_PI1 (3 << 12)
135#define PCIX_CAP_MASK_PI2 (7 << 12)
136#define PRSNT_CHANGE_DETECTED (1 << 16)
137#define ISO_PFAULT_DETECTED (1 << 17)
138#define BUTTON_PRESS_DETECTED (1 << 18)
139#define MRL_CHANGE_DETECTED (1 << 19)
140#define CON_PFAULT_DETECTED (1 << 20)
141#define PRSNT_CHANGE_INTR_MASK (1 << 24)
142#define ISO_PFAULT_INTR_MASK (1 << 25)
143#define BUTTON_PRESS_INTR_MASK (1 << 26)
144#define MRL_CHANGE_INTR_MASK (1 << 27)
145#define CON_PFAULT_INTR_MASK (1 << 28)
146#define MRL_CHANGE_SERR_MASK (1 << 29)
147#define CON_PFAULT_SERR_MASK (1 << 30)
148#define SLOT_REG_RSVDZ_MASK (1 << 15) | (7 << 21)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Kenji Kaneshige40853992006-05-12 11:11:48 +0900150/*
151 * SHPC Command Code definitnions
152 *
153 * Slot Operation 00h - 3Fh
154 * Set Bus Segment Speed/Mode A 40h - 47h
155 * Power-Only All Slots 48h
156 * Enable All Slots 49h
157 * Set Bus Segment Speed/Mode B (PI=2) 50h - 5Fh
158 * Reserved Command Codes 60h - BFh
159 * Vendor Specific Commands C0h - FFh
160 */
161#define SET_SLOT_PWR 0x01 /* Slot Operation */
162#define SET_SLOT_ENABLE 0x02
163#define SET_SLOT_DISABLE 0x03
164#define SET_PWR_ON 0x04
165#define SET_PWR_BLINK 0x08
166#define SET_PWR_OFF 0x0c
167#define SET_ATTN_ON 0x10
168#define SET_ATTN_BLINK 0x20
169#define SET_ATTN_OFF 0x30
170#define SETA_PCI_33MHZ 0x40 /* Set Bus Segment Speed/Mode A */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#define SETA_PCI_66MHZ 0x41
172#define SETA_PCIX_66MHZ 0x42
173#define SETA_PCIX_100MHZ 0x43
174#define SETA_PCIX_133MHZ 0x44
Kenji Kaneshige40853992006-05-12 11:11:48 +0900175#define SETA_RESERVED1 0x45
176#define SETA_RESERVED2 0x46
177#define SETA_RESERVED3 0x47
178#define SET_PWR_ONLY_ALL 0x48 /* Power-Only All Slots */
179#define SET_ENABLE_ALL 0x49 /* Enable All Slots */
180#define SETB_PCI_33MHZ 0x50 /* Set Bus Segment Speed/Mode B */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#define SETB_PCI_66MHZ 0x51
182#define SETB_PCIX_66MHZ_PM 0x52
183#define SETB_PCIX_100MHZ_PM 0x53
184#define SETB_PCIX_133MHZ_PM 0x54
185#define SETB_PCIX_66MHZ_EM 0x55
186#define SETB_PCIX_100MHZ_EM 0x56
187#define SETB_PCIX_133MHZ_EM 0x57
188#define SETB_PCIX_66MHZ_266 0x58
189#define SETB_PCIX_100MHZ_266 0x59
190#define SETB_PCIX_133MHZ_266 0x5a
191#define SETB_PCIX_66MHZ_533 0x5b
192#define SETB_PCIX_100MHZ_533 0x5c
193#define SETB_PCIX_133MHZ_533 0x5d
Kenji Kaneshige40853992006-05-12 11:11:48 +0900194#define SETB_RESERVED1 0x5e
195#define SETB_RESERVED2 0x5f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Kenji Kaneshige40853992006-05-12 11:11:48 +0900197/*
198 * SHPC controller command error code
199 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#define SWITCH_OPEN 0x1
201#define INVALID_CMD 0x2
202#define INVALID_SPEED_MODE 0x4
203
Kenji Kaneshige40853992006-05-12 11:11:48 +0900204/*
205 * For accessing SHPC Working Register Set via PCI Configuration Space
206 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define DWORD_SELECT 0x2
208#define DWORD_DATA 0x4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/* Field Offset in Logical Slot Register - byte boundary */
211#define SLOT_EVENT_LATCH 0x2
212#define SLOT_SERR_INT_MASK 0x3
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
215static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
216static int ctlr_seq_num = 0; /* Controller sequenc # */
217static spinlock_t list_lock;
218
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +0900219static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
220
David Howells7d12e782006-10-05 14:55:46 +0100221static irqreturn_t shpc_isr(int irq, void *dev_id);
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900222static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900223static int hpc_check_cmd_status(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900225static inline u8 shpc_readb(struct controller *ctrl, int reg)
226{
227 return readb(ctrl->hpc_ctlr_handle->creg + reg);
228}
229
230static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
231{
232 writeb(val, ctrl->hpc_ctlr_handle->creg + reg);
233}
234
235static inline u16 shpc_readw(struct controller *ctrl, int reg)
236{
237 return readw(ctrl->hpc_ctlr_handle->creg + reg);
238}
239
240static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
241{
242 writew(val, ctrl->hpc_ctlr_handle->creg + reg);
243}
244
245static inline u32 shpc_readl(struct controller *ctrl, int reg)
246{
247 return readl(ctrl->hpc_ctlr_handle->creg + reg);
248}
249
250static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
251{
252 writel(val, ctrl->hpc_ctlr_handle->creg + reg);
253}
254
255static inline int shpc_indirect_read(struct controller *ctrl, int index,
256 u32 *value)
257{
258 int rc;
259 u32 cap_offset = ctrl->cap_offset;
260 struct pci_dev *pdev = ctrl->pci_dev;
261
262 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
263 if (rc)
264 return rc;
265 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
266}
267
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900268/*
269 * This is the interrupt polling timeout function.
270 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static void int_poll_timeout(unsigned long lphp_ctlr)
272{
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900273 struct php_ctlr_state_s *php_ctlr =
274 (struct php_ctlr_state_s *)lphp_ctlr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900276 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900278 /* Poll for interrupt events. regs == NULL => polling */
David Howells7d12e782006-10-05 14:55:46 +0100279 shpc_isr(0, php_ctlr->callback_instance_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900281 init_timer(&php_ctlr->int_poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 if (!shpchp_poll_time)
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900283 shpchp_poll_time = 2; /* default polling interval is 2 sec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900285 start_int_poll_timer(php_ctlr, shpchp_poll_time);
286
287 DBG_LEAVE_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900290/*
291 * This function starts the interrupt polling timer.
292 */
293static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900295 /* Clamp to sane value */
296 if ((sec <= 0) || (sec > 60))
297 sec = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Kenji Kaneshigef4263952006-05-12 11:13:02 +0900299 php_ctlr->int_poll_timer.function = &int_poll_timeout;
300 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr;
301 php_ctlr->int_poll_timer.expires = jiffies + sec * HZ;
302 add_timer(&php_ctlr->int_poll_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
304
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700305static inline int is_ctrl_busy(struct controller *ctrl)
306{
307 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
308 return cmd_status & 0x1;
309}
310
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700311/*
312 * Returns 1 if SHPC finishes executing a command within 1 sec,
313 * otherwise returns 0.
314 */
315static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
316{
317 int i;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700318
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700319 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700320 return 1;
321
322 /* Check every 0.1 sec for a total of 1 sec */
323 for (i = 0; i < 10; i++) {
324 msleep(100);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700325 if (!is_ctrl_busy(ctrl))
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700326 return 1;
327 }
328
329 return 0;
330}
331
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900332static inline int shpc_wait_cmd(struct controller *ctrl)
333{
334 int retval = 0;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700335 unsigned long timeout = msecs_to_jiffies(1000);
336 int rc;
337
338 if (shpchp_poll_mode)
339 rc = shpc_poll_ctrl_busy(ctrl);
340 else
341 rc = wait_event_interruptible_timeout(ctrl->queue,
Kenji Kaneshige6aa562c2006-09-28 15:51:36 -0700342 !is_ctrl_busy(ctrl), timeout);
Kenji Kaneshiged1729cc2006-09-28 15:51:21 -0700343 if (!rc && is_ctrl_busy(ctrl)) {
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900344 retval = -EIO;
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700345 err("Command not completed in 1000 msec\n");
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900346 } else if (rc < 0) {
347 retval = -EINTR;
348 info("Command was interrupted by a signal\n");
349 }
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900350
351 return retval;
352}
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
355{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900356 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 u16 cmd_status;
358 int retval = 0;
359 u16 temp_word;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 DBG_ENTER_ROUTINE
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900362
363 mutex_lock(&slot->ctrl->cmd_lock);
364
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700365 if (!shpc_poll_ctrl_busy(ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* After 1 sec and and the controller is still busy */
Kenji Kaneshigeb4a1eff2006-09-22 12:52:37 -0700367 err("%s : Controller is still busy after 1 sec.\n",
368 __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900369 retval = -EBUSY;
370 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372
373 ++t_slot;
374 temp_word = (t_slot << 8) | (cmd & 0xFF);
375 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
376
377 /* To make sure the Controller Busy bit is 0 before we send out the
378 * command.
379 */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900380 shpc_writew(ctrl, CMD, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900382 /*
383 * Wait for command completion.
384 */
385 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900386 if (retval)
387 goto out;
388
389 cmd_status = hpc_check_cmd_status(slot->ctrl);
390 if (cmd_status) {
391 err("%s: Failed to issued command 0x%x (error code = %d)\n",
392 __FUNCTION__, cmd, cmd_status);
393 retval = -EIO;
394 }
395 out:
396 mutex_unlock(&slot->ctrl->cmd_lock);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 DBG_LEAVE_ROUTINE
399 return retval;
400}
401
402static int hpc_check_cmd_status(struct controller *ctrl)
403{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 u16 cmd_status;
405 int retval = 0;
406
407 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900409 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 switch (cmd_status >> 1) {
412 case 0:
413 retval = 0;
414 break;
415 case 1:
416 retval = SWITCH_OPEN;
417 err("%s: Switch opened!\n", __FUNCTION__);
418 break;
419 case 2:
420 retval = INVALID_CMD;
421 err("%s: Invalid HPC command!\n", __FUNCTION__);
422 break;
423 case 4:
424 retval = INVALID_SPEED_MODE;
425 err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
426 break;
427 default:
428 retval = cmd_status;
429 }
430
431 DBG_LEAVE_ROUTINE
432 return retval;
433}
434
435
436static int hpc_get_attention_status(struct slot *slot, u8 *status)
437{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900438 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900440 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 DBG_ENTER_ROUTINE
443
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900444 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900445 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Kenji Kaneshige58587592006-05-02 11:10:37 +0900447 switch (state) {
448 case ATN_LED_STATE_ON:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 *status = 1; /* On */
450 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900451 case ATN_LED_STATE_BLINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 *status = 2; /* Blink */
453 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900454 case ATN_LED_STATE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 *status = 0; /* Off */
456 break;
457 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900458 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 break;
460 }
461
462 DBG_LEAVE_ROUTINE
463 return 0;
464}
465
466static int hpc_get_power_status(struct slot * slot, u8 *status)
467{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900468 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900470 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472 DBG_ENTER_ROUTINE
473
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900474 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900475 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Kenji Kaneshige58587592006-05-02 11:10:37 +0900477 switch (state) {
478 case SLOT_STATE_PWRONLY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 *status = 2; /* Powered only */
480 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900481 case SLOT_STATE_ENABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 *status = 1; /* Enabled */
483 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900484 case SLOT_STATE_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 *status = 0; /* Disabled */
486 break;
487 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900488 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 break;
490 }
491
492 DBG_LEAVE_ROUTINE
Kenji Kaneshige58587592006-05-02 11:10:37 +0900493 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
496
497static int hpc_get_latch_status(struct slot *slot, u8 *status)
498{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900499 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 DBG_ENTER_ROUTINE
503
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900504 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900505 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 DBG_LEAVE_ROUTINE
508 return 0;
509}
510
511static int hpc_get_adapter_status(struct slot *slot, u8 *status)
512{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900513 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900515 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 DBG_ENTER_ROUTINE
518
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900519 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900520 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
521 *status = (state != 0x3) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 DBG_LEAVE_ROUTINE
524 return 0;
525}
526
527static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
528{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900529 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900533 *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 DBG_LEAVE_ROUTINE
536 return 0;
537}
538
539static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
540{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900542 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900543 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900544 u8 m66_cap = !!(slot_reg & MHZ66_CAP);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900545 u8 pi, pcix_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 DBG_ENTER_ROUTINE
548
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900549 if ((retval = hpc_get_prog_int(slot, &pi)))
550 return retval;
551
552 switch (pi) {
553 case 1:
554 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
555 break;
556 case 2:
557 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
558 break;
559 default:
560 return -ENODEV;
561 }
562
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900563 dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
564 __FUNCTION__, slot_reg, pcix_cap, m66_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900566 switch (pcix_cap) {
567 case 0x0:
568 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
569 break;
570 case 0x1:
571 *value = PCI_SPEED_66MHz_PCIX;
572 break;
573 case 0x3:
574 *value = PCI_SPEED_133MHz_PCIX;
575 break;
576 case 0x4:
577 *value = PCI_SPEED_133MHz_PCIX_266;
578 break;
579 case 0x5:
580 *value = PCI_SPEED_133MHz_PCIX_533;
581 break;
582 case 0x2:
583 default:
584 *value = PCI_SPEED_UNKNOWN;
585 retval = -ENODEV;
586 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
589 dbg("Adapter speed = %d\n", *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 DBG_LEAVE_ROUTINE
591 return retval;
592}
593
594static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
595{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900596 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 u16 sec_bus_status;
598 u8 pi;
599 int retval = 0;
600
601 DBG_ENTER_ROUTINE
602
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900603 pi = shpc_readb(ctrl, PROG_INTERFACE);
604 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 if (pi == 2) {
Kenji Kaneshige87d6c552005-11-24 11:35:05 +0900607 *mode = (sec_bus_status & 0x0100) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 } else {
609 retval = -1;
610 }
611
612 dbg("Mode 1 ECC cap = %d\n", *mode);
613
614 DBG_LEAVE_ROUTINE
615 return retval;
616}
617
618static int hpc_query_power_fault(struct slot * slot)
619{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900620 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 DBG_ENTER_ROUTINE
624
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900625 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 DBG_LEAVE_ROUTINE
628 /* Note: Logic 0 => fault */
Kenji Kaneshige58587592006-05-02 11:10:37 +0900629 return !(slot_reg & POWER_FAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}
631
632static int hpc_set_attention_status(struct slot *slot, u8 value)
633{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 u8 slot_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 switch (value) {
637 case 0 :
Kenji Kaneshige40853992006-05-12 11:11:48 +0900638 slot_cmd = SET_ATTN_OFF; /* OFF */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 break;
640 case 1:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900641 slot_cmd = SET_ATTN_ON; /* ON */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 break;
643 case 2:
Kenji Kaneshige40853992006-05-12 11:11:48 +0900644 slot_cmd = SET_ATTN_BLINK; /* BLINK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 break;
646 default:
647 return -1;
648 }
649
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900650 return shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
653
654static void hpc_set_green_led_on(struct slot *slot)
655{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900656 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
659static void hpc_set_green_led_off(struct slot *slot)
660{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900661 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
664static void hpc_set_green_led_blink(struct slot *slot)
665{
Kenji Kaneshige40853992006-05-12 11:11:48 +0900666 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668
669int shpc_get_ctlr_slot_config(struct controller *ctrl,
670 int *num_ctlr_slots, /* number of slots in this HPC */
671 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
672 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
673 int *updown, /* physical_slot_num increament: 1 or -1 */
674 int *flags)
675{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900676 u32 slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 DBG_ENTER_ROUTINE
679
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900680 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
681 *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8;
682 *num_ctlr_slots = slot_config & SLOT_NUM;
683 *physical_slot_num = (slot_config & PSN) >> 16;
684 *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 DBG_LEAVE_ROUTINE
689 return 0;
690}
691
692static void hpc_release_ctlr(struct controller *ctrl)
693{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700694 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 struct php_ctlr_state_s *p, *p_prev;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800696 int i;
Kenji Kaneshiged49f2c42006-05-03 23:34:17 +0900697 u32 slot_reg, serr_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 DBG_ENTER_ROUTINE
700
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800701 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900702 * Mask event interrupts and SERRs of all slots
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800703 */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900704 for (i = 0; i < ctrl->num_slots; i++) {
705 slot_reg = shpc_readl(ctrl, SLOT_REG(i));
706 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
707 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
708 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
709 CON_PFAULT_SERR_MASK);
710 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
711 shpc_writel(ctrl, SLOT_REG(i), slot_reg);
712 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800713
714 cleanup_slots(ctrl);
715
Kenji Kaneshiged49f2c42006-05-03 23:34:17 +0900716 /*
717 * Mask SERR and System Interrut generation
718 */
719 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
720 serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
721 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
722 serr_int &= ~SERR_INTR_RSVDZ_MASK;
723 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 if (shpchp_poll_mode) {
726 del_timer(&php_ctlr->int_poll_timer);
727 } else {
728 if (php_ctlr->irq) {
729 free_irq(php_ctlr->irq, ctrl);
730 php_ctlr->irq = 0;
731 pci_disable_msi(php_ctlr->pci_dev);
732 }
733 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 if (php_ctlr->pci_dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 iounmap(php_ctlr->creg);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900737 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 php_ctlr->pci_dev = NULL;
739 }
740
741 spin_lock(&list_lock);
742 p = php_ctlr_list_head;
743 p_prev = NULL;
744 while (p) {
745 if (p == php_ctlr) {
746 if (p_prev)
747 p_prev->pnext = p->pnext;
748 else
749 php_ctlr_list_head = p->pnext;
750 break;
751 } else {
752 p_prev = p;
753 p = p->pnext;
754 }
755 }
756 spin_unlock(&list_lock);
757
758 kfree(php_ctlr);
759
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +0900760 /*
761 * If this is the last controller to be released, destroy the
762 * shpchpd work queue
763 */
764 if (atomic_dec_and_test(&shpchp_num_controllers))
765 destroy_workqueue(shpchp_wq);
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767DBG_LEAVE_ROUTINE
768
769}
770
771static int hpc_power_on_slot(struct slot * slot)
772{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900773 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 DBG_ENTER_ROUTINE
776
Kenji Kaneshige40853992006-05-12 11:11:48 +0900777 retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 if (retval) {
779 err("%s: Write command failed!\n", __FUNCTION__);
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900780 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 }
782
783 DBG_LEAVE_ROUTINE
784
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900785 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786}
787
788static int hpc_slot_enable(struct slot * slot)
789{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900790 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 DBG_ENTER_ROUTINE
793
Kenji Kaneshige40853992006-05-12 11:11:48 +0900794 /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
795 retval = shpc_write_cmd(slot, slot->hp_slot,
796 SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (retval) {
798 err("%s: Write command failed!\n", __FUNCTION__);
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900799 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801
802 DBG_LEAVE_ROUTINE
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900803 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
806static int hpc_slot_disable(struct slot * slot)
807{
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900808 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 DBG_ENTER_ROUTINE
811
Kenji Kaneshige40853992006-05-12 11:11:48 +0900812 /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */
813 retval = shpc_write_cmd(slot, slot->hp_slot,
814 SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (retval) {
816 err("%s: Write command failed!\n", __FUNCTION__);
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900817 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
819
820 DBG_LEAVE_ROUTINE
Kenji Kaneshiged4fbf602006-05-12 11:05:59 +0900821 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822}
823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
825{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900826 int retval;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900827 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900828 u8 pi, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900832 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900833 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
834 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900836 switch (value) {
837 case PCI_SPEED_33MHz:
838 cmd = SETA_PCI_33MHZ;
839 break;
840 case PCI_SPEED_66MHz:
841 cmd = SETA_PCI_66MHZ;
842 break;
843 case PCI_SPEED_66MHz_PCIX:
844 cmd = SETA_PCIX_66MHZ;
845 break;
846 case PCI_SPEED_100MHz_PCIX:
847 cmd = SETA_PCIX_100MHZ;
848 break;
849 case PCI_SPEED_133MHz_PCIX:
850 cmd = SETA_PCIX_133MHZ;
851 break;
852 case PCI_SPEED_66MHz_PCIX_ECC:
853 cmd = SETB_PCIX_66MHZ_EM;
854 break;
855 case PCI_SPEED_100MHz_PCIX_ECC:
856 cmd = SETB_PCIX_100MHZ_EM;
857 break;
858 case PCI_SPEED_133MHz_PCIX_ECC:
859 cmd = SETB_PCIX_133MHZ_EM;
860 break;
861 case PCI_SPEED_66MHz_PCIX_266:
862 cmd = SETB_PCIX_66MHZ_266;
863 break;
864 case PCI_SPEED_100MHz_PCIX_266:
865 cmd = SETB_PCIX_100MHZ_266;
866 break;
867 case PCI_SPEED_133MHz_PCIX_266:
868 cmd = SETB_PCIX_133MHZ_266;
869 break;
870 case PCI_SPEED_66MHz_PCIX_533:
871 cmd = SETB_PCIX_66MHZ_533;
872 break;
873 case PCI_SPEED_100MHz_PCIX_533:
874 cmd = SETB_PCIX_100MHZ_533;
875 break;
876 case PCI_SPEED_133MHz_PCIX_533:
877 cmd = SETB_PCIX_133MHZ_533;
878 break;
879 default:
880 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900882
883 retval = shpc_write_cmd(slot, 0, cmd);
884 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 err("%s: Write command failed!\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 DBG_LEAVE_ROUTINE
888 return retval;
889}
890
David Howells7d12e782006-10-05 14:55:46 +0100891static irqreturn_t shpc_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892{
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900893 struct controller *ctrl = (struct controller *)dev_id;
894 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
895 u32 serr_int, slot_reg, intr_loc, intr_loc2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 int hp_slot;
897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 /* Check to see if it was our interrupt */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900899 intr_loc = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 if (!intr_loc)
901 return IRQ_NONE;
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
904
905 if(!shpchp_poll_mode) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900906 /*
907 * Mask Global Interrupt Mask - see implementation
908 * note on p. 139 of SHPC spec rev 1.0
909 */
910 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
911 serr_int |= GLOBAL_INTR_MASK;
912 serr_int &= ~SERR_INTR_RSVDZ_MASK;
913 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900915 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
917 }
918
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900919 if (intr_loc & CMD_INTR_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 /*
921 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +0900922 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 * Detect bit in Controller SERR-INT register
924 */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900925 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
926 serr_int &= ~SERR_INTR_RSVDZ_MASK;
927 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 wake_up_interruptible(&ctrl->queue);
930 }
931
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900932 if (!(intr_loc & ~CMD_INTR_PENDING))
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900933 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
935 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900936 /* To find out which slot has interrupt pending */
937 if (!(intr_loc & SLOT_INTR_PENDING(hp_slot)))
938 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900940 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
941 dbg("%s: Slot %x with intr, slot register = %x\n",
942 __FUNCTION__, hp_slot, slot_reg);
943
944 if (slot_reg & MRL_CHANGE_DETECTED)
945 php_ctlr->switch_change_callback(
946 hp_slot, php_ctlr->callback_instance_id);
947
948 if (slot_reg & BUTTON_PRESS_DETECTED)
949 php_ctlr->attention_button_callback(
950 hp_slot, php_ctlr->callback_instance_id);
951
952 if (slot_reg & PRSNT_CHANGE_DETECTED)
953 php_ctlr->presence_change_callback(
954 hp_slot , php_ctlr->callback_instance_id);
955
956 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
957 php_ctlr->power_fault_callback(
958 hp_slot, php_ctlr->callback_instance_id);
959
960 /* Clear all slot events */
961 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
962 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +0900964 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 if (!shpchp_poll_mode) {
966 /* Unmask Global Interrupt Mask */
Kenji Kaneshigec4cecc12006-05-12 11:10:56 +0900967 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
968 serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
969 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 }
971
972 return IRQ_HANDLED;
973}
974
975static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
976{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900977 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900978 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900980 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
981 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
982 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 DBG_ENTER_ROUTINE
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900987 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900988 bus_speed = PCI_SPEED_133MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900989 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900990 bus_speed = PCI_SPEED_100MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900991 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900992 bus_speed = PCI_SPEED_66MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900993 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900994 bus_speed = PCI_SPEED_133MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900995 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900996 bus_speed = PCI_SPEED_100MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +0900997 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900998 bus_speed = PCI_SPEED_66MHz_PCIX_266;
999 }
1000
1001 if (bus_speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001002 if (slot_avail1 & SLOT_133MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001003 bus_speed = PCI_SPEED_133MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001004 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001005 bus_speed = PCI_SPEED_100MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001006 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001007 bus_speed = PCI_SPEED_66MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001008 else if (slot_avail2 & SLOT_66MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001009 bus_speed = PCI_SPEED_66MHz;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001010 else if (slot_avail1 & SLOT_33MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001011 bus_speed = PCI_SPEED_33MHz;
1012 else
1013 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015
1016 *value = bus_speed;
1017 dbg("Max bus speed = %d\n", bus_speed);
1018 DBG_LEAVE_ROUTINE
1019 return retval;
1020}
1021
1022static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1023{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001024 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001025 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001027 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
1028 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001029 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 DBG_ENTER_ROUTINE
1032
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001033 if ((pi == 1) && (speed_mode > 4)) {
1034 *value = PCI_SPEED_UNKNOWN;
1035 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001038 switch (speed_mode) {
1039 case 0x0:
1040 *value = PCI_SPEED_33MHz;
1041 break;
1042 case 0x1:
1043 *value = PCI_SPEED_66MHz;
1044 break;
1045 case 0x2:
1046 *value = PCI_SPEED_66MHz_PCIX;
1047 break;
1048 case 0x3:
1049 *value = PCI_SPEED_100MHz_PCIX;
1050 break;
1051 case 0x4:
1052 *value = PCI_SPEED_133MHz_PCIX;
1053 break;
1054 case 0x5:
1055 *value = PCI_SPEED_66MHz_PCIX_ECC;
1056 break;
1057 case 0x6:
1058 *value = PCI_SPEED_100MHz_PCIX_ECC;
1059 break;
1060 case 0x7:
1061 *value = PCI_SPEED_133MHz_PCIX_ECC;
1062 break;
1063 case 0x8:
1064 *value = PCI_SPEED_66MHz_PCIX_266;
1065 break;
1066 case 0x9:
1067 *value = PCI_SPEED_100MHz_PCIX_266;
1068 break;
1069 case 0xa:
1070 *value = PCI_SPEED_133MHz_PCIX_266;
1071 break;
1072 case 0xb:
1073 *value = PCI_SPEED_66MHz_PCIX_533;
1074 break;
1075 case 0xc:
1076 *value = PCI_SPEED_100MHz_PCIX_533;
1077 break;
1078 case 0xd:
1079 *value = PCI_SPEED_133MHz_PCIX_533;
1080 break;
1081 default:
1082 *value = PCI_SPEED_UNKNOWN;
1083 retval = -ENODEV;
1084 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 dbg("Current bus speed = %d\n", bus_speed);
1088 DBG_LEAVE_ROUTINE
1089 return retval;
1090}
1091
1092static struct hpc_ops shpchp_hpc_ops = {
1093 .power_on_slot = hpc_power_on_slot,
1094 .slot_enable = hpc_slot_enable,
1095 .slot_disable = hpc_slot_disable,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1097 .set_attention_status = hpc_set_attention_status,
1098 .get_power_status = hpc_get_power_status,
1099 .get_attention_status = hpc_get_attention_status,
1100 .get_latch_status = hpc_get_latch_status,
1101 .get_adapter_status = hpc_get_adapter_status,
1102
1103 .get_max_bus_speed = hpc_get_max_bus_speed,
1104 .get_cur_bus_speed = hpc_get_cur_bus_speed,
1105 .get_adapter_speed = hpc_get_adapter_speed,
1106 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
1107 .get_prog_int = hpc_get_prog_int,
1108
1109 .query_power_fault = hpc_query_power_fault,
1110 .green_led_on = hpc_set_green_led_on,
1111 .green_led_off = hpc_set_green_led_off,
1112 .green_led_blink = hpc_set_green_led_blink,
1113
1114 .release_ctlr = hpc_release_ctlr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115};
1116
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001117int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
1119 struct php_ctlr_state_s *php_ctlr, *p;
1120 void *instance_id = ctrl;
Amol Lad662a98f2006-10-05 12:07:32 +05301121 int rc = -1, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 u8 hp_slot;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001123 u32 shpc_base_offset;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001124 u32 tempdword, slot_reg, slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 u8 i;
1126
1127 DBG_ENTER_ROUTINE
1128
Kenji Kaneshige04559862005-11-24 11:36:59 +09001129 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 spin_lock_init(&list_lock);
Kenji Kaneshige57c95c02006-01-26 10:02:41 +09001132 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 if (!php_ctlr) { /* allocate controller state data */
1135 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1136 goto abort;
1137 }
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1140
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001141 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1142 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001143 /* amd shpc driver doesn't use Base Offset; assume 0 */
1144 ctrl->mmio_base = pci_resource_start(pdev, 0);
1145 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001147 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1148 if (!ctrl->cap_offset) {
1149 err("%s : cap_offset == 0\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 goto abort_free_ctlr;
1151 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001152 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1153
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001154 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001156 err("%s: cannot read base_offset\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 goto abort_free_ctlr;
1158 }
1159
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001160 rc = shpc_indirect_read(ctrl, 3, &tempdword);
Kenji Kaneshige04559862005-11-24 11:36:59 +09001161 if (rc) {
1162 err("%s: cannot read slot config\n", __FUNCTION__);
1163 goto abort_free_ctlr;
1164 }
1165 num_slots = tempdword & SLOT_NUM;
1166 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
1167
1168 for (i = 0; i < 9 + num_slots; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001169 rc = shpc_indirect_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001171 err("%s: cannot read creg (index = %d)\n",
1172 __FUNCTION__, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 goto abort_free_ctlr;
1174 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001175 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1176 tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001178
1179 ctrl->mmio_base =
1180 pci_resource_start(pdev, 0) + shpc_base_offset;
1181 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 }
1183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1185 pdev->subsystem_device);
1186
Amol Lad662a98f2006-10-05 12:07:32 +05301187 rc = pci_enable_device(pdev);
1188 if (rc) {
1189 err("%s: pci_enable_device failed\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 goto abort_free_ctlr;
Amol Lad662a98f2006-10-05 12:07:32 +05301191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Kenji Kaneshige04559862005-11-24 11:36:59 +09001193 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
Amol Lad662a98f2006-10-05 12:07:32 +05301195 rc = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 goto abort_free_ctlr;
1197 }
1198
Kenji Kaneshige04559862005-11-24 11:36:59 +09001199 php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 if (!php_ctlr->creg) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001201 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1202 ctrl->mmio_size, ctrl->mmio_base);
1203 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Amol Lad662a98f2006-10-05 12:07:32 +05301204 rc = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 goto abort_free_ctlr;
1206 }
1207 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001209 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +09001210 mutex_init(&ctrl->cmd_lock);
1211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 /* Setup wait queue */
1213 init_waitqueue_head(&ctrl->queue);
1214
1215 /* Find the IRQ */
1216 php_ctlr->irq = pdev->irq;
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001217 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1218 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1219 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1220 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 php_ctlr->callback_instance_id = instance_id;
1222
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001223 ctrl->hpc_ctlr_handle = php_ctlr;
1224 ctrl->hpc_ops = &shpchp_hpc_ops;
1225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 /* Return PCI Controller Info */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001227 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
1228 php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1229 php_ctlr->num_slots = slot_config & SLOT_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
1231 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
1232
1233 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001234 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001236 tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
1237 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
1238 tempdword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001239 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1240 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1242
1243 /* Mask the MRL sensor SERR Mask of individual slot in
1244 * Slot SERR-INT Mask & clear all the existing event if any
1245 */
1246 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001247 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1249 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001250 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1251 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1252 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
1253 CON_PFAULT_SERR_MASK);
1254 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
1255 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 }
1257
1258 if (shpchp_poll_mode) {/* Install interrupt polling code */
1259 /* Install and start the interrupt polling timer */
1260 init_timer(&php_ctlr->int_poll_timer);
1261 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
1262 } else {
1263 /* Installs the interrupt handler */
1264 rc = pci_enable_msi(pdev);
1265 if (rc) {
1266 info("Can't get msi for the hotplug controller\n");
1267 info("Use INTx for the hotplug controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 } else
1269 php_ctlr->irq = pdev->irq;
1270
Thomas Gleixner6b4486e2006-07-01 19:29:41 -07001271 rc = request_irq(php_ctlr->irq, shpc_isr, IRQF_SHARED, MY_NAME, (void *) ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
1273 if (rc) {
1274 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
1275 goto abort_free_ctlr;
1276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001278 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
1279 pdev->bus->number, PCI_SLOT(pdev->devfn),
1280 PCI_FUNC(pdev->devfn), pdev->irq);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -07001281 get_hp_hw_control_from_firmware(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
1283 /* Add this HPC instance into the HPC list */
1284 spin_lock(&list_lock);
1285 if (php_ctlr_list_head == 0) {
1286 php_ctlr_list_head = php_ctlr;
1287 p = php_ctlr_list_head;
1288 p->pnext = NULL;
1289 } else {
1290 p = php_ctlr_list_head;
1291
1292 while (p->pnext)
1293 p = p->pnext;
1294
1295 p->pnext = php_ctlr;
1296 }
1297 spin_unlock(&list_lock);
1298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 ctlr_seq_num++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001301 /*
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +09001302 * If this is the first controller to be initialized,
1303 * initialize the shpchpd work queue
1304 */
1305 if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
1306 shpchp_wq = create_singlethread_workqueue("shpchpd");
Amol Lad662a98f2006-10-05 12:07:32 +05301307 if (!shpchp_wq) {
1308 rc = -ENOMEM;
1309 goto abort_free_ctlr;
1310 }
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +09001311 }
1312
1313 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001314 * Unmask all event interrupts of all slots
1315 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001317 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1319 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001320 slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1321 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1322 CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
1323 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
1325 if (!shpchp_poll_mode) {
1326 /* Unmask all general input interrupts and SERR */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001327 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001328 tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
1329 SERR_INTR_RSVDZ_MASK);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001330 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1331 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1333 }
1334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 DBG_LEAVE_ROUTINE
1336 return 0;
1337
1338 /* We end up here for the many possible ways to fail this API. */
1339abort_free_ctlr:
Amol Lad662a98f2006-10-05 12:07:32 +05301340 if (php_ctlr->creg)
1341 iounmap(php_ctlr->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 kfree(php_ctlr);
1343abort:
1344 DBG_LEAVE_ROUTINE
Amol Lad662a98f2006-10-05 12:07:32 +05301345 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}