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 | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 177 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 178 | pslot->hpc_ops->green_led_off(pslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 180 | if (ATTN_LED(ctrl)) { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 181 | if (pslot->hpc_ops->set_attention_status(pslot, 1)) { |
| 182 | err("%s: Issue of Set Attention Led command failed\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 183 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return; |
| 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
| 190 | * board_added - Called after a board has been added to the system. |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 191 | * @p_slot: &slot where board is added |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 193 | * Turns power on for the board. |
| 194 | * Configures board. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 196 | static int board_added(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 198 | int retval = 0; |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 199 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
rajesh.shah@intel.com | 1a9ed1b | 2005-10-31 16:20:10 -0800 | [diff] [blame] | 201 | dbg("%s: slot device, slot offset, hp slot = %d, %d ,%d\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 202 | __func__, p_slot->device, |
Kenji Kaneshige | 941f10e | 2007-11-09 17:29:42 +0900 | [diff] [blame] | 203 | ctrl->slot_device_offset, p_slot->hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 205 | if (POWER_CTRL(ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | /* Power on slot */ |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 207 | retval = p_slot->hpc_ops->power_on_slot(p_slot); |
| 208 | if (retval) |
| 209 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 211 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 212 | if (PWR_LED(ctrl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | p_slot->hpc_ops->green_led_blink(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* Wait for ~1 second */ |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 216 | msleep(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 218 | /* Check link training status */ |
| 219 | retval = p_slot->hpc_ops->check_lnk_status(ctrl); |
| 220 | if (retval) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 221 | err("%s: Failed to check link status\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | set_slot_off(ctrl, p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 223 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | /* Check for a power fault */ |
Rajesh Shah | 5a49f20 | 2005-11-23 15:44:54 -0800 | [diff] [blame] | 227 | if (p_slot->hpc_ops->query_power_fault(p_slot)) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 228 | dbg("%s: power fault detected\n", __func__); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 229 | retval = POWER_FAILURE; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 230 | goto err_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 233 | retval = pciehp_configure_device(p_slot); |
| 234 | if (retval) { |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 235 | err("Cannot add device 0x%x:%x\n", p_slot->bus, |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 236 | p_slot->device); |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 237 | goto err_exit; |
| 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 240 | /* |
| 241 | * Some PCI Express root ports require fixup after hot-plug operation. |
| 242 | */ |
| 243 | if (pcie_mch_quirk) |
| 244 | pci_fixup_device(pci_fixup_final, ctrl->pci_dev); |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 245 | if (PWR_LED(ctrl)) |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 246 | p_slot->hpc_ops->green_led_on(p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | return 0; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 249 | |
| 250 | err_exit: |
| 251 | set_slot_off(ctrl, p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 252 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 256 | * remove_board - Turns off slot and LEDs |
| 257 | * @p_slot: slot where board is being removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 259 | static int remove_board(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 261 | int retval = 0; |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 262 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 264 | retval = pciehp_unconfigure_device(p_slot); |
| 265 | if (retval) |
| 266 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 268 | dbg("In %s, hp_slot = %d\n", __func__, p_slot->hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 270 | if (POWER_CTRL(ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /* power off slot */ |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 272 | retval = p_slot->hpc_ops->power_off_slot(p_slot); |
| 273 | if (retval) { |
| 274 | err("%s: Issue of Slot Disable command failed\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 275 | __func__); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 276 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 280 | if (PWR_LED(ctrl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* turn off Green LED */ |
| 282 | p_slot->hpc_ops->green_led_off(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | return 0; |
| 285 | } |
| 286 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 287 | struct power_work_info { |
| 288 | struct slot *p_slot; |
| 289 | struct work_struct work; |
| 290 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 293 | * pciehp_power_thread - handle pushbutton events |
| 294 | * @work: &struct work_struct describing work to be done |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 296 | * Scheduled procedure to handle blocking stuff for the pushbuttons. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | * Handles all pending events and exits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 299 | static void pciehp_power_thread(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 301 | struct power_work_info *info = |
| 302 | container_of(work, struct power_work_info, work); |
| 303 | struct slot *p_slot = info->p_slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 305 | mutex_lock(&p_slot->lock); |
| 306 | switch (p_slot->state) { |
| 307 | case POWEROFF_STATE: |
| 308 | mutex_unlock(&p_slot->lock); |
| 309 | dbg("%s: disabling bus:device(%x:%x)\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 310 | __func__, p_slot->bus, p_slot->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | pciehp_disable_slot(p_slot); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 312 | mutex_lock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | p_slot->state = STATIC_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 314 | break; |
| 315 | case POWERON_STATE: |
| 316 | mutex_unlock(&p_slot->lock); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 317 | if (pciehp_enable_slot(p_slot) && |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 318 | PWR_LED(p_slot->ctrl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | p_slot->hpc_ops->green_led_off(p_slot); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 320 | mutex_lock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | p_slot->state = STATIC_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 322 | break; |
| 323 | default: |
| 324 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 326 | mutex_unlock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 328 | kfree(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Kristen Carlson Accardi | e325e1f | 2007-03-21 11:45:31 -0700 | [diff] [blame] | 331 | void pciehp_queue_pushbutton_work(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 333 | struct slot *p_slot = container_of(work, struct slot, work.work); |
| 334 | struct power_work_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 336 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 337 | if (!info) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 338 | err("%s: Cannot allocate memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return; |
| 340 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 341 | info->p_slot = p_slot; |
| 342 | INIT_WORK(&info->work, pciehp_power_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 344 | mutex_lock(&p_slot->lock); |
| 345 | switch (p_slot->state) { |
| 346 | case BLINKINGOFF_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | p_slot->state = POWEROFF_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 348 | break; |
| 349 | case BLINKINGON_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | p_slot->state = POWERON_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 351 | break; |
| 352 | default: |
| 353 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 355 | queue_work(pciehp_wq, &info->work); |
| 356 | out: |
| 357 | mutex_unlock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | static int update_slot_info(struct slot *slot) |
| 361 | { |
| 362 | struct hotplug_slot_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | int result; |
| 364 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 365 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (!info) |
| 367 | return -ENOMEM; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | slot->hpc_ops->get_power_status(slot, &(info->power_status)); |
| 370 | slot->hpc_ops->get_attention_status(slot, &(info->attention_status)); |
| 371 | slot->hpc_ops->get_latch_status(slot, &(info->latch_status)); |
| 372 | slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status)); |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | result = pci_hp_change_slot_info(slot->hotplug_slot, info); |
| 375 | kfree (info); |
| 376 | return result; |
| 377 | } |
| 378 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 379 | /* |
| 380 | * Note: This function must be called with slot->lock held |
| 381 | */ |
| 382 | static void handle_button_press_event(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 384 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | u8 getstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 387 | switch (p_slot->state) { |
| 388 | case STATIC_STATE: |
| 389 | p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 390 | if (getstatus) { |
| 391 | p_slot->state = BLINKINGOFF_STATE; |
| 392 | info("PCI slot #%s - powering off due to button " |
| 393 | "press.\n", p_slot->name); |
| 394 | } else { |
| 395 | p_slot->state = BLINKINGON_STATE; |
| 396 | info("PCI slot #%s - powering on due to button " |
| 397 | "press.\n", p_slot->name); |
| 398 | } |
| 399 | /* blink green LED and turn off amber */ |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 400 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 401 | p_slot->hpc_ops->green_led_blink(p_slot); |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 402 | if (ATTN_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 403 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 405 | schedule_delayed_work(&p_slot->work, 5*HZ); |
| 406 | break; |
| 407 | case BLINKINGOFF_STATE: |
| 408 | case BLINKINGON_STATE: |
| 409 | /* |
| 410 | * Cancel if we are still blinking; this means that we |
| 411 | * press the attention again before the 5 sec. limit |
| 412 | * expires to cancel hot-add or hot-remove |
| 413 | */ |
| 414 | info("Button cancel on Slot(%s)\n", p_slot->name); |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 415 | dbg("%s: button cancel\n", __func__); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 416 | cancel_delayed_work(&p_slot->work); |
| 417 | if (p_slot->state == BLINKINGOFF_STATE) { |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 418 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 419 | p_slot->hpc_ops->green_led_on(p_slot); |
| 420 | } else { |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 421 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 422 | p_slot->hpc_ops->green_led_off(p_slot); |
| 423 | } |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 424 | if (ATTN_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 425 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
| 426 | info("PCI slot #%s - action canceled due to button press\n", |
| 427 | p_slot->name); |
| 428 | p_slot->state = STATIC_STATE; |
| 429 | break; |
| 430 | case POWEROFF_STATE: |
| 431 | case POWERON_STATE: |
| 432 | /* |
| 433 | * Ignore if the slot is on power-on or power-off state; |
| 434 | * this means that the previous attention button action |
| 435 | * to hot-add or hot-remove is undergoing |
| 436 | */ |
| 437 | info("Button ignore on Slot(%s)\n", p_slot->name); |
| 438 | update_slot_info(p_slot); |
| 439 | break; |
| 440 | default: |
| 441 | warn("Not a valid state\n"); |
| 442 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 446 | /* |
| 447 | * Note: This function must be called with slot->lock held |
| 448 | */ |
| 449 | static void handle_surprise_event(struct slot *p_slot) |
| 450 | { |
| 451 | u8 getstatus; |
| 452 | struct power_work_info *info; |
| 453 | |
| 454 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 455 | if (!info) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 456 | err("%s: Cannot allocate memory\n", __func__); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 457 | return; |
| 458 | } |
| 459 | info->p_slot = p_slot; |
| 460 | INIT_WORK(&info->work, pciehp_power_thread); |
| 461 | |
| 462 | p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 463 | if (!getstatus) |
| 464 | p_slot->state = POWEROFF_STATE; |
| 465 | else |
| 466 | p_slot->state = POWERON_STATE; |
| 467 | |
| 468 | queue_work(pciehp_wq, &info->work); |
| 469 | } |
| 470 | |
| 471 | static void interrupt_event_handler(struct work_struct *work) |
| 472 | { |
| 473 | struct event_info *info = container_of(work, struct event_info, work); |
| 474 | struct slot *p_slot = info->p_slot; |
| 475 | struct controller *ctrl = p_slot->ctrl; |
| 476 | |
| 477 | mutex_lock(&p_slot->lock); |
| 478 | switch (info->event_type) { |
| 479 | case INT_BUTTON_PRESS: |
| 480 | handle_button_press_event(p_slot); |
| 481 | break; |
| 482 | case INT_POWER_FAULT: |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 483 | if (!POWER_CTRL(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 484 | break; |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 485 | if (ATTN_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 486 | p_slot->hpc_ops->set_attention_status(p_slot, 1); |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 487 | if (PWR_LED(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 488 | p_slot->hpc_ops->green_led_off(p_slot); |
| 489 | break; |
| 490 | case INT_PRESENCE_ON: |
| 491 | case INT_PRESENCE_OFF: |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 492 | if (!HP_SUPR_RM(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 493 | break; |
| 494 | dbg("Surprise Removal\n"); |
| 495 | update_slot_info(p_slot); |
| 496 | handle_surprise_event(p_slot); |
| 497 | break; |
| 498 | default: |
| 499 | update_slot_info(p_slot); |
| 500 | break; |
| 501 | } |
| 502 | mutex_unlock(&p_slot->lock); |
| 503 | |
| 504 | kfree(info); |
| 505 | } |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | int pciehp_enable_slot(struct slot *p_slot) |
| 508 | { |
| 509 | u8 getstatus = 0; |
| 510 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | /* Check to see if (latch closed, card present, power off) */ |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 513 | mutex_lock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 516 | if (rc || !getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 517 | info("%s: no adapter on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 518 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 519 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 520 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 522 | if (MRL_SENS(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 524 | if (rc || getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 525 | info("%s: latch open on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 526 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 527 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 528 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 531 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 532 | if (POWER_CTRL(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 534 | if (rc || getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 535 | info("%s: already enabled on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 536 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 537 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 538 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 544 | rc = board_added(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Eric Sesterhenn | 9ef9977 | 2006-09-25 00:56:53 +0200 | [diff] [blame] | 549 | update_slot_info(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Kenji Kaneshige | dd5619c | 2006-09-22 10:17:29 -0700 | [diff] [blame] | 551 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return rc; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | int pciehp_disable_slot(struct slot *p_slot) |
| 557 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | u8 getstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | if (!p_slot->ctrl) |
| 562 | return 1; |
| 563 | |
| 564 | /* Check to see if (latch closed, card present, power on) */ |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 565 | mutex_lock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 567 | if (!HP_SUPR_RM(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 569 | if (ret || !getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 570 | info("%s: no adapter on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 571 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 572 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 573 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 577 | if (MRL_SENS(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 579 | if (ret || getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 580 | info("%s: latch open on slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 581 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 582 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 583 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 587 | if (POWER_CTRL(p_slot->ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 589 | if (ret || !getstatus) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 590 | info("%s: already disabled slot(%s)\n", __func__, |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 591 | p_slot->name); |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 592 | mutex_unlock(&p_slot->ctrl->crit_sect); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 593 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 597 | ret = remove_board(p_slot); |
| 598 | update_slot_info(p_slot); |
Kenji Kaneshige | dd5619c | 2006-09-22 10:17:29 -0700 | [diff] [blame] | 599 | |
| 600 | mutex_unlock(&p_slot->ctrl->crit_sect); |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 601 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 604 | int pciehp_sysfs_enable_slot(struct slot *p_slot) |
| 605 | { |
| 606 | int retval = -ENODEV; |
| 607 | |
| 608 | mutex_lock(&p_slot->lock); |
| 609 | switch (p_slot->state) { |
| 610 | case BLINKINGON_STATE: |
| 611 | cancel_delayed_work(&p_slot->work); |
| 612 | case STATIC_STATE: |
| 613 | p_slot->state = POWERON_STATE; |
| 614 | mutex_unlock(&p_slot->lock); |
| 615 | retval = pciehp_enable_slot(p_slot); |
| 616 | mutex_lock(&p_slot->lock); |
| 617 | p_slot->state = STATIC_STATE; |
| 618 | break; |
| 619 | case POWERON_STATE: |
| 620 | info("Slot %s is already in powering on state\n", |
| 621 | p_slot->name); |
| 622 | break; |
| 623 | case BLINKINGOFF_STATE: |
| 624 | case POWEROFF_STATE: |
| 625 | info("Already enabled on slot %s\n", p_slot->name); |
| 626 | break; |
| 627 | default: |
| 628 | err("Not a valid state on slot %s\n", p_slot->name); |
| 629 | break; |
| 630 | } |
| 631 | mutex_unlock(&p_slot->lock); |
| 632 | |
| 633 | return retval; |
| 634 | } |
| 635 | |
| 636 | int pciehp_sysfs_disable_slot(struct slot *p_slot) |
| 637 | { |
| 638 | int retval = -ENODEV; |
| 639 | |
| 640 | mutex_lock(&p_slot->lock); |
| 641 | switch (p_slot->state) { |
| 642 | case BLINKINGOFF_STATE: |
| 643 | cancel_delayed_work(&p_slot->work); |
| 644 | case STATIC_STATE: |
| 645 | p_slot->state = POWEROFF_STATE; |
| 646 | mutex_unlock(&p_slot->lock); |
| 647 | retval = pciehp_disable_slot(p_slot); |
| 648 | mutex_lock(&p_slot->lock); |
| 649 | p_slot->state = STATIC_STATE; |
| 650 | break; |
| 651 | case POWEROFF_STATE: |
| 652 | info("Slot %s is already in powering off state\n", |
| 653 | p_slot->name); |
| 654 | break; |
| 655 | case BLINKINGON_STATE: |
| 656 | case POWERON_STATE: |
| 657 | info("Already disabled on slot %s\n", p_slot->name); |
| 658 | break; |
| 659 | default: |
| 660 | err("Not a valid state on slot %s\n", p_slot->name); |
| 661 | break; |
| 662 | } |
| 663 | mutex_unlock(&p_slot->lock); |
| 664 | |
| 665 | return retval; |
| 666 | } |