Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PCI Express 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 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 Accardi | 8cf4c19 | 2005-08-16 15:16:10 -0700 | [diff] [blame] | 26 | * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/smp_lock.h> |
| 34 | #include <linux/pci.h> |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 35 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "../pci.h" |
| 37 | #include "pciehp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 39 | static void interrupt_event_handler(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 41 | static int queue_interrupt_event(struct slot *p_slot, u32 event_type) |
Kenji Kaneshige | 49ed2b4 | 2006-09-22 10:17:10 -0700 | [diff] [blame] | 42 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 43 | struct event_info *info; |
| 44 | |
| 45 | info = kmalloc(sizeof(*info), GFP_ATOMIC); |
| 46 | if (!info) |
| 47 | return -ENOMEM; |
| 48 | |
| 49 | info->event_type = event_type; |
| 50 | info->p_slot = p_slot; |
| 51 | INIT_WORK(&info->work, interrupt_event_handler); |
| 52 | |
| 53 | schedule_work(&info->work); |
| 54 | |
| 55 | return 0; |
Kenji Kaneshige | 49ed2b4 | 2006-09-22 10:17:10 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Kenji Kaneshige | dbd79ae | 2008-05-27 19:03:16 +0900 | [diff] [blame] | 58 | u8 pciehp_handle_attention_button(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 60 | u32 event_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* Attention Button Change */ |
| 63 | dbg("pciehp: Attention button interrupt received.\n"); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* |
| 66 | * Button pressed - See if need to TAKE ACTION!!! |
| 67 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 68 | info("Button pressed on Slot(%s)\n", p_slot->name); |
| 69 | event_type = INT_BUTTON_PRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 71 | queue_interrupt_event(p_slot, event_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Kenji Kaneshige | dbd79ae | 2008-05-27 19:03:16 +0900 | [diff] [blame] | 76 | u8 pciehp_handle_switch_change(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | u8 getstatus; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 79 | u32 event_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* Switch Change */ |
| 82 | dbg("pciehp: Switch interrupt received.\n"); |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (getstatus) { |
| 86 | /* |
| 87 | * Switch opened |
| 88 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 89 | info("Latch open on Slot(%s)\n", p_slot->name); |
| 90 | event_type = INT_SWITCH_OPEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } else { |
| 92 | /* |
| 93 | * Switch closed |
| 94 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 95 | info("Latch close on Slot(%s)\n", p_slot->name); |
| 96 | event_type = INT_SWITCH_CLOSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 99 | queue_interrupt_event(p_slot, event_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 101 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Kenji Kaneshige | dbd79ae | 2008-05-27 19:03:16 +0900 | [diff] [blame] | 104 | u8 pciehp_handle_presence_change(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 106 | u32 event_type; |
| 107 | u8 presence_save; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | /* Presence Change */ |
| 110 | dbg("pciehp: Presence/Notify input change.\n"); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* Switch is open, assume a presence change |
| 113 | * Save the presence state |
| 114 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 115 | p_slot->hpc_ops->get_adapter_status(p_slot, &presence_save); |
| 116 | if (presence_save) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* |
| 118 | * Card Present |
| 119 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 120 | info("Card present on Slot(%s)\n", p_slot->name); |
| 121 | event_type = INT_PRESENCE_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } else { |
| 123 | /* |
| 124 | * Not Present |
| 125 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 126 | info("Card not present on Slot(%s)\n", p_slot->name); |
| 127 | event_type = INT_PRESENCE_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 130 | queue_interrupt_event(p_slot, event_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 132 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Kenji Kaneshige | dbd79ae | 2008-05-27 19:03:16 +0900 | [diff] [blame] | 135 | u8 pciehp_handle_power_fault(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 137 | u32 event_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | /* power fault */ |
| 140 | dbg("pciehp: Power fault interrupt received.\n"); |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) { |
| 143 | /* |
| 144 | * power fault Cleared |
| 145 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 146 | info("Power fault cleared on Slot(%s)\n", p_slot->name); |
| 147 | event_type = INT_POWER_FAULT_CLEAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } else { |
| 149 | /* |
| 150 | * power fault |
| 151 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 152 | info("Power fault on Slot(%s)\n", p_slot->name); |
| 153 | event_type = INT_POWER_FAULT; |
Kenji Kaneshige | dbd79ae | 2008-05-27 19:03:16 +0900 | [diff] [blame] | 154 | info("power fault bit %x set\n", 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 157 | queue_interrupt_event(p_slot, event_type); |
| 158 | |
| 159 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 162 | /* The following routines constitute the bulk of the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | hotplug controller logic |
| 164 | */ |
| 165 | |
| 166 | static void set_slot_off(struct controller *ctrl, struct slot * pslot) |
| 167 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* turn off slot, turn on Amber LED, turn off Green LED if supported*/ |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 169 | if (POWER_CTRL(ctrl)) { |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 170 | if (pslot->hpc_ops->power_off_slot(pslot)) { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 171 | err("%s: Issue of Slot Power Off command failed\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 172 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | return; |
| 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Kenji Kaneshige | 0711c70 | 2008-05-27 19:06:22 +0900 | [diff] [blame] | 177 | /* |
| 178 | * After turning power off, we must wait for at least 1 second |
| 179 | * before taking any action that relies on power having been |
| 180 | * removed from the slot/adapter. |
| 181 | */ |
| 182 | msleep(1000); |
| 183 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 184 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 185 | pslot->hpc_ops->green_led_off(pslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 187 | if (ATTN_LED(ctrl)) { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 188 | if (pslot->hpc_ops->set_attention_status(pslot, 1)) { |
| 189 | err("%s: Issue of Set Attention Led command failed\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 190 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | return; |
| 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * board_added - Called after a board has been added to the system. |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 198 | * @p_slot: &slot where board is added |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 200 | * Turns power on for the board. |
| 201 | * Configures board. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 203 | static int board_added(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 205 | int retval = 0; |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 206 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 208 | dbg("%s: slot device, slot offset, hp slot = %d, %d ,%d\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 209 | __func__, p_slot->device, |
Kenji Kaneshige | 941f10e | 2007-11-09 17:29:42 +0900 | [diff] [blame] | 210 | ctrl->slot_device_offset, p_slot->hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 212 | if (POWER_CTRL(ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | /* Power on slot */ |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 214 | retval = p_slot->hpc_ops->power_on_slot(p_slot); |
| 215 | if (retval) |
| 216 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 218 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 219 | if (PWR_LED(ctrl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | p_slot->hpc_ops->green_led_blink(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* Wait for ~1 second */ |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 223 | msleep(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 225 | /* Check link training status */ |
| 226 | retval = p_slot->hpc_ops->check_lnk_status(ctrl); |
| 227 | if (retval) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 228 | err("%s: Failed to check link status\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | set_slot_off(ctrl, p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 230 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* Check for a power fault */ |
Rajesh Shah | 5a49f20 | 2005-11-23 15:44:54 -0800 | [diff] [blame] | 234 | if (p_slot->hpc_ops->query_power_fault(p_slot)) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 235 | dbg("%s: power fault detected\n", __func__); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 236 | retval = POWER_FAILURE; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 237 | goto err_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 240 | retval = pciehp_configure_device(p_slot); |
| 241 | if (retval) { |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 242 | err("Cannot add device 0x%x:%x\n", p_slot->bus, |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 243 | p_slot->device); |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 244 | goto err_exit; |
| 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 247 | /* |
| 248 | * Some PCI Express root ports require fixup after hot-plug operation. |
| 249 | */ |
| 250 | if (pcie_mch_quirk) |
| 251 | pci_fixup_device(pci_fixup_final, ctrl->pci_dev); |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 252 | if (PWR_LED(ctrl)) |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 253 | p_slot->hpc_ops->green_led_on(p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return 0; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 256 | |
| 257 | err_exit: |
| 258 | set_slot_off(ctrl, p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 259 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 263 | * remove_board - Turns off slot and LEDs |
| 264 | * @p_slot: slot where board is being removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 266 | static int remove_board(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 268 | int retval = 0; |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 269 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 271 | retval = pciehp_unconfigure_device(p_slot); |
| 272 | if (retval) |
| 273 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 275 | dbg("In %s, hp_slot = %d\n", __func__, p_slot->hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 277 | if (POWER_CTRL(ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* power off slot */ |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 279 | retval = p_slot->hpc_ops->power_off_slot(p_slot); |
| 280 | if (retval) { |
| 281 | err("%s: Issue of Slot Disable command failed\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 282 | __func__); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 283 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Kenji Kaneshige | 0711c70 | 2008-05-27 19:06:22 +0900 | [diff] [blame] | 287 | /* |
| 288 | * After turning power off, we must wait for at least 1 second |
| 289 | * before taking any action that relies on power having been |
| 290 | * removed from the slot/adapter. |
| 291 | */ |
| 292 | msleep(1000); |
| 293 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 294 | if (PWR_LED(ctrl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | /* turn off Green LED */ |
| 296 | p_slot->hpc_ops->green_led_off(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 301 | struct power_work_info { |
| 302 | struct slot *p_slot; |
| 303 | struct work_struct work; |
| 304 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 307 | * pciehp_power_thread - handle pushbutton events |
| 308 | * @work: &struct work_struct describing work to be done |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 310 | * Scheduled procedure to handle blocking stuff for the pushbuttons. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | * Handles all pending events and exits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 313 | static void pciehp_power_thread(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 315 | struct power_work_info *info = |
| 316 | container_of(work, struct power_work_info, work); |
| 317 | struct slot *p_slot = info->p_slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 319 | mutex_lock(&p_slot->lock); |
| 320 | switch (p_slot->state) { |
| 321 | case POWEROFF_STATE: |
| 322 | mutex_unlock(&p_slot->lock); |
| 323 | dbg("%s: disabling bus:device(%x:%x)\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 324 | __func__, p_slot->bus, p_slot->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | pciehp_disable_slot(p_slot); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 326 | mutex_lock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | p_slot->state = STATIC_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 328 | break; |
| 329 | case POWERON_STATE: |
| 330 | mutex_unlock(&p_slot->lock); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 331 | if (pciehp_enable_slot(p_slot) && |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 332 | PWR_LED(p_slot->ctrl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | p_slot->hpc_ops->green_led_off(p_slot); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 334 | mutex_lock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | p_slot->state = STATIC_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 336 | break; |
| 337 | default: |
| 338 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 340 | mutex_unlock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 342 | kfree(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Kristen Carlson Accardi | e325e1f | 2007-03-21 11:45:31 -0700 | [diff] [blame] | 345 | void pciehp_queue_pushbutton_work(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 347 | struct slot *p_slot = container_of(work, struct slot, work.work); |
| 348 | struct power_work_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 350 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 351 | if (!info) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 352 | err("%s: Cannot allocate memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return; |
| 354 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 355 | info->p_slot = p_slot; |
| 356 | INIT_WORK(&info->work, pciehp_power_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 358 | mutex_lock(&p_slot->lock); |
| 359 | switch (p_slot->state) { |
| 360 | case BLINKINGOFF_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | p_slot->state = POWEROFF_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 362 | break; |
| 363 | case BLINKINGON_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | p_slot->state = POWERON_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 365 | break; |
| 366 | default: |
| 367 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 369 | queue_work(pciehp_wq, &info->work); |
| 370 | out: |
| 371 | mutex_unlock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | static int update_slot_info(struct slot *slot) |
| 375 | { |
| 376 | struct hotplug_slot_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | int result; |
| 378 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 379 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | if (!info) |
| 381 | return -ENOMEM; |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | slot->hpc_ops->get_power_status(slot, &(info->power_status)); |
| 384 | slot->hpc_ops->get_attention_status(slot, &(info->attention_status)); |
| 385 | slot->hpc_ops->get_latch_status(slot, &(info->latch_status)); |
| 386 | slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status)); |
| 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | result = pci_hp_change_slot_info(slot->hotplug_slot, info); |
| 389 | kfree (info); |
| 390 | return result; |
| 391 | } |
| 392 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 393 | /* |
| 394 | * Note: This function must be called with slot->lock held |
| 395 | */ |
| 396 | static void handle_button_press_event(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 398 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | u8 getstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 401 | switch (p_slot->state) { |
| 402 | case STATIC_STATE: |
| 403 | p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 404 | if (getstatus) { |
| 405 | p_slot->state = BLINKINGOFF_STATE; |
| 406 | info("PCI slot #%s - powering off due to button " |
| 407 | "press.\n", p_slot->name); |
| 408 | } else { |
| 409 | p_slot->state = BLINKINGON_STATE; |
| 410 | info("PCI slot #%s - powering on due to button " |
| 411 | "press.\n", p_slot->name); |
| 412 | } |
| 413 | /* blink green LED and turn off amber */ |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 414 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 415 | p_slot->hpc_ops->green_led_blink(p_slot); |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 416 | if (ATTN_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 417 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 419 | schedule_delayed_work(&p_slot->work, 5*HZ); |
| 420 | break; |
| 421 | case BLINKINGOFF_STATE: |
| 422 | case BLINKINGON_STATE: |
| 423 | /* |
| 424 | * Cancel if we are still blinking; this means that we |
| 425 | * press the attention again before the 5 sec. limit |
| 426 | * expires to cancel hot-add or hot-remove |
| 427 | */ |
| 428 | info("Button cancel on Slot(%s)\n", p_slot->name); |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 429 | dbg("%s: button cancel\n", __func__); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 430 | cancel_delayed_work(&p_slot->work); |
| 431 | if (p_slot->state == BLINKINGOFF_STATE) { |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 432 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 433 | p_slot->hpc_ops->green_led_on(p_slot); |
| 434 | } else { |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 435 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 436 | p_slot->hpc_ops->green_led_off(p_slot); |
| 437 | } |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 438 | if (ATTN_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 439 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
| 440 | info("PCI slot #%s - action canceled due to button press\n", |
| 441 | p_slot->name); |
| 442 | p_slot->state = STATIC_STATE; |
| 443 | break; |
| 444 | case POWEROFF_STATE: |
| 445 | case POWERON_STATE: |
| 446 | /* |
| 447 | * Ignore if the slot is on power-on or power-off state; |
| 448 | * this means that the previous attention button action |
| 449 | * to hot-add or hot-remove is undergoing |
| 450 | */ |
| 451 | info("Button ignore on Slot(%s)\n", p_slot->name); |
| 452 | update_slot_info(p_slot); |
| 453 | break; |
| 454 | default: |
| 455 | warn("Not a valid state\n"); |
| 456 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 460 | /* |
| 461 | * Note: This function must be called with slot->lock held |
| 462 | */ |
| 463 | static void handle_surprise_event(struct slot *p_slot) |
| 464 | { |
| 465 | u8 getstatus; |
| 466 | struct power_work_info *info; |
| 467 | |
| 468 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 469 | if (!info) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 470 | err("%s: Cannot allocate memory\n", __func__); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 471 | return; |
| 472 | } |
| 473 | info->p_slot = p_slot; |
| 474 | INIT_WORK(&info->work, pciehp_power_thread); |
| 475 | |
| 476 | p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 477 | if (!getstatus) |
| 478 | p_slot->state = POWEROFF_STATE; |
| 479 | else |
| 480 | p_slot->state = POWERON_STATE; |
| 481 | |
| 482 | queue_work(pciehp_wq, &info->work); |
| 483 | } |
| 484 | |
| 485 | static void interrupt_event_handler(struct work_struct *work) |
| 486 | { |
| 487 | struct event_info *info = container_of(work, struct event_info, work); |
| 488 | struct slot *p_slot = info->p_slot; |
| 489 | struct controller *ctrl = p_slot->ctrl; |
| 490 | |
| 491 | mutex_lock(&p_slot->lock); |
| 492 | switch (info->event_type) { |
| 493 | case INT_BUTTON_PRESS: |
| 494 | handle_button_press_event(p_slot); |
| 495 | break; |
| 496 | case INT_POWER_FAULT: |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 497 | if (!POWER_CTRL(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 498 | break; |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 499 | if (ATTN_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 500 | p_slot->hpc_ops->set_attention_status(p_slot, 1); |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 501 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 502 | p_slot->hpc_ops->green_led_off(p_slot); |
| 503 | break; |
| 504 | case INT_PRESENCE_ON: |
| 505 | case INT_PRESENCE_OFF: |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 506 | if (!HP_SUPR_RM(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 507 | break; |
| 508 | dbg("Surprise Removal\n"); |
| 509 | update_slot_info(p_slot); |
| 510 | handle_surprise_event(p_slot); |
| 511 | break; |
| 512 | default: |
| 513 | update_slot_info(p_slot); |
| 514 | break; |
| 515 | } |
| 516 | mutex_unlock(&p_slot->lock); |
| 517 | |
| 518 | kfree(info); |
| 519 | } |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | int pciehp_enable_slot(struct slot *p_slot) |
| 522 | { |
| 523 | u8 getstatus = 0; |
| 524 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | /* Check to see if (latch closed, card present, power off) */ |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 527 | mutex_lock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 530 | if (rc || !getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 531 | info("%s: no adapter on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 532 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 533 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 534 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 536 | if (MRL_SENS(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 538 | if (rc || getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 539 | info("%s: latch open on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 540 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 541 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 542 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 545 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 546 | if (POWER_CTRL(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 548 | if (rc || getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 549 | info("%s: already enabled on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 550 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 551 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 552 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 558 | rc = board_added(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Eric Sesterhenn | 9ef9977 | 2006-09-25 00:56:53 +0200 | [diff] [blame] | 563 | update_slot_info(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Kenji Kaneshige | dd5619c | 2006-09-22 10:17:29 -0700 | [diff] [blame] | 565 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | return rc; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | int pciehp_disable_slot(struct slot *p_slot) |
| 571 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | u8 getstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | if (!p_slot->ctrl) |
| 576 | return 1; |
| 577 | |
| 578 | /* Check to see if (latch closed, card present, power on) */ |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 579 | mutex_lock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 581 | if (!HP_SUPR_RM(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 583 | if (ret || !getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 584 | info("%s: no adapter on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 585 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 586 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 587 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 591 | if (MRL_SENS(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 593 | if (ret || getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 594 | info("%s: latch open on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 595 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 596 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 597 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 601 | if (POWER_CTRL(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 603 | if (ret || !getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 604 | info("%s: already disabled slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 605 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 606 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 607 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 611 | ret = remove_board(p_slot); |
| 612 | update_slot_info(p_slot); |
Kenji Kaneshige | dd5619c | 2006-09-22 10:17:29 -0700 | [diff] [blame] | 613 | |
| 614 | mutex_unlock(&p_slot->ctrl->crit_sect); |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 615 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 618 | int pciehp_sysfs_enable_slot(struct slot *p_slot) |
| 619 | { |
| 620 | int retval = -ENODEV; |
| 621 | |
| 622 | mutex_lock(&p_slot->lock); |
| 623 | switch (p_slot->state) { |
| 624 | case BLINKINGON_STATE: |
| 625 | cancel_delayed_work(&p_slot->work); |
| 626 | case STATIC_STATE: |
| 627 | p_slot->state = POWERON_STATE; |
| 628 | mutex_unlock(&p_slot->lock); |
| 629 | retval = pciehp_enable_slot(p_slot); |
| 630 | mutex_lock(&p_slot->lock); |
| 631 | p_slot->state = STATIC_STATE; |
| 632 | break; |
| 633 | case POWERON_STATE: |
| 634 | info("Slot %s is already in powering on state\n", |
| 635 | p_slot->name); |
| 636 | break; |
| 637 | case BLINKINGOFF_STATE: |
| 638 | case POWEROFF_STATE: |
| 639 | info("Already enabled on slot %s\n", p_slot->name); |
| 640 | break; |
| 641 | default: |
| 642 | err("Not a valid state on slot %s\n", p_slot->name); |
| 643 | break; |
| 644 | } |
| 645 | mutex_unlock(&p_slot->lock); |
| 646 | |
| 647 | return retval; |
| 648 | } |
| 649 | |
| 650 | int pciehp_sysfs_disable_slot(struct slot *p_slot) |
| 651 | { |
| 652 | int retval = -ENODEV; |
| 653 | |
| 654 | mutex_lock(&p_slot->lock); |
| 655 | switch (p_slot->state) { |
| 656 | case BLINKINGOFF_STATE: |
| 657 | cancel_delayed_work(&p_slot->work); |
| 658 | case STATIC_STATE: |
| 659 | p_slot->state = POWEROFF_STATE; |
| 660 | mutex_unlock(&p_slot->lock); |
| 661 | retval = pciehp_disable_slot(p_slot); |
| 662 | mutex_lock(&p_slot->lock); |
| 663 | p_slot->state = STATIC_STATE; |
| 664 | break; |
| 665 | case POWEROFF_STATE: |
| 666 | info("Slot %s is already in powering off state\n", |
| 667 | p_slot->name); |
| 668 | break; |
| 669 | case BLINKINGON_STATE: |
| 670 | case POWERON_STATE: |
| 671 | info("Already disabled on slot %s\n", p_slot->name); |
| 672 | break; |
| 673 | default: |
| 674 | err("Not a valid state on slot %s\n", p_slot->name); |
| 675 | break; |
| 676 | } |
| 677 | mutex_unlock(&p_slot->lock); |
| 678 | |
| 679 | return retval; |
| 680 | } |