Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Standard Hot Plug Controller Driver |
| 3 | * |
| 4 | * Copyright (C) 1995,2001 Compaq Computer Corporation |
| 5 | * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) |
| 6 | * Copyright (C) 2001 IBM 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> |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 35 | #include "../pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "shpchp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static void interrupt_event_handler(struct controller *ctrl); |
| 39 | |
| 40 | static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */ |
| 41 | static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */ |
| 42 | static int event_finished; |
| 43 | static unsigned long pushbutton_pending; /* = 0 */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) |
| 46 | { |
| 47 | struct controller *ctrl = (struct controller *) inst_id; |
| 48 | struct slot *p_slot; |
| 49 | u8 rc = 0; |
| 50 | u8 getstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | struct event_info *taskInfo; |
| 52 | |
| 53 | /* Attention Button Change */ |
| 54 | dbg("shpchp: Attention button interrupt received.\n"); |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* This is the structure that tells the worker thread what to do */ |
| 57 | taskInfo = &(ctrl->event_queue[ctrl->next_event]); |
| 58 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
| 59 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 60 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 62 | |
| 63 | ctrl->next_event = (ctrl->next_event + 1) % 10; |
| 64 | taskInfo->hp_slot = hp_slot; |
| 65 | |
| 66 | rc++; |
| 67 | |
| 68 | /* |
| 69 | * Button pressed - See if need to TAKE ACTION!!! |
| 70 | */ |
| 71 | info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot); |
| 72 | taskInfo->event_type = INT_BUTTON_PRESS; |
| 73 | |
| 74 | if ((p_slot->state == BLINKINGON_STATE) |
| 75 | || (p_slot->state == BLINKINGOFF_STATE)) { |
| 76 | /* Cancel if we are still blinking; this means that we press the |
| 77 | * attention again before the 5 sec. limit expires to cancel hot-add |
| 78 | * or hot-remove |
| 79 | */ |
| 80 | taskInfo->event_type = INT_BUTTON_CANCEL; |
| 81 | info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot); |
| 82 | } else if ((p_slot->state == POWERON_STATE) |
| 83 | || (p_slot->state == POWEROFF_STATE)) { |
| 84 | /* Ignore if the slot is on power-on or power-off state; this |
| 85 | * means that the previous attention button action to hot-add or |
| 86 | * hot-remove is undergoing |
| 87 | */ |
| 88 | taskInfo->event_type = INT_BUTTON_IGNORE; |
| 89 | info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot); |
| 90 | } |
| 91 | |
| 92 | if (rc) |
| 93 | up(&event_semaphore); /* signal event thread that new event is posted */ |
| 94 | |
| 95 | return 0; |
| 96 | |
| 97 | } |
| 98 | |
| 99 | u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id) |
| 100 | { |
| 101 | struct controller *ctrl = (struct controller *) inst_id; |
| 102 | struct slot *p_slot; |
| 103 | u8 rc = 0; |
| 104 | u8 getstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | struct event_info *taskInfo; |
| 106 | |
| 107 | /* Switch Change */ |
| 108 | dbg("shpchp: Switch interrupt received.\n"); |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* This is the structure that tells the worker thread |
| 111 | * what to do |
| 112 | */ |
| 113 | taskInfo = &(ctrl->event_queue[ctrl->next_event]); |
| 114 | ctrl->next_event = (ctrl->next_event + 1) % 10; |
| 115 | taskInfo->hp_slot = hp_slot; |
| 116 | |
| 117 | rc++; |
| 118 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 119 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 121 | dbg("%s: Card present %x Power status %x\n", __FUNCTION__, |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 122 | p_slot->presence_save, p_slot->pwr_save); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | if (getstatus) { |
| 125 | /* |
| 126 | * Switch opened |
| 127 | */ |
| 128 | info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | taskInfo->event_type = INT_SWITCH_OPEN; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 130 | if (p_slot->pwr_save && p_slot->presence_save) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | taskInfo->event_type = INT_POWER_FAULT; |
| 132 | err("Surprise Removal of card\n"); |
| 133 | } |
| 134 | } else { |
| 135 | /* |
| 136 | * Switch closed |
| 137 | */ |
| 138 | info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | taskInfo->event_type = INT_SWITCH_CLOSE; |
| 140 | } |
| 141 | |
| 142 | if (rc) |
| 143 | up(&event_semaphore); /* signal event thread that new event is posted */ |
| 144 | |
| 145 | return rc; |
| 146 | } |
| 147 | |
| 148 | u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id) |
| 149 | { |
| 150 | struct controller *ctrl = (struct controller *) inst_id; |
| 151 | struct slot *p_slot; |
| 152 | u8 rc = 0; |
| 153 | /*u8 temp_byte;*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | struct event_info *taskInfo; |
| 155 | |
| 156 | /* Presence Change */ |
| 157 | dbg("shpchp: Presence/Notify input change.\n"); |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* This is the structure that tells the worker thread |
| 160 | * what to do |
| 161 | */ |
| 162 | taskInfo = &(ctrl->event_queue[ctrl->next_event]); |
| 163 | ctrl->next_event = (ctrl->next_event + 1) % 10; |
| 164 | taskInfo->hp_slot = hp_slot; |
| 165 | |
| 166 | rc++; |
| 167 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
| 168 | |
| 169 | /* |
| 170 | * Save the presence state |
| 171 | */ |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 172 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
| 173 | if (p_slot->presence_save) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* |
| 175 | * Card Present |
| 176 | */ |
| 177 | info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot); |
| 178 | taskInfo->event_type = INT_PRESENCE_ON; |
| 179 | } else { |
| 180 | /* |
| 181 | * Not Present |
| 182 | */ |
| 183 | info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot); |
| 184 | taskInfo->event_type = INT_PRESENCE_OFF; |
| 185 | } |
| 186 | |
| 187 | if (rc) |
| 188 | up(&event_semaphore); /* signal event thread that new event is posted */ |
| 189 | |
| 190 | return rc; |
| 191 | } |
| 192 | |
| 193 | u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) |
| 194 | { |
| 195 | struct controller *ctrl = (struct controller *) inst_id; |
| 196 | struct slot *p_slot; |
| 197 | u8 rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | struct event_info *taskInfo; |
| 199 | |
| 200 | /* Power fault */ |
| 201 | dbg("shpchp: Power fault interrupt received.\n"); |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* This is the structure that tells the worker thread |
| 204 | * what to do |
| 205 | */ |
| 206 | taskInfo = &(ctrl->event_queue[ctrl->next_event]); |
| 207 | ctrl->next_event = (ctrl->next_event + 1) % 10; |
| 208 | taskInfo->hp_slot = hp_slot; |
| 209 | |
| 210 | rc++; |
| 211 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
| 212 | |
| 213 | if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) { |
| 214 | /* |
| 215 | * Power fault Cleared |
| 216 | */ |
| 217 | info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot); |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 218 | p_slot->status = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | taskInfo->event_type = INT_POWER_FAULT_CLEAR; |
| 220 | } else { |
| 221 | /* |
| 222 | * Power fault |
| 223 | */ |
| 224 | info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot); |
| 225 | taskInfo->event_type = INT_POWER_FAULT; |
| 226 | /* set power fault status for this board */ |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 227 | p_slot->status = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | info("power fault bit %x set\n", hp_slot); |
| 229 | } |
| 230 | if (rc) |
| 231 | up(&event_semaphore); /* signal event thread that new event is posted */ |
| 232 | |
| 233 | return rc; |
| 234 | } |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* The following routines constitute the bulk of the |
| 237 | hotplug controller logic |
| 238 | */ |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 239 | static int change_bus_speed(struct controller *ctrl, struct slot *p_slot, |
| 240 | enum pci_bus_speed speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 242 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | dbg("%s: change to speed %d\n", __FUNCTION__, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) { |
| 246 | err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return WRONG_BUS_FREQUENCY; |
| 248 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return rc; |
| 250 | } |
| 251 | |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 252 | static int fix_bus_speed(struct controller *ctrl, struct slot *pslot, |
| 253 | u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp, |
| 254 | enum pci_bus_speed msp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 256 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | if (flag != 0) { /* Other slots on the same bus are occupied */ |
| 259 | if ( asp < bsp ) { |
| 260 | err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bsp, asp); |
| 261 | return WRONG_BUS_FREQUENCY; |
| 262 | } |
| 263 | } else { |
| 264 | /* Other slots on the same bus are empty */ |
| 265 | if (msp == bsp) { |
| 266 | /* if adapter_speed >= bus_speed, do nothing */ |
| 267 | if (asp < bsp) { |
| 268 | /* |
| 269 | * Try to lower bus speed to accommodate the adapter if other slots |
| 270 | * on the same controller are empty |
| 271 | */ |
| 272 | if ((rc = change_bus_speed(ctrl, pslot, asp))) |
| 273 | return rc; |
| 274 | } |
| 275 | } else { |
| 276 | if (asp < msp) { |
| 277 | if ((rc = change_bus_speed(ctrl, pslot, asp))) |
| 278 | return rc; |
| 279 | } else { |
| 280 | if ((rc = change_bus_speed(ctrl, pslot, msp))) |
| 281 | return rc; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return rc; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * board_added - Called after a board has been added to the system. |
| 290 | * |
| 291 | * Turns power on for the board |
| 292 | * Configures board |
| 293 | * |
| 294 | */ |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 295 | static int board_added(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | u8 hp_slot; |
| 298 | u8 slots_not_empty = 0; |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 299 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed; |
| 301 | u8 pi, mode; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 302 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 304 | hp_slot = p_slot->device - ctrl->slot_device_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 306 | dbg("%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n", |
| 307 | __FUNCTION__, p_slot->device, |
| 308 | ctrl->slot_device_offset, hp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | /* Power on slot without connecting to bus */ |
| 311 | rc = p_slot->hpc_ops->power_on_slot(p_slot); |
| 312 | if (rc) { |
| 313 | err("%s: Failed to power on slot\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return -1; |
| 315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) { |
| 318 | if (slots_not_empty) |
| 319 | return WRONG_BUS_FREQUENCY; |
| 320 | |
| 321 | if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) { |
| 322 | err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return WRONG_BUS_FREQUENCY; |
| 324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | /* turn on board, blink green LED, turn off Amber LED */ |
| 327 | if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { |
| 328 | err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return rc; |
| 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed); |
| 334 | /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */ |
| 335 | /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */ |
| 336 | /* 0xd = PCI-X 133 Mhz 533 */ |
| 337 | /* This encoding is different from the one used in cur_bus_speed & */ |
| 338 | /* max_bus_speed */ |
| 339 | |
| 340 | if (rc || adapter_speed == PCI_SPEED_UNKNOWN) { |
| 341 | err("%s: Can't get adapter speed or bus mode mismatch\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | return WRONG_BUS_FREQUENCY; |
| 343 | } |
| 344 | |
| 345 | rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bus_speed); |
| 346 | if (rc || bus_speed == PCI_SPEED_UNKNOWN) { |
| 347 | err("%s: Can't get bus operation speed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | return WRONG_BUS_FREQUENCY; |
| 349 | } |
| 350 | |
| 351 | rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed); |
| 352 | if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) { |
| 353 | err("%s: Can't get max bus operation speed\n", __FUNCTION__); |
| 354 | max_bus_speed = bus_speed; |
| 355 | } |
| 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | if ((rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi))) { |
| 358 | err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__); |
| 359 | pi = 1; |
| 360 | } |
| 361 | |
| 362 | /* Check if there are other slots or devices on the same bus */ |
| 363 | if (!list_empty(&ctrl->pci_dev->subordinate->devices)) |
| 364 | slots_not_empty = 1; |
| 365 | |
| 366 | dbg("%s: slots_not_empty %d, pi %d\n", __FUNCTION__, |
| 367 | slots_not_empty, pi); |
| 368 | dbg("adapter_speed %d, bus_speed %d, max_bus_speed %d\n", |
| 369 | adapter_speed, bus_speed, max_bus_speed); |
| 370 | |
| 371 | if (pi == 2) { |
| 372 | dbg("%s: In PI = %d\n", __FUNCTION__, pi); |
| 373 | if ((rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode))) { |
| 374 | err("%s: Can't get Mode1_ECC, set mode to 0\n", __FUNCTION__); |
| 375 | mode = 0; |
| 376 | } |
| 377 | |
| 378 | switch (adapter_speed) { |
| 379 | case PCI_SPEED_133MHz_PCIX_533: |
| 380 | case PCI_SPEED_133MHz_PCIX_266: |
| 381 | if ((bus_speed != adapter_speed) && |
| 382 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 383 | return rc; |
| 384 | break; |
| 385 | case PCI_SPEED_133MHz_PCIX_ECC: |
| 386 | case PCI_SPEED_133MHz_PCIX: |
| 387 | if (mode) { /* Bus - Mode 1 ECC */ |
| 388 | if ((bus_speed != 0x7) && |
| 389 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 390 | return rc; |
| 391 | } else { |
| 392 | if ((bus_speed != 0x4) && |
| 393 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 394 | return rc; |
| 395 | } |
| 396 | break; |
| 397 | case PCI_SPEED_66MHz_PCIX_ECC: |
| 398 | case PCI_SPEED_66MHz_PCIX: |
| 399 | if (mode) { /* Bus - Mode 1 ECC */ |
| 400 | if ((bus_speed != 0x5) && |
| 401 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 402 | return rc; |
| 403 | } else { |
| 404 | if ((bus_speed != 0x2) && |
| 405 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 406 | return rc; |
| 407 | } |
| 408 | break; |
| 409 | case PCI_SPEED_66MHz: |
| 410 | if ((bus_speed != 0x1) && |
| 411 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 412 | return rc; |
| 413 | break; |
| 414 | case PCI_SPEED_33MHz: |
| 415 | if (bus_speed > 0x0) { |
| 416 | if (slots_not_empty == 0) { |
| 417 | if ((rc = change_bus_speed(ctrl, p_slot, adapter_speed))) |
| 418 | return rc; |
| 419 | } else { |
| 420 | err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); |
| 421 | return WRONG_BUS_FREQUENCY; |
| 422 | } |
| 423 | } |
| 424 | break; |
| 425 | default: |
| 426 | err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed); |
| 427 | return WRONG_BUS_FREQUENCY; |
| 428 | } |
| 429 | } else { |
| 430 | /* If adpater_speed == bus_speed, nothing to do here */ |
| 431 | dbg("%s: In PI = %d\n", __FUNCTION__, pi); |
| 432 | if ((adapter_speed != bus_speed) && |
| 433 | ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed)))) |
| 434 | return rc; |
| 435 | } |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | /* turn on board, blink green LED, turn off Amber LED */ |
| 438 | if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { |
| 439 | err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | return rc; |
| 441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /* Wait for ~1 second */ |
Kenji Kaneshige | 68c0b67 | 2006-02-21 15:45:42 -0800 | [diff] [blame^] | 444 | msleep(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 446 | dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | /* Check for a power fault */ |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 448 | if (p_slot->status == 0xFF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* power fault occurred, but it was benign */ |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 450 | dbg("%s: power fault\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | rc = POWER_FAILURE; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 452 | p_slot->status = 0; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 453 | goto err_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 456 | if (shpchp_configure_device(p_slot)) { |
| 457 | err("Cannot add device at 0x%x:0x%x\n", p_slot->bus, |
| 458 | p_slot->device); |
| 459 | goto err_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 461 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 462 | p_slot->status = 0; |
| 463 | p_slot->is_a_board = 0x01; |
| 464 | p_slot->pwr_save = 1; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 465 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 466 | p_slot->hpc_ops->green_led_on(p_slot); |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return 0; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 469 | |
| 470 | err_exit: |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 471 | /* turn off slot, turn on Amber LED, turn off Green LED */ |
| 472 | rc = p_slot->hpc_ops->slot_disable(p_slot); |
| 473 | if (rc) { |
| 474 | err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 475 | return rc; |
| 476 | } |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 477 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 478 | return(rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | |
| 482 | /** |
| 483 | * remove_board - Turns off slot and LED's |
| 484 | * |
| 485 | */ |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 486 | static int remove_board(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 488 | struct controller *ctrl = p_slot->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | u8 hp_slot; |
rajesh.shah@intel.com | ee13833 | 2005-10-13 12:05:42 -0700 | [diff] [blame] | 490 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 492 | if (shpchp_unconfigure_device(p_slot)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return(1); |
| 494 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 495 | hp_slot = p_slot->device - ctrl->slot_device_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
| 497 | |
| 498 | dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); |
| 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | /* Change status to shutdown */ |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 501 | if (p_slot->is_a_board) |
| 502 | p_slot->status = 0x01; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | /* turn off slot, turn on Amber LED, turn off Green LED */ |
| 505 | rc = p_slot->hpc_ops->slot_disable(p_slot); |
| 506 | if (rc) { |
| 507 | err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | return rc; |
| 509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | rc = p_slot->hpc_ops->set_attention_status(p_slot, 0); |
| 512 | if (rc) { |
| 513 | err("%s: Issue of Set Attention command failed\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | return rc; |
| 515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 517 | p_slot->pwr_save = 0; |
| 518 | p_slot->is_a_board = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | |
| 524 | static void pushbutton_helper_thread (unsigned long data) |
| 525 | { |
| 526 | pushbutton_pending = data; |
| 527 | |
| 528 | up(&event_semaphore); |
| 529 | } |
| 530 | |
| 531 | |
| 532 | /** |
| 533 | * shpchp_pushbutton_thread |
| 534 | * |
| 535 | * Scheduled procedure to handle blocking stuff for the pushbuttons |
| 536 | * Handles all pending events and exits. |
| 537 | * |
| 538 | */ |
| 539 | static void shpchp_pushbutton_thread (unsigned long slot) |
| 540 | { |
| 541 | struct slot *p_slot = (struct slot *) slot; |
| 542 | u8 getstatus; |
| 543 | |
| 544 | pushbutton_pending = 0; |
| 545 | |
| 546 | if (!p_slot) { |
| 547 | dbg("%s: Error! slot NULL\n", __FUNCTION__); |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 552 | if (getstatus) { |
| 553 | p_slot->state = POWEROFF_STATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | shpchp_disable_slot(p_slot); |
| 556 | p_slot->state = STATIC_STATE; |
| 557 | } else { |
| 558 | p_slot->state = POWERON_STATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
Kenji Kaneshige | d29aadd | 2006-01-26 09:59:24 +0900 | [diff] [blame] | 560 | if (shpchp_enable_slot(p_slot)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | p_slot->hpc_ops->green_led_off(p_slot); |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | p_slot->state = STATIC_STATE; |
| 564 | } |
| 565 | |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | /* this is the main worker thread */ |
| 571 | static int event_thread(void* data) |
| 572 | { |
| 573 | struct controller *ctrl; |
| 574 | lock_kernel(); |
| 575 | daemonize("shpchpd_event"); |
| 576 | unlock_kernel(); |
| 577 | |
| 578 | while (1) { |
| 579 | dbg("!!!!event_thread sleeping\n"); |
| 580 | down_interruptible (&event_semaphore); |
| 581 | dbg("event_thread woken finished = %d\n", event_finished); |
| 582 | if (event_finished || signal_pending(current)) |
| 583 | break; |
| 584 | /* Do stuff here */ |
| 585 | if (pushbutton_pending) |
| 586 | shpchp_pushbutton_thread(pushbutton_pending); |
| 587 | else |
Kenji Kaneshige | a453456 | 2006-01-26 09:58:30 +0900 | [diff] [blame] | 588 | list_for_each_entry(ctrl, &shpchp_ctrl_list, ctrl_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | interrupt_event_handler(ctrl); |
| 590 | } |
| 591 | dbg("event_thread signals exit\n"); |
| 592 | up(&event_exit); |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | int shpchp_event_start_thread (void) |
| 597 | { |
| 598 | int pid; |
| 599 | |
| 600 | /* initialize our semaphores */ |
| 601 | init_MUTEX_LOCKED(&event_exit); |
| 602 | event_finished=0; |
| 603 | |
| 604 | init_MUTEX_LOCKED(&event_semaphore); |
| 605 | pid = kernel_thread(event_thread, NULL, 0); |
| 606 | |
| 607 | if (pid < 0) { |
| 608 | err ("Can't start up our event thread\n"); |
| 609 | return -1; |
| 610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | |
| 615 | void shpchp_event_stop_thread (void) |
| 616 | { |
| 617 | event_finished = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | up(&event_semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | down(&event_exit); |
| 620 | } |
| 621 | |
| 622 | |
| 623 | static int update_slot_info (struct slot *slot) |
| 624 | { |
| 625 | struct hotplug_slot_info *info; |
| 626 | int result; |
| 627 | |
| 628 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 629 | if (!info) |
| 630 | return -ENOMEM; |
| 631 | |
| 632 | slot->hpc_ops->get_power_status(slot, &(info->power_status)); |
| 633 | slot->hpc_ops->get_attention_status(slot, &(info->attention_status)); |
| 634 | slot->hpc_ops->get_latch_status(slot, &(info->latch_status)); |
| 635 | slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status)); |
| 636 | |
| 637 | result = pci_hp_change_slot_info(slot->hotplug_slot, info); |
| 638 | kfree (info); |
| 639 | return result; |
| 640 | } |
| 641 | |
| 642 | static void interrupt_event_handler(struct controller *ctrl) |
| 643 | { |
| 644 | int loop = 0; |
| 645 | int change = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | u8 hp_slot; |
| 647 | u8 getstatus; |
| 648 | struct slot *p_slot; |
| 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | while (change) { |
| 651 | change = 0; |
| 652 | |
| 653 | for (loop = 0; loop < 10; loop++) { |
| 654 | if (ctrl->event_queue[loop].event_type != 0) { |
| 655 | dbg("%s:loop %x event_type %x\n", __FUNCTION__, loop, |
| 656 | ctrl->event_queue[loop].event_type); |
| 657 | hp_slot = ctrl->event_queue[loop].hp_slot; |
| 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) { |
| 662 | dbg("%s: button cancel\n", __FUNCTION__); |
| 663 | del_timer(&p_slot->task_event); |
| 664 | |
| 665 | switch (p_slot->state) { |
| 666 | case BLINKINGOFF_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | p_slot->hpc_ops->green_led_on(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | break; |
| 670 | case BLINKINGON_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | p_slot->hpc_ops->green_led_off(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | break; |
| 674 | default: |
| 675 | warn("Not a valid state\n"); |
| 676 | return; |
| 677 | } |
| 678 | info(msg_button_cancel, p_slot->number); |
| 679 | p_slot->state = STATIC_STATE; |
| 680 | } else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) { |
| 681 | /* Button Pressed (No action on 1st press...) */ |
| 682 | dbg("%s: Button pressed\n", __FUNCTION__); |
| 683 | |
| 684 | p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 685 | if (getstatus) { |
| 686 | /* slot is on */ |
| 687 | dbg("%s: slot is on\n", __FUNCTION__); |
| 688 | p_slot->state = BLINKINGOFF_STATE; |
| 689 | info(msg_button_off, p_slot->number); |
| 690 | } else { |
| 691 | /* slot is off */ |
| 692 | dbg("%s: slot is off\n", __FUNCTION__); |
| 693 | p_slot->state = BLINKINGON_STATE; |
| 694 | info(msg_button_on, p_slot->number); |
| 695 | } |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | /* blink green LED and turn off amber */ |
| 698 | p_slot->hpc_ops->green_led_blink(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | p_slot->hpc_ops->set_attention_status(p_slot, 0); |
| 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | init_timer(&p_slot->task_event); |
| 702 | p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ |
| 703 | p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread; |
| 704 | p_slot->task_event.data = (unsigned long) p_slot; |
| 705 | |
| 706 | dbg("%s: add_timer p_slot = %p\n", __FUNCTION__,(void *) p_slot); |
| 707 | add_timer(&p_slot->task_event); |
| 708 | } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) { |
| 709 | /***********POWER FAULT********************/ |
| 710 | dbg("%s: power fault\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | p_slot->hpc_ops->set_attention_status(p_slot, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | p_slot->hpc_ops->green_led_off(p_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } else { |
| 714 | /* refresh notification */ |
| 715 | if (p_slot) |
| 716 | update_slot_info(p_slot); |
| 717 | } |
| 718 | |
| 719 | ctrl->event_queue[loop].event_type = 0; |
| 720 | |
| 721 | change = 1; |
| 722 | } |
| 723 | } /* End of FOR loop */ |
| 724 | } |
| 725 | |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | |
| 730 | int shpchp_enable_slot (struct slot *p_slot) |
| 731 | { |
| 732 | u8 getstatus = 0; |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 733 | int rc, retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | /* Check to see if (latch closed, card present, power off) */ |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 736 | mutex_lock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 738 | if (rc || !getstatus) { |
| 739 | info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 740 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 743 | if (rc || getstatus) { |
| 744 | info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 745 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } |
| 747 | rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 748 | if (rc || getstatus) { |
| 749 | info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 750 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 753 | p_slot->is_a_board = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
| 755 | /* We have to save the presence info for these slots */ |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 756 | p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); |
| 757 | p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save)); |
| 758 | dbg("%s: p_slot->pwr_save %x\n", __FUNCTION__, p_slot->pwr_save); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Keck, David | 53044f3 | 2006-01-16 15:22:36 -0600 | [diff] [blame] | 761 | if(((p_slot->ctrl->pci_dev->vendor == PCI_VENDOR_ID_AMD) || |
| 762 | (p_slot->ctrl->pci_dev->device == PCI_DEVICE_ID_AMD_POGO_7458)) |
| 763 | && p_slot->ctrl->num_slots == 1) { |
| 764 | /* handle amd pogo errata; this must be done before enable */ |
| 765 | amd_pogo_errata_save_misc_reg(p_slot); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 766 | retval = board_added(p_slot); |
Keck, David | 53044f3 | 2006-01-16 15:22:36 -0600 | [diff] [blame] | 767 | /* handle amd pogo errata; this must be done after enable */ |
| 768 | amd_pogo_errata_restore_misc_reg(p_slot); |
| 769 | } else |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 770 | retval = board_added(p_slot); |
Keck, David | 53044f3 | 2006-01-16 15:22:36 -0600 | [diff] [blame] | 771 | |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 772 | if (retval) { |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 773 | p_slot->hpc_ops->get_adapter_status(p_slot, |
| 774 | &(p_slot->presence_save)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 778 | update_slot_info(p_slot); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 779 | out: |
| 780 | mutex_unlock(&p_slot->ctrl->crit_sect); |
| 781 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
| 785 | int shpchp_disable_slot (struct slot *p_slot) |
| 786 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | u8 getstatus = 0; |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 788 | int rc, retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | if (!p_slot->ctrl) |
Dely Sy | ee17fd9 | 2005-05-05 11:57:25 -0700 | [diff] [blame] | 791 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* Check to see if (latch closed, card present, power on) */ |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 794 | mutex_lock(&p_slot->ctrl->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 796 | rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); |
| 797 | if (rc || !getstatus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 799 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 801 | rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); |
| 802 | if (rc || getstatus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 804 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 806 | rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); |
| 807 | if (rc || !getstatus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 809 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 812 | retval = remove_board(p_slot); |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 813 | update_slot_info(p_slot); |
Kenji Kaneshige | ef3be54 | 2006-01-26 10:00:33 +0900 | [diff] [blame] | 814 | out: |
| 815 | mutex_unlock(&p_slot->ctrl->crit_sect); |
| 816 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |