blob: 5e8f589d0b643ec850f1285ee2334167225cd9b9 [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 Kaneshigee7138722006-05-02 11:12:37 +090094 * Controller SERR-INT Register
95 */
96#define GLOBAL_INTR_MASK (1 << 0)
97#define GLOBAL_SERR_MASK (1 << 1)
98#define COMMAND_INTR_MASK (1 << 2)
99#define ARBITER_SERR_MASK (1 << 3)
100#define COMMAND_DETECTED (1 << 16)
101#define ARBITER_DETECTED (1 << 17)
102#define SERR_INTR_RSVDZ_MASK 0xfffc0000
103
104/*
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900105 * Logical Slot Register definitions
106 */
107#define SLOT_REG(i) (SLOT1 + (4 * i))
108
Kenji Kaneshige58587592006-05-02 11:10:37 +0900109#define SLOT_STATE_SHIFT (0)
110#define SLOT_STATE_MASK (3 << 0)
111#define SLOT_STATE_PWRONLY (1)
112#define SLOT_STATE_ENABLED (2)
113#define SLOT_STATE_DISABLED (3)
114#define PWR_LED_STATE_SHIFT (2)
115#define PWR_LED_STATE_MASK (3 << 2)
116#define ATN_LED_STATE_SHIFT (4)
117#define ATN_LED_STATE_MASK (3 << 4)
118#define ATN_LED_STATE_ON (1)
119#define ATN_LED_STATE_BLINK (2)
120#define ATN_LED_STATE_OFF (3)
121#define POWER_FAULT (1 << 6)
122#define ATN_BUTTON (1 << 7)
123#define MRL_SENSOR (1 << 8)
124#define MHZ66_CAP (1 << 9)
125#define PRSNT_SHIFT (10)
126#define PRSNT_MASK (3 << 10)
127#define PCIX_CAP_SHIFT (12)
128#define PCIX_CAP_MASK_PI1 (3 << 12)
129#define PCIX_CAP_MASK_PI2 (7 << 12)
130#define PRSNT_CHANGE_DETECTED (1 << 16)
131#define ISO_PFAULT_DETECTED (1 << 17)
132#define BUTTON_PRESS_DETECTED (1 << 18)
133#define MRL_CHANGE_DETECTED (1 << 19)
134#define CON_PFAULT_DETECTED (1 << 20)
135#define PRSNT_CHANGE_INTR_MASK (1 << 24)
136#define ISO_PFAULT_INTR_MASK (1 << 25)
137#define BUTTON_PRESS_INTR_MASK (1 << 26)
138#define MRL_CHANGE_INTR_MASK (1 << 27)
139#define CON_PFAULT_INTR_MASK (1 << 28)
140#define MRL_CHANGE_SERR_MASK (1 << 29)
141#define CON_PFAULT_SERR_MASK (1 << 30)
142#define SLOT_REG_RSVDZ_MASK (1 << 15) | (7 << 21)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144/* SHPC 'write' operations/commands */
145
146/* Slot operation - 0x00h to 0x3Fh */
147
148#define NO_CHANGE 0x00
149
150/* Slot state - Bits 0 & 1 of controller command register */
151#define SET_SLOT_PWR 0x01
152#define SET_SLOT_ENABLE 0x02
153#define SET_SLOT_DISABLE 0x03
154
155/* Power indicator state - Bits 2 & 3 of controller command register*/
156#define SET_PWR_ON 0x04
157#define SET_PWR_BLINK 0x08
158#define SET_PWR_OFF 0x0C
159
160/* Attention indicator state - Bits 4 & 5 of controller command register*/
161#define SET_ATTN_ON 0x010
162#define SET_ATTN_BLINK 0x020
163#define SET_ATTN_OFF 0x030
164
165/* Set bus speed/mode A - 0x40h to 0x47h */
166#define SETA_PCI_33MHZ 0x40
167#define SETA_PCI_66MHZ 0x41
168#define SETA_PCIX_66MHZ 0x42
169#define SETA_PCIX_100MHZ 0x43
170#define SETA_PCIX_133MHZ 0x44
171#define RESERV_1 0x45
172#define RESERV_2 0x46
173#define RESERV_3 0x47
174
175/* Set bus speed/mode B - 0x50h to 0x5fh */
176#define SETB_PCI_33MHZ 0x50
177#define SETB_PCI_66MHZ 0x51
178#define SETB_PCIX_66MHZ_PM 0x52
179#define SETB_PCIX_100MHZ_PM 0x53
180#define SETB_PCIX_133MHZ_PM 0x54
181#define SETB_PCIX_66MHZ_EM 0x55
182#define SETB_PCIX_100MHZ_EM 0x56
183#define SETB_PCIX_133MHZ_EM 0x57
184#define SETB_PCIX_66MHZ_266 0x58
185#define SETB_PCIX_100MHZ_266 0x59
186#define SETB_PCIX_133MHZ_266 0x5a
187#define SETB_PCIX_66MHZ_533 0x5b
188#define SETB_PCIX_100MHZ_533 0x5c
189#define SETB_PCIX_133MHZ_533 0x5d
190
191
192/* Power-on all slots - 0x48h */
193#define SET_PWR_ON_ALL 0x48
194
195/* Enable all slots - 0x49h */
196#define SET_ENABLE_ALL 0x49
197
198/* SHPC controller command error code */
199#define SWITCH_OPEN 0x1
200#define INVALID_CMD 0x2
201#define INVALID_SPEED_MODE 0x4
202
203/* For accessing SHPC Working Register Set */
204#define DWORD_SELECT 0x2
205#define DWORD_DATA 0x4
206#define BASE_OFFSET 0x0
207
208/* Field Offset in Logical Slot Register - byte boundary */
209#define SLOT_EVENT_LATCH 0x2
210#define SLOT_SERR_INT_MASK 0x3
211
212static spinlock_t hpc_event_lock;
213
214DEFINE_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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs);
222
223static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900224static int hpc_check_cmd_status(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900226static inline u8 shpc_readb(struct controller *ctrl, int reg)
227{
228 return readb(ctrl->hpc_ctlr_handle->creg + reg);
229}
230
231static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
232{
233 writeb(val, ctrl->hpc_ctlr_handle->creg + reg);
234}
235
236static inline u16 shpc_readw(struct controller *ctrl, int reg)
237{
238 return readw(ctrl->hpc_ctlr_handle->creg + reg);
239}
240
241static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
242{
243 writew(val, ctrl->hpc_ctlr_handle->creg + reg);
244}
245
246static inline u32 shpc_readl(struct controller *ctrl, int reg)
247{
248 return readl(ctrl->hpc_ctlr_handle->creg + reg);
249}
250
251static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
252{
253 writel(val, ctrl->hpc_ctlr_handle->creg + reg);
254}
255
256static inline int shpc_indirect_read(struct controller *ctrl, int index,
257 u32 *value)
258{
259 int rc;
260 u32 cap_offset = ctrl->cap_offset;
261 struct pci_dev *pdev = ctrl->pci_dev;
262
263 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
264 if (rc)
265 return rc;
266 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269/* This is the interrupt polling timeout function. */
270static void int_poll_timeout(unsigned long lphp_ctlr)
271{
272 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr;
273
274 DBG_ENTER_ROUTINE
275
276 if ( !php_ctlr ) {
277 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
278 return;
279 }
280
281 /* Poll for interrupt events. regs == NULL => polling */
282 shpc_isr( 0, (void *)php_ctlr, NULL );
283
284 init_timer(&php_ctlr->int_poll_timer);
285 if (!shpchp_poll_time)
286 shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
287
288 start_int_poll_timer(php_ctlr, shpchp_poll_time);
289
290 return;
291}
292
293/* This function starts the interrupt polling timer. */
294static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
295{
296 if (!php_ctlr) {
297 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
298 return;
299 }
300
301 if ( ( seconds <= 0 ) || ( seconds > 60 ) )
302 seconds = 2; /* Clamp to sane value */
303
304 php_ctlr->int_poll_timer.function = &int_poll_timeout;
305 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */
306 php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ;
307 add_timer(&php_ctlr->int_poll_timer);
308
309 return;
310}
311
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900312static inline int shpc_wait_cmd(struct controller *ctrl)
313{
314 int retval = 0;
315 unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000;
316 unsigned long timeout = msecs_to_jiffies(timeout_msec);
317 int rc = wait_event_interruptible_timeout(ctrl->queue,
318 !ctrl->cmd_busy, timeout);
319 if (!rc) {
320 retval = -EIO;
321 err("Command not completed in %d msec\n", timeout_msec);
322 } else if (rc < 0) {
323 retval = -EINTR;
324 info("Command was interrupted by a signal\n");
325 }
326 ctrl->cmd_busy = 0;
327
328 return retval;
329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
332{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700333 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900334 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 u16 cmd_status;
336 int retval = 0;
337 u16 temp_word;
338 int i;
339
340 DBG_ENTER_ROUTINE
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900341
342 mutex_lock(&slot->ctrl->cmd_lock);
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 if (!php_ctlr) {
345 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900346 retval = -EINVAL;
347 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349
350 for (i = 0; i < 10; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900351 cmd_status = shpc_readw(ctrl, CMD_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 if (!(cmd_status & 0x1))
354 break;
355 /* Check every 0.1 sec for a total of 1 sec*/
356 msleep(100);
357 }
358
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900359 cmd_status = shpc_readw(ctrl, CMD_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 if (cmd_status & 0x1) {
362 /* After 1 sec and and the controller is still busy */
363 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900364 retval = -EBUSY;
365 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367
368 ++t_slot;
369 temp_word = (t_slot << 8) | (cmd & 0xFF);
370 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
371
372 /* To make sure the Controller Busy bit is 0 before we send out the
373 * command.
374 */
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900375 slot->ctrl->cmd_busy = 1;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900376 shpc_writew(ctrl, CMD, temp_word);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900378 /*
379 * Wait for command completion.
380 */
381 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900382 if (retval)
383 goto out;
384
385 cmd_status = hpc_check_cmd_status(slot->ctrl);
386 if (cmd_status) {
387 err("%s: Failed to issued command 0x%x (error code = %d)\n",
388 __FUNCTION__, cmd, cmd_status);
389 retval = -EIO;
390 }
391 out:
392 mutex_unlock(&slot->ctrl->cmd_lock);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 DBG_LEAVE_ROUTINE
395 return retval;
396}
397
398static int hpc_check_cmd_status(struct controller *ctrl)
399{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 u16 cmd_status;
401 int retval = 0;
402
403 DBG_ENTER_ROUTINE
404
405 if (!ctrl->hpc_ctlr_handle) {
406 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
407 return -1;
408 }
409
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900410 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 switch (cmd_status >> 1) {
413 case 0:
414 retval = 0;
415 break;
416 case 1:
417 retval = SWITCH_OPEN;
418 err("%s: Switch opened!\n", __FUNCTION__);
419 break;
420 case 2:
421 retval = INVALID_CMD;
422 err("%s: Invalid HPC command!\n", __FUNCTION__);
423 break;
424 case 4:
425 retval = INVALID_SPEED_MODE;
426 err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
427 break;
428 default:
429 retval = cmd_status;
430 }
431
432 DBG_LEAVE_ROUTINE
433 return retval;
434}
435
436
437static int hpc_get_attention_status(struct slot *slot, u8 *status)
438{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900439 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900441 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 DBG_ENTER_ROUTINE
444
445 if (!slot->ctrl->hpc_ctlr_handle) {
446 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
447 return -1;
448 }
449
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900450 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900451 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Kenji Kaneshige58587592006-05-02 11:10:37 +0900453 switch (state) {
454 case ATN_LED_STATE_ON:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 *status = 1; /* On */
456 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900457 case ATN_LED_STATE_BLINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 *status = 2; /* Blink */
459 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900460 case ATN_LED_STATE_OFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 *status = 0; /* Off */
462 break;
463 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900464 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 break;
466 }
467
468 DBG_LEAVE_ROUTINE
469 return 0;
470}
471
472static int hpc_get_power_status(struct slot * slot, u8 *status)
473{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900474 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900476 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 DBG_ENTER_ROUTINE
479
480 if (!slot->ctrl->hpc_ctlr_handle) {
481 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
482 return -1;
483 }
484
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900485 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900486 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Kenji Kaneshige58587592006-05-02 11:10:37 +0900488 switch (state) {
489 case SLOT_STATE_PWRONLY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 *status = 2; /* Powered only */
491 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900492 case SLOT_STATE_ENABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 *status = 1; /* Enabled */
494 break;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900495 case SLOT_STATE_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 *status = 0; /* Disabled */
497 break;
498 default:
Kenji Kaneshige58587592006-05-02 11:10:37 +0900499 *status = 0xFF; /* Reserved */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 break;
501 }
502
503 DBG_LEAVE_ROUTINE
Kenji Kaneshige58587592006-05-02 11:10:37 +0900504 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
507
508static int hpc_get_latch_status(struct slot *slot, u8 *status)
509{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900510 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 DBG_ENTER_ROUTINE
514
515 if (!slot->ctrl->hpc_ctlr_handle) {
516 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
517 return -1;
518 }
519
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900520 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900521 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 DBG_LEAVE_ROUTINE
524 return 0;
525}
526
527static int hpc_get_adapter_status(struct slot *slot, u8 *status)
528{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900529 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 u32 slot_reg;
Kenji Kaneshige58587592006-05-02 11:10:37 +0900531 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 DBG_ENTER_ROUTINE
534
535 if (!slot->ctrl->hpc_ctlr_handle) {
536 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
537 return -1;
538 }
539
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900540 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900541 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
542 *status = (state != 0x3) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 DBG_LEAVE_ROUTINE
545 return 0;
546}
547
548static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
549{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900550 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 DBG_ENTER_ROUTINE
553
554 if (!slot->ctrl->hpc_ctlr_handle) {
555 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
556 return -1;
557 }
558
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900559 *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 DBG_LEAVE_ROUTINE
562 return 0;
563}
564
565static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
566{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900568 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900569 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Kenji Kaneshige58587592006-05-02 11:10:37 +0900570 u8 m66_cap = !!(slot_reg & MHZ66_CAP);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900571 u8 pi, pcix_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 DBG_ENTER_ROUTINE
574
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900575 if ((retval = hpc_get_prog_int(slot, &pi)))
576 return retval;
577
578 switch (pi) {
579 case 1:
580 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
581 break;
582 case 2:
583 pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
584 break;
585 default:
586 return -ENODEV;
587 }
588
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900589 dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
590 __FUNCTION__, slot_reg, pcix_cap, m66_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900592 switch (pcix_cap) {
593 case 0x0:
594 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
595 break;
596 case 0x1:
597 *value = PCI_SPEED_66MHz_PCIX;
598 break;
599 case 0x3:
600 *value = PCI_SPEED_133MHz_PCIX;
601 break;
602 case 0x4:
603 *value = PCI_SPEED_133MHz_PCIX_266;
604 break;
605 case 0x5:
606 *value = PCI_SPEED_133MHz_PCIX_533;
607 break;
608 case 0x2:
609 default:
610 *value = PCI_SPEED_UNKNOWN;
611 retval = -ENODEV;
612 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
615 dbg("Adapter speed = %d\n", *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 DBG_LEAVE_ROUTINE
617 return retval;
618}
619
620static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
621{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900622 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 u16 sec_bus_status;
624 u8 pi;
625 int retval = 0;
626
627 DBG_ENTER_ROUTINE
628
629 if (!slot->ctrl->hpc_ctlr_handle) {
630 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
631 return -1;
632 }
633
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900634 pi = shpc_readb(ctrl, PROG_INTERFACE);
635 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 if (pi == 2) {
Kenji Kaneshige87d6c552005-11-24 11:35:05 +0900638 *mode = (sec_bus_status & 0x0100) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 } else {
640 retval = -1;
641 }
642
643 dbg("Mode 1 ECC cap = %d\n", *mode);
644
645 DBG_LEAVE_ROUTINE
646 return retval;
647}
648
649static int hpc_query_power_fault(struct slot * slot)
650{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900651 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 u32 slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 DBG_ENTER_ROUTINE
655
656 if (!slot->ctrl->hpc_ctlr_handle) {
657 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
658 return -1;
659 }
660
Kenji Kaneshige2b34da72006-05-02 11:09:42 +0900661 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 DBG_LEAVE_ROUTINE
664 /* Note: Logic 0 => fault */
Kenji Kaneshige58587592006-05-02 11:10:37 +0900665 return !(slot_reg & POWER_FAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668static int hpc_set_attention_status(struct slot *slot, u8 value)
669{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700670 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 u8 slot_cmd = 0;
672 int rc = 0;
673
674 if (!slot->ctrl->hpc_ctlr_handle) {
675 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
676 return -1;
677 }
678
679 if (slot->hp_slot >= php_ctlr->num_slots) {
680 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
681 return -1;
682 }
683
684 switch (value) {
685 case 0 :
686 slot_cmd = 0x30; /* OFF */
687 break;
688 case 1:
689 slot_cmd = 0x10; /* ON */
690 break;
691 case 2:
692 slot_cmd = 0x20; /* BLINK */
693 break;
694 default:
695 return -1;
696 }
697
698 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
699
700 return rc;
701}
702
703
704static void hpc_set_green_led_on(struct slot *slot)
705{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700706 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 u8 slot_cmd;
708
709 if (!slot->ctrl->hpc_ctlr_handle) {
710 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
711 return ;
712 }
713
714 if (slot->hp_slot >= php_ctlr->num_slots) {
715 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
716 return ;
717 }
718
719 slot_cmd = 0x04;
720
721 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
722
723 return;
724}
725
726static void hpc_set_green_led_off(struct slot *slot)
727{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700728 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 u8 slot_cmd;
730
731 if (!slot->ctrl->hpc_ctlr_handle) {
732 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
733 return ;
734 }
735
736 if (slot->hp_slot >= php_ctlr->num_slots) {
737 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
738 return ;
739 }
740
741 slot_cmd = 0x0C;
742
743 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
744
745 return;
746}
747
748static void hpc_set_green_led_blink(struct slot *slot)
749{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700750 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 u8 slot_cmd;
752
753 if (!slot->ctrl->hpc_ctlr_handle) {
754 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
755 return ;
756 }
757
758 if (slot->hp_slot >= php_ctlr->num_slots) {
759 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
760 return ;
761 }
762
763 slot_cmd = 0x08;
764
765 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
766
767 return;
768}
769
770int shpc_get_ctlr_slot_config(struct controller *ctrl,
771 int *num_ctlr_slots, /* number of slots in this HPC */
772 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
773 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
774 int *updown, /* physical_slot_num increament: 1 or -1 */
775 int *flags)
776{
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900777 u32 slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 DBG_ENTER_ROUTINE
780
781 if (!ctrl->hpc_ctlr_handle) {
782 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
783 return -1;
784 }
785
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900786 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
787 *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8;
788 *num_ctlr_slots = slot_config & SLOT_NUM;
789 *physical_slot_num = (slot_config & PSN) >> 16;
790 *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 DBG_LEAVE_ROUTINE
795 return 0;
796}
797
798static void hpc_release_ctlr(struct controller *ctrl)
799{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700800 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 struct php_ctlr_state_s *p, *p_prev;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800802 int i;
Kenji Kaneshiged49f2c42006-05-03 23:34:17 +0900803 u32 slot_reg, serr_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 DBG_ENTER_ROUTINE
806
807 if (!ctrl->hpc_ctlr_handle) {
808 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
809 return ;
810 }
811
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800812 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900813 * Mask event interrupts and SERRs of all slots
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800814 */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +0900815 for (i = 0; i < ctrl->num_slots; i++) {
816 slot_reg = shpc_readl(ctrl, SLOT_REG(i));
817 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
818 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
819 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
820 CON_PFAULT_SERR_MASK);
821 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
822 shpc_writel(ctrl, SLOT_REG(i), slot_reg);
823 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800824
825 cleanup_slots(ctrl);
826
Kenji Kaneshiged49f2c42006-05-03 23:34:17 +0900827 /*
828 * Mask SERR and System Interrut generation
829 */
830 serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
831 serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
832 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
833 serr_int &= ~SERR_INTR_RSVDZ_MASK;
834 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
835
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 if (shpchp_poll_mode) {
837 del_timer(&php_ctlr->int_poll_timer);
838 } else {
839 if (php_ctlr->irq) {
840 free_irq(php_ctlr->irq, ctrl);
841 php_ctlr->irq = 0;
842 pci_disable_msi(php_ctlr->pci_dev);
843 }
844 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 if (php_ctlr->pci_dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 iounmap(php_ctlr->creg);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900848 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 php_ctlr->pci_dev = NULL;
850 }
851
852 spin_lock(&list_lock);
853 p = php_ctlr_list_head;
854 p_prev = NULL;
855 while (p) {
856 if (p == php_ctlr) {
857 if (p_prev)
858 p_prev->pnext = p->pnext;
859 else
860 php_ctlr_list_head = p->pnext;
861 break;
862 } else {
863 p_prev = p;
864 p = p->pnext;
865 }
866 }
867 spin_unlock(&list_lock);
868
869 kfree(php_ctlr);
870
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +0900871 /*
872 * If this is the last controller to be released, destroy the
873 * shpchpd work queue
874 */
875 if (atomic_dec_and_test(&shpchp_num_controllers))
876 destroy_workqueue(shpchp_wq);
877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878DBG_LEAVE_ROUTINE
879
880}
881
882static int hpc_power_on_slot(struct slot * slot)
883{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700884 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 u8 slot_cmd;
886 int retval = 0;
887
888 DBG_ENTER_ROUTINE
889
890 if (!slot->ctrl->hpc_ctlr_handle) {
891 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
892 return -1;
893 }
894
895 if (slot->hp_slot >= php_ctlr->num_slots) {
896 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
897 return -1;
898 }
899 slot_cmd = 0x01;
900
901 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
902
903 if (retval) {
904 err("%s: Write command failed!\n", __FUNCTION__);
905 return -1;
906 }
907
908 DBG_LEAVE_ROUTINE
909
910 return retval;
911}
912
913static int hpc_slot_enable(struct slot * slot)
914{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700915 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 u8 slot_cmd;
917 int retval = 0;
918
919 DBG_ENTER_ROUTINE
920
921 if (!slot->ctrl->hpc_ctlr_handle) {
922 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
923 return -1;
924 }
925
926 if (slot->hp_slot >= php_ctlr->num_slots) {
927 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
928 return -1;
929 }
930 /* 3A => Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
931 slot_cmd = 0x3A;
932
933 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
934
935 if (retval) {
936 err("%s: Write command failed!\n", __FUNCTION__);
937 return -1;
938 }
939
940 DBG_LEAVE_ROUTINE
941 return retval;
942}
943
944static int hpc_slot_disable(struct slot * slot)
945{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700946 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 u8 slot_cmd;
948 int retval = 0;
949
950 DBG_ENTER_ROUTINE
951
952 if (!slot->ctrl->hpc_ctlr_handle) {
953 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
954 return -1;
955 }
956
957 if (slot->hp_slot >= php_ctlr->num_slots) {
958 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
959 return -1;
960 }
961
962 /* 1F => Slot - Disable, Power Indicator - Off, Attention Indicator - On */
963 slot_cmd = 0x1F;
964
965 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
966
967 if (retval) {
968 err("%s: Write command failed!\n", __FUNCTION__);
969 return -1;
970 }
971
972 DBG_LEAVE_ROUTINE
973 return retval;
974}
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
977{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900978 int retval;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900979 struct controller *ctrl = slot->ctrl;
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900980 u8 pi, cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 DBG_ENTER_ROUTINE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Kenji Kaneshige75d97c52006-05-02 11:08:42 +0900984 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900985 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
986 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Kenji Kaneshige0afabe92006-03-01 14:55:11 +0900988 switch (value) {
989 case PCI_SPEED_33MHz:
990 cmd = SETA_PCI_33MHZ;
991 break;
992 case PCI_SPEED_66MHz:
993 cmd = SETA_PCI_66MHZ;
994 break;
995 case PCI_SPEED_66MHz_PCIX:
996 cmd = SETA_PCIX_66MHZ;
997 break;
998 case PCI_SPEED_100MHz_PCIX:
999 cmd = SETA_PCIX_100MHZ;
1000 break;
1001 case PCI_SPEED_133MHz_PCIX:
1002 cmd = SETA_PCIX_133MHZ;
1003 break;
1004 case PCI_SPEED_66MHz_PCIX_ECC:
1005 cmd = SETB_PCIX_66MHZ_EM;
1006 break;
1007 case PCI_SPEED_100MHz_PCIX_ECC:
1008 cmd = SETB_PCIX_100MHZ_EM;
1009 break;
1010 case PCI_SPEED_133MHz_PCIX_ECC:
1011 cmd = SETB_PCIX_133MHZ_EM;
1012 break;
1013 case PCI_SPEED_66MHz_PCIX_266:
1014 cmd = SETB_PCIX_66MHZ_266;
1015 break;
1016 case PCI_SPEED_100MHz_PCIX_266:
1017 cmd = SETB_PCIX_100MHZ_266;
1018 break;
1019 case PCI_SPEED_133MHz_PCIX_266:
1020 cmd = SETB_PCIX_133MHZ_266;
1021 break;
1022 case PCI_SPEED_66MHz_PCIX_533:
1023 cmd = SETB_PCIX_66MHZ_533;
1024 break;
1025 case PCI_SPEED_100MHz_PCIX_533:
1026 cmd = SETB_PCIX_100MHZ_533;
1027 break;
1028 case PCI_SPEED_133MHz_PCIX_533:
1029 cmd = SETB_PCIX_133MHZ_533;
1030 break;
1031 default:
1032 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001034
1035 retval = shpc_write_cmd(slot, 0, cmd);
1036 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 err("%s: Write command failed!\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 DBG_LEAVE_ROUTINE
1040 return retval;
1041}
1042
1043static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1044{
1045 struct controller *ctrl = NULL;
1046 struct php_ctlr_state_s *php_ctlr;
1047 u8 schedule_flag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 u32 temp_dword, intr_loc, intr_loc2;
1049 int hp_slot;
1050
1051 if (!dev_id)
1052 return IRQ_NONE;
1053
1054 if (!shpchp_poll_mode) {
1055 ctrl = (struct controller *)dev_id;
1056 php_ctlr = ctrl->hpc_ctlr_handle;
1057 } else {
1058 php_ctlr = (struct php_ctlr_state_s *) dev_id;
1059 ctrl = (struct controller *)php_ctlr->callback_instance_id;
1060 }
1061
1062 if (!ctrl)
1063 return IRQ_NONE;
1064
1065 if (!php_ctlr || !php_ctlr->creg)
1066 return IRQ_NONE;
1067
1068 /* Check to see if it was our interrupt */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001069 intr_loc = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 if (!intr_loc)
1072 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
1074
1075 if(!shpchp_poll_mode) {
1076 /* Mask Global Interrupt Mask - see implementation note on p. 139 */
1077 /* of SHPC spec rev 1.0*/
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001078 temp_dword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001079 temp_dword |= GLOBAL_INTR_MASK;
1080 temp_dword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001081 shpc_writel(ctrl, SERR_INTR_ENABLE, temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001083 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1085 }
1086
1087 if (intr_loc & 0x0001) {
1088 /*
1089 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +09001090 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 * Detect bit in Controller SERR-INT register
1092 */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001093 temp_dword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001094 temp_dword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001095 shpc_writel(ctrl, SERR_INTR_ENABLE, temp_dword);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +09001096 ctrl->cmd_busy = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 wake_up_interruptible(&ctrl->queue);
1098 }
1099
Kenji Kaneshigee4e73042006-01-26 10:05:57 +09001100 if ((intr_loc = (intr_loc >> 1)) == 0)
1101 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1104 /* To find out which slot has interrupt pending */
1105 if ((intr_loc >> hp_slot) & 0x01) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001106 temp_dword = shpc_readl(ctrl, SLOT_REG(hp_slot));
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001107 dbg("%s: Slot %x with intr, slot register = %x\n",
1108 __FUNCTION__, hp_slot, temp_dword);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001109 if ((php_ctlr->switch_change_callback) &&
1110 (temp_dword & MRL_CHANGE_DETECTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 schedule_flag += php_ctlr->switch_change_callback(
1112 hp_slot, php_ctlr->callback_instance_id);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001113 if ((php_ctlr->attention_button_callback) &&
1114 (temp_dword & BUTTON_PRESS_DETECTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 schedule_flag += php_ctlr->attention_button_callback(
1116 hp_slot, php_ctlr->callback_instance_id);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001117 if ((php_ctlr->presence_change_callback) &&
1118 (temp_dword & PRSNT_CHANGE_DETECTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 schedule_flag += php_ctlr->presence_change_callback(
1120 hp_slot , php_ctlr->callback_instance_id);
Kenji Kaneshige58587592006-05-02 11:10:37 +09001121 if ((php_ctlr->power_fault_callback) &&
1122 (temp_dword & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 schedule_flag += php_ctlr->power_fault_callback(
1124 hp_slot, php_ctlr->callback_instance_id);
1125
1126 /* Clear all slot events */
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001127 temp_dword &= ~SLOT_REG_RSVDZ_MASK;
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001128 shpc_writel(ctrl, SLOT_REG(hp_slot), temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001130 intr_loc2 = shpc_readl(ctrl, INTR_LOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1132 }
1133 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +09001134 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 if (!shpchp_poll_mode) {
1136 /* Unmask Global Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001137 temp_dword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001138 temp_dword &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001139 shpc_writel(ctrl, SERR_INTR_ENABLE, temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141
1142 return IRQ_HANDLED;
1143}
1144
1145static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1146{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001147 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001148 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001150 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
1151 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
1152 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 DBG_ENTER_ROUTINE
1155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001157 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001158 bus_speed = PCI_SPEED_133MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001159 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001160 bus_speed = PCI_SPEED_100MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001161 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001162 bus_speed = PCI_SPEED_66MHz_PCIX_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001163 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001164 bus_speed = PCI_SPEED_133MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001165 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001166 bus_speed = PCI_SPEED_100MHz_PCIX_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001167 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001168 bus_speed = PCI_SPEED_66MHz_PCIX_266;
1169 }
1170
1171 if (bus_speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001172 if (slot_avail1 & SLOT_133MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001173 bus_speed = PCI_SPEED_133MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001174 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001175 bus_speed = PCI_SPEED_100MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001176 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001177 bus_speed = PCI_SPEED_66MHz_PCIX;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001178 else if (slot_avail2 & SLOT_66MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001179 bus_speed = PCI_SPEED_66MHz;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001180 else if (slot_avail1 & SLOT_33MHZ)
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001181 bus_speed = PCI_SPEED_33MHz;
1182 else
1183 retval = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185
1186 *value = bus_speed;
1187 dbg("Max bus speed = %d\n", bus_speed);
1188 DBG_LEAVE_ROUTINE
1189 return retval;
1190}
1191
1192static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1193{
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001194 int retval = 0;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001195 struct controller *ctrl = slot->ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001197 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
1198 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001199 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 DBG_ENTER_ROUTINE
1202
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001203 if ((pi == 1) && (speed_mode > 4)) {
1204 *value = PCI_SPEED_UNKNOWN;
1205 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207
Kenji Kaneshige0afabe92006-03-01 14:55:11 +09001208 switch (speed_mode) {
1209 case 0x0:
1210 *value = PCI_SPEED_33MHz;
1211 break;
1212 case 0x1:
1213 *value = PCI_SPEED_66MHz;
1214 break;
1215 case 0x2:
1216 *value = PCI_SPEED_66MHz_PCIX;
1217 break;
1218 case 0x3:
1219 *value = PCI_SPEED_100MHz_PCIX;
1220 break;
1221 case 0x4:
1222 *value = PCI_SPEED_133MHz_PCIX;
1223 break;
1224 case 0x5:
1225 *value = PCI_SPEED_66MHz_PCIX_ECC;
1226 break;
1227 case 0x6:
1228 *value = PCI_SPEED_100MHz_PCIX_ECC;
1229 break;
1230 case 0x7:
1231 *value = PCI_SPEED_133MHz_PCIX_ECC;
1232 break;
1233 case 0x8:
1234 *value = PCI_SPEED_66MHz_PCIX_266;
1235 break;
1236 case 0x9:
1237 *value = PCI_SPEED_100MHz_PCIX_266;
1238 break;
1239 case 0xa:
1240 *value = PCI_SPEED_133MHz_PCIX_266;
1241 break;
1242 case 0xb:
1243 *value = PCI_SPEED_66MHz_PCIX_533;
1244 break;
1245 case 0xc:
1246 *value = PCI_SPEED_100MHz_PCIX_533;
1247 break;
1248 case 0xd:
1249 *value = PCI_SPEED_133MHz_PCIX_533;
1250 break;
1251 default:
1252 *value = PCI_SPEED_UNKNOWN;
1253 retval = -ENODEV;
1254 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 dbg("Current bus speed = %d\n", bus_speed);
1258 DBG_LEAVE_ROUTINE
1259 return retval;
1260}
1261
1262static struct hpc_ops shpchp_hpc_ops = {
1263 .power_on_slot = hpc_power_on_slot,
1264 .slot_enable = hpc_slot_enable,
1265 .slot_disable = hpc_slot_disable,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1267 .set_attention_status = hpc_set_attention_status,
1268 .get_power_status = hpc_get_power_status,
1269 .get_attention_status = hpc_get_attention_status,
1270 .get_latch_status = hpc_get_latch_status,
1271 .get_adapter_status = hpc_get_adapter_status,
1272
1273 .get_max_bus_speed = hpc_get_max_bus_speed,
1274 .get_cur_bus_speed = hpc_get_cur_bus_speed,
1275 .get_adapter_speed = hpc_get_adapter_speed,
1276 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
1277 .get_prog_int = hpc_get_prog_int,
1278
1279 .query_power_fault = hpc_query_power_fault,
1280 .green_led_on = hpc_set_green_led_on,
1281 .green_led_off = hpc_set_green_led_off,
1282 .green_led_blink = hpc_set_green_led_blink,
1283
1284 .release_ctlr = hpc_release_ctlr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285};
1286
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001287int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288{
1289 struct php_ctlr_state_s *php_ctlr, *p;
1290 void *instance_id = ctrl;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001291 int rc, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 u8 hp_slot;
1293 static int first = 1;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001294 u32 shpc_base_offset;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001295 u32 tempdword, slot_reg, slot_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 u8 i;
1297
1298 DBG_ENTER_ROUTINE
1299
Kenji Kaneshige04559862005-11-24 11:36:59 +09001300 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 spin_lock_init(&list_lock);
Kenji Kaneshige57c95c02006-01-26 10:02:41 +09001303 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 if (!php_ctlr) { /* allocate controller state data */
1306 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1307 goto abort;
1308 }
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1311
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001312 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1313 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001314 /* amd shpc driver doesn't use Base Offset; assume 0 */
1315 ctrl->mmio_base = pci_resource_start(pdev, 0);
1316 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001318 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1319 if (!ctrl->cap_offset) {
1320 err("%s : cap_offset == 0\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 goto abort_free_ctlr;
1322 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001323 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1324
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001325 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001327 err("%s: cannot read base_offset\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 goto abort_free_ctlr;
1329 }
1330
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001331 rc = shpc_indirect_read(ctrl, 3, &tempdword);
Kenji Kaneshige04559862005-11-24 11:36:59 +09001332 if (rc) {
1333 err("%s: cannot read slot config\n", __FUNCTION__);
1334 goto abort_free_ctlr;
1335 }
1336 num_slots = tempdword & SLOT_NUM;
1337 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
1338
1339 for (i = 0; i < 9 + num_slots; i++) {
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001340 rc = shpc_indirect_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001342 err("%s: cannot read creg (index = %d)\n",
1343 __FUNCTION__, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 goto abort_free_ctlr;
1345 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001346 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1347 tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001349
1350 ctrl->mmio_base =
1351 pci_resource_start(pdev, 0) + shpc_base_offset;
1352 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 }
1354
1355 if (first) {
1356 spin_lock_init(&hpc_event_lock);
1357 first = 0;
1358 }
1359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1361 pdev->subsystem_device);
1362
1363 if (pci_enable_device(pdev))
1364 goto abort_free_ctlr;
1365
Kenji Kaneshige04559862005-11-24 11:36:59 +09001366 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1368 goto abort_free_ctlr;
1369 }
1370
Kenji Kaneshige04559862005-11-24 11:36:59 +09001371 php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 if (!php_ctlr->creg) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001373 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1374 ctrl->mmio_size, ctrl->mmio_base);
1375 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 goto abort_free_ctlr;
1377 }
1378 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001380 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +09001381 mutex_init(&ctrl->cmd_lock);
1382
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 /* Setup wait queue */
1384 init_waitqueue_head(&ctrl->queue);
1385
1386 /* Find the IRQ */
1387 php_ctlr->irq = pdev->irq;
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001388 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1389 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1390 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1391 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 php_ctlr->callback_instance_id = instance_id;
1393
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001394 ctrl->hpc_ctlr_handle = php_ctlr;
1395 ctrl->hpc_ops = &shpchp_hpc_ops;
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 /* Return PCI Controller Info */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001398 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
1399 php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1400 php_ctlr->num_slots = slot_config & SLOT_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
1402 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
1403
1404 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001405 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001407 tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
1408 COMMAND_INTR_MASK | ARBITER_SERR_MASK);
1409 tempdword &= ~SERR_INTR_RSVDZ_MASK;
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001410 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1411 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1413
1414 /* Mask the MRL sensor SERR Mask of individual slot in
1415 * Slot SERR-INT Mask & clear all the existing event if any
1416 */
1417 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001418 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1420 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001421 slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1422 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1423 CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
1424 CON_PFAULT_SERR_MASK);
1425 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
1426 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428
1429 if (shpchp_poll_mode) {/* Install interrupt polling code */
1430 /* Install and start the interrupt polling timer */
1431 init_timer(&php_ctlr->int_poll_timer);
1432 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
1433 } else {
1434 /* Installs the interrupt handler */
1435 rc = pci_enable_msi(pdev);
1436 if (rc) {
1437 info("Can't get msi for the hotplug controller\n");
1438 info("Use INTx for the hotplug controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 } else
1440 php_ctlr->irq = pdev->irq;
1441
1442 rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);
1443 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
1444 if (rc) {
1445 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
1446 goto abort_free_ctlr;
1447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001449 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
1450 pdev->bus->number, PCI_SLOT(pdev->devfn),
1451 PCI_FUNC(pdev->devfn), pdev->irq);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -07001452 get_hp_hw_control_from_firmware(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 /* Add this HPC instance into the HPC list */
1455 spin_lock(&list_lock);
1456 if (php_ctlr_list_head == 0) {
1457 php_ctlr_list_head = php_ctlr;
1458 p = php_ctlr_list_head;
1459 p->pnext = NULL;
1460 } else {
1461 p = php_ctlr_list_head;
1462
1463 while (p->pnext)
1464 p = p->pnext;
1465
1466 p->pnext = php_ctlr;
1467 }
1468 spin_unlock(&list_lock);
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 ctlr_seq_num++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001472 /*
Kenji Kaneshige82d5f4a2006-05-03 23:42:04 +09001473 * If this is the first controller to be initialized,
1474 * initialize the shpchpd work queue
1475 */
1476 if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
1477 shpchp_wq = create_singlethread_workqueue("shpchpd");
1478 if (!shpchp_wq)
1479 return -ENOMEM;
1480 }
1481
1482 /*
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001483 * Unmask all event interrupts of all slots
1484 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
Kenji Kaneshige2b34da72006-05-02 11:09:42 +09001486 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1488 hp_slot, slot_reg);
Kenji Kaneshige795eb5c2006-05-02 11:11:54 +09001489 slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
1490 BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
1491 CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
1492 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 }
1494 if (!shpchp_poll_mode) {
1495 /* Unmask all general input interrupts and SERR */
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001496 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Kenji Kaneshigee7138722006-05-02 11:12:37 +09001497 tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
1498 SERR_INTR_RSVDZ_MASK);
Kenji Kaneshige75d97c52006-05-02 11:08:42 +09001499 shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
1500 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1502 }
1503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 DBG_LEAVE_ROUTINE
1505 return 0;
1506
1507 /* We end up here for the many possible ways to fail this API. */
1508abort_free_ctlr:
1509 kfree(php_ctlr);
1510abort:
1511 DBG_LEAVE_ROUTINE
1512 return -1;
1513}