blob: f036485cd9eca7a672e5768eb76513718fe96b12 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Standard Hot Plug Controller 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
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#ifndef _SHPCHP_H
30#define _SHPCHP_H
31
32#include <linux/types.h>
33#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070034#include <linux/pci_hotplug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/delay.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080036#include <linux/sched.h> /* signal_pending(), struct timer_list */
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +010037#include <linux/mutex.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#if !defined(MODULE)
40 #define MY_NAME "shpchp"
41#else
42 #define MY_NAME THIS_MODULE->name
43#endif
44
45extern int shpchp_poll_mode;
46extern int shpchp_poll_time;
47extern int shpchp_debug;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -080048extern struct workqueue_struct *shpchp_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/
51#define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0)
52#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
53#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
54#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
55
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +090056#define SLOT_NAME_SIZE 10
Linus Torvalds1da177e2005-04-16 15:20:36 -070057struct slot {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 u8 bus;
59 u8 device;
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070060 u16 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 u32 number;
62 u8 is_a_board;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 u8 state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 u8 presence_save;
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070065 u8 pwr_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 struct timer_list task_event;
67 u8 hp_slot;
68 struct controller *ctrl;
69 struct hpc_ops *hpc_ops;
70 struct hotplug_slot *hotplug_slot;
71 struct list_head slot_list;
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +090072 char name[SLOT_NAME_SIZE];
David Howellsc4028952006-11-22 14:57:56 +000073 struct delayed_work work; /* work for button event */
Kenji Kaneshigea246fa42006-02-21 15:45:48 -080074 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077struct event_info {
78 u32 event_type;
Kenji Kaneshigef7391f52006-02-21 15:45:45 -080079 struct slot *p_slot;
80 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
83struct controller {
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +010084 struct mutex crit_sect; /* critical section mutex */
Kenji Kaneshiged29aadd2006-01-26 09:59:24 +090085 struct mutex cmd_lock; /* command lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int num_slots; /* Number of slots on ctlr */
87 int slot_num_inc; /* 1 or -1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct pci_dev *pci_dev;
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +090089 struct list_head slot_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 struct hpc_ops *hpc_ops;
91 wait_queue_head_t queue; /* sleep & wake process */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 u8 bus;
93 u8 device;
94 u8 function;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 u8 slot_device_offset;
96 u8 add_support;
Keck, David53044f32006-01-16 15:22:36 -060097 u32 pcix_misc2_reg; /* for amd pogo errata */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 enum pci_bus_speed speed;
99 u32 first_slot; /* First physical slot number */
100 u8 slot_bus; /* Bus where the slots handled by this controller sit */
Kenji Kaneshige04559862005-11-24 11:36:59 +0900101 u32 cap_offset;
102 unsigned long mmio_base;
103 unsigned long mmio_size;
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800104 void __iomem *creg;
105 struct timer_list poll_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* Define AMD SHPC ID */
110#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
Keck, David53044f32006-01-16 15:22:36 -0600111#define PCI_DEVICE_ID_AMD_POGO_7458 0x7458
112
113/* AMD PCIX bridge registers */
114
115#define PCIX_MEM_BASE_LIMIT_OFFSET 0x1C
116#define PCIX_MISCII_OFFSET 0x48
117#define PCIX_MISC_BRIDGE_ERRORS_OFFSET 0x80
118
119/* AMD PCIX_MISCII masks and offsets */
120#define PERRNONFATALENABLE_MASK 0x00040000
121#define PERRFATALENABLE_MASK 0x00080000
122#define PERRFLOODENABLE_MASK 0x00100000
123#define SERRNONFATALENABLE_MASK 0x00200000
124#define SERRFATALENABLE_MASK 0x00400000
125
126/* AMD PCIX_MISC_BRIDGE_ERRORS masks and offsets */
127#define PERR_OBSERVED_MASK 0x00000001
128
129/* AMD PCIX_MEM_BASE_LIMIT masks */
130#define RSE_MASK 0x40000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132#define INT_BUTTON_IGNORE 0
133#define INT_PRESENCE_ON 1
134#define INT_PRESENCE_OFF 2
135#define INT_SWITCH_CLOSE 3
136#define INT_SWITCH_OPEN 4
137#define INT_POWER_FAULT 5
138#define INT_POWER_FAULT_CLEAR 6
139#define INT_BUTTON_PRESS 7
140#define INT_BUTTON_RELEASE 8
141#define INT_BUTTON_CANCEL 9
142
143#define STATIC_STATE 0
144#define BLINKINGON_STATE 1
145#define BLINKINGOFF_STATE 2
146#define POWERON_STATE 3
147#define POWEROFF_STATE 4
148
149#define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
150
151/* Error messages */
152#define INTERLOCK_OPEN 0x00000002
153#define ADD_NOT_SUPPORTED 0x00000003
154#define CARD_FUNCTIONING 0x00000005
155#define ADAPTER_NOT_SAME 0x00000006
156#define NO_ADAPTER_PRESENT 0x00000009
157#define NOT_ENOUGH_RESOURCES 0x0000000B
158#define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C
159#define WRONG_BUS_FREQUENCY 0x0000000D
160#define POWER_FAILURE 0x0000000E
161
162#define REMOVE_NOT_SUPPORTED 0x00000003
163
164#define DISABLE_CARD 1
165
166/*
167 * error Messages
168 */
169#define msg_initialization_err "Initialization failure, error=%d\n"
Kenji Kaneshige99ff1242006-05-12 11:13:50 +0900170#define msg_button_on "PCI slot #%s - powering on due to button press.\n"
171#define msg_button_off "PCI slot #%s - powering off due to button press.\n"
172#define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174/* sysfs functions for the hotplug controller info */
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -0700175extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Kenji Kaneshigea246fa42006-02-21 15:45:48 -0800177extern int shpchp_sysfs_enable_slot(struct slot *slot);
178extern int shpchp_sysfs_disable_slot(struct slot *slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Kenji Kaneshige0abe68c2006-12-16 15:25:34 -0800180extern u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl);
181extern u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl);
182extern u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
183extern u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* pci functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num);
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700187extern int shpchp_configure_device(struct slot *p_slot);
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -0700188extern int shpchp_unconfigure_device(struct slot *p_slot);
rajesh.shah@intel.comc2608a12005-10-13 12:05:44 -0700189extern void shpchp_remove_ctrl_files(struct controller *ctrl);
Kenji Kaneshigef7391f52006-02-21 15:45:45 -0800190extern void cleanup_slots(struct controller *ctrl);
David Howellsc4028952006-11-22 14:57:56 +0000191extern void queue_pushbutton_work(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Kristen Accardi783c49f2006-03-03 10:16:05 -0800193
194#ifdef CONFIG_ACPI
195static inline int get_hp_params_from_firmware(struct pci_dev *dev,
196 struct hotplug_params *hpp)
197{
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900198 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev->bus, hpp)))
Kristen Accardi783c49f2006-03-03 10:16:05 -0800199 return -ENODEV;
200 return 0;
201}
202#define get_hp_hw_control_from_firmware(pdev) \
203 do { \
204 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \
205 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev))); \
206 } while (0)
207#else
208#define get_hp_params_from_firmware(dev, hpp) (-ENODEV)
209#define get_hp_hw_control_from_firmware(dev) do { } while (0)
210#endif
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212struct ctrl_reg {
213 volatile u32 base_offset;
214 volatile u32 slot_avail1;
215 volatile u32 slot_avail2;
216 volatile u32 slot_config;
217 volatile u16 sec_bus_config;
218 volatile u8 msi_ctrl;
219 volatile u8 prog_interface;
220 volatile u16 cmd;
221 volatile u16 cmd_status;
222 volatile u32 intr_loc;
223 volatile u32 serr_loc;
224 volatile u32 serr_intr_enable;
225 volatile u32 slot1;
226 volatile u32 slot2;
227 volatile u32 slot3;
228 volatile u32 slot4;
229 volatile u32 slot5;
230 volatile u32 slot6;
231 volatile u32 slot7;
232 volatile u32 slot8;
233 volatile u32 slot9;
234 volatile u32 slot10;
235 volatile u32 slot11;
236 volatile u32 slot12;
237} __attribute__ ((packed));
238
239/* offsets to the controller registers based on the above structure layout */
240enum ctrl_offsets {
241 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset),
242 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1),
243 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2),
244 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config),
245 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config),
246 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl),
247 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface),
248 CMD = offsetof(struct ctrl_reg, cmd),
249 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status),
250 INTR_LOC = offsetof(struct ctrl_reg, intr_loc),
251 SERR_LOC = offsetof(struct ctrl_reg, serr_loc),
252 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable),
253 SLOT1 = offsetof(struct ctrl_reg, slot1),
254 SLOT2 = offsetof(struct ctrl_reg, slot2),
255 SLOT3 = offsetof(struct ctrl_reg, slot3),
256 SLOT4 = offsetof(struct ctrl_reg, slot4),
257 SLOT5 = offsetof(struct ctrl_reg, slot5),
258 SLOT6 = offsetof(struct ctrl_reg, slot6),
259 SLOT7 = offsetof(struct ctrl_reg, slot7),
260 SLOT8 = offsetof(struct ctrl_reg, slot8),
261 SLOT9 = offsetof(struct ctrl_reg, slot9),
262 SLOT10 = offsetof(struct ctrl_reg, slot10),
263 SLOT11 = offsetof(struct ctrl_reg, slot11),
264 SLOT12 = offsetof(struct ctrl_reg, slot12),
265};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267/* Inline functions to check the sanity of a pointer that is passed to us */
268static inline int slot_paranoia_check (struct slot *slot, const char *function)
269{
270 if (!slot) {
271 dbg("%s - slot == NULL", function);
272 return -1;
273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (!slot->hotplug_slot) {
275 dbg("%s - slot->hotplug_slot == NULL!", function);
276 return -1;
277 }
278 return 0;
279}
280
281static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
282{
283 struct slot *slot;
284
285 if (!hotplug_slot) {
286 dbg("%s - hotplug_slot == NULL\n", function);
287 return NULL;
288 }
289
290 slot = (struct slot *)hotplug_slot->private;
291 if (slot_paranoia_check (slot, function))
292 return NULL;
293 return slot;
294}
295
296static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device)
297{
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900298 struct slot *slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 if (!ctrl)
301 return NULL;
302
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900303 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
304 if (slot->device == device)
305 return slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900308 err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device);
309
310 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Keck, David53044f32006-01-16 15:22:36 -0600313static inline void amd_pogo_errata_save_misc_reg(struct slot *p_slot)
314{
315 u32 pcix_misc2_temp;
316
317 /* save MiscII register */
318 pci_read_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, &pcix_misc2_temp);
319
320 p_slot->ctrl->pcix_misc2_reg = pcix_misc2_temp;
321
322 /* clear SERR/PERR enable bits */
323 pcix_misc2_temp &= ~SERRFATALENABLE_MASK;
324 pcix_misc2_temp &= ~SERRNONFATALENABLE_MASK;
325 pcix_misc2_temp &= ~PERRFLOODENABLE_MASK;
326 pcix_misc2_temp &= ~PERRFATALENABLE_MASK;
327 pcix_misc2_temp &= ~PERRNONFATALENABLE_MASK;
328 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp);
329}
330
331static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot)
332{
333 u32 pcix_misc2_temp;
334 u32 pcix_bridge_errors_reg;
335 u32 pcix_mem_base_reg;
336 u8 perr_set;
337 u8 rse_set;
338
339 /* write-one-to-clear Bridge_Errors[ PERR_OBSERVED ] */
340 pci_read_config_dword(p_slot->ctrl->pci_dev, PCIX_MISC_BRIDGE_ERRORS_OFFSET, &pcix_bridge_errors_reg);
341 perr_set = pcix_bridge_errors_reg & PERR_OBSERVED_MASK;
342 if (perr_set) {
343 dbg ("%s W1C: Bridge_Errors[ PERR_OBSERVED = %08X]\n",__FUNCTION__ , perr_set);
344
345 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISC_BRIDGE_ERRORS_OFFSET, perr_set);
346 }
347
348 /* write-one-to-clear Memory_Base_Limit[ RSE ] */
349 pci_read_config_dword(p_slot->ctrl->pci_dev, PCIX_MEM_BASE_LIMIT_OFFSET, &pcix_mem_base_reg);
350 rse_set = pcix_mem_base_reg & RSE_MASK;
351 if (rse_set) {
352 dbg ("%s W1C: Memory_Base_Limit[ RSE ]\n",__FUNCTION__ );
353
354 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MEM_BASE_LIMIT_OFFSET, rse_set);
355 }
356 /* restore MiscII register */
357 pci_read_config_dword( p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, &pcix_misc2_temp );
358
359 if (p_slot->ctrl->pcix_misc2_reg & SERRFATALENABLE_MASK)
360 pcix_misc2_temp |= SERRFATALENABLE_MASK;
361 else
362 pcix_misc2_temp &= ~SERRFATALENABLE_MASK;
363
364 if (p_slot->ctrl->pcix_misc2_reg & SERRNONFATALENABLE_MASK)
365 pcix_misc2_temp |= SERRNONFATALENABLE_MASK;
366 else
367 pcix_misc2_temp &= ~SERRNONFATALENABLE_MASK;
368
369 if (p_slot->ctrl->pcix_misc2_reg & PERRFLOODENABLE_MASK)
370 pcix_misc2_temp |= PERRFLOODENABLE_MASK;
371 else
372 pcix_misc2_temp &= ~PERRFLOODENABLE_MASK;
373
374 if (p_slot->ctrl->pcix_misc2_reg & PERRFATALENABLE_MASK)
375 pcix_misc2_temp |= PERRFATALENABLE_MASK;
376 else
377 pcix_misc2_temp &= ~PERRFATALENABLE_MASK;
378
379 if (p_slot->ctrl->pcix_misc2_reg & PERRNONFATALENABLE_MASK)
380 pcix_misc2_temp |= PERRNONFATALENABLE_MASK;
381 else
382 pcix_misc2_temp &= ~PERRNONFATALENABLE_MASK;
383 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp);
384}
385
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700386int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388struct hpc_ops {
389 int (*power_on_slot ) (struct slot *slot);
390 int (*slot_enable ) (struct slot *slot);
391 int (*slot_disable ) (struct slot *slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed);
393 int (*get_power_status) (struct slot *slot, u8 *status);
394 int (*get_attention_status) (struct slot *slot, u8 *status);
395 int (*set_attention_status) (struct slot *slot, u8 status);
396 int (*get_latch_status) (struct slot *slot, u8 *status);
397 int (*get_adapter_status) (struct slot *slot, u8 *status);
398
399 int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
400 int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
401 int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed);
402 int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode);
403 int (*get_prog_int) (struct slot *slot, u8 *prog_int);
404
405 int (*query_power_fault) (struct slot *slot);
406 void (*green_led_on) (struct slot *slot);
407 void (*green_led_off) (struct slot *slot);
408 void (*green_led_blink) (struct slot *slot);
409 void (*release_ctlr) (struct controller *ctrl);
410 int (*check_cmd_status) (struct controller *ctrl);
411};
412
413#endif /* _SHPCHP_H */