blob: d46a4760338696e000133e2aa1cf27bec77e8bb8 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "shpchp.h"
35
36#ifdef DEBUG
37#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
38#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
39#define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */
40#define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */
41#define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT)
42#define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE)
43/* Redefine this flagword to set debug level */
44#define DEBUG_LEVEL DBG_K_STANDARD
45
46#define DEFINE_DBG_BUFFER char __dbg_str_buf[256];
47
48#define DBG_PRINT( dbg_flags, args... ) \
49 do { \
50 if ( DEBUG_LEVEL & ( dbg_flags ) ) \
51 { \
52 int len; \
53 len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \
54 __FILE__, __LINE__, __FUNCTION__ ); \
55 sprintf( __dbg_str_buf + len, args ); \
56 printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \
57 } \
58 } while (0)
59
60#define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]");
61#define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]");
62#else
63#define DEFINE_DBG_BUFFER
64#define DBG_ENTER_ROUTINE
65#define DBG_LEAVE_ROUTINE
66#endif /* DEBUG */
67
68/* Slot Available Register I field definition */
69#define SLOT_33MHZ 0x0000001f
70#define SLOT_66MHZ_PCIX 0x00001f00
71#define SLOT_100MHZ_PCIX 0x001f0000
72#define SLOT_133MHZ_PCIX 0x1f000000
73
74/* Slot Available Register II field definition */
75#define SLOT_66MHZ 0x0000001f
76#define SLOT_66MHZ_PCIX_266 0x00000f00
77#define SLOT_100MHZ_PCIX_266 0x0000f000
78#define SLOT_133MHZ_PCIX_266 0x000f0000
79#define SLOT_66MHZ_PCIX_533 0x00f00000
80#define SLOT_100MHZ_PCIX_533 0x0f000000
81#define SLOT_133MHZ_PCIX_533 0xf0000000
82
83
84/* Secondary Bus Configuration Register */
85/* For PI = 1, Bits 0 to 2 have been encoded as follows to show current bus speed/mode */
86#define PCI_33MHZ 0x0
87#define PCI_66MHZ 0x1
88#define PCIX_66MHZ 0x2
89#define PCIX_100MHZ 0x3
90#define PCIX_133MHZ 0x4
91
92/* For PI = 2, Bits 0 to 3 have been encoded as follows to show current bus speed/mode */
93#define PCI_33MHZ 0x0
94#define PCI_66MHZ 0x1
95#define PCIX_66MHZ 0x2
96#define PCIX_100MHZ 0x3
97#define PCIX_133MHZ 0x4
98#define PCIX_66MHZ_ECC 0x5
99#define PCIX_100MHZ_ECC 0x6
100#define PCIX_133MHZ_ECC 0x7
101#define PCIX_66MHZ_266 0x9
102#define PCIX_100MHZ_266 0xa
103#define PCIX_133MHZ_266 0xb
104#define PCIX_66MHZ_533 0x11
105#define PCIX_100MHZ_533 0x12
106#define PCIX_133MHZ_533 0x13
107
108/* Slot Configuration */
109#define SLOT_NUM 0x0000001F
110#define FIRST_DEV_NUM 0x00001F00
111#define PSN 0x07FF0000
112#define UPDOWN 0x20000000
113#define MRLSENSOR 0x40000000
114#define ATTN_BUTTON 0x80000000
115
116/* Slot Status Field Definitions */
117/* Slot State */
118#define PWR_ONLY 0x0001
119#define ENABLED 0x0002
120#define DISABLED 0x0003
121
122/* Power Indicator State */
123#define PWR_LED_ON 0x0004
124#define PWR_LED_BLINK 0x0008
125#define PWR_LED_OFF 0x000c
126
127/* Attention Indicator State */
128#define ATTEN_LED_ON 0x0010
129#define ATTEN_LED_BLINK 0x0020
130#define ATTEN_LED_OFF 0x0030
131
132/* Power Fault */
133#define pwr_fault 0x0040
134
135/* Attention Button */
136#define ATTEN_BUTTON 0x0080
137
138/* MRL Sensor */
139#define MRL_SENSOR 0x0100
140
141/* 66 MHz Capable */
142#define IS_66MHZ_CAP 0x0200
143
144/* PRSNT1#/PRSNT2# */
145#define SLOT_EMP 0x0c00
146
147/* PCI-X Capability */
148#define NON_PCIX 0x0000
149#define PCIX_66 0x1000
150#define PCIX_133 0x3000
151#define PCIX_266 0x4000 /* For PI = 2 only */
152#define PCIX_533 0x5000 /* For PI = 2 only */
153
154/* SHPC 'write' operations/commands */
155
156/* Slot operation - 0x00h to 0x3Fh */
157
158#define NO_CHANGE 0x00
159
160/* Slot state - Bits 0 & 1 of controller command register */
161#define SET_SLOT_PWR 0x01
162#define SET_SLOT_ENABLE 0x02
163#define SET_SLOT_DISABLE 0x03
164
165/* Power indicator state - Bits 2 & 3 of controller command register*/
166#define SET_PWR_ON 0x04
167#define SET_PWR_BLINK 0x08
168#define SET_PWR_OFF 0x0C
169
170/* Attention indicator state - Bits 4 & 5 of controller command register*/
171#define SET_ATTN_ON 0x010
172#define SET_ATTN_BLINK 0x020
173#define SET_ATTN_OFF 0x030
174
175/* Set bus speed/mode A - 0x40h to 0x47h */
176#define SETA_PCI_33MHZ 0x40
177#define SETA_PCI_66MHZ 0x41
178#define SETA_PCIX_66MHZ 0x42
179#define SETA_PCIX_100MHZ 0x43
180#define SETA_PCIX_133MHZ 0x44
181#define RESERV_1 0x45
182#define RESERV_2 0x46
183#define RESERV_3 0x47
184
185/* Set bus speed/mode B - 0x50h to 0x5fh */
186#define SETB_PCI_33MHZ 0x50
187#define SETB_PCI_66MHZ 0x51
188#define SETB_PCIX_66MHZ_PM 0x52
189#define SETB_PCIX_100MHZ_PM 0x53
190#define SETB_PCIX_133MHZ_PM 0x54
191#define SETB_PCIX_66MHZ_EM 0x55
192#define SETB_PCIX_100MHZ_EM 0x56
193#define SETB_PCIX_133MHZ_EM 0x57
194#define SETB_PCIX_66MHZ_266 0x58
195#define SETB_PCIX_100MHZ_266 0x59
196#define SETB_PCIX_133MHZ_266 0x5a
197#define SETB_PCIX_66MHZ_533 0x5b
198#define SETB_PCIX_100MHZ_533 0x5c
199#define SETB_PCIX_133MHZ_533 0x5d
200
201
202/* Power-on all slots - 0x48h */
203#define SET_PWR_ON_ALL 0x48
204
205/* Enable all slots - 0x49h */
206#define SET_ENABLE_ALL 0x49
207
208/* SHPC controller command error code */
209#define SWITCH_OPEN 0x1
210#define INVALID_CMD 0x2
211#define INVALID_SPEED_MODE 0x4
212
213/* For accessing SHPC Working Register Set */
214#define DWORD_SELECT 0x2
215#define DWORD_DATA 0x4
216#define BASE_OFFSET 0x0
217
218/* Field Offset in Logical Slot Register - byte boundary */
219#define SLOT_EVENT_LATCH 0x2
220#define SLOT_SERR_INT_MASK 0x3
221
222static spinlock_t hpc_event_lock;
223
224DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
225static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
226static int ctlr_seq_num = 0; /* Controller sequenc # */
227static spinlock_t list_lock;
228
229static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs);
230
231static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
232
233/* This is the interrupt polling timeout function. */
234static void int_poll_timeout(unsigned long lphp_ctlr)
235{
236 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr;
237
238 DBG_ENTER_ROUTINE
239
240 if ( !php_ctlr ) {
241 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
242 return;
243 }
244
245 /* Poll for interrupt events. regs == NULL => polling */
246 shpc_isr( 0, (void *)php_ctlr, NULL );
247
248 init_timer(&php_ctlr->int_poll_timer);
249 if (!shpchp_poll_time)
250 shpchp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/
251
252 start_int_poll_timer(php_ctlr, shpchp_poll_time);
253
254 return;
255}
256
257/* This function starts the interrupt polling timer. */
258static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
259{
260 if (!php_ctlr) {
261 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
262 return;
263 }
264
265 if ( ( seconds <= 0 ) || ( seconds > 60 ) )
266 seconds = 2; /* Clamp to sane value */
267
268 php_ctlr->int_poll_timer.function = &int_poll_timeout;
269 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */
270 php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ;
271 add_timer(&php_ctlr->int_poll_timer);
272
273 return;
274}
275
276static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
277{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700278 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 u16 cmd_status;
280 int retval = 0;
281 u16 temp_word;
282 int i;
283
284 DBG_ENTER_ROUTINE
285
286 if (!php_ctlr) {
287 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
288 return -1;
289 }
290
291 for (i = 0; i < 10; i++) {
292 cmd_status = readw(php_ctlr->creg + CMD_STATUS);
293
294 if (!(cmd_status & 0x1))
295 break;
296 /* Check every 0.1 sec for a total of 1 sec*/
297 msleep(100);
298 }
299
300 cmd_status = readw(php_ctlr->creg + CMD_STATUS);
301
302 if (cmd_status & 0x1) {
303 /* After 1 sec and and the controller is still busy */
304 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
305 return -1;
306 }
307
308 ++t_slot;
309 temp_word = (t_slot << 8) | (cmd & 0xFF);
310 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
311
312 /* To make sure the Controller Busy bit is 0 before we send out the
313 * command.
314 */
315 writew(temp_word, php_ctlr->creg + CMD);
316 dbg("%s: temp_word written %x\n", __FUNCTION__, temp_word);
317
318 DBG_LEAVE_ROUTINE
319 return retval;
320}
321
322static int hpc_check_cmd_status(struct controller *ctrl)
323{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700324 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 u16 cmd_status;
326 int retval = 0;
327
328 DBG_ENTER_ROUTINE
329
330 if (!ctrl->hpc_ctlr_handle) {
331 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
332 return -1;
333 }
334
335 cmd_status = readw(php_ctlr->creg + CMD_STATUS) & 0x000F;
336
337 switch (cmd_status >> 1) {
338 case 0:
339 retval = 0;
340 break;
341 case 1:
342 retval = SWITCH_OPEN;
343 err("%s: Switch opened!\n", __FUNCTION__);
344 break;
345 case 2:
346 retval = INVALID_CMD;
347 err("%s: Invalid HPC command!\n", __FUNCTION__);
348 break;
349 case 4:
350 retval = INVALID_SPEED_MODE;
351 err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
352 break;
353 default:
354 retval = cmd_status;
355 }
356
357 DBG_LEAVE_ROUTINE
358 return retval;
359}
360
361
362static int hpc_get_attention_status(struct slot *slot, u8 *status)
363{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700364 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 u32 slot_reg;
366 u16 slot_status;
367 u8 atten_led_state;
368
369 DBG_ENTER_ROUTINE
370
371 if (!slot->ctrl->hpc_ctlr_handle) {
372 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
373 return -1;
374 }
375
376 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
377 slot_status = (u16) slot_reg;
378 atten_led_state = (slot_status & 0x0030) >> 4;
379
380 switch (atten_led_state) {
381 case 0:
382 *status = 0xFF; /* Reserved */
383 break;
384 case 1:
385 *status = 1; /* On */
386 break;
387 case 2:
388 *status = 2; /* Blink */
389 break;
390 case 3:
391 *status = 0; /* Off */
392 break;
393 default:
394 *status = 0xFF;
395 break;
396 }
397
398 DBG_LEAVE_ROUTINE
399 return 0;
400}
401
402static int hpc_get_power_status(struct slot * slot, u8 *status)
403{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700404 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 u32 slot_reg;
406 u16 slot_status;
407 u8 slot_state;
408 int retval = 0;
409
410 DBG_ENTER_ROUTINE
411
412 if (!slot->ctrl->hpc_ctlr_handle) {
413 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
414 return -1;
415 }
416
417 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
418 slot_status = (u16) slot_reg;
419 slot_state = (slot_status & 0x0003);
420
421 switch (slot_state) {
422 case 0:
423 *status = 0xFF;
424 break;
425 case 1:
426 *status = 2; /* Powered only */
427 break;
428 case 2:
429 *status = 1; /* Enabled */
430 break;
431 case 3:
432 *status = 0; /* Disabled */
433 break;
434 default:
435 *status = 0xFF;
436 break;
437 }
438
439 DBG_LEAVE_ROUTINE
440 return retval;
441}
442
443
444static int hpc_get_latch_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
450 DBG_ENTER_ROUTINE
451
452 if (!slot->ctrl->hpc_ctlr_handle) {
453 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
454 return -1;
455 }
456
457 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
458 slot_status = (u16)slot_reg;
459
460 *status = ((slot_status & 0x0100) == 0) ? 0 : 1; /* 0 -> close; 1 -> open */
461
462
463 DBG_LEAVE_ROUTINE
464 return 0;
465}
466
467static int hpc_get_adapter_status(struct slot *slot, u8 *status)
468{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700469 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 u32 slot_reg;
471 u16 slot_status;
472 u8 card_state;
473
474 DBG_ENTER_ROUTINE
475
476 if (!slot->ctrl->hpc_ctlr_handle) {
477 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
478 return -1;
479 }
480
481 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
482 slot_status = (u16)slot_reg;
483 card_state = (u8)((slot_status & 0x0C00) >> 10);
484 *status = (card_state != 0x3) ? 1 : 0;
485
486 DBG_LEAVE_ROUTINE
487 return 0;
488}
489
490static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
491{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700492 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 DBG_ENTER_ROUTINE
495
496 if (!slot->ctrl->hpc_ctlr_handle) {
497 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
498 return -1;
499 }
500
501 *prog_int = readb(php_ctlr->creg + PROG_INTERFACE);
502
503 DBG_LEAVE_ROUTINE
504 return 0;
505}
506
507static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
508{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700509 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 u32 slot_reg;
511 u16 slot_status, sec_bus_status;
512 u8 m66_cap, pcix_cap, pi;
513 int retval = 0;
514
515 DBG_ENTER_ROUTINE
516
517 if (!slot->ctrl->hpc_ctlr_handle) {
518 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
519 return -1;
520 }
521
522 if (slot->hp_slot >= php_ctlr->num_slots) {
523 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
524 return -1;
525 }
526
527 pi = readb(php_ctlr->creg + PROG_INTERFACE);
528 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
529 dbg("%s: pi = %d, slot_reg = %x\n", __FUNCTION__, pi, slot_reg);
530 slot_status = (u16) slot_reg;
531 dbg("%s: slot_status = %x\n", __FUNCTION__, slot_status);
532 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
533
534 pcix_cap = (u8) ((slot_status & 0x3000) >> 12);
535 dbg("%s: pcix_cap = %x\n", __FUNCTION__, pcix_cap);
536 m66_cap = (u8) ((slot_status & 0x0200) >> 9);
537 dbg("%s: m66_cap = %x\n", __FUNCTION__, m66_cap);
538
539
540 if (pi == 2) {
541 switch (pcix_cap) {
542 case 0:
543 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
544 break;
545 case 1:
546 *value = PCI_SPEED_66MHz_PCIX;
547 break;
548 case 3:
549 *value = PCI_SPEED_133MHz_PCIX;
550 break;
551 case 4:
552 *value = PCI_SPEED_133MHz_PCIX_266;
553 break;
554 case 5:
555 *value = PCI_SPEED_133MHz_PCIX_533;
556 break;
557 case 2: /* Reserved */
558 default:
559 *value = PCI_SPEED_UNKNOWN;
560 retval = -ENODEV;
561 break;
562 }
563 } else {
564 switch (pcix_cap) {
565 case 0:
566 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
567 break;
568 case 1:
569 *value = PCI_SPEED_66MHz_PCIX;
570 break;
571 case 3:
572 *value = PCI_SPEED_133MHz_PCIX;
573 break;
574 case 2: /* Reserved */
575 default:
576 *value = PCI_SPEED_UNKNOWN;
577 retval = -ENODEV;
578 break;
579 }
580 }
581
582 dbg("Adapter speed = %d\n", *value);
583
584 DBG_LEAVE_ROUTINE
585 return retval;
586}
587
588static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
589{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700590 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 u16 sec_bus_status;
592 u8 pi;
593 int retval = 0;
594
595 DBG_ENTER_ROUTINE
596
597 if (!slot->ctrl->hpc_ctlr_handle) {
598 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
599 return -1;
600 }
601
602 pi = readb(php_ctlr->creg + PROG_INTERFACE);
603 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
604
605 if (pi == 2) {
606 *mode = (sec_bus_status & 0x0100) >> 7;
607 } else {
608 retval = -1;
609 }
610
611 dbg("Mode 1 ECC cap = %d\n", *mode);
612
613 DBG_LEAVE_ROUTINE
614 return retval;
615}
616
617static int hpc_query_power_fault(struct slot * slot)
618{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700619 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 u32 slot_reg;
621 u16 slot_status;
622 u8 pwr_fault_state, status;
623
624 DBG_ENTER_ROUTINE
625
626 if (!slot->ctrl->hpc_ctlr_handle) {
627 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
628 return -1;
629 }
630
631 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
632 slot_status = (u16) slot_reg;
633 pwr_fault_state = (slot_status & 0x0040) >> 7;
634 status = (pwr_fault_state == 1) ? 0 : 1;
635
636 DBG_LEAVE_ROUTINE
637 /* Note: Logic 0 => fault */
638 return status;
639}
640
641static int hpc_set_attention_status(struct slot *slot, u8 value)
642{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700643 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 u8 slot_cmd = 0;
645 int rc = 0;
646
647 if (!slot->ctrl->hpc_ctlr_handle) {
648 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
649 return -1;
650 }
651
652 if (slot->hp_slot >= php_ctlr->num_slots) {
653 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
654 return -1;
655 }
656
657 switch (value) {
658 case 0 :
659 slot_cmd = 0x30; /* OFF */
660 break;
661 case 1:
662 slot_cmd = 0x10; /* ON */
663 break;
664 case 2:
665 slot_cmd = 0x20; /* BLINK */
666 break;
667 default:
668 return -1;
669 }
670
671 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
672
673 return rc;
674}
675
676
677static void hpc_set_green_led_on(struct slot *slot)
678{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700679 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 u8 slot_cmd;
681
682 if (!slot->ctrl->hpc_ctlr_handle) {
683 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
684 return ;
685 }
686
687 if (slot->hp_slot >= php_ctlr->num_slots) {
688 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
689 return ;
690 }
691
692 slot_cmd = 0x04;
693
694 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
695
696 return;
697}
698
699static void hpc_set_green_led_off(struct slot *slot)
700{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700701 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 u8 slot_cmd;
703
704 if (!slot->ctrl->hpc_ctlr_handle) {
705 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
706 return ;
707 }
708
709 if (slot->hp_slot >= php_ctlr->num_slots) {
710 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
711 return ;
712 }
713
714 slot_cmd = 0x0C;
715
716 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
717
718 return;
719}
720
721static void hpc_set_green_led_blink(struct slot *slot)
722{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700723 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 u8 slot_cmd;
725
726 if (!slot->ctrl->hpc_ctlr_handle) {
727 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
728 return ;
729 }
730
731 if (slot->hp_slot >= php_ctlr->num_slots) {
732 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
733 return ;
734 }
735
736 slot_cmd = 0x08;
737
738 shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
739
740 return;
741}
742
743int shpc_get_ctlr_slot_config(struct controller *ctrl,
744 int *num_ctlr_slots, /* number of slots in this HPC */
745 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
746 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
747 int *updown, /* physical_slot_num increament: 1 or -1 */
748 int *flags)
749{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700750 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 DBG_ENTER_ROUTINE
753
754 if (!ctrl->hpc_ctlr_handle) {
755 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
756 return -1;
757 }
758
759 *first_device_num = php_ctlr->slot_device_offset; /* Obtained in shpc_init() */
760 *num_ctlr_slots = php_ctlr->num_slots; /* Obtained in shpc_init() */
761
762 *physical_slot_num = (readl(php_ctlr->creg + SLOT_CONFIG) & PSN) >> 16;
763 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
764 *updown = ((readl(php_ctlr->creg + SLOT_CONFIG) & UPDOWN ) >> 29) ? 1 : -1;
765
766 DBG_LEAVE_ROUTINE
767 return 0;
768}
769
770static void hpc_release_ctlr(struct controller *ctrl)
771{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700772 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 struct php_ctlr_state_s *p, *p_prev;
774
775 DBG_ENTER_ROUTINE
776
777 if (!ctrl->hpc_ctlr_handle) {
778 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
779 return ;
780 }
781
782 if (shpchp_poll_mode) {
783 del_timer(&php_ctlr->int_poll_timer);
784 } else {
785 if (php_ctlr->irq) {
786 free_irq(php_ctlr->irq, ctrl);
787 php_ctlr->irq = 0;
788 pci_disable_msi(php_ctlr->pci_dev);
789 }
790 }
791 if (php_ctlr->pci_dev) {
792 dbg("%s: before calling iounmap & release_mem_region\n", __FUNCTION__);
793 iounmap(php_ctlr->creg);
794 release_mem_region(pci_resource_start(php_ctlr->pci_dev, 0), pci_resource_len(php_ctlr->pci_dev, 0));
795 dbg("%s: before calling iounmap & release_mem_region\n", __FUNCTION__);
796 php_ctlr->pci_dev = NULL;
797 }
798
799 spin_lock(&list_lock);
800 p = php_ctlr_list_head;
801 p_prev = NULL;
802 while (p) {
803 if (p == php_ctlr) {
804 if (p_prev)
805 p_prev->pnext = p->pnext;
806 else
807 php_ctlr_list_head = p->pnext;
808 break;
809 } else {
810 p_prev = p;
811 p = p->pnext;
812 }
813 }
814 spin_unlock(&list_lock);
815
816 kfree(php_ctlr);
817
818DBG_LEAVE_ROUTINE
819
820}
821
822static int hpc_power_on_slot(struct slot * slot)
823{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700824 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 u8 slot_cmd;
826 int retval = 0;
827
828 DBG_ENTER_ROUTINE
829
830 if (!slot->ctrl->hpc_ctlr_handle) {
831 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
832 return -1;
833 }
834
835 if (slot->hp_slot >= php_ctlr->num_slots) {
836 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
837 return -1;
838 }
839 slot_cmd = 0x01;
840
841 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
842
843 if (retval) {
844 err("%s: Write command failed!\n", __FUNCTION__);
845 return -1;
846 }
847
848 DBG_LEAVE_ROUTINE
849
850 return retval;
851}
852
853static int hpc_slot_enable(struct slot * slot)
854{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700855 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 u8 slot_cmd;
857 int retval = 0;
858
859 DBG_ENTER_ROUTINE
860
861 if (!slot->ctrl->hpc_ctlr_handle) {
862 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
863 return -1;
864 }
865
866 if (slot->hp_slot >= php_ctlr->num_slots) {
867 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
868 return -1;
869 }
870 /* 3A => Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
871 slot_cmd = 0x3A;
872
873 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
874
875 if (retval) {
876 err("%s: Write command failed!\n", __FUNCTION__);
877 return -1;
878 }
879
880 DBG_LEAVE_ROUTINE
881 return retval;
882}
883
884static int hpc_slot_disable(struct slot * slot)
885{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700886 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 u8 slot_cmd;
888 int retval = 0;
889
890 DBG_ENTER_ROUTINE
891
892 if (!slot->ctrl->hpc_ctlr_handle) {
893 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
894 return -1;
895 }
896
897 if (slot->hp_slot >= php_ctlr->num_slots) {
898 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
899 return -1;
900 }
901
902 /* 1F => Slot - Disable, Power Indicator - Off, Attention Indicator - On */
903 slot_cmd = 0x1F;
904
905 retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
906
907 if (retval) {
908 err("%s: Write command failed!\n", __FUNCTION__);
909 return -1;
910 }
911
912 DBG_LEAVE_ROUTINE
913 return retval;
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
917{
918 u8 slot_cmd;
919 u8 pi;
920 int retval = 0;
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700921 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 DBG_ENTER_ROUTINE
924
925 if (!slot->ctrl->hpc_ctlr_handle) {
926 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
927 return -1;
928 }
929
930 pi = readb(php_ctlr->creg + PROG_INTERFACE);
931
932 if (pi == 1) {
933 switch (value) {
934 case 0:
935 slot_cmd = SETA_PCI_33MHZ;
936 break;
937 case 1:
938 slot_cmd = SETA_PCI_66MHZ;
939 break;
940 case 2:
941 slot_cmd = SETA_PCIX_66MHZ;
942 break;
943 case 3:
944 slot_cmd = SETA_PCIX_100MHZ;
945 break;
946 case 4:
947 slot_cmd = SETA_PCIX_133MHZ;
948 break;
949 default:
950 slot_cmd = PCI_SPEED_UNKNOWN;
951 retval = -ENODEV;
952 return retval;
953 }
954 } else {
955 switch (value) {
956 case 0:
957 slot_cmd = SETB_PCI_33MHZ;
958 break;
959 case 1:
960 slot_cmd = SETB_PCI_66MHZ;
961 break;
962 case 2:
963 slot_cmd = SETB_PCIX_66MHZ_PM;
964 break;
965 case 3:
966 slot_cmd = SETB_PCIX_100MHZ_PM;
967 break;
968 case 4:
969 slot_cmd = SETB_PCIX_133MHZ_PM;
970 break;
971 case 5:
972 slot_cmd = SETB_PCIX_66MHZ_EM;
973 break;
974 case 6:
975 slot_cmd = SETB_PCIX_100MHZ_EM;
976 break;
977 case 7:
978 slot_cmd = SETB_PCIX_133MHZ_EM;
979 break;
980 case 8:
981 slot_cmd = SETB_PCIX_66MHZ_266;
982 break;
983 case 0x9:
984 slot_cmd = SETB_PCIX_100MHZ_266;
985 break;
986 case 0xa:
987 slot_cmd = SETB_PCIX_133MHZ_266;
988 break;
989 case 0xb:
990 slot_cmd = SETB_PCIX_66MHZ_533;
991 break;
992 case 0xc:
993 slot_cmd = SETB_PCIX_100MHZ_533;
994 break;
995 case 0xd:
996 slot_cmd = SETB_PCIX_133MHZ_533;
997 break;
998 default:
999 slot_cmd = PCI_SPEED_UNKNOWN;
1000 retval = -ENODEV;
1001 return retval;
1002 }
1003
1004 }
1005 retval = shpc_write_cmd(slot, 0, slot_cmd);
1006 if (retval) {
1007 err("%s: Write command failed!\n", __FUNCTION__);
1008 return -1;
1009 }
1010
1011 DBG_LEAVE_ROUTINE
1012 return retval;
1013}
1014
1015static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1016{
1017 struct controller *ctrl = NULL;
1018 struct php_ctlr_state_s *php_ctlr;
1019 u8 schedule_flag = 0;
1020 u8 temp_byte;
1021 u32 temp_dword, intr_loc, intr_loc2;
1022 int hp_slot;
1023
1024 if (!dev_id)
1025 return IRQ_NONE;
1026
1027 if (!shpchp_poll_mode) {
1028 ctrl = (struct controller *)dev_id;
1029 php_ctlr = ctrl->hpc_ctlr_handle;
1030 } else {
1031 php_ctlr = (struct php_ctlr_state_s *) dev_id;
1032 ctrl = (struct controller *)php_ctlr->callback_instance_id;
1033 }
1034
1035 if (!ctrl)
1036 return IRQ_NONE;
1037
1038 if (!php_ctlr || !php_ctlr->creg)
1039 return IRQ_NONE;
1040
1041 /* Check to see if it was our interrupt */
1042 intr_loc = readl(php_ctlr->creg + INTR_LOC);
1043
1044 if (!intr_loc)
1045 return IRQ_NONE;
1046 dbg("%s: shpc_isr proceeds\n", __FUNCTION__);
1047 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
1048
1049 if(!shpchp_poll_mode) {
1050 /* Mask Global Interrupt Mask - see implementation note on p. 139 */
1051 /* of SHPC spec rev 1.0*/
1052 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1053 dbg("%s: Before masking global interrupt, temp_dword = %x\n",
1054 __FUNCTION__, temp_dword);
1055 temp_dword |= 0x00000001;
1056 dbg("%s: After masking global interrupt, temp_dword = %x\n",
1057 __FUNCTION__, temp_dword);
1058 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1059
1060 intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
1061 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1062 }
1063
1064 if (intr_loc & 0x0001) {
1065 /*
1066 * Command Complete Interrupt Pending
1067 * RO only - clear by writing 0 to the Command Completion
1068 * Detect bit in Controller SERR-INT register
1069 */
1070 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1071 dbg("%s: Before clearing CCIP, temp_dword = %x\n",
1072 __FUNCTION__, temp_dword);
1073 temp_dword &= 0xfffeffff;
1074 dbg("%s: After clearing CCIP, temp_dword = %x\n",
1075 __FUNCTION__, temp_dword);
1076 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1077 wake_up_interruptible(&ctrl->queue);
1078 }
1079
1080 if ((intr_loc = (intr_loc >> 1)) == 0) {
1081 /* Unmask Global Interrupt Mask */
1082 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1083 dbg("%s: 1-Before unmasking global interrupt, temp_dword = %x\n",
1084 __FUNCTION__, temp_dword);
1085 temp_dword &= 0xfffffffe;
1086 dbg("%s: 1-After unmasking global interrupt, temp_dword = %x\n",
1087 __FUNCTION__, temp_dword);
1088 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1089
1090 return IRQ_NONE;
1091 }
1092
1093 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1094 /* To find out which slot has interrupt pending */
1095 if ((intr_loc >> hp_slot) & 0x01) {
1096 temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot));
1097 dbg("%s: Slot %x with intr, temp_dword = %x\n",
1098 __FUNCTION__, hp_slot, temp_dword);
1099 temp_byte = (temp_dword >> 16) & 0xFF;
1100 dbg("%s: Slot with intr, temp_byte = %x\n",
1101 __FUNCTION__, temp_byte);
1102 if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08))
1103 schedule_flag += php_ctlr->switch_change_callback(
1104 hp_slot, php_ctlr->callback_instance_id);
1105 if ((php_ctlr->attention_button_callback) && (temp_byte & 0x04))
1106 schedule_flag += php_ctlr->attention_button_callback(
1107 hp_slot, php_ctlr->callback_instance_id);
1108 if ((php_ctlr->presence_change_callback) && (temp_byte & 0x01))
1109 schedule_flag += php_ctlr->presence_change_callback(
1110 hp_slot , php_ctlr->callback_instance_id);
1111 if ((php_ctlr->power_fault_callback) && (temp_byte & 0x12))
1112 schedule_flag += php_ctlr->power_fault_callback(
1113 hp_slot, php_ctlr->callback_instance_id);
1114
1115 /* Clear all slot events */
1116 temp_dword = 0xe01f3fff;
1117 dbg("%s: Clearing slot events, temp_dword = %x\n",
1118 __FUNCTION__, temp_dword);
1119 writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1120
1121 intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
1122 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1123 }
1124 }
1125 if (!shpchp_poll_mode) {
1126 /* Unmask Global Interrupt Mask */
1127 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1128 dbg("%s: 2-Before unmasking global interrupt, temp_dword = %x\n",
1129 __FUNCTION__, temp_dword);
1130 temp_dword &= 0xfffffffe;
1131 dbg("%s: 2-After unmasking global interrupt, temp_dword = %x\n",
1132 __FUNCTION__, temp_dword);
1133 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1134 }
1135
1136 return IRQ_HANDLED;
1137}
1138
1139static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1140{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001141 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1143 int retval = 0;
1144 u8 pi;
1145 u32 slot_avail1, slot_avail2;
1146 int slot_num;
1147
1148 DBG_ENTER_ROUTINE
1149
1150 if (!slot->ctrl->hpc_ctlr_handle) {
1151 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
1152 return -1;
1153 }
1154
1155 if (slot->hp_slot >= php_ctlr->num_slots) {
1156 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
1157 return -1;
1158 }
1159
1160 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1161 slot_avail1 = readl(php_ctlr->creg + SLOT_AVAIL1);
1162 slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);
1163
1164 if (pi == 2) {
1165 if ((slot_num = ((slot_avail2 & SLOT_133MHZ_PCIX_533) >> 27) ) != 0 )
1166 bus_speed = PCIX_133MHZ_533;
1167 else if ((slot_num = ((slot_avail2 & SLOT_100MHZ_PCIX_533) >> 23) ) != 0 )
1168 bus_speed = PCIX_100MHZ_533;
1169 else if ((slot_num = ((slot_avail2 & SLOT_66MHZ_PCIX_533) >> 19) ) != 0 )
1170 bus_speed = PCIX_66MHZ_533;
1171 else if ((slot_num = ((slot_avail2 & SLOT_133MHZ_PCIX_266) >> 15) ) != 0 )
1172 bus_speed = PCIX_133MHZ_266;
1173 else if ((slot_num = ((slot_avail2 & SLOT_100MHZ_PCIX_266) >> 11) ) != 0 )
1174 bus_speed = PCIX_100MHZ_266;
1175 else if ((slot_num = ((slot_avail2 & SLOT_66MHZ_PCIX_266) >> 7) ) != 0 )
1176 bus_speed = PCIX_66MHZ_266;
1177 else if ((slot_num = ((slot_avail1 & SLOT_133MHZ_PCIX) >> 23) ) != 0 )
1178 bus_speed = PCIX_133MHZ;
1179 else if ((slot_num = ((slot_avail1 & SLOT_100MHZ_PCIX) >> 15) ) != 0 )
1180 bus_speed = PCIX_100MHZ;
1181 else if ((slot_num = ((slot_avail1 & SLOT_66MHZ_PCIX) >> 7) ) != 0 )
1182 bus_speed = PCIX_66MHZ;
1183 else if ((slot_num = (slot_avail2 & SLOT_66MHZ)) != 0 )
1184 bus_speed = PCI_66MHZ;
1185 else if ((slot_num = (slot_avail1 & SLOT_33MHZ)) != 0 )
1186 bus_speed = PCI_33MHZ;
1187 else bus_speed = PCI_SPEED_UNKNOWN;
1188 } else {
1189 if ((slot_num = ((slot_avail1 & SLOT_133MHZ_PCIX) >> 23) ) != 0 )
1190 bus_speed = PCIX_133MHZ;
1191 else if ((slot_num = ((slot_avail1 & SLOT_100MHZ_PCIX) >> 15) ) != 0 )
1192 bus_speed = PCIX_100MHZ;
1193 else if ((slot_num = ((slot_avail1 & SLOT_66MHZ_PCIX) >> 7) ) != 0 )
1194 bus_speed = PCIX_66MHZ;
1195 else if ((slot_num = (slot_avail2 & SLOT_66MHZ)) != 0 )
1196 bus_speed = PCI_66MHZ;
1197 else if ((slot_num = (slot_avail1 & SLOT_33MHZ)) != 0 )
1198 bus_speed = PCI_33MHZ;
1199 else bus_speed = PCI_SPEED_UNKNOWN;
1200 }
1201
1202 *value = bus_speed;
1203 dbg("Max bus speed = %d\n", bus_speed);
1204 DBG_LEAVE_ROUTINE
1205 return retval;
1206}
1207
1208static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1209{
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001210 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1212 u16 sec_bus_status;
1213 int retval = 0;
1214 u8 pi;
1215
1216 DBG_ENTER_ROUTINE
1217
1218 if (!slot->ctrl->hpc_ctlr_handle) {
1219 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
1220 return -1;
1221 }
1222
1223 if (slot->hp_slot >= php_ctlr->num_slots) {
1224 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
1225 return -1;
1226 }
1227
1228 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1229 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
1230
1231 if (pi == 2) {
1232 switch (sec_bus_status & 0x000f) {
1233 case 0:
1234 bus_speed = PCI_SPEED_33MHz;
1235 break;
1236 case 1:
1237 bus_speed = PCI_SPEED_66MHz;
1238 break;
1239 case 2:
1240 bus_speed = PCI_SPEED_66MHz_PCIX;
1241 break;
1242 case 3:
1243 bus_speed = PCI_SPEED_100MHz_PCIX;
1244 break;
1245 case 4:
1246 bus_speed = PCI_SPEED_133MHz_PCIX;
1247 break;
1248 case 5:
1249 bus_speed = PCI_SPEED_66MHz_PCIX_ECC;
1250 break;
1251 case 6:
1252 bus_speed = PCI_SPEED_100MHz_PCIX_ECC;
1253 break;
1254 case 7:
1255 bus_speed = PCI_SPEED_133MHz_PCIX_ECC;
1256 break;
1257 case 8:
1258 bus_speed = PCI_SPEED_66MHz_PCIX_266;
1259 break;
1260 case 9:
1261 bus_speed = PCI_SPEED_100MHz_PCIX_266;
1262 break;
1263 case 0xa:
1264 bus_speed = PCI_SPEED_133MHz_PCIX_266;
1265 break;
1266 case 0xb:
1267 bus_speed = PCI_SPEED_66MHz_PCIX_533;
1268 break;
1269 case 0xc:
1270 bus_speed = PCI_SPEED_100MHz_PCIX_533;
1271 break;
1272 case 0xd:
1273 bus_speed = PCI_SPEED_133MHz_PCIX_533;
1274 break;
1275 case 0xe:
1276 case 0xf:
1277 default:
1278 bus_speed = PCI_SPEED_UNKNOWN;
1279 break;
1280 }
1281 } else {
1282 /* In the case where pi is undefined, default it to 1 */
1283 switch (sec_bus_status & 0x0007) {
1284 case 0:
1285 bus_speed = PCI_SPEED_33MHz;
1286 break;
1287 case 1:
1288 bus_speed = PCI_SPEED_66MHz;
1289 break;
1290 case 2:
1291 bus_speed = PCI_SPEED_66MHz_PCIX;
1292 break;
1293 case 3:
1294 bus_speed = PCI_SPEED_100MHz_PCIX;
1295 break;
1296 case 4:
1297 bus_speed = PCI_SPEED_133MHz_PCIX;
1298 break;
1299 case 5:
1300 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1301 break;
1302 case 6:
1303 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1304 break;
1305 case 7:
1306 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1307 break;
1308 default:
1309 bus_speed = PCI_SPEED_UNKNOWN;
1310 break;
1311 }
1312 }
1313
1314 *value = bus_speed;
1315 dbg("Current bus speed = %d\n", bus_speed);
1316 DBG_LEAVE_ROUTINE
1317 return retval;
1318}
1319
1320static struct hpc_ops shpchp_hpc_ops = {
1321 .power_on_slot = hpc_power_on_slot,
1322 .slot_enable = hpc_slot_enable,
1323 .slot_disable = hpc_slot_disable,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1325 .set_attention_status = hpc_set_attention_status,
1326 .get_power_status = hpc_get_power_status,
1327 .get_attention_status = hpc_get_attention_status,
1328 .get_latch_status = hpc_get_latch_status,
1329 .get_adapter_status = hpc_get_adapter_status,
1330
1331 .get_max_bus_speed = hpc_get_max_bus_speed,
1332 .get_cur_bus_speed = hpc_get_cur_bus_speed,
1333 .get_adapter_speed = hpc_get_adapter_speed,
1334 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
1335 .get_prog_int = hpc_get_prog_int,
1336
1337 .query_power_fault = hpc_query_power_fault,
1338 .green_led_on = hpc_set_green_led_on,
1339 .green_led_off = hpc_set_green_led_off,
1340 .green_led_blink = hpc_set_green_led_blink,
1341
1342 .release_ctlr = hpc_release_ctlr,
1343 .check_cmd_status = hpc_check_cmd_status,
1344};
1345
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001346int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
1348 struct php_ctlr_state_s *php_ctlr, *p;
1349 void *instance_id = ctrl;
1350 int rc;
1351 u8 hp_slot;
1352 static int first = 1;
1353 u32 shpc_cap_offset, shpc_base_offset;
1354 u32 tempdword, slot_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 u8 i;
1356
1357 DBG_ENTER_ROUTINE
1358
1359 spin_lock_init(&list_lock);
1360 php_ctlr = (struct php_ctlr_state_s *) kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL);
1361
1362 if (!php_ctlr) { /* allocate controller state data */
1363 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1364 goto abort;
1365 }
1366
1367 memset(php_ctlr, 0, sizeof(struct php_ctlr_state_s));
1368
1369 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1370
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001371 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1372 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 shpc_base_offset = 0; /* amd shpc driver doesn't use this; assume 0 */
1374 } else {
1375 if ((shpc_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC)) == 0) {
1376 err("%s : shpc_cap_offset == 0\n", __FUNCTION__);
1377 goto abort_free_ctlr;
1378 }
1379 dbg("%s: shpc_cap_offset = %x\n", __FUNCTION__, shpc_cap_offset);
1380
1381 rc = pci_write_config_byte(pdev, (u8)shpc_cap_offset + DWORD_SELECT , BASE_OFFSET);
1382 if (rc) {
1383 err("%s : pci_word_config_byte failed\n", __FUNCTION__);
1384 goto abort_free_ctlr;
1385 }
1386
1387 rc = pci_read_config_dword(pdev, (u8)shpc_cap_offset + DWORD_DATA, &shpc_base_offset);
1388 if (rc) {
1389 err("%s : pci_read_config_dword failed\n", __FUNCTION__);
1390 goto abort_free_ctlr;
1391 }
1392
1393 for (i = 0; i <= 14; i++) {
1394 rc = pci_write_config_byte(pdev, (u8)shpc_cap_offset + DWORD_SELECT , i);
1395 if (rc) {
1396 err("%s : pci_word_config_byte failed\n", __FUNCTION__);
1397 goto abort_free_ctlr;
1398 }
1399
1400 rc = pci_read_config_dword(pdev, (u8)shpc_cap_offset + DWORD_DATA, &tempdword);
1401 if (rc) {
1402 err("%s : pci_read_config_dword failed\n", __FUNCTION__);
1403 goto abort_free_ctlr;
1404 }
1405 dbg("%s: offset %d: tempdword %x\n", __FUNCTION__,i, tempdword);
1406 }
1407 }
1408
1409 if (first) {
1410 spin_lock_init(&hpc_event_lock);
1411 first = 0;
1412 }
1413
1414 dbg("pdev = %p: b:d:f:irq=0x%x:%x:%x:%x\n", pdev, pdev->bus->number, PCI_SLOT(pdev->devfn),
1415 PCI_FUNC(pdev->devfn), pdev->irq);
1416 for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)
1417 if (pci_resource_len(pdev, rc) > 0)
1418 dbg("pci resource[%d] start=0x%lx(len=0x%lx), shpc_base_offset %x\n", rc,
1419 pci_resource_start(pdev, rc), pci_resource_len(pdev, rc), shpc_base_offset);
1420
1421 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1422 pdev->subsystem_device);
1423
1424 if (pci_enable_device(pdev))
1425 goto abort_free_ctlr;
1426
1427 if (!request_mem_region(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0), MY_NAME)) {
1428 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1429 goto abort_free_ctlr;
1430 }
1431
1432 php_ctlr->creg = ioremap(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0));
1433 if (!php_ctlr->creg) {
1434 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, pci_resource_len(pdev, 0),
1435 pci_resource_start(pdev, 0) + shpc_base_offset);
1436 release_mem_region(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0));
1437 goto abort_free_ctlr;
1438 }
1439 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
1440 dbg("%s: physical addr %p\n", __FUNCTION__, (void*)pci_resource_start(pdev, 0));
1441
1442 init_MUTEX(&ctrl->crit_sect);
1443 /* Setup wait queue */
1444 init_waitqueue_head(&ctrl->queue);
1445
1446 /* Find the IRQ */
1447 php_ctlr->irq = pdev->irq;
1448 dbg("HPC interrupt = %d\n", php_ctlr->irq);
1449
rajesh.shah@intel.comee138332005-10-13 12:05:42 -07001450 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1451 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1452 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1453 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 php_ctlr->callback_instance_id = instance_id;
1455
1456 /* Return PCI Controller Info */
1457 php_ctlr->slot_device_offset = (readl(php_ctlr->creg + SLOT_CONFIG) & FIRST_DEV_NUM ) >> 8;
1458 php_ctlr->num_slots = readl(php_ctlr->creg + SLOT_CONFIG) & SLOT_NUM;
1459 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
1460 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
1461
1462 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
1463 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1464 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1465 tempdword = 0x0003000f;
1466 writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);
1467 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1468 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1469
1470 /* Mask the MRL sensor SERR Mask of individual slot in
1471 * Slot SERR-INT Mask & clear all the existing event if any
1472 */
1473 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
1474 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );
1475 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1476 hp_slot, slot_reg);
1477 tempdword = 0xffff3fff;
1478 writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1479 }
1480
1481 if (shpchp_poll_mode) {/* Install interrupt polling code */
1482 /* Install and start the interrupt polling timer */
1483 init_timer(&php_ctlr->int_poll_timer);
1484 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
1485 } else {
1486 /* Installs the interrupt handler */
1487 rc = pci_enable_msi(pdev);
1488 if (rc) {
1489 info("Can't get msi for the hotplug controller\n");
1490 info("Use INTx for the hotplug controller\n");
1491 dbg("%s: rc = %x\n", __FUNCTION__, rc);
1492 } else
1493 php_ctlr->irq = pdev->irq;
1494
1495 rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);
1496 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
1497 if (rc) {
1498 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
1499 goto abort_free_ctlr;
1500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 }
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -07001502 get_hp_hw_control_from_firmware(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 dbg("%s: Before adding HPC to HPC list\n", __FUNCTION__);
1504
1505 /* Add this HPC instance into the HPC list */
1506 spin_lock(&list_lock);
1507 if (php_ctlr_list_head == 0) {
1508 php_ctlr_list_head = php_ctlr;
1509 p = php_ctlr_list_head;
1510 p->pnext = NULL;
1511 } else {
1512 p = php_ctlr_list_head;
1513
1514 while (p->pnext)
1515 p = p->pnext;
1516
1517 p->pnext = php_ctlr;
1518 }
1519 spin_unlock(&list_lock);
1520
1521
1522 ctlr_seq_num++;
1523 ctrl->hpc_ctlr_handle = php_ctlr;
1524 ctrl->hpc_ops = &shpchp_hpc_ops;
1525
1526 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
1527 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );
1528 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1529 hp_slot, slot_reg);
1530 tempdword = 0xe01f3fff;
1531 writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1532 }
1533 if (!shpchp_poll_mode) {
1534 /* Unmask all general input interrupts and SERR */
1535 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1536 tempdword = 0x0000000a;
1537 writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);
1538 tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1539 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1540 }
1541
1542 dbg("%s: Leaving shpc_init\n", __FUNCTION__);
1543 DBG_LEAVE_ROUTINE
1544 return 0;
1545
1546 /* We end up here for the many possible ways to fail this API. */
1547abort_free_ctlr:
1548 kfree(php_ctlr);
1549abort:
1550 DBG_LEAVE_ROUTINE
1551 return -1;
1552}