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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/pci.h> |
| 35 | #include "../pci.h" |
| 36 | #include "pciehp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 38 | static void interrupt_event_handler(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Bjorn Helgaas | 4f092fe | 2015-06-14 21:35:13 -0500 | [diff] [blame] | 40 | void pciehp_queue_interrupt_event(struct slot *p_slot, u32 event_type) |
Kenji Kaneshige | 49ed2b4 | 2006-09-22 10:17:10 -0700 | [diff] [blame] | 41 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 42 | struct event_info *info; |
| 43 | |
| 44 | info = kmalloc(sizeof(*info), GFP_ATOMIC); |
Bjorn Helgaas | 7d852b6 | 2015-06-14 21:27:52 -0500 | [diff] [blame] | 45 | if (!info) { |
| 46 | ctrl_err(p_slot->ctrl, "dropped event %d (ENOMEM)\n", event_type); |
| 47 | return; |
| 48 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 49 | |
Bjorn Helgaas | 7d852b6 | 2015-06-14 21:27:52 -0500 | [diff] [blame] | 50 | INIT_WORK(&info->work, interrupt_event_handler); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 51 | info->event_type = event_type; |
| 52 | info->p_slot = p_slot; |
Yijing Wang | c2be6f9 | 2013-01-11 10:15:54 +0800 | [diff] [blame] | 53 | queue_work(p_slot->wq, &info->work); |
Kenji Kaneshige | 49ed2b4 | 2006-09-22 10:17:10 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 56 | /* The following routines constitute the bulk of the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | hotplug controller logic |
| 58 | */ |
| 59 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 60 | static void set_slot_off(struct controller *ctrl, struct slot *pslot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* 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] | 63 | if (POWER_CTRL(ctrl)) { |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 64 | pciehp_power_off_slot(pslot); |
| 65 | |
Kenji Kaneshige | c7b4fee | 2008-10-24 14:26:35 +0900 | [diff] [blame] | 66 | /* |
| 67 | * After turning power off, we must wait for at least 1 second |
| 68 | * before taking any action that relies on power having been |
| 69 | * removed from the slot/adapter. |
| 70 | */ |
| 71 | msleep(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 74 | pciehp_green_led_off(pslot); |
| 75 | pciehp_set_attention_status(pslot, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /** |
| 79 | * board_added - Called after a board has been added to the system. |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 80 | * @p_slot: &slot where board is added |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 82 | * Turns power on for the board. |
| 83 | * Configures board. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 85 | static int board_added(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 87 | int retval = 0; |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 88 | struct controller *ctrl = p_slot->ctrl; |
Kenji Kaneshige | 385e249 | 2009-09-15 17:30:14 +0900 | [diff] [blame] | 89 | struct pci_bus *parent = ctrl->pcie->port->subordinate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 91 | if (POWER_CTRL(ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* Power on slot */ |
Kenji Kaneshige | 82a9e79 | 2009-09-15 17:30:48 +0900 | [diff] [blame] | 93 | retval = pciehp_power_on_slot(p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 94 | if (retval) |
| 95 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 97 | |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 98 | pciehp_green_led_blink(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 100 | /* Check link training status */ |
Kenji Kaneshige | 82a9e79 | 2009-09-15 17:30:48 +0900 | [diff] [blame] | 101 | retval = pciehp_check_link_status(ctrl); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 102 | if (retval) { |
Taku Izumi | 18b341b | 2008-10-23 11:47:32 +0900 | [diff] [blame] | 103 | ctrl_err(ctrl, "Failed to check link status\n"); |
Kenji Kaneshige | 5651c48 | 2009-11-13 15:14:10 +0900 | [diff] [blame] | 104 | goto err_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* Check for a power fault */ |
Kenji Kaneshige | 5651c48 | 2009-11-13 15:14:10 +0900 | [diff] [blame] | 108 | if (ctrl->power_fault_detected || pciehp_query_power_fault(p_slot)) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 109 | ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(p_slot)); |
Kenji Kaneshige | d9fb42a8 | 2009-09-15 17:33:30 +0900 | [diff] [blame] | 110 | retval = -EIO; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 111 | goto err_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 114 | retval = pciehp_configure_device(p_slot); |
| 115 | if (retval) { |
Kenji Kaneshige | d689f7e | 2009-09-15 17:26:56 +0900 | [diff] [blame] | 116 | ctrl_err(ctrl, "Cannot add device at %04x:%02x:00\n", |
| 117 | pci_domain_nr(parent), parent->number); |
Yijing Wang | 50277c8 | 2014-02-11 17:36:51 -0700 | [diff] [blame] | 118 | if (retval != -EEXIST) |
| 119 | goto err_exit; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 122 | pciehp_green_led_on(p_slot); |
Keith Busch | 8b7c8b4 | 2016-08-03 17:29:45 -0600 | [diff] [blame] | 123 | pciehp_set_attention_status(p_slot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return 0; |
rajesh.shah@intel.com | 71b720c | 2005-10-31 16:20:06 -0800 | [diff] [blame] | 125 | |
| 126 | err_exit: |
| 127 | set_slot_off(ctrl, p_slot); |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 128 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 132 | * remove_board - Turns off slot and LEDs |
| 133 | * @p_slot: slot where board is being removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | */ |
rajesh.shah@intel.com | ed6cbcf | 2005-10-31 16:20:09 -0800 | [diff] [blame] | 135 | static int remove_board(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 137 | int retval; |
rajesh.shah@intel.com | ca22a5e | 2005-10-31 16:20:08 -0800 | [diff] [blame] | 138 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Kenji Kaneshige | 44ef4ce | 2006-12-21 17:01:09 -0800 | [diff] [blame] | 140 | retval = pciehp_unconfigure_device(p_slot); |
| 141 | if (retval) |
| 142 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 144 | if (POWER_CTRL(ctrl)) { |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 145 | pciehp_power_off_slot(p_slot); |
| 146 | |
Kenji Kaneshige | c7b4fee | 2008-10-24 14:26:35 +0900 | [diff] [blame] | 147 | /* |
| 148 | * After turning power off, we must wait for at least 1 second |
| 149 | * before taking any action that relies on power having been |
| 150 | * removed from the slot/adapter. |
| 151 | */ |
| 152 | msleep(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Kenji Kaneshige | 82a9e79 | 2009-09-15 17:30:48 +0900 | [diff] [blame] | 155 | /* turn off Green LED */ |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 156 | pciehp_green_led_off(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 160 | struct power_work_info { |
| 161 | struct slot *p_slot; |
| 162 | struct work_struct work; |
Rajat Jain | c4f2f5e | 2014-02-04 18:30:56 -0800 | [diff] [blame] | 163 | unsigned int req; |
| 164 | #define DISABLE_REQ 0 |
| 165 | #define ENABLE_REQ 1 |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 166 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 169 | * pciehp_power_thread - handle pushbutton events |
| 170 | * @work: &struct work_struct describing work to be done |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 172 | * Scheduled procedure to handle blocking stuff for the pushbuttons. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | * Handles all pending events and exits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | */ |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 175 | static void pciehp_power_thread(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 177 | struct power_work_info *info = |
| 178 | container_of(work, struct power_work_info, work); |
| 179 | struct slot *p_slot = info->p_slot; |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 180 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Rajat Jain | c4f2f5e | 2014-02-04 18:30:56 -0800 | [diff] [blame] | 182 | switch (info->req) { |
| 183 | case DISABLE_REQ: |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 184 | mutex_lock(&p_slot->hotplug_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | pciehp_disable_slot(p_slot); |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 186 | mutex_unlock(&p_slot->hotplug_lock); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 187 | mutex_lock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | p_slot->state = STATIC_STATE; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 189 | mutex_unlock(&p_slot->lock); |
Rajat Jain | c4f2f5e | 2014-02-04 18:30:56 -0800 | [diff] [blame] | 190 | break; |
| 191 | case ENABLE_REQ: |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 192 | mutex_lock(&p_slot->hotplug_lock); |
| 193 | ret = pciehp_enable_slot(p_slot); |
| 194 | mutex_unlock(&p_slot->hotplug_lock); |
| 195 | if (ret) |
Kenji Kaneshige | 82a9e79 | 2009-09-15 17:30:48 +0900 | [diff] [blame] | 196 | pciehp_green_led_off(p_slot); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 197 | mutex_lock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | p_slot->state = STATIC_STATE; |
Rajat Jain | c4f2f5e | 2014-02-04 18:30:56 -0800 | [diff] [blame] | 199 | mutex_unlock(&p_slot->lock); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 200 | break; |
| 201 | default: |
| 202 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 205 | kfree(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 208 | static void pciehp_queue_power_work(struct slot *p_slot, int req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 210 | struct power_work_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 212 | p_slot->state = (req == ENABLE_REQ) ? POWERON_STATE : POWEROFF_STATE; |
| 213 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 214 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 215 | if (!info) { |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 216 | ctrl_err(p_slot->ctrl, "no memory to queue %s request\n", |
| 217 | (req == ENABLE_REQ) ? "poweron" : "poweroff"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return; |
| 219 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 220 | info->p_slot = p_slot; |
| 221 | INIT_WORK(&info->work, pciehp_power_thread); |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 222 | info->req = req; |
| 223 | queue_work(p_slot->wq, &info->work); |
| 224 | } |
| 225 | |
| 226 | void pciehp_queue_pushbutton_work(struct work_struct *work) |
| 227 | { |
| 228 | struct slot *p_slot = container_of(work, struct slot, work.work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 230 | mutex_lock(&p_slot->lock); |
| 231 | switch (p_slot->state) { |
| 232 | case BLINKINGOFF_STATE: |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 233 | pciehp_queue_power_work(p_slot, DISABLE_REQ); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 234 | break; |
| 235 | case BLINKINGON_STATE: |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 236 | pciehp_queue_power_work(p_slot, ENABLE_REQ); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 237 | break; |
| 238 | default: |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 239 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 241 | mutex_unlock(&p_slot->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 244 | /* |
| 245 | * Note: This function must be called with slot->lock held |
| 246 | */ |
| 247 | static void handle_button_press_event(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 249 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | u8 getstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 252 | switch (p_slot->state) { |
| 253 | case STATIC_STATE: |
Kenji Kaneshige | 82a9e79 | 2009-09-15 17:30:48 +0900 | [diff] [blame] | 254 | pciehp_get_power_status(p_slot, &getstatus); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 255 | if (getstatus) { |
| 256 | p_slot->state = BLINKINGOFF_STATE; |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 257 | ctrl_info(ctrl, "Slot(%s): Powering off due to button press\n", |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 258 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 259 | } else { |
| 260 | p_slot->state = BLINKINGON_STATE; |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 261 | ctrl_info(ctrl, "Slot(%s) Powering on due to button press\n", |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 262 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 263 | } |
| 264 | /* blink green LED and turn off amber */ |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 265 | pciehp_green_led_blink(p_slot); |
| 266 | pciehp_set_attention_status(p_slot, 0); |
Yijing Wang | c2be6f9 | 2013-01-11 10:15:54 +0800 | [diff] [blame] | 267 | queue_delayed_work(p_slot->wq, &p_slot->work, 5*HZ); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 268 | break; |
| 269 | case BLINKINGOFF_STATE: |
| 270 | case BLINKINGON_STATE: |
| 271 | /* |
| 272 | * Cancel if we are still blinking; this means that we |
| 273 | * press the attention again before the 5 sec. limit |
| 274 | * expires to cancel hot-add or hot-remove |
| 275 | */ |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 276 | ctrl_info(ctrl, "Slot(%s): Button cancel\n", slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 277 | cancel_delayed_work(&p_slot->work); |
Bjorn Helgaas | 9cad7f5 | 2014-02-11 15:26:29 -0700 | [diff] [blame] | 278 | if (p_slot->state == BLINKINGOFF_STATE) |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 279 | pciehp_green_led_on(p_slot); |
Bjorn Helgaas | 9cad7f5 | 2014-02-11 15:26:29 -0700 | [diff] [blame] | 280 | else |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 281 | pciehp_green_led_off(p_slot); |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 282 | pciehp_set_attention_status(p_slot, 0); |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 283 | ctrl_info(ctrl, "Slot(%s): Action canceled due to button press\n", |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 284 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 285 | p_slot->state = STATIC_STATE; |
| 286 | break; |
| 287 | case POWEROFF_STATE: |
| 288 | case POWERON_STATE: |
| 289 | /* |
| 290 | * Ignore if the slot is on power-on or power-off state; |
| 291 | * this means that the previous attention button action |
| 292 | * to hot-add or hot-remove is undergoing |
| 293 | */ |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 294 | ctrl_info(ctrl, "Slot(%s): Button ignored\n", |
| 295 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 296 | break; |
| 297 | default: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 298 | ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n", |
| 299 | slot_name(p_slot), p_slot->state); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 300 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 304 | /* |
| 305 | * Note: This function must be called with slot->lock held |
| 306 | */ |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 307 | static void handle_link_event(struct slot *p_slot, u32 event) |
| 308 | { |
| 309 | struct controller *ctrl = p_slot->ctrl; |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 310 | |
| 311 | switch (p_slot->state) { |
| 312 | case BLINKINGON_STATE: |
| 313 | case BLINKINGOFF_STATE: |
| 314 | cancel_delayed_work(&p_slot->work); |
| 315 | /* Fall through */ |
| 316 | case STATIC_STATE: |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 317 | pciehp_queue_power_work(p_slot, event == INT_LINK_UP ? |
| 318 | ENABLE_REQ : DISABLE_REQ); |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 319 | break; |
| 320 | case POWERON_STATE: |
| 321 | if (event == INT_LINK_UP) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 322 | ctrl_info(ctrl, "Slot(%s): Link Up event ignored; already powering on\n", |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 323 | slot_name(p_slot)); |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 324 | } else { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 325 | ctrl_info(ctrl, "Slot(%s): Link Down event queued; currently getting powered on\n", |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 326 | slot_name(p_slot)); |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 327 | pciehp_queue_power_work(p_slot, DISABLE_REQ); |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 328 | } |
| 329 | break; |
| 330 | case POWEROFF_STATE: |
| 331 | if (event == INT_LINK_UP) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 332 | ctrl_info(ctrl, "Slot(%s): Link Up event queued; currently getting powered off\n", |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 333 | slot_name(p_slot)); |
Guenter Roeck | bee6775 | 2015-10-12 12:10:12 -0700 | [diff] [blame] | 334 | pciehp_queue_power_work(p_slot, ENABLE_REQ); |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 335 | } else { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 336 | ctrl_info(ctrl, "Slot(%s): Link Down event ignored; already powering off\n", |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 337 | slot_name(p_slot)); |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 338 | } |
| 339 | break; |
| 340 | default: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 341 | ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n", |
| 342 | slot_name(p_slot), p_slot->state); |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 343 | break; |
| 344 | } |
| 345 | } |
| 346 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 347 | static void interrupt_event_handler(struct work_struct *work) |
| 348 | { |
| 349 | struct event_info *info = container_of(work, struct event_info, work); |
| 350 | struct slot *p_slot = info->p_slot; |
| 351 | struct controller *ctrl = p_slot->ctrl; |
| 352 | |
| 353 | mutex_lock(&p_slot->lock); |
| 354 | switch (info->event_type) { |
| 355 | case INT_BUTTON_PRESS: |
| 356 | handle_button_press_event(p_slot); |
| 357 | break; |
| 358 | case INT_POWER_FAULT: |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 359 | if (!POWER_CTRL(ctrl)) |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 360 | break; |
Bjorn Helgaas | af9ab79 | 2013-12-15 17:23:54 -0700 | [diff] [blame] | 361 | pciehp_set_attention_status(p_slot, 1); |
| 362 | pciehp_green_led_off(p_slot); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 363 | break; |
| 364 | case INT_PRESENCE_ON: |
Mayurkumar Patel | 69bd3c5 | 2016-08-23 08:58:51 +0000 | [diff] [blame] | 365 | pciehp_queue_power_work(p_slot, ENABLE_REQ); |
Rajat Jain | 2b3940b | 2014-02-18 18:53:19 -0800 | [diff] [blame] | 366 | break; |
| 367 | case INT_PRESENCE_OFF: |
| 368 | /* |
| 369 | * Regardless of surprise capability, we need to |
| 370 | * definitely remove a card that has been pulled out! |
| 371 | */ |
Mayurkumar Patel | 69bd3c5 | 2016-08-23 08:58:51 +0000 | [diff] [blame] | 372 | pciehp_queue_power_work(p_slot, DISABLE_REQ); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 373 | break; |
Rajat Jain | e48f1b6 | 2014-02-04 18:29:10 -0800 | [diff] [blame] | 374 | case INT_LINK_UP: |
| 375 | case INT_LINK_DOWN: |
| 376 | handle_link_event(p_slot, info->event_type); |
| 377 | break; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 378 | default: |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 379 | break; |
| 380 | } |
| 381 | mutex_unlock(&p_slot->lock); |
| 382 | |
| 383 | kfree(info); |
| 384 | } |
| 385 | |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 386 | /* |
| 387 | * Note: This function must be called with slot->hotplug_lock held |
| 388 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | int pciehp_enable_slot(struct slot *p_slot) |
| 390 | { |
| 391 | u8 getstatus = 0; |
Taku Izumi | 7f2feec | 2008-09-05 12:11:26 +0900 | [diff] [blame] | 392 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 394 | pciehp_get_adapter_status(p_slot, &getstatus); |
| 395 | if (!getstatus) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 396 | ctrl_info(ctrl, "Slot(%s): No adapter\n", slot_name(p_slot)); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 397 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 399 | if (MRL_SENS(p_slot->ctrl)) { |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 400 | pciehp_get_latch_status(p_slot, &getstatus); |
| 401 | if (getstatus) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 402 | ctrl_info(ctrl, "Slot(%s): Latch open\n", |
Taku Izumi | 18b341b | 2008-10-23 11:47:32 +0900 | [diff] [blame] | 403 | slot_name(p_slot)); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 404 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | } |
Kenji Kaneshige | 36ed27b | 2007-08-09 16:09:36 -0700 | [diff] [blame] | 407 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 408 | if (POWER_CTRL(p_slot->ctrl)) { |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 409 | pciehp_get_power_status(p_slot, &getstatus); |
| 410 | if (getstatus) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 411 | ctrl_info(ctrl, "Slot(%s): Already enabled\n", |
Taku Izumi | 18b341b | 2008-10-23 11:47:32 +0900 | [diff] [blame] | 412 | slot_name(p_slot)); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 413 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Bjorn Helgaas | 29a654e | 2016-09-07 17:50:30 -0500 | [diff] [blame] | 417 | return board_added(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 420 | /* |
| 421 | * Note: This function must be called with slot->hotplug_lock held |
| 422 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | int pciehp_disable_slot(struct slot *p_slot) |
| 424 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | u8 getstatus = 0; |
Taku Izumi | 7f2feec | 2008-09-05 12:11:26 +0900 | [diff] [blame] | 426 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | if (!p_slot->ctrl) |
| 429 | return 1; |
| 430 | |
Kenji Kaneshige | ae416e6 | 2008-04-25 14:39:06 -0700 | [diff] [blame] | 431 | if (POWER_CTRL(p_slot->ctrl)) { |
Bjorn Helgaas | 6dae620 | 2013-12-14 13:06:16 -0700 | [diff] [blame] | 432 | pciehp_get_power_status(p_slot, &getstatus); |
| 433 | if (!getstatus) { |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 434 | ctrl_info(ctrl, "Slot(%s): Already disabled\n", |
Taku Izumi | 18b341b | 2008-10-23 11:47:32 +0900 | [diff] [blame] | 435 | slot_name(p_slot)); |
Kenji Kaneshige | c9d86d7 | 2006-09-19 17:04:33 -0700 | [diff] [blame] | 436 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Kenji Kaneshige | 445f798 | 2009-10-05 17:42:59 +0900 | [diff] [blame] | 440 | return remove_board(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 443 | int pciehp_sysfs_enable_slot(struct slot *p_slot) |
| 444 | { |
| 445 | int retval = -ENODEV; |
Taku Izumi | 7f2feec | 2008-09-05 12:11:26 +0900 | [diff] [blame] | 446 | struct controller *ctrl = p_slot->ctrl; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 447 | |
| 448 | mutex_lock(&p_slot->lock); |
| 449 | switch (p_slot->state) { |
| 450 | case BLINKINGON_STATE: |
| 451 | cancel_delayed_work(&p_slot->work); |
| 452 | case STATIC_STATE: |
| 453 | p_slot->state = POWERON_STATE; |
| 454 | mutex_unlock(&p_slot->lock); |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 455 | mutex_lock(&p_slot->hotplug_lock); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 456 | retval = pciehp_enable_slot(p_slot); |
Rajat Jain | 50b52fd | 2014-02-04 18:31:11 -0800 | [diff] [blame] | 457 | mutex_unlock(&p_slot->hotplug_lock); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 458 | mutex_lock(&p_slot->lock); |
| 459 | p_slot->state = STATIC_STATE; |
| 460 | break; |
| 461 | case POWERON_STATE: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 462 | ctrl_info(ctrl, "Slot(%s): Already in powering on state\n", |
Alex Chiang | e1acb24 | 2008-10-20 17:41:38 -0600 | [diff] [blame] | 463 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 464 | break; |
| 465 | case BLINKINGOFF_STATE: |
| 466 | case POWEROFF_STATE: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 467 | ctrl_info(ctrl, "Slot(%s): Already enabled\n", |
Alex Chiang | e1acb24 | 2008-10-20 17:41:38 -0600 | [diff] [blame] | 468 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 469 | break; |
| 470 | default: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 471 | ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", |
| 472 | slot_name(p_slot), p_slot->state); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 473 | break; |
| 474 | } |
| 475 | mutex_unlock(&p_slot->lock); |
| 476 | |
| 477 | return retval; |
| 478 | } |
| 479 | |
| 480 | int pciehp_sysfs_disable_slot(struct slot *p_slot) |
| 481 | { |
| 482 | int retval = -ENODEV; |
Taku Izumi | 7f2feec | 2008-09-05 12:11:26 +0900 | [diff] [blame] | 483 | struct controller *ctrl = p_slot->ctrl; |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 484 | |
| 485 | mutex_lock(&p_slot->lock); |
| 486 | switch (p_slot->state) { |
| 487 | case BLINKINGOFF_STATE: |
| 488 | cancel_delayed_work(&p_slot->work); |
| 489 | case STATIC_STATE: |
| 490 | p_slot->state = POWEROFF_STATE; |
| 491 | mutex_unlock(&p_slot->lock); |
Guenter Roeck | 64609ea | 2015-11-01 13:58:40 -0800 | [diff] [blame] | 492 | mutex_lock(&p_slot->hotplug_lock); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 493 | retval = pciehp_disable_slot(p_slot); |
Guenter Roeck | 64609ea | 2015-11-01 13:58:40 -0800 | [diff] [blame] | 494 | mutex_unlock(&p_slot->hotplug_lock); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 495 | mutex_lock(&p_slot->lock); |
| 496 | p_slot->state = STATIC_STATE; |
| 497 | break; |
| 498 | case POWEROFF_STATE: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 499 | ctrl_info(ctrl, "Slot(%s): Already in powering off state\n", |
Alex Chiang | e1acb24 | 2008-10-20 17:41:38 -0600 | [diff] [blame] | 500 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 501 | break; |
| 502 | case BLINKINGON_STATE: |
| 503 | case POWERON_STATE: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 504 | ctrl_info(ctrl, "Slot(%s): Already disabled\n", |
Alex Chiang | e1acb24 | 2008-10-20 17:41:38 -0600 | [diff] [blame] | 505 | slot_name(p_slot)); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 506 | break; |
| 507 | default: |
Bjorn Helgaas | 6e49b304 | 2016-09-08 15:19:58 -0500 | [diff] [blame] | 508 | ctrl_err(ctrl, "Slot(%s): Invalid state %#x\n", |
| 509 | slot_name(p_slot), p_slot->state); |
Kenji Kaneshige | 5d386e1 | 2007-03-06 15:02:26 -0800 | [diff] [blame] | 510 | break; |
| 511 | } |
| 512 | mutex_unlock(&p_slot->lock); |
| 513 | |
| 514 | return retval; |
| 515 | } |