blob: b392606a905a6019272ff74c22b49e5f9b11d1fd [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
85
86/* Secondary Bus Configuration Register */
87/* For PI = 1, Bits 0 to 2 have been encoded as follows to show current bus speed/mode */
88#define PCI_33MHZ 0x0
89#define PCI_66MHZ 0x1
90#define PCIX_66MHZ 0x2
91#define PCIX_100MHZ 0x3
92#define PCIX_133MHZ 0x4
93
94/* For PI = 2, Bits 0 to 3 have been encoded as follows to show current bus speed/mode */
95#define PCI_33MHZ 0x0
96#define PCI_66MHZ 0x1
97#define PCIX_66MHZ 0x2
98#define PCIX_100MHZ 0x3
99#define PCIX_133MHZ 0x4
100#define PCIX_66MHZ_ECC 0x5
101#define PCIX_100MHZ_ECC 0x6
102#define PCIX_133MHZ_ECC 0x7
103#define PCIX_66MHZ_266 0x9
104#define PCIX_100MHZ_266 0xa
105#define PCIX_133MHZ_266 0xb
106#define PCIX_66MHZ_533 0x11
107#define PCIX_100MHZ_533 0x12
108#define PCIX_133MHZ_533 0x13
109
110/* Slot Configuration */
111#define SLOT_NUM 0x0000001F
112#define FIRST_DEV_NUM 0x00001F00
113#define PSN 0x07FF0000
114#define UPDOWN 0x20000000
115#define MRLSENSOR 0x40000000
116#define ATTN_BUTTON 0x80000000
117
118/* Slot Status Field Definitions */
119/* Slot State */
120#define PWR_ONLY 0x0001
121#define ENABLED 0x0002
122#define DISABLED 0x0003
123
124/* Power Indicator State */
125#define PWR_LED_ON 0x0004
126#define PWR_LED_BLINK 0x0008
127#define PWR_LED_OFF 0x000c
128
129/* Attention Indicator State */
130#define ATTEN_LED_ON 0x0010
131#define ATTEN_LED_BLINK 0x0020
132#define ATTEN_LED_OFF 0x0030
133
134/* Power Fault */
135#define pwr_fault 0x0040
136
137/* Attention Button */
138#define ATTEN_BUTTON 0x0080
139
140/* MRL Sensor */
141#define MRL_SENSOR 0x0100
142
143/* 66 MHz Capable */
144#define IS_66MHZ_CAP 0x0200
145
146/* PRSNT1#/PRSNT2# */
147#define SLOT_EMP 0x0c00
148
149/* PCI-X Capability */
150#define NON_PCIX 0x0000
151#define PCIX_66 0x1000
152#define PCIX_133 0x3000
153#define PCIX_266 0x4000 /* For PI = 2 only */
154#define PCIX_533 0x5000 /* For PI = 2 only */
155
156/* SHPC 'write' operations/commands */
157
158/* Slot operation - 0x00h to 0x3Fh */
159
160#define NO_CHANGE 0x00
161
162/* Slot state - Bits 0 & 1 of controller command register */
163#define SET_SLOT_PWR 0x01
164#define SET_SLOT_ENABLE 0x02
165#define SET_SLOT_DISABLE 0x03
166
167/* Power indicator state - Bits 2 & 3 of controller command register*/
168#define SET_PWR_ON 0x04
169#define SET_PWR_BLINK 0x08
170#define SET_PWR_OFF 0x0C
171
172/* Attention indicator state - Bits 4 & 5 of controller command register*/
173#define SET_ATTN_ON 0x010
174#define SET_ATTN_BLINK 0x020
175#define SET_ATTN_OFF 0x030
176
177/* Set bus speed/mode A - 0x40h to 0x47h */
178#define SETA_PCI_33MHZ 0x40
179#define SETA_PCI_66MHZ 0x41
180#define SETA_PCIX_66MHZ 0x42
181#define SETA_PCIX_100MHZ 0x43
182#define SETA_PCIX_133MHZ 0x44
183#define RESERV_1 0x45
184#define RESERV_2 0x46
185#define RESERV_3 0x47
186
187/* Set bus speed/mode B - 0x50h to 0x5fh */
188#define SETB_PCI_33MHZ 0x50
189#define SETB_PCI_66MHZ 0x51
190#define SETB_PCIX_66MHZ_PM 0x52
191#define SETB_PCIX_100MHZ_PM 0x53
192#define SETB_PCIX_133MHZ_PM 0x54
193#define SETB_PCIX_66MHZ_EM 0x55
194#define SETB_PCIX_100MHZ_EM 0x56
195#define SETB_PCIX_133MHZ_EM 0x57
196#define SETB_PCIX_66MHZ_266 0x58
197#define SETB_PCIX_100MHZ_266 0x59
198#define SETB_PCIX_133MHZ_266 0x5a
199#define SETB_PCIX_66MHZ_533 0x5b
200#define SETB_PCIX_100MHZ_533 0x5c
201#define SETB_PCIX_133MHZ_533 0x5d
202
203
204/* Power-on all slots - 0x48h */
205#define SET_PWR_ON_ALL 0x48
206
207/* Enable all slots - 0x49h */
208#define SET_ENABLE_ALL 0x49
209
210/* SHPC controller command error code */
211#define SWITCH_OPEN 0x1
212#define INVALID_CMD 0x2
213#define INVALID_SPEED_MODE 0x4
214
215/* For accessing SHPC Working Register Set */
216#define DWORD_SELECT 0x2
217#define DWORD_DATA 0x4
218#define BASE_OFFSET 0x0
219
220/* Field Offset in Logical Slot Register - byte boundary */
221#define SLOT_EVENT_LATCH 0x2
222#define SLOT_SERR_INT_MASK 0x3
223
224static spinlock_t hpc_event_lock;
225
226DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
227static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
228static int ctlr_seq_num = 0; /* Controller sequenc # */
229static spinlock_t list_lock;
230
231static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs);
232
233static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900234static int hpc_check_cmd_status(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236/* This is the interrupt polling timeout function. */
237static void int_poll_timeout(unsigned long lphp_ctlr)
238{
239 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr;
240
241 DBG_ENTER_ROUTINE
242
243 if ( !php_ctlr ) {
244 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
245 return;
246 }
247
248 /* Poll for interrupt events. regs == NULL => polling */
249 shpc_isr( 0, (void *)php_ctlr, NULL );
250
251 init_timer(&php_ctlr->int_poll_timer);
252 if (!shpchp_poll_time)
253 shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
254
255 start_int_poll_timer(php_ctlr, shpchp_poll_time);
256
257 return;
258}
259
260/* This function starts the interrupt polling timer. */
261static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
262{
263 if (!php_ctlr) {
264 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
265 return;
266 }
267
268 if ( ( seconds <= 0 ) || ( seconds > 60 ) )
269 seconds = 2; /* Clamp to sane value */
270
271 php_ctlr->int_poll_timer.function = &int_poll_timeout;
272 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */
273 php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ;
274 add_timer(&php_ctlr->int_poll_timer);
275
276 return;
277}
278
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900279static inline int shpc_wait_cmd(struct controller *ctrl)
280{
281 int retval = 0;
282 unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000;
283 unsigned long timeout = msecs_to_jiffies(timeout_msec);
284 int rc = wait_event_interruptible_timeout(ctrl->queue,
285 !ctrl->cmd_busy, timeout);
286 if (!rc) {
287 retval = -EIO;
288 err("Command not completed in %d msec\n", timeout_msec);
289 } else if (rc < 0) {
290 retval = -EINTR;
291 info("Command was interrupted by a signal\n");
292 }
293 ctrl->cmd_busy = 0;
294
295 return retval;
296}
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
299{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700300 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 u16 cmd_status;
302 int retval = 0;
303 u16 temp_word;
304 int i;
305
306 DBG_ENTER_ROUTINE
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900307
308 mutex_lock(&slot->ctrl->cmd_lock);
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 if (!php_ctlr) {
311 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900312 retval = -EINVAL;
313 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315
316 for (i = 0; i < 10; i++) {
317 cmd_status = readw(php_ctlr->creg + CMD_STATUS);
318
319 if (!(cmd_status & 0x1))
320 break;
321 /* Check every 0.1 sec for a total of 1 sec*/
322 msleep(100);
323 }
324
325 cmd_status = readw(php_ctlr->creg + CMD_STATUS);
326
327 if (cmd_status & 0x1) {
328 /* After 1 sec and and the controller is still busy */
329 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900330 retval = -EBUSY;
331 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
334 ++t_slot;
335 temp_word = (t_slot << 8) | (cmd & 0xFF);
336 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
337
338 /* To make sure the Controller Busy bit is 0 before we send out the
339 * command.
340 */
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900341 slot->ctrl->cmd_busy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 writew(temp_word, php_ctlr->creg + CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900344 /*
345 * Wait for command completion.
346 */
347 retval = shpc_wait_cmd(slot->ctrl);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +0900348 if (retval)
349 goto out;
350
351 cmd_status = hpc_check_cmd_status(slot->ctrl);
352 if (cmd_status) {
353 err("%s: Failed to issued command 0x%x (error code = %d)\n",
354 __FUNCTION__, cmd, cmd_status);
355 retval = -EIO;
356 }
357 out:
358 mutex_unlock(&slot->ctrl->cmd_lock);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +0900359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 DBG_LEAVE_ROUTINE
361 return retval;
362}
363
364static int hpc_check_cmd_status(struct controller *ctrl)
365{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700366 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 u16 cmd_status;
368 int retval = 0;
369
370 DBG_ENTER_ROUTINE
371
372 if (!ctrl->hpc_ctlr_handle) {
373 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
374 return -1;
375 }
376
377 cmd_status = readw(php_ctlr->creg + CMD_STATUS) & 0x000F;
378
379 switch (cmd_status >> 1) {
380 case 0:
381 retval = 0;
382 break;
383 case 1:
384 retval = SWITCH_OPEN;
385 err("%s: Switch opened!\n", __FUNCTION__);
386 break;
387 case 2:
388 retval = INVALID_CMD;
389 err("%s: Invalid HPC command!\n", __FUNCTION__);
390 break;
391 case 4:
392 retval = INVALID_SPEED_MODE;
393 err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
394 break;
395 default:
396 retval = cmd_status;
397 }
398
399 DBG_LEAVE_ROUTINE
400 return retval;
401}
402
403
404static int hpc_get_attention_status(struct slot *slot, u8 *status)
405{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700406 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 u32 slot_reg;
408 u16 slot_status;
409 u8 atten_led_state;
410
411 DBG_ENTER_ROUTINE
412
413 if (!slot->ctrl->hpc_ctlr_handle) {
414 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
415 return -1;
416 }
417
418 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
419 slot_status = (u16) slot_reg;
420 atten_led_state = (slot_status & 0x0030) >> 4;
421
422 switch (atten_led_state) {
423 case 0:
424 *status = 0xFF; /* Reserved */
425 break;
426 case 1:
427 *status = 1; /* On */
428 break;
429 case 2:
430 *status = 2; /* Blink */
431 break;
432 case 3:
433 *status = 0; /* Off */
434 break;
435 default:
436 *status = 0xFF;
437 break;
438 }
439
440 DBG_LEAVE_ROUTINE
441 return 0;
442}
443
444static int hpc_get_power_status(struct slot * slot, u8 *status)
445{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700446 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 u32 slot_reg;
448 u16 slot_status;
449 u8 slot_state;
450 int retval = 0;
451
452 DBG_ENTER_ROUTINE
453
454 if (!slot->ctrl->hpc_ctlr_handle) {
455 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
456 return -1;
457 }
458
459 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
460 slot_status = (u16) slot_reg;
461 slot_state = (slot_status & 0x0003);
462
463 switch (slot_state) {
464 case 0:
465 *status = 0xFF;
466 break;
467 case 1:
468 *status = 2; /* Powered only */
469 break;
470 case 2:
471 *status = 1; /* Enabled */
472 break;
473 case 3:
474 *status = 0; /* Disabled */
475 break;
476 default:
477 *status = 0xFF;
478 break;
479 }
480
481 DBG_LEAVE_ROUTINE
482 return retval;
483}
484
485
486static int hpc_get_latch_status(struct slot *slot, u8 *status)
487{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700488 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 u32 slot_reg;
490 u16 slot_status;
491
492 DBG_ENTER_ROUTINE
493
494 if (!slot->ctrl->hpc_ctlr_handle) {
495 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
496 return -1;
497 }
498
499 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
500 slot_status = (u16)slot_reg;
501
502 *status = ((slot_status & 0x0100) == 0) ? 0 : 1; /* 0 -> close; 1 -> open */
503
504
505 DBG_LEAVE_ROUTINE
506 return 0;
507}
508
509static int hpc_get_adapter_status(struct slot *slot, u8 *status)
510{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700511 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 u32 slot_reg;
513 u16 slot_status;
514 u8 card_state;
515
516 DBG_ENTER_ROUTINE
517
518 if (!slot->ctrl->hpc_ctlr_handle) {
519 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
520 return -1;
521 }
522
523 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
524 slot_status = (u16)slot_reg;
525 card_state = (u8)((slot_status & 0x0C00) >> 10);
526 *status = (card_state != 0x3) ? 1 : 0;
527
528 DBG_LEAVE_ROUTINE
529 return 0;
530}
531
532static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
533{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700534 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 DBG_ENTER_ROUTINE
537
538 if (!slot->ctrl->hpc_ctlr_handle) {
539 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
540 return -1;
541 }
542
543 *prog_int = readb(php_ctlr->creg + PROG_INTERFACE);
544
545 DBG_LEAVE_ROUTINE
546 return 0;
547}
548
549static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
550{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700551 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 u32 slot_reg;
553 u16 slot_status, sec_bus_status;
554 u8 m66_cap, pcix_cap, pi;
555 int retval = 0;
556
557 DBG_ENTER_ROUTINE
558
559 if (!slot->ctrl->hpc_ctlr_handle) {
560 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
561 return -1;
562 }
563
564 if (slot->hp_slot >= php_ctlr->num_slots) {
565 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
566 return -1;
567 }
568
569 pi = readb(php_ctlr->creg + PROG_INTERFACE);
570 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
571 dbg("%s: pi = %d, slot_reg = %x\n", __FUNCTION__, pi, slot_reg);
572 slot_status = (u16) slot_reg;
573 dbg("%s: slot_status = %x\n", __FUNCTION__, slot_status);
574 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
575
576 pcix_cap = (u8) ((slot_status & 0x3000) >> 12);
577 dbg("%s: pcix_cap = %x\n", __FUNCTION__, pcix_cap);
578 m66_cap = (u8) ((slot_status & 0x0200) >> 9);
579 dbg("%s: m66_cap = %x\n", __FUNCTION__, m66_cap);
580
581
582 if (pi == 2) {
583 switch (pcix_cap) {
584 case 0:
585 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
586 break;
587 case 1:
588 *value = PCI_SPEED_66MHz_PCIX;
589 break;
590 case 3:
591 *value = PCI_SPEED_133MHz_PCIX;
592 break;
593 case 4:
594 *value = PCI_SPEED_133MHz_PCIX_266;
595 break;
596 case 5:
597 *value = PCI_SPEED_133MHz_PCIX_533;
598 break;
599 case 2: /* Reserved */
600 default:
601 *value = PCI_SPEED_UNKNOWN;
602 retval = -ENODEV;
603 break;
604 }
605 } else {
606 switch (pcix_cap) {
607 case 0:
608 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
609 break;
610 case 1:
611 *value = PCI_SPEED_66MHz_PCIX;
612 break;
613 case 3:
614 *value = PCI_SPEED_133MHz_PCIX;
615 break;
616 case 2: /* Reserved */
617 default:
618 *value = PCI_SPEED_UNKNOWN;
619 retval = -ENODEV;
620 break;
621 }
622 }
623
624 dbg("Adapter speed = %d\n", *value);
625
626 DBG_LEAVE_ROUTINE
627 return retval;
628}
629
630static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
631{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700632 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 u16 sec_bus_status;
634 u8 pi;
635 int retval = 0;
636
637 DBG_ENTER_ROUTINE
638
639 if (!slot->ctrl->hpc_ctlr_handle) {
640 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
641 return -1;
642 }
643
644 pi = readb(php_ctlr->creg + PROG_INTERFACE);
645 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
646
647 if (pi == 2) {
Kenji Kaneshige87d6c552005-11-24 11:35:05 +0900648 *mode = (sec_bus_status & 0x0100) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 } else {
650 retval = -1;
651 }
652
653 dbg("Mode 1 ECC cap = %d\n", *mode);
654
655 DBG_LEAVE_ROUTINE
656 return retval;
657}
658
659static int hpc_query_power_fault(struct slot * slot)
660{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700661 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 u32 slot_reg;
663 u16 slot_status;
664 u8 pwr_fault_state, status;
665
666 DBG_ENTER_ROUTINE
667
668 if (!slot->ctrl->hpc_ctlr_handle) {
669 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
670 return -1;
671 }
672
673 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
674 slot_status = (u16) slot_reg;
675 pwr_fault_state = (slot_status & 0x0040) >> 7;
676 status = (pwr_fault_state == 1) ? 0 : 1;
677
678 DBG_LEAVE_ROUTINE
679 /* Note: Logic 0 => fault */
680 return status;
681}
682
683static int hpc_set_attention_status(struct slot *slot, u8 value)
684{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700685 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 u8 slot_cmd = 0;
687 int rc = 0;
688
689 if (!slot->ctrl->hpc_ctlr_handle) {
690 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
691 return -1;
692 }
693
694 if (slot->hp_slot >= php_ctlr->num_slots) {
695 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
696 return -1;
697 }
698
699 switch (value) {
700 case 0 :
701 slot_cmd = 0x30; /* OFF */
702 break;
703 case 1:
704 slot_cmd = 0x10; /* ON */
705 break;
706 case 2:
707 slot_cmd = 0x20; /* BLINK */
708 break;
709 default:
710 return -1;
711 }
712
713 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
714
715 return rc;
716}
717
718
719static void hpc_set_green_led_on(struct slot *slot)
720{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700721 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 u8 slot_cmd;
723
724 if (!slot->ctrl->hpc_ctlr_handle) {
725 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
726 return ;
727 }
728
729 if (slot->hp_slot >= php_ctlr->num_slots) {
730 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
731 return ;
732 }
733
734 slot_cmd = 0x04;
735
736 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
737
738 return;
739}
740
741static void hpc_set_green_led_off(struct slot *slot)
742{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700743 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 u8 slot_cmd;
745
746 if (!slot->ctrl->hpc_ctlr_handle) {
747 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
748 return ;
749 }
750
751 if (slot->hp_slot >= php_ctlr->num_slots) {
752 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
753 return ;
754 }
755
756 slot_cmd = 0x0C;
757
758 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
759
760 return;
761}
762
763static void hpc_set_green_led_blink(struct slot *slot)
764{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700765 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 u8 slot_cmd;
767
768 if (!slot->ctrl->hpc_ctlr_handle) {
769 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
770 return ;
771 }
772
773 if (slot->hp_slot >= php_ctlr->num_slots) {
774 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
775 return ;
776 }
777
778 slot_cmd = 0x08;
779
780 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
781
782 return;
783}
784
785int shpc_get_ctlr_slot_config(struct controller *ctrl,
786 int *num_ctlr_slots, /* number of slots in this HPC */
787 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
788 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
789 int *updown, /* physical_slot_num increament: 1 or -1 */
790 int *flags)
791{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700792 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 DBG_ENTER_ROUTINE
795
796 if (!ctrl->hpc_ctlr_handle) {
797 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
798 return -1;
799 }
800
801 *first_device_num = php_ctlr->slot_device_offset; /* Obtained in shpc_init() */
802 *num_ctlr_slots = php_ctlr->num_slots; /* Obtained in shpc_init() */
803
804 *physical_slot_num = (readl(php_ctlr->creg + SLOT_CONFIG) & PSN) >> 16;
805 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
806 *updown = ((readl(php_ctlr->creg + SLOT_CONFIG) & UPDOWN ) >> 29) ? 1 : -1;
807
808 DBG_LEAVE_ROUTINE
809 return 0;
810}
811
812static void hpc_release_ctlr(struct controller *ctrl)
813{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700814 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 struct php_ctlr_state_s *p, *p_prev;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800816 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 DBG_ENTER_ROUTINE
819
820 if (!ctrl->hpc_ctlr_handle) {
821 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
822 return ;
823 }
824
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800825 /*
826 * Mask all slot event interrupts
827 */
828 for (i = 0; i < ctrl->num_slots; i++)
829 writel(0xffff3fff, php_ctlr->creg + SLOT1 + (4 * i));
830
831 cleanup_slots(ctrl);
832
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (shpchp_poll_mode) {
834 del_timer(&php_ctlr->int_poll_timer);
835 } else {
836 if (php_ctlr->irq) {
837 free_irq(php_ctlr->irq, ctrl);
838 php_ctlr->irq = 0;
839 pci_disable_msi(php_ctlr->pci_dev);
840 }
841 }
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 if (php_ctlr->pci_dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 iounmap(php_ctlr->creg);
Kenji Kaneshige04559862005-11-24 11:36:59 +0900845 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 php_ctlr->pci_dev = NULL;
847 }
848
849 spin_lock(&list_lock);
850 p = php_ctlr_list_head;
851 p_prev = NULL;
852 while (p) {
853 if (p == php_ctlr) {
854 if (p_prev)
855 p_prev->pnext = p->pnext;
856 else
857 php_ctlr_list_head = p->pnext;
858 break;
859 } else {
860 p_prev = p;
861 p = p->pnext;
862 }
863 }
864 spin_unlock(&list_lock);
865
866 kfree(php_ctlr);
867
868DBG_LEAVE_ROUTINE
869
870}
871
872static int hpc_power_on_slot(struct slot * slot)
873{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700874 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 u8 slot_cmd;
876 int retval = 0;
877
878 DBG_ENTER_ROUTINE
879
880 if (!slot->ctrl->hpc_ctlr_handle) {
881 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
882 return -1;
883 }
884
885 if (slot->hp_slot >= php_ctlr->num_slots) {
886 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
887 return -1;
888 }
889 slot_cmd = 0x01;
890
891 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
892
893 if (retval) {
894 err("%s: Write command failed!\n", __FUNCTION__);
895 return -1;
896 }
897
898 DBG_LEAVE_ROUTINE
899
900 return retval;
901}
902
903static int hpc_slot_enable(struct slot * slot)
904{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700905 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 u8 slot_cmd;
907 int retval = 0;
908
909 DBG_ENTER_ROUTINE
910
911 if (!slot->ctrl->hpc_ctlr_handle) {
912 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
913 return -1;
914 }
915
916 if (slot->hp_slot >= php_ctlr->num_slots) {
917 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
918 return -1;
919 }
920 /* 3A => Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
921 slot_cmd = 0x3A;
922
923 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
924
925 if (retval) {
926 err("%s: Write command failed!\n", __FUNCTION__);
927 return -1;
928 }
929
930 DBG_LEAVE_ROUTINE
931 return retval;
932}
933
934static int hpc_slot_disable(struct slot * slot)
935{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700936 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 u8 slot_cmd;
938 int retval = 0;
939
940 DBG_ENTER_ROUTINE
941
942 if (!slot->ctrl->hpc_ctlr_handle) {
943 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
944 return -1;
945 }
946
947 if (slot->hp_slot >= php_ctlr->num_slots) {
948 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
949 return -1;
950 }
951
952 /* 1F => Slot - Disable, Power Indicator - Off, Attention Indicator - On */
953 slot_cmd = 0x1F;
954
955 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
956
957 if (retval) {
958 err("%s: Write command failed!\n", __FUNCTION__);
959 return -1;
960 }
961
962 DBG_LEAVE_ROUTINE
963 return retval;
964}
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
967{
968 u8 slot_cmd;
969 u8 pi;
970 int retval = 0;
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700971 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 DBG_ENTER_ROUTINE
974
975 if (!slot->ctrl->hpc_ctlr_handle) {
976 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
977 return -1;
978 }
979
980 pi = readb(php_ctlr->creg + PROG_INTERFACE);
981
982 if (pi == 1) {
983 switch (value) {
984 case 0:
985 slot_cmd = SETA_PCI_33MHZ;
986 break;
987 case 1:
988 slot_cmd = SETA_PCI_66MHZ;
989 break;
990 case 2:
991 slot_cmd = SETA_PCIX_66MHZ;
992 break;
993 case 3:
994 slot_cmd = SETA_PCIX_100MHZ;
995 break;
996 case 4:
997 slot_cmd = SETA_PCIX_133MHZ;
998 break;
999 default:
1000 slot_cmd = PCI_SPEED_UNKNOWN;
1001 retval = -ENODEV;
1002 return retval;
1003 }
1004 } else {
1005 switch (value) {
1006 case 0:
1007 slot_cmd = SETB_PCI_33MHZ;
1008 break;
1009 case 1:
1010 slot_cmd = SETB_PCI_66MHZ;
1011 break;
1012 case 2:
1013 slot_cmd = SETB_PCIX_66MHZ_PM;
1014 break;
1015 case 3:
1016 slot_cmd = SETB_PCIX_100MHZ_PM;
1017 break;
1018 case 4:
1019 slot_cmd = SETB_PCIX_133MHZ_PM;
1020 break;
1021 case 5:
1022 slot_cmd = SETB_PCIX_66MHZ_EM;
1023 break;
1024 case 6:
1025 slot_cmd = SETB_PCIX_100MHZ_EM;
1026 break;
1027 case 7:
1028 slot_cmd = SETB_PCIX_133MHZ_EM;
1029 break;
1030 case 8:
1031 slot_cmd = SETB_PCIX_66MHZ_266;
1032 break;
1033 case 0x9:
1034 slot_cmd = SETB_PCIX_100MHZ_266;
1035 break;
1036 case 0xa:
1037 slot_cmd = SETB_PCIX_133MHZ_266;
1038 break;
1039 case 0xb:
1040 slot_cmd = SETB_PCIX_66MHZ_533;
1041 break;
1042 case 0xc:
1043 slot_cmd = SETB_PCIX_100MHZ_533;
1044 break;
1045 case 0xd:
1046 slot_cmd = SETB_PCIX_133MHZ_533;
1047 break;
1048 default:
1049 slot_cmd = PCI_SPEED_UNKNOWN;
1050 retval = -ENODEV;
1051 return retval;
1052 }
1053
1054 }
1055 retval = shpc_write_cmd(slot, 0, slot_cmd);
1056 if (retval) {
1057 err("%s: Write command failed!\n", __FUNCTION__);
1058 return -1;
1059 }
1060
1061 DBG_LEAVE_ROUTINE
1062 return retval;
1063}
1064
1065static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1066{
1067 struct controller *ctrl = NULL;
1068 struct php_ctlr_state_s *php_ctlr;
1069 u8 schedule_flag = 0;
1070 u8 temp_byte;
1071 u32 temp_dword, intr_loc, intr_loc2;
1072 int hp_slot;
1073
1074 if (!dev_id)
1075 return IRQ_NONE;
1076
1077 if (!shpchp_poll_mode) {
1078 ctrl = (struct controller *)dev_id;
1079 php_ctlr = ctrl->hpc_ctlr_handle;
1080 } else {
1081 php_ctlr = (struct php_ctlr_state_s *) dev_id;
1082 ctrl = (struct controller *)php_ctlr->callback_instance_id;
1083 }
1084
1085 if (!ctrl)
1086 return IRQ_NONE;
1087
1088 if (!php_ctlr || !php_ctlr->creg)
1089 return IRQ_NONE;
1090
1091 /* Check to see if it was our interrupt */
1092 intr_loc = readl(php_ctlr->creg + INTR_LOC);
1093
1094 if (!intr_loc)
1095 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
1097
1098 if(!shpchp_poll_mode) {
1099 /* Mask Global Interrupt Mask - see implementation note on p. 139 */
1100 /* of SHPC spec rev 1.0*/
1101 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 temp_dword |= 0x00000001;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1104
1105 intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
1106 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1107 }
1108
1109 if (intr_loc & 0x0001) {
1110 /*
1111 * Command Complete Interrupt Pending
Kenji Kaneshigef467f612005-11-24 11:39:29 +09001112 * RO only - clear by writing 1 to the Command Completion
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 * Detect bit in Controller SERR-INT register
1114 */
1115 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
Kenji Kaneshigef467f612005-11-24 11:39:29 +09001116 temp_dword &= 0xfffdffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
Kenji Kaneshigebd62e272005-11-25 12:28:53 +09001118 ctrl->cmd_busy = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 wake_up_interruptible(&ctrl->queue);
1120 }
1121
Kenji Kaneshigee4e73042006-01-26 10:05:57 +09001122 if ((intr_loc = (intr_loc >> 1)) == 0)
1123 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1126 /* To find out which slot has interrupt pending */
1127 if ((intr_loc >> hp_slot) & 0x01) {
1128 temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot));
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001129 dbg("%s: Slot %x with intr, slot register = %x\n",
1130 __FUNCTION__, hp_slot, temp_dword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 temp_byte = (temp_dword >> 16) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08))
1133 schedule_flag += php_ctlr->switch_change_callback(
1134 hp_slot, php_ctlr->callback_instance_id);
1135 if ((php_ctlr->attention_button_callback) && (temp_byte & 0x04))
1136 schedule_flag += php_ctlr->attention_button_callback(
1137 hp_slot, php_ctlr->callback_instance_id);
1138 if ((php_ctlr->presence_change_callback) && (temp_byte & 0x01))
1139 schedule_flag += php_ctlr->presence_change_callback(
1140 hp_slot , php_ctlr->callback_instance_id);
1141 if ((php_ctlr->power_fault_callback) && (temp_byte & 0x12))
1142 schedule_flag += php_ctlr->power_fault_callback(
1143 hp_slot, php_ctlr->callback_instance_id);
1144
1145 /* Clear all slot events */
1146 temp_dword = 0xe01f3fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1148
1149 intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
1150 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1151 }
1152 }
Kenji Kaneshigee4e73042006-01-26 10:05:57 +09001153 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 if (!shpchp_poll_mode) {
1155 /* Unmask Global Interrupt Mask */
1156 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 temp_dword &= 0xfffffffe;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1159 }
1160
1161 return IRQ_HANDLED;
1162}
1163
1164static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1165{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001166 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1168 int retval = 0;
1169 u8 pi;
1170 u32 slot_avail1, slot_avail2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 DBG_ENTER_ROUTINE
1173
1174 if (!slot->ctrl->hpc_ctlr_handle) {
1175 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
1176 return -1;
1177 }
1178
1179 if (slot->hp_slot >= php_ctlr->num_slots) {
1180 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
1181 return -1;
1182 }
1183
1184 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1185 slot_avail1 = readl(php_ctlr->creg + SLOT_AVAIL1);
1186 slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);
1187
1188 if (pi == 2) {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001189 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 bus_speed = PCIX_133MHZ_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001191 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 bus_speed = PCIX_100MHZ_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001193 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 bus_speed = PCIX_66MHZ_533;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001195 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 bus_speed = PCIX_133MHZ_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001197 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 bus_speed = PCIX_100MHZ_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001199 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 bus_speed = PCIX_66MHZ_266;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001201 else if (slot_avail1 & SLOT_133MHZ_PCIX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 bus_speed = PCIX_133MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001203 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 bus_speed = PCIX_100MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001205 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 bus_speed = PCIX_66MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001207 else if (slot_avail2 & SLOT_66MHZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 bus_speed = PCI_66MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001209 else if (slot_avail1 & SLOT_33MHZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 bus_speed = PCI_33MHZ;
1211 else bus_speed = PCI_SPEED_UNKNOWN;
1212 } else {
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001213 if (slot_avail1 & SLOT_133MHZ_PCIX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 bus_speed = PCIX_133MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001215 else if (slot_avail1 & SLOT_100MHZ_PCIX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 bus_speed = PCIX_100MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001217 else if (slot_avail1 & SLOT_66MHZ_PCIX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 bus_speed = PCIX_66MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001219 else if (slot_avail2 & SLOT_66MHZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 bus_speed = PCI_66MHZ;
Kenji Kaneshige6558b6a2005-11-24 13:44:01 +09001221 else if (slot_avail1 & SLOT_33MHZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 bus_speed = PCI_33MHZ;
1223 else bus_speed = PCI_SPEED_UNKNOWN;
1224 }
1225
1226 *value = bus_speed;
1227 dbg("Max bus speed = %d\n", bus_speed);
1228 DBG_LEAVE_ROUTINE
1229 return retval;
1230}
1231
1232static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1233{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001234 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1236 u16 sec_bus_status;
1237 int retval = 0;
1238 u8 pi;
1239
1240 DBG_ENTER_ROUTINE
1241
1242 if (!slot->ctrl->hpc_ctlr_handle) {
1243 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
1244 return -1;
1245 }
1246
1247 if (slot->hp_slot >= php_ctlr->num_slots) {
1248 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
1249 return -1;
1250 }
1251
1252 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1253 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
1254
1255 if (pi == 2) {
1256 switch (sec_bus_status & 0x000f) {
1257 case 0:
1258 bus_speed = PCI_SPEED_33MHz;
1259 break;
1260 case 1:
1261 bus_speed = PCI_SPEED_66MHz;
1262 break;
1263 case 2:
1264 bus_speed = PCI_SPEED_66MHz_PCIX;
1265 break;
1266 case 3:
1267 bus_speed = PCI_SPEED_100MHz_PCIX;
1268 break;
1269 case 4:
1270 bus_speed = PCI_SPEED_133MHz_PCIX;
1271 break;
1272 case 5:
1273 bus_speed = PCI_SPEED_66MHz_PCIX_ECC;
1274 break;
1275 case 6:
1276 bus_speed = PCI_SPEED_100MHz_PCIX_ECC;
1277 break;
1278 case 7:
1279 bus_speed = PCI_SPEED_133MHz_PCIX_ECC;
1280 break;
1281 case 8:
1282 bus_speed = PCI_SPEED_66MHz_PCIX_266;
1283 break;
1284 case 9:
1285 bus_speed = PCI_SPEED_100MHz_PCIX_266;
1286 break;
1287 case 0xa:
1288 bus_speed = PCI_SPEED_133MHz_PCIX_266;
1289 break;
1290 case 0xb:
1291 bus_speed = PCI_SPEED_66MHz_PCIX_533;
1292 break;
1293 case 0xc:
1294 bus_speed = PCI_SPEED_100MHz_PCIX_533;
1295 break;
1296 case 0xd:
1297 bus_speed = PCI_SPEED_133MHz_PCIX_533;
1298 break;
1299 case 0xe:
1300 case 0xf:
1301 default:
1302 bus_speed = PCI_SPEED_UNKNOWN;
1303 break;
1304 }
1305 } else {
1306 /* In the case where pi is undefined, default it to 1 */
1307 switch (sec_bus_status & 0x0007) {
1308 case 0:
1309 bus_speed = PCI_SPEED_33MHz;
1310 break;
1311 case 1:
1312 bus_speed = PCI_SPEED_66MHz;
1313 break;
1314 case 2:
1315 bus_speed = PCI_SPEED_66MHz_PCIX;
1316 break;
1317 case 3:
1318 bus_speed = PCI_SPEED_100MHz_PCIX;
1319 break;
1320 case 4:
1321 bus_speed = PCI_SPEED_133MHz_PCIX;
1322 break;
1323 case 5:
1324 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1325 break;
1326 case 6:
1327 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1328 break;
1329 case 7:
1330 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1331 break;
1332 default:
1333 bus_speed = PCI_SPEED_UNKNOWN;
1334 break;
1335 }
1336 }
1337
1338 *value = bus_speed;
1339 dbg("Current bus speed = %d\n", bus_speed);
1340 DBG_LEAVE_ROUTINE
1341 return retval;
1342}
1343
1344static struct hpc_ops shpchp_hpc_ops = {
1345 .power_on_slot = hpc_power_on_slot,
1346 .slot_enable = hpc_slot_enable,
1347 .slot_disable = hpc_slot_disable,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1349 .set_attention_status = hpc_set_attention_status,
1350 .get_power_status = hpc_get_power_status,
1351 .get_attention_status = hpc_get_attention_status,
1352 .get_latch_status = hpc_get_latch_status,
1353 .get_adapter_status = hpc_get_adapter_status,
1354
1355 .get_max_bus_speed = hpc_get_max_bus_speed,
1356 .get_cur_bus_speed = hpc_get_cur_bus_speed,
1357 .get_adapter_speed = hpc_get_adapter_speed,
1358 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
1359 .get_prog_int = hpc_get_prog_int,
1360
1361 .query_power_fault = hpc_query_power_fault,
1362 .green_led_on = hpc_set_green_led_on,
1363 .green_led_off = hpc_set_green_led_off,
1364 .green_led_blink = hpc_set_green_led_blink,
1365
1366 .release_ctlr = hpc_release_ctlr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367};
1368
Kenji Kaneshige04559862005-11-24 11:36:59 +09001369inline static int shpc_indirect_creg_read(struct controller *ctrl, int index,
1370 u32 *value)
1371{
1372 int rc;
1373 u32 cap_offset = ctrl->cap_offset;
1374 struct pci_dev *pdev = ctrl->pci_dev;
1375
1376 rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
1377 if (rc)
1378 return rc;
1379 return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
1380}
1381
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001382int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
1384 struct php_ctlr_state_s *php_ctlr, *p;
1385 void *instance_id = ctrl;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001386 int rc, num_slots = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 u8 hp_slot;
1388 static int first = 1;
Kenji Kaneshige04559862005-11-24 11:36:59 +09001389 u32 shpc_base_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 u32 tempdword, slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 u8 i;
1392
1393 DBG_ENTER_ROUTINE
1394
Kenji Kaneshige04559862005-11-24 11:36:59 +09001395 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 spin_lock_init(&list_lock);
Kenji Kaneshige57c95c02006-01-26 10:02:41 +09001398 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
1400 if (!php_ctlr) { /* allocate controller state data */
1401 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1402 goto abort;
1403 }
1404
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1406
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001407 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1408 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001409 /* amd shpc driver doesn't use Base Offset; assume 0 */
1410 ctrl->mmio_base = pci_resource_start(pdev, 0);
1411 ctrl->mmio_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 } else {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001413 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1414 if (!ctrl->cap_offset) {
1415 err("%s : cap_offset == 0\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 goto abort_free_ctlr;
1417 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001418 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1419
1420 rc = shpc_indirect_creg_read(ctrl, 0, &shpc_base_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001422 err("%s: cannot read base_offset\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 goto abort_free_ctlr;
1424 }
1425
Kenji Kaneshige04559862005-11-24 11:36:59 +09001426 rc = shpc_indirect_creg_read(ctrl, 3, &tempdword);
1427 if (rc) {
1428 err("%s: cannot read slot config\n", __FUNCTION__);
1429 goto abort_free_ctlr;
1430 }
1431 num_slots = tempdword & SLOT_NUM;
1432 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
1433
1434 for (i = 0; i < 9 + num_slots; i++) {
1435 rc = shpc_indirect_creg_read(ctrl, i, &tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 if (rc) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001437 err("%s: cannot read creg (index = %d)\n",
1438 __FUNCTION__, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 goto abort_free_ctlr;
1440 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001441 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1442 tempdword);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
Kenji Kaneshige04559862005-11-24 11:36:59 +09001444
1445 ctrl->mmio_base =
1446 pci_resource_start(pdev, 0) + shpc_base_offset;
1447 ctrl->mmio_size = 0x24 + 0x4 * num_slots;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
1449
1450 if (first) {
1451 spin_lock_init(&hpc_event_lock);
1452 first = 0;
1453 }
1454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1456 pdev->subsystem_device);
1457
1458 if (pci_enable_device(pdev))
1459 goto abort_free_ctlr;
1460
Kenji Kaneshige04559862005-11-24 11:36:59 +09001461 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1463 goto abort_free_ctlr;
1464 }
1465
Kenji Kaneshige04559862005-11-24 11:36:59 +09001466 php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 if (!php_ctlr->creg) {
Kenji Kaneshige04559862005-11-24 11:36:59 +09001468 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1469 ctrl->mmio_size, ctrl->mmio_base);
1470 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 goto abort_free_ctlr;
1472 }
1473 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001475 mutex_init(&ctrl->crit_sect);
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +09001476 mutex_init(&ctrl->cmd_lock);
1477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 /* Setup wait queue */
1479 init_waitqueue_head(&ctrl->queue);
1480
1481 /* Find the IRQ */
1482 php_ctlr->irq = pdev->irq;
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001483 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1484 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1485 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1486 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 php_ctlr->callback_instance_id = instance_id;
1488
1489 /* Return PCI Controller Info */
1490 php_ctlr->slot_device_offset = (readl(php_ctlr->creg + SLOT_CONFIG) & FIRST_DEV_NUM ) >> 8;
1491 php_ctlr->num_slots = readl(php_ctlr->creg + SLOT_CONFIG) & SLOT_NUM;
1492 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
1493 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
1494
1495 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
1496 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1497 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1498 tempdword = 0x0003000f;
1499 writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);
1500 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1501 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1502
1503 /* Mask the MRL sensor SERR Mask of individual slot in
1504 * Slot SERR-INT Mask & clear all the existing event if any
1505 */
1506 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
1507 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );
1508 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1509 hp_slot, slot_reg);
1510 tempdword = 0xffff3fff;
1511 writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1512 }
1513
1514 if (shpchp_poll_mode) {/* Install interrupt polling code */
1515 /* Install and start the interrupt polling timer */
1516 init_timer(&php_ctlr->int_poll_timer);
1517 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
1518 } else {
1519 /* Installs the interrupt handler */
1520 rc = pci_enable_msi(pdev);
1521 if (rc) {
1522 info("Can't get msi for the hotplug controller\n");
1523 info("Use INTx for the hotplug controller\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 } else
1525 php_ctlr->irq = pdev->irq;
1526
1527 rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);
1528 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
1529 if (rc) {
1530 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
1531 goto abort_free_ctlr;
1532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
rajesh.shah@intel.com7c8942f2005-10-13 12:05:43 -07001534 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
1535 pdev->bus->number, PCI_SLOT(pdev->devfn),
1536 PCI_FUNC(pdev->devfn), pdev->irq);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -07001537 get_hp_hw_control_from_firmware(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 /* Add this HPC instance into the HPC list */
1540 spin_lock(&list_lock);
1541 if (php_ctlr_list_head == 0) {
1542 php_ctlr_list_head = php_ctlr;
1543 p = php_ctlr_list_head;
1544 p->pnext = NULL;
1545 } else {
1546 p = php_ctlr_list_head;
1547
1548 while (p->pnext)
1549 p = p->pnext;
1550
1551 p->pnext = php_ctlr;
1552 }
1553 spin_unlock(&list_lock);
1554
1555
1556 ctlr_seq_num++;
1557 ctrl->hpc_ctlr_handle = php_ctlr;
1558 ctrl->hpc_ops = &shpchp_hpc_ops;
1559
1560 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
1561 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );
1562 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1563 hp_slot, slot_reg);
1564 tempdword = 0xe01f3fff;
1565 writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1566 }
1567 if (!shpchp_poll_mode) {
1568 /* Unmask all general input interrupts and SERR */
1569 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1570 tempdword = 0x0000000a;
1571 writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);
1572 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1573 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1574 }
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 DBG_LEAVE_ROUTINE
1577 return 0;
1578
1579 /* We end up here for the many possible ways to fail this API. */
1580abort_free_ctlr:
1581 kfree(php_ctlr);
1582abort:
1583 DBG_LEAVE_ROUTINE
1584 return -1;
1585}