18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Standard Hot Plug Controller Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 1995,2001 Compaq Computer Corporation 68c2ecf20Sopenharmony_ci * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) 78c2ecf20Sopenharmony_ci * Copyright (C) 2001 IBM Corp. 88c2ecf20Sopenharmony_ci * Copyright (C) 2003-2004 Intel Corporation 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * All rights reserved. 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com> 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/module.h> 178c2ecf20Sopenharmony_ci#include <linux/kernel.h> 188c2ecf20Sopenharmony_ci#include <linux/types.h> 198c2ecf20Sopenharmony_ci#include <linux/slab.h> 208c2ecf20Sopenharmony_ci#include <linux/pci.h> 218c2ecf20Sopenharmony_ci#include "../pci.h" 228c2ecf20Sopenharmony_ci#include "shpchp.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic void interrupt_event_handler(struct work_struct *work); 258c2ecf20Sopenharmony_cistatic int shpchp_enable_slot(struct slot *p_slot); 268c2ecf20Sopenharmony_cistatic int shpchp_disable_slot(struct slot *p_slot); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic int queue_interrupt_event(struct slot *p_slot, u32 event_type) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci struct event_info *info; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci info = kmalloc(sizeof(*info), GFP_ATOMIC); 338c2ecf20Sopenharmony_ci if (!info) 348c2ecf20Sopenharmony_ci return -ENOMEM; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci info->event_type = event_type; 378c2ecf20Sopenharmony_ci info->p_slot = p_slot; 388c2ecf20Sopenharmony_ci INIT_WORK(&info->work, interrupt_event_handler); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci queue_work(p_slot->wq, &info->work); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci return 0; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ciu8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci struct slot *p_slot; 488c2ecf20Sopenharmony_ci u32 event_type; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* Attention Button Change */ 518c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "Attention button interrupt received\n"); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 548c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci /* 578c2ecf20Sopenharmony_ci * Button pressed - See if need to TAKE ACTION!!! 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Button pressed on Slot(%s)\n", slot_name(p_slot)); 608c2ecf20Sopenharmony_ci event_type = INT_BUTTON_PRESS; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci queue_interrupt_event(p_slot, event_type); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci return 0; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciu8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci struct slot *p_slot; 718c2ecf20Sopenharmony_ci u8 getstatus; 728c2ecf20Sopenharmony_ci u32 event_type; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci /* Switch Change */ 758c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "Switch interrupt received\n"); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 788c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 798c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 808c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "Card present %x Power status %x\n", 818c2ecf20Sopenharmony_ci p_slot->presence_save, p_slot->pwr_save); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci if (getstatus) { 848c2ecf20Sopenharmony_ci /* 858c2ecf20Sopenharmony_ci * Switch opened 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Latch open on Slot(%s)\n", slot_name(p_slot)); 888c2ecf20Sopenharmony_ci event_type = INT_SWITCH_OPEN; 898c2ecf20Sopenharmony_ci if (p_slot->pwr_save && p_slot->presence_save) { 908c2ecf20Sopenharmony_ci event_type = INT_POWER_FAULT; 918c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Surprise Removal of card\n"); 928c2ecf20Sopenharmony_ci } 938c2ecf20Sopenharmony_ci } else { 948c2ecf20Sopenharmony_ci /* 958c2ecf20Sopenharmony_ci * Switch closed 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Latch close on Slot(%s)\n", slot_name(p_slot)); 988c2ecf20Sopenharmony_ci event_type = INT_SWITCH_CLOSE; 998c2ecf20Sopenharmony_ci } 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci queue_interrupt_event(p_slot, event_type); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci return 1; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ciu8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci struct slot *p_slot; 1098c2ecf20Sopenharmony_ci u32 event_type; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci /* Presence Change */ 1128c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "Presence/Notify input change\n"); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci /* 1178c2ecf20Sopenharmony_ci * Save the presence state 1188c2ecf20Sopenharmony_ci */ 1198c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 1208c2ecf20Sopenharmony_ci if (p_slot->presence_save) { 1218c2ecf20Sopenharmony_ci /* 1228c2ecf20Sopenharmony_ci * Card Present 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Card present on Slot(%s)\n", 1258c2ecf20Sopenharmony_ci slot_name(p_slot)); 1268c2ecf20Sopenharmony_ci event_type = INT_PRESENCE_ON; 1278c2ecf20Sopenharmony_ci } else { 1288c2ecf20Sopenharmony_ci /* 1298c2ecf20Sopenharmony_ci * Not Present 1308c2ecf20Sopenharmony_ci */ 1318c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Card not present on Slot(%s)\n", 1328c2ecf20Sopenharmony_ci slot_name(p_slot)); 1338c2ecf20Sopenharmony_ci event_type = INT_PRESENCE_OFF; 1348c2ecf20Sopenharmony_ci } 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci queue_interrupt_event(p_slot, event_type); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci return 1; 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ciu8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci struct slot *p_slot; 1448c2ecf20Sopenharmony_ci u32 event_type; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci /* Power fault */ 1478c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "Power fault interrupt received\n"); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci if (!(p_slot->hpc_ops->query_power_fault(p_slot))) { 1528c2ecf20Sopenharmony_ci /* 1538c2ecf20Sopenharmony_ci * Power fault Cleared 1548c2ecf20Sopenharmony_ci */ 1558c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Power fault cleared on Slot(%s)\n", 1568c2ecf20Sopenharmony_ci slot_name(p_slot)); 1578c2ecf20Sopenharmony_ci p_slot->status = 0x00; 1588c2ecf20Sopenharmony_ci event_type = INT_POWER_FAULT_CLEAR; 1598c2ecf20Sopenharmony_ci } else { 1608c2ecf20Sopenharmony_ci /* 1618c2ecf20Sopenharmony_ci * Power fault 1628c2ecf20Sopenharmony_ci */ 1638c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Power fault on Slot(%s)\n", slot_name(p_slot)); 1648c2ecf20Sopenharmony_ci event_type = INT_POWER_FAULT; 1658c2ecf20Sopenharmony_ci /* set power fault status for this board */ 1668c2ecf20Sopenharmony_ci p_slot->status = 0xFF; 1678c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Power fault bit %x set\n", hp_slot); 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci queue_interrupt_event(p_slot, event_type); 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci return 1; 1738c2ecf20Sopenharmony_ci} 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/* The following routines constitute the bulk of the 1768c2ecf20Sopenharmony_ci hotplug controller logic 1778c2ecf20Sopenharmony_ci */ 1788c2ecf20Sopenharmony_cistatic int change_bus_speed(struct controller *ctrl, struct slot *p_slot, 1798c2ecf20Sopenharmony_ci enum pci_bus_speed speed) 1808c2ecf20Sopenharmony_ci{ 1818c2ecf20Sopenharmony_ci int rc = 0; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "Change speed to %d\n", speed); 1848c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed); 1858c2ecf20Sopenharmony_ci if (rc) { 1868c2ecf20Sopenharmony_ci ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n", 1878c2ecf20Sopenharmony_ci __func__); 1888c2ecf20Sopenharmony_ci return WRONG_BUS_FREQUENCY; 1898c2ecf20Sopenharmony_ci } 1908c2ecf20Sopenharmony_ci return rc; 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic int fix_bus_speed(struct controller *ctrl, struct slot *pslot, 1948c2ecf20Sopenharmony_ci u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp, 1958c2ecf20Sopenharmony_ci enum pci_bus_speed msp) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci int rc = 0; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* 2008c2ecf20Sopenharmony_ci * If other slots on the same bus are occupied, we cannot 2018c2ecf20Sopenharmony_ci * change the bus speed. 2028c2ecf20Sopenharmony_ci */ 2038c2ecf20Sopenharmony_ci if (flag) { 2048c2ecf20Sopenharmony_ci if (asp < bsp) { 2058c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Speed of bus %x and adapter %x mismatch\n", 2068c2ecf20Sopenharmony_ci bsp, asp); 2078c2ecf20Sopenharmony_ci rc = WRONG_BUS_FREQUENCY; 2088c2ecf20Sopenharmony_ci } 2098c2ecf20Sopenharmony_ci return rc; 2108c2ecf20Sopenharmony_ci } 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci if (asp < msp) { 2138c2ecf20Sopenharmony_ci if (bsp != asp) 2148c2ecf20Sopenharmony_ci rc = change_bus_speed(ctrl, pslot, asp); 2158c2ecf20Sopenharmony_ci } else { 2168c2ecf20Sopenharmony_ci if (bsp != msp) 2178c2ecf20Sopenharmony_ci rc = change_bus_speed(ctrl, pslot, msp); 2188c2ecf20Sopenharmony_ci } 2198c2ecf20Sopenharmony_ci return rc; 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci/** 2238c2ecf20Sopenharmony_ci * board_added - Called after a board has been added to the system. 2248c2ecf20Sopenharmony_ci * @p_slot: target &slot 2258c2ecf20Sopenharmony_ci * 2268c2ecf20Sopenharmony_ci * Turns power on for the board. 2278c2ecf20Sopenharmony_ci * Configures board. 2288c2ecf20Sopenharmony_ci */ 2298c2ecf20Sopenharmony_cistatic int board_added(struct slot *p_slot) 2308c2ecf20Sopenharmony_ci{ 2318c2ecf20Sopenharmony_ci u8 hp_slot; 2328c2ecf20Sopenharmony_ci u8 slots_not_empty = 0; 2338c2ecf20Sopenharmony_ci int rc = 0; 2348c2ecf20Sopenharmony_ci enum pci_bus_speed asp, bsp, msp; 2358c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 2368c2ecf20Sopenharmony_ci struct pci_bus *parent = ctrl->pci_dev->subordinate; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci hp_slot = p_slot->device - ctrl->slot_device_offset; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n", 2418c2ecf20Sopenharmony_ci __func__, p_slot->device, ctrl->slot_device_offset, hp_slot); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci /* Power on slot without connecting to bus */ 2448c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->power_on_slot(p_slot); 2458c2ecf20Sopenharmony_ci if (rc) { 2468c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Failed to power on slot\n"); 2478c2ecf20Sopenharmony_ci return -1; 2488c2ecf20Sopenharmony_ci } 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) { 2518c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz); 2528c2ecf20Sopenharmony_ci if (rc) { 2538c2ecf20Sopenharmony_ci ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n", 2548c2ecf20Sopenharmony_ci __func__); 2558c2ecf20Sopenharmony_ci return WRONG_BUS_FREQUENCY; 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* turn on board, blink green LED, turn off Amber LED */ 2598c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->slot_enable(p_slot); 2608c2ecf20Sopenharmony_ci if (rc) { 2618c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Issue of Slot Enable command failed\n"); 2628c2ecf20Sopenharmony_ci return rc; 2638c2ecf20Sopenharmony_ci } 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &asp); 2678c2ecf20Sopenharmony_ci if (rc) { 2688c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Can't get adapter speed or bus mode mismatch\n"); 2698c2ecf20Sopenharmony_ci return WRONG_BUS_FREQUENCY; 2708c2ecf20Sopenharmony_ci } 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci bsp = ctrl->pci_dev->subordinate->cur_bus_speed; 2738c2ecf20Sopenharmony_ci msp = ctrl->pci_dev->subordinate->max_bus_speed; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci /* Check if there are other slots or devices on the same bus */ 2768c2ecf20Sopenharmony_ci if (!list_empty(&ctrl->pci_dev->subordinate->devices)) 2778c2ecf20Sopenharmony_ci slots_not_empty = 1; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "%s: slots_not_empty %d, adapter_speed %d, bus_speed %d, max_bus_speed %d\n", 2808c2ecf20Sopenharmony_ci __func__, slots_not_empty, asp, 2818c2ecf20Sopenharmony_ci bsp, msp); 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, asp, bsp, msp); 2848c2ecf20Sopenharmony_ci if (rc) 2858c2ecf20Sopenharmony_ci return rc; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci /* turn on board, blink green LED, turn off Amber LED */ 2888c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->slot_enable(p_slot); 2898c2ecf20Sopenharmony_ci if (rc) { 2908c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Issue of Slot Enable command failed\n"); 2918c2ecf20Sopenharmony_ci return rc; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci /* Wait for ~1 second */ 2958c2ecf20Sopenharmony_ci msleep(1000); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "%s: slot status = %x\n", __func__, p_slot->status); 2988c2ecf20Sopenharmony_ci /* Check for a power fault */ 2998c2ecf20Sopenharmony_ci if (p_slot->status == 0xFF) { 3008c2ecf20Sopenharmony_ci /* power fault occurred, but it was benign */ 3018c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "%s: Power fault\n", __func__); 3028c2ecf20Sopenharmony_ci p_slot->status = 0; 3038c2ecf20Sopenharmony_ci goto err_exit; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci if (shpchp_configure_device(p_slot)) { 3078c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Cannot add device at %04x:%02x:%02x\n", 3088c2ecf20Sopenharmony_ci pci_domain_nr(parent), p_slot->bus, p_slot->device); 3098c2ecf20Sopenharmony_ci goto err_exit; 3108c2ecf20Sopenharmony_ci } 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci p_slot->status = 0; 3138c2ecf20Sopenharmony_ci p_slot->is_a_board = 0x01; 3148c2ecf20Sopenharmony_ci p_slot->pwr_save = 1; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci p_slot->hpc_ops->green_led_on(p_slot); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci return 0; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_cierr_exit: 3218c2ecf20Sopenharmony_ci /* turn off slot, turn on Amber LED, turn off Green LED */ 3228c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->slot_disable(p_slot); 3238c2ecf20Sopenharmony_ci if (rc) { 3248c2ecf20Sopenharmony_ci ctrl_err(ctrl, "%s: Issue of Slot Disable command failed\n", 3258c2ecf20Sopenharmony_ci __func__); 3268c2ecf20Sopenharmony_ci return rc; 3278c2ecf20Sopenharmony_ci } 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci return(rc); 3308c2ecf20Sopenharmony_ci} 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci/** 3348c2ecf20Sopenharmony_ci * remove_board - Turns off slot and LEDs 3358c2ecf20Sopenharmony_ci * @p_slot: target &slot 3368c2ecf20Sopenharmony_ci */ 3378c2ecf20Sopenharmony_cistatic int remove_board(struct slot *p_slot) 3388c2ecf20Sopenharmony_ci{ 3398c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 3408c2ecf20Sopenharmony_ci u8 hp_slot; 3418c2ecf20Sopenharmony_ci int rc; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci shpchp_unconfigure_device(p_slot); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci hp_slot = p_slot->device - ctrl->slot_device_offset; 3468c2ecf20Sopenharmony_ci p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "%s: hp_slot = %d\n", __func__, hp_slot); 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci /* Change status to shutdown */ 3518c2ecf20Sopenharmony_ci if (p_slot->is_a_board) 3528c2ecf20Sopenharmony_ci p_slot->status = 0x01; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci /* turn off slot, turn on Amber LED, turn off Green LED */ 3558c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->slot_disable(p_slot); 3568c2ecf20Sopenharmony_ci if (rc) { 3578c2ecf20Sopenharmony_ci ctrl_err(ctrl, "%s: Issue of Slot Disable command failed\n", 3588c2ecf20Sopenharmony_ci __func__); 3598c2ecf20Sopenharmony_ci return rc; 3608c2ecf20Sopenharmony_ci } 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->set_attention_status(p_slot, 0); 3638c2ecf20Sopenharmony_ci if (rc) { 3648c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Issue of Set Attention command failed\n"); 3658c2ecf20Sopenharmony_ci return rc; 3668c2ecf20Sopenharmony_ci } 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci p_slot->pwr_save = 0; 3698c2ecf20Sopenharmony_ci p_slot->is_a_board = 0; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci return 0; 3728c2ecf20Sopenharmony_ci} 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_cistruct pushbutton_work_info { 3768c2ecf20Sopenharmony_ci struct slot *p_slot; 3778c2ecf20Sopenharmony_ci struct work_struct work; 3788c2ecf20Sopenharmony_ci}; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci/** 3818c2ecf20Sopenharmony_ci * shpchp_pushbutton_thread - handle pushbutton events 3828c2ecf20Sopenharmony_ci * @work: &struct work_struct to be handled 3838c2ecf20Sopenharmony_ci * 3848c2ecf20Sopenharmony_ci * Scheduled procedure to handle blocking stuff for the pushbuttons. 3858c2ecf20Sopenharmony_ci * Handles all pending events and exits. 3868c2ecf20Sopenharmony_ci */ 3878c2ecf20Sopenharmony_cistatic void shpchp_pushbutton_thread(struct work_struct *work) 3888c2ecf20Sopenharmony_ci{ 3898c2ecf20Sopenharmony_ci struct pushbutton_work_info *info = 3908c2ecf20Sopenharmony_ci container_of(work, struct pushbutton_work_info, work); 3918c2ecf20Sopenharmony_ci struct slot *p_slot = info->p_slot; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 3948c2ecf20Sopenharmony_ci switch (p_slot->state) { 3958c2ecf20Sopenharmony_ci case POWEROFF_STATE: 3968c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 3978c2ecf20Sopenharmony_ci shpchp_disable_slot(p_slot); 3988c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 3998c2ecf20Sopenharmony_ci p_slot->state = STATIC_STATE; 4008c2ecf20Sopenharmony_ci break; 4018c2ecf20Sopenharmony_ci case POWERON_STATE: 4028c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 4038c2ecf20Sopenharmony_ci if (shpchp_enable_slot(p_slot)) 4048c2ecf20Sopenharmony_ci p_slot->hpc_ops->green_led_off(p_slot); 4058c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 4068c2ecf20Sopenharmony_ci p_slot->state = STATIC_STATE; 4078c2ecf20Sopenharmony_ci break; 4088c2ecf20Sopenharmony_ci default: 4098c2ecf20Sopenharmony_ci break; 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci kfree(info); 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_civoid shpchp_queue_pushbutton_work(struct work_struct *work) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci struct slot *p_slot = container_of(work, struct slot, work.work); 4198c2ecf20Sopenharmony_ci struct pushbutton_work_info *info; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci info = kmalloc(sizeof(*info), GFP_KERNEL); 4228c2ecf20Sopenharmony_ci if (!info) { 4238c2ecf20Sopenharmony_ci ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n", 4248c2ecf20Sopenharmony_ci __func__); 4258c2ecf20Sopenharmony_ci return; 4268c2ecf20Sopenharmony_ci } 4278c2ecf20Sopenharmony_ci info->p_slot = p_slot; 4288c2ecf20Sopenharmony_ci INIT_WORK(&info->work, shpchp_pushbutton_thread); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 4318c2ecf20Sopenharmony_ci switch (p_slot->state) { 4328c2ecf20Sopenharmony_ci case BLINKINGOFF_STATE: 4338c2ecf20Sopenharmony_ci p_slot->state = POWEROFF_STATE; 4348c2ecf20Sopenharmony_ci break; 4358c2ecf20Sopenharmony_ci case BLINKINGON_STATE: 4368c2ecf20Sopenharmony_ci p_slot->state = POWERON_STATE; 4378c2ecf20Sopenharmony_ci break; 4388c2ecf20Sopenharmony_ci default: 4398c2ecf20Sopenharmony_ci kfree(info); 4408c2ecf20Sopenharmony_ci goto out; 4418c2ecf20Sopenharmony_ci } 4428c2ecf20Sopenharmony_ci queue_work(p_slot->wq, &info->work); 4438c2ecf20Sopenharmony_ci out: 4448c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 4458c2ecf20Sopenharmony_ci} 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_cistatic void update_slot_info(struct slot *slot) 4488c2ecf20Sopenharmony_ci{ 4498c2ecf20Sopenharmony_ci slot->hpc_ops->get_power_status(slot, &slot->pwr_save); 4508c2ecf20Sopenharmony_ci slot->hpc_ops->get_attention_status(slot, &slot->attention_save); 4518c2ecf20Sopenharmony_ci slot->hpc_ops->get_latch_status(slot, &slot->latch_save); 4528c2ecf20Sopenharmony_ci slot->hpc_ops->get_adapter_status(slot, &slot->presence_save); 4538c2ecf20Sopenharmony_ci} 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci/* 4568c2ecf20Sopenharmony_ci * Note: This function must be called with slot->lock held 4578c2ecf20Sopenharmony_ci */ 4588c2ecf20Sopenharmony_cistatic void handle_button_press_event(struct slot *p_slot) 4598c2ecf20Sopenharmony_ci{ 4608c2ecf20Sopenharmony_ci u8 getstatus; 4618c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci switch (p_slot->state) { 4648c2ecf20Sopenharmony_ci case STATIC_STATE: 4658c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 4668c2ecf20Sopenharmony_ci if (getstatus) { 4678c2ecf20Sopenharmony_ci p_slot->state = BLINKINGOFF_STATE; 4688c2ecf20Sopenharmony_ci ctrl_info(ctrl, "PCI slot #%s - powering off due to button press\n", 4698c2ecf20Sopenharmony_ci slot_name(p_slot)); 4708c2ecf20Sopenharmony_ci } else { 4718c2ecf20Sopenharmony_ci p_slot->state = BLINKINGON_STATE; 4728c2ecf20Sopenharmony_ci ctrl_info(ctrl, "PCI slot #%s - powering on due to button press\n", 4738c2ecf20Sopenharmony_ci slot_name(p_slot)); 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci /* blink green LED and turn off amber */ 4768c2ecf20Sopenharmony_ci p_slot->hpc_ops->green_led_blink(p_slot); 4778c2ecf20Sopenharmony_ci p_slot->hpc_ops->set_attention_status(p_slot, 0); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci queue_delayed_work(p_slot->wq, &p_slot->work, 5*HZ); 4808c2ecf20Sopenharmony_ci break; 4818c2ecf20Sopenharmony_ci case BLINKINGOFF_STATE: 4828c2ecf20Sopenharmony_ci case BLINKINGON_STATE: 4838c2ecf20Sopenharmony_ci /* 4848c2ecf20Sopenharmony_ci * Cancel if we are still blinking; this means that we 4858c2ecf20Sopenharmony_ci * press the attention again before the 5 sec. limit 4868c2ecf20Sopenharmony_ci * expires to cancel hot-add or hot-remove 4878c2ecf20Sopenharmony_ci */ 4888c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Button cancel on Slot(%s)\n", 4898c2ecf20Sopenharmony_ci slot_name(p_slot)); 4908c2ecf20Sopenharmony_ci cancel_delayed_work(&p_slot->work); 4918c2ecf20Sopenharmony_ci if (p_slot->state == BLINKINGOFF_STATE) 4928c2ecf20Sopenharmony_ci p_slot->hpc_ops->green_led_on(p_slot); 4938c2ecf20Sopenharmony_ci else 4948c2ecf20Sopenharmony_ci p_slot->hpc_ops->green_led_off(p_slot); 4958c2ecf20Sopenharmony_ci p_slot->hpc_ops->set_attention_status(p_slot, 0); 4968c2ecf20Sopenharmony_ci ctrl_info(ctrl, "PCI slot #%s - action canceled due to button press\n", 4978c2ecf20Sopenharmony_ci slot_name(p_slot)); 4988c2ecf20Sopenharmony_ci p_slot->state = STATIC_STATE; 4998c2ecf20Sopenharmony_ci break; 5008c2ecf20Sopenharmony_ci case POWEROFF_STATE: 5018c2ecf20Sopenharmony_ci case POWERON_STATE: 5028c2ecf20Sopenharmony_ci /* 5038c2ecf20Sopenharmony_ci * Ignore if the slot is on power-on or power-off state; 5048c2ecf20Sopenharmony_ci * this means that the previous attention button action 5058c2ecf20Sopenharmony_ci * to hot-add or hot-remove is undergoing 5068c2ecf20Sopenharmony_ci */ 5078c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Button ignore on Slot(%s)\n", 5088c2ecf20Sopenharmony_ci slot_name(p_slot)); 5098c2ecf20Sopenharmony_ci update_slot_info(p_slot); 5108c2ecf20Sopenharmony_ci break; 5118c2ecf20Sopenharmony_ci default: 5128c2ecf20Sopenharmony_ci ctrl_warn(ctrl, "Not a valid state\n"); 5138c2ecf20Sopenharmony_ci break; 5148c2ecf20Sopenharmony_ci } 5158c2ecf20Sopenharmony_ci} 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_cistatic void interrupt_event_handler(struct work_struct *work) 5188c2ecf20Sopenharmony_ci{ 5198c2ecf20Sopenharmony_ci struct event_info *info = container_of(work, struct event_info, work); 5208c2ecf20Sopenharmony_ci struct slot *p_slot = info->p_slot; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 5238c2ecf20Sopenharmony_ci switch (info->event_type) { 5248c2ecf20Sopenharmony_ci case INT_BUTTON_PRESS: 5258c2ecf20Sopenharmony_ci handle_button_press_event(p_slot); 5268c2ecf20Sopenharmony_ci break; 5278c2ecf20Sopenharmony_ci case INT_POWER_FAULT: 5288c2ecf20Sopenharmony_ci ctrl_dbg(p_slot->ctrl, "%s: Power fault\n", __func__); 5298c2ecf20Sopenharmony_ci p_slot->hpc_ops->set_attention_status(p_slot, 1); 5308c2ecf20Sopenharmony_ci p_slot->hpc_ops->green_led_off(p_slot); 5318c2ecf20Sopenharmony_ci break; 5328c2ecf20Sopenharmony_ci default: 5338c2ecf20Sopenharmony_ci update_slot_info(p_slot); 5348c2ecf20Sopenharmony_ci break; 5358c2ecf20Sopenharmony_ci } 5368c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci kfree(info); 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_cistatic int shpchp_enable_slot (struct slot *p_slot) 5438c2ecf20Sopenharmony_ci{ 5448c2ecf20Sopenharmony_ci u8 getstatus = 0; 5458c2ecf20Sopenharmony_ci int rc, retval = -ENODEV; 5468c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci /* Check to see if (latch closed, card present, power off) */ 5498c2ecf20Sopenharmony_ci mutex_lock(&p_slot->ctrl->crit_sect); 5508c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 5518c2ecf20Sopenharmony_ci if (rc || !getstatus) { 5528c2ecf20Sopenharmony_ci ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot)); 5538c2ecf20Sopenharmony_ci goto out; 5548c2ecf20Sopenharmony_ci } 5558c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 5568c2ecf20Sopenharmony_ci if (rc || getstatus) { 5578c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Latch open on slot(%s)\n", slot_name(p_slot)); 5588c2ecf20Sopenharmony_ci goto out; 5598c2ecf20Sopenharmony_ci } 5608c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 5618c2ecf20Sopenharmony_ci if (rc || getstatus) { 5628c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Already enabled on slot(%s)\n", 5638c2ecf20Sopenharmony_ci slot_name(p_slot)); 5648c2ecf20Sopenharmony_ci goto out; 5658c2ecf20Sopenharmony_ci } 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci p_slot->is_a_board = 1; 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci /* We have to save the presence info for these slots */ 5708c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 5718c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save)); 5728c2ecf20Sopenharmony_ci ctrl_dbg(ctrl, "%s: p_slot->pwr_save %x\n", __func__, p_slot->pwr_save); 5738c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci if ((p_slot->ctrl->pci_dev->vendor == PCI_VENDOR_ID_AMD && 5768c2ecf20Sopenharmony_ci p_slot->ctrl->pci_dev->device == PCI_DEVICE_ID_AMD_POGO_7458) 5778c2ecf20Sopenharmony_ci && p_slot->ctrl->num_slots == 1) { 5788c2ecf20Sopenharmony_ci /* handle AMD POGO errata; this must be done before enable */ 5798c2ecf20Sopenharmony_ci amd_pogo_errata_save_misc_reg(p_slot); 5808c2ecf20Sopenharmony_ci retval = board_added(p_slot); 5818c2ecf20Sopenharmony_ci /* handle AMD POGO errata; this must be done after enable */ 5828c2ecf20Sopenharmony_ci amd_pogo_errata_restore_misc_reg(p_slot); 5838c2ecf20Sopenharmony_ci } else 5848c2ecf20Sopenharmony_ci retval = board_added(p_slot); 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci if (retval) { 5878c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_adapter_status(p_slot, 5888c2ecf20Sopenharmony_ci &(p_slot->presence_save)); 5898c2ecf20Sopenharmony_ci p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 5908c2ecf20Sopenharmony_ci } 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci update_slot_info(p_slot); 5938c2ecf20Sopenharmony_ci out: 5948c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->ctrl->crit_sect); 5958c2ecf20Sopenharmony_ci return retval; 5968c2ecf20Sopenharmony_ci} 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_cistatic int shpchp_disable_slot (struct slot *p_slot) 6008c2ecf20Sopenharmony_ci{ 6018c2ecf20Sopenharmony_ci u8 getstatus = 0; 6028c2ecf20Sopenharmony_ci int rc, retval = -ENODEV; 6038c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci if (!p_slot->ctrl) 6068c2ecf20Sopenharmony_ci return -ENODEV; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci /* Check to see if (latch closed, card present, power on) */ 6098c2ecf20Sopenharmony_ci mutex_lock(&p_slot->ctrl->crit_sect); 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 6128c2ecf20Sopenharmony_ci if (rc || !getstatus) { 6138c2ecf20Sopenharmony_ci ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot)); 6148c2ecf20Sopenharmony_ci goto out; 6158c2ecf20Sopenharmony_ci } 6168c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 6178c2ecf20Sopenharmony_ci if (rc || getstatus) { 6188c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Latch open on slot(%s)\n", slot_name(p_slot)); 6198c2ecf20Sopenharmony_ci goto out; 6208c2ecf20Sopenharmony_ci } 6218c2ecf20Sopenharmony_ci rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 6228c2ecf20Sopenharmony_ci if (rc || !getstatus) { 6238c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Already disabled on slot(%s)\n", 6248c2ecf20Sopenharmony_ci slot_name(p_slot)); 6258c2ecf20Sopenharmony_ci goto out; 6268c2ecf20Sopenharmony_ci } 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci retval = remove_board(p_slot); 6298c2ecf20Sopenharmony_ci update_slot_info(p_slot); 6308c2ecf20Sopenharmony_ci out: 6318c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->ctrl->crit_sect); 6328c2ecf20Sopenharmony_ci return retval; 6338c2ecf20Sopenharmony_ci} 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ciint shpchp_sysfs_enable_slot(struct slot *p_slot) 6368c2ecf20Sopenharmony_ci{ 6378c2ecf20Sopenharmony_ci int retval = -ENODEV; 6388c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 6418c2ecf20Sopenharmony_ci switch (p_slot->state) { 6428c2ecf20Sopenharmony_ci case BLINKINGON_STATE: 6438c2ecf20Sopenharmony_ci cancel_delayed_work(&p_slot->work); 6448c2ecf20Sopenharmony_ci fallthrough; 6458c2ecf20Sopenharmony_ci case STATIC_STATE: 6468c2ecf20Sopenharmony_ci p_slot->state = POWERON_STATE; 6478c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 6488c2ecf20Sopenharmony_ci retval = shpchp_enable_slot(p_slot); 6498c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 6508c2ecf20Sopenharmony_ci p_slot->state = STATIC_STATE; 6518c2ecf20Sopenharmony_ci break; 6528c2ecf20Sopenharmony_ci case POWERON_STATE: 6538c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Slot %s is already in powering on state\n", 6548c2ecf20Sopenharmony_ci slot_name(p_slot)); 6558c2ecf20Sopenharmony_ci break; 6568c2ecf20Sopenharmony_ci case BLINKINGOFF_STATE: 6578c2ecf20Sopenharmony_ci case POWEROFF_STATE: 6588c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Already enabled on slot %s\n", 6598c2ecf20Sopenharmony_ci slot_name(p_slot)); 6608c2ecf20Sopenharmony_ci break; 6618c2ecf20Sopenharmony_ci default: 6628c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Not a valid state on slot %s\n", 6638c2ecf20Sopenharmony_ci slot_name(p_slot)); 6648c2ecf20Sopenharmony_ci break; 6658c2ecf20Sopenharmony_ci } 6668c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci return retval; 6698c2ecf20Sopenharmony_ci} 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ciint shpchp_sysfs_disable_slot(struct slot *p_slot) 6728c2ecf20Sopenharmony_ci{ 6738c2ecf20Sopenharmony_ci int retval = -ENODEV; 6748c2ecf20Sopenharmony_ci struct controller *ctrl = p_slot->ctrl; 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 6778c2ecf20Sopenharmony_ci switch (p_slot->state) { 6788c2ecf20Sopenharmony_ci case BLINKINGOFF_STATE: 6798c2ecf20Sopenharmony_ci cancel_delayed_work(&p_slot->work); 6808c2ecf20Sopenharmony_ci fallthrough; 6818c2ecf20Sopenharmony_ci case STATIC_STATE: 6828c2ecf20Sopenharmony_ci p_slot->state = POWEROFF_STATE; 6838c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 6848c2ecf20Sopenharmony_ci retval = shpchp_disable_slot(p_slot); 6858c2ecf20Sopenharmony_ci mutex_lock(&p_slot->lock); 6868c2ecf20Sopenharmony_ci p_slot->state = STATIC_STATE; 6878c2ecf20Sopenharmony_ci break; 6888c2ecf20Sopenharmony_ci case POWEROFF_STATE: 6898c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Slot %s is already in powering off state\n", 6908c2ecf20Sopenharmony_ci slot_name(p_slot)); 6918c2ecf20Sopenharmony_ci break; 6928c2ecf20Sopenharmony_ci case BLINKINGON_STATE: 6938c2ecf20Sopenharmony_ci case POWERON_STATE: 6948c2ecf20Sopenharmony_ci ctrl_info(ctrl, "Already disabled on slot %s\n", 6958c2ecf20Sopenharmony_ci slot_name(p_slot)); 6968c2ecf20Sopenharmony_ci break; 6978c2ecf20Sopenharmony_ci default: 6988c2ecf20Sopenharmony_ci ctrl_err(ctrl, "Not a valid state on slot %s\n", 6998c2ecf20Sopenharmony_ci slot_name(p_slot)); 7008c2ecf20Sopenharmony_ci break; 7018c2ecf20Sopenharmony_ci } 7028c2ecf20Sopenharmony_ci mutex_unlock(&p_slot->lock); 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci return retval; 7058c2ecf20Sopenharmony_ci} 706